effect
stringclasses 48
values | original_source_type
stringlengths 0
23k
| opens_and_abbrevs
listlengths 2
92
| isa_cross_project_example
bool 1
class | source_definition
stringlengths 9
57.9k
| partial_definition
stringlengths 7
23.3k
| is_div
bool 2
classes | is_type
null | is_proof
bool 2
classes | completed_definiton
stringlengths 1
250k
| dependencies
dict | effect_flags
sequencelengths 0
2
| ideal_premises
sequencelengths 0
236
| mutual_with
sequencelengths 0
11
| file_context
stringlengths 0
407k
| interleaved
bool 1
class | is_simply_typed
bool 2
classes | file_name
stringlengths 5
48
| vconfig
dict | is_simple_lemma
null | source_type
stringlengths 10
23k
| proof_features
sequencelengths 0
1
| name
stringlengths 8
95
| source
dict | verbose_type
stringlengths 1
7.42k
| source_range
dict |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Prims.Tot | [
{
"abbrev": true,
"full_module": "InterpreterTarget",
"short_module": "I"
},
{
"abbrev": true,
"full_module": "Target",
"short_module": "T"
},
{
"abbrev": true,
"full_module": "Ast",
"short_module": "A"
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.All",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.Printf",
"short_module": "Printf"
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let mk_app fn = function
| None -> fn
| Some args -> Printf.sprintf "(%s %s)" fn args | let mk_app fn = | false | null | false | function
| None -> fn
| Some args -> Printf.sprintf "(%s %s)" fn args | {
"checked_file": "Z3TestGen.fst.checked",
"dependencies": [
"Z3.fsti.checked",
"Target.fsti.checked",
"prims.fst.checked",
"OS.fsti.checked",
"Lisp.fsti.checked",
"InterpreterTarget.fsti.checked",
"FStar.String.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Printf.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.List.Tot.fst.checked",
"FStar.List.fst.checked",
"FStar.IO.fst.checked",
"FStar.Char.fsti.checked",
"FStar.All.fst.checked",
"Ast.fst.checked"
],
"interface_file": false,
"source_file": "Z3TestGen.fst"
} | [
"total"
] | [
"Prims.string",
"FStar.Pervasives.Native.option",
"FStar.Printf.sprintf"
] | [] | module Z3TestGen
module Printf = FStar.Printf
open FStar.All
open FStar.Mul
module A = Ast
module T = Target
module I = InterpreterTarget
let prelude : string =
"
(set-option :produce-models true)
(declare-datatypes () ((State (mk-state (input-size Int) (choice-index Int)))))
(declare-datatypes () ((Result (mk-result (return-value Int) (after-state State)))))
(define-fun parse-empty ((x State)) Result
(mk-result 0 x)
)
(declare-fun choose (Int) Int)
(assert (forall ((i Int))
(and (<= 0 (choose i)) (< (choose i) 256))
))
(define-fun parse-false ((x State)) State
(mk-state -1 (choice-index x))
)
(define-fun parse-all-bytes ((x State)) State
(if (<= (input-size x) 0)
x
(mk-state 0 (+ (choice-index x) (input-size x)))
)
)
(define-fun parse-all-zeros ((x State)) State
(if (<= (input-size x) 0)
x
(mk-state
(if
(forall ((j Int))
(if (and (<= 0 j) (< j (input-size x)))
(= (choose (+ (choice-index x) j)) 0)
true
)
)
0
-1
)
(+ (choice-index x) (input-size x))
)
)
)
(define-fun parse-u8 ((x State)) Result
(mk-result
(choose (choice-index x))
(mk-state (- (input-size x) 1) (+ (choice-index x) 1))
)
)
(define-fun parse-u16-be ((x State)) Result
(mk-result
(+ (choose (+ 1 (choice-index x)))
(* 256
(choose (+ 0 (choice-index x)))
)
)
(mk-state (- (input-size x) 2) (+ (choice-index x) 2))
)
)
(define-fun parse-u16-le ((x State)) Result
(mk-result
(+ (choose (+ 0 (choice-index x)))
(* 256
(choose (+ 1 (choice-index x)))
)
)
(mk-state (- (input-size x) 2) (+ (choice-index x) 2))
)
)
(define-fun parse-u32-be ((x State)) Result
(mk-result
(+ (choose (+ 3 (choice-index x)))
(* 256
(+ (choose (+ 2 (choice-index x)))
(* 256
(+ (choose (+ 1 (choice-index x)))
(* 256
(choose (+ 0 (choice-index x)))
)
)
)
)
)
)
(mk-state (- (input-size x) 4) (+ (choice-index x) 4))
)
)
(define-fun parse-u32-le ((x State)) Result
(mk-result
(+ (choose (+ 0 (choice-index x)))
(* 256
(+ (choose (+ 1 (choice-index x)))
(* 256
(+ (choose (+ 2 (choice-index x)))
(* 256
(choose (+ 3 (choice-index x)))
)
)
)
)
)
)
(mk-state (- (input-size x) 4) (+ (choice-index x) 4))
)
)
(define-fun parse-u64-be ((x State)) Result
(mk-result
(+ (choose (+ 7 (choice-index x)))
(* 256
(+ (choose (+ 6 (choice-index x)))
(* 256
(+ (choose (+ 5 (choice-index x)))
(* 256
(+ (choose (+ 4 (choice-index x)))
(* 256
(+ (choose (+ 3 (choice-index x)))
(* 256
(+ (choose (+ 2 (choice-index x)))
(* 256
(+ (choose (+ 1 (choice-index x)))
(* 256
(choose (+ 0 (choice-index x)))
)
)
)
)
)
)
)
)
)
)
)
)
)
)
(mk-state (- (input-size x) 8) (+ (choice-index x) 8))
)
)
(define-fun parse-u64-le ((x State)) Result
(mk-result
(+ (choose (+ 0 (choice-index x)))
(* 256
(+ (choose (+ 1 (choice-index x)))
(* 256
(+ (choose (+ 2 (choice-index x)))
(* 256
(+ (choose (+ 3 (choice-index x)))
(* 256
(+ (choose (+ 4 (choice-index x)))
(* 256
(+ (choose (+ 5 (choice-index x)))
(* 256
(+ (choose (+ 6 (choice-index x)))
(* 256
(choose (+ 7 (choice-index x)))
)
)
)
)
)
)
)
)
)
)
)
)
)
)
(mk-state (- (input-size x) 8) (+ (choice-index x) 8))
)
)
(define-fun-rec pow-2 ((amount Int)) Int
(if (<= amount 0)
1
(* 2 (pow-2 (- amount 1)))
)
)
;; see LowParse.BitFields.get_bitfield_eq
(define-fun get-bitfield-lsb ((nbBits Int) (value Int) (bitsFrom Int) (bitsTo Int)) Int
(mod (div value (pow-2 bitsFrom)) (pow-2 (- bitsTo bitsFrom)))
)
;; see EverParse3d.Prelude.StaticHeader
(define-fun get-bitfield-msb ((nbBits Int) (value Int) (bitsFrom Int) (bitsTo Int)) Int
(get-bitfield-lsb nbBits value (- nbBits bitsTo) (- nbBits bitsFrom))
)
(declare-const initial-input-size Int)
(assert (>= initial-input-size 0))
(define-fun initial-state () State (mk-state initial-input-size 0))
"
let mk_constant = function
| A.Unit -> "0"
| A.Int _ x -> string_of_int x
| A.XInt _ x -> string_of_int (OS.int_of_string x)
| A.Bool true -> "true"
| A.Bool false -> "false" | false | true | Z3TestGen.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val mk_app : fn: Prims.string -> _: FStar.Pervasives.Native.option Prims.string -> Prims.string | [] | Z3TestGen.mk_app | {
"file_name": "src/3d/Z3TestGen.fst",
"git_rev": "446a08ce38df905547cf20f28c43776b22b8087a",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | fn: Prims.string -> _: FStar.Pervasives.Native.option Prims.string -> Prims.string | {
"end_col": 49,
"end_line": 224,
"start_col": 16,
"start_line": 222
} |
|
Prims.Tot | val readable_itype_parser_suffix (i: I.itype) : Tot string | [
{
"abbrev": true,
"full_module": "InterpreterTarget",
"short_module": "I"
},
{
"abbrev": true,
"full_module": "Target",
"short_module": "T"
},
{
"abbrev": true,
"full_module": "Ast",
"short_module": "A"
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.All",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.Printf",
"short_module": "Printf"
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let readable_itype_parser_suffix (i: I.itype) : Tot string = match i with
| I.UInt8 | I.UInt8BE -> "u8"
| I.UInt16 -> "u16-le"
| I.UInt16BE -> "u16-be"
| I.UInt32 -> "u32-le"
| I.UInt32BE -> "u32-be"
| I.UInt64 -> "u64-le"
| I.UInt64BE -> "u64-be"
| I.Unit -> "empty"
| I.AllBytes -> "all-bytes"
| I.AllZeros -> "all-zeros" | val readable_itype_parser_suffix (i: I.itype) : Tot string
let readable_itype_parser_suffix (i: I.itype) : Tot string = | false | null | false | match i with
| I.UInt8 | I.UInt8BE -> "u8"
| I.UInt16 -> "u16-le"
| I.UInt16BE -> "u16-be"
| I.UInt32 -> "u32-le"
| I.UInt32BE -> "u32-be"
| I.UInt64 -> "u64-le"
| I.UInt64BE -> "u64-be"
| I.Unit -> "empty"
| I.AllBytes -> "all-bytes"
| I.AllZeros -> "all-zeros" | {
"checked_file": "Z3TestGen.fst.checked",
"dependencies": [
"Z3.fsti.checked",
"Target.fsti.checked",
"prims.fst.checked",
"OS.fsti.checked",
"Lisp.fsti.checked",
"InterpreterTarget.fsti.checked",
"FStar.String.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Printf.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.List.Tot.fst.checked",
"FStar.List.fst.checked",
"FStar.IO.fst.checked",
"FStar.Char.fsti.checked",
"FStar.All.fst.checked",
"Ast.fst.checked"
],
"interface_file": false,
"source_file": "Z3TestGen.fst"
} | [
"total"
] | [
"InterpreterTarget.itype",
"Prims.string"
] | [] | module Z3TestGen
module Printf = FStar.Printf
open FStar.All
open FStar.Mul
module A = Ast
module T = Target
module I = InterpreterTarget
let prelude : string =
"
(set-option :produce-models true)
(declare-datatypes () ((State (mk-state (input-size Int) (choice-index Int)))))
(declare-datatypes () ((Result (mk-result (return-value Int) (after-state State)))))
(define-fun parse-empty ((x State)) Result
(mk-result 0 x)
)
(declare-fun choose (Int) Int)
(assert (forall ((i Int))
(and (<= 0 (choose i)) (< (choose i) 256))
))
(define-fun parse-false ((x State)) State
(mk-state -1 (choice-index x))
)
(define-fun parse-all-bytes ((x State)) State
(if (<= (input-size x) 0)
x
(mk-state 0 (+ (choice-index x) (input-size x)))
)
)
(define-fun parse-all-zeros ((x State)) State
(if (<= (input-size x) 0)
x
(mk-state
(if
(forall ((j Int))
(if (and (<= 0 j) (< j (input-size x)))
(= (choose (+ (choice-index x) j)) 0)
true
)
)
0
-1
)
(+ (choice-index x) (input-size x))
)
)
)
(define-fun parse-u8 ((x State)) Result
(mk-result
(choose (choice-index x))
(mk-state (- (input-size x) 1) (+ (choice-index x) 1))
)
)
(define-fun parse-u16-be ((x State)) Result
(mk-result
(+ (choose (+ 1 (choice-index x)))
(* 256
(choose (+ 0 (choice-index x)))
)
)
(mk-state (- (input-size x) 2) (+ (choice-index x) 2))
)
)
(define-fun parse-u16-le ((x State)) Result
(mk-result
(+ (choose (+ 0 (choice-index x)))
(* 256
(choose (+ 1 (choice-index x)))
)
)
(mk-state (- (input-size x) 2) (+ (choice-index x) 2))
)
)
(define-fun parse-u32-be ((x State)) Result
(mk-result
(+ (choose (+ 3 (choice-index x)))
(* 256
(+ (choose (+ 2 (choice-index x)))
(* 256
(+ (choose (+ 1 (choice-index x)))
(* 256
(choose (+ 0 (choice-index x)))
)
)
)
)
)
)
(mk-state (- (input-size x) 4) (+ (choice-index x) 4))
)
)
(define-fun parse-u32-le ((x State)) Result
(mk-result
(+ (choose (+ 0 (choice-index x)))
(* 256
(+ (choose (+ 1 (choice-index x)))
(* 256
(+ (choose (+ 2 (choice-index x)))
(* 256
(choose (+ 3 (choice-index x)))
)
)
)
)
)
)
(mk-state (- (input-size x) 4) (+ (choice-index x) 4))
)
)
(define-fun parse-u64-be ((x State)) Result
(mk-result
(+ (choose (+ 7 (choice-index x)))
(* 256
(+ (choose (+ 6 (choice-index x)))
(* 256
(+ (choose (+ 5 (choice-index x)))
(* 256
(+ (choose (+ 4 (choice-index x)))
(* 256
(+ (choose (+ 3 (choice-index x)))
(* 256
(+ (choose (+ 2 (choice-index x)))
(* 256
(+ (choose (+ 1 (choice-index x)))
(* 256
(choose (+ 0 (choice-index x)))
)
)
)
)
)
)
)
)
)
)
)
)
)
)
(mk-state (- (input-size x) 8) (+ (choice-index x) 8))
)
)
(define-fun parse-u64-le ((x State)) Result
(mk-result
(+ (choose (+ 0 (choice-index x)))
(* 256
(+ (choose (+ 1 (choice-index x)))
(* 256
(+ (choose (+ 2 (choice-index x)))
(* 256
(+ (choose (+ 3 (choice-index x)))
(* 256
(+ (choose (+ 4 (choice-index x)))
(* 256
(+ (choose (+ 5 (choice-index x)))
(* 256
(+ (choose (+ 6 (choice-index x)))
(* 256
(choose (+ 7 (choice-index x)))
)
)
)
)
)
)
)
)
)
)
)
)
)
)
(mk-state (- (input-size x) 8) (+ (choice-index x) 8))
)
)
(define-fun-rec pow-2 ((amount Int)) Int
(if (<= amount 0)
1
(* 2 (pow-2 (- amount 1)))
)
)
;; see LowParse.BitFields.get_bitfield_eq
(define-fun get-bitfield-lsb ((nbBits Int) (value Int) (bitsFrom Int) (bitsTo Int)) Int
(mod (div value (pow-2 bitsFrom)) (pow-2 (- bitsTo bitsFrom)))
)
;; see EverParse3d.Prelude.StaticHeader
(define-fun get-bitfield-msb ((nbBits Int) (value Int) (bitsFrom Int) (bitsTo Int)) Int
(get-bitfield-lsb nbBits value (- nbBits bitsTo) (- nbBits bitsFrom))
)
(declare-const initial-input-size Int)
(assert (>= initial-input-size 0))
(define-fun initial-state () State (mk-state initial-input-size 0))
"
let mk_constant = function
| A.Unit -> "0"
| A.Int _ x -> string_of_int x
| A.XInt _ x -> string_of_int (OS.int_of_string x)
| A.Bool true -> "true"
| A.Bool false -> "false"
let mk_app fn = function
| None -> fn
| Some args -> Printf.sprintf "(%s %s)" fn args
let assert_some = function
| None -> failwith "assert_some"
| Some x -> x
let is_bitwise_op (x: T.op) : Tot (option A.integer_type) =
match x with
| T.BitwiseAnd a
| T.BitwiseXor a
| T.BitwiseOr a
| T.BitwiseNot a
| T.ShiftLeft a
| T.ShiftRight a
-> Some a
| _ -> None
let mk_bitwise_op (op: string) (bitvec_args: option string) : ML string =
mk_app "bv2int" (Some (mk_app op bitvec_args))
let integer_type_bit_size = function
| A.UInt8 -> 8
| A.UInt16 -> 16
| A.UInt32 -> 32
| A.UInt64 -> 64
let mk_bitwise_not (a: A.integer_type) (bitvec_arg: option string) : ML string =
match bitvec_arg with
| None -> failwith "ill-formed bitwise_not"
| Some arg -> "(bv2int (bvxor "^arg^" #b"^String.make (integer_type_bit_size a) '1'^"))"
let mk_op : T.op -> option string -> ML string = function
| T.Eq -> mk_app "="
| T.Neq -> (fun s -> mk_app "not" (Some (mk_app "=" s)))
| T.And -> mk_app "and"
| T.Or -> mk_app "or"
| T.Not -> mk_app "not"
| T.Plus _ -> mk_app "+"
| T.Minus _ -> mk_app "-"
| T.Mul _ -> mk_app "*"
| T.Division _ -> mk_app "div"
| T.Remainder _ -> mk_app "mod"
| T.BitwiseAnd _ -> mk_bitwise_op "bvand"
| T.BitwiseXor _ -> mk_bitwise_op "bvxor"
| T.BitwiseOr _ -> mk_bitwise_op "bvor"
| T.BitwiseNot a -> mk_bitwise_not a
| T.ShiftLeft _ -> mk_bitwise_op "bvshl"
| T.ShiftRight _ -> mk_bitwise_op "bvlshr"
| T.LT _ -> mk_app "<"
| T.GT _ -> mk_app ">"
| T.LE _ -> mk_app "<="
| T.GE _ -> mk_app ">="
| T.IfThenElse -> mk_app "if"
| T.BitFieldOf size order -> (fun arg -> Printf.sprintf "(get-bitfield-%ssb %d %s)" (match order with A.LSBFirst -> "l" | A.MSBFirst -> "m") size (assert_some arg))
| T.Cast _ _ -> assert_some (* casts allowed only if they are proven not to lose precision *)
| T.Ext s -> mk_app s
let ident_to_string = A.ident_to_string
let mk_bitwise_arg (t: A.integer_type) (arg: string) : Tot string =
mk_app ("(_ int2bv "^string_of_int (integer_type_bit_size t)^")") (Some arg)
let mk_maybe_bitwise_arg (t: option A.integer_type) (arg: string) : Tot string =
match t with
| None -> arg
| Some t -> mk_bitwise_arg t arg
let rec mk_expr (e: T.expr) : ML string = match fst e with
| T.Constant c -> mk_constant c
| T.Identifier i -> ident_to_string i
| T.App hd args -> mk_op hd (mk_args (is_bitwise_op hd) args)
| _ -> failwith "mk_expr: not supported"
and mk_args_aux (is_bitwise_op: option A.integer_type) accu : (list T.expr -> ML string) = function
| [] -> accu
| a :: q -> mk_args_aux is_bitwise_op (Printf.sprintf "%s %s" accu (mk_maybe_bitwise_arg is_bitwise_op (mk_expr a))) q
and mk_args (is_bitwise_op: option A.integer_type) (l: list T.expr) : ML (option string) = match l with
| [] -> None
| a :: q -> Some (mk_args_aux is_bitwise_op (mk_maybe_bitwise_arg is_bitwise_op (mk_expr a)) q)
type reading = { call: string }
type not_reading = { call: string }
type binders = {
is_empty: bool;
bind: string;
args: string;
}
let empty_binders : binders = {
is_empty = true;
bind = "";
args = "";
}
let push_binder (name: string) (typ: string) (b: binders) : binders = {
is_empty = false;
bind = Printf.sprintf "(%s %s) %s" name typ b.bind;
args = Printf.sprintf " %s%s" name b.args;
}
let mk_function_call (name: string) (b: binders) =
Printf.sprintf "%s%s" name b.args
type parser (a: Type) =
(* name *) string ->
(* binders *) binders ->
(* is_toplevel *) bool ->
(* out *) (string -> ML unit) ->
ML a
let unsupported_parser (s: string) (a: Type) : Tot (parser a) =
fun _ _ _ _ -> failwith (Printf.sprintf "unsupported parser: %s" s)
let leaf_reading_parser (name: string) : parser reading =
fun _ _ _ _ -> { call = name } | false | true | Z3TestGen.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val readable_itype_parser_suffix (i: I.itype) : Tot string | [] | Z3TestGen.readable_itype_parser_suffix | {
"file_name": "src/3d/Z3TestGen.fst",
"git_rev": "446a08ce38df905547cf20f28c43776b22b8087a",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | i: InterpreterTarget.itype -> Prims.string | {
"end_col": 29,
"end_line": 352,
"start_col": 61,
"start_line": 342
} |
FStar.All.ML | val mk_op: T.op -> option string -> ML string | [
{
"abbrev": true,
"full_module": "InterpreterTarget",
"short_module": "I"
},
{
"abbrev": true,
"full_module": "Target",
"short_module": "T"
},
{
"abbrev": true,
"full_module": "Ast",
"short_module": "A"
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.All",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.Printf",
"short_module": "Printf"
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let mk_op : T.op -> option string -> ML string = function
| T.Eq -> mk_app "="
| T.Neq -> (fun s -> mk_app "not" (Some (mk_app "=" s)))
| T.And -> mk_app "and"
| T.Or -> mk_app "or"
| T.Not -> mk_app "not"
| T.Plus _ -> mk_app "+"
| T.Minus _ -> mk_app "-"
| T.Mul _ -> mk_app "*"
| T.Division _ -> mk_app "div"
| T.Remainder _ -> mk_app "mod"
| T.BitwiseAnd _ -> mk_bitwise_op "bvand"
| T.BitwiseXor _ -> mk_bitwise_op "bvxor"
| T.BitwiseOr _ -> mk_bitwise_op "bvor"
| T.BitwiseNot a -> mk_bitwise_not a
| T.ShiftLeft _ -> mk_bitwise_op "bvshl"
| T.ShiftRight _ -> mk_bitwise_op "bvlshr"
| T.LT _ -> mk_app "<"
| T.GT _ -> mk_app ">"
| T.LE _ -> mk_app "<="
| T.GE _ -> mk_app ">="
| T.IfThenElse -> mk_app "if"
| T.BitFieldOf size order -> (fun arg -> Printf.sprintf "(get-bitfield-%ssb %d %s)" (match order with A.LSBFirst -> "l" | A.MSBFirst -> "m") size (assert_some arg))
| T.Cast _ _ -> assert_some (* casts allowed only if they are proven not to lose precision *)
| T.Ext s -> mk_app s | val mk_op: T.op -> option string -> ML string
let mk_op: T.op -> option string -> ML string = | true | null | false | function
| T.Eq -> mk_app "="
| T.Neq -> (fun s -> mk_app "not" (Some (mk_app "=" s)))
| T.And -> mk_app "and"
| T.Or -> mk_app "or"
| T.Not -> mk_app "not"
| T.Plus _ -> mk_app "+"
| T.Minus _ -> mk_app "-"
| T.Mul _ -> mk_app "*"
| T.Division _ -> mk_app "div"
| T.Remainder _ -> mk_app "mod"
| T.BitwiseAnd _ -> mk_bitwise_op "bvand"
| T.BitwiseXor _ -> mk_bitwise_op "bvxor"
| T.BitwiseOr _ -> mk_bitwise_op "bvor"
| T.BitwiseNot a -> mk_bitwise_not a
| T.ShiftLeft _ -> mk_bitwise_op "bvshl"
| T.ShiftRight _ -> mk_bitwise_op "bvlshr"
| T.LT _ -> mk_app "<"
| T.GT _ -> mk_app ">"
| T.LE _ -> mk_app "<="
| T.GE _ -> mk_app ">="
| T.IfThenElse -> mk_app "if"
| T.BitFieldOf size order ->
(fun arg ->
Printf.sprintf "(get-bitfield-%ssb %d %s)"
(match order with
| A.LSBFirst -> "l"
| A.MSBFirst -> "m")
size
(assert_some arg))
| T.Cast _ _ -> assert_some
| T.Ext s -> mk_app s | {
"checked_file": "Z3TestGen.fst.checked",
"dependencies": [
"Z3.fsti.checked",
"Target.fsti.checked",
"prims.fst.checked",
"OS.fsti.checked",
"Lisp.fsti.checked",
"InterpreterTarget.fsti.checked",
"FStar.String.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Printf.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.List.Tot.fst.checked",
"FStar.List.fst.checked",
"FStar.IO.fst.checked",
"FStar.Char.fsti.checked",
"FStar.All.fst.checked",
"Ast.fst.checked"
],
"interface_file": false,
"source_file": "Z3TestGen.fst"
} | [
"ml"
] | [
"Target.op",
"Z3TestGen.mk_app",
"FStar.Pervasives.Native.option",
"Prims.string",
"FStar.Pervasives.Native.Some",
"Ast.integer_type",
"Z3TestGen.mk_bitwise_op",
"Z3TestGen.mk_bitwise_not",
"Prims.int",
"Ast.bitfield_bit_order",
"FStar.Printf.sprintf",
"Z3TestGen.assert_some"
] | [] | module Z3TestGen
module Printf = FStar.Printf
open FStar.All
open FStar.Mul
module A = Ast
module T = Target
module I = InterpreterTarget
let prelude : string =
"
(set-option :produce-models true)
(declare-datatypes () ((State (mk-state (input-size Int) (choice-index Int)))))
(declare-datatypes () ((Result (mk-result (return-value Int) (after-state State)))))
(define-fun parse-empty ((x State)) Result
(mk-result 0 x)
)
(declare-fun choose (Int) Int)
(assert (forall ((i Int))
(and (<= 0 (choose i)) (< (choose i) 256))
))
(define-fun parse-false ((x State)) State
(mk-state -1 (choice-index x))
)
(define-fun parse-all-bytes ((x State)) State
(if (<= (input-size x) 0)
x
(mk-state 0 (+ (choice-index x) (input-size x)))
)
)
(define-fun parse-all-zeros ((x State)) State
(if (<= (input-size x) 0)
x
(mk-state
(if
(forall ((j Int))
(if (and (<= 0 j) (< j (input-size x)))
(= (choose (+ (choice-index x) j)) 0)
true
)
)
0
-1
)
(+ (choice-index x) (input-size x))
)
)
)
(define-fun parse-u8 ((x State)) Result
(mk-result
(choose (choice-index x))
(mk-state (- (input-size x) 1) (+ (choice-index x) 1))
)
)
(define-fun parse-u16-be ((x State)) Result
(mk-result
(+ (choose (+ 1 (choice-index x)))
(* 256
(choose (+ 0 (choice-index x)))
)
)
(mk-state (- (input-size x) 2) (+ (choice-index x) 2))
)
)
(define-fun parse-u16-le ((x State)) Result
(mk-result
(+ (choose (+ 0 (choice-index x)))
(* 256
(choose (+ 1 (choice-index x)))
)
)
(mk-state (- (input-size x) 2) (+ (choice-index x) 2))
)
)
(define-fun parse-u32-be ((x State)) Result
(mk-result
(+ (choose (+ 3 (choice-index x)))
(* 256
(+ (choose (+ 2 (choice-index x)))
(* 256
(+ (choose (+ 1 (choice-index x)))
(* 256
(choose (+ 0 (choice-index x)))
)
)
)
)
)
)
(mk-state (- (input-size x) 4) (+ (choice-index x) 4))
)
)
(define-fun parse-u32-le ((x State)) Result
(mk-result
(+ (choose (+ 0 (choice-index x)))
(* 256
(+ (choose (+ 1 (choice-index x)))
(* 256
(+ (choose (+ 2 (choice-index x)))
(* 256
(choose (+ 3 (choice-index x)))
)
)
)
)
)
)
(mk-state (- (input-size x) 4) (+ (choice-index x) 4))
)
)
(define-fun parse-u64-be ((x State)) Result
(mk-result
(+ (choose (+ 7 (choice-index x)))
(* 256
(+ (choose (+ 6 (choice-index x)))
(* 256
(+ (choose (+ 5 (choice-index x)))
(* 256
(+ (choose (+ 4 (choice-index x)))
(* 256
(+ (choose (+ 3 (choice-index x)))
(* 256
(+ (choose (+ 2 (choice-index x)))
(* 256
(+ (choose (+ 1 (choice-index x)))
(* 256
(choose (+ 0 (choice-index x)))
)
)
)
)
)
)
)
)
)
)
)
)
)
)
(mk-state (- (input-size x) 8) (+ (choice-index x) 8))
)
)
(define-fun parse-u64-le ((x State)) Result
(mk-result
(+ (choose (+ 0 (choice-index x)))
(* 256
(+ (choose (+ 1 (choice-index x)))
(* 256
(+ (choose (+ 2 (choice-index x)))
(* 256
(+ (choose (+ 3 (choice-index x)))
(* 256
(+ (choose (+ 4 (choice-index x)))
(* 256
(+ (choose (+ 5 (choice-index x)))
(* 256
(+ (choose (+ 6 (choice-index x)))
(* 256
(choose (+ 7 (choice-index x)))
)
)
)
)
)
)
)
)
)
)
)
)
)
)
(mk-state (- (input-size x) 8) (+ (choice-index x) 8))
)
)
(define-fun-rec pow-2 ((amount Int)) Int
(if (<= amount 0)
1
(* 2 (pow-2 (- amount 1)))
)
)
;; see LowParse.BitFields.get_bitfield_eq
(define-fun get-bitfield-lsb ((nbBits Int) (value Int) (bitsFrom Int) (bitsTo Int)) Int
(mod (div value (pow-2 bitsFrom)) (pow-2 (- bitsTo bitsFrom)))
)
;; see EverParse3d.Prelude.StaticHeader
(define-fun get-bitfield-msb ((nbBits Int) (value Int) (bitsFrom Int) (bitsTo Int)) Int
(get-bitfield-lsb nbBits value (- nbBits bitsTo) (- nbBits bitsFrom))
)
(declare-const initial-input-size Int)
(assert (>= initial-input-size 0))
(define-fun initial-state () State (mk-state initial-input-size 0))
"
let mk_constant = function
| A.Unit -> "0"
| A.Int _ x -> string_of_int x
| A.XInt _ x -> string_of_int (OS.int_of_string x)
| A.Bool true -> "true"
| A.Bool false -> "false"
let mk_app fn = function
| None -> fn
| Some args -> Printf.sprintf "(%s %s)" fn args
let assert_some = function
| None -> failwith "assert_some"
| Some x -> x
let is_bitwise_op (x: T.op) : Tot (option A.integer_type) =
match x with
| T.BitwiseAnd a
| T.BitwiseXor a
| T.BitwiseOr a
| T.BitwiseNot a
| T.ShiftLeft a
| T.ShiftRight a
-> Some a
| _ -> None
let mk_bitwise_op (op: string) (bitvec_args: option string) : ML string =
mk_app "bv2int" (Some (mk_app op bitvec_args))
let integer_type_bit_size = function
| A.UInt8 -> 8
| A.UInt16 -> 16
| A.UInt32 -> 32
| A.UInt64 -> 64
let mk_bitwise_not (a: A.integer_type) (bitvec_arg: option string) : ML string =
match bitvec_arg with
| None -> failwith "ill-formed bitwise_not"
| Some arg -> "(bv2int (bvxor "^arg^" #b"^String.make (integer_type_bit_size a) '1'^"))" | false | false | Z3TestGen.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val mk_op: T.op -> option string -> ML string | [] | Z3TestGen.mk_op | {
"file_name": "src/3d/Z3TestGen.fst",
"git_rev": "446a08ce38df905547cf20f28c43776b22b8087a",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | _: Target.op -> _: FStar.Pervasives.Native.option Prims.string -> FStar.All.ML Prims.string | {
"end_col": 23,
"end_line": 279,
"start_col": 49,
"start_line": 255
} |
FStar.All.ALL | [
{
"abbrev": true,
"full_module": "InterpreterTarget",
"short_module": "I"
},
{
"abbrev": true,
"full_module": "Target",
"short_module": "T"
},
{
"abbrev": true,
"full_module": "Ast",
"short_module": "A"
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.All",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.Printf",
"short_module": "Printf"
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let assert_some = function
| None -> failwith "assert_some"
| Some x -> x | let assert_some = | true | null | false | function
| None -> failwith "assert_some"
| Some x -> x | {
"checked_file": "Z3TestGen.fst.checked",
"dependencies": [
"Z3.fsti.checked",
"Target.fsti.checked",
"prims.fst.checked",
"OS.fsti.checked",
"Lisp.fsti.checked",
"InterpreterTarget.fsti.checked",
"FStar.String.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Printf.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.List.Tot.fst.checked",
"FStar.List.fst.checked",
"FStar.IO.fst.checked",
"FStar.Char.fsti.checked",
"FStar.All.fst.checked",
"Ast.fst.checked"
],
"interface_file": false,
"source_file": "Z3TestGen.fst"
} | [] | [
"FStar.Pervasives.Native.option",
"FStar.All.failwith"
] | [] | module Z3TestGen
module Printf = FStar.Printf
open FStar.All
open FStar.Mul
module A = Ast
module T = Target
module I = InterpreterTarget
let prelude : string =
"
(set-option :produce-models true)
(declare-datatypes () ((State (mk-state (input-size Int) (choice-index Int)))))
(declare-datatypes () ((Result (mk-result (return-value Int) (after-state State)))))
(define-fun parse-empty ((x State)) Result
(mk-result 0 x)
)
(declare-fun choose (Int) Int)
(assert (forall ((i Int))
(and (<= 0 (choose i)) (< (choose i) 256))
))
(define-fun parse-false ((x State)) State
(mk-state -1 (choice-index x))
)
(define-fun parse-all-bytes ((x State)) State
(if (<= (input-size x) 0)
x
(mk-state 0 (+ (choice-index x) (input-size x)))
)
)
(define-fun parse-all-zeros ((x State)) State
(if (<= (input-size x) 0)
x
(mk-state
(if
(forall ((j Int))
(if (and (<= 0 j) (< j (input-size x)))
(= (choose (+ (choice-index x) j)) 0)
true
)
)
0
-1
)
(+ (choice-index x) (input-size x))
)
)
)
(define-fun parse-u8 ((x State)) Result
(mk-result
(choose (choice-index x))
(mk-state (- (input-size x) 1) (+ (choice-index x) 1))
)
)
(define-fun parse-u16-be ((x State)) Result
(mk-result
(+ (choose (+ 1 (choice-index x)))
(* 256
(choose (+ 0 (choice-index x)))
)
)
(mk-state (- (input-size x) 2) (+ (choice-index x) 2))
)
)
(define-fun parse-u16-le ((x State)) Result
(mk-result
(+ (choose (+ 0 (choice-index x)))
(* 256
(choose (+ 1 (choice-index x)))
)
)
(mk-state (- (input-size x) 2) (+ (choice-index x) 2))
)
)
(define-fun parse-u32-be ((x State)) Result
(mk-result
(+ (choose (+ 3 (choice-index x)))
(* 256
(+ (choose (+ 2 (choice-index x)))
(* 256
(+ (choose (+ 1 (choice-index x)))
(* 256
(choose (+ 0 (choice-index x)))
)
)
)
)
)
)
(mk-state (- (input-size x) 4) (+ (choice-index x) 4))
)
)
(define-fun parse-u32-le ((x State)) Result
(mk-result
(+ (choose (+ 0 (choice-index x)))
(* 256
(+ (choose (+ 1 (choice-index x)))
(* 256
(+ (choose (+ 2 (choice-index x)))
(* 256
(choose (+ 3 (choice-index x)))
)
)
)
)
)
)
(mk-state (- (input-size x) 4) (+ (choice-index x) 4))
)
)
(define-fun parse-u64-be ((x State)) Result
(mk-result
(+ (choose (+ 7 (choice-index x)))
(* 256
(+ (choose (+ 6 (choice-index x)))
(* 256
(+ (choose (+ 5 (choice-index x)))
(* 256
(+ (choose (+ 4 (choice-index x)))
(* 256
(+ (choose (+ 3 (choice-index x)))
(* 256
(+ (choose (+ 2 (choice-index x)))
(* 256
(+ (choose (+ 1 (choice-index x)))
(* 256
(choose (+ 0 (choice-index x)))
)
)
)
)
)
)
)
)
)
)
)
)
)
)
(mk-state (- (input-size x) 8) (+ (choice-index x) 8))
)
)
(define-fun parse-u64-le ((x State)) Result
(mk-result
(+ (choose (+ 0 (choice-index x)))
(* 256
(+ (choose (+ 1 (choice-index x)))
(* 256
(+ (choose (+ 2 (choice-index x)))
(* 256
(+ (choose (+ 3 (choice-index x)))
(* 256
(+ (choose (+ 4 (choice-index x)))
(* 256
(+ (choose (+ 5 (choice-index x)))
(* 256
(+ (choose (+ 6 (choice-index x)))
(* 256
(choose (+ 7 (choice-index x)))
)
)
)
)
)
)
)
)
)
)
)
)
)
)
(mk-state (- (input-size x) 8) (+ (choice-index x) 8))
)
)
(define-fun-rec pow-2 ((amount Int)) Int
(if (<= amount 0)
1
(* 2 (pow-2 (- amount 1)))
)
)
;; see LowParse.BitFields.get_bitfield_eq
(define-fun get-bitfield-lsb ((nbBits Int) (value Int) (bitsFrom Int) (bitsTo Int)) Int
(mod (div value (pow-2 bitsFrom)) (pow-2 (- bitsTo bitsFrom)))
)
;; see EverParse3d.Prelude.StaticHeader
(define-fun get-bitfield-msb ((nbBits Int) (value Int) (bitsFrom Int) (bitsTo Int)) Int
(get-bitfield-lsb nbBits value (- nbBits bitsTo) (- nbBits bitsFrom))
)
(declare-const initial-input-size Int)
(assert (>= initial-input-size 0))
(define-fun initial-state () State (mk-state initial-input-size 0))
"
let mk_constant = function
| A.Unit -> "0"
| A.Int _ x -> string_of_int x
| A.XInt _ x -> string_of_int (OS.int_of_string x)
| A.Bool true -> "true"
| A.Bool false -> "false"
let mk_app fn = function
| None -> fn
| Some args -> Printf.sprintf "(%s %s)" fn args | false | false | Z3TestGen.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val assert_some : _: FStar.Pervasives.Native.option _ -> FStar.All.ALL _ | [] | Z3TestGen.assert_some | {
"file_name": "src/3d/Z3TestGen.fst",
"git_rev": "446a08ce38df905547cf20f28c43776b22b8087a",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | _: FStar.Pervasives.Native.option _ -> FStar.All.ALL _ | {
"end_col": 15,
"end_line": 228,
"start_col": 18,
"start_line": 226
} |
|
Prims.Tot | val parse_itype: I.itype -> parser not_reading | [
{
"abbrev": true,
"full_module": "InterpreterTarget",
"short_module": "I"
},
{
"abbrev": true,
"full_module": "Target",
"short_module": "T"
},
{
"abbrev": true,
"full_module": "Ast",
"short_module": "A"
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.All",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.Printf",
"short_module": "Printf"
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let parse_itype : I.itype -> parser not_reading = function
| I.AllBytes -> parse_all_bytes
| I.AllZeros -> parse_all_zeros
| i -> wrap_parser (parse_readable_itype i) | val parse_itype: I.itype -> parser not_reading
let parse_itype: I.itype -> parser not_reading = | false | null | false | function
| I.AllBytes -> parse_all_bytes
| I.AllZeros -> parse_all_zeros
| i -> wrap_parser (parse_readable_itype i) | {
"checked_file": "Z3TestGen.fst.checked",
"dependencies": [
"Z3.fsti.checked",
"Target.fsti.checked",
"prims.fst.checked",
"OS.fsti.checked",
"Lisp.fsti.checked",
"InterpreterTarget.fsti.checked",
"FStar.String.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Printf.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.List.Tot.fst.checked",
"FStar.List.fst.checked",
"FStar.IO.fst.checked",
"FStar.Char.fsti.checked",
"FStar.All.fst.checked",
"Ast.fst.checked"
],
"interface_file": false,
"source_file": "Z3TestGen.fst"
} | [
"total"
] | [
"InterpreterTarget.itype",
"Z3TestGen.parse_all_bytes",
"Z3TestGen.parse_all_zeros",
"Z3TestGen.wrap_parser",
"Z3TestGen.parse_readable_itype",
"Z3TestGen.parser",
"Z3TestGen.not_reading"
] | [] | module Z3TestGen
module Printf = FStar.Printf
open FStar.All
open FStar.Mul
module A = Ast
module T = Target
module I = InterpreterTarget
let prelude : string =
"
(set-option :produce-models true)
(declare-datatypes () ((State (mk-state (input-size Int) (choice-index Int)))))
(declare-datatypes () ((Result (mk-result (return-value Int) (after-state State)))))
(define-fun parse-empty ((x State)) Result
(mk-result 0 x)
)
(declare-fun choose (Int) Int)
(assert (forall ((i Int))
(and (<= 0 (choose i)) (< (choose i) 256))
))
(define-fun parse-false ((x State)) State
(mk-state -1 (choice-index x))
)
(define-fun parse-all-bytes ((x State)) State
(if (<= (input-size x) 0)
x
(mk-state 0 (+ (choice-index x) (input-size x)))
)
)
(define-fun parse-all-zeros ((x State)) State
(if (<= (input-size x) 0)
x
(mk-state
(if
(forall ((j Int))
(if (and (<= 0 j) (< j (input-size x)))
(= (choose (+ (choice-index x) j)) 0)
true
)
)
0
-1
)
(+ (choice-index x) (input-size x))
)
)
)
(define-fun parse-u8 ((x State)) Result
(mk-result
(choose (choice-index x))
(mk-state (- (input-size x) 1) (+ (choice-index x) 1))
)
)
(define-fun parse-u16-be ((x State)) Result
(mk-result
(+ (choose (+ 1 (choice-index x)))
(* 256
(choose (+ 0 (choice-index x)))
)
)
(mk-state (- (input-size x) 2) (+ (choice-index x) 2))
)
)
(define-fun parse-u16-le ((x State)) Result
(mk-result
(+ (choose (+ 0 (choice-index x)))
(* 256
(choose (+ 1 (choice-index x)))
)
)
(mk-state (- (input-size x) 2) (+ (choice-index x) 2))
)
)
(define-fun parse-u32-be ((x State)) Result
(mk-result
(+ (choose (+ 3 (choice-index x)))
(* 256
(+ (choose (+ 2 (choice-index x)))
(* 256
(+ (choose (+ 1 (choice-index x)))
(* 256
(choose (+ 0 (choice-index x)))
)
)
)
)
)
)
(mk-state (- (input-size x) 4) (+ (choice-index x) 4))
)
)
(define-fun parse-u32-le ((x State)) Result
(mk-result
(+ (choose (+ 0 (choice-index x)))
(* 256
(+ (choose (+ 1 (choice-index x)))
(* 256
(+ (choose (+ 2 (choice-index x)))
(* 256
(choose (+ 3 (choice-index x)))
)
)
)
)
)
)
(mk-state (- (input-size x) 4) (+ (choice-index x) 4))
)
)
(define-fun parse-u64-be ((x State)) Result
(mk-result
(+ (choose (+ 7 (choice-index x)))
(* 256
(+ (choose (+ 6 (choice-index x)))
(* 256
(+ (choose (+ 5 (choice-index x)))
(* 256
(+ (choose (+ 4 (choice-index x)))
(* 256
(+ (choose (+ 3 (choice-index x)))
(* 256
(+ (choose (+ 2 (choice-index x)))
(* 256
(+ (choose (+ 1 (choice-index x)))
(* 256
(choose (+ 0 (choice-index x)))
)
)
)
)
)
)
)
)
)
)
)
)
)
)
(mk-state (- (input-size x) 8) (+ (choice-index x) 8))
)
)
(define-fun parse-u64-le ((x State)) Result
(mk-result
(+ (choose (+ 0 (choice-index x)))
(* 256
(+ (choose (+ 1 (choice-index x)))
(* 256
(+ (choose (+ 2 (choice-index x)))
(* 256
(+ (choose (+ 3 (choice-index x)))
(* 256
(+ (choose (+ 4 (choice-index x)))
(* 256
(+ (choose (+ 5 (choice-index x)))
(* 256
(+ (choose (+ 6 (choice-index x)))
(* 256
(choose (+ 7 (choice-index x)))
)
)
)
)
)
)
)
)
)
)
)
)
)
)
(mk-state (- (input-size x) 8) (+ (choice-index x) 8))
)
)
(define-fun-rec pow-2 ((amount Int)) Int
(if (<= amount 0)
1
(* 2 (pow-2 (- amount 1)))
)
)
;; see LowParse.BitFields.get_bitfield_eq
(define-fun get-bitfield-lsb ((nbBits Int) (value Int) (bitsFrom Int) (bitsTo Int)) Int
(mod (div value (pow-2 bitsFrom)) (pow-2 (- bitsTo bitsFrom)))
)
;; see EverParse3d.Prelude.StaticHeader
(define-fun get-bitfield-msb ((nbBits Int) (value Int) (bitsFrom Int) (bitsTo Int)) Int
(get-bitfield-lsb nbBits value (- nbBits bitsTo) (- nbBits bitsFrom))
)
(declare-const initial-input-size Int)
(assert (>= initial-input-size 0))
(define-fun initial-state () State (mk-state initial-input-size 0))
"
let mk_constant = function
| A.Unit -> "0"
| A.Int _ x -> string_of_int x
| A.XInt _ x -> string_of_int (OS.int_of_string x)
| A.Bool true -> "true"
| A.Bool false -> "false"
let mk_app fn = function
| None -> fn
| Some args -> Printf.sprintf "(%s %s)" fn args
let assert_some = function
| None -> failwith "assert_some"
| Some x -> x
let is_bitwise_op (x: T.op) : Tot (option A.integer_type) =
match x with
| T.BitwiseAnd a
| T.BitwiseXor a
| T.BitwiseOr a
| T.BitwiseNot a
| T.ShiftLeft a
| T.ShiftRight a
-> Some a
| _ -> None
let mk_bitwise_op (op: string) (bitvec_args: option string) : ML string =
mk_app "bv2int" (Some (mk_app op bitvec_args))
let integer_type_bit_size = function
| A.UInt8 -> 8
| A.UInt16 -> 16
| A.UInt32 -> 32
| A.UInt64 -> 64
let mk_bitwise_not (a: A.integer_type) (bitvec_arg: option string) : ML string =
match bitvec_arg with
| None -> failwith "ill-formed bitwise_not"
| Some arg -> "(bv2int (bvxor "^arg^" #b"^String.make (integer_type_bit_size a) '1'^"))"
let mk_op : T.op -> option string -> ML string = function
| T.Eq -> mk_app "="
| T.Neq -> (fun s -> mk_app "not" (Some (mk_app "=" s)))
| T.And -> mk_app "and"
| T.Or -> mk_app "or"
| T.Not -> mk_app "not"
| T.Plus _ -> mk_app "+"
| T.Minus _ -> mk_app "-"
| T.Mul _ -> mk_app "*"
| T.Division _ -> mk_app "div"
| T.Remainder _ -> mk_app "mod"
| T.BitwiseAnd _ -> mk_bitwise_op "bvand"
| T.BitwiseXor _ -> mk_bitwise_op "bvxor"
| T.BitwiseOr _ -> mk_bitwise_op "bvor"
| T.BitwiseNot a -> mk_bitwise_not a
| T.ShiftLeft _ -> mk_bitwise_op "bvshl"
| T.ShiftRight _ -> mk_bitwise_op "bvlshr"
| T.LT _ -> mk_app "<"
| T.GT _ -> mk_app ">"
| T.LE _ -> mk_app "<="
| T.GE _ -> mk_app ">="
| T.IfThenElse -> mk_app "if"
| T.BitFieldOf size order -> (fun arg -> Printf.sprintf "(get-bitfield-%ssb %d %s)" (match order with A.LSBFirst -> "l" | A.MSBFirst -> "m") size (assert_some arg))
| T.Cast _ _ -> assert_some (* casts allowed only if they are proven not to lose precision *)
| T.Ext s -> mk_app s
let ident_to_string = A.ident_to_string
let mk_bitwise_arg (t: A.integer_type) (arg: string) : Tot string =
mk_app ("(_ int2bv "^string_of_int (integer_type_bit_size t)^")") (Some arg)
let mk_maybe_bitwise_arg (t: option A.integer_type) (arg: string) : Tot string =
match t with
| None -> arg
| Some t -> mk_bitwise_arg t arg
let rec mk_expr (e: T.expr) : ML string = match fst e with
| T.Constant c -> mk_constant c
| T.Identifier i -> ident_to_string i
| T.App hd args -> mk_op hd (mk_args (is_bitwise_op hd) args)
| _ -> failwith "mk_expr: not supported"
and mk_args_aux (is_bitwise_op: option A.integer_type) accu : (list T.expr -> ML string) = function
| [] -> accu
| a :: q -> mk_args_aux is_bitwise_op (Printf.sprintf "%s %s" accu (mk_maybe_bitwise_arg is_bitwise_op (mk_expr a))) q
and mk_args (is_bitwise_op: option A.integer_type) (l: list T.expr) : ML (option string) = match l with
| [] -> None
| a :: q -> Some (mk_args_aux is_bitwise_op (mk_maybe_bitwise_arg is_bitwise_op (mk_expr a)) q)
type reading = { call: string }
type not_reading = { call: string }
type binders = {
is_empty: bool;
bind: string;
args: string;
}
let empty_binders : binders = {
is_empty = true;
bind = "";
args = "";
}
let push_binder (name: string) (typ: string) (b: binders) : binders = {
is_empty = false;
bind = Printf.sprintf "(%s %s) %s" name typ b.bind;
args = Printf.sprintf " %s%s" name b.args;
}
let mk_function_call (name: string) (b: binders) =
Printf.sprintf "%s%s" name b.args
type parser (a: Type) =
(* name *) string ->
(* binders *) binders ->
(* is_toplevel *) bool ->
(* out *) (string -> ML unit) ->
ML a
let unsupported_parser (s: string) (a: Type) : Tot (parser a) =
fun _ _ _ _ -> failwith (Printf.sprintf "unsupported parser: %s" s)
let leaf_reading_parser (name: string) : parser reading =
fun _ _ _ _ -> { call = name }
let readable_itype_parser_suffix (i: I.itype) : Tot string = match i with
| I.UInt8 | I.UInt8BE -> "u8"
| I.UInt16 -> "u16-le"
| I.UInt16BE -> "u16-be"
| I.UInt32 -> "u32-le"
| I.UInt32BE -> "u32-be"
| I.UInt64 -> "u64-le"
| I.UInt64BE -> "u64-be"
| I.Unit -> "empty"
| I.AllBytes -> "all-bytes"
| I.AllZeros -> "all-zeros"
let parse_readable_itype (i: I.readable_itype) : Tot (parser reading) =
leaf_reading_parser ("parse-" ^ readable_itype_parser_suffix i)
let mk_wrap_parser
(name: string)
(binders: string)
(body: string)
: string
= let input = Printf.sprintf "%s-input" name in
let tmp = Printf.sprintf "%s-tmp" name in
"(define-fun "^name^" ("^binders^"("^input^" State)) State
(after-state ("^body^" "^input^"))
)
"
let wrap_parser (p: parser reading) : parser not_reading =
fun name binders _ out ->
let name' = Printf.sprintf "%s-wrapped" name in
let body = p name' binders false out in
out (mk_wrap_parser name binders.bind body.call);
{ call = mk_function_call name binders }
let mk_toplevel_parser
(name: string)
(binders: string)
(body: string)
: string
= let input = Printf.sprintf "%s-input" name in
"(define-fun "^name^" ("^binders^"("^input^" State)) State
("^body^" "^input^")
)
"
let maybe_toplevel_parser (p: parser not_reading) : parser not_reading =
fun name binders is_toplevel out ->
if is_toplevel
then begin
let name' = Printf.sprintf "%s-body" name in
let body = p name' binders false out in
out (mk_toplevel_parser name binders.bind body.call);
{ call = mk_function_call name binders }
end
else p name binders false out
let parse_all_bytes : parser not_reading =
maybe_toplevel_parser (fun _ _ _ _ -> { call = "parse-all-bytes" })
let parse_all_zeros : parser not_reading =
maybe_toplevel_parser (fun _ _ _ _ -> { call = "parse-all-zeros" }) | false | true | Z3TestGen.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val parse_itype: I.itype -> parser not_reading | [] | Z3TestGen.parse_itype | {
"file_name": "src/3d/Z3TestGen.fst",
"git_rev": "446a08ce38df905547cf20f28c43776b22b8087a",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | _: InterpreterTarget.itype -> Z3TestGen.parser Z3TestGen.not_reading | {
"end_col": 45,
"end_line": 407,
"start_col": 51,
"start_line": 404
} |
Prims.Tot | val arg_type_of_typ (t: T.typ) : Tot (option arg_type) | [
{
"abbrev": true,
"full_module": "InterpreterTarget",
"short_module": "I"
},
{
"abbrev": true,
"full_module": "Target",
"short_module": "T"
},
{
"abbrev": true,
"full_module": "Ast",
"short_module": "A"
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.All",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.Printf",
"short_module": "Printf"
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let arg_type_of_typ (t: T.typ) : Tot (option arg_type) =
match t with
| T.T_pointer _
| T.T_app _ A.KindOutput _
| T.T_app _ A.KindExtern _
| T.T_app {v = {modul_name = None; name = "PUINT8"}} _ _
-> Some ArgPointer
| T.T_app {v = {modul_name = None; name = "Bool"}} _ _
-> Some ArgBool
| T.T_app i _ _
->
begin match A.maybe_as_integer_typ i with
| Some t -> Some (ArgInt t)
| None -> None
end
| _ -> None | val arg_type_of_typ (t: T.typ) : Tot (option arg_type)
let arg_type_of_typ (t: T.typ) : Tot (option arg_type) = | false | null | false | match t with
| T.T_pointer _
| T.T_app _ A.KindOutput _
| T.T_app _ A.KindExtern _
| T.T_app { v = { modul_name = None ; name = "PUINT8" } } _ _ -> Some ArgPointer
| T.T_app { v = { modul_name = None ; name = "Bool" } } _ _ -> Some ArgBool
| T.T_app i _ _ ->
(match A.maybe_as_integer_typ i with
| Some t -> Some (ArgInt t)
| None -> None)
| _ -> None | {
"checked_file": "Z3TestGen.fst.checked",
"dependencies": [
"Z3.fsti.checked",
"Target.fsti.checked",
"prims.fst.checked",
"OS.fsti.checked",
"Lisp.fsti.checked",
"InterpreterTarget.fsti.checked",
"FStar.String.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Printf.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.List.Tot.fst.checked",
"FStar.List.fst.checked",
"FStar.IO.fst.checked",
"FStar.Char.fsti.checked",
"FStar.All.fst.checked",
"Ast.fst.checked"
],
"interface_file": false,
"source_file": "Z3TestGen.fst"
} | [
"total"
] | [
"Target.typ",
"FStar.Pervasives.Native.Some",
"Z3TestGen.arg_type",
"Z3TestGen.ArgPointer",
"Ast.ident",
"Prims.list",
"FStar.Pervasives.either",
"Target.expr",
"Ast.range",
"Ast.comments",
"Ast.t_kind",
"Z3TestGen.ArgBool",
"Ast.maybe_as_integer_typ",
"Ast.integer_type",
"Z3TestGen.ArgInt",
"FStar.Pervasives.Native.None",
"FStar.Pervasives.Native.option"
] | [] | module Z3TestGen
module Printf = FStar.Printf
open FStar.All
open FStar.Mul
module A = Ast
module T = Target
module I = InterpreterTarget
let prelude : string =
"
(set-option :produce-models true)
(declare-datatypes () ((State (mk-state (input-size Int) (choice-index Int)))))
(declare-datatypes () ((Result (mk-result (return-value Int) (after-state State)))))
(define-fun parse-empty ((x State)) Result
(mk-result 0 x)
)
(declare-fun choose (Int) Int)
(assert (forall ((i Int))
(and (<= 0 (choose i)) (< (choose i) 256))
))
(define-fun parse-false ((x State)) State
(mk-state -1 (choice-index x))
)
(define-fun parse-all-bytes ((x State)) State
(if (<= (input-size x) 0)
x
(mk-state 0 (+ (choice-index x) (input-size x)))
)
)
(define-fun parse-all-zeros ((x State)) State
(if (<= (input-size x) 0)
x
(mk-state
(if
(forall ((j Int))
(if (and (<= 0 j) (< j (input-size x)))
(= (choose (+ (choice-index x) j)) 0)
true
)
)
0
-1
)
(+ (choice-index x) (input-size x))
)
)
)
(define-fun parse-u8 ((x State)) Result
(mk-result
(choose (choice-index x))
(mk-state (- (input-size x) 1) (+ (choice-index x) 1))
)
)
(define-fun parse-u16-be ((x State)) Result
(mk-result
(+ (choose (+ 1 (choice-index x)))
(* 256
(choose (+ 0 (choice-index x)))
)
)
(mk-state (- (input-size x) 2) (+ (choice-index x) 2))
)
)
(define-fun parse-u16-le ((x State)) Result
(mk-result
(+ (choose (+ 0 (choice-index x)))
(* 256
(choose (+ 1 (choice-index x)))
)
)
(mk-state (- (input-size x) 2) (+ (choice-index x) 2))
)
)
(define-fun parse-u32-be ((x State)) Result
(mk-result
(+ (choose (+ 3 (choice-index x)))
(* 256
(+ (choose (+ 2 (choice-index x)))
(* 256
(+ (choose (+ 1 (choice-index x)))
(* 256
(choose (+ 0 (choice-index x)))
)
)
)
)
)
)
(mk-state (- (input-size x) 4) (+ (choice-index x) 4))
)
)
(define-fun parse-u32-le ((x State)) Result
(mk-result
(+ (choose (+ 0 (choice-index x)))
(* 256
(+ (choose (+ 1 (choice-index x)))
(* 256
(+ (choose (+ 2 (choice-index x)))
(* 256
(choose (+ 3 (choice-index x)))
)
)
)
)
)
)
(mk-state (- (input-size x) 4) (+ (choice-index x) 4))
)
)
(define-fun parse-u64-be ((x State)) Result
(mk-result
(+ (choose (+ 7 (choice-index x)))
(* 256
(+ (choose (+ 6 (choice-index x)))
(* 256
(+ (choose (+ 5 (choice-index x)))
(* 256
(+ (choose (+ 4 (choice-index x)))
(* 256
(+ (choose (+ 3 (choice-index x)))
(* 256
(+ (choose (+ 2 (choice-index x)))
(* 256
(+ (choose (+ 1 (choice-index x)))
(* 256
(choose (+ 0 (choice-index x)))
)
)
)
)
)
)
)
)
)
)
)
)
)
)
(mk-state (- (input-size x) 8) (+ (choice-index x) 8))
)
)
(define-fun parse-u64-le ((x State)) Result
(mk-result
(+ (choose (+ 0 (choice-index x)))
(* 256
(+ (choose (+ 1 (choice-index x)))
(* 256
(+ (choose (+ 2 (choice-index x)))
(* 256
(+ (choose (+ 3 (choice-index x)))
(* 256
(+ (choose (+ 4 (choice-index x)))
(* 256
(+ (choose (+ 5 (choice-index x)))
(* 256
(+ (choose (+ 6 (choice-index x)))
(* 256
(choose (+ 7 (choice-index x)))
)
)
)
)
)
)
)
)
)
)
)
)
)
)
(mk-state (- (input-size x) 8) (+ (choice-index x) 8))
)
)
(define-fun-rec pow-2 ((amount Int)) Int
(if (<= amount 0)
1
(* 2 (pow-2 (- amount 1)))
)
)
;; see LowParse.BitFields.get_bitfield_eq
(define-fun get-bitfield-lsb ((nbBits Int) (value Int) (bitsFrom Int) (bitsTo Int)) Int
(mod (div value (pow-2 bitsFrom)) (pow-2 (- bitsTo bitsFrom)))
)
;; see EverParse3d.Prelude.StaticHeader
(define-fun get-bitfield-msb ((nbBits Int) (value Int) (bitsFrom Int) (bitsTo Int)) Int
(get-bitfield-lsb nbBits value (- nbBits bitsTo) (- nbBits bitsFrom))
)
(declare-const initial-input-size Int)
(assert (>= initial-input-size 0))
(define-fun initial-state () State (mk-state initial-input-size 0))
"
let mk_constant = function
| A.Unit -> "0"
| A.Int _ x -> string_of_int x
| A.XInt _ x -> string_of_int (OS.int_of_string x)
| A.Bool true -> "true"
| A.Bool false -> "false"
let mk_app fn = function
| None -> fn
| Some args -> Printf.sprintf "(%s %s)" fn args
let assert_some = function
| None -> failwith "assert_some"
| Some x -> x
let is_bitwise_op (x: T.op) : Tot (option A.integer_type) =
match x with
| T.BitwiseAnd a
| T.BitwiseXor a
| T.BitwiseOr a
| T.BitwiseNot a
| T.ShiftLeft a
| T.ShiftRight a
-> Some a
| _ -> None
let mk_bitwise_op (op: string) (bitvec_args: option string) : ML string =
mk_app "bv2int" (Some (mk_app op bitvec_args))
let integer_type_bit_size = function
| A.UInt8 -> 8
| A.UInt16 -> 16
| A.UInt32 -> 32
| A.UInt64 -> 64
let mk_bitwise_not (a: A.integer_type) (bitvec_arg: option string) : ML string =
match bitvec_arg with
| None -> failwith "ill-formed bitwise_not"
| Some arg -> "(bv2int (bvxor "^arg^" #b"^String.make (integer_type_bit_size a) '1'^"))"
let mk_op : T.op -> option string -> ML string = function
| T.Eq -> mk_app "="
| T.Neq -> (fun s -> mk_app "not" (Some (mk_app "=" s)))
| T.And -> mk_app "and"
| T.Or -> mk_app "or"
| T.Not -> mk_app "not"
| T.Plus _ -> mk_app "+"
| T.Minus _ -> mk_app "-"
| T.Mul _ -> mk_app "*"
| T.Division _ -> mk_app "div"
| T.Remainder _ -> mk_app "mod"
| T.BitwiseAnd _ -> mk_bitwise_op "bvand"
| T.BitwiseXor _ -> mk_bitwise_op "bvxor"
| T.BitwiseOr _ -> mk_bitwise_op "bvor"
| T.BitwiseNot a -> mk_bitwise_not a
| T.ShiftLeft _ -> mk_bitwise_op "bvshl"
| T.ShiftRight _ -> mk_bitwise_op "bvlshr"
| T.LT _ -> mk_app "<"
| T.GT _ -> mk_app ">"
| T.LE _ -> mk_app "<="
| T.GE _ -> mk_app ">="
| T.IfThenElse -> mk_app "if"
| T.BitFieldOf size order -> (fun arg -> Printf.sprintf "(get-bitfield-%ssb %d %s)" (match order with A.LSBFirst -> "l" | A.MSBFirst -> "m") size (assert_some arg))
| T.Cast _ _ -> assert_some (* casts allowed only if they are proven not to lose precision *)
| T.Ext s -> mk_app s
let ident_to_string = A.ident_to_string
let mk_bitwise_arg (t: A.integer_type) (arg: string) : Tot string =
mk_app ("(_ int2bv "^string_of_int (integer_type_bit_size t)^")") (Some arg)
let mk_maybe_bitwise_arg (t: option A.integer_type) (arg: string) : Tot string =
match t with
| None -> arg
| Some t -> mk_bitwise_arg t arg
let rec mk_expr (e: T.expr) : ML string = match fst e with
| T.Constant c -> mk_constant c
| T.Identifier i -> ident_to_string i
| T.App hd args -> mk_op hd (mk_args (is_bitwise_op hd) args)
| _ -> failwith "mk_expr: not supported"
and mk_args_aux (is_bitwise_op: option A.integer_type) accu : (list T.expr -> ML string) = function
| [] -> accu
| a :: q -> mk_args_aux is_bitwise_op (Printf.sprintf "%s %s" accu (mk_maybe_bitwise_arg is_bitwise_op (mk_expr a))) q
and mk_args (is_bitwise_op: option A.integer_type) (l: list T.expr) : ML (option string) = match l with
| [] -> None
| a :: q -> Some (mk_args_aux is_bitwise_op (mk_maybe_bitwise_arg is_bitwise_op (mk_expr a)) q)
type reading = { call: string }
type not_reading = { call: string }
type binders = {
is_empty: bool;
bind: string;
args: string;
}
let empty_binders : binders = {
is_empty = true;
bind = "";
args = "";
}
let push_binder (name: string) (typ: string) (b: binders) : binders = {
is_empty = false;
bind = Printf.sprintf "(%s %s) %s" name typ b.bind;
args = Printf.sprintf " %s%s" name b.args;
}
let mk_function_call (name: string) (b: binders) =
Printf.sprintf "%s%s" name b.args
type parser (a: Type) =
(* name *) string ->
(* binders *) binders ->
(* is_toplevel *) bool ->
(* out *) (string -> ML unit) ->
ML a
let unsupported_parser (s: string) (a: Type) : Tot (parser a) =
fun _ _ _ _ -> failwith (Printf.sprintf "unsupported parser: %s" s)
let leaf_reading_parser (name: string) : parser reading =
fun _ _ _ _ -> { call = name }
let readable_itype_parser_suffix (i: I.itype) : Tot string = match i with
| I.UInt8 | I.UInt8BE -> "u8"
| I.UInt16 -> "u16-le"
| I.UInt16BE -> "u16-be"
| I.UInt32 -> "u32-le"
| I.UInt32BE -> "u32-be"
| I.UInt64 -> "u64-le"
| I.UInt64BE -> "u64-be"
| I.Unit -> "empty"
| I.AllBytes -> "all-bytes"
| I.AllZeros -> "all-zeros"
let parse_readable_itype (i: I.readable_itype) : Tot (parser reading) =
leaf_reading_parser ("parse-" ^ readable_itype_parser_suffix i)
let mk_wrap_parser
(name: string)
(binders: string)
(body: string)
: string
= let input = Printf.sprintf "%s-input" name in
let tmp = Printf.sprintf "%s-tmp" name in
"(define-fun "^name^" ("^binders^"("^input^" State)) State
(after-state ("^body^" "^input^"))
)
"
let wrap_parser (p: parser reading) : parser not_reading =
fun name binders _ out ->
let name' = Printf.sprintf "%s-wrapped" name in
let body = p name' binders false out in
out (mk_wrap_parser name binders.bind body.call);
{ call = mk_function_call name binders }
let mk_toplevel_parser
(name: string)
(binders: string)
(body: string)
: string
= let input = Printf.sprintf "%s-input" name in
"(define-fun "^name^" ("^binders^"("^input^" State)) State
("^body^" "^input^")
)
"
let maybe_toplevel_parser (p: parser not_reading) : parser not_reading =
fun name binders is_toplevel out ->
if is_toplevel
then begin
let name' = Printf.sprintf "%s-body" name in
let body = p name' binders false out in
out (mk_toplevel_parser name binders.bind body.call);
{ call = mk_function_call name binders }
end
else p name binders false out
let parse_all_bytes : parser not_reading =
maybe_toplevel_parser (fun _ _ _ _ -> { call = "parse-all-bytes" })
let parse_all_zeros : parser not_reading =
maybe_toplevel_parser (fun _ _ _ _ -> { call = "parse-all-zeros" })
let parse_itype : I.itype -> parser not_reading = function
| I.AllBytes -> parse_all_bytes
| I.AllZeros -> parse_all_zeros
| i -> wrap_parser (parse_readable_itype i)
let mk_app_without_paren id args =
mk_args_aux None (ident_to_string id) args
let parse_readable_app
(hd: A.ident)
(args: list I.expr)
: Tot (parser reading)
= fun _ _ _ _ -> { call = mk_app_without_paren hd args }
let parse_readable_dtyp
(d: I.readable_dtyp)
: Tot (parser reading)
= match d with
| I.DT_IType i -> parse_readable_itype i
| I.DT_App _ hd args -> parse_readable_app hd args
let parse_not_readable_app
(hd: A.ident)
(args: list I.expr)
: Tot (parser not_reading)
= maybe_toplevel_parser (fun _ _ _ _ -> { call = mk_app_without_paren hd args })
let parse_dtyp
(d: I.dtyp)
: Tot (parser not_reading)
= if I.allow_reader_of_dtyp d
then wrap_parser (parse_readable_dtyp d)
else match d with
| I.DT_IType i -> parse_itype i
| I.DT_App _ hd args -> parse_not_readable_app hd args
let parse_false : parser not_reading =
maybe_toplevel_parser (fun _ _ _ _ -> { call = "parse-false" })
let parse_denoted (d: I.dtyp) : parser not_reading =
parse_dtyp d
let mk_parse_pair
(name: string)
(binders: string)
(fst: string)
(snd: string)
: string
= let input = Printf.sprintf "%s-input" name in
let tmp = Printf.sprintf "%s-tmp" name in
"(define-fun "^name^" ("^binders^"("^input^" State)) State
(let (("^tmp^" ("^fst^" "^input^")))
(if (< (input-size "^tmp^") 0)
"^tmp^"
("^snd^" "^tmp^")
)
)
)
"
let parse_pair (fst: parser not_reading) (snd: parser not_reading) : parser not_reading =
fun name binders _ out ->
let name_fst = Printf.sprintf "%s-fst" name in
let body_fst = fst name_fst binders false out in
let name_snd = Printf.sprintf "%s-snd" name in
let body_snd = snd name_snd binders false out in
out (mk_parse_pair name binders.bind body_fst.call body_snd.call);
{ call = mk_function_call name binders }
let parse_square (p: parser not_reading) : parser not_reading =
fun name binders _ out ->
let body_name = Printf.sprintf "%s-snd" name in
let body = p body_name binders false out in
out (mk_parse_pair name binders.bind body.call body.call);
{ call = mk_function_call name binders }
let mk_parse_dep_pair_with_refinement
(name: string)
(binders: string)
(dfst: string)
(cond_binder_name: string)
(cond: string)
(dsnd_binder_name: string)
(dsnd: string) (* already contains the new argument *)
: string
= let input = Printf.sprintf "%s-input" name in
let tmp = Printf.sprintf "%s-tmp" name in
"(define-fun "^name^" ("^binders^"("^input^" State)) State
(let (("^tmp^" ("^dfst^" "^input^")))
(if (< (input-size (after-state "^tmp^")) 0)
(after-state "^tmp^")
(if (let (("^cond_binder_name^" (return-value "^tmp^"))) "^cond^")
(let (("^dsnd_binder_name^" (return-value "^tmp^")))
("^dsnd^" (after-state "^tmp^"))
)
(mk-state -1 (choice-index (after-state "^tmp^")))
)
)
)
)
"
let parse_dep_pair_with_refinement_gen (tag: parser reading) (cond_binder: string) (cond: unit -> ML string) (payload_binder: string) (payload: parser not_reading) : parser not_reading =
fun name binders _ out ->
let name_tag = Printf.sprintf "%s-tag" name in
let body_tag = tag name_tag binders false out in
let binders' = push_binder payload_binder "Int" binders in (* TODO: support more types *)
let name_payload = Printf.sprintf "%s-payload" name in
let body_payload = payload name_payload binders' false out in
out (mk_parse_dep_pair_with_refinement name binders.bind body_tag.call cond_binder (cond ()) payload_binder body_payload.call);
{ call = mk_function_call name binders }
let parse_dep_pair_with_refinement (tag: parser reading) (cond_binder: A.ident) (cond: unit -> ML string) (payload_binder: A.ident) (payload: parser not_reading) : parser not_reading =
parse_dep_pair_with_refinement_gen tag (ident_to_string cond_binder) cond (ident_to_string payload_binder) payload
let parse_dep_pair (tag: parser reading) (new_binder: A.ident) (payload: parser not_reading) : parser not_reading =
parse_dep_pair_with_refinement tag new_binder (fun _ -> "true") new_binder payload
let parse_refine (tag: parser reading) (cond_binder: A.ident) (cond: unit -> ML string) : parser not_reading =
parse_dep_pair_with_refinement tag cond_binder cond cond_binder (parse_itype I.Unit)
let mk_parse_ifthenelse
(name: string)
(binders: string)
(cond: string)
(f_then: string)
(f_else: string)
: string
= let input = Printf.sprintf "%s-input" name in
"(define-fun "^name^" ("^binders^"("^input^" State)) State
(if "^cond^"
("^f_then^" "^input^")
("^f_else^" "^input^")
)
)
"
let parse_ifthenelse (cond: unit -> ML string) (pthen: parser not_reading) (pelse: parser not_reading) : parser not_reading =
fun name binders _ out ->
let name_then = Printf.sprintf "%s-then" name in
let body_then = pthen name_then binders false out in
let name_else = Printf.sprintf "%s-else" name in
let body_else = pelse name_else binders false out in
out (mk_parse_ifthenelse name binders.bind (cond ()) body_then.call body_else.call);
{ call = mk_function_call name binders }
let mk_parse_exact
(name: string)
(binders: string)
(body: string)
(size: string)
: string
= let input = Printf.sprintf "%s-input" name in
let sz = Printf.sprintf "%s-size" name in
let res = Printf.sprintf "%s-res" name in
"(define-fun "^name^" ("^binders^"("^input^" State)) State
(let (("^sz^" "^size^"))
(if (< (input-size "^input^") "^sz^")
(mk-state -1 (choice-index "^input^"))
(let (("^res^" ("^body^" (mk-state "^sz^" (choice-index "^input^")))))
(mk-state
(if (= (input-size "^res^") 0)
(- (input-size "^input^") "^sz^")
-1
)
(choice-index "^res^")
)
)
)
)
)
"
let parse_exact
(size: unit -> ML string)
(body: parser not_reading)
: Tot (parser not_reading)
= fun name binders _ out ->
let body_name = Printf.sprintf "%s-body" name in
let body = body body_name binders false out in
out (mk_parse_exact name binders.bind body.call (size ()));
{ call = mk_function_call name binders }
let parse_at_most
(size: unit -> ML string)
(body: parser not_reading)
: Tot (parser not_reading)
= parse_exact size (parse_pair body parse_all_bytes)
(*
let mk_parse_list_one
(name: string)
(binders: string)
(p: string)
: string
= let input = Printf.sprintf "%s-input" name in
let res = Printf.sprintf "%s-res" name in
"(define-fun "^name^" ("^binders^"("^input^" (Seq Int))) (Seq Int)
(if (= (seq.len "^input^") 0)
(seq.unit 0)
(let (("^res^" ("^p^" "^input^")))
(if (= (seq.len "^res^") 0)
(as seq.empty (Seq Int))
(if (= (seq.nth "^res^" 0) 0)
(as seq.empty (Seq Int))
"^res^"
)
)
)
)
)
"
let parse_list_one
(body: parser not_reading)
: Tot (parser not_reading)
= fun name binders _ out ->
let body_name = Printf.sprintf "%s-body" name in
let body = body body_name binders false out in
out (mk_parse_list_one name binders.bind body.call);
{ call = mk_function_call name binders }
let rec parse_list_bounded'
(body: parser not_reading)
(logn: nat)
: Tot (parser not_reading)
(decreases logn)
= if logn = 0
then parse_list_one body
else
let logn' = logn - 1 in
parse_square (parse_list_bounded' body logn')
let parse_list_bounded body = parse_list_bounded' body 3 // 64
*)
let mk_parse_list
(name: string)
(rec_call: string)
(binders: string)
(body: string)
: string
= let input = Printf.sprintf "%s-input" name in
"(define-fun-rec "^name^" ("^binders^"("^input^" State)) State
(if (<= (input-size "^input^") 0)
"^input^"
("^rec_call^" ("^body^" "^input^"))
)
)
"
let parse_list
(body: parser not_reading)
: Tot (parser not_reading)
= fun name binders _ out ->
let rec_call = mk_function_call name binders in
let body_name = Printf.sprintf "%s-body" name in
let body = body body_name binders false out in
out (mk_parse_list name rec_call binders.bind body.call);
{ call = rec_call }
let parse_nlist
(size: unit -> ML string)
(body: parser not_reading)
: Tot (parser not_reading)
= parse_exact size (parse_list body)
let mk_parse_string
(name: string)
(rec_call: string)
(binders: string)
(body: string)
(terminator: string)
: string
= let input = Printf.sprintf "%s-input" name in
let tmp = Printf.sprintf "%s-tmp" name in
"(define-fun-rec "^name^" ("^binders^"("^input^" State)) State
(let (("^tmp^" ("^body^" "^input^")))
(if (< (choice-index (after-state "^tmp^")) 0)
(mk-state -1 (choice-index (after-state "^tmp^")))
(if (= (return-value "^tmp^") "^terminator^")
(after-state "^tmp^")
("^rec_call^" (after-state "^tmp^"))
)
)
)
)
"
let parse_string
(body: parser reading)
(terminator: (unit -> ML string))
: Tot (parser not_reading)
= fun name binders _ out ->
let rec_call = mk_function_call name binders in
let body_name = Printf.sprintf "%s-body" name in
let body = body body_name binders false out in
out (mk_parse_string name rec_call binders.bind body.call (terminator ()));
{ call = rec_call }
let rec type_has_actions = function
| I.T_with_dep_action _ _ _
| I.T_dep_pair_with_action _ _ _ _
| I.T_refine_with_action _ _ _ _
| I.T_dep_pair_with_refinement_and_action _ _ _ _ _
| I.T_with_action _ _ _
-> true
| I.T_false _
| I.T_denoted _ _
| I.T_refine _ _ _
| I.T_string _ _ _
-> false
| I.T_if_else _ t1 t2
| I.T_pair _ t1 t2 ->
type_has_actions t1 || type_has_actions t2
| I.T_at_most _ _ t
| I.T_exact _ _ t
| I.T_nlist _ _ t
| I.T_with_comment _ t _
| I.T_dep_pair_with_refinement _ _ _ (_, t)
| I.T_dep_pair _ _ (_, t) ->
type_has_actions t
let rec parse_typ (t : I.typ) : Pure (parser not_reading)
(requires (type_has_actions t == false))
(ensures (fun _ -> True))
= match t with
| I.T_false _ -> parse_false
| I.T_denoted _ d -> parse_denoted d
| I.T_pair _ t1 t2 -> parse_pair (parse_typ t1) (parse_typ t2)
| I.T_dep_pair _ t1 (lam, t2) -> parse_dep_pair (parse_readable_dtyp t1) lam (parse_typ t2)
| I.T_refine _ base (lam, cond) -> parse_refine (parse_readable_dtyp base) lam (fun _ -> mk_expr cond)
| I.T_dep_pair_with_refinement _ base (lam_cond, cond) (lam_k, k) -> parse_dep_pair_with_refinement (parse_readable_dtyp base) lam_cond (fun _ -> mk_expr cond) lam_k (parse_typ k)
| I.T_if_else cond t1 t2 -> parse_ifthenelse (fun _ -> mk_expr cond) (parse_typ t1) (parse_typ t2)
| I.T_with_comment _ base _ -> parse_typ base
| I.T_at_most _ size body -> parse_at_most (fun _ -> mk_expr size) (parse_typ body)
| I.T_exact _ size body -> parse_exact (fun _ -> mk_expr size) (parse_typ body)
| I.T_string _ elt terminator -> parse_string (parse_readable_dtyp elt) (fun _ -> mk_expr terminator)
| I.T_nlist _ size body -> parse_nlist (fun _ -> mk_expr size) (parse_typ body)
type arg_type =
| ArgInt of A.integer_type
| ArgBool
| ArgPointer | false | true | Z3TestGen.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val arg_type_of_typ (t: T.typ) : Tot (option arg_type) | [] | Z3TestGen.arg_type_of_typ | {
"file_name": "src/3d/Z3TestGen.fst",
"git_rev": "446a08ce38df905547cf20f28c43776b22b8087a",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | t: Target.typ -> FStar.Pervasives.Native.option Z3TestGen.arg_type | {
"end_col": 13,
"end_line": 764,
"start_col": 2,
"start_line": 750
} |
FStar.All.ML | val with_option_out_file (#a: Type) (name: option string)
: Tot (body: ((string -> ML unit) -> ML a) -> ML a) | [
{
"abbrev": true,
"full_module": "InterpreterTarget",
"short_module": "I"
},
{
"abbrev": true,
"full_module": "Target",
"short_module": "T"
},
{
"abbrev": true,
"full_module": "Ast",
"short_module": "A"
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.All",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.Printf",
"short_module": "Printf"
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let with_option_out_file
(#a: Type)
(name: option string)
: Tot ((body: ((string -> ML unit) -> ML a)) -> ML a)
= match name with
| Some name -> with_out_file name
| None -> (fun body -> body (fun _ -> ())) | val with_option_out_file (#a: Type) (name: option string)
: Tot (body: ((string -> ML unit) -> ML a) -> ML a)
let with_option_out_file (#a: Type) (name: option string)
: Tot (body: ((string -> ML unit) -> ML a) -> ML a) = | true | null | false | match name with
| Some name -> with_out_file name
| None -> (fun body -> body (fun _ -> ())) | {
"checked_file": "Z3TestGen.fst.checked",
"dependencies": [
"Z3.fsti.checked",
"Target.fsti.checked",
"prims.fst.checked",
"OS.fsti.checked",
"Lisp.fsti.checked",
"InterpreterTarget.fsti.checked",
"FStar.String.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Printf.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.List.Tot.fst.checked",
"FStar.List.fst.checked",
"FStar.IO.fst.checked",
"FStar.Char.fsti.checked",
"FStar.All.fst.checked",
"Ast.fst.checked"
],
"interface_file": false,
"source_file": "Z3TestGen.fst"
} | [
"ml"
] | [
"FStar.Pervasives.Native.option",
"Prims.string",
"Z3TestGen.with_out_file",
"Prims.unit"
] | [] | module Z3TestGen
module Printf = FStar.Printf
open FStar.All
open FStar.Mul
module A = Ast
module T = Target
module I = InterpreterTarget
let prelude : string =
"
(set-option :produce-models true)
(declare-datatypes () ((State (mk-state (input-size Int) (choice-index Int)))))
(declare-datatypes () ((Result (mk-result (return-value Int) (after-state State)))))
(define-fun parse-empty ((x State)) Result
(mk-result 0 x)
)
(declare-fun choose (Int) Int)
(assert (forall ((i Int))
(and (<= 0 (choose i)) (< (choose i) 256))
))
(define-fun parse-false ((x State)) State
(mk-state -1 (choice-index x))
)
(define-fun parse-all-bytes ((x State)) State
(if (<= (input-size x) 0)
x
(mk-state 0 (+ (choice-index x) (input-size x)))
)
)
(define-fun parse-all-zeros ((x State)) State
(if (<= (input-size x) 0)
x
(mk-state
(if
(forall ((j Int))
(if (and (<= 0 j) (< j (input-size x)))
(= (choose (+ (choice-index x) j)) 0)
true
)
)
0
-1
)
(+ (choice-index x) (input-size x))
)
)
)
(define-fun parse-u8 ((x State)) Result
(mk-result
(choose (choice-index x))
(mk-state (- (input-size x) 1) (+ (choice-index x) 1))
)
)
(define-fun parse-u16-be ((x State)) Result
(mk-result
(+ (choose (+ 1 (choice-index x)))
(* 256
(choose (+ 0 (choice-index x)))
)
)
(mk-state (- (input-size x) 2) (+ (choice-index x) 2))
)
)
(define-fun parse-u16-le ((x State)) Result
(mk-result
(+ (choose (+ 0 (choice-index x)))
(* 256
(choose (+ 1 (choice-index x)))
)
)
(mk-state (- (input-size x) 2) (+ (choice-index x) 2))
)
)
(define-fun parse-u32-be ((x State)) Result
(mk-result
(+ (choose (+ 3 (choice-index x)))
(* 256
(+ (choose (+ 2 (choice-index x)))
(* 256
(+ (choose (+ 1 (choice-index x)))
(* 256
(choose (+ 0 (choice-index x)))
)
)
)
)
)
)
(mk-state (- (input-size x) 4) (+ (choice-index x) 4))
)
)
(define-fun parse-u32-le ((x State)) Result
(mk-result
(+ (choose (+ 0 (choice-index x)))
(* 256
(+ (choose (+ 1 (choice-index x)))
(* 256
(+ (choose (+ 2 (choice-index x)))
(* 256
(choose (+ 3 (choice-index x)))
)
)
)
)
)
)
(mk-state (- (input-size x) 4) (+ (choice-index x) 4))
)
)
(define-fun parse-u64-be ((x State)) Result
(mk-result
(+ (choose (+ 7 (choice-index x)))
(* 256
(+ (choose (+ 6 (choice-index x)))
(* 256
(+ (choose (+ 5 (choice-index x)))
(* 256
(+ (choose (+ 4 (choice-index x)))
(* 256
(+ (choose (+ 3 (choice-index x)))
(* 256
(+ (choose (+ 2 (choice-index x)))
(* 256
(+ (choose (+ 1 (choice-index x)))
(* 256
(choose (+ 0 (choice-index x)))
)
)
)
)
)
)
)
)
)
)
)
)
)
)
(mk-state (- (input-size x) 8) (+ (choice-index x) 8))
)
)
(define-fun parse-u64-le ((x State)) Result
(mk-result
(+ (choose (+ 0 (choice-index x)))
(* 256
(+ (choose (+ 1 (choice-index x)))
(* 256
(+ (choose (+ 2 (choice-index x)))
(* 256
(+ (choose (+ 3 (choice-index x)))
(* 256
(+ (choose (+ 4 (choice-index x)))
(* 256
(+ (choose (+ 5 (choice-index x)))
(* 256
(+ (choose (+ 6 (choice-index x)))
(* 256
(choose (+ 7 (choice-index x)))
)
)
)
)
)
)
)
)
)
)
)
)
)
)
(mk-state (- (input-size x) 8) (+ (choice-index x) 8))
)
)
(define-fun-rec pow-2 ((amount Int)) Int
(if (<= amount 0)
1
(* 2 (pow-2 (- amount 1)))
)
)
;; see LowParse.BitFields.get_bitfield_eq
(define-fun get-bitfield-lsb ((nbBits Int) (value Int) (bitsFrom Int) (bitsTo Int)) Int
(mod (div value (pow-2 bitsFrom)) (pow-2 (- bitsTo bitsFrom)))
)
;; see EverParse3d.Prelude.StaticHeader
(define-fun get-bitfield-msb ((nbBits Int) (value Int) (bitsFrom Int) (bitsTo Int)) Int
(get-bitfield-lsb nbBits value (- nbBits bitsTo) (- nbBits bitsFrom))
)
(declare-const initial-input-size Int)
(assert (>= initial-input-size 0))
(define-fun initial-state () State (mk-state initial-input-size 0))
"
let mk_constant = function
| A.Unit -> "0"
| A.Int _ x -> string_of_int x
| A.XInt _ x -> string_of_int (OS.int_of_string x)
| A.Bool true -> "true"
| A.Bool false -> "false"
let mk_app fn = function
| None -> fn
| Some args -> Printf.sprintf "(%s %s)" fn args
let assert_some = function
| None -> failwith "assert_some"
| Some x -> x
let is_bitwise_op (x: T.op) : Tot (option A.integer_type) =
match x with
| T.BitwiseAnd a
| T.BitwiseXor a
| T.BitwiseOr a
| T.BitwiseNot a
| T.ShiftLeft a
| T.ShiftRight a
-> Some a
| _ -> None
let mk_bitwise_op (op: string) (bitvec_args: option string) : ML string =
mk_app "bv2int" (Some (mk_app op bitvec_args))
let integer_type_bit_size = function
| A.UInt8 -> 8
| A.UInt16 -> 16
| A.UInt32 -> 32
| A.UInt64 -> 64
let mk_bitwise_not (a: A.integer_type) (bitvec_arg: option string) : ML string =
match bitvec_arg with
| None -> failwith "ill-formed bitwise_not"
| Some arg -> "(bv2int (bvxor "^arg^" #b"^String.make (integer_type_bit_size a) '1'^"))"
let mk_op : T.op -> option string -> ML string = function
| T.Eq -> mk_app "="
| T.Neq -> (fun s -> mk_app "not" (Some (mk_app "=" s)))
| T.And -> mk_app "and"
| T.Or -> mk_app "or"
| T.Not -> mk_app "not"
| T.Plus _ -> mk_app "+"
| T.Minus _ -> mk_app "-"
| T.Mul _ -> mk_app "*"
| T.Division _ -> mk_app "div"
| T.Remainder _ -> mk_app "mod"
| T.BitwiseAnd _ -> mk_bitwise_op "bvand"
| T.BitwiseXor _ -> mk_bitwise_op "bvxor"
| T.BitwiseOr _ -> mk_bitwise_op "bvor"
| T.BitwiseNot a -> mk_bitwise_not a
| T.ShiftLeft _ -> mk_bitwise_op "bvshl"
| T.ShiftRight _ -> mk_bitwise_op "bvlshr"
| T.LT _ -> mk_app "<"
| T.GT _ -> mk_app ">"
| T.LE _ -> mk_app "<="
| T.GE _ -> mk_app ">="
| T.IfThenElse -> mk_app "if"
| T.BitFieldOf size order -> (fun arg -> Printf.sprintf "(get-bitfield-%ssb %d %s)" (match order with A.LSBFirst -> "l" | A.MSBFirst -> "m") size (assert_some arg))
| T.Cast _ _ -> assert_some (* casts allowed only if they are proven not to lose precision *)
| T.Ext s -> mk_app s
let ident_to_string = A.ident_to_string
let mk_bitwise_arg (t: A.integer_type) (arg: string) : Tot string =
mk_app ("(_ int2bv "^string_of_int (integer_type_bit_size t)^")") (Some arg)
let mk_maybe_bitwise_arg (t: option A.integer_type) (arg: string) : Tot string =
match t with
| None -> arg
| Some t -> mk_bitwise_arg t arg
let rec mk_expr (e: T.expr) : ML string = match fst e with
| T.Constant c -> mk_constant c
| T.Identifier i -> ident_to_string i
| T.App hd args -> mk_op hd (mk_args (is_bitwise_op hd) args)
| _ -> failwith "mk_expr: not supported"
and mk_args_aux (is_bitwise_op: option A.integer_type) accu : (list T.expr -> ML string) = function
| [] -> accu
| a :: q -> mk_args_aux is_bitwise_op (Printf.sprintf "%s %s" accu (mk_maybe_bitwise_arg is_bitwise_op (mk_expr a))) q
and mk_args (is_bitwise_op: option A.integer_type) (l: list T.expr) : ML (option string) = match l with
| [] -> None
| a :: q -> Some (mk_args_aux is_bitwise_op (mk_maybe_bitwise_arg is_bitwise_op (mk_expr a)) q)
type reading = { call: string }
type not_reading = { call: string }
type binders = {
is_empty: bool;
bind: string;
args: string;
}
let empty_binders : binders = {
is_empty = true;
bind = "";
args = "";
}
let push_binder (name: string) (typ: string) (b: binders) : binders = {
is_empty = false;
bind = Printf.sprintf "(%s %s) %s" name typ b.bind;
args = Printf.sprintf " %s%s" name b.args;
}
let mk_function_call (name: string) (b: binders) =
Printf.sprintf "%s%s" name b.args
type parser (a: Type) =
(* name *) string ->
(* binders *) binders ->
(* is_toplevel *) bool ->
(* out *) (string -> ML unit) ->
ML a
let unsupported_parser (s: string) (a: Type) : Tot (parser a) =
fun _ _ _ _ -> failwith (Printf.sprintf "unsupported parser: %s" s)
let leaf_reading_parser (name: string) : parser reading =
fun _ _ _ _ -> { call = name }
let readable_itype_parser_suffix (i: I.itype) : Tot string = match i with
| I.UInt8 | I.UInt8BE -> "u8"
| I.UInt16 -> "u16-le"
| I.UInt16BE -> "u16-be"
| I.UInt32 -> "u32-le"
| I.UInt32BE -> "u32-be"
| I.UInt64 -> "u64-le"
| I.UInt64BE -> "u64-be"
| I.Unit -> "empty"
| I.AllBytes -> "all-bytes"
| I.AllZeros -> "all-zeros"
let parse_readable_itype (i: I.readable_itype) : Tot (parser reading) =
leaf_reading_parser ("parse-" ^ readable_itype_parser_suffix i)
let mk_wrap_parser
(name: string)
(binders: string)
(body: string)
: string
= let input = Printf.sprintf "%s-input" name in
let tmp = Printf.sprintf "%s-tmp" name in
"(define-fun "^name^" ("^binders^"("^input^" State)) State
(after-state ("^body^" "^input^"))
)
"
let wrap_parser (p: parser reading) : parser not_reading =
fun name binders _ out ->
let name' = Printf.sprintf "%s-wrapped" name in
let body = p name' binders false out in
out (mk_wrap_parser name binders.bind body.call);
{ call = mk_function_call name binders }
let mk_toplevel_parser
(name: string)
(binders: string)
(body: string)
: string
= let input = Printf.sprintf "%s-input" name in
"(define-fun "^name^" ("^binders^"("^input^" State)) State
("^body^" "^input^")
)
"
let maybe_toplevel_parser (p: parser not_reading) : parser not_reading =
fun name binders is_toplevel out ->
if is_toplevel
then begin
let name' = Printf.sprintf "%s-body" name in
let body = p name' binders false out in
out (mk_toplevel_parser name binders.bind body.call);
{ call = mk_function_call name binders }
end
else p name binders false out
let parse_all_bytes : parser not_reading =
maybe_toplevel_parser (fun _ _ _ _ -> { call = "parse-all-bytes" })
let parse_all_zeros : parser not_reading =
maybe_toplevel_parser (fun _ _ _ _ -> { call = "parse-all-zeros" })
let parse_itype : I.itype -> parser not_reading = function
| I.AllBytes -> parse_all_bytes
| I.AllZeros -> parse_all_zeros
| i -> wrap_parser (parse_readable_itype i)
let mk_app_without_paren id args =
mk_args_aux None (ident_to_string id) args
let parse_readable_app
(hd: A.ident)
(args: list I.expr)
: Tot (parser reading)
= fun _ _ _ _ -> { call = mk_app_without_paren hd args }
let parse_readable_dtyp
(d: I.readable_dtyp)
: Tot (parser reading)
= match d with
| I.DT_IType i -> parse_readable_itype i
| I.DT_App _ hd args -> parse_readable_app hd args
let parse_not_readable_app
(hd: A.ident)
(args: list I.expr)
: Tot (parser not_reading)
= maybe_toplevel_parser (fun _ _ _ _ -> { call = mk_app_without_paren hd args })
let parse_dtyp
(d: I.dtyp)
: Tot (parser not_reading)
= if I.allow_reader_of_dtyp d
then wrap_parser (parse_readable_dtyp d)
else match d with
| I.DT_IType i -> parse_itype i
| I.DT_App _ hd args -> parse_not_readable_app hd args
let parse_false : parser not_reading =
maybe_toplevel_parser (fun _ _ _ _ -> { call = "parse-false" })
let parse_denoted (d: I.dtyp) : parser not_reading =
parse_dtyp d
let mk_parse_pair
(name: string)
(binders: string)
(fst: string)
(snd: string)
: string
= let input = Printf.sprintf "%s-input" name in
let tmp = Printf.sprintf "%s-tmp" name in
"(define-fun "^name^" ("^binders^"("^input^" State)) State
(let (("^tmp^" ("^fst^" "^input^")))
(if (< (input-size "^tmp^") 0)
"^tmp^"
("^snd^" "^tmp^")
)
)
)
"
let parse_pair (fst: parser not_reading) (snd: parser not_reading) : parser not_reading =
fun name binders _ out ->
let name_fst = Printf.sprintf "%s-fst" name in
let body_fst = fst name_fst binders false out in
let name_snd = Printf.sprintf "%s-snd" name in
let body_snd = snd name_snd binders false out in
out (mk_parse_pair name binders.bind body_fst.call body_snd.call);
{ call = mk_function_call name binders }
let parse_square (p: parser not_reading) : parser not_reading =
fun name binders _ out ->
let body_name = Printf.sprintf "%s-snd" name in
let body = p body_name binders false out in
out (mk_parse_pair name binders.bind body.call body.call);
{ call = mk_function_call name binders }
let mk_parse_dep_pair_with_refinement
(name: string)
(binders: string)
(dfst: string)
(cond_binder_name: string)
(cond: string)
(dsnd_binder_name: string)
(dsnd: string) (* already contains the new argument *)
: string
= let input = Printf.sprintf "%s-input" name in
let tmp = Printf.sprintf "%s-tmp" name in
"(define-fun "^name^" ("^binders^"("^input^" State)) State
(let (("^tmp^" ("^dfst^" "^input^")))
(if (< (input-size (after-state "^tmp^")) 0)
(after-state "^tmp^")
(if (let (("^cond_binder_name^" (return-value "^tmp^"))) "^cond^")
(let (("^dsnd_binder_name^" (return-value "^tmp^")))
("^dsnd^" (after-state "^tmp^"))
)
(mk-state -1 (choice-index (after-state "^tmp^")))
)
)
)
)
"
let parse_dep_pair_with_refinement_gen (tag: parser reading) (cond_binder: string) (cond: unit -> ML string) (payload_binder: string) (payload: parser not_reading) : parser not_reading =
fun name binders _ out ->
let name_tag = Printf.sprintf "%s-tag" name in
let body_tag = tag name_tag binders false out in
let binders' = push_binder payload_binder "Int" binders in (* TODO: support more types *)
let name_payload = Printf.sprintf "%s-payload" name in
let body_payload = payload name_payload binders' false out in
out (mk_parse_dep_pair_with_refinement name binders.bind body_tag.call cond_binder (cond ()) payload_binder body_payload.call);
{ call = mk_function_call name binders }
let parse_dep_pair_with_refinement (tag: parser reading) (cond_binder: A.ident) (cond: unit -> ML string) (payload_binder: A.ident) (payload: parser not_reading) : parser not_reading =
parse_dep_pair_with_refinement_gen tag (ident_to_string cond_binder) cond (ident_to_string payload_binder) payload
let parse_dep_pair (tag: parser reading) (new_binder: A.ident) (payload: parser not_reading) : parser not_reading =
parse_dep_pair_with_refinement tag new_binder (fun _ -> "true") new_binder payload
let parse_refine (tag: parser reading) (cond_binder: A.ident) (cond: unit -> ML string) : parser not_reading =
parse_dep_pair_with_refinement tag cond_binder cond cond_binder (parse_itype I.Unit)
let mk_parse_ifthenelse
(name: string)
(binders: string)
(cond: string)
(f_then: string)
(f_else: string)
: string
= let input = Printf.sprintf "%s-input" name in
"(define-fun "^name^" ("^binders^"("^input^" State)) State
(if "^cond^"
("^f_then^" "^input^")
("^f_else^" "^input^")
)
)
"
let parse_ifthenelse (cond: unit -> ML string) (pthen: parser not_reading) (pelse: parser not_reading) : parser not_reading =
fun name binders _ out ->
let name_then = Printf.sprintf "%s-then" name in
let body_then = pthen name_then binders false out in
let name_else = Printf.sprintf "%s-else" name in
let body_else = pelse name_else binders false out in
out (mk_parse_ifthenelse name binders.bind (cond ()) body_then.call body_else.call);
{ call = mk_function_call name binders }
let mk_parse_exact
(name: string)
(binders: string)
(body: string)
(size: string)
: string
= let input = Printf.sprintf "%s-input" name in
let sz = Printf.sprintf "%s-size" name in
let res = Printf.sprintf "%s-res" name in
"(define-fun "^name^" ("^binders^"("^input^" State)) State
(let (("^sz^" "^size^"))
(if (< (input-size "^input^") "^sz^")
(mk-state -1 (choice-index "^input^"))
(let (("^res^" ("^body^" (mk-state "^sz^" (choice-index "^input^")))))
(mk-state
(if (= (input-size "^res^") 0)
(- (input-size "^input^") "^sz^")
-1
)
(choice-index "^res^")
)
)
)
)
)
"
let parse_exact
(size: unit -> ML string)
(body: parser not_reading)
: Tot (parser not_reading)
= fun name binders _ out ->
let body_name = Printf.sprintf "%s-body" name in
let body = body body_name binders false out in
out (mk_parse_exact name binders.bind body.call (size ()));
{ call = mk_function_call name binders }
let parse_at_most
(size: unit -> ML string)
(body: parser not_reading)
: Tot (parser not_reading)
= parse_exact size (parse_pair body parse_all_bytes)
(*
let mk_parse_list_one
(name: string)
(binders: string)
(p: string)
: string
= let input = Printf.sprintf "%s-input" name in
let res = Printf.sprintf "%s-res" name in
"(define-fun "^name^" ("^binders^"("^input^" (Seq Int))) (Seq Int)
(if (= (seq.len "^input^") 0)
(seq.unit 0)
(let (("^res^" ("^p^" "^input^")))
(if (= (seq.len "^res^") 0)
(as seq.empty (Seq Int))
(if (= (seq.nth "^res^" 0) 0)
(as seq.empty (Seq Int))
"^res^"
)
)
)
)
)
"
let parse_list_one
(body: parser not_reading)
: Tot (parser not_reading)
= fun name binders _ out ->
let body_name = Printf.sprintf "%s-body" name in
let body = body body_name binders false out in
out (mk_parse_list_one name binders.bind body.call);
{ call = mk_function_call name binders }
let rec parse_list_bounded'
(body: parser not_reading)
(logn: nat)
: Tot (parser not_reading)
(decreases logn)
= if logn = 0
then parse_list_one body
else
let logn' = logn - 1 in
parse_square (parse_list_bounded' body logn')
let parse_list_bounded body = parse_list_bounded' body 3 // 64
*)
let mk_parse_list
(name: string)
(rec_call: string)
(binders: string)
(body: string)
: string
= let input = Printf.sprintf "%s-input" name in
"(define-fun-rec "^name^" ("^binders^"("^input^" State)) State
(if (<= (input-size "^input^") 0)
"^input^"
("^rec_call^" ("^body^" "^input^"))
)
)
"
let parse_list
(body: parser not_reading)
: Tot (parser not_reading)
= fun name binders _ out ->
let rec_call = mk_function_call name binders in
let body_name = Printf.sprintf "%s-body" name in
let body = body body_name binders false out in
out (mk_parse_list name rec_call binders.bind body.call);
{ call = rec_call }
let parse_nlist
(size: unit -> ML string)
(body: parser not_reading)
: Tot (parser not_reading)
= parse_exact size (parse_list body)
let mk_parse_string
(name: string)
(rec_call: string)
(binders: string)
(body: string)
(terminator: string)
: string
= let input = Printf.sprintf "%s-input" name in
let tmp = Printf.sprintf "%s-tmp" name in
"(define-fun-rec "^name^" ("^binders^"("^input^" State)) State
(let (("^tmp^" ("^body^" "^input^")))
(if (< (choice-index (after-state "^tmp^")) 0)
(mk-state -1 (choice-index (after-state "^tmp^")))
(if (= (return-value "^tmp^") "^terminator^")
(after-state "^tmp^")
("^rec_call^" (after-state "^tmp^"))
)
)
)
)
"
let parse_string
(body: parser reading)
(terminator: (unit -> ML string))
: Tot (parser not_reading)
= fun name binders _ out ->
let rec_call = mk_function_call name binders in
let body_name = Printf.sprintf "%s-body" name in
let body = body body_name binders false out in
out (mk_parse_string name rec_call binders.bind body.call (terminator ()));
{ call = rec_call }
let rec type_has_actions = function
| I.T_with_dep_action _ _ _
| I.T_dep_pair_with_action _ _ _ _
| I.T_refine_with_action _ _ _ _
| I.T_dep_pair_with_refinement_and_action _ _ _ _ _
| I.T_with_action _ _ _
-> true
| I.T_false _
| I.T_denoted _ _
| I.T_refine _ _ _
| I.T_string _ _ _
-> false
| I.T_if_else _ t1 t2
| I.T_pair _ t1 t2 ->
type_has_actions t1 || type_has_actions t2
| I.T_at_most _ _ t
| I.T_exact _ _ t
| I.T_nlist _ _ t
| I.T_with_comment _ t _
| I.T_dep_pair_with_refinement _ _ _ (_, t)
| I.T_dep_pair _ _ (_, t) ->
type_has_actions t
let rec parse_typ (t : I.typ) : Pure (parser not_reading)
(requires (type_has_actions t == false))
(ensures (fun _ -> True))
= match t with
| I.T_false _ -> parse_false
| I.T_denoted _ d -> parse_denoted d
| I.T_pair _ t1 t2 -> parse_pair (parse_typ t1) (parse_typ t2)
| I.T_dep_pair _ t1 (lam, t2) -> parse_dep_pair (parse_readable_dtyp t1) lam (parse_typ t2)
| I.T_refine _ base (lam, cond) -> parse_refine (parse_readable_dtyp base) lam (fun _ -> mk_expr cond)
| I.T_dep_pair_with_refinement _ base (lam_cond, cond) (lam_k, k) -> parse_dep_pair_with_refinement (parse_readable_dtyp base) lam_cond (fun _ -> mk_expr cond) lam_k (parse_typ k)
| I.T_if_else cond t1 t2 -> parse_ifthenelse (fun _ -> mk_expr cond) (parse_typ t1) (parse_typ t2)
| I.T_with_comment _ base _ -> parse_typ base
| I.T_at_most _ size body -> parse_at_most (fun _ -> mk_expr size) (parse_typ body)
| I.T_exact _ size body -> parse_exact (fun _ -> mk_expr size) (parse_typ body)
| I.T_string _ elt terminator -> parse_string (parse_readable_dtyp elt) (fun _ -> mk_expr terminator)
| I.T_nlist _ size body -> parse_nlist (fun _ -> mk_expr size) (parse_typ body)
type arg_type =
| ArgInt of A.integer_type
| ArgBool
| ArgPointer
let arg_type_of_typ (t: T.typ) : Tot (option arg_type) =
match t with
| T.T_pointer _
| T.T_app _ A.KindOutput _
| T.T_app _ A.KindExtern _
| T.T_app {v = {modul_name = None; name = "PUINT8"}} _ _
-> Some ArgPointer
| T.T_app {v = {modul_name = None; name = "Bool"}} _ _
-> Some ArgBool
| T.T_app i _ _
->
begin match A.maybe_as_integer_typ i with
| Some t -> Some (ArgInt t)
| None -> None
end
| _ -> None
let smt_type_of_typ (t: T.typ) : Tot string =
match arg_type_of_typ t with
| Some ArgBool -> "Bool"
| _ -> "Int"
let rec binders_of_params = function
| [] -> empty_binders
| (id, t) :: q -> push_binder (ident_to_string id) (smt_type_of_typ t) (binders_of_params q)
let mk_definition
(name: string)
(binders: string)
(typ: string)
(body: string)
: Tot string
= "(define-fun "^name^" ("^binders^") "^typ^" "^body^")"
let produce_definition
(i: A.ident)
(param: list T.param)
(typ: T.typ)
(body: T.expr)
(out: string -> ML unit)
: ML unit
= let binders = binders_of_params param in
out (mk_definition (ident_to_string i) binders.bind (smt_type_of_typ typ) (mk_expr body))
let produce_not_type_decl (a: I.not_type_decl) (out: string -> ML unit) : ML unit =
match fst a with
| T.Definition (i, param, typ, body) ->
produce_definition i param typ body out
| T.Assumption _ -> failwith "produce_not_type_decl: unsupported"
| T.Output_type _
| T.Output_type_expr _ _
| T.Extern_type _
| T.Extern_fn _ _ _
-> ()
let prog = list (string & list arg_type)
let produce_type_decl (out: string -> ML unit) (accu: prog) (a: I.type_decl) : ML prog =
let binders = binders_of_params a.name.td_params in
let name = ident_to_string a.name.td_name in
if type_has_actions a.typ then failwith (Printf.sprintf "produce_type_decl: %s still has some actions" name);
let _ = parse_typ a.typ name binders true out in
(name, List.map (fun (i, ty) -> match arg_type_of_typ ty with Some t -> t | None -> failwith (Printf.sprintf "Parser %s has unsupported argument type for %s" name (ident_to_string i))) a.name.td_params) :: accu
let produce_decl (out: string -> ML unit) (accu: prog) (a: I.decl) : ML prog =
match a with
| Inl a -> produce_not_type_decl a out; accu
| Inr a -> produce_type_decl out accu a
let produce_decls (out: string -> ML unit) (accu: prog) (l: list I.decl) : ML prog =
List.fold_left (produce_decl out) accu l
(* Produce the SMT2 encoding of the parser spec *)
let with_out_file
(#a: Type)
(name: string)
(body: ((string -> ML unit) -> ML a))
: ML a
= let fd = FStar.IO.open_write_file name in
let res = body (FStar.IO.write_string fd) in
FStar.IO.close_write_file fd;
res
let with_option_out_file
(#a: Type)
(name: option string) | false | false | Z3TestGen.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val with_option_out_file (#a: Type) (name: option string)
: Tot (body: ((string -> ML unit) -> ML a) -> ML a) | [] | Z3TestGen.with_option_out_file | {
"file_name": "src/3d/Z3TestGen.fst",
"git_rev": "446a08ce38df905547cf20f28c43776b22b8087a",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} |
name: FStar.Pervasives.Native.option Prims.string ->
body: (_: (_: Prims.string -> FStar.All.ML Prims.unit) -> FStar.All.ML a)
-> FStar.All.ML a | {
"end_col": 44,
"end_line": 839,
"start_col": 2,
"start_line": 837
} |
FStar.All.ML | val produce_decl (out: (string -> ML unit)) (accu: prog) (a: I.decl) : ML prog | [
{
"abbrev": true,
"full_module": "InterpreterTarget",
"short_module": "I"
},
{
"abbrev": true,
"full_module": "Target",
"short_module": "T"
},
{
"abbrev": true,
"full_module": "Ast",
"short_module": "A"
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.All",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.Printf",
"short_module": "Printf"
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let produce_decl (out: string -> ML unit) (accu: prog) (a: I.decl) : ML prog =
match a with
| Inl a -> produce_not_type_decl a out; accu
| Inr a -> produce_type_decl out accu a | val produce_decl (out: (string -> ML unit)) (accu: prog) (a: I.decl) : ML prog
let produce_decl (out: (string -> ML unit)) (accu: prog) (a: I.decl) : ML prog = | true | null | false | match a with
| Inl a ->
produce_not_type_decl a out;
accu
| Inr a -> produce_type_decl out accu a | {
"checked_file": "Z3TestGen.fst.checked",
"dependencies": [
"Z3.fsti.checked",
"Target.fsti.checked",
"prims.fst.checked",
"OS.fsti.checked",
"Lisp.fsti.checked",
"InterpreterTarget.fsti.checked",
"FStar.String.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Printf.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.List.Tot.fst.checked",
"FStar.List.fst.checked",
"FStar.IO.fst.checked",
"FStar.Char.fsti.checked",
"FStar.All.fst.checked",
"Ast.fst.checked"
],
"interface_file": false,
"source_file": "Z3TestGen.fst"
} | [
"ml"
] | [
"Prims.string",
"Prims.unit",
"Z3TestGen.prog",
"InterpreterTarget.decl",
"InterpreterTarget.not_type_decl",
"Z3TestGen.produce_not_type_decl",
"InterpreterTarget.type_decl",
"Z3TestGen.produce_type_decl"
] | [] | module Z3TestGen
module Printf = FStar.Printf
open FStar.All
open FStar.Mul
module A = Ast
module T = Target
module I = InterpreterTarget
let prelude : string =
"
(set-option :produce-models true)
(declare-datatypes () ((State (mk-state (input-size Int) (choice-index Int)))))
(declare-datatypes () ((Result (mk-result (return-value Int) (after-state State)))))
(define-fun parse-empty ((x State)) Result
(mk-result 0 x)
)
(declare-fun choose (Int) Int)
(assert (forall ((i Int))
(and (<= 0 (choose i)) (< (choose i) 256))
))
(define-fun parse-false ((x State)) State
(mk-state -1 (choice-index x))
)
(define-fun parse-all-bytes ((x State)) State
(if (<= (input-size x) 0)
x
(mk-state 0 (+ (choice-index x) (input-size x)))
)
)
(define-fun parse-all-zeros ((x State)) State
(if (<= (input-size x) 0)
x
(mk-state
(if
(forall ((j Int))
(if (and (<= 0 j) (< j (input-size x)))
(= (choose (+ (choice-index x) j)) 0)
true
)
)
0
-1
)
(+ (choice-index x) (input-size x))
)
)
)
(define-fun parse-u8 ((x State)) Result
(mk-result
(choose (choice-index x))
(mk-state (- (input-size x) 1) (+ (choice-index x) 1))
)
)
(define-fun parse-u16-be ((x State)) Result
(mk-result
(+ (choose (+ 1 (choice-index x)))
(* 256
(choose (+ 0 (choice-index x)))
)
)
(mk-state (- (input-size x) 2) (+ (choice-index x) 2))
)
)
(define-fun parse-u16-le ((x State)) Result
(mk-result
(+ (choose (+ 0 (choice-index x)))
(* 256
(choose (+ 1 (choice-index x)))
)
)
(mk-state (- (input-size x) 2) (+ (choice-index x) 2))
)
)
(define-fun parse-u32-be ((x State)) Result
(mk-result
(+ (choose (+ 3 (choice-index x)))
(* 256
(+ (choose (+ 2 (choice-index x)))
(* 256
(+ (choose (+ 1 (choice-index x)))
(* 256
(choose (+ 0 (choice-index x)))
)
)
)
)
)
)
(mk-state (- (input-size x) 4) (+ (choice-index x) 4))
)
)
(define-fun parse-u32-le ((x State)) Result
(mk-result
(+ (choose (+ 0 (choice-index x)))
(* 256
(+ (choose (+ 1 (choice-index x)))
(* 256
(+ (choose (+ 2 (choice-index x)))
(* 256
(choose (+ 3 (choice-index x)))
)
)
)
)
)
)
(mk-state (- (input-size x) 4) (+ (choice-index x) 4))
)
)
(define-fun parse-u64-be ((x State)) Result
(mk-result
(+ (choose (+ 7 (choice-index x)))
(* 256
(+ (choose (+ 6 (choice-index x)))
(* 256
(+ (choose (+ 5 (choice-index x)))
(* 256
(+ (choose (+ 4 (choice-index x)))
(* 256
(+ (choose (+ 3 (choice-index x)))
(* 256
(+ (choose (+ 2 (choice-index x)))
(* 256
(+ (choose (+ 1 (choice-index x)))
(* 256
(choose (+ 0 (choice-index x)))
)
)
)
)
)
)
)
)
)
)
)
)
)
)
(mk-state (- (input-size x) 8) (+ (choice-index x) 8))
)
)
(define-fun parse-u64-le ((x State)) Result
(mk-result
(+ (choose (+ 0 (choice-index x)))
(* 256
(+ (choose (+ 1 (choice-index x)))
(* 256
(+ (choose (+ 2 (choice-index x)))
(* 256
(+ (choose (+ 3 (choice-index x)))
(* 256
(+ (choose (+ 4 (choice-index x)))
(* 256
(+ (choose (+ 5 (choice-index x)))
(* 256
(+ (choose (+ 6 (choice-index x)))
(* 256
(choose (+ 7 (choice-index x)))
)
)
)
)
)
)
)
)
)
)
)
)
)
)
(mk-state (- (input-size x) 8) (+ (choice-index x) 8))
)
)
(define-fun-rec pow-2 ((amount Int)) Int
(if (<= amount 0)
1
(* 2 (pow-2 (- amount 1)))
)
)
;; see LowParse.BitFields.get_bitfield_eq
(define-fun get-bitfield-lsb ((nbBits Int) (value Int) (bitsFrom Int) (bitsTo Int)) Int
(mod (div value (pow-2 bitsFrom)) (pow-2 (- bitsTo bitsFrom)))
)
;; see EverParse3d.Prelude.StaticHeader
(define-fun get-bitfield-msb ((nbBits Int) (value Int) (bitsFrom Int) (bitsTo Int)) Int
(get-bitfield-lsb nbBits value (- nbBits bitsTo) (- nbBits bitsFrom))
)
(declare-const initial-input-size Int)
(assert (>= initial-input-size 0))
(define-fun initial-state () State (mk-state initial-input-size 0))
"
let mk_constant = function
| A.Unit -> "0"
| A.Int _ x -> string_of_int x
| A.XInt _ x -> string_of_int (OS.int_of_string x)
| A.Bool true -> "true"
| A.Bool false -> "false"
let mk_app fn = function
| None -> fn
| Some args -> Printf.sprintf "(%s %s)" fn args
let assert_some = function
| None -> failwith "assert_some"
| Some x -> x
let is_bitwise_op (x: T.op) : Tot (option A.integer_type) =
match x with
| T.BitwiseAnd a
| T.BitwiseXor a
| T.BitwiseOr a
| T.BitwiseNot a
| T.ShiftLeft a
| T.ShiftRight a
-> Some a
| _ -> None
let mk_bitwise_op (op: string) (bitvec_args: option string) : ML string =
mk_app "bv2int" (Some (mk_app op bitvec_args))
let integer_type_bit_size = function
| A.UInt8 -> 8
| A.UInt16 -> 16
| A.UInt32 -> 32
| A.UInt64 -> 64
let mk_bitwise_not (a: A.integer_type) (bitvec_arg: option string) : ML string =
match bitvec_arg with
| None -> failwith "ill-formed bitwise_not"
| Some arg -> "(bv2int (bvxor "^arg^" #b"^String.make (integer_type_bit_size a) '1'^"))"
let mk_op : T.op -> option string -> ML string = function
| T.Eq -> mk_app "="
| T.Neq -> (fun s -> mk_app "not" (Some (mk_app "=" s)))
| T.And -> mk_app "and"
| T.Or -> mk_app "or"
| T.Not -> mk_app "not"
| T.Plus _ -> mk_app "+"
| T.Minus _ -> mk_app "-"
| T.Mul _ -> mk_app "*"
| T.Division _ -> mk_app "div"
| T.Remainder _ -> mk_app "mod"
| T.BitwiseAnd _ -> mk_bitwise_op "bvand"
| T.BitwiseXor _ -> mk_bitwise_op "bvxor"
| T.BitwiseOr _ -> mk_bitwise_op "bvor"
| T.BitwiseNot a -> mk_bitwise_not a
| T.ShiftLeft _ -> mk_bitwise_op "bvshl"
| T.ShiftRight _ -> mk_bitwise_op "bvlshr"
| T.LT _ -> mk_app "<"
| T.GT _ -> mk_app ">"
| T.LE _ -> mk_app "<="
| T.GE _ -> mk_app ">="
| T.IfThenElse -> mk_app "if"
| T.BitFieldOf size order -> (fun arg -> Printf.sprintf "(get-bitfield-%ssb %d %s)" (match order with A.LSBFirst -> "l" | A.MSBFirst -> "m") size (assert_some arg))
| T.Cast _ _ -> assert_some (* casts allowed only if they are proven not to lose precision *)
| T.Ext s -> mk_app s
let ident_to_string = A.ident_to_string
let mk_bitwise_arg (t: A.integer_type) (arg: string) : Tot string =
mk_app ("(_ int2bv "^string_of_int (integer_type_bit_size t)^")") (Some arg)
let mk_maybe_bitwise_arg (t: option A.integer_type) (arg: string) : Tot string =
match t with
| None -> arg
| Some t -> mk_bitwise_arg t arg
let rec mk_expr (e: T.expr) : ML string = match fst e with
| T.Constant c -> mk_constant c
| T.Identifier i -> ident_to_string i
| T.App hd args -> mk_op hd (mk_args (is_bitwise_op hd) args)
| _ -> failwith "mk_expr: not supported"
and mk_args_aux (is_bitwise_op: option A.integer_type) accu : (list T.expr -> ML string) = function
| [] -> accu
| a :: q -> mk_args_aux is_bitwise_op (Printf.sprintf "%s %s" accu (mk_maybe_bitwise_arg is_bitwise_op (mk_expr a))) q
and mk_args (is_bitwise_op: option A.integer_type) (l: list T.expr) : ML (option string) = match l with
| [] -> None
| a :: q -> Some (mk_args_aux is_bitwise_op (mk_maybe_bitwise_arg is_bitwise_op (mk_expr a)) q)
type reading = { call: string }
type not_reading = { call: string }
type binders = {
is_empty: bool;
bind: string;
args: string;
}
let empty_binders : binders = {
is_empty = true;
bind = "";
args = "";
}
let push_binder (name: string) (typ: string) (b: binders) : binders = {
is_empty = false;
bind = Printf.sprintf "(%s %s) %s" name typ b.bind;
args = Printf.sprintf " %s%s" name b.args;
}
let mk_function_call (name: string) (b: binders) =
Printf.sprintf "%s%s" name b.args
type parser (a: Type) =
(* name *) string ->
(* binders *) binders ->
(* is_toplevel *) bool ->
(* out *) (string -> ML unit) ->
ML a
let unsupported_parser (s: string) (a: Type) : Tot (parser a) =
fun _ _ _ _ -> failwith (Printf.sprintf "unsupported parser: %s" s)
let leaf_reading_parser (name: string) : parser reading =
fun _ _ _ _ -> { call = name }
let readable_itype_parser_suffix (i: I.itype) : Tot string = match i with
| I.UInt8 | I.UInt8BE -> "u8"
| I.UInt16 -> "u16-le"
| I.UInt16BE -> "u16-be"
| I.UInt32 -> "u32-le"
| I.UInt32BE -> "u32-be"
| I.UInt64 -> "u64-le"
| I.UInt64BE -> "u64-be"
| I.Unit -> "empty"
| I.AllBytes -> "all-bytes"
| I.AllZeros -> "all-zeros"
let parse_readable_itype (i: I.readable_itype) : Tot (parser reading) =
leaf_reading_parser ("parse-" ^ readable_itype_parser_suffix i)
let mk_wrap_parser
(name: string)
(binders: string)
(body: string)
: string
= let input = Printf.sprintf "%s-input" name in
let tmp = Printf.sprintf "%s-tmp" name in
"(define-fun "^name^" ("^binders^"("^input^" State)) State
(after-state ("^body^" "^input^"))
)
"
let wrap_parser (p: parser reading) : parser not_reading =
fun name binders _ out ->
let name' = Printf.sprintf "%s-wrapped" name in
let body = p name' binders false out in
out (mk_wrap_parser name binders.bind body.call);
{ call = mk_function_call name binders }
let mk_toplevel_parser
(name: string)
(binders: string)
(body: string)
: string
= let input = Printf.sprintf "%s-input" name in
"(define-fun "^name^" ("^binders^"("^input^" State)) State
("^body^" "^input^")
)
"
let maybe_toplevel_parser (p: parser not_reading) : parser not_reading =
fun name binders is_toplevel out ->
if is_toplevel
then begin
let name' = Printf.sprintf "%s-body" name in
let body = p name' binders false out in
out (mk_toplevel_parser name binders.bind body.call);
{ call = mk_function_call name binders }
end
else p name binders false out
let parse_all_bytes : parser not_reading =
maybe_toplevel_parser (fun _ _ _ _ -> { call = "parse-all-bytes" })
let parse_all_zeros : parser not_reading =
maybe_toplevel_parser (fun _ _ _ _ -> { call = "parse-all-zeros" })
let parse_itype : I.itype -> parser not_reading = function
| I.AllBytes -> parse_all_bytes
| I.AllZeros -> parse_all_zeros
| i -> wrap_parser (parse_readable_itype i)
let mk_app_without_paren id args =
mk_args_aux None (ident_to_string id) args
let parse_readable_app
(hd: A.ident)
(args: list I.expr)
: Tot (parser reading)
= fun _ _ _ _ -> { call = mk_app_without_paren hd args }
let parse_readable_dtyp
(d: I.readable_dtyp)
: Tot (parser reading)
= match d with
| I.DT_IType i -> parse_readable_itype i
| I.DT_App _ hd args -> parse_readable_app hd args
let parse_not_readable_app
(hd: A.ident)
(args: list I.expr)
: Tot (parser not_reading)
= maybe_toplevel_parser (fun _ _ _ _ -> { call = mk_app_without_paren hd args })
let parse_dtyp
(d: I.dtyp)
: Tot (parser not_reading)
= if I.allow_reader_of_dtyp d
then wrap_parser (parse_readable_dtyp d)
else match d with
| I.DT_IType i -> parse_itype i
| I.DT_App _ hd args -> parse_not_readable_app hd args
let parse_false : parser not_reading =
maybe_toplevel_parser (fun _ _ _ _ -> { call = "parse-false" })
let parse_denoted (d: I.dtyp) : parser not_reading =
parse_dtyp d
let mk_parse_pair
(name: string)
(binders: string)
(fst: string)
(snd: string)
: string
= let input = Printf.sprintf "%s-input" name in
let tmp = Printf.sprintf "%s-tmp" name in
"(define-fun "^name^" ("^binders^"("^input^" State)) State
(let (("^tmp^" ("^fst^" "^input^")))
(if (< (input-size "^tmp^") 0)
"^tmp^"
("^snd^" "^tmp^")
)
)
)
"
let parse_pair (fst: parser not_reading) (snd: parser not_reading) : parser not_reading =
fun name binders _ out ->
let name_fst = Printf.sprintf "%s-fst" name in
let body_fst = fst name_fst binders false out in
let name_snd = Printf.sprintf "%s-snd" name in
let body_snd = snd name_snd binders false out in
out (mk_parse_pair name binders.bind body_fst.call body_snd.call);
{ call = mk_function_call name binders }
let parse_square (p: parser not_reading) : parser not_reading =
fun name binders _ out ->
let body_name = Printf.sprintf "%s-snd" name in
let body = p body_name binders false out in
out (mk_parse_pair name binders.bind body.call body.call);
{ call = mk_function_call name binders }
let mk_parse_dep_pair_with_refinement
(name: string)
(binders: string)
(dfst: string)
(cond_binder_name: string)
(cond: string)
(dsnd_binder_name: string)
(dsnd: string) (* already contains the new argument *)
: string
= let input = Printf.sprintf "%s-input" name in
let tmp = Printf.sprintf "%s-tmp" name in
"(define-fun "^name^" ("^binders^"("^input^" State)) State
(let (("^tmp^" ("^dfst^" "^input^")))
(if (< (input-size (after-state "^tmp^")) 0)
(after-state "^tmp^")
(if (let (("^cond_binder_name^" (return-value "^tmp^"))) "^cond^")
(let (("^dsnd_binder_name^" (return-value "^tmp^")))
("^dsnd^" (after-state "^tmp^"))
)
(mk-state -1 (choice-index (after-state "^tmp^")))
)
)
)
)
"
let parse_dep_pair_with_refinement_gen (tag: parser reading) (cond_binder: string) (cond: unit -> ML string) (payload_binder: string) (payload: parser not_reading) : parser not_reading =
fun name binders _ out ->
let name_tag = Printf.sprintf "%s-tag" name in
let body_tag = tag name_tag binders false out in
let binders' = push_binder payload_binder "Int" binders in (* TODO: support more types *)
let name_payload = Printf.sprintf "%s-payload" name in
let body_payload = payload name_payload binders' false out in
out (mk_parse_dep_pair_with_refinement name binders.bind body_tag.call cond_binder (cond ()) payload_binder body_payload.call);
{ call = mk_function_call name binders }
let parse_dep_pair_with_refinement (tag: parser reading) (cond_binder: A.ident) (cond: unit -> ML string) (payload_binder: A.ident) (payload: parser not_reading) : parser not_reading =
parse_dep_pair_with_refinement_gen tag (ident_to_string cond_binder) cond (ident_to_string payload_binder) payload
let parse_dep_pair (tag: parser reading) (new_binder: A.ident) (payload: parser not_reading) : parser not_reading =
parse_dep_pair_with_refinement tag new_binder (fun _ -> "true") new_binder payload
let parse_refine (tag: parser reading) (cond_binder: A.ident) (cond: unit -> ML string) : parser not_reading =
parse_dep_pair_with_refinement tag cond_binder cond cond_binder (parse_itype I.Unit)
let mk_parse_ifthenelse
(name: string)
(binders: string)
(cond: string)
(f_then: string)
(f_else: string)
: string
= let input = Printf.sprintf "%s-input" name in
"(define-fun "^name^" ("^binders^"("^input^" State)) State
(if "^cond^"
("^f_then^" "^input^")
("^f_else^" "^input^")
)
)
"
let parse_ifthenelse (cond: unit -> ML string) (pthen: parser not_reading) (pelse: parser not_reading) : parser not_reading =
fun name binders _ out ->
let name_then = Printf.sprintf "%s-then" name in
let body_then = pthen name_then binders false out in
let name_else = Printf.sprintf "%s-else" name in
let body_else = pelse name_else binders false out in
out (mk_parse_ifthenelse name binders.bind (cond ()) body_then.call body_else.call);
{ call = mk_function_call name binders }
let mk_parse_exact
(name: string)
(binders: string)
(body: string)
(size: string)
: string
= let input = Printf.sprintf "%s-input" name in
let sz = Printf.sprintf "%s-size" name in
let res = Printf.sprintf "%s-res" name in
"(define-fun "^name^" ("^binders^"("^input^" State)) State
(let (("^sz^" "^size^"))
(if (< (input-size "^input^") "^sz^")
(mk-state -1 (choice-index "^input^"))
(let (("^res^" ("^body^" (mk-state "^sz^" (choice-index "^input^")))))
(mk-state
(if (= (input-size "^res^") 0)
(- (input-size "^input^") "^sz^")
-1
)
(choice-index "^res^")
)
)
)
)
)
"
let parse_exact
(size: unit -> ML string)
(body: parser not_reading)
: Tot (parser not_reading)
= fun name binders _ out ->
let body_name = Printf.sprintf "%s-body" name in
let body = body body_name binders false out in
out (mk_parse_exact name binders.bind body.call (size ()));
{ call = mk_function_call name binders }
let parse_at_most
(size: unit -> ML string)
(body: parser not_reading)
: Tot (parser not_reading)
= parse_exact size (parse_pair body parse_all_bytes)
(*
let mk_parse_list_one
(name: string)
(binders: string)
(p: string)
: string
= let input = Printf.sprintf "%s-input" name in
let res = Printf.sprintf "%s-res" name in
"(define-fun "^name^" ("^binders^"("^input^" (Seq Int))) (Seq Int)
(if (= (seq.len "^input^") 0)
(seq.unit 0)
(let (("^res^" ("^p^" "^input^")))
(if (= (seq.len "^res^") 0)
(as seq.empty (Seq Int))
(if (= (seq.nth "^res^" 0) 0)
(as seq.empty (Seq Int))
"^res^"
)
)
)
)
)
"
let parse_list_one
(body: parser not_reading)
: Tot (parser not_reading)
= fun name binders _ out ->
let body_name = Printf.sprintf "%s-body" name in
let body = body body_name binders false out in
out (mk_parse_list_one name binders.bind body.call);
{ call = mk_function_call name binders }
let rec parse_list_bounded'
(body: parser not_reading)
(logn: nat)
: Tot (parser not_reading)
(decreases logn)
= if logn = 0
then parse_list_one body
else
let logn' = logn - 1 in
parse_square (parse_list_bounded' body logn')
let parse_list_bounded body = parse_list_bounded' body 3 // 64
*)
let mk_parse_list
(name: string)
(rec_call: string)
(binders: string)
(body: string)
: string
= let input = Printf.sprintf "%s-input" name in
"(define-fun-rec "^name^" ("^binders^"("^input^" State)) State
(if (<= (input-size "^input^") 0)
"^input^"
("^rec_call^" ("^body^" "^input^"))
)
)
"
let parse_list
(body: parser not_reading)
: Tot (parser not_reading)
= fun name binders _ out ->
let rec_call = mk_function_call name binders in
let body_name = Printf.sprintf "%s-body" name in
let body = body body_name binders false out in
out (mk_parse_list name rec_call binders.bind body.call);
{ call = rec_call }
let parse_nlist
(size: unit -> ML string)
(body: parser not_reading)
: Tot (parser not_reading)
= parse_exact size (parse_list body)
let mk_parse_string
(name: string)
(rec_call: string)
(binders: string)
(body: string)
(terminator: string)
: string
= let input = Printf.sprintf "%s-input" name in
let tmp = Printf.sprintf "%s-tmp" name in
"(define-fun-rec "^name^" ("^binders^"("^input^" State)) State
(let (("^tmp^" ("^body^" "^input^")))
(if (< (choice-index (after-state "^tmp^")) 0)
(mk-state -1 (choice-index (after-state "^tmp^")))
(if (= (return-value "^tmp^") "^terminator^")
(after-state "^tmp^")
("^rec_call^" (after-state "^tmp^"))
)
)
)
)
"
let parse_string
(body: parser reading)
(terminator: (unit -> ML string))
: Tot (parser not_reading)
= fun name binders _ out ->
let rec_call = mk_function_call name binders in
let body_name = Printf.sprintf "%s-body" name in
let body = body body_name binders false out in
out (mk_parse_string name rec_call binders.bind body.call (terminator ()));
{ call = rec_call }
let rec type_has_actions = function
| I.T_with_dep_action _ _ _
| I.T_dep_pair_with_action _ _ _ _
| I.T_refine_with_action _ _ _ _
| I.T_dep_pair_with_refinement_and_action _ _ _ _ _
| I.T_with_action _ _ _
-> true
| I.T_false _
| I.T_denoted _ _
| I.T_refine _ _ _
| I.T_string _ _ _
-> false
| I.T_if_else _ t1 t2
| I.T_pair _ t1 t2 ->
type_has_actions t1 || type_has_actions t2
| I.T_at_most _ _ t
| I.T_exact _ _ t
| I.T_nlist _ _ t
| I.T_with_comment _ t _
| I.T_dep_pair_with_refinement _ _ _ (_, t)
| I.T_dep_pair _ _ (_, t) ->
type_has_actions t
let rec parse_typ (t : I.typ) : Pure (parser not_reading)
(requires (type_has_actions t == false))
(ensures (fun _ -> True))
= match t with
| I.T_false _ -> parse_false
| I.T_denoted _ d -> parse_denoted d
| I.T_pair _ t1 t2 -> parse_pair (parse_typ t1) (parse_typ t2)
| I.T_dep_pair _ t1 (lam, t2) -> parse_dep_pair (parse_readable_dtyp t1) lam (parse_typ t2)
| I.T_refine _ base (lam, cond) -> parse_refine (parse_readable_dtyp base) lam (fun _ -> mk_expr cond)
| I.T_dep_pair_with_refinement _ base (lam_cond, cond) (lam_k, k) -> parse_dep_pair_with_refinement (parse_readable_dtyp base) lam_cond (fun _ -> mk_expr cond) lam_k (parse_typ k)
| I.T_if_else cond t1 t2 -> parse_ifthenelse (fun _ -> mk_expr cond) (parse_typ t1) (parse_typ t2)
| I.T_with_comment _ base _ -> parse_typ base
| I.T_at_most _ size body -> parse_at_most (fun _ -> mk_expr size) (parse_typ body)
| I.T_exact _ size body -> parse_exact (fun _ -> mk_expr size) (parse_typ body)
| I.T_string _ elt terminator -> parse_string (parse_readable_dtyp elt) (fun _ -> mk_expr terminator)
| I.T_nlist _ size body -> parse_nlist (fun _ -> mk_expr size) (parse_typ body)
type arg_type =
| ArgInt of A.integer_type
| ArgBool
| ArgPointer
let arg_type_of_typ (t: T.typ) : Tot (option arg_type) =
match t with
| T.T_pointer _
| T.T_app _ A.KindOutput _
| T.T_app _ A.KindExtern _
| T.T_app {v = {modul_name = None; name = "PUINT8"}} _ _
-> Some ArgPointer
| T.T_app {v = {modul_name = None; name = "Bool"}} _ _
-> Some ArgBool
| T.T_app i _ _
->
begin match A.maybe_as_integer_typ i with
| Some t -> Some (ArgInt t)
| None -> None
end
| _ -> None
let smt_type_of_typ (t: T.typ) : Tot string =
match arg_type_of_typ t with
| Some ArgBool -> "Bool"
| _ -> "Int"
let rec binders_of_params = function
| [] -> empty_binders
| (id, t) :: q -> push_binder (ident_to_string id) (smt_type_of_typ t) (binders_of_params q)
let mk_definition
(name: string)
(binders: string)
(typ: string)
(body: string)
: Tot string
= "(define-fun "^name^" ("^binders^") "^typ^" "^body^")"
let produce_definition
(i: A.ident)
(param: list T.param)
(typ: T.typ)
(body: T.expr)
(out: string -> ML unit)
: ML unit
= let binders = binders_of_params param in
out (mk_definition (ident_to_string i) binders.bind (smt_type_of_typ typ) (mk_expr body))
let produce_not_type_decl (a: I.not_type_decl) (out: string -> ML unit) : ML unit =
match fst a with
| T.Definition (i, param, typ, body) ->
produce_definition i param typ body out
| T.Assumption _ -> failwith "produce_not_type_decl: unsupported"
| T.Output_type _
| T.Output_type_expr _ _
| T.Extern_type _
| T.Extern_fn _ _ _
-> ()
let prog = list (string & list arg_type)
let produce_type_decl (out: string -> ML unit) (accu: prog) (a: I.type_decl) : ML prog =
let binders = binders_of_params a.name.td_params in
let name = ident_to_string a.name.td_name in
if type_has_actions a.typ then failwith (Printf.sprintf "produce_type_decl: %s still has some actions" name);
let _ = parse_typ a.typ name binders true out in
(name, List.map (fun (i, ty) -> match arg_type_of_typ ty with Some t -> t | None -> failwith (Printf.sprintf "Parser %s has unsupported argument type for %s" name (ident_to_string i))) a.name.td_params) :: accu | false | false | Z3TestGen.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val produce_decl (out: (string -> ML unit)) (accu: prog) (a: I.decl) : ML prog | [] | Z3TestGen.produce_decl | {
"file_name": "src/3d/Z3TestGen.fst",
"git_rev": "446a08ce38df905547cf20f28c43776b22b8087a",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} |
out: (_: Prims.string -> FStar.All.ML Prims.unit) ->
accu: Z3TestGen.prog ->
a: InterpreterTarget.decl
-> FStar.All.ML Z3TestGen.prog | {
"end_col": 41,
"end_line": 816,
"start_col": 2,
"start_line": 814
} |
FStar.All.ML | val produce_type_decl (out: (string -> ML unit)) (accu: prog) (a: I.type_decl) : ML prog | [
{
"abbrev": true,
"full_module": "InterpreterTarget",
"short_module": "I"
},
{
"abbrev": true,
"full_module": "Target",
"short_module": "T"
},
{
"abbrev": true,
"full_module": "Ast",
"short_module": "A"
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.All",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.Printf",
"short_module": "Printf"
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let produce_type_decl (out: string -> ML unit) (accu: prog) (a: I.type_decl) : ML prog =
let binders = binders_of_params a.name.td_params in
let name = ident_to_string a.name.td_name in
if type_has_actions a.typ then failwith (Printf.sprintf "produce_type_decl: %s still has some actions" name);
let _ = parse_typ a.typ name binders true out in
(name, List.map (fun (i, ty) -> match arg_type_of_typ ty with Some t -> t | None -> failwith (Printf.sprintf "Parser %s has unsupported argument type for %s" name (ident_to_string i))) a.name.td_params) :: accu | val produce_type_decl (out: (string -> ML unit)) (accu: prog) (a: I.type_decl) : ML prog
let produce_type_decl (out: (string -> ML unit)) (accu: prog) (a: I.type_decl) : ML prog = | true | null | false | let binders = binders_of_params a.name.td_params in
let name = ident_to_string a.name.td_name in
if type_has_actions a.typ
then failwith (Printf.sprintf "produce_type_decl: %s still has some actions" name);
let _ = parse_typ a.typ name binders true out in
(name,
List.map (fun (i, ty) ->
match arg_type_of_typ ty with
| Some t -> t
| None ->
failwith (Printf.sprintf "Parser %s has unsupported argument type for %s"
name
(ident_to_string i)))
a.name.td_params) ::
accu | {
"checked_file": "Z3TestGen.fst.checked",
"dependencies": [
"Z3.fsti.checked",
"Target.fsti.checked",
"prims.fst.checked",
"OS.fsti.checked",
"Lisp.fsti.checked",
"InterpreterTarget.fsti.checked",
"FStar.String.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Printf.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.List.Tot.fst.checked",
"FStar.List.fst.checked",
"FStar.IO.fst.checked",
"FStar.Char.fsti.checked",
"FStar.All.fst.checked",
"Ast.fst.checked"
],
"interface_file": false,
"source_file": "Z3TestGen.fst"
} | [
"ml"
] | [
"Prims.string",
"Prims.unit",
"Z3TestGen.prog",
"InterpreterTarget.type_decl",
"Prims.Cons",
"FStar.Pervasives.Native.tuple2",
"Prims.list",
"Z3TestGen.arg_type",
"FStar.Pervasives.Native.Mktuple2",
"FStar.List.map",
"Ast.with_meta_t",
"Ast.ident'",
"Target.typ",
"Z3TestGen.arg_type_of_typ",
"FStar.All.failwith",
"FStar.Printf.sprintf",
"Z3TestGen.ident_to_string",
"Target.__proj__Mktypedef_name__item__td_params",
"InterpreterTarget.__proj__Mktype_decl__item__name",
"Z3TestGen.not_reading",
"Z3TestGen.parse_typ",
"InterpreterTarget.__proj__Mktype_decl__item__typ",
"Z3TestGen.type_has_actions",
"Prims.bool",
"Target.__proj__Mktypedef_name__item__td_name",
"Z3TestGen.binders",
"Z3TestGen.binders_of_params"
] | [] | module Z3TestGen
module Printf = FStar.Printf
open FStar.All
open FStar.Mul
module A = Ast
module T = Target
module I = InterpreterTarget
let prelude : string =
"
(set-option :produce-models true)
(declare-datatypes () ((State (mk-state (input-size Int) (choice-index Int)))))
(declare-datatypes () ((Result (mk-result (return-value Int) (after-state State)))))
(define-fun parse-empty ((x State)) Result
(mk-result 0 x)
)
(declare-fun choose (Int) Int)
(assert (forall ((i Int))
(and (<= 0 (choose i)) (< (choose i) 256))
))
(define-fun parse-false ((x State)) State
(mk-state -1 (choice-index x))
)
(define-fun parse-all-bytes ((x State)) State
(if (<= (input-size x) 0)
x
(mk-state 0 (+ (choice-index x) (input-size x)))
)
)
(define-fun parse-all-zeros ((x State)) State
(if (<= (input-size x) 0)
x
(mk-state
(if
(forall ((j Int))
(if (and (<= 0 j) (< j (input-size x)))
(= (choose (+ (choice-index x) j)) 0)
true
)
)
0
-1
)
(+ (choice-index x) (input-size x))
)
)
)
(define-fun parse-u8 ((x State)) Result
(mk-result
(choose (choice-index x))
(mk-state (- (input-size x) 1) (+ (choice-index x) 1))
)
)
(define-fun parse-u16-be ((x State)) Result
(mk-result
(+ (choose (+ 1 (choice-index x)))
(* 256
(choose (+ 0 (choice-index x)))
)
)
(mk-state (- (input-size x) 2) (+ (choice-index x) 2))
)
)
(define-fun parse-u16-le ((x State)) Result
(mk-result
(+ (choose (+ 0 (choice-index x)))
(* 256
(choose (+ 1 (choice-index x)))
)
)
(mk-state (- (input-size x) 2) (+ (choice-index x) 2))
)
)
(define-fun parse-u32-be ((x State)) Result
(mk-result
(+ (choose (+ 3 (choice-index x)))
(* 256
(+ (choose (+ 2 (choice-index x)))
(* 256
(+ (choose (+ 1 (choice-index x)))
(* 256
(choose (+ 0 (choice-index x)))
)
)
)
)
)
)
(mk-state (- (input-size x) 4) (+ (choice-index x) 4))
)
)
(define-fun parse-u32-le ((x State)) Result
(mk-result
(+ (choose (+ 0 (choice-index x)))
(* 256
(+ (choose (+ 1 (choice-index x)))
(* 256
(+ (choose (+ 2 (choice-index x)))
(* 256
(choose (+ 3 (choice-index x)))
)
)
)
)
)
)
(mk-state (- (input-size x) 4) (+ (choice-index x) 4))
)
)
(define-fun parse-u64-be ((x State)) Result
(mk-result
(+ (choose (+ 7 (choice-index x)))
(* 256
(+ (choose (+ 6 (choice-index x)))
(* 256
(+ (choose (+ 5 (choice-index x)))
(* 256
(+ (choose (+ 4 (choice-index x)))
(* 256
(+ (choose (+ 3 (choice-index x)))
(* 256
(+ (choose (+ 2 (choice-index x)))
(* 256
(+ (choose (+ 1 (choice-index x)))
(* 256
(choose (+ 0 (choice-index x)))
)
)
)
)
)
)
)
)
)
)
)
)
)
)
(mk-state (- (input-size x) 8) (+ (choice-index x) 8))
)
)
(define-fun parse-u64-le ((x State)) Result
(mk-result
(+ (choose (+ 0 (choice-index x)))
(* 256
(+ (choose (+ 1 (choice-index x)))
(* 256
(+ (choose (+ 2 (choice-index x)))
(* 256
(+ (choose (+ 3 (choice-index x)))
(* 256
(+ (choose (+ 4 (choice-index x)))
(* 256
(+ (choose (+ 5 (choice-index x)))
(* 256
(+ (choose (+ 6 (choice-index x)))
(* 256
(choose (+ 7 (choice-index x)))
)
)
)
)
)
)
)
)
)
)
)
)
)
)
(mk-state (- (input-size x) 8) (+ (choice-index x) 8))
)
)
(define-fun-rec pow-2 ((amount Int)) Int
(if (<= amount 0)
1
(* 2 (pow-2 (- amount 1)))
)
)
;; see LowParse.BitFields.get_bitfield_eq
(define-fun get-bitfield-lsb ((nbBits Int) (value Int) (bitsFrom Int) (bitsTo Int)) Int
(mod (div value (pow-2 bitsFrom)) (pow-2 (- bitsTo bitsFrom)))
)
;; see EverParse3d.Prelude.StaticHeader
(define-fun get-bitfield-msb ((nbBits Int) (value Int) (bitsFrom Int) (bitsTo Int)) Int
(get-bitfield-lsb nbBits value (- nbBits bitsTo) (- nbBits bitsFrom))
)
(declare-const initial-input-size Int)
(assert (>= initial-input-size 0))
(define-fun initial-state () State (mk-state initial-input-size 0))
"
let mk_constant = function
| A.Unit -> "0"
| A.Int _ x -> string_of_int x
| A.XInt _ x -> string_of_int (OS.int_of_string x)
| A.Bool true -> "true"
| A.Bool false -> "false"
let mk_app fn = function
| None -> fn
| Some args -> Printf.sprintf "(%s %s)" fn args
let assert_some = function
| None -> failwith "assert_some"
| Some x -> x
let is_bitwise_op (x: T.op) : Tot (option A.integer_type) =
match x with
| T.BitwiseAnd a
| T.BitwiseXor a
| T.BitwiseOr a
| T.BitwiseNot a
| T.ShiftLeft a
| T.ShiftRight a
-> Some a
| _ -> None
let mk_bitwise_op (op: string) (bitvec_args: option string) : ML string =
mk_app "bv2int" (Some (mk_app op bitvec_args))
let integer_type_bit_size = function
| A.UInt8 -> 8
| A.UInt16 -> 16
| A.UInt32 -> 32
| A.UInt64 -> 64
let mk_bitwise_not (a: A.integer_type) (bitvec_arg: option string) : ML string =
match bitvec_arg with
| None -> failwith "ill-formed bitwise_not"
| Some arg -> "(bv2int (bvxor "^arg^" #b"^String.make (integer_type_bit_size a) '1'^"))"
let mk_op : T.op -> option string -> ML string = function
| T.Eq -> mk_app "="
| T.Neq -> (fun s -> mk_app "not" (Some (mk_app "=" s)))
| T.And -> mk_app "and"
| T.Or -> mk_app "or"
| T.Not -> mk_app "not"
| T.Plus _ -> mk_app "+"
| T.Minus _ -> mk_app "-"
| T.Mul _ -> mk_app "*"
| T.Division _ -> mk_app "div"
| T.Remainder _ -> mk_app "mod"
| T.BitwiseAnd _ -> mk_bitwise_op "bvand"
| T.BitwiseXor _ -> mk_bitwise_op "bvxor"
| T.BitwiseOr _ -> mk_bitwise_op "bvor"
| T.BitwiseNot a -> mk_bitwise_not a
| T.ShiftLeft _ -> mk_bitwise_op "bvshl"
| T.ShiftRight _ -> mk_bitwise_op "bvlshr"
| T.LT _ -> mk_app "<"
| T.GT _ -> mk_app ">"
| T.LE _ -> mk_app "<="
| T.GE _ -> mk_app ">="
| T.IfThenElse -> mk_app "if"
| T.BitFieldOf size order -> (fun arg -> Printf.sprintf "(get-bitfield-%ssb %d %s)" (match order with A.LSBFirst -> "l" | A.MSBFirst -> "m") size (assert_some arg))
| T.Cast _ _ -> assert_some (* casts allowed only if they are proven not to lose precision *)
| T.Ext s -> mk_app s
let ident_to_string = A.ident_to_string
let mk_bitwise_arg (t: A.integer_type) (arg: string) : Tot string =
mk_app ("(_ int2bv "^string_of_int (integer_type_bit_size t)^")") (Some arg)
let mk_maybe_bitwise_arg (t: option A.integer_type) (arg: string) : Tot string =
match t with
| None -> arg
| Some t -> mk_bitwise_arg t arg
let rec mk_expr (e: T.expr) : ML string = match fst e with
| T.Constant c -> mk_constant c
| T.Identifier i -> ident_to_string i
| T.App hd args -> mk_op hd (mk_args (is_bitwise_op hd) args)
| _ -> failwith "mk_expr: not supported"
and mk_args_aux (is_bitwise_op: option A.integer_type) accu : (list T.expr -> ML string) = function
| [] -> accu
| a :: q -> mk_args_aux is_bitwise_op (Printf.sprintf "%s %s" accu (mk_maybe_bitwise_arg is_bitwise_op (mk_expr a))) q
and mk_args (is_bitwise_op: option A.integer_type) (l: list T.expr) : ML (option string) = match l with
| [] -> None
| a :: q -> Some (mk_args_aux is_bitwise_op (mk_maybe_bitwise_arg is_bitwise_op (mk_expr a)) q)
type reading = { call: string }
type not_reading = { call: string }
type binders = {
is_empty: bool;
bind: string;
args: string;
}
let empty_binders : binders = {
is_empty = true;
bind = "";
args = "";
}
let push_binder (name: string) (typ: string) (b: binders) : binders = {
is_empty = false;
bind = Printf.sprintf "(%s %s) %s" name typ b.bind;
args = Printf.sprintf " %s%s" name b.args;
}
let mk_function_call (name: string) (b: binders) =
Printf.sprintf "%s%s" name b.args
type parser (a: Type) =
(* name *) string ->
(* binders *) binders ->
(* is_toplevel *) bool ->
(* out *) (string -> ML unit) ->
ML a
let unsupported_parser (s: string) (a: Type) : Tot (parser a) =
fun _ _ _ _ -> failwith (Printf.sprintf "unsupported parser: %s" s)
let leaf_reading_parser (name: string) : parser reading =
fun _ _ _ _ -> { call = name }
let readable_itype_parser_suffix (i: I.itype) : Tot string = match i with
| I.UInt8 | I.UInt8BE -> "u8"
| I.UInt16 -> "u16-le"
| I.UInt16BE -> "u16-be"
| I.UInt32 -> "u32-le"
| I.UInt32BE -> "u32-be"
| I.UInt64 -> "u64-le"
| I.UInt64BE -> "u64-be"
| I.Unit -> "empty"
| I.AllBytes -> "all-bytes"
| I.AllZeros -> "all-zeros"
let parse_readable_itype (i: I.readable_itype) : Tot (parser reading) =
leaf_reading_parser ("parse-" ^ readable_itype_parser_suffix i)
let mk_wrap_parser
(name: string)
(binders: string)
(body: string)
: string
= let input = Printf.sprintf "%s-input" name in
let tmp = Printf.sprintf "%s-tmp" name in
"(define-fun "^name^" ("^binders^"("^input^" State)) State
(after-state ("^body^" "^input^"))
)
"
let wrap_parser (p: parser reading) : parser not_reading =
fun name binders _ out ->
let name' = Printf.sprintf "%s-wrapped" name in
let body = p name' binders false out in
out (mk_wrap_parser name binders.bind body.call);
{ call = mk_function_call name binders }
let mk_toplevel_parser
(name: string)
(binders: string)
(body: string)
: string
= let input = Printf.sprintf "%s-input" name in
"(define-fun "^name^" ("^binders^"("^input^" State)) State
("^body^" "^input^")
)
"
let maybe_toplevel_parser (p: parser not_reading) : parser not_reading =
fun name binders is_toplevel out ->
if is_toplevel
then begin
let name' = Printf.sprintf "%s-body" name in
let body = p name' binders false out in
out (mk_toplevel_parser name binders.bind body.call);
{ call = mk_function_call name binders }
end
else p name binders false out
let parse_all_bytes : parser not_reading =
maybe_toplevel_parser (fun _ _ _ _ -> { call = "parse-all-bytes" })
let parse_all_zeros : parser not_reading =
maybe_toplevel_parser (fun _ _ _ _ -> { call = "parse-all-zeros" })
let parse_itype : I.itype -> parser not_reading = function
| I.AllBytes -> parse_all_bytes
| I.AllZeros -> parse_all_zeros
| i -> wrap_parser (parse_readable_itype i)
let mk_app_without_paren id args =
mk_args_aux None (ident_to_string id) args
let parse_readable_app
(hd: A.ident)
(args: list I.expr)
: Tot (parser reading)
= fun _ _ _ _ -> { call = mk_app_without_paren hd args }
let parse_readable_dtyp
(d: I.readable_dtyp)
: Tot (parser reading)
= match d with
| I.DT_IType i -> parse_readable_itype i
| I.DT_App _ hd args -> parse_readable_app hd args
let parse_not_readable_app
(hd: A.ident)
(args: list I.expr)
: Tot (parser not_reading)
= maybe_toplevel_parser (fun _ _ _ _ -> { call = mk_app_without_paren hd args })
let parse_dtyp
(d: I.dtyp)
: Tot (parser not_reading)
= if I.allow_reader_of_dtyp d
then wrap_parser (parse_readable_dtyp d)
else match d with
| I.DT_IType i -> parse_itype i
| I.DT_App _ hd args -> parse_not_readable_app hd args
let parse_false : parser not_reading =
maybe_toplevel_parser (fun _ _ _ _ -> { call = "parse-false" })
let parse_denoted (d: I.dtyp) : parser not_reading =
parse_dtyp d
let mk_parse_pair
(name: string)
(binders: string)
(fst: string)
(snd: string)
: string
= let input = Printf.sprintf "%s-input" name in
let tmp = Printf.sprintf "%s-tmp" name in
"(define-fun "^name^" ("^binders^"("^input^" State)) State
(let (("^tmp^" ("^fst^" "^input^")))
(if (< (input-size "^tmp^") 0)
"^tmp^"
("^snd^" "^tmp^")
)
)
)
"
let parse_pair (fst: parser not_reading) (snd: parser not_reading) : parser not_reading =
fun name binders _ out ->
let name_fst = Printf.sprintf "%s-fst" name in
let body_fst = fst name_fst binders false out in
let name_snd = Printf.sprintf "%s-snd" name in
let body_snd = snd name_snd binders false out in
out (mk_parse_pair name binders.bind body_fst.call body_snd.call);
{ call = mk_function_call name binders }
let parse_square (p: parser not_reading) : parser not_reading =
fun name binders _ out ->
let body_name = Printf.sprintf "%s-snd" name in
let body = p body_name binders false out in
out (mk_parse_pair name binders.bind body.call body.call);
{ call = mk_function_call name binders }
let mk_parse_dep_pair_with_refinement
(name: string)
(binders: string)
(dfst: string)
(cond_binder_name: string)
(cond: string)
(dsnd_binder_name: string)
(dsnd: string) (* already contains the new argument *)
: string
= let input = Printf.sprintf "%s-input" name in
let tmp = Printf.sprintf "%s-tmp" name in
"(define-fun "^name^" ("^binders^"("^input^" State)) State
(let (("^tmp^" ("^dfst^" "^input^")))
(if (< (input-size (after-state "^tmp^")) 0)
(after-state "^tmp^")
(if (let (("^cond_binder_name^" (return-value "^tmp^"))) "^cond^")
(let (("^dsnd_binder_name^" (return-value "^tmp^")))
("^dsnd^" (after-state "^tmp^"))
)
(mk-state -1 (choice-index (after-state "^tmp^")))
)
)
)
)
"
let parse_dep_pair_with_refinement_gen (tag: parser reading) (cond_binder: string) (cond: unit -> ML string) (payload_binder: string) (payload: parser not_reading) : parser not_reading =
fun name binders _ out ->
let name_tag = Printf.sprintf "%s-tag" name in
let body_tag = tag name_tag binders false out in
let binders' = push_binder payload_binder "Int" binders in (* TODO: support more types *)
let name_payload = Printf.sprintf "%s-payload" name in
let body_payload = payload name_payload binders' false out in
out (mk_parse_dep_pair_with_refinement name binders.bind body_tag.call cond_binder (cond ()) payload_binder body_payload.call);
{ call = mk_function_call name binders }
let parse_dep_pair_with_refinement (tag: parser reading) (cond_binder: A.ident) (cond: unit -> ML string) (payload_binder: A.ident) (payload: parser not_reading) : parser not_reading =
parse_dep_pair_with_refinement_gen tag (ident_to_string cond_binder) cond (ident_to_string payload_binder) payload
let parse_dep_pair (tag: parser reading) (new_binder: A.ident) (payload: parser not_reading) : parser not_reading =
parse_dep_pair_with_refinement tag new_binder (fun _ -> "true") new_binder payload
let parse_refine (tag: parser reading) (cond_binder: A.ident) (cond: unit -> ML string) : parser not_reading =
parse_dep_pair_with_refinement tag cond_binder cond cond_binder (parse_itype I.Unit)
let mk_parse_ifthenelse
(name: string)
(binders: string)
(cond: string)
(f_then: string)
(f_else: string)
: string
= let input = Printf.sprintf "%s-input" name in
"(define-fun "^name^" ("^binders^"("^input^" State)) State
(if "^cond^"
("^f_then^" "^input^")
("^f_else^" "^input^")
)
)
"
let parse_ifthenelse (cond: unit -> ML string) (pthen: parser not_reading) (pelse: parser not_reading) : parser not_reading =
fun name binders _ out ->
let name_then = Printf.sprintf "%s-then" name in
let body_then = pthen name_then binders false out in
let name_else = Printf.sprintf "%s-else" name in
let body_else = pelse name_else binders false out in
out (mk_parse_ifthenelse name binders.bind (cond ()) body_then.call body_else.call);
{ call = mk_function_call name binders }
let mk_parse_exact
(name: string)
(binders: string)
(body: string)
(size: string)
: string
= let input = Printf.sprintf "%s-input" name in
let sz = Printf.sprintf "%s-size" name in
let res = Printf.sprintf "%s-res" name in
"(define-fun "^name^" ("^binders^"("^input^" State)) State
(let (("^sz^" "^size^"))
(if (< (input-size "^input^") "^sz^")
(mk-state -1 (choice-index "^input^"))
(let (("^res^" ("^body^" (mk-state "^sz^" (choice-index "^input^")))))
(mk-state
(if (= (input-size "^res^") 0)
(- (input-size "^input^") "^sz^")
-1
)
(choice-index "^res^")
)
)
)
)
)
"
let parse_exact
(size: unit -> ML string)
(body: parser not_reading)
: Tot (parser not_reading)
= fun name binders _ out ->
let body_name = Printf.sprintf "%s-body" name in
let body = body body_name binders false out in
out (mk_parse_exact name binders.bind body.call (size ()));
{ call = mk_function_call name binders }
let parse_at_most
(size: unit -> ML string)
(body: parser not_reading)
: Tot (parser not_reading)
= parse_exact size (parse_pair body parse_all_bytes)
(*
let mk_parse_list_one
(name: string)
(binders: string)
(p: string)
: string
= let input = Printf.sprintf "%s-input" name in
let res = Printf.sprintf "%s-res" name in
"(define-fun "^name^" ("^binders^"("^input^" (Seq Int))) (Seq Int)
(if (= (seq.len "^input^") 0)
(seq.unit 0)
(let (("^res^" ("^p^" "^input^")))
(if (= (seq.len "^res^") 0)
(as seq.empty (Seq Int))
(if (= (seq.nth "^res^" 0) 0)
(as seq.empty (Seq Int))
"^res^"
)
)
)
)
)
"
let parse_list_one
(body: parser not_reading)
: Tot (parser not_reading)
= fun name binders _ out ->
let body_name = Printf.sprintf "%s-body" name in
let body = body body_name binders false out in
out (mk_parse_list_one name binders.bind body.call);
{ call = mk_function_call name binders }
let rec parse_list_bounded'
(body: parser not_reading)
(logn: nat)
: Tot (parser not_reading)
(decreases logn)
= if logn = 0
then parse_list_one body
else
let logn' = logn - 1 in
parse_square (parse_list_bounded' body logn')
let parse_list_bounded body = parse_list_bounded' body 3 // 64
*)
let mk_parse_list
(name: string)
(rec_call: string)
(binders: string)
(body: string)
: string
= let input = Printf.sprintf "%s-input" name in
"(define-fun-rec "^name^" ("^binders^"("^input^" State)) State
(if (<= (input-size "^input^") 0)
"^input^"
("^rec_call^" ("^body^" "^input^"))
)
)
"
let parse_list
(body: parser not_reading)
: Tot (parser not_reading)
= fun name binders _ out ->
let rec_call = mk_function_call name binders in
let body_name = Printf.sprintf "%s-body" name in
let body = body body_name binders false out in
out (mk_parse_list name rec_call binders.bind body.call);
{ call = rec_call }
let parse_nlist
(size: unit -> ML string)
(body: parser not_reading)
: Tot (parser not_reading)
= parse_exact size (parse_list body)
let mk_parse_string
(name: string)
(rec_call: string)
(binders: string)
(body: string)
(terminator: string)
: string
= let input = Printf.sprintf "%s-input" name in
let tmp = Printf.sprintf "%s-tmp" name in
"(define-fun-rec "^name^" ("^binders^"("^input^" State)) State
(let (("^tmp^" ("^body^" "^input^")))
(if (< (choice-index (after-state "^tmp^")) 0)
(mk-state -1 (choice-index (after-state "^tmp^")))
(if (= (return-value "^tmp^") "^terminator^")
(after-state "^tmp^")
("^rec_call^" (after-state "^tmp^"))
)
)
)
)
"
let parse_string
(body: parser reading)
(terminator: (unit -> ML string))
: Tot (parser not_reading)
= fun name binders _ out ->
let rec_call = mk_function_call name binders in
let body_name = Printf.sprintf "%s-body" name in
let body = body body_name binders false out in
out (mk_parse_string name rec_call binders.bind body.call (terminator ()));
{ call = rec_call }
let rec type_has_actions = function
| I.T_with_dep_action _ _ _
| I.T_dep_pair_with_action _ _ _ _
| I.T_refine_with_action _ _ _ _
| I.T_dep_pair_with_refinement_and_action _ _ _ _ _
| I.T_with_action _ _ _
-> true
| I.T_false _
| I.T_denoted _ _
| I.T_refine _ _ _
| I.T_string _ _ _
-> false
| I.T_if_else _ t1 t2
| I.T_pair _ t1 t2 ->
type_has_actions t1 || type_has_actions t2
| I.T_at_most _ _ t
| I.T_exact _ _ t
| I.T_nlist _ _ t
| I.T_with_comment _ t _
| I.T_dep_pair_with_refinement _ _ _ (_, t)
| I.T_dep_pair _ _ (_, t) ->
type_has_actions t
let rec parse_typ (t : I.typ) : Pure (parser not_reading)
(requires (type_has_actions t == false))
(ensures (fun _ -> True))
= match t with
| I.T_false _ -> parse_false
| I.T_denoted _ d -> parse_denoted d
| I.T_pair _ t1 t2 -> parse_pair (parse_typ t1) (parse_typ t2)
| I.T_dep_pair _ t1 (lam, t2) -> parse_dep_pair (parse_readable_dtyp t1) lam (parse_typ t2)
| I.T_refine _ base (lam, cond) -> parse_refine (parse_readable_dtyp base) lam (fun _ -> mk_expr cond)
| I.T_dep_pair_with_refinement _ base (lam_cond, cond) (lam_k, k) -> parse_dep_pair_with_refinement (parse_readable_dtyp base) lam_cond (fun _ -> mk_expr cond) lam_k (parse_typ k)
| I.T_if_else cond t1 t2 -> parse_ifthenelse (fun _ -> mk_expr cond) (parse_typ t1) (parse_typ t2)
| I.T_with_comment _ base _ -> parse_typ base
| I.T_at_most _ size body -> parse_at_most (fun _ -> mk_expr size) (parse_typ body)
| I.T_exact _ size body -> parse_exact (fun _ -> mk_expr size) (parse_typ body)
| I.T_string _ elt terminator -> parse_string (parse_readable_dtyp elt) (fun _ -> mk_expr terminator)
| I.T_nlist _ size body -> parse_nlist (fun _ -> mk_expr size) (parse_typ body)
type arg_type =
| ArgInt of A.integer_type
| ArgBool
| ArgPointer
let arg_type_of_typ (t: T.typ) : Tot (option arg_type) =
match t with
| T.T_pointer _
| T.T_app _ A.KindOutput _
| T.T_app _ A.KindExtern _
| T.T_app {v = {modul_name = None; name = "PUINT8"}} _ _
-> Some ArgPointer
| T.T_app {v = {modul_name = None; name = "Bool"}} _ _
-> Some ArgBool
| T.T_app i _ _
->
begin match A.maybe_as_integer_typ i with
| Some t -> Some (ArgInt t)
| None -> None
end
| _ -> None
let smt_type_of_typ (t: T.typ) : Tot string =
match arg_type_of_typ t with
| Some ArgBool -> "Bool"
| _ -> "Int"
let rec binders_of_params = function
| [] -> empty_binders
| (id, t) :: q -> push_binder (ident_to_string id) (smt_type_of_typ t) (binders_of_params q)
let mk_definition
(name: string)
(binders: string)
(typ: string)
(body: string)
: Tot string
= "(define-fun "^name^" ("^binders^") "^typ^" "^body^")"
let produce_definition
(i: A.ident)
(param: list T.param)
(typ: T.typ)
(body: T.expr)
(out: string -> ML unit)
: ML unit
= let binders = binders_of_params param in
out (mk_definition (ident_to_string i) binders.bind (smt_type_of_typ typ) (mk_expr body))
let produce_not_type_decl (a: I.not_type_decl) (out: string -> ML unit) : ML unit =
match fst a with
| T.Definition (i, param, typ, body) ->
produce_definition i param typ body out
| T.Assumption _ -> failwith "produce_not_type_decl: unsupported"
| T.Output_type _
| T.Output_type_expr _ _
| T.Extern_type _
| T.Extern_fn _ _ _
-> ()
let prog = list (string & list arg_type) | false | false | Z3TestGen.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val produce_type_decl (out: (string -> ML unit)) (accu: prog) (a: I.type_decl) : ML prog | [] | Z3TestGen.produce_type_decl | {
"file_name": "src/3d/Z3TestGen.fst",
"git_rev": "446a08ce38df905547cf20f28c43776b22b8087a",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} |
out: (_: Prims.string -> FStar.All.ML Prims.unit) ->
accu: Z3TestGen.prog ->
a: InterpreterTarget.type_decl
-> FStar.All.ML Z3TestGen.prog | {
"end_col": 212,
"end_line": 811,
"start_col": 88,
"start_line": 806
} |
Prims.Tot | [
{
"abbrev": true,
"full_module": "InterpreterTarget",
"short_module": "I"
},
{
"abbrev": true,
"full_module": "Target",
"short_module": "T"
},
{
"abbrev": true,
"full_module": "Ast",
"short_module": "A"
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.All",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.Printf",
"short_module": "Printf"
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let rec type_has_actions = function
| I.T_with_dep_action _ _ _
| I.T_dep_pair_with_action _ _ _ _
| I.T_refine_with_action _ _ _ _
| I.T_dep_pair_with_refinement_and_action _ _ _ _ _
| I.T_with_action _ _ _
-> true
| I.T_false _
| I.T_denoted _ _
| I.T_refine _ _ _
| I.T_string _ _ _
-> false
| I.T_if_else _ t1 t2
| I.T_pair _ t1 t2 ->
type_has_actions t1 || type_has_actions t2
| I.T_at_most _ _ t
| I.T_exact _ _ t
| I.T_nlist _ _ t
| I.T_with_comment _ t _
| I.T_dep_pair_with_refinement _ _ _ (_, t)
| I.T_dep_pair _ _ (_, t) ->
type_has_actions t | let rec type_has_actions = | false | null | false | function
| I.T_with_dep_action _ _ _
| I.T_dep_pair_with_action _ _ _ _
| I.T_refine_with_action _ _ _ _
| I.T_dep_pair_with_refinement_and_action _ _ _ _ _
| I.T_with_action _ _ _ -> true
| I.T_false _ | I.T_denoted _ _ | I.T_refine _ _ _ | I.T_string _ _ _ -> false
| I.T_if_else _ t1 t2 | I.T_pair _ t1 t2 -> type_has_actions t1 || type_has_actions t2
| I.T_at_most _ _ t
| I.T_exact _ _ t
| I.T_nlist _ _ t
| I.T_with_comment _ t _
| I.T_dep_pair_with_refinement _ _ _ (_, t)
| I.T_dep_pair _ _ (_, t) -> type_has_actions t | {
"checked_file": "Z3TestGen.fst.checked",
"dependencies": [
"Z3.fsti.checked",
"Target.fsti.checked",
"prims.fst.checked",
"OS.fsti.checked",
"Lisp.fsti.checked",
"InterpreterTarget.fsti.checked",
"FStar.String.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Printf.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.List.Tot.fst.checked",
"FStar.List.fst.checked",
"FStar.IO.fst.checked",
"FStar.Char.fsti.checked",
"FStar.All.fst.checked",
"Ast.fst.checked"
],
"interface_file": false,
"source_file": "Z3TestGen.fst"
} | [
"total"
] | [
"InterpreterTarget.typ",
"InterpreterTarget.non_empty_string",
"InterpreterTarget.readable_dtyp",
"InterpreterTarget.lam",
"InterpreterTarget.action",
"InterpreterTarget.expr",
"InterpreterTarget.dtyp",
"Prims.op_BarBar",
"Z3TestGen.type_has_actions",
"Prims.string",
"Ast.ident",
"Prims.bool"
] | [] | module Z3TestGen
module Printf = FStar.Printf
open FStar.All
open FStar.Mul
module A = Ast
module T = Target
module I = InterpreterTarget
let prelude : string =
"
(set-option :produce-models true)
(declare-datatypes () ((State (mk-state (input-size Int) (choice-index Int)))))
(declare-datatypes () ((Result (mk-result (return-value Int) (after-state State)))))
(define-fun parse-empty ((x State)) Result
(mk-result 0 x)
)
(declare-fun choose (Int) Int)
(assert (forall ((i Int))
(and (<= 0 (choose i)) (< (choose i) 256))
))
(define-fun parse-false ((x State)) State
(mk-state -1 (choice-index x))
)
(define-fun parse-all-bytes ((x State)) State
(if (<= (input-size x) 0)
x
(mk-state 0 (+ (choice-index x) (input-size x)))
)
)
(define-fun parse-all-zeros ((x State)) State
(if (<= (input-size x) 0)
x
(mk-state
(if
(forall ((j Int))
(if (and (<= 0 j) (< j (input-size x)))
(= (choose (+ (choice-index x) j)) 0)
true
)
)
0
-1
)
(+ (choice-index x) (input-size x))
)
)
)
(define-fun parse-u8 ((x State)) Result
(mk-result
(choose (choice-index x))
(mk-state (- (input-size x) 1) (+ (choice-index x) 1))
)
)
(define-fun parse-u16-be ((x State)) Result
(mk-result
(+ (choose (+ 1 (choice-index x)))
(* 256
(choose (+ 0 (choice-index x)))
)
)
(mk-state (- (input-size x) 2) (+ (choice-index x) 2))
)
)
(define-fun parse-u16-le ((x State)) Result
(mk-result
(+ (choose (+ 0 (choice-index x)))
(* 256
(choose (+ 1 (choice-index x)))
)
)
(mk-state (- (input-size x) 2) (+ (choice-index x) 2))
)
)
(define-fun parse-u32-be ((x State)) Result
(mk-result
(+ (choose (+ 3 (choice-index x)))
(* 256
(+ (choose (+ 2 (choice-index x)))
(* 256
(+ (choose (+ 1 (choice-index x)))
(* 256
(choose (+ 0 (choice-index x)))
)
)
)
)
)
)
(mk-state (- (input-size x) 4) (+ (choice-index x) 4))
)
)
(define-fun parse-u32-le ((x State)) Result
(mk-result
(+ (choose (+ 0 (choice-index x)))
(* 256
(+ (choose (+ 1 (choice-index x)))
(* 256
(+ (choose (+ 2 (choice-index x)))
(* 256
(choose (+ 3 (choice-index x)))
)
)
)
)
)
)
(mk-state (- (input-size x) 4) (+ (choice-index x) 4))
)
)
(define-fun parse-u64-be ((x State)) Result
(mk-result
(+ (choose (+ 7 (choice-index x)))
(* 256
(+ (choose (+ 6 (choice-index x)))
(* 256
(+ (choose (+ 5 (choice-index x)))
(* 256
(+ (choose (+ 4 (choice-index x)))
(* 256
(+ (choose (+ 3 (choice-index x)))
(* 256
(+ (choose (+ 2 (choice-index x)))
(* 256
(+ (choose (+ 1 (choice-index x)))
(* 256
(choose (+ 0 (choice-index x)))
)
)
)
)
)
)
)
)
)
)
)
)
)
)
(mk-state (- (input-size x) 8) (+ (choice-index x) 8))
)
)
(define-fun parse-u64-le ((x State)) Result
(mk-result
(+ (choose (+ 0 (choice-index x)))
(* 256
(+ (choose (+ 1 (choice-index x)))
(* 256
(+ (choose (+ 2 (choice-index x)))
(* 256
(+ (choose (+ 3 (choice-index x)))
(* 256
(+ (choose (+ 4 (choice-index x)))
(* 256
(+ (choose (+ 5 (choice-index x)))
(* 256
(+ (choose (+ 6 (choice-index x)))
(* 256
(choose (+ 7 (choice-index x)))
)
)
)
)
)
)
)
)
)
)
)
)
)
)
(mk-state (- (input-size x) 8) (+ (choice-index x) 8))
)
)
(define-fun-rec pow-2 ((amount Int)) Int
(if (<= amount 0)
1
(* 2 (pow-2 (- amount 1)))
)
)
;; see LowParse.BitFields.get_bitfield_eq
(define-fun get-bitfield-lsb ((nbBits Int) (value Int) (bitsFrom Int) (bitsTo Int)) Int
(mod (div value (pow-2 bitsFrom)) (pow-2 (- bitsTo bitsFrom)))
)
;; see EverParse3d.Prelude.StaticHeader
(define-fun get-bitfield-msb ((nbBits Int) (value Int) (bitsFrom Int) (bitsTo Int)) Int
(get-bitfield-lsb nbBits value (- nbBits bitsTo) (- nbBits bitsFrom))
)
(declare-const initial-input-size Int)
(assert (>= initial-input-size 0))
(define-fun initial-state () State (mk-state initial-input-size 0))
"
let mk_constant = function
| A.Unit -> "0"
| A.Int _ x -> string_of_int x
| A.XInt _ x -> string_of_int (OS.int_of_string x)
| A.Bool true -> "true"
| A.Bool false -> "false"
let mk_app fn = function
| None -> fn
| Some args -> Printf.sprintf "(%s %s)" fn args
let assert_some = function
| None -> failwith "assert_some"
| Some x -> x
let is_bitwise_op (x: T.op) : Tot (option A.integer_type) =
match x with
| T.BitwiseAnd a
| T.BitwiseXor a
| T.BitwiseOr a
| T.BitwiseNot a
| T.ShiftLeft a
| T.ShiftRight a
-> Some a
| _ -> None
let mk_bitwise_op (op: string) (bitvec_args: option string) : ML string =
mk_app "bv2int" (Some (mk_app op bitvec_args))
let integer_type_bit_size = function
| A.UInt8 -> 8
| A.UInt16 -> 16
| A.UInt32 -> 32
| A.UInt64 -> 64
let mk_bitwise_not (a: A.integer_type) (bitvec_arg: option string) : ML string =
match bitvec_arg with
| None -> failwith "ill-formed bitwise_not"
| Some arg -> "(bv2int (bvxor "^arg^" #b"^String.make (integer_type_bit_size a) '1'^"))"
let mk_op : T.op -> option string -> ML string = function
| T.Eq -> mk_app "="
| T.Neq -> (fun s -> mk_app "not" (Some (mk_app "=" s)))
| T.And -> mk_app "and"
| T.Or -> mk_app "or"
| T.Not -> mk_app "not"
| T.Plus _ -> mk_app "+"
| T.Minus _ -> mk_app "-"
| T.Mul _ -> mk_app "*"
| T.Division _ -> mk_app "div"
| T.Remainder _ -> mk_app "mod"
| T.BitwiseAnd _ -> mk_bitwise_op "bvand"
| T.BitwiseXor _ -> mk_bitwise_op "bvxor"
| T.BitwiseOr _ -> mk_bitwise_op "bvor"
| T.BitwiseNot a -> mk_bitwise_not a
| T.ShiftLeft _ -> mk_bitwise_op "bvshl"
| T.ShiftRight _ -> mk_bitwise_op "bvlshr"
| T.LT _ -> mk_app "<"
| T.GT _ -> mk_app ">"
| T.LE _ -> mk_app "<="
| T.GE _ -> mk_app ">="
| T.IfThenElse -> mk_app "if"
| T.BitFieldOf size order -> (fun arg -> Printf.sprintf "(get-bitfield-%ssb %d %s)" (match order with A.LSBFirst -> "l" | A.MSBFirst -> "m") size (assert_some arg))
| T.Cast _ _ -> assert_some (* casts allowed only if they are proven not to lose precision *)
| T.Ext s -> mk_app s
let ident_to_string = A.ident_to_string
let mk_bitwise_arg (t: A.integer_type) (arg: string) : Tot string =
mk_app ("(_ int2bv "^string_of_int (integer_type_bit_size t)^")") (Some arg)
let mk_maybe_bitwise_arg (t: option A.integer_type) (arg: string) : Tot string =
match t with
| None -> arg
| Some t -> mk_bitwise_arg t arg
let rec mk_expr (e: T.expr) : ML string = match fst e with
| T.Constant c -> mk_constant c
| T.Identifier i -> ident_to_string i
| T.App hd args -> mk_op hd (mk_args (is_bitwise_op hd) args)
| _ -> failwith "mk_expr: not supported"
and mk_args_aux (is_bitwise_op: option A.integer_type) accu : (list T.expr -> ML string) = function
| [] -> accu
| a :: q -> mk_args_aux is_bitwise_op (Printf.sprintf "%s %s" accu (mk_maybe_bitwise_arg is_bitwise_op (mk_expr a))) q
and mk_args (is_bitwise_op: option A.integer_type) (l: list T.expr) : ML (option string) = match l with
| [] -> None
| a :: q -> Some (mk_args_aux is_bitwise_op (mk_maybe_bitwise_arg is_bitwise_op (mk_expr a)) q)
type reading = { call: string }
type not_reading = { call: string }
type binders = {
is_empty: bool;
bind: string;
args: string;
}
let empty_binders : binders = {
is_empty = true;
bind = "";
args = "";
}
let push_binder (name: string) (typ: string) (b: binders) : binders = {
is_empty = false;
bind = Printf.sprintf "(%s %s) %s" name typ b.bind;
args = Printf.sprintf " %s%s" name b.args;
}
let mk_function_call (name: string) (b: binders) =
Printf.sprintf "%s%s" name b.args
type parser (a: Type) =
(* name *) string ->
(* binders *) binders ->
(* is_toplevel *) bool ->
(* out *) (string -> ML unit) ->
ML a
let unsupported_parser (s: string) (a: Type) : Tot (parser a) =
fun _ _ _ _ -> failwith (Printf.sprintf "unsupported parser: %s" s)
let leaf_reading_parser (name: string) : parser reading =
fun _ _ _ _ -> { call = name }
let readable_itype_parser_suffix (i: I.itype) : Tot string = match i with
| I.UInt8 | I.UInt8BE -> "u8"
| I.UInt16 -> "u16-le"
| I.UInt16BE -> "u16-be"
| I.UInt32 -> "u32-le"
| I.UInt32BE -> "u32-be"
| I.UInt64 -> "u64-le"
| I.UInt64BE -> "u64-be"
| I.Unit -> "empty"
| I.AllBytes -> "all-bytes"
| I.AllZeros -> "all-zeros"
let parse_readable_itype (i: I.readable_itype) : Tot (parser reading) =
leaf_reading_parser ("parse-" ^ readable_itype_parser_suffix i)
let mk_wrap_parser
(name: string)
(binders: string)
(body: string)
: string
= let input = Printf.sprintf "%s-input" name in
let tmp = Printf.sprintf "%s-tmp" name in
"(define-fun "^name^" ("^binders^"("^input^" State)) State
(after-state ("^body^" "^input^"))
)
"
let wrap_parser (p: parser reading) : parser not_reading =
fun name binders _ out ->
let name' = Printf.sprintf "%s-wrapped" name in
let body = p name' binders false out in
out (mk_wrap_parser name binders.bind body.call);
{ call = mk_function_call name binders }
let mk_toplevel_parser
(name: string)
(binders: string)
(body: string)
: string
= let input = Printf.sprintf "%s-input" name in
"(define-fun "^name^" ("^binders^"("^input^" State)) State
("^body^" "^input^")
)
"
let maybe_toplevel_parser (p: parser not_reading) : parser not_reading =
fun name binders is_toplevel out ->
if is_toplevel
then begin
let name' = Printf.sprintf "%s-body" name in
let body = p name' binders false out in
out (mk_toplevel_parser name binders.bind body.call);
{ call = mk_function_call name binders }
end
else p name binders false out
let parse_all_bytes : parser not_reading =
maybe_toplevel_parser (fun _ _ _ _ -> { call = "parse-all-bytes" })
let parse_all_zeros : parser not_reading =
maybe_toplevel_parser (fun _ _ _ _ -> { call = "parse-all-zeros" })
let parse_itype : I.itype -> parser not_reading = function
| I.AllBytes -> parse_all_bytes
| I.AllZeros -> parse_all_zeros
| i -> wrap_parser (parse_readable_itype i)
let mk_app_without_paren id args =
mk_args_aux None (ident_to_string id) args
let parse_readable_app
(hd: A.ident)
(args: list I.expr)
: Tot (parser reading)
= fun _ _ _ _ -> { call = mk_app_without_paren hd args }
let parse_readable_dtyp
(d: I.readable_dtyp)
: Tot (parser reading)
= match d with
| I.DT_IType i -> parse_readable_itype i
| I.DT_App _ hd args -> parse_readable_app hd args
let parse_not_readable_app
(hd: A.ident)
(args: list I.expr)
: Tot (parser not_reading)
= maybe_toplevel_parser (fun _ _ _ _ -> { call = mk_app_without_paren hd args })
let parse_dtyp
(d: I.dtyp)
: Tot (parser not_reading)
= if I.allow_reader_of_dtyp d
then wrap_parser (parse_readable_dtyp d)
else match d with
| I.DT_IType i -> parse_itype i
| I.DT_App _ hd args -> parse_not_readable_app hd args
let parse_false : parser not_reading =
maybe_toplevel_parser (fun _ _ _ _ -> { call = "parse-false" })
let parse_denoted (d: I.dtyp) : parser not_reading =
parse_dtyp d
let mk_parse_pair
(name: string)
(binders: string)
(fst: string)
(snd: string)
: string
= let input = Printf.sprintf "%s-input" name in
let tmp = Printf.sprintf "%s-tmp" name in
"(define-fun "^name^" ("^binders^"("^input^" State)) State
(let (("^tmp^" ("^fst^" "^input^")))
(if (< (input-size "^tmp^") 0)
"^tmp^"
("^snd^" "^tmp^")
)
)
)
"
let parse_pair (fst: parser not_reading) (snd: parser not_reading) : parser not_reading =
fun name binders _ out ->
let name_fst = Printf.sprintf "%s-fst" name in
let body_fst = fst name_fst binders false out in
let name_snd = Printf.sprintf "%s-snd" name in
let body_snd = snd name_snd binders false out in
out (mk_parse_pair name binders.bind body_fst.call body_snd.call);
{ call = mk_function_call name binders }
let parse_square (p: parser not_reading) : parser not_reading =
fun name binders _ out ->
let body_name = Printf.sprintf "%s-snd" name in
let body = p body_name binders false out in
out (mk_parse_pair name binders.bind body.call body.call);
{ call = mk_function_call name binders }
let mk_parse_dep_pair_with_refinement
(name: string)
(binders: string)
(dfst: string)
(cond_binder_name: string)
(cond: string)
(dsnd_binder_name: string)
(dsnd: string) (* already contains the new argument *)
: string
= let input = Printf.sprintf "%s-input" name in
let tmp = Printf.sprintf "%s-tmp" name in
"(define-fun "^name^" ("^binders^"("^input^" State)) State
(let (("^tmp^" ("^dfst^" "^input^")))
(if (< (input-size (after-state "^tmp^")) 0)
(after-state "^tmp^")
(if (let (("^cond_binder_name^" (return-value "^tmp^"))) "^cond^")
(let (("^dsnd_binder_name^" (return-value "^tmp^")))
("^dsnd^" (after-state "^tmp^"))
)
(mk-state -1 (choice-index (after-state "^tmp^")))
)
)
)
)
"
let parse_dep_pair_with_refinement_gen (tag: parser reading) (cond_binder: string) (cond: unit -> ML string) (payload_binder: string) (payload: parser not_reading) : parser not_reading =
fun name binders _ out ->
let name_tag = Printf.sprintf "%s-tag" name in
let body_tag = tag name_tag binders false out in
let binders' = push_binder payload_binder "Int" binders in (* TODO: support more types *)
let name_payload = Printf.sprintf "%s-payload" name in
let body_payload = payload name_payload binders' false out in
out (mk_parse_dep_pair_with_refinement name binders.bind body_tag.call cond_binder (cond ()) payload_binder body_payload.call);
{ call = mk_function_call name binders }
let parse_dep_pair_with_refinement (tag: parser reading) (cond_binder: A.ident) (cond: unit -> ML string) (payload_binder: A.ident) (payload: parser not_reading) : parser not_reading =
parse_dep_pair_with_refinement_gen tag (ident_to_string cond_binder) cond (ident_to_string payload_binder) payload
let parse_dep_pair (tag: parser reading) (new_binder: A.ident) (payload: parser not_reading) : parser not_reading =
parse_dep_pair_with_refinement tag new_binder (fun _ -> "true") new_binder payload
let parse_refine (tag: parser reading) (cond_binder: A.ident) (cond: unit -> ML string) : parser not_reading =
parse_dep_pair_with_refinement tag cond_binder cond cond_binder (parse_itype I.Unit)
let mk_parse_ifthenelse
(name: string)
(binders: string)
(cond: string)
(f_then: string)
(f_else: string)
: string
= let input = Printf.sprintf "%s-input" name in
"(define-fun "^name^" ("^binders^"("^input^" State)) State
(if "^cond^"
("^f_then^" "^input^")
("^f_else^" "^input^")
)
)
"
let parse_ifthenelse (cond: unit -> ML string) (pthen: parser not_reading) (pelse: parser not_reading) : parser not_reading =
fun name binders _ out ->
let name_then = Printf.sprintf "%s-then" name in
let body_then = pthen name_then binders false out in
let name_else = Printf.sprintf "%s-else" name in
let body_else = pelse name_else binders false out in
out (mk_parse_ifthenelse name binders.bind (cond ()) body_then.call body_else.call);
{ call = mk_function_call name binders }
let mk_parse_exact
(name: string)
(binders: string)
(body: string)
(size: string)
: string
= let input = Printf.sprintf "%s-input" name in
let sz = Printf.sprintf "%s-size" name in
let res = Printf.sprintf "%s-res" name in
"(define-fun "^name^" ("^binders^"("^input^" State)) State
(let (("^sz^" "^size^"))
(if (< (input-size "^input^") "^sz^")
(mk-state -1 (choice-index "^input^"))
(let (("^res^" ("^body^" (mk-state "^sz^" (choice-index "^input^")))))
(mk-state
(if (= (input-size "^res^") 0)
(- (input-size "^input^") "^sz^")
-1
)
(choice-index "^res^")
)
)
)
)
)
"
let parse_exact
(size: unit -> ML string)
(body: parser not_reading)
: Tot (parser not_reading)
= fun name binders _ out ->
let body_name = Printf.sprintf "%s-body" name in
let body = body body_name binders false out in
out (mk_parse_exact name binders.bind body.call (size ()));
{ call = mk_function_call name binders }
let parse_at_most
(size: unit -> ML string)
(body: parser not_reading)
: Tot (parser not_reading)
= parse_exact size (parse_pair body parse_all_bytes)
(*
let mk_parse_list_one
(name: string)
(binders: string)
(p: string)
: string
= let input = Printf.sprintf "%s-input" name in
let res = Printf.sprintf "%s-res" name in
"(define-fun "^name^" ("^binders^"("^input^" (Seq Int))) (Seq Int)
(if (= (seq.len "^input^") 0)
(seq.unit 0)
(let (("^res^" ("^p^" "^input^")))
(if (= (seq.len "^res^") 0)
(as seq.empty (Seq Int))
(if (= (seq.nth "^res^" 0) 0)
(as seq.empty (Seq Int))
"^res^"
)
)
)
)
)
"
let parse_list_one
(body: parser not_reading)
: Tot (parser not_reading)
= fun name binders _ out ->
let body_name = Printf.sprintf "%s-body" name in
let body = body body_name binders false out in
out (mk_parse_list_one name binders.bind body.call);
{ call = mk_function_call name binders }
let rec parse_list_bounded'
(body: parser not_reading)
(logn: nat)
: Tot (parser not_reading)
(decreases logn)
= if logn = 0
then parse_list_one body
else
let logn' = logn - 1 in
parse_square (parse_list_bounded' body logn')
let parse_list_bounded body = parse_list_bounded' body 3 // 64
*)
let mk_parse_list
(name: string)
(rec_call: string)
(binders: string)
(body: string)
: string
= let input = Printf.sprintf "%s-input" name in
"(define-fun-rec "^name^" ("^binders^"("^input^" State)) State
(if (<= (input-size "^input^") 0)
"^input^"
("^rec_call^" ("^body^" "^input^"))
)
)
"
let parse_list
(body: parser not_reading)
: Tot (parser not_reading)
= fun name binders _ out ->
let rec_call = mk_function_call name binders in
let body_name = Printf.sprintf "%s-body" name in
let body = body body_name binders false out in
out (mk_parse_list name rec_call binders.bind body.call);
{ call = rec_call }
let parse_nlist
(size: unit -> ML string)
(body: parser not_reading)
: Tot (parser not_reading)
= parse_exact size (parse_list body)
let mk_parse_string
(name: string)
(rec_call: string)
(binders: string)
(body: string)
(terminator: string)
: string
= let input = Printf.sprintf "%s-input" name in
let tmp = Printf.sprintf "%s-tmp" name in
"(define-fun-rec "^name^" ("^binders^"("^input^" State)) State
(let (("^tmp^" ("^body^" "^input^")))
(if (< (choice-index (after-state "^tmp^")) 0)
(mk-state -1 (choice-index (after-state "^tmp^")))
(if (= (return-value "^tmp^") "^terminator^")
(after-state "^tmp^")
("^rec_call^" (after-state "^tmp^"))
)
)
)
)
"
let parse_string
(body: parser reading)
(terminator: (unit -> ML string))
: Tot (parser not_reading)
= fun name binders _ out ->
let rec_call = mk_function_call name binders in
let body_name = Printf.sprintf "%s-body" name in
let body = body body_name binders false out in
out (mk_parse_string name rec_call binders.bind body.call (terminator ()));
{ call = rec_call } | false | true | Z3TestGen.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val type_has_actions : _: InterpreterTarget.typ -> Prims.bool | [
"recursion"
] | Z3TestGen.type_has_actions | {
"file_name": "src/3d/Z3TestGen.fst",
"git_rev": "446a08ce38df905547cf20f28c43776b22b8087a",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | _: InterpreterTarget.typ -> Prims.bool | {
"end_col": 22,
"end_line": 725,
"start_col": 27,
"start_line": 704
} |
|
FStar.All.ML | val print_witness_as_c
(out: (string -> ML unit))
(positive: bool)
(wrapper_name: string)
(arg_types: list arg_type)
(witness: Seq.seq int)
(args: list string)
: ML unit | [
{
"abbrev": true,
"full_module": "InterpreterTarget",
"short_module": "I"
},
{
"abbrev": true,
"full_module": "Target",
"short_module": "T"
},
{
"abbrev": true,
"full_module": "Ast",
"short_module": "A"
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.All",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.Printf",
"short_module": "Printf"
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let print_witness_as_c
(out: (string -> ML unit))
(positive: bool)
(wrapper_name: string)
(arg_types: list arg_type)
(witness: Seq.seq int)
(args: list string)
: ML unit
= print_witness_as_c_gen out witness (fun len ->
print_witness_call_as_c out positive wrapper_name arg_types len args
) | val print_witness_as_c
(out: (string -> ML unit))
(positive: bool)
(wrapper_name: string)
(arg_types: list arg_type)
(witness: Seq.seq int)
(args: list string)
: ML unit
let print_witness_as_c
(out: (string -> ML unit))
(positive: bool)
(wrapper_name: string)
(arg_types: list arg_type)
(witness: Seq.seq int)
(args: list string)
: ML unit = | true | null | false | print_witness_as_c_gen out
witness
(fun len -> print_witness_call_as_c out positive wrapper_name arg_types len args) | {
"checked_file": "Z3TestGen.fst.checked",
"dependencies": [
"Z3.fsti.checked",
"Target.fsti.checked",
"prims.fst.checked",
"OS.fsti.checked",
"Lisp.fsti.checked",
"InterpreterTarget.fsti.checked",
"FStar.String.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Printf.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.List.Tot.fst.checked",
"FStar.List.fst.checked",
"FStar.IO.fst.checked",
"FStar.Char.fsti.checked",
"FStar.All.fst.checked",
"Ast.fst.checked"
],
"interface_file": false,
"source_file": "Z3TestGen.fst"
} | [
"ml"
] | [
"Prims.string",
"Prims.unit",
"Prims.bool",
"Prims.list",
"Z3TestGen.arg_type",
"FStar.Seq.Base.seq",
"Prims.int",
"Z3TestGen.print_witness_as_c_gen",
"Prims.eq2",
"FStar.Seq.Base.length",
"Z3TestGen.print_witness_call_as_c"
] | [] | module Z3TestGen
module Printf = FStar.Printf
open FStar.All
open FStar.Mul
module A = Ast
module T = Target
module I = InterpreterTarget
let prelude : string =
"
(set-option :produce-models true)
(declare-datatypes () ((State (mk-state (input-size Int) (choice-index Int)))))
(declare-datatypes () ((Result (mk-result (return-value Int) (after-state State)))))
(define-fun parse-empty ((x State)) Result
(mk-result 0 x)
)
(declare-fun choose (Int) Int)
(assert (forall ((i Int))
(and (<= 0 (choose i)) (< (choose i) 256))
))
(define-fun parse-false ((x State)) State
(mk-state -1 (choice-index x))
)
(define-fun parse-all-bytes ((x State)) State
(if (<= (input-size x) 0)
x
(mk-state 0 (+ (choice-index x) (input-size x)))
)
)
(define-fun parse-all-zeros ((x State)) State
(if (<= (input-size x) 0)
x
(mk-state
(if
(forall ((j Int))
(if (and (<= 0 j) (< j (input-size x)))
(= (choose (+ (choice-index x) j)) 0)
true
)
)
0
-1
)
(+ (choice-index x) (input-size x))
)
)
)
(define-fun parse-u8 ((x State)) Result
(mk-result
(choose (choice-index x))
(mk-state (- (input-size x) 1) (+ (choice-index x) 1))
)
)
(define-fun parse-u16-be ((x State)) Result
(mk-result
(+ (choose (+ 1 (choice-index x)))
(* 256
(choose (+ 0 (choice-index x)))
)
)
(mk-state (- (input-size x) 2) (+ (choice-index x) 2))
)
)
(define-fun parse-u16-le ((x State)) Result
(mk-result
(+ (choose (+ 0 (choice-index x)))
(* 256
(choose (+ 1 (choice-index x)))
)
)
(mk-state (- (input-size x) 2) (+ (choice-index x) 2))
)
)
(define-fun parse-u32-be ((x State)) Result
(mk-result
(+ (choose (+ 3 (choice-index x)))
(* 256
(+ (choose (+ 2 (choice-index x)))
(* 256
(+ (choose (+ 1 (choice-index x)))
(* 256
(choose (+ 0 (choice-index x)))
)
)
)
)
)
)
(mk-state (- (input-size x) 4) (+ (choice-index x) 4))
)
)
(define-fun parse-u32-le ((x State)) Result
(mk-result
(+ (choose (+ 0 (choice-index x)))
(* 256
(+ (choose (+ 1 (choice-index x)))
(* 256
(+ (choose (+ 2 (choice-index x)))
(* 256
(choose (+ 3 (choice-index x)))
)
)
)
)
)
)
(mk-state (- (input-size x) 4) (+ (choice-index x) 4))
)
)
(define-fun parse-u64-be ((x State)) Result
(mk-result
(+ (choose (+ 7 (choice-index x)))
(* 256
(+ (choose (+ 6 (choice-index x)))
(* 256
(+ (choose (+ 5 (choice-index x)))
(* 256
(+ (choose (+ 4 (choice-index x)))
(* 256
(+ (choose (+ 3 (choice-index x)))
(* 256
(+ (choose (+ 2 (choice-index x)))
(* 256
(+ (choose (+ 1 (choice-index x)))
(* 256
(choose (+ 0 (choice-index x)))
)
)
)
)
)
)
)
)
)
)
)
)
)
)
(mk-state (- (input-size x) 8) (+ (choice-index x) 8))
)
)
(define-fun parse-u64-le ((x State)) Result
(mk-result
(+ (choose (+ 0 (choice-index x)))
(* 256
(+ (choose (+ 1 (choice-index x)))
(* 256
(+ (choose (+ 2 (choice-index x)))
(* 256
(+ (choose (+ 3 (choice-index x)))
(* 256
(+ (choose (+ 4 (choice-index x)))
(* 256
(+ (choose (+ 5 (choice-index x)))
(* 256
(+ (choose (+ 6 (choice-index x)))
(* 256
(choose (+ 7 (choice-index x)))
)
)
)
)
)
)
)
)
)
)
)
)
)
)
(mk-state (- (input-size x) 8) (+ (choice-index x) 8))
)
)
(define-fun-rec pow-2 ((amount Int)) Int
(if (<= amount 0)
1
(* 2 (pow-2 (- amount 1)))
)
)
;; see LowParse.BitFields.get_bitfield_eq
(define-fun get-bitfield-lsb ((nbBits Int) (value Int) (bitsFrom Int) (bitsTo Int)) Int
(mod (div value (pow-2 bitsFrom)) (pow-2 (- bitsTo bitsFrom)))
)
;; see EverParse3d.Prelude.StaticHeader
(define-fun get-bitfield-msb ((nbBits Int) (value Int) (bitsFrom Int) (bitsTo Int)) Int
(get-bitfield-lsb nbBits value (- nbBits bitsTo) (- nbBits bitsFrom))
)
(declare-const initial-input-size Int)
(assert (>= initial-input-size 0))
(define-fun initial-state () State (mk-state initial-input-size 0))
"
let mk_constant = function
| A.Unit -> "0"
| A.Int _ x -> string_of_int x
| A.XInt _ x -> string_of_int (OS.int_of_string x)
| A.Bool true -> "true"
| A.Bool false -> "false"
let mk_app fn = function
| None -> fn
| Some args -> Printf.sprintf "(%s %s)" fn args
let assert_some = function
| None -> failwith "assert_some"
| Some x -> x
let is_bitwise_op (x: T.op) : Tot (option A.integer_type) =
match x with
| T.BitwiseAnd a
| T.BitwiseXor a
| T.BitwiseOr a
| T.BitwiseNot a
| T.ShiftLeft a
| T.ShiftRight a
-> Some a
| _ -> None
let mk_bitwise_op (op: string) (bitvec_args: option string) : ML string =
mk_app "bv2int" (Some (mk_app op bitvec_args))
let integer_type_bit_size = function
| A.UInt8 -> 8
| A.UInt16 -> 16
| A.UInt32 -> 32
| A.UInt64 -> 64
let mk_bitwise_not (a: A.integer_type) (bitvec_arg: option string) : ML string =
match bitvec_arg with
| None -> failwith "ill-formed bitwise_not"
| Some arg -> "(bv2int (bvxor "^arg^" #b"^String.make (integer_type_bit_size a) '1'^"))"
let mk_op : T.op -> option string -> ML string = function
| T.Eq -> mk_app "="
| T.Neq -> (fun s -> mk_app "not" (Some (mk_app "=" s)))
| T.And -> mk_app "and"
| T.Or -> mk_app "or"
| T.Not -> mk_app "not"
| T.Plus _ -> mk_app "+"
| T.Minus _ -> mk_app "-"
| T.Mul _ -> mk_app "*"
| T.Division _ -> mk_app "div"
| T.Remainder _ -> mk_app "mod"
| T.BitwiseAnd _ -> mk_bitwise_op "bvand"
| T.BitwiseXor _ -> mk_bitwise_op "bvxor"
| T.BitwiseOr _ -> mk_bitwise_op "bvor"
| T.BitwiseNot a -> mk_bitwise_not a
| T.ShiftLeft _ -> mk_bitwise_op "bvshl"
| T.ShiftRight _ -> mk_bitwise_op "bvlshr"
| T.LT _ -> mk_app "<"
| T.GT _ -> mk_app ">"
| T.LE _ -> mk_app "<="
| T.GE _ -> mk_app ">="
| T.IfThenElse -> mk_app "if"
| T.BitFieldOf size order -> (fun arg -> Printf.sprintf "(get-bitfield-%ssb %d %s)" (match order with A.LSBFirst -> "l" | A.MSBFirst -> "m") size (assert_some arg))
| T.Cast _ _ -> assert_some (* casts allowed only if they are proven not to lose precision *)
| T.Ext s -> mk_app s
let ident_to_string = A.ident_to_string
let mk_bitwise_arg (t: A.integer_type) (arg: string) : Tot string =
mk_app ("(_ int2bv "^string_of_int (integer_type_bit_size t)^")") (Some arg)
let mk_maybe_bitwise_arg (t: option A.integer_type) (arg: string) : Tot string =
match t with
| None -> arg
| Some t -> mk_bitwise_arg t arg
let rec mk_expr (e: T.expr) : ML string = match fst e with
| T.Constant c -> mk_constant c
| T.Identifier i -> ident_to_string i
| T.App hd args -> mk_op hd (mk_args (is_bitwise_op hd) args)
| _ -> failwith "mk_expr: not supported"
and mk_args_aux (is_bitwise_op: option A.integer_type) accu : (list T.expr -> ML string) = function
| [] -> accu
| a :: q -> mk_args_aux is_bitwise_op (Printf.sprintf "%s %s" accu (mk_maybe_bitwise_arg is_bitwise_op (mk_expr a))) q
and mk_args (is_bitwise_op: option A.integer_type) (l: list T.expr) : ML (option string) = match l with
| [] -> None
| a :: q -> Some (mk_args_aux is_bitwise_op (mk_maybe_bitwise_arg is_bitwise_op (mk_expr a)) q)
type reading = { call: string }
type not_reading = { call: string }
type binders = {
is_empty: bool;
bind: string;
args: string;
}
let empty_binders : binders = {
is_empty = true;
bind = "";
args = "";
}
let push_binder (name: string) (typ: string) (b: binders) : binders = {
is_empty = false;
bind = Printf.sprintf "(%s %s) %s" name typ b.bind;
args = Printf.sprintf " %s%s" name b.args;
}
let mk_function_call (name: string) (b: binders) =
Printf.sprintf "%s%s" name b.args
type parser (a: Type) =
(* name *) string ->
(* binders *) binders ->
(* is_toplevel *) bool ->
(* out *) (string -> ML unit) ->
ML a
let unsupported_parser (s: string) (a: Type) : Tot (parser a) =
fun _ _ _ _ -> failwith (Printf.sprintf "unsupported parser: %s" s)
let leaf_reading_parser (name: string) : parser reading =
fun _ _ _ _ -> { call = name }
let readable_itype_parser_suffix (i: I.itype) : Tot string = match i with
| I.UInt8 | I.UInt8BE -> "u8"
| I.UInt16 -> "u16-le"
| I.UInt16BE -> "u16-be"
| I.UInt32 -> "u32-le"
| I.UInt32BE -> "u32-be"
| I.UInt64 -> "u64-le"
| I.UInt64BE -> "u64-be"
| I.Unit -> "empty"
| I.AllBytes -> "all-bytes"
| I.AllZeros -> "all-zeros"
let parse_readable_itype (i: I.readable_itype) : Tot (parser reading) =
leaf_reading_parser ("parse-" ^ readable_itype_parser_suffix i)
let mk_wrap_parser
(name: string)
(binders: string)
(body: string)
: string
= let input = Printf.sprintf "%s-input" name in
let tmp = Printf.sprintf "%s-tmp" name in
"(define-fun "^name^" ("^binders^"("^input^" State)) State
(after-state ("^body^" "^input^"))
)
"
let wrap_parser (p: parser reading) : parser not_reading =
fun name binders _ out ->
let name' = Printf.sprintf "%s-wrapped" name in
let body = p name' binders false out in
out (mk_wrap_parser name binders.bind body.call);
{ call = mk_function_call name binders }
let mk_toplevel_parser
(name: string)
(binders: string)
(body: string)
: string
= let input = Printf.sprintf "%s-input" name in
"(define-fun "^name^" ("^binders^"("^input^" State)) State
("^body^" "^input^")
)
"
let maybe_toplevel_parser (p: parser not_reading) : parser not_reading =
fun name binders is_toplevel out ->
if is_toplevel
then begin
let name' = Printf.sprintf "%s-body" name in
let body = p name' binders false out in
out (mk_toplevel_parser name binders.bind body.call);
{ call = mk_function_call name binders }
end
else p name binders false out
let parse_all_bytes : parser not_reading =
maybe_toplevel_parser (fun _ _ _ _ -> { call = "parse-all-bytes" })
let parse_all_zeros : parser not_reading =
maybe_toplevel_parser (fun _ _ _ _ -> { call = "parse-all-zeros" })
let parse_itype : I.itype -> parser not_reading = function
| I.AllBytes -> parse_all_bytes
| I.AllZeros -> parse_all_zeros
| i -> wrap_parser (parse_readable_itype i)
let mk_app_without_paren id args =
mk_args_aux None (ident_to_string id) args
let parse_readable_app
(hd: A.ident)
(args: list I.expr)
: Tot (parser reading)
= fun _ _ _ _ -> { call = mk_app_without_paren hd args }
let parse_readable_dtyp
(d: I.readable_dtyp)
: Tot (parser reading)
= match d with
| I.DT_IType i -> parse_readable_itype i
| I.DT_App _ hd args -> parse_readable_app hd args
let parse_not_readable_app
(hd: A.ident)
(args: list I.expr)
: Tot (parser not_reading)
= maybe_toplevel_parser (fun _ _ _ _ -> { call = mk_app_without_paren hd args })
let parse_dtyp
(d: I.dtyp)
: Tot (parser not_reading)
= if I.allow_reader_of_dtyp d
then wrap_parser (parse_readable_dtyp d)
else match d with
| I.DT_IType i -> parse_itype i
| I.DT_App _ hd args -> parse_not_readable_app hd args
let parse_false : parser not_reading =
maybe_toplevel_parser (fun _ _ _ _ -> { call = "parse-false" })
let parse_denoted (d: I.dtyp) : parser not_reading =
parse_dtyp d
let mk_parse_pair
(name: string)
(binders: string)
(fst: string)
(snd: string)
: string
= let input = Printf.sprintf "%s-input" name in
let tmp = Printf.sprintf "%s-tmp" name in
"(define-fun "^name^" ("^binders^"("^input^" State)) State
(let (("^tmp^" ("^fst^" "^input^")))
(if (< (input-size "^tmp^") 0)
"^tmp^"
("^snd^" "^tmp^")
)
)
)
"
let parse_pair (fst: parser not_reading) (snd: parser not_reading) : parser not_reading =
fun name binders _ out ->
let name_fst = Printf.sprintf "%s-fst" name in
let body_fst = fst name_fst binders false out in
let name_snd = Printf.sprintf "%s-snd" name in
let body_snd = snd name_snd binders false out in
out (mk_parse_pair name binders.bind body_fst.call body_snd.call);
{ call = mk_function_call name binders }
let parse_square (p: parser not_reading) : parser not_reading =
fun name binders _ out ->
let body_name = Printf.sprintf "%s-snd" name in
let body = p body_name binders false out in
out (mk_parse_pair name binders.bind body.call body.call);
{ call = mk_function_call name binders }
let mk_parse_dep_pair_with_refinement
(name: string)
(binders: string)
(dfst: string)
(cond_binder_name: string)
(cond: string)
(dsnd_binder_name: string)
(dsnd: string) (* already contains the new argument *)
: string
= let input = Printf.sprintf "%s-input" name in
let tmp = Printf.sprintf "%s-tmp" name in
"(define-fun "^name^" ("^binders^"("^input^" State)) State
(let (("^tmp^" ("^dfst^" "^input^")))
(if (< (input-size (after-state "^tmp^")) 0)
(after-state "^tmp^")
(if (let (("^cond_binder_name^" (return-value "^tmp^"))) "^cond^")
(let (("^dsnd_binder_name^" (return-value "^tmp^")))
("^dsnd^" (after-state "^tmp^"))
)
(mk-state -1 (choice-index (after-state "^tmp^")))
)
)
)
)
"
let parse_dep_pair_with_refinement_gen (tag: parser reading) (cond_binder: string) (cond: unit -> ML string) (payload_binder: string) (payload: parser not_reading) : parser not_reading =
fun name binders _ out ->
let name_tag = Printf.sprintf "%s-tag" name in
let body_tag = tag name_tag binders false out in
let binders' = push_binder payload_binder "Int" binders in (* TODO: support more types *)
let name_payload = Printf.sprintf "%s-payload" name in
let body_payload = payload name_payload binders' false out in
out (mk_parse_dep_pair_with_refinement name binders.bind body_tag.call cond_binder (cond ()) payload_binder body_payload.call);
{ call = mk_function_call name binders }
let parse_dep_pair_with_refinement (tag: parser reading) (cond_binder: A.ident) (cond: unit -> ML string) (payload_binder: A.ident) (payload: parser not_reading) : parser not_reading =
parse_dep_pair_with_refinement_gen tag (ident_to_string cond_binder) cond (ident_to_string payload_binder) payload
let parse_dep_pair (tag: parser reading) (new_binder: A.ident) (payload: parser not_reading) : parser not_reading =
parse_dep_pair_with_refinement tag new_binder (fun _ -> "true") new_binder payload
let parse_refine (tag: parser reading) (cond_binder: A.ident) (cond: unit -> ML string) : parser not_reading =
parse_dep_pair_with_refinement tag cond_binder cond cond_binder (parse_itype I.Unit)
let mk_parse_ifthenelse
(name: string)
(binders: string)
(cond: string)
(f_then: string)
(f_else: string)
: string
= let input = Printf.sprintf "%s-input" name in
"(define-fun "^name^" ("^binders^"("^input^" State)) State
(if "^cond^"
("^f_then^" "^input^")
("^f_else^" "^input^")
)
)
"
let parse_ifthenelse (cond: unit -> ML string) (pthen: parser not_reading) (pelse: parser not_reading) : parser not_reading =
fun name binders _ out ->
let name_then = Printf.sprintf "%s-then" name in
let body_then = pthen name_then binders false out in
let name_else = Printf.sprintf "%s-else" name in
let body_else = pelse name_else binders false out in
out (mk_parse_ifthenelse name binders.bind (cond ()) body_then.call body_else.call);
{ call = mk_function_call name binders }
let mk_parse_exact
(name: string)
(binders: string)
(body: string)
(size: string)
: string
= let input = Printf.sprintf "%s-input" name in
let sz = Printf.sprintf "%s-size" name in
let res = Printf.sprintf "%s-res" name in
"(define-fun "^name^" ("^binders^"("^input^" State)) State
(let (("^sz^" "^size^"))
(if (< (input-size "^input^") "^sz^")
(mk-state -1 (choice-index "^input^"))
(let (("^res^" ("^body^" (mk-state "^sz^" (choice-index "^input^")))))
(mk-state
(if (= (input-size "^res^") 0)
(- (input-size "^input^") "^sz^")
-1
)
(choice-index "^res^")
)
)
)
)
)
"
let parse_exact
(size: unit -> ML string)
(body: parser not_reading)
: Tot (parser not_reading)
= fun name binders _ out ->
let body_name = Printf.sprintf "%s-body" name in
let body = body body_name binders false out in
out (mk_parse_exact name binders.bind body.call (size ()));
{ call = mk_function_call name binders }
let parse_at_most
(size: unit -> ML string)
(body: parser not_reading)
: Tot (parser not_reading)
= parse_exact size (parse_pair body parse_all_bytes)
(*
let mk_parse_list_one
(name: string)
(binders: string)
(p: string)
: string
= let input = Printf.sprintf "%s-input" name in
let res = Printf.sprintf "%s-res" name in
"(define-fun "^name^" ("^binders^"("^input^" (Seq Int))) (Seq Int)
(if (= (seq.len "^input^") 0)
(seq.unit 0)
(let (("^res^" ("^p^" "^input^")))
(if (= (seq.len "^res^") 0)
(as seq.empty (Seq Int))
(if (= (seq.nth "^res^" 0) 0)
(as seq.empty (Seq Int))
"^res^"
)
)
)
)
)
"
let parse_list_one
(body: parser not_reading)
: Tot (parser not_reading)
= fun name binders _ out ->
let body_name = Printf.sprintf "%s-body" name in
let body = body body_name binders false out in
out (mk_parse_list_one name binders.bind body.call);
{ call = mk_function_call name binders }
let rec parse_list_bounded'
(body: parser not_reading)
(logn: nat)
: Tot (parser not_reading)
(decreases logn)
= if logn = 0
then parse_list_one body
else
let logn' = logn - 1 in
parse_square (parse_list_bounded' body logn')
let parse_list_bounded body = parse_list_bounded' body 3 // 64
*)
let mk_parse_list
(name: string)
(rec_call: string)
(binders: string)
(body: string)
: string
= let input = Printf.sprintf "%s-input" name in
"(define-fun-rec "^name^" ("^binders^"("^input^" State)) State
(if (<= (input-size "^input^") 0)
"^input^"
("^rec_call^" ("^body^" "^input^"))
)
)
"
let parse_list
(body: parser not_reading)
: Tot (parser not_reading)
= fun name binders _ out ->
let rec_call = mk_function_call name binders in
let body_name = Printf.sprintf "%s-body" name in
let body = body body_name binders false out in
out (mk_parse_list name rec_call binders.bind body.call);
{ call = rec_call }
let parse_nlist
(size: unit -> ML string)
(body: parser not_reading)
: Tot (parser not_reading)
= parse_exact size (parse_list body)
let mk_parse_string
(name: string)
(rec_call: string)
(binders: string)
(body: string)
(terminator: string)
: string
= let input = Printf.sprintf "%s-input" name in
let tmp = Printf.sprintf "%s-tmp" name in
"(define-fun-rec "^name^" ("^binders^"("^input^" State)) State
(let (("^tmp^" ("^body^" "^input^")))
(if (< (choice-index (after-state "^tmp^")) 0)
(mk-state -1 (choice-index (after-state "^tmp^")))
(if (= (return-value "^tmp^") "^terminator^")
(after-state "^tmp^")
("^rec_call^" (after-state "^tmp^"))
)
)
)
)
"
let parse_string
(body: parser reading)
(terminator: (unit -> ML string))
: Tot (parser not_reading)
= fun name binders _ out ->
let rec_call = mk_function_call name binders in
let body_name = Printf.sprintf "%s-body" name in
let body = body body_name binders false out in
out (mk_parse_string name rec_call binders.bind body.call (terminator ()));
{ call = rec_call }
let rec type_has_actions = function
| I.T_with_dep_action _ _ _
| I.T_dep_pair_with_action _ _ _ _
| I.T_refine_with_action _ _ _ _
| I.T_dep_pair_with_refinement_and_action _ _ _ _ _
| I.T_with_action _ _ _
-> true
| I.T_false _
| I.T_denoted _ _
| I.T_refine _ _ _
| I.T_string _ _ _
-> false
| I.T_if_else _ t1 t2
| I.T_pair _ t1 t2 ->
type_has_actions t1 || type_has_actions t2
| I.T_at_most _ _ t
| I.T_exact _ _ t
| I.T_nlist _ _ t
| I.T_with_comment _ t _
| I.T_dep_pair_with_refinement _ _ _ (_, t)
| I.T_dep_pair _ _ (_, t) ->
type_has_actions t
let rec parse_typ (t : I.typ) : Pure (parser not_reading)
(requires (type_has_actions t == false))
(ensures (fun _ -> True))
= match t with
| I.T_false _ -> parse_false
| I.T_denoted _ d -> parse_denoted d
| I.T_pair _ t1 t2 -> parse_pair (parse_typ t1) (parse_typ t2)
| I.T_dep_pair _ t1 (lam, t2) -> parse_dep_pair (parse_readable_dtyp t1) lam (parse_typ t2)
| I.T_refine _ base (lam, cond) -> parse_refine (parse_readable_dtyp base) lam (fun _ -> mk_expr cond)
| I.T_dep_pair_with_refinement _ base (lam_cond, cond) (lam_k, k) -> parse_dep_pair_with_refinement (parse_readable_dtyp base) lam_cond (fun _ -> mk_expr cond) lam_k (parse_typ k)
| I.T_if_else cond t1 t2 -> parse_ifthenelse (fun _ -> mk_expr cond) (parse_typ t1) (parse_typ t2)
| I.T_with_comment _ base _ -> parse_typ base
| I.T_at_most _ size body -> parse_at_most (fun _ -> mk_expr size) (parse_typ body)
| I.T_exact _ size body -> parse_exact (fun _ -> mk_expr size) (parse_typ body)
| I.T_string _ elt terminator -> parse_string (parse_readable_dtyp elt) (fun _ -> mk_expr terminator)
| I.T_nlist _ size body -> parse_nlist (fun _ -> mk_expr size) (parse_typ body)
type arg_type =
| ArgInt of A.integer_type
| ArgBool
| ArgPointer
let arg_type_of_typ (t: T.typ) : Tot (option arg_type) =
match t with
| T.T_pointer _
| T.T_app _ A.KindOutput _
| T.T_app _ A.KindExtern _
| T.T_app {v = {modul_name = None; name = "PUINT8"}} _ _
-> Some ArgPointer
| T.T_app {v = {modul_name = None; name = "Bool"}} _ _
-> Some ArgBool
| T.T_app i _ _
->
begin match A.maybe_as_integer_typ i with
| Some t -> Some (ArgInt t)
| None -> None
end
| _ -> None
let smt_type_of_typ (t: T.typ) : Tot string =
match arg_type_of_typ t with
| Some ArgBool -> "Bool"
| _ -> "Int"
let rec binders_of_params = function
| [] -> empty_binders
| (id, t) :: q -> push_binder (ident_to_string id) (smt_type_of_typ t) (binders_of_params q)
let mk_definition
(name: string)
(binders: string)
(typ: string)
(body: string)
: Tot string
= "(define-fun "^name^" ("^binders^") "^typ^" "^body^")"
let produce_definition
(i: A.ident)
(param: list T.param)
(typ: T.typ)
(body: T.expr)
(out: string -> ML unit)
: ML unit
= let binders = binders_of_params param in
out (mk_definition (ident_to_string i) binders.bind (smt_type_of_typ typ) (mk_expr body))
let produce_not_type_decl (a: I.not_type_decl) (out: string -> ML unit) : ML unit =
match fst a with
| T.Definition (i, param, typ, body) ->
produce_definition i param typ body out
| T.Assumption _ -> failwith "produce_not_type_decl: unsupported"
| T.Output_type _
| T.Output_type_expr _ _
| T.Extern_type _
| T.Extern_fn _ _ _
-> ()
let prog = list (string & list arg_type)
let produce_type_decl (out: string -> ML unit) (accu: prog) (a: I.type_decl) : ML prog =
let binders = binders_of_params a.name.td_params in
let name = ident_to_string a.name.td_name in
if type_has_actions a.typ then failwith (Printf.sprintf "produce_type_decl: %s still has some actions" name);
let _ = parse_typ a.typ name binders true out in
(name, List.map (fun (i, ty) -> match arg_type_of_typ ty with Some t -> t | None -> failwith (Printf.sprintf "Parser %s has unsupported argument type for %s" name (ident_to_string i))) a.name.td_params) :: accu
let produce_decl (out: string -> ML unit) (accu: prog) (a: I.decl) : ML prog =
match a with
| Inl a -> produce_not_type_decl a out; accu
| Inr a -> produce_type_decl out accu a
let produce_decls (out: string -> ML unit) (accu: prog) (l: list I.decl) : ML prog =
List.fold_left (produce_decl out) accu l
(* Produce the SMT2 encoding of the parser spec *)
let with_out_file
(#a: Type)
(name: string)
(body: ((string -> ML unit) -> ML a))
: ML a
= let fd = FStar.IO.open_write_file name in
let res = body (FStar.IO.write_string fd) in
FStar.IO.close_write_file fd;
res
let with_option_out_file
(#a: Type)
(name: option string)
: Tot ((body: ((string -> ML unit) -> ML a)) -> ML a)
= match name with
| Some name -> with_out_file name
| None -> (fun body -> body (fun _ -> ()))
(* Ask Z3 for test witnesses *)
let read_witness (z3: Z3.z3) : ML (Seq.seq int) =
z3.to_z3 "(get-value (state-witness-size))\n";
let (_, witness_size) = Lisp.read_int_from z3.from_z3 "state-witness-size" in
let rec aux (accu: Seq.seq int) (remaining: int) : ML (Seq.seq int) =
if remaining <= 0
then accu
else
let index = remaining - 1 in
let _ = z3.to_z3 (Printf.sprintf "(eval (choose %d))\n" index) in
let v = Lisp.read_bare_int_from z3.from_z3 in
aux (Seq.cons v accu) index
in
aux Seq.empty witness_size
let rec read_witness_args (z3: Z3.z3) (accu: list string) (n: nat) : ML (list string) =
if n = 0
then accu
else begin
let n' = n - 1 in
z3.to_z3 (Printf.sprintf "(get-value (arg-%d))\n" n');
let arg = Lisp.read_any_from z3.from_z3 (Printf.sprintf "arg-%d" n') in
read_witness_args z3 (arg :: accu) n'
end
let module_and_wrapper_name
(s: string)
: ML (string & string)
= match String.split ['.'] s with
| [modul; fn] -> modul, Target.wrapper_name modul fn
| _ -> failwith "Z3TestGen.wrapper_name"
let rec print_witness_args_as_c
(out: (string -> ML unit))
(l: list arg_type) (args: list string)
: ML unit
= match l, args with
| ArgPointer :: q, _ ->
out "NULL, ";
print_witness_args_as_c out q args
| ty :: ql, a :: qargs ->
out a;
(if ArgInt? ty then out "U" else ());
out ", ";
print_witness_args_as_c out ql qargs
| _ -> ()
let print_witness_call_as_c_aux
(out: (string -> ML unit))
(wrapper_name: string)
(arg_types: list arg_type)
(witness_length: nat)
(args: list string)
: ML unit
=
out wrapper_name;
out "(";
print_witness_args_as_c out arg_types args;
out "witness, ";
out (string_of_int witness_length);
out ");"
let print_witness_call_as_c
(out: (string -> ML unit))
(positive: bool)
(wrapper_name: string)
(arg_types: list arg_type)
(witness_length: nat)
(args: list string)
: ML unit
=
out "
{
BOOLEAN result = ";
print_witness_call_as_c_aux out wrapper_name arg_types witness_length args;
out "
printf(\" ";
print_witness_call_as_c_aux out wrapper_name arg_types witness_length args;
out " // \");
if (result) printf (\"ACCEPTED\\n\\n\"); else printf (\"REJECTED\\n\\n\");
if (";
if positive then out "!";
out "result)
return 1;
};
"
let print_witness_as_c_aux
(out: (string -> ML unit))
(witness: Seq.seq int)
(len: int { len == Seq.length witness })
: ML unit
=
out " uint8_t witness[";
out (string_of_int len);
out "] = {";
begin match Seq.seq_to_list witness with
| [] -> ()
| a :: q ->
out (string_of_int a);
List.iter (fun i -> out ", "; out (string_of_int i)) q
end;
out "};"
let print_witness_as_c_gen
(out: (string -> ML unit))
(witness: Seq.seq int)
(f: (len: int { len == Seq.length witness }) -> ML unit)
: ML unit
= let len = Seq.length witness in
out "{\n";
print_witness_as_c_aux out witness len;
out "
printf(\"";
print_witness_as_c_aux out witness len;
out "\\n\");
";
f len;
out "};
"
let print_witness_as_c
(out: (string -> ML unit))
(positive: bool)
(wrapper_name: string)
(arg_types: list arg_type)
(witness: Seq.seq int)
(args: list string) | false | false | Z3TestGen.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val print_witness_as_c
(out: (string -> ML unit))
(positive: bool)
(wrapper_name: string)
(arg_types: list arg_type)
(witness: Seq.seq int)
(args: list string)
: ML unit | [] | Z3TestGen.print_witness_as_c | {
"file_name": "src/3d/Z3TestGen.fst",
"git_rev": "446a08ce38df905547cf20f28c43776b22b8087a",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} |
out: (_: Prims.string -> FStar.All.ML Prims.unit) ->
positive: Prims.bool ->
wrapper_name: Prims.string ->
arg_types: Prims.list Z3TestGen.arg_type ->
witness: FStar.Seq.Base.seq Prims.int ->
args: Prims.list Prims.string
-> FStar.All.ML Prims.unit | {
"end_col": 3,
"end_line": 973,
"start_col": 2,
"start_line": 971
} |
Prims.Tot | val mk_arg_conj (accu: string) (i: nat) (l: list string) : Tot string (decreases l) | [
{
"abbrev": true,
"full_module": "InterpreterTarget",
"short_module": "I"
},
{
"abbrev": true,
"full_module": "Target",
"short_module": "T"
},
{
"abbrev": true,
"full_module": "Ast",
"short_module": "A"
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.All",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.Printf",
"short_module": "Printf"
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let rec mk_arg_conj (accu: string) (i: nat) (l: list string) : Tot string (decreases l) =
match l with
| [] -> accu
| arg :: q ->
mk_arg_conj (Printf.sprintf "(and %s (= arg-%d %s))" accu i arg) (i + 1) q | val mk_arg_conj (accu: string) (i: nat) (l: list string) : Tot string (decreases l)
let rec mk_arg_conj (accu: string) (i: nat) (l: list string) : Tot string (decreases l) = | false | null | false | match l with
| [] -> accu
| arg :: q -> mk_arg_conj (Printf.sprintf "(and %s (= arg-%d %s))" accu i arg) (i + 1) q | {
"checked_file": "Z3TestGen.fst.checked",
"dependencies": [
"Z3.fsti.checked",
"Target.fsti.checked",
"prims.fst.checked",
"OS.fsti.checked",
"Lisp.fsti.checked",
"InterpreterTarget.fsti.checked",
"FStar.String.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Printf.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.List.Tot.fst.checked",
"FStar.List.fst.checked",
"FStar.IO.fst.checked",
"FStar.Char.fsti.checked",
"FStar.All.fst.checked",
"Ast.fst.checked"
],
"interface_file": false,
"source_file": "Z3TestGen.fst"
} | [
"total",
""
] | [
"Prims.string",
"Prims.nat",
"Prims.list",
"Z3TestGen.mk_arg_conj",
"FStar.Printf.sprintf",
"Prims.op_Addition"
] | [] | module Z3TestGen
module Printf = FStar.Printf
open FStar.All
open FStar.Mul
module A = Ast
module T = Target
module I = InterpreterTarget
let prelude : string =
"
(set-option :produce-models true)
(declare-datatypes () ((State (mk-state (input-size Int) (choice-index Int)))))
(declare-datatypes () ((Result (mk-result (return-value Int) (after-state State)))))
(define-fun parse-empty ((x State)) Result
(mk-result 0 x)
)
(declare-fun choose (Int) Int)
(assert (forall ((i Int))
(and (<= 0 (choose i)) (< (choose i) 256))
))
(define-fun parse-false ((x State)) State
(mk-state -1 (choice-index x))
)
(define-fun parse-all-bytes ((x State)) State
(if (<= (input-size x) 0)
x
(mk-state 0 (+ (choice-index x) (input-size x)))
)
)
(define-fun parse-all-zeros ((x State)) State
(if (<= (input-size x) 0)
x
(mk-state
(if
(forall ((j Int))
(if (and (<= 0 j) (< j (input-size x)))
(= (choose (+ (choice-index x) j)) 0)
true
)
)
0
-1
)
(+ (choice-index x) (input-size x))
)
)
)
(define-fun parse-u8 ((x State)) Result
(mk-result
(choose (choice-index x))
(mk-state (- (input-size x) 1) (+ (choice-index x) 1))
)
)
(define-fun parse-u16-be ((x State)) Result
(mk-result
(+ (choose (+ 1 (choice-index x)))
(* 256
(choose (+ 0 (choice-index x)))
)
)
(mk-state (- (input-size x) 2) (+ (choice-index x) 2))
)
)
(define-fun parse-u16-le ((x State)) Result
(mk-result
(+ (choose (+ 0 (choice-index x)))
(* 256
(choose (+ 1 (choice-index x)))
)
)
(mk-state (- (input-size x) 2) (+ (choice-index x) 2))
)
)
(define-fun parse-u32-be ((x State)) Result
(mk-result
(+ (choose (+ 3 (choice-index x)))
(* 256
(+ (choose (+ 2 (choice-index x)))
(* 256
(+ (choose (+ 1 (choice-index x)))
(* 256
(choose (+ 0 (choice-index x)))
)
)
)
)
)
)
(mk-state (- (input-size x) 4) (+ (choice-index x) 4))
)
)
(define-fun parse-u32-le ((x State)) Result
(mk-result
(+ (choose (+ 0 (choice-index x)))
(* 256
(+ (choose (+ 1 (choice-index x)))
(* 256
(+ (choose (+ 2 (choice-index x)))
(* 256
(choose (+ 3 (choice-index x)))
)
)
)
)
)
)
(mk-state (- (input-size x) 4) (+ (choice-index x) 4))
)
)
(define-fun parse-u64-be ((x State)) Result
(mk-result
(+ (choose (+ 7 (choice-index x)))
(* 256
(+ (choose (+ 6 (choice-index x)))
(* 256
(+ (choose (+ 5 (choice-index x)))
(* 256
(+ (choose (+ 4 (choice-index x)))
(* 256
(+ (choose (+ 3 (choice-index x)))
(* 256
(+ (choose (+ 2 (choice-index x)))
(* 256
(+ (choose (+ 1 (choice-index x)))
(* 256
(choose (+ 0 (choice-index x)))
)
)
)
)
)
)
)
)
)
)
)
)
)
)
(mk-state (- (input-size x) 8) (+ (choice-index x) 8))
)
)
(define-fun parse-u64-le ((x State)) Result
(mk-result
(+ (choose (+ 0 (choice-index x)))
(* 256
(+ (choose (+ 1 (choice-index x)))
(* 256
(+ (choose (+ 2 (choice-index x)))
(* 256
(+ (choose (+ 3 (choice-index x)))
(* 256
(+ (choose (+ 4 (choice-index x)))
(* 256
(+ (choose (+ 5 (choice-index x)))
(* 256
(+ (choose (+ 6 (choice-index x)))
(* 256
(choose (+ 7 (choice-index x)))
)
)
)
)
)
)
)
)
)
)
)
)
)
)
(mk-state (- (input-size x) 8) (+ (choice-index x) 8))
)
)
(define-fun-rec pow-2 ((amount Int)) Int
(if (<= amount 0)
1
(* 2 (pow-2 (- amount 1)))
)
)
;; see LowParse.BitFields.get_bitfield_eq
(define-fun get-bitfield-lsb ((nbBits Int) (value Int) (bitsFrom Int) (bitsTo Int)) Int
(mod (div value (pow-2 bitsFrom)) (pow-2 (- bitsTo bitsFrom)))
)
;; see EverParse3d.Prelude.StaticHeader
(define-fun get-bitfield-msb ((nbBits Int) (value Int) (bitsFrom Int) (bitsTo Int)) Int
(get-bitfield-lsb nbBits value (- nbBits bitsTo) (- nbBits bitsFrom))
)
(declare-const initial-input-size Int)
(assert (>= initial-input-size 0))
(define-fun initial-state () State (mk-state initial-input-size 0))
"
let mk_constant = function
| A.Unit -> "0"
| A.Int _ x -> string_of_int x
| A.XInt _ x -> string_of_int (OS.int_of_string x)
| A.Bool true -> "true"
| A.Bool false -> "false"
let mk_app fn = function
| None -> fn
| Some args -> Printf.sprintf "(%s %s)" fn args
let assert_some = function
| None -> failwith "assert_some"
| Some x -> x
let is_bitwise_op (x: T.op) : Tot (option A.integer_type) =
match x with
| T.BitwiseAnd a
| T.BitwiseXor a
| T.BitwiseOr a
| T.BitwiseNot a
| T.ShiftLeft a
| T.ShiftRight a
-> Some a
| _ -> None
let mk_bitwise_op (op: string) (bitvec_args: option string) : ML string =
mk_app "bv2int" (Some (mk_app op bitvec_args))
let integer_type_bit_size = function
| A.UInt8 -> 8
| A.UInt16 -> 16
| A.UInt32 -> 32
| A.UInt64 -> 64
let mk_bitwise_not (a: A.integer_type) (bitvec_arg: option string) : ML string =
match bitvec_arg with
| None -> failwith "ill-formed bitwise_not"
| Some arg -> "(bv2int (bvxor "^arg^" #b"^String.make (integer_type_bit_size a) '1'^"))"
let mk_op : T.op -> option string -> ML string = function
| T.Eq -> mk_app "="
| T.Neq -> (fun s -> mk_app "not" (Some (mk_app "=" s)))
| T.And -> mk_app "and"
| T.Or -> mk_app "or"
| T.Not -> mk_app "not"
| T.Plus _ -> mk_app "+"
| T.Minus _ -> mk_app "-"
| T.Mul _ -> mk_app "*"
| T.Division _ -> mk_app "div"
| T.Remainder _ -> mk_app "mod"
| T.BitwiseAnd _ -> mk_bitwise_op "bvand"
| T.BitwiseXor _ -> mk_bitwise_op "bvxor"
| T.BitwiseOr _ -> mk_bitwise_op "bvor"
| T.BitwiseNot a -> mk_bitwise_not a
| T.ShiftLeft _ -> mk_bitwise_op "bvshl"
| T.ShiftRight _ -> mk_bitwise_op "bvlshr"
| T.LT _ -> mk_app "<"
| T.GT _ -> mk_app ">"
| T.LE _ -> mk_app "<="
| T.GE _ -> mk_app ">="
| T.IfThenElse -> mk_app "if"
| T.BitFieldOf size order -> (fun arg -> Printf.sprintf "(get-bitfield-%ssb %d %s)" (match order with A.LSBFirst -> "l" | A.MSBFirst -> "m") size (assert_some arg))
| T.Cast _ _ -> assert_some (* casts allowed only if they are proven not to lose precision *)
| T.Ext s -> mk_app s
let ident_to_string = A.ident_to_string
let mk_bitwise_arg (t: A.integer_type) (arg: string) : Tot string =
mk_app ("(_ int2bv "^string_of_int (integer_type_bit_size t)^")") (Some arg)
let mk_maybe_bitwise_arg (t: option A.integer_type) (arg: string) : Tot string =
match t with
| None -> arg
| Some t -> mk_bitwise_arg t arg
let rec mk_expr (e: T.expr) : ML string = match fst e with
| T.Constant c -> mk_constant c
| T.Identifier i -> ident_to_string i
| T.App hd args -> mk_op hd (mk_args (is_bitwise_op hd) args)
| _ -> failwith "mk_expr: not supported"
and mk_args_aux (is_bitwise_op: option A.integer_type) accu : (list T.expr -> ML string) = function
| [] -> accu
| a :: q -> mk_args_aux is_bitwise_op (Printf.sprintf "%s %s" accu (mk_maybe_bitwise_arg is_bitwise_op (mk_expr a))) q
and mk_args (is_bitwise_op: option A.integer_type) (l: list T.expr) : ML (option string) = match l with
| [] -> None
| a :: q -> Some (mk_args_aux is_bitwise_op (mk_maybe_bitwise_arg is_bitwise_op (mk_expr a)) q)
type reading = { call: string }
type not_reading = { call: string }
type binders = {
is_empty: bool;
bind: string;
args: string;
}
let empty_binders : binders = {
is_empty = true;
bind = "";
args = "";
}
let push_binder (name: string) (typ: string) (b: binders) : binders = {
is_empty = false;
bind = Printf.sprintf "(%s %s) %s" name typ b.bind;
args = Printf.sprintf " %s%s" name b.args;
}
let mk_function_call (name: string) (b: binders) =
Printf.sprintf "%s%s" name b.args
type parser (a: Type) =
(* name *) string ->
(* binders *) binders ->
(* is_toplevel *) bool ->
(* out *) (string -> ML unit) ->
ML a
let unsupported_parser (s: string) (a: Type) : Tot (parser a) =
fun _ _ _ _ -> failwith (Printf.sprintf "unsupported parser: %s" s)
let leaf_reading_parser (name: string) : parser reading =
fun _ _ _ _ -> { call = name }
let readable_itype_parser_suffix (i: I.itype) : Tot string = match i with
| I.UInt8 | I.UInt8BE -> "u8"
| I.UInt16 -> "u16-le"
| I.UInt16BE -> "u16-be"
| I.UInt32 -> "u32-le"
| I.UInt32BE -> "u32-be"
| I.UInt64 -> "u64-le"
| I.UInt64BE -> "u64-be"
| I.Unit -> "empty"
| I.AllBytes -> "all-bytes"
| I.AllZeros -> "all-zeros"
let parse_readable_itype (i: I.readable_itype) : Tot (parser reading) =
leaf_reading_parser ("parse-" ^ readable_itype_parser_suffix i)
let mk_wrap_parser
(name: string)
(binders: string)
(body: string)
: string
= let input = Printf.sprintf "%s-input" name in
let tmp = Printf.sprintf "%s-tmp" name in
"(define-fun "^name^" ("^binders^"("^input^" State)) State
(after-state ("^body^" "^input^"))
)
"
let wrap_parser (p: parser reading) : parser not_reading =
fun name binders _ out ->
let name' = Printf.sprintf "%s-wrapped" name in
let body = p name' binders false out in
out (mk_wrap_parser name binders.bind body.call);
{ call = mk_function_call name binders }
let mk_toplevel_parser
(name: string)
(binders: string)
(body: string)
: string
= let input = Printf.sprintf "%s-input" name in
"(define-fun "^name^" ("^binders^"("^input^" State)) State
("^body^" "^input^")
)
"
let maybe_toplevel_parser (p: parser not_reading) : parser not_reading =
fun name binders is_toplevel out ->
if is_toplevel
then begin
let name' = Printf.sprintf "%s-body" name in
let body = p name' binders false out in
out (mk_toplevel_parser name binders.bind body.call);
{ call = mk_function_call name binders }
end
else p name binders false out
let parse_all_bytes : parser not_reading =
maybe_toplevel_parser (fun _ _ _ _ -> { call = "parse-all-bytes" })
let parse_all_zeros : parser not_reading =
maybe_toplevel_parser (fun _ _ _ _ -> { call = "parse-all-zeros" })
let parse_itype : I.itype -> parser not_reading = function
| I.AllBytes -> parse_all_bytes
| I.AllZeros -> parse_all_zeros
| i -> wrap_parser (parse_readable_itype i)
let mk_app_without_paren id args =
mk_args_aux None (ident_to_string id) args
let parse_readable_app
(hd: A.ident)
(args: list I.expr)
: Tot (parser reading)
= fun _ _ _ _ -> { call = mk_app_without_paren hd args }
let parse_readable_dtyp
(d: I.readable_dtyp)
: Tot (parser reading)
= match d with
| I.DT_IType i -> parse_readable_itype i
| I.DT_App _ hd args -> parse_readable_app hd args
let parse_not_readable_app
(hd: A.ident)
(args: list I.expr)
: Tot (parser not_reading)
= maybe_toplevel_parser (fun _ _ _ _ -> { call = mk_app_without_paren hd args })
let parse_dtyp
(d: I.dtyp)
: Tot (parser not_reading)
= if I.allow_reader_of_dtyp d
then wrap_parser (parse_readable_dtyp d)
else match d with
| I.DT_IType i -> parse_itype i
| I.DT_App _ hd args -> parse_not_readable_app hd args
let parse_false : parser not_reading =
maybe_toplevel_parser (fun _ _ _ _ -> { call = "parse-false" })
let parse_denoted (d: I.dtyp) : parser not_reading =
parse_dtyp d
let mk_parse_pair
(name: string)
(binders: string)
(fst: string)
(snd: string)
: string
= let input = Printf.sprintf "%s-input" name in
let tmp = Printf.sprintf "%s-tmp" name in
"(define-fun "^name^" ("^binders^"("^input^" State)) State
(let (("^tmp^" ("^fst^" "^input^")))
(if (< (input-size "^tmp^") 0)
"^tmp^"
("^snd^" "^tmp^")
)
)
)
"
let parse_pair (fst: parser not_reading) (snd: parser not_reading) : parser not_reading =
fun name binders _ out ->
let name_fst = Printf.sprintf "%s-fst" name in
let body_fst = fst name_fst binders false out in
let name_snd = Printf.sprintf "%s-snd" name in
let body_snd = snd name_snd binders false out in
out (mk_parse_pair name binders.bind body_fst.call body_snd.call);
{ call = mk_function_call name binders }
let parse_square (p: parser not_reading) : parser not_reading =
fun name binders _ out ->
let body_name = Printf.sprintf "%s-snd" name in
let body = p body_name binders false out in
out (mk_parse_pair name binders.bind body.call body.call);
{ call = mk_function_call name binders }
let mk_parse_dep_pair_with_refinement
(name: string)
(binders: string)
(dfst: string)
(cond_binder_name: string)
(cond: string)
(dsnd_binder_name: string)
(dsnd: string) (* already contains the new argument *)
: string
= let input = Printf.sprintf "%s-input" name in
let tmp = Printf.sprintf "%s-tmp" name in
"(define-fun "^name^" ("^binders^"("^input^" State)) State
(let (("^tmp^" ("^dfst^" "^input^")))
(if (< (input-size (after-state "^tmp^")) 0)
(after-state "^tmp^")
(if (let (("^cond_binder_name^" (return-value "^tmp^"))) "^cond^")
(let (("^dsnd_binder_name^" (return-value "^tmp^")))
("^dsnd^" (after-state "^tmp^"))
)
(mk-state -1 (choice-index (after-state "^tmp^")))
)
)
)
)
"
let parse_dep_pair_with_refinement_gen (tag: parser reading) (cond_binder: string) (cond: unit -> ML string) (payload_binder: string) (payload: parser not_reading) : parser not_reading =
fun name binders _ out ->
let name_tag = Printf.sprintf "%s-tag" name in
let body_tag = tag name_tag binders false out in
let binders' = push_binder payload_binder "Int" binders in (* TODO: support more types *)
let name_payload = Printf.sprintf "%s-payload" name in
let body_payload = payload name_payload binders' false out in
out (mk_parse_dep_pair_with_refinement name binders.bind body_tag.call cond_binder (cond ()) payload_binder body_payload.call);
{ call = mk_function_call name binders }
let parse_dep_pair_with_refinement (tag: parser reading) (cond_binder: A.ident) (cond: unit -> ML string) (payload_binder: A.ident) (payload: parser not_reading) : parser not_reading =
parse_dep_pair_with_refinement_gen tag (ident_to_string cond_binder) cond (ident_to_string payload_binder) payload
let parse_dep_pair (tag: parser reading) (new_binder: A.ident) (payload: parser not_reading) : parser not_reading =
parse_dep_pair_with_refinement tag new_binder (fun _ -> "true") new_binder payload
let parse_refine (tag: parser reading) (cond_binder: A.ident) (cond: unit -> ML string) : parser not_reading =
parse_dep_pair_with_refinement tag cond_binder cond cond_binder (parse_itype I.Unit)
let mk_parse_ifthenelse
(name: string)
(binders: string)
(cond: string)
(f_then: string)
(f_else: string)
: string
= let input = Printf.sprintf "%s-input" name in
"(define-fun "^name^" ("^binders^"("^input^" State)) State
(if "^cond^"
("^f_then^" "^input^")
("^f_else^" "^input^")
)
)
"
let parse_ifthenelse (cond: unit -> ML string) (pthen: parser not_reading) (pelse: parser not_reading) : parser not_reading =
fun name binders _ out ->
let name_then = Printf.sprintf "%s-then" name in
let body_then = pthen name_then binders false out in
let name_else = Printf.sprintf "%s-else" name in
let body_else = pelse name_else binders false out in
out (mk_parse_ifthenelse name binders.bind (cond ()) body_then.call body_else.call);
{ call = mk_function_call name binders }
let mk_parse_exact
(name: string)
(binders: string)
(body: string)
(size: string)
: string
= let input = Printf.sprintf "%s-input" name in
let sz = Printf.sprintf "%s-size" name in
let res = Printf.sprintf "%s-res" name in
"(define-fun "^name^" ("^binders^"("^input^" State)) State
(let (("^sz^" "^size^"))
(if (< (input-size "^input^") "^sz^")
(mk-state -1 (choice-index "^input^"))
(let (("^res^" ("^body^" (mk-state "^sz^" (choice-index "^input^")))))
(mk-state
(if (= (input-size "^res^") 0)
(- (input-size "^input^") "^sz^")
-1
)
(choice-index "^res^")
)
)
)
)
)
"
let parse_exact
(size: unit -> ML string)
(body: parser not_reading)
: Tot (parser not_reading)
= fun name binders _ out ->
let body_name = Printf.sprintf "%s-body" name in
let body = body body_name binders false out in
out (mk_parse_exact name binders.bind body.call (size ()));
{ call = mk_function_call name binders }
let parse_at_most
(size: unit -> ML string)
(body: parser not_reading)
: Tot (parser not_reading)
= parse_exact size (parse_pair body parse_all_bytes)
(*
let mk_parse_list_one
(name: string)
(binders: string)
(p: string)
: string
= let input = Printf.sprintf "%s-input" name in
let res = Printf.sprintf "%s-res" name in
"(define-fun "^name^" ("^binders^"("^input^" (Seq Int))) (Seq Int)
(if (= (seq.len "^input^") 0)
(seq.unit 0)
(let (("^res^" ("^p^" "^input^")))
(if (= (seq.len "^res^") 0)
(as seq.empty (Seq Int))
(if (= (seq.nth "^res^" 0) 0)
(as seq.empty (Seq Int))
"^res^"
)
)
)
)
)
"
let parse_list_one
(body: parser not_reading)
: Tot (parser not_reading)
= fun name binders _ out ->
let body_name = Printf.sprintf "%s-body" name in
let body = body body_name binders false out in
out (mk_parse_list_one name binders.bind body.call);
{ call = mk_function_call name binders }
let rec parse_list_bounded'
(body: parser not_reading)
(logn: nat)
: Tot (parser not_reading)
(decreases logn)
= if logn = 0
then parse_list_one body
else
let logn' = logn - 1 in
parse_square (parse_list_bounded' body logn')
let parse_list_bounded body = parse_list_bounded' body 3 // 64
*)
let mk_parse_list
(name: string)
(rec_call: string)
(binders: string)
(body: string)
: string
= let input = Printf.sprintf "%s-input" name in
"(define-fun-rec "^name^" ("^binders^"("^input^" State)) State
(if (<= (input-size "^input^") 0)
"^input^"
("^rec_call^" ("^body^" "^input^"))
)
)
"
let parse_list
(body: parser not_reading)
: Tot (parser not_reading)
= fun name binders _ out ->
let rec_call = mk_function_call name binders in
let body_name = Printf.sprintf "%s-body" name in
let body = body body_name binders false out in
out (mk_parse_list name rec_call binders.bind body.call);
{ call = rec_call }
let parse_nlist
(size: unit -> ML string)
(body: parser not_reading)
: Tot (parser not_reading)
= parse_exact size (parse_list body)
let mk_parse_string
(name: string)
(rec_call: string)
(binders: string)
(body: string)
(terminator: string)
: string
= let input = Printf.sprintf "%s-input" name in
let tmp = Printf.sprintf "%s-tmp" name in
"(define-fun-rec "^name^" ("^binders^"("^input^" State)) State
(let (("^tmp^" ("^body^" "^input^")))
(if (< (choice-index (after-state "^tmp^")) 0)
(mk-state -1 (choice-index (after-state "^tmp^")))
(if (= (return-value "^tmp^") "^terminator^")
(after-state "^tmp^")
("^rec_call^" (after-state "^tmp^"))
)
)
)
)
"
let parse_string
(body: parser reading)
(terminator: (unit -> ML string))
: Tot (parser not_reading)
= fun name binders _ out ->
let rec_call = mk_function_call name binders in
let body_name = Printf.sprintf "%s-body" name in
let body = body body_name binders false out in
out (mk_parse_string name rec_call binders.bind body.call (terminator ()));
{ call = rec_call }
let rec type_has_actions = function
| I.T_with_dep_action _ _ _
| I.T_dep_pair_with_action _ _ _ _
| I.T_refine_with_action _ _ _ _
| I.T_dep_pair_with_refinement_and_action _ _ _ _ _
| I.T_with_action _ _ _
-> true
| I.T_false _
| I.T_denoted _ _
| I.T_refine _ _ _
| I.T_string _ _ _
-> false
| I.T_if_else _ t1 t2
| I.T_pair _ t1 t2 ->
type_has_actions t1 || type_has_actions t2
| I.T_at_most _ _ t
| I.T_exact _ _ t
| I.T_nlist _ _ t
| I.T_with_comment _ t _
| I.T_dep_pair_with_refinement _ _ _ (_, t)
| I.T_dep_pair _ _ (_, t) ->
type_has_actions t
let rec parse_typ (t : I.typ) : Pure (parser not_reading)
(requires (type_has_actions t == false))
(ensures (fun _ -> True))
= match t with
| I.T_false _ -> parse_false
| I.T_denoted _ d -> parse_denoted d
| I.T_pair _ t1 t2 -> parse_pair (parse_typ t1) (parse_typ t2)
| I.T_dep_pair _ t1 (lam, t2) -> parse_dep_pair (parse_readable_dtyp t1) lam (parse_typ t2)
| I.T_refine _ base (lam, cond) -> parse_refine (parse_readable_dtyp base) lam (fun _ -> mk_expr cond)
| I.T_dep_pair_with_refinement _ base (lam_cond, cond) (lam_k, k) -> parse_dep_pair_with_refinement (parse_readable_dtyp base) lam_cond (fun _ -> mk_expr cond) lam_k (parse_typ k)
| I.T_if_else cond t1 t2 -> parse_ifthenelse (fun _ -> mk_expr cond) (parse_typ t1) (parse_typ t2)
| I.T_with_comment _ base _ -> parse_typ base
| I.T_at_most _ size body -> parse_at_most (fun _ -> mk_expr size) (parse_typ body)
| I.T_exact _ size body -> parse_exact (fun _ -> mk_expr size) (parse_typ body)
| I.T_string _ elt terminator -> parse_string (parse_readable_dtyp elt) (fun _ -> mk_expr terminator)
| I.T_nlist _ size body -> parse_nlist (fun _ -> mk_expr size) (parse_typ body)
type arg_type =
| ArgInt of A.integer_type
| ArgBool
| ArgPointer
let arg_type_of_typ (t: T.typ) : Tot (option arg_type) =
match t with
| T.T_pointer _
| T.T_app _ A.KindOutput _
| T.T_app _ A.KindExtern _
| T.T_app {v = {modul_name = None; name = "PUINT8"}} _ _
-> Some ArgPointer
| T.T_app {v = {modul_name = None; name = "Bool"}} _ _
-> Some ArgBool
| T.T_app i _ _
->
begin match A.maybe_as_integer_typ i with
| Some t -> Some (ArgInt t)
| None -> None
end
| _ -> None
let smt_type_of_typ (t: T.typ) : Tot string =
match arg_type_of_typ t with
| Some ArgBool -> "Bool"
| _ -> "Int"
let rec binders_of_params = function
| [] -> empty_binders
| (id, t) :: q -> push_binder (ident_to_string id) (smt_type_of_typ t) (binders_of_params q)
let mk_definition
(name: string)
(binders: string)
(typ: string)
(body: string)
: Tot string
= "(define-fun "^name^" ("^binders^") "^typ^" "^body^")"
let produce_definition
(i: A.ident)
(param: list T.param)
(typ: T.typ)
(body: T.expr)
(out: string -> ML unit)
: ML unit
= let binders = binders_of_params param in
out (mk_definition (ident_to_string i) binders.bind (smt_type_of_typ typ) (mk_expr body))
let produce_not_type_decl (a: I.not_type_decl) (out: string -> ML unit) : ML unit =
match fst a with
| T.Definition (i, param, typ, body) ->
produce_definition i param typ body out
| T.Assumption _ -> failwith "produce_not_type_decl: unsupported"
| T.Output_type _
| T.Output_type_expr _ _
| T.Extern_type _
| T.Extern_fn _ _ _
-> ()
let prog = list (string & list arg_type)
let produce_type_decl (out: string -> ML unit) (accu: prog) (a: I.type_decl) : ML prog =
let binders = binders_of_params a.name.td_params in
let name = ident_to_string a.name.td_name in
if type_has_actions a.typ then failwith (Printf.sprintf "produce_type_decl: %s still has some actions" name);
let _ = parse_typ a.typ name binders true out in
(name, List.map (fun (i, ty) -> match arg_type_of_typ ty with Some t -> t | None -> failwith (Printf.sprintf "Parser %s has unsupported argument type for %s" name (ident_to_string i))) a.name.td_params) :: accu
let produce_decl (out: string -> ML unit) (accu: prog) (a: I.decl) : ML prog =
match a with
| Inl a -> produce_not_type_decl a out; accu
| Inr a -> produce_type_decl out accu a
let produce_decls (out: string -> ML unit) (accu: prog) (l: list I.decl) : ML prog =
List.fold_left (produce_decl out) accu l
(* Produce the SMT2 encoding of the parser spec *)
let with_out_file
(#a: Type)
(name: string)
(body: ((string -> ML unit) -> ML a))
: ML a
= let fd = FStar.IO.open_write_file name in
let res = body (FStar.IO.write_string fd) in
FStar.IO.close_write_file fd;
res
let with_option_out_file
(#a: Type)
(name: option string)
: Tot ((body: ((string -> ML unit) -> ML a)) -> ML a)
= match name with
| Some name -> with_out_file name
| None -> (fun body -> body (fun _ -> ()))
(* Ask Z3 for test witnesses *)
let read_witness (z3: Z3.z3) : ML (Seq.seq int) =
z3.to_z3 "(get-value (state-witness-size))\n";
let (_, witness_size) = Lisp.read_int_from z3.from_z3 "state-witness-size" in
let rec aux (accu: Seq.seq int) (remaining: int) : ML (Seq.seq int) =
if remaining <= 0
then accu
else
let index = remaining - 1 in
let _ = z3.to_z3 (Printf.sprintf "(eval (choose %d))\n" index) in
let v = Lisp.read_bare_int_from z3.from_z3 in
aux (Seq.cons v accu) index
in
aux Seq.empty witness_size
let rec read_witness_args (z3: Z3.z3) (accu: list string) (n: nat) : ML (list string) =
if n = 0
then accu
else begin
let n' = n - 1 in
z3.to_z3 (Printf.sprintf "(get-value (arg-%d))\n" n');
let arg = Lisp.read_any_from z3.from_z3 (Printf.sprintf "arg-%d" n') in
read_witness_args z3 (arg :: accu) n'
end
let module_and_wrapper_name
(s: string)
: ML (string & string)
= match String.split ['.'] s with
| [modul; fn] -> modul, Target.wrapper_name modul fn
| _ -> failwith "Z3TestGen.wrapper_name"
let rec print_witness_args_as_c
(out: (string -> ML unit))
(l: list arg_type) (args: list string)
: ML unit
= match l, args with
| ArgPointer :: q, _ ->
out "NULL, ";
print_witness_args_as_c out q args
| ty :: ql, a :: qargs ->
out a;
(if ArgInt? ty then out "U" else ());
out ", ";
print_witness_args_as_c out ql qargs
| _ -> ()
let print_witness_call_as_c_aux
(out: (string -> ML unit))
(wrapper_name: string)
(arg_types: list arg_type)
(witness_length: nat)
(args: list string)
: ML unit
=
out wrapper_name;
out "(";
print_witness_args_as_c out arg_types args;
out "witness, ";
out (string_of_int witness_length);
out ");"
let print_witness_call_as_c
(out: (string -> ML unit))
(positive: bool)
(wrapper_name: string)
(arg_types: list arg_type)
(witness_length: nat)
(args: list string)
: ML unit
=
out "
{
BOOLEAN result = ";
print_witness_call_as_c_aux out wrapper_name arg_types witness_length args;
out "
printf(\" ";
print_witness_call_as_c_aux out wrapper_name arg_types witness_length args;
out " // \");
if (result) printf (\"ACCEPTED\\n\\n\"); else printf (\"REJECTED\\n\\n\");
if (";
if positive then out "!";
out "result)
return 1;
};
"
let print_witness_as_c_aux
(out: (string -> ML unit))
(witness: Seq.seq int)
(len: int { len == Seq.length witness })
: ML unit
=
out " uint8_t witness[";
out (string_of_int len);
out "] = {";
begin match Seq.seq_to_list witness with
| [] -> ()
| a :: q ->
out (string_of_int a);
List.iter (fun i -> out ", "; out (string_of_int i)) q
end;
out "};"
let print_witness_as_c_gen
(out: (string -> ML unit))
(witness: Seq.seq int)
(f: (len: int { len == Seq.length witness }) -> ML unit)
: ML unit
= let len = Seq.length witness in
out "{\n";
print_witness_as_c_aux out witness len;
out "
printf(\"";
print_witness_as_c_aux out witness len;
out "\\n\");
";
f len;
out "};
"
let print_witness_as_c
(out: (string -> ML unit))
(positive: bool)
(wrapper_name: string)
(arg_types: list arg_type)
(witness: Seq.seq int)
(args: list string)
: ML unit
= print_witness_as_c_gen out witness (fun len ->
print_witness_call_as_c out positive wrapper_name arg_types len args
)
let print_diff_witness_as_c
(out: (string -> ML unit))
(wrapper_name1: string)
(wrapper_name2: string)
(arg_types: list arg_type)
(witness: Seq.seq int)
(args: list string)
: ML unit
= print_witness_as_c_gen out witness (fun len ->
print_witness_call_as_c out true wrapper_name1 arg_types len args;
print_witness_call_as_c out false wrapper_name2 arg_types len args
)
let print_witness (witness: Seq.seq int) : ML unit =
FStar.IO.print_string " produced witness: [";
List.iter (fun i -> FStar.IO.print_string (string_of_int i); FStar.IO.print_string "; ") (Seq.seq_to_list witness);
FStar.IO.print_string "]\n"
let rec mk_witness_call (accu: string) (l: list arg_type) (args: list string) : Tot string (decreases l) =
match l, args with
| ArgPointer :: q, _ -> mk_witness_call (Printf.sprintf "%s 0" accu) q args
| _ :: ql, a :: qargs -> mk_witness_call (Printf.sprintf "%s %s" accu a) ql qargs
| _ -> Printf.sprintf "(%s)" accu
let print_witness_and_call (name: string) (l: list arg_type) (witness: Seq.seq int) (args: list string) : ML unit =
FStar.IO.print_string ";; call ";
FStar.IO.print_string (mk_witness_call name l args);
print_witness witness
let count_args (l: list arg_type) : Tot nat = List.Tot.length (List.Tot.filter (function ArgPointer -> false | _ -> true) l)
let rec want_witnesses (print_test_case: (Seq.seq int -> list string -> ML unit)) (z3: Z3.z3) (name: string) (l: list arg_type) (nargs: nat { nargs == count_args l }) (mk_want_another_witness: Seq.seq int -> list string -> Tot string) i : ML unit =
z3.to_z3 "(check-sat)\n";
let status = z3.from_z3 () in
if status = "sat" then begin
let witness = read_witness z3 in
let witness_args = read_witness_args z3 [] nargs in
print_witness_and_call name l witness witness_args;
print_test_case witness witness_args;
if i <= 1
then ()
else begin
z3.to_z3 (mk_want_another_witness witness witness_args);
want_witnesses print_test_case z3 name l nargs mk_want_another_witness (i - 1)
end
end
else begin
FStar.IO.print_string
begin
if status = "unsat"
then";; unsat: no more witnesses"
else if status = "unknown"
then begin
z3.to_z3 "(get-info :reason-unknown)";
let msg = z3.from_z3 () in
Printf.sprintf ";; unknown: %s" msg
end
else Printf.sprintf ";; %s: z3 gave up" status
end;
FStar.IO.print_newline ()
end
let witnesses_for (print_test_case: (Seq.seq int -> list string -> ML unit)) (z3: Z3.z3) (name: string) (l: list arg_type) (nargs: nat { nargs == count_args l }) mk_get_first_witness mk_want_another_witness nbwitnesses =
z3.to_z3 "(push)\n";
z3.to_z3 mk_get_first_witness;
want_witnesses print_test_case z3 name l nargs mk_want_another_witness nbwitnesses;
z3.to_z3 "(pop)\n"
let rec mk_call_args (accu: string) (i: nat) (l: list arg_type) : Tot string (decreases l) =
match l with
| [] -> accu
| ArgPointer :: q -> mk_call_args (Printf.sprintf "%s 0" accu) i q
| _ :: q -> mk_call_args (Printf.sprintf "%s arg-%d" accu i) (i + 1) q
let rec mk_assert_args (accu: string) (i: nat) (l: list arg_type) : Tot string (decreases l) =
match l with
| [] -> accu
| ArgPointer :: q -> mk_assert_args accu i q
| ArgBool :: q -> mk_assert_args (Printf.sprintf "%s(declare-fun arg-%d () Bool)\n" accu i) (i + 1) q
| ArgInt it :: q -> mk_assert_args (Printf.sprintf "%s(declare-fun arg-%d () Int)\n(assert (and (<= 0 arg-%d) (< arg-%d %d)))\n" accu i i i (pow2 (integer_type_bit_size it))) (i + 1) q
let mk_get_witness (name: string) (l: list arg_type) : string =
Printf.sprintf "
%s
(define-fun state-witness () State (%s initial-state))
(define-fun state-witness-input-size () Int (input-size state-witness))
(declare-fun state-witness-size () Int)
(assert (<= state-witness-size (choice-index state-witness)))
(assert (>= state-witness-size (choice-index state-witness)))
"
(mk_assert_args "" 0 l)
(mk_call_args name 0 l)
let mk_get_first_positive_test_witness (name: string) (l: list arg_type) : string =
mk_get_witness name l ^ "
(assert (>= state-witness-input-size 0))
"
let rec mk_choose_conj (witness: Seq.seq int) (accu: string) (i: nat) : Tot string
(decreases (if i >= Seq.length witness then 0 else Seq.length witness - i))
= if i >= Seq.length witness
then accu
else mk_choose_conj witness ("(and (= (choose "^string_of_int i^") "^string_of_int (Seq.index witness i)^") "^accu^")") (i + 1) | false | true | Z3TestGen.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val mk_arg_conj (accu: string) (i: nat) (l: list string) : Tot string (decreases l) | [
"recursion"
] | Z3TestGen.mk_arg_conj | {
"file_name": "src/3d/Z3TestGen.fst",
"git_rev": "446a08ce38df905547cf20f28c43776b22b8087a",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | accu: Prims.string -> i: Prims.nat -> l: Prims.list Prims.string -> Prims.Tot Prims.string | {
"end_col": 78,
"end_line": 1083,
"start_col": 2,
"start_line": 1080
} |
FStar.All.ALL | [
{
"abbrev": true,
"full_module": "InterpreterTarget",
"short_module": "I"
},
{
"abbrev": true,
"full_module": "Target",
"short_module": "T"
},
{
"abbrev": true,
"full_module": "Ast",
"short_module": "A"
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.All",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.Printf",
"short_module": "Printf"
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let do_diff_test (out_file: option string) (z3: Z3.z3) (prog: prog) name1 name2 nbwitnesses =
let args = List.assoc name1 prog in
if None? args
then failwith (Printf.sprintf "do_diff_test: parser %s not found" name1);
let args = Some?.v args in
let args2 = List.assoc name2 prog in
if None? args2
then failwith (Printf.sprintf "do_diff_test: parser %s not found" name2);
if args2 <> Some args
then failwith (Printf.sprintf "do_diff_test: parsers %s and %s do not have the same arg types" name1 name2);
let nargs = count_args args in
let modul1, wrapper_name1 = module_and_wrapper_name name1 in
let modul2, wrapper_name2 = module_and_wrapper_name name2 in
with_option_out_file out_file (fun cout ->
cout "#include <stdio.h>
#include \"";
cout modul1;
cout "Wrapper.h\"
#include \"";
cout modul2;
cout "Wrapper.h\"
int main(void) {
";
do_diff_test_for cout z3 prog name1 name2 args nargs wrapper_name1 wrapper_name2 nbwitnesses;
do_diff_test_for cout z3 prog name2 name1 args nargs wrapper_name2 wrapper_name1 nbwitnesses;
cout " return 0;
}
"
) | let do_diff_test (out_file: option string) (z3: Z3.z3) (prog: prog) name1 name2 nbwitnesses = | true | null | false | let args = List.assoc name1 prog in
if None? args then failwith (Printf.sprintf "do_diff_test: parser %s not found" name1);
let args = Some?.v args in
let args2 = List.assoc name2 prog in
if None? args2 then failwith (Printf.sprintf "do_diff_test: parser %s not found" name2);
if args2 <> Some args
then
failwith (Printf.sprintf "do_diff_test: parsers %s and %s do not have the same arg types"
name1
name2);
let nargs = count_args args in
let modul1, wrapper_name1 = module_and_wrapper_name name1 in
let modul2, wrapper_name2 = module_and_wrapper_name name2 in
with_option_out_file out_file
(fun cout ->
cout "#include <stdio.h>\n#include \"";
cout modul1;
cout "Wrapper.h\"\n#include \"";
cout modul2;
cout "Wrapper.h\"\n int main(void) {\n";
do_diff_test_for cout z3 prog name1 name2 args nargs wrapper_name1 wrapper_name2 nbwitnesses;
do_diff_test_for cout z3 prog name2 name1 args nargs wrapper_name2 wrapper_name1 nbwitnesses;
cout " return 0;\n }\n") | {
"checked_file": "Z3TestGen.fst.checked",
"dependencies": [
"Z3.fsti.checked",
"Target.fsti.checked",
"prims.fst.checked",
"OS.fsti.checked",
"Lisp.fsti.checked",
"InterpreterTarget.fsti.checked",
"FStar.String.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Printf.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.List.Tot.fst.checked",
"FStar.List.fst.checked",
"FStar.IO.fst.checked",
"FStar.Char.fsti.checked",
"FStar.All.fst.checked",
"Ast.fst.checked"
],
"interface_file": false,
"source_file": "Z3TestGen.fst"
} | [] | [
"FStar.Pervasives.Native.option",
"Prims.string",
"Z3.Base.z3",
"Z3TestGen.prog",
"Prims.int",
"Z3TestGen.with_option_out_file",
"Prims.unit",
"Z3TestGen.do_diff_test_for",
"FStar.Pervasives.Native.tuple2",
"Z3TestGen.module_and_wrapper_name",
"Prims.nat",
"Z3TestGen.count_args",
"Prims.op_disEquality",
"Prims.list",
"Z3TestGen.arg_type",
"FStar.Pervasives.Native.Some",
"FStar.All.failwith",
"FStar.Printf.sprintf",
"Prims.bool",
"FStar.Pervasives.Native.uu___is_None",
"FStar.List.Tot.Base.assoc",
"FStar.Pervasives.Native.__proj__Some__item__v"
] | [] | module Z3TestGen
module Printf = FStar.Printf
open FStar.All
open FStar.Mul
module A = Ast
module T = Target
module I = InterpreterTarget
let prelude : string =
"
(set-option :produce-models true)
(declare-datatypes () ((State (mk-state (input-size Int) (choice-index Int)))))
(declare-datatypes () ((Result (mk-result (return-value Int) (after-state State)))))
(define-fun parse-empty ((x State)) Result
(mk-result 0 x)
)
(declare-fun choose (Int) Int)
(assert (forall ((i Int))
(and (<= 0 (choose i)) (< (choose i) 256))
))
(define-fun parse-false ((x State)) State
(mk-state -1 (choice-index x))
)
(define-fun parse-all-bytes ((x State)) State
(if (<= (input-size x) 0)
x
(mk-state 0 (+ (choice-index x) (input-size x)))
)
)
(define-fun parse-all-zeros ((x State)) State
(if (<= (input-size x) 0)
x
(mk-state
(if
(forall ((j Int))
(if (and (<= 0 j) (< j (input-size x)))
(= (choose (+ (choice-index x) j)) 0)
true
)
)
0
-1
)
(+ (choice-index x) (input-size x))
)
)
)
(define-fun parse-u8 ((x State)) Result
(mk-result
(choose (choice-index x))
(mk-state (- (input-size x) 1) (+ (choice-index x) 1))
)
)
(define-fun parse-u16-be ((x State)) Result
(mk-result
(+ (choose (+ 1 (choice-index x)))
(* 256
(choose (+ 0 (choice-index x)))
)
)
(mk-state (- (input-size x) 2) (+ (choice-index x) 2))
)
)
(define-fun parse-u16-le ((x State)) Result
(mk-result
(+ (choose (+ 0 (choice-index x)))
(* 256
(choose (+ 1 (choice-index x)))
)
)
(mk-state (- (input-size x) 2) (+ (choice-index x) 2))
)
)
(define-fun parse-u32-be ((x State)) Result
(mk-result
(+ (choose (+ 3 (choice-index x)))
(* 256
(+ (choose (+ 2 (choice-index x)))
(* 256
(+ (choose (+ 1 (choice-index x)))
(* 256
(choose (+ 0 (choice-index x)))
)
)
)
)
)
)
(mk-state (- (input-size x) 4) (+ (choice-index x) 4))
)
)
(define-fun parse-u32-le ((x State)) Result
(mk-result
(+ (choose (+ 0 (choice-index x)))
(* 256
(+ (choose (+ 1 (choice-index x)))
(* 256
(+ (choose (+ 2 (choice-index x)))
(* 256
(choose (+ 3 (choice-index x)))
)
)
)
)
)
)
(mk-state (- (input-size x) 4) (+ (choice-index x) 4))
)
)
(define-fun parse-u64-be ((x State)) Result
(mk-result
(+ (choose (+ 7 (choice-index x)))
(* 256
(+ (choose (+ 6 (choice-index x)))
(* 256
(+ (choose (+ 5 (choice-index x)))
(* 256
(+ (choose (+ 4 (choice-index x)))
(* 256
(+ (choose (+ 3 (choice-index x)))
(* 256
(+ (choose (+ 2 (choice-index x)))
(* 256
(+ (choose (+ 1 (choice-index x)))
(* 256
(choose (+ 0 (choice-index x)))
)
)
)
)
)
)
)
)
)
)
)
)
)
)
(mk-state (- (input-size x) 8) (+ (choice-index x) 8))
)
)
(define-fun parse-u64-le ((x State)) Result
(mk-result
(+ (choose (+ 0 (choice-index x)))
(* 256
(+ (choose (+ 1 (choice-index x)))
(* 256
(+ (choose (+ 2 (choice-index x)))
(* 256
(+ (choose (+ 3 (choice-index x)))
(* 256
(+ (choose (+ 4 (choice-index x)))
(* 256
(+ (choose (+ 5 (choice-index x)))
(* 256
(+ (choose (+ 6 (choice-index x)))
(* 256
(choose (+ 7 (choice-index x)))
)
)
)
)
)
)
)
)
)
)
)
)
)
)
(mk-state (- (input-size x) 8) (+ (choice-index x) 8))
)
)
(define-fun-rec pow-2 ((amount Int)) Int
(if (<= amount 0)
1
(* 2 (pow-2 (- amount 1)))
)
)
;; see LowParse.BitFields.get_bitfield_eq
(define-fun get-bitfield-lsb ((nbBits Int) (value Int) (bitsFrom Int) (bitsTo Int)) Int
(mod (div value (pow-2 bitsFrom)) (pow-2 (- bitsTo bitsFrom)))
)
;; see EverParse3d.Prelude.StaticHeader
(define-fun get-bitfield-msb ((nbBits Int) (value Int) (bitsFrom Int) (bitsTo Int)) Int
(get-bitfield-lsb nbBits value (- nbBits bitsTo) (- nbBits bitsFrom))
)
(declare-const initial-input-size Int)
(assert (>= initial-input-size 0))
(define-fun initial-state () State (mk-state initial-input-size 0))
"
let mk_constant = function
| A.Unit -> "0"
| A.Int _ x -> string_of_int x
| A.XInt _ x -> string_of_int (OS.int_of_string x)
| A.Bool true -> "true"
| A.Bool false -> "false"
let mk_app fn = function
| None -> fn
| Some args -> Printf.sprintf "(%s %s)" fn args
let assert_some = function
| None -> failwith "assert_some"
| Some x -> x
let is_bitwise_op (x: T.op) : Tot (option A.integer_type) =
match x with
| T.BitwiseAnd a
| T.BitwiseXor a
| T.BitwiseOr a
| T.BitwiseNot a
| T.ShiftLeft a
| T.ShiftRight a
-> Some a
| _ -> None
let mk_bitwise_op (op: string) (bitvec_args: option string) : ML string =
mk_app "bv2int" (Some (mk_app op bitvec_args))
let integer_type_bit_size = function
| A.UInt8 -> 8
| A.UInt16 -> 16
| A.UInt32 -> 32
| A.UInt64 -> 64
let mk_bitwise_not (a: A.integer_type) (bitvec_arg: option string) : ML string =
match bitvec_arg with
| None -> failwith "ill-formed bitwise_not"
| Some arg -> "(bv2int (bvxor "^arg^" #b"^String.make (integer_type_bit_size a) '1'^"))"
let mk_op : T.op -> option string -> ML string = function
| T.Eq -> mk_app "="
| T.Neq -> (fun s -> mk_app "not" (Some (mk_app "=" s)))
| T.And -> mk_app "and"
| T.Or -> mk_app "or"
| T.Not -> mk_app "not"
| T.Plus _ -> mk_app "+"
| T.Minus _ -> mk_app "-"
| T.Mul _ -> mk_app "*"
| T.Division _ -> mk_app "div"
| T.Remainder _ -> mk_app "mod"
| T.BitwiseAnd _ -> mk_bitwise_op "bvand"
| T.BitwiseXor _ -> mk_bitwise_op "bvxor"
| T.BitwiseOr _ -> mk_bitwise_op "bvor"
| T.BitwiseNot a -> mk_bitwise_not a
| T.ShiftLeft _ -> mk_bitwise_op "bvshl"
| T.ShiftRight _ -> mk_bitwise_op "bvlshr"
| T.LT _ -> mk_app "<"
| T.GT _ -> mk_app ">"
| T.LE _ -> mk_app "<="
| T.GE _ -> mk_app ">="
| T.IfThenElse -> mk_app "if"
| T.BitFieldOf size order -> (fun arg -> Printf.sprintf "(get-bitfield-%ssb %d %s)" (match order with A.LSBFirst -> "l" | A.MSBFirst -> "m") size (assert_some arg))
| T.Cast _ _ -> assert_some (* casts allowed only if they are proven not to lose precision *)
| T.Ext s -> mk_app s
let ident_to_string = A.ident_to_string
let mk_bitwise_arg (t: A.integer_type) (arg: string) : Tot string =
mk_app ("(_ int2bv "^string_of_int (integer_type_bit_size t)^")") (Some arg)
let mk_maybe_bitwise_arg (t: option A.integer_type) (arg: string) : Tot string =
match t with
| None -> arg
| Some t -> mk_bitwise_arg t arg
let rec mk_expr (e: T.expr) : ML string = match fst e with
| T.Constant c -> mk_constant c
| T.Identifier i -> ident_to_string i
| T.App hd args -> mk_op hd (mk_args (is_bitwise_op hd) args)
| _ -> failwith "mk_expr: not supported"
and mk_args_aux (is_bitwise_op: option A.integer_type) accu : (list T.expr -> ML string) = function
| [] -> accu
| a :: q -> mk_args_aux is_bitwise_op (Printf.sprintf "%s %s" accu (mk_maybe_bitwise_arg is_bitwise_op (mk_expr a))) q
and mk_args (is_bitwise_op: option A.integer_type) (l: list T.expr) : ML (option string) = match l with
| [] -> None
| a :: q -> Some (mk_args_aux is_bitwise_op (mk_maybe_bitwise_arg is_bitwise_op (mk_expr a)) q)
type reading = { call: string }
type not_reading = { call: string }
type binders = {
is_empty: bool;
bind: string;
args: string;
}
let empty_binders : binders = {
is_empty = true;
bind = "";
args = "";
}
let push_binder (name: string) (typ: string) (b: binders) : binders = {
is_empty = false;
bind = Printf.sprintf "(%s %s) %s" name typ b.bind;
args = Printf.sprintf " %s%s" name b.args;
}
let mk_function_call (name: string) (b: binders) =
Printf.sprintf "%s%s" name b.args
type parser (a: Type) =
(* name *) string ->
(* binders *) binders ->
(* is_toplevel *) bool ->
(* out *) (string -> ML unit) ->
ML a
let unsupported_parser (s: string) (a: Type) : Tot (parser a) =
fun _ _ _ _ -> failwith (Printf.sprintf "unsupported parser: %s" s)
let leaf_reading_parser (name: string) : parser reading =
fun _ _ _ _ -> { call = name }
let readable_itype_parser_suffix (i: I.itype) : Tot string = match i with
| I.UInt8 | I.UInt8BE -> "u8"
| I.UInt16 -> "u16-le"
| I.UInt16BE -> "u16-be"
| I.UInt32 -> "u32-le"
| I.UInt32BE -> "u32-be"
| I.UInt64 -> "u64-le"
| I.UInt64BE -> "u64-be"
| I.Unit -> "empty"
| I.AllBytes -> "all-bytes"
| I.AllZeros -> "all-zeros"
let parse_readable_itype (i: I.readable_itype) : Tot (parser reading) =
leaf_reading_parser ("parse-" ^ readable_itype_parser_suffix i)
let mk_wrap_parser
(name: string)
(binders: string)
(body: string)
: string
= let input = Printf.sprintf "%s-input" name in
let tmp = Printf.sprintf "%s-tmp" name in
"(define-fun "^name^" ("^binders^"("^input^" State)) State
(after-state ("^body^" "^input^"))
)
"
let wrap_parser (p: parser reading) : parser not_reading =
fun name binders _ out ->
let name' = Printf.sprintf "%s-wrapped" name in
let body = p name' binders false out in
out (mk_wrap_parser name binders.bind body.call);
{ call = mk_function_call name binders }
let mk_toplevel_parser
(name: string)
(binders: string)
(body: string)
: string
= let input = Printf.sprintf "%s-input" name in
"(define-fun "^name^" ("^binders^"("^input^" State)) State
("^body^" "^input^")
)
"
let maybe_toplevel_parser (p: parser not_reading) : parser not_reading =
fun name binders is_toplevel out ->
if is_toplevel
then begin
let name' = Printf.sprintf "%s-body" name in
let body = p name' binders false out in
out (mk_toplevel_parser name binders.bind body.call);
{ call = mk_function_call name binders }
end
else p name binders false out
let parse_all_bytes : parser not_reading =
maybe_toplevel_parser (fun _ _ _ _ -> { call = "parse-all-bytes" })
let parse_all_zeros : parser not_reading =
maybe_toplevel_parser (fun _ _ _ _ -> { call = "parse-all-zeros" })
let parse_itype : I.itype -> parser not_reading = function
| I.AllBytes -> parse_all_bytes
| I.AllZeros -> parse_all_zeros
| i -> wrap_parser (parse_readable_itype i)
let mk_app_without_paren id args =
mk_args_aux None (ident_to_string id) args
let parse_readable_app
(hd: A.ident)
(args: list I.expr)
: Tot (parser reading)
= fun _ _ _ _ -> { call = mk_app_without_paren hd args }
let parse_readable_dtyp
(d: I.readable_dtyp)
: Tot (parser reading)
= match d with
| I.DT_IType i -> parse_readable_itype i
| I.DT_App _ hd args -> parse_readable_app hd args
let parse_not_readable_app
(hd: A.ident)
(args: list I.expr)
: Tot (parser not_reading)
= maybe_toplevel_parser (fun _ _ _ _ -> { call = mk_app_without_paren hd args })
let parse_dtyp
(d: I.dtyp)
: Tot (parser not_reading)
= if I.allow_reader_of_dtyp d
then wrap_parser (parse_readable_dtyp d)
else match d with
| I.DT_IType i -> parse_itype i
| I.DT_App _ hd args -> parse_not_readable_app hd args
let parse_false : parser not_reading =
maybe_toplevel_parser (fun _ _ _ _ -> { call = "parse-false" })
let parse_denoted (d: I.dtyp) : parser not_reading =
parse_dtyp d
let mk_parse_pair
(name: string)
(binders: string)
(fst: string)
(snd: string)
: string
= let input = Printf.sprintf "%s-input" name in
let tmp = Printf.sprintf "%s-tmp" name in
"(define-fun "^name^" ("^binders^"("^input^" State)) State
(let (("^tmp^" ("^fst^" "^input^")))
(if (< (input-size "^tmp^") 0)
"^tmp^"
("^snd^" "^tmp^")
)
)
)
"
let parse_pair (fst: parser not_reading) (snd: parser not_reading) : parser not_reading =
fun name binders _ out ->
let name_fst = Printf.sprintf "%s-fst" name in
let body_fst = fst name_fst binders false out in
let name_snd = Printf.sprintf "%s-snd" name in
let body_snd = snd name_snd binders false out in
out (mk_parse_pair name binders.bind body_fst.call body_snd.call);
{ call = mk_function_call name binders }
let parse_square (p: parser not_reading) : parser not_reading =
fun name binders _ out ->
let body_name = Printf.sprintf "%s-snd" name in
let body = p body_name binders false out in
out (mk_parse_pair name binders.bind body.call body.call);
{ call = mk_function_call name binders }
let mk_parse_dep_pair_with_refinement
(name: string)
(binders: string)
(dfst: string)
(cond_binder_name: string)
(cond: string)
(dsnd_binder_name: string)
(dsnd: string) (* already contains the new argument *)
: string
= let input = Printf.sprintf "%s-input" name in
let tmp = Printf.sprintf "%s-tmp" name in
"(define-fun "^name^" ("^binders^"("^input^" State)) State
(let (("^tmp^" ("^dfst^" "^input^")))
(if (< (input-size (after-state "^tmp^")) 0)
(after-state "^tmp^")
(if (let (("^cond_binder_name^" (return-value "^tmp^"))) "^cond^")
(let (("^dsnd_binder_name^" (return-value "^tmp^")))
("^dsnd^" (after-state "^tmp^"))
)
(mk-state -1 (choice-index (after-state "^tmp^")))
)
)
)
)
"
let parse_dep_pair_with_refinement_gen (tag: parser reading) (cond_binder: string) (cond: unit -> ML string) (payload_binder: string) (payload: parser not_reading) : parser not_reading =
fun name binders _ out ->
let name_tag = Printf.sprintf "%s-tag" name in
let body_tag = tag name_tag binders false out in
let binders' = push_binder payload_binder "Int" binders in (* TODO: support more types *)
let name_payload = Printf.sprintf "%s-payload" name in
let body_payload = payload name_payload binders' false out in
out (mk_parse_dep_pair_with_refinement name binders.bind body_tag.call cond_binder (cond ()) payload_binder body_payload.call);
{ call = mk_function_call name binders }
let parse_dep_pair_with_refinement (tag: parser reading) (cond_binder: A.ident) (cond: unit -> ML string) (payload_binder: A.ident) (payload: parser not_reading) : parser not_reading =
parse_dep_pair_with_refinement_gen tag (ident_to_string cond_binder) cond (ident_to_string payload_binder) payload
let parse_dep_pair (tag: parser reading) (new_binder: A.ident) (payload: parser not_reading) : parser not_reading =
parse_dep_pair_with_refinement tag new_binder (fun _ -> "true") new_binder payload
let parse_refine (tag: parser reading) (cond_binder: A.ident) (cond: unit -> ML string) : parser not_reading =
parse_dep_pair_with_refinement tag cond_binder cond cond_binder (parse_itype I.Unit)
let mk_parse_ifthenelse
(name: string)
(binders: string)
(cond: string)
(f_then: string)
(f_else: string)
: string
= let input = Printf.sprintf "%s-input" name in
"(define-fun "^name^" ("^binders^"("^input^" State)) State
(if "^cond^"
("^f_then^" "^input^")
("^f_else^" "^input^")
)
)
"
let parse_ifthenelse (cond: unit -> ML string) (pthen: parser not_reading) (pelse: parser not_reading) : parser not_reading =
fun name binders _ out ->
let name_then = Printf.sprintf "%s-then" name in
let body_then = pthen name_then binders false out in
let name_else = Printf.sprintf "%s-else" name in
let body_else = pelse name_else binders false out in
out (mk_parse_ifthenelse name binders.bind (cond ()) body_then.call body_else.call);
{ call = mk_function_call name binders }
let mk_parse_exact
(name: string)
(binders: string)
(body: string)
(size: string)
: string
= let input = Printf.sprintf "%s-input" name in
let sz = Printf.sprintf "%s-size" name in
let res = Printf.sprintf "%s-res" name in
"(define-fun "^name^" ("^binders^"("^input^" State)) State
(let (("^sz^" "^size^"))
(if (< (input-size "^input^") "^sz^")
(mk-state -1 (choice-index "^input^"))
(let (("^res^" ("^body^" (mk-state "^sz^" (choice-index "^input^")))))
(mk-state
(if (= (input-size "^res^") 0)
(- (input-size "^input^") "^sz^")
-1
)
(choice-index "^res^")
)
)
)
)
)
"
let parse_exact
(size: unit -> ML string)
(body: parser not_reading)
: Tot (parser not_reading)
= fun name binders _ out ->
let body_name = Printf.sprintf "%s-body" name in
let body = body body_name binders false out in
out (mk_parse_exact name binders.bind body.call (size ()));
{ call = mk_function_call name binders }
let parse_at_most
(size: unit -> ML string)
(body: parser not_reading)
: Tot (parser not_reading)
= parse_exact size (parse_pair body parse_all_bytes)
(*
let mk_parse_list_one
(name: string)
(binders: string)
(p: string)
: string
= let input = Printf.sprintf "%s-input" name in
let res = Printf.sprintf "%s-res" name in
"(define-fun "^name^" ("^binders^"("^input^" (Seq Int))) (Seq Int)
(if (= (seq.len "^input^") 0)
(seq.unit 0)
(let (("^res^" ("^p^" "^input^")))
(if (= (seq.len "^res^") 0)
(as seq.empty (Seq Int))
(if (= (seq.nth "^res^" 0) 0)
(as seq.empty (Seq Int))
"^res^"
)
)
)
)
)
"
let parse_list_one
(body: parser not_reading)
: Tot (parser not_reading)
= fun name binders _ out ->
let body_name = Printf.sprintf "%s-body" name in
let body = body body_name binders false out in
out (mk_parse_list_one name binders.bind body.call);
{ call = mk_function_call name binders }
let rec parse_list_bounded'
(body: parser not_reading)
(logn: nat)
: Tot (parser not_reading)
(decreases logn)
= if logn = 0
then parse_list_one body
else
let logn' = logn - 1 in
parse_square (parse_list_bounded' body logn')
let parse_list_bounded body = parse_list_bounded' body 3 // 64
*)
let mk_parse_list
(name: string)
(rec_call: string)
(binders: string)
(body: string)
: string
= let input = Printf.sprintf "%s-input" name in
"(define-fun-rec "^name^" ("^binders^"("^input^" State)) State
(if (<= (input-size "^input^") 0)
"^input^"
("^rec_call^" ("^body^" "^input^"))
)
)
"
let parse_list
(body: parser not_reading)
: Tot (parser not_reading)
= fun name binders _ out ->
let rec_call = mk_function_call name binders in
let body_name = Printf.sprintf "%s-body" name in
let body = body body_name binders false out in
out (mk_parse_list name rec_call binders.bind body.call);
{ call = rec_call }
let parse_nlist
(size: unit -> ML string)
(body: parser not_reading)
: Tot (parser not_reading)
= parse_exact size (parse_list body)
let mk_parse_string
(name: string)
(rec_call: string)
(binders: string)
(body: string)
(terminator: string)
: string
= let input = Printf.sprintf "%s-input" name in
let tmp = Printf.sprintf "%s-tmp" name in
"(define-fun-rec "^name^" ("^binders^"("^input^" State)) State
(let (("^tmp^" ("^body^" "^input^")))
(if (< (choice-index (after-state "^tmp^")) 0)
(mk-state -1 (choice-index (after-state "^tmp^")))
(if (= (return-value "^tmp^") "^terminator^")
(after-state "^tmp^")
("^rec_call^" (after-state "^tmp^"))
)
)
)
)
"
let parse_string
(body: parser reading)
(terminator: (unit -> ML string))
: Tot (parser not_reading)
= fun name binders _ out ->
let rec_call = mk_function_call name binders in
let body_name = Printf.sprintf "%s-body" name in
let body = body body_name binders false out in
out (mk_parse_string name rec_call binders.bind body.call (terminator ()));
{ call = rec_call }
let rec type_has_actions = function
| I.T_with_dep_action _ _ _
| I.T_dep_pair_with_action _ _ _ _
| I.T_refine_with_action _ _ _ _
| I.T_dep_pair_with_refinement_and_action _ _ _ _ _
| I.T_with_action _ _ _
-> true
| I.T_false _
| I.T_denoted _ _
| I.T_refine _ _ _
| I.T_string _ _ _
-> false
| I.T_if_else _ t1 t2
| I.T_pair _ t1 t2 ->
type_has_actions t1 || type_has_actions t2
| I.T_at_most _ _ t
| I.T_exact _ _ t
| I.T_nlist _ _ t
| I.T_with_comment _ t _
| I.T_dep_pair_with_refinement _ _ _ (_, t)
| I.T_dep_pair _ _ (_, t) ->
type_has_actions t
let rec parse_typ (t : I.typ) : Pure (parser not_reading)
(requires (type_has_actions t == false))
(ensures (fun _ -> True))
= match t with
| I.T_false _ -> parse_false
| I.T_denoted _ d -> parse_denoted d
| I.T_pair _ t1 t2 -> parse_pair (parse_typ t1) (parse_typ t2)
| I.T_dep_pair _ t1 (lam, t2) -> parse_dep_pair (parse_readable_dtyp t1) lam (parse_typ t2)
| I.T_refine _ base (lam, cond) -> parse_refine (parse_readable_dtyp base) lam (fun _ -> mk_expr cond)
| I.T_dep_pair_with_refinement _ base (lam_cond, cond) (lam_k, k) -> parse_dep_pair_with_refinement (parse_readable_dtyp base) lam_cond (fun _ -> mk_expr cond) lam_k (parse_typ k)
| I.T_if_else cond t1 t2 -> parse_ifthenelse (fun _ -> mk_expr cond) (parse_typ t1) (parse_typ t2)
| I.T_with_comment _ base _ -> parse_typ base
| I.T_at_most _ size body -> parse_at_most (fun _ -> mk_expr size) (parse_typ body)
| I.T_exact _ size body -> parse_exact (fun _ -> mk_expr size) (parse_typ body)
| I.T_string _ elt terminator -> parse_string (parse_readable_dtyp elt) (fun _ -> mk_expr terminator)
| I.T_nlist _ size body -> parse_nlist (fun _ -> mk_expr size) (parse_typ body)
type arg_type =
| ArgInt of A.integer_type
| ArgBool
| ArgPointer
let arg_type_of_typ (t: T.typ) : Tot (option arg_type) =
match t with
| T.T_pointer _
| T.T_app _ A.KindOutput _
| T.T_app _ A.KindExtern _
| T.T_app {v = {modul_name = None; name = "PUINT8"}} _ _
-> Some ArgPointer
| T.T_app {v = {modul_name = None; name = "Bool"}} _ _
-> Some ArgBool
| T.T_app i _ _
->
begin match A.maybe_as_integer_typ i with
| Some t -> Some (ArgInt t)
| None -> None
end
| _ -> None
let smt_type_of_typ (t: T.typ) : Tot string =
match arg_type_of_typ t with
| Some ArgBool -> "Bool"
| _ -> "Int"
let rec binders_of_params = function
| [] -> empty_binders
| (id, t) :: q -> push_binder (ident_to_string id) (smt_type_of_typ t) (binders_of_params q)
let mk_definition
(name: string)
(binders: string)
(typ: string)
(body: string)
: Tot string
= "(define-fun "^name^" ("^binders^") "^typ^" "^body^")"
let produce_definition
(i: A.ident)
(param: list T.param)
(typ: T.typ)
(body: T.expr)
(out: string -> ML unit)
: ML unit
= let binders = binders_of_params param in
out (mk_definition (ident_to_string i) binders.bind (smt_type_of_typ typ) (mk_expr body))
let produce_not_type_decl (a: I.not_type_decl) (out: string -> ML unit) : ML unit =
match fst a with
| T.Definition (i, param, typ, body) ->
produce_definition i param typ body out
| T.Assumption _ -> failwith "produce_not_type_decl: unsupported"
| T.Output_type _
| T.Output_type_expr _ _
| T.Extern_type _
| T.Extern_fn _ _ _
-> ()
let prog = list (string & list arg_type)
let produce_type_decl (out: string -> ML unit) (accu: prog) (a: I.type_decl) : ML prog =
let binders = binders_of_params a.name.td_params in
let name = ident_to_string a.name.td_name in
if type_has_actions a.typ then failwith (Printf.sprintf "produce_type_decl: %s still has some actions" name);
let _ = parse_typ a.typ name binders true out in
(name, List.map (fun (i, ty) -> match arg_type_of_typ ty with Some t -> t | None -> failwith (Printf.sprintf "Parser %s has unsupported argument type for %s" name (ident_to_string i))) a.name.td_params) :: accu
let produce_decl (out: string -> ML unit) (accu: prog) (a: I.decl) : ML prog =
match a with
| Inl a -> produce_not_type_decl a out; accu
| Inr a -> produce_type_decl out accu a
let produce_decls (out: string -> ML unit) (accu: prog) (l: list I.decl) : ML prog =
List.fold_left (produce_decl out) accu l
(* Produce the SMT2 encoding of the parser spec *)
let with_out_file
(#a: Type)
(name: string)
(body: ((string -> ML unit) -> ML a))
: ML a
= let fd = FStar.IO.open_write_file name in
let res = body (FStar.IO.write_string fd) in
FStar.IO.close_write_file fd;
res
let with_option_out_file
(#a: Type)
(name: option string)
: Tot ((body: ((string -> ML unit) -> ML a)) -> ML a)
= match name with
| Some name -> with_out_file name
| None -> (fun body -> body (fun _ -> ()))
(* Ask Z3 for test witnesses *)
let read_witness (z3: Z3.z3) : ML (Seq.seq int) =
z3.to_z3 "(get-value (state-witness-size))\n";
let (_, witness_size) = Lisp.read_int_from z3.from_z3 "state-witness-size" in
let rec aux (accu: Seq.seq int) (remaining: int) : ML (Seq.seq int) =
if remaining <= 0
then accu
else
let index = remaining - 1 in
let _ = z3.to_z3 (Printf.sprintf "(eval (choose %d))\n" index) in
let v = Lisp.read_bare_int_from z3.from_z3 in
aux (Seq.cons v accu) index
in
aux Seq.empty witness_size
let rec read_witness_args (z3: Z3.z3) (accu: list string) (n: nat) : ML (list string) =
if n = 0
then accu
else begin
let n' = n - 1 in
z3.to_z3 (Printf.sprintf "(get-value (arg-%d))\n" n');
let arg = Lisp.read_any_from z3.from_z3 (Printf.sprintf "arg-%d" n') in
read_witness_args z3 (arg :: accu) n'
end
let module_and_wrapper_name
(s: string)
: ML (string & string)
= match String.split ['.'] s with
| [modul; fn] -> modul, Target.wrapper_name modul fn
| _ -> failwith "Z3TestGen.wrapper_name"
let rec print_witness_args_as_c
(out: (string -> ML unit))
(l: list arg_type) (args: list string)
: ML unit
= match l, args with
| ArgPointer :: q, _ ->
out "NULL, ";
print_witness_args_as_c out q args
| ty :: ql, a :: qargs ->
out a;
(if ArgInt? ty then out "U" else ());
out ", ";
print_witness_args_as_c out ql qargs
| _ -> ()
let print_witness_call_as_c_aux
(out: (string -> ML unit))
(wrapper_name: string)
(arg_types: list arg_type)
(witness_length: nat)
(args: list string)
: ML unit
=
out wrapper_name;
out "(";
print_witness_args_as_c out arg_types args;
out "witness, ";
out (string_of_int witness_length);
out ");"
let print_witness_call_as_c
(out: (string -> ML unit))
(positive: bool)
(wrapper_name: string)
(arg_types: list arg_type)
(witness_length: nat)
(args: list string)
: ML unit
=
out "
{
BOOLEAN result = ";
print_witness_call_as_c_aux out wrapper_name arg_types witness_length args;
out "
printf(\" ";
print_witness_call_as_c_aux out wrapper_name arg_types witness_length args;
out " // \");
if (result) printf (\"ACCEPTED\\n\\n\"); else printf (\"REJECTED\\n\\n\");
if (";
if positive then out "!";
out "result)
return 1;
};
"
let print_witness_as_c_aux
(out: (string -> ML unit))
(witness: Seq.seq int)
(len: int { len == Seq.length witness })
: ML unit
=
out " uint8_t witness[";
out (string_of_int len);
out "] = {";
begin match Seq.seq_to_list witness with
| [] -> ()
| a :: q ->
out (string_of_int a);
List.iter (fun i -> out ", "; out (string_of_int i)) q
end;
out "};"
let print_witness_as_c_gen
(out: (string -> ML unit))
(witness: Seq.seq int)
(f: (len: int { len == Seq.length witness }) -> ML unit)
: ML unit
= let len = Seq.length witness in
out "{\n";
print_witness_as_c_aux out witness len;
out "
printf(\"";
print_witness_as_c_aux out witness len;
out "\\n\");
";
f len;
out "};
"
let print_witness_as_c
(out: (string -> ML unit))
(positive: bool)
(wrapper_name: string)
(arg_types: list arg_type)
(witness: Seq.seq int)
(args: list string)
: ML unit
= print_witness_as_c_gen out witness (fun len ->
print_witness_call_as_c out positive wrapper_name arg_types len args
)
let print_diff_witness_as_c
(out: (string -> ML unit))
(wrapper_name1: string)
(wrapper_name2: string)
(arg_types: list arg_type)
(witness: Seq.seq int)
(args: list string)
: ML unit
= print_witness_as_c_gen out witness (fun len ->
print_witness_call_as_c out true wrapper_name1 arg_types len args;
print_witness_call_as_c out false wrapper_name2 arg_types len args
)
let print_witness (witness: Seq.seq int) : ML unit =
FStar.IO.print_string " produced witness: [";
List.iter (fun i -> FStar.IO.print_string (string_of_int i); FStar.IO.print_string "; ") (Seq.seq_to_list witness);
FStar.IO.print_string "]\n"
let rec mk_witness_call (accu: string) (l: list arg_type) (args: list string) : Tot string (decreases l) =
match l, args with
| ArgPointer :: q, _ -> mk_witness_call (Printf.sprintf "%s 0" accu) q args
| _ :: ql, a :: qargs -> mk_witness_call (Printf.sprintf "%s %s" accu a) ql qargs
| _ -> Printf.sprintf "(%s)" accu
let print_witness_and_call (name: string) (l: list arg_type) (witness: Seq.seq int) (args: list string) : ML unit =
FStar.IO.print_string ";; call ";
FStar.IO.print_string (mk_witness_call name l args);
print_witness witness
let count_args (l: list arg_type) : Tot nat = List.Tot.length (List.Tot.filter (function ArgPointer -> false | _ -> true) l)
let rec want_witnesses (print_test_case: (Seq.seq int -> list string -> ML unit)) (z3: Z3.z3) (name: string) (l: list arg_type) (nargs: nat { nargs == count_args l }) (mk_want_another_witness: Seq.seq int -> list string -> Tot string) i : ML unit =
z3.to_z3 "(check-sat)\n";
let status = z3.from_z3 () in
if status = "sat" then begin
let witness = read_witness z3 in
let witness_args = read_witness_args z3 [] nargs in
print_witness_and_call name l witness witness_args;
print_test_case witness witness_args;
if i <= 1
then ()
else begin
z3.to_z3 (mk_want_another_witness witness witness_args);
want_witnesses print_test_case z3 name l nargs mk_want_another_witness (i - 1)
end
end
else begin
FStar.IO.print_string
begin
if status = "unsat"
then";; unsat: no more witnesses"
else if status = "unknown"
then begin
z3.to_z3 "(get-info :reason-unknown)";
let msg = z3.from_z3 () in
Printf.sprintf ";; unknown: %s" msg
end
else Printf.sprintf ";; %s: z3 gave up" status
end;
FStar.IO.print_newline ()
end
let witnesses_for (print_test_case: (Seq.seq int -> list string -> ML unit)) (z3: Z3.z3) (name: string) (l: list arg_type) (nargs: nat { nargs == count_args l }) mk_get_first_witness mk_want_another_witness nbwitnesses =
z3.to_z3 "(push)\n";
z3.to_z3 mk_get_first_witness;
want_witnesses print_test_case z3 name l nargs mk_want_another_witness nbwitnesses;
z3.to_z3 "(pop)\n"
let rec mk_call_args (accu: string) (i: nat) (l: list arg_type) : Tot string (decreases l) =
match l with
| [] -> accu
| ArgPointer :: q -> mk_call_args (Printf.sprintf "%s 0" accu) i q
| _ :: q -> mk_call_args (Printf.sprintf "%s arg-%d" accu i) (i + 1) q
let rec mk_assert_args (accu: string) (i: nat) (l: list arg_type) : Tot string (decreases l) =
match l with
| [] -> accu
| ArgPointer :: q -> mk_assert_args accu i q
| ArgBool :: q -> mk_assert_args (Printf.sprintf "%s(declare-fun arg-%d () Bool)\n" accu i) (i + 1) q
| ArgInt it :: q -> mk_assert_args (Printf.sprintf "%s(declare-fun arg-%d () Int)\n(assert (and (<= 0 arg-%d) (< arg-%d %d)))\n" accu i i i (pow2 (integer_type_bit_size it))) (i + 1) q
let mk_get_witness (name: string) (l: list arg_type) : string =
Printf.sprintf "
%s
(define-fun state-witness () State (%s initial-state))
(define-fun state-witness-input-size () Int (input-size state-witness))
(declare-fun state-witness-size () Int)
(assert (<= state-witness-size (choice-index state-witness)))
(assert (>= state-witness-size (choice-index state-witness)))
"
(mk_assert_args "" 0 l)
(mk_call_args name 0 l)
let mk_get_first_positive_test_witness (name: string) (l: list arg_type) : string =
mk_get_witness name l ^ "
(assert (>= state-witness-input-size 0))
"
let rec mk_choose_conj (witness: Seq.seq int) (accu: string) (i: nat) : Tot string
(decreases (if i >= Seq.length witness then 0 else Seq.length witness - i))
= if i >= Seq.length witness
then accu
else mk_choose_conj witness ("(and (= (choose "^string_of_int i^") "^string_of_int (Seq.index witness i)^") "^accu^")") (i + 1)
let rec mk_arg_conj (accu: string) (i: nat) (l: list string) : Tot string (decreases l) =
match l with
| [] -> accu
| arg :: q ->
mk_arg_conj (Printf.sprintf "(and %s (= arg-%d %s))" accu i arg) (i + 1) q
let mk_want_another_distinct_witness witness witness_args : Tot string =
Printf.sprintf
"(assert (not %s))
"
(mk_arg_conj (mk_choose_conj witness ("(= (choice-index state-witness) "^string_of_int (Seq.length witness)^")") 0) 0 witness_args)
let mk_get_first_negative_test_witness (name: string) (l: list arg_type) : string =
mk_get_witness name l ^
"
(assert (< state-witness-input-size 0))
"
let do_test (out_file: option string) (z3: Z3.z3) (prog: prog) (name1: string) (nbwitnesses: int) (pos: bool) (neg: bool) : ML unit =
let args = List.assoc name1 prog in
if None? args
then failwith (Printf.sprintf "do_test: parser %s not found" name1);
let args = Some?.v args in
let modul, wrapper_name = module_and_wrapper_name name1 in
let nargs = count_args args in with_option_out_file out_file (fun cout ->
cout "#include <stdio.h>
#include \"";
cout modul;
cout "Wrapper.h\"
int main(void) {
";
if pos
then begin
FStar.IO.print_string (Printf.sprintf ";; Positive test witnesses for %s\n" name1);
witnesses_for (print_witness_as_c cout true wrapper_name args) z3 name1 args nargs (mk_get_first_positive_test_witness name1 args) mk_want_another_distinct_witness nbwitnesses
end;
if neg
then begin
FStar.IO.print_string (Printf.sprintf ";; Negative test witnesses for %s\n" name1);
witnesses_for (print_witness_as_c cout false wrapper_name args) z3 name1 args nargs (mk_get_first_negative_test_witness name1 args) mk_want_another_distinct_witness nbwitnesses
end;
cout " return 0;
}
"
)
let mk_get_first_diff_test_witness (name1: string) (l: list arg_type) (name2: string) : string =
Printf.sprintf
"
%s
(assert (< (input-size (%s initial-state)) 0))
"
(mk_get_first_positive_test_witness name1 l)
(mk_call_args name2 0 l)
let do_diff_test_for (cout: string -> ML unit) (z3: Z3.z3) (prog: prog) name1 name2 args (nargs: nat { nargs == count_args args }) wrapper_name1 wrapper_name2 nbwitnesses =
FStar.IO.print_string (Printf.sprintf ";; Witnesses that work with %s but not with %s\n" name1 name2);
witnesses_for (print_diff_witness_as_c cout wrapper_name1 wrapper_name2 args) z3 name1 args nargs (mk_get_first_diff_test_witness name1 args name2) mk_want_another_distinct_witness nbwitnesses | false | false | Z3TestGen.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val do_diff_test : out_file: FStar.Pervasives.Native.option Prims.string ->
z3: Z3.Base.z3 ->
prog: Z3TestGen.prog ->
name1: Prims.string ->
name2: Prims.string ->
nbwitnesses: Prims.int
-> FStar.All.ALL Prims.unit | [] | Z3TestGen.do_diff_test | {
"file_name": "src/3d/Z3TestGen.fst",
"git_rev": "446a08ce38df905547cf20f28c43776b22b8087a",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} |
out_file: FStar.Pervasives.Native.option Prims.string ->
z3: Z3.Base.z3 ->
prog: Z3TestGen.prog ->
name1: Prims.string ->
name2: Prims.string ->
nbwitnesses: Prims.int
-> FStar.All.ALL Prims.unit | {
"end_col": 1,
"end_line": 1166,
"start_col": 93,
"start_line": 1138
} |
|
Prims.Tot | val heap_taint (hi:heap_impl) : memTaint_t | [
{
"abbrev": true,
"full_module": "Vale.Lib.Map16",
"short_module": "Map16"
},
{
"abbrev": false,
"full_module": "Vale.Arch.HeapImpl",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Interop",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Interop.Heap_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.MachineHeap_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.HeapTypes_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let heap_taint hi = hi.vf_layout.vl_taint | val heap_taint (hi:heap_impl) : memTaint_t
let heap_taint hi = | false | null | false | hi.vf_layout.vl_taint | {
"checked_file": "Vale.Arch.Heap.fst.checked",
"dependencies": [
"Vale.Lib.Map16.fsti.checked",
"Vale.Interop.fsti.checked",
"Vale.Arch.HeapImpl.fst.checked",
"Vale.Arch.HeapImpl.fst.checked",
"prims.fst.checked",
"FStar.Set.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Map.fsti.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": true,
"source_file": "Vale.Arch.Heap.fst"
} | [
"total"
] | [
"Vale.Arch.Heap.heap_impl",
"Vale.Arch.HeapImpl.__proj__Mkvale_heap_layout__item__vl_taint",
"Vale.Arch.HeapImpl.__proj__Mkvale_full_heap__item__vf_layout",
"Vale.Arch.HeapTypes_s.memTaint_t"
] | [] | module Vale.Arch.Heap
open FStar.Mul
open Vale.Interop
open Vale.Arch.HeapImpl
module Map16 = Vale.Lib.Map16
friend Vale.Arch.HeapImpl
let heap_impl = vale_full_heap
let heap_get hi = hi.vf_heap.mh | false | true | Vale.Arch.Heap.fst | {
"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"
} | null | val heap_taint (hi:heap_impl) : memTaint_t | [] | Vale.Arch.Heap.heap_taint | {
"file_name": "vale/code/arch/Vale.Arch.Heap.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | hi: Vale.Arch.Heap.heap_impl -> Vale.Arch.HeapTypes_s.memTaint_t | {
"end_col": 41,
"end_line": 12,
"start_col": 20,
"start_line": 12
} |
Prims.GTot | val one_heaplet (ih: interop_heap) (id: option heaplet_id) : GTot vale_heap | [
{
"abbrev": true,
"full_module": "Vale.Lib.Map16",
"short_module": "Map16"
},
{
"abbrev": false,
"full_module": "Vale.Arch.HeapImpl",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Interop",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Interop.Heap_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.MachineHeap_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.HeapTypes_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let one_heaplet (ih:interop_heap) (id:option heaplet_id) : GTot vale_heap =
let m = down_mem ih in
let g = Ghost.hide ih in
ValeHeap m g id | val one_heaplet (ih: interop_heap) (id: option heaplet_id) : GTot vale_heap
let one_heaplet (ih: interop_heap) (id: option heaplet_id) : GTot vale_heap = | false | null | false | let m = down_mem ih in
let g = Ghost.hide ih in
ValeHeap m g id | {
"checked_file": "Vale.Arch.Heap.fst.checked",
"dependencies": [
"Vale.Lib.Map16.fsti.checked",
"Vale.Interop.fsti.checked",
"Vale.Arch.HeapImpl.fst.checked",
"Vale.Arch.HeapImpl.fst.checked",
"prims.fst.checked",
"FStar.Set.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Map.fsti.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": true,
"source_file": "Vale.Arch.Heap.fst"
} | [
"sometrivial"
] | [
"Vale.Interop.Heap_s.interop_heap",
"FStar.Pervasives.Native.option",
"Vale.Arch.HeapImpl.heaplet_id",
"Vale.Arch.HeapImpl.ValeHeap",
"FStar.Ghost.erased",
"FStar.Ghost.hide",
"Vale.Arch.MachineHeap_s.machine_heap",
"Vale.Interop.Heap_s.correct_down",
"Vale.Interop.down_mem",
"Vale.Arch.HeapImpl.vale_heap"
] | [] | module Vale.Arch.Heap
open FStar.Mul
open Vale.Interop
open Vale.Arch.HeapImpl
module Map16 = Vale.Lib.Map16
friend Vale.Arch.HeapImpl
let heap_impl = vale_full_heap
let heap_get hi = hi.vf_heap.mh
let heap_taint hi = hi.vf_layout.vl_taint
// Update heaplet k with mh', but only for the addresses that k owns (addresses not owned by k remain unmodified)
let heaplet_upd_f (vfh:vale_full_heap) (mh':machine_heap) (k:heaplet_id) : vale_heap =
let hk = Map16.sel vfh.vf_heaplets k in
let mhk = hk.mh in
let dom_upd = Set.intersect (vfh.vf_layout.vl_inner.vl_heaplet_sets k) (Map.domain mhk) in
let mhk' = Map.concat mhk (Map.restrict dom_upd mh') in
mi_heap_upd hk mhk'
let heap_upd hi mh' mt' =
let h' = mi_heap_upd hi.vf_heap mh' in
let hs' = Map16.init vale_heap (heaplet_upd_f hi mh') in
{
vf_layout = {hi.vf_layout with vl_taint = mt'};
vf_heap = h';
vf_heaplets = hs';
}
let heap_create_machine ih =
down_mem ih | false | false | Vale.Arch.Heap.fst | {
"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"
} | null | val one_heaplet (ih: interop_heap) (id: option heaplet_id) : GTot vale_heap | [] | Vale.Arch.Heap.one_heaplet | {
"file_name": "vale/code/arch/Vale.Arch.Heap.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} |
ih: Vale.Interop.Heap_s.interop_heap ->
id: FStar.Pervasives.Native.option Vale.Arch.HeapImpl.heaplet_id
-> Prims.GTot Vale.Arch.HeapImpl.vale_heap | {
"end_col": 17,
"end_line": 37,
"start_col": 75,
"start_line": 34
} |
Prims.Tot | val heap_impl : Type u#1 | [
{
"abbrev": true,
"full_module": "Vale.Lib.Map16",
"short_module": "Map16"
},
{
"abbrev": false,
"full_module": "Vale.Arch.HeapImpl",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Interop",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Interop.Heap_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.MachineHeap_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.HeapTypes_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let heap_impl = vale_full_heap | val heap_impl : Type u#1
let heap_impl = | false | null | false | vale_full_heap | {
"checked_file": "Vale.Arch.Heap.fst.checked",
"dependencies": [
"Vale.Lib.Map16.fsti.checked",
"Vale.Interop.fsti.checked",
"Vale.Arch.HeapImpl.fst.checked",
"Vale.Arch.HeapImpl.fst.checked",
"prims.fst.checked",
"FStar.Set.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Map.fsti.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": true,
"source_file": "Vale.Arch.Heap.fst"
} | [
"total"
] | [
"Vale.Arch.HeapImpl.vale_full_heap"
] | [] | module Vale.Arch.Heap
open FStar.Mul
open Vale.Interop
open Vale.Arch.HeapImpl
module Map16 = Vale.Lib.Map16
friend Vale.Arch.HeapImpl | false | true | Vale.Arch.Heap.fst | {
"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"
} | null | val heap_impl : Type u#1 | [] | Vale.Arch.Heap.heap_impl | {
"file_name": "vale/code/arch/Vale.Arch.Heap.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | Type | {
"end_col": 30,
"end_line": 8,
"start_col": 16,
"start_line": 8
} |
Prims.Tot | val heap_get (hi:heap_impl) : machine_heap | [
{
"abbrev": true,
"full_module": "Vale.Lib.Map16",
"short_module": "Map16"
},
{
"abbrev": false,
"full_module": "Vale.Arch.HeapImpl",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Interop",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Interop.Heap_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.MachineHeap_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.HeapTypes_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let heap_get hi = hi.vf_heap.mh | val heap_get (hi:heap_impl) : machine_heap
let heap_get hi = | false | null | false | hi.vf_heap.mh | {
"checked_file": "Vale.Arch.Heap.fst.checked",
"dependencies": [
"Vale.Lib.Map16.fsti.checked",
"Vale.Interop.fsti.checked",
"Vale.Arch.HeapImpl.fst.checked",
"Vale.Arch.HeapImpl.fst.checked",
"prims.fst.checked",
"FStar.Set.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Map.fsti.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": true,
"source_file": "Vale.Arch.Heap.fst"
} | [
"total"
] | [
"Vale.Arch.Heap.heap_impl",
"Vale.Arch.HeapImpl.__proj__ValeHeap__item__mh",
"Vale.Arch.HeapImpl.__proj__Mkvale_full_heap__item__vf_heap",
"Vale.Arch.MachineHeap_s.machine_heap"
] | [] | module Vale.Arch.Heap
open FStar.Mul
open Vale.Interop
open Vale.Arch.HeapImpl
module Map16 = Vale.Lib.Map16
friend Vale.Arch.HeapImpl
let heap_impl = vale_full_heap | false | true | Vale.Arch.Heap.fst | {
"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"
} | null | val heap_get (hi:heap_impl) : machine_heap | [] | Vale.Arch.Heap.heap_get | {
"file_name": "vale/code/arch/Vale.Arch.Heap.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | hi: Vale.Arch.Heap.heap_impl -> Vale.Arch.MachineHeap_s.machine_heap | {
"end_col": 31,
"end_line": 10,
"start_col": 18,
"start_line": 10
} |
Prims.Ghost | val heap_create_machine (ih:interop_heap) : Ghost machine_heap
(requires True)
(ensures fun mh -> correct_down ih mh) | [
{
"abbrev": true,
"full_module": "Vale.Lib.Map16",
"short_module": "Map16"
},
{
"abbrev": false,
"full_module": "Vale.Arch.HeapImpl",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Interop",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Interop.Heap_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.MachineHeap_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.HeapTypes_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let heap_create_machine ih =
down_mem ih | val heap_create_machine (ih:interop_heap) : Ghost machine_heap
(requires True)
(ensures fun mh -> correct_down ih mh)
let heap_create_machine ih = | false | null | false | down_mem ih | {
"checked_file": "Vale.Arch.Heap.fst.checked",
"dependencies": [
"Vale.Lib.Map16.fsti.checked",
"Vale.Interop.fsti.checked",
"Vale.Arch.HeapImpl.fst.checked",
"Vale.Arch.HeapImpl.fst.checked",
"prims.fst.checked",
"FStar.Set.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Map.fsti.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": true,
"source_file": "Vale.Arch.Heap.fst"
} | [] | [
"Vale.Interop.Heap_s.interop_heap",
"Vale.Interop.down_mem",
"Vale.Arch.MachineHeap_s.machine_heap"
] | [] | module Vale.Arch.Heap
open FStar.Mul
open Vale.Interop
open Vale.Arch.HeapImpl
module Map16 = Vale.Lib.Map16
friend Vale.Arch.HeapImpl
let heap_impl = vale_full_heap
let heap_get hi = hi.vf_heap.mh
let heap_taint hi = hi.vf_layout.vl_taint
// Update heaplet k with mh', but only for the addresses that k owns (addresses not owned by k remain unmodified)
let heaplet_upd_f (vfh:vale_full_heap) (mh':machine_heap) (k:heaplet_id) : vale_heap =
let hk = Map16.sel vfh.vf_heaplets k in
let mhk = hk.mh in
let dom_upd = Set.intersect (vfh.vf_layout.vl_inner.vl_heaplet_sets k) (Map.domain mhk) in
let mhk' = Map.concat mhk (Map.restrict dom_upd mh') in
mi_heap_upd hk mhk'
let heap_upd hi mh' mt' =
let h' = mi_heap_upd hi.vf_heap mh' in
let hs' = Map16.init vale_heap (heaplet_upd_f hi mh') in
{
vf_layout = {hi.vf_layout with vl_taint = mt'};
vf_heap = h';
vf_heaplets = hs';
} | false | false | Vale.Arch.Heap.fst | {
"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"
} | null | val heap_create_machine (ih:interop_heap) : Ghost machine_heap
(requires True)
(ensures fun mh -> correct_down ih mh) | [] | Vale.Arch.Heap.heap_create_machine | {
"file_name": "vale/code/arch/Vale.Arch.Heap.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | ih: Vale.Interop.Heap_s.interop_heap -> Prims.Ghost Vale.Arch.MachineHeap_s.machine_heap | {
"end_col": 13,
"end_line": 32,
"start_col": 2,
"start_line": 32
} |
Prims.Ghost | val heap_create_impl (ih:interop_heap) (mt:memTaint_t) : Ghost heap_impl
(requires True)
(ensures fun hi -> heap_get hi == heap_create_machine ih /\ heap_taint hi == mt) | [
{
"abbrev": true,
"full_module": "Vale.Lib.Map16",
"short_module": "Map16"
},
{
"abbrev": false,
"full_module": "Vale.Arch.HeapImpl",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Interop",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Interop.Heap_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.MachineHeap_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.HeapTypes_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let heap_create_impl ih mt =
let vh = one_heaplet ih None in
let layout = {vl_inner = empty_vale_heap_layout_inner vh; vl_taint = mt;} in
{
vf_layout = layout;
vf_heap = vh;
vf_heaplets = empty_vale_heaplets vh;
} | val heap_create_impl (ih:interop_heap) (mt:memTaint_t) : Ghost heap_impl
(requires True)
(ensures fun hi -> heap_get hi == heap_create_machine ih /\ heap_taint hi == mt)
let heap_create_impl ih mt = | false | null | false | let vh = one_heaplet ih None in
let layout = { vl_inner = empty_vale_heap_layout_inner vh; vl_taint = mt } in
{ vf_layout = layout; vf_heap = vh; vf_heaplets = empty_vale_heaplets vh } | {
"checked_file": "Vale.Arch.Heap.fst.checked",
"dependencies": [
"Vale.Lib.Map16.fsti.checked",
"Vale.Interop.fsti.checked",
"Vale.Arch.HeapImpl.fst.checked",
"Vale.Arch.HeapImpl.fst.checked",
"prims.fst.checked",
"FStar.Set.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Map.fsti.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": true,
"source_file": "Vale.Arch.Heap.fst"
} | [] | [
"Vale.Interop.Heap_s.interop_heap",
"Vale.Arch.HeapTypes_s.memTaint_t",
"Vale.Arch.HeapImpl.Mkvale_full_heap",
"Vale.Arch.HeapImpl.empty_vale_heaplets",
"Vale.Arch.HeapImpl.vale_heap_layout",
"Vale.Arch.HeapImpl.Mkvale_heap_layout",
"Vale.Arch.HeapImpl.empty_vale_heap_layout_inner",
"Vale.Arch.HeapImpl.vale_heap",
"Vale.Arch.Heap.one_heaplet",
"FStar.Pervasives.Native.None",
"Vale.Arch.HeapImpl.heaplet_id",
"Vale.Arch.Heap.heap_impl"
] | [] | module Vale.Arch.Heap
open FStar.Mul
open Vale.Interop
open Vale.Arch.HeapImpl
module Map16 = Vale.Lib.Map16
friend Vale.Arch.HeapImpl
let heap_impl = vale_full_heap
let heap_get hi = hi.vf_heap.mh
let heap_taint hi = hi.vf_layout.vl_taint
// Update heaplet k with mh', but only for the addresses that k owns (addresses not owned by k remain unmodified)
let heaplet_upd_f (vfh:vale_full_heap) (mh':machine_heap) (k:heaplet_id) : vale_heap =
let hk = Map16.sel vfh.vf_heaplets k in
let mhk = hk.mh in
let dom_upd = Set.intersect (vfh.vf_layout.vl_inner.vl_heaplet_sets k) (Map.domain mhk) in
let mhk' = Map.concat mhk (Map.restrict dom_upd mh') in
mi_heap_upd hk mhk'
let heap_upd hi mh' mt' =
let h' = mi_heap_upd hi.vf_heap mh' in
let hs' = Map16.init vale_heap (heaplet_upd_f hi mh') in
{
vf_layout = {hi.vf_layout with vl_taint = mt'};
vf_heap = h';
vf_heaplets = hs';
}
let heap_create_machine ih =
down_mem ih
let one_heaplet (ih:interop_heap) (id:option heaplet_id) : GTot vale_heap =
let m = down_mem ih in
let g = Ghost.hide ih in
ValeHeap m g id | false | false | Vale.Arch.Heap.fst | {
"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"
} | null | val heap_create_impl (ih:interop_heap) (mt:memTaint_t) : Ghost heap_impl
(requires True)
(ensures fun hi -> heap_get hi == heap_create_machine ih /\ heap_taint hi == mt) | [] | Vale.Arch.Heap.heap_create_impl | {
"file_name": "vale/code/arch/Vale.Arch.Heap.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | ih: Vale.Interop.Heap_s.interop_heap -> mt: Vale.Arch.HeapTypes_s.memTaint_t
-> Prims.Ghost Vale.Arch.Heap.heap_impl | {
"end_col": 3,
"end_line": 46,
"start_col": 28,
"start_line": 39
} |
Prims.Pure | val heap_upd (hi:heap_impl) (mh':machine_heap) (mt':memTaint_t) : Pure heap_impl
(requires is_machine_heap_update (heap_get hi) mh')
(ensures fun hi -> heap_get hi == mh' /\ heap_taint hi == mt') | [
{
"abbrev": true,
"full_module": "Vale.Lib.Map16",
"short_module": "Map16"
},
{
"abbrev": false,
"full_module": "Vale.Arch.HeapImpl",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Interop",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Interop.Heap_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.MachineHeap_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.HeapTypes_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let heap_upd hi mh' mt' =
let h' = mi_heap_upd hi.vf_heap mh' in
let hs' = Map16.init vale_heap (heaplet_upd_f hi mh') in
{
vf_layout = {hi.vf_layout with vl_taint = mt'};
vf_heap = h';
vf_heaplets = hs';
} | val heap_upd (hi:heap_impl) (mh':machine_heap) (mt':memTaint_t) : Pure heap_impl
(requires is_machine_heap_update (heap_get hi) mh')
(ensures fun hi -> heap_get hi == mh' /\ heap_taint hi == mt')
let heap_upd hi mh' mt' = | false | null | false | let h' = mi_heap_upd hi.vf_heap mh' in
let hs' = Map16.init vale_heap (heaplet_upd_f hi mh') in
{ vf_layout = { hi.vf_layout with vl_taint = mt' }; vf_heap = h'; vf_heaplets = hs' } | {
"checked_file": "Vale.Arch.Heap.fst.checked",
"dependencies": [
"Vale.Lib.Map16.fsti.checked",
"Vale.Interop.fsti.checked",
"Vale.Arch.HeapImpl.fst.checked",
"Vale.Arch.HeapImpl.fst.checked",
"prims.fst.checked",
"FStar.Set.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Map.fsti.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": true,
"source_file": "Vale.Arch.Heap.fst"
} | [] | [
"Vale.Arch.Heap.heap_impl",
"Vale.Arch.MachineHeap_s.machine_heap",
"Vale.Arch.HeapTypes_s.memTaint_t",
"Vale.Arch.HeapImpl.Mkvale_full_heap",
"Vale.Arch.HeapImpl.Mkvale_heap_layout",
"Vale.Arch.HeapImpl.__proj__Mkvale_heap_layout__item__vl_inner",
"Vale.Arch.HeapImpl.vale_heap_layout",
"Vale.Arch.HeapImpl.__proj__Mkvale_full_heap__item__vf_layout",
"Vale.Lib.Map16.map16",
"Vale.Arch.HeapImpl.vale_heap",
"Vale.Lib.Map16.init",
"Vale.Arch.Heap.heaplet_upd_f",
"Vale.Arch.HeapImpl.mi_heap_upd",
"Vale.Arch.HeapImpl.__proj__Mkvale_full_heap__item__vf_heap"
] | [] | module Vale.Arch.Heap
open FStar.Mul
open Vale.Interop
open Vale.Arch.HeapImpl
module Map16 = Vale.Lib.Map16
friend Vale.Arch.HeapImpl
let heap_impl = vale_full_heap
let heap_get hi = hi.vf_heap.mh
let heap_taint hi = hi.vf_layout.vl_taint
// Update heaplet k with mh', but only for the addresses that k owns (addresses not owned by k remain unmodified)
let heaplet_upd_f (vfh:vale_full_heap) (mh':machine_heap) (k:heaplet_id) : vale_heap =
let hk = Map16.sel vfh.vf_heaplets k in
let mhk = hk.mh in
let dom_upd = Set.intersect (vfh.vf_layout.vl_inner.vl_heaplet_sets k) (Map.domain mhk) in
let mhk' = Map.concat mhk (Map.restrict dom_upd mh') in
mi_heap_upd hk mhk' | false | false | Vale.Arch.Heap.fst | {
"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"
} | null | val heap_upd (hi:heap_impl) (mh':machine_heap) (mt':memTaint_t) : Pure heap_impl
(requires is_machine_heap_update (heap_get hi) mh')
(ensures fun hi -> heap_get hi == mh' /\ heap_taint hi == mt') | [] | Vale.Arch.Heap.heap_upd | {
"file_name": "vale/code/arch/Vale.Arch.Heap.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} |
hi: Vale.Arch.Heap.heap_impl ->
mh': Vale.Arch.MachineHeap_s.machine_heap ->
mt': Vale.Arch.HeapTypes_s.memTaint_t
-> Prims.Pure Vale.Arch.Heap.heap_impl | {
"end_col": 3,
"end_line": 29,
"start_col": 25,
"start_line": 22
} |
Prims.Tot | val heaplet_upd_f (vfh: vale_full_heap) (mh': machine_heap) (k: heaplet_id) : vale_heap | [
{
"abbrev": true,
"full_module": "Vale.Lib.Map16",
"short_module": "Map16"
},
{
"abbrev": false,
"full_module": "Vale.Arch.HeapImpl",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Interop",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Interop.Heap_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.MachineHeap_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.HeapTypes_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let heaplet_upd_f (vfh:vale_full_heap) (mh':machine_heap) (k:heaplet_id) : vale_heap =
let hk = Map16.sel vfh.vf_heaplets k in
let mhk = hk.mh in
let dom_upd = Set.intersect (vfh.vf_layout.vl_inner.vl_heaplet_sets k) (Map.domain mhk) in
let mhk' = Map.concat mhk (Map.restrict dom_upd mh') in
mi_heap_upd hk mhk' | val heaplet_upd_f (vfh: vale_full_heap) (mh': machine_heap) (k: heaplet_id) : vale_heap
let heaplet_upd_f (vfh: vale_full_heap) (mh': machine_heap) (k: heaplet_id) : vale_heap = | false | null | false | let hk = Map16.sel vfh.vf_heaplets k in
let mhk = hk.mh in
let dom_upd = Set.intersect (vfh.vf_layout.vl_inner.vl_heaplet_sets k) (Map.domain mhk) in
let mhk' = Map.concat mhk (Map.restrict dom_upd mh') in
mi_heap_upd hk mhk' | {
"checked_file": "Vale.Arch.Heap.fst.checked",
"dependencies": [
"Vale.Lib.Map16.fsti.checked",
"Vale.Interop.fsti.checked",
"Vale.Arch.HeapImpl.fst.checked",
"Vale.Arch.HeapImpl.fst.checked",
"prims.fst.checked",
"FStar.Set.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Map.fsti.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": true,
"source_file": "Vale.Arch.Heap.fst"
} | [
"total"
] | [
"Vale.Arch.HeapImpl.vale_full_heap",
"Vale.Arch.MachineHeap_s.machine_heap",
"Vale.Arch.HeapImpl.heaplet_id",
"Vale.Arch.HeapImpl.mi_heap_upd",
"FStar.Map.t",
"Prims.int",
"Vale.Def.Words_s.nat8",
"FStar.Map.concat",
"Vale.Def.Types_s.nat8",
"FStar.Map.restrict",
"FStar.Set.set",
"FStar.Set.intersect",
"Vale.Arch.HeapImpl.__proj__Mkvale_heap_layout_inner__item__vl_heaplet_sets",
"Vale.Arch.HeapImpl.__proj__Mkvale_heap_layout__item__vl_inner",
"Vale.Arch.HeapImpl.__proj__Mkvale_full_heap__item__vf_layout",
"FStar.Map.domain",
"Vale.Arch.HeapImpl.__proj__ValeHeap__item__mh",
"Vale.Arch.HeapImpl.vale_heap",
"Vale.Lib.Map16.sel",
"Vale.Arch.HeapImpl.__proj__Mkvale_full_heap__item__vf_heaplets"
] | [] | module Vale.Arch.Heap
open FStar.Mul
open Vale.Interop
open Vale.Arch.HeapImpl
module Map16 = Vale.Lib.Map16
friend Vale.Arch.HeapImpl
let heap_impl = vale_full_heap
let heap_get hi = hi.vf_heap.mh
let heap_taint hi = hi.vf_layout.vl_taint | false | true | Vale.Arch.Heap.fst | {
"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"
} | null | val heaplet_upd_f (vfh: vale_full_heap) (mh': machine_heap) (k: heaplet_id) : vale_heap | [] | Vale.Arch.Heap.heaplet_upd_f | {
"file_name": "vale/code/arch/Vale.Arch.Heap.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} |
vfh: Vale.Arch.HeapImpl.vale_full_heap ->
mh': Vale.Arch.MachineHeap_s.machine_heap ->
k: Vale.Arch.HeapImpl.heaplet_id
-> Vale.Arch.HeapImpl.vale_heap | {
"end_col": 21,
"end_line": 20,
"start_col": 86,
"start_line": 15
} |
Prims.Tot | val va_ens_Memcpy
(va_b0: va_code)
(va_s0: va_state)
(win: bool)
(dst src: buffer64)
(va_sM: va_state)
(va_fM: va_fuel)
: prop | [
{
"abbrev": false,
"full_module": "Vale.X64.QuickCodes",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.QuickCode",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.InsVector",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.InsMem",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.InsBasic",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Decls",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.State",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Memory",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.HeapImpl",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.QuickCodes",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.QuickCode",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.InsVector",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.InsMem",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.InsBasic",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Decls",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.State",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Memory",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.HeapImpl",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Test.X64",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Test.X64",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let va_ens_Memcpy (va_b0:va_code) (va_s0:va_state) (win:bool) (dst:buffer64) (src:buffer64)
(va_sM:va_state) (va_fM:va_fuel) : prop =
(va_req_Memcpy va_b0 va_s0 win dst src /\ va_ensure_total va_b0 va_s0 va_sM va_fM /\ va_get_ok
va_sM /\ Vale.X64.Memory.buffer_as_seq #Vale.X64.Memory.vuint64 (va_get_mem va_sM) dst ==
Vale.X64.Memory.buffer_as_seq #Vale.X64.Memory.vuint64 (va_get_mem va_sM) src /\
Vale.X64.Decls.modifies_mem (Vale.X64.Decls.loc_buffer #Vale.X64.Memory.vuint64 dst)
(va_get_mem va_s0) (va_get_mem va_sM) /\ va_state_eq va_sM (va_update_mem_heaplet 1 va_sM
(va_update_mem_layout va_sM (va_update_reg64 rR9 va_sM (va_update_reg64 rRcx va_sM
(va_update_reg64 rRax va_sM (va_update_ok va_sM (va_update_mem va_sM va_s0)))))))) | val va_ens_Memcpy
(va_b0: va_code)
(va_s0: va_state)
(win: bool)
(dst src: buffer64)
(va_sM: va_state)
(va_fM: va_fuel)
: prop
let va_ens_Memcpy
(va_b0: va_code)
(va_s0: va_state)
(win: bool)
(dst src: buffer64)
(va_sM: va_state)
(va_fM: va_fuel)
: prop = | false | null | false | (va_req_Memcpy va_b0 va_s0 win dst src /\ va_ensure_total va_b0 va_s0 va_sM va_fM /\ va_get_ok va_sM /\
Vale.X64.Memory.buffer_as_seq #Vale.X64.Memory.vuint64 (va_get_mem va_sM) dst ==
Vale.X64.Memory.buffer_as_seq #Vale.X64.Memory.vuint64 (va_get_mem va_sM) src /\
Vale.X64.Decls.modifies_mem (Vale.X64.Decls.loc_buffer #Vale.X64.Memory.vuint64 dst)
(va_get_mem va_s0)
(va_get_mem va_sM) /\
va_state_eq va_sM
(va_update_mem_heaplet 1
va_sM
(va_update_mem_layout va_sM
(va_update_reg64 rR9
va_sM
(va_update_reg64 rRcx
va_sM
(va_update_reg64 rRax va_sM (va_update_ok va_sM (va_update_mem va_sM va_s0))))))
)) | {
"checked_file": "Vale.Test.X64.Vale_memcpy.fsti.checked",
"dependencies": [
"Vale.X64.State.fsti.checked",
"Vale.X64.QuickCodes.fsti.checked",
"Vale.X64.QuickCode.fst.checked",
"Vale.X64.Memory.fsti.checked",
"Vale.X64.Machine_s.fst.checked",
"Vale.X64.InsVector.fsti.checked",
"Vale.X64.InsMem.fsti.checked",
"Vale.X64.InsBasic.fsti.checked",
"Vale.X64.Decls.fsti.checked",
"Vale.Arch.HeapImpl.fsti.checked",
"prims.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked"
],
"interface_file": false,
"source_file": "Vale.Test.X64.Vale_memcpy.fsti"
} | [
"total"
] | [
"Vale.X64.Decls.va_code",
"Vale.X64.Decls.va_state",
"Prims.bool",
"Vale.X64.Memory.buffer64",
"Vale.X64.Decls.va_fuel",
"Prims.l_and",
"Vale.Test.X64.Vale_memcpy.va_req_Memcpy",
"Vale.X64.Decls.va_ensure_total",
"Prims.b2t",
"Vale.X64.Decls.va_get_ok",
"Prims.eq2",
"FStar.Seq.Base.seq",
"Vale.X64.Memory.base_typ_as_vale_type",
"Vale.X64.Memory.vuint64",
"Vale.X64.Memory.buffer_as_seq",
"Vale.X64.Decls.va_get_mem",
"Vale.X64.Decls.modifies_mem",
"Vale.X64.Decls.loc_buffer",
"Vale.X64.Decls.va_state_eq",
"Vale.X64.Decls.va_update_mem_heaplet",
"Vale.X64.Decls.va_update_mem_layout",
"Vale.X64.Decls.va_update_reg64",
"Vale.X64.Machine_s.rR9",
"Vale.X64.Machine_s.rRcx",
"Vale.X64.Machine_s.rRax",
"Vale.X64.Decls.va_update_ok",
"Vale.X64.Decls.va_update_mem",
"Prims.prop"
] | [] | module Vale.Test.X64.Vale_memcpy
open Vale.Arch.HeapImpl
open Vale.X64.Machine_s
open Vale.X64.Memory
open Vale.X64.State
open Vale.X64.Decls
open Vale.X64.InsBasic
open Vale.X64.InsMem
open Vale.X64.InsVector
open Vale.X64.QuickCode
open Vale.X64.QuickCodes
#set-options "--z3rlimit 20"
//-- Memcpy
val va_code_Memcpy : win:bool -> Tot va_code
val va_codegen_success_Memcpy : win:bool -> Tot va_pbool
let va_req_Memcpy (va_b0:va_code) (va_s0:va_state) (win:bool) (dst:buffer64) (src:buffer64) : prop =
(va_require_total va_b0 (va_code_Memcpy win) va_s0 /\ va_get_ok va_s0 /\
Vale.X64.Memory.is_initial_heap (va_get_mem_layout va_s0) (va_get_mem va_s0) /\
Vale.X64.Decls.locs_disjoint ([Vale.X64.Decls.loc_buffer #Vale.X64.Memory.vuint64 dst;
Vale.X64.Decls.loc_buffer #Vale.X64.Memory.vuint64 src]) /\ Vale.X64.Decls.validSrcAddrs64
(va_get_mem va_s0) (if win then va_get_reg64 rRdx va_s0 else va_get_reg64 rRsi va_s0) src 2
(va_get_mem_layout va_s0) Secret /\ Vale.X64.Decls.validDstAddrs64 (va_get_mem va_s0) (if win
then va_get_reg64 rRcx va_s0 else va_get_reg64 rRdi va_s0) dst 2 (va_get_mem_layout va_s0)
Secret /\ Vale.X64.Decls.buffer_length #Vale.X64.Memory.vuint64 src == 2 /\
Vale.X64.Decls.buffer_length #Vale.X64.Memory.vuint64 dst == 2)
let va_ens_Memcpy (va_b0:va_code) (va_s0:va_state) (win:bool) (dst:buffer64) (src:buffer64) | false | true | Vale.Test.X64.Vale_memcpy.fsti | {
"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": 20,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val va_ens_Memcpy
(va_b0: va_code)
(va_s0: va_state)
(win: bool)
(dst src: buffer64)
(va_sM: va_state)
(va_fM: va_fuel)
: prop | [] | Vale.Test.X64.Vale_memcpy.va_ens_Memcpy | {
"file_name": "obj/Vale.Test.X64.Vale_memcpy.fsti",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} |
va_b0: Vale.X64.Decls.va_code ->
va_s0: Vale.X64.Decls.va_state ->
win: Prims.bool ->
dst: Vale.X64.Memory.buffer64 ->
src: Vale.X64.Memory.buffer64 ->
va_sM: Vale.X64.Decls.va_state ->
va_fM: Vale.X64.Decls.va_fuel
-> Prims.prop | {
"end_col": 86,
"end_line": 37,
"start_col": 2,
"start_line": 31
} |
Prims.Tot | val va_req_Memcpy (va_b0: va_code) (va_s0: va_state) (win: bool) (dst src: buffer64) : prop | [
{
"abbrev": false,
"full_module": "Vale.X64.QuickCodes",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.QuickCode",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.InsVector",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.InsMem",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.InsBasic",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Decls",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.State",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Memory",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.HeapImpl",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.QuickCodes",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.QuickCode",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.InsVector",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.InsMem",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.InsBasic",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Decls",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.State",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Memory",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.HeapImpl",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Test.X64",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Test.X64",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let va_req_Memcpy (va_b0:va_code) (va_s0:va_state) (win:bool) (dst:buffer64) (src:buffer64) : prop =
(va_require_total va_b0 (va_code_Memcpy win) va_s0 /\ va_get_ok va_s0 /\
Vale.X64.Memory.is_initial_heap (va_get_mem_layout va_s0) (va_get_mem va_s0) /\
Vale.X64.Decls.locs_disjoint ([Vale.X64.Decls.loc_buffer #Vale.X64.Memory.vuint64 dst;
Vale.X64.Decls.loc_buffer #Vale.X64.Memory.vuint64 src]) /\ Vale.X64.Decls.validSrcAddrs64
(va_get_mem va_s0) (if win then va_get_reg64 rRdx va_s0 else va_get_reg64 rRsi va_s0) src 2
(va_get_mem_layout va_s0) Secret /\ Vale.X64.Decls.validDstAddrs64 (va_get_mem va_s0) (if win
then va_get_reg64 rRcx va_s0 else va_get_reg64 rRdi va_s0) dst 2 (va_get_mem_layout va_s0)
Secret /\ Vale.X64.Decls.buffer_length #Vale.X64.Memory.vuint64 src == 2 /\
Vale.X64.Decls.buffer_length #Vale.X64.Memory.vuint64 dst == 2) | val va_req_Memcpy (va_b0: va_code) (va_s0: va_state) (win: bool) (dst src: buffer64) : prop
let va_req_Memcpy (va_b0: va_code) (va_s0: va_state) (win: bool) (dst src: buffer64) : prop = | false | null | false | (va_require_total va_b0 (va_code_Memcpy win) va_s0 /\ va_get_ok va_s0 /\
Vale.X64.Memory.is_initial_heap (va_get_mem_layout va_s0) (va_get_mem va_s0) /\
Vale.X64.Decls.locs_disjoint ([
Vale.X64.Decls.loc_buffer #Vale.X64.Memory.vuint64 dst;
Vale.X64.Decls.loc_buffer #Vale.X64.Memory.vuint64 src
]) /\
Vale.X64.Decls.validSrcAddrs64 (va_get_mem va_s0)
(if win then va_get_reg64 rRdx va_s0 else va_get_reg64 rRsi va_s0)
src
2
(va_get_mem_layout va_s0)
Secret /\
Vale.X64.Decls.validDstAddrs64 (va_get_mem va_s0)
(if win then va_get_reg64 rRcx va_s0 else va_get_reg64 rRdi va_s0)
dst
2
(va_get_mem_layout va_s0)
Secret /\ Vale.X64.Decls.buffer_length #Vale.X64.Memory.vuint64 src == 2 /\
Vale.X64.Decls.buffer_length #Vale.X64.Memory.vuint64 dst == 2) | {
"checked_file": "Vale.Test.X64.Vale_memcpy.fsti.checked",
"dependencies": [
"Vale.X64.State.fsti.checked",
"Vale.X64.QuickCodes.fsti.checked",
"Vale.X64.QuickCode.fst.checked",
"Vale.X64.Memory.fsti.checked",
"Vale.X64.Machine_s.fst.checked",
"Vale.X64.InsVector.fsti.checked",
"Vale.X64.InsMem.fsti.checked",
"Vale.X64.InsBasic.fsti.checked",
"Vale.X64.Decls.fsti.checked",
"Vale.Arch.HeapImpl.fsti.checked",
"prims.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked"
],
"interface_file": false,
"source_file": "Vale.Test.X64.Vale_memcpy.fsti"
} | [
"total"
] | [
"Vale.X64.Decls.va_code",
"Vale.X64.Decls.va_state",
"Prims.bool",
"Vale.X64.Memory.buffer64",
"Prims.l_and",
"Vale.X64.Decls.va_require_total",
"Vale.Test.X64.Vale_memcpy.va_code_Memcpy",
"Prims.b2t",
"Vale.X64.Decls.va_get_ok",
"Vale.X64.Memory.is_initial_heap",
"Vale.X64.Decls.va_get_mem_layout",
"Vale.X64.Decls.va_get_mem",
"Vale.X64.Decls.locs_disjoint",
"Prims.Cons",
"Vale.X64.Memory.loc",
"Vale.X64.Decls.loc_buffer",
"Vale.X64.Memory.vuint64",
"Prims.Nil",
"Vale.X64.Decls.validSrcAddrs64",
"Vale.X64.Decls.va_get_reg64",
"Vale.X64.Machine_s.rRdx",
"Vale.X64.Machine_s.rRsi",
"Prims.int",
"Vale.Arch.HeapTypes_s.Secret",
"Vale.X64.Decls.validDstAddrs64",
"Vale.X64.Machine_s.rRcx",
"Vale.X64.Machine_s.rRdi",
"Prims.eq2",
"Vale.X64.Decls.buffer_length",
"Prims.prop"
] | [] | module Vale.Test.X64.Vale_memcpy
open Vale.Arch.HeapImpl
open Vale.X64.Machine_s
open Vale.X64.Memory
open Vale.X64.State
open Vale.X64.Decls
open Vale.X64.InsBasic
open Vale.X64.InsMem
open Vale.X64.InsVector
open Vale.X64.QuickCode
open Vale.X64.QuickCodes
#set-options "--z3rlimit 20"
//-- Memcpy
val va_code_Memcpy : win:bool -> Tot va_code
val va_codegen_success_Memcpy : win:bool -> Tot va_pbool | false | true | Vale.Test.X64.Vale_memcpy.fsti | {
"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": 20,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val va_req_Memcpy (va_b0: va_code) (va_s0: va_state) (win: bool) (dst src: buffer64) : prop | [] | Vale.Test.X64.Vale_memcpy.va_req_Memcpy | {
"file_name": "obj/Vale.Test.X64.Vale_memcpy.fsti",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} |
va_b0: Vale.X64.Decls.va_code ->
va_s0: Vale.X64.Decls.va_state ->
win: Prims.bool ->
dst: Vale.X64.Memory.buffer64 ->
src: Vale.X64.Memory.buffer64
-> Prims.prop | {
"end_col": 67,
"end_line": 28,
"start_col": 2,
"start_line": 20
} |
Prims.Tot | val va_wp_Memcpy
(win: bool)
(dst src: buffer64)
(va_s0: va_state)
(va_k: (va_state -> unit -> Type0))
: Type0 | [
{
"abbrev": false,
"full_module": "Vale.X64.QuickCodes",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.QuickCode",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.InsVector",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.InsMem",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.InsBasic",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Decls",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.State",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Memory",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.HeapImpl",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.QuickCodes",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.QuickCode",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.InsVector",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.InsMem",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.InsBasic",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Decls",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.State",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Memory",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.HeapImpl",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Test.X64",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Test.X64",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let va_wp_Memcpy (win:bool) (dst:buffer64) (src:buffer64) (va_s0:va_state) (va_k:(va_state -> unit
-> Type0)) : Type0 =
(va_get_ok va_s0 /\ Vale.X64.Memory.is_initial_heap (va_get_mem_layout va_s0) (va_get_mem va_s0)
/\ Vale.X64.Decls.locs_disjoint ([Vale.X64.Decls.loc_buffer #Vale.X64.Memory.vuint64 dst;
Vale.X64.Decls.loc_buffer #Vale.X64.Memory.vuint64 src]) /\ Vale.X64.Decls.validSrcAddrs64
(va_get_mem va_s0) (va_if win (fun _ -> va_get_reg64 rRdx va_s0) (fun _ -> va_get_reg64 rRsi
va_s0)) src 2 (va_get_mem_layout va_s0) Secret /\ Vale.X64.Decls.validDstAddrs64 (va_get_mem
va_s0) (va_if win (fun _ -> va_get_reg64 rRcx va_s0) (fun _ -> va_get_reg64 rRdi va_s0)) dst 2
(va_get_mem_layout va_s0) Secret /\ Vale.X64.Decls.buffer_length #Vale.X64.Memory.vuint64 src
== 2 /\ Vale.X64.Decls.buffer_length #Vale.X64.Memory.vuint64 dst == 2 /\ (forall
(va_x_mem:vale_heap) (va_x_rax:nat64) (va_x_rcx:nat64) (va_x_r9:nat64)
(va_x_memLayout:vale_heap_layout) (va_x_heap1:vale_heap) . let va_sM = va_upd_mem_heaplet 1
va_x_heap1 (va_upd_mem_layout va_x_memLayout (va_upd_reg64 rR9 va_x_r9 (va_upd_reg64 rRcx
va_x_rcx (va_upd_reg64 rRax va_x_rax (va_upd_mem va_x_mem va_s0))))) in va_get_ok va_sM /\
Vale.X64.Memory.buffer_as_seq #Vale.X64.Memory.vuint64 (va_get_mem va_sM) dst ==
Vale.X64.Memory.buffer_as_seq #Vale.X64.Memory.vuint64 (va_get_mem va_sM) src /\
Vale.X64.Decls.modifies_mem (Vale.X64.Decls.loc_buffer #Vale.X64.Memory.vuint64 dst)
(va_get_mem va_s0) (va_get_mem va_sM) ==> va_k va_sM (()))) | val va_wp_Memcpy
(win: bool)
(dst src: buffer64)
(va_s0: va_state)
(va_k: (va_state -> unit -> Type0))
: Type0
let va_wp_Memcpy
(win: bool)
(dst src: buffer64)
(va_s0: va_state)
(va_k: (va_state -> unit -> Type0))
: Type0 = | false | null | false | (va_get_ok va_s0 /\ Vale.X64.Memory.is_initial_heap (va_get_mem_layout va_s0) (va_get_mem va_s0) /\
Vale.X64.Decls.locs_disjoint ([
Vale.X64.Decls.loc_buffer #Vale.X64.Memory.vuint64 dst;
Vale.X64.Decls.loc_buffer #Vale.X64.Memory.vuint64 src
]) /\
Vale.X64.Decls.validSrcAddrs64 (va_get_mem va_s0)
(va_if win (fun _ -> va_get_reg64 rRdx va_s0) (fun _ -> va_get_reg64 rRsi va_s0))
src
2
(va_get_mem_layout va_s0)
Secret /\
Vale.X64.Decls.validDstAddrs64 (va_get_mem va_s0)
(va_if win (fun _ -> va_get_reg64 rRcx va_s0) (fun _ -> va_get_reg64 rRdi va_s0))
dst
2
(va_get_mem_layout va_s0)
Secret /\ Vale.X64.Decls.buffer_length #Vale.X64.Memory.vuint64 src == 2 /\
Vale.X64.Decls.buffer_length #Vale.X64.Memory.vuint64 dst == 2 /\
(forall (va_x_mem: vale_heap)
(va_x_rax: nat64)
(va_x_rcx: nat64)
(va_x_r9: nat64)
(va_x_memLayout: vale_heap_layout)
(va_x_heap1: vale_heap).
let va_sM =
va_upd_mem_heaplet 1
va_x_heap1
(va_upd_mem_layout va_x_memLayout
(va_upd_reg64 rR9
va_x_r9
(va_upd_reg64 rRcx
va_x_rcx
(va_upd_reg64 rRax va_x_rax (va_upd_mem va_x_mem va_s0)))))
in
va_get_ok va_sM /\
Vale.X64.Memory.buffer_as_seq #Vale.X64.Memory.vuint64 (va_get_mem va_sM) dst ==
Vale.X64.Memory.buffer_as_seq #Vale.X64.Memory.vuint64 (va_get_mem va_sM) src /\
Vale.X64.Decls.modifies_mem (Vale.X64.Decls.loc_buffer #Vale.X64.Memory.vuint64 dst)
(va_get_mem va_s0)
(va_get_mem va_sM) ==>
va_k va_sM (()))) | {
"checked_file": "Vale.Test.X64.Vale_memcpy.fsti.checked",
"dependencies": [
"Vale.X64.State.fsti.checked",
"Vale.X64.QuickCodes.fsti.checked",
"Vale.X64.QuickCode.fst.checked",
"Vale.X64.Memory.fsti.checked",
"Vale.X64.Machine_s.fst.checked",
"Vale.X64.InsVector.fsti.checked",
"Vale.X64.InsMem.fsti.checked",
"Vale.X64.InsBasic.fsti.checked",
"Vale.X64.Decls.fsti.checked",
"Vale.Arch.HeapImpl.fsti.checked",
"prims.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked"
],
"interface_file": false,
"source_file": "Vale.Test.X64.Vale_memcpy.fsti"
} | [
"total"
] | [
"Prims.bool",
"Vale.X64.Memory.buffer64",
"Vale.X64.Decls.va_state",
"Prims.unit",
"Prims.l_and",
"Prims.b2t",
"Vale.X64.Decls.va_get_ok",
"Vale.X64.Memory.is_initial_heap",
"Vale.X64.Decls.va_get_mem_layout",
"Vale.X64.Decls.va_get_mem",
"Vale.X64.Decls.locs_disjoint",
"Prims.Cons",
"Vale.X64.Memory.loc",
"Vale.X64.Decls.loc_buffer",
"Vale.X64.Memory.vuint64",
"Prims.Nil",
"Vale.X64.Decls.validSrcAddrs64",
"Vale.X64.Decls.va_if",
"Vale.Def.Types_s.nat64",
"Vale.X64.Decls.va_get_reg64",
"Vale.X64.Machine_s.rRdx",
"Prims.l_not",
"Vale.X64.Machine_s.rRsi",
"Vale.Arch.HeapTypes_s.Secret",
"Vale.X64.Decls.validDstAddrs64",
"Vale.X64.Machine_s.rRcx",
"Vale.X64.Machine_s.rRdi",
"Prims.eq2",
"Prims.int",
"Vale.X64.Decls.buffer_length",
"Prims.l_Forall",
"Vale.X64.InsBasic.vale_heap",
"Vale.X64.Memory.nat64",
"Vale.Arch.HeapImpl.vale_heap_layout",
"Prims.l_imp",
"FStar.Seq.Base.seq",
"Vale.X64.Memory.base_typ_as_vale_type",
"Vale.X64.Memory.buffer_as_seq",
"Vale.X64.Decls.modifies_mem",
"Vale.X64.State.vale_state",
"Vale.X64.Decls.va_upd_mem_heaplet",
"Vale.X64.Decls.va_upd_mem_layout",
"Vale.X64.Decls.va_upd_reg64",
"Vale.X64.Machine_s.rR9",
"Vale.X64.Machine_s.rRax",
"Vale.X64.Decls.va_upd_mem"
] | [] | module Vale.Test.X64.Vale_memcpy
open Vale.Arch.HeapImpl
open Vale.X64.Machine_s
open Vale.X64.Memory
open Vale.X64.State
open Vale.X64.Decls
open Vale.X64.InsBasic
open Vale.X64.InsMem
open Vale.X64.InsVector
open Vale.X64.QuickCode
open Vale.X64.QuickCodes
#set-options "--z3rlimit 20"
//-- Memcpy
val va_code_Memcpy : win:bool -> Tot va_code
val va_codegen_success_Memcpy : win:bool -> Tot va_pbool
let va_req_Memcpy (va_b0:va_code) (va_s0:va_state) (win:bool) (dst:buffer64) (src:buffer64) : prop =
(va_require_total va_b0 (va_code_Memcpy win) va_s0 /\ va_get_ok va_s0 /\
Vale.X64.Memory.is_initial_heap (va_get_mem_layout va_s0) (va_get_mem va_s0) /\
Vale.X64.Decls.locs_disjoint ([Vale.X64.Decls.loc_buffer #Vale.X64.Memory.vuint64 dst;
Vale.X64.Decls.loc_buffer #Vale.X64.Memory.vuint64 src]) /\ Vale.X64.Decls.validSrcAddrs64
(va_get_mem va_s0) (if win then va_get_reg64 rRdx va_s0 else va_get_reg64 rRsi va_s0) src 2
(va_get_mem_layout va_s0) Secret /\ Vale.X64.Decls.validDstAddrs64 (va_get_mem va_s0) (if win
then va_get_reg64 rRcx va_s0 else va_get_reg64 rRdi va_s0) dst 2 (va_get_mem_layout va_s0)
Secret /\ Vale.X64.Decls.buffer_length #Vale.X64.Memory.vuint64 src == 2 /\
Vale.X64.Decls.buffer_length #Vale.X64.Memory.vuint64 dst == 2)
let va_ens_Memcpy (va_b0:va_code) (va_s0:va_state) (win:bool) (dst:buffer64) (src:buffer64)
(va_sM:va_state) (va_fM:va_fuel) : prop =
(va_req_Memcpy va_b0 va_s0 win dst src /\ va_ensure_total va_b0 va_s0 va_sM va_fM /\ va_get_ok
va_sM /\ Vale.X64.Memory.buffer_as_seq #Vale.X64.Memory.vuint64 (va_get_mem va_sM) dst ==
Vale.X64.Memory.buffer_as_seq #Vale.X64.Memory.vuint64 (va_get_mem va_sM) src /\
Vale.X64.Decls.modifies_mem (Vale.X64.Decls.loc_buffer #Vale.X64.Memory.vuint64 dst)
(va_get_mem va_s0) (va_get_mem va_sM) /\ va_state_eq va_sM (va_update_mem_heaplet 1 va_sM
(va_update_mem_layout va_sM (va_update_reg64 rR9 va_sM (va_update_reg64 rRcx va_sM
(va_update_reg64 rRax va_sM (va_update_ok va_sM (va_update_mem va_sM va_s0))))))))
val va_lemma_Memcpy : va_b0:va_code -> va_s0:va_state -> win:bool -> dst:buffer64 -> src:buffer64
-> Ghost (va_state & va_fuel)
(requires (va_require_total va_b0 (va_code_Memcpy win) va_s0 /\ va_get_ok va_s0 /\
Vale.X64.Memory.is_initial_heap (va_get_mem_layout va_s0) (va_get_mem va_s0) /\
Vale.X64.Decls.locs_disjoint ([Vale.X64.Decls.loc_buffer #Vale.X64.Memory.vuint64 dst;
Vale.X64.Decls.loc_buffer #Vale.X64.Memory.vuint64 src]) /\ Vale.X64.Decls.validSrcAddrs64
(va_get_mem va_s0) (if win then va_get_reg64 rRdx va_s0 else va_get_reg64 rRsi va_s0) src 2
(va_get_mem_layout va_s0) Secret /\ Vale.X64.Decls.validDstAddrs64 (va_get_mem va_s0) (if win
then va_get_reg64 rRcx va_s0 else va_get_reg64 rRdi va_s0) dst 2 (va_get_mem_layout va_s0)
Secret /\ Vale.X64.Decls.buffer_length #Vale.X64.Memory.vuint64 src == 2 /\
Vale.X64.Decls.buffer_length #Vale.X64.Memory.vuint64 dst == 2))
(ensures (fun (va_sM, va_fM) -> va_ensure_total va_b0 va_s0 va_sM va_fM /\ va_get_ok va_sM /\
Vale.X64.Memory.buffer_as_seq #Vale.X64.Memory.vuint64 (va_get_mem va_sM) dst ==
Vale.X64.Memory.buffer_as_seq #Vale.X64.Memory.vuint64 (va_get_mem va_sM) src /\
Vale.X64.Decls.modifies_mem (Vale.X64.Decls.loc_buffer #Vale.X64.Memory.vuint64 dst)
(va_get_mem va_s0) (va_get_mem va_sM) /\ va_state_eq va_sM (va_update_mem_heaplet 1 va_sM
(va_update_mem_layout va_sM (va_update_reg64 rR9 va_sM (va_update_reg64 rRcx va_sM
(va_update_reg64 rRax va_sM (va_update_ok va_sM (va_update_mem va_sM va_s0)))))))))
[@ va_qattr]
let va_wp_Memcpy (win:bool) (dst:buffer64) (src:buffer64) (va_s0:va_state) (va_k:(va_state -> unit | false | true | Vale.Test.X64.Vale_memcpy.fsti | {
"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": 20,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val va_wp_Memcpy
(win: bool)
(dst src: buffer64)
(va_s0: va_state)
(va_k: (va_state -> unit -> Type0))
: Type0 | [] | Vale.Test.X64.Vale_memcpy.va_wp_Memcpy | {
"file_name": "obj/Vale.Test.X64.Vale_memcpy.fsti",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} |
win: Prims.bool ->
dst: Vale.X64.Memory.buffer64 ->
src: Vale.X64.Memory.buffer64 ->
va_s0: Vale.X64.Decls.va_state ->
va_k: (_: Vale.X64.Decls.va_state -> _: Prims.unit -> Type0)
-> Type0 | {
"end_col": 63,
"end_line": 75,
"start_col": 2,
"start_line": 60
} |
Prims.Tot | val va_quick_Memcpy (win: bool) (dst src: buffer64) : (va_quickCode unit (va_code_Memcpy win)) | [
{
"abbrev": false,
"full_module": "Vale.X64.QuickCodes",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.QuickCode",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.InsVector",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.InsMem",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.InsBasic",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Decls",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.State",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Memory",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.HeapImpl",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.QuickCodes",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.QuickCode",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.InsVector",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.InsMem",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.InsBasic",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Decls",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.State",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Memory",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.HeapImpl",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Test.X64",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Test.X64",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let va_quick_Memcpy (win:bool) (dst:buffer64) (src:buffer64) : (va_quickCode unit (va_code_Memcpy
win)) =
(va_QProc (va_code_Memcpy win) ([va_Mod_mem_heaplet 1; va_Mod_mem_layout; va_Mod_reg64 rR9;
va_Mod_reg64 rRcx; va_Mod_reg64 rRax; va_Mod_mem]) (va_wp_Memcpy win dst src)
(va_wpProof_Memcpy win dst src)) | val va_quick_Memcpy (win: bool) (dst src: buffer64) : (va_quickCode unit (va_code_Memcpy win))
let va_quick_Memcpy (win: bool) (dst src: buffer64) : (va_quickCode unit (va_code_Memcpy win)) = | false | null | false | (va_QProc (va_code_Memcpy win)
([
va_Mod_mem_heaplet 1;
va_Mod_mem_layout;
va_Mod_reg64 rR9;
va_Mod_reg64 rRcx;
va_Mod_reg64 rRax;
va_Mod_mem
])
(va_wp_Memcpy win dst src)
(va_wpProof_Memcpy win dst src)) | {
"checked_file": "Vale.Test.X64.Vale_memcpy.fsti.checked",
"dependencies": [
"Vale.X64.State.fsti.checked",
"Vale.X64.QuickCodes.fsti.checked",
"Vale.X64.QuickCode.fst.checked",
"Vale.X64.Memory.fsti.checked",
"Vale.X64.Machine_s.fst.checked",
"Vale.X64.InsVector.fsti.checked",
"Vale.X64.InsMem.fsti.checked",
"Vale.X64.InsBasic.fsti.checked",
"Vale.X64.Decls.fsti.checked",
"Vale.Arch.HeapImpl.fsti.checked",
"prims.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked"
],
"interface_file": false,
"source_file": "Vale.Test.X64.Vale_memcpy.fsti"
} | [
"total"
] | [
"Prims.bool",
"Vale.X64.Memory.buffer64",
"Vale.X64.QuickCode.va_QProc",
"Prims.unit",
"Vale.Test.X64.Vale_memcpy.va_code_Memcpy",
"Prims.Cons",
"Vale.X64.QuickCode.mod_t",
"Vale.X64.QuickCode.va_Mod_mem_heaplet",
"Vale.X64.QuickCode.va_Mod_mem_layout",
"Vale.X64.QuickCode.va_Mod_reg64",
"Vale.X64.Machine_s.rR9",
"Vale.X64.Machine_s.rRcx",
"Vale.X64.Machine_s.rRax",
"Vale.X64.QuickCode.va_Mod_mem",
"Prims.Nil",
"Vale.Test.X64.Vale_memcpy.va_wp_Memcpy",
"Vale.Test.X64.Vale_memcpy.va_wpProof_Memcpy",
"Vale.X64.QuickCode.va_quickCode"
] | [] | module Vale.Test.X64.Vale_memcpy
open Vale.Arch.HeapImpl
open Vale.X64.Machine_s
open Vale.X64.Memory
open Vale.X64.State
open Vale.X64.Decls
open Vale.X64.InsBasic
open Vale.X64.InsMem
open Vale.X64.InsVector
open Vale.X64.QuickCode
open Vale.X64.QuickCodes
#set-options "--z3rlimit 20"
//-- Memcpy
val va_code_Memcpy : win:bool -> Tot va_code
val va_codegen_success_Memcpy : win:bool -> Tot va_pbool
let va_req_Memcpy (va_b0:va_code) (va_s0:va_state) (win:bool) (dst:buffer64) (src:buffer64) : prop =
(va_require_total va_b0 (va_code_Memcpy win) va_s0 /\ va_get_ok va_s0 /\
Vale.X64.Memory.is_initial_heap (va_get_mem_layout va_s0) (va_get_mem va_s0) /\
Vale.X64.Decls.locs_disjoint ([Vale.X64.Decls.loc_buffer #Vale.X64.Memory.vuint64 dst;
Vale.X64.Decls.loc_buffer #Vale.X64.Memory.vuint64 src]) /\ Vale.X64.Decls.validSrcAddrs64
(va_get_mem va_s0) (if win then va_get_reg64 rRdx va_s0 else va_get_reg64 rRsi va_s0) src 2
(va_get_mem_layout va_s0) Secret /\ Vale.X64.Decls.validDstAddrs64 (va_get_mem va_s0) (if win
then va_get_reg64 rRcx va_s0 else va_get_reg64 rRdi va_s0) dst 2 (va_get_mem_layout va_s0)
Secret /\ Vale.X64.Decls.buffer_length #Vale.X64.Memory.vuint64 src == 2 /\
Vale.X64.Decls.buffer_length #Vale.X64.Memory.vuint64 dst == 2)
let va_ens_Memcpy (va_b0:va_code) (va_s0:va_state) (win:bool) (dst:buffer64) (src:buffer64)
(va_sM:va_state) (va_fM:va_fuel) : prop =
(va_req_Memcpy va_b0 va_s0 win dst src /\ va_ensure_total va_b0 va_s0 va_sM va_fM /\ va_get_ok
va_sM /\ Vale.X64.Memory.buffer_as_seq #Vale.X64.Memory.vuint64 (va_get_mem va_sM) dst ==
Vale.X64.Memory.buffer_as_seq #Vale.X64.Memory.vuint64 (va_get_mem va_sM) src /\
Vale.X64.Decls.modifies_mem (Vale.X64.Decls.loc_buffer #Vale.X64.Memory.vuint64 dst)
(va_get_mem va_s0) (va_get_mem va_sM) /\ va_state_eq va_sM (va_update_mem_heaplet 1 va_sM
(va_update_mem_layout va_sM (va_update_reg64 rR9 va_sM (va_update_reg64 rRcx va_sM
(va_update_reg64 rRax va_sM (va_update_ok va_sM (va_update_mem va_sM va_s0))))))))
val va_lemma_Memcpy : va_b0:va_code -> va_s0:va_state -> win:bool -> dst:buffer64 -> src:buffer64
-> Ghost (va_state & va_fuel)
(requires (va_require_total va_b0 (va_code_Memcpy win) va_s0 /\ va_get_ok va_s0 /\
Vale.X64.Memory.is_initial_heap (va_get_mem_layout va_s0) (va_get_mem va_s0) /\
Vale.X64.Decls.locs_disjoint ([Vale.X64.Decls.loc_buffer #Vale.X64.Memory.vuint64 dst;
Vale.X64.Decls.loc_buffer #Vale.X64.Memory.vuint64 src]) /\ Vale.X64.Decls.validSrcAddrs64
(va_get_mem va_s0) (if win then va_get_reg64 rRdx va_s0 else va_get_reg64 rRsi va_s0) src 2
(va_get_mem_layout va_s0) Secret /\ Vale.X64.Decls.validDstAddrs64 (va_get_mem va_s0) (if win
then va_get_reg64 rRcx va_s0 else va_get_reg64 rRdi va_s0) dst 2 (va_get_mem_layout va_s0)
Secret /\ Vale.X64.Decls.buffer_length #Vale.X64.Memory.vuint64 src == 2 /\
Vale.X64.Decls.buffer_length #Vale.X64.Memory.vuint64 dst == 2))
(ensures (fun (va_sM, va_fM) -> va_ensure_total va_b0 va_s0 va_sM va_fM /\ va_get_ok va_sM /\
Vale.X64.Memory.buffer_as_seq #Vale.X64.Memory.vuint64 (va_get_mem va_sM) dst ==
Vale.X64.Memory.buffer_as_seq #Vale.X64.Memory.vuint64 (va_get_mem va_sM) src /\
Vale.X64.Decls.modifies_mem (Vale.X64.Decls.loc_buffer #Vale.X64.Memory.vuint64 dst)
(va_get_mem va_s0) (va_get_mem va_sM) /\ va_state_eq va_sM (va_update_mem_heaplet 1 va_sM
(va_update_mem_layout va_sM (va_update_reg64 rR9 va_sM (va_update_reg64 rRcx va_sM
(va_update_reg64 rRax va_sM (va_update_ok va_sM (va_update_mem va_sM va_s0)))))))))
[@ va_qattr]
let va_wp_Memcpy (win:bool) (dst:buffer64) (src:buffer64) (va_s0:va_state) (va_k:(va_state -> unit
-> Type0)) : Type0 =
(va_get_ok va_s0 /\ Vale.X64.Memory.is_initial_heap (va_get_mem_layout va_s0) (va_get_mem va_s0)
/\ Vale.X64.Decls.locs_disjoint ([Vale.X64.Decls.loc_buffer #Vale.X64.Memory.vuint64 dst;
Vale.X64.Decls.loc_buffer #Vale.X64.Memory.vuint64 src]) /\ Vale.X64.Decls.validSrcAddrs64
(va_get_mem va_s0) (va_if win (fun _ -> va_get_reg64 rRdx va_s0) (fun _ -> va_get_reg64 rRsi
va_s0)) src 2 (va_get_mem_layout va_s0) Secret /\ Vale.X64.Decls.validDstAddrs64 (va_get_mem
va_s0) (va_if win (fun _ -> va_get_reg64 rRcx va_s0) (fun _ -> va_get_reg64 rRdi va_s0)) dst 2
(va_get_mem_layout va_s0) Secret /\ Vale.X64.Decls.buffer_length #Vale.X64.Memory.vuint64 src
== 2 /\ Vale.X64.Decls.buffer_length #Vale.X64.Memory.vuint64 dst == 2 /\ (forall
(va_x_mem:vale_heap) (va_x_rax:nat64) (va_x_rcx:nat64) (va_x_r9:nat64)
(va_x_memLayout:vale_heap_layout) (va_x_heap1:vale_heap) . let va_sM = va_upd_mem_heaplet 1
va_x_heap1 (va_upd_mem_layout va_x_memLayout (va_upd_reg64 rR9 va_x_r9 (va_upd_reg64 rRcx
va_x_rcx (va_upd_reg64 rRax va_x_rax (va_upd_mem va_x_mem va_s0))))) in va_get_ok va_sM /\
Vale.X64.Memory.buffer_as_seq #Vale.X64.Memory.vuint64 (va_get_mem va_sM) dst ==
Vale.X64.Memory.buffer_as_seq #Vale.X64.Memory.vuint64 (va_get_mem va_sM) src /\
Vale.X64.Decls.modifies_mem (Vale.X64.Decls.loc_buffer #Vale.X64.Memory.vuint64 dst)
(va_get_mem va_s0) (va_get_mem va_sM) ==> va_k va_sM (())))
val va_wpProof_Memcpy : win:bool -> dst:buffer64 -> src:buffer64 -> va_s0:va_state ->
va_k:(va_state -> unit -> Type0)
-> Ghost (va_state & va_fuel & unit)
(requires (va_t_require va_s0 /\ va_wp_Memcpy win dst src va_s0 va_k))
(ensures (fun (va_sM, va_f0, va_g) -> va_t_ensure (va_code_Memcpy win) ([va_Mod_mem_heaplet 1;
va_Mod_mem_layout; va_Mod_reg64 rR9; va_Mod_reg64 rRcx; va_Mod_reg64 rRax; va_Mod_mem]) va_s0
va_k ((va_sM, va_f0, va_g))))
[@ "opaque_to_smt" va_qattr]
let va_quick_Memcpy (win:bool) (dst:buffer64) (src:buffer64) : (va_quickCode unit (va_code_Memcpy | false | false | Vale.Test.X64.Vale_memcpy.fsti | {
"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": 20,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val va_quick_Memcpy (win: bool) (dst src: buffer64) : (va_quickCode unit (va_code_Memcpy win)) | [] | Vale.Test.X64.Vale_memcpy.va_quick_Memcpy | {
"file_name": "obj/Vale.Test.X64.Vale_memcpy.fsti",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | win: Prims.bool -> dst: Vale.X64.Memory.buffer64 -> src: Vale.X64.Memory.buffer64
-> Vale.X64.QuickCode.va_quickCode Prims.unit (Vale.Test.X64.Vale_memcpy.va_code_Memcpy win) | {
"end_col": 36,
"end_line": 89,
"start_col": 2,
"start_line": 87
} |
Prims.Tot | val all_finite_map_facts_ambient:squash (all_finite_map_facts u#b) | [
{
"abbrev": false,
"full_module": "FStar.FiniteMap.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.FiniteMap",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.FiniteMap",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let all_finite_map_facts_ambient : squash (all_finite_map_facts u#b) =
all_finite_map_facts_lemma u#b () | val all_finite_map_facts_ambient:squash (all_finite_map_facts u#b)
let all_finite_map_facts_ambient:squash (all_finite_map_facts u#b) = | false | null | true | all_finite_map_facts_lemma u#b () | {
"checked_file": "FStar.FiniteMap.Ambient.fst.checked",
"dependencies": [
"prims.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.FiniteMap.Base.fsti.checked"
],
"interface_file": false,
"source_file": "FStar.FiniteMap.Ambient.fst"
} | [
"total"
] | [
"FStar.FiniteMap.Base.all_finite_map_facts_lemma"
] | [] | (*
Copyright 2008-2021 John Li, Jay Lorch, Rustan Leino, Alex Summers,
Dan Rosen, Nikhil Swamy, Microsoft Research, and contributors to
the Dafny Project
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
Includes material from the Dafny project
(https://github.com/dafny-lang/dafny) which carries this license
information:
Created 9 February 2008 by Rustan Leino.
Converted to Boogie 2 on 28 June 2008.
Edited sequence axioms 20 October 2009 by Alex Summers.
Modified 2014 by Dan Rosen.
Copyright (c) 2008-2014, Microsoft.
Copyright by the contributors to the Dafny Project
SPDX-License-Identifier: MIT
*)
(**
This module brings properties about finite maps ambiently into the
context. The properties are modeled after those in the Dafny sequence
axioms, with patterns for quantifiers chosen as in those axioms.
@summary Puts properties of finite maps into the ambient context
*)
module FStar.FiniteMap.Ambient
open FStar.FiniteMap.Base | false | true | FStar.FiniteMap.Ambient.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val all_finite_map_facts_ambient:squash (all_finite_map_facts u#b) | [] | FStar.FiniteMap.Ambient.all_finite_map_facts_ambient | {
"file_name": "ulib/FStar.FiniteMap.Ambient.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | Prims.squash FStar.FiniteMap.Base.all_finite_map_facts | {
"end_col": 35,
"end_line": 43,
"start_col": 2,
"start_line": 43
} |
Prims.Tot | [
{
"abbrev": true,
"full_module": "FStar.FunctionalExtensionality",
"short_module": "F"
},
{
"abbrev": false,
"full_module": "FStar.FunctionalExtensionality",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let disjoint (#a:Type) (s1: set a) (s2: set a) =
equal (intersect s1 s2) empty | let disjoint (#a: Type) (s1 s2: set a) = | false | null | false | equal (intersect s1 s2) empty | {
"checked_file": "FStar.GSet.fsti.checked",
"dependencies": [
"prims.fst.checked",
"FStar.Set.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": false,
"source_file": "FStar.GSet.fsti"
} | [
"total"
] | [
"FStar.GSet.set",
"FStar.GSet.equal",
"FStar.GSet.intersect",
"FStar.GSet.empty"
] | [] | (*
Copyright 2008-2014 Nikhil Swamy, Aseem Rastogi,
Microsoft Research, University of Maryland
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 FStar.GSet
(** Computational sets (on Types): membership is a boolean function *)
#set-options "--initial_fuel 0 --max_fuel 0 --initial_ifuel 0 --max_ifuel 0"
(*
* AR: mark it must_erase_for_extraction temporarily until CMI comes in
*)
[@@must_erase_for_extraction]
val set (a: Type u#a) : Type u#a
val equal (#a:Type) (s1:set a) (s2:set a) : Type0
(* destructors *)
val mem : #a:Type -> a -> set a -> GTot bool
(* constructors *)
val empty : #a:Type -> Tot (set a)
val singleton : #a:Type -> a -> Tot (set a)
val union : #a:Type -> set a -> set a -> Tot (set a)
val intersect : #a:Type -> set a -> set a -> Tot (set a)
val complement : #a:Type -> set a -> Tot (set a)
val comprehend (#a: Type) (f: (a -> GTot bool)) : set a
val of_set (#a: eqtype) (f: Set.set a) : set a
(* a property about sets *) | false | false | FStar.GSet.fsti | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val disjoint : s1: FStar.GSet.set a -> s2: FStar.GSet.set a -> Type0 | [] | FStar.GSet.disjoint | {
"file_name": "ulib/FStar.GSet.fsti",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | s1: FStar.GSet.set a -> s2: FStar.GSet.set a -> Type0 | {
"end_col": 31,
"end_line": 44,
"start_col": 2,
"start_line": 44
} |
|
Prims.Tot | val as_set' (#a: Type) (l: list a) : set a | [
{
"abbrev": true,
"full_module": "FStar.FunctionalExtensionality",
"short_module": "F"
},
{
"abbrev": false,
"full_module": "FStar.FunctionalExtensionality",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let rec as_set' (#a:Type) (l:list a) : set a =
match l with
| [] -> empty
| hd::tl -> union (singleton hd) (as_set' tl) | val as_set' (#a: Type) (l: list a) : set a
let rec as_set' (#a: Type) (l: list a) : set a = | false | null | false | match l with
| [] -> empty
| hd :: tl -> union (singleton hd) (as_set' tl) | {
"checked_file": "FStar.GSet.fsti.checked",
"dependencies": [
"prims.fst.checked",
"FStar.Set.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": false,
"source_file": "FStar.GSet.fsti"
} | [
"total"
] | [
"Prims.list",
"FStar.GSet.empty",
"FStar.GSet.union",
"FStar.GSet.singleton",
"FStar.GSet.as_set'",
"FStar.GSet.set"
] | [] | (*
Copyright 2008-2014 Nikhil Swamy, Aseem Rastogi,
Microsoft Research, University of Maryland
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 FStar.GSet
(** Computational sets (on Types): membership is a boolean function *)
#set-options "--initial_fuel 0 --max_fuel 0 --initial_ifuel 0 --max_ifuel 0"
(*
* AR: mark it must_erase_for_extraction temporarily until CMI comes in
*)
[@@must_erase_for_extraction]
val set (a: Type u#a) : Type u#a
val equal (#a:Type) (s1:set a) (s2:set a) : Type0
(* destructors *)
val mem : #a:Type -> a -> set a -> GTot bool
(* constructors *)
val empty : #a:Type -> Tot (set a)
val singleton : #a:Type -> a -> Tot (set a)
val union : #a:Type -> set a -> set a -> Tot (set a)
val intersect : #a:Type -> set a -> set a -> Tot (set a)
val complement : #a:Type -> set a -> Tot (set a)
val comprehend (#a: Type) (f: (a -> GTot bool)) : set a
val of_set (#a: eqtype) (f: Set.set a) : set a
(* a property about sets *)
let disjoint (#a:Type) (s1: set a) (s2: set a) =
equal (intersect s1 s2) empty
(* ops *)
type subset (#a:Type) (s1:set a) (s2:set a) :Type0 = forall x. mem x s1 ==> mem x s2
(* Properties *)
val mem_empty: #a:Type -> x:a -> Lemma
(requires True)
(ensures (not (mem x empty)))
[SMTPat (mem x empty)]
val mem_singleton: #a:Type -> x:a -> y:a -> Lemma
(requires True)
(ensures (mem y (singleton x) <==> (x==y)))
[SMTPat (mem y (singleton x))]
val mem_union: #a:Type -> x:a -> s1:set a -> s2:set a -> Lemma
(requires True)
(ensures (mem x (union s1 s2) = (mem x s1 || mem x s2)))
[SMTPat (mem x (union s1 s2))]
val mem_intersect: #a:Type -> x:a -> s1:set a -> s2:set a -> Lemma
(requires True)
(ensures (mem x (intersect s1 s2) = (mem x s1 && mem x s2)))
[SMTPat (mem x (intersect s1 s2))]
val mem_complement: #a:Type -> x:a -> s:set a -> Lemma
(requires True)
(ensures (mem x (complement s) = not (mem x s)))
[SMTPat (mem x (complement s))]
val mem_subset: #a:Type -> s1:set a -> s2:set a -> Lemma
(requires (forall x. mem x s1 ==> mem x s2))
(ensures (subset s1 s2))
[SMTPat (subset s1 s2)]
val subset_mem: #a:Type -> s1:set a -> s2:set a -> Lemma
(requires (subset s1 s2))
(ensures (forall x. mem x s1 ==> mem x s2))
[SMTPat (subset s1 s2)]
val comprehend_mem (#a: Type) (f: (a -> GTot bool)) (x: a)
: Lemma (ensures (mem x (comprehend f) == f x))
[SMTPat (mem x (comprehend f))]
val mem_of_set (#a: eqtype) (f: Set.set a) (x: a)
: Lemma (ensures (mem x (of_set f) <==> Set.mem x f))
[SMTPat (mem x (of_set f))]
(* extensionality *)
val lemma_equal_intro: #a:Type -> s1:set a -> s2:set a -> Lemma
(requires (forall x. mem x s1 = mem x s2))
(ensures (equal s1 s2))
[SMTPat (equal s1 s2)]
val lemma_equal_elim: #a:Type -> s1:set a -> s2:set a -> Lemma
(requires (equal s1 s2))
(ensures (s1 == s2))
[SMTPat (equal s1 s2)]
val lemma_equal_refl: #a:Type -> s1:set a -> s2:set a -> Lemma
(requires (s1 == s2))
(ensures (equal s1 s2))
[SMTPat (equal s1 s2)]
let disjoint_not_in_both (a:Type) (s1:set a) (s2:set a) :
Lemma
(requires (disjoint s1 s2))
(ensures (forall (x:a).{:pattern (mem x s1) \/ (mem x s2)} mem x s1 ==> ~(mem x s2)))
[SMTPat (disjoint s1 s2)]
= let f (x:a) : Lemma (~(mem x (intersect s1 s2))) = () in
FStar.Classical.forall_intro f
(* Converting lists to sets *)
#reset-options //restore fuel usage here | false | false | FStar.GSet.fsti | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val as_set' (#a: Type) (l: list a) : set a | [
"recursion"
] | FStar.GSet.as_set' | {
"file_name": "ulib/FStar.GSet.fsti",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | l: Prims.list a -> FStar.GSet.set a | {
"end_col": 47,
"end_line": 124,
"start_col": 2,
"start_line": 122
} |
FStar.Pervasives.Lemma | val disjoint_not_in_both (a: Type) (s1 s2: set a)
: Lemma (requires (disjoint s1 s2))
(ensures (forall (x: a). {:pattern (mem x s1)\/(mem x s2)} mem x s1 ==> ~(mem x s2)))
[SMTPat (disjoint s1 s2)] | [
{
"abbrev": true,
"full_module": "FStar.FunctionalExtensionality",
"short_module": "F"
},
{
"abbrev": false,
"full_module": "FStar.FunctionalExtensionality",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let disjoint_not_in_both (a:Type) (s1:set a) (s2:set a) :
Lemma
(requires (disjoint s1 s2))
(ensures (forall (x:a).{:pattern (mem x s1) \/ (mem x s2)} mem x s1 ==> ~(mem x s2)))
[SMTPat (disjoint s1 s2)]
= let f (x:a) : Lemma (~(mem x (intersect s1 s2))) = () in
FStar.Classical.forall_intro f | val disjoint_not_in_both (a: Type) (s1 s2: set a)
: Lemma (requires (disjoint s1 s2))
(ensures (forall (x: a). {:pattern (mem x s1)\/(mem x s2)} mem x s1 ==> ~(mem x s2)))
[SMTPat (disjoint s1 s2)]
let disjoint_not_in_both (a: Type) (s1 s2: set a)
: Lemma (requires (disjoint s1 s2))
(ensures (forall (x: a). {:pattern (mem x s1)\/(mem x s2)} mem x s1 ==> ~(mem x s2)))
[SMTPat (disjoint s1 s2)] = | false | null | true | let f (x: a) : Lemma (~(mem x (intersect s1 s2))) = () in
FStar.Classical.forall_intro f | {
"checked_file": "FStar.GSet.fsti.checked",
"dependencies": [
"prims.fst.checked",
"FStar.Set.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": false,
"source_file": "FStar.GSet.fsti"
} | [
"lemma"
] | [
"FStar.GSet.set",
"FStar.Classical.forall_intro",
"Prims.l_not",
"Prims.b2t",
"FStar.GSet.mem",
"FStar.GSet.intersect",
"Prims.unit",
"Prims.l_True",
"Prims.squash",
"Prims.Nil",
"FStar.Pervasives.pattern",
"FStar.GSet.disjoint",
"Prims.l_Forall",
"Prims.l_imp",
"Prims.Cons",
"FStar.Pervasives.smt_pat"
] | [] | (*
Copyright 2008-2014 Nikhil Swamy, Aseem Rastogi,
Microsoft Research, University of Maryland
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 FStar.GSet
(** Computational sets (on Types): membership is a boolean function *)
#set-options "--initial_fuel 0 --max_fuel 0 --initial_ifuel 0 --max_ifuel 0"
(*
* AR: mark it must_erase_for_extraction temporarily until CMI comes in
*)
[@@must_erase_for_extraction]
val set (a: Type u#a) : Type u#a
val equal (#a:Type) (s1:set a) (s2:set a) : Type0
(* destructors *)
val mem : #a:Type -> a -> set a -> GTot bool
(* constructors *)
val empty : #a:Type -> Tot (set a)
val singleton : #a:Type -> a -> Tot (set a)
val union : #a:Type -> set a -> set a -> Tot (set a)
val intersect : #a:Type -> set a -> set a -> Tot (set a)
val complement : #a:Type -> set a -> Tot (set a)
val comprehend (#a: Type) (f: (a -> GTot bool)) : set a
val of_set (#a: eqtype) (f: Set.set a) : set a
(* a property about sets *)
let disjoint (#a:Type) (s1: set a) (s2: set a) =
equal (intersect s1 s2) empty
(* ops *)
type subset (#a:Type) (s1:set a) (s2:set a) :Type0 = forall x. mem x s1 ==> mem x s2
(* Properties *)
val mem_empty: #a:Type -> x:a -> Lemma
(requires True)
(ensures (not (mem x empty)))
[SMTPat (mem x empty)]
val mem_singleton: #a:Type -> x:a -> y:a -> Lemma
(requires True)
(ensures (mem y (singleton x) <==> (x==y)))
[SMTPat (mem y (singleton x))]
val mem_union: #a:Type -> x:a -> s1:set a -> s2:set a -> Lemma
(requires True)
(ensures (mem x (union s1 s2) = (mem x s1 || mem x s2)))
[SMTPat (mem x (union s1 s2))]
val mem_intersect: #a:Type -> x:a -> s1:set a -> s2:set a -> Lemma
(requires True)
(ensures (mem x (intersect s1 s2) = (mem x s1 && mem x s2)))
[SMTPat (mem x (intersect s1 s2))]
val mem_complement: #a:Type -> x:a -> s:set a -> Lemma
(requires True)
(ensures (mem x (complement s) = not (mem x s)))
[SMTPat (mem x (complement s))]
val mem_subset: #a:Type -> s1:set a -> s2:set a -> Lemma
(requires (forall x. mem x s1 ==> mem x s2))
(ensures (subset s1 s2))
[SMTPat (subset s1 s2)]
val subset_mem: #a:Type -> s1:set a -> s2:set a -> Lemma
(requires (subset s1 s2))
(ensures (forall x. mem x s1 ==> mem x s2))
[SMTPat (subset s1 s2)]
val comprehend_mem (#a: Type) (f: (a -> GTot bool)) (x: a)
: Lemma (ensures (mem x (comprehend f) == f x))
[SMTPat (mem x (comprehend f))]
val mem_of_set (#a: eqtype) (f: Set.set a) (x: a)
: Lemma (ensures (mem x (of_set f) <==> Set.mem x f))
[SMTPat (mem x (of_set f))]
(* extensionality *)
val lemma_equal_intro: #a:Type -> s1:set a -> s2:set a -> Lemma
(requires (forall x. mem x s1 = mem x s2))
(ensures (equal s1 s2))
[SMTPat (equal s1 s2)]
val lemma_equal_elim: #a:Type -> s1:set a -> s2:set a -> Lemma
(requires (equal s1 s2))
(ensures (s1 == s2))
[SMTPat (equal s1 s2)]
val lemma_equal_refl: #a:Type -> s1:set a -> s2:set a -> Lemma
(requires (s1 == s2))
(ensures (equal s1 s2))
[SMTPat (equal s1 s2)]
let disjoint_not_in_both (a:Type) (s1:set a) (s2:set a) :
Lemma
(requires (disjoint s1 s2))
(ensures (forall (x:a).{:pattern (mem x s1) \/ (mem x s2)} mem x s1 ==> ~(mem x s2))) | false | false | FStar.GSet.fsti | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val disjoint_not_in_both (a: Type) (s1 s2: set a)
: Lemma (requires (disjoint s1 s2))
(ensures (forall (x: a). {:pattern (mem x s1)\/(mem x s2)} mem x s1 ==> ~(mem x s2)))
[SMTPat (disjoint s1 s2)] | [] | FStar.GSet.disjoint_not_in_both | {
"file_name": "ulib/FStar.GSet.fsti",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | a: Type -> s1: FStar.GSet.set a -> s2: FStar.GSet.set a
-> FStar.Pervasives.Lemma (requires FStar.GSet.disjoint s1 s2)
(ensures
forall (x: a). {:pattern FStar.GSet.mem x s1\/FStar.GSet.mem x s2}
FStar.GSet.mem x s1 ==> ~(FStar.GSet.mem x s2))
[SMTPat (FStar.GSet.disjoint s1 s2)] | {
"end_col": 32,
"end_line": 116,
"start_col": 1,
"start_line": 115
} |
Prims.Tot | val shift_left: v:int -> i:nat -> Tot (res:int{res = v * (pow2 i)}) | [
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Math",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Math",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let shift_left v i =
v * (pow2 i) | val shift_left: v:int -> i:nat -> Tot (res:int{res = v * (pow2 i)})
let shift_left v i = | false | null | false | v * (pow2 i) | {
"checked_file": "FStar.Math.Lib.fst.checked",
"dependencies": [
"prims.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked"
],
"interface_file": false,
"source_file": "FStar.Math.Lib.fst"
} | [
"total"
] | [
"Prims.int",
"Prims.nat",
"FStar.Mul.op_Star",
"Prims.pow2",
"Prims.b2t",
"Prims.op_Equality"
] | [] | (*
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 FStar.Math.Lib
open FStar.Mul
(* Definition of the division operator *)
val lemma_div_def: a:nat -> b:pos -> Lemma (a = b * (a/b) + a % b)
let lemma_div_def a b = ()
private let mul_lemma (a:nat) (b:nat) (c:nat) : Lemma (requires (a <= b))
(ensures (c * a <= c * b))
= ()
private let mul_lemma' (a:nat) (b:nat) (c:pos) : Lemma (requires (c * a <= c * b))
(ensures (a <= b))
= ()
private let mul_div_lemma (a:nat) (b:pos) : Lemma (b * (a / b) <= a) = ()
val slash_decr_axiom: a:nat -> b:pos -> Lemma (a / b <= a)
let slash_decr_axiom a b =
mul_lemma 1 b a;
mul_div_lemma a b;
mul_lemma' (a / b) a b
private let lemma_mul_minus_distr_l (a:int) (b:int) (c:int) : Lemma (a * (b - c) = a * b - a * c)
= ()
(* Axiom: definition of the "b divides c" relation *)
#reset-options "--z3rlimit 30"
val slash_star_axiom: a:nat -> b:pos -> c:nat -> Lemma
(requires (a * b = c))
(ensures (a = c / b))
let slash_star_axiom a b c =
lemma_div_def c b;
lemma_mul_minus_distr_l b a (c/b)
#reset-options
val log_2: x:pos -> Tot nat
let rec log_2 x =
if x >= 2 then 1 + log_2 (x / 2) else 0
(* Function: power of x *)
val powx : x:int -> n:nat -> Tot int
let rec powx x n =
match n with
| 0 -> 1
| n -> x * powx x (n - 1)
(* Function: absolute value *)
val abs: x:int -> Tot (y:int{ (x >= 0 ==> y = x) /\ (x < 0 ==> y = -x) })
let abs x = if x >= 0 then x else -x
(* Function: maximum value *)
val max: x:int -> y:int -> Tot (z:int{ (x >= y ==> z = x) /\ (x < y ==> z = y) })
let max x y = if x >= y then x else y
(* Function: minimum value *)
val min: x:int -> y:int -> Tot (z:int{ (x >= y ==> z = y) /\ (x < y ==> z = x) })
let min x y = if x >= y then y else x
(* Function: standard euclidean division, the rest is always positive *)
val div: a:int -> b:pos -> Tot (c:int{(a < 0 ==> c < 0) /\ (a >= 0 ==> c >= 0)})
let div a b =
if a < 0 then
begin
slash_decr_axiom (-a) b;
if a % b = 0 then - (-a / b)
else - (-a / b) - 1
end
else a / b
(* Function: equivalent of the '/' operator in C, hence the rest can be negative *)
val div_non_eucl: a:int -> b:pos ->
Tot (q:int{ ( a >= 0 ==> q = a / b ) /\ ( a < 0 ==> q = -((-a)/b) ) })
let div_non_eucl a b =
if a < 0 then 0 - ((0 - a) / b)
else a / b
(* The equivalent of the << C operator *)
val shift_left: v:int -> i:nat -> Tot (res:int{res = v * (pow2 i)}) | false | false | FStar.Math.Lib.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val shift_left: v:int -> i:nat -> Tot (res:int{res = v * (pow2 i)}) | [] | FStar.Math.Lib.shift_left | {
"file_name": "ulib/FStar.Math.Lib.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | v: Prims.int -> i: Prims.nat -> res: Prims.int{res = v * Prims.pow2 i} | {
"end_col": 14,
"end_line": 97,
"start_col": 2,
"start_line": 97
} |
Prims.Tot | val arithmetic_shift_right: v:int -> i:nat -> Tot (res:int{ res = div v (pow2 i) }) | [
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Math",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Math",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let arithmetic_shift_right v i =
div v (pow2 i) | val arithmetic_shift_right: v:int -> i:nat -> Tot (res:int{ res = div v (pow2 i) })
let arithmetic_shift_right v i = | false | null | false | div v (pow2 i) | {
"checked_file": "FStar.Math.Lib.fst.checked",
"dependencies": [
"prims.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked"
],
"interface_file": false,
"source_file": "FStar.Math.Lib.fst"
} | [
"total"
] | [
"Prims.int",
"Prims.nat",
"FStar.Math.Lib.div",
"Prims.pow2",
"Prims.b2t",
"Prims.op_Equality"
] | [] | (*
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 FStar.Math.Lib
open FStar.Mul
(* Definition of the division operator *)
val lemma_div_def: a:nat -> b:pos -> Lemma (a = b * (a/b) + a % b)
let lemma_div_def a b = ()
private let mul_lemma (a:nat) (b:nat) (c:nat) : Lemma (requires (a <= b))
(ensures (c * a <= c * b))
= ()
private let mul_lemma' (a:nat) (b:nat) (c:pos) : Lemma (requires (c * a <= c * b))
(ensures (a <= b))
= ()
private let mul_div_lemma (a:nat) (b:pos) : Lemma (b * (a / b) <= a) = ()
val slash_decr_axiom: a:nat -> b:pos -> Lemma (a / b <= a)
let slash_decr_axiom a b =
mul_lemma 1 b a;
mul_div_lemma a b;
mul_lemma' (a / b) a b
private let lemma_mul_minus_distr_l (a:int) (b:int) (c:int) : Lemma (a * (b - c) = a * b - a * c)
= ()
(* Axiom: definition of the "b divides c" relation *)
#reset-options "--z3rlimit 30"
val slash_star_axiom: a:nat -> b:pos -> c:nat -> Lemma
(requires (a * b = c))
(ensures (a = c / b))
let slash_star_axiom a b c =
lemma_div_def c b;
lemma_mul_minus_distr_l b a (c/b)
#reset-options
val log_2: x:pos -> Tot nat
let rec log_2 x =
if x >= 2 then 1 + log_2 (x / 2) else 0
(* Function: power of x *)
val powx : x:int -> n:nat -> Tot int
let rec powx x n =
match n with
| 0 -> 1
| n -> x * powx x (n - 1)
(* Function: absolute value *)
val abs: x:int -> Tot (y:int{ (x >= 0 ==> y = x) /\ (x < 0 ==> y = -x) })
let abs x = if x >= 0 then x else -x
(* Function: maximum value *)
val max: x:int -> y:int -> Tot (z:int{ (x >= y ==> z = x) /\ (x < y ==> z = y) })
let max x y = if x >= y then x else y
(* Function: minimum value *)
val min: x:int -> y:int -> Tot (z:int{ (x >= y ==> z = y) /\ (x < y ==> z = x) })
let min x y = if x >= y then y else x
(* Function: standard euclidean division, the rest is always positive *)
val div: a:int -> b:pos -> Tot (c:int{(a < 0 ==> c < 0) /\ (a >= 0 ==> c >= 0)})
let div a b =
if a < 0 then
begin
slash_decr_axiom (-a) b;
if a % b = 0 then - (-a / b)
else - (-a / b) - 1
end
else a / b
(* Function: equivalent of the '/' operator in C, hence the rest can be negative *)
val div_non_eucl: a:int -> b:pos ->
Tot (q:int{ ( a >= 0 ==> q = a / b ) /\ ( a < 0 ==> q = -((-a)/b) ) })
let div_non_eucl a b =
if a < 0 then 0 - ((0 - a) / b)
else a / b
(* The equivalent of the << C operator *)
val shift_left: v:int -> i:nat -> Tot (res:int{res = v * (pow2 i)})
let shift_left v i =
v * (pow2 i)
(* asr OCaml operator *)
val arithmetic_shift_right: v:int -> i:nat -> Tot (res:int{ res = div v (pow2 i) }) | false | false | FStar.Math.Lib.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val arithmetic_shift_right: v:int -> i:nat -> Tot (res:int{ res = div v (pow2 i) }) | [] | FStar.Math.Lib.arithmetic_shift_right | {
"file_name": "ulib/FStar.Math.Lib.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | v: Prims.int -> i: Prims.nat -> res: Prims.int{res = FStar.Math.Lib.div v (Prims.pow2 i)} | {
"end_col": 16,
"end_line": 102,
"start_col": 2,
"start_line": 102
} |
Prims.Tot | val log_2: x:pos -> Tot nat | [
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Math",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Math",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let rec log_2 x =
if x >= 2 then 1 + log_2 (x / 2) else 0 | val log_2: x:pos -> Tot nat
let rec log_2 x = | false | null | false | if x >= 2 then 1 + log_2 (x / 2) else 0 | {
"checked_file": "FStar.Math.Lib.fst.checked",
"dependencies": [
"prims.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked"
],
"interface_file": false,
"source_file": "FStar.Math.Lib.fst"
} | [
"total"
] | [
"Prims.pos",
"Prims.op_GreaterThanOrEqual",
"Prims.op_Addition",
"FStar.Math.Lib.log_2",
"Prims.op_Division",
"Prims.bool",
"Prims.nat"
] | [] | (*
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 FStar.Math.Lib
open FStar.Mul
(* Definition of the division operator *)
val lemma_div_def: a:nat -> b:pos -> Lemma (a = b * (a/b) + a % b)
let lemma_div_def a b = ()
private let mul_lemma (a:nat) (b:nat) (c:nat) : Lemma (requires (a <= b))
(ensures (c * a <= c * b))
= ()
private let mul_lemma' (a:nat) (b:nat) (c:pos) : Lemma (requires (c * a <= c * b))
(ensures (a <= b))
= ()
private let mul_div_lemma (a:nat) (b:pos) : Lemma (b * (a / b) <= a) = ()
val slash_decr_axiom: a:nat -> b:pos -> Lemma (a / b <= a)
let slash_decr_axiom a b =
mul_lemma 1 b a;
mul_div_lemma a b;
mul_lemma' (a / b) a b
private let lemma_mul_minus_distr_l (a:int) (b:int) (c:int) : Lemma (a * (b - c) = a * b - a * c)
= ()
(* Axiom: definition of the "b divides c" relation *)
#reset-options "--z3rlimit 30"
val slash_star_axiom: a:nat -> b:pos -> c:nat -> Lemma
(requires (a * b = c))
(ensures (a = c / b))
let slash_star_axiom a b c =
lemma_div_def c b;
lemma_mul_minus_distr_l b a (c/b)
#reset-options
val log_2: x:pos -> Tot nat | false | true | FStar.Math.Lib.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val log_2: x:pos -> Tot nat | [
"recursion"
] | FStar.Math.Lib.log_2 | {
"file_name": "ulib/FStar.Math.Lib.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | x: Prims.pos -> Prims.nat | {
"end_col": 41,
"end_line": 55,
"start_col": 2,
"start_line": 55
} |
Prims.Tot | val min: x:int -> y:int -> Tot (z:int{ (x >= y ==> z = y) /\ (x < y ==> z = x) }) | [
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Math",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Math",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let min x y = if x >= y then y else x | val min: x:int -> y:int -> Tot (z:int{ (x >= y ==> z = y) /\ (x < y ==> z = x) })
let min x y = | false | null | false | if x >= y then y else x | {
"checked_file": "FStar.Math.Lib.fst.checked",
"dependencies": [
"prims.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked"
],
"interface_file": false,
"source_file": "FStar.Math.Lib.fst"
} | [
"total"
] | [
"Prims.int",
"Prims.op_GreaterThanOrEqual",
"Prims.bool",
"Prims.l_and",
"Prims.l_imp",
"Prims.b2t",
"Prims.op_Equality",
"Prims.op_LessThan"
] | [] | (*
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 FStar.Math.Lib
open FStar.Mul
(* Definition of the division operator *)
val lemma_div_def: a:nat -> b:pos -> Lemma (a = b * (a/b) + a % b)
let lemma_div_def a b = ()
private let mul_lemma (a:nat) (b:nat) (c:nat) : Lemma (requires (a <= b))
(ensures (c * a <= c * b))
= ()
private let mul_lemma' (a:nat) (b:nat) (c:pos) : Lemma (requires (c * a <= c * b))
(ensures (a <= b))
= ()
private let mul_div_lemma (a:nat) (b:pos) : Lemma (b * (a / b) <= a) = ()
val slash_decr_axiom: a:nat -> b:pos -> Lemma (a / b <= a)
let slash_decr_axiom a b =
mul_lemma 1 b a;
mul_div_lemma a b;
mul_lemma' (a / b) a b
private let lemma_mul_minus_distr_l (a:int) (b:int) (c:int) : Lemma (a * (b - c) = a * b - a * c)
= ()
(* Axiom: definition of the "b divides c" relation *)
#reset-options "--z3rlimit 30"
val slash_star_axiom: a:nat -> b:pos -> c:nat -> Lemma
(requires (a * b = c))
(ensures (a = c / b))
let slash_star_axiom a b c =
lemma_div_def c b;
lemma_mul_minus_distr_l b a (c/b)
#reset-options
val log_2: x:pos -> Tot nat
let rec log_2 x =
if x >= 2 then 1 + log_2 (x / 2) else 0
(* Function: power of x *)
val powx : x:int -> n:nat -> Tot int
let rec powx x n =
match n with
| 0 -> 1
| n -> x * powx x (n - 1)
(* Function: absolute value *)
val abs: x:int -> Tot (y:int{ (x >= 0 ==> y = x) /\ (x < 0 ==> y = -x) })
let abs x = if x >= 0 then x else -x
(* Function: maximum value *)
val max: x:int -> y:int -> Tot (z:int{ (x >= y ==> z = x) /\ (x < y ==> z = y) })
let max x y = if x >= y then x else y
(* Function: minimum value *) | false | false | FStar.Math.Lib.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val min: x:int -> y:int -> Tot (z:int{ (x >= y ==> z = y) /\ (x < y ==> z = x) }) | [] | FStar.Math.Lib.min | {
"file_name": "ulib/FStar.Math.Lib.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | x: Prims.int -> y: Prims.int -> z: Prims.int{(x >= y ==> z = y) /\ (x < y ==> z = x)} | {
"end_col": 37,
"end_line": 74,
"start_col": 14,
"start_line": 74
} |
Prims.Tot | val powx : x:int -> n:nat -> Tot int | [
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Math",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Math",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let rec powx x n =
match n with
| 0 -> 1
| n -> x * powx x (n - 1) | val powx : x:int -> n:nat -> Tot int
let rec powx x n = | false | null | false | match n with
| 0 -> 1
| n -> x * powx x (n - 1) | {
"checked_file": "FStar.Math.Lib.fst.checked",
"dependencies": [
"prims.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked"
],
"interface_file": false,
"source_file": "FStar.Math.Lib.fst"
} | [
"total"
] | [
"Prims.int",
"Prims.nat",
"FStar.Mul.op_Star",
"FStar.Math.Lib.powx",
"Prims.op_Subtraction"
] | [] | (*
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 FStar.Math.Lib
open FStar.Mul
(* Definition of the division operator *)
val lemma_div_def: a:nat -> b:pos -> Lemma (a = b * (a/b) + a % b)
let lemma_div_def a b = ()
private let mul_lemma (a:nat) (b:nat) (c:nat) : Lemma (requires (a <= b))
(ensures (c * a <= c * b))
= ()
private let mul_lemma' (a:nat) (b:nat) (c:pos) : Lemma (requires (c * a <= c * b))
(ensures (a <= b))
= ()
private let mul_div_lemma (a:nat) (b:pos) : Lemma (b * (a / b) <= a) = ()
val slash_decr_axiom: a:nat -> b:pos -> Lemma (a / b <= a)
let slash_decr_axiom a b =
mul_lemma 1 b a;
mul_div_lemma a b;
mul_lemma' (a / b) a b
private let lemma_mul_minus_distr_l (a:int) (b:int) (c:int) : Lemma (a * (b - c) = a * b - a * c)
= ()
(* Axiom: definition of the "b divides c" relation *)
#reset-options "--z3rlimit 30"
val slash_star_axiom: a:nat -> b:pos -> c:nat -> Lemma
(requires (a * b = c))
(ensures (a = c / b))
let slash_star_axiom a b c =
lemma_div_def c b;
lemma_mul_minus_distr_l b a (c/b)
#reset-options
val log_2: x:pos -> Tot nat
let rec log_2 x =
if x >= 2 then 1 + log_2 (x / 2) else 0
(* Function: power of x *)
val powx : x:int -> n:nat -> Tot int | false | true | FStar.Math.Lib.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val powx : x:int -> n:nat -> Tot int | [
"recursion"
] | FStar.Math.Lib.powx | {
"file_name": "ulib/FStar.Math.Lib.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | x: Prims.int -> n: Prims.nat -> Prims.int | {
"end_col": 27,
"end_line": 62,
"start_col": 2,
"start_line": 60
} |
Prims.Tot | val max: x:int -> y:int -> Tot (z:int{ (x >= y ==> z = x) /\ (x < y ==> z = y) }) | [
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Math",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Math",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let max x y = if x >= y then x else y | val max: x:int -> y:int -> Tot (z:int{ (x >= y ==> z = x) /\ (x < y ==> z = y) })
let max x y = | false | null | false | if x >= y then x else y | {
"checked_file": "FStar.Math.Lib.fst.checked",
"dependencies": [
"prims.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked"
],
"interface_file": false,
"source_file": "FStar.Math.Lib.fst"
} | [
"total"
] | [
"Prims.int",
"Prims.op_GreaterThanOrEqual",
"Prims.bool",
"Prims.l_and",
"Prims.l_imp",
"Prims.b2t",
"Prims.op_Equality",
"Prims.op_LessThan"
] | [] | (*
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 FStar.Math.Lib
open FStar.Mul
(* Definition of the division operator *)
val lemma_div_def: a:nat -> b:pos -> Lemma (a = b * (a/b) + a % b)
let lemma_div_def a b = ()
private let mul_lemma (a:nat) (b:nat) (c:nat) : Lemma (requires (a <= b))
(ensures (c * a <= c * b))
= ()
private let mul_lemma' (a:nat) (b:nat) (c:pos) : Lemma (requires (c * a <= c * b))
(ensures (a <= b))
= ()
private let mul_div_lemma (a:nat) (b:pos) : Lemma (b * (a / b) <= a) = ()
val slash_decr_axiom: a:nat -> b:pos -> Lemma (a / b <= a)
let slash_decr_axiom a b =
mul_lemma 1 b a;
mul_div_lemma a b;
mul_lemma' (a / b) a b
private let lemma_mul_minus_distr_l (a:int) (b:int) (c:int) : Lemma (a * (b - c) = a * b - a * c)
= ()
(* Axiom: definition of the "b divides c" relation *)
#reset-options "--z3rlimit 30"
val slash_star_axiom: a:nat -> b:pos -> c:nat -> Lemma
(requires (a * b = c))
(ensures (a = c / b))
let slash_star_axiom a b c =
lemma_div_def c b;
lemma_mul_minus_distr_l b a (c/b)
#reset-options
val log_2: x:pos -> Tot nat
let rec log_2 x =
if x >= 2 then 1 + log_2 (x / 2) else 0
(* Function: power of x *)
val powx : x:int -> n:nat -> Tot int
let rec powx x n =
match n with
| 0 -> 1
| n -> x * powx x (n - 1)
(* Function: absolute value *)
val abs: x:int -> Tot (y:int{ (x >= 0 ==> y = x) /\ (x < 0 ==> y = -x) })
let abs x = if x >= 0 then x else -x
(* Function: maximum value *) | false | false | FStar.Math.Lib.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val max: x:int -> y:int -> Tot (z:int{ (x >= y ==> z = x) /\ (x < y ==> z = y) }) | [] | FStar.Math.Lib.max | {
"file_name": "ulib/FStar.Math.Lib.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | x: Prims.int -> y: Prims.int -> z: Prims.int{(x >= y ==> z = x) /\ (x < y ==> z = y)} | {
"end_col": 37,
"end_line": 70,
"start_col": 14,
"start_line": 70
} |
Prims.Tot | val abs: x:int -> Tot (y:int{ (x >= 0 ==> y = x) /\ (x < 0 ==> y = -x) }) | [
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Math",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Math",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let abs x = if x >= 0 then x else -x | val abs: x:int -> Tot (y:int{ (x >= 0 ==> y = x) /\ (x < 0 ==> y = -x) })
let abs x = | false | null | false | if x >= 0 then x else - x | {
"checked_file": "FStar.Math.Lib.fst.checked",
"dependencies": [
"prims.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked"
],
"interface_file": false,
"source_file": "FStar.Math.Lib.fst"
} | [
"total"
] | [
"Prims.int",
"Prims.op_GreaterThanOrEqual",
"Prims.bool",
"Prims.op_Minus",
"Prims.l_and",
"Prims.l_imp",
"Prims.b2t",
"Prims.op_Equality",
"Prims.op_LessThan"
] | [] | (*
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 FStar.Math.Lib
open FStar.Mul
(* Definition of the division operator *)
val lemma_div_def: a:nat -> b:pos -> Lemma (a = b * (a/b) + a % b)
let lemma_div_def a b = ()
private let mul_lemma (a:nat) (b:nat) (c:nat) : Lemma (requires (a <= b))
(ensures (c * a <= c * b))
= ()
private let mul_lemma' (a:nat) (b:nat) (c:pos) : Lemma (requires (c * a <= c * b))
(ensures (a <= b))
= ()
private let mul_div_lemma (a:nat) (b:pos) : Lemma (b * (a / b) <= a) = ()
val slash_decr_axiom: a:nat -> b:pos -> Lemma (a / b <= a)
let slash_decr_axiom a b =
mul_lemma 1 b a;
mul_div_lemma a b;
mul_lemma' (a / b) a b
private let lemma_mul_minus_distr_l (a:int) (b:int) (c:int) : Lemma (a * (b - c) = a * b - a * c)
= ()
(* Axiom: definition of the "b divides c" relation *)
#reset-options "--z3rlimit 30"
val slash_star_axiom: a:nat -> b:pos -> c:nat -> Lemma
(requires (a * b = c))
(ensures (a = c / b))
let slash_star_axiom a b c =
lemma_div_def c b;
lemma_mul_minus_distr_l b a (c/b)
#reset-options
val log_2: x:pos -> Tot nat
let rec log_2 x =
if x >= 2 then 1 + log_2 (x / 2) else 0
(* Function: power of x *)
val powx : x:int -> n:nat -> Tot int
let rec powx x n =
match n with
| 0 -> 1
| n -> x * powx x (n - 1)
(* Function: absolute value *) | false | false | FStar.Math.Lib.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val abs: x:int -> Tot (y:int{ (x >= 0 ==> y = x) /\ (x < 0 ==> y = -x) }) | [] | FStar.Math.Lib.abs | {
"file_name": "ulib/FStar.Math.Lib.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | x: Prims.int -> y: Prims.int{(x >= 0 ==> y = x) /\ (x < 0 ==> y = - x)} | {
"end_col": 36,
"end_line": 66,
"start_col": 12,
"start_line": 66
} |
Prims.Tot | val signed_modulo: v:int -> p:pos -> Tot (res:int{ res = v - ((div_non_eucl v p) * p) }) | [
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Math",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Math",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let signed_modulo v p =
if v >= 0 then v % p
else 0 - ( (0-v) % p) | val signed_modulo: v:int -> p:pos -> Tot (res:int{ res = v - ((div_non_eucl v p) * p) })
let signed_modulo v p = | false | null | false | if v >= 0 then v % p else 0 - ((0 - v) % p) | {
"checked_file": "FStar.Math.Lib.fst.checked",
"dependencies": [
"prims.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked"
],
"interface_file": false,
"source_file": "FStar.Math.Lib.fst"
} | [
"total"
] | [
"Prims.int",
"Prims.pos",
"Prims.op_GreaterThanOrEqual",
"Prims.op_Modulus",
"Prims.bool",
"Prims.op_Subtraction",
"Prims.b2t",
"Prims.op_Equality",
"FStar.Mul.op_Star",
"FStar.Math.Lib.div_non_eucl"
] | [] | (*
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 FStar.Math.Lib
open FStar.Mul
(* Definition of the division operator *)
val lemma_div_def: a:nat -> b:pos -> Lemma (a = b * (a/b) + a % b)
let lemma_div_def a b = ()
private let mul_lemma (a:nat) (b:nat) (c:nat) : Lemma (requires (a <= b))
(ensures (c * a <= c * b))
= ()
private let mul_lemma' (a:nat) (b:nat) (c:pos) : Lemma (requires (c * a <= c * b))
(ensures (a <= b))
= ()
private let mul_div_lemma (a:nat) (b:pos) : Lemma (b * (a / b) <= a) = ()
val slash_decr_axiom: a:nat -> b:pos -> Lemma (a / b <= a)
let slash_decr_axiom a b =
mul_lemma 1 b a;
mul_div_lemma a b;
mul_lemma' (a / b) a b
private let lemma_mul_minus_distr_l (a:int) (b:int) (c:int) : Lemma (a * (b - c) = a * b - a * c)
= ()
(* Axiom: definition of the "b divides c" relation *)
#reset-options "--z3rlimit 30"
val slash_star_axiom: a:nat -> b:pos -> c:nat -> Lemma
(requires (a * b = c))
(ensures (a = c / b))
let slash_star_axiom a b c =
lemma_div_def c b;
lemma_mul_minus_distr_l b a (c/b)
#reset-options
val log_2: x:pos -> Tot nat
let rec log_2 x =
if x >= 2 then 1 + log_2 (x / 2) else 0
(* Function: power of x *)
val powx : x:int -> n:nat -> Tot int
let rec powx x n =
match n with
| 0 -> 1
| n -> x * powx x (n - 1)
(* Function: absolute value *)
val abs: x:int -> Tot (y:int{ (x >= 0 ==> y = x) /\ (x < 0 ==> y = -x) })
let abs x = if x >= 0 then x else -x
(* Function: maximum value *)
val max: x:int -> y:int -> Tot (z:int{ (x >= y ==> z = x) /\ (x < y ==> z = y) })
let max x y = if x >= y then x else y
(* Function: minimum value *)
val min: x:int -> y:int -> Tot (z:int{ (x >= y ==> z = y) /\ (x < y ==> z = x) })
let min x y = if x >= y then y else x
(* Function: standard euclidean division, the rest is always positive *)
val div: a:int -> b:pos -> Tot (c:int{(a < 0 ==> c < 0) /\ (a >= 0 ==> c >= 0)})
let div a b =
if a < 0 then
begin
slash_decr_axiom (-a) b;
if a % b = 0 then - (-a / b)
else - (-a / b) - 1
end
else a / b
(* Function: equivalent of the '/' operator in C, hence the rest can be negative *)
val div_non_eucl: a:int -> b:pos ->
Tot (q:int{ ( a >= 0 ==> q = a / b ) /\ ( a < 0 ==> q = -((-a)/b) ) })
let div_non_eucl a b =
if a < 0 then 0 - ((0 - a) / b)
else a / b
(* The equivalent of the << C operator *)
val shift_left: v:int -> i:nat -> Tot (res:int{res = v * (pow2 i)})
let shift_left v i =
v * (pow2 i)
(* asr OCaml operator *)
val arithmetic_shift_right: v:int -> i:nat -> Tot (res:int{ res = div v (pow2 i) })
let arithmetic_shift_right v i =
div v (pow2 i)
(* Case of C cast functions ? *)
(* Implemented by "mod" in OCaml *)
val signed_modulo: v:int -> p:pos -> Tot (res:int{ res = v - ((div_non_eucl v p) * p) }) | false | false | FStar.Math.Lib.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val signed_modulo: v:int -> p:pos -> Tot (res:int{ res = v - ((div_non_eucl v p) * p) }) | [] | FStar.Math.Lib.signed_modulo | {
"file_name": "ulib/FStar.Math.Lib.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | v: Prims.int -> p: Prims.pos -> res: Prims.int{res = v - FStar.Math.Lib.div_non_eucl v p * p} | {
"end_col": 23,
"end_line": 109,
"start_col": 2,
"start_line": 108
} |
FStar.Pervasives.Lemma | val div_non_eucl_decr_lemma: a:int -> b:pos -> Lemma (abs (div_non_eucl a b) <= abs a) | [
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Math",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Math",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let div_non_eucl_decr_lemma a b =
slash_decr_axiom (abs a) b | val div_non_eucl_decr_lemma: a:int -> b:pos -> Lemma (abs (div_non_eucl a b) <= abs a)
let div_non_eucl_decr_lemma a b = | false | null | true | slash_decr_axiom (abs a) b | {
"checked_file": "FStar.Math.Lib.fst.checked",
"dependencies": [
"prims.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked"
],
"interface_file": false,
"source_file": "FStar.Math.Lib.fst"
} | [
"lemma"
] | [
"Prims.int",
"Prims.pos",
"FStar.Math.Lib.slash_decr_axiom",
"FStar.Math.Lib.abs",
"Prims.unit"
] | [] | (*
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 FStar.Math.Lib
open FStar.Mul
(* Definition of the division operator *)
val lemma_div_def: a:nat -> b:pos -> Lemma (a = b * (a/b) + a % b)
let lemma_div_def a b = ()
private let mul_lemma (a:nat) (b:nat) (c:nat) : Lemma (requires (a <= b))
(ensures (c * a <= c * b))
= ()
private let mul_lemma' (a:nat) (b:nat) (c:pos) : Lemma (requires (c * a <= c * b))
(ensures (a <= b))
= ()
private let mul_div_lemma (a:nat) (b:pos) : Lemma (b * (a / b) <= a) = ()
val slash_decr_axiom: a:nat -> b:pos -> Lemma (a / b <= a)
let slash_decr_axiom a b =
mul_lemma 1 b a;
mul_div_lemma a b;
mul_lemma' (a / b) a b
private let lemma_mul_minus_distr_l (a:int) (b:int) (c:int) : Lemma (a * (b - c) = a * b - a * c)
= ()
(* Axiom: definition of the "b divides c" relation *)
#reset-options "--z3rlimit 30"
val slash_star_axiom: a:nat -> b:pos -> c:nat -> Lemma
(requires (a * b = c))
(ensures (a = c / b))
let slash_star_axiom a b c =
lemma_div_def c b;
lemma_mul_minus_distr_l b a (c/b)
#reset-options
val log_2: x:pos -> Tot nat
let rec log_2 x =
if x >= 2 then 1 + log_2 (x / 2) else 0
(* Function: power of x *)
val powx : x:int -> n:nat -> Tot int
let rec powx x n =
match n with
| 0 -> 1
| n -> x * powx x (n - 1)
(* Function: absolute value *)
val abs: x:int -> Tot (y:int{ (x >= 0 ==> y = x) /\ (x < 0 ==> y = -x) })
let abs x = if x >= 0 then x else -x
(* Function: maximum value *)
val max: x:int -> y:int -> Tot (z:int{ (x >= y ==> z = x) /\ (x < y ==> z = y) })
let max x y = if x >= y then x else y
(* Function: minimum value *)
val min: x:int -> y:int -> Tot (z:int{ (x >= y ==> z = y) /\ (x < y ==> z = x) })
let min x y = if x >= y then y else x
(* Function: standard euclidean division, the rest is always positive *)
val div: a:int -> b:pos -> Tot (c:int{(a < 0 ==> c < 0) /\ (a >= 0 ==> c >= 0)})
let div a b =
if a < 0 then
begin
slash_decr_axiom (-a) b;
if a % b = 0 then - (-a / b)
else - (-a / b) - 1
end
else a / b
(* Function: equivalent of the '/' operator in C, hence the rest can be negative *)
val div_non_eucl: a:int -> b:pos ->
Tot (q:int{ ( a >= 0 ==> q = a / b ) /\ ( a < 0 ==> q = -((-a)/b) ) })
let div_non_eucl a b =
if a < 0 then 0 - ((0 - a) / b)
else a / b
(* The equivalent of the << C operator *)
val shift_left: v:int -> i:nat -> Tot (res:int{res = v * (pow2 i)})
let shift_left v i =
v * (pow2 i)
(* asr OCaml operator *)
val arithmetic_shift_right: v:int -> i:nat -> Tot (res:int{ res = div v (pow2 i) })
let arithmetic_shift_right v i =
div v (pow2 i)
(* Case of C cast functions ? *)
(* Implemented by "mod" in OCaml *)
val signed_modulo: v:int -> p:pos -> Tot (res:int{ res = v - ((div_non_eucl v p) * p) })
let signed_modulo v p =
if v >= 0 then v % p
else 0 - ( (0-v) % p)
val op_Plus_Percent : a:int -> p:pos ->
Tot (res:int{ (a >= 0 ==> res = a % p) /\ (a < 0 ==> res = -((-a) % p)) })
let op_Plus_Percent a p = signed_modulo a p
(** Useful lemmas for future proofs **)
(* Lemmas of x^n *)
val powx_lemma1: a:int -> Lemma (powx a 1 = a)
let powx_lemma1 a = ()
val powx_lemma2: x:int -> n:nat -> m:nat -> Lemma
(powx x n * powx x m = powx x (n + m))
let rec powx_lemma2 x n m =
let ass (x y z : int) : Lemma ((x*y)*z == x*(y*z)) = () in
match n with
| 0 -> ()
| _ -> powx_lemma2 x (n-1) m; ass x (powx x (n-1)) (powx x m)
(* Lemma: absolute value of product is the product of the absolute values *)
val abs_mul_lemma: a:int -> b:int -> Lemma (abs (a * b) = abs a * abs b)
let abs_mul_lemma a b = ()
(* Lemma: absolute value of a signed_module b is bounded by b *)
val signed_modulo_property: v:int -> p:pos -> Lemma (abs (signed_modulo v p ) < p)
let signed_modulo_property v p = ()
(* Lemma: non-Euclidean division has a smaller output compared to its input *)
val div_non_eucl_decr_lemma: a:int -> b:pos -> Lemma (abs (div_non_eucl a b) <= abs a) | false | false | FStar.Math.Lib.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val div_non_eucl_decr_lemma: a:int -> b:pos -> Lemma (abs (div_non_eucl a b) <= abs a) | [] | FStar.Math.Lib.div_non_eucl_decr_lemma | {
"file_name": "ulib/FStar.Math.Lib.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | a: Prims.int -> b: Prims.pos
-> FStar.Pervasives.Lemma
(ensures FStar.Math.Lib.abs (FStar.Math.Lib.div_non_eucl a b) <= FStar.Math.Lib.abs a) | {
"end_col": 28,
"end_line": 140,
"start_col": 2,
"start_line": 140
} |
FStar.Pervasives.Lemma | val slash_decr_axiom: a:nat -> b:pos -> Lemma (a / b <= a) | [
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Math",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Math",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let slash_decr_axiom a b =
mul_lemma 1 b a;
mul_div_lemma a b;
mul_lemma' (a / b) a b | val slash_decr_axiom: a:nat -> b:pos -> Lemma (a / b <= a)
let slash_decr_axiom a b = | false | null | true | mul_lemma 1 b a;
mul_div_lemma a b;
mul_lemma' (a / b) a b | {
"checked_file": "FStar.Math.Lib.fst.checked",
"dependencies": [
"prims.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked"
],
"interface_file": false,
"source_file": "FStar.Math.Lib.fst"
} | [
"lemma"
] | [
"Prims.nat",
"Prims.pos",
"FStar.Math.Lib.mul_lemma'",
"Prims.op_Division",
"Prims.unit",
"FStar.Math.Lib.mul_div_lemma",
"FStar.Math.Lib.mul_lemma"
] | [] | (*
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 FStar.Math.Lib
open FStar.Mul
(* Definition of the division operator *)
val lemma_div_def: a:nat -> b:pos -> Lemma (a = b * (a/b) + a % b)
let lemma_div_def a b = ()
private let mul_lemma (a:nat) (b:nat) (c:nat) : Lemma (requires (a <= b))
(ensures (c * a <= c * b))
= ()
private let mul_lemma' (a:nat) (b:nat) (c:pos) : Lemma (requires (c * a <= c * b))
(ensures (a <= b))
= ()
private let mul_div_lemma (a:nat) (b:pos) : Lemma (b * (a / b) <= a) = ()
val slash_decr_axiom: a:nat -> b:pos -> Lemma (a / b <= a) | false | false | FStar.Math.Lib.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val slash_decr_axiom: a:nat -> b:pos -> Lemma (a / b <= a) | [] | FStar.Math.Lib.slash_decr_axiom | {
"file_name": "ulib/FStar.Math.Lib.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | a: Prims.nat -> b: Prims.pos -> FStar.Pervasives.Lemma (ensures a / b <= a) | {
"end_col": 26,
"end_line": 38,
"start_col": 4,
"start_line": 36
} |
Prims.Tot | val op_Plus_Percent : a:int -> p:pos ->
Tot (res:int{ (a >= 0 ==> res = a % p) /\ (a < 0 ==> res = -((-a) % p)) }) | [
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Math",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Math",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let op_Plus_Percent a p = signed_modulo a p | val op_Plus_Percent : a:int -> p:pos ->
Tot (res:int{ (a >= 0 ==> res = a % p) /\ (a < 0 ==> res = -((-a) % p)) })
let op_Plus_Percent a p = | false | null | false | signed_modulo a p | {
"checked_file": "FStar.Math.Lib.fst.checked",
"dependencies": [
"prims.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked"
],
"interface_file": false,
"source_file": "FStar.Math.Lib.fst"
} | [
"total"
] | [
"Prims.int",
"Prims.pos",
"FStar.Math.Lib.signed_modulo",
"Prims.l_and",
"Prims.l_imp",
"Prims.b2t",
"Prims.op_GreaterThanOrEqual",
"Prims.op_Equality",
"Prims.op_Modulus",
"Prims.op_LessThan",
"Prims.op_Minus"
] | [] | (*
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 FStar.Math.Lib
open FStar.Mul
(* Definition of the division operator *)
val lemma_div_def: a:nat -> b:pos -> Lemma (a = b * (a/b) + a % b)
let lemma_div_def a b = ()
private let mul_lemma (a:nat) (b:nat) (c:nat) : Lemma (requires (a <= b))
(ensures (c * a <= c * b))
= ()
private let mul_lemma' (a:nat) (b:nat) (c:pos) : Lemma (requires (c * a <= c * b))
(ensures (a <= b))
= ()
private let mul_div_lemma (a:nat) (b:pos) : Lemma (b * (a / b) <= a) = ()
val slash_decr_axiom: a:nat -> b:pos -> Lemma (a / b <= a)
let slash_decr_axiom a b =
mul_lemma 1 b a;
mul_div_lemma a b;
mul_lemma' (a / b) a b
private let lemma_mul_minus_distr_l (a:int) (b:int) (c:int) : Lemma (a * (b - c) = a * b - a * c)
= ()
(* Axiom: definition of the "b divides c" relation *)
#reset-options "--z3rlimit 30"
val slash_star_axiom: a:nat -> b:pos -> c:nat -> Lemma
(requires (a * b = c))
(ensures (a = c / b))
let slash_star_axiom a b c =
lemma_div_def c b;
lemma_mul_minus_distr_l b a (c/b)
#reset-options
val log_2: x:pos -> Tot nat
let rec log_2 x =
if x >= 2 then 1 + log_2 (x / 2) else 0
(* Function: power of x *)
val powx : x:int -> n:nat -> Tot int
let rec powx x n =
match n with
| 0 -> 1
| n -> x * powx x (n - 1)
(* Function: absolute value *)
val abs: x:int -> Tot (y:int{ (x >= 0 ==> y = x) /\ (x < 0 ==> y = -x) })
let abs x = if x >= 0 then x else -x
(* Function: maximum value *)
val max: x:int -> y:int -> Tot (z:int{ (x >= y ==> z = x) /\ (x < y ==> z = y) })
let max x y = if x >= y then x else y
(* Function: minimum value *)
val min: x:int -> y:int -> Tot (z:int{ (x >= y ==> z = y) /\ (x < y ==> z = x) })
let min x y = if x >= y then y else x
(* Function: standard euclidean division, the rest is always positive *)
val div: a:int -> b:pos -> Tot (c:int{(a < 0 ==> c < 0) /\ (a >= 0 ==> c >= 0)})
let div a b =
if a < 0 then
begin
slash_decr_axiom (-a) b;
if a % b = 0 then - (-a / b)
else - (-a / b) - 1
end
else a / b
(* Function: equivalent of the '/' operator in C, hence the rest can be negative *)
val div_non_eucl: a:int -> b:pos ->
Tot (q:int{ ( a >= 0 ==> q = a / b ) /\ ( a < 0 ==> q = -((-a)/b) ) })
let div_non_eucl a b =
if a < 0 then 0 - ((0 - a) / b)
else a / b
(* The equivalent of the << C operator *)
val shift_left: v:int -> i:nat -> Tot (res:int{res = v * (pow2 i)})
let shift_left v i =
v * (pow2 i)
(* asr OCaml operator *)
val arithmetic_shift_right: v:int -> i:nat -> Tot (res:int{ res = div v (pow2 i) })
let arithmetic_shift_right v i =
div v (pow2 i)
(* Case of C cast functions ? *)
(* Implemented by "mod" in OCaml *)
val signed_modulo: v:int -> p:pos -> Tot (res:int{ res = v - ((div_non_eucl v p) * p) })
let signed_modulo v p =
if v >= 0 then v % p
else 0 - ( (0-v) % p)
val op_Plus_Percent : a:int -> p:pos -> | false | false | FStar.Math.Lib.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val op_Plus_Percent : a:int -> p:pos ->
Tot (res:int{ (a >= 0 ==> res = a % p) /\ (a < 0 ==> res = -((-a) % p)) }) | [] | FStar.Math.Lib.op_Plus_Percent | {
"file_name": "ulib/FStar.Math.Lib.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | a: Prims.int -> p: Prims.pos
-> res: Prims.int{(a >= 0 ==> res = a % p) /\ (a < 0 ==> res = - (- a) % p)} | {
"end_col": 43,
"end_line": 113,
"start_col": 26,
"start_line": 113
} |
Prims.Tot | val div: a:int -> b:pos -> Tot (c:int{(a < 0 ==> c < 0) /\ (a >= 0 ==> c >= 0)}) | [
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Math",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Math",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let div a b =
if a < 0 then
begin
slash_decr_axiom (-a) b;
if a % b = 0 then - (-a / b)
else - (-a / b) - 1
end
else a / b | val div: a:int -> b:pos -> Tot (c:int{(a < 0 ==> c < 0) /\ (a >= 0 ==> c >= 0)})
let div a b = | false | null | false | if a < 0
then
(slash_decr_axiom (- a) b;
if a % b = 0 then - (- a / b) else - (- a / b) - 1)
else a / b | {
"checked_file": "FStar.Math.Lib.fst.checked",
"dependencies": [
"prims.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked"
],
"interface_file": false,
"source_file": "FStar.Math.Lib.fst"
} | [
"total"
] | [
"Prims.int",
"Prims.pos",
"Prims.op_LessThan",
"Prims.op_Equality",
"Prims.op_Modulus",
"Prims.op_Minus",
"Prims.op_Division",
"Prims.bool",
"Prims.op_Subtraction",
"Prims.l_and",
"Prims.l_imp",
"Prims.b2t",
"Prims.op_GreaterThanOrEqual",
"Prims.unit",
"FStar.Math.Lib.slash_decr_axiom"
] | [] | (*
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 FStar.Math.Lib
open FStar.Mul
(* Definition of the division operator *)
val lemma_div_def: a:nat -> b:pos -> Lemma (a = b * (a/b) + a % b)
let lemma_div_def a b = ()
private let mul_lemma (a:nat) (b:nat) (c:nat) : Lemma (requires (a <= b))
(ensures (c * a <= c * b))
= ()
private let mul_lemma' (a:nat) (b:nat) (c:pos) : Lemma (requires (c * a <= c * b))
(ensures (a <= b))
= ()
private let mul_div_lemma (a:nat) (b:pos) : Lemma (b * (a / b) <= a) = ()
val slash_decr_axiom: a:nat -> b:pos -> Lemma (a / b <= a)
let slash_decr_axiom a b =
mul_lemma 1 b a;
mul_div_lemma a b;
mul_lemma' (a / b) a b
private let lemma_mul_minus_distr_l (a:int) (b:int) (c:int) : Lemma (a * (b - c) = a * b - a * c)
= ()
(* Axiom: definition of the "b divides c" relation *)
#reset-options "--z3rlimit 30"
val slash_star_axiom: a:nat -> b:pos -> c:nat -> Lemma
(requires (a * b = c))
(ensures (a = c / b))
let slash_star_axiom a b c =
lemma_div_def c b;
lemma_mul_minus_distr_l b a (c/b)
#reset-options
val log_2: x:pos -> Tot nat
let rec log_2 x =
if x >= 2 then 1 + log_2 (x / 2) else 0
(* Function: power of x *)
val powx : x:int -> n:nat -> Tot int
let rec powx x n =
match n with
| 0 -> 1
| n -> x * powx x (n - 1)
(* Function: absolute value *)
val abs: x:int -> Tot (y:int{ (x >= 0 ==> y = x) /\ (x < 0 ==> y = -x) })
let abs x = if x >= 0 then x else -x
(* Function: maximum value *)
val max: x:int -> y:int -> Tot (z:int{ (x >= y ==> z = x) /\ (x < y ==> z = y) })
let max x y = if x >= y then x else y
(* Function: minimum value *)
val min: x:int -> y:int -> Tot (z:int{ (x >= y ==> z = y) /\ (x < y ==> z = x) })
let min x y = if x >= y then y else x
(* Function: standard euclidean division, the rest is always positive *)
val div: a:int -> b:pos -> Tot (c:int{(a < 0 ==> c < 0) /\ (a >= 0 ==> c >= 0)}) | false | false | FStar.Math.Lib.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val div: a:int -> b:pos -> Tot (c:int{(a < 0 ==> c < 0) /\ (a >= 0 ==> c >= 0)}) | [] | FStar.Math.Lib.div | {
"file_name": "ulib/FStar.Math.Lib.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | a: Prims.int -> b: Prims.pos -> c: Prims.int{(a < 0 ==> c < 0) /\ (a >= 0 ==> c >= 0)} | {
"end_col": 12,
"end_line": 85,
"start_col": 2,
"start_line": 79
} |
Prims.Tot | val div_non_eucl: a:int -> b:pos ->
Tot (q:int{ ( a >= 0 ==> q = a / b ) /\ ( a < 0 ==> q = -((-a)/b) ) }) | [
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Math",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Math",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let div_non_eucl a b =
if a < 0 then 0 - ((0 - a) / b)
else a / b | val div_non_eucl: a:int -> b:pos ->
Tot (q:int{ ( a >= 0 ==> q = a / b ) /\ ( a < 0 ==> q = -((-a)/b) ) })
let div_non_eucl a b = | false | null | false | if a < 0 then 0 - ((0 - a) / b) else a / b | {
"checked_file": "FStar.Math.Lib.fst.checked",
"dependencies": [
"prims.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked"
],
"interface_file": false,
"source_file": "FStar.Math.Lib.fst"
} | [
"total"
] | [
"Prims.int",
"Prims.pos",
"Prims.op_LessThan",
"Prims.op_Subtraction",
"Prims.op_Division",
"Prims.bool",
"Prims.l_and",
"Prims.l_imp",
"Prims.b2t",
"Prims.op_GreaterThanOrEqual",
"Prims.op_Equality",
"Prims.op_Minus"
] | [] | (*
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 FStar.Math.Lib
open FStar.Mul
(* Definition of the division operator *)
val lemma_div_def: a:nat -> b:pos -> Lemma (a = b * (a/b) + a % b)
let lemma_div_def a b = ()
private let mul_lemma (a:nat) (b:nat) (c:nat) : Lemma (requires (a <= b))
(ensures (c * a <= c * b))
= ()
private let mul_lemma' (a:nat) (b:nat) (c:pos) : Lemma (requires (c * a <= c * b))
(ensures (a <= b))
= ()
private let mul_div_lemma (a:nat) (b:pos) : Lemma (b * (a / b) <= a) = ()
val slash_decr_axiom: a:nat -> b:pos -> Lemma (a / b <= a)
let slash_decr_axiom a b =
mul_lemma 1 b a;
mul_div_lemma a b;
mul_lemma' (a / b) a b
private let lemma_mul_minus_distr_l (a:int) (b:int) (c:int) : Lemma (a * (b - c) = a * b - a * c)
= ()
(* Axiom: definition of the "b divides c" relation *)
#reset-options "--z3rlimit 30"
val slash_star_axiom: a:nat -> b:pos -> c:nat -> Lemma
(requires (a * b = c))
(ensures (a = c / b))
let slash_star_axiom a b c =
lemma_div_def c b;
lemma_mul_minus_distr_l b a (c/b)
#reset-options
val log_2: x:pos -> Tot nat
let rec log_2 x =
if x >= 2 then 1 + log_2 (x / 2) else 0
(* Function: power of x *)
val powx : x:int -> n:nat -> Tot int
let rec powx x n =
match n with
| 0 -> 1
| n -> x * powx x (n - 1)
(* Function: absolute value *)
val abs: x:int -> Tot (y:int{ (x >= 0 ==> y = x) /\ (x < 0 ==> y = -x) })
let abs x = if x >= 0 then x else -x
(* Function: maximum value *)
val max: x:int -> y:int -> Tot (z:int{ (x >= y ==> z = x) /\ (x < y ==> z = y) })
let max x y = if x >= y then x else y
(* Function: minimum value *)
val min: x:int -> y:int -> Tot (z:int{ (x >= y ==> z = y) /\ (x < y ==> z = x) })
let min x y = if x >= y then y else x
(* Function: standard euclidean division, the rest is always positive *)
val div: a:int -> b:pos -> Tot (c:int{(a < 0 ==> c < 0) /\ (a >= 0 ==> c >= 0)})
let div a b =
if a < 0 then
begin
slash_decr_axiom (-a) b;
if a % b = 0 then - (-a / b)
else - (-a / b) - 1
end
else a / b
(* Function: equivalent of the '/' operator in C, hence the rest can be negative *)
val div_non_eucl: a:int -> b:pos ->
Tot (q:int{ ( a >= 0 ==> q = a / b ) /\ ( a < 0 ==> q = -((-a)/b) ) }) | false | false | FStar.Math.Lib.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val div_non_eucl: a:int -> b:pos ->
Tot (q:int{ ( a >= 0 ==> q = a / b ) /\ ( a < 0 ==> q = -((-a)/b) ) }) | [] | FStar.Math.Lib.div_non_eucl | {
"file_name": "ulib/FStar.Math.Lib.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | a: Prims.int -> b: Prims.pos -> q: Prims.int{(a >= 0 ==> q = a / b) /\ (a < 0 ==> q = - (- a) / b)} | {
"end_col": 12,
"end_line": 92,
"start_col": 2,
"start_line": 91
} |
FStar.Pervasives.Lemma | val powx_lemma2: x:int -> n:nat -> m:nat -> Lemma
(powx x n * powx x m = powx x (n + m)) | [
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Math",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Math",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let rec powx_lemma2 x n m =
let ass (x y z : int) : Lemma ((x*y)*z == x*(y*z)) = () in
match n with
| 0 -> ()
| _ -> powx_lemma2 x (n-1) m; ass x (powx x (n-1)) (powx x m) | val powx_lemma2: x:int -> n:nat -> m:nat -> Lemma
(powx x n * powx x m = powx x (n + m))
let rec powx_lemma2 x n m = | false | null | true | let ass (x y z: int) : Lemma ((x * y) * z == x * (y * z)) = () in
match n with
| 0 -> ()
| _ ->
powx_lemma2 x (n - 1) m;
ass x (powx x (n - 1)) (powx x m) | {
"checked_file": "FStar.Math.Lib.fst.checked",
"dependencies": [
"prims.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked"
],
"interface_file": false,
"source_file": "FStar.Math.Lib.fst"
} | [
"lemma"
] | [
"Prims.int",
"Prims.nat",
"FStar.Math.Lib.powx",
"Prims.op_Subtraction",
"Prims.unit",
"FStar.Math.Lib.powx_lemma2",
"Prims.l_True",
"Prims.squash",
"Prims.eq2",
"Prims.op_Multiply",
"Prims.Nil",
"FStar.Pervasives.pattern",
"FStar.Mul.op_Star"
] | [] | (*
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 FStar.Math.Lib
open FStar.Mul
(* Definition of the division operator *)
val lemma_div_def: a:nat -> b:pos -> Lemma (a = b * (a/b) + a % b)
let lemma_div_def a b = ()
private let mul_lemma (a:nat) (b:nat) (c:nat) : Lemma (requires (a <= b))
(ensures (c * a <= c * b))
= ()
private let mul_lemma' (a:nat) (b:nat) (c:pos) : Lemma (requires (c * a <= c * b))
(ensures (a <= b))
= ()
private let mul_div_lemma (a:nat) (b:pos) : Lemma (b * (a / b) <= a) = ()
val slash_decr_axiom: a:nat -> b:pos -> Lemma (a / b <= a)
let slash_decr_axiom a b =
mul_lemma 1 b a;
mul_div_lemma a b;
mul_lemma' (a / b) a b
private let lemma_mul_minus_distr_l (a:int) (b:int) (c:int) : Lemma (a * (b - c) = a * b - a * c)
= ()
(* Axiom: definition of the "b divides c" relation *)
#reset-options "--z3rlimit 30"
val slash_star_axiom: a:nat -> b:pos -> c:nat -> Lemma
(requires (a * b = c))
(ensures (a = c / b))
let slash_star_axiom a b c =
lemma_div_def c b;
lemma_mul_minus_distr_l b a (c/b)
#reset-options
val log_2: x:pos -> Tot nat
let rec log_2 x =
if x >= 2 then 1 + log_2 (x / 2) else 0
(* Function: power of x *)
val powx : x:int -> n:nat -> Tot int
let rec powx x n =
match n with
| 0 -> 1
| n -> x * powx x (n - 1)
(* Function: absolute value *)
val abs: x:int -> Tot (y:int{ (x >= 0 ==> y = x) /\ (x < 0 ==> y = -x) })
let abs x = if x >= 0 then x else -x
(* Function: maximum value *)
val max: x:int -> y:int -> Tot (z:int{ (x >= y ==> z = x) /\ (x < y ==> z = y) })
let max x y = if x >= y then x else y
(* Function: minimum value *)
val min: x:int -> y:int -> Tot (z:int{ (x >= y ==> z = y) /\ (x < y ==> z = x) })
let min x y = if x >= y then y else x
(* Function: standard euclidean division, the rest is always positive *)
val div: a:int -> b:pos -> Tot (c:int{(a < 0 ==> c < 0) /\ (a >= 0 ==> c >= 0)})
let div a b =
if a < 0 then
begin
slash_decr_axiom (-a) b;
if a % b = 0 then - (-a / b)
else - (-a / b) - 1
end
else a / b
(* Function: equivalent of the '/' operator in C, hence the rest can be negative *)
val div_non_eucl: a:int -> b:pos ->
Tot (q:int{ ( a >= 0 ==> q = a / b ) /\ ( a < 0 ==> q = -((-a)/b) ) })
let div_non_eucl a b =
if a < 0 then 0 - ((0 - a) / b)
else a / b
(* The equivalent of the << C operator *)
val shift_left: v:int -> i:nat -> Tot (res:int{res = v * (pow2 i)})
let shift_left v i =
v * (pow2 i)
(* asr OCaml operator *)
val arithmetic_shift_right: v:int -> i:nat -> Tot (res:int{ res = div v (pow2 i) })
let arithmetic_shift_right v i =
div v (pow2 i)
(* Case of C cast functions ? *)
(* Implemented by "mod" in OCaml *)
val signed_modulo: v:int -> p:pos -> Tot (res:int{ res = v - ((div_non_eucl v p) * p) })
let signed_modulo v p =
if v >= 0 then v % p
else 0 - ( (0-v) % p)
val op_Plus_Percent : a:int -> p:pos ->
Tot (res:int{ (a >= 0 ==> res = a % p) /\ (a < 0 ==> res = -((-a) % p)) })
let op_Plus_Percent a p = signed_modulo a p
(** Useful lemmas for future proofs **)
(* Lemmas of x^n *)
val powx_lemma1: a:int -> Lemma (powx a 1 = a)
let powx_lemma1 a = ()
val powx_lemma2: x:int -> n:nat -> m:nat -> Lemma | false | false | FStar.Math.Lib.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val powx_lemma2: x:int -> n:nat -> m:nat -> Lemma
(powx x n * powx x m = powx x (n + m)) | [
"recursion"
] | FStar.Math.Lib.powx_lemma2 | {
"file_name": "ulib/FStar.Math.Lib.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | x: Prims.int -> n: Prims.nat -> m: Prims.nat
-> FStar.Pervasives.Lemma
(ensures FStar.Math.Lib.powx x n * FStar.Math.Lib.powx x m = FStar.Math.Lib.powx x (n + m)) | {
"end_col": 63,
"end_line": 127,
"start_col": 27,
"start_line": 123
} |
FStar.Pervasives.Lemma | val slash_star_axiom: a:nat -> b:pos -> c:nat -> Lemma
(requires (a * b = c))
(ensures (a = c / b)) | [
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Math",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Math",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let slash_star_axiom a b c =
lemma_div_def c b;
lemma_mul_minus_distr_l b a (c/b) | val slash_star_axiom: a:nat -> b:pos -> c:nat -> Lemma
(requires (a * b = c))
(ensures (a = c / b))
let slash_star_axiom a b c = | false | null | true | lemma_div_def c b;
lemma_mul_minus_distr_l b a (c / b) | {
"checked_file": "FStar.Math.Lib.fst.checked",
"dependencies": [
"prims.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked"
],
"interface_file": false,
"source_file": "FStar.Math.Lib.fst"
} | [
"lemma"
] | [
"Prims.nat",
"Prims.pos",
"FStar.Math.Lib.lemma_mul_minus_distr_l",
"Prims.op_Division",
"Prims.unit",
"FStar.Math.Lib.lemma_div_def"
] | [] | (*
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 FStar.Math.Lib
open FStar.Mul
(* Definition of the division operator *)
val lemma_div_def: a:nat -> b:pos -> Lemma (a = b * (a/b) + a % b)
let lemma_div_def a b = ()
private let mul_lemma (a:nat) (b:nat) (c:nat) : Lemma (requires (a <= b))
(ensures (c * a <= c * b))
= ()
private let mul_lemma' (a:nat) (b:nat) (c:pos) : Lemma (requires (c * a <= c * b))
(ensures (a <= b))
= ()
private let mul_div_lemma (a:nat) (b:pos) : Lemma (b * (a / b) <= a) = ()
val slash_decr_axiom: a:nat -> b:pos -> Lemma (a / b <= a)
let slash_decr_axiom a b =
mul_lemma 1 b a;
mul_div_lemma a b;
mul_lemma' (a / b) a b
private let lemma_mul_minus_distr_l (a:int) (b:int) (c:int) : Lemma (a * (b - c) = a * b - a * c)
= ()
(* Axiom: definition of the "b divides c" relation *)
#reset-options "--z3rlimit 30"
val slash_star_axiom: a:nat -> b:pos -> c:nat -> Lemma
(requires (a * b = c))
(ensures (a = c / b)) | false | false | FStar.Math.Lib.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 30,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val slash_star_axiom: a:nat -> b:pos -> c:nat -> Lemma
(requires (a * b = c))
(ensures (a = c / b)) | [] | FStar.Math.Lib.slash_star_axiom | {
"file_name": "ulib/FStar.Math.Lib.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | a: Prims.nat -> b: Prims.pos -> c: Prims.nat
-> FStar.Pervasives.Lemma (requires a * b = c) (ensures a = c / b) | {
"end_col": 35,
"end_line": 50,
"start_col": 2,
"start_line": 49
} |
Prims.Tot | val everparse_version : string | [
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let everparse_version = "afb6fff3 (unreleased)" | val everparse_version : string
let everparse_version = | false | null | false | "afb6fff3 (unreleased)" | {
"checked_file": "Version.fst.checked",
"dependencies": [
"prims.fst.checked",
"FStar.Pervasives.fsti.checked"
],
"interface_file": true,
"source_file": "Version.fst"
} | [
"total"
] | [] | [] | false | true | Version.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val everparse_version : string | [] | Version.everparse_version | {
"file_name": "src/3d/Version.fst",
"git_rev": "446a08ce38df905547cf20f28c43776b22b8087a",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | Prims.string | {
"end_col": 47,
"end_line": 2,
"start_col": 24,
"start_line": 2
} |
|
Prims.Tot | val karamel_commit : string | [
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let karamel_commit = "7460546b" | val karamel_commit : string
let karamel_commit = | false | null | false | "7460546b" | {
"checked_file": "Version.fst.checked",
"dependencies": [
"prims.fst.checked",
"FStar.Pervasives.fsti.checked"
],
"interface_file": true,
"source_file": "Version.fst"
} | [
"total"
] | [] | [] | module Version
let everparse_version = "afb6fff3 (unreleased)" | false | true | Version.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val karamel_commit : string | [] | Version.karamel_commit | {
"file_name": "src/3d/Version.fst",
"git_rev": "446a08ce38df905547cf20f28c43776b22b8087a",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | Prims.string | {
"end_col": 31,
"end_line": 4,
"start_col": 21,
"start_line": 4
} |
Prims.Tot | val fstar_commit : string | [
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let fstar_commit = "61ccb46077" | val fstar_commit : string
let fstar_commit = | false | null | false | "61ccb46077" | {
"checked_file": "Version.fst.checked",
"dependencies": [
"prims.fst.checked",
"FStar.Pervasives.fsti.checked"
],
"interface_file": true,
"source_file": "Version.fst"
} | [
"total"
] | [] | [] | module Version | false | true | Version.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val fstar_commit : string | [] | Version.fstar_commit | {
"file_name": "src/3d/Version.fst",
"git_rev": "446a08ce38df905547cf20f28c43776b22b8087a",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | Prims.string | {
"end_col": 31,
"end_line": 3,
"start_col": 19,
"start_line": 3
} |
Prims.Tot | [
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Math.Poly2",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Math.Poly2_s",
"short_module": null
},
{
"abbrev": true,
"full_module": "Vale.Math.Poly2_s",
"short_module": "P"
},
{
"abbrev": true,
"full_module": "Spec.GaloisField",
"short_module": "G"
},
{
"abbrev": true,
"full_module": "Lib.IntTypes",
"short_module": "I"
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Math.Poly2",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Math.Poly2",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let min = FStar.Math.Lib.min | let min = | false | null | false | FStar.Math.Lib.min | {
"checked_file": "Vale.Math.Poly2.Galois.fsti.checked",
"dependencies": [
"Vale.Math.Poly2_s.fsti.checked",
"Vale.Math.Poly2.fsti.checked",
"Spec.GaloisField.fst.checked",
"prims.fst.checked",
"Lib.IntTypes.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lib.fst.checked"
],
"interface_file": false,
"source_file": "Vale.Math.Poly2.Galois.fsti"
} | [
"total"
] | [
"FStar.Math.Lib.min"
] | [] | module Vale.Math.Poly2.Galois
open FStar.Mul
module I = Lib.IntTypes
module G = Spec.GaloisField
module P = Vale.Math.Poly2_s
open Vale.Math.Poly2_s
open Vale.Math.Poly2
open FStar.Seq
(*
Connect Spec.GaloisField to Vale.Math.Poly2*
*)
val to_poly (#f:G.field) (e:G.felem f) : poly
val to_felem (f:G.field) (p:poly) : G.felem f
let irred_poly (f:G.field) : poly =
let G.GF t irred = f in
monomial (I.bits t) +. to_poly #f irred | false | false | Vale.Math.Poly2.Galois.fsti | {
"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"
} | null | val min : x: Prims.int -> y: Prims.int -> z: Prims.int{(x >= y ==> z = y) /\ (x < y ==> z = x)} | [] | Vale.Math.Poly2.Galois.min | {
"file_name": "vale/code/lib/math/Vale.Math.Poly2.Galois.fsti",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | x: Prims.int -> y: Prims.int -> z: Prims.int{(x >= y ==> z = y) /\ (x < y ==> z = x)} | {
"end_col": 35,
"end_line": 21,
"start_col": 17,
"start_line": 21
} |
|
Prims.Tot | [
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Math.Poly2",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Math.Poly2_s",
"short_module": null
},
{
"abbrev": true,
"full_module": "Vale.Math.Poly2_s",
"short_module": "P"
},
{
"abbrev": true,
"full_module": "Spec.GaloisField",
"short_module": "G"
},
{
"abbrev": true,
"full_module": "Lib.IntTypes",
"short_module": "I"
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Math.Poly2",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Math.Poly2",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let max = FStar.Math.Lib.max | let max = | false | null | false | FStar.Math.Lib.max | {
"checked_file": "Vale.Math.Poly2.Galois.fsti.checked",
"dependencies": [
"Vale.Math.Poly2_s.fsti.checked",
"Vale.Math.Poly2.fsti.checked",
"Spec.GaloisField.fst.checked",
"prims.fst.checked",
"Lib.IntTypes.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lib.fst.checked"
],
"interface_file": false,
"source_file": "Vale.Math.Poly2.Galois.fsti"
} | [
"total"
] | [
"FStar.Math.Lib.max"
] | [] | module Vale.Math.Poly2.Galois
open FStar.Mul
module I = Lib.IntTypes
module G = Spec.GaloisField
module P = Vale.Math.Poly2_s
open Vale.Math.Poly2_s
open Vale.Math.Poly2
open FStar.Seq
(*
Connect Spec.GaloisField to Vale.Math.Poly2*
*)
val to_poly (#f:G.field) (e:G.felem f) : poly
val to_felem (f:G.field) (p:poly) : G.felem f
let irred_poly (f:G.field) : poly =
let G.GF t irred = f in
monomial (I.bits t) +. to_poly #f irred | false | false | Vale.Math.Poly2.Galois.fsti | {
"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"
} | null | val max : x: Prims.int -> y: Prims.int -> z: Prims.int{(x >= y ==> z = x) /\ (x < y ==> z = y)} | [] | Vale.Math.Poly2.Galois.max | {
"file_name": "vale/code/lib/math/Vale.Math.Poly2.Galois.fsti",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | x: Prims.int -> y: Prims.int -> z: Prims.int{(x >= y ==> z = x) /\ (x < y ==> z = y)} | {
"end_col": 35,
"end_line": 22,
"start_col": 17,
"start_line": 22
} |
|
Prims.Tot | val irred_poly (f: G.field) : poly | [
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Math.Poly2",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Math.Poly2_s",
"short_module": null
},
{
"abbrev": true,
"full_module": "Vale.Math.Poly2_s",
"short_module": "P"
},
{
"abbrev": true,
"full_module": "Spec.GaloisField",
"short_module": "G"
},
{
"abbrev": true,
"full_module": "Lib.IntTypes",
"short_module": "I"
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Math.Poly2",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Math.Poly2",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let irred_poly (f:G.field) : poly =
let G.GF t irred = f in
monomial (I.bits t) +. to_poly #f irred | val irred_poly (f: G.field) : poly
let irred_poly (f: G.field) : poly = | false | null | false | let G.GF t irred = f in
monomial (I.bits t) +. to_poly #f irred | {
"checked_file": "Vale.Math.Poly2.Galois.fsti.checked",
"dependencies": [
"Vale.Math.Poly2_s.fsti.checked",
"Vale.Math.Poly2.fsti.checked",
"Spec.GaloisField.fst.checked",
"prims.fst.checked",
"Lib.IntTypes.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lib.fst.checked"
],
"interface_file": false,
"source_file": "Vale.Math.Poly2.Galois.fsti"
} | [
"total"
] | [
"Spec.GaloisField.field",
"Lib.IntTypes.inttype",
"Prims.l_and",
"Prims.b2t",
"Lib.IntTypes.unsigned",
"Prims.op_disEquality",
"Lib.IntTypes.U1",
"Lib.IntTypes.uint_t",
"Lib.IntTypes.SEC",
"Vale.Math.Poly2.op_Plus_Dot",
"Vale.Math.Poly2_s.monomial",
"Lib.IntTypes.bits",
"Vale.Math.Poly2.Galois.to_poly",
"Vale.Math.Poly2_s.poly"
] | [] | module Vale.Math.Poly2.Galois
open FStar.Mul
module I = Lib.IntTypes
module G = Spec.GaloisField
module P = Vale.Math.Poly2_s
open Vale.Math.Poly2_s
open Vale.Math.Poly2
open FStar.Seq
(*
Connect Spec.GaloisField to Vale.Math.Poly2*
*)
val to_poly (#f:G.field) (e:G.felem f) : poly
val to_felem (f:G.field) (p:poly) : G.felem f | false | true | Vale.Math.Poly2.Galois.fsti | {
"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"
} | null | val irred_poly (f: G.field) : poly | [] | Vale.Math.Poly2.Galois.irred_poly | {
"file_name": "vale/code/lib/math/Vale.Math.Poly2.Galois.fsti",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | f: Spec.GaloisField.field -> Vale.Math.Poly2_s.poly | {
"end_col": 41,
"end_line": 19,
"start_col": 35,
"start_line": 17
} |
Prims.Tot | val reseed: a:supported_alg -> reseed_st a | [
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": true,
"full_module": "Spec.HMAC_DRBG",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "Hacl.HMAC",
"short_module": "HMAC"
},
{
"abbrev": true,
"full_module": "Lib.Sequence",
"short_module": "LSeq"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": false,
"full_module": "Lib.Buffer",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Hash.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let reseed a st
entropy_input_len entropy_input
additional_input_input_len additional_input_input =
match a with
| SHA1 ->
mk_reseed Hacl.HMAC.legacy_compute_sha1 st
entropy_input_len entropy_input
additional_input_input_len additional_input_input
| SHA2_256 ->
mk_reseed Hacl.HMAC.compute_sha2_256 st
entropy_input_len entropy_input
additional_input_input_len additional_input_input
| SHA2_384 ->
mk_reseed Hacl.HMAC.compute_sha2_384 st
entropy_input_len entropy_input
additional_input_input_len additional_input_input
| SHA2_512 ->
mk_reseed Hacl.HMAC.compute_sha2_512 st
entropy_input_len entropy_input
additional_input_input_len additional_input_input | val reseed: a:supported_alg -> reseed_st a
let reseed a st entropy_input_len entropy_input additional_input_input_len additional_input_input = | false | null | false | match a with
| SHA1 ->
mk_reseed Hacl.HMAC.legacy_compute_sha1
st
entropy_input_len
entropy_input
additional_input_input_len
additional_input_input
| SHA2_256 ->
mk_reseed Hacl.HMAC.compute_sha2_256
st
entropy_input_len
entropy_input
additional_input_input_len
additional_input_input
| SHA2_384 ->
mk_reseed Hacl.HMAC.compute_sha2_384
st
entropy_input_len
entropy_input
additional_input_input_len
additional_input_input
| SHA2_512 ->
mk_reseed Hacl.HMAC.compute_sha2_512
st
entropy_input_len
entropy_input
additional_input_input_len
additional_input_input | {
"checked_file": "Hacl.HMAC_DRBG.fst.checked",
"dependencies": [
"Spec.HMAC_DRBG.fst.checked",
"Spec.HMAC_DRBG.fst.checked",
"Spec.Hash.Definitions.fst.checked",
"Spec.Agile.HMAC.fsti.checked",
"prims.fst.checked",
"LowStar.Buffer.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.Buffer.fsti.checked",
"Hacl.HMAC.fsti.checked",
"Hacl.Hash.Definitions.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked"
],
"interface_file": true,
"source_file": "Hacl.HMAC_DRBG.fst"
} | [
"total"
] | [
"Hacl.HMAC_DRBG.supported_alg",
"Hacl.HMAC_DRBG.state",
"Lib.IntTypes.size_t",
"Lib.Buffer.lbuffer",
"Lib.IntTypes.uint8",
"Hacl.HMAC_DRBG.mk_reseed",
"Spec.Hash.Definitions.SHA1",
"Hacl.HMAC.legacy_compute_sha1",
"Prims.unit",
"Spec.Hash.Definitions.SHA2_256",
"Hacl.HMAC.compute_sha2_256",
"Spec.Hash.Definitions.SHA2_384",
"Hacl.HMAC.compute_sha2_384",
"Spec.Hash.Definitions.SHA2_512",
"Hacl.HMAC.compute_sha2_512"
] | [] | module Hacl.HMAC_DRBG
open FStar.HyperStack.ST
module ST = FStar.HyperStack.ST
open Spec.Hash.Definitions
open Lib.IntTypes
open Lib.Buffer
module HS = FStar.HyperStack
module B = LowStar.Buffer
module LSeq = Lib.Sequence
module HMAC = Hacl.HMAC
module S = Spec.HMAC_DRBG
friend Spec.HMAC_DRBG
unfold
let hash_len (a:supported_alg) = Hacl.Hash.Definitions.hash_len a
#set-options "--fuel 0 --ifuel 0 --z3rlimit 50"
inline_for_extraction noextract
val update_round: #a:supported_alg
-> hmac:HMAC.compute_st a
-> len:size_t
-> data:lbuffer uint8 len
-> n:uint8
-> k:lbuffer uint8 (hash_len a)
-> v:lbuffer uint8 (hash_len a)
-> Stack unit
(requires fun h0 ->
live h0 k /\ live h0 v /\ live h0 data /\
disjoint k v /\
// HMAC input length must fit in size_t
hash_length a + 1 + uint_v len + block_length a < pow2 32)
(ensures fun h0 _ h1 ->
S.hmac_input_bound a;
as_seq h1 k == Spec.Agile.HMAC.hmac a
(as_seq h0 k)
(Seq.append (as_seq h0 v) (Seq.cons n (as_seq h0 data))) /\
as_seq h1 v == Spec.Agile.HMAC.hmac a (as_seq h1 k) (as_seq h0 v) /\
modifies2 k v h0 h1)
let update_round #a hmac len data n k v =
let h0 = ST.get() in
push_frame();
let input_len = hash_len a +! 1ul +! len in
let input = create input_len (u8 0) in
let k' = sub input 0ul (hash_len a) in
copy k' v;
if len <> 0ul then copy (sub input (hash_len a +! 1ul) len) data;
input.(hash_len a) <- n;
let h1 = ST.get() in
assert (Seq.equal (as_seq h1 input)
(Seq.append (as_seq h0 v) (Seq.cons n (as_seq h0 data))));
S.hmac_input_bound a;
hmac k' k (hash_len a) input input_len;
hmac v k' (hash_len a) v (hash_len a);
copy k k';
pop_frame()
inline_for_extraction noextract
val update: #a:supported_alg
-> hmac:HMAC.compute_st a
-> len:size_t
-> data:lbuffer uint8 len
-> k:lbuffer uint8 (hash_len a)
-> v:lbuffer uint8 (hash_len a)
-> Stack unit
(requires fun h0 ->
live h0 data /\ live h0 k /\ live h0 v /\
disjoint k v /\ disjoint k data /\ disjoint v data /\
hash_length a + 1 + uint_v len + block_length a < pow2 32)
(ensures fun h0 _ h1 ->
S.hmac_input_bound a;
let k', v' = S.update #a (as_seq h0 data) (as_seq h0 k) (as_seq h0 v) in
modifies2 k v h0 h1 /\
as_seq h1 k == k' /\
as_seq h1 v == v')
let update #a hmac len data k v =
update_round hmac len data (u8 0) k v;
if len <> 0ul then
update_round hmac len data (u8 1) k v
noeq
type state (a:supported_alg) =
| State:
k:lbuffer uint8 (hash_len a)
-> v:lbuffer uint8 (hash_len a)
-> reseed_counter:lbuffer size_t 1ul
{disjoint k v /\ disjoint k reseed_counter /\ disjoint v reseed_counter}
-> state a
let freeable #a st =
let k:B.buffer uint8 = st.k in
let v:B.buffer uint8 = st.v in
let ctr:B.buffer size_t = st.reseed_counter in
B.freeable k /\ B.freeable v /\ B.freeable ctr
let footprint #a st =
let k:B.buffer uint8 = st.k in
let v:B.buffer uint8 = st.v in
let ctr:B.buffer size_t = st.reseed_counter in
B.loc_addr_of_buffer k |+| B.loc_addr_of_buffer v |+| B.loc_addr_of_buffer ctr
let invariant #a st h =
live h st.k /\ live h st.v /\ live h st.reseed_counter /\ (
// JP: the disjoint predicate from lib hardcodes loc_buffer instead of
// loc_addr_of_buffer, which prevents us from writing a proper free function
// (probably why it wasn't written here in the first place)... we add on top
// of the lib-style predicate a non-lib-style predicate which allows writing
// an actual free function
let k = st.k <: B.buffer uint8 in
let v = st.v <: B.buffer uint8 in
let ctr = st.reseed_counter <: B.buffer size_t in
B.(all_disjoint [ loc_addr_of_buffer k; loc_addr_of_buffer v; loc_addr_of_buffer ctr ]))
let repr #a st h =
S.State (as_seq h st.k) (as_seq h st.v) (v (bget h st.reseed_counter 0))
let alloca a =
let k =
match a with
| SHA1 -> create (hash_len SHA1) (u8 0)
| SHA2_256 -> create (hash_len SHA2_256) (u8 0)
| SHA2_384 -> create (hash_len SHA2_384) (u8 0)
| SHA2_512 -> create (hash_len SHA2_512) (u8 0)
in
let v =
match a with
| SHA1 -> create (hash_len SHA1) (u8 0)
| SHA2_256 -> create (hash_len SHA2_256) (u8 0)
| SHA2_384 -> create (hash_len SHA2_384) (u8 0)
| SHA2_512 -> create (hash_len SHA2_512) (u8 0)
in
let ctr = create 1ul 1ul in
State k v ctr
let create_in a r =
let k:B.buffer uint8 =
match a with
| SHA1 -> B.malloc r (u8 0) (hash_len SHA1)
| SHA2_256 -> B.malloc r (u8 0) (hash_len SHA2_256)
| SHA2_384 -> B.malloc r (u8 0) (hash_len SHA2_384)
| SHA2_512 -> B.malloc r (u8 0) (hash_len SHA2_512)
in
let v:B.buffer uint8 =
match a with
| SHA1 -> B.malloc r (u8 0) (hash_len SHA1)
| SHA2_256 -> B.malloc r (u8 0) (hash_len SHA2_256)
| SHA2_384 -> B.malloc r (u8 0) (hash_len SHA2_384)
| SHA2_512 -> B.malloc r (u8 0) (hash_len SHA2_512)
in
let ctr:B.buffer size_t = B.malloc r 1ul 1ul in
State k v ctr
#push-options "--z3rlimit 200"
let mk_instantiate #a hmac st
entropy_input_len entropy_input
nonce_len nonce
personalization_string_len personalization_string
=
let h0 = ST.get () in
push_frame();
let seed_material = create (entropy_input_len +! nonce_len +! personalization_string_len) (u8 0) in
copy (sub seed_material 0ul entropy_input_len) entropy_input;
copy (sub seed_material entropy_input_len nonce_len) nonce;
copy (sub seed_material (entropy_input_len +! nonce_len) personalization_string_len) personalization_string;
let State k v ctr = st in
memset k (u8 0) (hash_len a);
memset v (u8 1) (hash_len a);
let h1 = ST.get () in
assert (Seq.equal (as_seq h1 seed_material)
(Seq.append (as_seq h0 entropy_input) (Seq.append (as_seq h0 nonce)
(as_seq h0 personalization_string))));
assert (LSeq.equal (as_seq h1 k) (LSeq.create (hash_length a) (u8 0)));
assert (LSeq.equal (as_seq h1 v) (LSeq.create (hash_length a) (u8 1)));
ctr.(0ul) <- 1ul;
update hmac (entropy_input_len +! nonce_len +! personalization_string_len)
seed_material k v;
pop_frame()
#pop-options
let instantiate a st
entropy_input_len entropy_input
nonce_len nonce
personalization_string_len personalization_string
=
match a with
| SHA1 ->
mk_instantiate Hacl.HMAC.legacy_compute_sha1 st
entropy_input_len entropy_input
nonce_len nonce
personalization_string_len personalization_string
| SHA2_256 ->
mk_instantiate Hacl.HMAC.compute_sha2_256 st
entropy_input_len entropy_input
nonce_len nonce
personalization_string_len personalization_string
| SHA2_384 ->
mk_instantiate Hacl.HMAC.compute_sha2_384 st
entropy_input_len entropy_input
nonce_len nonce
personalization_string_len personalization_string
| SHA2_512 ->
mk_instantiate Hacl.HMAC.compute_sha2_512 st
entropy_input_len entropy_input
nonce_len nonce
personalization_string_len personalization_string
let mk_reseed #a hmac st
entropy_input_len entropy_input
additional_input_len additional_input
=
let h0 = ST.get () in
push_frame();
let seed_material = create (entropy_input_len +! additional_input_len) (u8 0) in
copy (sub seed_material 0ul entropy_input_len) entropy_input;
copy (sub seed_material entropy_input_len additional_input_len) additional_input;
let h1 = ST.get () in
LSeq.eq_intro (as_seq h1 seed_material)
LSeq.(as_seq h0 entropy_input @| as_seq h0 additional_input);
let State k v ctr: state a = st in
update hmac (entropy_input_len +! additional_input_len) seed_material k v;
ctr.(0ul) <- 1ul;
pop_frame()
let reseed a st
entropy_input_len entropy_input | false | false | Hacl.HMAC_DRBG.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val reseed: a:supported_alg -> reseed_st a | [] | Hacl.HMAC_DRBG.reseed | {
"file_name": "code/drbg/Hacl.HMAC_DRBG.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | a: Hacl.HMAC_DRBG.supported_alg -> Hacl.HMAC_DRBG.reseed_st a | {
"end_col": 55,
"end_line": 257,
"start_col": 2,
"start_line": 241
} |
Prims.Tot | val invariant: #a:supported_alg -> st:state a -> h:HS.mem -> Type0 | [
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": true,
"full_module": "Spec.HMAC_DRBG",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "Hacl.HMAC",
"short_module": "HMAC"
},
{
"abbrev": true,
"full_module": "Lib.Sequence",
"short_module": "LSeq"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": false,
"full_module": "Lib.Buffer",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Hash.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let invariant #a st h =
live h st.k /\ live h st.v /\ live h st.reseed_counter /\ (
// JP: the disjoint predicate from lib hardcodes loc_buffer instead of
// loc_addr_of_buffer, which prevents us from writing a proper free function
// (probably why it wasn't written here in the first place)... we add on top
// of the lib-style predicate a non-lib-style predicate which allows writing
// an actual free function
let k = st.k <: B.buffer uint8 in
let v = st.v <: B.buffer uint8 in
let ctr = st.reseed_counter <: B.buffer size_t in
B.(all_disjoint [ loc_addr_of_buffer k; loc_addr_of_buffer v; loc_addr_of_buffer ctr ])) | val invariant: #a:supported_alg -> st:state a -> h:HS.mem -> Type0
let invariant #a st h = | false | null | false | live h st.k /\ live h st.v /\ live h st.reseed_counter /\
(let k = st.k <: B.buffer uint8 in
let v = st.v <: B.buffer uint8 in
let ctr = st.reseed_counter <: B.buffer size_t in
let open B in all_disjoint [loc_addr_of_buffer k; loc_addr_of_buffer v; loc_addr_of_buffer ctr]) | {
"checked_file": "Hacl.HMAC_DRBG.fst.checked",
"dependencies": [
"Spec.HMAC_DRBG.fst.checked",
"Spec.HMAC_DRBG.fst.checked",
"Spec.Hash.Definitions.fst.checked",
"Spec.Agile.HMAC.fsti.checked",
"prims.fst.checked",
"LowStar.Buffer.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.Buffer.fsti.checked",
"Hacl.HMAC.fsti.checked",
"Hacl.Hash.Definitions.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked"
],
"interface_file": true,
"source_file": "Hacl.HMAC_DRBG.fst"
} | [
"total"
] | [
"Hacl.HMAC_DRBG.supported_alg",
"Hacl.HMAC_DRBG.state",
"FStar.Monotonic.HyperStack.mem",
"Prims.l_and",
"Lib.Buffer.live",
"Lib.Buffer.MUT",
"Lib.IntTypes.uint8",
"Hacl.HMAC_DRBG.__proj__State__item__k",
"Hacl.HMAC_DRBG.__proj__State__item__v",
"Lib.IntTypes.size_t",
"Hacl.HMAC_DRBG.__proj__State__item__reseed_counter",
"LowStar.Monotonic.Buffer.all_disjoint",
"Prims.Cons",
"LowStar.Monotonic.Buffer.loc",
"LowStar.Monotonic.Buffer.loc_addr_of_buffer",
"LowStar.Buffer.trivial_preorder",
"Prims.Nil",
"LowStar.Buffer.buffer",
"Lib.IntTypes.int_t",
"Lib.IntTypes.U32",
"Lib.IntTypes.PUB",
"Lib.IntTypes.U8",
"Lib.IntTypes.SEC"
] | [] | module Hacl.HMAC_DRBG
open FStar.HyperStack.ST
module ST = FStar.HyperStack.ST
open Spec.Hash.Definitions
open Lib.IntTypes
open Lib.Buffer
module HS = FStar.HyperStack
module B = LowStar.Buffer
module LSeq = Lib.Sequence
module HMAC = Hacl.HMAC
module S = Spec.HMAC_DRBG
friend Spec.HMAC_DRBG
unfold
let hash_len (a:supported_alg) = Hacl.Hash.Definitions.hash_len a
#set-options "--fuel 0 --ifuel 0 --z3rlimit 50"
inline_for_extraction noextract
val update_round: #a:supported_alg
-> hmac:HMAC.compute_st a
-> len:size_t
-> data:lbuffer uint8 len
-> n:uint8
-> k:lbuffer uint8 (hash_len a)
-> v:lbuffer uint8 (hash_len a)
-> Stack unit
(requires fun h0 ->
live h0 k /\ live h0 v /\ live h0 data /\
disjoint k v /\
// HMAC input length must fit in size_t
hash_length a + 1 + uint_v len + block_length a < pow2 32)
(ensures fun h0 _ h1 ->
S.hmac_input_bound a;
as_seq h1 k == Spec.Agile.HMAC.hmac a
(as_seq h0 k)
(Seq.append (as_seq h0 v) (Seq.cons n (as_seq h0 data))) /\
as_seq h1 v == Spec.Agile.HMAC.hmac a (as_seq h1 k) (as_seq h0 v) /\
modifies2 k v h0 h1)
let update_round #a hmac len data n k v =
let h0 = ST.get() in
push_frame();
let input_len = hash_len a +! 1ul +! len in
let input = create input_len (u8 0) in
let k' = sub input 0ul (hash_len a) in
copy k' v;
if len <> 0ul then copy (sub input (hash_len a +! 1ul) len) data;
input.(hash_len a) <- n;
let h1 = ST.get() in
assert (Seq.equal (as_seq h1 input)
(Seq.append (as_seq h0 v) (Seq.cons n (as_seq h0 data))));
S.hmac_input_bound a;
hmac k' k (hash_len a) input input_len;
hmac v k' (hash_len a) v (hash_len a);
copy k k';
pop_frame()
inline_for_extraction noextract
val update: #a:supported_alg
-> hmac:HMAC.compute_st a
-> len:size_t
-> data:lbuffer uint8 len
-> k:lbuffer uint8 (hash_len a)
-> v:lbuffer uint8 (hash_len a)
-> Stack unit
(requires fun h0 ->
live h0 data /\ live h0 k /\ live h0 v /\
disjoint k v /\ disjoint k data /\ disjoint v data /\
hash_length a + 1 + uint_v len + block_length a < pow2 32)
(ensures fun h0 _ h1 ->
S.hmac_input_bound a;
let k', v' = S.update #a (as_seq h0 data) (as_seq h0 k) (as_seq h0 v) in
modifies2 k v h0 h1 /\
as_seq h1 k == k' /\
as_seq h1 v == v')
let update #a hmac len data k v =
update_round hmac len data (u8 0) k v;
if len <> 0ul then
update_round hmac len data (u8 1) k v
noeq
type state (a:supported_alg) =
| State:
k:lbuffer uint8 (hash_len a)
-> v:lbuffer uint8 (hash_len a)
-> reseed_counter:lbuffer size_t 1ul
{disjoint k v /\ disjoint k reseed_counter /\ disjoint v reseed_counter}
-> state a
let freeable #a st =
let k:B.buffer uint8 = st.k in
let v:B.buffer uint8 = st.v in
let ctr:B.buffer size_t = st.reseed_counter in
B.freeable k /\ B.freeable v /\ B.freeable ctr
let footprint #a st =
let k:B.buffer uint8 = st.k in
let v:B.buffer uint8 = st.v in
let ctr:B.buffer size_t = st.reseed_counter in
B.loc_addr_of_buffer k |+| B.loc_addr_of_buffer v |+| B.loc_addr_of_buffer ctr | false | false | Hacl.HMAC_DRBG.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val invariant: #a:supported_alg -> st:state a -> h:HS.mem -> Type0 | [] | Hacl.HMAC_DRBG.invariant | {
"file_name": "code/drbg/Hacl.HMAC_DRBG.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | st: Hacl.HMAC_DRBG.state a -> h: FStar.Monotonic.HyperStack.mem -> Type0 | {
"end_col": 90,
"end_line": 122,
"start_col": 2,
"start_line": 113
} |
Prims.Tot | val generate: a:supported_alg -> generate_st a | [
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": true,
"full_module": "Spec.HMAC_DRBG",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "Hacl.HMAC",
"short_module": "HMAC"
},
{
"abbrev": true,
"full_module": "Lib.Sequence",
"short_module": "LSeq"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": false,
"full_module": "Lib.Buffer",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Hash.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let generate a output st n additional_input_len additional_input =
match a with
| SHA1 ->
mk_generate Hacl.HMAC.legacy_compute_sha1 output st n
additional_input_len additional_input
| SHA2_256 ->
mk_generate Hacl.HMAC.compute_sha2_256 output st n
additional_input_len additional_input
| SHA2_384 ->
mk_generate Hacl.HMAC.compute_sha2_384 output st n
additional_input_len additional_input
| SHA2_512 ->
mk_generate Hacl.HMAC.compute_sha2_512 output st n
additional_input_len additional_input | val generate: a:supported_alg -> generate_st a
let generate a output st n additional_input_len additional_input = | false | null | false | match a with
| SHA1 ->
mk_generate Hacl.HMAC.legacy_compute_sha1 output st n additional_input_len additional_input
| SHA2_256 ->
mk_generate Hacl.HMAC.compute_sha2_256 output st n additional_input_len additional_input
| SHA2_384 ->
mk_generate Hacl.HMAC.compute_sha2_384 output st n additional_input_len additional_input
| SHA2_512 ->
mk_generate Hacl.HMAC.compute_sha2_512 output st n additional_input_len additional_input | {
"checked_file": "Hacl.HMAC_DRBG.fst.checked",
"dependencies": [
"Spec.HMAC_DRBG.fst.checked",
"Spec.HMAC_DRBG.fst.checked",
"Spec.Hash.Definitions.fst.checked",
"Spec.Agile.HMAC.fsti.checked",
"prims.fst.checked",
"LowStar.Buffer.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.Buffer.fsti.checked",
"Hacl.HMAC.fsti.checked",
"Hacl.Hash.Definitions.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked"
],
"interface_file": true,
"source_file": "Hacl.HMAC_DRBG.fst"
} | [
"total"
] | [
"Hacl.HMAC_DRBG.supported_alg",
"Lib.Buffer.buffer",
"Lib.IntTypes.uint8",
"Hacl.HMAC_DRBG.state",
"Lib.IntTypes.size_t",
"Lib.Buffer.lbuffer",
"Hacl.HMAC_DRBG.mk_generate",
"Spec.Hash.Definitions.SHA1",
"Hacl.HMAC.legacy_compute_sha1",
"Prims.bool",
"Spec.Hash.Definitions.SHA2_256",
"Hacl.HMAC.compute_sha2_256",
"Spec.Hash.Definitions.SHA2_384",
"Hacl.HMAC.compute_sha2_384",
"Spec.Hash.Definitions.SHA2_512",
"Hacl.HMAC.compute_sha2_512"
] | [] | module Hacl.HMAC_DRBG
open FStar.HyperStack.ST
module ST = FStar.HyperStack.ST
open Spec.Hash.Definitions
open Lib.IntTypes
open Lib.Buffer
module HS = FStar.HyperStack
module B = LowStar.Buffer
module LSeq = Lib.Sequence
module HMAC = Hacl.HMAC
module S = Spec.HMAC_DRBG
friend Spec.HMAC_DRBG
unfold
let hash_len (a:supported_alg) = Hacl.Hash.Definitions.hash_len a
#set-options "--fuel 0 --ifuel 0 --z3rlimit 50"
inline_for_extraction noextract
val update_round: #a:supported_alg
-> hmac:HMAC.compute_st a
-> len:size_t
-> data:lbuffer uint8 len
-> n:uint8
-> k:lbuffer uint8 (hash_len a)
-> v:lbuffer uint8 (hash_len a)
-> Stack unit
(requires fun h0 ->
live h0 k /\ live h0 v /\ live h0 data /\
disjoint k v /\
// HMAC input length must fit in size_t
hash_length a + 1 + uint_v len + block_length a < pow2 32)
(ensures fun h0 _ h1 ->
S.hmac_input_bound a;
as_seq h1 k == Spec.Agile.HMAC.hmac a
(as_seq h0 k)
(Seq.append (as_seq h0 v) (Seq.cons n (as_seq h0 data))) /\
as_seq h1 v == Spec.Agile.HMAC.hmac a (as_seq h1 k) (as_seq h0 v) /\
modifies2 k v h0 h1)
let update_round #a hmac len data n k v =
let h0 = ST.get() in
push_frame();
let input_len = hash_len a +! 1ul +! len in
let input = create input_len (u8 0) in
let k' = sub input 0ul (hash_len a) in
copy k' v;
if len <> 0ul then copy (sub input (hash_len a +! 1ul) len) data;
input.(hash_len a) <- n;
let h1 = ST.get() in
assert (Seq.equal (as_seq h1 input)
(Seq.append (as_seq h0 v) (Seq.cons n (as_seq h0 data))));
S.hmac_input_bound a;
hmac k' k (hash_len a) input input_len;
hmac v k' (hash_len a) v (hash_len a);
copy k k';
pop_frame()
inline_for_extraction noextract
val update: #a:supported_alg
-> hmac:HMAC.compute_st a
-> len:size_t
-> data:lbuffer uint8 len
-> k:lbuffer uint8 (hash_len a)
-> v:lbuffer uint8 (hash_len a)
-> Stack unit
(requires fun h0 ->
live h0 data /\ live h0 k /\ live h0 v /\
disjoint k v /\ disjoint k data /\ disjoint v data /\
hash_length a + 1 + uint_v len + block_length a < pow2 32)
(ensures fun h0 _ h1 ->
S.hmac_input_bound a;
let k', v' = S.update #a (as_seq h0 data) (as_seq h0 k) (as_seq h0 v) in
modifies2 k v h0 h1 /\
as_seq h1 k == k' /\
as_seq h1 v == v')
let update #a hmac len data k v =
update_round hmac len data (u8 0) k v;
if len <> 0ul then
update_round hmac len data (u8 1) k v
noeq
type state (a:supported_alg) =
| State:
k:lbuffer uint8 (hash_len a)
-> v:lbuffer uint8 (hash_len a)
-> reseed_counter:lbuffer size_t 1ul
{disjoint k v /\ disjoint k reseed_counter /\ disjoint v reseed_counter}
-> state a
let freeable #a st =
let k:B.buffer uint8 = st.k in
let v:B.buffer uint8 = st.v in
let ctr:B.buffer size_t = st.reseed_counter in
B.freeable k /\ B.freeable v /\ B.freeable ctr
let footprint #a st =
let k:B.buffer uint8 = st.k in
let v:B.buffer uint8 = st.v in
let ctr:B.buffer size_t = st.reseed_counter in
B.loc_addr_of_buffer k |+| B.loc_addr_of_buffer v |+| B.loc_addr_of_buffer ctr
let invariant #a st h =
live h st.k /\ live h st.v /\ live h st.reseed_counter /\ (
// JP: the disjoint predicate from lib hardcodes loc_buffer instead of
// loc_addr_of_buffer, which prevents us from writing a proper free function
// (probably why it wasn't written here in the first place)... we add on top
// of the lib-style predicate a non-lib-style predicate which allows writing
// an actual free function
let k = st.k <: B.buffer uint8 in
let v = st.v <: B.buffer uint8 in
let ctr = st.reseed_counter <: B.buffer size_t in
B.(all_disjoint [ loc_addr_of_buffer k; loc_addr_of_buffer v; loc_addr_of_buffer ctr ]))
let repr #a st h =
S.State (as_seq h st.k) (as_seq h st.v) (v (bget h st.reseed_counter 0))
let alloca a =
let k =
match a with
| SHA1 -> create (hash_len SHA1) (u8 0)
| SHA2_256 -> create (hash_len SHA2_256) (u8 0)
| SHA2_384 -> create (hash_len SHA2_384) (u8 0)
| SHA2_512 -> create (hash_len SHA2_512) (u8 0)
in
let v =
match a with
| SHA1 -> create (hash_len SHA1) (u8 0)
| SHA2_256 -> create (hash_len SHA2_256) (u8 0)
| SHA2_384 -> create (hash_len SHA2_384) (u8 0)
| SHA2_512 -> create (hash_len SHA2_512) (u8 0)
in
let ctr = create 1ul 1ul in
State k v ctr
let create_in a r =
let k:B.buffer uint8 =
match a with
| SHA1 -> B.malloc r (u8 0) (hash_len SHA1)
| SHA2_256 -> B.malloc r (u8 0) (hash_len SHA2_256)
| SHA2_384 -> B.malloc r (u8 0) (hash_len SHA2_384)
| SHA2_512 -> B.malloc r (u8 0) (hash_len SHA2_512)
in
let v:B.buffer uint8 =
match a with
| SHA1 -> B.malloc r (u8 0) (hash_len SHA1)
| SHA2_256 -> B.malloc r (u8 0) (hash_len SHA2_256)
| SHA2_384 -> B.malloc r (u8 0) (hash_len SHA2_384)
| SHA2_512 -> B.malloc r (u8 0) (hash_len SHA2_512)
in
let ctr:B.buffer size_t = B.malloc r 1ul 1ul in
State k v ctr
#push-options "--z3rlimit 200"
let mk_instantiate #a hmac st
entropy_input_len entropy_input
nonce_len nonce
personalization_string_len personalization_string
=
let h0 = ST.get () in
push_frame();
let seed_material = create (entropy_input_len +! nonce_len +! personalization_string_len) (u8 0) in
copy (sub seed_material 0ul entropy_input_len) entropy_input;
copy (sub seed_material entropy_input_len nonce_len) nonce;
copy (sub seed_material (entropy_input_len +! nonce_len) personalization_string_len) personalization_string;
let State k v ctr = st in
memset k (u8 0) (hash_len a);
memset v (u8 1) (hash_len a);
let h1 = ST.get () in
assert (Seq.equal (as_seq h1 seed_material)
(Seq.append (as_seq h0 entropy_input) (Seq.append (as_seq h0 nonce)
(as_seq h0 personalization_string))));
assert (LSeq.equal (as_seq h1 k) (LSeq.create (hash_length a) (u8 0)));
assert (LSeq.equal (as_seq h1 v) (LSeq.create (hash_length a) (u8 1)));
ctr.(0ul) <- 1ul;
update hmac (entropy_input_len +! nonce_len +! personalization_string_len)
seed_material k v;
pop_frame()
#pop-options
let instantiate a st
entropy_input_len entropy_input
nonce_len nonce
personalization_string_len personalization_string
=
match a with
| SHA1 ->
mk_instantiate Hacl.HMAC.legacy_compute_sha1 st
entropy_input_len entropy_input
nonce_len nonce
personalization_string_len personalization_string
| SHA2_256 ->
mk_instantiate Hacl.HMAC.compute_sha2_256 st
entropy_input_len entropy_input
nonce_len nonce
personalization_string_len personalization_string
| SHA2_384 ->
mk_instantiate Hacl.HMAC.compute_sha2_384 st
entropy_input_len entropy_input
nonce_len nonce
personalization_string_len personalization_string
| SHA2_512 ->
mk_instantiate Hacl.HMAC.compute_sha2_512 st
entropy_input_len entropy_input
nonce_len nonce
personalization_string_len personalization_string
let mk_reseed #a hmac st
entropy_input_len entropy_input
additional_input_len additional_input
=
let h0 = ST.get () in
push_frame();
let seed_material = create (entropy_input_len +! additional_input_len) (u8 0) in
copy (sub seed_material 0ul entropy_input_len) entropy_input;
copy (sub seed_material entropy_input_len additional_input_len) additional_input;
let h1 = ST.get () in
LSeq.eq_intro (as_seq h1 seed_material)
LSeq.(as_seq h0 entropy_input @| as_seq h0 additional_input);
let State k v ctr: state a = st in
update hmac (entropy_input_len +! additional_input_len) seed_material k v;
ctr.(0ul) <- 1ul;
pop_frame()
let reseed a st
entropy_input_len entropy_input
additional_input_input_len additional_input_input =
match a with
| SHA1 ->
mk_reseed Hacl.HMAC.legacy_compute_sha1 st
entropy_input_len entropy_input
additional_input_input_len additional_input_input
| SHA2_256 ->
mk_reseed Hacl.HMAC.compute_sha2_256 st
entropy_input_len entropy_input
additional_input_input_len additional_input_input
| SHA2_384 ->
mk_reseed Hacl.HMAC.compute_sha2_384 st
entropy_input_len entropy_input
additional_input_input_len additional_input_input
| SHA2_512 ->
mk_reseed Hacl.HMAC.compute_sha2_512 st
entropy_input_len entropy_input
additional_input_input_len additional_input_input
#push-options "--z3rlimit 300"
let mk_generate #a hmac output st n additional_input_len additional_input =
if st.reseed_counter.(0ul) >. reseed_interval then
false
else
begin
S.hmac_input_bound a;
Math.Lemmas.lemma_div_mod (v n) (hash_length a);
let State k v ctr = st in
if additional_input_len >. 0ul then
update hmac additional_input_len additional_input k v;
let output:lbuffer uint8 n = output in
let max = n /. hash_len a in
let out = sub output 0ul (max *! hash_len a) in
[@inline_let]
let a_spec = S.a_spec a in
[@inline_let]
let refl h i = as_seq h v in
[@inline_let]
let spec h0 = S.generate_loop a (as_seq h0 k) (uint_v max) in
let h0 = ST.get () in
fill_blocks h0 (hash_len a) max out a_spec refl (fun i -> loc v) spec
(fun i ->
LSeq.unfold_generate_blocks
(hash_length a) (uint_v max) a_spec (spec h0) (as_seq h0 v) (uint_v i);
hmac v k (hash_len a) v (hash_len a);
copy (sub out (i *! hash_len a) (hash_len a)) v
);
if max *! hash_len a <. n then
begin
let h1 = ST.get () in
let block = sub output (max *! hash_len a) (n -! (max *! hash_len a)) in
hmac v k (hash_len a) v (hash_len a);
copy block (sub v 0ul (n -! (max *! hash_len a)));
let h2 = ST.get () in
LSeq.eq_intro (as_seq h2 output)
(as_seq h1 out `LSeq.op_At_Bar` as_seq h2 block)
end;
update hmac additional_input_len additional_input k v;
let old_ctr = ctr.(0ul) in
ctr.(0ul) <- old_ctr +! 1ul;
true
end
#pop-options | false | false | Hacl.HMAC_DRBG.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val generate: a:supported_alg -> generate_st a | [] | Hacl.HMAC_DRBG.generate | {
"file_name": "code/drbg/Hacl.HMAC_DRBG.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | a: Hacl.HMAC_DRBG.supported_alg -> Hacl.HMAC_DRBG.generate_st a | {
"end_col": 43,
"end_line": 319,
"start_col": 2,
"start_line": 307
} |
Prims.Tot | val instantiate: a:supported_alg -> instantiate_st a | [
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": true,
"full_module": "Spec.HMAC_DRBG",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "Hacl.HMAC",
"short_module": "HMAC"
},
{
"abbrev": true,
"full_module": "Lib.Sequence",
"short_module": "LSeq"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": false,
"full_module": "Lib.Buffer",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Hash.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let instantiate a st
entropy_input_len entropy_input
nonce_len nonce
personalization_string_len personalization_string
=
match a with
| SHA1 ->
mk_instantiate Hacl.HMAC.legacy_compute_sha1 st
entropy_input_len entropy_input
nonce_len nonce
personalization_string_len personalization_string
| SHA2_256 ->
mk_instantiate Hacl.HMAC.compute_sha2_256 st
entropy_input_len entropy_input
nonce_len nonce
personalization_string_len personalization_string
| SHA2_384 ->
mk_instantiate Hacl.HMAC.compute_sha2_384 st
entropy_input_len entropy_input
nonce_len nonce
personalization_string_len personalization_string
| SHA2_512 ->
mk_instantiate Hacl.HMAC.compute_sha2_512 st
entropy_input_len entropy_input
nonce_len nonce
personalization_string_len personalization_string | val instantiate: a:supported_alg -> instantiate_st a
let instantiate
a
st
entropy_input_len
entropy_input
nonce_len
nonce
personalization_string_len
personalization_string
= | false | null | false | match a with
| SHA1 ->
mk_instantiate Hacl.HMAC.legacy_compute_sha1
st
entropy_input_len
entropy_input
nonce_len
nonce
personalization_string_len
personalization_string
| SHA2_256 ->
mk_instantiate Hacl.HMAC.compute_sha2_256
st
entropy_input_len
entropy_input
nonce_len
nonce
personalization_string_len
personalization_string
| SHA2_384 ->
mk_instantiate Hacl.HMAC.compute_sha2_384
st
entropy_input_len
entropy_input
nonce_len
nonce
personalization_string_len
personalization_string
| SHA2_512 ->
mk_instantiate Hacl.HMAC.compute_sha2_512
st
entropy_input_len
entropy_input
nonce_len
nonce
personalization_string_len
personalization_string | {
"checked_file": "Hacl.HMAC_DRBG.fst.checked",
"dependencies": [
"Spec.HMAC_DRBG.fst.checked",
"Spec.HMAC_DRBG.fst.checked",
"Spec.Hash.Definitions.fst.checked",
"Spec.Agile.HMAC.fsti.checked",
"prims.fst.checked",
"LowStar.Buffer.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.Buffer.fsti.checked",
"Hacl.HMAC.fsti.checked",
"Hacl.Hash.Definitions.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked"
],
"interface_file": true,
"source_file": "Hacl.HMAC_DRBG.fst"
} | [
"total"
] | [
"Hacl.HMAC_DRBG.supported_alg",
"Hacl.HMAC_DRBG.state",
"Lib.IntTypes.size_t",
"Lib.Buffer.lbuffer",
"Lib.IntTypes.uint8",
"Hacl.HMAC_DRBG.mk_instantiate",
"Spec.Hash.Definitions.SHA1",
"Hacl.HMAC.legacy_compute_sha1",
"Prims.unit",
"Spec.Hash.Definitions.SHA2_256",
"Hacl.HMAC.compute_sha2_256",
"Spec.Hash.Definitions.SHA2_384",
"Hacl.HMAC.compute_sha2_384",
"Spec.Hash.Definitions.SHA2_512",
"Hacl.HMAC.compute_sha2_512"
] | [] | module Hacl.HMAC_DRBG
open FStar.HyperStack.ST
module ST = FStar.HyperStack.ST
open Spec.Hash.Definitions
open Lib.IntTypes
open Lib.Buffer
module HS = FStar.HyperStack
module B = LowStar.Buffer
module LSeq = Lib.Sequence
module HMAC = Hacl.HMAC
module S = Spec.HMAC_DRBG
friend Spec.HMAC_DRBG
unfold
let hash_len (a:supported_alg) = Hacl.Hash.Definitions.hash_len a
#set-options "--fuel 0 --ifuel 0 --z3rlimit 50"
inline_for_extraction noextract
val update_round: #a:supported_alg
-> hmac:HMAC.compute_st a
-> len:size_t
-> data:lbuffer uint8 len
-> n:uint8
-> k:lbuffer uint8 (hash_len a)
-> v:lbuffer uint8 (hash_len a)
-> Stack unit
(requires fun h0 ->
live h0 k /\ live h0 v /\ live h0 data /\
disjoint k v /\
// HMAC input length must fit in size_t
hash_length a + 1 + uint_v len + block_length a < pow2 32)
(ensures fun h0 _ h1 ->
S.hmac_input_bound a;
as_seq h1 k == Spec.Agile.HMAC.hmac a
(as_seq h0 k)
(Seq.append (as_seq h0 v) (Seq.cons n (as_seq h0 data))) /\
as_seq h1 v == Spec.Agile.HMAC.hmac a (as_seq h1 k) (as_seq h0 v) /\
modifies2 k v h0 h1)
let update_round #a hmac len data n k v =
let h0 = ST.get() in
push_frame();
let input_len = hash_len a +! 1ul +! len in
let input = create input_len (u8 0) in
let k' = sub input 0ul (hash_len a) in
copy k' v;
if len <> 0ul then copy (sub input (hash_len a +! 1ul) len) data;
input.(hash_len a) <- n;
let h1 = ST.get() in
assert (Seq.equal (as_seq h1 input)
(Seq.append (as_seq h0 v) (Seq.cons n (as_seq h0 data))));
S.hmac_input_bound a;
hmac k' k (hash_len a) input input_len;
hmac v k' (hash_len a) v (hash_len a);
copy k k';
pop_frame()
inline_for_extraction noextract
val update: #a:supported_alg
-> hmac:HMAC.compute_st a
-> len:size_t
-> data:lbuffer uint8 len
-> k:lbuffer uint8 (hash_len a)
-> v:lbuffer uint8 (hash_len a)
-> Stack unit
(requires fun h0 ->
live h0 data /\ live h0 k /\ live h0 v /\
disjoint k v /\ disjoint k data /\ disjoint v data /\
hash_length a + 1 + uint_v len + block_length a < pow2 32)
(ensures fun h0 _ h1 ->
S.hmac_input_bound a;
let k', v' = S.update #a (as_seq h0 data) (as_seq h0 k) (as_seq h0 v) in
modifies2 k v h0 h1 /\
as_seq h1 k == k' /\
as_seq h1 v == v')
let update #a hmac len data k v =
update_round hmac len data (u8 0) k v;
if len <> 0ul then
update_round hmac len data (u8 1) k v
noeq
type state (a:supported_alg) =
| State:
k:lbuffer uint8 (hash_len a)
-> v:lbuffer uint8 (hash_len a)
-> reseed_counter:lbuffer size_t 1ul
{disjoint k v /\ disjoint k reseed_counter /\ disjoint v reseed_counter}
-> state a
let freeable #a st =
let k:B.buffer uint8 = st.k in
let v:B.buffer uint8 = st.v in
let ctr:B.buffer size_t = st.reseed_counter in
B.freeable k /\ B.freeable v /\ B.freeable ctr
let footprint #a st =
let k:B.buffer uint8 = st.k in
let v:B.buffer uint8 = st.v in
let ctr:B.buffer size_t = st.reseed_counter in
B.loc_addr_of_buffer k |+| B.loc_addr_of_buffer v |+| B.loc_addr_of_buffer ctr
let invariant #a st h =
live h st.k /\ live h st.v /\ live h st.reseed_counter /\ (
// JP: the disjoint predicate from lib hardcodes loc_buffer instead of
// loc_addr_of_buffer, which prevents us from writing a proper free function
// (probably why it wasn't written here in the first place)... we add on top
// of the lib-style predicate a non-lib-style predicate which allows writing
// an actual free function
let k = st.k <: B.buffer uint8 in
let v = st.v <: B.buffer uint8 in
let ctr = st.reseed_counter <: B.buffer size_t in
B.(all_disjoint [ loc_addr_of_buffer k; loc_addr_of_buffer v; loc_addr_of_buffer ctr ]))
let repr #a st h =
S.State (as_seq h st.k) (as_seq h st.v) (v (bget h st.reseed_counter 0))
let alloca a =
let k =
match a with
| SHA1 -> create (hash_len SHA1) (u8 0)
| SHA2_256 -> create (hash_len SHA2_256) (u8 0)
| SHA2_384 -> create (hash_len SHA2_384) (u8 0)
| SHA2_512 -> create (hash_len SHA2_512) (u8 0)
in
let v =
match a with
| SHA1 -> create (hash_len SHA1) (u8 0)
| SHA2_256 -> create (hash_len SHA2_256) (u8 0)
| SHA2_384 -> create (hash_len SHA2_384) (u8 0)
| SHA2_512 -> create (hash_len SHA2_512) (u8 0)
in
let ctr = create 1ul 1ul in
State k v ctr
let create_in a r =
let k:B.buffer uint8 =
match a with
| SHA1 -> B.malloc r (u8 0) (hash_len SHA1)
| SHA2_256 -> B.malloc r (u8 0) (hash_len SHA2_256)
| SHA2_384 -> B.malloc r (u8 0) (hash_len SHA2_384)
| SHA2_512 -> B.malloc r (u8 0) (hash_len SHA2_512)
in
let v:B.buffer uint8 =
match a with
| SHA1 -> B.malloc r (u8 0) (hash_len SHA1)
| SHA2_256 -> B.malloc r (u8 0) (hash_len SHA2_256)
| SHA2_384 -> B.malloc r (u8 0) (hash_len SHA2_384)
| SHA2_512 -> B.malloc r (u8 0) (hash_len SHA2_512)
in
let ctr:B.buffer size_t = B.malloc r 1ul 1ul in
State k v ctr
#push-options "--z3rlimit 200"
let mk_instantiate #a hmac st
entropy_input_len entropy_input
nonce_len nonce
personalization_string_len personalization_string
=
let h0 = ST.get () in
push_frame();
let seed_material = create (entropy_input_len +! nonce_len +! personalization_string_len) (u8 0) in
copy (sub seed_material 0ul entropy_input_len) entropy_input;
copy (sub seed_material entropy_input_len nonce_len) nonce;
copy (sub seed_material (entropy_input_len +! nonce_len) personalization_string_len) personalization_string;
let State k v ctr = st in
memset k (u8 0) (hash_len a);
memset v (u8 1) (hash_len a);
let h1 = ST.get () in
assert (Seq.equal (as_seq h1 seed_material)
(Seq.append (as_seq h0 entropy_input) (Seq.append (as_seq h0 nonce)
(as_seq h0 personalization_string))));
assert (LSeq.equal (as_seq h1 k) (LSeq.create (hash_length a) (u8 0)));
assert (LSeq.equal (as_seq h1 v) (LSeq.create (hash_length a) (u8 1)));
ctr.(0ul) <- 1ul;
update hmac (entropy_input_len +! nonce_len +! personalization_string_len)
seed_material k v;
pop_frame()
#pop-options
let instantiate a st
entropy_input_len entropy_input
nonce_len nonce
personalization_string_len personalization_string | false | false | Hacl.HMAC_DRBG.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val instantiate: a:supported_alg -> instantiate_st a | [] | Hacl.HMAC_DRBG.instantiate | {
"file_name": "code/drbg/Hacl.HMAC_DRBG.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | a: Hacl.HMAC_DRBG.supported_alg -> Hacl.HMAC_DRBG.instantiate_st a | {
"end_col": 55,
"end_line": 217,
"start_col": 2,
"start_line": 197
} |
Prims.Tot | [
{
"abbrev": true,
"full_module": "Spec.HMAC_DRBG",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "Hacl.HMAC",
"short_module": "HMAC"
},
{
"abbrev": true,
"full_module": "Lib.Sequence",
"short_module": "LSeq"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": false,
"full_module": "Lib.Buffer",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Hash.Definitions",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": true,
"full_module": "Spec.HMAC_DRBG",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "Hacl.HMAC",
"short_module": "HMAC"
},
{
"abbrev": true,
"full_module": "Lib.Sequence",
"short_module": "LSeq"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": false,
"full_module": "Lib.Buffer",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Hash.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let hash_len (a:supported_alg) = Hacl.Hash.Definitions.hash_len a | let hash_len (a: supported_alg) = | false | null | false | Hacl.Hash.Definitions.hash_len a | {
"checked_file": "Hacl.HMAC_DRBG.fst.checked",
"dependencies": [
"Spec.HMAC_DRBG.fst.checked",
"Spec.HMAC_DRBG.fst.checked",
"Spec.Hash.Definitions.fst.checked",
"Spec.Agile.HMAC.fsti.checked",
"prims.fst.checked",
"LowStar.Buffer.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.Buffer.fsti.checked",
"Hacl.HMAC.fsti.checked",
"Hacl.Hash.Definitions.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked"
],
"interface_file": true,
"source_file": "Hacl.HMAC_DRBG.fst"
} | [
"total"
] | [
"Hacl.HMAC_DRBG.supported_alg",
"Hacl.Hash.Definitions.hash_len",
"Lib.IntTypes.size_t",
"Prims.b2t",
"Prims.op_Equality",
"Prims.int",
"Prims.l_or",
"Lib.IntTypes.range",
"Lib.IntTypes.U32",
"Prims.l_and",
"Prims.op_GreaterThanOrEqual",
"Prims.op_LessThanOrEqual",
"Lib.IntTypes.max_size_t",
"Prims.op_GreaterThan",
"Lib.IntTypes.v",
"Lib.IntTypes.PUB",
"Spec.Hash.Definitions.hash_length"
] | [] | module Hacl.HMAC_DRBG
open FStar.HyperStack.ST
module ST = FStar.HyperStack.ST
open Spec.Hash.Definitions
open Lib.IntTypes
open Lib.Buffer
module HS = FStar.HyperStack
module B = LowStar.Buffer
module LSeq = Lib.Sequence
module HMAC = Hacl.HMAC
module S = Spec.HMAC_DRBG
friend Spec.HMAC_DRBG | false | false | Hacl.HMAC_DRBG.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val hash_len : a: Hacl.HMAC_DRBG.supported_alg
-> n: Lib.IntTypes.size_t{Lib.IntTypes.v n = Spec.Hash.Definitions.hash_length a} | [] | Hacl.HMAC_DRBG.hash_len | {
"file_name": "code/drbg/Hacl.HMAC_DRBG.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | a: Hacl.HMAC_DRBG.supported_alg
-> n: Lib.IntTypes.size_t{Lib.IntTypes.v n = Spec.Hash.Definitions.hash_length a} | {
"end_col": 65,
"end_line": 21,
"start_col": 33,
"start_line": 21
} |
|
Prims.GTot | val footprint: #a:supported_alg -> st:state a -> GTot B.loc | [
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": true,
"full_module": "Spec.HMAC_DRBG",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "Hacl.HMAC",
"short_module": "HMAC"
},
{
"abbrev": true,
"full_module": "Lib.Sequence",
"short_module": "LSeq"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": false,
"full_module": "Lib.Buffer",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Hash.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let footprint #a st =
let k:B.buffer uint8 = st.k in
let v:B.buffer uint8 = st.v in
let ctr:B.buffer size_t = st.reseed_counter in
B.loc_addr_of_buffer k |+| B.loc_addr_of_buffer v |+| B.loc_addr_of_buffer ctr | val footprint: #a:supported_alg -> st:state a -> GTot B.loc
let footprint #a st = | false | null | false | let k:B.buffer uint8 = st.k in
let v:B.buffer uint8 = st.v in
let ctr:B.buffer size_t = st.reseed_counter in
B.loc_addr_of_buffer k |+| B.loc_addr_of_buffer v |+| B.loc_addr_of_buffer ctr | {
"checked_file": "Hacl.HMAC_DRBG.fst.checked",
"dependencies": [
"Spec.HMAC_DRBG.fst.checked",
"Spec.HMAC_DRBG.fst.checked",
"Spec.Hash.Definitions.fst.checked",
"Spec.Agile.HMAC.fsti.checked",
"prims.fst.checked",
"LowStar.Buffer.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.Buffer.fsti.checked",
"Hacl.HMAC.fsti.checked",
"Hacl.Hash.Definitions.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked"
],
"interface_file": true,
"source_file": "Hacl.HMAC_DRBG.fst"
} | [
"sometrivial"
] | [
"Hacl.HMAC_DRBG.supported_alg",
"Hacl.HMAC_DRBG.state",
"Lib.Buffer.op_Bar_Plus_Bar",
"LowStar.Monotonic.Buffer.loc_addr_of_buffer",
"Lib.IntTypes.int_t",
"Lib.IntTypes.U8",
"Lib.IntTypes.SEC",
"LowStar.Buffer.trivial_preorder",
"Lib.IntTypes.U32",
"Lib.IntTypes.PUB",
"LowStar.Buffer.buffer",
"Hacl.HMAC_DRBG.__proj__State__item__reseed_counter",
"Hacl.HMAC_DRBG.__proj__State__item__v",
"Hacl.HMAC_DRBG.__proj__State__item__k",
"LowStar.Monotonic.Buffer.loc"
] | [] | module Hacl.HMAC_DRBG
open FStar.HyperStack.ST
module ST = FStar.HyperStack.ST
open Spec.Hash.Definitions
open Lib.IntTypes
open Lib.Buffer
module HS = FStar.HyperStack
module B = LowStar.Buffer
module LSeq = Lib.Sequence
module HMAC = Hacl.HMAC
module S = Spec.HMAC_DRBG
friend Spec.HMAC_DRBG
unfold
let hash_len (a:supported_alg) = Hacl.Hash.Definitions.hash_len a
#set-options "--fuel 0 --ifuel 0 --z3rlimit 50"
inline_for_extraction noextract
val update_round: #a:supported_alg
-> hmac:HMAC.compute_st a
-> len:size_t
-> data:lbuffer uint8 len
-> n:uint8
-> k:lbuffer uint8 (hash_len a)
-> v:lbuffer uint8 (hash_len a)
-> Stack unit
(requires fun h0 ->
live h0 k /\ live h0 v /\ live h0 data /\
disjoint k v /\
// HMAC input length must fit in size_t
hash_length a + 1 + uint_v len + block_length a < pow2 32)
(ensures fun h0 _ h1 ->
S.hmac_input_bound a;
as_seq h1 k == Spec.Agile.HMAC.hmac a
(as_seq h0 k)
(Seq.append (as_seq h0 v) (Seq.cons n (as_seq h0 data))) /\
as_seq h1 v == Spec.Agile.HMAC.hmac a (as_seq h1 k) (as_seq h0 v) /\
modifies2 k v h0 h1)
let update_round #a hmac len data n k v =
let h0 = ST.get() in
push_frame();
let input_len = hash_len a +! 1ul +! len in
let input = create input_len (u8 0) in
let k' = sub input 0ul (hash_len a) in
copy k' v;
if len <> 0ul then copy (sub input (hash_len a +! 1ul) len) data;
input.(hash_len a) <- n;
let h1 = ST.get() in
assert (Seq.equal (as_seq h1 input)
(Seq.append (as_seq h0 v) (Seq.cons n (as_seq h0 data))));
S.hmac_input_bound a;
hmac k' k (hash_len a) input input_len;
hmac v k' (hash_len a) v (hash_len a);
copy k k';
pop_frame()
inline_for_extraction noextract
val update: #a:supported_alg
-> hmac:HMAC.compute_st a
-> len:size_t
-> data:lbuffer uint8 len
-> k:lbuffer uint8 (hash_len a)
-> v:lbuffer uint8 (hash_len a)
-> Stack unit
(requires fun h0 ->
live h0 data /\ live h0 k /\ live h0 v /\
disjoint k v /\ disjoint k data /\ disjoint v data /\
hash_length a + 1 + uint_v len + block_length a < pow2 32)
(ensures fun h0 _ h1 ->
S.hmac_input_bound a;
let k', v' = S.update #a (as_seq h0 data) (as_seq h0 k) (as_seq h0 v) in
modifies2 k v h0 h1 /\
as_seq h1 k == k' /\
as_seq h1 v == v')
let update #a hmac len data k v =
update_round hmac len data (u8 0) k v;
if len <> 0ul then
update_round hmac len data (u8 1) k v
noeq
type state (a:supported_alg) =
| State:
k:lbuffer uint8 (hash_len a)
-> v:lbuffer uint8 (hash_len a)
-> reseed_counter:lbuffer size_t 1ul
{disjoint k v /\ disjoint k reseed_counter /\ disjoint v reseed_counter}
-> state a
let freeable #a st =
let k:B.buffer uint8 = st.k in
let v:B.buffer uint8 = st.v in
let ctr:B.buffer size_t = st.reseed_counter in
B.freeable k /\ B.freeable v /\ B.freeable ctr | false | false | Hacl.HMAC_DRBG.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val footprint: #a:supported_alg -> st:state a -> GTot B.loc | [] | Hacl.HMAC_DRBG.footprint | {
"file_name": "code/drbg/Hacl.HMAC_DRBG.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | st: Hacl.HMAC_DRBG.state a -> Prims.GTot LowStar.Monotonic.Buffer.loc | {
"end_col": 80,
"end_line": 110,
"start_col": 21,
"start_line": 106
} |
Prims.Tot | val freeable: #a:supported_alg -> st:state a -> Type0 | [
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": true,
"full_module": "Spec.HMAC_DRBG",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "Hacl.HMAC",
"short_module": "HMAC"
},
{
"abbrev": true,
"full_module": "Lib.Sequence",
"short_module": "LSeq"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": false,
"full_module": "Lib.Buffer",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Hash.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let freeable #a st =
let k:B.buffer uint8 = st.k in
let v:B.buffer uint8 = st.v in
let ctr:B.buffer size_t = st.reseed_counter in
B.freeable k /\ B.freeable v /\ B.freeable ctr | val freeable: #a:supported_alg -> st:state a -> Type0
let freeable #a st = | false | null | false | let k:B.buffer uint8 = st.k in
let v:B.buffer uint8 = st.v in
let ctr:B.buffer size_t = st.reseed_counter in
B.freeable k /\ B.freeable v /\ B.freeable ctr | {
"checked_file": "Hacl.HMAC_DRBG.fst.checked",
"dependencies": [
"Spec.HMAC_DRBG.fst.checked",
"Spec.HMAC_DRBG.fst.checked",
"Spec.Hash.Definitions.fst.checked",
"Spec.Agile.HMAC.fsti.checked",
"prims.fst.checked",
"LowStar.Buffer.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.Buffer.fsti.checked",
"Hacl.HMAC.fsti.checked",
"Hacl.Hash.Definitions.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked"
],
"interface_file": true,
"source_file": "Hacl.HMAC_DRBG.fst"
} | [
"total"
] | [
"Hacl.HMAC_DRBG.supported_alg",
"Hacl.HMAC_DRBG.state",
"Prims.l_and",
"LowStar.Monotonic.Buffer.freeable",
"Lib.IntTypes.int_t",
"Lib.IntTypes.U8",
"Lib.IntTypes.SEC",
"LowStar.Buffer.trivial_preorder",
"Lib.IntTypes.U32",
"Lib.IntTypes.PUB",
"LowStar.Buffer.buffer",
"Hacl.HMAC_DRBG.__proj__State__item__reseed_counter",
"Hacl.HMAC_DRBG.__proj__State__item__v",
"Hacl.HMAC_DRBG.__proj__State__item__k"
] | [] | module Hacl.HMAC_DRBG
open FStar.HyperStack.ST
module ST = FStar.HyperStack.ST
open Spec.Hash.Definitions
open Lib.IntTypes
open Lib.Buffer
module HS = FStar.HyperStack
module B = LowStar.Buffer
module LSeq = Lib.Sequence
module HMAC = Hacl.HMAC
module S = Spec.HMAC_DRBG
friend Spec.HMAC_DRBG
unfold
let hash_len (a:supported_alg) = Hacl.Hash.Definitions.hash_len a
#set-options "--fuel 0 --ifuel 0 --z3rlimit 50"
inline_for_extraction noextract
val update_round: #a:supported_alg
-> hmac:HMAC.compute_st a
-> len:size_t
-> data:lbuffer uint8 len
-> n:uint8
-> k:lbuffer uint8 (hash_len a)
-> v:lbuffer uint8 (hash_len a)
-> Stack unit
(requires fun h0 ->
live h0 k /\ live h0 v /\ live h0 data /\
disjoint k v /\
// HMAC input length must fit in size_t
hash_length a + 1 + uint_v len + block_length a < pow2 32)
(ensures fun h0 _ h1 ->
S.hmac_input_bound a;
as_seq h1 k == Spec.Agile.HMAC.hmac a
(as_seq h0 k)
(Seq.append (as_seq h0 v) (Seq.cons n (as_seq h0 data))) /\
as_seq h1 v == Spec.Agile.HMAC.hmac a (as_seq h1 k) (as_seq h0 v) /\
modifies2 k v h0 h1)
let update_round #a hmac len data n k v =
let h0 = ST.get() in
push_frame();
let input_len = hash_len a +! 1ul +! len in
let input = create input_len (u8 0) in
let k' = sub input 0ul (hash_len a) in
copy k' v;
if len <> 0ul then copy (sub input (hash_len a +! 1ul) len) data;
input.(hash_len a) <- n;
let h1 = ST.get() in
assert (Seq.equal (as_seq h1 input)
(Seq.append (as_seq h0 v) (Seq.cons n (as_seq h0 data))));
S.hmac_input_bound a;
hmac k' k (hash_len a) input input_len;
hmac v k' (hash_len a) v (hash_len a);
copy k k';
pop_frame()
inline_for_extraction noextract
val update: #a:supported_alg
-> hmac:HMAC.compute_st a
-> len:size_t
-> data:lbuffer uint8 len
-> k:lbuffer uint8 (hash_len a)
-> v:lbuffer uint8 (hash_len a)
-> Stack unit
(requires fun h0 ->
live h0 data /\ live h0 k /\ live h0 v /\
disjoint k v /\ disjoint k data /\ disjoint v data /\
hash_length a + 1 + uint_v len + block_length a < pow2 32)
(ensures fun h0 _ h1 ->
S.hmac_input_bound a;
let k', v' = S.update #a (as_seq h0 data) (as_seq h0 k) (as_seq h0 v) in
modifies2 k v h0 h1 /\
as_seq h1 k == k' /\
as_seq h1 v == v')
let update #a hmac len data k v =
update_round hmac len data (u8 0) k v;
if len <> 0ul then
update_round hmac len data (u8 1) k v
noeq
type state (a:supported_alg) =
| State:
k:lbuffer uint8 (hash_len a)
-> v:lbuffer uint8 (hash_len a)
-> reseed_counter:lbuffer size_t 1ul
{disjoint k v /\ disjoint k reseed_counter /\ disjoint v reseed_counter}
-> state a | false | false | Hacl.HMAC_DRBG.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val freeable: #a:supported_alg -> st:state a -> Type0 | [] | Hacl.HMAC_DRBG.freeable | {
"file_name": "code/drbg/Hacl.HMAC_DRBG.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | st: Hacl.HMAC_DRBG.state a -> Type0 | {
"end_col": 48,
"end_line": 104,
"start_col": 20,
"start_line": 100
} |
Prims.GTot | val repr: #a:supported_alg -> st:state a -> h:HS.mem -> GTot (S.state a) | [
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": true,
"full_module": "Spec.HMAC_DRBG",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "Hacl.HMAC",
"short_module": "HMAC"
},
{
"abbrev": true,
"full_module": "Lib.Sequence",
"short_module": "LSeq"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": false,
"full_module": "Lib.Buffer",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Hash.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let repr #a st h =
S.State (as_seq h st.k) (as_seq h st.v) (v (bget h st.reseed_counter 0)) | val repr: #a:supported_alg -> st:state a -> h:HS.mem -> GTot (S.state a)
let repr #a st h = | false | null | false | S.State (as_seq h st.k) (as_seq h st.v) (v (bget h st.reseed_counter 0)) | {
"checked_file": "Hacl.HMAC_DRBG.fst.checked",
"dependencies": [
"Spec.HMAC_DRBG.fst.checked",
"Spec.HMAC_DRBG.fst.checked",
"Spec.Hash.Definitions.fst.checked",
"Spec.Agile.HMAC.fsti.checked",
"prims.fst.checked",
"LowStar.Buffer.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.Buffer.fsti.checked",
"Hacl.HMAC.fsti.checked",
"Hacl.Hash.Definitions.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked"
],
"interface_file": true,
"source_file": "Hacl.HMAC_DRBG.fst"
} | [
"sometrivial"
] | [
"Hacl.HMAC_DRBG.supported_alg",
"Hacl.HMAC_DRBG.state",
"FStar.Monotonic.HyperStack.mem",
"Spec.HMAC_DRBG.State",
"Lib.Buffer.as_seq",
"Lib.Buffer.MUT",
"Lib.IntTypes.uint8",
"Hacl.HMAC_DRBG.hash_len",
"Hacl.HMAC_DRBG.__proj__State__item__k",
"Hacl.HMAC_DRBG.__proj__State__item__v",
"Lib.IntTypes.v",
"Lib.IntTypes.U32",
"Lib.IntTypes.PUB",
"Lib.Buffer.bget",
"Lib.IntTypes.size_t",
"FStar.UInt32.__uint_to_t",
"Hacl.HMAC_DRBG.__proj__State__item__reseed_counter",
"Spec.HMAC_DRBG.state"
] | [] | module Hacl.HMAC_DRBG
open FStar.HyperStack.ST
module ST = FStar.HyperStack.ST
open Spec.Hash.Definitions
open Lib.IntTypes
open Lib.Buffer
module HS = FStar.HyperStack
module B = LowStar.Buffer
module LSeq = Lib.Sequence
module HMAC = Hacl.HMAC
module S = Spec.HMAC_DRBG
friend Spec.HMAC_DRBG
unfold
let hash_len (a:supported_alg) = Hacl.Hash.Definitions.hash_len a
#set-options "--fuel 0 --ifuel 0 --z3rlimit 50"
inline_for_extraction noextract
val update_round: #a:supported_alg
-> hmac:HMAC.compute_st a
-> len:size_t
-> data:lbuffer uint8 len
-> n:uint8
-> k:lbuffer uint8 (hash_len a)
-> v:lbuffer uint8 (hash_len a)
-> Stack unit
(requires fun h0 ->
live h0 k /\ live h0 v /\ live h0 data /\
disjoint k v /\
// HMAC input length must fit in size_t
hash_length a + 1 + uint_v len + block_length a < pow2 32)
(ensures fun h0 _ h1 ->
S.hmac_input_bound a;
as_seq h1 k == Spec.Agile.HMAC.hmac a
(as_seq h0 k)
(Seq.append (as_seq h0 v) (Seq.cons n (as_seq h0 data))) /\
as_seq h1 v == Spec.Agile.HMAC.hmac a (as_seq h1 k) (as_seq h0 v) /\
modifies2 k v h0 h1)
let update_round #a hmac len data n k v =
let h0 = ST.get() in
push_frame();
let input_len = hash_len a +! 1ul +! len in
let input = create input_len (u8 0) in
let k' = sub input 0ul (hash_len a) in
copy k' v;
if len <> 0ul then copy (sub input (hash_len a +! 1ul) len) data;
input.(hash_len a) <- n;
let h1 = ST.get() in
assert (Seq.equal (as_seq h1 input)
(Seq.append (as_seq h0 v) (Seq.cons n (as_seq h0 data))));
S.hmac_input_bound a;
hmac k' k (hash_len a) input input_len;
hmac v k' (hash_len a) v (hash_len a);
copy k k';
pop_frame()
inline_for_extraction noextract
val update: #a:supported_alg
-> hmac:HMAC.compute_st a
-> len:size_t
-> data:lbuffer uint8 len
-> k:lbuffer uint8 (hash_len a)
-> v:lbuffer uint8 (hash_len a)
-> Stack unit
(requires fun h0 ->
live h0 data /\ live h0 k /\ live h0 v /\
disjoint k v /\ disjoint k data /\ disjoint v data /\
hash_length a + 1 + uint_v len + block_length a < pow2 32)
(ensures fun h0 _ h1 ->
S.hmac_input_bound a;
let k', v' = S.update #a (as_seq h0 data) (as_seq h0 k) (as_seq h0 v) in
modifies2 k v h0 h1 /\
as_seq h1 k == k' /\
as_seq h1 v == v')
let update #a hmac len data k v =
update_round hmac len data (u8 0) k v;
if len <> 0ul then
update_round hmac len data (u8 1) k v
noeq
type state (a:supported_alg) =
| State:
k:lbuffer uint8 (hash_len a)
-> v:lbuffer uint8 (hash_len a)
-> reseed_counter:lbuffer size_t 1ul
{disjoint k v /\ disjoint k reseed_counter /\ disjoint v reseed_counter}
-> state a
let freeable #a st =
let k:B.buffer uint8 = st.k in
let v:B.buffer uint8 = st.v in
let ctr:B.buffer size_t = st.reseed_counter in
B.freeable k /\ B.freeable v /\ B.freeable ctr
let footprint #a st =
let k:B.buffer uint8 = st.k in
let v:B.buffer uint8 = st.v in
let ctr:B.buffer size_t = st.reseed_counter in
B.loc_addr_of_buffer k |+| B.loc_addr_of_buffer v |+| B.loc_addr_of_buffer ctr
let invariant #a st h =
live h st.k /\ live h st.v /\ live h st.reseed_counter /\ (
// JP: the disjoint predicate from lib hardcodes loc_buffer instead of
// loc_addr_of_buffer, which prevents us from writing a proper free function
// (probably why it wasn't written here in the first place)... we add on top
// of the lib-style predicate a non-lib-style predicate which allows writing
// an actual free function
let k = st.k <: B.buffer uint8 in
let v = st.v <: B.buffer uint8 in
let ctr = st.reseed_counter <: B.buffer size_t in
B.(all_disjoint [ loc_addr_of_buffer k; loc_addr_of_buffer v; loc_addr_of_buffer ctr ])) | false | false | Hacl.HMAC_DRBG.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val repr: #a:supported_alg -> st:state a -> h:HS.mem -> GTot (S.state a) | [] | Hacl.HMAC_DRBG.repr | {
"file_name": "code/drbg/Hacl.HMAC_DRBG.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | st: Hacl.HMAC_DRBG.state a -> h: FStar.Monotonic.HyperStack.mem
-> Prims.GTot (Spec.HMAC_DRBG.state a) | {
"end_col": 74,
"end_line": 125,
"start_col": 2,
"start_line": 125
} |
Prims.Tot | val free: #a:supported_alg -> free_st a | [
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": true,
"full_module": "Spec.HMAC_DRBG",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "Hacl.HMAC",
"short_module": "HMAC"
},
{
"abbrev": true,
"full_module": "Lib.Sequence",
"short_module": "LSeq"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": false,
"full_module": "Lib.Buffer",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Hash.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let free #_ s =
let State k v ctr = s in
B.free (k <: B.buffer uint8);
B.free (v <: B.buffer uint8);
B.free (ctr <: B.buffer size_t) | val free: #a:supported_alg -> free_st a
let free #_ s = | false | null | false | let State k v ctr = s in
B.free (k <: B.buffer uint8);
B.free (v <: B.buffer uint8);
B.free (ctr <: B.buffer size_t) | {
"checked_file": "Hacl.HMAC_DRBG.fst.checked",
"dependencies": [
"Spec.HMAC_DRBG.fst.checked",
"Spec.HMAC_DRBG.fst.checked",
"Spec.Hash.Definitions.fst.checked",
"Spec.Agile.HMAC.fsti.checked",
"prims.fst.checked",
"LowStar.Buffer.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.Buffer.fsti.checked",
"Hacl.HMAC.fsti.checked",
"Hacl.Hash.Definitions.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked"
],
"interface_file": true,
"source_file": "Hacl.HMAC_DRBG.fst"
} | [
"total"
] | [
"Hacl.HMAC_DRBG.supported_alg",
"Hacl.HMAC_DRBG.state",
"Lib.Buffer.lbuffer",
"Lib.IntTypes.uint8",
"Hacl.HMAC_DRBG.hash_len",
"Lib.IntTypes.size_t",
"FStar.UInt32.__uint_to_t",
"Prims.l_and",
"Lib.Buffer.disjoint",
"Lib.Buffer.MUT",
"LowStar.Monotonic.Buffer.free",
"LowStar.Buffer.trivial_preorder",
"LowStar.Buffer.buffer",
"Prims.unit"
] | [] | module Hacl.HMAC_DRBG
open FStar.HyperStack.ST
module ST = FStar.HyperStack.ST
open Spec.Hash.Definitions
open Lib.IntTypes
open Lib.Buffer
module HS = FStar.HyperStack
module B = LowStar.Buffer
module LSeq = Lib.Sequence
module HMAC = Hacl.HMAC
module S = Spec.HMAC_DRBG
friend Spec.HMAC_DRBG
unfold
let hash_len (a:supported_alg) = Hacl.Hash.Definitions.hash_len a
#set-options "--fuel 0 --ifuel 0 --z3rlimit 50"
inline_for_extraction noextract
val update_round: #a:supported_alg
-> hmac:HMAC.compute_st a
-> len:size_t
-> data:lbuffer uint8 len
-> n:uint8
-> k:lbuffer uint8 (hash_len a)
-> v:lbuffer uint8 (hash_len a)
-> Stack unit
(requires fun h0 ->
live h0 k /\ live h0 v /\ live h0 data /\
disjoint k v /\
// HMAC input length must fit in size_t
hash_length a + 1 + uint_v len + block_length a < pow2 32)
(ensures fun h0 _ h1 ->
S.hmac_input_bound a;
as_seq h1 k == Spec.Agile.HMAC.hmac a
(as_seq h0 k)
(Seq.append (as_seq h0 v) (Seq.cons n (as_seq h0 data))) /\
as_seq h1 v == Spec.Agile.HMAC.hmac a (as_seq h1 k) (as_seq h0 v) /\
modifies2 k v h0 h1)
let update_round #a hmac len data n k v =
let h0 = ST.get() in
push_frame();
let input_len = hash_len a +! 1ul +! len in
let input = create input_len (u8 0) in
let k' = sub input 0ul (hash_len a) in
copy k' v;
if len <> 0ul then copy (sub input (hash_len a +! 1ul) len) data;
input.(hash_len a) <- n;
let h1 = ST.get() in
assert (Seq.equal (as_seq h1 input)
(Seq.append (as_seq h0 v) (Seq.cons n (as_seq h0 data))));
S.hmac_input_bound a;
hmac k' k (hash_len a) input input_len;
hmac v k' (hash_len a) v (hash_len a);
copy k k';
pop_frame()
inline_for_extraction noextract
val update: #a:supported_alg
-> hmac:HMAC.compute_st a
-> len:size_t
-> data:lbuffer uint8 len
-> k:lbuffer uint8 (hash_len a)
-> v:lbuffer uint8 (hash_len a)
-> Stack unit
(requires fun h0 ->
live h0 data /\ live h0 k /\ live h0 v /\
disjoint k v /\ disjoint k data /\ disjoint v data /\
hash_length a + 1 + uint_v len + block_length a < pow2 32)
(ensures fun h0 _ h1 ->
S.hmac_input_bound a;
let k', v' = S.update #a (as_seq h0 data) (as_seq h0 k) (as_seq h0 v) in
modifies2 k v h0 h1 /\
as_seq h1 k == k' /\
as_seq h1 v == v')
let update #a hmac len data k v =
update_round hmac len data (u8 0) k v;
if len <> 0ul then
update_round hmac len data (u8 1) k v
noeq
type state (a:supported_alg) =
| State:
k:lbuffer uint8 (hash_len a)
-> v:lbuffer uint8 (hash_len a)
-> reseed_counter:lbuffer size_t 1ul
{disjoint k v /\ disjoint k reseed_counter /\ disjoint v reseed_counter}
-> state a
let freeable #a st =
let k:B.buffer uint8 = st.k in
let v:B.buffer uint8 = st.v in
let ctr:B.buffer size_t = st.reseed_counter in
B.freeable k /\ B.freeable v /\ B.freeable ctr
let footprint #a st =
let k:B.buffer uint8 = st.k in
let v:B.buffer uint8 = st.v in
let ctr:B.buffer size_t = st.reseed_counter in
B.loc_addr_of_buffer k |+| B.loc_addr_of_buffer v |+| B.loc_addr_of_buffer ctr
let invariant #a st h =
live h st.k /\ live h st.v /\ live h st.reseed_counter /\ (
// JP: the disjoint predicate from lib hardcodes loc_buffer instead of
// loc_addr_of_buffer, which prevents us from writing a proper free function
// (probably why it wasn't written here in the first place)... we add on top
// of the lib-style predicate a non-lib-style predicate which allows writing
// an actual free function
let k = st.k <: B.buffer uint8 in
let v = st.v <: B.buffer uint8 in
let ctr = st.reseed_counter <: B.buffer size_t in
B.(all_disjoint [ loc_addr_of_buffer k; loc_addr_of_buffer v; loc_addr_of_buffer ctr ]))
let repr #a st h =
S.State (as_seq h st.k) (as_seq h st.v) (v (bget h st.reseed_counter 0))
let alloca a =
let k =
match a with
| SHA1 -> create (hash_len SHA1) (u8 0)
| SHA2_256 -> create (hash_len SHA2_256) (u8 0)
| SHA2_384 -> create (hash_len SHA2_384) (u8 0)
| SHA2_512 -> create (hash_len SHA2_512) (u8 0)
in
let v =
match a with
| SHA1 -> create (hash_len SHA1) (u8 0)
| SHA2_256 -> create (hash_len SHA2_256) (u8 0)
| SHA2_384 -> create (hash_len SHA2_384) (u8 0)
| SHA2_512 -> create (hash_len SHA2_512) (u8 0)
in
let ctr = create 1ul 1ul in
State k v ctr
let create_in a r =
let k:B.buffer uint8 =
match a with
| SHA1 -> B.malloc r (u8 0) (hash_len SHA1)
| SHA2_256 -> B.malloc r (u8 0) (hash_len SHA2_256)
| SHA2_384 -> B.malloc r (u8 0) (hash_len SHA2_384)
| SHA2_512 -> B.malloc r (u8 0) (hash_len SHA2_512)
in
let v:B.buffer uint8 =
match a with
| SHA1 -> B.malloc r (u8 0) (hash_len SHA1)
| SHA2_256 -> B.malloc r (u8 0) (hash_len SHA2_256)
| SHA2_384 -> B.malloc r (u8 0) (hash_len SHA2_384)
| SHA2_512 -> B.malloc r (u8 0) (hash_len SHA2_512)
in
let ctr:B.buffer size_t = B.malloc r 1ul 1ul in
State k v ctr
#push-options "--z3rlimit 200"
let mk_instantiate #a hmac st
entropy_input_len entropy_input
nonce_len nonce
personalization_string_len personalization_string
=
let h0 = ST.get () in
push_frame();
let seed_material = create (entropy_input_len +! nonce_len +! personalization_string_len) (u8 0) in
copy (sub seed_material 0ul entropy_input_len) entropy_input;
copy (sub seed_material entropy_input_len nonce_len) nonce;
copy (sub seed_material (entropy_input_len +! nonce_len) personalization_string_len) personalization_string;
let State k v ctr = st in
memset k (u8 0) (hash_len a);
memset v (u8 1) (hash_len a);
let h1 = ST.get () in
assert (Seq.equal (as_seq h1 seed_material)
(Seq.append (as_seq h0 entropy_input) (Seq.append (as_seq h0 nonce)
(as_seq h0 personalization_string))));
assert (LSeq.equal (as_seq h1 k) (LSeq.create (hash_length a) (u8 0)));
assert (LSeq.equal (as_seq h1 v) (LSeq.create (hash_length a) (u8 1)));
ctr.(0ul) <- 1ul;
update hmac (entropy_input_len +! nonce_len +! personalization_string_len)
seed_material k v;
pop_frame()
#pop-options
let instantiate a st
entropy_input_len entropy_input
nonce_len nonce
personalization_string_len personalization_string
=
match a with
| SHA1 ->
mk_instantiate Hacl.HMAC.legacy_compute_sha1 st
entropy_input_len entropy_input
nonce_len nonce
personalization_string_len personalization_string
| SHA2_256 ->
mk_instantiate Hacl.HMAC.compute_sha2_256 st
entropy_input_len entropy_input
nonce_len nonce
personalization_string_len personalization_string
| SHA2_384 ->
mk_instantiate Hacl.HMAC.compute_sha2_384 st
entropy_input_len entropy_input
nonce_len nonce
personalization_string_len personalization_string
| SHA2_512 ->
mk_instantiate Hacl.HMAC.compute_sha2_512 st
entropy_input_len entropy_input
nonce_len nonce
personalization_string_len personalization_string
let mk_reseed #a hmac st
entropy_input_len entropy_input
additional_input_len additional_input
=
let h0 = ST.get () in
push_frame();
let seed_material = create (entropy_input_len +! additional_input_len) (u8 0) in
copy (sub seed_material 0ul entropy_input_len) entropy_input;
copy (sub seed_material entropy_input_len additional_input_len) additional_input;
let h1 = ST.get () in
LSeq.eq_intro (as_seq h1 seed_material)
LSeq.(as_seq h0 entropy_input @| as_seq h0 additional_input);
let State k v ctr: state a = st in
update hmac (entropy_input_len +! additional_input_len) seed_material k v;
ctr.(0ul) <- 1ul;
pop_frame()
let reseed a st
entropy_input_len entropy_input
additional_input_input_len additional_input_input =
match a with
| SHA1 ->
mk_reseed Hacl.HMAC.legacy_compute_sha1 st
entropy_input_len entropy_input
additional_input_input_len additional_input_input
| SHA2_256 ->
mk_reseed Hacl.HMAC.compute_sha2_256 st
entropy_input_len entropy_input
additional_input_input_len additional_input_input
| SHA2_384 ->
mk_reseed Hacl.HMAC.compute_sha2_384 st
entropy_input_len entropy_input
additional_input_input_len additional_input_input
| SHA2_512 ->
mk_reseed Hacl.HMAC.compute_sha2_512 st
entropy_input_len entropy_input
additional_input_input_len additional_input_input
#push-options "--z3rlimit 300"
let mk_generate #a hmac output st n additional_input_len additional_input =
if st.reseed_counter.(0ul) >. reseed_interval then
false
else
begin
S.hmac_input_bound a;
Math.Lemmas.lemma_div_mod (v n) (hash_length a);
let State k v ctr = st in
if additional_input_len >. 0ul then
update hmac additional_input_len additional_input k v;
let output:lbuffer uint8 n = output in
let max = n /. hash_len a in
let out = sub output 0ul (max *! hash_len a) in
[@inline_let]
let a_spec = S.a_spec a in
[@inline_let]
let refl h i = as_seq h v in
[@inline_let]
let spec h0 = S.generate_loop a (as_seq h0 k) (uint_v max) in
let h0 = ST.get () in
fill_blocks h0 (hash_len a) max out a_spec refl (fun i -> loc v) spec
(fun i ->
LSeq.unfold_generate_blocks
(hash_length a) (uint_v max) a_spec (spec h0) (as_seq h0 v) (uint_v i);
hmac v k (hash_len a) v (hash_len a);
copy (sub out (i *! hash_len a) (hash_len a)) v
);
if max *! hash_len a <. n then
begin
let h1 = ST.get () in
let block = sub output (max *! hash_len a) (n -! (max *! hash_len a)) in
hmac v k (hash_len a) v (hash_len a);
copy block (sub v 0ul (n -! (max *! hash_len a)));
let h2 = ST.get () in
LSeq.eq_intro (as_seq h2 output)
(as_seq h1 out `LSeq.op_At_Bar` as_seq h2 block)
end;
update hmac additional_input_len additional_input k v;
let old_ctr = ctr.(0ul) in
ctr.(0ul) <- old_ctr +! 1ul;
true
end
#pop-options
let generate a output st n additional_input_len additional_input =
match a with
| SHA1 ->
mk_generate Hacl.HMAC.legacy_compute_sha1 output st n
additional_input_len additional_input
| SHA2_256 ->
mk_generate Hacl.HMAC.compute_sha2_256 output st n
additional_input_len additional_input
| SHA2_384 ->
mk_generate Hacl.HMAC.compute_sha2_384 output st n
additional_input_len additional_input
| SHA2_512 ->
mk_generate Hacl.HMAC.compute_sha2_512 output st n
additional_input_len additional_input | false | false | Hacl.HMAC_DRBG.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val free: #a:supported_alg -> free_st a | [] | Hacl.HMAC_DRBG.free | {
"file_name": "code/drbg/Hacl.HMAC_DRBG.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | Hacl.HMAC_DRBG.free_st a | {
"end_col": 33,
"end_line": 325,
"start_col": 15,
"start_line": 321
} |
FStar.HyperStack.ST.ST | val create_in: a:supported_alg -> r:HS.rid -> ST (state a)
(requires fun _ -> is_eternal_region r)
(ensures fun h0 st h1 ->
B.modifies B.loc_none h0 h1 /\
B.fresh_loc (footprint st) h0 h1 /\
B.(loc_includes (loc_region_only true r)) (footprint st) /\
invariant st h1 /\
freeable st) | [
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": true,
"full_module": "Spec.HMAC_DRBG",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "Hacl.HMAC",
"short_module": "HMAC"
},
{
"abbrev": true,
"full_module": "Lib.Sequence",
"short_module": "LSeq"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": false,
"full_module": "Lib.Buffer",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Hash.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let create_in a r =
let k:B.buffer uint8 =
match a with
| SHA1 -> B.malloc r (u8 0) (hash_len SHA1)
| SHA2_256 -> B.malloc r (u8 0) (hash_len SHA2_256)
| SHA2_384 -> B.malloc r (u8 0) (hash_len SHA2_384)
| SHA2_512 -> B.malloc r (u8 0) (hash_len SHA2_512)
in
let v:B.buffer uint8 =
match a with
| SHA1 -> B.malloc r (u8 0) (hash_len SHA1)
| SHA2_256 -> B.malloc r (u8 0) (hash_len SHA2_256)
| SHA2_384 -> B.malloc r (u8 0) (hash_len SHA2_384)
| SHA2_512 -> B.malloc r (u8 0) (hash_len SHA2_512)
in
let ctr:B.buffer size_t = B.malloc r 1ul 1ul in
State k v ctr | val create_in: a:supported_alg -> r:HS.rid -> ST (state a)
(requires fun _ -> is_eternal_region r)
(ensures fun h0 st h1 ->
B.modifies B.loc_none h0 h1 /\
B.fresh_loc (footprint st) h0 h1 /\
B.(loc_includes (loc_region_only true r)) (footprint st) /\
invariant st h1 /\
freeable st)
let create_in a r = | true | null | false | let k:B.buffer uint8 =
match a with
| SHA1 -> B.malloc r (u8 0) (hash_len SHA1)
| SHA2_256 -> B.malloc r (u8 0) (hash_len SHA2_256)
| SHA2_384 -> B.malloc r (u8 0) (hash_len SHA2_384)
| SHA2_512 -> B.malloc r (u8 0) (hash_len SHA2_512)
in
let v:B.buffer uint8 =
match a with
| SHA1 -> B.malloc r (u8 0) (hash_len SHA1)
| SHA2_256 -> B.malloc r (u8 0) (hash_len SHA2_256)
| SHA2_384 -> B.malloc r (u8 0) (hash_len SHA2_384)
| SHA2_512 -> B.malloc r (u8 0) (hash_len SHA2_512)
in
let ctr:B.buffer size_t = B.malloc r 1ul 1ul in
State k v ctr | {
"checked_file": "Hacl.HMAC_DRBG.fst.checked",
"dependencies": [
"Spec.HMAC_DRBG.fst.checked",
"Spec.HMAC_DRBG.fst.checked",
"Spec.Hash.Definitions.fst.checked",
"Spec.Agile.HMAC.fsti.checked",
"prims.fst.checked",
"LowStar.Buffer.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.Buffer.fsti.checked",
"Hacl.HMAC.fsti.checked",
"Hacl.Hash.Definitions.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked"
],
"interface_file": true,
"source_file": "Hacl.HMAC_DRBG.fst"
} | [] | [
"Hacl.HMAC_DRBG.supported_alg",
"FStar.Monotonic.HyperHeap.rid",
"Hacl.HMAC_DRBG.State",
"Hacl.HMAC_DRBG.state",
"LowStar.Buffer.buffer",
"Lib.IntTypes.int_t",
"Lib.IntTypes.U32",
"Lib.IntTypes.PUB",
"LowStar.Buffer.malloc",
"FStar.UInt32.__uint_to_t",
"LowStar.Monotonic.Buffer.mbuffer",
"LowStar.Buffer.trivial_preorder",
"Prims.l_and",
"Prims.eq2",
"Prims.nat",
"LowStar.Monotonic.Buffer.length",
"FStar.UInt32.v",
"Prims.b2t",
"Prims.op_Negation",
"LowStar.Monotonic.Buffer.g_is_null",
"LowStar.Monotonic.Buffer.frameOf",
"LowStar.Monotonic.Buffer.freeable",
"Lib.IntTypes.U8",
"Lib.IntTypes.SEC",
"Lib.IntTypes.u8",
"Hacl.HMAC_DRBG.hash_len",
"Spec.Hash.Definitions.SHA1",
"Spec.Hash.Definitions.SHA2_256",
"Spec.Hash.Definitions.SHA2_384",
"Spec.Hash.Definitions.SHA2_512"
] | [] | module Hacl.HMAC_DRBG
open FStar.HyperStack.ST
module ST = FStar.HyperStack.ST
open Spec.Hash.Definitions
open Lib.IntTypes
open Lib.Buffer
module HS = FStar.HyperStack
module B = LowStar.Buffer
module LSeq = Lib.Sequence
module HMAC = Hacl.HMAC
module S = Spec.HMAC_DRBG
friend Spec.HMAC_DRBG
unfold
let hash_len (a:supported_alg) = Hacl.Hash.Definitions.hash_len a
#set-options "--fuel 0 --ifuel 0 --z3rlimit 50"
inline_for_extraction noextract
val update_round: #a:supported_alg
-> hmac:HMAC.compute_st a
-> len:size_t
-> data:lbuffer uint8 len
-> n:uint8
-> k:lbuffer uint8 (hash_len a)
-> v:lbuffer uint8 (hash_len a)
-> Stack unit
(requires fun h0 ->
live h0 k /\ live h0 v /\ live h0 data /\
disjoint k v /\
// HMAC input length must fit in size_t
hash_length a + 1 + uint_v len + block_length a < pow2 32)
(ensures fun h0 _ h1 ->
S.hmac_input_bound a;
as_seq h1 k == Spec.Agile.HMAC.hmac a
(as_seq h0 k)
(Seq.append (as_seq h0 v) (Seq.cons n (as_seq h0 data))) /\
as_seq h1 v == Spec.Agile.HMAC.hmac a (as_seq h1 k) (as_seq h0 v) /\
modifies2 k v h0 h1)
let update_round #a hmac len data n k v =
let h0 = ST.get() in
push_frame();
let input_len = hash_len a +! 1ul +! len in
let input = create input_len (u8 0) in
let k' = sub input 0ul (hash_len a) in
copy k' v;
if len <> 0ul then copy (sub input (hash_len a +! 1ul) len) data;
input.(hash_len a) <- n;
let h1 = ST.get() in
assert (Seq.equal (as_seq h1 input)
(Seq.append (as_seq h0 v) (Seq.cons n (as_seq h0 data))));
S.hmac_input_bound a;
hmac k' k (hash_len a) input input_len;
hmac v k' (hash_len a) v (hash_len a);
copy k k';
pop_frame()
inline_for_extraction noextract
val update: #a:supported_alg
-> hmac:HMAC.compute_st a
-> len:size_t
-> data:lbuffer uint8 len
-> k:lbuffer uint8 (hash_len a)
-> v:lbuffer uint8 (hash_len a)
-> Stack unit
(requires fun h0 ->
live h0 data /\ live h0 k /\ live h0 v /\
disjoint k v /\ disjoint k data /\ disjoint v data /\
hash_length a + 1 + uint_v len + block_length a < pow2 32)
(ensures fun h0 _ h1 ->
S.hmac_input_bound a;
let k', v' = S.update #a (as_seq h0 data) (as_seq h0 k) (as_seq h0 v) in
modifies2 k v h0 h1 /\
as_seq h1 k == k' /\
as_seq h1 v == v')
let update #a hmac len data k v =
update_round hmac len data (u8 0) k v;
if len <> 0ul then
update_round hmac len data (u8 1) k v
noeq
type state (a:supported_alg) =
| State:
k:lbuffer uint8 (hash_len a)
-> v:lbuffer uint8 (hash_len a)
-> reseed_counter:lbuffer size_t 1ul
{disjoint k v /\ disjoint k reseed_counter /\ disjoint v reseed_counter}
-> state a
let freeable #a st =
let k:B.buffer uint8 = st.k in
let v:B.buffer uint8 = st.v in
let ctr:B.buffer size_t = st.reseed_counter in
B.freeable k /\ B.freeable v /\ B.freeable ctr
let footprint #a st =
let k:B.buffer uint8 = st.k in
let v:B.buffer uint8 = st.v in
let ctr:B.buffer size_t = st.reseed_counter in
B.loc_addr_of_buffer k |+| B.loc_addr_of_buffer v |+| B.loc_addr_of_buffer ctr
let invariant #a st h =
live h st.k /\ live h st.v /\ live h st.reseed_counter /\ (
// JP: the disjoint predicate from lib hardcodes loc_buffer instead of
// loc_addr_of_buffer, which prevents us from writing a proper free function
// (probably why it wasn't written here in the first place)... we add on top
// of the lib-style predicate a non-lib-style predicate which allows writing
// an actual free function
let k = st.k <: B.buffer uint8 in
let v = st.v <: B.buffer uint8 in
let ctr = st.reseed_counter <: B.buffer size_t in
B.(all_disjoint [ loc_addr_of_buffer k; loc_addr_of_buffer v; loc_addr_of_buffer ctr ]))
let repr #a st h =
S.State (as_seq h st.k) (as_seq h st.v) (v (bget h st.reseed_counter 0))
let alloca a =
let k =
match a with
| SHA1 -> create (hash_len SHA1) (u8 0)
| SHA2_256 -> create (hash_len SHA2_256) (u8 0)
| SHA2_384 -> create (hash_len SHA2_384) (u8 0)
| SHA2_512 -> create (hash_len SHA2_512) (u8 0)
in
let v =
match a with
| SHA1 -> create (hash_len SHA1) (u8 0)
| SHA2_256 -> create (hash_len SHA2_256) (u8 0)
| SHA2_384 -> create (hash_len SHA2_384) (u8 0)
| SHA2_512 -> create (hash_len SHA2_512) (u8 0)
in
let ctr = create 1ul 1ul in
State k v ctr | false | false | Hacl.HMAC_DRBG.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val create_in: a:supported_alg -> r:HS.rid -> ST (state a)
(requires fun _ -> is_eternal_region r)
(ensures fun h0 st h1 ->
B.modifies B.loc_none h0 h1 /\
B.fresh_loc (footprint st) h0 h1 /\
B.(loc_includes (loc_region_only true r)) (footprint st) /\
invariant st h1 /\
freeable st) | [] | Hacl.HMAC_DRBG.create_in | {
"file_name": "code/drbg/Hacl.HMAC_DRBG.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | a: Hacl.HMAC_DRBG.supported_alg -> r: FStar.Monotonic.HyperHeap.rid
-> FStar.HyperStack.ST.ST (Hacl.HMAC_DRBG.state a) | {
"end_col": 15,
"end_line": 161,
"start_col": 19,
"start_line": 145
} |
FStar.HyperStack.ST.StackInline | val alloca: a:supported_alg -> StackInline (state a)
(requires fun _ -> True)
(ensures fun h0 st h1 ->
B.modifies B.loc_none h0 h1 /\
B.fresh_loc (footprint st) h0 h1 /\
B.(loc_includes (loc_region_only true (HS.get_tip h1)) (footprint st)) /\
invariant st h1) | [
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": true,
"full_module": "Spec.HMAC_DRBG",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "Hacl.HMAC",
"short_module": "HMAC"
},
{
"abbrev": true,
"full_module": "Lib.Sequence",
"short_module": "LSeq"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": false,
"full_module": "Lib.Buffer",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Hash.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let alloca a =
let k =
match a with
| SHA1 -> create (hash_len SHA1) (u8 0)
| SHA2_256 -> create (hash_len SHA2_256) (u8 0)
| SHA2_384 -> create (hash_len SHA2_384) (u8 0)
| SHA2_512 -> create (hash_len SHA2_512) (u8 0)
in
let v =
match a with
| SHA1 -> create (hash_len SHA1) (u8 0)
| SHA2_256 -> create (hash_len SHA2_256) (u8 0)
| SHA2_384 -> create (hash_len SHA2_384) (u8 0)
| SHA2_512 -> create (hash_len SHA2_512) (u8 0)
in
let ctr = create 1ul 1ul in
State k v ctr | val alloca: a:supported_alg -> StackInline (state a)
(requires fun _ -> True)
(ensures fun h0 st h1 ->
B.modifies B.loc_none h0 h1 /\
B.fresh_loc (footprint st) h0 h1 /\
B.(loc_includes (loc_region_only true (HS.get_tip h1)) (footprint st)) /\
invariant st h1)
let alloca a = | true | null | false | let k =
match a with
| SHA1 -> create (hash_len SHA1) (u8 0)
| SHA2_256 -> create (hash_len SHA2_256) (u8 0)
| SHA2_384 -> create (hash_len SHA2_384) (u8 0)
| SHA2_512 -> create (hash_len SHA2_512) (u8 0)
in
let v =
match a with
| SHA1 -> create (hash_len SHA1) (u8 0)
| SHA2_256 -> create (hash_len SHA2_256) (u8 0)
| SHA2_384 -> create (hash_len SHA2_384) (u8 0)
| SHA2_512 -> create (hash_len SHA2_512) (u8 0)
in
let ctr = create 1ul 1ul in
State k v ctr | {
"checked_file": "Hacl.HMAC_DRBG.fst.checked",
"dependencies": [
"Spec.HMAC_DRBG.fst.checked",
"Spec.HMAC_DRBG.fst.checked",
"Spec.Hash.Definitions.fst.checked",
"Spec.Agile.HMAC.fsti.checked",
"prims.fst.checked",
"LowStar.Buffer.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.Buffer.fsti.checked",
"Hacl.HMAC.fsti.checked",
"Hacl.Hash.Definitions.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked"
],
"interface_file": true,
"source_file": "Hacl.HMAC_DRBG.fst"
} | [] | [
"Hacl.HMAC_DRBG.supported_alg",
"Hacl.HMAC_DRBG.State",
"Hacl.HMAC_DRBG.state",
"Lib.Buffer.lbuffer_t",
"Lib.Buffer.MUT",
"Lib.IntTypes.int_t",
"Lib.IntTypes.U32",
"Lib.IntTypes.PUB",
"FStar.UInt32.uint_to_t",
"FStar.UInt32.t",
"Lib.Buffer.create",
"Lib.IntTypes.size_t",
"FStar.UInt32.__uint_to_t",
"Lib.Buffer.lbuffer",
"Lib.IntTypes.U8",
"Lib.IntTypes.SEC",
"Hacl.Hash.Definitions.hash_len",
"Lib.IntTypes.uint8",
"Hacl.HMAC_DRBG.hash_len",
"Spec.Hash.Definitions.SHA1",
"Lib.IntTypes.u8",
"Spec.Hash.Definitions.SHA2_256",
"Spec.Hash.Definitions.SHA2_384",
"Spec.Hash.Definitions.SHA2_512"
] | [] | module Hacl.HMAC_DRBG
open FStar.HyperStack.ST
module ST = FStar.HyperStack.ST
open Spec.Hash.Definitions
open Lib.IntTypes
open Lib.Buffer
module HS = FStar.HyperStack
module B = LowStar.Buffer
module LSeq = Lib.Sequence
module HMAC = Hacl.HMAC
module S = Spec.HMAC_DRBG
friend Spec.HMAC_DRBG
unfold
let hash_len (a:supported_alg) = Hacl.Hash.Definitions.hash_len a
#set-options "--fuel 0 --ifuel 0 --z3rlimit 50"
inline_for_extraction noextract
val update_round: #a:supported_alg
-> hmac:HMAC.compute_st a
-> len:size_t
-> data:lbuffer uint8 len
-> n:uint8
-> k:lbuffer uint8 (hash_len a)
-> v:lbuffer uint8 (hash_len a)
-> Stack unit
(requires fun h0 ->
live h0 k /\ live h0 v /\ live h0 data /\
disjoint k v /\
// HMAC input length must fit in size_t
hash_length a + 1 + uint_v len + block_length a < pow2 32)
(ensures fun h0 _ h1 ->
S.hmac_input_bound a;
as_seq h1 k == Spec.Agile.HMAC.hmac a
(as_seq h0 k)
(Seq.append (as_seq h0 v) (Seq.cons n (as_seq h0 data))) /\
as_seq h1 v == Spec.Agile.HMAC.hmac a (as_seq h1 k) (as_seq h0 v) /\
modifies2 k v h0 h1)
let update_round #a hmac len data n k v =
let h0 = ST.get() in
push_frame();
let input_len = hash_len a +! 1ul +! len in
let input = create input_len (u8 0) in
let k' = sub input 0ul (hash_len a) in
copy k' v;
if len <> 0ul then copy (sub input (hash_len a +! 1ul) len) data;
input.(hash_len a) <- n;
let h1 = ST.get() in
assert (Seq.equal (as_seq h1 input)
(Seq.append (as_seq h0 v) (Seq.cons n (as_seq h0 data))));
S.hmac_input_bound a;
hmac k' k (hash_len a) input input_len;
hmac v k' (hash_len a) v (hash_len a);
copy k k';
pop_frame()
inline_for_extraction noextract
val update: #a:supported_alg
-> hmac:HMAC.compute_st a
-> len:size_t
-> data:lbuffer uint8 len
-> k:lbuffer uint8 (hash_len a)
-> v:lbuffer uint8 (hash_len a)
-> Stack unit
(requires fun h0 ->
live h0 data /\ live h0 k /\ live h0 v /\
disjoint k v /\ disjoint k data /\ disjoint v data /\
hash_length a + 1 + uint_v len + block_length a < pow2 32)
(ensures fun h0 _ h1 ->
S.hmac_input_bound a;
let k', v' = S.update #a (as_seq h0 data) (as_seq h0 k) (as_seq h0 v) in
modifies2 k v h0 h1 /\
as_seq h1 k == k' /\
as_seq h1 v == v')
let update #a hmac len data k v =
update_round hmac len data (u8 0) k v;
if len <> 0ul then
update_round hmac len data (u8 1) k v
noeq
type state (a:supported_alg) =
| State:
k:lbuffer uint8 (hash_len a)
-> v:lbuffer uint8 (hash_len a)
-> reseed_counter:lbuffer size_t 1ul
{disjoint k v /\ disjoint k reseed_counter /\ disjoint v reseed_counter}
-> state a
let freeable #a st =
let k:B.buffer uint8 = st.k in
let v:B.buffer uint8 = st.v in
let ctr:B.buffer size_t = st.reseed_counter in
B.freeable k /\ B.freeable v /\ B.freeable ctr
let footprint #a st =
let k:B.buffer uint8 = st.k in
let v:B.buffer uint8 = st.v in
let ctr:B.buffer size_t = st.reseed_counter in
B.loc_addr_of_buffer k |+| B.loc_addr_of_buffer v |+| B.loc_addr_of_buffer ctr
let invariant #a st h =
live h st.k /\ live h st.v /\ live h st.reseed_counter /\ (
// JP: the disjoint predicate from lib hardcodes loc_buffer instead of
// loc_addr_of_buffer, which prevents us from writing a proper free function
// (probably why it wasn't written here in the first place)... we add on top
// of the lib-style predicate a non-lib-style predicate which allows writing
// an actual free function
let k = st.k <: B.buffer uint8 in
let v = st.v <: B.buffer uint8 in
let ctr = st.reseed_counter <: B.buffer size_t in
B.(all_disjoint [ loc_addr_of_buffer k; loc_addr_of_buffer v; loc_addr_of_buffer ctr ]))
let repr #a st h =
S.State (as_seq h st.k) (as_seq h st.v) (v (bget h st.reseed_counter 0)) | false | false | Hacl.HMAC_DRBG.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val alloca: a:supported_alg -> StackInline (state a)
(requires fun _ -> True)
(ensures fun h0 st h1 ->
B.modifies B.loc_none h0 h1 /\
B.fresh_loc (footprint st) h0 h1 /\
B.(loc_includes (loc_region_only true (HS.get_tip h1)) (footprint st)) /\
invariant st h1) | [] | Hacl.HMAC_DRBG.alloca | {
"file_name": "code/drbg/Hacl.HMAC_DRBG.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | a: Hacl.HMAC_DRBG.supported_alg -> FStar.HyperStack.ST.StackInline (Hacl.HMAC_DRBG.state a) | {
"end_col": 15,
"end_line": 143,
"start_col": 14,
"start_line": 127
} |
FStar.HyperStack.ST.Stack | val update: #a:supported_alg
-> hmac:HMAC.compute_st a
-> len:size_t
-> data:lbuffer uint8 len
-> k:lbuffer uint8 (hash_len a)
-> v:lbuffer uint8 (hash_len a)
-> Stack unit
(requires fun h0 ->
live h0 data /\ live h0 k /\ live h0 v /\
disjoint k v /\ disjoint k data /\ disjoint v data /\
hash_length a + 1 + uint_v len + block_length a < pow2 32)
(ensures fun h0 _ h1 ->
S.hmac_input_bound a;
let k', v' = S.update #a (as_seq h0 data) (as_seq h0 k) (as_seq h0 v) in
modifies2 k v h0 h1 /\
as_seq h1 k == k' /\
as_seq h1 v == v') | [
{
"abbrev": true,
"full_module": "Spec.HMAC_DRBG",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "Hacl.HMAC",
"short_module": "HMAC"
},
{
"abbrev": true,
"full_module": "Lib.Sequence",
"short_module": "LSeq"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": false,
"full_module": "Lib.Buffer",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Hash.Definitions",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": true,
"full_module": "Spec.HMAC_DRBG",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "Hacl.HMAC",
"short_module": "HMAC"
},
{
"abbrev": true,
"full_module": "Lib.Sequence",
"short_module": "LSeq"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": false,
"full_module": "Lib.Buffer",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Hash.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let update #a hmac len data k v =
update_round hmac len data (u8 0) k v;
if len <> 0ul then
update_round hmac len data (u8 1) k v | val update: #a:supported_alg
-> hmac:HMAC.compute_st a
-> len:size_t
-> data:lbuffer uint8 len
-> k:lbuffer uint8 (hash_len a)
-> v:lbuffer uint8 (hash_len a)
-> Stack unit
(requires fun h0 ->
live h0 data /\ live h0 k /\ live h0 v /\
disjoint k v /\ disjoint k data /\ disjoint v data /\
hash_length a + 1 + uint_v len + block_length a < pow2 32)
(ensures fun h0 _ h1 ->
S.hmac_input_bound a;
let k', v' = S.update #a (as_seq h0 data) (as_seq h0 k) (as_seq h0 v) in
modifies2 k v h0 h1 /\
as_seq h1 k == k' /\
as_seq h1 v == v')
let update #a hmac len data k v = | true | null | false | update_round hmac len data (u8 0) k v;
if len <> 0ul then update_round hmac len data (u8 1) k v | {
"checked_file": "Hacl.HMAC_DRBG.fst.checked",
"dependencies": [
"Spec.HMAC_DRBG.fst.checked",
"Spec.HMAC_DRBG.fst.checked",
"Spec.Hash.Definitions.fst.checked",
"Spec.Agile.HMAC.fsti.checked",
"prims.fst.checked",
"LowStar.Buffer.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.Buffer.fsti.checked",
"Hacl.HMAC.fsti.checked",
"Hacl.Hash.Definitions.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked"
],
"interface_file": true,
"source_file": "Hacl.HMAC_DRBG.fst"
} | [] | [
"Hacl.HMAC_DRBG.supported_alg",
"Hacl.HMAC.compute_st",
"Lib.IntTypes.size_t",
"Lib.Buffer.lbuffer",
"Lib.IntTypes.uint8",
"Hacl.HMAC_DRBG.hash_len",
"Prims.op_disEquality",
"FStar.UInt32.t",
"FStar.UInt32.__uint_to_t",
"Hacl.HMAC_DRBG.update_round",
"Lib.IntTypes.u8",
"Prims.unit",
"Prims.bool"
] | [] | module Hacl.HMAC_DRBG
open FStar.HyperStack.ST
module ST = FStar.HyperStack.ST
open Spec.Hash.Definitions
open Lib.IntTypes
open Lib.Buffer
module HS = FStar.HyperStack
module B = LowStar.Buffer
module LSeq = Lib.Sequence
module HMAC = Hacl.HMAC
module S = Spec.HMAC_DRBG
friend Spec.HMAC_DRBG
unfold
let hash_len (a:supported_alg) = Hacl.Hash.Definitions.hash_len a
#set-options "--fuel 0 --ifuel 0 --z3rlimit 50"
inline_for_extraction noextract
val update_round: #a:supported_alg
-> hmac:HMAC.compute_st a
-> len:size_t
-> data:lbuffer uint8 len
-> n:uint8
-> k:lbuffer uint8 (hash_len a)
-> v:lbuffer uint8 (hash_len a)
-> Stack unit
(requires fun h0 ->
live h0 k /\ live h0 v /\ live h0 data /\
disjoint k v /\
// HMAC input length must fit in size_t
hash_length a + 1 + uint_v len + block_length a < pow2 32)
(ensures fun h0 _ h1 ->
S.hmac_input_bound a;
as_seq h1 k == Spec.Agile.HMAC.hmac a
(as_seq h0 k)
(Seq.append (as_seq h0 v) (Seq.cons n (as_seq h0 data))) /\
as_seq h1 v == Spec.Agile.HMAC.hmac a (as_seq h1 k) (as_seq h0 v) /\
modifies2 k v h0 h1)
let update_round #a hmac len data n k v =
let h0 = ST.get() in
push_frame();
let input_len = hash_len a +! 1ul +! len in
let input = create input_len (u8 0) in
let k' = sub input 0ul (hash_len a) in
copy k' v;
if len <> 0ul then copy (sub input (hash_len a +! 1ul) len) data;
input.(hash_len a) <- n;
let h1 = ST.get() in
assert (Seq.equal (as_seq h1 input)
(Seq.append (as_seq h0 v) (Seq.cons n (as_seq h0 data))));
S.hmac_input_bound a;
hmac k' k (hash_len a) input input_len;
hmac v k' (hash_len a) v (hash_len a);
copy k k';
pop_frame()
inline_for_extraction noextract
val update: #a:supported_alg
-> hmac:HMAC.compute_st a
-> len:size_t
-> data:lbuffer uint8 len
-> k:lbuffer uint8 (hash_len a)
-> v:lbuffer uint8 (hash_len a)
-> Stack unit
(requires fun h0 ->
live h0 data /\ live h0 k /\ live h0 v /\
disjoint k v /\ disjoint k data /\ disjoint v data /\
hash_length a + 1 + uint_v len + block_length a < pow2 32)
(ensures fun h0 _ h1 ->
S.hmac_input_bound a;
let k', v' = S.update #a (as_seq h0 data) (as_seq h0 k) (as_seq h0 v) in
modifies2 k v h0 h1 /\
as_seq h1 k == k' /\
as_seq h1 v == v') | false | false | Hacl.HMAC_DRBG.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val update: #a:supported_alg
-> hmac:HMAC.compute_st a
-> len:size_t
-> data:lbuffer uint8 len
-> k:lbuffer uint8 (hash_len a)
-> v:lbuffer uint8 (hash_len a)
-> Stack unit
(requires fun h0 ->
live h0 data /\ live h0 k /\ live h0 v /\
disjoint k v /\ disjoint k data /\ disjoint v data /\
hash_length a + 1 + uint_v len + block_length a < pow2 32)
(ensures fun h0 _ h1 ->
S.hmac_input_bound a;
let k', v' = S.update #a (as_seq h0 data) (as_seq h0 k) (as_seq h0 v) in
modifies2 k v h0 h1 /\
as_seq h1 k == k' /\
as_seq h1 v == v') | [] | Hacl.HMAC_DRBG.update | {
"file_name": "code/drbg/Hacl.HMAC_DRBG.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} |
hmac: Hacl.HMAC.compute_st a ->
len: Lib.IntTypes.size_t ->
data: Lib.Buffer.lbuffer Lib.IntTypes.uint8 len ->
k: Lib.Buffer.lbuffer Lib.IntTypes.uint8 (Hacl.HMAC_DRBG.hash_len a) ->
v: Lib.Buffer.lbuffer Lib.IntTypes.uint8 (Hacl.HMAC_DRBG.hash_len a)
-> FStar.HyperStack.ST.Stack Prims.unit | {
"end_col": 41,
"end_line": 88,
"start_col": 2,
"start_line": 86
} |
Prims.Tot | val mk_reseed: #a:supported_alg -> hmac:HMAC.compute_st a -> reseed_st a | [
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": true,
"full_module": "Spec.HMAC_DRBG",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "Hacl.HMAC",
"short_module": "HMAC"
},
{
"abbrev": true,
"full_module": "Lib.Sequence",
"short_module": "LSeq"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": false,
"full_module": "Lib.Buffer",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Hash.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let mk_reseed #a hmac st
entropy_input_len entropy_input
additional_input_len additional_input
=
let h0 = ST.get () in
push_frame();
let seed_material = create (entropy_input_len +! additional_input_len) (u8 0) in
copy (sub seed_material 0ul entropy_input_len) entropy_input;
copy (sub seed_material entropy_input_len additional_input_len) additional_input;
let h1 = ST.get () in
LSeq.eq_intro (as_seq h1 seed_material)
LSeq.(as_seq h0 entropy_input @| as_seq h0 additional_input);
let State k v ctr: state a = st in
update hmac (entropy_input_len +! additional_input_len) seed_material k v;
ctr.(0ul) <- 1ul;
pop_frame() | val mk_reseed: #a:supported_alg -> hmac:HMAC.compute_st a -> reseed_st a
let mk_reseed #a hmac st entropy_input_len entropy_input additional_input_len additional_input = | false | null | false | let h0 = ST.get () in
push_frame ();
let seed_material = create (entropy_input_len +! additional_input_len) (u8 0) in
copy (sub seed_material 0ul entropy_input_len) entropy_input;
copy (sub seed_material entropy_input_len additional_input_len) additional_input;
let h1 = ST.get () in
LSeq.eq_intro (as_seq h1 seed_material) LSeq.(as_seq h0 entropy_input @| as_seq h0 additional_input);
let State k v ctr:state a = st in
update hmac (entropy_input_len +! additional_input_len) seed_material k v;
ctr.(0ul) <- 1ul;
pop_frame () | {
"checked_file": "Hacl.HMAC_DRBG.fst.checked",
"dependencies": [
"Spec.HMAC_DRBG.fst.checked",
"Spec.HMAC_DRBG.fst.checked",
"Spec.Hash.Definitions.fst.checked",
"Spec.Agile.HMAC.fsti.checked",
"prims.fst.checked",
"LowStar.Buffer.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.Buffer.fsti.checked",
"Hacl.HMAC.fsti.checked",
"Hacl.Hash.Definitions.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked"
],
"interface_file": true,
"source_file": "Hacl.HMAC_DRBG.fst"
} | [
"total"
] | [
"Hacl.HMAC_DRBG.supported_alg",
"Hacl.HMAC.compute_st",
"Hacl.HMAC_DRBG.state",
"Lib.IntTypes.size_t",
"Lib.Buffer.lbuffer",
"Lib.IntTypes.uint8",
"Hacl.HMAC_DRBG.hash_len",
"FStar.UInt32.__uint_to_t",
"Prims.l_and",
"Lib.Buffer.disjoint",
"Lib.Buffer.MUT",
"FStar.HyperStack.ST.pop_frame",
"Prims.unit",
"Lib.Buffer.op_Array_Assignment",
"Hacl.HMAC_DRBG.update",
"Lib.IntTypes.op_Plus_Bang",
"Lib.IntTypes.U32",
"Lib.IntTypes.PUB",
"Lib.Sequence.eq_intro",
"Lib.IntTypes.v",
"Lib.Buffer.as_seq",
"Lib.Sequence.op_At_Bar",
"FStar.Monotonic.HyperStack.mem",
"FStar.HyperStack.ST.get",
"Lib.Buffer.copy",
"Lib.Buffer.lbuffer_t",
"Lib.IntTypes.int_t",
"Lib.IntTypes.U8",
"Lib.IntTypes.SEC",
"Lib.Buffer.sub",
"Lib.IntTypes.add",
"Lib.Buffer.create",
"Lib.IntTypes.u8",
"FStar.HyperStack.ST.push_frame"
] | [] | module Hacl.HMAC_DRBG
open FStar.HyperStack.ST
module ST = FStar.HyperStack.ST
open Spec.Hash.Definitions
open Lib.IntTypes
open Lib.Buffer
module HS = FStar.HyperStack
module B = LowStar.Buffer
module LSeq = Lib.Sequence
module HMAC = Hacl.HMAC
module S = Spec.HMAC_DRBG
friend Spec.HMAC_DRBG
unfold
let hash_len (a:supported_alg) = Hacl.Hash.Definitions.hash_len a
#set-options "--fuel 0 --ifuel 0 --z3rlimit 50"
inline_for_extraction noextract
val update_round: #a:supported_alg
-> hmac:HMAC.compute_st a
-> len:size_t
-> data:lbuffer uint8 len
-> n:uint8
-> k:lbuffer uint8 (hash_len a)
-> v:lbuffer uint8 (hash_len a)
-> Stack unit
(requires fun h0 ->
live h0 k /\ live h0 v /\ live h0 data /\
disjoint k v /\
// HMAC input length must fit in size_t
hash_length a + 1 + uint_v len + block_length a < pow2 32)
(ensures fun h0 _ h1 ->
S.hmac_input_bound a;
as_seq h1 k == Spec.Agile.HMAC.hmac a
(as_seq h0 k)
(Seq.append (as_seq h0 v) (Seq.cons n (as_seq h0 data))) /\
as_seq h1 v == Spec.Agile.HMAC.hmac a (as_seq h1 k) (as_seq h0 v) /\
modifies2 k v h0 h1)
let update_round #a hmac len data n k v =
let h0 = ST.get() in
push_frame();
let input_len = hash_len a +! 1ul +! len in
let input = create input_len (u8 0) in
let k' = sub input 0ul (hash_len a) in
copy k' v;
if len <> 0ul then copy (sub input (hash_len a +! 1ul) len) data;
input.(hash_len a) <- n;
let h1 = ST.get() in
assert (Seq.equal (as_seq h1 input)
(Seq.append (as_seq h0 v) (Seq.cons n (as_seq h0 data))));
S.hmac_input_bound a;
hmac k' k (hash_len a) input input_len;
hmac v k' (hash_len a) v (hash_len a);
copy k k';
pop_frame()
inline_for_extraction noextract
val update: #a:supported_alg
-> hmac:HMAC.compute_st a
-> len:size_t
-> data:lbuffer uint8 len
-> k:lbuffer uint8 (hash_len a)
-> v:lbuffer uint8 (hash_len a)
-> Stack unit
(requires fun h0 ->
live h0 data /\ live h0 k /\ live h0 v /\
disjoint k v /\ disjoint k data /\ disjoint v data /\
hash_length a + 1 + uint_v len + block_length a < pow2 32)
(ensures fun h0 _ h1 ->
S.hmac_input_bound a;
let k', v' = S.update #a (as_seq h0 data) (as_seq h0 k) (as_seq h0 v) in
modifies2 k v h0 h1 /\
as_seq h1 k == k' /\
as_seq h1 v == v')
let update #a hmac len data k v =
update_round hmac len data (u8 0) k v;
if len <> 0ul then
update_round hmac len data (u8 1) k v
noeq
type state (a:supported_alg) =
| State:
k:lbuffer uint8 (hash_len a)
-> v:lbuffer uint8 (hash_len a)
-> reseed_counter:lbuffer size_t 1ul
{disjoint k v /\ disjoint k reseed_counter /\ disjoint v reseed_counter}
-> state a
let freeable #a st =
let k:B.buffer uint8 = st.k in
let v:B.buffer uint8 = st.v in
let ctr:B.buffer size_t = st.reseed_counter in
B.freeable k /\ B.freeable v /\ B.freeable ctr
let footprint #a st =
let k:B.buffer uint8 = st.k in
let v:B.buffer uint8 = st.v in
let ctr:B.buffer size_t = st.reseed_counter in
B.loc_addr_of_buffer k |+| B.loc_addr_of_buffer v |+| B.loc_addr_of_buffer ctr
let invariant #a st h =
live h st.k /\ live h st.v /\ live h st.reseed_counter /\ (
// JP: the disjoint predicate from lib hardcodes loc_buffer instead of
// loc_addr_of_buffer, which prevents us from writing a proper free function
// (probably why it wasn't written here in the first place)... we add on top
// of the lib-style predicate a non-lib-style predicate which allows writing
// an actual free function
let k = st.k <: B.buffer uint8 in
let v = st.v <: B.buffer uint8 in
let ctr = st.reseed_counter <: B.buffer size_t in
B.(all_disjoint [ loc_addr_of_buffer k; loc_addr_of_buffer v; loc_addr_of_buffer ctr ]))
let repr #a st h =
S.State (as_seq h st.k) (as_seq h st.v) (v (bget h st.reseed_counter 0))
let alloca a =
let k =
match a with
| SHA1 -> create (hash_len SHA1) (u8 0)
| SHA2_256 -> create (hash_len SHA2_256) (u8 0)
| SHA2_384 -> create (hash_len SHA2_384) (u8 0)
| SHA2_512 -> create (hash_len SHA2_512) (u8 0)
in
let v =
match a with
| SHA1 -> create (hash_len SHA1) (u8 0)
| SHA2_256 -> create (hash_len SHA2_256) (u8 0)
| SHA2_384 -> create (hash_len SHA2_384) (u8 0)
| SHA2_512 -> create (hash_len SHA2_512) (u8 0)
in
let ctr = create 1ul 1ul in
State k v ctr
let create_in a r =
let k:B.buffer uint8 =
match a with
| SHA1 -> B.malloc r (u8 0) (hash_len SHA1)
| SHA2_256 -> B.malloc r (u8 0) (hash_len SHA2_256)
| SHA2_384 -> B.malloc r (u8 0) (hash_len SHA2_384)
| SHA2_512 -> B.malloc r (u8 0) (hash_len SHA2_512)
in
let v:B.buffer uint8 =
match a with
| SHA1 -> B.malloc r (u8 0) (hash_len SHA1)
| SHA2_256 -> B.malloc r (u8 0) (hash_len SHA2_256)
| SHA2_384 -> B.malloc r (u8 0) (hash_len SHA2_384)
| SHA2_512 -> B.malloc r (u8 0) (hash_len SHA2_512)
in
let ctr:B.buffer size_t = B.malloc r 1ul 1ul in
State k v ctr
#push-options "--z3rlimit 200"
let mk_instantiate #a hmac st
entropy_input_len entropy_input
nonce_len nonce
personalization_string_len personalization_string
=
let h0 = ST.get () in
push_frame();
let seed_material = create (entropy_input_len +! nonce_len +! personalization_string_len) (u8 0) in
copy (sub seed_material 0ul entropy_input_len) entropy_input;
copy (sub seed_material entropy_input_len nonce_len) nonce;
copy (sub seed_material (entropy_input_len +! nonce_len) personalization_string_len) personalization_string;
let State k v ctr = st in
memset k (u8 0) (hash_len a);
memset v (u8 1) (hash_len a);
let h1 = ST.get () in
assert (Seq.equal (as_seq h1 seed_material)
(Seq.append (as_seq h0 entropy_input) (Seq.append (as_seq h0 nonce)
(as_seq h0 personalization_string))));
assert (LSeq.equal (as_seq h1 k) (LSeq.create (hash_length a) (u8 0)));
assert (LSeq.equal (as_seq h1 v) (LSeq.create (hash_length a) (u8 1)));
ctr.(0ul) <- 1ul;
update hmac (entropy_input_len +! nonce_len +! personalization_string_len)
seed_material k v;
pop_frame()
#pop-options
let instantiate a st
entropy_input_len entropy_input
nonce_len nonce
personalization_string_len personalization_string
=
match a with
| SHA1 ->
mk_instantiate Hacl.HMAC.legacy_compute_sha1 st
entropy_input_len entropy_input
nonce_len nonce
personalization_string_len personalization_string
| SHA2_256 ->
mk_instantiate Hacl.HMAC.compute_sha2_256 st
entropy_input_len entropy_input
nonce_len nonce
personalization_string_len personalization_string
| SHA2_384 ->
mk_instantiate Hacl.HMAC.compute_sha2_384 st
entropy_input_len entropy_input
nonce_len nonce
personalization_string_len personalization_string
| SHA2_512 ->
mk_instantiate Hacl.HMAC.compute_sha2_512 st
entropy_input_len entropy_input
nonce_len nonce
personalization_string_len personalization_string
let mk_reseed #a hmac st
entropy_input_len entropy_input | false | false | Hacl.HMAC_DRBG.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val mk_reseed: #a:supported_alg -> hmac:HMAC.compute_st a -> reseed_st a | [] | Hacl.HMAC_DRBG.mk_reseed | {
"file_name": "code/drbg/Hacl.HMAC_DRBG.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | hmac: Hacl.HMAC.compute_st a -> Hacl.HMAC_DRBG.reseed_st a | {
"end_col": 13,
"end_line": 235,
"start_col": 1,
"start_line": 223
} |
FStar.HyperStack.ST.Stack | val update_round: #a:supported_alg
-> hmac:HMAC.compute_st a
-> len:size_t
-> data:lbuffer uint8 len
-> n:uint8
-> k:lbuffer uint8 (hash_len a)
-> v:lbuffer uint8 (hash_len a)
-> Stack unit
(requires fun h0 ->
live h0 k /\ live h0 v /\ live h0 data /\
disjoint k v /\
// HMAC input length must fit in size_t
hash_length a + 1 + uint_v len + block_length a < pow2 32)
(ensures fun h0 _ h1 ->
S.hmac_input_bound a;
as_seq h1 k == Spec.Agile.HMAC.hmac a
(as_seq h0 k)
(Seq.append (as_seq h0 v) (Seq.cons n (as_seq h0 data))) /\
as_seq h1 v == Spec.Agile.HMAC.hmac a (as_seq h1 k) (as_seq h0 v) /\
modifies2 k v h0 h1) | [
{
"abbrev": true,
"full_module": "Spec.HMAC_DRBG",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "Hacl.HMAC",
"short_module": "HMAC"
},
{
"abbrev": true,
"full_module": "Lib.Sequence",
"short_module": "LSeq"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": false,
"full_module": "Lib.Buffer",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Hash.Definitions",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": true,
"full_module": "Spec.HMAC_DRBG",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "Hacl.HMAC",
"short_module": "HMAC"
},
{
"abbrev": true,
"full_module": "Lib.Sequence",
"short_module": "LSeq"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": false,
"full_module": "Lib.Buffer",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Hash.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let update_round #a hmac len data n k v =
let h0 = ST.get() in
push_frame();
let input_len = hash_len a +! 1ul +! len in
let input = create input_len (u8 0) in
let k' = sub input 0ul (hash_len a) in
copy k' v;
if len <> 0ul then copy (sub input (hash_len a +! 1ul) len) data;
input.(hash_len a) <- n;
let h1 = ST.get() in
assert (Seq.equal (as_seq h1 input)
(Seq.append (as_seq h0 v) (Seq.cons n (as_seq h0 data))));
S.hmac_input_bound a;
hmac k' k (hash_len a) input input_len;
hmac v k' (hash_len a) v (hash_len a);
copy k k';
pop_frame() | val update_round: #a:supported_alg
-> hmac:HMAC.compute_st a
-> len:size_t
-> data:lbuffer uint8 len
-> n:uint8
-> k:lbuffer uint8 (hash_len a)
-> v:lbuffer uint8 (hash_len a)
-> Stack unit
(requires fun h0 ->
live h0 k /\ live h0 v /\ live h0 data /\
disjoint k v /\
// HMAC input length must fit in size_t
hash_length a + 1 + uint_v len + block_length a < pow2 32)
(ensures fun h0 _ h1 ->
S.hmac_input_bound a;
as_seq h1 k == Spec.Agile.HMAC.hmac a
(as_seq h0 k)
(Seq.append (as_seq h0 v) (Seq.cons n (as_seq h0 data))) /\
as_seq h1 v == Spec.Agile.HMAC.hmac a (as_seq h1 k) (as_seq h0 v) /\
modifies2 k v h0 h1)
let update_round #a hmac len data n k v = | true | null | false | let h0 = ST.get () in
push_frame ();
let input_len = hash_len a +! 1ul +! len in
let input = create input_len (u8 0) in
let k' = sub input 0ul (hash_len a) in
copy k' v;
if len <> 0ul then copy (sub input (hash_len a +! 1ul) len) data;
input.(hash_len a) <- n;
let h1 = ST.get () in
assert (Seq.equal (as_seq h1 input) (Seq.append (as_seq h0 v) (Seq.cons n (as_seq h0 data))));
S.hmac_input_bound a;
hmac k' k (hash_len a) input input_len;
hmac v k' (hash_len a) v (hash_len a);
copy k k';
pop_frame () | {
"checked_file": "Hacl.HMAC_DRBG.fst.checked",
"dependencies": [
"Spec.HMAC_DRBG.fst.checked",
"Spec.HMAC_DRBG.fst.checked",
"Spec.Hash.Definitions.fst.checked",
"Spec.Agile.HMAC.fsti.checked",
"prims.fst.checked",
"LowStar.Buffer.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.Buffer.fsti.checked",
"Hacl.HMAC.fsti.checked",
"Hacl.Hash.Definitions.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked"
],
"interface_file": true,
"source_file": "Hacl.HMAC_DRBG.fst"
} | [] | [
"Hacl.HMAC_DRBG.supported_alg",
"Hacl.HMAC.compute_st",
"Lib.IntTypes.size_t",
"Lib.Buffer.lbuffer",
"Lib.IntTypes.uint8",
"Hacl.HMAC_DRBG.hash_len",
"FStar.HyperStack.ST.pop_frame",
"Prims.unit",
"Lib.Buffer.copy",
"Lib.Buffer.MUT",
"Spec.HMAC_DRBG.hmac_input_bound",
"Prims._assert",
"FStar.Seq.Base.equal",
"Lib.Buffer.as_seq",
"FStar.Seq.Base.append",
"FStar.Seq.Properties.cons",
"FStar.Monotonic.HyperStack.mem",
"FStar.HyperStack.ST.get",
"Lib.Buffer.op_Array_Assignment",
"Prims.op_disEquality",
"FStar.UInt32.t",
"FStar.UInt32.__uint_to_t",
"Lib.Buffer.lbuffer_t",
"Lib.IntTypes.int_t",
"Lib.IntTypes.U8",
"Lib.IntTypes.SEC",
"Lib.Buffer.sub",
"Lib.IntTypes.op_Plus_Bang",
"Lib.IntTypes.U32",
"Lib.IntTypes.PUB",
"Prims.bool",
"Hacl.Hash.Definitions.hash_len",
"Lib.Buffer.create",
"Lib.IntTypes.u8",
"FStar.HyperStack.ST.push_frame"
] | [] | module Hacl.HMAC_DRBG
open FStar.HyperStack.ST
module ST = FStar.HyperStack.ST
open Spec.Hash.Definitions
open Lib.IntTypes
open Lib.Buffer
module HS = FStar.HyperStack
module B = LowStar.Buffer
module LSeq = Lib.Sequence
module HMAC = Hacl.HMAC
module S = Spec.HMAC_DRBG
friend Spec.HMAC_DRBG
unfold
let hash_len (a:supported_alg) = Hacl.Hash.Definitions.hash_len a
#set-options "--fuel 0 --ifuel 0 --z3rlimit 50"
inline_for_extraction noextract
val update_round: #a:supported_alg
-> hmac:HMAC.compute_st a
-> len:size_t
-> data:lbuffer uint8 len
-> n:uint8
-> k:lbuffer uint8 (hash_len a)
-> v:lbuffer uint8 (hash_len a)
-> Stack unit
(requires fun h0 ->
live h0 k /\ live h0 v /\ live h0 data /\
disjoint k v /\
// HMAC input length must fit in size_t
hash_length a + 1 + uint_v len + block_length a < pow2 32)
(ensures fun h0 _ h1 ->
S.hmac_input_bound a;
as_seq h1 k == Spec.Agile.HMAC.hmac a
(as_seq h0 k)
(Seq.append (as_seq h0 v) (Seq.cons n (as_seq h0 data))) /\
as_seq h1 v == Spec.Agile.HMAC.hmac a (as_seq h1 k) (as_seq h0 v) /\
modifies2 k v h0 h1) | false | false | Hacl.HMAC_DRBG.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val update_round: #a:supported_alg
-> hmac:HMAC.compute_st a
-> len:size_t
-> data:lbuffer uint8 len
-> n:uint8
-> k:lbuffer uint8 (hash_len a)
-> v:lbuffer uint8 (hash_len a)
-> Stack unit
(requires fun h0 ->
live h0 k /\ live h0 v /\ live h0 data /\
disjoint k v /\
// HMAC input length must fit in size_t
hash_length a + 1 + uint_v len + block_length a < pow2 32)
(ensures fun h0 _ h1 ->
S.hmac_input_bound a;
as_seq h1 k == Spec.Agile.HMAC.hmac a
(as_seq h0 k)
(Seq.append (as_seq h0 v) (Seq.cons n (as_seq h0 data))) /\
as_seq h1 v == Spec.Agile.HMAC.hmac a (as_seq h1 k) (as_seq h0 v) /\
modifies2 k v h0 h1) | [] | Hacl.HMAC_DRBG.update_round | {
"file_name": "code/drbg/Hacl.HMAC_DRBG.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} |
hmac: Hacl.HMAC.compute_st a ->
len: Lib.IntTypes.size_t ->
data: Lib.Buffer.lbuffer Lib.IntTypes.uint8 len ->
n: Lib.IntTypes.uint8 ->
k: Lib.Buffer.lbuffer Lib.IntTypes.uint8 (Hacl.HMAC_DRBG.hash_len a) ->
v: Lib.Buffer.lbuffer Lib.IntTypes.uint8 (Hacl.HMAC_DRBG.hash_len a)
-> FStar.HyperStack.ST.Stack Prims.unit | {
"end_col": 13,
"end_line": 63,
"start_col": 41,
"start_line": 47
} |
Prims.Tot | val mk_generate: #a:supported_alg -> HMAC.compute_st a -> generate_st a | [
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": true,
"full_module": "Spec.HMAC_DRBG",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "Hacl.HMAC",
"short_module": "HMAC"
},
{
"abbrev": true,
"full_module": "Lib.Sequence",
"short_module": "LSeq"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": false,
"full_module": "Lib.Buffer",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Hash.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let mk_generate #a hmac output st n additional_input_len additional_input =
if st.reseed_counter.(0ul) >. reseed_interval then
false
else
begin
S.hmac_input_bound a;
Math.Lemmas.lemma_div_mod (v n) (hash_length a);
let State k v ctr = st in
if additional_input_len >. 0ul then
update hmac additional_input_len additional_input k v;
let output:lbuffer uint8 n = output in
let max = n /. hash_len a in
let out = sub output 0ul (max *! hash_len a) in
[@inline_let]
let a_spec = S.a_spec a in
[@inline_let]
let refl h i = as_seq h v in
[@inline_let]
let spec h0 = S.generate_loop a (as_seq h0 k) (uint_v max) in
let h0 = ST.get () in
fill_blocks h0 (hash_len a) max out a_spec refl (fun i -> loc v) spec
(fun i ->
LSeq.unfold_generate_blocks
(hash_length a) (uint_v max) a_spec (spec h0) (as_seq h0 v) (uint_v i);
hmac v k (hash_len a) v (hash_len a);
copy (sub out (i *! hash_len a) (hash_len a)) v
);
if max *! hash_len a <. n then
begin
let h1 = ST.get () in
let block = sub output (max *! hash_len a) (n -! (max *! hash_len a)) in
hmac v k (hash_len a) v (hash_len a);
copy block (sub v 0ul (n -! (max *! hash_len a)));
let h2 = ST.get () in
LSeq.eq_intro (as_seq h2 output)
(as_seq h1 out `LSeq.op_At_Bar` as_seq h2 block)
end;
update hmac additional_input_len additional_input k v;
let old_ctr = ctr.(0ul) in
ctr.(0ul) <- old_ctr +! 1ul;
true
end | val mk_generate: #a:supported_alg -> HMAC.compute_st a -> generate_st a
let mk_generate #a hmac output st n additional_input_len additional_input = | false | null | false | if st.reseed_counter.(0ul) >. reseed_interval
then false
else
(S.hmac_input_bound a;
Math.Lemmas.lemma_div_mod (v n) (hash_length a);
let State k v ctr = st in
if additional_input_len >. 0ul then update hmac additional_input_len additional_input k v;
let output:lbuffer uint8 n = output in
let max = n /. hash_len a in
let out = sub output 0ul (max *! hash_len a) in
[@@ inline_let ]let a_spec = S.a_spec a in
[@@ inline_let ]let refl h i = as_seq h v in
[@@ inline_let ]let spec h0 = S.generate_loop a (as_seq h0 k) (uint_v max) in
let h0 = ST.get () in
fill_blocks h0
(hash_len a)
max
out
a_spec
refl
(fun i -> loc v)
spec
(fun i ->
LSeq.unfold_generate_blocks (hash_length a)
(uint_v max)
a_spec
(spec h0)
(as_seq h0 v)
(uint_v i);
hmac v k (hash_len a) v (hash_len a);
copy (sub out (i *! hash_len a) (hash_len a)) v);
if max *! hash_len a <. n
then
(let h1 = ST.get () in
let block = sub output (max *! hash_len a) (n -! (max *! hash_len a)) in
hmac v k (hash_len a) v (hash_len a);
copy block (sub v 0ul (n -! (max *! hash_len a)));
let h2 = ST.get () in
LSeq.eq_intro (as_seq h2 output) ((as_seq h1 out) `LSeq.op_At_Bar` (as_seq h2 block)));
update hmac additional_input_len additional_input k v;
let old_ctr = ctr.(0ul) in
ctr.(0ul) <- old_ctr +! 1ul;
true) | {
"checked_file": "Hacl.HMAC_DRBG.fst.checked",
"dependencies": [
"Spec.HMAC_DRBG.fst.checked",
"Spec.HMAC_DRBG.fst.checked",
"Spec.Hash.Definitions.fst.checked",
"Spec.Agile.HMAC.fsti.checked",
"prims.fst.checked",
"LowStar.Buffer.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.Buffer.fsti.checked",
"Hacl.HMAC.fsti.checked",
"Hacl.Hash.Definitions.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked"
],
"interface_file": true,
"source_file": "Hacl.HMAC_DRBG.fst"
} | [
"total"
] | [
"Hacl.HMAC_DRBG.supported_alg",
"Hacl.HMAC.compute_st",
"Lib.Buffer.buffer",
"Lib.IntTypes.uint8",
"Hacl.HMAC_DRBG.state",
"Lib.IntTypes.size_t",
"Lib.Buffer.lbuffer",
"Prims.bool",
"Hacl.HMAC_DRBG.hash_len",
"FStar.UInt32.__uint_to_t",
"Prims.l_and",
"Lib.Buffer.disjoint",
"Lib.Buffer.MUT",
"Prims.unit",
"Lib.Buffer.op_Array_Assignment",
"Lib.IntTypes.op_Plus_Bang",
"Lib.IntTypes.U32",
"Lib.IntTypes.PUB",
"Lib.IntTypes.int_t",
"Lib.Buffer.op_Array_Access",
"Hacl.HMAC_DRBG.update",
"Lib.IntTypes.op_Less_Dot",
"Lib.IntTypes.op_Star_Bang",
"Lib.Sequence.eq_intro",
"Lib.IntTypes.U8",
"Lib.IntTypes.SEC",
"Lib.IntTypes.v",
"Lib.Buffer.as_seq",
"Lib.Sequence.op_At_Bar",
"Lib.IntTypes.op_Subtraction_Bang",
"FStar.Monotonic.HyperStack.mem",
"FStar.HyperStack.ST.get",
"Lib.Buffer.copy",
"Lib.Buffer.lbuffer_t",
"Lib.IntTypes.sub",
"Lib.IntTypes.mul",
"Hacl.Hash.Definitions.hash_len",
"Lib.Buffer.sub",
"Lib.Buffer.fill_blocks",
"Lib.IntTypes.size_nat",
"Prims.b2t",
"Prims.op_LessThanOrEqual",
"Lib.Buffer.loc",
"LowStar.Monotonic.Buffer.loc",
"LowStar.Monotonic.Buffer.loc_disjoint",
"LowStar.Monotonic.Buffer.loc_includes",
"LowStar.Monotonic.Buffer.address_liveness_insensitive_locs",
"Prims.op_LessThan",
"Lib.Sequence.unfold_generate_blocks",
"Spec.Hash.Definitions.hash_length",
"Lib.IntTypes.uint_v",
"Prims.nat",
"Spec.HMAC_DRBG.a_spec",
"FStar.Pervasives.Native.tuple2",
"Prims.op_Addition",
"Lib.Sequence.lseq",
"Prims.l_True",
"Spec.HMAC_DRBG.generate_loop",
"Prims.op_Subtraction",
"Prims.pow2",
"Lib.IntTypes.op_Slash_Dot",
"Lib.IntTypes.op_Greater_Dot",
"FStar.Math.Lemmas.lemma_div_mod",
"Spec.HMAC_DRBG.hmac_input_bound",
"Hacl.HMAC_DRBG.reseed_interval",
"Hacl.HMAC_DRBG.__proj__State__item__reseed_counter"
] | [] | module Hacl.HMAC_DRBG
open FStar.HyperStack.ST
module ST = FStar.HyperStack.ST
open Spec.Hash.Definitions
open Lib.IntTypes
open Lib.Buffer
module HS = FStar.HyperStack
module B = LowStar.Buffer
module LSeq = Lib.Sequence
module HMAC = Hacl.HMAC
module S = Spec.HMAC_DRBG
friend Spec.HMAC_DRBG
unfold
let hash_len (a:supported_alg) = Hacl.Hash.Definitions.hash_len a
#set-options "--fuel 0 --ifuel 0 --z3rlimit 50"
inline_for_extraction noextract
val update_round: #a:supported_alg
-> hmac:HMAC.compute_st a
-> len:size_t
-> data:lbuffer uint8 len
-> n:uint8
-> k:lbuffer uint8 (hash_len a)
-> v:lbuffer uint8 (hash_len a)
-> Stack unit
(requires fun h0 ->
live h0 k /\ live h0 v /\ live h0 data /\
disjoint k v /\
// HMAC input length must fit in size_t
hash_length a + 1 + uint_v len + block_length a < pow2 32)
(ensures fun h0 _ h1 ->
S.hmac_input_bound a;
as_seq h1 k == Spec.Agile.HMAC.hmac a
(as_seq h0 k)
(Seq.append (as_seq h0 v) (Seq.cons n (as_seq h0 data))) /\
as_seq h1 v == Spec.Agile.HMAC.hmac a (as_seq h1 k) (as_seq h0 v) /\
modifies2 k v h0 h1)
let update_round #a hmac len data n k v =
let h0 = ST.get() in
push_frame();
let input_len = hash_len a +! 1ul +! len in
let input = create input_len (u8 0) in
let k' = sub input 0ul (hash_len a) in
copy k' v;
if len <> 0ul then copy (sub input (hash_len a +! 1ul) len) data;
input.(hash_len a) <- n;
let h1 = ST.get() in
assert (Seq.equal (as_seq h1 input)
(Seq.append (as_seq h0 v) (Seq.cons n (as_seq h0 data))));
S.hmac_input_bound a;
hmac k' k (hash_len a) input input_len;
hmac v k' (hash_len a) v (hash_len a);
copy k k';
pop_frame()
inline_for_extraction noextract
val update: #a:supported_alg
-> hmac:HMAC.compute_st a
-> len:size_t
-> data:lbuffer uint8 len
-> k:lbuffer uint8 (hash_len a)
-> v:lbuffer uint8 (hash_len a)
-> Stack unit
(requires fun h0 ->
live h0 data /\ live h0 k /\ live h0 v /\
disjoint k v /\ disjoint k data /\ disjoint v data /\
hash_length a + 1 + uint_v len + block_length a < pow2 32)
(ensures fun h0 _ h1 ->
S.hmac_input_bound a;
let k', v' = S.update #a (as_seq h0 data) (as_seq h0 k) (as_seq h0 v) in
modifies2 k v h0 h1 /\
as_seq h1 k == k' /\
as_seq h1 v == v')
let update #a hmac len data k v =
update_round hmac len data (u8 0) k v;
if len <> 0ul then
update_round hmac len data (u8 1) k v
noeq
type state (a:supported_alg) =
| State:
k:lbuffer uint8 (hash_len a)
-> v:lbuffer uint8 (hash_len a)
-> reseed_counter:lbuffer size_t 1ul
{disjoint k v /\ disjoint k reseed_counter /\ disjoint v reseed_counter}
-> state a
let freeable #a st =
let k:B.buffer uint8 = st.k in
let v:B.buffer uint8 = st.v in
let ctr:B.buffer size_t = st.reseed_counter in
B.freeable k /\ B.freeable v /\ B.freeable ctr
let footprint #a st =
let k:B.buffer uint8 = st.k in
let v:B.buffer uint8 = st.v in
let ctr:B.buffer size_t = st.reseed_counter in
B.loc_addr_of_buffer k |+| B.loc_addr_of_buffer v |+| B.loc_addr_of_buffer ctr
let invariant #a st h =
live h st.k /\ live h st.v /\ live h st.reseed_counter /\ (
// JP: the disjoint predicate from lib hardcodes loc_buffer instead of
// loc_addr_of_buffer, which prevents us from writing a proper free function
// (probably why it wasn't written here in the first place)... we add on top
// of the lib-style predicate a non-lib-style predicate which allows writing
// an actual free function
let k = st.k <: B.buffer uint8 in
let v = st.v <: B.buffer uint8 in
let ctr = st.reseed_counter <: B.buffer size_t in
B.(all_disjoint [ loc_addr_of_buffer k; loc_addr_of_buffer v; loc_addr_of_buffer ctr ]))
let repr #a st h =
S.State (as_seq h st.k) (as_seq h st.v) (v (bget h st.reseed_counter 0))
let alloca a =
let k =
match a with
| SHA1 -> create (hash_len SHA1) (u8 0)
| SHA2_256 -> create (hash_len SHA2_256) (u8 0)
| SHA2_384 -> create (hash_len SHA2_384) (u8 0)
| SHA2_512 -> create (hash_len SHA2_512) (u8 0)
in
let v =
match a with
| SHA1 -> create (hash_len SHA1) (u8 0)
| SHA2_256 -> create (hash_len SHA2_256) (u8 0)
| SHA2_384 -> create (hash_len SHA2_384) (u8 0)
| SHA2_512 -> create (hash_len SHA2_512) (u8 0)
in
let ctr = create 1ul 1ul in
State k v ctr
let create_in a r =
let k:B.buffer uint8 =
match a with
| SHA1 -> B.malloc r (u8 0) (hash_len SHA1)
| SHA2_256 -> B.malloc r (u8 0) (hash_len SHA2_256)
| SHA2_384 -> B.malloc r (u8 0) (hash_len SHA2_384)
| SHA2_512 -> B.malloc r (u8 0) (hash_len SHA2_512)
in
let v:B.buffer uint8 =
match a with
| SHA1 -> B.malloc r (u8 0) (hash_len SHA1)
| SHA2_256 -> B.malloc r (u8 0) (hash_len SHA2_256)
| SHA2_384 -> B.malloc r (u8 0) (hash_len SHA2_384)
| SHA2_512 -> B.malloc r (u8 0) (hash_len SHA2_512)
in
let ctr:B.buffer size_t = B.malloc r 1ul 1ul in
State k v ctr
#push-options "--z3rlimit 200"
let mk_instantiate #a hmac st
entropy_input_len entropy_input
nonce_len nonce
personalization_string_len personalization_string
=
let h0 = ST.get () in
push_frame();
let seed_material = create (entropy_input_len +! nonce_len +! personalization_string_len) (u8 0) in
copy (sub seed_material 0ul entropy_input_len) entropy_input;
copy (sub seed_material entropy_input_len nonce_len) nonce;
copy (sub seed_material (entropy_input_len +! nonce_len) personalization_string_len) personalization_string;
let State k v ctr = st in
memset k (u8 0) (hash_len a);
memset v (u8 1) (hash_len a);
let h1 = ST.get () in
assert (Seq.equal (as_seq h1 seed_material)
(Seq.append (as_seq h0 entropy_input) (Seq.append (as_seq h0 nonce)
(as_seq h0 personalization_string))));
assert (LSeq.equal (as_seq h1 k) (LSeq.create (hash_length a) (u8 0)));
assert (LSeq.equal (as_seq h1 v) (LSeq.create (hash_length a) (u8 1)));
ctr.(0ul) <- 1ul;
update hmac (entropy_input_len +! nonce_len +! personalization_string_len)
seed_material k v;
pop_frame()
#pop-options
let instantiate a st
entropy_input_len entropy_input
nonce_len nonce
personalization_string_len personalization_string
=
match a with
| SHA1 ->
mk_instantiate Hacl.HMAC.legacy_compute_sha1 st
entropy_input_len entropy_input
nonce_len nonce
personalization_string_len personalization_string
| SHA2_256 ->
mk_instantiate Hacl.HMAC.compute_sha2_256 st
entropy_input_len entropy_input
nonce_len nonce
personalization_string_len personalization_string
| SHA2_384 ->
mk_instantiate Hacl.HMAC.compute_sha2_384 st
entropy_input_len entropy_input
nonce_len nonce
personalization_string_len personalization_string
| SHA2_512 ->
mk_instantiate Hacl.HMAC.compute_sha2_512 st
entropy_input_len entropy_input
nonce_len nonce
personalization_string_len personalization_string
let mk_reseed #a hmac st
entropy_input_len entropy_input
additional_input_len additional_input
=
let h0 = ST.get () in
push_frame();
let seed_material = create (entropy_input_len +! additional_input_len) (u8 0) in
copy (sub seed_material 0ul entropy_input_len) entropy_input;
copy (sub seed_material entropy_input_len additional_input_len) additional_input;
let h1 = ST.get () in
LSeq.eq_intro (as_seq h1 seed_material)
LSeq.(as_seq h0 entropy_input @| as_seq h0 additional_input);
let State k v ctr: state a = st in
update hmac (entropy_input_len +! additional_input_len) seed_material k v;
ctr.(0ul) <- 1ul;
pop_frame()
let reseed a st
entropy_input_len entropy_input
additional_input_input_len additional_input_input =
match a with
| SHA1 ->
mk_reseed Hacl.HMAC.legacy_compute_sha1 st
entropy_input_len entropy_input
additional_input_input_len additional_input_input
| SHA2_256 ->
mk_reseed Hacl.HMAC.compute_sha2_256 st
entropy_input_len entropy_input
additional_input_input_len additional_input_input
| SHA2_384 ->
mk_reseed Hacl.HMAC.compute_sha2_384 st
entropy_input_len entropy_input
additional_input_input_len additional_input_input
| SHA2_512 ->
mk_reseed Hacl.HMAC.compute_sha2_512 st
entropy_input_len entropy_input
additional_input_input_len additional_input_input
#push-options "--z3rlimit 300" | false | false | Hacl.HMAC_DRBG.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 300,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val mk_generate: #a:supported_alg -> HMAC.compute_st a -> generate_st a | [] | Hacl.HMAC_DRBG.mk_generate | {
"file_name": "code/drbg/Hacl.HMAC_DRBG.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | hmac: Hacl.HMAC.compute_st a -> Hacl.HMAC_DRBG.generate_st a | {
"end_col": 7,
"end_line": 302,
"start_col": 2,
"start_line": 262
} |
Prims.Tot | val mk_instantiate: #a:supported_alg -> hmac:HMAC.compute_st a -> instantiate_st a | [
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": true,
"full_module": "Spec.HMAC_DRBG",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "Hacl.HMAC",
"short_module": "HMAC"
},
{
"abbrev": true,
"full_module": "Lib.Sequence",
"short_module": "LSeq"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": false,
"full_module": "Lib.Buffer",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Hash.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let mk_instantiate #a hmac st
entropy_input_len entropy_input
nonce_len nonce
personalization_string_len personalization_string
=
let h0 = ST.get () in
push_frame();
let seed_material = create (entropy_input_len +! nonce_len +! personalization_string_len) (u8 0) in
copy (sub seed_material 0ul entropy_input_len) entropy_input;
copy (sub seed_material entropy_input_len nonce_len) nonce;
copy (sub seed_material (entropy_input_len +! nonce_len) personalization_string_len) personalization_string;
let State k v ctr = st in
memset k (u8 0) (hash_len a);
memset v (u8 1) (hash_len a);
let h1 = ST.get () in
assert (Seq.equal (as_seq h1 seed_material)
(Seq.append (as_seq h0 entropy_input) (Seq.append (as_seq h0 nonce)
(as_seq h0 personalization_string))));
assert (LSeq.equal (as_seq h1 k) (LSeq.create (hash_length a) (u8 0)));
assert (LSeq.equal (as_seq h1 v) (LSeq.create (hash_length a) (u8 1)));
ctr.(0ul) <- 1ul;
update hmac (entropy_input_len +! nonce_len +! personalization_string_len)
seed_material k v;
pop_frame() | val mk_instantiate: #a:supported_alg -> hmac:HMAC.compute_st a -> instantiate_st a
let mk_instantiate
#a
hmac
st
entropy_input_len
entropy_input
nonce_len
nonce
personalization_string_len
personalization_string
= | false | null | false | let h0 = ST.get () in
push_frame ();
let seed_material = create (entropy_input_len +! nonce_len +! personalization_string_len) (u8 0) in
copy (sub seed_material 0ul entropy_input_len) entropy_input;
copy (sub seed_material entropy_input_len nonce_len) nonce;
copy (sub seed_material (entropy_input_len +! nonce_len) personalization_string_len)
personalization_string;
let State k v ctr = st in
memset k (u8 0) (hash_len a);
memset v (u8 1) (hash_len a);
let h1 = ST.get () in
assert (Seq.equal (as_seq h1 seed_material)
(Seq.append (as_seq h0 entropy_input)
(Seq.append (as_seq h0 nonce) (as_seq h0 personalization_string))));
assert (LSeq.equal (as_seq h1 k) (LSeq.create (hash_length a) (u8 0)));
assert (LSeq.equal (as_seq h1 v) (LSeq.create (hash_length a) (u8 1)));
ctr.(0ul) <- 1ul;
update hmac (entropy_input_len +! nonce_len +! personalization_string_len) seed_material k v;
pop_frame () | {
"checked_file": "Hacl.HMAC_DRBG.fst.checked",
"dependencies": [
"Spec.HMAC_DRBG.fst.checked",
"Spec.HMAC_DRBG.fst.checked",
"Spec.Hash.Definitions.fst.checked",
"Spec.Agile.HMAC.fsti.checked",
"prims.fst.checked",
"LowStar.Buffer.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.Buffer.fsti.checked",
"Hacl.HMAC.fsti.checked",
"Hacl.Hash.Definitions.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked"
],
"interface_file": true,
"source_file": "Hacl.HMAC_DRBG.fst"
} | [
"total"
] | [
"Hacl.HMAC_DRBG.supported_alg",
"Hacl.HMAC.compute_st",
"Hacl.HMAC_DRBG.state",
"Lib.IntTypes.size_t",
"Lib.Buffer.lbuffer",
"Lib.IntTypes.uint8",
"Hacl.HMAC_DRBG.hash_len",
"FStar.UInt32.__uint_to_t",
"Prims.l_and",
"Lib.Buffer.disjoint",
"Lib.Buffer.MUT",
"FStar.HyperStack.ST.pop_frame",
"Prims.unit",
"Hacl.HMAC_DRBG.update",
"Lib.IntTypes.op_Plus_Bang",
"Lib.IntTypes.U32",
"Lib.IntTypes.PUB",
"Lib.Buffer.op_Array_Assignment",
"Prims._assert",
"Lib.Sequence.equal",
"Lib.IntTypes.v",
"Lib.Buffer.as_seq",
"Lib.Sequence.create",
"Spec.Hash.Definitions.hash_length",
"Lib.IntTypes.u8",
"FStar.Seq.Base.equal",
"FStar.Seq.Base.append",
"FStar.Monotonic.HyperStack.mem",
"FStar.HyperStack.ST.get",
"Lib.Buffer.memset",
"Lib.Buffer.copy",
"Lib.Buffer.lbuffer_t",
"Lib.IntTypes.int_t",
"Lib.IntTypes.U8",
"Lib.IntTypes.SEC",
"Lib.Buffer.sub",
"Lib.IntTypes.add",
"Lib.Buffer.create",
"FStar.HyperStack.ST.push_frame"
] | [] | module Hacl.HMAC_DRBG
open FStar.HyperStack.ST
module ST = FStar.HyperStack.ST
open Spec.Hash.Definitions
open Lib.IntTypes
open Lib.Buffer
module HS = FStar.HyperStack
module B = LowStar.Buffer
module LSeq = Lib.Sequence
module HMAC = Hacl.HMAC
module S = Spec.HMAC_DRBG
friend Spec.HMAC_DRBG
unfold
let hash_len (a:supported_alg) = Hacl.Hash.Definitions.hash_len a
#set-options "--fuel 0 --ifuel 0 --z3rlimit 50"
inline_for_extraction noextract
val update_round: #a:supported_alg
-> hmac:HMAC.compute_st a
-> len:size_t
-> data:lbuffer uint8 len
-> n:uint8
-> k:lbuffer uint8 (hash_len a)
-> v:lbuffer uint8 (hash_len a)
-> Stack unit
(requires fun h0 ->
live h0 k /\ live h0 v /\ live h0 data /\
disjoint k v /\
// HMAC input length must fit in size_t
hash_length a + 1 + uint_v len + block_length a < pow2 32)
(ensures fun h0 _ h1 ->
S.hmac_input_bound a;
as_seq h1 k == Spec.Agile.HMAC.hmac a
(as_seq h0 k)
(Seq.append (as_seq h0 v) (Seq.cons n (as_seq h0 data))) /\
as_seq h1 v == Spec.Agile.HMAC.hmac a (as_seq h1 k) (as_seq h0 v) /\
modifies2 k v h0 h1)
let update_round #a hmac len data n k v =
let h0 = ST.get() in
push_frame();
let input_len = hash_len a +! 1ul +! len in
let input = create input_len (u8 0) in
let k' = sub input 0ul (hash_len a) in
copy k' v;
if len <> 0ul then copy (sub input (hash_len a +! 1ul) len) data;
input.(hash_len a) <- n;
let h1 = ST.get() in
assert (Seq.equal (as_seq h1 input)
(Seq.append (as_seq h0 v) (Seq.cons n (as_seq h0 data))));
S.hmac_input_bound a;
hmac k' k (hash_len a) input input_len;
hmac v k' (hash_len a) v (hash_len a);
copy k k';
pop_frame()
inline_for_extraction noextract
val update: #a:supported_alg
-> hmac:HMAC.compute_st a
-> len:size_t
-> data:lbuffer uint8 len
-> k:lbuffer uint8 (hash_len a)
-> v:lbuffer uint8 (hash_len a)
-> Stack unit
(requires fun h0 ->
live h0 data /\ live h0 k /\ live h0 v /\
disjoint k v /\ disjoint k data /\ disjoint v data /\
hash_length a + 1 + uint_v len + block_length a < pow2 32)
(ensures fun h0 _ h1 ->
S.hmac_input_bound a;
let k', v' = S.update #a (as_seq h0 data) (as_seq h0 k) (as_seq h0 v) in
modifies2 k v h0 h1 /\
as_seq h1 k == k' /\
as_seq h1 v == v')
let update #a hmac len data k v =
update_round hmac len data (u8 0) k v;
if len <> 0ul then
update_round hmac len data (u8 1) k v
noeq
type state (a:supported_alg) =
| State:
k:lbuffer uint8 (hash_len a)
-> v:lbuffer uint8 (hash_len a)
-> reseed_counter:lbuffer size_t 1ul
{disjoint k v /\ disjoint k reseed_counter /\ disjoint v reseed_counter}
-> state a
let freeable #a st =
let k:B.buffer uint8 = st.k in
let v:B.buffer uint8 = st.v in
let ctr:B.buffer size_t = st.reseed_counter in
B.freeable k /\ B.freeable v /\ B.freeable ctr
let footprint #a st =
let k:B.buffer uint8 = st.k in
let v:B.buffer uint8 = st.v in
let ctr:B.buffer size_t = st.reseed_counter in
B.loc_addr_of_buffer k |+| B.loc_addr_of_buffer v |+| B.loc_addr_of_buffer ctr
let invariant #a st h =
live h st.k /\ live h st.v /\ live h st.reseed_counter /\ (
// JP: the disjoint predicate from lib hardcodes loc_buffer instead of
// loc_addr_of_buffer, which prevents us from writing a proper free function
// (probably why it wasn't written here in the first place)... we add on top
// of the lib-style predicate a non-lib-style predicate which allows writing
// an actual free function
let k = st.k <: B.buffer uint8 in
let v = st.v <: B.buffer uint8 in
let ctr = st.reseed_counter <: B.buffer size_t in
B.(all_disjoint [ loc_addr_of_buffer k; loc_addr_of_buffer v; loc_addr_of_buffer ctr ]))
let repr #a st h =
S.State (as_seq h st.k) (as_seq h st.v) (v (bget h st.reseed_counter 0))
let alloca a =
let k =
match a with
| SHA1 -> create (hash_len SHA1) (u8 0)
| SHA2_256 -> create (hash_len SHA2_256) (u8 0)
| SHA2_384 -> create (hash_len SHA2_384) (u8 0)
| SHA2_512 -> create (hash_len SHA2_512) (u8 0)
in
let v =
match a with
| SHA1 -> create (hash_len SHA1) (u8 0)
| SHA2_256 -> create (hash_len SHA2_256) (u8 0)
| SHA2_384 -> create (hash_len SHA2_384) (u8 0)
| SHA2_512 -> create (hash_len SHA2_512) (u8 0)
in
let ctr = create 1ul 1ul in
State k v ctr
let create_in a r =
let k:B.buffer uint8 =
match a with
| SHA1 -> B.malloc r (u8 0) (hash_len SHA1)
| SHA2_256 -> B.malloc r (u8 0) (hash_len SHA2_256)
| SHA2_384 -> B.malloc r (u8 0) (hash_len SHA2_384)
| SHA2_512 -> B.malloc r (u8 0) (hash_len SHA2_512)
in
let v:B.buffer uint8 =
match a with
| SHA1 -> B.malloc r (u8 0) (hash_len SHA1)
| SHA2_256 -> B.malloc r (u8 0) (hash_len SHA2_256)
| SHA2_384 -> B.malloc r (u8 0) (hash_len SHA2_384)
| SHA2_512 -> B.malloc r (u8 0) (hash_len SHA2_512)
in
let ctr:B.buffer size_t = B.malloc r 1ul 1ul in
State k v ctr
#push-options "--z3rlimit 200"
let mk_instantiate #a hmac st
entropy_input_len entropy_input
nonce_len nonce | false | false | Hacl.HMAC_DRBG.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 200,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val mk_instantiate: #a:supported_alg -> hmac:HMAC.compute_st a -> instantiate_st a | [] | Hacl.HMAC_DRBG.mk_instantiate | {
"file_name": "code/drbg/Hacl.HMAC_DRBG.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | hmac: Hacl.HMAC.compute_st a -> Hacl.HMAC_DRBG.instantiate_st a | {
"end_col": 13,
"end_line": 188,
"start_col": 1,
"start_line": 169
} |
Prims.Tot | val int_of_char (c: char) : nat | [
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"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
}
] | false | let int_of_char (c: char) : nat = U32.v (u32_of_char c) | val int_of_char (c: char) : nat
let int_of_char (c: char) : nat = | false | null | false | U32.v (u32_of_char c) | {
"checked_file": "FStar.Char.fsti.checked",
"dependencies": [
"prims.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.Pervasives.fsti.checked"
],
"interface_file": false,
"source_file": "FStar.Char.fsti"
} | [
"total"
] | [
"FStar.Char.char",
"FStar.UInt32.v",
"FStar.Char.u32_of_char",
"Prims.nat"
] | [] | (*
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 FStar.Char
/// This module provides the [char] type, an abstract type
/// representing UTF-8 characters.
///
/// UTF-8 characters are representing in a variable-length encoding of
/// between 1 and 4 bytes, with a maximum of 21 bits used to represent
/// a code.
///
/// See https://en.wikipedia.org/wiki/UTF-8 and
/// https://erratique.ch/software/uucp/doc/unicode.html
module U32 = FStar.UInt32
(** [char] is a new primitive type with decidable equality *)
new
val char:eqtype
(** A [char_code] is the representation of a UTF-8 char code in
an unsigned 32-bit integer whose value is at most 0x110000,
and not between 0xd800 and 0xe000 *)
type char_code = n: U32.t{U32.v n < 0xd7ff \/ (U32.v n >= 0xe000 /\ U32.v n <= 0x10ffff)}
(** A primitive to extract the [char_code] of a [char] *)
val u32_of_char: char -> Tot char_code
(** A primitive to promote a [char_code] to a [char] *)
val char_of_u32: char_code -> Tot char
(** Encoding and decoding from [char] to [char_code] is the identity *)
val char_of_u32_of_char (c: char)
: Lemma (ensures (char_of_u32 (u32_of_char c) == c)) [SMTPat (u32_of_char c)]
(** Encoding and decoding from [char] to [char_code] is the identity *)
val u32_of_char_of_u32 (c: char_code)
: Lemma (ensures (u32_of_char (char_of_u32 c) == c)) [SMTPat (char_of_u32 c)]
(** A couple of utilities to use mathematical integers rather than [U32.t] | false | true | FStar.Char.fsti | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val int_of_char (c: char) : nat | [] | FStar.Char.int_of_char | {
"file_name": "ulib/FStar.Char.fsti",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | c: FStar.Char.char -> Prims.nat | {
"end_col": 55,
"end_line": 56,
"start_col": 34,
"start_line": 56
} |
Prims.Tot | val char_of_int (i: nat{i < 0xd7ff \/ (i >= 0xe000 /\ i <= 0x10ffff)}) : char | [
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"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
}
] | false | let char_of_int (i: nat{i < 0xd7ff \/ (i >= 0xe000 /\ i <= 0x10ffff)}) : char = char_of_u32 (U32.uint_to_t i) | val char_of_int (i: nat{i < 0xd7ff \/ (i >= 0xe000 /\ i <= 0x10ffff)}) : char
let char_of_int (i: nat{i < 0xd7ff \/ (i >= 0xe000 /\ i <= 0x10ffff)}) : char = | false | null | false | char_of_u32 (U32.uint_to_t i) | {
"checked_file": "FStar.Char.fsti.checked",
"dependencies": [
"prims.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.Pervasives.fsti.checked"
],
"interface_file": false,
"source_file": "FStar.Char.fsti"
} | [
"total"
] | [
"Prims.nat",
"Prims.l_or",
"Prims.b2t",
"Prims.op_LessThan",
"Prims.l_and",
"Prims.op_GreaterThanOrEqual",
"Prims.op_LessThanOrEqual",
"FStar.Char.char_of_u32",
"FStar.UInt32.uint_to_t",
"FStar.Char.char"
] | [] | (*
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 FStar.Char
/// This module provides the [char] type, an abstract type
/// representing UTF-8 characters.
///
/// UTF-8 characters are representing in a variable-length encoding of
/// between 1 and 4 bytes, with a maximum of 21 bits used to represent
/// a code.
///
/// See https://en.wikipedia.org/wiki/UTF-8 and
/// https://erratique.ch/software/uucp/doc/unicode.html
module U32 = FStar.UInt32
(** [char] is a new primitive type with decidable equality *)
new
val char:eqtype
(** A [char_code] is the representation of a UTF-8 char code in
an unsigned 32-bit integer whose value is at most 0x110000,
and not between 0xd800 and 0xe000 *)
type char_code = n: U32.t{U32.v n < 0xd7ff \/ (U32.v n >= 0xe000 /\ U32.v n <= 0x10ffff)}
(** A primitive to extract the [char_code] of a [char] *)
val u32_of_char: char -> Tot char_code
(** A primitive to promote a [char_code] to a [char] *)
val char_of_u32: char_code -> Tot char
(** Encoding and decoding from [char] to [char_code] is the identity *)
val char_of_u32_of_char (c: char)
: Lemma (ensures (char_of_u32 (u32_of_char c) == c)) [SMTPat (u32_of_char c)]
(** Encoding and decoding from [char] to [char_code] is the identity *)
val u32_of_char_of_u32 (c: char_code)
: Lemma (ensures (u32_of_char (char_of_u32 c) == c)) [SMTPat (char_of_u32 c)]
(** A couple of utilities to use mathematical integers rather than [U32.t]
to represent a [char_code] *) | false | false | FStar.Char.fsti | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val char_of_int (i: nat{i < 0xd7ff \/ (i >= 0xe000 /\ i <= 0x10ffff)}) : char | [] | FStar.Char.char_of_int | {
"file_name": "ulib/FStar.Char.fsti",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | i: Prims.nat{i < 0xd7ff \/ i >= 0xe000 /\ i <= 0x10ffff} -> FStar.Char.char | {
"end_col": 109,
"end_line": 57,
"start_col": 80,
"start_line": 57
} |
Prims.Tot | [
{
"abbrev": false,
"full_module": "FStar.Exn",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Heap",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let all_wp (a : Type) = all_wp_h heap a | let all_wp (a: Type) = | false | null | false | all_wp_h heap a | {
"checked_file": "FStar.All.fst.checked",
"dependencies": [
"prims.fst.checked",
"FStar.ST.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Heap.fst.checked",
"FStar.Exn.fst.checked"
],
"interface_file": false,
"source_file": "FStar.All.fst"
} | [
"total"
] | [
"FStar.Pervasives.all_wp_h",
"FStar.Monotonic.Heap.heap"
] | [] | (*
Copyright 2008-2014 Nikhil Swamy and 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 FStar.All
open FStar.Heap
include FStar.ST
include FStar.Exn
let all_pre = all_pre_h heap
let all_post' (a : Type) (pre:Type) = all_post_h' heap a pre | false | true | FStar.All.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val all_wp : a: Type -> Type | [] | FStar.All.all_wp | {
"file_name": "ulib/FStar.All.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | a: Type -> Type | {
"end_col": 39,
"end_line": 24,
"start_col": 24,
"start_line": 24
} |
|
Prims.Tot | [
{
"abbrev": false,
"full_module": "FStar.Exn",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Heap",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let lift_state_all (a : Type) (wp : st_wp a) (p : all_post a) = wp (fun a -> p (V a)) | let lift_state_all (a: Type) (wp: st_wp a) (p: all_post a) = | false | null | false | wp (fun a -> p (V a)) | {
"checked_file": "FStar.All.fst.checked",
"dependencies": [
"prims.fst.checked",
"FStar.ST.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Heap.fst.checked",
"FStar.Exn.fst.checked"
],
"interface_file": false,
"source_file": "FStar.All.fst"
} | [
"total"
] | [
"FStar.ST.st_wp",
"FStar.All.all_post",
"FStar.Pervasives.V",
"FStar.Monotonic.Heap.heap",
"Prims.l_True",
"FStar.Pervasives.st_pre_h"
] | [] | (*
Copyright 2008-2014 Nikhil Swamy and 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 FStar.All
open FStar.Heap
include FStar.ST
include FStar.Exn
let all_pre = all_pre_h heap
let all_post' (a : Type) (pre:Type) = all_post_h' heap a pre
let all_post (a : Type) = all_post_h heap a
let all_wp (a : Type) = all_wp_h heap a
new_effect ALL = ALL_h heap | false | false | FStar.All.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val lift_state_all : a: Type -> wp: FStar.ST.st_wp a -> p: FStar.All.all_post a
-> FStar.Pervasives.st_pre_h FStar.Monotonic.Heap.heap | [] | FStar.All.lift_state_all | {
"file_name": "ulib/FStar.All.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | a: Type -> wp: FStar.ST.st_wp a -> p: FStar.All.all_post a
-> FStar.Pervasives.st_pre_h FStar.Monotonic.Heap.heap | {
"end_col": 92,
"end_line": 27,
"start_col": 71,
"start_line": 27
} |
|
Prims.Tot | [
{
"abbrev": false,
"full_module": "FStar.Exn",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Heap",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let all_post (a : Type) = all_post_h heap a | let all_post (a: Type) = | false | null | false | all_post_h heap a | {
"checked_file": "FStar.All.fst.checked",
"dependencies": [
"prims.fst.checked",
"FStar.ST.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Heap.fst.checked",
"FStar.Exn.fst.checked"
],
"interface_file": false,
"source_file": "FStar.All.fst"
} | [
"total"
] | [
"FStar.Pervasives.all_post_h",
"FStar.Monotonic.Heap.heap"
] | [] | (*
Copyright 2008-2014 Nikhil Swamy and 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 FStar.All
open FStar.Heap
include FStar.ST
include FStar.Exn
let all_pre = all_pre_h heap | false | true | FStar.All.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val all_post : a: Type -> Type | [] | FStar.All.all_post | {
"file_name": "ulib/FStar.All.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | a: Type -> Type | {
"end_col": 43,
"end_line": 23,
"start_col": 26,
"start_line": 23
} |
|
Prims.Tot | [
{
"abbrev": false,
"full_module": "FStar.Exn",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Heap",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let all_pre = all_pre_h heap | let all_pre = | false | null | false | all_pre_h heap | {
"checked_file": "FStar.All.fst.checked",
"dependencies": [
"prims.fst.checked",
"FStar.ST.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Heap.fst.checked",
"FStar.Exn.fst.checked"
],
"interface_file": false,
"source_file": "FStar.All.fst"
} | [
"total"
] | [
"FStar.Pervasives.all_pre_h",
"FStar.Monotonic.Heap.heap"
] | [] | (*
Copyright 2008-2014 Nikhil Swamy and 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 FStar.All
open FStar.Heap
include FStar.ST
include FStar.Exn | false | true | FStar.All.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val all_pre : Type | [] | FStar.All.all_pre | {
"file_name": "ulib/FStar.All.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | Type | {
"end_col": 28,
"end_line": 21,
"start_col": 14,
"start_line": 21
} |
|
FStar.All.ML | [
{
"abbrev": false,
"full_module": "FStar.Exn",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Heap",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let pipe_right = ( |> ) | let pipe_right = | false | null | false | ( |> ) | {
"checked_file": "FStar.All.fst.checked",
"dependencies": [
"prims.fst.checked",
"FStar.ST.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Heap.fst.checked",
"FStar.Exn.fst.checked"
],
"interface_file": false,
"source_file": "FStar.All.fst"
} | [
"ml"
] | [
"FStar.All.op_Bar_Greater"
] | [] | (*
Copyright 2008-2014 Nikhil Swamy and 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 FStar.All
open FStar.Heap
include FStar.ST
include FStar.Exn
let all_pre = all_pre_h heap
let all_post' (a : Type) (pre:Type) = all_post_h' heap a pre
let all_post (a : Type) = all_post_h heap a
let all_wp (a : Type) = all_wp_h heap a
new_effect ALL = ALL_h heap
unfold let lift_state_all (a : Type) (wp : st_wp a) (p : all_post a) = wp (fun a -> p (V a))
sub_effect STATE ~> ALL { lift_wp = lift_state_all }
unfold
let lift_exn_all (a : Type) (wp : ex_wp a) (p : all_post a) (h : heap) = wp (fun ra -> p ra h)
sub_effect EXN ~> ALL { lift_wp = lift_exn_all }
effect All (a:Type) (pre:all_pre) (post:(h:heap -> Tot (all_post' a (pre h)))) =
ALL a
(fun (p : all_post a) (h : heap) -> pre h /\ (forall ra h1. post h ra h1 ==> p ra h1))
effect ML (a:Type) = ALL a (fun (p:all_post a) (_:heap) -> forall (a:result a) (h:heap). p a h) | false | false | FStar.All.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val pipe_right : x: _ -> f: (_: _ -> FStar.All.ML _) -> FStar.All.ML _ | [] | FStar.All.pipe_right | {
"file_name": "ulib/FStar.All.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | x: _ -> f: (_: _ -> FStar.All.ML _) -> FStar.All.ML _ | {
"end_col": 21,
"end_line": 40,
"start_col": 19,
"start_line": 40
} |
|
Prims.Tot | [
{
"abbrev": false,
"full_module": "FStar.Exn",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Heap",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let lift_exn_all (a : Type) (wp : ex_wp a) (p : all_post a) (h : heap) = wp (fun ra -> p ra h) | let lift_exn_all (a: Type) (wp: ex_wp a) (p: all_post a) (h: heap) = | false | null | false | wp (fun ra -> p ra h) | {
"checked_file": "FStar.All.fst.checked",
"dependencies": [
"prims.fst.checked",
"FStar.ST.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Heap.fst.checked",
"FStar.Exn.fst.checked"
],
"interface_file": false,
"source_file": "FStar.All.fst"
} | [
"total"
] | [
"FStar.Pervasives.ex_wp",
"FStar.All.all_post",
"FStar.Monotonic.Heap.heap",
"FStar.Pervasives.result",
"Prims.l_True",
"FStar.Pervasives.ex_pre"
] | [] | (*
Copyright 2008-2014 Nikhil Swamy and 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 FStar.All
open FStar.Heap
include FStar.ST
include FStar.Exn
let all_pre = all_pre_h heap
let all_post' (a : Type) (pre:Type) = all_post_h' heap a pre
let all_post (a : Type) = all_post_h heap a
let all_wp (a : Type) = all_wp_h heap a
new_effect ALL = ALL_h heap
unfold let lift_state_all (a : Type) (wp : st_wp a) (p : all_post a) = wp (fun a -> p (V a))
sub_effect STATE ~> ALL { lift_wp = lift_state_all } | false | false | FStar.All.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val lift_exn_all : a: Type -> wp: FStar.Pervasives.ex_wp a -> p: FStar.All.all_post a -> h: FStar.Monotonic.Heap.heap
-> FStar.Pervasives.ex_pre | [] | FStar.All.lift_exn_all | {
"file_name": "ulib/FStar.All.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | a: Type -> wp: FStar.Pervasives.ex_wp a -> p: FStar.All.all_post a -> h: FStar.Monotonic.Heap.heap
-> FStar.Pervasives.ex_pre | {
"end_col": 94,
"end_line": 31,
"start_col": 73,
"start_line": 31
} |
|
Prims.Tot | [
{
"abbrev": false,
"full_module": "FStar.Exn",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Heap",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let all_post' (a : Type) (pre:Type) = all_post_h' heap a pre | let all_post' (a pre: Type) = | false | null | false | all_post_h' heap a pre | {
"checked_file": "FStar.All.fst.checked",
"dependencies": [
"prims.fst.checked",
"FStar.ST.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Heap.fst.checked",
"FStar.Exn.fst.checked"
],
"interface_file": false,
"source_file": "FStar.All.fst"
} | [
"total"
] | [
"FStar.Pervasives.all_post_h'",
"FStar.Monotonic.Heap.heap"
] | [] | (*
Copyright 2008-2014 Nikhil Swamy and 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 FStar.All
open FStar.Heap
include FStar.ST
include FStar.Exn | false | true | FStar.All.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val all_post' : a: Type -> pre: Type -> Type | [] | FStar.All.all_post' | {
"file_name": "ulib/FStar.All.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | a: Type -> pre: Type -> Type | {
"end_col": 60,
"end_line": 22,
"start_col": 38,
"start_line": 22
} |
|
FStar.All.ML | val op_Less_Bar (f: ('a -> ML 'b)) (x: 'a) : ML 'b | [
{
"abbrev": false,
"full_module": "FStar.Exn",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Heap",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let ( <| ) (f : ('a -> ML 'b)) (x : 'a) : ML 'b = f x | val op_Less_Bar (f: ('a -> ML 'b)) (x: 'a) : ML 'b
let op_Less_Bar (f: ('a -> ML 'b)) (x: 'a) : ML 'b = | false | null | false | f x | {
"checked_file": "FStar.All.fst.checked",
"dependencies": [
"prims.fst.checked",
"FStar.ST.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Heap.fst.checked",
"FStar.Exn.fst.checked"
],
"interface_file": false,
"source_file": "FStar.All.fst"
} | [
"ml"
] | [] | [] | (*
Copyright 2008-2014 Nikhil Swamy and 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 FStar.All
open FStar.Heap
include FStar.ST
include FStar.Exn
let all_pre = all_pre_h heap
let all_post' (a : Type) (pre:Type) = all_post_h' heap a pre
let all_post (a : Type) = all_post_h heap a
let all_wp (a : Type) = all_wp_h heap a
new_effect ALL = ALL_h heap
unfold let lift_state_all (a : Type) (wp : st_wp a) (p : all_post a) = wp (fun a -> p (V a))
sub_effect STATE ~> ALL { lift_wp = lift_state_all }
unfold
let lift_exn_all (a : Type) (wp : ex_wp a) (p : all_post a) (h : heap) = wp (fun ra -> p ra h)
sub_effect EXN ~> ALL { lift_wp = lift_exn_all }
effect All (a:Type) (pre:all_pre) (post:(h:heap -> Tot (all_post' a (pre h)))) =
ALL a
(fun (p : all_post a) (h : heap) -> pre h /\ (forall ra h1. post h ra h1 ==> p ra h1))
effect ML (a:Type) = ALL a (fun (p:all_post a) (_:heap) -> forall (a:result a) (h:heap). p a h)
let ( |> ) (x : 'a) (f : ('a -> ML 'b)) : ML 'b = f x
let pipe_right = ( |> ) | false | false | FStar.All.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val op_Less_Bar (f: ('a -> ML 'b)) (x: 'a) : ML 'b | [] | FStar.All.op_Less_Bar | {
"file_name": "ulib/FStar.All.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | f: (_: 'a -> FStar.All.ML 'b) -> x: 'a -> FStar.All.ML 'b | {
"end_col": 53,
"end_line": 42,
"start_col": 50,
"start_line": 42
} |
FStar.All.ML | val op_Bar_Greater (x: 'a) (f: ('a -> ML 'b)) : ML 'b | [
{
"abbrev": false,
"full_module": "FStar.Exn",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Heap",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let ( |> ) (x : 'a) (f : ('a -> ML 'b)) : ML 'b = f x | val op_Bar_Greater (x: 'a) (f: ('a -> ML 'b)) : ML 'b
let op_Bar_Greater (x: 'a) (f: ('a -> ML 'b)) : ML 'b = | false | null | false | f x | {
"checked_file": "FStar.All.fst.checked",
"dependencies": [
"prims.fst.checked",
"FStar.ST.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Heap.fst.checked",
"FStar.Exn.fst.checked"
],
"interface_file": false,
"source_file": "FStar.All.fst"
} | [
"ml"
] | [] | [] | (*
Copyright 2008-2014 Nikhil Swamy and 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 FStar.All
open FStar.Heap
include FStar.ST
include FStar.Exn
let all_pre = all_pre_h heap
let all_post' (a : Type) (pre:Type) = all_post_h' heap a pre
let all_post (a : Type) = all_post_h heap a
let all_wp (a : Type) = all_wp_h heap a
new_effect ALL = ALL_h heap
unfold let lift_state_all (a : Type) (wp : st_wp a) (p : all_post a) = wp (fun a -> p (V a))
sub_effect STATE ~> ALL { lift_wp = lift_state_all }
unfold
let lift_exn_all (a : Type) (wp : ex_wp a) (p : all_post a) (h : heap) = wp (fun ra -> p ra h)
sub_effect EXN ~> ALL { lift_wp = lift_exn_all }
effect All (a:Type) (pre:all_pre) (post:(h:heap -> Tot (all_post' a (pre h)))) =
ALL a
(fun (p : all_post a) (h : heap) -> pre h /\ (forall ra h1. post h ra h1 ==> p ra h1))
effect ML (a:Type) = ALL a (fun (p:all_post a) (_:heap) -> forall (a:result a) (h:heap). p a h) | false | false | FStar.All.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val op_Bar_Greater (x: 'a) (f: ('a -> ML 'b)) : ML 'b | [] | FStar.All.op_Bar_Greater | {
"file_name": "ulib/FStar.All.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | x: 'a -> f: (_: 'a -> FStar.All.ML 'b) -> FStar.All.ML 'b | {
"end_col": 53,
"end_line": 39,
"start_col": 50,
"start_line": 39
} |
FStar.All.ML | [
{
"abbrev": false,
"full_module": "FStar.Exn",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Heap",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let pipe_left = ( <| ) | let pipe_left = | false | null | false | ( <| ) | {
"checked_file": "FStar.All.fst.checked",
"dependencies": [
"prims.fst.checked",
"FStar.ST.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Heap.fst.checked",
"FStar.Exn.fst.checked"
],
"interface_file": false,
"source_file": "FStar.All.fst"
} | [
"ml"
] | [
"FStar.All.op_Less_Bar"
] | [] | (*
Copyright 2008-2014 Nikhil Swamy and 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 FStar.All
open FStar.Heap
include FStar.ST
include FStar.Exn
let all_pre = all_pre_h heap
let all_post' (a : Type) (pre:Type) = all_post_h' heap a pre
let all_post (a : Type) = all_post_h heap a
let all_wp (a : Type) = all_wp_h heap a
new_effect ALL = ALL_h heap
unfold let lift_state_all (a : Type) (wp : st_wp a) (p : all_post a) = wp (fun a -> p (V a))
sub_effect STATE ~> ALL { lift_wp = lift_state_all }
unfold
let lift_exn_all (a : Type) (wp : ex_wp a) (p : all_post a) (h : heap) = wp (fun ra -> p ra h)
sub_effect EXN ~> ALL { lift_wp = lift_exn_all }
effect All (a:Type) (pre:all_pre) (post:(h:heap -> Tot (all_post' a (pre h)))) =
ALL a
(fun (p : all_post a) (h : heap) -> pre h /\ (forall ra h1. post h ra h1 ==> p ra h1))
effect ML (a:Type) = ALL a (fun (p:all_post a) (_:heap) -> forall (a:result a) (h:heap). p a h)
let ( |> ) (x : 'a) (f : ('a -> ML 'b)) : ML 'b = f x
let pipe_right = ( |> ) | false | false | FStar.All.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val pipe_left : f: (_: _ -> FStar.All.ML _) -> x: _ -> FStar.All.ML _ | [] | FStar.All.pipe_left | {
"file_name": "ulib/FStar.All.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | f: (_: _ -> FStar.All.ML _) -> x: _ -> FStar.All.ML _ | {
"end_col": 20,
"end_line": 43,
"start_col": 18,
"start_line": 43
} |
|
FStar.Pervasives.Lemma | val lemma_load_buffer_read128 (h:vale_heap) (b:buffer128) (i:int) : Lemma
(requires valid_buffer_read h b i)
(ensures buffer_read b i h == load_mem128 (buffer_addr b h + 16 * i) h)
[SMTPat (buffer_read b i h)] | [
{
"abbrev": false,
"full_module": "Vale.PPC64LE.Memory_Sems",
"short_module": null
},
{
"abbrev": true,
"full_module": "Vale.PPC64LE.Semantics_s",
"short_module": "S"
},
{
"abbrev": false,
"full_module": "Vale.Arch.Heap",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.HeapImpl",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.PPC64LE.Memory",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.PPC64LE.State",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.PPC64LE.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.PPC64LE",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.PPC64LE",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let lemma_load_buffer_read128 h b i =
lemma_load_mem128 b i h | val lemma_load_buffer_read128 (h:vale_heap) (b:buffer128) (i:int) : Lemma
(requires valid_buffer_read h b i)
(ensures buffer_read b i h == load_mem128 (buffer_addr b h + 16 * i) h)
[SMTPat (buffer_read b i h)]
let lemma_load_buffer_read128 h b i = | false | null | true | lemma_load_mem128 b i h | {
"checked_file": "Vale.PPC64LE.StateLemmas.fst.checked",
"dependencies": [
"Vale.PPC64LE.Memory_Sems.fsti.checked",
"Vale.PPC64LE.Memory.fsti.checked",
"prims.fst.checked",
"FStar.Pervasives.fsti.checked"
],
"interface_file": true,
"source_file": "Vale.PPC64LE.StateLemmas.fst"
} | [
"lemma"
] | [
"Vale.PPC64LE.Memory.vale_heap",
"Vale.PPC64LE.Memory.buffer128",
"Prims.int",
"Vale.PPC64LE.Memory.lemma_load_mem128",
"Prims.unit"
] | [] | module Vale.PPC64LE.StateLemmas
open Vale.PPC64LE.Memory_Sems
open Vale.PPC64LE.Memory
#reset-options "--initial_fuel 2 --max_fuel 2"
let lemma_to_eval_reg s r = ()
let lemma_to_eval_vec s v = ()
let lemma_to_eval_maddr s m = ()
let lemma_to_eval_cmp_opr s o = ()
let lemma_to_valid_maddr64 s m = ()
let lemma_valid_mem_addr64 h ptr =
bytes_valid64 ptr (get_vale_heap h);
lemma_heap_get_heap h;
()
let lemma_valid_mem_addr128 h ptr =
bytes_valid128 ptr (get_vale_heap h);
lemma_heap_get_heap h;
()
let lemma_load_mem_get64 h ptr =
equiv_load_mem64 ptr (get_vale_heap h);
lemma_heap_get_heap h;
()
let lemma_load_mem_get128 h ptr =
equiv_load_mem128 ptr (get_vale_heap h);
lemma_heap_get_heap h;
()
let lemma_load_buffer_read64 h b i =
lemma_load_mem64 b i h | false | false | Vale.PPC64LE.StateLemmas.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 0,
"max_fuel": 2,
"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"
} | null | val lemma_load_buffer_read128 (h:vale_heap) (b:buffer128) (i:int) : Lemma
(requires valid_buffer_read h b i)
(ensures buffer_read b i h == load_mem128 (buffer_addr b h + 16 * i) h)
[SMTPat (buffer_read b i h)] | [] | Vale.PPC64LE.StateLemmas.lemma_load_buffer_read128 | {
"file_name": "vale/code/arch/ppc64le/Vale.PPC64LE.StateLemmas.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | h: Vale.PPC64LE.Memory.vale_heap -> b: Vale.PPC64LE.Memory.buffer128 -> i: Prims.int
-> FStar.Pervasives.Lemma (requires Vale.PPC64LE.Memory.valid_buffer_read h b i)
(ensures
Vale.PPC64LE.Memory.buffer_read b i h ==
Vale.PPC64LE.Memory.load_mem128 (Vale.PPC64LE.Memory.buffer_addr b h + 16 * i) h)
[SMTPat (Vale.PPC64LE.Memory.buffer_read b i h)] | {
"end_col": 25,
"end_line": 37,
"start_col": 2,
"start_line": 37
} |
FStar.Pervasives.Lemma | val lemma_load_buffer_read64 (h:vale_heap) (b:buffer64) (i:int) : Lemma
(requires valid_buffer_read h b i)
(ensures buffer_read b i h == load_mem64 (buffer_addr b h + 8 * i) h)
[SMTPat (buffer_read b i h)] | [
{
"abbrev": false,
"full_module": "Vale.PPC64LE.Memory_Sems",
"short_module": null
},
{
"abbrev": true,
"full_module": "Vale.PPC64LE.Semantics_s",
"short_module": "S"
},
{
"abbrev": false,
"full_module": "Vale.Arch.Heap",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.HeapImpl",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.PPC64LE.Memory",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.PPC64LE.State",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.PPC64LE.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.PPC64LE",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.PPC64LE",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let lemma_load_buffer_read64 h b i =
lemma_load_mem64 b i h | val lemma_load_buffer_read64 (h:vale_heap) (b:buffer64) (i:int) : Lemma
(requires valid_buffer_read h b i)
(ensures buffer_read b i h == load_mem64 (buffer_addr b h + 8 * i) h)
[SMTPat (buffer_read b i h)]
let lemma_load_buffer_read64 h b i = | false | null | true | lemma_load_mem64 b i h | {
"checked_file": "Vale.PPC64LE.StateLemmas.fst.checked",
"dependencies": [
"Vale.PPC64LE.Memory_Sems.fsti.checked",
"Vale.PPC64LE.Memory.fsti.checked",
"prims.fst.checked",
"FStar.Pervasives.fsti.checked"
],
"interface_file": true,
"source_file": "Vale.PPC64LE.StateLemmas.fst"
} | [
"lemma"
] | [
"Vale.PPC64LE.Memory.vale_heap",
"Vale.PPC64LE.Memory.buffer64",
"Prims.int",
"Vale.PPC64LE.Memory.lemma_load_mem64",
"Prims.unit"
] | [] | module Vale.PPC64LE.StateLemmas
open Vale.PPC64LE.Memory_Sems
open Vale.PPC64LE.Memory
#reset-options "--initial_fuel 2 --max_fuel 2"
let lemma_to_eval_reg s r = ()
let lemma_to_eval_vec s v = ()
let lemma_to_eval_maddr s m = ()
let lemma_to_eval_cmp_opr s o = ()
let lemma_to_valid_maddr64 s m = ()
let lemma_valid_mem_addr64 h ptr =
bytes_valid64 ptr (get_vale_heap h);
lemma_heap_get_heap h;
()
let lemma_valid_mem_addr128 h ptr =
bytes_valid128 ptr (get_vale_heap h);
lemma_heap_get_heap h;
()
let lemma_load_mem_get64 h ptr =
equiv_load_mem64 ptr (get_vale_heap h);
lemma_heap_get_heap h;
()
let lemma_load_mem_get128 h ptr =
equiv_load_mem128 ptr (get_vale_heap h);
lemma_heap_get_heap h;
() | false | false | Vale.PPC64LE.StateLemmas.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 0,
"max_fuel": 2,
"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"
} | null | val lemma_load_buffer_read64 (h:vale_heap) (b:buffer64) (i:int) : Lemma
(requires valid_buffer_read h b i)
(ensures buffer_read b i h == load_mem64 (buffer_addr b h + 8 * i) h)
[SMTPat (buffer_read b i h)] | [] | Vale.PPC64LE.StateLemmas.lemma_load_buffer_read64 | {
"file_name": "vale/code/arch/ppc64le/Vale.PPC64LE.StateLemmas.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | h: Vale.PPC64LE.Memory.vale_heap -> b: Vale.PPC64LE.Memory.buffer64 -> i: Prims.int
-> FStar.Pervasives.Lemma (requires Vale.PPC64LE.Memory.valid_buffer_read h b i)
(ensures
Vale.PPC64LE.Memory.buffer_read b i h ==
Vale.PPC64LE.Memory.load_mem64 (Vale.PPC64LE.Memory.buffer_addr b h + 8 * i) h)
[SMTPat (Vale.PPC64LE.Memory.buffer_read b i h)] | {
"end_col": 24,
"end_line": 34,
"start_col": 2,
"start_line": 34
} |
FStar.Pervasives.Lemma | val lemma_valid_mem_addr128 (h:vale_full_heap) (ptr:int) : Lemma
(requires valid_mem128 ptr (get_vale_heap h))
(ensures S.valid_addr128 ptr (heap_get (coerce h)))
[SMTPat (valid_mem128 ptr (get_vale_heap h))] | [
{
"abbrev": false,
"full_module": "Vale.PPC64LE.Memory_Sems",
"short_module": null
},
{
"abbrev": true,
"full_module": "Vale.PPC64LE.Semantics_s",
"short_module": "S"
},
{
"abbrev": false,
"full_module": "Vale.Arch.Heap",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.HeapImpl",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.PPC64LE.Memory",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.PPC64LE.State",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.PPC64LE.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.PPC64LE",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.PPC64LE",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let lemma_valid_mem_addr128 h ptr =
bytes_valid128 ptr (get_vale_heap h);
lemma_heap_get_heap h;
() | val lemma_valid_mem_addr128 (h:vale_full_heap) (ptr:int) : Lemma
(requires valid_mem128 ptr (get_vale_heap h))
(ensures S.valid_addr128 ptr (heap_get (coerce h)))
[SMTPat (valid_mem128 ptr (get_vale_heap h))]
let lemma_valid_mem_addr128 h ptr = | false | null | true | bytes_valid128 ptr (get_vale_heap h);
lemma_heap_get_heap h;
() | {
"checked_file": "Vale.PPC64LE.StateLemmas.fst.checked",
"dependencies": [
"Vale.PPC64LE.Memory_Sems.fsti.checked",
"Vale.PPC64LE.Memory.fsti.checked",
"prims.fst.checked",
"FStar.Pervasives.fsti.checked"
],
"interface_file": true,
"source_file": "Vale.PPC64LE.StateLemmas.fst"
} | [
"lemma"
] | [
"Vale.PPC64LE.Memory.vale_full_heap",
"Prims.int",
"Prims.unit",
"Vale.PPC64LE.Memory_Sems.lemma_heap_get_heap",
"Vale.PPC64LE.Memory_Sems.bytes_valid128",
"Vale.PPC64LE.Memory.get_vale_heap"
] | [] | module Vale.PPC64LE.StateLemmas
open Vale.PPC64LE.Memory_Sems
open Vale.PPC64LE.Memory
#reset-options "--initial_fuel 2 --max_fuel 2"
let lemma_to_eval_reg s r = ()
let lemma_to_eval_vec s v = ()
let lemma_to_eval_maddr s m = ()
let lemma_to_eval_cmp_opr s o = ()
let lemma_to_valid_maddr64 s m = ()
let lemma_valid_mem_addr64 h ptr =
bytes_valid64 ptr (get_vale_heap h);
lemma_heap_get_heap h;
() | false | false | Vale.PPC64LE.StateLemmas.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 0,
"max_fuel": 2,
"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"
} | null | val lemma_valid_mem_addr128 (h:vale_full_heap) (ptr:int) : Lemma
(requires valid_mem128 ptr (get_vale_heap h))
(ensures S.valid_addr128 ptr (heap_get (coerce h)))
[SMTPat (valid_mem128 ptr (get_vale_heap h))] | [] | Vale.PPC64LE.StateLemmas.lemma_valid_mem_addr128 | {
"file_name": "vale/code/arch/ppc64le/Vale.PPC64LE.StateLemmas.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | h: Vale.PPC64LE.Memory.vale_full_heap -> ptr: Prims.int
-> FStar.Pervasives.Lemma
(requires Vale.PPC64LE.Memory.valid_mem128 ptr (Vale.PPC64LE.Memory.get_vale_heap h))
(ensures
Vale.Arch.MachineHeap_s.valid_addr128 ptr
(Vale.Arch.Heap.heap_get (Vale.PPC64LE.Memory_Sems.coerce h)))
[SMTPat (Vale.PPC64LE.Memory.valid_mem128 ptr (Vale.PPC64LE.Memory.get_vale_heap h))] | {
"end_col": 4,
"end_line": 21,
"start_col": 2,
"start_line": 19
} |
FStar.Pervasives.Lemma | val lemma_valid_mem_addr64 (h:vale_full_heap) (ptr:int) : Lemma
(requires valid_mem64 ptr (get_vale_heap h))
(ensures S.valid_addr64 ptr (heap_get (coerce h)))
[SMTPat (valid_mem64 ptr (get_vale_heap h))] | [
{
"abbrev": false,
"full_module": "Vale.PPC64LE.Memory_Sems",
"short_module": null
},
{
"abbrev": true,
"full_module": "Vale.PPC64LE.Semantics_s",
"short_module": "S"
},
{
"abbrev": false,
"full_module": "Vale.Arch.Heap",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.HeapImpl",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.PPC64LE.Memory",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.PPC64LE.State",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.PPC64LE.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.PPC64LE",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.PPC64LE",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let lemma_valid_mem_addr64 h ptr =
bytes_valid64 ptr (get_vale_heap h);
lemma_heap_get_heap h;
() | val lemma_valid_mem_addr64 (h:vale_full_heap) (ptr:int) : Lemma
(requires valid_mem64 ptr (get_vale_heap h))
(ensures S.valid_addr64 ptr (heap_get (coerce h)))
[SMTPat (valid_mem64 ptr (get_vale_heap h))]
let lemma_valid_mem_addr64 h ptr = | false | null | true | bytes_valid64 ptr (get_vale_heap h);
lemma_heap_get_heap h;
() | {
"checked_file": "Vale.PPC64LE.StateLemmas.fst.checked",
"dependencies": [
"Vale.PPC64LE.Memory_Sems.fsti.checked",
"Vale.PPC64LE.Memory.fsti.checked",
"prims.fst.checked",
"FStar.Pervasives.fsti.checked"
],
"interface_file": true,
"source_file": "Vale.PPC64LE.StateLemmas.fst"
} | [
"lemma"
] | [
"Vale.PPC64LE.Memory.vale_full_heap",
"Prims.int",
"Prims.unit",
"Vale.PPC64LE.Memory_Sems.lemma_heap_get_heap",
"Vale.PPC64LE.Memory_Sems.bytes_valid64",
"Vale.PPC64LE.Memory.get_vale_heap"
] | [] | module Vale.PPC64LE.StateLemmas
open Vale.PPC64LE.Memory_Sems
open Vale.PPC64LE.Memory
#reset-options "--initial_fuel 2 --max_fuel 2"
let lemma_to_eval_reg s r = ()
let lemma_to_eval_vec s v = ()
let lemma_to_eval_maddr s m = ()
let lemma_to_eval_cmp_opr s o = ()
let lemma_to_valid_maddr64 s m = () | false | false | Vale.PPC64LE.StateLemmas.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 0,
"max_fuel": 2,
"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"
} | null | val lemma_valid_mem_addr64 (h:vale_full_heap) (ptr:int) : Lemma
(requires valid_mem64 ptr (get_vale_heap h))
(ensures S.valid_addr64 ptr (heap_get (coerce h)))
[SMTPat (valid_mem64 ptr (get_vale_heap h))] | [] | Vale.PPC64LE.StateLemmas.lemma_valid_mem_addr64 | {
"file_name": "vale/code/arch/ppc64le/Vale.PPC64LE.StateLemmas.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | h: Vale.PPC64LE.Memory.vale_full_heap -> ptr: Prims.int
-> FStar.Pervasives.Lemma
(requires Vale.PPC64LE.Memory.valid_mem64 ptr (Vale.PPC64LE.Memory.get_vale_heap h))
(ensures
Vale.Arch.MachineHeap_s.valid_addr64 ptr
(Vale.Arch.Heap.heap_get (Vale.PPC64LE.Memory_Sems.coerce h)))
[SMTPat (Vale.PPC64LE.Memory.valid_mem64 ptr (Vale.PPC64LE.Memory.get_vale_heap h))] | {
"end_col": 4,
"end_line": 16,
"start_col": 2,
"start_line": 14
} |
FStar.Pervasives.Lemma | val lemma_load_mem_get64 (h:vale_full_heap) (ptr:int) : Lemma
(requires valid_mem64 ptr (get_vale_heap h))
(ensures load_mem64 ptr (get_vale_heap h) == S.get_heap_val64 ptr (heap_get (coerce h)))
[SMTPat (load_mem64 ptr (get_vale_heap h))] | [
{
"abbrev": false,
"full_module": "Vale.PPC64LE.Memory_Sems",
"short_module": null
},
{
"abbrev": true,
"full_module": "Vale.PPC64LE.Semantics_s",
"short_module": "S"
},
{
"abbrev": false,
"full_module": "Vale.Arch.Heap",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.HeapImpl",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.PPC64LE.Memory",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.PPC64LE.State",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.PPC64LE.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.PPC64LE",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.PPC64LE",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let lemma_load_mem_get64 h ptr =
equiv_load_mem64 ptr (get_vale_heap h);
lemma_heap_get_heap h;
() | val lemma_load_mem_get64 (h:vale_full_heap) (ptr:int) : Lemma
(requires valid_mem64 ptr (get_vale_heap h))
(ensures load_mem64 ptr (get_vale_heap h) == S.get_heap_val64 ptr (heap_get (coerce h)))
[SMTPat (load_mem64 ptr (get_vale_heap h))]
let lemma_load_mem_get64 h ptr = | false | null | true | equiv_load_mem64 ptr (get_vale_heap h);
lemma_heap_get_heap h;
() | {
"checked_file": "Vale.PPC64LE.StateLemmas.fst.checked",
"dependencies": [
"Vale.PPC64LE.Memory_Sems.fsti.checked",
"Vale.PPC64LE.Memory.fsti.checked",
"prims.fst.checked",
"FStar.Pervasives.fsti.checked"
],
"interface_file": true,
"source_file": "Vale.PPC64LE.StateLemmas.fst"
} | [
"lemma"
] | [
"Vale.PPC64LE.Memory.vale_full_heap",
"Prims.int",
"Prims.unit",
"Vale.PPC64LE.Memory_Sems.lemma_heap_get_heap",
"Vale.PPC64LE.Memory_Sems.equiv_load_mem64",
"Vale.PPC64LE.Memory.get_vale_heap"
] | [] | module Vale.PPC64LE.StateLemmas
open Vale.PPC64LE.Memory_Sems
open Vale.PPC64LE.Memory
#reset-options "--initial_fuel 2 --max_fuel 2"
let lemma_to_eval_reg s r = ()
let lemma_to_eval_vec s v = ()
let lemma_to_eval_maddr s m = ()
let lemma_to_eval_cmp_opr s o = ()
let lemma_to_valid_maddr64 s m = ()
let lemma_valid_mem_addr64 h ptr =
bytes_valid64 ptr (get_vale_heap h);
lemma_heap_get_heap h;
()
let lemma_valid_mem_addr128 h ptr =
bytes_valid128 ptr (get_vale_heap h);
lemma_heap_get_heap h;
() | false | false | Vale.PPC64LE.StateLemmas.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 0,
"max_fuel": 2,
"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"
} | null | val lemma_load_mem_get64 (h:vale_full_heap) (ptr:int) : Lemma
(requires valid_mem64 ptr (get_vale_heap h))
(ensures load_mem64 ptr (get_vale_heap h) == S.get_heap_val64 ptr (heap_get (coerce h)))
[SMTPat (load_mem64 ptr (get_vale_heap h))] | [] | Vale.PPC64LE.StateLemmas.lemma_load_mem_get64 | {
"file_name": "vale/code/arch/ppc64le/Vale.PPC64LE.StateLemmas.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | h: Vale.PPC64LE.Memory.vale_full_heap -> ptr: Prims.int
-> FStar.Pervasives.Lemma
(requires Vale.PPC64LE.Memory.valid_mem64 ptr (Vale.PPC64LE.Memory.get_vale_heap h))
(ensures
Vale.PPC64LE.Memory.load_mem64 ptr (Vale.PPC64LE.Memory.get_vale_heap h) ==
Vale.Arch.MachineHeap_s.get_heap_val64 ptr
(Vale.Arch.Heap.heap_get (Vale.PPC64LE.Memory_Sems.coerce h)))
[SMTPat (Vale.PPC64LE.Memory.load_mem64 ptr (Vale.PPC64LE.Memory.get_vale_heap h))] | {
"end_col": 4,
"end_line": 26,
"start_col": 2,
"start_line": 24
} |
FStar.Pervasives.Lemma | val lemma_load_mem_get128 (h:vale_full_heap) (ptr:int) : Lemma
(requires valid_mem128 ptr (get_vale_heap h))
(ensures load_mem128 ptr (get_vale_heap h) == S.get_heap_val128 ptr (heap_get (coerce h)))
[SMTPat (load_mem128 ptr (get_vale_heap h))] | [
{
"abbrev": false,
"full_module": "Vale.PPC64LE.Memory_Sems",
"short_module": null
},
{
"abbrev": true,
"full_module": "Vale.PPC64LE.Semantics_s",
"short_module": "S"
},
{
"abbrev": false,
"full_module": "Vale.Arch.Heap",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.HeapImpl",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.PPC64LE.Memory",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.PPC64LE.State",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.PPC64LE.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.PPC64LE",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.PPC64LE",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let lemma_load_mem_get128 h ptr =
equiv_load_mem128 ptr (get_vale_heap h);
lemma_heap_get_heap h;
() | val lemma_load_mem_get128 (h:vale_full_heap) (ptr:int) : Lemma
(requires valid_mem128 ptr (get_vale_heap h))
(ensures load_mem128 ptr (get_vale_heap h) == S.get_heap_val128 ptr (heap_get (coerce h)))
[SMTPat (load_mem128 ptr (get_vale_heap h))]
let lemma_load_mem_get128 h ptr = | false | null | true | equiv_load_mem128 ptr (get_vale_heap h);
lemma_heap_get_heap h;
() | {
"checked_file": "Vale.PPC64LE.StateLemmas.fst.checked",
"dependencies": [
"Vale.PPC64LE.Memory_Sems.fsti.checked",
"Vale.PPC64LE.Memory.fsti.checked",
"prims.fst.checked",
"FStar.Pervasives.fsti.checked"
],
"interface_file": true,
"source_file": "Vale.PPC64LE.StateLemmas.fst"
} | [
"lemma"
] | [
"Vale.PPC64LE.Memory.vale_full_heap",
"Prims.int",
"Prims.unit",
"Vale.PPC64LE.Memory_Sems.lemma_heap_get_heap",
"Vale.PPC64LE.Memory_Sems.equiv_load_mem128",
"Vale.PPC64LE.Memory.get_vale_heap"
] | [] | module Vale.PPC64LE.StateLemmas
open Vale.PPC64LE.Memory_Sems
open Vale.PPC64LE.Memory
#reset-options "--initial_fuel 2 --max_fuel 2"
let lemma_to_eval_reg s r = ()
let lemma_to_eval_vec s v = ()
let lemma_to_eval_maddr s m = ()
let lemma_to_eval_cmp_opr s o = ()
let lemma_to_valid_maddr64 s m = ()
let lemma_valid_mem_addr64 h ptr =
bytes_valid64 ptr (get_vale_heap h);
lemma_heap_get_heap h;
()
let lemma_valid_mem_addr128 h ptr =
bytes_valid128 ptr (get_vale_heap h);
lemma_heap_get_heap h;
()
let lemma_load_mem_get64 h ptr =
equiv_load_mem64 ptr (get_vale_heap h);
lemma_heap_get_heap h;
() | false | false | Vale.PPC64LE.StateLemmas.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 0,
"max_fuel": 2,
"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"
} | null | val lemma_load_mem_get128 (h:vale_full_heap) (ptr:int) : Lemma
(requires valid_mem128 ptr (get_vale_heap h))
(ensures load_mem128 ptr (get_vale_heap h) == S.get_heap_val128 ptr (heap_get (coerce h)))
[SMTPat (load_mem128 ptr (get_vale_heap h))] | [] | Vale.PPC64LE.StateLemmas.lemma_load_mem_get128 | {
"file_name": "vale/code/arch/ppc64le/Vale.PPC64LE.StateLemmas.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | h: Vale.PPC64LE.Memory.vale_full_heap -> ptr: Prims.int
-> FStar.Pervasives.Lemma
(requires Vale.PPC64LE.Memory.valid_mem128 ptr (Vale.PPC64LE.Memory.get_vale_heap h))
(ensures
Vale.PPC64LE.Memory.load_mem128 ptr (Vale.PPC64LE.Memory.get_vale_heap h) ==
Vale.Arch.MachineHeap_s.get_heap_val128 ptr
(Vale.Arch.Heap.heap_get (Vale.PPC64LE.Memory_Sems.coerce h)))
[SMTPat (Vale.PPC64LE.Memory.load_mem128 ptr (Vale.PPC64LE.Memory.get_vale_heap h))] | {
"end_col": 4,
"end_line": 31,
"start_col": 2,
"start_line": 29
} |
Prims.Tot | [
{
"abbrev": true,
"full_module": "FStar.FunctionalExtensionality",
"short_module": "F"
},
{
"abbrev": true,
"full_module": "Vale.X64.Stack_Sems",
"short_module": "VSS"
},
{
"abbrev": true,
"full_module": "Vale.X64.Stack_i",
"short_module": "VST"
},
{
"abbrev": true,
"full_module": "Vale.X64.Memory",
"short_module": "ME"
},
{
"abbrev": true,
"full_module": "Vale.X64.Memory_Sems",
"short_module": "MS"
},
{
"abbrev": true,
"full_module": "Vale.X64.Machine_Semantics_s",
"short_module": "BS"
},
{
"abbrev": false,
"full_module": "Vale.X64.State",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.HeapImpl",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Prop_s",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.FunctionalExtensionality",
"short_module": "F"
},
{
"abbrev": true,
"full_module": "Vale.X64.Stack_Sems",
"short_module": "VSS"
},
{
"abbrev": false,
"full_module": "Vale.Arch.MachineHeap_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Memory",
"short_module": null
},
{
"abbrev": true,
"full_module": "Vale.X64.Machine_Semantics_s",
"short_module": "Ms"
},
{
"abbrev": false,
"full_module": "FStar.FunctionalExtensionality",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.State",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Heap",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let machine_state_eq (s1 s2:machine_state) =
s1 == s2 | let machine_state_eq (s1 s2: machine_state) = | false | null | false | s1 == s2 | {
"checked_file": "Vale.X64.StateLemmas.fsti.checked",
"dependencies": [
"Vale.X64.State.fsti.checked",
"Vale.X64.Stack_Sems.fsti.checked",
"Vale.X64.Regs.fsti.checked",
"Vale.X64.Memory.fsti.checked",
"Vale.X64.Machine_Semantics_s.fst.checked",
"Vale.X64.Machine_s.fst.checked",
"Vale.X64.Flags.fsti.checked",
"Vale.Def.Prop_s.fst.checked",
"Vale.Arch.MachineHeap_s.fst.checked",
"Vale.Arch.Heap.fsti.checked",
"prims.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.FunctionalExtensionality.fsti.checked"
],
"interface_file": false,
"source_file": "Vale.X64.StateLemmas.fsti"
} | [
"total"
] | [
"Vale.X64.StateLemmas.machine_state",
"Prims.eq2",
"Prims.logical"
] | [] | module Vale.X64.StateLemmas
open Vale.X64.Machine_s
open Vale.Arch.Heap
open Vale.X64.State
open FStar.FunctionalExtensionality
module Ms = Vale.X64.Machine_Semantics_s
//open Vale.X64.Machine_Semantics_s
//module ME = Vale.X64.Memory
open Vale.X64.Memory
open Vale.Arch.MachineHeap_s
//module MS = Vale.X64.Memory_Sems
module VSS = Vale.X64.Stack_Sems
module F = FStar.FunctionalExtensionality
open Vale.Def.Prop_s
open FStar.Mul
unfold let machine_state = Ms.machine_state
unfold let code = Ms.code
unfold let machine_eval_code = Ms.machine_eval_code
val same_heap_types : squash (vale_full_heap == heap_impl)
unfold let coerce (#b #a:Type) (x:a{a == b}) : b = x | false | true | Vale.X64.StateLemmas.fsti | {
"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"
} | null | val machine_state_eq : s1: Vale.X64.StateLemmas.machine_state -> s2: Vale.X64.StateLemmas.machine_state -> Prims.logical | [] | Vale.X64.StateLemmas.machine_state_eq | {
"file_name": "vale/code/arch/x64/Vale.X64.StateLemmas.fsti",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | s1: Vale.X64.StateLemmas.machine_state -> s2: Vale.X64.StateLemmas.machine_state -> Prims.logical | {
"end_col": 10,
"end_line": 24,
"start_col": 2,
"start_line": 24
} |
|
Prims.Tot | [
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Prop_s",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.FunctionalExtensionality",
"short_module": "F"
},
{
"abbrev": true,
"full_module": "Vale.X64.Stack_Sems",
"short_module": "VSS"
},
{
"abbrev": false,
"full_module": "Vale.Arch.MachineHeap_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Memory",
"short_module": null
},
{
"abbrev": true,
"full_module": "Vale.X64.Machine_Semantics_s",
"short_module": "Ms"
},
{
"abbrev": false,
"full_module": "FStar.FunctionalExtensionality",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.State",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Heap",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let machine_state = Ms.machine_state | let machine_state = | false | null | false | Ms.machine_state | {
"checked_file": "Vale.X64.StateLemmas.fsti.checked",
"dependencies": [
"Vale.X64.State.fsti.checked",
"Vale.X64.Stack_Sems.fsti.checked",
"Vale.X64.Regs.fsti.checked",
"Vale.X64.Memory.fsti.checked",
"Vale.X64.Machine_Semantics_s.fst.checked",
"Vale.X64.Machine_s.fst.checked",
"Vale.X64.Flags.fsti.checked",
"Vale.Def.Prop_s.fst.checked",
"Vale.Arch.MachineHeap_s.fst.checked",
"Vale.Arch.Heap.fsti.checked",
"prims.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.FunctionalExtensionality.fsti.checked"
],
"interface_file": false,
"source_file": "Vale.X64.StateLemmas.fsti"
} | [
"total"
] | [
"Vale.X64.Machine_Semantics_s.machine_state"
] | [] | module Vale.X64.StateLemmas
open Vale.X64.Machine_s
open Vale.Arch.Heap
open Vale.X64.State
open FStar.FunctionalExtensionality
module Ms = Vale.X64.Machine_Semantics_s
//open Vale.X64.Machine_Semantics_s
//module ME = Vale.X64.Memory
open Vale.X64.Memory
open Vale.Arch.MachineHeap_s
//module MS = Vale.X64.Memory_Sems
module VSS = Vale.X64.Stack_Sems
module F = FStar.FunctionalExtensionality
open Vale.Def.Prop_s
open FStar.Mul | false | true | Vale.X64.StateLemmas.fsti | {
"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"
} | null | val machine_state : Type | [] | Vale.X64.StateLemmas.machine_state | {
"file_name": "vale/code/arch/x64/Vale.X64.StateLemmas.fsti",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | Type | {
"end_col": 43,
"end_line": 17,
"start_col": 27,
"start_line": 17
} |
|
Prims.Tot | [
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Prop_s",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.FunctionalExtensionality",
"short_module": "F"
},
{
"abbrev": true,
"full_module": "Vale.X64.Stack_Sems",
"short_module": "VSS"
},
{
"abbrev": false,
"full_module": "Vale.Arch.MachineHeap_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Memory",
"short_module": null
},
{
"abbrev": true,
"full_module": "Vale.X64.Machine_Semantics_s",
"short_module": "Ms"
},
{
"abbrev": false,
"full_module": "FStar.FunctionalExtensionality",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.State",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Heap",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let machine_eval_code = Ms.machine_eval_code | let machine_eval_code = | false | null | false | Ms.machine_eval_code | {
"checked_file": "Vale.X64.StateLemmas.fsti.checked",
"dependencies": [
"Vale.X64.State.fsti.checked",
"Vale.X64.Stack_Sems.fsti.checked",
"Vale.X64.Regs.fsti.checked",
"Vale.X64.Memory.fsti.checked",
"Vale.X64.Machine_Semantics_s.fst.checked",
"Vale.X64.Machine_s.fst.checked",
"Vale.X64.Flags.fsti.checked",
"Vale.Def.Prop_s.fst.checked",
"Vale.Arch.MachineHeap_s.fst.checked",
"Vale.Arch.Heap.fsti.checked",
"prims.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.FunctionalExtensionality.fsti.checked"
],
"interface_file": false,
"source_file": "Vale.X64.StateLemmas.fsti"
} | [
"total",
""
] | [
"Vale.X64.Machine_Semantics_s.machine_eval_code"
] | [] | module Vale.X64.StateLemmas
open Vale.X64.Machine_s
open Vale.Arch.Heap
open Vale.X64.State
open FStar.FunctionalExtensionality
module Ms = Vale.X64.Machine_Semantics_s
//open Vale.X64.Machine_Semantics_s
//module ME = Vale.X64.Memory
open Vale.X64.Memory
open Vale.Arch.MachineHeap_s
//module MS = Vale.X64.Memory_Sems
module VSS = Vale.X64.Stack_Sems
module F = FStar.FunctionalExtensionality
open Vale.Def.Prop_s
open FStar.Mul
unfold let machine_state = Ms.machine_state | false | true | Vale.X64.StateLemmas.fsti | {
"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"
} | null | val machine_eval_code : c: Vale.X64.Machine_Semantics_s.code ->
fuel: Prims.nat ->
s: Vale.X64.Machine_Semantics_s.machine_state
-> Prims.Tot (FStar.Pervasives.Native.option Vale.X64.Machine_Semantics_s.machine_state) | [] | Vale.X64.StateLemmas.machine_eval_code | {
"file_name": "vale/code/arch/x64/Vale.X64.StateLemmas.fsti",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} |
c: Vale.X64.Machine_Semantics_s.code ->
fuel: Prims.nat ->
s: Vale.X64.Machine_Semantics_s.machine_state
-> Prims.Tot (FStar.Pervasives.Native.option Vale.X64.Machine_Semantics_s.machine_state) | {
"end_col": 51,
"end_line": 19,
"start_col": 31,
"start_line": 19
} |
|
Prims.Tot | [
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Prop_s",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.FunctionalExtensionality",
"short_module": "F"
},
{
"abbrev": true,
"full_module": "Vale.X64.Stack_Sems",
"short_module": "VSS"
},
{
"abbrev": false,
"full_module": "Vale.Arch.MachineHeap_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Memory",
"short_module": null
},
{
"abbrev": true,
"full_module": "Vale.X64.Machine_Semantics_s",
"short_module": "Ms"
},
{
"abbrev": false,
"full_module": "FStar.FunctionalExtensionality",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.State",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Heap",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let code = Ms.code | let code = | false | null | false | Ms.code | {
"checked_file": "Vale.X64.StateLemmas.fsti.checked",
"dependencies": [
"Vale.X64.State.fsti.checked",
"Vale.X64.Stack_Sems.fsti.checked",
"Vale.X64.Regs.fsti.checked",
"Vale.X64.Memory.fsti.checked",
"Vale.X64.Machine_Semantics_s.fst.checked",
"Vale.X64.Machine_s.fst.checked",
"Vale.X64.Flags.fsti.checked",
"Vale.Def.Prop_s.fst.checked",
"Vale.Arch.MachineHeap_s.fst.checked",
"Vale.Arch.Heap.fsti.checked",
"prims.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.FunctionalExtensionality.fsti.checked"
],
"interface_file": false,
"source_file": "Vale.X64.StateLemmas.fsti"
} | [
"total"
] | [
"Vale.X64.Machine_Semantics_s.code"
] | [] | module Vale.X64.StateLemmas
open Vale.X64.Machine_s
open Vale.Arch.Heap
open Vale.X64.State
open FStar.FunctionalExtensionality
module Ms = Vale.X64.Machine_Semantics_s
//open Vale.X64.Machine_Semantics_s
//module ME = Vale.X64.Memory
open Vale.X64.Memory
open Vale.Arch.MachineHeap_s
//module MS = Vale.X64.Memory_Sems
module VSS = Vale.X64.Stack_Sems
module F = FStar.FunctionalExtensionality
open Vale.Def.Prop_s
open FStar.Mul | false | true | Vale.X64.StateLemmas.fsti | {
"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"
} | null | val code : Type0 | [] | Vale.X64.StateLemmas.code | {
"file_name": "vale/code/arch/x64/Vale.X64.StateLemmas.fsti",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | Type0 | {
"end_col": 25,
"end_line": 18,
"start_col": 18,
"start_line": 18
} |
|
Prims.Tot | [
{
"abbrev": true,
"full_module": "FStar.FunctionalExtensionality",
"short_module": "F"
},
{
"abbrev": true,
"full_module": "Vale.X64.Stack_Sems",
"short_module": "VSS"
},
{
"abbrev": true,
"full_module": "Vale.X64.Stack_i",
"short_module": "VST"
},
{
"abbrev": true,
"full_module": "Vale.X64.Memory",
"short_module": "ME"
},
{
"abbrev": true,
"full_module": "Vale.X64.Memory_Sems",
"short_module": "MS"
},
{
"abbrev": true,
"full_module": "Vale.X64.Machine_Semantics_s",
"short_module": "BS"
},
{
"abbrev": false,
"full_module": "Vale.X64.State",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.HeapImpl",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Prop_s",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.FunctionalExtensionality",
"short_module": "F"
},
{
"abbrev": true,
"full_module": "Vale.X64.Stack_Sems",
"short_module": "VSS"
},
{
"abbrev": false,
"full_module": "Vale.Arch.MachineHeap_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Memory",
"short_module": null
},
{
"abbrev": true,
"full_module": "Vale.X64.Machine_Semantics_s",
"short_module": "Ms"
},
{
"abbrev": false,
"full_module": "FStar.FunctionalExtensionality",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.State",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Heap",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let machine_state_equal (s1 s2:machine_state) =
let open Vale.X64.Machine_Semantics_s in
s1.ms_ok == s2.ms_ok /\
F.feq s1.ms_regs s2.ms_regs /\
F.feq s1.ms_flags s2.ms_flags /\
s1.ms_heap == s2.ms_heap /\
s1.ms_stack == s2.ms_stack /\
s1.ms_stackTaint == s2.ms_stackTaint /\
s1.ms_trace == s2.ms_trace /\
True | let machine_state_equal (s1 s2: machine_state) = | false | null | false | let open Vale.X64.Machine_Semantics_s in
s1.ms_ok == s2.ms_ok /\ F.feq s1.ms_regs s2.ms_regs /\ F.feq s1.ms_flags s2.ms_flags /\
s1.ms_heap == s2.ms_heap /\ s1.ms_stack == s2.ms_stack /\ s1.ms_stackTaint == s2.ms_stackTaint /\
s1.ms_trace == s2.ms_trace /\ True | {
"checked_file": "Vale.X64.StateLemmas.fsti.checked",
"dependencies": [
"Vale.X64.State.fsti.checked",
"Vale.X64.Stack_Sems.fsti.checked",
"Vale.X64.Regs.fsti.checked",
"Vale.X64.Memory.fsti.checked",
"Vale.X64.Machine_Semantics_s.fst.checked",
"Vale.X64.Machine_s.fst.checked",
"Vale.X64.Flags.fsti.checked",
"Vale.Def.Prop_s.fst.checked",
"Vale.Arch.MachineHeap_s.fst.checked",
"Vale.Arch.Heap.fsti.checked",
"prims.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.FunctionalExtensionality.fsti.checked"
],
"interface_file": false,
"source_file": "Vale.X64.StateLemmas.fsti"
} | [
"total"
] | [
"Vale.X64.StateLemmas.machine_state",
"Prims.l_and",
"Prims.eq2",
"Prims.bool",
"Vale.X64.Machine_Semantics_s.__proj__Mkmachine_state__item__ms_ok",
"FStar.FunctionalExtensionality.feq",
"Vale.X64.Machine_s.reg",
"Vale.X64.Machine_s.t_reg",
"Vale.X64.Machine_Semantics_s.__proj__Mkmachine_state__item__ms_regs",
"Vale.X64.Machine_s.flag",
"Vale.X64.Machine_Semantics_s.flag_val_t",
"Vale.X64.Machine_Semantics_s.__proj__Mkmachine_state__item__ms_flags",
"Vale.Arch.Heap.heap_impl",
"Vale.X64.Machine_Semantics_s.__proj__Mkmachine_state__item__ms_heap",
"Vale.X64.Machine_Semantics_s.machine_stack",
"Vale.X64.Machine_Semantics_s.__proj__Mkmachine_state__item__ms_stack",
"Vale.Arch.HeapTypes_s.memTaint_t",
"Vale.X64.Machine_Semantics_s.__proj__Mkmachine_state__item__ms_stackTaint",
"Prims.list",
"Vale.X64.Machine_s.observation",
"Vale.X64.Machine_Semantics_s.__proj__Mkmachine_state__item__ms_trace",
"Prims.l_True",
"Prims.logical"
] | [] | module Vale.X64.StateLemmas
open Vale.X64.Machine_s
open Vale.Arch.Heap
open Vale.X64.State
open FStar.FunctionalExtensionality
module Ms = Vale.X64.Machine_Semantics_s
//open Vale.X64.Machine_Semantics_s
//module ME = Vale.X64.Memory
open Vale.X64.Memory
open Vale.Arch.MachineHeap_s
//module MS = Vale.X64.Memory_Sems
module VSS = Vale.X64.Stack_Sems
module F = FStar.FunctionalExtensionality
open Vale.Def.Prop_s
open FStar.Mul
unfold let machine_state = Ms.machine_state
unfold let code = Ms.code
unfold let machine_eval_code = Ms.machine_eval_code
val same_heap_types : squash (vale_full_heap == heap_impl)
unfold let coerce (#b #a:Type) (x:a{a == b}) : b = x
let machine_state_eq (s1 s2:machine_state) =
s1 == s2 | false | true | Vale.X64.StateLemmas.fsti | {
"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"
} | null | val machine_state_equal : s1: Vale.X64.StateLemmas.machine_state -> s2: Vale.X64.StateLemmas.machine_state -> Prims.logical | [] | Vale.X64.StateLemmas.machine_state_equal | {
"file_name": "vale/code/arch/x64/Vale.X64.StateLemmas.fsti",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | s1: Vale.X64.StateLemmas.machine_state -> s2: Vale.X64.StateLemmas.machine_state -> Prims.logical | {
"end_col": 6,
"end_line": 35,
"start_col": 2,
"start_line": 27
} |
|
Prims.GTot | val state_to_S (s: vale_state) : GTot machine_state | [
{
"abbrev": true,
"full_module": "FStar.FunctionalExtensionality",
"short_module": "F"
},
{
"abbrev": true,
"full_module": "Vale.X64.Stack_Sems",
"short_module": "VSS"
},
{
"abbrev": true,
"full_module": "Vale.X64.Stack_i",
"short_module": "VST"
},
{
"abbrev": true,
"full_module": "Vale.X64.Memory",
"short_module": "ME"
},
{
"abbrev": true,
"full_module": "Vale.X64.Memory_Sems",
"short_module": "MS"
},
{
"abbrev": true,
"full_module": "Vale.X64.Machine_Semantics_s",
"short_module": "BS"
},
{
"abbrev": false,
"full_module": "Vale.X64.State",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.HeapImpl",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Prop_s",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.FunctionalExtensionality",
"short_module": "F"
},
{
"abbrev": true,
"full_module": "Vale.X64.Stack_Sems",
"short_module": "VSS"
},
{
"abbrev": false,
"full_module": "Vale.Arch.MachineHeap_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Memory",
"short_module": null
},
{
"abbrev": true,
"full_module": "Vale.X64.Machine_Semantics_s",
"short_module": "Ms"
},
{
"abbrev": false,
"full_module": "FStar.FunctionalExtensionality",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.State",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Heap",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let state_to_S (s:vale_state) : GTot machine_state =
let open Ms in
{
ms_ok = s.vs_ok;
ms_regs = Regs.to_fun s.vs_regs;
ms_flags = Flags.to_fun s.vs_flags;
ms_heap = coerce s.vs_heap;
ms_stack = VSS.stack_to_s s.vs_stack;
ms_stackTaint = s.vs_stackTaint;
ms_trace = [];
} | val state_to_S (s: vale_state) : GTot machine_state
let state_to_S (s: vale_state) : GTot machine_state = | false | null | false | let open Ms in
{
ms_ok = s.vs_ok;
ms_regs = Regs.to_fun s.vs_regs;
ms_flags = Flags.to_fun s.vs_flags;
ms_heap = coerce s.vs_heap;
ms_stack = VSS.stack_to_s s.vs_stack;
ms_stackTaint = s.vs_stackTaint;
ms_trace = []
} | {
"checked_file": "Vale.X64.StateLemmas.fsti.checked",
"dependencies": [
"Vale.X64.State.fsti.checked",
"Vale.X64.Stack_Sems.fsti.checked",
"Vale.X64.Regs.fsti.checked",
"Vale.X64.Memory.fsti.checked",
"Vale.X64.Machine_Semantics_s.fst.checked",
"Vale.X64.Machine_s.fst.checked",
"Vale.X64.Flags.fsti.checked",
"Vale.Def.Prop_s.fst.checked",
"Vale.Arch.MachineHeap_s.fst.checked",
"Vale.Arch.Heap.fsti.checked",
"prims.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.FunctionalExtensionality.fsti.checked"
],
"interface_file": false,
"source_file": "Vale.X64.StateLemmas.fsti"
} | [
"sometrivial"
] | [
"Vale.X64.State.vale_state",
"Vale.X64.Machine_Semantics_s.Mkmachine_state",
"Vale.X64.State.__proj__Mkvale_state__item__vs_ok",
"Vale.X64.Regs.to_fun",
"Vale.X64.State.__proj__Mkvale_state__item__vs_regs",
"Vale.X64.Flags.to_fun",
"Vale.X64.State.__proj__Mkvale_state__item__vs_flags",
"Vale.X64.StateLemmas.coerce",
"Vale.Arch.Heap.heap_impl",
"Vale.X64.Memory.vale_full_heap",
"Vale.X64.State.__proj__Mkvale_state__item__vs_heap",
"Vale.X64.Stack_Sems.stack_to_s",
"Vale.X64.State.__proj__Mkvale_state__item__vs_stack",
"Vale.X64.State.__proj__Mkvale_state__item__vs_stackTaint",
"Prims.Nil",
"Vale.X64.Machine_s.observation",
"Vale.X64.StateLemmas.machine_state"
] | [] | module Vale.X64.StateLemmas
open Vale.X64.Machine_s
open Vale.Arch.Heap
open Vale.X64.State
open FStar.FunctionalExtensionality
module Ms = Vale.X64.Machine_Semantics_s
//open Vale.X64.Machine_Semantics_s
//module ME = Vale.X64.Memory
open Vale.X64.Memory
open Vale.Arch.MachineHeap_s
//module MS = Vale.X64.Memory_Sems
module VSS = Vale.X64.Stack_Sems
module F = FStar.FunctionalExtensionality
open Vale.Def.Prop_s
open FStar.Mul
unfold let machine_state = Ms.machine_state
unfold let code = Ms.code
unfold let machine_eval_code = Ms.machine_eval_code
val same_heap_types : squash (vale_full_heap == heap_impl)
unfold let coerce (#b #a:Type) (x:a{a == b}) : b = x
let machine_state_eq (s1 s2:machine_state) =
s1 == s2
let machine_state_equal (s1 s2:machine_state) =
let open Vale.X64.Machine_Semantics_s in
s1.ms_ok == s2.ms_ok /\
F.feq s1.ms_regs s2.ms_regs /\
F.feq s1.ms_flags s2.ms_flags /\
s1.ms_heap == s2.ms_heap /\
s1.ms_stack == s2.ms_stack /\
s1.ms_stackTaint == s2.ms_stackTaint /\
s1.ms_trace == s2.ms_trace /\
True
val use_machine_state_equal (_:unit) : Lemma
(requires True)
(ensures forall (s1 s2:machine_state).{:pattern machine_state_eq s1 s2}
machine_state_equal s1 s2 ==> machine_state_eq s1 s2) | false | false | Vale.X64.StateLemmas.fsti | {
"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"
} | null | val state_to_S (s: vale_state) : GTot machine_state | [] | Vale.X64.StateLemmas.state_to_S | {
"file_name": "vale/code/arch/x64/Vale.X64.StateLemmas.fsti",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | s: Vale.X64.State.vale_state -> Prims.GTot Vale.X64.StateLemmas.machine_state | {
"end_col": 3,
"end_line": 52,
"start_col": 2,
"start_line": 43
} |
Prims.GTot | val state_of_S (s: machine_state) : GTot vale_state | [
{
"abbrev": true,
"full_module": "FStar.FunctionalExtensionality",
"short_module": "F"
},
{
"abbrev": true,
"full_module": "Vale.X64.Stack_Sems",
"short_module": "VSS"
},
{
"abbrev": true,
"full_module": "Vale.X64.Stack_i",
"short_module": "VST"
},
{
"abbrev": true,
"full_module": "Vale.X64.Memory",
"short_module": "ME"
},
{
"abbrev": true,
"full_module": "Vale.X64.Memory_Sems",
"short_module": "MS"
},
{
"abbrev": true,
"full_module": "Vale.X64.Machine_Semantics_s",
"short_module": "BS"
},
{
"abbrev": false,
"full_module": "Vale.X64.State",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.HeapImpl",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Prop_s",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.FunctionalExtensionality",
"short_module": "F"
},
{
"abbrev": true,
"full_module": "Vale.X64.Stack_Sems",
"short_module": "VSS"
},
{
"abbrev": false,
"full_module": "Vale.Arch.MachineHeap_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Memory",
"short_module": null
},
{
"abbrev": true,
"full_module": "Vale.X64.Machine_Semantics_s",
"short_module": "Ms"
},
{
"abbrev": false,
"full_module": "FStar.FunctionalExtensionality",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.State",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Heap",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let state_of_S (s:machine_state) : GTot vale_state =
let open Ms in
{
vs_ok = s.ms_ok;
vs_regs = Regs.of_fun s.ms_regs;
vs_flags = Flags.of_fun s.ms_flags;
vs_heap = coerce s.ms_heap;
vs_stack = VSS.stack_from_s s.ms_stack;
vs_stackTaint = s.ms_stackTaint;
} | val state_of_S (s: machine_state) : GTot vale_state
let state_of_S (s: machine_state) : GTot vale_state = | false | null | false | let open Ms in
{
vs_ok = s.ms_ok;
vs_regs = Regs.of_fun s.ms_regs;
vs_flags = Flags.of_fun s.ms_flags;
vs_heap = coerce s.ms_heap;
vs_stack = VSS.stack_from_s s.ms_stack;
vs_stackTaint = s.ms_stackTaint
} | {
"checked_file": "Vale.X64.StateLemmas.fsti.checked",
"dependencies": [
"Vale.X64.State.fsti.checked",
"Vale.X64.Stack_Sems.fsti.checked",
"Vale.X64.Regs.fsti.checked",
"Vale.X64.Memory.fsti.checked",
"Vale.X64.Machine_Semantics_s.fst.checked",
"Vale.X64.Machine_s.fst.checked",
"Vale.X64.Flags.fsti.checked",
"Vale.Def.Prop_s.fst.checked",
"Vale.Arch.MachineHeap_s.fst.checked",
"Vale.Arch.Heap.fsti.checked",
"prims.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.FunctionalExtensionality.fsti.checked"
],
"interface_file": false,
"source_file": "Vale.X64.StateLemmas.fsti"
} | [
"sometrivial"
] | [
"Vale.X64.StateLemmas.machine_state",
"Vale.X64.State.Mkvale_state",
"Vale.X64.Machine_Semantics_s.__proj__Mkmachine_state__item__ms_ok",
"Vale.X64.Regs.of_fun",
"Vale.X64.Machine_Semantics_s.__proj__Mkmachine_state__item__ms_regs",
"Vale.X64.Flags.of_fun",
"Vale.X64.Machine_Semantics_s.__proj__Mkmachine_state__item__ms_flags",
"Vale.X64.StateLemmas.coerce",
"Vale.X64.Memory.vale_full_heap",
"Vale.Arch.Heap.heap_impl",
"Vale.X64.Machine_Semantics_s.__proj__Mkmachine_state__item__ms_heap",
"Vale.X64.Stack_Sems.stack_from_s",
"Vale.X64.Machine_Semantics_s.__proj__Mkmachine_state__item__ms_stack",
"Vale.X64.Machine_Semantics_s.__proj__Mkmachine_state__item__ms_stackTaint",
"Vale.X64.State.vale_state"
] | [] | module Vale.X64.StateLemmas
open Vale.X64.Machine_s
open Vale.Arch.Heap
open Vale.X64.State
open FStar.FunctionalExtensionality
module Ms = Vale.X64.Machine_Semantics_s
//open Vale.X64.Machine_Semantics_s
//module ME = Vale.X64.Memory
open Vale.X64.Memory
open Vale.Arch.MachineHeap_s
//module MS = Vale.X64.Memory_Sems
module VSS = Vale.X64.Stack_Sems
module F = FStar.FunctionalExtensionality
open Vale.Def.Prop_s
open FStar.Mul
unfold let machine_state = Ms.machine_state
unfold let code = Ms.code
unfold let machine_eval_code = Ms.machine_eval_code
val same_heap_types : squash (vale_full_heap == heap_impl)
unfold let coerce (#b #a:Type) (x:a{a == b}) : b = x
let machine_state_eq (s1 s2:machine_state) =
s1 == s2
let machine_state_equal (s1 s2:machine_state) =
let open Vale.X64.Machine_Semantics_s in
s1.ms_ok == s2.ms_ok /\
F.feq s1.ms_regs s2.ms_regs /\
F.feq s1.ms_flags s2.ms_flags /\
s1.ms_heap == s2.ms_heap /\
s1.ms_stack == s2.ms_stack /\
s1.ms_stackTaint == s2.ms_stackTaint /\
s1.ms_trace == s2.ms_trace /\
True
val use_machine_state_equal (_:unit) : Lemma
(requires True)
(ensures forall (s1 s2:machine_state).{:pattern machine_state_eq s1 s2}
machine_state_equal s1 s2 ==> machine_state_eq s1 s2)
let state_to_S (s:vale_state) : GTot machine_state =
let open Ms in
{
ms_ok = s.vs_ok;
ms_regs = Regs.to_fun s.vs_regs;
ms_flags = Flags.to_fun s.vs_flags;
ms_heap = coerce s.vs_heap;
ms_stack = VSS.stack_to_s s.vs_stack;
ms_stackTaint = s.vs_stackTaint;
ms_trace = [];
} | false | false | Vale.X64.StateLemmas.fsti | {
"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"
} | null | val state_of_S (s: machine_state) : GTot vale_state | [] | Vale.X64.StateLemmas.state_of_S | {
"file_name": "vale/code/arch/x64/Vale.X64.StateLemmas.fsti",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | s: Vale.X64.StateLemmas.machine_state -> Prims.GTot Vale.X64.State.vale_state | {
"end_col": 3,
"end_line": 63,
"start_col": 2,
"start_line": 55
} |
Prims.Tot | val coerce (#b #a: Type) (x: a{a == b}) : b | [
{
"abbrev": true,
"full_module": "FStar.FunctionalExtensionality",
"short_module": "F"
},
{
"abbrev": true,
"full_module": "Vale.X64.Stack_Sems",
"short_module": "VSS"
},
{
"abbrev": true,
"full_module": "Vale.X64.Stack_i",
"short_module": "VST"
},
{
"abbrev": true,
"full_module": "Vale.X64.Memory",
"short_module": "ME"
},
{
"abbrev": true,
"full_module": "Vale.X64.Memory_Sems",
"short_module": "MS"
},
{
"abbrev": true,
"full_module": "Vale.X64.Machine_Semantics_s",
"short_module": "BS"
},
{
"abbrev": false,
"full_module": "Vale.X64.State",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.HeapImpl",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Prop_s",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.FunctionalExtensionality",
"short_module": "F"
},
{
"abbrev": true,
"full_module": "Vale.X64.Stack_Sems",
"short_module": "VSS"
},
{
"abbrev": false,
"full_module": "Vale.Arch.MachineHeap_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Memory",
"short_module": null
},
{
"abbrev": true,
"full_module": "Vale.X64.Machine_Semantics_s",
"short_module": "Ms"
},
{
"abbrev": false,
"full_module": "FStar.FunctionalExtensionality",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.State",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Heap",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let coerce (#b #a:Type) (x:a{a == b}) : b = x | val coerce (#b #a: Type) (x: a{a == b}) : b
let coerce (#b #a: Type) (x: a{a == b}) : b = | false | null | false | x | {
"checked_file": "Vale.X64.StateLemmas.fsti.checked",
"dependencies": [
"Vale.X64.State.fsti.checked",
"Vale.X64.Stack_Sems.fsti.checked",
"Vale.X64.Regs.fsti.checked",
"Vale.X64.Memory.fsti.checked",
"Vale.X64.Machine_Semantics_s.fst.checked",
"Vale.X64.Machine_s.fst.checked",
"Vale.X64.Flags.fsti.checked",
"Vale.Def.Prop_s.fst.checked",
"Vale.Arch.MachineHeap_s.fst.checked",
"Vale.Arch.Heap.fsti.checked",
"prims.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.FunctionalExtensionality.fsti.checked"
],
"interface_file": false,
"source_file": "Vale.X64.StateLemmas.fsti"
} | [
"total"
] | [
"Prims.eq2"
] | [] | module Vale.X64.StateLemmas
open Vale.X64.Machine_s
open Vale.Arch.Heap
open Vale.X64.State
open FStar.FunctionalExtensionality
module Ms = Vale.X64.Machine_Semantics_s
//open Vale.X64.Machine_Semantics_s
//module ME = Vale.X64.Memory
open Vale.X64.Memory
open Vale.Arch.MachineHeap_s
//module MS = Vale.X64.Memory_Sems
module VSS = Vale.X64.Stack_Sems
module F = FStar.FunctionalExtensionality
open Vale.Def.Prop_s
open FStar.Mul
unfold let machine_state = Ms.machine_state
unfold let code = Ms.code
unfold let machine_eval_code = Ms.machine_eval_code | false | false | Vale.X64.StateLemmas.fsti | {
"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"
} | null | val coerce (#b #a: Type) (x: a{a == b}) : b | [] | Vale.X64.StateLemmas.coerce | {
"file_name": "vale/code/arch/x64/Vale.X64.StateLemmas.fsti",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | x: a{a == b} -> b | {
"end_col": 52,
"end_line": 21,
"start_col": 51,
"start_line": 21
} |
Prims.Tot | [
{
"abbrev": false,
"full_module": "Vale.Transformers.PeepHole",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.InsLemmas",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Transformers.InstructionReorder",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.PossiblyMonad",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Print_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_Semantics_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Instructions_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Instruction_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Bytes_Code_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Transformers",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Transformers",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let mov_mov_elim_ph = {
ph = (fun is ->
if safe_mov_mov_elim is then (
let [i1; i2] = is in
Some [i2]
) else None);
input_hint = 2;
} | let mov_mov_elim_ph = | false | null | false | {
ph
=
(fun is ->
if safe_mov_mov_elim is
then
(let [i1 ; i2] = is in
Some [i2])
else None);
input_hint = 2
} | {
"checked_file": "Vale.Transformers.MovMovElim.fst.checked",
"dependencies": [
"Vale.X64.Print_s.fst.checked",
"Vale.X64.Machine_Semantics_s.fst.checked",
"Vale.X64.Machine_s.fst.checked",
"Vale.X64.Instructions_s.fsti.checked",
"Vale.X64.Instruction_s.fsti.checked",
"Vale.X64.InsLemmas.fsti.checked",
"Vale.X64.Bytes_Code_s.fst.checked",
"Vale.Transformers.PeepHole.fsti.checked",
"Vale.Transformers.InstructionReorder.fst.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.Def.PossiblyMonad.fst.checked",
"Vale.Arch.Heap.fsti.checked",
"prims.fst.checked",
"FStar.Pervasives.fsti.checked"
],
"interface_file": false,
"source_file": "Vale.Transformers.MovMovElim.fst"
} | [
"total"
] | [
"Vale.Transformers.PeepHole.Mkpre_peephole",
"Prims.list",
"Vale.X64.Machine_Semantics_s.ins",
"Vale.Transformers.MovMovElim.safe_mov_mov_elim",
"FStar.Pervasives.Native.Some",
"Prims.Cons",
"Prims.Nil",
"FStar.Pervasives.Native.option",
"Prims.bool",
"FStar.Pervasives.Native.None"
] | [] | module Vale.Transformers.MovMovElim
open Vale.X64.Bytes_Code_s
open Vale.X64.Instruction_s
open Vale.X64.Instructions_s
open Vale.X64.Machine_Semantics_s
open Vale.X64.Machine_s
open Vale.X64.Print_s
open Vale.Def.PossiblyMonad
open Vale.Transformers.InstructionReorder
open Vale.X64.InsLemmas
open Vale.Transformers.PeepHole
(*
* AR: this proof relies on multiple inductive type inversions to know that
* oprs1 is a Mov64 (resp. for oprs2)
*
* this used to go through earlier with just ifuel 1, because F* was weakening
* the branch VCs with discriminator expressions, thereby unintentionally
* triggering the inversions, this is no longer true in F*, and hence more ifuel
*)
#push-options "--ifuel 4"
let safe_mov_mov_elim (is:list ins) : Tot bool =
match is with
| [Instr i1 oprs1 (AnnotateMov64 ()); Instr i2 oprs2 (AnnotateMov64 ())] ->
let oprs1:normal (instr_operands_t [out op64] [op64]) =
coerce_to_normal #(instr_operands_t [out op64] [op64]) oprs1 in
let oprs2:normal (instr_operands_t [out op64] [op64]) =
coerce_to_normal #(instr_operands_t [out op64] [op64]) oprs2 in
let (dst1, (src1, ())) = oprs1 in
let (dst2, (src2, ())) = oprs2 in
dst1 = dst2 && OReg? dst1 && (
let OReg rd = dst1 in
match src2 with
| OConst _ -> true
| OReg rs2 -> not (rs2 = rd)
| OStack (m, _) | OMem (m, _) ->
match m with
| MConst _ -> true
| _ -> false // TODO: Can we relax this restriction?
)
| _ -> false
#pop-options | false | true | Vale.Transformers.MovMovElim.fst | {
"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"
} | null | val mov_mov_elim_ph : Vale.Transformers.PeepHole.pre_peephole | [] | Vale.Transformers.MovMovElim.mov_mov_elim_ph | {
"file_name": "vale/code/lib/transformers/Vale.Transformers.MovMovElim.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | Vale.Transformers.PeepHole.pre_peephole | {
"end_col": 17,
"end_line": 53,
"start_col": 2,
"start_line": 48
} |
|
FStar.Pervasives.Lemma | val mov_mov_elim_correct (is: list ins) (s: machine_state)
: Lemma (peephole_correct mov_mov_elim_ph is s) [SMTPat (peephole_correct mov_mov_elim_ph is s)] | [
{
"abbrev": true,
"full_module": "Vale.Arch.Heap",
"short_module": "H"
},
{
"abbrev": true,
"full_module": "Vale.Def.Types_s",
"short_module": "T"
},
{
"abbrev": false,
"full_module": "Vale.Transformers.PeepHole",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.InsLemmas",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Transformers.InstructionReorder",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.PossiblyMonad",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Print_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_Semantics_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Instructions_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Instruction_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Bytes_Code_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Transformers",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Transformers",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let mov_mov_elim_correct (is:list ins) (s:machine_state) :
Lemma (peephole_correct mov_mov_elim_ph is s)
[SMTPat (peephole_correct mov_mov_elim_ph is s)] =
if safe_mov_mov_elim is then (
let [i1; i2] = is in
lemma_mov_mov_is_mov i1 i2 s
) else () | val mov_mov_elim_correct (is: list ins) (s: machine_state)
: Lemma (peephole_correct mov_mov_elim_ph is s) [SMTPat (peephole_correct mov_mov_elim_ph is s)]
let mov_mov_elim_correct (is: list ins) (s: machine_state)
: Lemma (peephole_correct mov_mov_elim_ph is s) [SMTPat (peephole_correct mov_mov_elim_ph is s)] = | false | null | true | if safe_mov_mov_elim is
then
(let [i1 ; i2] = is in
lemma_mov_mov_is_mov i1 i2 s) | {
"checked_file": "Vale.Transformers.MovMovElim.fst.checked",
"dependencies": [
"Vale.X64.Print_s.fst.checked",
"Vale.X64.Machine_Semantics_s.fst.checked",
"Vale.X64.Machine_s.fst.checked",
"Vale.X64.Instructions_s.fsti.checked",
"Vale.X64.Instruction_s.fsti.checked",
"Vale.X64.InsLemmas.fsti.checked",
"Vale.X64.Bytes_Code_s.fst.checked",
"Vale.Transformers.PeepHole.fsti.checked",
"Vale.Transformers.InstructionReorder.fst.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.Def.PossiblyMonad.fst.checked",
"Vale.Arch.Heap.fsti.checked",
"prims.fst.checked",
"FStar.Pervasives.fsti.checked"
],
"interface_file": false,
"source_file": "Vale.Transformers.MovMovElim.fst"
} | [
"lemma"
] | [
"Prims.list",
"Vale.X64.Machine_Semantics_s.ins",
"Vale.X64.Machine_Semantics_s.machine_state",
"Vale.Transformers.MovMovElim.safe_mov_mov_elim",
"Vale.Transformers.MovMovElim.lemma_mov_mov_is_mov",
"Prims.unit",
"Prims.bool",
"Prims.l_True",
"Prims.squash",
"Vale.Transformers.PeepHole.peephole_correct",
"Vale.Transformers.MovMovElim.mov_mov_elim_ph",
"Prims.Cons",
"FStar.Pervasives.pattern",
"FStar.Pervasives.smt_pat",
"Prims.Nil"
] | [] | module Vale.Transformers.MovMovElim
open Vale.X64.Bytes_Code_s
open Vale.X64.Instruction_s
open Vale.X64.Instructions_s
open Vale.X64.Machine_Semantics_s
open Vale.X64.Machine_s
open Vale.X64.Print_s
open Vale.Def.PossiblyMonad
open Vale.Transformers.InstructionReorder
open Vale.X64.InsLemmas
open Vale.Transformers.PeepHole
(*
* AR: this proof relies on multiple inductive type inversions to know that
* oprs1 is a Mov64 (resp. for oprs2)
*
* this used to go through earlier with just ifuel 1, because F* was weakening
* the branch VCs with discriminator expressions, thereby unintentionally
* triggering the inversions, this is no longer true in F*, and hence more ifuel
*)
#push-options "--ifuel 4"
let safe_mov_mov_elim (is:list ins) : Tot bool =
match is with
| [Instr i1 oprs1 (AnnotateMov64 ()); Instr i2 oprs2 (AnnotateMov64 ())] ->
let oprs1:normal (instr_operands_t [out op64] [op64]) =
coerce_to_normal #(instr_operands_t [out op64] [op64]) oprs1 in
let oprs2:normal (instr_operands_t [out op64] [op64]) =
coerce_to_normal #(instr_operands_t [out op64] [op64]) oprs2 in
let (dst1, (src1, ())) = oprs1 in
let (dst2, (src2, ())) = oprs2 in
dst1 = dst2 && OReg? dst1 && (
let OReg rd = dst1 in
match src2 with
| OConst _ -> true
| OReg rs2 -> not (rs2 = rd)
| OStack (m, _) | OMem (m, _) ->
match m with
| MConst _ -> true
| _ -> false // TODO: Can we relax this restriction?
)
| _ -> false
#pop-options
let mov_mov_elim_ph = {
ph = (fun is ->
if safe_mov_mov_elim is then (
let [i1; i2] = is in
Some [i2]
) else None);
input_hint = 2;
}
module T = Vale.Def.Types_s
module H = Vale.Arch.Heap
#push-options "--initial_fuel 2 --max_fuel 8 --initial_ifuel 1 --max_ifuel 2 --query_stats"
let lemma_mov_mov_is_mov (i1 i2:ins) (s:machine_state) :
Lemma
(requires (safe_mov_mov_elim [i1; i2]))
(ensures (
let s1 = machine_eval_ins i2 (machine_eval_ins i1 s) in
let s2 = machine_eval_ins i2 s in
s1.ms_ok ==> equiv_states s1 s2)) =
let Instr ii1 oprs1 (AnnotateMov64 ()) = i1 in
let Instr ii2 oprs2 (AnnotateMov64 ()) = i2 in
let oprs1:normal (instr_operands_t [out op64] [op64]) =
coerce_to_normal #(instr_operands_t [out op64] [op64]) oprs1 in
let oprs2:normal (instr_operands_t [out op64] [op64]) =
coerce_to_normal #(instr_operands_t [out op64] [op64]) oprs2 in
let (dst1, (src1, ())) = oprs1 in
let (dst2, (src2, ())) = oprs2 in
let dst = assert (dst1 == dst2); dst1 in
let pre_s1 = machine_eval_ins i1 s in
let s1 = machine_eval_ins i2 pre_s1 in
let s2 = machine_eval_ins i2 s in
if s1.ms_ok then (
assert (pre_s1.ms_ok);
let v1 = eval_operand src1 s in
let v2' = eval_operand src2 s in
let v2 = eval_operand src2 pre_s1 in
assert (v2 == v2');
lemma_double_update_reg dst s pre_s1 s1 s2 v1 v2
) else ()
#pop-options
#push-options "--initial_fuel 3 --max_fuel 3 --initial_ifuel 0 --max_ifuel 0"
let mov_mov_elim_correct (is:list ins) (s:machine_state) :
Lemma (peephole_correct mov_mov_elim_ph is s) | false | false | Vale.Transformers.MovMovElim.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 3,
"initial_ifuel": 0,
"max_fuel": 3,
"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"
],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val mov_mov_elim_correct (is: list ins) (s: machine_state)
: Lemma (peephole_correct mov_mov_elim_ph is s) [SMTPat (peephole_correct mov_mov_elim_ph is s)] | [] | Vale.Transformers.MovMovElim.mov_mov_elim_correct | {
"file_name": "vale/code/lib/transformers/Vale.Transformers.MovMovElim.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | is: Prims.list Vale.X64.Machine_Semantics_s.ins -> s: Vale.X64.Machine_Semantics_s.machine_state
-> FStar.Pervasives.Lemma
(ensures
Vale.Transformers.PeepHole.peephole_correct Vale.Transformers.MovMovElim.mov_mov_elim_ph
is
s)
[
SMTPat (Vale.Transformers.PeepHole.peephole_correct Vale.Transformers.MovMovElim.mov_mov_elim_ph
is
s)
] | {
"end_col": 11,
"end_line": 97,
"start_col": 2,
"start_line": 94
} |
Prims.Tot | val safe_mov_mov_elim (is: list ins) : Tot bool | [
{
"abbrev": false,
"full_module": "Vale.Transformers.PeepHole",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.InsLemmas",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Transformers.InstructionReorder",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.PossiblyMonad",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Print_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_Semantics_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Instructions_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Instruction_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Bytes_Code_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Transformers",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Transformers",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let safe_mov_mov_elim (is:list ins) : Tot bool =
match is with
| [Instr i1 oprs1 (AnnotateMov64 ()); Instr i2 oprs2 (AnnotateMov64 ())] ->
let oprs1:normal (instr_operands_t [out op64] [op64]) =
coerce_to_normal #(instr_operands_t [out op64] [op64]) oprs1 in
let oprs2:normal (instr_operands_t [out op64] [op64]) =
coerce_to_normal #(instr_operands_t [out op64] [op64]) oprs2 in
let (dst1, (src1, ())) = oprs1 in
let (dst2, (src2, ())) = oprs2 in
dst1 = dst2 && OReg? dst1 && (
let OReg rd = dst1 in
match src2 with
| OConst _ -> true
| OReg rs2 -> not (rs2 = rd)
| OStack (m, _) | OMem (m, _) ->
match m with
| MConst _ -> true
| _ -> false // TODO: Can we relax this restriction?
)
| _ -> false | val safe_mov_mov_elim (is: list ins) : Tot bool
let safe_mov_mov_elim (is: list ins) : Tot bool = | false | null | false | match is with
| [Instr i1 oprs1 (AnnotateMov64 ()) ; Instr i2 oprs2 (AnnotateMov64 ())] ->
let oprs1:normal (instr_operands_t [out op64] [op64]) =
coerce_to_normal #(instr_operands_t [out op64] [op64]) oprs1
in
let oprs2:normal (instr_operands_t [out op64] [op64]) =
coerce_to_normal #(instr_operands_t [out op64] [op64]) oprs2
in
let dst1, (src1, ()) = oprs1 in
let dst2, (src2, ()) = oprs2 in
dst1 = dst2 && OReg? dst1 &&
(let OReg rd = dst1 in
match src2 with
| OConst _ -> true
| OReg rs2 -> not (rs2 = rd)
| OStack (m, _)
| OMem (m, _) ->
match m with
| MConst _ -> true
| _ -> false)
| _ -> false | {
"checked_file": "Vale.Transformers.MovMovElim.fst.checked",
"dependencies": [
"Vale.X64.Print_s.fst.checked",
"Vale.X64.Machine_Semantics_s.fst.checked",
"Vale.X64.Machine_s.fst.checked",
"Vale.X64.Instructions_s.fsti.checked",
"Vale.X64.Instruction_s.fsti.checked",
"Vale.X64.InsLemmas.fsti.checked",
"Vale.X64.Bytes_Code_s.fst.checked",
"Vale.Transformers.PeepHole.fsti.checked",
"Vale.Transformers.InstructionReorder.fst.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.Def.PossiblyMonad.fst.checked",
"Vale.Arch.Heap.fsti.checked",
"prims.fst.checked",
"FStar.Pervasives.fsti.checked"
],
"interface_file": false,
"source_file": "Vale.Transformers.MovMovElim.fst"
} | [
"total"
] | [
"Prims.list",
"Vale.X64.Machine_Semantics_s.ins",
"Vale.X64.Instruction_s.instr_t_record",
"Vale.X64.Instruction_s.instr_operands_t",
"Vale.X64.Instruction_s.__proj__InstrTypeRecord__item__outs",
"Vale.X64.Instruction_s.__proj__InstrTypeRecord__item__args",
"Vale.X64.Machine_s.operand64",
"Prims.op_AmpAmp",
"Prims.op_Equality",
"Vale.X64.Machine_s.uu___is_OReg",
"Vale.X64.Machine_s.nat64",
"Vale.X64.Machine_s.reg_64",
"Prims.op_Negation",
"Vale.X64.Machine_s.maddr",
"Vale.Arch.HeapTypes_s.taint",
"Prims.int",
"Prims.bool",
"FStar.Pervasives.norm",
"Prims.Cons",
"FStar.Pervasives.norm_step",
"FStar.Pervasives.zeta",
"FStar.Pervasives.iota",
"FStar.Pervasives.delta_attr",
"Prims.string",
"Prims.Nil",
"Vale.X64.Instruction_s.instr_out",
"FStar.Pervasives.Native.Mktuple2",
"Vale.X64.Instruction_s.instr_operand_inout",
"Vale.X64.Instruction_s.instr_operand",
"Vale.X64.Instruction_s.Out",
"Vale.X64.Instruction_s.IOpEx",
"Vale.X64.Instruction_s.IOp64",
"Vale.Transformers.PeepHole.coerce_to_normal",
"Vale.X64.Instruction_s.out",
"Vale.X64.Instruction_s.op64"
] | [] | module Vale.Transformers.MovMovElim
open Vale.X64.Bytes_Code_s
open Vale.X64.Instruction_s
open Vale.X64.Instructions_s
open Vale.X64.Machine_Semantics_s
open Vale.X64.Machine_s
open Vale.X64.Print_s
open Vale.Def.PossiblyMonad
open Vale.Transformers.InstructionReorder
open Vale.X64.InsLemmas
open Vale.Transformers.PeepHole
(*
* AR: this proof relies on multiple inductive type inversions to know that
* oprs1 is a Mov64 (resp. for oprs2)
*
* this used to go through earlier with just ifuel 1, because F* was weakening
* the branch VCs with discriminator expressions, thereby unintentionally
* triggering the inversions, this is no longer true in F*, and hence more ifuel
*)
#push-options "--ifuel 4" | false | true | Vale.Transformers.MovMovElim.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 4,
"max_fuel": 1,
"max_ifuel": 4,
"no_plugins": false,
"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"
} | null | val safe_mov_mov_elim (is: list ins) : Tot bool | [] | Vale.Transformers.MovMovElim.safe_mov_mov_elim | {
"file_name": "vale/code/lib/transformers/Vale.Transformers.MovMovElim.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | is: Prims.list Vale.X64.Machine_Semantics_s.ins -> Prims.bool | {
"end_col": 14,
"end_line": 44,
"start_col": 2,
"start_line": 26
} |
FStar.Pervasives.Lemma | val lemma_mov_mov_is_mov (i1 i2: ins) (s: machine_state)
: Lemma (requires (safe_mov_mov_elim [i1; i2]))
(ensures
(let s1 = machine_eval_ins i2 (machine_eval_ins i1 s) in
let s2 = machine_eval_ins i2 s in
s1.ms_ok ==> equiv_states s1 s2)) | [
{
"abbrev": true,
"full_module": "Vale.Arch.Heap",
"short_module": "H"
},
{
"abbrev": true,
"full_module": "Vale.Def.Types_s",
"short_module": "T"
},
{
"abbrev": false,
"full_module": "Vale.Transformers.PeepHole",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.InsLemmas",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Transformers.InstructionReorder",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.PossiblyMonad",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Print_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_Semantics_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Instructions_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Instruction_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Bytes_Code_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Transformers",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Transformers",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let lemma_mov_mov_is_mov (i1 i2:ins) (s:machine_state) :
Lemma
(requires (safe_mov_mov_elim [i1; i2]))
(ensures (
let s1 = machine_eval_ins i2 (machine_eval_ins i1 s) in
let s2 = machine_eval_ins i2 s in
s1.ms_ok ==> equiv_states s1 s2)) =
let Instr ii1 oprs1 (AnnotateMov64 ()) = i1 in
let Instr ii2 oprs2 (AnnotateMov64 ()) = i2 in
let oprs1:normal (instr_operands_t [out op64] [op64]) =
coerce_to_normal #(instr_operands_t [out op64] [op64]) oprs1 in
let oprs2:normal (instr_operands_t [out op64] [op64]) =
coerce_to_normal #(instr_operands_t [out op64] [op64]) oprs2 in
let (dst1, (src1, ())) = oprs1 in
let (dst2, (src2, ())) = oprs2 in
let dst = assert (dst1 == dst2); dst1 in
let pre_s1 = machine_eval_ins i1 s in
let s1 = machine_eval_ins i2 pre_s1 in
let s2 = machine_eval_ins i2 s in
if s1.ms_ok then (
assert (pre_s1.ms_ok);
let v1 = eval_operand src1 s in
let v2' = eval_operand src2 s in
let v2 = eval_operand src2 pre_s1 in
assert (v2 == v2');
lemma_double_update_reg dst s pre_s1 s1 s2 v1 v2
) else () | val lemma_mov_mov_is_mov (i1 i2: ins) (s: machine_state)
: Lemma (requires (safe_mov_mov_elim [i1; i2]))
(ensures
(let s1 = machine_eval_ins i2 (machine_eval_ins i1 s) in
let s2 = machine_eval_ins i2 s in
s1.ms_ok ==> equiv_states s1 s2))
let lemma_mov_mov_is_mov (i1 i2: ins) (s: machine_state)
: Lemma (requires (safe_mov_mov_elim [i1; i2]))
(ensures
(let s1 = machine_eval_ins i2 (machine_eval_ins i1 s) in
let s2 = machine_eval_ins i2 s in
s1.ms_ok ==> equiv_states s1 s2)) = | false | null | true | let Instr ii1 oprs1 (AnnotateMov64 ()) = i1 in
let Instr ii2 oprs2 (AnnotateMov64 ()) = i2 in
let oprs1:normal (instr_operands_t [out op64] [op64]) =
coerce_to_normal #(instr_operands_t [out op64] [op64]) oprs1
in
let oprs2:normal (instr_operands_t [out op64] [op64]) =
coerce_to_normal #(instr_operands_t [out op64] [op64]) oprs2
in
let dst1, (src1, ()) = oprs1 in
let dst2, (src2, ()) = oprs2 in
let dst =
assert (dst1 == dst2);
dst1
in
let pre_s1 = machine_eval_ins i1 s in
let s1 = machine_eval_ins i2 pre_s1 in
let s2 = machine_eval_ins i2 s in
if s1.ms_ok
then
(assert (pre_s1.ms_ok);
let v1 = eval_operand src1 s in
let v2' = eval_operand src2 s in
let v2 = eval_operand src2 pre_s1 in
assert (v2 == v2');
lemma_double_update_reg dst s pre_s1 s1 s2 v1 v2) | {
"checked_file": "Vale.Transformers.MovMovElim.fst.checked",
"dependencies": [
"Vale.X64.Print_s.fst.checked",
"Vale.X64.Machine_Semantics_s.fst.checked",
"Vale.X64.Machine_s.fst.checked",
"Vale.X64.Instructions_s.fsti.checked",
"Vale.X64.Instruction_s.fsti.checked",
"Vale.X64.InsLemmas.fsti.checked",
"Vale.X64.Bytes_Code_s.fst.checked",
"Vale.Transformers.PeepHole.fsti.checked",
"Vale.Transformers.InstructionReorder.fst.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.Def.PossiblyMonad.fst.checked",
"Vale.Arch.Heap.fsti.checked",
"prims.fst.checked",
"FStar.Pervasives.fsti.checked"
],
"interface_file": false,
"source_file": "Vale.Transformers.MovMovElim.fst"
} | [
"lemma"
] | [
"Vale.X64.Machine_Semantics_s.ins",
"Vale.X64.Machine_Semantics_s.machine_state",
"Vale.X64.Instruction_s.instr_t_record",
"Vale.X64.Instruction_s.instr_operands_t",
"Vale.X64.Instruction_s.__proj__InstrTypeRecord__item__outs",
"Vale.X64.Instruction_s.__proj__InstrTypeRecord__item__args",
"Vale.X64.Machine_s.operand64",
"Vale.X64.Machine_Semantics_s.__proj__Mkmachine_state__item__ms_ok",
"Vale.Transformers.PeepHole.lemma_double_update_reg",
"Prims.unit",
"Prims._assert",
"Prims.eq2",
"Vale.Def.Types_s.nat64",
"Vale.Def.Words_s.nat64",
"Vale.X64.Machine_Semantics_s.eval_operand",
"Prims.b2t",
"Prims.bool",
"Vale.X64.Machine_Semantics_s.machine_eval_ins",
"FStar.Pervasives.norm",
"Prims.Cons",
"FStar.Pervasives.norm_step",
"FStar.Pervasives.zeta",
"FStar.Pervasives.iota",
"FStar.Pervasives.delta_attr",
"Prims.string",
"Prims.Nil",
"Vale.X64.Instruction_s.instr_out",
"FStar.Pervasives.Native.Mktuple2",
"Vale.X64.Instruction_s.instr_operand_inout",
"Vale.X64.Instruction_s.instr_operand",
"Vale.X64.Instruction_s.Out",
"Vale.X64.Instruction_s.IOpEx",
"Vale.X64.Instruction_s.IOp64",
"Vale.Transformers.PeepHole.coerce_to_normal",
"Vale.X64.Instruction_s.out",
"Vale.X64.Instruction_s.op64",
"Vale.Transformers.MovMovElim.safe_mov_mov_elim",
"Prims.squash",
"Prims.l_imp",
"Vale.Transformers.InstructionReorder.equiv_states",
"FStar.Pervasives.pattern"
] | [] | module Vale.Transformers.MovMovElim
open Vale.X64.Bytes_Code_s
open Vale.X64.Instruction_s
open Vale.X64.Instructions_s
open Vale.X64.Machine_Semantics_s
open Vale.X64.Machine_s
open Vale.X64.Print_s
open Vale.Def.PossiblyMonad
open Vale.Transformers.InstructionReorder
open Vale.X64.InsLemmas
open Vale.Transformers.PeepHole
(*
* AR: this proof relies on multiple inductive type inversions to know that
* oprs1 is a Mov64 (resp. for oprs2)
*
* this used to go through earlier with just ifuel 1, because F* was weakening
* the branch VCs with discriminator expressions, thereby unintentionally
* triggering the inversions, this is no longer true in F*, and hence more ifuel
*)
#push-options "--ifuel 4"
let safe_mov_mov_elim (is:list ins) : Tot bool =
match is with
| [Instr i1 oprs1 (AnnotateMov64 ()); Instr i2 oprs2 (AnnotateMov64 ())] ->
let oprs1:normal (instr_operands_t [out op64] [op64]) =
coerce_to_normal #(instr_operands_t [out op64] [op64]) oprs1 in
let oprs2:normal (instr_operands_t [out op64] [op64]) =
coerce_to_normal #(instr_operands_t [out op64] [op64]) oprs2 in
let (dst1, (src1, ())) = oprs1 in
let (dst2, (src2, ())) = oprs2 in
dst1 = dst2 && OReg? dst1 && (
let OReg rd = dst1 in
match src2 with
| OConst _ -> true
| OReg rs2 -> not (rs2 = rd)
| OStack (m, _) | OMem (m, _) ->
match m with
| MConst _ -> true
| _ -> false // TODO: Can we relax this restriction?
)
| _ -> false
#pop-options
let mov_mov_elim_ph = {
ph = (fun is ->
if safe_mov_mov_elim is then (
let [i1; i2] = is in
Some [i2]
) else None);
input_hint = 2;
}
module T = Vale.Def.Types_s
module H = Vale.Arch.Heap
#push-options "--initial_fuel 2 --max_fuel 8 --initial_ifuel 1 --max_ifuel 2 --query_stats"
let lemma_mov_mov_is_mov (i1 i2:ins) (s:machine_state) :
Lemma
(requires (safe_mov_mov_elim [i1; i2]))
(ensures (
let s1 = machine_eval_ins i2 (machine_eval_ins i1 s) in | false | false | Vale.Transformers.MovMovElim.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": 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"
} | null | val lemma_mov_mov_is_mov (i1 i2: ins) (s: machine_state)
: Lemma (requires (safe_mov_mov_elim [i1; i2]))
(ensures
(let s1 = machine_eval_ins i2 (machine_eval_ins i1 s) in
let s2 = machine_eval_ins i2 s in
s1.ms_ok ==> equiv_states s1 s2)) | [] | Vale.Transformers.MovMovElim.lemma_mov_mov_is_mov | {
"file_name": "vale/code/lib/transformers/Vale.Transformers.MovMovElim.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} |
i1: Vale.X64.Machine_Semantics_s.ins ->
i2: Vale.X64.Machine_Semantics_s.ins ->
s: Vale.X64.Machine_Semantics_s.machine_state
-> FStar.Pervasives.Lemma (requires Vale.Transformers.MovMovElim.safe_mov_mov_elim [i1; i2])
(ensures
(let s1 =
Vale.X64.Machine_Semantics_s.machine_eval_ins i2
(Vale.X64.Machine_Semantics_s.machine_eval_ins i1 s)
in
let s2 = Vale.X64.Machine_Semantics_s.machine_eval_ins i2 s in
Mkmachine_state?.ms_ok s1 ==> Vale.Transformers.InstructionReorder.equiv_states s1 s2)) | {
"end_col": 11,
"end_line": 86,
"start_col": 43,
"start_line": 66
} |
Prims.GTot | [
{
"abbrev": true,
"full_module": "Lib.ByteSequence",
"short_module": "BSeq"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.P256.Montgomery",
"short_module": "SM"
},
{
"abbrev": true,
"full_module": "Spec.P256",
"short_module": "S"
},
{
"abbrev": false,
"full_module": "Hacl.Impl.P256.Bignum",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Buffer",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.All",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl.P256",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl.P256",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let qmont_as_nat (h:mem) (a:felem) = SM.from_qmont (as_nat h a) | let qmont_as_nat (h: mem) (a: felem) = | false | null | false | SM.from_qmont (as_nat h a) | {
"checked_file": "Hacl.Impl.P256.Scalar.fsti.checked",
"dependencies": [
"Spec.P256.fst.checked",
"prims.fst.checked",
"Lib.IntTypes.fsti.checked",
"Lib.ByteSequence.fsti.checked",
"Lib.Buffer.fsti.checked",
"Hacl.Spec.P256.Montgomery.fsti.checked",
"Hacl.Impl.P256.Bignum.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.All.fst.checked",
"FStar.HyperStack.fst.checked"
],
"interface_file": false,
"source_file": "Hacl.Impl.P256.Scalar.fsti"
} | [
"sometrivial"
] | [
"FStar.Monotonic.HyperStack.mem",
"Hacl.Impl.P256.Bignum.felem",
"Hacl.Spec.P256.Montgomery.from_qmont",
"Hacl.Impl.P256.Bignum.as_nat",
"Spec.P256.PointOps.qelem"
] | [] | module Hacl.Impl.P256.Scalar
open FStar.Mul
open FStar.HyperStack.All
open FStar.HyperStack
module ST = FStar.HyperStack.ST
open Lib.IntTypes
open Lib.Buffer
open Hacl.Impl.P256.Bignum
module S = Spec.P256
module SM = Hacl.Spec.P256.Montgomery
module BSeq = Lib.ByteSequence
#set-options "--z3rlimit 30 --fuel 0 --ifuel 0" | false | false | Hacl.Impl.P256.Scalar.fsti | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 30,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val qmont_as_nat : h: FStar.Monotonic.HyperStack.mem -> a: Hacl.Impl.P256.Bignum.felem
-> Prims.GTot Spec.P256.PointOps.qelem | [] | Hacl.Impl.P256.Scalar.qmont_as_nat | {
"file_name": "code/ecdsap256/Hacl.Impl.P256.Scalar.fsti",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | h: FStar.Monotonic.HyperStack.mem -> a: Hacl.Impl.P256.Bignum.felem
-> Prims.GTot Spec.P256.PointOps.qelem | {
"end_col": 63,
"end_line": 19,
"start_col": 37,
"start_line": 19
} |
|
FStar.Tactics.Effect.Tac | val contains_uvar (t: term) (uvs g: env) : T.Tac bool | [
{
"abbrev": true,
"full_module": "Pulse.Checker.Prover.Substs",
"short_module": "PS"
},
{
"abbrev": true,
"full_module": "Pulse.Syntax.Printer",
"short_module": "P"
},
{
"abbrev": true,
"full_module": "Pulse.Reflection.Util",
"short_module": "RUtil"
},
{
"abbrev": true,
"full_module": "FStar.Tactics.V2",
"short_module": "T"
},
{
"abbrev": true,
"full_module": "FStar.Reflection.V2.TermEq",
"short_module": "TermEq"
},
{
"abbrev": true,
"full_module": "FStar.Reflection.V2",
"short_module": "R"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "Pulse.Checker.Prover.Util",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Checker.Prover.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Checker.VPropEquiv",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Typing.Util",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Typing.Metatheory",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Typing.Combinators",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Typing",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Syntax",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Checker.Prover.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Checker.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Typing",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Syntax",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.Tactics",
"short_module": "T"
},
{
"abbrev": false,
"full_module": "Pulse.Checker.Prover",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Checker.Prover",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let contains_uvar (t:term) (uvs:env) (g:env) : T.Tac bool =
not (check_disjoint uvs (freevars t)) | val contains_uvar (t: term) (uvs g: env) : T.Tac bool
let contains_uvar (t: term) (uvs g: env) : T.Tac bool = | true | null | false | not (check_disjoint uvs (freevars t)) | {
"checked_file": "Pulse.Checker.Prover.Match.fst.checked",
"dependencies": [
"Pulse.Typing.Util.fsti.checked",
"Pulse.Typing.Metatheory.fsti.checked",
"Pulse.Typing.Combinators.fsti.checked",
"Pulse.Typing.fst.checked",
"Pulse.Syntax.Printer.fsti.checked",
"Pulse.Syntax.fst.checked",
"Pulse.Reflection.Util.fst.checked",
"Pulse.Checker.VPropEquiv.fsti.checked",
"Pulse.Checker.Prover.Util.fsti.checked",
"Pulse.Checker.Prover.Substs.fsti.checked",
"Pulse.Checker.Prover.Base.fsti.checked",
"prims.fst.checked",
"FStar.Tactics.V2.fst.checked",
"FStar.Squash.fsti.checked",
"FStar.Set.fsti.checked",
"FStar.Reflection.V2.TermEq.fst.checked",
"FStar.Reflection.V2.fst.checked",
"FStar.Reflection.Typing.fsti.checked",
"FStar.Printf.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked"
],
"interface_file": true,
"source_file": "Pulse.Checker.Prover.Match.fst"
} | [] | [
"Pulse.Syntax.Base.term",
"Pulse.Typing.Env.env",
"Prims.op_Negation",
"Pulse.Typing.Env.check_disjoint",
"Pulse.Syntax.Naming.freevars",
"Prims.bool"
] | [] | module Pulse.Checker.Prover.Match
open Pulse.Syntax
open Pulse.Typing
open Pulse.Typing.Combinators
open Pulse.Typing.Metatheory
open Pulse.Typing.Util
open Pulse.Checker.VPropEquiv
open Pulse.Checker.Prover.Base
open Pulse.Checker.Prover.Util
module L = FStar.List.Tot
module R = FStar.Reflection.V2
module TermEq = FStar.Reflection.V2.TermEq
module T = FStar.Tactics.V2
module RUtil = Pulse.Reflection.Util
module P = Pulse.Syntax.Printer
module PS = Pulse.Checker.Prover.Substs
let equational (t:term) : bool =
match t.t with
| Tm_FStar host_term ->
(match R.inspect_ln host_term with
| R.Tv_Match _ _ _ -> true
| _ -> false)
| _ -> false
let type_of_fv (g:env) (fv:R.fv)
: T.Tac (option R.term)
= let n = R.inspect_fv fv in
match R.lookup_typ (fstar_env g) n with
| None -> None
| Some se ->
match R.inspect_sigelt se with
| R.Unk -> None
| R.Sg_Let _ lbs -> (
L.tryPick
(fun lb ->
let lbv = R.inspect_lb lb in
if R.inspect_fv lbv.lb_fv = n
then Some lbv.lb_typ
else None)
lbs
)
| R.Sg_Val _ _ t -> Some t
| R.Sg_Inductive _nm _univs params typ _ -> None
let is_smt_fallback (t:R.term) : bool =
match R.inspect_ln t with
| R.Tv_FVar fv ->
let name = R.inspect_fv fv in
name = ["Steel";"Effect";"Common";"smt_fallback"]
| _ -> false
(*
When comparing t0 =?= t1, if they are not syntactically equal, we
have to decide whether or not we should fire an SMT query to compare
them for provable equality.
The criterion is as follows:
1. We allow an SMT query if either t0 or t1 is "equational". For now, that means
that either is a match expression.
2. Otherwise, if they are both applications of `f v0...vn` and `f u0...un`
of the same head symbol `f`, a top-level constant, then we check if the
type of `f` decorates any of its binders with the `smt_fallback` attribute.
- If none of them are marked as such,
then we check if `f v0...` is syntactically equal to `f u0...`
and allow an SMT query to check if vn = vm. That is, the default behavior
for predicates is that they *last* argument is eligible for SMT equality.
- Otherwise, for each binder that is NOT marked as `smt_fallback`, we check
if the corresponding argument is syntactically equal. If so, we allow
t0 and t1 to be compared for SMT equality.
For example, Steel.ST.Reference.pts_to is defined like so:
/// For instance, [pts_to r (sum_perm (half_perm p) (half_perm p)) (v + 1)]
/// is unifiable with [pts_to r p (1 + v)]
val pts_to (#a:Type0)
(r:ref a)
([@@@smt_fallback] p:perm)
([@@@smt_fallback] v:a)
: vprop
*)
let eligible_for_smt_equality (g:env) (t0 t1:term)
: T.Tac bool
= let either_equational () = equational t0 || equational t1 in
let head_eq (t0 t1:R.term) =
match R.inspect_ln t0, R.inspect_ln t1 with
| R.Tv_App h0 _, R.Tv_App h1 _ ->
TermEq.term_eq h0 h1
| _ -> false
in
match t0.t, t1.t with
| Tm_FStar t0, Tm_FStar t1 -> (
let h0, args0 = R.collect_app_ln t0 in
let h1, args1 = R.collect_app_ln t1 in
if TermEq.term_eq h0 h1 && L.length args0 = L.length args1
then (
match R.inspect_ln h0 with
| R.Tv_FVar fv
| R.Tv_UInst fv _ -> (
match type_of_fv g fv with
| None -> either_equational()
| Some t ->
let bs, _ = R.collect_arr_ln_bs t in
let is_smt_fallback (b:R.binder) =
let bview = R.inspect_binder b in
L.existsb is_smt_fallback bview.attrs
in
let some_fallbacks, fallbacks =
L.fold_right
(fun b (some_fallbacks, bs) ->
if is_smt_fallback b
then true, true::bs
else some_fallbacks, false::bs)
bs (false, [])
in
if not some_fallbacks
then (
//if none of the binders are marked fallback
//then, by default, consider only the last argument as
//fallback
head_eq t0 t1
)
else (
let rec aux args0 args1 fallbacks =
match args0, args1, fallbacks with
| (a0, _)::args0, (a1, _)::args1, b::fallbacks ->
if b
then aux args0 args1 fallbacks
else if not (TermEq.term_eq a0 a1)
then false
else aux args0 args1 fallbacks
| [], [], [] -> true
| _ -> either_equational() //unequal lengths
in
aux args0 args1 fallbacks
)
)
| _ -> either_equational ()
)
else either_equational ()
)
| _ -> either_equational ()
let refl_uvar (t:R.term) (uvs:env) : option var =
let open R in
match inspect_ln t with
| Tv_Var v ->
let {uniq=n} = inspect_namedv v in
if contains uvs n then Some n else None
| _ -> None
let is_uvar (t:term) (uvs:env) : option var =
match t.t with
| Tm_FStar t -> refl_uvar t uvs
| _ -> None | false | false | Pulse.Checker.Prover.Match.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val contains_uvar (t: term) (uvs g: env) : T.Tac bool | [] | Pulse.Checker.Prover.Match.contains_uvar | {
"file_name": "lib/steel/pulse/Pulse.Checker.Prover.Match.fst",
"git_rev": "7fbb54e94dd4f48ff7cb867d3bae6889a635541e",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | t: Pulse.Syntax.Base.term -> uvs: Pulse.Typing.Env.env -> g: Pulse.Typing.Env.env
-> FStar.Tactics.Effect.Tac Prims.bool | {
"end_col": 39,
"end_line": 166,
"start_col": 2,
"start_line": 166
} |
Prims.Tot | val refl_uvar (t: R.term) (uvs: env) : option var | [
{
"abbrev": true,
"full_module": "Pulse.Checker.Prover.Substs",
"short_module": "PS"
},
{
"abbrev": true,
"full_module": "Pulse.Syntax.Printer",
"short_module": "P"
},
{
"abbrev": true,
"full_module": "Pulse.Reflection.Util",
"short_module": "RUtil"
},
{
"abbrev": true,
"full_module": "FStar.Tactics.V2",
"short_module": "T"
},
{
"abbrev": true,
"full_module": "FStar.Reflection.V2.TermEq",
"short_module": "TermEq"
},
{
"abbrev": true,
"full_module": "FStar.Reflection.V2",
"short_module": "R"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "Pulse.Checker.Prover.Util",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Checker.Prover.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Checker.VPropEquiv",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Typing.Util",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Typing.Metatheory",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Typing.Combinators",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Typing",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Syntax",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Checker.Prover.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Checker.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Typing",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Syntax",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.Tactics",
"short_module": "T"
},
{
"abbrev": false,
"full_module": "Pulse.Checker.Prover",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Checker.Prover",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let refl_uvar (t:R.term) (uvs:env) : option var =
let open R in
match inspect_ln t with
| Tv_Var v ->
let {uniq=n} = inspect_namedv v in
if contains uvs n then Some n else None
| _ -> None | val refl_uvar (t: R.term) (uvs: env) : option var
let refl_uvar (t: R.term) (uvs: env) : option var = | false | null | false | let open R in
match inspect_ln t with
| Tv_Var v ->
let { uniq = n } = inspect_namedv v in
if contains uvs n then Some n else None
| _ -> None | {
"checked_file": "Pulse.Checker.Prover.Match.fst.checked",
"dependencies": [
"Pulse.Typing.Util.fsti.checked",
"Pulse.Typing.Metatheory.fsti.checked",
"Pulse.Typing.Combinators.fsti.checked",
"Pulse.Typing.fst.checked",
"Pulse.Syntax.Printer.fsti.checked",
"Pulse.Syntax.fst.checked",
"Pulse.Reflection.Util.fst.checked",
"Pulse.Checker.VPropEquiv.fsti.checked",
"Pulse.Checker.Prover.Util.fsti.checked",
"Pulse.Checker.Prover.Substs.fsti.checked",
"Pulse.Checker.Prover.Base.fsti.checked",
"prims.fst.checked",
"FStar.Tactics.V2.fst.checked",
"FStar.Squash.fsti.checked",
"FStar.Set.fsti.checked",
"FStar.Reflection.V2.TermEq.fst.checked",
"FStar.Reflection.V2.fst.checked",
"FStar.Reflection.Typing.fsti.checked",
"FStar.Printf.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked"
],
"interface_file": true,
"source_file": "Pulse.Checker.Prover.Match.fst"
} | [
"total"
] | [
"FStar.Reflection.Types.term",
"Pulse.Typing.Env.env",
"FStar.Reflection.V2.Builtins.inspect_ln",
"FStar.Reflection.Types.namedv",
"Prims.nat",
"FStar.Sealed.sealed",
"FStar.Reflection.Types.typ",
"FStar.Reflection.V2.Data.ppname_t",
"Pulse.Typing.Env.contains",
"FStar.Pervasives.Native.Some",
"Pulse.Syntax.Base.var",
"Prims.bool",
"FStar.Pervasives.Native.None",
"FStar.Pervasives.Native.option",
"FStar.Reflection.V2.Data.namedv_view",
"Prims.precedes",
"FStar.Reflection.V2.Builtins.inspect_namedv",
"FStar.Reflection.V2.Data.term_view"
] | [] | module Pulse.Checker.Prover.Match
open Pulse.Syntax
open Pulse.Typing
open Pulse.Typing.Combinators
open Pulse.Typing.Metatheory
open Pulse.Typing.Util
open Pulse.Checker.VPropEquiv
open Pulse.Checker.Prover.Base
open Pulse.Checker.Prover.Util
module L = FStar.List.Tot
module R = FStar.Reflection.V2
module TermEq = FStar.Reflection.V2.TermEq
module T = FStar.Tactics.V2
module RUtil = Pulse.Reflection.Util
module P = Pulse.Syntax.Printer
module PS = Pulse.Checker.Prover.Substs
let equational (t:term) : bool =
match t.t with
| Tm_FStar host_term ->
(match R.inspect_ln host_term with
| R.Tv_Match _ _ _ -> true
| _ -> false)
| _ -> false
let type_of_fv (g:env) (fv:R.fv)
: T.Tac (option R.term)
= let n = R.inspect_fv fv in
match R.lookup_typ (fstar_env g) n with
| None -> None
| Some se ->
match R.inspect_sigelt se with
| R.Unk -> None
| R.Sg_Let _ lbs -> (
L.tryPick
(fun lb ->
let lbv = R.inspect_lb lb in
if R.inspect_fv lbv.lb_fv = n
then Some lbv.lb_typ
else None)
lbs
)
| R.Sg_Val _ _ t -> Some t
| R.Sg_Inductive _nm _univs params typ _ -> None
let is_smt_fallback (t:R.term) : bool =
match R.inspect_ln t with
| R.Tv_FVar fv ->
let name = R.inspect_fv fv in
name = ["Steel";"Effect";"Common";"smt_fallback"]
| _ -> false
(*
When comparing t0 =?= t1, if they are not syntactically equal, we
have to decide whether or not we should fire an SMT query to compare
them for provable equality.
The criterion is as follows:
1. We allow an SMT query if either t0 or t1 is "equational". For now, that means
that either is a match expression.
2. Otherwise, if they are both applications of `f v0...vn` and `f u0...un`
of the same head symbol `f`, a top-level constant, then we check if the
type of `f` decorates any of its binders with the `smt_fallback` attribute.
- If none of them are marked as such,
then we check if `f v0...` is syntactically equal to `f u0...`
and allow an SMT query to check if vn = vm. That is, the default behavior
for predicates is that they *last* argument is eligible for SMT equality.
- Otherwise, for each binder that is NOT marked as `smt_fallback`, we check
if the corresponding argument is syntactically equal. If so, we allow
t0 and t1 to be compared for SMT equality.
For example, Steel.ST.Reference.pts_to is defined like so:
/// For instance, [pts_to r (sum_perm (half_perm p) (half_perm p)) (v + 1)]
/// is unifiable with [pts_to r p (1 + v)]
val pts_to (#a:Type0)
(r:ref a)
([@@@smt_fallback] p:perm)
([@@@smt_fallback] v:a)
: vprop
*)
let eligible_for_smt_equality (g:env) (t0 t1:term)
: T.Tac bool
= let either_equational () = equational t0 || equational t1 in
let head_eq (t0 t1:R.term) =
match R.inspect_ln t0, R.inspect_ln t1 with
| R.Tv_App h0 _, R.Tv_App h1 _ ->
TermEq.term_eq h0 h1
| _ -> false
in
match t0.t, t1.t with
| Tm_FStar t0, Tm_FStar t1 -> (
let h0, args0 = R.collect_app_ln t0 in
let h1, args1 = R.collect_app_ln t1 in
if TermEq.term_eq h0 h1 && L.length args0 = L.length args1
then (
match R.inspect_ln h0 with
| R.Tv_FVar fv
| R.Tv_UInst fv _ -> (
match type_of_fv g fv with
| None -> either_equational()
| Some t ->
let bs, _ = R.collect_arr_ln_bs t in
let is_smt_fallback (b:R.binder) =
let bview = R.inspect_binder b in
L.existsb is_smt_fallback bview.attrs
in
let some_fallbacks, fallbacks =
L.fold_right
(fun b (some_fallbacks, bs) ->
if is_smt_fallback b
then true, true::bs
else some_fallbacks, false::bs)
bs (false, [])
in
if not some_fallbacks
then (
//if none of the binders are marked fallback
//then, by default, consider only the last argument as
//fallback
head_eq t0 t1
)
else (
let rec aux args0 args1 fallbacks =
match args0, args1, fallbacks with
| (a0, _)::args0, (a1, _)::args1, b::fallbacks ->
if b
then aux args0 args1 fallbacks
else if not (TermEq.term_eq a0 a1)
then false
else aux args0 args1 fallbacks
| [], [], [] -> true
| _ -> either_equational() //unequal lengths
in
aux args0 args1 fallbacks
)
)
| _ -> either_equational ()
)
else either_equational ()
)
| _ -> either_equational () | false | true | Pulse.Checker.Prover.Match.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val refl_uvar (t: R.term) (uvs: env) : option var | [] | Pulse.Checker.Prover.Match.refl_uvar | {
"file_name": "lib/steel/pulse/Pulse.Checker.Prover.Match.fst",
"git_rev": "7fbb54e94dd4f48ff7cb867d3bae6889a635541e",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | t: FStar.Reflection.Types.term -> uvs: Pulse.Typing.Env.env
-> FStar.Pervasives.Native.option Pulse.Syntax.Base.var | {
"end_col": 13,
"end_line": 158,
"start_col": 2,
"start_line": 153
} |
Prims.Tot | val equational (t: term) : bool | [
{
"abbrev": true,
"full_module": "Pulse.Checker.Prover.Substs",
"short_module": "PS"
},
{
"abbrev": true,
"full_module": "Pulse.Syntax.Printer",
"short_module": "P"
},
{
"abbrev": true,
"full_module": "Pulse.Reflection.Util",
"short_module": "RUtil"
},
{
"abbrev": true,
"full_module": "FStar.Tactics.V2",
"short_module": "T"
},
{
"abbrev": true,
"full_module": "FStar.Reflection.V2.TermEq",
"short_module": "TermEq"
},
{
"abbrev": true,
"full_module": "FStar.Reflection.V2",
"short_module": "R"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "Pulse.Checker.Prover.Util",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Checker.Prover.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Checker.VPropEquiv",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Typing.Util",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Typing.Metatheory",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Typing.Combinators",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Typing",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Syntax",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Checker.Prover.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Checker.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Typing",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Syntax",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.Tactics",
"short_module": "T"
},
{
"abbrev": false,
"full_module": "Pulse.Checker.Prover",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Checker.Prover",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let equational (t:term) : bool =
match t.t with
| Tm_FStar host_term ->
(match R.inspect_ln host_term with
| R.Tv_Match _ _ _ -> true
| _ -> false)
| _ -> false | val equational (t: term) : bool
let equational (t: term) : bool = | false | null | false | match t.t with
| Tm_FStar host_term ->
(match R.inspect_ln host_term with
| R.Tv_Match _ _ _ -> true
| _ -> false)
| _ -> false | {
"checked_file": "Pulse.Checker.Prover.Match.fst.checked",
"dependencies": [
"Pulse.Typing.Util.fsti.checked",
"Pulse.Typing.Metatheory.fsti.checked",
"Pulse.Typing.Combinators.fsti.checked",
"Pulse.Typing.fst.checked",
"Pulse.Syntax.Printer.fsti.checked",
"Pulse.Syntax.fst.checked",
"Pulse.Reflection.Util.fst.checked",
"Pulse.Checker.VPropEquiv.fsti.checked",
"Pulse.Checker.Prover.Util.fsti.checked",
"Pulse.Checker.Prover.Substs.fsti.checked",
"Pulse.Checker.Prover.Base.fsti.checked",
"prims.fst.checked",
"FStar.Tactics.V2.fst.checked",
"FStar.Squash.fsti.checked",
"FStar.Set.fsti.checked",
"FStar.Reflection.V2.TermEq.fst.checked",
"FStar.Reflection.V2.fst.checked",
"FStar.Reflection.Typing.fsti.checked",
"FStar.Printf.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked"
],
"interface_file": true,
"source_file": "Pulse.Checker.Prover.Match.fst"
} | [
"total"
] | [
"Pulse.Syntax.Base.term",
"Pulse.Syntax.Base.__proj__Mkterm__item__t",
"Pulse.Syntax.Base.host_term",
"FStar.Reflection.V2.Builtins.inspect_ln",
"FStar.Reflection.Types.term",
"FStar.Pervasives.Native.option",
"FStar.Reflection.Types.match_returns_ascription",
"Prims.list",
"FStar.Reflection.V2.Data.branch",
"FStar.Reflection.V2.Data.term_view",
"Prims.bool",
"Pulse.Syntax.Base.term'"
] | [] | module Pulse.Checker.Prover.Match
open Pulse.Syntax
open Pulse.Typing
open Pulse.Typing.Combinators
open Pulse.Typing.Metatheory
open Pulse.Typing.Util
open Pulse.Checker.VPropEquiv
open Pulse.Checker.Prover.Base
open Pulse.Checker.Prover.Util
module L = FStar.List.Tot
module R = FStar.Reflection.V2
module TermEq = FStar.Reflection.V2.TermEq
module T = FStar.Tactics.V2
module RUtil = Pulse.Reflection.Util
module P = Pulse.Syntax.Printer
module PS = Pulse.Checker.Prover.Substs | false | true | Pulse.Checker.Prover.Match.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val equational (t: term) : bool | [] | Pulse.Checker.Prover.Match.equational | {
"file_name": "lib/steel/pulse/Pulse.Checker.Prover.Match.fst",
"git_rev": "7fbb54e94dd4f48ff7cb867d3bae6889a635541e",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | t: Pulse.Syntax.Base.term -> Prims.bool | {
"end_col": 14,
"end_line": 27,
"start_col": 2,
"start_line": 22
} |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.