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": "Hacl.Spec.Bignum.Convert",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "Lib.Sequence",
"short_module": "LSeq"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": false,
"full_module": "Hacl.Bignum.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.ByteBuffer",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Buffer",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Bignum",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Bignum",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let bn_from_bytes_le_st (t:limb_t) =
len:size_t{0 < v len /\ numbytes t * v (blocks len (size (numbytes t))) <= max_size_t}
-> b:lbuffer uint8 len
-> res:lbignum t (blocks len (size (numbytes t))) ->
Stack unit
(requires fun h -> live h b /\ live h res /\ disjoint res b)
(ensures fun h0 _ h1 -> modifies (loc res) h0 h1 /\
as_seq h1 res == S.bn_from_bytes_le (v len) (as_seq h0 b)) | let bn_from_bytes_le_st (t: limb_t) = | false | null | false |
len: size_t{0 < v len /\ numbytes t * v (blocks len (size (numbytes t))) <= max_size_t} ->
b: lbuffer uint8 len ->
res: lbignum t (blocks len (size (numbytes t)))
-> Stack unit
(requires fun h -> live h b /\ live h res /\ disjoint res b)
(ensures
fun h0 _ h1 ->
modifies (loc res) h0 h1 /\ as_seq h1 res == S.bn_from_bytes_le (v len) (as_seq h0 b)) | {
"checked_file": "Hacl.Bignum.Convert.fst.checked",
"dependencies": [
"prims.fst.checked",
"LowStar.Ignore.fsti.checked",
"LowStar.Buffer.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.ByteBuffer.fsti.checked",
"Lib.Buffer.fsti.checked",
"Hacl.Spec.Bignum.Convert.fst.checked",
"Hacl.Bignum.Definitions.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked"
],
"interface_file": false,
"source_file": "Hacl.Bignum.Convert.fst"
} | [
"total"
] | [
"Hacl.Bignum.Definitions.limb_t",
"Lib.IntTypes.size_t",
"Prims.l_and",
"Prims.b2t",
"Prims.op_LessThan",
"Lib.IntTypes.v",
"Lib.IntTypes.U32",
"Lib.IntTypes.PUB",
"Prims.op_LessThanOrEqual",
"FStar.Mul.op_Star",
"Lib.IntTypes.numbytes",
"Hacl.Bignum.Definitions.blocks",
"Lib.IntTypes.size",
"Lib.IntTypes.max_size_t",
"Lib.Buffer.lbuffer",
"Lib.IntTypes.uint8",
"Hacl.Bignum.Definitions.lbignum",
"Prims.unit",
"FStar.Monotonic.HyperStack.mem",
"Lib.Buffer.live",
"Lib.Buffer.MUT",
"Hacl.Bignum.Definitions.limb",
"Lib.Buffer.disjoint",
"Lib.Buffer.modifies",
"Lib.Buffer.loc",
"Prims.eq2",
"Lib.Sequence.seq",
"Prims.l_or",
"Prims.nat",
"FStar.Seq.Base.length",
"Hacl.Spec.Bignum.Definitions.limb",
"Hacl.Spec.Bignum.Definitions.blocks",
"Lib.Buffer.as_seq",
"Hacl.Spec.Bignum.Convert.bn_from_bytes_le"
] | [] | module Hacl.Bignum.Convert
open FStar.HyperStack
open FStar.HyperStack.ST
open FStar.Mul
open Lib.IntTypes
open Lib.Buffer
open Lib.ByteBuffer
open Hacl.Bignum.Definitions
module ST = FStar.HyperStack.ST
module LSeq = Lib.Sequence
module S = Hacl.Spec.Bignum.Convert
#reset-options "--z3rlimit 50 --fuel 0 --ifuel 0"
inline_for_extraction noextract
val bn_from_uint:
#t:limb_t
-> len:size_t{0 < v len}
-> x:limb t
-> b:lbignum t len ->
Stack unit
(requires fun h -> live h b)
(ensures fun h0 _ h1 -> modifies (loc b) h0 h1 /\
as_seq h1 b == S.bn_from_uint (v len) x)
let bn_from_uint #t len x b =
memset b (uint #t 0) len;
b.(0ul) <- x
inline_for_extraction noextract
val bn_from_bytes_be_:
#t:limb_t
-> len:size_t{numbytes t * v len <= max_size_t}
-> b:lbuffer uint8 (size (numbytes t) *! len)
-> res:lbignum t len ->
Stack unit
(requires fun h -> live h b /\ live h res /\ disjoint res b)
(ensures fun h0 _ h1 -> modifies (loc res) h0 h1 /\
as_seq h1 res == S.bn_from_bytes_be_ (v len) (as_seq h0 b))
let bn_from_bytes_be_ #t len b res =
let h0 = ST.get () in
[@inline_let]
let spec h = S.bn_from_bytes_be_f (v len) (as_seq h b) in
fill h0 len res spec
(fun j -> uint_from_bytes_be (sub b ((len -! j -! 1ul) *! (size (numbytes t))) (size (numbytes t))))
inline_for_extraction noextract
let bn_from_bytes_be_st (t:limb_t) =
len:size_t{0 < v len /\ numbytes t * v (blocks len (size (numbytes t))) <= max_size_t}
-> b:lbuffer uint8 len
-> res:lbignum t (blocks len (size (numbytes t))) ->
Stack unit
(requires fun h -> live h b /\ live h res /\ disjoint res b)
(ensures fun h0 _ h1 -> modifies (loc res) h0 h1 /\
as_seq h1 res == S.bn_from_bytes_be (v len) (as_seq h0 b))
inline_for_extraction noextract
val mk_bn_from_bytes_be: #t:limb_t -> is_known_len:bool -> bn_from_bytes_be_st t
let mk_bn_from_bytes_be #t is_known_len len b res =
push_frame ();
if is_known_len then begin
[@inline_let] let numb = size (numbytes t) in
[@inline_let] let bnLen = blocks len numb in
[@inline_let] let tmpLen = numb *! bnLen in
if tmpLen =. len then
bn_from_bytes_be_ bnLen b res
else begin
let tmp = create tmpLen (u8 0) in
update_sub tmp (tmpLen -! len) len b;
bn_from_bytes_be_ bnLen tmp res end end
else begin
[@inline_let] let numb = size (numbytes t) in
let bnLen = blocks len numb in
let tmpLen = numb *! bnLen in
let tmp = create tmpLen (u8 0) in
update_sub tmp (tmpLen -! len) len b;
bn_from_bytes_be_ bnLen tmp res end;
pop_frame ()
[@CInline]
let bn_from_bytes_be_uint32 : bn_from_bytes_be_st U32 = mk_bn_from_bytes_be #U32 false
let bn_from_bytes_be_uint64 : bn_from_bytes_be_st U64 = mk_bn_from_bytes_be #U64 false
inline_for_extraction noextract
val bn_from_bytes_be: #t:limb_t -> bn_from_bytes_be_st t
let bn_from_bytes_be #t =
match t with
| U32 -> bn_from_bytes_be_uint32
| U64 -> bn_from_bytes_be_uint64
inline_for_extraction noextract | false | true | Hacl.Bignum.Convert.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 bn_from_bytes_le_st : t: Hacl.Bignum.Definitions.limb_t -> Type0 | [] | Hacl.Bignum.Convert.bn_from_bytes_le_st | {
"file_name": "code/bignum/Hacl.Bignum.Convert.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | t: Hacl.Bignum.Definitions.limb_t -> Type0 | {
"end_col": 62,
"end_line": 111,
"start_col": 4,
"start_line": 105
} |
|
Prims.Tot | val bn_to_bytes_le: #t:_ -> len:_ -> bn_to_bytes_le_st t len | [
{
"abbrev": true,
"full_module": "Hacl.Spec.Bignum.Convert",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "Lib.Sequence",
"short_module": "LSeq"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": false,
"full_module": "Hacl.Bignum.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.ByteBuffer",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Buffer",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Bignum",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Bignum",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let bn_to_bytes_le #t =
match t with
| U32 -> bn_to_bytes_le_uint32
| U64 -> bn_to_bytes_le_uint64 | val bn_to_bytes_le: #t:_ -> len:_ -> bn_to_bytes_le_st t len
let bn_to_bytes_le #t = | false | null | false | match t with
| U32 -> bn_to_bytes_le_uint32
| U64 -> bn_to_bytes_le_uint64 | {
"checked_file": "Hacl.Bignum.Convert.fst.checked",
"dependencies": [
"prims.fst.checked",
"LowStar.Ignore.fsti.checked",
"LowStar.Buffer.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.ByteBuffer.fsti.checked",
"Lib.Buffer.fsti.checked",
"Hacl.Spec.Bignum.Convert.fst.checked",
"Hacl.Bignum.Definitions.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked"
],
"interface_file": false,
"source_file": "Hacl.Bignum.Convert.fst"
} | [
"total"
] | [
"Hacl.Bignum.Definitions.limb_t",
"Hacl.Bignum.Convert.bn_to_bytes_le_uint32",
"Hacl.Bignum.Convert.bn_to_bytes_le_uint64",
"Lib.IntTypes.size_t",
"Prims.l_and",
"Prims.b2t",
"Prims.op_LessThan",
"Lib.IntTypes.v",
"Lib.IntTypes.U32",
"Lib.IntTypes.PUB",
"Prims.op_LessThanOrEqual",
"FStar.Mul.op_Star",
"Lib.IntTypes.numbytes",
"Hacl.Bignum.Definitions.blocks",
"Lib.IntTypes.size",
"Lib.IntTypes.max_size_t",
"Hacl.Bignum.Convert.bn_to_bytes_le_st"
] | [] | module Hacl.Bignum.Convert
open FStar.HyperStack
open FStar.HyperStack.ST
open FStar.Mul
open Lib.IntTypes
open Lib.Buffer
open Lib.ByteBuffer
open Hacl.Bignum.Definitions
module ST = FStar.HyperStack.ST
module LSeq = Lib.Sequence
module S = Hacl.Spec.Bignum.Convert
#reset-options "--z3rlimit 50 --fuel 0 --ifuel 0"
inline_for_extraction noextract
val bn_from_uint:
#t:limb_t
-> len:size_t{0 < v len}
-> x:limb t
-> b:lbignum t len ->
Stack unit
(requires fun h -> live h b)
(ensures fun h0 _ h1 -> modifies (loc b) h0 h1 /\
as_seq h1 b == S.bn_from_uint (v len) x)
let bn_from_uint #t len x b =
memset b (uint #t 0) len;
b.(0ul) <- x
inline_for_extraction noextract
val bn_from_bytes_be_:
#t:limb_t
-> len:size_t{numbytes t * v len <= max_size_t}
-> b:lbuffer uint8 (size (numbytes t) *! len)
-> res:lbignum t len ->
Stack unit
(requires fun h -> live h b /\ live h res /\ disjoint res b)
(ensures fun h0 _ h1 -> modifies (loc res) h0 h1 /\
as_seq h1 res == S.bn_from_bytes_be_ (v len) (as_seq h0 b))
let bn_from_bytes_be_ #t len b res =
let h0 = ST.get () in
[@inline_let]
let spec h = S.bn_from_bytes_be_f (v len) (as_seq h b) in
fill h0 len res spec
(fun j -> uint_from_bytes_be (sub b ((len -! j -! 1ul) *! (size (numbytes t))) (size (numbytes t))))
inline_for_extraction noextract
let bn_from_bytes_be_st (t:limb_t) =
len:size_t{0 < v len /\ numbytes t * v (blocks len (size (numbytes t))) <= max_size_t}
-> b:lbuffer uint8 len
-> res:lbignum t (blocks len (size (numbytes t))) ->
Stack unit
(requires fun h -> live h b /\ live h res /\ disjoint res b)
(ensures fun h0 _ h1 -> modifies (loc res) h0 h1 /\
as_seq h1 res == S.bn_from_bytes_be (v len) (as_seq h0 b))
inline_for_extraction noextract
val mk_bn_from_bytes_be: #t:limb_t -> is_known_len:bool -> bn_from_bytes_be_st t
let mk_bn_from_bytes_be #t is_known_len len b res =
push_frame ();
if is_known_len then begin
[@inline_let] let numb = size (numbytes t) in
[@inline_let] let bnLen = blocks len numb in
[@inline_let] let tmpLen = numb *! bnLen in
if tmpLen =. len then
bn_from_bytes_be_ bnLen b res
else begin
let tmp = create tmpLen (u8 0) in
update_sub tmp (tmpLen -! len) len b;
bn_from_bytes_be_ bnLen tmp res end end
else begin
[@inline_let] let numb = size (numbytes t) in
let bnLen = blocks len numb in
let tmpLen = numb *! bnLen in
let tmp = create tmpLen (u8 0) in
update_sub tmp (tmpLen -! len) len b;
bn_from_bytes_be_ bnLen tmp res end;
pop_frame ()
[@CInline]
let bn_from_bytes_be_uint32 : bn_from_bytes_be_st U32 = mk_bn_from_bytes_be #U32 false
let bn_from_bytes_be_uint64 : bn_from_bytes_be_st U64 = mk_bn_from_bytes_be #U64 false
inline_for_extraction noextract
val bn_from_bytes_be: #t:limb_t -> bn_from_bytes_be_st t
let bn_from_bytes_be #t =
match t with
| U32 -> bn_from_bytes_be_uint32
| U64 -> bn_from_bytes_be_uint64
inline_for_extraction noextract
let bn_from_bytes_le_st (t:limb_t) =
len:size_t{0 < v len /\ numbytes t * v (blocks len (size (numbytes t))) <= max_size_t}
-> b:lbuffer uint8 len
-> res:lbignum t (blocks len (size (numbytes t))) ->
Stack unit
(requires fun h -> live h b /\ live h res /\ disjoint res b)
(ensures fun h0 _ h1 -> modifies (loc res) h0 h1 /\
as_seq h1 res == S.bn_from_bytes_le (v len) (as_seq h0 b))
inline_for_extraction noextract
val mk_bn_from_bytes_le: #t:limb_t -> is_known_len:bool -> bn_from_bytes_le_st t
let mk_bn_from_bytes_le #t is_known_len len b res =
push_frame ();
if is_known_len then begin
[@inline_let] let numb = size (numbytes t) in
[@inline_let] let bnLen = blocks len numb in
[@inline_let] let tmpLen = numb *! bnLen in
if tmpLen =. len then
uints_from_bytes_le res b
else begin
let tmp = create tmpLen (u8 0) in
update_sub tmp 0ul len b;
uints_from_bytes_le res tmp end end
else begin
[@inline_let] let numb = size (numbytes t) in
let bnLen = blocks len numb in
let tmpLen = numb *! bnLen in
let tmp = create tmpLen (u8 0) in
update_sub tmp 0ul len b;
uints_from_bytes_le res tmp end;
pop_frame ()
[@CInline]
let bn_from_bytes_le_uint32 : bn_from_bytes_le_st U32 = mk_bn_from_bytes_le #U32 false
[@CInline]
let bn_from_bytes_le_uint64 : bn_from_bytes_le_st U64 = mk_bn_from_bytes_le #U64 false
inline_for_extraction noextract
val bn_from_bytes_le: #t:limb_t -> bn_from_bytes_le_st t
let bn_from_bytes_le #t =
match t with
| U32 -> bn_from_bytes_le_uint32
| U64 -> bn_from_bytes_le_uint64
inline_for_extraction noextract
val bn_to_bytes_be_:
#t:limb_t
-> len:size_t{numbytes t * v len <= max_size_t}
-> b:lbignum t len
-> res:lbuffer uint8 (size (numbytes t) *! len) ->
Stack unit
(requires fun h -> live h b /\ live h res /\ disjoint res b)
(ensures fun h0 _ h1 -> modifies (loc res) h0 h1 /\
as_seq h1 res == S.bn_to_bytes_be_ (v len) (as_seq h0 b))
let bn_to_bytes_be_ #t len b res =
[@inline_let] let numb = size (numbytes t) in
let h0 = ST.get () in
[@ inline_let]
let a_spec (i:nat{i <= v len}) = unit in
[@ inline_let]
let spec (h:mem) = S.bn_to_bytes_be_f (v len) (as_seq h b) in
fill_blocks h0 numb len res a_spec (fun _ _ -> ()) (fun _ -> LowStar.Buffer.loc_none) spec
(fun j -> uint_to_bytes_be (sub res (j *! numb) numb) b.(len -! j -! 1ul));
norm_spec [delta_only [`%S.bn_to_bytes_be_]] (S.bn_to_bytes_be_ (v len) (as_seq h0 b))
inline_for_extraction noextract
let bn_to_bytes_be_st (t:limb_t) (len:size_t{0 < v len /\ numbytes t * v (blocks len (size (numbytes t))) <= max_size_t}) =
b:lbignum t (blocks len (size (numbytes t)))
-> res:lbuffer uint8 len ->
Stack unit
(requires fun h ->
live h b /\ live h res /\ disjoint res b)
(ensures fun h0 _ h1 -> modifies (loc res) h0 h1 /\
as_seq h1 res == S.bn_to_bytes_be (v len) (as_seq h0 b))
inline_for_extraction noextract
val mk_bn_to_bytes_be:
#t:limb_t
-> is_known_len:bool
-> len:size_t{0 < v len /\ numbytes t * v (blocks len (size (numbytes t))) <= max_size_t} ->
bn_to_bytes_be_st t len
let mk_bn_to_bytes_be #t is_known_len len b res =
push_frame ();
if is_known_len then begin
[@inline_let] let numb = size (numbytes t) in
[@inline_let] let bnLen = blocks len numb in
[@inline_let] let tmpLen = numb *! bnLen in
let tmp = create tmpLen (u8 0) in
if tmpLen =. len then begin
LowStar.Ignore.ignore tmp;
bn_to_bytes_be_ bnLen b res end
else begin
bn_to_bytes_be_ bnLen b tmp;
copy res (sub tmp (tmpLen -! len) len) end end
else begin
[@inline_let] let numb = size (numbytes t) in
let bnLen = blocks len numb in
let tmpLen = numb *! bnLen in
let tmp = create tmpLen (u8 0) in
bn_to_bytes_be_ bnLen b tmp;
copy res (sub tmp (tmpLen -! len) len) end;
pop_frame ()
[@CInline]
let bn_to_bytes_be_uint32 len : bn_to_bytes_be_st U32 len = mk_bn_to_bytes_be #U32 false len
let bn_to_bytes_be_uint64 len : bn_to_bytes_be_st U64 len = mk_bn_to_bytes_be #U64 false len
inline_for_extraction noextract
val bn_to_bytes_be: #t:_ -> len:_ -> bn_to_bytes_be_st t len
let bn_to_bytes_be #t =
match t with
| U32 -> bn_to_bytes_be_uint32
| U64 -> bn_to_bytes_be_uint64
inline_for_extraction noextract
let bn_to_bytes_le_st (t:limb_t) (len:size_t{0 < v len /\ numbytes t * v (blocks len (size (numbytes t))) <= max_size_t}) =
b:lbignum t (blocks len (size (numbytes t)))
-> res:lbuffer uint8 len ->
Stack unit
(requires fun h ->
live h b /\ live h res /\ disjoint res b)
(ensures fun h0 _ h1 -> modifies (loc res) h0 h1 /\
as_seq h1 res == S.bn_to_bytes_le (v len) (as_seq h0 b))
inline_for_extraction noextract
val mk_bn_to_bytes_le:
#t:limb_t
-> is_known_len:bool
-> len:size_t{0 < v len /\ numbytes t * v (blocks len (size (numbytes t))) <= max_size_t} ->
bn_to_bytes_le_st t len
let mk_bn_to_bytes_le #t is_known_len len b res =
push_frame ();
if is_known_len then begin
[@inline_let] let numb = size (numbytes t) in
[@inline_let] let bnLen = blocks len numb in
[@inline_let] let tmpLen = numb *! bnLen in
let tmp = create tmpLen (u8 0) in
if tmpLen =. len then begin
LowStar.Ignore.ignore tmp;
uints_to_bytes_le bnLen res b end
else begin
uints_to_bytes_le bnLen tmp b;
copy res (sub tmp 0ul len) end end
else begin
[@inline_let] let numb = size (numbytes t) in
let bnLen = blocks len numb in
let tmpLen = numb *! bnLen in
let tmp = create tmpLen (u8 0) in
uints_to_bytes_le bnLen tmp b;
copy res (sub tmp 0ul len) end;
pop_frame ()
[@CInline]
let bn_to_bytes_le_uint32 len : bn_to_bytes_le_st U32 len = mk_bn_to_bytes_le #U32 false len
[@CInline]
let bn_to_bytes_le_uint64 len : bn_to_bytes_le_st U64 len = mk_bn_to_bytes_le #U64 false len
inline_for_extraction noextract
val bn_to_bytes_le: #t:_ -> len:_ -> bn_to_bytes_le_st t len | false | false | Hacl.Bignum.Convert.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 bn_to_bytes_le: #t:_ -> len:_ -> bn_to_bytes_le_st t len | [] | Hacl.Bignum.Convert.bn_to_bytes_le | {
"file_name": "code/bignum/Hacl.Bignum.Convert.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} |
len:
Lib.IntTypes.size_t
{ 0 < Lib.IntTypes.v len /\
Lib.IntTypes.numbytes t *
Lib.IntTypes.v (Hacl.Bignum.Definitions.blocks len
(Lib.IntTypes.size (Lib.IntTypes.numbytes t))) <=
Lib.IntTypes.max_size_t }
-> Hacl.Bignum.Convert.bn_to_bytes_le_st t len | {
"end_col": 32,
"end_line": 280,
"start_col": 2,
"start_line": 278
} |
Prims.Tot | val bn_to_bytes_le_uint64 (len: _) : bn_to_bytes_le_st U64 len | [
{
"abbrev": true,
"full_module": "Hacl.Spec.Bignum.Convert",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "Lib.Sequence",
"short_module": "LSeq"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": false,
"full_module": "Hacl.Bignum.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.ByteBuffer",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Buffer",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Bignum",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Bignum",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let bn_to_bytes_le_uint64 len : bn_to_bytes_le_st U64 len = mk_bn_to_bytes_le #U64 false len | val bn_to_bytes_le_uint64 (len: _) : bn_to_bytes_le_st U64 len
let bn_to_bytes_le_uint64 len : bn_to_bytes_le_st U64 len = | false | null | false | mk_bn_to_bytes_le #U64 false len | {
"checked_file": "Hacl.Bignum.Convert.fst.checked",
"dependencies": [
"prims.fst.checked",
"LowStar.Ignore.fsti.checked",
"LowStar.Buffer.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.ByteBuffer.fsti.checked",
"Lib.Buffer.fsti.checked",
"Hacl.Spec.Bignum.Convert.fst.checked",
"Hacl.Bignum.Definitions.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked"
],
"interface_file": false,
"source_file": "Hacl.Bignum.Convert.fst"
} | [
"total"
] | [
"Lib.IntTypes.size_t",
"Prims.l_and",
"Prims.b2t",
"Prims.op_LessThan",
"Lib.IntTypes.v",
"Lib.IntTypes.U32",
"Lib.IntTypes.PUB",
"Prims.op_LessThanOrEqual",
"FStar.Mul.op_Star",
"Lib.IntTypes.numbytes",
"Lib.IntTypes.U64",
"Hacl.Bignum.Definitions.blocks",
"Lib.IntTypes.size",
"Lib.IntTypes.max_size_t",
"Hacl.Bignum.Convert.mk_bn_to_bytes_le",
"Hacl.Bignum.Convert.bn_to_bytes_le_st"
] | [] | module Hacl.Bignum.Convert
open FStar.HyperStack
open FStar.HyperStack.ST
open FStar.Mul
open Lib.IntTypes
open Lib.Buffer
open Lib.ByteBuffer
open Hacl.Bignum.Definitions
module ST = FStar.HyperStack.ST
module LSeq = Lib.Sequence
module S = Hacl.Spec.Bignum.Convert
#reset-options "--z3rlimit 50 --fuel 0 --ifuel 0"
inline_for_extraction noextract
val bn_from_uint:
#t:limb_t
-> len:size_t{0 < v len}
-> x:limb t
-> b:lbignum t len ->
Stack unit
(requires fun h -> live h b)
(ensures fun h0 _ h1 -> modifies (loc b) h0 h1 /\
as_seq h1 b == S.bn_from_uint (v len) x)
let bn_from_uint #t len x b =
memset b (uint #t 0) len;
b.(0ul) <- x
inline_for_extraction noextract
val bn_from_bytes_be_:
#t:limb_t
-> len:size_t{numbytes t * v len <= max_size_t}
-> b:lbuffer uint8 (size (numbytes t) *! len)
-> res:lbignum t len ->
Stack unit
(requires fun h -> live h b /\ live h res /\ disjoint res b)
(ensures fun h0 _ h1 -> modifies (loc res) h0 h1 /\
as_seq h1 res == S.bn_from_bytes_be_ (v len) (as_seq h0 b))
let bn_from_bytes_be_ #t len b res =
let h0 = ST.get () in
[@inline_let]
let spec h = S.bn_from_bytes_be_f (v len) (as_seq h b) in
fill h0 len res spec
(fun j -> uint_from_bytes_be (sub b ((len -! j -! 1ul) *! (size (numbytes t))) (size (numbytes t))))
inline_for_extraction noextract
let bn_from_bytes_be_st (t:limb_t) =
len:size_t{0 < v len /\ numbytes t * v (blocks len (size (numbytes t))) <= max_size_t}
-> b:lbuffer uint8 len
-> res:lbignum t (blocks len (size (numbytes t))) ->
Stack unit
(requires fun h -> live h b /\ live h res /\ disjoint res b)
(ensures fun h0 _ h1 -> modifies (loc res) h0 h1 /\
as_seq h1 res == S.bn_from_bytes_be (v len) (as_seq h0 b))
inline_for_extraction noextract
val mk_bn_from_bytes_be: #t:limb_t -> is_known_len:bool -> bn_from_bytes_be_st t
let mk_bn_from_bytes_be #t is_known_len len b res =
push_frame ();
if is_known_len then begin
[@inline_let] let numb = size (numbytes t) in
[@inline_let] let bnLen = blocks len numb in
[@inline_let] let tmpLen = numb *! bnLen in
if tmpLen =. len then
bn_from_bytes_be_ bnLen b res
else begin
let tmp = create tmpLen (u8 0) in
update_sub tmp (tmpLen -! len) len b;
bn_from_bytes_be_ bnLen tmp res end end
else begin
[@inline_let] let numb = size (numbytes t) in
let bnLen = blocks len numb in
let tmpLen = numb *! bnLen in
let tmp = create tmpLen (u8 0) in
update_sub tmp (tmpLen -! len) len b;
bn_from_bytes_be_ bnLen tmp res end;
pop_frame ()
[@CInline]
let bn_from_bytes_be_uint32 : bn_from_bytes_be_st U32 = mk_bn_from_bytes_be #U32 false
let bn_from_bytes_be_uint64 : bn_from_bytes_be_st U64 = mk_bn_from_bytes_be #U64 false
inline_for_extraction noextract
val bn_from_bytes_be: #t:limb_t -> bn_from_bytes_be_st t
let bn_from_bytes_be #t =
match t with
| U32 -> bn_from_bytes_be_uint32
| U64 -> bn_from_bytes_be_uint64
inline_for_extraction noextract
let bn_from_bytes_le_st (t:limb_t) =
len:size_t{0 < v len /\ numbytes t * v (blocks len (size (numbytes t))) <= max_size_t}
-> b:lbuffer uint8 len
-> res:lbignum t (blocks len (size (numbytes t))) ->
Stack unit
(requires fun h -> live h b /\ live h res /\ disjoint res b)
(ensures fun h0 _ h1 -> modifies (loc res) h0 h1 /\
as_seq h1 res == S.bn_from_bytes_le (v len) (as_seq h0 b))
inline_for_extraction noextract
val mk_bn_from_bytes_le: #t:limb_t -> is_known_len:bool -> bn_from_bytes_le_st t
let mk_bn_from_bytes_le #t is_known_len len b res =
push_frame ();
if is_known_len then begin
[@inline_let] let numb = size (numbytes t) in
[@inline_let] let bnLen = blocks len numb in
[@inline_let] let tmpLen = numb *! bnLen in
if tmpLen =. len then
uints_from_bytes_le res b
else begin
let tmp = create tmpLen (u8 0) in
update_sub tmp 0ul len b;
uints_from_bytes_le res tmp end end
else begin
[@inline_let] let numb = size (numbytes t) in
let bnLen = blocks len numb in
let tmpLen = numb *! bnLen in
let tmp = create tmpLen (u8 0) in
update_sub tmp 0ul len b;
uints_from_bytes_le res tmp end;
pop_frame ()
[@CInline]
let bn_from_bytes_le_uint32 : bn_from_bytes_le_st U32 = mk_bn_from_bytes_le #U32 false
[@CInline]
let bn_from_bytes_le_uint64 : bn_from_bytes_le_st U64 = mk_bn_from_bytes_le #U64 false
inline_for_extraction noextract
val bn_from_bytes_le: #t:limb_t -> bn_from_bytes_le_st t
let bn_from_bytes_le #t =
match t with
| U32 -> bn_from_bytes_le_uint32
| U64 -> bn_from_bytes_le_uint64
inline_for_extraction noextract
val bn_to_bytes_be_:
#t:limb_t
-> len:size_t{numbytes t * v len <= max_size_t}
-> b:lbignum t len
-> res:lbuffer uint8 (size (numbytes t) *! len) ->
Stack unit
(requires fun h -> live h b /\ live h res /\ disjoint res b)
(ensures fun h0 _ h1 -> modifies (loc res) h0 h1 /\
as_seq h1 res == S.bn_to_bytes_be_ (v len) (as_seq h0 b))
let bn_to_bytes_be_ #t len b res =
[@inline_let] let numb = size (numbytes t) in
let h0 = ST.get () in
[@ inline_let]
let a_spec (i:nat{i <= v len}) = unit in
[@ inline_let]
let spec (h:mem) = S.bn_to_bytes_be_f (v len) (as_seq h b) in
fill_blocks h0 numb len res a_spec (fun _ _ -> ()) (fun _ -> LowStar.Buffer.loc_none) spec
(fun j -> uint_to_bytes_be (sub res (j *! numb) numb) b.(len -! j -! 1ul));
norm_spec [delta_only [`%S.bn_to_bytes_be_]] (S.bn_to_bytes_be_ (v len) (as_seq h0 b))
inline_for_extraction noextract
let bn_to_bytes_be_st (t:limb_t) (len:size_t{0 < v len /\ numbytes t * v (blocks len (size (numbytes t))) <= max_size_t}) =
b:lbignum t (blocks len (size (numbytes t)))
-> res:lbuffer uint8 len ->
Stack unit
(requires fun h ->
live h b /\ live h res /\ disjoint res b)
(ensures fun h0 _ h1 -> modifies (loc res) h0 h1 /\
as_seq h1 res == S.bn_to_bytes_be (v len) (as_seq h0 b))
inline_for_extraction noextract
val mk_bn_to_bytes_be:
#t:limb_t
-> is_known_len:bool
-> len:size_t{0 < v len /\ numbytes t * v (blocks len (size (numbytes t))) <= max_size_t} ->
bn_to_bytes_be_st t len
let mk_bn_to_bytes_be #t is_known_len len b res =
push_frame ();
if is_known_len then begin
[@inline_let] let numb = size (numbytes t) in
[@inline_let] let bnLen = blocks len numb in
[@inline_let] let tmpLen = numb *! bnLen in
let tmp = create tmpLen (u8 0) in
if tmpLen =. len then begin
LowStar.Ignore.ignore tmp;
bn_to_bytes_be_ bnLen b res end
else begin
bn_to_bytes_be_ bnLen b tmp;
copy res (sub tmp (tmpLen -! len) len) end end
else begin
[@inline_let] let numb = size (numbytes t) in
let bnLen = blocks len numb in
let tmpLen = numb *! bnLen in
let tmp = create tmpLen (u8 0) in
bn_to_bytes_be_ bnLen b tmp;
copy res (sub tmp (tmpLen -! len) len) end;
pop_frame ()
[@CInline]
let bn_to_bytes_be_uint32 len : bn_to_bytes_be_st U32 len = mk_bn_to_bytes_be #U32 false len
let bn_to_bytes_be_uint64 len : bn_to_bytes_be_st U64 len = mk_bn_to_bytes_be #U64 false len
inline_for_extraction noextract
val bn_to_bytes_be: #t:_ -> len:_ -> bn_to_bytes_be_st t len
let bn_to_bytes_be #t =
match t with
| U32 -> bn_to_bytes_be_uint32
| U64 -> bn_to_bytes_be_uint64
inline_for_extraction noextract
let bn_to_bytes_le_st (t:limb_t) (len:size_t{0 < v len /\ numbytes t * v (blocks len (size (numbytes t))) <= max_size_t}) =
b:lbignum t (blocks len (size (numbytes t)))
-> res:lbuffer uint8 len ->
Stack unit
(requires fun h ->
live h b /\ live h res /\ disjoint res b)
(ensures fun h0 _ h1 -> modifies (loc res) h0 h1 /\
as_seq h1 res == S.bn_to_bytes_le (v len) (as_seq h0 b))
inline_for_extraction noextract
val mk_bn_to_bytes_le:
#t:limb_t
-> is_known_len:bool
-> len:size_t{0 < v len /\ numbytes t * v (blocks len (size (numbytes t))) <= max_size_t} ->
bn_to_bytes_le_st t len
let mk_bn_to_bytes_le #t is_known_len len b res =
push_frame ();
if is_known_len then begin
[@inline_let] let numb = size (numbytes t) in
[@inline_let] let bnLen = blocks len numb in
[@inline_let] let tmpLen = numb *! bnLen in
let tmp = create tmpLen (u8 0) in
if tmpLen =. len then begin
LowStar.Ignore.ignore tmp;
uints_to_bytes_le bnLen res b end
else begin
uints_to_bytes_le bnLen tmp b;
copy res (sub tmp 0ul len) end end
else begin
[@inline_let] let numb = size (numbytes t) in
let bnLen = blocks len numb in
let tmpLen = numb *! bnLen in
let tmp = create tmpLen (u8 0) in
uints_to_bytes_le bnLen tmp b;
copy res (sub tmp 0ul len) end;
pop_frame ()
[@CInline]
let bn_to_bytes_le_uint32 len : bn_to_bytes_le_st U32 len = mk_bn_to_bytes_le #U32 false len | false | false | Hacl.Bignum.Convert.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 bn_to_bytes_le_uint64 (len: _) : bn_to_bytes_le_st U64 len | [] | Hacl.Bignum.Convert.bn_to_bytes_le_uint64 | {
"file_name": "code/bignum/Hacl.Bignum.Convert.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} |
len:
Lib.IntTypes.size_t
{ 0 < Lib.IntTypes.v len /\
Lib.IntTypes.numbytes Lib.IntTypes.U64 *
Lib.IntTypes.v (Hacl.Bignum.Definitions.blocks len
(Lib.IntTypes.size (Lib.IntTypes.numbytes Lib.IntTypes.U64))) <=
Lib.IntTypes.max_size_t }
-> Hacl.Bignum.Convert.bn_to_bytes_le_st Lib.IntTypes.U64 len | {
"end_col": 92,
"end_line": 272,
"start_col": 60,
"start_line": 272
} |
Prims.Tot | [
{
"abbrev": true,
"full_module": "Hacl.Spec.Bignum.Convert",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "Lib.Sequence",
"short_module": "LSeq"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": false,
"full_module": "Hacl.Bignum.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.ByteBuffer",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Buffer",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Bignum",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Bignum",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let bn_to_bytes_le_st (t:limb_t) (len:size_t{0 < v len /\ numbytes t * v (blocks len (size (numbytes t))) <= max_size_t}) =
b:lbignum t (blocks len (size (numbytes t)))
-> res:lbuffer uint8 len ->
Stack unit
(requires fun h ->
live h b /\ live h res /\ disjoint res b)
(ensures fun h0 _ h1 -> modifies (loc res) h0 h1 /\
as_seq h1 res == S.bn_to_bytes_le (v len) (as_seq h0 b)) | let bn_to_bytes_le_st
(t: limb_t)
(len: size_t{0 < v len /\ numbytes t * v (blocks len (size (numbytes t))) <= max_size_t})
= | false | null | false | b: lbignum t (blocks len (size (numbytes t))) -> res: lbuffer uint8 len
-> Stack unit
(requires fun h -> live h b /\ live h res /\ disjoint res b)
(ensures
fun h0 _ h1 ->
modifies (loc res) h0 h1 /\ as_seq h1 res == S.bn_to_bytes_le (v len) (as_seq h0 b)) | {
"checked_file": "Hacl.Bignum.Convert.fst.checked",
"dependencies": [
"prims.fst.checked",
"LowStar.Ignore.fsti.checked",
"LowStar.Buffer.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.ByteBuffer.fsti.checked",
"Lib.Buffer.fsti.checked",
"Hacl.Spec.Bignum.Convert.fst.checked",
"Hacl.Bignum.Definitions.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked"
],
"interface_file": false,
"source_file": "Hacl.Bignum.Convert.fst"
} | [
"total"
] | [
"Hacl.Bignum.Definitions.limb_t",
"Lib.IntTypes.size_t",
"Prims.l_and",
"Prims.b2t",
"Prims.op_LessThan",
"Lib.IntTypes.v",
"Lib.IntTypes.U32",
"Lib.IntTypes.PUB",
"Prims.op_LessThanOrEqual",
"FStar.Mul.op_Star",
"Lib.IntTypes.numbytes",
"Hacl.Bignum.Definitions.blocks",
"Lib.IntTypes.size",
"Lib.IntTypes.max_size_t",
"Hacl.Bignum.Definitions.lbignum",
"Lib.Buffer.lbuffer",
"Lib.IntTypes.uint8",
"Prims.unit",
"FStar.Monotonic.HyperStack.mem",
"Lib.Buffer.live",
"Lib.Buffer.MUT",
"Hacl.Bignum.Definitions.limb",
"Lib.Buffer.disjoint",
"Lib.Buffer.modifies",
"Lib.Buffer.loc",
"Prims.eq2",
"Lib.Sequence.lseq",
"Lib.Buffer.as_seq",
"Hacl.Spec.Bignum.Convert.bn_to_bytes_le"
] | [] | module Hacl.Bignum.Convert
open FStar.HyperStack
open FStar.HyperStack.ST
open FStar.Mul
open Lib.IntTypes
open Lib.Buffer
open Lib.ByteBuffer
open Hacl.Bignum.Definitions
module ST = FStar.HyperStack.ST
module LSeq = Lib.Sequence
module S = Hacl.Spec.Bignum.Convert
#reset-options "--z3rlimit 50 --fuel 0 --ifuel 0"
inline_for_extraction noextract
val bn_from_uint:
#t:limb_t
-> len:size_t{0 < v len}
-> x:limb t
-> b:lbignum t len ->
Stack unit
(requires fun h -> live h b)
(ensures fun h0 _ h1 -> modifies (loc b) h0 h1 /\
as_seq h1 b == S.bn_from_uint (v len) x)
let bn_from_uint #t len x b =
memset b (uint #t 0) len;
b.(0ul) <- x
inline_for_extraction noextract
val bn_from_bytes_be_:
#t:limb_t
-> len:size_t{numbytes t * v len <= max_size_t}
-> b:lbuffer uint8 (size (numbytes t) *! len)
-> res:lbignum t len ->
Stack unit
(requires fun h -> live h b /\ live h res /\ disjoint res b)
(ensures fun h0 _ h1 -> modifies (loc res) h0 h1 /\
as_seq h1 res == S.bn_from_bytes_be_ (v len) (as_seq h0 b))
let bn_from_bytes_be_ #t len b res =
let h0 = ST.get () in
[@inline_let]
let spec h = S.bn_from_bytes_be_f (v len) (as_seq h b) in
fill h0 len res spec
(fun j -> uint_from_bytes_be (sub b ((len -! j -! 1ul) *! (size (numbytes t))) (size (numbytes t))))
inline_for_extraction noextract
let bn_from_bytes_be_st (t:limb_t) =
len:size_t{0 < v len /\ numbytes t * v (blocks len (size (numbytes t))) <= max_size_t}
-> b:lbuffer uint8 len
-> res:lbignum t (blocks len (size (numbytes t))) ->
Stack unit
(requires fun h -> live h b /\ live h res /\ disjoint res b)
(ensures fun h0 _ h1 -> modifies (loc res) h0 h1 /\
as_seq h1 res == S.bn_from_bytes_be (v len) (as_seq h0 b))
inline_for_extraction noextract
val mk_bn_from_bytes_be: #t:limb_t -> is_known_len:bool -> bn_from_bytes_be_st t
let mk_bn_from_bytes_be #t is_known_len len b res =
push_frame ();
if is_known_len then begin
[@inline_let] let numb = size (numbytes t) in
[@inline_let] let bnLen = blocks len numb in
[@inline_let] let tmpLen = numb *! bnLen in
if tmpLen =. len then
bn_from_bytes_be_ bnLen b res
else begin
let tmp = create tmpLen (u8 0) in
update_sub tmp (tmpLen -! len) len b;
bn_from_bytes_be_ bnLen tmp res end end
else begin
[@inline_let] let numb = size (numbytes t) in
let bnLen = blocks len numb in
let tmpLen = numb *! bnLen in
let tmp = create tmpLen (u8 0) in
update_sub tmp (tmpLen -! len) len b;
bn_from_bytes_be_ bnLen tmp res end;
pop_frame ()
[@CInline]
let bn_from_bytes_be_uint32 : bn_from_bytes_be_st U32 = mk_bn_from_bytes_be #U32 false
let bn_from_bytes_be_uint64 : bn_from_bytes_be_st U64 = mk_bn_from_bytes_be #U64 false
inline_for_extraction noextract
val bn_from_bytes_be: #t:limb_t -> bn_from_bytes_be_st t
let bn_from_bytes_be #t =
match t with
| U32 -> bn_from_bytes_be_uint32
| U64 -> bn_from_bytes_be_uint64
inline_for_extraction noextract
let bn_from_bytes_le_st (t:limb_t) =
len:size_t{0 < v len /\ numbytes t * v (blocks len (size (numbytes t))) <= max_size_t}
-> b:lbuffer uint8 len
-> res:lbignum t (blocks len (size (numbytes t))) ->
Stack unit
(requires fun h -> live h b /\ live h res /\ disjoint res b)
(ensures fun h0 _ h1 -> modifies (loc res) h0 h1 /\
as_seq h1 res == S.bn_from_bytes_le (v len) (as_seq h0 b))
inline_for_extraction noextract
val mk_bn_from_bytes_le: #t:limb_t -> is_known_len:bool -> bn_from_bytes_le_st t
let mk_bn_from_bytes_le #t is_known_len len b res =
push_frame ();
if is_known_len then begin
[@inline_let] let numb = size (numbytes t) in
[@inline_let] let bnLen = blocks len numb in
[@inline_let] let tmpLen = numb *! bnLen in
if tmpLen =. len then
uints_from_bytes_le res b
else begin
let tmp = create tmpLen (u8 0) in
update_sub tmp 0ul len b;
uints_from_bytes_le res tmp end end
else begin
[@inline_let] let numb = size (numbytes t) in
let bnLen = blocks len numb in
let tmpLen = numb *! bnLen in
let tmp = create tmpLen (u8 0) in
update_sub tmp 0ul len b;
uints_from_bytes_le res tmp end;
pop_frame ()
[@CInline]
let bn_from_bytes_le_uint32 : bn_from_bytes_le_st U32 = mk_bn_from_bytes_le #U32 false
[@CInline]
let bn_from_bytes_le_uint64 : bn_from_bytes_le_st U64 = mk_bn_from_bytes_le #U64 false
inline_for_extraction noextract
val bn_from_bytes_le: #t:limb_t -> bn_from_bytes_le_st t
let bn_from_bytes_le #t =
match t with
| U32 -> bn_from_bytes_le_uint32
| U64 -> bn_from_bytes_le_uint64
inline_for_extraction noextract
val bn_to_bytes_be_:
#t:limb_t
-> len:size_t{numbytes t * v len <= max_size_t}
-> b:lbignum t len
-> res:lbuffer uint8 (size (numbytes t) *! len) ->
Stack unit
(requires fun h -> live h b /\ live h res /\ disjoint res b)
(ensures fun h0 _ h1 -> modifies (loc res) h0 h1 /\
as_seq h1 res == S.bn_to_bytes_be_ (v len) (as_seq h0 b))
let bn_to_bytes_be_ #t len b res =
[@inline_let] let numb = size (numbytes t) in
let h0 = ST.get () in
[@ inline_let]
let a_spec (i:nat{i <= v len}) = unit in
[@ inline_let]
let spec (h:mem) = S.bn_to_bytes_be_f (v len) (as_seq h b) in
fill_blocks h0 numb len res a_spec (fun _ _ -> ()) (fun _ -> LowStar.Buffer.loc_none) spec
(fun j -> uint_to_bytes_be (sub res (j *! numb) numb) b.(len -! j -! 1ul));
norm_spec [delta_only [`%S.bn_to_bytes_be_]] (S.bn_to_bytes_be_ (v len) (as_seq h0 b))
inline_for_extraction noextract
let bn_to_bytes_be_st (t:limb_t) (len:size_t{0 < v len /\ numbytes t * v (blocks len (size (numbytes t))) <= max_size_t}) =
b:lbignum t (blocks len (size (numbytes t)))
-> res:lbuffer uint8 len ->
Stack unit
(requires fun h ->
live h b /\ live h res /\ disjoint res b)
(ensures fun h0 _ h1 -> modifies (loc res) h0 h1 /\
as_seq h1 res == S.bn_to_bytes_be (v len) (as_seq h0 b))
inline_for_extraction noextract
val mk_bn_to_bytes_be:
#t:limb_t
-> is_known_len:bool
-> len:size_t{0 < v len /\ numbytes t * v (blocks len (size (numbytes t))) <= max_size_t} ->
bn_to_bytes_be_st t len
let mk_bn_to_bytes_be #t is_known_len len b res =
push_frame ();
if is_known_len then begin
[@inline_let] let numb = size (numbytes t) in
[@inline_let] let bnLen = blocks len numb in
[@inline_let] let tmpLen = numb *! bnLen in
let tmp = create tmpLen (u8 0) in
if tmpLen =. len then begin
LowStar.Ignore.ignore tmp;
bn_to_bytes_be_ bnLen b res end
else begin
bn_to_bytes_be_ bnLen b tmp;
copy res (sub tmp (tmpLen -! len) len) end end
else begin
[@inline_let] let numb = size (numbytes t) in
let bnLen = blocks len numb in
let tmpLen = numb *! bnLen in
let tmp = create tmpLen (u8 0) in
bn_to_bytes_be_ bnLen b tmp;
copy res (sub tmp (tmpLen -! len) len) end;
pop_frame ()
[@CInline]
let bn_to_bytes_be_uint32 len : bn_to_bytes_be_st U32 len = mk_bn_to_bytes_be #U32 false len
let bn_to_bytes_be_uint64 len : bn_to_bytes_be_st U64 len = mk_bn_to_bytes_be #U64 false len
inline_for_extraction noextract
val bn_to_bytes_be: #t:_ -> len:_ -> bn_to_bytes_be_st t len
let bn_to_bytes_be #t =
match t with
| U32 -> bn_to_bytes_be_uint32
| U64 -> bn_to_bytes_be_uint64
inline_for_extraction noextract | false | false | Hacl.Bignum.Convert.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 bn_to_bytes_le_st : t: Hacl.Bignum.Definitions.limb_t ->
len:
Lib.IntTypes.size_t
{ 0 < Lib.IntTypes.v len /\
Lib.IntTypes.numbytes t *
Lib.IntTypes.v (Hacl.Bignum.Definitions.blocks len
(Lib.IntTypes.size (Lib.IntTypes.numbytes t))) <=
Lib.IntTypes.max_size_t }
-> Type0 | [] | Hacl.Bignum.Convert.bn_to_bytes_le_st | {
"file_name": "code/bignum/Hacl.Bignum.Convert.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} |
t: Hacl.Bignum.Definitions.limb_t ->
len:
Lib.IntTypes.size_t
{ 0 < Lib.IntTypes.v len /\
Lib.IntTypes.numbytes t *
Lib.IntTypes.v (Hacl.Bignum.Definitions.blocks len
(Lib.IntTypes.size (Lib.IntTypes.numbytes t))) <=
Lib.IntTypes.max_size_t }
-> Type0 | {
"end_col": 60,
"end_line": 236,
"start_col": 4,
"start_line": 230
} |
|
Prims.Tot | val bn_to_bytes_be: #t:_ -> len:_ -> bn_to_bytes_be_st t len | [
{
"abbrev": true,
"full_module": "Hacl.Spec.Bignum.Convert",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "Lib.Sequence",
"short_module": "LSeq"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": false,
"full_module": "Hacl.Bignum.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.ByteBuffer",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Buffer",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Bignum",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Bignum",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let bn_to_bytes_be #t =
match t with
| U32 -> bn_to_bytes_be_uint32
| U64 -> bn_to_bytes_be_uint64 | val bn_to_bytes_be: #t:_ -> len:_ -> bn_to_bytes_be_st t len
let bn_to_bytes_be #t = | false | null | false | match t with
| U32 -> bn_to_bytes_be_uint32
| U64 -> bn_to_bytes_be_uint64 | {
"checked_file": "Hacl.Bignum.Convert.fst.checked",
"dependencies": [
"prims.fst.checked",
"LowStar.Ignore.fsti.checked",
"LowStar.Buffer.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.ByteBuffer.fsti.checked",
"Lib.Buffer.fsti.checked",
"Hacl.Spec.Bignum.Convert.fst.checked",
"Hacl.Bignum.Definitions.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked"
],
"interface_file": false,
"source_file": "Hacl.Bignum.Convert.fst"
} | [
"total"
] | [
"Hacl.Bignum.Definitions.limb_t",
"Hacl.Bignum.Convert.bn_to_bytes_be_uint32",
"Hacl.Bignum.Convert.bn_to_bytes_be_uint64",
"Lib.IntTypes.size_t",
"Prims.l_and",
"Prims.b2t",
"Prims.op_LessThan",
"Lib.IntTypes.v",
"Lib.IntTypes.U32",
"Lib.IntTypes.PUB",
"Prims.op_LessThanOrEqual",
"FStar.Mul.op_Star",
"Lib.IntTypes.numbytes",
"Hacl.Bignum.Definitions.blocks",
"Lib.IntTypes.size",
"Lib.IntTypes.max_size_t",
"Hacl.Bignum.Convert.bn_to_bytes_be_st"
] | [] | module Hacl.Bignum.Convert
open FStar.HyperStack
open FStar.HyperStack.ST
open FStar.Mul
open Lib.IntTypes
open Lib.Buffer
open Lib.ByteBuffer
open Hacl.Bignum.Definitions
module ST = FStar.HyperStack.ST
module LSeq = Lib.Sequence
module S = Hacl.Spec.Bignum.Convert
#reset-options "--z3rlimit 50 --fuel 0 --ifuel 0"
inline_for_extraction noextract
val bn_from_uint:
#t:limb_t
-> len:size_t{0 < v len}
-> x:limb t
-> b:lbignum t len ->
Stack unit
(requires fun h -> live h b)
(ensures fun h0 _ h1 -> modifies (loc b) h0 h1 /\
as_seq h1 b == S.bn_from_uint (v len) x)
let bn_from_uint #t len x b =
memset b (uint #t 0) len;
b.(0ul) <- x
inline_for_extraction noextract
val bn_from_bytes_be_:
#t:limb_t
-> len:size_t{numbytes t * v len <= max_size_t}
-> b:lbuffer uint8 (size (numbytes t) *! len)
-> res:lbignum t len ->
Stack unit
(requires fun h -> live h b /\ live h res /\ disjoint res b)
(ensures fun h0 _ h1 -> modifies (loc res) h0 h1 /\
as_seq h1 res == S.bn_from_bytes_be_ (v len) (as_seq h0 b))
let bn_from_bytes_be_ #t len b res =
let h0 = ST.get () in
[@inline_let]
let spec h = S.bn_from_bytes_be_f (v len) (as_seq h b) in
fill h0 len res spec
(fun j -> uint_from_bytes_be (sub b ((len -! j -! 1ul) *! (size (numbytes t))) (size (numbytes t))))
inline_for_extraction noextract
let bn_from_bytes_be_st (t:limb_t) =
len:size_t{0 < v len /\ numbytes t * v (blocks len (size (numbytes t))) <= max_size_t}
-> b:lbuffer uint8 len
-> res:lbignum t (blocks len (size (numbytes t))) ->
Stack unit
(requires fun h -> live h b /\ live h res /\ disjoint res b)
(ensures fun h0 _ h1 -> modifies (loc res) h0 h1 /\
as_seq h1 res == S.bn_from_bytes_be (v len) (as_seq h0 b))
inline_for_extraction noextract
val mk_bn_from_bytes_be: #t:limb_t -> is_known_len:bool -> bn_from_bytes_be_st t
let mk_bn_from_bytes_be #t is_known_len len b res =
push_frame ();
if is_known_len then begin
[@inline_let] let numb = size (numbytes t) in
[@inline_let] let bnLen = blocks len numb in
[@inline_let] let tmpLen = numb *! bnLen in
if tmpLen =. len then
bn_from_bytes_be_ bnLen b res
else begin
let tmp = create tmpLen (u8 0) in
update_sub tmp (tmpLen -! len) len b;
bn_from_bytes_be_ bnLen tmp res end end
else begin
[@inline_let] let numb = size (numbytes t) in
let bnLen = blocks len numb in
let tmpLen = numb *! bnLen in
let tmp = create tmpLen (u8 0) in
update_sub tmp (tmpLen -! len) len b;
bn_from_bytes_be_ bnLen tmp res end;
pop_frame ()
[@CInline]
let bn_from_bytes_be_uint32 : bn_from_bytes_be_st U32 = mk_bn_from_bytes_be #U32 false
let bn_from_bytes_be_uint64 : bn_from_bytes_be_st U64 = mk_bn_from_bytes_be #U64 false
inline_for_extraction noextract
val bn_from_bytes_be: #t:limb_t -> bn_from_bytes_be_st t
let bn_from_bytes_be #t =
match t with
| U32 -> bn_from_bytes_be_uint32
| U64 -> bn_from_bytes_be_uint64
inline_for_extraction noextract
let bn_from_bytes_le_st (t:limb_t) =
len:size_t{0 < v len /\ numbytes t * v (blocks len (size (numbytes t))) <= max_size_t}
-> b:lbuffer uint8 len
-> res:lbignum t (blocks len (size (numbytes t))) ->
Stack unit
(requires fun h -> live h b /\ live h res /\ disjoint res b)
(ensures fun h0 _ h1 -> modifies (loc res) h0 h1 /\
as_seq h1 res == S.bn_from_bytes_le (v len) (as_seq h0 b))
inline_for_extraction noextract
val mk_bn_from_bytes_le: #t:limb_t -> is_known_len:bool -> bn_from_bytes_le_st t
let mk_bn_from_bytes_le #t is_known_len len b res =
push_frame ();
if is_known_len then begin
[@inline_let] let numb = size (numbytes t) in
[@inline_let] let bnLen = blocks len numb in
[@inline_let] let tmpLen = numb *! bnLen in
if tmpLen =. len then
uints_from_bytes_le res b
else begin
let tmp = create tmpLen (u8 0) in
update_sub tmp 0ul len b;
uints_from_bytes_le res tmp end end
else begin
[@inline_let] let numb = size (numbytes t) in
let bnLen = blocks len numb in
let tmpLen = numb *! bnLen in
let tmp = create tmpLen (u8 0) in
update_sub tmp 0ul len b;
uints_from_bytes_le res tmp end;
pop_frame ()
[@CInline]
let bn_from_bytes_le_uint32 : bn_from_bytes_le_st U32 = mk_bn_from_bytes_le #U32 false
[@CInline]
let bn_from_bytes_le_uint64 : bn_from_bytes_le_st U64 = mk_bn_from_bytes_le #U64 false
inline_for_extraction noextract
val bn_from_bytes_le: #t:limb_t -> bn_from_bytes_le_st t
let bn_from_bytes_le #t =
match t with
| U32 -> bn_from_bytes_le_uint32
| U64 -> bn_from_bytes_le_uint64
inline_for_extraction noextract
val bn_to_bytes_be_:
#t:limb_t
-> len:size_t{numbytes t * v len <= max_size_t}
-> b:lbignum t len
-> res:lbuffer uint8 (size (numbytes t) *! len) ->
Stack unit
(requires fun h -> live h b /\ live h res /\ disjoint res b)
(ensures fun h0 _ h1 -> modifies (loc res) h0 h1 /\
as_seq h1 res == S.bn_to_bytes_be_ (v len) (as_seq h0 b))
let bn_to_bytes_be_ #t len b res =
[@inline_let] let numb = size (numbytes t) in
let h0 = ST.get () in
[@ inline_let]
let a_spec (i:nat{i <= v len}) = unit in
[@ inline_let]
let spec (h:mem) = S.bn_to_bytes_be_f (v len) (as_seq h b) in
fill_blocks h0 numb len res a_spec (fun _ _ -> ()) (fun _ -> LowStar.Buffer.loc_none) spec
(fun j -> uint_to_bytes_be (sub res (j *! numb) numb) b.(len -! j -! 1ul));
norm_spec [delta_only [`%S.bn_to_bytes_be_]] (S.bn_to_bytes_be_ (v len) (as_seq h0 b))
inline_for_extraction noextract
let bn_to_bytes_be_st (t:limb_t) (len:size_t{0 < v len /\ numbytes t * v (blocks len (size (numbytes t))) <= max_size_t}) =
b:lbignum t (blocks len (size (numbytes t)))
-> res:lbuffer uint8 len ->
Stack unit
(requires fun h ->
live h b /\ live h res /\ disjoint res b)
(ensures fun h0 _ h1 -> modifies (loc res) h0 h1 /\
as_seq h1 res == S.bn_to_bytes_be (v len) (as_seq h0 b))
inline_for_extraction noextract
val mk_bn_to_bytes_be:
#t:limb_t
-> is_known_len:bool
-> len:size_t{0 < v len /\ numbytes t * v (blocks len (size (numbytes t))) <= max_size_t} ->
bn_to_bytes_be_st t len
let mk_bn_to_bytes_be #t is_known_len len b res =
push_frame ();
if is_known_len then begin
[@inline_let] let numb = size (numbytes t) in
[@inline_let] let bnLen = blocks len numb in
[@inline_let] let tmpLen = numb *! bnLen in
let tmp = create tmpLen (u8 0) in
if tmpLen =. len then begin
LowStar.Ignore.ignore tmp;
bn_to_bytes_be_ bnLen b res end
else begin
bn_to_bytes_be_ bnLen b tmp;
copy res (sub tmp (tmpLen -! len) len) end end
else begin
[@inline_let] let numb = size (numbytes t) in
let bnLen = blocks len numb in
let tmpLen = numb *! bnLen in
let tmp = create tmpLen (u8 0) in
bn_to_bytes_be_ bnLen b tmp;
copy res (sub tmp (tmpLen -! len) len) end;
pop_frame ()
[@CInline]
let bn_to_bytes_be_uint32 len : bn_to_bytes_be_st U32 len = mk_bn_to_bytes_be #U32 false len
let bn_to_bytes_be_uint64 len : bn_to_bytes_be_st U64 len = mk_bn_to_bytes_be #U64 false len
inline_for_extraction noextract
val bn_to_bytes_be: #t:_ -> len:_ -> bn_to_bytes_be_st t len | false | false | Hacl.Bignum.Convert.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 bn_to_bytes_be: #t:_ -> len:_ -> bn_to_bytes_be_st t len | [] | Hacl.Bignum.Convert.bn_to_bytes_be | {
"file_name": "code/bignum/Hacl.Bignum.Convert.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} |
len:
Lib.IntTypes.size_t
{ 0 < Lib.IntTypes.v len /\
Lib.IntTypes.numbytes t *
Lib.IntTypes.v (Hacl.Bignum.Definitions.blocks len
(Lib.IntTypes.size (Lib.IntTypes.numbytes t))) <=
Lib.IntTypes.max_size_t }
-> Hacl.Bignum.Convert.bn_to_bytes_be_st t len | {
"end_col": 32,
"end_line": 225,
"start_col": 2,
"start_line": 223
} |
FStar.HyperStack.ST.Stack | val bn_from_uint:
#t:limb_t
-> len:size_t{0 < v len}
-> x:limb t
-> b:lbignum t len ->
Stack unit
(requires fun h -> live h b)
(ensures fun h0 _ h1 -> modifies (loc b) h0 h1 /\
as_seq h1 b == S.bn_from_uint (v len) x) | [
{
"abbrev": true,
"full_module": "Hacl.Spec.Bignum.Convert",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "Lib.Sequence",
"short_module": "LSeq"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": false,
"full_module": "Hacl.Bignum.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.ByteBuffer",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Buffer",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Bignum",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Bignum",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let bn_from_uint #t len x b =
memset b (uint #t 0) len;
b.(0ul) <- x | val bn_from_uint:
#t:limb_t
-> len:size_t{0 < v len}
-> x:limb t
-> b:lbignum t len ->
Stack unit
(requires fun h -> live h b)
(ensures fun h0 _ h1 -> modifies (loc b) h0 h1 /\
as_seq h1 b == S.bn_from_uint (v len) x)
let bn_from_uint #t len x b = | true | null | false | memset b (uint #t 0) len;
b.(0ul) <- x | {
"checked_file": "Hacl.Bignum.Convert.fst.checked",
"dependencies": [
"prims.fst.checked",
"LowStar.Ignore.fsti.checked",
"LowStar.Buffer.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.ByteBuffer.fsti.checked",
"Lib.Buffer.fsti.checked",
"Hacl.Spec.Bignum.Convert.fst.checked",
"Hacl.Bignum.Definitions.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked"
],
"interface_file": false,
"source_file": "Hacl.Bignum.Convert.fst"
} | [] | [
"Hacl.Bignum.Definitions.limb_t",
"Lib.IntTypes.size_t",
"Prims.b2t",
"Prims.op_LessThan",
"Lib.IntTypes.v",
"Lib.IntTypes.U32",
"Lib.IntTypes.PUB",
"Hacl.Bignum.Definitions.limb",
"Hacl.Bignum.Definitions.lbignum",
"Lib.Buffer.op_Array_Assignment",
"FStar.UInt32.__uint_to_t",
"Prims.unit",
"Lib.Buffer.memset",
"Lib.IntTypes.uint",
"Lib.IntTypes.SEC"
] | [] | module Hacl.Bignum.Convert
open FStar.HyperStack
open FStar.HyperStack.ST
open FStar.Mul
open Lib.IntTypes
open Lib.Buffer
open Lib.ByteBuffer
open Hacl.Bignum.Definitions
module ST = FStar.HyperStack.ST
module LSeq = Lib.Sequence
module S = Hacl.Spec.Bignum.Convert
#reset-options "--z3rlimit 50 --fuel 0 --ifuel 0"
inline_for_extraction noextract
val bn_from_uint:
#t:limb_t
-> len:size_t{0 < v len}
-> x:limb t
-> b:lbignum t len ->
Stack unit
(requires fun h -> live h b)
(ensures fun h0 _ h1 -> modifies (loc b) h0 h1 /\
as_seq h1 b == S.bn_from_uint (v len) x) | false | false | Hacl.Bignum.Convert.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 bn_from_uint:
#t:limb_t
-> len:size_t{0 < v len}
-> x:limb t
-> b:lbignum t len ->
Stack unit
(requires fun h -> live h b)
(ensures fun h0 _ h1 -> modifies (loc b) h0 h1 /\
as_seq h1 b == S.bn_from_uint (v len) x) | [] | Hacl.Bignum.Convert.bn_from_uint | {
"file_name": "code/bignum/Hacl.Bignum.Convert.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} |
len: Lib.IntTypes.size_t{0 < Lib.IntTypes.v len} ->
x: Hacl.Bignum.Definitions.limb t ->
b: Hacl.Bignum.Definitions.lbignum t len
-> FStar.HyperStack.ST.Stack Prims.unit | {
"end_col": 14,
"end_line": 33,
"start_col": 2,
"start_line": 32
} |
FStar.HyperStack.ST.Stack | val bn_from_bytes_be_:
#t:limb_t
-> len:size_t{numbytes t * v len <= max_size_t}
-> b:lbuffer uint8 (size (numbytes t) *! len)
-> res:lbignum t len ->
Stack unit
(requires fun h -> live h b /\ live h res /\ disjoint res b)
(ensures fun h0 _ h1 -> modifies (loc res) h0 h1 /\
as_seq h1 res == S.bn_from_bytes_be_ (v len) (as_seq h0 b)) | [
{
"abbrev": true,
"full_module": "Hacl.Spec.Bignum.Convert",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "Lib.Sequence",
"short_module": "LSeq"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": false,
"full_module": "Hacl.Bignum.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.ByteBuffer",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Buffer",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Bignum",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Bignum",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let bn_from_bytes_be_ #t len b res =
let h0 = ST.get () in
[@inline_let]
let spec h = S.bn_from_bytes_be_f (v len) (as_seq h b) in
fill h0 len res spec
(fun j -> uint_from_bytes_be (sub b ((len -! j -! 1ul) *! (size (numbytes t))) (size (numbytes t)))) | val bn_from_bytes_be_:
#t:limb_t
-> len:size_t{numbytes t * v len <= max_size_t}
-> b:lbuffer uint8 (size (numbytes t) *! len)
-> res:lbignum t len ->
Stack unit
(requires fun h -> live h b /\ live h res /\ disjoint res b)
(ensures fun h0 _ h1 -> modifies (loc res) h0 h1 /\
as_seq h1 res == S.bn_from_bytes_be_ (v len) (as_seq h0 b))
let bn_from_bytes_be_ #t len b res = | true | null | false | let h0 = ST.get () in
[@@ inline_let ]let spec h = S.bn_from_bytes_be_f (v len) (as_seq h b) in
fill h0
len
res
spec
(fun j ->
uint_from_bytes_be (sub b ((len -! j -! 1ul) *! (size (numbytes t))) (size (numbytes t)))) | {
"checked_file": "Hacl.Bignum.Convert.fst.checked",
"dependencies": [
"prims.fst.checked",
"LowStar.Ignore.fsti.checked",
"LowStar.Buffer.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.ByteBuffer.fsti.checked",
"Lib.Buffer.fsti.checked",
"Hacl.Spec.Bignum.Convert.fst.checked",
"Hacl.Bignum.Definitions.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked"
],
"interface_file": false,
"source_file": "Hacl.Bignum.Convert.fst"
} | [] | [
"Hacl.Bignum.Definitions.limb_t",
"Lib.IntTypes.size_t",
"Prims.b2t",
"Prims.op_LessThanOrEqual",
"FStar.Mul.op_Star",
"Lib.IntTypes.numbytes",
"Lib.IntTypes.v",
"Lib.IntTypes.U32",
"Lib.IntTypes.PUB",
"Lib.IntTypes.max_size_t",
"Lib.Buffer.lbuffer",
"Lib.IntTypes.uint8",
"Lib.IntTypes.op_Star_Bang",
"Lib.IntTypes.size",
"Hacl.Bignum.Definitions.lbignum",
"Lib.Buffer.fill",
"Hacl.Bignum.Definitions.limb",
"Prims.op_LessThan",
"Lib.ByteBuffer.uint_from_bytes_be",
"Lib.IntTypes.SEC",
"Lib.IntTypes.uint_t",
"Lib.Buffer.lbuffer_t",
"Lib.Buffer.MUT",
"Lib.IntTypes.int_t",
"Lib.IntTypes.U8",
"Lib.IntTypes.mk_int",
"Lib.Buffer.sub",
"Lib.IntTypes.op_Subtraction_Bang",
"FStar.UInt32.__uint_to_t",
"Prims.unit",
"FStar.Monotonic.HyperStack.mem",
"Prims.nat",
"Hacl.Spec.Bignum.Definitions.limb",
"Hacl.Spec.Bignum.Convert.bn_from_bytes_be_f",
"Lib.Buffer.as_seq",
"FStar.HyperStack.ST.get"
] | [] | module Hacl.Bignum.Convert
open FStar.HyperStack
open FStar.HyperStack.ST
open FStar.Mul
open Lib.IntTypes
open Lib.Buffer
open Lib.ByteBuffer
open Hacl.Bignum.Definitions
module ST = FStar.HyperStack.ST
module LSeq = Lib.Sequence
module S = Hacl.Spec.Bignum.Convert
#reset-options "--z3rlimit 50 --fuel 0 --ifuel 0"
inline_for_extraction noextract
val bn_from_uint:
#t:limb_t
-> len:size_t{0 < v len}
-> x:limb t
-> b:lbignum t len ->
Stack unit
(requires fun h -> live h b)
(ensures fun h0 _ h1 -> modifies (loc b) h0 h1 /\
as_seq h1 b == S.bn_from_uint (v len) x)
let bn_from_uint #t len x b =
memset b (uint #t 0) len;
b.(0ul) <- x
inline_for_extraction noextract
val bn_from_bytes_be_:
#t:limb_t
-> len:size_t{numbytes t * v len <= max_size_t}
-> b:lbuffer uint8 (size (numbytes t) *! len)
-> res:lbignum t len ->
Stack unit
(requires fun h -> live h b /\ live h res /\ disjoint res b)
(ensures fun h0 _ h1 -> modifies (loc res) h0 h1 /\
as_seq h1 res == S.bn_from_bytes_be_ (v len) (as_seq h0 b)) | false | false | Hacl.Bignum.Convert.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 bn_from_bytes_be_:
#t:limb_t
-> len:size_t{numbytes t * v len <= max_size_t}
-> b:lbuffer uint8 (size (numbytes t) *! len)
-> res:lbignum t len ->
Stack unit
(requires fun h -> live h b /\ live h res /\ disjoint res b)
(ensures fun h0 _ h1 -> modifies (loc res) h0 h1 /\
as_seq h1 res == S.bn_from_bytes_be_ (v len) (as_seq h0 b)) | [] | Hacl.Bignum.Convert.bn_from_bytes_be_ | {
"file_name": "code/bignum/Hacl.Bignum.Convert.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} |
len:
Lib.IntTypes.size_t{Lib.IntTypes.numbytes t * Lib.IntTypes.v len <= Lib.IntTypes.max_size_t} ->
b: Lib.Buffer.lbuffer Lib.IntTypes.uint8 (Lib.IntTypes.size (Lib.IntTypes.numbytes t) *! len) ->
res: Hacl.Bignum.Definitions.lbignum t len
-> FStar.HyperStack.ST.Stack Prims.unit | {
"end_col": 102,
"end_line": 52,
"start_col": 36,
"start_line": 47
} |
FStar.HyperStack.ST.Stack | val bn_to_bytes_be_:
#t:limb_t
-> len:size_t{numbytes t * v len <= max_size_t}
-> b:lbignum t len
-> res:lbuffer uint8 (size (numbytes t) *! len) ->
Stack unit
(requires fun h -> live h b /\ live h res /\ disjoint res b)
(ensures fun h0 _ h1 -> modifies (loc res) h0 h1 /\
as_seq h1 res == S.bn_to_bytes_be_ (v len) (as_seq h0 b)) | [
{
"abbrev": true,
"full_module": "Hacl.Spec.Bignum.Convert",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "Lib.Sequence",
"short_module": "LSeq"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": false,
"full_module": "Hacl.Bignum.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.ByteBuffer",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Buffer",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Bignum",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Bignum",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let bn_to_bytes_be_ #t len b res =
[@inline_let] let numb = size (numbytes t) in
let h0 = ST.get () in
[@ inline_let]
let a_spec (i:nat{i <= v len}) = unit in
[@ inline_let]
let spec (h:mem) = S.bn_to_bytes_be_f (v len) (as_seq h b) in
fill_blocks h0 numb len res a_spec (fun _ _ -> ()) (fun _ -> LowStar.Buffer.loc_none) spec
(fun j -> uint_to_bytes_be (sub res (j *! numb) numb) b.(len -! j -! 1ul));
norm_spec [delta_only [`%S.bn_to_bytes_be_]] (S.bn_to_bytes_be_ (v len) (as_seq h0 b)) | val bn_to_bytes_be_:
#t:limb_t
-> len:size_t{numbytes t * v len <= max_size_t}
-> b:lbignum t len
-> res:lbuffer uint8 (size (numbytes t) *! len) ->
Stack unit
(requires fun h -> live h b /\ live h res /\ disjoint res b)
(ensures fun h0 _ h1 -> modifies (loc res) h0 h1 /\
as_seq h1 res == S.bn_to_bytes_be_ (v len) (as_seq h0 b))
let bn_to_bytes_be_ #t len b res = | true | null | false | [@@ inline_let ]let numb = size (numbytes t) in
let h0 = ST.get () in
[@@ inline_let ]let a_spec (i: nat{i <= v len}) = unit in
[@@ inline_let ]let spec (h: mem) = S.bn_to_bytes_be_f (v len) (as_seq h b) in
fill_blocks h0
numb
len
res
a_spec
(fun _ _ -> ())
(fun _ -> LowStar.Buffer.loc_none)
spec
(fun j -> uint_to_bytes_be (sub res (j *! numb) numb) b.(len -! j -! 1ul));
norm_spec [delta_only [`%S.bn_to_bytes_be_]] (S.bn_to_bytes_be_ (v len) (as_seq h0 b)) | {
"checked_file": "Hacl.Bignum.Convert.fst.checked",
"dependencies": [
"prims.fst.checked",
"LowStar.Ignore.fsti.checked",
"LowStar.Buffer.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.ByteBuffer.fsti.checked",
"Lib.Buffer.fsti.checked",
"Hacl.Spec.Bignum.Convert.fst.checked",
"Hacl.Bignum.Definitions.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked"
],
"interface_file": false,
"source_file": "Hacl.Bignum.Convert.fst"
} | [] | [
"Hacl.Bignum.Definitions.limb_t",
"Lib.IntTypes.size_t",
"Prims.b2t",
"Prims.op_LessThanOrEqual",
"FStar.Mul.op_Star",
"Lib.IntTypes.numbytes",
"Lib.IntTypes.v",
"Lib.IntTypes.U32",
"Lib.IntTypes.PUB",
"Lib.IntTypes.max_size_t",
"Hacl.Bignum.Definitions.lbignum",
"Lib.Buffer.lbuffer",
"Lib.IntTypes.uint8",
"Lib.IntTypes.op_Star_Bang",
"Lib.IntTypes.size",
"FStar.Pervasives.norm_spec",
"Prims.Cons",
"FStar.Pervasives.norm_step",
"FStar.Pervasives.delta_only",
"Prims.string",
"Prims.Nil",
"Lib.Sequence.lseq",
"Hacl.Spec.Bignum.Convert.bn_to_bytes_be_",
"Lib.Buffer.as_seq",
"Lib.Buffer.MUT",
"Hacl.Bignum.Definitions.limb",
"Prims.unit",
"Lib.Buffer.fill_blocks",
"FStar.Monotonic.HyperStack.mem",
"Lib.IntTypes.size_nat",
"LowStar.Monotonic.Buffer.loc_none",
"LowStar.Monotonic.Buffer.loc",
"Prims.l_and",
"LowStar.Monotonic.Buffer.loc_disjoint",
"Lib.Buffer.loc",
"LowStar.Monotonic.Buffer.loc_includes",
"LowStar.Monotonic.Buffer.address_liveness_insensitive_locs",
"Prims.op_LessThan",
"Lib.ByteBuffer.uint_to_bytes_be",
"Lib.IntTypes.SEC",
"Lib.IntTypes.int_t",
"Lib.Buffer.op_Array_Access",
"Lib.IntTypes.op_Subtraction_Bang",
"FStar.UInt32.__uint_to_t",
"Lib.Buffer.lbuffer_t",
"Lib.IntTypes.U8",
"Lib.IntTypes.mk_int",
"Lib.Buffer.sub",
"Prims.nat",
"FStar.Pervasives.Native.tuple2",
"Hacl.Spec.Bignum.Convert.bn_to_bytes_be_f",
"Prims.eqtype",
"FStar.HyperStack.ST.get"
] | [] | module Hacl.Bignum.Convert
open FStar.HyperStack
open FStar.HyperStack.ST
open FStar.Mul
open Lib.IntTypes
open Lib.Buffer
open Lib.ByteBuffer
open Hacl.Bignum.Definitions
module ST = FStar.HyperStack.ST
module LSeq = Lib.Sequence
module S = Hacl.Spec.Bignum.Convert
#reset-options "--z3rlimit 50 --fuel 0 --ifuel 0"
inline_for_extraction noextract
val bn_from_uint:
#t:limb_t
-> len:size_t{0 < v len}
-> x:limb t
-> b:lbignum t len ->
Stack unit
(requires fun h -> live h b)
(ensures fun h0 _ h1 -> modifies (loc b) h0 h1 /\
as_seq h1 b == S.bn_from_uint (v len) x)
let bn_from_uint #t len x b =
memset b (uint #t 0) len;
b.(0ul) <- x
inline_for_extraction noextract
val bn_from_bytes_be_:
#t:limb_t
-> len:size_t{numbytes t * v len <= max_size_t}
-> b:lbuffer uint8 (size (numbytes t) *! len)
-> res:lbignum t len ->
Stack unit
(requires fun h -> live h b /\ live h res /\ disjoint res b)
(ensures fun h0 _ h1 -> modifies (loc res) h0 h1 /\
as_seq h1 res == S.bn_from_bytes_be_ (v len) (as_seq h0 b))
let bn_from_bytes_be_ #t len b res =
let h0 = ST.get () in
[@inline_let]
let spec h = S.bn_from_bytes_be_f (v len) (as_seq h b) in
fill h0 len res spec
(fun j -> uint_from_bytes_be (sub b ((len -! j -! 1ul) *! (size (numbytes t))) (size (numbytes t))))
inline_for_extraction noextract
let bn_from_bytes_be_st (t:limb_t) =
len:size_t{0 < v len /\ numbytes t * v (blocks len (size (numbytes t))) <= max_size_t}
-> b:lbuffer uint8 len
-> res:lbignum t (blocks len (size (numbytes t))) ->
Stack unit
(requires fun h -> live h b /\ live h res /\ disjoint res b)
(ensures fun h0 _ h1 -> modifies (loc res) h0 h1 /\
as_seq h1 res == S.bn_from_bytes_be (v len) (as_seq h0 b))
inline_for_extraction noextract
val mk_bn_from_bytes_be: #t:limb_t -> is_known_len:bool -> bn_from_bytes_be_st t
let mk_bn_from_bytes_be #t is_known_len len b res =
push_frame ();
if is_known_len then begin
[@inline_let] let numb = size (numbytes t) in
[@inline_let] let bnLen = blocks len numb in
[@inline_let] let tmpLen = numb *! bnLen in
if tmpLen =. len then
bn_from_bytes_be_ bnLen b res
else begin
let tmp = create tmpLen (u8 0) in
update_sub tmp (tmpLen -! len) len b;
bn_from_bytes_be_ bnLen tmp res end end
else begin
[@inline_let] let numb = size (numbytes t) in
let bnLen = blocks len numb in
let tmpLen = numb *! bnLen in
let tmp = create tmpLen (u8 0) in
update_sub tmp (tmpLen -! len) len b;
bn_from_bytes_be_ bnLen tmp res end;
pop_frame ()
[@CInline]
let bn_from_bytes_be_uint32 : bn_from_bytes_be_st U32 = mk_bn_from_bytes_be #U32 false
let bn_from_bytes_be_uint64 : bn_from_bytes_be_st U64 = mk_bn_from_bytes_be #U64 false
inline_for_extraction noextract
val bn_from_bytes_be: #t:limb_t -> bn_from_bytes_be_st t
let bn_from_bytes_be #t =
match t with
| U32 -> bn_from_bytes_be_uint32
| U64 -> bn_from_bytes_be_uint64
inline_for_extraction noextract
let bn_from_bytes_le_st (t:limb_t) =
len:size_t{0 < v len /\ numbytes t * v (blocks len (size (numbytes t))) <= max_size_t}
-> b:lbuffer uint8 len
-> res:lbignum t (blocks len (size (numbytes t))) ->
Stack unit
(requires fun h -> live h b /\ live h res /\ disjoint res b)
(ensures fun h0 _ h1 -> modifies (loc res) h0 h1 /\
as_seq h1 res == S.bn_from_bytes_le (v len) (as_seq h0 b))
inline_for_extraction noextract
val mk_bn_from_bytes_le: #t:limb_t -> is_known_len:bool -> bn_from_bytes_le_st t
let mk_bn_from_bytes_le #t is_known_len len b res =
push_frame ();
if is_known_len then begin
[@inline_let] let numb = size (numbytes t) in
[@inline_let] let bnLen = blocks len numb in
[@inline_let] let tmpLen = numb *! bnLen in
if tmpLen =. len then
uints_from_bytes_le res b
else begin
let tmp = create tmpLen (u8 0) in
update_sub tmp 0ul len b;
uints_from_bytes_le res tmp end end
else begin
[@inline_let] let numb = size (numbytes t) in
let bnLen = blocks len numb in
let tmpLen = numb *! bnLen in
let tmp = create tmpLen (u8 0) in
update_sub tmp 0ul len b;
uints_from_bytes_le res tmp end;
pop_frame ()
[@CInline]
let bn_from_bytes_le_uint32 : bn_from_bytes_le_st U32 = mk_bn_from_bytes_le #U32 false
[@CInline]
let bn_from_bytes_le_uint64 : bn_from_bytes_le_st U64 = mk_bn_from_bytes_le #U64 false
inline_for_extraction noextract
val bn_from_bytes_le: #t:limb_t -> bn_from_bytes_le_st t
let bn_from_bytes_le #t =
match t with
| U32 -> bn_from_bytes_le_uint32
| U64 -> bn_from_bytes_le_uint64
inline_for_extraction noextract
val bn_to_bytes_be_:
#t:limb_t
-> len:size_t{numbytes t * v len <= max_size_t}
-> b:lbignum t len
-> res:lbuffer uint8 (size (numbytes t) *! len) ->
Stack unit
(requires fun h -> live h b /\ live h res /\ disjoint res b)
(ensures fun h0 _ h1 -> modifies (loc res) h0 h1 /\
as_seq h1 res == S.bn_to_bytes_be_ (v len) (as_seq h0 b)) | false | false | Hacl.Bignum.Convert.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 bn_to_bytes_be_:
#t:limb_t
-> len:size_t{numbytes t * v len <= max_size_t}
-> b:lbignum t len
-> res:lbuffer uint8 (size (numbytes t) *! len) ->
Stack unit
(requires fun h -> live h b /\ live h res /\ disjoint res b)
(ensures fun h0 _ h1 -> modifies (loc res) h0 h1 /\
as_seq h1 res == S.bn_to_bytes_be_ (v len) (as_seq h0 b)) | [] | Hacl.Bignum.Convert.bn_to_bytes_be_ | {
"file_name": "code/bignum/Hacl.Bignum.Convert.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} |
len:
Lib.IntTypes.size_t{Lib.IntTypes.numbytes t * Lib.IntTypes.v len <= Lib.IntTypes.max_size_t} ->
b: Hacl.Bignum.Definitions.lbignum t len ->
res: Lib.Buffer.lbuffer Lib.IntTypes.uint8 (Lib.IntTypes.size (Lib.IntTypes.numbytes t) *! len)
-> FStar.HyperStack.ST.Stack Prims.unit | {
"end_col": 88,
"end_line": 172,
"start_col": 2,
"start_line": 164
} |
Prims.Tot | val mk_bn_from_bytes_be: #t:limb_t -> is_known_len:bool -> bn_from_bytes_be_st t | [
{
"abbrev": true,
"full_module": "Hacl.Spec.Bignum.Convert",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "Lib.Sequence",
"short_module": "LSeq"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": false,
"full_module": "Hacl.Bignum.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.ByteBuffer",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Buffer",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Bignum",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Bignum",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let mk_bn_from_bytes_be #t is_known_len len b res =
push_frame ();
if is_known_len then begin
[@inline_let] let numb = size (numbytes t) in
[@inline_let] let bnLen = blocks len numb in
[@inline_let] let tmpLen = numb *! bnLen in
if tmpLen =. len then
bn_from_bytes_be_ bnLen b res
else begin
let tmp = create tmpLen (u8 0) in
update_sub tmp (tmpLen -! len) len b;
bn_from_bytes_be_ bnLen tmp res end end
else begin
[@inline_let] let numb = size (numbytes t) in
let bnLen = blocks len numb in
let tmpLen = numb *! bnLen in
let tmp = create tmpLen (u8 0) in
update_sub tmp (tmpLen -! len) len b;
bn_from_bytes_be_ bnLen tmp res end;
pop_frame () | val mk_bn_from_bytes_be: #t:limb_t -> is_known_len:bool -> bn_from_bytes_be_st t
let mk_bn_from_bytes_be #t is_known_len len b res = | false | null | false | push_frame ();
if is_known_len
then
[@@ inline_let ]let numb = size (numbytes t) in
[@@ inline_let ]let bnLen = blocks len numb in
[@@ inline_let ]let tmpLen = numb *! bnLen in
if tmpLen =. len
then bn_from_bytes_be_ bnLen b res
else
let tmp = create tmpLen (u8 0) in
update_sub tmp (tmpLen -! len) len b;
bn_from_bytes_be_ bnLen tmp res
else
([@@ inline_let ]let numb = size (numbytes t) in
let bnLen = blocks len numb in
let tmpLen = numb *! bnLen in
let tmp = create tmpLen (u8 0) in
update_sub tmp (tmpLen -! len) len b;
bn_from_bytes_be_ bnLen tmp res);
pop_frame () | {
"checked_file": "Hacl.Bignum.Convert.fst.checked",
"dependencies": [
"prims.fst.checked",
"LowStar.Ignore.fsti.checked",
"LowStar.Buffer.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.ByteBuffer.fsti.checked",
"Lib.Buffer.fsti.checked",
"Hacl.Spec.Bignum.Convert.fst.checked",
"Hacl.Bignum.Definitions.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked"
],
"interface_file": false,
"source_file": "Hacl.Bignum.Convert.fst"
} | [
"total"
] | [
"Hacl.Bignum.Definitions.limb_t",
"Prims.bool",
"Lib.IntTypes.size_t",
"Prims.l_and",
"Prims.b2t",
"Prims.op_LessThan",
"Lib.IntTypes.v",
"Lib.IntTypes.U32",
"Lib.IntTypes.PUB",
"Prims.op_LessThanOrEqual",
"FStar.Mul.op_Star",
"Lib.IntTypes.numbytes",
"Hacl.Bignum.Definitions.blocks",
"Lib.IntTypes.size",
"Lib.IntTypes.max_size_t",
"Lib.Buffer.lbuffer",
"Lib.IntTypes.uint8",
"Hacl.Bignum.Definitions.lbignum",
"FStar.HyperStack.ST.pop_frame",
"Prims.unit",
"Lib.IntTypes.op_Equals_Dot",
"Hacl.Bignum.Convert.bn_from_bytes_be_",
"Lib.Buffer.update_sub",
"Lib.Buffer.MUT",
"Lib.IntTypes.op_Subtraction_Bang",
"Lib.Buffer.lbuffer_t",
"Lib.IntTypes.int_t",
"Lib.IntTypes.U8",
"Lib.IntTypes.SEC",
"Lib.Buffer.create",
"Lib.IntTypes.u8",
"Lib.IntTypes.op_Star_Bang",
"Prims.eq2",
"Prims.int",
"Prims.l_or",
"Lib.IntTypes.range",
"Prims.op_GreaterThan",
"Prims.op_Subtraction",
"Prims.pow2",
"Prims.op_Multiply",
"Hacl.Spec.Bignum.Definitions.blocks",
"FStar.HyperStack.ST.push_frame"
] | [] | module Hacl.Bignum.Convert
open FStar.HyperStack
open FStar.HyperStack.ST
open FStar.Mul
open Lib.IntTypes
open Lib.Buffer
open Lib.ByteBuffer
open Hacl.Bignum.Definitions
module ST = FStar.HyperStack.ST
module LSeq = Lib.Sequence
module S = Hacl.Spec.Bignum.Convert
#reset-options "--z3rlimit 50 --fuel 0 --ifuel 0"
inline_for_extraction noextract
val bn_from_uint:
#t:limb_t
-> len:size_t{0 < v len}
-> x:limb t
-> b:lbignum t len ->
Stack unit
(requires fun h -> live h b)
(ensures fun h0 _ h1 -> modifies (loc b) h0 h1 /\
as_seq h1 b == S.bn_from_uint (v len) x)
let bn_from_uint #t len x b =
memset b (uint #t 0) len;
b.(0ul) <- x
inline_for_extraction noextract
val bn_from_bytes_be_:
#t:limb_t
-> len:size_t{numbytes t * v len <= max_size_t}
-> b:lbuffer uint8 (size (numbytes t) *! len)
-> res:lbignum t len ->
Stack unit
(requires fun h -> live h b /\ live h res /\ disjoint res b)
(ensures fun h0 _ h1 -> modifies (loc res) h0 h1 /\
as_seq h1 res == S.bn_from_bytes_be_ (v len) (as_seq h0 b))
let bn_from_bytes_be_ #t len b res =
let h0 = ST.get () in
[@inline_let]
let spec h = S.bn_from_bytes_be_f (v len) (as_seq h b) in
fill h0 len res spec
(fun j -> uint_from_bytes_be (sub b ((len -! j -! 1ul) *! (size (numbytes t))) (size (numbytes t))))
inline_for_extraction noextract
let bn_from_bytes_be_st (t:limb_t) =
len:size_t{0 < v len /\ numbytes t * v (blocks len (size (numbytes t))) <= max_size_t}
-> b:lbuffer uint8 len
-> res:lbignum t (blocks len (size (numbytes t))) ->
Stack unit
(requires fun h -> live h b /\ live h res /\ disjoint res b)
(ensures fun h0 _ h1 -> modifies (loc res) h0 h1 /\
as_seq h1 res == S.bn_from_bytes_be (v len) (as_seq h0 b))
inline_for_extraction noextract
val mk_bn_from_bytes_be: #t:limb_t -> is_known_len:bool -> bn_from_bytes_be_st t | false | false | Hacl.Bignum.Convert.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_bn_from_bytes_be: #t:limb_t -> is_known_len:bool -> bn_from_bytes_be_st t | [] | Hacl.Bignum.Convert.mk_bn_from_bytes_be | {
"file_name": "code/bignum/Hacl.Bignum.Convert.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | is_known_len: Prims.bool -> Hacl.Bignum.Convert.bn_from_bytes_be_st t | {
"end_col": 14,
"end_line": 87,
"start_col": 2,
"start_line": 69
} |
Prims.Tot | val mk_bn_from_bytes_le: #t:limb_t -> is_known_len:bool -> bn_from_bytes_le_st t | [
{
"abbrev": true,
"full_module": "Hacl.Spec.Bignum.Convert",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "Lib.Sequence",
"short_module": "LSeq"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": false,
"full_module": "Hacl.Bignum.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.ByteBuffer",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Buffer",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Bignum",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Bignum",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let mk_bn_from_bytes_le #t is_known_len len b res =
push_frame ();
if is_known_len then begin
[@inline_let] let numb = size (numbytes t) in
[@inline_let] let bnLen = blocks len numb in
[@inline_let] let tmpLen = numb *! bnLen in
if tmpLen =. len then
uints_from_bytes_le res b
else begin
let tmp = create tmpLen (u8 0) in
update_sub tmp 0ul len b;
uints_from_bytes_le res tmp end end
else begin
[@inline_let] let numb = size (numbytes t) in
let bnLen = blocks len numb in
let tmpLen = numb *! bnLen in
let tmp = create tmpLen (u8 0) in
update_sub tmp 0ul len b;
uints_from_bytes_le res tmp end;
pop_frame () | val mk_bn_from_bytes_le: #t:limb_t -> is_known_len:bool -> bn_from_bytes_le_st t
let mk_bn_from_bytes_le #t is_known_len len b res = | false | null | false | push_frame ();
if is_known_len
then
[@@ inline_let ]let numb = size (numbytes t) in
[@@ inline_let ]let bnLen = blocks len numb in
[@@ inline_let ]let tmpLen = numb *! bnLen in
if tmpLen =. len
then uints_from_bytes_le res b
else
let tmp = create tmpLen (u8 0) in
update_sub tmp 0ul len b;
uints_from_bytes_le res tmp
else
([@@ inline_let ]let numb = size (numbytes t) in
let bnLen = blocks len numb in
let tmpLen = numb *! bnLen in
let tmp = create tmpLen (u8 0) in
update_sub tmp 0ul len b;
uints_from_bytes_le res tmp);
pop_frame () | {
"checked_file": "Hacl.Bignum.Convert.fst.checked",
"dependencies": [
"prims.fst.checked",
"LowStar.Ignore.fsti.checked",
"LowStar.Buffer.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.ByteBuffer.fsti.checked",
"Lib.Buffer.fsti.checked",
"Hacl.Spec.Bignum.Convert.fst.checked",
"Hacl.Bignum.Definitions.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked"
],
"interface_file": false,
"source_file": "Hacl.Bignum.Convert.fst"
} | [
"total"
] | [
"Hacl.Bignum.Definitions.limb_t",
"Prims.bool",
"Lib.IntTypes.size_t",
"Prims.l_and",
"Prims.b2t",
"Prims.op_LessThan",
"Lib.IntTypes.v",
"Lib.IntTypes.U32",
"Lib.IntTypes.PUB",
"Prims.op_LessThanOrEqual",
"FStar.Mul.op_Star",
"Lib.IntTypes.numbytes",
"Hacl.Bignum.Definitions.blocks",
"Lib.IntTypes.size",
"Lib.IntTypes.max_size_t",
"Lib.Buffer.lbuffer",
"Lib.IntTypes.uint8",
"Hacl.Bignum.Definitions.lbignum",
"FStar.HyperStack.ST.pop_frame",
"Prims.unit",
"Lib.IntTypes.op_Equals_Dot",
"Lib.ByteBuffer.uints_from_bytes_le",
"Lib.IntTypes.SEC",
"Lib.Buffer.update_sub",
"Lib.Buffer.MUT",
"FStar.UInt32.__uint_to_t",
"Lib.Buffer.lbuffer_t",
"Lib.IntTypes.int_t",
"Lib.IntTypes.U8",
"Lib.Buffer.create",
"Lib.IntTypes.u8",
"Lib.IntTypes.op_Star_Bang",
"Prims.eq2",
"Prims.int",
"Prims.l_or",
"Lib.IntTypes.range",
"Prims.op_GreaterThan",
"Prims.op_Subtraction",
"Prims.pow2",
"Prims.op_Multiply",
"Hacl.Spec.Bignum.Definitions.blocks",
"FStar.HyperStack.ST.push_frame"
] | [] | module Hacl.Bignum.Convert
open FStar.HyperStack
open FStar.HyperStack.ST
open FStar.Mul
open Lib.IntTypes
open Lib.Buffer
open Lib.ByteBuffer
open Hacl.Bignum.Definitions
module ST = FStar.HyperStack.ST
module LSeq = Lib.Sequence
module S = Hacl.Spec.Bignum.Convert
#reset-options "--z3rlimit 50 --fuel 0 --ifuel 0"
inline_for_extraction noextract
val bn_from_uint:
#t:limb_t
-> len:size_t{0 < v len}
-> x:limb t
-> b:lbignum t len ->
Stack unit
(requires fun h -> live h b)
(ensures fun h0 _ h1 -> modifies (loc b) h0 h1 /\
as_seq h1 b == S.bn_from_uint (v len) x)
let bn_from_uint #t len x b =
memset b (uint #t 0) len;
b.(0ul) <- x
inline_for_extraction noextract
val bn_from_bytes_be_:
#t:limb_t
-> len:size_t{numbytes t * v len <= max_size_t}
-> b:lbuffer uint8 (size (numbytes t) *! len)
-> res:lbignum t len ->
Stack unit
(requires fun h -> live h b /\ live h res /\ disjoint res b)
(ensures fun h0 _ h1 -> modifies (loc res) h0 h1 /\
as_seq h1 res == S.bn_from_bytes_be_ (v len) (as_seq h0 b))
let bn_from_bytes_be_ #t len b res =
let h0 = ST.get () in
[@inline_let]
let spec h = S.bn_from_bytes_be_f (v len) (as_seq h b) in
fill h0 len res spec
(fun j -> uint_from_bytes_be (sub b ((len -! j -! 1ul) *! (size (numbytes t))) (size (numbytes t))))
inline_for_extraction noextract
let bn_from_bytes_be_st (t:limb_t) =
len:size_t{0 < v len /\ numbytes t * v (blocks len (size (numbytes t))) <= max_size_t}
-> b:lbuffer uint8 len
-> res:lbignum t (blocks len (size (numbytes t))) ->
Stack unit
(requires fun h -> live h b /\ live h res /\ disjoint res b)
(ensures fun h0 _ h1 -> modifies (loc res) h0 h1 /\
as_seq h1 res == S.bn_from_bytes_be (v len) (as_seq h0 b))
inline_for_extraction noextract
val mk_bn_from_bytes_be: #t:limb_t -> is_known_len:bool -> bn_from_bytes_be_st t
let mk_bn_from_bytes_be #t is_known_len len b res =
push_frame ();
if is_known_len then begin
[@inline_let] let numb = size (numbytes t) in
[@inline_let] let bnLen = blocks len numb in
[@inline_let] let tmpLen = numb *! bnLen in
if tmpLen =. len then
bn_from_bytes_be_ bnLen b res
else begin
let tmp = create tmpLen (u8 0) in
update_sub tmp (tmpLen -! len) len b;
bn_from_bytes_be_ bnLen tmp res end end
else begin
[@inline_let] let numb = size (numbytes t) in
let bnLen = blocks len numb in
let tmpLen = numb *! bnLen in
let tmp = create tmpLen (u8 0) in
update_sub tmp (tmpLen -! len) len b;
bn_from_bytes_be_ bnLen tmp res end;
pop_frame ()
[@CInline]
let bn_from_bytes_be_uint32 : bn_from_bytes_be_st U32 = mk_bn_from_bytes_be #U32 false
let bn_from_bytes_be_uint64 : bn_from_bytes_be_st U64 = mk_bn_from_bytes_be #U64 false
inline_for_extraction noextract
val bn_from_bytes_be: #t:limb_t -> bn_from_bytes_be_st t
let bn_from_bytes_be #t =
match t with
| U32 -> bn_from_bytes_be_uint32
| U64 -> bn_from_bytes_be_uint64
inline_for_extraction noextract
let bn_from_bytes_le_st (t:limb_t) =
len:size_t{0 < v len /\ numbytes t * v (blocks len (size (numbytes t))) <= max_size_t}
-> b:lbuffer uint8 len
-> res:lbignum t (blocks len (size (numbytes t))) ->
Stack unit
(requires fun h -> live h b /\ live h res /\ disjoint res b)
(ensures fun h0 _ h1 -> modifies (loc res) h0 h1 /\
as_seq h1 res == S.bn_from_bytes_le (v len) (as_seq h0 b))
inline_for_extraction noextract
val mk_bn_from_bytes_le: #t:limb_t -> is_known_len:bool -> bn_from_bytes_le_st t | false | false | Hacl.Bignum.Convert.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_bn_from_bytes_le: #t:limb_t -> is_known_len:bool -> bn_from_bytes_le_st t | [] | Hacl.Bignum.Convert.mk_bn_from_bytes_le | {
"file_name": "code/bignum/Hacl.Bignum.Convert.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | is_known_len: Prims.bool -> Hacl.Bignum.Convert.bn_from_bytes_le_st t | {
"end_col": 14,
"end_line": 135,
"start_col": 2,
"start_line": 117
} |
Prims.Tot | val mk_bn_to_bytes_be:
#t:limb_t
-> is_known_len:bool
-> len:size_t{0 < v len /\ numbytes t * v (blocks len (size (numbytes t))) <= max_size_t} ->
bn_to_bytes_be_st t len | [
{
"abbrev": true,
"full_module": "Hacl.Spec.Bignum.Convert",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "Lib.Sequence",
"short_module": "LSeq"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": false,
"full_module": "Hacl.Bignum.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.ByteBuffer",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Buffer",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Bignum",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Bignum",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let mk_bn_to_bytes_be #t is_known_len len b res =
push_frame ();
if is_known_len then begin
[@inline_let] let numb = size (numbytes t) in
[@inline_let] let bnLen = blocks len numb in
[@inline_let] let tmpLen = numb *! bnLen in
let tmp = create tmpLen (u8 0) in
if tmpLen =. len then begin
LowStar.Ignore.ignore tmp;
bn_to_bytes_be_ bnLen b res end
else begin
bn_to_bytes_be_ bnLen b tmp;
copy res (sub tmp (tmpLen -! len) len) end end
else begin
[@inline_let] let numb = size (numbytes t) in
let bnLen = blocks len numb in
let tmpLen = numb *! bnLen in
let tmp = create tmpLen (u8 0) in
bn_to_bytes_be_ bnLen b tmp;
copy res (sub tmp (tmpLen -! len) len) end;
pop_frame () | val mk_bn_to_bytes_be:
#t:limb_t
-> is_known_len:bool
-> len:size_t{0 < v len /\ numbytes t * v (blocks len (size (numbytes t))) <= max_size_t} ->
bn_to_bytes_be_st t len
let mk_bn_to_bytes_be #t is_known_len len b res = | false | null | false | push_frame ();
if is_known_len
then
[@@ inline_let ]let numb = size (numbytes t) in
[@@ inline_let ]let bnLen = blocks len numb in
[@@ inline_let ]let tmpLen = numb *! bnLen in
let tmp = create tmpLen (u8 0) in
if tmpLen =. len
then
(LowStar.Ignore.ignore tmp;
bn_to_bytes_be_ bnLen b res)
else
(bn_to_bytes_be_ bnLen b tmp;
copy res (sub tmp (tmpLen -! len) len))
else
([@@ inline_let ]let numb = size (numbytes t) in
let bnLen = blocks len numb in
let tmpLen = numb *! bnLen in
let tmp = create tmpLen (u8 0) in
bn_to_bytes_be_ bnLen b tmp;
copy res (sub tmp (tmpLen -! len) len));
pop_frame () | {
"checked_file": "Hacl.Bignum.Convert.fst.checked",
"dependencies": [
"prims.fst.checked",
"LowStar.Ignore.fsti.checked",
"LowStar.Buffer.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.ByteBuffer.fsti.checked",
"Lib.Buffer.fsti.checked",
"Hacl.Spec.Bignum.Convert.fst.checked",
"Hacl.Bignum.Definitions.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked"
],
"interface_file": false,
"source_file": "Hacl.Bignum.Convert.fst"
} | [
"total"
] | [
"Hacl.Bignum.Definitions.limb_t",
"Prims.bool",
"Lib.IntTypes.size_t",
"Prims.l_and",
"Prims.b2t",
"Prims.op_LessThan",
"Lib.IntTypes.v",
"Lib.IntTypes.U32",
"Lib.IntTypes.PUB",
"Prims.op_LessThanOrEqual",
"FStar.Mul.op_Star",
"Lib.IntTypes.numbytes",
"Hacl.Bignum.Definitions.blocks",
"Lib.IntTypes.size",
"Lib.IntTypes.max_size_t",
"Hacl.Bignum.Definitions.lbignum",
"Lib.Buffer.lbuffer",
"Lib.IntTypes.uint8",
"FStar.HyperStack.ST.pop_frame",
"Prims.unit",
"Lib.IntTypes.op_Equals_Dot",
"Hacl.Bignum.Convert.bn_to_bytes_be_",
"LowStar.Ignore.ignore",
"Lib.Buffer.copy",
"Lib.Buffer.MUT",
"Lib.Buffer.lbuffer_t",
"Lib.IntTypes.int_t",
"Lib.IntTypes.U8",
"Lib.IntTypes.SEC",
"Lib.Buffer.sub",
"Lib.IntTypes.op_Subtraction_Bang",
"Lib.Buffer.create",
"Lib.IntTypes.u8",
"Lib.IntTypes.op_Star_Bang",
"Prims.eq2",
"Prims.int",
"Prims.l_or",
"Lib.IntTypes.range",
"Prims.op_GreaterThan",
"Prims.op_Subtraction",
"Prims.pow2",
"Prims.op_Multiply",
"Hacl.Spec.Bignum.Definitions.blocks",
"FStar.HyperStack.ST.push_frame"
] | [] | module Hacl.Bignum.Convert
open FStar.HyperStack
open FStar.HyperStack.ST
open FStar.Mul
open Lib.IntTypes
open Lib.Buffer
open Lib.ByteBuffer
open Hacl.Bignum.Definitions
module ST = FStar.HyperStack.ST
module LSeq = Lib.Sequence
module S = Hacl.Spec.Bignum.Convert
#reset-options "--z3rlimit 50 --fuel 0 --ifuel 0"
inline_for_extraction noextract
val bn_from_uint:
#t:limb_t
-> len:size_t{0 < v len}
-> x:limb t
-> b:lbignum t len ->
Stack unit
(requires fun h -> live h b)
(ensures fun h0 _ h1 -> modifies (loc b) h0 h1 /\
as_seq h1 b == S.bn_from_uint (v len) x)
let bn_from_uint #t len x b =
memset b (uint #t 0) len;
b.(0ul) <- x
inline_for_extraction noextract
val bn_from_bytes_be_:
#t:limb_t
-> len:size_t{numbytes t * v len <= max_size_t}
-> b:lbuffer uint8 (size (numbytes t) *! len)
-> res:lbignum t len ->
Stack unit
(requires fun h -> live h b /\ live h res /\ disjoint res b)
(ensures fun h0 _ h1 -> modifies (loc res) h0 h1 /\
as_seq h1 res == S.bn_from_bytes_be_ (v len) (as_seq h0 b))
let bn_from_bytes_be_ #t len b res =
let h0 = ST.get () in
[@inline_let]
let spec h = S.bn_from_bytes_be_f (v len) (as_seq h b) in
fill h0 len res spec
(fun j -> uint_from_bytes_be (sub b ((len -! j -! 1ul) *! (size (numbytes t))) (size (numbytes t))))
inline_for_extraction noextract
let bn_from_bytes_be_st (t:limb_t) =
len:size_t{0 < v len /\ numbytes t * v (blocks len (size (numbytes t))) <= max_size_t}
-> b:lbuffer uint8 len
-> res:lbignum t (blocks len (size (numbytes t))) ->
Stack unit
(requires fun h -> live h b /\ live h res /\ disjoint res b)
(ensures fun h0 _ h1 -> modifies (loc res) h0 h1 /\
as_seq h1 res == S.bn_from_bytes_be (v len) (as_seq h0 b))
inline_for_extraction noextract
val mk_bn_from_bytes_be: #t:limb_t -> is_known_len:bool -> bn_from_bytes_be_st t
let mk_bn_from_bytes_be #t is_known_len len b res =
push_frame ();
if is_known_len then begin
[@inline_let] let numb = size (numbytes t) in
[@inline_let] let bnLen = blocks len numb in
[@inline_let] let tmpLen = numb *! bnLen in
if tmpLen =. len then
bn_from_bytes_be_ bnLen b res
else begin
let tmp = create tmpLen (u8 0) in
update_sub tmp (tmpLen -! len) len b;
bn_from_bytes_be_ bnLen tmp res end end
else begin
[@inline_let] let numb = size (numbytes t) in
let bnLen = blocks len numb in
let tmpLen = numb *! bnLen in
let tmp = create tmpLen (u8 0) in
update_sub tmp (tmpLen -! len) len b;
bn_from_bytes_be_ bnLen tmp res end;
pop_frame ()
[@CInline]
let bn_from_bytes_be_uint32 : bn_from_bytes_be_st U32 = mk_bn_from_bytes_be #U32 false
let bn_from_bytes_be_uint64 : bn_from_bytes_be_st U64 = mk_bn_from_bytes_be #U64 false
inline_for_extraction noextract
val bn_from_bytes_be: #t:limb_t -> bn_from_bytes_be_st t
let bn_from_bytes_be #t =
match t with
| U32 -> bn_from_bytes_be_uint32
| U64 -> bn_from_bytes_be_uint64
inline_for_extraction noextract
let bn_from_bytes_le_st (t:limb_t) =
len:size_t{0 < v len /\ numbytes t * v (blocks len (size (numbytes t))) <= max_size_t}
-> b:lbuffer uint8 len
-> res:lbignum t (blocks len (size (numbytes t))) ->
Stack unit
(requires fun h -> live h b /\ live h res /\ disjoint res b)
(ensures fun h0 _ h1 -> modifies (loc res) h0 h1 /\
as_seq h1 res == S.bn_from_bytes_le (v len) (as_seq h0 b))
inline_for_extraction noextract
val mk_bn_from_bytes_le: #t:limb_t -> is_known_len:bool -> bn_from_bytes_le_st t
let mk_bn_from_bytes_le #t is_known_len len b res =
push_frame ();
if is_known_len then begin
[@inline_let] let numb = size (numbytes t) in
[@inline_let] let bnLen = blocks len numb in
[@inline_let] let tmpLen = numb *! bnLen in
if tmpLen =. len then
uints_from_bytes_le res b
else begin
let tmp = create tmpLen (u8 0) in
update_sub tmp 0ul len b;
uints_from_bytes_le res tmp end end
else begin
[@inline_let] let numb = size (numbytes t) in
let bnLen = blocks len numb in
let tmpLen = numb *! bnLen in
let tmp = create tmpLen (u8 0) in
update_sub tmp 0ul len b;
uints_from_bytes_le res tmp end;
pop_frame ()
[@CInline]
let bn_from_bytes_le_uint32 : bn_from_bytes_le_st U32 = mk_bn_from_bytes_le #U32 false
[@CInline]
let bn_from_bytes_le_uint64 : bn_from_bytes_le_st U64 = mk_bn_from_bytes_le #U64 false
inline_for_extraction noextract
val bn_from_bytes_le: #t:limb_t -> bn_from_bytes_le_st t
let bn_from_bytes_le #t =
match t with
| U32 -> bn_from_bytes_le_uint32
| U64 -> bn_from_bytes_le_uint64
inline_for_extraction noextract
val bn_to_bytes_be_:
#t:limb_t
-> len:size_t{numbytes t * v len <= max_size_t}
-> b:lbignum t len
-> res:lbuffer uint8 (size (numbytes t) *! len) ->
Stack unit
(requires fun h -> live h b /\ live h res /\ disjoint res b)
(ensures fun h0 _ h1 -> modifies (loc res) h0 h1 /\
as_seq h1 res == S.bn_to_bytes_be_ (v len) (as_seq h0 b))
let bn_to_bytes_be_ #t len b res =
[@inline_let] let numb = size (numbytes t) in
let h0 = ST.get () in
[@ inline_let]
let a_spec (i:nat{i <= v len}) = unit in
[@ inline_let]
let spec (h:mem) = S.bn_to_bytes_be_f (v len) (as_seq h b) in
fill_blocks h0 numb len res a_spec (fun _ _ -> ()) (fun _ -> LowStar.Buffer.loc_none) spec
(fun j -> uint_to_bytes_be (sub res (j *! numb) numb) b.(len -! j -! 1ul));
norm_spec [delta_only [`%S.bn_to_bytes_be_]] (S.bn_to_bytes_be_ (v len) (as_seq h0 b))
inline_for_extraction noextract
let bn_to_bytes_be_st (t:limb_t) (len:size_t{0 < v len /\ numbytes t * v (blocks len (size (numbytes t))) <= max_size_t}) =
b:lbignum t (blocks len (size (numbytes t)))
-> res:lbuffer uint8 len ->
Stack unit
(requires fun h ->
live h b /\ live h res /\ disjoint res b)
(ensures fun h0 _ h1 -> modifies (loc res) h0 h1 /\
as_seq h1 res == S.bn_to_bytes_be (v len) (as_seq h0 b))
inline_for_extraction noextract
val mk_bn_to_bytes_be:
#t:limb_t
-> is_known_len:bool
-> len:size_t{0 < v len /\ numbytes t * v (blocks len (size (numbytes t))) <= max_size_t} ->
bn_to_bytes_be_st t len | false | false | Hacl.Bignum.Convert.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_bn_to_bytes_be:
#t:limb_t
-> is_known_len:bool
-> len:size_t{0 < v len /\ numbytes t * v (blocks len (size (numbytes t))) <= max_size_t} ->
bn_to_bytes_be_st t len | [] | Hacl.Bignum.Convert.mk_bn_to_bytes_be | {
"file_name": "code/bignum/Hacl.Bignum.Convert.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} |
is_known_len: Prims.bool ->
len:
Lib.IntTypes.size_t
{ 0 < Lib.IntTypes.v len /\
Lib.IntTypes.numbytes t *
Lib.IntTypes.v (Hacl.Bignum.Definitions.blocks len
(Lib.IntTypes.size (Lib.IntTypes.numbytes t))) <=
Lib.IntTypes.max_size_t }
-> Hacl.Bignum.Convert.bn_to_bytes_be_st t len | {
"end_col": 14,
"end_line": 212,
"start_col": 2,
"start_line": 193
} |
Prims.Tot | val mk_bn_to_bytes_le:
#t:limb_t
-> is_known_len:bool
-> len:size_t{0 < v len /\ numbytes t * v (blocks len (size (numbytes t))) <= max_size_t} ->
bn_to_bytes_le_st t len | [
{
"abbrev": true,
"full_module": "Hacl.Spec.Bignum.Convert",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "Lib.Sequence",
"short_module": "LSeq"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": false,
"full_module": "Hacl.Bignum.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.ByteBuffer",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Buffer",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Bignum",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Bignum",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let mk_bn_to_bytes_le #t is_known_len len b res =
push_frame ();
if is_known_len then begin
[@inline_let] let numb = size (numbytes t) in
[@inline_let] let bnLen = blocks len numb in
[@inline_let] let tmpLen = numb *! bnLen in
let tmp = create tmpLen (u8 0) in
if tmpLen =. len then begin
LowStar.Ignore.ignore tmp;
uints_to_bytes_le bnLen res b end
else begin
uints_to_bytes_le bnLen tmp b;
copy res (sub tmp 0ul len) end end
else begin
[@inline_let] let numb = size (numbytes t) in
let bnLen = blocks len numb in
let tmpLen = numb *! bnLen in
let tmp = create tmpLen (u8 0) in
uints_to_bytes_le bnLen tmp b;
copy res (sub tmp 0ul len) end;
pop_frame () | val mk_bn_to_bytes_le:
#t:limb_t
-> is_known_len:bool
-> len:size_t{0 < v len /\ numbytes t * v (blocks len (size (numbytes t))) <= max_size_t} ->
bn_to_bytes_le_st t len
let mk_bn_to_bytes_le #t is_known_len len b res = | false | null | false | push_frame ();
if is_known_len
then
[@@ inline_let ]let numb = size (numbytes t) in
[@@ inline_let ]let bnLen = blocks len numb in
[@@ inline_let ]let tmpLen = numb *! bnLen in
let tmp = create tmpLen (u8 0) in
if tmpLen =. len
then
(LowStar.Ignore.ignore tmp;
uints_to_bytes_le bnLen res b)
else
(uints_to_bytes_le bnLen tmp b;
copy res (sub tmp 0ul len))
else
([@@ inline_let ]let numb = size (numbytes t) in
let bnLen = blocks len numb in
let tmpLen = numb *! bnLen in
let tmp = create tmpLen (u8 0) in
uints_to_bytes_le bnLen tmp b;
copy res (sub tmp 0ul len));
pop_frame () | {
"checked_file": "Hacl.Bignum.Convert.fst.checked",
"dependencies": [
"prims.fst.checked",
"LowStar.Ignore.fsti.checked",
"LowStar.Buffer.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.ByteBuffer.fsti.checked",
"Lib.Buffer.fsti.checked",
"Hacl.Spec.Bignum.Convert.fst.checked",
"Hacl.Bignum.Definitions.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked"
],
"interface_file": false,
"source_file": "Hacl.Bignum.Convert.fst"
} | [
"total"
] | [
"Hacl.Bignum.Definitions.limb_t",
"Prims.bool",
"Lib.IntTypes.size_t",
"Prims.l_and",
"Prims.b2t",
"Prims.op_LessThan",
"Lib.IntTypes.v",
"Lib.IntTypes.U32",
"Lib.IntTypes.PUB",
"Prims.op_LessThanOrEqual",
"FStar.Mul.op_Star",
"Lib.IntTypes.numbytes",
"Hacl.Bignum.Definitions.blocks",
"Lib.IntTypes.size",
"Lib.IntTypes.max_size_t",
"Hacl.Bignum.Definitions.lbignum",
"Lib.Buffer.lbuffer",
"Lib.IntTypes.uint8",
"FStar.HyperStack.ST.pop_frame",
"Prims.unit",
"Lib.IntTypes.op_Equals_Dot",
"Lib.ByteBuffer.uints_to_bytes_le",
"Lib.IntTypes.SEC",
"LowStar.Ignore.ignore",
"Lib.IntTypes.uint_t",
"Lib.IntTypes.U8",
"Lib.Buffer.copy",
"Lib.Buffer.MUT",
"Lib.Buffer.lbuffer_t",
"Lib.IntTypes.int_t",
"Lib.Buffer.sub",
"FStar.UInt32.__uint_to_t",
"Lib.Buffer.create",
"Lib.IntTypes.u8",
"Lib.IntTypes.op_Star_Bang",
"Prims.eq2",
"Prims.int",
"Prims.l_or",
"Lib.IntTypes.range",
"Prims.op_GreaterThan",
"Prims.op_Subtraction",
"Prims.pow2",
"Prims.op_Multiply",
"Hacl.Spec.Bignum.Definitions.blocks",
"FStar.HyperStack.ST.push_frame"
] | [] | module Hacl.Bignum.Convert
open FStar.HyperStack
open FStar.HyperStack.ST
open FStar.Mul
open Lib.IntTypes
open Lib.Buffer
open Lib.ByteBuffer
open Hacl.Bignum.Definitions
module ST = FStar.HyperStack.ST
module LSeq = Lib.Sequence
module S = Hacl.Spec.Bignum.Convert
#reset-options "--z3rlimit 50 --fuel 0 --ifuel 0"
inline_for_extraction noextract
val bn_from_uint:
#t:limb_t
-> len:size_t{0 < v len}
-> x:limb t
-> b:lbignum t len ->
Stack unit
(requires fun h -> live h b)
(ensures fun h0 _ h1 -> modifies (loc b) h0 h1 /\
as_seq h1 b == S.bn_from_uint (v len) x)
let bn_from_uint #t len x b =
memset b (uint #t 0) len;
b.(0ul) <- x
inline_for_extraction noextract
val bn_from_bytes_be_:
#t:limb_t
-> len:size_t{numbytes t * v len <= max_size_t}
-> b:lbuffer uint8 (size (numbytes t) *! len)
-> res:lbignum t len ->
Stack unit
(requires fun h -> live h b /\ live h res /\ disjoint res b)
(ensures fun h0 _ h1 -> modifies (loc res) h0 h1 /\
as_seq h1 res == S.bn_from_bytes_be_ (v len) (as_seq h0 b))
let bn_from_bytes_be_ #t len b res =
let h0 = ST.get () in
[@inline_let]
let spec h = S.bn_from_bytes_be_f (v len) (as_seq h b) in
fill h0 len res spec
(fun j -> uint_from_bytes_be (sub b ((len -! j -! 1ul) *! (size (numbytes t))) (size (numbytes t))))
inline_for_extraction noextract
let bn_from_bytes_be_st (t:limb_t) =
len:size_t{0 < v len /\ numbytes t * v (blocks len (size (numbytes t))) <= max_size_t}
-> b:lbuffer uint8 len
-> res:lbignum t (blocks len (size (numbytes t))) ->
Stack unit
(requires fun h -> live h b /\ live h res /\ disjoint res b)
(ensures fun h0 _ h1 -> modifies (loc res) h0 h1 /\
as_seq h1 res == S.bn_from_bytes_be (v len) (as_seq h0 b))
inline_for_extraction noextract
val mk_bn_from_bytes_be: #t:limb_t -> is_known_len:bool -> bn_from_bytes_be_st t
let mk_bn_from_bytes_be #t is_known_len len b res =
push_frame ();
if is_known_len then begin
[@inline_let] let numb = size (numbytes t) in
[@inline_let] let bnLen = blocks len numb in
[@inline_let] let tmpLen = numb *! bnLen in
if tmpLen =. len then
bn_from_bytes_be_ bnLen b res
else begin
let tmp = create tmpLen (u8 0) in
update_sub tmp (tmpLen -! len) len b;
bn_from_bytes_be_ bnLen tmp res end end
else begin
[@inline_let] let numb = size (numbytes t) in
let bnLen = blocks len numb in
let tmpLen = numb *! bnLen in
let tmp = create tmpLen (u8 0) in
update_sub tmp (tmpLen -! len) len b;
bn_from_bytes_be_ bnLen tmp res end;
pop_frame ()
[@CInline]
let bn_from_bytes_be_uint32 : bn_from_bytes_be_st U32 = mk_bn_from_bytes_be #U32 false
let bn_from_bytes_be_uint64 : bn_from_bytes_be_st U64 = mk_bn_from_bytes_be #U64 false
inline_for_extraction noextract
val bn_from_bytes_be: #t:limb_t -> bn_from_bytes_be_st t
let bn_from_bytes_be #t =
match t with
| U32 -> bn_from_bytes_be_uint32
| U64 -> bn_from_bytes_be_uint64
inline_for_extraction noextract
let bn_from_bytes_le_st (t:limb_t) =
len:size_t{0 < v len /\ numbytes t * v (blocks len (size (numbytes t))) <= max_size_t}
-> b:lbuffer uint8 len
-> res:lbignum t (blocks len (size (numbytes t))) ->
Stack unit
(requires fun h -> live h b /\ live h res /\ disjoint res b)
(ensures fun h0 _ h1 -> modifies (loc res) h0 h1 /\
as_seq h1 res == S.bn_from_bytes_le (v len) (as_seq h0 b))
inline_for_extraction noextract
val mk_bn_from_bytes_le: #t:limb_t -> is_known_len:bool -> bn_from_bytes_le_st t
let mk_bn_from_bytes_le #t is_known_len len b res =
push_frame ();
if is_known_len then begin
[@inline_let] let numb = size (numbytes t) in
[@inline_let] let bnLen = blocks len numb in
[@inline_let] let tmpLen = numb *! bnLen in
if tmpLen =. len then
uints_from_bytes_le res b
else begin
let tmp = create tmpLen (u8 0) in
update_sub tmp 0ul len b;
uints_from_bytes_le res tmp end end
else begin
[@inline_let] let numb = size (numbytes t) in
let bnLen = blocks len numb in
let tmpLen = numb *! bnLen in
let tmp = create tmpLen (u8 0) in
update_sub tmp 0ul len b;
uints_from_bytes_le res tmp end;
pop_frame ()
[@CInline]
let bn_from_bytes_le_uint32 : bn_from_bytes_le_st U32 = mk_bn_from_bytes_le #U32 false
[@CInline]
let bn_from_bytes_le_uint64 : bn_from_bytes_le_st U64 = mk_bn_from_bytes_le #U64 false
inline_for_extraction noextract
val bn_from_bytes_le: #t:limb_t -> bn_from_bytes_le_st t
let bn_from_bytes_le #t =
match t with
| U32 -> bn_from_bytes_le_uint32
| U64 -> bn_from_bytes_le_uint64
inline_for_extraction noextract
val bn_to_bytes_be_:
#t:limb_t
-> len:size_t{numbytes t * v len <= max_size_t}
-> b:lbignum t len
-> res:lbuffer uint8 (size (numbytes t) *! len) ->
Stack unit
(requires fun h -> live h b /\ live h res /\ disjoint res b)
(ensures fun h0 _ h1 -> modifies (loc res) h0 h1 /\
as_seq h1 res == S.bn_to_bytes_be_ (v len) (as_seq h0 b))
let bn_to_bytes_be_ #t len b res =
[@inline_let] let numb = size (numbytes t) in
let h0 = ST.get () in
[@ inline_let]
let a_spec (i:nat{i <= v len}) = unit in
[@ inline_let]
let spec (h:mem) = S.bn_to_bytes_be_f (v len) (as_seq h b) in
fill_blocks h0 numb len res a_spec (fun _ _ -> ()) (fun _ -> LowStar.Buffer.loc_none) spec
(fun j -> uint_to_bytes_be (sub res (j *! numb) numb) b.(len -! j -! 1ul));
norm_spec [delta_only [`%S.bn_to_bytes_be_]] (S.bn_to_bytes_be_ (v len) (as_seq h0 b))
inline_for_extraction noextract
let bn_to_bytes_be_st (t:limb_t) (len:size_t{0 < v len /\ numbytes t * v (blocks len (size (numbytes t))) <= max_size_t}) =
b:lbignum t (blocks len (size (numbytes t)))
-> res:lbuffer uint8 len ->
Stack unit
(requires fun h ->
live h b /\ live h res /\ disjoint res b)
(ensures fun h0 _ h1 -> modifies (loc res) h0 h1 /\
as_seq h1 res == S.bn_to_bytes_be (v len) (as_seq h0 b))
inline_for_extraction noextract
val mk_bn_to_bytes_be:
#t:limb_t
-> is_known_len:bool
-> len:size_t{0 < v len /\ numbytes t * v (blocks len (size (numbytes t))) <= max_size_t} ->
bn_to_bytes_be_st t len
let mk_bn_to_bytes_be #t is_known_len len b res =
push_frame ();
if is_known_len then begin
[@inline_let] let numb = size (numbytes t) in
[@inline_let] let bnLen = blocks len numb in
[@inline_let] let tmpLen = numb *! bnLen in
let tmp = create tmpLen (u8 0) in
if tmpLen =. len then begin
LowStar.Ignore.ignore tmp;
bn_to_bytes_be_ bnLen b res end
else begin
bn_to_bytes_be_ bnLen b tmp;
copy res (sub tmp (tmpLen -! len) len) end end
else begin
[@inline_let] let numb = size (numbytes t) in
let bnLen = blocks len numb in
let tmpLen = numb *! bnLen in
let tmp = create tmpLen (u8 0) in
bn_to_bytes_be_ bnLen b tmp;
copy res (sub tmp (tmpLen -! len) len) end;
pop_frame ()
[@CInline]
let bn_to_bytes_be_uint32 len : bn_to_bytes_be_st U32 len = mk_bn_to_bytes_be #U32 false len
let bn_to_bytes_be_uint64 len : bn_to_bytes_be_st U64 len = mk_bn_to_bytes_be #U64 false len
inline_for_extraction noextract
val bn_to_bytes_be: #t:_ -> len:_ -> bn_to_bytes_be_st t len
let bn_to_bytes_be #t =
match t with
| U32 -> bn_to_bytes_be_uint32
| U64 -> bn_to_bytes_be_uint64
inline_for_extraction noextract
let bn_to_bytes_le_st (t:limb_t) (len:size_t{0 < v len /\ numbytes t * v (blocks len (size (numbytes t))) <= max_size_t}) =
b:lbignum t (blocks len (size (numbytes t)))
-> res:lbuffer uint8 len ->
Stack unit
(requires fun h ->
live h b /\ live h res /\ disjoint res b)
(ensures fun h0 _ h1 -> modifies (loc res) h0 h1 /\
as_seq h1 res == S.bn_to_bytes_le (v len) (as_seq h0 b))
inline_for_extraction noextract
val mk_bn_to_bytes_le:
#t:limb_t
-> is_known_len:bool
-> len:size_t{0 < v len /\ numbytes t * v (blocks len (size (numbytes t))) <= max_size_t} ->
bn_to_bytes_le_st t len | false | false | Hacl.Bignum.Convert.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_bn_to_bytes_le:
#t:limb_t
-> is_known_len:bool
-> len:size_t{0 < v len /\ numbytes t * v (blocks len (size (numbytes t))) <= max_size_t} ->
bn_to_bytes_le_st t len | [] | Hacl.Bignum.Convert.mk_bn_to_bytes_le | {
"file_name": "code/bignum/Hacl.Bignum.Convert.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} |
is_known_len: Prims.bool ->
len:
Lib.IntTypes.size_t
{ 0 < Lib.IntTypes.v len /\
Lib.IntTypes.numbytes t *
Lib.IntTypes.v (Hacl.Bignum.Definitions.blocks len
(Lib.IntTypes.size (Lib.IntTypes.numbytes t))) <=
Lib.IntTypes.max_size_t }
-> Hacl.Bignum.Convert.bn_to_bytes_le_st t len | {
"end_col": 14,
"end_line": 266,
"start_col": 2,
"start_line": 247
} |
Prims.GTot | val mt_empty (#hsz:pos): merkle_tree #hsz -> GTot bool | [
{
"abbrev": true,
"full_module": "MerkleTree.Spec",
"short_module": "MTS"
},
{
"abbrev": true,
"full_module": "FStar.UInt8",
"short_module": "U8"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "S"
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Ghost",
"short_module": null
},
{
"abbrev": false,
"full_module": "MerkleTree.New",
"short_module": null
},
{
"abbrev": false,
"full_module": "MerkleTree.New",
"short_module": null
},
{
"abbrev": 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 mt_empty #hsz mt =
MT?.j mt = 0 | val mt_empty (#hsz:pos): merkle_tree #hsz -> GTot bool
let mt_empty #hsz mt = | false | null | false | MT?.j mt = 0 | {
"checked_file": "MerkleTree.New.High.fst.checked",
"dependencies": [
"Spec.Hash.Definitions.fst.checked",
"prims.fst.checked",
"MerkleTree.Spec.fst.checked",
"Lib.IntTypes.fsti.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "MerkleTree.New.High.fst"
} | [
"sometrivial"
] | [
"Prims.pos",
"MerkleTree.New.High.merkle_tree",
"Prims.op_Equality",
"Prims.int",
"MerkleTree.New.High.__proj__MT__item__j",
"Prims.bool"
] | [] | module MerkleTree.New.High
open FStar.Ghost
open FStar.Seq
module S = FStar.Seq
module U32 = FStar.UInt32
module U8 = FStar.UInt8
module MTS = MerkleTree.Spec
#set-options "--z3rlimit 10 --max_fuel 0 --max_ifuel 0"
type uint32_t = U32.t
type uint8_t = U8.t
type hash (#hsz:pos) = b:Spec.Hash.Definitions.bytes{Seq.length b = hsz}
type hashes (#hsz:pos) = S.seq (hash #hsz)
type hashess (#hsz:pos) = S.seq (hashes #hsz)
noextract
let hash_init (#hsz:pos): hash #hsz =
Seq.create hsz (Lib.IntTypes.u8 0)
val sha256_compress: src1:hash #32 -> src2:hash #32 -> GTot (hash #32)
let sha256_compress = MTS.sha256_compress
/// Facts about sequences
val seq_slice_equal_index:
#a:Type -> s1:S.seq a -> s2:S.seq a ->
i:nat -> j:nat{i <= j && j <= S.length s1 && j <= S.length s2} ->
k:nat{i <= k && k < j} ->
Lemma (requires S.equal (S.slice s1 i j) (S.slice s2 i j))
(ensures S.index s1 k == S.index s2 k)
[SMTPat (S.equal (S.slice s1 i j) (S.slice s2 i j));
SMTPat (S.index s1 k)]
let seq_slice_equal_index #a s1 s2 i j k =
assert (S.index (S.slice s1 i j) (k - i) == S.index (S.slice s2 i j) (k - i))
private val seq_slice_more_equal:
#a:Type -> s1:S.seq a -> s2:S.seq a ->
n:nat -> m:nat{n <= m && m <= S.length s1 && m <= S.length s2} ->
k:nat{n <= k} -> l:nat{k <= l && l <= m} ->
Lemma (requires S.equal (S.slice s1 n m) (S.slice s2 n m))
(ensures S.equal (S.slice s1 k l) (S.slice s2 k l))
[SMTPat (S.equal (S.slice s1 n m) (S.slice s2 n m));
SMTPat (S.equal (S.slice s1 k l) (S.slice s2 k l))]
private let seq_slice_more_equal #a s1 s2 n m k l =
slice_slice s1 n m (k - n) (l - n);
slice_slice s2 n m (k - n) (l - n)
/// Facts about "2"
val remainder_2_not_1_div: n:nat ->
Lemma (requires n % 2 <> 1)
(ensures n / 2 = (n + 1) / 2)
let remainder_2_not_1_div n = ()
val remainder_2_1_div: n:nat ->
Lemma (requires n % 2 = 1)
(ensures n / 2 + 1 = (n + 1) / 2)
let remainder_2_1_div n = ()
/// High-level Merkle tree data structure
noeq type merkle_tree (#hsz:pos) =
| MT: i:nat ->
j:nat{i <= j && j < pow2 32} ->
hs:hashess #hsz {S.length hs = 32} ->
rhs_ok:bool ->
rhs:hashes #hsz {S.length rhs = 32} -> // Rightmost hashes
mroot:hash #hsz ->
hash_fun:MTS.hash_fun_t #hsz ->
merkle_tree #hsz
val mt_not_full (#hsz:pos): merkle_tree #hsz -> GTot bool
let mt_not_full #hsz mt =
MT?.j mt < pow2 32 - 1
val mt_empty (#hsz:pos): merkle_tree #hsz -> GTot bool | false | false | MerkleTree.New.High.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 10,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val mt_empty (#hsz:pos): merkle_tree #hsz -> GTot bool | [] | MerkleTree.New.High.mt_empty | {
"file_name": "src/MerkleTree.New.High.fst",
"git_rev": "3b0f086655c145aa23f58a97259ebf4cf112a4a3",
"git_url": "https://github.com/hacl-star/merkle-tree.git",
"project_name": "merkle-tree"
} | mt: MerkleTree.New.High.merkle_tree -> Prims.GTot Prims.bool | {
"end_col": 14,
"end_line": 85,
"start_col": 2,
"start_line": 85
} |
Prims.GTot | val sha256_compress: src1:hash #32 -> src2:hash #32 -> GTot (hash #32) | [
{
"abbrev": true,
"full_module": "MerkleTree.Spec",
"short_module": "MTS"
},
{
"abbrev": true,
"full_module": "FStar.UInt8",
"short_module": "U8"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "S"
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Ghost",
"short_module": null
},
{
"abbrev": false,
"full_module": "MerkleTree.New",
"short_module": null
},
{
"abbrev": false,
"full_module": "MerkleTree.New",
"short_module": null
},
{
"abbrev": 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 sha256_compress = MTS.sha256_compress | val sha256_compress: src1:hash #32 -> src2:hash #32 -> GTot (hash #32)
let sha256_compress = | false | null | false | MTS.sha256_compress | {
"checked_file": "MerkleTree.New.High.fst.checked",
"dependencies": [
"Spec.Hash.Definitions.fst.checked",
"prims.fst.checked",
"MerkleTree.Spec.fst.checked",
"Lib.IntTypes.fsti.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "MerkleTree.New.High.fst"
} | [
"sometrivial"
] | [
"MerkleTree.Spec.sha256_compress"
] | [] | module MerkleTree.New.High
open FStar.Ghost
open FStar.Seq
module S = FStar.Seq
module U32 = FStar.UInt32
module U8 = FStar.UInt8
module MTS = MerkleTree.Spec
#set-options "--z3rlimit 10 --max_fuel 0 --max_ifuel 0"
type uint32_t = U32.t
type uint8_t = U8.t
type hash (#hsz:pos) = b:Spec.Hash.Definitions.bytes{Seq.length b = hsz}
type hashes (#hsz:pos) = S.seq (hash #hsz)
type hashess (#hsz:pos) = S.seq (hashes #hsz)
noextract
let hash_init (#hsz:pos): hash #hsz =
Seq.create hsz (Lib.IntTypes.u8 0) | false | false | MerkleTree.New.High.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 10,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val sha256_compress: src1:hash #32 -> src2:hash #32 -> GTot (hash #32) | [] | MerkleTree.New.High.sha256_compress | {
"file_name": "src/MerkleTree.New.High.fst",
"git_rev": "3b0f086655c145aa23f58a97259ebf4cf112a4a3",
"git_url": "https://github.com/hacl-star/merkle-tree.git",
"project_name": "merkle-tree"
} | src1: MerkleTree.New.High.hash -> src2: MerkleTree.New.High.hash
-> Prims.GTot MerkleTree.New.High.hash | {
"end_col": 41,
"end_line": 27,
"start_col": 22,
"start_line": 27
} |
Prims.GTot | val path_insert: (#hsz:pos) -> p:path #hsz -> hp:hash #hsz -> GTot (path #hsz) | [
{
"abbrev": true,
"full_module": "MerkleTree.Spec",
"short_module": "MTS"
},
{
"abbrev": true,
"full_module": "FStar.UInt8",
"short_module": "U8"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "S"
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Ghost",
"short_module": null
},
{
"abbrev": false,
"full_module": "MerkleTree.New",
"short_module": null
},
{
"abbrev": false,
"full_module": "MerkleTree.New",
"short_module": null
},
{
"abbrev": 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 path_insert #_ p hp = S.snoc p hp | val path_insert: (#hsz:pos) -> p:path #hsz -> hp:hash #hsz -> GTot (path #hsz)
let path_insert #_ p hp = | false | null | false | S.snoc p hp | {
"checked_file": "MerkleTree.New.High.fst.checked",
"dependencies": [
"Spec.Hash.Definitions.fst.checked",
"prims.fst.checked",
"MerkleTree.Spec.fst.checked",
"Lib.IntTypes.fsti.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "MerkleTree.New.High.fst"
} | [
"sometrivial"
] | [
"Prims.pos",
"MerkleTree.New.High.path",
"MerkleTree.New.High.hash",
"FStar.Seq.Properties.snoc"
] | [] | module MerkleTree.New.High
open FStar.Ghost
open FStar.Seq
module S = FStar.Seq
module U32 = FStar.UInt32
module U8 = FStar.UInt8
module MTS = MerkleTree.Spec
#set-options "--z3rlimit 10 --max_fuel 0 --max_ifuel 0"
type uint32_t = U32.t
type uint8_t = U8.t
type hash (#hsz:pos) = b:Spec.Hash.Definitions.bytes{Seq.length b = hsz}
type hashes (#hsz:pos) = S.seq (hash #hsz)
type hashess (#hsz:pos) = S.seq (hashes #hsz)
noextract
let hash_init (#hsz:pos): hash #hsz =
Seq.create hsz (Lib.IntTypes.u8 0)
val sha256_compress: src1:hash #32 -> src2:hash #32 -> GTot (hash #32)
let sha256_compress = MTS.sha256_compress
/// Facts about sequences
val seq_slice_equal_index:
#a:Type -> s1:S.seq a -> s2:S.seq a ->
i:nat -> j:nat{i <= j && j <= S.length s1 && j <= S.length s2} ->
k:nat{i <= k && k < j} ->
Lemma (requires S.equal (S.slice s1 i j) (S.slice s2 i j))
(ensures S.index s1 k == S.index s2 k)
[SMTPat (S.equal (S.slice s1 i j) (S.slice s2 i j));
SMTPat (S.index s1 k)]
let seq_slice_equal_index #a s1 s2 i j k =
assert (S.index (S.slice s1 i j) (k - i) == S.index (S.slice s2 i j) (k - i))
private val seq_slice_more_equal:
#a:Type -> s1:S.seq a -> s2:S.seq a ->
n:nat -> m:nat{n <= m && m <= S.length s1 && m <= S.length s2} ->
k:nat{n <= k} -> l:nat{k <= l && l <= m} ->
Lemma (requires S.equal (S.slice s1 n m) (S.slice s2 n m))
(ensures S.equal (S.slice s1 k l) (S.slice s2 k l))
[SMTPat (S.equal (S.slice s1 n m) (S.slice s2 n m));
SMTPat (S.equal (S.slice s1 k l) (S.slice s2 k l))]
private let seq_slice_more_equal #a s1 s2 n m k l =
slice_slice s1 n m (k - n) (l - n);
slice_slice s2 n m (k - n) (l - n)
/// Facts about "2"
val remainder_2_not_1_div: n:nat ->
Lemma (requires n % 2 <> 1)
(ensures n / 2 = (n + 1) / 2)
let remainder_2_not_1_div n = ()
val remainder_2_1_div: n:nat ->
Lemma (requires n % 2 = 1)
(ensures n / 2 + 1 = (n + 1) / 2)
let remainder_2_1_div n = ()
/// High-level Merkle tree data structure
noeq type merkle_tree (#hsz:pos) =
| MT: i:nat ->
j:nat{i <= j && j < pow2 32} ->
hs:hashess #hsz {S.length hs = 32} ->
rhs_ok:bool ->
rhs:hashes #hsz {S.length rhs = 32} -> // Rightmost hashes
mroot:hash #hsz ->
hash_fun:MTS.hash_fun_t #hsz ->
merkle_tree #hsz
val mt_not_full (#hsz:pos): merkle_tree #hsz -> GTot bool
let mt_not_full #hsz mt =
MT?.j mt < pow2 32 - 1
val mt_empty (#hsz:pos): merkle_tree #hsz -> GTot bool
let mt_empty #hsz mt =
MT?.j mt = 0
val mt_not_empty (#hsz:pos): merkle_tree #hsz -> GTot bool
let mt_not_empty #hsz mt =
MT?.j mt > 0
/// Well-formedness w.r.t. indices of base hash elements
noextract
val offset_of: i:nat -> Tot nat
let offset_of i =
if i % 2 = 0 then i else i - 1
val hs_wf_elts:
#hsz:pos ->
lv:nat{lv <= 32} ->
hs:hashess #hsz {S.length hs = 32} ->
i:nat -> j:nat{j >= i} ->
GTot Type0 (decreases (32 - lv))
let rec hs_wf_elts #hsz lv hs i j =
if lv = 32 then true
else (let ofs = offset_of i in
S.length (S.index hs lv) == j - ofs /\
hs_wf_elts #hsz (lv + 1) hs (i / 2) (j / 2))
#push-options "--max_fuel 1"
val hs_wf_elts_equal:
#hsz:pos ->
lv:nat{lv <= 32} ->
hs1:hashess #hsz {S.length hs1 = 32} ->
hs2:hashess #hsz {S.length hs2 = 32} ->
i:nat ->
j:nat{j >= i} ->
Lemma (requires hs_wf_elts lv hs1 i j /\
S.equal (S.slice hs1 lv 32) (S.slice hs2 lv 32))
(ensures hs_wf_elts lv hs2 i j)
(decreases (32 - lv))
let rec hs_wf_elts_equal #hsz lv hs1 hs2 i j =
if lv = 32 then ()
else (S.slice_slice hs1 lv 32 1 (32 - lv);
S.slice_slice hs2 lv 32 1 (32 - lv);
assert (S.equal (S.slice hs1 (lv + 1) 32)
(S.slice hs2 (lv + 1) 32));
S.lemma_index_slice hs1 lv 32 0;
S.lemma_index_slice hs2 lv 32 0;
assert (S.index hs1 lv == S.index hs2 lv);
hs_wf_elts_equal (lv + 1) hs1 hs2 (i / 2) (j / 2))
val mt_wf_elts (#hsz:pos): merkle_tree #hsz -> GTot Type0
let mt_wf_elts #_ (MT i j hs _ _ _ _) =
hs_wf_elts 0 hs i j
/// Construction
val hs_wf_elts_empty:
#hsz:pos ->
lv:nat{lv <= 32} ->
Lemma (requires True)
(ensures hs_wf_elts #hsz lv (S.create 32 S.empty) 0 0)
(decreases (32 - lv))
let rec hs_wf_elts_empty #hsz lv =
if lv = 32 then ()
else hs_wf_elts_empty #hsz (lv + 1)
// NOTE: the public function is `create_mt` defined below, which
// builds a tree with an initial hash.
noextract inline_for_extraction
val create_empty_mt (#hsz:pos) (#f:MTS.hash_fun_t #hsz): unit -> GTot (mt:merkle_tree #hsz {mt_wf_elts #hsz mt})
let create_empty_mt #hsz #f _ =
hs_wf_elts_empty #hsz 0;
MT 0 0 (S.create 32 S.empty) false (S.create 32 (hash_init #hsz)) (hash_init #hsz) f
/// Insertion
val hashess_insert:
#hsz:pos ->
lv:nat{lv < 32} ->
i:nat ->
j:nat{i <= j /\ j < pow2 (32 - lv) - 1} ->
hs:hashess #hsz {S.length hs = 32 /\ hs_wf_elts lv hs i j} ->
v:hash #hsz ->
GTot (ihs:hashess #hsz {S.length ihs = 32 /\ hs_wf_elts (lv + 1) ihs (i / 2) (j / 2)})
let hashess_insert #hsz lv i j hs v =
let ihs = S.upd hs lv (S.snoc (S.index hs lv) v) in
hs_wf_elts_equal (lv + 1) hs ihs (i / 2) (j / 2);
ihs
val insert_:
#hsz:pos -> #f:MTS.hash_fun_t #hsz ->
lv:nat{lv < 32} ->
i:nat ->
j:nat{i <= j /\ j < pow2 (32 - lv) - 1} ->
hs:hashess #hsz {S.length hs = 32 /\ hs_wf_elts lv hs i j} ->
acc:hash #hsz ->
GTot (ihs:hashess #hsz {
S.length ihs = 32 /\
hs_wf_elts #hsz lv ihs i (j + 1) /\
S.equal (S.slice hs 0 lv) (S.slice ihs 0 lv)})
(decreases j)
let rec insert_ #hsz #f lv i j hs acc =
let ihs = hashess_insert #hsz lv i j hs acc in
assert (S.equal (S.slice hs 0 lv) (S.slice ihs 0 lv));
if j % 2 = 1 // S.length (S.index hs lv) > 0
then begin
remainder_2_1_div j;
let nacc = f (S.last (S.index hs lv)) acc in
let rihs = insert_ #hsz #f (lv + 1) (i / 2) (j / 2) ihs nacc in
assert (hs_wf_elts #hsz (lv + 1) rihs (i / 2) (j / 2 + 1));
assert (S.equal (S.slice ihs 0 (lv + 1)) (S.slice rihs 0 (lv + 1)));
assert (S.index ihs lv == S.index rihs lv);
assert (S.length (S.index rihs lv) = (j + 1) - offset_of i);
assert (S.equal (S.slice ihs 0 (lv + 1)) (S.slice rihs 0 (lv + 1)));
assert (S.equal (S.slice ihs 0 lv) (S.slice rihs 0 lv));
rihs
end
else ihs
val insert_base:
#hsz:pos -> #f:MTS.hash_fun_t #hsz ->
lv:nat -> i:nat -> j:nat -> hs:hashess #hsz -> acc:hash #hsz ->
Lemma (requires
lv < 32 /\ i <= j /\ j < pow2 (32 - lv) - 1 /\
S.length hs = 32 /\ hs_wf_elts lv hs i j /\
j % 2 <> 1)
(ensures S.equal (insert_ #_ #f lv i j hs acc)
(hashess_insert lv i j hs acc))
let insert_base #_ #_ lv i j hs acc = ()
val insert_rec:
#hsz:pos -> #f:MTS.hash_fun_t #hsz ->
lv:nat -> i:nat -> j:nat -> hs:hashess -> acc:hash ->
Lemma (requires
lv < 32 /\ i <= j /\ j < pow2 (32 - lv) - 1 /\
S.length hs = 32 /\ hs_wf_elts lv hs i j /\
j % 2 == 1)
(ensures
(hs_wf_elts_equal (lv + 1) hs
(hashess_insert lv i j hs acc) (i / 2) (j / 2);
S.equal (insert_ #_ #f lv i j hs acc)
(insert_ #_ #f (lv + 1) (i / 2) (j / 2)
(hashess_insert lv i j hs acc)
(f (S.last (S.index hs lv)) acc))))
let insert_rec #_ #_ lv i j hs acc = ()
val mt_insert:
#hsz:pos ->
mt:merkle_tree #hsz {mt_wf_elts mt /\ mt_not_full mt} -> v:hash #hsz ->
GTot (imt:merkle_tree #hsz{mt_wf_elts #hsz imt})
let mt_insert #hsz mt v =
MT (MT?.i mt)
(MT?.j mt + 1)
(insert_ #_ #(MT?.hash_fun mt) 0 (MT?.i mt) (MT?.j mt) (MT?.hs mt) v)
false
(MT?.rhs mt)
(MT?.mroot mt)
(MT?.hash_fun mt)
val mt_create:
hsz:pos -> f:MTS.hash_fun_t #hsz ->
init:hash #hsz -> GTot (mt:merkle_tree{mt_wf_elts #hsz mt})
let mt_create hsz f init =
mt_insert #_ (create_empty_mt #_ #f ()) init
/// Getting the Merkle root and path
type path (#hsz:pos) = S.seq (hash #hsz)
// Construct the rightmost hashes for a given (incomplete) Merkle tree.
// This function calculates the Merkle root as well, which is the final
// accumulator value.
val construct_rhs:
#hsz:pos -> #f:MTS.hash_fun_t #hsz ->
lv:nat{lv <= 32} ->
hs:hashess #hsz {S.length hs = 32} ->
rhs:hashes #hsz {S.length rhs = 32} ->
i:nat ->
j:nat{
i <= j /\ j < pow2 (32 - lv) /\
hs_wf_elts #hsz lv hs i j} ->
acc:hash #hsz ->
actd:bool ->
GTot (crhs:hashes #hsz {S.length crhs = 32} * (hash #hsz))
(decreases j)
let rec construct_rhs #hsz #f lv hs rhs i j acc actd =
let ofs = offset_of i in
if j = 0 then (rhs, acc)
else
(if j % 2 = 0
then (construct_rhs #_ #f (lv + 1) hs rhs (i / 2) (j / 2) acc actd)
else (let nrhs = if actd then S.upd rhs lv acc else rhs in
let nacc = if actd
then f (S.index (S.index hs lv) (j - 1 - ofs)) acc
else S.index (S.index hs lv) (j - 1 - ofs) in
construct_rhs #_ #f (lv + 1) hs nrhs (i / 2) (j / 2) nacc true))
val construct_rhs_unchanged:
#hsz:pos -> #f:MTS.hash_fun_t #hsz ->
lv:nat{lv <= 32} ->
hs:hashess #hsz {S.length hs = 32} ->
rhs:hashes #hsz {S.length rhs = 32} ->
i:nat ->
j:nat{
i <= j /\ j < pow2 (32 - lv) /\
hs_wf_elts #hsz lv hs i j} ->
acc:hash #hsz ->
actd:bool ->
Lemma (requires True)
(ensures S.equal (S.slice rhs 0 lv)
(S.slice (fst (construct_rhs #_ #f lv hs rhs i j acc actd)) 0 lv))
(decreases j)
let rec construct_rhs_unchanged #hsz #f lv hs rhs i j acc actd =
let ofs = offset_of i in
if j = 0 then ()
else if j % 2 = 0
then (construct_rhs_unchanged #_ #f (lv + 1) hs rhs (i / 2) (j / 2) acc actd;
let rrhs = fst (construct_rhs #_ #f (lv + 1) hs rhs (i / 2) (j / 2) acc actd) in
assert (S.equal (S.slice rhs 0 lv) (S.slice rrhs 0 lv)))
else (let nrhs = if actd then S.upd rhs lv acc else rhs in
let nacc = if actd
then f (S.index (S.index hs lv) (j - 1 - ofs)) acc
else S.index (S.index hs lv) (j - 1 - ofs) in
construct_rhs_unchanged #_ #f (lv + 1) hs nrhs (i / 2) (j / 2) nacc true;
let rrhs = fst (construct_rhs #_ #f (lv + 1) hs nrhs (i / 2) (j / 2) nacc true) in
assert (S.equal (S.slice nrhs 0 lv) (S.slice rrhs 0 lv));
assert (S.equal (S.slice rhs 0 lv) (S.slice nrhs 0 lv)))
val construct_rhs_even:
#hsz:pos -> #f:MTS.hash_fun_t #hsz ->
lv:nat{lv <= 32} ->
hs:hashess #hsz {S.length hs = 32} ->
rhs:hashes #hsz {S.length rhs = 32} ->
i:nat ->
j:nat{
i <= j /\ j < pow2 (32 - lv) /\
hs_wf_elts #hsz lv hs i j} ->
acc:hash #hsz ->
actd:bool ->
Lemma (requires j <> 0 /\ j % 2 = 0)
(ensures construct_rhs #_ #f lv hs rhs i j acc actd ==
construct_rhs #_ #f (lv + 1) hs rhs (i / 2) (j / 2) acc actd)
let construct_rhs_even #_ #_ _ _ _ _ _ _ _ = ()
val construct_rhs_odd:
#hsz:pos -> #f:MTS.hash_fun_t #hsz ->
lv:nat{lv <= 32} ->
hs:hashess #hsz {S.length hs = 32} ->
rhs:hashes #hsz {S.length rhs = 32} ->
i:nat ->
j:nat{
i <= j /\ j < pow2 (32 - lv) /\
hs_wf_elts lv hs i j} ->
acc:hash ->
actd:bool ->
Lemma (requires j % 2 = 1)
(ensures construct_rhs #_ #f lv hs rhs i j acc actd ==
(let ofs = offset_of i in
let nrhs = if actd then S.upd rhs lv acc else rhs in
let nacc = if actd
then f (S.index (S.index hs lv) (j - 1 - ofs)) acc
else S.index (S.index hs lv) (j - 1 - ofs) in
construct_rhs #_ #f (lv + 1) hs nrhs (i / 2) (j / 2) nacc true))
let construct_rhs_odd #_ #_ _ _ _ _ _ _ _ = ()
val mt_get_root:
#hsz:pos ->
mt:merkle_tree #hsz {mt_wf_elts #hsz mt} -> drt:hash #hsz ->
GTot (merkle_tree #hsz * hash #hsz)
let mt_get_root #hsz mt drt =
if MT?.rhs_ok mt then (mt, MT?.mroot mt)
else begin
let (nrhs, rt) = construct_rhs #_ #(MT?.hash_fun mt) 0 (MT?.hs mt) (MT?.rhs mt) (MT?.i mt) (MT?.j mt) drt false in
(MT (MT?.i mt) (MT?.j mt) (MT?.hs mt) true nrhs rt (MT?.hash_fun mt), rt)
end
val mt_get_root_rhs_ok_true:
#hsz:pos ->
mt:merkle_tree #hsz {mt_wf_elts mt} -> drt:hash #hsz ->
Lemma (requires MT?.rhs_ok mt == true)
(ensures mt_get_root #hsz mt drt == (mt, MT?.mroot mt))
let mt_get_root_rhs_ok_true #hsz mt drt = ()
val mt_get_root_rhs_ok_false:
#hsz:pos ->
mt:merkle_tree #hsz {mt_wf_elts mt} -> drt:hash ->
Lemma (requires MT?.rhs_ok mt == false)
(ensures mt_get_root mt drt ==
(let (nrhs, rt) =
construct_rhs #_ #(MT?.hash_fun mt)
0 (MT?.hs mt) (MT?.rhs mt) (MT?.i mt) (MT?.j mt)
drt false in
(MT (MT?.i mt) (MT?.j mt) (MT?.hs mt) true nrhs rt (MT?.hash_fun mt), rt)))
let mt_get_root_rhs_ok_false #_ _ _ = () | false | false | MerkleTree.New.High.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 1,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 10,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val path_insert: (#hsz:pos) -> p:path #hsz -> hp:hash #hsz -> GTot (path #hsz) | [] | MerkleTree.New.High.path_insert | {
"file_name": "src/MerkleTree.New.High.fst",
"git_rev": "3b0f086655c145aa23f58a97259ebf4cf112a4a3",
"git_url": "https://github.com/hacl-star/merkle-tree.git",
"project_name": "merkle-tree"
} | p: MerkleTree.New.High.path -> hp: MerkleTree.New.High.hash -> Prims.GTot MerkleTree.New.High.path | {
"end_col": 37,
"end_line": 380,
"start_col": 26,
"start_line": 380
} |
Prims.GTot | val mt_not_empty (#hsz:pos): merkle_tree #hsz -> GTot bool | [
{
"abbrev": true,
"full_module": "MerkleTree.Spec",
"short_module": "MTS"
},
{
"abbrev": true,
"full_module": "FStar.UInt8",
"short_module": "U8"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "S"
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Ghost",
"short_module": null
},
{
"abbrev": false,
"full_module": "MerkleTree.New",
"short_module": null
},
{
"abbrev": false,
"full_module": "MerkleTree.New",
"short_module": null
},
{
"abbrev": 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 mt_not_empty #hsz mt =
MT?.j mt > 0 | val mt_not_empty (#hsz:pos): merkle_tree #hsz -> GTot bool
let mt_not_empty #hsz mt = | false | null | false | MT?.j mt > 0 | {
"checked_file": "MerkleTree.New.High.fst.checked",
"dependencies": [
"Spec.Hash.Definitions.fst.checked",
"prims.fst.checked",
"MerkleTree.Spec.fst.checked",
"Lib.IntTypes.fsti.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "MerkleTree.New.High.fst"
} | [
"sometrivial"
] | [
"Prims.pos",
"MerkleTree.New.High.merkle_tree",
"Prims.op_GreaterThan",
"MerkleTree.New.High.__proj__MT__item__j",
"Prims.bool"
] | [] | module MerkleTree.New.High
open FStar.Ghost
open FStar.Seq
module S = FStar.Seq
module U32 = FStar.UInt32
module U8 = FStar.UInt8
module MTS = MerkleTree.Spec
#set-options "--z3rlimit 10 --max_fuel 0 --max_ifuel 0"
type uint32_t = U32.t
type uint8_t = U8.t
type hash (#hsz:pos) = b:Spec.Hash.Definitions.bytes{Seq.length b = hsz}
type hashes (#hsz:pos) = S.seq (hash #hsz)
type hashess (#hsz:pos) = S.seq (hashes #hsz)
noextract
let hash_init (#hsz:pos): hash #hsz =
Seq.create hsz (Lib.IntTypes.u8 0)
val sha256_compress: src1:hash #32 -> src2:hash #32 -> GTot (hash #32)
let sha256_compress = MTS.sha256_compress
/// Facts about sequences
val seq_slice_equal_index:
#a:Type -> s1:S.seq a -> s2:S.seq a ->
i:nat -> j:nat{i <= j && j <= S.length s1 && j <= S.length s2} ->
k:nat{i <= k && k < j} ->
Lemma (requires S.equal (S.slice s1 i j) (S.slice s2 i j))
(ensures S.index s1 k == S.index s2 k)
[SMTPat (S.equal (S.slice s1 i j) (S.slice s2 i j));
SMTPat (S.index s1 k)]
let seq_slice_equal_index #a s1 s2 i j k =
assert (S.index (S.slice s1 i j) (k - i) == S.index (S.slice s2 i j) (k - i))
private val seq_slice_more_equal:
#a:Type -> s1:S.seq a -> s2:S.seq a ->
n:nat -> m:nat{n <= m && m <= S.length s1 && m <= S.length s2} ->
k:nat{n <= k} -> l:nat{k <= l && l <= m} ->
Lemma (requires S.equal (S.slice s1 n m) (S.slice s2 n m))
(ensures S.equal (S.slice s1 k l) (S.slice s2 k l))
[SMTPat (S.equal (S.slice s1 n m) (S.slice s2 n m));
SMTPat (S.equal (S.slice s1 k l) (S.slice s2 k l))]
private let seq_slice_more_equal #a s1 s2 n m k l =
slice_slice s1 n m (k - n) (l - n);
slice_slice s2 n m (k - n) (l - n)
/// Facts about "2"
val remainder_2_not_1_div: n:nat ->
Lemma (requires n % 2 <> 1)
(ensures n / 2 = (n + 1) / 2)
let remainder_2_not_1_div n = ()
val remainder_2_1_div: n:nat ->
Lemma (requires n % 2 = 1)
(ensures n / 2 + 1 = (n + 1) / 2)
let remainder_2_1_div n = ()
/// High-level Merkle tree data structure
noeq type merkle_tree (#hsz:pos) =
| MT: i:nat ->
j:nat{i <= j && j < pow2 32} ->
hs:hashess #hsz {S.length hs = 32} ->
rhs_ok:bool ->
rhs:hashes #hsz {S.length rhs = 32} -> // Rightmost hashes
mroot:hash #hsz ->
hash_fun:MTS.hash_fun_t #hsz ->
merkle_tree #hsz
val mt_not_full (#hsz:pos): merkle_tree #hsz -> GTot bool
let mt_not_full #hsz mt =
MT?.j mt < pow2 32 - 1
val mt_empty (#hsz:pos): merkle_tree #hsz -> GTot bool
let mt_empty #hsz mt =
MT?.j mt = 0
val mt_not_empty (#hsz:pos): merkle_tree #hsz -> GTot bool | false | false | MerkleTree.New.High.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 10,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val mt_not_empty (#hsz:pos): merkle_tree #hsz -> GTot bool | [] | MerkleTree.New.High.mt_not_empty | {
"file_name": "src/MerkleTree.New.High.fst",
"git_rev": "3b0f086655c145aa23f58a97259ebf4cf112a4a3",
"git_url": "https://github.com/hacl-star/merkle-tree.git",
"project_name": "merkle-tree"
} | mt: MerkleTree.New.High.merkle_tree -> Prims.GTot Prims.bool | {
"end_col": 14,
"end_line": 89,
"start_col": 2,
"start_line": 89
} |
Prims.GTot | val mt_not_full (#hsz:pos): merkle_tree #hsz -> GTot bool | [
{
"abbrev": true,
"full_module": "MerkleTree.Spec",
"short_module": "MTS"
},
{
"abbrev": true,
"full_module": "FStar.UInt8",
"short_module": "U8"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "S"
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Ghost",
"short_module": null
},
{
"abbrev": false,
"full_module": "MerkleTree.New",
"short_module": null
},
{
"abbrev": false,
"full_module": "MerkleTree.New",
"short_module": null
},
{
"abbrev": 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 mt_not_full #hsz mt =
MT?.j mt < pow2 32 - 1 | val mt_not_full (#hsz:pos): merkle_tree #hsz -> GTot bool
let mt_not_full #hsz mt = | false | null | false | MT?.j mt < pow2 32 - 1 | {
"checked_file": "MerkleTree.New.High.fst.checked",
"dependencies": [
"Spec.Hash.Definitions.fst.checked",
"prims.fst.checked",
"MerkleTree.Spec.fst.checked",
"Lib.IntTypes.fsti.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "MerkleTree.New.High.fst"
} | [
"sometrivial"
] | [
"Prims.pos",
"MerkleTree.New.High.merkle_tree",
"Prims.op_LessThan",
"MerkleTree.New.High.__proj__MT__item__j",
"Prims.op_Subtraction",
"Prims.pow2",
"Prims.bool"
] | [] | module MerkleTree.New.High
open FStar.Ghost
open FStar.Seq
module S = FStar.Seq
module U32 = FStar.UInt32
module U8 = FStar.UInt8
module MTS = MerkleTree.Spec
#set-options "--z3rlimit 10 --max_fuel 0 --max_ifuel 0"
type uint32_t = U32.t
type uint8_t = U8.t
type hash (#hsz:pos) = b:Spec.Hash.Definitions.bytes{Seq.length b = hsz}
type hashes (#hsz:pos) = S.seq (hash #hsz)
type hashess (#hsz:pos) = S.seq (hashes #hsz)
noextract
let hash_init (#hsz:pos): hash #hsz =
Seq.create hsz (Lib.IntTypes.u8 0)
val sha256_compress: src1:hash #32 -> src2:hash #32 -> GTot (hash #32)
let sha256_compress = MTS.sha256_compress
/// Facts about sequences
val seq_slice_equal_index:
#a:Type -> s1:S.seq a -> s2:S.seq a ->
i:nat -> j:nat{i <= j && j <= S.length s1 && j <= S.length s2} ->
k:nat{i <= k && k < j} ->
Lemma (requires S.equal (S.slice s1 i j) (S.slice s2 i j))
(ensures S.index s1 k == S.index s2 k)
[SMTPat (S.equal (S.slice s1 i j) (S.slice s2 i j));
SMTPat (S.index s1 k)]
let seq_slice_equal_index #a s1 s2 i j k =
assert (S.index (S.slice s1 i j) (k - i) == S.index (S.slice s2 i j) (k - i))
private val seq_slice_more_equal:
#a:Type -> s1:S.seq a -> s2:S.seq a ->
n:nat -> m:nat{n <= m && m <= S.length s1 && m <= S.length s2} ->
k:nat{n <= k} -> l:nat{k <= l && l <= m} ->
Lemma (requires S.equal (S.slice s1 n m) (S.slice s2 n m))
(ensures S.equal (S.slice s1 k l) (S.slice s2 k l))
[SMTPat (S.equal (S.slice s1 n m) (S.slice s2 n m));
SMTPat (S.equal (S.slice s1 k l) (S.slice s2 k l))]
private let seq_slice_more_equal #a s1 s2 n m k l =
slice_slice s1 n m (k - n) (l - n);
slice_slice s2 n m (k - n) (l - n)
/// Facts about "2"
val remainder_2_not_1_div: n:nat ->
Lemma (requires n % 2 <> 1)
(ensures n / 2 = (n + 1) / 2)
let remainder_2_not_1_div n = ()
val remainder_2_1_div: n:nat ->
Lemma (requires n % 2 = 1)
(ensures n / 2 + 1 = (n + 1) / 2)
let remainder_2_1_div n = ()
/// High-level Merkle tree data structure
noeq type merkle_tree (#hsz:pos) =
| MT: i:nat ->
j:nat{i <= j && j < pow2 32} ->
hs:hashess #hsz {S.length hs = 32} ->
rhs_ok:bool ->
rhs:hashes #hsz {S.length rhs = 32} -> // Rightmost hashes
mroot:hash #hsz ->
hash_fun:MTS.hash_fun_t #hsz ->
merkle_tree #hsz
val mt_not_full (#hsz:pos): merkle_tree #hsz -> GTot bool | false | false | MerkleTree.New.High.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 10,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val mt_not_full (#hsz:pos): merkle_tree #hsz -> GTot bool | [] | MerkleTree.New.High.mt_not_full | {
"file_name": "src/MerkleTree.New.High.fst",
"git_rev": "3b0f086655c145aa23f58a97259ebf4cf112a4a3",
"git_url": "https://github.com/hacl-star/merkle-tree.git",
"project_name": "merkle-tree"
} | mt: MerkleTree.New.High.merkle_tree -> Prims.GTot Prims.bool | {
"end_col": 24,
"end_line": 81,
"start_col": 2,
"start_line": 81
} |
Prims.GTot | val mt_wf_elts (#hsz:pos): merkle_tree #hsz -> GTot Type0 | [
{
"abbrev": true,
"full_module": "MerkleTree.Spec",
"short_module": "MTS"
},
{
"abbrev": true,
"full_module": "FStar.UInt8",
"short_module": "U8"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "S"
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Ghost",
"short_module": null
},
{
"abbrev": false,
"full_module": "MerkleTree.New",
"short_module": null
},
{
"abbrev": false,
"full_module": "MerkleTree.New",
"short_module": null
},
{
"abbrev": 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 mt_wf_elts #_ (MT i j hs _ _ _ _) =
hs_wf_elts 0 hs i j | val mt_wf_elts (#hsz:pos): merkle_tree #hsz -> GTot Type0
let mt_wf_elts #_ (MT i j hs _ _ _ _) = | false | null | false | hs_wf_elts 0 hs i j | {
"checked_file": "MerkleTree.New.High.fst.checked",
"dependencies": [
"Spec.Hash.Definitions.fst.checked",
"prims.fst.checked",
"MerkleTree.Spec.fst.checked",
"Lib.IntTypes.fsti.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "MerkleTree.New.High.fst"
} | [
"sometrivial"
] | [
"Prims.pos",
"MerkleTree.New.High.merkle_tree",
"Prims.nat",
"Prims.b2t",
"Prims.op_AmpAmp",
"Prims.op_LessThanOrEqual",
"Prims.op_LessThan",
"Prims.pow2",
"MerkleTree.New.High.hashess",
"Prims.op_Equality",
"Prims.int",
"FStar.Seq.Base.length",
"MerkleTree.New.High.hashes",
"Prims.bool",
"MerkleTree.New.High.hash",
"MerkleTree.Spec.hash_fun_t",
"MerkleTree.New.High.hs_wf_elts"
] | [] | module MerkleTree.New.High
open FStar.Ghost
open FStar.Seq
module S = FStar.Seq
module U32 = FStar.UInt32
module U8 = FStar.UInt8
module MTS = MerkleTree.Spec
#set-options "--z3rlimit 10 --max_fuel 0 --max_ifuel 0"
type uint32_t = U32.t
type uint8_t = U8.t
type hash (#hsz:pos) = b:Spec.Hash.Definitions.bytes{Seq.length b = hsz}
type hashes (#hsz:pos) = S.seq (hash #hsz)
type hashess (#hsz:pos) = S.seq (hashes #hsz)
noextract
let hash_init (#hsz:pos): hash #hsz =
Seq.create hsz (Lib.IntTypes.u8 0)
val sha256_compress: src1:hash #32 -> src2:hash #32 -> GTot (hash #32)
let sha256_compress = MTS.sha256_compress
/// Facts about sequences
val seq_slice_equal_index:
#a:Type -> s1:S.seq a -> s2:S.seq a ->
i:nat -> j:nat{i <= j && j <= S.length s1 && j <= S.length s2} ->
k:nat{i <= k && k < j} ->
Lemma (requires S.equal (S.slice s1 i j) (S.slice s2 i j))
(ensures S.index s1 k == S.index s2 k)
[SMTPat (S.equal (S.slice s1 i j) (S.slice s2 i j));
SMTPat (S.index s1 k)]
let seq_slice_equal_index #a s1 s2 i j k =
assert (S.index (S.slice s1 i j) (k - i) == S.index (S.slice s2 i j) (k - i))
private val seq_slice_more_equal:
#a:Type -> s1:S.seq a -> s2:S.seq a ->
n:nat -> m:nat{n <= m && m <= S.length s1 && m <= S.length s2} ->
k:nat{n <= k} -> l:nat{k <= l && l <= m} ->
Lemma (requires S.equal (S.slice s1 n m) (S.slice s2 n m))
(ensures S.equal (S.slice s1 k l) (S.slice s2 k l))
[SMTPat (S.equal (S.slice s1 n m) (S.slice s2 n m));
SMTPat (S.equal (S.slice s1 k l) (S.slice s2 k l))]
private let seq_slice_more_equal #a s1 s2 n m k l =
slice_slice s1 n m (k - n) (l - n);
slice_slice s2 n m (k - n) (l - n)
/// Facts about "2"
val remainder_2_not_1_div: n:nat ->
Lemma (requires n % 2 <> 1)
(ensures n / 2 = (n + 1) / 2)
let remainder_2_not_1_div n = ()
val remainder_2_1_div: n:nat ->
Lemma (requires n % 2 = 1)
(ensures n / 2 + 1 = (n + 1) / 2)
let remainder_2_1_div n = ()
/// High-level Merkle tree data structure
noeq type merkle_tree (#hsz:pos) =
| MT: i:nat ->
j:nat{i <= j && j < pow2 32} ->
hs:hashess #hsz {S.length hs = 32} ->
rhs_ok:bool ->
rhs:hashes #hsz {S.length rhs = 32} -> // Rightmost hashes
mroot:hash #hsz ->
hash_fun:MTS.hash_fun_t #hsz ->
merkle_tree #hsz
val mt_not_full (#hsz:pos): merkle_tree #hsz -> GTot bool
let mt_not_full #hsz mt =
MT?.j mt < pow2 32 - 1
val mt_empty (#hsz:pos): merkle_tree #hsz -> GTot bool
let mt_empty #hsz mt =
MT?.j mt = 0
val mt_not_empty (#hsz:pos): merkle_tree #hsz -> GTot bool
let mt_not_empty #hsz mt =
MT?.j mt > 0
/// Well-formedness w.r.t. indices of base hash elements
noextract
val offset_of: i:nat -> Tot nat
let offset_of i =
if i % 2 = 0 then i else i - 1
val hs_wf_elts:
#hsz:pos ->
lv:nat{lv <= 32} ->
hs:hashess #hsz {S.length hs = 32} ->
i:nat -> j:nat{j >= i} ->
GTot Type0 (decreases (32 - lv))
let rec hs_wf_elts #hsz lv hs i j =
if lv = 32 then true
else (let ofs = offset_of i in
S.length (S.index hs lv) == j - ofs /\
hs_wf_elts #hsz (lv + 1) hs (i / 2) (j / 2))
#push-options "--max_fuel 1"
val hs_wf_elts_equal:
#hsz:pos ->
lv:nat{lv <= 32} ->
hs1:hashess #hsz {S.length hs1 = 32} ->
hs2:hashess #hsz {S.length hs2 = 32} ->
i:nat ->
j:nat{j >= i} ->
Lemma (requires hs_wf_elts lv hs1 i j /\
S.equal (S.slice hs1 lv 32) (S.slice hs2 lv 32))
(ensures hs_wf_elts lv hs2 i j)
(decreases (32 - lv))
let rec hs_wf_elts_equal #hsz lv hs1 hs2 i j =
if lv = 32 then ()
else (S.slice_slice hs1 lv 32 1 (32 - lv);
S.slice_slice hs2 lv 32 1 (32 - lv);
assert (S.equal (S.slice hs1 (lv + 1) 32)
(S.slice hs2 (lv + 1) 32));
S.lemma_index_slice hs1 lv 32 0;
S.lemma_index_slice hs2 lv 32 0;
assert (S.index hs1 lv == S.index hs2 lv);
hs_wf_elts_equal (lv + 1) hs1 hs2 (i / 2) (j / 2))
val mt_wf_elts (#hsz:pos): merkle_tree #hsz -> GTot Type0 | false | false | MerkleTree.New.High.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 1,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 10,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val mt_wf_elts (#hsz:pos): merkle_tree #hsz -> GTot Type0 | [] | MerkleTree.New.High.mt_wf_elts | {
"file_name": "src/MerkleTree.New.High.fst",
"git_rev": "3b0f086655c145aa23f58a97259ebf4cf112a4a3",
"git_url": "https://github.com/hacl-star/merkle-tree.git",
"project_name": "merkle-tree"
} | _: MerkleTree.New.High.merkle_tree -> Prims.GTot Type0 | {
"end_col": 21,
"end_line": 136,
"start_col": 2,
"start_line": 136
} |
Prims.GTot | val mt_insert:
#hsz:pos ->
mt:merkle_tree #hsz {mt_wf_elts mt /\ mt_not_full mt} -> v:hash #hsz ->
GTot (imt:merkle_tree #hsz{mt_wf_elts #hsz imt}) | [
{
"abbrev": true,
"full_module": "MerkleTree.Spec",
"short_module": "MTS"
},
{
"abbrev": true,
"full_module": "FStar.UInt8",
"short_module": "U8"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "S"
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Ghost",
"short_module": null
},
{
"abbrev": false,
"full_module": "MerkleTree.New",
"short_module": null
},
{
"abbrev": false,
"full_module": "MerkleTree.New",
"short_module": null
},
{
"abbrev": 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 mt_insert #hsz mt v =
MT (MT?.i mt)
(MT?.j mt + 1)
(insert_ #_ #(MT?.hash_fun mt) 0 (MT?.i mt) (MT?.j mt) (MT?.hs mt) v)
false
(MT?.rhs mt)
(MT?.mroot mt)
(MT?.hash_fun mt) | val mt_insert:
#hsz:pos ->
mt:merkle_tree #hsz {mt_wf_elts mt /\ mt_not_full mt} -> v:hash #hsz ->
GTot (imt:merkle_tree #hsz{mt_wf_elts #hsz imt})
let mt_insert #hsz mt v = | false | null | false | MT (MT?.i mt)
(MT?.j mt + 1)
(insert_ #_ #(MT?.hash_fun mt) 0 (MT?.i mt) (MT?.j mt) (MT?.hs mt) v)
false
(MT?.rhs mt)
(MT?.mroot mt)
(MT?.hash_fun mt) | {
"checked_file": "MerkleTree.New.High.fst.checked",
"dependencies": [
"Spec.Hash.Definitions.fst.checked",
"prims.fst.checked",
"MerkleTree.Spec.fst.checked",
"Lib.IntTypes.fsti.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "MerkleTree.New.High.fst"
} | [
"sometrivial"
] | [
"Prims.pos",
"MerkleTree.New.High.merkle_tree",
"Prims.l_and",
"MerkleTree.New.High.mt_wf_elts",
"Prims.b2t",
"MerkleTree.New.High.mt_not_full",
"MerkleTree.New.High.hash",
"MerkleTree.New.High.MT",
"MerkleTree.New.High.__proj__MT__item__i",
"Prims.op_Addition",
"MerkleTree.New.High.__proj__MT__item__j",
"MerkleTree.New.High.insert_",
"MerkleTree.New.High.__proj__MT__item__hash_fun",
"MerkleTree.New.High.__proj__MT__item__hs",
"MerkleTree.New.High.__proj__MT__item__rhs",
"MerkleTree.New.High.__proj__MT__item__mroot"
] | [] | module MerkleTree.New.High
open FStar.Ghost
open FStar.Seq
module S = FStar.Seq
module U32 = FStar.UInt32
module U8 = FStar.UInt8
module MTS = MerkleTree.Spec
#set-options "--z3rlimit 10 --max_fuel 0 --max_ifuel 0"
type uint32_t = U32.t
type uint8_t = U8.t
type hash (#hsz:pos) = b:Spec.Hash.Definitions.bytes{Seq.length b = hsz}
type hashes (#hsz:pos) = S.seq (hash #hsz)
type hashess (#hsz:pos) = S.seq (hashes #hsz)
noextract
let hash_init (#hsz:pos): hash #hsz =
Seq.create hsz (Lib.IntTypes.u8 0)
val sha256_compress: src1:hash #32 -> src2:hash #32 -> GTot (hash #32)
let sha256_compress = MTS.sha256_compress
/// Facts about sequences
val seq_slice_equal_index:
#a:Type -> s1:S.seq a -> s2:S.seq a ->
i:nat -> j:nat{i <= j && j <= S.length s1 && j <= S.length s2} ->
k:nat{i <= k && k < j} ->
Lemma (requires S.equal (S.slice s1 i j) (S.slice s2 i j))
(ensures S.index s1 k == S.index s2 k)
[SMTPat (S.equal (S.slice s1 i j) (S.slice s2 i j));
SMTPat (S.index s1 k)]
let seq_slice_equal_index #a s1 s2 i j k =
assert (S.index (S.slice s1 i j) (k - i) == S.index (S.slice s2 i j) (k - i))
private val seq_slice_more_equal:
#a:Type -> s1:S.seq a -> s2:S.seq a ->
n:nat -> m:nat{n <= m && m <= S.length s1 && m <= S.length s2} ->
k:nat{n <= k} -> l:nat{k <= l && l <= m} ->
Lemma (requires S.equal (S.slice s1 n m) (S.slice s2 n m))
(ensures S.equal (S.slice s1 k l) (S.slice s2 k l))
[SMTPat (S.equal (S.slice s1 n m) (S.slice s2 n m));
SMTPat (S.equal (S.slice s1 k l) (S.slice s2 k l))]
private let seq_slice_more_equal #a s1 s2 n m k l =
slice_slice s1 n m (k - n) (l - n);
slice_slice s2 n m (k - n) (l - n)
/// Facts about "2"
val remainder_2_not_1_div: n:nat ->
Lemma (requires n % 2 <> 1)
(ensures n / 2 = (n + 1) / 2)
let remainder_2_not_1_div n = ()
val remainder_2_1_div: n:nat ->
Lemma (requires n % 2 = 1)
(ensures n / 2 + 1 = (n + 1) / 2)
let remainder_2_1_div n = ()
/// High-level Merkle tree data structure
noeq type merkle_tree (#hsz:pos) =
| MT: i:nat ->
j:nat{i <= j && j < pow2 32} ->
hs:hashess #hsz {S.length hs = 32} ->
rhs_ok:bool ->
rhs:hashes #hsz {S.length rhs = 32} -> // Rightmost hashes
mroot:hash #hsz ->
hash_fun:MTS.hash_fun_t #hsz ->
merkle_tree #hsz
val mt_not_full (#hsz:pos): merkle_tree #hsz -> GTot bool
let mt_not_full #hsz mt =
MT?.j mt < pow2 32 - 1
val mt_empty (#hsz:pos): merkle_tree #hsz -> GTot bool
let mt_empty #hsz mt =
MT?.j mt = 0
val mt_not_empty (#hsz:pos): merkle_tree #hsz -> GTot bool
let mt_not_empty #hsz mt =
MT?.j mt > 0
/// Well-formedness w.r.t. indices of base hash elements
noextract
val offset_of: i:nat -> Tot nat
let offset_of i =
if i % 2 = 0 then i else i - 1
val hs_wf_elts:
#hsz:pos ->
lv:nat{lv <= 32} ->
hs:hashess #hsz {S.length hs = 32} ->
i:nat -> j:nat{j >= i} ->
GTot Type0 (decreases (32 - lv))
let rec hs_wf_elts #hsz lv hs i j =
if lv = 32 then true
else (let ofs = offset_of i in
S.length (S.index hs lv) == j - ofs /\
hs_wf_elts #hsz (lv + 1) hs (i / 2) (j / 2))
#push-options "--max_fuel 1"
val hs_wf_elts_equal:
#hsz:pos ->
lv:nat{lv <= 32} ->
hs1:hashess #hsz {S.length hs1 = 32} ->
hs2:hashess #hsz {S.length hs2 = 32} ->
i:nat ->
j:nat{j >= i} ->
Lemma (requires hs_wf_elts lv hs1 i j /\
S.equal (S.slice hs1 lv 32) (S.slice hs2 lv 32))
(ensures hs_wf_elts lv hs2 i j)
(decreases (32 - lv))
let rec hs_wf_elts_equal #hsz lv hs1 hs2 i j =
if lv = 32 then ()
else (S.slice_slice hs1 lv 32 1 (32 - lv);
S.slice_slice hs2 lv 32 1 (32 - lv);
assert (S.equal (S.slice hs1 (lv + 1) 32)
(S.slice hs2 (lv + 1) 32));
S.lemma_index_slice hs1 lv 32 0;
S.lemma_index_slice hs2 lv 32 0;
assert (S.index hs1 lv == S.index hs2 lv);
hs_wf_elts_equal (lv + 1) hs1 hs2 (i / 2) (j / 2))
val mt_wf_elts (#hsz:pos): merkle_tree #hsz -> GTot Type0
let mt_wf_elts #_ (MT i j hs _ _ _ _) =
hs_wf_elts 0 hs i j
/// Construction
val hs_wf_elts_empty:
#hsz:pos ->
lv:nat{lv <= 32} ->
Lemma (requires True)
(ensures hs_wf_elts #hsz lv (S.create 32 S.empty) 0 0)
(decreases (32 - lv))
let rec hs_wf_elts_empty #hsz lv =
if lv = 32 then ()
else hs_wf_elts_empty #hsz (lv + 1)
// NOTE: the public function is `create_mt` defined below, which
// builds a tree with an initial hash.
noextract inline_for_extraction
val create_empty_mt (#hsz:pos) (#f:MTS.hash_fun_t #hsz): unit -> GTot (mt:merkle_tree #hsz {mt_wf_elts #hsz mt})
let create_empty_mt #hsz #f _ =
hs_wf_elts_empty #hsz 0;
MT 0 0 (S.create 32 S.empty) false (S.create 32 (hash_init #hsz)) (hash_init #hsz) f
/// Insertion
val hashess_insert:
#hsz:pos ->
lv:nat{lv < 32} ->
i:nat ->
j:nat{i <= j /\ j < pow2 (32 - lv) - 1} ->
hs:hashess #hsz {S.length hs = 32 /\ hs_wf_elts lv hs i j} ->
v:hash #hsz ->
GTot (ihs:hashess #hsz {S.length ihs = 32 /\ hs_wf_elts (lv + 1) ihs (i / 2) (j / 2)})
let hashess_insert #hsz lv i j hs v =
let ihs = S.upd hs lv (S.snoc (S.index hs lv) v) in
hs_wf_elts_equal (lv + 1) hs ihs (i / 2) (j / 2);
ihs
val insert_:
#hsz:pos -> #f:MTS.hash_fun_t #hsz ->
lv:nat{lv < 32} ->
i:nat ->
j:nat{i <= j /\ j < pow2 (32 - lv) - 1} ->
hs:hashess #hsz {S.length hs = 32 /\ hs_wf_elts lv hs i j} ->
acc:hash #hsz ->
GTot (ihs:hashess #hsz {
S.length ihs = 32 /\
hs_wf_elts #hsz lv ihs i (j + 1) /\
S.equal (S.slice hs 0 lv) (S.slice ihs 0 lv)})
(decreases j)
let rec insert_ #hsz #f lv i j hs acc =
let ihs = hashess_insert #hsz lv i j hs acc in
assert (S.equal (S.slice hs 0 lv) (S.slice ihs 0 lv));
if j % 2 = 1 // S.length (S.index hs lv) > 0
then begin
remainder_2_1_div j;
let nacc = f (S.last (S.index hs lv)) acc in
let rihs = insert_ #hsz #f (lv + 1) (i / 2) (j / 2) ihs nacc in
assert (hs_wf_elts #hsz (lv + 1) rihs (i / 2) (j / 2 + 1));
assert (S.equal (S.slice ihs 0 (lv + 1)) (S.slice rihs 0 (lv + 1)));
assert (S.index ihs lv == S.index rihs lv);
assert (S.length (S.index rihs lv) = (j + 1) - offset_of i);
assert (S.equal (S.slice ihs 0 (lv + 1)) (S.slice rihs 0 (lv + 1)));
assert (S.equal (S.slice ihs 0 lv) (S.slice rihs 0 lv));
rihs
end
else ihs
val insert_base:
#hsz:pos -> #f:MTS.hash_fun_t #hsz ->
lv:nat -> i:nat -> j:nat -> hs:hashess #hsz -> acc:hash #hsz ->
Lemma (requires
lv < 32 /\ i <= j /\ j < pow2 (32 - lv) - 1 /\
S.length hs = 32 /\ hs_wf_elts lv hs i j /\
j % 2 <> 1)
(ensures S.equal (insert_ #_ #f lv i j hs acc)
(hashess_insert lv i j hs acc))
let insert_base #_ #_ lv i j hs acc = ()
val insert_rec:
#hsz:pos -> #f:MTS.hash_fun_t #hsz ->
lv:nat -> i:nat -> j:nat -> hs:hashess -> acc:hash ->
Lemma (requires
lv < 32 /\ i <= j /\ j < pow2 (32 - lv) - 1 /\
S.length hs = 32 /\ hs_wf_elts lv hs i j /\
j % 2 == 1)
(ensures
(hs_wf_elts_equal (lv + 1) hs
(hashess_insert lv i j hs acc) (i / 2) (j / 2);
S.equal (insert_ #_ #f lv i j hs acc)
(insert_ #_ #f (lv + 1) (i / 2) (j / 2)
(hashess_insert lv i j hs acc)
(f (S.last (S.index hs lv)) acc))))
let insert_rec #_ #_ lv i j hs acc = ()
val mt_insert:
#hsz:pos ->
mt:merkle_tree #hsz {mt_wf_elts mt /\ mt_not_full mt} -> v:hash #hsz ->
GTot (imt:merkle_tree #hsz{mt_wf_elts #hsz imt}) | false | false | MerkleTree.New.High.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 1,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 10,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val mt_insert:
#hsz:pos ->
mt:merkle_tree #hsz {mt_wf_elts mt /\ mt_not_full mt} -> v:hash #hsz ->
GTot (imt:merkle_tree #hsz{mt_wf_elts #hsz imt}) | [] | MerkleTree.New.High.mt_insert | {
"file_name": "src/MerkleTree.New.High.fst",
"git_rev": "3b0f086655c145aa23f58a97259ebf4cf112a4a3",
"git_url": "https://github.com/hacl-star/merkle-tree.git",
"project_name": "merkle-tree"
} |
mt:
MerkleTree.New.High.merkle_tree
{MerkleTree.New.High.mt_wf_elts mt /\ MerkleTree.New.High.mt_not_full mt} ->
v: MerkleTree.New.High.hash
-> Prims.GTot (imt: MerkleTree.New.High.merkle_tree{MerkleTree.New.High.mt_wf_elts imt}) | {
"end_col": 22,
"end_line": 241,
"start_col": 2,
"start_line": 235
} |
Prims.GTot | val create_empty_mt (#hsz:pos) (#f:MTS.hash_fun_t #hsz): unit -> GTot (mt:merkle_tree #hsz {mt_wf_elts #hsz mt}) | [
{
"abbrev": true,
"full_module": "MerkleTree.Spec",
"short_module": "MTS"
},
{
"abbrev": true,
"full_module": "FStar.UInt8",
"short_module": "U8"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "S"
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Ghost",
"short_module": null
},
{
"abbrev": false,
"full_module": "MerkleTree.New",
"short_module": null
},
{
"abbrev": false,
"full_module": "MerkleTree.New",
"short_module": null
},
{
"abbrev": 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_empty_mt #hsz #f _ =
hs_wf_elts_empty #hsz 0;
MT 0 0 (S.create 32 S.empty) false (S.create 32 (hash_init #hsz)) (hash_init #hsz) f | val create_empty_mt (#hsz:pos) (#f:MTS.hash_fun_t #hsz): unit -> GTot (mt:merkle_tree #hsz {mt_wf_elts #hsz mt})
let create_empty_mt #hsz #f _ = | false | null | false | hs_wf_elts_empty #hsz 0;
MT 0 0 (S.create 32 S.empty) false (S.create 32 (hash_init #hsz)) (hash_init #hsz) f | {
"checked_file": "MerkleTree.New.High.fst.checked",
"dependencies": [
"Spec.Hash.Definitions.fst.checked",
"prims.fst.checked",
"MerkleTree.Spec.fst.checked",
"Lib.IntTypes.fsti.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "MerkleTree.New.High.fst"
} | [
"sometrivial"
] | [
"Prims.pos",
"MerkleTree.Spec.hash_fun_t",
"Prims.unit",
"MerkleTree.New.High.MT",
"FStar.Seq.Base.create",
"MerkleTree.New.High.hashes",
"FStar.Seq.Base.empty",
"MerkleTree.New.High.hash",
"MerkleTree.New.High.hash_init",
"MerkleTree.New.High.hs_wf_elts_empty",
"MerkleTree.New.High.merkle_tree",
"MerkleTree.New.High.mt_wf_elts"
] | [] | module MerkleTree.New.High
open FStar.Ghost
open FStar.Seq
module S = FStar.Seq
module U32 = FStar.UInt32
module U8 = FStar.UInt8
module MTS = MerkleTree.Spec
#set-options "--z3rlimit 10 --max_fuel 0 --max_ifuel 0"
type uint32_t = U32.t
type uint8_t = U8.t
type hash (#hsz:pos) = b:Spec.Hash.Definitions.bytes{Seq.length b = hsz}
type hashes (#hsz:pos) = S.seq (hash #hsz)
type hashess (#hsz:pos) = S.seq (hashes #hsz)
noextract
let hash_init (#hsz:pos): hash #hsz =
Seq.create hsz (Lib.IntTypes.u8 0)
val sha256_compress: src1:hash #32 -> src2:hash #32 -> GTot (hash #32)
let sha256_compress = MTS.sha256_compress
/// Facts about sequences
val seq_slice_equal_index:
#a:Type -> s1:S.seq a -> s2:S.seq a ->
i:nat -> j:nat{i <= j && j <= S.length s1 && j <= S.length s2} ->
k:nat{i <= k && k < j} ->
Lemma (requires S.equal (S.slice s1 i j) (S.slice s2 i j))
(ensures S.index s1 k == S.index s2 k)
[SMTPat (S.equal (S.slice s1 i j) (S.slice s2 i j));
SMTPat (S.index s1 k)]
let seq_slice_equal_index #a s1 s2 i j k =
assert (S.index (S.slice s1 i j) (k - i) == S.index (S.slice s2 i j) (k - i))
private val seq_slice_more_equal:
#a:Type -> s1:S.seq a -> s2:S.seq a ->
n:nat -> m:nat{n <= m && m <= S.length s1 && m <= S.length s2} ->
k:nat{n <= k} -> l:nat{k <= l && l <= m} ->
Lemma (requires S.equal (S.slice s1 n m) (S.slice s2 n m))
(ensures S.equal (S.slice s1 k l) (S.slice s2 k l))
[SMTPat (S.equal (S.slice s1 n m) (S.slice s2 n m));
SMTPat (S.equal (S.slice s1 k l) (S.slice s2 k l))]
private let seq_slice_more_equal #a s1 s2 n m k l =
slice_slice s1 n m (k - n) (l - n);
slice_slice s2 n m (k - n) (l - n)
/// Facts about "2"
val remainder_2_not_1_div: n:nat ->
Lemma (requires n % 2 <> 1)
(ensures n / 2 = (n + 1) / 2)
let remainder_2_not_1_div n = ()
val remainder_2_1_div: n:nat ->
Lemma (requires n % 2 = 1)
(ensures n / 2 + 1 = (n + 1) / 2)
let remainder_2_1_div n = ()
/// High-level Merkle tree data structure
noeq type merkle_tree (#hsz:pos) =
| MT: i:nat ->
j:nat{i <= j && j < pow2 32} ->
hs:hashess #hsz {S.length hs = 32} ->
rhs_ok:bool ->
rhs:hashes #hsz {S.length rhs = 32} -> // Rightmost hashes
mroot:hash #hsz ->
hash_fun:MTS.hash_fun_t #hsz ->
merkle_tree #hsz
val mt_not_full (#hsz:pos): merkle_tree #hsz -> GTot bool
let mt_not_full #hsz mt =
MT?.j mt < pow2 32 - 1
val mt_empty (#hsz:pos): merkle_tree #hsz -> GTot bool
let mt_empty #hsz mt =
MT?.j mt = 0
val mt_not_empty (#hsz:pos): merkle_tree #hsz -> GTot bool
let mt_not_empty #hsz mt =
MT?.j mt > 0
/// Well-formedness w.r.t. indices of base hash elements
noextract
val offset_of: i:nat -> Tot nat
let offset_of i =
if i % 2 = 0 then i else i - 1
val hs_wf_elts:
#hsz:pos ->
lv:nat{lv <= 32} ->
hs:hashess #hsz {S.length hs = 32} ->
i:nat -> j:nat{j >= i} ->
GTot Type0 (decreases (32 - lv))
let rec hs_wf_elts #hsz lv hs i j =
if lv = 32 then true
else (let ofs = offset_of i in
S.length (S.index hs lv) == j - ofs /\
hs_wf_elts #hsz (lv + 1) hs (i / 2) (j / 2))
#push-options "--max_fuel 1"
val hs_wf_elts_equal:
#hsz:pos ->
lv:nat{lv <= 32} ->
hs1:hashess #hsz {S.length hs1 = 32} ->
hs2:hashess #hsz {S.length hs2 = 32} ->
i:nat ->
j:nat{j >= i} ->
Lemma (requires hs_wf_elts lv hs1 i j /\
S.equal (S.slice hs1 lv 32) (S.slice hs2 lv 32))
(ensures hs_wf_elts lv hs2 i j)
(decreases (32 - lv))
let rec hs_wf_elts_equal #hsz lv hs1 hs2 i j =
if lv = 32 then ()
else (S.slice_slice hs1 lv 32 1 (32 - lv);
S.slice_slice hs2 lv 32 1 (32 - lv);
assert (S.equal (S.slice hs1 (lv + 1) 32)
(S.slice hs2 (lv + 1) 32));
S.lemma_index_slice hs1 lv 32 0;
S.lemma_index_slice hs2 lv 32 0;
assert (S.index hs1 lv == S.index hs2 lv);
hs_wf_elts_equal (lv + 1) hs1 hs2 (i / 2) (j / 2))
val mt_wf_elts (#hsz:pos): merkle_tree #hsz -> GTot Type0
let mt_wf_elts #_ (MT i j hs _ _ _ _) =
hs_wf_elts 0 hs i j
/// Construction
val hs_wf_elts_empty:
#hsz:pos ->
lv:nat{lv <= 32} ->
Lemma (requires True)
(ensures hs_wf_elts #hsz lv (S.create 32 S.empty) 0 0)
(decreases (32 - lv))
let rec hs_wf_elts_empty #hsz lv =
if lv = 32 then ()
else hs_wf_elts_empty #hsz (lv + 1)
// NOTE: the public function is `create_mt` defined below, which
// builds a tree with an initial hash.
noextract inline_for_extraction
val create_empty_mt (#hsz:pos) (#f:MTS.hash_fun_t #hsz): unit -> GTot (mt:merkle_tree #hsz {mt_wf_elts #hsz mt}) | false | false | MerkleTree.New.High.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 1,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 10,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val create_empty_mt (#hsz:pos) (#f:MTS.hash_fun_t #hsz): unit -> GTot (mt:merkle_tree #hsz {mt_wf_elts #hsz mt}) | [] | MerkleTree.New.High.create_empty_mt | {
"file_name": "src/MerkleTree.New.High.fst",
"git_rev": "3b0f086655c145aa23f58a97259ebf4cf112a4a3",
"git_url": "https://github.com/hacl-star/merkle-tree.git",
"project_name": "merkle-tree"
} | _: Prims.unit -> Prims.GTot (mt: MerkleTree.New.High.merkle_tree{MerkleTree.New.High.mt_wf_elts mt}) | {
"end_col": 86,
"end_line": 156,
"start_col": 2,
"start_line": 155
} |
Prims.GTot | val mt_path_length_step:
k:nat -> j:nat{k <= j} -> actd:bool -> GTot nat | [
{
"abbrev": true,
"full_module": "MerkleTree.Spec",
"short_module": "MTS"
},
{
"abbrev": true,
"full_module": "FStar.UInt8",
"short_module": "U8"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "S"
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Ghost",
"short_module": null
},
{
"abbrev": false,
"full_module": "MerkleTree.New",
"short_module": null
},
{
"abbrev": false,
"full_module": "MerkleTree.New",
"short_module": null
},
{
"abbrev": 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 mt_path_length_step k j actd =
if j = 0 then 0
else (if k % 2 = 0
then (if j = k || (j = k + 1 && not actd) then 0 else 1)
else 1) | val mt_path_length_step:
k:nat -> j:nat{k <= j} -> actd:bool -> GTot nat
let mt_path_length_step k j actd = | false | null | false | if j = 0 then 0 else (if k % 2 = 0 then (if j = k || (j = k + 1 && not actd) then 0 else 1) else 1) | {
"checked_file": "MerkleTree.New.High.fst.checked",
"dependencies": [
"Spec.Hash.Definitions.fst.checked",
"prims.fst.checked",
"MerkleTree.Spec.fst.checked",
"Lib.IntTypes.fsti.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "MerkleTree.New.High.fst"
} | [
"sometrivial"
] | [
"Prims.nat",
"Prims.b2t",
"Prims.op_LessThanOrEqual",
"Prims.bool",
"Prims.op_Equality",
"Prims.int",
"Prims.op_Modulus",
"Prims.op_BarBar",
"Prims.op_AmpAmp",
"Prims.op_Addition",
"Prims.op_Negation"
] | [] | module MerkleTree.New.High
open FStar.Ghost
open FStar.Seq
module S = FStar.Seq
module U32 = FStar.UInt32
module U8 = FStar.UInt8
module MTS = MerkleTree.Spec
#set-options "--z3rlimit 10 --max_fuel 0 --max_ifuel 0"
type uint32_t = U32.t
type uint8_t = U8.t
type hash (#hsz:pos) = b:Spec.Hash.Definitions.bytes{Seq.length b = hsz}
type hashes (#hsz:pos) = S.seq (hash #hsz)
type hashess (#hsz:pos) = S.seq (hashes #hsz)
noextract
let hash_init (#hsz:pos): hash #hsz =
Seq.create hsz (Lib.IntTypes.u8 0)
val sha256_compress: src1:hash #32 -> src2:hash #32 -> GTot (hash #32)
let sha256_compress = MTS.sha256_compress
/// Facts about sequences
val seq_slice_equal_index:
#a:Type -> s1:S.seq a -> s2:S.seq a ->
i:nat -> j:nat{i <= j && j <= S.length s1 && j <= S.length s2} ->
k:nat{i <= k && k < j} ->
Lemma (requires S.equal (S.slice s1 i j) (S.slice s2 i j))
(ensures S.index s1 k == S.index s2 k)
[SMTPat (S.equal (S.slice s1 i j) (S.slice s2 i j));
SMTPat (S.index s1 k)]
let seq_slice_equal_index #a s1 s2 i j k =
assert (S.index (S.slice s1 i j) (k - i) == S.index (S.slice s2 i j) (k - i))
private val seq_slice_more_equal:
#a:Type -> s1:S.seq a -> s2:S.seq a ->
n:nat -> m:nat{n <= m && m <= S.length s1 && m <= S.length s2} ->
k:nat{n <= k} -> l:nat{k <= l && l <= m} ->
Lemma (requires S.equal (S.slice s1 n m) (S.slice s2 n m))
(ensures S.equal (S.slice s1 k l) (S.slice s2 k l))
[SMTPat (S.equal (S.slice s1 n m) (S.slice s2 n m));
SMTPat (S.equal (S.slice s1 k l) (S.slice s2 k l))]
private let seq_slice_more_equal #a s1 s2 n m k l =
slice_slice s1 n m (k - n) (l - n);
slice_slice s2 n m (k - n) (l - n)
/// Facts about "2"
val remainder_2_not_1_div: n:nat ->
Lemma (requires n % 2 <> 1)
(ensures n / 2 = (n + 1) / 2)
let remainder_2_not_1_div n = ()
val remainder_2_1_div: n:nat ->
Lemma (requires n % 2 = 1)
(ensures n / 2 + 1 = (n + 1) / 2)
let remainder_2_1_div n = ()
/// High-level Merkle tree data structure
noeq type merkle_tree (#hsz:pos) =
| MT: i:nat ->
j:nat{i <= j && j < pow2 32} ->
hs:hashess #hsz {S.length hs = 32} ->
rhs_ok:bool ->
rhs:hashes #hsz {S.length rhs = 32} -> // Rightmost hashes
mroot:hash #hsz ->
hash_fun:MTS.hash_fun_t #hsz ->
merkle_tree #hsz
val mt_not_full (#hsz:pos): merkle_tree #hsz -> GTot bool
let mt_not_full #hsz mt =
MT?.j mt < pow2 32 - 1
val mt_empty (#hsz:pos): merkle_tree #hsz -> GTot bool
let mt_empty #hsz mt =
MT?.j mt = 0
val mt_not_empty (#hsz:pos): merkle_tree #hsz -> GTot bool
let mt_not_empty #hsz mt =
MT?.j mt > 0
/// Well-formedness w.r.t. indices of base hash elements
noextract
val offset_of: i:nat -> Tot nat
let offset_of i =
if i % 2 = 0 then i else i - 1
val hs_wf_elts:
#hsz:pos ->
lv:nat{lv <= 32} ->
hs:hashess #hsz {S.length hs = 32} ->
i:nat -> j:nat{j >= i} ->
GTot Type0 (decreases (32 - lv))
let rec hs_wf_elts #hsz lv hs i j =
if lv = 32 then true
else (let ofs = offset_of i in
S.length (S.index hs lv) == j - ofs /\
hs_wf_elts #hsz (lv + 1) hs (i / 2) (j / 2))
#push-options "--max_fuel 1"
val hs_wf_elts_equal:
#hsz:pos ->
lv:nat{lv <= 32} ->
hs1:hashess #hsz {S.length hs1 = 32} ->
hs2:hashess #hsz {S.length hs2 = 32} ->
i:nat ->
j:nat{j >= i} ->
Lemma (requires hs_wf_elts lv hs1 i j /\
S.equal (S.slice hs1 lv 32) (S.slice hs2 lv 32))
(ensures hs_wf_elts lv hs2 i j)
(decreases (32 - lv))
let rec hs_wf_elts_equal #hsz lv hs1 hs2 i j =
if lv = 32 then ()
else (S.slice_slice hs1 lv 32 1 (32 - lv);
S.slice_slice hs2 lv 32 1 (32 - lv);
assert (S.equal (S.slice hs1 (lv + 1) 32)
(S.slice hs2 (lv + 1) 32));
S.lemma_index_slice hs1 lv 32 0;
S.lemma_index_slice hs2 lv 32 0;
assert (S.index hs1 lv == S.index hs2 lv);
hs_wf_elts_equal (lv + 1) hs1 hs2 (i / 2) (j / 2))
val mt_wf_elts (#hsz:pos): merkle_tree #hsz -> GTot Type0
let mt_wf_elts #_ (MT i j hs _ _ _ _) =
hs_wf_elts 0 hs i j
/// Construction
val hs_wf_elts_empty:
#hsz:pos ->
lv:nat{lv <= 32} ->
Lemma (requires True)
(ensures hs_wf_elts #hsz lv (S.create 32 S.empty) 0 0)
(decreases (32 - lv))
let rec hs_wf_elts_empty #hsz lv =
if lv = 32 then ()
else hs_wf_elts_empty #hsz (lv + 1)
// NOTE: the public function is `create_mt` defined below, which
// builds a tree with an initial hash.
noextract inline_for_extraction
val create_empty_mt (#hsz:pos) (#f:MTS.hash_fun_t #hsz): unit -> GTot (mt:merkle_tree #hsz {mt_wf_elts #hsz mt})
let create_empty_mt #hsz #f _ =
hs_wf_elts_empty #hsz 0;
MT 0 0 (S.create 32 S.empty) false (S.create 32 (hash_init #hsz)) (hash_init #hsz) f
/// Insertion
val hashess_insert:
#hsz:pos ->
lv:nat{lv < 32} ->
i:nat ->
j:nat{i <= j /\ j < pow2 (32 - lv) - 1} ->
hs:hashess #hsz {S.length hs = 32 /\ hs_wf_elts lv hs i j} ->
v:hash #hsz ->
GTot (ihs:hashess #hsz {S.length ihs = 32 /\ hs_wf_elts (lv + 1) ihs (i / 2) (j / 2)})
let hashess_insert #hsz lv i j hs v =
let ihs = S.upd hs lv (S.snoc (S.index hs lv) v) in
hs_wf_elts_equal (lv + 1) hs ihs (i / 2) (j / 2);
ihs
val insert_:
#hsz:pos -> #f:MTS.hash_fun_t #hsz ->
lv:nat{lv < 32} ->
i:nat ->
j:nat{i <= j /\ j < pow2 (32 - lv) - 1} ->
hs:hashess #hsz {S.length hs = 32 /\ hs_wf_elts lv hs i j} ->
acc:hash #hsz ->
GTot (ihs:hashess #hsz {
S.length ihs = 32 /\
hs_wf_elts #hsz lv ihs i (j + 1) /\
S.equal (S.slice hs 0 lv) (S.slice ihs 0 lv)})
(decreases j)
let rec insert_ #hsz #f lv i j hs acc =
let ihs = hashess_insert #hsz lv i j hs acc in
assert (S.equal (S.slice hs 0 lv) (S.slice ihs 0 lv));
if j % 2 = 1 // S.length (S.index hs lv) > 0
then begin
remainder_2_1_div j;
let nacc = f (S.last (S.index hs lv)) acc in
let rihs = insert_ #hsz #f (lv + 1) (i / 2) (j / 2) ihs nacc in
assert (hs_wf_elts #hsz (lv + 1) rihs (i / 2) (j / 2 + 1));
assert (S.equal (S.slice ihs 0 (lv + 1)) (S.slice rihs 0 (lv + 1)));
assert (S.index ihs lv == S.index rihs lv);
assert (S.length (S.index rihs lv) = (j + 1) - offset_of i);
assert (S.equal (S.slice ihs 0 (lv + 1)) (S.slice rihs 0 (lv + 1)));
assert (S.equal (S.slice ihs 0 lv) (S.slice rihs 0 lv));
rihs
end
else ihs
val insert_base:
#hsz:pos -> #f:MTS.hash_fun_t #hsz ->
lv:nat -> i:nat -> j:nat -> hs:hashess #hsz -> acc:hash #hsz ->
Lemma (requires
lv < 32 /\ i <= j /\ j < pow2 (32 - lv) - 1 /\
S.length hs = 32 /\ hs_wf_elts lv hs i j /\
j % 2 <> 1)
(ensures S.equal (insert_ #_ #f lv i j hs acc)
(hashess_insert lv i j hs acc))
let insert_base #_ #_ lv i j hs acc = ()
val insert_rec:
#hsz:pos -> #f:MTS.hash_fun_t #hsz ->
lv:nat -> i:nat -> j:nat -> hs:hashess -> acc:hash ->
Lemma (requires
lv < 32 /\ i <= j /\ j < pow2 (32 - lv) - 1 /\
S.length hs = 32 /\ hs_wf_elts lv hs i j /\
j % 2 == 1)
(ensures
(hs_wf_elts_equal (lv + 1) hs
(hashess_insert lv i j hs acc) (i / 2) (j / 2);
S.equal (insert_ #_ #f lv i j hs acc)
(insert_ #_ #f (lv + 1) (i / 2) (j / 2)
(hashess_insert lv i j hs acc)
(f (S.last (S.index hs lv)) acc))))
let insert_rec #_ #_ lv i j hs acc = ()
val mt_insert:
#hsz:pos ->
mt:merkle_tree #hsz {mt_wf_elts mt /\ mt_not_full mt} -> v:hash #hsz ->
GTot (imt:merkle_tree #hsz{mt_wf_elts #hsz imt})
let mt_insert #hsz mt v =
MT (MT?.i mt)
(MT?.j mt + 1)
(insert_ #_ #(MT?.hash_fun mt) 0 (MT?.i mt) (MT?.j mt) (MT?.hs mt) v)
false
(MT?.rhs mt)
(MT?.mroot mt)
(MT?.hash_fun mt)
val mt_create:
hsz:pos -> f:MTS.hash_fun_t #hsz ->
init:hash #hsz -> GTot (mt:merkle_tree{mt_wf_elts #hsz mt})
let mt_create hsz f init =
mt_insert #_ (create_empty_mt #_ #f ()) init
/// Getting the Merkle root and path
type path (#hsz:pos) = S.seq (hash #hsz)
// Construct the rightmost hashes for a given (incomplete) Merkle tree.
// This function calculates the Merkle root as well, which is the final
// accumulator value.
val construct_rhs:
#hsz:pos -> #f:MTS.hash_fun_t #hsz ->
lv:nat{lv <= 32} ->
hs:hashess #hsz {S.length hs = 32} ->
rhs:hashes #hsz {S.length rhs = 32} ->
i:nat ->
j:nat{
i <= j /\ j < pow2 (32 - lv) /\
hs_wf_elts #hsz lv hs i j} ->
acc:hash #hsz ->
actd:bool ->
GTot (crhs:hashes #hsz {S.length crhs = 32} * (hash #hsz))
(decreases j)
let rec construct_rhs #hsz #f lv hs rhs i j acc actd =
let ofs = offset_of i in
if j = 0 then (rhs, acc)
else
(if j % 2 = 0
then (construct_rhs #_ #f (lv + 1) hs rhs (i / 2) (j / 2) acc actd)
else (let nrhs = if actd then S.upd rhs lv acc else rhs in
let nacc = if actd
then f (S.index (S.index hs lv) (j - 1 - ofs)) acc
else S.index (S.index hs lv) (j - 1 - ofs) in
construct_rhs #_ #f (lv + 1) hs nrhs (i / 2) (j / 2) nacc true))
val construct_rhs_unchanged:
#hsz:pos -> #f:MTS.hash_fun_t #hsz ->
lv:nat{lv <= 32} ->
hs:hashess #hsz {S.length hs = 32} ->
rhs:hashes #hsz {S.length rhs = 32} ->
i:nat ->
j:nat{
i <= j /\ j < pow2 (32 - lv) /\
hs_wf_elts #hsz lv hs i j} ->
acc:hash #hsz ->
actd:bool ->
Lemma (requires True)
(ensures S.equal (S.slice rhs 0 lv)
(S.slice (fst (construct_rhs #_ #f lv hs rhs i j acc actd)) 0 lv))
(decreases j)
let rec construct_rhs_unchanged #hsz #f lv hs rhs i j acc actd =
let ofs = offset_of i in
if j = 0 then ()
else if j % 2 = 0
then (construct_rhs_unchanged #_ #f (lv + 1) hs rhs (i / 2) (j / 2) acc actd;
let rrhs = fst (construct_rhs #_ #f (lv + 1) hs rhs (i / 2) (j / 2) acc actd) in
assert (S.equal (S.slice rhs 0 lv) (S.slice rrhs 0 lv)))
else (let nrhs = if actd then S.upd rhs lv acc else rhs in
let nacc = if actd
then f (S.index (S.index hs lv) (j - 1 - ofs)) acc
else S.index (S.index hs lv) (j - 1 - ofs) in
construct_rhs_unchanged #_ #f (lv + 1) hs nrhs (i / 2) (j / 2) nacc true;
let rrhs = fst (construct_rhs #_ #f (lv + 1) hs nrhs (i / 2) (j / 2) nacc true) in
assert (S.equal (S.slice nrhs 0 lv) (S.slice rrhs 0 lv));
assert (S.equal (S.slice rhs 0 lv) (S.slice nrhs 0 lv)))
val construct_rhs_even:
#hsz:pos -> #f:MTS.hash_fun_t #hsz ->
lv:nat{lv <= 32} ->
hs:hashess #hsz {S.length hs = 32} ->
rhs:hashes #hsz {S.length rhs = 32} ->
i:nat ->
j:nat{
i <= j /\ j < pow2 (32 - lv) /\
hs_wf_elts #hsz lv hs i j} ->
acc:hash #hsz ->
actd:bool ->
Lemma (requires j <> 0 /\ j % 2 = 0)
(ensures construct_rhs #_ #f lv hs rhs i j acc actd ==
construct_rhs #_ #f (lv + 1) hs rhs (i / 2) (j / 2) acc actd)
let construct_rhs_even #_ #_ _ _ _ _ _ _ _ = ()
val construct_rhs_odd:
#hsz:pos -> #f:MTS.hash_fun_t #hsz ->
lv:nat{lv <= 32} ->
hs:hashess #hsz {S.length hs = 32} ->
rhs:hashes #hsz {S.length rhs = 32} ->
i:nat ->
j:nat{
i <= j /\ j < pow2 (32 - lv) /\
hs_wf_elts lv hs i j} ->
acc:hash ->
actd:bool ->
Lemma (requires j % 2 = 1)
(ensures construct_rhs #_ #f lv hs rhs i j acc actd ==
(let ofs = offset_of i in
let nrhs = if actd then S.upd rhs lv acc else rhs in
let nacc = if actd
then f (S.index (S.index hs lv) (j - 1 - ofs)) acc
else S.index (S.index hs lv) (j - 1 - ofs) in
construct_rhs #_ #f (lv + 1) hs nrhs (i / 2) (j / 2) nacc true))
let construct_rhs_odd #_ #_ _ _ _ _ _ _ _ = ()
val mt_get_root:
#hsz:pos ->
mt:merkle_tree #hsz {mt_wf_elts #hsz mt} -> drt:hash #hsz ->
GTot (merkle_tree #hsz * hash #hsz)
let mt_get_root #hsz mt drt =
if MT?.rhs_ok mt then (mt, MT?.mroot mt)
else begin
let (nrhs, rt) = construct_rhs #_ #(MT?.hash_fun mt) 0 (MT?.hs mt) (MT?.rhs mt) (MT?.i mt) (MT?.j mt) drt false in
(MT (MT?.i mt) (MT?.j mt) (MT?.hs mt) true nrhs rt (MT?.hash_fun mt), rt)
end
val mt_get_root_rhs_ok_true:
#hsz:pos ->
mt:merkle_tree #hsz {mt_wf_elts mt} -> drt:hash #hsz ->
Lemma (requires MT?.rhs_ok mt == true)
(ensures mt_get_root #hsz mt drt == (mt, MT?.mroot mt))
let mt_get_root_rhs_ok_true #hsz mt drt = ()
val mt_get_root_rhs_ok_false:
#hsz:pos ->
mt:merkle_tree #hsz {mt_wf_elts mt} -> drt:hash ->
Lemma (requires MT?.rhs_ok mt == false)
(ensures mt_get_root mt drt ==
(let (nrhs, rt) =
construct_rhs #_ #(MT?.hash_fun mt)
0 (MT?.hs mt) (MT?.rhs mt) (MT?.i mt) (MT?.j mt)
drt false in
(MT (MT?.i mt) (MT?.j mt) (MT?.hs mt) true nrhs rt (MT?.hash_fun mt), rt)))
let mt_get_root_rhs_ok_false #_ _ _ = ()
val path_insert: (#hsz:pos) -> p:path #hsz -> hp:hash #hsz -> GTot (path #hsz)
let path_insert #_ p hp = S.snoc p hp
val mt_path_length_step:
k:nat -> j:nat{k <= j} -> actd:bool -> GTot nat | false | false | MerkleTree.New.High.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 1,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 10,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val mt_path_length_step:
k:nat -> j:nat{k <= j} -> actd:bool -> GTot nat | [] | MerkleTree.New.High.mt_path_length_step | {
"file_name": "src/MerkleTree.New.High.fst",
"git_rev": "3b0f086655c145aa23f58a97259ebf4cf112a4a3",
"git_url": "https://github.com/hacl-star/merkle-tree.git",
"project_name": "merkle-tree"
} | k: Prims.nat -> j: Prims.nat{k <= j} -> actd: Prims.bool -> Prims.GTot Prims.nat | {
"end_col": 14,
"end_line": 388,
"start_col": 2,
"start_line": 385
} |
Prims.GTot | val mt_get_root:
#hsz:pos ->
mt:merkle_tree #hsz {mt_wf_elts #hsz mt} -> drt:hash #hsz ->
GTot (merkle_tree #hsz * hash #hsz) | [
{
"abbrev": true,
"full_module": "MerkleTree.Spec",
"short_module": "MTS"
},
{
"abbrev": true,
"full_module": "FStar.UInt8",
"short_module": "U8"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "S"
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Ghost",
"short_module": null
},
{
"abbrev": false,
"full_module": "MerkleTree.New",
"short_module": null
},
{
"abbrev": false,
"full_module": "MerkleTree.New",
"short_module": null
},
{
"abbrev": 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 mt_get_root #hsz mt drt =
if MT?.rhs_ok mt then (mt, MT?.mroot mt)
else begin
let (nrhs, rt) = construct_rhs #_ #(MT?.hash_fun mt) 0 (MT?.hs mt) (MT?.rhs mt) (MT?.i mt) (MT?.j mt) drt false in
(MT (MT?.i mt) (MT?.j mt) (MT?.hs mt) true nrhs rt (MT?.hash_fun mt), rt)
end | val mt_get_root:
#hsz:pos ->
mt:merkle_tree #hsz {mt_wf_elts #hsz mt} -> drt:hash #hsz ->
GTot (merkle_tree #hsz * hash #hsz)
let mt_get_root #hsz mt drt = | false | null | false | if MT?.rhs_ok mt
then (mt, MT?.mroot mt)
else
let nrhs, rt =
construct_rhs #_ #(MT?.hash_fun mt) 0 (MT?.hs mt) (MT?.rhs mt) (MT?.i mt) (MT?.j mt) drt false
in
(MT (MT?.i mt) (MT?.j mt) (MT?.hs mt) true nrhs rt (MT?.hash_fun mt), rt) | {
"checked_file": "MerkleTree.New.High.fst.checked",
"dependencies": [
"Spec.Hash.Definitions.fst.checked",
"prims.fst.checked",
"MerkleTree.Spec.fst.checked",
"Lib.IntTypes.fsti.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "MerkleTree.New.High.fst"
} | [
"sometrivial"
] | [
"Prims.pos",
"MerkleTree.New.High.merkle_tree",
"MerkleTree.New.High.mt_wf_elts",
"MerkleTree.New.High.hash",
"MerkleTree.New.High.__proj__MT__item__rhs_ok",
"FStar.Pervasives.Native.Mktuple2",
"MerkleTree.New.High.__proj__MT__item__mroot",
"Prims.bool",
"MerkleTree.New.High.hashes",
"Prims.b2t",
"Prims.op_Equality",
"Prims.int",
"FStar.Seq.Base.length",
"MerkleTree.New.High.MT",
"MerkleTree.New.High.__proj__MT__item__i",
"MerkleTree.New.High.__proj__MT__item__j",
"MerkleTree.New.High.__proj__MT__item__hs",
"MerkleTree.New.High.__proj__MT__item__hash_fun",
"FStar.Pervasives.Native.tuple2",
"MerkleTree.New.High.construct_rhs",
"MerkleTree.New.High.__proj__MT__item__rhs"
] | [] | module MerkleTree.New.High
open FStar.Ghost
open FStar.Seq
module S = FStar.Seq
module U32 = FStar.UInt32
module U8 = FStar.UInt8
module MTS = MerkleTree.Spec
#set-options "--z3rlimit 10 --max_fuel 0 --max_ifuel 0"
type uint32_t = U32.t
type uint8_t = U8.t
type hash (#hsz:pos) = b:Spec.Hash.Definitions.bytes{Seq.length b = hsz}
type hashes (#hsz:pos) = S.seq (hash #hsz)
type hashess (#hsz:pos) = S.seq (hashes #hsz)
noextract
let hash_init (#hsz:pos): hash #hsz =
Seq.create hsz (Lib.IntTypes.u8 0)
val sha256_compress: src1:hash #32 -> src2:hash #32 -> GTot (hash #32)
let sha256_compress = MTS.sha256_compress
/// Facts about sequences
val seq_slice_equal_index:
#a:Type -> s1:S.seq a -> s2:S.seq a ->
i:nat -> j:nat{i <= j && j <= S.length s1 && j <= S.length s2} ->
k:nat{i <= k && k < j} ->
Lemma (requires S.equal (S.slice s1 i j) (S.slice s2 i j))
(ensures S.index s1 k == S.index s2 k)
[SMTPat (S.equal (S.slice s1 i j) (S.slice s2 i j));
SMTPat (S.index s1 k)]
let seq_slice_equal_index #a s1 s2 i j k =
assert (S.index (S.slice s1 i j) (k - i) == S.index (S.slice s2 i j) (k - i))
private val seq_slice_more_equal:
#a:Type -> s1:S.seq a -> s2:S.seq a ->
n:nat -> m:nat{n <= m && m <= S.length s1 && m <= S.length s2} ->
k:nat{n <= k} -> l:nat{k <= l && l <= m} ->
Lemma (requires S.equal (S.slice s1 n m) (S.slice s2 n m))
(ensures S.equal (S.slice s1 k l) (S.slice s2 k l))
[SMTPat (S.equal (S.slice s1 n m) (S.slice s2 n m));
SMTPat (S.equal (S.slice s1 k l) (S.slice s2 k l))]
private let seq_slice_more_equal #a s1 s2 n m k l =
slice_slice s1 n m (k - n) (l - n);
slice_slice s2 n m (k - n) (l - n)
/// Facts about "2"
val remainder_2_not_1_div: n:nat ->
Lemma (requires n % 2 <> 1)
(ensures n / 2 = (n + 1) / 2)
let remainder_2_not_1_div n = ()
val remainder_2_1_div: n:nat ->
Lemma (requires n % 2 = 1)
(ensures n / 2 + 1 = (n + 1) / 2)
let remainder_2_1_div n = ()
/// High-level Merkle tree data structure
noeq type merkle_tree (#hsz:pos) =
| MT: i:nat ->
j:nat{i <= j && j < pow2 32} ->
hs:hashess #hsz {S.length hs = 32} ->
rhs_ok:bool ->
rhs:hashes #hsz {S.length rhs = 32} -> // Rightmost hashes
mroot:hash #hsz ->
hash_fun:MTS.hash_fun_t #hsz ->
merkle_tree #hsz
val mt_not_full (#hsz:pos): merkle_tree #hsz -> GTot bool
let mt_not_full #hsz mt =
MT?.j mt < pow2 32 - 1
val mt_empty (#hsz:pos): merkle_tree #hsz -> GTot bool
let mt_empty #hsz mt =
MT?.j mt = 0
val mt_not_empty (#hsz:pos): merkle_tree #hsz -> GTot bool
let mt_not_empty #hsz mt =
MT?.j mt > 0
/// Well-formedness w.r.t. indices of base hash elements
noextract
val offset_of: i:nat -> Tot nat
let offset_of i =
if i % 2 = 0 then i else i - 1
val hs_wf_elts:
#hsz:pos ->
lv:nat{lv <= 32} ->
hs:hashess #hsz {S.length hs = 32} ->
i:nat -> j:nat{j >= i} ->
GTot Type0 (decreases (32 - lv))
let rec hs_wf_elts #hsz lv hs i j =
if lv = 32 then true
else (let ofs = offset_of i in
S.length (S.index hs lv) == j - ofs /\
hs_wf_elts #hsz (lv + 1) hs (i / 2) (j / 2))
#push-options "--max_fuel 1"
val hs_wf_elts_equal:
#hsz:pos ->
lv:nat{lv <= 32} ->
hs1:hashess #hsz {S.length hs1 = 32} ->
hs2:hashess #hsz {S.length hs2 = 32} ->
i:nat ->
j:nat{j >= i} ->
Lemma (requires hs_wf_elts lv hs1 i j /\
S.equal (S.slice hs1 lv 32) (S.slice hs2 lv 32))
(ensures hs_wf_elts lv hs2 i j)
(decreases (32 - lv))
let rec hs_wf_elts_equal #hsz lv hs1 hs2 i j =
if lv = 32 then ()
else (S.slice_slice hs1 lv 32 1 (32 - lv);
S.slice_slice hs2 lv 32 1 (32 - lv);
assert (S.equal (S.slice hs1 (lv + 1) 32)
(S.slice hs2 (lv + 1) 32));
S.lemma_index_slice hs1 lv 32 0;
S.lemma_index_slice hs2 lv 32 0;
assert (S.index hs1 lv == S.index hs2 lv);
hs_wf_elts_equal (lv + 1) hs1 hs2 (i / 2) (j / 2))
val mt_wf_elts (#hsz:pos): merkle_tree #hsz -> GTot Type0
let mt_wf_elts #_ (MT i j hs _ _ _ _) =
hs_wf_elts 0 hs i j
/// Construction
val hs_wf_elts_empty:
#hsz:pos ->
lv:nat{lv <= 32} ->
Lemma (requires True)
(ensures hs_wf_elts #hsz lv (S.create 32 S.empty) 0 0)
(decreases (32 - lv))
let rec hs_wf_elts_empty #hsz lv =
if lv = 32 then ()
else hs_wf_elts_empty #hsz (lv + 1)
// NOTE: the public function is `create_mt` defined below, which
// builds a tree with an initial hash.
noextract inline_for_extraction
val create_empty_mt (#hsz:pos) (#f:MTS.hash_fun_t #hsz): unit -> GTot (mt:merkle_tree #hsz {mt_wf_elts #hsz mt})
let create_empty_mt #hsz #f _ =
hs_wf_elts_empty #hsz 0;
MT 0 0 (S.create 32 S.empty) false (S.create 32 (hash_init #hsz)) (hash_init #hsz) f
/// Insertion
val hashess_insert:
#hsz:pos ->
lv:nat{lv < 32} ->
i:nat ->
j:nat{i <= j /\ j < pow2 (32 - lv) - 1} ->
hs:hashess #hsz {S.length hs = 32 /\ hs_wf_elts lv hs i j} ->
v:hash #hsz ->
GTot (ihs:hashess #hsz {S.length ihs = 32 /\ hs_wf_elts (lv + 1) ihs (i / 2) (j / 2)})
let hashess_insert #hsz lv i j hs v =
let ihs = S.upd hs lv (S.snoc (S.index hs lv) v) in
hs_wf_elts_equal (lv + 1) hs ihs (i / 2) (j / 2);
ihs
val insert_:
#hsz:pos -> #f:MTS.hash_fun_t #hsz ->
lv:nat{lv < 32} ->
i:nat ->
j:nat{i <= j /\ j < pow2 (32 - lv) - 1} ->
hs:hashess #hsz {S.length hs = 32 /\ hs_wf_elts lv hs i j} ->
acc:hash #hsz ->
GTot (ihs:hashess #hsz {
S.length ihs = 32 /\
hs_wf_elts #hsz lv ihs i (j + 1) /\
S.equal (S.slice hs 0 lv) (S.slice ihs 0 lv)})
(decreases j)
let rec insert_ #hsz #f lv i j hs acc =
let ihs = hashess_insert #hsz lv i j hs acc in
assert (S.equal (S.slice hs 0 lv) (S.slice ihs 0 lv));
if j % 2 = 1 // S.length (S.index hs lv) > 0
then begin
remainder_2_1_div j;
let nacc = f (S.last (S.index hs lv)) acc in
let rihs = insert_ #hsz #f (lv + 1) (i / 2) (j / 2) ihs nacc in
assert (hs_wf_elts #hsz (lv + 1) rihs (i / 2) (j / 2 + 1));
assert (S.equal (S.slice ihs 0 (lv + 1)) (S.slice rihs 0 (lv + 1)));
assert (S.index ihs lv == S.index rihs lv);
assert (S.length (S.index rihs lv) = (j + 1) - offset_of i);
assert (S.equal (S.slice ihs 0 (lv + 1)) (S.slice rihs 0 (lv + 1)));
assert (S.equal (S.slice ihs 0 lv) (S.slice rihs 0 lv));
rihs
end
else ihs
val insert_base:
#hsz:pos -> #f:MTS.hash_fun_t #hsz ->
lv:nat -> i:nat -> j:nat -> hs:hashess #hsz -> acc:hash #hsz ->
Lemma (requires
lv < 32 /\ i <= j /\ j < pow2 (32 - lv) - 1 /\
S.length hs = 32 /\ hs_wf_elts lv hs i j /\
j % 2 <> 1)
(ensures S.equal (insert_ #_ #f lv i j hs acc)
(hashess_insert lv i j hs acc))
let insert_base #_ #_ lv i j hs acc = ()
val insert_rec:
#hsz:pos -> #f:MTS.hash_fun_t #hsz ->
lv:nat -> i:nat -> j:nat -> hs:hashess -> acc:hash ->
Lemma (requires
lv < 32 /\ i <= j /\ j < pow2 (32 - lv) - 1 /\
S.length hs = 32 /\ hs_wf_elts lv hs i j /\
j % 2 == 1)
(ensures
(hs_wf_elts_equal (lv + 1) hs
(hashess_insert lv i j hs acc) (i / 2) (j / 2);
S.equal (insert_ #_ #f lv i j hs acc)
(insert_ #_ #f (lv + 1) (i / 2) (j / 2)
(hashess_insert lv i j hs acc)
(f (S.last (S.index hs lv)) acc))))
let insert_rec #_ #_ lv i j hs acc = ()
val mt_insert:
#hsz:pos ->
mt:merkle_tree #hsz {mt_wf_elts mt /\ mt_not_full mt} -> v:hash #hsz ->
GTot (imt:merkle_tree #hsz{mt_wf_elts #hsz imt})
let mt_insert #hsz mt v =
MT (MT?.i mt)
(MT?.j mt + 1)
(insert_ #_ #(MT?.hash_fun mt) 0 (MT?.i mt) (MT?.j mt) (MT?.hs mt) v)
false
(MT?.rhs mt)
(MT?.mroot mt)
(MT?.hash_fun mt)
val mt_create:
hsz:pos -> f:MTS.hash_fun_t #hsz ->
init:hash #hsz -> GTot (mt:merkle_tree{mt_wf_elts #hsz mt})
let mt_create hsz f init =
mt_insert #_ (create_empty_mt #_ #f ()) init
/// Getting the Merkle root and path
type path (#hsz:pos) = S.seq (hash #hsz)
// Construct the rightmost hashes for a given (incomplete) Merkle tree.
// This function calculates the Merkle root as well, which is the final
// accumulator value.
val construct_rhs:
#hsz:pos -> #f:MTS.hash_fun_t #hsz ->
lv:nat{lv <= 32} ->
hs:hashess #hsz {S.length hs = 32} ->
rhs:hashes #hsz {S.length rhs = 32} ->
i:nat ->
j:nat{
i <= j /\ j < pow2 (32 - lv) /\
hs_wf_elts #hsz lv hs i j} ->
acc:hash #hsz ->
actd:bool ->
GTot (crhs:hashes #hsz {S.length crhs = 32} * (hash #hsz))
(decreases j)
let rec construct_rhs #hsz #f lv hs rhs i j acc actd =
let ofs = offset_of i in
if j = 0 then (rhs, acc)
else
(if j % 2 = 0
then (construct_rhs #_ #f (lv + 1) hs rhs (i / 2) (j / 2) acc actd)
else (let nrhs = if actd then S.upd rhs lv acc else rhs in
let nacc = if actd
then f (S.index (S.index hs lv) (j - 1 - ofs)) acc
else S.index (S.index hs lv) (j - 1 - ofs) in
construct_rhs #_ #f (lv + 1) hs nrhs (i / 2) (j / 2) nacc true))
val construct_rhs_unchanged:
#hsz:pos -> #f:MTS.hash_fun_t #hsz ->
lv:nat{lv <= 32} ->
hs:hashess #hsz {S.length hs = 32} ->
rhs:hashes #hsz {S.length rhs = 32} ->
i:nat ->
j:nat{
i <= j /\ j < pow2 (32 - lv) /\
hs_wf_elts #hsz lv hs i j} ->
acc:hash #hsz ->
actd:bool ->
Lemma (requires True)
(ensures S.equal (S.slice rhs 0 lv)
(S.slice (fst (construct_rhs #_ #f lv hs rhs i j acc actd)) 0 lv))
(decreases j)
let rec construct_rhs_unchanged #hsz #f lv hs rhs i j acc actd =
let ofs = offset_of i in
if j = 0 then ()
else if j % 2 = 0
then (construct_rhs_unchanged #_ #f (lv + 1) hs rhs (i / 2) (j / 2) acc actd;
let rrhs = fst (construct_rhs #_ #f (lv + 1) hs rhs (i / 2) (j / 2) acc actd) in
assert (S.equal (S.slice rhs 0 lv) (S.slice rrhs 0 lv)))
else (let nrhs = if actd then S.upd rhs lv acc else rhs in
let nacc = if actd
then f (S.index (S.index hs lv) (j - 1 - ofs)) acc
else S.index (S.index hs lv) (j - 1 - ofs) in
construct_rhs_unchanged #_ #f (lv + 1) hs nrhs (i / 2) (j / 2) nacc true;
let rrhs = fst (construct_rhs #_ #f (lv + 1) hs nrhs (i / 2) (j / 2) nacc true) in
assert (S.equal (S.slice nrhs 0 lv) (S.slice rrhs 0 lv));
assert (S.equal (S.slice rhs 0 lv) (S.slice nrhs 0 lv)))
val construct_rhs_even:
#hsz:pos -> #f:MTS.hash_fun_t #hsz ->
lv:nat{lv <= 32} ->
hs:hashess #hsz {S.length hs = 32} ->
rhs:hashes #hsz {S.length rhs = 32} ->
i:nat ->
j:nat{
i <= j /\ j < pow2 (32 - lv) /\
hs_wf_elts #hsz lv hs i j} ->
acc:hash #hsz ->
actd:bool ->
Lemma (requires j <> 0 /\ j % 2 = 0)
(ensures construct_rhs #_ #f lv hs rhs i j acc actd ==
construct_rhs #_ #f (lv + 1) hs rhs (i / 2) (j / 2) acc actd)
let construct_rhs_even #_ #_ _ _ _ _ _ _ _ = ()
val construct_rhs_odd:
#hsz:pos -> #f:MTS.hash_fun_t #hsz ->
lv:nat{lv <= 32} ->
hs:hashess #hsz {S.length hs = 32} ->
rhs:hashes #hsz {S.length rhs = 32} ->
i:nat ->
j:nat{
i <= j /\ j < pow2 (32 - lv) /\
hs_wf_elts lv hs i j} ->
acc:hash ->
actd:bool ->
Lemma (requires j % 2 = 1)
(ensures construct_rhs #_ #f lv hs rhs i j acc actd ==
(let ofs = offset_of i in
let nrhs = if actd then S.upd rhs lv acc else rhs in
let nacc = if actd
then f (S.index (S.index hs lv) (j - 1 - ofs)) acc
else S.index (S.index hs lv) (j - 1 - ofs) in
construct_rhs #_ #f (lv + 1) hs nrhs (i / 2) (j / 2) nacc true))
let construct_rhs_odd #_ #_ _ _ _ _ _ _ _ = ()
val mt_get_root:
#hsz:pos ->
mt:merkle_tree #hsz {mt_wf_elts #hsz mt} -> drt:hash #hsz ->
GTot (merkle_tree #hsz * hash #hsz) | false | false | MerkleTree.New.High.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 1,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 10,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val mt_get_root:
#hsz:pos ->
mt:merkle_tree #hsz {mt_wf_elts #hsz mt} -> drt:hash #hsz ->
GTot (merkle_tree #hsz * hash #hsz) | [] | MerkleTree.New.High.mt_get_root | {
"file_name": "src/MerkleTree.New.High.fst",
"git_rev": "3b0f086655c145aa23f58a97259ebf4cf112a4a3",
"git_url": "https://github.com/hacl-star/merkle-tree.git",
"project_name": "merkle-tree"
} |
mt: MerkleTree.New.High.merkle_tree{MerkleTree.New.High.mt_wf_elts mt} ->
drt: MerkleTree.New.High.hash
-> Prims.GTot (MerkleTree.New.High.merkle_tree * MerkleTree.New.High.hash) | {
"end_col": 5,
"end_line": 358,
"start_col": 2,
"start_line": 354
} |
Prims.GTot | val mt_flush:
#hsz:pos ->
mt:merkle_tree #hsz {mt_wf_elts mt /\ MT?.j mt > MT?.i mt} ->
GTot (fmt:merkle_tree{mt_wf_elts #hsz fmt}) | [
{
"abbrev": true,
"full_module": "MerkleTree.Spec",
"short_module": "MTS"
},
{
"abbrev": true,
"full_module": "FStar.UInt8",
"short_module": "U8"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "S"
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Ghost",
"short_module": null
},
{
"abbrev": false,
"full_module": "MerkleTree.New",
"short_module": null
},
{
"abbrev": false,
"full_module": "MerkleTree.New",
"short_module": null
},
{
"abbrev": 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 mt_flush #hsz mt =
mt_flush_to mt (MT?.j mt - 1) | val mt_flush:
#hsz:pos ->
mt:merkle_tree #hsz {mt_wf_elts mt /\ MT?.j mt > MT?.i mt} ->
GTot (fmt:merkle_tree{mt_wf_elts #hsz fmt})
let mt_flush #hsz mt = | false | null | false | mt_flush_to mt (MT?.j mt - 1) | {
"checked_file": "MerkleTree.New.High.fst.checked",
"dependencies": [
"Spec.Hash.Definitions.fst.checked",
"prims.fst.checked",
"MerkleTree.Spec.fst.checked",
"Lib.IntTypes.fsti.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "MerkleTree.New.High.fst"
} | [
"sometrivial"
] | [
"Prims.pos",
"MerkleTree.New.High.merkle_tree",
"Prims.l_and",
"MerkleTree.New.High.mt_wf_elts",
"Prims.b2t",
"Prims.op_GreaterThan",
"MerkleTree.New.High.__proj__MT__item__j",
"MerkleTree.New.High.__proj__MT__item__i",
"MerkleTree.New.High.mt_flush_to",
"Prims.op_Subtraction"
] | [] | module MerkleTree.New.High
open FStar.Ghost
open FStar.Seq
module S = FStar.Seq
module U32 = FStar.UInt32
module U8 = FStar.UInt8
module MTS = MerkleTree.Spec
#set-options "--z3rlimit 10 --max_fuel 0 --max_ifuel 0"
type uint32_t = U32.t
type uint8_t = U8.t
type hash (#hsz:pos) = b:Spec.Hash.Definitions.bytes{Seq.length b = hsz}
type hashes (#hsz:pos) = S.seq (hash #hsz)
type hashess (#hsz:pos) = S.seq (hashes #hsz)
noextract
let hash_init (#hsz:pos): hash #hsz =
Seq.create hsz (Lib.IntTypes.u8 0)
val sha256_compress: src1:hash #32 -> src2:hash #32 -> GTot (hash #32)
let sha256_compress = MTS.sha256_compress
/// Facts about sequences
val seq_slice_equal_index:
#a:Type -> s1:S.seq a -> s2:S.seq a ->
i:nat -> j:nat{i <= j && j <= S.length s1 && j <= S.length s2} ->
k:nat{i <= k && k < j} ->
Lemma (requires S.equal (S.slice s1 i j) (S.slice s2 i j))
(ensures S.index s1 k == S.index s2 k)
[SMTPat (S.equal (S.slice s1 i j) (S.slice s2 i j));
SMTPat (S.index s1 k)]
let seq_slice_equal_index #a s1 s2 i j k =
assert (S.index (S.slice s1 i j) (k - i) == S.index (S.slice s2 i j) (k - i))
private val seq_slice_more_equal:
#a:Type -> s1:S.seq a -> s2:S.seq a ->
n:nat -> m:nat{n <= m && m <= S.length s1 && m <= S.length s2} ->
k:nat{n <= k} -> l:nat{k <= l && l <= m} ->
Lemma (requires S.equal (S.slice s1 n m) (S.slice s2 n m))
(ensures S.equal (S.slice s1 k l) (S.slice s2 k l))
[SMTPat (S.equal (S.slice s1 n m) (S.slice s2 n m));
SMTPat (S.equal (S.slice s1 k l) (S.slice s2 k l))]
private let seq_slice_more_equal #a s1 s2 n m k l =
slice_slice s1 n m (k - n) (l - n);
slice_slice s2 n m (k - n) (l - n)
/// Facts about "2"
val remainder_2_not_1_div: n:nat ->
Lemma (requires n % 2 <> 1)
(ensures n / 2 = (n + 1) / 2)
let remainder_2_not_1_div n = ()
val remainder_2_1_div: n:nat ->
Lemma (requires n % 2 = 1)
(ensures n / 2 + 1 = (n + 1) / 2)
let remainder_2_1_div n = ()
/// High-level Merkle tree data structure
noeq type merkle_tree (#hsz:pos) =
| MT: i:nat ->
j:nat{i <= j && j < pow2 32} ->
hs:hashess #hsz {S.length hs = 32} ->
rhs_ok:bool ->
rhs:hashes #hsz {S.length rhs = 32} -> // Rightmost hashes
mroot:hash #hsz ->
hash_fun:MTS.hash_fun_t #hsz ->
merkle_tree #hsz
val mt_not_full (#hsz:pos): merkle_tree #hsz -> GTot bool
let mt_not_full #hsz mt =
MT?.j mt < pow2 32 - 1
val mt_empty (#hsz:pos): merkle_tree #hsz -> GTot bool
let mt_empty #hsz mt =
MT?.j mt = 0
val mt_not_empty (#hsz:pos): merkle_tree #hsz -> GTot bool
let mt_not_empty #hsz mt =
MT?.j mt > 0
/// Well-formedness w.r.t. indices of base hash elements
noextract
val offset_of: i:nat -> Tot nat
let offset_of i =
if i % 2 = 0 then i else i - 1
val hs_wf_elts:
#hsz:pos ->
lv:nat{lv <= 32} ->
hs:hashess #hsz {S.length hs = 32} ->
i:nat -> j:nat{j >= i} ->
GTot Type0 (decreases (32 - lv))
let rec hs_wf_elts #hsz lv hs i j =
if lv = 32 then true
else (let ofs = offset_of i in
S.length (S.index hs lv) == j - ofs /\
hs_wf_elts #hsz (lv + 1) hs (i / 2) (j / 2))
#push-options "--max_fuel 1"
val hs_wf_elts_equal:
#hsz:pos ->
lv:nat{lv <= 32} ->
hs1:hashess #hsz {S.length hs1 = 32} ->
hs2:hashess #hsz {S.length hs2 = 32} ->
i:nat ->
j:nat{j >= i} ->
Lemma (requires hs_wf_elts lv hs1 i j /\
S.equal (S.slice hs1 lv 32) (S.slice hs2 lv 32))
(ensures hs_wf_elts lv hs2 i j)
(decreases (32 - lv))
let rec hs_wf_elts_equal #hsz lv hs1 hs2 i j =
if lv = 32 then ()
else (S.slice_slice hs1 lv 32 1 (32 - lv);
S.slice_slice hs2 lv 32 1 (32 - lv);
assert (S.equal (S.slice hs1 (lv + 1) 32)
(S.slice hs2 (lv + 1) 32));
S.lemma_index_slice hs1 lv 32 0;
S.lemma_index_slice hs2 lv 32 0;
assert (S.index hs1 lv == S.index hs2 lv);
hs_wf_elts_equal (lv + 1) hs1 hs2 (i / 2) (j / 2))
val mt_wf_elts (#hsz:pos): merkle_tree #hsz -> GTot Type0
let mt_wf_elts #_ (MT i j hs _ _ _ _) =
hs_wf_elts 0 hs i j
/// Construction
val hs_wf_elts_empty:
#hsz:pos ->
lv:nat{lv <= 32} ->
Lemma (requires True)
(ensures hs_wf_elts #hsz lv (S.create 32 S.empty) 0 0)
(decreases (32 - lv))
let rec hs_wf_elts_empty #hsz lv =
if lv = 32 then ()
else hs_wf_elts_empty #hsz (lv + 1)
// NOTE: the public function is `create_mt` defined below, which
// builds a tree with an initial hash.
noextract inline_for_extraction
val create_empty_mt (#hsz:pos) (#f:MTS.hash_fun_t #hsz): unit -> GTot (mt:merkle_tree #hsz {mt_wf_elts #hsz mt})
let create_empty_mt #hsz #f _ =
hs_wf_elts_empty #hsz 0;
MT 0 0 (S.create 32 S.empty) false (S.create 32 (hash_init #hsz)) (hash_init #hsz) f
/// Insertion
val hashess_insert:
#hsz:pos ->
lv:nat{lv < 32} ->
i:nat ->
j:nat{i <= j /\ j < pow2 (32 - lv) - 1} ->
hs:hashess #hsz {S.length hs = 32 /\ hs_wf_elts lv hs i j} ->
v:hash #hsz ->
GTot (ihs:hashess #hsz {S.length ihs = 32 /\ hs_wf_elts (lv + 1) ihs (i / 2) (j / 2)})
let hashess_insert #hsz lv i j hs v =
let ihs = S.upd hs lv (S.snoc (S.index hs lv) v) in
hs_wf_elts_equal (lv + 1) hs ihs (i / 2) (j / 2);
ihs
val insert_:
#hsz:pos -> #f:MTS.hash_fun_t #hsz ->
lv:nat{lv < 32} ->
i:nat ->
j:nat{i <= j /\ j < pow2 (32 - lv) - 1} ->
hs:hashess #hsz {S.length hs = 32 /\ hs_wf_elts lv hs i j} ->
acc:hash #hsz ->
GTot (ihs:hashess #hsz {
S.length ihs = 32 /\
hs_wf_elts #hsz lv ihs i (j + 1) /\
S.equal (S.slice hs 0 lv) (S.slice ihs 0 lv)})
(decreases j)
let rec insert_ #hsz #f lv i j hs acc =
let ihs = hashess_insert #hsz lv i j hs acc in
assert (S.equal (S.slice hs 0 lv) (S.slice ihs 0 lv));
if j % 2 = 1 // S.length (S.index hs lv) > 0
then begin
remainder_2_1_div j;
let nacc = f (S.last (S.index hs lv)) acc in
let rihs = insert_ #hsz #f (lv + 1) (i / 2) (j / 2) ihs nacc in
assert (hs_wf_elts #hsz (lv + 1) rihs (i / 2) (j / 2 + 1));
assert (S.equal (S.slice ihs 0 (lv + 1)) (S.slice rihs 0 (lv + 1)));
assert (S.index ihs lv == S.index rihs lv);
assert (S.length (S.index rihs lv) = (j + 1) - offset_of i);
assert (S.equal (S.slice ihs 0 (lv + 1)) (S.slice rihs 0 (lv + 1)));
assert (S.equal (S.slice ihs 0 lv) (S.slice rihs 0 lv));
rihs
end
else ihs
val insert_base:
#hsz:pos -> #f:MTS.hash_fun_t #hsz ->
lv:nat -> i:nat -> j:nat -> hs:hashess #hsz -> acc:hash #hsz ->
Lemma (requires
lv < 32 /\ i <= j /\ j < pow2 (32 - lv) - 1 /\
S.length hs = 32 /\ hs_wf_elts lv hs i j /\
j % 2 <> 1)
(ensures S.equal (insert_ #_ #f lv i j hs acc)
(hashess_insert lv i j hs acc))
let insert_base #_ #_ lv i j hs acc = ()
val insert_rec:
#hsz:pos -> #f:MTS.hash_fun_t #hsz ->
lv:nat -> i:nat -> j:nat -> hs:hashess -> acc:hash ->
Lemma (requires
lv < 32 /\ i <= j /\ j < pow2 (32 - lv) - 1 /\
S.length hs = 32 /\ hs_wf_elts lv hs i j /\
j % 2 == 1)
(ensures
(hs_wf_elts_equal (lv + 1) hs
(hashess_insert lv i j hs acc) (i / 2) (j / 2);
S.equal (insert_ #_ #f lv i j hs acc)
(insert_ #_ #f (lv + 1) (i / 2) (j / 2)
(hashess_insert lv i j hs acc)
(f (S.last (S.index hs lv)) acc))))
let insert_rec #_ #_ lv i j hs acc = ()
val mt_insert:
#hsz:pos ->
mt:merkle_tree #hsz {mt_wf_elts mt /\ mt_not_full mt} -> v:hash #hsz ->
GTot (imt:merkle_tree #hsz{mt_wf_elts #hsz imt})
let mt_insert #hsz mt v =
MT (MT?.i mt)
(MT?.j mt + 1)
(insert_ #_ #(MT?.hash_fun mt) 0 (MT?.i mt) (MT?.j mt) (MT?.hs mt) v)
false
(MT?.rhs mt)
(MT?.mroot mt)
(MT?.hash_fun mt)
val mt_create:
hsz:pos -> f:MTS.hash_fun_t #hsz ->
init:hash #hsz -> GTot (mt:merkle_tree{mt_wf_elts #hsz mt})
let mt_create hsz f init =
mt_insert #_ (create_empty_mt #_ #f ()) init
/// Getting the Merkle root and path
type path (#hsz:pos) = S.seq (hash #hsz)
// Construct the rightmost hashes for a given (incomplete) Merkle tree.
// This function calculates the Merkle root as well, which is the final
// accumulator value.
val construct_rhs:
#hsz:pos -> #f:MTS.hash_fun_t #hsz ->
lv:nat{lv <= 32} ->
hs:hashess #hsz {S.length hs = 32} ->
rhs:hashes #hsz {S.length rhs = 32} ->
i:nat ->
j:nat{
i <= j /\ j < pow2 (32 - lv) /\
hs_wf_elts #hsz lv hs i j} ->
acc:hash #hsz ->
actd:bool ->
GTot (crhs:hashes #hsz {S.length crhs = 32} * (hash #hsz))
(decreases j)
let rec construct_rhs #hsz #f lv hs rhs i j acc actd =
let ofs = offset_of i in
if j = 0 then (rhs, acc)
else
(if j % 2 = 0
then (construct_rhs #_ #f (lv + 1) hs rhs (i / 2) (j / 2) acc actd)
else (let nrhs = if actd then S.upd rhs lv acc else rhs in
let nacc = if actd
then f (S.index (S.index hs lv) (j - 1 - ofs)) acc
else S.index (S.index hs lv) (j - 1 - ofs) in
construct_rhs #_ #f (lv + 1) hs nrhs (i / 2) (j / 2) nacc true))
val construct_rhs_unchanged:
#hsz:pos -> #f:MTS.hash_fun_t #hsz ->
lv:nat{lv <= 32} ->
hs:hashess #hsz {S.length hs = 32} ->
rhs:hashes #hsz {S.length rhs = 32} ->
i:nat ->
j:nat{
i <= j /\ j < pow2 (32 - lv) /\
hs_wf_elts #hsz lv hs i j} ->
acc:hash #hsz ->
actd:bool ->
Lemma (requires True)
(ensures S.equal (S.slice rhs 0 lv)
(S.slice (fst (construct_rhs #_ #f lv hs rhs i j acc actd)) 0 lv))
(decreases j)
let rec construct_rhs_unchanged #hsz #f lv hs rhs i j acc actd =
let ofs = offset_of i in
if j = 0 then ()
else if j % 2 = 0
then (construct_rhs_unchanged #_ #f (lv + 1) hs rhs (i / 2) (j / 2) acc actd;
let rrhs = fst (construct_rhs #_ #f (lv + 1) hs rhs (i / 2) (j / 2) acc actd) in
assert (S.equal (S.slice rhs 0 lv) (S.slice rrhs 0 lv)))
else (let nrhs = if actd then S.upd rhs lv acc else rhs in
let nacc = if actd
then f (S.index (S.index hs lv) (j - 1 - ofs)) acc
else S.index (S.index hs lv) (j - 1 - ofs) in
construct_rhs_unchanged #_ #f (lv + 1) hs nrhs (i / 2) (j / 2) nacc true;
let rrhs = fst (construct_rhs #_ #f (lv + 1) hs nrhs (i / 2) (j / 2) nacc true) in
assert (S.equal (S.slice nrhs 0 lv) (S.slice rrhs 0 lv));
assert (S.equal (S.slice rhs 0 lv) (S.slice nrhs 0 lv)))
val construct_rhs_even:
#hsz:pos -> #f:MTS.hash_fun_t #hsz ->
lv:nat{lv <= 32} ->
hs:hashess #hsz {S.length hs = 32} ->
rhs:hashes #hsz {S.length rhs = 32} ->
i:nat ->
j:nat{
i <= j /\ j < pow2 (32 - lv) /\
hs_wf_elts #hsz lv hs i j} ->
acc:hash #hsz ->
actd:bool ->
Lemma (requires j <> 0 /\ j % 2 = 0)
(ensures construct_rhs #_ #f lv hs rhs i j acc actd ==
construct_rhs #_ #f (lv + 1) hs rhs (i / 2) (j / 2) acc actd)
let construct_rhs_even #_ #_ _ _ _ _ _ _ _ = ()
val construct_rhs_odd:
#hsz:pos -> #f:MTS.hash_fun_t #hsz ->
lv:nat{lv <= 32} ->
hs:hashess #hsz {S.length hs = 32} ->
rhs:hashes #hsz {S.length rhs = 32} ->
i:nat ->
j:nat{
i <= j /\ j < pow2 (32 - lv) /\
hs_wf_elts lv hs i j} ->
acc:hash ->
actd:bool ->
Lemma (requires j % 2 = 1)
(ensures construct_rhs #_ #f lv hs rhs i j acc actd ==
(let ofs = offset_of i in
let nrhs = if actd then S.upd rhs lv acc else rhs in
let nacc = if actd
then f (S.index (S.index hs lv) (j - 1 - ofs)) acc
else S.index (S.index hs lv) (j - 1 - ofs) in
construct_rhs #_ #f (lv + 1) hs nrhs (i / 2) (j / 2) nacc true))
let construct_rhs_odd #_ #_ _ _ _ _ _ _ _ = ()
val mt_get_root:
#hsz:pos ->
mt:merkle_tree #hsz {mt_wf_elts #hsz mt} -> drt:hash #hsz ->
GTot (merkle_tree #hsz * hash #hsz)
let mt_get_root #hsz mt drt =
if MT?.rhs_ok mt then (mt, MT?.mroot mt)
else begin
let (nrhs, rt) = construct_rhs #_ #(MT?.hash_fun mt) 0 (MT?.hs mt) (MT?.rhs mt) (MT?.i mt) (MT?.j mt) drt false in
(MT (MT?.i mt) (MT?.j mt) (MT?.hs mt) true nrhs rt (MT?.hash_fun mt), rt)
end
val mt_get_root_rhs_ok_true:
#hsz:pos ->
mt:merkle_tree #hsz {mt_wf_elts mt} -> drt:hash #hsz ->
Lemma (requires MT?.rhs_ok mt == true)
(ensures mt_get_root #hsz mt drt == (mt, MT?.mroot mt))
let mt_get_root_rhs_ok_true #hsz mt drt = ()
val mt_get_root_rhs_ok_false:
#hsz:pos ->
mt:merkle_tree #hsz {mt_wf_elts mt} -> drt:hash ->
Lemma (requires MT?.rhs_ok mt == false)
(ensures mt_get_root mt drt ==
(let (nrhs, rt) =
construct_rhs #_ #(MT?.hash_fun mt)
0 (MT?.hs mt) (MT?.rhs mt) (MT?.i mt) (MT?.j mt)
drt false in
(MT (MT?.i mt) (MT?.j mt) (MT?.hs mt) true nrhs rt (MT?.hash_fun mt), rt)))
let mt_get_root_rhs_ok_false #_ _ _ = ()
val path_insert: (#hsz:pos) -> p:path #hsz -> hp:hash #hsz -> GTot (path #hsz)
let path_insert #_ p hp = S.snoc p hp
val mt_path_length_step:
k:nat -> j:nat{k <= j} -> actd:bool -> GTot nat
let mt_path_length_step k j actd =
if j = 0 then 0
else (if k % 2 = 0
then (if j = k || (j = k + 1 && not actd) then 0 else 1)
else 1)
val mt_path_length:
k:nat -> j:nat{k <= j} -> actd:bool -> GTot nat
let rec mt_path_length k j actd =
if j = 0 then 0
else (let nactd = actd || (j % 2 = 1) in
mt_path_length_step k j actd +
mt_path_length (k / 2) (j / 2) nactd)
val mt_make_path_step:
#hsz:pos ->
lv:nat{lv <= 32} ->
hs:hashess #hsz {S.length hs = 32} ->
rhs:hashes #hsz {S.length rhs = 32} ->
i:nat ->
j:nat{
j <> 0 /\ i <= j /\ j < pow2 (32 - lv) /\
hs_wf_elts lv hs i j} ->
k:nat{i <= k && k <= j} ->
p:path #hsz ->
actd:bool ->
GTot (path #hsz)
let mt_make_path_step #hsz lv hs rhs i j k p actd =
let ofs = offset_of i in
if k % 2 = 1
then path_insert p (S.index (S.index hs lv) (k - 1 - ofs))
else (if k = j then p
else if k + 1 = j
then (if actd
then path_insert p (S.index rhs lv)
else p)
else path_insert p (S.index (S.index hs lv) (k + 1 - ofs)))
// Construct a Merkle path for a given index `k`, hashes `hs`,
// and rightmost hashes `rhs`.
val mt_get_path_:
#hsz:pos ->
lv:nat{lv <= 32} ->
hs:hashess #hsz {S.length hs = 32} ->
rhs:hashes #hsz {S.length rhs = 32} ->
i:nat ->
j:nat{
i <= j /\ j < pow2 (32 - lv) /\
hs_wf_elts lv hs i j} ->
k:nat{i <= k && k <= j} ->
p:path #hsz ->
actd:bool ->
GTot (np:path #hsz {S.length np = S.length p + mt_path_length k j actd})
(decreases (32 - lv))
let rec mt_get_path_ #hsz lv hs rhs i j k p actd =
let ofs = offset_of i in
if j = 0 then p
else
(let np = mt_make_path_step lv hs rhs i j k p actd in
mt_get_path_ (lv + 1) hs rhs (i / 2) (j / 2) (k / 2) np
(if j % 2 = 0 then actd else true))
val mt_get_path_unchanged:
#hsz:pos ->
lv:nat{lv <= 32} ->
hs:hashess #hsz {S.length hs = 32} ->
rhs:hashes #hsz {S.length rhs = 32} ->
i:nat ->
j:nat{
i <= j /\ j < pow2 (32 - lv) /\
hs_wf_elts #hsz lv hs i j} ->
k:nat{i <= k && k <= j} ->
p:path #hsz ->
actd:bool ->
Lemma (requires True)
(ensures S.equal p (S.slice (mt_get_path_ lv hs rhs i j k p actd)
0 (S.length p)))
(decreases (32 - lv))
let rec mt_get_path_unchanged #hsz lv hs rhs i j k p actd =
let ofs = offset_of i in
if j = 0 then ()
else
(let np = mt_make_path_step lv hs rhs i j k p actd in
assert (S.equal p (S.slice np 0 (S.length p)));
mt_get_path_unchanged (lv + 1) hs rhs (i / 2) (j / 2) (k / 2) np
(if j % 2 = 0 then actd else true))
#push-options "--z3rlimit 20"
val mt_get_path_pull:
#hsz:pos ->
lv:nat{lv <= 32} ->
hs:hashess #hsz {S.length hs = 32} ->
rhs:hashes #hsz {S.length rhs = 32} ->
i:nat ->
j:nat{
i <= j /\ j < pow2 (32 - lv) /\
hs_wf_elts lv hs i j} ->
k:nat{i <= k && k <= j} ->
p:path #hsz ->
actd:bool ->
Lemma (requires True)
(ensures S.equal (mt_get_path_ lv hs rhs i j k p actd)
(S.append p (mt_get_path_ lv hs rhs i j k S.empty actd)))
(decreases (32 - lv))
let rec mt_get_path_pull #hsz lv hs rhs i j k p actd =
let ofs = offset_of i in
if j = 0 then ()
else
(let np = mt_make_path_step lv hs rhs i j k p actd in
let nactd = if j % 2 = 0 then actd else true in
mt_get_path_pull (lv + 1) hs rhs (i / 2) (j / 2) (k / 2) np nactd;
mt_get_path_pull (lv + 1) hs rhs (i / 2) (j / 2) (k / 2)
(mt_make_path_step lv hs rhs i j k S.empty actd) nactd)
#pop-options
val mt_get_path_slice:
#hsz:pos ->
lv:nat{lv <= 32} ->
hs:hashess #hsz {S.length hs = 32} ->
rhs:hashes #hsz {S.length rhs = 32} ->
i:nat ->
j:nat{
i <= j /\ j < pow2 (32 - lv) /\
hs_wf_elts lv hs i j} ->
k:nat{i <= k && k <= j} ->
p:path #hsz ->
actd:bool ->
Lemma (requires True)
(ensures S.equal (S.slice (mt_get_path_ lv hs rhs i j k p actd)
(S.length p) (S.length p + mt_path_length k j actd))
(mt_get_path_ lv hs rhs i j k S.empty actd))
(decreases (32 - lv))
let mt_get_path_slice #hsz lv hs rhs i j k p actd =
mt_get_path_pull lv hs rhs i j k p actd
val mt_get_path:
#hsz:pos ->
mt:merkle_tree #hsz {mt_wf_elts mt} ->
idx:nat{MT?.i mt <= idx /\ idx < MT?.j mt} ->
drt:hash #hsz ->
GTot (nat *
(np:path #hsz {S.length np = 1 + mt_path_length idx (MT?.j mt) false}) *
hash #hsz)
let mt_get_path #hsz mt idx drt =
let (umt, root) = mt_get_root mt drt in
let ofs = offset_of (MT?.i umt) in
let np = path_insert S.empty (S.index (S.index (MT?.hs umt) 0) (idx - ofs)) in
MT?.j umt,
mt_get_path_ 0 (MT?.hs umt) (MT?.rhs umt)
(MT?.i umt) (MT?.j umt) idx np false,
root
/// Flushing
val mt_flush_to_:
#hsz:pos ->
lv:nat{lv < 32} ->
hs:hashess #hsz {S.length hs = 32} ->
pi:nat ->
i:nat{i >= pi} ->
j:nat{
j >= i /\ j < pow2 (32 - lv) /\
hs_wf_elts #hsz lv hs pi j} ->
GTot (fhs:hashess{
S.length fhs = 32 /\
S.equal (S.slice hs 0 lv) (S.slice fhs 0 lv) /\
hs_wf_elts #hsz lv fhs i j})
(decreases i)
let rec mt_flush_to_ #hsz lv hs pi i j =
let oi = offset_of i in
let opi = offset_of pi in
if oi = opi then hs
else (let ofs = oi - opi in
let hvec = S.index hs lv in
let flushed = S.slice hvec ofs (S.length hvec) in
let nhs = S.upd hs lv flushed in
hs_wf_elts_equal (lv + 1) hs nhs (pi / 2) (j / 2);
mt_flush_to_ (lv + 1) nhs (pi / 2) (i / 2) (j / 2))
val mt_flush_to_rec:
#hsz:pos ->
lv:nat{lv < 32} ->
hs:hashess #hsz {S.length hs = 32} ->
pi:nat ->
i:nat{i >= pi} ->
j:nat{
j >= i /\ j < pow2 (32 - lv) /\
hs_wf_elts lv hs pi j} ->
Lemma (requires offset_of i <> offset_of pi)
(ensures mt_flush_to_ lv hs pi i j ==
(let ofs = offset_of i - offset_of pi in
let hvec = S.index hs lv in
let flushed = S.slice hvec ofs (S.length hvec) in
let nhs = S.upd hs lv flushed in
hs_wf_elts_equal (lv + 1) hs nhs (pi / 2) (j / 2);
mt_flush_to_ #hsz (lv + 1) nhs (pi / 2) (i / 2) (j / 2)))
let mt_flush_to_rec #hsz lv hs pi i j = ()
val mt_flush_to:
#hsz:pos ->
mt:merkle_tree #hsz {mt_wf_elts mt} ->
idx:nat{idx >= MT?.i mt /\ idx < MT?.j mt} ->
GTot (fmt:merkle_tree{mt_wf_elts #hsz fmt})
let mt_flush_to #hsz mt idx =
let fhs = mt_flush_to_ #hsz 0 (MT?.hs mt) (MT?.i mt) idx (MT?.j mt) in
MT idx (MT?.j mt) fhs (MT?.rhs_ok mt) (MT?.rhs mt) (MT?.mroot mt) (MT?.hash_fun mt)
val mt_flush:
#hsz:pos ->
mt:merkle_tree #hsz {mt_wf_elts mt /\ MT?.j mt > MT?.i mt} ->
GTot (fmt:merkle_tree{mt_wf_elts #hsz fmt}) | false | false | MerkleTree.New.High.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 1,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 10,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val mt_flush:
#hsz:pos ->
mt:merkle_tree #hsz {mt_wf_elts mt /\ MT?.j mt > MT?.i mt} ->
GTot (fmt:merkle_tree{mt_wf_elts #hsz fmt}) | [] | MerkleTree.New.High.mt_flush | {
"file_name": "src/MerkleTree.New.High.fst",
"git_rev": "3b0f086655c145aa23f58a97259ebf4cf112a4a3",
"git_url": "https://github.com/hacl-star/merkle-tree.git",
"project_name": "merkle-tree"
} | mt: MerkleTree.New.High.merkle_tree{MerkleTree.New.High.mt_wf_elts mt /\ MT?.j mt > MT?.i mt}
-> Prims.GTot (fmt: MerkleTree.New.High.merkle_tree{MerkleTree.New.High.mt_wf_elts fmt}) | {
"end_col": 31,
"end_line": 598,
"start_col": 2,
"start_line": 598
} |
Prims.Tot | val offset_of: i:nat -> Tot nat | [
{
"abbrev": true,
"full_module": "MerkleTree.Spec",
"short_module": "MTS"
},
{
"abbrev": true,
"full_module": "FStar.UInt8",
"short_module": "U8"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "S"
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Ghost",
"short_module": null
},
{
"abbrev": false,
"full_module": "MerkleTree.New",
"short_module": null
},
{
"abbrev": false,
"full_module": "MerkleTree.New",
"short_module": null
},
{
"abbrev": 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 offset_of i =
if i % 2 = 0 then i else i - 1 | val offset_of: i:nat -> Tot nat
let offset_of i = | false | null | false | if i % 2 = 0 then i else i - 1 | {
"checked_file": "MerkleTree.New.High.fst.checked",
"dependencies": [
"Spec.Hash.Definitions.fst.checked",
"prims.fst.checked",
"MerkleTree.Spec.fst.checked",
"Lib.IntTypes.fsti.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "MerkleTree.New.High.fst"
} | [
"total"
] | [
"Prims.nat",
"Prims.op_Equality",
"Prims.int",
"Prims.op_Modulus",
"Prims.bool",
"Prims.op_Subtraction"
] | [] | module MerkleTree.New.High
open FStar.Ghost
open FStar.Seq
module S = FStar.Seq
module U32 = FStar.UInt32
module U8 = FStar.UInt8
module MTS = MerkleTree.Spec
#set-options "--z3rlimit 10 --max_fuel 0 --max_ifuel 0"
type uint32_t = U32.t
type uint8_t = U8.t
type hash (#hsz:pos) = b:Spec.Hash.Definitions.bytes{Seq.length b = hsz}
type hashes (#hsz:pos) = S.seq (hash #hsz)
type hashess (#hsz:pos) = S.seq (hashes #hsz)
noextract
let hash_init (#hsz:pos): hash #hsz =
Seq.create hsz (Lib.IntTypes.u8 0)
val sha256_compress: src1:hash #32 -> src2:hash #32 -> GTot (hash #32)
let sha256_compress = MTS.sha256_compress
/// Facts about sequences
val seq_slice_equal_index:
#a:Type -> s1:S.seq a -> s2:S.seq a ->
i:nat -> j:nat{i <= j && j <= S.length s1 && j <= S.length s2} ->
k:nat{i <= k && k < j} ->
Lemma (requires S.equal (S.slice s1 i j) (S.slice s2 i j))
(ensures S.index s1 k == S.index s2 k)
[SMTPat (S.equal (S.slice s1 i j) (S.slice s2 i j));
SMTPat (S.index s1 k)]
let seq_slice_equal_index #a s1 s2 i j k =
assert (S.index (S.slice s1 i j) (k - i) == S.index (S.slice s2 i j) (k - i))
private val seq_slice_more_equal:
#a:Type -> s1:S.seq a -> s2:S.seq a ->
n:nat -> m:nat{n <= m && m <= S.length s1 && m <= S.length s2} ->
k:nat{n <= k} -> l:nat{k <= l && l <= m} ->
Lemma (requires S.equal (S.slice s1 n m) (S.slice s2 n m))
(ensures S.equal (S.slice s1 k l) (S.slice s2 k l))
[SMTPat (S.equal (S.slice s1 n m) (S.slice s2 n m));
SMTPat (S.equal (S.slice s1 k l) (S.slice s2 k l))]
private let seq_slice_more_equal #a s1 s2 n m k l =
slice_slice s1 n m (k - n) (l - n);
slice_slice s2 n m (k - n) (l - n)
/// Facts about "2"
val remainder_2_not_1_div: n:nat ->
Lemma (requires n % 2 <> 1)
(ensures n / 2 = (n + 1) / 2)
let remainder_2_not_1_div n = ()
val remainder_2_1_div: n:nat ->
Lemma (requires n % 2 = 1)
(ensures n / 2 + 1 = (n + 1) / 2)
let remainder_2_1_div n = ()
/// High-level Merkle tree data structure
noeq type merkle_tree (#hsz:pos) =
| MT: i:nat ->
j:nat{i <= j && j < pow2 32} ->
hs:hashess #hsz {S.length hs = 32} ->
rhs_ok:bool ->
rhs:hashes #hsz {S.length rhs = 32} -> // Rightmost hashes
mroot:hash #hsz ->
hash_fun:MTS.hash_fun_t #hsz ->
merkle_tree #hsz
val mt_not_full (#hsz:pos): merkle_tree #hsz -> GTot bool
let mt_not_full #hsz mt =
MT?.j mt < pow2 32 - 1
val mt_empty (#hsz:pos): merkle_tree #hsz -> GTot bool
let mt_empty #hsz mt =
MT?.j mt = 0
val mt_not_empty (#hsz:pos): merkle_tree #hsz -> GTot bool
let mt_not_empty #hsz mt =
MT?.j mt > 0
/// Well-formedness w.r.t. indices of base hash elements
noextract
val offset_of: i:nat -> Tot nat | false | true | MerkleTree.New.High.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 10,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val offset_of: i:nat -> Tot nat | [] | MerkleTree.New.High.offset_of | {
"file_name": "src/MerkleTree.New.High.fst",
"git_rev": "3b0f086655c145aa23f58a97259ebf4cf112a4a3",
"git_url": "https://github.com/hacl-star/merkle-tree.git",
"project_name": "merkle-tree"
} | i: Prims.nat -> Prims.nat | {
"end_col": 32,
"end_line": 96,
"start_col": 2,
"start_line": 96
} |
Prims.GTot | val mt_create:
hsz:pos -> f:MTS.hash_fun_t #hsz ->
init:hash #hsz -> GTot (mt:merkle_tree{mt_wf_elts #hsz mt}) | [
{
"abbrev": true,
"full_module": "MerkleTree.Spec",
"short_module": "MTS"
},
{
"abbrev": true,
"full_module": "FStar.UInt8",
"short_module": "U8"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "S"
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Ghost",
"short_module": null
},
{
"abbrev": false,
"full_module": "MerkleTree.New",
"short_module": null
},
{
"abbrev": false,
"full_module": "MerkleTree.New",
"short_module": null
},
{
"abbrev": 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 mt_create hsz f init =
mt_insert #_ (create_empty_mt #_ #f ()) init | val mt_create:
hsz:pos -> f:MTS.hash_fun_t #hsz ->
init:hash #hsz -> GTot (mt:merkle_tree{mt_wf_elts #hsz mt})
let mt_create hsz f init = | false | null | false | mt_insert #_ (create_empty_mt #_ #f ()) init | {
"checked_file": "MerkleTree.New.High.fst.checked",
"dependencies": [
"Spec.Hash.Definitions.fst.checked",
"prims.fst.checked",
"MerkleTree.Spec.fst.checked",
"Lib.IntTypes.fsti.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "MerkleTree.New.High.fst"
} | [
"sometrivial"
] | [
"Prims.pos",
"MerkleTree.Spec.hash_fun_t",
"MerkleTree.New.High.hash",
"MerkleTree.New.High.mt_insert",
"MerkleTree.New.High.create_empty_mt",
"MerkleTree.New.High.merkle_tree",
"MerkleTree.New.High.mt_wf_elts"
] | [] | module MerkleTree.New.High
open FStar.Ghost
open FStar.Seq
module S = FStar.Seq
module U32 = FStar.UInt32
module U8 = FStar.UInt8
module MTS = MerkleTree.Spec
#set-options "--z3rlimit 10 --max_fuel 0 --max_ifuel 0"
type uint32_t = U32.t
type uint8_t = U8.t
type hash (#hsz:pos) = b:Spec.Hash.Definitions.bytes{Seq.length b = hsz}
type hashes (#hsz:pos) = S.seq (hash #hsz)
type hashess (#hsz:pos) = S.seq (hashes #hsz)
noextract
let hash_init (#hsz:pos): hash #hsz =
Seq.create hsz (Lib.IntTypes.u8 0)
val sha256_compress: src1:hash #32 -> src2:hash #32 -> GTot (hash #32)
let sha256_compress = MTS.sha256_compress
/// Facts about sequences
val seq_slice_equal_index:
#a:Type -> s1:S.seq a -> s2:S.seq a ->
i:nat -> j:nat{i <= j && j <= S.length s1 && j <= S.length s2} ->
k:nat{i <= k && k < j} ->
Lemma (requires S.equal (S.slice s1 i j) (S.slice s2 i j))
(ensures S.index s1 k == S.index s2 k)
[SMTPat (S.equal (S.slice s1 i j) (S.slice s2 i j));
SMTPat (S.index s1 k)]
let seq_slice_equal_index #a s1 s2 i j k =
assert (S.index (S.slice s1 i j) (k - i) == S.index (S.slice s2 i j) (k - i))
private val seq_slice_more_equal:
#a:Type -> s1:S.seq a -> s2:S.seq a ->
n:nat -> m:nat{n <= m && m <= S.length s1 && m <= S.length s2} ->
k:nat{n <= k} -> l:nat{k <= l && l <= m} ->
Lemma (requires S.equal (S.slice s1 n m) (S.slice s2 n m))
(ensures S.equal (S.slice s1 k l) (S.slice s2 k l))
[SMTPat (S.equal (S.slice s1 n m) (S.slice s2 n m));
SMTPat (S.equal (S.slice s1 k l) (S.slice s2 k l))]
private let seq_slice_more_equal #a s1 s2 n m k l =
slice_slice s1 n m (k - n) (l - n);
slice_slice s2 n m (k - n) (l - n)
/// Facts about "2"
val remainder_2_not_1_div: n:nat ->
Lemma (requires n % 2 <> 1)
(ensures n / 2 = (n + 1) / 2)
let remainder_2_not_1_div n = ()
val remainder_2_1_div: n:nat ->
Lemma (requires n % 2 = 1)
(ensures n / 2 + 1 = (n + 1) / 2)
let remainder_2_1_div n = ()
/// High-level Merkle tree data structure
noeq type merkle_tree (#hsz:pos) =
| MT: i:nat ->
j:nat{i <= j && j < pow2 32} ->
hs:hashess #hsz {S.length hs = 32} ->
rhs_ok:bool ->
rhs:hashes #hsz {S.length rhs = 32} -> // Rightmost hashes
mroot:hash #hsz ->
hash_fun:MTS.hash_fun_t #hsz ->
merkle_tree #hsz
val mt_not_full (#hsz:pos): merkle_tree #hsz -> GTot bool
let mt_not_full #hsz mt =
MT?.j mt < pow2 32 - 1
val mt_empty (#hsz:pos): merkle_tree #hsz -> GTot bool
let mt_empty #hsz mt =
MT?.j mt = 0
val mt_not_empty (#hsz:pos): merkle_tree #hsz -> GTot bool
let mt_not_empty #hsz mt =
MT?.j mt > 0
/// Well-formedness w.r.t. indices of base hash elements
noextract
val offset_of: i:nat -> Tot nat
let offset_of i =
if i % 2 = 0 then i else i - 1
val hs_wf_elts:
#hsz:pos ->
lv:nat{lv <= 32} ->
hs:hashess #hsz {S.length hs = 32} ->
i:nat -> j:nat{j >= i} ->
GTot Type0 (decreases (32 - lv))
let rec hs_wf_elts #hsz lv hs i j =
if lv = 32 then true
else (let ofs = offset_of i in
S.length (S.index hs lv) == j - ofs /\
hs_wf_elts #hsz (lv + 1) hs (i / 2) (j / 2))
#push-options "--max_fuel 1"
val hs_wf_elts_equal:
#hsz:pos ->
lv:nat{lv <= 32} ->
hs1:hashess #hsz {S.length hs1 = 32} ->
hs2:hashess #hsz {S.length hs2 = 32} ->
i:nat ->
j:nat{j >= i} ->
Lemma (requires hs_wf_elts lv hs1 i j /\
S.equal (S.slice hs1 lv 32) (S.slice hs2 lv 32))
(ensures hs_wf_elts lv hs2 i j)
(decreases (32 - lv))
let rec hs_wf_elts_equal #hsz lv hs1 hs2 i j =
if lv = 32 then ()
else (S.slice_slice hs1 lv 32 1 (32 - lv);
S.slice_slice hs2 lv 32 1 (32 - lv);
assert (S.equal (S.slice hs1 (lv + 1) 32)
(S.slice hs2 (lv + 1) 32));
S.lemma_index_slice hs1 lv 32 0;
S.lemma_index_slice hs2 lv 32 0;
assert (S.index hs1 lv == S.index hs2 lv);
hs_wf_elts_equal (lv + 1) hs1 hs2 (i / 2) (j / 2))
val mt_wf_elts (#hsz:pos): merkle_tree #hsz -> GTot Type0
let mt_wf_elts #_ (MT i j hs _ _ _ _) =
hs_wf_elts 0 hs i j
/// Construction
val hs_wf_elts_empty:
#hsz:pos ->
lv:nat{lv <= 32} ->
Lemma (requires True)
(ensures hs_wf_elts #hsz lv (S.create 32 S.empty) 0 0)
(decreases (32 - lv))
let rec hs_wf_elts_empty #hsz lv =
if lv = 32 then ()
else hs_wf_elts_empty #hsz (lv + 1)
// NOTE: the public function is `create_mt` defined below, which
// builds a tree with an initial hash.
noextract inline_for_extraction
val create_empty_mt (#hsz:pos) (#f:MTS.hash_fun_t #hsz): unit -> GTot (mt:merkle_tree #hsz {mt_wf_elts #hsz mt})
let create_empty_mt #hsz #f _ =
hs_wf_elts_empty #hsz 0;
MT 0 0 (S.create 32 S.empty) false (S.create 32 (hash_init #hsz)) (hash_init #hsz) f
/// Insertion
val hashess_insert:
#hsz:pos ->
lv:nat{lv < 32} ->
i:nat ->
j:nat{i <= j /\ j < pow2 (32 - lv) - 1} ->
hs:hashess #hsz {S.length hs = 32 /\ hs_wf_elts lv hs i j} ->
v:hash #hsz ->
GTot (ihs:hashess #hsz {S.length ihs = 32 /\ hs_wf_elts (lv + 1) ihs (i / 2) (j / 2)})
let hashess_insert #hsz lv i j hs v =
let ihs = S.upd hs lv (S.snoc (S.index hs lv) v) in
hs_wf_elts_equal (lv + 1) hs ihs (i / 2) (j / 2);
ihs
val insert_:
#hsz:pos -> #f:MTS.hash_fun_t #hsz ->
lv:nat{lv < 32} ->
i:nat ->
j:nat{i <= j /\ j < pow2 (32 - lv) - 1} ->
hs:hashess #hsz {S.length hs = 32 /\ hs_wf_elts lv hs i j} ->
acc:hash #hsz ->
GTot (ihs:hashess #hsz {
S.length ihs = 32 /\
hs_wf_elts #hsz lv ihs i (j + 1) /\
S.equal (S.slice hs 0 lv) (S.slice ihs 0 lv)})
(decreases j)
let rec insert_ #hsz #f lv i j hs acc =
let ihs = hashess_insert #hsz lv i j hs acc in
assert (S.equal (S.slice hs 0 lv) (S.slice ihs 0 lv));
if j % 2 = 1 // S.length (S.index hs lv) > 0
then begin
remainder_2_1_div j;
let nacc = f (S.last (S.index hs lv)) acc in
let rihs = insert_ #hsz #f (lv + 1) (i / 2) (j / 2) ihs nacc in
assert (hs_wf_elts #hsz (lv + 1) rihs (i / 2) (j / 2 + 1));
assert (S.equal (S.slice ihs 0 (lv + 1)) (S.slice rihs 0 (lv + 1)));
assert (S.index ihs lv == S.index rihs lv);
assert (S.length (S.index rihs lv) = (j + 1) - offset_of i);
assert (S.equal (S.slice ihs 0 (lv + 1)) (S.slice rihs 0 (lv + 1)));
assert (S.equal (S.slice ihs 0 lv) (S.slice rihs 0 lv));
rihs
end
else ihs
val insert_base:
#hsz:pos -> #f:MTS.hash_fun_t #hsz ->
lv:nat -> i:nat -> j:nat -> hs:hashess #hsz -> acc:hash #hsz ->
Lemma (requires
lv < 32 /\ i <= j /\ j < pow2 (32 - lv) - 1 /\
S.length hs = 32 /\ hs_wf_elts lv hs i j /\
j % 2 <> 1)
(ensures S.equal (insert_ #_ #f lv i j hs acc)
(hashess_insert lv i j hs acc))
let insert_base #_ #_ lv i j hs acc = ()
val insert_rec:
#hsz:pos -> #f:MTS.hash_fun_t #hsz ->
lv:nat -> i:nat -> j:nat -> hs:hashess -> acc:hash ->
Lemma (requires
lv < 32 /\ i <= j /\ j < pow2 (32 - lv) - 1 /\
S.length hs = 32 /\ hs_wf_elts lv hs i j /\
j % 2 == 1)
(ensures
(hs_wf_elts_equal (lv + 1) hs
(hashess_insert lv i j hs acc) (i / 2) (j / 2);
S.equal (insert_ #_ #f lv i j hs acc)
(insert_ #_ #f (lv + 1) (i / 2) (j / 2)
(hashess_insert lv i j hs acc)
(f (S.last (S.index hs lv)) acc))))
let insert_rec #_ #_ lv i j hs acc = ()
val mt_insert:
#hsz:pos ->
mt:merkle_tree #hsz {mt_wf_elts mt /\ mt_not_full mt} -> v:hash #hsz ->
GTot (imt:merkle_tree #hsz{mt_wf_elts #hsz imt})
let mt_insert #hsz mt v =
MT (MT?.i mt)
(MT?.j mt + 1)
(insert_ #_ #(MT?.hash_fun mt) 0 (MT?.i mt) (MT?.j mt) (MT?.hs mt) v)
false
(MT?.rhs mt)
(MT?.mroot mt)
(MT?.hash_fun mt)
val mt_create:
hsz:pos -> f:MTS.hash_fun_t #hsz ->
init:hash #hsz -> GTot (mt:merkle_tree{mt_wf_elts #hsz mt}) | false | false | MerkleTree.New.High.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 1,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 10,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val mt_create:
hsz:pos -> f:MTS.hash_fun_t #hsz ->
init:hash #hsz -> GTot (mt:merkle_tree{mt_wf_elts #hsz mt}) | [] | MerkleTree.New.High.mt_create | {
"file_name": "src/MerkleTree.New.High.fst",
"git_rev": "3b0f086655c145aa23f58a97259ebf4cf112a4a3",
"git_url": "https://github.com/hacl-star/merkle-tree.git",
"project_name": "merkle-tree"
} | hsz: Prims.pos -> f: MerkleTree.Spec.hash_fun_t -> init: MerkleTree.New.High.hash
-> Prims.GTot (mt: MerkleTree.New.High.merkle_tree{MerkleTree.New.High.mt_wf_elts mt}) | {
"end_col": 46,
"end_line": 247,
"start_col": 2,
"start_line": 247
} |
Prims.GTot | val mt_verify:
#hsz:pos -> #f:MTS.hash_fun_t #hsz ->
k:nat ->
j:nat{k < j} ->
p:path #hsz {S.length p = 1 + mt_path_length k j false} ->
rt:hash #hsz ->
GTot prop | [
{
"abbrev": true,
"full_module": "MerkleTree.Spec",
"short_module": "MTS"
},
{
"abbrev": true,
"full_module": "FStar.UInt8",
"short_module": "U8"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "S"
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Ghost",
"short_module": null
},
{
"abbrev": false,
"full_module": "MerkleTree.New",
"short_module": null
},
{
"abbrev": false,
"full_module": "MerkleTree.New",
"short_module": null
},
{
"abbrev": 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 mt_verify #_ #f k j p rt =
let crt = mt_verify_ #_ #f k j p 1 (S.index p 0) false in
crt == rt | val mt_verify:
#hsz:pos -> #f:MTS.hash_fun_t #hsz ->
k:nat ->
j:nat{k < j} ->
p:path #hsz {S.length p = 1 + mt_path_length k j false} ->
rt:hash #hsz ->
GTot prop
let mt_verify #_ #f k j p rt = | false | null | false | let crt = mt_verify_ #_ #f k j p 1 (S.index p 0) false in
crt == rt | {
"checked_file": "MerkleTree.New.High.fst.checked",
"dependencies": [
"Spec.Hash.Definitions.fst.checked",
"prims.fst.checked",
"MerkleTree.Spec.fst.checked",
"Lib.IntTypes.fsti.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "MerkleTree.New.High.fst"
} | [
"sometrivial"
] | [
"Prims.pos",
"MerkleTree.Spec.hash_fun_t",
"Prims.nat",
"Prims.b2t",
"Prims.op_LessThan",
"MerkleTree.New.High.path",
"Prims.op_Equality",
"Prims.int",
"FStar.Seq.Base.length",
"MerkleTree.New.High.hash",
"Prims.op_Addition",
"MerkleTree.New.High.mt_path_length",
"Prims.eq2",
"MerkleTree.New.High.mt_verify_",
"FStar.Seq.Base.index",
"Prims.prop"
] | [] | module MerkleTree.New.High
open FStar.Ghost
open FStar.Seq
module S = FStar.Seq
module U32 = FStar.UInt32
module U8 = FStar.UInt8
module MTS = MerkleTree.Spec
#set-options "--z3rlimit 10 --max_fuel 0 --max_ifuel 0"
type uint32_t = U32.t
type uint8_t = U8.t
type hash (#hsz:pos) = b:Spec.Hash.Definitions.bytes{Seq.length b = hsz}
type hashes (#hsz:pos) = S.seq (hash #hsz)
type hashess (#hsz:pos) = S.seq (hashes #hsz)
noextract
let hash_init (#hsz:pos): hash #hsz =
Seq.create hsz (Lib.IntTypes.u8 0)
val sha256_compress: src1:hash #32 -> src2:hash #32 -> GTot (hash #32)
let sha256_compress = MTS.sha256_compress
/// Facts about sequences
val seq_slice_equal_index:
#a:Type -> s1:S.seq a -> s2:S.seq a ->
i:nat -> j:nat{i <= j && j <= S.length s1 && j <= S.length s2} ->
k:nat{i <= k && k < j} ->
Lemma (requires S.equal (S.slice s1 i j) (S.slice s2 i j))
(ensures S.index s1 k == S.index s2 k)
[SMTPat (S.equal (S.slice s1 i j) (S.slice s2 i j));
SMTPat (S.index s1 k)]
let seq_slice_equal_index #a s1 s2 i j k =
assert (S.index (S.slice s1 i j) (k - i) == S.index (S.slice s2 i j) (k - i))
private val seq_slice_more_equal:
#a:Type -> s1:S.seq a -> s2:S.seq a ->
n:nat -> m:nat{n <= m && m <= S.length s1 && m <= S.length s2} ->
k:nat{n <= k} -> l:nat{k <= l && l <= m} ->
Lemma (requires S.equal (S.slice s1 n m) (S.slice s2 n m))
(ensures S.equal (S.slice s1 k l) (S.slice s2 k l))
[SMTPat (S.equal (S.slice s1 n m) (S.slice s2 n m));
SMTPat (S.equal (S.slice s1 k l) (S.slice s2 k l))]
private let seq_slice_more_equal #a s1 s2 n m k l =
slice_slice s1 n m (k - n) (l - n);
slice_slice s2 n m (k - n) (l - n)
/// Facts about "2"
val remainder_2_not_1_div: n:nat ->
Lemma (requires n % 2 <> 1)
(ensures n / 2 = (n + 1) / 2)
let remainder_2_not_1_div n = ()
val remainder_2_1_div: n:nat ->
Lemma (requires n % 2 = 1)
(ensures n / 2 + 1 = (n + 1) / 2)
let remainder_2_1_div n = ()
/// High-level Merkle tree data structure
noeq type merkle_tree (#hsz:pos) =
| MT: i:nat ->
j:nat{i <= j && j < pow2 32} ->
hs:hashess #hsz {S.length hs = 32} ->
rhs_ok:bool ->
rhs:hashes #hsz {S.length rhs = 32} -> // Rightmost hashes
mroot:hash #hsz ->
hash_fun:MTS.hash_fun_t #hsz ->
merkle_tree #hsz
val mt_not_full (#hsz:pos): merkle_tree #hsz -> GTot bool
let mt_not_full #hsz mt =
MT?.j mt < pow2 32 - 1
val mt_empty (#hsz:pos): merkle_tree #hsz -> GTot bool
let mt_empty #hsz mt =
MT?.j mt = 0
val mt_not_empty (#hsz:pos): merkle_tree #hsz -> GTot bool
let mt_not_empty #hsz mt =
MT?.j mt > 0
/// Well-formedness w.r.t. indices of base hash elements
noextract
val offset_of: i:nat -> Tot nat
let offset_of i =
if i % 2 = 0 then i else i - 1
val hs_wf_elts:
#hsz:pos ->
lv:nat{lv <= 32} ->
hs:hashess #hsz {S.length hs = 32} ->
i:nat -> j:nat{j >= i} ->
GTot Type0 (decreases (32 - lv))
let rec hs_wf_elts #hsz lv hs i j =
if lv = 32 then true
else (let ofs = offset_of i in
S.length (S.index hs lv) == j - ofs /\
hs_wf_elts #hsz (lv + 1) hs (i / 2) (j / 2))
#push-options "--max_fuel 1"
val hs_wf_elts_equal:
#hsz:pos ->
lv:nat{lv <= 32} ->
hs1:hashess #hsz {S.length hs1 = 32} ->
hs2:hashess #hsz {S.length hs2 = 32} ->
i:nat ->
j:nat{j >= i} ->
Lemma (requires hs_wf_elts lv hs1 i j /\
S.equal (S.slice hs1 lv 32) (S.slice hs2 lv 32))
(ensures hs_wf_elts lv hs2 i j)
(decreases (32 - lv))
let rec hs_wf_elts_equal #hsz lv hs1 hs2 i j =
if lv = 32 then ()
else (S.slice_slice hs1 lv 32 1 (32 - lv);
S.slice_slice hs2 lv 32 1 (32 - lv);
assert (S.equal (S.slice hs1 (lv + 1) 32)
(S.slice hs2 (lv + 1) 32));
S.lemma_index_slice hs1 lv 32 0;
S.lemma_index_slice hs2 lv 32 0;
assert (S.index hs1 lv == S.index hs2 lv);
hs_wf_elts_equal (lv + 1) hs1 hs2 (i / 2) (j / 2))
val mt_wf_elts (#hsz:pos): merkle_tree #hsz -> GTot Type0
let mt_wf_elts #_ (MT i j hs _ _ _ _) =
hs_wf_elts 0 hs i j
/// Construction
val hs_wf_elts_empty:
#hsz:pos ->
lv:nat{lv <= 32} ->
Lemma (requires True)
(ensures hs_wf_elts #hsz lv (S.create 32 S.empty) 0 0)
(decreases (32 - lv))
let rec hs_wf_elts_empty #hsz lv =
if lv = 32 then ()
else hs_wf_elts_empty #hsz (lv + 1)
// NOTE: the public function is `create_mt` defined below, which
// builds a tree with an initial hash.
noextract inline_for_extraction
val create_empty_mt (#hsz:pos) (#f:MTS.hash_fun_t #hsz): unit -> GTot (mt:merkle_tree #hsz {mt_wf_elts #hsz mt})
let create_empty_mt #hsz #f _ =
hs_wf_elts_empty #hsz 0;
MT 0 0 (S.create 32 S.empty) false (S.create 32 (hash_init #hsz)) (hash_init #hsz) f
/// Insertion
val hashess_insert:
#hsz:pos ->
lv:nat{lv < 32} ->
i:nat ->
j:nat{i <= j /\ j < pow2 (32 - lv) - 1} ->
hs:hashess #hsz {S.length hs = 32 /\ hs_wf_elts lv hs i j} ->
v:hash #hsz ->
GTot (ihs:hashess #hsz {S.length ihs = 32 /\ hs_wf_elts (lv + 1) ihs (i / 2) (j / 2)})
let hashess_insert #hsz lv i j hs v =
let ihs = S.upd hs lv (S.snoc (S.index hs lv) v) in
hs_wf_elts_equal (lv + 1) hs ihs (i / 2) (j / 2);
ihs
val insert_:
#hsz:pos -> #f:MTS.hash_fun_t #hsz ->
lv:nat{lv < 32} ->
i:nat ->
j:nat{i <= j /\ j < pow2 (32 - lv) - 1} ->
hs:hashess #hsz {S.length hs = 32 /\ hs_wf_elts lv hs i j} ->
acc:hash #hsz ->
GTot (ihs:hashess #hsz {
S.length ihs = 32 /\
hs_wf_elts #hsz lv ihs i (j + 1) /\
S.equal (S.slice hs 0 lv) (S.slice ihs 0 lv)})
(decreases j)
let rec insert_ #hsz #f lv i j hs acc =
let ihs = hashess_insert #hsz lv i j hs acc in
assert (S.equal (S.slice hs 0 lv) (S.slice ihs 0 lv));
if j % 2 = 1 // S.length (S.index hs lv) > 0
then begin
remainder_2_1_div j;
let nacc = f (S.last (S.index hs lv)) acc in
let rihs = insert_ #hsz #f (lv + 1) (i / 2) (j / 2) ihs nacc in
assert (hs_wf_elts #hsz (lv + 1) rihs (i / 2) (j / 2 + 1));
assert (S.equal (S.slice ihs 0 (lv + 1)) (S.slice rihs 0 (lv + 1)));
assert (S.index ihs lv == S.index rihs lv);
assert (S.length (S.index rihs lv) = (j + 1) - offset_of i);
assert (S.equal (S.slice ihs 0 (lv + 1)) (S.slice rihs 0 (lv + 1)));
assert (S.equal (S.slice ihs 0 lv) (S.slice rihs 0 lv));
rihs
end
else ihs
val insert_base:
#hsz:pos -> #f:MTS.hash_fun_t #hsz ->
lv:nat -> i:nat -> j:nat -> hs:hashess #hsz -> acc:hash #hsz ->
Lemma (requires
lv < 32 /\ i <= j /\ j < pow2 (32 - lv) - 1 /\
S.length hs = 32 /\ hs_wf_elts lv hs i j /\
j % 2 <> 1)
(ensures S.equal (insert_ #_ #f lv i j hs acc)
(hashess_insert lv i j hs acc))
let insert_base #_ #_ lv i j hs acc = ()
val insert_rec:
#hsz:pos -> #f:MTS.hash_fun_t #hsz ->
lv:nat -> i:nat -> j:nat -> hs:hashess -> acc:hash ->
Lemma (requires
lv < 32 /\ i <= j /\ j < pow2 (32 - lv) - 1 /\
S.length hs = 32 /\ hs_wf_elts lv hs i j /\
j % 2 == 1)
(ensures
(hs_wf_elts_equal (lv + 1) hs
(hashess_insert lv i j hs acc) (i / 2) (j / 2);
S.equal (insert_ #_ #f lv i j hs acc)
(insert_ #_ #f (lv + 1) (i / 2) (j / 2)
(hashess_insert lv i j hs acc)
(f (S.last (S.index hs lv)) acc))))
let insert_rec #_ #_ lv i j hs acc = ()
val mt_insert:
#hsz:pos ->
mt:merkle_tree #hsz {mt_wf_elts mt /\ mt_not_full mt} -> v:hash #hsz ->
GTot (imt:merkle_tree #hsz{mt_wf_elts #hsz imt})
let mt_insert #hsz mt v =
MT (MT?.i mt)
(MT?.j mt + 1)
(insert_ #_ #(MT?.hash_fun mt) 0 (MT?.i mt) (MT?.j mt) (MT?.hs mt) v)
false
(MT?.rhs mt)
(MT?.mroot mt)
(MT?.hash_fun mt)
val mt_create:
hsz:pos -> f:MTS.hash_fun_t #hsz ->
init:hash #hsz -> GTot (mt:merkle_tree{mt_wf_elts #hsz mt})
let mt_create hsz f init =
mt_insert #_ (create_empty_mt #_ #f ()) init
/// Getting the Merkle root and path
type path (#hsz:pos) = S.seq (hash #hsz)
// Construct the rightmost hashes for a given (incomplete) Merkle tree.
// This function calculates the Merkle root as well, which is the final
// accumulator value.
val construct_rhs:
#hsz:pos -> #f:MTS.hash_fun_t #hsz ->
lv:nat{lv <= 32} ->
hs:hashess #hsz {S.length hs = 32} ->
rhs:hashes #hsz {S.length rhs = 32} ->
i:nat ->
j:nat{
i <= j /\ j < pow2 (32 - lv) /\
hs_wf_elts #hsz lv hs i j} ->
acc:hash #hsz ->
actd:bool ->
GTot (crhs:hashes #hsz {S.length crhs = 32} * (hash #hsz))
(decreases j)
let rec construct_rhs #hsz #f lv hs rhs i j acc actd =
let ofs = offset_of i in
if j = 0 then (rhs, acc)
else
(if j % 2 = 0
then (construct_rhs #_ #f (lv + 1) hs rhs (i / 2) (j / 2) acc actd)
else (let nrhs = if actd then S.upd rhs lv acc else rhs in
let nacc = if actd
then f (S.index (S.index hs lv) (j - 1 - ofs)) acc
else S.index (S.index hs lv) (j - 1 - ofs) in
construct_rhs #_ #f (lv + 1) hs nrhs (i / 2) (j / 2) nacc true))
val construct_rhs_unchanged:
#hsz:pos -> #f:MTS.hash_fun_t #hsz ->
lv:nat{lv <= 32} ->
hs:hashess #hsz {S.length hs = 32} ->
rhs:hashes #hsz {S.length rhs = 32} ->
i:nat ->
j:nat{
i <= j /\ j < pow2 (32 - lv) /\
hs_wf_elts #hsz lv hs i j} ->
acc:hash #hsz ->
actd:bool ->
Lemma (requires True)
(ensures S.equal (S.slice rhs 0 lv)
(S.slice (fst (construct_rhs #_ #f lv hs rhs i j acc actd)) 0 lv))
(decreases j)
let rec construct_rhs_unchanged #hsz #f lv hs rhs i j acc actd =
let ofs = offset_of i in
if j = 0 then ()
else if j % 2 = 0
then (construct_rhs_unchanged #_ #f (lv + 1) hs rhs (i / 2) (j / 2) acc actd;
let rrhs = fst (construct_rhs #_ #f (lv + 1) hs rhs (i / 2) (j / 2) acc actd) in
assert (S.equal (S.slice rhs 0 lv) (S.slice rrhs 0 lv)))
else (let nrhs = if actd then S.upd rhs lv acc else rhs in
let nacc = if actd
then f (S.index (S.index hs lv) (j - 1 - ofs)) acc
else S.index (S.index hs lv) (j - 1 - ofs) in
construct_rhs_unchanged #_ #f (lv + 1) hs nrhs (i / 2) (j / 2) nacc true;
let rrhs = fst (construct_rhs #_ #f (lv + 1) hs nrhs (i / 2) (j / 2) nacc true) in
assert (S.equal (S.slice nrhs 0 lv) (S.slice rrhs 0 lv));
assert (S.equal (S.slice rhs 0 lv) (S.slice nrhs 0 lv)))
val construct_rhs_even:
#hsz:pos -> #f:MTS.hash_fun_t #hsz ->
lv:nat{lv <= 32} ->
hs:hashess #hsz {S.length hs = 32} ->
rhs:hashes #hsz {S.length rhs = 32} ->
i:nat ->
j:nat{
i <= j /\ j < pow2 (32 - lv) /\
hs_wf_elts #hsz lv hs i j} ->
acc:hash #hsz ->
actd:bool ->
Lemma (requires j <> 0 /\ j % 2 = 0)
(ensures construct_rhs #_ #f lv hs rhs i j acc actd ==
construct_rhs #_ #f (lv + 1) hs rhs (i / 2) (j / 2) acc actd)
let construct_rhs_even #_ #_ _ _ _ _ _ _ _ = ()
val construct_rhs_odd:
#hsz:pos -> #f:MTS.hash_fun_t #hsz ->
lv:nat{lv <= 32} ->
hs:hashess #hsz {S.length hs = 32} ->
rhs:hashes #hsz {S.length rhs = 32} ->
i:nat ->
j:nat{
i <= j /\ j < pow2 (32 - lv) /\
hs_wf_elts lv hs i j} ->
acc:hash ->
actd:bool ->
Lemma (requires j % 2 = 1)
(ensures construct_rhs #_ #f lv hs rhs i j acc actd ==
(let ofs = offset_of i in
let nrhs = if actd then S.upd rhs lv acc else rhs in
let nacc = if actd
then f (S.index (S.index hs lv) (j - 1 - ofs)) acc
else S.index (S.index hs lv) (j - 1 - ofs) in
construct_rhs #_ #f (lv + 1) hs nrhs (i / 2) (j / 2) nacc true))
let construct_rhs_odd #_ #_ _ _ _ _ _ _ _ = ()
val mt_get_root:
#hsz:pos ->
mt:merkle_tree #hsz {mt_wf_elts #hsz mt} -> drt:hash #hsz ->
GTot (merkle_tree #hsz * hash #hsz)
let mt_get_root #hsz mt drt =
if MT?.rhs_ok mt then (mt, MT?.mroot mt)
else begin
let (nrhs, rt) = construct_rhs #_ #(MT?.hash_fun mt) 0 (MT?.hs mt) (MT?.rhs mt) (MT?.i mt) (MT?.j mt) drt false in
(MT (MT?.i mt) (MT?.j mt) (MT?.hs mt) true nrhs rt (MT?.hash_fun mt), rt)
end
val mt_get_root_rhs_ok_true:
#hsz:pos ->
mt:merkle_tree #hsz {mt_wf_elts mt} -> drt:hash #hsz ->
Lemma (requires MT?.rhs_ok mt == true)
(ensures mt_get_root #hsz mt drt == (mt, MT?.mroot mt))
let mt_get_root_rhs_ok_true #hsz mt drt = ()
val mt_get_root_rhs_ok_false:
#hsz:pos ->
mt:merkle_tree #hsz {mt_wf_elts mt} -> drt:hash ->
Lemma (requires MT?.rhs_ok mt == false)
(ensures mt_get_root mt drt ==
(let (nrhs, rt) =
construct_rhs #_ #(MT?.hash_fun mt)
0 (MT?.hs mt) (MT?.rhs mt) (MT?.i mt) (MT?.j mt)
drt false in
(MT (MT?.i mt) (MT?.j mt) (MT?.hs mt) true nrhs rt (MT?.hash_fun mt), rt)))
let mt_get_root_rhs_ok_false #_ _ _ = ()
val path_insert: (#hsz:pos) -> p:path #hsz -> hp:hash #hsz -> GTot (path #hsz)
let path_insert #_ p hp = S.snoc p hp
val mt_path_length_step:
k:nat -> j:nat{k <= j} -> actd:bool -> GTot nat
let mt_path_length_step k j actd =
if j = 0 then 0
else (if k % 2 = 0
then (if j = k || (j = k + 1 && not actd) then 0 else 1)
else 1)
val mt_path_length:
k:nat -> j:nat{k <= j} -> actd:bool -> GTot nat
let rec mt_path_length k j actd =
if j = 0 then 0
else (let nactd = actd || (j % 2 = 1) in
mt_path_length_step k j actd +
mt_path_length (k / 2) (j / 2) nactd)
val mt_make_path_step:
#hsz:pos ->
lv:nat{lv <= 32} ->
hs:hashess #hsz {S.length hs = 32} ->
rhs:hashes #hsz {S.length rhs = 32} ->
i:nat ->
j:nat{
j <> 0 /\ i <= j /\ j < pow2 (32 - lv) /\
hs_wf_elts lv hs i j} ->
k:nat{i <= k && k <= j} ->
p:path #hsz ->
actd:bool ->
GTot (path #hsz)
let mt_make_path_step #hsz lv hs rhs i j k p actd =
let ofs = offset_of i in
if k % 2 = 1
then path_insert p (S.index (S.index hs lv) (k - 1 - ofs))
else (if k = j then p
else if k + 1 = j
then (if actd
then path_insert p (S.index rhs lv)
else p)
else path_insert p (S.index (S.index hs lv) (k + 1 - ofs)))
// Construct a Merkle path for a given index `k`, hashes `hs`,
// and rightmost hashes `rhs`.
val mt_get_path_:
#hsz:pos ->
lv:nat{lv <= 32} ->
hs:hashess #hsz {S.length hs = 32} ->
rhs:hashes #hsz {S.length rhs = 32} ->
i:nat ->
j:nat{
i <= j /\ j < pow2 (32 - lv) /\
hs_wf_elts lv hs i j} ->
k:nat{i <= k && k <= j} ->
p:path #hsz ->
actd:bool ->
GTot (np:path #hsz {S.length np = S.length p + mt_path_length k j actd})
(decreases (32 - lv))
let rec mt_get_path_ #hsz lv hs rhs i j k p actd =
let ofs = offset_of i in
if j = 0 then p
else
(let np = mt_make_path_step lv hs rhs i j k p actd in
mt_get_path_ (lv + 1) hs rhs (i / 2) (j / 2) (k / 2) np
(if j % 2 = 0 then actd else true))
val mt_get_path_unchanged:
#hsz:pos ->
lv:nat{lv <= 32} ->
hs:hashess #hsz {S.length hs = 32} ->
rhs:hashes #hsz {S.length rhs = 32} ->
i:nat ->
j:nat{
i <= j /\ j < pow2 (32 - lv) /\
hs_wf_elts #hsz lv hs i j} ->
k:nat{i <= k && k <= j} ->
p:path #hsz ->
actd:bool ->
Lemma (requires True)
(ensures S.equal p (S.slice (mt_get_path_ lv hs rhs i j k p actd)
0 (S.length p)))
(decreases (32 - lv))
let rec mt_get_path_unchanged #hsz lv hs rhs i j k p actd =
let ofs = offset_of i in
if j = 0 then ()
else
(let np = mt_make_path_step lv hs rhs i j k p actd in
assert (S.equal p (S.slice np 0 (S.length p)));
mt_get_path_unchanged (lv + 1) hs rhs (i / 2) (j / 2) (k / 2) np
(if j % 2 = 0 then actd else true))
#push-options "--z3rlimit 20"
val mt_get_path_pull:
#hsz:pos ->
lv:nat{lv <= 32} ->
hs:hashess #hsz {S.length hs = 32} ->
rhs:hashes #hsz {S.length rhs = 32} ->
i:nat ->
j:nat{
i <= j /\ j < pow2 (32 - lv) /\
hs_wf_elts lv hs i j} ->
k:nat{i <= k && k <= j} ->
p:path #hsz ->
actd:bool ->
Lemma (requires True)
(ensures S.equal (mt_get_path_ lv hs rhs i j k p actd)
(S.append p (mt_get_path_ lv hs rhs i j k S.empty actd)))
(decreases (32 - lv))
let rec mt_get_path_pull #hsz lv hs rhs i j k p actd =
let ofs = offset_of i in
if j = 0 then ()
else
(let np = mt_make_path_step lv hs rhs i j k p actd in
let nactd = if j % 2 = 0 then actd else true in
mt_get_path_pull (lv + 1) hs rhs (i / 2) (j / 2) (k / 2) np nactd;
mt_get_path_pull (lv + 1) hs rhs (i / 2) (j / 2) (k / 2)
(mt_make_path_step lv hs rhs i j k S.empty actd) nactd)
#pop-options
val mt_get_path_slice:
#hsz:pos ->
lv:nat{lv <= 32} ->
hs:hashess #hsz {S.length hs = 32} ->
rhs:hashes #hsz {S.length rhs = 32} ->
i:nat ->
j:nat{
i <= j /\ j < pow2 (32 - lv) /\
hs_wf_elts lv hs i j} ->
k:nat{i <= k && k <= j} ->
p:path #hsz ->
actd:bool ->
Lemma (requires True)
(ensures S.equal (S.slice (mt_get_path_ lv hs rhs i j k p actd)
(S.length p) (S.length p + mt_path_length k j actd))
(mt_get_path_ lv hs rhs i j k S.empty actd))
(decreases (32 - lv))
let mt_get_path_slice #hsz lv hs rhs i j k p actd =
mt_get_path_pull lv hs rhs i j k p actd
val mt_get_path:
#hsz:pos ->
mt:merkle_tree #hsz {mt_wf_elts mt} ->
idx:nat{MT?.i mt <= idx /\ idx < MT?.j mt} ->
drt:hash #hsz ->
GTot (nat *
(np:path #hsz {S.length np = 1 + mt_path_length idx (MT?.j mt) false}) *
hash #hsz)
let mt_get_path #hsz mt idx drt =
let (umt, root) = mt_get_root mt drt in
let ofs = offset_of (MT?.i umt) in
let np = path_insert S.empty (S.index (S.index (MT?.hs umt) 0) (idx - ofs)) in
MT?.j umt,
mt_get_path_ 0 (MT?.hs umt) (MT?.rhs umt)
(MT?.i umt) (MT?.j umt) idx np false,
root
/// Flushing
val mt_flush_to_:
#hsz:pos ->
lv:nat{lv < 32} ->
hs:hashess #hsz {S.length hs = 32} ->
pi:nat ->
i:nat{i >= pi} ->
j:nat{
j >= i /\ j < pow2 (32 - lv) /\
hs_wf_elts #hsz lv hs pi j} ->
GTot (fhs:hashess{
S.length fhs = 32 /\
S.equal (S.slice hs 0 lv) (S.slice fhs 0 lv) /\
hs_wf_elts #hsz lv fhs i j})
(decreases i)
let rec mt_flush_to_ #hsz lv hs pi i j =
let oi = offset_of i in
let opi = offset_of pi in
if oi = opi then hs
else (let ofs = oi - opi in
let hvec = S.index hs lv in
let flushed = S.slice hvec ofs (S.length hvec) in
let nhs = S.upd hs lv flushed in
hs_wf_elts_equal (lv + 1) hs nhs (pi / 2) (j / 2);
mt_flush_to_ (lv + 1) nhs (pi / 2) (i / 2) (j / 2))
val mt_flush_to_rec:
#hsz:pos ->
lv:nat{lv < 32} ->
hs:hashess #hsz {S.length hs = 32} ->
pi:nat ->
i:nat{i >= pi} ->
j:nat{
j >= i /\ j < pow2 (32 - lv) /\
hs_wf_elts lv hs pi j} ->
Lemma (requires offset_of i <> offset_of pi)
(ensures mt_flush_to_ lv hs pi i j ==
(let ofs = offset_of i - offset_of pi in
let hvec = S.index hs lv in
let flushed = S.slice hvec ofs (S.length hvec) in
let nhs = S.upd hs lv flushed in
hs_wf_elts_equal (lv + 1) hs nhs (pi / 2) (j / 2);
mt_flush_to_ #hsz (lv + 1) nhs (pi / 2) (i / 2) (j / 2)))
let mt_flush_to_rec #hsz lv hs pi i j = ()
val mt_flush_to:
#hsz:pos ->
mt:merkle_tree #hsz {mt_wf_elts mt} ->
idx:nat{idx >= MT?.i mt /\ idx < MT?.j mt} ->
GTot (fmt:merkle_tree{mt_wf_elts #hsz fmt})
let mt_flush_to #hsz mt idx =
let fhs = mt_flush_to_ #hsz 0 (MT?.hs mt) (MT?.i mt) idx (MT?.j mt) in
MT idx (MT?.j mt) fhs (MT?.rhs_ok mt) (MT?.rhs mt) (MT?.mroot mt) (MT?.hash_fun mt)
val mt_flush:
#hsz:pos ->
mt:merkle_tree #hsz {mt_wf_elts mt /\ MT?.j mt > MT?.i mt} ->
GTot (fmt:merkle_tree{mt_wf_elts #hsz fmt})
let mt_flush #hsz mt =
mt_flush_to mt (MT?.j mt - 1)
#push-options "--max_fuel 2"
/// Retraction
val mt_retract_to_:
#hsz:pos ->
hs:hashess #hsz {S.length hs = 32} ->
lv:nat{lv < S.length hs} ->
i:nat ->
s:nat -> // s is the first index excluded from nhs
j:nat{ i <= s /\ s <= j /\
j < pow2 (S.length hs - lv) /\
hs_wf_elts lv hs i j} ->
GTot (nhs:hashess #hsz {
S.length nhs = S.length hs /\
S.equal (S.slice hs 0 lv) (S.slice nhs 0 lv) /\
hs_wf_elts #hsz lv nhs i s})
(decreases (S.length hs - lv))
let rec mt_retract_to_ #hsz hs lv i s j =
if lv >= S.length hs then hs
else begin
let hvec = S.index hs lv in
let old_len = j - offset_of i in
let new_len = s - offset_of i in
assert (S.length hvec = old_len);
assert (new_len <= old_len);
assert (new_len <= S.length hvec);
let retracted = S.slice hvec 0 new_len in
let nhs = S.upd hs lv retracted in
if lv >= S.length hs - 1 then nhs else
begin
hs_wf_elts_equal (lv + 1) hs nhs (i / 2) (j / 2);
mt_retract_to_ nhs (lv + 1) (i / 2) (s / 2) (j / 2)
end
end
#pop-options
val mt_retract_to:
#hsz:pos ->
mt:merkle_tree #hsz {mt_wf_elts mt} ->
r:nat{MT?.i mt <= r /\ r < MT?.j mt} ->
GTot (rmt:merkle_tree #hsz {mt_wf_elts rmt /\ MT?.i rmt = MT?.i mt /\ MT?.j rmt = r + 1})
let mt_retract_to #hsz mt r =
let nhs = mt_retract_to_ (MT?.hs mt) 0 (MT?.i mt) (r+1) (MT?.j mt) in
MT (MT?.i mt) (r+1) nhs false (MT?.rhs mt) (MT?.mroot mt) (MT?.hash_fun mt)
/// Verification
val mt_verify_:
#hsz:pos -> #f:MTS.hash_fun_t #hsz ->
k:nat ->
j:nat{k <= j} ->
p:path #hsz ->
ppos:nat ->
acc:hash #hsz ->
actd:bool{ppos + mt_path_length k j actd <= S.length p} ->
GTot (hash #hsz)
let rec mt_verify_ #hsz #f k j p ppos acc actd =
if j = 0 then acc
else (let nactd = actd || (j % 2 = 1) in
if k % 2 = 0
then (if j = k || (j = k + 1 && not actd)
then mt_verify_ #_ #f (k / 2) (j / 2) p ppos acc nactd
else (let nacc = f acc (S.index p ppos) in
mt_verify_ #_ #f (k / 2) (j / 2) p (ppos + 1) nacc nactd))
else (let nacc = f (S.index p ppos) acc in
mt_verify_ #_ #f (k / 2) (j / 2) p (ppos + 1) nacc nactd))
val mt_verify:
#hsz:pos -> #f:MTS.hash_fun_t #hsz ->
k:nat ->
j:nat{k < j} ->
p:path #hsz {S.length p = 1 + mt_path_length k j false} ->
rt:hash #hsz -> | false | false | MerkleTree.New.High.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 1,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 10,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val mt_verify:
#hsz:pos -> #f:MTS.hash_fun_t #hsz ->
k:nat ->
j:nat{k < j} ->
p:path #hsz {S.length p = 1 + mt_path_length k j false} ->
rt:hash #hsz ->
GTot prop | [] | MerkleTree.New.High.mt_verify | {
"file_name": "src/MerkleTree.New.High.fst",
"git_rev": "3b0f086655c145aa23f58a97259ebf4cf112a4a3",
"git_url": "https://github.com/hacl-star/merkle-tree.git",
"project_name": "merkle-tree"
} |
k: Prims.nat ->
j: Prims.nat{k < j} ->
p:
MerkleTree.New.High.path
{FStar.Seq.Base.length p = 1 + MerkleTree.New.High.mt_path_length k j false} ->
rt: MerkleTree.New.High.hash
-> Prims.GTot Prims.prop | {
"end_col": 11,
"end_line": 679,
"start_col": 30,
"start_line": 677
} |
Prims.GTot | val hs_wf_elts:
#hsz:pos ->
lv:nat{lv <= 32} ->
hs:hashess #hsz {S.length hs = 32} ->
i:nat -> j:nat{j >= i} ->
GTot Type0 (decreases (32 - lv)) | [
{
"abbrev": true,
"full_module": "MerkleTree.Spec",
"short_module": "MTS"
},
{
"abbrev": true,
"full_module": "FStar.UInt8",
"short_module": "U8"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "S"
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Ghost",
"short_module": null
},
{
"abbrev": false,
"full_module": "MerkleTree.New",
"short_module": null
},
{
"abbrev": false,
"full_module": "MerkleTree.New",
"short_module": null
},
{
"abbrev": 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 hs_wf_elts #hsz lv hs i j =
if lv = 32 then true
else (let ofs = offset_of i in
S.length (S.index hs lv) == j - ofs /\
hs_wf_elts #hsz (lv + 1) hs (i / 2) (j / 2)) | val hs_wf_elts:
#hsz:pos ->
lv:nat{lv <= 32} ->
hs:hashess #hsz {S.length hs = 32} ->
i:nat -> j:nat{j >= i} ->
GTot Type0 (decreases (32 - lv))
let rec hs_wf_elts #hsz lv hs i j = | false | null | false | if lv = 32
then true
else
(let ofs = offset_of i in
S.length (S.index hs lv) == j - ofs /\ hs_wf_elts #hsz (lv + 1) hs (i / 2) (j / 2)) | {
"checked_file": "MerkleTree.New.High.fst.checked",
"dependencies": [
"Spec.Hash.Definitions.fst.checked",
"prims.fst.checked",
"MerkleTree.Spec.fst.checked",
"Lib.IntTypes.fsti.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "MerkleTree.New.High.fst"
} | [
"sometrivial",
""
] | [
"Prims.pos",
"Prims.nat",
"Prims.b2t",
"Prims.op_LessThanOrEqual",
"MerkleTree.New.High.hashess",
"Prims.op_Equality",
"Prims.int",
"FStar.Seq.Base.length",
"MerkleTree.New.High.hashes",
"Prims.op_GreaterThanOrEqual",
"Prims.bool",
"Prims.l_and",
"Prims.eq2",
"MerkleTree.New.High.hash",
"FStar.Seq.Base.index",
"Prims.op_Subtraction",
"MerkleTree.New.High.hs_wf_elts",
"Prims.op_Addition",
"Prims.op_Division",
"MerkleTree.New.High.offset_of"
] | [] | module MerkleTree.New.High
open FStar.Ghost
open FStar.Seq
module S = FStar.Seq
module U32 = FStar.UInt32
module U8 = FStar.UInt8
module MTS = MerkleTree.Spec
#set-options "--z3rlimit 10 --max_fuel 0 --max_ifuel 0"
type uint32_t = U32.t
type uint8_t = U8.t
type hash (#hsz:pos) = b:Spec.Hash.Definitions.bytes{Seq.length b = hsz}
type hashes (#hsz:pos) = S.seq (hash #hsz)
type hashess (#hsz:pos) = S.seq (hashes #hsz)
noextract
let hash_init (#hsz:pos): hash #hsz =
Seq.create hsz (Lib.IntTypes.u8 0)
val sha256_compress: src1:hash #32 -> src2:hash #32 -> GTot (hash #32)
let sha256_compress = MTS.sha256_compress
/// Facts about sequences
val seq_slice_equal_index:
#a:Type -> s1:S.seq a -> s2:S.seq a ->
i:nat -> j:nat{i <= j && j <= S.length s1 && j <= S.length s2} ->
k:nat{i <= k && k < j} ->
Lemma (requires S.equal (S.slice s1 i j) (S.slice s2 i j))
(ensures S.index s1 k == S.index s2 k)
[SMTPat (S.equal (S.slice s1 i j) (S.slice s2 i j));
SMTPat (S.index s1 k)]
let seq_slice_equal_index #a s1 s2 i j k =
assert (S.index (S.slice s1 i j) (k - i) == S.index (S.slice s2 i j) (k - i))
private val seq_slice_more_equal:
#a:Type -> s1:S.seq a -> s2:S.seq a ->
n:nat -> m:nat{n <= m && m <= S.length s1 && m <= S.length s2} ->
k:nat{n <= k} -> l:nat{k <= l && l <= m} ->
Lemma (requires S.equal (S.slice s1 n m) (S.slice s2 n m))
(ensures S.equal (S.slice s1 k l) (S.slice s2 k l))
[SMTPat (S.equal (S.slice s1 n m) (S.slice s2 n m));
SMTPat (S.equal (S.slice s1 k l) (S.slice s2 k l))]
private let seq_slice_more_equal #a s1 s2 n m k l =
slice_slice s1 n m (k - n) (l - n);
slice_slice s2 n m (k - n) (l - n)
/// Facts about "2"
val remainder_2_not_1_div: n:nat ->
Lemma (requires n % 2 <> 1)
(ensures n / 2 = (n + 1) / 2)
let remainder_2_not_1_div n = ()
val remainder_2_1_div: n:nat ->
Lemma (requires n % 2 = 1)
(ensures n / 2 + 1 = (n + 1) / 2)
let remainder_2_1_div n = ()
/// High-level Merkle tree data structure
noeq type merkle_tree (#hsz:pos) =
| MT: i:nat ->
j:nat{i <= j && j < pow2 32} ->
hs:hashess #hsz {S.length hs = 32} ->
rhs_ok:bool ->
rhs:hashes #hsz {S.length rhs = 32} -> // Rightmost hashes
mroot:hash #hsz ->
hash_fun:MTS.hash_fun_t #hsz ->
merkle_tree #hsz
val mt_not_full (#hsz:pos): merkle_tree #hsz -> GTot bool
let mt_not_full #hsz mt =
MT?.j mt < pow2 32 - 1
val mt_empty (#hsz:pos): merkle_tree #hsz -> GTot bool
let mt_empty #hsz mt =
MT?.j mt = 0
val mt_not_empty (#hsz:pos): merkle_tree #hsz -> GTot bool
let mt_not_empty #hsz mt =
MT?.j mt > 0
/// Well-formedness w.r.t. indices of base hash elements
noextract
val offset_of: i:nat -> Tot nat
let offset_of i =
if i % 2 = 0 then i else i - 1
val hs_wf_elts:
#hsz:pos ->
lv:nat{lv <= 32} ->
hs:hashess #hsz {S.length hs = 32} ->
i:nat -> j:nat{j >= i} ->
GTot Type0 (decreases (32 - lv)) | false | false | MerkleTree.New.High.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 10,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val hs_wf_elts:
#hsz:pos ->
lv:nat{lv <= 32} ->
hs:hashess #hsz {S.length hs = 32} ->
i:nat -> j:nat{j >= i} ->
GTot Type0 (decreases (32 - lv)) | [
"recursion"
] | MerkleTree.New.High.hs_wf_elts | {
"file_name": "src/MerkleTree.New.High.fst",
"git_rev": "3b0f086655c145aa23f58a97259ebf4cf112a4a3",
"git_url": "https://github.com/hacl-star/merkle-tree.git",
"project_name": "merkle-tree"
} |
lv: Prims.nat{lv <= 32} ->
hs: MerkleTree.New.High.hashess{FStar.Seq.Base.length hs = 32} ->
i: Prims.nat ->
j: Prims.nat{j >= i}
-> Prims.GTot Type0 | {
"end_col": 51,
"end_line": 108,
"start_col": 2,
"start_line": 105
} |
Prims.Tot | val hash_init (#hsz: pos) : hash #hsz | [
{
"abbrev": true,
"full_module": "MerkleTree.Spec",
"short_module": "MTS"
},
{
"abbrev": true,
"full_module": "FStar.UInt8",
"short_module": "U8"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "S"
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Ghost",
"short_module": null
},
{
"abbrev": false,
"full_module": "MerkleTree.New",
"short_module": null
},
{
"abbrev": false,
"full_module": "MerkleTree.New",
"short_module": null
},
{
"abbrev": 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_init (#hsz:pos): hash #hsz =
Seq.create hsz (Lib.IntTypes.u8 0) | val hash_init (#hsz: pos) : hash #hsz
let hash_init (#hsz: pos) : hash #hsz = | false | null | false | Seq.create hsz (Lib.IntTypes.u8 0) | {
"checked_file": "MerkleTree.New.High.fst.checked",
"dependencies": [
"Spec.Hash.Definitions.fst.checked",
"prims.fst.checked",
"MerkleTree.Spec.fst.checked",
"Lib.IntTypes.fsti.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "MerkleTree.New.High.fst"
} | [
"total"
] | [
"Prims.pos",
"FStar.Seq.Base.create",
"Lib.IntTypes.uint8",
"Lib.IntTypes.u8",
"MerkleTree.New.High.hash"
] | [] | module MerkleTree.New.High
open FStar.Ghost
open FStar.Seq
module S = FStar.Seq
module U32 = FStar.UInt32
module U8 = FStar.UInt8
module MTS = MerkleTree.Spec
#set-options "--z3rlimit 10 --max_fuel 0 --max_ifuel 0"
type uint32_t = U32.t
type uint8_t = U8.t
type hash (#hsz:pos) = b:Spec.Hash.Definitions.bytes{Seq.length b = hsz}
type hashes (#hsz:pos) = S.seq (hash #hsz)
type hashess (#hsz:pos) = S.seq (hashes #hsz)
noextract | false | false | MerkleTree.New.High.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 10,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val hash_init (#hsz: pos) : hash #hsz | [] | MerkleTree.New.High.hash_init | {
"file_name": "src/MerkleTree.New.High.fst",
"git_rev": "3b0f086655c145aa23f58a97259ebf4cf112a4a3",
"git_url": "https://github.com/hacl-star/merkle-tree.git",
"project_name": "merkle-tree"
} | MerkleTree.New.High.hash | {
"end_col": 36,
"end_line": 24,
"start_col": 2,
"start_line": 24
} |
Prims.GTot | val mt_flush_to:
#hsz:pos ->
mt:merkle_tree #hsz {mt_wf_elts mt} ->
idx:nat{idx >= MT?.i mt /\ idx < MT?.j mt} ->
GTot (fmt:merkle_tree{mt_wf_elts #hsz fmt}) | [
{
"abbrev": true,
"full_module": "MerkleTree.Spec",
"short_module": "MTS"
},
{
"abbrev": true,
"full_module": "FStar.UInt8",
"short_module": "U8"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "S"
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Ghost",
"short_module": null
},
{
"abbrev": false,
"full_module": "MerkleTree.New",
"short_module": null
},
{
"abbrev": false,
"full_module": "MerkleTree.New",
"short_module": null
},
{
"abbrev": 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 mt_flush_to #hsz mt idx =
let fhs = mt_flush_to_ #hsz 0 (MT?.hs mt) (MT?.i mt) idx (MT?.j mt) in
MT idx (MT?.j mt) fhs (MT?.rhs_ok mt) (MT?.rhs mt) (MT?.mroot mt) (MT?.hash_fun mt) | val mt_flush_to:
#hsz:pos ->
mt:merkle_tree #hsz {mt_wf_elts mt} ->
idx:nat{idx >= MT?.i mt /\ idx < MT?.j mt} ->
GTot (fmt:merkle_tree{mt_wf_elts #hsz fmt})
let mt_flush_to #hsz mt idx = | false | null | false | let fhs = mt_flush_to_ #hsz 0 (MT?.hs mt) (MT?.i mt) idx (MT?.j mt) in
MT idx (MT?.j mt) fhs (MT?.rhs_ok mt) (MT?.rhs mt) (MT?.mroot mt) (MT?.hash_fun mt) | {
"checked_file": "MerkleTree.New.High.fst.checked",
"dependencies": [
"Spec.Hash.Definitions.fst.checked",
"prims.fst.checked",
"MerkleTree.Spec.fst.checked",
"Lib.IntTypes.fsti.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "MerkleTree.New.High.fst"
} | [
"sometrivial"
] | [
"Prims.pos",
"MerkleTree.New.High.merkle_tree",
"MerkleTree.New.High.mt_wf_elts",
"Prims.nat",
"Prims.l_and",
"Prims.b2t",
"Prims.op_GreaterThanOrEqual",
"MerkleTree.New.High.__proj__MT__item__i",
"Prims.op_LessThan",
"MerkleTree.New.High.__proj__MT__item__j",
"MerkleTree.New.High.MT",
"MerkleTree.New.High.__proj__MT__item__rhs_ok",
"MerkleTree.New.High.__proj__MT__item__rhs",
"MerkleTree.New.High.__proj__MT__item__mroot",
"MerkleTree.New.High.__proj__MT__item__hash_fun",
"MerkleTree.New.High.hashess",
"Prims.op_Equality",
"Prims.int",
"FStar.Seq.Base.length",
"MerkleTree.New.High.hashes",
"FStar.Seq.Base.equal",
"FStar.Seq.Base.slice",
"MerkleTree.New.High.__proj__MT__item__hs",
"MerkleTree.New.High.hs_wf_elts",
"MerkleTree.New.High.mt_flush_to_"
] | [] | module MerkleTree.New.High
open FStar.Ghost
open FStar.Seq
module S = FStar.Seq
module U32 = FStar.UInt32
module U8 = FStar.UInt8
module MTS = MerkleTree.Spec
#set-options "--z3rlimit 10 --max_fuel 0 --max_ifuel 0"
type uint32_t = U32.t
type uint8_t = U8.t
type hash (#hsz:pos) = b:Spec.Hash.Definitions.bytes{Seq.length b = hsz}
type hashes (#hsz:pos) = S.seq (hash #hsz)
type hashess (#hsz:pos) = S.seq (hashes #hsz)
noextract
let hash_init (#hsz:pos): hash #hsz =
Seq.create hsz (Lib.IntTypes.u8 0)
val sha256_compress: src1:hash #32 -> src2:hash #32 -> GTot (hash #32)
let sha256_compress = MTS.sha256_compress
/// Facts about sequences
val seq_slice_equal_index:
#a:Type -> s1:S.seq a -> s2:S.seq a ->
i:nat -> j:nat{i <= j && j <= S.length s1 && j <= S.length s2} ->
k:nat{i <= k && k < j} ->
Lemma (requires S.equal (S.slice s1 i j) (S.slice s2 i j))
(ensures S.index s1 k == S.index s2 k)
[SMTPat (S.equal (S.slice s1 i j) (S.slice s2 i j));
SMTPat (S.index s1 k)]
let seq_slice_equal_index #a s1 s2 i j k =
assert (S.index (S.slice s1 i j) (k - i) == S.index (S.slice s2 i j) (k - i))
private val seq_slice_more_equal:
#a:Type -> s1:S.seq a -> s2:S.seq a ->
n:nat -> m:nat{n <= m && m <= S.length s1 && m <= S.length s2} ->
k:nat{n <= k} -> l:nat{k <= l && l <= m} ->
Lemma (requires S.equal (S.slice s1 n m) (S.slice s2 n m))
(ensures S.equal (S.slice s1 k l) (S.slice s2 k l))
[SMTPat (S.equal (S.slice s1 n m) (S.slice s2 n m));
SMTPat (S.equal (S.slice s1 k l) (S.slice s2 k l))]
private let seq_slice_more_equal #a s1 s2 n m k l =
slice_slice s1 n m (k - n) (l - n);
slice_slice s2 n m (k - n) (l - n)
/// Facts about "2"
val remainder_2_not_1_div: n:nat ->
Lemma (requires n % 2 <> 1)
(ensures n / 2 = (n + 1) / 2)
let remainder_2_not_1_div n = ()
val remainder_2_1_div: n:nat ->
Lemma (requires n % 2 = 1)
(ensures n / 2 + 1 = (n + 1) / 2)
let remainder_2_1_div n = ()
/// High-level Merkle tree data structure
noeq type merkle_tree (#hsz:pos) =
| MT: i:nat ->
j:nat{i <= j && j < pow2 32} ->
hs:hashess #hsz {S.length hs = 32} ->
rhs_ok:bool ->
rhs:hashes #hsz {S.length rhs = 32} -> // Rightmost hashes
mroot:hash #hsz ->
hash_fun:MTS.hash_fun_t #hsz ->
merkle_tree #hsz
val mt_not_full (#hsz:pos): merkle_tree #hsz -> GTot bool
let mt_not_full #hsz mt =
MT?.j mt < pow2 32 - 1
val mt_empty (#hsz:pos): merkle_tree #hsz -> GTot bool
let mt_empty #hsz mt =
MT?.j mt = 0
val mt_not_empty (#hsz:pos): merkle_tree #hsz -> GTot bool
let mt_not_empty #hsz mt =
MT?.j mt > 0
/// Well-formedness w.r.t. indices of base hash elements
noextract
val offset_of: i:nat -> Tot nat
let offset_of i =
if i % 2 = 0 then i else i - 1
val hs_wf_elts:
#hsz:pos ->
lv:nat{lv <= 32} ->
hs:hashess #hsz {S.length hs = 32} ->
i:nat -> j:nat{j >= i} ->
GTot Type0 (decreases (32 - lv))
let rec hs_wf_elts #hsz lv hs i j =
if lv = 32 then true
else (let ofs = offset_of i in
S.length (S.index hs lv) == j - ofs /\
hs_wf_elts #hsz (lv + 1) hs (i / 2) (j / 2))
#push-options "--max_fuel 1"
val hs_wf_elts_equal:
#hsz:pos ->
lv:nat{lv <= 32} ->
hs1:hashess #hsz {S.length hs1 = 32} ->
hs2:hashess #hsz {S.length hs2 = 32} ->
i:nat ->
j:nat{j >= i} ->
Lemma (requires hs_wf_elts lv hs1 i j /\
S.equal (S.slice hs1 lv 32) (S.slice hs2 lv 32))
(ensures hs_wf_elts lv hs2 i j)
(decreases (32 - lv))
let rec hs_wf_elts_equal #hsz lv hs1 hs2 i j =
if lv = 32 then ()
else (S.slice_slice hs1 lv 32 1 (32 - lv);
S.slice_slice hs2 lv 32 1 (32 - lv);
assert (S.equal (S.slice hs1 (lv + 1) 32)
(S.slice hs2 (lv + 1) 32));
S.lemma_index_slice hs1 lv 32 0;
S.lemma_index_slice hs2 lv 32 0;
assert (S.index hs1 lv == S.index hs2 lv);
hs_wf_elts_equal (lv + 1) hs1 hs2 (i / 2) (j / 2))
val mt_wf_elts (#hsz:pos): merkle_tree #hsz -> GTot Type0
let mt_wf_elts #_ (MT i j hs _ _ _ _) =
hs_wf_elts 0 hs i j
/// Construction
val hs_wf_elts_empty:
#hsz:pos ->
lv:nat{lv <= 32} ->
Lemma (requires True)
(ensures hs_wf_elts #hsz lv (S.create 32 S.empty) 0 0)
(decreases (32 - lv))
let rec hs_wf_elts_empty #hsz lv =
if lv = 32 then ()
else hs_wf_elts_empty #hsz (lv + 1)
// NOTE: the public function is `create_mt` defined below, which
// builds a tree with an initial hash.
noextract inline_for_extraction
val create_empty_mt (#hsz:pos) (#f:MTS.hash_fun_t #hsz): unit -> GTot (mt:merkle_tree #hsz {mt_wf_elts #hsz mt})
let create_empty_mt #hsz #f _ =
hs_wf_elts_empty #hsz 0;
MT 0 0 (S.create 32 S.empty) false (S.create 32 (hash_init #hsz)) (hash_init #hsz) f
/// Insertion
val hashess_insert:
#hsz:pos ->
lv:nat{lv < 32} ->
i:nat ->
j:nat{i <= j /\ j < pow2 (32 - lv) - 1} ->
hs:hashess #hsz {S.length hs = 32 /\ hs_wf_elts lv hs i j} ->
v:hash #hsz ->
GTot (ihs:hashess #hsz {S.length ihs = 32 /\ hs_wf_elts (lv + 1) ihs (i / 2) (j / 2)})
let hashess_insert #hsz lv i j hs v =
let ihs = S.upd hs lv (S.snoc (S.index hs lv) v) in
hs_wf_elts_equal (lv + 1) hs ihs (i / 2) (j / 2);
ihs
val insert_:
#hsz:pos -> #f:MTS.hash_fun_t #hsz ->
lv:nat{lv < 32} ->
i:nat ->
j:nat{i <= j /\ j < pow2 (32 - lv) - 1} ->
hs:hashess #hsz {S.length hs = 32 /\ hs_wf_elts lv hs i j} ->
acc:hash #hsz ->
GTot (ihs:hashess #hsz {
S.length ihs = 32 /\
hs_wf_elts #hsz lv ihs i (j + 1) /\
S.equal (S.slice hs 0 lv) (S.slice ihs 0 lv)})
(decreases j)
let rec insert_ #hsz #f lv i j hs acc =
let ihs = hashess_insert #hsz lv i j hs acc in
assert (S.equal (S.slice hs 0 lv) (S.slice ihs 0 lv));
if j % 2 = 1 // S.length (S.index hs lv) > 0
then begin
remainder_2_1_div j;
let nacc = f (S.last (S.index hs lv)) acc in
let rihs = insert_ #hsz #f (lv + 1) (i / 2) (j / 2) ihs nacc in
assert (hs_wf_elts #hsz (lv + 1) rihs (i / 2) (j / 2 + 1));
assert (S.equal (S.slice ihs 0 (lv + 1)) (S.slice rihs 0 (lv + 1)));
assert (S.index ihs lv == S.index rihs lv);
assert (S.length (S.index rihs lv) = (j + 1) - offset_of i);
assert (S.equal (S.slice ihs 0 (lv + 1)) (S.slice rihs 0 (lv + 1)));
assert (S.equal (S.slice ihs 0 lv) (S.slice rihs 0 lv));
rihs
end
else ihs
val insert_base:
#hsz:pos -> #f:MTS.hash_fun_t #hsz ->
lv:nat -> i:nat -> j:nat -> hs:hashess #hsz -> acc:hash #hsz ->
Lemma (requires
lv < 32 /\ i <= j /\ j < pow2 (32 - lv) - 1 /\
S.length hs = 32 /\ hs_wf_elts lv hs i j /\
j % 2 <> 1)
(ensures S.equal (insert_ #_ #f lv i j hs acc)
(hashess_insert lv i j hs acc))
let insert_base #_ #_ lv i j hs acc = ()
val insert_rec:
#hsz:pos -> #f:MTS.hash_fun_t #hsz ->
lv:nat -> i:nat -> j:nat -> hs:hashess -> acc:hash ->
Lemma (requires
lv < 32 /\ i <= j /\ j < pow2 (32 - lv) - 1 /\
S.length hs = 32 /\ hs_wf_elts lv hs i j /\
j % 2 == 1)
(ensures
(hs_wf_elts_equal (lv + 1) hs
(hashess_insert lv i j hs acc) (i / 2) (j / 2);
S.equal (insert_ #_ #f lv i j hs acc)
(insert_ #_ #f (lv + 1) (i / 2) (j / 2)
(hashess_insert lv i j hs acc)
(f (S.last (S.index hs lv)) acc))))
let insert_rec #_ #_ lv i j hs acc = ()
val mt_insert:
#hsz:pos ->
mt:merkle_tree #hsz {mt_wf_elts mt /\ mt_not_full mt} -> v:hash #hsz ->
GTot (imt:merkle_tree #hsz{mt_wf_elts #hsz imt})
let mt_insert #hsz mt v =
MT (MT?.i mt)
(MT?.j mt + 1)
(insert_ #_ #(MT?.hash_fun mt) 0 (MT?.i mt) (MT?.j mt) (MT?.hs mt) v)
false
(MT?.rhs mt)
(MT?.mroot mt)
(MT?.hash_fun mt)
val mt_create:
hsz:pos -> f:MTS.hash_fun_t #hsz ->
init:hash #hsz -> GTot (mt:merkle_tree{mt_wf_elts #hsz mt})
let mt_create hsz f init =
mt_insert #_ (create_empty_mt #_ #f ()) init
/// Getting the Merkle root and path
type path (#hsz:pos) = S.seq (hash #hsz)
// Construct the rightmost hashes for a given (incomplete) Merkle tree.
// This function calculates the Merkle root as well, which is the final
// accumulator value.
val construct_rhs:
#hsz:pos -> #f:MTS.hash_fun_t #hsz ->
lv:nat{lv <= 32} ->
hs:hashess #hsz {S.length hs = 32} ->
rhs:hashes #hsz {S.length rhs = 32} ->
i:nat ->
j:nat{
i <= j /\ j < pow2 (32 - lv) /\
hs_wf_elts #hsz lv hs i j} ->
acc:hash #hsz ->
actd:bool ->
GTot (crhs:hashes #hsz {S.length crhs = 32} * (hash #hsz))
(decreases j)
let rec construct_rhs #hsz #f lv hs rhs i j acc actd =
let ofs = offset_of i in
if j = 0 then (rhs, acc)
else
(if j % 2 = 0
then (construct_rhs #_ #f (lv + 1) hs rhs (i / 2) (j / 2) acc actd)
else (let nrhs = if actd then S.upd rhs lv acc else rhs in
let nacc = if actd
then f (S.index (S.index hs lv) (j - 1 - ofs)) acc
else S.index (S.index hs lv) (j - 1 - ofs) in
construct_rhs #_ #f (lv + 1) hs nrhs (i / 2) (j / 2) nacc true))
val construct_rhs_unchanged:
#hsz:pos -> #f:MTS.hash_fun_t #hsz ->
lv:nat{lv <= 32} ->
hs:hashess #hsz {S.length hs = 32} ->
rhs:hashes #hsz {S.length rhs = 32} ->
i:nat ->
j:nat{
i <= j /\ j < pow2 (32 - lv) /\
hs_wf_elts #hsz lv hs i j} ->
acc:hash #hsz ->
actd:bool ->
Lemma (requires True)
(ensures S.equal (S.slice rhs 0 lv)
(S.slice (fst (construct_rhs #_ #f lv hs rhs i j acc actd)) 0 lv))
(decreases j)
let rec construct_rhs_unchanged #hsz #f lv hs rhs i j acc actd =
let ofs = offset_of i in
if j = 0 then ()
else if j % 2 = 0
then (construct_rhs_unchanged #_ #f (lv + 1) hs rhs (i / 2) (j / 2) acc actd;
let rrhs = fst (construct_rhs #_ #f (lv + 1) hs rhs (i / 2) (j / 2) acc actd) in
assert (S.equal (S.slice rhs 0 lv) (S.slice rrhs 0 lv)))
else (let nrhs = if actd then S.upd rhs lv acc else rhs in
let nacc = if actd
then f (S.index (S.index hs lv) (j - 1 - ofs)) acc
else S.index (S.index hs lv) (j - 1 - ofs) in
construct_rhs_unchanged #_ #f (lv + 1) hs nrhs (i / 2) (j / 2) nacc true;
let rrhs = fst (construct_rhs #_ #f (lv + 1) hs nrhs (i / 2) (j / 2) nacc true) in
assert (S.equal (S.slice nrhs 0 lv) (S.slice rrhs 0 lv));
assert (S.equal (S.slice rhs 0 lv) (S.slice nrhs 0 lv)))
val construct_rhs_even:
#hsz:pos -> #f:MTS.hash_fun_t #hsz ->
lv:nat{lv <= 32} ->
hs:hashess #hsz {S.length hs = 32} ->
rhs:hashes #hsz {S.length rhs = 32} ->
i:nat ->
j:nat{
i <= j /\ j < pow2 (32 - lv) /\
hs_wf_elts #hsz lv hs i j} ->
acc:hash #hsz ->
actd:bool ->
Lemma (requires j <> 0 /\ j % 2 = 0)
(ensures construct_rhs #_ #f lv hs rhs i j acc actd ==
construct_rhs #_ #f (lv + 1) hs rhs (i / 2) (j / 2) acc actd)
let construct_rhs_even #_ #_ _ _ _ _ _ _ _ = ()
val construct_rhs_odd:
#hsz:pos -> #f:MTS.hash_fun_t #hsz ->
lv:nat{lv <= 32} ->
hs:hashess #hsz {S.length hs = 32} ->
rhs:hashes #hsz {S.length rhs = 32} ->
i:nat ->
j:nat{
i <= j /\ j < pow2 (32 - lv) /\
hs_wf_elts lv hs i j} ->
acc:hash ->
actd:bool ->
Lemma (requires j % 2 = 1)
(ensures construct_rhs #_ #f lv hs rhs i j acc actd ==
(let ofs = offset_of i in
let nrhs = if actd then S.upd rhs lv acc else rhs in
let nacc = if actd
then f (S.index (S.index hs lv) (j - 1 - ofs)) acc
else S.index (S.index hs lv) (j - 1 - ofs) in
construct_rhs #_ #f (lv + 1) hs nrhs (i / 2) (j / 2) nacc true))
let construct_rhs_odd #_ #_ _ _ _ _ _ _ _ = ()
val mt_get_root:
#hsz:pos ->
mt:merkle_tree #hsz {mt_wf_elts #hsz mt} -> drt:hash #hsz ->
GTot (merkle_tree #hsz * hash #hsz)
let mt_get_root #hsz mt drt =
if MT?.rhs_ok mt then (mt, MT?.mroot mt)
else begin
let (nrhs, rt) = construct_rhs #_ #(MT?.hash_fun mt) 0 (MT?.hs mt) (MT?.rhs mt) (MT?.i mt) (MT?.j mt) drt false in
(MT (MT?.i mt) (MT?.j mt) (MT?.hs mt) true nrhs rt (MT?.hash_fun mt), rt)
end
val mt_get_root_rhs_ok_true:
#hsz:pos ->
mt:merkle_tree #hsz {mt_wf_elts mt} -> drt:hash #hsz ->
Lemma (requires MT?.rhs_ok mt == true)
(ensures mt_get_root #hsz mt drt == (mt, MT?.mroot mt))
let mt_get_root_rhs_ok_true #hsz mt drt = ()
val mt_get_root_rhs_ok_false:
#hsz:pos ->
mt:merkle_tree #hsz {mt_wf_elts mt} -> drt:hash ->
Lemma (requires MT?.rhs_ok mt == false)
(ensures mt_get_root mt drt ==
(let (nrhs, rt) =
construct_rhs #_ #(MT?.hash_fun mt)
0 (MT?.hs mt) (MT?.rhs mt) (MT?.i mt) (MT?.j mt)
drt false in
(MT (MT?.i mt) (MT?.j mt) (MT?.hs mt) true nrhs rt (MT?.hash_fun mt), rt)))
let mt_get_root_rhs_ok_false #_ _ _ = ()
val path_insert: (#hsz:pos) -> p:path #hsz -> hp:hash #hsz -> GTot (path #hsz)
let path_insert #_ p hp = S.snoc p hp
val mt_path_length_step:
k:nat -> j:nat{k <= j} -> actd:bool -> GTot nat
let mt_path_length_step k j actd =
if j = 0 then 0
else (if k % 2 = 0
then (if j = k || (j = k + 1 && not actd) then 0 else 1)
else 1)
val mt_path_length:
k:nat -> j:nat{k <= j} -> actd:bool -> GTot nat
let rec mt_path_length k j actd =
if j = 0 then 0
else (let nactd = actd || (j % 2 = 1) in
mt_path_length_step k j actd +
mt_path_length (k / 2) (j / 2) nactd)
val mt_make_path_step:
#hsz:pos ->
lv:nat{lv <= 32} ->
hs:hashess #hsz {S.length hs = 32} ->
rhs:hashes #hsz {S.length rhs = 32} ->
i:nat ->
j:nat{
j <> 0 /\ i <= j /\ j < pow2 (32 - lv) /\
hs_wf_elts lv hs i j} ->
k:nat{i <= k && k <= j} ->
p:path #hsz ->
actd:bool ->
GTot (path #hsz)
let mt_make_path_step #hsz lv hs rhs i j k p actd =
let ofs = offset_of i in
if k % 2 = 1
then path_insert p (S.index (S.index hs lv) (k - 1 - ofs))
else (if k = j then p
else if k + 1 = j
then (if actd
then path_insert p (S.index rhs lv)
else p)
else path_insert p (S.index (S.index hs lv) (k + 1 - ofs)))
// Construct a Merkle path for a given index `k`, hashes `hs`,
// and rightmost hashes `rhs`.
val mt_get_path_:
#hsz:pos ->
lv:nat{lv <= 32} ->
hs:hashess #hsz {S.length hs = 32} ->
rhs:hashes #hsz {S.length rhs = 32} ->
i:nat ->
j:nat{
i <= j /\ j < pow2 (32 - lv) /\
hs_wf_elts lv hs i j} ->
k:nat{i <= k && k <= j} ->
p:path #hsz ->
actd:bool ->
GTot (np:path #hsz {S.length np = S.length p + mt_path_length k j actd})
(decreases (32 - lv))
let rec mt_get_path_ #hsz lv hs rhs i j k p actd =
let ofs = offset_of i in
if j = 0 then p
else
(let np = mt_make_path_step lv hs rhs i j k p actd in
mt_get_path_ (lv + 1) hs rhs (i / 2) (j / 2) (k / 2) np
(if j % 2 = 0 then actd else true))
val mt_get_path_unchanged:
#hsz:pos ->
lv:nat{lv <= 32} ->
hs:hashess #hsz {S.length hs = 32} ->
rhs:hashes #hsz {S.length rhs = 32} ->
i:nat ->
j:nat{
i <= j /\ j < pow2 (32 - lv) /\
hs_wf_elts #hsz lv hs i j} ->
k:nat{i <= k && k <= j} ->
p:path #hsz ->
actd:bool ->
Lemma (requires True)
(ensures S.equal p (S.slice (mt_get_path_ lv hs rhs i j k p actd)
0 (S.length p)))
(decreases (32 - lv))
let rec mt_get_path_unchanged #hsz lv hs rhs i j k p actd =
let ofs = offset_of i in
if j = 0 then ()
else
(let np = mt_make_path_step lv hs rhs i j k p actd in
assert (S.equal p (S.slice np 0 (S.length p)));
mt_get_path_unchanged (lv + 1) hs rhs (i / 2) (j / 2) (k / 2) np
(if j % 2 = 0 then actd else true))
#push-options "--z3rlimit 20"
val mt_get_path_pull:
#hsz:pos ->
lv:nat{lv <= 32} ->
hs:hashess #hsz {S.length hs = 32} ->
rhs:hashes #hsz {S.length rhs = 32} ->
i:nat ->
j:nat{
i <= j /\ j < pow2 (32 - lv) /\
hs_wf_elts lv hs i j} ->
k:nat{i <= k && k <= j} ->
p:path #hsz ->
actd:bool ->
Lemma (requires True)
(ensures S.equal (mt_get_path_ lv hs rhs i j k p actd)
(S.append p (mt_get_path_ lv hs rhs i j k S.empty actd)))
(decreases (32 - lv))
let rec mt_get_path_pull #hsz lv hs rhs i j k p actd =
let ofs = offset_of i in
if j = 0 then ()
else
(let np = mt_make_path_step lv hs rhs i j k p actd in
let nactd = if j % 2 = 0 then actd else true in
mt_get_path_pull (lv + 1) hs rhs (i / 2) (j / 2) (k / 2) np nactd;
mt_get_path_pull (lv + 1) hs rhs (i / 2) (j / 2) (k / 2)
(mt_make_path_step lv hs rhs i j k S.empty actd) nactd)
#pop-options
val mt_get_path_slice:
#hsz:pos ->
lv:nat{lv <= 32} ->
hs:hashess #hsz {S.length hs = 32} ->
rhs:hashes #hsz {S.length rhs = 32} ->
i:nat ->
j:nat{
i <= j /\ j < pow2 (32 - lv) /\
hs_wf_elts lv hs i j} ->
k:nat{i <= k && k <= j} ->
p:path #hsz ->
actd:bool ->
Lemma (requires True)
(ensures S.equal (S.slice (mt_get_path_ lv hs rhs i j k p actd)
(S.length p) (S.length p + mt_path_length k j actd))
(mt_get_path_ lv hs rhs i j k S.empty actd))
(decreases (32 - lv))
let mt_get_path_slice #hsz lv hs rhs i j k p actd =
mt_get_path_pull lv hs rhs i j k p actd
val mt_get_path:
#hsz:pos ->
mt:merkle_tree #hsz {mt_wf_elts mt} ->
idx:nat{MT?.i mt <= idx /\ idx < MT?.j mt} ->
drt:hash #hsz ->
GTot (nat *
(np:path #hsz {S.length np = 1 + mt_path_length idx (MT?.j mt) false}) *
hash #hsz)
let mt_get_path #hsz mt idx drt =
let (umt, root) = mt_get_root mt drt in
let ofs = offset_of (MT?.i umt) in
let np = path_insert S.empty (S.index (S.index (MT?.hs umt) 0) (idx - ofs)) in
MT?.j umt,
mt_get_path_ 0 (MT?.hs umt) (MT?.rhs umt)
(MT?.i umt) (MT?.j umt) idx np false,
root
/// Flushing
val mt_flush_to_:
#hsz:pos ->
lv:nat{lv < 32} ->
hs:hashess #hsz {S.length hs = 32} ->
pi:nat ->
i:nat{i >= pi} ->
j:nat{
j >= i /\ j < pow2 (32 - lv) /\
hs_wf_elts #hsz lv hs pi j} ->
GTot (fhs:hashess{
S.length fhs = 32 /\
S.equal (S.slice hs 0 lv) (S.slice fhs 0 lv) /\
hs_wf_elts #hsz lv fhs i j})
(decreases i)
let rec mt_flush_to_ #hsz lv hs pi i j =
let oi = offset_of i in
let opi = offset_of pi in
if oi = opi then hs
else (let ofs = oi - opi in
let hvec = S.index hs lv in
let flushed = S.slice hvec ofs (S.length hvec) in
let nhs = S.upd hs lv flushed in
hs_wf_elts_equal (lv + 1) hs nhs (pi / 2) (j / 2);
mt_flush_to_ (lv + 1) nhs (pi / 2) (i / 2) (j / 2))
val mt_flush_to_rec:
#hsz:pos ->
lv:nat{lv < 32} ->
hs:hashess #hsz {S.length hs = 32} ->
pi:nat ->
i:nat{i >= pi} ->
j:nat{
j >= i /\ j < pow2 (32 - lv) /\
hs_wf_elts lv hs pi j} ->
Lemma (requires offset_of i <> offset_of pi)
(ensures mt_flush_to_ lv hs pi i j ==
(let ofs = offset_of i - offset_of pi in
let hvec = S.index hs lv in
let flushed = S.slice hvec ofs (S.length hvec) in
let nhs = S.upd hs lv flushed in
hs_wf_elts_equal (lv + 1) hs nhs (pi / 2) (j / 2);
mt_flush_to_ #hsz (lv + 1) nhs (pi / 2) (i / 2) (j / 2)))
let mt_flush_to_rec #hsz lv hs pi i j = ()
val mt_flush_to:
#hsz:pos ->
mt:merkle_tree #hsz {mt_wf_elts mt} ->
idx:nat{idx >= MT?.i mt /\ idx < MT?.j mt} -> | false | false | MerkleTree.New.High.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 1,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 10,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val mt_flush_to:
#hsz:pos ->
mt:merkle_tree #hsz {mt_wf_elts mt} ->
idx:nat{idx >= MT?.i mt /\ idx < MT?.j mt} ->
GTot (fmt:merkle_tree{mt_wf_elts #hsz fmt}) | [] | MerkleTree.New.High.mt_flush_to | {
"file_name": "src/MerkleTree.New.High.fst",
"git_rev": "3b0f086655c145aa23f58a97259ebf4cf112a4a3",
"git_url": "https://github.com/hacl-star/merkle-tree.git",
"project_name": "merkle-tree"
} |
mt: MerkleTree.New.High.merkle_tree{MerkleTree.New.High.mt_wf_elts mt} ->
idx: Prims.nat{idx >= MT?.i mt /\ idx < MT?.j mt}
-> Prims.GTot (fmt: MerkleTree.New.High.merkle_tree{MerkleTree.New.High.mt_wf_elts fmt}) | {
"end_col": 85,
"end_line": 591,
"start_col": 29,
"start_line": 589
} |
Prims.GTot | val mt_path_length:
k:nat -> j:nat{k <= j} -> actd:bool -> GTot nat | [
{
"abbrev": true,
"full_module": "MerkleTree.Spec",
"short_module": "MTS"
},
{
"abbrev": true,
"full_module": "FStar.UInt8",
"short_module": "U8"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "S"
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Ghost",
"short_module": null
},
{
"abbrev": false,
"full_module": "MerkleTree.New",
"short_module": null
},
{
"abbrev": false,
"full_module": "MerkleTree.New",
"short_module": null
},
{
"abbrev": 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 mt_path_length k j actd =
if j = 0 then 0
else (let nactd = actd || (j % 2 = 1) in
mt_path_length_step k j actd +
mt_path_length (k / 2) (j / 2) nactd) | val mt_path_length:
k:nat -> j:nat{k <= j} -> actd:bool -> GTot nat
let rec mt_path_length k j actd = | false | null | false | if j = 0
then 0
else
(let nactd = actd || (j % 2 = 1) in
mt_path_length_step k j actd + mt_path_length (k / 2) (j / 2) nactd) | {
"checked_file": "MerkleTree.New.High.fst.checked",
"dependencies": [
"Spec.Hash.Definitions.fst.checked",
"prims.fst.checked",
"MerkleTree.Spec.fst.checked",
"Lib.IntTypes.fsti.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "MerkleTree.New.High.fst"
} | [
"sometrivial"
] | [
"Prims.nat",
"Prims.b2t",
"Prims.op_LessThanOrEqual",
"Prims.bool",
"Prims.op_Equality",
"Prims.int",
"Prims.op_Addition",
"MerkleTree.New.High.mt_path_length_step",
"MerkleTree.New.High.mt_path_length",
"Prims.op_Division",
"Prims.op_BarBar",
"Prims.op_Modulus"
] | [] | module MerkleTree.New.High
open FStar.Ghost
open FStar.Seq
module S = FStar.Seq
module U32 = FStar.UInt32
module U8 = FStar.UInt8
module MTS = MerkleTree.Spec
#set-options "--z3rlimit 10 --max_fuel 0 --max_ifuel 0"
type uint32_t = U32.t
type uint8_t = U8.t
type hash (#hsz:pos) = b:Spec.Hash.Definitions.bytes{Seq.length b = hsz}
type hashes (#hsz:pos) = S.seq (hash #hsz)
type hashess (#hsz:pos) = S.seq (hashes #hsz)
noextract
let hash_init (#hsz:pos): hash #hsz =
Seq.create hsz (Lib.IntTypes.u8 0)
val sha256_compress: src1:hash #32 -> src2:hash #32 -> GTot (hash #32)
let sha256_compress = MTS.sha256_compress
/// Facts about sequences
val seq_slice_equal_index:
#a:Type -> s1:S.seq a -> s2:S.seq a ->
i:nat -> j:nat{i <= j && j <= S.length s1 && j <= S.length s2} ->
k:nat{i <= k && k < j} ->
Lemma (requires S.equal (S.slice s1 i j) (S.slice s2 i j))
(ensures S.index s1 k == S.index s2 k)
[SMTPat (S.equal (S.slice s1 i j) (S.slice s2 i j));
SMTPat (S.index s1 k)]
let seq_slice_equal_index #a s1 s2 i j k =
assert (S.index (S.slice s1 i j) (k - i) == S.index (S.slice s2 i j) (k - i))
private val seq_slice_more_equal:
#a:Type -> s1:S.seq a -> s2:S.seq a ->
n:nat -> m:nat{n <= m && m <= S.length s1 && m <= S.length s2} ->
k:nat{n <= k} -> l:nat{k <= l && l <= m} ->
Lemma (requires S.equal (S.slice s1 n m) (S.slice s2 n m))
(ensures S.equal (S.slice s1 k l) (S.slice s2 k l))
[SMTPat (S.equal (S.slice s1 n m) (S.slice s2 n m));
SMTPat (S.equal (S.slice s1 k l) (S.slice s2 k l))]
private let seq_slice_more_equal #a s1 s2 n m k l =
slice_slice s1 n m (k - n) (l - n);
slice_slice s2 n m (k - n) (l - n)
/// Facts about "2"
val remainder_2_not_1_div: n:nat ->
Lemma (requires n % 2 <> 1)
(ensures n / 2 = (n + 1) / 2)
let remainder_2_not_1_div n = ()
val remainder_2_1_div: n:nat ->
Lemma (requires n % 2 = 1)
(ensures n / 2 + 1 = (n + 1) / 2)
let remainder_2_1_div n = ()
/// High-level Merkle tree data structure
noeq type merkle_tree (#hsz:pos) =
| MT: i:nat ->
j:nat{i <= j && j < pow2 32} ->
hs:hashess #hsz {S.length hs = 32} ->
rhs_ok:bool ->
rhs:hashes #hsz {S.length rhs = 32} -> // Rightmost hashes
mroot:hash #hsz ->
hash_fun:MTS.hash_fun_t #hsz ->
merkle_tree #hsz
val mt_not_full (#hsz:pos): merkle_tree #hsz -> GTot bool
let mt_not_full #hsz mt =
MT?.j mt < pow2 32 - 1
val mt_empty (#hsz:pos): merkle_tree #hsz -> GTot bool
let mt_empty #hsz mt =
MT?.j mt = 0
val mt_not_empty (#hsz:pos): merkle_tree #hsz -> GTot bool
let mt_not_empty #hsz mt =
MT?.j mt > 0
/// Well-formedness w.r.t. indices of base hash elements
noextract
val offset_of: i:nat -> Tot nat
let offset_of i =
if i % 2 = 0 then i else i - 1
val hs_wf_elts:
#hsz:pos ->
lv:nat{lv <= 32} ->
hs:hashess #hsz {S.length hs = 32} ->
i:nat -> j:nat{j >= i} ->
GTot Type0 (decreases (32 - lv))
let rec hs_wf_elts #hsz lv hs i j =
if lv = 32 then true
else (let ofs = offset_of i in
S.length (S.index hs lv) == j - ofs /\
hs_wf_elts #hsz (lv + 1) hs (i / 2) (j / 2))
#push-options "--max_fuel 1"
val hs_wf_elts_equal:
#hsz:pos ->
lv:nat{lv <= 32} ->
hs1:hashess #hsz {S.length hs1 = 32} ->
hs2:hashess #hsz {S.length hs2 = 32} ->
i:nat ->
j:nat{j >= i} ->
Lemma (requires hs_wf_elts lv hs1 i j /\
S.equal (S.slice hs1 lv 32) (S.slice hs2 lv 32))
(ensures hs_wf_elts lv hs2 i j)
(decreases (32 - lv))
let rec hs_wf_elts_equal #hsz lv hs1 hs2 i j =
if lv = 32 then ()
else (S.slice_slice hs1 lv 32 1 (32 - lv);
S.slice_slice hs2 lv 32 1 (32 - lv);
assert (S.equal (S.slice hs1 (lv + 1) 32)
(S.slice hs2 (lv + 1) 32));
S.lemma_index_slice hs1 lv 32 0;
S.lemma_index_slice hs2 lv 32 0;
assert (S.index hs1 lv == S.index hs2 lv);
hs_wf_elts_equal (lv + 1) hs1 hs2 (i / 2) (j / 2))
val mt_wf_elts (#hsz:pos): merkle_tree #hsz -> GTot Type0
let mt_wf_elts #_ (MT i j hs _ _ _ _) =
hs_wf_elts 0 hs i j
/// Construction
val hs_wf_elts_empty:
#hsz:pos ->
lv:nat{lv <= 32} ->
Lemma (requires True)
(ensures hs_wf_elts #hsz lv (S.create 32 S.empty) 0 0)
(decreases (32 - lv))
let rec hs_wf_elts_empty #hsz lv =
if lv = 32 then ()
else hs_wf_elts_empty #hsz (lv + 1)
// NOTE: the public function is `create_mt` defined below, which
// builds a tree with an initial hash.
noextract inline_for_extraction
val create_empty_mt (#hsz:pos) (#f:MTS.hash_fun_t #hsz): unit -> GTot (mt:merkle_tree #hsz {mt_wf_elts #hsz mt})
let create_empty_mt #hsz #f _ =
hs_wf_elts_empty #hsz 0;
MT 0 0 (S.create 32 S.empty) false (S.create 32 (hash_init #hsz)) (hash_init #hsz) f
/// Insertion
val hashess_insert:
#hsz:pos ->
lv:nat{lv < 32} ->
i:nat ->
j:nat{i <= j /\ j < pow2 (32 - lv) - 1} ->
hs:hashess #hsz {S.length hs = 32 /\ hs_wf_elts lv hs i j} ->
v:hash #hsz ->
GTot (ihs:hashess #hsz {S.length ihs = 32 /\ hs_wf_elts (lv + 1) ihs (i / 2) (j / 2)})
let hashess_insert #hsz lv i j hs v =
let ihs = S.upd hs lv (S.snoc (S.index hs lv) v) in
hs_wf_elts_equal (lv + 1) hs ihs (i / 2) (j / 2);
ihs
val insert_:
#hsz:pos -> #f:MTS.hash_fun_t #hsz ->
lv:nat{lv < 32} ->
i:nat ->
j:nat{i <= j /\ j < pow2 (32 - lv) - 1} ->
hs:hashess #hsz {S.length hs = 32 /\ hs_wf_elts lv hs i j} ->
acc:hash #hsz ->
GTot (ihs:hashess #hsz {
S.length ihs = 32 /\
hs_wf_elts #hsz lv ihs i (j + 1) /\
S.equal (S.slice hs 0 lv) (S.slice ihs 0 lv)})
(decreases j)
let rec insert_ #hsz #f lv i j hs acc =
let ihs = hashess_insert #hsz lv i j hs acc in
assert (S.equal (S.slice hs 0 lv) (S.slice ihs 0 lv));
if j % 2 = 1 // S.length (S.index hs lv) > 0
then begin
remainder_2_1_div j;
let nacc = f (S.last (S.index hs lv)) acc in
let rihs = insert_ #hsz #f (lv + 1) (i / 2) (j / 2) ihs nacc in
assert (hs_wf_elts #hsz (lv + 1) rihs (i / 2) (j / 2 + 1));
assert (S.equal (S.slice ihs 0 (lv + 1)) (S.slice rihs 0 (lv + 1)));
assert (S.index ihs lv == S.index rihs lv);
assert (S.length (S.index rihs lv) = (j + 1) - offset_of i);
assert (S.equal (S.slice ihs 0 (lv + 1)) (S.slice rihs 0 (lv + 1)));
assert (S.equal (S.slice ihs 0 lv) (S.slice rihs 0 lv));
rihs
end
else ihs
val insert_base:
#hsz:pos -> #f:MTS.hash_fun_t #hsz ->
lv:nat -> i:nat -> j:nat -> hs:hashess #hsz -> acc:hash #hsz ->
Lemma (requires
lv < 32 /\ i <= j /\ j < pow2 (32 - lv) - 1 /\
S.length hs = 32 /\ hs_wf_elts lv hs i j /\
j % 2 <> 1)
(ensures S.equal (insert_ #_ #f lv i j hs acc)
(hashess_insert lv i j hs acc))
let insert_base #_ #_ lv i j hs acc = ()
val insert_rec:
#hsz:pos -> #f:MTS.hash_fun_t #hsz ->
lv:nat -> i:nat -> j:nat -> hs:hashess -> acc:hash ->
Lemma (requires
lv < 32 /\ i <= j /\ j < pow2 (32 - lv) - 1 /\
S.length hs = 32 /\ hs_wf_elts lv hs i j /\
j % 2 == 1)
(ensures
(hs_wf_elts_equal (lv + 1) hs
(hashess_insert lv i j hs acc) (i / 2) (j / 2);
S.equal (insert_ #_ #f lv i j hs acc)
(insert_ #_ #f (lv + 1) (i / 2) (j / 2)
(hashess_insert lv i j hs acc)
(f (S.last (S.index hs lv)) acc))))
let insert_rec #_ #_ lv i j hs acc = ()
val mt_insert:
#hsz:pos ->
mt:merkle_tree #hsz {mt_wf_elts mt /\ mt_not_full mt} -> v:hash #hsz ->
GTot (imt:merkle_tree #hsz{mt_wf_elts #hsz imt})
let mt_insert #hsz mt v =
MT (MT?.i mt)
(MT?.j mt + 1)
(insert_ #_ #(MT?.hash_fun mt) 0 (MT?.i mt) (MT?.j mt) (MT?.hs mt) v)
false
(MT?.rhs mt)
(MT?.mroot mt)
(MT?.hash_fun mt)
val mt_create:
hsz:pos -> f:MTS.hash_fun_t #hsz ->
init:hash #hsz -> GTot (mt:merkle_tree{mt_wf_elts #hsz mt})
let mt_create hsz f init =
mt_insert #_ (create_empty_mt #_ #f ()) init
/// Getting the Merkle root and path
type path (#hsz:pos) = S.seq (hash #hsz)
// Construct the rightmost hashes for a given (incomplete) Merkle tree.
// This function calculates the Merkle root as well, which is the final
// accumulator value.
val construct_rhs:
#hsz:pos -> #f:MTS.hash_fun_t #hsz ->
lv:nat{lv <= 32} ->
hs:hashess #hsz {S.length hs = 32} ->
rhs:hashes #hsz {S.length rhs = 32} ->
i:nat ->
j:nat{
i <= j /\ j < pow2 (32 - lv) /\
hs_wf_elts #hsz lv hs i j} ->
acc:hash #hsz ->
actd:bool ->
GTot (crhs:hashes #hsz {S.length crhs = 32} * (hash #hsz))
(decreases j)
let rec construct_rhs #hsz #f lv hs rhs i j acc actd =
let ofs = offset_of i in
if j = 0 then (rhs, acc)
else
(if j % 2 = 0
then (construct_rhs #_ #f (lv + 1) hs rhs (i / 2) (j / 2) acc actd)
else (let nrhs = if actd then S.upd rhs lv acc else rhs in
let nacc = if actd
then f (S.index (S.index hs lv) (j - 1 - ofs)) acc
else S.index (S.index hs lv) (j - 1 - ofs) in
construct_rhs #_ #f (lv + 1) hs nrhs (i / 2) (j / 2) nacc true))
val construct_rhs_unchanged:
#hsz:pos -> #f:MTS.hash_fun_t #hsz ->
lv:nat{lv <= 32} ->
hs:hashess #hsz {S.length hs = 32} ->
rhs:hashes #hsz {S.length rhs = 32} ->
i:nat ->
j:nat{
i <= j /\ j < pow2 (32 - lv) /\
hs_wf_elts #hsz lv hs i j} ->
acc:hash #hsz ->
actd:bool ->
Lemma (requires True)
(ensures S.equal (S.slice rhs 0 lv)
(S.slice (fst (construct_rhs #_ #f lv hs rhs i j acc actd)) 0 lv))
(decreases j)
let rec construct_rhs_unchanged #hsz #f lv hs rhs i j acc actd =
let ofs = offset_of i in
if j = 0 then ()
else if j % 2 = 0
then (construct_rhs_unchanged #_ #f (lv + 1) hs rhs (i / 2) (j / 2) acc actd;
let rrhs = fst (construct_rhs #_ #f (lv + 1) hs rhs (i / 2) (j / 2) acc actd) in
assert (S.equal (S.slice rhs 0 lv) (S.slice rrhs 0 lv)))
else (let nrhs = if actd then S.upd rhs lv acc else rhs in
let nacc = if actd
then f (S.index (S.index hs lv) (j - 1 - ofs)) acc
else S.index (S.index hs lv) (j - 1 - ofs) in
construct_rhs_unchanged #_ #f (lv + 1) hs nrhs (i / 2) (j / 2) nacc true;
let rrhs = fst (construct_rhs #_ #f (lv + 1) hs nrhs (i / 2) (j / 2) nacc true) in
assert (S.equal (S.slice nrhs 0 lv) (S.slice rrhs 0 lv));
assert (S.equal (S.slice rhs 0 lv) (S.slice nrhs 0 lv)))
val construct_rhs_even:
#hsz:pos -> #f:MTS.hash_fun_t #hsz ->
lv:nat{lv <= 32} ->
hs:hashess #hsz {S.length hs = 32} ->
rhs:hashes #hsz {S.length rhs = 32} ->
i:nat ->
j:nat{
i <= j /\ j < pow2 (32 - lv) /\
hs_wf_elts #hsz lv hs i j} ->
acc:hash #hsz ->
actd:bool ->
Lemma (requires j <> 0 /\ j % 2 = 0)
(ensures construct_rhs #_ #f lv hs rhs i j acc actd ==
construct_rhs #_ #f (lv + 1) hs rhs (i / 2) (j / 2) acc actd)
let construct_rhs_even #_ #_ _ _ _ _ _ _ _ = ()
val construct_rhs_odd:
#hsz:pos -> #f:MTS.hash_fun_t #hsz ->
lv:nat{lv <= 32} ->
hs:hashess #hsz {S.length hs = 32} ->
rhs:hashes #hsz {S.length rhs = 32} ->
i:nat ->
j:nat{
i <= j /\ j < pow2 (32 - lv) /\
hs_wf_elts lv hs i j} ->
acc:hash ->
actd:bool ->
Lemma (requires j % 2 = 1)
(ensures construct_rhs #_ #f lv hs rhs i j acc actd ==
(let ofs = offset_of i in
let nrhs = if actd then S.upd rhs lv acc else rhs in
let nacc = if actd
then f (S.index (S.index hs lv) (j - 1 - ofs)) acc
else S.index (S.index hs lv) (j - 1 - ofs) in
construct_rhs #_ #f (lv + 1) hs nrhs (i / 2) (j / 2) nacc true))
let construct_rhs_odd #_ #_ _ _ _ _ _ _ _ = ()
val mt_get_root:
#hsz:pos ->
mt:merkle_tree #hsz {mt_wf_elts #hsz mt} -> drt:hash #hsz ->
GTot (merkle_tree #hsz * hash #hsz)
let mt_get_root #hsz mt drt =
if MT?.rhs_ok mt then (mt, MT?.mroot mt)
else begin
let (nrhs, rt) = construct_rhs #_ #(MT?.hash_fun mt) 0 (MT?.hs mt) (MT?.rhs mt) (MT?.i mt) (MT?.j mt) drt false in
(MT (MT?.i mt) (MT?.j mt) (MT?.hs mt) true nrhs rt (MT?.hash_fun mt), rt)
end
val mt_get_root_rhs_ok_true:
#hsz:pos ->
mt:merkle_tree #hsz {mt_wf_elts mt} -> drt:hash #hsz ->
Lemma (requires MT?.rhs_ok mt == true)
(ensures mt_get_root #hsz mt drt == (mt, MT?.mroot mt))
let mt_get_root_rhs_ok_true #hsz mt drt = ()
val mt_get_root_rhs_ok_false:
#hsz:pos ->
mt:merkle_tree #hsz {mt_wf_elts mt} -> drt:hash ->
Lemma (requires MT?.rhs_ok mt == false)
(ensures mt_get_root mt drt ==
(let (nrhs, rt) =
construct_rhs #_ #(MT?.hash_fun mt)
0 (MT?.hs mt) (MT?.rhs mt) (MT?.i mt) (MT?.j mt)
drt false in
(MT (MT?.i mt) (MT?.j mt) (MT?.hs mt) true nrhs rt (MT?.hash_fun mt), rt)))
let mt_get_root_rhs_ok_false #_ _ _ = ()
val path_insert: (#hsz:pos) -> p:path #hsz -> hp:hash #hsz -> GTot (path #hsz)
let path_insert #_ p hp = S.snoc p hp
val mt_path_length_step:
k:nat -> j:nat{k <= j} -> actd:bool -> GTot nat
let mt_path_length_step k j actd =
if j = 0 then 0
else (if k % 2 = 0
then (if j = k || (j = k + 1 && not actd) then 0 else 1)
else 1)
val mt_path_length:
k:nat -> j:nat{k <= j} -> actd:bool -> GTot nat | false | false | MerkleTree.New.High.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 1,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 10,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val mt_path_length:
k:nat -> j:nat{k <= j} -> actd:bool -> GTot nat | [
"recursion"
] | MerkleTree.New.High.mt_path_length | {
"file_name": "src/MerkleTree.New.High.fst",
"git_rev": "3b0f086655c145aa23f58a97259ebf4cf112a4a3",
"git_url": "https://github.com/hacl-star/merkle-tree.git",
"project_name": "merkle-tree"
} | k: Prims.nat -> j: Prims.nat{k <= j} -> actd: Prims.bool -> Prims.GTot Prims.nat | {
"end_col": 44,
"end_line": 396,
"start_col": 2,
"start_line": 393
} |
FStar.Pervasives.Lemma | val seq_slice_more_equal:
#a:Type -> s1:S.seq a -> s2:S.seq a ->
n:nat -> m:nat{n <= m && m <= S.length s1 && m <= S.length s2} ->
k:nat{n <= k} -> l:nat{k <= l && l <= m} ->
Lemma (requires S.equal (S.slice s1 n m) (S.slice s2 n m))
(ensures S.equal (S.slice s1 k l) (S.slice s2 k l))
[SMTPat (S.equal (S.slice s1 n m) (S.slice s2 n m));
SMTPat (S.equal (S.slice s1 k l) (S.slice s2 k l))] | [
{
"abbrev": true,
"full_module": "MerkleTree.Spec",
"short_module": "MTS"
},
{
"abbrev": true,
"full_module": "FStar.UInt8",
"short_module": "U8"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "S"
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Ghost",
"short_module": null
},
{
"abbrev": false,
"full_module": "MerkleTree.New",
"short_module": null
},
{
"abbrev": false,
"full_module": "MerkleTree.New",
"short_module": null
},
{
"abbrev": 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 seq_slice_more_equal #a s1 s2 n m k l =
slice_slice s1 n m (k - n) (l - n);
slice_slice s2 n m (k - n) (l - n) | val seq_slice_more_equal:
#a:Type -> s1:S.seq a -> s2:S.seq a ->
n:nat -> m:nat{n <= m && m <= S.length s1 && m <= S.length s2} ->
k:nat{n <= k} -> l:nat{k <= l && l <= m} ->
Lemma (requires S.equal (S.slice s1 n m) (S.slice s2 n m))
(ensures S.equal (S.slice s1 k l) (S.slice s2 k l))
[SMTPat (S.equal (S.slice s1 n m) (S.slice s2 n m));
SMTPat (S.equal (S.slice s1 k l) (S.slice s2 k l))]
let seq_slice_more_equal #a s1 s2 n m k l = | false | null | true | slice_slice s1 n m (k - n) (l - n);
slice_slice s2 n m (k - n) (l - n) | {
"checked_file": "MerkleTree.New.High.fst.checked",
"dependencies": [
"Spec.Hash.Definitions.fst.checked",
"prims.fst.checked",
"MerkleTree.Spec.fst.checked",
"Lib.IntTypes.fsti.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "MerkleTree.New.High.fst"
} | [
"lemma"
] | [
"FStar.Seq.Base.seq",
"Prims.nat",
"Prims.b2t",
"Prims.op_AmpAmp",
"Prims.op_LessThanOrEqual",
"FStar.Seq.Base.length",
"FStar.Seq.Properties.slice_slice",
"Prims.op_Subtraction",
"Prims.unit"
] | [] | module MerkleTree.New.High
open FStar.Ghost
open FStar.Seq
module S = FStar.Seq
module U32 = FStar.UInt32
module U8 = FStar.UInt8
module MTS = MerkleTree.Spec
#set-options "--z3rlimit 10 --max_fuel 0 --max_ifuel 0"
type uint32_t = U32.t
type uint8_t = U8.t
type hash (#hsz:pos) = b:Spec.Hash.Definitions.bytes{Seq.length b = hsz}
type hashes (#hsz:pos) = S.seq (hash #hsz)
type hashess (#hsz:pos) = S.seq (hashes #hsz)
noextract
let hash_init (#hsz:pos): hash #hsz =
Seq.create hsz (Lib.IntTypes.u8 0)
val sha256_compress: src1:hash #32 -> src2:hash #32 -> GTot (hash #32)
let sha256_compress = MTS.sha256_compress
/// Facts about sequences
val seq_slice_equal_index:
#a:Type -> s1:S.seq a -> s2:S.seq a ->
i:nat -> j:nat{i <= j && j <= S.length s1 && j <= S.length s2} ->
k:nat{i <= k && k < j} ->
Lemma (requires S.equal (S.slice s1 i j) (S.slice s2 i j))
(ensures S.index s1 k == S.index s2 k)
[SMTPat (S.equal (S.slice s1 i j) (S.slice s2 i j));
SMTPat (S.index s1 k)]
let seq_slice_equal_index #a s1 s2 i j k =
assert (S.index (S.slice s1 i j) (k - i) == S.index (S.slice s2 i j) (k - i))
private val seq_slice_more_equal:
#a:Type -> s1:S.seq a -> s2:S.seq a ->
n:nat -> m:nat{n <= m && m <= S.length s1 && m <= S.length s2} ->
k:nat{n <= k} -> l:nat{k <= l && l <= m} ->
Lemma (requires S.equal (S.slice s1 n m) (S.slice s2 n m))
(ensures S.equal (S.slice s1 k l) (S.slice s2 k l))
[SMTPat (S.equal (S.slice s1 n m) (S.slice s2 n m));
SMTPat (S.equal (S.slice s1 k l) (S.slice s2 k l))] | false | false | MerkleTree.New.High.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 10,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val seq_slice_more_equal:
#a:Type -> s1:S.seq a -> s2:S.seq a ->
n:nat -> m:nat{n <= m && m <= S.length s1 && m <= S.length s2} ->
k:nat{n <= k} -> l:nat{k <= l && l <= m} ->
Lemma (requires S.equal (S.slice s1 n m) (S.slice s2 n m))
(ensures S.equal (S.slice s1 k l) (S.slice s2 k l))
[SMTPat (S.equal (S.slice s1 n m) (S.slice s2 n m));
SMTPat (S.equal (S.slice s1 k l) (S.slice s2 k l))] | [] | MerkleTree.New.High.seq_slice_more_equal | {
"file_name": "src/MerkleTree.New.High.fst",
"git_rev": "3b0f086655c145aa23f58a97259ebf4cf112a4a3",
"git_url": "https://github.com/hacl-star/merkle-tree.git",
"project_name": "merkle-tree"
} |
s1: FStar.Seq.Base.seq a ->
s2: FStar.Seq.Base.seq a ->
n: Prims.nat ->
m: Prims.nat{n <= m && m <= FStar.Seq.Base.length s1 && m <= FStar.Seq.Base.length s2} ->
k: Prims.nat{n <= k} ->
l: Prims.nat{k <= l && l <= m}
-> FStar.Pervasives.Lemma
(requires FStar.Seq.Base.equal (FStar.Seq.Base.slice s1 n m) (FStar.Seq.Base.slice s2 n m))
(ensures FStar.Seq.Base.equal (FStar.Seq.Base.slice s1 k l) (FStar.Seq.Base.slice s2 k l))
[
SMTPat (FStar.Seq.Base.equal (FStar.Seq.Base.slice s1 n m) (FStar.Seq.Base.slice s2 n m));
SMTPat (FStar.Seq.Base.equal (FStar.Seq.Base.slice s1 k l) (FStar.Seq.Base.slice s2 k l))
] | {
"end_col": 36,
"end_line": 53,
"start_col": 2,
"start_line": 52
} |
FStar.Pervasives.Lemma | val hs_wf_elts_empty:
#hsz:pos ->
lv:nat{lv <= 32} ->
Lemma (requires True)
(ensures hs_wf_elts #hsz lv (S.create 32 S.empty) 0 0)
(decreases (32 - lv)) | [
{
"abbrev": true,
"full_module": "MerkleTree.Spec",
"short_module": "MTS"
},
{
"abbrev": true,
"full_module": "FStar.UInt8",
"short_module": "U8"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "S"
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Ghost",
"short_module": null
},
{
"abbrev": false,
"full_module": "MerkleTree.New",
"short_module": null
},
{
"abbrev": false,
"full_module": "MerkleTree.New",
"short_module": null
},
{
"abbrev": 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 hs_wf_elts_empty #hsz lv =
if lv = 32 then ()
else hs_wf_elts_empty #hsz (lv + 1) | val hs_wf_elts_empty:
#hsz:pos ->
lv:nat{lv <= 32} ->
Lemma (requires True)
(ensures hs_wf_elts #hsz lv (S.create 32 S.empty) 0 0)
(decreases (32 - lv))
let rec hs_wf_elts_empty #hsz lv = | false | null | true | if lv = 32 then () else hs_wf_elts_empty #hsz (lv + 1) | {
"checked_file": "MerkleTree.New.High.fst.checked",
"dependencies": [
"Spec.Hash.Definitions.fst.checked",
"prims.fst.checked",
"MerkleTree.Spec.fst.checked",
"Lib.IntTypes.fsti.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "MerkleTree.New.High.fst"
} | [
"lemma",
""
] | [
"Prims.pos",
"Prims.nat",
"Prims.b2t",
"Prims.op_LessThanOrEqual",
"Prims.op_Equality",
"Prims.int",
"Prims.bool",
"MerkleTree.New.High.hs_wf_elts_empty",
"Prims.op_Addition",
"Prims.unit"
] | [] | module MerkleTree.New.High
open FStar.Ghost
open FStar.Seq
module S = FStar.Seq
module U32 = FStar.UInt32
module U8 = FStar.UInt8
module MTS = MerkleTree.Spec
#set-options "--z3rlimit 10 --max_fuel 0 --max_ifuel 0"
type uint32_t = U32.t
type uint8_t = U8.t
type hash (#hsz:pos) = b:Spec.Hash.Definitions.bytes{Seq.length b = hsz}
type hashes (#hsz:pos) = S.seq (hash #hsz)
type hashess (#hsz:pos) = S.seq (hashes #hsz)
noextract
let hash_init (#hsz:pos): hash #hsz =
Seq.create hsz (Lib.IntTypes.u8 0)
val sha256_compress: src1:hash #32 -> src2:hash #32 -> GTot (hash #32)
let sha256_compress = MTS.sha256_compress
/// Facts about sequences
val seq_slice_equal_index:
#a:Type -> s1:S.seq a -> s2:S.seq a ->
i:nat -> j:nat{i <= j && j <= S.length s1 && j <= S.length s2} ->
k:nat{i <= k && k < j} ->
Lemma (requires S.equal (S.slice s1 i j) (S.slice s2 i j))
(ensures S.index s1 k == S.index s2 k)
[SMTPat (S.equal (S.slice s1 i j) (S.slice s2 i j));
SMTPat (S.index s1 k)]
let seq_slice_equal_index #a s1 s2 i j k =
assert (S.index (S.slice s1 i j) (k - i) == S.index (S.slice s2 i j) (k - i))
private val seq_slice_more_equal:
#a:Type -> s1:S.seq a -> s2:S.seq a ->
n:nat -> m:nat{n <= m && m <= S.length s1 && m <= S.length s2} ->
k:nat{n <= k} -> l:nat{k <= l && l <= m} ->
Lemma (requires S.equal (S.slice s1 n m) (S.slice s2 n m))
(ensures S.equal (S.slice s1 k l) (S.slice s2 k l))
[SMTPat (S.equal (S.slice s1 n m) (S.slice s2 n m));
SMTPat (S.equal (S.slice s1 k l) (S.slice s2 k l))]
private let seq_slice_more_equal #a s1 s2 n m k l =
slice_slice s1 n m (k - n) (l - n);
slice_slice s2 n m (k - n) (l - n)
/// Facts about "2"
val remainder_2_not_1_div: n:nat ->
Lemma (requires n % 2 <> 1)
(ensures n / 2 = (n + 1) / 2)
let remainder_2_not_1_div n = ()
val remainder_2_1_div: n:nat ->
Lemma (requires n % 2 = 1)
(ensures n / 2 + 1 = (n + 1) / 2)
let remainder_2_1_div n = ()
/// High-level Merkle tree data structure
noeq type merkle_tree (#hsz:pos) =
| MT: i:nat ->
j:nat{i <= j && j < pow2 32} ->
hs:hashess #hsz {S.length hs = 32} ->
rhs_ok:bool ->
rhs:hashes #hsz {S.length rhs = 32} -> // Rightmost hashes
mroot:hash #hsz ->
hash_fun:MTS.hash_fun_t #hsz ->
merkle_tree #hsz
val mt_not_full (#hsz:pos): merkle_tree #hsz -> GTot bool
let mt_not_full #hsz mt =
MT?.j mt < pow2 32 - 1
val mt_empty (#hsz:pos): merkle_tree #hsz -> GTot bool
let mt_empty #hsz mt =
MT?.j mt = 0
val mt_not_empty (#hsz:pos): merkle_tree #hsz -> GTot bool
let mt_not_empty #hsz mt =
MT?.j mt > 0
/// Well-formedness w.r.t. indices of base hash elements
noextract
val offset_of: i:nat -> Tot nat
let offset_of i =
if i % 2 = 0 then i else i - 1
val hs_wf_elts:
#hsz:pos ->
lv:nat{lv <= 32} ->
hs:hashess #hsz {S.length hs = 32} ->
i:nat -> j:nat{j >= i} ->
GTot Type0 (decreases (32 - lv))
let rec hs_wf_elts #hsz lv hs i j =
if lv = 32 then true
else (let ofs = offset_of i in
S.length (S.index hs lv) == j - ofs /\
hs_wf_elts #hsz (lv + 1) hs (i / 2) (j / 2))
#push-options "--max_fuel 1"
val hs_wf_elts_equal:
#hsz:pos ->
lv:nat{lv <= 32} ->
hs1:hashess #hsz {S.length hs1 = 32} ->
hs2:hashess #hsz {S.length hs2 = 32} ->
i:nat ->
j:nat{j >= i} ->
Lemma (requires hs_wf_elts lv hs1 i j /\
S.equal (S.slice hs1 lv 32) (S.slice hs2 lv 32))
(ensures hs_wf_elts lv hs2 i j)
(decreases (32 - lv))
let rec hs_wf_elts_equal #hsz lv hs1 hs2 i j =
if lv = 32 then ()
else (S.slice_slice hs1 lv 32 1 (32 - lv);
S.slice_slice hs2 lv 32 1 (32 - lv);
assert (S.equal (S.slice hs1 (lv + 1) 32)
(S.slice hs2 (lv + 1) 32));
S.lemma_index_slice hs1 lv 32 0;
S.lemma_index_slice hs2 lv 32 0;
assert (S.index hs1 lv == S.index hs2 lv);
hs_wf_elts_equal (lv + 1) hs1 hs2 (i / 2) (j / 2))
val mt_wf_elts (#hsz:pos): merkle_tree #hsz -> GTot Type0
let mt_wf_elts #_ (MT i j hs _ _ _ _) =
hs_wf_elts 0 hs i j
/// Construction
val hs_wf_elts_empty:
#hsz:pos ->
lv:nat{lv <= 32} ->
Lemma (requires True)
(ensures hs_wf_elts #hsz lv (S.create 32 S.empty) 0 0)
(decreases (32 - lv)) | false | false | MerkleTree.New.High.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 1,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 10,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val hs_wf_elts_empty:
#hsz:pos ->
lv:nat{lv <= 32} ->
Lemma (requires True)
(ensures hs_wf_elts #hsz lv (S.create 32 S.empty) 0 0)
(decreases (32 - lv)) | [
"recursion"
] | MerkleTree.New.High.hs_wf_elts_empty | {
"file_name": "src/MerkleTree.New.High.fst",
"git_rev": "3b0f086655c145aa23f58a97259ebf4cf112a4a3",
"git_url": "https://github.com/hacl-star/merkle-tree.git",
"project_name": "merkle-tree"
} | lv: Prims.nat{lv <= 32}
-> FStar.Pervasives.Lemma
(ensures MerkleTree.New.High.hs_wf_elts lv (FStar.Seq.Base.create 32 FStar.Seq.Base.empty) 0 0
) (decreases 32 - lv) | {
"end_col": 37,
"end_line": 148,
"start_col": 2,
"start_line": 147
} |
FStar.Pervasives.Lemma | val seq_slice_equal_index:
#a:Type -> s1:S.seq a -> s2:S.seq a ->
i:nat -> j:nat{i <= j && j <= S.length s1 && j <= S.length s2} ->
k:nat{i <= k && k < j} ->
Lemma (requires S.equal (S.slice s1 i j) (S.slice s2 i j))
(ensures S.index s1 k == S.index s2 k)
[SMTPat (S.equal (S.slice s1 i j) (S.slice s2 i j));
SMTPat (S.index s1 k)] | [
{
"abbrev": true,
"full_module": "MerkleTree.Spec",
"short_module": "MTS"
},
{
"abbrev": true,
"full_module": "FStar.UInt8",
"short_module": "U8"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "S"
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Ghost",
"short_module": null
},
{
"abbrev": false,
"full_module": "MerkleTree.New",
"short_module": null
},
{
"abbrev": false,
"full_module": "MerkleTree.New",
"short_module": null
},
{
"abbrev": 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 seq_slice_equal_index #a s1 s2 i j k =
assert (S.index (S.slice s1 i j) (k - i) == S.index (S.slice s2 i j) (k - i)) | val seq_slice_equal_index:
#a:Type -> s1:S.seq a -> s2:S.seq a ->
i:nat -> j:nat{i <= j && j <= S.length s1 && j <= S.length s2} ->
k:nat{i <= k && k < j} ->
Lemma (requires S.equal (S.slice s1 i j) (S.slice s2 i j))
(ensures S.index s1 k == S.index s2 k)
[SMTPat (S.equal (S.slice s1 i j) (S.slice s2 i j));
SMTPat (S.index s1 k)]
let seq_slice_equal_index #a s1 s2 i j k = | false | null | true | assert (S.index (S.slice s1 i j) (k - i) == S.index (S.slice s2 i j) (k - i)) | {
"checked_file": "MerkleTree.New.High.fst.checked",
"dependencies": [
"Spec.Hash.Definitions.fst.checked",
"prims.fst.checked",
"MerkleTree.Spec.fst.checked",
"Lib.IntTypes.fsti.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "MerkleTree.New.High.fst"
} | [
"lemma"
] | [
"FStar.Seq.Base.seq",
"Prims.nat",
"Prims.b2t",
"Prims.op_AmpAmp",
"Prims.op_LessThanOrEqual",
"FStar.Seq.Base.length",
"Prims.op_LessThan",
"Prims._assert",
"Prims.eq2",
"FStar.Seq.Base.index",
"FStar.Seq.Base.slice",
"Prims.op_Subtraction",
"Prims.unit"
] | [] | module MerkleTree.New.High
open FStar.Ghost
open FStar.Seq
module S = FStar.Seq
module U32 = FStar.UInt32
module U8 = FStar.UInt8
module MTS = MerkleTree.Spec
#set-options "--z3rlimit 10 --max_fuel 0 --max_ifuel 0"
type uint32_t = U32.t
type uint8_t = U8.t
type hash (#hsz:pos) = b:Spec.Hash.Definitions.bytes{Seq.length b = hsz}
type hashes (#hsz:pos) = S.seq (hash #hsz)
type hashess (#hsz:pos) = S.seq (hashes #hsz)
noextract
let hash_init (#hsz:pos): hash #hsz =
Seq.create hsz (Lib.IntTypes.u8 0)
val sha256_compress: src1:hash #32 -> src2:hash #32 -> GTot (hash #32)
let sha256_compress = MTS.sha256_compress
/// Facts about sequences
val seq_slice_equal_index:
#a:Type -> s1:S.seq a -> s2:S.seq a ->
i:nat -> j:nat{i <= j && j <= S.length s1 && j <= S.length s2} ->
k:nat{i <= k && k < j} ->
Lemma (requires S.equal (S.slice s1 i j) (S.slice s2 i j))
(ensures S.index s1 k == S.index s2 k)
[SMTPat (S.equal (S.slice s1 i j) (S.slice s2 i j));
SMTPat (S.index s1 k)] | false | false | MerkleTree.New.High.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 10,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val seq_slice_equal_index:
#a:Type -> s1:S.seq a -> s2:S.seq a ->
i:nat -> j:nat{i <= j && j <= S.length s1 && j <= S.length s2} ->
k:nat{i <= k && k < j} ->
Lemma (requires S.equal (S.slice s1 i j) (S.slice s2 i j))
(ensures S.index s1 k == S.index s2 k)
[SMTPat (S.equal (S.slice s1 i j) (S.slice s2 i j));
SMTPat (S.index s1 k)] | [] | MerkleTree.New.High.seq_slice_equal_index | {
"file_name": "src/MerkleTree.New.High.fst",
"git_rev": "3b0f086655c145aa23f58a97259ebf4cf112a4a3",
"git_url": "https://github.com/hacl-star/merkle-tree.git",
"project_name": "merkle-tree"
} |
s1: FStar.Seq.Base.seq a ->
s2: FStar.Seq.Base.seq a ->
i: Prims.nat ->
j: Prims.nat{i <= j && j <= FStar.Seq.Base.length s1 && j <= FStar.Seq.Base.length s2} ->
k: Prims.nat{i <= k && k < j}
-> FStar.Pervasives.Lemma
(requires FStar.Seq.Base.equal (FStar.Seq.Base.slice s1 i j) (FStar.Seq.Base.slice s2 i j))
(ensures FStar.Seq.Base.index s1 k == FStar.Seq.Base.index s2 k)
[
SMTPat (FStar.Seq.Base.equal (FStar.Seq.Base.slice s1 i j) (FStar.Seq.Base.slice s2 i j));
SMTPat (FStar.Seq.Base.index s1 k)
] | {
"end_col": 79,
"end_line": 41,
"start_col": 2,
"start_line": 41
} |
Prims.GTot | val mt_verify_:
#hsz:pos -> #f:MTS.hash_fun_t #hsz ->
k:nat ->
j:nat{k <= j} ->
p:path #hsz ->
ppos:nat ->
acc:hash #hsz ->
actd:bool{ppos + mt_path_length k j actd <= S.length p} ->
GTot (hash #hsz) | [
{
"abbrev": true,
"full_module": "MerkleTree.Spec",
"short_module": "MTS"
},
{
"abbrev": true,
"full_module": "FStar.UInt8",
"short_module": "U8"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "S"
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Ghost",
"short_module": null
},
{
"abbrev": false,
"full_module": "MerkleTree.New",
"short_module": null
},
{
"abbrev": false,
"full_module": "MerkleTree.New",
"short_module": null
},
{
"abbrev": 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 mt_verify_ #hsz #f k j p ppos acc actd =
if j = 0 then acc
else (let nactd = actd || (j % 2 = 1) in
if k % 2 = 0
then (if j = k || (j = k + 1 && not actd)
then mt_verify_ #_ #f (k / 2) (j / 2) p ppos acc nactd
else (let nacc = f acc (S.index p ppos) in
mt_verify_ #_ #f (k / 2) (j / 2) p (ppos + 1) nacc nactd))
else (let nacc = f (S.index p ppos) acc in
mt_verify_ #_ #f (k / 2) (j / 2) p (ppos + 1) nacc nactd)) | val mt_verify_:
#hsz:pos -> #f:MTS.hash_fun_t #hsz ->
k:nat ->
j:nat{k <= j} ->
p:path #hsz ->
ppos:nat ->
acc:hash #hsz ->
actd:bool{ppos + mt_path_length k j actd <= S.length p} ->
GTot (hash #hsz)
let rec mt_verify_ #hsz #f k j p ppos acc actd = | false | null | false | if j = 0
then acc
else
(let nactd = actd || (j % 2 = 1) in
if k % 2 = 0
then
(if j = k || (j = k + 1 && not actd)
then mt_verify_ #_ #f (k / 2) (j / 2) p ppos acc nactd
else
(let nacc = f acc (S.index p ppos) in
mt_verify_ #_ #f (k / 2) (j / 2) p (ppos + 1) nacc nactd))
else
(let nacc = f (S.index p ppos) acc in
mt_verify_ #_ #f (k / 2) (j / 2) p (ppos + 1) nacc nactd)) | {
"checked_file": "MerkleTree.New.High.fst.checked",
"dependencies": [
"Spec.Hash.Definitions.fst.checked",
"prims.fst.checked",
"MerkleTree.Spec.fst.checked",
"Lib.IntTypes.fsti.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "MerkleTree.New.High.fst"
} | [
"sometrivial"
] | [
"Prims.pos",
"MerkleTree.Spec.hash_fun_t",
"Prims.nat",
"Prims.b2t",
"Prims.op_LessThanOrEqual",
"MerkleTree.New.High.path",
"MerkleTree.New.High.hash",
"Prims.bool",
"Prims.op_Addition",
"MerkleTree.New.High.mt_path_length",
"FStar.Seq.Base.length",
"Prims.op_Equality",
"Prims.int",
"Prims.op_Modulus",
"Prims.op_BarBar",
"Prims.op_AmpAmp",
"Prims.op_Negation",
"MerkleTree.New.High.mt_verify_",
"Prims.op_Division",
"MerkleTree.Spec.hash",
"FStar.Seq.Base.index"
] | [] | module MerkleTree.New.High
open FStar.Ghost
open FStar.Seq
module S = FStar.Seq
module U32 = FStar.UInt32
module U8 = FStar.UInt8
module MTS = MerkleTree.Spec
#set-options "--z3rlimit 10 --max_fuel 0 --max_ifuel 0"
type uint32_t = U32.t
type uint8_t = U8.t
type hash (#hsz:pos) = b:Spec.Hash.Definitions.bytes{Seq.length b = hsz}
type hashes (#hsz:pos) = S.seq (hash #hsz)
type hashess (#hsz:pos) = S.seq (hashes #hsz)
noextract
let hash_init (#hsz:pos): hash #hsz =
Seq.create hsz (Lib.IntTypes.u8 0)
val sha256_compress: src1:hash #32 -> src2:hash #32 -> GTot (hash #32)
let sha256_compress = MTS.sha256_compress
/// Facts about sequences
val seq_slice_equal_index:
#a:Type -> s1:S.seq a -> s2:S.seq a ->
i:nat -> j:nat{i <= j && j <= S.length s1 && j <= S.length s2} ->
k:nat{i <= k && k < j} ->
Lemma (requires S.equal (S.slice s1 i j) (S.slice s2 i j))
(ensures S.index s1 k == S.index s2 k)
[SMTPat (S.equal (S.slice s1 i j) (S.slice s2 i j));
SMTPat (S.index s1 k)]
let seq_slice_equal_index #a s1 s2 i j k =
assert (S.index (S.slice s1 i j) (k - i) == S.index (S.slice s2 i j) (k - i))
private val seq_slice_more_equal:
#a:Type -> s1:S.seq a -> s2:S.seq a ->
n:nat -> m:nat{n <= m && m <= S.length s1 && m <= S.length s2} ->
k:nat{n <= k} -> l:nat{k <= l && l <= m} ->
Lemma (requires S.equal (S.slice s1 n m) (S.slice s2 n m))
(ensures S.equal (S.slice s1 k l) (S.slice s2 k l))
[SMTPat (S.equal (S.slice s1 n m) (S.slice s2 n m));
SMTPat (S.equal (S.slice s1 k l) (S.slice s2 k l))]
private let seq_slice_more_equal #a s1 s2 n m k l =
slice_slice s1 n m (k - n) (l - n);
slice_slice s2 n m (k - n) (l - n)
/// Facts about "2"
val remainder_2_not_1_div: n:nat ->
Lemma (requires n % 2 <> 1)
(ensures n / 2 = (n + 1) / 2)
let remainder_2_not_1_div n = ()
val remainder_2_1_div: n:nat ->
Lemma (requires n % 2 = 1)
(ensures n / 2 + 1 = (n + 1) / 2)
let remainder_2_1_div n = ()
/// High-level Merkle tree data structure
noeq type merkle_tree (#hsz:pos) =
| MT: i:nat ->
j:nat{i <= j && j < pow2 32} ->
hs:hashess #hsz {S.length hs = 32} ->
rhs_ok:bool ->
rhs:hashes #hsz {S.length rhs = 32} -> // Rightmost hashes
mroot:hash #hsz ->
hash_fun:MTS.hash_fun_t #hsz ->
merkle_tree #hsz
val mt_not_full (#hsz:pos): merkle_tree #hsz -> GTot bool
let mt_not_full #hsz mt =
MT?.j mt < pow2 32 - 1
val mt_empty (#hsz:pos): merkle_tree #hsz -> GTot bool
let mt_empty #hsz mt =
MT?.j mt = 0
val mt_not_empty (#hsz:pos): merkle_tree #hsz -> GTot bool
let mt_not_empty #hsz mt =
MT?.j mt > 0
/// Well-formedness w.r.t. indices of base hash elements
noextract
val offset_of: i:nat -> Tot nat
let offset_of i =
if i % 2 = 0 then i else i - 1
val hs_wf_elts:
#hsz:pos ->
lv:nat{lv <= 32} ->
hs:hashess #hsz {S.length hs = 32} ->
i:nat -> j:nat{j >= i} ->
GTot Type0 (decreases (32 - lv))
let rec hs_wf_elts #hsz lv hs i j =
if lv = 32 then true
else (let ofs = offset_of i in
S.length (S.index hs lv) == j - ofs /\
hs_wf_elts #hsz (lv + 1) hs (i / 2) (j / 2))
#push-options "--max_fuel 1"
val hs_wf_elts_equal:
#hsz:pos ->
lv:nat{lv <= 32} ->
hs1:hashess #hsz {S.length hs1 = 32} ->
hs2:hashess #hsz {S.length hs2 = 32} ->
i:nat ->
j:nat{j >= i} ->
Lemma (requires hs_wf_elts lv hs1 i j /\
S.equal (S.slice hs1 lv 32) (S.slice hs2 lv 32))
(ensures hs_wf_elts lv hs2 i j)
(decreases (32 - lv))
let rec hs_wf_elts_equal #hsz lv hs1 hs2 i j =
if lv = 32 then ()
else (S.slice_slice hs1 lv 32 1 (32 - lv);
S.slice_slice hs2 lv 32 1 (32 - lv);
assert (S.equal (S.slice hs1 (lv + 1) 32)
(S.slice hs2 (lv + 1) 32));
S.lemma_index_slice hs1 lv 32 0;
S.lemma_index_slice hs2 lv 32 0;
assert (S.index hs1 lv == S.index hs2 lv);
hs_wf_elts_equal (lv + 1) hs1 hs2 (i / 2) (j / 2))
val mt_wf_elts (#hsz:pos): merkle_tree #hsz -> GTot Type0
let mt_wf_elts #_ (MT i j hs _ _ _ _) =
hs_wf_elts 0 hs i j
/// Construction
val hs_wf_elts_empty:
#hsz:pos ->
lv:nat{lv <= 32} ->
Lemma (requires True)
(ensures hs_wf_elts #hsz lv (S.create 32 S.empty) 0 0)
(decreases (32 - lv))
let rec hs_wf_elts_empty #hsz lv =
if lv = 32 then ()
else hs_wf_elts_empty #hsz (lv + 1)
// NOTE: the public function is `create_mt` defined below, which
// builds a tree with an initial hash.
noextract inline_for_extraction
val create_empty_mt (#hsz:pos) (#f:MTS.hash_fun_t #hsz): unit -> GTot (mt:merkle_tree #hsz {mt_wf_elts #hsz mt})
let create_empty_mt #hsz #f _ =
hs_wf_elts_empty #hsz 0;
MT 0 0 (S.create 32 S.empty) false (S.create 32 (hash_init #hsz)) (hash_init #hsz) f
/// Insertion
val hashess_insert:
#hsz:pos ->
lv:nat{lv < 32} ->
i:nat ->
j:nat{i <= j /\ j < pow2 (32 - lv) - 1} ->
hs:hashess #hsz {S.length hs = 32 /\ hs_wf_elts lv hs i j} ->
v:hash #hsz ->
GTot (ihs:hashess #hsz {S.length ihs = 32 /\ hs_wf_elts (lv + 1) ihs (i / 2) (j / 2)})
let hashess_insert #hsz lv i j hs v =
let ihs = S.upd hs lv (S.snoc (S.index hs lv) v) in
hs_wf_elts_equal (lv + 1) hs ihs (i / 2) (j / 2);
ihs
val insert_:
#hsz:pos -> #f:MTS.hash_fun_t #hsz ->
lv:nat{lv < 32} ->
i:nat ->
j:nat{i <= j /\ j < pow2 (32 - lv) - 1} ->
hs:hashess #hsz {S.length hs = 32 /\ hs_wf_elts lv hs i j} ->
acc:hash #hsz ->
GTot (ihs:hashess #hsz {
S.length ihs = 32 /\
hs_wf_elts #hsz lv ihs i (j + 1) /\
S.equal (S.slice hs 0 lv) (S.slice ihs 0 lv)})
(decreases j)
let rec insert_ #hsz #f lv i j hs acc =
let ihs = hashess_insert #hsz lv i j hs acc in
assert (S.equal (S.slice hs 0 lv) (S.slice ihs 0 lv));
if j % 2 = 1 // S.length (S.index hs lv) > 0
then begin
remainder_2_1_div j;
let nacc = f (S.last (S.index hs lv)) acc in
let rihs = insert_ #hsz #f (lv + 1) (i / 2) (j / 2) ihs nacc in
assert (hs_wf_elts #hsz (lv + 1) rihs (i / 2) (j / 2 + 1));
assert (S.equal (S.slice ihs 0 (lv + 1)) (S.slice rihs 0 (lv + 1)));
assert (S.index ihs lv == S.index rihs lv);
assert (S.length (S.index rihs lv) = (j + 1) - offset_of i);
assert (S.equal (S.slice ihs 0 (lv + 1)) (S.slice rihs 0 (lv + 1)));
assert (S.equal (S.slice ihs 0 lv) (S.slice rihs 0 lv));
rihs
end
else ihs
val insert_base:
#hsz:pos -> #f:MTS.hash_fun_t #hsz ->
lv:nat -> i:nat -> j:nat -> hs:hashess #hsz -> acc:hash #hsz ->
Lemma (requires
lv < 32 /\ i <= j /\ j < pow2 (32 - lv) - 1 /\
S.length hs = 32 /\ hs_wf_elts lv hs i j /\
j % 2 <> 1)
(ensures S.equal (insert_ #_ #f lv i j hs acc)
(hashess_insert lv i j hs acc))
let insert_base #_ #_ lv i j hs acc = ()
val insert_rec:
#hsz:pos -> #f:MTS.hash_fun_t #hsz ->
lv:nat -> i:nat -> j:nat -> hs:hashess -> acc:hash ->
Lemma (requires
lv < 32 /\ i <= j /\ j < pow2 (32 - lv) - 1 /\
S.length hs = 32 /\ hs_wf_elts lv hs i j /\
j % 2 == 1)
(ensures
(hs_wf_elts_equal (lv + 1) hs
(hashess_insert lv i j hs acc) (i / 2) (j / 2);
S.equal (insert_ #_ #f lv i j hs acc)
(insert_ #_ #f (lv + 1) (i / 2) (j / 2)
(hashess_insert lv i j hs acc)
(f (S.last (S.index hs lv)) acc))))
let insert_rec #_ #_ lv i j hs acc = ()
val mt_insert:
#hsz:pos ->
mt:merkle_tree #hsz {mt_wf_elts mt /\ mt_not_full mt} -> v:hash #hsz ->
GTot (imt:merkle_tree #hsz{mt_wf_elts #hsz imt})
let mt_insert #hsz mt v =
MT (MT?.i mt)
(MT?.j mt + 1)
(insert_ #_ #(MT?.hash_fun mt) 0 (MT?.i mt) (MT?.j mt) (MT?.hs mt) v)
false
(MT?.rhs mt)
(MT?.mroot mt)
(MT?.hash_fun mt)
val mt_create:
hsz:pos -> f:MTS.hash_fun_t #hsz ->
init:hash #hsz -> GTot (mt:merkle_tree{mt_wf_elts #hsz mt})
let mt_create hsz f init =
mt_insert #_ (create_empty_mt #_ #f ()) init
/// Getting the Merkle root and path
type path (#hsz:pos) = S.seq (hash #hsz)
// Construct the rightmost hashes for a given (incomplete) Merkle tree.
// This function calculates the Merkle root as well, which is the final
// accumulator value.
val construct_rhs:
#hsz:pos -> #f:MTS.hash_fun_t #hsz ->
lv:nat{lv <= 32} ->
hs:hashess #hsz {S.length hs = 32} ->
rhs:hashes #hsz {S.length rhs = 32} ->
i:nat ->
j:nat{
i <= j /\ j < pow2 (32 - lv) /\
hs_wf_elts #hsz lv hs i j} ->
acc:hash #hsz ->
actd:bool ->
GTot (crhs:hashes #hsz {S.length crhs = 32} * (hash #hsz))
(decreases j)
let rec construct_rhs #hsz #f lv hs rhs i j acc actd =
let ofs = offset_of i in
if j = 0 then (rhs, acc)
else
(if j % 2 = 0
then (construct_rhs #_ #f (lv + 1) hs rhs (i / 2) (j / 2) acc actd)
else (let nrhs = if actd then S.upd rhs lv acc else rhs in
let nacc = if actd
then f (S.index (S.index hs lv) (j - 1 - ofs)) acc
else S.index (S.index hs lv) (j - 1 - ofs) in
construct_rhs #_ #f (lv + 1) hs nrhs (i / 2) (j / 2) nacc true))
val construct_rhs_unchanged:
#hsz:pos -> #f:MTS.hash_fun_t #hsz ->
lv:nat{lv <= 32} ->
hs:hashess #hsz {S.length hs = 32} ->
rhs:hashes #hsz {S.length rhs = 32} ->
i:nat ->
j:nat{
i <= j /\ j < pow2 (32 - lv) /\
hs_wf_elts #hsz lv hs i j} ->
acc:hash #hsz ->
actd:bool ->
Lemma (requires True)
(ensures S.equal (S.slice rhs 0 lv)
(S.slice (fst (construct_rhs #_ #f lv hs rhs i j acc actd)) 0 lv))
(decreases j)
let rec construct_rhs_unchanged #hsz #f lv hs rhs i j acc actd =
let ofs = offset_of i in
if j = 0 then ()
else if j % 2 = 0
then (construct_rhs_unchanged #_ #f (lv + 1) hs rhs (i / 2) (j / 2) acc actd;
let rrhs = fst (construct_rhs #_ #f (lv + 1) hs rhs (i / 2) (j / 2) acc actd) in
assert (S.equal (S.slice rhs 0 lv) (S.slice rrhs 0 lv)))
else (let nrhs = if actd then S.upd rhs lv acc else rhs in
let nacc = if actd
then f (S.index (S.index hs lv) (j - 1 - ofs)) acc
else S.index (S.index hs lv) (j - 1 - ofs) in
construct_rhs_unchanged #_ #f (lv + 1) hs nrhs (i / 2) (j / 2) nacc true;
let rrhs = fst (construct_rhs #_ #f (lv + 1) hs nrhs (i / 2) (j / 2) nacc true) in
assert (S.equal (S.slice nrhs 0 lv) (S.slice rrhs 0 lv));
assert (S.equal (S.slice rhs 0 lv) (S.slice nrhs 0 lv)))
val construct_rhs_even:
#hsz:pos -> #f:MTS.hash_fun_t #hsz ->
lv:nat{lv <= 32} ->
hs:hashess #hsz {S.length hs = 32} ->
rhs:hashes #hsz {S.length rhs = 32} ->
i:nat ->
j:nat{
i <= j /\ j < pow2 (32 - lv) /\
hs_wf_elts #hsz lv hs i j} ->
acc:hash #hsz ->
actd:bool ->
Lemma (requires j <> 0 /\ j % 2 = 0)
(ensures construct_rhs #_ #f lv hs rhs i j acc actd ==
construct_rhs #_ #f (lv + 1) hs rhs (i / 2) (j / 2) acc actd)
let construct_rhs_even #_ #_ _ _ _ _ _ _ _ = ()
val construct_rhs_odd:
#hsz:pos -> #f:MTS.hash_fun_t #hsz ->
lv:nat{lv <= 32} ->
hs:hashess #hsz {S.length hs = 32} ->
rhs:hashes #hsz {S.length rhs = 32} ->
i:nat ->
j:nat{
i <= j /\ j < pow2 (32 - lv) /\
hs_wf_elts lv hs i j} ->
acc:hash ->
actd:bool ->
Lemma (requires j % 2 = 1)
(ensures construct_rhs #_ #f lv hs rhs i j acc actd ==
(let ofs = offset_of i in
let nrhs = if actd then S.upd rhs lv acc else rhs in
let nacc = if actd
then f (S.index (S.index hs lv) (j - 1 - ofs)) acc
else S.index (S.index hs lv) (j - 1 - ofs) in
construct_rhs #_ #f (lv + 1) hs nrhs (i / 2) (j / 2) nacc true))
let construct_rhs_odd #_ #_ _ _ _ _ _ _ _ = ()
val mt_get_root:
#hsz:pos ->
mt:merkle_tree #hsz {mt_wf_elts #hsz mt} -> drt:hash #hsz ->
GTot (merkle_tree #hsz * hash #hsz)
let mt_get_root #hsz mt drt =
if MT?.rhs_ok mt then (mt, MT?.mroot mt)
else begin
let (nrhs, rt) = construct_rhs #_ #(MT?.hash_fun mt) 0 (MT?.hs mt) (MT?.rhs mt) (MT?.i mt) (MT?.j mt) drt false in
(MT (MT?.i mt) (MT?.j mt) (MT?.hs mt) true nrhs rt (MT?.hash_fun mt), rt)
end
val mt_get_root_rhs_ok_true:
#hsz:pos ->
mt:merkle_tree #hsz {mt_wf_elts mt} -> drt:hash #hsz ->
Lemma (requires MT?.rhs_ok mt == true)
(ensures mt_get_root #hsz mt drt == (mt, MT?.mroot mt))
let mt_get_root_rhs_ok_true #hsz mt drt = ()
val mt_get_root_rhs_ok_false:
#hsz:pos ->
mt:merkle_tree #hsz {mt_wf_elts mt} -> drt:hash ->
Lemma (requires MT?.rhs_ok mt == false)
(ensures mt_get_root mt drt ==
(let (nrhs, rt) =
construct_rhs #_ #(MT?.hash_fun mt)
0 (MT?.hs mt) (MT?.rhs mt) (MT?.i mt) (MT?.j mt)
drt false in
(MT (MT?.i mt) (MT?.j mt) (MT?.hs mt) true nrhs rt (MT?.hash_fun mt), rt)))
let mt_get_root_rhs_ok_false #_ _ _ = ()
val path_insert: (#hsz:pos) -> p:path #hsz -> hp:hash #hsz -> GTot (path #hsz)
let path_insert #_ p hp = S.snoc p hp
val mt_path_length_step:
k:nat -> j:nat{k <= j} -> actd:bool -> GTot nat
let mt_path_length_step k j actd =
if j = 0 then 0
else (if k % 2 = 0
then (if j = k || (j = k + 1 && not actd) then 0 else 1)
else 1)
val mt_path_length:
k:nat -> j:nat{k <= j} -> actd:bool -> GTot nat
let rec mt_path_length k j actd =
if j = 0 then 0
else (let nactd = actd || (j % 2 = 1) in
mt_path_length_step k j actd +
mt_path_length (k / 2) (j / 2) nactd)
val mt_make_path_step:
#hsz:pos ->
lv:nat{lv <= 32} ->
hs:hashess #hsz {S.length hs = 32} ->
rhs:hashes #hsz {S.length rhs = 32} ->
i:nat ->
j:nat{
j <> 0 /\ i <= j /\ j < pow2 (32 - lv) /\
hs_wf_elts lv hs i j} ->
k:nat{i <= k && k <= j} ->
p:path #hsz ->
actd:bool ->
GTot (path #hsz)
let mt_make_path_step #hsz lv hs rhs i j k p actd =
let ofs = offset_of i in
if k % 2 = 1
then path_insert p (S.index (S.index hs lv) (k - 1 - ofs))
else (if k = j then p
else if k + 1 = j
then (if actd
then path_insert p (S.index rhs lv)
else p)
else path_insert p (S.index (S.index hs lv) (k + 1 - ofs)))
// Construct a Merkle path for a given index `k`, hashes `hs`,
// and rightmost hashes `rhs`.
val mt_get_path_:
#hsz:pos ->
lv:nat{lv <= 32} ->
hs:hashess #hsz {S.length hs = 32} ->
rhs:hashes #hsz {S.length rhs = 32} ->
i:nat ->
j:nat{
i <= j /\ j < pow2 (32 - lv) /\
hs_wf_elts lv hs i j} ->
k:nat{i <= k && k <= j} ->
p:path #hsz ->
actd:bool ->
GTot (np:path #hsz {S.length np = S.length p + mt_path_length k j actd})
(decreases (32 - lv))
let rec mt_get_path_ #hsz lv hs rhs i j k p actd =
let ofs = offset_of i in
if j = 0 then p
else
(let np = mt_make_path_step lv hs rhs i j k p actd in
mt_get_path_ (lv + 1) hs rhs (i / 2) (j / 2) (k / 2) np
(if j % 2 = 0 then actd else true))
val mt_get_path_unchanged:
#hsz:pos ->
lv:nat{lv <= 32} ->
hs:hashess #hsz {S.length hs = 32} ->
rhs:hashes #hsz {S.length rhs = 32} ->
i:nat ->
j:nat{
i <= j /\ j < pow2 (32 - lv) /\
hs_wf_elts #hsz lv hs i j} ->
k:nat{i <= k && k <= j} ->
p:path #hsz ->
actd:bool ->
Lemma (requires True)
(ensures S.equal p (S.slice (mt_get_path_ lv hs rhs i j k p actd)
0 (S.length p)))
(decreases (32 - lv))
let rec mt_get_path_unchanged #hsz lv hs rhs i j k p actd =
let ofs = offset_of i in
if j = 0 then ()
else
(let np = mt_make_path_step lv hs rhs i j k p actd in
assert (S.equal p (S.slice np 0 (S.length p)));
mt_get_path_unchanged (lv + 1) hs rhs (i / 2) (j / 2) (k / 2) np
(if j % 2 = 0 then actd else true))
#push-options "--z3rlimit 20"
val mt_get_path_pull:
#hsz:pos ->
lv:nat{lv <= 32} ->
hs:hashess #hsz {S.length hs = 32} ->
rhs:hashes #hsz {S.length rhs = 32} ->
i:nat ->
j:nat{
i <= j /\ j < pow2 (32 - lv) /\
hs_wf_elts lv hs i j} ->
k:nat{i <= k && k <= j} ->
p:path #hsz ->
actd:bool ->
Lemma (requires True)
(ensures S.equal (mt_get_path_ lv hs rhs i j k p actd)
(S.append p (mt_get_path_ lv hs rhs i j k S.empty actd)))
(decreases (32 - lv))
let rec mt_get_path_pull #hsz lv hs rhs i j k p actd =
let ofs = offset_of i in
if j = 0 then ()
else
(let np = mt_make_path_step lv hs rhs i j k p actd in
let nactd = if j % 2 = 0 then actd else true in
mt_get_path_pull (lv + 1) hs rhs (i / 2) (j / 2) (k / 2) np nactd;
mt_get_path_pull (lv + 1) hs rhs (i / 2) (j / 2) (k / 2)
(mt_make_path_step lv hs rhs i j k S.empty actd) nactd)
#pop-options
val mt_get_path_slice:
#hsz:pos ->
lv:nat{lv <= 32} ->
hs:hashess #hsz {S.length hs = 32} ->
rhs:hashes #hsz {S.length rhs = 32} ->
i:nat ->
j:nat{
i <= j /\ j < pow2 (32 - lv) /\
hs_wf_elts lv hs i j} ->
k:nat{i <= k && k <= j} ->
p:path #hsz ->
actd:bool ->
Lemma (requires True)
(ensures S.equal (S.slice (mt_get_path_ lv hs rhs i j k p actd)
(S.length p) (S.length p + mt_path_length k j actd))
(mt_get_path_ lv hs rhs i j k S.empty actd))
(decreases (32 - lv))
let mt_get_path_slice #hsz lv hs rhs i j k p actd =
mt_get_path_pull lv hs rhs i j k p actd
val mt_get_path:
#hsz:pos ->
mt:merkle_tree #hsz {mt_wf_elts mt} ->
idx:nat{MT?.i mt <= idx /\ idx < MT?.j mt} ->
drt:hash #hsz ->
GTot (nat *
(np:path #hsz {S.length np = 1 + mt_path_length idx (MT?.j mt) false}) *
hash #hsz)
let mt_get_path #hsz mt idx drt =
let (umt, root) = mt_get_root mt drt in
let ofs = offset_of (MT?.i umt) in
let np = path_insert S.empty (S.index (S.index (MT?.hs umt) 0) (idx - ofs)) in
MT?.j umt,
mt_get_path_ 0 (MT?.hs umt) (MT?.rhs umt)
(MT?.i umt) (MT?.j umt) idx np false,
root
/// Flushing
val mt_flush_to_:
#hsz:pos ->
lv:nat{lv < 32} ->
hs:hashess #hsz {S.length hs = 32} ->
pi:nat ->
i:nat{i >= pi} ->
j:nat{
j >= i /\ j < pow2 (32 - lv) /\
hs_wf_elts #hsz lv hs pi j} ->
GTot (fhs:hashess{
S.length fhs = 32 /\
S.equal (S.slice hs 0 lv) (S.slice fhs 0 lv) /\
hs_wf_elts #hsz lv fhs i j})
(decreases i)
let rec mt_flush_to_ #hsz lv hs pi i j =
let oi = offset_of i in
let opi = offset_of pi in
if oi = opi then hs
else (let ofs = oi - opi in
let hvec = S.index hs lv in
let flushed = S.slice hvec ofs (S.length hvec) in
let nhs = S.upd hs lv flushed in
hs_wf_elts_equal (lv + 1) hs nhs (pi / 2) (j / 2);
mt_flush_to_ (lv + 1) nhs (pi / 2) (i / 2) (j / 2))
val mt_flush_to_rec:
#hsz:pos ->
lv:nat{lv < 32} ->
hs:hashess #hsz {S.length hs = 32} ->
pi:nat ->
i:nat{i >= pi} ->
j:nat{
j >= i /\ j < pow2 (32 - lv) /\
hs_wf_elts lv hs pi j} ->
Lemma (requires offset_of i <> offset_of pi)
(ensures mt_flush_to_ lv hs pi i j ==
(let ofs = offset_of i - offset_of pi in
let hvec = S.index hs lv in
let flushed = S.slice hvec ofs (S.length hvec) in
let nhs = S.upd hs lv flushed in
hs_wf_elts_equal (lv + 1) hs nhs (pi / 2) (j / 2);
mt_flush_to_ #hsz (lv + 1) nhs (pi / 2) (i / 2) (j / 2)))
let mt_flush_to_rec #hsz lv hs pi i j = ()
val mt_flush_to:
#hsz:pos ->
mt:merkle_tree #hsz {mt_wf_elts mt} ->
idx:nat{idx >= MT?.i mt /\ idx < MT?.j mt} ->
GTot (fmt:merkle_tree{mt_wf_elts #hsz fmt})
let mt_flush_to #hsz mt idx =
let fhs = mt_flush_to_ #hsz 0 (MT?.hs mt) (MT?.i mt) idx (MT?.j mt) in
MT idx (MT?.j mt) fhs (MT?.rhs_ok mt) (MT?.rhs mt) (MT?.mroot mt) (MT?.hash_fun mt)
val mt_flush:
#hsz:pos ->
mt:merkle_tree #hsz {mt_wf_elts mt /\ MT?.j mt > MT?.i mt} ->
GTot (fmt:merkle_tree{mt_wf_elts #hsz fmt})
let mt_flush #hsz mt =
mt_flush_to mt (MT?.j mt - 1)
#push-options "--max_fuel 2"
/// Retraction
val mt_retract_to_:
#hsz:pos ->
hs:hashess #hsz {S.length hs = 32} ->
lv:nat{lv < S.length hs} ->
i:nat ->
s:nat -> // s is the first index excluded from nhs
j:nat{ i <= s /\ s <= j /\
j < pow2 (S.length hs - lv) /\
hs_wf_elts lv hs i j} ->
GTot (nhs:hashess #hsz {
S.length nhs = S.length hs /\
S.equal (S.slice hs 0 lv) (S.slice nhs 0 lv) /\
hs_wf_elts #hsz lv nhs i s})
(decreases (S.length hs - lv))
let rec mt_retract_to_ #hsz hs lv i s j =
if lv >= S.length hs then hs
else begin
let hvec = S.index hs lv in
let old_len = j - offset_of i in
let new_len = s - offset_of i in
assert (S.length hvec = old_len);
assert (new_len <= old_len);
assert (new_len <= S.length hvec);
let retracted = S.slice hvec 0 new_len in
let nhs = S.upd hs lv retracted in
if lv >= S.length hs - 1 then nhs else
begin
hs_wf_elts_equal (lv + 1) hs nhs (i / 2) (j / 2);
mt_retract_to_ nhs (lv + 1) (i / 2) (s / 2) (j / 2)
end
end
#pop-options
val mt_retract_to:
#hsz:pos ->
mt:merkle_tree #hsz {mt_wf_elts mt} ->
r:nat{MT?.i mt <= r /\ r < MT?.j mt} ->
GTot (rmt:merkle_tree #hsz {mt_wf_elts rmt /\ MT?.i rmt = MT?.i mt /\ MT?.j rmt = r + 1})
let mt_retract_to #hsz mt r =
let nhs = mt_retract_to_ (MT?.hs mt) 0 (MT?.i mt) (r+1) (MT?.j mt) in
MT (MT?.i mt) (r+1) nhs false (MT?.rhs mt) (MT?.mroot mt) (MT?.hash_fun mt)
/// Verification
val mt_verify_:
#hsz:pos -> #f:MTS.hash_fun_t #hsz ->
k:nat ->
j:nat{k <= j} ->
p:path #hsz ->
ppos:nat ->
acc:hash #hsz ->
actd:bool{ppos + mt_path_length k j actd <= S.length p} ->
GTot (hash #hsz) | false | false | MerkleTree.New.High.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 1,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 10,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val mt_verify_:
#hsz:pos -> #f:MTS.hash_fun_t #hsz ->
k:nat ->
j:nat{k <= j} ->
p:path #hsz ->
ppos:nat ->
acc:hash #hsz ->
actd:bool{ppos + mt_path_length k j actd <= S.length p} ->
GTot (hash #hsz) | [
"recursion"
] | MerkleTree.New.High.mt_verify_ | {
"file_name": "src/MerkleTree.New.High.fst",
"git_rev": "3b0f086655c145aa23f58a97259ebf4cf112a4a3",
"git_url": "https://github.com/hacl-star/merkle-tree.git",
"project_name": "merkle-tree"
} |
k: Prims.nat ->
j: Prims.nat{k <= j} ->
p: MerkleTree.New.High.path ->
ppos: Prims.nat ->
acc: MerkleTree.New.High.hash ->
actd: Prims.bool{ppos + MerkleTree.New.High.mt_path_length k j actd <= FStar.Seq.Base.length p}
-> Prims.GTot MerkleTree.New.High.hash | {
"end_col": 63,
"end_line": 668,
"start_col": 2,
"start_line": 660
} |
Prims.GTot | val mt_retract_to:
#hsz:pos ->
mt:merkle_tree #hsz {mt_wf_elts mt} ->
r:nat{MT?.i mt <= r /\ r < MT?.j mt} ->
GTot (rmt:merkle_tree #hsz {mt_wf_elts rmt /\ MT?.i rmt = MT?.i mt /\ MT?.j rmt = r + 1}) | [
{
"abbrev": true,
"full_module": "MerkleTree.Spec",
"short_module": "MTS"
},
{
"abbrev": true,
"full_module": "FStar.UInt8",
"short_module": "U8"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "S"
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Ghost",
"short_module": null
},
{
"abbrev": false,
"full_module": "MerkleTree.New",
"short_module": null
},
{
"abbrev": false,
"full_module": "MerkleTree.New",
"short_module": null
},
{
"abbrev": 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 mt_retract_to #hsz mt r =
let nhs = mt_retract_to_ (MT?.hs mt) 0 (MT?.i mt) (r+1) (MT?.j mt) in
MT (MT?.i mt) (r+1) nhs false (MT?.rhs mt) (MT?.mroot mt) (MT?.hash_fun mt) | val mt_retract_to:
#hsz:pos ->
mt:merkle_tree #hsz {mt_wf_elts mt} ->
r:nat{MT?.i mt <= r /\ r < MT?.j mt} ->
GTot (rmt:merkle_tree #hsz {mt_wf_elts rmt /\ MT?.i rmt = MT?.i mt /\ MT?.j rmt = r + 1})
let mt_retract_to #hsz mt r = | false | null | false | let nhs = mt_retract_to_ (MT?.hs mt) 0 (MT?.i mt) (r + 1) (MT?.j mt) in
MT (MT?.i mt) (r + 1) nhs false (MT?.rhs mt) (MT?.mroot mt) (MT?.hash_fun mt) | {
"checked_file": "MerkleTree.New.High.fst.checked",
"dependencies": [
"Spec.Hash.Definitions.fst.checked",
"prims.fst.checked",
"MerkleTree.Spec.fst.checked",
"Lib.IntTypes.fsti.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "MerkleTree.New.High.fst"
} | [
"sometrivial"
] | [
"Prims.pos",
"MerkleTree.New.High.merkle_tree",
"MerkleTree.New.High.mt_wf_elts",
"Prims.nat",
"Prims.l_and",
"Prims.b2t",
"Prims.op_LessThanOrEqual",
"MerkleTree.New.High.__proj__MT__item__i",
"Prims.op_LessThan",
"MerkleTree.New.High.__proj__MT__item__j",
"MerkleTree.New.High.MT",
"Prims.op_Addition",
"MerkleTree.New.High.__proj__MT__item__rhs",
"MerkleTree.New.High.__proj__MT__item__mroot",
"MerkleTree.New.High.__proj__MT__item__hash_fun",
"MerkleTree.New.High.hashess",
"Prims.op_Equality",
"FStar.Seq.Base.length",
"MerkleTree.New.High.hashes",
"MerkleTree.New.High.__proj__MT__item__hs",
"FStar.Seq.Base.equal",
"FStar.Seq.Base.slice",
"MerkleTree.New.High.hs_wf_elts",
"MerkleTree.New.High.mt_retract_to_",
"Prims.int"
] | [] | module MerkleTree.New.High
open FStar.Ghost
open FStar.Seq
module S = FStar.Seq
module U32 = FStar.UInt32
module U8 = FStar.UInt8
module MTS = MerkleTree.Spec
#set-options "--z3rlimit 10 --max_fuel 0 --max_ifuel 0"
type uint32_t = U32.t
type uint8_t = U8.t
type hash (#hsz:pos) = b:Spec.Hash.Definitions.bytes{Seq.length b = hsz}
type hashes (#hsz:pos) = S.seq (hash #hsz)
type hashess (#hsz:pos) = S.seq (hashes #hsz)
noextract
let hash_init (#hsz:pos): hash #hsz =
Seq.create hsz (Lib.IntTypes.u8 0)
val sha256_compress: src1:hash #32 -> src2:hash #32 -> GTot (hash #32)
let sha256_compress = MTS.sha256_compress
/// Facts about sequences
val seq_slice_equal_index:
#a:Type -> s1:S.seq a -> s2:S.seq a ->
i:nat -> j:nat{i <= j && j <= S.length s1 && j <= S.length s2} ->
k:nat{i <= k && k < j} ->
Lemma (requires S.equal (S.slice s1 i j) (S.slice s2 i j))
(ensures S.index s1 k == S.index s2 k)
[SMTPat (S.equal (S.slice s1 i j) (S.slice s2 i j));
SMTPat (S.index s1 k)]
let seq_slice_equal_index #a s1 s2 i j k =
assert (S.index (S.slice s1 i j) (k - i) == S.index (S.slice s2 i j) (k - i))
private val seq_slice_more_equal:
#a:Type -> s1:S.seq a -> s2:S.seq a ->
n:nat -> m:nat{n <= m && m <= S.length s1 && m <= S.length s2} ->
k:nat{n <= k} -> l:nat{k <= l && l <= m} ->
Lemma (requires S.equal (S.slice s1 n m) (S.slice s2 n m))
(ensures S.equal (S.slice s1 k l) (S.slice s2 k l))
[SMTPat (S.equal (S.slice s1 n m) (S.slice s2 n m));
SMTPat (S.equal (S.slice s1 k l) (S.slice s2 k l))]
private let seq_slice_more_equal #a s1 s2 n m k l =
slice_slice s1 n m (k - n) (l - n);
slice_slice s2 n m (k - n) (l - n)
/// Facts about "2"
val remainder_2_not_1_div: n:nat ->
Lemma (requires n % 2 <> 1)
(ensures n / 2 = (n + 1) / 2)
let remainder_2_not_1_div n = ()
val remainder_2_1_div: n:nat ->
Lemma (requires n % 2 = 1)
(ensures n / 2 + 1 = (n + 1) / 2)
let remainder_2_1_div n = ()
/// High-level Merkle tree data structure
noeq type merkle_tree (#hsz:pos) =
| MT: i:nat ->
j:nat{i <= j && j < pow2 32} ->
hs:hashess #hsz {S.length hs = 32} ->
rhs_ok:bool ->
rhs:hashes #hsz {S.length rhs = 32} -> // Rightmost hashes
mroot:hash #hsz ->
hash_fun:MTS.hash_fun_t #hsz ->
merkle_tree #hsz
val mt_not_full (#hsz:pos): merkle_tree #hsz -> GTot bool
let mt_not_full #hsz mt =
MT?.j mt < pow2 32 - 1
val mt_empty (#hsz:pos): merkle_tree #hsz -> GTot bool
let mt_empty #hsz mt =
MT?.j mt = 0
val mt_not_empty (#hsz:pos): merkle_tree #hsz -> GTot bool
let mt_not_empty #hsz mt =
MT?.j mt > 0
/// Well-formedness w.r.t. indices of base hash elements
noextract
val offset_of: i:nat -> Tot nat
let offset_of i =
if i % 2 = 0 then i else i - 1
val hs_wf_elts:
#hsz:pos ->
lv:nat{lv <= 32} ->
hs:hashess #hsz {S.length hs = 32} ->
i:nat -> j:nat{j >= i} ->
GTot Type0 (decreases (32 - lv))
let rec hs_wf_elts #hsz lv hs i j =
if lv = 32 then true
else (let ofs = offset_of i in
S.length (S.index hs lv) == j - ofs /\
hs_wf_elts #hsz (lv + 1) hs (i / 2) (j / 2))
#push-options "--max_fuel 1"
val hs_wf_elts_equal:
#hsz:pos ->
lv:nat{lv <= 32} ->
hs1:hashess #hsz {S.length hs1 = 32} ->
hs2:hashess #hsz {S.length hs2 = 32} ->
i:nat ->
j:nat{j >= i} ->
Lemma (requires hs_wf_elts lv hs1 i j /\
S.equal (S.slice hs1 lv 32) (S.slice hs2 lv 32))
(ensures hs_wf_elts lv hs2 i j)
(decreases (32 - lv))
let rec hs_wf_elts_equal #hsz lv hs1 hs2 i j =
if lv = 32 then ()
else (S.slice_slice hs1 lv 32 1 (32 - lv);
S.slice_slice hs2 lv 32 1 (32 - lv);
assert (S.equal (S.slice hs1 (lv + 1) 32)
(S.slice hs2 (lv + 1) 32));
S.lemma_index_slice hs1 lv 32 0;
S.lemma_index_slice hs2 lv 32 0;
assert (S.index hs1 lv == S.index hs2 lv);
hs_wf_elts_equal (lv + 1) hs1 hs2 (i / 2) (j / 2))
val mt_wf_elts (#hsz:pos): merkle_tree #hsz -> GTot Type0
let mt_wf_elts #_ (MT i j hs _ _ _ _) =
hs_wf_elts 0 hs i j
/// Construction
val hs_wf_elts_empty:
#hsz:pos ->
lv:nat{lv <= 32} ->
Lemma (requires True)
(ensures hs_wf_elts #hsz lv (S.create 32 S.empty) 0 0)
(decreases (32 - lv))
let rec hs_wf_elts_empty #hsz lv =
if lv = 32 then ()
else hs_wf_elts_empty #hsz (lv + 1)
// NOTE: the public function is `create_mt` defined below, which
// builds a tree with an initial hash.
noextract inline_for_extraction
val create_empty_mt (#hsz:pos) (#f:MTS.hash_fun_t #hsz): unit -> GTot (mt:merkle_tree #hsz {mt_wf_elts #hsz mt})
let create_empty_mt #hsz #f _ =
hs_wf_elts_empty #hsz 0;
MT 0 0 (S.create 32 S.empty) false (S.create 32 (hash_init #hsz)) (hash_init #hsz) f
/// Insertion
val hashess_insert:
#hsz:pos ->
lv:nat{lv < 32} ->
i:nat ->
j:nat{i <= j /\ j < pow2 (32 - lv) - 1} ->
hs:hashess #hsz {S.length hs = 32 /\ hs_wf_elts lv hs i j} ->
v:hash #hsz ->
GTot (ihs:hashess #hsz {S.length ihs = 32 /\ hs_wf_elts (lv + 1) ihs (i / 2) (j / 2)})
let hashess_insert #hsz lv i j hs v =
let ihs = S.upd hs lv (S.snoc (S.index hs lv) v) in
hs_wf_elts_equal (lv + 1) hs ihs (i / 2) (j / 2);
ihs
val insert_:
#hsz:pos -> #f:MTS.hash_fun_t #hsz ->
lv:nat{lv < 32} ->
i:nat ->
j:nat{i <= j /\ j < pow2 (32 - lv) - 1} ->
hs:hashess #hsz {S.length hs = 32 /\ hs_wf_elts lv hs i j} ->
acc:hash #hsz ->
GTot (ihs:hashess #hsz {
S.length ihs = 32 /\
hs_wf_elts #hsz lv ihs i (j + 1) /\
S.equal (S.slice hs 0 lv) (S.slice ihs 0 lv)})
(decreases j)
let rec insert_ #hsz #f lv i j hs acc =
let ihs = hashess_insert #hsz lv i j hs acc in
assert (S.equal (S.slice hs 0 lv) (S.slice ihs 0 lv));
if j % 2 = 1 // S.length (S.index hs lv) > 0
then begin
remainder_2_1_div j;
let nacc = f (S.last (S.index hs lv)) acc in
let rihs = insert_ #hsz #f (lv + 1) (i / 2) (j / 2) ihs nacc in
assert (hs_wf_elts #hsz (lv + 1) rihs (i / 2) (j / 2 + 1));
assert (S.equal (S.slice ihs 0 (lv + 1)) (S.slice rihs 0 (lv + 1)));
assert (S.index ihs lv == S.index rihs lv);
assert (S.length (S.index rihs lv) = (j + 1) - offset_of i);
assert (S.equal (S.slice ihs 0 (lv + 1)) (S.slice rihs 0 (lv + 1)));
assert (S.equal (S.slice ihs 0 lv) (S.slice rihs 0 lv));
rihs
end
else ihs
val insert_base:
#hsz:pos -> #f:MTS.hash_fun_t #hsz ->
lv:nat -> i:nat -> j:nat -> hs:hashess #hsz -> acc:hash #hsz ->
Lemma (requires
lv < 32 /\ i <= j /\ j < pow2 (32 - lv) - 1 /\
S.length hs = 32 /\ hs_wf_elts lv hs i j /\
j % 2 <> 1)
(ensures S.equal (insert_ #_ #f lv i j hs acc)
(hashess_insert lv i j hs acc))
let insert_base #_ #_ lv i j hs acc = ()
val insert_rec:
#hsz:pos -> #f:MTS.hash_fun_t #hsz ->
lv:nat -> i:nat -> j:nat -> hs:hashess -> acc:hash ->
Lemma (requires
lv < 32 /\ i <= j /\ j < pow2 (32 - lv) - 1 /\
S.length hs = 32 /\ hs_wf_elts lv hs i j /\
j % 2 == 1)
(ensures
(hs_wf_elts_equal (lv + 1) hs
(hashess_insert lv i j hs acc) (i / 2) (j / 2);
S.equal (insert_ #_ #f lv i j hs acc)
(insert_ #_ #f (lv + 1) (i / 2) (j / 2)
(hashess_insert lv i j hs acc)
(f (S.last (S.index hs lv)) acc))))
let insert_rec #_ #_ lv i j hs acc = ()
val mt_insert:
#hsz:pos ->
mt:merkle_tree #hsz {mt_wf_elts mt /\ mt_not_full mt} -> v:hash #hsz ->
GTot (imt:merkle_tree #hsz{mt_wf_elts #hsz imt})
let mt_insert #hsz mt v =
MT (MT?.i mt)
(MT?.j mt + 1)
(insert_ #_ #(MT?.hash_fun mt) 0 (MT?.i mt) (MT?.j mt) (MT?.hs mt) v)
false
(MT?.rhs mt)
(MT?.mroot mt)
(MT?.hash_fun mt)
val mt_create:
hsz:pos -> f:MTS.hash_fun_t #hsz ->
init:hash #hsz -> GTot (mt:merkle_tree{mt_wf_elts #hsz mt})
let mt_create hsz f init =
mt_insert #_ (create_empty_mt #_ #f ()) init
/// Getting the Merkle root and path
type path (#hsz:pos) = S.seq (hash #hsz)
// Construct the rightmost hashes for a given (incomplete) Merkle tree.
// This function calculates the Merkle root as well, which is the final
// accumulator value.
val construct_rhs:
#hsz:pos -> #f:MTS.hash_fun_t #hsz ->
lv:nat{lv <= 32} ->
hs:hashess #hsz {S.length hs = 32} ->
rhs:hashes #hsz {S.length rhs = 32} ->
i:nat ->
j:nat{
i <= j /\ j < pow2 (32 - lv) /\
hs_wf_elts #hsz lv hs i j} ->
acc:hash #hsz ->
actd:bool ->
GTot (crhs:hashes #hsz {S.length crhs = 32} * (hash #hsz))
(decreases j)
let rec construct_rhs #hsz #f lv hs rhs i j acc actd =
let ofs = offset_of i in
if j = 0 then (rhs, acc)
else
(if j % 2 = 0
then (construct_rhs #_ #f (lv + 1) hs rhs (i / 2) (j / 2) acc actd)
else (let nrhs = if actd then S.upd rhs lv acc else rhs in
let nacc = if actd
then f (S.index (S.index hs lv) (j - 1 - ofs)) acc
else S.index (S.index hs lv) (j - 1 - ofs) in
construct_rhs #_ #f (lv + 1) hs nrhs (i / 2) (j / 2) nacc true))
val construct_rhs_unchanged:
#hsz:pos -> #f:MTS.hash_fun_t #hsz ->
lv:nat{lv <= 32} ->
hs:hashess #hsz {S.length hs = 32} ->
rhs:hashes #hsz {S.length rhs = 32} ->
i:nat ->
j:nat{
i <= j /\ j < pow2 (32 - lv) /\
hs_wf_elts #hsz lv hs i j} ->
acc:hash #hsz ->
actd:bool ->
Lemma (requires True)
(ensures S.equal (S.slice rhs 0 lv)
(S.slice (fst (construct_rhs #_ #f lv hs rhs i j acc actd)) 0 lv))
(decreases j)
let rec construct_rhs_unchanged #hsz #f lv hs rhs i j acc actd =
let ofs = offset_of i in
if j = 0 then ()
else if j % 2 = 0
then (construct_rhs_unchanged #_ #f (lv + 1) hs rhs (i / 2) (j / 2) acc actd;
let rrhs = fst (construct_rhs #_ #f (lv + 1) hs rhs (i / 2) (j / 2) acc actd) in
assert (S.equal (S.slice rhs 0 lv) (S.slice rrhs 0 lv)))
else (let nrhs = if actd then S.upd rhs lv acc else rhs in
let nacc = if actd
then f (S.index (S.index hs lv) (j - 1 - ofs)) acc
else S.index (S.index hs lv) (j - 1 - ofs) in
construct_rhs_unchanged #_ #f (lv + 1) hs nrhs (i / 2) (j / 2) nacc true;
let rrhs = fst (construct_rhs #_ #f (lv + 1) hs nrhs (i / 2) (j / 2) nacc true) in
assert (S.equal (S.slice nrhs 0 lv) (S.slice rrhs 0 lv));
assert (S.equal (S.slice rhs 0 lv) (S.slice nrhs 0 lv)))
val construct_rhs_even:
#hsz:pos -> #f:MTS.hash_fun_t #hsz ->
lv:nat{lv <= 32} ->
hs:hashess #hsz {S.length hs = 32} ->
rhs:hashes #hsz {S.length rhs = 32} ->
i:nat ->
j:nat{
i <= j /\ j < pow2 (32 - lv) /\
hs_wf_elts #hsz lv hs i j} ->
acc:hash #hsz ->
actd:bool ->
Lemma (requires j <> 0 /\ j % 2 = 0)
(ensures construct_rhs #_ #f lv hs rhs i j acc actd ==
construct_rhs #_ #f (lv + 1) hs rhs (i / 2) (j / 2) acc actd)
let construct_rhs_even #_ #_ _ _ _ _ _ _ _ = ()
val construct_rhs_odd:
#hsz:pos -> #f:MTS.hash_fun_t #hsz ->
lv:nat{lv <= 32} ->
hs:hashess #hsz {S.length hs = 32} ->
rhs:hashes #hsz {S.length rhs = 32} ->
i:nat ->
j:nat{
i <= j /\ j < pow2 (32 - lv) /\
hs_wf_elts lv hs i j} ->
acc:hash ->
actd:bool ->
Lemma (requires j % 2 = 1)
(ensures construct_rhs #_ #f lv hs rhs i j acc actd ==
(let ofs = offset_of i in
let nrhs = if actd then S.upd rhs lv acc else rhs in
let nacc = if actd
then f (S.index (S.index hs lv) (j - 1 - ofs)) acc
else S.index (S.index hs lv) (j - 1 - ofs) in
construct_rhs #_ #f (lv + 1) hs nrhs (i / 2) (j / 2) nacc true))
let construct_rhs_odd #_ #_ _ _ _ _ _ _ _ = ()
val mt_get_root:
#hsz:pos ->
mt:merkle_tree #hsz {mt_wf_elts #hsz mt} -> drt:hash #hsz ->
GTot (merkle_tree #hsz * hash #hsz)
let mt_get_root #hsz mt drt =
if MT?.rhs_ok mt then (mt, MT?.mroot mt)
else begin
let (nrhs, rt) = construct_rhs #_ #(MT?.hash_fun mt) 0 (MT?.hs mt) (MT?.rhs mt) (MT?.i mt) (MT?.j mt) drt false in
(MT (MT?.i mt) (MT?.j mt) (MT?.hs mt) true nrhs rt (MT?.hash_fun mt), rt)
end
val mt_get_root_rhs_ok_true:
#hsz:pos ->
mt:merkle_tree #hsz {mt_wf_elts mt} -> drt:hash #hsz ->
Lemma (requires MT?.rhs_ok mt == true)
(ensures mt_get_root #hsz mt drt == (mt, MT?.mroot mt))
let mt_get_root_rhs_ok_true #hsz mt drt = ()
val mt_get_root_rhs_ok_false:
#hsz:pos ->
mt:merkle_tree #hsz {mt_wf_elts mt} -> drt:hash ->
Lemma (requires MT?.rhs_ok mt == false)
(ensures mt_get_root mt drt ==
(let (nrhs, rt) =
construct_rhs #_ #(MT?.hash_fun mt)
0 (MT?.hs mt) (MT?.rhs mt) (MT?.i mt) (MT?.j mt)
drt false in
(MT (MT?.i mt) (MT?.j mt) (MT?.hs mt) true nrhs rt (MT?.hash_fun mt), rt)))
let mt_get_root_rhs_ok_false #_ _ _ = ()
val path_insert: (#hsz:pos) -> p:path #hsz -> hp:hash #hsz -> GTot (path #hsz)
let path_insert #_ p hp = S.snoc p hp
val mt_path_length_step:
k:nat -> j:nat{k <= j} -> actd:bool -> GTot nat
let mt_path_length_step k j actd =
if j = 0 then 0
else (if k % 2 = 0
then (if j = k || (j = k + 1 && not actd) then 0 else 1)
else 1)
val mt_path_length:
k:nat -> j:nat{k <= j} -> actd:bool -> GTot nat
let rec mt_path_length k j actd =
if j = 0 then 0
else (let nactd = actd || (j % 2 = 1) in
mt_path_length_step k j actd +
mt_path_length (k / 2) (j / 2) nactd)
val mt_make_path_step:
#hsz:pos ->
lv:nat{lv <= 32} ->
hs:hashess #hsz {S.length hs = 32} ->
rhs:hashes #hsz {S.length rhs = 32} ->
i:nat ->
j:nat{
j <> 0 /\ i <= j /\ j < pow2 (32 - lv) /\
hs_wf_elts lv hs i j} ->
k:nat{i <= k && k <= j} ->
p:path #hsz ->
actd:bool ->
GTot (path #hsz)
let mt_make_path_step #hsz lv hs rhs i j k p actd =
let ofs = offset_of i in
if k % 2 = 1
then path_insert p (S.index (S.index hs lv) (k - 1 - ofs))
else (if k = j then p
else if k + 1 = j
then (if actd
then path_insert p (S.index rhs lv)
else p)
else path_insert p (S.index (S.index hs lv) (k + 1 - ofs)))
// Construct a Merkle path for a given index `k`, hashes `hs`,
// and rightmost hashes `rhs`.
val mt_get_path_:
#hsz:pos ->
lv:nat{lv <= 32} ->
hs:hashess #hsz {S.length hs = 32} ->
rhs:hashes #hsz {S.length rhs = 32} ->
i:nat ->
j:nat{
i <= j /\ j < pow2 (32 - lv) /\
hs_wf_elts lv hs i j} ->
k:nat{i <= k && k <= j} ->
p:path #hsz ->
actd:bool ->
GTot (np:path #hsz {S.length np = S.length p + mt_path_length k j actd})
(decreases (32 - lv))
let rec mt_get_path_ #hsz lv hs rhs i j k p actd =
let ofs = offset_of i in
if j = 0 then p
else
(let np = mt_make_path_step lv hs rhs i j k p actd in
mt_get_path_ (lv + 1) hs rhs (i / 2) (j / 2) (k / 2) np
(if j % 2 = 0 then actd else true))
val mt_get_path_unchanged:
#hsz:pos ->
lv:nat{lv <= 32} ->
hs:hashess #hsz {S.length hs = 32} ->
rhs:hashes #hsz {S.length rhs = 32} ->
i:nat ->
j:nat{
i <= j /\ j < pow2 (32 - lv) /\
hs_wf_elts #hsz lv hs i j} ->
k:nat{i <= k && k <= j} ->
p:path #hsz ->
actd:bool ->
Lemma (requires True)
(ensures S.equal p (S.slice (mt_get_path_ lv hs rhs i j k p actd)
0 (S.length p)))
(decreases (32 - lv))
let rec mt_get_path_unchanged #hsz lv hs rhs i j k p actd =
let ofs = offset_of i in
if j = 0 then ()
else
(let np = mt_make_path_step lv hs rhs i j k p actd in
assert (S.equal p (S.slice np 0 (S.length p)));
mt_get_path_unchanged (lv + 1) hs rhs (i / 2) (j / 2) (k / 2) np
(if j % 2 = 0 then actd else true))
#push-options "--z3rlimit 20"
val mt_get_path_pull:
#hsz:pos ->
lv:nat{lv <= 32} ->
hs:hashess #hsz {S.length hs = 32} ->
rhs:hashes #hsz {S.length rhs = 32} ->
i:nat ->
j:nat{
i <= j /\ j < pow2 (32 - lv) /\
hs_wf_elts lv hs i j} ->
k:nat{i <= k && k <= j} ->
p:path #hsz ->
actd:bool ->
Lemma (requires True)
(ensures S.equal (mt_get_path_ lv hs rhs i j k p actd)
(S.append p (mt_get_path_ lv hs rhs i j k S.empty actd)))
(decreases (32 - lv))
let rec mt_get_path_pull #hsz lv hs rhs i j k p actd =
let ofs = offset_of i in
if j = 0 then ()
else
(let np = mt_make_path_step lv hs rhs i j k p actd in
let nactd = if j % 2 = 0 then actd else true in
mt_get_path_pull (lv + 1) hs rhs (i / 2) (j / 2) (k / 2) np nactd;
mt_get_path_pull (lv + 1) hs rhs (i / 2) (j / 2) (k / 2)
(mt_make_path_step lv hs rhs i j k S.empty actd) nactd)
#pop-options
val mt_get_path_slice:
#hsz:pos ->
lv:nat{lv <= 32} ->
hs:hashess #hsz {S.length hs = 32} ->
rhs:hashes #hsz {S.length rhs = 32} ->
i:nat ->
j:nat{
i <= j /\ j < pow2 (32 - lv) /\
hs_wf_elts lv hs i j} ->
k:nat{i <= k && k <= j} ->
p:path #hsz ->
actd:bool ->
Lemma (requires True)
(ensures S.equal (S.slice (mt_get_path_ lv hs rhs i j k p actd)
(S.length p) (S.length p + mt_path_length k j actd))
(mt_get_path_ lv hs rhs i j k S.empty actd))
(decreases (32 - lv))
let mt_get_path_slice #hsz lv hs rhs i j k p actd =
mt_get_path_pull lv hs rhs i j k p actd
val mt_get_path:
#hsz:pos ->
mt:merkle_tree #hsz {mt_wf_elts mt} ->
idx:nat{MT?.i mt <= idx /\ idx < MT?.j mt} ->
drt:hash #hsz ->
GTot (nat *
(np:path #hsz {S.length np = 1 + mt_path_length idx (MT?.j mt) false}) *
hash #hsz)
let mt_get_path #hsz mt idx drt =
let (umt, root) = mt_get_root mt drt in
let ofs = offset_of (MT?.i umt) in
let np = path_insert S.empty (S.index (S.index (MT?.hs umt) 0) (idx - ofs)) in
MT?.j umt,
mt_get_path_ 0 (MT?.hs umt) (MT?.rhs umt)
(MT?.i umt) (MT?.j umt) idx np false,
root
/// Flushing
val mt_flush_to_:
#hsz:pos ->
lv:nat{lv < 32} ->
hs:hashess #hsz {S.length hs = 32} ->
pi:nat ->
i:nat{i >= pi} ->
j:nat{
j >= i /\ j < pow2 (32 - lv) /\
hs_wf_elts #hsz lv hs pi j} ->
GTot (fhs:hashess{
S.length fhs = 32 /\
S.equal (S.slice hs 0 lv) (S.slice fhs 0 lv) /\
hs_wf_elts #hsz lv fhs i j})
(decreases i)
let rec mt_flush_to_ #hsz lv hs pi i j =
let oi = offset_of i in
let opi = offset_of pi in
if oi = opi then hs
else (let ofs = oi - opi in
let hvec = S.index hs lv in
let flushed = S.slice hvec ofs (S.length hvec) in
let nhs = S.upd hs lv flushed in
hs_wf_elts_equal (lv + 1) hs nhs (pi / 2) (j / 2);
mt_flush_to_ (lv + 1) nhs (pi / 2) (i / 2) (j / 2))
val mt_flush_to_rec:
#hsz:pos ->
lv:nat{lv < 32} ->
hs:hashess #hsz {S.length hs = 32} ->
pi:nat ->
i:nat{i >= pi} ->
j:nat{
j >= i /\ j < pow2 (32 - lv) /\
hs_wf_elts lv hs pi j} ->
Lemma (requires offset_of i <> offset_of pi)
(ensures mt_flush_to_ lv hs pi i j ==
(let ofs = offset_of i - offset_of pi in
let hvec = S.index hs lv in
let flushed = S.slice hvec ofs (S.length hvec) in
let nhs = S.upd hs lv flushed in
hs_wf_elts_equal (lv + 1) hs nhs (pi / 2) (j / 2);
mt_flush_to_ #hsz (lv + 1) nhs (pi / 2) (i / 2) (j / 2)))
let mt_flush_to_rec #hsz lv hs pi i j = ()
val mt_flush_to:
#hsz:pos ->
mt:merkle_tree #hsz {mt_wf_elts mt} ->
idx:nat{idx >= MT?.i mt /\ idx < MT?.j mt} ->
GTot (fmt:merkle_tree{mt_wf_elts #hsz fmt})
let mt_flush_to #hsz mt idx =
let fhs = mt_flush_to_ #hsz 0 (MT?.hs mt) (MT?.i mt) idx (MT?.j mt) in
MT idx (MT?.j mt) fhs (MT?.rhs_ok mt) (MT?.rhs mt) (MT?.mroot mt) (MT?.hash_fun mt)
val mt_flush:
#hsz:pos ->
mt:merkle_tree #hsz {mt_wf_elts mt /\ MT?.j mt > MT?.i mt} ->
GTot (fmt:merkle_tree{mt_wf_elts #hsz fmt})
let mt_flush #hsz mt =
mt_flush_to mt (MT?.j mt - 1)
#push-options "--max_fuel 2"
/// Retraction
val mt_retract_to_:
#hsz:pos ->
hs:hashess #hsz {S.length hs = 32} ->
lv:nat{lv < S.length hs} ->
i:nat ->
s:nat -> // s is the first index excluded from nhs
j:nat{ i <= s /\ s <= j /\
j < pow2 (S.length hs - lv) /\
hs_wf_elts lv hs i j} ->
GTot (nhs:hashess #hsz {
S.length nhs = S.length hs /\
S.equal (S.slice hs 0 lv) (S.slice nhs 0 lv) /\
hs_wf_elts #hsz lv nhs i s})
(decreases (S.length hs - lv))
let rec mt_retract_to_ #hsz hs lv i s j =
if lv >= S.length hs then hs
else begin
let hvec = S.index hs lv in
let old_len = j - offset_of i in
let new_len = s - offset_of i in
assert (S.length hvec = old_len);
assert (new_len <= old_len);
assert (new_len <= S.length hvec);
let retracted = S.slice hvec 0 new_len in
let nhs = S.upd hs lv retracted in
if lv >= S.length hs - 1 then nhs else
begin
hs_wf_elts_equal (lv + 1) hs nhs (i / 2) (j / 2);
mt_retract_to_ nhs (lv + 1) (i / 2) (s / 2) (j / 2)
end
end
#pop-options
val mt_retract_to:
#hsz:pos ->
mt:merkle_tree #hsz {mt_wf_elts mt} ->
r:nat{MT?.i mt <= r /\ r < MT?.j mt} -> | false | false | MerkleTree.New.High.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 1,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 10,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val mt_retract_to:
#hsz:pos ->
mt:merkle_tree #hsz {mt_wf_elts mt} ->
r:nat{MT?.i mt <= r /\ r < MT?.j mt} ->
GTot (rmt:merkle_tree #hsz {mt_wf_elts rmt /\ MT?.i rmt = MT?.i mt /\ MT?.j rmt = r + 1}) | [] | MerkleTree.New.High.mt_retract_to | {
"file_name": "src/MerkleTree.New.High.fst",
"git_rev": "3b0f086655c145aa23f58a97259ebf4cf112a4a3",
"git_url": "https://github.com/hacl-star/merkle-tree.git",
"project_name": "merkle-tree"
} |
mt: MerkleTree.New.High.merkle_tree{MerkleTree.New.High.mt_wf_elts mt} ->
r: Prims.nat{MT?.i mt <= r /\ r < MT?.j mt}
-> Prims.GTot
(rmt:
MerkleTree.New.High.merkle_tree
{MerkleTree.New.High.mt_wf_elts rmt /\ MT?.i rmt = MT?.i mt /\ MT?.j rmt = r + 1}) | {
"end_col": 77,
"end_line": 645,
"start_col": 29,
"start_line": 643
} |
Prims.GTot | val mt_make_path_step:
#hsz:pos ->
lv:nat{lv <= 32} ->
hs:hashess #hsz {S.length hs = 32} ->
rhs:hashes #hsz {S.length rhs = 32} ->
i:nat ->
j:nat{
j <> 0 /\ i <= j /\ j < pow2 (32 - lv) /\
hs_wf_elts lv hs i j} ->
k:nat{i <= k && k <= j} ->
p:path #hsz ->
actd:bool ->
GTot (path #hsz) | [
{
"abbrev": true,
"full_module": "MerkleTree.Spec",
"short_module": "MTS"
},
{
"abbrev": true,
"full_module": "FStar.UInt8",
"short_module": "U8"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "S"
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Ghost",
"short_module": null
},
{
"abbrev": false,
"full_module": "MerkleTree.New",
"short_module": null
},
{
"abbrev": false,
"full_module": "MerkleTree.New",
"short_module": null
},
{
"abbrev": 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 mt_make_path_step #hsz lv hs rhs i j k p actd =
let ofs = offset_of i in
if k % 2 = 1
then path_insert p (S.index (S.index hs lv) (k - 1 - ofs))
else (if k = j then p
else if k + 1 = j
then (if actd
then path_insert p (S.index rhs lv)
else p)
else path_insert p (S.index (S.index hs lv) (k + 1 - ofs))) | val mt_make_path_step:
#hsz:pos ->
lv:nat{lv <= 32} ->
hs:hashess #hsz {S.length hs = 32} ->
rhs:hashes #hsz {S.length rhs = 32} ->
i:nat ->
j:nat{
j <> 0 /\ i <= j /\ j < pow2 (32 - lv) /\
hs_wf_elts lv hs i j} ->
k:nat{i <= k && k <= j} ->
p:path #hsz ->
actd:bool ->
GTot (path #hsz)
let mt_make_path_step #hsz lv hs rhs i j k p actd = | false | null | false | let ofs = offset_of i in
if k % 2 = 1
then path_insert p (S.index (S.index hs lv) (k - 1 - ofs))
else
(if k = j
then p
else
if k + 1 = j
then (if actd then path_insert p (S.index rhs lv) else p)
else path_insert p (S.index (S.index hs lv) (k + 1 - ofs))) | {
"checked_file": "MerkleTree.New.High.fst.checked",
"dependencies": [
"Spec.Hash.Definitions.fst.checked",
"prims.fst.checked",
"MerkleTree.Spec.fst.checked",
"Lib.IntTypes.fsti.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "MerkleTree.New.High.fst"
} | [
"sometrivial"
] | [
"Prims.pos",
"Prims.nat",
"Prims.b2t",
"Prims.op_LessThanOrEqual",
"MerkleTree.New.High.hashess",
"Prims.op_Equality",
"Prims.int",
"FStar.Seq.Base.length",
"MerkleTree.New.High.hashes",
"MerkleTree.New.High.hash",
"Prims.l_and",
"Prims.op_disEquality",
"Prims.op_LessThan",
"Prims.pow2",
"Prims.op_Subtraction",
"MerkleTree.New.High.hs_wf_elts",
"Prims.op_AmpAmp",
"MerkleTree.New.High.path",
"Prims.bool",
"Prims.op_Modulus",
"MerkleTree.New.High.path_insert",
"FStar.Seq.Base.index",
"Prims.l_or",
"Prims.op_Addition",
"MerkleTree.New.High.offset_of"
] | [] | module MerkleTree.New.High
open FStar.Ghost
open FStar.Seq
module S = FStar.Seq
module U32 = FStar.UInt32
module U8 = FStar.UInt8
module MTS = MerkleTree.Spec
#set-options "--z3rlimit 10 --max_fuel 0 --max_ifuel 0"
type uint32_t = U32.t
type uint8_t = U8.t
type hash (#hsz:pos) = b:Spec.Hash.Definitions.bytes{Seq.length b = hsz}
type hashes (#hsz:pos) = S.seq (hash #hsz)
type hashess (#hsz:pos) = S.seq (hashes #hsz)
noextract
let hash_init (#hsz:pos): hash #hsz =
Seq.create hsz (Lib.IntTypes.u8 0)
val sha256_compress: src1:hash #32 -> src2:hash #32 -> GTot (hash #32)
let sha256_compress = MTS.sha256_compress
/// Facts about sequences
val seq_slice_equal_index:
#a:Type -> s1:S.seq a -> s2:S.seq a ->
i:nat -> j:nat{i <= j && j <= S.length s1 && j <= S.length s2} ->
k:nat{i <= k && k < j} ->
Lemma (requires S.equal (S.slice s1 i j) (S.slice s2 i j))
(ensures S.index s1 k == S.index s2 k)
[SMTPat (S.equal (S.slice s1 i j) (S.slice s2 i j));
SMTPat (S.index s1 k)]
let seq_slice_equal_index #a s1 s2 i j k =
assert (S.index (S.slice s1 i j) (k - i) == S.index (S.slice s2 i j) (k - i))
private val seq_slice_more_equal:
#a:Type -> s1:S.seq a -> s2:S.seq a ->
n:nat -> m:nat{n <= m && m <= S.length s1 && m <= S.length s2} ->
k:nat{n <= k} -> l:nat{k <= l && l <= m} ->
Lemma (requires S.equal (S.slice s1 n m) (S.slice s2 n m))
(ensures S.equal (S.slice s1 k l) (S.slice s2 k l))
[SMTPat (S.equal (S.slice s1 n m) (S.slice s2 n m));
SMTPat (S.equal (S.slice s1 k l) (S.slice s2 k l))]
private let seq_slice_more_equal #a s1 s2 n m k l =
slice_slice s1 n m (k - n) (l - n);
slice_slice s2 n m (k - n) (l - n)
/// Facts about "2"
val remainder_2_not_1_div: n:nat ->
Lemma (requires n % 2 <> 1)
(ensures n / 2 = (n + 1) / 2)
let remainder_2_not_1_div n = ()
val remainder_2_1_div: n:nat ->
Lemma (requires n % 2 = 1)
(ensures n / 2 + 1 = (n + 1) / 2)
let remainder_2_1_div n = ()
/// High-level Merkle tree data structure
noeq type merkle_tree (#hsz:pos) =
| MT: i:nat ->
j:nat{i <= j && j < pow2 32} ->
hs:hashess #hsz {S.length hs = 32} ->
rhs_ok:bool ->
rhs:hashes #hsz {S.length rhs = 32} -> // Rightmost hashes
mroot:hash #hsz ->
hash_fun:MTS.hash_fun_t #hsz ->
merkle_tree #hsz
val mt_not_full (#hsz:pos): merkle_tree #hsz -> GTot bool
let mt_not_full #hsz mt =
MT?.j mt < pow2 32 - 1
val mt_empty (#hsz:pos): merkle_tree #hsz -> GTot bool
let mt_empty #hsz mt =
MT?.j mt = 0
val mt_not_empty (#hsz:pos): merkle_tree #hsz -> GTot bool
let mt_not_empty #hsz mt =
MT?.j mt > 0
/// Well-formedness w.r.t. indices of base hash elements
noextract
val offset_of: i:nat -> Tot nat
let offset_of i =
if i % 2 = 0 then i else i - 1
val hs_wf_elts:
#hsz:pos ->
lv:nat{lv <= 32} ->
hs:hashess #hsz {S.length hs = 32} ->
i:nat -> j:nat{j >= i} ->
GTot Type0 (decreases (32 - lv))
let rec hs_wf_elts #hsz lv hs i j =
if lv = 32 then true
else (let ofs = offset_of i in
S.length (S.index hs lv) == j - ofs /\
hs_wf_elts #hsz (lv + 1) hs (i / 2) (j / 2))
#push-options "--max_fuel 1"
val hs_wf_elts_equal:
#hsz:pos ->
lv:nat{lv <= 32} ->
hs1:hashess #hsz {S.length hs1 = 32} ->
hs2:hashess #hsz {S.length hs2 = 32} ->
i:nat ->
j:nat{j >= i} ->
Lemma (requires hs_wf_elts lv hs1 i j /\
S.equal (S.slice hs1 lv 32) (S.slice hs2 lv 32))
(ensures hs_wf_elts lv hs2 i j)
(decreases (32 - lv))
let rec hs_wf_elts_equal #hsz lv hs1 hs2 i j =
if lv = 32 then ()
else (S.slice_slice hs1 lv 32 1 (32 - lv);
S.slice_slice hs2 lv 32 1 (32 - lv);
assert (S.equal (S.slice hs1 (lv + 1) 32)
(S.slice hs2 (lv + 1) 32));
S.lemma_index_slice hs1 lv 32 0;
S.lemma_index_slice hs2 lv 32 0;
assert (S.index hs1 lv == S.index hs2 lv);
hs_wf_elts_equal (lv + 1) hs1 hs2 (i / 2) (j / 2))
val mt_wf_elts (#hsz:pos): merkle_tree #hsz -> GTot Type0
let mt_wf_elts #_ (MT i j hs _ _ _ _) =
hs_wf_elts 0 hs i j
/// Construction
val hs_wf_elts_empty:
#hsz:pos ->
lv:nat{lv <= 32} ->
Lemma (requires True)
(ensures hs_wf_elts #hsz lv (S.create 32 S.empty) 0 0)
(decreases (32 - lv))
let rec hs_wf_elts_empty #hsz lv =
if lv = 32 then ()
else hs_wf_elts_empty #hsz (lv + 1)
// NOTE: the public function is `create_mt` defined below, which
// builds a tree with an initial hash.
noextract inline_for_extraction
val create_empty_mt (#hsz:pos) (#f:MTS.hash_fun_t #hsz): unit -> GTot (mt:merkle_tree #hsz {mt_wf_elts #hsz mt})
let create_empty_mt #hsz #f _ =
hs_wf_elts_empty #hsz 0;
MT 0 0 (S.create 32 S.empty) false (S.create 32 (hash_init #hsz)) (hash_init #hsz) f
/// Insertion
val hashess_insert:
#hsz:pos ->
lv:nat{lv < 32} ->
i:nat ->
j:nat{i <= j /\ j < pow2 (32 - lv) - 1} ->
hs:hashess #hsz {S.length hs = 32 /\ hs_wf_elts lv hs i j} ->
v:hash #hsz ->
GTot (ihs:hashess #hsz {S.length ihs = 32 /\ hs_wf_elts (lv + 1) ihs (i / 2) (j / 2)})
let hashess_insert #hsz lv i j hs v =
let ihs = S.upd hs lv (S.snoc (S.index hs lv) v) in
hs_wf_elts_equal (lv + 1) hs ihs (i / 2) (j / 2);
ihs
val insert_:
#hsz:pos -> #f:MTS.hash_fun_t #hsz ->
lv:nat{lv < 32} ->
i:nat ->
j:nat{i <= j /\ j < pow2 (32 - lv) - 1} ->
hs:hashess #hsz {S.length hs = 32 /\ hs_wf_elts lv hs i j} ->
acc:hash #hsz ->
GTot (ihs:hashess #hsz {
S.length ihs = 32 /\
hs_wf_elts #hsz lv ihs i (j + 1) /\
S.equal (S.slice hs 0 lv) (S.slice ihs 0 lv)})
(decreases j)
let rec insert_ #hsz #f lv i j hs acc =
let ihs = hashess_insert #hsz lv i j hs acc in
assert (S.equal (S.slice hs 0 lv) (S.slice ihs 0 lv));
if j % 2 = 1 // S.length (S.index hs lv) > 0
then begin
remainder_2_1_div j;
let nacc = f (S.last (S.index hs lv)) acc in
let rihs = insert_ #hsz #f (lv + 1) (i / 2) (j / 2) ihs nacc in
assert (hs_wf_elts #hsz (lv + 1) rihs (i / 2) (j / 2 + 1));
assert (S.equal (S.slice ihs 0 (lv + 1)) (S.slice rihs 0 (lv + 1)));
assert (S.index ihs lv == S.index rihs lv);
assert (S.length (S.index rihs lv) = (j + 1) - offset_of i);
assert (S.equal (S.slice ihs 0 (lv + 1)) (S.slice rihs 0 (lv + 1)));
assert (S.equal (S.slice ihs 0 lv) (S.slice rihs 0 lv));
rihs
end
else ihs
val insert_base:
#hsz:pos -> #f:MTS.hash_fun_t #hsz ->
lv:nat -> i:nat -> j:nat -> hs:hashess #hsz -> acc:hash #hsz ->
Lemma (requires
lv < 32 /\ i <= j /\ j < pow2 (32 - lv) - 1 /\
S.length hs = 32 /\ hs_wf_elts lv hs i j /\
j % 2 <> 1)
(ensures S.equal (insert_ #_ #f lv i j hs acc)
(hashess_insert lv i j hs acc))
let insert_base #_ #_ lv i j hs acc = ()
val insert_rec:
#hsz:pos -> #f:MTS.hash_fun_t #hsz ->
lv:nat -> i:nat -> j:nat -> hs:hashess -> acc:hash ->
Lemma (requires
lv < 32 /\ i <= j /\ j < pow2 (32 - lv) - 1 /\
S.length hs = 32 /\ hs_wf_elts lv hs i j /\
j % 2 == 1)
(ensures
(hs_wf_elts_equal (lv + 1) hs
(hashess_insert lv i j hs acc) (i / 2) (j / 2);
S.equal (insert_ #_ #f lv i j hs acc)
(insert_ #_ #f (lv + 1) (i / 2) (j / 2)
(hashess_insert lv i j hs acc)
(f (S.last (S.index hs lv)) acc))))
let insert_rec #_ #_ lv i j hs acc = ()
val mt_insert:
#hsz:pos ->
mt:merkle_tree #hsz {mt_wf_elts mt /\ mt_not_full mt} -> v:hash #hsz ->
GTot (imt:merkle_tree #hsz{mt_wf_elts #hsz imt})
let mt_insert #hsz mt v =
MT (MT?.i mt)
(MT?.j mt + 1)
(insert_ #_ #(MT?.hash_fun mt) 0 (MT?.i mt) (MT?.j mt) (MT?.hs mt) v)
false
(MT?.rhs mt)
(MT?.mroot mt)
(MT?.hash_fun mt)
val mt_create:
hsz:pos -> f:MTS.hash_fun_t #hsz ->
init:hash #hsz -> GTot (mt:merkle_tree{mt_wf_elts #hsz mt})
let mt_create hsz f init =
mt_insert #_ (create_empty_mt #_ #f ()) init
/// Getting the Merkle root and path
type path (#hsz:pos) = S.seq (hash #hsz)
// Construct the rightmost hashes for a given (incomplete) Merkle tree.
// This function calculates the Merkle root as well, which is the final
// accumulator value.
val construct_rhs:
#hsz:pos -> #f:MTS.hash_fun_t #hsz ->
lv:nat{lv <= 32} ->
hs:hashess #hsz {S.length hs = 32} ->
rhs:hashes #hsz {S.length rhs = 32} ->
i:nat ->
j:nat{
i <= j /\ j < pow2 (32 - lv) /\
hs_wf_elts #hsz lv hs i j} ->
acc:hash #hsz ->
actd:bool ->
GTot (crhs:hashes #hsz {S.length crhs = 32} * (hash #hsz))
(decreases j)
let rec construct_rhs #hsz #f lv hs rhs i j acc actd =
let ofs = offset_of i in
if j = 0 then (rhs, acc)
else
(if j % 2 = 0
then (construct_rhs #_ #f (lv + 1) hs rhs (i / 2) (j / 2) acc actd)
else (let nrhs = if actd then S.upd rhs lv acc else rhs in
let nacc = if actd
then f (S.index (S.index hs lv) (j - 1 - ofs)) acc
else S.index (S.index hs lv) (j - 1 - ofs) in
construct_rhs #_ #f (lv + 1) hs nrhs (i / 2) (j / 2) nacc true))
val construct_rhs_unchanged:
#hsz:pos -> #f:MTS.hash_fun_t #hsz ->
lv:nat{lv <= 32} ->
hs:hashess #hsz {S.length hs = 32} ->
rhs:hashes #hsz {S.length rhs = 32} ->
i:nat ->
j:nat{
i <= j /\ j < pow2 (32 - lv) /\
hs_wf_elts #hsz lv hs i j} ->
acc:hash #hsz ->
actd:bool ->
Lemma (requires True)
(ensures S.equal (S.slice rhs 0 lv)
(S.slice (fst (construct_rhs #_ #f lv hs rhs i j acc actd)) 0 lv))
(decreases j)
let rec construct_rhs_unchanged #hsz #f lv hs rhs i j acc actd =
let ofs = offset_of i in
if j = 0 then ()
else if j % 2 = 0
then (construct_rhs_unchanged #_ #f (lv + 1) hs rhs (i / 2) (j / 2) acc actd;
let rrhs = fst (construct_rhs #_ #f (lv + 1) hs rhs (i / 2) (j / 2) acc actd) in
assert (S.equal (S.slice rhs 0 lv) (S.slice rrhs 0 lv)))
else (let nrhs = if actd then S.upd rhs lv acc else rhs in
let nacc = if actd
then f (S.index (S.index hs lv) (j - 1 - ofs)) acc
else S.index (S.index hs lv) (j - 1 - ofs) in
construct_rhs_unchanged #_ #f (lv + 1) hs nrhs (i / 2) (j / 2) nacc true;
let rrhs = fst (construct_rhs #_ #f (lv + 1) hs nrhs (i / 2) (j / 2) nacc true) in
assert (S.equal (S.slice nrhs 0 lv) (S.slice rrhs 0 lv));
assert (S.equal (S.slice rhs 0 lv) (S.slice nrhs 0 lv)))
val construct_rhs_even:
#hsz:pos -> #f:MTS.hash_fun_t #hsz ->
lv:nat{lv <= 32} ->
hs:hashess #hsz {S.length hs = 32} ->
rhs:hashes #hsz {S.length rhs = 32} ->
i:nat ->
j:nat{
i <= j /\ j < pow2 (32 - lv) /\
hs_wf_elts #hsz lv hs i j} ->
acc:hash #hsz ->
actd:bool ->
Lemma (requires j <> 0 /\ j % 2 = 0)
(ensures construct_rhs #_ #f lv hs rhs i j acc actd ==
construct_rhs #_ #f (lv + 1) hs rhs (i / 2) (j / 2) acc actd)
let construct_rhs_even #_ #_ _ _ _ _ _ _ _ = ()
val construct_rhs_odd:
#hsz:pos -> #f:MTS.hash_fun_t #hsz ->
lv:nat{lv <= 32} ->
hs:hashess #hsz {S.length hs = 32} ->
rhs:hashes #hsz {S.length rhs = 32} ->
i:nat ->
j:nat{
i <= j /\ j < pow2 (32 - lv) /\
hs_wf_elts lv hs i j} ->
acc:hash ->
actd:bool ->
Lemma (requires j % 2 = 1)
(ensures construct_rhs #_ #f lv hs rhs i j acc actd ==
(let ofs = offset_of i in
let nrhs = if actd then S.upd rhs lv acc else rhs in
let nacc = if actd
then f (S.index (S.index hs lv) (j - 1 - ofs)) acc
else S.index (S.index hs lv) (j - 1 - ofs) in
construct_rhs #_ #f (lv + 1) hs nrhs (i / 2) (j / 2) nacc true))
let construct_rhs_odd #_ #_ _ _ _ _ _ _ _ = ()
val mt_get_root:
#hsz:pos ->
mt:merkle_tree #hsz {mt_wf_elts #hsz mt} -> drt:hash #hsz ->
GTot (merkle_tree #hsz * hash #hsz)
let mt_get_root #hsz mt drt =
if MT?.rhs_ok mt then (mt, MT?.mroot mt)
else begin
let (nrhs, rt) = construct_rhs #_ #(MT?.hash_fun mt) 0 (MT?.hs mt) (MT?.rhs mt) (MT?.i mt) (MT?.j mt) drt false in
(MT (MT?.i mt) (MT?.j mt) (MT?.hs mt) true nrhs rt (MT?.hash_fun mt), rt)
end
val mt_get_root_rhs_ok_true:
#hsz:pos ->
mt:merkle_tree #hsz {mt_wf_elts mt} -> drt:hash #hsz ->
Lemma (requires MT?.rhs_ok mt == true)
(ensures mt_get_root #hsz mt drt == (mt, MT?.mroot mt))
let mt_get_root_rhs_ok_true #hsz mt drt = ()
val mt_get_root_rhs_ok_false:
#hsz:pos ->
mt:merkle_tree #hsz {mt_wf_elts mt} -> drt:hash ->
Lemma (requires MT?.rhs_ok mt == false)
(ensures mt_get_root mt drt ==
(let (nrhs, rt) =
construct_rhs #_ #(MT?.hash_fun mt)
0 (MT?.hs mt) (MT?.rhs mt) (MT?.i mt) (MT?.j mt)
drt false in
(MT (MT?.i mt) (MT?.j mt) (MT?.hs mt) true nrhs rt (MT?.hash_fun mt), rt)))
let mt_get_root_rhs_ok_false #_ _ _ = ()
val path_insert: (#hsz:pos) -> p:path #hsz -> hp:hash #hsz -> GTot (path #hsz)
let path_insert #_ p hp = S.snoc p hp
val mt_path_length_step:
k:nat -> j:nat{k <= j} -> actd:bool -> GTot nat
let mt_path_length_step k j actd =
if j = 0 then 0
else (if k % 2 = 0
then (if j = k || (j = k + 1 && not actd) then 0 else 1)
else 1)
val mt_path_length:
k:nat -> j:nat{k <= j} -> actd:bool -> GTot nat
let rec mt_path_length k j actd =
if j = 0 then 0
else (let nactd = actd || (j % 2 = 1) in
mt_path_length_step k j actd +
mt_path_length (k / 2) (j / 2) nactd)
val mt_make_path_step:
#hsz:pos ->
lv:nat{lv <= 32} ->
hs:hashess #hsz {S.length hs = 32} ->
rhs:hashes #hsz {S.length rhs = 32} ->
i:nat ->
j:nat{
j <> 0 /\ i <= j /\ j < pow2 (32 - lv) /\
hs_wf_elts lv hs i j} ->
k:nat{i <= k && k <= j} ->
p:path #hsz ->
actd:bool -> | false | false | MerkleTree.New.High.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 1,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 10,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val mt_make_path_step:
#hsz:pos ->
lv:nat{lv <= 32} ->
hs:hashess #hsz {S.length hs = 32} ->
rhs:hashes #hsz {S.length rhs = 32} ->
i:nat ->
j:nat{
j <> 0 /\ i <= j /\ j < pow2 (32 - lv) /\
hs_wf_elts lv hs i j} ->
k:nat{i <= k && k <= j} ->
p:path #hsz ->
actd:bool ->
GTot (path #hsz) | [] | MerkleTree.New.High.mt_make_path_step | {
"file_name": "src/MerkleTree.New.High.fst",
"git_rev": "3b0f086655c145aa23f58a97259ebf4cf112a4a3",
"git_url": "https://github.com/hacl-star/merkle-tree.git",
"project_name": "merkle-tree"
} |
lv: Prims.nat{lv <= 32} ->
hs: MerkleTree.New.High.hashess{FStar.Seq.Base.length hs = 32} ->
rhs: MerkleTree.New.High.hashes{FStar.Seq.Base.length rhs = 32} ->
i: Prims.nat ->
j:
Prims.nat
{j <> 0 /\ i <= j /\ j < Prims.pow2 (32 - lv) /\ MerkleTree.New.High.hs_wf_elts lv hs i j} ->
k: Prims.nat{i <= k && k <= j} ->
p: MerkleTree.New.High.path ->
actd: Prims.bool
-> Prims.GTot MerkleTree.New.High.path | {
"end_col": 64,
"end_line": 420,
"start_col": 51,
"start_line": 411
} |
FStar.Pervasives.Lemma | val hs_wf_elts_equal:
#hsz:pos ->
lv:nat{lv <= 32} ->
hs1:hashess #hsz {S.length hs1 = 32} ->
hs2:hashess #hsz {S.length hs2 = 32} ->
i:nat ->
j:nat{j >= i} ->
Lemma (requires hs_wf_elts lv hs1 i j /\
S.equal (S.slice hs1 lv 32) (S.slice hs2 lv 32))
(ensures hs_wf_elts lv hs2 i j)
(decreases (32 - lv)) | [
{
"abbrev": true,
"full_module": "MerkleTree.Spec",
"short_module": "MTS"
},
{
"abbrev": true,
"full_module": "FStar.UInt8",
"short_module": "U8"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "S"
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Ghost",
"short_module": null
},
{
"abbrev": false,
"full_module": "MerkleTree.New",
"short_module": null
},
{
"abbrev": false,
"full_module": "MerkleTree.New",
"short_module": null
},
{
"abbrev": 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 hs_wf_elts_equal #hsz lv hs1 hs2 i j =
if lv = 32 then ()
else (S.slice_slice hs1 lv 32 1 (32 - lv);
S.slice_slice hs2 lv 32 1 (32 - lv);
assert (S.equal (S.slice hs1 (lv + 1) 32)
(S.slice hs2 (lv + 1) 32));
S.lemma_index_slice hs1 lv 32 0;
S.lemma_index_slice hs2 lv 32 0;
assert (S.index hs1 lv == S.index hs2 lv);
hs_wf_elts_equal (lv + 1) hs1 hs2 (i / 2) (j / 2)) | val hs_wf_elts_equal:
#hsz:pos ->
lv:nat{lv <= 32} ->
hs1:hashess #hsz {S.length hs1 = 32} ->
hs2:hashess #hsz {S.length hs2 = 32} ->
i:nat ->
j:nat{j >= i} ->
Lemma (requires hs_wf_elts lv hs1 i j /\
S.equal (S.slice hs1 lv 32) (S.slice hs2 lv 32))
(ensures hs_wf_elts lv hs2 i j)
(decreases (32 - lv))
let rec hs_wf_elts_equal #hsz lv hs1 hs2 i j = | false | null | true | if lv = 32
then ()
else
(S.slice_slice hs1 lv 32 1 (32 - lv);
S.slice_slice hs2 lv 32 1 (32 - lv);
assert (S.equal (S.slice hs1 (lv + 1) 32) (S.slice hs2 (lv + 1) 32));
S.lemma_index_slice hs1 lv 32 0;
S.lemma_index_slice hs2 lv 32 0;
assert (S.index hs1 lv == S.index hs2 lv);
hs_wf_elts_equal (lv + 1) hs1 hs2 (i / 2) (j / 2)) | {
"checked_file": "MerkleTree.New.High.fst.checked",
"dependencies": [
"Spec.Hash.Definitions.fst.checked",
"prims.fst.checked",
"MerkleTree.Spec.fst.checked",
"Lib.IntTypes.fsti.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "MerkleTree.New.High.fst"
} | [
"lemma",
""
] | [
"Prims.pos",
"Prims.nat",
"Prims.b2t",
"Prims.op_LessThanOrEqual",
"MerkleTree.New.High.hashess",
"Prims.op_Equality",
"Prims.int",
"FStar.Seq.Base.length",
"MerkleTree.New.High.hashes",
"Prims.op_GreaterThanOrEqual",
"Prims.bool",
"MerkleTree.New.High.hs_wf_elts_equal",
"Prims.op_Addition",
"Prims.op_Division",
"Prims.unit",
"Prims._assert",
"Prims.eq2",
"FStar.Seq.Base.index",
"FStar.Seq.Base.lemma_index_slice",
"FStar.Seq.Base.equal",
"FStar.Seq.Base.slice",
"FStar.Seq.Properties.slice_slice",
"Prims.op_Subtraction"
] | [] | module MerkleTree.New.High
open FStar.Ghost
open FStar.Seq
module S = FStar.Seq
module U32 = FStar.UInt32
module U8 = FStar.UInt8
module MTS = MerkleTree.Spec
#set-options "--z3rlimit 10 --max_fuel 0 --max_ifuel 0"
type uint32_t = U32.t
type uint8_t = U8.t
type hash (#hsz:pos) = b:Spec.Hash.Definitions.bytes{Seq.length b = hsz}
type hashes (#hsz:pos) = S.seq (hash #hsz)
type hashess (#hsz:pos) = S.seq (hashes #hsz)
noextract
let hash_init (#hsz:pos): hash #hsz =
Seq.create hsz (Lib.IntTypes.u8 0)
val sha256_compress: src1:hash #32 -> src2:hash #32 -> GTot (hash #32)
let sha256_compress = MTS.sha256_compress
/// Facts about sequences
val seq_slice_equal_index:
#a:Type -> s1:S.seq a -> s2:S.seq a ->
i:nat -> j:nat{i <= j && j <= S.length s1 && j <= S.length s2} ->
k:nat{i <= k && k < j} ->
Lemma (requires S.equal (S.slice s1 i j) (S.slice s2 i j))
(ensures S.index s1 k == S.index s2 k)
[SMTPat (S.equal (S.slice s1 i j) (S.slice s2 i j));
SMTPat (S.index s1 k)]
let seq_slice_equal_index #a s1 s2 i j k =
assert (S.index (S.slice s1 i j) (k - i) == S.index (S.slice s2 i j) (k - i))
private val seq_slice_more_equal:
#a:Type -> s1:S.seq a -> s2:S.seq a ->
n:nat -> m:nat{n <= m && m <= S.length s1 && m <= S.length s2} ->
k:nat{n <= k} -> l:nat{k <= l && l <= m} ->
Lemma (requires S.equal (S.slice s1 n m) (S.slice s2 n m))
(ensures S.equal (S.slice s1 k l) (S.slice s2 k l))
[SMTPat (S.equal (S.slice s1 n m) (S.slice s2 n m));
SMTPat (S.equal (S.slice s1 k l) (S.slice s2 k l))]
private let seq_slice_more_equal #a s1 s2 n m k l =
slice_slice s1 n m (k - n) (l - n);
slice_slice s2 n m (k - n) (l - n)
/// Facts about "2"
val remainder_2_not_1_div: n:nat ->
Lemma (requires n % 2 <> 1)
(ensures n / 2 = (n + 1) / 2)
let remainder_2_not_1_div n = ()
val remainder_2_1_div: n:nat ->
Lemma (requires n % 2 = 1)
(ensures n / 2 + 1 = (n + 1) / 2)
let remainder_2_1_div n = ()
/// High-level Merkle tree data structure
noeq type merkle_tree (#hsz:pos) =
| MT: i:nat ->
j:nat{i <= j && j < pow2 32} ->
hs:hashess #hsz {S.length hs = 32} ->
rhs_ok:bool ->
rhs:hashes #hsz {S.length rhs = 32} -> // Rightmost hashes
mroot:hash #hsz ->
hash_fun:MTS.hash_fun_t #hsz ->
merkle_tree #hsz
val mt_not_full (#hsz:pos): merkle_tree #hsz -> GTot bool
let mt_not_full #hsz mt =
MT?.j mt < pow2 32 - 1
val mt_empty (#hsz:pos): merkle_tree #hsz -> GTot bool
let mt_empty #hsz mt =
MT?.j mt = 0
val mt_not_empty (#hsz:pos): merkle_tree #hsz -> GTot bool
let mt_not_empty #hsz mt =
MT?.j mt > 0
/// Well-formedness w.r.t. indices of base hash elements
noextract
val offset_of: i:nat -> Tot nat
let offset_of i =
if i % 2 = 0 then i else i - 1
val hs_wf_elts:
#hsz:pos ->
lv:nat{lv <= 32} ->
hs:hashess #hsz {S.length hs = 32} ->
i:nat -> j:nat{j >= i} ->
GTot Type0 (decreases (32 - lv))
let rec hs_wf_elts #hsz lv hs i j =
if lv = 32 then true
else (let ofs = offset_of i in
S.length (S.index hs lv) == j - ofs /\
hs_wf_elts #hsz (lv + 1) hs (i / 2) (j / 2))
#push-options "--max_fuel 1"
val hs_wf_elts_equal:
#hsz:pos ->
lv:nat{lv <= 32} ->
hs1:hashess #hsz {S.length hs1 = 32} ->
hs2:hashess #hsz {S.length hs2 = 32} ->
i:nat ->
j:nat{j >= i} ->
Lemma (requires hs_wf_elts lv hs1 i j /\
S.equal (S.slice hs1 lv 32) (S.slice hs2 lv 32))
(ensures hs_wf_elts lv hs2 i j)
(decreases (32 - lv)) | false | false | MerkleTree.New.High.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 1,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 10,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val hs_wf_elts_equal:
#hsz:pos ->
lv:nat{lv <= 32} ->
hs1:hashess #hsz {S.length hs1 = 32} ->
hs2:hashess #hsz {S.length hs2 = 32} ->
i:nat ->
j:nat{j >= i} ->
Lemma (requires hs_wf_elts lv hs1 i j /\
S.equal (S.slice hs1 lv 32) (S.slice hs2 lv 32))
(ensures hs_wf_elts lv hs2 i j)
(decreases (32 - lv)) | [
"recursion"
] | MerkleTree.New.High.hs_wf_elts_equal | {
"file_name": "src/MerkleTree.New.High.fst",
"git_rev": "3b0f086655c145aa23f58a97259ebf4cf112a4a3",
"git_url": "https://github.com/hacl-star/merkle-tree.git",
"project_name": "merkle-tree"
} |
lv: Prims.nat{lv <= 32} ->
hs1: MerkleTree.New.High.hashess{FStar.Seq.Base.length hs1 = 32} ->
hs2: MerkleTree.New.High.hashess{FStar.Seq.Base.length hs2 = 32} ->
i: Prims.nat ->
j: Prims.nat{j >= i}
-> FStar.Pervasives.Lemma
(requires
MerkleTree.New.High.hs_wf_elts lv hs1 i j /\
FStar.Seq.Base.equal (FStar.Seq.Base.slice hs1 lv 32) (FStar.Seq.Base.slice hs2 lv 32))
(ensures MerkleTree.New.High.hs_wf_elts lv hs2 i j)
(decreases 32 - lv) | {
"end_col": 57,
"end_line": 132,
"start_col": 2,
"start_line": 124
} |
Prims.GTot | val construct_rhs:
#hsz:pos -> #f:MTS.hash_fun_t #hsz ->
lv:nat{lv <= 32} ->
hs:hashess #hsz {S.length hs = 32} ->
rhs:hashes #hsz {S.length rhs = 32} ->
i:nat ->
j:nat{
i <= j /\ j < pow2 (32 - lv) /\
hs_wf_elts #hsz lv hs i j} ->
acc:hash #hsz ->
actd:bool ->
GTot (crhs:hashes #hsz {S.length crhs = 32} * (hash #hsz))
(decreases j) | [
{
"abbrev": true,
"full_module": "MerkleTree.Spec",
"short_module": "MTS"
},
{
"abbrev": true,
"full_module": "FStar.UInt8",
"short_module": "U8"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "S"
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Ghost",
"short_module": null
},
{
"abbrev": false,
"full_module": "MerkleTree.New",
"short_module": null
},
{
"abbrev": false,
"full_module": "MerkleTree.New",
"short_module": null
},
{
"abbrev": 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 construct_rhs #hsz #f lv hs rhs i j acc actd =
let ofs = offset_of i in
if j = 0 then (rhs, acc)
else
(if j % 2 = 0
then (construct_rhs #_ #f (lv + 1) hs rhs (i / 2) (j / 2) acc actd)
else (let nrhs = if actd then S.upd rhs lv acc else rhs in
let nacc = if actd
then f (S.index (S.index hs lv) (j - 1 - ofs)) acc
else S.index (S.index hs lv) (j - 1 - ofs) in
construct_rhs #_ #f (lv + 1) hs nrhs (i / 2) (j / 2) nacc true)) | val construct_rhs:
#hsz:pos -> #f:MTS.hash_fun_t #hsz ->
lv:nat{lv <= 32} ->
hs:hashess #hsz {S.length hs = 32} ->
rhs:hashes #hsz {S.length rhs = 32} ->
i:nat ->
j:nat{
i <= j /\ j < pow2 (32 - lv) /\
hs_wf_elts #hsz lv hs i j} ->
acc:hash #hsz ->
actd:bool ->
GTot (crhs:hashes #hsz {S.length crhs = 32} * (hash #hsz))
(decreases j)
let rec construct_rhs #hsz #f lv hs rhs i j acc actd = | false | null | false | let ofs = offset_of i in
if j = 0
then (rhs, acc)
else
(if j % 2 = 0
then (construct_rhs #_ #f (lv + 1) hs rhs (i / 2) (j / 2) acc actd)
else
(let nrhs = if actd then S.upd rhs lv acc else rhs in
let nacc =
if actd
then f (S.index (S.index hs lv) (j - 1 - ofs)) acc
else S.index (S.index hs lv) (j - 1 - ofs)
in
construct_rhs #_ #f (lv + 1) hs nrhs (i / 2) (j / 2) nacc true)) | {
"checked_file": "MerkleTree.New.High.fst.checked",
"dependencies": [
"Spec.Hash.Definitions.fst.checked",
"prims.fst.checked",
"MerkleTree.Spec.fst.checked",
"Lib.IntTypes.fsti.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "MerkleTree.New.High.fst"
} | [
"sometrivial",
""
] | [
"Prims.pos",
"MerkleTree.Spec.hash_fun_t",
"Prims.nat",
"Prims.b2t",
"Prims.op_LessThanOrEqual",
"MerkleTree.New.High.hashess",
"Prims.op_Equality",
"Prims.int",
"FStar.Seq.Base.length",
"MerkleTree.New.High.hashes",
"MerkleTree.New.High.hash",
"Prims.l_and",
"Prims.op_LessThan",
"Prims.pow2",
"Prims.op_Subtraction",
"MerkleTree.New.High.hs_wf_elts",
"Prims.bool",
"FStar.Pervasives.Native.Mktuple2",
"Prims.op_Modulus",
"MerkleTree.New.High.construct_rhs",
"Prims.op_Addition",
"Prims.op_Division",
"FStar.Seq.Base.index",
"FStar.Seq.Base.upd",
"FStar.Pervasives.Native.tuple2",
"MerkleTree.New.High.offset_of"
] | [] | module MerkleTree.New.High
open FStar.Ghost
open FStar.Seq
module S = FStar.Seq
module U32 = FStar.UInt32
module U8 = FStar.UInt8
module MTS = MerkleTree.Spec
#set-options "--z3rlimit 10 --max_fuel 0 --max_ifuel 0"
type uint32_t = U32.t
type uint8_t = U8.t
type hash (#hsz:pos) = b:Spec.Hash.Definitions.bytes{Seq.length b = hsz}
type hashes (#hsz:pos) = S.seq (hash #hsz)
type hashess (#hsz:pos) = S.seq (hashes #hsz)
noextract
let hash_init (#hsz:pos): hash #hsz =
Seq.create hsz (Lib.IntTypes.u8 0)
val sha256_compress: src1:hash #32 -> src2:hash #32 -> GTot (hash #32)
let sha256_compress = MTS.sha256_compress
/// Facts about sequences
val seq_slice_equal_index:
#a:Type -> s1:S.seq a -> s2:S.seq a ->
i:nat -> j:nat{i <= j && j <= S.length s1 && j <= S.length s2} ->
k:nat{i <= k && k < j} ->
Lemma (requires S.equal (S.slice s1 i j) (S.slice s2 i j))
(ensures S.index s1 k == S.index s2 k)
[SMTPat (S.equal (S.slice s1 i j) (S.slice s2 i j));
SMTPat (S.index s1 k)]
let seq_slice_equal_index #a s1 s2 i j k =
assert (S.index (S.slice s1 i j) (k - i) == S.index (S.slice s2 i j) (k - i))
private val seq_slice_more_equal:
#a:Type -> s1:S.seq a -> s2:S.seq a ->
n:nat -> m:nat{n <= m && m <= S.length s1 && m <= S.length s2} ->
k:nat{n <= k} -> l:nat{k <= l && l <= m} ->
Lemma (requires S.equal (S.slice s1 n m) (S.slice s2 n m))
(ensures S.equal (S.slice s1 k l) (S.slice s2 k l))
[SMTPat (S.equal (S.slice s1 n m) (S.slice s2 n m));
SMTPat (S.equal (S.slice s1 k l) (S.slice s2 k l))]
private let seq_slice_more_equal #a s1 s2 n m k l =
slice_slice s1 n m (k - n) (l - n);
slice_slice s2 n m (k - n) (l - n)
/// Facts about "2"
val remainder_2_not_1_div: n:nat ->
Lemma (requires n % 2 <> 1)
(ensures n / 2 = (n + 1) / 2)
let remainder_2_not_1_div n = ()
val remainder_2_1_div: n:nat ->
Lemma (requires n % 2 = 1)
(ensures n / 2 + 1 = (n + 1) / 2)
let remainder_2_1_div n = ()
/// High-level Merkle tree data structure
noeq type merkle_tree (#hsz:pos) =
| MT: i:nat ->
j:nat{i <= j && j < pow2 32} ->
hs:hashess #hsz {S.length hs = 32} ->
rhs_ok:bool ->
rhs:hashes #hsz {S.length rhs = 32} -> // Rightmost hashes
mroot:hash #hsz ->
hash_fun:MTS.hash_fun_t #hsz ->
merkle_tree #hsz
val mt_not_full (#hsz:pos): merkle_tree #hsz -> GTot bool
let mt_not_full #hsz mt =
MT?.j mt < pow2 32 - 1
val mt_empty (#hsz:pos): merkle_tree #hsz -> GTot bool
let mt_empty #hsz mt =
MT?.j mt = 0
val mt_not_empty (#hsz:pos): merkle_tree #hsz -> GTot bool
let mt_not_empty #hsz mt =
MT?.j mt > 0
/// Well-formedness w.r.t. indices of base hash elements
noextract
val offset_of: i:nat -> Tot nat
let offset_of i =
if i % 2 = 0 then i else i - 1
val hs_wf_elts:
#hsz:pos ->
lv:nat{lv <= 32} ->
hs:hashess #hsz {S.length hs = 32} ->
i:nat -> j:nat{j >= i} ->
GTot Type0 (decreases (32 - lv))
let rec hs_wf_elts #hsz lv hs i j =
if lv = 32 then true
else (let ofs = offset_of i in
S.length (S.index hs lv) == j - ofs /\
hs_wf_elts #hsz (lv + 1) hs (i / 2) (j / 2))
#push-options "--max_fuel 1"
val hs_wf_elts_equal:
#hsz:pos ->
lv:nat{lv <= 32} ->
hs1:hashess #hsz {S.length hs1 = 32} ->
hs2:hashess #hsz {S.length hs2 = 32} ->
i:nat ->
j:nat{j >= i} ->
Lemma (requires hs_wf_elts lv hs1 i j /\
S.equal (S.slice hs1 lv 32) (S.slice hs2 lv 32))
(ensures hs_wf_elts lv hs2 i j)
(decreases (32 - lv))
let rec hs_wf_elts_equal #hsz lv hs1 hs2 i j =
if lv = 32 then ()
else (S.slice_slice hs1 lv 32 1 (32 - lv);
S.slice_slice hs2 lv 32 1 (32 - lv);
assert (S.equal (S.slice hs1 (lv + 1) 32)
(S.slice hs2 (lv + 1) 32));
S.lemma_index_slice hs1 lv 32 0;
S.lemma_index_slice hs2 lv 32 0;
assert (S.index hs1 lv == S.index hs2 lv);
hs_wf_elts_equal (lv + 1) hs1 hs2 (i / 2) (j / 2))
val mt_wf_elts (#hsz:pos): merkle_tree #hsz -> GTot Type0
let mt_wf_elts #_ (MT i j hs _ _ _ _) =
hs_wf_elts 0 hs i j
/// Construction
val hs_wf_elts_empty:
#hsz:pos ->
lv:nat{lv <= 32} ->
Lemma (requires True)
(ensures hs_wf_elts #hsz lv (S.create 32 S.empty) 0 0)
(decreases (32 - lv))
let rec hs_wf_elts_empty #hsz lv =
if lv = 32 then ()
else hs_wf_elts_empty #hsz (lv + 1)
// NOTE: the public function is `create_mt` defined below, which
// builds a tree with an initial hash.
noextract inline_for_extraction
val create_empty_mt (#hsz:pos) (#f:MTS.hash_fun_t #hsz): unit -> GTot (mt:merkle_tree #hsz {mt_wf_elts #hsz mt})
let create_empty_mt #hsz #f _ =
hs_wf_elts_empty #hsz 0;
MT 0 0 (S.create 32 S.empty) false (S.create 32 (hash_init #hsz)) (hash_init #hsz) f
/// Insertion
val hashess_insert:
#hsz:pos ->
lv:nat{lv < 32} ->
i:nat ->
j:nat{i <= j /\ j < pow2 (32 - lv) - 1} ->
hs:hashess #hsz {S.length hs = 32 /\ hs_wf_elts lv hs i j} ->
v:hash #hsz ->
GTot (ihs:hashess #hsz {S.length ihs = 32 /\ hs_wf_elts (lv + 1) ihs (i / 2) (j / 2)})
let hashess_insert #hsz lv i j hs v =
let ihs = S.upd hs lv (S.snoc (S.index hs lv) v) in
hs_wf_elts_equal (lv + 1) hs ihs (i / 2) (j / 2);
ihs
val insert_:
#hsz:pos -> #f:MTS.hash_fun_t #hsz ->
lv:nat{lv < 32} ->
i:nat ->
j:nat{i <= j /\ j < pow2 (32 - lv) - 1} ->
hs:hashess #hsz {S.length hs = 32 /\ hs_wf_elts lv hs i j} ->
acc:hash #hsz ->
GTot (ihs:hashess #hsz {
S.length ihs = 32 /\
hs_wf_elts #hsz lv ihs i (j + 1) /\
S.equal (S.slice hs 0 lv) (S.slice ihs 0 lv)})
(decreases j)
let rec insert_ #hsz #f lv i j hs acc =
let ihs = hashess_insert #hsz lv i j hs acc in
assert (S.equal (S.slice hs 0 lv) (S.slice ihs 0 lv));
if j % 2 = 1 // S.length (S.index hs lv) > 0
then begin
remainder_2_1_div j;
let nacc = f (S.last (S.index hs lv)) acc in
let rihs = insert_ #hsz #f (lv + 1) (i / 2) (j / 2) ihs nacc in
assert (hs_wf_elts #hsz (lv + 1) rihs (i / 2) (j / 2 + 1));
assert (S.equal (S.slice ihs 0 (lv + 1)) (S.slice rihs 0 (lv + 1)));
assert (S.index ihs lv == S.index rihs lv);
assert (S.length (S.index rihs lv) = (j + 1) - offset_of i);
assert (S.equal (S.slice ihs 0 (lv + 1)) (S.slice rihs 0 (lv + 1)));
assert (S.equal (S.slice ihs 0 lv) (S.slice rihs 0 lv));
rihs
end
else ihs
val insert_base:
#hsz:pos -> #f:MTS.hash_fun_t #hsz ->
lv:nat -> i:nat -> j:nat -> hs:hashess #hsz -> acc:hash #hsz ->
Lemma (requires
lv < 32 /\ i <= j /\ j < pow2 (32 - lv) - 1 /\
S.length hs = 32 /\ hs_wf_elts lv hs i j /\
j % 2 <> 1)
(ensures S.equal (insert_ #_ #f lv i j hs acc)
(hashess_insert lv i j hs acc))
let insert_base #_ #_ lv i j hs acc = ()
val insert_rec:
#hsz:pos -> #f:MTS.hash_fun_t #hsz ->
lv:nat -> i:nat -> j:nat -> hs:hashess -> acc:hash ->
Lemma (requires
lv < 32 /\ i <= j /\ j < pow2 (32 - lv) - 1 /\
S.length hs = 32 /\ hs_wf_elts lv hs i j /\
j % 2 == 1)
(ensures
(hs_wf_elts_equal (lv + 1) hs
(hashess_insert lv i j hs acc) (i / 2) (j / 2);
S.equal (insert_ #_ #f lv i j hs acc)
(insert_ #_ #f (lv + 1) (i / 2) (j / 2)
(hashess_insert lv i j hs acc)
(f (S.last (S.index hs lv)) acc))))
let insert_rec #_ #_ lv i j hs acc = ()
val mt_insert:
#hsz:pos ->
mt:merkle_tree #hsz {mt_wf_elts mt /\ mt_not_full mt} -> v:hash #hsz ->
GTot (imt:merkle_tree #hsz{mt_wf_elts #hsz imt})
let mt_insert #hsz mt v =
MT (MT?.i mt)
(MT?.j mt + 1)
(insert_ #_ #(MT?.hash_fun mt) 0 (MT?.i mt) (MT?.j mt) (MT?.hs mt) v)
false
(MT?.rhs mt)
(MT?.mroot mt)
(MT?.hash_fun mt)
val mt_create:
hsz:pos -> f:MTS.hash_fun_t #hsz ->
init:hash #hsz -> GTot (mt:merkle_tree{mt_wf_elts #hsz mt})
let mt_create hsz f init =
mt_insert #_ (create_empty_mt #_ #f ()) init
/// Getting the Merkle root and path
type path (#hsz:pos) = S.seq (hash #hsz)
// Construct the rightmost hashes for a given (incomplete) Merkle tree.
// This function calculates the Merkle root as well, which is the final
// accumulator value.
val construct_rhs:
#hsz:pos -> #f:MTS.hash_fun_t #hsz ->
lv:nat{lv <= 32} ->
hs:hashess #hsz {S.length hs = 32} ->
rhs:hashes #hsz {S.length rhs = 32} ->
i:nat ->
j:nat{
i <= j /\ j < pow2 (32 - lv) /\
hs_wf_elts #hsz lv hs i j} ->
acc:hash #hsz ->
actd:bool ->
GTot (crhs:hashes #hsz {S.length crhs = 32} * (hash #hsz)) | false | false | MerkleTree.New.High.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 1,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 10,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val construct_rhs:
#hsz:pos -> #f:MTS.hash_fun_t #hsz ->
lv:nat{lv <= 32} ->
hs:hashess #hsz {S.length hs = 32} ->
rhs:hashes #hsz {S.length rhs = 32} ->
i:nat ->
j:nat{
i <= j /\ j < pow2 (32 - lv) /\
hs_wf_elts #hsz lv hs i j} ->
acc:hash #hsz ->
actd:bool ->
GTot (crhs:hashes #hsz {S.length crhs = 32} * (hash #hsz))
(decreases j) | [
"recursion"
] | MerkleTree.New.High.construct_rhs | {
"file_name": "src/MerkleTree.New.High.fst",
"git_rev": "3b0f086655c145aa23f58a97259ebf4cf112a4a3",
"git_url": "https://github.com/hacl-star/merkle-tree.git",
"project_name": "merkle-tree"
} |
lv: Prims.nat{lv <= 32} ->
hs: MerkleTree.New.High.hashess{FStar.Seq.Base.length hs = 32} ->
rhs: MerkleTree.New.High.hashes{FStar.Seq.Base.length rhs = 32} ->
i: Prims.nat ->
j: Prims.nat{i <= j /\ j < Prims.pow2 (32 - lv) /\ MerkleTree.New.High.hs_wf_elts lv hs i j} ->
acc: MerkleTree.New.High.hash ->
actd: Prims.bool
-> Prims.GTot
(crhs: MerkleTree.New.High.hashes{FStar.Seq.Base.length crhs = 32} * MerkleTree.New.High.hash) | {
"end_col": 73,
"end_line": 279,
"start_col": 54,
"start_line": 269
} |
FStar.Pervasives.Lemma | val mt_get_path_slice:
#hsz:pos ->
lv:nat{lv <= 32} ->
hs:hashess #hsz {S.length hs = 32} ->
rhs:hashes #hsz {S.length rhs = 32} ->
i:nat ->
j:nat{
i <= j /\ j < pow2 (32 - lv) /\
hs_wf_elts lv hs i j} ->
k:nat{i <= k && k <= j} ->
p:path #hsz ->
actd:bool ->
Lemma (requires True)
(ensures S.equal (S.slice (mt_get_path_ lv hs rhs i j k p actd)
(S.length p) (S.length p + mt_path_length k j actd))
(mt_get_path_ lv hs rhs i j k S.empty actd))
(decreases (32 - lv)) | [
{
"abbrev": true,
"full_module": "MerkleTree.Spec",
"short_module": "MTS"
},
{
"abbrev": true,
"full_module": "FStar.UInt8",
"short_module": "U8"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "S"
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Ghost",
"short_module": null
},
{
"abbrev": false,
"full_module": "MerkleTree.New",
"short_module": null
},
{
"abbrev": false,
"full_module": "MerkleTree.New",
"short_module": null
},
{
"abbrev": 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 mt_get_path_slice #hsz lv hs rhs i j k p actd =
mt_get_path_pull lv hs rhs i j k p actd | val mt_get_path_slice:
#hsz:pos ->
lv:nat{lv <= 32} ->
hs:hashess #hsz {S.length hs = 32} ->
rhs:hashes #hsz {S.length rhs = 32} ->
i:nat ->
j:nat{
i <= j /\ j < pow2 (32 - lv) /\
hs_wf_elts lv hs i j} ->
k:nat{i <= k && k <= j} ->
p:path #hsz ->
actd:bool ->
Lemma (requires True)
(ensures S.equal (S.slice (mt_get_path_ lv hs rhs i j k p actd)
(S.length p) (S.length p + mt_path_length k j actd))
(mt_get_path_ lv hs rhs i j k S.empty actd))
(decreases (32 - lv))
let mt_get_path_slice #hsz lv hs rhs i j k p actd = | false | null | true | mt_get_path_pull lv hs rhs i j k p actd | {
"checked_file": "MerkleTree.New.High.fst.checked",
"dependencies": [
"Spec.Hash.Definitions.fst.checked",
"prims.fst.checked",
"MerkleTree.Spec.fst.checked",
"Lib.IntTypes.fsti.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "MerkleTree.New.High.fst"
} | [
"lemma",
""
] | [
"Prims.pos",
"Prims.nat",
"Prims.b2t",
"Prims.op_LessThanOrEqual",
"MerkleTree.New.High.hashess",
"Prims.op_Equality",
"Prims.int",
"FStar.Seq.Base.length",
"MerkleTree.New.High.hashes",
"MerkleTree.New.High.hash",
"Prims.l_and",
"Prims.op_LessThan",
"Prims.pow2",
"Prims.op_Subtraction",
"MerkleTree.New.High.hs_wf_elts",
"Prims.op_AmpAmp",
"MerkleTree.New.High.path",
"Prims.bool",
"MerkleTree.New.High.mt_get_path_pull",
"Prims.unit"
] | [] | module MerkleTree.New.High
open FStar.Ghost
open FStar.Seq
module S = FStar.Seq
module U32 = FStar.UInt32
module U8 = FStar.UInt8
module MTS = MerkleTree.Spec
#set-options "--z3rlimit 10 --max_fuel 0 --max_ifuel 0"
type uint32_t = U32.t
type uint8_t = U8.t
type hash (#hsz:pos) = b:Spec.Hash.Definitions.bytes{Seq.length b = hsz}
type hashes (#hsz:pos) = S.seq (hash #hsz)
type hashess (#hsz:pos) = S.seq (hashes #hsz)
noextract
let hash_init (#hsz:pos): hash #hsz =
Seq.create hsz (Lib.IntTypes.u8 0)
val sha256_compress: src1:hash #32 -> src2:hash #32 -> GTot (hash #32)
let sha256_compress = MTS.sha256_compress
/// Facts about sequences
val seq_slice_equal_index:
#a:Type -> s1:S.seq a -> s2:S.seq a ->
i:nat -> j:nat{i <= j && j <= S.length s1 && j <= S.length s2} ->
k:nat{i <= k && k < j} ->
Lemma (requires S.equal (S.slice s1 i j) (S.slice s2 i j))
(ensures S.index s1 k == S.index s2 k)
[SMTPat (S.equal (S.slice s1 i j) (S.slice s2 i j));
SMTPat (S.index s1 k)]
let seq_slice_equal_index #a s1 s2 i j k =
assert (S.index (S.slice s1 i j) (k - i) == S.index (S.slice s2 i j) (k - i))
private val seq_slice_more_equal:
#a:Type -> s1:S.seq a -> s2:S.seq a ->
n:nat -> m:nat{n <= m && m <= S.length s1 && m <= S.length s2} ->
k:nat{n <= k} -> l:nat{k <= l && l <= m} ->
Lemma (requires S.equal (S.slice s1 n m) (S.slice s2 n m))
(ensures S.equal (S.slice s1 k l) (S.slice s2 k l))
[SMTPat (S.equal (S.slice s1 n m) (S.slice s2 n m));
SMTPat (S.equal (S.slice s1 k l) (S.slice s2 k l))]
private let seq_slice_more_equal #a s1 s2 n m k l =
slice_slice s1 n m (k - n) (l - n);
slice_slice s2 n m (k - n) (l - n)
/// Facts about "2"
val remainder_2_not_1_div: n:nat ->
Lemma (requires n % 2 <> 1)
(ensures n / 2 = (n + 1) / 2)
let remainder_2_not_1_div n = ()
val remainder_2_1_div: n:nat ->
Lemma (requires n % 2 = 1)
(ensures n / 2 + 1 = (n + 1) / 2)
let remainder_2_1_div n = ()
/// High-level Merkle tree data structure
noeq type merkle_tree (#hsz:pos) =
| MT: i:nat ->
j:nat{i <= j && j < pow2 32} ->
hs:hashess #hsz {S.length hs = 32} ->
rhs_ok:bool ->
rhs:hashes #hsz {S.length rhs = 32} -> // Rightmost hashes
mroot:hash #hsz ->
hash_fun:MTS.hash_fun_t #hsz ->
merkle_tree #hsz
val mt_not_full (#hsz:pos): merkle_tree #hsz -> GTot bool
let mt_not_full #hsz mt =
MT?.j mt < pow2 32 - 1
val mt_empty (#hsz:pos): merkle_tree #hsz -> GTot bool
let mt_empty #hsz mt =
MT?.j mt = 0
val mt_not_empty (#hsz:pos): merkle_tree #hsz -> GTot bool
let mt_not_empty #hsz mt =
MT?.j mt > 0
/// Well-formedness w.r.t. indices of base hash elements
noextract
val offset_of: i:nat -> Tot nat
let offset_of i =
if i % 2 = 0 then i else i - 1
val hs_wf_elts:
#hsz:pos ->
lv:nat{lv <= 32} ->
hs:hashess #hsz {S.length hs = 32} ->
i:nat -> j:nat{j >= i} ->
GTot Type0 (decreases (32 - lv))
let rec hs_wf_elts #hsz lv hs i j =
if lv = 32 then true
else (let ofs = offset_of i in
S.length (S.index hs lv) == j - ofs /\
hs_wf_elts #hsz (lv + 1) hs (i / 2) (j / 2))
#push-options "--max_fuel 1"
val hs_wf_elts_equal:
#hsz:pos ->
lv:nat{lv <= 32} ->
hs1:hashess #hsz {S.length hs1 = 32} ->
hs2:hashess #hsz {S.length hs2 = 32} ->
i:nat ->
j:nat{j >= i} ->
Lemma (requires hs_wf_elts lv hs1 i j /\
S.equal (S.slice hs1 lv 32) (S.slice hs2 lv 32))
(ensures hs_wf_elts lv hs2 i j)
(decreases (32 - lv))
let rec hs_wf_elts_equal #hsz lv hs1 hs2 i j =
if lv = 32 then ()
else (S.slice_slice hs1 lv 32 1 (32 - lv);
S.slice_slice hs2 lv 32 1 (32 - lv);
assert (S.equal (S.slice hs1 (lv + 1) 32)
(S.slice hs2 (lv + 1) 32));
S.lemma_index_slice hs1 lv 32 0;
S.lemma_index_slice hs2 lv 32 0;
assert (S.index hs1 lv == S.index hs2 lv);
hs_wf_elts_equal (lv + 1) hs1 hs2 (i / 2) (j / 2))
val mt_wf_elts (#hsz:pos): merkle_tree #hsz -> GTot Type0
let mt_wf_elts #_ (MT i j hs _ _ _ _) =
hs_wf_elts 0 hs i j
/// Construction
val hs_wf_elts_empty:
#hsz:pos ->
lv:nat{lv <= 32} ->
Lemma (requires True)
(ensures hs_wf_elts #hsz lv (S.create 32 S.empty) 0 0)
(decreases (32 - lv))
let rec hs_wf_elts_empty #hsz lv =
if lv = 32 then ()
else hs_wf_elts_empty #hsz (lv + 1)
// NOTE: the public function is `create_mt` defined below, which
// builds a tree with an initial hash.
noextract inline_for_extraction
val create_empty_mt (#hsz:pos) (#f:MTS.hash_fun_t #hsz): unit -> GTot (mt:merkle_tree #hsz {mt_wf_elts #hsz mt})
let create_empty_mt #hsz #f _ =
hs_wf_elts_empty #hsz 0;
MT 0 0 (S.create 32 S.empty) false (S.create 32 (hash_init #hsz)) (hash_init #hsz) f
/// Insertion
val hashess_insert:
#hsz:pos ->
lv:nat{lv < 32} ->
i:nat ->
j:nat{i <= j /\ j < pow2 (32 - lv) - 1} ->
hs:hashess #hsz {S.length hs = 32 /\ hs_wf_elts lv hs i j} ->
v:hash #hsz ->
GTot (ihs:hashess #hsz {S.length ihs = 32 /\ hs_wf_elts (lv + 1) ihs (i / 2) (j / 2)})
let hashess_insert #hsz lv i j hs v =
let ihs = S.upd hs lv (S.snoc (S.index hs lv) v) in
hs_wf_elts_equal (lv + 1) hs ihs (i / 2) (j / 2);
ihs
val insert_:
#hsz:pos -> #f:MTS.hash_fun_t #hsz ->
lv:nat{lv < 32} ->
i:nat ->
j:nat{i <= j /\ j < pow2 (32 - lv) - 1} ->
hs:hashess #hsz {S.length hs = 32 /\ hs_wf_elts lv hs i j} ->
acc:hash #hsz ->
GTot (ihs:hashess #hsz {
S.length ihs = 32 /\
hs_wf_elts #hsz lv ihs i (j + 1) /\
S.equal (S.slice hs 0 lv) (S.slice ihs 0 lv)})
(decreases j)
let rec insert_ #hsz #f lv i j hs acc =
let ihs = hashess_insert #hsz lv i j hs acc in
assert (S.equal (S.slice hs 0 lv) (S.slice ihs 0 lv));
if j % 2 = 1 // S.length (S.index hs lv) > 0
then begin
remainder_2_1_div j;
let nacc = f (S.last (S.index hs lv)) acc in
let rihs = insert_ #hsz #f (lv + 1) (i / 2) (j / 2) ihs nacc in
assert (hs_wf_elts #hsz (lv + 1) rihs (i / 2) (j / 2 + 1));
assert (S.equal (S.slice ihs 0 (lv + 1)) (S.slice rihs 0 (lv + 1)));
assert (S.index ihs lv == S.index rihs lv);
assert (S.length (S.index rihs lv) = (j + 1) - offset_of i);
assert (S.equal (S.slice ihs 0 (lv + 1)) (S.slice rihs 0 (lv + 1)));
assert (S.equal (S.slice ihs 0 lv) (S.slice rihs 0 lv));
rihs
end
else ihs
val insert_base:
#hsz:pos -> #f:MTS.hash_fun_t #hsz ->
lv:nat -> i:nat -> j:nat -> hs:hashess #hsz -> acc:hash #hsz ->
Lemma (requires
lv < 32 /\ i <= j /\ j < pow2 (32 - lv) - 1 /\
S.length hs = 32 /\ hs_wf_elts lv hs i j /\
j % 2 <> 1)
(ensures S.equal (insert_ #_ #f lv i j hs acc)
(hashess_insert lv i j hs acc))
let insert_base #_ #_ lv i j hs acc = ()
val insert_rec:
#hsz:pos -> #f:MTS.hash_fun_t #hsz ->
lv:nat -> i:nat -> j:nat -> hs:hashess -> acc:hash ->
Lemma (requires
lv < 32 /\ i <= j /\ j < pow2 (32 - lv) - 1 /\
S.length hs = 32 /\ hs_wf_elts lv hs i j /\
j % 2 == 1)
(ensures
(hs_wf_elts_equal (lv + 1) hs
(hashess_insert lv i j hs acc) (i / 2) (j / 2);
S.equal (insert_ #_ #f lv i j hs acc)
(insert_ #_ #f (lv + 1) (i / 2) (j / 2)
(hashess_insert lv i j hs acc)
(f (S.last (S.index hs lv)) acc))))
let insert_rec #_ #_ lv i j hs acc = ()
val mt_insert:
#hsz:pos ->
mt:merkle_tree #hsz {mt_wf_elts mt /\ mt_not_full mt} -> v:hash #hsz ->
GTot (imt:merkle_tree #hsz{mt_wf_elts #hsz imt})
let mt_insert #hsz mt v =
MT (MT?.i mt)
(MT?.j mt + 1)
(insert_ #_ #(MT?.hash_fun mt) 0 (MT?.i mt) (MT?.j mt) (MT?.hs mt) v)
false
(MT?.rhs mt)
(MT?.mroot mt)
(MT?.hash_fun mt)
val mt_create:
hsz:pos -> f:MTS.hash_fun_t #hsz ->
init:hash #hsz -> GTot (mt:merkle_tree{mt_wf_elts #hsz mt})
let mt_create hsz f init =
mt_insert #_ (create_empty_mt #_ #f ()) init
/// Getting the Merkle root and path
type path (#hsz:pos) = S.seq (hash #hsz)
// Construct the rightmost hashes for a given (incomplete) Merkle tree.
// This function calculates the Merkle root as well, which is the final
// accumulator value.
val construct_rhs:
#hsz:pos -> #f:MTS.hash_fun_t #hsz ->
lv:nat{lv <= 32} ->
hs:hashess #hsz {S.length hs = 32} ->
rhs:hashes #hsz {S.length rhs = 32} ->
i:nat ->
j:nat{
i <= j /\ j < pow2 (32 - lv) /\
hs_wf_elts #hsz lv hs i j} ->
acc:hash #hsz ->
actd:bool ->
GTot (crhs:hashes #hsz {S.length crhs = 32} * (hash #hsz))
(decreases j)
let rec construct_rhs #hsz #f lv hs rhs i j acc actd =
let ofs = offset_of i in
if j = 0 then (rhs, acc)
else
(if j % 2 = 0
then (construct_rhs #_ #f (lv + 1) hs rhs (i / 2) (j / 2) acc actd)
else (let nrhs = if actd then S.upd rhs lv acc else rhs in
let nacc = if actd
then f (S.index (S.index hs lv) (j - 1 - ofs)) acc
else S.index (S.index hs lv) (j - 1 - ofs) in
construct_rhs #_ #f (lv + 1) hs nrhs (i / 2) (j / 2) nacc true))
val construct_rhs_unchanged:
#hsz:pos -> #f:MTS.hash_fun_t #hsz ->
lv:nat{lv <= 32} ->
hs:hashess #hsz {S.length hs = 32} ->
rhs:hashes #hsz {S.length rhs = 32} ->
i:nat ->
j:nat{
i <= j /\ j < pow2 (32 - lv) /\
hs_wf_elts #hsz lv hs i j} ->
acc:hash #hsz ->
actd:bool ->
Lemma (requires True)
(ensures S.equal (S.slice rhs 0 lv)
(S.slice (fst (construct_rhs #_ #f lv hs rhs i j acc actd)) 0 lv))
(decreases j)
let rec construct_rhs_unchanged #hsz #f lv hs rhs i j acc actd =
let ofs = offset_of i in
if j = 0 then ()
else if j % 2 = 0
then (construct_rhs_unchanged #_ #f (lv + 1) hs rhs (i / 2) (j / 2) acc actd;
let rrhs = fst (construct_rhs #_ #f (lv + 1) hs rhs (i / 2) (j / 2) acc actd) in
assert (S.equal (S.slice rhs 0 lv) (S.slice rrhs 0 lv)))
else (let nrhs = if actd then S.upd rhs lv acc else rhs in
let nacc = if actd
then f (S.index (S.index hs lv) (j - 1 - ofs)) acc
else S.index (S.index hs lv) (j - 1 - ofs) in
construct_rhs_unchanged #_ #f (lv + 1) hs nrhs (i / 2) (j / 2) nacc true;
let rrhs = fst (construct_rhs #_ #f (lv + 1) hs nrhs (i / 2) (j / 2) nacc true) in
assert (S.equal (S.slice nrhs 0 lv) (S.slice rrhs 0 lv));
assert (S.equal (S.slice rhs 0 lv) (S.slice nrhs 0 lv)))
val construct_rhs_even:
#hsz:pos -> #f:MTS.hash_fun_t #hsz ->
lv:nat{lv <= 32} ->
hs:hashess #hsz {S.length hs = 32} ->
rhs:hashes #hsz {S.length rhs = 32} ->
i:nat ->
j:nat{
i <= j /\ j < pow2 (32 - lv) /\
hs_wf_elts #hsz lv hs i j} ->
acc:hash #hsz ->
actd:bool ->
Lemma (requires j <> 0 /\ j % 2 = 0)
(ensures construct_rhs #_ #f lv hs rhs i j acc actd ==
construct_rhs #_ #f (lv + 1) hs rhs (i / 2) (j / 2) acc actd)
let construct_rhs_even #_ #_ _ _ _ _ _ _ _ = ()
val construct_rhs_odd:
#hsz:pos -> #f:MTS.hash_fun_t #hsz ->
lv:nat{lv <= 32} ->
hs:hashess #hsz {S.length hs = 32} ->
rhs:hashes #hsz {S.length rhs = 32} ->
i:nat ->
j:nat{
i <= j /\ j < pow2 (32 - lv) /\
hs_wf_elts lv hs i j} ->
acc:hash ->
actd:bool ->
Lemma (requires j % 2 = 1)
(ensures construct_rhs #_ #f lv hs rhs i j acc actd ==
(let ofs = offset_of i in
let nrhs = if actd then S.upd rhs lv acc else rhs in
let nacc = if actd
then f (S.index (S.index hs lv) (j - 1 - ofs)) acc
else S.index (S.index hs lv) (j - 1 - ofs) in
construct_rhs #_ #f (lv + 1) hs nrhs (i / 2) (j / 2) nacc true))
let construct_rhs_odd #_ #_ _ _ _ _ _ _ _ = ()
val mt_get_root:
#hsz:pos ->
mt:merkle_tree #hsz {mt_wf_elts #hsz mt} -> drt:hash #hsz ->
GTot (merkle_tree #hsz * hash #hsz)
let mt_get_root #hsz mt drt =
if MT?.rhs_ok mt then (mt, MT?.mroot mt)
else begin
let (nrhs, rt) = construct_rhs #_ #(MT?.hash_fun mt) 0 (MT?.hs mt) (MT?.rhs mt) (MT?.i mt) (MT?.j mt) drt false in
(MT (MT?.i mt) (MT?.j mt) (MT?.hs mt) true nrhs rt (MT?.hash_fun mt), rt)
end
val mt_get_root_rhs_ok_true:
#hsz:pos ->
mt:merkle_tree #hsz {mt_wf_elts mt} -> drt:hash #hsz ->
Lemma (requires MT?.rhs_ok mt == true)
(ensures mt_get_root #hsz mt drt == (mt, MT?.mroot mt))
let mt_get_root_rhs_ok_true #hsz mt drt = ()
val mt_get_root_rhs_ok_false:
#hsz:pos ->
mt:merkle_tree #hsz {mt_wf_elts mt} -> drt:hash ->
Lemma (requires MT?.rhs_ok mt == false)
(ensures mt_get_root mt drt ==
(let (nrhs, rt) =
construct_rhs #_ #(MT?.hash_fun mt)
0 (MT?.hs mt) (MT?.rhs mt) (MT?.i mt) (MT?.j mt)
drt false in
(MT (MT?.i mt) (MT?.j mt) (MT?.hs mt) true nrhs rt (MT?.hash_fun mt), rt)))
let mt_get_root_rhs_ok_false #_ _ _ = ()
val path_insert: (#hsz:pos) -> p:path #hsz -> hp:hash #hsz -> GTot (path #hsz)
let path_insert #_ p hp = S.snoc p hp
val mt_path_length_step:
k:nat -> j:nat{k <= j} -> actd:bool -> GTot nat
let mt_path_length_step k j actd =
if j = 0 then 0
else (if k % 2 = 0
then (if j = k || (j = k + 1 && not actd) then 0 else 1)
else 1)
val mt_path_length:
k:nat -> j:nat{k <= j} -> actd:bool -> GTot nat
let rec mt_path_length k j actd =
if j = 0 then 0
else (let nactd = actd || (j % 2 = 1) in
mt_path_length_step k j actd +
mt_path_length (k / 2) (j / 2) nactd)
val mt_make_path_step:
#hsz:pos ->
lv:nat{lv <= 32} ->
hs:hashess #hsz {S.length hs = 32} ->
rhs:hashes #hsz {S.length rhs = 32} ->
i:nat ->
j:nat{
j <> 0 /\ i <= j /\ j < pow2 (32 - lv) /\
hs_wf_elts lv hs i j} ->
k:nat{i <= k && k <= j} ->
p:path #hsz ->
actd:bool ->
GTot (path #hsz)
let mt_make_path_step #hsz lv hs rhs i j k p actd =
let ofs = offset_of i in
if k % 2 = 1
then path_insert p (S.index (S.index hs lv) (k - 1 - ofs))
else (if k = j then p
else if k + 1 = j
then (if actd
then path_insert p (S.index rhs lv)
else p)
else path_insert p (S.index (S.index hs lv) (k + 1 - ofs)))
// Construct a Merkle path for a given index `k`, hashes `hs`,
// and rightmost hashes `rhs`.
val mt_get_path_:
#hsz:pos ->
lv:nat{lv <= 32} ->
hs:hashess #hsz {S.length hs = 32} ->
rhs:hashes #hsz {S.length rhs = 32} ->
i:nat ->
j:nat{
i <= j /\ j < pow2 (32 - lv) /\
hs_wf_elts lv hs i j} ->
k:nat{i <= k && k <= j} ->
p:path #hsz ->
actd:bool ->
GTot (np:path #hsz {S.length np = S.length p + mt_path_length k j actd})
(decreases (32 - lv))
let rec mt_get_path_ #hsz lv hs rhs i j k p actd =
let ofs = offset_of i in
if j = 0 then p
else
(let np = mt_make_path_step lv hs rhs i j k p actd in
mt_get_path_ (lv + 1) hs rhs (i / 2) (j / 2) (k / 2) np
(if j % 2 = 0 then actd else true))
val mt_get_path_unchanged:
#hsz:pos ->
lv:nat{lv <= 32} ->
hs:hashess #hsz {S.length hs = 32} ->
rhs:hashes #hsz {S.length rhs = 32} ->
i:nat ->
j:nat{
i <= j /\ j < pow2 (32 - lv) /\
hs_wf_elts #hsz lv hs i j} ->
k:nat{i <= k && k <= j} ->
p:path #hsz ->
actd:bool ->
Lemma (requires True)
(ensures S.equal p (S.slice (mt_get_path_ lv hs rhs i j k p actd)
0 (S.length p)))
(decreases (32 - lv))
let rec mt_get_path_unchanged #hsz lv hs rhs i j k p actd =
let ofs = offset_of i in
if j = 0 then ()
else
(let np = mt_make_path_step lv hs rhs i j k p actd in
assert (S.equal p (S.slice np 0 (S.length p)));
mt_get_path_unchanged (lv + 1) hs rhs (i / 2) (j / 2) (k / 2) np
(if j % 2 = 0 then actd else true))
#push-options "--z3rlimit 20"
val mt_get_path_pull:
#hsz:pos ->
lv:nat{lv <= 32} ->
hs:hashess #hsz {S.length hs = 32} ->
rhs:hashes #hsz {S.length rhs = 32} ->
i:nat ->
j:nat{
i <= j /\ j < pow2 (32 - lv) /\
hs_wf_elts lv hs i j} ->
k:nat{i <= k && k <= j} ->
p:path #hsz ->
actd:bool ->
Lemma (requires True)
(ensures S.equal (mt_get_path_ lv hs rhs i j k p actd)
(S.append p (mt_get_path_ lv hs rhs i j k S.empty actd)))
(decreases (32 - lv))
let rec mt_get_path_pull #hsz lv hs rhs i j k p actd =
let ofs = offset_of i in
if j = 0 then ()
else
(let np = mt_make_path_step lv hs rhs i j k p actd in
let nactd = if j % 2 = 0 then actd else true in
mt_get_path_pull (lv + 1) hs rhs (i / 2) (j / 2) (k / 2) np nactd;
mt_get_path_pull (lv + 1) hs rhs (i / 2) (j / 2) (k / 2)
(mt_make_path_step lv hs rhs i j k S.empty actd) nactd)
#pop-options
val mt_get_path_slice:
#hsz:pos ->
lv:nat{lv <= 32} ->
hs:hashess #hsz {S.length hs = 32} ->
rhs:hashes #hsz {S.length rhs = 32} ->
i:nat ->
j:nat{
i <= j /\ j < pow2 (32 - lv) /\
hs_wf_elts lv hs i j} ->
k:nat{i <= k && k <= j} ->
p:path #hsz ->
actd:bool ->
Lemma (requires True)
(ensures S.equal (S.slice (mt_get_path_ lv hs rhs i j k p actd)
(S.length p) (S.length p + mt_path_length k j actd))
(mt_get_path_ lv hs rhs i j k S.empty actd))
(decreases (32 - lv)) | false | false | MerkleTree.New.High.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 1,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 10,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val mt_get_path_slice:
#hsz:pos ->
lv:nat{lv <= 32} ->
hs:hashess #hsz {S.length hs = 32} ->
rhs:hashes #hsz {S.length rhs = 32} ->
i:nat ->
j:nat{
i <= j /\ j < pow2 (32 - lv) /\
hs_wf_elts lv hs i j} ->
k:nat{i <= k && k <= j} ->
p:path #hsz ->
actd:bool ->
Lemma (requires True)
(ensures S.equal (S.slice (mt_get_path_ lv hs rhs i j k p actd)
(S.length p) (S.length p + mt_path_length k j actd))
(mt_get_path_ lv hs rhs i j k S.empty actd))
(decreases (32 - lv)) | [] | MerkleTree.New.High.mt_get_path_slice | {
"file_name": "src/MerkleTree.New.High.fst",
"git_rev": "3b0f086655c145aa23f58a97259ebf4cf112a4a3",
"git_url": "https://github.com/hacl-star/merkle-tree.git",
"project_name": "merkle-tree"
} |
lv: Prims.nat{lv <= 32} ->
hs: MerkleTree.New.High.hashess{FStar.Seq.Base.length hs = 32} ->
rhs: MerkleTree.New.High.hashes{FStar.Seq.Base.length rhs = 32} ->
i: Prims.nat ->
j: Prims.nat{i <= j /\ j < Prims.pow2 (32 - lv) /\ MerkleTree.New.High.hs_wf_elts lv hs i j} ->
k: Prims.nat{i <= k && k <= j} ->
p: MerkleTree.New.High.path ->
actd: Prims.bool
-> FStar.Pervasives.Lemma
(ensures
FStar.Seq.Base.equal (FStar.Seq.Base.slice (MerkleTree.New.High.mt_get_path_ lv
hs
rhs
i
j
k
p
actd)
(FStar.Seq.Base.length p)
(FStar.Seq.Base.length p + MerkleTree.New.High.mt_path_length k j actd))
(MerkleTree.New.High.mt_get_path_ lv hs rhs i j k FStar.Seq.Base.empty actd))
(decreases 32 - lv) | {
"end_col": 41,
"end_line": 519,
"start_col": 2,
"start_line": 519
} |
Prims.GTot | val mt_get_path:
#hsz:pos ->
mt:merkle_tree #hsz {mt_wf_elts mt} ->
idx:nat{MT?.i mt <= idx /\ idx < MT?.j mt} ->
drt:hash #hsz ->
GTot (nat *
(np:path #hsz {S.length np = 1 + mt_path_length idx (MT?.j mt) false}) *
hash #hsz) | [
{
"abbrev": true,
"full_module": "MerkleTree.Spec",
"short_module": "MTS"
},
{
"abbrev": true,
"full_module": "FStar.UInt8",
"short_module": "U8"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "S"
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Ghost",
"short_module": null
},
{
"abbrev": false,
"full_module": "MerkleTree.New",
"short_module": null
},
{
"abbrev": false,
"full_module": "MerkleTree.New",
"short_module": null
},
{
"abbrev": 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 mt_get_path #hsz mt idx drt =
let (umt, root) = mt_get_root mt drt in
let ofs = offset_of (MT?.i umt) in
let np = path_insert S.empty (S.index (S.index (MT?.hs umt) 0) (idx - ofs)) in
MT?.j umt,
mt_get_path_ 0 (MT?.hs umt) (MT?.rhs umt)
(MT?.i umt) (MT?.j umt) idx np false,
root | val mt_get_path:
#hsz:pos ->
mt:merkle_tree #hsz {mt_wf_elts mt} ->
idx:nat{MT?.i mt <= idx /\ idx < MT?.j mt} ->
drt:hash #hsz ->
GTot (nat *
(np:path #hsz {S.length np = 1 + mt_path_length idx (MT?.j mt) false}) *
hash #hsz)
let mt_get_path #hsz mt idx drt = | false | null | false | let umt, root = mt_get_root mt drt in
let ofs = offset_of (MT?.i umt) in
let np = path_insert S.empty (S.index (S.index (MT?.hs umt) 0) (idx - ofs)) in
MT?.j umt, mt_get_path_ 0 (MT?.hs umt) (MT?.rhs umt) (MT?.i umt) (MT?.j umt) idx np false, root | {
"checked_file": "MerkleTree.New.High.fst.checked",
"dependencies": [
"Spec.Hash.Definitions.fst.checked",
"prims.fst.checked",
"MerkleTree.Spec.fst.checked",
"Lib.IntTypes.fsti.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "MerkleTree.New.High.fst"
} | [
"sometrivial"
] | [
"Prims.pos",
"MerkleTree.New.High.merkle_tree",
"MerkleTree.New.High.mt_wf_elts",
"Prims.nat",
"Prims.l_and",
"Prims.b2t",
"Prims.op_LessThanOrEqual",
"MerkleTree.New.High.__proj__MT__item__i",
"Prims.op_LessThan",
"MerkleTree.New.High.__proj__MT__item__j",
"MerkleTree.New.High.hash",
"FStar.Pervasives.Native.Mktuple3",
"MerkleTree.New.High.path",
"Prims.op_Equality",
"Prims.int",
"FStar.Seq.Base.length",
"Prims.op_Addition",
"MerkleTree.New.High.mt_path_length",
"MerkleTree.New.High.mt_get_path_",
"MerkleTree.New.High.__proj__MT__item__hs",
"MerkleTree.New.High.__proj__MT__item__rhs",
"MerkleTree.New.High.path_insert",
"FStar.Seq.Base.empty",
"FStar.Seq.Base.index",
"MerkleTree.New.High.hashes",
"Prims.op_Subtraction",
"MerkleTree.New.High.offset_of",
"FStar.Pervasives.Native.tuple3",
"FStar.Pervasives.Native.tuple2",
"MerkleTree.New.High.mt_get_root"
] | [] | module MerkleTree.New.High
open FStar.Ghost
open FStar.Seq
module S = FStar.Seq
module U32 = FStar.UInt32
module U8 = FStar.UInt8
module MTS = MerkleTree.Spec
#set-options "--z3rlimit 10 --max_fuel 0 --max_ifuel 0"
type uint32_t = U32.t
type uint8_t = U8.t
type hash (#hsz:pos) = b:Spec.Hash.Definitions.bytes{Seq.length b = hsz}
type hashes (#hsz:pos) = S.seq (hash #hsz)
type hashess (#hsz:pos) = S.seq (hashes #hsz)
noextract
let hash_init (#hsz:pos): hash #hsz =
Seq.create hsz (Lib.IntTypes.u8 0)
val sha256_compress: src1:hash #32 -> src2:hash #32 -> GTot (hash #32)
let sha256_compress = MTS.sha256_compress
/// Facts about sequences
val seq_slice_equal_index:
#a:Type -> s1:S.seq a -> s2:S.seq a ->
i:nat -> j:nat{i <= j && j <= S.length s1 && j <= S.length s2} ->
k:nat{i <= k && k < j} ->
Lemma (requires S.equal (S.slice s1 i j) (S.slice s2 i j))
(ensures S.index s1 k == S.index s2 k)
[SMTPat (S.equal (S.slice s1 i j) (S.slice s2 i j));
SMTPat (S.index s1 k)]
let seq_slice_equal_index #a s1 s2 i j k =
assert (S.index (S.slice s1 i j) (k - i) == S.index (S.slice s2 i j) (k - i))
private val seq_slice_more_equal:
#a:Type -> s1:S.seq a -> s2:S.seq a ->
n:nat -> m:nat{n <= m && m <= S.length s1 && m <= S.length s2} ->
k:nat{n <= k} -> l:nat{k <= l && l <= m} ->
Lemma (requires S.equal (S.slice s1 n m) (S.slice s2 n m))
(ensures S.equal (S.slice s1 k l) (S.slice s2 k l))
[SMTPat (S.equal (S.slice s1 n m) (S.slice s2 n m));
SMTPat (S.equal (S.slice s1 k l) (S.slice s2 k l))]
private let seq_slice_more_equal #a s1 s2 n m k l =
slice_slice s1 n m (k - n) (l - n);
slice_slice s2 n m (k - n) (l - n)
/// Facts about "2"
val remainder_2_not_1_div: n:nat ->
Lemma (requires n % 2 <> 1)
(ensures n / 2 = (n + 1) / 2)
let remainder_2_not_1_div n = ()
val remainder_2_1_div: n:nat ->
Lemma (requires n % 2 = 1)
(ensures n / 2 + 1 = (n + 1) / 2)
let remainder_2_1_div n = ()
/// High-level Merkle tree data structure
noeq type merkle_tree (#hsz:pos) =
| MT: i:nat ->
j:nat{i <= j && j < pow2 32} ->
hs:hashess #hsz {S.length hs = 32} ->
rhs_ok:bool ->
rhs:hashes #hsz {S.length rhs = 32} -> // Rightmost hashes
mroot:hash #hsz ->
hash_fun:MTS.hash_fun_t #hsz ->
merkle_tree #hsz
val mt_not_full (#hsz:pos): merkle_tree #hsz -> GTot bool
let mt_not_full #hsz mt =
MT?.j mt < pow2 32 - 1
val mt_empty (#hsz:pos): merkle_tree #hsz -> GTot bool
let mt_empty #hsz mt =
MT?.j mt = 0
val mt_not_empty (#hsz:pos): merkle_tree #hsz -> GTot bool
let mt_not_empty #hsz mt =
MT?.j mt > 0
/// Well-formedness w.r.t. indices of base hash elements
noextract
val offset_of: i:nat -> Tot nat
let offset_of i =
if i % 2 = 0 then i else i - 1
val hs_wf_elts:
#hsz:pos ->
lv:nat{lv <= 32} ->
hs:hashess #hsz {S.length hs = 32} ->
i:nat -> j:nat{j >= i} ->
GTot Type0 (decreases (32 - lv))
let rec hs_wf_elts #hsz lv hs i j =
if lv = 32 then true
else (let ofs = offset_of i in
S.length (S.index hs lv) == j - ofs /\
hs_wf_elts #hsz (lv + 1) hs (i / 2) (j / 2))
#push-options "--max_fuel 1"
val hs_wf_elts_equal:
#hsz:pos ->
lv:nat{lv <= 32} ->
hs1:hashess #hsz {S.length hs1 = 32} ->
hs2:hashess #hsz {S.length hs2 = 32} ->
i:nat ->
j:nat{j >= i} ->
Lemma (requires hs_wf_elts lv hs1 i j /\
S.equal (S.slice hs1 lv 32) (S.slice hs2 lv 32))
(ensures hs_wf_elts lv hs2 i j)
(decreases (32 - lv))
let rec hs_wf_elts_equal #hsz lv hs1 hs2 i j =
if lv = 32 then ()
else (S.slice_slice hs1 lv 32 1 (32 - lv);
S.slice_slice hs2 lv 32 1 (32 - lv);
assert (S.equal (S.slice hs1 (lv + 1) 32)
(S.slice hs2 (lv + 1) 32));
S.lemma_index_slice hs1 lv 32 0;
S.lemma_index_slice hs2 lv 32 0;
assert (S.index hs1 lv == S.index hs2 lv);
hs_wf_elts_equal (lv + 1) hs1 hs2 (i / 2) (j / 2))
val mt_wf_elts (#hsz:pos): merkle_tree #hsz -> GTot Type0
let mt_wf_elts #_ (MT i j hs _ _ _ _) =
hs_wf_elts 0 hs i j
/// Construction
val hs_wf_elts_empty:
#hsz:pos ->
lv:nat{lv <= 32} ->
Lemma (requires True)
(ensures hs_wf_elts #hsz lv (S.create 32 S.empty) 0 0)
(decreases (32 - lv))
let rec hs_wf_elts_empty #hsz lv =
if lv = 32 then ()
else hs_wf_elts_empty #hsz (lv + 1)
// NOTE: the public function is `create_mt` defined below, which
// builds a tree with an initial hash.
noextract inline_for_extraction
val create_empty_mt (#hsz:pos) (#f:MTS.hash_fun_t #hsz): unit -> GTot (mt:merkle_tree #hsz {mt_wf_elts #hsz mt})
let create_empty_mt #hsz #f _ =
hs_wf_elts_empty #hsz 0;
MT 0 0 (S.create 32 S.empty) false (S.create 32 (hash_init #hsz)) (hash_init #hsz) f
/// Insertion
val hashess_insert:
#hsz:pos ->
lv:nat{lv < 32} ->
i:nat ->
j:nat{i <= j /\ j < pow2 (32 - lv) - 1} ->
hs:hashess #hsz {S.length hs = 32 /\ hs_wf_elts lv hs i j} ->
v:hash #hsz ->
GTot (ihs:hashess #hsz {S.length ihs = 32 /\ hs_wf_elts (lv + 1) ihs (i / 2) (j / 2)})
let hashess_insert #hsz lv i j hs v =
let ihs = S.upd hs lv (S.snoc (S.index hs lv) v) in
hs_wf_elts_equal (lv + 1) hs ihs (i / 2) (j / 2);
ihs
val insert_:
#hsz:pos -> #f:MTS.hash_fun_t #hsz ->
lv:nat{lv < 32} ->
i:nat ->
j:nat{i <= j /\ j < pow2 (32 - lv) - 1} ->
hs:hashess #hsz {S.length hs = 32 /\ hs_wf_elts lv hs i j} ->
acc:hash #hsz ->
GTot (ihs:hashess #hsz {
S.length ihs = 32 /\
hs_wf_elts #hsz lv ihs i (j + 1) /\
S.equal (S.slice hs 0 lv) (S.slice ihs 0 lv)})
(decreases j)
let rec insert_ #hsz #f lv i j hs acc =
let ihs = hashess_insert #hsz lv i j hs acc in
assert (S.equal (S.slice hs 0 lv) (S.slice ihs 0 lv));
if j % 2 = 1 // S.length (S.index hs lv) > 0
then begin
remainder_2_1_div j;
let nacc = f (S.last (S.index hs lv)) acc in
let rihs = insert_ #hsz #f (lv + 1) (i / 2) (j / 2) ihs nacc in
assert (hs_wf_elts #hsz (lv + 1) rihs (i / 2) (j / 2 + 1));
assert (S.equal (S.slice ihs 0 (lv + 1)) (S.slice rihs 0 (lv + 1)));
assert (S.index ihs lv == S.index rihs lv);
assert (S.length (S.index rihs lv) = (j + 1) - offset_of i);
assert (S.equal (S.slice ihs 0 (lv + 1)) (S.slice rihs 0 (lv + 1)));
assert (S.equal (S.slice ihs 0 lv) (S.slice rihs 0 lv));
rihs
end
else ihs
val insert_base:
#hsz:pos -> #f:MTS.hash_fun_t #hsz ->
lv:nat -> i:nat -> j:nat -> hs:hashess #hsz -> acc:hash #hsz ->
Lemma (requires
lv < 32 /\ i <= j /\ j < pow2 (32 - lv) - 1 /\
S.length hs = 32 /\ hs_wf_elts lv hs i j /\
j % 2 <> 1)
(ensures S.equal (insert_ #_ #f lv i j hs acc)
(hashess_insert lv i j hs acc))
let insert_base #_ #_ lv i j hs acc = ()
val insert_rec:
#hsz:pos -> #f:MTS.hash_fun_t #hsz ->
lv:nat -> i:nat -> j:nat -> hs:hashess -> acc:hash ->
Lemma (requires
lv < 32 /\ i <= j /\ j < pow2 (32 - lv) - 1 /\
S.length hs = 32 /\ hs_wf_elts lv hs i j /\
j % 2 == 1)
(ensures
(hs_wf_elts_equal (lv + 1) hs
(hashess_insert lv i j hs acc) (i / 2) (j / 2);
S.equal (insert_ #_ #f lv i j hs acc)
(insert_ #_ #f (lv + 1) (i / 2) (j / 2)
(hashess_insert lv i j hs acc)
(f (S.last (S.index hs lv)) acc))))
let insert_rec #_ #_ lv i j hs acc = ()
val mt_insert:
#hsz:pos ->
mt:merkle_tree #hsz {mt_wf_elts mt /\ mt_not_full mt} -> v:hash #hsz ->
GTot (imt:merkle_tree #hsz{mt_wf_elts #hsz imt})
let mt_insert #hsz mt v =
MT (MT?.i mt)
(MT?.j mt + 1)
(insert_ #_ #(MT?.hash_fun mt) 0 (MT?.i mt) (MT?.j mt) (MT?.hs mt) v)
false
(MT?.rhs mt)
(MT?.mroot mt)
(MT?.hash_fun mt)
val mt_create:
hsz:pos -> f:MTS.hash_fun_t #hsz ->
init:hash #hsz -> GTot (mt:merkle_tree{mt_wf_elts #hsz mt})
let mt_create hsz f init =
mt_insert #_ (create_empty_mt #_ #f ()) init
/// Getting the Merkle root and path
type path (#hsz:pos) = S.seq (hash #hsz)
// Construct the rightmost hashes for a given (incomplete) Merkle tree.
// This function calculates the Merkle root as well, which is the final
// accumulator value.
val construct_rhs:
#hsz:pos -> #f:MTS.hash_fun_t #hsz ->
lv:nat{lv <= 32} ->
hs:hashess #hsz {S.length hs = 32} ->
rhs:hashes #hsz {S.length rhs = 32} ->
i:nat ->
j:nat{
i <= j /\ j < pow2 (32 - lv) /\
hs_wf_elts #hsz lv hs i j} ->
acc:hash #hsz ->
actd:bool ->
GTot (crhs:hashes #hsz {S.length crhs = 32} * (hash #hsz))
(decreases j)
let rec construct_rhs #hsz #f lv hs rhs i j acc actd =
let ofs = offset_of i in
if j = 0 then (rhs, acc)
else
(if j % 2 = 0
then (construct_rhs #_ #f (lv + 1) hs rhs (i / 2) (j / 2) acc actd)
else (let nrhs = if actd then S.upd rhs lv acc else rhs in
let nacc = if actd
then f (S.index (S.index hs lv) (j - 1 - ofs)) acc
else S.index (S.index hs lv) (j - 1 - ofs) in
construct_rhs #_ #f (lv + 1) hs nrhs (i / 2) (j / 2) nacc true))
val construct_rhs_unchanged:
#hsz:pos -> #f:MTS.hash_fun_t #hsz ->
lv:nat{lv <= 32} ->
hs:hashess #hsz {S.length hs = 32} ->
rhs:hashes #hsz {S.length rhs = 32} ->
i:nat ->
j:nat{
i <= j /\ j < pow2 (32 - lv) /\
hs_wf_elts #hsz lv hs i j} ->
acc:hash #hsz ->
actd:bool ->
Lemma (requires True)
(ensures S.equal (S.slice rhs 0 lv)
(S.slice (fst (construct_rhs #_ #f lv hs rhs i j acc actd)) 0 lv))
(decreases j)
let rec construct_rhs_unchanged #hsz #f lv hs rhs i j acc actd =
let ofs = offset_of i in
if j = 0 then ()
else if j % 2 = 0
then (construct_rhs_unchanged #_ #f (lv + 1) hs rhs (i / 2) (j / 2) acc actd;
let rrhs = fst (construct_rhs #_ #f (lv + 1) hs rhs (i / 2) (j / 2) acc actd) in
assert (S.equal (S.slice rhs 0 lv) (S.slice rrhs 0 lv)))
else (let nrhs = if actd then S.upd rhs lv acc else rhs in
let nacc = if actd
then f (S.index (S.index hs lv) (j - 1 - ofs)) acc
else S.index (S.index hs lv) (j - 1 - ofs) in
construct_rhs_unchanged #_ #f (lv + 1) hs nrhs (i / 2) (j / 2) nacc true;
let rrhs = fst (construct_rhs #_ #f (lv + 1) hs nrhs (i / 2) (j / 2) nacc true) in
assert (S.equal (S.slice nrhs 0 lv) (S.slice rrhs 0 lv));
assert (S.equal (S.slice rhs 0 lv) (S.slice nrhs 0 lv)))
val construct_rhs_even:
#hsz:pos -> #f:MTS.hash_fun_t #hsz ->
lv:nat{lv <= 32} ->
hs:hashess #hsz {S.length hs = 32} ->
rhs:hashes #hsz {S.length rhs = 32} ->
i:nat ->
j:nat{
i <= j /\ j < pow2 (32 - lv) /\
hs_wf_elts #hsz lv hs i j} ->
acc:hash #hsz ->
actd:bool ->
Lemma (requires j <> 0 /\ j % 2 = 0)
(ensures construct_rhs #_ #f lv hs rhs i j acc actd ==
construct_rhs #_ #f (lv + 1) hs rhs (i / 2) (j / 2) acc actd)
let construct_rhs_even #_ #_ _ _ _ _ _ _ _ = ()
val construct_rhs_odd:
#hsz:pos -> #f:MTS.hash_fun_t #hsz ->
lv:nat{lv <= 32} ->
hs:hashess #hsz {S.length hs = 32} ->
rhs:hashes #hsz {S.length rhs = 32} ->
i:nat ->
j:nat{
i <= j /\ j < pow2 (32 - lv) /\
hs_wf_elts lv hs i j} ->
acc:hash ->
actd:bool ->
Lemma (requires j % 2 = 1)
(ensures construct_rhs #_ #f lv hs rhs i j acc actd ==
(let ofs = offset_of i in
let nrhs = if actd then S.upd rhs lv acc else rhs in
let nacc = if actd
then f (S.index (S.index hs lv) (j - 1 - ofs)) acc
else S.index (S.index hs lv) (j - 1 - ofs) in
construct_rhs #_ #f (lv + 1) hs nrhs (i / 2) (j / 2) nacc true))
let construct_rhs_odd #_ #_ _ _ _ _ _ _ _ = ()
val mt_get_root:
#hsz:pos ->
mt:merkle_tree #hsz {mt_wf_elts #hsz mt} -> drt:hash #hsz ->
GTot (merkle_tree #hsz * hash #hsz)
let mt_get_root #hsz mt drt =
if MT?.rhs_ok mt then (mt, MT?.mroot mt)
else begin
let (nrhs, rt) = construct_rhs #_ #(MT?.hash_fun mt) 0 (MT?.hs mt) (MT?.rhs mt) (MT?.i mt) (MT?.j mt) drt false in
(MT (MT?.i mt) (MT?.j mt) (MT?.hs mt) true nrhs rt (MT?.hash_fun mt), rt)
end
val mt_get_root_rhs_ok_true:
#hsz:pos ->
mt:merkle_tree #hsz {mt_wf_elts mt} -> drt:hash #hsz ->
Lemma (requires MT?.rhs_ok mt == true)
(ensures mt_get_root #hsz mt drt == (mt, MT?.mroot mt))
let mt_get_root_rhs_ok_true #hsz mt drt = ()
val mt_get_root_rhs_ok_false:
#hsz:pos ->
mt:merkle_tree #hsz {mt_wf_elts mt} -> drt:hash ->
Lemma (requires MT?.rhs_ok mt == false)
(ensures mt_get_root mt drt ==
(let (nrhs, rt) =
construct_rhs #_ #(MT?.hash_fun mt)
0 (MT?.hs mt) (MT?.rhs mt) (MT?.i mt) (MT?.j mt)
drt false in
(MT (MT?.i mt) (MT?.j mt) (MT?.hs mt) true nrhs rt (MT?.hash_fun mt), rt)))
let mt_get_root_rhs_ok_false #_ _ _ = ()
val path_insert: (#hsz:pos) -> p:path #hsz -> hp:hash #hsz -> GTot (path #hsz)
let path_insert #_ p hp = S.snoc p hp
val mt_path_length_step:
k:nat -> j:nat{k <= j} -> actd:bool -> GTot nat
let mt_path_length_step k j actd =
if j = 0 then 0
else (if k % 2 = 0
then (if j = k || (j = k + 1 && not actd) then 0 else 1)
else 1)
val mt_path_length:
k:nat -> j:nat{k <= j} -> actd:bool -> GTot nat
let rec mt_path_length k j actd =
if j = 0 then 0
else (let nactd = actd || (j % 2 = 1) in
mt_path_length_step k j actd +
mt_path_length (k / 2) (j / 2) nactd)
val mt_make_path_step:
#hsz:pos ->
lv:nat{lv <= 32} ->
hs:hashess #hsz {S.length hs = 32} ->
rhs:hashes #hsz {S.length rhs = 32} ->
i:nat ->
j:nat{
j <> 0 /\ i <= j /\ j < pow2 (32 - lv) /\
hs_wf_elts lv hs i j} ->
k:nat{i <= k && k <= j} ->
p:path #hsz ->
actd:bool ->
GTot (path #hsz)
let mt_make_path_step #hsz lv hs rhs i j k p actd =
let ofs = offset_of i in
if k % 2 = 1
then path_insert p (S.index (S.index hs lv) (k - 1 - ofs))
else (if k = j then p
else if k + 1 = j
then (if actd
then path_insert p (S.index rhs lv)
else p)
else path_insert p (S.index (S.index hs lv) (k + 1 - ofs)))
// Construct a Merkle path for a given index `k`, hashes `hs`,
// and rightmost hashes `rhs`.
val mt_get_path_:
#hsz:pos ->
lv:nat{lv <= 32} ->
hs:hashess #hsz {S.length hs = 32} ->
rhs:hashes #hsz {S.length rhs = 32} ->
i:nat ->
j:nat{
i <= j /\ j < pow2 (32 - lv) /\
hs_wf_elts lv hs i j} ->
k:nat{i <= k && k <= j} ->
p:path #hsz ->
actd:bool ->
GTot (np:path #hsz {S.length np = S.length p + mt_path_length k j actd})
(decreases (32 - lv))
let rec mt_get_path_ #hsz lv hs rhs i j k p actd =
let ofs = offset_of i in
if j = 0 then p
else
(let np = mt_make_path_step lv hs rhs i j k p actd in
mt_get_path_ (lv + 1) hs rhs (i / 2) (j / 2) (k / 2) np
(if j % 2 = 0 then actd else true))
val mt_get_path_unchanged:
#hsz:pos ->
lv:nat{lv <= 32} ->
hs:hashess #hsz {S.length hs = 32} ->
rhs:hashes #hsz {S.length rhs = 32} ->
i:nat ->
j:nat{
i <= j /\ j < pow2 (32 - lv) /\
hs_wf_elts #hsz lv hs i j} ->
k:nat{i <= k && k <= j} ->
p:path #hsz ->
actd:bool ->
Lemma (requires True)
(ensures S.equal p (S.slice (mt_get_path_ lv hs rhs i j k p actd)
0 (S.length p)))
(decreases (32 - lv))
let rec mt_get_path_unchanged #hsz lv hs rhs i j k p actd =
let ofs = offset_of i in
if j = 0 then ()
else
(let np = mt_make_path_step lv hs rhs i j k p actd in
assert (S.equal p (S.slice np 0 (S.length p)));
mt_get_path_unchanged (lv + 1) hs rhs (i / 2) (j / 2) (k / 2) np
(if j % 2 = 0 then actd else true))
#push-options "--z3rlimit 20"
val mt_get_path_pull:
#hsz:pos ->
lv:nat{lv <= 32} ->
hs:hashess #hsz {S.length hs = 32} ->
rhs:hashes #hsz {S.length rhs = 32} ->
i:nat ->
j:nat{
i <= j /\ j < pow2 (32 - lv) /\
hs_wf_elts lv hs i j} ->
k:nat{i <= k && k <= j} ->
p:path #hsz ->
actd:bool ->
Lemma (requires True)
(ensures S.equal (mt_get_path_ lv hs rhs i j k p actd)
(S.append p (mt_get_path_ lv hs rhs i j k S.empty actd)))
(decreases (32 - lv))
let rec mt_get_path_pull #hsz lv hs rhs i j k p actd =
let ofs = offset_of i in
if j = 0 then ()
else
(let np = mt_make_path_step lv hs rhs i j k p actd in
let nactd = if j % 2 = 0 then actd else true in
mt_get_path_pull (lv + 1) hs rhs (i / 2) (j / 2) (k / 2) np nactd;
mt_get_path_pull (lv + 1) hs rhs (i / 2) (j / 2) (k / 2)
(mt_make_path_step lv hs rhs i j k S.empty actd) nactd)
#pop-options
val mt_get_path_slice:
#hsz:pos ->
lv:nat{lv <= 32} ->
hs:hashess #hsz {S.length hs = 32} ->
rhs:hashes #hsz {S.length rhs = 32} ->
i:nat ->
j:nat{
i <= j /\ j < pow2 (32 - lv) /\
hs_wf_elts lv hs i j} ->
k:nat{i <= k && k <= j} ->
p:path #hsz ->
actd:bool ->
Lemma (requires True)
(ensures S.equal (S.slice (mt_get_path_ lv hs rhs i j k p actd)
(S.length p) (S.length p + mt_path_length k j actd))
(mt_get_path_ lv hs rhs i j k S.empty actd))
(decreases (32 - lv))
let mt_get_path_slice #hsz lv hs rhs i j k p actd =
mt_get_path_pull lv hs rhs i j k p actd
val mt_get_path:
#hsz:pos ->
mt:merkle_tree #hsz {mt_wf_elts mt} ->
idx:nat{MT?.i mt <= idx /\ idx < MT?.j mt} ->
drt:hash #hsz ->
GTot (nat *
(np:path #hsz {S.length np = 1 + mt_path_length idx (MT?.j mt) false}) * | false | false | MerkleTree.New.High.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 1,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 10,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val mt_get_path:
#hsz:pos ->
mt:merkle_tree #hsz {mt_wf_elts mt} ->
idx:nat{MT?.i mt <= idx /\ idx < MT?.j mt} ->
drt:hash #hsz ->
GTot (nat *
(np:path #hsz {S.length np = 1 + mt_path_length idx (MT?.j mt) false}) *
hash #hsz) | [] | MerkleTree.New.High.mt_get_path | {
"file_name": "src/MerkleTree.New.High.fst",
"git_rev": "3b0f086655c145aa23f58a97259ebf4cf112a4a3",
"git_url": "https://github.com/hacl-star/merkle-tree.git",
"project_name": "merkle-tree"
} |
mt: MerkleTree.New.High.merkle_tree{MerkleTree.New.High.mt_wf_elts mt} ->
idx: Prims.nat{MT?.i mt <= idx /\ idx < MT?.j mt} ->
drt: MerkleTree.New.High.hash
-> Prims.GTot
((Prims.nat *
np:
MerkleTree.New.High.path
{FStar.Seq.Base.length np = 1 + MerkleTree.New.High.mt_path_length idx (MT?.j mt) false}) *
MerkleTree.New.High.hash) | {
"end_col": 6,
"end_line": 536,
"start_col": 33,
"start_line": 529
} |
Prims.GTot | val hashess_insert:
#hsz:pos ->
lv:nat{lv < 32} ->
i:nat ->
j:nat{i <= j /\ j < pow2 (32 - lv) - 1} ->
hs:hashess #hsz {S.length hs = 32 /\ hs_wf_elts lv hs i j} ->
v:hash #hsz ->
GTot (ihs:hashess #hsz {S.length ihs = 32 /\ hs_wf_elts (lv + 1) ihs (i / 2) (j / 2)}) | [
{
"abbrev": true,
"full_module": "MerkleTree.Spec",
"short_module": "MTS"
},
{
"abbrev": true,
"full_module": "FStar.UInt8",
"short_module": "U8"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "S"
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Ghost",
"short_module": null
},
{
"abbrev": false,
"full_module": "MerkleTree.New",
"short_module": null
},
{
"abbrev": false,
"full_module": "MerkleTree.New",
"short_module": null
},
{
"abbrev": 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 hashess_insert #hsz lv i j hs v =
let ihs = S.upd hs lv (S.snoc (S.index hs lv) v) in
hs_wf_elts_equal (lv + 1) hs ihs (i / 2) (j / 2);
ihs | val hashess_insert:
#hsz:pos ->
lv:nat{lv < 32} ->
i:nat ->
j:nat{i <= j /\ j < pow2 (32 - lv) - 1} ->
hs:hashess #hsz {S.length hs = 32 /\ hs_wf_elts lv hs i j} ->
v:hash #hsz ->
GTot (ihs:hashess #hsz {S.length ihs = 32 /\ hs_wf_elts (lv + 1) ihs (i / 2) (j / 2)})
let hashess_insert #hsz lv i j hs v = | false | null | false | let ihs = S.upd hs lv (S.snoc (S.index hs lv) v) in
hs_wf_elts_equal (lv + 1) hs ihs (i / 2) (j / 2);
ihs | {
"checked_file": "MerkleTree.New.High.fst.checked",
"dependencies": [
"Spec.Hash.Definitions.fst.checked",
"prims.fst.checked",
"MerkleTree.Spec.fst.checked",
"Lib.IntTypes.fsti.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "MerkleTree.New.High.fst"
} | [
"sometrivial"
] | [
"Prims.pos",
"Prims.nat",
"Prims.b2t",
"Prims.op_LessThan",
"Prims.l_and",
"Prims.op_LessThanOrEqual",
"Prims.op_Subtraction",
"Prims.pow2",
"MerkleTree.New.High.hashess",
"Prims.op_Equality",
"Prims.int",
"FStar.Seq.Base.length",
"MerkleTree.New.High.hashes",
"MerkleTree.New.High.hs_wf_elts",
"MerkleTree.New.High.hash",
"Prims.unit",
"MerkleTree.New.High.hs_wf_elts_equal",
"Prims.op_Addition",
"Prims.op_Division",
"FStar.Seq.Base.seq",
"FStar.Seq.Base.upd",
"FStar.Seq.Properties.snoc",
"FStar.Seq.Base.index"
] | [] | module MerkleTree.New.High
open FStar.Ghost
open FStar.Seq
module S = FStar.Seq
module U32 = FStar.UInt32
module U8 = FStar.UInt8
module MTS = MerkleTree.Spec
#set-options "--z3rlimit 10 --max_fuel 0 --max_ifuel 0"
type uint32_t = U32.t
type uint8_t = U8.t
type hash (#hsz:pos) = b:Spec.Hash.Definitions.bytes{Seq.length b = hsz}
type hashes (#hsz:pos) = S.seq (hash #hsz)
type hashess (#hsz:pos) = S.seq (hashes #hsz)
noextract
let hash_init (#hsz:pos): hash #hsz =
Seq.create hsz (Lib.IntTypes.u8 0)
val sha256_compress: src1:hash #32 -> src2:hash #32 -> GTot (hash #32)
let sha256_compress = MTS.sha256_compress
/// Facts about sequences
val seq_slice_equal_index:
#a:Type -> s1:S.seq a -> s2:S.seq a ->
i:nat -> j:nat{i <= j && j <= S.length s1 && j <= S.length s2} ->
k:nat{i <= k && k < j} ->
Lemma (requires S.equal (S.slice s1 i j) (S.slice s2 i j))
(ensures S.index s1 k == S.index s2 k)
[SMTPat (S.equal (S.slice s1 i j) (S.slice s2 i j));
SMTPat (S.index s1 k)]
let seq_slice_equal_index #a s1 s2 i j k =
assert (S.index (S.slice s1 i j) (k - i) == S.index (S.slice s2 i j) (k - i))
private val seq_slice_more_equal:
#a:Type -> s1:S.seq a -> s2:S.seq a ->
n:nat -> m:nat{n <= m && m <= S.length s1 && m <= S.length s2} ->
k:nat{n <= k} -> l:nat{k <= l && l <= m} ->
Lemma (requires S.equal (S.slice s1 n m) (S.slice s2 n m))
(ensures S.equal (S.slice s1 k l) (S.slice s2 k l))
[SMTPat (S.equal (S.slice s1 n m) (S.slice s2 n m));
SMTPat (S.equal (S.slice s1 k l) (S.slice s2 k l))]
private let seq_slice_more_equal #a s1 s2 n m k l =
slice_slice s1 n m (k - n) (l - n);
slice_slice s2 n m (k - n) (l - n)
/// Facts about "2"
val remainder_2_not_1_div: n:nat ->
Lemma (requires n % 2 <> 1)
(ensures n / 2 = (n + 1) / 2)
let remainder_2_not_1_div n = ()
val remainder_2_1_div: n:nat ->
Lemma (requires n % 2 = 1)
(ensures n / 2 + 1 = (n + 1) / 2)
let remainder_2_1_div n = ()
/// High-level Merkle tree data structure
noeq type merkle_tree (#hsz:pos) =
| MT: i:nat ->
j:nat{i <= j && j < pow2 32} ->
hs:hashess #hsz {S.length hs = 32} ->
rhs_ok:bool ->
rhs:hashes #hsz {S.length rhs = 32} -> // Rightmost hashes
mroot:hash #hsz ->
hash_fun:MTS.hash_fun_t #hsz ->
merkle_tree #hsz
val mt_not_full (#hsz:pos): merkle_tree #hsz -> GTot bool
let mt_not_full #hsz mt =
MT?.j mt < pow2 32 - 1
val mt_empty (#hsz:pos): merkle_tree #hsz -> GTot bool
let mt_empty #hsz mt =
MT?.j mt = 0
val mt_not_empty (#hsz:pos): merkle_tree #hsz -> GTot bool
let mt_not_empty #hsz mt =
MT?.j mt > 0
/// Well-formedness w.r.t. indices of base hash elements
noextract
val offset_of: i:nat -> Tot nat
let offset_of i =
if i % 2 = 0 then i else i - 1
val hs_wf_elts:
#hsz:pos ->
lv:nat{lv <= 32} ->
hs:hashess #hsz {S.length hs = 32} ->
i:nat -> j:nat{j >= i} ->
GTot Type0 (decreases (32 - lv))
let rec hs_wf_elts #hsz lv hs i j =
if lv = 32 then true
else (let ofs = offset_of i in
S.length (S.index hs lv) == j - ofs /\
hs_wf_elts #hsz (lv + 1) hs (i / 2) (j / 2))
#push-options "--max_fuel 1"
val hs_wf_elts_equal:
#hsz:pos ->
lv:nat{lv <= 32} ->
hs1:hashess #hsz {S.length hs1 = 32} ->
hs2:hashess #hsz {S.length hs2 = 32} ->
i:nat ->
j:nat{j >= i} ->
Lemma (requires hs_wf_elts lv hs1 i j /\
S.equal (S.slice hs1 lv 32) (S.slice hs2 lv 32))
(ensures hs_wf_elts lv hs2 i j)
(decreases (32 - lv))
let rec hs_wf_elts_equal #hsz lv hs1 hs2 i j =
if lv = 32 then ()
else (S.slice_slice hs1 lv 32 1 (32 - lv);
S.slice_slice hs2 lv 32 1 (32 - lv);
assert (S.equal (S.slice hs1 (lv + 1) 32)
(S.slice hs2 (lv + 1) 32));
S.lemma_index_slice hs1 lv 32 0;
S.lemma_index_slice hs2 lv 32 0;
assert (S.index hs1 lv == S.index hs2 lv);
hs_wf_elts_equal (lv + 1) hs1 hs2 (i / 2) (j / 2))
val mt_wf_elts (#hsz:pos): merkle_tree #hsz -> GTot Type0
let mt_wf_elts #_ (MT i j hs _ _ _ _) =
hs_wf_elts 0 hs i j
/// Construction
val hs_wf_elts_empty:
#hsz:pos ->
lv:nat{lv <= 32} ->
Lemma (requires True)
(ensures hs_wf_elts #hsz lv (S.create 32 S.empty) 0 0)
(decreases (32 - lv))
let rec hs_wf_elts_empty #hsz lv =
if lv = 32 then ()
else hs_wf_elts_empty #hsz (lv + 1)
// NOTE: the public function is `create_mt` defined below, which
// builds a tree with an initial hash.
noextract inline_for_extraction
val create_empty_mt (#hsz:pos) (#f:MTS.hash_fun_t #hsz): unit -> GTot (mt:merkle_tree #hsz {mt_wf_elts #hsz mt})
let create_empty_mt #hsz #f _ =
hs_wf_elts_empty #hsz 0;
MT 0 0 (S.create 32 S.empty) false (S.create 32 (hash_init #hsz)) (hash_init #hsz) f
/// Insertion
val hashess_insert:
#hsz:pos ->
lv:nat{lv < 32} ->
i:nat ->
j:nat{i <= j /\ j < pow2 (32 - lv) - 1} ->
hs:hashess #hsz {S.length hs = 32 /\ hs_wf_elts lv hs i j} ->
v:hash #hsz -> | false | false | MerkleTree.New.High.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 1,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 10,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val hashess_insert:
#hsz:pos ->
lv:nat{lv < 32} ->
i:nat ->
j:nat{i <= j /\ j < pow2 (32 - lv) - 1} ->
hs:hashess #hsz {S.length hs = 32 /\ hs_wf_elts lv hs i j} ->
v:hash #hsz ->
GTot (ihs:hashess #hsz {S.length ihs = 32 /\ hs_wf_elts (lv + 1) ihs (i / 2) (j / 2)}) | [] | MerkleTree.New.High.hashess_insert | {
"file_name": "src/MerkleTree.New.High.fst",
"git_rev": "3b0f086655c145aa23f58a97259ebf4cf112a4a3",
"git_url": "https://github.com/hacl-star/merkle-tree.git",
"project_name": "merkle-tree"
} |
lv: Prims.nat{lv < 32} ->
i: Prims.nat ->
j: Prims.nat{i <= j /\ j < Prims.pow2 (32 - lv) - 1} ->
hs:
MerkleTree.New.High.hashess
{FStar.Seq.Base.length hs = 32 /\ MerkleTree.New.High.hs_wf_elts lv hs i j} ->
v: MerkleTree.New.High.hash
-> Prims.GTot
(ihs:
MerkleTree.New.High.hashess
{ FStar.Seq.Base.length ihs = 32 /\
MerkleTree.New.High.hs_wf_elts (lv + 1) ihs (i / 2) (j / 2) }) | {
"end_col": 5,
"end_line": 171,
"start_col": 37,
"start_line": 168
} |
Prims.GTot | val mt_get_path_:
#hsz:pos ->
lv:nat{lv <= 32} ->
hs:hashess #hsz {S.length hs = 32} ->
rhs:hashes #hsz {S.length rhs = 32} ->
i:nat ->
j:nat{
i <= j /\ j < pow2 (32 - lv) /\
hs_wf_elts lv hs i j} ->
k:nat{i <= k && k <= j} ->
p:path #hsz ->
actd:bool ->
GTot (np:path #hsz {S.length np = S.length p + mt_path_length k j actd})
(decreases (32 - lv)) | [
{
"abbrev": true,
"full_module": "MerkleTree.Spec",
"short_module": "MTS"
},
{
"abbrev": true,
"full_module": "FStar.UInt8",
"short_module": "U8"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "S"
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Ghost",
"short_module": null
},
{
"abbrev": false,
"full_module": "MerkleTree.New",
"short_module": null
},
{
"abbrev": false,
"full_module": "MerkleTree.New",
"short_module": null
},
{
"abbrev": 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 mt_get_path_ #hsz lv hs rhs i j k p actd =
let ofs = offset_of i in
if j = 0 then p
else
(let np = mt_make_path_step lv hs rhs i j k p actd in
mt_get_path_ (lv + 1) hs rhs (i / 2) (j / 2) (k / 2) np
(if j % 2 = 0 then actd else true)) | val mt_get_path_:
#hsz:pos ->
lv:nat{lv <= 32} ->
hs:hashess #hsz {S.length hs = 32} ->
rhs:hashes #hsz {S.length rhs = 32} ->
i:nat ->
j:nat{
i <= j /\ j < pow2 (32 - lv) /\
hs_wf_elts lv hs i j} ->
k:nat{i <= k && k <= j} ->
p:path #hsz ->
actd:bool ->
GTot (np:path #hsz {S.length np = S.length p + mt_path_length k j actd})
(decreases (32 - lv))
let rec mt_get_path_ #hsz lv hs rhs i j k p actd = | false | null | false | let ofs = offset_of i in
if j = 0
then p
else
(let np = mt_make_path_step lv hs rhs i j k p actd in
mt_get_path_ (lv + 1) hs rhs (i / 2) (j / 2) (k / 2) np (if j % 2 = 0 then actd else true)) | {
"checked_file": "MerkleTree.New.High.fst.checked",
"dependencies": [
"Spec.Hash.Definitions.fst.checked",
"prims.fst.checked",
"MerkleTree.Spec.fst.checked",
"Lib.IntTypes.fsti.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "MerkleTree.New.High.fst"
} | [
"sometrivial",
""
] | [
"Prims.pos",
"Prims.nat",
"Prims.b2t",
"Prims.op_LessThanOrEqual",
"MerkleTree.New.High.hashess",
"Prims.op_Equality",
"Prims.int",
"FStar.Seq.Base.length",
"MerkleTree.New.High.hashes",
"MerkleTree.New.High.hash",
"Prims.l_and",
"Prims.op_LessThan",
"Prims.pow2",
"Prims.op_Subtraction",
"MerkleTree.New.High.hs_wf_elts",
"Prims.op_AmpAmp",
"MerkleTree.New.High.path",
"Prims.bool",
"MerkleTree.New.High.mt_get_path_",
"Prims.op_Addition",
"Prims.op_Division",
"Prims.op_Modulus",
"Prims.precedes",
"MerkleTree.New.High.mt_make_path_step",
"MerkleTree.New.High.mt_path_length",
"MerkleTree.New.High.offset_of"
] | [] | module MerkleTree.New.High
open FStar.Ghost
open FStar.Seq
module S = FStar.Seq
module U32 = FStar.UInt32
module U8 = FStar.UInt8
module MTS = MerkleTree.Spec
#set-options "--z3rlimit 10 --max_fuel 0 --max_ifuel 0"
type uint32_t = U32.t
type uint8_t = U8.t
type hash (#hsz:pos) = b:Spec.Hash.Definitions.bytes{Seq.length b = hsz}
type hashes (#hsz:pos) = S.seq (hash #hsz)
type hashess (#hsz:pos) = S.seq (hashes #hsz)
noextract
let hash_init (#hsz:pos): hash #hsz =
Seq.create hsz (Lib.IntTypes.u8 0)
val sha256_compress: src1:hash #32 -> src2:hash #32 -> GTot (hash #32)
let sha256_compress = MTS.sha256_compress
/// Facts about sequences
val seq_slice_equal_index:
#a:Type -> s1:S.seq a -> s2:S.seq a ->
i:nat -> j:nat{i <= j && j <= S.length s1 && j <= S.length s2} ->
k:nat{i <= k && k < j} ->
Lemma (requires S.equal (S.slice s1 i j) (S.slice s2 i j))
(ensures S.index s1 k == S.index s2 k)
[SMTPat (S.equal (S.slice s1 i j) (S.slice s2 i j));
SMTPat (S.index s1 k)]
let seq_slice_equal_index #a s1 s2 i j k =
assert (S.index (S.slice s1 i j) (k - i) == S.index (S.slice s2 i j) (k - i))
private val seq_slice_more_equal:
#a:Type -> s1:S.seq a -> s2:S.seq a ->
n:nat -> m:nat{n <= m && m <= S.length s1 && m <= S.length s2} ->
k:nat{n <= k} -> l:nat{k <= l && l <= m} ->
Lemma (requires S.equal (S.slice s1 n m) (S.slice s2 n m))
(ensures S.equal (S.slice s1 k l) (S.slice s2 k l))
[SMTPat (S.equal (S.slice s1 n m) (S.slice s2 n m));
SMTPat (S.equal (S.slice s1 k l) (S.slice s2 k l))]
private let seq_slice_more_equal #a s1 s2 n m k l =
slice_slice s1 n m (k - n) (l - n);
slice_slice s2 n m (k - n) (l - n)
/// Facts about "2"
val remainder_2_not_1_div: n:nat ->
Lemma (requires n % 2 <> 1)
(ensures n / 2 = (n + 1) / 2)
let remainder_2_not_1_div n = ()
val remainder_2_1_div: n:nat ->
Lemma (requires n % 2 = 1)
(ensures n / 2 + 1 = (n + 1) / 2)
let remainder_2_1_div n = ()
/// High-level Merkle tree data structure
noeq type merkle_tree (#hsz:pos) =
| MT: i:nat ->
j:nat{i <= j && j < pow2 32} ->
hs:hashess #hsz {S.length hs = 32} ->
rhs_ok:bool ->
rhs:hashes #hsz {S.length rhs = 32} -> // Rightmost hashes
mroot:hash #hsz ->
hash_fun:MTS.hash_fun_t #hsz ->
merkle_tree #hsz
val mt_not_full (#hsz:pos): merkle_tree #hsz -> GTot bool
let mt_not_full #hsz mt =
MT?.j mt < pow2 32 - 1
val mt_empty (#hsz:pos): merkle_tree #hsz -> GTot bool
let mt_empty #hsz mt =
MT?.j mt = 0
val mt_not_empty (#hsz:pos): merkle_tree #hsz -> GTot bool
let mt_not_empty #hsz mt =
MT?.j mt > 0
/// Well-formedness w.r.t. indices of base hash elements
noextract
val offset_of: i:nat -> Tot nat
let offset_of i =
if i % 2 = 0 then i else i - 1
val hs_wf_elts:
#hsz:pos ->
lv:nat{lv <= 32} ->
hs:hashess #hsz {S.length hs = 32} ->
i:nat -> j:nat{j >= i} ->
GTot Type0 (decreases (32 - lv))
let rec hs_wf_elts #hsz lv hs i j =
if lv = 32 then true
else (let ofs = offset_of i in
S.length (S.index hs lv) == j - ofs /\
hs_wf_elts #hsz (lv + 1) hs (i / 2) (j / 2))
#push-options "--max_fuel 1"
val hs_wf_elts_equal:
#hsz:pos ->
lv:nat{lv <= 32} ->
hs1:hashess #hsz {S.length hs1 = 32} ->
hs2:hashess #hsz {S.length hs2 = 32} ->
i:nat ->
j:nat{j >= i} ->
Lemma (requires hs_wf_elts lv hs1 i j /\
S.equal (S.slice hs1 lv 32) (S.slice hs2 lv 32))
(ensures hs_wf_elts lv hs2 i j)
(decreases (32 - lv))
let rec hs_wf_elts_equal #hsz lv hs1 hs2 i j =
if lv = 32 then ()
else (S.slice_slice hs1 lv 32 1 (32 - lv);
S.slice_slice hs2 lv 32 1 (32 - lv);
assert (S.equal (S.slice hs1 (lv + 1) 32)
(S.slice hs2 (lv + 1) 32));
S.lemma_index_slice hs1 lv 32 0;
S.lemma_index_slice hs2 lv 32 0;
assert (S.index hs1 lv == S.index hs2 lv);
hs_wf_elts_equal (lv + 1) hs1 hs2 (i / 2) (j / 2))
val mt_wf_elts (#hsz:pos): merkle_tree #hsz -> GTot Type0
let mt_wf_elts #_ (MT i j hs _ _ _ _) =
hs_wf_elts 0 hs i j
/// Construction
val hs_wf_elts_empty:
#hsz:pos ->
lv:nat{lv <= 32} ->
Lemma (requires True)
(ensures hs_wf_elts #hsz lv (S.create 32 S.empty) 0 0)
(decreases (32 - lv))
let rec hs_wf_elts_empty #hsz lv =
if lv = 32 then ()
else hs_wf_elts_empty #hsz (lv + 1)
// NOTE: the public function is `create_mt` defined below, which
// builds a tree with an initial hash.
noextract inline_for_extraction
val create_empty_mt (#hsz:pos) (#f:MTS.hash_fun_t #hsz): unit -> GTot (mt:merkle_tree #hsz {mt_wf_elts #hsz mt})
let create_empty_mt #hsz #f _ =
hs_wf_elts_empty #hsz 0;
MT 0 0 (S.create 32 S.empty) false (S.create 32 (hash_init #hsz)) (hash_init #hsz) f
/// Insertion
val hashess_insert:
#hsz:pos ->
lv:nat{lv < 32} ->
i:nat ->
j:nat{i <= j /\ j < pow2 (32 - lv) - 1} ->
hs:hashess #hsz {S.length hs = 32 /\ hs_wf_elts lv hs i j} ->
v:hash #hsz ->
GTot (ihs:hashess #hsz {S.length ihs = 32 /\ hs_wf_elts (lv + 1) ihs (i / 2) (j / 2)})
let hashess_insert #hsz lv i j hs v =
let ihs = S.upd hs lv (S.snoc (S.index hs lv) v) in
hs_wf_elts_equal (lv + 1) hs ihs (i / 2) (j / 2);
ihs
val insert_:
#hsz:pos -> #f:MTS.hash_fun_t #hsz ->
lv:nat{lv < 32} ->
i:nat ->
j:nat{i <= j /\ j < pow2 (32 - lv) - 1} ->
hs:hashess #hsz {S.length hs = 32 /\ hs_wf_elts lv hs i j} ->
acc:hash #hsz ->
GTot (ihs:hashess #hsz {
S.length ihs = 32 /\
hs_wf_elts #hsz lv ihs i (j + 1) /\
S.equal (S.slice hs 0 lv) (S.slice ihs 0 lv)})
(decreases j)
let rec insert_ #hsz #f lv i j hs acc =
let ihs = hashess_insert #hsz lv i j hs acc in
assert (S.equal (S.slice hs 0 lv) (S.slice ihs 0 lv));
if j % 2 = 1 // S.length (S.index hs lv) > 0
then begin
remainder_2_1_div j;
let nacc = f (S.last (S.index hs lv)) acc in
let rihs = insert_ #hsz #f (lv + 1) (i / 2) (j / 2) ihs nacc in
assert (hs_wf_elts #hsz (lv + 1) rihs (i / 2) (j / 2 + 1));
assert (S.equal (S.slice ihs 0 (lv + 1)) (S.slice rihs 0 (lv + 1)));
assert (S.index ihs lv == S.index rihs lv);
assert (S.length (S.index rihs lv) = (j + 1) - offset_of i);
assert (S.equal (S.slice ihs 0 (lv + 1)) (S.slice rihs 0 (lv + 1)));
assert (S.equal (S.slice ihs 0 lv) (S.slice rihs 0 lv));
rihs
end
else ihs
val insert_base:
#hsz:pos -> #f:MTS.hash_fun_t #hsz ->
lv:nat -> i:nat -> j:nat -> hs:hashess #hsz -> acc:hash #hsz ->
Lemma (requires
lv < 32 /\ i <= j /\ j < pow2 (32 - lv) - 1 /\
S.length hs = 32 /\ hs_wf_elts lv hs i j /\
j % 2 <> 1)
(ensures S.equal (insert_ #_ #f lv i j hs acc)
(hashess_insert lv i j hs acc))
let insert_base #_ #_ lv i j hs acc = ()
val insert_rec:
#hsz:pos -> #f:MTS.hash_fun_t #hsz ->
lv:nat -> i:nat -> j:nat -> hs:hashess -> acc:hash ->
Lemma (requires
lv < 32 /\ i <= j /\ j < pow2 (32 - lv) - 1 /\
S.length hs = 32 /\ hs_wf_elts lv hs i j /\
j % 2 == 1)
(ensures
(hs_wf_elts_equal (lv + 1) hs
(hashess_insert lv i j hs acc) (i / 2) (j / 2);
S.equal (insert_ #_ #f lv i j hs acc)
(insert_ #_ #f (lv + 1) (i / 2) (j / 2)
(hashess_insert lv i j hs acc)
(f (S.last (S.index hs lv)) acc))))
let insert_rec #_ #_ lv i j hs acc = ()
val mt_insert:
#hsz:pos ->
mt:merkle_tree #hsz {mt_wf_elts mt /\ mt_not_full mt} -> v:hash #hsz ->
GTot (imt:merkle_tree #hsz{mt_wf_elts #hsz imt})
let mt_insert #hsz mt v =
MT (MT?.i mt)
(MT?.j mt + 1)
(insert_ #_ #(MT?.hash_fun mt) 0 (MT?.i mt) (MT?.j mt) (MT?.hs mt) v)
false
(MT?.rhs mt)
(MT?.mroot mt)
(MT?.hash_fun mt)
val mt_create:
hsz:pos -> f:MTS.hash_fun_t #hsz ->
init:hash #hsz -> GTot (mt:merkle_tree{mt_wf_elts #hsz mt})
let mt_create hsz f init =
mt_insert #_ (create_empty_mt #_ #f ()) init
/// Getting the Merkle root and path
type path (#hsz:pos) = S.seq (hash #hsz)
// Construct the rightmost hashes for a given (incomplete) Merkle tree.
// This function calculates the Merkle root as well, which is the final
// accumulator value.
val construct_rhs:
#hsz:pos -> #f:MTS.hash_fun_t #hsz ->
lv:nat{lv <= 32} ->
hs:hashess #hsz {S.length hs = 32} ->
rhs:hashes #hsz {S.length rhs = 32} ->
i:nat ->
j:nat{
i <= j /\ j < pow2 (32 - lv) /\
hs_wf_elts #hsz lv hs i j} ->
acc:hash #hsz ->
actd:bool ->
GTot (crhs:hashes #hsz {S.length crhs = 32} * (hash #hsz))
(decreases j)
let rec construct_rhs #hsz #f lv hs rhs i j acc actd =
let ofs = offset_of i in
if j = 0 then (rhs, acc)
else
(if j % 2 = 0
then (construct_rhs #_ #f (lv + 1) hs rhs (i / 2) (j / 2) acc actd)
else (let nrhs = if actd then S.upd rhs lv acc else rhs in
let nacc = if actd
then f (S.index (S.index hs lv) (j - 1 - ofs)) acc
else S.index (S.index hs lv) (j - 1 - ofs) in
construct_rhs #_ #f (lv + 1) hs nrhs (i / 2) (j / 2) nacc true))
val construct_rhs_unchanged:
#hsz:pos -> #f:MTS.hash_fun_t #hsz ->
lv:nat{lv <= 32} ->
hs:hashess #hsz {S.length hs = 32} ->
rhs:hashes #hsz {S.length rhs = 32} ->
i:nat ->
j:nat{
i <= j /\ j < pow2 (32 - lv) /\
hs_wf_elts #hsz lv hs i j} ->
acc:hash #hsz ->
actd:bool ->
Lemma (requires True)
(ensures S.equal (S.slice rhs 0 lv)
(S.slice (fst (construct_rhs #_ #f lv hs rhs i j acc actd)) 0 lv))
(decreases j)
let rec construct_rhs_unchanged #hsz #f lv hs rhs i j acc actd =
let ofs = offset_of i in
if j = 0 then ()
else if j % 2 = 0
then (construct_rhs_unchanged #_ #f (lv + 1) hs rhs (i / 2) (j / 2) acc actd;
let rrhs = fst (construct_rhs #_ #f (lv + 1) hs rhs (i / 2) (j / 2) acc actd) in
assert (S.equal (S.slice rhs 0 lv) (S.slice rrhs 0 lv)))
else (let nrhs = if actd then S.upd rhs lv acc else rhs in
let nacc = if actd
then f (S.index (S.index hs lv) (j - 1 - ofs)) acc
else S.index (S.index hs lv) (j - 1 - ofs) in
construct_rhs_unchanged #_ #f (lv + 1) hs nrhs (i / 2) (j / 2) nacc true;
let rrhs = fst (construct_rhs #_ #f (lv + 1) hs nrhs (i / 2) (j / 2) nacc true) in
assert (S.equal (S.slice nrhs 0 lv) (S.slice rrhs 0 lv));
assert (S.equal (S.slice rhs 0 lv) (S.slice nrhs 0 lv)))
val construct_rhs_even:
#hsz:pos -> #f:MTS.hash_fun_t #hsz ->
lv:nat{lv <= 32} ->
hs:hashess #hsz {S.length hs = 32} ->
rhs:hashes #hsz {S.length rhs = 32} ->
i:nat ->
j:nat{
i <= j /\ j < pow2 (32 - lv) /\
hs_wf_elts #hsz lv hs i j} ->
acc:hash #hsz ->
actd:bool ->
Lemma (requires j <> 0 /\ j % 2 = 0)
(ensures construct_rhs #_ #f lv hs rhs i j acc actd ==
construct_rhs #_ #f (lv + 1) hs rhs (i / 2) (j / 2) acc actd)
let construct_rhs_even #_ #_ _ _ _ _ _ _ _ = ()
val construct_rhs_odd:
#hsz:pos -> #f:MTS.hash_fun_t #hsz ->
lv:nat{lv <= 32} ->
hs:hashess #hsz {S.length hs = 32} ->
rhs:hashes #hsz {S.length rhs = 32} ->
i:nat ->
j:nat{
i <= j /\ j < pow2 (32 - lv) /\
hs_wf_elts lv hs i j} ->
acc:hash ->
actd:bool ->
Lemma (requires j % 2 = 1)
(ensures construct_rhs #_ #f lv hs rhs i j acc actd ==
(let ofs = offset_of i in
let nrhs = if actd then S.upd rhs lv acc else rhs in
let nacc = if actd
then f (S.index (S.index hs lv) (j - 1 - ofs)) acc
else S.index (S.index hs lv) (j - 1 - ofs) in
construct_rhs #_ #f (lv + 1) hs nrhs (i / 2) (j / 2) nacc true))
let construct_rhs_odd #_ #_ _ _ _ _ _ _ _ = ()
val mt_get_root:
#hsz:pos ->
mt:merkle_tree #hsz {mt_wf_elts #hsz mt} -> drt:hash #hsz ->
GTot (merkle_tree #hsz * hash #hsz)
let mt_get_root #hsz mt drt =
if MT?.rhs_ok mt then (mt, MT?.mroot mt)
else begin
let (nrhs, rt) = construct_rhs #_ #(MT?.hash_fun mt) 0 (MT?.hs mt) (MT?.rhs mt) (MT?.i mt) (MT?.j mt) drt false in
(MT (MT?.i mt) (MT?.j mt) (MT?.hs mt) true nrhs rt (MT?.hash_fun mt), rt)
end
val mt_get_root_rhs_ok_true:
#hsz:pos ->
mt:merkle_tree #hsz {mt_wf_elts mt} -> drt:hash #hsz ->
Lemma (requires MT?.rhs_ok mt == true)
(ensures mt_get_root #hsz mt drt == (mt, MT?.mroot mt))
let mt_get_root_rhs_ok_true #hsz mt drt = ()
val mt_get_root_rhs_ok_false:
#hsz:pos ->
mt:merkle_tree #hsz {mt_wf_elts mt} -> drt:hash ->
Lemma (requires MT?.rhs_ok mt == false)
(ensures mt_get_root mt drt ==
(let (nrhs, rt) =
construct_rhs #_ #(MT?.hash_fun mt)
0 (MT?.hs mt) (MT?.rhs mt) (MT?.i mt) (MT?.j mt)
drt false in
(MT (MT?.i mt) (MT?.j mt) (MT?.hs mt) true nrhs rt (MT?.hash_fun mt), rt)))
let mt_get_root_rhs_ok_false #_ _ _ = ()
val path_insert: (#hsz:pos) -> p:path #hsz -> hp:hash #hsz -> GTot (path #hsz)
let path_insert #_ p hp = S.snoc p hp
val mt_path_length_step:
k:nat -> j:nat{k <= j} -> actd:bool -> GTot nat
let mt_path_length_step k j actd =
if j = 0 then 0
else (if k % 2 = 0
then (if j = k || (j = k + 1 && not actd) then 0 else 1)
else 1)
val mt_path_length:
k:nat -> j:nat{k <= j} -> actd:bool -> GTot nat
let rec mt_path_length k j actd =
if j = 0 then 0
else (let nactd = actd || (j % 2 = 1) in
mt_path_length_step k j actd +
mt_path_length (k / 2) (j / 2) nactd)
val mt_make_path_step:
#hsz:pos ->
lv:nat{lv <= 32} ->
hs:hashess #hsz {S.length hs = 32} ->
rhs:hashes #hsz {S.length rhs = 32} ->
i:nat ->
j:nat{
j <> 0 /\ i <= j /\ j < pow2 (32 - lv) /\
hs_wf_elts lv hs i j} ->
k:nat{i <= k && k <= j} ->
p:path #hsz ->
actd:bool ->
GTot (path #hsz)
let mt_make_path_step #hsz lv hs rhs i j k p actd =
let ofs = offset_of i in
if k % 2 = 1
then path_insert p (S.index (S.index hs lv) (k - 1 - ofs))
else (if k = j then p
else if k + 1 = j
then (if actd
then path_insert p (S.index rhs lv)
else p)
else path_insert p (S.index (S.index hs lv) (k + 1 - ofs)))
// Construct a Merkle path for a given index `k`, hashes `hs`,
// and rightmost hashes `rhs`.
val mt_get_path_:
#hsz:pos ->
lv:nat{lv <= 32} ->
hs:hashess #hsz {S.length hs = 32} ->
rhs:hashes #hsz {S.length rhs = 32} ->
i:nat ->
j:nat{
i <= j /\ j < pow2 (32 - lv) /\
hs_wf_elts lv hs i j} ->
k:nat{i <= k && k <= j} ->
p:path #hsz ->
actd:bool ->
GTot (np:path #hsz {S.length np = S.length p + mt_path_length k j actd}) | false | false | MerkleTree.New.High.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 1,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 10,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val mt_get_path_:
#hsz:pos ->
lv:nat{lv <= 32} ->
hs:hashess #hsz {S.length hs = 32} ->
rhs:hashes #hsz {S.length rhs = 32} ->
i:nat ->
j:nat{
i <= j /\ j < pow2 (32 - lv) /\
hs_wf_elts lv hs i j} ->
k:nat{i <= k && k <= j} ->
p:path #hsz ->
actd:bool ->
GTot (np:path #hsz {S.length np = S.length p + mt_path_length k j actd})
(decreases (32 - lv)) | [
"recursion"
] | MerkleTree.New.High.mt_get_path_ | {
"file_name": "src/MerkleTree.New.High.fst",
"git_rev": "3b0f086655c145aa23f58a97259ebf4cf112a4a3",
"git_url": "https://github.com/hacl-star/merkle-tree.git",
"project_name": "merkle-tree"
} |
lv: Prims.nat{lv <= 32} ->
hs: MerkleTree.New.High.hashess{FStar.Seq.Base.length hs = 32} ->
rhs: MerkleTree.New.High.hashes{FStar.Seq.Base.length rhs = 32} ->
i: Prims.nat ->
j: Prims.nat{i <= j /\ j < Prims.pow2 (32 - lv) /\ MerkleTree.New.High.hs_wf_elts lv hs i j} ->
k: Prims.nat{i <= k && k <= j} ->
p: MerkleTree.New.High.path ->
actd: Prims.bool
-> Prims.GTot
(np:
MerkleTree.New.High.path
{ FStar.Seq.Base.length np =
FStar.Seq.Base.length p + MerkleTree.New.High.mt_path_length k j actd }) | {
"end_col": 42,
"end_line": 444,
"start_col": 50,
"start_line": 438
} |
FStar.Pervasives.Lemma | val construct_rhs_unchanged:
#hsz:pos -> #f:MTS.hash_fun_t #hsz ->
lv:nat{lv <= 32} ->
hs:hashess #hsz {S.length hs = 32} ->
rhs:hashes #hsz {S.length rhs = 32} ->
i:nat ->
j:nat{
i <= j /\ j < pow2 (32 - lv) /\
hs_wf_elts #hsz lv hs i j} ->
acc:hash #hsz ->
actd:bool ->
Lemma (requires True)
(ensures S.equal (S.slice rhs 0 lv)
(S.slice (fst (construct_rhs #_ #f lv hs rhs i j acc actd)) 0 lv))
(decreases j) | [
{
"abbrev": true,
"full_module": "MerkleTree.Spec",
"short_module": "MTS"
},
{
"abbrev": true,
"full_module": "FStar.UInt8",
"short_module": "U8"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "S"
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Ghost",
"short_module": null
},
{
"abbrev": false,
"full_module": "MerkleTree.New",
"short_module": null
},
{
"abbrev": false,
"full_module": "MerkleTree.New",
"short_module": null
},
{
"abbrev": 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 construct_rhs_unchanged #hsz #f lv hs rhs i j acc actd =
let ofs = offset_of i in
if j = 0 then ()
else if j % 2 = 0
then (construct_rhs_unchanged #_ #f (lv + 1) hs rhs (i / 2) (j / 2) acc actd;
let rrhs = fst (construct_rhs #_ #f (lv + 1) hs rhs (i / 2) (j / 2) acc actd) in
assert (S.equal (S.slice rhs 0 lv) (S.slice rrhs 0 lv)))
else (let nrhs = if actd then S.upd rhs lv acc else rhs in
let nacc = if actd
then f (S.index (S.index hs lv) (j - 1 - ofs)) acc
else S.index (S.index hs lv) (j - 1 - ofs) in
construct_rhs_unchanged #_ #f (lv + 1) hs nrhs (i / 2) (j / 2) nacc true;
let rrhs = fst (construct_rhs #_ #f (lv + 1) hs nrhs (i / 2) (j / 2) nacc true) in
assert (S.equal (S.slice nrhs 0 lv) (S.slice rrhs 0 lv));
assert (S.equal (S.slice rhs 0 lv) (S.slice nrhs 0 lv))) | val construct_rhs_unchanged:
#hsz:pos -> #f:MTS.hash_fun_t #hsz ->
lv:nat{lv <= 32} ->
hs:hashess #hsz {S.length hs = 32} ->
rhs:hashes #hsz {S.length rhs = 32} ->
i:nat ->
j:nat{
i <= j /\ j < pow2 (32 - lv) /\
hs_wf_elts #hsz lv hs i j} ->
acc:hash #hsz ->
actd:bool ->
Lemma (requires True)
(ensures S.equal (S.slice rhs 0 lv)
(S.slice (fst (construct_rhs #_ #f lv hs rhs i j acc actd)) 0 lv))
(decreases j)
let rec construct_rhs_unchanged #hsz #f lv hs rhs i j acc actd = | false | null | true | let ofs = offset_of i in
if j = 0
then ()
else
if j % 2 = 0
then
(construct_rhs_unchanged #_ #f (lv + 1) hs rhs (i / 2) (j / 2) acc actd;
let rrhs = fst (construct_rhs #_ #f (lv + 1) hs rhs (i / 2) (j / 2) acc actd) in
assert (S.equal (S.slice rhs 0 lv) (S.slice rrhs 0 lv)))
else
(let nrhs = if actd then S.upd rhs lv acc else rhs in
let nacc =
if actd
then f (S.index (S.index hs lv) (j - 1 - ofs)) acc
else S.index (S.index hs lv) (j - 1 - ofs)
in
construct_rhs_unchanged #_ #f (lv + 1) hs nrhs (i / 2) (j / 2) nacc true;
let rrhs = fst (construct_rhs #_ #f (lv + 1) hs nrhs (i / 2) (j / 2) nacc true) in
assert (S.equal (S.slice nrhs 0 lv) (S.slice rrhs 0 lv));
assert (S.equal (S.slice rhs 0 lv) (S.slice nrhs 0 lv))) | {
"checked_file": "MerkleTree.New.High.fst.checked",
"dependencies": [
"Spec.Hash.Definitions.fst.checked",
"prims.fst.checked",
"MerkleTree.Spec.fst.checked",
"Lib.IntTypes.fsti.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "MerkleTree.New.High.fst"
} | [
"lemma",
""
] | [
"Prims.pos",
"MerkleTree.Spec.hash_fun_t",
"Prims.nat",
"Prims.b2t",
"Prims.op_LessThanOrEqual",
"MerkleTree.New.High.hashess",
"Prims.op_Equality",
"Prims.int",
"FStar.Seq.Base.length",
"MerkleTree.New.High.hashes",
"MerkleTree.New.High.hash",
"Prims.l_and",
"Prims.op_LessThan",
"Prims.pow2",
"Prims.op_Subtraction",
"MerkleTree.New.High.hs_wf_elts",
"Prims.bool",
"Prims.op_Modulus",
"Prims._assert",
"FStar.Seq.Base.equal",
"FStar.Seq.Base.slice",
"FStar.Pervasives.Native.fst",
"MerkleTree.New.High.construct_rhs",
"Prims.op_Addition",
"Prims.op_Division",
"Prims.unit",
"MerkleTree.New.High.construct_rhs_unchanged",
"FStar.Seq.Base.index",
"FStar.Seq.Base.seq",
"FStar.Seq.Base.upd",
"MerkleTree.New.High.offset_of"
] | [] | module MerkleTree.New.High
open FStar.Ghost
open FStar.Seq
module S = FStar.Seq
module U32 = FStar.UInt32
module U8 = FStar.UInt8
module MTS = MerkleTree.Spec
#set-options "--z3rlimit 10 --max_fuel 0 --max_ifuel 0"
type uint32_t = U32.t
type uint8_t = U8.t
type hash (#hsz:pos) = b:Spec.Hash.Definitions.bytes{Seq.length b = hsz}
type hashes (#hsz:pos) = S.seq (hash #hsz)
type hashess (#hsz:pos) = S.seq (hashes #hsz)
noextract
let hash_init (#hsz:pos): hash #hsz =
Seq.create hsz (Lib.IntTypes.u8 0)
val sha256_compress: src1:hash #32 -> src2:hash #32 -> GTot (hash #32)
let sha256_compress = MTS.sha256_compress
/// Facts about sequences
val seq_slice_equal_index:
#a:Type -> s1:S.seq a -> s2:S.seq a ->
i:nat -> j:nat{i <= j && j <= S.length s1 && j <= S.length s2} ->
k:nat{i <= k && k < j} ->
Lemma (requires S.equal (S.slice s1 i j) (S.slice s2 i j))
(ensures S.index s1 k == S.index s2 k)
[SMTPat (S.equal (S.slice s1 i j) (S.slice s2 i j));
SMTPat (S.index s1 k)]
let seq_slice_equal_index #a s1 s2 i j k =
assert (S.index (S.slice s1 i j) (k - i) == S.index (S.slice s2 i j) (k - i))
private val seq_slice_more_equal:
#a:Type -> s1:S.seq a -> s2:S.seq a ->
n:nat -> m:nat{n <= m && m <= S.length s1 && m <= S.length s2} ->
k:nat{n <= k} -> l:nat{k <= l && l <= m} ->
Lemma (requires S.equal (S.slice s1 n m) (S.slice s2 n m))
(ensures S.equal (S.slice s1 k l) (S.slice s2 k l))
[SMTPat (S.equal (S.slice s1 n m) (S.slice s2 n m));
SMTPat (S.equal (S.slice s1 k l) (S.slice s2 k l))]
private let seq_slice_more_equal #a s1 s2 n m k l =
slice_slice s1 n m (k - n) (l - n);
slice_slice s2 n m (k - n) (l - n)
/// Facts about "2"
val remainder_2_not_1_div: n:nat ->
Lemma (requires n % 2 <> 1)
(ensures n / 2 = (n + 1) / 2)
let remainder_2_not_1_div n = ()
val remainder_2_1_div: n:nat ->
Lemma (requires n % 2 = 1)
(ensures n / 2 + 1 = (n + 1) / 2)
let remainder_2_1_div n = ()
/// High-level Merkle tree data structure
noeq type merkle_tree (#hsz:pos) =
| MT: i:nat ->
j:nat{i <= j && j < pow2 32} ->
hs:hashess #hsz {S.length hs = 32} ->
rhs_ok:bool ->
rhs:hashes #hsz {S.length rhs = 32} -> // Rightmost hashes
mroot:hash #hsz ->
hash_fun:MTS.hash_fun_t #hsz ->
merkle_tree #hsz
val mt_not_full (#hsz:pos): merkle_tree #hsz -> GTot bool
let mt_not_full #hsz mt =
MT?.j mt < pow2 32 - 1
val mt_empty (#hsz:pos): merkle_tree #hsz -> GTot bool
let mt_empty #hsz mt =
MT?.j mt = 0
val mt_not_empty (#hsz:pos): merkle_tree #hsz -> GTot bool
let mt_not_empty #hsz mt =
MT?.j mt > 0
/// Well-formedness w.r.t. indices of base hash elements
noextract
val offset_of: i:nat -> Tot nat
let offset_of i =
if i % 2 = 0 then i else i - 1
val hs_wf_elts:
#hsz:pos ->
lv:nat{lv <= 32} ->
hs:hashess #hsz {S.length hs = 32} ->
i:nat -> j:nat{j >= i} ->
GTot Type0 (decreases (32 - lv))
let rec hs_wf_elts #hsz lv hs i j =
if lv = 32 then true
else (let ofs = offset_of i in
S.length (S.index hs lv) == j - ofs /\
hs_wf_elts #hsz (lv + 1) hs (i / 2) (j / 2))
#push-options "--max_fuel 1"
val hs_wf_elts_equal:
#hsz:pos ->
lv:nat{lv <= 32} ->
hs1:hashess #hsz {S.length hs1 = 32} ->
hs2:hashess #hsz {S.length hs2 = 32} ->
i:nat ->
j:nat{j >= i} ->
Lemma (requires hs_wf_elts lv hs1 i j /\
S.equal (S.slice hs1 lv 32) (S.slice hs2 lv 32))
(ensures hs_wf_elts lv hs2 i j)
(decreases (32 - lv))
let rec hs_wf_elts_equal #hsz lv hs1 hs2 i j =
if lv = 32 then ()
else (S.slice_slice hs1 lv 32 1 (32 - lv);
S.slice_slice hs2 lv 32 1 (32 - lv);
assert (S.equal (S.slice hs1 (lv + 1) 32)
(S.slice hs2 (lv + 1) 32));
S.lemma_index_slice hs1 lv 32 0;
S.lemma_index_slice hs2 lv 32 0;
assert (S.index hs1 lv == S.index hs2 lv);
hs_wf_elts_equal (lv + 1) hs1 hs2 (i / 2) (j / 2))
val mt_wf_elts (#hsz:pos): merkle_tree #hsz -> GTot Type0
let mt_wf_elts #_ (MT i j hs _ _ _ _) =
hs_wf_elts 0 hs i j
/// Construction
val hs_wf_elts_empty:
#hsz:pos ->
lv:nat{lv <= 32} ->
Lemma (requires True)
(ensures hs_wf_elts #hsz lv (S.create 32 S.empty) 0 0)
(decreases (32 - lv))
let rec hs_wf_elts_empty #hsz lv =
if lv = 32 then ()
else hs_wf_elts_empty #hsz (lv + 1)
// NOTE: the public function is `create_mt` defined below, which
// builds a tree with an initial hash.
noextract inline_for_extraction
val create_empty_mt (#hsz:pos) (#f:MTS.hash_fun_t #hsz): unit -> GTot (mt:merkle_tree #hsz {mt_wf_elts #hsz mt})
let create_empty_mt #hsz #f _ =
hs_wf_elts_empty #hsz 0;
MT 0 0 (S.create 32 S.empty) false (S.create 32 (hash_init #hsz)) (hash_init #hsz) f
/// Insertion
val hashess_insert:
#hsz:pos ->
lv:nat{lv < 32} ->
i:nat ->
j:nat{i <= j /\ j < pow2 (32 - lv) - 1} ->
hs:hashess #hsz {S.length hs = 32 /\ hs_wf_elts lv hs i j} ->
v:hash #hsz ->
GTot (ihs:hashess #hsz {S.length ihs = 32 /\ hs_wf_elts (lv + 1) ihs (i / 2) (j / 2)})
let hashess_insert #hsz lv i j hs v =
let ihs = S.upd hs lv (S.snoc (S.index hs lv) v) in
hs_wf_elts_equal (lv + 1) hs ihs (i / 2) (j / 2);
ihs
val insert_:
#hsz:pos -> #f:MTS.hash_fun_t #hsz ->
lv:nat{lv < 32} ->
i:nat ->
j:nat{i <= j /\ j < pow2 (32 - lv) - 1} ->
hs:hashess #hsz {S.length hs = 32 /\ hs_wf_elts lv hs i j} ->
acc:hash #hsz ->
GTot (ihs:hashess #hsz {
S.length ihs = 32 /\
hs_wf_elts #hsz lv ihs i (j + 1) /\
S.equal (S.slice hs 0 lv) (S.slice ihs 0 lv)})
(decreases j)
let rec insert_ #hsz #f lv i j hs acc =
let ihs = hashess_insert #hsz lv i j hs acc in
assert (S.equal (S.slice hs 0 lv) (S.slice ihs 0 lv));
if j % 2 = 1 // S.length (S.index hs lv) > 0
then begin
remainder_2_1_div j;
let nacc = f (S.last (S.index hs lv)) acc in
let rihs = insert_ #hsz #f (lv + 1) (i / 2) (j / 2) ihs nacc in
assert (hs_wf_elts #hsz (lv + 1) rihs (i / 2) (j / 2 + 1));
assert (S.equal (S.slice ihs 0 (lv + 1)) (S.slice rihs 0 (lv + 1)));
assert (S.index ihs lv == S.index rihs lv);
assert (S.length (S.index rihs lv) = (j + 1) - offset_of i);
assert (S.equal (S.slice ihs 0 (lv + 1)) (S.slice rihs 0 (lv + 1)));
assert (S.equal (S.slice ihs 0 lv) (S.slice rihs 0 lv));
rihs
end
else ihs
val insert_base:
#hsz:pos -> #f:MTS.hash_fun_t #hsz ->
lv:nat -> i:nat -> j:nat -> hs:hashess #hsz -> acc:hash #hsz ->
Lemma (requires
lv < 32 /\ i <= j /\ j < pow2 (32 - lv) - 1 /\
S.length hs = 32 /\ hs_wf_elts lv hs i j /\
j % 2 <> 1)
(ensures S.equal (insert_ #_ #f lv i j hs acc)
(hashess_insert lv i j hs acc))
let insert_base #_ #_ lv i j hs acc = ()
val insert_rec:
#hsz:pos -> #f:MTS.hash_fun_t #hsz ->
lv:nat -> i:nat -> j:nat -> hs:hashess -> acc:hash ->
Lemma (requires
lv < 32 /\ i <= j /\ j < pow2 (32 - lv) - 1 /\
S.length hs = 32 /\ hs_wf_elts lv hs i j /\
j % 2 == 1)
(ensures
(hs_wf_elts_equal (lv + 1) hs
(hashess_insert lv i j hs acc) (i / 2) (j / 2);
S.equal (insert_ #_ #f lv i j hs acc)
(insert_ #_ #f (lv + 1) (i / 2) (j / 2)
(hashess_insert lv i j hs acc)
(f (S.last (S.index hs lv)) acc))))
let insert_rec #_ #_ lv i j hs acc = ()
val mt_insert:
#hsz:pos ->
mt:merkle_tree #hsz {mt_wf_elts mt /\ mt_not_full mt} -> v:hash #hsz ->
GTot (imt:merkle_tree #hsz{mt_wf_elts #hsz imt})
let mt_insert #hsz mt v =
MT (MT?.i mt)
(MT?.j mt + 1)
(insert_ #_ #(MT?.hash_fun mt) 0 (MT?.i mt) (MT?.j mt) (MT?.hs mt) v)
false
(MT?.rhs mt)
(MT?.mroot mt)
(MT?.hash_fun mt)
val mt_create:
hsz:pos -> f:MTS.hash_fun_t #hsz ->
init:hash #hsz -> GTot (mt:merkle_tree{mt_wf_elts #hsz mt})
let mt_create hsz f init =
mt_insert #_ (create_empty_mt #_ #f ()) init
/// Getting the Merkle root and path
type path (#hsz:pos) = S.seq (hash #hsz)
// Construct the rightmost hashes for a given (incomplete) Merkle tree.
// This function calculates the Merkle root as well, which is the final
// accumulator value.
val construct_rhs:
#hsz:pos -> #f:MTS.hash_fun_t #hsz ->
lv:nat{lv <= 32} ->
hs:hashess #hsz {S.length hs = 32} ->
rhs:hashes #hsz {S.length rhs = 32} ->
i:nat ->
j:nat{
i <= j /\ j < pow2 (32 - lv) /\
hs_wf_elts #hsz lv hs i j} ->
acc:hash #hsz ->
actd:bool ->
GTot (crhs:hashes #hsz {S.length crhs = 32} * (hash #hsz))
(decreases j)
let rec construct_rhs #hsz #f lv hs rhs i j acc actd =
let ofs = offset_of i in
if j = 0 then (rhs, acc)
else
(if j % 2 = 0
then (construct_rhs #_ #f (lv + 1) hs rhs (i / 2) (j / 2) acc actd)
else (let nrhs = if actd then S.upd rhs lv acc else rhs in
let nacc = if actd
then f (S.index (S.index hs lv) (j - 1 - ofs)) acc
else S.index (S.index hs lv) (j - 1 - ofs) in
construct_rhs #_ #f (lv + 1) hs nrhs (i / 2) (j / 2) nacc true))
val construct_rhs_unchanged:
#hsz:pos -> #f:MTS.hash_fun_t #hsz ->
lv:nat{lv <= 32} ->
hs:hashess #hsz {S.length hs = 32} ->
rhs:hashes #hsz {S.length rhs = 32} ->
i:nat ->
j:nat{
i <= j /\ j < pow2 (32 - lv) /\
hs_wf_elts #hsz lv hs i j} ->
acc:hash #hsz ->
actd:bool ->
Lemma (requires True)
(ensures S.equal (S.slice rhs 0 lv)
(S.slice (fst (construct_rhs #_ #f lv hs rhs i j acc actd)) 0 lv)) | false | false | MerkleTree.New.High.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 1,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 10,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val construct_rhs_unchanged:
#hsz:pos -> #f:MTS.hash_fun_t #hsz ->
lv:nat{lv <= 32} ->
hs:hashess #hsz {S.length hs = 32} ->
rhs:hashes #hsz {S.length rhs = 32} ->
i:nat ->
j:nat{
i <= j /\ j < pow2 (32 - lv) /\
hs_wf_elts #hsz lv hs i j} ->
acc:hash #hsz ->
actd:bool ->
Lemma (requires True)
(ensures S.equal (S.slice rhs 0 lv)
(S.slice (fst (construct_rhs #_ #f lv hs rhs i j acc actd)) 0 lv))
(decreases j) | [
"recursion"
] | MerkleTree.New.High.construct_rhs_unchanged | {
"file_name": "src/MerkleTree.New.High.fst",
"git_rev": "3b0f086655c145aa23f58a97259ebf4cf112a4a3",
"git_url": "https://github.com/hacl-star/merkle-tree.git",
"project_name": "merkle-tree"
} |
lv: Prims.nat{lv <= 32} ->
hs: MerkleTree.New.High.hashess{FStar.Seq.Base.length hs = 32} ->
rhs: MerkleTree.New.High.hashes{FStar.Seq.Base.length rhs = 32} ->
i: Prims.nat ->
j: Prims.nat{i <= j /\ j < Prims.pow2 (32 - lv) /\ MerkleTree.New.High.hs_wf_elts lv hs i j} ->
acc: MerkleTree.New.High.hash ->
actd: Prims.bool
-> FStar.Pervasives.Lemma
(ensures
FStar.Seq.Base.equal (FStar.Seq.Base.slice rhs 0 lv)
(FStar.Seq.Base.slice (FStar.Pervasives.Native.fst (MerkleTree.New.High.construct_rhs lv
hs
rhs
i
j
acc
actd))
0
lv)) (decreases j) | {
"end_col": 63,
"end_line": 310,
"start_col": 64,
"start_line": 296
} |
Prims.GTot | val insert_:
#hsz:pos -> #f:MTS.hash_fun_t #hsz ->
lv:nat{lv < 32} ->
i:nat ->
j:nat{i <= j /\ j < pow2 (32 - lv) - 1} ->
hs:hashess #hsz {S.length hs = 32 /\ hs_wf_elts lv hs i j} ->
acc:hash #hsz ->
GTot (ihs:hashess #hsz {
S.length ihs = 32 /\
hs_wf_elts #hsz lv ihs i (j + 1) /\
S.equal (S.slice hs 0 lv) (S.slice ihs 0 lv)})
(decreases j) | [
{
"abbrev": true,
"full_module": "MerkleTree.Spec",
"short_module": "MTS"
},
{
"abbrev": true,
"full_module": "FStar.UInt8",
"short_module": "U8"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "S"
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Ghost",
"short_module": null
},
{
"abbrev": false,
"full_module": "MerkleTree.New",
"short_module": null
},
{
"abbrev": false,
"full_module": "MerkleTree.New",
"short_module": null
},
{
"abbrev": 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 insert_ #hsz #f lv i j hs acc =
let ihs = hashess_insert #hsz lv i j hs acc in
assert (S.equal (S.slice hs 0 lv) (S.slice ihs 0 lv));
if j % 2 = 1 // S.length (S.index hs lv) > 0
then begin
remainder_2_1_div j;
let nacc = f (S.last (S.index hs lv)) acc in
let rihs = insert_ #hsz #f (lv + 1) (i / 2) (j / 2) ihs nacc in
assert (hs_wf_elts #hsz (lv + 1) rihs (i / 2) (j / 2 + 1));
assert (S.equal (S.slice ihs 0 (lv + 1)) (S.slice rihs 0 (lv + 1)));
assert (S.index ihs lv == S.index rihs lv);
assert (S.length (S.index rihs lv) = (j + 1) - offset_of i);
assert (S.equal (S.slice ihs 0 (lv + 1)) (S.slice rihs 0 (lv + 1)));
assert (S.equal (S.slice ihs 0 lv) (S.slice rihs 0 lv));
rihs
end
else ihs | val insert_:
#hsz:pos -> #f:MTS.hash_fun_t #hsz ->
lv:nat{lv < 32} ->
i:nat ->
j:nat{i <= j /\ j < pow2 (32 - lv) - 1} ->
hs:hashess #hsz {S.length hs = 32 /\ hs_wf_elts lv hs i j} ->
acc:hash #hsz ->
GTot (ihs:hashess #hsz {
S.length ihs = 32 /\
hs_wf_elts #hsz lv ihs i (j + 1) /\
S.equal (S.slice hs 0 lv) (S.slice ihs 0 lv)})
(decreases j)
let rec insert_ #hsz #f lv i j hs acc = | false | null | false | let ihs = hashess_insert #hsz lv i j hs acc in
assert (S.equal (S.slice hs 0 lv) (S.slice ihs 0 lv));
if j % 2 = 1
then
(remainder_2_1_div j;
let nacc = f (S.last (S.index hs lv)) acc in
let rihs = insert_ #hsz #f (lv + 1) (i / 2) (j / 2) ihs nacc in
assert (hs_wf_elts #hsz (lv + 1) rihs (i / 2) (j / 2 + 1));
assert (S.equal (S.slice ihs 0 (lv + 1)) (S.slice rihs 0 (lv + 1)));
assert (S.index ihs lv == S.index rihs lv);
assert (S.length (S.index rihs lv) = (j + 1) - offset_of i);
assert (S.equal (S.slice ihs 0 (lv + 1)) (S.slice rihs 0 (lv + 1)));
assert (S.equal (S.slice ihs 0 lv) (S.slice rihs 0 lv));
rihs)
else ihs | {
"checked_file": "MerkleTree.New.High.fst.checked",
"dependencies": [
"Spec.Hash.Definitions.fst.checked",
"prims.fst.checked",
"MerkleTree.Spec.fst.checked",
"Lib.IntTypes.fsti.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "MerkleTree.New.High.fst"
} | [
"sometrivial",
""
] | [
"Prims.pos",
"MerkleTree.Spec.hash_fun_t",
"Prims.nat",
"Prims.b2t",
"Prims.op_LessThan",
"Prims.l_and",
"Prims.op_LessThanOrEqual",
"Prims.op_Subtraction",
"Prims.pow2",
"MerkleTree.New.High.hashess",
"Prims.op_Equality",
"Prims.int",
"FStar.Seq.Base.length",
"MerkleTree.New.High.hashes",
"MerkleTree.New.High.hs_wf_elts",
"MerkleTree.New.High.hash",
"Prims.op_Modulus",
"Prims.unit",
"Prims._assert",
"FStar.Seq.Base.equal",
"FStar.Seq.Base.slice",
"Prims.op_Addition",
"FStar.Seq.Base.index",
"MerkleTree.New.High.offset_of",
"Prims.eq2",
"Prims.op_Division",
"MerkleTree.New.High.insert_",
"MerkleTree.Spec.hash",
"FStar.Seq.Properties.last",
"MerkleTree.New.High.remainder_2_1_div",
"Prims.bool",
"MerkleTree.New.High.hashess_insert"
] | [] | module MerkleTree.New.High
open FStar.Ghost
open FStar.Seq
module S = FStar.Seq
module U32 = FStar.UInt32
module U8 = FStar.UInt8
module MTS = MerkleTree.Spec
#set-options "--z3rlimit 10 --max_fuel 0 --max_ifuel 0"
type uint32_t = U32.t
type uint8_t = U8.t
type hash (#hsz:pos) = b:Spec.Hash.Definitions.bytes{Seq.length b = hsz}
type hashes (#hsz:pos) = S.seq (hash #hsz)
type hashess (#hsz:pos) = S.seq (hashes #hsz)
noextract
let hash_init (#hsz:pos): hash #hsz =
Seq.create hsz (Lib.IntTypes.u8 0)
val sha256_compress: src1:hash #32 -> src2:hash #32 -> GTot (hash #32)
let sha256_compress = MTS.sha256_compress
/// Facts about sequences
val seq_slice_equal_index:
#a:Type -> s1:S.seq a -> s2:S.seq a ->
i:nat -> j:nat{i <= j && j <= S.length s1 && j <= S.length s2} ->
k:nat{i <= k && k < j} ->
Lemma (requires S.equal (S.slice s1 i j) (S.slice s2 i j))
(ensures S.index s1 k == S.index s2 k)
[SMTPat (S.equal (S.slice s1 i j) (S.slice s2 i j));
SMTPat (S.index s1 k)]
let seq_slice_equal_index #a s1 s2 i j k =
assert (S.index (S.slice s1 i j) (k - i) == S.index (S.slice s2 i j) (k - i))
private val seq_slice_more_equal:
#a:Type -> s1:S.seq a -> s2:S.seq a ->
n:nat -> m:nat{n <= m && m <= S.length s1 && m <= S.length s2} ->
k:nat{n <= k} -> l:nat{k <= l && l <= m} ->
Lemma (requires S.equal (S.slice s1 n m) (S.slice s2 n m))
(ensures S.equal (S.slice s1 k l) (S.slice s2 k l))
[SMTPat (S.equal (S.slice s1 n m) (S.slice s2 n m));
SMTPat (S.equal (S.slice s1 k l) (S.slice s2 k l))]
private let seq_slice_more_equal #a s1 s2 n m k l =
slice_slice s1 n m (k - n) (l - n);
slice_slice s2 n m (k - n) (l - n)
/// Facts about "2"
val remainder_2_not_1_div: n:nat ->
Lemma (requires n % 2 <> 1)
(ensures n / 2 = (n + 1) / 2)
let remainder_2_not_1_div n = ()
val remainder_2_1_div: n:nat ->
Lemma (requires n % 2 = 1)
(ensures n / 2 + 1 = (n + 1) / 2)
let remainder_2_1_div n = ()
/// High-level Merkle tree data structure
noeq type merkle_tree (#hsz:pos) =
| MT: i:nat ->
j:nat{i <= j && j < pow2 32} ->
hs:hashess #hsz {S.length hs = 32} ->
rhs_ok:bool ->
rhs:hashes #hsz {S.length rhs = 32} -> // Rightmost hashes
mroot:hash #hsz ->
hash_fun:MTS.hash_fun_t #hsz ->
merkle_tree #hsz
val mt_not_full (#hsz:pos): merkle_tree #hsz -> GTot bool
let mt_not_full #hsz mt =
MT?.j mt < pow2 32 - 1
val mt_empty (#hsz:pos): merkle_tree #hsz -> GTot bool
let mt_empty #hsz mt =
MT?.j mt = 0
val mt_not_empty (#hsz:pos): merkle_tree #hsz -> GTot bool
let mt_not_empty #hsz mt =
MT?.j mt > 0
/// Well-formedness w.r.t. indices of base hash elements
noextract
val offset_of: i:nat -> Tot nat
let offset_of i =
if i % 2 = 0 then i else i - 1
val hs_wf_elts:
#hsz:pos ->
lv:nat{lv <= 32} ->
hs:hashess #hsz {S.length hs = 32} ->
i:nat -> j:nat{j >= i} ->
GTot Type0 (decreases (32 - lv))
let rec hs_wf_elts #hsz lv hs i j =
if lv = 32 then true
else (let ofs = offset_of i in
S.length (S.index hs lv) == j - ofs /\
hs_wf_elts #hsz (lv + 1) hs (i / 2) (j / 2))
#push-options "--max_fuel 1"
val hs_wf_elts_equal:
#hsz:pos ->
lv:nat{lv <= 32} ->
hs1:hashess #hsz {S.length hs1 = 32} ->
hs2:hashess #hsz {S.length hs2 = 32} ->
i:nat ->
j:nat{j >= i} ->
Lemma (requires hs_wf_elts lv hs1 i j /\
S.equal (S.slice hs1 lv 32) (S.slice hs2 lv 32))
(ensures hs_wf_elts lv hs2 i j)
(decreases (32 - lv))
let rec hs_wf_elts_equal #hsz lv hs1 hs2 i j =
if lv = 32 then ()
else (S.slice_slice hs1 lv 32 1 (32 - lv);
S.slice_slice hs2 lv 32 1 (32 - lv);
assert (S.equal (S.slice hs1 (lv + 1) 32)
(S.slice hs2 (lv + 1) 32));
S.lemma_index_slice hs1 lv 32 0;
S.lemma_index_slice hs2 lv 32 0;
assert (S.index hs1 lv == S.index hs2 lv);
hs_wf_elts_equal (lv + 1) hs1 hs2 (i / 2) (j / 2))
val mt_wf_elts (#hsz:pos): merkle_tree #hsz -> GTot Type0
let mt_wf_elts #_ (MT i j hs _ _ _ _) =
hs_wf_elts 0 hs i j
/// Construction
val hs_wf_elts_empty:
#hsz:pos ->
lv:nat{lv <= 32} ->
Lemma (requires True)
(ensures hs_wf_elts #hsz lv (S.create 32 S.empty) 0 0)
(decreases (32 - lv))
let rec hs_wf_elts_empty #hsz lv =
if lv = 32 then ()
else hs_wf_elts_empty #hsz (lv + 1)
// NOTE: the public function is `create_mt` defined below, which
// builds a tree with an initial hash.
noextract inline_for_extraction
val create_empty_mt (#hsz:pos) (#f:MTS.hash_fun_t #hsz): unit -> GTot (mt:merkle_tree #hsz {mt_wf_elts #hsz mt})
let create_empty_mt #hsz #f _ =
hs_wf_elts_empty #hsz 0;
MT 0 0 (S.create 32 S.empty) false (S.create 32 (hash_init #hsz)) (hash_init #hsz) f
/// Insertion
val hashess_insert:
#hsz:pos ->
lv:nat{lv < 32} ->
i:nat ->
j:nat{i <= j /\ j < pow2 (32 - lv) - 1} ->
hs:hashess #hsz {S.length hs = 32 /\ hs_wf_elts lv hs i j} ->
v:hash #hsz ->
GTot (ihs:hashess #hsz {S.length ihs = 32 /\ hs_wf_elts (lv + 1) ihs (i / 2) (j / 2)})
let hashess_insert #hsz lv i j hs v =
let ihs = S.upd hs lv (S.snoc (S.index hs lv) v) in
hs_wf_elts_equal (lv + 1) hs ihs (i / 2) (j / 2);
ihs
val insert_:
#hsz:pos -> #f:MTS.hash_fun_t #hsz ->
lv:nat{lv < 32} ->
i:nat ->
j:nat{i <= j /\ j < pow2 (32 - lv) - 1} ->
hs:hashess #hsz {S.length hs = 32 /\ hs_wf_elts lv hs i j} ->
acc:hash #hsz ->
GTot (ihs:hashess #hsz {
S.length ihs = 32 /\
hs_wf_elts #hsz lv ihs i (j + 1) /\
S.equal (S.slice hs 0 lv) (S.slice ihs 0 lv)}) | false | false | MerkleTree.New.High.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 1,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 10,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val insert_:
#hsz:pos -> #f:MTS.hash_fun_t #hsz ->
lv:nat{lv < 32} ->
i:nat ->
j:nat{i <= j /\ j < pow2 (32 - lv) - 1} ->
hs:hashess #hsz {S.length hs = 32 /\ hs_wf_elts lv hs i j} ->
acc:hash #hsz ->
GTot (ihs:hashess #hsz {
S.length ihs = 32 /\
hs_wf_elts #hsz lv ihs i (j + 1) /\
S.equal (S.slice hs 0 lv) (S.slice ihs 0 lv)})
(decreases j) | [
"recursion"
] | MerkleTree.New.High.insert_ | {
"file_name": "src/MerkleTree.New.High.fst",
"git_rev": "3b0f086655c145aa23f58a97259ebf4cf112a4a3",
"git_url": "https://github.com/hacl-star/merkle-tree.git",
"project_name": "merkle-tree"
} |
lv: Prims.nat{lv < 32} ->
i: Prims.nat ->
j: Prims.nat{i <= j /\ j < Prims.pow2 (32 - lv) - 1} ->
hs:
MerkleTree.New.High.hashess
{FStar.Seq.Base.length hs = 32 /\ MerkleTree.New.High.hs_wf_elts lv hs i j} ->
acc: MerkleTree.New.High.hash
-> Prims.GTot
(ihs:
MerkleTree.New.High.hashess
{ FStar.Seq.Base.length ihs = 32 /\ MerkleTree.New.High.hs_wf_elts lv ihs i (j + 1) /\
FStar.Seq.Base.equal (FStar.Seq.Base.slice hs 0 lv) (FStar.Seq.Base.slice ihs 0 lv) }) | {
"end_col": 10,
"end_line": 201,
"start_col": 39,
"start_line": 185
} |
Prims.GTot | val mt_retract_to_:
#hsz:pos ->
hs:hashess #hsz {S.length hs = 32} ->
lv:nat{lv < S.length hs} ->
i:nat ->
s:nat -> // s is the first index excluded from nhs
j:nat{ i <= s /\ s <= j /\
j < pow2 (S.length hs - lv) /\
hs_wf_elts lv hs i j} ->
GTot (nhs:hashess #hsz {
S.length nhs = S.length hs /\
S.equal (S.slice hs 0 lv) (S.slice nhs 0 lv) /\
hs_wf_elts #hsz lv nhs i s})
(decreases (S.length hs - lv)) | [
{
"abbrev": true,
"full_module": "MerkleTree.Spec",
"short_module": "MTS"
},
{
"abbrev": true,
"full_module": "FStar.UInt8",
"short_module": "U8"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "S"
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Ghost",
"short_module": null
},
{
"abbrev": false,
"full_module": "MerkleTree.New",
"short_module": null
},
{
"abbrev": false,
"full_module": "MerkleTree.New",
"short_module": null
},
{
"abbrev": 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 mt_retract_to_ #hsz hs lv i s j =
if lv >= S.length hs then hs
else begin
let hvec = S.index hs lv in
let old_len = j - offset_of i in
let new_len = s - offset_of i in
assert (S.length hvec = old_len);
assert (new_len <= old_len);
assert (new_len <= S.length hvec);
let retracted = S.slice hvec 0 new_len in
let nhs = S.upd hs lv retracted in
if lv >= S.length hs - 1 then nhs else
begin
hs_wf_elts_equal (lv + 1) hs nhs (i / 2) (j / 2);
mt_retract_to_ nhs (lv + 1) (i / 2) (s / 2) (j / 2)
end
end | val mt_retract_to_:
#hsz:pos ->
hs:hashess #hsz {S.length hs = 32} ->
lv:nat{lv < S.length hs} ->
i:nat ->
s:nat -> // s is the first index excluded from nhs
j:nat{ i <= s /\ s <= j /\
j < pow2 (S.length hs - lv) /\
hs_wf_elts lv hs i j} ->
GTot (nhs:hashess #hsz {
S.length nhs = S.length hs /\
S.equal (S.slice hs 0 lv) (S.slice nhs 0 lv) /\
hs_wf_elts #hsz lv nhs i s})
(decreases (S.length hs - lv))
let rec mt_retract_to_ #hsz hs lv i s j = | false | null | false | if lv >= S.length hs
then hs
else
let hvec = S.index hs lv in
let old_len = j - offset_of i in
let new_len = s - offset_of i in
assert (S.length hvec = old_len);
assert (new_len <= old_len);
assert (new_len <= S.length hvec);
let retracted = S.slice hvec 0 new_len in
let nhs = S.upd hs lv retracted in
if lv >= S.length hs - 1
then nhs
else
(hs_wf_elts_equal (lv + 1) hs nhs (i / 2) (j / 2);
mt_retract_to_ nhs (lv + 1) (i / 2) (s / 2) (j / 2)) | {
"checked_file": "MerkleTree.New.High.fst.checked",
"dependencies": [
"Spec.Hash.Definitions.fst.checked",
"prims.fst.checked",
"MerkleTree.Spec.fst.checked",
"Lib.IntTypes.fsti.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "MerkleTree.New.High.fst"
} | [
"sometrivial",
""
] | [
"Prims.pos",
"MerkleTree.New.High.hashess",
"Prims.b2t",
"Prims.op_Equality",
"Prims.int",
"FStar.Seq.Base.length",
"MerkleTree.New.High.hashes",
"Prims.nat",
"Prims.op_LessThan",
"Prims.l_and",
"Prims.op_LessThanOrEqual",
"Prims.pow2",
"Prims.op_Subtraction",
"MerkleTree.New.High.hs_wf_elts",
"Prims.op_GreaterThanOrEqual",
"Prims.bool",
"MerkleTree.New.High.mt_retract_to_",
"Prims.op_Addition",
"Prims.op_Division",
"Prims.unit",
"MerkleTree.New.High.hs_wf_elts_equal",
"FStar.Seq.Base.equal",
"FStar.Seq.Base.slice",
"FStar.Seq.Base.seq",
"FStar.Seq.Base.upd",
"MerkleTree.New.High.hash",
"Prims._assert",
"MerkleTree.New.High.offset_of",
"FStar.Seq.Base.index"
] | [] | module MerkleTree.New.High
open FStar.Ghost
open FStar.Seq
module S = FStar.Seq
module U32 = FStar.UInt32
module U8 = FStar.UInt8
module MTS = MerkleTree.Spec
#set-options "--z3rlimit 10 --max_fuel 0 --max_ifuel 0"
type uint32_t = U32.t
type uint8_t = U8.t
type hash (#hsz:pos) = b:Spec.Hash.Definitions.bytes{Seq.length b = hsz}
type hashes (#hsz:pos) = S.seq (hash #hsz)
type hashess (#hsz:pos) = S.seq (hashes #hsz)
noextract
let hash_init (#hsz:pos): hash #hsz =
Seq.create hsz (Lib.IntTypes.u8 0)
val sha256_compress: src1:hash #32 -> src2:hash #32 -> GTot (hash #32)
let sha256_compress = MTS.sha256_compress
/// Facts about sequences
val seq_slice_equal_index:
#a:Type -> s1:S.seq a -> s2:S.seq a ->
i:nat -> j:nat{i <= j && j <= S.length s1 && j <= S.length s2} ->
k:nat{i <= k && k < j} ->
Lemma (requires S.equal (S.slice s1 i j) (S.slice s2 i j))
(ensures S.index s1 k == S.index s2 k)
[SMTPat (S.equal (S.slice s1 i j) (S.slice s2 i j));
SMTPat (S.index s1 k)]
let seq_slice_equal_index #a s1 s2 i j k =
assert (S.index (S.slice s1 i j) (k - i) == S.index (S.slice s2 i j) (k - i))
private val seq_slice_more_equal:
#a:Type -> s1:S.seq a -> s2:S.seq a ->
n:nat -> m:nat{n <= m && m <= S.length s1 && m <= S.length s2} ->
k:nat{n <= k} -> l:nat{k <= l && l <= m} ->
Lemma (requires S.equal (S.slice s1 n m) (S.slice s2 n m))
(ensures S.equal (S.slice s1 k l) (S.slice s2 k l))
[SMTPat (S.equal (S.slice s1 n m) (S.slice s2 n m));
SMTPat (S.equal (S.slice s1 k l) (S.slice s2 k l))]
private let seq_slice_more_equal #a s1 s2 n m k l =
slice_slice s1 n m (k - n) (l - n);
slice_slice s2 n m (k - n) (l - n)
/// Facts about "2"
val remainder_2_not_1_div: n:nat ->
Lemma (requires n % 2 <> 1)
(ensures n / 2 = (n + 1) / 2)
let remainder_2_not_1_div n = ()
val remainder_2_1_div: n:nat ->
Lemma (requires n % 2 = 1)
(ensures n / 2 + 1 = (n + 1) / 2)
let remainder_2_1_div n = ()
/// High-level Merkle tree data structure
noeq type merkle_tree (#hsz:pos) =
| MT: i:nat ->
j:nat{i <= j && j < pow2 32} ->
hs:hashess #hsz {S.length hs = 32} ->
rhs_ok:bool ->
rhs:hashes #hsz {S.length rhs = 32} -> // Rightmost hashes
mroot:hash #hsz ->
hash_fun:MTS.hash_fun_t #hsz ->
merkle_tree #hsz
val mt_not_full (#hsz:pos): merkle_tree #hsz -> GTot bool
let mt_not_full #hsz mt =
MT?.j mt < pow2 32 - 1
val mt_empty (#hsz:pos): merkle_tree #hsz -> GTot bool
let mt_empty #hsz mt =
MT?.j mt = 0
val mt_not_empty (#hsz:pos): merkle_tree #hsz -> GTot bool
let mt_not_empty #hsz mt =
MT?.j mt > 0
/// Well-formedness w.r.t. indices of base hash elements
noextract
val offset_of: i:nat -> Tot nat
let offset_of i =
if i % 2 = 0 then i else i - 1
val hs_wf_elts:
#hsz:pos ->
lv:nat{lv <= 32} ->
hs:hashess #hsz {S.length hs = 32} ->
i:nat -> j:nat{j >= i} ->
GTot Type0 (decreases (32 - lv))
let rec hs_wf_elts #hsz lv hs i j =
if lv = 32 then true
else (let ofs = offset_of i in
S.length (S.index hs lv) == j - ofs /\
hs_wf_elts #hsz (lv + 1) hs (i / 2) (j / 2))
#push-options "--max_fuel 1"
val hs_wf_elts_equal:
#hsz:pos ->
lv:nat{lv <= 32} ->
hs1:hashess #hsz {S.length hs1 = 32} ->
hs2:hashess #hsz {S.length hs2 = 32} ->
i:nat ->
j:nat{j >= i} ->
Lemma (requires hs_wf_elts lv hs1 i j /\
S.equal (S.slice hs1 lv 32) (S.slice hs2 lv 32))
(ensures hs_wf_elts lv hs2 i j)
(decreases (32 - lv))
let rec hs_wf_elts_equal #hsz lv hs1 hs2 i j =
if lv = 32 then ()
else (S.slice_slice hs1 lv 32 1 (32 - lv);
S.slice_slice hs2 lv 32 1 (32 - lv);
assert (S.equal (S.slice hs1 (lv + 1) 32)
(S.slice hs2 (lv + 1) 32));
S.lemma_index_slice hs1 lv 32 0;
S.lemma_index_slice hs2 lv 32 0;
assert (S.index hs1 lv == S.index hs2 lv);
hs_wf_elts_equal (lv + 1) hs1 hs2 (i / 2) (j / 2))
val mt_wf_elts (#hsz:pos): merkle_tree #hsz -> GTot Type0
let mt_wf_elts #_ (MT i j hs _ _ _ _) =
hs_wf_elts 0 hs i j
/// Construction
val hs_wf_elts_empty:
#hsz:pos ->
lv:nat{lv <= 32} ->
Lemma (requires True)
(ensures hs_wf_elts #hsz lv (S.create 32 S.empty) 0 0)
(decreases (32 - lv))
let rec hs_wf_elts_empty #hsz lv =
if lv = 32 then ()
else hs_wf_elts_empty #hsz (lv + 1)
// NOTE: the public function is `create_mt` defined below, which
// builds a tree with an initial hash.
noextract inline_for_extraction
val create_empty_mt (#hsz:pos) (#f:MTS.hash_fun_t #hsz): unit -> GTot (mt:merkle_tree #hsz {mt_wf_elts #hsz mt})
let create_empty_mt #hsz #f _ =
hs_wf_elts_empty #hsz 0;
MT 0 0 (S.create 32 S.empty) false (S.create 32 (hash_init #hsz)) (hash_init #hsz) f
/// Insertion
val hashess_insert:
#hsz:pos ->
lv:nat{lv < 32} ->
i:nat ->
j:nat{i <= j /\ j < pow2 (32 - lv) - 1} ->
hs:hashess #hsz {S.length hs = 32 /\ hs_wf_elts lv hs i j} ->
v:hash #hsz ->
GTot (ihs:hashess #hsz {S.length ihs = 32 /\ hs_wf_elts (lv + 1) ihs (i / 2) (j / 2)})
let hashess_insert #hsz lv i j hs v =
let ihs = S.upd hs lv (S.snoc (S.index hs lv) v) in
hs_wf_elts_equal (lv + 1) hs ihs (i / 2) (j / 2);
ihs
val insert_:
#hsz:pos -> #f:MTS.hash_fun_t #hsz ->
lv:nat{lv < 32} ->
i:nat ->
j:nat{i <= j /\ j < pow2 (32 - lv) - 1} ->
hs:hashess #hsz {S.length hs = 32 /\ hs_wf_elts lv hs i j} ->
acc:hash #hsz ->
GTot (ihs:hashess #hsz {
S.length ihs = 32 /\
hs_wf_elts #hsz lv ihs i (j + 1) /\
S.equal (S.slice hs 0 lv) (S.slice ihs 0 lv)})
(decreases j)
let rec insert_ #hsz #f lv i j hs acc =
let ihs = hashess_insert #hsz lv i j hs acc in
assert (S.equal (S.slice hs 0 lv) (S.slice ihs 0 lv));
if j % 2 = 1 // S.length (S.index hs lv) > 0
then begin
remainder_2_1_div j;
let nacc = f (S.last (S.index hs lv)) acc in
let rihs = insert_ #hsz #f (lv + 1) (i / 2) (j / 2) ihs nacc in
assert (hs_wf_elts #hsz (lv + 1) rihs (i / 2) (j / 2 + 1));
assert (S.equal (S.slice ihs 0 (lv + 1)) (S.slice rihs 0 (lv + 1)));
assert (S.index ihs lv == S.index rihs lv);
assert (S.length (S.index rihs lv) = (j + 1) - offset_of i);
assert (S.equal (S.slice ihs 0 (lv + 1)) (S.slice rihs 0 (lv + 1)));
assert (S.equal (S.slice ihs 0 lv) (S.slice rihs 0 lv));
rihs
end
else ihs
val insert_base:
#hsz:pos -> #f:MTS.hash_fun_t #hsz ->
lv:nat -> i:nat -> j:nat -> hs:hashess #hsz -> acc:hash #hsz ->
Lemma (requires
lv < 32 /\ i <= j /\ j < pow2 (32 - lv) - 1 /\
S.length hs = 32 /\ hs_wf_elts lv hs i j /\
j % 2 <> 1)
(ensures S.equal (insert_ #_ #f lv i j hs acc)
(hashess_insert lv i j hs acc))
let insert_base #_ #_ lv i j hs acc = ()
val insert_rec:
#hsz:pos -> #f:MTS.hash_fun_t #hsz ->
lv:nat -> i:nat -> j:nat -> hs:hashess -> acc:hash ->
Lemma (requires
lv < 32 /\ i <= j /\ j < pow2 (32 - lv) - 1 /\
S.length hs = 32 /\ hs_wf_elts lv hs i j /\
j % 2 == 1)
(ensures
(hs_wf_elts_equal (lv + 1) hs
(hashess_insert lv i j hs acc) (i / 2) (j / 2);
S.equal (insert_ #_ #f lv i j hs acc)
(insert_ #_ #f (lv + 1) (i / 2) (j / 2)
(hashess_insert lv i j hs acc)
(f (S.last (S.index hs lv)) acc))))
let insert_rec #_ #_ lv i j hs acc = ()
val mt_insert:
#hsz:pos ->
mt:merkle_tree #hsz {mt_wf_elts mt /\ mt_not_full mt} -> v:hash #hsz ->
GTot (imt:merkle_tree #hsz{mt_wf_elts #hsz imt})
let mt_insert #hsz mt v =
MT (MT?.i mt)
(MT?.j mt + 1)
(insert_ #_ #(MT?.hash_fun mt) 0 (MT?.i mt) (MT?.j mt) (MT?.hs mt) v)
false
(MT?.rhs mt)
(MT?.mroot mt)
(MT?.hash_fun mt)
val mt_create:
hsz:pos -> f:MTS.hash_fun_t #hsz ->
init:hash #hsz -> GTot (mt:merkle_tree{mt_wf_elts #hsz mt})
let mt_create hsz f init =
mt_insert #_ (create_empty_mt #_ #f ()) init
/// Getting the Merkle root and path
type path (#hsz:pos) = S.seq (hash #hsz)
// Construct the rightmost hashes for a given (incomplete) Merkle tree.
// This function calculates the Merkle root as well, which is the final
// accumulator value.
val construct_rhs:
#hsz:pos -> #f:MTS.hash_fun_t #hsz ->
lv:nat{lv <= 32} ->
hs:hashess #hsz {S.length hs = 32} ->
rhs:hashes #hsz {S.length rhs = 32} ->
i:nat ->
j:nat{
i <= j /\ j < pow2 (32 - lv) /\
hs_wf_elts #hsz lv hs i j} ->
acc:hash #hsz ->
actd:bool ->
GTot (crhs:hashes #hsz {S.length crhs = 32} * (hash #hsz))
(decreases j)
let rec construct_rhs #hsz #f lv hs rhs i j acc actd =
let ofs = offset_of i in
if j = 0 then (rhs, acc)
else
(if j % 2 = 0
then (construct_rhs #_ #f (lv + 1) hs rhs (i / 2) (j / 2) acc actd)
else (let nrhs = if actd then S.upd rhs lv acc else rhs in
let nacc = if actd
then f (S.index (S.index hs lv) (j - 1 - ofs)) acc
else S.index (S.index hs lv) (j - 1 - ofs) in
construct_rhs #_ #f (lv + 1) hs nrhs (i / 2) (j / 2) nacc true))
val construct_rhs_unchanged:
#hsz:pos -> #f:MTS.hash_fun_t #hsz ->
lv:nat{lv <= 32} ->
hs:hashess #hsz {S.length hs = 32} ->
rhs:hashes #hsz {S.length rhs = 32} ->
i:nat ->
j:nat{
i <= j /\ j < pow2 (32 - lv) /\
hs_wf_elts #hsz lv hs i j} ->
acc:hash #hsz ->
actd:bool ->
Lemma (requires True)
(ensures S.equal (S.slice rhs 0 lv)
(S.slice (fst (construct_rhs #_ #f lv hs rhs i j acc actd)) 0 lv))
(decreases j)
let rec construct_rhs_unchanged #hsz #f lv hs rhs i j acc actd =
let ofs = offset_of i in
if j = 0 then ()
else if j % 2 = 0
then (construct_rhs_unchanged #_ #f (lv + 1) hs rhs (i / 2) (j / 2) acc actd;
let rrhs = fst (construct_rhs #_ #f (lv + 1) hs rhs (i / 2) (j / 2) acc actd) in
assert (S.equal (S.slice rhs 0 lv) (S.slice rrhs 0 lv)))
else (let nrhs = if actd then S.upd rhs lv acc else rhs in
let nacc = if actd
then f (S.index (S.index hs lv) (j - 1 - ofs)) acc
else S.index (S.index hs lv) (j - 1 - ofs) in
construct_rhs_unchanged #_ #f (lv + 1) hs nrhs (i / 2) (j / 2) nacc true;
let rrhs = fst (construct_rhs #_ #f (lv + 1) hs nrhs (i / 2) (j / 2) nacc true) in
assert (S.equal (S.slice nrhs 0 lv) (S.slice rrhs 0 lv));
assert (S.equal (S.slice rhs 0 lv) (S.slice nrhs 0 lv)))
val construct_rhs_even:
#hsz:pos -> #f:MTS.hash_fun_t #hsz ->
lv:nat{lv <= 32} ->
hs:hashess #hsz {S.length hs = 32} ->
rhs:hashes #hsz {S.length rhs = 32} ->
i:nat ->
j:nat{
i <= j /\ j < pow2 (32 - lv) /\
hs_wf_elts #hsz lv hs i j} ->
acc:hash #hsz ->
actd:bool ->
Lemma (requires j <> 0 /\ j % 2 = 0)
(ensures construct_rhs #_ #f lv hs rhs i j acc actd ==
construct_rhs #_ #f (lv + 1) hs rhs (i / 2) (j / 2) acc actd)
let construct_rhs_even #_ #_ _ _ _ _ _ _ _ = ()
val construct_rhs_odd:
#hsz:pos -> #f:MTS.hash_fun_t #hsz ->
lv:nat{lv <= 32} ->
hs:hashess #hsz {S.length hs = 32} ->
rhs:hashes #hsz {S.length rhs = 32} ->
i:nat ->
j:nat{
i <= j /\ j < pow2 (32 - lv) /\
hs_wf_elts lv hs i j} ->
acc:hash ->
actd:bool ->
Lemma (requires j % 2 = 1)
(ensures construct_rhs #_ #f lv hs rhs i j acc actd ==
(let ofs = offset_of i in
let nrhs = if actd then S.upd rhs lv acc else rhs in
let nacc = if actd
then f (S.index (S.index hs lv) (j - 1 - ofs)) acc
else S.index (S.index hs lv) (j - 1 - ofs) in
construct_rhs #_ #f (lv + 1) hs nrhs (i / 2) (j / 2) nacc true))
let construct_rhs_odd #_ #_ _ _ _ _ _ _ _ = ()
val mt_get_root:
#hsz:pos ->
mt:merkle_tree #hsz {mt_wf_elts #hsz mt} -> drt:hash #hsz ->
GTot (merkle_tree #hsz * hash #hsz)
let mt_get_root #hsz mt drt =
if MT?.rhs_ok mt then (mt, MT?.mroot mt)
else begin
let (nrhs, rt) = construct_rhs #_ #(MT?.hash_fun mt) 0 (MT?.hs mt) (MT?.rhs mt) (MT?.i mt) (MT?.j mt) drt false in
(MT (MT?.i mt) (MT?.j mt) (MT?.hs mt) true nrhs rt (MT?.hash_fun mt), rt)
end
val mt_get_root_rhs_ok_true:
#hsz:pos ->
mt:merkle_tree #hsz {mt_wf_elts mt} -> drt:hash #hsz ->
Lemma (requires MT?.rhs_ok mt == true)
(ensures mt_get_root #hsz mt drt == (mt, MT?.mroot mt))
let mt_get_root_rhs_ok_true #hsz mt drt = ()
val mt_get_root_rhs_ok_false:
#hsz:pos ->
mt:merkle_tree #hsz {mt_wf_elts mt} -> drt:hash ->
Lemma (requires MT?.rhs_ok mt == false)
(ensures mt_get_root mt drt ==
(let (nrhs, rt) =
construct_rhs #_ #(MT?.hash_fun mt)
0 (MT?.hs mt) (MT?.rhs mt) (MT?.i mt) (MT?.j mt)
drt false in
(MT (MT?.i mt) (MT?.j mt) (MT?.hs mt) true nrhs rt (MT?.hash_fun mt), rt)))
let mt_get_root_rhs_ok_false #_ _ _ = ()
val path_insert: (#hsz:pos) -> p:path #hsz -> hp:hash #hsz -> GTot (path #hsz)
let path_insert #_ p hp = S.snoc p hp
val mt_path_length_step:
k:nat -> j:nat{k <= j} -> actd:bool -> GTot nat
let mt_path_length_step k j actd =
if j = 0 then 0
else (if k % 2 = 0
then (if j = k || (j = k + 1 && not actd) then 0 else 1)
else 1)
val mt_path_length:
k:nat -> j:nat{k <= j} -> actd:bool -> GTot nat
let rec mt_path_length k j actd =
if j = 0 then 0
else (let nactd = actd || (j % 2 = 1) in
mt_path_length_step k j actd +
mt_path_length (k / 2) (j / 2) nactd)
val mt_make_path_step:
#hsz:pos ->
lv:nat{lv <= 32} ->
hs:hashess #hsz {S.length hs = 32} ->
rhs:hashes #hsz {S.length rhs = 32} ->
i:nat ->
j:nat{
j <> 0 /\ i <= j /\ j < pow2 (32 - lv) /\
hs_wf_elts lv hs i j} ->
k:nat{i <= k && k <= j} ->
p:path #hsz ->
actd:bool ->
GTot (path #hsz)
let mt_make_path_step #hsz lv hs rhs i j k p actd =
let ofs = offset_of i in
if k % 2 = 1
then path_insert p (S.index (S.index hs lv) (k - 1 - ofs))
else (if k = j then p
else if k + 1 = j
then (if actd
then path_insert p (S.index rhs lv)
else p)
else path_insert p (S.index (S.index hs lv) (k + 1 - ofs)))
// Construct a Merkle path for a given index `k`, hashes `hs`,
// and rightmost hashes `rhs`.
val mt_get_path_:
#hsz:pos ->
lv:nat{lv <= 32} ->
hs:hashess #hsz {S.length hs = 32} ->
rhs:hashes #hsz {S.length rhs = 32} ->
i:nat ->
j:nat{
i <= j /\ j < pow2 (32 - lv) /\
hs_wf_elts lv hs i j} ->
k:nat{i <= k && k <= j} ->
p:path #hsz ->
actd:bool ->
GTot (np:path #hsz {S.length np = S.length p + mt_path_length k j actd})
(decreases (32 - lv))
let rec mt_get_path_ #hsz lv hs rhs i j k p actd =
let ofs = offset_of i in
if j = 0 then p
else
(let np = mt_make_path_step lv hs rhs i j k p actd in
mt_get_path_ (lv + 1) hs rhs (i / 2) (j / 2) (k / 2) np
(if j % 2 = 0 then actd else true))
val mt_get_path_unchanged:
#hsz:pos ->
lv:nat{lv <= 32} ->
hs:hashess #hsz {S.length hs = 32} ->
rhs:hashes #hsz {S.length rhs = 32} ->
i:nat ->
j:nat{
i <= j /\ j < pow2 (32 - lv) /\
hs_wf_elts #hsz lv hs i j} ->
k:nat{i <= k && k <= j} ->
p:path #hsz ->
actd:bool ->
Lemma (requires True)
(ensures S.equal p (S.slice (mt_get_path_ lv hs rhs i j k p actd)
0 (S.length p)))
(decreases (32 - lv))
let rec mt_get_path_unchanged #hsz lv hs rhs i j k p actd =
let ofs = offset_of i in
if j = 0 then ()
else
(let np = mt_make_path_step lv hs rhs i j k p actd in
assert (S.equal p (S.slice np 0 (S.length p)));
mt_get_path_unchanged (lv + 1) hs rhs (i / 2) (j / 2) (k / 2) np
(if j % 2 = 0 then actd else true))
#push-options "--z3rlimit 20"
val mt_get_path_pull:
#hsz:pos ->
lv:nat{lv <= 32} ->
hs:hashess #hsz {S.length hs = 32} ->
rhs:hashes #hsz {S.length rhs = 32} ->
i:nat ->
j:nat{
i <= j /\ j < pow2 (32 - lv) /\
hs_wf_elts lv hs i j} ->
k:nat{i <= k && k <= j} ->
p:path #hsz ->
actd:bool ->
Lemma (requires True)
(ensures S.equal (mt_get_path_ lv hs rhs i j k p actd)
(S.append p (mt_get_path_ lv hs rhs i j k S.empty actd)))
(decreases (32 - lv))
let rec mt_get_path_pull #hsz lv hs rhs i j k p actd =
let ofs = offset_of i in
if j = 0 then ()
else
(let np = mt_make_path_step lv hs rhs i j k p actd in
let nactd = if j % 2 = 0 then actd else true in
mt_get_path_pull (lv + 1) hs rhs (i / 2) (j / 2) (k / 2) np nactd;
mt_get_path_pull (lv + 1) hs rhs (i / 2) (j / 2) (k / 2)
(mt_make_path_step lv hs rhs i j k S.empty actd) nactd)
#pop-options
val mt_get_path_slice:
#hsz:pos ->
lv:nat{lv <= 32} ->
hs:hashess #hsz {S.length hs = 32} ->
rhs:hashes #hsz {S.length rhs = 32} ->
i:nat ->
j:nat{
i <= j /\ j < pow2 (32 - lv) /\
hs_wf_elts lv hs i j} ->
k:nat{i <= k && k <= j} ->
p:path #hsz ->
actd:bool ->
Lemma (requires True)
(ensures S.equal (S.slice (mt_get_path_ lv hs rhs i j k p actd)
(S.length p) (S.length p + mt_path_length k j actd))
(mt_get_path_ lv hs rhs i j k S.empty actd))
(decreases (32 - lv))
let mt_get_path_slice #hsz lv hs rhs i j k p actd =
mt_get_path_pull lv hs rhs i j k p actd
val mt_get_path:
#hsz:pos ->
mt:merkle_tree #hsz {mt_wf_elts mt} ->
idx:nat{MT?.i mt <= idx /\ idx < MT?.j mt} ->
drt:hash #hsz ->
GTot (nat *
(np:path #hsz {S.length np = 1 + mt_path_length idx (MT?.j mt) false}) *
hash #hsz)
let mt_get_path #hsz mt idx drt =
let (umt, root) = mt_get_root mt drt in
let ofs = offset_of (MT?.i umt) in
let np = path_insert S.empty (S.index (S.index (MT?.hs umt) 0) (idx - ofs)) in
MT?.j umt,
mt_get_path_ 0 (MT?.hs umt) (MT?.rhs umt)
(MT?.i umt) (MT?.j umt) idx np false,
root
/// Flushing
val mt_flush_to_:
#hsz:pos ->
lv:nat{lv < 32} ->
hs:hashess #hsz {S.length hs = 32} ->
pi:nat ->
i:nat{i >= pi} ->
j:nat{
j >= i /\ j < pow2 (32 - lv) /\
hs_wf_elts #hsz lv hs pi j} ->
GTot (fhs:hashess{
S.length fhs = 32 /\
S.equal (S.slice hs 0 lv) (S.slice fhs 0 lv) /\
hs_wf_elts #hsz lv fhs i j})
(decreases i)
let rec mt_flush_to_ #hsz lv hs pi i j =
let oi = offset_of i in
let opi = offset_of pi in
if oi = opi then hs
else (let ofs = oi - opi in
let hvec = S.index hs lv in
let flushed = S.slice hvec ofs (S.length hvec) in
let nhs = S.upd hs lv flushed in
hs_wf_elts_equal (lv + 1) hs nhs (pi / 2) (j / 2);
mt_flush_to_ (lv + 1) nhs (pi / 2) (i / 2) (j / 2))
val mt_flush_to_rec:
#hsz:pos ->
lv:nat{lv < 32} ->
hs:hashess #hsz {S.length hs = 32} ->
pi:nat ->
i:nat{i >= pi} ->
j:nat{
j >= i /\ j < pow2 (32 - lv) /\
hs_wf_elts lv hs pi j} ->
Lemma (requires offset_of i <> offset_of pi)
(ensures mt_flush_to_ lv hs pi i j ==
(let ofs = offset_of i - offset_of pi in
let hvec = S.index hs lv in
let flushed = S.slice hvec ofs (S.length hvec) in
let nhs = S.upd hs lv flushed in
hs_wf_elts_equal (lv + 1) hs nhs (pi / 2) (j / 2);
mt_flush_to_ #hsz (lv + 1) nhs (pi / 2) (i / 2) (j / 2)))
let mt_flush_to_rec #hsz lv hs pi i j = ()
val mt_flush_to:
#hsz:pos ->
mt:merkle_tree #hsz {mt_wf_elts mt} ->
idx:nat{idx >= MT?.i mt /\ idx < MT?.j mt} ->
GTot (fmt:merkle_tree{mt_wf_elts #hsz fmt})
let mt_flush_to #hsz mt idx =
let fhs = mt_flush_to_ #hsz 0 (MT?.hs mt) (MT?.i mt) idx (MT?.j mt) in
MT idx (MT?.j mt) fhs (MT?.rhs_ok mt) (MT?.rhs mt) (MT?.mroot mt) (MT?.hash_fun mt)
val mt_flush:
#hsz:pos ->
mt:merkle_tree #hsz {mt_wf_elts mt /\ MT?.j mt > MT?.i mt} ->
GTot (fmt:merkle_tree{mt_wf_elts #hsz fmt})
let mt_flush #hsz mt =
mt_flush_to mt (MT?.j mt - 1)
#push-options "--max_fuel 2"
/// Retraction
val mt_retract_to_:
#hsz:pos ->
hs:hashess #hsz {S.length hs = 32} ->
lv:nat{lv < S.length hs} ->
i:nat ->
s:nat -> // s is the first index excluded from nhs
j:nat{ i <= s /\ s <= j /\
j < pow2 (S.length hs - lv) /\
hs_wf_elts lv hs i j} ->
GTot (nhs:hashess #hsz {
S.length nhs = S.length hs /\
S.equal (S.slice hs 0 lv) (S.slice nhs 0 lv) /\
hs_wf_elts #hsz lv nhs i s})
(decreases (S.length hs - lv)) | false | false | MerkleTree.New.High.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 2,
"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": 10,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val mt_retract_to_:
#hsz:pos ->
hs:hashess #hsz {S.length hs = 32} ->
lv:nat{lv < S.length hs} ->
i:nat ->
s:nat -> // s is the first index excluded from nhs
j:nat{ i <= s /\ s <= j /\
j < pow2 (S.length hs - lv) /\
hs_wf_elts lv hs i j} ->
GTot (nhs:hashess #hsz {
S.length nhs = S.length hs /\
S.equal (S.slice hs 0 lv) (S.slice nhs 0 lv) /\
hs_wf_elts #hsz lv nhs i s})
(decreases (S.length hs - lv)) | [
"recursion"
] | MerkleTree.New.High.mt_retract_to_ | {
"file_name": "src/MerkleTree.New.High.fst",
"git_rev": "3b0f086655c145aa23f58a97259ebf4cf112a4a3",
"git_url": "https://github.com/hacl-star/merkle-tree.git",
"project_name": "merkle-tree"
} |
hs: MerkleTree.New.High.hashess{FStar.Seq.Base.length hs = 32} ->
lv: Prims.nat{lv < FStar.Seq.Base.length hs} ->
i: Prims.nat ->
s: Prims.nat ->
j:
Prims.nat
{ i <= s /\ s <= j /\ j < Prims.pow2 (FStar.Seq.Base.length hs - lv) /\
MerkleTree.New.High.hs_wf_elts lv hs i j }
-> Prims.GTot
(nhs:
MerkleTree.New.High.hashess
{ FStar.Seq.Base.length nhs = FStar.Seq.Base.length hs /\
FStar.Seq.Base.equal (FStar.Seq.Base.slice hs 0 lv) (FStar.Seq.Base.slice nhs 0 lv) /\
MerkleTree.New.High.hs_wf_elts lv nhs i s }) | {
"end_col": 5,
"end_line": 634,
"start_col": 2,
"start_line": 619
} |
Prims.GTot | val mt_flush_to_:
#hsz:pos ->
lv:nat{lv < 32} ->
hs:hashess #hsz {S.length hs = 32} ->
pi:nat ->
i:nat{i >= pi} ->
j:nat{
j >= i /\ j < pow2 (32 - lv) /\
hs_wf_elts #hsz lv hs pi j} ->
GTot (fhs:hashess{
S.length fhs = 32 /\
S.equal (S.slice hs 0 lv) (S.slice fhs 0 lv) /\
hs_wf_elts #hsz lv fhs i j})
(decreases i) | [
{
"abbrev": true,
"full_module": "MerkleTree.Spec",
"short_module": "MTS"
},
{
"abbrev": true,
"full_module": "FStar.UInt8",
"short_module": "U8"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "S"
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Ghost",
"short_module": null
},
{
"abbrev": false,
"full_module": "MerkleTree.New",
"short_module": null
},
{
"abbrev": false,
"full_module": "MerkleTree.New",
"short_module": null
},
{
"abbrev": 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 mt_flush_to_ #hsz lv hs pi i j =
let oi = offset_of i in
let opi = offset_of pi in
if oi = opi then hs
else (let ofs = oi - opi in
let hvec = S.index hs lv in
let flushed = S.slice hvec ofs (S.length hvec) in
let nhs = S.upd hs lv flushed in
hs_wf_elts_equal (lv + 1) hs nhs (pi / 2) (j / 2);
mt_flush_to_ (lv + 1) nhs (pi / 2) (i / 2) (j / 2)) | val mt_flush_to_:
#hsz:pos ->
lv:nat{lv < 32} ->
hs:hashess #hsz {S.length hs = 32} ->
pi:nat ->
i:nat{i >= pi} ->
j:nat{
j >= i /\ j < pow2 (32 - lv) /\
hs_wf_elts #hsz lv hs pi j} ->
GTot (fhs:hashess{
S.length fhs = 32 /\
S.equal (S.slice hs 0 lv) (S.slice fhs 0 lv) /\
hs_wf_elts #hsz lv fhs i j})
(decreases i)
let rec mt_flush_to_ #hsz lv hs pi i j = | false | null | false | let oi = offset_of i in
let opi = offset_of pi in
if oi = opi
then hs
else
(let ofs = oi - opi in
let hvec = S.index hs lv in
let flushed = S.slice hvec ofs (S.length hvec) in
let nhs = S.upd hs lv flushed in
hs_wf_elts_equal (lv + 1) hs nhs (pi / 2) (j / 2);
mt_flush_to_ (lv + 1) nhs (pi / 2) (i / 2) (j / 2)) | {
"checked_file": "MerkleTree.New.High.fst.checked",
"dependencies": [
"Spec.Hash.Definitions.fst.checked",
"prims.fst.checked",
"MerkleTree.Spec.fst.checked",
"Lib.IntTypes.fsti.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "MerkleTree.New.High.fst"
} | [
"sometrivial",
""
] | [
"Prims.pos",
"Prims.nat",
"Prims.b2t",
"Prims.op_LessThan",
"MerkleTree.New.High.hashess",
"Prims.op_Equality",
"Prims.int",
"FStar.Seq.Base.length",
"MerkleTree.New.High.hashes",
"Prims.op_GreaterThanOrEqual",
"Prims.l_and",
"Prims.pow2",
"Prims.op_Subtraction",
"MerkleTree.New.High.hs_wf_elts",
"Prims.bool",
"MerkleTree.New.High.mt_flush_to_",
"Prims.op_Addition",
"Prims.op_Division",
"Prims.unit",
"MerkleTree.New.High.hs_wf_elts_equal",
"FStar.Seq.Base.seq",
"FStar.Seq.Base.upd",
"MerkleTree.New.High.hash",
"FStar.Seq.Base.slice",
"FStar.Seq.Base.index",
"FStar.Seq.Base.equal",
"MerkleTree.New.High.offset_of"
] | [] | module MerkleTree.New.High
open FStar.Ghost
open FStar.Seq
module S = FStar.Seq
module U32 = FStar.UInt32
module U8 = FStar.UInt8
module MTS = MerkleTree.Spec
#set-options "--z3rlimit 10 --max_fuel 0 --max_ifuel 0"
type uint32_t = U32.t
type uint8_t = U8.t
type hash (#hsz:pos) = b:Spec.Hash.Definitions.bytes{Seq.length b = hsz}
type hashes (#hsz:pos) = S.seq (hash #hsz)
type hashess (#hsz:pos) = S.seq (hashes #hsz)
noextract
let hash_init (#hsz:pos): hash #hsz =
Seq.create hsz (Lib.IntTypes.u8 0)
val sha256_compress: src1:hash #32 -> src2:hash #32 -> GTot (hash #32)
let sha256_compress = MTS.sha256_compress
/// Facts about sequences
val seq_slice_equal_index:
#a:Type -> s1:S.seq a -> s2:S.seq a ->
i:nat -> j:nat{i <= j && j <= S.length s1 && j <= S.length s2} ->
k:nat{i <= k && k < j} ->
Lemma (requires S.equal (S.slice s1 i j) (S.slice s2 i j))
(ensures S.index s1 k == S.index s2 k)
[SMTPat (S.equal (S.slice s1 i j) (S.slice s2 i j));
SMTPat (S.index s1 k)]
let seq_slice_equal_index #a s1 s2 i j k =
assert (S.index (S.slice s1 i j) (k - i) == S.index (S.slice s2 i j) (k - i))
private val seq_slice_more_equal:
#a:Type -> s1:S.seq a -> s2:S.seq a ->
n:nat -> m:nat{n <= m && m <= S.length s1 && m <= S.length s2} ->
k:nat{n <= k} -> l:nat{k <= l && l <= m} ->
Lemma (requires S.equal (S.slice s1 n m) (S.slice s2 n m))
(ensures S.equal (S.slice s1 k l) (S.slice s2 k l))
[SMTPat (S.equal (S.slice s1 n m) (S.slice s2 n m));
SMTPat (S.equal (S.slice s1 k l) (S.slice s2 k l))]
private let seq_slice_more_equal #a s1 s2 n m k l =
slice_slice s1 n m (k - n) (l - n);
slice_slice s2 n m (k - n) (l - n)
/// Facts about "2"
val remainder_2_not_1_div: n:nat ->
Lemma (requires n % 2 <> 1)
(ensures n / 2 = (n + 1) / 2)
let remainder_2_not_1_div n = ()
val remainder_2_1_div: n:nat ->
Lemma (requires n % 2 = 1)
(ensures n / 2 + 1 = (n + 1) / 2)
let remainder_2_1_div n = ()
/// High-level Merkle tree data structure
noeq type merkle_tree (#hsz:pos) =
| MT: i:nat ->
j:nat{i <= j && j < pow2 32} ->
hs:hashess #hsz {S.length hs = 32} ->
rhs_ok:bool ->
rhs:hashes #hsz {S.length rhs = 32} -> // Rightmost hashes
mroot:hash #hsz ->
hash_fun:MTS.hash_fun_t #hsz ->
merkle_tree #hsz
val mt_not_full (#hsz:pos): merkle_tree #hsz -> GTot bool
let mt_not_full #hsz mt =
MT?.j mt < pow2 32 - 1
val mt_empty (#hsz:pos): merkle_tree #hsz -> GTot bool
let mt_empty #hsz mt =
MT?.j mt = 0
val mt_not_empty (#hsz:pos): merkle_tree #hsz -> GTot bool
let mt_not_empty #hsz mt =
MT?.j mt > 0
/// Well-formedness w.r.t. indices of base hash elements
noextract
val offset_of: i:nat -> Tot nat
let offset_of i =
if i % 2 = 0 then i else i - 1
val hs_wf_elts:
#hsz:pos ->
lv:nat{lv <= 32} ->
hs:hashess #hsz {S.length hs = 32} ->
i:nat -> j:nat{j >= i} ->
GTot Type0 (decreases (32 - lv))
let rec hs_wf_elts #hsz lv hs i j =
if lv = 32 then true
else (let ofs = offset_of i in
S.length (S.index hs lv) == j - ofs /\
hs_wf_elts #hsz (lv + 1) hs (i / 2) (j / 2))
#push-options "--max_fuel 1"
val hs_wf_elts_equal:
#hsz:pos ->
lv:nat{lv <= 32} ->
hs1:hashess #hsz {S.length hs1 = 32} ->
hs2:hashess #hsz {S.length hs2 = 32} ->
i:nat ->
j:nat{j >= i} ->
Lemma (requires hs_wf_elts lv hs1 i j /\
S.equal (S.slice hs1 lv 32) (S.slice hs2 lv 32))
(ensures hs_wf_elts lv hs2 i j)
(decreases (32 - lv))
let rec hs_wf_elts_equal #hsz lv hs1 hs2 i j =
if lv = 32 then ()
else (S.slice_slice hs1 lv 32 1 (32 - lv);
S.slice_slice hs2 lv 32 1 (32 - lv);
assert (S.equal (S.slice hs1 (lv + 1) 32)
(S.slice hs2 (lv + 1) 32));
S.lemma_index_slice hs1 lv 32 0;
S.lemma_index_slice hs2 lv 32 0;
assert (S.index hs1 lv == S.index hs2 lv);
hs_wf_elts_equal (lv + 1) hs1 hs2 (i / 2) (j / 2))
val mt_wf_elts (#hsz:pos): merkle_tree #hsz -> GTot Type0
let mt_wf_elts #_ (MT i j hs _ _ _ _) =
hs_wf_elts 0 hs i j
/// Construction
val hs_wf_elts_empty:
#hsz:pos ->
lv:nat{lv <= 32} ->
Lemma (requires True)
(ensures hs_wf_elts #hsz lv (S.create 32 S.empty) 0 0)
(decreases (32 - lv))
let rec hs_wf_elts_empty #hsz lv =
if lv = 32 then ()
else hs_wf_elts_empty #hsz (lv + 1)
// NOTE: the public function is `create_mt` defined below, which
// builds a tree with an initial hash.
noextract inline_for_extraction
val create_empty_mt (#hsz:pos) (#f:MTS.hash_fun_t #hsz): unit -> GTot (mt:merkle_tree #hsz {mt_wf_elts #hsz mt})
let create_empty_mt #hsz #f _ =
hs_wf_elts_empty #hsz 0;
MT 0 0 (S.create 32 S.empty) false (S.create 32 (hash_init #hsz)) (hash_init #hsz) f
/// Insertion
val hashess_insert:
#hsz:pos ->
lv:nat{lv < 32} ->
i:nat ->
j:nat{i <= j /\ j < pow2 (32 - lv) - 1} ->
hs:hashess #hsz {S.length hs = 32 /\ hs_wf_elts lv hs i j} ->
v:hash #hsz ->
GTot (ihs:hashess #hsz {S.length ihs = 32 /\ hs_wf_elts (lv + 1) ihs (i / 2) (j / 2)})
let hashess_insert #hsz lv i j hs v =
let ihs = S.upd hs lv (S.snoc (S.index hs lv) v) in
hs_wf_elts_equal (lv + 1) hs ihs (i / 2) (j / 2);
ihs
val insert_:
#hsz:pos -> #f:MTS.hash_fun_t #hsz ->
lv:nat{lv < 32} ->
i:nat ->
j:nat{i <= j /\ j < pow2 (32 - lv) - 1} ->
hs:hashess #hsz {S.length hs = 32 /\ hs_wf_elts lv hs i j} ->
acc:hash #hsz ->
GTot (ihs:hashess #hsz {
S.length ihs = 32 /\
hs_wf_elts #hsz lv ihs i (j + 1) /\
S.equal (S.slice hs 0 lv) (S.slice ihs 0 lv)})
(decreases j)
let rec insert_ #hsz #f lv i j hs acc =
let ihs = hashess_insert #hsz lv i j hs acc in
assert (S.equal (S.slice hs 0 lv) (S.slice ihs 0 lv));
if j % 2 = 1 // S.length (S.index hs lv) > 0
then begin
remainder_2_1_div j;
let nacc = f (S.last (S.index hs lv)) acc in
let rihs = insert_ #hsz #f (lv + 1) (i / 2) (j / 2) ihs nacc in
assert (hs_wf_elts #hsz (lv + 1) rihs (i / 2) (j / 2 + 1));
assert (S.equal (S.slice ihs 0 (lv + 1)) (S.slice rihs 0 (lv + 1)));
assert (S.index ihs lv == S.index rihs lv);
assert (S.length (S.index rihs lv) = (j + 1) - offset_of i);
assert (S.equal (S.slice ihs 0 (lv + 1)) (S.slice rihs 0 (lv + 1)));
assert (S.equal (S.slice ihs 0 lv) (S.slice rihs 0 lv));
rihs
end
else ihs
val insert_base:
#hsz:pos -> #f:MTS.hash_fun_t #hsz ->
lv:nat -> i:nat -> j:nat -> hs:hashess #hsz -> acc:hash #hsz ->
Lemma (requires
lv < 32 /\ i <= j /\ j < pow2 (32 - lv) - 1 /\
S.length hs = 32 /\ hs_wf_elts lv hs i j /\
j % 2 <> 1)
(ensures S.equal (insert_ #_ #f lv i j hs acc)
(hashess_insert lv i j hs acc))
let insert_base #_ #_ lv i j hs acc = ()
val insert_rec:
#hsz:pos -> #f:MTS.hash_fun_t #hsz ->
lv:nat -> i:nat -> j:nat -> hs:hashess -> acc:hash ->
Lemma (requires
lv < 32 /\ i <= j /\ j < pow2 (32 - lv) - 1 /\
S.length hs = 32 /\ hs_wf_elts lv hs i j /\
j % 2 == 1)
(ensures
(hs_wf_elts_equal (lv + 1) hs
(hashess_insert lv i j hs acc) (i / 2) (j / 2);
S.equal (insert_ #_ #f lv i j hs acc)
(insert_ #_ #f (lv + 1) (i / 2) (j / 2)
(hashess_insert lv i j hs acc)
(f (S.last (S.index hs lv)) acc))))
let insert_rec #_ #_ lv i j hs acc = ()
val mt_insert:
#hsz:pos ->
mt:merkle_tree #hsz {mt_wf_elts mt /\ mt_not_full mt} -> v:hash #hsz ->
GTot (imt:merkle_tree #hsz{mt_wf_elts #hsz imt})
let mt_insert #hsz mt v =
MT (MT?.i mt)
(MT?.j mt + 1)
(insert_ #_ #(MT?.hash_fun mt) 0 (MT?.i mt) (MT?.j mt) (MT?.hs mt) v)
false
(MT?.rhs mt)
(MT?.mroot mt)
(MT?.hash_fun mt)
val mt_create:
hsz:pos -> f:MTS.hash_fun_t #hsz ->
init:hash #hsz -> GTot (mt:merkle_tree{mt_wf_elts #hsz mt})
let mt_create hsz f init =
mt_insert #_ (create_empty_mt #_ #f ()) init
/// Getting the Merkle root and path
type path (#hsz:pos) = S.seq (hash #hsz)
// Construct the rightmost hashes for a given (incomplete) Merkle tree.
// This function calculates the Merkle root as well, which is the final
// accumulator value.
val construct_rhs:
#hsz:pos -> #f:MTS.hash_fun_t #hsz ->
lv:nat{lv <= 32} ->
hs:hashess #hsz {S.length hs = 32} ->
rhs:hashes #hsz {S.length rhs = 32} ->
i:nat ->
j:nat{
i <= j /\ j < pow2 (32 - lv) /\
hs_wf_elts #hsz lv hs i j} ->
acc:hash #hsz ->
actd:bool ->
GTot (crhs:hashes #hsz {S.length crhs = 32} * (hash #hsz))
(decreases j)
let rec construct_rhs #hsz #f lv hs rhs i j acc actd =
let ofs = offset_of i in
if j = 0 then (rhs, acc)
else
(if j % 2 = 0
then (construct_rhs #_ #f (lv + 1) hs rhs (i / 2) (j / 2) acc actd)
else (let nrhs = if actd then S.upd rhs lv acc else rhs in
let nacc = if actd
then f (S.index (S.index hs lv) (j - 1 - ofs)) acc
else S.index (S.index hs lv) (j - 1 - ofs) in
construct_rhs #_ #f (lv + 1) hs nrhs (i / 2) (j / 2) nacc true))
val construct_rhs_unchanged:
#hsz:pos -> #f:MTS.hash_fun_t #hsz ->
lv:nat{lv <= 32} ->
hs:hashess #hsz {S.length hs = 32} ->
rhs:hashes #hsz {S.length rhs = 32} ->
i:nat ->
j:nat{
i <= j /\ j < pow2 (32 - lv) /\
hs_wf_elts #hsz lv hs i j} ->
acc:hash #hsz ->
actd:bool ->
Lemma (requires True)
(ensures S.equal (S.slice rhs 0 lv)
(S.slice (fst (construct_rhs #_ #f lv hs rhs i j acc actd)) 0 lv))
(decreases j)
let rec construct_rhs_unchanged #hsz #f lv hs rhs i j acc actd =
let ofs = offset_of i in
if j = 0 then ()
else if j % 2 = 0
then (construct_rhs_unchanged #_ #f (lv + 1) hs rhs (i / 2) (j / 2) acc actd;
let rrhs = fst (construct_rhs #_ #f (lv + 1) hs rhs (i / 2) (j / 2) acc actd) in
assert (S.equal (S.slice rhs 0 lv) (S.slice rrhs 0 lv)))
else (let nrhs = if actd then S.upd rhs lv acc else rhs in
let nacc = if actd
then f (S.index (S.index hs lv) (j - 1 - ofs)) acc
else S.index (S.index hs lv) (j - 1 - ofs) in
construct_rhs_unchanged #_ #f (lv + 1) hs nrhs (i / 2) (j / 2) nacc true;
let rrhs = fst (construct_rhs #_ #f (lv + 1) hs nrhs (i / 2) (j / 2) nacc true) in
assert (S.equal (S.slice nrhs 0 lv) (S.slice rrhs 0 lv));
assert (S.equal (S.slice rhs 0 lv) (S.slice nrhs 0 lv)))
val construct_rhs_even:
#hsz:pos -> #f:MTS.hash_fun_t #hsz ->
lv:nat{lv <= 32} ->
hs:hashess #hsz {S.length hs = 32} ->
rhs:hashes #hsz {S.length rhs = 32} ->
i:nat ->
j:nat{
i <= j /\ j < pow2 (32 - lv) /\
hs_wf_elts #hsz lv hs i j} ->
acc:hash #hsz ->
actd:bool ->
Lemma (requires j <> 0 /\ j % 2 = 0)
(ensures construct_rhs #_ #f lv hs rhs i j acc actd ==
construct_rhs #_ #f (lv + 1) hs rhs (i / 2) (j / 2) acc actd)
let construct_rhs_even #_ #_ _ _ _ _ _ _ _ = ()
val construct_rhs_odd:
#hsz:pos -> #f:MTS.hash_fun_t #hsz ->
lv:nat{lv <= 32} ->
hs:hashess #hsz {S.length hs = 32} ->
rhs:hashes #hsz {S.length rhs = 32} ->
i:nat ->
j:nat{
i <= j /\ j < pow2 (32 - lv) /\
hs_wf_elts lv hs i j} ->
acc:hash ->
actd:bool ->
Lemma (requires j % 2 = 1)
(ensures construct_rhs #_ #f lv hs rhs i j acc actd ==
(let ofs = offset_of i in
let nrhs = if actd then S.upd rhs lv acc else rhs in
let nacc = if actd
then f (S.index (S.index hs lv) (j - 1 - ofs)) acc
else S.index (S.index hs lv) (j - 1 - ofs) in
construct_rhs #_ #f (lv + 1) hs nrhs (i / 2) (j / 2) nacc true))
let construct_rhs_odd #_ #_ _ _ _ _ _ _ _ = ()
val mt_get_root:
#hsz:pos ->
mt:merkle_tree #hsz {mt_wf_elts #hsz mt} -> drt:hash #hsz ->
GTot (merkle_tree #hsz * hash #hsz)
let mt_get_root #hsz mt drt =
if MT?.rhs_ok mt then (mt, MT?.mroot mt)
else begin
let (nrhs, rt) = construct_rhs #_ #(MT?.hash_fun mt) 0 (MT?.hs mt) (MT?.rhs mt) (MT?.i mt) (MT?.j mt) drt false in
(MT (MT?.i mt) (MT?.j mt) (MT?.hs mt) true nrhs rt (MT?.hash_fun mt), rt)
end
val mt_get_root_rhs_ok_true:
#hsz:pos ->
mt:merkle_tree #hsz {mt_wf_elts mt} -> drt:hash #hsz ->
Lemma (requires MT?.rhs_ok mt == true)
(ensures mt_get_root #hsz mt drt == (mt, MT?.mroot mt))
let mt_get_root_rhs_ok_true #hsz mt drt = ()
val mt_get_root_rhs_ok_false:
#hsz:pos ->
mt:merkle_tree #hsz {mt_wf_elts mt} -> drt:hash ->
Lemma (requires MT?.rhs_ok mt == false)
(ensures mt_get_root mt drt ==
(let (nrhs, rt) =
construct_rhs #_ #(MT?.hash_fun mt)
0 (MT?.hs mt) (MT?.rhs mt) (MT?.i mt) (MT?.j mt)
drt false in
(MT (MT?.i mt) (MT?.j mt) (MT?.hs mt) true nrhs rt (MT?.hash_fun mt), rt)))
let mt_get_root_rhs_ok_false #_ _ _ = ()
val path_insert: (#hsz:pos) -> p:path #hsz -> hp:hash #hsz -> GTot (path #hsz)
let path_insert #_ p hp = S.snoc p hp
val mt_path_length_step:
k:nat -> j:nat{k <= j} -> actd:bool -> GTot nat
let mt_path_length_step k j actd =
if j = 0 then 0
else (if k % 2 = 0
then (if j = k || (j = k + 1 && not actd) then 0 else 1)
else 1)
val mt_path_length:
k:nat -> j:nat{k <= j} -> actd:bool -> GTot nat
let rec mt_path_length k j actd =
if j = 0 then 0
else (let nactd = actd || (j % 2 = 1) in
mt_path_length_step k j actd +
mt_path_length (k / 2) (j / 2) nactd)
val mt_make_path_step:
#hsz:pos ->
lv:nat{lv <= 32} ->
hs:hashess #hsz {S.length hs = 32} ->
rhs:hashes #hsz {S.length rhs = 32} ->
i:nat ->
j:nat{
j <> 0 /\ i <= j /\ j < pow2 (32 - lv) /\
hs_wf_elts lv hs i j} ->
k:nat{i <= k && k <= j} ->
p:path #hsz ->
actd:bool ->
GTot (path #hsz)
let mt_make_path_step #hsz lv hs rhs i j k p actd =
let ofs = offset_of i in
if k % 2 = 1
then path_insert p (S.index (S.index hs lv) (k - 1 - ofs))
else (if k = j then p
else if k + 1 = j
then (if actd
then path_insert p (S.index rhs lv)
else p)
else path_insert p (S.index (S.index hs lv) (k + 1 - ofs)))
// Construct a Merkle path for a given index `k`, hashes `hs`,
// and rightmost hashes `rhs`.
val mt_get_path_:
#hsz:pos ->
lv:nat{lv <= 32} ->
hs:hashess #hsz {S.length hs = 32} ->
rhs:hashes #hsz {S.length rhs = 32} ->
i:nat ->
j:nat{
i <= j /\ j < pow2 (32 - lv) /\
hs_wf_elts lv hs i j} ->
k:nat{i <= k && k <= j} ->
p:path #hsz ->
actd:bool ->
GTot (np:path #hsz {S.length np = S.length p + mt_path_length k j actd})
(decreases (32 - lv))
let rec mt_get_path_ #hsz lv hs rhs i j k p actd =
let ofs = offset_of i in
if j = 0 then p
else
(let np = mt_make_path_step lv hs rhs i j k p actd in
mt_get_path_ (lv + 1) hs rhs (i / 2) (j / 2) (k / 2) np
(if j % 2 = 0 then actd else true))
val mt_get_path_unchanged:
#hsz:pos ->
lv:nat{lv <= 32} ->
hs:hashess #hsz {S.length hs = 32} ->
rhs:hashes #hsz {S.length rhs = 32} ->
i:nat ->
j:nat{
i <= j /\ j < pow2 (32 - lv) /\
hs_wf_elts #hsz lv hs i j} ->
k:nat{i <= k && k <= j} ->
p:path #hsz ->
actd:bool ->
Lemma (requires True)
(ensures S.equal p (S.slice (mt_get_path_ lv hs rhs i j k p actd)
0 (S.length p)))
(decreases (32 - lv))
let rec mt_get_path_unchanged #hsz lv hs rhs i j k p actd =
let ofs = offset_of i in
if j = 0 then ()
else
(let np = mt_make_path_step lv hs rhs i j k p actd in
assert (S.equal p (S.slice np 0 (S.length p)));
mt_get_path_unchanged (lv + 1) hs rhs (i / 2) (j / 2) (k / 2) np
(if j % 2 = 0 then actd else true))
#push-options "--z3rlimit 20"
val mt_get_path_pull:
#hsz:pos ->
lv:nat{lv <= 32} ->
hs:hashess #hsz {S.length hs = 32} ->
rhs:hashes #hsz {S.length rhs = 32} ->
i:nat ->
j:nat{
i <= j /\ j < pow2 (32 - lv) /\
hs_wf_elts lv hs i j} ->
k:nat{i <= k && k <= j} ->
p:path #hsz ->
actd:bool ->
Lemma (requires True)
(ensures S.equal (mt_get_path_ lv hs rhs i j k p actd)
(S.append p (mt_get_path_ lv hs rhs i j k S.empty actd)))
(decreases (32 - lv))
let rec mt_get_path_pull #hsz lv hs rhs i j k p actd =
let ofs = offset_of i in
if j = 0 then ()
else
(let np = mt_make_path_step lv hs rhs i j k p actd in
let nactd = if j % 2 = 0 then actd else true in
mt_get_path_pull (lv + 1) hs rhs (i / 2) (j / 2) (k / 2) np nactd;
mt_get_path_pull (lv + 1) hs rhs (i / 2) (j / 2) (k / 2)
(mt_make_path_step lv hs rhs i j k S.empty actd) nactd)
#pop-options
val mt_get_path_slice:
#hsz:pos ->
lv:nat{lv <= 32} ->
hs:hashess #hsz {S.length hs = 32} ->
rhs:hashes #hsz {S.length rhs = 32} ->
i:nat ->
j:nat{
i <= j /\ j < pow2 (32 - lv) /\
hs_wf_elts lv hs i j} ->
k:nat{i <= k && k <= j} ->
p:path #hsz ->
actd:bool ->
Lemma (requires True)
(ensures S.equal (S.slice (mt_get_path_ lv hs rhs i j k p actd)
(S.length p) (S.length p + mt_path_length k j actd))
(mt_get_path_ lv hs rhs i j k S.empty actd))
(decreases (32 - lv))
let mt_get_path_slice #hsz lv hs rhs i j k p actd =
mt_get_path_pull lv hs rhs i j k p actd
val mt_get_path:
#hsz:pos ->
mt:merkle_tree #hsz {mt_wf_elts mt} ->
idx:nat{MT?.i mt <= idx /\ idx < MT?.j mt} ->
drt:hash #hsz ->
GTot (nat *
(np:path #hsz {S.length np = 1 + mt_path_length idx (MT?.j mt) false}) *
hash #hsz)
let mt_get_path #hsz mt idx drt =
let (umt, root) = mt_get_root mt drt in
let ofs = offset_of (MT?.i umt) in
let np = path_insert S.empty (S.index (S.index (MT?.hs umt) 0) (idx - ofs)) in
MT?.j umt,
mt_get_path_ 0 (MT?.hs umt) (MT?.rhs umt)
(MT?.i umt) (MT?.j umt) idx np false,
root
/// Flushing
val mt_flush_to_:
#hsz:pos ->
lv:nat{lv < 32} ->
hs:hashess #hsz {S.length hs = 32} ->
pi:nat ->
i:nat{i >= pi} ->
j:nat{
j >= i /\ j < pow2 (32 - lv) /\
hs_wf_elts #hsz lv hs pi j} ->
GTot (fhs:hashess{
S.length fhs = 32 /\
S.equal (S.slice hs 0 lv) (S.slice fhs 0 lv) /\
hs_wf_elts #hsz lv fhs i j}) | false | false | MerkleTree.New.High.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 1,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 10,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val mt_flush_to_:
#hsz:pos ->
lv:nat{lv < 32} ->
hs:hashess #hsz {S.length hs = 32} ->
pi:nat ->
i:nat{i >= pi} ->
j:nat{
j >= i /\ j < pow2 (32 - lv) /\
hs_wf_elts #hsz lv hs pi j} ->
GTot (fhs:hashess{
S.length fhs = 32 /\
S.equal (S.slice hs 0 lv) (S.slice fhs 0 lv) /\
hs_wf_elts #hsz lv fhs i j})
(decreases i) | [
"recursion"
] | MerkleTree.New.High.mt_flush_to_ | {
"file_name": "src/MerkleTree.New.High.fst",
"git_rev": "3b0f086655c145aa23f58a97259ebf4cf112a4a3",
"git_url": "https://github.com/hacl-star/merkle-tree.git",
"project_name": "merkle-tree"
} |
lv: Prims.nat{lv < 32} ->
hs: MerkleTree.New.High.hashess{FStar.Seq.Base.length hs = 32} ->
pi: Prims.nat ->
i: Prims.nat{i >= pi} ->
j: Prims.nat{j >= i /\ j < Prims.pow2 (32 - lv) /\ MerkleTree.New.High.hs_wf_elts lv hs pi j}
-> Prims.GTot
(fhs:
MerkleTree.New.High.hashess
{ FStar.Seq.Base.length fhs = 32 /\
FStar.Seq.Base.equal (FStar.Seq.Base.slice hs 0 lv) (FStar.Seq.Base.slice fhs 0 lv) /\
MerkleTree.New.High.hs_wf_elts lv fhs i j }) | {
"end_col": 58,
"end_line": 563,
"start_col": 40,
"start_line": 554
} |
FStar.Pervasives.Lemma | val mt_get_path_unchanged:
#hsz:pos ->
lv:nat{lv <= 32} ->
hs:hashess #hsz {S.length hs = 32} ->
rhs:hashes #hsz {S.length rhs = 32} ->
i:nat ->
j:nat{
i <= j /\ j < pow2 (32 - lv) /\
hs_wf_elts #hsz lv hs i j} ->
k:nat{i <= k && k <= j} ->
p:path #hsz ->
actd:bool ->
Lemma (requires True)
(ensures S.equal p (S.slice (mt_get_path_ lv hs rhs i j k p actd)
0 (S.length p)))
(decreases (32 - lv)) | [
{
"abbrev": true,
"full_module": "MerkleTree.Spec",
"short_module": "MTS"
},
{
"abbrev": true,
"full_module": "FStar.UInt8",
"short_module": "U8"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "S"
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Ghost",
"short_module": null
},
{
"abbrev": false,
"full_module": "MerkleTree.New",
"short_module": null
},
{
"abbrev": false,
"full_module": "MerkleTree.New",
"short_module": null
},
{
"abbrev": 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 mt_get_path_unchanged #hsz lv hs rhs i j k p actd =
let ofs = offset_of i in
if j = 0 then ()
else
(let np = mt_make_path_step lv hs rhs i j k p actd in
assert (S.equal p (S.slice np 0 (S.length p)));
mt_get_path_unchanged (lv + 1) hs rhs (i / 2) (j / 2) (k / 2) np
(if j % 2 = 0 then actd else true)) | val mt_get_path_unchanged:
#hsz:pos ->
lv:nat{lv <= 32} ->
hs:hashess #hsz {S.length hs = 32} ->
rhs:hashes #hsz {S.length rhs = 32} ->
i:nat ->
j:nat{
i <= j /\ j < pow2 (32 - lv) /\
hs_wf_elts #hsz lv hs i j} ->
k:nat{i <= k && k <= j} ->
p:path #hsz ->
actd:bool ->
Lemma (requires True)
(ensures S.equal p (S.slice (mt_get_path_ lv hs rhs i j k p actd)
0 (S.length p)))
(decreases (32 - lv))
let rec mt_get_path_unchanged #hsz lv hs rhs i j k p actd = | false | null | true | let ofs = offset_of i in
if j = 0
then ()
else
(let np = mt_make_path_step lv hs rhs i j k p actd in
assert (S.equal p (S.slice np 0 (S.length p)));
mt_get_path_unchanged (lv + 1)
hs
rhs
(i / 2)
(j / 2)
(k / 2)
np
(if j % 2 = 0 then actd else true)) | {
"checked_file": "MerkleTree.New.High.fst.checked",
"dependencies": [
"Spec.Hash.Definitions.fst.checked",
"prims.fst.checked",
"MerkleTree.Spec.fst.checked",
"Lib.IntTypes.fsti.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "MerkleTree.New.High.fst"
} | [
"lemma",
""
] | [
"Prims.pos",
"Prims.nat",
"Prims.b2t",
"Prims.op_LessThanOrEqual",
"MerkleTree.New.High.hashess",
"Prims.op_Equality",
"Prims.int",
"FStar.Seq.Base.length",
"MerkleTree.New.High.hashes",
"MerkleTree.New.High.hash",
"Prims.l_and",
"Prims.op_LessThan",
"Prims.pow2",
"Prims.op_Subtraction",
"MerkleTree.New.High.hs_wf_elts",
"Prims.op_AmpAmp",
"MerkleTree.New.High.path",
"Prims.bool",
"MerkleTree.New.High.mt_get_path_unchanged",
"Prims.op_Addition",
"Prims.op_Division",
"Prims.op_Modulus",
"Prims.precedes",
"Prims.unit",
"Prims._assert",
"FStar.Seq.Base.equal",
"FStar.Seq.Base.slice",
"MerkleTree.New.High.mt_make_path_step",
"MerkleTree.New.High.offset_of"
] | [] | module MerkleTree.New.High
open FStar.Ghost
open FStar.Seq
module S = FStar.Seq
module U32 = FStar.UInt32
module U8 = FStar.UInt8
module MTS = MerkleTree.Spec
#set-options "--z3rlimit 10 --max_fuel 0 --max_ifuel 0"
type uint32_t = U32.t
type uint8_t = U8.t
type hash (#hsz:pos) = b:Spec.Hash.Definitions.bytes{Seq.length b = hsz}
type hashes (#hsz:pos) = S.seq (hash #hsz)
type hashess (#hsz:pos) = S.seq (hashes #hsz)
noextract
let hash_init (#hsz:pos): hash #hsz =
Seq.create hsz (Lib.IntTypes.u8 0)
val sha256_compress: src1:hash #32 -> src2:hash #32 -> GTot (hash #32)
let sha256_compress = MTS.sha256_compress
/// Facts about sequences
val seq_slice_equal_index:
#a:Type -> s1:S.seq a -> s2:S.seq a ->
i:nat -> j:nat{i <= j && j <= S.length s1 && j <= S.length s2} ->
k:nat{i <= k && k < j} ->
Lemma (requires S.equal (S.slice s1 i j) (S.slice s2 i j))
(ensures S.index s1 k == S.index s2 k)
[SMTPat (S.equal (S.slice s1 i j) (S.slice s2 i j));
SMTPat (S.index s1 k)]
let seq_slice_equal_index #a s1 s2 i j k =
assert (S.index (S.slice s1 i j) (k - i) == S.index (S.slice s2 i j) (k - i))
private val seq_slice_more_equal:
#a:Type -> s1:S.seq a -> s2:S.seq a ->
n:nat -> m:nat{n <= m && m <= S.length s1 && m <= S.length s2} ->
k:nat{n <= k} -> l:nat{k <= l && l <= m} ->
Lemma (requires S.equal (S.slice s1 n m) (S.slice s2 n m))
(ensures S.equal (S.slice s1 k l) (S.slice s2 k l))
[SMTPat (S.equal (S.slice s1 n m) (S.slice s2 n m));
SMTPat (S.equal (S.slice s1 k l) (S.slice s2 k l))]
private let seq_slice_more_equal #a s1 s2 n m k l =
slice_slice s1 n m (k - n) (l - n);
slice_slice s2 n m (k - n) (l - n)
/// Facts about "2"
val remainder_2_not_1_div: n:nat ->
Lemma (requires n % 2 <> 1)
(ensures n / 2 = (n + 1) / 2)
let remainder_2_not_1_div n = ()
val remainder_2_1_div: n:nat ->
Lemma (requires n % 2 = 1)
(ensures n / 2 + 1 = (n + 1) / 2)
let remainder_2_1_div n = ()
/// High-level Merkle tree data structure
noeq type merkle_tree (#hsz:pos) =
| MT: i:nat ->
j:nat{i <= j && j < pow2 32} ->
hs:hashess #hsz {S.length hs = 32} ->
rhs_ok:bool ->
rhs:hashes #hsz {S.length rhs = 32} -> // Rightmost hashes
mroot:hash #hsz ->
hash_fun:MTS.hash_fun_t #hsz ->
merkle_tree #hsz
val mt_not_full (#hsz:pos): merkle_tree #hsz -> GTot bool
let mt_not_full #hsz mt =
MT?.j mt < pow2 32 - 1
val mt_empty (#hsz:pos): merkle_tree #hsz -> GTot bool
let mt_empty #hsz mt =
MT?.j mt = 0
val mt_not_empty (#hsz:pos): merkle_tree #hsz -> GTot bool
let mt_not_empty #hsz mt =
MT?.j mt > 0
/// Well-formedness w.r.t. indices of base hash elements
noextract
val offset_of: i:nat -> Tot nat
let offset_of i =
if i % 2 = 0 then i else i - 1
val hs_wf_elts:
#hsz:pos ->
lv:nat{lv <= 32} ->
hs:hashess #hsz {S.length hs = 32} ->
i:nat -> j:nat{j >= i} ->
GTot Type0 (decreases (32 - lv))
let rec hs_wf_elts #hsz lv hs i j =
if lv = 32 then true
else (let ofs = offset_of i in
S.length (S.index hs lv) == j - ofs /\
hs_wf_elts #hsz (lv + 1) hs (i / 2) (j / 2))
#push-options "--max_fuel 1"
val hs_wf_elts_equal:
#hsz:pos ->
lv:nat{lv <= 32} ->
hs1:hashess #hsz {S.length hs1 = 32} ->
hs2:hashess #hsz {S.length hs2 = 32} ->
i:nat ->
j:nat{j >= i} ->
Lemma (requires hs_wf_elts lv hs1 i j /\
S.equal (S.slice hs1 lv 32) (S.slice hs2 lv 32))
(ensures hs_wf_elts lv hs2 i j)
(decreases (32 - lv))
let rec hs_wf_elts_equal #hsz lv hs1 hs2 i j =
if lv = 32 then ()
else (S.slice_slice hs1 lv 32 1 (32 - lv);
S.slice_slice hs2 lv 32 1 (32 - lv);
assert (S.equal (S.slice hs1 (lv + 1) 32)
(S.slice hs2 (lv + 1) 32));
S.lemma_index_slice hs1 lv 32 0;
S.lemma_index_slice hs2 lv 32 0;
assert (S.index hs1 lv == S.index hs2 lv);
hs_wf_elts_equal (lv + 1) hs1 hs2 (i / 2) (j / 2))
val mt_wf_elts (#hsz:pos): merkle_tree #hsz -> GTot Type0
let mt_wf_elts #_ (MT i j hs _ _ _ _) =
hs_wf_elts 0 hs i j
/// Construction
val hs_wf_elts_empty:
#hsz:pos ->
lv:nat{lv <= 32} ->
Lemma (requires True)
(ensures hs_wf_elts #hsz lv (S.create 32 S.empty) 0 0)
(decreases (32 - lv))
let rec hs_wf_elts_empty #hsz lv =
if lv = 32 then ()
else hs_wf_elts_empty #hsz (lv + 1)
// NOTE: the public function is `create_mt` defined below, which
// builds a tree with an initial hash.
noextract inline_for_extraction
val create_empty_mt (#hsz:pos) (#f:MTS.hash_fun_t #hsz): unit -> GTot (mt:merkle_tree #hsz {mt_wf_elts #hsz mt})
let create_empty_mt #hsz #f _ =
hs_wf_elts_empty #hsz 0;
MT 0 0 (S.create 32 S.empty) false (S.create 32 (hash_init #hsz)) (hash_init #hsz) f
/// Insertion
val hashess_insert:
#hsz:pos ->
lv:nat{lv < 32} ->
i:nat ->
j:nat{i <= j /\ j < pow2 (32 - lv) - 1} ->
hs:hashess #hsz {S.length hs = 32 /\ hs_wf_elts lv hs i j} ->
v:hash #hsz ->
GTot (ihs:hashess #hsz {S.length ihs = 32 /\ hs_wf_elts (lv + 1) ihs (i / 2) (j / 2)})
let hashess_insert #hsz lv i j hs v =
let ihs = S.upd hs lv (S.snoc (S.index hs lv) v) in
hs_wf_elts_equal (lv + 1) hs ihs (i / 2) (j / 2);
ihs
val insert_:
#hsz:pos -> #f:MTS.hash_fun_t #hsz ->
lv:nat{lv < 32} ->
i:nat ->
j:nat{i <= j /\ j < pow2 (32 - lv) - 1} ->
hs:hashess #hsz {S.length hs = 32 /\ hs_wf_elts lv hs i j} ->
acc:hash #hsz ->
GTot (ihs:hashess #hsz {
S.length ihs = 32 /\
hs_wf_elts #hsz lv ihs i (j + 1) /\
S.equal (S.slice hs 0 lv) (S.slice ihs 0 lv)})
(decreases j)
let rec insert_ #hsz #f lv i j hs acc =
let ihs = hashess_insert #hsz lv i j hs acc in
assert (S.equal (S.slice hs 0 lv) (S.slice ihs 0 lv));
if j % 2 = 1 // S.length (S.index hs lv) > 0
then begin
remainder_2_1_div j;
let nacc = f (S.last (S.index hs lv)) acc in
let rihs = insert_ #hsz #f (lv + 1) (i / 2) (j / 2) ihs nacc in
assert (hs_wf_elts #hsz (lv + 1) rihs (i / 2) (j / 2 + 1));
assert (S.equal (S.slice ihs 0 (lv + 1)) (S.slice rihs 0 (lv + 1)));
assert (S.index ihs lv == S.index rihs lv);
assert (S.length (S.index rihs lv) = (j + 1) - offset_of i);
assert (S.equal (S.slice ihs 0 (lv + 1)) (S.slice rihs 0 (lv + 1)));
assert (S.equal (S.slice ihs 0 lv) (S.slice rihs 0 lv));
rihs
end
else ihs
val insert_base:
#hsz:pos -> #f:MTS.hash_fun_t #hsz ->
lv:nat -> i:nat -> j:nat -> hs:hashess #hsz -> acc:hash #hsz ->
Lemma (requires
lv < 32 /\ i <= j /\ j < pow2 (32 - lv) - 1 /\
S.length hs = 32 /\ hs_wf_elts lv hs i j /\
j % 2 <> 1)
(ensures S.equal (insert_ #_ #f lv i j hs acc)
(hashess_insert lv i j hs acc))
let insert_base #_ #_ lv i j hs acc = ()
val insert_rec:
#hsz:pos -> #f:MTS.hash_fun_t #hsz ->
lv:nat -> i:nat -> j:nat -> hs:hashess -> acc:hash ->
Lemma (requires
lv < 32 /\ i <= j /\ j < pow2 (32 - lv) - 1 /\
S.length hs = 32 /\ hs_wf_elts lv hs i j /\
j % 2 == 1)
(ensures
(hs_wf_elts_equal (lv + 1) hs
(hashess_insert lv i j hs acc) (i / 2) (j / 2);
S.equal (insert_ #_ #f lv i j hs acc)
(insert_ #_ #f (lv + 1) (i / 2) (j / 2)
(hashess_insert lv i j hs acc)
(f (S.last (S.index hs lv)) acc))))
let insert_rec #_ #_ lv i j hs acc = ()
val mt_insert:
#hsz:pos ->
mt:merkle_tree #hsz {mt_wf_elts mt /\ mt_not_full mt} -> v:hash #hsz ->
GTot (imt:merkle_tree #hsz{mt_wf_elts #hsz imt})
let mt_insert #hsz mt v =
MT (MT?.i mt)
(MT?.j mt + 1)
(insert_ #_ #(MT?.hash_fun mt) 0 (MT?.i mt) (MT?.j mt) (MT?.hs mt) v)
false
(MT?.rhs mt)
(MT?.mroot mt)
(MT?.hash_fun mt)
val mt_create:
hsz:pos -> f:MTS.hash_fun_t #hsz ->
init:hash #hsz -> GTot (mt:merkle_tree{mt_wf_elts #hsz mt})
let mt_create hsz f init =
mt_insert #_ (create_empty_mt #_ #f ()) init
/// Getting the Merkle root and path
type path (#hsz:pos) = S.seq (hash #hsz)
// Construct the rightmost hashes for a given (incomplete) Merkle tree.
// This function calculates the Merkle root as well, which is the final
// accumulator value.
val construct_rhs:
#hsz:pos -> #f:MTS.hash_fun_t #hsz ->
lv:nat{lv <= 32} ->
hs:hashess #hsz {S.length hs = 32} ->
rhs:hashes #hsz {S.length rhs = 32} ->
i:nat ->
j:nat{
i <= j /\ j < pow2 (32 - lv) /\
hs_wf_elts #hsz lv hs i j} ->
acc:hash #hsz ->
actd:bool ->
GTot (crhs:hashes #hsz {S.length crhs = 32} * (hash #hsz))
(decreases j)
let rec construct_rhs #hsz #f lv hs rhs i j acc actd =
let ofs = offset_of i in
if j = 0 then (rhs, acc)
else
(if j % 2 = 0
then (construct_rhs #_ #f (lv + 1) hs rhs (i / 2) (j / 2) acc actd)
else (let nrhs = if actd then S.upd rhs lv acc else rhs in
let nacc = if actd
then f (S.index (S.index hs lv) (j - 1 - ofs)) acc
else S.index (S.index hs lv) (j - 1 - ofs) in
construct_rhs #_ #f (lv + 1) hs nrhs (i / 2) (j / 2) nacc true))
val construct_rhs_unchanged:
#hsz:pos -> #f:MTS.hash_fun_t #hsz ->
lv:nat{lv <= 32} ->
hs:hashess #hsz {S.length hs = 32} ->
rhs:hashes #hsz {S.length rhs = 32} ->
i:nat ->
j:nat{
i <= j /\ j < pow2 (32 - lv) /\
hs_wf_elts #hsz lv hs i j} ->
acc:hash #hsz ->
actd:bool ->
Lemma (requires True)
(ensures S.equal (S.slice rhs 0 lv)
(S.slice (fst (construct_rhs #_ #f lv hs rhs i j acc actd)) 0 lv))
(decreases j)
let rec construct_rhs_unchanged #hsz #f lv hs rhs i j acc actd =
let ofs = offset_of i in
if j = 0 then ()
else if j % 2 = 0
then (construct_rhs_unchanged #_ #f (lv + 1) hs rhs (i / 2) (j / 2) acc actd;
let rrhs = fst (construct_rhs #_ #f (lv + 1) hs rhs (i / 2) (j / 2) acc actd) in
assert (S.equal (S.slice rhs 0 lv) (S.slice rrhs 0 lv)))
else (let nrhs = if actd then S.upd rhs lv acc else rhs in
let nacc = if actd
then f (S.index (S.index hs lv) (j - 1 - ofs)) acc
else S.index (S.index hs lv) (j - 1 - ofs) in
construct_rhs_unchanged #_ #f (lv + 1) hs nrhs (i / 2) (j / 2) nacc true;
let rrhs = fst (construct_rhs #_ #f (lv + 1) hs nrhs (i / 2) (j / 2) nacc true) in
assert (S.equal (S.slice nrhs 0 lv) (S.slice rrhs 0 lv));
assert (S.equal (S.slice rhs 0 lv) (S.slice nrhs 0 lv)))
val construct_rhs_even:
#hsz:pos -> #f:MTS.hash_fun_t #hsz ->
lv:nat{lv <= 32} ->
hs:hashess #hsz {S.length hs = 32} ->
rhs:hashes #hsz {S.length rhs = 32} ->
i:nat ->
j:nat{
i <= j /\ j < pow2 (32 - lv) /\
hs_wf_elts #hsz lv hs i j} ->
acc:hash #hsz ->
actd:bool ->
Lemma (requires j <> 0 /\ j % 2 = 0)
(ensures construct_rhs #_ #f lv hs rhs i j acc actd ==
construct_rhs #_ #f (lv + 1) hs rhs (i / 2) (j / 2) acc actd)
let construct_rhs_even #_ #_ _ _ _ _ _ _ _ = ()
val construct_rhs_odd:
#hsz:pos -> #f:MTS.hash_fun_t #hsz ->
lv:nat{lv <= 32} ->
hs:hashess #hsz {S.length hs = 32} ->
rhs:hashes #hsz {S.length rhs = 32} ->
i:nat ->
j:nat{
i <= j /\ j < pow2 (32 - lv) /\
hs_wf_elts lv hs i j} ->
acc:hash ->
actd:bool ->
Lemma (requires j % 2 = 1)
(ensures construct_rhs #_ #f lv hs rhs i j acc actd ==
(let ofs = offset_of i in
let nrhs = if actd then S.upd rhs lv acc else rhs in
let nacc = if actd
then f (S.index (S.index hs lv) (j - 1 - ofs)) acc
else S.index (S.index hs lv) (j - 1 - ofs) in
construct_rhs #_ #f (lv + 1) hs nrhs (i / 2) (j / 2) nacc true))
let construct_rhs_odd #_ #_ _ _ _ _ _ _ _ = ()
val mt_get_root:
#hsz:pos ->
mt:merkle_tree #hsz {mt_wf_elts #hsz mt} -> drt:hash #hsz ->
GTot (merkle_tree #hsz * hash #hsz)
let mt_get_root #hsz mt drt =
if MT?.rhs_ok mt then (mt, MT?.mroot mt)
else begin
let (nrhs, rt) = construct_rhs #_ #(MT?.hash_fun mt) 0 (MT?.hs mt) (MT?.rhs mt) (MT?.i mt) (MT?.j mt) drt false in
(MT (MT?.i mt) (MT?.j mt) (MT?.hs mt) true nrhs rt (MT?.hash_fun mt), rt)
end
val mt_get_root_rhs_ok_true:
#hsz:pos ->
mt:merkle_tree #hsz {mt_wf_elts mt} -> drt:hash #hsz ->
Lemma (requires MT?.rhs_ok mt == true)
(ensures mt_get_root #hsz mt drt == (mt, MT?.mroot mt))
let mt_get_root_rhs_ok_true #hsz mt drt = ()
val mt_get_root_rhs_ok_false:
#hsz:pos ->
mt:merkle_tree #hsz {mt_wf_elts mt} -> drt:hash ->
Lemma (requires MT?.rhs_ok mt == false)
(ensures mt_get_root mt drt ==
(let (nrhs, rt) =
construct_rhs #_ #(MT?.hash_fun mt)
0 (MT?.hs mt) (MT?.rhs mt) (MT?.i mt) (MT?.j mt)
drt false in
(MT (MT?.i mt) (MT?.j mt) (MT?.hs mt) true nrhs rt (MT?.hash_fun mt), rt)))
let mt_get_root_rhs_ok_false #_ _ _ = ()
val path_insert: (#hsz:pos) -> p:path #hsz -> hp:hash #hsz -> GTot (path #hsz)
let path_insert #_ p hp = S.snoc p hp
val mt_path_length_step:
k:nat -> j:nat{k <= j} -> actd:bool -> GTot nat
let mt_path_length_step k j actd =
if j = 0 then 0
else (if k % 2 = 0
then (if j = k || (j = k + 1 && not actd) then 0 else 1)
else 1)
val mt_path_length:
k:nat -> j:nat{k <= j} -> actd:bool -> GTot nat
let rec mt_path_length k j actd =
if j = 0 then 0
else (let nactd = actd || (j % 2 = 1) in
mt_path_length_step k j actd +
mt_path_length (k / 2) (j / 2) nactd)
val mt_make_path_step:
#hsz:pos ->
lv:nat{lv <= 32} ->
hs:hashess #hsz {S.length hs = 32} ->
rhs:hashes #hsz {S.length rhs = 32} ->
i:nat ->
j:nat{
j <> 0 /\ i <= j /\ j < pow2 (32 - lv) /\
hs_wf_elts lv hs i j} ->
k:nat{i <= k && k <= j} ->
p:path #hsz ->
actd:bool ->
GTot (path #hsz)
let mt_make_path_step #hsz lv hs rhs i j k p actd =
let ofs = offset_of i in
if k % 2 = 1
then path_insert p (S.index (S.index hs lv) (k - 1 - ofs))
else (if k = j then p
else if k + 1 = j
then (if actd
then path_insert p (S.index rhs lv)
else p)
else path_insert p (S.index (S.index hs lv) (k + 1 - ofs)))
// Construct a Merkle path for a given index `k`, hashes `hs`,
// and rightmost hashes `rhs`.
val mt_get_path_:
#hsz:pos ->
lv:nat{lv <= 32} ->
hs:hashess #hsz {S.length hs = 32} ->
rhs:hashes #hsz {S.length rhs = 32} ->
i:nat ->
j:nat{
i <= j /\ j < pow2 (32 - lv) /\
hs_wf_elts lv hs i j} ->
k:nat{i <= k && k <= j} ->
p:path #hsz ->
actd:bool ->
GTot (np:path #hsz {S.length np = S.length p + mt_path_length k j actd})
(decreases (32 - lv))
let rec mt_get_path_ #hsz lv hs rhs i j k p actd =
let ofs = offset_of i in
if j = 0 then p
else
(let np = mt_make_path_step lv hs rhs i j k p actd in
mt_get_path_ (lv + 1) hs rhs (i / 2) (j / 2) (k / 2) np
(if j % 2 = 0 then actd else true))
val mt_get_path_unchanged:
#hsz:pos ->
lv:nat{lv <= 32} ->
hs:hashess #hsz {S.length hs = 32} ->
rhs:hashes #hsz {S.length rhs = 32} ->
i:nat ->
j:nat{
i <= j /\ j < pow2 (32 - lv) /\
hs_wf_elts #hsz lv hs i j} ->
k:nat{i <= k && k <= j} ->
p:path #hsz ->
actd:bool ->
Lemma (requires True)
(ensures S.equal p (S.slice (mt_get_path_ lv hs rhs i j k p actd)
0 (S.length p))) | false | false | MerkleTree.New.High.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 1,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 10,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val mt_get_path_unchanged:
#hsz:pos ->
lv:nat{lv <= 32} ->
hs:hashess #hsz {S.length hs = 32} ->
rhs:hashes #hsz {S.length rhs = 32} ->
i:nat ->
j:nat{
i <= j /\ j < pow2 (32 - lv) /\
hs_wf_elts #hsz lv hs i j} ->
k:nat{i <= k && k <= j} ->
p:path #hsz ->
actd:bool ->
Lemma (requires True)
(ensures S.equal p (S.slice (mt_get_path_ lv hs rhs i j k p actd)
0 (S.length p)))
(decreases (32 - lv)) | [
"recursion"
] | MerkleTree.New.High.mt_get_path_unchanged | {
"file_name": "src/MerkleTree.New.High.fst",
"git_rev": "3b0f086655c145aa23f58a97259ebf4cf112a4a3",
"git_url": "https://github.com/hacl-star/merkle-tree.git",
"project_name": "merkle-tree"
} |
lv: Prims.nat{lv <= 32} ->
hs: MerkleTree.New.High.hashess{FStar.Seq.Base.length hs = 32} ->
rhs: MerkleTree.New.High.hashes{FStar.Seq.Base.length rhs = 32} ->
i: Prims.nat ->
j: Prims.nat{i <= j /\ j < Prims.pow2 (32 - lv) /\ MerkleTree.New.High.hs_wf_elts lv hs i j} ->
k: Prims.nat{i <= k && k <= j} ->
p: MerkleTree.New.High.path ->
actd: Prims.bool
-> FStar.Pervasives.Lemma
(ensures
FStar.Seq.Base.equal p
(FStar.Seq.Base.slice (MerkleTree.New.High.mt_get_path_ lv hs rhs i j k p actd)
0
(FStar.Seq.Base.length p))) (decreases 32 - lv) | {
"end_col": 41,
"end_line": 469,
"start_col": 59,
"start_line": 462
} |
FStar.Pervasives.Lemma | val mt_get_path_pull:
#hsz:pos ->
lv:nat{lv <= 32} ->
hs:hashess #hsz {S.length hs = 32} ->
rhs:hashes #hsz {S.length rhs = 32} ->
i:nat ->
j:nat{
i <= j /\ j < pow2 (32 - lv) /\
hs_wf_elts lv hs i j} ->
k:nat{i <= k && k <= j} ->
p:path #hsz ->
actd:bool ->
Lemma (requires True)
(ensures S.equal (mt_get_path_ lv hs rhs i j k p actd)
(S.append p (mt_get_path_ lv hs rhs i j k S.empty actd)))
(decreases (32 - lv)) | [
{
"abbrev": true,
"full_module": "MerkleTree.Spec",
"short_module": "MTS"
},
{
"abbrev": true,
"full_module": "FStar.UInt8",
"short_module": "U8"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "S"
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Ghost",
"short_module": null
},
{
"abbrev": false,
"full_module": "MerkleTree.New",
"short_module": null
},
{
"abbrev": false,
"full_module": "MerkleTree.New",
"short_module": null
},
{
"abbrev": 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 mt_get_path_pull #hsz lv hs rhs i j k p actd =
let ofs = offset_of i in
if j = 0 then ()
else
(let np = mt_make_path_step lv hs rhs i j k p actd in
let nactd = if j % 2 = 0 then actd else true in
mt_get_path_pull (lv + 1) hs rhs (i / 2) (j / 2) (k / 2) np nactd;
mt_get_path_pull (lv + 1) hs rhs (i / 2) (j / 2) (k / 2)
(mt_make_path_step lv hs rhs i j k S.empty actd) nactd) | val mt_get_path_pull:
#hsz:pos ->
lv:nat{lv <= 32} ->
hs:hashess #hsz {S.length hs = 32} ->
rhs:hashes #hsz {S.length rhs = 32} ->
i:nat ->
j:nat{
i <= j /\ j < pow2 (32 - lv) /\
hs_wf_elts lv hs i j} ->
k:nat{i <= k && k <= j} ->
p:path #hsz ->
actd:bool ->
Lemma (requires True)
(ensures S.equal (mt_get_path_ lv hs rhs i j k p actd)
(S.append p (mt_get_path_ lv hs rhs i j k S.empty actd)))
(decreases (32 - lv))
let rec mt_get_path_pull #hsz lv hs rhs i j k p actd = | false | null | true | let ofs = offset_of i in
if j = 0
then ()
else
(let np = mt_make_path_step lv hs rhs i j k p actd in
let nactd = if j % 2 = 0 then actd else true in
mt_get_path_pull (lv + 1) hs rhs (i / 2) (j / 2) (k / 2) np nactd;
mt_get_path_pull (lv + 1)
hs
rhs
(i / 2)
(j / 2)
(k / 2)
(mt_make_path_step lv hs rhs i j k S.empty actd)
nactd) | {
"checked_file": "MerkleTree.New.High.fst.checked",
"dependencies": [
"Spec.Hash.Definitions.fst.checked",
"prims.fst.checked",
"MerkleTree.Spec.fst.checked",
"Lib.IntTypes.fsti.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "MerkleTree.New.High.fst"
} | [
"lemma",
""
] | [
"Prims.pos",
"Prims.nat",
"Prims.b2t",
"Prims.op_LessThanOrEqual",
"MerkleTree.New.High.hashess",
"Prims.op_Equality",
"Prims.int",
"FStar.Seq.Base.length",
"MerkleTree.New.High.hashes",
"MerkleTree.New.High.hash",
"Prims.l_and",
"Prims.op_LessThan",
"Prims.pow2",
"Prims.op_Subtraction",
"MerkleTree.New.High.hs_wf_elts",
"Prims.op_AmpAmp",
"MerkleTree.New.High.path",
"Prims.bool",
"MerkleTree.New.High.mt_get_path_pull",
"Prims.op_Addition",
"Prims.op_Division",
"MerkleTree.New.High.mt_make_path_step",
"FStar.Seq.Base.empty",
"Prims.unit",
"Prims.precedes",
"Prims.op_Modulus",
"MerkleTree.New.High.offset_of"
] | [] | module MerkleTree.New.High
open FStar.Ghost
open FStar.Seq
module S = FStar.Seq
module U32 = FStar.UInt32
module U8 = FStar.UInt8
module MTS = MerkleTree.Spec
#set-options "--z3rlimit 10 --max_fuel 0 --max_ifuel 0"
type uint32_t = U32.t
type uint8_t = U8.t
type hash (#hsz:pos) = b:Spec.Hash.Definitions.bytes{Seq.length b = hsz}
type hashes (#hsz:pos) = S.seq (hash #hsz)
type hashess (#hsz:pos) = S.seq (hashes #hsz)
noextract
let hash_init (#hsz:pos): hash #hsz =
Seq.create hsz (Lib.IntTypes.u8 0)
val sha256_compress: src1:hash #32 -> src2:hash #32 -> GTot (hash #32)
let sha256_compress = MTS.sha256_compress
/// Facts about sequences
val seq_slice_equal_index:
#a:Type -> s1:S.seq a -> s2:S.seq a ->
i:nat -> j:nat{i <= j && j <= S.length s1 && j <= S.length s2} ->
k:nat{i <= k && k < j} ->
Lemma (requires S.equal (S.slice s1 i j) (S.slice s2 i j))
(ensures S.index s1 k == S.index s2 k)
[SMTPat (S.equal (S.slice s1 i j) (S.slice s2 i j));
SMTPat (S.index s1 k)]
let seq_slice_equal_index #a s1 s2 i j k =
assert (S.index (S.slice s1 i j) (k - i) == S.index (S.slice s2 i j) (k - i))
private val seq_slice_more_equal:
#a:Type -> s1:S.seq a -> s2:S.seq a ->
n:nat -> m:nat{n <= m && m <= S.length s1 && m <= S.length s2} ->
k:nat{n <= k} -> l:nat{k <= l && l <= m} ->
Lemma (requires S.equal (S.slice s1 n m) (S.slice s2 n m))
(ensures S.equal (S.slice s1 k l) (S.slice s2 k l))
[SMTPat (S.equal (S.slice s1 n m) (S.slice s2 n m));
SMTPat (S.equal (S.slice s1 k l) (S.slice s2 k l))]
private let seq_slice_more_equal #a s1 s2 n m k l =
slice_slice s1 n m (k - n) (l - n);
slice_slice s2 n m (k - n) (l - n)
/// Facts about "2"
val remainder_2_not_1_div: n:nat ->
Lemma (requires n % 2 <> 1)
(ensures n / 2 = (n + 1) / 2)
let remainder_2_not_1_div n = ()
val remainder_2_1_div: n:nat ->
Lemma (requires n % 2 = 1)
(ensures n / 2 + 1 = (n + 1) / 2)
let remainder_2_1_div n = ()
/// High-level Merkle tree data structure
noeq type merkle_tree (#hsz:pos) =
| MT: i:nat ->
j:nat{i <= j && j < pow2 32} ->
hs:hashess #hsz {S.length hs = 32} ->
rhs_ok:bool ->
rhs:hashes #hsz {S.length rhs = 32} -> // Rightmost hashes
mroot:hash #hsz ->
hash_fun:MTS.hash_fun_t #hsz ->
merkle_tree #hsz
val mt_not_full (#hsz:pos): merkle_tree #hsz -> GTot bool
let mt_not_full #hsz mt =
MT?.j mt < pow2 32 - 1
val mt_empty (#hsz:pos): merkle_tree #hsz -> GTot bool
let mt_empty #hsz mt =
MT?.j mt = 0
val mt_not_empty (#hsz:pos): merkle_tree #hsz -> GTot bool
let mt_not_empty #hsz mt =
MT?.j mt > 0
/// Well-formedness w.r.t. indices of base hash elements
noextract
val offset_of: i:nat -> Tot nat
let offset_of i =
if i % 2 = 0 then i else i - 1
val hs_wf_elts:
#hsz:pos ->
lv:nat{lv <= 32} ->
hs:hashess #hsz {S.length hs = 32} ->
i:nat -> j:nat{j >= i} ->
GTot Type0 (decreases (32 - lv))
let rec hs_wf_elts #hsz lv hs i j =
if lv = 32 then true
else (let ofs = offset_of i in
S.length (S.index hs lv) == j - ofs /\
hs_wf_elts #hsz (lv + 1) hs (i / 2) (j / 2))
#push-options "--max_fuel 1"
val hs_wf_elts_equal:
#hsz:pos ->
lv:nat{lv <= 32} ->
hs1:hashess #hsz {S.length hs1 = 32} ->
hs2:hashess #hsz {S.length hs2 = 32} ->
i:nat ->
j:nat{j >= i} ->
Lemma (requires hs_wf_elts lv hs1 i j /\
S.equal (S.slice hs1 lv 32) (S.slice hs2 lv 32))
(ensures hs_wf_elts lv hs2 i j)
(decreases (32 - lv))
let rec hs_wf_elts_equal #hsz lv hs1 hs2 i j =
if lv = 32 then ()
else (S.slice_slice hs1 lv 32 1 (32 - lv);
S.slice_slice hs2 lv 32 1 (32 - lv);
assert (S.equal (S.slice hs1 (lv + 1) 32)
(S.slice hs2 (lv + 1) 32));
S.lemma_index_slice hs1 lv 32 0;
S.lemma_index_slice hs2 lv 32 0;
assert (S.index hs1 lv == S.index hs2 lv);
hs_wf_elts_equal (lv + 1) hs1 hs2 (i / 2) (j / 2))
val mt_wf_elts (#hsz:pos): merkle_tree #hsz -> GTot Type0
let mt_wf_elts #_ (MT i j hs _ _ _ _) =
hs_wf_elts 0 hs i j
/// Construction
val hs_wf_elts_empty:
#hsz:pos ->
lv:nat{lv <= 32} ->
Lemma (requires True)
(ensures hs_wf_elts #hsz lv (S.create 32 S.empty) 0 0)
(decreases (32 - lv))
let rec hs_wf_elts_empty #hsz lv =
if lv = 32 then ()
else hs_wf_elts_empty #hsz (lv + 1)
// NOTE: the public function is `create_mt` defined below, which
// builds a tree with an initial hash.
noextract inline_for_extraction
val create_empty_mt (#hsz:pos) (#f:MTS.hash_fun_t #hsz): unit -> GTot (mt:merkle_tree #hsz {mt_wf_elts #hsz mt})
let create_empty_mt #hsz #f _ =
hs_wf_elts_empty #hsz 0;
MT 0 0 (S.create 32 S.empty) false (S.create 32 (hash_init #hsz)) (hash_init #hsz) f
/// Insertion
val hashess_insert:
#hsz:pos ->
lv:nat{lv < 32} ->
i:nat ->
j:nat{i <= j /\ j < pow2 (32 - lv) - 1} ->
hs:hashess #hsz {S.length hs = 32 /\ hs_wf_elts lv hs i j} ->
v:hash #hsz ->
GTot (ihs:hashess #hsz {S.length ihs = 32 /\ hs_wf_elts (lv + 1) ihs (i / 2) (j / 2)})
let hashess_insert #hsz lv i j hs v =
let ihs = S.upd hs lv (S.snoc (S.index hs lv) v) in
hs_wf_elts_equal (lv + 1) hs ihs (i / 2) (j / 2);
ihs
val insert_:
#hsz:pos -> #f:MTS.hash_fun_t #hsz ->
lv:nat{lv < 32} ->
i:nat ->
j:nat{i <= j /\ j < pow2 (32 - lv) - 1} ->
hs:hashess #hsz {S.length hs = 32 /\ hs_wf_elts lv hs i j} ->
acc:hash #hsz ->
GTot (ihs:hashess #hsz {
S.length ihs = 32 /\
hs_wf_elts #hsz lv ihs i (j + 1) /\
S.equal (S.slice hs 0 lv) (S.slice ihs 0 lv)})
(decreases j)
let rec insert_ #hsz #f lv i j hs acc =
let ihs = hashess_insert #hsz lv i j hs acc in
assert (S.equal (S.slice hs 0 lv) (S.slice ihs 0 lv));
if j % 2 = 1 // S.length (S.index hs lv) > 0
then begin
remainder_2_1_div j;
let nacc = f (S.last (S.index hs lv)) acc in
let rihs = insert_ #hsz #f (lv + 1) (i / 2) (j / 2) ihs nacc in
assert (hs_wf_elts #hsz (lv + 1) rihs (i / 2) (j / 2 + 1));
assert (S.equal (S.slice ihs 0 (lv + 1)) (S.slice rihs 0 (lv + 1)));
assert (S.index ihs lv == S.index rihs lv);
assert (S.length (S.index rihs lv) = (j + 1) - offset_of i);
assert (S.equal (S.slice ihs 0 (lv + 1)) (S.slice rihs 0 (lv + 1)));
assert (S.equal (S.slice ihs 0 lv) (S.slice rihs 0 lv));
rihs
end
else ihs
val insert_base:
#hsz:pos -> #f:MTS.hash_fun_t #hsz ->
lv:nat -> i:nat -> j:nat -> hs:hashess #hsz -> acc:hash #hsz ->
Lemma (requires
lv < 32 /\ i <= j /\ j < pow2 (32 - lv) - 1 /\
S.length hs = 32 /\ hs_wf_elts lv hs i j /\
j % 2 <> 1)
(ensures S.equal (insert_ #_ #f lv i j hs acc)
(hashess_insert lv i j hs acc))
let insert_base #_ #_ lv i j hs acc = ()
val insert_rec:
#hsz:pos -> #f:MTS.hash_fun_t #hsz ->
lv:nat -> i:nat -> j:nat -> hs:hashess -> acc:hash ->
Lemma (requires
lv < 32 /\ i <= j /\ j < pow2 (32 - lv) - 1 /\
S.length hs = 32 /\ hs_wf_elts lv hs i j /\
j % 2 == 1)
(ensures
(hs_wf_elts_equal (lv + 1) hs
(hashess_insert lv i j hs acc) (i / 2) (j / 2);
S.equal (insert_ #_ #f lv i j hs acc)
(insert_ #_ #f (lv + 1) (i / 2) (j / 2)
(hashess_insert lv i j hs acc)
(f (S.last (S.index hs lv)) acc))))
let insert_rec #_ #_ lv i j hs acc = ()
val mt_insert:
#hsz:pos ->
mt:merkle_tree #hsz {mt_wf_elts mt /\ mt_not_full mt} -> v:hash #hsz ->
GTot (imt:merkle_tree #hsz{mt_wf_elts #hsz imt})
let mt_insert #hsz mt v =
MT (MT?.i mt)
(MT?.j mt + 1)
(insert_ #_ #(MT?.hash_fun mt) 0 (MT?.i mt) (MT?.j mt) (MT?.hs mt) v)
false
(MT?.rhs mt)
(MT?.mroot mt)
(MT?.hash_fun mt)
val mt_create:
hsz:pos -> f:MTS.hash_fun_t #hsz ->
init:hash #hsz -> GTot (mt:merkle_tree{mt_wf_elts #hsz mt})
let mt_create hsz f init =
mt_insert #_ (create_empty_mt #_ #f ()) init
/// Getting the Merkle root and path
type path (#hsz:pos) = S.seq (hash #hsz)
// Construct the rightmost hashes for a given (incomplete) Merkle tree.
// This function calculates the Merkle root as well, which is the final
// accumulator value.
val construct_rhs:
#hsz:pos -> #f:MTS.hash_fun_t #hsz ->
lv:nat{lv <= 32} ->
hs:hashess #hsz {S.length hs = 32} ->
rhs:hashes #hsz {S.length rhs = 32} ->
i:nat ->
j:nat{
i <= j /\ j < pow2 (32 - lv) /\
hs_wf_elts #hsz lv hs i j} ->
acc:hash #hsz ->
actd:bool ->
GTot (crhs:hashes #hsz {S.length crhs = 32} * (hash #hsz))
(decreases j)
let rec construct_rhs #hsz #f lv hs rhs i j acc actd =
let ofs = offset_of i in
if j = 0 then (rhs, acc)
else
(if j % 2 = 0
then (construct_rhs #_ #f (lv + 1) hs rhs (i / 2) (j / 2) acc actd)
else (let nrhs = if actd then S.upd rhs lv acc else rhs in
let nacc = if actd
then f (S.index (S.index hs lv) (j - 1 - ofs)) acc
else S.index (S.index hs lv) (j - 1 - ofs) in
construct_rhs #_ #f (lv + 1) hs nrhs (i / 2) (j / 2) nacc true))
val construct_rhs_unchanged:
#hsz:pos -> #f:MTS.hash_fun_t #hsz ->
lv:nat{lv <= 32} ->
hs:hashess #hsz {S.length hs = 32} ->
rhs:hashes #hsz {S.length rhs = 32} ->
i:nat ->
j:nat{
i <= j /\ j < pow2 (32 - lv) /\
hs_wf_elts #hsz lv hs i j} ->
acc:hash #hsz ->
actd:bool ->
Lemma (requires True)
(ensures S.equal (S.slice rhs 0 lv)
(S.slice (fst (construct_rhs #_ #f lv hs rhs i j acc actd)) 0 lv))
(decreases j)
let rec construct_rhs_unchanged #hsz #f lv hs rhs i j acc actd =
let ofs = offset_of i in
if j = 0 then ()
else if j % 2 = 0
then (construct_rhs_unchanged #_ #f (lv + 1) hs rhs (i / 2) (j / 2) acc actd;
let rrhs = fst (construct_rhs #_ #f (lv + 1) hs rhs (i / 2) (j / 2) acc actd) in
assert (S.equal (S.slice rhs 0 lv) (S.slice rrhs 0 lv)))
else (let nrhs = if actd then S.upd rhs lv acc else rhs in
let nacc = if actd
then f (S.index (S.index hs lv) (j - 1 - ofs)) acc
else S.index (S.index hs lv) (j - 1 - ofs) in
construct_rhs_unchanged #_ #f (lv + 1) hs nrhs (i / 2) (j / 2) nacc true;
let rrhs = fst (construct_rhs #_ #f (lv + 1) hs nrhs (i / 2) (j / 2) nacc true) in
assert (S.equal (S.slice nrhs 0 lv) (S.slice rrhs 0 lv));
assert (S.equal (S.slice rhs 0 lv) (S.slice nrhs 0 lv)))
val construct_rhs_even:
#hsz:pos -> #f:MTS.hash_fun_t #hsz ->
lv:nat{lv <= 32} ->
hs:hashess #hsz {S.length hs = 32} ->
rhs:hashes #hsz {S.length rhs = 32} ->
i:nat ->
j:nat{
i <= j /\ j < pow2 (32 - lv) /\
hs_wf_elts #hsz lv hs i j} ->
acc:hash #hsz ->
actd:bool ->
Lemma (requires j <> 0 /\ j % 2 = 0)
(ensures construct_rhs #_ #f lv hs rhs i j acc actd ==
construct_rhs #_ #f (lv + 1) hs rhs (i / 2) (j / 2) acc actd)
let construct_rhs_even #_ #_ _ _ _ _ _ _ _ = ()
val construct_rhs_odd:
#hsz:pos -> #f:MTS.hash_fun_t #hsz ->
lv:nat{lv <= 32} ->
hs:hashess #hsz {S.length hs = 32} ->
rhs:hashes #hsz {S.length rhs = 32} ->
i:nat ->
j:nat{
i <= j /\ j < pow2 (32 - lv) /\
hs_wf_elts lv hs i j} ->
acc:hash ->
actd:bool ->
Lemma (requires j % 2 = 1)
(ensures construct_rhs #_ #f lv hs rhs i j acc actd ==
(let ofs = offset_of i in
let nrhs = if actd then S.upd rhs lv acc else rhs in
let nacc = if actd
then f (S.index (S.index hs lv) (j - 1 - ofs)) acc
else S.index (S.index hs lv) (j - 1 - ofs) in
construct_rhs #_ #f (lv + 1) hs nrhs (i / 2) (j / 2) nacc true))
let construct_rhs_odd #_ #_ _ _ _ _ _ _ _ = ()
val mt_get_root:
#hsz:pos ->
mt:merkle_tree #hsz {mt_wf_elts #hsz mt} -> drt:hash #hsz ->
GTot (merkle_tree #hsz * hash #hsz)
let mt_get_root #hsz mt drt =
if MT?.rhs_ok mt then (mt, MT?.mroot mt)
else begin
let (nrhs, rt) = construct_rhs #_ #(MT?.hash_fun mt) 0 (MT?.hs mt) (MT?.rhs mt) (MT?.i mt) (MT?.j mt) drt false in
(MT (MT?.i mt) (MT?.j mt) (MT?.hs mt) true nrhs rt (MT?.hash_fun mt), rt)
end
val mt_get_root_rhs_ok_true:
#hsz:pos ->
mt:merkle_tree #hsz {mt_wf_elts mt} -> drt:hash #hsz ->
Lemma (requires MT?.rhs_ok mt == true)
(ensures mt_get_root #hsz mt drt == (mt, MT?.mroot mt))
let mt_get_root_rhs_ok_true #hsz mt drt = ()
val mt_get_root_rhs_ok_false:
#hsz:pos ->
mt:merkle_tree #hsz {mt_wf_elts mt} -> drt:hash ->
Lemma (requires MT?.rhs_ok mt == false)
(ensures mt_get_root mt drt ==
(let (nrhs, rt) =
construct_rhs #_ #(MT?.hash_fun mt)
0 (MT?.hs mt) (MT?.rhs mt) (MT?.i mt) (MT?.j mt)
drt false in
(MT (MT?.i mt) (MT?.j mt) (MT?.hs mt) true nrhs rt (MT?.hash_fun mt), rt)))
let mt_get_root_rhs_ok_false #_ _ _ = ()
val path_insert: (#hsz:pos) -> p:path #hsz -> hp:hash #hsz -> GTot (path #hsz)
let path_insert #_ p hp = S.snoc p hp
val mt_path_length_step:
k:nat -> j:nat{k <= j} -> actd:bool -> GTot nat
let mt_path_length_step k j actd =
if j = 0 then 0
else (if k % 2 = 0
then (if j = k || (j = k + 1 && not actd) then 0 else 1)
else 1)
val mt_path_length:
k:nat -> j:nat{k <= j} -> actd:bool -> GTot nat
let rec mt_path_length k j actd =
if j = 0 then 0
else (let nactd = actd || (j % 2 = 1) in
mt_path_length_step k j actd +
mt_path_length (k / 2) (j / 2) nactd)
val mt_make_path_step:
#hsz:pos ->
lv:nat{lv <= 32} ->
hs:hashess #hsz {S.length hs = 32} ->
rhs:hashes #hsz {S.length rhs = 32} ->
i:nat ->
j:nat{
j <> 0 /\ i <= j /\ j < pow2 (32 - lv) /\
hs_wf_elts lv hs i j} ->
k:nat{i <= k && k <= j} ->
p:path #hsz ->
actd:bool ->
GTot (path #hsz)
let mt_make_path_step #hsz lv hs rhs i j k p actd =
let ofs = offset_of i in
if k % 2 = 1
then path_insert p (S.index (S.index hs lv) (k - 1 - ofs))
else (if k = j then p
else if k + 1 = j
then (if actd
then path_insert p (S.index rhs lv)
else p)
else path_insert p (S.index (S.index hs lv) (k + 1 - ofs)))
// Construct a Merkle path for a given index `k`, hashes `hs`,
// and rightmost hashes `rhs`.
val mt_get_path_:
#hsz:pos ->
lv:nat{lv <= 32} ->
hs:hashess #hsz {S.length hs = 32} ->
rhs:hashes #hsz {S.length rhs = 32} ->
i:nat ->
j:nat{
i <= j /\ j < pow2 (32 - lv) /\
hs_wf_elts lv hs i j} ->
k:nat{i <= k && k <= j} ->
p:path #hsz ->
actd:bool ->
GTot (np:path #hsz {S.length np = S.length p + mt_path_length k j actd})
(decreases (32 - lv))
let rec mt_get_path_ #hsz lv hs rhs i j k p actd =
let ofs = offset_of i in
if j = 0 then p
else
(let np = mt_make_path_step lv hs rhs i j k p actd in
mt_get_path_ (lv + 1) hs rhs (i / 2) (j / 2) (k / 2) np
(if j % 2 = 0 then actd else true))
val mt_get_path_unchanged:
#hsz:pos ->
lv:nat{lv <= 32} ->
hs:hashess #hsz {S.length hs = 32} ->
rhs:hashes #hsz {S.length rhs = 32} ->
i:nat ->
j:nat{
i <= j /\ j < pow2 (32 - lv) /\
hs_wf_elts #hsz lv hs i j} ->
k:nat{i <= k && k <= j} ->
p:path #hsz ->
actd:bool ->
Lemma (requires True)
(ensures S.equal p (S.slice (mt_get_path_ lv hs rhs i j k p actd)
0 (S.length p)))
(decreases (32 - lv))
let rec mt_get_path_unchanged #hsz lv hs rhs i j k p actd =
let ofs = offset_of i in
if j = 0 then ()
else
(let np = mt_make_path_step lv hs rhs i j k p actd in
assert (S.equal p (S.slice np 0 (S.length p)));
mt_get_path_unchanged (lv + 1) hs rhs (i / 2) (j / 2) (k / 2) np
(if j % 2 = 0 then actd else true))
#push-options "--z3rlimit 20"
val mt_get_path_pull:
#hsz:pos ->
lv:nat{lv <= 32} ->
hs:hashess #hsz {S.length hs = 32} ->
rhs:hashes #hsz {S.length rhs = 32} ->
i:nat ->
j:nat{
i <= j /\ j < pow2 (32 - lv) /\
hs_wf_elts lv hs i j} ->
k:nat{i <= k && k <= j} ->
p:path #hsz ->
actd:bool ->
Lemma (requires True)
(ensures S.equal (mt_get_path_ lv hs rhs i j k p actd)
(S.append p (mt_get_path_ lv hs rhs i j k S.empty actd))) | false | false | MerkleTree.New.High.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 1,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 20,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val mt_get_path_pull:
#hsz:pos ->
lv:nat{lv <= 32} ->
hs:hashess #hsz {S.length hs = 32} ->
rhs:hashes #hsz {S.length rhs = 32} ->
i:nat ->
j:nat{
i <= j /\ j < pow2 (32 - lv) /\
hs_wf_elts lv hs i j} ->
k:nat{i <= k && k <= j} ->
p:path #hsz ->
actd:bool ->
Lemma (requires True)
(ensures S.equal (mt_get_path_ lv hs rhs i j k p actd)
(S.append p (mt_get_path_ lv hs rhs i j k S.empty actd)))
(decreases (32 - lv)) | [
"recursion"
] | MerkleTree.New.High.mt_get_path_pull | {
"file_name": "src/MerkleTree.New.High.fst",
"git_rev": "3b0f086655c145aa23f58a97259ebf4cf112a4a3",
"git_url": "https://github.com/hacl-star/merkle-tree.git",
"project_name": "merkle-tree"
} |
lv: Prims.nat{lv <= 32} ->
hs: MerkleTree.New.High.hashess{FStar.Seq.Base.length hs = 32} ->
rhs: MerkleTree.New.High.hashes{FStar.Seq.Base.length rhs = 32} ->
i: Prims.nat ->
j: Prims.nat{i <= j /\ j < Prims.pow2 (32 - lv) /\ MerkleTree.New.High.hs_wf_elts lv hs i j} ->
k: Prims.nat{i <= k && k <= j} ->
p: MerkleTree.New.High.path ->
actd: Prims.bool
-> FStar.Pervasives.Lemma
(ensures
FStar.Seq.Base.equal (MerkleTree.New.High.mt_get_path_ lv hs rhs i j k p actd)
(FStar.Seq.Base.append p
(MerkleTree.New.High.mt_get_path_ lv hs rhs i j k FStar.Seq.Base.empty actd)))
(decreases 32 - lv) | {
"end_col": 61,
"end_line": 497,
"start_col": 54,
"start_line": 489
} |
FStar.Pervasives.Lemma | val ffdhe_p_bits_lemma: a:ffdhe_alg -> Lemma
(let ffdhe_p = get_ffdhe_params a in
let len = ffdhe_len a in
let p = Mk_ffdhe_params?.ffdhe_p ffdhe_p in
let p_n = nat_from_bytes_be p in
pow2 (8 * len - 1) < p_n) | [
{
"abbrev": false,
"full_module": "Spec.FFDHE",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.ByteSequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Sequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.FFDHE",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.FFDHE",
"short_module": null
},
{
"abbrev": 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 ffdhe_p_bits_lemma a =
let ffdhe_p = get_ffdhe_params a in
let len = ffdhe_len a in
let p = Mk_ffdhe_params?.ffdhe_p ffdhe_p in
let p_n = nat_from_bytes_be p in
nat_from_intseq_be_slice_lemma p 1;
assert (p_n == nat_from_bytes_be (slice p 1 len) + pow2 (8 * (len - 1)) * nat_from_bytes_be (slice p 0 1));
nat_from_intseq_be_lemma0 (slice p 0 1);
assert (p_n == nat_from_bytes_be (slice p 1 len) + pow2 (8 * (len - 1)) * v p.[0]);
assert (pow2 (8 * (len - 1)) * v p.[0] <= p_n);
ffdhe_p_lemma_len a;
assert (pow2 (8 * (len - 1)) * (pow2 8 - 1) <= p_n);
pow2_lt_len len | val ffdhe_p_bits_lemma: a:ffdhe_alg -> Lemma
(let ffdhe_p = get_ffdhe_params a in
let len = ffdhe_len a in
let p = Mk_ffdhe_params?.ffdhe_p ffdhe_p in
let p_n = nat_from_bytes_be p in
pow2 (8 * len - 1) < p_n)
let ffdhe_p_bits_lemma a = | false | null | true | let ffdhe_p = get_ffdhe_params a in
let len = ffdhe_len a in
let p = Mk_ffdhe_params?.ffdhe_p ffdhe_p in
let p_n = nat_from_bytes_be p in
nat_from_intseq_be_slice_lemma p 1;
assert (p_n ==
nat_from_bytes_be (slice p 1 len) + pow2 (8 * (len - 1)) * nat_from_bytes_be (slice p 0 1));
nat_from_intseq_be_lemma0 (slice p 0 1);
assert (p_n == nat_from_bytes_be (slice p 1 len) + pow2 (8 * (len - 1)) * v p.[ 0 ]);
assert (pow2 (8 * (len - 1)) * v p.[ 0 ] <= p_n);
ffdhe_p_lemma_len a;
assert (pow2 (8 * (len - 1)) * (pow2 8 - 1) <= p_n);
pow2_lt_len len | {
"checked_file": "Hacl.Spec.FFDHE.Lemmas.fst.checked",
"dependencies": [
"Spec.FFDHE.fst.checked",
"prims.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.ByteSequence.fsti.checked",
"FStar.UInt8.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.List.Tot.fst.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": false,
"source_file": "Hacl.Spec.FFDHE.Lemmas.fst"
} | [
"lemma"
] | [
"Spec.FFDHE.ffdhe_alg",
"Hacl.Spec.FFDHE.Lemmas.pow2_lt_len",
"Prims.unit",
"Prims._assert",
"Prims.b2t",
"Prims.op_LessThanOrEqual",
"FStar.Mul.op_Star",
"Prims.pow2",
"Prims.op_Subtraction",
"Hacl.Spec.FFDHE.Lemmas.ffdhe_p_lemma_len",
"Lib.IntTypes.v",
"Lib.IntTypes.U8",
"Lib.IntTypes.PUB",
"Lib.Sequence.op_String_Access",
"Lib.IntTypes.pub_uint8",
"Spec.FFDHE.__proj__Mk_ffdhe_params__item__ffdhe_p_len",
"Prims.eq2",
"Prims.int",
"Prims.op_Addition",
"Lib.ByteSequence.nat_from_bytes_be",
"Lib.Sequence.slice",
"Lib.ByteSequence.nat_from_intseq_be_lemma0",
"Lib.ByteSequence.nat_from_intseq_be_slice_lemma",
"Prims.nat",
"Prims.op_LessThan",
"Prims.op_Multiply",
"Lib.Sequence.length",
"Lib.IntTypes.int_t",
"Lib.Sequence.lseq",
"Spec.FFDHE.__proj__Mk_ffdhe_params__item__ffdhe_p",
"Prims.pos",
"Spec.FFDHE.ffdhe_len",
"Spec.FFDHE.ffdhe_params_t",
"Spec.FFDHE.get_ffdhe_params"
] | [] | module Hacl.Spec.FFDHE.Lemmas
open FStar.Mul
open Lib.IntTypes
open Lib.Sequence
open Lib.ByteSequence
open Spec.FFDHE
#set-options "--z3rlimit 50 --fuel 0 --ifuel 0"
val ffdhe_p_lemma_len: a:ffdhe_alg -> Lemma
(let ffdhe_p = get_ffdhe_params a in
let p = Mk_ffdhe_params?.ffdhe_p ffdhe_p in
Seq.index p 0 == 0xffuy)
let ffdhe_p_lemma_len a =
let ffdhe_p = get_ffdhe_params a in
let p = Mk_ffdhe_params?.ffdhe_p ffdhe_p in
allow_inversion ffdhe_alg;
match a with
| FFDHE2048 ->
assert (p == of_list list_ffdhe_p2048);
assert_norm (List.Tot.index list_ffdhe_p2048 0 == 0xffuy);
assert (Seq.index (Seq.seq_of_list list_ffdhe_p2048) 0 == 0xffuy)
| FFDHE3072 ->
assert (p == of_list list_ffdhe_p3072);
assert_norm (List.Tot.index list_ffdhe_p3072 0 == 0xffuy);
assert (Seq.index (Seq.seq_of_list list_ffdhe_p3072) 0 == 0xffuy)
| FFDHE4096 ->
assert (p == of_list list_ffdhe_p4096);
assert_norm (List.Tot.index list_ffdhe_p4096 0 == 0xffuy);
assert (Seq.index (Seq.seq_of_list list_ffdhe_p4096) 0 == 0xffuy)
| FFDHE6144 ->
assert (p == of_list list_ffdhe_p6144);
assert_norm (List.Tot.index list_ffdhe_p6144 0 == 0xffuy);
assert (Seq.index (Seq.seq_of_list list_ffdhe_p6144) 0 == 0xffuy)
| FFDHE8192 ->
assert (p == of_list list_ffdhe_p8192);
assert_norm (List.Tot.index list_ffdhe_p8192 0 == 0xffuy);
assert (Seq.index (Seq.seq_of_list list_ffdhe_p8192) 0 == 0xffuy)
// the proof should be somehow simpler
val pow2_lt_len: len:size_pos -> Lemma (pow2 (8 * len - 1) < pow2 (8 * (len - 1)) * (pow2 8 - 1))
let pow2_lt_len len =
let a = pow2 (8 * len - 1) in
let b = pow2 (8 * (len - 1)) * (pow2 8 - 1) in
calc (==) {
b / a;
(==) { Math.Lemmas.pow2_plus (8 * len - 8) 7 }
b / (pow2 (8 * len - 8) * pow2 7);
(==) { Math.Lemmas.division_multiplication_lemma b (pow2 (8 * len - 8)) (pow2 7) }
b / pow2 (8 * len - 8) / pow2 7;
(==) { Math.Lemmas.cancel_mul_div (pow2 8 - 1) (pow2 (8 * len - 8)) }
(pow2 8 - 1) / pow2 7;
(==) { Math.Lemmas.pow2_plus 7 1 }
(pow2 7 * 2 - 1) / pow2 7;
(==) { }
1;
};
// assert (b / a * a <= b);
// assert (a <= b)
calc (>) {
pow2 (8 * len - 8) * (pow2 8 - 1) % pow2 (8 * len - 1);
(==) { Math.Lemmas.pow2_plus (8 * len - 8) 8 }
(pow2 (8 * len) - pow2 (8 * len - 8)) % pow2 (8 * len - 1);
(==) { Math.Lemmas.lemma_mod_plus_distr_l (pow2 (8 * len)) (- pow2 (8 * len - 8)) (pow2 (8 * len - 1)) }
(pow2 (8 * len) % pow2 (8 * len - 1) - pow2 (8 * len - 8)) % pow2 (8 * len - 1);
(==) { Math.Lemmas.pow2_multiplication_modulo_lemma_1 1 (8 * len - 1) (8 * len) }
(0 - pow2 (8 * len - 8)) % pow2 (8 * len - 1);
//(==) { Math.Lemmas.pow2_lt_compat (8 * len - 1) (8 * len - 8) }
//pow2 (8 * len - 1) - pow2 (8 * len - 8);
(>) { Math.Lemmas.pow2_lt_compat (8 * len - 1) (8 * len - 8) }
0;
};
assert (a < b)
val ffdhe_p_bits_lemma: a:ffdhe_alg -> Lemma
(let ffdhe_p = get_ffdhe_params a in
let len = ffdhe_len a in
let p = Mk_ffdhe_params?.ffdhe_p ffdhe_p in
let p_n = nat_from_bytes_be p in
pow2 (8 * len - 1) < p_n) | false | false | Hacl.Spec.FFDHE.Lemmas.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 ffdhe_p_bits_lemma: a:ffdhe_alg -> Lemma
(let ffdhe_p = get_ffdhe_params a in
let len = ffdhe_len a in
let p = Mk_ffdhe_params?.ffdhe_p ffdhe_p in
let p_n = nat_from_bytes_be p in
pow2 (8 * len - 1) < p_n) | [] | Hacl.Spec.FFDHE.Lemmas.ffdhe_p_bits_lemma | {
"file_name": "code/ffdhe/Hacl.Spec.FFDHE.Lemmas.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | a: Spec.FFDHE.ffdhe_alg
-> FStar.Pervasives.Lemma
(ensures
(let ffdhe_p = Spec.FFDHE.get_ffdhe_params a in
let len = Spec.FFDHE.ffdhe_len a in
let p = Mk_ffdhe_params?.ffdhe_p ffdhe_p in
let p_n = Lib.ByteSequence.nat_from_bytes_be p in
Prims.pow2 (8 * len - 1) < p_n)) | {
"end_col": 17,
"end_line": 104,
"start_col": 26,
"start_line": 91
} |
FStar.Pervasives.Lemma | val pow2_lt_len: len:size_pos -> Lemma (pow2 (8 * len - 1) < pow2 (8 * (len - 1)) * (pow2 8 - 1)) | [
{
"abbrev": false,
"full_module": "Spec.FFDHE",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.ByteSequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Sequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.FFDHE",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.FFDHE",
"short_module": null
},
{
"abbrev": 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 pow2_lt_len len =
let a = pow2 (8 * len - 1) in
let b = pow2 (8 * (len - 1)) * (pow2 8 - 1) in
calc (==) {
b / a;
(==) { Math.Lemmas.pow2_plus (8 * len - 8) 7 }
b / (pow2 (8 * len - 8) * pow2 7);
(==) { Math.Lemmas.division_multiplication_lemma b (pow2 (8 * len - 8)) (pow2 7) }
b / pow2 (8 * len - 8) / pow2 7;
(==) { Math.Lemmas.cancel_mul_div (pow2 8 - 1) (pow2 (8 * len - 8)) }
(pow2 8 - 1) / pow2 7;
(==) { Math.Lemmas.pow2_plus 7 1 }
(pow2 7 * 2 - 1) / pow2 7;
(==) { }
1;
};
// assert (b / a * a <= b);
// assert (a <= b)
calc (>) {
pow2 (8 * len - 8) * (pow2 8 - 1) % pow2 (8 * len - 1);
(==) { Math.Lemmas.pow2_plus (8 * len - 8) 8 }
(pow2 (8 * len) - pow2 (8 * len - 8)) % pow2 (8 * len - 1);
(==) { Math.Lemmas.lemma_mod_plus_distr_l (pow2 (8 * len)) (- pow2 (8 * len - 8)) (pow2 (8 * len - 1)) }
(pow2 (8 * len) % pow2 (8 * len - 1) - pow2 (8 * len - 8)) % pow2 (8 * len - 1);
(==) { Math.Lemmas.pow2_multiplication_modulo_lemma_1 1 (8 * len - 1) (8 * len) }
(0 - pow2 (8 * len - 8)) % pow2 (8 * len - 1);
//(==) { Math.Lemmas.pow2_lt_compat (8 * len - 1) (8 * len - 8) }
//pow2 (8 * len - 1) - pow2 (8 * len - 8);
(>) { Math.Lemmas.pow2_lt_compat (8 * len - 1) (8 * len - 8) }
0;
};
assert (a < b) | val pow2_lt_len: len:size_pos -> Lemma (pow2 (8 * len - 1) < pow2 (8 * (len - 1)) * (pow2 8 - 1))
let pow2_lt_len len = | false | null | true | let a = pow2 (8 * len - 1) in
let b = pow2 (8 * (len - 1)) * (pow2 8 - 1) in
calc ( == ) {
b / a;
( == ) { Math.Lemmas.pow2_plus (8 * len - 8) 7 }
b / (pow2 (8 * len - 8) * pow2 7);
( == ) { Math.Lemmas.division_multiplication_lemma b (pow2 (8 * len - 8)) (pow2 7) }
b / pow2 (8 * len - 8) / pow2 7;
( == ) { Math.Lemmas.cancel_mul_div (pow2 8 - 1) (pow2 (8 * len - 8)) }
(pow2 8 - 1) / pow2 7;
( == ) { Math.Lemmas.pow2_plus 7 1 }
(pow2 7 * 2 - 1) / pow2 7;
( == ) { () }
1;
};
calc ( > ) {
pow2 (8 * len - 8) * (pow2 8 - 1) % pow2 (8 * len - 1);
( == ) { Math.Lemmas.pow2_plus (8 * len - 8) 8 }
(pow2 (8 * len) - pow2 (8 * len - 8)) % pow2 (8 * len - 1);
( == ) { Math.Lemmas.lemma_mod_plus_distr_l (pow2 (8 * len))
(- pow2 (8 * len - 8))
(pow2 (8 * len - 1)) }
(pow2 (8 * len) % pow2 (8 * len - 1) - pow2 (8 * len - 8)) % pow2 (8 * len - 1);
( == ) { Math.Lemmas.pow2_multiplication_modulo_lemma_1 1 (8 * len - 1) (8 * len) }
(0 - pow2 (8 * len - 8)) % pow2 (8 * len - 1);
( > ) { Math.Lemmas.pow2_lt_compat (8 * len - 1) (8 * len - 8) }
0;
};
assert (a < b) | {
"checked_file": "Hacl.Spec.FFDHE.Lemmas.fst.checked",
"dependencies": [
"Spec.FFDHE.fst.checked",
"prims.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.ByteSequence.fsti.checked",
"FStar.UInt8.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.List.Tot.fst.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": false,
"source_file": "Hacl.Spec.FFDHE.Lemmas.fst"
} | [
"lemma"
] | [
"Lib.IntTypes.size_pos",
"Prims._assert",
"Prims.b2t",
"Prims.op_LessThan",
"Prims.unit",
"FStar.Calc.calc_finish",
"Prims.int",
"Prims.op_GreaterThan",
"Prims.op_Modulus",
"FStar.Mul.op_Star",
"Prims.pow2",
"Prims.op_Subtraction",
"Prims.Cons",
"FStar.Preorder.relation",
"Prims.eq2",
"Prims.Nil",
"FStar.Calc.calc_step",
"FStar.Calc.calc_init",
"FStar.Calc.calc_pack",
"FStar.Math.Lemmas.pow2_plus",
"Prims.squash",
"FStar.Math.Lemmas.lemma_mod_plus_distr_l",
"Prims.op_Minus",
"FStar.Math.Lemmas.pow2_multiplication_modulo_lemma_1",
"FStar.Math.Lemmas.pow2_lt_compat",
"Prims.op_Division",
"FStar.Math.Lemmas.division_multiplication_lemma",
"FStar.Math.Lemmas.cancel_mul_div",
"Prims.pos"
] | [] | module Hacl.Spec.FFDHE.Lemmas
open FStar.Mul
open Lib.IntTypes
open Lib.Sequence
open Lib.ByteSequence
open Spec.FFDHE
#set-options "--z3rlimit 50 --fuel 0 --ifuel 0"
val ffdhe_p_lemma_len: a:ffdhe_alg -> Lemma
(let ffdhe_p = get_ffdhe_params a in
let p = Mk_ffdhe_params?.ffdhe_p ffdhe_p in
Seq.index p 0 == 0xffuy)
let ffdhe_p_lemma_len a =
let ffdhe_p = get_ffdhe_params a in
let p = Mk_ffdhe_params?.ffdhe_p ffdhe_p in
allow_inversion ffdhe_alg;
match a with
| FFDHE2048 ->
assert (p == of_list list_ffdhe_p2048);
assert_norm (List.Tot.index list_ffdhe_p2048 0 == 0xffuy);
assert (Seq.index (Seq.seq_of_list list_ffdhe_p2048) 0 == 0xffuy)
| FFDHE3072 ->
assert (p == of_list list_ffdhe_p3072);
assert_norm (List.Tot.index list_ffdhe_p3072 0 == 0xffuy);
assert (Seq.index (Seq.seq_of_list list_ffdhe_p3072) 0 == 0xffuy)
| FFDHE4096 ->
assert (p == of_list list_ffdhe_p4096);
assert_norm (List.Tot.index list_ffdhe_p4096 0 == 0xffuy);
assert (Seq.index (Seq.seq_of_list list_ffdhe_p4096) 0 == 0xffuy)
| FFDHE6144 ->
assert (p == of_list list_ffdhe_p6144);
assert_norm (List.Tot.index list_ffdhe_p6144 0 == 0xffuy);
assert (Seq.index (Seq.seq_of_list list_ffdhe_p6144) 0 == 0xffuy)
| FFDHE8192 ->
assert (p == of_list list_ffdhe_p8192);
assert_norm (List.Tot.index list_ffdhe_p8192 0 == 0xffuy);
assert (Seq.index (Seq.seq_of_list list_ffdhe_p8192) 0 == 0xffuy)
// the proof should be somehow simpler | false | false | Hacl.Spec.FFDHE.Lemmas.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 pow2_lt_len: len:size_pos -> Lemma (pow2 (8 * len - 1) < pow2 (8 * (len - 1)) * (pow2 8 - 1)) | [] | Hacl.Spec.FFDHE.Lemmas.pow2_lt_len | {
"file_name": "code/ffdhe/Hacl.Spec.FFDHE.Lemmas.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | len: Lib.IntTypes.size_pos
-> FStar.Pervasives.Lemma
(ensures Prims.pow2 (8 * len - 1) < Prims.pow2 (8 * (len - 1)) * (Prims.pow2 8 - 1)) | {
"end_col": 16,
"end_line": 81,
"start_col": 21,
"start_line": 48
} |
FStar.Pervasives.Lemma | val ffdhe_p_lemma_len: a:ffdhe_alg -> Lemma
(let ffdhe_p = get_ffdhe_params a in
let p = Mk_ffdhe_params?.ffdhe_p ffdhe_p in
Seq.index p 0 == 0xffuy) | [
{
"abbrev": false,
"full_module": "Spec.FFDHE",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.ByteSequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Sequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.FFDHE",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.FFDHE",
"short_module": null
},
{
"abbrev": 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 ffdhe_p_lemma_len a =
let ffdhe_p = get_ffdhe_params a in
let p = Mk_ffdhe_params?.ffdhe_p ffdhe_p in
allow_inversion ffdhe_alg;
match a with
| FFDHE2048 ->
assert (p == of_list list_ffdhe_p2048);
assert_norm (List.Tot.index list_ffdhe_p2048 0 == 0xffuy);
assert (Seq.index (Seq.seq_of_list list_ffdhe_p2048) 0 == 0xffuy)
| FFDHE3072 ->
assert (p == of_list list_ffdhe_p3072);
assert_norm (List.Tot.index list_ffdhe_p3072 0 == 0xffuy);
assert (Seq.index (Seq.seq_of_list list_ffdhe_p3072) 0 == 0xffuy)
| FFDHE4096 ->
assert (p == of_list list_ffdhe_p4096);
assert_norm (List.Tot.index list_ffdhe_p4096 0 == 0xffuy);
assert (Seq.index (Seq.seq_of_list list_ffdhe_p4096) 0 == 0xffuy)
| FFDHE6144 ->
assert (p == of_list list_ffdhe_p6144);
assert_norm (List.Tot.index list_ffdhe_p6144 0 == 0xffuy);
assert (Seq.index (Seq.seq_of_list list_ffdhe_p6144) 0 == 0xffuy)
| FFDHE8192 ->
assert (p == of_list list_ffdhe_p8192);
assert_norm (List.Tot.index list_ffdhe_p8192 0 == 0xffuy);
assert (Seq.index (Seq.seq_of_list list_ffdhe_p8192) 0 == 0xffuy) | val ffdhe_p_lemma_len: a:ffdhe_alg -> Lemma
(let ffdhe_p = get_ffdhe_params a in
let p = Mk_ffdhe_params?.ffdhe_p ffdhe_p in
Seq.index p 0 == 0xffuy)
let ffdhe_p_lemma_len a = | false | null | true | let ffdhe_p = get_ffdhe_params a in
let p = Mk_ffdhe_params?.ffdhe_p ffdhe_p in
allow_inversion ffdhe_alg;
match a with
| FFDHE2048 ->
assert (p == of_list list_ffdhe_p2048);
assert_norm (List.Tot.index list_ffdhe_p2048 0 == 0xffuy);
assert (Seq.index (Seq.seq_of_list list_ffdhe_p2048) 0 == 0xffuy)
| FFDHE3072 ->
assert (p == of_list list_ffdhe_p3072);
assert_norm (List.Tot.index list_ffdhe_p3072 0 == 0xffuy);
assert (Seq.index (Seq.seq_of_list list_ffdhe_p3072) 0 == 0xffuy)
| FFDHE4096 ->
assert (p == of_list list_ffdhe_p4096);
assert_norm (List.Tot.index list_ffdhe_p4096 0 == 0xffuy);
assert (Seq.index (Seq.seq_of_list list_ffdhe_p4096) 0 == 0xffuy)
| FFDHE6144 ->
assert (p == of_list list_ffdhe_p6144);
assert_norm (List.Tot.index list_ffdhe_p6144 0 == 0xffuy);
assert (Seq.index (Seq.seq_of_list list_ffdhe_p6144) 0 == 0xffuy)
| FFDHE8192 ->
assert (p == of_list list_ffdhe_p8192);
assert_norm (List.Tot.index list_ffdhe_p8192 0 == 0xffuy);
assert (Seq.index (Seq.seq_of_list list_ffdhe_p8192) 0 == 0xffuy) | {
"checked_file": "Hacl.Spec.FFDHE.Lemmas.fst.checked",
"dependencies": [
"Spec.FFDHE.fst.checked",
"prims.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.ByteSequence.fsti.checked",
"FStar.UInt8.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.List.Tot.fst.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": false,
"source_file": "Hacl.Spec.FFDHE.Lemmas.fst"
} | [
"lemma"
] | [
"Spec.FFDHE.ffdhe_alg",
"Prims._assert",
"Prims.eq2",
"FStar.UInt8.t",
"FStar.Seq.Base.index",
"Lib.IntTypes.int_t",
"Lib.IntTypes.U8",
"Lib.IntTypes.PUB",
"FStar.Seq.Properties.seq_of_list",
"Spec.FFDHE.list_ffdhe_p2048",
"FStar.UInt8.__uint_to_t",
"Prims.unit",
"FStar.Pervasives.assert_norm",
"FStar.List.Tot.Base.index",
"Lib.Sequence.seq",
"Lib.IntTypes.pub_uint8",
"Prims.l_or",
"Prims.nat",
"FStar.Seq.Base.length",
"Spec.FFDHE.__proj__Mk_ffdhe_params__item__ffdhe_p_len",
"Prims.l_and",
"FStar.List.Tot.Base.length",
"FStar.Seq.Base.seq",
"Lib.Sequence.to_seq",
"Lib.Sequence.of_list",
"Spec.FFDHE.list_ffdhe_p3072",
"Spec.FFDHE.list_ffdhe_p4096",
"Spec.FFDHE.list_ffdhe_p6144",
"Spec.FFDHE.list_ffdhe_p8192",
"FStar.Pervasives.allow_inversion",
"Lib.Sequence.lseq",
"Spec.FFDHE.__proj__Mk_ffdhe_params__item__ffdhe_p",
"Spec.FFDHE.ffdhe_params_t",
"Spec.FFDHE.get_ffdhe_params"
] | [] | module Hacl.Spec.FFDHE.Lemmas
open FStar.Mul
open Lib.IntTypes
open Lib.Sequence
open Lib.ByteSequence
open Spec.FFDHE
#set-options "--z3rlimit 50 --fuel 0 --ifuel 0"
val ffdhe_p_lemma_len: a:ffdhe_alg -> Lemma
(let ffdhe_p = get_ffdhe_params a in
let p = Mk_ffdhe_params?.ffdhe_p ffdhe_p in
Seq.index p 0 == 0xffuy) | false | false | Hacl.Spec.FFDHE.Lemmas.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 ffdhe_p_lemma_len: a:ffdhe_alg -> Lemma
(let ffdhe_p = get_ffdhe_params a in
let p = Mk_ffdhe_params?.ffdhe_p ffdhe_p in
Seq.index p 0 == 0xffuy) | [] | Hacl.Spec.FFDHE.Lemmas.ffdhe_p_lemma_len | {
"file_name": "code/ffdhe/Hacl.Spec.FFDHE.Lemmas.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | a: Spec.FFDHE.ffdhe_alg
-> FStar.Pervasives.Lemma
(ensures
(let ffdhe_p = Spec.FFDHE.get_ffdhe_params a in
let p = Mk_ffdhe_params?.ffdhe_p ffdhe_p in
FStar.Seq.Base.index p 0 == 0xffuy)) | {
"end_col": 69,
"end_line": 43,
"start_col": 25,
"start_line": 18
} |
Prims.Tot | val cswap2: cswap2_t M64 p | [
{
"abbrev": true,
"full_module": "Hacl.Impl.Curve25519.Field64",
"short_module": "F64"
},
{
"abbrev": true,
"full_module": "Vale.Wrapper.X64.Fadd",
"short_module": "FA"
},
{
"abbrev": true,
"full_module": "Spec.Curve25519",
"short_module": "P"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.Curve25519.Field64.Definition",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "Lib.Buffer",
"short_module": "B"
},
{
"abbrev": false,
"full_module": "Lib.Buffer",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Sequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.All",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Calc",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": false,
"full_module": "Hacl.Impl.Curve25519.Fields.Core",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl.Curve25519.Field64",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl.Curve25519.Field64",
"short_module": null
},
{
"abbrev": 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 cswap2 bit p1 p2 =
let h0 = ST.get() in
if EverCrypt.TargetConfig.hacl_can_compile_inline_asm then
Vale.Inline.X64.Fswap_inline.cswap2 bit p1 p2
else
Vale.Wrapper.X64.Fswap.cswap2_e bit p1 p2;
let h1 = ST.get() in
// Seq.equal is swapped in the interop wrappers, so the SMTPat is not matching:
// We have Seq.equal s1 s2 but are trying to prove s2 == s1
let aux1 () : Lemma
(requires v bit == 1)
(ensures as_seq h1 p1 == as_seq h0 p2 /\ as_seq h1 p2 == as_seq h0 p1)
= Seq.lemma_eq_elim (B.as_seq h0 p2) (B.as_seq h1 p1);
Seq.lemma_eq_elim (B.as_seq h0 p1) (B.as_seq h1 p2)
in let aux2 () : Lemma
(requires v bit == 0)
(ensures as_seq h1 p1 == as_seq h0 p1 /\ as_seq h1 p2 == as_seq h0 p2)
= Seq.lemma_eq_elim (B.as_seq h0 p1) (B.as_seq h1 p1);
Seq.lemma_eq_elim (B.as_seq h0 p2) (B.as_seq h1 p2)
in
Classical.move_requires aux1 ();
Classical.move_requires aux2 () | val cswap2: cswap2_t M64 p
let cswap2 bit p1 p2 = | false | null | false | let h0 = ST.get () in
if EverCrypt.TargetConfig.hacl_can_compile_inline_asm
then Vale.Inline.X64.Fswap_inline.cswap2 bit p1 p2
else Vale.Wrapper.X64.Fswap.cswap2_e bit p1 p2;
let h1 = ST.get () in
let aux1 ()
: Lemma (requires v bit == 1)
(ensures as_seq h1 p1 == as_seq h0 p2 /\ as_seq h1 p2 == as_seq h0 p1) =
Seq.lemma_eq_elim (B.as_seq h0 p2) (B.as_seq h1 p1);
Seq.lemma_eq_elim (B.as_seq h0 p1) (B.as_seq h1 p2)
in
let aux2 ()
: Lemma (requires v bit == 0)
(ensures as_seq h1 p1 == as_seq h0 p1 /\ as_seq h1 p2 == as_seq h0 p2) =
Seq.lemma_eq_elim (B.as_seq h0 p1) (B.as_seq h1 p1);
Seq.lemma_eq_elim (B.as_seq h0 p2) (B.as_seq h1 p2)
in
Classical.move_requires aux1 ();
Classical.move_requires aux2 () | {
"checked_file": "Hacl.Impl.Curve25519.Field64.Vale.fst.checked",
"dependencies": [
"Vale.Wrapper.X64.Fswap.fsti.checked",
"Vale.Wrapper.X64.Fsub.fsti.checked",
"Vale.Wrapper.X64.Fsqr.fsti.checked",
"Vale.Wrapper.X64.Fmul.fsti.checked",
"Vale.Wrapper.X64.Fadd.fsti.checked",
"Vale.Inline.X64.Fswap_inline.fsti.checked",
"Vale.Inline.X64.Fsqr_inline.fsti.checked",
"Vale.Inline.X64.Fmul_inline.fsti.checked",
"Vale.Inline.X64.Fadd_inline.fsti.checked",
"Vale.Curve25519.Fast_defs.fst.checked",
"Spec.Curve25519.fst.checked",
"prims.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.IntTypes.fst.checked",
"Lib.Buffer.fst.checked",
"Hacl.Spec.Curve25519.Field64.Definition.fst.checked",
"Hacl.Impl.Curve25519.Field64.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.All.fst.checked",
"FStar.HyperStack.fst.checked",
"FStar.Classical.fsti.checked",
"FStar.Calc.fsti.checked",
"EverCrypt.TargetConfig.fsti.checked"
],
"interface_file": true,
"source_file": "Hacl.Impl.Curve25519.Field64.Vale.fst"
} | [
"total"
] | [
"Lib.IntTypes.uint64",
"Prims.b2t",
"Prims.op_LessThanOrEqual",
"Lib.IntTypes.v",
"Lib.IntTypes.U64",
"Lib.IntTypes.SEC",
"Hacl.Impl.Curve25519.Fields.Core.felem2",
"Hacl.Impl.Curve25519.Fields.Core.M64",
"FStar.Classical.move_requires",
"Prims.unit",
"Prims.eq2",
"Prims.int",
"Prims.l_and",
"Lib.Sequence.lseq",
"Hacl.Impl.Curve25519.Fields.Core.limb",
"Lib.IntTypes.U32",
"Lib.IntTypes.PUB",
"Lib.IntTypes.op_Plus_Dot",
"Hacl.Impl.Curve25519.Fields.Core.nlimb",
"Lib.Buffer.as_seq",
"Lib.Buffer.MUT",
"Prims.squash",
"Lib.IntTypes.int_t",
"Lib.IntTypes.add_mod",
"FStar.UInt32.uint_to_t",
"FStar.UInt32.t",
"Prims.Nil",
"FStar.Pervasives.pattern",
"FStar.Seq.Base.lemma_eq_elim",
"FStar.Monotonic.HyperStack.mem",
"FStar.HyperStack.ST.get",
"EverCrypt.TargetConfig.hacl_can_compile_inline_asm",
"Vale.Inline.X64.Fswap_inline.cswap2",
"Prims.bool",
"Vale.Wrapper.X64.Fswap.cswap2_e"
] | [] | module Hacl.Impl.Curve25519.Field64.Vale
module HS = FStar.HyperStack
module ST = FStar.HyperStack.ST
open FStar.Calc
friend Lib.Buffer
friend Lib.IntTypes
open FStar.HyperStack
open FStar.HyperStack.All
open FStar.Mul
open Lib.Sequence
open Lib.IntTypes
open Lib.Buffer
module B = Lib.Buffer
module S = Hacl.Spec.Curve25519.Field64.Definition
module P = Spec.Curve25519
module FA = Vale.Wrapper.X64.Fadd
module F64 = Hacl.Impl.Curve25519.Field64
/// We are trying to connect HACL* abstractions with regular F* libraries, so in
/// addition to ``friend``'ing ``Lib.*``, we also write a couple lemmas that we
/// prove via normalization to facilitate the job of proving that calling the
/// Vale interop signatures faithfully implements the required HACL* signature.
#set-options "--max_fuel 0 --max_ifuel 0 --z3rlimit 300 --z3refresh"
let buffer_is_buffer a len: Lemma
(ensures (lbuffer a len == b:B.buffer a{B.length b == UInt32.v len}))
[ SMTPat (lbuffer a len) ]
=
assert_norm (lbuffer a len == b:B.buffer a{B.length b == UInt32.v len})
let as_nat_is_as_nat (b:lbuffer uint64 4ul) (h:HS.mem): Lemma
(ensures (FA.as_nat b h == F64.as_nat h b))
[ SMTPat (as_nat h b) ]
=
()
let _: squash (Vale.Curve25519.Fast_defs.prime = Spec.Curve25519.prime) =
assert_norm (Vale.Curve25519.Fast_defs.prime = Spec.Curve25519.prime)
// This one only goes through in a reasonable amount of rlimit thanks to
// ``as_nat_is_as_nat`` and ``buffer_is_buffer`` above.
[@ CInline]
let add_scalar out f1 f2 =
if EverCrypt.TargetConfig.hacl_can_compile_inline_asm then
Vale.Inline.X64.Fadd_inline.add_scalar out f1 f2
else
Vale.Wrapper.X64.Fadd.add_scalar_e out f1 f2
// Spec discrepancy. Need to call the right lemma from FStar.Math.Lemmas.
#push-options "--max_fuel 0 --max_ifuel 0 --z3rlimit 400"
[@ CInline]
let fadd out f1 f2 =
let h0 = ST.get () in
let aux () : Lemma (P.fadd (F64.fevalh h0 f1) (F64.fevalh h0 f2) == (FA.as_nat f1 h0 + FA.as_nat f2 h0) % Vale.Curve25519.Fast_defs.prime) =
let a = P.fadd (F64.fevalh h0 f1) (F64.fevalh h0 f2) in
let a1 = (as_nat h0 f1 % Vale.Curve25519.Fast_defs.prime + as_nat h0 f2 % Vale.Curve25519.Fast_defs.prime) % Vale.Curve25519.Fast_defs.prime in
let a2 = (as_nat h0 f1 % Vale.Curve25519.Fast_defs.prime + as_nat h0 f2) % Vale.Curve25519.Fast_defs.prime in
let a3 = (as_nat h0 f1 + as_nat h0 f2) % Vale.Curve25519.Fast_defs.prime in
let b = (FA.as_nat f1 h0 + FA.as_nat f2 h0) % Vale.Curve25519.Fast_defs.prime in
calc (==) {
a;
== { FStar.Math.Lemmas.modulo_distributivity
(as_nat h0 f1) (as_nat h0 f2) Vale.Curve25519.Fast_defs.prime }
a1;
== { FStar.Math.Lemmas.lemma_mod_add_distr (as_nat h0 f1 % Vale.Curve25519.Fast_defs.prime)
(as_nat h0 f2) Vale.Curve25519.Fast_defs.prime }
a2;
== { FStar.Math.Lemmas.lemma_mod_add_distr (as_nat h0 f2) (as_nat h0 f1) Vale.Curve25519.Fast_defs.prime }
a3;
== { }
b;
}
in aux();
if EverCrypt.TargetConfig.hacl_can_compile_inline_asm then
Vale.Inline.X64.Fadd_inline.fadd out f1 f2
else
Vale.Wrapper.X64.Fadd.fadd_e out f1 f2
#pop-options
[@ CInline]
let fsub out f1 f2 =
let h0 = ST.get() in
let aux () : Lemma (P.fsub (F64.fevalh h0 f1) (F64.fevalh h0 f2) == (FA.as_nat f1 h0 - FA.as_nat f2 h0) % Vale.Curve25519.Fast_defs.prime) =
let a = P.fsub (F64.fevalh h0 f1) (F64.fevalh h0 f2) in
let a1 = (as_nat h0 f1 % Vale.Curve25519.Fast_defs.prime - as_nat h0 f2 % Vale.Curve25519.Fast_defs.prime) % Vale.Curve25519.Fast_defs.prime in
let a2 = (as_nat h0 f1 % Vale.Curve25519.Fast_defs.prime - as_nat h0 f2) % Vale.Curve25519.Fast_defs.prime in
let a3 = (as_nat h0 f1 - as_nat h0 f2) % Vale.Curve25519.Fast_defs.prime in
let b = (FA.as_nat f1 h0 - FA.as_nat f2 h0) % Vale.Curve25519.Fast_defs.prime in
calc (==) {
a;
== { }
a1;
== { FStar.Math.Lemmas.lemma_mod_sub_distr (as_nat h0 f1 % Vale.Curve25519.Fast_defs.prime) (as_nat h0 f2)
Vale.Curve25519.Fast_defs.prime }
a2;
== { FStar.Math.Lemmas.lemma_mod_add_distr (- as_nat h0 f2) (as_nat h0 f1) Vale.Curve25519.Fast_defs.prime }
a3;
== { }
b;
}
in aux();
if EverCrypt.TargetConfig.hacl_can_compile_inline_asm then
Vale.Inline.X64.Fadd_inline.fsub out f1 f2
else
Vale.Wrapper.X64.Fsub.fsub_e out f1 f2
#push-options "--z3rlimit 200"
let lemma_fmul_equiv (h0:HS.mem) (f1 f2:F64.u256) : Lemma
(P.fmul (F64.fevalh h0 f1) (F64.fevalh h0 f2) == (FA.as_nat f1 h0 * FA.as_nat f2 h0) % Vale.Curve25519.Fast_defs.prime)
= let a = P.fmul (F64.fevalh h0 f1) (F64.fevalh h0 f2) in
let a1 = ((F64.as_nat h0 f1 % Vale.Curve25519.Fast_defs.prime) * (F64.as_nat h0 f2 % Vale.Curve25519.Fast_defs.prime)) % Vale.Curve25519.Fast_defs.prime in
let a2 = ((F64.as_nat h0 f1 % Vale.Curve25519.Fast_defs.prime) * F64.as_nat h0 f2) % Vale.Curve25519.Fast_defs.prime in
let a3 = (F64.as_nat h0 f1 * F64.as_nat h0 f2) % Vale.Curve25519.Fast_defs.prime in
let b = (FA.as_nat f1 h0 * FA.as_nat f2 h0) % Vale.Curve25519.Fast_defs.prime in
calc (==) {
a;
== { }
a1;
== { FStar.Math.Lemmas.lemma_mod_mul_distr_r (F64.as_nat h0 f1 % Vale.Curve25519.Fast_defs.prime) (F64.as_nat h0 f2) Vale.Curve25519.Fast_defs.prime }
a2;
== { FStar.Math.Lemmas.lemma_mod_mul_distr_l (F64.as_nat h0 f1) (F64.as_nat h0 f2) Vale.Curve25519.Fast_defs.prime }
a3;
== { }
b;
}
#pop-options
[@ CInline]
let fmul out f1 f2 tmp =
let h0 = ST.get() in
lemma_fmul_equiv h0 f1 f2;
if EverCrypt.TargetConfig.hacl_can_compile_inline_asm then (
assert (disjoint f1 (gsub tmp 0ul 8ul));
assert (disjoint f2 (gsub tmp 0ul 8ul));
Vale.Inline.X64.Fmul_inline.fmul out f1 f2 (sub tmp 0ul 8ul)
) else
Vale.Wrapper.X64.Fmul.fmul_e (sub tmp 0ul 8ul) f1 out f2
#push-options "--z3rlimit 500"
[@ CInline]
let fmul2 out f1 f2 tmp =
let h0 = ST.get() in
lemma_fmul_equiv h0 (gsub f1 0ul 4ul) (gsub f2 0ul 4ul);
lemma_fmul_equiv h0 (gsub f1 4ul 4ul) (gsub f2 4ul 4ul);
if EverCrypt.TargetConfig.hacl_can_compile_inline_asm then
Vale.Inline.X64.Fmul_inline.fmul2 out f1 f2 tmp
else
Vale.Wrapper.X64.Fmul.fmul2_e tmp f1 out f2
#pop-options
[@ CInline]
let fmul_scalar out f1 f2 =
let h0 = ST.get() in
let aux () : Lemma (P.fmul (F64.fevalh h0 f1) (v f2) == (FA.as_nat f1 h0 * v f2) % Vale.Curve25519.Fast_defs.prime) =
let a = P.fmul (F64.fevalh h0 f1) (v f2) in
let a1 = ((F64.as_nat h0 f1 % Vale.Curve25519.Fast_defs.prime) * v f2) % Vale.Curve25519.Fast_defs.prime in
let a2 = (F64.as_nat h0 f1 * v f2) % Vale.Curve25519.Fast_defs.prime in
let b = (FA.as_nat f1 h0 * v f2) % Vale.Curve25519.Fast_defs.prime in
calc (==) {
a;
== { }
a1;
== { FStar.Math.Lemmas.lemma_mod_mul_distr_l (F64.as_nat h0 f1) (v f2) Vale.Curve25519.Fast_defs.prime }
a2;
== { }
b;
}
in aux();
assert_norm (pow2 17 = 131072);
if EverCrypt.TargetConfig.hacl_can_compile_inline_asm then
Vale.Inline.X64.Fmul_inline.fmul_scalar out f1 f2
else
Vale.Wrapper.X64.Fmul.fmul_scalar_e out f1 f2
[@ CInline]
let fsqr out f1 tmp =
let h0 = ST.get() in
lemma_fmul_equiv h0 f1 f1;
if EverCrypt.TargetConfig.hacl_can_compile_inline_asm then
Vale.Inline.X64.Fsqr_inline.fsqr out f1 tmp
else
Vale.Wrapper.X64.Fsqr.fsqr_e tmp f1 out
[@ CInline]
let fsqr2 out f tmp =
let h0 = ST.get() in
lemma_fmul_equiv h0 (gsub f 0ul 4ul) (gsub f 0ul 4ul);
lemma_fmul_equiv h0 (gsub f 4ul 4ul) (gsub f 4ul 4ul);
if EverCrypt.TargetConfig.hacl_can_compile_inline_asm then
Vale.Inline.X64.Fsqr_inline.fsqr2 out f tmp
else
Vale.Wrapper.X64.Fsqr.fsqr2_e tmp f out | false | true | Hacl.Impl.Curve25519.Field64.Vale.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": true,
"z3rlimit": 300,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val cswap2: cswap2_t M64 p | [] | Hacl.Impl.Curve25519.Field64.Vale.cswap2 | {
"file_name": "code/curve25519/Hacl.Impl.Curve25519.Field64.Vale.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | Hacl.Impl.Curve25519.Fields.Core.cswap2_t Hacl.Impl.Curve25519.Fields.Core.M64
Hacl.Impl.Curve25519.Field64.Vale.p | {
"end_col": 33,
"end_line": 224,
"start_col": 22,
"start_line": 203
} |
Prims.Tot | val fmul: fmul_t M64 p | [
{
"abbrev": true,
"full_module": "Hacl.Impl.Curve25519.Field64",
"short_module": "F64"
},
{
"abbrev": true,
"full_module": "Vale.Wrapper.X64.Fadd",
"short_module": "FA"
},
{
"abbrev": true,
"full_module": "Spec.Curve25519",
"short_module": "P"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.Curve25519.Field64.Definition",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "Lib.Buffer",
"short_module": "B"
},
{
"abbrev": false,
"full_module": "Lib.Buffer",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Sequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.All",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Calc",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": false,
"full_module": "Hacl.Impl.Curve25519.Fields.Core",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl.Curve25519.Field64",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl.Curve25519.Field64",
"short_module": null
},
{
"abbrev": 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 fmul out f1 f2 tmp =
let h0 = ST.get() in
lemma_fmul_equiv h0 f1 f2;
if EverCrypt.TargetConfig.hacl_can_compile_inline_asm then (
assert (disjoint f1 (gsub tmp 0ul 8ul));
assert (disjoint f2 (gsub tmp 0ul 8ul));
Vale.Inline.X64.Fmul_inline.fmul out f1 f2 (sub tmp 0ul 8ul)
) else
Vale.Wrapper.X64.Fmul.fmul_e (sub tmp 0ul 8ul) f1 out f2 | val fmul: fmul_t M64 p
let fmul out f1 f2 tmp = | false | null | false | let h0 = ST.get () in
lemma_fmul_equiv h0 f1 f2;
if EverCrypt.TargetConfig.hacl_can_compile_inline_asm
then
(assert (disjoint f1 (gsub tmp 0ul 8ul));
assert (disjoint f2 (gsub tmp 0ul 8ul));
Vale.Inline.X64.Fmul_inline.fmul out f1 f2 (sub tmp 0ul 8ul))
else Vale.Wrapper.X64.Fmul.fmul_e (sub tmp 0ul 8ul) f1 out f2 | {
"checked_file": "Hacl.Impl.Curve25519.Field64.Vale.fst.checked",
"dependencies": [
"Vale.Wrapper.X64.Fswap.fsti.checked",
"Vale.Wrapper.X64.Fsub.fsti.checked",
"Vale.Wrapper.X64.Fsqr.fsti.checked",
"Vale.Wrapper.X64.Fmul.fsti.checked",
"Vale.Wrapper.X64.Fadd.fsti.checked",
"Vale.Inline.X64.Fswap_inline.fsti.checked",
"Vale.Inline.X64.Fsqr_inline.fsti.checked",
"Vale.Inline.X64.Fmul_inline.fsti.checked",
"Vale.Inline.X64.Fadd_inline.fsti.checked",
"Vale.Curve25519.Fast_defs.fst.checked",
"Spec.Curve25519.fst.checked",
"prims.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.IntTypes.fst.checked",
"Lib.Buffer.fst.checked",
"Hacl.Spec.Curve25519.Field64.Definition.fst.checked",
"Hacl.Impl.Curve25519.Field64.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.All.fst.checked",
"FStar.HyperStack.fst.checked",
"FStar.Classical.fsti.checked",
"FStar.Calc.fsti.checked",
"EverCrypt.TargetConfig.fsti.checked"
],
"interface_file": true,
"source_file": "Hacl.Impl.Curve25519.Field64.Vale.fst"
} | [
"total"
] | [
"Hacl.Impl.Curve25519.Fields.Core.felem",
"Hacl.Impl.Curve25519.Fields.Core.M64",
"Hacl.Impl.Curve25519.Fields.Core.felem_wide2",
"EverCrypt.TargetConfig.hacl_can_compile_inline_asm",
"Vale.Inline.X64.Fmul_inline.fmul",
"Prims.unit",
"LowStar.Buffer.buffer",
"FStar.UInt64.t",
"Prims.eq2",
"Prims.int",
"LowStar.Monotonic.Buffer.length",
"LowStar.Buffer.trivial_preorder",
"Lib.Buffer.sub",
"Lib.Buffer.MUT",
"Hacl.Impl.Curve25519.Fields.Core.wide",
"Lib.IntTypes.op_Plus_Dot",
"Lib.IntTypes.U32",
"Lib.IntTypes.PUB",
"Hacl.Impl.Curve25519.Fields.Core.nwide",
"FStar.UInt32.__uint_to_t",
"Lib.Buffer.lbuffer_t",
"Prims._assert",
"Lib.Buffer.disjoint",
"Hacl.Impl.Curve25519.Fields.Core.limb",
"Lib.Buffer.gsub",
"Prims.bool",
"Vale.Wrapper.X64.Fmul.fmul_e",
"Hacl.Impl.Curve25519.Field64.Vale.lemma_fmul_equiv",
"FStar.Monotonic.HyperStack.mem",
"FStar.HyperStack.ST.get"
] | [] | module Hacl.Impl.Curve25519.Field64.Vale
module HS = FStar.HyperStack
module ST = FStar.HyperStack.ST
open FStar.Calc
friend Lib.Buffer
friend Lib.IntTypes
open FStar.HyperStack
open FStar.HyperStack.All
open FStar.Mul
open Lib.Sequence
open Lib.IntTypes
open Lib.Buffer
module B = Lib.Buffer
module S = Hacl.Spec.Curve25519.Field64.Definition
module P = Spec.Curve25519
module FA = Vale.Wrapper.X64.Fadd
module F64 = Hacl.Impl.Curve25519.Field64
/// We are trying to connect HACL* abstractions with regular F* libraries, so in
/// addition to ``friend``'ing ``Lib.*``, we also write a couple lemmas that we
/// prove via normalization to facilitate the job of proving that calling the
/// Vale interop signatures faithfully implements the required HACL* signature.
#set-options "--max_fuel 0 --max_ifuel 0 --z3rlimit 300 --z3refresh"
let buffer_is_buffer a len: Lemma
(ensures (lbuffer a len == b:B.buffer a{B.length b == UInt32.v len}))
[ SMTPat (lbuffer a len) ]
=
assert_norm (lbuffer a len == b:B.buffer a{B.length b == UInt32.v len})
let as_nat_is_as_nat (b:lbuffer uint64 4ul) (h:HS.mem): Lemma
(ensures (FA.as_nat b h == F64.as_nat h b))
[ SMTPat (as_nat h b) ]
=
()
let _: squash (Vale.Curve25519.Fast_defs.prime = Spec.Curve25519.prime) =
assert_norm (Vale.Curve25519.Fast_defs.prime = Spec.Curve25519.prime)
// This one only goes through in a reasonable amount of rlimit thanks to
// ``as_nat_is_as_nat`` and ``buffer_is_buffer`` above.
[@ CInline]
let add_scalar out f1 f2 =
if EverCrypt.TargetConfig.hacl_can_compile_inline_asm then
Vale.Inline.X64.Fadd_inline.add_scalar out f1 f2
else
Vale.Wrapper.X64.Fadd.add_scalar_e out f1 f2
// Spec discrepancy. Need to call the right lemma from FStar.Math.Lemmas.
#push-options "--max_fuel 0 --max_ifuel 0 --z3rlimit 400"
[@ CInline]
let fadd out f1 f2 =
let h0 = ST.get () in
let aux () : Lemma (P.fadd (F64.fevalh h0 f1) (F64.fevalh h0 f2) == (FA.as_nat f1 h0 + FA.as_nat f2 h0) % Vale.Curve25519.Fast_defs.prime) =
let a = P.fadd (F64.fevalh h0 f1) (F64.fevalh h0 f2) in
let a1 = (as_nat h0 f1 % Vale.Curve25519.Fast_defs.prime + as_nat h0 f2 % Vale.Curve25519.Fast_defs.prime) % Vale.Curve25519.Fast_defs.prime in
let a2 = (as_nat h0 f1 % Vale.Curve25519.Fast_defs.prime + as_nat h0 f2) % Vale.Curve25519.Fast_defs.prime in
let a3 = (as_nat h0 f1 + as_nat h0 f2) % Vale.Curve25519.Fast_defs.prime in
let b = (FA.as_nat f1 h0 + FA.as_nat f2 h0) % Vale.Curve25519.Fast_defs.prime in
calc (==) {
a;
== { FStar.Math.Lemmas.modulo_distributivity
(as_nat h0 f1) (as_nat h0 f2) Vale.Curve25519.Fast_defs.prime }
a1;
== { FStar.Math.Lemmas.lemma_mod_add_distr (as_nat h0 f1 % Vale.Curve25519.Fast_defs.prime)
(as_nat h0 f2) Vale.Curve25519.Fast_defs.prime }
a2;
== { FStar.Math.Lemmas.lemma_mod_add_distr (as_nat h0 f2) (as_nat h0 f1) Vale.Curve25519.Fast_defs.prime }
a3;
== { }
b;
}
in aux();
if EverCrypt.TargetConfig.hacl_can_compile_inline_asm then
Vale.Inline.X64.Fadd_inline.fadd out f1 f2
else
Vale.Wrapper.X64.Fadd.fadd_e out f1 f2
#pop-options
[@ CInline]
let fsub out f1 f2 =
let h0 = ST.get() in
let aux () : Lemma (P.fsub (F64.fevalh h0 f1) (F64.fevalh h0 f2) == (FA.as_nat f1 h0 - FA.as_nat f2 h0) % Vale.Curve25519.Fast_defs.prime) =
let a = P.fsub (F64.fevalh h0 f1) (F64.fevalh h0 f2) in
let a1 = (as_nat h0 f1 % Vale.Curve25519.Fast_defs.prime - as_nat h0 f2 % Vale.Curve25519.Fast_defs.prime) % Vale.Curve25519.Fast_defs.prime in
let a2 = (as_nat h0 f1 % Vale.Curve25519.Fast_defs.prime - as_nat h0 f2) % Vale.Curve25519.Fast_defs.prime in
let a3 = (as_nat h0 f1 - as_nat h0 f2) % Vale.Curve25519.Fast_defs.prime in
let b = (FA.as_nat f1 h0 - FA.as_nat f2 h0) % Vale.Curve25519.Fast_defs.prime in
calc (==) {
a;
== { }
a1;
== { FStar.Math.Lemmas.lemma_mod_sub_distr (as_nat h0 f1 % Vale.Curve25519.Fast_defs.prime) (as_nat h0 f2)
Vale.Curve25519.Fast_defs.prime }
a2;
== { FStar.Math.Lemmas.lemma_mod_add_distr (- as_nat h0 f2) (as_nat h0 f1) Vale.Curve25519.Fast_defs.prime }
a3;
== { }
b;
}
in aux();
if EverCrypt.TargetConfig.hacl_can_compile_inline_asm then
Vale.Inline.X64.Fadd_inline.fsub out f1 f2
else
Vale.Wrapper.X64.Fsub.fsub_e out f1 f2
#push-options "--z3rlimit 200"
let lemma_fmul_equiv (h0:HS.mem) (f1 f2:F64.u256) : Lemma
(P.fmul (F64.fevalh h0 f1) (F64.fevalh h0 f2) == (FA.as_nat f1 h0 * FA.as_nat f2 h0) % Vale.Curve25519.Fast_defs.prime)
= let a = P.fmul (F64.fevalh h0 f1) (F64.fevalh h0 f2) in
let a1 = ((F64.as_nat h0 f1 % Vale.Curve25519.Fast_defs.prime) * (F64.as_nat h0 f2 % Vale.Curve25519.Fast_defs.prime)) % Vale.Curve25519.Fast_defs.prime in
let a2 = ((F64.as_nat h0 f1 % Vale.Curve25519.Fast_defs.prime) * F64.as_nat h0 f2) % Vale.Curve25519.Fast_defs.prime in
let a3 = (F64.as_nat h0 f1 * F64.as_nat h0 f2) % Vale.Curve25519.Fast_defs.prime in
let b = (FA.as_nat f1 h0 * FA.as_nat f2 h0) % Vale.Curve25519.Fast_defs.prime in
calc (==) {
a;
== { }
a1;
== { FStar.Math.Lemmas.lemma_mod_mul_distr_r (F64.as_nat h0 f1 % Vale.Curve25519.Fast_defs.prime) (F64.as_nat h0 f2) Vale.Curve25519.Fast_defs.prime }
a2;
== { FStar.Math.Lemmas.lemma_mod_mul_distr_l (F64.as_nat h0 f1) (F64.as_nat h0 f2) Vale.Curve25519.Fast_defs.prime }
a3;
== { }
b;
}
#pop-options | false | true | Hacl.Impl.Curve25519.Field64.Vale.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": true,
"z3rlimit": 300,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val fmul: fmul_t M64 p | [] | Hacl.Impl.Curve25519.Field64.Vale.fmul | {
"file_name": "code/curve25519/Hacl.Impl.Curve25519.Field64.Vale.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | Hacl.Impl.Curve25519.Fields.Core.fmul_t Hacl.Impl.Curve25519.Fields.Core.M64
Hacl.Impl.Curve25519.Field64.Vale.p | {
"end_col": 60,
"end_line": 145,
"start_col": 24,
"start_line": 137
} |
Prims.Tot | val fmul_scalar: fmul1_t M64 p | [
{
"abbrev": true,
"full_module": "Hacl.Impl.Curve25519.Field64",
"short_module": "F64"
},
{
"abbrev": true,
"full_module": "Vale.Wrapper.X64.Fadd",
"short_module": "FA"
},
{
"abbrev": true,
"full_module": "Spec.Curve25519",
"short_module": "P"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.Curve25519.Field64.Definition",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "Lib.Buffer",
"short_module": "B"
},
{
"abbrev": false,
"full_module": "Lib.Buffer",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Sequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.All",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Calc",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": false,
"full_module": "Hacl.Impl.Curve25519.Fields.Core",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl.Curve25519.Field64",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl.Curve25519.Field64",
"short_module": null
},
{
"abbrev": 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 fmul_scalar out f1 f2 =
let h0 = ST.get() in
let aux () : Lemma (P.fmul (F64.fevalh h0 f1) (v f2) == (FA.as_nat f1 h0 * v f2) % Vale.Curve25519.Fast_defs.prime) =
let a = P.fmul (F64.fevalh h0 f1) (v f2) in
let a1 = ((F64.as_nat h0 f1 % Vale.Curve25519.Fast_defs.prime) * v f2) % Vale.Curve25519.Fast_defs.prime in
let a2 = (F64.as_nat h0 f1 * v f2) % Vale.Curve25519.Fast_defs.prime in
let b = (FA.as_nat f1 h0 * v f2) % Vale.Curve25519.Fast_defs.prime in
calc (==) {
a;
== { }
a1;
== { FStar.Math.Lemmas.lemma_mod_mul_distr_l (F64.as_nat h0 f1) (v f2) Vale.Curve25519.Fast_defs.prime }
a2;
== { }
b;
}
in aux();
assert_norm (pow2 17 = 131072);
if EverCrypt.TargetConfig.hacl_can_compile_inline_asm then
Vale.Inline.X64.Fmul_inline.fmul_scalar out f1 f2
else
Vale.Wrapper.X64.Fmul.fmul_scalar_e out f1 f2 | val fmul_scalar: fmul1_t M64 p
let fmul_scalar out f1 f2 = | false | null | false | let h0 = ST.get () in
let aux ()
: Lemma
(P.fmul (F64.fevalh h0 f1) (v f2) == (FA.as_nat f1 h0 * v f2) % Vale.Curve25519.Fast_defs.prime)
=
let a = P.fmul (F64.fevalh h0 f1) (v f2) in
let a1 =
((F64.as_nat h0 f1 % Vale.Curve25519.Fast_defs.prime) * v f2) % Vale.Curve25519.Fast_defs.prime
in
let a2 = (F64.as_nat h0 f1 * v f2) % Vale.Curve25519.Fast_defs.prime in
let b = (FA.as_nat f1 h0 * v f2) % Vale.Curve25519.Fast_defs.prime in
calc ( == ) {
a;
( == ) { () }
a1;
( == ) { FStar.Math.Lemmas.lemma_mod_mul_distr_l (F64.as_nat h0 f1)
(v f2)
Vale.Curve25519.Fast_defs.prime }
a2;
( == ) { () }
b;
}
in
aux ();
assert_norm (pow2 17 = 131072);
if EverCrypt.TargetConfig.hacl_can_compile_inline_asm
then Vale.Inline.X64.Fmul_inline.fmul_scalar out f1 f2
else Vale.Wrapper.X64.Fmul.fmul_scalar_e out f1 f2 | {
"checked_file": "Hacl.Impl.Curve25519.Field64.Vale.fst.checked",
"dependencies": [
"Vale.Wrapper.X64.Fswap.fsti.checked",
"Vale.Wrapper.X64.Fsub.fsti.checked",
"Vale.Wrapper.X64.Fsqr.fsti.checked",
"Vale.Wrapper.X64.Fmul.fsti.checked",
"Vale.Wrapper.X64.Fadd.fsti.checked",
"Vale.Inline.X64.Fswap_inline.fsti.checked",
"Vale.Inline.X64.Fsqr_inline.fsti.checked",
"Vale.Inline.X64.Fmul_inline.fsti.checked",
"Vale.Inline.X64.Fadd_inline.fsti.checked",
"Vale.Curve25519.Fast_defs.fst.checked",
"Spec.Curve25519.fst.checked",
"prims.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.IntTypes.fst.checked",
"Lib.Buffer.fst.checked",
"Hacl.Spec.Curve25519.Field64.Definition.fst.checked",
"Hacl.Impl.Curve25519.Field64.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.All.fst.checked",
"FStar.HyperStack.fst.checked",
"FStar.Classical.fsti.checked",
"FStar.Calc.fsti.checked",
"EverCrypt.TargetConfig.fsti.checked"
],
"interface_file": true,
"source_file": "Hacl.Impl.Curve25519.Field64.Vale.fst"
} | [
"total"
] | [
"Hacl.Impl.Curve25519.Fields.Core.felem",
"Hacl.Impl.Curve25519.Fields.Core.M64",
"Lib.IntTypes.uint64",
"EverCrypt.TargetConfig.hacl_can_compile_inline_asm",
"Vale.Inline.X64.Fmul_inline.fmul_scalar",
"Prims.unit",
"Prims.bool",
"Vale.Wrapper.X64.Fmul.fmul_scalar_e",
"FStar.Pervasives.assert_norm",
"Prims.b2t",
"Prims.op_Equality",
"Prims.int",
"Prims.pow2",
"Prims.l_True",
"Prims.squash",
"Prims.eq2",
"Spec.Curve25519.fmul",
"Hacl.Impl.Curve25519.Field64.fevalh",
"Lib.IntTypes.v",
"Lib.IntTypes.U64",
"Lib.IntTypes.SEC",
"Prims.op_Modulus",
"Prims.op_Multiply",
"Vale.Wrapper.X64.Fadd.as_nat",
"Prims.Nil",
"FStar.Pervasives.pattern",
"FStar.Calc.calc_finish",
"Spec.Curve25519.elem",
"Prims.Cons",
"FStar.Preorder.relation",
"FStar.Calc.calc_step",
"FStar.Calc.calc_init",
"FStar.Calc.calc_pack",
"FStar.Math.Lemmas.lemma_mod_mul_distr_l",
"Hacl.Impl.Curve25519.Field64.as_nat",
"Vale.Curve25519.Fast_defs.prime",
"FStar.Mul.op_Star",
"FStar.Monotonic.HyperStack.mem",
"FStar.HyperStack.ST.get"
] | [] | module Hacl.Impl.Curve25519.Field64.Vale
module HS = FStar.HyperStack
module ST = FStar.HyperStack.ST
open FStar.Calc
friend Lib.Buffer
friend Lib.IntTypes
open FStar.HyperStack
open FStar.HyperStack.All
open FStar.Mul
open Lib.Sequence
open Lib.IntTypes
open Lib.Buffer
module B = Lib.Buffer
module S = Hacl.Spec.Curve25519.Field64.Definition
module P = Spec.Curve25519
module FA = Vale.Wrapper.X64.Fadd
module F64 = Hacl.Impl.Curve25519.Field64
/// We are trying to connect HACL* abstractions with regular F* libraries, so in
/// addition to ``friend``'ing ``Lib.*``, we also write a couple lemmas that we
/// prove via normalization to facilitate the job of proving that calling the
/// Vale interop signatures faithfully implements the required HACL* signature.
#set-options "--max_fuel 0 --max_ifuel 0 --z3rlimit 300 --z3refresh"
let buffer_is_buffer a len: Lemma
(ensures (lbuffer a len == b:B.buffer a{B.length b == UInt32.v len}))
[ SMTPat (lbuffer a len) ]
=
assert_norm (lbuffer a len == b:B.buffer a{B.length b == UInt32.v len})
let as_nat_is_as_nat (b:lbuffer uint64 4ul) (h:HS.mem): Lemma
(ensures (FA.as_nat b h == F64.as_nat h b))
[ SMTPat (as_nat h b) ]
=
()
let _: squash (Vale.Curve25519.Fast_defs.prime = Spec.Curve25519.prime) =
assert_norm (Vale.Curve25519.Fast_defs.prime = Spec.Curve25519.prime)
// This one only goes through in a reasonable amount of rlimit thanks to
// ``as_nat_is_as_nat`` and ``buffer_is_buffer`` above.
[@ CInline]
let add_scalar out f1 f2 =
if EverCrypt.TargetConfig.hacl_can_compile_inline_asm then
Vale.Inline.X64.Fadd_inline.add_scalar out f1 f2
else
Vale.Wrapper.X64.Fadd.add_scalar_e out f1 f2
// Spec discrepancy. Need to call the right lemma from FStar.Math.Lemmas.
#push-options "--max_fuel 0 --max_ifuel 0 --z3rlimit 400"
[@ CInline]
let fadd out f1 f2 =
let h0 = ST.get () in
let aux () : Lemma (P.fadd (F64.fevalh h0 f1) (F64.fevalh h0 f2) == (FA.as_nat f1 h0 + FA.as_nat f2 h0) % Vale.Curve25519.Fast_defs.prime) =
let a = P.fadd (F64.fevalh h0 f1) (F64.fevalh h0 f2) in
let a1 = (as_nat h0 f1 % Vale.Curve25519.Fast_defs.prime + as_nat h0 f2 % Vale.Curve25519.Fast_defs.prime) % Vale.Curve25519.Fast_defs.prime in
let a2 = (as_nat h0 f1 % Vale.Curve25519.Fast_defs.prime + as_nat h0 f2) % Vale.Curve25519.Fast_defs.prime in
let a3 = (as_nat h0 f1 + as_nat h0 f2) % Vale.Curve25519.Fast_defs.prime in
let b = (FA.as_nat f1 h0 + FA.as_nat f2 h0) % Vale.Curve25519.Fast_defs.prime in
calc (==) {
a;
== { FStar.Math.Lemmas.modulo_distributivity
(as_nat h0 f1) (as_nat h0 f2) Vale.Curve25519.Fast_defs.prime }
a1;
== { FStar.Math.Lemmas.lemma_mod_add_distr (as_nat h0 f1 % Vale.Curve25519.Fast_defs.prime)
(as_nat h0 f2) Vale.Curve25519.Fast_defs.prime }
a2;
== { FStar.Math.Lemmas.lemma_mod_add_distr (as_nat h0 f2) (as_nat h0 f1) Vale.Curve25519.Fast_defs.prime }
a3;
== { }
b;
}
in aux();
if EverCrypt.TargetConfig.hacl_can_compile_inline_asm then
Vale.Inline.X64.Fadd_inline.fadd out f1 f2
else
Vale.Wrapper.X64.Fadd.fadd_e out f1 f2
#pop-options
[@ CInline]
let fsub out f1 f2 =
let h0 = ST.get() in
let aux () : Lemma (P.fsub (F64.fevalh h0 f1) (F64.fevalh h0 f2) == (FA.as_nat f1 h0 - FA.as_nat f2 h0) % Vale.Curve25519.Fast_defs.prime) =
let a = P.fsub (F64.fevalh h0 f1) (F64.fevalh h0 f2) in
let a1 = (as_nat h0 f1 % Vale.Curve25519.Fast_defs.prime - as_nat h0 f2 % Vale.Curve25519.Fast_defs.prime) % Vale.Curve25519.Fast_defs.prime in
let a2 = (as_nat h0 f1 % Vale.Curve25519.Fast_defs.prime - as_nat h0 f2) % Vale.Curve25519.Fast_defs.prime in
let a3 = (as_nat h0 f1 - as_nat h0 f2) % Vale.Curve25519.Fast_defs.prime in
let b = (FA.as_nat f1 h0 - FA.as_nat f2 h0) % Vale.Curve25519.Fast_defs.prime in
calc (==) {
a;
== { }
a1;
== { FStar.Math.Lemmas.lemma_mod_sub_distr (as_nat h0 f1 % Vale.Curve25519.Fast_defs.prime) (as_nat h0 f2)
Vale.Curve25519.Fast_defs.prime }
a2;
== { FStar.Math.Lemmas.lemma_mod_add_distr (- as_nat h0 f2) (as_nat h0 f1) Vale.Curve25519.Fast_defs.prime }
a3;
== { }
b;
}
in aux();
if EverCrypt.TargetConfig.hacl_can_compile_inline_asm then
Vale.Inline.X64.Fadd_inline.fsub out f1 f2
else
Vale.Wrapper.X64.Fsub.fsub_e out f1 f2
#push-options "--z3rlimit 200"
let lemma_fmul_equiv (h0:HS.mem) (f1 f2:F64.u256) : Lemma
(P.fmul (F64.fevalh h0 f1) (F64.fevalh h0 f2) == (FA.as_nat f1 h0 * FA.as_nat f2 h0) % Vale.Curve25519.Fast_defs.prime)
= let a = P.fmul (F64.fevalh h0 f1) (F64.fevalh h0 f2) in
let a1 = ((F64.as_nat h0 f1 % Vale.Curve25519.Fast_defs.prime) * (F64.as_nat h0 f2 % Vale.Curve25519.Fast_defs.prime)) % Vale.Curve25519.Fast_defs.prime in
let a2 = ((F64.as_nat h0 f1 % Vale.Curve25519.Fast_defs.prime) * F64.as_nat h0 f2) % Vale.Curve25519.Fast_defs.prime in
let a3 = (F64.as_nat h0 f1 * F64.as_nat h0 f2) % Vale.Curve25519.Fast_defs.prime in
let b = (FA.as_nat f1 h0 * FA.as_nat f2 h0) % Vale.Curve25519.Fast_defs.prime in
calc (==) {
a;
== { }
a1;
== { FStar.Math.Lemmas.lemma_mod_mul_distr_r (F64.as_nat h0 f1 % Vale.Curve25519.Fast_defs.prime) (F64.as_nat h0 f2) Vale.Curve25519.Fast_defs.prime }
a2;
== { FStar.Math.Lemmas.lemma_mod_mul_distr_l (F64.as_nat h0 f1) (F64.as_nat h0 f2) Vale.Curve25519.Fast_defs.prime }
a3;
== { }
b;
}
#pop-options
[@ CInline]
let fmul out f1 f2 tmp =
let h0 = ST.get() in
lemma_fmul_equiv h0 f1 f2;
if EverCrypt.TargetConfig.hacl_can_compile_inline_asm then (
assert (disjoint f1 (gsub tmp 0ul 8ul));
assert (disjoint f2 (gsub tmp 0ul 8ul));
Vale.Inline.X64.Fmul_inline.fmul out f1 f2 (sub tmp 0ul 8ul)
) else
Vale.Wrapper.X64.Fmul.fmul_e (sub tmp 0ul 8ul) f1 out f2
#push-options "--z3rlimit 500"
[@ CInline]
let fmul2 out f1 f2 tmp =
let h0 = ST.get() in
lemma_fmul_equiv h0 (gsub f1 0ul 4ul) (gsub f2 0ul 4ul);
lemma_fmul_equiv h0 (gsub f1 4ul 4ul) (gsub f2 4ul 4ul);
if EverCrypt.TargetConfig.hacl_can_compile_inline_asm then
Vale.Inline.X64.Fmul_inline.fmul2 out f1 f2 tmp
else
Vale.Wrapper.X64.Fmul.fmul2_e tmp f1 out f2
#pop-options | false | true | Hacl.Impl.Curve25519.Field64.Vale.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": true,
"z3rlimit": 300,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val fmul_scalar: fmul1_t M64 p | [] | Hacl.Impl.Curve25519.Field64.Vale.fmul_scalar | {
"file_name": "code/curve25519/Hacl.Impl.Curve25519.Field64.Vale.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | Hacl.Impl.Curve25519.Fields.Core.fmul1_t Hacl.Impl.Curve25519.Fields.Core.M64
Hacl.Impl.Curve25519.Field64.Vale.p | {
"end_col": 49,
"end_line": 181,
"start_col": 27,
"start_line": 160
} |
Prims.Tot | val fsqr: fsqr_t M64 p | [
{
"abbrev": true,
"full_module": "Hacl.Impl.Curve25519.Field64",
"short_module": "F64"
},
{
"abbrev": true,
"full_module": "Vale.Wrapper.X64.Fadd",
"short_module": "FA"
},
{
"abbrev": true,
"full_module": "Spec.Curve25519",
"short_module": "P"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.Curve25519.Field64.Definition",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "Lib.Buffer",
"short_module": "B"
},
{
"abbrev": false,
"full_module": "Lib.Buffer",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Sequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.All",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Calc",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": false,
"full_module": "Hacl.Impl.Curve25519.Fields.Core",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl.Curve25519.Field64",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl.Curve25519.Field64",
"short_module": null
},
{
"abbrev": 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 fsqr out f1 tmp =
let h0 = ST.get() in
lemma_fmul_equiv h0 f1 f1;
if EverCrypt.TargetConfig.hacl_can_compile_inline_asm then
Vale.Inline.X64.Fsqr_inline.fsqr out f1 tmp
else
Vale.Wrapper.X64.Fsqr.fsqr_e tmp f1 out | val fsqr: fsqr_t M64 p
let fsqr out f1 tmp = | false | null | false | let h0 = ST.get () in
lemma_fmul_equiv h0 f1 f1;
if EverCrypt.TargetConfig.hacl_can_compile_inline_asm
then Vale.Inline.X64.Fsqr_inline.fsqr out f1 tmp
else Vale.Wrapper.X64.Fsqr.fsqr_e tmp f1 out | {
"checked_file": "Hacl.Impl.Curve25519.Field64.Vale.fst.checked",
"dependencies": [
"Vale.Wrapper.X64.Fswap.fsti.checked",
"Vale.Wrapper.X64.Fsub.fsti.checked",
"Vale.Wrapper.X64.Fsqr.fsti.checked",
"Vale.Wrapper.X64.Fmul.fsti.checked",
"Vale.Wrapper.X64.Fadd.fsti.checked",
"Vale.Inline.X64.Fswap_inline.fsti.checked",
"Vale.Inline.X64.Fsqr_inline.fsti.checked",
"Vale.Inline.X64.Fmul_inline.fsti.checked",
"Vale.Inline.X64.Fadd_inline.fsti.checked",
"Vale.Curve25519.Fast_defs.fst.checked",
"Spec.Curve25519.fst.checked",
"prims.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.IntTypes.fst.checked",
"Lib.Buffer.fst.checked",
"Hacl.Spec.Curve25519.Field64.Definition.fst.checked",
"Hacl.Impl.Curve25519.Field64.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.All.fst.checked",
"FStar.HyperStack.fst.checked",
"FStar.Classical.fsti.checked",
"FStar.Calc.fsti.checked",
"EverCrypt.TargetConfig.fsti.checked"
],
"interface_file": true,
"source_file": "Hacl.Impl.Curve25519.Field64.Vale.fst"
} | [
"total"
] | [
"Hacl.Impl.Curve25519.Fields.Core.felem",
"Hacl.Impl.Curve25519.Fields.Core.M64",
"Hacl.Impl.Curve25519.Fields.Core.felem_wide",
"EverCrypt.TargetConfig.hacl_can_compile_inline_asm",
"Vale.Inline.X64.Fsqr_inline.fsqr",
"Prims.unit",
"Prims.bool",
"Vale.Wrapper.X64.Fsqr.fsqr_e",
"Hacl.Impl.Curve25519.Field64.Vale.lemma_fmul_equiv",
"FStar.Monotonic.HyperStack.mem",
"FStar.HyperStack.ST.get"
] | [] | module Hacl.Impl.Curve25519.Field64.Vale
module HS = FStar.HyperStack
module ST = FStar.HyperStack.ST
open FStar.Calc
friend Lib.Buffer
friend Lib.IntTypes
open FStar.HyperStack
open FStar.HyperStack.All
open FStar.Mul
open Lib.Sequence
open Lib.IntTypes
open Lib.Buffer
module B = Lib.Buffer
module S = Hacl.Spec.Curve25519.Field64.Definition
module P = Spec.Curve25519
module FA = Vale.Wrapper.X64.Fadd
module F64 = Hacl.Impl.Curve25519.Field64
/// We are trying to connect HACL* abstractions with regular F* libraries, so in
/// addition to ``friend``'ing ``Lib.*``, we also write a couple lemmas that we
/// prove via normalization to facilitate the job of proving that calling the
/// Vale interop signatures faithfully implements the required HACL* signature.
#set-options "--max_fuel 0 --max_ifuel 0 --z3rlimit 300 --z3refresh"
let buffer_is_buffer a len: Lemma
(ensures (lbuffer a len == b:B.buffer a{B.length b == UInt32.v len}))
[ SMTPat (lbuffer a len) ]
=
assert_norm (lbuffer a len == b:B.buffer a{B.length b == UInt32.v len})
let as_nat_is_as_nat (b:lbuffer uint64 4ul) (h:HS.mem): Lemma
(ensures (FA.as_nat b h == F64.as_nat h b))
[ SMTPat (as_nat h b) ]
=
()
let _: squash (Vale.Curve25519.Fast_defs.prime = Spec.Curve25519.prime) =
assert_norm (Vale.Curve25519.Fast_defs.prime = Spec.Curve25519.prime)
// This one only goes through in a reasonable amount of rlimit thanks to
// ``as_nat_is_as_nat`` and ``buffer_is_buffer`` above.
[@ CInline]
let add_scalar out f1 f2 =
if EverCrypt.TargetConfig.hacl_can_compile_inline_asm then
Vale.Inline.X64.Fadd_inline.add_scalar out f1 f2
else
Vale.Wrapper.X64.Fadd.add_scalar_e out f1 f2
// Spec discrepancy. Need to call the right lemma from FStar.Math.Lemmas.
#push-options "--max_fuel 0 --max_ifuel 0 --z3rlimit 400"
[@ CInline]
let fadd out f1 f2 =
let h0 = ST.get () in
let aux () : Lemma (P.fadd (F64.fevalh h0 f1) (F64.fevalh h0 f2) == (FA.as_nat f1 h0 + FA.as_nat f2 h0) % Vale.Curve25519.Fast_defs.prime) =
let a = P.fadd (F64.fevalh h0 f1) (F64.fevalh h0 f2) in
let a1 = (as_nat h0 f1 % Vale.Curve25519.Fast_defs.prime + as_nat h0 f2 % Vale.Curve25519.Fast_defs.prime) % Vale.Curve25519.Fast_defs.prime in
let a2 = (as_nat h0 f1 % Vale.Curve25519.Fast_defs.prime + as_nat h0 f2) % Vale.Curve25519.Fast_defs.prime in
let a3 = (as_nat h0 f1 + as_nat h0 f2) % Vale.Curve25519.Fast_defs.prime in
let b = (FA.as_nat f1 h0 + FA.as_nat f2 h0) % Vale.Curve25519.Fast_defs.prime in
calc (==) {
a;
== { FStar.Math.Lemmas.modulo_distributivity
(as_nat h0 f1) (as_nat h0 f2) Vale.Curve25519.Fast_defs.prime }
a1;
== { FStar.Math.Lemmas.lemma_mod_add_distr (as_nat h0 f1 % Vale.Curve25519.Fast_defs.prime)
(as_nat h0 f2) Vale.Curve25519.Fast_defs.prime }
a2;
== { FStar.Math.Lemmas.lemma_mod_add_distr (as_nat h0 f2) (as_nat h0 f1) Vale.Curve25519.Fast_defs.prime }
a3;
== { }
b;
}
in aux();
if EverCrypt.TargetConfig.hacl_can_compile_inline_asm then
Vale.Inline.X64.Fadd_inline.fadd out f1 f2
else
Vale.Wrapper.X64.Fadd.fadd_e out f1 f2
#pop-options
[@ CInline]
let fsub out f1 f2 =
let h0 = ST.get() in
let aux () : Lemma (P.fsub (F64.fevalh h0 f1) (F64.fevalh h0 f2) == (FA.as_nat f1 h0 - FA.as_nat f2 h0) % Vale.Curve25519.Fast_defs.prime) =
let a = P.fsub (F64.fevalh h0 f1) (F64.fevalh h0 f2) in
let a1 = (as_nat h0 f1 % Vale.Curve25519.Fast_defs.prime - as_nat h0 f2 % Vale.Curve25519.Fast_defs.prime) % Vale.Curve25519.Fast_defs.prime in
let a2 = (as_nat h0 f1 % Vale.Curve25519.Fast_defs.prime - as_nat h0 f2) % Vale.Curve25519.Fast_defs.prime in
let a3 = (as_nat h0 f1 - as_nat h0 f2) % Vale.Curve25519.Fast_defs.prime in
let b = (FA.as_nat f1 h0 - FA.as_nat f2 h0) % Vale.Curve25519.Fast_defs.prime in
calc (==) {
a;
== { }
a1;
== { FStar.Math.Lemmas.lemma_mod_sub_distr (as_nat h0 f1 % Vale.Curve25519.Fast_defs.prime) (as_nat h0 f2)
Vale.Curve25519.Fast_defs.prime }
a2;
== { FStar.Math.Lemmas.lemma_mod_add_distr (- as_nat h0 f2) (as_nat h0 f1) Vale.Curve25519.Fast_defs.prime }
a3;
== { }
b;
}
in aux();
if EverCrypt.TargetConfig.hacl_can_compile_inline_asm then
Vale.Inline.X64.Fadd_inline.fsub out f1 f2
else
Vale.Wrapper.X64.Fsub.fsub_e out f1 f2
#push-options "--z3rlimit 200"
let lemma_fmul_equiv (h0:HS.mem) (f1 f2:F64.u256) : Lemma
(P.fmul (F64.fevalh h0 f1) (F64.fevalh h0 f2) == (FA.as_nat f1 h0 * FA.as_nat f2 h0) % Vale.Curve25519.Fast_defs.prime)
= let a = P.fmul (F64.fevalh h0 f1) (F64.fevalh h0 f2) in
let a1 = ((F64.as_nat h0 f1 % Vale.Curve25519.Fast_defs.prime) * (F64.as_nat h0 f2 % Vale.Curve25519.Fast_defs.prime)) % Vale.Curve25519.Fast_defs.prime in
let a2 = ((F64.as_nat h0 f1 % Vale.Curve25519.Fast_defs.prime) * F64.as_nat h0 f2) % Vale.Curve25519.Fast_defs.prime in
let a3 = (F64.as_nat h0 f1 * F64.as_nat h0 f2) % Vale.Curve25519.Fast_defs.prime in
let b = (FA.as_nat f1 h0 * FA.as_nat f2 h0) % Vale.Curve25519.Fast_defs.prime in
calc (==) {
a;
== { }
a1;
== { FStar.Math.Lemmas.lemma_mod_mul_distr_r (F64.as_nat h0 f1 % Vale.Curve25519.Fast_defs.prime) (F64.as_nat h0 f2) Vale.Curve25519.Fast_defs.prime }
a2;
== { FStar.Math.Lemmas.lemma_mod_mul_distr_l (F64.as_nat h0 f1) (F64.as_nat h0 f2) Vale.Curve25519.Fast_defs.prime }
a3;
== { }
b;
}
#pop-options
[@ CInline]
let fmul out f1 f2 tmp =
let h0 = ST.get() in
lemma_fmul_equiv h0 f1 f2;
if EverCrypt.TargetConfig.hacl_can_compile_inline_asm then (
assert (disjoint f1 (gsub tmp 0ul 8ul));
assert (disjoint f2 (gsub tmp 0ul 8ul));
Vale.Inline.X64.Fmul_inline.fmul out f1 f2 (sub tmp 0ul 8ul)
) else
Vale.Wrapper.X64.Fmul.fmul_e (sub tmp 0ul 8ul) f1 out f2
#push-options "--z3rlimit 500"
[@ CInline]
let fmul2 out f1 f2 tmp =
let h0 = ST.get() in
lemma_fmul_equiv h0 (gsub f1 0ul 4ul) (gsub f2 0ul 4ul);
lemma_fmul_equiv h0 (gsub f1 4ul 4ul) (gsub f2 4ul 4ul);
if EverCrypt.TargetConfig.hacl_can_compile_inline_asm then
Vale.Inline.X64.Fmul_inline.fmul2 out f1 f2 tmp
else
Vale.Wrapper.X64.Fmul.fmul2_e tmp f1 out f2
#pop-options
[@ CInline]
let fmul_scalar out f1 f2 =
let h0 = ST.get() in
let aux () : Lemma (P.fmul (F64.fevalh h0 f1) (v f2) == (FA.as_nat f1 h0 * v f2) % Vale.Curve25519.Fast_defs.prime) =
let a = P.fmul (F64.fevalh h0 f1) (v f2) in
let a1 = ((F64.as_nat h0 f1 % Vale.Curve25519.Fast_defs.prime) * v f2) % Vale.Curve25519.Fast_defs.prime in
let a2 = (F64.as_nat h0 f1 * v f2) % Vale.Curve25519.Fast_defs.prime in
let b = (FA.as_nat f1 h0 * v f2) % Vale.Curve25519.Fast_defs.prime in
calc (==) {
a;
== { }
a1;
== { FStar.Math.Lemmas.lemma_mod_mul_distr_l (F64.as_nat h0 f1) (v f2) Vale.Curve25519.Fast_defs.prime }
a2;
== { }
b;
}
in aux();
assert_norm (pow2 17 = 131072);
if EverCrypt.TargetConfig.hacl_can_compile_inline_asm then
Vale.Inline.X64.Fmul_inline.fmul_scalar out f1 f2
else
Vale.Wrapper.X64.Fmul.fmul_scalar_e out f1 f2 | false | true | Hacl.Impl.Curve25519.Field64.Vale.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": true,
"z3rlimit": 300,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val fsqr: fsqr_t M64 p | [] | Hacl.Impl.Curve25519.Field64.Vale.fsqr | {
"file_name": "code/curve25519/Hacl.Impl.Curve25519.Field64.Vale.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | Hacl.Impl.Curve25519.Fields.Core.fsqr_t Hacl.Impl.Curve25519.Fields.Core.M64
Hacl.Impl.Curve25519.Field64.Vale.p | {
"end_col": 43,
"end_line": 190,
"start_col": 21,
"start_line": 184
} |
FStar.Pervasives.Lemma | val buffer_is_buffer (a len: _)
: Lemma (ensures (lbuffer a len == b: B.buffer a {B.length b == UInt32.v len}))
[SMTPat (lbuffer a len)] | [
{
"abbrev": true,
"full_module": "Hacl.Impl.Curve25519.Field64",
"short_module": "F64"
},
{
"abbrev": true,
"full_module": "Vale.Wrapper.X64.Fadd",
"short_module": "FA"
},
{
"abbrev": true,
"full_module": "Spec.Curve25519",
"short_module": "P"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.Curve25519.Field64.Definition",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "Lib.Buffer",
"short_module": "B"
},
{
"abbrev": false,
"full_module": "Lib.Buffer",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Sequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.All",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Calc",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": false,
"full_module": "Hacl.Impl.Curve25519.Fields.Core",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl.Curve25519.Field64",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl.Curve25519.Field64",
"short_module": null
},
{
"abbrev": 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 buffer_is_buffer a len: Lemma
(ensures (lbuffer a len == b:B.buffer a{B.length b == UInt32.v len}))
[ SMTPat (lbuffer a len) ]
=
assert_norm (lbuffer a len == b:B.buffer a{B.length b == UInt32.v len}) | val buffer_is_buffer (a len: _)
: Lemma (ensures (lbuffer a len == b: B.buffer a {B.length b == UInt32.v len}))
[SMTPat (lbuffer a len)]
let buffer_is_buffer a len
: Lemma (ensures (lbuffer a len == b: B.buffer a {B.length b == UInt32.v len}))
[SMTPat (lbuffer a len)] = | false | null | true | assert_norm (lbuffer a len == b: B.buffer a {B.length b == UInt32.v len}) | {
"checked_file": "Hacl.Impl.Curve25519.Field64.Vale.fst.checked",
"dependencies": [
"Vale.Wrapper.X64.Fswap.fsti.checked",
"Vale.Wrapper.X64.Fsub.fsti.checked",
"Vale.Wrapper.X64.Fsqr.fsti.checked",
"Vale.Wrapper.X64.Fmul.fsti.checked",
"Vale.Wrapper.X64.Fadd.fsti.checked",
"Vale.Inline.X64.Fswap_inline.fsti.checked",
"Vale.Inline.X64.Fsqr_inline.fsti.checked",
"Vale.Inline.X64.Fmul_inline.fsti.checked",
"Vale.Inline.X64.Fadd_inline.fsti.checked",
"Vale.Curve25519.Fast_defs.fst.checked",
"Spec.Curve25519.fst.checked",
"prims.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.IntTypes.fst.checked",
"Lib.Buffer.fst.checked",
"Hacl.Spec.Curve25519.Field64.Definition.fst.checked",
"Hacl.Impl.Curve25519.Field64.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.All.fst.checked",
"FStar.HyperStack.fst.checked",
"FStar.Classical.fsti.checked",
"FStar.Calc.fsti.checked",
"EverCrypt.TargetConfig.fsti.checked"
],
"interface_file": true,
"source_file": "Hacl.Impl.Curve25519.Field64.Vale.fst"
} | [
"lemma"
] | [
"FStar.UInt32.t",
"FStar.Pervasives.assert_norm",
"Prims.eq2",
"Lib.Buffer.lbuffer",
"Lib.Buffer.buffer",
"Prims.int",
"Prims.l_or",
"Prims.b2t",
"Prims.op_GreaterThanOrEqual",
"FStar.UInt.size",
"FStar.UInt32.n",
"Lib.Buffer.length",
"Lib.Buffer.MUT",
"FStar.UInt32.v",
"Prims.unit",
"Prims.l_True",
"Prims.squash",
"Prims.Cons",
"FStar.Pervasives.pattern",
"FStar.Pervasives.smt_pat",
"Prims.Nil"
] | [] | module Hacl.Impl.Curve25519.Field64.Vale
module HS = FStar.HyperStack
module ST = FStar.HyperStack.ST
open FStar.Calc
friend Lib.Buffer
friend Lib.IntTypes
open FStar.HyperStack
open FStar.HyperStack.All
open FStar.Mul
open Lib.Sequence
open Lib.IntTypes
open Lib.Buffer
module B = Lib.Buffer
module S = Hacl.Spec.Curve25519.Field64.Definition
module P = Spec.Curve25519
module FA = Vale.Wrapper.X64.Fadd
module F64 = Hacl.Impl.Curve25519.Field64
/// We are trying to connect HACL* abstractions with regular F* libraries, so in
/// addition to ``friend``'ing ``Lib.*``, we also write a couple lemmas that we
/// prove via normalization to facilitate the job of proving that calling the
/// Vale interop signatures faithfully implements the required HACL* signature.
#set-options "--max_fuel 0 --max_ifuel 0 --z3rlimit 300 --z3refresh"
let buffer_is_buffer a len: Lemma
(ensures (lbuffer a len == b:B.buffer a{B.length b == UInt32.v len}))
[ SMTPat (lbuffer a len) ] | false | false | Hacl.Impl.Curve25519.Field64.Vale.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": true,
"z3rlimit": 300,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val buffer_is_buffer (a len: _)
: Lemma (ensures (lbuffer a len == b: B.buffer a {B.length b == UInt32.v len}))
[SMTPat (lbuffer a len)] | [] | Hacl.Impl.Curve25519.Field64.Vale.buffer_is_buffer | {
"file_name": "code/curve25519/Hacl.Impl.Curve25519.Field64.Vale.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | a: Type0 -> len: FStar.UInt32.t
-> FStar.Pervasives.Lemma
(ensures
Lib.Buffer.lbuffer a len ==
b:
Lib.Buffer.buffer a {Lib.Buffer.length b == FStar.UInt32.v len})
[SMTPat (Lib.Buffer.lbuffer a len)] | {
"end_col": 73,
"end_line": 37,
"start_col": 2,
"start_line": 37
} |
FStar.Pervasives.Lemma | val lemma_fmul_equiv (h0: HS.mem) (f1 f2: F64.u256)
: Lemma
(P.fmul (F64.fevalh h0 f1) (F64.fevalh h0 f2) ==
(FA.as_nat f1 h0 * FA.as_nat f2 h0) % Vale.Curve25519.Fast_defs.prime) | [
{
"abbrev": true,
"full_module": "Hacl.Impl.Curve25519.Field64",
"short_module": "F64"
},
{
"abbrev": true,
"full_module": "Vale.Wrapper.X64.Fadd",
"short_module": "FA"
},
{
"abbrev": true,
"full_module": "Spec.Curve25519",
"short_module": "P"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.Curve25519.Field64.Definition",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "Lib.Buffer",
"short_module": "B"
},
{
"abbrev": false,
"full_module": "Lib.Buffer",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Sequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.All",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Calc",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": false,
"full_module": "Hacl.Impl.Curve25519.Fields.Core",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl.Curve25519.Field64",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl.Curve25519.Field64",
"short_module": null
},
{
"abbrev": 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_fmul_equiv (h0:HS.mem) (f1 f2:F64.u256) : Lemma
(P.fmul (F64.fevalh h0 f1) (F64.fevalh h0 f2) == (FA.as_nat f1 h0 * FA.as_nat f2 h0) % Vale.Curve25519.Fast_defs.prime)
= let a = P.fmul (F64.fevalh h0 f1) (F64.fevalh h0 f2) in
let a1 = ((F64.as_nat h0 f1 % Vale.Curve25519.Fast_defs.prime) * (F64.as_nat h0 f2 % Vale.Curve25519.Fast_defs.prime)) % Vale.Curve25519.Fast_defs.prime in
let a2 = ((F64.as_nat h0 f1 % Vale.Curve25519.Fast_defs.prime) * F64.as_nat h0 f2) % Vale.Curve25519.Fast_defs.prime in
let a3 = (F64.as_nat h0 f1 * F64.as_nat h0 f2) % Vale.Curve25519.Fast_defs.prime in
let b = (FA.as_nat f1 h0 * FA.as_nat f2 h0) % Vale.Curve25519.Fast_defs.prime in
calc (==) {
a;
== { }
a1;
== { FStar.Math.Lemmas.lemma_mod_mul_distr_r (F64.as_nat h0 f1 % Vale.Curve25519.Fast_defs.prime) (F64.as_nat h0 f2) Vale.Curve25519.Fast_defs.prime }
a2;
== { FStar.Math.Lemmas.lemma_mod_mul_distr_l (F64.as_nat h0 f1) (F64.as_nat h0 f2) Vale.Curve25519.Fast_defs.prime }
a3;
== { }
b;
} | val lemma_fmul_equiv (h0: HS.mem) (f1 f2: F64.u256)
: Lemma
(P.fmul (F64.fevalh h0 f1) (F64.fevalh h0 f2) ==
(FA.as_nat f1 h0 * FA.as_nat f2 h0) % Vale.Curve25519.Fast_defs.prime)
let lemma_fmul_equiv (h0: HS.mem) (f1 f2: F64.u256)
: Lemma
(P.fmul (F64.fevalh h0 f1) (F64.fevalh h0 f2) ==
(FA.as_nat f1 h0 * FA.as_nat f2 h0) % Vale.Curve25519.Fast_defs.prime) = | false | null | true | let a = P.fmul (F64.fevalh h0 f1) (F64.fevalh h0 f2) in
let a1 =
((F64.as_nat h0 f1 % Vale.Curve25519.Fast_defs.prime) *
(F64.as_nat h0 f2 % Vale.Curve25519.Fast_defs.prime)) %
Vale.Curve25519.Fast_defs.prime
in
let a2 =
((F64.as_nat h0 f1 % Vale.Curve25519.Fast_defs.prime) * F64.as_nat h0 f2) %
Vale.Curve25519.Fast_defs.prime
in
let a3 = (F64.as_nat h0 f1 * F64.as_nat h0 f2) % Vale.Curve25519.Fast_defs.prime in
let b = (FA.as_nat f1 h0 * FA.as_nat f2 h0) % Vale.Curve25519.Fast_defs.prime in
calc ( == ) {
a;
( == ) { () }
a1;
( == ) { FStar.Math.Lemmas.lemma_mod_mul_distr_r (F64.as_nat h0 f1 %
Vale.Curve25519.Fast_defs.prime)
(F64.as_nat h0 f2)
Vale.Curve25519.Fast_defs.prime }
a2;
( == ) { FStar.Math.Lemmas.lemma_mod_mul_distr_l (F64.as_nat h0 f1)
(F64.as_nat h0 f2)
Vale.Curve25519.Fast_defs.prime }
a3;
( == ) { () }
b;
} | {
"checked_file": "Hacl.Impl.Curve25519.Field64.Vale.fst.checked",
"dependencies": [
"Vale.Wrapper.X64.Fswap.fsti.checked",
"Vale.Wrapper.X64.Fsub.fsti.checked",
"Vale.Wrapper.X64.Fsqr.fsti.checked",
"Vale.Wrapper.X64.Fmul.fsti.checked",
"Vale.Wrapper.X64.Fadd.fsti.checked",
"Vale.Inline.X64.Fswap_inline.fsti.checked",
"Vale.Inline.X64.Fsqr_inline.fsti.checked",
"Vale.Inline.X64.Fmul_inline.fsti.checked",
"Vale.Inline.X64.Fadd_inline.fsti.checked",
"Vale.Curve25519.Fast_defs.fst.checked",
"Spec.Curve25519.fst.checked",
"prims.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.IntTypes.fst.checked",
"Lib.Buffer.fst.checked",
"Hacl.Spec.Curve25519.Field64.Definition.fst.checked",
"Hacl.Impl.Curve25519.Field64.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.All.fst.checked",
"FStar.HyperStack.fst.checked",
"FStar.Classical.fsti.checked",
"FStar.Calc.fsti.checked",
"EverCrypt.TargetConfig.fsti.checked"
],
"interface_file": true,
"source_file": "Hacl.Impl.Curve25519.Field64.Vale.fst"
} | [
"lemma"
] | [
"FStar.Monotonic.HyperStack.mem",
"Hacl.Impl.Curve25519.Field64.u256",
"FStar.Calc.calc_finish",
"Spec.Curve25519.elem",
"Prims.eq2",
"Prims.Cons",
"FStar.Preorder.relation",
"Prims.Nil",
"Prims.unit",
"FStar.Calc.calc_step",
"FStar.Calc.calc_init",
"FStar.Calc.calc_pack",
"Prims.squash",
"FStar.Math.Lemmas.lemma_mod_mul_distr_r",
"Prims.op_Modulus",
"Hacl.Impl.Curve25519.Field64.as_nat",
"Vale.Curve25519.Fast_defs.prime",
"FStar.Math.Lemmas.lemma_mod_mul_distr_l",
"Prims.int",
"FStar.Mul.op_Star",
"Vale.Wrapper.X64.Fadd.as_nat",
"Spec.Curve25519.fmul",
"Hacl.Impl.Curve25519.Field64.fevalh",
"Prims.l_True",
"FStar.Pervasives.pattern"
] | [] | module Hacl.Impl.Curve25519.Field64.Vale
module HS = FStar.HyperStack
module ST = FStar.HyperStack.ST
open FStar.Calc
friend Lib.Buffer
friend Lib.IntTypes
open FStar.HyperStack
open FStar.HyperStack.All
open FStar.Mul
open Lib.Sequence
open Lib.IntTypes
open Lib.Buffer
module B = Lib.Buffer
module S = Hacl.Spec.Curve25519.Field64.Definition
module P = Spec.Curve25519
module FA = Vale.Wrapper.X64.Fadd
module F64 = Hacl.Impl.Curve25519.Field64
/// We are trying to connect HACL* abstractions with regular F* libraries, so in
/// addition to ``friend``'ing ``Lib.*``, we also write a couple lemmas that we
/// prove via normalization to facilitate the job of proving that calling the
/// Vale interop signatures faithfully implements the required HACL* signature.
#set-options "--max_fuel 0 --max_ifuel 0 --z3rlimit 300 --z3refresh"
let buffer_is_buffer a len: Lemma
(ensures (lbuffer a len == b:B.buffer a{B.length b == UInt32.v len}))
[ SMTPat (lbuffer a len) ]
=
assert_norm (lbuffer a len == b:B.buffer a{B.length b == UInt32.v len})
let as_nat_is_as_nat (b:lbuffer uint64 4ul) (h:HS.mem): Lemma
(ensures (FA.as_nat b h == F64.as_nat h b))
[ SMTPat (as_nat h b) ]
=
()
let _: squash (Vale.Curve25519.Fast_defs.prime = Spec.Curve25519.prime) =
assert_norm (Vale.Curve25519.Fast_defs.prime = Spec.Curve25519.prime)
// This one only goes through in a reasonable amount of rlimit thanks to
// ``as_nat_is_as_nat`` and ``buffer_is_buffer`` above.
[@ CInline]
let add_scalar out f1 f2 =
if EverCrypt.TargetConfig.hacl_can_compile_inline_asm then
Vale.Inline.X64.Fadd_inline.add_scalar out f1 f2
else
Vale.Wrapper.X64.Fadd.add_scalar_e out f1 f2
// Spec discrepancy. Need to call the right lemma from FStar.Math.Lemmas.
#push-options "--max_fuel 0 --max_ifuel 0 --z3rlimit 400"
[@ CInline]
let fadd out f1 f2 =
let h0 = ST.get () in
let aux () : Lemma (P.fadd (F64.fevalh h0 f1) (F64.fevalh h0 f2) == (FA.as_nat f1 h0 + FA.as_nat f2 h0) % Vale.Curve25519.Fast_defs.prime) =
let a = P.fadd (F64.fevalh h0 f1) (F64.fevalh h0 f2) in
let a1 = (as_nat h0 f1 % Vale.Curve25519.Fast_defs.prime + as_nat h0 f2 % Vale.Curve25519.Fast_defs.prime) % Vale.Curve25519.Fast_defs.prime in
let a2 = (as_nat h0 f1 % Vale.Curve25519.Fast_defs.prime + as_nat h0 f2) % Vale.Curve25519.Fast_defs.prime in
let a3 = (as_nat h0 f1 + as_nat h0 f2) % Vale.Curve25519.Fast_defs.prime in
let b = (FA.as_nat f1 h0 + FA.as_nat f2 h0) % Vale.Curve25519.Fast_defs.prime in
calc (==) {
a;
== { FStar.Math.Lemmas.modulo_distributivity
(as_nat h0 f1) (as_nat h0 f2) Vale.Curve25519.Fast_defs.prime }
a1;
== { FStar.Math.Lemmas.lemma_mod_add_distr (as_nat h0 f1 % Vale.Curve25519.Fast_defs.prime)
(as_nat h0 f2) Vale.Curve25519.Fast_defs.prime }
a2;
== { FStar.Math.Lemmas.lemma_mod_add_distr (as_nat h0 f2) (as_nat h0 f1) Vale.Curve25519.Fast_defs.prime }
a3;
== { }
b;
}
in aux();
if EverCrypt.TargetConfig.hacl_can_compile_inline_asm then
Vale.Inline.X64.Fadd_inline.fadd out f1 f2
else
Vale.Wrapper.X64.Fadd.fadd_e out f1 f2
#pop-options
[@ CInline]
let fsub out f1 f2 =
let h0 = ST.get() in
let aux () : Lemma (P.fsub (F64.fevalh h0 f1) (F64.fevalh h0 f2) == (FA.as_nat f1 h0 - FA.as_nat f2 h0) % Vale.Curve25519.Fast_defs.prime) =
let a = P.fsub (F64.fevalh h0 f1) (F64.fevalh h0 f2) in
let a1 = (as_nat h0 f1 % Vale.Curve25519.Fast_defs.prime - as_nat h0 f2 % Vale.Curve25519.Fast_defs.prime) % Vale.Curve25519.Fast_defs.prime in
let a2 = (as_nat h0 f1 % Vale.Curve25519.Fast_defs.prime - as_nat h0 f2) % Vale.Curve25519.Fast_defs.prime in
let a3 = (as_nat h0 f1 - as_nat h0 f2) % Vale.Curve25519.Fast_defs.prime in
let b = (FA.as_nat f1 h0 - FA.as_nat f2 h0) % Vale.Curve25519.Fast_defs.prime in
calc (==) {
a;
== { }
a1;
== { FStar.Math.Lemmas.lemma_mod_sub_distr (as_nat h0 f1 % Vale.Curve25519.Fast_defs.prime) (as_nat h0 f2)
Vale.Curve25519.Fast_defs.prime }
a2;
== { FStar.Math.Lemmas.lemma_mod_add_distr (- as_nat h0 f2) (as_nat h0 f1) Vale.Curve25519.Fast_defs.prime }
a3;
== { }
b;
}
in aux();
if EverCrypt.TargetConfig.hacl_can_compile_inline_asm then
Vale.Inline.X64.Fadd_inline.fsub out f1 f2
else
Vale.Wrapper.X64.Fsub.fsub_e out f1 f2
#push-options "--z3rlimit 200"
let lemma_fmul_equiv (h0:HS.mem) (f1 f2:F64.u256) : Lemma | false | false | Hacl.Impl.Curve25519.Field64.Vale.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": true,
"z3rlimit": 200,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val lemma_fmul_equiv (h0: HS.mem) (f1 f2: F64.u256)
: Lemma
(P.fmul (F64.fevalh h0 f1) (F64.fevalh h0 f2) ==
(FA.as_nat f1 h0 * FA.as_nat f2 h0) % Vale.Curve25519.Fast_defs.prime) | [] | Hacl.Impl.Curve25519.Field64.Vale.lemma_fmul_equiv | {
"file_name": "code/curve25519/Hacl.Impl.Curve25519.Field64.Vale.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} |
h0: FStar.Monotonic.HyperStack.mem ->
f1: Hacl.Impl.Curve25519.Field64.u256 ->
f2: Hacl.Impl.Curve25519.Field64.u256
-> FStar.Pervasives.Lemma
(ensures
Spec.Curve25519.fmul (Hacl.Impl.Curve25519.Field64.fevalh h0 f1)
(Hacl.Impl.Curve25519.Field64.fevalh h0 f2) ==
Vale.Wrapper.X64.Fadd.as_nat f1 h0 * Vale.Wrapper.X64.Fadd.as_nat f2 h0 %
Vale.Curve25519.Fast_defs.prime) | {
"end_col": 5,
"end_line": 133,
"start_col": 3,
"start_line": 118
} |
Prims.Tot | val add_scalar: add1_t p | [
{
"abbrev": true,
"full_module": "Hacl.Impl.Curve25519.Field64",
"short_module": "F64"
},
{
"abbrev": true,
"full_module": "Vale.Wrapper.X64.Fadd",
"short_module": "FA"
},
{
"abbrev": true,
"full_module": "Spec.Curve25519",
"short_module": "P"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.Curve25519.Field64.Definition",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "Lib.Buffer",
"short_module": "B"
},
{
"abbrev": false,
"full_module": "Lib.Buffer",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Sequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.All",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Calc",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": false,
"full_module": "Hacl.Impl.Curve25519.Fields.Core",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl.Curve25519.Field64",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl.Curve25519.Field64",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let add_scalar out f1 f2 =
if EverCrypt.TargetConfig.hacl_can_compile_inline_asm then
Vale.Inline.X64.Fadd_inline.add_scalar out f1 f2
else
Vale.Wrapper.X64.Fadd.add_scalar_e out f1 f2 | val add_scalar: add1_t p
let add_scalar out f1 f2 = | false | null | false | if EverCrypt.TargetConfig.hacl_can_compile_inline_asm
then Vale.Inline.X64.Fadd_inline.add_scalar out f1 f2
else Vale.Wrapper.X64.Fadd.add_scalar_e out f1 f2 | {
"checked_file": "Hacl.Impl.Curve25519.Field64.Vale.fst.checked",
"dependencies": [
"Vale.Wrapper.X64.Fswap.fsti.checked",
"Vale.Wrapper.X64.Fsub.fsti.checked",
"Vale.Wrapper.X64.Fsqr.fsti.checked",
"Vale.Wrapper.X64.Fmul.fsti.checked",
"Vale.Wrapper.X64.Fadd.fsti.checked",
"Vale.Inline.X64.Fswap_inline.fsti.checked",
"Vale.Inline.X64.Fsqr_inline.fsti.checked",
"Vale.Inline.X64.Fmul_inline.fsti.checked",
"Vale.Inline.X64.Fadd_inline.fsti.checked",
"Vale.Curve25519.Fast_defs.fst.checked",
"Spec.Curve25519.fst.checked",
"prims.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.IntTypes.fst.checked",
"Lib.Buffer.fst.checked",
"Hacl.Spec.Curve25519.Field64.Definition.fst.checked",
"Hacl.Impl.Curve25519.Field64.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.All.fst.checked",
"FStar.HyperStack.fst.checked",
"FStar.Classical.fsti.checked",
"FStar.Calc.fsti.checked",
"EverCrypt.TargetConfig.fsti.checked"
],
"interface_file": true,
"source_file": "Hacl.Impl.Curve25519.Field64.Vale.fst"
} | [
"total"
] | [
"Hacl.Impl.Curve25519.Fields.Core.felem",
"Hacl.Impl.Curve25519.Fields.Core.M64",
"Lib.IntTypes.uint64",
"EverCrypt.TargetConfig.hacl_can_compile_inline_asm",
"Vale.Inline.X64.Fadd_inline.add_scalar",
"FStar.Ghost.erased",
"FStar.UInt64.t",
"Prims.bool",
"Vale.Wrapper.X64.Fadd.add_scalar_e"
] | [] | module Hacl.Impl.Curve25519.Field64.Vale
module HS = FStar.HyperStack
module ST = FStar.HyperStack.ST
open FStar.Calc
friend Lib.Buffer
friend Lib.IntTypes
open FStar.HyperStack
open FStar.HyperStack.All
open FStar.Mul
open Lib.Sequence
open Lib.IntTypes
open Lib.Buffer
module B = Lib.Buffer
module S = Hacl.Spec.Curve25519.Field64.Definition
module P = Spec.Curve25519
module FA = Vale.Wrapper.X64.Fadd
module F64 = Hacl.Impl.Curve25519.Field64
/// We are trying to connect HACL* abstractions with regular F* libraries, so in
/// addition to ``friend``'ing ``Lib.*``, we also write a couple lemmas that we
/// prove via normalization to facilitate the job of proving that calling the
/// Vale interop signatures faithfully implements the required HACL* signature.
#set-options "--max_fuel 0 --max_ifuel 0 --z3rlimit 300 --z3refresh"
let buffer_is_buffer a len: Lemma
(ensures (lbuffer a len == b:B.buffer a{B.length b == UInt32.v len}))
[ SMTPat (lbuffer a len) ]
=
assert_norm (lbuffer a len == b:B.buffer a{B.length b == UInt32.v len})
let as_nat_is_as_nat (b:lbuffer uint64 4ul) (h:HS.mem): Lemma
(ensures (FA.as_nat b h == F64.as_nat h b))
[ SMTPat (as_nat h b) ]
=
()
let _: squash (Vale.Curve25519.Fast_defs.prime = Spec.Curve25519.prime) =
assert_norm (Vale.Curve25519.Fast_defs.prime = Spec.Curve25519.prime)
// This one only goes through in a reasonable amount of rlimit thanks to
// ``as_nat_is_as_nat`` and ``buffer_is_buffer`` above.
[@ CInline] | false | true | Hacl.Impl.Curve25519.Field64.Vale.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": true,
"z3rlimit": 300,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val add_scalar: add1_t p | [] | Hacl.Impl.Curve25519.Field64.Vale.add_scalar | {
"file_name": "code/curve25519/Hacl.Impl.Curve25519.Field64.Vale.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | Hacl.Impl.Curve25519.Fields.Core.add1_t Hacl.Impl.Curve25519.Field64.Vale.p | {
"end_col": 48,
"end_line": 55,
"start_col": 2,
"start_line": 52
} |
Prims.Tot | val fadd: fadd_t M64 p | [
{
"abbrev": true,
"full_module": "Hacl.Impl.Curve25519.Field64",
"short_module": "F64"
},
{
"abbrev": true,
"full_module": "Vale.Wrapper.X64.Fadd",
"short_module": "FA"
},
{
"abbrev": true,
"full_module": "Spec.Curve25519",
"short_module": "P"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.Curve25519.Field64.Definition",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "Lib.Buffer",
"short_module": "B"
},
{
"abbrev": false,
"full_module": "Lib.Buffer",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Sequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.All",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Calc",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": false,
"full_module": "Hacl.Impl.Curve25519.Fields.Core",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl.Curve25519.Field64",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl.Curve25519.Field64",
"short_module": null
},
{
"abbrev": 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 fadd out f1 f2 =
let h0 = ST.get () in
let aux () : Lemma (P.fadd (F64.fevalh h0 f1) (F64.fevalh h0 f2) == (FA.as_nat f1 h0 + FA.as_nat f2 h0) % Vale.Curve25519.Fast_defs.prime) =
let a = P.fadd (F64.fevalh h0 f1) (F64.fevalh h0 f2) in
let a1 = (as_nat h0 f1 % Vale.Curve25519.Fast_defs.prime + as_nat h0 f2 % Vale.Curve25519.Fast_defs.prime) % Vale.Curve25519.Fast_defs.prime in
let a2 = (as_nat h0 f1 % Vale.Curve25519.Fast_defs.prime + as_nat h0 f2) % Vale.Curve25519.Fast_defs.prime in
let a3 = (as_nat h0 f1 + as_nat h0 f2) % Vale.Curve25519.Fast_defs.prime in
let b = (FA.as_nat f1 h0 + FA.as_nat f2 h0) % Vale.Curve25519.Fast_defs.prime in
calc (==) {
a;
== { FStar.Math.Lemmas.modulo_distributivity
(as_nat h0 f1) (as_nat h0 f2) Vale.Curve25519.Fast_defs.prime }
a1;
== { FStar.Math.Lemmas.lemma_mod_add_distr (as_nat h0 f1 % Vale.Curve25519.Fast_defs.prime)
(as_nat h0 f2) Vale.Curve25519.Fast_defs.prime }
a2;
== { FStar.Math.Lemmas.lemma_mod_add_distr (as_nat h0 f2) (as_nat h0 f1) Vale.Curve25519.Fast_defs.prime }
a3;
== { }
b;
}
in aux();
if EverCrypt.TargetConfig.hacl_can_compile_inline_asm then
Vale.Inline.X64.Fadd_inline.fadd out f1 f2
else
Vale.Wrapper.X64.Fadd.fadd_e out f1 f2 | val fadd: fadd_t M64 p
let fadd out f1 f2 = | false | null | false | let h0 = ST.get () in
let aux ()
: Lemma
(P.fadd (F64.fevalh h0 f1) (F64.fevalh h0 f2) ==
(FA.as_nat f1 h0 + FA.as_nat f2 h0) % Vale.Curve25519.Fast_defs.prime) =
let a = P.fadd (F64.fevalh h0 f1) (F64.fevalh h0 f2) in
let a1 =
(as_nat h0 f1 % Vale.Curve25519.Fast_defs.prime + as_nat h0 f2 % Vale.Curve25519.Fast_defs.prime
) %
Vale.Curve25519.Fast_defs.prime
in
let a2 =
(as_nat h0 f1 % Vale.Curve25519.Fast_defs.prime + as_nat h0 f2) %
Vale.Curve25519.Fast_defs.prime
in
let a3 = (as_nat h0 f1 + as_nat h0 f2) % Vale.Curve25519.Fast_defs.prime in
let b = (FA.as_nat f1 h0 + FA.as_nat f2 h0) % Vale.Curve25519.Fast_defs.prime in
calc ( == ) {
a;
( == ) { FStar.Math.Lemmas.modulo_distributivity (as_nat h0 f1)
(as_nat h0 f2)
Vale.Curve25519.Fast_defs.prime }
a1;
( == ) { FStar.Math.Lemmas.lemma_mod_add_distr (as_nat h0 f1 % Vale.Curve25519.Fast_defs.prime)
(as_nat h0 f2)
Vale.Curve25519.Fast_defs.prime }
a2;
( == ) { FStar.Math.Lemmas.lemma_mod_add_distr (as_nat h0 f2)
(as_nat h0 f1)
Vale.Curve25519.Fast_defs.prime }
a3;
( == ) { () }
b;
}
in
aux ();
if EverCrypt.TargetConfig.hacl_can_compile_inline_asm
then Vale.Inline.X64.Fadd_inline.fadd out f1 f2
else Vale.Wrapper.X64.Fadd.fadd_e out f1 f2 | {
"checked_file": "Hacl.Impl.Curve25519.Field64.Vale.fst.checked",
"dependencies": [
"Vale.Wrapper.X64.Fswap.fsti.checked",
"Vale.Wrapper.X64.Fsub.fsti.checked",
"Vale.Wrapper.X64.Fsqr.fsti.checked",
"Vale.Wrapper.X64.Fmul.fsti.checked",
"Vale.Wrapper.X64.Fadd.fsti.checked",
"Vale.Inline.X64.Fswap_inline.fsti.checked",
"Vale.Inline.X64.Fsqr_inline.fsti.checked",
"Vale.Inline.X64.Fmul_inline.fsti.checked",
"Vale.Inline.X64.Fadd_inline.fsti.checked",
"Vale.Curve25519.Fast_defs.fst.checked",
"Spec.Curve25519.fst.checked",
"prims.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.IntTypes.fst.checked",
"Lib.Buffer.fst.checked",
"Hacl.Spec.Curve25519.Field64.Definition.fst.checked",
"Hacl.Impl.Curve25519.Field64.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.All.fst.checked",
"FStar.HyperStack.fst.checked",
"FStar.Classical.fsti.checked",
"FStar.Calc.fsti.checked",
"EverCrypt.TargetConfig.fsti.checked"
],
"interface_file": true,
"source_file": "Hacl.Impl.Curve25519.Field64.Vale.fst"
} | [
"total"
] | [
"Hacl.Impl.Curve25519.Fields.Core.felem",
"Hacl.Impl.Curve25519.Fields.Core.M64",
"EverCrypt.TargetConfig.hacl_can_compile_inline_asm",
"Vale.Inline.X64.Fadd_inline.fadd",
"Prims.unit",
"Prims.bool",
"Vale.Wrapper.X64.Fadd.fadd_e",
"Prims.l_True",
"Prims.squash",
"Prims.eq2",
"Prims.int",
"Spec.Curve25519.fadd",
"Hacl.Impl.Curve25519.Field64.fevalh",
"Prims.op_Modulus",
"Prims.op_Addition",
"Vale.Wrapper.X64.Fadd.as_nat",
"Prims.Nil",
"FStar.Pervasives.pattern",
"FStar.Calc.calc_finish",
"Spec.Curve25519.elem",
"Prims.Cons",
"FStar.Preorder.relation",
"FStar.Calc.calc_step",
"FStar.Calc.calc_init",
"FStar.Calc.calc_pack",
"FStar.Math.Lemmas.modulo_distributivity",
"Hacl.Impl.Curve25519.Fields.Core.as_nat",
"Vale.Curve25519.Fast_defs.prime",
"FStar.Math.Lemmas.lemma_mod_add_distr",
"FStar.Monotonic.HyperStack.mem",
"FStar.HyperStack.ST.get"
] | [] | module Hacl.Impl.Curve25519.Field64.Vale
module HS = FStar.HyperStack
module ST = FStar.HyperStack.ST
open FStar.Calc
friend Lib.Buffer
friend Lib.IntTypes
open FStar.HyperStack
open FStar.HyperStack.All
open FStar.Mul
open Lib.Sequence
open Lib.IntTypes
open Lib.Buffer
module B = Lib.Buffer
module S = Hacl.Spec.Curve25519.Field64.Definition
module P = Spec.Curve25519
module FA = Vale.Wrapper.X64.Fadd
module F64 = Hacl.Impl.Curve25519.Field64
/// We are trying to connect HACL* abstractions with regular F* libraries, so in
/// addition to ``friend``'ing ``Lib.*``, we also write a couple lemmas that we
/// prove via normalization to facilitate the job of proving that calling the
/// Vale interop signatures faithfully implements the required HACL* signature.
#set-options "--max_fuel 0 --max_ifuel 0 --z3rlimit 300 --z3refresh"
let buffer_is_buffer a len: Lemma
(ensures (lbuffer a len == b:B.buffer a{B.length b == UInt32.v len}))
[ SMTPat (lbuffer a len) ]
=
assert_norm (lbuffer a len == b:B.buffer a{B.length b == UInt32.v len})
let as_nat_is_as_nat (b:lbuffer uint64 4ul) (h:HS.mem): Lemma
(ensures (FA.as_nat b h == F64.as_nat h b))
[ SMTPat (as_nat h b) ]
=
()
let _: squash (Vale.Curve25519.Fast_defs.prime = Spec.Curve25519.prime) =
assert_norm (Vale.Curve25519.Fast_defs.prime = Spec.Curve25519.prime)
// This one only goes through in a reasonable amount of rlimit thanks to
// ``as_nat_is_as_nat`` and ``buffer_is_buffer`` above.
[@ CInline]
let add_scalar out f1 f2 =
if EverCrypt.TargetConfig.hacl_can_compile_inline_asm then
Vale.Inline.X64.Fadd_inline.add_scalar out f1 f2
else
Vale.Wrapper.X64.Fadd.add_scalar_e out f1 f2
// Spec discrepancy. Need to call the right lemma from FStar.Math.Lemmas.
#push-options "--max_fuel 0 --max_ifuel 0 --z3rlimit 400" | false | true | Hacl.Impl.Curve25519.Field64.Vale.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": true,
"z3rlimit": 400,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val fadd: fadd_t M64 p | [] | Hacl.Impl.Curve25519.Field64.Vale.fadd | {
"file_name": "code/curve25519/Hacl.Impl.Curve25519.Field64.Vale.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | Hacl.Impl.Curve25519.Fields.Core.fadd_t Hacl.Impl.Curve25519.Fields.Core.M64
Hacl.Impl.Curve25519.Field64.Vale.p | {
"end_col": 42,
"end_line": 85,
"start_col": 20,
"start_line": 60
} |
Prims.Tot | val fsub: fsub_t M64 p | [
{
"abbrev": true,
"full_module": "Hacl.Impl.Curve25519.Field64",
"short_module": "F64"
},
{
"abbrev": true,
"full_module": "Vale.Wrapper.X64.Fadd",
"short_module": "FA"
},
{
"abbrev": true,
"full_module": "Spec.Curve25519",
"short_module": "P"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.Curve25519.Field64.Definition",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "Lib.Buffer",
"short_module": "B"
},
{
"abbrev": false,
"full_module": "Lib.Buffer",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Sequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.All",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Calc",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": false,
"full_module": "Hacl.Impl.Curve25519.Fields.Core",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl.Curve25519.Field64",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl.Curve25519.Field64",
"short_module": null
},
{
"abbrev": 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 fsub out f1 f2 =
let h0 = ST.get() in
let aux () : Lemma (P.fsub (F64.fevalh h0 f1) (F64.fevalh h0 f2) == (FA.as_nat f1 h0 - FA.as_nat f2 h0) % Vale.Curve25519.Fast_defs.prime) =
let a = P.fsub (F64.fevalh h0 f1) (F64.fevalh h0 f2) in
let a1 = (as_nat h0 f1 % Vale.Curve25519.Fast_defs.prime - as_nat h0 f2 % Vale.Curve25519.Fast_defs.prime) % Vale.Curve25519.Fast_defs.prime in
let a2 = (as_nat h0 f1 % Vale.Curve25519.Fast_defs.prime - as_nat h0 f2) % Vale.Curve25519.Fast_defs.prime in
let a3 = (as_nat h0 f1 - as_nat h0 f2) % Vale.Curve25519.Fast_defs.prime in
let b = (FA.as_nat f1 h0 - FA.as_nat f2 h0) % Vale.Curve25519.Fast_defs.prime in
calc (==) {
a;
== { }
a1;
== { FStar.Math.Lemmas.lemma_mod_sub_distr (as_nat h0 f1 % Vale.Curve25519.Fast_defs.prime) (as_nat h0 f2)
Vale.Curve25519.Fast_defs.prime }
a2;
== { FStar.Math.Lemmas.lemma_mod_add_distr (- as_nat h0 f2) (as_nat h0 f1) Vale.Curve25519.Fast_defs.prime }
a3;
== { }
b;
}
in aux();
if EverCrypt.TargetConfig.hacl_can_compile_inline_asm then
Vale.Inline.X64.Fadd_inline.fsub out f1 f2
else
Vale.Wrapper.X64.Fsub.fsub_e out f1 f2 | val fsub: fsub_t M64 p
let fsub out f1 f2 = | false | null | false | let h0 = ST.get () in
let aux ()
: Lemma
(P.fsub (F64.fevalh h0 f1) (F64.fevalh h0 f2) ==
(FA.as_nat f1 h0 - FA.as_nat f2 h0) % Vale.Curve25519.Fast_defs.prime) =
let a = P.fsub (F64.fevalh h0 f1) (F64.fevalh h0 f2) in
let a1 =
(as_nat h0 f1 % Vale.Curve25519.Fast_defs.prime - as_nat h0 f2 % Vale.Curve25519.Fast_defs.prime
) %
Vale.Curve25519.Fast_defs.prime
in
let a2 =
(as_nat h0 f1 % Vale.Curve25519.Fast_defs.prime - as_nat h0 f2) %
Vale.Curve25519.Fast_defs.prime
in
let a3 = (as_nat h0 f1 - as_nat h0 f2) % Vale.Curve25519.Fast_defs.prime in
let b = (FA.as_nat f1 h0 - FA.as_nat f2 h0) % Vale.Curve25519.Fast_defs.prime in
calc ( == ) {
a;
( == ) { () }
a1;
( == ) { FStar.Math.Lemmas.lemma_mod_sub_distr (as_nat h0 f1 % Vale.Curve25519.Fast_defs.prime)
(as_nat h0 f2)
Vale.Curve25519.Fast_defs.prime }
a2;
( == ) { FStar.Math.Lemmas.lemma_mod_add_distr (- as_nat h0 f2)
(as_nat h0 f1)
Vale.Curve25519.Fast_defs.prime }
a3;
( == ) { () }
b;
}
in
aux ();
if EverCrypt.TargetConfig.hacl_can_compile_inline_asm
then Vale.Inline.X64.Fadd_inline.fsub out f1 f2
else Vale.Wrapper.X64.Fsub.fsub_e out f1 f2 | {
"checked_file": "Hacl.Impl.Curve25519.Field64.Vale.fst.checked",
"dependencies": [
"Vale.Wrapper.X64.Fswap.fsti.checked",
"Vale.Wrapper.X64.Fsub.fsti.checked",
"Vale.Wrapper.X64.Fsqr.fsti.checked",
"Vale.Wrapper.X64.Fmul.fsti.checked",
"Vale.Wrapper.X64.Fadd.fsti.checked",
"Vale.Inline.X64.Fswap_inline.fsti.checked",
"Vale.Inline.X64.Fsqr_inline.fsti.checked",
"Vale.Inline.X64.Fmul_inline.fsti.checked",
"Vale.Inline.X64.Fadd_inline.fsti.checked",
"Vale.Curve25519.Fast_defs.fst.checked",
"Spec.Curve25519.fst.checked",
"prims.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.IntTypes.fst.checked",
"Lib.Buffer.fst.checked",
"Hacl.Spec.Curve25519.Field64.Definition.fst.checked",
"Hacl.Impl.Curve25519.Field64.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.All.fst.checked",
"FStar.HyperStack.fst.checked",
"FStar.Classical.fsti.checked",
"FStar.Calc.fsti.checked",
"EverCrypt.TargetConfig.fsti.checked"
],
"interface_file": true,
"source_file": "Hacl.Impl.Curve25519.Field64.Vale.fst"
} | [
"total"
] | [
"Hacl.Impl.Curve25519.Fields.Core.felem",
"Hacl.Impl.Curve25519.Fields.Core.M64",
"EverCrypt.TargetConfig.hacl_can_compile_inline_asm",
"Vale.Inline.X64.Fadd_inline.fsub",
"Prims.unit",
"Prims.bool",
"Vale.Wrapper.X64.Fsub.fsub_e",
"Prims.l_True",
"Prims.squash",
"Prims.eq2",
"Prims.int",
"Spec.Curve25519.fsub",
"Hacl.Impl.Curve25519.Field64.fevalh",
"Prims.op_Modulus",
"Prims.op_Subtraction",
"Vale.Wrapper.X64.Fadd.as_nat",
"Prims.Nil",
"FStar.Pervasives.pattern",
"FStar.Calc.calc_finish",
"Spec.Curve25519.elem",
"Prims.Cons",
"FStar.Preorder.relation",
"FStar.Calc.calc_step",
"FStar.Calc.calc_init",
"FStar.Calc.calc_pack",
"FStar.Math.Lemmas.lemma_mod_sub_distr",
"Hacl.Impl.Curve25519.Fields.Core.as_nat",
"Vale.Curve25519.Fast_defs.prime",
"FStar.Math.Lemmas.lemma_mod_add_distr",
"Prims.op_Minus",
"FStar.Monotonic.HyperStack.mem",
"FStar.HyperStack.ST.get"
] | [] | module Hacl.Impl.Curve25519.Field64.Vale
module HS = FStar.HyperStack
module ST = FStar.HyperStack.ST
open FStar.Calc
friend Lib.Buffer
friend Lib.IntTypes
open FStar.HyperStack
open FStar.HyperStack.All
open FStar.Mul
open Lib.Sequence
open Lib.IntTypes
open Lib.Buffer
module B = Lib.Buffer
module S = Hacl.Spec.Curve25519.Field64.Definition
module P = Spec.Curve25519
module FA = Vale.Wrapper.X64.Fadd
module F64 = Hacl.Impl.Curve25519.Field64
/// We are trying to connect HACL* abstractions with regular F* libraries, so in
/// addition to ``friend``'ing ``Lib.*``, we also write a couple lemmas that we
/// prove via normalization to facilitate the job of proving that calling the
/// Vale interop signatures faithfully implements the required HACL* signature.
#set-options "--max_fuel 0 --max_ifuel 0 --z3rlimit 300 --z3refresh"
let buffer_is_buffer a len: Lemma
(ensures (lbuffer a len == b:B.buffer a{B.length b == UInt32.v len}))
[ SMTPat (lbuffer a len) ]
=
assert_norm (lbuffer a len == b:B.buffer a{B.length b == UInt32.v len})
let as_nat_is_as_nat (b:lbuffer uint64 4ul) (h:HS.mem): Lemma
(ensures (FA.as_nat b h == F64.as_nat h b))
[ SMTPat (as_nat h b) ]
=
()
let _: squash (Vale.Curve25519.Fast_defs.prime = Spec.Curve25519.prime) =
assert_norm (Vale.Curve25519.Fast_defs.prime = Spec.Curve25519.prime)
// This one only goes through in a reasonable amount of rlimit thanks to
// ``as_nat_is_as_nat`` and ``buffer_is_buffer`` above.
[@ CInline]
let add_scalar out f1 f2 =
if EverCrypt.TargetConfig.hacl_can_compile_inline_asm then
Vale.Inline.X64.Fadd_inline.add_scalar out f1 f2
else
Vale.Wrapper.X64.Fadd.add_scalar_e out f1 f2
// Spec discrepancy. Need to call the right lemma from FStar.Math.Lemmas.
#push-options "--max_fuel 0 --max_ifuel 0 --z3rlimit 400"
[@ CInline]
let fadd out f1 f2 =
let h0 = ST.get () in
let aux () : Lemma (P.fadd (F64.fevalh h0 f1) (F64.fevalh h0 f2) == (FA.as_nat f1 h0 + FA.as_nat f2 h0) % Vale.Curve25519.Fast_defs.prime) =
let a = P.fadd (F64.fevalh h0 f1) (F64.fevalh h0 f2) in
let a1 = (as_nat h0 f1 % Vale.Curve25519.Fast_defs.prime + as_nat h0 f2 % Vale.Curve25519.Fast_defs.prime) % Vale.Curve25519.Fast_defs.prime in
let a2 = (as_nat h0 f1 % Vale.Curve25519.Fast_defs.prime + as_nat h0 f2) % Vale.Curve25519.Fast_defs.prime in
let a3 = (as_nat h0 f1 + as_nat h0 f2) % Vale.Curve25519.Fast_defs.prime in
let b = (FA.as_nat f1 h0 + FA.as_nat f2 h0) % Vale.Curve25519.Fast_defs.prime in
calc (==) {
a;
== { FStar.Math.Lemmas.modulo_distributivity
(as_nat h0 f1) (as_nat h0 f2) Vale.Curve25519.Fast_defs.prime }
a1;
== { FStar.Math.Lemmas.lemma_mod_add_distr (as_nat h0 f1 % Vale.Curve25519.Fast_defs.prime)
(as_nat h0 f2) Vale.Curve25519.Fast_defs.prime }
a2;
== { FStar.Math.Lemmas.lemma_mod_add_distr (as_nat h0 f2) (as_nat h0 f1) Vale.Curve25519.Fast_defs.prime }
a3;
== { }
b;
}
in aux();
if EverCrypt.TargetConfig.hacl_can_compile_inline_asm then
Vale.Inline.X64.Fadd_inline.fadd out f1 f2
else
Vale.Wrapper.X64.Fadd.fadd_e out f1 f2
#pop-options | false | true | Hacl.Impl.Curve25519.Field64.Vale.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": true,
"z3rlimit": 300,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val fsub: fsub_t M64 p | [] | Hacl.Impl.Curve25519.Field64.Vale.fsub | {
"file_name": "code/curve25519/Hacl.Impl.Curve25519.Field64.Vale.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | Hacl.Impl.Curve25519.Fields.Core.fsub_t Hacl.Impl.Curve25519.Fields.Core.M64
Hacl.Impl.Curve25519.Field64.Vale.p | {
"end_col": 42,
"end_line": 113,
"start_col": 20,
"start_line": 89
} |
Prims.Tot | val fsqr2: fsqr2_t M64 p | [
{
"abbrev": true,
"full_module": "Hacl.Impl.Curve25519.Field64",
"short_module": "F64"
},
{
"abbrev": true,
"full_module": "Vale.Wrapper.X64.Fadd",
"short_module": "FA"
},
{
"abbrev": true,
"full_module": "Spec.Curve25519",
"short_module": "P"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.Curve25519.Field64.Definition",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "Lib.Buffer",
"short_module": "B"
},
{
"abbrev": false,
"full_module": "Lib.Buffer",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Sequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.All",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Calc",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": false,
"full_module": "Hacl.Impl.Curve25519.Fields.Core",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl.Curve25519.Field64",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl.Curve25519.Field64",
"short_module": null
},
{
"abbrev": 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 fsqr2 out f tmp =
let h0 = ST.get() in
lemma_fmul_equiv h0 (gsub f 0ul 4ul) (gsub f 0ul 4ul);
lemma_fmul_equiv h0 (gsub f 4ul 4ul) (gsub f 4ul 4ul);
if EverCrypt.TargetConfig.hacl_can_compile_inline_asm then
Vale.Inline.X64.Fsqr_inline.fsqr2 out f tmp
else
Vale.Wrapper.X64.Fsqr.fsqr2_e tmp f out | val fsqr2: fsqr2_t M64 p
let fsqr2 out f tmp = | false | null | false | let h0 = ST.get () in
lemma_fmul_equiv h0 (gsub f 0ul 4ul) (gsub f 0ul 4ul);
lemma_fmul_equiv h0 (gsub f 4ul 4ul) (gsub f 4ul 4ul);
if EverCrypt.TargetConfig.hacl_can_compile_inline_asm
then Vale.Inline.X64.Fsqr_inline.fsqr2 out f tmp
else Vale.Wrapper.X64.Fsqr.fsqr2_e tmp f out | {
"checked_file": "Hacl.Impl.Curve25519.Field64.Vale.fst.checked",
"dependencies": [
"Vale.Wrapper.X64.Fswap.fsti.checked",
"Vale.Wrapper.X64.Fsub.fsti.checked",
"Vale.Wrapper.X64.Fsqr.fsti.checked",
"Vale.Wrapper.X64.Fmul.fsti.checked",
"Vale.Wrapper.X64.Fadd.fsti.checked",
"Vale.Inline.X64.Fswap_inline.fsti.checked",
"Vale.Inline.X64.Fsqr_inline.fsti.checked",
"Vale.Inline.X64.Fmul_inline.fsti.checked",
"Vale.Inline.X64.Fadd_inline.fsti.checked",
"Vale.Curve25519.Fast_defs.fst.checked",
"Spec.Curve25519.fst.checked",
"prims.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.IntTypes.fst.checked",
"Lib.Buffer.fst.checked",
"Hacl.Spec.Curve25519.Field64.Definition.fst.checked",
"Hacl.Impl.Curve25519.Field64.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.All.fst.checked",
"FStar.HyperStack.fst.checked",
"FStar.Classical.fsti.checked",
"FStar.Calc.fsti.checked",
"EverCrypt.TargetConfig.fsti.checked"
],
"interface_file": true,
"source_file": "Hacl.Impl.Curve25519.Field64.Vale.fst"
} | [
"total"
] | [
"Hacl.Impl.Curve25519.Fields.Core.felem2",
"Hacl.Impl.Curve25519.Fields.Core.M64",
"Hacl.Impl.Curve25519.Fields.Core.felem_wide2",
"EverCrypt.TargetConfig.hacl_can_compile_inline_asm",
"Vale.Inline.X64.Fsqr_inline.fsqr2",
"Prims.unit",
"Prims.bool",
"Vale.Wrapper.X64.Fsqr.fsqr2_e",
"Hacl.Impl.Curve25519.Field64.Vale.lemma_fmul_equiv",
"Lib.Buffer.gsub",
"Lib.Buffer.MUT",
"Hacl.Impl.Curve25519.Fields.Core.limb",
"Lib.IntTypes.op_Plus_Dot",
"Lib.IntTypes.U32",
"Lib.IntTypes.PUB",
"Hacl.Impl.Curve25519.Fields.Core.nlimb",
"FStar.UInt32.__uint_to_t",
"FStar.Monotonic.HyperStack.mem",
"FStar.HyperStack.ST.get"
] | [] | module Hacl.Impl.Curve25519.Field64.Vale
module HS = FStar.HyperStack
module ST = FStar.HyperStack.ST
open FStar.Calc
friend Lib.Buffer
friend Lib.IntTypes
open FStar.HyperStack
open FStar.HyperStack.All
open FStar.Mul
open Lib.Sequence
open Lib.IntTypes
open Lib.Buffer
module B = Lib.Buffer
module S = Hacl.Spec.Curve25519.Field64.Definition
module P = Spec.Curve25519
module FA = Vale.Wrapper.X64.Fadd
module F64 = Hacl.Impl.Curve25519.Field64
/// We are trying to connect HACL* abstractions with regular F* libraries, so in
/// addition to ``friend``'ing ``Lib.*``, we also write a couple lemmas that we
/// prove via normalization to facilitate the job of proving that calling the
/// Vale interop signatures faithfully implements the required HACL* signature.
#set-options "--max_fuel 0 --max_ifuel 0 --z3rlimit 300 --z3refresh"
let buffer_is_buffer a len: Lemma
(ensures (lbuffer a len == b:B.buffer a{B.length b == UInt32.v len}))
[ SMTPat (lbuffer a len) ]
=
assert_norm (lbuffer a len == b:B.buffer a{B.length b == UInt32.v len})
let as_nat_is_as_nat (b:lbuffer uint64 4ul) (h:HS.mem): Lemma
(ensures (FA.as_nat b h == F64.as_nat h b))
[ SMTPat (as_nat h b) ]
=
()
let _: squash (Vale.Curve25519.Fast_defs.prime = Spec.Curve25519.prime) =
assert_norm (Vale.Curve25519.Fast_defs.prime = Spec.Curve25519.prime)
// This one only goes through in a reasonable amount of rlimit thanks to
// ``as_nat_is_as_nat`` and ``buffer_is_buffer`` above.
[@ CInline]
let add_scalar out f1 f2 =
if EverCrypt.TargetConfig.hacl_can_compile_inline_asm then
Vale.Inline.X64.Fadd_inline.add_scalar out f1 f2
else
Vale.Wrapper.X64.Fadd.add_scalar_e out f1 f2
// Spec discrepancy. Need to call the right lemma from FStar.Math.Lemmas.
#push-options "--max_fuel 0 --max_ifuel 0 --z3rlimit 400"
[@ CInline]
let fadd out f1 f2 =
let h0 = ST.get () in
let aux () : Lemma (P.fadd (F64.fevalh h0 f1) (F64.fevalh h0 f2) == (FA.as_nat f1 h0 + FA.as_nat f2 h0) % Vale.Curve25519.Fast_defs.prime) =
let a = P.fadd (F64.fevalh h0 f1) (F64.fevalh h0 f2) in
let a1 = (as_nat h0 f1 % Vale.Curve25519.Fast_defs.prime + as_nat h0 f2 % Vale.Curve25519.Fast_defs.prime) % Vale.Curve25519.Fast_defs.prime in
let a2 = (as_nat h0 f1 % Vale.Curve25519.Fast_defs.prime + as_nat h0 f2) % Vale.Curve25519.Fast_defs.prime in
let a3 = (as_nat h0 f1 + as_nat h0 f2) % Vale.Curve25519.Fast_defs.prime in
let b = (FA.as_nat f1 h0 + FA.as_nat f2 h0) % Vale.Curve25519.Fast_defs.prime in
calc (==) {
a;
== { FStar.Math.Lemmas.modulo_distributivity
(as_nat h0 f1) (as_nat h0 f2) Vale.Curve25519.Fast_defs.prime }
a1;
== { FStar.Math.Lemmas.lemma_mod_add_distr (as_nat h0 f1 % Vale.Curve25519.Fast_defs.prime)
(as_nat h0 f2) Vale.Curve25519.Fast_defs.prime }
a2;
== { FStar.Math.Lemmas.lemma_mod_add_distr (as_nat h0 f2) (as_nat h0 f1) Vale.Curve25519.Fast_defs.prime }
a3;
== { }
b;
}
in aux();
if EverCrypt.TargetConfig.hacl_can_compile_inline_asm then
Vale.Inline.X64.Fadd_inline.fadd out f1 f2
else
Vale.Wrapper.X64.Fadd.fadd_e out f1 f2
#pop-options
[@ CInline]
let fsub out f1 f2 =
let h0 = ST.get() in
let aux () : Lemma (P.fsub (F64.fevalh h0 f1) (F64.fevalh h0 f2) == (FA.as_nat f1 h0 - FA.as_nat f2 h0) % Vale.Curve25519.Fast_defs.prime) =
let a = P.fsub (F64.fevalh h0 f1) (F64.fevalh h0 f2) in
let a1 = (as_nat h0 f1 % Vale.Curve25519.Fast_defs.prime - as_nat h0 f2 % Vale.Curve25519.Fast_defs.prime) % Vale.Curve25519.Fast_defs.prime in
let a2 = (as_nat h0 f1 % Vale.Curve25519.Fast_defs.prime - as_nat h0 f2) % Vale.Curve25519.Fast_defs.prime in
let a3 = (as_nat h0 f1 - as_nat h0 f2) % Vale.Curve25519.Fast_defs.prime in
let b = (FA.as_nat f1 h0 - FA.as_nat f2 h0) % Vale.Curve25519.Fast_defs.prime in
calc (==) {
a;
== { }
a1;
== { FStar.Math.Lemmas.lemma_mod_sub_distr (as_nat h0 f1 % Vale.Curve25519.Fast_defs.prime) (as_nat h0 f2)
Vale.Curve25519.Fast_defs.prime }
a2;
== { FStar.Math.Lemmas.lemma_mod_add_distr (- as_nat h0 f2) (as_nat h0 f1) Vale.Curve25519.Fast_defs.prime }
a3;
== { }
b;
}
in aux();
if EverCrypt.TargetConfig.hacl_can_compile_inline_asm then
Vale.Inline.X64.Fadd_inline.fsub out f1 f2
else
Vale.Wrapper.X64.Fsub.fsub_e out f1 f2
#push-options "--z3rlimit 200"
let lemma_fmul_equiv (h0:HS.mem) (f1 f2:F64.u256) : Lemma
(P.fmul (F64.fevalh h0 f1) (F64.fevalh h0 f2) == (FA.as_nat f1 h0 * FA.as_nat f2 h0) % Vale.Curve25519.Fast_defs.prime)
= let a = P.fmul (F64.fevalh h0 f1) (F64.fevalh h0 f2) in
let a1 = ((F64.as_nat h0 f1 % Vale.Curve25519.Fast_defs.prime) * (F64.as_nat h0 f2 % Vale.Curve25519.Fast_defs.prime)) % Vale.Curve25519.Fast_defs.prime in
let a2 = ((F64.as_nat h0 f1 % Vale.Curve25519.Fast_defs.prime) * F64.as_nat h0 f2) % Vale.Curve25519.Fast_defs.prime in
let a3 = (F64.as_nat h0 f1 * F64.as_nat h0 f2) % Vale.Curve25519.Fast_defs.prime in
let b = (FA.as_nat f1 h0 * FA.as_nat f2 h0) % Vale.Curve25519.Fast_defs.prime in
calc (==) {
a;
== { }
a1;
== { FStar.Math.Lemmas.lemma_mod_mul_distr_r (F64.as_nat h0 f1 % Vale.Curve25519.Fast_defs.prime) (F64.as_nat h0 f2) Vale.Curve25519.Fast_defs.prime }
a2;
== { FStar.Math.Lemmas.lemma_mod_mul_distr_l (F64.as_nat h0 f1) (F64.as_nat h0 f2) Vale.Curve25519.Fast_defs.prime }
a3;
== { }
b;
}
#pop-options
[@ CInline]
let fmul out f1 f2 tmp =
let h0 = ST.get() in
lemma_fmul_equiv h0 f1 f2;
if EverCrypt.TargetConfig.hacl_can_compile_inline_asm then (
assert (disjoint f1 (gsub tmp 0ul 8ul));
assert (disjoint f2 (gsub tmp 0ul 8ul));
Vale.Inline.X64.Fmul_inline.fmul out f1 f2 (sub tmp 0ul 8ul)
) else
Vale.Wrapper.X64.Fmul.fmul_e (sub tmp 0ul 8ul) f1 out f2
#push-options "--z3rlimit 500"
[@ CInline]
let fmul2 out f1 f2 tmp =
let h0 = ST.get() in
lemma_fmul_equiv h0 (gsub f1 0ul 4ul) (gsub f2 0ul 4ul);
lemma_fmul_equiv h0 (gsub f1 4ul 4ul) (gsub f2 4ul 4ul);
if EverCrypt.TargetConfig.hacl_can_compile_inline_asm then
Vale.Inline.X64.Fmul_inline.fmul2 out f1 f2 tmp
else
Vale.Wrapper.X64.Fmul.fmul2_e tmp f1 out f2
#pop-options
[@ CInline]
let fmul_scalar out f1 f2 =
let h0 = ST.get() in
let aux () : Lemma (P.fmul (F64.fevalh h0 f1) (v f2) == (FA.as_nat f1 h0 * v f2) % Vale.Curve25519.Fast_defs.prime) =
let a = P.fmul (F64.fevalh h0 f1) (v f2) in
let a1 = ((F64.as_nat h0 f1 % Vale.Curve25519.Fast_defs.prime) * v f2) % Vale.Curve25519.Fast_defs.prime in
let a2 = (F64.as_nat h0 f1 * v f2) % Vale.Curve25519.Fast_defs.prime in
let b = (FA.as_nat f1 h0 * v f2) % Vale.Curve25519.Fast_defs.prime in
calc (==) {
a;
== { }
a1;
== { FStar.Math.Lemmas.lemma_mod_mul_distr_l (F64.as_nat h0 f1) (v f2) Vale.Curve25519.Fast_defs.prime }
a2;
== { }
b;
}
in aux();
assert_norm (pow2 17 = 131072);
if EverCrypt.TargetConfig.hacl_can_compile_inline_asm then
Vale.Inline.X64.Fmul_inline.fmul_scalar out f1 f2
else
Vale.Wrapper.X64.Fmul.fmul_scalar_e out f1 f2
[@ CInline]
let fsqr out f1 tmp =
let h0 = ST.get() in
lemma_fmul_equiv h0 f1 f1;
if EverCrypt.TargetConfig.hacl_can_compile_inline_asm then
Vale.Inline.X64.Fsqr_inline.fsqr out f1 tmp
else
Vale.Wrapper.X64.Fsqr.fsqr_e tmp f1 out | false | true | Hacl.Impl.Curve25519.Field64.Vale.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": true,
"z3rlimit": 300,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val fsqr2: fsqr2_t M64 p | [] | Hacl.Impl.Curve25519.Field64.Vale.fsqr2 | {
"file_name": "code/curve25519/Hacl.Impl.Curve25519.Field64.Vale.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | Hacl.Impl.Curve25519.Fields.Core.fsqr2_t Hacl.Impl.Curve25519.Fields.Core.M64
Hacl.Impl.Curve25519.Field64.Vale.p | {
"end_col": 43,
"end_line": 200,
"start_col": 21,
"start_line": 193
} |
Prims.Tot | val fmul2: fmul2_t M64 p | [
{
"abbrev": true,
"full_module": "Hacl.Impl.Curve25519.Field64",
"short_module": "F64"
},
{
"abbrev": true,
"full_module": "Vale.Wrapper.X64.Fadd",
"short_module": "FA"
},
{
"abbrev": true,
"full_module": "Spec.Curve25519",
"short_module": "P"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.Curve25519.Field64.Definition",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "Lib.Buffer",
"short_module": "B"
},
{
"abbrev": false,
"full_module": "Lib.Buffer",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Sequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.All",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Calc",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": false,
"full_module": "Hacl.Impl.Curve25519.Fields.Core",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl.Curve25519.Field64",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl.Curve25519.Field64",
"short_module": null
},
{
"abbrev": 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 fmul2 out f1 f2 tmp =
let h0 = ST.get() in
lemma_fmul_equiv h0 (gsub f1 0ul 4ul) (gsub f2 0ul 4ul);
lemma_fmul_equiv h0 (gsub f1 4ul 4ul) (gsub f2 4ul 4ul);
if EverCrypt.TargetConfig.hacl_can_compile_inline_asm then
Vale.Inline.X64.Fmul_inline.fmul2 out f1 f2 tmp
else
Vale.Wrapper.X64.Fmul.fmul2_e tmp f1 out f2 | val fmul2: fmul2_t M64 p
let fmul2 out f1 f2 tmp = | false | null | false | let h0 = ST.get () in
lemma_fmul_equiv h0 (gsub f1 0ul 4ul) (gsub f2 0ul 4ul);
lemma_fmul_equiv h0 (gsub f1 4ul 4ul) (gsub f2 4ul 4ul);
if EverCrypt.TargetConfig.hacl_can_compile_inline_asm
then Vale.Inline.X64.Fmul_inline.fmul2 out f1 f2 tmp
else Vale.Wrapper.X64.Fmul.fmul2_e tmp f1 out f2 | {
"checked_file": "Hacl.Impl.Curve25519.Field64.Vale.fst.checked",
"dependencies": [
"Vale.Wrapper.X64.Fswap.fsti.checked",
"Vale.Wrapper.X64.Fsub.fsti.checked",
"Vale.Wrapper.X64.Fsqr.fsti.checked",
"Vale.Wrapper.X64.Fmul.fsti.checked",
"Vale.Wrapper.X64.Fadd.fsti.checked",
"Vale.Inline.X64.Fswap_inline.fsti.checked",
"Vale.Inline.X64.Fsqr_inline.fsti.checked",
"Vale.Inline.X64.Fmul_inline.fsti.checked",
"Vale.Inline.X64.Fadd_inline.fsti.checked",
"Vale.Curve25519.Fast_defs.fst.checked",
"Spec.Curve25519.fst.checked",
"prims.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.IntTypes.fst.checked",
"Lib.Buffer.fst.checked",
"Hacl.Spec.Curve25519.Field64.Definition.fst.checked",
"Hacl.Impl.Curve25519.Field64.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.All.fst.checked",
"FStar.HyperStack.fst.checked",
"FStar.Classical.fsti.checked",
"FStar.Calc.fsti.checked",
"EverCrypt.TargetConfig.fsti.checked"
],
"interface_file": true,
"source_file": "Hacl.Impl.Curve25519.Field64.Vale.fst"
} | [
"total"
] | [
"Hacl.Impl.Curve25519.Fields.Core.felem2",
"Hacl.Impl.Curve25519.Fields.Core.M64",
"Hacl.Impl.Curve25519.Fields.Core.felem_wide2",
"EverCrypt.TargetConfig.hacl_can_compile_inline_asm",
"Vale.Inline.X64.Fmul_inline.fmul2",
"Prims.unit",
"Prims.bool",
"Vale.Wrapper.X64.Fmul.fmul2_e",
"Hacl.Impl.Curve25519.Field64.Vale.lemma_fmul_equiv",
"Lib.Buffer.gsub",
"Lib.Buffer.MUT",
"Hacl.Impl.Curve25519.Fields.Core.limb",
"Lib.IntTypes.op_Plus_Dot",
"Lib.IntTypes.U32",
"Lib.IntTypes.PUB",
"Hacl.Impl.Curve25519.Fields.Core.nlimb",
"FStar.UInt32.__uint_to_t",
"FStar.Monotonic.HyperStack.mem",
"FStar.HyperStack.ST.get"
] | [] | module Hacl.Impl.Curve25519.Field64.Vale
module HS = FStar.HyperStack
module ST = FStar.HyperStack.ST
open FStar.Calc
friend Lib.Buffer
friend Lib.IntTypes
open FStar.HyperStack
open FStar.HyperStack.All
open FStar.Mul
open Lib.Sequence
open Lib.IntTypes
open Lib.Buffer
module B = Lib.Buffer
module S = Hacl.Spec.Curve25519.Field64.Definition
module P = Spec.Curve25519
module FA = Vale.Wrapper.X64.Fadd
module F64 = Hacl.Impl.Curve25519.Field64
/// We are trying to connect HACL* abstractions with regular F* libraries, so in
/// addition to ``friend``'ing ``Lib.*``, we also write a couple lemmas that we
/// prove via normalization to facilitate the job of proving that calling the
/// Vale interop signatures faithfully implements the required HACL* signature.
#set-options "--max_fuel 0 --max_ifuel 0 --z3rlimit 300 --z3refresh"
let buffer_is_buffer a len: Lemma
(ensures (lbuffer a len == b:B.buffer a{B.length b == UInt32.v len}))
[ SMTPat (lbuffer a len) ]
=
assert_norm (lbuffer a len == b:B.buffer a{B.length b == UInt32.v len})
let as_nat_is_as_nat (b:lbuffer uint64 4ul) (h:HS.mem): Lemma
(ensures (FA.as_nat b h == F64.as_nat h b))
[ SMTPat (as_nat h b) ]
=
()
let _: squash (Vale.Curve25519.Fast_defs.prime = Spec.Curve25519.prime) =
assert_norm (Vale.Curve25519.Fast_defs.prime = Spec.Curve25519.prime)
// This one only goes through in a reasonable amount of rlimit thanks to
// ``as_nat_is_as_nat`` and ``buffer_is_buffer`` above.
[@ CInline]
let add_scalar out f1 f2 =
if EverCrypt.TargetConfig.hacl_can_compile_inline_asm then
Vale.Inline.X64.Fadd_inline.add_scalar out f1 f2
else
Vale.Wrapper.X64.Fadd.add_scalar_e out f1 f2
// Spec discrepancy. Need to call the right lemma from FStar.Math.Lemmas.
#push-options "--max_fuel 0 --max_ifuel 0 --z3rlimit 400"
[@ CInline]
let fadd out f1 f2 =
let h0 = ST.get () in
let aux () : Lemma (P.fadd (F64.fevalh h0 f1) (F64.fevalh h0 f2) == (FA.as_nat f1 h0 + FA.as_nat f2 h0) % Vale.Curve25519.Fast_defs.prime) =
let a = P.fadd (F64.fevalh h0 f1) (F64.fevalh h0 f2) in
let a1 = (as_nat h0 f1 % Vale.Curve25519.Fast_defs.prime + as_nat h0 f2 % Vale.Curve25519.Fast_defs.prime) % Vale.Curve25519.Fast_defs.prime in
let a2 = (as_nat h0 f1 % Vale.Curve25519.Fast_defs.prime + as_nat h0 f2) % Vale.Curve25519.Fast_defs.prime in
let a3 = (as_nat h0 f1 + as_nat h0 f2) % Vale.Curve25519.Fast_defs.prime in
let b = (FA.as_nat f1 h0 + FA.as_nat f2 h0) % Vale.Curve25519.Fast_defs.prime in
calc (==) {
a;
== { FStar.Math.Lemmas.modulo_distributivity
(as_nat h0 f1) (as_nat h0 f2) Vale.Curve25519.Fast_defs.prime }
a1;
== { FStar.Math.Lemmas.lemma_mod_add_distr (as_nat h0 f1 % Vale.Curve25519.Fast_defs.prime)
(as_nat h0 f2) Vale.Curve25519.Fast_defs.prime }
a2;
== { FStar.Math.Lemmas.lemma_mod_add_distr (as_nat h0 f2) (as_nat h0 f1) Vale.Curve25519.Fast_defs.prime }
a3;
== { }
b;
}
in aux();
if EverCrypt.TargetConfig.hacl_can_compile_inline_asm then
Vale.Inline.X64.Fadd_inline.fadd out f1 f2
else
Vale.Wrapper.X64.Fadd.fadd_e out f1 f2
#pop-options
[@ CInline]
let fsub out f1 f2 =
let h0 = ST.get() in
let aux () : Lemma (P.fsub (F64.fevalh h0 f1) (F64.fevalh h0 f2) == (FA.as_nat f1 h0 - FA.as_nat f2 h0) % Vale.Curve25519.Fast_defs.prime) =
let a = P.fsub (F64.fevalh h0 f1) (F64.fevalh h0 f2) in
let a1 = (as_nat h0 f1 % Vale.Curve25519.Fast_defs.prime - as_nat h0 f2 % Vale.Curve25519.Fast_defs.prime) % Vale.Curve25519.Fast_defs.prime in
let a2 = (as_nat h0 f1 % Vale.Curve25519.Fast_defs.prime - as_nat h0 f2) % Vale.Curve25519.Fast_defs.prime in
let a3 = (as_nat h0 f1 - as_nat h0 f2) % Vale.Curve25519.Fast_defs.prime in
let b = (FA.as_nat f1 h0 - FA.as_nat f2 h0) % Vale.Curve25519.Fast_defs.prime in
calc (==) {
a;
== { }
a1;
== { FStar.Math.Lemmas.lemma_mod_sub_distr (as_nat h0 f1 % Vale.Curve25519.Fast_defs.prime) (as_nat h0 f2)
Vale.Curve25519.Fast_defs.prime }
a2;
== { FStar.Math.Lemmas.lemma_mod_add_distr (- as_nat h0 f2) (as_nat h0 f1) Vale.Curve25519.Fast_defs.prime }
a3;
== { }
b;
}
in aux();
if EverCrypt.TargetConfig.hacl_can_compile_inline_asm then
Vale.Inline.X64.Fadd_inline.fsub out f1 f2
else
Vale.Wrapper.X64.Fsub.fsub_e out f1 f2
#push-options "--z3rlimit 200"
let lemma_fmul_equiv (h0:HS.mem) (f1 f2:F64.u256) : Lemma
(P.fmul (F64.fevalh h0 f1) (F64.fevalh h0 f2) == (FA.as_nat f1 h0 * FA.as_nat f2 h0) % Vale.Curve25519.Fast_defs.prime)
= let a = P.fmul (F64.fevalh h0 f1) (F64.fevalh h0 f2) in
let a1 = ((F64.as_nat h0 f1 % Vale.Curve25519.Fast_defs.prime) * (F64.as_nat h0 f2 % Vale.Curve25519.Fast_defs.prime)) % Vale.Curve25519.Fast_defs.prime in
let a2 = ((F64.as_nat h0 f1 % Vale.Curve25519.Fast_defs.prime) * F64.as_nat h0 f2) % Vale.Curve25519.Fast_defs.prime in
let a3 = (F64.as_nat h0 f1 * F64.as_nat h0 f2) % Vale.Curve25519.Fast_defs.prime in
let b = (FA.as_nat f1 h0 * FA.as_nat f2 h0) % Vale.Curve25519.Fast_defs.prime in
calc (==) {
a;
== { }
a1;
== { FStar.Math.Lemmas.lemma_mod_mul_distr_r (F64.as_nat h0 f1 % Vale.Curve25519.Fast_defs.prime) (F64.as_nat h0 f2) Vale.Curve25519.Fast_defs.prime }
a2;
== { FStar.Math.Lemmas.lemma_mod_mul_distr_l (F64.as_nat h0 f1) (F64.as_nat h0 f2) Vale.Curve25519.Fast_defs.prime }
a3;
== { }
b;
}
#pop-options
[@ CInline]
let fmul out f1 f2 tmp =
let h0 = ST.get() in
lemma_fmul_equiv h0 f1 f2;
if EverCrypt.TargetConfig.hacl_can_compile_inline_asm then (
assert (disjoint f1 (gsub tmp 0ul 8ul));
assert (disjoint f2 (gsub tmp 0ul 8ul));
Vale.Inline.X64.Fmul_inline.fmul out f1 f2 (sub tmp 0ul 8ul)
) else
Vale.Wrapper.X64.Fmul.fmul_e (sub tmp 0ul 8ul) f1 out f2
#push-options "--z3rlimit 500" | false | true | Hacl.Impl.Curve25519.Field64.Vale.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": true,
"z3rlimit": 500,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val fmul2: fmul2_t M64 p | [] | Hacl.Impl.Curve25519.Field64.Vale.fmul2 | {
"file_name": "code/curve25519/Hacl.Impl.Curve25519.Field64.Vale.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | Hacl.Impl.Curve25519.Fields.Core.fmul2_t Hacl.Impl.Curve25519.Fields.Core.M64
Hacl.Impl.Curve25519.Field64.Vale.p | {
"end_col": 47,
"end_line": 156,
"start_col": 25,
"start_line": 149
} |
Prims.Tot | val compute_merge_total (f0:fuel) (fM:fuel) : fuel | [
{
"abbrev": true,
"full_module": "Vale.X64.Memory",
"short_module": "ME"
},
{
"abbrev": false,
"full_module": "Vale.X64.Instruction_s",
"short_module": null
},
{
"abbrev": true,
"full_module": "Vale.Lib.Map16",
"short_module": "Map16"
},
{
"abbrev": true,
"full_module": "Vale.X64.Machine_Semantics_s",
"short_module": "BS"
},
{
"abbrev": false,
"full_module": "Vale.X64.Bytes_Code_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.StateLemmas",
"short_module": null
},
{
"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.HeapLemmas",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.HeapImpl",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Heap",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"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 compute_merge_total (f0:fuel) (fM:fuel) =
if f0 > fM then f0 else fM | val compute_merge_total (f0:fuel) (fM:fuel) : fuel
let compute_merge_total (f0 fM: fuel) = | false | null | false | if f0 > fM then f0 else fM | {
"checked_file": "Vale.X64.Lemmas.fst.checked",
"dependencies": [
"Vale.X64.StateLemmas.fsti.checked",
"Vale.X64.State.fsti.checked",
"Vale.X64.Memory.fsti.checked",
"Vale.X64.Machine_Semantics_s.fst.checked",
"Vale.X64.Machine_s.fst.checked",
"Vale.X64.Instruction_s.fsti.checked",
"Vale.X64.Flags.fsti.checked",
"Vale.X64.Bytes_Code_s.fst.checked",
"prims.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.FunctionalExtensionality.fsti.checked"
],
"interface_file": true,
"source_file": "Vale.X64.Lemmas.fst"
} | [
"total"
] | [
"Vale.X64.Lemmas.fuel",
"Prims.op_GreaterThan",
"Prims.bool"
] | [] | module Vale.X64.Lemmas
open FStar.Mul
open Vale.X64.Machine_s
open Vale.X64.State
open Vale.X64.StateLemmas
open Vale.X64.Instruction_s
open Vale.X64.Bytes_Code_s
module BS = Vale.X64.Machine_Semantics_s
module ME = Vale.X64.Memory
#reset-options "--initial_fuel 1 --max_fuel 1 --z3rlimit 100"
#restart-solver
let rec lemma_eq_instr_apply_eval_args
(outs:list instr_out) (args:list instr_operand)
(f:instr_args_t outs args) (oprs:instr_operands_t_args args) (s1 s2:machine_state)
: Lemma
(requires state_eq_S true s1 s2)
(ensures
BS.instr_apply_eval_args outs args f oprs s1 ==
BS.instr_apply_eval_args outs args f oprs s2)
=
let open BS in
lemma_heap_ignore_ghost_machine s1.BS.ms_heap s2.BS.ms_heap;
match args with
| [] -> ()
| i::args ->
(
let (v, oprs) : option (instr_val_t i) & instr_operands_t_args args =
match i with
| IOpEx i -> let oprs = coerce oprs in (instr_eval_operand_explicit i (fst oprs) s1, snd oprs)
| IOpIm i -> (instr_eval_operand_implicit i s1, coerce oprs)
in
let f:arrow (instr_val_t i) (instr_args_t outs args) = coerce f in
match v with
| None -> ()
| Some v -> lemma_eq_instr_apply_eval_args outs args (f v) oprs s1 s2
)
#restart-solver
let rec lemma_eq_instr_apply_eval_inouts
(outs inouts:list instr_out) (args:list instr_operand)
(f:instr_inouts_t outs inouts args) (oprs:instr_operands_t inouts args) (s1 s2:machine_state)
: Lemma
(requires state_eq_S true s1 s2)
(ensures
BS.instr_apply_eval_inouts outs inouts args f oprs s1 ==
BS.instr_apply_eval_inouts outs inouts args f oprs s2)
=
let open BS in
lemma_heap_ignore_ghost_machine s1.BS.ms_heap s2.BS.ms_heap;
match inouts with
| [] -> lemma_eq_instr_apply_eval_args outs args f oprs s1 s2
| (Out, i)::inouts ->
let oprs =
match i with
| IOpEx i -> snd #(instr_operand_t i) (coerce oprs)
| IOpIm i -> coerce oprs
in
lemma_eq_instr_apply_eval_inouts outs inouts args (coerce f) oprs s1 s2
| (InOut, i)::inouts ->
(
let (v, oprs) : option (instr_val_t i) & instr_operands_t inouts args =
match i with
| IOpEx i -> let oprs = coerce oprs in (instr_eval_operand_explicit i (fst oprs) s1, snd oprs)
| IOpIm i -> (instr_eval_operand_implicit i s1, coerce oprs)
in
let f:arrow (instr_val_t i) (instr_inouts_t outs inouts args) = coerce f in
match v with
| None -> ()
| Some v -> lemma_eq_instr_apply_eval_inouts outs inouts args (f v) oprs s1 s2
)
#restart-solver
#push-options "--z3rlimit_factor 2"
let rec lemma_eq_instr_write_outputs
(outs:list instr_out) (args:list instr_operand)
(vs:instr_ret_t outs) (oprs:instr_operands_t outs args) (s1_orig s1 s2_orig s2:machine_state)
: Lemma
(requires state_eq_S true s1_orig s2_orig /\ state_eq_S true s1 s2)
(ensures
state_eq_S true
(BS.instr_write_outputs outs args vs oprs s1_orig s1)
(BS.instr_write_outputs outs args vs oprs s2_orig s2))
=
let open BS in
use_machine_state_equal ();
lemma_heap_ignore_ghost_machine s1.BS.ms_heap s2.BS.ms_heap;
lemma_heap_ignore_ghost_machine s1_orig.BS.ms_heap s2_orig.BS.ms_heap;
allow_inversion tmaddr;
match outs with
| [] -> ()
| (_, i)::outs ->
(
let ((v:instr_val_t i), (vs:instr_ret_t outs)) =
match outs with
| [] -> (vs, ())
| _::_ -> let vs = coerce vs in (fst vs, snd vs)
in
match i with
| IOpEx i ->
let oprs = coerce oprs in
let s1 = instr_write_output_explicit i v (fst oprs) s1_orig s1 in
let s2 = instr_write_output_explicit i v (fst oprs) s2_orig s2 in
lemma_eq_instr_write_outputs outs args vs (snd oprs) s1_orig s1 s2_orig s2
| IOpIm i ->
let s1 = instr_write_output_implicit i v s1_orig s1 in
let s2 = instr_write_output_implicit i v s2_orig s2 in
allow_inversion operand64;
allow_inversion operand128;
lemma_eq_instr_write_outputs outs args vs (coerce oprs) s1_orig s1 s2_orig s2
)
#pop-options
#restart-solver
let eval_ins_eq_instr (inst:BS.ins) (s1 s2:machine_state) : Lemma
(requires Instr? inst /\ state_eq_S true s1 s2)
(ensures state_eq_S true (BS.machine_eval_ins inst s1) (BS.machine_eval_ins inst s2))
=
let open BS in
let Instr it oprs ann = inst in
let InstrTypeRecord #outs #args #havoc_flags' i = it in
lemma_eq_instr_apply_eval_inouts outs outs args (instr_eval i) oprs s1 s2;
let vs = instr_apply_eval outs args (instr_eval i) oprs s1 in
let hav s =
match havoc_flags' with
| HavocFlags -> {s with ms_flags = havoc_flags}
| PreserveFlags -> s
in
let s1' = hav s1 in
let s2' = hav s2 in
match vs with
| None -> ()
| Some vs -> lemma_eq_instr_write_outputs outs args vs oprs s1 s1' s2 s2'
let eval_code_eq_instr (inst:BS.ins) (f:fuel) (s1 s2:machine_state) : Lemma
(requires Instr? inst /\ state_eq_S true s1 s2)
(ensures state_eq_opt true (BS.machine_eval_code (Ins inst) f s1) (BS.machine_eval_code (Ins inst) f s2))
=
reveal_opaque (`%BS.machine_eval_code_ins) BS.machine_eval_code_ins;
eval_ins_eq_instr inst ({s1 with BS.ms_trace = []}) ({s2 with BS.ms_trace = []})
let eval_code_eq_dealloc (inst:BS.ins) (f:fuel) (s1 s2:machine_state) : Lemma
(requires Dealloc? inst /\ state_eq_S true s1 s2)
(ensures state_eq_opt true (BS.machine_eval_code (Ins inst) f s1) (BS.machine_eval_code (Ins inst) f s2))
=
reveal_opaque (`%BS.machine_eval_code_ins) BS.machine_eval_code_ins;
use_machine_state_equal ();
lemma_heap_ignore_ghost_machine s1.BS.ms_heap s2.BS.ms_heap;
allow_inversion tmaddr
let eval_code_eq_alloc (inst:BS.ins) (f:fuel) (s1 s2:machine_state) : Lemma
(requires Alloc? inst /\ state_eq_S true s1 s2)
(ensures state_eq_opt true (BS.machine_eval_code (Ins inst) f s1) (BS.machine_eval_code (Ins inst) f s2))
=
reveal_opaque (`%BS.machine_eval_code_ins) BS.machine_eval_code_ins;
use_machine_state_equal ();
lemma_heap_ignore_ghost_machine s1.BS.ms_heap s2.BS.ms_heap;
allow_inversion tmaddr
let eval_code_eq_push (inst:BS.ins) (f:fuel) (s1 s2:machine_state) : Lemma
(requires Push? inst /\ state_eq_S true s1 s2)
(ensures state_eq_opt true (BS.machine_eval_code (Ins inst) f s1) (BS.machine_eval_code (Ins inst) f s2))
=
reveal_opaque (`%BS.machine_eval_code_ins) BS.machine_eval_code_ins;
use_machine_state_equal ();
lemma_heap_ignore_ghost_machine s1.BS.ms_heap s2.BS.ms_heap;
allow_inversion tmaddr
let eval_code_eq_pop (inst:BS.ins) (f:fuel) (s1 s2:machine_state) : Lemma
(requires Pop? inst /\ state_eq_S true s1 s2)
(ensures state_eq_opt true (BS.machine_eval_code (Ins inst) f s1) (BS.machine_eval_code (Ins inst) f s2))
=
reveal_opaque (`%BS.machine_eval_code_ins) BS.machine_eval_code_ins;
use_machine_state_equal ();
lemma_heap_ignore_ghost_machine s1.BS.ms_heap s2.BS.ms_heap;
allow_inversion tmaddr
let eval_code_eq_ins (i:BS.ins) (f:fuel) (s1 s2:machine_state) : Lemma
(requires state_eq_S true s1 s2)
(ensures state_eq_opt true (BS.machine_eval_code (Ins i) f s1) (BS.machine_eval_code (Ins i) f s2))
=
match i with
| Instr _ _ _ -> eval_code_eq_instr i f s1 s2
| Dealloc _ -> eval_code_eq_dealloc i f s1 s2
| Alloc _ -> eval_code_eq_alloc i f s1 s2
| Push _ _ -> eval_code_eq_push i f s1 s2
| Pop _ _ -> eval_code_eq_pop i f s1 s2
#reset-options "--fuel 2 --z3rlimit 30"
let eval_ocmp_eq_core (g:bool) (cond:ocmp) (s:machine_state) : Lemma
(ensures (
let (s1, b1) = BS.machine_eval_ocmp s cond in
let (s2, b2) = BS.machine_eval_ocmp (core_state g s) cond in
state_eq_S g s1 s2 /\ b1 == b2
))
=
reveal_opaque (`%BS.valid_ocmp_opaque) BS.valid_ocmp_opaque;
reveal_opaque (`%BS.eval_ocmp_opaque) BS.eval_ocmp_opaque;
()
#restart-solver
let rec eval_code_eq_core (g:bool) (c:code) (f:fuel) (s:machine_state) : Lemma
(ensures state_eq_opt g (BS.machine_eval_code c f s) (BS.machine_eval_code c f (core_state g s)))
(decreases %[f; c])
=
match c with
| Ins i ->
reveal_opaque (`%BS.machine_eval_code_ins) BS.machine_eval_code_ins;
if g then eval_code_eq_ins i f s (core_state g s)
| Block cs -> eval_codes_eq_core g cs f s
| IfElse cond ct cf ->
eval_ocmp_eq_core g cond s;
let (s', _) = BS.machine_eval_ocmp s cond in
let (t', _) = BS.machine_eval_ocmp (core_state g s) cond in
eval_code_eq_core g ct f s';
eval_code_eq_core g ct f t';
eval_code_eq_core g cf f s';
eval_code_eq_core g cf f t';
()
| While cond body -> eval_while_eq_core g cond body f s
and eval_codes_eq_core (g:bool) (cs:codes) (f:fuel) (s:machine_state) : Lemma
(ensures state_eq_opt g (BS.machine_eval_codes cs f s) (BS.machine_eval_codes cs f (core_state g s)))
(decreases %[f; cs])
=
match cs with
| [] -> ()
| c'::cs' -> (
eval_code_eq_core g c' f s;
match (machine_eval_code c' f s, machine_eval_code c' f (core_state g s)) with
| (None, None) -> ()
| (Some s', Some t') -> eval_codes_eq_core g cs' f s'; eval_codes_eq_core g cs' f t'
)
and eval_while_eq_core (g:bool) (cond:ocmp) (body:code) (f:fuel) (s:machine_state) : Lemma
(ensures state_eq_opt g (BS.machine_eval_while cond body f s) (BS.machine_eval_while cond body f (core_state g s)))
(decreases %[f; body])
=
if f > 0 then (
eval_ocmp_eq_core g cond s;
let (s1, _) = BS.machine_eval_ocmp s cond in
let (t1, _) = BS.machine_eval_ocmp (core_state g s) cond in
eval_code_eq_core g body (f - 1) s1;
eval_code_eq_core g body (f - 1) t1;
match (BS.machine_eval_code body (f - 1) s1, BS.machine_eval_code body (f - 1) t1) with
| (None, None) -> ()
| (Some s2, Some t2) ->
eval_while_eq_core g cond body (f - 1) s2;
eval_while_eq_core g cond body (f - 1) t2;
()
)
let eval_code_eq_f (c:code) (f:fuel) (s1 s2:machine_state) : Lemma
(requires state_eq_S false s1 s2)
(ensures state_eq_opt false (BS.machine_eval_code c f s1) (BS.machine_eval_code c f s2))
[SMTPat (BS.machine_eval_code c f s1); SMTPat (BS.machine_eval_code c f s2)]
=
eval_code_eq_core false c f s1; eval_code_eq_core false c f s2
let eval_codes_eq_f (cs:codes) (f:fuel) (s1 s2:machine_state) : Lemma
(requires state_eq_S false s1 s2)
(ensures state_eq_opt false (BS.machine_eval_codes cs f s1) (BS.machine_eval_codes cs f s2))
[SMTPat (BS.machine_eval_codes cs f s1); SMTPat (BS.machine_eval_codes cs f s2)]
=
eval_codes_eq_core false cs f s1; eval_codes_eq_core false cs f s2
let eval_while_eq_f (cond:ocmp) (body:code) (f:fuel) (s1 s2:machine_state) : Lemma
(requires state_eq_S false s1 s2)
(ensures state_eq_opt false (BS.machine_eval_while cond body f s1) (BS.machine_eval_while cond body f s2))
[SMTPat (BS.machine_eval_while cond body f s1); SMTPat (BS.machine_eval_while cond body f s2)]
=
eval_while_eq_core false cond body f s1; eval_while_eq_core false cond body f s2
let eval_code_eq_t (c:code) (f:fuel) (s1 s2:machine_state) : Lemma
(requires state_eq_S true s1 s2)
(ensures state_eq_opt true (BS.machine_eval_code c f s1) (BS.machine_eval_code c f s2))
[SMTPat (BS.machine_eval_code c f s1); SMTPat (BS.machine_eval_code c f s2)]
=
eval_code_eq_core true c f s1; eval_code_eq_core true c f s2
let eval_codes_eq_t (cs:codes) (f:fuel) (s1 s2:machine_state) : Lemma
(requires state_eq_S true s1 s2)
(ensures state_eq_opt true (BS.machine_eval_codes cs f s1) (BS.machine_eval_codes cs f s2))
[SMTPat (BS.machine_eval_codes cs f s1); SMTPat (BS.machine_eval_codes cs f s2)]
=
eval_codes_eq_core true cs f s1; eval_codes_eq_core true cs f s2
let eval_while_eq_t (cond:ocmp) (body:code) (f:fuel) (s1 s2:machine_state) : Lemma
(requires state_eq_S true s1 s2)
(ensures state_eq_opt true (BS.machine_eval_while cond body f s1) (BS.machine_eval_while cond body f s2))
[SMTPat (BS.machine_eval_while cond body f s1); SMTPat (BS.machine_eval_while cond body f s2)]
=
eval_while_eq_core true cond body f s1; eval_while_eq_core true cond body f s2
let eval_code_ts (g:bool) (c:code) (s0:machine_state) (f0:fuel) (s1:machine_state) : Type0 =
state_eq_opt g (BS.machine_eval_code c f0 s0) (Some s1)
let rec increase_fuel (g:bool) (c:code) (s0:machine_state) (f0:fuel) (sN:machine_state) (fN:fuel) : Lemma
(requires eval_code_ts g c s0 f0 sN /\ f0 <= fN)
(ensures eval_code_ts g c s0 fN sN)
(decreases %[f0; c])
=
match c with
| Ins ins -> ()
| Block l -> increase_fuels g l s0 f0 sN fN
| IfElse cond t f ->
let (s0, b0) = BS.machine_eval_ocmp s0 cond in
if b0 then increase_fuel g t s0 f0 sN fN else increase_fuel g f s0 f0 sN fN
| While cond c ->
let (s1, b0) = BS.machine_eval_ocmp s0 cond in
if b0 then (
match BS.machine_eval_code c (f0 - 1) s1 with
| None -> ()
| Some s2 ->
increase_fuel g c s1 (f0 - 1) s2 (fN - 1);
if s2.BS.ms_ok then increase_fuel g (While cond c) s2 (f0 - 1) sN (fN - 1)
else ()
)
and increase_fuels (g:bool) (c:codes) (s0:machine_state) (f0:fuel) (sN:machine_state) (fN:fuel) : Lemma
(requires eval_code_ts g (Block c) s0 f0 sN /\ f0 <= fN)
(ensures eval_code_ts g (Block c) s0 fN sN)
(decreases %[f0; c])
=
match c with
| [] -> ()
| h::t ->
(
let Some s1 = BS.machine_eval_code h f0 s0 in
increase_fuel g h s0 f0 s1 fN;
increase_fuels g t s1 f0 sN fN
)
let lemma_cmp_eq s o1 o2 = reveal_opaque (`%BS.eval_ocmp_opaque) BS.eval_ocmp_opaque
let lemma_cmp_ne s o1 o2 = reveal_opaque (`%BS.eval_ocmp_opaque) BS.eval_ocmp_opaque
let lemma_cmp_le s o1 o2 = reveal_opaque (`%BS.eval_ocmp_opaque) BS.eval_ocmp_opaque
let lemma_cmp_ge s o1 o2 = reveal_opaque (`%BS.eval_ocmp_opaque) BS.eval_ocmp_opaque
let lemma_cmp_lt s o1 o2 = reveal_opaque (`%BS.eval_ocmp_opaque) BS.eval_ocmp_opaque
let lemma_cmp_gt s o1 o2 = reveal_opaque (`%BS.eval_ocmp_opaque) BS.eval_ocmp_opaque
let lemma_valid_cmp_eq s o1 o2 = ()
let lemma_valid_cmp_ne s o1 o2 = ()
let lemma_valid_cmp_le s o1 o2 = ()
let lemma_valid_cmp_ge s o1 o2 = ()
let lemma_valid_cmp_lt s o1 o2 = ()
let lemma_valid_cmp_gt s o1 o2 = () | false | true | Vale.X64.Lemmas.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": 30,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val compute_merge_total (f0:fuel) (fM:fuel) : fuel | [] | Vale.X64.Lemmas.compute_merge_total | {
"file_name": "vale/code/arch/x64/Vale.X64.Lemmas.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | f0: Vale.X64.Lemmas.fuel -> fM: Vale.X64.Lemmas.fuel -> Vale.X64.Lemmas.fuel | {
"end_col": 28,
"end_line": 348,
"start_col": 2,
"start_line": 348
} |
Prims.Tot | val eval_code_ts (g: bool) (c: code) (s0: machine_state) (f0: fuel) (s1: machine_state) : Type0 | [
{
"abbrev": true,
"full_module": "Vale.X64.Memory",
"short_module": "ME"
},
{
"abbrev": true,
"full_module": "Vale.X64.Machine_Semantics_s",
"short_module": "BS"
},
{
"abbrev": false,
"full_module": "Vale.X64.Bytes_Code_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Instruction_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.StateLemmas",
"short_module": null
},
{
"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": "FStar.Mul",
"short_module": null
},
{
"abbrev": true,
"full_module": "Vale.Lib.Map16",
"short_module": "Map16"
},
{
"abbrev": true,
"full_module": "Vale.X64.Machine_Semantics_s",
"short_module": "BS"
},
{
"abbrev": false,
"full_module": "Vale.X64.Bytes_Code_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.StateLemmas",
"short_module": null
},
{
"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.HeapLemmas",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.HeapImpl",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Heap",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"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 eval_code_ts (g:bool) (c:code) (s0:machine_state) (f0:fuel) (s1:machine_state) : Type0 =
state_eq_opt g (BS.machine_eval_code c f0 s0) (Some s1) | val eval_code_ts (g: bool) (c: code) (s0: machine_state) (f0: fuel) (s1: machine_state) : Type0
let eval_code_ts (g: bool) (c: code) (s0: machine_state) (f0: fuel) (s1: machine_state) : Type0 = | false | null | false | state_eq_opt g (BS.machine_eval_code c f0 s0) (Some s1) | {
"checked_file": "Vale.X64.Lemmas.fst.checked",
"dependencies": [
"Vale.X64.StateLemmas.fsti.checked",
"Vale.X64.State.fsti.checked",
"Vale.X64.Memory.fsti.checked",
"Vale.X64.Machine_Semantics_s.fst.checked",
"Vale.X64.Machine_s.fst.checked",
"Vale.X64.Instruction_s.fsti.checked",
"Vale.X64.Flags.fsti.checked",
"Vale.X64.Bytes_Code_s.fst.checked",
"prims.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.FunctionalExtensionality.fsti.checked"
],
"interface_file": true,
"source_file": "Vale.X64.Lemmas.fst"
} | [
"total"
] | [
"Prims.bool",
"Vale.X64.StateLemmas.code",
"Vale.X64.StateLemmas.machine_state",
"Vale.X64.Lemmas.fuel",
"Vale.X64.Lemmas.state_eq_opt",
"Vale.X64.Machine_Semantics_s.machine_eval_code",
"FStar.Pervasives.Native.Some",
"Vale.X64.Machine_Semantics_s.machine_state"
] | [] | module Vale.X64.Lemmas
open FStar.Mul
open Vale.X64.Machine_s
open Vale.X64.State
open Vale.X64.StateLemmas
open Vale.X64.Instruction_s
open Vale.X64.Bytes_Code_s
module BS = Vale.X64.Machine_Semantics_s
module ME = Vale.X64.Memory
#reset-options "--initial_fuel 1 --max_fuel 1 --z3rlimit 100"
#restart-solver
let rec lemma_eq_instr_apply_eval_args
(outs:list instr_out) (args:list instr_operand)
(f:instr_args_t outs args) (oprs:instr_operands_t_args args) (s1 s2:machine_state)
: Lemma
(requires state_eq_S true s1 s2)
(ensures
BS.instr_apply_eval_args outs args f oprs s1 ==
BS.instr_apply_eval_args outs args f oprs s2)
=
let open BS in
lemma_heap_ignore_ghost_machine s1.BS.ms_heap s2.BS.ms_heap;
match args with
| [] -> ()
| i::args ->
(
let (v, oprs) : option (instr_val_t i) & instr_operands_t_args args =
match i with
| IOpEx i -> let oprs = coerce oprs in (instr_eval_operand_explicit i (fst oprs) s1, snd oprs)
| IOpIm i -> (instr_eval_operand_implicit i s1, coerce oprs)
in
let f:arrow (instr_val_t i) (instr_args_t outs args) = coerce f in
match v with
| None -> ()
| Some v -> lemma_eq_instr_apply_eval_args outs args (f v) oprs s1 s2
)
#restart-solver
let rec lemma_eq_instr_apply_eval_inouts
(outs inouts:list instr_out) (args:list instr_operand)
(f:instr_inouts_t outs inouts args) (oprs:instr_operands_t inouts args) (s1 s2:machine_state)
: Lemma
(requires state_eq_S true s1 s2)
(ensures
BS.instr_apply_eval_inouts outs inouts args f oprs s1 ==
BS.instr_apply_eval_inouts outs inouts args f oprs s2)
=
let open BS in
lemma_heap_ignore_ghost_machine s1.BS.ms_heap s2.BS.ms_heap;
match inouts with
| [] -> lemma_eq_instr_apply_eval_args outs args f oprs s1 s2
| (Out, i)::inouts ->
let oprs =
match i with
| IOpEx i -> snd #(instr_operand_t i) (coerce oprs)
| IOpIm i -> coerce oprs
in
lemma_eq_instr_apply_eval_inouts outs inouts args (coerce f) oprs s1 s2
| (InOut, i)::inouts ->
(
let (v, oprs) : option (instr_val_t i) & instr_operands_t inouts args =
match i with
| IOpEx i -> let oprs = coerce oprs in (instr_eval_operand_explicit i (fst oprs) s1, snd oprs)
| IOpIm i -> (instr_eval_operand_implicit i s1, coerce oprs)
in
let f:arrow (instr_val_t i) (instr_inouts_t outs inouts args) = coerce f in
match v with
| None -> ()
| Some v -> lemma_eq_instr_apply_eval_inouts outs inouts args (f v) oprs s1 s2
)
#restart-solver
#push-options "--z3rlimit_factor 2"
let rec lemma_eq_instr_write_outputs
(outs:list instr_out) (args:list instr_operand)
(vs:instr_ret_t outs) (oprs:instr_operands_t outs args) (s1_orig s1 s2_orig s2:machine_state)
: Lemma
(requires state_eq_S true s1_orig s2_orig /\ state_eq_S true s1 s2)
(ensures
state_eq_S true
(BS.instr_write_outputs outs args vs oprs s1_orig s1)
(BS.instr_write_outputs outs args vs oprs s2_orig s2))
=
let open BS in
use_machine_state_equal ();
lemma_heap_ignore_ghost_machine s1.BS.ms_heap s2.BS.ms_heap;
lemma_heap_ignore_ghost_machine s1_orig.BS.ms_heap s2_orig.BS.ms_heap;
allow_inversion tmaddr;
match outs with
| [] -> ()
| (_, i)::outs ->
(
let ((v:instr_val_t i), (vs:instr_ret_t outs)) =
match outs with
| [] -> (vs, ())
| _::_ -> let vs = coerce vs in (fst vs, snd vs)
in
match i with
| IOpEx i ->
let oprs = coerce oprs in
let s1 = instr_write_output_explicit i v (fst oprs) s1_orig s1 in
let s2 = instr_write_output_explicit i v (fst oprs) s2_orig s2 in
lemma_eq_instr_write_outputs outs args vs (snd oprs) s1_orig s1 s2_orig s2
| IOpIm i ->
let s1 = instr_write_output_implicit i v s1_orig s1 in
let s2 = instr_write_output_implicit i v s2_orig s2 in
allow_inversion operand64;
allow_inversion operand128;
lemma_eq_instr_write_outputs outs args vs (coerce oprs) s1_orig s1 s2_orig s2
)
#pop-options
#restart-solver
let eval_ins_eq_instr (inst:BS.ins) (s1 s2:machine_state) : Lemma
(requires Instr? inst /\ state_eq_S true s1 s2)
(ensures state_eq_S true (BS.machine_eval_ins inst s1) (BS.machine_eval_ins inst s2))
=
let open BS in
let Instr it oprs ann = inst in
let InstrTypeRecord #outs #args #havoc_flags' i = it in
lemma_eq_instr_apply_eval_inouts outs outs args (instr_eval i) oprs s1 s2;
let vs = instr_apply_eval outs args (instr_eval i) oprs s1 in
let hav s =
match havoc_flags' with
| HavocFlags -> {s with ms_flags = havoc_flags}
| PreserveFlags -> s
in
let s1' = hav s1 in
let s2' = hav s2 in
match vs with
| None -> ()
| Some vs -> lemma_eq_instr_write_outputs outs args vs oprs s1 s1' s2 s2'
let eval_code_eq_instr (inst:BS.ins) (f:fuel) (s1 s2:machine_state) : Lemma
(requires Instr? inst /\ state_eq_S true s1 s2)
(ensures state_eq_opt true (BS.machine_eval_code (Ins inst) f s1) (BS.machine_eval_code (Ins inst) f s2))
=
reveal_opaque (`%BS.machine_eval_code_ins) BS.machine_eval_code_ins;
eval_ins_eq_instr inst ({s1 with BS.ms_trace = []}) ({s2 with BS.ms_trace = []})
let eval_code_eq_dealloc (inst:BS.ins) (f:fuel) (s1 s2:machine_state) : Lemma
(requires Dealloc? inst /\ state_eq_S true s1 s2)
(ensures state_eq_opt true (BS.machine_eval_code (Ins inst) f s1) (BS.machine_eval_code (Ins inst) f s2))
=
reveal_opaque (`%BS.machine_eval_code_ins) BS.machine_eval_code_ins;
use_machine_state_equal ();
lemma_heap_ignore_ghost_machine s1.BS.ms_heap s2.BS.ms_heap;
allow_inversion tmaddr
let eval_code_eq_alloc (inst:BS.ins) (f:fuel) (s1 s2:machine_state) : Lemma
(requires Alloc? inst /\ state_eq_S true s1 s2)
(ensures state_eq_opt true (BS.machine_eval_code (Ins inst) f s1) (BS.machine_eval_code (Ins inst) f s2))
=
reveal_opaque (`%BS.machine_eval_code_ins) BS.machine_eval_code_ins;
use_machine_state_equal ();
lemma_heap_ignore_ghost_machine s1.BS.ms_heap s2.BS.ms_heap;
allow_inversion tmaddr
let eval_code_eq_push (inst:BS.ins) (f:fuel) (s1 s2:machine_state) : Lemma
(requires Push? inst /\ state_eq_S true s1 s2)
(ensures state_eq_opt true (BS.machine_eval_code (Ins inst) f s1) (BS.machine_eval_code (Ins inst) f s2))
=
reveal_opaque (`%BS.machine_eval_code_ins) BS.machine_eval_code_ins;
use_machine_state_equal ();
lemma_heap_ignore_ghost_machine s1.BS.ms_heap s2.BS.ms_heap;
allow_inversion tmaddr
let eval_code_eq_pop (inst:BS.ins) (f:fuel) (s1 s2:machine_state) : Lemma
(requires Pop? inst /\ state_eq_S true s1 s2)
(ensures state_eq_opt true (BS.machine_eval_code (Ins inst) f s1) (BS.machine_eval_code (Ins inst) f s2))
=
reveal_opaque (`%BS.machine_eval_code_ins) BS.machine_eval_code_ins;
use_machine_state_equal ();
lemma_heap_ignore_ghost_machine s1.BS.ms_heap s2.BS.ms_heap;
allow_inversion tmaddr
let eval_code_eq_ins (i:BS.ins) (f:fuel) (s1 s2:machine_state) : Lemma
(requires state_eq_S true s1 s2)
(ensures state_eq_opt true (BS.machine_eval_code (Ins i) f s1) (BS.machine_eval_code (Ins i) f s2))
=
match i with
| Instr _ _ _ -> eval_code_eq_instr i f s1 s2
| Dealloc _ -> eval_code_eq_dealloc i f s1 s2
| Alloc _ -> eval_code_eq_alloc i f s1 s2
| Push _ _ -> eval_code_eq_push i f s1 s2
| Pop _ _ -> eval_code_eq_pop i f s1 s2
#reset-options "--fuel 2 --z3rlimit 30"
let eval_ocmp_eq_core (g:bool) (cond:ocmp) (s:machine_state) : Lemma
(ensures (
let (s1, b1) = BS.machine_eval_ocmp s cond in
let (s2, b2) = BS.machine_eval_ocmp (core_state g s) cond in
state_eq_S g s1 s2 /\ b1 == b2
))
=
reveal_opaque (`%BS.valid_ocmp_opaque) BS.valid_ocmp_opaque;
reveal_opaque (`%BS.eval_ocmp_opaque) BS.eval_ocmp_opaque;
()
#restart-solver
let rec eval_code_eq_core (g:bool) (c:code) (f:fuel) (s:machine_state) : Lemma
(ensures state_eq_opt g (BS.machine_eval_code c f s) (BS.machine_eval_code c f (core_state g s)))
(decreases %[f; c])
=
match c with
| Ins i ->
reveal_opaque (`%BS.machine_eval_code_ins) BS.machine_eval_code_ins;
if g then eval_code_eq_ins i f s (core_state g s)
| Block cs -> eval_codes_eq_core g cs f s
| IfElse cond ct cf ->
eval_ocmp_eq_core g cond s;
let (s', _) = BS.machine_eval_ocmp s cond in
let (t', _) = BS.machine_eval_ocmp (core_state g s) cond in
eval_code_eq_core g ct f s';
eval_code_eq_core g ct f t';
eval_code_eq_core g cf f s';
eval_code_eq_core g cf f t';
()
| While cond body -> eval_while_eq_core g cond body f s
and eval_codes_eq_core (g:bool) (cs:codes) (f:fuel) (s:machine_state) : Lemma
(ensures state_eq_opt g (BS.machine_eval_codes cs f s) (BS.machine_eval_codes cs f (core_state g s)))
(decreases %[f; cs])
=
match cs with
| [] -> ()
| c'::cs' -> (
eval_code_eq_core g c' f s;
match (machine_eval_code c' f s, machine_eval_code c' f (core_state g s)) with
| (None, None) -> ()
| (Some s', Some t') -> eval_codes_eq_core g cs' f s'; eval_codes_eq_core g cs' f t'
)
and eval_while_eq_core (g:bool) (cond:ocmp) (body:code) (f:fuel) (s:machine_state) : Lemma
(ensures state_eq_opt g (BS.machine_eval_while cond body f s) (BS.machine_eval_while cond body f (core_state g s)))
(decreases %[f; body])
=
if f > 0 then (
eval_ocmp_eq_core g cond s;
let (s1, _) = BS.machine_eval_ocmp s cond in
let (t1, _) = BS.machine_eval_ocmp (core_state g s) cond in
eval_code_eq_core g body (f - 1) s1;
eval_code_eq_core g body (f - 1) t1;
match (BS.machine_eval_code body (f - 1) s1, BS.machine_eval_code body (f - 1) t1) with
| (None, None) -> ()
| (Some s2, Some t2) ->
eval_while_eq_core g cond body (f - 1) s2;
eval_while_eq_core g cond body (f - 1) t2;
()
)
let eval_code_eq_f (c:code) (f:fuel) (s1 s2:machine_state) : Lemma
(requires state_eq_S false s1 s2)
(ensures state_eq_opt false (BS.machine_eval_code c f s1) (BS.machine_eval_code c f s2))
[SMTPat (BS.machine_eval_code c f s1); SMTPat (BS.machine_eval_code c f s2)]
=
eval_code_eq_core false c f s1; eval_code_eq_core false c f s2
let eval_codes_eq_f (cs:codes) (f:fuel) (s1 s2:machine_state) : Lemma
(requires state_eq_S false s1 s2)
(ensures state_eq_opt false (BS.machine_eval_codes cs f s1) (BS.machine_eval_codes cs f s2))
[SMTPat (BS.machine_eval_codes cs f s1); SMTPat (BS.machine_eval_codes cs f s2)]
=
eval_codes_eq_core false cs f s1; eval_codes_eq_core false cs f s2
let eval_while_eq_f (cond:ocmp) (body:code) (f:fuel) (s1 s2:machine_state) : Lemma
(requires state_eq_S false s1 s2)
(ensures state_eq_opt false (BS.machine_eval_while cond body f s1) (BS.machine_eval_while cond body f s2))
[SMTPat (BS.machine_eval_while cond body f s1); SMTPat (BS.machine_eval_while cond body f s2)]
=
eval_while_eq_core false cond body f s1; eval_while_eq_core false cond body f s2
let eval_code_eq_t (c:code) (f:fuel) (s1 s2:machine_state) : Lemma
(requires state_eq_S true s1 s2)
(ensures state_eq_opt true (BS.machine_eval_code c f s1) (BS.machine_eval_code c f s2))
[SMTPat (BS.machine_eval_code c f s1); SMTPat (BS.machine_eval_code c f s2)]
=
eval_code_eq_core true c f s1; eval_code_eq_core true c f s2
let eval_codes_eq_t (cs:codes) (f:fuel) (s1 s2:machine_state) : Lemma
(requires state_eq_S true s1 s2)
(ensures state_eq_opt true (BS.machine_eval_codes cs f s1) (BS.machine_eval_codes cs f s2))
[SMTPat (BS.machine_eval_codes cs f s1); SMTPat (BS.machine_eval_codes cs f s2)]
=
eval_codes_eq_core true cs f s1; eval_codes_eq_core true cs f s2
let eval_while_eq_t (cond:ocmp) (body:code) (f:fuel) (s1 s2:machine_state) : Lemma
(requires state_eq_S true s1 s2)
(ensures state_eq_opt true (BS.machine_eval_while cond body f s1) (BS.machine_eval_while cond body f s2))
[SMTPat (BS.machine_eval_while cond body f s1); SMTPat (BS.machine_eval_while cond body f s2)]
=
eval_while_eq_core true cond body f s1; eval_while_eq_core true cond body f s2 | false | true | Vale.X64.Lemmas.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": 30,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val eval_code_ts (g: bool) (c: code) (s0: machine_state) (f0: fuel) (s1: machine_state) : Type0 | [] | Vale.X64.Lemmas.eval_code_ts | {
"file_name": "vale/code/arch/x64/Vale.X64.Lemmas.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} |
g: Prims.bool ->
c: Vale.X64.StateLemmas.code ->
s0: Vale.X64.StateLemmas.machine_state ->
f0: Vale.X64.Lemmas.fuel ->
s1: Vale.X64.StateLemmas.machine_state
-> Type0 | {
"end_col": 57,
"end_line": 296,
"start_col": 2,
"start_line": 296
} |
Prims.Tot | val eval_while_inv (c:code) (s0:vale_state) (fW:fuel) (sW:vale_state) : Type0 | [
{
"abbrev": true,
"full_module": "Vale.X64.Memory",
"short_module": "ME"
},
{
"abbrev": false,
"full_module": "Vale.X64.Instruction_s",
"short_module": null
},
{
"abbrev": true,
"full_module": "Vale.Lib.Map16",
"short_module": "Map16"
},
{
"abbrev": true,
"full_module": "Vale.X64.Machine_Semantics_s",
"short_module": "BS"
},
{
"abbrev": false,
"full_module": "Vale.X64.Bytes_Code_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.StateLemmas",
"short_module": null
},
{
"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.HeapLemmas",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.HeapImpl",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Heap",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"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 eval_while_inv (c:code) (s0:vale_state) (fW:fuel) (sW:vale_state) : Type0 =
eval_while_inv_temp c s0 fW sW | val eval_while_inv (c:code) (s0:vale_state) (fW:fuel) (sW:vale_state) : Type0
let eval_while_inv (c: code) (s0: vale_state) (fW: fuel) (sW: vale_state) : Type0 = | false | null | false | eval_while_inv_temp c s0 fW sW | {
"checked_file": "Vale.X64.Lemmas.fst.checked",
"dependencies": [
"Vale.X64.StateLemmas.fsti.checked",
"Vale.X64.State.fsti.checked",
"Vale.X64.Memory.fsti.checked",
"Vale.X64.Machine_Semantics_s.fst.checked",
"Vale.X64.Machine_s.fst.checked",
"Vale.X64.Instruction_s.fsti.checked",
"Vale.X64.Flags.fsti.checked",
"Vale.X64.Bytes_Code_s.fst.checked",
"prims.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.FunctionalExtensionality.fsti.checked"
],
"interface_file": true,
"source_file": "Vale.X64.Lemmas.fst"
} | [
"total"
] | [
"Vale.X64.StateLemmas.code",
"Vale.X64.State.vale_state",
"Vale.X64.Lemmas.fuel",
"Vale.X64.Lemmas.eval_while_inv_temp"
] | [] | module Vale.X64.Lemmas
open FStar.Mul
open Vale.X64.Machine_s
open Vale.X64.State
open Vale.X64.StateLemmas
open Vale.X64.Instruction_s
open Vale.X64.Bytes_Code_s
module BS = Vale.X64.Machine_Semantics_s
module ME = Vale.X64.Memory
#reset-options "--initial_fuel 1 --max_fuel 1 --z3rlimit 100"
#restart-solver
let rec lemma_eq_instr_apply_eval_args
(outs:list instr_out) (args:list instr_operand)
(f:instr_args_t outs args) (oprs:instr_operands_t_args args) (s1 s2:machine_state)
: Lemma
(requires state_eq_S true s1 s2)
(ensures
BS.instr_apply_eval_args outs args f oprs s1 ==
BS.instr_apply_eval_args outs args f oprs s2)
=
let open BS in
lemma_heap_ignore_ghost_machine s1.BS.ms_heap s2.BS.ms_heap;
match args with
| [] -> ()
| i::args ->
(
let (v, oprs) : option (instr_val_t i) & instr_operands_t_args args =
match i with
| IOpEx i -> let oprs = coerce oprs in (instr_eval_operand_explicit i (fst oprs) s1, snd oprs)
| IOpIm i -> (instr_eval_operand_implicit i s1, coerce oprs)
in
let f:arrow (instr_val_t i) (instr_args_t outs args) = coerce f in
match v with
| None -> ()
| Some v -> lemma_eq_instr_apply_eval_args outs args (f v) oprs s1 s2
)
#restart-solver
let rec lemma_eq_instr_apply_eval_inouts
(outs inouts:list instr_out) (args:list instr_operand)
(f:instr_inouts_t outs inouts args) (oprs:instr_operands_t inouts args) (s1 s2:machine_state)
: Lemma
(requires state_eq_S true s1 s2)
(ensures
BS.instr_apply_eval_inouts outs inouts args f oprs s1 ==
BS.instr_apply_eval_inouts outs inouts args f oprs s2)
=
let open BS in
lemma_heap_ignore_ghost_machine s1.BS.ms_heap s2.BS.ms_heap;
match inouts with
| [] -> lemma_eq_instr_apply_eval_args outs args f oprs s1 s2
| (Out, i)::inouts ->
let oprs =
match i with
| IOpEx i -> snd #(instr_operand_t i) (coerce oprs)
| IOpIm i -> coerce oprs
in
lemma_eq_instr_apply_eval_inouts outs inouts args (coerce f) oprs s1 s2
| (InOut, i)::inouts ->
(
let (v, oprs) : option (instr_val_t i) & instr_operands_t inouts args =
match i with
| IOpEx i -> let oprs = coerce oprs in (instr_eval_operand_explicit i (fst oprs) s1, snd oprs)
| IOpIm i -> (instr_eval_operand_implicit i s1, coerce oprs)
in
let f:arrow (instr_val_t i) (instr_inouts_t outs inouts args) = coerce f in
match v with
| None -> ()
| Some v -> lemma_eq_instr_apply_eval_inouts outs inouts args (f v) oprs s1 s2
)
#restart-solver
#push-options "--z3rlimit_factor 2"
let rec lemma_eq_instr_write_outputs
(outs:list instr_out) (args:list instr_operand)
(vs:instr_ret_t outs) (oprs:instr_operands_t outs args) (s1_orig s1 s2_orig s2:machine_state)
: Lemma
(requires state_eq_S true s1_orig s2_orig /\ state_eq_S true s1 s2)
(ensures
state_eq_S true
(BS.instr_write_outputs outs args vs oprs s1_orig s1)
(BS.instr_write_outputs outs args vs oprs s2_orig s2))
=
let open BS in
use_machine_state_equal ();
lemma_heap_ignore_ghost_machine s1.BS.ms_heap s2.BS.ms_heap;
lemma_heap_ignore_ghost_machine s1_orig.BS.ms_heap s2_orig.BS.ms_heap;
allow_inversion tmaddr;
match outs with
| [] -> ()
| (_, i)::outs ->
(
let ((v:instr_val_t i), (vs:instr_ret_t outs)) =
match outs with
| [] -> (vs, ())
| _::_ -> let vs = coerce vs in (fst vs, snd vs)
in
match i with
| IOpEx i ->
let oprs = coerce oprs in
let s1 = instr_write_output_explicit i v (fst oprs) s1_orig s1 in
let s2 = instr_write_output_explicit i v (fst oprs) s2_orig s2 in
lemma_eq_instr_write_outputs outs args vs (snd oprs) s1_orig s1 s2_orig s2
| IOpIm i ->
let s1 = instr_write_output_implicit i v s1_orig s1 in
let s2 = instr_write_output_implicit i v s2_orig s2 in
allow_inversion operand64;
allow_inversion operand128;
lemma_eq_instr_write_outputs outs args vs (coerce oprs) s1_orig s1 s2_orig s2
)
#pop-options
#restart-solver
let eval_ins_eq_instr (inst:BS.ins) (s1 s2:machine_state) : Lemma
(requires Instr? inst /\ state_eq_S true s1 s2)
(ensures state_eq_S true (BS.machine_eval_ins inst s1) (BS.machine_eval_ins inst s2))
=
let open BS in
let Instr it oprs ann = inst in
let InstrTypeRecord #outs #args #havoc_flags' i = it in
lemma_eq_instr_apply_eval_inouts outs outs args (instr_eval i) oprs s1 s2;
let vs = instr_apply_eval outs args (instr_eval i) oprs s1 in
let hav s =
match havoc_flags' with
| HavocFlags -> {s with ms_flags = havoc_flags}
| PreserveFlags -> s
in
let s1' = hav s1 in
let s2' = hav s2 in
match vs with
| None -> ()
| Some vs -> lemma_eq_instr_write_outputs outs args vs oprs s1 s1' s2 s2'
let eval_code_eq_instr (inst:BS.ins) (f:fuel) (s1 s2:machine_state) : Lemma
(requires Instr? inst /\ state_eq_S true s1 s2)
(ensures state_eq_opt true (BS.machine_eval_code (Ins inst) f s1) (BS.machine_eval_code (Ins inst) f s2))
=
reveal_opaque (`%BS.machine_eval_code_ins) BS.machine_eval_code_ins;
eval_ins_eq_instr inst ({s1 with BS.ms_trace = []}) ({s2 with BS.ms_trace = []})
let eval_code_eq_dealloc (inst:BS.ins) (f:fuel) (s1 s2:machine_state) : Lemma
(requires Dealloc? inst /\ state_eq_S true s1 s2)
(ensures state_eq_opt true (BS.machine_eval_code (Ins inst) f s1) (BS.machine_eval_code (Ins inst) f s2))
=
reveal_opaque (`%BS.machine_eval_code_ins) BS.machine_eval_code_ins;
use_machine_state_equal ();
lemma_heap_ignore_ghost_machine s1.BS.ms_heap s2.BS.ms_heap;
allow_inversion tmaddr
let eval_code_eq_alloc (inst:BS.ins) (f:fuel) (s1 s2:machine_state) : Lemma
(requires Alloc? inst /\ state_eq_S true s1 s2)
(ensures state_eq_opt true (BS.machine_eval_code (Ins inst) f s1) (BS.machine_eval_code (Ins inst) f s2))
=
reveal_opaque (`%BS.machine_eval_code_ins) BS.machine_eval_code_ins;
use_machine_state_equal ();
lemma_heap_ignore_ghost_machine s1.BS.ms_heap s2.BS.ms_heap;
allow_inversion tmaddr
let eval_code_eq_push (inst:BS.ins) (f:fuel) (s1 s2:machine_state) : Lemma
(requires Push? inst /\ state_eq_S true s1 s2)
(ensures state_eq_opt true (BS.machine_eval_code (Ins inst) f s1) (BS.machine_eval_code (Ins inst) f s2))
=
reveal_opaque (`%BS.machine_eval_code_ins) BS.machine_eval_code_ins;
use_machine_state_equal ();
lemma_heap_ignore_ghost_machine s1.BS.ms_heap s2.BS.ms_heap;
allow_inversion tmaddr
let eval_code_eq_pop (inst:BS.ins) (f:fuel) (s1 s2:machine_state) : Lemma
(requires Pop? inst /\ state_eq_S true s1 s2)
(ensures state_eq_opt true (BS.machine_eval_code (Ins inst) f s1) (BS.machine_eval_code (Ins inst) f s2))
=
reveal_opaque (`%BS.machine_eval_code_ins) BS.machine_eval_code_ins;
use_machine_state_equal ();
lemma_heap_ignore_ghost_machine s1.BS.ms_heap s2.BS.ms_heap;
allow_inversion tmaddr
let eval_code_eq_ins (i:BS.ins) (f:fuel) (s1 s2:machine_state) : Lemma
(requires state_eq_S true s1 s2)
(ensures state_eq_opt true (BS.machine_eval_code (Ins i) f s1) (BS.machine_eval_code (Ins i) f s2))
=
match i with
| Instr _ _ _ -> eval_code_eq_instr i f s1 s2
| Dealloc _ -> eval_code_eq_dealloc i f s1 s2
| Alloc _ -> eval_code_eq_alloc i f s1 s2
| Push _ _ -> eval_code_eq_push i f s1 s2
| Pop _ _ -> eval_code_eq_pop i f s1 s2
#reset-options "--fuel 2 --z3rlimit 30"
let eval_ocmp_eq_core (g:bool) (cond:ocmp) (s:machine_state) : Lemma
(ensures (
let (s1, b1) = BS.machine_eval_ocmp s cond in
let (s2, b2) = BS.machine_eval_ocmp (core_state g s) cond in
state_eq_S g s1 s2 /\ b1 == b2
))
=
reveal_opaque (`%BS.valid_ocmp_opaque) BS.valid_ocmp_opaque;
reveal_opaque (`%BS.eval_ocmp_opaque) BS.eval_ocmp_opaque;
()
#restart-solver
let rec eval_code_eq_core (g:bool) (c:code) (f:fuel) (s:machine_state) : Lemma
(ensures state_eq_opt g (BS.machine_eval_code c f s) (BS.machine_eval_code c f (core_state g s)))
(decreases %[f; c])
=
match c with
| Ins i ->
reveal_opaque (`%BS.machine_eval_code_ins) BS.machine_eval_code_ins;
if g then eval_code_eq_ins i f s (core_state g s)
| Block cs -> eval_codes_eq_core g cs f s
| IfElse cond ct cf ->
eval_ocmp_eq_core g cond s;
let (s', _) = BS.machine_eval_ocmp s cond in
let (t', _) = BS.machine_eval_ocmp (core_state g s) cond in
eval_code_eq_core g ct f s';
eval_code_eq_core g ct f t';
eval_code_eq_core g cf f s';
eval_code_eq_core g cf f t';
()
| While cond body -> eval_while_eq_core g cond body f s
and eval_codes_eq_core (g:bool) (cs:codes) (f:fuel) (s:machine_state) : Lemma
(ensures state_eq_opt g (BS.machine_eval_codes cs f s) (BS.machine_eval_codes cs f (core_state g s)))
(decreases %[f; cs])
=
match cs with
| [] -> ()
| c'::cs' -> (
eval_code_eq_core g c' f s;
match (machine_eval_code c' f s, machine_eval_code c' f (core_state g s)) with
| (None, None) -> ()
| (Some s', Some t') -> eval_codes_eq_core g cs' f s'; eval_codes_eq_core g cs' f t'
)
and eval_while_eq_core (g:bool) (cond:ocmp) (body:code) (f:fuel) (s:machine_state) : Lemma
(ensures state_eq_opt g (BS.machine_eval_while cond body f s) (BS.machine_eval_while cond body f (core_state g s)))
(decreases %[f; body])
=
if f > 0 then (
eval_ocmp_eq_core g cond s;
let (s1, _) = BS.machine_eval_ocmp s cond in
let (t1, _) = BS.machine_eval_ocmp (core_state g s) cond in
eval_code_eq_core g body (f - 1) s1;
eval_code_eq_core g body (f - 1) t1;
match (BS.machine_eval_code body (f - 1) s1, BS.machine_eval_code body (f - 1) t1) with
| (None, None) -> ()
| (Some s2, Some t2) ->
eval_while_eq_core g cond body (f - 1) s2;
eval_while_eq_core g cond body (f - 1) t2;
()
)
let eval_code_eq_f (c:code) (f:fuel) (s1 s2:machine_state) : Lemma
(requires state_eq_S false s1 s2)
(ensures state_eq_opt false (BS.machine_eval_code c f s1) (BS.machine_eval_code c f s2))
[SMTPat (BS.machine_eval_code c f s1); SMTPat (BS.machine_eval_code c f s2)]
=
eval_code_eq_core false c f s1; eval_code_eq_core false c f s2
let eval_codes_eq_f (cs:codes) (f:fuel) (s1 s2:machine_state) : Lemma
(requires state_eq_S false s1 s2)
(ensures state_eq_opt false (BS.machine_eval_codes cs f s1) (BS.machine_eval_codes cs f s2))
[SMTPat (BS.machine_eval_codes cs f s1); SMTPat (BS.machine_eval_codes cs f s2)]
=
eval_codes_eq_core false cs f s1; eval_codes_eq_core false cs f s2
let eval_while_eq_f (cond:ocmp) (body:code) (f:fuel) (s1 s2:machine_state) : Lemma
(requires state_eq_S false s1 s2)
(ensures state_eq_opt false (BS.machine_eval_while cond body f s1) (BS.machine_eval_while cond body f s2))
[SMTPat (BS.machine_eval_while cond body f s1); SMTPat (BS.machine_eval_while cond body f s2)]
=
eval_while_eq_core false cond body f s1; eval_while_eq_core false cond body f s2
let eval_code_eq_t (c:code) (f:fuel) (s1 s2:machine_state) : Lemma
(requires state_eq_S true s1 s2)
(ensures state_eq_opt true (BS.machine_eval_code c f s1) (BS.machine_eval_code c f s2))
[SMTPat (BS.machine_eval_code c f s1); SMTPat (BS.machine_eval_code c f s2)]
=
eval_code_eq_core true c f s1; eval_code_eq_core true c f s2
let eval_codes_eq_t (cs:codes) (f:fuel) (s1 s2:machine_state) : Lemma
(requires state_eq_S true s1 s2)
(ensures state_eq_opt true (BS.machine_eval_codes cs f s1) (BS.machine_eval_codes cs f s2))
[SMTPat (BS.machine_eval_codes cs f s1); SMTPat (BS.machine_eval_codes cs f s2)]
=
eval_codes_eq_core true cs f s1; eval_codes_eq_core true cs f s2
let eval_while_eq_t (cond:ocmp) (body:code) (f:fuel) (s1 s2:machine_state) : Lemma
(requires state_eq_S true s1 s2)
(ensures state_eq_opt true (BS.machine_eval_while cond body f s1) (BS.machine_eval_while cond body f s2))
[SMTPat (BS.machine_eval_while cond body f s1); SMTPat (BS.machine_eval_while cond body f s2)]
=
eval_while_eq_core true cond body f s1; eval_while_eq_core true cond body f s2
let eval_code_ts (g:bool) (c:code) (s0:machine_state) (f0:fuel) (s1:machine_state) : Type0 =
state_eq_opt g (BS.machine_eval_code c f0 s0) (Some s1)
let rec increase_fuel (g:bool) (c:code) (s0:machine_state) (f0:fuel) (sN:machine_state) (fN:fuel) : Lemma
(requires eval_code_ts g c s0 f0 sN /\ f0 <= fN)
(ensures eval_code_ts g c s0 fN sN)
(decreases %[f0; c])
=
match c with
| Ins ins -> ()
| Block l -> increase_fuels g l s0 f0 sN fN
| IfElse cond t f ->
let (s0, b0) = BS.machine_eval_ocmp s0 cond in
if b0 then increase_fuel g t s0 f0 sN fN else increase_fuel g f s0 f0 sN fN
| While cond c ->
let (s1, b0) = BS.machine_eval_ocmp s0 cond in
if b0 then (
match BS.machine_eval_code c (f0 - 1) s1 with
| None -> ()
| Some s2 ->
increase_fuel g c s1 (f0 - 1) s2 (fN - 1);
if s2.BS.ms_ok then increase_fuel g (While cond c) s2 (f0 - 1) sN (fN - 1)
else ()
)
and increase_fuels (g:bool) (c:codes) (s0:machine_state) (f0:fuel) (sN:machine_state) (fN:fuel) : Lemma
(requires eval_code_ts g (Block c) s0 f0 sN /\ f0 <= fN)
(ensures eval_code_ts g (Block c) s0 fN sN)
(decreases %[f0; c])
=
match c with
| [] -> ()
| h::t ->
(
let Some s1 = BS.machine_eval_code h f0 s0 in
increase_fuel g h s0 f0 s1 fN;
increase_fuels g t s1 f0 sN fN
)
let lemma_cmp_eq s o1 o2 = reveal_opaque (`%BS.eval_ocmp_opaque) BS.eval_ocmp_opaque
let lemma_cmp_ne s o1 o2 = reveal_opaque (`%BS.eval_ocmp_opaque) BS.eval_ocmp_opaque
let lemma_cmp_le s o1 o2 = reveal_opaque (`%BS.eval_ocmp_opaque) BS.eval_ocmp_opaque
let lemma_cmp_ge s o1 o2 = reveal_opaque (`%BS.eval_ocmp_opaque) BS.eval_ocmp_opaque
let lemma_cmp_lt s o1 o2 = reveal_opaque (`%BS.eval_ocmp_opaque) BS.eval_ocmp_opaque
let lemma_cmp_gt s o1 o2 = reveal_opaque (`%BS.eval_ocmp_opaque) BS.eval_ocmp_opaque
let lemma_valid_cmp_eq s o1 o2 = ()
let lemma_valid_cmp_ne s o1 o2 = ()
let lemma_valid_cmp_le s o1 o2 = ()
let lemma_valid_cmp_ge s o1 o2 = ()
let lemma_valid_cmp_lt s o1 o2 = ()
let lemma_valid_cmp_gt s o1 o2 = ()
let compute_merge_total (f0:fuel) (fM:fuel) =
if f0 > fM then f0 else fM
let lemma_merge_total (b0:codes) (s0:vale_state) (f0:fuel) (sM:vale_state) (fM:fuel) (sN:vale_state) =
let f = if f0 > fM then f0 else fM in
increase_fuel (codes_modifies_ghost b0) (Cons?.hd b0) (state_to_S s0) f0 (state_to_S sM) f;
increase_fuel (codes_modifies_ghost b0) (Block (Cons?.tl b0)) (state_to_S sM) fM (state_to_S sN) f
let lemma_empty_total (s0:vale_state) (bN:codes) =
(s0, 0)
let lemma_ifElse_total (ifb:ocmp) (ct:code) (cf:code) (s0:vale_state) =
(eval_ocmp s0 ifb, {s0 with vs_flags = havoc_flags}, s0, 0)
let lemma_havoc_flags : squash (Flags.to_fun havoc_flags == BS.havoc_flags) =
assert (FStar.FunctionalExtensionality.feq (Flags.to_fun havoc_flags) BS.havoc_flags)
let lemma_ifElseTrue_total (ifb:ocmp) (ct:code) (cf:code) (s0:vale_state) (f0:fuel) (sM:vale_state) =
reveal_opaque (`%BS.valid_ocmp_opaque) BS.valid_ocmp_opaque;
reveal_opaque (`%BS.eval_ocmp_opaque) BS.eval_ocmp_opaque
let lemma_ifElseFalse_total (ifb:ocmp) (ct:code) (cf:code) (s0:vale_state) (f0:fuel) (sM:vale_state) =
reveal_opaque (`%BS.valid_ocmp_opaque) BS.valid_ocmp_opaque;
reveal_opaque (`%BS.eval_ocmp_opaque) BS.eval_ocmp_opaque
let eval_while_inv_temp (c:code) (s0:vale_state) (fW:fuel) (sW:vale_state) : Type0 =
forall (f:nat).{:pattern BS.machine_eval_code c f (state_to_S sW)}
Some? (BS.machine_eval_code c f (state_to_S sW)) ==>
state_eq_opt (code_modifies_ghost c)
(BS.machine_eval_code c (f + fW) (state_to_S s0))
(BS.machine_eval_code c f (state_to_S sW)) | false | true | Vale.X64.Lemmas.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": 30,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val eval_while_inv (c:code) (s0:vale_state) (fW:fuel) (sW:vale_state) : Type0 | [] | Vale.X64.Lemmas.eval_while_inv | {
"file_name": "vale/code/arch/x64/Vale.X64.Lemmas.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} |
c: Vale.X64.StateLemmas.code ->
s0: Vale.X64.State.vale_state ->
fW: Vale.X64.Lemmas.fuel ->
sW: Vale.X64.State.vale_state
-> Type0 | {
"end_col": 32,
"end_line": 380,
"start_col": 2,
"start_line": 380
} |
FStar.Pervasives.Lemma | val eval_codes_eq_t (cs: codes) (f: fuel) (s1 s2: machine_state)
: Lemma (requires state_eq_S true s1 s2)
(ensures state_eq_opt true (BS.machine_eval_codes cs f s1) (BS.machine_eval_codes cs f s2))
[SMTPat (BS.machine_eval_codes cs f s1); SMTPat (BS.machine_eval_codes cs f s2)] | [
{
"abbrev": true,
"full_module": "Vale.X64.Memory",
"short_module": "ME"
},
{
"abbrev": true,
"full_module": "Vale.X64.Machine_Semantics_s",
"short_module": "BS"
},
{
"abbrev": false,
"full_module": "Vale.X64.Bytes_Code_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Instruction_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.StateLemmas",
"short_module": null
},
{
"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": "FStar.Mul",
"short_module": null
},
{
"abbrev": true,
"full_module": "Vale.Lib.Map16",
"short_module": "Map16"
},
{
"abbrev": true,
"full_module": "Vale.X64.Machine_Semantics_s",
"short_module": "BS"
},
{
"abbrev": false,
"full_module": "Vale.X64.Bytes_Code_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.StateLemmas",
"short_module": null
},
{
"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.HeapLemmas",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.HeapImpl",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Heap",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"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 eval_codes_eq_t (cs:codes) (f:fuel) (s1 s2:machine_state) : Lemma
(requires state_eq_S true s1 s2)
(ensures state_eq_opt true (BS.machine_eval_codes cs f s1) (BS.machine_eval_codes cs f s2))
[SMTPat (BS.machine_eval_codes cs f s1); SMTPat (BS.machine_eval_codes cs f s2)]
=
eval_codes_eq_core true cs f s1; eval_codes_eq_core true cs f s2 | val eval_codes_eq_t (cs: codes) (f: fuel) (s1 s2: machine_state)
: Lemma (requires state_eq_S true s1 s2)
(ensures state_eq_opt true (BS.machine_eval_codes cs f s1) (BS.machine_eval_codes cs f s2))
[SMTPat (BS.machine_eval_codes cs f s1); SMTPat (BS.machine_eval_codes cs f s2)]
let eval_codes_eq_t (cs: codes) (f: fuel) (s1 s2: machine_state)
: Lemma (requires state_eq_S true s1 s2)
(ensures state_eq_opt true (BS.machine_eval_codes cs f s1) (BS.machine_eval_codes cs f s2))
[SMTPat (BS.machine_eval_codes cs f s1); SMTPat (BS.machine_eval_codes cs f s2)] = | false | null | true | eval_codes_eq_core true cs f s1;
eval_codes_eq_core true cs f s2 | {
"checked_file": "Vale.X64.Lemmas.fst.checked",
"dependencies": [
"Vale.X64.StateLemmas.fsti.checked",
"Vale.X64.State.fsti.checked",
"Vale.X64.Memory.fsti.checked",
"Vale.X64.Machine_Semantics_s.fst.checked",
"Vale.X64.Machine_s.fst.checked",
"Vale.X64.Instruction_s.fsti.checked",
"Vale.X64.Flags.fsti.checked",
"Vale.X64.Bytes_Code_s.fst.checked",
"prims.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.FunctionalExtensionality.fsti.checked"
],
"interface_file": true,
"source_file": "Vale.X64.Lemmas.fst"
} | [
"lemma"
] | [
"Vale.X64.Lemmas.codes",
"Vale.X64.Lemmas.fuel",
"Vale.X64.StateLemmas.machine_state",
"Vale.X64.Lemmas.eval_codes_eq_core",
"Prims.unit",
"Vale.X64.Lemmas.state_eq_S",
"Prims.squash",
"Vale.X64.Lemmas.state_eq_opt",
"Vale.X64.Machine_Semantics_s.machine_eval_codes",
"Prims.Cons",
"FStar.Pervasives.pattern",
"FStar.Pervasives.smt_pat",
"FStar.Pervasives.Native.option",
"Vale.X64.Machine_Semantics_s.machine_state",
"Prims.Nil"
] | [] | module Vale.X64.Lemmas
open FStar.Mul
open Vale.X64.Machine_s
open Vale.X64.State
open Vale.X64.StateLemmas
open Vale.X64.Instruction_s
open Vale.X64.Bytes_Code_s
module BS = Vale.X64.Machine_Semantics_s
module ME = Vale.X64.Memory
#reset-options "--initial_fuel 1 --max_fuel 1 --z3rlimit 100"
#restart-solver
let rec lemma_eq_instr_apply_eval_args
(outs:list instr_out) (args:list instr_operand)
(f:instr_args_t outs args) (oprs:instr_operands_t_args args) (s1 s2:machine_state)
: Lemma
(requires state_eq_S true s1 s2)
(ensures
BS.instr_apply_eval_args outs args f oprs s1 ==
BS.instr_apply_eval_args outs args f oprs s2)
=
let open BS in
lemma_heap_ignore_ghost_machine s1.BS.ms_heap s2.BS.ms_heap;
match args with
| [] -> ()
| i::args ->
(
let (v, oprs) : option (instr_val_t i) & instr_operands_t_args args =
match i with
| IOpEx i -> let oprs = coerce oprs in (instr_eval_operand_explicit i (fst oprs) s1, snd oprs)
| IOpIm i -> (instr_eval_operand_implicit i s1, coerce oprs)
in
let f:arrow (instr_val_t i) (instr_args_t outs args) = coerce f in
match v with
| None -> ()
| Some v -> lemma_eq_instr_apply_eval_args outs args (f v) oprs s1 s2
)
#restart-solver
let rec lemma_eq_instr_apply_eval_inouts
(outs inouts:list instr_out) (args:list instr_operand)
(f:instr_inouts_t outs inouts args) (oprs:instr_operands_t inouts args) (s1 s2:machine_state)
: Lemma
(requires state_eq_S true s1 s2)
(ensures
BS.instr_apply_eval_inouts outs inouts args f oprs s1 ==
BS.instr_apply_eval_inouts outs inouts args f oprs s2)
=
let open BS in
lemma_heap_ignore_ghost_machine s1.BS.ms_heap s2.BS.ms_heap;
match inouts with
| [] -> lemma_eq_instr_apply_eval_args outs args f oprs s1 s2
| (Out, i)::inouts ->
let oprs =
match i with
| IOpEx i -> snd #(instr_operand_t i) (coerce oprs)
| IOpIm i -> coerce oprs
in
lemma_eq_instr_apply_eval_inouts outs inouts args (coerce f) oprs s1 s2
| (InOut, i)::inouts ->
(
let (v, oprs) : option (instr_val_t i) & instr_operands_t inouts args =
match i with
| IOpEx i -> let oprs = coerce oprs in (instr_eval_operand_explicit i (fst oprs) s1, snd oprs)
| IOpIm i -> (instr_eval_operand_implicit i s1, coerce oprs)
in
let f:arrow (instr_val_t i) (instr_inouts_t outs inouts args) = coerce f in
match v with
| None -> ()
| Some v -> lemma_eq_instr_apply_eval_inouts outs inouts args (f v) oprs s1 s2
)
#restart-solver
#push-options "--z3rlimit_factor 2"
let rec lemma_eq_instr_write_outputs
(outs:list instr_out) (args:list instr_operand)
(vs:instr_ret_t outs) (oprs:instr_operands_t outs args) (s1_orig s1 s2_orig s2:machine_state)
: Lemma
(requires state_eq_S true s1_orig s2_orig /\ state_eq_S true s1 s2)
(ensures
state_eq_S true
(BS.instr_write_outputs outs args vs oprs s1_orig s1)
(BS.instr_write_outputs outs args vs oprs s2_orig s2))
=
let open BS in
use_machine_state_equal ();
lemma_heap_ignore_ghost_machine s1.BS.ms_heap s2.BS.ms_heap;
lemma_heap_ignore_ghost_machine s1_orig.BS.ms_heap s2_orig.BS.ms_heap;
allow_inversion tmaddr;
match outs with
| [] -> ()
| (_, i)::outs ->
(
let ((v:instr_val_t i), (vs:instr_ret_t outs)) =
match outs with
| [] -> (vs, ())
| _::_ -> let vs = coerce vs in (fst vs, snd vs)
in
match i with
| IOpEx i ->
let oprs = coerce oprs in
let s1 = instr_write_output_explicit i v (fst oprs) s1_orig s1 in
let s2 = instr_write_output_explicit i v (fst oprs) s2_orig s2 in
lemma_eq_instr_write_outputs outs args vs (snd oprs) s1_orig s1 s2_orig s2
| IOpIm i ->
let s1 = instr_write_output_implicit i v s1_orig s1 in
let s2 = instr_write_output_implicit i v s2_orig s2 in
allow_inversion operand64;
allow_inversion operand128;
lemma_eq_instr_write_outputs outs args vs (coerce oprs) s1_orig s1 s2_orig s2
)
#pop-options
#restart-solver
let eval_ins_eq_instr (inst:BS.ins) (s1 s2:machine_state) : Lemma
(requires Instr? inst /\ state_eq_S true s1 s2)
(ensures state_eq_S true (BS.machine_eval_ins inst s1) (BS.machine_eval_ins inst s2))
=
let open BS in
let Instr it oprs ann = inst in
let InstrTypeRecord #outs #args #havoc_flags' i = it in
lemma_eq_instr_apply_eval_inouts outs outs args (instr_eval i) oprs s1 s2;
let vs = instr_apply_eval outs args (instr_eval i) oprs s1 in
let hav s =
match havoc_flags' with
| HavocFlags -> {s with ms_flags = havoc_flags}
| PreserveFlags -> s
in
let s1' = hav s1 in
let s2' = hav s2 in
match vs with
| None -> ()
| Some vs -> lemma_eq_instr_write_outputs outs args vs oprs s1 s1' s2 s2'
let eval_code_eq_instr (inst:BS.ins) (f:fuel) (s1 s2:machine_state) : Lemma
(requires Instr? inst /\ state_eq_S true s1 s2)
(ensures state_eq_opt true (BS.machine_eval_code (Ins inst) f s1) (BS.machine_eval_code (Ins inst) f s2))
=
reveal_opaque (`%BS.machine_eval_code_ins) BS.machine_eval_code_ins;
eval_ins_eq_instr inst ({s1 with BS.ms_trace = []}) ({s2 with BS.ms_trace = []})
let eval_code_eq_dealloc (inst:BS.ins) (f:fuel) (s1 s2:machine_state) : Lemma
(requires Dealloc? inst /\ state_eq_S true s1 s2)
(ensures state_eq_opt true (BS.machine_eval_code (Ins inst) f s1) (BS.machine_eval_code (Ins inst) f s2))
=
reveal_opaque (`%BS.machine_eval_code_ins) BS.machine_eval_code_ins;
use_machine_state_equal ();
lemma_heap_ignore_ghost_machine s1.BS.ms_heap s2.BS.ms_heap;
allow_inversion tmaddr
let eval_code_eq_alloc (inst:BS.ins) (f:fuel) (s1 s2:machine_state) : Lemma
(requires Alloc? inst /\ state_eq_S true s1 s2)
(ensures state_eq_opt true (BS.machine_eval_code (Ins inst) f s1) (BS.machine_eval_code (Ins inst) f s2))
=
reveal_opaque (`%BS.machine_eval_code_ins) BS.machine_eval_code_ins;
use_machine_state_equal ();
lemma_heap_ignore_ghost_machine s1.BS.ms_heap s2.BS.ms_heap;
allow_inversion tmaddr
let eval_code_eq_push (inst:BS.ins) (f:fuel) (s1 s2:machine_state) : Lemma
(requires Push? inst /\ state_eq_S true s1 s2)
(ensures state_eq_opt true (BS.machine_eval_code (Ins inst) f s1) (BS.machine_eval_code (Ins inst) f s2))
=
reveal_opaque (`%BS.machine_eval_code_ins) BS.machine_eval_code_ins;
use_machine_state_equal ();
lemma_heap_ignore_ghost_machine s1.BS.ms_heap s2.BS.ms_heap;
allow_inversion tmaddr
let eval_code_eq_pop (inst:BS.ins) (f:fuel) (s1 s2:machine_state) : Lemma
(requires Pop? inst /\ state_eq_S true s1 s2)
(ensures state_eq_opt true (BS.machine_eval_code (Ins inst) f s1) (BS.machine_eval_code (Ins inst) f s2))
=
reveal_opaque (`%BS.machine_eval_code_ins) BS.machine_eval_code_ins;
use_machine_state_equal ();
lemma_heap_ignore_ghost_machine s1.BS.ms_heap s2.BS.ms_heap;
allow_inversion tmaddr
let eval_code_eq_ins (i:BS.ins) (f:fuel) (s1 s2:machine_state) : Lemma
(requires state_eq_S true s1 s2)
(ensures state_eq_opt true (BS.machine_eval_code (Ins i) f s1) (BS.machine_eval_code (Ins i) f s2))
=
match i with
| Instr _ _ _ -> eval_code_eq_instr i f s1 s2
| Dealloc _ -> eval_code_eq_dealloc i f s1 s2
| Alloc _ -> eval_code_eq_alloc i f s1 s2
| Push _ _ -> eval_code_eq_push i f s1 s2
| Pop _ _ -> eval_code_eq_pop i f s1 s2
#reset-options "--fuel 2 --z3rlimit 30"
let eval_ocmp_eq_core (g:bool) (cond:ocmp) (s:machine_state) : Lemma
(ensures (
let (s1, b1) = BS.machine_eval_ocmp s cond in
let (s2, b2) = BS.machine_eval_ocmp (core_state g s) cond in
state_eq_S g s1 s2 /\ b1 == b2
))
=
reveal_opaque (`%BS.valid_ocmp_opaque) BS.valid_ocmp_opaque;
reveal_opaque (`%BS.eval_ocmp_opaque) BS.eval_ocmp_opaque;
()
#restart-solver
let rec eval_code_eq_core (g:bool) (c:code) (f:fuel) (s:machine_state) : Lemma
(ensures state_eq_opt g (BS.machine_eval_code c f s) (BS.machine_eval_code c f (core_state g s)))
(decreases %[f; c])
=
match c with
| Ins i ->
reveal_opaque (`%BS.machine_eval_code_ins) BS.machine_eval_code_ins;
if g then eval_code_eq_ins i f s (core_state g s)
| Block cs -> eval_codes_eq_core g cs f s
| IfElse cond ct cf ->
eval_ocmp_eq_core g cond s;
let (s', _) = BS.machine_eval_ocmp s cond in
let (t', _) = BS.machine_eval_ocmp (core_state g s) cond in
eval_code_eq_core g ct f s';
eval_code_eq_core g ct f t';
eval_code_eq_core g cf f s';
eval_code_eq_core g cf f t';
()
| While cond body -> eval_while_eq_core g cond body f s
and eval_codes_eq_core (g:bool) (cs:codes) (f:fuel) (s:machine_state) : Lemma
(ensures state_eq_opt g (BS.machine_eval_codes cs f s) (BS.machine_eval_codes cs f (core_state g s)))
(decreases %[f; cs])
=
match cs with
| [] -> ()
| c'::cs' -> (
eval_code_eq_core g c' f s;
match (machine_eval_code c' f s, machine_eval_code c' f (core_state g s)) with
| (None, None) -> ()
| (Some s', Some t') -> eval_codes_eq_core g cs' f s'; eval_codes_eq_core g cs' f t'
)
and eval_while_eq_core (g:bool) (cond:ocmp) (body:code) (f:fuel) (s:machine_state) : Lemma
(ensures state_eq_opt g (BS.machine_eval_while cond body f s) (BS.machine_eval_while cond body f (core_state g s)))
(decreases %[f; body])
=
if f > 0 then (
eval_ocmp_eq_core g cond s;
let (s1, _) = BS.machine_eval_ocmp s cond in
let (t1, _) = BS.machine_eval_ocmp (core_state g s) cond in
eval_code_eq_core g body (f - 1) s1;
eval_code_eq_core g body (f - 1) t1;
match (BS.machine_eval_code body (f - 1) s1, BS.machine_eval_code body (f - 1) t1) with
| (None, None) -> ()
| (Some s2, Some t2) ->
eval_while_eq_core g cond body (f - 1) s2;
eval_while_eq_core g cond body (f - 1) t2;
()
)
let eval_code_eq_f (c:code) (f:fuel) (s1 s2:machine_state) : Lemma
(requires state_eq_S false s1 s2)
(ensures state_eq_opt false (BS.machine_eval_code c f s1) (BS.machine_eval_code c f s2))
[SMTPat (BS.machine_eval_code c f s1); SMTPat (BS.machine_eval_code c f s2)]
=
eval_code_eq_core false c f s1; eval_code_eq_core false c f s2
let eval_codes_eq_f (cs:codes) (f:fuel) (s1 s2:machine_state) : Lemma
(requires state_eq_S false s1 s2)
(ensures state_eq_opt false (BS.machine_eval_codes cs f s1) (BS.machine_eval_codes cs f s2))
[SMTPat (BS.machine_eval_codes cs f s1); SMTPat (BS.machine_eval_codes cs f s2)]
=
eval_codes_eq_core false cs f s1; eval_codes_eq_core false cs f s2
let eval_while_eq_f (cond:ocmp) (body:code) (f:fuel) (s1 s2:machine_state) : Lemma
(requires state_eq_S false s1 s2)
(ensures state_eq_opt false (BS.machine_eval_while cond body f s1) (BS.machine_eval_while cond body f s2))
[SMTPat (BS.machine_eval_while cond body f s1); SMTPat (BS.machine_eval_while cond body f s2)]
=
eval_while_eq_core false cond body f s1; eval_while_eq_core false cond body f s2
let eval_code_eq_t (c:code) (f:fuel) (s1 s2:machine_state) : Lemma
(requires state_eq_S true s1 s2)
(ensures state_eq_opt true (BS.machine_eval_code c f s1) (BS.machine_eval_code c f s2))
[SMTPat (BS.machine_eval_code c f s1); SMTPat (BS.machine_eval_code c f s2)]
=
eval_code_eq_core true c f s1; eval_code_eq_core true c f s2
let eval_codes_eq_t (cs:codes) (f:fuel) (s1 s2:machine_state) : Lemma
(requires state_eq_S true s1 s2)
(ensures state_eq_opt true (BS.machine_eval_codes cs f s1) (BS.machine_eval_codes cs f s2))
[SMTPat (BS.machine_eval_codes cs f s1); SMTPat (BS.machine_eval_codes cs f s2)] | false | false | Vale.X64.Lemmas.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": 30,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val eval_codes_eq_t (cs: codes) (f: fuel) (s1 s2: machine_state)
: Lemma (requires state_eq_S true s1 s2)
(ensures state_eq_opt true (BS.machine_eval_codes cs f s1) (BS.machine_eval_codes cs f s2))
[SMTPat (BS.machine_eval_codes cs f s1); SMTPat (BS.machine_eval_codes cs f s2)] | [] | Vale.X64.Lemmas.eval_codes_eq_t | {
"file_name": "vale/code/arch/x64/Vale.X64.Lemmas.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} |
cs: Vale.X64.Lemmas.codes ->
f: Vale.X64.Lemmas.fuel ->
s1: Vale.X64.StateLemmas.machine_state ->
s2: Vale.X64.StateLemmas.machine_state
-> FStar.Pervasives.Lemma (requires Vale.X64.Lemmas.state_eq_S true s1 s2)
(ensures
Vale.X64.Lemmas.state_eq_opt true
(Vale.X64.Machine_Semantics_s.machine_eval_codes cs f s1)
(Vale.X64.Machine_Semantics_s.machine_eval_codes cs f s2))
[
SMTPat (Vale.X64.Machine_Semantics_s.machine_eval_codes cs f s1);
SMTPat (Vale.X64.Machine_Semantics_s.machine_eval_codes cs f s2)
] | {
"end_col": 66,
"end_line": 286,
"start_col": 2,
"start_line": 286
} |
FStar.Pervasives.Lemma | val eval_code_eq_f (c: code) (f: fuel) (s1 s2: machine_state)
: Lemma (requires state_eq_S false s1 s2)
(ensures state_eq_opt false (BS.machine_eval_code c f s1) (BS.machine_eval_code c f s2))
[SMTPat (BS.machine_eval_code c f s1); SMTPat (BS.machine_eval_code c f s2)] | [
{
"abbrev": true,
"full_module": "Vale.X64.Memory",
"short_module": "ME"
},
{
"abbrev": true,
"full_module": "Vale.X64.Machine_Semantics_s",
"short_module": "BS"
},
{
"abbrev": false,
"full_module": "Vale.X64.Bytes_Code_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Instruction_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.StateLemmas",
"short_module": null
},
{
"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": "FStar.Mul",
"short_module": null
},
{
"abbrev": true,
"full_module": "Vale.Lib.Map16",
"short_module": "Map16"
},
{
"abbrev": true,
"full_module": "Vale.X64.Machine_Semantics_s",
"short_module": "BS"
},
{
"abbrev": false,
"full_module": "Vale.X64.Bytes_Code_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.StateLemmas",
"short_module": null
},
{
"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.HeapLemmas",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.HeapImpl",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Heap",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"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 eval_code_eq_f (c:code) (f:fuel) (s1 s2:machine_state) : Lemma
(requires state_eq_S false s1 s2)
(ensures state_eq_opt false (BS.machine_eval_code c f s1) (BS.machine_eval_code c f s2))
[SMTPat (BS.machine_eval_code c f s1); SMTPat (BS.machine_eval_code c f s2)]
=
eval_code_eq_core false c f s1; eval_code_eq_core false c f s2 | val eval_code_eq_f (c: code) (f: fuel) (s1 s2: machine_state)
: Lemma (requires state_eq_S false s1 s2)
(ensures state_eq_opt false (BS.machine_eval_code c f s1) (BS.machine_eval_code c f s2))
[SMTPat (BS.machine_eval_code c f s1); SMTPat (BS.machine_eval_code c f s2)]
let eval_code_eq_f (c: code) (f: fuel) (s1 s2: machine_state)
: Lemma (requires state_eq_S false s1 s2)
(ensures state_eq_opt false (BS.machine_eval_code c f s1) (BS.machine_eval_code c f s2))
[SMTPat (BS.machine_eval_code c f s1); SMTPat (BS.machine_eval_code c f s2)] = | false | null | true | eval_code_eq_core false c f s1;
eval_code_eq_core false c f s2 | {
"checked_file": "Vale.X64.Lemmas.fst.checked",
"dependencies": [
"Vale.X64.StateLemmas.fsti.checked",
"Vale.X64.State.fsti.checked",
"Vale.X64.Memory.fsti.checked",
"Vale.X64.Machine_Semantics_s.fst.checked",
"Vale.X64.Machine_s.fst.checked",
"Vale.X64.Instruction_s.fsti.checked",
"Vale.X64.Flags.fsti.checked",
"Vale.X64.Bytes_Code_s.fst.checked",
"prims.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.FunctionalExtensionality.fsti.checked"
],
"interface_file": true,
"source_file": "Vale.X64.Lemmas.fst"
} | [
"lemma"
] | [
"Vale.X64.StateLemmas.code",
"Vale.X64.Lemmas.fuel",
"Vale.X64.StateLemmas.machine_state",
"Vale.X64.Lemmas.eval_code_eq_core",
"Prims.unit",
"Vale.X64.Lemmas.state_eq_S",
"Prims.squash",
"Vale.X64.Lemmas.state_eq_opt",
"Vale.X64.Machine_Semantics_s.machine_eval_code",
"Prims.Cons",
"FStar.Pervasives.pattern",
"FStar.Pervasives.smt_pat",
"FStar.Pervasives.Native.option",
"Vale.X64.Machine_Semantics_s.machine_state",
"Prims.Nil"
] | [] | module Vale.X64.Lemmas
open FStar.Mul
open Vale.X64.Machine_s
open Vale.X64.State
open Vale.X64.StateLemmas
open Vale.X64.Instruction_s
open Vale.X64.Bytes_Code_s
module BS = Vale.X64.Machine_Semantics_s
module ME = Vale.X64.Memory
#reset-options "--initial_fuel 1 --max_fuel 1 --z3rlimit 100"
#restart-solver
let rec lemma_eq_instr_apply_eval_args
(outs:list instr_out) (args:list instr_operand)
(f:instr_args_t outs args) (oprs:instr_operands_t_args args) (s1 s2:machine_state)
: Lemma
(requires state_eq_S true s1 s2)
(ensures
BS.instr_apply_eval_args outs args f oprs s1 ==
BS.instr_apply_eval_args outs args f oprs s2)
=
let open BS in
lemma_heap_ignore_ghost_machine s1.BS.ms_heap s2.BS.ms_heap;
match args with
| [] -> ()
| i::args ->
(
let (v, oprs) : option (instr_val_t i) & instr_operands_t_args args =
match i with
| IOpEx i -> let oprs = coerce oprs in (instr_eval_operand_explicit i (fst oprs) s1, snd oprs)
| IOpIm i -> (instr_eval_operand_implicit i s1, coerce oprs)
in
let f:arrow (instr_val_t i) (instr_args_t outs args) = coerce f in
match v with
| None -> ()
| Some v -> lemma_eq_instr_apply_eval_args outs args (f v) oprs s1 s2
)
#restart-solver
let rec lemma_eq_instr_apply_eval_inouts
(outs inouts:list instr_out) (args:list instr_operand)
(f:instr_inouts_t outs inouts args) (oprs:instr_operands_t inouts args) (s1 s2:machine_state)
: Lemma
(requires state_eq_S true s1 s2)
(ensures
BS.instr_apply_eval_inouts outs inouts args f oprs s1 ==
BS.instr_apply_eval_inouts outs inouts args f oprs s2)
=
let open BS in
lemma_heap_ignore_ghost_machine s1.BS.ms_heap s2.BS.ms_heap;
match inouts with
| [] -> lemma_eq_instr_apply_eval_args outs args f oprs s1 s2
| (Out, i)::inouts ->
let oprs =
match i with
| IOpEx i -> snd #(instr_operand_t i) (coerce oprs)
| IOpIm i -> coerce oprs
in
lemma_eq_instr_apply_eval_inouts outs inouts args (coerce f) oprs s1 s2
| (InOut, i)::inouts ->
(
let (v, oprs) : option (instr_val_t i) & instr_operands_t inouts args =
match i with
| IOpEx i -> let oprs = coerce oprs in (instr_eval_operand_explicit i (fst oprs) s1, snd oprs)
| IOpIm i -> (instr_eval_operand_implicit i s1, coerce oprs)
in
let f:arrow (instr_val_t i) (instr_inouts_t outs inouts args) = coerce f in
match v with
| None -> ()
| Some v -> lemma_eq_instr_apply_eval_inouts outs inouts args (f v) oprs s1 s2
)
#restart-solver
#push-options "--z3rlimit_factor 2"
let rec lemma_eq_instr_write_outputs
(outs:list instr_out) (args:list instr_operand)
(vs:instr_ret_t outs) (oprs:instr_operands_t outs args) (s1_orig s1 s2_orig s2:machine_state)
: Lemma
(requires state_eq_S true s1_orig s2_orig /\ state_eq_S true s1 s2)
(ensures
state_eq_S true
(BS.instr_write_outputs outs args vs oprs s1_orig s1)
(BS.instr_write_outputs outs args vs oprs s2_orig s2))
=
let open BS in
use_machine_state_equal ();
lemma_heap_ignore_ghost_machine s1.BS.ms_heap s2.BS.ms_heap;
lemma_heap_ignore_ghost_machine s1_orig.BS.ms_heap s2_orig.BS.ms_heap;
allow_inversion tmaddr;
match outs with
| [] -> ()
| (_, i)::outs ->
(
let ((v:instr_val_t i), (vs:instr_ret_t outs)) =
match outs with
| [] -> (vs, ())
| _::_ -> let vs = coerce vs in (fst vs, snd vs)
in
match i with
| IOpEx i ->
let oprs = coerce oprs in
let s1 = instr_write_output_explicit i v (fst oprs) s1_orig s1 in
let s2 = instr_write_output_explicit i v (fst oprs) s2_orig s2 in
lemma_eq_instr_write_outputs outs args vs (snd oprs) s1_orig s1 s2_orig s2
| IOpIm i ->
let s1 = instr_write_output_implicit i v s1_orig s1 in
let s2 = instr_write_output_implicit i v s2_orig s2 in
allow_inversion operand64;
allow_inversion operand128;
lemma_eq_instr_write_outputs outs args vs (coerce oprs) s1_orig s1 s2_orig s2
)
#pop-options
#restart-solver
let eval_ins_eq_instr (inst:BS.ins) (s1 s2:machine_state) : Lemma
(requires Instr? inst /\ state_eq_S true s1 s2)
(ensures state_eq_S true (BS.machine_eval_ins inst s1) (BS.machine_eval_ins inst s2))
=
let open BS in
let Instr it oprs ann = inst in
let InstrTypeRecord #outs #args #havoc_flags' i = it in
lemma_eq_instr_apply_eval_inouts outs outs args (instr_eval i) oprs s1 s2;
let vs = instr_apply_eval outs args (instr_eval i) oprs s1 in
let hav s =
match havoc_flags' with
| HavocFlags -> {s with ms_flags = havoc_flags}
| PreserveFlags -> s
in
let s1' = hav s1 in
let s2' = hav s2 in
match vs with
| None -> ()
| Some vs -> lemma_eq_instr_write_outputs outs args vs oprs s1 s1' s2 s2'
let eval_code_eq_instr (inst:BS.ins) (f:fuel) (s1 s2:machine_state) : Lemma
(requires Instr? inst /\ state_eq_S true s1 s2)
(ensures state_eq_opt true (BS.machine_eval_code (Ins inst) f s1) (BS.machine_eval_code (Ins inst) f s2))
=
reveal_opaque (`%BS.machine_eval_code_ins) BS.machine_eval_code_ins;
eval_ins_eq_instr inst ({s1 with BS.ms_trace = []}) ({s2 with BS.ms_trace = []})
let eval_code_eq_dealloc (inst:BS.ins) (f:fuel) (s1 s2:machine_state) : Lemma
(requires Dealloc? inst /\ state_eq_S true s1 s2)
(ensures state_eq_opt true (BS.machine_eval_code (Ins inst) f s1) (BS.machine_eval_code (Ins inst) f s2))
=
reveal_opaque (`%BS.machine_eval_code_ins) BS.machine_eval_code_ins;
use_machine_state_equal ();
lemma_heap_ignore_ghost_machine s1.BS.ms_heap s2.BS.ms_heap;
allow_inversion tmaddr
let eval_code_eq_alloc (inst:BS.ins) (f:fuel) (s1 s2:machine_state) : Lemma
(requires Alloc? inst /\ state_eq_S true s1 s2)
(ensures state_eq_opt true (BS.machine_eval_code (Ins inst) f s1) (BS.machine_eval_code (Ins inst) f s2))
=
reveal_opaque (`%BS.machine_eval_code_ins) BS.machine_eval_code_ins;
use_machine_state_equal ();
lemma_heap_ignore_ghost_machine s1.BS.ms_heap s2.BS.ms_heap;
allow_inversion tmaddr
let eval_code_eq_push (inst:BS.ins) (f:fuel) (s1 s2:machine_state) : Lemma
(requires Push? inst /\ state_eq_S true s1 s2)
(ensures state_eq_opt true (BS.machine_eval_code (Ins inst) f s1) (BS.machine_eval_code (Ins inst) f s2))
=
reveal_opaque (`%BS.machine_eval_code_ins) BS.machine_eval_code_ins;
use_machine_state_equal ();
lemma_heap_ignore_ghost_machine s1.BS.ms_heap s2.BS.ms_heap;
allow_inversion tmaddr
let eval_code_eq_pop (inst:BS.ins) (f:fuel) (s1 s2:machine_state) : Lemma
(requires Pop? inst /\ state_eq_S true s1 s2)
(ensures state_eq_opt true (BS.machine_eval_code (Ins inst) f s1) (BS.machine_eval_code (Ins inst) f s2))
=
reveal_opaque (`%BS.machine_eval_code_ins) BS.machine_eval_code_ins;
use_machine_state_equal ();
lemma_heap_ignore_ghost_machine s1.BS.ms_heap s2.BS.ms_heap;
allow_inversion tmaddr
let eval_code_eq_ins (i:BS.ins) (f:fuel) (s1 s2:machine_state) : Lemma
(requires state_eq_S true s1 s2)
(ensures state_eq_opt true (BS.machine_eval_code (Ins i) f s1) (BS.machine_eval_code (Ins i) f s2))
=
match i with
| Instr _ _ _ -> eval_code_eq_instr i f s1 s2
| Dealloc _ -> eval_code_eq_dealloc i f s1 s2
| Alloc _ -> eval_code_eq_alloc i f s1 s2
| Push _ _ -> eval_code_eq_push i f s1 s2
| Pop _ _ -> eval_code_eq_pop i f s1 s2
#reset-options "--fuel 2 --z3rlimit 30"
let eval_ocmp_eq_core (g:bool) (cond:ocmp) (s:machine_state) : Lemma
(ensures (
let (s1, b1) = BS.machine_eval_ocmp s cond in
let (s2, b2) = BS.machine_eval_ocmp (core_state g s) cond in
state_eq_S g s1 s2 /\ b1 == b2
))
=
reveal_opaque (`%BS.valid_ocmp_opaque) BS.valid_ocmp_opaque;
reveal_opaque (`%BS.eval_ocmp_opaque) BS.eval_ocmp_opaque;
()
#restart-solver
let rec eval_code_eq_core (g:bool) (c:code) (f:fuel) (s:machine_state) : Lemma
(ensures state_eq_opt g (BS.machine_eval_code c f s) (BS.machine_eval_code c f (core_state g s)))
(decreases %[f; c])
=
match c with
| Ins i ->
reveal_opaque (`%BS.machine_eval_code_ins) BS.machine_eval_code_ins;
if g then eval_code_eq_ins i f s (core_state g s)
| Block cs -> eval_codes_eq_core g cs f s
| IfElse cond ct cf ->
eval_ocmp_eq_core g cond s;
let (s', _) = BS.machine_eval_ocmp s cond in
let (t', _) = BS.machine_eval_ocmp (core_state g s) cond in
eval_code_eq_core g ct f s';
eval_code_eq_core g ct f t';
eval_code_eq_core g cf f s';
eval_code_eq_core g cf f t';
()
| While cond body -> eval_while_eq_core g cond body f s
and eval_codes_eq_core (g:bool) (cs:codes) (f:fuel) (s:machine_state) : Lemma
(ensures state_eq_opt g (BS.machine_eval_codes cs f s) (BS.machine_eval_codes cs f (core_state g s)))
(decreases %[f; cs])
=
match cs with
| [] -> ()
| c'::cs' -> (
eval_code_eq_core g c' f s;
match (machine_eval_code c' f s, machine_eval_code c' f (core_state g s)) with
| (None, None) -> ()
| (Some s', Some t') -> eval_codes_eq_core g cs' f s'; eval_codes_eq_core g cs' f t'
)
and eval_while_eq_core (g:bool) (cond:ocmp) (body:code) (f:fuel) (s:machine_state) : Lemma
(ensures state_eq_opt g (BS.machine_eval_while cond body f s) (BS.machine_eval_while cond body f (core_state g s)))
(decreases %[f; body])
=
if f > 0 then (
eval_ocmp_eq_core g cond s;
let (s1, _) = BS.machine_eval_ocmp s cond in
let (t1, _) = BS.machine_eval_ocmp (core_state g s) cond in
eval_code_eq_core g body (f - 1) s1;
eval_code_eq_core g body (f - 1) t1;
match (BS.machine_eval_code body (f - 1) s1, BS.machine_eval_code body (f - 1) t1) with
| (None, None) -> ()
| (Some s2, Some t2) ->
eval_while_eq_core g cond body (f - 1) s2;
eval_while_eq_core g cond body (f - 1) t2;
()
)
let eval_code_eq_f (c:code) (f:fuel) (s1 s2:machine_state) : Lemma
(requires state_eq_S false s1 s2)
(ensures state_eq_opt false (BS.machine_eval_code c f s1) (BS.machine_eval_code c f s2))
[SMTPat (BS.machine_eval_code c f s1); SMTPat (BS.machine_eval_code c f s2)] | false | false | Vale.X64.Lemmas.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": 30,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val eval_code_eq_f (c: code) (f: fuel) (s1 s2: machine_state)
: Lemma (requires state_eq_S false s1 s2)
(ensures state_eq_opt false (BS.machine_eval_code c f s1) (BS.machine_eval_code c f s2))
[SMTPat (BS.machine_eval_code c f s1); SMTPat (BS.machine_eval_code c f s2)] | [] | Vale.X64.Lemmas.eval_code_eq_f | {
"file_name": "vale/code/arch/x64/Vale.X64.Lemmas.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} |
c: Vale.X64.StateLemmas.code ->
f: Vale.X64.Lemmas.fuel ->
s1: Vale.X64.StateLemmas.machine_state ->
s2: Vale.X64.StateLemmas.machine_state
-> FStar.Pervasives.Lemma (requires Vale.X64.Lemmas.state_eq_S false s1 s2)
(ensures
Vale.X64.Lemmas.state_eq_opt false
(Vale.X64.Machine_Semantics_s.machine_eval_code c f s1)
(Vale.X64.Machine_Semantics_s.machine_eval_code c f s2))
[
SMTPat (Vale.X64.Machine_Semantics_s.machine_eval_code c f s1);
SMTPat (Vale.X64.Machine_Semantics_s.machine_eval_code c f s2)
] | {
"end_col": 64,
"end_line": 258,
"start_col": 2,
"start_line": 258
} |
Prims.Ghost | val lemma_ifElse_total (ifb:ocmp) (ct:code) (cf:code) (s0:vale_state) : Ghost (bool & vale_state & vale_state & fuel)
(requires True)
(ensures (fun (cond, sM, sN, f0) ->
cond == eval_ocmp s0 ifb /\
sM == {s0 with vs_flags = havoc_flags}
)) | [
{
"abbrev": true,
"full_module": "Vale.X64.Memory",
"short_module": "ME"
},
{
"abbrev": false,
"full_module": "Vale.X64.Instruction_s",
"short_module": null
},
{
"abbrev": true,
"full_module": "Vale.Lib.Map16",
"short_module": "Map16"
},
{
"abbrev": true,
"full_module": "Vale.X64.Machine_Semantics_s",
"short_module": "BS"
},
{
"abbrev": false,
"full_module": "Vale.X64.Bytes_Code_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.StateLemmas",
"short_module": null
},
{
"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.HeapLemmas",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.HeapImpl",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Heap",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"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 lemma_ifElse_total (ifb:ocmp) (ct:code) (cf:code) (s0:vale_state) =
(eval_ocmp s0 ifb, {s0 with vs_flags = havoc_flags}, s0, 0) | val lemma_ifElse_total (ifb:ocmp) (ct:code) (cf:code) (s0:vale_state) : Ghost (bool & vale_state & vale_state & fuel)
(requires True)
(ensures (fun (cond, sM, sN, f0) ->
cond == eval_ocmp s0 ifb /\
sM == {s0 with vs_flags = havoc_flags}
))
let lemma_ifElse_total (ifb: ocmp) (ct cf: code) (s0: vale_state) = | false | null | false | (eval_ocmp s0 ifb, { s0 with vs_flags = havoc_flags }, s0, 0) | {
"checked_file": "Vale.X64.Lemmas.fst.checked",
"dependencies": [
"Vale.X64.StateLemmas.fsti.checked",
"Vale.X64.State.fsti.checked",
"Vale.X64.Memory.fsti.checked",
"Vale.X64.Machine_Semantics_s.fst.checked",
"Vale.X64.Machine_s.fst.checked",
"Vale.X64.Instruction_s.fsti.checked",
"Vale.X64.Flags.fsti.checked",
"Vale.X64.Bytes_Code_s.fst.checked",
"prims.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.FunctionalExtensionality.fsti.checked"
],
"interface_file": true,
"source_file": "Vale.X64.Lemmas.fst"
} | [] | [
"Vale.X64.Bytes_Code_s.ocmp",
"Vale.X64.StateLemmas.code",
"Vale.X64.State.vale_state",
"FStar.Pervasives.Native.Mktuple4",
"Prims.bool",
"Vale.X64.Lemmas.fuel",
"Vale.X64.Lemmas.eval_ocmp",
"Vale.X64.State.Mkvale_state",
"Vale.X64.State.__proj__Mkvale_state__item__vs_ok",
"Vale.X64.State.__proj__Mkvale_state__item__vs_regs",
"Vale.X64.Lemmas.havoc_flags",
"Vale.X64.State.__proj__Mkvale_state__item__vs_heap",
"Vale.X64.State.__proj__Mkvale_state__item__vs_stack",
"Vale.X64.State.__proj__Mkvale_state__item__vs_stackTaint",
"FStar.Pervasives.Native.tuple4"
] | [] | module Vale.X64.Lemmas
open FStar.Mul
open Vale.X64.Machine_s
open Vale.X64.State
open Vale.X64.StateLemmas
open Vale.X64.Instruction_s
open Vale.X64.Bytes_Code_s
module BS = Vale.X64.Machine_Semantics_s
module ME = Vale.X64.Memory
#reset-options "--initial_fuel 1 --max_fuel 1 --z3rlimit 100"
#restart-solver
let rec lemma_eq_instr_apply_eval_args
(outs:list instr_out) (args:list instr_operand)
(f:instr_args_t outs args) (oprs:instr_operands_t_args args) (s1 s2:machine_state)
: Lemma
(requires state_eq_S true s1 s2)
(ensures
BS.instr_apply_eval_args outs args f oprs s1 ==
BS.instr_apply_eval_args outs args f oprs s2)
=
let open BS in
lemma_heap_ignore_ghost_machine s1.BS.ms_heap s2.BS.ms_heap;
match args with
| [] -> ()
| i::args ->
(
let (v, oprs) : option (instr_val_t i) & instr_operands_t_args args =
match i with
| IOpEx i -> let oprs = coerce oprs in (instr_eval_operand_explicit i (fst oprs) s1, snd oprs)
| IOpIm i -> (instr_eval_operand_implicit i s1, coerce oprs)
in
let f:arrow (instr_val_t i) (instr_args_t outs args) = coerce f in
match v with
| None -> ()
| Some v -> lemma_eq_instr_apply_eval_args outs args (f v) oprs s1 s2
)
#restart-solver
let rec lemma_eq_instr_apply_eval_inouts
(outs inouts:list instr_out) (args:list instr_operand)
(f:instr_inouts_t outs inouts args) (oprs:instr_operands_t inouts args) (s1 s2:machine_state)
: Lemma
(requires state_eq_S true s1 s2)
(ensures
BS.instr_apply_eval_inouts outs inouts args f oprs s1 ==
BS.instr_apply_eval_inouts outs inouts args f oprs s2)
=
let open BS in
lemma_heap_ignore_ghost_machine s1.BS.ms_heap s2.BS.ms_heap;
match inouts with
| [] -> lemma_eq_instr_apply_eval_args outs args f oprs s1 s2
| (Out, i)::inouts ->
let oprs =
match i with
| IOpEx i -> snd #(instr_operand_t i) (coerce oprs)
| IOpIm i -> coerce oprs
in
lemma_eq_instr_apply_eval_inouts outs inouts args (coerce f) oprs s1 s2
| (InOut, i)::inouts ->
(
let (v, oprs) : option (instr_val_t i) & instr_operands_t inouts args =
match i with
| IOpEx i -> let oprs = coerce oprs in (instr_eval_operand_explicit i (fst oprs) s1, snd oprs)
| IOpIm i -> (instr_eval_operand_implicit i s1, coerce oprs)
in
let f:arrow (instr_val_t i) (instr_inouts_t outs inouts args) = coerce f in
match v with
| None -> ()
| Some v -> lemma_eq_instr_apply_eval_inouts outs inouts args (f v) oprs s1 s2
)
#restart-solver
#push-options "--z3rlimit_factor 2"
let rec lemma_eq_instr_write_outputs
(outs:list instr_out) (args:list instr_operand)
(vs:instr_ret_t outs) (oprs:instr_operands_t outs args) (s1_orig s1 s2_orig s2:machine_state)
: Lemma
(requires state_eq_S true s1_orig s2_orig /\ state_eq_S true s1 s2)
(ensures
state_eq_S true
(BS.instr_write_outputs outs args vs oprs s1_orig s1)
(BS.instr_write_outputs outs args vs oprs s2_orig s2))
=
let open BS in
use_machine_state_equal ();
lemma_heap_ignore_ghost_machine s1.BS.ms_heap s2.BS.ms_heap;
lemma_heap_ignore_ghost_machine s1_orig.BS.ms_heap s2_orig.BS.ms_heap;
allow_inversion tmaddr;
match outs with
| [] -> ()
| (_, i)::outs ->
(
let ((v:instr_val_t i), (vs:instr_ret_t outs)) =
match outs with
| [] -> (vs, ())
| _::_ -> let vs = coerce vs in (fst vs, snd vs)
in
match i with
| IOpEx i ->
let oprs = coerce oprs in
let s1 = instr_write_output_explicit i v (fst oprs) s1_orig s1 in
let s2 = instr_write_output_explicit i v (fst oprs) s2_orig s2 in
lemma_eq_instr_write_outputs outs args vs (snd oprs) s1_orig s1 s2_orig s2
| IOpIm i ->
let s1 = instr_write_output_implicit i v s1_orig s1 in
let s2 = instr_write_output_implicit i v s2_orig s2 in
allow_inversion operand64;
allow_inversion operand128;
lemma_eq_instr_write_outputs outs args vs (coerce oprs) s1_orig s1 s2_orig s2
)
#pop-options
#restart-solver
let eval_ins_eq_instr (inst:BS.ins) (s1 s2:machine_state) : Lemma
(requires Instr? inst /\ state_eq_S true s1 s2)
(ensures state_eq_S true (BS.machine_eval_ins inst s1) (BS.machine_eval_ins inst s2))
=
let open BS in
let Instr it oprs ann = inst in
let InstrTypeRecord #outs #args #havoc_flags' i = it in
lemma_eq_instr_apply_eval_inouts outs outs args (instr_eval i) oprs s1 s2;
let vs = instr_apply_eval outs args (instr_eval i) oprs s1 in
let hav s =
match havoc_flags' with
| HavocFlags -> {s with ms_flags = havoc_flags}
| PreserveFlags -> s
in
let s1' = hav s1 in
let s2' = hav s2 in
match vs with
| None -> ()
| Some vs -> lemma_eq_instr_write_outputs outs args vs oprs s1 s1' s2 s2'
let eval_code_eq_instr (inst:BS.ins) (f:fuel) (s1 s2:machine_state) : Lemma
(requires Instr? inst /\ state_eq_S true s1 s2)
(ensures state_eq_opt true (BS.machine_eval_code (Ins inst) f s1) (BS.machine_eval_code (Ins inst) f s2))
=
reveal_opaque (`%BS.machine_eval_code_ins) BS.machine_eval_code_ins;
eval_ins_eq_instr inst ({s1 with BS.ms_trace = []}) ({s2 with BS.ms_trace = []})
let eval_code_eq_dealloc (inst:BS.ins) (f:fuel) (s1 s2:machine_state) : Lemma
(requires Dealloc? inst /\ state_eq_S true s1 s2)
(ensures state_eq_opt true (BS.machine_eval_code (Ins inst) f s1) (BS.machine_eval_code (Ins inst) f s2))
=
reveal_opaque (`%BS.machine_eval_code_ins) BS.machine_eval_code_ins;
use_machine_state_equal ();
lemma_heap_ignore_ghost_machine s1.BS.ms_heap s2.BS.ms_heap;
allow_inversion tmaddr
let eval_code_eq_alloc (inst:BS.ins) (f:fuel) (s1 s2:machine_state) : Lemma
(requires Alloc? inst /\ state_eq_S true s1 s2)
(ensures state_eq_opt true (BS.machine_eval_code (Ins inst) f s1) (BS.machine_eval_code (Ins inst) f s2))
=
reveal_opaque (`%BS.machine_eval_code_ins) BS.machine_eval_code_ins;
use_machine_state_equal ();
lemma_heap_ignore_ghost_machine s1.BS.ms_heap s2.BS.ms_heap;
allow_inversion tmaddr
let eval_code_eq_push (inst:BS.ins) (f:fuel) (s1 s2:machine_state) : Lemma
(requires Push? inst /\ state_eq_S true s1 s2)
(ensures state_eq_opt true (BS.machine_eval_code (Ins inst) f s1) (BS.machine_eval_code (Ins inst) f s2))
=
reveal_opaque (`%BS.machine_eval_code_ins) BS.machine_eval_code_ins;
use_machine_state_equal ();
lemma_heap_ignore_ghost_machine s1.BS.ms_heap s2.BS.ms_heap;
allow_inversion tmaddr
let eval_code_eq_pop (inst:BS.ins) (f:fuel) (s1 s2:machine_state) : Lemma
(requires Pop? inst /\ state_eq_S true s1 s2)
(ensures state_eq_opt true (BS.machine_eval_code (Ins inst) f s1) (BS.machine_eval_code (Ins inst) f s2))
=
reveal_opaque (`%BS.machine_eval_code_ins) BS.machine_eval_code_ins;
use_machine_state_equal ();
lemma_heap_ignore_ghost_machine s1.BS.ms_heap s2.BS.ms_heap;
allow_inversion tmaddr
let eval_code_eq_ins (i:BS.ins) (f:fuel) (s1 s2:machine_state) : Lemma
(requires state_eq_S true s1 s2)
(ensures state_eq_opt true (BS.machine_eval_code (Ins i) f s1) (BS.machine_eval_code (Ins i) f s2))
=
match i with
| Instr _ _ _ -> eval_code_eq_instr i f s1 s2
| Dealloc _ -> eval_code_eq_dealloc i f s1 s2
| Alloc _ -> eval_code_eq_alloc i f s1 s2
| Push _ _ -> eval_code_eq_push i f s1 s2
| Pop _ _ -> eval_code_eq_pop i f s1 s2
#reset-options "--fuel 2 --z3rlimit 30"
let eval_ocmp_eq_core (g:bool) (cond:ocmp) (s:machine_state) : Lemma
(ensures (
let (s1, b1) = BS.machine_eval_ocmp s cond in
let (s2, b2) = BS.machine_eval_ocmp (core_state g s) cond in
state_eq_S g s1 s2 /\ b1 == b2
))
=
reveal_opaque (`%BS.valid_ocmp_opaque) BS.valid_ocmp_opaque;
reveal_opaque (`%BS.eval_ocmp_opaque) BS.eval_ocmp_opaque;
()
#restart-solver
let rec eval_code_eq_core (g:bool) (c:code) (f:fuel) (s:machine_state) : Lemma
(ensures state_eq_opt g (BS.machine_eval_code c f s) (BS.machine_eval_code c f (core_state g s)))
(decreases %[f; c])
=
match c with
| Ins i ->
reveal_opaque (`%BS.machine_eval_code_ins) BS.machine_eval_code_ins;
if g then eval_code_eq_ins i f s (core_state g s)
| Block cs -> eval_codes_eq_core g cs f s
| IfElse cond ct cf ->
eval_ocmp_eq_core g cond s;
let (s', _) = BS.machine_eval_ocmp s cond in
let (t', _) = BS.machine_eval_ocmp (core_state g s) cond in
eval_code_eq_core g ct f s';
eval_code_eq_core g ct f t';
eval_code_eq_core g cf f s';
eval_code_eq_core g cf f t';
()
| While cond body -> eval_while_eq_core g cond body f s
and eval_codes_eq_core (g:bool) (cs:codes) (f:fuel) (s:machine_state) : Lemma
(ensures state_eq_opt g (BS.machine_eval_codes cs f s) (BS.machine_eval_codes cs f (core_state g s)))
(decreases %[f; cs])
=
match cs with
| [] -> ()
| c'::cs' -> (
eval_code_eq_core g c' f s;
match (machine_eval_code c' f s, machine_eval_code c' f (core_state g s)) with
| (None, None) -> ()
| (Some s', Some t') -> eval_codes_eq_core g cs' f s'; eval_codes_eq_core g cs' f t'
)
and eval_while_eq_core (g:bool) (cond:ocmp) (body:code) (f:fuel) (s:machine_state) : Lemma
(ensures state_eq_opt g (BS.machine_eval_while cond body f s) (BS.machine_eval_while cond body f (core_state g s)))
(decreases %[f; body])
=
if f > 0 then (
eval_ocmp_eq_core g cond s;
let (s1, _) = BS.machine_eval_ocmp s cond in
let (t1, _) = BS.machine_eval_ocmp (core_state g s) cond in
eval_code_eq_core g body (f - 1) s1;
eval_code_eq_core g body (f - 1) t1;
match (BS.machine_eval_code body (f - 1) s1, BS.machine_eval_code body (f - 1) t1) with
| (None, None) -> ()
| (Some s2, Some t2) ->
eval_while_eq_core g cond body (f - 1) s2;
eval_while_eq_core g cond body (f - 1) t2;
()
)
let eval_code_eq_f (c:code) (f:fuel) (s1 s2:machine_state) : Lemma
(requires state_eq_S false s1 s2)
(ensures state_eq_opt false (BS.machine_eval_code c f s1) (BS.machine_eval_code c f s2))
[SMTPat (BS.machine_eval_code c f s1); SMTPat (BS.machine_eval_code c f s2)]
=
eval_code_eq_core false c f s1; eval_code_eq_core false c f s2
let eval_codes_eq_f (cs:codes) (f:fuel) (s1 s2:machine_state) : Lemma
(requires state_eq_S false s1 s2)
(ensures state_eq_opt false (BS.machine_eval_codes cs f s1) (BS.machine_eval_codes cs f s2))
[SMTPat (BS.machine_eval_codes cs f s1); SMTPat (BS.machine_eval_codes cs f s2)]
=
eval_codes_eq_core false cs f s1; eval_codes_eq_core false cs f s2
let eval_while_eq_f (cond:ocmp) (body:code) (f:fuel) (s1 s2:machine_state) : Lemma
(requires state_eq_S false s1 s2)
(ensures state_eq_opt false (BS.machine_eval_while cond body f s1) (BS.machine_eval_while cond body f s2))
[SMTPat (BS.machine_eval_while cond body f s1); SMTPat (BS.machine_eval_while cond body f s2)]
=
eval_while_eq_core false cond body f s1; eval_while_eq_core false cond body f s2
let eval_code_eq_t (c:code) (f:fuel) (s1 s2:machine_state) : Lemma
(requires state_eq_S true s1 s2)
(ensures state_eq_opt true (BS.machine_eval_code c f s1) (BS.machine_eval_code c f s2))
[SMTPat (BS.machine_eval_code c f s1); SMTPat (BS.machine_eval_code c f s2)]
=
eval_code_eq_core true c f s1; eval_code_eq_core true c f s2
let eval_codes_eq_t (cs:codes) (f:fuel) (s1 s2:machine_state) : Lemma
(requires state_eq_S true s1 s2)
(ensures state_eq_opt true (BS.machine_eval_codes cs f s1) (BS.machine_eval_codes cs f s2))
[SMTPat (BS.machine_eval_codes cs f s1); SMTPat (BS.machine_eval_codes cs f s2)]
=
eval_codes_eq_core true cs f s1; eval_codes_eq_core true cs f s2
let eval_while_eq_t (cond:ocmp) (body:code) (f:fuel) (s1 s2:machine_state) : Lemma
(requires state_eq_S true s1 s2)
(ensures state_eq_opt true (BS.machine_eval_while cond body f s1) (BS.machine_eval_while cond body f s2))
[SMTPat (BS.machine_eval_while cond body f s1); SMTPat (BS.machine_eval_while cond body f s2)]
=
eval_while_eq_core true cond body f s1; eval_while_eq_core true cond body f s2
let eval_code_ts (g:bool) (c:code) (s0:machine_state) (f0:fuel) (s1:machine_state) : Type0 =
state_eq_opt g (BS.machine_eval_code c f0 s0) (Some s1)
let rec increase_fuel (g:bool) (c:code) (s0:machine_state) (f0:fuel) (sN:machine_state) (fN:fuel) : Lemma
(requires eval_code_ts g c s0 f0 sN /\ f0 <= fN)
(ensures eval_code_ts g c s0 fN sN)
(decreases %[f0; c])
=
match c with
| Ins ins -> ()
| Block l -> increase_fuels g l s0 f0 sN fN
| IfElse cond t f ->
let (s0, b0) = BS.machine_eval_ocmp s0 cond in
if b0 then increase_fuel g t s0 f0 sN fN else increase_fuel g f s0 f0 sN fN
| While cond c ->
let (s1, b0) = BS.machine_eval_ocmp s0 cond in
if b0 then (
match BS.machine_eval_code c (f0 - 1) s1 with
| None -> ()
| Some s2 ->
increase_fuel g c s1 (f0 - 1) s2 (fN - 1);
if s2.BS.ms_ok then increase_fuel g (While cond c) s2 (f0 - 1) sN (fN - 1)
else ()
)
and increase_fuels (g:bool) (c:codes) (s0:machine_state) (f0:fuel) (sN:machine_state) (fN:fuel) : Lemma
(requires eval_code_ts g (Block c) s0 f0 sN /\ f0 <= fN)
(ensures eval_code_ts g (Block c) s0 fN sN)
(decreases %[f0; c])
=
match c with
| [] -> ()
| h::t ->
(
let Some s1 = BS.machine_eval_code h f0 s0 in
increase_fuel g h s0 f0 s1 fN;
increase_fuels g t s1 f0 sN fN
)
let lemma_cmp_eq s o1 o2 = reveal_opaque (`%BS.eval_ocmp_opaque) BS.eval_ocmp_opaque
let lemma_cmp_ne s o1 o2 = reveal_opaque (`%BS.eval_ocmp_opaque) BS.eval_ocmp_opaque
let lemma_cmp_le s o1 o2 = reveal_opaque (`%BS.eval_ocmp_opaque) BS.eval_ocmp_opaque
let lemma_cmp_ge s o1 o2 = reveal_opaque (`%BS.eval_ocmp_opaque) BS.eval_ocmp_opaque
let lemma_cmp_lt s o1 o2 = reveal_opaque (`%BS.eval_ocmp_opaque) BS.eval_ocmp_opaque
let lemma_cmp_gt s o1 o2 = reveal_opaque (`%BS.eval_ocmp_opaque) BS.eval_ocmp_opaque
let lemma_valid_cmp_eq s o1 o2 = ()
let lemma_valid_cmp_ne s o1 o2 = ()
let lemma_valid_cmp_le s o1 o2 = ()
let lemma_valid_cmp_ge s o1 o2 = ()
let lemma_valid_cmp_lt s o1 o2 = ()
let lemma_valid_cmp_gt s o1 o2 = ()
let compute_merge_total (f0:fuel) (fM:fuel) =
if f0 > fM then f0 else fM
let lemma_merge_total (b0:codes) (s0:vale_state) (f0:fuel) (sM:vale_state) (fM:fuel) (sN:vale_state) =
let f = if f0 > fM then f0 else fM in
increase_fuel (codes_modifies_ghost b0) (Cons?.hd b0) (state_to_S s0) f0 (state_to_S sM) f;
increase_fuel (codes_modifies_ghost b0) (Block (Cons?.tl b0)) (state_to_S sM) fM (state_to_S sN) f
let lemma_empty_total (s0:vale_state) (bN:codes) =
(s0, 0) | false | false | Vale.X64.Lemmas.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": 30,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val lemma_ifElse_total (ifb:ocmp) (ct:code) (cf:code) (s0:vale_state) : Ghost (bool & vale_state & vale_state & fuel)
(requires True)
(ensures (fun (cond, sM, sN, f0) ->
cond == eval_ocmp s0 ifb /\
sM == {s0 with vs_flags = havoc_flags}
)) | [] | Vale.X64.Lemmas.lemma_ifElse_total | {
"file_name": "vale/code/arch/x64/Vale.X64.Lemmas.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} |
ifb: Vale.X64.Bytes_Code_s.ocmp ->
ct: Vale.X64.StateLemmas.code ->
cf: Vale.X64.StateLemmas.code ->
s0: Vale.X64.State.vale_state
-> Prims.Ghost
(((Prims.bool * Vale.X64.State.vale_state) * Vale.X64.State.vale_state) * Vale.X64.Lemmas.fuel) | {
"end_col": 61,
"end_line": 359,
"start_col": 2,
"start_line": 359
} |
FStar.Pervasives.Lemma | val eval_code_eq_t (c: code) (f: fuel) (s1 s2: machine_state)
: Lemma (requires state_eq_S true s1 s2)
(ensures state_eq_opt true (BS.machine_eval_code c f s1) (BS.machine_eval_code c f s2))
[SMTPat (BS.machine_eval_code c f s1); SMTPat (BS.machine_eval_code c f s2)] | [
{
"abbrev": true,
"full_module": "Vale.X64.Memory",
"short_module": "ME"
},
{
"abbrev": true,
"full_module": "Vale.X64.Machine_Semantics_s",
"short_module": "BS"
},
{
"abbrev": false,
"full_module": "Vale.X64.Bytes_Code_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Instruction_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.StateLemmas",
"short_module": null
},
{
"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": "FStar.Mul",
"short_module": null
},
{
"abbrev": true,
"full_module": "Vale.Lib.Map16",
"short_module": "Map16"
},
{
"abbrev": true,
"full_module": "Vale.X64.Machine_Semantics_s",
"short_module": "BS"
},
{
"abbrev": false,
"full_module": "Vale.X64.Bytes_Code_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.StateLemmas",
"short_module": null
},
{
"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.HeapLemmas",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.HeapImpl",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Heap",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"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 eval_code_eq_t (c:code) (f:fuel) (s1 s2:machine_state) : Lemma
(requires state_eq_S true s1 s2)
(ensures state_eq_opt true (BS.machine_eval_code c f s1) (BS.machine_eval_code c f s2))
[SMTPat (BS.machine_eval_code c f s1); SMTPat (BS.machine_eval_code c f s2)]
=
eval_code_eq_core true c f s1; eval_code_eq_core true c f s2 | val eval_code_eq_t (c: code) (f: fuel) (s1 s2: machine_state)
: Lemma (requires state_eq_S true s1 s2)
(ensures state_eq_opt true (BS.machine_eval_code c f s1) (BS.machine_eval_code c f s2))
[SMTPat (BS.machine_eval_code c f s1); SMTPat (BS.machine_eval_code c f s2)]
let eval_code_eq_t (c: code) (f: fuel) (s1 s2: machine_state)
: Lemma (requires state_eq_S true s1 s2)
(ensures state_eq_opt true (BS.machine_eval_code c f s1) (BS.machine_eval_code c f s2))
[SMTPat (BS.machine_eval_code c f s1); SMTPat (BS.machine_eval_code c f s2)] = | false | null | true | eval_code_eq_core true c f s1;
eval_code_eq_core true c f s2 | {
"checked_file": "Vale.X64.Lemmas.fst.checked",
"dependencies": [
"Vale.X64.StateLemmas.fsti.checked",
"Vale.X64.State.fsti.checked",
"Vale.X64.Memory.fsti.checked",
"Vale.X64.Machine_Semantics_s.fst.checked",
"Vale.X64.Machine_s.fst.checked",
"Vale.X64.Instruction_s.fsti.checked",
"Vale.X64.Flags.fsti.checked",
"Vale.X64.Bytes_Code_s.fst.checked",
"prims.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.FunctionalExtensionality.fsti.checked"
],
"interface_file": true,
"source_file": "Vale.X64.Lemmas.fst"
} | [
"lemma"
] | [
"Vale.X64.StateLemmas.code",
"Vale.X64.Lemmas.fuel",
"Vale.X64.StateLemmas.machine_state",
"Vale.X64.Lemmas.eval_code_eq_core",
"Prims.unit",
"Vale.X64.Lemmas.state_eq_S",
"Prims.squash",
"Vale.X64.Lemmas.state_eq_opt",
"Vale.X64.Machine_Semantics_s.machine_eval_code",
"Prims.Cons",
"FStar.Pervasives.pattern",
"FStar.Pervasives.smt_pat",
"FStar.Pervasives.Native.option",
"Vale.X64.Machine_Semantics_s.machine_state",
"Prims.Nil"
] | [] | module Vale.X64.Lemmas
open FStar.Mul
open Vale.X64.Machine_s
open Vale.X64.State
open Vale.X64.StateLemmas
open Vale.X64.Instruction_s
open Vale.X64.Bytes_Code_s
module BS = Vale.X64.Machine_Semantics_s
module ME = Vale.X64.Memory
#reset-options "--initial_fuel 1 --max_fuel 1 --z3rlimit 100"
#restart-solver
let rec lemma_eq_instr_apply_eval_args
(outs:list instr_out) (args:list instr_operand)
(f:instr_args_t outs args) (oprs:instr_operands_t_args args) (s1 s2:machine_state)
: Lemma
(requires state_eq_S true s1 s2)
(ensures
BS.instr_apply_eval_args outs args f oprs s1 ==
BS.instr_apply_eval_args outs args f oprs s2)
=
let open BS in
lemma_heap_ignore_ghost_machine s1.BS.ms_heap s2.BS.ms_heap;
match args with
| [] -> ()
| i::args ->
(
let (v, oprs) : option (instr_val_t i) & instr_operands_t_args args =
match i with
| IOpEx i -> let oprs = coerce oprs in (instr_eval_operand_explicit i (fst oprs) s1, snd oprs)
| IOpIm i -> (instr_eval_operand_implicit i s1, coerce oprs)
in
let f:arrow (instr_val_t i) (instr_args_t outs args) = coerce f in
match v with
| None -> ()
| Some v -> lemma_eq_instr_apply_eval_args outs args (f v) oprs s1 s2
)
#restart-solver
let rec lemma_eq_instr_apply_eval_inouts
(outs inouts:list instr_out) (args:list instr_operand)
(f:instr_inouts_t outs inouts args) (oprs:instr_operands_t inouts args) (s1 s2:machine_state)
: Lemma
(requires state_eq_S true s1 s2)
(ensures
BS.instr_apply_eval_inouts outs inouts args f oprs s1 ==
BS.instr_apply_eval_inouts outs inouts args f oprs s2)
=
let open BS in
lemma_heap_ignore_ghost_machine s1.BS.ms_heap s2.BS.ms_heap;
match inouts with
| [] -> lemma_eq_instr_apply_eval_args outs args f oprs s1 s2
| (Out, i)::inouts ->
let oprs =
match i with
| IOpEx i -> snd #(instr_operand_t i) (coerce oprs)
| IOpIm i -> coerce oprs
in
lemma_eq_instr_apply_eval_inouts outs inouts args (coerce f) oprs s1 s2
| (InOut, i)::inouts ->
(
let (v, oprs) : option (instr_val_t i) & instr_operands_t inouts args =
match i with
| IOpEx i -> let oprs = coerce oprs in (instr_eval_operand_explicit i (fst oprs) s1, snd oprs)
| IOpIm i -> (instr_eval_operand_implicit i s1, coerce oprs)
in
let f:arrow (instr_val_t i) (instr_inouts_t outs inouts args) = coerce f in
match v with
| None -> ()
| Some v -> lemma_eq_instr_apply_eval_inouts outs inouts args (f v) oprs s1 s2
)
#restart-solver
#push-options "--z3rlimit_factor 2"
let rec lemma_eq_instr_write_outputs
(outs:list instr_out) (args:list instr_operand)
(vs:instr_ret_t outs) (oprs:instr_operands_t outs args) (s1_orig s1 s2_orig s2:machine_state)
: Lemma
(requires state_eq_S true s1_orig s2_orig /\ state_eq_S true s1 s2)
(ensures
state_eq_S true
(BS.instr_write_outputs outs args vs oprs s1_orig s1)
(BS.instr_write_outputs outs args vs oprs s2_orig s2))
=
let open BS in
use_machine_state_equal ();
lemma_heap_ignore_ghost_machine s1.BS.ms_heap s2.BS.ms_heap;
lemma_heap_ignore_ghost_machine s1_orig.BS.ms_heap s2_orig.BS.ms_heap;
allow_inversion tmaddr;
match outs with
| [] -> ()
| (_, i)::outs ->
(
let ((v:instr_val_t i), (vs:instr_ret_t outs)) =
match outs with
| [] -> (vs, ())
| _::_ -> let vs = coerce vs in (fst vs, snd vs)
in
match i with
| IOpEx i ->
let oprs = coerce oprs in
let s1 = instr_write_output_explicit i v (fst oprs) s1_orig s1 in
let s2 = instr_write_output_explicit i v (fst oprs) s2_orig s2 in
lemma_eq_instr_write_outputs outs args vs (snd oprs) s1_orig s1 s2_orig s2
| IOpIm i ->
let s1 = instr_write_output_implicit i v s1_orig s1 in
let s2 = instr_write_output_implicit i v s2_orig s2 in
allow_inversion operand64;
allow_inversion operand128;
lemma_eq_instr_write_outputs outs args vs (coerce oprs) s1_orig s1 s2_orig s2
)
#pop-options
#restart-solver
let eval_ins_eq_instr (inst:BS.ins) (s1 s2:machine_state) : Lemma
(requires Instr? inst /\ state_eq_S true s1 s2)
(ensures state_eq_S true (BS.machine_eval_ins inst s1) (BS.machine_eval_ins inst s2))
=
let open BS in
let Instr it oprs ann = inst in
let InstrTypeRecord #outs #args #havoc_flags' i = it in
lemma_eq_instr_apply_eval_inouts outs outs args (instr_eval i) oprs s1 s2;
let vs = instr_apply_eval outs args (instr_eval i) oprs s1 in
let hav s =
match havoc_flags' with
| HavocFlags -> {s with ms_flags = havoc_flags}
| PreserveFlags -> s
in
let s1' = hav s1 in
let s2' = hav s2 in
match vs with
| None -> ()
| Some vs -> lemma_eq_instr_write_outputs outs args vs oprs s1 s1' s2 s2'
let eval_code_eq_instr (inst:BS.ins) (f:fuel) (s1 s2:machine_state) : Lemma
(requires Instr? inst /\ state_eq_S true s1 s2)
(ensures state_eq_opt true (BS.machine_eval_code (Ins inst) f s1) (BS.machine_eval_code (Ins inst) f s2))
=
reveal_opaque (`%BS.machine_eval_code_ins) BS.machine_eval_code_ins;
eval_ins_eq_instr inst ({s1 with BS.ms_trace = []}) ({s2 with BS.ms_trace = []})
let eval_code_eq_dealloc (inst:BS.ins) (f:fuel) (s1 s2:machine_state) : Lemma
(requires Dealloc? inst /\ state_eq_S true s1 s2)
(ensures state_eq_opt true (BS.machine_eval_code (Ins inst) f s1) (BS.machine_eval_code (Ins inst) f s2))
=
reveal_opaque (`%BS.machine_eval_code_ins) BS.machine_eval_code_ins;
use_machine_state_equal ();
lemma_heap_ignore_ghost_machine s1.BS.ms_heap s2.BS.ms_heap;
allow_inversion tmaddr
let eval_code_eq_alloc (inst:BS.ins) (f:fuel) (s1 s2:machine_state) : Lemma
(requires Alloc? inst /\ state_eq_S true s1 s2)
(ensures state_eq_opt true (BS.machine_eval_code (Ins inst) f s1) (BS.machine_eval_code (Ins inst) f s2))
=
reveal_opaque (`%BS.machine_eval_code_ins) BS.machine_eval_code_ins;
use_machine_state_equal ();
lemma_heap_ignore_ghost_machine s1.BS.ms_heap s2.BS.ms_heap;
allow_inversion tmaddr
let eval_code_eq_push (inst:BS.ins) (f:fuel) (s1 s2:machine_state) : Lemma
(requires Push? inst /\ state_eq_S true s1 s2)
(ensures state_eq_opt true (BS.machine_eval_code (Ins inst) f s1) (BS.machine_eval_code (Ins inst) f s2))
=
reveal_opaque (`%BS.machine_eval_code_ins) BS.machine_eval_code_ins;
use_machine_state_equal ();
lemma_heap_ignore_ghost_machine s1.BS.ms_heap s2.BS.ms_heap;
allow_inversion tmaddr
let eval_code_eq_pop (inst:BS.ins) (f:fuel) (s1 s2:machine_state) : Lemma
(requires Pop? inst /\ state_eq_S true s1 s2)
(ensures state_eq_opt true (BS.machine_eval_code (Ins inst) f s1) (BS.machine_eval_code (Ins inst) f s2))
=
reveal_opaque (`%BS.machine_eval_code_ins) BS.machine_eval_code_ins;
use_machine_state_equal ();
lemma_heap_ignore_ghost_machine s1.BS.ms_heap s2.BS.ms_heap;
allow_inversion tmaddr
let eval_code_eq_ins (i:BS.ins) (f:fuel) (s1 s2:machine_state) : Lemma
(requires state_eq_S true s1 s2)
(ensures state_eq_opt true (BS.machine_eval_code (Ins i) f s1) (BS.machine_eval_code (Ins i) f s2))
=
match i with
| Instr _ _ _ -> eval_code_eq_instr i f s1 s2
| Dealloc _ -> eval_code_eq_dealloc i f s1 s2
| Alloc _ -> eval_code_eq_alloc i f s1 s2
| Push _ _ -> eval_code_eq_push i f s1 s2
| Pop _ _ -> eval_code_eq_pop i f s1 s2
#reset-options "--fuel 2 --z3rlimit 30"
let eval_ocmp_eq_core (g:bool) (cond:ocmp) (s:machine_state) : Lemma
(ensures (
let (s1, b1) = BS.machine_eval_ocmp s cond in
let (s2, b2) = BS.machine_eval_ocmp (core_state g s) cond in
state_eq_S g s1 s2 /\ b1 == b2
))
=
reveal_opaque (`%BS.valid_ocmp_opaque) BS.valid_ocmp_opaque;
reveal_opaque (`%BS.eval_ocmp_opaque) BS.eval_ocmp_opaque;
()
#restart-solver
let rec eval_code_eq_core (g:bool) (c:code) (f:fuel) (s:machine_state) : Lemma
(ensures state_eq_opt g (BS.machine_eval_code c f s) (BS.machine_eval_code c f (core_state g s)))
(decreases %[f; c])
=
match c with
| Ins i ->
reveal_opaque (`%BS.machine_eval_code_ins) BS.machine_eval_code_ins;
if g then eval_code_eq_ins i f s (core_state g s)
| Block cs -> eval_codes_eq_core g cs f s
| IfElse cond ct cf ->
eval_ocmp_eq_core g cond s;
let (s', _) = BS.machine_eval_ocmp s cond in
let (t', _) = BS.machine_eval_ocmp (core_state g s) cond in
eval_code_eq_core g ct f s';
eval_code_eq_core g ct f t';
eval_code_eq_core g cf f s';
eval_code_eq_core g cf f t';
()
| While cond body -> eval_while_eq_core g cond body f s
and eval_codes_eq_core (g:bool) (cs:codes) (f:fuel) (s:machine_state) : Lemma
(ensures state_eq_opt g (BS.machine_eval_codes cs f s) (BS.machine_eval_codes cs f (core_state g s)))
(decreases %[f; cs])
=
match cs with
| [] -> ()
| c'::cs' -> (
eval_code_eq_core g c' f s;
match (machine_eval_code c' f s, machine_eval_code c' f (core_state g s)) with
| (None, None) -> ()
| (Some s', Some t') -> eval_codes_eq_core g cs' f s'; eval_codes_eq_core g cs' f t'
)
and eval_while_eq_core (g:bool) (cond:ocmp) (body:code) (f:fuel) (s:machine_state) : Lemma
(ensures state_eq_opt g (BS.machine_eval_while cond body f s) (BS.machine_eval_while cond body f (core_state g s)))
(decreases %[f; body])
=
if f > 0 then (
eval_ocmp_eq_core g cond s;
let (s1, _) = BS.machine_eval_ocmp s cond in
let (t1, _) = BS.machine_eval_ocmp (core_state g s) cond in
eval_code_eq_core g body (f - 1) s1;
eval_code_eq_core g body (f - 1) t1;
match (BS.machine_eval_code body (f - 1) s1, BS.machine_eval_code body (f - 1) t1) with
| (None, None) -> ()
| (Some s2, Some t2) ->
eval_while_eq_core g cond body (f - 1) s2;
eval_while_eq_core g cond body (f - 1) t2;
()
)
let eval_code_eq_f (c:code) (f:fuel) (s1 s2:machine_state) : Lemma
(requires state_eq_S false s1 s2)
(ensures state_eq_opt false (BS.machine_eval_code c f s1) (BS.machine_eval_code c f s2))
[SMTPat (BS.machine_eval_code c f s1); SMTPat (BS.machine_eval_code c f s2)]
=
eval_code_eq_core false c f s1; eval_code_eq_core false c f s2
let eval_codes_eq_f (cs:codes) (f:fuel) (s1 s2:machine_state) : Lemma
(requires state_eq_S false s1 s2)
(ensures state_eq_opt false (BS.machine_eval_codes cs f s1) (BS.machine_eval_codes cs f s2))
[SMTPat (BS.machine_eval_codes cs f s1); SMTPat (BS.machine_eval_codes cs f s2)]
=
eval_codes_eq_core false cs f s1; eval_codes_eq_core false cs f s2
let eval_while_eq_f (cond:ocmp) (body:code) (f:fuel) (s1 s2:machine_state) : Lemma
(requires state_eq_S false s1 s2)
(ensures state_eq_opt false (BS.machine_eval_while cond body f s1) (BS.machine_eval_while cond body f s2))
[SMTPat (BS.machine_eval_while cond body f s1); SMTPat (BS.machine_eval_while cond body f s2)]
=
eval_while_eq_core false cond body f s1; eval_while_eq_core false cond body f s2
let eval_code_eq_t (c:code) (f:fuel) (s1 s2:machine_state) : Lemma
(requires state_eq_S true s1 s2)
(ensures state_eq_opt true (BS.machine_eval_code c f s1) (BS.machine_eval_code c f s2))
[SMTPat (BS.machine_eval_code c f s1); SMTPat (BS.machine_eval_code c f s2)] | false | false | Vale.X64.Lemmas.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": 30,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val eval_code_eq_t (c: code) (f: fuel) (s1 s2: machine_state)
: Lemma (requires state_eq_S true s1 s2)
(ensures state_eq_opt true (BS.machine_eval_code c f s1) (BS.machine_eval_code c f s2))
[SMTPat (BS.machine_eval_code c f s1); SMTPat (BS.machine_eval_code c f s2)] | [] | Vale.X64.Lemmas.eval_code_eq_t | {
"file_name": "vale/code/arch/x64/Vale.X64.Lemmas.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} |
c: Vale.X64.StateLemmas.code ->
f: Vale.X64.Lemmas.fuel ->
s1: Vale.X64.StateLemmas.machine_state ->
s2: Vale.X64.StateLemmas.machine_state
-> FStar.Pervasives.Lemma (requires Vale.X64.Lemmas.state_eq_S true s1 s2)
(ensures
Vale.X64.Lemmas.state_eq_opt true
(Vale.X64.Machine_Semantics_s.machine_eval_code c f s1)
(Vale.X64.Machine_Semantics_s.machine_eval_code c f s2))
[
SMTPat (Vale.X64.Machine_Semantics_s.machine_eval_code c f s1);
SMTPat (Vale.X64.Machine_Semantics_s.machine_eval_code c f s2)
] | {
"end_col": 62,
"end_line": 279,
"start_col": 2,
"start_line": 279
} |
FStar.Pervasives.Lemma | val eval_while_eq_t (cond: ocmp) (body: code) (f: fuel) (s1 s2: machine_state)
: Lemma (requires state_eq_S true s1 s2)
(ensures
state_eq_opt true
(BS.machine_eval_while cond body f s1)
(BS.machine_eval_while cond body f s2))
[SMTPat (BS.machine_eval_while cond body f s1); SMTPat (BS.machine_eval_while cond body f s2)] | [
{
"abbrev": true,
"full_module": "Vale.X64.Memory",
"short_module": "ME"
},
{
"abbrev": true,
"full_module": "Vale.X64.Machine_Semantics_s",
"short_module": "BS"
},
{
"abbrev": false,
"full_module": "Vale.X64.Bytes_Code_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Instruction_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.StateLemmas",
"short_module": null
},
{
"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": "FStar.Mul",
"short_module": null
},
{
"abbrev": true,
"full_module": "Vale.Lib.Map16",
"short_module": "Map16"
},
{
"abbrev": true,
"full_module": "Vale.X64.Machine_Semantics_s",
"short_module": "BS"
},
{
"abbrev": false,
"full_module": "Vale.X64.Bytes_Code_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.StateLemmas",
"short_module": null
},
{
"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.HeapLemmas",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.HeapImpl",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Heap",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"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 eval_while_eq_t (cond:ocmp) (body:code) (f:fuel) (s1 s2:machine_state) : Lemma
(requires state_eq_S true s1 s2)
(ensures state_eq_opt true (BS.machine_eval_while cond body f s1) (BS.machine_eval_while cond body f s2))
[SMTPat (BS.machine_eval_while cond body f s1); SMTPat (BS.machine_eval_while cond body f s2)]
=
eval_while_eq_core true cond body f s1; eval_while_eq_core true cond body f s2 | val eval_while_eq_t (cond: ocmp) (body: code) (f: fuel) (s1 s2: machine_state)
: Lemma (requires state_eq_S true s1 s2)
(ensures
state_eq_opt true
(BS.machine_eval_while cond body f s1)
(BS.machine_eval_while cond body f s2))
[SMTPat (BS.machine_eval_while cond body f s1); SMTPat (BS.machine_eval_while cond body f s2)]
let eval_while_eq_t (cond: ocmp) (body: code) (f: fuel) (s1 s2: machine_state)
: Lemma (requires state_eq_S true s1 s2)
(ensures
state_eq_opt true
(BS.machine_eval_while cond body f s1)
(BS.machine_eval_while cond body f s2))
[SMTPat (BS.machine_eval_while cond body f s1); SMTPat (BS.machine_eval_while cond body f s2)] = | false | null | true | eval_while_eq_core true cond body f s1;
eval_while_eq_core true cond body f s2 | {
"checked_file": "Vale.X64.Lemmas.fst.checked",
"dependencies": [
"Vale.X64.StateLemmas.fsti.checked",
"Vale.X64.State.fsti.checked",
"Vale.X64.Memory.fsti.checked",
"Vale.X64.Machine_Semantics_s.fst.checked",
"Vale.X64.Machine_s.fst.checked",
"Vale.X64.Instruction_s.fsti.checked",
"Vale.X64.Flags.fsti.checked",
"Vale.X64.Bytes_Code_s.fst.checked",
"prims.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.FunctionalExtensionality.fsti.checked"
],
"interface_file": true,
"source_file": "Vale.X64.Lemmas.fst"
} | [
"lemma"
] | [
"Vale.X64.Bytes_Code_s.ocmp",
"Vale.X64.StateLemmas.code",
"Vale.X64.Lemmas.fuel",
"Vale.X64.StateLemmas.machine_state",
"Vale.X64.Lemmas.eval_while_eq_core",
"Prims.unit",
"Vale.X64.Lemmas.state_eq_S",
"Prims.squash",
"Vale.X64.Lemmas.state_eq_opt",
"Vale.X64.Machine_Semantics_s.machine_eval_while",
"Prims.Cons",
"FStar.Pervasives.pattern",
"FStar.Pervasives.smt_pat",
"FStar.Pervasives.Native.option",
"Vale.X64.Machine_Semantics_s.machine_state",
"Prims.Nil"
] | [] | module Vale.X64.Lemmas
open FStar.Mul
open Vale.X64.Machine_s
open Vale.X64.State
open Vale.X64.StateLemmas
open Vale.X64.Instruction_s
open Vale.X64.Bytes_Code_s
module BS = Vale.X64.Machine_Semantics_s
module ME = Vale.X64.Memory
#reset-options "--initial_fuel 1 --max_fuel 1 --z3rlimit 100"
#restart-solver
let rec lemma_eq_instr_apply_eval_args
(outs:list instr_out) (args:list instr_operand)
(f:instr_args_t outs args) (oprs:instr_operands_t_args args) (s1 s2:machine_state)
: Lemma
(requires state_eq_S true s1 s2)
(ensures
BS.instr_apply_eval_args outs args f oprs s1 ==
BS.instr_apply_eval_args outs args f oprs s2)
=
let open BS in
lemma_heap_ignore_ghost_machine s1.BS.ms_heap s2.BS.ms_heap;
match args with
| [] -> ()
| i::args ->
(
let (v, oprs) : option (instr_val_t i) & instr_operands_t_args args =
match i with
| IOpEx i -> let oprs = coerce oprs in (instr_eval_operand_explicit i (fst oprs) s1, snd oprs)
| IOpIm i -> (instr_eval_operand_implicit i s1, coerce oprs)
in
let f:arrow (instr_val_t i) (instr_args_t outs args) = coerce f in
match v with
| None -> ()
| Some v -> lemma_eq_instr_apply_eval_args outs args (f v) oprs s1 s2
)
#restart-solver
let rec lemma_eq_instr_apply_eval_inouts
(outs inouts:list instr_out) (args:list instr_operand)
(f:instr_inouts_t outs inouts args) (oprs:instr_operands_t inouts args) (s1 s2:machine_state)
: Lemma
(requires state_eq_S true s1 s2)
(ensures
BS.instr_apply_eval_inouts outs inouts args f oprs s1 ==
BS.instr_apply_eval_inouts outs inouts args f oprs s2)
=
let open BS in
lemma_heap_ignore_ghost_machine s1.BS.ms_heap s2.BS.ms_heap;
match inouts with
| [] -> lemma_eq_instr_apply_eval_args outs args f oprs s1 s2
| (Out, i)::inouts ->
let oprs =
match i with
| IOpEx i -> snd #(instr_operand_t i) (coerce oprs)
| IOpIm i -> coerce oprs
in
lemma_eq_instr_apply_eval_inouts outs inouts args (coerce f) oprs s1 s2
| (InOut, i)::inouts ->
(
let (v, oprs) : option (instr_val_t i) & instr_operands_t inouts args =
match i with
| IOpEx i -> let oprs = coerce oprs in (instr_eval_operand_explicit i (fst oprs) s1, snd oprs)
| IOpIm i -> (instr_eval_operand_implicit i s1, coerce oprs)
in
let f:arrow (instr_val_t i) (instr_inouts_t outs inouts args) = coerce f in
match v with
| None -> ()
| Some v -> lemma_eq_instr_apply_eval_inouts outs inouts args (f v) oprs s1 s2
)
#restart-solver
#push-options "--z3rlimit_factor 2"
let rec lemma_eq_instr_write_outputs
(outs:list instr_out) (args:list instr_operand)
(vs:instr_ret_t outs) (oprs:instr_operands_t outs args) (s1_orig s1 s2_orig s2:machine_state)
: Lemma
(requires state_eq_S true s1_orig s2_orig /\ state_eq_S true s1 s2)
(ensures
state_eq_S true
(BS.instr_write_outputs outs args vs oprs s1_orig s1)
(BS.instr_write_outputs outs args vs oprs s2_orig s2))
=
let open BS in
use_machine_state_equal ();
lemma_heap_ignore_ghost_machine s1.BS.ms_heap s2.BS.ms_heap;
lemma_heap_ignore_ghost_machine s1_orig.BS.ms_heap s2_orig.BS.ms_heap;
allow_inversion tmaddr;
match outs with
| [] -> ()
| (_, i)::outs ->
(
let ((v:instr_val_t i), (vs:instr_ret_t outs)) =
match outs with
| [] -> (vs, ())
| _::_ -> let vs = coerce vs in (fst vs, snd vs)
in
match i with
| IOpEx i ->
let oprs = coerce oprs in
let s1 = instr_write_output_explicit i v (fst oprs) s1_orig s1 in
let s2 = instr_write_output_explicit i v (fst oprs) s2_orig s2 in
lemma_eq_instr_write_outputs outs args vs (snd oprs) s1_orig s1 s2_orig s2
| IOpIm i ->
let s1 = instr_write_output_implicit i v s1_orig s1 in
let s2 = instr_write_output_implicit i v s2_orig s2 in
allow_inversion operand64;
allow_inversion operand128;
lemma_eq_instr_write_outputs outs args vs (coerce oprs) s1_orig s1 s2_orig s2
)
#pop-options
#restart-solver
let eval_ins_eq_instr (inst:BS.ins) (s1 s2:machine_state) : Lemma
(requires Instr? inst /\ state_eq_S true s1 s2)
(ensures state_eq_S true (BS.machine_eval_ins inst s1) (BS.machine_eval_ins inst s2))
=
let open BS in
let Instr it oprs ann = inst in
let InstrTypeRecord #outs #args #havoc_flags' i = it in
lemma_eq_instr_apply_eval_inouts outs outs args (instr_eval i) oprs s1 s2;
let vs = instr_apply_eval outs args (instr_eval i) oprs s1 in
let hav s =
match havoc_flags' with
| HavocFlags -> {s with ms_flags = havoc_flags}
| PreserveFlags -> s
in
let s1' = hav s1 in
let s2' = hav s2 in
match vs with
| None -> ()
| Some vs -> lemma_eq_instr_write_outputs outs args vs oprs s1 s1' s2 s2'
let eval_code_eq_instr (inst:BS.ins) (f:fuel) (s1 s2:machine_state) : Lemma
(requires Instr? inst /\ state_eq_S true s1 s2)
(ensures state_eq_opt true (BS.machine_eval_code (Ins inst) f s1) (BS.machine_eval_code (Ins inst) f s2))
=
reveal_opaque (`%BS.machine_eval_code_ins) BS.machine_eval_code_ins;
eval_ins_eq_instr inst ({s1 with BS.ms_trace = []}) ({s2 with BS.ms_trace = []})
let eval_code_eq_dealloc (inst:BS.ins) (f:fuel) (s1 s2:machine_state) : Lemma
(requires Dealloc? inst /\ state_eq_S true s1 s2)
(ensures state_eq_opt true (BS.machine_eval_code (Ins inst) f s1) (BS.machine_eval_code (Ins inst) f s2))
=
reveal_opaque (`%BS.machine_eval_code_ins) BS.machine_eval_code_ins;
use_machine_state_equal ();
lemma_heap_ignore_ghost_machine s1.BS.ms_heap s2.BS.ms_heap;
allow_inversion tmaddr
let eval_code_eq_alloc (inst:BS.ins) (f:fuel) (s1 s2:machine_state) : Lemma
(requires Alloc? inst /\ state_eq_S true s1 s2)
(ensures state_eq_opt true (BS.machine_eval_code (Ins inst) f s1) (BS.machine_eval_code (Ins inst) f s2))
=
reveal_opaque (`%BS.machine_eval_code_ins) BS.machine_eval_code_ins;
use_machine_state_equal ();
lemma_heap_ignore_ghost_machine s1.BS.ms_heap s2.BS.ms_heap;
allow_inversion tmaddr
let eval_code_eq_push (inst:BS.ins) (f:fuel) (s1 s2:machine_state) : Lemma
(requires Push? inst /\ state_eq_S true s1 s2)
(ensures state_eq_opt true (BS.machine_eval_code (Ins inst) f s1) (BS.machine_eval_code (Ins inst) f s2))
=
reveal_opaque (`%BS.machine_eval_code_ins) BS.machine_eval_code_ins;
use_machine_state_equal ();
lemma_heap_ignore_ghost_machine s1.BS.ms_heap s2.BS.ms_heap;
allow_inversion tmaddr
let eval_code_eq_pop (inst:BS.ins) (f:fuel) (s1 s2:machine_state) : Lemma
(requires Pop? inst /\ state_eq_S true s1 s2)
(ensures state_eq_opt true (BS.machine_eval_code (Ins inst) f s1) (BS.machine_eval_code (Ins inst) f s2))
=
reveal_opaque (`%BS.machine_eval_code_ins) BS.machine_eval_code_ins;
use_machine_state_equal ();
lemma_heap_ignore_ghost_machine s1.BS.ms_heap s2.BS.ms_heap;
allow_inversion tmaddr
let eval_code_eq_ins (i:BS.ins) (f:fuel) (s1 s2:machine_state) : Lemma
(requires state_eq_S true s1 s2)
(ensures state_eq_opt true (BS.machine_eval_code (Ins i) f s1) (BS.machine_eval_code (Ins i) f s2))
=
match i with
| Instr _ _ _ -> eval_code_eq_instr i f s1 s2
| Dealloc _ -> eval_code_eq_dealloc i f s1 s2
| Alloc _ -> eval_code_eq_alloc i f s1 s2
| Push _ _ -> eval_code_eq_push i f s1 s2
| Pop _ _ -> eval_code_eq_pop i f s1 s2
#reset-options "--fuel 2 --z3rlimit 30"
let eval_ocmp_eq_core (g:bool) (cond:ocmp) (s:machine_state) : Lemma
(ensures (
let (s1, b1) = BS.machine_eval_ocmp s cond in
let (s2, b2) = BS.machine_eval_ocmp (core_state g s) cond in
state_eq_S g s1 s2 /\ b1 == b2
))
=
reveal_opaque (`%BS.valid_ocmp_opaque) BS.valid_ocmp_opaque;
reveal_opaque (`%BS.eval_ocmp_opaque) BS.eval_ocmp_opaque;
()
#restart-solver
let rec eval_code_eq_core (g:bool) (c:code) (f:fuel) (s:machine_state) : Lemma
(ensures state_eq_opt g (BS.machine_eval_code c f s) (BS.machine_eval_code c f (core_state g s)))
(decreases %[f; c])
=
match c with
| Ins i ->
reveal_opaque (`%BS.machine_eval_code_ins) BS.machine_eval_code_ins;
if g then eval_code_eq_ins i f s (core_state g s)
| Block cs -> eval_codes_eq_core g cs f s
| IfElse cond ct cf ->
eval_ocmp_eq_core g cond s;
let (s', _) = BS.machine_eval_ocmp s cond in
let (t', _) = BS.machine_eval_ocmp (core_state g s) cond in
eval_code_eq_core g ct f s';
eval_code_eq_core g ct f t';
eval_code_eq_core g cf f s';
eval_code_eq_core g cf f t';
()
| While cond body -> eval_while_eq_core g cond body f s
and eval_codes_eq_core (g:bool) (cs:codes) (f:fuel) (s:machine_state) : Lemma
(ensures state_eq_opt g (BS.machine_eval_codes cs f s) (BS.machine_eval_codes cs f (core_state g s)))
(decreases %[f; cs])
=
match cs with
| [] -> ()
| c'::cs' -> (
eval_code_eq_core g c' f s;
match (machine_eval_code c' f s, machine_eval_code c' f (core_state g s)) with
| (None, None) -> ()
| (Some s', Some t') -> eval_codes_eq_core g cs' f s'; eval_codes_eq_core g cs' f t'
)
and eval_while_eq_core (g:bool) (cond:ocmp) (body:code) (f:fuel) (s:machine_state) : Lemma
(ensures state_eq_opt g (BS.machine_eval_while cond body f s) (BS.machine_eval_while cond body f (core_state g s)))
(decreases %[f; body])
=
if f > 0 then (
eval_ocmp_eq_core g cond s;
let (s1, _) = BS.machine_eval_ocmp s cond in
let (t1, _) = BS.machine_eval_ocmp (core_state g s) cond in
eval_code_eq_core g body (f - 1) s1;
eval_code_eq_core g body (f - 1) t1;
match (BS.machine_eval_code body (f - 1) s1, BS.machine_eval_code body (f - 1) t1) with
| (None, None) -> ()
| (Some s2, Some t2) ->
eval_while_eq_core g cond body (f - 1) s2;
eval_while_eq_core g cond body (f - 1) t2;
()
)
let eval_code_eq_f (c:code) (f:fuel) (s1 s2:machine_state) : Lemma
(requires state_eq_S false s1 s2)
(ensures state_eq_opt false (BS.machine_eval_code c f s1) (BS.machine_eval_code c f s2))
[SMTPat (BS.machine_eval_code c f s1); SMTPat (BS.machine_eval_code c f s2)]
=
eval_code_eq_core false c f s1; eval_code_eq_core false c f s2
let eval_codes_eq_f (cs:codes) (f:fuel) (s1 s2:machine_state) : Lemma
(requires state_eq_S false s1 s2)
(ensures state_eq_opt false (BS.machine_eval_codes cs f s1) (BS.machine_eval_codes cs f s2))
[SMTPat (BS.machine_eval_codes cs f s1); SMTPat (BS.machine_eval_codes cs f s2)]
=
eval_codes_eq_core false cs f s1; eval_codes_eq_core false cs f s2
let eval_while_eq_f (cond:ocmp) (body:code) (f:fuel) (s1 s2:machine_state) : Lemma
(requires state_eq_S false s1 s2)
(ensures state_eq_opt false (BS.machine_eval_while cond body f s1) (BS.machine_eval_while cond body f s2))
[SMTPat (BS.machine_eval_while cond body f s1); SMTPat (BS.machine_eval_while cond body f s2)]
=
eval_while_eq_core false cond body f s1; eval_while_eq_core false cond body f s2
let eval_code_eq_t (c:code) (f:fuel) (s1 s2:machine_state) : Lemma
(requires state_eq_S true s1 s2)
(ensures state_eq_opt true (BS.machine_eval_code c f s1) (BS.machine_eval_code c f s2))
[SMTPat (BS.machine_eval_code c f s1); SMTPat (BS.machine_eval_code c f s2)]
=
eval_code_eq_core true c f s1; eval_code_eq_core true c f s2
let eval_codes_eq_t (cs:codes) (f:fuel) (s1 s2:machine_state) : Lemma
(requires state_eq_S true s1 s2)
(ensures state_eq_opt true (BS.machine_eval_codes cs f s1) (BS.machine_eval_codes cs f s2))
[SMTPat (BS.machine_eval_codes cs f s1); SMTPat (BS.machine_eval_codes cs f s2)]
=
eval_codes_eq_core true cs f s1; eval_codes_eq_core true cs f s2
let eval_while_eq_t (cond:ocmp) (body:code) (f:fuel) (s1 s2:machine_state) : Lemma
(requires state_eq_S true s1 s2)
(ensures state_eq_opt true (BS.machine_eval_while cond body f s1) (BS.machine_eval_while cond body f s2))
[SMTPat (BS.machine_eval_while cond body f s1); SMTPat (BS.machine_eval_while cond body f s2)] | false | false | Vale.X64.Lemmas.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": 30,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val eval_while_eq_t (cond: ocmp) (body: code) (f: fuel) (s1 s2: machine_state)
: Lemma (requires state_eq_S true s1 s2)
(ensures
state_eq_opt true
(BS.machine_eval_while cond body f s1)
(BS.machine_eval_while cond body f s2))
[SMTPat (BS.machine_eval_while cond body f s1); SMTPat (BS.machine_eval_while cond body f s2)] | [] | Vale.X64.Lemmas.eval_while_eq_t | {
"file_name": "vale/code/arch/x64/Vale.X64.Lemmas.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} |
cond: Vale.X64.Bytes_Code_s.ocmp ->
body: Vale.X64.StateLemmas.code ->
f: Vale.X64.Lemmas.fuel ->
s1: Vale.X64.StateLemmas.machine_state ->
s2: Vale.X64.StateLemmas.machine_state
-> FStar.Pervasives.Lemma (requires Vale.X64.Lemmas.state_eq_S true s1 s2)
(ensures
Vale.X64.Lemmas.state_eq_opt true
(Vale.X64.Machine_Semantics_s.machine_eval_while cond body f s1)
(Vale.X64.Machine_Semantics_s.machine_eval_while cond body f s2))
[
SMTPat (Vale.X64.Machine_Semantics_s.machine_eval_while cond body f s1);
SMTPat (Vale.X64.Machine_Semantics_s.machine_eval_while cond body f s2)
] | {
"end_col": 80,
"end_line": 293,
"start_col": 2,
"start_line": 293
} |
Prims.Ghost | val lemma_empty_total (s0:vale_state) (bN:codes) : Ghost (vale_state & fuel)
(requires True)
(ensures (fun (sM, fM) ->
s0 == sM /\
eval_code (Block []) s0 fM sM
)) | [
{
"abbrev": true,
"full_module": "Vale.X64.Memory",
"short_module": "ME"
},
{
"abbrev": false,
"full_module": "Vale.X64.Instruction_s",
"short_module": null
},
{
"abbrev": true,
"full_module": "Vale.Lib.Map16",
"short_module": "Map16"
},
{
"abbrev": true,
"full_module": "Vale.X64.Machine_Semantics_s",
"short_module": "BS"
},
{
"abbrev": false,
"full_module": "Vale.X64.Bytes_Code_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.StateLemmas",
"short_module": null
},
{
"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.HeapLemmas",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.HeapImpl",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Heap",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"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 lemma_empty_total (s0:vale_state) (bN:codes) =
(s0, 0) | val lemma_empty_total (s0:vale_state) (bN:codes) : Ghost (vale_state & fuel)
(requires True)
(ensures (fun (sM, fM) ->
s0 == sM /\
eval_code (Block []) s0 fM sM
))
let lemma_empty_total (s0: vale_state) (bN: codes) = | false | null | false | (s0, 0) | {
"checked_file": "Vale.X64.Lemmas.fst.checked",
"dependencies": [
"Vale.X64.StateLemmas.fsti.checked",
"Vale.X64.State.fsti.checked",
"Vale.X64.Memory.fsti.checked",
"Vale.X64.Machine_Semantics_s.fst.checked",
"Vale.X64.Machine_s.fst.checked",
"Vale.X64.Instruction_s.fsti.checked",
"Vale.X64.Flags.fsti.checked",
"Vale.X64.Bytes_Code_s.fst.checked",
"prims.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.FunctionalExtensionality.fsti.checked"
],
"interface_file": true,
"source_file": "Vale.X64.Lemmas.fst"
} | [] | [
"Vale.X64.State.vale_state",
"Vale.X64.Lemmas.codes",
"FStar.Pervasives.Native.Mktuple2",
"Vale.X64.Lemmas.fuel",
"FStar.Pervasives.Native.tuple2"
] | [] | module Vale.X64.Lemmas
open FStar.Mul
open Vale.X64.Machine_s
open Vale.X64.State
open Vale.X64.StateLemmas
open Vale.X64.Instruction_s
open Vale.X64.Bytes_Code_s
module BS = Vale.X64.Machine_Semantics_s
module ME = Vale.X64.Memory
#reset-options "--initial_fuel 1 --max_fuel 1 --z3rlimit 100"
#restart-solver
let rec lemma_eq_instr_apply_eval_args
(outs:list instr_out) (args:list instr_operand)
(f:instr_args_t outs args) (oprs:instr_operands_t_args args) (s1 s2:machine_state)
: Lemma
(requires state_eq_S true s1 s2)
(ensures
BS.instr_apply_eval_args outs args f oprs s1 ==
BS.instr_apply_eval_args outs args f oprs s2)
=
let open BS in
lemma_heap_ignore_ghost_machine s1.BS.ms_heap s2.BS.ms_heap;
match args with
| [] -> ()
| i::args ->
(
let (v, oprs) : option (instr_val_t i) & instr_operands_t_args args =
match i with
| IOpEx i -> let oprs = coerce oprs in (instr_eval_operand_explicit i (fst oprs) s1, snd oprs)
| IOpIm i -> (instr_eval_operand_implicit i s1, coerce oprs)
in
let f:arrow (instr_val_t i) (instr_args_t outs args) = coerce f in
match v with
| None -> ()
| Some v -> lemma_eq_instr_apply_eval_args outs args (f v) oprs s1 s2
)
#restart-solver
let rec lemma_eq_instr_apply_eval_inouts
(outs inouts:list instr_out) (args:list instr_operand)
(f:instr_inouts_t outs inouts args) (oprs:instr_operands_t inouts args) (s1 s2:machine_state)
: Lemma
(requires state_eq_S true s1 s2)
(ensures
BS.instr_apply_eval_inouts outs inouts args f oprs s1 ==
BS.instr_apply_eval_inouts outs inouts args f oprs s2)
=
let open BS in
lemma_heap_ignore_ghost_machine s1.BS.ms_heap s2.BS.ms_heap;
match inouts with
| [] -> lemma_eq_instr_apply_eval_args outs args f oprs s1 s2
| (Out, i)::inouts ->
let oprs =
match i with
| IOpEx i -> snd #(instr_operand_t i) (coerce oprs)
| IOpIm i -> coerce oprs
in
lemma_eq_instr_apply_eval_inouts outs inouts args (coerce f) oprs s1 s2
| (InOut, i)::inouts ->
(
let (v, oprs) : option (instr_val_t i) & instr_operands_t inouts args =
match i with
| IOpEx i -> let oprs = coerce oprs in (instr_eval_operand_explicit i (fst oprs) s1, snd oprs)
| IOpIm i -> (instr_eval_operand_implicit i s1, coerce oprs)
in
let f:arrow (instr_val_t i) (instr_inouts_t outs inouts args) = coerce f in
match v with
| None -> ()
| Some v -> lemma_eq_instr_apply_eval_inouts outs inouts args (f v) oprs s1 s2
)
#restart-solver
#push-options "--z3rlimit_factor 2"
let rec lemma_eq_instr_write_outputs
(outs:list instr_out) (args:list instr_operand)
(vs:instr_ret_t outs) (oprs:instr_operands_t outs args) (s1_orig s1 s2_orig s2:machine_state)
: Lemma
(requires state_eq_S true s1_orig s2_orig /\ state_eq_S true s1 s2)
(ensures
state_eq_S true
(BS.instr_write_outputs outs args vs oprs s1_orig s1)
(BS.instr_write_outputs outs args vs oprs s2_orig s2))
=
let open BS in
use_machine_state_equal ();
lemma_heap_ignore_ghost_machine s1.BS.ms_heap s2.BS.ms_heap;
lemma_heap_ignore_ghost_machine s1_orig.BS.ms_heap s2_orig.BS.ms_heap;
allow_inversion tmaddr;
match outs with
| [] -> ()
| (_, i)::outs ->
(
let ((v:instr_val_t i), (vs:instr_ret_t outs)) =
match outs with
| [] -> (vs, ())
| _::_ -> let vs = coerce vs in (fst vs, snd vs)
in
match i with
| IOpEx i ->
let oprs = coerce oprs in
let s1 = instr_write_output_explicit i v (fst oprs) s1_orig s1 in
let s2 = instr_write_output_explicit i v (fst oprs) s2_orig s2 in
lemma_eq_instr_write_outputs outs args vs (snd oprs) s1_orig s1 s2_orig s2
| IOpIm i ->
let s1 = instr_write_output_implicit i v s1_orig s1 in
let s2 = instr_write_output_implicit i v s2_orig s2 in
allow_inversion operand64;
allow_inversion operand128;
lemma_eq_instr_write_outputs outs args vs (coerce oprs) s1_orig s1 s2_orig s2
)
#pop-options
#restart-solver
let eval_ins_eq_instr (inst:BS.ins) (s1 s2:machine_state) : Lemma
(requires Instr? inst /\ state_eq_S true s1 s2)
(ensures state_eq_S true (BS.machine_eval_ins inst s1) (BS.machine_eval_ins inst s2))
=
let open BS in
let Instr it oprs ann = inst in
let InstrTypeRecord #outs #args #havoc_flags' i = it in
lemma_eq_instr_apply_eval_inouts outs outs args (instr_eval i) oprs s1 s2;
let vs = instr_apply_eval outs args (instr_eval i) oprs s1 in
let hav s =
match havoc_flags' with
| HavocFlags -> {s with ms_flags = havoc_flags}
| PreserveFlags -> s
in
let s1' = hav s1 in
let s2' = hav s2 in
match vs with
| None -> ()
| Some vs -> lemma_eq_instr_write_outputs outs args vs oprs s1 s1' s2 s2'
let eval_code_eq_instr (inst:BS.ins) (f:fuel) (s1 s2:machine_state) : Lemma
(requires Instr? inst /\ state_eq_S true s1 s2)
(ensures state_eq_opt true (BS.machine_eval_code (Ins inst) f s1) (BS.machine_eval_code (Ins inst) f s2))
=
reveal_opaque (`%BS.machine_eval_code_ins) BS.machine_eval_code_ins;
eval_ins_eq_instr inst ({s1 with BS.ms_trace = []}) ({s2 with BS.ms_trace = []})
let eval_code_eq_dealloc (inst:BS.ins) (f:fuel) (s1 s2:machine_state) : Lemma
(requires Dealloc? inst /\ state_eq_S true s1 s2)
(ensures state_eq_opt true (BS.machine_eval_code (Ins inst) f s1) (BS.machine_eval_code (Ins inst) f s2))
=
reveal_opaque (`%BS.machine_eval_code_ins) BS.machine_eval_code_ins;
use_machine_state_equal ();
lemma_heap_ignore_ghost_machine s1.BS.ms_heap s2.BS.ms_heap;
allow_inversion tmaddr
let eval_code_eq_alloc (inst:BS.ins) (f:fuel) (s1 s2:machine_state) : Lemma
(requires Alloc? inst /\ state_eq_S true s1 s2)
(ensures state_eq_opt true (BS.machine_eval_code (Ins inst) f s1) (BS.machine_eval_code (Ins inst) f s2))
=
reveal_opaque (`%BS.machine_eval_code_ins) BS.machine_eval_code_ins;
use_machine_state_equal ();
lemma_heap_ignore_ghost_machine s1.BS.ms_heap s2.BS.ms_heap;
allow_inversion tmaddr
let eval_code_eq_push (inst:BS.ins) (f:fuel) (s1 s2:machine_state) : Lemma
(requires Push? inst /\ state_eq_S true s1 s2)
(ensures state_eq_opt true (BS.machine_eval_code (Ins inst) f s1) (BS.machine_eval_code (Ins inst) f s2))
=
reveal_opaque (`%BS.machine_eval_code_ins) BS.machine_eval_code_ins;
use_machine_state_equal ();
lemma_heap_ignore_ghost_machine s1.BS.ms_heap s2.BS.ms_heap;
allow_inversion tmaddr
let eval_code_eq_pop (inst:BS.ins) (f:fuel) (s1 s2:machine_state) : Lemma
(requires Pop? inst /\ state_eq_S true s1 s2)
(ensures state_eq_opt true (BS.machine_eval_code (Ins inst) f s1) (BS.machine_eval_code (Ins inst) f s2))
=
reveal_opaque (`%BS.machine_eval_code_ins) BS.machine_eval_code_ins;
use_machine_state_equal ();
lemma_heap_ignore_ghost_machine s1.BS.ms_heap s2.BS.ms_heap;
allow_inversion tmaddr
let eval_code_eq_ins (i:BS.ins) (f:fuel) (s1 s2:machine_state) : Lemma
(requires state_eq_S true s1 s2)
(ensures state_eq_opt true (BS.machine_eval_code (Ins i) f s1) (BS.machine_eval_code (Ins i) f s2))
=
match i with
| Instr _ _ _ -> eval_code_eq_instr i f s1 s2
| Dealloc _ -> eval_code_eq_dealloc i f s1 s2
| Alloc _ -> eval_code_eq_alloc i f s1 s2
| Push _ _ -> eval_code_eq_push i f s1 s2
| Pop _ _ -> eval_code_eq_pop i f s1 s2
#reset-options "--fuel 2 --z3rlimit 30"
let eval_ocmp_eq_core (g:bool) (cond:ocmp) (s:machine_state) : Lemma
(ensures (
let (s1, b1) = BS.machine_eval_ocmp s cond in
let (s2, b2) = BS.machine_eval_ocmp (core_state g s) cond in
state_eq_S g s1 s2 /\ b1 == b2
))
=
reveal_opaque (`%BS.valid_ocmp_opaque) BS.valid_ocmp_opaque;
reveal_opaque (`%BS.eval_ocmp_opaque) BS.eval_ocmp_opaque;
()
#restart-solver
let rec eval_code_eq_core (g:bool) (c:code) (f:fuel) (s:machine_state) : Lemma
(ensures state_eq_opt g (BS.machine_eval_code c f s) (BS.machine_eval_code c f (core_state g s)))
(decreases %[f; c])
=
match c with
| Ins i ->
reveal_opaque (`%BS.machine_eval_code_ins) BS.machine_eval_code_ins;
if g then eval_code_eq_ins i f s (core_state g s)
| Block cs -> eval_codes_eq_core g cs f s
| IfElse cond ct cf ->
eval_ocmp_eq_core g cond s;
let (s', _) = BS.machine_eval_ocmp s cond in
let (t', _) = BS.machine_eval_ocmp (core_state g s) cond in
eval_code_eq_core g ct f s';
eval_code_eq_core g ct f t';
eval_code_eq_core g cf f s';
eval_code_eq_core g cf f t';
()
| While cond body -> eval_while_eq_core g cond body f s
and eval_codes_eq_core (g:bool) (cs:codes) (f:fuel) (s:machine_state) : Lemma
(ensures state_eq_opt g (BS.machine_eval_codes cs f s) (BS.machine_eval_codes cs f (core_state g s)))
(decreases %[f; cs])
=
match cs with
| [] -> ()
| c'::cs' -> (
eval_code_eq_core g c' f s;
match (machine_eval_code c' f s, machine_eval_code c' f (core_state g s)) with
| (None, None) -> ()
| (Some s', Some t') -> eval_codes_eq_core g cs' f s'; eval_codes_eq_core g cs' f t'
)
and eval_while_eq_core (g:bool) (cond:ocmp) (body:code) (f:fuel) (s:machine_state) : Lemma
(ensures state_eq_opt g (BS.machine_eval_while cond body f s) (BS.machine_eval_while cond body f (core_state g s)))
(decreases %[f; body])
=
if f > 0 then (
eval_ocmp_eq_core g cond s;
let (s1, _) = BS.machine_eval_ocmp s cond in
let (t1, _) = BS.machine_eval_ocmp (core_state g s) cond in
eval_code_eq_core g body (f - 1) s1;
eval_code_eq_core g body (f - 1) t1;
match (BS.machine_eval_code body (f - 1) s1, BS.machine_eval_code body (f - 1) t1) with
| (None, None) -> ()
| (Some s2, Some t2) ->
eval_while_eq_core g cond body (f - 1) s2;
eval_while_eq_core g cond body (f - 1) t2;
()
)
let eval_code_eq_f (c:code) (f:fuel) (s1 s2:machine_state) : Lemma
(requires state_eq_S false s1 s2)
(ensures state_eq_opt false (BS.machine_eval_code c f s1) (BS.machine_eval_code c f s2))
[SMTPat (BS.machine_eval_code c f s1); SMTPat (BS.machine_eval_code c f s2)]
=
eval_code_eq_core false c f s1; eval_code_eq_core false c f s2
let eval_codes_eq_f (cs:codes) (f:fuel) (s1 s2:machine_state) : Lemma
(requires state_eq_S false s1 s2)
(ensures state_eq_opt false (BS.machine_eval_codes cs f s1) (BS.machine_eval_codes cs f s2))
[SMTPat (BS.machine_eval_codes cs f s1); SMTPat (BS.machine_eval_codes cs f s2)]
=
eval_codes_eq_core false cs f s1; eval_codes_eq_core false cs f s2
let eval_while_eq_f (cond:ocmp) (body:code) (f:fuel) (s1 s2:machine_state) : Lemma
(requires state_eq_S false s1 s2)
(ensures state_eq_opt false (BS.machine_eval_while cond body f s1) (BS.machine_eval_while cond body f s2))
[SMTPat (BS.machine_eval_while cond body f s1); SMTPat (BS.machine_eval_while cond body f s2)]
=
eval_while_eq_core false cond body f s1; eval_while_eq_core false cond body f s2
let eval_code_eq_t (c:code) (f:fuel) (s1 s2:machine_state) : Lemma
(requires state_eq_S true s1 s2)
(ensures state_eq_opt true (BS.machine_eval_code c f s1) (BS.machine_eval_code c f s2))
[SMTPat (BS.machine_eval_code c f s1); SMTPat (BS.machine_eval_code c f s2)]
=
eval_code_eq_core true c f s1; eval_code_eq_core true c f s2
let eval_codes_eq_t (cs:codes) (f:fuel) (s1 s2:machine_state) : Lemma
(requires state_eq_S true s1 s2)
(ensures state_eq_opt true (BS.machine_eval_codes cs f s1) (BS.machine_eval_codes cs f s2))
[SMTPat (BS.machine_eval_codes cs f s1); SMTPat (BS.machine_eval_codes cs f s2)]
=
eval_codes_eq_core true cs f s1; eval_codes_eq_core true cs f s2
let eval_while_eq_t (cond:ocmp) (body:code) (f:fuel) (s1 s2:machine_state) : Lemma
(requires state_eq_S true s1 s2)
(ensures state_eq_opt true (BS.machine_eval_while cond body f s1) (BS.machine_eval_while cond body f s2))
[SMTPat (BS.machine_eval_while cond body f s1); SMTPat (BS.machine_eval_while cond body f s2)]
=
eval_while_eq_core true cond body f s1; eval_while_eq_core true cond body f s2
let eval_code_ts (g:bool) (c:code) (s0:machine_state) (f0:fuel) (s1:machine_state) : Type0 =
state_eq_opt g (BS.machine_eval_code c f0 s0) (Some s1)
let rec increase_fuel (g:bool) (c:code) (s0:machine_state) (f0:fuel) (sN:machine_state) (fN:fuel) : Lemma
(requires eval_code_ts g c s0 f0 sN /\ f0 <= fN)
(ensures eval_code_ts g c s0 fN sN)
(decreases %[f0; c])
=
match c with
| Ins ins -> ()
| Block l -> increase_fuels g l s0 f0 sN fN
| IfElse cond t f ->
let (s0, b0) = BS.machine_eval_ocmp s0 cond in
if b0 then increase_fuel g t s0 f0 sN fN else increase_fuel g f s0 f0 sN fN
| While cond c ->
let (s1, b0) = BS.machine_eval_ocmp s0 cond in
if b0 then (
match BS.machine_eval_code c (f0 - 1) s1 with
| None -> ()
| Some s2 ->
increase_fuel g c s1 (f0 - 1) s2 (fN - 1);
if s2.BS.ms_ok then increase_fuel g (While cond c) s2 (f0 - 1) sN (fN - 1)
else ()
)
and increase_fuels (g:bool) (c:codes) (s0:machine_state) (f0:fuel) (sN:machine_state) (fN:fuel) : Lemma
(requires eval_code_ts g (Block c) s0 f0 sN /\ f0 <= fN)
(ensures eval_code_ts g (Block c) s0 fN sN)
(decreases %[f0; c])
=
match c with
| [] -> ()
| h::t ->
(
let Some s1 = BS.machine_eval_code h f0 s0 in
increase_fuel g h s0 f0 s1 fN;
increase_fuels g t s1 f0 sN fN
)
let lemma_cmp_eq s o1 o2 = reveal_opaque (`%BS.eval_ocmp_opaque) BS.eval_ocmp_opaque
let lemma_cmp_ne s o1 o2 = reveal_opaque (`%BS.eval_ocmp_opaque) BS.eval_ocmp_opaque
let lemma_cmp_le s o1 o2 = reveal_opaque (`%BS.eval_ocmp_opaque) BS.eval_ocmp_opaque
let lemma_cmp_ge s o1 o2 = reveal_opaque (`%BS.eval_ocmp_opaque) BS.eval_ocmp_opaque
let lemma_cmp_lt s o1 o2 = reveal_opaque (`%BS.eval_ocmp_opaque) BS.eval_ocmp_opaque
let lemma_cmp_gt s o1 o2 = reveal_opaque (`%BS.eval_ocmp_opaque) BS.eval_ocmp_opaque
let lemma_valid_cmp_eq s o1 o2 = ()
let lemma_valid_cmp_ne s o1 o2 = ()
let lemma_valid_cmp_le s o1 o2 = ()
let lemma_valid_cmp_ge s o1 o2 = ()
let lemma_valid_cmp_lt s o1 o2 = ()
let lemma_valid_cmp_gt s o1 o2 = ()
let compute_merge_total (f0:fuel) (fM:fuel) =
if f0 > fM then f0 else fM
let lemma_merge_total (b0:codes) (s0:vale_state) (f0:fuel) (sM:vale_state) (fM:fuel) (sN:vale_state) =
let f = if f0 > fM then f0 else fM in
increase_fuel (codes_modifies_ghost b0) (Cons?.hd b0) (state_to_S s0) f0 (state_to_S sM) f;
increase_fuel (codes_modifies_ghost b0) (Block (Cons?.tl b0)) (state_to_S sM) fM (state_to_S sN) f | false | false | Vale.X64.Lemmas.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": 30,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val lemma_empty_total (s0:vale_state) (bN:codes) : Ghost (vale_state & fuel)
(requires True)
(ensures (fun (sM, fM) ->
s0 == sM /\
eval_code (Block []) s0 fM sM
)) | [] | Vale.X64.Lemmas.lemma_empty_total | {
"file_name": "vale/code/arch/x64/Vale.X64.Lemmas.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | s0: Vale.X64.State.vale_state -> bN: Vale.X64.Lemmas.codes
-> Prims.Ghost (Vale.X64.State.vale_state * Vale.X64.Lemmas.fuel) | {
"end_col": 9,
"end_line": 356,
"start_col": 2,
"start_line": 356
} |
Prims.Ghost | val lemma_while_total (b:ocmp) (c:code) (s0:vale_state) : Ghost (vale_state & fuel)
(requires True)
(ensures fun (s1, f1) ->
s1 == s0 /\
eval_while_inv (While b c) s1 f1 s1
) | [
{
"abbrev": true,
"full_module": "Vale.X64.Memory",
"short_module": "ME"
},
{
"abbrev": false,
"full_module": "Vale.X64.Instruction_s",
"short_module": null
},
{
"abbrev": true,
"full_module": "Vale.Lib.Map16",
"short_module": "Map16"
},
{
"abbrev": true,
"full_module": "Vale.X64.Machine_Semantics_s",
"short_module": "BS"
},
{
"abbrev": false,
"full_module": "Vale.X64.Bytes_Code_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.StateLemmas",
"short_module": null
},
{
"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.HeapLemmas",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.HeapImpl",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Heap",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"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 lemma_while_total (b:ocmp) (c:code) (s0:vale_state) =
(s0, 0) | val lemma_while_total (b:ocmp) (c:code) (s0:vale_state) : Ghost (vale_state & fuel)
(requires True)
(ensures fun (s1, f1) ->
s1 == s0 /\
eval_while_inv (While b c) s1 f1 s1
)
let lemma_while_total (b: ocmp) (c: code) (s0: vale_state) = | false | null | false | (s0, 0) | {
"checked_file": "Vale.X64.Lemmas.fst.checked",
"dependencies": [
"Vale.X64.StateLemmas.fsti.checked",
"Vale.X64.State.fsti.checked",
"Vale.X64.Memory.fsti.checked",
"Vale.X64.Machine_Semantics_s.fst.checked",
"Vale.X64.Machine_s.fst.checked",
"Vale.X64.Instruction_s.fsti.checked",
"Vale.X64.Flags.fsti.checked",
"Vale.X64.Bytes_Code_s.fst.checked",
"prims.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.FunctionalExtensionality.fsti.checked"
],
"interface_file": true,
"source_file": "Vale.X64.Lemmas.fst"
} | [] | [
"Vale.X64.Bytes_Code_s.ocmp",
"Vale.X64.StateLemmas.code",
"Vale.X64.State.vale_state",
"FStar.Pervasives.Native.Mktuple2",
"Vale.X64.Lemmas.fuel",
"FStar.Pervasives.Native.tuple2"
] | [] | module Vale.X64.Lemmas
open FStar.Mul
open Vale.X64.Machine_s
open Vale.X64.State
open Vale.X64.StateLemmas
open Vale.X64.Instruction_s
open Vale.X64.Bytes_Code_s
module BS = Vale.X64.Machine_Semantics_s
module ME = Vale.X64.Memory
#reset-options "--initial_fuel 1 --max_fuel 1 --z3rlimit 100"
#restart-solver
let rec lemma_eq_instr_apply_eval_args
(outs:list instr_out) (args:list instr_operand)
(f:instr_args_t outs args) (oprs:instr_operands_t_args args) (s1 s2:machine_state)
: Lemma
(requires state_eq_S true s1 s2)
(ensures
BS.instr_apply_eval_args outs args f oprs s1 ==
BS.instr_apply_eval_args outs args f oprs s2)
=
let open BS in
lemma_heap_ignore_ghost_machine s1.BS.ms_heap s2.BS.ms_heap;
match args with
| [] -> ()
| i::args ->
(
let (v, oprs) : option (instr_val_t i) & instr_operands_t_args args =
match i with
| IOpEx i -> let oprs = coerce oprs in (instr_eval_operand_explicit i (fst oprs) s1, snd oprs)
| IOpIm i -> (instr_eval_operand_implicit i s1, coerce oprs)
in
let f:arrow (instr_val_t i) (instr_args_t outs args) = coerce f in
match v with
| None -> ()
| Some v -> lemma_eq_instr_apply_eval_args outs args (f v) oprs s1 s2
)
#restart-solver
let rec lemma_eq_instr_apply_eval_inouts
(outs inouts:list instr_out) (args:list instr_operand)
(f:instr_inouts_t outs inouts args) (oprs:instr_operands_t inouts args) (s1 s2:machine_state)
: Lemma
(requires state_eq_S true s1 s2)
(ensures
BS.instr_apply_eval_inouts outs inouts args f oprs s1 ==
BS.instr_apply_eval_inouts outs inouts args f oprs s2)
=
let open BS in
lemma_heap_ignore_ghost_machine s1.BS.ms_heap s2.BS.ms_heap;
match inouts with
| [] -> lemma_eq_instr_apply_eval_args outs args f oprs s1 s2
| (Out, i)::inouts ->
let oprs =
match i with
| IOpEx i -> snd #(instr_operand_t i) (coerce oprs)
| IOpIm i -> coerce oprs
in
lemma_eq_instr_apply_eval_inouts outs inouts args (coerce f) oprs s1 s2
| (InOut, i)::inouts ->
(
let (v, oprs) : option (instr_val_t i) & instr_operands_t inouts args =
match i with
| IOpEx i -> let oprs = coerce oprs in (instr_eval_operand_explicit i (fst oprs) s1, snd oprs)
| IOpIm i -> (instr_eval_operand_implicit i s1, coerce oprs)
in
let f:arrow (instr_val_t i) (instr_inouts_t outs inouts args) = coerce f in
match v with
| None -> ()
| Some v -> lemma_eq_instr_apply_eval_inouts outs inouts args (f v) oprs s1 s2
)
#restart-solver
#push-options "--z3rlimit_factor 2"
let rec lemma_eq_instr_write_outputs
(outs:list instr_out) (args:list instr_operand)
(vs:instr_ret_t outs) (oprs:instr_operands_t outs args) (s1_orig s1 s2_orig s2:machine_state)
: Lemma
(requires state_eq_S true s1_orig s2_orig /\ state_eq_S true s1 s2)
(ensures
state_eq_S true
(BS.instr_write_outputs outs args vs oprs s1_orig s1)
(BS.instr_write_outputs outs args vs oprs s2_orig s2))
=
let open BS in
use_machine_state_equal ();
lemma_heap_ignore_ghost_machine s1.BS.ms_heap s2.BS.ms_heap;
lemma_heap_ignore_ghost_machine s1_orig.BS.ms_heap s2_orig.BS.ms_heap;
allow_inversion tmaddr;
match outs with
| [] -> ()
| (_, i)::outs ->
(
let ((v:instr_val_t i), (vs:instr_ret_t outs)) =
match outs with
| [] -> (vs, ())
| _::_ -> let vs = coerce vs in (fst vs, snd vs)
in
match i with
| IOpEx i ->
let oprs = coerce oprs in
let s1 = instr_write_output_explicit i v (fst oprs) s1_orig s1 in
let s2 = instr_write_output_explicit i v (fst oprs) s2_orig s2 in
lemma_eq_instr_write_outputs outs args vs (snd oprs) s1_orig s1 s2_orig s2
| IOpIm i ->
let s1 = instr_write_output_implicit i v s1_orig s1 in
let s2 = instr_write_output_implicit i v s2_orig s2 in
allow_inversion operand64;
allow_inversion operand128;
lemma_eq_instr_write_outputs outs args vs (coerce oprs) s1_orig s1 s2_orig s2
)
#pop-options
#restart-solver
let eval_ins_eq_instr (inst:BS.ins) (s1 s2:machine_state) : Lemma
(requires Instr? inst /\ state_eq_S true s1 s2)
(ensures state_eq_S true (BS.machine_eval_ins inst s1) (BS.machine_eval_ins inst s2))
=
let open BS in
let Instr it oprs ann = inst in
let InstrTypeRecord #outs #args #havoc_flags' i = it in
lemma_eq_instr_apply_eval_inouts outs outs args (instr_eval i) oprs s1 s2;
let vs = instr_apply_eval outs args (instr_eval i) oprs s1 in
let hav s =
match havoc_flags' with
| HavocFlags -> {s with ms_flags = havoc_flags}
| PreserveFlags -> s
in
let s1' = hav s1 in
let s2' = hav s2 in
match vs with
| None -> ()
| Some vs -> lemma_eq_instr_write_outputs outs args vs oprs s1 s1' s2 s2'
let eval_code_eq_instr (inst:BS.ins) (f:fuel) (s1 s2:machine_state) : Lemma
(requires Instr? inst /\ state_eq_S true s1 s2)
(ensures state_eq_opt true (BS.machine_eval_code (Ins inst) f s1) (BS.machine_eval_code (Ins inst) f s2))
=
reveal_opaque (`%BS.machine_eval_code_ins) BS.machine_eval_code_ins;
eval_ins_eq_instr inst ({s1 with BS.ms_trace = []}) ({s2 with BS.ms_trace = []})
let eval_code_eq_dealloc (inst:BS.ins) (f:fuel) (s1 s2:machine_state) : Lemma
(requires Dealloc? inst /\ state_eq_S true s1 s2)
(ensures state_eq_opt true (BS.machine_eval_code (Ins inst) f s1) (BS.machine_eval_code (Ins inst) f s2))
=
reveal_opaque (`%BS.machine_eval_code_ins) BS.machine_eval_code_ins;
use_machine_state_equal ();
lemma_heap_ignore_ghost_machine s1.BS.ms_heap s2.BS.ms_heap;
allow_inversion tmaddr
let eval_code_eq_alloc (inst:BS.ins) (f:fuel) (s1 s2:machine_state) : Lemma
(requires Alloc? inst /\ state_eq_S true s1 s2)
(ensures state_eq_opt true (BS.machine_eval_code (Ins inst) f s1) (BS.machine_eval_code (Ins inst) f s2))
=
reveal_opaque (`%BS.machine_eval_code_ins) BS.machine_eval_code_ins;
use_machine_state_equal ();
lemma_heap_ignore_ghost_machine s1.BS.ms_heap s2.BS.ms_heap;
allow_inversion tmaddr
let eval_code_eq_push (inst:BS.ins) (f:fuel) (s1 s2:machine_state) : Lemma
(requires Push? inst /\ state_eq_S true s1 s2)
(ensures state_eq_opt true (BS.machine_eval_code (Ins inst) f s1) (BS.machine_eval_code (Ins inst) f s2))
=
reveal_opaque (`%BS.machine_eval_code_ins) BS.machine_eval_code_ins;
use_machine_state_equal ();
lemma_heap_ignore_ghost_machine s1.BS.ms_heap s2.BS.ms_heap;
allow_inversion tmaddr
let eval_code_eq_pop (inst:BS.ins) (f:fuel) (s1 s2:machine_state) : Lemma
(requires Pop? inst /\ state_eq_S true s1 s2)
(ensures state_eq_opt true (BS.machine_eval_code (Ins inst) f s1) (BS.machine_eval_code (Ins inst) f s2))
=
reveal_opaque (`%BS.machine_eval_code_ins) BS.machine_eval_code_ins;
use_machine_state_equal ();
lemma_heap_ignore_ghost_machine s1.BS.ms_heap s2.BS.ms_heap;
allow_inversion tmaddr
let eval_code_eq_ins (i:BS.ins) (f:fuel) (s1 s2:machine_state) : Lemma
(requires state_eq_S true s1 s2)
(ensures state_eq_opt true (BS.machine_eval_code (Ins i) f s1) (BS.machine_eval_code (Ins i) f s2))
=
match i with
| Instr _ _ _ -> eval_code_eq_instr i f s1 s2
| Dealloc _ -> eval_code_eq_dealloc i f s1 s2
| Alloc _ -> eval_code_eq_alloc i f s1 s2
| Push _ _ -> eval_code_eq_push i f s1 s2
| Pop _ _ -> eval_code_eq_pop i f s1 s2
#reset-options "--fuel 2 --z3rlimit 30"
let eval_ocmp_eq_core (g:bool) (cond:ocmp) (s:machine_state) : Lemma
(ensures (
let (s1, b1) = BS.machine_eval_ocmp s cond in
let (s2, b2) = BS.machine_eval_ocmp (core_state g s) cond in
state_eq_S g s1 s2 /\ b1 == b2
))
=
reveal_opaque (`%BS.valid_ocmp_opaque) BS.valid_ocmp_opaque;
reveal_opaque (`%BS.eval_ocmp_opaque) BS.eval_ocmp_opaque;
()
#restart-solver
let rec eval_code_eq_core (g:bool) (c:code) (f:fuel) (s:machine_state) : Lemma
(ensures state_eq_opt g (BS.machine_eval_code c f s) (BS.machine_eval_code c f (core_state g s)))
(decreases %[f; c])
=
match c with
| Ins i ->
reveal_opaque (`%BS.machine_eval_code_ins) BS.machine_eval_code_ins;
if g then eval_code_eq_ins i f s (core_state g s)
| Block cs -> eval_codes_eq_core g cs f s
| IfElse cond ct cf ->
eval_ocmp_eq_core g cond s;
let (s', _) = BS.machine_eval_ocmp s cond in
let (t', _) = BS.machine_eval_ocmp (core_state g s) cond in
eval_code_eq_core g ct f s';
eval_code_eq_core g ct f t';
eval_code_eq_core g cf f s';
eval_code_eq_core g cf f t';
()
| While cond body -> eval_while_eq_core g cond body f s
and eval_codes_eq_core (g:bool) (cs:codes) (f:fuel) (s:machine_state) : Lemma
(ensures state_eq_opt g (BS.machine_eval_codes cs f s) (BS.machine_eval_codes cs f (core_state g s)))
(decreases %[f; cs])
=
match cs with
| [] -> ()
| c'::cs' -> (
eval_code_eq_core g c' f s;
match (machine_eval_code c' f s, machine_eval_code c' f (core_state g s)) with
| (None, None) -> ()
| (Some s', Some t') -> eval_codes_eq_core g cs' f s'; eval_codes_eq_core g cs' f t'
)
and eval_while_eq_core (g:bool) (cond:ocmp) (body:code) (f:fuel) (s:machine_state) : Lemma
(ensures state_eq_opt g (BS.machine_eval_while cond body f s) (BS.machine_eval_while cond body f (core_state g s)))
(decreases %[f; body])
=
if f > 0 then (
eval_ocmp_eq_core g cond s;
let (s1, _) = BS.machine_eval_ocmp s cond in
let (t1, _) = BS.machine_eval_ocmp (core_state g s) cond in
eval_code_eq_core g body (f - 1) s1;
eval_code_eq_core g body (f - 1) t1;
match (BS.machine_eval_code body (f - 1) s1, BS.machine_eval_code body (f - 1) t1) with
| (None, None) -> ()
| (Some s2, Some t2) ->
eval_while_eq_core g cond body (f - 1) s2;
eval_while_eq_core g cond body (f - 1) t2;
()
)
let eval_code_eq_f (c:code) (f:fuel) (s1 s2:machine_state) : Lemma
(requires state_eq_S false s1 s2)
(ensures state_eq_opt false (BS.machine_eval_code c f s1) (BS.machine_eval_code c f s2))
[SMTPat (BS.machine_eval_code c f s1); SMTPat (BS.machine_eval_code c f s2)]
=
eval_code_eq_core false c f s1; eval_code_eq_core false c f s2
let eval_codes_eq_f (cs:codes) (f:fuel) (s1 s2:machine_state) : Lemma
(requires state_eq_S false s1 s2)
(ensures state_eq_opt false (BS.machine_eval_codes cs f s1) (BS.machine_eval_codes cs f s2))
[SMTPat (BS.machine_eval_codes cs f s1); SMTPat (BS.machine_eval_codes cs f s2)]
=
eval_codes_eq_core false cs f s1; eval_codes_eq_core false cs f s2
let eval_while_eq_f (cond:ocmp) (body:code) (f:fuel) (s1 s2:machine_state) : Lemma
(requires state_eq_S false s1 s2)
(ensures state_eq_opt false (BS.machine_eval_while cond body f s1) (BS.machine_eval_while cond body f s2))
[SMTPat (BS.machine_eval_while cond body f s1); SMTPat (BS.machine_eval_while cond body f s2)]
=
eval_while_eq_core false cond body f s1; eval_while_eq_core false cond body f s2
let eval_code_eq_t (c:code) (f:fuel) (s1 s2:machine_state) : Lemma
(requires state_eq_S true s1 s2)
(ensures state_eq_opt true (BS.machine_eval_code c f s1) (BS.machine_eval_code c f s2))
[SMTPat (BS.machine_eval_code c f s1); SMTPat (BS.machine_eval_code c f s2)]
=
eval_code_eq_core true c f s1; eval_code_eq_core true c f s2
let eval_codes_eq_t (cs:codes) (f:fuel) (s1 s2:machine_state) : Lemma
(requires state_eq_S true s1 s2)
(ensures state_eq_opt true (BS.machine_eval_codes cs f s1) (BS.machine_eval_codes cs f s2))
[SMTPat (BS.machine_eval_codes cs f s1); SMTPat (BS.machine_eval_codes cs f s2)]
=
eval_codes_eq_core true cs f s1; eval_codes_eq_core true cs f s2
let eval_while_eq_t (cond:ocmp) (body:code) (f:fuel) (s1 s2:machine_state) : Lemma
(requires state_eq_S true s1 s2)
(ensures state_eq_opt true (BS.machine_eval_while cond body f s1) (BS.machine_eval_while cond body f s2))
[SMTPat (BS.machine_eval_while cond body f s1); SMTPat (BS.machine_eval_while cond body f s2)]
=
eval_while_eq_core true cond body f s1; eval_while_eq_core true cond body f s2
let eval_code_ts (g:bool) (c:code) (s0:machine_state) (f0:fuel) (s1:machine_state) : Type0 =
state_eq_opt g (BS.machine_eval_code c f0 s0) (Some s1)
let rec increase_fuel (g:bool) (c:code) (s0:machine_state) (f0:fuel) (sN:machine_state) (fN:fuel) : Lemma
(requires eval_code_ts g c s0 f0 sN /\ f0 <= fN)
(ensures eval_code_ts g c s0 fN sN)
(decreases %[f0; c])
=
match c with
| Ins ins -> ()
| Block l -> increase_fuels g l s0 f0 sN fN
| IfElse cond t f ->
let (s0, b0) = BS.machine_eval_ocmp s0 cond in
if b0 then increase_fuel g t s0 f0 sN fN else increase_fuel g f s0 f0 sN fN
| While cond c ->
let (s1, b0) = BS.machine_eval_ocmp s0 cond in
if b0 then (
match BS.machine_eval_code c (f0 - 1) s1 with
| None -> ()
| Some s2 ->
increase_fuel g c s1 (f0 - 1) s2 (fN - 1);
if s2.BS.ms_ok then increase_fuel g (While cond c) s2 (f0 - 1) sN (fN - 1)
else ()
)
and increase_fuels (g:bool) (c:codes) (s0:machine_state) (f0:fuel) (sN:machine_state) (fN:fuel) : Lemma
(requires eval_code_ts g (Block c) s0 f0 sN /\ f0 <= fN)
(ensures eval_code_ts g (Block c) s0 fN sN)
(decreases %[f0; c])
=
match c with
| [] -> ()
| h::t ->
(
let Some s1 = BS.machine_eval_code h f0 s0 in
increase_fuel g h s0 f0 s1 fN;
increase_fuels g t s1 f0 sN fN
)
let lemma_cmp_eq s o1 o2 = reveal_opaque (`%BS.eval_ocmp_opaque) BS.eval_ocmp_opaque
let lemma_cmp_ne s o1 o2 = reveal_opaque (`%BS.eval_ocmp_opaque) BS.eval_ocmp_opaque
let lemma_cmp_le s o1 o2 = reveal_opaque (`%BS.eval_ocmp_opaque) BS.eval_ocmp_opaque
let lemma_cmp_ge s o1 o2 = reveal_opaque (`%BS.eval_ocmp_opaque) BS.eval_ocmp_opaque
let lemma_cmp_lt s o1 o2 = reveal_opaque (`%BS.eval_ocmp_opaque) BS.eval_ocmp_opaque
let lemma_cmp_gt s o1 o2 = reveal_opaque (`%BS.eval_ocmp_opaque) BS.eval_ocmp_opaque
let lemma_valid_cmp_eq s o1 o2 = ()
let lemma_valid_cmp_ne s o1 o2 = ()
let lemma_valid_cmp_le s o1 o2 = ()
let lemma_valid_cmp_ge s o1 o2 = ()
let lemma_valid_cmp_lt s o1 o2 = ()
let lemma_valid_cmp_gt s o1 o2 = ()
let compute_merge_total (f0:fuel) (fM:fuel) =
if f0 > fM then f0 else fM
let lemma_merge_total (b0:codes) (s0:vale_state) (f0:fuel) (sM:vale_state) (fM:fuel) (sN:vale_state) =
let f = if f0 > fM then f0 else fM in
increase_fuel (codes_modifies_ghost b0) (Cons?.hd b0) (state_to_S s0) f0 (state_to_S sM) f;
increase_fuel (codes_modifies_ghost b0) (Block (Cons?.tl b0)) (state_to_S sM) fM (state_to_S sN) f
let lemma_empty_total (s0:vale_state) (bN:codes) =
(s0, 0)
let lemma_ifElse_total (ifb:ocmp) (ct:code) (cf:code) (s0:vale_state) =
(eval_ocmp s0 ifb, {s0 with vs_flags = havoc_flags}, s0, 0)
let lemma_havoc_flags : squash (Flags.to_fun havoc_flags == BS.havoc_flags) =
assert (FStar.FunctionalExtensionality.feq (Flags.to_fun havoc_flags) BS.havoc_flags)
let lemma_ifElseTrue_total (ifb:ocmp) (ct:code) (cf:code) (s0:vale_state) (f0:fuel) (sM:vale_state) =
reveal_opaque (`%BS.valid_ocmp_opaque) BS.valid_ocmp_opaque;
reveal_opaque (`%BS.eval_ocmp_opaque) BS.eval_ocmp_opaque
let lemma_ifElseFalse_total (ifb:ocmp) (ct:code) (cf:code) (s0:vale_state) (f0:fuel) (sM:vale_state) =
reveal_opaque (`%BS.valid_ocmp_opaque) BS.valid_ocmp_opaque;
reveal_opaque (`%BS.eval_ocmp_opaque) BS.eval_ocmp_opaque
let eval_while_inv_temp (c:code) (s0:vale_state) (fW:fuel) (sW:vale_state) : Type0 =
forall (f:nat).{:pattern BS.machine_eval_code c f (state_to_S sW)}
Some? (BS.machine_eval_code c f (state_to_S sW)) ==>
state_eq_opt (code_modifies_ghost c)
(BS.machine_eval_code c (f + fW) (state_to_S s0))
(BS.machine_eval_code c f (state_to_S sW))
let eval_while_inv (c:code) (s0:vale_state) (fW:fuel) (sW:vale_state) : Type0 =
eval_while_inv_temp c s0 fW sW | false | false | Vale.X64.Lemmas.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": 30,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val lemma_while_total (b:ocmp) (c:code) (s0:vale_state) : Ghost (vale_state & fuel)
(requires True)
(ensures fun (s1, f1) ->
s1 == s0 /\
eval_while_inv (While b c) s1 f1 s1
) | [] | Vale.X64.Lemmas.lemma_while_total | {
"file_name": "vale/code/arch/x64/Vale.X64.Lemmas.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | b: Vale.X64.Bytes_Code_s.ocmp -> c: Vale.X64.StateLemmas.code -> s0: Vale.X64.State.vale_state
-> Prims.Ghost (Vale.X64.State.vale_state * Vale.X64.Lemmas.fuel) | {
"end_col": 9,
"end_line": 383,
"start_col": 2,
"start_line": 383
} |
FStar.Pervasives.Lemma | val eval_code_eq_instr (inst: BS.ins) (f: fuel) (s1 s2: machine_state)
: Lemma (requires Instr? inst /\ state_eq_S true s1 s2)
(ensures
state_eq_opt true
(BS.machine_eval_code (Ins inst) f s1)
(BS.machine_eval_code (Ins inst) f s2)) | [
{
"abbrev": true,
"full_module": "Vale.X64.Memory",
"short_module": "ME"
},
{
"abbrev": true,
"full_module": "Vale.X64.Machine_Semantics_s",
"short_module": "BS"
},
{
"abbrev": false,
"full_module": "Vale.X64.Bytes_Code_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Instruction_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.StateLemmas",
"short_module": null
},
{
"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": "FStar.Mul",
"short_module": null
},
{
"abbrev": true,
"full_module": "Vale.Lib.Map16",
"short_module": "Map16"
},
{
"abbrev": true,
"full_module": "Vale.X64.Machine_Semantics_s",
"short_module": "BS"
},
{
"abbrev": false,
"full_module": "Vale.X64.Bytes_Code_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.StateLemmas",
"short_module": null
},
{
"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.HeapLemmas",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.HeapImpl",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Heap",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"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 eval_code_eq_instr (inst:BS.ins) (f:fuel) (s1 s2:machine_state) : Lemma
(requires Instr? inst /\ state_eq_S true s1 s2)
(ensures state_eq_opt true (BS.machine_eval_code (Ins inst) f s1) (BS.machine_eval_code (Ins inst) f s2))
=
reveal_opaque (`%BS.machine_eval_code_ins) BS.machine_eval_code_ins;
eval_ins_eq_instr inst ({s1 with BS.ms_trace = []}) ({s2 with BS.ms_trace = []}) | val eval_code_eq_instr (inst: BS.ins) (f: fuel) (s1 s2: machine_state)
: Lemma (requires Instr? inst /\ state_eq_S true s1 s2)
(ensures
state_eq_opt true
(BS.machine_eval_code (Ins inst) f s1)
(BS.machine_eval_code (Ins inst) f s2))
let eval_code_eq_instr (inst: BS.ins) (f: fuel) (s1 s2: machine_state)
: Lemma (requires Instr? inst /\ state_eq_S true s1 s2)
(ensures
state_eq_opt true
(BS.machine_eval_code (Ins inst) f s1)
(BS.machine_eval_code (Ins inst) f s2)) = | false | null | true | reveal_opaque (`%BS.machine_eval_code_ins) BS.machine_eval_code_ins;
eval_ins_eq_instr inst ({ s1 with BS.ms_trace = [] }) ({ s2 with BS.ms_trace = [] }) | {
"checked_file": "Vale.X64.Lemmas.fst.checked",
"dependencies": [
"Vale.X64.StateLemmas.fsti.checked",
"Vale.X64.State.fsti.checked",
"Vale.X64.Memory.fsti.checked",
"Vale.X64.Machine_Semantics_s.fst.checked",
"Vale.X64.Machine_s.fst.checked",
"Vale.X64.Instruction_s.fsti.checked",
"Vale.X64.Flags.fsti.checked",
"Vale.X64.Bytes_Code_s.fst.checked",
"prims.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.FunctionalExtensionality.fsti.checked"
],
"interface_file": true,
"source_file": "Vale.X64.Lemmas.fst"
} | [
"lemma"
] | [
"Vale.X64.Machine_Semantics_s.ins",
"Vale.X64.Lemmas.fuel",
"Vale.X64.StateLemmas.machine_state",
"Vale.X64.Lemmas.eval_ins_eq_instr",
"Vale.X64.Machine_Semantics_s.Mkmachine_state",
"Vale.X64.Machine_Semantics_s.__proj__Mkmachine_state__item__ms_ok",
"Vale.X64.Machine_Semantics_s.__proj__Mkmachine_state__item__ms_regs",
"Vale.X64.Machine_Semantics_s.__proj__Mkmachine_state__item__ms_flags",
"Vale.X64.Machine_Semantics_s.__proj__Mkmachine_state__item__ms_heap",
"Vale.X64.Machine_Semantics_s.__proj__Mkmachine_state__item__ms_stack",
"Vale.X64.Machine_Semantics_s.__proj__Mkmachine_state__item__ms_stackTaint",
"Prims.Nil",
"Vale.X64.Machine_s.observation",
"Prims.unit",
"FStar.Pervasives.reveal_opaque",
"Vale.X64.Machine_Semantics_s.machine_state",
"FStar.Pervasives.Native.option",
"Vale.X64.Machine_Semantics_s.machine_eval_code_ins",
"Prims.l_and",
"Prims.b2t",
"Vale.X64.Bytes_Code_s.uu___is_Instr",
"Vale.X64.Machine_Semantics_s.instr_annotation",
"Vale.X64.Lemmas.state_eq_S",
"Prims.squash",
"Vale.X64.Lemmas.state_eq_opt",
"Vale.X64.Machine_Semantics_s.machine_eval_code",
"Vale.X64.Machine_s.Ins",
"Vale.X64.Bytes_Code_s.instruction_t",
"Vale.X64.Bytes_Code_s.ocmp",
"FStar.Pervasives.pattern"
] | [] | module Vale.X64.Lemmas
open FStar.Mul
open Vale.X64.Machine_s
open Vale.X64.State
open Vale.X64.StateLemmas
open Vale.X64.Instruction_s
open Vale.X64.Bytes_Code_s
module BS = Vale.X64.Machine_Semantics_s
module ME = Vale.X64.Memory
#reset-options "--initial_fuel 1 --max_fuel 1 --z3rlimit 100"
#restart-solver
let rec lemma_eq_instr_apply_eval_args
(outs:list instr_out) (args:list instr_operand)
(f:instr_args_t outs args) (oprs:instr_operands_t_args args) (s1 s2:machine_state)
: Lemma
(requires state_eq_S true s1 s2)
(ensures
BS.instr_apply_eval_args outs args f oprs s1 ==
BS.instr_apply_eval_args outs args f oprs s2)
=
let open BS in
lemma_heap_ignore_ghost_machine s1.BS.ms_heap s2.BS.ms_heap;
match args with
| [] -> ()
| i::args ->
(
let (v, oprs) : option (instr_val_t i) & instr_operands_t_args args =
match i with
| IOpEx i -> let oprs = coerce oprs in (instr_eval_operand_explicit i (fst oprs) s1, snd oprs)
| IOpIm i -> (instr_eval_operand_implicit i s1, coerce oprs)
in
let f:arrow (instr_val_t i) (instr_args_t outs args) = coerce f in
match v with
| None -> ()
| Some v -> lemma_eq_instr_apply_eval_args outs args (f v) oprs s1 s2
)
#restart-solver
let rec lemma_eq_instr_apply_eval_inouts
(outs inouts:list instr_out) (args:list instr_operand)
(f:instr_inouts_t outs inouts args) (oprs:instr_operands_t inouts args) (s1 s2:machine_state)
: Lemma
(requires state_eq_S true s1 s2)
(ensures
BS.instr_apply_eval_inouts outs inouts args f oprs s1 ==
BS.instr_apply_eval_inouts outs inouts args f oprs s2)
=
let open BS in
lemma_heap_ignore_ghost_machine s1.BS.ms_heap s2.BS.ms_heap;
match inouts with
| [] -> lemma_eq_instr_apply_eval_args outs args f oprs s1 s2
| (Out, i)::inouts ->
let oprs =
match i with
| IOpEx i -> snd #(instr_operand_t i) (coerce oprs)
| IOpIm i -> coerce oprs
in
lemma_eq_instr_apply_eval_inouts outs inouts args (coerce f) oprs s1 s2
| (InOut, i)::inouts ->
(
let (v, oprs) : option (instr_val_t i) & instr_operands_t inouts args =
match i with
| IOpEx i -> let oprs = coerce oprs in (instr_eval_operand_explicit i (fst oprs) s1, snd oprs)
| IOpIm i -> (instr_eval_operand_implicit i s1, coerce oprs)
in
let f:arrow (instr_val_t i) (instr_inouts_t outs inouts args) = coerce f in
match v with
| None -> ()
| Some v -> lemma_eq_instr_apply_eval_inouts outs inouts args (f v) oprs s1 s2
)
#restart-solver
#push-options "--z3rlimit_factor 2"
let rec lemma_eq_instr_write_outputs
(outs:list instr_out) (args:list instr_operand)
(vs:instr_ret_t outs) (oprs:instr_operands_t outs args) (s1_orig s1 s2_orig s2:machine_state)
: Lemma
(requires state_eq_S true s1_orig s2_orig /\ state_eq_S true s1 s2)
(ensures
state_eq_S true
(BS.instr_write_outputs outs args vs oprs s1_orig s1)
(BS.instr_write_outputs outs args vs oprs s2_orig s2))
=
let open BS in
use_machine_state_equal ();
lemma_heap_ignore_ghost_machine s1.BS.ms_heap s2.BS.ms_heap;
lemma_heap_ignore_ghost_machine s1_orig.BS.ms_heap s2_orig.BS.ms_heap;
allow_inversion tmaddr;
match outs with
| [] -> ()
| (_, i)::outs ->
(
let ((v:instr_val_t i), (vs:instr_ret_t outs)) =
match outs with
| [] -> (vs, ())
| _::_ -> let vs = coerce vs in (fst vs, snd vs)
in
match i with
| IOpEx i ->
let oprs = coerce oprs in
let s1 = instr_write_output_explicit i v (fst oprs) s1_orig s1 in
let s2 = instr_write_output_explicit i v (fst oprs) s2_orig s2 in
lemma_eq_instr_write_outputs outs args vs (snd oprs) s1_orig s1 s2_orig s2
| IOpIm i ->
let s1 = instr_write_output_implicit i v s1_orig s1 in
let s2 = instr_write_output_implicit i v s2_orig s2 in
allow_inversion operand64;
allow_inversion operand128;
lemma_eq_instr_write_outputs outs args vs (coerce oprs) s1_orig s1 s2_orig s2
)
#pop-options
#restart-solver
let eval_ins_eq_instr (inst:BS.ins) (s1 s2:machine_state) : Lemma
(requires Instr? inst /\ state_eq_S true s1 s2)
(ensures state_eq_S true (BS.machine_eval_ins inst s1) (BS.machine_eval_ins inst s2))
=
let open BS in
let Instr it oprs ann = inst in
let InstrTypeRecord #outs #args #havoc_flags' i = it in
lemma_eq_instr_apply_eval_inouts outs outs args (instr_eval i) oprs s1 s2;
let vs = instr_apply_eval outs args (instr_eval i) oprs s1 in
let hav s =
match havoc_flags' with
| HavocFlags -> {s with ms_flags = havoc_flags}
| PreserveFlags -> s
in
let s1' = hav s1 in
let s2' = hav s2 in
match vs with
| None -> ()
| Some vs -> lemma_eq_instr_write_outputs outs args vs oprs s1 s1' s2 s2'
let eval_code_eq_instr (inst:BS.ins) (f:fuel) (s1 s2:machine_state) : Lemma
(requires Instr? inst /\ state_eq_S true s1 s2)
(ensures state_eq_opt true (BS.machine_eval_code (Ins inst) f s1) (BS.machine_eval_code (Ins inst) f s2)) | false | false | Vale.X64.Lemmas.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 1,
"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": 100,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val eval_code_eq_instr (inst: BS.ins) (f: fuel) (s1 s2: machine_state)
: Lemma (requires Instr? inst /\ state_eq_S true s1 s2)
(ensures
state_eq_opt true
(BS.machine_eval_code (Ins inst) f s1)
(BS.machine_eval_code (Ins inst) f s2)) | [] | Vale.X64.Lemmas.eval_code_eq_instr | {
"file_name": "vale/code/arch/x64/Vale.X64.Lemmas.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} |
inst: Vale.X64.Machine_Semantics_s.ins ->
f: Vale.X64.Lemmas.fuel ->
s1: Vale.X64.StateLemmas.machine_state ->
s2: Vale.X64.StateLemmas.machine_state
-> FStar.Pervasives.Lemma (requires Instr? inst /\ Vale.X64.Lemmas.state_eq_S true s1 s2)
(ensures
Vale.X64.Lemmas.state_eq_opt true
(Vale.X64.Machine_Semantics_s.machine_eval_code (Vale.X64.Machine_s.Ins inst) f s1)
(Vale.X64.Machine_Semantics_s.machine_eval_code (Vale.X64.Machine_s.Ins inst) f s2)) | {
"end_col": 82,
"end_line": 141,
"start_col": 2,
"start_line": 140
} |
FStar.Pervasives.Lemma | val eval_codes_eq_f (cs: codes) (f: fuel) (s1 s2: machine_state)
: Lemma (requires state_eq_S false s1 s2)
(ensures state_eq_opt false (BS.machine_eval_codes cs f s1) (BS.machine_eval_codes cs f s2))
[SMTPat (BS.machine_eval_codes cs f s1); SMTPat (BS.machine_eval_codes cs f s2)] | [
{
"abbrev": true,
"full_module": "Vale.X64.Memory",
"short_module": "ME"
},
{
"abbrev": true,
"full_module": "Vale.X64.Machine_Semantics_s",
"short_module": "BS"
},
{
"abbrev": false,
"full_module": "Vale.X64.Bytes_Code_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Instruction_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.StateLemmas",
"short_module": null
},
{
"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": "FStar.Mul",
"short_module": null
},
{
"abbrev": true,
"full_module": "Vale.Lib.Map16",
"short_module": "Map16"
},
{
"abbrev": true,
"full_module": "Vale.X64.Machine_Semantics_s",
"short_module": "BS"
},
{
"abbrev": false,
"full_module": "Vale.X64.Bytes_Code_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.StateLemmas",
"short_module": null
},
{
"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.HeapLemmas",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.HeapImpl",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Heap",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"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 eval_codes_eq_f (cs:codes) (f:fuel) (s1 s2:machine_state) : Lemma
(requires state_eq_S false s1 s2)
(ensures state_eq_opt false (BS.machine_eval_codes cs f s1) (BS.machine_eval_codes cs f s2))
[SMTPat (BS.machine_eval_codes cs f s1); SMTPat (BS.machine_eval_codes cs f s2)]
=
eval_codes_eq_core false cs f s1; eval_codes_eq_core false cs f s2 | val eval_codes_eq_f (cs: codes) (f: fuel) (s1 s2: machine_state)
: Lemma (requires state_eq_S false s1 s2)
(ensures state_eq_opt false (BS.machine_eval_codes cs f s1) (BS.machine_eval_codes cs f s2))
[SMTPat (BS.machine_eval_codes cs f s1); SMTPat (BS.machine_eval_codes cs f s2)]
let eval_codes_eq_f (cs: codes) (f: fuel) (s1 s2: machine_state)
: Lemma (requires state_eq_S false s1 s2)
(ensures state_eq_opt false (BS.machine_eval_codes cs f s1) (BS.machine_eval_codes cs f s2))
[SMTPat (BS.machine_eval_codes cs f s1); SMTPat (BS.machine_eval_codes cs f s2)] = | false | null | true | eval_codes_eq_core false cs f s1;
eval_codes_eq_core false cs f s2 | {
"checked_file": "Vale.X64.Lemmas.fst.checked",
"dependencies": [
"Vale.X64.StateLemmas.fsti.checked",
"Vale.X64.State.fsti.checked",
"Vale.X64.Memory.fsti.checked",
"Vale.X64.Machine_Semantics_s.fst.checked",
"Vale.X64.Machine_s.fst.checked",
"Vale.X64.Instruction_s.fsti.checked",
"Vale.X64.Flags.fsti.checked",
"Vale.X64.Bytes_Code_s.fst.checked",
"prims.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.FunctionalExtensionality.fsti.checked"
],
"interface_file": true,
"source_file": "Vale.X64.Lemmas.fst"
} | [
"lemma"
] | [
"Vale.X64.Lemmas.codes",
"Vale.X64.Lemmas.fuel",
"Vale.X64.StateLemmas.machine_state",
"Vale.X64.Lemmas.eval_codes_eq_core",
"Prims.unit",
"Vale.X64.Lemmas.state_eq_S",
"Prims.squash",
"Vale.X64.Lemmas.state_eq_opt",
"Vale.X64.Machine_Semantics_s.machine_eval_codes",
"Prims.Cons",
"FStar.Pervasives.pattern",
"FStar.Pervasives.smt_pat",
"FStar.Pervasives.Native.option",
"Vale.X64.Machine_Semantics_s.machine_state",
"Prims.Nil"
] | [] | module Vale.X64.Lemmas
open FStar.Mul
open Vale.X64.Machine_s
open Vale.X64.State
open Vale.X64.StateLemmas
open Vale.X64.Instruction_s
open Vale.X64.Bytes_Code_s
module BS = Vale.X64.Machine_Semantics_s
module ME = Vale.X64.Memory
#reset-options "--initial_fuel 1 --max_fuel 1 --z3rlimit 100"
#restart-solver
let rec lemma_eq_instr_apply_eval_args
(outs:list instr_out) (args:list instr_operand)
(f:instr_args_t outs args) (oprs:instr_operands_t_args args) (s1 s2:machine_state)
: Lemma
(requires state_eq_S true s1 s2)
(ensures
BS.instr_apply_eval_args outs args f oprs s1 ==
BS.instr_apply_eval_args outs args f oprs s2)
=
let open BS in
lemma_heap_ignore_ghost_machine s1.BS.ms_heap s2.BS.ms_heap;
match args with
| [] -> ()
| i::args ->
(
let (v, oprs) : option (instr_val_t i) & instr_operands_t_args args =
match i with
| IOpEx i -> let oprs = coerce oprs in (instr_eval_operand_explicit i (fst oprs) s1, snd oprs)
| IOpIm i -> (instr_eval_operand_implicit i s1, coerce oprs)
in
let f:arrow (instr_val_t i) (instr_args_t outs args) = coerce f in
match v with
| None -> ()
| Some v -> lemma_eq_instr_apply_eval_args outs args (f v) oprs s1 s2
)
#restart-solver
let rec lemma_eq_instr_apply_eval_inouts
(outs inouts:list instr_out) (args:list instr_operand)
(f:instr_inouts_t outs inouts args) (oprs:instr_operands_t inouts args) (s1 s2:machine_state)
: Lemma
(requires state_eq_S true s1 s2)
(ensures
BS.instr_apply_eval_inouts outs inouts args f oprs s1 ==
BS.instr_apply_eval_inouts outs inouts args f oprs s2)
=
let open BS in
lemma_heap_ignore_ghost_machine s1.BS.ms_heap s2.BS.ms_heap;
match inouts with
| [] -> lemma_eq_instr_apply_eval_args outs args f oprs s1 s2
| (Out, i)::inouts ->
let oprs =
match i with
| IOpEx i -> snd #(instr_operand_t i) (coerce oprs)
| IOpIm i -> coerce oprs
in
lemma_eq_instr_apply_eval_inouts outs inouts args (coerce f) oprs s1 s2
| (InOut, i)::inouts ->
(
let (v, oprs) : option (instr_val_t i) & instr_operands_t inouts args =
match i with
| IOpEx i -> let oprs = coerce oprs in (instr_eval_operand_explicit i (fst oprs) s1, snd oprs)
| IOpIm i -> (instr_eval_operand_implicit i s1, coerce oprs)
in
let f:arrow (instr_val_t i) (instr_inouts_t outs inouts args) = coerce f in
match v with
| None -> ()
| Some v -> lemma_eq_instr_apply_eval_inouts outs inouts args (f v) oprs s1 s2
)
#restart-solver
#push-options "--z3rlimit_factor 2"
let rec lemma_eq_instr_write_outputs
(outs:list instr_out) (args:list instr_operand)
(vs:instr_ret_t outs) (oprs:instr_operands_t outs args) (s1_orig s1 s2_orig s2:machine_state)
: Lemma
(requires state_eq_S true s1_orig s2_orig /\ state_eq_S true s1 s2)
(ensures
state_eq_S true
(BS.instr_write_outputs outs args vs oprs s1_orig s1)
(BS.instr_write_outputs outs args vs oprs s2_orig s2))
=
let open BS in
use_machine_state_equal ();
lemma_heap_ignore_ghost_machine s1.BS.ms_heap s2.BS.ms_heap;
lemma_heap_ignore_ghost_machine s1_orig.BS.ms_heap s2_orig.BS.ms_heap;
allow_inversion tmaddr;
match outs with
| [] -> ()
| (_, i)::outs ->
(
let ((v:instr_val_t i), (vs:instr_ret_t outs)) =
match outs with
| [] -> (vs, ())
| _::_ -> let vs = coerce vs in (fst vs, snd vs)
in
match i with
| IOpEx i ->
let oprs = coerce oprs in
let s1 = instr_write_output_explicit i v (fst oprs) s1_orig s1 in
let s2 = instr_write_output_explicit i v (fst oprs) s2_orig s2 in
lemma_eq_instr_write_outputs outs args vs (snd oprs) s1_orig s1 s2_orig s2
| IOpIm i ->
let s1 = instr_write_output_implicit i v s1_orig s1 in
let s2 = instr_write_output_implicit i v s2_orig s2 in
allow_inversion operand64;
allow_inversion operand128;
lemma_eq_instr_write_outputs outs args vs (coerce oprs) s1_orig s1 s2_orig s2
)
#pop-options
#restart-solver
let eval_ins_eq_instr (inst:BS.ins) (s1 s2:machine_state) : Lemma
(requires Instr? inst /\ state_eq_S true s1 s2)
(ensures state_eq_S true (BS.machine_eval_ins inst s1) (BS.machine_eval_ins inst s2))
=
let open BS in
let Instr it oprs ann = inst in
let InstrTypeRecord #outs #args #havoc_flags' i = it in
lemma_eq_instr_apply_eval_inouts outs outs args (instr_eval i) oprs s1 s2;
let vs = instr_apply_eval outs args (instr_eval i) oprs s1 in
let hav s =
match havoc_flags' with
| HavocFlags -> {s with ms_flags = havoc_flags}
| PreserveFlags -> s
in
let s1' = hav s1 in
let s2' = hav s2 in
match vs with
| None -> ()
| Some vs -> lemma_eq_instr_write_outputs outs args vs oprs s1 s1' s2 s2'
let eval_code_eq_instr (inst:BS.ins) (f:fuel) (s1 s2:machine_state) : Lemma
(requires Instr? inst /\ state_eq_S true s1 s2)
(ensures state_eq_opt true (BS.machine_eval_code (Ins inst) f s1) (BS.machine_eval_code (Ins inst) f s2))
=
reveal_opaque (`%BS.machine_eval_code_ins) BS.machine_eval_code_ins;
eval_ins_eq_instr inst ({s1 with BS.ms_trace = []}) ({s2 with BS.ms_trace = []})
let eval_code_eq_dealloc (inst:BS.ins) (f:fuel) (s1 s2:machine_state) : Lemma
(requires Dealloc? inst /\ state_eq_S true s1 s2)
(ensures state_eq_opt true (BS.machine_eval_code (Ins inst) f s1) (BS.machine_eval_code (Ins inst) f s2))
=
reveal_opaque (`%BS.machine_eval_code_ins) BS.machine_eval_code_ins;
use_machine_state_equal ();
lemma_heap_ignore_ghost_machine s1.BS.ms_heap s2.BS.ms_heap;
allow_inversion tmaddr
let eval_code_eq_alloc (inst:BS.ins) (f:fuel) (s1 s2:machine_state) : Lemma
(requires Alloc? inst /\ state_eq_S true s1 s2)
(ensures state_eq_opt true (BS.machine_eval_code (Ins inst) f s1) (BS.machine_eval_code (Ins inst) f s2))
=
reveal_opaque (`%BS.machine_eval_code_ins) BS.machine_eval_code_ins;
use_machine_state_equal ();
lemma_heap_ignore_ghost_machine s1.BS.ms_heap s2.BS.ms_heap;
allow_inversion tmaddr
let eval_code_eq_push (inst:BS.ins) (f:fuel) (s1 s2:machine_state) : Lemma
(requires Push? inst /\ state_eq_S true s1 s2)
(ensures state_eq_opt true (BS.machine_eval_code (Ins inst) f s1) (BS.machine_eval_code (Ins inst) f s2))
=
reveal_opaque (`%BS.machine_eval_code_ins) BS.machine_eval_code_ins;
use_machine_state_equal ();
lemma_heap_ignore_ghost_machine s1.BS.ms_heap s2.BS.ms_heap;
allow_inversion tmaddr
let eval_code_eq_pop (inst:BS.ins) (f:fuel) (s1 s2:machine_state) : Lemma
(requires Pop? inst /\ state_eq_S true s1 s2)
(ensures state_eq_opt true (BS.machine_eval_code (Ins inst) f s1) (BS.machine_eval_code (Ins inst) f s2))
=
reveal_opaque (`%BS.machine_eval_code_ins) BS.machine_eval_code_ins;
use_machine_state_equal ();
lemma_heap_ignore_ghost_machine s1.BS.ms_heap s2.BS.ms_heap;
allow_inversion tmaddr
let eval_code_eq_ins (i:BS.ins) (f:fuel) (s1 s2:machine_state) : Lemma
(requires state_eq_S true s1 s2)
(ensures state_eq_opt true (BS.machine_eval_code (Ins i) f s1) (BS.machine_eval_code (Ins i) f s2))
=
match i with
| Instr _ _ _ -> eval_code_eq_instr i f s1 s2
| Dealloc _ -> eval_code_eq_dealloc i f s1 s2
| Alloc _ -> eval_code_eq_alloc i f s1 s2
| Push _ _ -> eval_code_eq_push i f s1 s2
| Pop _ _ -> eval_code_eq_pop i f s1 s2
#reset-options "--fuel 2 --z3rlimit 30"
let eval_ocmp_eq_core (g:bool) (cond:ocmp) (s:machine_state) : Lemma
(ensures (
let (s1, b1) = BS.machine_eval_ocmp s cond in
let (s2, b2) = BS.machine_eval_ocmp (core_state g s) cond in
state_eq_S g s1 s2 /\ b1 == b2
))
=
reveal_opaque (`%BS.valid_ocmp_opaque) BS.valid_ocmp_opaque;
reveal_opaque (`%BS.eval_ocmp_opaque) BS.eval_ocmp_opaque;
()
#restart-solver
let rec eval_code_eq_core (g:bool) (c:code) (f:fuel) (s:machine_state) : Lemma
(ensures state_eq_opt g (BS.machine_eval_code c f s) (BS.machine_eval_code c f (core_state g s)))
(decreases %[f; c])
=
match c with
| Ins i ->
reveal_opaque (`%BS.machine_eval_code_ins) BS.machine_eval_code_ins;
if g then eval_code_eq_ins i f s (core_state g s)
| Block cs -> eval_codes_eq_core g cs f s
| IfElse cond ct cf ->
eval_ocmp_eq_core g cond s;
let (s', _) = BS.machine_eval_ocmp s cond in
let (t', _) = BS.machine_eval_ocmp (core_state g s) cond in
eval_code_eq_core g ct f s';
eval_code_eq_core g ct f t';
eval_code_eq_core g cf f s';
eval_code_eq_core g cf f t';
()
| While cond body -> eval_while_eq_core g cond body f s
and eval_codes_eq_core (g:bool) (cs:codes) (f:fuel) (s:machine_state) : Lemma
(ensures state_eq_opt g (BS.machine_eval_codes cs f s) (BS.machine_eval_codes cs f (core_state g s)))
(decreases %[f; cs])
=
match cs with
| [] -> ()
| c'::cs' -> (
eval_code_eq_core g c' f s;
match (machine_eval_code c' f s, machine_eval_code c' f (core_state g s)) with
| (None, None) -> ()
| (Some s', Some t') -> eval_codes_eq_core g cs' f s'; eval_codes_eq_core g cs' f t'
)
and eval_while_eq_core (g:bool) (cond:ocmp) (body:code) (f:fuel) (s:machine_state) : Lemma
(ensures state_eq_opt g (BS.machine_eval_while cond body f s) (BS.machine_eval_while cond body f (core_state g s)))
(decreases %[f; body])
=
if f > 0 then (
eval_ocmp_eq_core g cond s;
let (s1, _) = BS.machine_eval_ocmp s cond in
let (t1, _) = BS.machine_eval_ocmp (core_state g s) cond in
eval_code_eq_core g body (f - 1) s1;
eval_code_eq_core g body (f - 1) t1;
match (BS.machine_eval_code body (f - 1) s1, BS.machine_eval_code body (f - 1) t1) with
| (None, None) -> ()
| (Some s2, Some t2) ->
eval_while_eq_core g cond body (f - 1) s2;
eval_while_eq_core g cond body (f - 1) t2;
()
)
let eval_code_eq_f (c:code) (f:fuel) (s1 s2:machine_state) : Lemma
(requires state_eq_S false s1 s2)
(ensures state_eq_opt false (BS.machine_eval_code c f s1) (BS.machine_eval_code c f s2))
[SMTPat (BS.machine_eval_code c f s1); SMTPat (BS.machine_eval_code c f s2)]
=
eval_code_eq_core false c f s1; eval_code_eq_core false c f s2
let eval_codes_eq_f (cs:codes) (f:fuel) (s1 s2:machine_state) : Lemma
(requires state_eq_S false s1 s2)
(ensures state_eq_opt false (BS.machine_eval_codes cs f s1) (BS.machine_eval_codes cs f s2))
[SMTPat (BS.machine_eval_codes cs f s1); SMTPat (BS.machine_eval_codes cs f s2)] | false | false | Vale.X64.Lemmas.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": 30,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val eval_codes_eq_f (cs: codes) (f: fuel) (s1 s2: machine_state)
: Lemma (requires state_eq_S false s1 s2)
(ensures state_eq_opt false (BS.machine_eval_codes cs f s1) (BS.machine_eval_codes cs f s2))
[SMTPat (BS.machine_eval_codes cs f s1); SMTPat (BS.machine_eval_codes cs f s2)] | [] | Vale.X64.Lemmas.eval_codes_eq_f | {
"file_name": "vale/code/arch/x64/Vale.X64.Lemmas.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} |
cs: Vale.X64.Lemmas.codes ->
f: Vale.X64.Lemmas.fuel ->
s1: Vale.X64.StateLemmas.machine_state ->
s2: Vale.X64.StateLemmas.machine_state
-> FStar.Pervasives.Lemma (requires Vale.X64.Lemmas.state_eq_S false s1 s2)
(ensures
Vale.X64.Lemmas.state_eq_opt false
(Vale.X64.Machine_Semantics_s.machine_eval_codes cs f s1)
(Vale.X64.Machine_Semantics_s.machine_eval_codes cs f s2))
[
SMTPat (Vale.X64.Machine_Semantics_s.machine_eval_codes cs f s1);
SMTPat (Vale.X64.Machine_Semantics_s.machine_eval_codes cs f s2)
] | {
"end_col": 68,
"end_line": 265,
"start_col": 2,
"start_line": 265
} |
FStar.Pervasives.Lemma | val eval_while_eq_f (cond: ocmp) (body: code) (f: fuel) (s1 s2: machine_state)
: Lemma (requires state_eq_S false s1 s2)
(ensures
state_eq_opt false
(BS.machine_eval_while cond body f s1)
(BS.machine_eval_while cond body f s2))
[SMTPat (BS.machine_eval_while cond body f s1); SMTPat (BS.machine_eval_while cond body f s2)] | [
{
"abbrev": true,
"full_module": "Vale.X64.Memory",
"short_module": "ME"
},
{
"abbrev": true,
"full_module": "Vale.X64.Machine_Semantics_s",
"short_module": "BS"
},
{
"abbrev": false,
"full_module": "Vale.X64.Bytes_Code_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Instruction_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.StateLemmas",
"short_module": null
},
{
"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": "FStar.Mul",
"short_module": null
},
{
"abbrev": true,
"full_module": "Vale.Lib.Map16",
"short_module": "Map16"
},
{
"abbrev": true,
"full_module": "Vale.X64.Machine_Semantics_s",
"short_module": "BS"
},
{
"abbrev": false,
"full_module": "Vale.X64.Bytes_Code_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.StateLemmas",
"short_module": null
},
{
"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.HeapLemmas",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.HeapImpl",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Heap",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"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 eval_while_eq_f (cond:ocmp) (body:code) (f:fuel) (s1 s2:machine_state) : Lemma
(requires state_eq_S false s1 s2)
(ensures state_eq_opt false (BS.machine_eval_while cond body f s1) (BS.machine_eval_while cond body f s2))
[SMTPat (BS.machine_eval_while cond body f s1); SMTPat (BS.machine_eval_while cond body f s2)]
=
eval_while_eq_core false cond body f s1; eval_while_eq_core false cond body f s2 | val eval_while_eq_f (cond: ocmp) (body: code) (f: fuel) (s1 s2: machine_state)
: Lemma (requires state_eq_S false s1 s2)
(ensures
state_eq_opt false
(BS.machine_eval_while cond body f s1)
(BS.machine_eval_while cond body f s2))
[SMTPat (BS.machine_eval_while cond body f s1); SMTPat (BS.machine_eval_while cond body f s2)]
let eval_while_eq_f (cond: ocmp) (body: code) (f: fuel) (s1 s2: machine_state)
: Lemma (requires state_eq_S false s1 s2)
(ensures
state_eq_opt false
(BS.machine_eval_while cond body f s1)
(BS.machine_eval_while cond body f s2))
[SMTPat (BS.machine_eval_while cond body f s1); SMTPat (BS.machine_eval_while cond body f s2)] = | false | null | true | eval_while_eq_core false cond body f s1;
eval_while_eq_core false cond body f s2 | {
"checked_file": "Vale.X64.Lemmas.fst.checked",
"dependencies": [
"Vale.X64.StateLemmas.fsti.checked",
"Vale.X64.State.fsti.checked",
"Vale.X64.Memory.fsti.checked",
"Vale.X64.Machine_Semantics_s.fst.checked",
"Vale.X64.Machine_s.fst.checked",
"Vale.X64.Instruction_s.fsti.checked",
"Vale.X64.Flags.fsti.checked",
"Vale.X64.Bytes_Code_s.fst.checked",
"prims.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.FunctionalExtensionality.fsti.checked"
],
"interface_file": true,
"source_file": "Vale.X64.Lemmas.fst"
} | [
"lemma"
] | [
"Vale.X64.Bytes_Code_s.ocmp",
"Vale.X64.StateLemmas.code",
"Vale.X64.Lemmas.fuel",
"Vale.X64.StateLemmas.machine_state",
"Vale.X64.Lemmas.eval_while_eq_core",
"Prims.unit",
"Vale.X64.Lemmas.state_eq_S",
"Prims.squash",
"Vale.X64.Lemmas.state_eq_opt",
"Vale.X64.Machine_Semantics_s.machine_eval_while",
"Prims.Cons",
"FStar.Pervasives.pattern",
"FStar.Pervasives.smt_pat",
"FStar.Pervasives.Native.option",
"Vale.X64.Machine_Semantics_s.machine_state",
"Prims.Nil"
] | [] | module Vale.X64.Lemmas
open FStar.Mul
open Vale.X64.Machine_s
open Vale.X64.State
open Vale.X64.StateLemmas
open Vale.X64.Instruction_s
open Vale.X64.Bytes_Code_s
module BS = Vale.X64.Machine_Semantics_s
module ME = Vale.X64.Memory
#reset-options "--initial_fuel 1 --max_fuel 1 --z3rlimit 100"
#restart-solver
let rec lemma_eq_instr_apply_eval_args
(outs:list instr_out) (args:list instr_operand)
(f:instr_args_t outs args) (oprs:instr_operands_t_args args) (s1 s2:machine_state)
: Lemma
(requires state_eq_S true s1 s2)
(ensures
BS.instr_apply_eval_args outs args f oprs s1 ==
BS.instr_apply_eval_args outs args f oprs s2)
=
let open BS in
lemma_heap_ignore_ghost_machine s1.BS.ms_heap s2.BS.ms_heap;
match args with
| [] -> ()
| i::args ->
(
let (v, oprs) : option (instr_val_t i) & instr_operands_t_args args =
match i with
| IOpEx i -> let oprs = coerce oprs in (instr_eval_operand_explicit i (fst oprs) s1, snd oprs)
| IOpIm i -> (instr_eval_operand_implicit i s1, coerce oprs)
in
let f:arrow (instr_val_t i) (instr_args_t outs args) = coerce f in
match v with
| None -> ()
| Some v -> lemma_eq_instr_apply_eval_args outs args (f v) oprs s1 s2
)
#restart-solver
let rec lemma_eq_instr_apply_eval_inouts
(outs inouts:list instr_out) (args:list instr_operand)
(f:instr_inouts_t outs inouts args) (oprs:instr_operands_t inouts args) (s1 s2:machine_state)
: Lemma
(requires state_eq_S true s1 s2)
(ensures
BS.instr_apply_eval_inouts outs inouts args f oprs s1 ==
BS.instr_apply_eval_inouts outs inouts args f oprs s2)
=
let open BS in
lemma_heap_ignore_ghost_machine s1.BS.ms_heap s2.BS.ms_heap;
match inouts with
| [] -> lemma_eq_instr_apply_eval_args outs args f oprs s1 s2
| (Out, i)::inouts ->
let oprs =
match i with
| IOpEx i -> snd #(instr_operand_t i) (coerce oprs)
| IOpIm i -> coerce oprs
in
lemma_eq_instr_apply_eval_inouts outs inouts args (coerce f) oprs s1 s2
| (InOut, i)::inouts ->
(
let (v, oprs) : option (instr_val_t i) & instr_operands_t inouts args =
match i with
| IOpEx i -> let oprs = coerce oprs in (instr_eval_operand_explicit i (fst oprs) s1, snd oprs)
| IOpIm i -> (instr_eval_operand_implicit i s1, coerce oprs)
in
let f:arrow (instr_val_t i) (instr_inouts_t outs inouts args) = coerce f in
match v with
| None -> ()
| Some v -> lemma_eq_instr_apply_eval_inouts outs inouts args (f v) oprs s1 s2
)
#restart-solver
#push-options "--z3rlimit_factor 2"
let rec lemma_eq_instr_write_outputs
(outs:list instr_out) (args:list instr_operand)
(vs:instr_ret_t outs) (oprs:instr_operands_t outs args) (s1_orig s1 s2_orig s2:machine_state)
: Lemma
(requires state_eq_S true s1_orig s2_orig /\ state_eq_S true s1 s2)
(ensures
state_eq_S true
(BS.instr_write_outputs outs args vs oprs s1_orig s1)
(BS.instr_write_outputs outs args vs oprs s2_orig s2))
=
let open BS in
use_machine_state_equal ();
lemma_heap_ignore_ghost_machine s1.BS.ms_heap s2.BS.ms_heap;
lemma_heap_ignore_ghost_machine s1_orig.BS.ms_heap s2_orig.BS.ms_heap;
allow_inversion tmaddr;
match outs with
| [] -> ()
| (_, i)::outs ->
(
let ((v:instr_val_t i), (vs:instr_ret_t outs)) =
match outs with
| [] -> (vs, ())
| _::_ -> let vs = coerce vs in (fst vs, snd vs)
in
match i with
| IOpEx i ->
let oprs = coerce oprs in
let s1 = instr_write_output_explicit i v (fst oprs) s1_orig s1 in
let s2 = instr_write_output_explicit i v (fst oprs) s2_orig s2 in
lemma_eq_instr_write_outputs outs args vs (snd oprs) s1_orig s1 s2_orig s2
| IOpIm i ->
let s1 = instr_write_output_implicit i v s1_orig s1 in
let s2 = instr_write_output_implicit i v s2_orig s2 in
allow_inversion operand64;
allow_inversion operand128;
lemma_eq_instr_write_outputs outs args vs (coerce oprs) s1_orig s1 s2_orig s2
)
#pop-options
#restart-solver
let eval_ins_eq_instr (inst:BS.ins) (s1 s2:machine_state) : Lemma
(requires Instr? inst /\ state_eq_S true s1 s2)
(ensures state_eq_S true (BS.machine_eval_ins inst s1) (BS.machine_eval_ins inst s2))
=
let open BS in
let Instr it oprs ann = inst in
let InstrTypeRecord #outs #args #havoc_flags' i = it in
lemma_eq_instr_apply_eval_inouts outs outs args (instr_eval i) oprs s1 s2;
let vs = instr_apply_eval outs args (instr_eval i) oprs s1 in
let hav s =
match havoc_flags' with
| HavocFlags -> {s with ms_flags = havoc_flags}
| PreserveFlags -> s
in
let s1' = hav s1 in
let s2' = hav s2 in
match vs with
| None -> ()
| Some vs -> lemma_eq_instr_write_outputs outs args vs oprs s1 s1' s2 s2'
let eval_code_eq_instr (inst:BS.ins) (f:fuel) (s1 s2:machine_state) : Lemma
(requires Instr? inst /\ state_eq_S true s1 s2)
(ensures state_eq_opt true (BS.machine_eval_code (Ins inst) f s1) (BS.machine_eval_code (Ins inst) f s2))
=
reveal_opaque (`%BS.machine_eval_code_ins) BS.machine_eval_code_ins;
eval_ins_eq_instr inst ({s1 with BS.ms_trace = []}) ({s2 with BS.ms_trace = []})
let eval_code_eq_dealloc (inst:BS.ins) (f:fuel) (s1 s2:machine_state) : Lemma
(requires Dealloc? inst /\ state_eq_S true s1 s2)
(ensures state_eq_opt true (BS.machine_eval_code (Ins inst) f s1) (BS.machine_eval_code (Ins inst) f s2))
=
reveal_opaque (`%BS.machine_eval_code_ins) BS.machine_eval_code_ins;
use_machine_state_equal ();
lemma_heap_ignore_ghost_machine s1.BS.ms_heap s2.BS.ms_heap;
allow_inversion tmaddr
let eval_code_eq_alloc (inst:BS.ins) (f:fuel) (s1 s2:machine_state) : Lemma
(requires Alloc? inst /\ state_eq_S true s1 s2)
(ensures state_eq_opt true (BS.machine_eval_code (Ins inst) f s1) (BS.machine_eval_code (Ins inst) f s2))
=
reveal_opaque (`%BS.machine_eval_code_ins) BS.machine_eval_code_ins;
use_machine_state_equal ();
lemma_heap_ignore_ghost_machine s1.BS.ms_heap s2.BS.ms_heap;
allow_inversion tmaddr
let eval_code_eq_push (inst:BS.ins) (f:fuel) (s1 s2:machine_state) : Lemma
(requires Push? inst /\ state_eq_S true s1 s2)
(ensures state_eq_opt true (BS.machine_eval_code (Ins inst) f s1) (BS.machine_eval_code (Ins inst) f s2))
=
reveal_opaque (`%BS.machine_eval_code_ins) BS.machine_eval_code_ins;
use_machine_state_equal ();
lemma_heap_ignore_ghost_machine s1.BS.ms_heap s2.BS.ms_heap;
allow_inversion tmaddr
let eval_code_eq_pop (inst:BS.ins) (f:fuel) (s1 s2:machine_state) : Lemma
(requires Pop? inst /\ state_eq_S true s1 s2)
(ensures state_eq_opt true (BS.machine_eval_code (Ins inst) f s1) (BS.machine_eval_code (Ins inst) f s2))
=
reveal_opaque (`%BS.machine_eval_code_ins) BS.machine_eval_code_ins;
use_machine_state_equal ();
lemma_heap_ignore_ghost_machine s1.BS.ms_heap s2.BS.ms_heap;
allow_inversion tmaddr
let eval_code_eq_ins (i:BS.ins) (f:fuel) (s1 s2:machine_state) : Lemma
(requires state_eq_S true s1 s2)
(ensures state_eq_opt true (BS.machine_eval_code (Ins i) f s1) (BS.machine_eval_code (Ins i) f s2))
=
match i with
| Instr _ _ _ -> eval_code_eq_instr i f s1 s2
| Dealloc _ -> eval_code_eq_dealloc i f s1 s2
| Alloc _ -> eval_code_eq_alloc i f s1 s2
| Push _ _ -> eval_code_eq_push i f s1 s2
| Pop _ _ -> eval_code_eq_pop i f s1 s2
#reset-options "--fuel 2 --z3rlimit 30"
let eval_ocmp_eq_core (g:bool) (cond:ocmp) (s:machine_state) : Lemma
(ensures (
let (s1, b1) = BS.machine_eval_ocmp s cond in
let (s2, b2) = BS.machine_eval_ocmp (core_state g s) cond in
state_eq_S g s1 s2 /\ b1 == b2
))
=
reveal_opaque (`%BS.valid_ocmp_opaque) BS.valid_ocmp_opaque;
reveal_opaque (`%BS.eval_ocmp_opaque) BS.eval_ocmp_opaque;
()
#restart-solver
let rec eval_code_eq_core (g:bool) (c:code) (f:fuel) (s:machine_state) : Lemma
(ensures state_eq_opt g (BS.machine_eval_code c f s) (BS.machine_eval_code c f (core_state g s)))
(decreases %[f; c])
=
match c with
| Ins i ->
reveal_opaque (`%BS.machine_eval_code_ins) BS.machine_eval_code_ins;
if g then eval_code_eq_ins i f s (core_state g s)
| Block cs -> eval_codes_eq_core g cs f s
| IfElse cond ct cf ->
eval_ocmp_eq_core g cond s;
let (s', _) = BS.machine_eval_ocmp s cond in
let (t', _) = BS.machine_eval_ocmp (core_state g s) cond in
eval_code_eq_core g ct f s';
eval_code_eq_core g ct f t';
eval_code_eq_core g cf f s';
eval_code_eq_core g cf f t';
()
| While cond body -> eval_while_eq_core g cond body f s
and eval_codes_eq_core (g:bool) (cs:codes) (f:fuel) (s:machine_state) : Lemma
(ensures state_eq_opt g (BS.machine_eval_codes cs f s) (BS.machine_eval_codes cs f (core_state g s)))
(decreases %[f; cs])
=
match cs with
| [] -> ()
| c'::cs' -> (
eval_code_eq_core g c' f s;
match (machine_eval_code c' f s, machine_eval_code c' f (core_state g s)) with
| (None, None) -> ()
| (Some s', Some t') -> eval_codes_eq_core g cs' f s'; eval_codes_eq_core g cs' f t'
)
and eval_while_eq_core (g:bool) (cond:ocmp) (body:code) (f:fuel) (s:machine_state) : Lemma
(ensures state_eq_opt g (BS.machine_eval_while cond body f s) (BS.machine_eval_while cond body f (core_state g s)))
(decreases %[f; body])
=
if f > 0 then (
eval_ocmp_eq_core g cond s;
let (s1, _) = BS.machine_eval_ocmp s cond in
let (t1, _) = BS.machine_eval_ocmp (core_state g s) cond in
eval_code_eq_core g body (f - 1) s1;
eval_code_eq_core g body (f - 1) t1;
match (BS.machine_eval_code body (f - 1) s1, BS.machine_eval_code body (f - 1) t1) with
| (None, None) -> ()
| (Some s2, Some t2) ->
eval_while_eq_core g cond body (f - 1) s2;
eval_while_eq_core g cond body (f - 1) t2;
()
)
let eval_code_eq_f (c:code) (f:fuel) (s1 s2:machine_state) : Lemma
(requires state_eq_S false s1 s2)
(ensures state_eq_opt false (BS.machine_eval_code c f s1) (BS.machine_eval_code c f s2))
[SMTPat (BS.machine_eval_code c f s1); SMTPat (BS.machine_eval_code c f s2)]
=
eval_code_eq_core false c f s1; eval_code_eq_core false c f s2
let eval_codes_eq_f (cs:codes) (f:fuel) (s1 s2:machine_state) : Lemma
(requires state_eq_S false s1 s2)
(ensures state_eq_opt false (BS.machine_eval_codes cs f s1) (BS.machine_eval_codes cs f s2))
[SMTPat (BS.machine_eval_codes cs f s1); SMTPat (BS.machine_eval_codes cs f s2)]
=
eval_codes_eq_core false cs f s1; eval_codes_eq_core false cs f s2
let eval_while_eq_f (cond:ocmp) (body:code) (f:fuel) (s1 s2:machine_state) : Lemma
(requires state_eq_S false s1 s2)
(ensures state_eq_opt false (BS.machine_eval_while cond body f s1) (BS.machine_eval_while cond body f s2))
[SMTPat (BS.machine_eval_while cond body f s1); SMTPat (BS.machine_eval_while cond body f s2)] | false | false | Vale.X64.Lemmas.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": 30,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val eval_while_eq_f (cond: ocmp) (body: code) (f: fuel) (s1 s2: machine_state)
: Lemma (requires state_eq_S false s1 s2)
(ensures
state_eq_opt false
(BS.machine_eval_while cond body f s1)
(BS.machine_eval_while cond body f s2))
[SMTPat (BS.machine_eval_while cond body f s1); SMTPat (BS.machine_eval_while cond body f s2)] | [] | Vale.X64.Lemmas.eval_while_eq_f | {
"file_name": "vale/code/arch/x64/Vale.X64.Lemmas.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} |
cond: Vale.X64.Bytes_Code_s.ocmp ->
body: Vale.X64.StateLemmas.code ->
f: Vale.X64.Lemmas.fuel ->
s1: Vale.X64.StateLemmas.machine_state ->
s2: Vale.X64.StateLemmas.machine_state
-> FStar.Pervasives.Lemma (requires Vale.X64.Lemmas.state_eq_S false s1 s2)
(ensures
Vale.X64.Lemmas.state_eq_opt false
(Vale.X64.Machine_Semantics_s.machine_eval_while cond body f s1)
(Vale.X64.Machine_Semantics_s.machine_eval_while cond body f s2))
[
SMTPat (Vale.X64.Machine_Semantics_s.machine_eval_while cond body f s1);
SMTPat (Vale.X64.Machine_Semantics_s.machine_eval_while cond body f s2)
] | {
"end_col": 82,
"end_line": 272,
"start_col": 2,
"start_line": 272
} |
Prims.Ghost | val lemma_whileTrue_total (b:ocmp) (c:code) (s0:vale_state) (sW:vale_state) (fW:fuel) : Ghost (vale_state & fuel)
(requires eval_ocmp sW b)
(ensures fun (s1, f1) -> s1 == {sW with vs_flags = havoc_flags} /\ f1 == fW) | [
{
"abbrev": true,
"full_module": "Vale.X64.Memory",
"short_module": "ME"
},
{
"abbrev": false,
"full_module": "Vale.X64.Instruction_s",
"short_module": null
},
{
"abbrev": true,
"full_module": "Vale.Lib.Map16",
"short_module": "Map16"
},
{
"abbrev": true,
"full_module": "Vale.X64.Machine_Semantics_s",
"short_module": "BS"
},
{
"abbrev": false,
"full_module": "Vale.X64.Bytes_Code_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.StateLemmas",
"short_module": null
},
{
"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.HeapLemmas",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.HeapImpl",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Heap",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"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 lemma_whileTrue_total (b:ocmp) (c:code) (s0:vale_state) (sW:vale_state) (fW:fuel) =
({sW with vs_flags = havoc_flags}, fW) | val lemma_whileTrue_total (b:ocmp) (c:code) (s0:vale_state) (sW:vale_state) (fW:fuel) : Ghost (vale_state & fuel)
(requires eval_ocmp sW b)
(ensures fun (s1, f1) -> s1 == {sW with vs_flags = havoc_flags} /\ f1 == fW)
let lemma_whileTrue_total (b: ocmp) (c: code) (s0 sW: vale_state) (fW: fuel) = | false | null | false | ({ sW with vs_flags = havoc_flags }, fW) | {
"checked_file": "Vale.X64.Lemmas.fst.checked",
"dependencies": [
"Vale.X64.StateLemmas.fsti.checked",
"Vale.X64.State.fsti.checked",
"Vale.X64.Memory.fsti.checked",
"Vale.X64.Machine_Semantics_s.fst.checked",
"Vale.X64.Machine_s.fst.checked",
"Vale.X64.Instruction_s.fsti.checked",
"Vale.X64.Flags.fsti.checked",
"Vale.X64.Bytes_Code_s.fst.checked",
"prims.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.FunctionalExtensionality.fsti.checked"
],
"interface_file": true,
"source_file": "Vale.X64.Lemmas.fst"
} | [] | [
"Vale.X64.Bytes_Code_s.ocmp",
"Vale.X64.StateLemmas.code",
"Vale.X64.State.vale_state",
"Vale.X64.Lemmas.fuel",
"FStar.Pervasives.Native.Mktuple2",
"Vale.X64.State.Mkvale_state",
"Vale.X64.State.__proj__Mkvale_state__item__vs_ok",
"Vale.X64.State.__proj__Mkvale_state__item__vs_regs",
"Vale.X64.Lemmas.havoc_flags",
"Vale.X64.State.__proj__Mkvale_state__item__vs_heap",
"Vale.X64.State.__proj__Mkvale_state__item__vs_stack",
"Vale.X64.State.__proj__Mkvale_state__item__vs_stackTaint",
"FStar.Pervasives.Native.tuple2"
] | [] | module Vale.X64.Lemmas
open FStar.Mul
open Vale.X64.Machine_s
open Vale.X64.State
open Vale.X64.StateLemmas
open Vale.X64.Instruction_s
open Vale.X64.Bytes_Code_s
module BS = Vale.X64.Machine_Semantics_s
module ME = Vale.X64.Memory
#reset-options "--initial_fuel 1 --max_fuel 1 --z3rlimit 100"
#restart-solver
let rec lemma_eq_instr_apply_eval_args
(outs:list instr_out) (args:list instr_operand)
(f:instr_args_t outs args) (oprs:instr_operands_t_args args) (s1 s2:machine_state)
: Lemma
(requires state_eq_S true s1 s2)
(ensures
BS.instr_apply_eval_args outs args f oprs s1 ==
BS.instr_apply_eval_args outs args f oprs s2)
=
let open BS in
lemma_heap_ignore_ghost_machine s1.BS.ms_heap s2.BS.ms_heap;
match args with
| [] -> ()
| i::args ->
(
let (v, oprs) : option (instr_val_t i) & instr_operands_t_args args =
match i with
| IOpEx i -> let oprs = coerce oprs in (instr_eval_operand_explicit i (fst oprs) s1, snd oprs)
| IOpIm i -> (instr_eval_operand_implicit i s1, coerce oprs)
in
let f:arrow (instr_val_t i) (instr_args_t outs args) = coerce f in
match v with
| None -> ()
| Some v -> lemma_eq_instr_apply_eval_args outs args (f v) oprs s1 s2
)
#restart-solver
let rec lemma_eq_instr_apply_eval_inouts
(outs inouts:list instr_out) (args:list instr_operand)
(f:instr_inouts_t outs inouts args) (oprs:instr_operands_t inouts args) (s1 s2:machine_state)
: Lemma
(requires state_eq_S true s1 s2)
(ensures
BS.instr_apply_eval_inouts outs inouts args f oprs s1 ==
BS.instr_apply_eval_inouts outs inouts args f oprs s2)
=
let open BS in
lemma_heap_ignore_ghost_machine s1.BS.ms_heap s2.BS.ms_heap;
match inouts with
| [] -> lemma_eq_instr_apply_eval_args outs args f oprs s1 s2
| (Out, i)::inouts ->
let oprs =
match i with
| IOpEx i -> snd #(instr_operand_t i) (coerce oprs)
| IOpIm i -> coerce oprs
in
lemma_eq_instr_apply_eval_inouts outs inouts args (coerce f) oprs s1 s2
| (InOut, i)::inouts ->
(
let (v, oprs) : option (instr_val_t i) & instr_operands_t inouts args =
match i with
| IOpEx i -> let oprs = coerce oprs in (instr_eval_operand_explicit i (fst oprs) s1, snd oprs)
| IOpIm i -> (instr_eval_operand_implicit i s1, coerce oprs)
in
let f:arrow (instr_val_t i) (instr_inouts_t outs inouts args) = coerce f in
match v with
| None -> ()
| Some v -> lemma_eq_instr_apply_eval_inouts outs inouts args (f v) oprs s1 s2
)
#restart-solver
#push-options "--z3rlimit_factor 2"
let rec lemma_eq_instr_write_outputs
(outs:list instr_out) (args:list instr_operand)
(vs:instr_ret_t outs) (oprs:instr_operands_t outs args) (s1_orig s1 s2_orig s2:machine_state)
: Lemma
(requires state_eq_S true s1_orig s2_orig /\ state_eq_S true s1 s2)
(ensures
state_eq_S true
(BS.instr_write_outputs outs args vs oprs s1_orig s1)
(BS.instr_write_outputs outs args vs oprs s2_orig s2))
=
let open BS in
use_machine_state_equal ();
lemma_heap_ignore_ghost_machine s1.BS.ms_heap s2.BS.ms_heap;
lemma_heap_ignore_ghost_machine s1_orig.BS.ms_heap s2_orig.BS.ms_heap;
allow_inversion tmaddr;
match outs with
| [] -> ()
| (_, i)::outs ->
(
let ((v:instr_val_t i), (vs:instr_ret_t outs)) =
match outs with
| [] -> (vs, ())
| _::_ -> let vs = coerce vs in (fst vs, snd vs)
in
match i with
| IOpEx i ->
let oprs = coerce oprs in
let s1 = instr_write_output_explicit i v (fst oprs) s1_orig s1 in
let s2 = instr_write_output_explicit i v (fst oprs) s2_orig s2 in
lemma_eq_instr_write_outputs outs args vs (snd oprs) s1_orig s1 s2_orig s2
| IOpIm i ->
let s1 = instr_write_output_implicit i v s1_orig s1 in
let s2 = instr_write_output_implicit i v s2_orig s2 in
allow_inversion operand64;
allow_inversion operand128;
lemma_eq_instr_write_outputs outs args vs (coerce oprs) s1_orig s1 s2_orig s2
)
#pop-options
#restart-solver
let eval_ins_eq_instr (inst:BS.ins) (s1 s2:machine_state) : Lemma
(requires Instr? inst /\ state_eq_S true s1 s2)
(ensures state_eq_S true (BS.machine_eval_ins inst s1) (BS.machine_eval_ins inst s2))
=
let open BS in
let Instr it oprs ann = inst in
let InstrTypeRecord #outs #args #havoc_flags' i = it in
lemma_eq_instr_apply_eval_inouts outs outs args (instr_eval i) oprs s1 s2;
let vs = instr_apply_eval outs args (instr_eval i) oprs s1 in
let hav s =
match havoc_flags' with
| HavocFlags -> {s with ms_flags = havoc_flags}
| PreserveFlags -> s
in
let s1' = hav s1 in
let s2' = hav s2 in
match vs with
| None -> ()
| Some vs -> lemma_eq_instr_write_outputs outs args vs oprs s1 s1' s2 s2'
let eval_code_eq_instr (inst:BS.ins) (f:fuel) (s1 s2:machine_state) : Lemma
(requires Instr? inst /\ state_eq_S true s1 s2)
(ensures state_eq_opt true (BS.machine_eval_code (Ins inst) f s1) (BS.machine_eval_code (Ins inst) f s2))
=
reveal_opaque (`%BS.machine_eval_code_ins) BS.machine_eval_code_ins;
eval_ins_eq_instr inst ({s1 with BS.ms_trace = []}) ({s2 with BS.ms_trace = []})
let eval_code_eq_dealloc (inst:BS.ins) (f:fuel) (s1 s2:machine_state) : Lemma
(requires Dealloc? inst /\ state_eq_S true s1 s2)
(ensures state_eq_opt true (BS.machine_eval_code (Ins inst) f s1) (BS.machine_eval_code (Ins inst) f s2))
=
reveal_opaque (`%BS.machine_eval_code_ins) BS.machine_eval_code_ins;
use_machine_state_equal ();
lemma_heap_ignore_ghost_machine s1.BS.ms_heap s2.BS.ms_heap;
allow_inversion tmaddr
let eval_code_eq_alloc (inst:BS.ins) (f:fuel) (s1 s2:machine_state) : Lemma
(requires Alloc? inst /\ state_eq_S true s1 s2)
(ensures state_eq_opt true (BS.machine_eval_code (Ins inst) f s1) (BS.machine_eval_code (Ins inst) f s2))
=
reveal_opaque (`%BS.machine_eval_code_ins) BS.machine_eval_code_ins;
use_machine_state_equal ();
lemma_heap_ignore_ghost_machine s1.BS.ms_heap s2.BS.ms_heap;
allow_inversion tmaddr
let eval_code_eq_push (inst:BS.ins) (f:fuel) (s1 s2:machine_state) : Lemma
(requires Push? inst /\ state_eq_S true s1 s2)
(ensures state_eq_opt true (BS.machine_eval_code (Ins inst) f s1) (BS.machine_eval_code (Ins inst) f s2))
=
reveal_opaque (`%BS.machine_eval_code_ins) BS.machine_eval_code_ins;
use_machine_state_equal ();
lemma_heap_ignore_ghost_machine s1.BS.ms_heap s2.BS.ms_heap;
allow_inversion tmaddr
let eval_code_eq_pop (inst:BS.ins) (f:fuel) (s1 s2:machine_state) : Lemma
(requires Pop? inst /\ state_eq_S true s1 s2)
(ensures state_eq_opt true (BS.machine_eval_code (Ins inst) f s1) (BS.machine_eval_code (Ins inst) f s2))
=
reveal_opaque (`%BS.machine_eval_code_ins) BS.machine_eval_code_ins;
use_machine_state_equal ();
lemma_heap_ignore_ghost_machine s1.BS.ms_heap s2.BS.ms_heap;
allow_inversion tmaddr
let eval_code_eq_ins (i:BS.ins) (f:fuel) (s1 s2:machine_state) : Lemma
(requires state_eq_S true s1 s2)
(ensures state_eq_opt true (BS.machine_eval_code (Ins i) f s1) (BS.machine_eval_code (Ins i) f s2))
=
match i with
| Instr _ _ _ -> eval_code_eq_instr i f s1 s2
| Dealloc _ -> eval_code_eq_dealloc i f s1 s2
| Alloc _ -> eval_code_eq_alloc i f s1 s2
| Push _ _ -> eval_code_eq_push i f s1 s2
| Pop _ _ -> eval_code_eq_pop i f s1 s2
#reset-options "--fuel 2 --z3rlimit 30"
let eval_ocmp_eq_core (g:bool) (cond:ocmp) (s:machine_state) : Lemma
(ensures (
let (s1, b1) = BS.machine_eval_ocmp s cond in
let (s2, b2) = BS.machine_eval_ocmp (core_state g s) cond in
state_eq_S g s1 s2 /\ b1 == b2
))
=
reveal_opaque (`%BS.valid_ocmp_opaque) BS.valid_ocmp_opaque;
reveal_opaque (`%BS.eval_ocmp_opaque) BS.eval_ocmp_opaque;
()
#restart-solver
let rec eval_code_eq_core (g:bool) (c:code) (f:fuel) (s:machine_state) : Lemma
(ensures state_eq_opt g (BS.machine_eval_code c f s) (BS.machine_eval_code c f (core_state g s)))
(decreases %[f; c])
=
match c with
| Ins i ->
reveal_opaque (`%BS.machine_eval_code_ins) BS.machine_eval_code_ins;
if g then eval_code_eq_ins i f s (core_state g s)
| Block cs -> eval_codes_eq_core g cs f s
| IfElse cond ct cf ->
eval_ocmp_eq_core g cond s;
let (s', _) = BS.machine_eval_ocmp s cond in
let (t', _) = BS.machine_eval_ocmp (core_state g s) cond in
eval_code_eq_core g ct f s';
eval_code_eq_core g ct f t';
eval_code_eq_core g cf f s';
eval_code_eq_core g cf f t';
()
| While cond body -> eval_while_eq_core g cond body f s
and eval_codes_eq_core (g:bool) (cs:codes) (f:fuel) (s:machine_state) : Lemma
(ensures state_eq_opt g (BS.machine_eval_codes cs f s) (BS.machine_eval_codes cs f (core_state g s)))
(decreases %[f; cs])
=
match cs with
| [] -> ()
| c'::cs' -> (
eval_code_eq_core g c' f s;
match (machine_eval_code c' f s, machine_eval_code c' f (core_state g s)) with
| (None, None) -> ()
| (Some s', Some t') -> eval_codes_eq_core g cs' f s'; eval_codes_eq_core g cs' f t'
)
and eval_while_eq_core (g:bool) (cond:ocmp) (body:code) (f:fuel) (s:machine_state) : Lemma
(ensures state_eq_opt g (BS.machine_eval_while cond body f s) (BS.machine_eval_while cond body f (core_state g s)))
(decreases %[f; body])
=
if f > 0 then (
eval_ocmp_eq_core g cond s;
let (s1, _) = BS.machine_eval_ocmp s cond in
let (t1, _) = BS.machine_eval_ocmp (core_state g s) cond in
eval_code_eq_core g body (f - 1) s1;
eval_code_eq_core g body (f - 1) t1;
match (BS.machine_eval_code body (f - 1) s1, BS.machine_eval_code body (f - 1) t1) with
| (None, None) -> ()
| (Some s2, Some t2) ->
eval_while_eq_core g cond body (f - 1) s2;
eval_while_eq_core g cond body (f - 1) t2;
()
)
let eval_code_eq_f (c:code) (f:fuel) (s1 s2:machine_state) : Lemma
(requires state_eq_S false s1 s2)
(ensures state_eq_opt false (BS.machine_eval_code c f s1) (BS.machine_eval_code c f s2))
[SMTPat (BS.machine_eval_code c f s1); SMTPat (BS.machine_eval_code c f s2)]
=
eval_code_eq_core false c f s1; eval_code_eq_core false c f s2
let eval_codes_eq_f (cs:codes) (f:fuel) (s1 s2:machine_state) : Lemma
(requires state_eq_S false s1 s2)
(ensures state_eq_opt false (BS.machine_eval_codes cs f s1) (BS.machine_eval_codes cs f s2))
[SMTPat (BS.machine_eval_codes cs f s1); SMTPat (BS.machine_eval_codes cs f s2)]
=
eval_codes_eq_core false cs f s1; eval_codes_eq_core false cs f s2
let eval_while_eq_f (cond:ocmp) (body:code) (f:fuel) (s1 s2:machine_state) : Lemma
(requires state_eq_S false s1 s2)
(ensures state_eq_opt false (BS.machine_eval_while cond body f s1) (BS.machine_eval_while cond body f s2))
[SMTPat (BS.machine_eval_while cond body f s1); SMTPat (BS.machine_eval_while cond body f s2)]
=
eval_while_eq_core false cond body f s1; eval_while_eq_core false cond body f s2
let eval_code_eq_t (c:code) (f:fuel) (s1 s2:machine_state) : Lemma
(requires state_eq_S true s1 s2)
(ensures state_eq_opt true (BS.machine_eval_code c f s1) (BS.machine_eval_code c f s2))
[SMTPat (BS.machine_eval_code c f s1); SMTPat (BS.machine_eval_code c f s2)]
=
eval_code_eq_core true c f s1; eval_code_eq_core true c f s2
let eval_codes_eq_t (cs:codes) (f:fuel) (s1 s2:machine_state) : Lemma
(requires state_eq_S true s1 s2)
(ensures state_eq_opt true (BS.machine_eval_codes cs f s1) (BS.machine_eval_codes cs f s2))
[SMTPat (BS.machine_eval_codes cs f s1); SMTPat (BS.machine_eval_codes cs f s2)]
=
eval_codes_eq_core true cs f s1; eval_codes_eq_core true cs f s2
let eval_while_eq_t (cond:ocmp) (body:code) (f:fuel) (s1 s2:machine_state) : Lemma
(requires state_eq_S true s1 s2)
(ensures state_eq_opt true (BS.machine_eval_while cond body f s1) (BS.machine_eval_while cond body f s2))
[SMTPat (BS.machine_eval_while cond body f s1); SMTPat (BS.machine_eval_while cond body f s2)]
=
eval_while_eq_core true cond body f s1; eval_while_eq_core true cond body f s2
let eval_code_ts (g:bool) (c:code) (s0:machine_state) (f0:fuel) (s1:machine_state) : Type0 =
state_eq_opt g (BS.machine_eval_code c f0 s0) (Some s1)
let rec increase_fuel (g:bool) (c:code) (s0:machine_state) (f0:fuel) (sN:machine_state) (fN:fuel) : Lemma
(requires eval_code_ts g c s0 f0 sN /\ f0 <= fN)
(ensures eval_code_ts g c s0 fN sN)
(decreases %[f0; c])
=
match c with
| Ins ins -> ()
| Block l -> increase_fuels g l s0 f0 sN fN
| IfElse cond t f ->
let (s0, b0) = BS.machine_eval_ocmp s0 cond in
if b0 then increase_fuel g t s0 f0 sN fN else increase_fuel g f s0 f0 sN fN
| While cond c ->
let (s1, b0) = BS.machine_eval_ocmp s0 cond in
if b0 then (
match BS.machine_eval_code c (f0 - 1) s1 with
| None -> ()
| Some s2 ->
increase_fuel g c s1 (f0 - 1) s2 (fN - 1);
if s2.BS.ms_ok then increase_fuel g (While cond c) s2 (f0 - 1) sN (fN - 1)
else ()
)
and increase_fuels (g:bool) (c:codes) (s0:machine_state) (f0:fuel) (sN:machine_state) (fN:fuel) : Lemma
(requires eval_code_ts g (Block c) s0 f0 sN /\ f0 <= fN)
(ensures eval_code_ts g (Block c) s0 fN sN)
(decreases %[f0; c])
=
match c with
| [] -> ()
| h::t ->
(
let Some s1 = BS.machine_eval_code h f0 s0 in
increase_fuel g h s0 f0 s1 fN;
increase_fuels g t s1 f0 sN fN
)
let lemma_cmp_eq s o1 o2 = reveal_opaque (`%BS.eval_ocmp_opaque) BS.eval_ocmp_opaque
let lemma_cmp_ne s o1 o2 = reveal_opaque (`%BS.eval_ocmp_opaque) BS.eval_ocmp_opaque
let lemma_cmp_le s o1 o2 = reveal_opaque (`%BS.eval_ocmp_opaque) BS.eval_ocmp_opaque
let lemma_cmp_ge s o1 o2 = reveal_opaque (`%BS.eval_ocmp_opaque) BS.eval_ocmp_opaque
let lemma_cmp_lt s o1 o2 = reveal_opaque (`%BS.eval_ocmp_opaque) BS.eval_ocmp_opaque
let lemma_cmp_gt s o1 o2 = reveal_opaque (`%BS.eval_ocmp_opaque) BS.eval_ocmp_opaque
let lemma_valid_cmp_eq s o1 o2 = ()
let lemma_valid_cmp_ne s o1 o2 = ()
let lemma_valid_cmp_le s o1 o2 = ()
let lemma_valid_cmp_ge s o1 o2 = ()
let lemma_valid_cmp_lt s o1 o2 = ()
let lemma_valid_cmp_gt s o1 o2 = ()
let compute_merge_total (f0:fuel) (fM:fuel) =
if f0 > fM then f0 else fM
let lemma_merge_total (b0:codes) (s0:vale_state) (f0:fuel) (sM:vale_state) (fM:fuel) (sN:vale_state) =
let f = if f0 > fM then f0 else fM in
increase_fuel (codes_modifies_ghost b0) (Cons?.hd b0) (state_to_S s0) f0 (state_to_S sM) f;
increase_fuel (codes_modifies_ghost b0) (Block (Cons?.tl b0)) (state_to_S sM) fM (state_to_S sN) f
let lemma_empty_total (s0:vale_state) (bN:codes) =
(s0, 0)
let lemma_ifElse_total (ifb:ocmp) (ct:code) (cf:code) (s0:vale_state) =
(eval_ocmp s0 ifb, {s0 with vs_flags = havoc_flags}, s0, 0)
let lemma_havoc_flags : squash (Flags.to_fun havoc_flags == BS.havoc_flags) =
assert (FStar.FunctionalExtensionality.feq (Flags.to_fun havoc_flags) BS.havoc_flags)
let lemma_ifElseTrue_total (ifb:ocmp) (ct:code) (cf:code) (s0:vale_state) (f0:fuel) (sM:vale_state) =
reveal_opaque (`%BS.valid_ocmp_opaque) BS.valid_ocmp_opaque;
reveal_opaque (`%BS.eval_ocmp_opaque) BS.eval_ocmp_opaque
let lemma_ifElseFalse_total (ifb:ocmp) (ct:code) (cf:code) (s0:vale_state) (f0:fuel) (sM:vale_state) =
reveal_opaque (`%BS.valid_ocmp_opaque) BS.valid_ocmp_opaque;
reveal_opaque (`%BS.eval_ocmp_opaque) BS.eval_ocmp_opaque
let eval_while_inv_temp (c:code) (s0:vale_state) (fW:fuel) (sW:vale_state) : Type0 =
forall (f:nat).{:pattern BS.machine_eval_code c f (state_to_S sW)}
Some? (BS.machine_eval_code c f (state_to_S sW)) ==>
state_eq_opt (code_modifies_ghost c)
(BS.machine_eval_code c (f + fW) (state_to_S s0))
(BS.machine_eval_code c f (state_to_S sW))
let eval_while_inv (c:code) (s0:vale_state) (fW:fuel) (sW:vale_state) : Type0 =
eval_while_inv_temp c s0 fW sW
let lemma_while_total (b:ocmp) (c:code) (s0:vale_state) =
(s0, 0) | false | false | Vale.X64.Lemmas.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": 30,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val lemma_whileTrue_total (b:ocmp) (c:code) (s0:vale_state) (sW:vale_state) (fW:fuel) : Ghost (vale_state & fuel)
(requires eval_ocmp sW b)
(ensures fun (s1, f1) -> s1 == {sW with vs_flags = havoc_flags} /\ f1 == fW) | [] | Vale.X64.Lemmas.lemma_whileTrue_total | {
"file_name": "vale/code/arch/x64/Vale.X64.Lemmas.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} |
b: Vale.X64.Bytes_Code_s.ocmp ->
c: Vale.X64.StateLemmas.code ->
s0: Vale.X64.State.vale_state ->
sW: Vale.X64.State.vale_state ->
fW: Vale.X64.Lemmas.fuel
-> Prims.Ghost (Vale.X64.State.vale_state * Vale.X64.Lemmas.fuel) | {
"end_col": 40,
"end_line": 386,
"start_col": 2,
"start_line": 386
} |
FStar.Pervasives.Lemma | val eval_code_eq_alloc (inst: BS.ins) (f: fuel) (s1 s2: machine_state)
: Lemma (requires Alloc? inst /\ state_eq_S true s1 s2)
(ensures
state_eq_opt true
(BS.machine_eval_code (Ins inst) f s1)
(BS.machine_eval_code (Ins inst) f s2)) | [
{
"abbrev": true,
"full_module": "Vale.X64.Memory",
"short_module": "ME"
},
{
"abbrev": true,
"full_module": "Vale.X64.Machine_Semantics_s",
"short_module": "BS"
},
{
"abbrev": false,
"full_module": "Vale.X64.Bytes_Code_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Instruction_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.StateLemmas",
"short_module": null
},
{
"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": "FStar.Mul",
"short_module": null
},
{
"abbrev": true,
"full_module": "Vale.Lib.Map16",
"short_module": "Map16"
},
{
"abbrev": true,
"full_module": "Vale.X64.Machine_Semantics_s",
"short_module": "BS"
},
{
"abbrev": false,
"full_module": "Vale.X64.Bytes_Code_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.StateLemmas",
"short_module": null
},
{
"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.HeapLemmas",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.HeapImpl",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Heap",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"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 eval_code_eq_alloc (inst:BS.ins) (f:fuel) (s1 s2:machine_state) : Lemma
(requires Alloc? inst /\ state_eq_S true s1 s2)
(ensures state_eq_opt true (BS.machine_eval_code (Ins inst) f s1) (BS.machine_eval_code (Ins inst) f s2))
=
reveal_opaque (`%BS.machine_eval_code_ins) BS.machine_eval_code_ins;
use_machine_state_equal ();
lemma_heap_ignore_ghost_machine s1.BS.ms_heap s2.BS.ms_heap;
allow_inversion tmaddr | val eval_code_eq_alloc (inst: BS.ins) (f: fuel) (s1 s2: machine_state)
: Lemma (requires Alloc? inst /\ state_eq_S true s1 s2)
(ensures
state_eq_opt true
(BS.machine_eval_code (Ins inst) f s1)
(BS.machine_eval_code (Ins inst) f s2))
let eval_code_eq_alloc (inst: BS.ins) (f: fuel) (s1 s2: machine_state)
: Lemma (requires Alloc? inst /\ state_eq_S true s1 s2)
(ensures
state_eq_opt true
(BS.machine_eval_code (Ins inst) f s1)
(BS.machine_eval_code (Ins inst) f s2)) = | false | null | true | reveal_opaque (`%BS.machine_eval_code_ins) BS.machine_eval_code_ins;
use_machine_state_equal ();
lemma_heap_ignore_ghost_machine s1.BS.ms_heap s2.BS.ms_heap;
allow_inversion tmaddr | {
"checked_file": "Vale.X64.Lemmas.fst.checked",
"dependencies": [
"Vale.X64.StateLemmas.fsti.checked",
"Vale.X64.State.fsti.checked",
"Vale.X64.Memory.fsti.checked",
"Vale.X64.Machine_Semantics_s.fst.checked",
"Vale.X64.Machine_s.fst.checked",
"Vale.X64.Instruction_s.fsti.checked",
"Vale.X64.Flags.fsti.checked",
"Vale.X64.Bytes_Code_s.fst.checked",
"prims.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.FunctionalExtensionality.fsti.checked"
],
"interface_file": true,
"source_file": "Vale.X64.Lemmas.fst"
} | [
"lemma"
] | [
"Vale.X64.Machine_Semantics_s.ins",
"Vale.X64.Lemmas.fuel",
"Vale.X64.StateLemmas.machine_state",
"FStar.Pervasives.allow_inversion",
"Vale.X64.Machine_s.tmaddr",
"Prims.unit",
"Vale.Arch.HeapLemmas.lemma_heap_ignore_ghost_machine",
"Vale.X64.Machine_Semantics_s.__proj__Mkmachine_state__item__ms_heap",
"Vale.X64.StateLemmas.use_machine_state_equal",
"FStar.Pervasives.reveal_opaque",
"Vale.X64.Machine_Semantics_s.machine_state",
"FStar.Pervasives.Native.option",
"Vale.X64.Machine_Semantics_s.machine_eval_code_ins",
"Prims.l_and",
"Prims.b2t",
"Vale.X64.Bytes_Code_s.uu___is_Alloc",
"Vale.X64.Machine_Semantics_s.instr_annotation",
"Vale.X64.Lemmas.state_eq_S",
"Prims.squash",
"Vale.X64.Lemmas.state_eq_opt",
"Vale.X64.Machine_Semantics_s.machine_eval_code",
"Vale.X64.Machine_s.Ins",
"Vale.X64.Bytes_Code_s.instruction_t",
"Vale.X64.Bytes_Code_s.ocmp",
"Prims.Nil",
"FStar.Pervasives.pattern"
] | [] | module Vale.X64.Lemmas
open FStar.Mul
open Vale.X64.Machine_s
open Vale.X64.State
open Vale.X64.StateLemmas
open Vale.X64.Instruction_s
open Vale.X64.Bytes_Code_s
module BS = Vale.X64.Machine_Semantics_s
module ME = Vale.X64.Memory
#reset-options "--initial_fuel 1 --max_fuel 1 --z3rlimit 100"
#restart-solver
let rec lemma_eq_instr_apply_eval_args
(outs:list instr_out) (args:list instr_operand)
(f:instr_args_t outs args) (oprs:instr_operands_t_args args) (s1 s2:machine_state)
: Lemma
(requires state_eq_S true s1 s2)
(ensures
BS.instr_apply_eval_args outs args f oprs s1 ==
BS.instr_apply_eval_args outs args f oprs s2)
=
let open BS in
lemma_heap_ignore_ghost_machine s1.BS.ms_heap s2.BS.ms_heap;
match args with
| [] -> ()
| i::args ->
(
let (v, oprs) : option (instr_val_t i) & instr_operands_t_args args =
match i with
| IOpEx i -> let oprs = coerce oprs in (instr_eval_operand_explicit i (fst oprs) s1, snd oprs)
| IOpIm i -> (instr_eval_operand_implicit i s1, coerce oprs)
in
let f:arrow (instr_val_t i) (instr_args_t outs args) = coerce f in
match v with
| None -> ()
| Some v -> lemma_eq_instr_apply_eval_args outs args (f v) oprs s1 s2
)
#restart-solver
let rec lemma_eq_instr_apply_eval_inouts
(outs inouts:list instr_out) (args:list instr_operand)
(f:instr_inouts_t outs inouts args) (oprs:instr_operands_t inouts args) (s1 s2:machine_state)
: Lemma
(requires state_eq_S true s1 s2)
(ensures
BS.instr_apply_eval_inouts outs inouts args f oprs s1 ==
BS.instr_apply_eval_inouts outs inouts args f oprs s2)
=
let open BS in
lemma_heap_ignore_ghost_machine s1.BS.ms_heap s2.BS.ms_heap;
match inouts with
| [] -> lemma_eq_instr_apply_eval_args outs args f oprs s1 s2
| (Out, i)::inouts ->
let oprs =
match i with
| IOpEx i -> snd #(instr_operand_t i) (coerce oprs)
| IOpIm i -> coerce oprs
in
lemma_eq_instr_apply_eval_inouts outs inouts args (coerce f) oprs s1 s2
| (InOut, i)::inouts ->
(
let (v, oprs) : option (instr_val_t i) & instr_operands_t inouts args =
match i with
| IOpEx i -> let oprs = coerce oprs in (instr_eval_operand_explicit i (fst oprs) s1, snd oprs)
| IOpIm i -> (instr_eval_operand_implicit i s1, coerce oprs)
in
let f:arrow (instr_val_t i) (instr_inouts_t outs inouts args) = coerce f in
match v with
| None -> ()
| Some v -> lemma_eq_instr_apply_eval_inouts outs inouts args (f v) oprs s1 s2
)
#restart-solver
#push-options "--z3rlimit_factor 2"
let rec lemma_eq_instr_write_outputs
(outs:list instr_out) (args:list instr_operand)
(vs:instr_ret_t outs) (oprs:instr_operands_t outs args) (s1_orig s1 s2_orig s2:machine_state)
: Lemma
(requires state_eq_S true s1_orig s2_orig /\ state_eq_S true s1 s2)
(ensures
state_eq_S true
(BS.instr_write_outputs outs args vs oprs s1_orig s1)
(BS.instr_write_outputs outs args vs oprs s2_orig s2))
=
let open BS in
use_machine_state_equal ();
lemma_heap_ignore_ghost_machine s1.BS.ms_heap s2.BS.ms_heap;
lemma_heap_ignore_ghost_machine s1_orig.BS.ms_heap s2_orig.BS.ms_heap;
allow_inversion tmaddr;
match outs with
| [] -> ()
| (_, i)::outs ->
(
let ((v:instr_val_t i), (vs:instr_ret_t outs)) =
match outs with
| [] -> (vs, ())
| _::_ -> let vs = coerce vs in (fst vs, snd vs)
in
match i with
| IOpEx i ->
let oprs = coerce oprs in
let s1 = instr_write_output_explicit i v (fst oprs) s1_orig s1 in
let s2 = instr_write_output_explicit i v (fst oprs) s2_orig s2 in
lemma_eq_instr_write_outputs outs args vs (snd oprs) s1_orig s1 s2_orig s2
| IOpIm i ->
let s1 = instr_write_output_implicit i v s1_orig s1 in
let s2 = instr_write_output_implicit i v s2_orig s2 in
allow_inversion operand64;
allow_inversion operand128;
lemma_eq_instr_write_outputs outs args vs (coerce oprs) s1_orig s1 s2_orig s2
)
#pop-options
#restart-solver
let eval_ins_eq_instr (inst:BS.ins) (s1 s2:machine_state) : Lemma
(requires Instr? inst /\ state_eq_S true s1 s2)
(ensures state_eq_S true (BS.machine_eval_ins inst s1) (BS.machine_eval_ins inst s2))
=
let open BS in
let Instr it oprs ann = inst in
let InstrTypeRecord #outs #args #havoc_flags' i = it in
lemma_eq_instr_apply_eval_inouts outs outs args (instr_eval i) oprs s1 s2;
let vs = instr_apply_eval outs args (instr_eval i) oprs s1 in
let hav s =
match havoc_flags' with
| HavocFlags -> {s with ms_flags = havoc_flags}
| PreserveFlags -> s
in
let s1' = hav s1 in
let s2' = hav s2 in
match vs with
| None -> ()
| Some vs -> lemma_eq_instr_write_outputs outs args vs oprs s1 s1' s2 s2'
let eval_code_eq_instr (inst:BS.ins) (f:fuel) (s1 s2:machine_state) : Lemma
(requires Instr? inst /\ state_eq_S true s1 s2)
(ensures state_eq_opt true (BS.machine_eval_code (Ins inst) f s1) (BS.machine_eval_code (Ins inst) f s2))
=
reveal_opaque (`%BS.machine_eval_code_ins) BS.machine_eval_code_ins;
eval_ins_eq_instr inst ({s1 with BS.ms_trace = []}) ({s2 with BS.ms_trace = []})
let eval_code_eq_dealloc (inst:BS.ins) (f:fuel) (s1 s2:machine_state) : Lemma
(requires Dealloc? inst /\ state_eq_S true s1 s2)
(ensures state_eq_opt true (BS.machine_eval_code (Ins inst) f s1) (BS.machine_eval_code (Ins inst) f s2))
=
reveal_opaque (`%BS.machine_eval_code_ins) BS.machine_eval_code_ins;
use_machine_state_equal ();
lemma_heap_ignore_ghost_machine s1.BS.ms_heap s2.BS.ms_heap;
allow_inversion tmaddr
let eval_code_eq_alloc (inst:BS.ins) (f:fuel) (s1 s2:machine_state) : Lemma
(requires Alloc? inst /\ state_eq_S true s1 s2)
(ensures state_eq_opt true (BS.machine_eval_code (Ins inst) f s1) (BS.machine_eval_code (Ins inst) f s2)) | false | false | Vale.X64.Lemmas.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 1,
"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": 100,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val eval_code_eq_alloc (inst: BS.ins) (f: fuel) (s1 s2: machine_state)
: Lemma (requires Alloc? inst /\ state_eq_S true s1 s2)
(ensures
state_eq_opt true
(BS.machine_eval_code (Ins inst) f s1)
(BS.machine_eval_code (Ins inst) f s2)) | [] | Vale.X64.Lemmas.eval_code_eq_alloc | {
"file_name": "vale/code/arch/x64/Vale.X64.Lemmas.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} |
inst: Vale.X64.Machine_Semantics_s.ins ->
f: Vale.X64.Lemmas.fuel ->
s1: Vale.X64.StateLemmas.machine_state ->
s2: Vale.X64.StateLemmas.machine_state
-> FStar.Pervasives.Lemma (requires Alloc? inst /\ Vale.X64.Lemmas.state_eq_S true s1 s2)
(ensures
Vale.X64.Lemmas.state_eq_opt true
(Vale.X64.Machine_Semantics_s.machine_eval_code (Vale.X64.Machine_s.Ins inst) f s1)
(Vale.X64.Machine_Semantics_s.machine_eval_code (Vale.X64.Machine_s.Ins inst) f s2)) | {
"end_col": 24,
"end_line": 159,
"start_col": 2,
"start_line": 156
} |
Prims.Tot | val eval_while_inv_temp (c: code) (s0: vale_state) (fW: fuel) (sW: vale_state) : Type0 | [
{
"abbrev": true,
"full_module": "Vale.X64.Memory",
"short_module": "ME"
},
{
"abbrev": true,
"full_module": "Vale.X64.Machine_Semantics_s",
"short_module": "BS"
},
{
"abbrev": false,
"full_module": "Vale.X64.Bytes_Code_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Instruction_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.StateLemmas",
"short_module": null
},
{
"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": "FStar.Mul",
"short_module": null
},
{
"abbrev": true,
"full_module": "Vale.Lib.Map16",
"short_module": "Map16"
},
{
"abbrev": true,
"full_module": "Vale.X64.Machine_Semantics_s",
"short_module": "BS"
},
{
"abbrev": false,
"full_module": "Vale.X64.Bytes_Code_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.StateLemmas",
"short_module": null
},
{
"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.HeapLemmas",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.HeapImpl",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Heap",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"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 eval_while_inv_temp (c:code) (s0:vale_state) (fW:fuel) (sW:vale_state) : Type0 =
forall (f:nat).{:pattern BS.machine_eval_code c f (state_to_S sW)}
Some? (BS.machine_eval_code c f (state_to_S sW)) ==>
state_eq_opt (code_modifies_ghost c)
(BS.machine_eval_code c (f + fW) (state_to_S s0))
(BS.machine_eval_code c f (state_to_S sW)) | val eval_while_inv_temp (c: code) (s0: vale_state) (fW: fuel) (sW: vale_state) : Type0
let eval_while_inv_temp (c: code) (s0: vale_state) (fW: fuel) (sW: vale_state) : Type0 = | false | null | false | forall (f: nat). {:pattern BS.machine_eval_code c f (state_to_S sW)}
Some? (BS.machine_eval_code c f (state_to_S sW)) ==>
state_eq_opt (code_modifies_ghost c)
(BS.machine_eval_code c (f + fW) (state_to_S s0))
(BS.machine_eval_code c f (state_to_S sW)) | {
"checked_file": "Vale.X64.Lemmas.fst.checked",
"dependencies": [
"Vale.X64.StateLemmas.fsti.checked",
"Vale.X64.State.fsti.checked",
"Vale.X64.Memory.fsti.checked",
"Vale.X64.Machine_Semantics_s.fst.checked",
"Vale.X64.Machine_s.fst.checked",
"Vale.X64.Instruction_s.fsti.checked",
"Vale.X64.Flags.fsti.checked",
"Vale.X64.Bytes_Code_s.fst.checked",
"prims.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.FunctionalExtensionality.fsti.checked"
],
"interface_file": true,
"source_file": "Vale.X64.Lemmas.fst"
} | [
"total"
] | [
"Vale.X64.StateLemmas.code",
"Vale.X64.State.vale_state",
"Vale.X64.Lemmas.fuel",
"Prims.l_Forall",
"Prims.nat",
"Prims.l_imp",
"Prims.b2t",
"FStar.Pervasives.Native.uu___is_Some",
"Vale.X64.Machine_Semantics_s.machine_state",
"Vale.X64.Machine_Semantics_s.machine_eval_code",
"Vale.X64.StateLemmas.state_to_S",
"Vale.X64.Lemmas.state_eq_opt",
"Vale.X64.Lemmas.code_modifies_ghost",
"Prims.op_Addition"
] | [] | module Vale.X64.Lemmas
open FStar.Mul
open Vale.X64.Machine_s
open Vale.X64.State
open Vale.X64.StateLemmas
open Vale.X64.Instruction_s
open Vale.X64.Bytes_Code_s
module BS = Vale.X64.Machine_Semantics_s
module ME = Vale.X64.Memory
#reset-options "--initial_fuel 1 --max_fuel 1 --z3rlimit 100"
#restart-solver
let rec lemma_eq_instr_apply_eval_args
(outs:list instr_out) (args:list instr_operand)
(f:instr_args_t outs args) (oprs:instr_operands_t_args args) (s1 s2:machine_state)
: Lemma
(requires state_eq_S true s1 s2)
(ensures
BS.instr_apply_eval_args outs args f oprs s1 ==
BS.instr_apply_eval_args outs args f oprs s2)
=
let open BS in
lemma_heap_ignore_ghost_machine s1.BS.ms_heap s2.BS.ms_heap;
match args with
| [] -> ()
| i::args ->
(
let (v, oprs) : option (instr_val_t i) & instr_operands_t_args args =
match i with
| IOpEx i -> let oprs = coerce oprs in (instr_eval_operand_explicit i (fst oprs) s1, snd oprs)
| IOpIm i -> (instr_eval_operand_implicit i s1, coerce oprs)
in
let f:arrow (instr_val_t i) (instr_args_t outs args) = coerce f in
match v with
| None -> ()
| Some v -> lemma_eq_instr_apply_eval_args outs args (f v) oprs s1 s2
)
#restart-solver
let rec lemma_eq_instr_apply_eval_inouts
(outs inouts:list instr_out) (args:list instr_operand)
(f:instr_inouts_t outs inouts args) (oprs:instr_operands_t inouts args) (s1 s2:machine_state)
: Lemma
(requires state_eq_S true s1 s2)
(ensures
BS.instr_apply_eval_inouts outs inouts args f oprs s1 ==
BS.instr_apply_eval_inouts outs inouts args f oprs s2)
=
let open BS in
lemma_heap_ignore_ghost_machine s1.BS.ms_heap s2.BS.ms_heap;
match inouts with
| [] -> lemma_eq_instr_apply_eval_args outs args f oprs s1 s2
| (Out, i)::inouts ->
let oprs =
match i with
| IOpEx i -> snd #(instr_operand_t i) (coerce oprs)
| IOpIm i -> coerce oprs
in
lemma_eq_instr_apply_eval_inouts outs inouts args (coerce f) oprs s1 s2
| (InOut, i)::inouts ->
(
let (v, oprs) : option (instr_val_t i) & instr_operands_t inouts args =
match i with
| IOpEx i -> let oprs = coerce oprs in (instr_eval_operand_explicit i (fst oprs) s1, snd oprs)
| IOpIm i -> (instr_eval_operand_implicit i s1, coerce oprs)
in
let f:arrow (instr_val_t i) (instr_inouts_t outs inouts args) = coerce f in
match v with
| None -> ()
| Some v -> lemma_eq_instr_apply_eval_inouts outs inouts args (f v) oprs s1 s2
)
#restart-solver
#push-options "--z3rlimit_factor 2"
let rec lemma_eq_instr_write_outputs
(outs:list instr_out) (args:list instr_operand)
(vs:instr_ret_t outs) (oprs:instr_operands_t outs args) (s1_orig s1 s2_orig s2:machine_state)
: Lemma
(requires state_eq_S true s1_orig s2_orig /\ state_eq_S true s1 s2)
(ensures
state_eq_S true
(BS.instr_write_outputs outs args vs oprs s1_orig s1)
(BS.instr_write_outputs outs args vs oprs s2_orig s2))
=
let open BS in
use_machine_state_equal ();
lemma_heap_ignore_ghost_machine s1.BS.ms_heap s2.BS.ms_heap;
lemma_heap_ignore_ghost_machine s1_orig.BS.ms_heap s2_orig.BS.ms_heap;
allow_inversion tmaddr;
match outs with
| [] -> ()
| (_, i)::outs ->
(
let ((v:instr_val_t i), (vs:instr_ret_t outs)) =
match outs with
| [] -> (vs, ())
| _::_ -> let vs = coerce vs in (fst vs, snd vs)
in
match i with
| IOpEx i ->
let oprs = coerce oprs in
let s1 = instr_write_output_explicit i v (fst oprs) s1_orig s1 in
let s2 = instr_write_output_explicit i v (fst oprs) s2_orig s2 in
lemma_eq_instr_write_outputs outs args vs (snd oprs) s1_orig s1 s2_orig s2
| IOpIm i ->
let s1 = instr_write_output_implicit i v s1_orig s1 in
let s2 = instr_write_output_implicit i v s2_orig s2 in
allow_inversion operand64;
allow_inversion operand128;
lemma_eq_instr_write_outputs outs args vs (coerce oprs) s1_orig s1 s2_orig s2
)
#pop-options
#restart-solver
let eval_ins_eq_instr (inst:BS.ins) (s1 s2:machine_state) : Lemma
(requires Instr? inst /\ state_eq_S true s1 s2)
(ensures state_eq_S true (BS.machine_eval_ins inst s1) (BS.machine_eval_ins inst s2))
=
let open BS in
let Instr it oprs ann = inst in
let InstrTypeRecord #outs #args #havoc_flags' i = it in
lemma_eq_instr_apply_eval_inouts outs outs args (instr_eval i) oprs s1 s2;
let vs = instr_apply_eval outs args (instr_eval i) oprs s1 in
let hav s =
match havoc_flags' with
| HavocFlags -> {s with ms_flags = havoc_flags}
| PreserveFlags -> s
in
let s1' = hav s1 in
let s2' = hav s2 in
match vs with
| None -> ()
| Some vs -> lemma_eq_instr_write_outputs outs args vs oprs s1 s1' s2 s2'
let eval_code_eq_instr (inst:BS.ins) (f:fuel) (s1 s2:machine_state) : Lemma
(requires Instr? inst /\ state_eq_S true s1 s2)
(ensures state_eq_opt true (BS.machine_eval_code (Ins inst) f s1) (BS.machine_eval_code (Ins inst) f s2))
=
reveal_opaque (`%BS.machine_eval_code_ins) BS.machine_eval_code_ins;
eval_ins_eq_instr inst ({s1 with BS.ms_trace = []}) ({s2 with BS.ms_trace = []})
let eval_code_eq_dealloc (inst:BS.ins) (f:fuel) (s1 s2:machine_state) : Lemma
(requires Dealloc? inst /\ state_eq_S true s1 s2)
(ensures state_eq_opt true (BS.machine_eval_code (Ins inst) f s1) (BS.machine_eval_code (Ins inst) f s2))
=
reveal_opaque (`%BS.machine_eval_code_ins) BS.machine_eval_code_ins;
use_machine_state_equal ();
lemma_heap_ignore_ghost_machine s1.BS.ms_heap s2.BS.ms_heap;
allow_inversion tmaddr
let eval_code_eq_alloc (inst:BS.ins) (f:fuel) (s1 s2:machine_state) : Lemma
(requires Alloc? inst /\ state_eq_S true s1 s2)
(ensures state_eq_opt true (BS.machine_eval_code (Ins inst) f s1) (BS.machine_eval_code (Ins inst) f s2))
=
reveal_opaque (`%BS.machine_eval_code_ins) BS.machine_eval_code_ins;
use_machine_state_equal ();
lemma_heap_ignore_ghost_machine s1.BS.ms_heap s2.BS.ms_heap;
allow_inversion tmaddr
let eval_code_eq_push (inst:BS.ins) (f:fuel) (s1 s2:machine_state) : Lemma
(requires Push? inst /\ state_eq_S true s1 s2)
(ensures state_eq_opt true (BS.machine_eval_code (Ins inst) f s1) (BS.machine_eval_code (Ins inst) f s2))
=
reveal_opaque (`%BS.machine_eval_code_ins) BS.machine_eval_code_ins;
use_machine_state_equal ();
lemma_heap_ignore_ghost_machine s1.BS.ms_heap s2.BS.ms_heap;
allow_inversion tmaddr
let eval_code_eq_pop (inst:BS.ins) (f:fuel) (s1 s2:machine_state) : Lemma
(requires Pop? inst /\ state_eq_S true s1 s2)
(ensures state_eq_opt true (BS.machine_eval_code (Ins inst) f s1) (BS.machine_eval_code (Ins inst) f s2))
=
reveal_opaque (`%BS.machine_eval_code_ins) BS.machine_eval_code_ins;
use_machine_state_equal ();
lemma_heap_ignore_ghost_machine s1.BS.ms_heap s2.BS.ms_heap;
allow_inversion tmaddr
let eval_code_eq_ins (i:BS.ins) (f:fuel) (s1 s2:machine_state) : Lemma
(requires state_eq_S true s1 s2)
(ensures state_eq_opt true (BS.machine_eval_code (Ins i) f s1) (BS.machine_eval_code (Ins i) f s2))
=
match i with
| Instr _ _ _ -> eval_code_eq_instr i f s1 s2
| Dealloc _ -> eval_code_eq_dealloc i f s1 s2
| Alloc _ -> eval_code_eq_alloc i f s1 s2
| Push _ _ -> eval_code_eq_push i f s1 s2
| Pop _ _ -> eval_code_eq_pop i f s1 s2
#reset-options "--fuel 2 --z3rlimit 30"
let eval_ocmp_eq_core (g:bool) (cond:ocmp) (s:machine_state) : Lemma
(ensures (
let (s1, b1) = BS.machine_eval_ocmp s cond in
let (s2, b2) = BS.machine_eval_ocmp (core_state g s) cond in
state_eq_S g s1 s2 /\ b1 == b2
))
=
reveal_opaque (`%BS.valid_ocmp_opaque) BS.valid_ocmp_opaque;
reveal_opaque (`%BS.eval_ocmp_opaque) BS.eval_ocmp_opaque;
()
#restart-solver
let rec eval_code_eq_core (g:bool) (c:code) (f:fuel) (s:machine_state) : Lemma
(ensures state_eq_opt g (BS.machine_eval_code c f s) (BS.machine_eval_code c f (core_state g s)))
(decreases %[f; c])
=
match c with
| Ins i ->
reveal_opaque (`%BS.machine_eval_code_ins) BS.machine_eval_code_ins;
if g then eval_code_eq_ins i f s (core_state g s)
| Block cs -> eval_codes_eq_core g cs f s
| IfElse cond ct cf ->
eval_ocmp_eq_core g cond s;
let (s', _) = BS.machine_eval_ocmp s cond in
let (t', _) = BS.machine_eval_ocmp (core_state g s) cond in
eval_code_eq_core g ct f s';
eval_code_eq_core g ct f t';
eval_code_eq_core g cf f s';
eval_code_eq_core g cf f t';
()
| While cond body -> eval_while_eq_core g cond body f s
and eval_codes_eq_core (g:bool) (cs:codes) (f:fuel) (s:machine_state) : Lemma
(ensures state_eq_opt g (BS.machine_eval_codes cs f s) (BS.machine_eval_codes cs f (core_state g s)))
(decreases %[f; cs])
=
match cs with
| [] -> ()
| c'::cs' -> (
eval_code_eq_core g c' f s;
match (machine_eval_code c' f s, machine_eval_code c' f (core_state g s)) with
| (None, None) -> ()
| (Some s', Some t') -> eval_codes_eq_core g cs' f s'; eval_codes_eq_core g cs' f t'
)
and eval_while_eq_core (g:bool) (cond:ocmp) (body:code) (f:fuel) (s:machine_state) : Lemma
(ensures state_eq_opt g (BS.machine_eval_while cond body f s) (BS.machine_eval_while cond body f (core_state g s)))
(decreases %[f; body])
=
if f > 0 then (
eval_ocmp_eq_core g cond s;
let (s1, _) = BS.machine_eval_ocmp s cond in
let (t1, _) = BS.machine_eval_ocmp (core_state g s) cond in
eval_code_eq_core g body (f - 1) s1;
eval_code_eq_core g body (f - 1) t1;
match (BS.machine_eval_code body (f - 1) s1, BS.machine_eval_code body (f - 1) t1) with
| (None, None) -> ()
| (Some s2, Some t2) ->
eval_while_eq_core g cond body (f - 1) s2;
eval_while_eq_core g cond body (f - 1) t2;
()
)
let eval_code_eq_f (c:code) (f:fuel) (s1 s2:machine_state) : Lemma
(requires state_eq_S false s1 s2)
(ensures state_eq_opt false (BS.machine_eval_code c f s1) (BS.machine_eval_code c f s2))
[SMTPat (BS.machine_eval_code c f s1); SMTPat (BS.machine_eval_code c f s2)]
=
eval_code_eq_core false c f s1; eval_code_eq_core false c f s2
let eval_codes_eq_f (cs:codes) (f:fuel) (s1 s2:machine_state) : Lemma
(requires state_eq_S false s1 s2)
(ensures state_eq_opt false (BS.machine_eval_codes cs f s1) (BS.machine_eval_codes cs f s2))
[SMTPat (BS.machine_eval_codes cs f s1); SMTPat (BS.machine_eval_codes cs f s2)]
=
eval_codes_eq_core false cs f s1; eval_codes_eq_core false cs f s2
let eval_while_eq_f (cond:ocmp) (body:code) (f:fuel) (s1 s2:machine_state) : Lemma
(requires state_eq_S false s1 s2)
(ensures state_eq_opt false (BS.machine_eval_while cond body f s1) (BS.machine_eval_while cond body f s2))
[SMTPat (BS.machine_eval_while cond body f s1); SMTPat (BS.machine_eval_while cond body f s2)]
=
eval_while_eq_core false cond body f s1; eval_while_eq_core false cond body f s2
let eval_code_eq_t (c:code) (f:fuel) (s1 s2:machine_state) : Lemma
(requires state_eq_S true s1 s2)
(ensures state_eq_opt true (BS.machine_eval_code c f s1) (BS.machine_eval_code c f s2))
[SMTPat (BS.machine_eval_code c f s1); SMTPat (BS.machine_eval_code c f s2)]
=
eval_code_eq_core true c f s1; eval_code_eq_core true c f s2
let eval_codes_eq_t (cs:codes) (f:fuel) (s1 s2:machine_state) : Lemma
(requires state_eq_S true s1 s2)
(ensures state_eq_opt true (BS.machine_eval_codes cs f s1) (BS.machine_eval_codes cs f s2))
[SMTPat (BS.machine_eval_codes cs f s1); SMTPat (BS.machine_eval_codes cs f s2)]
=
eval_codes_eq_core true cs f s1; eval_codes_eq_core true cs f s2
let eval_while_eq_t (cond:ocmp) (body:code) (f:fuel) (s1 s2:machine_state) : Lemma
(requires state_eq_S true s1 s2)
(ensures state_eq_opt true (BS.machine_eval_while cond body f s1) (BS.machine_eval_while cond body f s2))
[SMTPat (BS.machine_eval_while cond body f s1); SMTPat (BS.machine_eval_while cond body f s2)]
=
eval_while_eq_core true cond body f s1; eval_while_eq_core true cond body f s2
let eval_code_ts (g:bool) (c:code) (s0:machine_state) (f0:fuel) (s1:machine_state) : Type0 =
state_eq_opt g (BS.machine_eval_code c f0 s0) (Some s1)
let rec increase_fuel (g:bool) (c:code) (s0:machine_state) (f0:fuel) (sN:machine_state) (fN:fuel) : Lemma
(requires eval_code_ts g c s0 f0 sN /\ f0 <= fN)
(ensures eval_code_ts g c s0 fN sN)
(decreases %[f0; c])
=
match c with
| Ins ins -> ()
| Block l -> increase_fuels g l s0 f0 sN fN
| IfElse cond t f ->
let (s0, b0) = BS.machine_eval_ocmp s0 cond in
if b0 then increase_fuel g t s0 f0 sN fN else increase_fuel g f s0 f0 sN fN
| While cond c ->
let (s1, b0) = BS.machine_eval_ocmp s0 cond in
if b0 then (
match BS.machine_eval_code c (f0 - 1) s1 with
| None -> ()
| Some s2 ->
increase_fuel g c s1 (f0 - 1) s2 (fN - 1);
if s2.BS.ms_ok then increase_fuel g (While cond c) s2 (f0 - 1) sN (fN - 1)
else ()
)
and increase_fuels (g:bool) (c:codes) (s0:machine_state) (f0:fuel) (sN:machine_state) (fN:fuel) : Lemma
(requires eval_code_ts g (Block c) s0 f0 sN /\ f0 <= fN)
(ensures eval_code_ts g (Block c) s0 fN sN)
(decreases %[f0; c])
=
match c with
| [] -> ()
| h::t ->
(
let Some s1 = BS.machine_eval_code h f0 s0 in
increase_fuel g h s0 f0 s1 fN;
increase_fuels g t s1 f0 sN fN
)
let lemma_cmp_eq s o1 o2 = reveal_opaque (`%BS.eval_ocmp_opaque) BS.eval_ocmp_opaque
let lemma_cmp_ne s o1 o2 = reveal_opaque (`%BS.eval_ocmp_opaque) BS.eval_ocmp_opaque
let lemma_cmp_le s o1 o2 = reveal_opaque (`%BS.eval_ocmp_opaque) BS.eval_ocmp_opaque
let lemma_cmp_ge s o1 o2 = reveal_opaque (`%BS.eval_ocmp_opaque) BS.eval_ocmp_opaque
let lemma_cmp_lt s o1 o2 = reveal_opaque (`%BS.eval_ocmp_opaque) BS.eval_ocmp_opaque
let lemma_cmp_gt s o1 o2 = reveal_opaque (`%BS.eval_ocmp_opaque) BS.eval_ocmp_opaque
let lemma_valid_cmp_eq s o1 o2 = ()
let lemma_valid_cmp_ne s o1 o2 = ()
let lemma_valid_cmp_le s o1 o2 = ()
let lemma_valid_cmp_ge s o1 o2 = ()
let lemma_valid_cmp_lt s o1 o2 = ()
let lemma_valid_cmp_gt s o1 o2 = ()
let compute_merge_total (f0:fuel) (fM:fuel) =
if f0 > fM then f0 else fM
let lemma_merge_total (b0:codes) (s0:vale_state) (f0:fuel) (sM:vale_state) (fM:fuel) (sN:vale_state) =
let f = if f0 > fM then f0 else fM in
increase_fuel (codes_modifies_ghost b0) (Cons?.hd b0) (state_to_S s0) f0 (state_to_S sM) f;
increase_fuel (codes_modifies_ghost b0) (Block (Cons?.tl b0)) (state_to_S sM) fM (state_to_S sN) f
let lemma_empty_total (s0:vale_state) (bN:codes) =
(s0, 0)
let lemma_ifElse_total (ifb:ocmp) (ct:code) (cf:code) (s0:vale_state) =
(eval_ocmp s0 ifb, {s0 with vs_flags = havoc_flags}, s0, 0)
let lemma_havoc_flags : squash (Flags.to_fun havoc_flags == BS.havoc_flags) =
assert (FStar.FunctionalExtensionality.feq (Flags.to_fun havoc_flags) BS.havoc_flags)
let lemma_ifElseTrue_total (ifb:ocmp) (ct:code) (cf:code) (s0:vale_state) (f0:fuel) (sM:vale_state) =
reveal_opaque (`%BS.valid_ocmp_opaque) BS.valid_ocmp_opaque;
reveal_opaque (`%BS.eval_ocmp_opaque) BS.eval_ocmp_opaque
let lemma_ifElseFalse_total (ifb:ocmp) (ct:code) (cf:code) (s0:vale_state) (f0:fuel) (sM:vale_state) =
reveal_opaque (`%BS.valid_ocmp_opaque) BS.valid_ocmp_opaque;
reveal_opaque (`%BS.eval_ocmp_opaque) BS.eval_ocmp_opaque | false | true | Vale.X64.Lemmas.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": 30,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val eval_while_inv_temp (c: code) (s0: vale_state) (fW: fuel) (sW: vale_state) : Type0 | [] | Vale.X64.Lemmas.eval_while_inv_temp | {
"file_name": "vale/code/arch/x64/Vale.X64.Lemmas.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} |
c: Vale.X64.StateLemmas.code ->
s0: Vale.X64.State.vale_state ->
fW: Vale.X64.Lemmas.fuel ->
sW: Vale.X64.State.vale_state
-> Type0 | {
"end_col": 48,
"end_line": 377,
"start_col": 2,
"start_line": 373
} |
FStar.Pervasives.Lemma | val lemma_ifElseTrue_total (ifb:ocmp) (ct:code) (cf:code) (s0:vale_state) (f0:fuel) (sM:vale_state) : Lemma
(requires
valid_ocmp ifb s0 /\
eval_ocmp s0 ifb /\
eval_code ct ({s0 with vs_flags = havoc_flags}) f0 sM
)
(ensures
eval_code (IfElse ifb ct cf) s0 f0 sM
) | [
{
"abbrev": true,
"full_module": "Vale.X64.Memory",
"short_module": "ME"
},
{
"abbrev": false,
"full_module": "Vale.X64.Instruction_s",
"short_module": null
},
{
"abbrev": true,
"full_module": "Vale.Lib.Map16",
"short_module": "Map16"
},
{
"abbrev": true,
"full_module": "Vale.X64.Machine_Semantics_s",
"short_module": "BS"
},
{
"abbrev": false,
"full_module": "Vale.X64.Bytes_Code_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.StateLemmas",
"short_module": null
},
{
"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.HeapLemmas",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.HeapImpl",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Heap",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"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 lemma_ifElseTrue_total (ifb:ocmp) (ct:code) (cf:code) (s0:vale_state) (f0:fuel) (sM:vale_state) =
reveal_opaque (`%BS.valid_ocmp_opaque) BS.valid_ocmp_opaque;
reveal_opaque (`%BS.eval_ocmp_opaque) BS.eval_ocmp_opaque | val lemma_ifElseTrue_total (ifb:ocmp) (ct:code) (cf:code) (s0:vale_state) (f0:fuel) (sM:vale_state) : Lemma
(requires
valid_ocmp ifb s0 /\
eval_ocmp s0 ifb /\
eval_code ct ({s0 with vs_flags = havoc_flags}) f0 sM
)
(ensures
eval_code (IfElse ifb ct cf) s0 f0 sM
)
let lemma_ifElseTrue_total (ifb: ocmp) (ct cf: code) (s0: vale_state) (f0: fuel) (sM: vale_state) = | false | null | true | reveal_opaque (`%BS.valid_ocmp_opaque) BS.valid_ocmp_opaque;
reveal_opaque (`%BS.eval_ocmp_opaque) BS.eval_ocmp_opaque | {
"checked_file": "Vale.X64.Lemmas.fst.checked",
"dependencies": [
"Vale.X64.StateLemmas.fsti.checked",
"Vale.X64.State.fsti.checked",
"Vale.X64.Memory.fsti.checked",
"Vale.X64.Machine_Semantics_s.fst.checked",
"Vale.X64.Machine_s.fst.checked",
"Vale.X64.Instruction_s.fsti.checked",
"Vale.X64.Flags.fsti.checked",
"Vale.X64.Bytes_Code_s.fst.checked",
"prims.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.FunctionalExtensionality.fsti.checked"
],
"interface_file": true,
"source_file": "Vale.X64.Lemmas.fst"
} | [
"lemma"
] | [
"Vale.X64.Bytes_Code_s.ocmp",
"Vale.X64.StateLemmas.code",
"Vale.X64.State.vale_state",
"Vale.X64.Lemmas.fuel",
"FStar.Pervasives.reveal_opaque",
"Vale.X64.Machine_Semantics_s.machine_state",
"Vale.X64.Machine_Semantics_s.ocmp",
"Prims.bool",
"Vale.X64.Machine_Semantics_s.eval_ocmp_opaque",
"Prims.unit",
"Vale.X64.Machine_Semantics_s.valid_ocmp_opaque"
] | [] | module Vale.X64.Lemmas
open FStar.Mul
open Vale.X64.Machine_s
open Vale.X64.State
open Vale.X64.StateLemmas
open Vale.X64.Instruction_s
open Vale.X64.Bytes_Code_s
module BS = Vale.X64.Machine_Semantics_s
module ME = Vale.X64.Memory
#reset-options "--initial_fuel 1 --max_fuel 1 --z3rlimit 100"
#restart-solver
let rec lemma_eq_instr_apply_eval_args
(outs:list instr_out) (args:list instr_operand)
(f:instr_args_t outs args) (oprs:instr_operands_t_args args) (s1 s2:machine_state)
: Lemma
(requires state_eq_S true s1 s2)
(ensures
BS.instr_apply_eval_args outs args f oprs s1 ==
BS.instr_apply_eval_args outs args f oprs s2)
=
let open BS in
lemma_heap_ignore_ghost_machine s1.BS.ms_heap s2.BS.ms_heap;
match args with
| [] -> ()
| i::args ->
(
let (v, oprs) : option (instr_val_t i) & instr_operands_t_args args =
match i with
| IOpEx i -> let oprs = coerce oprs in (instr_eval_operand_explicit i (fst oprs) s1, snd oprs)
| IOpIm i -> (instr_eval_operand_implicit i s1, coerce oprs)
in
let f:arrow (instr_val_t i) (instr_args_t outs args) = coerce f in
match v with
| None -> ()
| Some v -> lemma_eq_instr_apply_eval_args outs args (f v) oprs s1 s2
)
#restart-solver
let rec lemma_eq_instr_apply_eval_inouts
(outs inouts:list instr_out) (args:list instr_operand)
(f:instr_inouts_t outs inouts args) (oprs:instr_operands_t inouts args) (s1 s2:machine_state)
: Lemma
(requires state_eq_S true s1 s2)
(ensures
BS.instr_apply_eval_inouts outs inouts args f oprs s1 ==
BS.instr_apply_eval_inouts outs inouts args f oprs s2)
=
let open BS in
lemma_heap_ignore_ghost_machine s1.BS.ms_heap s2.BS.ms_heap;
match inouts with
| [] -> lemma_eq_instr_apply_eval_args outs args f oprs s1 s2
| (Out, i)::inouts ->
let oprs =
match i with
| IOpEx i -> snd #(instr_operand_t i) (coerce oprs)
| IOpIm i -> coerce oprs
in
lemma_eq_instr_apply_eval_inouts outs inouts args (coerce f) oprs s1 s2
| (InOut, i)::inouts ->
(
let (v, oprs) : option (instr_val_t i) & instr_operands_t inouts args =
match i with
| IOpEx i -> let oprs = coerce oprs in (instr_eval_operand_explicit i (fst oprs) s1, snd oprs)
| IOpIm i -> (instr_eval_operand_implicit i s1, coerce oprs)
in
let f:arrow (instr_val_t i) (instr_inouts_t outs inouts args) = coerce f in
match v with
| None -> ()
| Some v -> lemma_eq_instr_apply_eval_inouts outs inouts args (f v) oprs s1 s2
)
#restart-solver
#push-options "--z3rlimit_factor 2"
let rec lemma_eq_instr_write_outputs
(outs:list instr_out) (args:list instr_operand)
(vs:instr_ret_t outs) (oprs:instr_operands_t outs args) (s1_orig s1 s2_orig s2:machine_state)
: Lemma
(requires state_eq_S true s1_orig s2_orig /\ state_eq_S true s1 s2)
(ensures
state_eq_S true
(BS.instr_write_outputs outs args vs oprs s1_orig s1)
(BS.instr_write_outputs outs args vs oprs s2_orig s2))
=
let open BS in
use_machine_state_equal ();
lemma_heap_ignore_ghost_machine s1.BS.ms_heap s2.BS.ms_heap;
lemma_heap_ignore_ghost_machine s1_orig.BS.ms_heap s2_orig.BS.ms_heap;
allow_inversion tmaddr;
match outs with
| [] -> ()
| (_, i)::outs ->
(
let ((v:instr_val_t i), (vs:instr_ret_t outs)) =
match outs with
| [] -> (vs, ())
| _::_ -> let vs = coerce vs in (fst vs, snd vs)
in
match i with
| IOpEx i ->
let oprs = coerce oprs in
let s1 = instr_write_output_explicit i v (fst oprs) s1_orig s1 in
let s2 = instr_write_output_explicit i v (fst oprs) s2_orig s2 in
lemma_eq_instr_write_outputs outs args vs (snd oprs) s1_orig s1 s2_orig s2
| IOpIm i ->
let s1 = instr_write_output_implicit i v s1_orig s1 in
let s2 = instr_write_output_implicit i v s2_orig s2 in
allow_inversion operand64;
allow_inversion operand128;
lemma_eq_instr_write_outputs outs args vs (coerce oprs) s1_orig s1 s2_orig s2
)
#pop-options
#restart-solver
let eval_ins_eq_instr (inst:BS.ins) (s1 s2:machine_state) : Lemma
(requires Instr? inst /\ state_eq_S true s1 s2)
(ensures state_eq_S true (BS.machine_eval_ins inst s1) (BS.machine_eval_ins inst s2))
=
let open BS in
let Instr it oprs ann = inst in
let InstrTypeRecord #outs #args #havoc_flags' i = it in
lemma_eq_instr_apply_eval_inouts outs outs args (instr_eval i) oprs s1 s2;
let vs = instr_apply_eval outs args (instr_eval i) oprs s1 in
let hav s =
match havoc_flags' with
| HavocFlags -> {s with ms_flags = havoc_flags}
| PreserveFlags -> s
in
let s1' = hav s1 in
let s2' = hav s2 in
match vs with
| None -> ()
| Some vs -> lemma_eq_instr_write_outputs outs args vs oprs s1 s1' s2 s2'
let eval_code_eq_instr (inst:BS.ins) (f:fuel) (s1 s2:machine_state) : Lemma
(requires Instr? inst /\ state_eq_S true s1 s2)
(ensures state_eq_opt true (BS.machine_eval_code (Ins inst) f s1) (BS.machine_eval_code (Ins inst) f s2))
=
reveal_opaque (`%BS.machine_eval_code_ins) BS.machine_eval_code_ins;
eval_ins_eq_instr inst ({s1 with BS.ms_trace = []}) ({s2 with BS.ms_trace = []})
let eval_code_eq_dealloc (inst:BS.ins) (f:fuel) (s1 s2:machine_state) : Lemma
(requires Dealloc? inst /\ state_eq_S true s1 s2)
(ensures state_eq_opt true (BS.machine_eval_code (Ins inst) f s1) (BS.machine_eval_code (Ins inst) f s2))
=
reveal_opaque (`%BS.machine_eval_code_ins) BS.machine_eval_code_ins;
use_machine_state_equal ();
lemma_heap_ignore_ghost_machine s1.BS.ms_heap s2.BS.ms_heap;
allow_inversion tmaddr
let eval_code_eq_alloc (inst:BS.ins) (f:fuel) (s1 s2:machine_state) : Lemma
(requires Alloc? inst /\ state_eq_S true s1 s2)
(ensures state_eq_opt true (BS.machine_eval_code (Ins inst) f s1) (BS.machine_eval_code (Ins inst) f s2))
=
reveal_opaque (`%BS.machine_eval_code_ins) BS.machine_eval_code_ins;
use_machine_state_equal ();
lemma_heap_ignore_ghost_machine s1.BS.ms_heap s2.BS.ms_heap;
allow_inversion tmaddr
let eval_code_eq_push (inst:BS.ins) (f:fuel) (s1 s2:machine_state) : Lemma
(requires Push? inst /\ state_eq_S true s1 s2)
(ensures state_eq_opt true (BS.machine_eval_code (Ins inst) f s1) (BS.machine_eval_code (Ins inst) f s2))
=
reveal_opaque (`%BS.machine_eval_code_ins) BS.machine_eval_code_ins;
use_machine_state_equal ();
lemma_heap_ignore_ghost_machine s1.BS.ms_heap s2.BS.ms_heap;
allow_inversion tmaddr
let eval_code_eq_pop (inst:BS.ins) (f:fuel) (s1 s2:machine_state) : Lemma
(requires Pop? inst /\ state_eq_S true s1 s2)
(ensures state_eq_opt true (BS.machine_eval_code (Ins inst) f s1) (BS.machine_eval_code (Ins inst) f s2))
=
reveal_opaque (`%BS.machine_eval_code_ins) BS.machine_eval_code_ins;
use_machine_state_equal ();
lemma_heap_ignore_ghost_machine s1.BS.ms_heap s2.BS.ms_heap;
allow_inversion tmaddr
let eval_code_eq_ins (i:BS.ins) (f:fuel) (s1 s2:machine_state) : Lemma
(requires state_eq_S true s1 s2)
(ensures state_eq_opt true (BS.machine_eval_code (Ins i) f s1) (BS.machine_eval_code (Ins i) f s2))
=
match i with
| Instr _ _ _ -> eval_code_eq_instr i f s1 s2
| Dealloc _ -> eval_code_eq_dealloc i f s1 s2
| Alloc _ -> eval_code_eq_alloc i f s1 s2
| Push _ _ -> eval_code_eq_push i f s1 s2
| Pop _ _ -> eval_code_eq_pop i f s1 s2
#reset-options "--fuel 2 --z3rlimit 30"
let eval_ocmp_eq_core (g:bool) (cond:ocmp) (s:machine_state) : Lemma
(ensures (
let (s1, b1) = BS.machine_eval_ocmp s cond in
let (s2, b2) = BS.machine_eval_ocmp (core_state g s) cond in
state_eq_S g s1 s2 /\ b1 == b2
))
=
reveal_opaque (`%BS.valid_ocmp_opaque) BS.valid_ocmp_opaque;
reveal_opaque (`%BS.eval_ocmp_opaque) BS.eval_ocmp_opaque;
()
#restart-solver
let rec eval_code_eq_core (g:bool) (c:code) (f:fuel) (s:machine_state) : Lemma
(ensures state_eq_opt g (BS.machine_eval_code c f s) (BS.machine_eval_code c f (core_state g s)))
(decreases %[f; c])
=
match c with
| Ins i ->
reveal_opaque (`%BS.machine_eval_code_ins) BS.machine_eval_code_ins;
if g then eval_code_eq_ins i f s (core_state g s)
| Block cs -> eval_codes_eq_core g cs f s
| IfElse cond ct cf ->
eval_ocmp_eq_core g cond s;
let (s', _) = BS.machine_eval_ocmp s cond in
let (t', _) = BS.machine_eval_ocmp (core_state g s) cond in
eval_code_eq_core g ct f s';
eval_code_eq_core g ct f t';
eval_code_eq_core g cf f s';
eval_code_eq_core g cf f t';
()
| While cond body -> eval_while_eq_core g cond body f s
and eval_codes_eq_core (g:bool) (cs:codes) (f:fuel) (s:machine_state) : Lemma
(ensures state_eq_opt g (BS.machine_eval_codes cs f s) (BS.machine_eval_codes cs f (core_state g s)))
(decreases %[f; cs])
=
match cs with
| [] -> ()
| c'::cs' -> (
eval_code_eq_core g c' f s;
match (machine_eval_code c' f s, machine_eval_code c' f (core_state g s)) with
| (None, None) -> ()
| (Some s', Some t') -> eval_codes_eq_core g cs' f s'; eval_codes_eq_core g cs' f t'
)
and eval_while_eq_core (g:bool) (cond:ocmp) (body:code) (f:fuel) (s:machine_state) : Lemma
(ensures state_eq_opt g (BS.machine_eval_while cond body f s) (BS.machine_eval_while cond body f (core_state g s)))
(decreases %[f; body])
=
if f > 0 then (
eval_ocmp_eq_core g cond s;
let (s1, _) = BS.machine_eval_ocmp s cond in
let (t1, _) = BS.machine_eval_ocmp (core_state g s) cond in
eval_code_eq_core g body (f - 1) s1;
eval_code_eq_core g body (f - 1) t1;
match (BS.machine_eval_code body (f - 1) s1, BS.machine_eval_code body (f - 1) t1) with
| (None, None) -> ()
| (Some s2, Some t2) ->
eval_while_eq_core g cond body (f - 1) s2;
eval_while_eq_core g cond body (f - 1) t2;
()
)
let eval_code_eq_f (c:code) (f:fuel) (s1 s2:machine_state) : Lemma
(requires state_eq_S false s1 s2)
(ensures state_eq_opt false (BS.machine_eval_code c f s1) (BS.machine_eval_code c f s2))
[SMTPat (BS.machine_eval_code c f s1); SMTPat (BS.machine_eval_code c f s2)]
=
eval_code_eq_core false c f s1; eval_code_eq_core false c f s2
let eval_codes_eq_f (cs:codes) (f:fuel) (s1 s2:machine_state) : Lemma
(requires state_eq_S false s1 s2)
(ensures state_eq_opt false (BS.machine_eval_codes cs f s1) (BS.machine_eval_codes cs f s2))
[SMTPat (BS.machine_eval_codes cs f s1); SMTPat (BS.machine_eval_codes cs f s2)]
=
eval_codes_eq_core false cs f s1; eval_codes_eq_core false cs f s2
let eval_while_eq_f (cond:ocmp) (body:code) (f:fuel) (s1 s2:machine_state) : Lemma
(requires state_eq_S false s1 s2)
(ensures state_eq_opt false (BS.machine_eval_while cond body f s1) (BS.machine_eval_while cond body f s2))
[SMTPat (BS.machine_eval_while cond body f s1); SMTPat (BS.machine_eval_while cond body f s2)]
=
eval_while_eq_core false cond body f s1; eval_while_eq_core false cond body f s2
let eval_code_eq_t (c:code) (f:fuel) (s1 s2:machine_state) : Lemma
(requires state_eq_S true s1 s2)
(ensures state_eq_opt true (BS.machine_eval_code c f s1) (BS.machine_eval_code c f s2))
[SMTPat (BS.machine_eval_code c f s1); SMTPat (BS.machine_eval_code c f s2)]
=
eval_code_eq_core true c f s1; eval_code_eq_core true c f s2
let eval_codes_eq_t (cs:codes) (f:fuel) (s1 s2:machine_state) : Lemma
(requires state_eq_S true s1 s2)
(ensures state_eq_opt true (BS.machine_eval_codes cs f s1) (BS.machine_eval_codes cs f s2))
[SMTPat (BS.machine_eval_codes cs f s1); SMTPat (BS.machine_eval_codes cs f s2)]
=
eval_codes_eq_core true cs f s1; eval_codes_eq_core true cs f s2
let eval_while_eq_t (cond:ocmp) (body:code) (f:fuel) (s1 s2:machine_state) : Lemma
(requires state_eq_S true s1 s2)
(ensures state_eq_opt true (BS.machine_eval_while cond body f s1) (BS.machine_eval_while cond body f s2))
[SMTPat (BS.machine_eval_while cond body f s1); SMTPat (BS.machine_eval_while cond body f s2)]
=
eval_while_eq_core true cond body f s1; eval_while_eq_core true cond body f s2
let eval_code_ts (g:bool) (c:code) (s0:machine_state) (f0:fuel) (s1:machine_state) : Type0 =
state_eq_opt g (BS.machine_eval_code c f0 s0) (Some s1)
let rec increase_fuel (g:bool) (c:code) (s0:machine_state) (f0:fuel) (sN:machine_state) (fN:fuel) : Lemma
(requires eval_code_ts g c s0 f0 sN /\ f0 <= fN)
(ensures eval_code_ts g c s0 fN sN)
(decreases %[f0; c])
=
match c with
| Ins ins -> ()
| Block l -> increase_fuels g l s0 f0 sN fN
| IfElse cond t f ->
let (s0, b0) = BS.machine_eval_ocmp s0 cond in
if b0 then increase_fuel g t s0 f0 sN fN else increase_fuel g f s0 f0 sN fN
| While cond c ->
let (s1, b0) = BS.machine_eval_ocmp s0 cond in
if b0 then (
match BS.machine_eval_code c (f0 - 1) s1 with
| None -> ()
| Some s2 ->
increase_fuel g c s1 (f0 - 1) s2 (fN - 1);
if s2.BS.ms_ok then increase_fuel g (While cond c) s2 (f0 - 1) sN (fN - 1)
else ()
)
and increase_fuels (g:bool) (c:codes) (s0:machine_state) (f0:fuel) (sN:machine_state) (fN:fuel) : Lemma
(requires eval_code_ts g (Block c) s0 f0 sN /\ f0 <= fN)
(ensures eval_code_ts g (Block c) s0 fN sN)
(decreases %[f0; c])
=
match c with
| [] -> ()
| h::t ->
(
let Some s1 = BS.machine_eval_code h f0 s0 in
increase_fuel g h s0 f0 s1 fN;
increase_fuels g t s1 f0 sN fN
)
let lemma_cmp_eq s o1 o2 = reveal_opaque (`%BS.eval_ocmp_opaque) BS.eval_ocmp_opaque
let lemma_cmp_ne s o1 o2 = reveal_opaque (`%BS.eval_ocmp_opaque) BS.eval_ocmp_opaque
let lemma_cmp_le s o1 o2 = reveal_opaque (`%BS.eval_ocmp_opaque) BS.eval_ocmp_opaque
let lemma_cmp_ge s o1 o2 = reveal_opaque (`%BS.eval_ocmp_opaque) BS.eval_ocmp_opaque
let lemma_cmp_lt s o1 o2 = reveal_opaque (`%BS.eval_ocmp_opaque) BS.eval_ocmp_opaque
let lemma_cmp_gt s o1 o2 = reveal_opaque (`%BS.eval_ocmp_opaque) BS.eval_ocmp_opaque
let lemma_valid_cmp_eq s o1 o2 = ()
let lemma_valid_cmp_ne s o1 o2 = ()
let lemma_valid_cmp_le s o1 o2 = ()
let lemma_valid_cmp_ge s o1 o2 = ()
let lemma_valid_cmp_lt s o1 o2 = ()
let lemma_valid_cmp_gt s o1 o2 = ()
let compute_merge_total (f0:fuel) (fM:fuel) =
if f0 > fM then f0 else fM
let lemma_merge_total (b0:codes) (s0:vale_state) (f0:fuel) (sM:vale_state) (fM:fuel) (sN:vale_state) =
let f = if f0 > fM then f0 else fM in
increase_fuel (codes_modifies_ghost b0) (Cons?.hd b0) (state_to_S s0) f0 (state_to_S sM) f;
increase_fuel (codes_modifies_ghost b0) (Block (Cons?.tl b0)) (state_to_S sM) fM (state_to_S sN) f
let lemma_empty_total (s0:vale_state) (bN:codes) =
(s0, 0)
let lemma_ifElse_total (ifb:ocmp) (ct:code) (cf:code) (s0:vale_state) =
(eval_ocmp s0 ifb, {s0 with vs_flags = havoc_flags}, s0, 0)
let lemma_havoc_flags : squash (Flags.to_fun havoc_flags == BS.havoc_flags) =
assert (FStar.FunctionalExtensionality.feq (Flags.to_fun havoc_flags) BS.havoc_flags) | false | false | Vale.X64.Lemmas.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": 30,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val lemma_ifElseTrue_total (ifb:ocmp) (ct:code) (cf:code) (s0:vale_state) (f0:fuel) (sM:vale_state) : Lemma
(requires
valid_ocmp ifb s0 /\
eval_ocmp s0 ifb /\
eval_code ct ({s0 with vs_flags = havoc_flags}) f0 sM
)
(ensures
eval_code (IfElse ifb ct cf) s0 f0 sM
) | [] | Vale.X64.Lemmas.lemma_ifElseTrue_total | {
"file_name": "vale/code/arch/x64/Vale.X64.Lemmas.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} |
ifb: Vale.X64.Bytes_Code_s.ocmp ->
ct: Vale.X64.StateLemmas.code ->
cf: Vale.X64.StateLemmas.code ->
s0: Vale.X64.State.vale_state ->
f0: Vale.X64.Lemmas.fuel ->
sM: Vale.X64.State.vale_state
-> FStar.Pervasives.Lemma
(requires
Vale.X64.Lemmas.valid_ocmp ifb s0 /\ Vale.X64.Lemmas.eval_ocmp s0 ifb /\
Vale.X64.Lemmas.eval_code ct
(Vale.X64.State.Mkvale_state (Mkvale_state?.vs_ok s0)
(Mkvale_state?.vs_regs s0)
Vale.X64.Lemmas.havoc_flags
(Mkvale_state?.vs_heap s0)
(Mkvale_state?.vs_stack s0)
(Mkvale_state?.vs_stackTaint s0))
f0
sM) (ensures Vale.X64.Lemmas.eval_code (Vale.X64.Machine_s.IfElse ifb ct cf) s0 f0 sM) | {
"end_col": 59,
"end_line": 366,
"start_col": 2,
"start_line": 365
} |
Prims.Tot | val lemma_havoc_flags:squash (Flags.to_fun havoc_flags == BS.havoc_flags) | [
{
"abbrev": true,
"full_module": "Vale.X64.Memory",
"short_module": "ME"
},
{
"abbrev": true,
"full_module": "Vale.X64.Machine_Semantics_s",
"short_module": "BS"
},
{
"abbrev": false,
"full_module": "Vale.X64.Bytes_Code_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Instruction_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.StateLemmas",
"short_module": null
},
{
"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": "FStar.Mul",
"short_module": null
},
{
"abbrev": true,
"full_module": "Vale.Lib.Map16",
"short_module": "Map16"
},
{
"abbrev": true,
"full_module": "Vale.X64.Machine_Semantics_s",
"short_module": "BS"
},
{
"abbrev": false,
"full_module": "Vale.X64.Bytes_Code_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.StateLemmas",
"short_module": null
},
{
"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.HeapLemmas",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.HeapImpl",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Heap",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"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 lemma_havoc_flags : squash (Flags.to_fun havoc_flags == BS.havoc_flags) =
assert (FStar.FunctionalExtensionality.feq (Flags.to_fun havoc_flags) BS.havoc_flags) | val lemma_havoc_flags:squash (Flags.to_fun havoc_flags == BS.havoc_flags)
let lemma_havoc_flags:squash (Flags.to_fun havoc_flags == BS.havoc_flags) = | false | null | true | assert (FStar.FunctionalExtensionality.feq (Flags.to_fun havoc_flags) BS.havoc_flags) | {
"checked_file": "Vale.X64.Lemmas.fst.checked",
"dependencies": [
"Vale.X64.StateLemmas.fsti.checked",
"Vale.X64.State.fsti.checked",
"Vale.X64.Memory.fsti.checked",
"Vale.X64.Machine_Semantics_s.fst.checked",
"Vale.X64.Machine_s.fst.checked",
"Vale.X64.Instruction_s.fsti.checked",
"Vale.X64.Flags.fsti.checked",
"Vale.X64.Bytes_Code_s.fst.checked",
"prims.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.FunctionalExtensionality.fsti.checked"
],
"interface_file": true,
"source_file": "Vale.X64.Lemmas.fst"
} | [
"total"
] | [
"Prims._assert",
"FStar.FunctionalExtensionality.feq",
"Vale.X64.Machine_s.flag",
"Vale.X64.Flags.flag_val_t",
"Vale.X64.Flags.to_fun",
"Vale.X64.Lemmas.havoc_flags",
"Vale.X64.Machine_Semantics_s.havoc_flags"
] | [] | module Vale.X64.Lemmas
open FStar.Mul
open Vale.X64.Machine_s
open Vale.X64.State
open Vale.X64.StateLemmas
open Vale.X64.Instruction_s
open Vale.X64.Bytes_Code_s
module BS = Vale.X64.Machine_Semantics_s
module ME = Vale.X64.Memory
#reset-options "--initial_fuel 1 --max_fuel 1 --z3rlimit 100"
#restart-solver
let rec lemma_eq_instr_apply_eval_args
(outs:list instr_out) (args:list instr_operand)
(f:instr_args_t outs args) (oprs:instr_operands_t_args args) (s1 s2:machine_state)
: Lemma
(requires state_eq_S true s1 s2)
(ensures
BS.instr_apply_eval_args outs args f oprs s1 ==
BS.instr_apply_eval_args outs args f oprs s2)
=
let open BS in
lemma_heap_ignore_ghost_machine s1.BS.ms_heap s2.BS.ms_heap;
match args with
| [] -> ()
| i::args ->
(
let (v, oprs) : option (instr_val_t i) & instr_operands_t_args args =
match i with
| IOpEx i -> let oprs = coerce oprs in (instr_eval_operand_explicit i (fst oprs) s1, snd oprs)
| IOpIm i -> (instr_eval_operand_implicit i s1, coerce oprs)
in
let f:arrow (instr_val_t i) (instr_args_t outs args) = coerce f in
match v with
| None -> ()
| Some v -> lemma_eq_instr_apply_eval_args outs args (f v) oprs s1 s2
)
#restart-solver
let rec lemma_eq_instr_apply_eval_inouts
(outs inouts:list instr_out) (args:list instr_operand)
(f:instr_inouts_t outs inouts args) (oprs:instr_operands_t inouts args) (s1 s2:machine_state)
: Lemma
(requires state_eq_S true s1 s2)
(ensures
BS.instr_apply_eval_inouts outs inouts args f oprs s1 ==
BS.instr_apply_eval_inouts outs inouts args f oprs s2)
=
let open BS in
lemma_heap_ignore_ghost_machine s1.BS.ms_heap s2.BS.ms_heap;
match inouts with
| [] -> lemma_eq_instr_apply_eval_args outs args f oprs s1 s2
| (Out, i)::inouts ->
let oprs =
match i with
| IOpEx i -> snd #(instr_operand_t i) (coerce oprs)
| IOpIm i -> coerce oprs
in
lemma_eq_instr_apply_eval_inouts outs inouts args (coerce f) oprs s1 s2
| (InOut, i)::inouts ->
(
let (v, oprs) : option (instr_val_t i) & instr_operands_t inouts args =
match i with
| IOpEx i -> let oprs = coerce oprs in (instr_eval_operand_explicit i (fst oprs) s1, snd oprs)
| IOpIm i -> (instr_eval_operand_implicit i s1, coerce oprs)
in
let f:arrow (instr_val_t i) (instr_inouts_t outs inouts args) = coerce f in
match v with
| None -> ()
| Some v -> lemma_eq_instr_apply_eval_inouts outs inouts args (f v) oprs s1 s2
)
#restart-solver
#push-options "--z3rlimit_factor 2"
let rec lemma_eq_instr_write_outputs
(outs:list instr_out) (args:list instr_operand)
(vs:instr_ret_t outs) (oprs:instr_operands_t outs args) (s1_orig s1 s2_orig s2:machine_state)
: Lemma
(requires state_eq_S true s1_orig s2_orig /\ state_eq_S true s1 s2)
(ensures
state_eq_S true
(BS.instr_write_outputs outs args vs oprs s1_orig s1)
(BS.instr_write_outputs outs args vs oprs s2_orig s2))
=
let open BS in
use_machine_state_equal ();
lemma_heap_ignore_ghost_machine s1.BS.ms_heap s2.BS.ms_heap;
lemma_heap_ignore_ghost_machine s1_orig.BS.ms_heap s2_orig.BS.ms_heap;
allow_inversion tmaddr;
match outs with
| [] -> ()
| (_, i)::outs ->
(
let ((v:instr_val_t i), (vs:instr_ret_t outs)) =
match outs with
| [] -> (vs, ())
| _::_ -> let vs = coerce vs in (fst vs, snd vs)
in
match i with
| IOpEx i ->
let oprs = coerce oprs in
let s1 = instr_write_output_explicit i v (fst oprs) s1_orig s1 in
let s2 = instr_write_output_explicit i v (fst oprs) s2_orig s2 in
lemma_eq_instr_write_outputs outs args vs (snd oprs) s1_orig s1 s2_orig s2
| IOpIm i ->
let s1 = instr_write_output_implicit i v s1_orig s1 in
let s2 = instr_write_output_implicit i v s2_orig s2 in
allow_inversion operand64;
allow_inversion operand128;
lemma_eq_instr_write_outputs outs args vs (coerce oprs) s1_orig s1 s2_orig s2
)
#pop-options
#restart-solver
let eval_ins_eq_instr (inst:BS.ins) (s1 s2:machine_state) : Lemma
(requires Instr? inst /\ state_eq_S true s1 s2)
(ensures state_eq_S true (BS.machine_eval_ins inst s1) (BS.machine_eval_ins inst s2))
=
let open BS in
let Instr it oprs ann = inst in
let InstrTypeRecord #outs #args #havoc_flags' i = it in
lemma_eq_instr_apply_eval_inouts outs outs args (instr_eval i) oprs s1 s2;
let vs = instr_apply_eval outs args (instr_eval i) oprs s1 in
let hav s =
match havoc_flags' with
| HavocFlags -> {s with ms_flags = havoc_flags}
| PreserveFlags -> s
in
let s1' = hav s1 in
let s2' = hav s2 in
match vs with
| None -> ()
| Some vs -> lemma_eq_instr_write_outputs outs args vs oprs s1 s1' s2 s2'
let eval_code_eq_instr (inst:BS.ins) (f:fuel) (s1 s2:machine_state) : Lemma
(requires Instr? inst /\ state_eq_S true s1 s2)
(ensures state_eq_opt true (BS.machine_eval_code (Ins inst) f s1) (BS.machine_eval_code (Ins inst) f s2))
=
reveal_opaque (`%BS.machine_eval_code_ins) BS.machine_eval_code_ins;
eval_ins_eq_instr inst ({s1 with BS.ms_trace = []}) ({s2 with BS.ms_trace = []})
let eval_code_eq_dealloc (inst:BS.ins) (f:fuel) (s1 s2:machine_state) : Lemma
(requires Dealloc? inst /\ state_eq_S true s1 s2)
(ensures state_eq_opt true (BS.machine_eval_code (Ins inst) f s1) (BS.machine_eval_code (Ins inst) f s2))
=
reveal_opaque (`%BS.machine_eval_code_ins) BS.machine_eval_code_ins;
use_machine_state_equal ();
lemma_heap_ignore_ghost_machine s1.BS.ms_heap s2.BS.ms_heap;
allow_inversion tmaddr
let eval_code_eq_alloc (inst:BS.ins) (f:fuel) (s1 s2:machine_state) : Lemma
(requires Alloc? inst /\ state_eq_S true s1 s2)
(ensures state_eq_opt true (BS.machine_eval_code (Ins inst) f s1) (BS.machine_eval_code (Ins inst) f s2))
=
reveal_opaque (`%BS.machine_eval_code_ins) BS.machine_eval_code_ins;
use_machine_state_equal ();
lemma_heap_ignore_ghost_machine s1.BS.ms_heap s2.BS.ms_heap;
allow_inversion tmaddr
let eval_code_eq_push (inst:BS.ins) (f:fuel) (s1 s2:machine_state) : Lemma
(requires Push? inst /\ state_eq_S true s1 s2)
(ensures state_eq_opt true (BS.machine_eval_code (Ins inst) f s1) (BS.machine_eval_code (Ins inst) f s2))
=
reveal_opaque (`%BS.machine_eval_code_ins) BS.machine_eval_code_ins;
use_machine_state_equal ();
lemma_heap_ignore_ghost_machine s1.BS.ms_heap s2.BS.ms_heap;
allow_inversion tmaddr
let eval_code_eq_pop (inst:BS.ins) (f:fuel) (s1 s2:machine_state) : Lemma
(requires Pop? inst /\ state_eq_S true s1 s2)
(ensures state_eq_opt true (BS.machine_eval_code (Ins inst) f s1) (BS.machine_eval_code (Ins inst) f s2))
=
reveal_opaque (`%BS.machine_eval_code_ins) BS.machine_eval_code_ins;
use_machine_state_equal ();
lemma_heap_ignore_ghost_machine s1.BS.ms_heap s2.BS.ms_heap;
allow_inversion tmaddr
let eval_code_eq_ins (i:BS.ins) (f:fuel) (s1 s2:machine_state) : Lemma
(requires state_eq_S true s1 s2)
(ensures state_eq_opt true (BS.machine_eval_code (Ins i) f s1) (BS.machine_eval_code (Ins i) f s2))
=
match i with
| Instr _ _ _ -> eval_code_eq_instr i f s1 s2
| Dealloc _ -> eval_code_eq_dealloc i f s1 s2
| Alloc _ -> eval_code_eq_alloc i f s1 s2
| Push _ _ -> eval_code_eq_push i f s1 s2
| Pop _ _ -> eval_code_eq_pop i f s1 s2
#reset-options "--fuel 2 --z3rlimit 30"
let eval_ocmp_eq_core (g:bool) (cond:ocmp) (s:machine_state) : Lemma
(ensures (
let (s1, b1) = BS.machine_eval_ocmp s cond in
let (s2, b2) = BS.machine_eval_ocmp (core_state g s) cond in
state_eq_S g s1 s2 /\ b1 == b2
))
=
reveal_opaque (`%BS.valid_ocmp_opaque) BS.valid_ocmp_opaque;
reveal_opaque (`%BS.eval_ocmp_opaque) BS.eval_ocmp_opaque;
()
#restart-solver
let rec eval_code_eq_core (g:bool) (c:code) (f:fuel) (s:machine_state) : Lemma
(ensures state_eq_opt g (BS.machine_eval_code c f s) (BS.machine_eval_code c f (core_state g s)))
(decreases %[f; c])
=
match c with
| Ins i ->
reveal_opaque (`%BS.machine_eval_code_ins) BS.machine_eval_code_ins;
if g then eval_code_eq_ins i f s (core_state g s)
| Block cs -> eval_codes_eq_core g cs f s
| IfElse cond ct cf ->
eval_ocmp_eq_core g cond s;
let (s', _) = BS.machine_eval_ocmp s cond in
let (t', _) = BS.machine_eval_ocmp (core_state g s) cond in
eval_code_eq_core g ct f s';
eval_code_eq_core g ct f t';
eval_code_eq_core g cf f s';
eval_code_eq_core g cf f t';
()
| While cond body -> eval_while_eq_core g cond body f s
and eval_codes_eq_core (g:bool) (cs:codes) (f:fuel) (s:machine_state) : Lemma
(ensures state_eq_opt g (BS.machine_eval_codes cs f s) (BS.machine_eval_codes cs f (core_state g s)))
(decreases %[f; cs])
=
match cs with
| [] -> ()
| c'::cs' -> (
eval_code_eq_core g c' f s;
match (machine_eval_code c' f s, machine_eval_code c' f (core_state g s)) with
| (None, None) -> ()
| (Some s', Some t') -> eval_codes_eq_core g cs' f s'; eval_codes_eq_core g cs' f t'
)
and eval_while_eq_core (g:bool) (cond:ocmp) (body:code) (f:fuel) (s:machine_state) : Lemma
(ensures state_eq_opt g (BS.machine_eval_while cond body f s) (BS.machine_eval_while cond body f (core_state g s)))
(decreases %[f; body])
=
if f > 0 then (
eval_ocmp_eq_core g cond s;
let (s1, _) = BS.machine_eval_ocmp s cond in
let (t1, _) = BS.machine_eval_ocmp (core_state g s) cond in
eval_code_eq_core g body (f - 1) s1;
eval_code_eq_core g body (f - 1) t1;
match (BS.machine_eval_code body (f - 1) s1, BS.machine_eval_code body (f - 1) t1) with
| (None, None) -> ()
| (Some s2, Some t2) ->
eval_while_eq_core g cond body (f - 1) s2;
eval_while_eq_core g cond body (f - 1) t2;
()
)
let eval_code_eq_f (c:code) (f:fuel) (s1 s2:machine_state) : Lemma
(requires state_eq_S false s1 s2)
(ensures state_eq_opt false (BS.machine_eval_code c f s1) (BS.machine_eval_code c f s2))
[SMTPat (BS.machine_eval_code c f s1); SMTPat (BS.machine_eval_code c f s2)]
=
eval_code_eq_core false c f s1; eval_code_eq_core false c f s2
let eval_codes_eq_f (cs:codes) (f:fuel) (s1 s2:machine_state) : Lemma
(requires state_eq_S false s1 s2)
(ensures state_eq_opt false (BS.machine_eval_codes cs f s1) (BS.machine_eval_codes cs f s2))
[SMTPat (BS.machine_eval_codes cs f s1); SMTPat (BS.machine_eval_codes cs f s2)]
=
eval_codes_eq_core false cs f s1; eval_codes_eq_core false cs f s2
let eval_while_eq_f (cond:ocmp) (body:code) (f:fuel) (s1 s2:machine_state) : Lemma
(requires state_eq_S false s1 s2)
(ensures state_eq_opt false (BS.machine_eval_while cond body f s1) (BS.machine_eval_while cond body f s2))
[SMTPat (BS.machine_eval_while cond body f s1); SMTPat (BS.machine_eval_while cond body f s2)]
=
eval_while_eq_core false cond body f s1; eval_while_eq_core false cond body f s2
let eval_code_eq_t (c:code) (f:fuel) (s1 s2:machine_state) : Lemma
(requires state_eq_S true s1 s2)
(ensures state_eq_opt true (BS.machine_eval_code c f s1) (BS.machine_eval_code c f s2))
[SMTPat (BS.machine_eval_code c f s1); SMTPat (BS.machine_eval_code c f s2)]
=
eval_code_eq_core true c f s1; eval_code_eq_core true c f s2
let eval_codes_eq_t (cs:codes) (f:fuel) (s1 s2:machine_state) : Lemma
(requires state_eq_S true s1 s2)
(ensures state_eq_opt true (BS.machine_eval_codes cs f s1) (BS.machine_eval_codes cs f s2))
[SMTPat (BS.machine_eval_codes cs f s1); SMTPat (BS.machine_eval_codes cs f s2)]
=
eval_codes_eq_core true cs f s1; eval_codes_eq_core true cs f s2
let eval_while_eq_t (cond:ocmp) (body:code) (f:fuel) (s1 s2:machine_state) : Lemma
(requires state_eq_S true s1 s2)
(ensures state_eq_opt true (BS.machine_eval_while cond body f s1) (BS.machine_eval_while cond body f s2))
[SMTPat (BS.machine_eval_while cond body f s1); SMTPat (BS.machine_eval_while cond body f s2)]
=
eval_while_eq_core true cond body f s1; eval_while_eq_core true cond body f s2
let eval_code_ts (g:bool) (c:code) (s0:machine_state) (f0:fuel) (s1:machine_state) : Type0 =
state_eq_opt g (BS.machine_eval_code c f0 s0) (Some s1)
let rec increase_fuel (g:bool) (c:code) (s0:machine_state) (f0:fuel) (sN:machine_state) (fN:fuel) : Lemma
(requires eval_code_ts g c s0 f0 sN /\ f0 <= fN)
(ensures eval_code_ts g c s0 fN sN)
(decreases %[f0; c])
=
match c with
| Ins ins -> ()
| Block l -> increase_fuels g l s0 f0 sN fN
| IfElse cond t f ->
let (s0, b0) = BS.machine_eval_ocmp s0 cond in
if b0 then increase_fuel g t s0 f0 sN fN else increase_fuel g f s0 f0 sN fN
| While cond c ->
let (s1, b0) = BS.machine_eval_ocmp s0 cond in
if b0 then (
match BS.machine_eval_code c (f0 - 1) s1 with
| None -> ()
| Some s2 ->
increase_fuel g c s1 (f0 - 1) s2 (fN - 1);
if s2.BS.ms_ok then increase_fuel g (While cond c) s2 (f0 - 1) sN (fN - 1)
else ()
)
and increase_fuels (g:bool) (c:codes) (s0:machine_state) (f0:fuel) (sN:machine_state) (fN:fuel) : Lemma
(requires eval_code_ts g (Block c) s0 f0 sN /\ f0 <= fN)
(ensures eval_code_ts g (Block c) s0 fN sN)
(decreases %[f0; c])
=
match c with
| [] -> ()
| h::t ->
(
let Some s1 = BS.machine_eval_code h f0 s0 in
increase_fuel g h s0 f0 s1 fN;
increase_fuels g t s1 f0 sN fN
)
let lemma_cmp_eq s o1 o2 = reveal_opaque (`%BS.eval_ocmp_opaque) BS.eval_ocmp_opaque
let lemma_cmp_ne s o1 o2 = reveal_opaque (`%BS.eval_ocmp_opaque) BS.eval_ocmp_opaque
let lemma_cmp_le s o1 o2 = reveal_opaque (`%BS.eval_ocmp_opaque) BS.eval_ocmp_opaque
let lemma_cmp_ge s o1 o2 = reveal_opaque (`%BS.eval_ocmp_opaque) BS.eval_ocmp_opaque
let lemma_cmp_lt s o1 o2 = reveal_opaque (`%BS.eval_ocmp_opaque) BS.eval_ocmp_opaque
let lemma_cmp_gt s o1 o2 = reveal_opaque (`%BS.eval_ocmp_opaque) BS.eval_ocmp_opaque
let lemma_valid_cmp_eq s o1 o2 = ()
let lemma_valid_cmp_ne s o1 o2 = ()
let lemma_valid_cmp_le s o1 o2 = ()
let lemma_valid_cmp_ge s o1 o2 = ()
let lemma_valid_cmp_lt s o1 o2 = ()
let lemma_valid_cmp_gt s o1 o2 = ()
let compute_merge_total (f0:fuel) (fM:fuel) =
if f0 > fM then f0 else fM
let lemma_merge_total (b0:codes) (s0:vale_state) (f0:fuel) (sM:vale_state) (fM:fuel) (sN:vale_state) =
let f = if f0 > fM then f0 else fM in
increase_fuel (codes_modifies_ghost b0) (Cons?.hd b0) (state_to_S s0) f0 (state_to_S sM) f;
increase_fuel (codes_modifies_ghost b0) (Block (Cons?.tl b0)) (state_to_S sM) fM (state_to_S sN) f
let lemma_empty_total (s0:vale_state) (bN:codes) =
(s0, 0)
let lemma_ifElse_total (ifb:ocmp) (ct:code) (cf:code) (s0:vale_state) =
(eval_ocmp s0 ifb, {s0 with vs_flags = havoc_flags}, s0, 0) | false | false | Vale.X64.Lemmas.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": 30,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val lemma_havoc_flags:squash (Flags.to_fun havoc_flags == BS.havoc_flags) | [] | Vale.X64.Lemmas.lemma_havoc_flags | {
"file_name": "vale/code/arch/x64/Vale.X64.Lemmas.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | Prims.squash (Vale.X64.Flags.to_fun Vale.X64.Lemmas.havoc_flags ==
Vale.X64.Machine_Semantics_s.havoc_flags) | {
"end_col": 87,
"end_line": 362,
"start_col": 2,
"start_line": 362
} |
FStar.Pervasives.Lemma | val eval_code_eq_dealloc (inst: BS.ins) (f: fuel) (s1 s2: machine_state)
: Lemma (requires Dealloc? inst /\ state_eq_S true s1 s2)
(ensures
state_eq_opt true
(BS.machine_eval_code (Ins inst) f s1)
(BS.machine_eval_code (Ins inst) f s2)) | [
{
"abbrev": true,
"full_module": "Vale.X64.Memory",
"short_module": "ME"
},
{
"abbrev": true,
"full_module": "Vale.X64.Machine_Semantics_s",
"short_module": "BS"
},
{
"abbrev": false,
"full_module": "Vale.X64.Bytes_Code_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Instruction_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.StateLemmas",
"short_module": null
},
{
"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": "FStar.Mul",
"short_module": null
},
{
"abbrev": true,
"full_module": "Vale.Lib.Map16",
"short_module": "Map16"
},
{
"abbrev": true,
"full_module": "Vale.X64.Machine_Semantics_s",
"short_module": "BS"
},
{
"abbrev": false,
"full_module": "Vale.X64.Bytes_Code_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.StateLemmas",
"short_module": null
},
{
"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.HeapLemmas",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.HeapImpl",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Heap",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"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 eval_code_eq_dealloc (inst:BS.ins) (f:fuel) (s1 s2:machine_state) : Lemma
(requires Dealloc? inst /\ state_eq_S true s1 s2)
(ensures state_eq_opt true (BS.machine_eval_code (Ins inst) f s1) (BS.machine_eval_code (Ins inst) f s2))
=
reveal_opaque (`%BS.machine_eval_code_ins) BS.machine_eval_code_ins;
use_machine_state_equal ();
lemma_heap_ignore_ghost_machine s1.BS.ms_heap s2.BS.ms_heap;
allow_inversion tmaddr | val eval_code_eq_dealloc (inst: BS.ins) (f: fuel) (s1 s2: machine_state)
: Lemma (requires Dealloc? inst /\ state_eq_S true s1 s2)
(ensures
state_eq_opt true
(BS.machine_eval_code (Ins inst) f s1)
(BS.machine_eval_code (Ins inst) f s2))
let eval_code_eq_dealloc (inst: BS.ins) (f: fuel) (s1 s2: machine_state)
: Lemma (requires Dealloc? inst /\ state_eq_S true s1 s2)
(ensures
state_eq_opt true
(BS.machine_eval_code (Ins inst) f s1)
(BS.machine_eval_code (Ins inst) f s2)) = | false | null | true | reveal_opaque (`%BS.machine_eval_code_ins) BS.machine_eval_code_ins;
use_machine_state_equal ();
lemma_heap_ignore_ghost_machine s1.BS.ms_heap s2.BS.ms_heap;
allow_inversion tmaddr | {
"checked_file": "Vale.X64.Lemmas.fst.checked",
"dependencies": [
"Vale.X64.StateLemmas.fsti.checked",
"Vale.X64.State.fsti.checked",
"Vale.X64.Memory.fsti.checked",
"Vale.X64.Machine_Semantics_s.fst.checked",
"Vale.X64.Machine_s.fst.checked",
"Vale.X64.Instruction_s.fsti.checked",
"Vale.X64.Flags.fsti.checked",
"Vale.X64.Bytes_Code_s.fst.checked",
"prims.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.FunctionalExtensionality.fsti.checked"
],
"interface_file": true,
"source_file": "Vale.X64.Lemmas.fst"
} | [
"lemma"
] | [
"Vale.X64.Machine_Semantics_s.ins",
"Vale.X64.Lemmas.fuel",
"Vale.X64.StateLemmas.machine_state",
"FStar.Pervasives.allow_inversion",
"Vale.X64.Machine_s.tmaddr",
"Prims.unit",
"Vale.Arch.HeapLemmas.lemma_heap_ignore_ghost_machine",
"Vale.X64.Machine_Semantics_s.__proj__Mkmachine_state__item__ms_heap",
"Vale.X64.StateLemmas.use_machine_state_equal",
"FStar.Pervasives.reveal_opaque",
"Vale.X64.Machine_Semantics_s.machine_state",
"FStar.Pervasives.Native.option",
"Vale.X64.Machine_Semantics_s.machine_eval_code_ins",
"Prims.l_and",
"Prims.b2t",
"Vale.X64.Bytes_Code_s.uu___is_Dealloc",
"Vale.X64.Machine_Semantics_s.instr_annotation",
"Vale.X64.Lemmas.state_eq_S",
"Prims.squash",
"Vale.X64.Lemmas.state_eq_opt",
"Vale.X64.Machine_Semantics_s.machine_eval_code",
"Vale.X64.Machine_s.Ins",
"Vale.X64.Bytes_Code_s.instruction_t",
"Vale.X64.Bytes_Code_s.ocmp",
"Prims.Nil",
"FStar.Pervasives.pattern"
] | [] | module Vale.X64.Lemmas
open FStar.Mul
open Vale.X64.Machine_s
open Vale.X64.State
open Vale.X64.StateLemmas
open Vale.X64.Instruction_s
open Vale.X64.Bytes_Code_s
module BS = Vale.X64.Machine_Semantics_s
module ME = Vale.X64.Memory
#reset-options "--initial_fuel 1 --max_fuel 1 --z3rlimit 100"
#restart-solver
let rec lemma_eq_instr_apply_eval_args
(outs:list instr_out) (args:list instr_operand)
(f:instr_args_t outs args) (oprs:instr_operands_t_args args) (s1 s2:machine_state)
: Lemma
(requires state_eq_S true s1 s2)
(ensures
BS.instr_apply_eval_args outs args f oprs s1 ==
BS.instr_apply_eval_args outs args f oprs s2)
=
let open BS in
lemma_heap_ignore_ghost_machine s1.BS.ms_heap s2.BS.ms_heap;
match args with
| [] -> ()
| i::args ->
(
let (v, oprs) : option (instr_val_t i) & instr_operands_t_args args =
match i with
| IOpEx i -> let oprs = coerce oprs in (instr_eval_operand_explicit i (fst oprs) s1, snd oprs)
| IOpIm i -> (instr_eval_operand_implicit i s1, coerce oprs)
in
let f:arrow (instr_val_t i) (instr_args_t outs args) = coerce f in
match v with
| None -> ()
| Some v -> lemma_eq_instr_apply_eval_args outs args (f v) oprs s1 s2
)
#restart-solver
let rec lemma_eq_instr_apply_eval_inouts
(outs inouts:list instr_out) (args:list instr_operand)
(f:instr_inouts_t outs inouts args) (oprs:instr_operands_t inouts args) (s1 s2:machine_state)
: Lemma
(requires state_eq_S true s1 s2)
(ensures
BS.instr_apply_eval_inouts outs inouts args f oprs s1 ==
BS.instr_apply_eval_inouts outs inouts args f oprs s2)
=
let open BS in
lemma_heap_ignore_ghost_machine s1.BS.ms_heap s2.BS.ms_heap;
match inouts with
| [] -> lemma_eq_instr_apply_eval_args outs args f oprs s1 s2
| (Out, i)::inouts ->
let oprs =
match i with
| IOpEx i -> snd #(instr_operand_t i) (coerce oprs)
| IOpIm i -> coerce oprs
in
lemma_eq_instr_apply_eval_inouts outs inouts args (coerce f) oprs s1 s2
| (InOut, i)::inouts ->
(
let (v, oprs) : option (instr_val_t i) & instr_operands_t inouts args =
match i with
| IOpEx i -> let oprs = coerce oprs in (instr_eval_operand_explicit i (fst oprs) s1, snd oprs)
| IOpIm i -> (instr_eval_operand_implicit i s1, coerce oprs)
in
let f:arrow (instr_val_t i) (instr_inouts_t outs inouts args) = coerce f in
match v with
| None -> ()
| Some v -> lemma_eq_instr_apply_eval_inouts outs inouts args (f v) oprs s1 s2
)
#restart-solver
#push-options "--z3rlimit_factor 2"
let rec lemma_eq_instr_write_outputs
(outs:list instr_out) (args:list instr_operand)
(vs:instr_ret_t outs) (oprs:instr_operands_t outs args) (s1_orig s1 s2_orig s2:machine_state)
: Lemma
(requires state_eq_S true s1_orig s2_orig /\ state_eq_S true s1 s2)
(ensures
state_eq_S true
(BS.instr_write_outputs outs args vs oprs s1_orig s1)
(BS.instr_write_outputs outs args vs oprs s2_orig s2))
=
let open BS in
use_machine_state_equal ();
lemma_heap_ignore_ghost_machine s1.BS.ms_heap s2.BS.ms_heap;
lemma_heap_ignore_ghost_machine s1_orig.BS.ms_heap s2_orig.BS.ms_heap;
allow_inversion tmaddr;
match outs with
| [] -> ()
| (_, i)::outs ->
(
let ((v:instr_val_t i), (vs:instr_ret_t outs)) =
match outs with
| [] -> (vs, ())
| _::_ -> let vs = coerce vs in (fst vs, snd vs)
in
match i with
| IOpEx i ->
let oprs = coerce oprs in
let s1 = instr_write_output_explicit i v (fst oprs) s1_orig s1 in
let s2 = instr_write_output_explicit i v (fst oprs) s2_orig s2 in
lemma_eq_instr_write_outputs outs args vs (snd oprs) s1_orig s1 s2_orig s2
| IOpIm i ->
let s1 = instr_write_output_implicit i v s1_orig s1 in
let s2 = instr_write_output_implicit i v s2_orig s2 in
allow_inversion operand64;
allow_inversion operand128;
lemma_eq_instr_write_outputs outs args vs (coerce oprs) s1_orig s1 s2_orig s2
)
#pop-options
#restart-solver
let eval_ins_eq_instr (inst:BS.ins) (s1 s2:machine_state) : Lemma
(requires Instr? inst /\ state_eq_S true s1 s2)
(ensures state_eq_S true (BS.machine_eval_ins inst s1) (BS.machine_eval_ins inst s2))
=
let open BS in
let Instr it oprs ann = inst in
let InstrTypeRecord #outs #args #havoc_flags' i = it in
lemma_eq_instr_apply_eval_inouts outs outs args (instr_eval i) oprs s1 s2;
let vs = instr_apply_eval outs args (instr_eval i) oprs s1 in
let hav s =
match havoc_flags' with
| HavocFlags -> {s with ms_flags = havoc_flags}
| PreserveFlags -> s
in
let s1' = hav s1 in
let s2' = hav s2 in
match vs with
| None -> ()
| Some vs -> lemma_eq_instr_write_outputs outs args vs oprs s1 s1' s2 s2'
let eval_code_eq_instr (inst:BS.ins) (f:fuel) (s1 s2:machine_state) : Lemma
(requires Instr? inst /\ state_eq_S true s1 s2)
(ensures state_eq_opt true (BS.machine_eval_code (Ins inst) f s1) (BS.machine_eval_code (Ins inst) f s2))
=
reveal_opaque (`%BS.machine_eval_code_ins) BS.machine_eval_code_ins;
eval_ins_eq_instr inst ({s1 with BS.ms_trace = []}) ({s2 with BS.ms_trace = []})
let eval_code_eq_dealloc (inst:BS.ins) (f:fuel) (s1 s2:machine_state) : Lemma
(requires Dealloc? inst /\ state_eq_S true s1 s2)
(ensures state_eq_opt true (BS.machine_eval_code (Ins inst) f s1) (BS.machine_eval_code (Ins inst) f s2)) | false | false | Vale.X64.Lemmas.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 1,
"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": 100,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val eval_code_eq_dealloc (inst: BS.ins) (f: fuel) (s1 s2: machine_state)
: Lemma (requires Dealloc? inst /\ state_eq_S true s1 s2)
(ensures
state_eq_opt true
(BS.machine_eval_code (Ins inst) f s1)
(BS.machine_eval_code (Ins inst) f s2)) | [] | Vale.X64.Lemmas.eval_code_eq_dealloc | {
"file_name": "vale/code/arch/x64/Vale.X64.Lemmas.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} |
inst: Vale.X64.Machine_Semantics_s.ins ->
f: Vale.X64.Lemmas.fuel ->
s1: Vale.X64.StateLemmas.machine_state ->
s2: Vale.X64.StateLemmas.machine_state
-> FStar.Pervasives.Lemma (requires Dealloc? inst /\ Vale.X64.Lemmas.state_eq_S true s1 s2)
(ensures
Vale.X64.Lemmas.state_eq_opt true
(Vale.X64.Machine_Semantics_s.machine_eval_code (Vale.X64.Machine_s.Ins inst) f s1)
(Vale.X64.Machine_Semantics_s.machine_eval_code (Vale.X64.Machine_s.Ins inst) f s2)) | {
"end_col": 24,
"end_line": 150,
"start_col": 2,
"start_line": 147
} |
FStar.Pervasives.Lemma | val lemma_ifElseFalse_total (ifb:ocmp) (ct:code) (cf:code) (s0:vale_state) (f0:fuel) (sM:vale_state) : Lemma
(requires
valid_ocmp ifb s0 /\
not (eval_ocmp s0 ifb) /\
eval_code cf ({s0 with vs_flags = havoc_flags}) f0 sM
)
(ensures
eval_code (IfElse ifb ct cf) s0 f0 sM
) | [
{
"abbrev": true,
"full_module": "Vale.X64.Memory",
"short_module": "ME"
},
{
"abbrev": false,
"full_module": "Vale.X64.Instruction_s",
"short_module": null
},
{
"abbrev": true,
"full_module": "Vale.Lib.Map16",
"short_module": "Map16"
},
{
"abbrev": true,
"full_module": "Vale.X64.Machine_Semantics_s",
"short_module": "BS"
},
{
"abbrev": false,
"full_module": "Vale.X64.Bytes_Code_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.StateLemmas",
"short_module": null
},
{
"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.HeapLemmas",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.HeapImpl",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Heap",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"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 lemma_ifElseFalse_total (ifb:ocmp) (ct:code) (cf:code) (s0:vale_state) (f0:fuel) (sM:vale_state) =
reveal_opaque (`%BS.valid_ocmp_opaque) BS.valid_ocmp_opaque;
reveal_opaque (`%BS.eval_ocmp_opaque) BS.eval_ocmp_opaque | val lemma_ifElseFalse_total (ifb:ocmp) (ct:code) (cf:code) (s0:vale_state) (f0:fuel) (sM:vale_state) : Lemma
(requires
valid_ocmp ifb s0 /\
not (eval_ocmp s0 ifb) /\
eval_code cf ({s0 with vs_flags = havoc_flags}) f0 sM
)
(ensures
eval_code (IfElse ifb ct cf) s0 f0 sM
)
let lemma_ifElseFalse_total (ifb: ocmp) (ct cf: code) (s0: vale_state) (f0: fuel) (sM: vale_state) = | false | null | true | reveal_opaque (`%BS.valid_ocmp_opaque) BS.valid_ocmp_opaque;
reveal_opaque (`%BS.eval_ocmp_opaque) BS.eval_ocmp_opaque | {
"checked_file": "Vale.X64.Lemmas.fst.checked",
"dependencies": [
"Vale.X64.StateLemmas.fsti.checked",
"Vale.X64.State.fsti.checked",
"Vale.X64.Memory.fsti.checked",
"Vale.X64.Machine_Semantics_s.fst.checked",
"Vale.X64.Machine_s.fst.checked",
"Vale.X64.Instruction_s.fsti.checked",
"Vale.X64.Flags.fsti.checked",
"Vale.X64.Bytes_Code_s.fst.checked",
"prims.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.FunctionalExtensionality.fsti.checked"
],
"interface_file": true,
"source_file": "Vale.X64.Lemmas.fst"
} | [
"lemma"
] | [
"Vale.X64.Bytes_Code_s.ocmp",
"Vale.X64.StateLemmas.code",
"Vale.X64.State.vale_state",
"Vale.X64.Lemmas.fuel",
"FStar.Pervasives.reveal_opaque",
"Vale.X64.Machine_Semantics_s.machine_state",
"Vale.X64.Machine_Semantics_s.ocmp",
"Prims.bool",
"Vale.X64.Machine_Semantics_s.eval_ocmp_opaque",
"Prims.unit",
"Vale.X64.Machine_Semantics_s.valid_ocmp_opaque"
] | [] | module Vale.X64.Lemmas
open FStar.Mul
open Vale.X64.Machine_s
open Vale.X64.State
open Vale.X64.StateLemmas
open Vale.X64.Instruction_s
open Vale.X64.Bytes_Code_s
module BS = Vale.X64.Machine_Semantics_s
module ME = Vale.X64.Memory
#reset-options "--initial_fuel 1 --max_fuel 1 --z3rlimit 100"
#restart-solver
let rec lemma_eq_instr_apply_eval_args
(outs:list instr_out) (args:list instr_operand)
(f:instr_args_t outs args) (oprs:instr_operands_t_args args) (s1 s2:machine_state)
: Lemma
(requires state_eq_S true s1 s2)
(ensures
BS.instr_apply_eval_args outs args f oprs s1 ==
BS.instr_apply_eval_args outs args f oprs s2)
=
let open BS in
lemma_heap_ignore_ghost_machine s1.BS.ms_heap s2.BS.ms_heap;
match args with
| [] -> ()
| i::args ->
(
let (v, oprs) : option (instr_val_t i) & instr_operands_t_args args =
match i with
| IOpEx i -> let oprs = coerce oprs in (instr_eval_operand_explicit i (fst oprs) s1, snd oprs)
| IOpIm i -> (instr_eval_operand_implicit i s1, coerce oprs)
in
let f:arrow (instr_val_t i) (instr_args_t outs args) = coerce f in
match v with
| None -> ()
| Some v -> lemma_eq_instr_apply_eval_args outs args (f v) oprs s1 s2
)
#restart-solver
let rec lemma_eq_instr_apply_eval_inouts
(outs inouts:list instr_out) (args:list instr_operand)
(f:instr_inouts_t outs inouts args) (oprs:instr_operands_t inouts args) (s1 s2:machine_state)
: Lemma
(requires state_eq_S true s1 s2)
(ensures
BS.instr_apply_eval_inouts outs inouts args f oprs s1 ==
BS.instr_apply_eval_inouts outs inouts args f oprs s2)
=
let open BS in
lemma_heap_ignore_ghost_machine s1.BS.ms_heap s2.BS.ms_heap;
match inouts with
| [] -> lemma_eq_instr_apply_eval_args outs args f oprs s1 s2
| (Out, i)::inouts ->
let oprs =
match i with
| IOpEx i -> snd #(instr_operand_t i) (coerce oprs)
| IOpIm i -> coerce oprs
in
lemma_eq_instr_apply_eval_inouts outs inouts args (coerce f) oprs s1 s2
| (InOut, i)::inouts ->
(
let (v, oprs) : option (instr_val_t i) & instr_operands_t inouts args =
match i with
| IOpEx i -> let oprs = coerce oprs in (instr_eval_operand_explicit i (fst oprs) s1, snd oprs)
| IOpIm i -> (instr_eval_operand_implicit i s1, coerce oprs)
in
let f:arrow (instr_val_t i) (instr_inouts_t outs inouts args) = coerce f in
match v with
| None -> ()
| Some v -> lemma_eq_instr_apply_eval_inouts outs inouts args (f v) oprs s1 s2
)
#restart-solver
#push-options "--z3rlimit_factor 2"
let rec lemma_eq_instr_write_outputs
(outs:list instr_out) (args:list instr_operand)
(vs:instr_ret_t outs) (oprs:instr_operands_t outs args) (s1_orig s1 s2_orig s2:machine_state)
: Lemma
(requires state_eq_S true s1_orig s2_orig /\ state_eq_S true s1 s2)
(ensures
state_eq_S true
(BS.instr_write_outputs outs args vs oprs s1_orig s1)
(BS.instr_write_outputs outs args vs oprs s2_orig s2))
=
let open BS in
use_machine_state_equal ();
lemma_heap_ignore_ghost_machine s1.BS.ms_heap s2.BS.ms_heap;
lemma_heap_ignore_ghost_machine s1_orig.BS.ms_heap s2_orig.BS.ms_heap;
allow_inversion tmaddr;
match outs with
| [] -> ()
| (_, i)::outs ->
(
let ((v:instr_val_t i), (vs:instr_ret_t outs)) =
match outs with
| [] -> (vs, ())
| _::_ -> let vs = coerce vs in (fst vs, snd vs)
in
match i with
| IOpEx i ->
let oprs = coerce oprs in
let s1 = instr_write_output_explicit i v (fst oprs) s1_orig s1 in
let s2 = instr_write_output_explicit i v (fst oprs) s2_orig s2 in
lemma_eq_instr_write_outputs outs args vs (snd oprs) s1_orig s1 s2_orig s2
| IOpIm i ->
let s1 = instr_write_output_implicit i v s1_orig s1 in
let s2 = instr_write_output_implicit i v s2_orig s2 in
allow_inversion operand64;
allow_inversion operand128;
lemma_eq_instr_write_outputs outs args vs (coerce oprs) s1_orig s1 s2_orig s2
)
#pop-options
#restart-solver
let eval_ins_eq_instr (inst:BS.ins) (s1 s2:machine_state) : Lemma
(requires Instr? inst /\ state_eq_S true s1 s2)
(ensures state_eq_S true (BS.machine_eval_ins inst s1) (BS.machine_eval_ins inst s2))
=
let open BS in
let Instr it oprs ann = inst in
let InstrTypeRecord #outs #args #havoc_flags' i = it in
lemma_eq_instr_apply_eval_inouts outs outs args (instr_eval i) oprs s1 s2;
let vs = instr_apply_eval outs args (instr_eval i) oprs s1 in
let hav s =
match havoc_flags' with
| HavocFlags -> {s with ms_flags = havoc_flags}
| PreserveFlags -> s
in
let s1' = hav s1 in
let s2' = hav s2 in
match vs with
| None -> ()
| Some vs -> lemma_eq_instr_write_outputs outs args vs oprs s1 s1' s2 s2'
let eval_code_eq_instr (inst:BS.ins) (f:fuel) (s1 s2:machine_state) : Lemma
(requires Instr? inst /\ state_eq_S true s1 s2)
(ensures state_eq_opt true (BS.machine_eval_code (Ins inst) f s1) (BS.machine_eval_code (Ins inst) f s2))
=
reveal_opaque (`%BS.machine_eval_code_ins) BS.machine_eval_code_ins;
eval_ins_eq_instr inst ({s1 with BS.ms_trace = []}) ({s2 with BS.ms_trace = []})
let eval_code_eq_dealloc (inst:BS.ins) (f:fuel) (s1 s2:machine_state) : Lemma
(requires Dealloc? inst /\ state_eq_S true s1 s2)
(ensures state_eq_opt true (BS.machine_eval_code (Ins inst) f s1) (BS.machine_eval_code (Ins inst) f s2))
=
reveal_opaque (`%BS.machine_eval_code_ins) BS.machine_eval_code_ins;
use_machine_state_equal ();
lemma_heap_ignore_ghost_machine s1.BS.ms_heap s2.BS.ms_heap;
allow_inversion tmaddr
let eval_code_eq_alloc (inst:BS.ins) (f:fuel) (s1 s2:machine_state) : Lemma
(requires Alloc? inst /\ state_eq_S true s1 s2)
(ensures state_eq_opt true (BS.machine_eval_code (Ins inst) f s1) (BS.machine_eval_code (Ins inst) f s2))
=
reveal_opaque (`%BS.machine_eval_code_ins) BS.machine_eval_code_ins;
use_machine_state_equal ();
lemma_heap_ignore_ghost_machine s1.BS.ms_heap s2.BS.ms_heap;
allow_inversion tmaddr
let eval_code_eq_push (inst:BS.ins) (f:fuel) (s1 s2:machine_state) : Lemma
(requires Push? inst /\ state_eq_S true s1 s2)
(ensures state_eq_opt true (BS.machine_eval_code (Ins inst) f s1) (BS.machine_eval_code (Ins inst) f s2))
=
reveal_opaque (`%BS.machine_eval_code_ins) BS.machine_eval_code_ins;
use_machine_state_equal ();
lemma_heap_ignore_ghost_machine s1.BS.ms_heap s2.BS.ms_heap;
allow_inversion tmaddr
let eval_code_eq_pop (inst:BS.ins) (f:fuel) (s1 s2:machine_state) : Lemma
(requires Pop? inst /\ state_eq_S true s1 s2)
(ensures state_eq_opt true (BS.machine_eval_code (Ins inst) f s1) (BS.machine_eval_code (Ins inst) f s2))
=
reveal_opaque (`%BS.machine_eval_code_ins) BS.machine_eval_code_ins;
use_machine_state_equal ();
lemma_heap_ignore_ghost_machine s1.BS.ms_heap s2.BS.ms_heap;
allow_inversion tmaddr
let eval_code_eq_ins (i:BS.ins) (f:fuel) (s1 s2:machine_state) : Lemma
(requires state_eq_S true s1 s2)
(ensures state_eq_opt true (BS.machine_eval_code (Ins i) f s1) (BS.machine_eval_code (Ins i) f s2))
=
match i with
| Instr _ _ _ -> eval_code_eq_instr i f s1 s2
| Dealloc _ -> eval_code_eq_dealloc i f s1 s2
| Alloc _ -> eval_code_eq_alloc i f s1 s2
| Push _ _ -> eval_code_eq_push i f s1 s2
| Pop _ _ -> eval_code_eq_pop i f s1 s2
#reset-options "--fuel 2 --z3rlimit 30"
let eval_ocmp_eq_core (g:bool) (cond:ocmp) (s:machine_state) : Lemma
(ensures (
let (s1, b1) = BS.machine_eval_ocmp s cond in
let (s2, b2) = BS.machine_eval_ocmp (core_state g s) cond in
state_eq_S g s1 s2 /\ b1 == b2
))
=
reveal_opaque (`%BS.valid_ocmp_opaque) BS.valid_ocmp_opaque;
reveal_opaque (`%BS.eval_ocmp_opaque) BS.eval_ocmp_opaque;
()
#restart-solver
let rec eval_code_eq_core (g:bool) (c:code) (f:fuel) (s:machine_state) : Lemma
(ensures state_eq_opt g (BS.machine_eval_code c f s) (BS.machine_eval_code c f (core_state g s)))
(decreases %[f; c])
=
match c with
| Ins i ->
reveal_opaque (`%BS.machine_eval_code_ins) BS.machine_eval_code_ins;
if g then eval_code_eq_ins i f s (core_state g s)
| Block cs -> eval_codes_eq_core g cs f s
| IfElse cond ct cf ->
eval_ocmp_eq_core g cond s;
let (s', _) = BS.machine_eval_ocmp s cond in
let (t', _) = BS.machine_eval_ocmp (core_state g s) cond in
eval_code_eq_core g ct f s';
eval_code_eq_core g ct f t';
eval_code_eq_core g cf f s';
eval_code_eq_core g cf f t';
()
| While cond body -> eval_while_eq_core g cond body f s
and eval_codes_eq_core (g:bool) (cs:codes) (f:fuel) (s:machine_state) : Lemma
(ensures state_eq_opt g (BS.machine_eval_codes cs f s) (BS.machine_eval_codes cs f (core_state g s)))
(decreases %[f; cs])
=
match cs with
| [] -> ()
| c'::cs' -> (
eval_code_eq_core g c' f s;
match (machine_eval_code c' f s, machine_eval_code c' f (core_state g s)) with
| (None, None) -> ()
| (Some s', Some t') -> eval_codes_eq_core g cs' f s'; eval_codes_eq_core g cs' f t'
)
and eval_while_eq_core (g:bool) (cond:ocmp) (body:code) (f:fuel) (s:machine_state) : Lemma
(ensures state_eq_opt g (BS.machine_eval_while cond body f s) (BS.machine_eval_while cond body f (core_state g s)))
(decreases %[f; body])
=
if f > 0 then (
eval_ocmp_eq_core g cond s;
let (s1, _) = BS.machine_eval_ocmp s cond in
let (t1, _) = BS.machine_eval_ocmp (core_state g s) cond in
eval_code_eq_core g body (f - 1) s1;
eval_code_eq_core g body (f - 1) t1;
match (BS.machine_eval_code body (f - 1) s1, BS.machine_eval_code body (f - 1) t1) with
| (None, None) -> ()
| (Some s2, Some t2) ->
eval_while_eq_core g cond body (f - 1) s2;
eval_while_eq_core g cond body (f - 1) t2;
()
)
let eval_code_eq_f (c:code) (f:fuel) (s1 s2:machine_state) : Lemma
(requires state_eq_S false s1 s2)
(ensures state_eq_opt false (BS.machine_eval_code c f s1) (BS.machine_eval_code c f s2))
[SMTPat (BS.machine_eval_code c f s1); SMTPat (BS.machine_eval_code c f s2)]
=
eval_code_eq_core false c f s1; eval_code_eq_core false c f s2
let eval_codes_eq_f (cs:codes) (f:fuel) (s1 s2:machine_state) : Lemma
(requires state_eq_S false s1 s2)
(ensures state_eq_opt false (BS.machine_eval_codes cs f s1) (BS.machine_eval_codes cs f s2))
[SMTPat (BS.machine_eval_codes cs f s1); SMTPat (BS.machine_eval_codes cs f s2)]
=
eval_codes_eq_core false cs f s1; eval_codes_eq_core false cs f s2
let eval_while_eq_f (cond:ocmp) (body:code) (f:fuel) (s1 s2:machine_state) : Lemma
(requires state_eq_S false s1 s2)
(ensures state_eq_opt false (BS.machine_eval_while cond body f s1) (BS.machine_eval_while cond body f s2))
[SMTPat (BS.machine_eval_while cond body f s1); SMTPat (BS.machine_eval_while cond body f s2)]
=
eval_while_eq_core false cond body f s1; eval_while_eq_core false cond body f s2
let eval_code_eq_t (c:code) (f:fuel) (s1 s2:machine_state) : Lemma
(requires state_eq_S true s1 s2)
(ensures state_eq_opt true (BS.machine_eval_code c f s1) (BS.machine_eval_code c f s2))
[SMTPat (BS.machine_eval_code c f s1); SMTPat (BS.machine_eval_code c f s2)]
=
eval_code_eq_core true c f s1; eval_code_eq_core true c f s2
let eval_codes_eq_t (cs:codes) (f:fuel) (s1 s2:machine_state) : Lemma
(requires state_eq_S true s1 s2)
(ensures state_eq_opt true (BS.machine_eval_codes cs f s1) (BS.machine_eval_codes cs f s2))
[SMTPat (BS.machine_eval_codes cs f s1); SMTPat (BS.machine_eval_codes cs f s2)]
=
eval_codes_eq_core true cs f s1; eval_codes_eq_core true cs f s2
let eval_while_eq_t (cond:ocmp) (body:code) (f:fuel) (s1 s2:machine_state) : Lemma
(requires state_eq_S true s1 s2)
(ensures state_eq_opt true (BS.machine_eval_while cond body f s1) (BS.machine_eval_while cond body f s2))
[SMTPat (BS.machine_eval_while cond body f s1); SMTPat (BS.machine_eval_while cond body f s2)]
=
eval_while_eq_core true cond body f s1; eval_while_eq_core true cond body f s2
let eval_code_ts (g:bool) (c:code) (s0:machine_state) (f0:fuel) (s1:machine_state) : Type0 =
state_eq_opt g (BS.machine_eval_code c f0 s0) (Some s1)
let rec increase_fuel (g:bool) (c:code) (s0:machine_state) (f0:fuel) (sN:machine_state) (fN:fuel) : Lemma
(requires eval_code_ts g c s0 f0 sN /\ f0 <= fN)
(ensures eval_code_ts g c s0 fN sN)
(decreases %[f0; c])
=
match c with
| Ins ins -> ()
| Block l -> increase_fuels g l s0 f0 sN fN
| IfElse cond t f ->
let (s0, b0) = BS.machine_eval_ocmp s0 cond in
if b0 then increase_fuel g t s0 f0 sN fN else increase_fuel g f s0 f0 sN fN
| While cond c ->
let (s1, b0) = BS.machine_eval_ocmp s0 cond in
if b0 then (
match BS.machine_eval_code c (f0 - 1) s1 with
| None -> ()
| Some s2 ->
increase_fuel g c s1 (f0 - 1) s2 (fN - 1);
if s2.BS.ms_ok then increase_fuel g (While cond c) s2 (f0 - 1) sN (fN - 1)
else ()
)
and increase_fuels (g:bool) (c:codes) (s0:machine_state) (f0:fuel) (sN:machine_state) (fN:fuel) : Lemma
(requires eval_code_ts g (Block c) s0 f0 sN /\ f0 <= fN)
(ensures eval_code_ts g (Block c) s0 fN sN)
(decreases %[f0; c])
=
match c with
| [] -> ()
| h::t ->
(
let Some s1 = BS.machine_eval_code h f0 s0 in
increase_fuel g h s0 f0 s1 fN;
increase_fuels g t s1 f0 sN fN
)
let lemma_cmp_eq s o1 o2 = reveal_opaque (`%BS.eval_ocmp_opaque) BS.eval_ocmp_opaque
let lemma_cmp_ne s o1 o2 = reveal_opaque (`%BS.eval_ocmp_opaque) BS.eval_ocmp_opaque
let lemma_cmp_le s o1 o2 = reveal_opaque (`%BS.eval_ocmp_opaque) BS.eval_ocmp_opaque
let lemma_cmp_ge s o1 o2 = reveal_opaque (`%BS.eval_ocmp_opaque) BS.eval_ocmp_opaque
let lemma_cmp_lt s o1 o2 = reveal_opaque (`%BS.eval_ocmp_opaque) BS.eval_ocmp_opaque
let lemma_cmp_gt s o1 o2 = reveal_opaque (`%BS.eval_ocmp_opaque) BS.eval_ocmp_opaque
let lemma_valid_cmp_eq s o1 o2 = ()
let lemma_valid_cmp_ne s o1 o2 = ()
let lemma_valid_cmp_le s o1 o2 = ()
let lemma_valid_cmp_ge s o1 o2 = ()
let lemma_valid_cmp_lt s o1 o2 = ()
let lemma_valid_cmp_gt s o1 o2 = ()
let compute_merge_total (f0:fuel) (fM:fuel) =
if f0 > fM then f0 else fM
let lemma_merge_total (b0:codes) (s0:vale_state) (f0:fuel) (sM:vale_state) (fM:fuel) (sN:vale_state) =
let f = if f0 > fM then f0 else fM in
increase_fuel (codes_modifies_ghost b0) (Cons?.hd b0) (state_to_S s0) f0 (state_to_S sM) f;
increase_fuel (codes_modifies_ghost b0) (Block (Cons?.tl b0)) (state_to_S sM) fM (state_to_S sN) f
let lemma_empty_total (s0:vale_state) (bN:codes) =
(s0, 0)
let lemma_ifElse_total (ifb:ocmp) (ct:code) (cf:code) (s0:vale_state) =
(eval_ocmp s0 ifb, {s0 with vs_flags = havoc_flags}, s0, 0)
let lemma_havoc_flags : squash (Flags.to_fun havoc_flags == BS.havoc_flags) =
assert (FStar.FunctionalExtensionality.feq (Flags.to_fun havoc_flags) BS.havoc_flags)
let lemma_ifElseTrue_total (ifb:ocmp) (ct:code) (cf:code) (s0:vale_state) (f0:fuel) (sM:vale_state) =
reveal_opaque (`%BS.valid_ocmp_opaque) BS.valid_ocmp_opaque;
reveal_opaque (`%BS.eval_ocmp_opaque) BS.eval_ocmp_opaque | false | false | Vale.X64.Lemmas.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": 30,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val lemma_ifElseFalse_total (ifb:ocmp) (ct:code) (cf:code) (s0:vale_state) (f0:fuel) (sM:vale_state) : Lemma
(requires
valid_ocmp ifb s0 /\
not (eval_ocmp s0 ifb) /\
eval_code cf ({s0 with vs_flags = havoc_flags}) f0 sM
)
(ensures
eval_code (IfElse ifb ct cf) s0 f0 sM
) | [] | Vale.X64.Lemmas.lemma_ifElseFalse_total | {
"file_name": "vale/code/arch/x64/Vale.X64.Lemmas.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} |
ifb: Vale.X64.Bytes_Code_s.ocmp ->
ct: Vale.X64.StateLemmas.code ->
cf: Vale.X64.StateLemmas.code ->
s0: Vale.X64.State.vale_state ->
f0: Vale.X64.Lemmas.fuel ->
sM: Vale.X64.State.vale_state
-> FStar.Pervasives.Lemma
(requires
Vale.X64.Lemmas.valid_ocmp ifb s0 /\ Prims.op_Negation (Vale.X64.Lemmas.eval_ocmp s0 ifb) /\
Vale.X64.Lemmas.eval_code cf
(Vale.X64.State.Mkvale_state (Mkvale_state?.vs_ok s0)
(Mkvale_state?.vs_regs s0)
Vale.X64.Lemmas.havoc_flags
(Mkvale_state?.vs_heap s0)
(Mkvale_state?.vs_stack s0)
(Mkvale_state?.vs_stackTaint s0))
f0
sM) (ensures Vale.X64.Lemmas.eval_code (Vale.X64.Machine_s.IfElse ifb ct cf) s0 f0 sM) | {
"end_col": 59,
"end_line": 370,
"start_col": 2,
"start_line": 369
} |
Prims.Ghost | val lemma_whileFalse_total (b:ocmp) (c:code) (s0:vale_state) (sW:vale_state) (fW:fuel) : Ghost (vale_state & fuel)
(requires
valid_ocmp b sW /\
not (eval_ocmp sW b) /\
eval_while_inv (While b c) s0 fW sW
)
(ensures fun (s1, f1) ->
s1 == {sW with vs_flags = havoc_flags} /\
eval_code (While b c) s0 f1 s1
) | [
{
"abbrev": true,
"full_module": "Vale.X64.Memory",
"short_module": "ME"
},
{
"abbrev": false,
"full_module": "Vale.X64.Instruction_s",
"short_module": null
},
{
"abbrev": true,
"full_module": "Vale.Lib.Map16",
"short_module": "Map16"
},
{
"abbrev": true,
"full_module": "Vale.X64.Machine_Semantics_s",
"short_module": "BS"
},
{
"abbrev": false,
"full_module": "Vale.X64.Bytes_Code_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.StateLemmas",
"short_module": null
},
{
"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.HeapLemmas",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.HeapImpl",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Heap",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"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 lemma_whileFalse_total (b:ocmp) (c:code) (s0:vale_state) (sW:vale_state) (fW:fuel) =
reveal_opaque (`%BS.valid_ocmp_opaque) BS.valid_ocmp_opaque;
reveal_opaque (`%BS.eval_ocmp_opaque) BS.eval_ocmp_opaque;
let f1 = fW + 1 in
let s1 = {sW with vs_flags = havoc_flags} in
assert (state_eq_opt (code_modifies_ghost c) (BS.machine_eval_code (While b c) f1 (state_to_S s0)) (BS.machine_eval_code (While b c) 1 (state_to_S sW)));
assert (eval_code (While b c) s0 f1 s1);
(s1, f1) | val lemma_whileFalse_total (b:ocmp) (c:code) (s0:vale_state) (sW:vale_state) (fW:fuel) : Ghost (vale_state & fuel)
(requires
valid_ocmp b sW /\
not (eval_ocmp sW b) /\
eval_while_inv (While b c) s0 fW sW
)
(ensures fun (s1, f1) ->
s1 == {sW with vs_flags = havoc_flags} /\
eval_code (While b c) s0 f1 s1
)
let lemma_whileFalse_total (b: ocmp) (c: code) (s0 sW: vale_state) (fW: fuel) = | false | null | false | reveal_opaque (`%BS.valid_ocmp_opaque) BS.valid_ocmp_opaque;
reveal_opaque (`%BS.eval_ocmp_opaque) BS.eval_ocmp_opaque;
let f1 = fW + 1 in
let s1 = { sW with vs_flags = havoc_flags } in
assert (state_eq_opt (code_modifies_ghost c)
(BS.machine_eval_code (While b c) f1 (state_to_S s0))
(BS.machine_eval_code (While b c) 1 (state_to_S sW)));
assert (eval_code (While b c) s0 f1 s1);
(s1, f1) | {
"checked_file": "Vale.X64.Lemmas.fst.checked",
"dependencies": [
"Vale.X64.StateLemmas.fsti.checked",
"Vale.X64.State.fsti.checked",
"Vale.X64.Memory.fsti.checked",
"Vale.X64.Machine_Semantics_s.fst.checked",
"Vale.X64.Machine_s.fst.checked",
"Vale.X64.Instruction_s.fsti.checked",
"Vale.X64.Flags.fsti.checked",
"Vale.X64.Bytes_Code_s.fst.checked",
"prims.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.FunctionalExtensionality.fsti.checked"
],
"interface_file": true,
"source_file": "Vale.X64.Lemmas.fst"
} | [] | [
"Vale.X64.Bytes_Code_s.ocmp",
"Vale.X64.StateLemmas.code",
"Vale.X64.State.vale_state",
"Vale.X64.Lemmas.fuel",
"FStar.Pervasives.Native.Mktuple2",
"Prims.unit",
"Prims._assert",
"Vale.X64.Lemmas.eval_code",
"Vale.X64.Machine_s.While",
"Vale.X64.Bytes_Code_s.instruction_t",
"Vale.X64.Machine_Semantics_s.instr_annotation",
"Vale.X64.Lemmas.state_eq_opt",
"Vale.X64.Lemmas.code_modifies_ghost",
"Vale.X64.Machine_Semantics_s.machine_eval_code",
"Vale.X64.StateLemmas.state_to_S",
"Vale.X64.State.Mkvale_state",
"Vale.X64.State.__proj__Mkvale_state__item__vs_ok",
"Vale.X64.State.__proj__Mkvale_state__item__vs_regs",
"Vale.X64.Lemmas.havoc_flags",
"Vale.X64.State.__proj__Mkvale_state__item__vs_heap",
"Vale.X64.State.__proj__Mkvale_state__item__vs_stack",
"Vale.X64.State.__proj__Mkvale_state__item__vs_stackTaint",
"Prims.int",
"Prims.op_Addition",
"FStar.Pervasives.reveal_opaque",
"Vale.X64.Machine_Semantics_s.machine_state",
"Vale.X64.Machine_Semantics_s.ocmp",
"Prims.bool",
"Vale.X64.Machine_Semantics_s.eval_ocmp_opaque",
"Vale.X64.Machine_Semantics_s.valid_ocmp_opaque",
"FStar.Pervasives.Native.tuple2"
] | [] | module Vale.X64.Lemmas
open FStar.Mul
open Vale.X64.Machine_s
open Vale.X64.State
open Vale.X64.StateLemmas
open Vale.X64.Instruction_s
open Vale.X64.Bytes_Code_s
module BS = Vale.X64.Machine_Semantics_s
module ME = Vale.X64.Memory
#reset-options "--initial_fuel 1 --max_fuel 1 --z3rlimit 100"
#restart-solver
let rec lemma_eq_instr_apply_eval_args
(outs:list instr_out) (args:list instr_operand)
(f:instr_args_t outs args) (oprs:instr_operands_t_args args) (s1 s2:machine_state)
: Lemma
(requires state_eq_S true s1 s2)
(ensures
BS.instr_apply_eval_args outs args f oprs s1 ==
BS.instr_apply_eval_args outs args f oprs s2)
=
let open BS in
lemma_heap_ignore_ghost_machine s1.BS.ms_heap s2.BS.ms_heap;
match args with
| [] -> ()
| i::args ->
(
let (v, oprs) : option (instr_val_t i) & instr_operands_t_args args =
match i with
| IOpEx i -> let oprs = coerce oprs in (instr_eval_operand_explicit i (fst oprs) s1, snd oprs)
| IOpIm i -> (instr_eval_operand_implicit i s1, coerce oprs)
in
let f:arrow (instr_val_t i) (instr_args_t outs args) = coerce f in
match v with
| None -> ()
| Some v -> lemma_eq_instr_apply_eval_args outs args (f v) oprs s1 s2
)
#restart-solver
let rec lemma_eq_instr_apply_eval_inouts
(outs inouts:list instr_out) (args:list instr_operand)
(f:instr_inouts_t outs inouts args) (oprs:instr_operands_t inouts args) (s1 s2:machine_state)
: Lemma
(requires state_eq_S true s1 s2)
(ensures
BS.instr_apply_eval_inouts outs inouts args f oprs s1 ==
BS.instr_apply_eval_inouts outs inouts args f oprs s2)
=
let open BS in
lemma_heap_ignore_ghost_machine s1.BS.ms_heap s2.BS.ms_heap;
match inouts with
| [] -> lemma_eq_instr_apply_eval_args outs args f oprs s1 s2
| (Out, i)::inouts ->
let oprs =
match i with
| IOpEx i -> snd #(instr_operand_t i) (coerce oprs)
| IOpIm i -> coerce oprs
in
lemma_eq_instr_apply_eval_inouts outs inouts args (coerce f) oprs s1 s2
| (InOut, i)::inouts ->
(
let (v, oprs) : option (instr_val_t i) & instr_operands_t inouts args =
match i with
| IOpEx i -> let oprs = coerce oprs in (instr_eval_operand_explicit i (fst oprs) s1, snd oprs)
| IOpIm i -> (instr_eval_operand_implicit i s1, coerce oprs)
in
let f:arrow (instr_val_t i) (instr_inouts_t outs inouts args) = coerce f in
match v with
| None -> ()
| Some v -> lemma_eq_instr_apply_eval_inouts outs inouts args (f v) oprs s1 s2
)
#restart-solver
#push-options "--z3rlimit_factor 2"
let rec lemma_eq_instr_write_outputs
(outs:list instr_out) (args:list instr_operand)
(vs:instr_ret_t outs) (oprs:instr_operands_t outs args) (s1_orig s1 s2_orig s2:machine_state)
: Lemma
(requires state_eq_S true s1_orig s2_orig /\ state_eq_S true s1 s2)
(ensures
state_eq_S true
(BS.instr_write_outputs outs args vs oprs s1_orig s1)
(BS.instr_write_outputs outs args vs oprs s2_orig s2))
=
let open BS in
use_machine_state_equal ();
lemma_heap_ignore_ghost_machine s1.BS.ms_heap s2.BS.ms_heap;
lemma_heap_ignore_ghost_machine s1_orig.BS.ms_heap s2_orig.BS.ms_heap;
allow_inversion tmaddr;
match outs with
| [] -> ()
| (_, i)::outs ->
(
let ((v:instr_val_t i), (vs:instr_ret_t outs)) =
match outs with
| [] -> (vs, ())
| _::_ -> let vs = coerce vs in (fst vs, snd vs)
in
match i with
| IOpEx i ->
let oprs = coerce oprs in
let s1 = instr_write_output_explicit i v (fst oprs) s1_orig s1 in
let s2 = instr_write_output_explicit i v (fst oprs) s2_orig s2 in
lemma_eq_instr_write_outputs outs args vs (snd oprs) s1_orig s1 s2_orig s2
| IOpIm i ->
let s1 = instr_write_output_implicit i v s1_orig s1 in
let s2 = instr_write_output_implicit i v s2_orig s2 in
allow_inversion operand64;
allow_inversion operand128;
lemma_eq_instr_write_outputs outs args vs (coerce oprs) s1_orig s1 s2_orig s2
)
#pop-options
#restart-solver
let eval_ins_eq_instr (inst:BS.ins) (s1 s2:machine_state) : Lemma
(requires Instr? inst /\ state_eq_S true s1 s2)
(ensures state_eq_S true (BS.machine_eval_ins inst s1) (BS.machine_eval_ins inst s2))
=
let open BS in
let Instr it oprs ann = inst in
let InstrTypeRecord #outs #args #havoc_flags' i = it in
lemma_eq_instr_apply_eval_inouts outs outs args (instr_eval i) oprs s1 s2;
let vs = instr_apply_eval outs args (instr_eval i) oprs s1 in
let hav s =
match havoc_flags' with
| HavocFlags -> {s with ms_flags = havoc_flags}
| PreserveFlags -> s
in
let s1' = hav s1 in
let s2' = hav s2 in
match vs with
| None -> ()
| Some vs -> lemma_eq_instr_write_outputs outs args vs oprs s1 s1' s2 s2'
let eval_code_eq_instr (inst:BS.ins) (f:fuel) (s1 s2:machine_state) : Lemma
(requires Instr? inst /\ state_eq_S true s1 s2)
(ensures state_eq_opt true (BS.machine_eval_code (Ins inst) f s1) (BS.machine_eval_code (Ins inst) f s2))
=
reveal_opaque (`%BS.machine_eval_code_ins) BS.machine_eval_code_ins;
eval_ins_eq_instr inst ({s1 with BS.ms_trace = []}) ({s2 with BS.ms_trace = []})
let eval_code_eq_dealloc (inst:BS.ins) (f:fuel) (s1 s2:machine_state) : Lemma
(requires Dealloc? inst /\ state_eq_S true s1 s2)
(ensures state_eq_opt true (BS.machine_eval_code (Ins inst) f s1) (BS.machine_eval_code (Ins inst) f s2))
=
reveal_opaque (`%BS.machine_eval_code_ins) BS.machine_eval_code_ins;
use_machine_state_equal ();
lemma_heap_ignore_ghost_machine s1.BS.ms_heap s2.BS.ms_heap;
allow_inversion tmaddr
let eval_code_eq_alloc (inst:BS.ins) (f:fuel) (s1 s2:machine_state) : Lemma
(requires Alloc? inst /\ state_eq_S true s1 s2)
(ensures state_eq_opt true (BS.machine_eval_code (Ins inst) f s1) (BS.machine_eval_code (Ins inst) f s2))
=
reveal_opaque (`%BS.machine_eval_code_ins) BS.machine_eval_code_ins;
use_machine_state_equal ();
lemma_heap_ignore_ghost_machine s1.BS.ms_heap s2.BS.ms_heap;
allow_inversion tmaddr
let eval_code_eq_push (inst:BS.ins) (f:fuel) (s1 s2:machine_state) : Lemma
(requires Push? inst /\ state_eq_S true s1 s2)
(ensures state_eq_opt true (BS.machine_eval_code (Ins inst) f s1) (BS.machine_eval_code (Ins inst) f s2))
=
reveal_opaque (`%BS.machine_eval_code_ins) BS.machine_eval_code_ins;
use_machine_state_equal ();
lemma_heap_ignore_ghost_machine s1.BS.ms_heap s2.BS.ms_heap;
allow_inversion tmaddr
let eval_code_eq_pop (inst:BS.ins) (f:fuel) (s1 s2:machine_state) : Lemma
(requires Pop? inst /\ state_eq_S true s1 s2)
(ensures state_eq_opt true (BS.machine_eval_code (Ins inst) f s1) (BS.machine_eval_code (Ins inst) f s2))
=
reveal_opaque (`%BS.machine_eval_code_ins) BS.machine_eval_code_ins;
use_machine_state_equal ();
lemma_heap_ignore_ghost_machine s1.BS.ms_heap s2.BS.ms_heap;
allow_inversion tmaddr
let eval_code_eq_ins (i:BS.ins) (f:fuel) (s1 s2:machine_state) : Lemma
(requires state_eq_S true s1 s2)
(ensures state_eq_opt true (BS.machine_eval_code (Ins i) f s1) (BS.machine_eval_code (Ins i) f s2))
=
match i with
| Instr _ _ _ -> eval_code_eq_instr i f s1 s2
| Dealloc _ -> eval_code_eq_dealloc i f s1 s2
| Alloc _ -> eval_code_eq_alloc i f s1 s2
| Push _ _ -> eval_code_eq_push i f s1 s2
| Pop _ _ -> eval_code_eq_pop i f s1 s2
#reset-options "--fuel 2 --z3rlimit 30"
let eval_ocmp_eq_core (g:bool) (cond:ocmp) (s:machine_state) : Lemma
(ensures (
let (s1, b1) = BS.machine_eval_ocmp s cond in
let (s2, b2) = BS.machine_eval_ocmp (core_state g s) cond in
state_eq_S g s1 s2 /\ b1 == b2
))
=
reveal_opaque (`%BS.valid_ocmp_opaque) BS.valid_ocmp_opaque;
reveal_opaque (`%BS.eval_ocmp_opaque) BS.eval_ocmp_opaque;
()
#restart-solver
let rec eval_code_eq_core (g:bool) (c:code) (f:fuel) (s:machine_state) : Lemma
(ensures state_eq_opt g (BS.machine_eval_code c f s) (BS.machine_eval_code c f (core_state g s)))
(decreases %[f; c])
=
match c with
| Ins i ->
reveal_opaque (`%BS.machine_eval_code_ins) BS.machine_eval_code_ins;
if g then eval_code_eq_ins i f s (core_state g s)
| Block cs -> eval_codes_eq_core g cs f s
| IfElse cond ct cf ->
eval_ocmp_eq_core g cond s;
let (s', _) = BS.machine_eval_ocmp s cond in
let (t', _) = BS.machine_eval_ocmp (core_state g s) cond in
eval_code_eq_core g ct f s';
eval_code_eq_core g ct f t';
eval_code_eq_core g cf f s';
eval_code_eq_core g cf f t';
()
| While cond body -> eval_while_eq_core g cond body f s
and eval_codes_eq_core (g:bool) (cs:codes) (f:fuel) (s:machine_state) : Lemma
(ensures state_eq_opt g (BS.machine_eval_codes cs f s) (BS.machine_eval_codes cs f (core_state g s)))
(decreases %[f; cs])
=
match cs with
| [] -> ()
| c'::cs' -> (
eval_code_eq_core g c' f s;
match (machine_eval_code c' f s, machine_eval_code c' f (core_state g s)) with
| (None, None) -> ()
| (Some s', Some t') -> eval_codes_eq_core g cs' f s'; eval_codes_eq_core g cs' f t'
)
and eval_while_eq_core (g:bool) (cond:ocmp) (body:code) (f:fuel) (s:machine_state) : Lemma
(ensures state_eq_opt g (BS.machine_eval_while cond body f s) (BS.machine_eval_while cond body f (core_state g s)))
(decreases %[f; body])
=
if f > 0 then (
eval_ocmp_eq_core g cond s;
let (s1, _) = BS.machine_eval_ocmp s cond in
let (t1, _) = BS.machine_eval_ocmp (core_state g s) cond in
eval_code_eq_core g body (f - 1) s1;
eval_code_eq_core g body (f - 1) t1;
match (BS.machine_eval_code body (f - 1) s1, BS.machine_eval_code body (f - 1) t1) with
| (None, None) -> ()
| (Some s2, Some t2) ->
eval_while_eq_core g cond body (f - 1) s2;
eval_while_eq_core g cond body (f - 1) t2;
()
)
let eval_code_eq_f (c:code) (f:fuel) (s1 s2:machine_state) : Lemma
(requires state_eq_S false s1 s2)
(ensures state_eq_opt false (BS.machine_eval_code c f s1) (BS.machine_eval_code c f s2))
[SMTPat (BS.machine_eval_code c f s1); SMTPat (BS.machine_eval_code c f s2)]
=
eval_code_eq_core false c f s1; eval_code_eq_core false c f s2
let eval_codes_eq_f (cs:codes) (f:fuel) (s1 s2:machine_state) : Lemma
(requires state_eq_S false s1 s2)
(ensures state_eq_opt false (BS.machine_eval_codes cs f s1) (BS.machine_eval_codes cs f s2))
[SMTPat (BS.machine_eval_codes cs f s1); SMTPat (BS.machine_eval_codes cs f s2)]
=
eval_codes_eq_core false cs f s1; eval_codes_eq_core false cs f s2
let eval_while_eq_f (cond:ocmp) (body:code) (f:fuel) (s1 s2:machine_state) : Lemma
(requires state_eq_S false s1 s2)
(ensures state_eq_opt false (BS.machine_eval_while cond body f s1) (BS.machine_eval_while cond body f s2))
[SMTPat (BS.machine_eval_while cond body f s1); SMTPat (BS.machine_eval_while cond body f s2)]
=
eval_while_eq_core false cond body f s1; eval_while_eq_core false cond body f s2
let eval_code_eq_t (c:code) (f:fuel) (s1 s2:machine_state) : Lemma
(requires state_eq_S true s1 s2)
(ensures state_eq_opt true (BS.machine_eval_code c f s1) (BS.machine_eval_code c f s2))
[SMTPat (BS.machine_eval_code c f s1); SMTPat (BS.machine_eval_code c f s2)]
=
eval_code_eq_core true c f s1; eval_code_eq_core true c f s2
let eval_codes_eq_t (cs:codes) (f:fuel) (s1 s2:machine_state) : Lemma
(requires state_eq_S true s1 s2)
(ensures state_eq_opt true (BS.machine_eval_codes cs f s1) (BS.machine_eval_codes cs f s2))
[SMTPat (BS.machine_eval_codes cs f s1); SMTPat (BS.machine_eval_codes cs f s2)]
=
eval_codes_eq_core true cs f s1; eval_codes_eq_core true cs f s2
let eval_while_eq_t (cond:ocmp) (body:code) (f:fuel) (s1 s2:machine_state) : Lemma
(requires state_eq_S true s1 s2)
(ensures state_eq_opt true (BS.machine_eval_while cond body f s1) (BS.machine_eval_while cond body f s2))
[SMTPat (BS.machine_eval_while cond body f s1); SMTPat (BS.machine_eval_while cond body f s2)]
=
eval_while_eq_core true cond body f s1; eval_while_eq_core true cond body f s2
let eval_code_ts (g:bool) (c:code) (s0:machine_state) (f0:fuel) (s1:machine_state) : Type0 =
state_eq_opt g (BS.machine_eval_code c f0 s0) (Some s1)
let rec increase_fuel (g:bool) (c:code) (s0:machine_state) (f0:fuel) (sN:machine_state) (fN:fuel) : Lemma
(requires eval_code_ts g c s0 f0 sN /\ f0 <= fN)
(ensures eval_code_ts g c s0 fN sN)
(decreases %[f0; c])
=
match c with
| Ins ins -> ()
| Block l -> increase_fuels g l s0 f0 sN fN
| IfElse cond t f ->
let (s0, b0) = BS.machine_eval_ocmp s0 cond in
if b0 then increase_fuel g t s0 f0 sN fN else increase_fuel g f s0 f0 sN fN
| While cond c ->
let (s1, b0) = BS.machine_eval_ocmp s0 cond in
if b0 then (
match BS.machine_eval_code c (f0 - 1) s1 with
| None -> ()
| Some s2 ->
increase_fuel g c s1 (f0 - 1) s2 (fN - 1);
if s2.BS.ms_ok then increase_fuel g (While cond c) s2 (f0 - 1) sN (fN - 1)
else ()
)
and increase_fuels (g:bool) (c:codes) (s0:machine_state) (f0:fuel) (sN:machine_state) (fN:fuel) : Lemma
(requires eval_code_ts g (Block c) s0 f0 sN /\ f0 <= fN)
(ensures eval_code_ts g (Block c) s0 fN sN)
(decreases %[f0; c])
=
match c with
| [] -> ()
| h::t ->
(
let Some s1 = BS.machine_eval_code h f0 s0 in
increase_fuel g h s0 f0 s1 fN;
increase_fuels g t s1 f0 sN fN
)
let lemma_cmp_eq s o1 o2 = reveal_opaque (`%BS.eval_ocmp_opaque) BS.eval_ocmp_opaque
let lemma_cmp_ne s o1 o2 = reveal_opaque (`%BS.eval_ocmp_opaque) BS.eval_ocmp_opaque
let lemma_cmp_le s o1 o2 = reveal_opaque (`%BS.eval_ocmp_opaque) BS.eval_ocmp_opaque
let lemma_cmp_ge s o1 o2 = reveal_opaque (`%BS.eval_ocmp_opaque) BS.eval_ocmp_opaque
let lemma_cmp_lt s o1 o2 = reveal_opaque (`%BS.eval_ocmp_opaque) BS.eval_ocmp_opaque
let lemma_cmp_gt s o1 o2 = reveal_opaque (`%BS.eval_ocmp_opaque) BS.eval_ocmp_opaque
let lemma_valid_cmp_eq s o1 o2 = ()
let lemma_valid_cmp_ne s o1 o2 = ()
let lemma_valid_cmp_le s o1 o2 = ()
let lemma_valid_cmp_ge s o1 o2 = ()
let lemma_valid_cmp_lt s o1 o2 = ()
let lemma_valid_cmp_gt s o1 o2 = ()
let compute_merge_total (f0:fuel) (fM:fuel) =
if f0 > fM then f0 else fM
let lemma_merge_total (b0:codes) (s0:vale_state) (f0:fuel) (sM:vale_state) (fM:fuel) (sN:vale_state) =
let f = if f0 > fM then f0 else fM in
increase_fuel (codes_modifies_ghost b0) (Cons?.hd b0) (state_to_S s0) f0 (state_to_S sM) f;
increase_fuel (codes_modifies_ghost b0) (Block (Cons?.tl b0)) (state_to_S sM) fM (state_to_S sN) f
let lemma_empty_total (s0:vale_state) (bN:codes) =
(s0, 0)
let lemma_ifElse_total (ifb:ocmp) (ct:code) (cf:code) (s0:vale_state) =
(eval_ocmp s0 ifb, {s0 with vs_flags = havoc_flags}, s0, 0)
let lemma_havoc_flags : squash (Flags.to_fun havoc_flags == BS.havoc_flags) =
assert (FStar.FunctionalExtensionality.feq (Flags.to_fun havoc_flags) BS.havoc_flags)
let lemma_ifElseTrue_total (ifb:ocmp) (ct:code) (cf:code) (s0:vale_state) (f0:fuel) (sM:vale_state) =
reveal_opaque (`%BS.valid_ocmp_opaque) BS.valid_ocmp_opaque;
reveal_opaque (`%BS.eval_ocmp_opaque) BS.eval_ocmp_opaque
let lemma_ifElseFalse_total (ifb:ocmp) (ct:code) (cf:code) (s0:vale_state) (f0:fuel) (sM:vale_state) =
reveal_opaque (`%BS.valid_ocmp_opaque) BS.valid_ocmp_opaque;
reveal_opaque (`%BS.eval_ocmp_opaque) BS.eval_ocmp_opaque
let eval_while_inv_temp (c:code) (s0:vale_state) (fW:fuel) (sW:vale_state) : Type0 =
forall (f:nat).{:pattern BS.machine_eval_code c f (state_to_S sW)}
Some? (BS.machine_eval_code c f (state_to_S sW)) ==>
state_eq_opt (code_modifies_ghost c)
(BS.machine_eval_code c (f + fW) (state_to_S s0))
(BS.machine_eval_code c f (state_to_S sW))
let eval_while_inv (c:code) (s0:vale_state) (fW:fuel) (sW:vale_state) : Type0 =
eval_while_inv_temp c s0 fW sW
let lemma_while_total (b:ocmp) (c:code) (s0:vale_state) =
(s0, 0)
let lemma_whileTrue_total (b:ocmp) (c:code) (s0:vale_state) (sW:vale_state) (fW:fuel) =
({sW with vs_flags = havoc_flags}, fW) | false | false | Vale.X64.Lemmas.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": 30,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val lemma_whileFalse_total (b:ocmp) (c:code) (s0:vale_state) (sW:vale_state) (fW:fuel) : Ghost (vale_state & fuel)
(requires
valid_ocmp b sW /\
not (eval_ocmp sW b) /\
eval_while_inv (While b c) s0 fW sW
)
(ensures fun (s1, f1) ->
s1 == {sW with vs_flags = havoc_flags} /\
eval_code (While b c) s0 f1 s1
) | [] | Vale.X64.Lemmas.lemma_whileFalse_total | {
"file_name": "vale/code/arch/x64/Vale.X64.Lemmas.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} |
b: Vale.X64.Bytes_Code_s.ocmp ->
c: Vale.X64.StateLemmas.code ->
s0: Vale.X64.State.vale_state ->
sW: Vale.X64.State.vale_state ->
fW: Vale.X64.Lemmas.fuel
-> Prims.Ghost (Vale.X64.State.vale_state * Vale.X64.Lemmas.fuel) | {
"end_col": 10,
"end_line": 395,
"start_col": 2,
"start_line": 389
} |
FStar.Pervasives.Lemma | val eval_code_eq_ins (i: BS.ins) (f: fuel) (s1 s2: machine_state)
: Lemma (requires state_eq_S true s1 s2)
(ensures
state_eq_opt true (BS.machine_eval_code (Ins i) f s1) (BS.machine_eval_code (Ins i) f s2)) | [
{
"abbrev": true,
"full_module": "Vale.X64.Memory",
"short_module": "ME"
},
{
"abbrev": true,
"full_module": "Vale.X64.Machine_Semantics_s",
"short_module": "BS"
},
{
"abbrev": false,
"full_module": "Vale.X64.Bytes_Code_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Instruction_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.StateLemmas",
"short_module": null
},
{
"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": "FStar.Mul",
"short_module": null
},
{
"abbrev": true,
"full_module": "Vale.Lib.Map16",
"short_module": "Map16"
},
{
"abbrev": true,
"full_module": "Vale.X64.Machine_Semantics_s",
"short_module": "BS"
},
{
"abbrev": false,
"full_module": "Vale.X64.Bytes_Code_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.StateLemmas",
"short_module": null
},
{
"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.HeapLemmas",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.HeapImpl",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Heap",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"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 eval_code_eq_ins (i:BS.ins) (f:fuel) (s1 s2:machine_state) : Lemma
(requires state_eq_S true s1 s2)
(ensures state_eq_opt true (BS.machine_eval_code (Ins i) f s1) (BS.machine_eval_code (Ins i) f s2))
=
match i with
| Instr _ _ _ -> eval_code_eq_instr i f s1 s2
| Dealloc _ -> eval_code_eq_dealloc i f s1 s2
| Alloc _ -> eval_code_eq_alloc i f s1 s2
| Push _ _ -> eval_code_eq_push i f s1 s2
| Pop _ _ -> eval_code_eq_pop i f s1 s2 | val eval_code_eq_ins (i: BS.ins) (f: fuel) (s1 s2: machine_state)
: Lemma (requires state_eq_S true s1 s2)
(ensures
state_eq_opt true (BS.machine_eval_code (Ins i) f s1) (BS.machine_eval_code (Ins i) f s2))
let eval_code_eq_ins (i: BS.ins) (f: fuel) (s1 s2: machine_state)
: Lemma (requires state_eq_S true s1 s2)
(ensures
state_eq_opt true (BS.machine_eval_code (Ins i) f s1) (BS.machine_eval_code (Ins i) f s2)) = | false | null | true | match i with
| Instr _ _ _ -> eval_code_eq_instr i f s1 s2
| Dealloc _ -> eval_code_eq_dealloc i f s1 s2
| Alloc _ -> eval_code_eq_alloc i f s1 s2
| Push _ _ -> eval_code_eq_push i f s1 s2
| Pop _ _ -> eval_code_eq_pop i f s1 s2 | {
"checked_file": "Vale.X64.Lemmas.fst.checked",
"dependencies": [
"Vale.X64.StateLemmas.fsti.checked",
"Vale.X64.State.fsti.checked",
"Vale.X64.Memory.fsti.checked",
"Vale.X64.Machine_Semantics_s.fst.checked",
"Vale.X64.Machine_s.fst.checked",
"Vale.X64.Instruction_s.fsti.checked",
"Vale.X64.Flags.fsti.checked",
"Vale.X64.Bytes_Code_s.fst.checked",
"prims.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.FunctionalExtensionality.fsti.checked"
],
"interface_file": true,
"source_file": "Vale.X64.Lemmas.fst"
} | [
"lemma"
] | [
"Vale.X64.Machine_Semantics_s.ins",
"Vale.X64.Lemmas.fuel",
"Vale.X64.StateLemmas.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_Semantics_s.instr_annotation",
"Vale.X64.Lemmas.eval_code_eq_instr",
"Vale.X64.Machine_s.nat64",
"Vale.X64.Lemmas.eval_code_eq_dealloc",
"Vale.X64.Lemmas.eval_code_eq_alloc",
"Vale.X64.Machine_s.operand64",
"Vale.Arch.HeapTypes_s.taint",
"Vale.X64.Lemmas.eval_code_eq_push",
"Vale.X64.Lemmas.eval_code_eq_pop",
"Prims.unit",
"Vale.X64.Lemmas.state_eq_S",
"Prims.squash",
"Vale.X64.Lemmas.state_eq_opt",
"Vale.X64.Machine_Semantics_s.machine_eval_code",
"Vale.X64.Machine_s.Ins",
"Vale.X64.Bytes_Code_s.instruction_t",
"Vale.X64.Bytes_Code_s.ocmp",
"Prims.Nil",
"FStar.Pervasives.pattern"
] | [] | module Vale.X64.Lemmas
open FStar.Mul
open Vale.X64.Machine_s
open Vale.X64.State
open Vale.X64.StateLemmas
open Vale.X64.Instruction_s
open Vale.X64.Bytes_Code_s
module BS = Vale.X64.Machine_Semantics_s
module ME = Vale.X64.Memory
#reset-options "--initial_fuel 1 --max_fuel 1 --z3rlimit 100"
#restart-solver
let rec lemma_eq_instr_apply_eval_args
(outs:list instr_out) (args:list instr_operand)
(f:instr_args_t outs args) (oprs:instr_operands_t_args args) (s1 s2:machine_state)
: Lemma
(requires state_eq_S true s1 s2)
(ensures
BS.instr_apply_eval_args outs args f oprs s1 ==
BS.instr_apply_eval_args outs args f oprs s2)
=
let open BS in
lemma_heap_ignore_ghost_machine s1.BS.ms_heap s2.BS.ms_heap;
match args with
| [] -> ()
| i::args ->
(
let (v, oprs) : option (instr_val_t i) & instr_operands_t_args args =
match i with
| IOpEx i -> let oprs = coerce oprs in (instr_eval_operand_explicit i (fst oprs) s1, snd oprs)
| IOpIm i -> (instr_eval_operand_implicit i s1, coerce oprs)
in
let f:arrow (instr_val_t i) (instr_args_t outs args) = coerce f in
match v with
| None -> ()
| Some v -> lemma_eq_instr_apply_eval_args outs args (f v) oprs s1 s2
)
#restart-solver
let rec lemma_eq_instr_apply_eval_inouts
(outs inouts:list instr_out) (args:list instr_operand)
(f:instr_inouts_t outs inouts args) (oprs:instr_operands_t inouts args) (s1 s2:machine_state)
: Lemma
(requires state_eq_S true s1 s2)
(ensures
BS.instr_apply_eval_inouts outs inouts args f oprs s1 ==
BS.instr_apply_eval_inouts outs inouts args f oprs s2)
=
let open BS in
lemma_heap_ignore_ghost_machine s1.BS.ms_heap s2.BS.ms_heap;
match inouts with
| [] -> lemma_eq_instr_apply_eval_args outs args f oprs s1 s2
| (Out, i)::inouts ->
let oprs =
match i with
| IOpEx i -> snd #(instr_operand_t i) (coerce oprs)
| IOpIm i -> coerce oprs
in
lemma_eq_instr_apply_eval_inouts outs inouts args (coerce f) oprs s1 s2
| (InOut, i)::inouts ->
(
let (v, oprs) : option (instr_val_t i) & instr_operands_t inouts args =
match i with
| IOpEx i -> let oprs = coerce oprs in (instr_eval_operand_explicit i (fst oprs) s1, snd oprs)
| IOpIm i -> (instr_eval_operand_implicit i s1, coerce oprs)
in
let f:arrow (instr_val_t i) (instr_inouts_t outs inouts args) = coerce f in
match v with
| None -> ()
| Some v -> lemma_eq_instr_apply_eval_inouts outs inouts args (f v) oprs s1 s2
)
#restart-solver
#push-options "--z3rlimit_factor 2"
let rec lemma_eq_instr_write_outputs
(outs:list instr_out) (args:list instr_operand)
(vs:instr_ret_t outs) (oprs:instr_operands_t outs args) (s1_orig s1 s2_orig s2:machine_state)
: Lemma
(requires state_eq_S true s1_orig s2_orig /\ state_eq_S true s1 s2)
(ensures
state_eq_S true
(BS.instr_write_outputs outs args vs oprs s1_orig s1)
(BS.instr_write_outputs outs args vs oprs s2_orig s2))
=
let open BS in
use_machine_state_equal ();
lemma_heap_ignore_ghost_machine s1.BS.ms_heap s2.BS.ms_heap;
lemma_heap_ignore_ghost_machine s1_orig.BS.ms_heap s2_orig.BS.ms_heap;
allow_inversion tmaddr;
match outs with
| [] -> ()
| (_, i)::outs ->
(
let ((v:instr_val_t i), (vs:instr_ret_t outs)) =
match outs with
| [] -> (vs, ())
| _::_ -> let vs = coerce vs in (fst vs, snd vs)
in
match i with
| IOpEx i ->
let oprs = coerce oprs in
let s1 = instr_write_output_explicit i v (fst oprs) s1_orig s1 in
let s2 = instr_write_output_explicit i v (fst oprs) s2_orig s2 in
lemma_eq_instr_write_outputs outs args vs (snd oprs) s1_orig s1 s2_orig s2
| IOpIm i ->
let s1 = instr_write_output_implicit i v s1_orig s1 in
let s2 = instr_write_output_implicit i v s2_orig s2 in
allow_inversion operand64;
allow_inversion operand128;
lemma_eq_instr_write_outputs outs args vs (coerce oprs) s1_orig s1 s2_orig s2
)
#pop-options
#restart-solver
let eval_ins_eq_instr (inst:BS.ins) (s1 s2:machine_state) : Lemma
(requires Instr? inst /\ state_eq_S true s1 s2)
(ensures state_eq_S true (BS.machine_eval_ins inst s1) (BS.machine_eval_ins inst s2))
=
let open BS in
let Instr it oprs ann = inst in
let InstrTypeRecord #outs #args #havoc_flags' i = it in
lemma_eq_instr_apply_eval_inouts outs outs args (instr_eval i) oprs s1 s2;
let vs = instr_apply_eval outs args (instr_eval i) oprs s1 in
let hav s =
match havoc_flags' with
| HavocFlags -> {s with ms_flags = havoc_flags}
| PreserveFlags -> s
in
let s1' = hav s1 in
let s2' = hav s2 in
match vs with
| None -> ()
| Some vs -> lemma_eq_instr_write_outputs outs args vs oprs s1 s1' s2 s2'
let eval_code_eq_instr (inst:BS.ins) (f:fuel) (s1 s2:machine_state) : Lemma
(requires Instr? inst /\ state_eq_S true s1 s2)
(ensures state_eq_opt true (BS.machine_eval_code (Ins inst) f s1) (BS.machine_eval_code (Ins inst) f s2))
=
reveal_opaque (`%BS.machine_eval_code_ins) BS.machine_eval_code_ins;
eval_ins_eq_instr inst ({s1 with BS.ms_trace = []}) ({s2 with BS.ms_trace = []})
let eval_code_eq_dealloc (inst:BS.ins) (f:fuel) (s1 s2:machine_state) : Lemma
(requires Dealloc? inst /\ state_eq_S true s1 s2)
(ensures state_eq_opt true (BS.machine_eval_code (Ins inst) f s1) (BS.machine_eval_code (Ins inst) f s2))
=
reveal_opaque (`%BS.machine_eval_code_ins) BS.machine_eval_code_ins;
use_machine_state_equal ();
lemma_heap_ignore_ghost_machine s1.BS.ms_heap s2.BS.ms_heap;
allow_inversion tmaddr
let eval_code_eq_alloc (inst:BS.ins) (f:fuel) (s1 s2:machine_state) : Lemma
(requires Alloc? inst /\ state_eq_S true s1 s2)
(ensures state_eq_opt true (BS.machine_eval_code (Ins inst) f s1) (BS.machine_eval_code (Ins inst) f s2))
=
reveal_opaque (`%BS.machine_eval_code_ins) BS.machine_eval_code_ins;
use_machine_state_equal ();
lemma_heap_ignore_ghost_machine s1.BS.ms_heap s2.BS.ms_heap;
allow_inversion tmaddr
let eval_code_eq_push (inst:BS.ins) (f:fuel) (s1 s2:machine_state) : Lemma
(requires Push? inst /\ state_eq_S true s1 s2)
(ensures state_eq_opt true (BS.machine_eval_code (Ins inst) f s1) (BS.machine_eval_code (Ins inst) f s2))
=
reveal_opaque (`%BS.machine_eval_code_ins) BS.machine_eval_code_ins;
use_machine_state_equal ();
lemma_heap_ignore_ghost_machine s1.BS.ms_heap s2.BS.ms_heap;
allow_inversion tmaddr
let eval_code_eq_pop (inst:BS.ins) (f:fuel) (s1 s2:machine_state) : Lemma
(requires Pop? inst /\ state_eq_S true s1 s2)
(ensures state_eq_opt true (BS.machine_eval_code (Ins inst) f s1) (BS.machine_eval_code (Ins inst) f s2))
=
reveal_opaque (`%BS.machine_eval_code_ins) BS.machine_eval_code_ins;
use_machine_state_equal ();
lemma_heap_ignore_ghost_machine s1.BS.ms_heap s2.BS.ms_heap;
allow_inversion tmaddr
let eval_code_eq_ins (i:BS.ins) (f:fuel) (s1 s2:machine_state) : Lemma
(requires state_eq_S true s1 s2)
(ensures state_eq_opt true (BS.machine_eval_code (Ins i) f s1) (BS.machine_eval_code (Ins i) f s2)) | false | false | Vale.X64.Lemmas.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 1,
"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": 100,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val eval_code_eq_ins (i: BS.ins) (f: fuel) (s1 s2: machine_state)
: Lemma (requires state_eq_S true s1 s2)
(ensures
state_eq_opt true (BS.machine_eval_code (Ins i) f s1) (BS.machine_eval_code (Ins i) f s2)) | [] | Vale.X64.Lemmas.eval_code_eq_ins | {
"file_name": "vale/code/arch/x64/Vale.X64.Lemmas.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} |
i: Vale.X64.Machine_Semantics_s.ins ->
f: Vale.X64.Lemmas.fuel ->
s1: Vale.X64.StateLemmas.machine_state ->
s2: Vale.X64.StateLemmas.machine_state
-> FStar.Pervasives.Lemma (requires Vale.X64.Lemmas.state_eq_S true s1 s2)
(ensures
Vale.X64.Lemmas.state_eq_opt true
(Vale.X64.Machine_Semantics_s.machine_eval_code (Vale.X64.Machine_s.Ins i) f s1)
(Vale.X64.Machine_Semantics_s.machine_eval_code (Vale.X64.Machine_s.Ins i) f s2)) | {
"end_col": 42,
"end_line": 188,
"start_col": 2,
"start_line": 183
} |
FStar.Pervasives.Lemma | val lemma_cmp_lt (s:vale_state) (o1:operand64{not (OMem? o1 || OStack? o1)}) (o2:operand64{not (OMem? o2 || OStack? o2)}) : Lemma
(ensures eval_ocmp s (OLt o1 o2) <==> eval_operand o1 s < eval_operand o2 s)
[SMTPat (eval_ocmp s (OLt o1 o2))] | [
{
"abbrev": true,
"full_module": "Vale.X64.Memory",
"short_module": "ME"
},
{
"abbrev": false,
"full_module": "Vale.X64.Instruction_s",
"short_module": null
},
{
"abbrev": true,
"full_module": "Vale.Lib.Map16",
"short_module": "Map16"
},
{
"abbrev": true,
"full_module": "Vale.X64.Machine_Semantics_s",
"short_module": "BS"
},
{
"abbrev": false,
"full_module": "Vale.X64.Bytes_Code_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.StateLemmas",
"short_module": null
},
{
"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.HeapLemmas",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.HeapImpl",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Heap",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"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 lemma_cmp_lt s o1 o2 = reveal_opaque (`%BS.eval_ocmp_opaque) BS.eval_ocmp_opaque | val lemma_cmp_lt (s:vale_state) (o1:operand64{not (OMem? o1 || OStack? o1)}) (o2:operand64{not (OMem? o2 || OStack? o2)}) : Lemma
(ensures eval_ocmp s (OLt o1 o2) <==> eval_operand o1 s < eval_operand o2 s)
[SMTPat (eval_ocmp s (OLt o1 o2))]
let lemma_cmp_lt s o1 o2 = | false | null | true | reveal_opaque (`%BS.eval_ocmp_opaque) BS.eval_ocmp_opaque | {
"checked_file": "Vale.X64.Lemmas.fst.checked",
"dependencies": [
"Vale.X64.StateLemmas.fsti.checked",
"Vale.X64.State.fsti.checked",
"Vale.X64.Memory.fsti.checked",
"Vale.X64.Machine_Semantics_s.fst.checked",
"Vale.X64.Machine_s.fst.checked",
"Vale.X64.Instruction_s.fsti.checked",
"Vale.X64.Flags.fsti.checked",
"Vale.X64.Bytes_Code_s.fst.checked",
"prims.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.FunctionalExtensionality.fsti.checked"
],
"interface_file": true,
"source_file": "Vale.X64.Lemmas.fst"
} | [
"lemma"
] | [
"Vale.X64.State.vale_state",
"Vale.X64.Machine_s.operand64",
"Prims.b2t",
"Prims.op_Negation",
"Prims.op_BarBar",
"Vale.X64.Machine_s.uu___is_OMem",
"Vale.X64.Machine_s.nat64",
"Vale.X64.Machine_s.reg_64",
"Vale.X64.Machine_s.uu___is_OStack",
"FStar.Pervasives.reveal_opaque",
"Vale.X64.Machine_Semantics_s.machine_state",
"Vale.X64.Machine_Semantics_s.ocmp",
"Prims.bool",
"Vale.X64.Machine_Semantics_s.eval_ocmp_opaque",
"Prims.unit"
] | [] | module Vale.X64.Lemmas
open FStar.Mul
open Vale.X64.Machine_s
open Vale.X64.State
open Vale.X64.StateLemmas
open Vale.X64.Instruction_s
open Vale.X64.Bytes_Code_s
module BS = Vale.X64.Machine_Semantics_s
module ME = Vale.X64.Memory
#reset-options "--initial_fuel 1 --max_fuel 1 --z3rlimit 100"
#restart-solver
let rec lemma_eq_instr_apply_eval_args
(outs:list instr_out) (args:list instr_operand)
(f:instr_args_t outs args) (oprs:instr_operands_t_args args) (s1 s2:machine_state)
: Lemma
(requires state_eq_S true s1 s2)
(ensures
BS.instr_apply_eval_args outs args f oprs s1 ==
BS.instr_apply_eval_args outs args f oprs s2)
=
let open BS in
lemma_heap_ignore_ghost_machine s1.BS.ms_heap s2.BS.ms_heap;
match args with
| [] -> ()
| i::args ->
(
let (v, oprs) : option (instr_val_t i) & instr_operands_t_args args =
match i with
| IOpEx i -> let oprs = coerce oprs in (instr_eval_operand_explicit i (fst oprs) s1, snd oprs)
| IOpIm i -> (instr_eval_operand_implicit i s1, coerce oprs)
in
let f:arrow (instr_val_t i) (instr_args_t outs args) = coerce f in
match v with
| None -> ()
| Some v -> lemma_eq_instr_apply_eval_args outs args (f v) oprs s1 s2
)
#restart-solver
let rec lemma_eq_instr_apply_eval_inouts
(outs inouts:list instr_out) (args:list instr_operand)
(f:instr_inouts_t outs inouts args) (oprs:instr_operands_t inouts args) (s1 s2:machine_state)
: Lemma
(requires state_eq_S true s1 s2)
(ensures
BS.instr_apply_eval_inouts outs inouts args f oprs s1 ==
BS.instr_apply_eval_inouts outs inouts args f oprs s2)
=
let open BS in
lemma_heap_ignore_ghost_machine s1.BS.ms_heap s2.BS.ms_heap;
match inouts with
| [] -> lemma_eq_instr_apply_eval_args outs args f oprs s1 s2
| (Out, i)::inouts ->
let oprs =
match i with
| IOpEx i -> snd #(instr_operand_t i) (coerce oprs)
| IOpIm i -> coerce oprs
in
lemma_eq_instr_apply_eval_inouts outs inouts args (coerce f) oprs s1 s2
| (InOut, i)::inouts ->
(
let (v, oprs) : option (instr_val_t i) & instr_operands_t inouts args =
match i with
| IOpEx i -> let oprs = coerce oprs in (instr_eval_operand_explicit i (fst oprs) s1, snd oprs)
| IOpIm i -> (instr_eval_operand_implicit i s1, coerce oprs)
in
let f:arrow (instr_val_t i) (instr_inouts_t outs inouts args) = coerce f in
match v with
| None -> ()
| Some v -> lemma_eq_instr_apply_eval_inouts outs inouts args (f v) oprs s1 s2
)
#restart-solver
#push-options "--z3rlimit_factor 2"
let rec lemma_eq_instr_write_outputs
(outs:list instr_out) (args:list instr_operand)
(vs:instr_ret_t outs) (oprs:instr_operands_t outs args) (s1_orig s1 s2_orig s2:machine_state)
: Lemma
(requires state_eq_S true s1_orig s2_orig /\ state_eq_S true s1 s2)
(ensures
state_eq_S true
(BS.instr_write_outputs outs args vs oprs s1_orig s1)
(BS.instr_write_outputs outs args vs oprs s2_orig s2))
=
let open BS in
use_machine_state_equal ();
lemma_heap_ignore_ghost_machine s1.BS.ms_heap s2.BS.ms_heap;
lemma_heap_ignore_ghost_machine s1_orig.BS.ms_heap s2_orig.BS.ms_heap;
allow_inversion tmaddr;
match outs with
| [] -> ()
| (_, i)::outs ->
(
let ((v:instr_val_t i), (vs:instr_ret_t outs)) =
match outs with
| [] -> (vs, ())
| _::_ -> let vs = coerce vs in (fst vs, snd vs)
in
match i with
| IOpEx i ->
let oprs = coerce oprs in
let s1 = instr_write_output_explicit i v (fst oprs) s1_orig s1 in
let s2 = instr_write_output_explicit i v (fst oprs) s2_orig s2 in
lemma_eq_instr_write_outputs outs args vs (snd oprs) s1_orig s1 s2_orig s2
| IOpIm i ->
let s1 = instr_write_output_implicit i v s1_orig s1 in
let s2 = instr_write_output_implicit i v s2_orig s2 in
allow_inversion operand64;
allow_inversion operand128;
lemma_eq_instr_write_outputs outs args vs (coerce oprs) s1_orig s1 s2_orig s2
)
#pop-options
#restart-solver
let eval_ins_eq_instr (inst:BS.ins) (s1 s2:machine_state) : Lemma
(requires Instr? inst /\ state_eq_S true s1 s2)
(ensures state_eq_S true (BS.machine_eval_ins inst s1) (BS.machine_eval_ins inst s2))
=
let open BS in
let Instr it oprs ann = inst in
let InstrTypeRecord #outs #args #havoc_flags' i = it in
lemma_eq_instr_apply_eval_inouts outs outs args (instr_eval i) oprs s1 s2;
let vs = instr_apply_eval outs args (instr_eval i) oprs s1 in
let hav s =
match havoc_flags' with
| HavocFlags -> {s with ms_flags = havoc_flags}
| PreserveFlags -> s
in
let s1' = hav s1 in
let s2' = hav s2 in
match vs with
| None -> ()
| Some vs -> lemma_eq_instr_write_outputs outs args vs oprs s1 s1' s2 s2'
let eval_code_eq_instr (inst:BS.ins) (f:fuel) (s1 s2:machine_state) : Lemma
(requires Instr? inst /\ state_eq_S true s1 s2)
(ensures state_eq_opt true (BS.machine_eval_code (Ins inst) f s1) (BS.machine_eval_code (Ins inst) f s2))
=
reveal_opaque (`%BS.machine_eval_code_ins) BS.machine_eval_code_ins;
eval_ins_eq_instr inst ({s1 with BS.ms_trace = []}) ({s2 with BS.ms_trace = []})
let eval_code_eq_dealloc (inst:BS.ins) (f:fuel) (s1 s2:machine_state) : Lemma
(requires Dealloc? inst /\ state_eq_S true s1 s2)
(ensures state_eq_opt true (BS.machine_eval_code (Ins inst) f s1) (BS.machine_eval_code (Ins inst) f s2))
=
reveal_opaque (`%BS.machine_eval_code_ins) BS.machine_eval_code_ins;
use_machine_state_equal ();
lemma_heap_ignore_ghost_machine s1.BS.ms_heap s2.BS.ms_heap;
allow_inversion tmaddr
let eval_code_eq_alloc (inst:BS.ins) (f:fuel) (s1 s2:machine_state) : Lemma
(requires Alloc? inst /\ state_eq_S true s1 s2)
(ensures state_eq_opt true (BS.machine_eval_code (Ins inst) f s1) (BS.machine_eval_code (Ins inst) f s2))
=
reveal_opaque (`%BS.machine_eval_code_ins) BS.machine_eval_code_ins;
use_machine_state_equal ();
lemma_heap_ignore_ghost_machine s1.BS.ms_heap s2.BS.ms_heap;
allow_inversion tmaddr
let eval_code_eq_push (inst:BS.ins) (f:fuel) (s1 s2:machine_state) : Lemma
(requires Push? inst /\ state_eq_S true s1 s2)
(ensures state_eq_opt true (BS.machine_eval_code (Ins inst) f s1) (BS.machine_eval_code (Ins inst) f s2))
=
reveal_opaque (`%BS.machine_eval_code_ins) BS.machine_eval_code_ins;
use_machine_state_equal ();
lemma_heap_ignore_ghost_machine s1.BS.ms_heap s2.BS.ms_heap;
allow_inversion tmaddr
let eval_code_eq_pop (inst:BS.ins) (f:fuel) (s1 s2:machine_state) : Lemma
(requires Pop? inst /\ state_eq_S true s1 s2)
(ensures state_eq_opt true (BS.machine_eval_code (Ins inst) f s1) (BS.machine_eval_code (Ins inst) f s2))
=
reveal_opaque (`%BS.machine_eval_code_ins) BS.machine_eval_code_ins;
use_machine_state_equal ();
lemma_heap_ignore_ghost_machine s1.BS.ms_heap s2.BS.ms_heap;
allow_inversion tmaddr
let eval_code_eq_ins (i:BS.ins) (f:fuel) (s1 s2:machine_state) : Lemma
(requires state_eq_S true s1 s2)
(ensures state_eq_opt true (BS.machine_eval_code (Ins i) f s1) (BS.machine_eval_code (Ins i) f s2))
=
match i with
| Instr _ _ _ -> eval_code_eq_instr i f s1 s2
| Dealloc _ -> eval_code_eq_dealloc i f s1 s2
| Alloc _ -> eval_code_eq_alloc i f s1 s2
| Push _ _ -> eval_code_eq_push i f s1 s2
| Pop _ _ -> eval_code_eq_pop i f s1 s2
#reset-options "--fuel 2 --z3rlimit 30"
let eval_ocmp_eq_core (g:bool) (cond:ocmp) (s:machine_state) : Lemma
(ensures (
let (s1, b1) = BS.machine_eval_ocmp s cond in
let (s2, b2) = BS.machine_eval_ocmp (core_state g s) cond in
state_eq_S g s1 s2 /\ b1 == b2
))
=
reveal_opaque (`%BS.valid_ocmp_opaque) BS.valid_ocmp_opaque;
reveal_opaque (`%BS.eval_ocmp_opaque) BS.eval_ocmp_opaque;
()
#restart-solver
let rec eval_code_eq_core (g:bool) (c:code) (f:fuel) (s:machine_state) : Lemma
(ensures state_eq_opt g (BS.machine_eval_code c f s) (BS.machine_eval_code c f (core_state g s)))
(decreases %[f; c])
=
match c with
| Ins i ->
reveal_opaque (`%BS.machine_eval_code_ins) BS.machine_eval_code_ins;
if g then eval_code_eq_ins i f s (core_state g s)
| Block cs -> eval_codes_eq_core g cs f s
| IfElse cond ct cf ->
eval_ocmp_eq_core g cond s;
let (s', _) = BS.machine_eval_ocmp s cond in
let (t', _) = BS.machine_eval_ocmp (core_state g s) cond in
eval_code_eq_core g ct f s';
eval_code_eq_core g ct f t';
eval_code_eq_core g cf f s';
eval_code_eq_core g cf f t';
()
| While cond body -> eval_while_eq_core g cond body f s
and eval_codes_eq_core (g:bool) (cs:codes) (f:fuel) (s:machine_state) : Lemma
(ensures state_eq_opt g (BS.machine_eval_codes cs f s) (BS.machine_eval_codes cs f (core_state g s)))
(decreases %[f; cs])
=
match cs with
| [] -> ()
| c'::cs' -> (
eval_code_eq_core g c' f s;
match (machine_eval_code c' f s, machine_eval_code c' f (core_state g s)) with
| (None, None) -> ()
| (Some s', Some t') -> eval_codes_eq_core g cs' f s'; eval_codes_eq_core g cs' f t'
)
and eval_while_eq_core (g:bool) (cond:ocmp) (body:code) (f:fuel) (s:machine_state) : Lemma
(ensures state_eq_opt g (BS.machine_eval_while cond body f s) (BS.machine_eval_while cond body f (core_state g s)))
(decreases %[f; body])
=
if f > 0 then (
eval_ocmp_eq_core g cond s;
let (s1, _) = BS.machine_eval_ocmp s cond in
let (t1, _) = BS.machine_eval_ocmp (core_state g s) cond in
eval_code_eq_core g body (f - 1) s1;
eval_code_eq_core g body (f - 1) t1;
match (BS.machine_eval_code body (f - 1) s1, BS.machine_eval_code body (f - 1) t1) with
| (None, None) -> ()
| (Some s2, Some t2) ->
eval_while_eq_core g cond body (f - 1) s2;
eval_while_eq_core g cond body (f - 1) t2;
()
)
let eval_code_eq_f (c:code) (f:fuel) (s1 s2:machine_state) : Lemma
(requires state_eq_S false s1 s2)
(ensures state_eq_opt false (BS.machine_eval_code c f s1) (BS.machine_eval_code c f s2))
[SMTPat (BS.machine_eval_code c f s1); SMTPat (BS.machine_eval_code c f s2)]
=
eval_code_eq_core false c f s1; eval_code_eq_core false c f s2
let eval_codes_eq_f (cs:codes) (f:fuel) (s1 s2:machine_state) : Lemma
(requires state_eq_S false s1 s2)
(ensures state_eq_opt false (BS.machine_eval_codes cs f s1) (BS.machine_eval_codes cs f s2))
[SMTPat (BS.machine_eval_codes cs f s1); SMTPat (BS.machine_eval_codes cs f s2)]
=
eval_codes_eq_core false cs f s1; eval_codes_eq_core false cs f s2
let eval_while_eq_f (cond:ocmp) (body:code) (f:fuel) (s1 s2:machine_state) : Lemma
(requires state_eq_S false s1 s2)
(ensures state_eq_opt false (BS.machine_eval_while cond body f s1) (BS.machine_eval_while cond body f s2))
[SMTPat (BS.machine_eval_while cond body f s1); SMTPat (BS.machine_eval_while cond body f s2)]
=
eval_while_eq_core false cond body f s1; eval_while_eq_core false cond body f s2
let eval_code_eq_t (c:code) (f:fuel) (s1 s2:machine_state) : Lemma
(requires state_eq_S true s1 s2)
(ensures state_eq_opt true (BS.machine_eval_code c f s1) (BS.machine_eval_code c f s2))
[SMTPat (BS.machine_eval_code c f s1); SMTPat (BS.machine_eval_code c f s2)]
=
eval_code_eq_core true c f s1; eval_code_eq_core true c f s2
let eval_codes_eq_t (cs:codes) (f:fuel) (s1 s2:machine_state) : Lemma
(requires state_eq_S true s1 s2)
(ensures state_eq_opt true (BS.machine_eval_codes cs f s1) (BS.machine_eval_codes cs f s2))
[SMTPat (BS.machine_eval_codes cs f s1); SMTPat (BS.machine_eval_codes cs f s2)]
=
eval_codes_eq_core true cs f s1; eval_codes_eq_core true cs f s2
let eval_while_eq_t (cond:ocmp) (body:code) (f:fuel) (s1 s2:machine_state) : Lemma
(requires state_eq_S true s1 s2)
(ensures state_eq_opt true (BS.machine_eval_while cond body f s1) (BS.machine_eval_while cond body f s2))
[SMTPat (BS.machine_eval_while cond body f s1); SMTPat (BS.machine_eval_while cond body f s2)]
=
eval_while_eq_core true cond body f s1; eval_while_eq_core true cond body f s2
let eval_code_ts (g:bool) (c:code) (s0:machine_state) (f0:fuel) (s1:machine_state) : Type0 =
state_eq_opt g (BS.machine_eval_code c f0 s0) (Some s1)
let rec increase_fuel (g:bool) (c:code) (s0:machine_state) (f0:fuel) (sN:machine_state) (fN:fuel) : Lemma
(requires eval_code_ts g c s0 f0 sN /\ f0 <= fN)
(ensures eval_code_ts g c s0 fN sN)
(decreases %[f0; c])
=
match c with
| Ins ins -> ()
| Block l -> increase_fuels g l s0 f0 sN fN
| IfElse cond t f ->
let (s0, b0) = BS.machine_eval_ocmp s0 cond in
if b0 then increase_fuel g t s0 f0 sN fN else increase_fuel g f s0 f0 sN fN
| While cond c ->
let (s1, b0) = BS.machine_eval_ocmp s0 cond in
if b0 then (
match BS.machine_eval_code c (f0 - 1) s1 with
| None -> ()
| Some s2 ->
increase_fuel g c s1 (f0 - 1) s2 (fN - 1);
if s2.BS.ms_ok then increase_fuel g (While cond c) s2 (f0 - 1) sN (fN - 1)
else ()
)
and increase_fuels (g:bool) (c:codes) (s0:machine_state) (f0:fuel) (sN:machine_state) (fN:fuel) : Lemma
(requires eval_code_ts g (Block c) s0 f0 sN /\ f0 <= fN)
(ensures eval_code_ts g (Block c) s0 fN sN)
(decreases %[f0; c])
=
match c with
| [] -> ()
| h::t ->
(
let Some s1 = BS.machine_eval_code h f0 s0 in
increase_fuel g h s0 f0 s1 fN;
increase_fuels g t s1 f0 sN fN
)
let lemma_cmp_eq s o1 o2 = reveal_opaque (`%BS.eval_ocmp_opaque) BS.eval_ocmp_opaque
let lemma_cmp_ne s o1 o2 = reveal_opaque (`%BS.eval_ocmp_opaque) BS.eval_ocmp_opaque
let lemma_cmp_le s o1 o2 = reveal_opaque (`%BS.eval_ocmp_opaque) BS.eval_ocmp_opaque | false | false | Vale.X64.Lemmas.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": 30,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val lemma_cmp_lt (s:vale_state) (o1:operand64{not (OMem? o1 || OStack? o1)}) (o2:operand64{not (OMem? o2 || OStack? o2)}) : Lemma
(ensures eval_ocmp s (OLt o1 o2) <==> eval_operand o1 s < eval_operand o2 s)
[SMTPat (eval_ocmp s (OLt o1 o2))] | [] | Vale.X64.Lemmas.lemma_cmp_lt | {
"file_name": "vale/code/arch/x64/Vale.X64.Lemmas.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} |
s: Vale.X64.State.vale_state ->
o1: Vale.X64.Machine_s.operand64{Prims.op_Negation (OMem? o1 || OStack? o1)} ->
o2: Vale.X64.Machine_s.operand64{Prims.op_Negation (OMem? o2 || OStack? o2)}
-> FStar.Pervasives.Lemma
(ensures
Vale.X64.Lemmas.eval_ocmp s (Vale.X64.Bytes_Code_s.OLt o1 o2) <==>
Vale.X64.State.eval_operand o1 s < Vale.X64.State.eval_operand o2 s)
[SMTPat (Vale.X64.Lemmas.eval_ocmp s (Vale.X64.Bytes_Code_s.OLt o1 o2))] | {
"end_col": 84,
"end_line": 337,
"start_col": 27,
"start_line": 337
} |
FStar.Pervasives.Lemma | val lemma_cmp_eq (s:vale_state) (o1:operand64{not (OMem? o1 || OStack? o1)}) (o2:operand64{not (OMem? o2 || OStack? o2)}) : Lemma
(ensures eval_ocmp s (OEq o1 o2) <==> eval_operand o1 s == eval_operand o2 s)
[SMTPat (eval_ocmp s (OEq o1 o2))] | [
{
"abbrev": true,
"full_module": "Vale.X64.Memory",
"short_module": "ME"
},
{
"abbrev": false,
"full_module": "Vale.X64.Instruction_s",
"short_module": null
},
{
"abbrev": true,
"full_module": "Vale.Lib.Map16",
"short_module": "Map16"
},
{
"abbrev": true,
"full_module": "Vale.X64.Machine_Semantics_s",
"short_module": "BS"
},
{
"abbrev": false,
"full_module": "Vale.X64.Bytes_Code_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.StateLemmas",
"short_module": null
},
{
"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.HeapLemmas",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.HeapImpl",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Heap",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"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 lemma_cmp_eq s o1 o2 = reveal_opaque (`%BS.eval_ocmp_opaque) BS.eval_ocmp_opaque | val lemma_cmp_eq (s:vale_state) (o1:operand64{not (OMem? o1 || OStack? o1)}) (o2:operand64{not (OMem? o2 || OStack? o2)}) : Lemma
(ensures eval_ocmp s (OEq o1 o2) <==> eval_operand o1 s == eval_operand o2 s)
[SMTPat (eval_ocmp s (OEq o1 o2))]
let lemma_cmp_eq s o1 o2 = | false | null | true | reveal_opaque (`%BS.eval_ocmp_opaque) BS.eval_ocmp_opaque | {
"checked_file": "Vale.X64.Lemmas.fst.checked",
"dependencies": [
"Vale.X64.StateLemmas.fsti.checked",
"Vale.X64.State.fsti.checked",
"Vale.X64.Memory.fsti.checked",
"Vale.X64.Machine_Semantics_s.fst.checked",
"Vale.X64.Machine_s.fst.checked",
"Vale.X64.Instruction_s.fsti.checked",
"Vale.X64.Flags.fsti.checked",
"Vale.X64.Bytes_Code_s.fst.checked",
"prims.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.FunctionalExtensionality.fsti.checked"
],
"interface_file": true,
"source_file": "Vale.X64.Lemmas.fst"
} | [
"lemma"
] | [
"Vale.X64.State.vale_state",
"Vale.X64.Machine_s.operand64",
"Prims.b2t",
"Prims.op_Negation",
"Prims.op_BarBar",
"Vale.X64.Machine_s.uu___is_OMem",
"Vale.X64.Machine_s.nat64",
"Vale.X64.Machine_s.reg_64",
"Vale.X64.Machine_s.uu___is_OStack",
"FStar.Pervasives.reveal_opaque",
"Vale.X64.Machine_Semantics_s.machine_state",
"Vale.X64.Machine_Semantics_s.ocmp",
"Prims.bool",
"Vale.X64.Machine_Semantics_s.eval_ocmp_opaque",
"Prims.unit"
] | [] | module Vale.X64.Lemmas
open FStar.Mul
open Vale.X64.Machine_s
open Vale.X64.State
open Vale.X64.StateLemmas
open Vale.X64.Instruction_s
open Vale.X64.Bytes_Code_s
module BS = Vale.X64.Machine_Semantics_s
module ME = Vale.X64.Memory
#reset-options "--initial_fuel 1 --max_fuel 1 --z3rlimit 100"
#restart-solver
let rec lemma_eq_instr_apply_eval_args
(outs:list instr_out) (args:list instr_operand)
(f:instr_args_t outs args) (oprs:instr_operands_t_args args) (s1 s2:machine_state)
: Lemma
(requires state_eq_S true s1 s2)
(ensures
BS.instr_apply_eval_args outs args f oprs s1 ==
BS.instr_apply_eval_args outs args f oprs s2)
=
let open BS in
lemma_heap_ignore_ghost_machine s1.BS.ms_heap s2.BS.ms_heap;
match args with
| [] -> ()
| i::args ->
(
let (v, oprs) : option (instr_val_t i) & instr_operands_t_args args =
match i with
| IOpEx i -> let oprs = coerce oprs in (instr_eval_operand_explicit i (fst oprs) s1, snd oprs)
| IOpIm i -> (instr_eval_operand_implicit i s1, coerce oprs)
in
let f:arrow (instr_val_t i) (instr_args_t outs args) = coerce f in
match v with
| None -> ()
| Some v -> lemma_eq_instr_apply_eval_args outs args (f v) oprs s1 s2
)
#restart-solver
let rec lemma_eq_instr_apply_eval_inouts
(outs inouts:list instr_out) (args:list instr_operand)
(f:instr_inouts_t outs inouts args) (oprs:instr_operands_t inouts args) (s1 s2:machine_state)
: Lemma
(requires state_eq_S true s1 s2)
(ensures
BS.instr_apply_eval_inouts outs inouts args f oprs s1 ==
BS.instr_apply_eval_inouts outs inouts args f oprs s2)
=
let open BS in
lemma_heap_ignore_ghost_machine s1.BS.ms_heap s2.BS.ms_heap;
match inouts with
| [] -> lemma_eq_instr_apply_eval_args outs args f oprs s1 s2
| (Out, i)::inouts ->
let oprs =
match i with
| IOpEx i -> snd #(instr_operand_t i) (coerce oprs)
| IOpIm i -> coerce oprs
in
lemma_eq_instr_apply_eval_inouts outs inouts args (coerce f) oprs s1 s2
| (InOut, i)::inouts ->
(
let (v, oprs) : option (instr_val_t i) & instr_operands_t inouts args =
match i with
| IOpEx i -> let oprs = coerce oprs in (instr_eval_operand_explicit i (fst oprs) s1, snd oprs)
| IOpIm i -> (instr_eval_operand_implicit i s1, coerce oprs)
in
let f:arrow (instr_val_t i) (instr_inouts_t outs inouts args) = coerce f in
match v with
| None -> ()
| Some v -> lemma_eq_instr_apply_eval_inouts outs inouts args (f v) oprs s1 s2
)
#restart-solver
#push-options "--z3rlimit_factor 2"
let rec lemma_eq_instr_write_outputs
(outs:list instr_out) (args:list instr_operand)
(vs:instr_ret_t outs) (oprs:instr_operands_t outs args) (s1_orig s1 s2_orig s2:machine_state)
: Lemma
(requires state_eq_S true s1_orig s2_orig /\ state_eq_S true s1 s2)
(ensures
state_eq_S true
(BS.instr_write_outputs outs args vs oprs s1_orig s1)
(BS.instr_write_outputs outs args vs oprs s2_orig s2))
=
let open BS in
use_machine_state_equal ();
lemma_heap_ignore_ghost_machine s1.BS.ms_heap s2.BS.ms_heap;
lemma_heap_ignore_ghost_machine s1_orig.BS.ms_heap s2_orig.BS.ms_heap;
allow_inversion tmaddr;
match outs with
| [] -> ()
| (_, i)::outs ->
(
let ((v:instr_val_t i), (vs:instr_ret_t outs)) =
match outs with
| [] -> (vs, ())
| _::_ -> let vs = coerce vs in (fst vs, snd vs)
in
match i with
| IOpEx i ->
let oprs = coerce oprs in
let s1 = instr_write_output_explicit i v (fst oprs) s1_orig s1 in
let s2 = instr_write_output_explicit i v (fst oprs) s2_orig s2 in
lemma_eq_instr_write_outputs outs args vs (snd oprs) s1_orig s1 s2_orig s2
| IOpIm i ->
let s1 = instr_write_output_implicit i v s1_orig s1 in
let s2 = instr_write_output_implicit i v s2_orig s2 in
allow_inversion operand64;
allow_inversion operand128;
lemma_eq_instr_write_outputs outs args vs (coerce oprs) s1_orig s1 s2_orig s2
)
#pop-options
#restart-solver
let eval_ins_eq_instr (inst:BS.ins) (s1 s2:machine_state) : Lemma
(requires Instr? inst /\ state_eq_S true s1 s2)
(ensures state_eq_S true (BS.machine_eval_ins inst s1) (BS.machine_eval_ins inst s2))
=
let open BS in
let Instr it oprs ann = inst in
let InstrTypeRecord #outs #args #havoc_flags' i = it in
lemma_eq_instr_apply_eval_inouts outs outs args (instr_eval i) oprs s1 s2;
let vs = instr_apply_eval outs args (instr_eval i) oprs s1 in
let hav s =
match havoc_flags' with
| HavocFlags -> {s with ms_flags = havoc_flags}
| PreserveFlags -> s
in
let s1' = hav s1 in
let s2' = hav s2 in
match vs with
| None -> ()
| Some vs -> lemma_eq_instr_write_outputs outs args vs oprs s1 s1' s2 s2'
let eval_code_eq_instr (inst:BS.ins) (f:fuel) (s1 s2:machine_state) : Lemma
(requires Instr? inst /\ state_eq_S true s1 s2)
(ensures state_eq_opt true (BS.machine_eval_code (Ins inst) f s1) (BS.machine_eval_code (Ins inst) f s2))
=
reveal_opaque (`%BS.machine_eval_code_ins) BS.machine_eval_code_ins;
eval_ins_eq_instr inst ({s1 with BS.ms_trace = []}) ({s2 with BS.ms_trace = []})
let eval_code_eq_dealloc (inst:BS.ins) (f:fuel) (s1 s2:machine_state) : Lemma
(requires Dealloc? inst /\ state_eq_S true s1 s2)
(ensures state_eq_opt true (BS.machine_eval_code (Ins inst) f s1) (BS.machine_eval_code (Ins inst) f s2))
=
reveal_opaque (`%BS.machine_eval_code_ins) BS.machine_eval_code_ins;
use_machine_state_equal ();
lemma_heap_ignore_ghost_machine s1.BS.ms_heap s2.BS.ms_heap;
allow_inversion tmaddr
let eval_code_eq_alloc (inst:BS.ins) (f:fuel) (s1 s2:machine_state) : Lemma
(requires Alloc? inst /\ state_eq_S true s1 s2)
(ensures state_eq_opt true (BS.machine_eval_code (Ins inst) f s1) (BS.machine_eval_code (Ins inst) f s2))
=
reveal_opaque (`%BS.machine_eval_code_ins) BS.machine_eval_code_ins;
use_machine_state_equal ();
lemma_heap_ignore_ghost_machine s1.BS.ms_heap s2.BS.ms_heap;
allow_inversion tmaddr
let eval_code_eq_push (inst:BS.ins) (f:fuel) (s1 s2:machine_state) : Lemma
(requires Push? inst /\ state_eq_S true s1 s2)
(ensures state_eq_opt true (BS.machine_eval_code (Ins inst) f s1) (BS.machine_eval_code (Ins inst) f s2))
=
reveal_opaque (`%BS.machine_eval_code_ins) BS.machine_eval_code_ins;
use_machine_state_equal ();
lemma_heap_ignore_ghost_machine s1.BS.ms_heap s2.BS.ms_heap;
allow_inversion tmaddr
let eval_code_eq_pop (inst:BS.ins) (f:fuel) (s1 s2:machine_state) : Lemma
(requires Pop? inst /\ state_eq_S true s1 s2)
(ensures state_eq_opt true (BS.machine_eval_code (Ins inst) f s1) (BS.machine_eval_code (Ins inst) f s2))
=
reveal_opaque (`%BS.machine_eval_code_ins) BS.machine_eval_code_ins;
use_machine_state_equal ();
lemma_heap_ignore_ghost_machine s1.BS.ms_heap s2.BS.ms_heap;
allow_inversion tmaddr
let eval_code_eq_ins (i:BS.ins) (f:fuel) (s1 s2:machine_state) : Lemma
(requires state_eq_S true s1 s2)
(ensures state_eq_opt true (BS.machine_eval_code (Ins i) f s1) (BS.machine_eval_code (Ins i) f s2))
=
match i with
| Instr _ _ _ -> eval_code_eq_instr i f s1 s2
| Dealloc _ -> eval_code_eq_dealloc i f s1 s2
| Alloc _ -> eval_code_eq_alloc i f s1 s2
| Push _ _ -> eval_code_eq_push i f s1 s2
| Pop _ _ -> eval_code_eq_pop i f s1 s2
#reset-options "--fuel 2 --z3rlimit 30"
let eval_ocmp_eq_core (g:bool) (cond:ocmp) (s:machine_state) : Lemma
(ensures (
let (s1, b1) = BS.machine_eval_ocmp s cond in
let (s2, b2) = BS.machine_eval_ocmp (core_state g s) cond in
state_eq_S g s1 s2 /\ b1 == b2
))
=
reveal_opaque (`%BS.valid_ocmp_opaque) BS.valid_ocmp_opaque;
reveal_opaque (`%BS.eval_ocmp_opaque) BS.eval_ocmp_opaque;
()
#restart-solver
let rec eval_code_eq_core (g:bool) (c:code) (f:fuel) (s:machine_state) : Lemma
(ensures state_eq_opt g (BS.machine_eval_code c f s) (BS.machine_eval_code c f (core_state g s)))
(decreases %[f; c])
=
match c with
| Ins i ->
reveal_opaque (`%BS.machine_eval_code_ins) BS.machine_eval_code_ins;
if g then eval_code_eq_ins i f s (core_state g s)
| Block cs -> eval_codes_eq_core g cs f s
| IfElse cond ct cf ->
eval_ocmp_eq_core g cond s;
let (s', _) = BS.machine_eval_ocmp s cond in
let (t', _) = BS.machine_eval_ocmp (core_state g s) cond in
eval_code_eq_core g ct f s';
eval_code_eq_core g ct f t';
eval_code_eq_core g cf f s';
eval_code_eq_core g cf f t';
()
| While cond body -> eval_while_eq_core g cond body f s
and eval_codes_eq_core (g:bool) (cs:codes) (f:fuel) (s:machine_state) : Lemma
(ensures state_eq_opt g (BS.machine_eval_codes cs f s) (BS.machine_eval_codes cs f (core_state g s)))
(decreases %[f; cs])
=
match cs with
| [] -> ()
| c'::cs' -> (
eval_code_eq_core g c' f s;
match (machine_eval_code c' f s, machine_eval_code c' f (core_state g s)) with
| (None, None) -> ()
| (Some s', Some t') -> eval_codes_eq_core g cs' f s'; eval_codes_eq_core g cs' f t'
)
and eval_while_eq_core (g:bool) (cond:ocmp) (body:code) (f:fuel) (s:machine_state) : Lemma
(ensures state_eq_opt g (BS.machine_eval_while cond body f s) (BS.machine_eval_while cond body f (core_state g s)))
(decreases %[f; body])
=
if f > 0 then (
eval_ocmp_eq_core g cond s;
let (s1, _) = BS.machine_eval_ocmp s cond in
let (t1, _) = BS.machine_eval_ocmp (core_state g s) cond in
eval_code_eq_core g body (f - 1) s1;
eval_code_eq_core g body (f - 1) t1;
match (BS.machine_eval_code body (f - 1) s1, BS.machine_eval_code body (f - 1) t1) with
| (None, None) -> ()
| (Some s2, Some t2) ->
eval_while_eq_core g cond body (f - 1) s2;
eval_while_eq_core g cond body (f - 1) t2;
()
)
let eval_code_eq_f (c:code) (f:fuel) (s1 s2:machine_state) : Lemma
(requires state_eq_S false s1 s2)
(ensures state_eq_opt false (BS.machine_eval_code c f s1) (BS.machine_eval_code c f s2))
[SMTPat (BS.machine_eval_code c f s1); SMTPat (BS.machine_eval_code c f s2)]
=
eval_code_eq_core false c f s1; eval_code_eq_core false c f s2
let eval_codes_eq_f (cs:codes) (f:fuel) (s1 s2:machine_state) : Lemma
(requires state_eq_S false s1 s2)
(ensures state_eq_opt false (BS.machine_eval_codes cs f s1) (BS.machine_eval_codes cs f s2))
[SMTPat (BS.machine_eval_codes cs f s1); SMTPat (BS.machine_eval_codes cs f s2)]
=
eval_codes_eq_core false cs f s1; eval_codes_eq_core false cs f s2
let eval_while_eq_f (cond:ocmp) (body:code) (f:fuel) (s1 s2:machine_state) : Lemma
(requires state_eq_S false s1 s2)
(ensures state_eq_opt false (BS.machine_eval_while cond body f s1) (BS.machine_eval_while cond body f s2))
[SMTPat (BS.machine_eval_while cond body f s1); SMTPat (BS.machine_eval_while cond body f s2)]
=
eval_while_eq_core false cond body f s1; eval_while_eq_core false cond body f s2
let eval_code_eq_t (c:code) (f:fuel) (s1 s2:machine_state) : Lemma
(requires state_eq_S true s1 s2)
(ensures state_eq_opt true (BS.machine_eval_code c f s1) (BS.machine_eval_code c f s2))
[SMTPat (BS.machine_eval_code c f s1); SMTPat (BS.machine_eval_code c f s2)]
=
eval_code_eq_core true c f s1; eval_code_eq_core true c f s2
let eval_codes_eq_t (cs:codes) (f:fuel) (s1 s2:machine_state) : Lemma
(requires state_eq_S true s1 s2)
(ensures state_eq_opt true (BS.machine_eval_codes cs f s1) (BS.machine_eval_codes cs f s2))
[SMTPat (BS.machine_eval_codes cs f s1); SMTPat (BS.machine_eval_codes cs f s2)]
=
eval_codes_eq_core true cs f s1; eval_codes_eq_core true cs f s2
let eval_while_eq_t (cond:ocmp) (body:code) (f:fuel) (s1 s2:machine_state) : Lemma
(requires state_eq_S true s1 s2)
(ensures state_eq_opt true (BS.machine_eval_while cond body f s1) (BS.machine_eval_while cond body f s2))
[SMTPat (BS.machine_eval_while cond body f s1); SMTPat (BS.machine_eval_while cond body f s2)]
=
eval_while_eq_core true cond body f s1; eval_while_eq_core true cond body f s2
let eval_code_ts (g:bool) (c:code) (s0:machine_state) (f0:fuel) (s1:machine_state) : Type0 =
state_eq_opt g (BS.machine_eval_code c f0 s0) (Some s1)
let rec increase_fuel (g:bool) (c:code) (s0:machine_state) (f0:fuel) (sN:machine_state) (fN:fuel) : Lemma
(requires eval_code_ts g c s0 f0 sN /\ f0 <= fN)
(ensures eval_code_ts g c s0 fN sN)
(decreases %[f0; c])
=
match c with
| Ins ins -> ()
| Block l -> increase_fuels g l s0 f0 sN fN
| IfElse cond t f ->
let (s0, b0) = BS.machine_eval_ocmp s0 cond in
if b0 then increase_fuel g t s0 f0 sN fN else increase_fuel g f s0 f0 sN fN
| While cond c ->
let (s1, b0) = BS.machine_eval_ocmp s0 cond in
if b0 then (
match BS.machine_eval_code c (f0 - 1) s1 with
| None -> ()
| Some s2 ->
increase_fuel g c s1 (f0 - 1) s2 (fN - 1);
if s2.BS.ms_ok then increase_fuel g (While cond c) s2 (f0 - 1) sN (fN - 1)
else ()
)
and increase_fuels (g:bool) (c:codes) (s0:machine_state) (f0:fuel) (sN:machine_state) (fN:fuel) : Lemma
(requires eval_code_ts g (Block c) s0 f0 sN /\ f0 <= fN)
(ensures eval_code_ts g (Block c) s0 fN sN)
(decreases %[f0; c])
=
match c with
| [] -> ()
| h::t ->
(
let Some s1 = BS.machine_eval_code h f0 s0 in
increase_fuel g h s0 f0 s1 fN;
increase_fuels g t s1 f0 sN fN
) | false | false | Vale.X64.Lemmas.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": 30,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val lemma_cmp_eq (s:vale_state) (o1:operand64{not (OMem? o1 || OStack? o1)}) (o2:operand64{not (OMem? o2 || OStack? o2)}) : Lemma
(ensures eval_ocmp s (OEq o1 o2) <==> eval_operand o1 s == eval_operand o2 s)
[SMTPat (eval_ocmp s (OEq o1 o2))] | [] | Vale.X64.Lemmas.lemma_cmp_eq | {
"file_name": "vale/code/arch/x64/Vale.X64.Lemmas.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} |
s: Vale.X64.State.vale_state ->
o1: Vale.X64.Machine_s.operand64{Prims.op_Negation (OMem? o1 || OStack? o1)} ->
o2: Vale.X64.Machine_s.operand64{Prims.op_Negation (OMem? o2 || OStack? o2)}
-> FStar.Pervasives.Lemma
(ensures
Vale.X64.Lemmas.eval_ocmp s (Vale.X64.Bytes_Code_s.OEq o1 o2) <==>
Vale.X64.State.eval_operand o1 s == Vale.X64.State.eval_operand o2 s)
[SMTPat (Vale.X64.Lemmas.eval_ocmp s (Vale.X64.Bytes_Code_s.OEq o1 o2))] | {
"end_col": 84,
"end_line": 333,
"start_col": 27,
"start_line": 333
} |
FStar.Pervasives.Lemma | val lemma_cmp_ne (s:vale_state) (o1:operand64{not (OMem? o1 || OStack? o1)}) (o2:operand64{not (OMem? o2 || OStack? o2)}) : Lemma
(ensures eval_ocmp s (ONe o1 o2) <==> eval_operand o1 s <> eval_operand o2 s)
[SMTPat (eval_ocmp s (ONe o1 o2))] | [
{
"abbrev": true,
"full_module": "Vale.X64.Memory",
"short_module": "ME"
},
{
"abbrev": false,
"full_module": "Vale.X64.Instruction_s",
"short_module": null
},
{
"abbrev": true,
"full_module": "Vale.Lib.Map16",
"short_module": "Map16"
},
{
"abbrev": true,
"full_module": "Vale.X64.Machine_Semantics_s",
"short_module": "BS"
},
{
"abbrev": false,
"full_module": "Vale.X64.Bytes_Code_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.StateLemmas",
"short_module": null
},
{
"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.HeapLemmas",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.HeapImpl",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Heap",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"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 lemma_cmp_ne s o1 o2 = reveal_opaque (`%BS.eval_ocmp_opaque) BS.eval_ocmp_opaque | val lemma_cmp_ne (s:vale_state) (o1:operand64{not (OMem? o1 || OStack? o1)}) (o2:operand64{not (OMem? o2 || OStack? o2)}) : Lemma
(ensures eval_ocmp s (ONe o1 o2) <==> eval_operand o1 s <> eval_operand o2 s)
[SMTPat (eval_ocmp s (ONe o1 o2))]
let lemma_cmp_ne s o1 o2 = | false | null | true | reveal_opaque (`%BS.eval_ocmp_opaque) BS.eval_ocmp_opaque | {
"checked_file": "Vale.X64.Lemmas.fst.checked",
"dependencies": [
"Vale.X64.StateLemmas.fsti.checked",
"Vale.X64.State.fsti.checked",
"Vale.X64.Memory.fsti.checked",
"Vale.X64.Machine_Semantics_s.fst.checked",
"Vale.X64.Machine_s.fst.checked",
"Vale.X64.Instruction_s.fsti.checked",
"Vale.X64.Flags.fsti.checked",
"Vale.X64.Bytes_Code_s.fst.checked",
"prims.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.FunctionalExtensionality.fsti.checked"
],
"interface_file": true,
"source_file": "Vale.X64.Lemmas.fst"
} | [
"lemma"
] | [
"Vale.X64.State.vale_state",
"Vale.X64.Machine_s.operand64",
"Prims.b2t",
"Prims.op_Negation",
"Prims.op_BarBar",
"Vale.X64.Machine_s.uu___is_OMem",
"Vale.X64.Machine_s.nat64",
"Vale.X64.Machine_s.reg_64",
"Vale.X64.Machine_s.uu___is_OStack",
"FStar.Pervasives.reveal_opaque",
"Vale.X64.Machine_Semantics_s.machine_state",
"Vale.X64.Machine_Semantics_s.ocmp",
"Prims.bool",
"Vale.X64.Machine_Semantics_s.eval_ocmp_opaque",
"Prims.unit"
] | [] | module Vale.X64.Lemmas
open FStar.Mul
open Vale.X64.Machine_s
open Vale.X64.State
open Vale.X64.StateLemmas
open Vale.X64.Instruction_s
open Vale.X64.Bytes_Code_s
module BS = Vale.X64.Machine_Semantics_s
module ME = Vale.X64.Memory
#reset-options "--initial_fuel 1 --max_fuel 1 --z3rlimit 100"
#restart-solver
let rec lemma_eq_instr_apply_eval_args
(outs:list instr_out) (args:list instr_operand)
(f:instr_args_t outs args) (oprs:instr_operands_t_args args) (s1 s2:machine_state)
: Lemma
(requires state_eq_S true s1 s2)
(ensures
BS.instr_apply_eval_args outs args f oprs s1 ==
BS.instr_apply_eval_args outs args f oprs s2)
=
let open BS in
lemma_heap_ignore_ghost_machine s1.BS.ms_heap s2.BS.ms_heap;
match args with
| [] -> ()
| i::args ->
(
let (v, oprs) : option (instr_val_t i) & instr_operands_t_args args =
match i with
| IOpEx i -> let oprs = coerce oprs in (instr_eval_operand_explicit i (fst oprs) s1, snd oprs)
| IOpIm i -> (instr_eval_operand_implicit i s1, coerce oprs)
in
let f:arrow (instr_val_t i) (instr_args_t outs args) = coerce f in
match v with
| None -> ()
| Some v -> lemma_eq_instr_apply_eval_args outs args (f v) oprs s1 s2
)
#restart-solver
let rec lemma_eq_instr_apply_eval_inouts
(outs inouts:list instr_out) (args:list instr_operand)
(f:instr_inouts_t outs inouts args) (oprs:instr_operands_t inouts args) (s1 s2:machine_state)
: Lemma
(requires state_eq_S true s1 s2)
(ensures
BS.instr_apply_eval_inouts outs inouts args f oprs s1 ==
BS.instr_apply_eval_inouts outs inouts args f oprs s2)
=
let open BS in
lemma_heap_ignore_ghost_machine s1.BS.ms_heap s2.BS.ms_heap;
match inouts with
| [] -> lemma_eq_instr_apply_eval_args outs args f oprs s1 s2
| (Out, i)::inouts ->
let oprs =
match i with
| IOpEx i -> snd #(instr_operand_t i) (coerce oprs)
| IOpIm i -> coerce oprs
in
lemma_eq_instr_apply_eval_inouts outs inouts args (coerce f) oprs s1 s2
| (InOut, i)::inouts ->
(
let (v, oprs) : option (instr_val_t i) & instr_operands_t inouts args =
match i with
| IOpEx i -> let oprs = coerce oprs in (instr_eval_operand_explicit i (fst oprs) s1, snd oprs)
| IOpIm i -> (instr_eval_operand_implicit i s1, coerce oprs)
in
let f:arrow (instr_val_t i) (instr_inouts_t outs inouts args) = coerce f in
match v with
| None -> ()
| Some v -> lemma_eq_instr_apply_eval_inouts outs inouts args (f v) oprs s1 s2
)
#restart-solver
#push-options "--z3rlimit_factor 2"
let rec lemma_eq_instr_write_outputs
(outs:list instr_out) (args:list instr_operand)
(vs:instr_ret_t outs) (oprs:instr_operands_t outs args) (s1_orig s1 s2_orig s2:machine_state)
: Lemma
(requires state_eq_S true s1_orig s2_orig /\ state_eq_S true s1 s2)
(ensures
state_eq_S true
(BS.instr_write_outputs outs args vs oprs s1_orig s1)
(BS.instr_write_outputs outs args vs oprs s2_orig s2))
=
let open BS in
use_machine_state_equal ();
lemma_heap_ignore_ghost_machine s1.BS.ms_heap s2.BS.ms_heap;
lemma_heap_ignore_ghost_machine s1_orig.BS.ms_heap s2_orig.BS.ms_heap;
allow_inversion tmaddr;
match outs with
| [] -> ()
| (_, i)::outs ->
(
let ((v:instr_val_t i), (vs:instr_ret_t outs)) =
match outs with
| [] -> (vs, ())
| _::_ -> let vs = coerce vs in (fst vs, snd vs)
in
match i with
| IOpEx i ->
let oprs = coerce oprs in
let s1 = instr_write_output_explicit i v (fst oprs) s1_orig s1 in
let s2 = instr_write_output_explicit i v (fst oprs) s2_orig s2 in
lemma_eq_instr_write_outputs outs args vs (snd oprs) s1_orig s1 s2_orig s2
| IOpIm i ->
let s1 = instr_write_output_implicit i v s1_orig s1 in
let s2 = instr_write_output_implicit i v s2_orig s2 in
allow_inversion operand64;
allow_inversion operand128;
lemma_eq_instr_write_outputs outs args vs (coerce oprs) s1_orig s1 s2_orig s2
)
#pop-options
#restart-solver
let eval_ins_eq_instr (inst:BS.ins) (s1 s2:machine_state) : Lemma
(requires Instr? inst /\ state_eq_S true s1 s2)
(ensures state_eq_S true (BS.machine_eval_ins inst s1) (BS.machine_eval_ins inst s2))
=
let open BS in
let Instr it oprs ann = inst in
let InstrTypeRecord #outs #args #havoc_flags' i = it in
lemma_eq_instr_apply_eval_inouts outs outs args (instr_eval i) oprs s1 s2;
let vs = instr_apply_eval outs args (instr_eval i) oprs s1 in
let hav s =
match havoc_flags' with
| HavocFlags -> {s with ms_flags = havoc_flags}
| PreserveFlags -> s
in
let s1' = hav s1 in
let s2' = hav s2 in
match vs with
| None -> ()
| Some vs -> lemma_eq_instr_write_outputs outs args vs oprs s1 s1' s2 s2'
let eval_code_eq_instr (inst:BS.ins) (f:fuel) (s1 s2:machine_state) : Lemma
(requires Instr? inst /\ state_eq_S true s1 s2)
(ensures state_eq_opt true (BS.machine_eval_code (Ins inst) f s1) (BS.machine_eval_code (Ins inst) f s2))
=
reveal_opaque (`%BS.machine_eval_code_ins) BS.machine_eval_code_ins;
eval_ins_eq_instr inst ({s1 with BS.ms_trace = []}) ({s2 with BS.ms_trace = []})
let eval_code_eq_dealloc (inst:BS.ins) (f:fuel) (s1 s2:machine_state) : Lemma
(requires Dealloc? inst /\ state_eq_S true s1 s2)
(ensures state_eq_opt true (BS.machine_eval_code (Ins inst) f s1) (BS.machine_eval_code (Ins inst) f s2))
=
reveal_opaque (`%BS.machine_eval_code_ins) BS.machine_eval_code_ins;
use_machine_state_equal ();
lemma_heap_ignore_ghost_machine s1.BS.ms_heap s2.BS.ms_heap;
allow_inversion tmaddr
let eval_code_eq_alloc (inst:BS.ins) (f:fuel) (s1 s2:machine_state) : Lemma
(requires Alloc? inst /\ state_eq_S true s1 s2)
(ensures state_eq_opt true (BS.machine_eval_code (Ins inst) f s1) (BS.machine_eval_code (Ins inst) f s2))
=
reveal_opaque (`%BS.machine_eval_code_ins) BS.machine_eval_code_ins;
use_machine_state_equal ();
lemma_heap_ignore_ghost_machine s1.BS.ms_heap s2.BS.ms_heap;
allow_inversion tmaddr
let eval_code_eq_push (inst:BS.ins) (f:fuel) (s1 s2:machine_state) : Lemma
(requires Push? inst /\ state_eq_S true s1 s2)
(ensures state_eq_opt true (BS.machine_eval_code (Ins inst) f s1) (BS.machine_eval_code (Ins inst) f s2))
=
reveal_opaque (`%BS.machine_eval_code_ins) BS.machine_eval_code_ins;
use_machine_state_equal ();
lemma_heap_ignore_ghost_machine s1.BS.ms_heap s2.BS.ms_heap;
allow_inversion tmaddr
let eval_code_eq_pop (inst:BS.ins) (f:fuel) (s1 s2:machine_state) : Lemma
(requires Pop? inst /\ state_eq_S true s1 s2)
(ensures state_eq_opt true (BS.machine_eval_code (Ins inst) f s1) (BS.machine_eval_code (Ins inst) f s2))
=
reveal_opaque (`%BS.machine_eval_code_ins) BS.machine_eval_code_ins;
use_machine_state_equal ();
lemma_heap_ignore_ghost_machine s1.BS.ms_heap s2.BS.ms_heap;
allow_inversion tmaddr
let eval_code_eq_ins (i:BS.ins) (f:fuel) (s1 s2:machine_state) : Lemma
(requires state_eq_S true s1 s2)
(ensures state_eq_opt true (BS.machine_eval_code (Ins i) f s1) (BS.machine_eval_code (Ins i) f s2))
=
match i with
| Instr _ _ _ -> eval_code_eq_instr i f s1 s2
| Dealloc _ -> eval_code_eq_dealloc i f s1 s2
| Alloc _ -> eval_code_eq_alloc i f s1 s2
| Push _ _ -> eval_code_eq_push i f s1 s2
| Pop _ _ -> eval_code_eq_pop i f s1 s2
#reset-options "--fuel 2 --z3rlimit 30"
let eval_ocmp_eq_core (g:bool) (cond:ocmp) (s:machine_state) : Lemma
(ensures (
let (s1, b1) = BS.machine_eval_ocmp s cond in
let (s2, b2) = BS.machine_eval_ocmp (core_state g s) cond in
state_eq_S g s1 s2 /\ b1 == b2
))
=
reveal_opaque (`%BS.valid_ocmp_opaque) BS.valid_ocmp_opaque;
reveal_opaque (`%BS.eval_ocmp_opaque) BS.eval_ocmp_opaque;
()
#restart-solver
let rec eval_code_eq_core (g:bool) (c:code) (f:fuel) (s:machine_state) : Lemma
(ensures state_eq_opt g (BS.machine_eval_code c f s) (BS.machine_eval_code c f (core_state g s)))
(decreases %[f; c])
=
match c with
| Ins i ->
reveal_opaque (`%BS.machine_eval_code_ins) BS.machine_eval_code_ins;
if g then eval_code_eq_ins i f s (core_state g s)
| Block cs -> eval_codes_eq_core g cs f s
| IfElse cond ct cf ->
eval_ocmp_eq_core g cond s;
let (s', _) = BS.machine_eval_ocmp s cond in
let (t', _) = BS.machine_eval_ocmp (core_state g s) cond in
eval_code_eq_core g ct f s';
eval_code_eq_core g ct f t';
eval_code_eq_core g cf f s';
eval_code_eq_core g cf f t';
()
| While cond body -> eval_while_eq_core g cond body f s
and eval_codes_eq_core (g:bool) (cs:codes) (f:fuel) (s:machine_state) : Lemma
(ensures state_eq_opt g (BS.machine_eval_codes cs f s) (BS.machine_eval_codes cs f (core_state g s)))
(decreases %[f; cs])
=
match cs with
| [] -> ()
| c'::cs' -> (
eval_code_eq_core g c' f s;
match (machine_eval_code c' f s, machine_eval_code c' f (core_state g s)) with
| (None, None) -> ()
| (Some s', Some t') -> eval_codes_eq_core g cs' f s'; eval_codes_eq_core g cs' f t'
)
and eval_while_eq_core (g:bool) (cond:ocmp) (body:code) (f:fuel) (s:machine_state) : Lemma
(ensures state_eq_opt g (BS.machine_eval_while cond body f s) (BS.machine_eval_while cond body f (core_state g s)))
(decreases %[f; body])
=
if f > 0 then (
eval_ocmp_eq_core g cond s;
let (s1, _) = BS.machine_eval_ocmp s cond in
let (t1, _) = BS.machine_eval_ocmp (core_state g s) cond in
eval_code_eq_core g body (f - 1) s1;
eval_code_eq_core g body (f - 1) t1;
match (BS.machine_eval_code body (f - 1) s1, BS.machine_eval_code body (f - 1) t1) with
| (None, None) -> ()
| (Some s2, Some t2) ->
eval_while_eq_core g cond body (f - 1) s2;
eval_while_eq_core g cond body (f - 1) t2;
()
)
let eval_code_eq_f (c:code) (f:fuel) (s1 s2:machine_state) : Lemma
(requires state_eq_S false s1 s2)
(ensures state_eq_opt false (BS.machine_eval_code c f s1) (BS.machine_eval_code c f s2))
[SMTPat (BS.machine_eval_code c f s1); SMTPat (BS.machine_eval_code c f s2)]
=
eval_code_eq_core false c f s1; eval_code_eq_core false c f s2
let eval_codes_eq_f (cs:codes) (f:fuel) (s1 s2:machine_state) : Lemma
(requires state_eq_S false s1 s2)
(ensures state_eq_opt false (BS.machine_eval_codes cs f s1) (BS.machine_eval_codes cs f s2))
[SMTPat (BS.machine_eval_codes cs f s1); SMTPat (BS.machine_eval_codes cs f s2)]
=
eval_codes_eq_core false cs f s1; eval_codes_eq_core false cs f s2
let eval_while_eq_f (cond:ocmp) (body:code) (f:fuel) (s1 s2:machine_state) : Lemma
(requires state_eq_S false s1 s2)
(ensures state_eq_opt false (BS.machine_eval_while cond body f s1) (BS.machine_eval_while cond body f s2))
[SMTPat (BS.machine_eval_while cond body f s1); SMTPat (BS.machine_eval_while cond body f s2)]
=
eval_while_eq_core false cond body f s1; eval_while_eq_core false cond body f s2
let eval_code_eq_t (c:code) (f:fuel) (s1 s2:machine_state) : Lemma
(requires state_eq_S true s1 s2)
(ensures state_eq_opt true (BS.machine_eval_code c f s1) (BS.machine_eval_code c f s2))
[SMTPat (BS.machine_eval_code c f s1); SMTPat (BS.machine_eval_code c f s2)]
=
eval_code_eq_core true c f s1; eval_code_eq_core true c f s2
let eval_codes_eq_t (cs:codes) (f:fuel) (s1 s2:machine_state) : Lemma
(requires state_eq_S true s1 s2)
(ensures state_eq_opt true (BS.machine_eval_codes cs f s1) (BS.machine_eval_codes cs f s2))
[SMTPat (BS.machine_eval_codes cs f s1); SMTPat (BS.machine_eval_codes cs f s2)]
=
eval_codes_eq_core true cs f s1; eval_codes_eq_core true cs f s2
let eval_while_eq_t (cond:ocmp) (body:code) (f:fuel) (s1 s2:machine_state) : Lemma
(requires state_eq_S true s1 s2)
(ensures state_eq_opt true (BS.machine_eval_while cond body f s1) (BS.machine_eval_while cond body f s2))
[SMTPat (BS.machine_eval_while cond body f s1); SMTPat (BS.machine_eval_while cond body f s2)]
=
eval_while_eq_core true cond body f s1; eval_while_eq_core true cond body f s2
let eval_code_ts (g:bool) (c:code) (s0:machine_state) (f0:fuel) (s1:machine_state) : Type0 =
state_eq_opt g (BS.machine_eval_code c f0 s0) (Some s1)
let rec increase_fuel (g:bool) (c:code) (s0:machine_state) (f0:fuel) (sN:machine_state) (fN:fuel) : Lemma
(requires eval_code_ts g c s0 f0 sN /\ f0 <= fN)
(ensures eval_code_ts g c s0 fN sN)
(decreases %[f0; c])
=
match c with
| Ins ins -> ()
| Block l -> increase_fuels g l s0 f0 sN fN
| IfElse cond t f ->
let (s0, b0) = BS.machine_eval_ocmp s0 cond in
if b0 then increase_fuel g t s0 f0 sN fN else increase_fuel g f s0 f0 sN fN
| While cond c ->
let (s1, b0) = BS.machine_eval_ocmp s0 cond in
if b0 then (
match BS.machine_eval_code c (f0 - 1) s1 with
| None -> ()
| Some s2 ->
increase_fuel g c s1 (f0 - 1) s2 (fN - 1);
if s2.BS.ms_ok then increase_fuel g (While cond c) s2 (f0 - 1) sN (fN - 1)
else ()
)
and increase_fuels (g:bool) (c:codes) (s0:machine_state) (f0:fuel) (sN:machine_state) (fN:fuel) : Lemma
(requires eval_code_ts g (Block c) s0 f0 sN /\ f0 <= fN)
(ensures eval_code_ts g (Block c) s0 fN sN)
(decreases %[f0; c])
=
match c with
| [] -> ()
| h::t ->
(
let Some s1 = BS.machine_eval_code h f0 s0 in
increase_fuel g h s0 f0 s1 fN;
increase_fuels g t s1 f0 sN fN
) | false | false | Vale.X64.Lemmas.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": 30,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val lemma_cmp_ne (s:vale_state) (o1:operand64{not (OMem? o1 || OStack? o1)}) (o2:operand64{not (OMem? o2 || OStack? o2)}) : Lemma
(ensures eval_ocmp s (ONe o1 o2) <==> eval_operand o1 s <> eval_operand o2 s)
[SMTPat (eval_ocmp s (ONe o1 o2))] | [] | Vale.X64.Lemmas.lemma_cmp_ne | {
"file_name": "vale/code/arch/x64/Vale.X64.Lemmas.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} |
s: Vale.X64.State.vale_state ->
o1: Vale.X64.Machine_s.operand64{Prims.op_Negation (OMem? o1 || OStack? o1)} ->
o2: Vale.X64.Machine_s.operand64{Prims.op_Negation (OMem? o2 || OStack? o2)}
-> FStar.Pervasives.Lemma
(ensures
Vale.X64.Lemmas.eval_ocmp s (Vale.X64.Bytes_Code_s.ONe o1 o2) <==>
Vale.X64.State.eval_operand o1 s <> Vale.X64.State.eval_operand o2 s)
[SMTPat (Vale.X64.Lemmas.eval_ocmp s (Vale.X64.Bytes_Code_s.ONe o1 o2))] | {
"end_col": 84,
"end_line": 334,
"start_col": 27,
"start_line": 334
} |
FStar.Pervasives.Lemma | val lemma_cmp_le (s:vale_state) (o1:operand64{not (OMem? o1 || OStack? o1)}) (o2:operand64{not (OMem? o2 || OStack? o2)}) : Lemma
(ensures eval_ocmp s (OLe o1 o2) <==> eval_operand o1 s <= eval_operand o2 s)
[SMTPat (eval_ocmp s (OLe o1 o2))] | [
{
"abbrev": true,
"full_module": "Vale.X64.Memory",
"short_module": "ME"
},
{
"abbrev": false,
"full_module": "Vale.X64.Instruction_s",
"short_module": null
},
{
"abbrev": true,
"full_module": "Vale.Lib.Map16",
"short_module": "Map16"
},
{
"abbrev": true,
"full_module": "Vale.X64.Machine_Semantics_s",
"short_module": "BS"
},
{
"abbrev": false,
"full_module": "Vale.X64.Bytes_Code_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.StateLemmas",
"short_module": null
},
{
"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.HeapLemmas",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.HeapImpl",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Heap",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"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 lemma_cmp_le s o1 o2 = reveal_opaque (`%BS.eval_ocmp_opaque) BS.eval_ocmp_opaque | val lemma_cmp_le (s:vale_state) (o1:operand64{not (OMem? o1 || OStack? o1)}) (o2:operand64{not (OMem? o2 || OStack? o2)}) : Lemma
(ensures eval_ocmp s (OLe o1 o2) <==> eval_operand o1 s <= eval_operand o2 s)
[SMTPat (eval_ocmp s (OLe o1 o2))]
let lemma_cmp_le s o1 o2 = | false | null | true | reveal_opaque (`%BS.eval_ocmp_opaque) BS.eval_ocmp_opaque | {
"checked_file": "Vale.X64.Lemmas.fst.checked",
"dependencies": [
"Vale.X64.StateLemmas.fsti.checked",
"Vale.X64.State.fsti.checked",
"Vale.X64.Memory.fsti.checked",
"Vale.X64.Machine_Semantics_s.fst.checked",
"Vale.X64.Machine_s.fst.checked",
"Vale.X64.Instruction_s.fsti.checked",
"Vale.X64.Flags.fsti.checked",
"Vale.X64.Bytes_Code_s.fst.checked",
"prims.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.FunctionalExtensionality.fsti.checked"
],
"interface_file": true,
"source_file": "Vale.X64.Lemmas.fst"
} | [
"lemma"
] | [
"Vale.X64.State.vale_state",
"Vale.X64.Machine_s.operand64",
"Prims.b2t",
"Prims.op_Negation",
"Prims.op_BarBar",
"Vale.X64.Machine_s.uu___is_OMem",
"Vale.X64.Machine_s.nat64",
"Vale.X64.Machine_s.reg_64",
"Vale.X64.Machine_s.uu___is_OStack",
"FStar.Pervasives.reveal_opaque",
"Vale.X64.Machine_Semantics_s.machine_state",
"Vale.X64.Machine_Semantics_s.ocmp",
"Prims.bool",
"Vale.X64.Machine_Semantics_s.eval_ocmp_opaque",
"Prims.unit"
] | [] | module Vale.X64.Lemmas
open FStar.Mul
open Vale.X64.Machine_s
open Vale.X64.State
open Vale.X64.StateLemmas
open Vale.X64.Instruction_s
open Vale.X64.Bytes_Code_s
module BS = Vale.X64.Machine_Semantics_s
module ME = Vale.X64.Memory
#reset-options "--initial_fuel 1 --max_fuel 1 --z3rlimit 100"
#restart-solver
let rec lemma_eq_instr_apply_eval_args
(outs:list instr_out) (args:list instr_operand)
(f:instr_args_t outs args) (oprs:instr_operands_t_args args) (s1 s2:machine_state)
: Lemma
(requires state_eq_S true s1 s2)
(ensures
BS.instr_apply_eval_args outs args f oprs s1 ==
BS.instr_apply_eval_args outs args f oprs s2)
=
let open BS in
lemma_heap_ignore_ghost_machine s1.BS.ms_heap s2.BS.ms_heap;
match args with
| [] -> ()
| i::args ->
(
let (v, oprs) : option (instr_val_t i) & instr_operands_t_args args =
match i with
| IOpEx i -> let oprs = coerce oprs in (instr_eval_operand_explicit i (fst oprs) s1, snd oprs)
| IOpIm i -> (instr_eval_operand_implicit i s1, coerce oprs)
in
let f:arrow (instr_val_t i) (instr_args_t outs args) = coerce f in
match v with
| None -> ()
| Some v -> lemma_eq_instr_apply_eval_args outs args (f v) oprs s1 s2
)
#restart-solver
let rec lemma_eq_instr_apply_eval_inouts
(outs inouts:list instr_out) (args:list instr_operand)
(f:instr_inouts_t outs inouts args) (oprs:instr_operands_t inouts args) (s1 s2:machine_state)
: Lemma
(requires state_eq_S true s1 s2)
(ensures
BS.instr_apply_eval_inouts outs inouts args f oprs s1 ==
BS.instr_apply_eval_inouts outs inouts args f oprs s2)
=
let open BS in
lemma_heap_ignore_ghost_machine s1.BS.ms_heap s2.BS.ms_heap;
match inouts with
| [] -> lemma_eq_instr_apply_eval_args outs args f oprs s1 s2
| (Out, i)::inouts ->
let oprs =
match i with
| IOpEx i -> snd #(instr_operand_t i) (coerce oprs)
| IOpIm i -> coerce oprs
in
lemma_eq_instr_apply_eval_inouts outs inouts args (coerce f) oprs s1 s2
| (InOut, i)::inouts ->
(
let (v, oprs) : option (instr_val_t i) & instr_operands_t inouts args =
match i with
| IOpEx i -> let oprs = coerce oprs in (instr_eval_operand_explicit i (fst oprs) s1, snd oprs)
| IOpIm i -> (instr_eval_operand_implicit i s1, coerce oprs)
in
let f:arrow (instr_val_t i) (instr_inouts_t outs inouts args) = coerce f in
match v with
| None -> ()
| Some v -> lemma_eq_instr_apply_eval_inouts outs inouts args (f v) oprs s1 s2
)
#restart-solver
#push-options "--z3rlimit_factor 2"
let rec lemma_eq_instr_write_outputs
(outs:list instr_out) (args:list instr_operand)
(vs:instr_ret_t outs) (oprs:instr_operands_t outs args) (s1_orig s1 s2_orig s2:machine_state)
: Lemma
(requires state_eq_S true s1_orig s2_orig /\ state_eq_S true s1 s2)
(ensures
state_eq_S true
(BS.instr_write_outputs outs args vs oprs s1_orig s1)
(BS.instr_write_outputs outs args vs oprs s2_orig s2))
=
let open BS in
use_machine_state_equal ();
lemma_heap_ignore_ghost_machine s1.BS.ms_heap s2.BS.ms_heap;
lemma_heap_ignore_ghost_machine s1_orig.BS.ms_heap s2_orig.BS.ms_heap;
allow_inversion tmaddr;
match outs with
| [] -> ()
| (_, i)::outs ->
(
let ((v:instr_val_t i), (vs:instr_ret_t outs)) =
match outs with
| [] -> (vs, ())
| _::_ -> let vs = coerce vs in (fst vs, snd vs)
in
match i with
| IOpEx i ->
let oprs = coerce oprs in
let s1 = instr_write_output_explicit i v (fst oprs) s1_orig s1 in
let s2 = instr_write_output_explicit i v (fst oprs) s2_orig s2 in
lemma_eq_instr_write_outputs outs args vs (snd oprs) s1_orig s1 s2_orig s2
| IOpIm i ->
let s1 = instr_write_output_implicit i v s1_orig s1 in
let s2 = instr_write_output_implicit i v s2_orig s2 in
allow_inversion operand64;
allow_inversion operand128;
lemma_eq_instr_write_outputs outs args vs (coerce oprs) s1_orig s1 s2_orig s2
)
#pop-options
#restart-solver
let eval_ins_eq_instr (inst:BS.ins) (s1 s2:machine_state) : Lemma
(requires Instr? inst /\ state_eq_S true s1 s2)
(ensures state_eq_S true (BS.machine_eval_ins inst s1) (BS.machine_eval_ins inst s2))
=
let open BS in
let Instr it oprs ann = inst in
let InstrTypeRecord #outs #args #havoc_flags' i = it in
lemma_eq_instr_apply_eval_inouts outs outs args (instr_eval i) oprs s1 s2;
let vs = instr_apply_eval outs args (instr_eval i) oprs s1 in
let hav s =
match havoc_flags' with
| HavocFlags -> {s with ms_flags = havoc_flags}
| PreserveFlags -> s
in
let s1' = hav s1 in
let s2' = hav s2 in
match vs with
| None -> ()
| Some vs -> lemma_eq_instr_write_outputs outs args vs oprs s1 s1' s2 s2'
let eval_code_eq_instr (inst:BS.ins) (f:fuel) (s1 s2:machine_state) : Lemma
(requires Instr? inst /\ state_eq_S true s1 s2)
(ensures state_eq_opt true (BS.machine_eval_code (Ins inst) f s1) (BS.machine_eval_code (Ins inst) f s2))
=
reveal_opaque (`%BS.machine_eval_code_ins) BS.machine_eval_code_ins;
eval_ins_eq_instr inst ({s1 with BS.ms_trace = []}) ({s2 with BS.ms_trace = []})
let eval_code_eq_dealloc (inst:BS.ins) (f:fuel) (s1 s2:machine_state) : Lemma
(requires Dealloc? inst /\ state_eq_S true s1 s2)
(ensures state_eq_opt true (BS.machine_eval_code (Ins inst) f s1) (BS.machine_eval_code (Ins inst) f s2))
=
reveal_opaque (`%BS.machine_eval_code_ins) BS.machine_eval_code_ins;
use_machine_state_equal ();
lemma_heap_ignore_ghost_machine s1.BS.ms_heap s2.BS.ms_heap;
allow_inversion tmaddr
let eval_code_eq_alloc (inst:BS.ins) (f:fuel) (s1 s2:machine_state) : Lemma
(requires Alloc? inst /\ state_eq_S true s1 s2)
(ensures state_eq_opt true (BS.machine_eval_code (Ins inst) f s1) (BS.machine_eval_code (Ins inst) f s2))
=
reveal_opaque (`%BS.machine_eval_code_ins) BS.machine_eval_code_ins;
use_machine_state_equal ();
lemma_heap_ignore_ghost_machine s1.BS.ms_heap s2.BS.ms_heap;
allow_inversion tmaddr
let eval_code_eq_push (inst:BS.ins) (f:fuel) (s1 s2:machine_state) : Lemma
(requires Push? inst /\ state_eq_S true s1 s2)
(ensures state_eq_opt true (BS.machine_eval_code (Ins inst) f s1) (BS.machine_eval_code (Ins inst) f s2))
=
reveal_opaque (`%BS.machine_eval_code_ins) BS.machine_eval_code_ins;
use_machine_state_equal ();
lemma_heap_ignore_ghost_machine s1.BS.ms_heap s2.BS.ms_heap;
allow_inversion tmaddr
let eval_code_eq_pop (inst:BS.ins) (f:fuel) (s1 s2:machine_state) : Lemma
(requires Pop? inst /\ state_eq_S true s1 s2)
(ensures state_eq_opt true (BS.machine_eval_code (Ins inst) f s1) (BS.machine_eval_code (Ins inst) f s2))
=
reveal_opaque (`%BS.machine_eval_code_ins) BS.machine_eval_code_ins;
use_machine_state_equal ();
lemma_heap_ignore_ghost_machine s1.BS.ms_heap s2.BS.ms_heap;
allow_inversion tmaddr
let eval_code_eq_ins (i:BS.ins) (f:fuel) (s1 s2:machine_state) : Lemma
(requires state_eq_S true s1 s2)
(ensures state_eq_opt true (BS.machine_eval_code (Ins i) f s1) (BS.machine_eval_code (Ins i) f s2))
=
match i with
| Instr _ _ _ -> eval_code_eq_instr i f s1 s2
| Dealloc _ -> eval_code_eq_dealloc i f s1 s2
| Alloc _ -> eval_code_eq_alloc i f s1 s2
| Push _ _ -> eval_code_eq_push i f s1 s2
| Pop _ _ -> eval_code_eq_pop i f s1 s2
#reset-options "--fuel 2 --z3rlimit 30"
let eval_ocmp_eq_core (g:bool) (cond:ocmp) (s:machine_state) : Lemma
(ensures (
let (s1, b1) = BS.machine_eval_ocmp s cond in
let (s2, b2) = BS.machine_eval_ocmp (core_state g s) cond in
state_eq_S g s1 s2 /\ b1 == b2
))
=
reveal_opaque (`%BS.valid_ocmp_opaque) BS.valid_ocmp_opaque;
reveal_opaque (`%BS.eval_ocmp_opaque) BS.eval_ocmp_opaque;
()
#restart-solver
let rec eval_code_eq_core (g:bool) (c:code) (f:fuel) (s:machine_state) : Lemma
(ensures state_eq_opt g (BS.machine_eval_code c f s) (BS.machine_eval_code c f (core_state g s)))
(decreases %[f; c])
=
match c with
| Ins i ->
reveal_opaque (`%BS.machine_eval_code_ins) BS.machine_eval_code_ins;
if g then eval_code_eq_ins i f s (core_state g s)
| Block cs -> eval_codes_eq_core g cs f s
| IfElse cond ct cf ->
eval_ocmp_eq_core g cond s;
let (s', _) = BS.machine_eval_ocmp s cond in
let (t', _) = BS.machine_eval_ocmp (core_state g s) cond in
eval_code_eq_core g ct f s';
eval_code_eq_core g ct f t';
eval_code_eq_core g cf f s';
eval_code_eq_core g cf f t';
()
| While cond body -> eval_while_eq_core g cond body f s
and eval_codes_eq_core (g:bool) (cs:codes) (f:fuel) (s:machine_state) : Lemma
(ensures state_eq_opt g (BS.machine_eval_codes cs f s) (BS.machine_eval_codes cs f (core_state g s)))
(decreases %[f; cs])
=
match cs with
| [] -> ()
| c'::cs' -> (
eval_code_eq_core g c' f s;
match (machine_eval_code c' f s, machine_eval_code c' f (core_state g s)) with
| (None, None) -> ()
| (Some s', Some t') -> eval_codes_eq_core g cs' f s'; eval_codes_eq_core g cs' f t'
)
and eval_while_eq_core (g:bool) (cond:ocmp) (body:code) (f:fuel) (s:machine_state) : Lemma
(ensures state_eq_opt g (BS.machine_eval_while cond body f s) (BS.machine_eval_while cond body f (core_state g s)))
(decreases %[f; body])
=
if f > 0 then (
eval_ocmp_eq_core g cond s;
let (s1, _) = BS.machine_eval_ocmp s cond in
let (t1, _) = BS.machine_eval_ocmp (core_state g s) cond in
eval_code_eq_core g body (f - 1) s1;
eval_code_eq_core g body (f - 1) t1;
match (BS.machine_eval_code body (f - 1) s1, BS.machine_eval_code body (f - 1) t1) with
| (None, None) -> ()
| (Some s2, Some t2) ->
eval_while_eq_core g cond body (f - 1) s2;
eval_while_eq_core g cond body (f - 1) t2;
()
)
let eval_code_eq_f (c:code) (f:fuel) (s1 s2:machine_state) : Lemma
(requires state_eq_S false s1 s2)
(ensures state_eq_opt false (BS.machine_eval_code c f s1) (BS.machine_eval_code c f s2))
[SMTPat (BS.machine_eval_code c f s1); SMTPat (BS.machine_eval_code c f s2)]
=
eval_code_eq_core false c f s1; eval_code_eq_core false c f s2
let eval_codes_eq_f (cs:codes) (f:fuel) (s1 s2:machine_state) : Lemma
(requires state_eq_S false s1 s2)
(ensures state_eq_opt false (BS.machine_eval_codes cs f s1) (BS.machine_eval_codes cs f s2))
[SMTPat (BS.machine_eval_codes cs f s1); SMTPat (BS.machine_eval_codes cs f s2)]
=
eval_codes_eq_core false cs f s1; eval_codes_eq_core false cs f s2
let eval_while_eq_f (cond:ocmp) (body:code) (f:fuel) (s1 s2:machine_state) : Lemma
(requires state_eq_S false s1 s2)
(ensures state_eq_opt false (BS.machine_eval_while cond body f s1) (BS.machine_eval_while cond body f s2))
[SMTPat (BS.machine_eval_while cond body f s1); SMTPat (BS.machine_eval_while cond body f s2)]
=
eval_while_eq_core false cond body f s1; eval_while_eq_core false cond body f s2
let eval_code_eq_t (c:code) (f:fuel) (s1 s2:machine_state) : Lemma
(requires state_eq_S true s1 s2)
(ensures state_eq_opt true (BS.machine_eval_code c f s1) (BS.machine_eval_code c f s2))
[SMTPat (BS.machine_eval_code c f s1); SMTPat (BS.machine_eval_code c f s2)]
=
eval_code_eq_core true c f s1; eval_code_eq_core true c f s2
let eval_codes_eq_t (cs:codes) (f:fuel) (s1 s2:machine_state) : Lemma
(requires state_eq_S true s1 s2)
(ensures state_eq_opt true (BS.machine_eval_codes cs f s1) (BS.machine_eval_codes cs f s2))
[SMTPat (BS.machine_eval_codes cs f s1); SMTPat (BS.machine_eval_codes cs f s2)]
=
eval_codes_eq_core true cs f s1; eval_codes_eq_core true cs f s2
let eval_while_eq_t (cond:ocmp) (body:code) (f:fuel) (s1 s2:machine_state) : Lemma
(requires state_eq_S true s1 s2)
(ensures state_eq_opt true (BS.machine_eval_while cond body f s1) (BS.machine_eval_while cond body f s2))
[SMTPat (BS.machine_eval_while cond body f s1); SMTPat (BS.machine_eval_while cond body f s2)]
=
eval_while_eq_core true cond body f s1; eval_while_eq_core true cond body f s2
let eval_code_ts (g:bool) (c:code) (s0:machine_state) (f0:fuel) (s1:machine_state) : Type0 =
state_eq_opt g (BS.machine_eval_code c f0 s0) (Some s1)
let rec increase_fuel (g:bool) (c:code) (s0:machine_state) (f0:fuel) (sN:machine_state) (fN:fuel) : Lemma
(requires eval_code_ts g c s0 f0 sN /\ f0 <= fN)
(ensures eval_code_ts g c s0 fN sN)
(decreases %[f0; c])
=
match c with
| Ins ins -> ()
| Block l -> increase_fuels g l s0 f0 sN fN
| IfElse cond t f ->
let (s0, b0) = BS.machine_eval_ocmp s0 cond in
if b0 then increase_fuel g t s0 f0 sN fN else increase_fuel g f s0 f0 sN fN
| While cond c ->
let (s1, b0) = BS.machine_eval_ocmp s0 cond in
if b0 then (
match BS.machine_eval_code c (f0 - 1) s1 with
| None -> ()
| Some s2 ->
increase_fuel g c s1 (f0 - 1) s2 (fN - 1);
if s2.BS.ms_ok then increase_fuel g (While cond c) s2 (f0 - 1) sN (fN - 1)
else ()
)
and increase_fuels (g:bool) (c:codes) (s0:machine_state) (f0:fuel) (sN:machine_state) (fN:fuel) : Lemma
(requires eval_code_ts g (Block c) s0 f0 sN /\ f0 <= fN)
(ensures eval_code_ts g (Block c) s0 fN sN)
(decreases %[f0; c])
=
match c with
| [] -> ()
| h::t ->
(
let Some s1 = BS.machine_eval_code h f0 s0 in
increase_fuel g h s0 f0 s1 fN;
increase_fuels g t s1 f0 sN fN
)
let lemma_cmp_eq s o1 o2 = reveal_opaque (`%BS.eval_ocmp_opaque) BS.eval_ocmp_opaque | false | false | Vale.X64.Lemmas.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": 30,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val lemma_cmp_le (s:vale_state) (o1:operand64{not (OMem? o1 || OStack? o1)}) (o2:operand64{not (OMem? o2 || OStack? o2)}) : Lemma
(ensures eval_ocmp s (OLe o1 o2) <==> eval_operand o1 s <= eval_operand o2 s)
[SMTPat (eval_ocmp s (OLe o1 o2))] | [] | Vale.X64.Lemmas.lemma_cmp_le | {
"file_name": "vale/code/arch/x64/Vale.X64.Lemmas.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} |
s: Vale.X64.State.vale_state ->
o1: Vale.X64.Machine_s.operand64{Prims.op_Negation (OMem? o1 || OStack? o1)} ->
o2: Vale.X64.Machine_s.operand64{Prims.op_Negation (OMem? o2 || OStack? o2)}
-> FStar.Pervasives.Lemma
(ensures
Vale.X64.Lemmas.eval_ocmp s (Vale.X64.Bytes_Code_s.OLe o1 o2) <==>
Vale.X64.State.eval_operand o1 s <= Vale.X64.State.eval_operand o2 s)
[SMTPat (Vale.X64.Lemmas.eval_ocmp s (Vale.X64.Bytes_Code_s.OLe o1 o2))] | {
"end_col": 84,
"end_line": 335,
"start_col": 27,
"start_line": 335
} |
FStar.Pervasives.Lemma | val eval_ins_eq_instr (inst: BS.ins) (s1 s2: machine_state)
: Lemma (requires Instr? inst /\ state_eq_S true s1 s2)
(ensures state_eq_S true (BS.machine_eval_ins inst s1) (BS.machine_eval_ins inst s2)) | [
{
"abbrev": true,
"full_module": "Vale.X64.Memory",
"short_module": "ME"
},
{
"abbrev": true,
"full_module": "Vale.X64.Machine_Semantics_s",
"short_module": "BS"
},
{
"abbrev": false,
"full_module": "Vale.X64.Bytes_Code_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Instruction_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.StateLemmas",
"short_module": null
},
{
"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": "FStar.Mul",
"short_module": null
},
{
"abbrev": true,
"full_module": "Vale.Lib.Map16",
"short_module": "Map16"
},
{
"abbrev": true,
"full_module": "Vale.X64.Machine_Semantics_s",
"short_module": "BS"
},
{
"abbrev": false,
"full_module": "Vale.X64.Bytes_Code_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.StateLemmas",
"short_module": null
},
{
"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.HeapLemmas",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.HeapImpl",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Heap",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"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 eval_ins_eq_instr (inst:BS.ins) (s1 s2:machine_state) : Lemma
(requires Instr? inst /\ state_eq_S true s1 s2)
(ensures state_eq_S true (BS.machine_eval_ins inst s1) (BS.machine_eval_ins inst s2))
=
let open BS in
let Instr it oprs ann = inst in
let InstrTypeRecord #outs #args #havoc_flags' i = it in
lemma_eq_instr_apply_eval_inouts outs outs args (instr_eval i) oprs s1 s2;
let vs = instr_apply_eval outs args (instr_eval i) oprs s1 in
let hav s =
match havoc_flags' with
| HavocFlags -> {s with ms_flags = havoc_flags}
| PreserveFlags -> s
in
let s1' = hav s1 in
let s2' = hav s2 in
match vs with
| None -> ()
| Some vs -> lemma_eq_instr_write_outputs outs args vs oprs s1 s1' s2 s2' | val eval_ins_eq_instr (inst: BS.ins) (s1 s2: machine_state)
: Lemma (requires Instr? inst /\ state_eq_S true s1 s2)
(ensures state_eq_S true (BS.machine_eval_ins inst s1) (BS.machine_eval_ins inst s2))
let eval_ins_eq_instr (inst: BS.ins) (s1 s2: machine_state)
: Lemma (requires Instr? inst /\ state_eq_S true s1 s2)
(ensures state_eq_S true (BS.machine_eval_ins inst s1) (BS.machine_eval_ins inst s2)) = | false | null | true | let open BS in
let Instr it oprs ann = inst in
let InstrTypeRecord #outs #args #havoc_flags' i = it in
lemma_eq_instr_apply_eval_inouts outs outs args (instr_eval i) oprs s1 s2;
let vs = instr_apply_eval outs args (instr_eval i) oprs s1 in
let hav s =
match havoc_flags' with
| HavocFlags -> { s with ms_flags = havoc_flags }
| PreserveFlags -> s
in
let s1' = hav s1 in
let s2' = hav s2 in
match vs with
| None -> ()
| Some vs -> lemma_eq_instr_write_outputs outs args vs oprs s1 s1' s2 s2' | {
"checked_file": "Vale.X64.Lemmas.fst.checked",
"dependencies": [
"Vale.X64.StateLemmas.fsti.checked",
"Vale.X64.State.fsti.checked",
"Vale.X64.Memory.fsti.checked",
"Vale.X64.Machine_Semantics_s.fst.checked",
"Vale.X64.Machine_s.fst.checked",
"Vale.X64.Instruction_s.fsti.checked",
"Vale.X64.Flags.fsti.checked",
"Vale.X64.Bytes_Code_s.fst.checked",
"prims.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.FunctionalExtensionality.fsti.checked"
],
"interface_file": true,
"source_file": "Vale.X64.Lemmas.fst"
} | [
"lemma"
] | [
"Vale.X64.Machine_Semantics_s.ins",
"Vale.X64.StateLemmas.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_Semantics_s.instr_annotation",
"Prims.list",
"Vale.X64.Instruction_s.instr_out",
"Vale.X64.Instruction_s.instr_operand",
"Vale.X64.Instruction_s.flag_havoc",
"Vale.X64.Instruction_s.instr_t",
"Vale.X64.Instruction_s.instr_ret_t",
"Vale.X64.Lemmas.lemma_eq_instr_write_outputs",
"Prims.unit",
"Vale.X64.Machine_Semantics_s.machine_state",
"Vale.X64.Machine_Semantics_s.Mkmachine_state",
"Vale.X64.Machine_Semantics_s.__proj__Mkmachine_state__item__ms_ok",
"Vale.X64.Machine_Semantics_s.__proj__Mkmachine_state__item__ms_regs",
"Vale.X64.Machine_Semantics_s.havoc_flags",
"Vale.X64.Machine_Semantics_s.__proj__Mkmachine_state__item__ms_heap",
"Vale.X64.Machine_Semantics_s.__proj__Mkmachine_state__item__ms_stack",
"Vale.X64.Machine_Semantics_s.__proj__Mkmachine_state__item__ms_stackTaint",
"Vale.X64.Machine_Semantics_s.__proj__Mkmachine_state__item__ms_trace",
"FStar.Pervasives.Native.option",
"Vale.X64.Machine_Semantics_s.instr_apply_eval",
"Vale.X64.Instruction_s.instr_eval",
"Vale.X64.Lemmas.lemma_eq_instr_apply_eval_inouts",
"Prims.l_and",
"Prims.b2t",
"Vale.X64.Bytes_Code_s.uu___is_Instr",
"Vale.X64.Lemmas.state_eq_S",
"Prims.squash",
"Vale.X64.Machine_Semantics_s.machine_eval_ins",
"Prims.Nil",
"FStar.Pervasives.pattern"
] | [] | module Vale.X64.Lemmas
open FStar.Mul
open Vale.X64.Machine_s
open Vale.X64.State
open Vale.X64.StateLemmas
open Vale.X64.Instruction_s
open Vale.X64.Bytes_Code_s
module BS = Vale.X64.Machine_Semantics_s
module ME = Vale.X64.Memory
#reset-options "--initial_fuel 1 --max_fuel 1 --z3rlimit 100"
#restart-solver
let rec lemma_eq_instr_apply_eval_args
(outs:list instr_out) (args:list instr_operand)
(f:instr_args_t outs args) (oprs:instr_operands_t_args args) (s1 s2:machine_state)
: Lemma
(requires state_eq_S true s1 s2)
(ensures
BS.instr_apply_eval_args outs args f oprs s1 ==
BS.instr_apply_eval_args outs args f oprs s2)
=
let open BS in
lemma_heap_ignore_ghost_machine s1.BS.ms_heap s2.BS.ms_heap;
match args with
| [] -> ()
| i::args ->
(
let (v, oprs) : option (instr_val_t i) & instr_operands_t_args args =
match i with
| IOpEx i -> let oprs = coerce oprs in (instr_eval_operand_explicit i (fst oprs) s1, snd oprs)
| IOpIm i -> (instr_eval_operand_implicit i s1, coerce oprs)
in
let f:arrow (instr_val_t i) (instr_args_t outs args) = coerce f in
match v with
| None -> ()
| Some v -> lemma_eq_instr_apply_eval_args outs args (f v) oprs s1 s2
)
#restart-solver
let rec lemma_eq_instr_apply_eval_inouts
(outs inouts:list instr_out) (args:list instr_operand)
(f:instr_inouts_t outs inouts args) (oprs:instr_operands_t inouts args) (s1 s2:machine_state)
: Lemma
(requires state_eq_S true s1 s2)
(ensures
BS.instr_apply_eval_inouts outs inouts args f oprs s1 ==
BS.instr_apply_eval_inouts outs inouts args f oprs s2)
=
let open BS in
lemma_heap_ignore_ghost_machine s1.BS.ms_heap s2.BS.ms_heap;
match inouts with
| [] -> lemma_eq_instr_apply_eval_args outs args f oprs s1 s2
| (Out, i)::inouts ->
let oprs =
match i with
| IOpEx i -> snd #(instr_operand_t i) (coerce oprs)
| IOpIm i -> coerce oprs
in
lemma_eq_instr_apply_eval_inouts outs inouts args (coerce f) oprs s1 s2
| (InOut, i)::inouts ->
(
let (v, oprs) : option (instr_val_t i) & instr_operands_t inouts args =
match i with
| IOpEx i -> let oprs = coerce oprs in (instr_eval_operand_explicit i (fst oprs) s1, snd oprs)
| IOpIm i -> (instr_eval_operand_implicit i s1, coerce oprs)
in
let f:arrow (instr_val_t i) (instr_inouts_t outs inouts args) = coerce f in
match v with
| None -> ()
| Some v -> lemma_eq_instr_apply_eval_inouts outs inouts args (f v) oprs s1 s2
)
#restart-solver
#push-options "--z3rlimit_factor 2"
let rec lemma_eq_instr_write_outputs
(outs:list instr_out) (args:list instr_operand)
(vs:instr_ret_t outs) (oprs:instr_operands_t outs args) (s1_orig s1 s2_orig s2:machine_state)
: Lemma
(requires state_eq_S true s1_orig s2_orig /\ state_eq_S true s1 s2)
(ensures
state_eq_S true
(BS.instr_write_outputs outs args vs oprs s1_orig s1)
(BS.instr_write_outputs outs args vs oprs s2_orig s2))
=
let open BS in
use_machine_state_equal ();
lemma_heap_ignore_ghost_machine s1.BS.ms_heap s2.BS.ms_heap;
lemma_heap_ignore_ghost_machine s1_orig.BS.ms_heap s2_orig.BS.ms_heap;
allow_inversion tmaddr;
match outs with
| [] -> ()
| (_, i)::outs ->
(
let ((v:instr_val_t i), (vs:instr_ret_t outs)) =
match outs with
| [] -> (vs, ())
| _::_ -> let vs = coerce vs in (fst vs, snd vs)
in
match i with
| IOpEx i ->
let oprs = coerce oprs in
let s1 = instr_write_output_explicit i v (fst oprs) s1_orig s1 in
let s2 = instr_write_output_explicit i v (fst oprs) s2_orig s2 in
lemma_eq_instr_write_outputs outs args vs (snd oprs) s1_orig s1 s2_orig s2
| IOpIm i ->
let s1 = instr_write_output_implicit i v s1_orig s1 in
let s2 = instr_write_output_implicit i v s2_orig s2 in
allow_inversion operand64;
allow_inversion operand128;
lemma_eq_instr_write_outputs outs args vs (coerce oprs) s1_orig s1 s2_orig s2
)
#pop-options
#restart-solver
let eval_ins_eq_instr (inst:BS.ins) (s1 s2:machine_state) : Lemma
(requires Instr? inst /\ state_eq_S true s1 s2)
(ensures state_eq_S true (BS.machine_eval_ins inst s1) (BS.machine_eval_ins inst s2)) | false | false | Vale.X64.Lemmas.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 1,
"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": 100,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val eval_ins_eq_instr (inst: BS.ins) (s1 s2: machine_state)
: Lemma (requires Instr? inst /\ state_eq_S true s1 s2)
(ensures state_eq_S true (BS.machine_eval_ins inst s1) (BS.machine_eval_ins inst s2)) | [] | Vale.X64.Lemmas.eval_ins_eq_instr | {
"file_name": "vale/code/arch/x64/Vale.X64.Lemmas.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} |
inst: Vale.X64.Machine_Semantics_s.ins ->
s1: Vale.X64.StateLemmas.machine_state ->
s2: Vale.X64.StateLemmas.machine_state
-> FStar.Pervasives.Lemma (requires Instr? inst /\ Vale.X64.Lemmas.state_eq_S true s1 s2)
(ensures
Vale.X64.Lemmas.state_eq_S true
(Vale.X64.Machine_Semantics_s.machine_eval_ins inst s1)
(Vale.X64.Machine_Semantics_s.machine_eval_ins inst s2)) | {
"end_col": 77,
"end_line": 134,
"start_col": 2,
"start_line": 120
} |
FStar.Pervasives.Lemma | val lemma_cmp_gt (s:vale_state) (o1:operand64{not (OMem? o1 || OStack? o1)}) (o2:operand64{not (OMem? o2 || OStack? o2)}) : Lemma
(ensures eval_ocmp s (OGt o1 o2) <==> eval_operand o1 s > eval_operand o2 s)
[SMTPat (eval_ocmp s (OGt o1 o2))] | [
{
"abbrev": true,
"full_module": "Vale.X64.Memory",
"short_module": "ME"
},
{
"abbrev": false,
"full_module": "Vale.X64.Instruction_s",
"short_module": null
},
{
"abbrev": true,
"full_module": "Vale.Lib.Map16",
"short_module": "Map16"
},
{
"abbrev": true,
"full_module": "Vale.X64.Machine_Semantics_s",
"short_module": "BS"
},
{
"abbrev": false,
"full_module": "Vale.X64.Bytes_Code_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.StateLemmas",
"short_module": null
},
{
"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.HeapLemmas",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.HeapImpl",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Heap",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"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 lemma_cmp_gt s o1 o2 = reveal_opaque (`%BS.eval_ocmp_opaque) BS.eval_ocmp_opaque | val lemma_cmp_gt (s:vale_state) (o1:operand64{not (OMem? o1 || OStack? o1)}) (o2:operand64{not (OMem? o2 || OStack? o2)}) : Lemma
(ensures eval_ocmp s (OGt o1 o2) <==> eval_operand o1 s > eval_operand o2 s)
[SMTPat (eval_ocmp s (OGt o1 o2))]
let lemma_cmp_gt s o1 o2 = | false | null | true | reveal_opaque (`%BS.eval_ocmp_opaque) BS.eval_ocmp_opaque | {
"checked_file": "Vale.X64.Lemmas.fst.checked",
"dependencies": [
"Vale.X64.StateLemmas.fsti.checked",
"Vale.X64.State.fsti.checked",
"Vale.X64.Memory.fsti.checked",
"Vale.X64.Machine_Semantics_s.fst.checked",
"Vale.X64.Machine_s.fst.checked",
"Vale.X64.Instruction_s.fsti.checked",
"Vale.X64.Flags.fsti.checked",
"Vale.X64.Bytes_Code_s.fst.checked",
"prims.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.FunctionalExtensionality.fsti.checked"
],
"interface_file": true,
"source_file": "Vale.X64.Lemmas.fst"
} | [
"lemma"
] | [
"Vale.X64.State.vale_state",
"Vale.X64.Machine_s.operand64",
"Prims.b2t",
"Prims.op_Negation",
"Prims.op_BarBar",
"Vale.X64.Machine_s.uu___is_OMem",
"Vale.X64.Machine_s.nat64",
"Vale.X64.Machine_s.reg_64",
"Vale.X64.Machine_s.uu___is_OStack",
"FStar.Pervasives.reveal_opaque",
"Vale.X64.Machine_Semantics_s.machine_state",
"Vale.X64.Machine_Semantics_s.ocmp",
"Prims.bool",
"Vale.X64.Machine_Semantics_s.eval_ocmp_opaque",
"Prims.unit"
] | [] | module Vale.X64.Lemmas
open FStar.Mul
open Vale.X64.Machine_s
open Vale.X64.State
open Vale.X64.StateLemmas
open Vale.X64.Instruction_s
open Vale.X64.Bytes_Code_s
module BS = Vale.X64.Machine_Semantics_s
module ME = Vale.X64.Memory
#reset-options "--initial_fuel 1 --max_fuel 1 --z3rlimit 100"
#restart-solver
let rec lemma_eq_instr_apply_eval_args
(outs:list instr_out) (args:list instr_operand)
(f:instr_args_t outs args) (oprs:instr_operands_t_args args) (s1 s2:machine_state)
: Lemma
(requires state_eq_S true s1 s2)
(ensures
BS.instr_apply_eval_args outs args f oprs s1 ==
BS.instr_apply_eval_args outs args f oprs s2)
=
let open BS in
lemma_heap_ignore_ghost_machine s1.BS.ms_heap s2.BS.ms_heap;
match args with
| [] -> ()
| i::args ->
(
let (v, oprs) : option (instr_val_t i) & instr_operands_t_args args =
match i with
| IOpEx i -> let oprs = coerce oprs in (instr_eval_operand_explicit i (fst oprs) s1, snd oprs)
| IOpIm i -> (instr_eval_operand_implicit i s1, coerce oprs)
in
let f:arrow (instr_val_t i) (instr_args_t outs args) = coerce f in
match v with
| None -> ()
| Some v -> lemma_eq_instr_apply_eval_args outs args (f v) oprs s1 s2
)
#restart-solver
let rec lemma_eq_instr_apply_eval_inouts
(outs inouts:list instr_out) (args:list instr_operand)
(f:instr_inouts_t outs inouts args) (oprs:instr_operands_t inouts args) (s1 s2:machine_state)
: Lemma
(requires state_eq_S true s1 s2)
(ensures
BS.instr_apply_eval_inouts outs inouts args f oprs s1 ==
BS.instr_apply_eval_inouts outs inouts args f oprs s2)
=
let open BS in
lemma_heap_ignore_ghost_machine s1.BS.ms_heap s2.BS.ms_heap;
match inouts with
| [] -> lemma_eq_instr_apply_eval_args outs args f oprs s1 s2
| (Out, i)::inouts ->
let oprs =
match i with
| IOpEx i -> snd #(instr_operand_t i) (coerce oprs)
| IOpIm i -> coerce oprs
in
lemma_eq_instr_apply_eval_inouts outs inouts args (coerce f) oprs s1 s2
| (InOut, i)::inouts ->
(
let (v, oprs) : option (instr_val_t i) & instr_operands_t inouts args =
match i with
| IOpEx i -> let oprs = coerce oprs in (instr_eval_operand_explicit i (fst oprs) s1, snd oprs)
| IOpIm i -> (instr_eval_operand_implicit i s1, coerce oprs)
in
let f:arrow (instr_val_t i) (instr_inouts_t outs inouts args) = coerce f in
match v with
| None -> ()
| Some v -> lemma_eq_instr_apply_eval_inouts outs inouts args (f v) oprs s1 s2
)
#restart-solver
#push-options "--z3rlimit_factor 2"
let rec lemma_eq_instr_write_outputs
(outs:list instr_out) (args:list instr_operand)
(vs:instr_ret_t outs) (oprs:instr_operands_t outs args) (s1_orig s1 s2_orig s2:machine_state)
: Lemma
(requires state_eq_S true s1_orig s2_orig /\ state_eq_S true s1 s2)
(ensures
state_eq_S true
(BS.instr_write_outputs outs args vs oprs s1_orig s1)
(BS.instr_write_outputs outs args vs oprs s2_orig s2))
=
let open BS in
use_machine_state_equal ();
lemma_heap_ignore_ghost_machine s1.BS.ms_heap s2.BS.ms_heap;
lemma_heap_ignore_ghost_machine s1_orig.BS.ms_heap s2_orig.BS.ms_heap;
allow_inversion tmaddr;
match outs with
| [] -> ()
| (_, i)::outs ->
(
let ((v:instr_val_t i), (vs:instr_ret_t outs)) =
match outs with
| [] -> (vs, ())
| _::_ -> let vs = coerce vs in (fst vs, snd vs)
in
match i with
| IOpEx i ->
let oprs = coerce oprs in
let s1 = instr_write_output_explicit i v (fst oprs) s1_orig s1 in
let s2 = instr_write_output_explicit i v (fst oprs) s2_orig s2 in
lemma_eq_instr_write_outputs outs args vs (snd oprs) s1_orig s1 s2_orig s2
| IOpIm i ->
let s1 = instr_write_output_implicit i v s1_orig s1 in
let s2 = instr_write_output_implicit i v s2_orig s2 in
allow_inversion operand64;
allow_inversion operand128;
lemma_eq_instr_write_outputs outs args vs (coerce oprs) s1_orig s1 s2_orig s2
)
#pop-options
#restart-solver
let eval_ins_eq_instr (inst:BS.ins) (s1 s2:machine_state) : Lemma
(requires Instr? inst /\ state_eq_S true s1 s2)
(ensures state_eq_S true (BS.machine_eval_ins inst s1) (BS.machine_eval_ins inst s2))
=
let open BS in
let Instr it oprs ann = inst in
let InstrTypeRecord #outs #args #havoc_flags' i = it in
lemma_eq_instr_apply_eval_inouts outs outs args (instr_eval i) oprs s1 s2;
let vs = instr_apply_eval outs args (instr_eval i) oprs s1 in
let hav s =
match havoc_flags' with
| HavocFlags -> {s with ms_flags = havoc_flags}
| PreserveFlags -> s
in
let s1' = hav s1 in
let s2' = hav s2 in
match vs with
| None -> ()
| Some vs -> lemma_eq_instr_write_outputs outs args vs oprs s1 s1' s2 s2'
let eval_code_eq_instr (inst:BS.ins) (f:fuel) (s1 s2:machine_state) : Lemma
(requires Instr? inst /\ state_eq_S true s1 s2)
(ensures state_eq_opt true (BS.machine_eval_code (Ins inst) f s1) (BS.machine_eval_code (Ins inst) f s2))
=
reveal_opaque (`%BS.machine_eval_code_ins) BS.machine_eval_code_ins;
eval_ins_eq_instr inst ({s1 with BS.ms_trace = []}) ({s2 with BS.ms_trace = []})
let eval_code_eq_dealloc (inst:BS.ins) (f:fuel) (s1 s2:machine_state) : Lemma
(requires Dealloc? inst /\ state_eq_S true s1 s2)
(ensures state_eq_opt true (BS.machine_eval_code (Ins inst) f s1) (BS.machine_eval_code (Ins inst) f s2))
=
reveal_opaque (`%BS.machine_eval_code_ins) BS.machine_eval_code_ins;
use_machine_state_equal ();
lemma_heap_ignore_ghost_machine s1.BS.ms_heap s2.BS.ms_heap;
allow_inversion tmaddr
let eval_code_eq_alloc (inst:BS.ins) (f:fuel) (s1 s2:machine_state) : Lemma
(requires Alloc? inst /\ state_eq_S true s1 s2)
(ensures state_eq_opt true (BS.machine_eval_code (Ins inst) f s1) (BS.machine_eval_code (Ins inst) f s2))
=
reveal_opaque (`%BS.machine_eval_code_ins) BS.machine_eval_code_ins;
use_machine_state_equal ();
lemma_heap_ignore_ghost_machine s1.BS.ms_heap s2.BS.ms_heap;
allow_inversion tmaddr
let eval_code_eq_push (inst:BS.ins) (f:fuel) (s1 s2:machine_state) : Lemma
(requires Push? inst /\ state_eq_S true s1 s2)
(ensures state_eq_opt true (BS.machine_eval_code (Ins inst) f s1) (BS.machine_eval_code (Ins inst) f s2))
=
reveal_opaque (`%BS.machine_eval_code_ins) BS.machine_eval_code_ins;
use_machine_state_equal ();
lemma_heap_ignore_ghost_machine s1.BS.ms_heap s2.BS.ms_heap;
allow_inversion tmaddr
let eval_code_eq_pop (inst:BS.ins) (f:fuel) (s1 s2:machine_state) : Lemma
(requires Pop? inst /\ state_eq_S true s1 s2)
(ensures state_eq_opt true (BS.machine_eval_code (Ins inst) f s1) (BS.machine_eval_code (Ins inst) f s2))
=
reveal_opaque (`%BS.machine_eval_code_ins) BS.machine_eval_code_ins;
use_machine_state_equal ();
lemma_heap_ignore_ghost_machine s1.BS.ms_heap s2.BS.ms_heap;
allow_inversion tmaddr
let eval_code_eq_ins (i:BS.ins) (f:fuel) (s1 s2:machine_state) : Lemma
(requires state_eq_S true s1 s2)
(ensures state_eq_opt true (BS.machine_eval_code (Ins i) f s1) (BS.machine_eval_code (Ins i) f s2))
=
match i with
| Instr _ _ _ -> eval_code_eq_instr i f s1 s2
| Dealloc _ -> eval_code_eq_dealloc i f s1 s2
| Alloc _ -> eval_code_eq_alloc i f s1 s2
| Push _ _ -> eval_code_eq_push i f s1 s2
| Pop _ _ -> eval_code_eq_pop i f s1 s2
#reset-options "--fuel 2 --z3rlimit 30"
let eval_ocmp_eq_core (g:bool) (cond:ocmp) (s:machine_state) : Lemma
(ensures (
let (s1, b1) = BS.machine_eval_ocmp s cond in
let (s2, b2) = BS.machine_eval_ocmp (core_state g s) cond in
state_eq_S g s1 s2 /\ b1 == b2
))
=
reveal_opaque (`%BS.valid_ocmp_opaque) BS.valid_ocmp_opaque;
reveal_opaque (`%BS.eval_ocmp_opaque) BS.eval_ocmp_opaque;
()
#restart-solver
let rec eval_code_eq_core (g:bool) (c:code) (f:fuel) (s:machine_state) : Lemma
(ensures state_eq_opt g (BS.machine_eval_code c f s) (BS.machine_eval_code c f (core_state g s)))
(decreases %[f; c])
=
match c with
| Ins i ->
reveal_opaque (`%BS.machine_eval_code_ins) BS.machine_eval_code_ins;
if g then eval_code_eq_ins i f s (core_state g s)
| Block cs -> eval_codes_eq_core g cs f s
| IfElse cond ct cf ->
eval_ocmp_eq_core g cond s;
let (s', _) = BS.machine_eval_ocmp s cond in
let (t', _) = BS.machine_eval_ocmp (core_state g s) cond in
eval_code_eq_core g ct f s';
eval_code_eq_core g ct f t';
eval_code_eq_core g cf f s';
eval_code_eq_core g cf f t';
()
| While cond body -> eval_while_eq_core g cond body f s
and eval_codes_eq_core (g:bool) (cs:codes) (f:fuel) (s:machine_state) : Lemma
(ensures state_eq_opt g (BS.machine_eval_codes cs f s) (BS.machine_eval_codes cs f (core_state g s)))
(decreases %[f; cs])
=
match cs with
| [] -> ()
| c'::cs' -> (
eval_code_eq_core g c' f s;
match (machine_eval_code c' f s, machine_eval_code c' f (core_state g s)) with
| (None, None) -> ()
| (Some s', Some t') -> eval_codes_eq_core g cs' f s'; eval_codes_eq_core g cs' f t'
)
and eval_while_eq_core (g:bool) (cond:ocmp) (body:code) (f:fuel) (s:machine_state) : Lemma
(ensures state_eq_opt g (BS.machine_eval_while cond body f s) (BS.machine_eval_while cond body f (core_state g s)))
(decreases %[f; body])
=
if f > 0 then (
eval_ocmp_eq_core g cond s;
let (s1, _) = BS.machine_eval_ocmp s cond in
let (t1, _) = BS.machine_eval_ocmp (core_state g s) cond in
eval_code_eq_core g body (f - 1) s1;
eval_code_eq_core g body (f - 1) t1;
match (BS.machine_eval_code body (f - 1) s1, BS.machine_eval_code body (f - 1) t1) with
| (None, None) -> ()
| (Some s2, Some t2) ->
eval_while_eq_core g cond body (f - 1) s2;
eval_while_eq_core g cond body (f - 1) t2;
()
)
let eval_code_eq_f (c:code) (f:fuel) (s1 s2:machine_state) : Lemma
(requires state_eq_S false s1 s2)
(ensures state_eq_opt false (BS.machine_eval_code c f s1) (BS.machine_eval_code c f s2))
[SMTPat (BS.machine_eval_code c f s1); SMTPat (BS.machine_eval_code c f s2)]
=
eval_code_eq_core false c f s1; eval_code_eq_core false c f s2
let eval_codes_eq_f (cs:codes) (f:fuel) (s1 s2:machine_state) : Lemma
(requires state_eq_S false s1 s2)
(ensures state_eq_opt false (BS.machine_eval_codes cs f s1) (BS.machine_eval_codes cs f s2))
[SMTPat (BS.machine_eval_codes cs f s1); SMTPat (BS.machine_eval_codes cs f s2)]
=
eval_codes_eq_core false cs f s1; eval_codes_eq_core false cs f s2
let eval_while_eq_f (cond:ocmp) (body:code) (f:fuel) (s1 s2:machine_state) : Lemma
(requires state_eq_S false s1 s2)
(ensures state_eq_opt false (BS.machine_eval_while cond body f s1) (BS.machine_eval_while cond body f s2))
[SMTPat (BS.machine_eval_while cond body f s1); SMTPat (BS.machine_eval_while cond body f s2)]
=
eval_while_eq_core false cond body f s1; eval_while_eq_core false cond body f s2
let eval_code_eq_t (c:code) (f:fuel) (s1 s2:machine_state) : Lemma
(requires state_eq_S true s1 s2)
(ensures state_eq_opt true (BS.machine_eval_code c f s1) (BS.machine_eval_code c f s2))
[SMTPat (BS.machine_eval_code c f s1); SMTPat (BS.machine_eval_code c f s2)]
=
eval_code_eq_core true c f s1; eval_code_eq_core true c f s2
let eval_codes_eq_t (cs:codes) (f:fuel) (s1 s2:machine_state) : Lemma
(requires state_eq_S true s1 s2)
(ensures state_eq_opt true (BS.machine_eval_codes cs f s1) (BS.machine_eval_codes cs f s2))
[SMTPat (BS.machine_eval_codes cs f s1); SMTPat (BS.machine_eval_codes cs f s2)]
=
eval_codes_eq_core true cs f s1; eval_codes_eq_core true cs f s2
let eval_while_eq_t (cond:ocmp) (body:code) (f:fuel) (s1 s2:machine_state) : Lemma
(requires state_eq_S true s1 s2)
(ensures state_eq_opt true (BS.machine_eval_while cond body f s1) (BS.machine_eval_while cond body f s2))
[SMTPat (BS.machine_eval_while cond body f s1); SMTPat (BS.machine_eval_while cond body f s2)]
=
eval_while_eq_core true cond body f s1; eval_while_eq_core true cond body f s2
let eval_code_ts (g:bool) (c:code) (s0:machine_state) (f0:fuel) (s1:machine_state) : Type0 =
state_eq_opt g (BS.machine_eval_code c f0 s0) (Some s1)
let rec increase_fuel (g:bool) (c:code) (s0:machine_state) (f0:fuel) (sN:machine_state) (fN:fuel) : Lemma
(requires eval_code_ts g c s0 f0 sN /\ f0 <= fN)
(ensures eval_code_ts g c s0 fN sN)
(decreases %[f0; c])
=
match c with
| Ins ins -> ()
| Block l -> increase_fuels g l s0 f0 sN fN
| IfElse cond t f ->
let (s0, b0) = BS.machine_eval_ocmp s0 cond in
if b0 then increase_fuel g t s0 f0 sN fN else increase_fuel g f s0 f0 sN fN
| While cond c ->
let (s1, b0) = BS.machine_eval_ocmp s0 cond in
if b0 then (
match BS.machine_eval_code c (f0 - 1) s1 with
| None -> ()
| Some s2 ->
increase_fuel g c s1 (f0 - 1) s2 (fN - 1);
if s2.BS.ms_ok then increase_fuel g (While cond c) s2 (f0 - 1) sN (fN - 1)
else ()
)
and increase_fuels (g:bool) (c:codes) (s0:machine_state) (f0:fuel) (sN:machine_state) (fN:fuel) : Lemma
(requires eval_code_ts g (Block c) s0 f0 sN /\ f0 <= fN)
(ensures eval_code_ts g (Block c) s0 fN sN)
(decreases %[f0; c])
=
match c with
| [] -> ()
| h::t ->
(
let Some s1 = BS.machine_eval_code h f0 s0 in
increase_fuel g h s0 f0 s1 fN;
increase_fuels g t s1 f0 sN fN
)
let lemma_cmp_eq s o1 o2 = reveal_opaque (`%BS.eval_ocmp_opaque) BS.eval_ocmp_opaque
let lemma_cmp_ne s o1 o2 = reveal_opaque (`%BS.eval_ocmp_opaque) BS.eval_ocmp_opaque
let lemma_cmp_le s o1 o2 = reveal_opaque (`%BS.eval_ocmp_opaque) BS.eval_ocmp_opaque
let lemma_cmp_ge s o1 o2 = reveal_opaque (`%BS.eval_ocmp_opaque) BS.eval_ocmp_opaque | false | false | Vale.X64.Lemmas.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": 30,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val lemma_cmp_gt (s:vale_state) (o1:operand64{not (OMem? o1 || OStack? o1)}) (o2:operand64{not (OMem? o2 || OStack? o2)}) : Lemma
(ensures eval_ocmp s (OGt o1 o2) <==> eval_operand o1 s > eval_operand o2 s)
[SMTPat (eval_ocmp s (OGt o1 o2))] | [] | Vale.X64.Lemmas.lemma_cmp_gt | {
"file_name": "vale/code/arch/x64/Vale.X64.Lemmas.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} |
s: Vale.X64.State.vale_state ->
o1: Vale.X64.Machine_s.operand64{Prims.op_Negation (OMem? o1 || OStack? o1)} ->
o2: Vale.X64.Machine_s.operand64{Prims.op_Negation (OMem? o2 || OStack? o2)}
-> FStar.Pervasives.Lemma
(ensures
Vale.X64.Lemmas.eval_ocmp s (Vale.X64.Bytes_Code_s.OGt o1 o2) <==>
Vale.X64.State.eval_operand o1 s > Vale.X64.State.eval_operand o2 s)
[SMTPat (Vale.X64.Lemmas.eval_ocmp s (Vale.X64.Bytes_Code_s.OGt o1 o2))] | {
"end_col": 84,
"end_line": 338,
"start_col": 27,
"start_line": 338
} |
FStar.Pervasives.Lemma | val lemma_cmp_ge (s:vale_state) (o1:operand64{not (OMem? o1 || OStack? o1)}) (o2:operand64{not (OMem? o2 || OStack? o2)}) : Lemma
(ensures eval_ocmp s (OGe o1 o2) <==> eval_operand o1 s >= eval_operand o2 s)
[SMTPat (eval_ocmp s (OGe o1 o2))] | [
{
"abbrev": true,
"full_module": "Vale.X64.Memory",
"short_module": "ME"
},
{
"abbrev": false,
"full_module": "Vale.X64.Instruction_s",
"short_module": null
},
{
"abbrev": true,
"full_module": "Vale.Lib.Map16",
"short_module": "Map16"
},
{
"abbrev": true,
"full_module": "Vale.X64.Machine_Semantics_s",
"short_module": "BS"
},
{
"abbrev": false,
"full_module": "Vale.X64.Bytes_Code_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.StateLemmas",
"short_module": null
},
{
"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.HeapLemmas",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.HeapImpl",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Heap",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"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 lemma_cmp_ge s o1 o2 = reveal_opaque (`%BS.eval_ocmp_opaque) BS.eval_ocmp_opaque | val lemma_cmp_ge (s:vale_state) (o1:operand64{not (OMem? o1 || OStack? o1)}) (o2:operand64{not (OMem? o2 || OStack? o2)}) : Lemma
(ensures eval_ocmp s (OGe o1 o2) <==> eval_operand o1 s >= eval_operand o2 s)
[SMTPat (eval_ocmp s (OGe o1 o2))]
let lemma_cmp_ge s o1 o2 = | false | null | true | reveal_opaque (`%BS.eval_ocmp_opaque) BS.eval_ocmp_opaque | {
"checked_file": "Vale.X64.Lemmas.fst.checked",
"dependencies": [
"Vale.X64.StateLemmas.fsti.checked",
"Vale.X64.State.fsti.checked",
"Vale.X64.Memory.fsti.checked",
"Vale.X64.Machine_Semantics_s.fst.checked",
"Vale.X64.Machine_s.fst.checked",
"Vale.X64.Instruction_s.fsti.checked",
"Vale.X64.Flags.fsti.checked",
"Vale.X64.Bytes_Code_s.fst.checked",
"prims.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.FunctionalExtensionality.fsti.checked"
],
"interface_file": true,
"source_file": "Vale.X64.Lemmas.fst"
} | [
"lemma"
] | [
"Vale.X64.State.vale_state",
"Vale.X64.Machine_s.operand64",
"Prims.b2t",
"Prims.op_Negation",
"Prims.op_BarBar",
"Vale.X64.Machine_s.uu___is_OMem",
"Vale.X64.Machine_s.nat64",
"Vale.X64.Machine_s.reg_64",
"Vale.X64.Machine_s.uu___is_OStack",
"FStar.Pervasives.reveal_opaque",
"Vale.X64.Machine_Semantics_s.machine_state",
"Vale.X64.Machine_Semantics_s.ocmp",
"Prims.bool",
"Vale.X64.Machine_Semantics_s.eval_ocmp_opaque",
"Prims.unit"
] | [] | module Vale.X64.Lemmas
open FStar.Mul
open Vale.X64.Machine_s
open Vale.X64.State
open Vale.X64.StateLemmas
open Vale.X64.Instruction_s
open Vale.X64.Bytes_Code_s
module BS = Vale.X64.Machine_Semantics_s
module ME = Vale.X64.Memory
#reset-options "--initial_fuel 1 --max_fuel 1 --z3rlimit 100"
#restart-solver
let rec lemma_eq_instr_apply_eval_args
(outs:list instr_out) (args:list instr_operand)
(f:instr_args_t outs args) (oprs:instr_operands_t_args args) (s1 s2:machine_state)
: Lemma
(requires state_eq_S true s1 s2)
(ensures
BS.instr_apply_eval_args outs args f oprs s1 ==
BS.instr_apply_eval_args outs args f oprs s2)
=
let open BS in
lemma_heap_ignore_ghost_machine s1.BS.ms_heap s2.BS.ms_heap;
match args with
| [] -> ()
| i::args ->
(
let (v, oprs) : option (instr_val_t i) & instr_operands_t_args args =
match i with
| IOpEx i -> let oprs = coerce oprs in (instr_eval_operand_explicit i (fst oprs) s1, snd oprs)
| IOpIm i -> (instr_eval_operand_implicit i s1, coerce oprs)
in
let f:arrow (instr_val_t i) (instr_args_t outs args) = coerce f in
match v with
| None -> ()
| Some v -> lemma_eq_instr_apply_eval_args outs args (f v) oprs s1 s2
)
#restart-solver
let rec lemma_eq_instr_apply_eval_inouts
(outs inouts:list instr_out) (args:list instr_operand)
(f:instr_inouts_t outs inouts args) (oprs:instr_operands_t inouts args) (s1 s2:machine_state)
: Lemma
(requires state_eq_S true s1 s2)
(ensures
BS.instr_apply_eval_inouts outs inouts args f oprs s1 ==
BS.instr_apply_eval_inouts outs inouts args f oprs s2)
=
let open BS in
lemma_heap_ignore_ghost_machine s1.BS.ms_heap s2.BS.ms_heap;
match inouts with
| [] -> lemma_eq_instr_apply_eval_args outs args f oprs s1 s2
| (Out, i)::inouts ->
let oprs =
match i with
| IOpEx i -> snd #(instr_operand_t i) (coerce oprs)
| IOpIm i -> coerce oprs
in
lemma_eq_instr_apply_eval_inouts outs inouts args (coerce f) oprs s1 s2
| (InOut, i)::inouts ->
(
let (v, oprs) : option (instr_val_t i) & instr_operands_t inouts args =
match i with
| IOpEx i -> let oprs = coerce oprs in (instr_eval_operand_explicit i (fst oprs) s1, snd oprs)
| IOpIm i -> (instr_eval_operand_implicit i s1, coerce oprs)
in
let f:arrow (instr_val_t i) (instr_inouts_t outs inouts args) = coerce f in
match v with
| None -> ()
| Some v -> lemma_eq_instr_apply_eval_inouts outs inouts args (f v) oprs s1 s2
)
#restart-solver
#push-options "--z3rlimit_factor 2"
let rec lemma_eq_instr_write_outputs
(outs:list instr_out) (args:list instr_operand)
(vs:instr_ret_t outs) (oprs:instr_operands_t outs args) (s1_orig s1 s2_orig s2:machine_state)
: Lemma
(requires state_eq_S true s1_orig s2_orig /\ state_eq_S true s1 s2)
(ensures
state_eq_S true
(BS.instr_write_outputs outs args vs oprs s1_orig s1)
(BS.instr_write_outputs outs args vs oprs s2_orig s2))
=
let open BS in
use_machine_state_equal ();
lemma_heap_ignore_ghost_machine s1.BS.ms_heap s2.BS.ms_heap;
lemma_heap_ignore_ghost_machine s1_orig.BS.ms_heap s2_orig.BS.ms_heap;
allow_inversion tmaddr;
match outs with
| [] -> ()
| (_, i)::outs ->
(
let ((v:instr_val_t i), (vs:instr_ret_t outs)) =
match outs with
| [] -> (vs, ())
| _::_ -> let vs = coerce vs in (fst vs, snd vs)
in
match i with
| IOpEx i ->
let oprs = coerce oprs in
let s1 = instr_write_output_explicit i v (fst oprs) s1_orig s1 in
let s2 = instr_write_output_explicit i v (fst oprs) s2_orig s2 in
lemma_eq_instr_write_outputs outs args vs (snd oprs) s1_orig s1 s2_orig s2
| IOpIm i ->
let s1 = instr_write_output_implicit i v s1_orig s1 in
let s2 = instr_write_output_implicit i v s2_orig s2 in
allow_inversion operand64;
allow_inversion operand128;
lemma_eq_instr_write_outputs outs args vs (coerce oprs) s1_orig s1 s2_orig s2
)
#pop-options
#restart-solver
let eval_ins_eq_instr (inst:BS.ins) (s1 s2:machine_state) : Lemma
(requires Instr? inst /\ state_eq_S true s1 s2)
(ensures state_eq_S true (BS.machine_eval_ins inst s1) (BS.machine_eval_ins inst s2))
=
let open BS in
let Instr it oprs ann = inst in
let InstrTypeRecord #outs #args #havoc_flags' i = it in
lemma_eq_instr_apply_eval_inouts outs outs args (instr_eval i) oprs s1 s2;
let vs = instr_apply_eval outs args (instr_eval i) oprs s1 in
let hav s =
match havoc_flags' with
| HavocFlags -> {s with ms_flags = havoc_flags}
| PreserveFlags -> s
in
let s1' = hav s1 in
let s2' = hav s2 in
match vs with
| None -> ()
| Some vs -> lemma_eq_instr_write_outputs outs args vs oprs s1 s1' s2 s2'
let eval_code_eq_instr (inst:BS.ins) (f:fuel) (s1 s2:machine_state) : Lemma
(requires Instr? inst /\ state_eq_S true s1 s2)
(ensures state_eq_opt true (BS.machine_eval_code (Ins inst) f s1) (BS.machine_eval_code (Ins inst) f s2))
=
reveal_opaque (`%BS.machine_eval_code_ins) BS.machine_eval_code_ins;
eval_ins_eq_instr inst ({s1 with BS.ms_trace = []}) ({s2 with BS.ms_trace = []})
let eval_code_eq_dealloc (inst:BS.ins) (f:fuel) (s1 s2:machine_state) : Lemma
(requires Dealloc? inst /\ state_eq_S true s1 s2)
(ensures state_eq_opt true (BS.machine_eval_code (Ins inst) f s1) (BS.machine_eval_code (Ins inst) f s2))
=
reveal_opaque (`%BS.machine_eval_code_ins) BS.machine_eval_code_ins;
use_machine_state_equal ();
lemma_heap_ignore_ghost_machine s1.BS.ms_heap s2.BS.ms_heap;
allow_inversion tmaddr
let eval_code_eq_alloc (inst:BS.ins) (f:fuel) (s1 s2:machine_state) : Lemma
(requires Alloc? inst /\ state_eq_S true s1 s2)
(ensures state_eq_opt true (BS.machine_eval_code (Ins inst) f s1) (BS.machine_eval_code (Ins inst) f s2))
=
reveal_opaque (`%BS.machine_eval_code_ins) BS.machine_eval_code_ins;
use_machine_state_equal ();
lemma_heap_ignore_ghost_machine s1.BS.ms_heap s2.BS.ms_heap;
allow_inversion tmaddr
let eval_code_eq_push (inst:BS.ins) (f:fuel) (s1 s2:machine_state) : Lemma
(requires Push? inst /\ state_eq_S true s1 s2)
(ensures state_eq_opt true (BS.machine_eval_code (Ins inst) f s1) (BS.machine_eval_code (Ins inst) f s2))
=
reveal_opaque (`%BS.machine_eval_code_ins) BS.machine_eval_code_ins;
use_machine_state_equal ();
lemma_heap_ignore_ghost_machine s1.BS.ms_heap s2.BS.ms_heap;
allow_inversion tmaddr
let eval_code_eq_pop (inst:BS.ins) (f:fuel) (s1 s2:machine_state) : Lemma
(requires Pop? inst /\ state_eq_S true s1 s2)
(ensures state_eq_opt true (BS.machine_eval_code (Ins inst) f s1) (BS.machine_eval_code (Ins inst) f s2))
=
reveal_opaque (`%BS.machine_eval_code_ins) BS.machine_eval_code_ins;
use_machine_state_equal ();
lemma_heap_ignore_ghost_machine s1.BS.ms_heap s2.BS.ms_heap;
allow_inversion tmaddr
let eval_code_eq_ins (i:BS.ins) (f:fuel) (s1 s2:machine_state) : Lemma
(requires state_eq_S true s1 s2)
(ensures state_eq_opt true (BS.machine_eval_code (Ins i) f s1) (BS.machine_eval_code (Ins i) f s2))
=
match i with
| Instr _ _ _ -> eval_code_eq_instr i f s1 s2
| Dealloc _ -> eval_code_eq_dealloc i f s1 s2
| Alloc _ -> eval_code_eq_alloc i f s1 s2
| Push _ _ -> eval_code_eq_push i f s1 s2
| Pop _ _ -> eval_code_eq_pop i f s1 s2
#reset-options "--fuel 2 --z3rlimit 30"
let eval_ocmp_eq_core (g:bool) (cond:ocmp) (s:machine_state) : Lemma
(ensures (
let (s1, b1) = BS.machine_eval_ocmp s cond in
let (s2, b2) = BS.machine_eval_ocmp (core_state g s) cond in
state_eq_S g s1 s2 /\ b1 == b2
))
=
reveal_opaque (`%BS.valid_ocmp_opaque) BS.valid_ocmp_opaque;
reveal_opaque (`%BS.eval_ocmp_opaque) BS.eval_ocmp_opaque;
()
#restart-solver
let rec eval_code_eq_core (g:bool) (c:code) (f:fuel) (s:machine_state) : Lemma
(ensures state_eq_opt g (BS.machine_eval_code c f s) (BS.machine_eval_code c f (core_state g s)))
(decreases %[f; c])
=
match c with
| Ins i ->
reveal_opaque (`%BS.machine_eval_code_ins) BS.machine_eval_code_ins;
if g then eval_code_eq_ins i f s (core_state g s)
| Block cs -> eval_codes_eq_core g cs f s
| IfElse cond ct cf ->
eval_ocmp_eq_core g cond s;
let (s', _) = BS.machine_eval_ocmp s cond in
let (t', _) = BS.machine_eval_ocmp (core_state g s) cond in
eval_code_eq_core g ct f s';
eval_code_eq_core g ct f t';
eval_code_eq_core g cf f s';
eval_code_eq_core g cf f t';
()
| While cond body -> eval_while_eq_core g cond body f s
and eval_codes_eq_core (g:bool) (cs:codes) (f:fuel) (s:machine_state) : Lemma
(ensures state_eq_opt g (BS.machine_eval_codes cs f s) (BS.machine_eval_codes cs f (core_state g s)))
(decreases %[f; cs])
=
match cs with
| [] -> ()
| c'::cs' -> (
eval_code_eq_core g c' f s;
match (machine_eval_code c' f s, machine_eval_code c' f (core_state g s)) with
| (None, None) -> ()
| (Some s', Some t') -> eval_codes_eq_core g cs' f s'; eval_codes_eq_core g cs' f t'
)
and eval_while_eq_core (g:bool) (cond:ocmp) (body:code) (f:fuel) (s:machine_state) : Lemma
(ensures state_eq_opt g (BS.machine_eval_while cond body f s) (BS.machine_eval_while cond body f (core_state g s)))
(decreases %[f; body])
=
if f > 0 then (
eval_ocmp_eq_core g cond s;
let (s1, _) = BS.machine_eval_ocmp s cond in
let (t1, _) = BS.machine_eval_ocmp (core_state g s) cond in
eval_code_eq_core g body (f - 1) s1;
eval_code_eq_core g body (f - 1) t1;
match (BS.machine_eval_code body (f - 1) s1, BS.machine_eval_code body (f - 1) t1) with
| (None, None) -> ()
| (Some s2, Some t2) ->
eval_while_eq_core g cond body (f - 1) s2;
eval_while_eq_core g cond body (f - 1) t2;
()
)
let eval_code_eq_f (c:code) (f:fuel) (s1 s2:machine_state) : Lemma
(requires state_eq_S false s1 s2)
(ensures state_eq_opt false (BS.machine_eval_code c f s1) (BS.machine_eval_code c f s2))
[SMTPat (BS.machine_eval_code c f s1); SMTPat (BS.machine_eval_code c f s2)]
=
eval_code_eq_core false c f s1; eval_code_eq_core false c f s2
let eval_codes_eq_f (cs:codes) (f:fuel) (s1 s2:machine_state) : Lemma
(requires state_eq_S false s1 s2)
(ensures state_eq_opt false (BS.machine_eval_codes cs f s1) (BS.machine_eval_codes cs f s2))
[SMTPat (BS.machine_eval_codes cs f s1); SMTPat (BS.machine_eval_codes cs f s2)]
=
eval_codes_eq_core false cs f s1; eval_codes_eq_core false cs f s2
let eval_while_eq_f (cond:ocmp) (body:code) (f:fuel) (s1 s2:machine_state) : Lemma
(requires state_eq_S false s1 s2)
(ensures state_eq_opt false (BS.machine_eval_while cond body f s1) (BS.machine_eval_while cond body f s2))
[SMTPat (BS.machine_eval_while cond body f s1); SMTPat (BS.machine_eval_while cond body f s2)]
=
eval_while_eq_core false cond body f s1; eval_while_eq_core false cond body f s2
let eval_code_eq_t (c:code) (f:fuel) (s1 s2:machine_state) : Lemma
(requires state_eq_S true s1 s2)
(ensures state_eq_opt true (BS.machine_eval_code c f s1) (BS.machine_eval_code c f s2))
[SMTPat (BS.machine_eval_code c f s1); SMTPat (BS.machine_eval_code c f s2)]
=
eval_code_eq_core true c f s1; eval_code_eq_core true c f s2
let eval_codes_eq_t (cs:codes) (f:fuel) (s1 s2:machine_state) : Lemma
(requires state_eq_S true s1 s2)
(ensures state_eq_opt true (BS.machine_eval_codes cs f s1) (BS.machine_eval_codes cs f s2))
[SMTPat (BS.machine_eval_codes cs f s1); SMTPat (BS.machine_eval_codes cs f s2)]
=
eval_codes_eq_core true cs f s1; eval_codes_eq_core true cs f s2
let eval_while_eq_t (cond:ocmp) (body:code) (f:fuel) (s1 s2:machine_state) : Lemma
(requires state_eq_S true s1 s2)
(ensures state_eq_opt true (BS.machine_eval_while cond body f s1) (BS.machine_eval_while cond body f s2))
[SMTPat (BS.machine_eval_while cond body f s1); SMTPat (BS.machine_eval_while cond body f s2)]
=
eval_while_eq_core true cond body f s1; eval_while_eq_core true cond body f s2
let eval_code_ts (g:bool) (c:code) (s0:machine_state) (f0:fuel) (s1:machine_state) : Type0 =
state_eq_opt g (BS.machine_eval_code c f0 s0) (Some s1)
let rec increase_fuel (g:bool) (c:code) (s0:machine_state) (f0:fuel) (sN:machine_state) (fN:fuel) : Lemma
(requires eval_code_ts g c s0 f0 sN /\ f0 <= fN)
(ensures eval_code_ts g c s0 fN sN)
(decreases %[f0; c])
=
match c with
| Ins ins -> ()
| Block l -> increase_fuels g l s0 f0 sN fN
| IfElse cond t f ->
let (s0, b0) = BS.machine_eval_ocmp s0 cond in
if b0 then increase_fuel g t s0 f0 sN fN else increase_fuel g f s0 f0 sN fN
| While cond c ->
let (s1, b0) = BS.machine_eval_ocmp s0 cond in
if b0 then (
match BS.machine_eval_code c (f0 - 1) s1 with
| None -> ()
| Some s2 ->
increase_fuel g c s1 (f0 - 1) s2 (fN - 1);
if s2.BS.ms_ok then increase_fuel g (While cond c) s2 (f0 - 1) sN (fN - 1)
else ()
)
and increase_fuels (g:bool) (c:codes) (s0:machine_state) (f0:fuel) (sN:machine_state) (fN:fuel) : Lemma
(requires eval_code_ts g (Block c) s0 f0 sN /\ f0 <= fN)
(ensures eval_code_ts g (Block c) s0 fN sN)
(decreases %[f0; c])
=
match c with
| [] -> ()
| h::t ->
(
let Some s1 = BS.machine_eval_code h f0 s0 in
increase_fuel g h s0 f0 s1 fN;
increase_fuels g t s1 f0 sN fN
)
let lemma_cmp_eq s o1 o2 = reveal_opaque (`%BS.eval_ocmp_opaque) BS.eval_ocmp_opaque
let lemma_cmp_ne s o1 o2 = reveal_opaque (`%BS.eval_ocmp_opaque) BS.eval_ocmp_opaque | false | false | Vale.X64.Lemmas.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": 30,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val lemma_cmp_ge (s:vale_state) (o1:operand64{not (OMem? o1 || OStack? o1)}) (o2:operand64{not (OMem? o2 || OStack? o2)}) : Lemma
(ensures eval_ocmp s (OGe o1 o2) <==> eval_operand o1 s >= eval_operand o2 s)
[SMTPat (eval_ocmp s (OGe o1 o2))] | [] | Vale.X64.Lemmas.lemma_cmp_ge | {
"file_name": "vale/code/arch/x64/Vale.X64.Lemmas.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} |
s: Vale.X64.State.vale_state ->
o1: Vale.X64.Machine_s.operand64{Prims.op_Negation (OMem? o1 || OStack? o1)} ->
o2: Vale.X64.Machine_s.operand64{Prims.op_Negation (OMem? o2 || OStack? o2)}
-> FStar.Pervasives.Lemma
(ensures
Vale.X64.Lemmas.eval_ocmp s (Vale.X64.Bytes_Code_s.OGe o1 o2) <==>
Vale.X64.State.eval_operand o1 s >= Vale.X64.State.eval_operand o2 s)
[SMTPat (Vale.X64.Lemmas.eval_ocmp s (Vale.X64.Bytes_Code_s.OGe o1 o2))] | {
"end_col": 84,
"end_line": 336,
"start_col": 27,
"start_line": 336
} |
FStar.Pervasives.Lemma | val eval_code_eq_push (inst: BS.ins) (f: fuel) (s1 s2: machine_state)
: Lemma (requires Push? inst /\ state_eq_S true s1 s2)
(ensures
state_eq_opt true
(BS.machine_eval_code (Ins inst) f s1)
(BS.machine_eval_code (Ins inst) f s2)) | [
{
"abbrev": true,
"full_module": "Vale.X64.Memory",
"short_module": "ME"
},
{
"abbrev": true,
"full_module": "Vale.X64.Machine_Semantics_s",
"short_module": "BS"
},
{
"abbrev": false,
"full_module": "Vale.X64.Bytes_Code_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Instruction_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.StateLemmas",
"short_module": null
},
{
"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": "FStar.Mul",
"short_module": null
},
{
"abbrev": true,
"full_module": "Vale.Lib.Map16",
"short_module": "Map16"
},
{
"abbrev": true,
"full_module": "Vale.X64.Machine_Semantics_s",
"short_module": "BS"
},
{
"abbrev": false,
"full_module": "Vale.X64.Bytes_Code_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.StateLemmas",
"short_module": null
},
{
"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.HeapLemmas",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.HeapImpl",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Heap",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"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 eval_code_eq_push (inst:BS.ins) (f:fuel) (s1 s2:machine_state) : Lemma
(requires Push? inst /\ state_eq_S true s1 s2)
(ensures state_eq_opt true (BS.machine_eval_code (Ins inst) f s1) (BS.machine_eval_code (Ins inst) f s2))
=
reveal_opaque (`%BS.machine_eval_code_ins) BS.machine_eval_code_ins;
use_machine_state_equal ();
lemma_heap_ignore_ghost_machine s1.BS.ms_heap s2.BS.ms_heap;
allow_inversion tmaddr | val eval_code_eq_push (inst: BS.ins) (f: fuel) (s1 s2: machine_state)
: Lemma (requires Push? inst /\ state_eq_S true s1 s2)
(ensures
state_eq_opt true
(BS.machine_eval_code (Ins inst) f s1)
(BS.machine_eval_code (Ins inst) f s2))
let eval_code_eq_push (inst: BS.ins) (f: fuel) (s1 s2: machine_state)
: Lemma (requires Push? inst /\ state_eq_S true s1 s2)
(ensures
state_eq_opt true
(BS.machine_eval_code (Ins inst) f s1)
(BS.machine_eval_code (Ins inst) f s2)) = | false | null | true | reveal_opaque (`%BS.machine_eval_code_ins) BS.machine_eval_code_ins;
use_machine_state_equal ();
lemma_heap_ignore_ghost_machine s1.BS.ms_heap s2.BS.ms_heap;
allow_inversion tmaddr | {
"checked_file": "Vale.X64.Lemmas.fst.checked",
"dependencies": [
"Vale.X64.StateLemmas.fsti.checked",
"Vale.X64.State.fsti.checked",
"Vale.X64.Memory.fsti.checked",
"Vale.X64.Machine_Semantics_s.fst.checked",
"Vale.X64.Machine_s.fst.checked",
"Vale.X64.Instruction_s.fsti.checked",
"Vale.X64.Flags.fsti.checked",
"Vale.X64.Bytes_Code_s.fst.checked",
"prims.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.FunctionalExtensionality.fsti.checked"
],
"interface_file": true,
"source_file": "Vale.X64.Lemmas.fst"
} | [
"lemma"
] | [
"Vale.X64.Machine_Semantics_s.ins",
"Vale.X64.Lemmas.fuel",
"Vale.X64.StateLemmas.machine_state",
"FStar.Pervasives.allow_inversion",
"Vale.X64.Machine_s.tmaddr",
"Prims.unit",
"Vale.Arch.HeapLemmas.lemma_heap_ignore_ghost_machine",
"Vale.X64.Machine_Semantics_s.__proj__Mkmachine_state__item__ms_heap",
"Vale.X64.StateLemmas.use_machine_state_equal",
"FStar.Pervasives.reveal_opaque",
"Vale.X64.Machine_Semantics_s.machine_state",
"FStar.Pervasives.Native.option",
"Vale.X64.Machine_Semantics_s.machine_eval_code_ins",
"Prims.l_and",
"Prims.b2t",
"Vale.X64.Bytes_Code_s.uu___is_Push",
"Vale.X64.Machine_Semantics_s.instr_annotation",
"Vale.X64.Lemmas.state_eq_S",
"Prims.squash",
"Vale.X64.Lemmas.state_eq_opt",
"Vale.X64.Machine_Semantics_s.machine_eval_code",
"Vale.X64.Machine_s.Ins",
"Vale.X64.Bytes_Code_s.instruction_t",
"Vale.X64.Bytes_Code_s.ocmp",
"Prims.Nil",
"FStar.Pervasives.pattern"
] | [] | module Vale.X64.Lemmas
open FStar.Mul
open Vale.X64.Machine_s
open Vale.X64.State
open Vale.X64.StateLemmas
open Vale.X64.Instruction_s
open Vale.X64.Bytes_Code_s
module BS = Vale.X64.Machine_Semantics_s
module ME = Vale.X64.Memory
#reset-options "--initial_fuel 1 --max_fuel 1 --z3rlimit 100"
#restart-solver
let rec lemma_eq_instr_apply_eval_args
(outs:list instr_out) (args:list instr_operand)
(f:instr_args_t outs args) (oprs:instr_operands_t_args args) (s1 s2:machine_state)
: Lemma
(requires state_eq_S true s1 s2)
(ensures
BS.instr_apply_eval_args outs args f oprs s1 ==
BS.instr_apply_eval_args outs args f oprs s2)
=
let open BS in
lemma_heap_ignore_ghost_machine s1.BS.ms_heap s2.BS.ms_heap;
match args with
| [] -> ()
| i::args ->
(
let (v, oprs) : option (instr_val_t i) & instr_operands_t_args args =
match i with
| IOpEx i -> let oprs = coerce oprs in (instr_eval_operand_explicit i (fst oprs) s1, snd oprs)
| IOpIm i -> (instr_eval_operand_implicit i s1, coerce oprs)
in
let f:arrow (instr_val_t i) (instr_args_t outs args) = coerce f in
match v with
| None -> ()
| Some v -> lemma_eq_instr_apply_eval_args outs args (f v) oprs s1 s2
)
#restart-solver
let rec lemma_eq_instr_apply_eval_inouts
(outs inouts:list instr_out) (args:list instr_operand)
(f:instr_inouts_t outs inouts args) (oprs:instr_operands_t inouts args) (s1 s2:machine_state)
: Lemma
(requires state_eq_S true s1 s2)
(ensures
BS.instr_apply_eval_inouts outs inouts args f oprs s1 ==
BS.instr_apply_eval_inouts outs inouts args f oprs s2)
=
let open BS in
lemma_heap_ignore_ghost_machine s1.BS.ms_heap s2.BS.ms_heap;
match inouts with
| [] -> lemma_eq_instr_apply_eval_args outs args f oprs s1 s2
| (Out, i)::inouts ->
let oprs =
match i with
| IOpEx i -> snd #(instr_operand_t i) (coerce oprs)
| IOpIm i -> coerce oprs
in
lemma_eq_instr_apply_eval_inouts outs inouts args (coerce f) oprs s1 s2
| (InOut, i)::inouts ->
(
let (v, oprs) : option (instr_val_t i) & instr_operands_t inouts args =
match i with
| IOpEx i -> let oprs = coerce oprs in (instr_eval_operand_explicit i (fst oprs) s1, snd oprs)
| IOpIm i -> (instr_eval_operand_implicit i s1, coerce oprs)
in
let f:arrow (instr_val_t i) (instr_inouts_t outs inouts args) = coerce f in
match v with
| None -> ()
| Some v -> lemma_eq_instr_apply_eval_inouts outs inouts args (f v) oprs s1 s2
)
#restart-solver
#push-options "--z3rlimit_factor 2"
let rec lemma_eq_instr_write_outputs
(outs:list instr_out) (args:list instr_operand)
(vs:instr_ret_t outs) (oprs:instr_operands_t outs args) (s1_orig s1 s2_orig s2:machine_state)
: Lemma
(requires state_eq_S true s1_orig s2_orig /\ state_eq_S true s1 s2)
(ensures
state_eq_S true
(BS.instr_write_outputs outs args vs oprs s1_orig s1)
(BS.instr_write_outputs outs args vs oprs s2_orig s2))
=
let open BS in
use_machine_state_equal ();
lemma_heap_ignore_ghost_machine s1.BS.ms_heap s2.BS.ms_heap;
lemma_heap_ignore_ghost_machine s1_orig.BS.ms_heap s2_orig.BS.ms_heap;
allow_inversion tmaddr;
match outs with
| [] -> ()
| (_, i)::outs ->
(
let ((v:instr_val_t i), (vs:instr_ret_t outs)) =
match outs with
| [] -> (vs, ())
| _::_ -> let vs = coerce vs in (fst vs, snd vs)
in
match i with
| IOpEx i ->
let oprs = coerce oprs in
let s1 = instr_write_output_explicit i v (fst oprs) s1_orig s1 in
let s2 = instr_write_output_explicit i v (fst oprs) s2_orig s2 in
lemma_eq_instr_write_outputs outs args vs (snd oprs) s1_orig s1 s2_orig s2
| IOpIm i ->
let s1 = instr_write_output_implicit i v s1_orig s1 in
let s2 = instr_write_output_implicit i v s2_orig s2 in
allow_inversion operand64;
allow_inversion operand128;
lemma_eq_instr_write_outputs outs args vs (coerce oprs) s1_orig s1 s2_orig s2
)
#pop-options
#restart-solver
let eval_ins_eq_instr (inst:BS.ins) (s1 s2:machine_state) : Lemma
(requires Instr? inst /\ state_eq_S true s1 s2)
(ensures state_eq_S true (BS.machine_eval_ins inst s1) (BS.machine_eval_ins inst s2))
=
let open BS in
let Instr it oprs ann = inst in
let InstrTypeRecord #outs #args #havoc_flags' i = it in
lemma_eq_instr_apply_eval_inouts outs outs args (instr_eval i) oprs s1 s2;
let vs = instr_apply_eval outs args (instr_eval i) oprs s1 in
let hav s =
match havoc_flags' with
| HavocFlags -> {s with ms_flags = havoc_flags}
| PreserveFlags -> s
in
let s1' = hav s1 in
let s2' = hav s2 in
match vs with
| None -> ()
| Some vs -> lemma_eq_instr_write_outputs outs args vs oprs s1 s1' s2 s2'
let eval_code_eq_instr (inst:BS.ins) (f:fuel) (s1 s2:machine_state) : Lemma
(requires Instr? inst /\ state_eq_S true s1 s2)
(ensures state_eq_opt true (BS.machine_eval_code (Ins inst) f s1) (BS.machine_eval_code (Ins inst) f s2))
=
reveal_opaque (`%BS.machine_eval_code_ins) BS.machine_eval_code_ins;
eval_ins_eq_instr inst ({s1 with BS.ms_trace = []}) ({s2 with BS.ms_trace = []})
let eval_code_eq_dealloc (inst:BS.ins) (f:fuel) (s1 s2:machine_state) : Lemma
(requires Dealloc? inst /\ state_eq_S true s1 s2)
(ensures state_eq_opt true (BS.machine_eval_code (Ins inst) f s1) (BS.machine_eval_code (Ins inst) f s2))
=
reveal_opaque (`%BS.machine_eval_code_ins) BS.machine_eval_code_ins;
use_machine_state_equal ();
lemma_heap_ignore_ghost_machine s1.BS.ms_heap s2.BS.ms_heap;
allow_inversion tmaddr
let eval_code_eq_alloc (inst:BS.ins) (f:fuel) (s1 s2:machine_state) : Lemma
(requires Alloc? inst /\ state_eq_S true s1 s2)
(ensures state_eq_opt true (BS.machine_eval_code (Ins inst) f s1) (BS.machine_eval_code (Ins inst) f s2))
=
reveal_opaque (`%BS.machine_eval_code_ins) BS.machine_eval_code_ins;
use_machine_state_equal ();
lemma_heap_ignore_ghost_machine s1.BS.ms_heap s2.BS.ms_heap;
allow_inversion tmaddr
let eval_code_eq_push (inst:BS.ins) (f:fuel) (s1 s2:machine_state) : Lemma
(requires Push? inst /\ state_eq_S true s1 s2)
(ensures state_eq_opt true (BS.machine_eval_code (Ins inst) f s1) (BS.machine_eval_code (Ins inst) f s2)) | false | false | Vale.X64.Lemmas.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 1,
"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": 100,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val eval_code_eq_push (inst: BS.ins) (f: fuel) (s1 s2: machine_state)
: Lemma (requires Push? inst /\ state_eq_S true s1 s2)
(ensures
state_eq_opt true
(BS.machine_eval_code (Ins inst) f s1)
(BS.machine_eval_code (Ins inst) f s2)) | [] | Vale.X64.Lemmas.eval_code_eq_push | {
"file_name": "vale/code/arch/x64/Vale.X64.Lemmas.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} |
inst: Vale.X64.Machine_Semantics_s.ins ->
f: Vale.X64.Lemmas.fuel ->
s1: Vale.X64.StateLemmas.machine_state ->
s2: Vale.X64.StateLemmas.machine_state
-> FStar.Pervasives.Lemma (requires Push? inst /\ Vale.X64.Lemmas.state_eq_S true s1 s2)
(ensures
Vale.X64.Lemmas.state_eq_opt true
(Vale.X64.Machine_Semantics_s.machine_eval_code (Vale.X64.Machine_s.Ins inst) f s1)
(Vale.X64.Machine_Semantics_s.machine_eval_code (Vale.X64.Machine_s.Ins inst) f s2)) | {
"end_col": 24,
"end_line": 168,
"start_col": 2,
"start_line": 165
} |
FStar.Pervasives.Lemma | val lemma_eq_instr_apply_eval_args
(outs: list instr_out)
(args: list instr_operand)
(f: instr_args_t outs args)
(oprs: instr_operands_t_args args)
(s1 s2: machine_state)
: Lemma (requires state_eq_S true s1 s2)
(ensures
BS.instr_apply_eval_args outs args f oprs s1 == BS.instr_apply_eval_args outs args f oprs s2
) | [
{
"abbrev": true,
"full_module": "Vale.X64.Memory",
"short_module": "ME"
},
{
"abbrev": true,
"full_module": "Vale.X64.Machine_Semantics_s",
"short_module": "BS"
},
{
"abbrev": false,
"full_module": "Vale.X64.Bytes_Code_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Instruction_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.StateLemmas",
"short_module": null
},
{
"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": "FStar.Mul",
"short_module": null
},
{
"abbrev": true,
"full_module": "Vale.Lib.Map16",
"short_module": "Map16"
},
{
"abbrev": true,
"full_module": "Vale.X64.Machine_Semantics_s",
"short_module": "BS"
},
{
"abbrev": false,
"full_module": "Vale.X64.Bytes_Code_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.StateLemmas",
"short_module": null
},
{
"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.HeapLemmas",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.HeapImpl",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Heap",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"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 rec lemma_eq_instr_apply_eval_args
(outs:list instr_out) (args:list instr_operand)
(f:instr_args_t outs args) (oprs:instr_operands_t_args args) (s1 s2:machine_state)
: Lemma
(requires state_eq_S true s1 s2)
(ensures
BS.instr_apply_eval_args outs args f oprs s1 ==
BS.instr_apply_eval_args outs args f oprs s2)
=
let open BS in
lemma_heap_ignore_ghost_machine s1.BS.ms_heap s2.BS.ms_heap;
match args with
| [] -> ()
| i::args ->
(
let (v, oprs) : option (instr_val_t i) & instr_operands_t_args args =
match i with
| IOpEx i -> let oprs = coerce oprs in (instr_eval_operand_explicit i (fst oprs) s1, snd oprs)
| IOpIm i -> (instr_eval_operand_implicit i s1, coerce oprs)
in
let f:arrow (instr_val_t i) (instr_args_t outs args) = coerce f in
match v with
| None -> ()
| Some v -> lemma_eq_instr_apply_eval_args outs args (f v) oprs s1 s2
) | val lemma_eq_instr_apply_eval_args
(outs: list instr_out)
(args: list instr_operand)
(f: instr_args_t outs args)
(oprs: instr_operands_t_args args)
(s1 s2: machine_state)
: Lemma (requires state_eq_S true s1 s2)
(ensures
BS.instr_apply_eval_args outs args f oprs s1 == BS.instr_apply_eval_args outs args f oprs s2
)
let rec lemma_eq_instr_apply_eval_args
(outs: list instr_out)
(args: list instr_operand)
(f: instr_args_t outs args)
(oprs: instr_operands_t_args args)
(s1 s2: machine_state)
: Lemma (requires state_eq_S true s1 s2)
(ensures
BS.instr_apply_eval_args outs args f oprs s1 == BS.instr_apply_eval_args outs args f oprs s2
) = | false | null | true | let open BS in
lemma_heap_ignore_ghost_machine s1.BS.ms_heap s2.BS.ms_heap;
match args with
| [] -> ()
| i :: args ->
(let v, oprs:option (instr_val_t i) & instr_operands_t_args args =
match i with
| IOpEx i ->
let oprs = coerce oprs in
(instr_eval_operand_explicit i (fst oprs) s1, snd oprs)
| IOpIm i -> (instr_eval_operand_implicit i s1, coerce oprs)
in
let f:arrow (instr_val_t i) (instr_args_t outs args) = coerce f in
match v with
| None -> ()
| Some v -> lemma_eq_instr_apply_eval_args outs args (f v) oprs s1 s2) | {
"checked_file": "Vale.X64.Lemmas.fst.checked",
"dependencies": [
"Vale.X64.StateLemmas.fsti.checked",
"Vale.X64.State.fsti.checked",
"Vale.X64.Memory.fsti.checked",
"Vale.X64.Machine_Semantics_s.fst.checked",
"Vale.X64.Machine_s.fst.checked",
"Vale.X64.Instruction_s.fsti.checked",
"Vale.X64.Flags.fsti.checked",
"Vale.X64.Bytes_Code_s.fst.checked",
"prims.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.FunctionalExtensionality.fsti.checked"
],
"interface_file": true,
"source_file": "Vale.X64.Lemmas.fst"
} | [
"lemma"
] | [
"Prims.list",
"Vale.X64.Instruction_s.instr_out",
"Vale.X64.Instruction_s.instr_operand",
"Vale.X64.Instruction_s.instr_args_t",
"Vale.X64.Instruction_s.instr_operands_t_args",
"Vale.X64.StateLemmas.machine_state",
"FStar.Pervasives.Native.option",
"Vale.X64.Instruction_s.instr_val_t",
"Vale.X64.Lemmas.lemma_eq_instr_apply_eval_args",
"Prims.unit",
"Vale.X64.Instruction_s.arrow",
"Vale.X64.Instruction_s.coerce",
"FStar.Pervasives.Native.tuple2",
"Vale.X64.Instruction_s.instr_operand_explicit",
"FStar.Pervasives.Native.Mktuple2",
"Vale.X64.Machine_Semantics_s.instr_eval_operand_explicit",
"FStar.Pervasives.Native.fst",
"Vale.X64.Instruction_s.instr_operand_t",
"FStar.Pervasives.Native.snd",
"Vale.X64.Instruction_s.instr_operand_implicit",
"Vale.X64.Machine_Semantics_s.instr_eval_operand_implicit",
"Vale.Arch.HeapLemmas.lemma_heap_ignore_ghost_machine",
"Vale.X64.Machine_Semantics_s.__proj__Mkmachine_state__item__ms_heap",
"Vale.X64.Lemmas.state_eq_S",
"Prims.squash",
"Prims.eq2",
"Vale.X64.Instruction_s.instr_ret_t",
"Vale.X64.Machine_Semantics_s.instr_apply_eval_args",
"Prims.Nil",
"FStar.Pervasives.pattern"
] | [] | module Vale.X64.Lemmas
open FStar.Mul
open Vale.X64.Machine_s
open Vale.X64.State
open Vale.X64.StateLemmas
open Vale.X64.Instruction_s
open Vale.X64.Bytes_Code_s
module BS = Vale.X64.Machine_Semantics_s
module ME = Vale.X64.Memory
#reset-options "--initial_fuel 1 --max_fuel 1 --z3rlimit 100"
#restart-solver
let rec lemma_eq_instr_apply_eval_args
(outs:list instr_out) (args:list instr_operand)
(f:instr_args_t outs args) (oprs:instr_operands_t_args args) (s1 s2:machine_state)
: Lemma
(requires state_eq_S true s1 s2)
(ensures
BS.instr_apply_eval_args outs args f oprs s1 ==
BS.instr_apply_eval_args outs args f oprs s2) | false | false | Vale.X64.Lemmas.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 1,
"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": 100,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val lemma_eq_instr_apply_eval_args
(outs: list instr_out)
(args: list instr_operand)
(f: instr_args_t outs args)
(oprs: instr_operands_t_args args)
(s1 s2: machine_state)
: Lemma (requires state_eq_S true s1 s2)
(ensures
BS.instr_apply_eval_args outs args f oprs s1 == BS.instr_apply_eval_args outs args f oprs s2
) | [
"recursion"
] | Vale.X64.Lemmas.lemma_eq_instr_apply_eval_args | {
"file_name": "vale/code/arch/x64/Vale.X64.Lemmas.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} |
outs: Prims.list Vale.X64.Instruction_s.instr_out ->
args: Prims.list Vale.X64.Instruction_s.instr_operand ->
f: Vale.X64.Instruction_s.instr_args_t outs args ->
oprs: Vale.X64.Instruction_s.instr_operands_t_args args ->
s1: Vale.X64.StateLemmas.machine_state ->
s2: Vale.X64.StateLemmas.machine_state
-> FStar.Pervasives.Lemma (requires Vale.X64.Lemmas.state_eq_S true s1 s2)
(ensures
Vale.X64.Machine_Semantics_s.instr_apply_eval_args outs args f oprs s1 ==
Vale.X64.Machine_Semantics_s.instr_apply_eval_args outs args f oprs s2) | {
"end_col": 5,
"end_line": 38,
"start_col": 2,
"start_line": 23
} |
FStar.Pervasives.Lemma | val eval_ocmp_eq_core (g: bool) (cond: ocmp) (s: machine_state)
: Lemma
(ensures
(let s1, b1 = BS.machine_eval_ocmp s cond in
let s2, b2 = BS.machine_eval_ocmp (core_state g s) cond in
state_eq_S g s1 s2 /\ b1 == b2)) | [
{
"abbrev": true,
"full_module": "Vale.X64.Memory",
"short_module": "ME"
},
{
"abbrev": true,
"full_module": "Vale.X64.Machine_Semantics_s",
"short_module": "BS"
},
{
"abbrev": false,
"full_module": "Vale.X64.Bytes_Code_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Instruction_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.StateLemmas",
"short_module": null
},
{
"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": "FStar.Mul",
"short_module": null
},
{
"abbrev": true,
"full_module": "Vale.Lib.Map16",
"short_module": "Map16"
},
{
"abbrev": true,
"full_module": "Vale.X64.Machine_Semantics_s",
"short_module": "BS"
},
{
"abbrev": false,
"full_module": "Vale.X64.Bytes_Code_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.StateLemmas",
"short_module": null
},
{
"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.HeapLemmas",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.HeapImpl",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Heap",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"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 eval_ocmp_eq_core (g:bool) (cond:ocmp) (s:machine_state) : Lemma
(ensures (
let (s1, b1) = BS.machine_eval_ocmp s cond in
let (s2, b2) = BS.machine_eval_ocmp (core_state g s) cond in
state_eq_S g s1 s2 /\ b1 == b2
))
=
reveal_opaque (`%BS.valid_ocmp_opaque) BS.valid_ocmp_opaque;
reveal_opaque (`%BS.eval_ocmp_opaque) BS.eval_ocmp_opaque;
() | val eval_ocmp_eq_core (g: bool) (cond: ocmp) (s: machine_state)
: Lemma
(ensures
(let s1, b1 = BS.machine_eval_ocmp s cond in
let s2, b2 = BS.machine_eval_ocmp (core_state g s) cond in
state_eq_S g s1 s2 /\ b1 == b2))
let eval_ocmp_eq_core (g: bool) (cond: ocmp) (s: machine_state)
: Lemma
(ensures
(let s1, b1 = BS.machine_eval_ocmp s cond in
let s2, b2 = BS.machine_eval_ocmp (core_state g s) cond in
state_eq_S g s1 s2 /\ b1 == b2)) = | false | null | true | reveal_opaque (`%BS.valid_ocmp_opaque) BS.valid_ocmp_opaque;
reveal_opaque (`%BS.eval_ocmp_opaque) BS.eval_ocmp_opaque;
() | {
"checked_file": "Vale.X64.Lemmas.fst.checked",
"dependencies": [
"Vale.X64.StateLemmas.fsti.checked",
"Vale.X64.State.fsti.checked",
"Vale.X64.Memory.fsti.checked",
"Vale.X64.Machine_Semantics_s.fst.checked",
"Vale.X64.Machine_s.fst.checked",
"Vale.X64.Instruction_s.fsti.checked",
"Vale.X64.Flags.fsti.checked",
"Vale.X64.Bytes_Code_s.fst.checked",
"prims.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.FunctionalExtensionality.fsti.checked"
],
"interface_file": true,
"source_file": "Vale.X64.Lemmas.fst"
} | [
"lemma"
] | [
"Prims.bool",
"Vale.X64.Bytes_Code_s.ocmp",
"Vale.X64.StateLemmas.machine_state",
"Prims.unit",
"FStar.Pervasives.reveal_opaque",
"Vale.X64.Machine_Semantics_s.machine_state",
"Vale.X64.Machine_Semantics_s.ocmp",
"Vale.X64.Machine_Semantics_s.eval_ocmp_opaque",
"Vale.X64.Machine_Semantics_s.valid_ocmp_opaque",
"Prims.l_True",
"Prims.squash",
"Prims.l_and",
"Vale.X64.Lemmas.state_eq_S",
"Prims.eq2",
"FStar.Pervasives.Native.tuple2",
"Vale.X64.Machine_Semantics_s.machine_eval_ocmp",
"Vale.X64.Lemmas.core_state",
"Prims.Nil",
"FStar.Pervasives.pattern"
] | [] | module Vale.X64.Lemmas
open FStar.Mul
open Vale.X64.Machine_s
open Vale.X64.State
open Vale.X64.StateLemmas
open Vale.X64.Instruction_s
open Vale.X64.Bytes_Code_s
module BS = Vale.X64.Machine_Semantics_s
module ME = Vale.X64.Memory
#reset-options "--initial_fuel 1 --max_fuel 1 --z3rlimit 100"
#restart-solver
let rec lemma_eq_instr_apply_eval_args
(outs:list instr_out) (args:list instr_operand)
(f:instr_args_t outs args) (oprs:instr_operands_t_args args) (s1 s2:machine_state)
: Lemma
(requires state_eq_S true s1 s2)
(ensures
BS.instr_apply_eval_args outs args f oprs s1 ==
BS.instr_apply_eval_args outs args f oprs s2)
=
let open BS in
lemma_heap_ignore_ghost_machine s1.BS.ms_heap s2.BS.ms_heap;
match args with
| [] -> ()
| i::args ->
(
let (v, oprs) : option (instr_val_t i) & instr_operands_t_args args =
match i with
| IOpEx i -> let oprs = coerce oprs in (instr_eval_operand_explicit i (fst oprs) s1, snd oprs)
| IOpIm i -> (instr_eval_operand_implicit i s1, coerce oprs)
in
let f:arrow (instr_val_t i) (instr_args_t outs args) = coerce f in
match v with
| None -> ()
| Some v -> lemma_eq_instr_apply_eval_args outs args (f v) oprs s1 s2
)
#restart-solver
let rec lemma_eq_instr_apply_eval_inouts
(outs inouts:list instr_out) (args:list instr_operand)
(f:instr_inouts_t outs inouts args) (oprs:instr_operands_t inouts args) (s1 s2:machine_state)
: Lemma
(requires state_eq_S true s1 s2)
(ensures
BS.instr_apply_eval_inouts outs inouts args f oprs s1 ==
BS.instr_apply_eval_inouts outs inouts args f oprs s2)
=
let open BS in
lemma_heap_ignore_ghost_machine s1.BS.ms_heap s2.BS.ms_heap;
match inouts with
| [] -> lemma_eq_instr_apply_eval_args outs args f oprs s1 s2
| (Out, i)::inouts ->
let oprs =
match i with
| IOpEx i -> snd #(instr_operand_t i) (coerce oprs)
| IOpIm i -> coerce oprs
in
lemma_eq_instr_apply_eval_inouts outs inouts args (coerce f) oprs s1 s2
| (InOut, i)::inouts ->
(
let (v, oprs) : option (instr_val_t i) & instr_operands_t inouts args =
match i with
| IOpEx i -> let oprs = coerce oprs in (instr_eval_operand_explicit i (fst oprs) s1, snd oprs)
| IOpIm i -> (instr_eval_operand_implicit i s1, coerce oprs)
in
let f:arrow (instr_val_t i) (instr_inouts_t outs inouts args) = coerce f in
match v with
| None -> ()
| Some v -> lemma_eq_instr_apply_eval_inouts outs inouts args (f v) oprs s1 s2
)
#restart-solver
#push-options "--z3rlimit_factor 2"
let rec lemma_eq_instr_write_outputs
(outs:list instr_out) (args:list instr_operand)
(vs:instr_ret_t outs) (oprs:instr_operands_t outs args) (s1_orig s1 s2_orig s2:machine_state)
: Lemma
(requires state_eq_S true s1_orig s2_orig /\ state_eq_S true s1 s2)
(ensures
state_eq_S true
(BS.instr_write_outputs outs args vs oprs s1_orig s1)
(BS.instr_write_outputs outs args vs oprs s2_orig s2))
=
let open BS in
use_machine_state_equal ();
lemma_heap_ignore_ghost_machine s1.BS.ms_heap s2.BS.ms_heap;
lemma_heap_ignore_ghost_machine s1_orig.BS.ms_heap s2_orig.BS.ms_heap;
allow_inversion tmaddr;
match outs with
| [] -> ()
| (_, i)::outs ->
(
let ((v:instr_val_t i), (vs:instr_ret_t outs)) =
match outs with
| [] -> (vs, ())
| _::_ -> let vs = coerce vs in (fst vs, snd vs)
in
match i with
| IOpEx i ->
let oprs = coerce oprs in
let s1 = instr_write_output_explicit i v (fst oprs) s1_orig s1 in
let s2 = instr_write_output_explicit i v (fst oprs) s2_orig s2 in
lemma_eq_instr_write_outputs outs args vs (snd oprs) s1_orig s1 s2_orig s2
| IOpIm i ->
let s1 = instr_write_output_implicit i v s1_orig s1 in
let s2 = instr_write_output_implicit i v s2_orig s2 in
allow_inversion operand64;
allow_inversion operand128;
lemma_eq_instr_write_outputs outs args vs (coerce oprs) s1_orig s1 s2_orig s2
)
#pop-options
#restart-solver
let eval_ins_eq_instr (inst:BS.ins) (s1 s2:machine_state) : Lemma
(requires Instr? inst /\ state_eq_S true s1 s2)
(ensures state_eq_S true (BS.machine_eval_ins inst s1) (BS.machine_eval_ins inst s2))
=
let open BS in
let Instr it oprs ann = inst in
let InstrTypeRecord #outs #args #havoc_flags' i = it in
lemma_eq_instr_apply_eval_inouts outs outs args (instr_eval i) oprs s1 s2;
let vs = instr_apply_eval outs args (instr_eval i) oprs s1 in
let hav s =
match havoc_flags' with
| HavocFlags -> {s with ms_flags = havoc_flags}
| PreserveFlags -> s
in
let s1' = hav s1 in
let s2' = hav s2 in
match vs with
| None -> ()
| Some vs -> lemma_eq_instr_write_outputs outs args vs oprs s1 s1' s2 s2'
let eval_code_eq_instr (inst:BS.ins) (f:fuel) (s1 s2:machine_state) : Lemma
(requires Instr? inst /\ state_eq_S true s1 s2)
(ensures state_eq_opt true (BS.machine_eval_code (Ins inst) f s1) (BS.machine_eval_code (Ins inst) f s2))
=
reveal_opaque (`%BS.machine_eval_code_ins) BS.machine_eval_code_ins;
eval_ins_eq_instr inst ({s1 with BS.ms_trace = []}) ({s2 with BS.ms_trace = []})
let eval_code_eq_dealloc (inst:BS.ins) (f:fuel) (s1 s2:machine_state) : Lemma
(requires Dealloc? inst /\ state_eq_S true s1 s2)
(ensures state_eq_opt true (BS.machine_eval_code (Ins inst) f s1) (BS.machine_eval_code (Ins inst) f s2))
=
reveal_opaque (`%BS.machine_eval_code_ins) BS.machine_eval_code_ins;
use_machine_state_equal ();
lemma_heap_ignore_ghost_machine s1.BS.ms_heap s2.BS.ms_heap;
allow_inversion tmaddr
let eval_code_eq_alloc (inst:BS.ins) (f:fuel) (s1 s2:machine_state) : Lemma
(requires Alloc? inst /\ state_eq_S true s1 s2)
(ensures state_eq_opt true (BS.machine_eval_code (Ins inst) f s1) (BS.machine_eval_code (Ins inst) f s2))
=
reveal_opaque (`%BS.machine_eval_code_ins) BS.machine_eval_code_ins;
use_machine_state_equal ();
lemma_heap_ignore_ghost_machine s1.BS.ms_heap s2.BS.ms_heap;
allow_inversion tmaddr
let eval_code_eq_push (inst:BS.ins) (f:fuel) (s1 s2:machine_state) : Lemma
(requires Push? inst /\ state_eq_S true s1 s2)
(ensures state_eq_opt true (BS.machine_eval_code (Ins inst) f s1) (BS.machine_eval_code (Ins inst) f s2))
=
reveal_opaque (`%BS.machine_eval_code_ins) BS.machine_eval_code_ins;
use_machine_state_equal ();
lemma_heap_ignore_ghost_machine s1.BS.ms_heap s2.BS.ms_heap;
allow_inversion tmaddr
let eval_code_eq_pop (inst:BS.ins) (f:fuel) (s1 s2:machine_state) : Lemma
(requires Pop? inst /\ state_eq_S true s1 s2)
(ensures state_eq_opt true (BS.machine_eval_code (Ins inst) f s1) (BS.machine_eval_code (Ins inst) f s2))
=
reveal_opaque (`%BS.machine_eval_code_ins) BS.machine_eval_code_ins;
use_machine_state_equal ();
lemma_heap_ignore_ghost_machine s1.BS.ms_heap s2.BS.ms_heap;
allow_inversion tmaddr
let eval_code_eq_ins (i:BS.ins) (f:fuel) (s1 s2:machine_state) : Lemma
(requires state_eq_S true s1 s2)
(ensures state_eq_opt true (BS.machine_eval_code (Ins i) f s1) (BS.machine_eval_code (Ins i) f s2))
=
match i with
| Instr _ _ _ -> eval_code_eq_instr i f s1 s2
| Dealloc _ -> eval_code_eq_dealloc i f s1 s2
| Alloc _ -> eval_code_eq_alloc i f s1 s2
| Push _ _ -> eval_code_eq_push i f s1 s2
| Pop _ _ -> eval_code_eq_pop i f s1 s2
#reset-options "--fuel 2 --z3rlimit 30"
let eval_ocmp_eq_core (g:bool) (cond:ocmp) (s:machine_state) : Lemma
(ensures (
let (s1, b1) = BS.machine_eval_ocmp s cond in
let (s2, b2) = BS.machine_eval_ocmp (core_state g s) cond in
state_eq_S g s1 s2 /\ b1 == b2
)) | false | false | Vale.X64.Lemmas.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": 30,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val eval_ocmp_eq_core (g: bool) (cond: ocmp) (s: machine_state)
: Lemma
(ensures
(let s1, b1 = BS.machine_eval_ocmp s cond in
let s2, b2 = BS.machine_eval_ocmp (core_state g s) cond in
state_eq_S g s1 s2 /\ b1 == b2)) | [] | Vale.X64.Lemmas.eval_ocmp_eq_core | {
"file_name": "vale/code/arch/x64/Vale.X64.Lemmas.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | g: Prims.bool -> cond: Vale.X64.Bytes_Code_s.ocmp -> s: Vale.X64.StateLemmas.machine_state
-> FStar.Pervasives.Lemma
(ensures
(let _ = Vale.X64.Machine_Semantics_s.machine_eval_ocmp s cond in
(let FStar.Pervasives.Native.Mktuple2 #_ #_ s1 b1 = _ in
let _ =
Vale.X64.Machine_Semantics_s.machine_eval_ocmp (Vale.X64.Lemmas.core_state g s) cond
in
(let FStar.Pervasives.Native.Mktuple2 #_ #_ s2 b2 = _ in
Vale.X64.Lemmas.state_eq_S g s1 s2 /\ b1 == b2)
<:
Type0)
<:
Type0)) | {
"end_col": 4,
"end_line": 201,
"start_col": 2,
"start_line": 199
} |
FStar.Pervasives.Lemma | val lemma_eq_instr_apply_eval_inouts
(outs inouts: list instr_out)
(args: list instr_operand)
(f: instr_inouts_t outs inouts args)
(oprs: instr_operands_t inouts args)
(s1 s2: machine_state)
: Lemma (requires state_eq_S true s1 s2)
(ensures
BS.instr_apply_eval_inouts outs inouts args f oprs s1 ==
BS.instr_apply_eval_inouts outs inouts args f oprs s2) | [
{
"abbrev": true,
"full_module": "Vale.X64.Memory",
"short_module": "ME"
},
{
"abbrev": true,
"full_module": "Vale.X64.Machine_Semantics_s",
"short_module": "BS"
},
{
"abbrev": false,
"full_module": "Vale.X64.Bytes_Code_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Instruction_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.StateLemmas",
"short_module": null
},
{
"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": "FStar.Mul",
"short_module": null
},
{
"abbrev": true,
"full_module": "Vale.Lib.Map16",
"short_module": "Map16"
},
{
"abbrev": true,
"full_module": "Vale.X64.Machine_Semantics_s",
"short_module": "BS"
},
{
"abbrev": false,
"full_module": "Vale.X64.Bytes_Code_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.StateLemmas",
"short_module": null
},
{
"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.HeapLemmas",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.HeapImpl",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Heap",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"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 rec lemma_eq_instr_apply_eval_inouts
(outs inouts:list instr_out) (args:list instr_operand)
(f:instr_inouts_t outs inouts args) (oprs:instr_operands_t inouts args) (s1 s2:machine_state)
: Lemma
(requires state_eq_S true s1 s2)
(ensures
BS.instr_apply_eval_inouts outs inouts args f oprs s1 ==
BS.instr_apply_eval_inouts outs inouts args f oprs s2)
=
let open BS in
lemma_heap_ignore_ghost_machine s1.BS.ms_heap s2.BS.ms_heap;
match inouts with
| [] -> lemma_eq_instr_apply_eval_args outs args f oprs s1 s2
| (Out, i)::inouts ->
let oprs =
match i with
| IOpEx i -> snd #(instr_operand_t i) (coerce oprs)
| IOpIm i -> coerce oprs
in
lemma_eq_instr_apply_eval_inouts outs inouts args (coerce f) oprs s1 s2
| (InOut, i)::inouts ->
(
let (v, oprs) : option (instr_val_t i) & instr_operands_t inouts args =
match i with
| IOpEx i -> let oprs = coerce oprs in (instr_eval_operand_explicit i (fst oprs) s1, snd oprs)
| IOpIm i -> (instr_eval_operand_implicit i s1, coerce oprs)
in
let f:arrow (instr_val_t i) (instr_inouts_t outs inouts args) = coerce f in
match v with
| None -> ()
| Some v -> lemma_eq_instr_apply_eval_inouts outs inouts args (f v) oprs s1 s2
) | val lemma_eq_instr_apply_eval_inouts
(outs inouts: list instr_out)
(args: list instr_operand)
(f: instr_inouts_t outs inouts args)
(oprs: instr_operands_t inouts args)
(s1 s2: machine_state)
: Lemma (requires state_eq_S true s1 s2)
(ensures
BS.instr_apply_eval_inouts outs inouts args f oprs s1 ==
BS.instr_apply_eval_inouts outs inouts args f oprs s2)
let rec lemma_eq_instr_apply_eval_inouts
(outs inouts: list instr_out)
(args: list instr_operand)
(f: instr_inouts_t outs inouts args)
(oprs: instr_operands_t inouts args)
(s1 s2: machine_state)
: Lemma (requires state_eq_S true s1 s2)
(ensures
BS.instr_apply_eval_inouts outs inouts args f oprs s1 ==
BS.instr_apply_eval_inouts outs inouts args f oprs s2) = | false | null | true | let open BS in
lemma_heap_ignore_ghost_machine s1.BS.ms_heap s2.BS.ms_heap;
match inouts with
| [] -> lemma_eq_instr_apply_eval_args outs args f oprs s1 s2
| (Out, i) :: inouts ->
let oprs =
match i with
| IOpEx i -> snd #(instr_operand_t i) (coerce oprs)
| IOpIm i -> coerce oprs
in
lemma_eq_instr_apply_eval_inouts outs inouts args (coerce f) oprs s1 s2
| (InOut, i) :: inouts ->
(let v, oprs:option (instr_val_t i) & instr_operands_t inouts args =
match i with
| IOpEx i ->
let oprs = coerce oprs in
(instr_eval_operand_explicit i (fst oprs) s1, snd oprs)
| IOpIm i -> (instr_eval_operand_implicit i s1, coerce oprs)
in
let f:arrow (instr_val_t i) (instr_inouts_t outs inouts args) = coerce f in
match v with
| None -> ()
| Some v -> lemma_eq_instr_apply_eval_inouts outs inouts args (f v) oprs s1 s2) | {
"checked_file": "Vale.X64.Lemmas.fst.checked",
"dependencies": [
"Vale.X64.StateLemmas.fsti.checked",
"Vale.X64.State.fsti.checked",
"Vale.X64.Memory.fsti.checked",
"Vale.X64.Machine_Semantics_s.fst.checked",
"Vale.X64.Machine_s.fst.checked",
"Vale.X64.Instruction_s.fsti.checked",
"Vale.X64.Flags.fsti.checked",
"Vale.X64.Bytes_Code_s.fst.checked",
"prims.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.FunctionalExtensionality.fsti.checked"
],
"interface_file": true,
"source_file": "Vale.X64.Lemmas.fst"
} | [
"lemma"
] | [
"Prims.list",
"Vale.X64.Instruction_s.instr_out",
"Vale.X64.Instruction_s.instr_operand",
"Vale.X64.Instruction_s.instr_inouts_t",
"Vale.X64.Instruction_s.instr_operands_t",
"Vale.X64.StateLemmas.machine_state",
"Vale.X64.Lemmas.lemma_eq_instr_apply_eval_args",
"Vale.X64.Lemmas.lemma_eq_instr_apply_eval_inouts",
"Vale.X64.Instruction_s.coerce",
"Vale.X64.Instruction_s.instr_operand_explicit",
"FStar.Pervasives.Native.snd",
"Vale.X64.Instruction_s.instr_operand_t",
"FStar.Pervasives.Native.tuple2",
"Vale.X64.Instruction_s.instr_operand_implicit",
"FStar.Pervasives.Native.option",
"Vale.X64.Instruction_s.instr_val_t",
"Prims.unit",
"Vale.X64.Instruction_s.arrow",
"FStar.Pervasives.Native.Mktuple2",
"Vale.X64.Machine_Semantics_s.instr_eval_operand_explicit",
"FStar.Pervasives.Native.fst",
"Vale.X64.Machine_Semantics_s.instr_eval_operand_implicit",
"Vale.Arch.HeapLemmas.lemma_heap_ignore_ghost_machine",
"Vale.X64.Machine_Semantics_s.__proj__Mkmachine_state__item__ms_heap",
"Vale.X64.Lemmas.state_eq_S",
"Prims.squash",
"Prims.eq2",
"Vale.X64.Instruction_s.instr_ret_t",
"Vale.X64.Machine_Semantics_s.instr_apply_eval_inouts",
"Prims.Nil",
"FStar.Pervasives.pattern"
] | [] | module Vale.X64.Lemmas
open FStar.Mul
open Vale.X64.Machine_s
open Vale.X64.State
open Vale.X64.StateLemmas
open Vale.X64.Instruction_s
open Vale.X64.Bytes_Code_s
module BS = Vale.X64.Machine_Semantics_s
module ME = Vale.X64.Memory
#reset-options "--initial_fuel 1 --max_fuel 1 --z3rlimit 100"
#restart-solver
let rec lemma_eq_instr_apply_eval_args
(outs:list instr_out) (args:list instr_operand)
(f:instr_args_t outs args) (oprs:instr_operands_t_args args) (s1 s2:machine_state)
: Lemma
(requires state_eq_S true s1 s2)
(ensures
BS.instr_apply_eval_args outs args f oprs s1 ==
BS.instr_apply_eval_args outs args f oprs s2)
=
let open BS in
lemma_heap_ignore_ghost_machine s1.BS.ms_heap s2.BS.ms_heap;
match args with
| [] -> ()
| i::args ->
(
let (v, oprs) : option (instr_val_t i) & instr_operands_t_args args =
match i with
| IOpEx i -> let oprs = coerce oprs in (instr_eval_operand_explicit i (fst oprs) s1, snd oprs)
| IOpIm i -> (instr_eval_operand_implicit i s1, coerce oprs)
in
let f:arrow (instr_val_t i) (instr_args_t outs args) = coerce f in
match v with
| None -> ()
| Some v -> lemma_eq_instr_apply_eval_args outs args (f v) oprs s1 s2
)
#restart-solver
let rec lemma_eq_instr_apply_eval_inouts
(outs inouts:list instr_out) (args:list instr_operand)
(f:instr_inouts_t outs inouts args) (oprs:instr_operands_t inouts args) (s1 s2:machine_state)
: Lemma
(requires state_eq_S true s1 s2)
(ensures
BS.instr_apply_eval_inouts outs inouts args f oprs s1 ==
BS.instr_apply_eval_inouts outs inouts args f oprs s2) | false | false | Vale.X64.Lemmas.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 1,
"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": 100,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val lemma_eq_instr_apply_eval_inouts
(outs inouts: list instr_out)
(args: list instr_operand)
(f: instr_inouts_t outs inouts args)
(oprs: instr_operands_t inouts args)
(s1 s2: machine_state)
: Lemma (requires state_eq_S true s1 s2)
(ensures
BS.instr_apply_eval_inouts outs inouts args f oprs s1 ==
BS.instr_apply_eval_inouts outs inouts args f oprs s2) | [
"recursion"
] | Vale.X64.Lemmas.lemma_eq_instr_apply_eval_inouts | {
"file_name": "vale/code/arch/x64/Vale.X64.Lemmas.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} |
outs: Prims.list Vale.X64.Instruction_s.instr_out ->
inouts: Prims.list Vale.X64.Instruction_s.instr_out ->
args: Prims.list Vale.X64.Instruction_s.instr_operand ->
f: Vale.X64.Instruction_s.instr_inouts_t outs inouts args ->
oprs: Vale.X64.Instruction_s.instr_operands_t inouts args ->
s1: Vale.X64.StateLemmas.machine_state ->
s2: Vale.X64.StateLemmas.machine_state
-> FStar.Pervasives.Lemma (requires Vale.X64.Lemmas.state_eq_S true s1 s2)
(ensures
Vale.X64.Machine_Semantics_s.instr_apply_eval_inouts outs inouts args f oprs s1 ==
Vale.X64.Machine_Semantics_s.instr_apply_eval_inouts outs inouts args f oprs s2) | {
"end_col": 5,
"end_line": 72,
"start_col": 2,
"start_line": 50
} |
FStar.Pervasives.Lemma | val lemma_merge_total (b0:codes) (s0:vale_state) (f0:fuel) (sM:vale_state) (fM:fuel) (sN:vale_state) : Lemma
(requires
Cons? b0 /\
eval_code (Cons?.hd b0) s0 f0 sM /\
eval_code (Block (Cons?.tl b0)) sM fM sN
)
(ensures eval_code (Block b0) s0 (compute_merge_total f0 fM) sN) | [
{
"abbrev": true,
"full_module": "Vale.X64.Memory",
"short_module": "ME"
},
{
"abbrev": false,
"full_module": "Vale.X64.Instruction_s",
"short_module": null
},
{
"abbrev": true,
"full_module": "Vale.Lib.Map16",
"short_module": "Map16"
},
{
"abbrev": true,
"full_module": "Vale.X64.Machine_Semantics_s",
"short_module": "BS"
},
{
"abbrev": false,
"full_module": "Vale.X64.Bytes_Code_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.StateLemmas",
"short_module": null
},
{
"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.HeapLemmas",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.HeapImpl",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Heap",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"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 lemma_merge_total (b0:codes) (s0:vale_state) (f0:fuel) (sM:vale_state) (fM:fuel) (sN:vale_state) =
let f = if f0 > fM then f0 else fM in
increase_fuel (codes_modifies_ghost b0) (Cons?.hd b0) (state_to_S s0) f0 (state_to_S sM) f;
increase_fuel (codes_modifies_ghost b0) (Block (Cons?.tl b0)) (state_to_S sM) fM (state_to_S sN) f | val lemma_merge_total (b0:codes) (s0:vale_state) (f0:fuel) (sM:vale_state) (fM:fuel) (sN:vale_state) : Lemma
(requires
Cons? b0 /\
eval_code (Cons?.hd b0) s0 f0 sM /\
eval_code (Block (Cons?.tl b0)) sM fM sN
)
(ensures eval_code (Block b0) s0 (compute_merge_total f0 fM) sN)
let lemma_merge_total
(b0: codes)
(s0: vale_state)
(f0: fuel)
(sM: vale_state)
(fM: fuel)
(sN: vale_state)
= | false | null | true | let f = if f0 > fM then f0 else fM in
increase_fuel (codes_modifies_ghost b0) (Cons?.hd b0) (state_to_S s0) f0 (state_to_S sM) f;
increase_fuel (codes_modifies_ghost b0) (Block (Cons?.tl b0)) (state_to_S sM) fM (state_to_S sN) f | {
"checked_file": "Vale.X64.Lemmas.fst.checked",
"dependencies": [
"Vale.X64.StateLemmas.fsti.checked",
"Vale.X64.State.fsti.checked",
"Vale.X64.Memory.fsti.checked",
"Vale.X64.Machine_Semantics_s.fst.checked",
"Vale.X64.Machine_s.fst.checked",
"Vale.X64.Instruction_s.fsti.checked",
"Vale.X64.Flags.fsti.checked",
"Vale.X64.Bytes_Code_s.fst.checked",
"prims.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.FunctionalExtensionality.fsti.checked"
],
"interface_file": true,
"source_file": "Vale.X64.Lemmas.fst"
} | [
"lemma"
] | [
"Vale.X64.Lemmas.codes",
"Vale.X64.State.vale_state",
"Vale.X64.Lemmas.fuel",
"Vale.X64.Lemmas.increase_fuel",
"Vale.X64.Lemmas.codes_modifies_ghost",
"Vale.X64.Machine_s.Block",
"Vale.X64.Bytes_Code_s.instruction_t",
"Vale.X64.Machine_Semantics_s.instr_annotation",
"Vale.X64.Bytes_Code_s.ocmp",
"Prims.__proj__Cons__item__tl",
"Vale.X64.Bytes_Code_s.code_t",
"Vale.X64.StateLemmas.state_to_S",
"Prims.unit",
"Prims.__proj__Cons__item__hd",
"Prims.nat",
"Prims.op_GreaterThan",
"Prims.bool"
] | [] | module Vale.X64.Lemmas
open FStar.Mul
open Vale.X64.Machine_s
open Vale.X64.State
open Vale.X64.StateLemmas
open Vale.X64.Instruction_s
open Vale.X64.Bytes_Code_s
module BS = Vale.X64.Machine_Semantics_s
module ME = Vale.X64.Memory
#reset-options "--initial_fuel 1 --max_fuel 1 --z3rlimit 100"
#restart-solver
let rec lemma_eq_instr_apply_eval_args
(outs:list instr_out) (args:list instr_operand)
(f:instr_args_t outs args) (oprs:instr_operands_t_args args) (s1 s2:machine_state)
: Lemma
(requires state_eq_S true s1 s2)
(ensures
BS.instr_apply_eval_args outs args f oprs s1 ==
BS.instr_apply_eval_args outs args f oprs s2)
=
let open BS in
lemma_heap_ignore_ghost_machine s1.BS.ms_heap s2.BS.ms_heap;
match args with
| [] -> ()
| i::args ->
(
let (v, oprs) : option (instr_val_t i) & instr_operands_t_args args =
match i with
| IOpEx i -> let oprs = coerce oprs in (instr_eval_operand_explicit i (fst oprs) s1, snd oprs)
| IOpIm i -> (instr_eval_operand_implicit i s1, coerce oprs)
in
let f:arrow (instr_val_t i) (instr_args_t outs args) = coerce f in
match v with
| None -> ()
| Some v -> lemma_eq_instr_apply_eval_args outs args (f v) oprs s1 s2
)
#restart-solver
let rec lemma_eq_instr_apply_eval_inouts
(outs inouts:list instr_out) (args:list instr_operand)
(f:instr_inouts_t outs inouts args) (oprs:instr_operands_t inouts args) (s1 s2:machine_state)
: Lemma
(requires state_eq_S true s1 s2)
(ensures
BS.instr_apply_eval_inouts outs inouts args f oprs s1 ==
BS.instr_apply_eval_inouts outs inouts args f oprs s2)
=
let open BS in
lemma_heap_ignore_ghost_machine s1.BS.ms_heap s2.BS.ms_heap;
match inouts with
| [] -> lemma_eq_instr_apply_eval_args outs args f oprs s1 s2
| (Out, i)::inouts ->
let oprs =
match i with
| IOpEx i -> snd #(instr_operand_t i) (coerce oprs)
| IOpIm i -> coerce oprs
in
lemma_eq_instr_apply_eval_inouts outs inouts args (coerce f) oprs s1 s2
| (InOut, i)::inouts ->
(
let (v, oprs) : option (instr_val_t i) & instr_operands_t inouts args =
match i with
| IOpEx i -> let oprs = coerce oprs in (instr_eval_operand_explicit i (fst oprs) s1, snd oprs)
| IOpIm i -> (instr_eval_operand_implicit i s1, coerce oprs)
in
let f:arrow (instr_val_t i) (instr_inouts_t outs inouts args) = coerce f in
match v with
| None -> ()
| Some v -> lemma_eq_instr_apply_eval_inouts outs inouts args (f v) oprs s1 s2
)
#restart-solver
#push-options "--z3rlimit_factor 2"
let rec lemma_eq_instr_write_outputs
(outs:list instr_out) (args:list instr_operand)
(vs:instr_ret_t outs) (oprs:instr_operands_t outs args) (s1_orig s1 s2_orig s2:machine_state)
: Lemma
(requires state_eq_S true s1_orig s2_orig /\ state_eq_S true s1 s2)
(ensures
state_eq_S true
(BS.instr_write_outputs outs args vs oprs s1_orig s1)
(BS.instr_write_outputs outs args vs oprs s2_orig s2))
=
let open BS in
use_machine_state_equal ();
lemma_heap_ignore_ghost_machine s1.BS.ms_heap s2.BS.ms_heap;
lemma_heap_ignore_ghost_machine s1_orig.BS.ms_heap s2_orig.BS.ms_heap;
allow_inversion tmaddr;
match outs with
| [] -> ()
| (_, i)::outs ->
(
let ((v:instr_val_t i), (vs:instr_ret_t outs)) =
match outs with
| [] -> (vs, ())
| _::_ -> let vs = coerce vs in (fst vs, snd vs)
in
match i with
| IOpEx i ->
let oprs = coerce oprs in
let s1 = instr_write_output_explicit i v (fst oprs) s1_orig s1 in
let s2 = instr_write_output_explicit i v (fst oprs) s2_orig s2 in
lemma_eq_instr_write_outputs outs args vs (snd oprs) s1_orig s1 s2_orig s2
| IOpIm i ->
let s1 = instr_write_output_implicit i v s1_orig s1 in
let s2 = instr_write_output_implicit i v s2_orig s2 in
allow_inversion operand64;
allow_inversion operand128;
lemma_eq_instr_write_outputs outs args vs (coerce oprs) s1_orig s1 s2_orig s2
)
#pop-options
#restart-solver
let eval_ins_eq_instr (inst:BS.ins) (s1 s2:machine_state) : Lemma
(requires Instr? inst /\ state_eq_S true s1 s2)
(ensures state_eq_S true (BS.machine_eval_ins inst s1) (BS.machine_eval_ins inst s2))
=
let open BS in
let Instr it oprs ann = inst in
let InstrTypeRecord #outs #args #havoc_flags' i = it in
lemma_eq_instr_apply_eval_inouts outs outs args (instr_eval i) oprs s1 s2;
let vs = instr_apply_eval outs args (instr_eval i) oprs s1 in
let hav s =
match havoc_flags' with
| HavocFlags -> {s with ms_flags = havoc_flags}
| PreserveFlags -> s
in
let s1' = hav s1 in
let s2' = hav s2 in
match vs with
| None -> ()
| Some vs -> lemma_eq_instr_write_outputs outs args vs oprs s1 s1' s2 s2'
let eval_code_eq_instr (inst:BS.ins) (f:fuel) (s1 s2:machine_state) : Lemma
(requires Instr? inst /\ state_eq_S true s1 s2)
(ensures state_eq_opt true (BS.machine_eval_code (Ins inst) f s1) (BS.machine_eval_code (Ins inst) f s2))
=
reveal_opaque (`%BS.machine_eval_code_ins) BS.machine_eval_code_ins;
eval_ins_eq_instr inst ({s1 with BS.ms_trace = []}) ({s2 with BS.ms_trace = []})
let eval_code_eq_dealloc (inst:BS.ins) (f:fuel) (s1 s2:machine_state) : Lemma
(requires Dealloc? inst /\ state_eq_S true s1 s2)
(ensures state_eq_opt true (BS.machine_eval_code (Ins inst) f s1) (BS.machine_eval_code (Ins inst) f s2))
=
reveal_opaque (`%BS.machine_eval_code_ins) BS.machine_eval_code_ins;
use_machine_state_equal ();
lemma_heap_ignore_ghost_machine s1.BS.ms_heap s2.BS.ms_heap;
allow_inversion tmaddr
let eval_code_eq_alloc (inst:BS.ins) (f:fuel) (s1 s2:machine_state) : Lemma
(requires Alloc? inst /\ state_eq_S true s1 s2)
(ensures state_eq_opt true (BS.machine_eval_code (Ins inst) f s1) (BS.machine_eval_code (Ins inst) f s2))
=
reveal_opaque (`%BS.machine_eval_code_ins) BS.machine_eval_code_ins;
use_machine_state_equal ();
lemma_heap_ignore_ghost_machine s1.BS.ms_heap s2.BS.ms_heap;
allow_inversion tmaddr
let eval_code_eq_push (inst:BS.ins) (f:fuel) (s1 s2:machine_state) : Lemma
(requires Push? inst /\ state_eq_S true s1 s2)
(ensures state_eq_opt true (BS.machine_eval_code (Ins inst) f s1) (BS.machine_eval_code (Ins inst) f s2))
=
reveal_opaque (`%BS.machine_eval_code_ins) BS.machine_eval_code_ins;
use_machine_state_equal ();
lemma_heap_ignore_ghost_machine s1.BS.ms_heap s2.BS.ms_heap;
allow_inversion tmaddr
let eval_code_eq_pop (inst:BS.ins) (f:fuel) (s1 s2:machine_state) : Lemma
(requires Pop? inst /\ state_eq_S true s1 s2)
(ensures state_eq_opt true (BS.machine_eval_code (Ins inst) f s1) (BS.machine_eval_code (Ins inst) f s2))
=
reveal_opaque (`%BS.machine_eval_code_ins) BS.machine_eval_code_ins;
use_machine_state_equal ();
lemma_heap_ignore_ghost_machine s1.BS.ms_heap s2.BS.ms_heap;
allow_inversion tmaddr
let eval_code_eq_ins (i:BS.ins) (f:fuel) (s1 s2:machine_state) : Lemma
(requires state_eq_S true s1 s2)
(ensures state_eq_opt true (BS.machine_eval_code (Ins i) f s1) (BS.machine_eval_code (Ins i) f s2))
=
match i with
| Instr _ _ _ -> eval_code_eq_instr i f s1 s2
| Dealloc _ -> eval_code_eq_dealloc i f s1 s2
| Alloc _ -> eval_code_eq_alloc i f s1 s2
| Push _ _ -> eval_code_eq_push i f s1 s2
| Pop _ _ -> eval_code_eq_pop i f s1 s2
#reset-options "--fuel 2 --z3rlimit 30"
let eval_ocmp_eq_core (g:bool) (cond:ocmp) (s:machine_state) : Lemma
(ensures (
let (s1, b1) = BS.machine_eval_ocmp s cond in
let (s2, b2) = BS.machine_eval_ocmp (core_state g s) cond in
state_eq_S g s1 s2 /\ b1 == b2
))
=
reveal_opaque (`%BS.valid_ocmp_opaque) BS.valid_ocmp_opaque;
reveal_opaque (`%BS.eval_ocmp_opaque) BS.eval_ocmp_opaque;
()
#restart-solver
let rec eval_code_eq_core (g:bool) (c:code) (f:fuel) (s:machine_state) : Lemma
(ensures state_eq_opt g (BS.machine_eval_code c f s) (BS.machine_eval_code c f (core_state g s)))
(decreases %[f; c])
=
match c with
| Ins i ->
reveal_opaque (`%BS.machine_eval_code_ins) BS.machine_eval_code_ins;
if g then eval_code_eq_ins i f s (core_state g s)
| Block cs -> eval_codes_eq_core g cs f s
| IfElse cond ct cf ->
eval_ocmp_eq_core g cond s;
let (s', _) = BS.machine_eval_ocmp s cond in
let (t', _) = BS.machine_eval_ocmp (core_state g s) cond in
eval_code_eq_core g ct f s';
eval_code_eq_core g ct f t';
eval_code_eq_core g cf f s';
eval_code_eq_core g cf f t';
()
| While cond body -> eval_while_eq_core g cond body f s
and eval_codes_eq_core (g:bool) (cs:codes) (f:fuel) (s:machine_state) : Lemma
(ensures state_eq_opt g (BS.machine_eval_codes cs f s) (BS.machine_eval_codes cs f (core_state g s)))
(decreases %[f; cs])
=
match cs with
| [] -> ()
| c'::cs' -> (
eval_code_eq_core g c' f s;
match (machine_eval_code c' f s, machine_eval_code c' f (core_state g s)) with
| (None, None) -> ()
| (Some s', Some t') -> eval_codes_eq_core g cs' f s'; eval_codes_eq_core g cs' f t'
)
and eval_while_eq_core (g:bool) (cond:ocmp) (body:code) (f:fuel) (s:machine_state) : Lemma
(ensures state_eq_opt g (BS.machine_eval_while cond body f s) (BS.machine_eval_while cond body f (core_state g s)))
(decreases %[f; body])
=
if f > 0 then (
eval_ocmp_eq_core g cond s;
let (s1, _) = BS.machine_eval_ocmp s cond in
let (t1, _) = BS.machine_eval_ocmp (core_state g s) cond in
eval_code_eq_core g body (f - 1) s1;
eval_code_eq_core g body (f - 1) t1;
match (BS.machine_eval_code body (f - 1) s1, BS.machine_eval_code body (f - 1) t1) with
| (None, None) -> ()
| (Some s2, Some t2) ->
eval_while_eq_core g cond body (f - 1) s2;
eval_while_eq_core g cond body (f - 1) t2;
()
)
let eval_code_eq_f (c:code) (f:fuel) (s1 s2:machine_state) : Lemma
(requires state_eq_S false s1 s2)
(ensures state_eq_opt false (BS.machine_eval_code c f s1) (BS.machine_eval_code c f s2))
[SMTPat (BS.machine_eval_code c f s1); SMTPat (BS.machine_eval_code c f s2)]
=
eval_code_eq_core false c f s1; eval_code_eq_core false c f s2
let eval_codes_eq_f (cs:codes) (f:fuel) (s1 s2:machine_state) : Lemma
(requires state_eq_S false s1 s2)
(ensures state_eq_opt false (BS.machine_eval_codes cs f s1) (BS.machine_eval_codes cs f s2))
[SMTPat (BS.machine_eval_codes cs f s1); SMTPat (BS.machine_eval_codes cs f s2)]
=
eval_codes_eq_core false cs f s1; eval_codes_eq_core false cs f s2
let eval_while_eq_f (cond:ocmp) (body:code) (f:fuel) (s1 s2:machine_state) : Lemma
(requires state_eq_S false s1 s2)
(ensures state_eq_opt false (BS.machine_eval_while cond body f s1) (BS.machine_eval_while cond body f s2))
[SMTPat (BS.machine_eval_while cond body f s1); SMTPat (BS.machine_eval_while cond body f s2)]
=
eval_while_eq_core false cond body f s1; eval_while_eq_core false cond body f s2
let eval_code_eq_t (c:code) (f:fuel) (s1 s2:machine_state) : Lemma
(requires state_eq_S true s1 s2)
(ensures state_eq_opt true (BS.machine_eval_code c f s1) (BS.machine_eval_code c f s2))
[SMTPat (BS.machine_eval_code c f s1); SMTPat (BS.machine_eval_code c f s2)]
=
eval_code_eq_core true c f s1; eval_code_eq_core true c f s2
let eval_codes_eq_t (cs:codes) (f:fuel) (s1 s2:machine_state) : Lemma
(requires state_eq_S true s1 s2)
(ensures state_eq_opt true (BS.machine_eval_codes cs f s1) (BS.machine_eval_codes cs f s2))
[SMTPat (BS.machine_eval_codes cs f s1); SMTPat (BS.machine_eval_codes cs f s2)]
=
eval_codes_eq_core true cs f s1; eval_codes_eq_core true cs f s2
let eval_while_eq_t (cond:ocmp) (body:code) (f:fuel) (s1 s2:machine_state) : Lemma
(requires state_eq_S true s1 s2)
(ensures state_eq_opt true (BS.machine_eval_while cond body f s1) (BS.machine_eval_while cond body f s2))
[SMTPat (BS.machine_eval_while cond body f s1); SMTPat (BS.machine_eval_while cond body f s2)]
=
eval_while_eq_core true cond body f s1; eval_while_eq_core true cond body f s2
let eval_code_ts (g:bool) (c:code) (s0:machine_state) (f0:fuel) (s1:machine_state) : Type0 =
state_eq_opt g (BS.machine_eval_code c f0 s0) (Some s1)
let rec increase_fuel (g:bool) (c:code) (s0:machine_state) (f0:fuel) (sN:machine_state) (fN:fuel) : Lemma
(requires eval_code_ts g c s0 f0 sN /\ f0 <= fN)
(ensures eval_code_ts g c s0 fN sN)
(decreases %[f0; c])
=
match c with
| Ins ins -> ()
| Block l -> increase_fuels g l s0 f0 sN fN
| IfElse cond t f ->
let (s0, b0) = BS.machine_eval_ocmp s0 cond in
if b0 then increase_fuel g t s0 f0 sN fN else increase_fuel g f s0 f0 sN fN
| While cond c ->
let (s1, b0) = BS.machine_eval_ocmp s0 cond in
if b0 then (
match BS.machine_eval_code c (f0 - 1) s1 with
| None -> ()
| Some s2 ->
increase_fuel g c s1 (f0 - 1) s2 (fN - 1);
if s2.BS.ms_ok then increase_fuel g (While cond c) s2 (f0 - 1) sN (fN - 1)
else ()
)
and increase_fuels (g:bool) (c:codes) (s0:machine_state) (f0:fuel) (sN:machine_state) (fN:fuel) : Lemma
(requires eval_code_ts g (Block c) s0 f0 sN /\ f0 <= fN)
(ensures eval_code_ts g (Block c) s0 fN sN)
(decreases %[f0; c])
=
match c with
| [] -> ()
| h::t ->
(
let Some s1 = BS.machine_eval_code h f0 s0 in
increase_fuel g h s0 f0 s1 fN;
increase_fuels g t s1 f0 sN fN
)
let lemma_cmp_eq s o1 o2 = reveal_opaque (`%BS.eval_ocmp_opaque) BS.eval_ocmp_opaque
let lemma_cmp_ne s o1 o2 = reveal_opaque (`%BS.eval_ocmp_opaque) BS.eval_ocmp_opaque
let lemma_cmp_le s o1 o2 = reveal_opaque (`%BS.eval_ocmp_opaque) BS.eval_ocmp_opaque
let lemma_cmp_ge s o1 o2 = reveal_opaque (`%BS.eval_ocmp_opaque) BS.eval_ocmp_opaque
let lemma_cmp_lt s o1 o2 = reveal_opaque (`%BS.eval_ocmp_opaque) BS.eval_ocmp_opaque
let lemma_cmp_gt s o1 o2 = reveal_opaque (`%BS.eval_ocmp_opaque) BS.eval_ocmp_opaque
let lemma_valid_cmp_eq s o1 o2 = ()
let lemma_valid_cmp_ne s o1 o2 = ()
let lemma_valid_cmp_le s o1 o2 = ()
let lemma_valid_cmp_ge s o1 o2 = ()
let lemma_valid_cmp_lt s o1 o2 = ()
let lemma_valid_cmp_gt s o1 o2 = ()
let compute_merge_total (f0:fuel) (fM:fuel) =
if f0 > fM then f0 else fM | false | false | Vale.X64.Lemmas.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": 30,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val lemma_merge_total (b0:codes) (s0:vale_state) (f0:fuel) (sM:vale_state) (fM:fuel) (sN:vale_state) : Lemma
(requires
Cons? b0 /\
eval_code (Cons?.hd b0) s0 f0 sM /\
eval_code (Block (Cons?.tl b0)) sM fM sN
)
(ensures eval_code (Block b0) s0 (compute_merge_total f0 fM) sN) | [] | Vale.X64.Lemmas.lemma_merge_total | {
"file_name": "vale/code/arch/x64/Vale.X64.Lemmas.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} |
b0: Vale.X64.Lemmas.codes ->
s0: Vale.X64.State.vale_state ->
f0: Vale.X64.Lemmas.fuel ->
sM: Vale.X64.State.vale_state ->
fM: Vale.X64.Lemmas.fuel ->
sN: Vale.X64.State.vale_state
-> FStar.Pervasives.Lemma
(requires
Cons? b0 /\ Vale.X64.Lemmas.eval_code (Cons?.hd b0) s0 f0 sM /\
Vale.X64.Lemmas.eval_code (Vale.X64.Machine_s.Block (Cons?.tl b0)) sM fM sN)
(ensures
Vale.X64.Lemmas.eval_code (Vale.X64.Machine_s.Block b0)
s0
(Vale.X64.Lemmas.compute_merge_total f0 fM)
sN) | {
"end_col": 100,
"end_line": 353,
"start_col": 102,
"start_line": 350
} |
FStar.Pervasives.Lemma | val eval_code_eq_pop (inst: BS.ins) (f: fuel) (s1 s2: machine_state)
: Lemma (requires Pop? inst /\ state_eq_S true s1 s2)
(ensures
state_eq_opt true
(BS.machine_eval_code (Ins inst) f s1)
(BS.machine_eval_code (Ins inst) f s2)) | [
{
"abbrev": true,
"full_module": "Vale.X64.Memory",
"short_module": "ME"
},
{
"abbrev": true,
"full_module": "Vale.X64.Machine_Semantics_s",
"short_module": "BS"
},
{
"abbrev": false,
"full_module": "Vale.X64.Bytes_Code_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Instruction_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.StateLemmas",
"short_module": null
},
{
"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": "FStar.Mul",
"short_module": null
},
{
"abbrev": true,
"full_module": "Vale.Lib.Map16",
"short_module": "Map16"
},
{
"abbrev": true,
"full_module": "Vale.X64.Machine_Semantics_s",
"short_module": "BS"
},
{
"abbrev": false,
"full_module": "Vale.X64.Bytes_Code_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.StateLemmas",
"short_module": null
},
{
"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.HeapLemmas",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.HeapImpl",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Heap",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"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 eval_code_eq_pop (inst:BS.ins) (f:fuel) (s1 s2:machine_state) : Lemma
(requires Pop? inst /\ state_eq_S true s1 s2)
(ensures state_eq_opt true (BS.machine_eval_code (Ins inst) f s1) (BS.machine_eval_code (Ins inst) f s2))
=
reveal_opaque (`%BS.machine_eval_code_ins) BS.machine_eval_code_ins;
use_machine_state_equal ();
lemma_heap_ignore_ghost_machine s1.BS.ms_heap s2.BS.ms_heap;
allow_inversion tmaddr | val eval_code_eq_pop (inst: BS.ins) (f: fuel) (s1 s2: machine_state)
: Lemma (requires Pop? inst /\ state_eq_S true s1 s2)
(ensures
state_eq_opt true
(BS.machine_eval_code (Ins inst) f s1)
(BS.machine_eval_code (Ins inst) f s2))
let eval_code_eq_pop (inst: BS.ins) (f: fuel) (s1 s2: machine_state)
: Lemma (requires Pop? inst /\ state_eq_S true s1 s2)
(ensures
state_eq_opt true
(BS.machine_eval_code (Ins inst) f s1)
(BS.machine_eval_code (Ins inst) f s2)) = | false | null | true | reveal_opaque (`%BS.machine_eval_code_ins) BS.machine_eval_code_ins;
use_machine_state_equal ();
lemma_heap_ignore_ghost_machine s1.BS.ms_heap s2.BS.ms_heap;
allow_inversion tmaddr | {
"checked_file": "Vale.X64.Lemmas.fst.checked",
"dependencies": [
"Vale.X64.StateLemmas.fsti.checked",
"Vale.X64.State.fsti.checked",
"Vale.X64.Memory.fsti.checked",
"Vale.X64.Machine_Semantics_s.fst.checked",
"Vale.X64.Machine_s.fst.checked",
"Vale.X64.Instruction_s.fsti.checked",
"Vale.X64.Flags.fsti.checked",
"Vale.X64.Bytes_Code_s.fst.checked",
"prims.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.FunctionalExtensionality.fsti.checked"
],
"interface_file": true,
"source_file": "Vale.X64.Lemmas.fst"
} | [
"lemma"
] | [
"Vale.X64.Machine_Semantics_s.ins",
"Vale.X64.Lemmas.fuel",
"Vale.X64.StateLemmas.machine_state",
"FStar.Pervasives.allow_inversion",
"Vale.X64.Machine_s.tmaddr",
"Prims.unit",
"Vale.Arch.HeapLemmas.lemma_heap_ignore_ghost_machine",
"Vale.X64.Machine_Semantics_s.__proj__Mkmachine_state__item__ms_heap",
"Vale.X64.StateLemmas.use_machine_state_equal",
"FStar.Pervasives.reveal_opaque",
"Vale.X64.Machine_Semantics_s.machine_state",
"FStar.Pervasives.Native.option",
"Vale.X64.Machine_Semantics_s.machine_eval_code_ins",
"Prims.l_and",
"Prims.b2t",
"Vale.X64.Bytes_Code_s.uu___is_Pop",
"Vale.X64.Machine_Semantics_s.instr_annotation",
"Vale.X64.Lemmas.state_eq_S",
"Prims.squash",
"Vale.X64.Lemmas.state_eq_opt",
"Vale.X64.Machine_Semantics_s.machine_eval_code",
"Vale.X64.Machine_s.Ins",
"Vale.X64.Bytes_Code_s.instruction_t",
"Vale.X64.Bytes_Code_s.ocmp",
"Prims.Nil",
"FStar.Pervasives.pattern"
] | [] | module Vale.X64.Lemmas
open FStar.Mul
open Vale.X64.Machine_s
open Vale.X64.State
open Vale.X64.StateLemmas
open Vale.X64.Instruction_s
open Vale.X64.Bytes_Code_s
module BS = Vale.X64.Machine_Semantics_s
module ME = Vale.X64.Memory
#reset-options "--initial_fuel 1 --max_fuel 1 --z3rlimit 100"
#restart-solver
let rec lemma_eq_instr_apply_eval_args
(outs:list instr_out) (args:list instr_operand)
(f:instr_args_t outs args) (oprs:instr_operands_t_args args) (s1 s2:machine_state)
: Lemma
(requires state_eq_S true s1 s2)
(ensures
BS.instr_apply_eval_args outs args f oprs s1 ==
BS.instr_apply_eval_args outs args f oprs s2)
=
let open BS in
lemma_heap_ignore_ghost_machine s1.BS.ms_heap s2.BS.ms_heap;
match args with
| [] -> ()
| i::args ->
(
let (v, oprs) : option (instr_val_t i) & instr_operands_t_args args =
match i with
| IOpEx i -> let oprs = coerce oprs in (instr_eval_operand_explicit i (fst oprs) s1, snd oprs)
| IOpIm i -> (instr_eval_operand_implicit i s1, coerce oprs)
in
let f:arrow (instr_val_t i) (instr_args_t outs args) = coerce f in
match v with
| None -> ()
| Some v -> lemma_eq_instr_apply_eval_args outs args (f v) oprs s1 s2
)
#restart-solver
let rec lemma_eq_instr_apply_eval_inouts
(outs inouts:list instr_out) (args:list instr_operand)
(f:instr_inouts_t outs inouts args) (oprs:instr_operands_t inouts args) (s1 s2:machine_state)
: Lemma
(requires state_eq_S true s1 s2)
(ensures
BS.instr_apply_eval_inouts outs inouts args f oprs s1 ==
BS.instr_apply_eval_inouts outs inouts args f oprs s2)
=
let open BS in
lemma_heap_ignore_ghost_machine s1.BS.ms_heap s2.BS.ms_heap;
match inouts with
| [] -> lemma_eq_instr_apply_eval_args outs args f oprs s1 s2
| (Out, i)::inouts ->
let oprs =
match i with
| IOpEx i -> snd #(instr_operand_t i) (coerce oprs)
| IOpIm i -> coerce oprs
in
lemma_eq_instr_apply_eval_inouts outs inouts args (coerce f) oprs s1 s2
| (InOut, i)::inouts ->
(
let (v, oprs) : option (instr_val_t i) & instr_operands_t inouts args =
match i with
| IOpEx i -> let oprs = coerce oprs in (instr_eval_operand_explicit i (fst oprs) s1, snd oprs)
| IOpIm i -> (instr_eval_operand_implicit i s1, coerce oprs)
in
let f:arrow (instr_val_t i) (instr_inouts_t outs inouts args) = coerce f in
match v with
| None -> ()
| Some v -> lemma_eq_instr_apply_eval_inouts outs inouts args (f v) oprs s1 s2
)
#restart-solver
#push-options "--z3rlimit_factor 2"
let rec lemma_eq_instr_write_outputs
(outs:list instr_out) (args:list instr_operand)
(vs:instr_ret_t outs) (oprs:instr_operands_t outs args) (s1_orig s1 s2_orig s2:machine_state)
: Lemma
(requires state_eq_S true s1_orig s2_orig /\ state_eq_S true s1 s2)
(ensures
state_eq_S true
(BS.instr_write_outputs outs args vs oprs s1_orig s1)
(BS.instr_write_outputs outs args vs oprs s2_orig s2))
=
let open BS in
use_machine_state_equal ();
lemma_heap_ignore_ghost_machine s1.BS.ms_heap s2.BS.ms_heap;
lemma_heap_ignore_ghost_machine s1_orig.BS.ms_heap s2_orig.BS.ms_heap;
allow_inversion tmaddr;
match outs with
| [] -> ()
| (_, i)::outs ->
(
let ((v:instr_val_t i), (vs:instr_ret_t outs)) =
match outs with
| [] -> (vs, ())
| _::_ -> let vs = coerce vs in (fst vs, snd vs)
in
match i with
| IOpEx i ->
let oprs = coerce oprs in
let s1 = instr_write_output_explicit i v (fst oprs) s1_orig s1 in
let s2 = instr_write_output_explicit i v (fst oprs) s2_orig s2 in
lemma_eq_instr_write_outputs outs args vs (snd oprs) s1_orig s1 s2_orig s2
| IOpIm i ->
let s1 = instr_write_output_implicit i v s1_orig s1 in
let s2 = instr_write_output_implicit i v s2_orig s2 in
allow_inversion operand64;
allow_inversion operand128;
lemma_eq_instr_write_outputs outs args vs (coerce oprs) s1_orig s1 s2_orig s2
)
#pop-options
#restart-solver
let eval_ins_eq_instr (inst:BS.ins) (s1 s2:machine_state) : Lemma
(requires Instr? inst /\ state_eq_S true s1 s2)
(ensures state_eq_S true (BS.machine_eval_ins inst s1) (BS.machine_eval_ins inst s2))
=
let open BS in
let Instr it oprs ann = inst in
let InstrTypeRecord #outs #args #havoc_flags' i = it in
lemma_eq_instr_apply_eval_inouts outs outs args (instr_eval i) oprs s1 s2;
let vs = instr_apply_eval outs args (instr_eval i) oprs s1 in
let hav s =
match havoc_flags' with
| HavocFlags -> {s with ms_flags = havoc_flags}
| PreserveFlags -> s
in
let s1' = hav s1 in
let s2' = hav s2 in
match vs with
| None -> ()
| Some vs -> lemma_eq_instr_write_outputs outs args vs oprs s1 s1' s2 s2'
let eval_code_eq_instr (inst:BS.ins) (f:fuel) (s1 s2:machine_state) : Lemma
(requires Instr? inst /\ state_eq_S true s1 s2)
(ensures state_eq_opt true (BS.machine_eval_code (Ins inst) f s1) (BS.machine_eval_code (Ins inst) f s2))
=
reveal_opaque (`%BS.machine_eval_code_ins) BS.machine_eval_code_ins;
eval_ins_eq_instr inst ({s1 with BS.ms_trace = []}) ({s2 with BS.ms_trace = []})
let eval_code_eq_dealloc (inst:BS.ins) (f:fuel) (s1 s2:machine_state) : Lemma
(requires Dealloc? inst /\ state_eq_S true s1 s2)
(ensures state_eq_opt true (BS.machine_eval_code (Ins inst) f s1) (BS.machine_eval_code (Ins inst) f s2))
=
reveal_opaque (`%BS.machine_eval_code_ins) BS.machine_eval_code_ins;
use_machine_state_equal ();
lemma_heap_ignore_ghost_machine s1.BS.ms_heap s2.BS.ms_heap;
allow_inversion tmaddr
let eval_code_eq_alloc (inst:BS.ins) (f:fuel) (s1 s2:machine_state) : Lemma
(requires Alloc? inst /\ state_eq_S true s1 s2)
(ensures state_eq_opt true (BS.machine_eval_code (Ins inst) f s1) (BS.machine_eval_code (Ins inst) f s2))
=
reveal_opaque (`%BS.machine_eval_code_ins) BS.machine_eval_code_ins;
use_machine_state_equal ();
lemma_heap_ignore_ghost_machine s1.BS.ms_heap s2.BS.ms_heap;
allow_inversion tmaddr
let eval_code_eq_push (inst:BS.ins) (f:fuel) (s1 s2:machine_state) : Lemma
(requires Push? inst /\ state_eq_S true s1 s2)
(ensures state_eq_opt true (BS.machine_eval_code (Ins inst) f s1) (BS.machine_eval_code (Ins inst) f s2))
=
reveal_opaque (`%BS.machine_eval_code_ins) BS.machine_eval_code_ins;
use_machine_state_equal ();
lemma_heap_ignore_ghost_machine s1.BS.ms_heap s2.BS.ms_heap;
allow_inversion tmaddr
let eval_code_eq_pop (inst:BS.ins) (f:fuel) (s1 s2:machine_state) : Lemma
(requires Pop? inst /\ state_eq_S true s1 s2)
(ensures state_eq_opt true (BS.machine_eval_code (Ins inst) f s1) (BS.machine_eval_code (Ins inst) f s2)) | false | false | Vale.X64.Lemmas.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 1,
"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": 100,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val eval_code_eq_pop (inst: BS.ins) (f: fuel) (s1 s2: machine_state)
: Lemma (requires Pop? inst /\ state_eq_S true s1 s2)
(ensures
state_eq_opt true
(BS.machine_eval_code (Ins inst) f s1)
(BS.machine_eval_code (Ins inst) f s2)) | [] | Vale.X64.Lemmas.eval_code_eq_pop | {
"file_name": "vale/code/arch/x64/Vale.X64.Lemmas.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} |
inst: Vale.X64.Machine_Semantics_s.ins ->
f: Vale.X64.Lemmas.fuel ->
s1: Vale.X64.StateLemmas.machine_state ->
s2: Vale.X64.StateLemmas.machine_state
-> FStar.Pervasives.Lemma (requires Pop? inst /\ Vale.X64.Lemmas.state_eq_S true s1 s2)
(ensures
Vale.X64.Lemmas.state_eq_opt true
(Vale.X64.Machine_Semantics_s.machine_eval_code (Vale.X64.Machine_s.Ins inst) f s1)
(Vale.X64.Machine_Semantics_s.machine_eval_code (Vale.X64.Machine_s.Ins inst) f s2)) | {
"end_col": 24,
"end_line": 177,
"start_col": 2,
"start_line": 174
} |
Prims.Ghost | val lemma_whileMerge_total (c:code) (s0:vale_state) (f0:fuel) (sM:vale_state) (fM:fuel) (sN:vale_state) : Ghost fuel
(requires While? c /\ (
let cond = While?.whileCond c in
sN.vs_ok /\
valid_ocmp cond sM /\
eval_ocmp sM cond /\
eval_while_inv c s0 f0 sM /\
eval_code (While?.whileBody c) ({sM with vs_flags = havoc_flags}) fM sN
))
(ensures (fun fN ->
eval_while_inv c s0 fN sN
)) | [
{
"abbrev": true,
"full_module": "Vale.X64.Memory",
"short_module": "ME"
},
{
"abbrev": false,
"full_module": "Vale.X64.Instruction_s",
"short_module": null
},
{
"abbrev": true,
"full_module": "Vale.Lib.Map16",
"short_module": "Map16"
},
{
"abbrev": true,
"full_module": "Vale.X64.Machine_Semantics_s",
"short_module": "BS"
},
{
"abbrev": false,
"full_module": "Vale.X64.Bytes_Code_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.StateLemmas",
"short_module": null
},
{
"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.HeapLemmas",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.HeapImpl",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Heap",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"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 lemma_whileMerge_total (c:code) (s0:vale_state) (f0:fuel) (sM:vale_state) (fM:fuel) (sN:vale_state) =
reveal_opaque (`%BS.valid_ocmp_opaque) BS.valid_ocmp_opaque;
reveal_opaque (`%BS.eval_ocmp_opaque) BS.eval_ocmp_opaque;
let fN:nat = f0 + fM + 1 in
let g = code_modifies_ghost c in
let fForall (f:nat) : Lemma
(requires Some? (BS.machine_eval_code c f (state_to_S sN)))
(ensures state_eq_opt g (BS.machine_eval_code c (f + fN) (state_to_S s0)) (BS.machine_eval_code c f (state_to_S sN)))
[SMTPat (BS.machine_eval_code c f (state_to_S sN))]
=
let Some sZ = BS.machine_eval_code c f (state_to_S sN) in
let fZ = if f > fM then f else fM in
let sM' = {sM with vs_flags = havoc_flags} in
increase_fuel (code_modifies_ghost c) (While?.whileBody c) (state_to_S sM') fM (state_to_S sN) fZ;
increase_fuel (code_modifies_ghost c) c (state_to_S sN) f sZ fZ;
assert (state_eq_opt g (BS.machine_eval_code c (fZ + 1) (state_to_S sM)) (Some sZ)); // via eval_code for While
assert (state_eq_opt g (BS.machine_eval_code c (fZ + 1) (state_to_S sM)) (BS.machine_eval_code c (fZ + 1 + f0) (state_to_S s0))); // via eval_while_inv, choosing f = fZ + 1
// Two assertions above prove (BS.machine_eval_code c (fZ + 1 + f0) (state_to_S s0)) equals (Some sZ)
// increase_fuel (code_modifies_ghost c) c s0 (fZ + 1 + f0) (state_of_S s0 sZ) (f + fN);
increase_fuel (code_modifies_ghost c) c (state_to_S s0) (fZ + 1 + f0) sZ (f + fN);
assert (state_eq_opt g (BS.machine_eval_code c (f + fN) (state_to_S s0)) (Some sZ));
()
in
fN | val lemma_whileMerge_total (c:code) (s0:vale_state) (f0:fuel) (sM:vale_state) (fM:fuel) (sN:vale_state) : Ghost fuel
(requires While? c /\ (
let cond = While?.whileCond c in
sN.vs_ok /\
valid_ocmp cond sM /\
eval_ocmp sM cond /\
eval_while_inv c s0 f0 sM /\
eval_code (While?.whileBody c) ({sM with vs_flags = havoc_flags}) fM sN
))
(ensures (fun fN ->
eval_while_inv c s0 fN sN
))
let lemma_whileMerge_total
(c: code)
(s0: vale_state)
(f0: fuel)
(sM: vale_state)
(fM: fuel)
(sN: vale_state)
= | false | null | false | reveal_opaque (`%BS.valid_ocmp_opaque) BS.valid_ocmp_opaque;
reveal_opaque (`%BS.eval_ocmp_opaque) BS.eval_ocmp_opaque;
let fN:nat = f0 + fM + 1 in
let g = code_modifies_ghost c in
let fForall (f: nat)
: Lemma (requires Some? (BS.machine_eval_code c f (state_to_S sN)))
(ensures
state_eq_opt g
(BS.machine_eval_code c (f + fN) (state_to_S s0))
(BS.machine_eval_code c f (state_to_S sN)))
[SMTPat (BS.machine_eval_code c f (state_to_S sN))] =
let Some sZ = BS.machine_eval_code c f (state_to_S sN) in
let fZ = if f > fM then f else fM in
let sM' = { sM with vs_flags = havoc_flags } in
increase_fuel (code_modifies_ghost c) (While?.whileBody c) (state_to_S sM') fM (state_to_S sN) fZ;
increase_fuel (code_modifies_ghost c) c (state_to_S sN) f sZ fZ;
assert (state_eq_opt g (BS.machine_eval_code c (fZ + 1) (state_to_S sM)) (Some sZ));
assert (state_eq_opt g
(BS.machine_eval_code c (fZ + 1) (state_to_S sM))
(BS.machine_eval_code c (fZ + 1 + f0) (state_to_S s0)));
increase_fuel (code_modifies_ghost c) c (state_to_S s0) (fZ + 1 + f0) sZ (f + fN);
assert (state_eq_opt g (BS.machine_eval_code c (f + fN) (state_to_S s0)) (Some sZ));
()
in
fN | {
"checked_file": "Vale.X64.Lemmas.fst.checked",
"dependencies": [
"Vale.X64.StateLemmas.fsti.checked",
"Vale.X64.State.fsti.checked",
"Vale.X64.Memory.fsti.checked",
"Vale.X64.Machine_Semantics_s.fst.checked",
"Vale.X64.Machine_s.fst.checked",
"Vale.X64.Instruction_s.fsti.checked",
"Vale.X64.Flags.fsti.checked",
"Vale.X64.Bytes_Code_s.fst.checked",
"prims.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.FunctionalExtensionality.fsti.checked"
],
"interface_file": true,
"source_file": "Vale.X64.Lemmas.fst"
} | [] | [
"Vale.X64.StateLemmas.code",
"Vale.X64.State.vale_state",
"Vale.X64.Lemmas.fuel",
"Prims.nat",
"Prims.unit",
"Prims.b2t",
"FStar.Pervasives.Native.uu___is_Some",
"Vale.X64.Machine_Semantics_s.machine_state",
"Vale.X64.Machine_Semantics_s.machine_eval_code",
"Vale.X64.StateLemmas.state_to_S",
"Prims.squash",
"Vale.X64.Lemmas.state_eq_opt",
"Prims.op_Addition",
"Prims.Cons",
"FStar.Pervasives.pattern",
"FStar.Pervasives.smt_pat",
"FStar.Pervasives.Native.option",
"Prims.Nil",
"Prims._assert",
"FStar.Pervasives.Native.Some",
"Vale.X64.Lemmas.increase_fuel",
"Vale.X64.Lemmas.code_modifies_ghost",
"Vale.X64.Machine_s.__proj__While__item__whileBody",
"Vale.X64.Bytes_Code_s.instruction_t",
"Vale.X64.Machine_Semantics_s.instr_annotation",
"Vale.X64.Bytes_Code_s.ocmp",
"Vale.X64.State.Mkvale_state",
"Vale.X64.State.__proj__Mkvale_state__item__vs_ok",
"Vale.X64.State.__proj__Mkvale_state__item__vs_regs",
"Vale.X64.Lemmas.havoc_flags",
"Vale.X64.State.__proj__Mkvale_state__item__vs_heap",
"Vale.X64.State.__proj__Mkvale_state__item__vs_stack",
"Vale.X64.State.__proj__Mkvale_state__item__vs_stackTaint",
"Prims.int",
"Prims.l_and",
"Prims.op_GreaterThanOrEqual",
"Prims.op_GreaterThan",
"Prims.bool",
"FStar.Pervasives.reveal_opaque",
"Vale.X64.Machine_Semantics_s.ocmp",
"Vale.X64.Machine_Semantics_s.eval_ocmp_opaque",
"Vale.X64.Machine_Semantics_s.valid_ocmp_opaque"
] | [] | module Vale.X64.Lemmas
open FStar.Mul
open Vale.X64.Machine_s
open Vale.X64.State
open Vale.X64.StateLemmas
open Vale.X64.Instruction_s
open Vale.X64.Bytes_Code_s
module BS = Vale.X64.Machine_Semantics_s
module ME = Vale.X64.Memory
#reset-options "--initial_fuel 1 --max_fuel 1 --z3rlimit 100"
#restart-solver
let rec lemma_eq_instr_apply_eval_args
(outs:list instr_out) (args:list instr_operand)
(f:instr_args_t outs args) (oprs:instr_operands_t_args args) (s1 s2:machine_state)
: Lemma
(requires state_eq_S true s1 s2)
(ensures
BS.instr_apply_eval_args outs args f oprs s1 ==
BS.instr_apply_eval_args outs args f oprs s2)
=
let open BS in
lemma_heap_ignore_ghost_machine s1.BS.ms_heap s2.BS.ms_heap;
match args with
| [] -> ()
| i::args ->
(
let (v, oprs) : option (instr_val_t i) & instr_operands_t_args args =
match i with
| IOpEx i -> let oprs = coerce oprs in (instr_eval_operand_explicit i (fst oprs) s1, snd oprs)
| IOpIm i -> (instr_eval_operand_implicit i s1, coerce oprs)
in
let f:arrow (instr_val_t i) (instr_args_t outs args) = coerce f in
match v with
| None -> ()
| Some v -> lemma_eq_instr_apply_eval_args outs args (f v) oprs s1 s2
)
#restart-solver
let rec lemma_eq_instr_apply_eval_inouts
(outs inouts:list instr_out) (args:list instr_operand)
(f:instr_inouts_t outs inouts args) (oprs:instr_operands_t inouts args) (s1 s2:machine_state)
: Lemma
(requires state_eq_S true s1 s2)
(ensures
BS.instr_apply_eval_inouts outs inouts args f oprs s1 ==
BS.instr_apply_eval_inouts outs inouts args f oprs s2)
=
let open BS in
lemma_heap_ignore_ghost_machine s1.BS.ms_heap s2.BS.ms_heap;
match inouts with
| [] -> lemma_eq_instr_apply_eval_args outs args f oprs s1 s2
| (Out, i)::inouts ->
let oprs =
match i with
| IOpEx i -> snd #(instr_operand_t i) (coerce oprs)
| IOpIm i -> coerce oprs
in
lemma_eq_instr_apply_eval_inouts outs inouts args (coerce f) oprs s1 s2
| (InOut, i)::inouts ->
(
let (v, oprs) : option (instr_val_t i) & instr_operands_t inouts args =
match i with
| IOpEx i -> let oprs = coerce oprs in (instr_eval_operand_explicit i (fst oprs) s1, snd oprs)
| IOpIm i -> (instr_eval_operand_implicit i s1, coerce oprs)
in
let f:arrow (instr_val_t i) (instr_inouts_t outs inouts args) = coerce f in
match v with
| None -> ()
| Some v -> lemma_eq_instr_apply_eval_inouts outs inouts args (f v) oprs s1 s2
)
#restart-solver
#push-options "--z3rlimit_factor 2"
let rec lemma_eq_instr_write_outputs
(outs:list instr_out) (args:list instr_operand)
(vs:instr_ret_t outs) (oprs:instr_operands_t outs args) (s1_orig s1 s2_orig s2:machine_state)
: Lemma
(requires state_eq_S true s1_orig s2_orig /\ state_eq_S true s1 s2)
(ensures
state_eq_S true
(BS.instr_write_outputs outs args vs oprs s1_orig s1)
(BS.instr_write_outputs outs args vs oprs s2_orig s2))
=
let open BS in
use_machine_state_equal ();
lemma_heap_ignore_ghost_machine s1.BS.ms_heap s2.BS.ms_heap;
lemma_heap_ignore_ghost_machine s1_orig.BS.ms_heap s2_orig.BS.ms_heap;
allow_inversion tmaddr;
match outs with
| [] -> ()
| (_, i)::outs ->
(
let ((v:instr_val_t i), (vs:instr_ret_t outs)) =
match outs with
| [] -> (vs, ())
| _::_ -> let vs = coerce vs in (fst vs, snd vs)
in
match i with
| IOpEx i ->
let oprs = coerce oprs in
let s1 = instr_write_output_explicit i v (fst oprs) s1_orig s1 in
let s2 = instr_write_output_explicit i v (fst oprs) s2_orig s2 in
lemma_eq_instr_write_outputs outs args vs (snd oprs) s1_orig s1 s2_orig s2
| IOpIm i ->
let s1 = instr_write_output_implicit i v s1_orig s1 in
let s2 = instr_write_output_implicit i v s2_orig s2 in
allow_inversion operand64;
allow_inversion operand128;
lemma_eq_instr_write_outputs outs args vs (coerce oprs) s1_orig s1 s2_orig s2
)
#pop-options
#restart-solver
let eval_ins_eq_instr (inst:BS.ins) (s1 s2:machine_state) : Lemma
(requires Instr? inst /\ state_eq_S true s1 s2)
(ensures state_eq_S true (BS.machine_eval_ins inst s1) (BS.machine_eval_ins inst s2))
=
let open BS in
let Instr it oprs ann = inst in
let InstrTypeRecord #outs #args #havoc_flags' i = it in
lemma_eq_instr_apply_eval_inouts outs outs args (instr_eval i) oprs s1 s2;
let vs = instr_apply_eval outs args (instr_eval i) oprs s1 in
let hav s =
match havoc_flags' with
| HavocFlags -> {s with ms_flags = havoc_flags}
| PreserveFlags -> s
in
let s1' = hav s1 in
let s2' = hav s2 in
match vs with
| None -> ()
| Some vs -> lemma_eq_instr_write_outputs outs args vs oprs s1 s1' s2 s2'
let eval_code_eq_instr (inst:BS.ins) (f:fuel) (s1 s2:machine_state) : Lemma
(requires Instr? inst /\ state_eq_S true s1 s2)
(ensures state_eq_opt true (BS.machine_eval_code (Ins inst) f s1) (BS.machine_eval_code (Ins inst) f s2))
=
reveal_opaque (`%BS.machine_eval_code_ins) BS.machine_eval_code_ins;
eval_ins_eq_instr inst ({s1 with BS.ms_trace = []}) ({s2 with BS.ms_trace = []})
let eval_code_eq_dealloc (inst:BS.ins) (f:fuel) (s1 s2:machine_state) : Lemma
(requires Dealloc? inst /\ state_eq_S true s1 s2)
(ensures state_eq_opt true (BS.machine_eval_code (Ins inst) f s1) (BS.machine_eval_code (Ins inst) f s2))
=
reveal_opaque (`%BS.machine_eval_code_ins) BS.machine_eval_code_ins;
use_machine_state_equal ();
lemma_heap_ignore_ghost_machine s1.BS.ms_heap s2.BS.ms_heap;
allow_inversion tmaddr
let eval_code_eq_alloc (inst:BS.ins) (f:fuel) (s1 s2:machine_state) : Lemma
(requires Alloc? inst /\ state_eq_S true s1 s2)
(ensures state_eq_opt true (BS.machine_eval_code (Ins inst) f s1) (BS.machine_eval_code (Ins inst) f s2))
=
reveal_opaque (`%BS.machine_eval_code_ins) BS.machine_eval_code_ins;
use_machine_state_equal ();
lemma_heap_ignore_ghost_machine s1.BS.ms_heap s2.BS.ms_heap;
allow_inversion tmaddr
let eval_code_eq_push (inst:BS.ins) (f:fuel) (s1 s2:machine_state) : Lemma
(requires Push? inst /\ state_eq_S true s1 s2)
(ensures state_eq_opt true (BS.machine_eval_code (Ins inst) f s1) (BS.machine_eval_code (Ins inst) f s2))
=
reveal_opaque (`%BS.machine_eval_code_ins) BS.machine_eval_code_ins;
use_machine_state_equal ();
lemma_heap_ignore_ghost_machine s1.BS.ms_heap s2.BS.ms_heap;
allow_inversion tmaddr
let eval_code_eq_pop (inst:BS.ins) (f:fuel) (s1 s2:machine_state) : Lemma
(requires Pop? inst /\ state_eq_S true s1 s2)
(ensures state_eq_opt true (BS.machine_eval_code (Ins inst) f s1) (BS.machine_eval_code (Ins inst) f s2))
=
reveal_opaque (`%BS.machine_eval_code_ins) BS.machine_eval_code_ins;
use_machine_state_equal ();
lemma_heap_ignore_ghost_machine s1.BS.ms_heap s2.BS.ms_heap;
allow_inversion tmaddr
let eval_code_eq_ins (i:BS.ins) (f:fuel) (s1 s2:machine_state) : Lemma
(requires state_eq_S true s1 s2)
(ensures state_eq_opt true (BS.machine_eval_code (Ins i) f s1) (BS.machine_eval_code (Ins i) f s2))
=
match i with
| Instr _ _ _ -> eval_code_eq_instr i f s1 s2
| Dealloc _ -> eval_code_eq_dealloc i f s1 s2
| Alloc _ -> eval_code_eq_alloc i f s1 s2
| Push _ _ -> eval_code_eq_push i f s1 s2
| Pop _ _ -> eval_code_eq_pop i f s1 s2
#reset-options "--fuel 2 --z3rlimit 30"
let eval_ocmp_eq_core (g:bool) (cond:ocmp) (s:machine_state) : Lemma
(ensures (
let (s1, b1) = BS.machine_eval_ocmp s cond in
let (s2, b2) = BS.machine_eval_ocmp (core_state g s) cond in
state_eq_S g s1 s2 /\ b1 == b2
))
=
reveal_opaque (`%BS.valid_ocmp_opaque) BS.valid_ocmp_opaque;
reveal_opaque (`%BS.eval_ocmp_opaque) BS.eval_ocmp_opaque;
()
#restart-solver
let rec eval_code_eq_core (g:bool) (c:code) (f:fuel) (s:machine_state) : Lemma
(ensures state_eq_opt g (BS.machine_eval_code c f s) (BS.machine_eval_code c f (core_state g s)))
(decreases %[f; c])
=
match c with
| Ins i ->
reveal_opaque (`%BS.machine_eval_code_ins) BS.machine_eval_code_ins;
if g then eval_code_eq_ins i f s (core_state g s)
| Block cs -> eval_codes_eq_core g cs f s
| IfElse cond ct cf ->
eval_ocmp_eq_core g cond s;
let (s', _) = BS.machine_eval_ocmp s cond in
let (t', _) = BS.machine_eval_ocmp (core_state g s) cond in
eval_code_eq_core g ct f s';
eval_code_eq_core g ct f t';
eval_code_eq_core g cf f s';
eval_code_eq_core g cf f t';
()
| While cond body -> eval_while_eq_core g cond body f s
and eval_codes_eq_core (g:bool) (cs:codes) (f:fuel) (s:machine_state) : Lemma
(ensures state_eq_opt g (BS.machine_eval_codes cs f s) (BS.machine_eval_codes cs f (core_state g s)))
(decreases %[f; cs])
=
match cs with
| [] -> ()
| c'::cs' -> (
eval_code_eq_core g c' f s;
match (machine_eval_code c' f s, machine_eval_code c' f (core_state g s)) with
| (None, None) -> ()
| (Some s', Some t') -> eval_codes_eq_core g cs' f s'; eval_codes_eq_core g cs' f t'
)
and eval_while_eq_core (g:bool) (cond:ocmp) (body:code) (f:fuel) (s:machine_state) : Lemma
(ensures state_eq_opt g (BS.machine_eval_while cond body f s) (BS.machine_eval_while cond body f (core_state g s)))
(decreases %[f; body])
=
if f > 0 then (
eval_ocmp_eq_core g cond s;
let (s1, _) = BS.machine_eval_ocmp s cond in
let (t1, _) = BS.machine_eval_ocmp (core_state g s) cond in
eval_code_eq_core g body (f - 1) s1;
eval_code_eq_core g body (f - 1) t1;
match (BS.machine_eval_code body (f - 1) s1, BS.machine_eval_code body (f - 1) t1) with
| (None, None) -> ()
| (Some s2, Some t2) ->
eval_while_eq_core g cond body (f - 1) s2;
eval_while_eq_core g cond body (f - 1) t2;
()
)
let eval_code_eq_f (c:code) (f:fuel) (s1 s2:machine_state) : Lemma
(requires state_eq_S false s1 s2)
(ensures state_eq_opt false (BS.machine_eval_code c f s1) (BS.machine_eval_code c f s2))
[SMTPat (BS.machine_eval_code c f s1); SMTPat (BS.machine_eval_code c f s2)]
=
eval_code_eq_core false c f s1; eval_code_eq_core false c f s2
let eval_codes_eq_f (cs:codes) (f:fuel) (s1 s2:machine_state) : Lemma
(requires state_eq_S false s1 s2)
(ensures state_eq_opt false (BS.machine_eval_codes cs f s1) (BS.machine_eval_codes cs f s2))
[SMTPat (BS.machine_eval_codes cs f s1); SMTPat (BS.machine_eval_codes cs f s2)]
=
eval_codes_eq_core false cs f s1; eval_codes_eq_core false cs f s2
let eval_while_eq_f (cond:ocmp) (body:code) (f:fuel) (s1 s2:machine_state) : Lemma
(requires state_eq_S false s1 s2)
(ensures state_eq_opt false (BS.machine_eval_while cond body f s1) (BS.machine_eval_while cond body f s2))
[SMTPat (BS.machine_eval_while cond body f s1); SMTPat (BS.machine_eval_while cond body f s2)]
=
eval_while_eq_core false cond body f s1; eval_while_eq_core false cond body f s2
let eval_code_eq_t (c:code) (f:fuel) (s1 s2:machine_state) : Lemma
(requires state_eq_S true s1 s2)
(ensures state_eq_opt true (BS.machine_eval_code c f s1) (BS.machine_eval_code c f s2))
[SMTPat (BS.machine_eval_code c f s1); SMTPat (BS.machine_eval_code c f s2)]
=
eval_code_eq_core true c f s1; eval_code_eq_core true c f s2
let eval_codes_eq_t (cs:codes) (f:fuel) (s1 s2:machine_state) : Lemma
(requires state_eq_S true s1 s2)
(ensures state_eq_opt true (BS.machine_eval_codes cs f s1) (BS.machine_eval_codes cs f s2))
[SMTPat (BS.machine_eval_codes cs f s1); SMTPat (BS.machine_eval_codes cs f s2)]
=
eval_codes_eq_core true cs f s1; eval_codes_eq_core true cs f s2
let eval_while_eq_t (cond:ocmp) (body:code) (f:fuel) (s1 s2:machine_state) : Lemma
(requires state_eq_S true s1 s2)
(ensures state_eq_opt true (BS.machine_eval_while cond body f s1) (BS.machine_eval_while cond body f s2))
[SMTPat (BS.machine_eval_while cond body f s1); SMTPat (BS.machine_eval_while cond body f s2)]
=
eval_while_eq_core true cond body f s1; eval_while_eq_core true cond body f s2
let eval_code_ts (g:bool) (c:code) (s0:machine_state) (f0:fuel) (s1:machine_state) : Type0 =
state_eq_opt g (BS.machine_eval_code c f0 s0) (Some s1)
let rec increase_fuel (g:bool) (c:code) (s0:machine_state) (f0:fuel) (sN:machine_state) (fN:fuel) : Lemma
(requires eval_code_ts g c s0 f0 sN /\ f0 <= fN)
(ensures eval_code_ts g c s0 fN sN)
(decreases %[f0; c])
=
match c with
| Ins ins -> ()
| Block l -> increase_fuels g l s0 f0 sN fN
| IfElse cond t f ->
let (s0, b0) = BS.machine_eval_ocmp s0 cond in
if b0 then increase_fuel g t s0 f0 sN fN else increase_fuel g f s0 f0 sN fN
| While cond c ->
let (s1, b0) = BS.machine_eval_ocmp s0 cond in
if b0 then (
match BS.machine_eval_code c (f0 - 1) s1 with
| None -> ()
| Some s2 ->
increase_fuel g c s1 (f0 - 1) s2 (fN - 1);
if s2.BS.ms_ok then increase_fuel g (While cond c) s2 (f0 - 1) sN (fN - 1)
else ()
)
and increase_fuels (g:bool) (c:codes) (s0:machine_state) (f0:fuel) (sN:machine_state) (fN:fuel) : Lemma
(requires eval_code_ts g (Block c) s0 f0 sN /\ f0 <= fN)
(ensures eval_code_ts g (Block c) s0 fN sN)
(decreases %[f0; c])
=
match c with
| [] -> ()
| h::t ->
(
let Some s1 = BS.machine_eval_code h f0 s0 in
increase_fuel g h s0 f0 s1 fN;
increase_fuels g t s1 f0 sN fN
)
let lemma_cmp_eq s o1 o2 = reveal_opaque (`%BS.eval_ocmp_opaque) BS.eval_ocmp_opaque
let lemma_cmp_ne s o1 o2 = reveal_opaque (`%BS.eval_ocmp_opaque) BS.eval_ocmp_opaque
let lemma_cmp_le s o1 o2 = reveal_opaque (`%BS.eval_ocmp_opaque) BS.eval_ocmp_opaque
let lemma_cmp_ge s o1 o2 = reveal_opaque (`%BS.eval_ocmp_opaque) BS.eval_ocmp_opaque
let lemma_cmp_lt s o1 o2 = reveal_opaque (`%BS.eval_ocmp_opaque) BS.eval_ocmp_opaque
let lemma_cmp_gt s o1 o2 = reveal_opaque (`%BS.eval_ocmp_opaque) BS.eval_ocmp_opaque
let lemma_valid_cmp_eq s o1 o2 = ()
let lemma_valid_cmp_ne s o1 o2 = ()
let lemma_valid_cmp_le s o1 o2 = ()
let lemma_valid_cmp_ge s o1 o2 = ()
let lemma_valid_cmp_lt s o1 o2 = ()
let lemma_valid_cmp_gt s o1 o2 = ()
let compute_merge_total (f0:fuel) (fM:fuel) =
if f0 > fM then f0 else fM
let lemma_merge_total (b0:codes) (s0:vale_state) (f0:fuel) (sM:vale_state) (fM:fuel) (sN:vale_state) =
let f = if f0 > fM then f0 else fM in
increase_fuel (codes_modifies_ghost b0) (Cons?.hd b0) (state_to_S s0) f0 (state_to_S sM) f;
increase_fuel (codes_modifies_ghost b0) (Block (Cons?.tl b0)) (state_to_S sM) fM (state_to_S sN) f
let lemma_empty_total (s0:vale_state) (bN:codes) =
(s0, 0)
let lemma_ifElse_total (ifb:ocmp) (ct:code) (cf:code) (s0:vale_state) =
(eval_ocmp s0 ifb, {s0 with vs_flags = havoc_flags}, s0, 0)
let lemma_havoc_flags : squash (Flags.to_fun havoc_flags == BS.havoc_flags) =
assert (FStar.FunctionalExtensionality.feq (Flags.to_fun havoc_flags) BS.havoc_flags)
let lemma_ifElseTrue_total (ifb:ocmp) (ct:code) (cf:code) (s0:vale_state) (f0:fuel) (sM:vale_state) =
reveal_opaque (`%BS.valid_ocmp_opaque) BS.valid_ocmp_opaque;
reveal_opaque (`%BS.eval_ocmp_opaque) BS.eval_ocmp_opaque
let lemma_ifElseFalse_total (ifb:ocmp) (ct:code) (cf:code) (s0:vale_state) (f0:fuel) (sM:vale_state) =
reveal_opaque (`%BS.valid_ocmp_opaque) BS.valid_ocmp_opaque;
reveal_opaque (`%BS.eval_ocmp_opaque) BS.eval_ocmp_opaque
let eval_while_inv_temp (c:code) (s0:vale_state) (fW:fuel) (sW:vale_state) : Type0 =
forall (f:nat).{:pattern BS.machine_eval_code c f (state_to_S sW)}
Some? (BS.machine_eval_code c f (state_to_S sW)) ==>
state_eq_opt (code_modifies_ghost c)
(BS.machine_eval_code c (f + fW) (state_to_S s0))
(BS.machine_eval_code c f (state_to_S sW))
let eval_while_inv (c:code) (s0:vale_state) (fW:fuel) (sW:vale_state) : Type0 =
eval_while_inv_temp c s0 fW sW
let lemma_while_total (b:ocmp) (c:code) (s0:vale_state) =
(s0, 0)
let lemma_whileTrue_total (b:ocmp) (c:code) (s0:vale_state) (sW:vale_state) (fW:fuel) =
({sW with vs_flags = havoc_flags}, fW)
let lemma_whileFalse_total (b:ocmp) (c:code) (s0:vale_state) (sW:vale_state) (fW:fuel) =
reveal_opaque (`%BS.valid_ocmp_opaque) BS.valid_ocmp_opaque;
reveal_opaque (`%BS.eval_ocmp_opaque) BS.eval_ocmp_opaque;
let f1 = fW + 1 in
let s1 = {sW with vs_flags = havoc_flags} in
assert (state_eq_opt (code_modifies_ghost c) (BS.machine_eval_code (While b c) f1 (state_to_S s0)) (BS.machine_eval_code (While b c) 1 (state_to_S sW)));
assert (eval_code (While b c) s0 f1 s1);
(s1, f1)
#restart-solver | false | false | Vale.X64.Lemmas.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": 30,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val lemma_whileMerge_total (c:code) (s0:vale_state) (f0:fuel) (sM:vale_state) (fM:fuel) (sN:vale_state) : Ghost fuel
(requires While? c /\ (
let cond = While?.whileCond c in
sN.vs_ok /\
valid_ocmp cond sM /\
eval_ocmp sM cond /\
eval_while_inv c s0 f0 sM /\
eval_code (While?.whileBody c) ({sM with vs_flags = havoc_flags}) fM sN
))
(ensures (fun fN ->
eval_while_inv c s0 fN sN
)) | [] | Vale.X64.Lemmas.lemma_whileMerge_total | {
"file_name": "vale/code/arch/x64/Vale.X64.Lemmas.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} |
c: Vale.X64.StateLemmas.code ->
s0: Vale.X64.State.vale_state ->
f0: Vale.X64.Lemmas.fuel ->
sM: Vale.X64.State.vale_state ->
fM: Vale.X64.Lemmas.fuel ->
sN: Vale.X64.State.vale_state
-> Prims.Ghost Vale.X64.Lemmas.fuel | {
"end_col": 4,
"end_line": 423,
"start_col": 2,
"start_line": 399
} |
FStar.Pervasives.Lemma | val lemma_eq_instr_write_outputs
(outs: list instr_out)
(args: list instr_operand)
(vs: instr_ret_t outs)
(oprs: instr_operands_t outs args)
(s1_orig s1 s2_orig s2: machine_state)
: Lemma (requires state_eq_S true s1_orig s2_orig /\ state_eq_S true s1 s2)
(ensures
state_eq_S true
(BS.instr_write_outputs outs args vs oprs s1_orig s1)
(BS.instr_write_outputs outs args vs oprs s2_orig s2)) | [
{
"abbrev": true,
"full_module": "Vale.X64.Memory",
"short_module": "ME"
},
{
"abbrev": true,
"full_module": "Vale.X64.Machine_Semantics_s",
"short_module": "BS"
},
{
"abbrev": false,
"full_module": "Vale.X64.Bytes_Code_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Instruction_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.StateLemmas",
"short_module": null
},
{
"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": "FStar.Mul",
"short_module": null
},
{
"abbrev": true,
"full_module": "Vale.Lib.Map16",
"short_module": "Map16"
},
{
"abbrev": true,
"full_module": "Vale.X64.Machine_Semantics_s",
"short_module": "BS"
},
{
"abbrev": false,
"full_module": "Vale.X64.Bytes_Code_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.StateLemmas",
"short_module": null
},
{
"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.HeapLemmas",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.HeapImpl",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Heap",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"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 rec lemma_eq_instr_write_outputs
(outs:list instr_out) (args:list instr_operand)
(vs:instr_ret_t outs) (oprs:instr_operands_t outs args) (s1_orig s1 s2_orig s2:machine_state)
: Lemma
(requires state_eq_S true s1_orig s2_orig /\ state_eq_S true s1 s2)
(ensures
state_eq_S true
(BS.instr_write_outputs outs args vs oprs s1_orig s1)
(BS.instr_write_outputs outs args vs oprs s2_orig s2))
=
let open BS in
use_machine_state_equal ();
lemma_heap_ignore_ghost_machine s1.BS.ms_heap s2.BS.ms_heap;
lemma_heap_ignore_ghost_machine s1_orig.BS.ms_heap s2_orig.BS.ms_heap;
allow_inversion tmaddr;
match outs with
| [] -> ()
| (_, i)::outs ->
(
let ((v:instr_val_t i), (vs:instr_ret_t outs)) =
match outs with
| [] -> (vs, ())
| _::_ -> let vs = coerce vs in (fst vs, snd vs)
in
match i with
| IOpEx i ->
let oprs = coerce oprs in
let s1 = instr_write_output_explicit i v (fst oprs) s1_orig s1 in
let s2 = instr_write_output_explicit i v (fst oprs) s2_orig s2 in
lemma_eq_instr_write_outputs outs args vs (snd oprs) s1_orig s1 s2_orig s2
| IOpIm i ->
let s1 = instr_write_output_implicit i v s1_orig s1 in
let s2 = instr_write_output_implicit i v s2_orig s2 in
allow_inversion operand64;
allow_inversion operand128;
lemma_eq_instr_write_outputs outs args vs (coerce oprs) s1_orig s1 s2_orig s2
) | val lemma_eq_instr_write_outputs
(outs: list instr_out)
(args: list instr_operand)
(vs: instr_ret_t outs)
(oprs: instr_operands_t outs args)
(s1_orig s1 s2_orig s2: machine_state)
: Lemma (requires state_eq_S true s1_orig s2_orig /\ state_eq_S true s1 s2)
(ensures
state_eq_S true
(BS.instr_write_outputs outs args vs oprs s1_orig s1)
(BS.instr_write_outputs outs args vs oprs s2_orig s2))
let rec lemma_eq_instr_write_outputs
(outs: list instr_out)
(args: list instr_operand)
(vs: instr_ret_t outs)
(oprs: instr_operands_t outs args)
(s1_orig s1 s2_orig s2: machine_state)
: Lemma (requires state_eq_S true s1_orig s2_orig /\ state_eq_S true s1 s2)
(ensures
state_eq_S true
(BS.instr_write_outputs outs args vs oprs s1_orig s1)
(BS.instr_write_outputs outs args vs oprs s2_orig s2)) = | false | null | true | let open BS in
use_machine_state_equal ();
lemma_heap_ignore_ghost_machine s1.BS.ms_heap s2.BS.ms_heap;
lemma_heap_ignore_ghost_machine s1_orig.BS.ms_heap s2_orig.BS.ms_heap;
allow_inversion tmaddr;
match outs with
| [] -> ()
| (_, i) :: outs ->
(let (v: instr_val_t i), (vs: instr_ret_t outs) =
match outs with
| [] -> (vs, ())
| _ :: _ ->
let vs = coerce vs in
(fst vs, snd vs)
in
match i with
| IOpEx i ->
let oprs = coerce oprs in
let s1 = instr_write_output_explicit i v (fst oprs) s1_orig s1 in
let s2 = instr_write_output_explicit i v (fst oprs) s2_orig s2 in
lemma_eq_instr_write_outputs outs args vs (snd oprs) s1_orig s1 s2_orig s2
| IOpIm i ->
let s1 = instr_write_output_implicit i v s1_orig s1 in
let s2 = instr_write_output_implicit i v s2_orig s2 in
allow_inversion operand64;
allow_inversion operand128;
lemma_eq_instr_write_outputs outs args vs (coerce oprs) s1_orig s1 s2_orig s2) | {
"checked_file": "Vale.X64.Lemmas.fst.checked",
"dependencies": [
"Vale.X64.StateLemmas.fsti.checked",
"Vale.X64.State.fsti.checked",
"Vale.X64.Memory.fsti.checked",
"Vale.X64.Machine_Semantics_s.fst.checked",
"Vale.X64.Machine_s.fst.checked",
"Vale.X64.Instruction_s.fsti.checked",
"Vale.X64.Flags.fsti.checked",
"Vale.X64.Bytes_Code_s.fst.checked",
"prims.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.FunctionalExtensionality.fsti.checked"
],
"interface_file": true,
"source_file": "Vale.X64.Lemmas.fst"
} | [
"lemma"
] | [
"Prims.list",
"Vale.X64.Instruction_s.instr_out",
"Vale.X64.Instruction_s.instr_operand",
"Vale.X64.Instruction_s.instr_ret_t",
"Vale.X64.Instruction_s.instr_operands_t",
"Vale.X64.StateLemmas.machine_state",
"Vale.X64.Instruction_s.instr_operand_inout",
"Vale.X64.Instruction_s.instr_val_t",
"Vale.X64.Instruction_s.instr_operand_explicit",
"Vale.X64.Lemmas.lemma_eq_instr_write_outputs",
"FStar.Pervasives.Native.snd",
"Vale.X64.Instruction_s.instr_operand_t",
"Vale.X64.Machine_Semantics_s.machine_state",
"Vale.X64.Machine_Semantics_s.instr_write_output_explicit",
"FStar.Pervasives.Native.fst",
"FStar.Pervasives.Native.tuple2",
"Vale.X64.Instruction_s.coerce",
"Vale.X64.Instruction_s.instr_operand_implicit",
"Prims.unit",
"FStar.Pervasives.allow_inversion",
"Vale.X64.Machine_s.operand128",
"Vale.X64.Machine_s.operand64",
"Vale.X64.Machine_Semantics_s.instr_write_output_implicit",
"FStar.Pervasives.Native.Mktuple2",
"Vale.X64.Machine_s.tmaddr",
"Vale.Arch.HeapLemmas.lemma_heap_ignore_ghost_machine",
"Vale.X64.Machine_Semantics_s.__proj__Mkmachine_state__item__ms_heap",
"Vale.X64.StateLemmas.use_machine_state_equal",
"Prims.l_and",
"Vale.X64.Lemmas.state_eq_S",
"Prims.squash",
"Vale.X64.Machine_Semantics_s.instr_write_outputs",
"Prims.Nil",
"FStar.Pervasives.pattern"
] | [] | module Vale.X64.Lemmas
open FStar.Mul
open Vale.X64.Machine_s
open Vale.X64.State
open Vale.X64.StateLemmas
open Vale.X64.Instruction_s
open Vale.X64.Bytes_Code_s
module BS = Vale.X64.Machine_Semantics_s
module ME = Vale.X64.Memory
#reset-options "--initial_fuel 1 --max_fuel 1 --z3rlimit 100"
#restart-solver
let rec lemma_eq_instr_apply_eval_args
(outs:list instr_out) (args:list instr_operand)
(f:instr_args_t outs args) (oprs:instr_operands_t_args args) (s1 s2:machine_state)
: Lemma
(requires state_eq_S true s1 s2)
(ensures
BS.instr_apply_eval_args outs args f oprs s1 ==
BS.instr_apply_eval_args outs args f oprs s2)
=
let open BS in
lemma_heap_ignore_ghost_machine s1.BS.ms_heap s2.BS.ms_heap;
match args with
| [] -> ()
| i::args ->
(
let (v, oprs) : option (instr_val_t i) & instr_operands_t_args args =
match i with
| IOpEx i -> let oprs = coerce oprs in (instr_eval_operand_explicit i (fst oprs) s1, snd oprs)
| IOpIm i -> (instr_eval_operand_implicit i s1, coerce oprs)
in
let f:arrow (instr_val_t i) (instr_args_t outs args) = coerce f in
match v with
| None -> ()
| Some v -> lemma_eq_instr_apply_eval_args outs args (f v) oprs s1 s2
)
#restart-solver
let rec lemma_eq_instr_apply_eval_inouts
(outs inouts:list instr_out) (args:list instr_operand)
(f:instr_inouts_t outs inouts args) (oprs:instr_operands_t inouts args) (s1 s2:machine_state)
: Lemma
(requires state_eq_S true s1 s2)
(ensures
BS.instr_apply_eval_inouts outs inouts args f oprs s1 ==
BS.instr_apply_eval_inouts outs inouts args f oprs s2)
=
let open BS in
lemma_heap_ignore_ghost_machine s1.BS.ms_heap s2.BS.ms_heap;
match inouts with
| [] -> lemma_eq_instr_apply_eval_args outs args f oprs s1 s2
| (Out, i)::inouts ->
let oprs =
match i with
| IOpEx i -> snd #(instr_operand_t i) (coerce oprs)
| IOpIm i -> coerce oprs
in
lemma_eq_instr_apply_eval_inouts outs inouts args (coerce f) oprs s1 s2
| (InOut, i)::inouts ->
(
let (v, oprs) : option (instr_val_t i) & instr_operands_t inouts args =
match i with
| IOpEx i -> let oprs = coerce oprs in (instr_eval_operand_explicit i (fst oprs) s1, snd oprs)
| IOpIm i -> (instr_eval_operand_implicit i s1, coerce oprs)
in
let f:arrow (instr_val_t i) (instr_inouts_t outs inouts args) = coerce f in
match v with
| None -> ()
| Some v -> lemma_eq_instr_apply_eval_inouts outs inouts args (f v) oprs s1 s2
)
#restart-solver
#push-options "--z3rlimit_factor 2"
let rec lemma_eq_instr_write_outputs
(outs:list instr_out) (args:list instr_operand)
(vs:instr_ret_t outs) (oprs:instr_operands_t outs args) (s1_orig s1 s2_orig s2:machine_state)
: Lemma
(requires state_eq_S true s1_orig s2_orig /\ state_eq_S true s1 s2)
(ensures
state_eq_S true
(BS.instr_write_outputs outs args vs oprs s1_orig s1)
(BS.instr_write_outputs outs args vs oprs s2_orig s2)) | false | false | Vale.X64.Lemmas.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 1,
"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": 100,
"z3rlimit_factor": 2,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val lemma_eq_instr_write_outputs
(outs: list instr_out)
(args: list instr_operand)
(vs: instr_ret_t outs)
(oprs: instr_operands_t outs args)
(s1_orig s1 s2_orig s2: machine_state)
: Lemma (requires state_eq_S true s1_orig s2_orig /\ state_eq_S true s1 s2)
(ensures
state_eq_S true
(BS.instr_write_outputs outs args vs oprs s1_orig s1)
(BS.instr_write_outputs outs args vs oprs s2_orig s2)) | [
"recursion"
] | Vale.X64.Lemmas.lemma_eq_instr_write_outputs | {
"file_name": "vale/code/arch/x64/Vale.X64.Lemmas.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} |
outs: Prims.list Vale.X64.Instruction_s.instr_out ->
args: Prims.list Vale.X64.Instruction_s.instr_operand ->
vs: Vale.X64.Instruction_s.instr_ret_t outs ->
oprs: Vale.X64.Instruction_s.instr_operands_t outs args ->
s1_orig: Vale.X64.StateLemmas.machine_state ->
s1: Vale.X64.StateLemmas.machine_state ->
s2_orig: Vale.X64.StateLemmas.machine_state ->
s2: Vale.X64.StateLemmas.machine_state
-> FStar.Pervasives.Lemma
(requires
Vale.X64.Lemmas.state_eq_S true s1_orig s2_orig /\ Vale.X64.Lemmas.state_eq_S true s1 s2)
(ensures
Vale.X64.Lemmas.state_eq_S true
(Vale.X64.Machine_Semantics_s.instr_write_outputs outs args vs oprs s1_orig s1)
(Vale.X64.Machine_Semantics_s.instr_write_outputs outs args vs oprs s2_orig s2)) | {
"end_col": 5,
"end_line": 112,
"start_col": 2,
"start_line": 86
} |
FStar.HyperStack.ST.Stack | val clear_matrix3:
a:FP.frodo_alg
-> sp_matrix:matrix_t params_nbar (params_n a)
-> ep_matrix:matrix_t params_nbar (params_n a)
-> epp_matrix:matrix_t params_nbar params_nbar
-> Stack unit
(requires fun h ->
live h sp_matrix /\ live h ep_matrix /\ live h epp_matrix /\
disjoint sp_matrix ep_matrix /\ disjoint sp_matrix epp_matrix /\
disjoint ep_matrix epp_matrix)
(ensures fun h0 _ h1 ->
modifies (loc sp_matrix |+| loc ep_matrix |+| loc epp_matrix) h0 h1) | [
{
"abbrev": true,
"full_module": "Hacl.Impl.Frodo.KEM.KeyGen",
"short_module": "KG"
},
{
"abbrev": true,
"full_module": "Spec.Matrix",
"short_module": "M"
},
{
"abbrev": true,
"full_module": "Spec.Frodo.KEM.Encaps",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "Spec.Frodo.Params",
"short_module": "FP"
},
{
"abbrev": true,
"full_module": "Lib.ByteSequence",
"short_module": "LB"
},
{
"abbrev": true,
"full_module": "Lib.Sequence",
"short_module": "LSeq"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": false,
"full_module": "Hacl.Frodo.Random",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl.Frodo.Sample",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl.Frodo.Pack",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl.Frodo.Encode",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl.Frodo.KEM",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl.Frodo.Params",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl.Matrix",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Buffer",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowStar.Buffer",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl.Frodo.KEM",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl.Frodo.KEM",
"short_module": null
},
{
"abbrev": 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 clear_matrix3 a sp_matrix ep_matrix epp_matrix =
clear_matrix sp_matrix;
clear_matrix ep_matrix;
clear_matrix epp_matrix | val clear_matrix3:
a:FP.frodo_alg
-> sp_matrix:matrix_t params_nbar (params_n a)
-> ep_matrix:matrix_t params_nbar (params_n a)
-> epp_matrix:matrix_t params_nbar params_nbar
-> Stack unit
(requires fun h ->
live h sp_matrix /\ live h ep_matrix /\ live h epp_matrix /\
disjoint sp_matrix ep_matrix /\ disjoint sp_matrix epp_matrix /\
disjoint ep_matrix epp_matrix)
(ensures fun h0 _ h1 ->
modifies (loc sp_matrix |+| loc ep_matrix |+| loc epp_matrix) h0 h1)
let clear_matrix3 a sp_matrix ep_matrix epp_matrix = | true | null | false | clear_matrix sp_matrix;
clear_matrix ep_matrix;
clear_matrix epp_matrix | {
"checked_file": "Hacl.Impl.Frodo.KEM.Encaps.fst.checked",
"dependencies": [
"Spec.Matrix.fst.checked",
"Spec.Frodo.Params.fst.checked",
"Spec.Frodo.KEM.Encaps.fst.checked",
"prims.fst.checked",
"LowStar.Buffer.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.ByteSequence.fsti.checked",
"Lib.Buffer.fsti.checked",
"Hacl.Impl.Matrix.fst.checked",
"Hacl.Impl.Frodo.Sample.fst.checked",
"Hacl.Impl.Frodo.Params.fst.checked",
"Hacl.Impl.Frodo.Pack.fst.checked",
"Hacl.Impl.Frodo.KEM.KeyGen.fst.checked",
"Hacl.Impl.Frodo.KEM.fst.checked",
"Hacl.Impl.Frodo.Encode.fst.checked",
"Hacl.Frodo.Random.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked"
],
"interface_file": false,
"source_file": "Hacl.Impl.Frodo.KEM.Encaps.fst"
} | [] | [
"Spec.Frodo.Params.frodo_alg",
"Hacl.Impl.Matrix.matrix_t",
"Hacl.Impl.Frodo.Params.params_nbar",
"Hacl.Impl.Frodo.Params.params_n",
"Hacl.Impl.Frodo.KEM.clear_matrix",
"Prims.unit"
] | [] | module Hacl.Impl.Frodo.KEM.Encaps
open FStar.HyperStack
open FStar.HyperStack.ST
open FStar.Mul
open LowStar.Buffer
open Lib.IntTypes
open Lib.Buffer
open Hacl.Impl.Matrix
open Hacl.Impl.Frodo.Params
open Hacl.Impl.Frodo.KEM
open Hacl.Impl.Frodo.Encode
open Hacl.Impl.Frodo.Pack
open Hacl.Impl.Frodo.Sample
open Hacl.Frodo.Random
module ST = FStar.HyperStack.ST
module LSeq = Lib.Sequence
module LB = Lib.ByteSequence
module FP = Spec.Frodo.Params
module S = Spec.Frodo.KEM.Encaps
module M = Spec.Matrix
module KG = Hacl.Impl.Frodo.KEM.KeyGen
#set-options "--z3rlimit 100 --fuel 0 --ifuel 0"
inline_for_extraction noextract
val frodo_mul_add_sa_plus_e:
a:FP.frodo_alg
-> gen_a:FP.frodo_gen_a{is_supported gen_a}
-> seed_a:lbytes bytes_seed_a
-> sp_matrix:matrix_t params_nbar (params_n a)
-> ep_matrix:matrix_t params_nbar (params_n a)
-> bp_matrix:matrix_t params_nbar (params_n a)
-> Stack unit
(requires fun h ->
live h seed_a /\ live h ep_matrix /\ live h sp_matrix /\ live h bp_matrix /\
disjoint bp_matrix seed_a /\ disjoint bp_matrix ep_matrix /\ disjoint bp_matrix sp_matrix)
(ensures fun h0 _ h1 -> modifies (loc bp_matrix) h0 h1 /\
as_matrix h1 bp_matrix ==
S.frodo_mul_add_sa_plus_e a gen_a (as_seq h0 seed_a) (as_matrix h0 sp_matrix) (as_matrix h0 ep_matrix))
let frodo_mul_add_sa_plus_e a gen_a seed_a sp_matrix ep_matrix bp_matrix =
push_frame ();
let a_matrix = matrix_create (params_n a) (params_n a) in
frodo_gen_matrix gen_a (params_n a) seed_a a_matrix;
matrix_mul sp_matrix a_matrix bp_matrix;
matrix_add bp_matrix ep_matrix;
pop_frame ()
inline_for_extraction noextract
val crypto_kem_enc_ct_pack_c1:
a:FP.frodo_alg
-> gen_a:FP.frodo_gen_a{is_supported gen_a}
-> seed_a:lbytes bytes_seed_a
-> sp_matrix:matrix_t params_nbar (params_n a)
-> ep_matrix:matrix_t params_nbar (params_n a)
-> c1:lbytes (ct1bytes_len a)
-> Stack unit
(requires fun h ->
live h seed_a /\ live h ep_matrix /\ live h sp_matrix /\ live h c1 /\
disjoint seed_a c1 /\ disjoint ep_matrix c1 /\ disjoint sp_matrix c1)
(ensures fun h0 _ h1 -> modifies (loc c1) h0 h1 /\
as_seq h1 c1 ==
S.crypto_kem_enc_ct_pack_c1 a gen_a (as_seq h0 seed_a) (as_matrix h0 sp_matrix) (as_matrix h0 ep_matrix))
let crypto_kem_enc_ct_pack_c1 a gen_a seed_a sp_matrix ep_matrix c1 =
push_frame ();
let bp_matrix = matrix_create params_nbar (params_n a) in
frodo_mul_add_sa_plus_e a gen_a seed_a sp_matrix ep_matrix bp_matrix;
frodo_pack (params_logq a) bp_matrix c1;
pop_frame ()
inline_for_extraction noextract
val frodo_mul_add_sb_plus_e:
a:FP.frodo_alg
-> b:lbytes (publicmatrixbytes_len a)
-> sp_matrix:matrix_t params_nbar (params_n a)
-> epp_matrix:matrix_t params_nbar params_nbar
-> v_matrix:matrix_t params_nbar params_nbar
-> Stack unit
(requires fun h ->
live h b /\ live h epp_matrix /\ live h v_matrix /\ live h sp_matrix /\
disjoint v_matrix b /\ disjoint v_matrix epp_matrix /\ disjoint v_matrix sp_matrix)
(ensures fun h0 _ h1 -> modifies (loc v_matrix) h0 h1 /\
as_matrix h1 v_matrix ==
S.frodo_mul_add_sb_plus_e a (as_seq h0 b) (as_matrix h0 sp_matrix) (as_matrix h0 epp_matrix))
let frodo_mul_add_sb_plus_e a b sp_matrix epp_matrix v_matrix =
push_frame ();
let b_matrix = matrix_create (params_n a) params_nbar in
frodo_unpack (params_n a) params_nbar (params_logq a) b b_matrix;
matrix_mul sp_matrix b_matrix v_matrix;
matrix_add v_matrix epp_matrix;
pop_frame ()
inline_for_extraction noextract
val frodo_mul_add_sb_plus_e_plus_mu:
a:FP.frodo_alg
-> mu:lbytes (bytes_mu a)
-> b:lbytes (publicmatrixbytes_len a)
-> sp_matrix:matrix_t params_nbar (params_n a)
-> epp_matrix:matrix_t params_nbar params_nbar
-> v_matrix:matrix_t params_nbar params_nbar
-> Stack unit
(requires fun h ->
live h b /\ live h mu /\ live h v_matrix /\
live h sp_matrix /\ live h epp_matrix /\
disjoint v_matrix b /\ disjoint v_matrix sp_matrix /\
disjoint v_matrix mu /\ disjoint v_matrix epp_matrix)
(ensures fun h0 _ h1 -> modifies (loc v_matrix) h0 h1 /\
as_matrix h1 v_matrix ==
S.frodo_mul_add_sb_plus_e_plus_mu a (as_seq h0 mu) (as_seq h0 b) (as_matrix h0 sp_matrix) (as_matrix h0 epp_matrix))
let frodo_mul_add_sb_plus_e_plus_mu a mu b sp_matrix epp_matrix v_matrix =
push_frame ();
frodo_mul_add_sb_plus_e a b sp_matrix epp_matrix v_matrix;
let mu_encode = matrix_create params_nbar params_nbar in
frodo_key_encode (params_logq a) (params_extracted_bits a) params_nbar mu mu_encode;
matrix_add v_matrix mu_encode;
clear_matrix mu_encode;
pop_frame ()
inline_for_extraction noextract
val crypto_kem_enc_ct_pack_c2:
a:FP.frodo_alg
-> mu:lbytes (bytes_mu a)
-> b:lbytes (publicmatrixbytes_len a)
-> sp_matrix:matrix_t params_nbar (params_n a)
-> epp_matrix:matrix_t params_nbar params_nbar
-> c2:lbytes (ct2bytes_len a)
-> Stack unit
(requires fun h ->
live h mu /\ live h b /\ live h sp_matrix /\
live h epp_matrix /\ live h c2 /\
disjoint mu c2 /\ disjoint b c2 /\
disjoint sp_matrix c2 /\ disjoint epp_matrix c2)
(ensures fun h0 _ h1 -> modifies (loc c2) h0 h1 /\
as_seq h1 c2 ==
S.crypto_kem_enc_ct_pack_c2 a (as_seq h0 mu) (as_seq h0 b) (as_matrix h0 sp_matrix) (as_matrix h0 epp_matrix))
#push-options "--z3rlimit 200"
let crypto_kem_enc_ct_pack_c2 a mu b sp_matrix epp_matrix c2 =
push_frame ();
let v_matrix = matrix_create params_nbar params_nbar in
frodo_mul_add_sb_plus_e_plus_mu a mu b sp_matrix epp_matrix v_matrix;
frodo_pack (params_logq a) v_matrix c2;
clear_matrix v_matrix;
pop_frame ()
#pop-options
inline_for_extraction noextract
val get_sp_ep_epp_matrices:
a:FP.frodo_alg
-> seed_se:lbytes (crypto_bytes a)
-> sp_matrix:matrix_t params_nbar (params_n a)
-> ep_matrix:matrix_t params_nbar (params_n a)
-> epp_matrix:matrix_t params_nbar params_nbar
-> Stack unit
(requires fun h ->
live h seed_se /\ live h sp_matrix /\
live h ep_matrix /\ live h epp_matrix /\
disjoint seed_se sp_matrix /\ disjoint seed_se ep_matrix /\
disjoint seed_se epp_matrix /\ disjoint sp_matrix ep_matrix /\
disjoint sp_matrix epp_matrix /\ disjoint ep_matrix epp_matrix)
(ensures fun h0 _ h1 -> modifies (loc sp_matrix |+| loc ep_matrix |+| loc epp_matrix) h0 h1 /\
(as_matrix h1 sp_matrix, as_matrix h1 ep_matrix, as_matrix h1 epp_matrix) ==
S.get_sp_ep_epp_matrices a (as_seq h0 seed_se))
let get_sp_ep_epp_matrices a seed_se sp_matrix ep_matrix epp_matrix =
push_frame ();
[@inline_let] let s_bytes_len = secretmatrixbytes_len a in
let r = create (2ul *! s_bytes_len +! 2ul *! params_nbar *! params_nbar) (u8 0) in
KG.frodo_shake_r a (u8 0x96) seed_se (2ul *! s_bytes_len +! 2ul *! params_nbar *! params_nbar) r;
frodo_sample_matrix a params_nbar (params_n a) (sub r 0ul s_bytes_len) sp_matrix;
frodo_sample_matrix a params_nbar (params_n a) (sub r s_bytes_len s_bytes_len) ep_matrix;
frodo_sample_matrix a params_nbar params_nbar (sub r (2ul *! s_bytes_len) (2ul *! params_nbar *! params_nbar)) epp_matrix;
pop_frame ()
inline_for_extraction noextract
val crypto_kem_enc_ct0:
a:FP.frodo_alg
-> gen_a:FP.frodo_gen_a{is_supported gen_a}
-> seed_a:lbytes bytes_seed_a
-> b:lbytes (publicmatrixbytes_len a)
-> mu:lbytes (bytes_mu a)
-> sp_matrix:matrix_t params_nbar (params_n a)
-> ep_matrix:matrix_t params_nbar (params_n a)
-> epp_matrix:matrix_t params_nbar params_nbar
-> ct:lbytes (crypto_ciphertextbytes a)
-> Stack unit
(requires fun h ->
live h seed_a /\ live h b /\ live h mu /\ live h ct /\
live h sp_matrix /\ live h ep_matrix /\ live h epp_matrix /\
disjoint ct seed_a /\ disjoint ct b /\ disjoint ct mu /\
disjoint ct sp_matrix /\ disjoint ct ep_matrix /\ disjoint ct epp_matrix)
(ensures fun h0 _ h1 -> modifies (loc ct) h0 h1 /\
(let c1:LB.lbytes (FP.ct1bytes_len a) = S.crypto_kem_enc_ct_pack_c1 a gen_a (as_seq h0 seed_a) (as_seq h0 sp_matrix) (as_seq h0 ep_matrix) in
let c2:LB.lbytes (FP.ct2bytes_len a) = S.crypto_kem_enc_ct_pack_c2 a (as_seq h0 mu) (as_seq h0 b) (as_seq h0 sp_matrix) (as_seq h0 epp_matrix) in
v (crypto_ciphertextbytes a) == FP.ct1bytes_len a + FP.ct2bytes_len a /\
as_seq h1 ct `Seq.equal` LSeq.concat #_ #(FP.ct1bytes_len a) #(FP.ct2bytes_len a) c1 c2))
let crypto_kem_enc_ct0 a gen_a seed_a b mu sp_matrix ep_matrix epp_matrix ct =
let c1 = sub ct 0ul (ct1bytes_len a) in
let c2 = sub ct (ct1bytes_len a) (ct2bytes_len a) in
let h0 = ST.get () in
crypto_kem_enc_ct_pack_c1 a gen_a seed_a sp_matrix ep_matrix c1;
let h1 = ST.get () in
crypto_kem_enc_ct_pack_c2 a mu b sp_matrix epp_matrix c2;
let h2 = ST.get () in
LSeq.eq_intro
(LSeq.sub (as_seq h2 ct) 0 (v (ct1bytes_len a)))
(LSeq.sub (as_seq h1 ct) 0 (v (ct1bytes_len a)));
LSeq.lemma_concat2
(v (ct1bytes_len a)) (LSeq.sub (as_seq h1 ct) 0 (v (ct1bytes_len a)))
(v (ct2bytes_len a)) (LSeq.sub (as_seq h2 ct) (v (ct1bytes_len a)) (v (ct2bytes_len a))) (as_seq h2 ct)
inline_for_extraction noextract
val clear_matrix3:
a:FP.frodo_alg
-> sp_matrix:matrix_t params_nbar (params_n a)
-> ep_matrix:matrix_t params_nbar (params_n a)
-> epp_matrix:matrix_t params_nbar params_nbar
-> Stack unit
(requires fun h ->
live h sp_matrix /\ live h ep_matrix /\ live h epp_matrix /\
disjoint sp_matrix ep_matrix /\ disjoint sp_matrix epp_matrix /\
disjoint ep_matrix epp_matrix)
(ensures fun h0 _ h1 ->
modifies (loc sp_matrix |+| loc ep_matrix |+| loc epp_matrix) h0 h1) | false | false | Hacl.Impl.Frodo.KEM.Encaps.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": 100,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val clear_matrix3:
a:FP.frodo_alg
-> sp_matrix:matrix_t params_nbar (params_n a)
-> ep_matrix:matrix_t params_nbar (params_n a)
-> epp_matrix:matrix_t params_nbar params_nbar
-> Stack unit
(requires fun h ->
live h sp_matrix /\ live h ep_matrix /\ live h epp_matrix /\
disjoint sp_matrix ep_matrix /\ disjoint sp_matrix epp_matrix /\
disjoint ep_matrix epp_matrix)
(ensures fun h0 _ h1 ->
modifies (loc sp_matrix |+| loc ep_matrix |+| loc epp_matrix) h0 h1) | [] | Hacl.Impl.Frodo.KEM.Encaps.clear_matrix3 | {
"file_name": "code/frodo/Hacl.Impl.Frodo.KEM.Encaps.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} |
a: Spec.Frodo.Params.frodo_alg ->
sp_matrix:
Hacl.Impl.Matrix.matrix_t Hacl.Impl.Frodo.Params.params_nbar
(Hacl.Impl.Frodo.Params.params_n a) ->
ep_matrix:
Hacl.Impl.Matrix.matrix_t Hacl.Impl.Frodo.Params.params_nbar
(Hacl.Impl.Frodo.Params.params_n a) ->
epp_matrix:
Hacl.Impl.Matrix.matrix_t Hacl.Impl.Frodo.Params.params_nbar
Hacl.Impl.Frodo.Params.params_nbar
-> FStar.HyperStack.ST.Stack Prims.unit | {
"end_col": 25,
"end_line": 245,
"start_col": 2,
"start_line": 243
} |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.