file_name
stringlengths
5
52
name
stringlengths
4
95
original_source_type
stringlengths
0
23k
source_type
stringlengths
9
23k
source_definition
stringlengths
9
57.9k
source
dict
source_range
dict
file_context
stringlengths
0
721k
dependencies
dict
opens_and_abbrevs
listlengths
2
94
vconfig
dict
interleaved
bool
1 class
verbose_type
stringlengths
1
7.42k
effect
stringclasses
118 values
effect_flags
sequencelengths
0
2
mutual_with
sequencelengths
0
11
ideal_premises
sequencelengths
0
236
proof_features
sequencelengths
0
1
is_simple_lemma
bool
2 classes
is_div
bool
2 classes
is_proof
bool
2 classes
is_simply_typed
bool
2 classes
is_type
bool
2 classes
partial_definition
stringlengths
5
3.99k
completed_definiton
stringlengths
1
1.63M
isa_cross_project_example
bool
1 class
Vale.AsLowStar.Test.fst
Vale.AsLowStar.Test.call_c_t
val call_c_t : Type0
let call_c_t = IX64.as_lowstar_sig_t_weak_stdcall c dom [] _ _ (W.mk_prediction c dom [] (v c IA.win))
{ "file_name": "vale/code/arch/x64/interop/Vale.AsLowStar.Test.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 102, "end_line": 42, "start_col": 0, "start_line": 42 }
module Vale.AsLowStar.Test open FStar.Mul open Vale.Interop.Base module ME = Vale.X64.Memory module IA = Vale.Interop.Assumptions module V = Vale.X64.Decls module IX64 = Vale.Interop.X64 module VSig = Vale.AsLowStar.ValeSig module LSig = Vale.AsLowStar.LowStarSig module W = Vale.AsLowStar.Wrapper module VS = Vale.X64.State module MS = Vale.X64.Machine_s (* A little utility to trigger normalization in types *) let as_t (#a:Type) (x:normal a) : a = x let as_normal_t (#a:Type) (x:a) : normal a = x //////////////////////////////////////////////////////////////////////////////// //First a little standalone, toy experiment [@__reduce__] let b64 = buf_t TUInt8 TUInt64 [@__reduce__] let ib64 = ibuf_t TUInt8 TUInt64 [@__reduce__] let t64_mod = TD_Buffer TUInt8 TUInt64 default_bq [@__reduce__] let t64_no_mod = TD_Buffer TUInt8 TUInt64 ({modified=false; strict_disjointness=false; taint=MS.Secret}) [@__reduce__] let t64_imm = TD_ImmBuffer TUInt8 TUInt64 ({modified=false; strict_disjointness=false; taint=MS.Secret}) [@__reduce__] let (dom : list td{List.length dom <= 20}) = let y = [t64_mod;t64_imm] in assert_norm (List.length y = 2); y assume val pre : VSig.vale_pre dom assume val post : VSig.vale_post dom assume val v: VSig.vale_sig_stdcall pre post assume val c: V.va_code
{ "checked_file": "/", "dependencies": [ "Vale.X64.State.fsti.checked", "Vale.X64.MemoryAdapters.fsti.checked", "Vale.X64.Memory.fsti.checked", "Vale.X64.Machine_s.fst.checked", "Vale.X64.Decls.fsti.checked", "Vale.X64.CPU_Features_s.fst.checked", "Vale.Test.X64.Vale_memcpy.fsti.checked", "Vale.Test.X64.Args.fsti.checked", "Vale.Lib.X64.Cpuidstdcall.fsti.checked", "Vale.Interop.X64.fsti.checked", "Vale.Interop.Base.fst.checked", "Vale.Interop.Assumptions.fst.checked", "Vale.AsLowStar.Wrapper.fsti.checked", "Vale.AsLowStar.ValeSig.fst.checked", "Vale.AsLowStar.MemoryHelpers.fsti.checked", "Vale.AsLowStar.LowStarSig.fst.checked", "prims.fst.checked", "LowStar.Monotonic.Buffer.fsti.checked", "LowStar.ImmutableBuffer.fst.checked", "LowStar.BufferView.Up.fsti.checked", "LowStar.BufferView.Down.fsti.checked", "LowStar.Buffer.fst.checked", "FStar.UInt8.fsti.checked", "FStar.UInt64.fsti.checked", "FStar.Tactics.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.List.fst.checked", "FStar.HyperStack.ST.fsti.checked" ], "interface_file": false, "source_file": "Vale.AsLowStar.Test.fst" }
[ { "abbrev": true, "full_module": "Vale.X64.Machine_s", "short_module": "MS" }, { "abbrev": true, "full_module": "Vale.X64.State", "short_module": "VS" }, { "abbrev": true, "full_module": "Vale.AsLowStar.Wrapper", "short_module": "W" }, { "abbrev": true, "full_module": "Vale.AsLowStar.LowStarSig", "short_module": "LSig" }, { "abbrev": true, "full_module": "Vale.AsLowStar.ValeSig", "short_module": "VSig" }, { "abbrev": true, "full_module": "Vale.Interop.X64", "short_module": "IX64" }, { "abbrev": true, "full_module": "Vale.X64.Decls", "short_module": "V" }, { "abbrev": true, "full_module": "Vale.Interop.Assumptions", "short_module": "IA" }, { "abbrev": true, "full_module": "Vale.X64.Memory", "short_module": "ME" }, { "abbrev": false, "full_module": "Vale.Interop.Base", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.AsLowStar", "short_module": null }, { "abbrev": false, "full_module": "Vale.AsLowStar", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 0, "max_fuel": 1, "max_ifuel": 1, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": true, "smtencoding_l_arith_repr": "native", "smtencoding_nl_arith_repr": "wrapped", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [ "smt.arith.nl=false", "smt.QI.EAGER_THRESHOLD=100", "smt.CASE_SPLIT=3" ], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
Type0
Prims.Tot
[ "total" ]
[]
[ "Vale.Interop.X64.as_lowstar_sig_t_weak_stdcall", "Vale.AsLowStar.Test.c", "Vale.AsLowStar.Test.dom", "Prims.Nil", "Vale.Interop.Base.arg", "Vale.AsLowStar.Wrapper.pre_rel_generic", "Vale.Interop.X64.max_stdcall", "Vale.Interop.X64.arg_reg_stdcall", "Vale.AsLowStar.Test.pre", "Vale.AsLowStar.Wrapper.post_rel_generic", "Vale.AsLowStar.Test.post", "Vale.AsLowStar.Wrapper.mk_prediction", "Vale.Interop.X64.regs_modified_stdcall", "Vale.Interop.X64.xmms_modified_stdcall", "Vale.AsLowStar.Test.v", "Vale.Interop.Assumptions.win" ]
[]
false
false
false
true
true
let call_c_t =
IX64.as_lowstar_sig_t_weak_stdcall c dom [] _ _ (W.mk_prediction c dom [] (v c IA.win))
false
Vale.AsLowStar.Test.fst
Vale.AsLowStar.Test.call_c
val call_c:call_c_t
val call_c:call_c_t
let call_c : call_c_t = IX64.wrap_weak_stdcall c dom (W.mk_prediction c dom [] (v c IA.win))
{ "file_name": "vale/code/arch/x64/interop/Vale.AsLowStar.Test.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 47, "end_line": 46, "start_col": 0, "start_line": 45 }
module Vale.AsLowStar.Test open FStar.Mul open Vale.Interop.Base module ME = Vale.X64.Memory module IA = Vale.Interop.Assumptions module V = Vale.X64.Decls module IX64 = Vale.Interop.X64 module VSig = Vale.AsLowStar.ValeSig module LSig = Vale.AsLowStar.LowStarSig module W = Vale.AsLowStar.Wrapper module VS = Vale.X64.State module MS = Vale.X64.Machine_s (* A little utility to trigger normalization in types *) let as_t (#a:Type) (x:normal a) : a = x let as_normal_t (#a:Type) (x:a) : normal a = x //////////////////////////////////////////////////////////////////////////////// //First a little standalone, toy experiment [@__reduce__] let b64 = buf_t TUInt8 TUInt64 [@__reduce__] let ib64 = ibuf_t TUInt8 TUInt64 [@__reduce__] let t64_mod = TD_Buffer TUInt8 TUInt64 default_bq [@__reduce__] let t64_no_mod = TD_Buffer TUInt8 TUInt64 ({modified=false; strict_disjointness=false; taint=MS.Secret}) [@__reduce__] let t64_imm = TD_ImmBuffer TUInt8 TUInt64 ({modified=false; strict_disjointness=false; taint=MS.Secret}) [@__reduce__] let (dom : list td{List.length dom <= 20}) = let y = [t64_mod;t64_imm] in assert_norm (List.length y = 2); y assume val pre : VSig.vale_pre dom assume val post : VSig.vale_post dom assume val v: VSig.vale_sig_stdcall pre post assume val c: V.va_code [@__reduce__] let call_c_t = IX64.as_lowstar_sig_t_weak_stdcall c dom [] _ _ (W.mk_prediction c dom [] (v c IA.win))
{ "checked_file": "/", "dependencies": [ "Vale.X64.State.fsti.checked", "Vale.X64.MemoryAdapters.fsti.checked", "Vale.X64.Memory.fsti.checked", "Vale.X64.Machine_s.fst.checked", "Vale.X64.Decls.fsti.checked", "Vale.X64.CPU_Features_s.fst.checked", "Vale.Test.X64.Vale_memcpy.fsti.checked", "Vale.Test.X64.Args.fsti.checked", "Vale.Lib.X64.Cpuidstdcall.fsti.checked", "Vale.Interop.X64.fsti.checked", "Vale.Interop.Base.fst.checked", "Vale.Interop.Assumptions.fst.checked", "Vale.AsLowStar.Wrapper.fsti.checked", "Vale.AsLowStar.ValeSig.fst.checked", "Vale.AsLowStar.MemoryHelpers.fsti.checked", "Vale.AsLowStar.LowStarSig.fst.checked", "prims.fst.checked", "LowStar.Monotonic.Buffer.fsti.checked", "LowStar.ImmutableBuffer.fst.checked", "LowStar.BufferView.Up.fsti.checked", "LowStar.BufferView.Down.fsti.checked", "LowStar.Buffer.fst.checked", "FStar.UInt8.fsti.checked", "FStar.UInt64.fsti.checked", "FStar.Tactics.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.List.fst.checked", "FStar.HyperStack.ST.fsti.checked" ], "interface_file": false, "source_file": "Vale.AsLowStar.Test.fst" }
[ { "abbrev": true, "full_module": "Vale.X64.Machine_s", "short_module": "MS" }, { "abbrev": true, "full_module": "Vale.X64.State", "short_module": "VS" }, { "abbrev": true, "full_module": "Vale.AsLowStar.Wrapper", "short_module": "W" }, { "abbrev": true, "full_module": "Vale.AsLowStar.LowStarSig", "short_module": "LSig" }, { "abbrev": true, "full_module": "Vale.AsLowStar.ValeSig", "short_module": "VSig" }, { "abbrev": true, "full_module": "Vale.Interop.X64", "short_module": "IX64" }, { "abbrev": true, "full_module": "Vale.X64.Decls", "short_module": "V" }, { "abbrev": true, "full_module": "Vale.Interop.Assumptions", "short_module": "IA" }, { "abbrev": true, "full_module": "Vale.X64.Memory", "short_module": "ME" }, { "abbrev": false, "full_module": "Vale.Interop.Base", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.AsLowStar", "short_module": null }, { "abbrev": false, "full_module": "Vale.AsLowStar", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 0, "max_fuel": 1, "max_ifuel": 1, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": true, "smtencoding_l_arith_repr": "native", "smtencoding_nl_arith_repr": "wrapped", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [ "smt.arith.nl=false", "smt.QI.EAGER_THRESHOLD=100", "smt.CASE_SPLIT=3" ], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
Vale.AsLowStar.Test.call_c_t
Prims.Tot
[ "total" ]
[]
[ "Vale.Interop.X64.wrap_weak_stdcall", "Vale.AsLowStar.Test.c", "Vale.AsLowStar.Test.dom", "Vale.AsLowStar.Wrapper.pre_rel_generic", "Vale.Interop.X64.max_stdcall", "Vale.Interop.X64.arg_reg_stdcall", "Prims.Nil", "Vale.Interop.Base.arg", "Vale.AsLowStar.Test.pre", "Vale.AsLowStar.Wrapper.post_rel_generic", "Vale.AsLowStar.Test.post", "Vale.AsLowStar.Wrapper.mk_prediction", "Vale.Interop.X64.regs_modified_stdcall", "Vale.Interop.X64.xmms_modified_stdcall", "Vale.AsLowStar.Test.v", "Vale.Interop.Assumptions.win" ]
[]
false
false
false
true
false
let call_c:call_c_t =
IX64.wrap_weak_stdcall c dom (W.mk_prediction c dom [] (v c IA.win))
false
Vale.AsLowStar.Test.fst
Vale.AsLowStar.Test.dom
val dom:dom: list td {List.length dom <= 20}
val dom:dom: list td {List.length dom <= 20}
let (dom : list td{List.length dom <= 20}) = let y = [t64_mod;t64_imm] in assert_norm (List.length y = 2); y
{ "file_name": "vale/code/arch/x64/interop/Vale.AsLowStar.Test.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 3, "end_line": 34, "start_col": 0, "start_line": 31 }
module Vale.AsLowStar.Test open FStar.Mul open Vale.Interop.Base module ME = Vale.X64.Memory module IA = Vale.Interop.Assumptions module V = Vale.X64.Decls module IX64 = Vale.Interop.X64 module VSig = Vale.AsLowStar.ValeSig module LSig = Vale.AsLowStar.LowStarSig module W = Vale.AsLowStar.Wrapper module VS = Vale.X64.State module MS = Vale.X64.Machine_s (* A little utility to trigger normalization in types *) let as_t (#a:Type) (x:normal a) : a = x let as_normal_t (#a:Type) (x:a) : normal a = x //////////////////////////////////////////////////////////////////////////////// //First a little standalone, toy experiment [@__reduce__] let b64 = buf_t TUInt8 TUInt64 [@__reduce__] let ib64 = ibuf_t TUInt8 TUInt64 [@__reduce__] let t64_mod = TD_Buffer TUInt8 TUInt64 default_bq [@__reduce__] let t64_no_mod = TD_Buffer TUInt8 TUInt64 ({modified=false; strict_disjointness=false; taint=MS.Secret}) [@__reduce__] let t64_imm = TD_ImmBuffer TUInt8 TUInt64 ({modified=false; strict_disjointness=false; taint=MS.Secret})
{ "checked_file": "/", "dependencies": [ "Vale.X64.State.fsti.checked", "Vale.X64.MemoryAdapters.fsti.checked", "Vale.X64.Memory.fsti.checked", "Vale.X64.Machine_s.fst.checked", "Vale.X64.Decls.fsti.checked", "Vale.X64.CPU_Features_s.fst.checked", "Vale.Test.X64.Vale_memcpy.fsti.checked", "Vale.Test.X64.Args.fsti.checked", "Vale.Lib.X64.Cpuidstdcall.fsti.checked", "Vale.Interop.X64.fsti.checked", "Vale.Interop.Base.fst.checked", "Vale.Interop.Assumptions.fst.checked", "Vale.AsLowStar.Wrapper.fsti.checked", "Vale.AsLowStar.ValeSig.fst.checked", "Vale.AsLowStar.MemoryHelpers.fsti.checked", "Vale.AsLowStar.LowStarSig.fst.checked", "prims.fst.checked", "LowStar.Monotonic.Buffer.fsti.checked", "LowStar.ImmutableBuffer.fst.checked", "LowStar.BufferView.Up.fsti.checked", "LowStar.BufferView.Down.fsti.checked", "LowStar.Buffer.fst.checked", "FStar.UInt8.fsti.checked", "FStar.UInt64.fsti.checked", "FStar.Tactics.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.List.fst.checked", "FStar.HyperStack.ST.fsti.checked" ], "interface_file": false, "source_file": "Vale.AsLowStar.Test.fst" }
[ { "abbrev": true, "full_module": "Vale.X64.Machine_s", "short_module": "MS" }, { "abbrev": true, "full_module": "Vale.X64.State", "short_module": "VS" }, { "abbrev": true, "full_module": "Vale.AsLowStar.Wrapper", "short_module": "W" }, { "abbrev": true, "full_module": "Vale.AsLowStar.LowStarSig", "short_module": "LSig" }, { "abbrev": true, "full_module": "Vale.AsLowStar.ValeSig", "short_module": "VSig" }, { "abbrev": true, "full_module": "Vale.Interop.X64", "short_module": "IX64" }, { "abbrev": true, "full_module": "Vale.X64.Decls", "short_module": "V" }, { "abbrev": true, "full_module": "Vale.Interop.Assumptions", "short_module": "IA" }, { "abbrev": true, "full_module": "Vale.X64.Memory", "short_module": "ME" }, { "abbrev": false, "full_module": "Vale.Interop.Base", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.AsLowStar", "short_module": null }, { "abbrev": false, "full_module": "Vale.AsLowStar", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 0, "max_fuel": 1, "max_ifuel": 1, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": true, "smtencoding_l_arith_repr": "native", "smtencoding_nl_arith_repr": "wrapped", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [ "smt.arith.nl=false", "smt.QI.EAGER_THRESHOLD=100", "smt.CASE_SPLIT=3" ], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
dom: Prims.list Vale.Interop.Base.td {FStar.List.Tot.Base.length dom <= 20}
Prims.Tot
[ "total" ]
[]
[ "Prims.unit", "FStar.Pervasives.assert_norm", "Prims.b2t", "Prims.op_Equality", "Prims.int", "FStar.List.Tot.Base.length", "Vale.Interop.Base.td", "Prims.list", "Prims.Cons", "Vale.AsLowStar.Test.t64_mod", "Vale.AsLowStar.Test.t64_imm", "Prims.Nil" ]
[]
false
false
false
false
false
let dom:dom: list td {List.length dom <= 20} =
let y = [t64_mod; t64_imm] in assert_norm (List.length y = 2); y
false
Hacl.Spec.Bignum.MontArithmetic.fst
Hacl.Spec.Bignum.MontArithmetic.bn_field_check_modulus
val bn_field_check_modulus: #t:limb_t -> #len:BN.bn_len t -> n:lbignum t len -> res:bool{res <==> bn_mont_ctx_pre n}
val bn_field_check_modulus: #t:limb_t -> #len:BN.bn_len t -> n:lbignum t len -> res:bool{res <==> bn_mont_ctx_pre n}
let bn_field_check_modulus #t #len n = let m = BM.bn_check_modulus n in BB.unsafe_bool_of_limb m
{ "file_name": "code/bignum/Hacl.Spec.Bignum.MontArithmetic.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 26, "end_line": 90, "start_col": 0, "start_line": 88 }
module Hacl.Spec.Bignum.MontArithmetic open FStar.Mul open Lib.IntTypes open Lib.Sequence open Hacl.Spec.Bignum.Definitions module M = Hacl.Spec.Montgomery.Lemmas module BM = Hacl.Spec.Bignum.Montgomery module BN = Hacl.Spec.Bignum module BB = Hacl.Spec.Bignum.Base module BL = Hacl.Spec.Bignum.Lib module BIL = Hacl.Spec.Bignum.ModInvLimb module E = Hacl.Spec.Exponentiation.Lemmas module ME = Hacl.Spec.Bignum.MontExponentiation module Euclid = FStar.Math.Euclid module BI = Hacl.Spec.Bignum.ModInv #set-options "--z3rlimit 50 --fuel 0 --ifuel 0" ////////////////////////////////////////// val mul_zero_lemma: n:pos{Euclid.is_prime n} -> x:int -> y:int -> Lemma (x * y % n == 0 <==> (x % n == 0 \/ y % n == 0)) let mul_zero_lemma n x y = assert (0 % n = 0); if x % n = 0 then Math.Lemmas.lemma_mod_mul_distr_l x y n else if y % n = 0 then Math.Lemmas.lemma_mod_mul_distr_r x y n else if x * y % n = 0 then Math.Fermat.mod_mult_congr n x 0 y else () val mul_nonzero_lemma: n:pos{Euclid.is_prime n} -> x:int -> y:int -> Lemma (requires x % n <> 0 /\ y % n <> 0) (ensures x * y % n <> 0) let mul_nonzero_lemma n x y = mul_zero_lemma n x y val from_mont_lemma_nonzero: pbits:pos -> rLen:pos -> n:pos -> mu:nat -> aM:nat -> Lemma (requires M.mont_pre pbits rLen n mu /\ 0 < aM /\ aM < n /\ Euclid.is_prime n) (ensures (let a = M.from_mont pbits rLen n mu aM in 0 < a /\ a < n)) let from_mont_lemma_nonzero pbits rLen n mu aM = let r = pow2 (pbits * rLen) in let d, _ = M.eea_pow2_odd (pbits * rLen) n in let a = M.from_mont pbits rLen n mu aM in M.from_mont_lemma pbits rLen n mu aM; assert (a == aM * d % n); assert (d <> 0); Math.Lemmas.small_mod aM n; assert (aM % n <> 0); let d1 = -d in assert (0 < d1 /\ d1 < n); Math.Lemmas.lemma_mod_sub_1 d1 n; assert ((-d1) % n == n - (d1 % n)); assert (d % n <> 0); mul_nonzero_lemma n aM d; assert (let a = M.from_mont pbits rLen n mu aM in 0 < a /\ a < n); // For some reason, this makes the proof instant. () /////////////////////////////////////////////// let bn_field_get_len #t k = k.len
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "Lib.Sequence.fsti.checked", "Lib.NatMod.fsti.checked", "Lib.IntTypes.fsti.checked", "Hacl.Spec.Montgomery.Lemmas.fst.checked", "Hacl.Spec.Exponentiation.Lemmas.fst.checked", "Hacl.Spec.Bignum.Montgomery.fsti.checked", "Hacl.Spec.Bignum.MontExponentiation.fst.checked", "Hacl.Spec.Bignum.ModInvLimb.fsti.checked", "Hacl.Spec.Bignum.ModInv.fst.checked", "Hacl.Spec.Bignum.Lib.fst.checked", "Hacl.Spec.Bignum.Definitions.fst.checked", "Hacl.Spec.Bignum.Base.fst.checked", "Hacl.Spec.Bignum.fsti.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.Math.Fermat.fsti.checked", "FStar.Math.Euclid.fsti.checked" ], "interface_file": true, "source_file": "Hacl.Spec.Bignum.MontArithmetic.fst" }
[ { "abbrev": true, "full_module": "Hacl.Spec.Bignum.ModInv", "short_module": "BI" }, { "abbrev": true, "full_module": "Hacl.Spec.Bignum.MontExponentiation", "short_module": "ME" }, { "abbrev": true, "full_module": "Hacl.Spec.Exponentiation.Lemmas", "short_module": "E" }, { "abbrev": true, "full_module": "Hacl.Spec.Bignum.ModInvLimb", "short_module": "BIL" }, { "abbrev": true, "full_module": "Hacl.Spec.Bignum.Lib", "short_module": "BL" }, { "abbrev": true, "full_module": "Hacl.Spec.Bignum.Base", "short_module": "BB" }, { "abbrev": true, "full_module": "Hacl.Spec.Bignum.Montgomery", "short_module": "BM" }, { "abbrev": true, "full_module": "Hacl.Spec.Bignum", "short_module": "BN" }, { "abbrev": true, "full_module": "Hacl.Spec.Montgomery.Lemmas", "short_module": "M" }, { "abbrev": true, "full_module": "FStar.Math.Euclid", "short_module": "Euclid" }, { "abbrev": false, "full_module": "Hacl.Spec.Bignum.Definitions", "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.Bignum", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.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 } ]
{ "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" }
false
n: Hacl.Spec.Bignum.Definitions.lbignum t len -> res: Prims.bool{res <==> Hacl.Spec.Bignum.MontArithmetic.bn_mont_ctx_pre n}
Prims.Tot
[ "total" ]
[]
[ "Hacl.Spec.Bignum.Definitions.limb_t", "Hacl.Spec.Bignum.bn_len", "Hacl.Spec.Bignum.Definitions.lbignum", "Hacl.Spec.Bignum.Base.unsafe_bool_of_limb", "Hacl.Spec.Bignum.Definitions.limb", "Prims.eq2", "Prims.int", "Lib.IntTypes.range", "Lib.IntTypes.v", "Lib.IntTypes.SEC", "Prims.op_AmpAmp", "Prims.op_Equality", "Prims.op_Modulus", "Hacl.Spec.Bignum.Definitions.bn_v", "Prims.op_LessThan", "Lib.IntTypes.ones", "Prims.bool", "Lib.IntTypes.zeros", "Hacl.Spec.Bignum.Montgomery.bn_check_modulus", "Prims.l_iff", "Prims.b2t", "Hacl.Spec.Bignum.MontArithmetic.bn_mont_ctx_pre" ]
[]
false
false
false
false
false
let bn_field_check_modulus #t #len n =
let m = BM.bn_check_modulus n in BB.unsafe_bool_of_limb m
false
Vale.AsLowStar.Test.fst
Vale.AsLowStar.Test.lowstar_Memcpy
val lowstar_Memcpy:lowstar_Memcpy_t
val lowstar_Memcpy:lowstar_Memcpy_t
let lowstar_Memcpy : lowstar_Memcpy_t = IX64.wrap_weak_stdcall code_Memcpy vm_dom (W.mk_prediction code_Memcpy vm_dom [] (vm_lemma code_Memcpy IA.win))
{ "file_name": "vale/code/arch/x64/interop/Vale.AsLowStar.Test.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 73, "end_line": 128, "start_col": 0, "start_line": 124 }
module Vale.AsLowStar.Test open FStar.Mul open Vale.Interop.Base module ME = Vale.X64.Memory module IA = Vale.Interop.Assumptions module V = Vale.X64.Decls module IX64 = Vale.Interop.X64 module VSig = Vale.AsLowStar.ValeSig module LSig = Vale.AsLowStar.LowStarSig module W = Vale.AsLowStar.Wrapper module VS = Vale.X64.State module MS = Vale.X64.Machine_s (* A little utility to trigger normalization in types *) let as_t (#a:Type) (x:normal a) : a = x let as_normal_t (#a:Type) (x:a) : normal a = x //////////////////////////////////////////////////////////////////////////////// //First a little standalone, toy experiment [@__reduce__] let b64 = buf_t TUInt8 TUInt64 [@__reduce__] let ib64 = ibuf_t TUInt8 TUInt64 [@__reduce__] let t64_mod = TD_Buffer TUInt8 TUInt64 default_bq [@__reduce__] let t64_no_mod = TD_Buffer TUInt8 TUInt64 ({modified=false; strict_disjointness=false; taint=MS.Secret}) [@__reduce__] let t64_imm = TD_ImmBuffer TUInt8 TUInt64 ({modified=false; strict_disjointness=false; taint=MS.Secret}) [@__reduce__] let (dom : list td{List.length dom <= 20}) = let y = [t64_mod;t64_imm] in assert_norm (List.length y = 2); y assume val pre : VSig.vale_pre dom assume val post : VSig.vale_post dom assume val v: VSig.vale_sig_stdcall pre post assume val c: V.va_code [@__reduce__] let call_c_t = IX64.as_lowstar_sig_t_weak_stdcall c dom [] _ _ (W.mk_prediction c dom [] (v c IA.win)) let call_c : call_c_t = IX64.wrap_weak_stdcall c dom (W.mk_prediction c dom [] (v c IA.win)) let call_c_normal_t : normal call_c_t = as_normal_t #call_c_t call_c //You can ask emacs to show you the type of call_c_normal_t ... //////////////////////////////////////////////////////////////////////////////// //Now memcpy module VM = Vale.Test.X64.Vale_memcpy [@__reduce__] let vm_dom = [t64_mod; t64_imm] open Vale.X64.MemoryAdapters (* Need to rearrange the order of arguments *) [@__reduce__] let vm_pre : VSig.vale_pre vm_dom = fun (c:V.va_code) (dst:b64) (src:ib64) (va_s0:V.va_state) -> VM.va_req_Memcpy c va_s0 IA.win (as_vale_buffer dst) (as_vale_immbuffer src) [@__reduce__] let vm_post : VSig.vale_post vm_dom = fun (c:V.va_code) (dst:b64) (src:ib64) (va_s0:V.va_state) (va_s1:V.va_state) (f:V.va_fuel) -> VM.va_ens_Memcpy c va_s0 IA.win (as_vale_buffer dst) (as_vale_immbuffer src) va_s1 f module VS = Vale.X64.State #reset-options "--print_effect_args --z3rlimit 200" (* The vale lemma doesn't quite suffice to prove the modifies clause expected of the interop layer *) [@__reduce__] let vm_lemma' (code:V.va_code) (_win:bool) (dst:b64) (src:ib64) (va_s0:V.va_state) : Ghost (V.va_state & V.va_fuel) (requires vm_pre code dst src va_s0) (ensures (fun (va_s1, f) -> V.eval_code code va_s0 f va_s1 /\ VSig.vale_calling_conventions_stdcall va_s0 va_s1 /\ vm_post code dst src va_s0 va_s1 f /\ ME.buffer_readable (VS.vs_get_vale_heap va_s1) (as_vale_immbuffer src) /\ ME.buffer_readable (VS.vs_get_vale_heap va_s1) (as_vale_buffer dst) /\ ME.buffer_writeable (as_vale_buffer dst) /\ ME.modifies (ME.loc_union (ME.loc_buffer (as_vale_buffer dst)) ME.loc_none) (VS.vs_get_vale_heap va_s0) (VS.vs_get_vale_heap va_s1) )) = let va_s1, f = VM.va_lemma_Memcpy code va_s0 IA.win (as_vale_buffer dst) (as_vale_immbuffer src) in Vale.AsLowStar.MemoryHelpers.buffer_writeable_reveal ME.TUInt8 ME.TUInt64 dst; (va_s1, f) (* Prove that vm_lemma' has the required type *) let vm_lemma = as_t #(VSig.vale_sig_stdcall vm_pre vm_post) vm_lemma' let code_Memcpy = VM.va_code_Memcpy IA.win (* Here's the type expected for the memcpy wrapper *) [@__reduce__] let lowstar_Memcpy_t = IX64.as_lowstar_sig_t_weak_stdcall code_Memcpy vm_dom [] _ _ (W.mk_prediction code_Memcpy vm_dom [] (vm_lemma code_Memcpy IA.win))
{ "checked_file": "/", "dependencies": [ "Vale.X64.State.fsti.checked", "Vale.X64.MemoryAdapters.fsti.checked", "Vale.X64.Memory.fsti.checked", "Vale.X64.Machine_s.fst.checked", "Vale.X64.Decls.fsti.checked", "Vale.X64.CPU_Features_s.fst.checked", "Vale.Test.X64.Vale_memcpy.fsti.checked", "Vale.Test.X64.Args.fsti.checked", "Vale.Lib.X64.Cpuidstdcall.fsti.checked", "Vale.Interop.X64.fsti.checked", "Vale.Interop.Base.fst.checked", "Vale.Interop.Assumptions.fst.checked", "Vale.AsLowStar.Wrapper.fsti.checked", "Vale.AsLowStar.ValeSig.fst.checked", "Vale.AsLowStar.MemoryHelpers.fsti.checked", "Vale.AsLowStar.LowStarSig.fst.checked", "prims.fst.checked", "LowStar.Monotonic.Buffer.fsti.checked", "LowStar.ImmutableBuffer.fst.checked", "LowStar.BufferView.Up.fsti.checked", "LowStar.BufferView.Down.fsti.checked", "LowStar.Buffer.fst.checked", "FStar.UInt8.fsti.checked", "FStar.UInt64.fsti.checked", "FStar.Tactics.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.List.fst.checked", "FStar.HyperStack.ST.fsti.checked" ], "interface_file": false, "source_file": "Vale.AsLowStar.Test.fst" }
[ { "abbrev": true, "full_module": "Vale.X64.State", "short_module": "VS" }, { "abbrev": false, "full_module": "Vale.X64.MemoryAdapters", "short_module": null }, { "abbrev": true, "full_module": "Vale.Test.X64.Vale_memcpy", "short_module": "VM" }, { "abbrev": true, "full_module": "Vale.X64.Machine_s", "short_module": "MS" }, { "abbrev": true, "full_module": "Vale.X64.State", "short_module": "VS" }, { "abbrev": true, "full_module": "Vale.AsLowStar.Wrapper", "short_module": "W" }, { "abbrev": true, "full_module": "Vale.AsLowStar.LowStarSig", "short_module": "LSig" }, { "abbrev": true, "full_module": "Vale.AsLowStar.ValeSig", "short_module": "VSig" }, { "abbrev": true, "full_module": "Vale.Interop.X64", "short_module": "IX64" }, { "abbrev": true, "full_module": "Vale.X64.Decls", "short_module": "V" }, { "abbrev": true, "full_module": "Vale.Interop.Assumptions", "short_module": "IA" }, { "abbrev": true, "full_module": "Vale.X64.Memory", "short_module": "ME" }, { "abbrev": false, "full_module": "Vale.Interop.Base", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.AsLowStar", "short_module": null }, { "abbrev": false, "full_module": "Vale.AsLowStar", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 0, "max_fuel": 1, "max_ifuel": 1, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": true, "smtencoding_l_arith_repr": "native", "smtencoding_nl_arith_repr": "wrapped", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [ "smt.arith.nl=false", "smt.QI.EAGER_THRESHOLD=100", "smt.CASE_SPLIT=3" ], "z3refresh": false, "z3rlimit": 200, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
Vale.AsLowStar.Test.lowstar_Memcpy_t
Prims.Tot
[ "total" ]
[]
[ "Vale.Interop.X64.wrap_weak_stdcall", "Vale.AsLowStar.Test.code_Memcpy", "Vale.AsLowStar.Test.vm_dom", "Vale.AsLowStar.Wrapper.pre_rel_generic", "Vale.Interop.X64.max_stdcall", "Vale.Interop.X64.arg_reg_stdcall", "Prims.Nil", "Vale.Interop.Base.arg", "Vale.AsLowStar.Test.vm_pre", "Vale.AsLowStar.Wrapper.post_rel_generic", "Vale.AsLowStar.Test.vm_post", "Vale.AsLowStar.Wrapper.mk_prediction", "Vale.Interop.X64.regs_modified_stdcall", "Vale.Interop.X64.xmms_modified_stdcall", "Vale.AsLowStar.Test.vm_lemma", "Vale.Interop.Assumptions.win" ]
[]
false
false
false
true
false
let lowstar_Memcpy:lowstar_Memcpy_t =
IX64.wrap_weak_stdcall code_Memcpy vm_dom (W.mk_prediction code_Memcpy vm_dom [] (vm_lemma code_Memcpy IA.win))
false
Vale.AsLowStar.Test.fst
Vale.AsLowStar.Test.aesni_dom
val aesni_dom:IX64.arity_ok_stdcall td
val aesni_dom:IX64.arity_ok_stdcall td
let aesni_dom : IX64.arity_ok_stdcall td = []
{ "file_name": "vale/code/arch/x64/interop/Vale.AsLowStar.Test.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 45, "end_line": 188, "start_col": 0, "start_line": 188 }
module Vale.AsLowStar.Test open FStar.Mul open Vale.Interop.Base module ME = Vale.X64.Memory module IA = Vale.Interop.Assumptions module V = Vale.X64.Decls module IX64 = Vale.Interop.X64 module VSig = Vale.AsLowStar.ValeSig module LSig = Vale.AsLowStar.LowStarSig module W = Vale.AsLowStar.Wrapper module VS = Vale.X64.State module MS = Vale.X64.Machine_s (* A little utility to trigger normalization in types *) let as_t (#a:Type) (x:normal a) : a = x let as_normal_t (#a:Type) (x:a) : normal a = x //////////////////////////////////////////////////////////////////////////////// //First a little standalone, toy experiment [@__reduce__] let b64 = buf_t TUInt8 TUInt64 [@__reduce__] let ib64 = ibuf_t TUInt8 TUInt64 [@__reduce__] let t64_mod = TD_Buffer TUInt8 TUInt64 default_bq [@__reduce__] let t64_no_mod = TD_Buffer TUInt8 TUInt64 ({modified=false; strict_disjointness=false; taint=MS.Secret}) [@__reduce__] let t64_imm = TD_ImmBuffer TUInt8 TUInt64 ({modified=false; strict_disjointness=false; taint=MS.Secret}) [@__reduce__] let (dom : list td{List.length dom <= 20}) = let y = [t64_mod;t64_imm] in assert_norm (List.length y = 2); y assume val pre : VSig.vale_pre dom assume val post : VSig.vale_post dom assume val v: VSig.vale_sig_stdcall pre post assume val c: V.va_code [@__reduce__] let call_c_t = IX64.as_lowstar_sig_t_weak_stdcall c dom [] _ _ (W.mk_prediction c dom [] (v c IA.win)) let call_c : call_c_t = IX64.wrap_weak_stdcall c dom (W.mk_prediction c dom [] (v c IA.win)) let call_c_normal_t : normal call_c_t = as_normal_t #call_c_t call_c //You can ask emacs to show you the type of call_c_normal_t ... //////////////////////////////////////////////////////////////////////////////// //Now memcpy module VM = Vale.Test.X64.Vale_memcpy [@__reduce__] let vm_dom = [t64_mod; t64_imm] open Vale.X64.MemoryAdapters (* Need to rearrange the order of arguments *) [@__reduce__] let vm_pre : VSig.vale_pre vm_dom = fun (c:V.va_code) (dst:b64) (src:ib64) (va_s0:V.va_state) -> VM.va_req_Memcpy c va_s0 IA.win (as_vale_buffer dst) (as_vale_immbuffer src) [@__reduce__] let vm_post : VSig.vale_post vm_dom = fun (c:V.va_code) (dst:b64) (src:ib64) (va_s0:V.va_state) (va_s1:V.va_state) (f:V.va_fuel) -> VM.va_ens_Memcpy c va_s0 IA.win (as_vale_buffer dst) (as_vale_immbuffer src) va_s1 f module VS = Vale.X64.State #reset-options "--print_effect_args --z3rlimit 200" (* The vale lemma doesn't quite suffice to prove the modifies clause expected of the interop layer *) [@__reduce__] let vm_lemma' (code:V.va_code) (_win:bool) (dst:b64) (src:ib64) (va_s0:V.va_state) : Ghost (V.va_state & V.va_fuel) (requires vm_pre code dst src va_s0) (ensures (fun (va_s1, f) -> V.eval_code code va_s0 f va_s1 /\ VSig.vale_calling_conventions_stdcall va_s0 va_s1 /\ vm_post code dst src va_s0 va_s1 f /\ ME.buffer_readable (VS.vs_get_vale_heap va_s1) (as_vale_immbuffer src) /\ ME.buffer_readable (VS.vs_get_vale_heap va_s1) (as_vale_buffer dst) /\ ME.buffer_writeable (as_vale_buffer dst) /\ ME.modifies (ME.loc_union (ME.loc_buffer (as_vale_buffer dst)) ME.loc_none) (VS.vs_get_vale_heap va_s0) (VS.vs_get_vale_heap va_s1) )) = let va_s1, f = VM.va_lemma_Memcpy code va_s0 IA.win (as_vale_buffer dst) (as_vale_immbuffer src) in Vale.AsLowStar.MemoryHelpers.buffer_writeable_reveal ME.TUInt8 ME.TUInt64 dst; (va_s1, f) (* Prove that vm_lemma' has the required type *) let vm_lemma = as_t #(VSig.vale_sig_stdcall vm_pre vm_post) vm_lemma' let code_Memcpy = VM.va_code_Memcpy IA.win (* Here's the type expected for the memcpy wrapper *) [@__reduce__] let lowstar_Memcpy_t = IX64.as_lowstar_sig_t_weak_stdcall code_Memcpy vm_dom [] _ _ (W.mk_prediction code_Memcpy vm_dom [] (vm_lemma code_Memcpy IA.win)) (* And here's the memcpy wrapper itself *) let lowstar_Memcpy : lowstar_Memcpy_t = IX64.wrap_weak_stdcall code_Memcpy vm_dom (W.mk_prediction code_Memcpy vm_dom [] (vm_lemma code_Memcpy IA.win)) let lowstar_Memcpy_normal_t //: normal lowstar_Memcpy_t = as_normal_t #lowstar_Memcpy_t lowstar_Memcpy module B = LowStar.Buffer module IB = LowStar.ImmutableBuffer module MB = LowStar.Monotonic.Buffer open FStar.HyperStack.ST module M = Vale.X64.Memory let test (x:b64) = assert (V.buffer_length (as_vale_buffer x) == (B.length x * view_n TUInt8) / view_n TUInt64); assert (V.buffer_length (as_vale_buffer x) == B.length x / 8) let itest (x:ib64) = assert (V.buffer_length (as_vale_immbuffer x) == (B.length x * view_n TUInt8) / view_n TUInt64); assert (V.buffer_length (as_vale_immbuffer x) == B.length x / 8) module T = FStar.Tactics #reset-options "--using_facts_from '* -FStar.Tactics -FStar.Reflection'" module LBV = LowStar.BufferView.Up module DV = LowStar.BufferView.Down #push-options "--ext compat:normalizer_memo_ignore_cfg" let memcpy_Test (dst:B.buffer UInt8.t{B.length dst % 8 == 0}) (src:IB.ibuffer UInt8.t{B.length src % 8 == 0}) : Stack UInt64.t (requires fun h0 -> B.live h0 dst /\ B.live h0 src /\ B.disjoint dst src /\ B.length dst == 16 /\ B.length src == 16) (ensures fun h0 _ h1 -> B.modifies (B.loc_buffer dst) h0 h1 /\ B.live h1 src /\ B.live h1 dst) // B.as_seq h1 dst == B.as_seq h1 src) // by (T.dump "A") (* in case you want to look at the VC *) = IB.inhabited_immutable_buffer_is_distinct_from_buffer (UInt8.uint_to_t 0) src dst; let (x, _) = lowstar_Memcpy_normal_t dst src () in //This is a call to the interop wrapper let h1 = get () in // let v = Vale.Interop.Views.up_view64 in // assert (DV.length_eq (get_downview dst); // DV.length_eq (get_downview src); // Seq.equal (LBV.as_seq h1 (LBV.mk_buffer (get_downview dst) v)) // (LBV.as_seq h1 (LBV.mk_buffer (get_downview src) v))); // lbv_as_seq_eq dst src Vale.Interop.Views.up_view64 h1; //And a lemma to rephrase the Vale postcondition x //with equalities of buffer views //back to equalities of buffers #pop-options module VC = Vale.Lib.X64.Cpuidstdcall [@__reduce__] let empty_list #a : l:list a {List.length l = 0} = []
{ "checked_file": "/", "dependencies": [ "Vale.X64.State.fsti.checked", "Vale.X64.MemoryAdapters.fsti.checked", "Vale.X64.Memory.fsti.checked", "Vale.X64.Machine_s.fst.checked", "Vale.X64.Decls.fsti.checked", "Vale.X64.CPU_Features_s.fst.checked", "Vale.Test.X64.Vale_memcpy.fsti.checked", "Vale.Test.X64.Args.fsti.checked", "Vale.Lib.X64.Cpuidstdcall.fsti.checked", "Vale.Interop.X64.fsti.checked", "Vale.Interop.Base.fst.checked", "Vale.Interop.Assumptions.fst.checked", "Vale.AsLowStar.Wrapper.fsti.checked", "Vale.AsLowStar.ValeSig.fst.checked", "Vale.AsLowStar.MemoryHelpers.fsti.checked", "Vale.AsLowStar.LowStarSig.fst.checked", "prims.fst.checked", "LowStar.Monotonic.Buffer.fsti.checked", "LowStar.ImmutableBuffer.fst.checked", "LowStar.BufferView.Up.fsti.checked", "LowStar.BufferView.Down.fsti.checked", "LowStar.Buffer.fst.checked", "FStar.UInt8.fsti.checked", "FStar.UInt64.fsti.checked", "FStar.Tactics.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.List.fst.checked", "FStar.HyperStack.ST.fsti.checked" ], "interface_file": false, "source_file": "Vale.AsLowStar.Test.fst" }
[ { "abbrev": true, "full_module": "Vale.Lib.X64.Cpuidstdcall", "short_module": "VC" }, { "abbrev": true, "full_module": "LowStar.BufferView.Down", "short_module": "DV" }, { "abbrev": true, "full_module": "LowStar.BufferView.Up", "short_module": "LBV" }, { "abbrev": true, "full_module": "FStar.Tactics", "short_module": "T" }, { "abbrev": true, "full_module": "Vale.X64.Memory", "short_module": "M" }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": true, "full_module": "LowStar.Monotonic.Buffer", "short_module": "MB" }, { "abbrev": true, "full_module": "LowStar.ImmutableBuffer", "short_module": "IB" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "Vale.X64.State", "short_module": "VS" }, { "abbrev": false, "full_module": "Vale.X64.MemoryAdapters", "short_module": null }, { "abbrev": true, "full_module": "Vale.Test.X64.Vale_memcpy", "short_module": "VM" }, { "abbrev": true, "full_module": "Vale.X64.Machine_s", "short_module": "MS" }, { "abbrev": true, "full_module": "Vale.X64.State", "short_module": "VS" }, { "abbrev": true, "full_module": "Vale.AsLowStar.Wrapper", "short_module": "W" }, { "abbrev": true, "full_module": "Vale.AsLowStar.LowStarSig", "short_module": "LSig" }, { "abbrev": true, "full_module": "Vale.AsLowStar.ValeSig", "short_module": "VSig" }, { "abbrev": true, "full_module": "Vale.Interop.X64", "short_module": "IX64" }, { "abbrev": true, "full_module": "Vale.X64.Decls", "short_module": "V" }, { "abbrev": true, "full_module": "Vale.Interop.Assumptions", "short_module": "IA" }, { "abbrev": true, "full_module": "Vale.X64.Memory", "short_module": "ME" }, { "abbrev": false, "full_module": "Vale.Interop.Base", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.AsLowStar", "short_module": null }, { "abbrev": false, "full_module": "Vale.AsLowStar", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 0, "max_fuel": 1, "max_ifuel": 1, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": true, "smtencoding_l_arith_repr": "native", "smtencoding_nl_arith_repr": "wrapped", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [ "smt.arith.nl=false", "smt.QI.EAGER_THRESHOLD=100", "smt.CASE_SPLIT=3" ], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
Vale.Interop.X64.arity_ok_stdcall Vale.Interop.Base.td
Prims.Tot
[ "total" ]
[]
[ "Prims.Nil", "Vale.Interop.Base.td" ]
[]
false
false
false
true
false
let aesni_dom:IX64.arity_ok_stdcall td =
[]
false
Hacl.Spec.Bignum.MontArithmetic.fst
Hacl.Spec.Bignum.MontArithmetic.from_mont_lemma_nonzero
val from_mont_lemma_nonzero: pbits:pos -> rLen:pos -> n:pos -> mu:nat -> aM:nat -> Lemma (requires M.mont_pre pbits rLen n mu /\ 0 < aM /\ aM < n /\ Euclid.is_prime n) (ensures (let a = M.from_mont pbits rLen n mu aM in 0 < a /\ a < n))
val from_mont_lemma_nonzero: pbits:pos -> rLen:pos -> n:pos -> mu:nat -> aM:nat -> Lemma (requires M.mont_pre pbits rLen n mu /\ 0 < aM /\ aM < n /\ Euclid.is_prime n) (ensures (let a = M.from_mont pbits rLen n mu aM in 0 < a /\ a < n))
let from_mont_lemma_nonzero pbits rLen n mu aM = let r = pow2 (pbits * rLen) in let d, _ = M.eea_pow2_odd (pbits * rLen) n in let a = M.from_mont pbits rLen n mu aM in M.from_mont_lemma pbits rLen n mu aM; assert (a == aM * d % n); assert (d <> 0); Math.Lemmas.small_mod aM n; assert (aM % n <> 0); let d1 = -d in assert (0 < d1 /\ d1 < n); Math.Lemmas.lemma_mod_sub_1 d1 n; assert ((-d1) % n == n - (d1 % n)); assert (d % n <> 0); mul_nonzero_lemma n aM d; assert (let a = M.from_mont pbits rLen n mu aM in 0 < a /\ a < n); // For some reason, this makes the proof instant. ()
{ "file_name": "code/bignum/Hacl.Spec.Bignum.MontArithmetic.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 4, "end_line": 80, "start_col": 0, "start_line": 58 }
module Hacl.Spec.Bignum.MontArithmetic open FStar.Mul open Lib.IntTypes open Lib.Sequence open Hacl.Spec.Bignum.Definitions module M = Hacl.Spec.Montgomery.Lemmas module BM = Hacl.Spec.Bignum.Montgomery module BN = Hacl.Spec.Bignum module BB = Hacl.Spec.Bignum.Base module BL = Hacl.Spec.Bignum.Lib module BIL = Hacl.Spec.Bignum.ModInvLimb module E = Hacl.Spec.Exponentiation.Lemmas module ME = Hacl.Spec.Bignum.MontExponentiation module Euclid = FStar.Math.Euclid module BI = Hacl.Spec.Bignum.ModInv #set-options "--z3rlimit 50 --fuel 0 --ifuel 0" ////////////////////////////////////////// val mul_zero_lemma: n:pos{Euclid.is_prime n} -> x:int -> y:int -> Lemma (x * y % n == 0 <==> (x % n == 0 \/ y % n == 0)) let mul_zero_lemma n x y = assert (0 % n = 0); if x % n = 0 then Math.Lemmas.lemma_mod_mul_distr_l x y n else if y % n = 0 then Math.Lemmas.lemma_mod_mul_distr_r x y n else if x * y % n = 0 then Math.Fermat.mod_mult_congr n x 0 y else () val mul_nonzero_lemma: n:pos{Euclid.is_prime n} -> x:int -> y:int -> Lemma (requires x % n <> 0 /\ y % n <> 0) (ensures x * y % n <> 0) let mul_nonzero_lemma n x y = mul_zero_lemma n x y val from_mont_lemma_nonzero: pbits:pos -> rLen:pos -> n:pos -> mu:nat -> aM:nat -> Lemma (requires M.mont_pre pbits rLen n mu /\ 0 < aM /\ aM < n /\ Euclid.is_prime n) (ensures (let a = M.from_mont pbits rLen n mu aM in 0 < a /\ a < n))
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "Lib.Sequence.fsti.checked", "Lib.NatMod.fsti.checked", "Lib.IntTypes.fsti.checked", "Hacl.Spec.Montgomery.Lemmas.fst.checked", "Hacl.Spec.Exponentiation.Lemmas.fst.checked", "Hacl.Spec.Bignum.Montgomery.fsti.checked", "Hacl.Spec.Bignum.MontExponentiation.fst.checked", "Hacl.Spec.Bignum.ModInvLimb.fsti.checked", "Hacl.Spec.Bignum.ModInv.fst.checked", "Hacl.Spec.Bignum.Lib.fst.checked", "Hacl.Spec.Bignum.Definitions.fst.checked", "Hacl.Spec.Bignum.Base.fst.checked", "Hacl.Spec.Bignum.fsti.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.Math.Fermat.fsti.checked", "FStar.Math.Euclid.fsti.checked" ], "interface_file": true, "source_file": "Hacl.Spec.Bignum.MontArithmetic.fst" }
[ { "abbrev": true, "full_module": "Hacl.Spec.Bignum.ModInv", "short_module": "BI" }, { "abbrev": true, "full_module": "FStar.Math.Euclid", "short_module": "Euclid" }, { "abbrev": true, "full_module": "Hacl.Spec.Bignum.MontExponentiation", "short_module": "ME" }, { "abbrev": true, "full_module": "Hacl.Spec.Exponentiation.Lemmas", "short_module": "E" }, { "abbrev": true, "full_module": "Hacl.Spec.Bignum.ModInvLimb", "short_module": "BIL" }, { "abbrev": true, "full_module": "Hacl.Spec.Bignum.Lib", "short_module": "BL" }, { "abbrev": true, "full_module": "Hacl.Spec.Bignum.Base", "short_module": "BB" }, { "abbrev": true, "full_module": "Hacl.Spec.Bignum", "short_module": "BN" }, { "abbrev": true, "full_module": "Hacl.Spec.Bignum.Montgomery", "short_module": "BM" }, { "abbrev": true, "full_module": "Hacl.Spec.Montgomery.Lemmas", "short_module": "M" }, { "abbrev": false, "full_module": "Hacl.Spec.Bignum.Definitions", "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": true, "full_module": "Hacl.Spec.Bignum", "short_module": "BN" }, { "abbrev": true, "full_module": "Hacl.Spec.Montgomery.Lemmas", "short_module": "M" }, { "abbrev": true, "full_module": "FStar.Math.Euclid", "short_module": "Euclid" }, { "abbrev": false, "full_module": "Hacl.Spec.Bignum.Definitions", "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.Bignum", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.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 } ]
{ "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" }
false
pbits: Prims.pos -> rLen: Prims.pos -> n: Prims.pos -> mu: Prims.nat -> aM: Prims.nat -> FStar.Pervasives.Lemma (requires Hacl.Spec.Montgomery.Lemmas.mont_pre pbits rLen n mu /\ 0 < aM /\ aM < n /\ FStar.Math.Euclid.is_prime n) (ensures (let a = Hacl.Spec.Montgomery.Lemmas.from_mont pbits rLen n mu aM in 0 < a /\ a < n))
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "Prims.pos", "Prims.nat", "Prims.int", "Prims.unit", "Prims._assert", "Prims.l_and", "Prims.b2t", "Prims.op_LessThan", "Hacl.Spec.Montgomery.Lemmas.from_mont", "Hacl.Spec.Bignum.MontArithmetic.mul_nonzero_lemma", "Prims.op_disEquality", "Prims.op_Modulus", "Prims.eq2", "Prims.op_Minus", "Prims.op_Subtraction", "FStar.Math.Lemmas.lemma_mod_sub_1", "FStar.Math.Lemmas.small_mod", "FStar.Mul.op_Star", "Hacl.Spec.Montgomery.Lemmas.from_mont_lemma", "FStar.Pervasives.Native.tuple2", "Hacl.Spec.Montgomery.Lemmas.eea_pow2_odd", "Prims.pow2" ]
[]
false
false
true
false
false
let from_mont_lemma_nonzero pbits rLen n mu aM =
let r = pow2 (pbits * rLen) in let d, _ = M.eea_pow2_odd (pbits * rLen) n in let a = M.from_mont pbits rLen n mu aM in M.from_mont_lemma pbits rLen n mu aM; assert (a == aM * d % n); assert (d <> 0); Math.Lemmas.small_mod aM n; assert (aM % n <> 0); let d1 = - d in assert (0 < d1 /\ d1 < n); Math.Lemmas.lemma_mod_sub_1 d1 n; assert ((- d1) % n == n - (d1 % n)); assert (d % n <> 0); mul_nonzero_lemma n aM d; assert (let a = M.from_mont pbits rLen n mu aM in 0 < a /\ a < n); ()
false
LowParseWriters.LowParse.fsti
LowParseWriters.LowParse.valid_buffer
val valid_buffer (p: parser) (h: HS.mem) (b: B.buffer U8.t) : GTot Type0
val valid_buffer (p: parser) (h: HS.mem) (b: B.buffer U8.t) : GTot Type0
let valid_buffer (p: parser) (h: HS.mem) (b: B.buffer U8.t) : GTot Type0 = valid_pos p h b 0ul (B.len b)
{ "file_name": "examples/layeredeffects/LowParseWriters.LowParse.fsti", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 31, "end_line": 279, "start_col": 0, "start_line": 274 }
module LowParseWriters.LowParse module HS = FStar.HyperStack module B = LowStar.Buffer module U8 = FStar.UInt8 module U32 = FStar.UInt32 module HST = FStar.HyperStack.ST type u8 : Type0 = U8.t val parser' (t: Type0) : Type u#1 inline_for_extraction noextract noeq type parser = | Parser: t: Type -> p: parser' t -> parser val valid_pos (p: parser) (h: HS.mem) (b: B.buffer U8.t) (pos: U32.t) (pos' : U32.t) : GTot Type0 val valid_pos_post (p: parser) (h: HS.mem) (b: B.buffer U8.t) (pos: U32.t) (pos' : U32.t) : Lemma (requires (valid_pos p h b pos pos')) (ensures ( B.live h b /\ U32.v pos <= U32.v pos' /\ U32.v pos' <= B.length b )) [SMTPat (valid_pos p h b pos pos')] val contents (p: parser) (h: HS.mem) (b: B.buffer U8.t) (pos: U32.t) (pos' : U32.t) : Ghost (Parser?.t p) (requires (valid_pos p h b pos pos')) (ensures (fun _ -> True)) val size (p: parser) (x: Parser?.t p) : GTot nat val contents_size (p: parser) (h: HS.mem) (b: B.buffer U8.t) (pos: U32.t) (pos' : U32.t) : Lemma (requires (valid_pos p h b pos pos')) (ensures ( valid_pos p h b pos pos' /\ size p (contents p h b pos pos') == U32.v pos' - U32.v pos )) [SMTPat (contents p h b pos pos')] inline_for_extraction val parse_empty' : parser' unit inline_for_extraction let parse_empty : parser = Parser unit parse_empty' val valid_parse_empty (h: HS.mem) (b: B.buffer u8) (pos: U32.t) (pos' : U32.t) : Lemma ( valid_pos parse_empty h b pos pos' <==> ( B.live h b /\ U32.v pos <= B.length b /\ U32.v pos' == U32.v pos )) [SMTPat (valid_pos parse_empty h b pos pos')] val size_parse_empty : squash (size parse_empty () == 0) inline_for_extraction val parse_pair' (#t1 #t2: Type) (p1: parser' t1) (p2: parser' t2) : Tot (parser' (t1 & t2)) inline_for_extraction let parse_pair (p1 p2: parser) : Tot parser = Parser (Parser?.t p1 & Parser?.t p2) (parse_pair' (Parser?.p p1) (Parser?.p p2)) val valid_parse_pair (p1 p2: parser) (h: HS.mem) (b: B.buffer U8.t) (pos1 pos2 pos3: U32.t) : Lemma (requires ( valid_pos p1 h b pos1 pos2 /\ valid_pos p2 h b pos2 pos3 )) (ensures ( valid_pos p1 h b pos1 pos2 /\ valid_pos p2 h b pos2 pos3 /\ valid_pos (p1 `parse_pair` p2) h b pos1 pos3 /\ contents (p1 `parse_pair` p2) h b pos1 pos3 == (contents p1 h b pos1 pos2, contents p2 h b pos2 pos3) )) val size_parse_pair (p1 p2: parser) (x1: Parser?.t p1) (x2: Parser?.t p2) : Lemma (size (p1 `parse_pair` p2) (x1, x2) == size p1 x1 + size p2 x2) [SMTPat (size (p1 `parse_pair` p2) (x1, x2))] val valid_ext (p: parser) (h1: HS.mem) (b1: B.buffer U8.t) (pos1: U32.t) (pos1' : U32.t) (h2: HS.mem) (b2: B.buffer U8.t) (pos2: U32.t) (pos2' : U32.t) : Lemma (requires ( valid_pos p h1 b1 pos1 pos1' /\ U32.v pos2 <= U32.v pos2' /\ U32.v pos2' <= B.length b2 /\ B.live h2 b2 /\ B.as_seq h2 (B.gsub b2 pos2 (pos2' `U32.sub` pos2)) `Seq.equal` B.as_seq h1 (B.gsub b1 pos1 (pos1' `U32.sub` pos1)) )) (ensures ( valid_pos p h1 b1 pos1 pos1' /\ valid_pos p h2 b2 pos2 pos2' /\ contents p h2 b2 pos2 pos2' == contents p h1 b1 pos1 pos1' )) let valid_frame (p: parser) (h: HS.mem) (b: B.buffer U8.t) (pos: U32.t) (pos' : U32.t) (l: B.loc) (h' : HS.mem) : Lemma (requires ( B.live h b /\ (valid_pos p h b pos pos' \/ valid_pos p h' b pos pos') /\ B.modifies l h h' /\ B.loc_disjoint l (B.loc_buffer_from_to b pos pos') )) (ensures ( valid_pos p h b pos pos' /\ valid_pos p h' b pos pos' /\ contents p h' b pos pos' == contents p h b pos pos' )) = B.loc_buffer_mgsub_eq (B.trivial_preorder _) b pos (pos' `U32.sub` pos); Classical.move_requires (valid_ext p h b pos pos' h' b pos) pos'; Classical.move_requires (valid_ext p h' b pos pos' h b pos) pos' let valid_gsub_elim (p: parser) (h: HS.mem) (b: B.buffer U8.t) (pos0 pos1 pos2: U32.t) (len: U32.t) : Lemma (requires ( U32.v pos0 + U32.v len <= B.length b /\ valid_pos p h (B.gsub b pos0 len) pos1 pos2 /\ B.live h b )) (ensures ( U32.v pos0 + U32.v pos2 <= B.length b /\ valid_pos p h (B.gsub b pos0 len) pos1 pos2 /\ valid_pos p h b (pos0 `U32.add` pos1) (pos0 `U32.add` pos2) /\ contents p h b (pos0 `U32.add` pos1) (pos0 `U32.add` pos2) == contents p h (B.gsub b pos0 len) pos1 pos2 )) [SMTPat (valid_pos p h (B.gsub b pos0 len) pos1 pos2)] = valid_ext p h (B.gsub b pos0 len) pos1 pos2 h b (pos0 `U32.add` pos1) (pos0 `U32.add` pos2) let valid_gsub_intro (p: parser) (h: HS.mem) (b: B.buffer U8.t) (pos0 pos1 pos2: U32.t) (len: U32.t) : Lemma (requires ( U32.v pos0 + U32.v len <= B.length b /\ U32.v pos1 <= U32.v pos2 /\ U32.v pos2 <= U32.v len /\ valid_pos p h b (pos0 `U32.add` pos1) (pos0 `U32.add` pos2) )) (ensures ( valid_pos p h (B.gsub b pos0 len) pos1 pos2 /\ contents p h b (pos0 `U32.add` pos1) (pos0 `U32.add` pos2) == contents p h (B.gsub b pos0 len) pos1 pos2 )) [SMTPat (valid_pos p h (B.gsub b pos0 len) pos1 pos2)] = valid_ext p h b (pos0 `U32.add` pos1) (pos0 `U32.add` pos2) h (B.gsub b pos0 len) pos1 pos2 inline_for_extraction let leaf_writer (p: parser) : Tot Type = (b: B.buffer U8.t) -> (len: U32.t { len == B.len b }) -> (x: Parser?.t p) -> HST.Stack (option U32.t) (requires (fun h -> B.live h b)) (ensures (fun h res h' -> match res with | None -> B.modifies (B.loc_buffer b) h h' /\ size p x > B.length b | Some xlen -> U32.v xlen <= B.length b /\ B.modifies (B.loc_buffer_from_to b 0ul xlen) h h' /\ valid_pos p h' b 0ul xlen /\ contents p h' b 0ul xlen == x /\ size p x == U32.v xlen )) val valid_parse_pair_inv_spec (h: HS.mem) (p1 p2: parser) (b: B.buffer U8.t) (pos1 pos3: U32.t) : Ghost U32.t (requires ( valid_pos (p1 `parse_pair` p2) h b pos1 pos3 )) (ensures (fun pos2 -> valid_pos p1 h b pos1 pos2 /\ valid_pos p2 h b pos2 pos3 /\ contents (p1 `parse_pair` p2) h b pos1 pos3 == (contents p1 h b pos1 pos2, contents p2 h b pos2 pos3) )) inline_for_extraction val valid_parse_pair_inv (p1 p2: parser) (b: B.buffer U8.t) (len: U32.t { len == B.len b }) (pos1 pos3: U32.t) : HST.Stack U32.t (requires (fun h -> valid_pos (p1 `parse_pair` p2) h b pos1 pos3 )) (ensures (fun h pos2 h' -> B.modifies B.loc_none h h' /\ pos2 == valid_parse_pair_inv_spec h p1 p2 b pos1 pos3 /\ valid_pos p1 h b pos1 pos2 /\ valid_pos p2 h b pos2 pos3 /\ contents (p1 `parse_pair` p2) h b pos1 pos3 == (contents p1 h b pos1 pos2, contents p2 h b pos2 pos3) ))
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowStar.Buffer.fst.checked", "FStar.UInt8.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Classical.fsti.checked" ], "interface_file": false, "source_file": "LowParseWriters.LowParse.fsti" }
[ { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": false, "full_module": "LowParseWriters", "short_module": null }, { "abbrev": false, "full_module": "LowParseWriters", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
p: LowParseWriters.LowParse.parser -> h: FStar.Monotonic.HyperStack.mem -> b: LowStar.Buffer.buffer FStar.UInt8.t -> Prims.GTot Type0
Prims.GTot
[ "sometrivial" ]
[]
[ "LowParseWriters.LowParse.parser", "FStar.Monotonic.HyperStack.mem", "LowStar.Buffer.buffer", "FStar.UInt8.t", "LowParseWriters.LowParse.valid_pos", "FStar.UInt32.__uint_to_t", "LowStar.Monotonic.Buffer.len", "LowStar.Buffer.trivial_preorder" ]
[]
false
false
false
false
true
let valid_buffer (p: parser) (h: HS.mem) (b: B.buffer U8.t) : GTot Type0 =
valid_pos p h b 0ul (B.len b)
false
Vale.AsLowStar.Test.fst
Vale.AsLowStar.Test.itest
val itest : x: Vale.AsLowStar.Test.ib64 -> Prims.unit
let itest (x:ib64) = assert (V.buffer_length (as_vale_immbuffer x) == (B.length x * view_n TUInt8) / view_n TUInt64); assert (V.buffer_length (as_vale_immbuffer x) == B.length x / 8)
{ "file_name": "vale/code/arch/x64/interop/Vale.AsLowStar.Test.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 66, "end_line": 145, "start_col": 0, "start_line": 143 }
module Vale.AsLowStar.Test open FStar.Mul open Vale.Interop.Base module ME = Vale.X64.Memory module IA = Vale.Interop.Assumptions module V = Vale.X64.Decls module IX64 = Vale.Interop.X64 module VSig = Vale.AsLowStar.ValeSig module LSig = Vale.AsLowStar.LowStarSig module W = Vale.AsLowStar.Wrapper module VS = Vale.X64.State module MS = Vale.X64.Machine_s (* A little utility to trigger normalization in types *) let as_t (#a:Type) (x:normal a) : a = x let as_normal_t (#a:Type) (x:a) : normal a = x //////////////////////////////////////////////////////////////////////////////// //First a little standalone, toy experiment [@__reduce__] let b64 = buf_t TUInt8 TUInt64 [@__reduce__] let ib64 = ibuf_t TUInt8 TUInt64 [@__reduce__] let t64_mod = TD_Buffer TUInt8 TUInt64 default_bq [@__reduce__] let t64_no_mod = TD_Buffer TUInt8 TUInt64 ({modified=false; strict_disjointness=false; taint=MS.Secret}) [@__reduce__] let t64_imm = TD_ImmBuffer TUInt8 TUInt64 ({modified=false; strict_disjointness=false; taint=MS.Secret}) [@__reduce__] let (dom : list td{List.length dom <= 20}) = let y = [t64_mod;t64_imm] in assert_norm (List.length y = 2); y assume val pre : VSig.vale_pre dom assume val post : VSig.vale_post dom assume val v: VSig.vale_sig_stdcall pre post assume val c: V.va_code [@__reduce__] let call_c_t = IX64.as_lowstar_sig_t_weak_stdcall c dom [] _ _ (W.mk_prediction c dom [] (v c IA.win)) let call_c : call_c_t = IX64.wrap_weak_stdcall c dom (W.mk_prediction c dom [] (v c IA.win)) let call_c_normal_t : normal call_c_t = as_normal_t #call_c_t call_c //You can ask emacs to show you the type of call_c_normal_t ... //////////////////////////////////////////////////////////////////////////////// //Now memcpy module VM = Vale.Test.X64.Vale_memcpy [@__reduce__] let vm_dom = [t64_mod; t64_imm] open Vale.X64.MemoryAdapters (* Need to rearrange the order of arguments *) [@__reduce__] let vm_pre : VSig.vale_pre vm_dom = fun (c:V.va_code) (dst:b64) (src:ib64) (va_s0:V.va_state) -> VM.va_req_Memcpy c va_s0 IA.win (as_vale_buffer dst) (as_vale_immbuffer src) [@__reduce__] let vm_post : VSig.vale_post vm_dom = fun (c:V.va_code) (dst:b64) (src:ib64) (va_s0:V.va_state) (va_s1:V.va_state) (f:V.va_fuel) -> VM.va_ens_Memcpy c va_s0 IA.win (as_vale_buffer dst) (as_vale_immbuffer src) va_s1 f module VS = Vale.X64.State #reset-options "--print_effect_args --z3rlimit 200" (* The vale lemma doesn't quite suffice to prove the modifies clause expected of the interop layer *) [@__reduce__] let vm_lemma' (code:V.va_code) (_win:bool) (dst:b64) (src:ib64) (va_s0:V.va_state) : Ghost (V.va_state & V.va_fuel) (requires vm_pre code dst src va_s0) (ensures (fun (va_s1, f) -> V.eval_code code va_s0 f va_s1 /\ VSig.vale_calling_conventions_stdcall va_s0 va_s1 /\ vm_post code dst src va_s0 va_s1 f /\ ME.buffer_readable (VS.vs_get_vale_heap va_s1) (as_vale_immbuffer src) /\ ME.buffer_readable (VS.vs_get_vale_heap va_s1) (as_vale_buffer dst) /\ ME.buffer_writeable (as_vale_buffer dst) /\ ME.modifies (ME.loc_union (ME.loc_buffer (as_vale_buffer dst)) ME.loc_none) (VS.vs_get_vale_heap va_s0) (VS.vs_get_vale_heap va_s1) )) = let va_s1, f = VM.va_lemma_Memcpy code va_s0 IA.win (as_vale_buffer dst) (as_vale_immbuffer src) in Vale.AsLowStar.MemoryHelpers.buffer_writeable_reveal ME.TUInt8 ME.TUInt64 dst; (va_s1, f) (* Prove that vm_lemma' has the required type *) let vm_lemma = as_t #(VSig.vale_sig_stdcall vm_pre vm_post) vm_lemma' let code_Memcpy = VM.va_code_Memcpy IA.win (* Here's the type expected for the memcpy wrapper *) [@__reduce__] let lowstar_Memcpy_t = IX64.as_lowstar_sig_t_weak_stdcall code_Memcpy vm_dom [] _ _ (W.mk_prediction code_Memcpy vm_dom [] (vm_lemma code_Memcpy IA.win)) (* And here's the memcpy wrapper itself *) let lowstar_Memcpy : lowstar_Memcpy_t = IX64.wrap_weak_stdcall code_Memcpy vm_dom (W.mk_prediction code_Memcpy vm_dom [] (vm_lemma code_Memcpy IA.win)) let lowstar_Memcpy_normal_t //: normal lowstar_Memcpy_t = as_normal_t #lowstar_Memcpy_t lowstar_Memcpy module B = LowStar.Buffer module IB = LowStar.ImmutableBuffer module MB = LowStar.Monotonic.Buffer open FStar.HyperStack.ST module M = Vale.X64.Memory let test (x:b64) = assert (V.buffer_length (as_vale_buffer x) == (B.length x * view_n TUInt8) / view_n TUInt64);
{ "checked_file": "/", "dependencies": [ "Vale.X64.State.fsti.checked", "Vale.X64.MemoryAdapters.fsti.checked", "Vale.X64.Memory.fsti.checked", "Vale.X64.Machine_s.fst.checked", "Vale.X64.Decls.fsti.checked", "Vale.X64.CPU_Features_s.fst.checked", "Vale.Test.X64.Vale_memcpy.fsti.checked", "Vale.Test.X64.Args.fsti.checked", "Vale.Lib.X64.Cpuidstdcall.fsti.checked", "Vale.Interop.X64.fsti.checked", "Vale.Interop.Base.fst.checked", "Vale.Interop.Assumptions.fst.checked", "Vale.AsLowStar.Wrapper.fsti.checked", "Vale.AsLowStar.ValeSig.fst.checked", "Vale.AsLowStar.MemoryHelpers.fsti.checked", "Vale.AsLowStar.LowStarSig.fst.checked", "prims.fst.checked", "LowStar.Monotonic.Buffer.fsti.checked", "LowStar.ImmutableBuffer.fst.checked", "LowStar.BufferView.Up.fsti.checked", "LowStar.BufferView.Down.fsti.checked", "LowStar.Buffer.fst.checked", "FStar.UInt8.fsti.checked", "FStar.UInt64.fsti.checked", "FStar.Tactics.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.List.fst.checked", "FStar.HyperStack.ST.fsti.checked" ], "interface_file": false, "source_file": "Vale.AsLowStar.Test.fst" }
[ { "abbrev": true, "full_module": "Vale.X64.Memory", "short_module": "M" }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": true, "full_module": "LowStar.Monotonic.Buffer", "short_module": "MB" }, { "abbrev": true, "full_module": "LowStar.ImmutableBuffer", "short_module": "IB" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "Vale.X64.State", "short_module": "VS" }, { "abbrev": false, "full_module": "Vale.X64.MemoryAdapters", "short_module": null }, { "abbrev": true, "full_module": "Vale.Test.X64.Vale_memcpy", "short_module": "VM" }, { "abbrev": true, "full_module": "Vale.X64.Machine_s", "short_module": "MS" }, { "abbrev": true, "full_module": "Vale.X64.State", "short_module": "VS" }, { "abbrev": true, "full_module": "Vale.AsLowStar.Wrapper", "short_module": "W" }, { "abbrev": true, "full_module": "Vale.AsLowStar.LowStarSig", "short_module": "LSig" }, { "abbrev": true, "full_module": "Vale.AsLowStar.ValeSig", "short_module": "VSig" }, { "abbrev": true, "full_module": "Vale.Interop.X64", "short_module": "IX64" }, { "abbrev": true, "full_module": "Vale.X64.Decls", "short_module": "V" }, { "abbrev": true, "full_module": "Vale.Interop.Assumptions", "short_module": "IA" }, { "abbrev": true, "full_module": "Vale.X64.Memory", "short_module": "ME" }, { "abbrev": false, "full_module": "Vale.Interop.Base", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.AsLowStar", "short_module": null }, { "abbrev": false, "full_module": "Vale.AsLowStar", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 0, "max_fuel": 1, "max_ifuel": 1, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": true, "smtencoding_l_arith_repr": "native", "smtencoding_nl_arith_repr": "wrapped", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [ "smt.arith.nl=false", "smt.QI.EAGER_THRESHOLD=100", "smt.CASE_SPLIT=3" ], "z3refresh": false, "z3rlimit": 200, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
x: Vale.AsLowStar.Test.ib64 -> Prims.unit
Prims.Tot
[ "total" ]
[]
[ "Vale.AsLowStar.Test.ib64", "Prims._assert", "Prims.eq2", "Prims.int", "Vale.X64.Decls.buffer_length", "Vale.Arch.HeapTypes_s.TUInt64", "Vale.X64.MemoryAdapters.as_vale_immbuffer", "Vale.Arch.HeapTypes_s.TUInt8", "Prims.op_Division", "LowStar.Monotonic.Buffer.length", "Vale.Interop.Types.base_typ_as_type", "LowStar.ImmutableBuffer.immutable_preorder", "Prims.unit", "FStar.Mul.op_Star", "Vale.Interop.Types.view_n" ]
[]
false
false
false
true
false
let itest (x: ib64) =
assert (V.buffer_length (as_vale_immbuffer x) == (B.length x * view_n TUInt8) / view_n TUInt64); assert (V.buffer_length (as_vale_immbuffer x) == B.length x / 8)
false
Hacl.Spec.Bignum.MontArithmetic.fst
Hacl.Spec.Bignum.MontArithmetic.mul_nonzero_lemma
val mul_nonzero_lemma: n:pos{Euclid.is_prime n} -> x:int -> y:int -> Lemma (requires x % n <> 0 /\ y % n <> 0) (ensures x * y % n <> 0)
val mul_nonzero_lemma: n:pos{Euclid.is_prime n} -> x:int -> y:int -> Lemma (requires x % n <> 0 /\ y % n <> 0) (ensures x * y % n <> 0)
let mul_nonzero_lemma n x y = mul_zero_lemma n x y
{ "file_name": "code/bignum/Hacl.Spec.Bignum.MontArithmetic.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 22, "end_line": 46, "start_col": 0, "start_line": 45 }
module Hacl.Spec.Bignum.MontArithmetic open FStar.Mul open Lib.IntTypes open Lib.Sequence open Hacl.Spec.Bignum.Definitions module M = Hacl.Spec.Montgomery.Lemmas module BM = Hacl.Spec.Bignum.Montgomery module BN = Hacl.Spec.Bignum module BB = Hacl.Spec.Bignum.Base module BL = Hacl.Spec.Bignum.Lib module BIL = Hacl.Spec.Bignum.ModInvLimb module E = Hacl.Spec.Exponentiation.Lemmas module ME = Hacl.Spec.Bignum.MontExponentiation module Euclid = FStar.Math.Euclid module BI = Hacl.Spec.Bignum.ModInv #set-options "--z3rlimit 50 --fuel 0 --ifuel 0" ////////////////////////////////////////// val mul_zero_lemma: n:pos{Euclid.is_prime n} -> x:int -> y:int -> Lemma (x * y % n == 0 <==> (x % n == 0 \/ y % n == 0)) let mul_zero_lemma n x y = assert (0 % n = 0); if x % n = 0 then Math.Lemmas.lemma_mod_mul_distr_l x y n else if y % n = 0 then Math.Lemmas.lemma_mod_mul_distr_r x y n else if x * y % n = 0 then Math.Fermat.mod_mult_congr n x 0 y else () val mul_nonzero_lemma: n:pos{Euclid.is_prime n} -> x:int -> y:int -> Lemma (requires x % n <> 0 /\ y % n <> 0)
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "Lib.Sequence.fsti.checked", "Lib.NatMod.fsti.checked", "Lib.IntTypes.fsti.checked", "Hacl.Spec.Montgomery.Lemmas.fst.checked", "Hacl.Spec.Exponentiation.Lemmas.fst.checked", "Hacl.Spec.Bignum.Montgomery.fsti.checked", "Hacl.Spec.Bignum.MontExponentiation.fst.checked", "Hacl.Spec.Bignum.ModInvLimb.fsti.checked", "Hacl.Spec.Bignum.ModInv.fst.checked", "Hacl.Spec.Bignum.Lib.fst.checked", "Hacl.Spec.Bignum.Definitions.fst.checked", "Hacl.Spec.Bignum.Base.fst.checked", "Hacl.Spec.Bignum.fsti.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.Math.Fermat.fsti.checked", "FStar.Math.Euclid.fsti.checked" ], "interface_file": true, "source_file": "Hacl.Spec.Bignum.MontArithmetic.fst" }
[ { "abbrev": true, "full_module": "Hacl.Spec.Bignum.ModInv", "short_module": "BI" }, { "abbrev": true, "full_module": "FStar.Math.Euclid", "short_module": "Euclid" }, { "abbrev": true, "full_module": "Hacl.Spec.Bignum.MontExponentiation", "short_module": "ME" }, { "abbrev": true, "full_module": "Hacl.Spec.Exponentiation.Lemmas", "short_module": "E" }, { "abbrev": true, "full_module": "Hacl.Spec.Bignum.ModInvLimb", "short_module": "BIL" }, { "abbrev": true, "full_module": "Hacl.Spec.Bignum.Lib", "short_module": "BL" }, { "abbrev": true, "full_module": "Hacl.Spec.Bignum.Base", "short_module": "BB" }, { "abbrev": true, "full_module": "Hacl.Spec.Bignum", "short_module": "BN" }, { "abbrev": true, "full_module": "Hacl.Spec.Bignum.Montgomery", "short_module": "BM" }, { "abbrev": true, "full_module": "Hacl.Spec.Montgomery.Lemmas", "short_module": "M" }, { "abbrev": false, "full_module": "Hacl.Spec.Bignum.Definitions", "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": true, "full_module": "Hacl.Spec.Bignum", "short_module": "BN" }, { "abbrev": true, "full_module": "Hacl.Spec.Montgomery.Lemmas", "short_module": "M" }, { "abbrev": true, "full_module": "FStar.Math.Euclid", "short_module": "Euclid" }, { "abbrev": false, "full_module": "Hacl.Spec.Bignum.Definitions", "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.Bignum", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.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 } ]
{ "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" }
false
n: Prims.pos{FStar.Math.Euclid.is_prime n} -> x: Prims.int -> y: Prims.int -> FStar.Pervasives.Lemma (requires x % n <> 0 /\ y % n <> 0) (ensures x * y % n <> 0)
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "Prims.pos", "FStar.Math.Euclid.is_prime", "Prims.int", "Hacl.Spec.Bignum.MontArithmetic.mul_zero_lemma", "Prims.unit" ]
[]
true
false
true
false
false
let mul_nonzero_lemma n x y =
mul_zero_lemma n x y
false
Vale.AsLowStar.Test.fst
Vale.AsLowStar.Test.empty_list
val empty_list (#a: _) : l: list a {List.length l = 0}
val empty_list (#a: _) : l: list a {List.length l = 0}
let empty_list #a : l:list a {List.length l = 0} = []
{ "file_name": "vale/code/arch/x64/interop/Vale.AsLowStar.Test.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 53, "end_line": 185, "start_col": 0, "start_line": 185 }
module Vale.AsLowStar.Test open FStar.Mul open Vale.Interop.Base module ME = Vale.X64.Memory module IA = Vale.Interop.Assumptions module V = Vale.X64.Decls module IX64 = Vale.Interop.X64 module VSig = Vale.AsLowStar.ValeSig module LSig = Vale.AsLowStar.LowStarSig module W = Vale.AsLowStar.Wrapper module VS = Vale.X64.State module MS = Vale.X64.Machine_s (* A little utility to trigger normalization in types *) let as_t (#a:Type) (x:normal a) : a = x let as_normal_t (#a:Type) (x:a) : normal a = x //////////////////////////////////////////////////////////////////////////////// //First a little standalone, toy experiment [@__reduce__] let b64 = buf_t TUInt8 TUInt64 [@__reduce__] let ib64 = ibuf_t TUInt8 TUInt64 [@__reduce__] let t64_mod = TD_Buffer TUInt8 TUInt64 default_bq [@__reduce__] let t64_no_mod = TD_Buffer TUInt8 TUInt64 ({modified=false; strict_disjointness=false; taint=MS.Secret}) [@__reduce__] let t64_imm = TD_ImmBuffer TUInt8 TUInt64 ({modified=false; strict_disjointness=false; taint=MS.Secret}) [@__reduce__] let (dom : list td{List.length dom <= 20}) = let y = [t64_mod;t64_imm] in assert_norm (List.length y = 2); y assume val pre : VSig.vale_pre dom assume val post : VSig.vale_post dom assume val v: VSig.vale_sig_stdcall pre post assume val c: V.va_code [@__reduce__] let call_c_t = IX64.as_lowstar_sig_t_weak_stdcall c dom [] _ _ (W.mk_prediction c dom [] (v c IA.win)) let call_c : call_c_t = IX64.wrap_weak_stdcall c dom (W.mk_prediction c dom [] (v c IA.win)) let call_c_normal_t : normal call_c_t = as_normal_t #call_c_t call_c //You can ask emacs to show you the type of call_c_normal_t ... //////////////////////////////////////////////////////////////////////////////// //Now memcpy module VM = Vale.Test.X64.Vale_memcpy [@__reduce__] let vm_dom = [t64_mod; t64_imm] open Vale.X64.MemoryAdapters (* Need to rearrange the order of arguments *) [@__reduce__] let vm_pre : VSig.vale_pre vm_dom = fun (c:V.va_code) (dst:b64) (src:ib64) (va_s0:V.va_state) -> VM.va_req_Memcpy c va_s0 IA.win (as_vale_buffer dst) (as_vale_immbuffer src) [@__reduce__] let vm_post : VSig.vale_post vm_dom = fun (c:V.va_code) (dst:b64) (src:ib64) (va_s0:V.va_state) (va_s1:V.va_state) (f:V.va_fuel) -> VM.va_ens_Memcpy c va_s0 IA.win (as_vale_buffer dst) (as_vale_immbuffer src) va_s1 f module VS = Vale.X64.State #reset-options "--print_effect_args --z3rlimit 200" (* The vale lemma doesn't quite suffice to prove the modifies clause expected of the interop layer *) [@__reduce__] let vm_lemma' (code:V.va_code) (_win:bool) (dst:b64) (src:ib64) (va_s0:V.va_state) : Ghost (V.va_state & V.va_fuel) (requires vm_pre code dst src va_s0) (ensures (fun (va_s1, f) -> V.eval_code code va_s0 f va_s1 /\ VSig.vale_calling_conventions_stdcall va_s0 va_s1 /\ vm_post code dst src va_s0 va_s1 f /\ ME.buffer_readable (VS.vs_get_vale_heap va_s1) (as_vale_immbuffer src) /\ ME.buffer_readable (VS.vs_get_vale_heap va_s1) (as_vale_buffer dst) /\ ME.buffer_writeable (as_vale_buffer dst) /\ ME.modifies (ME.loc_union (ME.loc_buffer (as_vale_buffer dst)) ME.loc_none) (VS.vs_get_vale_heap va_s0) (VS.vs_get_vale_heap va_s1) )) = let va_s1, f = VM.va_lemma_Memcpy code va_s0 IA.win (as_vale_buffer dst) (as_vale_immbuffer src) in Vale.AsLowStar.MemoryHelpers.buffer_writeable_reveal ME.TUInt8 ME.TUInt64 dst; (va_s1, f) (* Prove that vm_lemma' has the required type *) let vm_lemma = as_t #(VSig.vale_sig_stdcall vm_pre vm_post) vm_lemma' let code_Memcpy = VM.va_code_Memcpy IA.win (* Here's the type expected for the memcpy wrapper *) [@__reduce__] let lowstar_Memcpy_t = IX64.as_lowstar_sig_t_weak_stdcall code_Memcpy vm_dom [] _ _ (W.mk_prediction code_Memcpy vm_dom [] (vm_lemma code_Memcpy IA.win)) (* And here's the memcpy wrapper itself *) let lowstar_Memcpy : lowstar_Memcpy_t = IX64.wrap_weak_stdcall code_Memcpy vm_dom (W.mk_prediction code_Memcpy vm_dom [] (vm_lemma code_Memcpy IA.win)) let lowstar_Memcpy_normal_t //: normal lowstar_Memcpy_t = as_normal_t #lowstar_Memcpy_t lowstar_Memcpy module B = LowStar.Buffer module IB = LowStar.ImmutableBuffer module MB = LowStar.Monotonic.Buffer open FStar.HyperStack.ST module M = Vale.X64.Memory let test (x:b64) = assert (V.buffer_length (as_vale_buffer x) == (B.length x * view_n TUInt8) / view_n TUInt64); assert (V.buffer_length (as_vale_buffer x) == B.length x / 8) let itest (x:ib64) = assert (V.buffer_length (as_vale_immbuffer x) == (B.length x * view_n TUInt8) / view_n TUInt64); assert (V.buffer_length (as_vale_immbuffer x) == B.length x / 8) module T = FStar.Tactics #reset-options "--using_facts_from '* -FStar.Tactics -FStar.Reflection'" module LBV = LowStar.BufferView.Up module DV = LowStar.BufferView.Down #push-options "--ext compat:normalizer_memo_ignore_cfg" let memcpy_Test (dst:B.buffer UInt8.t{B.length dst % 8 == 0}) (src:IB.ibuffer UInt8.t{B.length src % 8 == 0}) : Stack UInt64.t (requires fun h0 -> B.live h0 dst /\ B.live h0 src /\ B.disjoint dst src /\ B.length dst == 16 /\ B.length src == 16) (ensures fun h0 _ h1 -> B.modifies (B.loc_buffer dst) h0 h1 /\ B.live h1 src /\ B.live h1 dst) // B.as_seq h1 dst == B.as_seq h1 src) // by (T.dump "A") (* in case you want to look at the VC *) = IB.inhabited_immutable_buffer_is_distinct_from_buffer (UInt8.uint_to_t 0) src dst; let (x, _) = lowstar_Memcpy_normal_t dst src () in //This is a call to the interop wrapper let h1 = get () in // let v = Vale.Interop.Views.up_view64 in // assert (DV.length_eq (get_downview dst); // DV.length_eq (get_downview src); // Seq.equal (LBV.as_seq h1 (LBV.mk_buffer (get_downview dst) v)) // (LBV.as_seq h1 (LBV.mk_buffer (get_downview src) v))); // lbv_as_seq_eq dst src Vale.Interop.Views.up_view64 h1; //And a lemma to rephrase the Vale postcondition x //with equalities of buffer views //back to equalities of buffers #pop-options module VC = Vale.Lib.X64.Cpuidstdcall
{ "checked_file": "/", "dependencies": [ "Vale.X64.State.fsti.checked", "Vale.X64.MemoryAdapters.fsti.checked", "Vale.X64.Memory.fsti.checked", "Vale.X64.Machine_s.fst.checked", "Vale.X64.Decls.fsti.checked", "Vale.X64.CPU_Features_s.fst.checked", "Vale.Test.X64.Vale_memcpy.fsti.checked", "Vale.Test.X64.Args.fsti.checked", "Vale.Lib.X64.Cpuidstdcall.fsti.checked", "Vale.Interop.X64.fsti.checked", "Vale.Interop.Base.fst.checked", "Vale.Interop.Assumptions.fst.checked", "Vale.AsLowStar.Wrapper.fsti.checked", "Vale.AsLowStar.ValeSig.fst.checked", "Vale.AsLowStar.MemoryHelpers.fsti.checked", "Vale.AsLowStar.LowStarSig.fst.checked", "prims.fst.checked", "LowStar.Monotonic.Buffer.fsti.checked", "LowStar.ImmutableBuffer.fst.checked", "LowStar.BufferView.Up.fsti.checked", "LowStar.BufferView.Down.fsti.checked", "LowStar.Buffer.fst.checked", "FStar.UInt8.fsti.checked", "FStar.UInt64.fsti.checked", "FStar.Tactics.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.List.fst.checked", "FStar.HyperStack.ST.fsti.checked" ], "interface_file": false, "source_file": "Vale.AsLowStar.Test.fst" }
[ { "abbrev": true, "full_module": "Vale.Lib.X64.Cpuidstdcall", "short_module": "VC" }, { "abbrev": true, "full_module": "LowStar.BufferView.Down", "short_module": "DV" }, { "abbrev": true, "full_module": "LowStar.BufferView.Up", "short_module": "LBV" }, { "abbrev": true, "full_module": "FStar.Tactics", "short_module": "T" }, { "abbrev": true, "full_module": "Vale.X64.Memory", "short_module": "M" }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": true, "full_module": "LowStar.Monotonic.Buffer", "short_module": "MB" }, { "abbrev": true, "full_module": "LowStar.ImmutableBuffer", "short_module": "IB" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "Vale.X64.State", "short_module": "VS" }, { "abbrev": false, "full_module": "Vale.X64.MemoryAdapters", "short_module": null }, { "abbrev": true, "full_module": "Vale.Test.X64.Vale_memcpy", "short_module": "VM" }, { "abbrev": true, "full_module": "Vale.X64.Machine_s", "short_module": "MS" }, { "abbrev": true, "full_module": "Vale.X64.State", "short_module": "VS" }, { "abbrev": true, "full_module": "Vale.AsLowStar.Wrapper", "short_module": "W" }, { "abbrev": true, "full_module": "Vale.AsLowStar.LowStarSig", "short_module": "LSig" }, { "abbrev": true, "full_module": "Vale.AsLowStar.ValeSig", "short_module": "VSig" }, { "abbrev": true, "full_module": "Vale.Interop.X64", "short_module": "IX64" }, { "abbrev": true, "full_module": "Vale.X64.Decls", "short_module": "V" }, { "abbrev": true, "full_module": "Vale.Interop.Assumptions", "short_module": "IA" }, { "abbrev": true, "full_module": "Vale.X64.Memory", "short_module": "ME" }, { "abbrev": false, "full_module": "Vale.Interop.Base", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.AsLowStar", "short_module": null }, { "abbrev": false, "full_module": "Vale.AsLowStar", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 0, "max_fuel": 1, "max_ifuel": 1, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": true, "smtencoding_l_arith_repr": "native", "smtencoding_nl_arith_repr": "wrapped", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [ "smt.arith.nl=false", "smt.QI.EAGER_THRESHOLD=100", "smt.CASE_SPLIT=3" ], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
l: Prims.list a {FStar.List.Tot.Base.length l = 0}
Prims.Tot
[ "total" ]
[]
[ "Prims.Nil", "Prims.list", "Prims.b2t", "Prims.op_Equality", "Prims.int", "FStar.List.Tot.Base.length" ]
[]
false
false
false
false
false
let empty_list #a : l: list a {List.length l = 0} =
[]
false
Hacl.Spec.Bignum.MontArithmetic.fst
Hacl.Spec.Bignum.MontArithmetic.bn_field_init
val bn_field_init: #t:limb_t -> #len:BN.bn_len t -> n:lbignum t len -> Pure (bn_mont_ctx t) (requires bn_mont_ctx_pre n) (ensures fun k -> bn_mont_ctx_inv k /\ k.n == n /\ k.len == len)
val bn_field_init: #t:limb_t -> #len:BN.bn_len t -> n:lbignum t len -> Pure (bn_mont_ctx t) (requires bn_mont_ctx_pre n) (ensures fun k -> bn_mont_ctx_inv k /\ k.n == n /\ k.len == len)
let bn_field_init #t #len n = let nBits = bits t * BL.bn_get_top_index n in BL.bn_low_bound_bits_lemma n; BM.bn_precomp_r2_mod_n_lemma nBits n; let r2 = BM.bn_precomp_r2_mod_n nBits n in assert (bn_v r2 == pow2 (2 * bits t * len) % bn_v n); let mu = BIL.mod_inv_limb n.[0] in BIL.bn_mod_inv_limb_lemma n; assert ((1 + bn_v n * v mu) % pow2 (bits t) == 0); bn_eval_bound n len; { len = len; n = n; mu = mu; r2 = r2 }
{ "file_name": "code/bignum/Hacl.Spec.Bignum.MontArithmetic.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 40, "end_line": 107, "start_col": 0, "start_line": 93 }
module Hacl.Spec.Bignum.MontArithmetic open FStar.Mul open Lib.IntTypes open Lib.Sequence open Hacl.Spec.Bignum.Definitions module M = Hacl.Spec.Montgomery.Lemmas module BM = Hacl.Spec.Bignum.Montgomery module BN = Hacl.Spec.Bignum module BB = Hacl.Spec.Bignum.Base module BL = Hacl.Spec.Bignum.Lib module BIL = Hacl.Spec.Bignum.ModInvLimb module E = Hacl.Spec.Exponentiation.Lemmas module ME = Hacl.Spec.Bignum.MontExponentiation module Euclid = FStar.Math.Euclid module BI = Hacl.Spec.Bignum.ModInv #set-options "--z3rlimit 50 --fuel 0 --ifuel 0" ////////////////////////////////////////// val mul_zero_lemma: n:pos{Euclid.is_prime n} -> x:int -> y:int -> Lemma (x * y % n == 0 <==> (x % n == 0 \/ y % n == 0)) let mul_zero_lemma n x y = assert (0 % n = 0); if x % n = 0 then Math.Lemmas.lemma_mod_mul_distr_l x y n else if y % n = 0 then Math.Lemmas.lemma_mod_mul_distr_r x y n else if x * y % n = 0 then Math.Fermat.mod_mult_congr n x 0 y else () val mul_nonzero_lemma: n:pos{Euclid.is_prime n} -> x:int -> y:int -> Lemma (requires x % n <> 0 /\ y % n <> 0) (ensures x * y % n <> 0) let mul_nonzero_lemma n x y = mul_zero_lemma n x y val from_mont_lemma_nonzero: pbits:pos -> rLen:pos -> n:pos -> mu:nat -> aM:nat -> Lemma (requires M.mont_pre pbits rLen n mu /\ 0 < aM /\ aM < n /\ Euclid.is_prime n) (ensures (let a = M.from_mont pbits rLen n mu aM in 0 < a /\ a < n)) let from_mont_lemma_nonzero pbits rLen n mu aM = let r = pow2 (pbits * rLen) in let d, _ = M.eea_pow2_odd (pbits * rLen) n in let a = M.from_mont pbits rLen n mu aM in M.from_mont_lemma pbits rLen n mu aM; assert (a == aM * d % n); assert (d <> 0); Math.Lemmas.small_mod aM n; assert (aM % n <> 0); let d1 = -d in assert (0 < d1 /\ d1 < n); Math.Lemmas.lemma_mod_sub_1 d1 n; assert ((-d1) % n == n - (d1 % n)); assert (d % n <> 0); mul_nonzero_lemma n aM d; assert (let a = M.from_mont pbits rLen n mu aM in 0 < a /\ a < n); // For some reason, this makes the proof instant. () /////////////////////////////////////////////// let bn_field_get_len #t k = k.len let bn_field_check_modulus #t #len n = let m = BM.bn_check_modulus n in BB.unsafe_bool_of_limb m
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "Lib.Sequence.fsti.checked", "Lib.NatMod.fsti.checked", "Lib.IntTypes.fsti.checked", "Hacl.Spec.Montgomery.Lemmas.fst.checked", "Hacl.Spec.Exponentiation.Lemmas.fst.checked", "Hacl.Spec.Bignum.Montgomery.fsti.checked", "Hacl.Spec.Bignum.MontExponentiation.fst.checked", "Hacl.Spec.Bignum.ModInvLimb.fsti.checked", "Hacl.Spec.Bignum.ModInv.fst.checked", "Hacl.Spec.Bignum.Lib.fst.checked", "Hacl.Spec.Bignum.Definitions.fst.checked", "Hacl.Spec.Bignum.Base.fst.checked", "Hacl.Spec.Bignum.fsti.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.Math.Fermat.fsti.checked", "FStar.Math.Euclid.fsti.checked" ], "interface_file": true, "source_file": "Hacl.Spec.Bignum.MontArithmetic.fst" }
[ { "abbrev": true, "full_module": "Hacl.Spec.Bignum.ModInv", "short_module": "BI" }, { "abbrev": true, "full_module": "Hacl.Spec.Bignum.MontExponentiation", "short_module": "ME" }, { "abbrev": true, "full_module": "Hacl.Spec.Exponentiation.Lemmas", "short_module": "E" }, { "abbrev": true, "full_module": "Hacl.Spec.Bignum.ModInvLimb", "short_module": "BIL" }, { "abbrev": true, "full_module": "Hacl.Spec.Bignum.Lib", "short_module": "BL" }, { "abbrev": true, "full_module": "Hacl.Spec.Bignum.Base", "short_module": "BB" }, { "abbrev": true, "full_module": "Hacl.Spec.Bignum.Montgomery", "short_module": "BM" }, { "abbrev": true, "full_module": "Hacl.Spec.Bignum", "short_module": "BN" }, { "abbrev": true, "full_module": "Hacl.Spec.Montgomery.Lemmas", "short_module": "M" }, { "abbrev": true, "full_module": "FStar.Math.Euclid", "short_module": "Euclid" }, { "abbrev": false, "full_module": "Hacl.Spec.Bignum.Definitions", "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.Bignum", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.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 } ]
{ "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" }
false
n: Hacl.Spec.Bignum.Definitions.lbignum t len -> Prims.Pure (Hacl.Spec.Bignum.MontArithmetic.bn_mont_ctx t)
Prims.Pure
[]
[]
[ "Hacl.Spec.Bignum.Definitions.limb_t", "Hacl.Spec.Bignum.bn_len", "Hacl.Spec.Bignum.Definitions.lbignum", "Hacl.Spec.Bignum.MontArithmetic.Mkbn_mont_ctx", "Prims.unit", "Hacl.Spec.Bignum.Definitions.bn_eval_bound", "Prims._assert", "Prims.eq2", "Prims.int", "Prims.op_Modulus", "Prims.op_Addition", "FStar.Mul.op_Star", "Hacl.Spec.Bignum.Definitions.bn_v", "Lib.IntTypes.v", "Lib.IntTypes.SEC", "Prims.pow2", "Lib.IntTypes.bits", "Hacl.Spec.Bignum.ModInvLimb.bn_mod_inv_limb_lemma", "Hacl.Spec.Bignum.Definitions.limb", "Hacl.Spec.Bignum.ModInvLimb.mod_inv_limb", "Lib.Sequence.op_String_Access", "Hacl.Spec.Bignum.Montgomery.bn_precomp_r2_mod_n", "Hacl.Spec.Bignum.Montgomery.bn_precomp_r2_mod_n_lemma", "Hacl.Spec.Bignum.Lib.bn_low_bound_bits_lemma", "Hacl.Spec.Bignum.Lib.bn_get_top_index", "Hacl.Spec.Bignum.MontArithmetic.bn_mont_ctx" ]
[]
false
false
false
false
false
let bn_field_init #t #len n =
let nBits = bits t * BL.bn_get_top_index n in BL.bn_low_bound_bits_lemma n; BM.bn_precomp_r2_mod_n_lemma nBits n; let r2 = BM.bn_precomp_r2_mod_n nBits n in assert (bn_v r2 == pow2 ((2 * bits t) * len) % bn_v n); let mu = BIL.mod_inv_limb n.[ 0 ] in BIL.bn_mod_inv_limb_lemma n; assert ((1 + bn_v n * v mu) % pow2 (bits t) == 0); bn_eval_bound n len; { len = len; n = n; mu = mu; r2 = r2 }
false
Vale.AsLowStar.Test.fst
Vale.AsLowStar.Test.lowstar_aesni
val lowstar_aesni:lowstar_aesni_t
val lowstar_aesni:lowstar_aesni_t
let lowstar_aesni : lowstar_aesni_t = IX64.wrap_weak_stdcall (coerce code_aesni) aesni_dom (W.mk_prediction code_aesni aesni_dom [] (aesni_lemma code_aesni IA.win))
{ "file_name": "vale/code/arch/x64/interop/Vale.AsLowStar.Test.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 77, "end_line": 252, "start_col": 0, "start_line": 248 }
module Vale.AsLowStar.Test open FStar.Mul open Vale.Interop.Base module ME = Vale.X64.Memory module IA = Vale.Interop.Assumptions module V = Vale.X64.Decls module IX64 = Vale.Interop.X64 module VSig = Vale.AsLowStar.ValeSig module LSig = Vale.AsLowStar.LowStarSig module W = Vale.AsLowStar.Wrapper module VS = Vale.X64.State module MS = Vale.X64.Machine_s (* A little utility to trigger normalization in types *) let as_t (#a:Type) (x:normal a) : a = x let as_normal_t (#a:Type) (x:a) : normal a = x //////////////////////////////////////////////////////////////////////////////// //First a little standalone, toy experiment [@__reduce__] let b64 = buf_t TUInt8 TUInt64 [@__reduce__] let ib64 = ibuf_t TUInt8 TUInt64 [@__reduce__] let t64_mod = TD_Buffer TUInt8 TUInt64 default_bq [@__reduce__] let t64_no_mod = TD_Buffer TUInt8 TUInt64 ({modified=false; strict_disjointness=false; taint=MS.Secret}) [@__reduce__] let t64_imm = TD_ImmBuffer TUInt8 TUInt64 ({modified=false; strict_disjointness=false; taint=MS.Secret}) [@__reduce__] let (dom : list td{List.length dom <= 20}) = let y = [t64_mod;t64_imm] in assert_norm (List.length y = 2); y assume val pre : VSig.vale_pre dom assume val post : VSig.vale_post dom assume val v: VSig.vale_sig_stdcall pre post assume val c: V.va_code [@__reduce__] let call_c_t = IX64.as_lowstar_sig_t_weak_stdcall c dom [] _ _ (W.mk_prediction c dom [] (v c IA.win)) let call_c : call_c_t = IX64.wrap_weak_stdcall c dom (W.mk_prediction c dom [] (v c IA.win)) let call_c_normal_t : normal call_c_t = as_normal_t #call_c_t call_c //You can ask emacs to show you the type of call_c_normal_t ... //////////////////////////////////////////////////////////////////////////////// //Now memcpy module VM = Vale.Test.X64.Vale_memcpy [@__reduce__] let vm_dom = [t64_mod; t64_imm] open Vale.X64.MemoryAdapters (* Need to rearrange the order of arguments *) [@__reduce__] let vm_pre : VSig.vale_pre vm_dom = fun (c:V.va_code) (dst:b64) (src:ib64) (va_s0:V.va_state) -> VM.va_req_Memcpy c va_s0 IA.win (as_vale_buffer dst) (as_vale_immbuffer src) [@__reduce__] let vm_post : VSig.vale_post vm_dom = fun (c:V.va_code) (dst:b64) (src:ib64) (va_s0:V.va_state) (va_s1:V.va_state) (f:V.va_fuel) -> VM.va_ens_Memcpy c va_s0 IA.win (as_vale_buffer dst) (as_vale_immbuffer src) va_s1 f module VS = Vale.X64.State #reset-options "--print_effect_args --z3rlimit 200" (* The vale lemma doesn't quite suffice to prove the modifies clause expected of the interop layer *) [@__reduce__] let vm_lemma' (code:V.va_code) (_win:bool) (dst:b64) (src:ib64) (va_s0:V.va_state) : Ghost (V.va_state & V.va_fuel) (requires vm_pre code dst src va_s0) (ensures (fun (va_s1, f) -> V.eval_code code va_s0 f va_s1 /\ VSig.vale_calling_conventions_stdcall va_s0 va_s1 /\ vm_post code dst src va_s0 va_s1 f /\ ME.buffer_readable (VS.vs_get_vale_heap va_s1) (as_vale_immbuffer src) /\ ME.buffer_readable (VS.vs_get_vale_heap va_s1) (as_vale_buffer dst) /\ ME.buffer_writeable (as_vale_buffer dst) /\ ME.modifies (ME.loc_union (ME.loc_buffer (as_vale_buffer dst)) ME.loc_none) (VS.vs_get_vale_heap va_s0) (VS.vs_get_vale_heap va_s1) )) = let va_s1, f = VM.va_lemma_Memcpy code va_s0 IA.win (as_vale_buffer dst) (as_vale_immbuffer src) in Vale.AsLowStar.MemoryHelpers.buffer_writeable_reveal ME.TUInt8 ME.TUInt64 dst; (va_s1, f) (* Prove that vm_lemma' has the required type *) let vm_lemma = as_t #(VSig.vale_sig_stdcall vm_pre vm_post) vm_lemma' let code_Memcpy = VM.va_code_Memcpy IA.win (* Here's the type expected for the memcpy wrapper *) [@__reduce__] let lowstar_Memcpy_t = IX64.as_lowstar_sig_t_weak_stdcall code_Memcpy vm_dom [] _ _ (W.mk_prediction code_Memcpy vm_dom [] (vm_lemma code_Memcpy IA.win)) (* And here's the memcpy wrapper itself *) let lowstar_Memcpy : lowstar_Memcpy_t = IX64.wrap_weak_stdcall code_Memcpy vm_dom (W.mk_prediction code_Memcpy vm_dom [] (vm_lemma code_Memcpy IA.win)) let lowstar_Memcpy_normal_t //: normal lowstar_Memcpy_t = as_normal_t #lowstar_Memcpy_t lowstar_Memcpy module B = LowStar.Buffer module IB = LowStar.ImmutableBuffer module MB = LowStar.Monotonic.Buffer open FStar.HyperStack.ST module M = Vale.X64.Memory let test (x:b64) = assert (V.buffer_length (as_vale_buffer x) == (B.length x * view_n TUInt8) / view_n TUInt64); assert (V.buffer_length (as_vale_buffer x) == B.length x / 8) let itest (x:ib64) = assert (V.buffer_length (as_vale_immbuffer x) == (B.length x * view_n TUInt8) / view_n TUInt64); assert (V.buffer_length (as_vale_immbuffer x) == B.length x / 8) module T = FStar.Tactics #reset-options "--using_facts_from '* -FStar.Tactics -FStar.Reflection'" module LBV = LowStar.BufferView.Up module DV = LowStar.BufferView.Down #push-options "--ext compat:normalizer_memo_ignore_cfg" let memcpy_Test (dst:B.buffer UInt8.t{B.length dst % 8 == 0}) (src:IB.ibuffer UInt8.t{B.length src % 8 == 0}) : Stack UInt64.t (requires fun h0 -> B.live h0 dst /\ B.live h0 src /\ B.disjoint dst src /\ B.length dst == 16 /\ B.length src == 16) (ensures fun h0 _ h1 -> B.modifies (B.loc_buffer dst) h0 h1 /\ B.live h1 src /\ B.live h1 dst) // B.as_seq h1 dst == B.as_seq h1 src) // by (T.dump "A") (* in case you want to look at the VC *) = IB.inhabited_immutable_buffer_is_distinct_from_buffer (UInt8.uint_to_t 0) src dst; let (x, _) = lowstar_Memcpy_normal_t dst src () in //This is a call to the interop wrapper let h1 = get () in // let v = Vale.Interop.Views.up_view64 in // assert (DV.length_eq (get_downview dst); // DV.length_eq (get_downview src); // Seq.equal (LBV.as_seq h1 (LBV.mk_buffer (get_downview dst) v)) // (LBV.as_seq h1 (LBV.mk_buffer (get_downview src) v))); // lbv_as_seq_eq dst src Vale.Interop.Views.up_view64 h1; //And a lemma to rephrase the Vale postcondition x //with equalities of buffer views //back to equalities of buffers #pop-options module VC = Vale.Lib.X64.Cpuidstdcall [@__reduce__] let empty_list #a : l:list a {List.length l = 0} = [] [@__reduce__] let aesni_dom : IX64.arity_ok_stdcall td = [] (* Need to rearrange the order of arguments *) [@__reduce__] let aesni_pre : VSig.vale_pre aesni_dom = fun (c:V.va_code) (va_s0:V.va_state) -> VC.va_req_Check_aesni_stdcall c va_s0 IA.win [@__reduce__] let aesni_post : VSig.vale_post aesni_dom = fun (c:V.va_code) (va_s0:V.va_state) (va_s1:V.va_state) (f:V.va_fuel) -> VC.va_ens_Check_aesni_stdcall c va_s0 IA.win va_s1 f [@__reduce__] let with_len (l:list 'a) : Pure (list 'a) (requires True) (ensures fun m -> m==l /\ List.length m == normalize_term (List.length l)) = l #set-options "--max_fuel 0 --max_ifuel 1 --z3rlimit_factor 2" (* The vale lemma doesn't quite suffice to prove the modifies clause expected of the interop layer *) [@__reduce__] let aesni_lemma' (code:V.va_code) (_win:bool) (va_s0:V.va_state) : Ghost (V.va_state & V.va_fuel) (requires aesni_pre code va_s0) (ensures (fun (va_s1, f) -> V.eval_code code va_s0 f va_s1 /\ VSig.vale_calling_conventions_stdcall va_s0 va_s1 /\ aesni_post code va_s0 va_s1 f)) = VC.va_lemma_Check_aesni_stdcall code va_s0 IA.win #set-options "--max_fuel 0 --max_ifuel 0 --z3rlimit_factor 2" (* Prove that vm_lemma' has the required type *) let aesni_lemma = as_t #(VSig.vale_sig_stdcall aesni_pre aesni_post) aesni_lemma' let code_aesni = VC.va_code_Check_aesni_stdcall IA.win (* Here's the type expected for the check_aesni wrapper *) [@__reduce__] let lowstar_aesni_t = IX64.as_lowstar_sig_t_weak_stdcall (coerce code_aesni) aesni_dom empty_list _ _ (W.mk_prediction code_aesni aesni_dom [] (aesni_lemma code_aesni IA.win))
{ "checked_file": "/", "dependencies": [ "Vale.X64.State.fsti.checked", "Vale.X64.MemoryAdapters.fsti.checked", "Vale.X64.Memory.fsti.checked", "Vale.X64.Machine_s.fst.checked", "Vale.X64.Decls.fsti.checked", "Vale.X64.CPU_Features_s.fst.checked", "Vale.Test.X64.Vale_memcpy.fsti.checked", "Vale.Test.X64.Args.fsti.checked", "Vale.Lib.X64.Cpuidstdcall.fsti.checked", "Vale.Interop.X64.fsti.checked", "Vale.Interop.Base.fst.checked", "Vale.Interop.Assumptions.fst.checked", "Vale.AsLowStar.Wrapper.fsti.checked", "Vale.AsLowStar.ValeSig.fst.checked", "Vale.AsLowStar.MemoryHelpers.fsti.checked", "Vale.AsLowStar.LowStarSig.fst.checked", "prims.fst.checked", "LowStar.Monotonic.Buffer.fsti.checked", "LowStar.ImmutableBuffer.fst.checked", "LowStar.BufferView.Up.fsti.checked", "LowStar.BufferView.Down.fsti.checked", "LowStar.Buffer.fst.checked", "FStar.UInt8.fsti.checked", "FStar.UInt64.fsti.checked", "FStar.Tactics.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.List.fst.checked", "FStar.HyperStack.ST.fsti.checked" ], "interface_file": false, "source_file": "Vale.AsLowStar.Test.fst" }
[ { "abbrev": true, "full_module": "Vale.Lib.X64.Cpuidstdcall", "short_module": "VC" }, { "abbrev": true, "full_module": "LowStar.BufferView.Down", "short_module": "DV" }, { "abbrev": true, "full_module": "LowStar.BufferView.Up", "short_module": "LBV" }, { "abbrev": true, "full_module": "FStar.Tactics", "short_module": "T" }, { "abbrev": true, "full_module": "Vale.X64.Memory", "short_module": "M" }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": true, "full_module": "LowStar.Monotonic.Buffer", "short_module": "MB" }, { "abbrev": true, "full_module": "LowStar.ImmutableBuffer", "short_module": "IB" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "Vale.X64.State", "short_module": "VS" }, { "abbrev": false, "full_module": "Vale.X64.MemoryAdapters", "short_module": null }, { "abbrev": true, "full_module": "Vale.Test.X64.Vale_memcpy", "short_module": "VM" }, { "abbrev": true, "full_module": "Vale.X64.Machine_s", "short_module": "MS" }, { "abbrev": true, "full_module": "Vale.X64.State", "short_module": "VS" }, { "abbrev": true, "full_module": "Vale.AsLowStar.Wrapper", "short_module": "W" }, { "abbrev": true, "full_module": "Vale.AsLowStar.LowStarSig", "short_module": "LSig" }, { "abbrev": true, "full_module": "Vale.AsLowStar.ValeSig", "short_module": "VSig" }, { "abbrev": true, "full_module": "Vale.Interop.X64", "short_module": "IX64" }, { "abbrev": true, "full_module": "Vale.X64.Decls", "short_module": "V" }, { "abbrev": true, "full_module": "Vale.Interop.Assumptions", "short_module": "IA" }, { "abbrev": true, "full_module": "Vale.X64.Memory", "short_module": "ME" }, { "abbrev": false, "full_module": "Vale.Interop.Base", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.AsLowStar", "short_module": null }, { "abbrev": false, "full_module": "Vale.AsLowStar", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 0, "max_fuel": 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": true, "smtencoding_l_arith_repr": "native", "smtencoding_nl_arith_repr": "wrapped", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [ "smt.arith.nl=false", "smt.QI.EAGER_THRESHOLD=100", "smt.CASE_SPLIT=3" ], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 2, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
Vale.AsLowStar.Test.lowstar_aesni_t
Prims.Tot
[ "total" ]
[]
[ "Vale.Interop.X64.wrap_weak_stdcall", "Vale.X64.MemoryAdapters.coerce", "Vale.X64.Machine_Semantics_s.code", "Vale.X64.Decls.va_code", "Vale.AsLowStar.Test.code_aesni", "Vale.AsLowStar.Test.aesni_dom", "Vale.AsLowStar.Wrapper.pre_rel_generic", "Vale.Interop.X64.max_stdcall", "Vale.Interop.X64.arg_reg_stdcall", "Prims.Nil", "Vale.Interop.Base.arg", "Vale.AsLowStar.Test.aesni_pre", "Vale.AsLowStar.Wrapper.post_rel_generic", "Vale.AsLowStar.Test.aesni_post", "Vale.AsLowStar.Wrapper.mk_prediction", "Vale.Interop.X64.regs_modified_stdcall", "Vale.Interop.X64.xmms_modified_stdcall", "Vale.AsLowStar.Test.aesni_lemma", "Vale.Interop.Assumptions.win" ]
[]
false
false
false
true
false
let lowstar_aesni:lowstar_aesni_t =
IX64.wrap_weak_stdcall (coerce code_aesni) aesni_dom (W.mk_prediction code_aesni aesni_dom [] (aesni_lemma code_aesni IA.win))
false
Vale.AsLowStar.Test.fst
Vale.AsLowStar.Test.ta_dom
val ta_dom:ta_dom: list td {List.length ta_dom <= 20}
val ta_dom:ta_dom: list td {List.length ta_dom <= 20}
let (ta_dom:list td{List.length ta_dom <= 20}) = let y = [t64_imm; t64_imm; t64_imm; t64_imm; t64_imm; t64_imm; t64_imm; t64_imm] in assert_norm (List.length y = 8); y
{ "file_name": "vale/code/arch/x64/interop/Vale.AsLowStar.Test.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 3, "end_line": 277, "start_col": 0, "start_line": 274 }
module Vale.AsLowStar.Test open FStar.Mul open Vale.Interop.Base module ME = Vale.X64.Memory module IA = Vale.Interop.Assumptions module V = Vale.X64.Decls module IX64 = Vale.Interop.X64 module VSig = Vale.AsLowStar.ValeSig module LSig = Vale.AsLowStar.LowStarSig module W = Vale.AsLowStar.Wrapper module VS = Vale.X64.State module MS = Vale.X64.Machine_s (* A little utility to trigger normalization in types *) let as_t (#a:Type) (x:normal a) : a = x let as_normal_t (#a:Type) (x:a) : normal a = x //////////////////////////////////////////////////////////////////////////////// //First a little standalone, toy experiment [@__reduce__] let b64 = buf_t TUInt8 TUInt64 [@__reduce__] let ib64 = ibuf_t TUInt8 TUInt64 [@__reduce__] let t64_mod = TD_Buffer TUInt8 TUInt64 default_bq [@__reduce__] let t64_no_mod = TD_Buffer TUInt8 TUInt64 ({modified=false; strict_disjointness=false; taint=MS.Secret}) [@__reduce__] let t64_imm = TD_ImmBuffer TUInt8 TUInt64 ({modified=false; strict_disjointness=false; taint=MS.Secret}) [@__reduce__] let (dom : list td{List.length dom <= 20}) = let y = [t64_mod;t64_imm] in assert_norm (List.length y = 2); y assume val pre : VSig.vale_pre dom assume val post : VSig.vale_post dom assume val v: VSig.vale_sig_stdcall pre post assume val c: V.va_code [@__reduce__] let call_c_t = IX64.as_lowstar_sig_t_weak_stdcall c dom [] _ _ (W.mk_prediction c dom [] (v c IA.win)) let call_c : call_c_t = IX64.wrap_weak_stdcall c dom (W.mk_prediction c dom [] (v c IA.win)) let call_c_normal_t : normal call_c_t = as_normal_t #call_c_t call_c //You can ask emacs to show you the type of call_c_normal_t ... //////////////////////////////////////////////////////////////////////////////// //Now memcpy module VM = Vale.Test.X64.Vale_memcpy [@__reduce__] let vm_dom = [t64_mod; t64_imm] open Vale.X64.MemoryAdapters (* Need to rearrange the order of arguments *) [@__reduce__] let vm_pre : VSig.vale_pre vm_dom = fun (c:V.va_code) (dst:b64) (src:ib64) (va_s0:V.va_state) -> VM.va_req_Memcpy c va_s0 IA.win (as_vale_buffer dst) (as_vale_immbuffer src) [@__reduce__] let vm_post : VSig.vale_post vm_dom = fun (c:V.va_code) (dst:b64) (src:ib64) (va_s0:V.va_state) (va_s1:V.va_state) (f:V.va_fuel) -> VM.va_ens_Memcpy c va_s0 IA.win (as_vale_buffer dst) (as_vale_immbuffer src) va_s1 f module VS = Vale.X64.State #reset-options "--print_effect_args --z3rlimit 200" (* The vale lemma doesn't quite suffice to prove the modifies clause expected of the interop layer *) [@__reduce__] let vm_lemma' (code:V.va_code) (_win:bool) (dst:b64) (src:ib64) (va_s0:V.va_state) : Ghost (V.va_state & V.va_fuel) (requires vm_pre code dst src va_s0) (ensures (fun (va_s1, f) -> V.eval_code code va_s0 f va_s1 /\ VSig.vale_calling_conventions_stdcall va_s0 va_s1 /\ vm_post code dst src va_s0 va_s1 f /\ ME.buffer_readable (VS.vs_get_vale_heap va_s1) (as_vale_immbuffer src) /\ ME.buffer_readable (VS.vs_get_vale_heap va_s1) (as_vale_buffer dst) /\ ME.buffer_writeable (as_vale_buffer dst) /\ ME.modifies (ME.loc_union (ME.loc_buffer (as_vale_buffer dst)) ME.loc_none) (VS.vs_get_vale_heap va_s0) (VS.vs_get_vale_heap va_s1) )) = let va_s1, f = VM.va_lemma_Memcpy code va_s0 IA.win (as_vale_buffer dst) (as_vale_immbuffer src) in Vale.AsLowStar.MemoryHelpers.buffer_writeable_reveal ME.TUInt8 ME.TUInt64 dst; (va_s1, f) (* Prove that vm_lemma' has the required type *) let vm_lemma = as_t #(VSig.vale_sig_stdcall vm_pre vm_post) vm_lemma' let code_Memcpy = VM.va_code_Memcpy IA.win (* Here's the type expected for the memcpy wrapper *) [@__reduce__] let lowstar_Memcpy_t = IX64.as_lowstar_sig_t_weak_stdcall code_Memcpy vm_dom [] _ _ (W.mk_prediction code_Memcpy vm_dom [] (vm_lemma code_Memcpy IA.win)) (* And here's the memcpy wrapper itself *) let lowstar_Memcpy : lowstar_Memcpy_t = IX64.wrap_weak_stdcall code_Memcpy vm_dom (W.mk_prediction code_Memcpy vm_dom [] (vm_lemma code_Memcpy IA.win)) let lowstar_Memcpy_normal_t //: normal lowstar_Memcpy_t = as_normal_t #lowstar_Memcpy_t lowstar_Memcpy module B = LowStar.Buffer module IB = LowStar.ImmutableBuffer module MB = LowStar.Monotonic.Buffer open FStar.HyperStack.ST module M = Vale.X64.Memory let test (x:b64) = assert (V.buffer_length (as_vale_buffer x) == (B.length x * view_n TUInt8) / view_n TUInt64); assert (V.buffer_length (as_vale_buffer x) == B.length x / 8) let itest (x:ib64) = assert (V.buffer_length (as_vale_immbuffer x) == (B.length x * view_n TUInt8) / view_n TUInt64); assert (V.buffer_length (as_vale_immbuffer x) == B.length x / 8) module T = FStar.Tactics #reset-options "--using_facts_from '* -FStar.Tactics -FStar.Reflection'" module LBV = LowStar.BufferView.Up module DV = LowStar.BufferView.Down #push-options "--ext compat:normalizer_memo_ignore_cfg" let memcpy_Test (dst:B.buffer UInt8.t{B.length dst % 8 == 0}) (src:IB.ibuffer UInt8.t{B.length src % 8 == 0}) : Stack UInt64.t (requires fun h0 -> B.live h0 dst /\ B.live h0 src /\ B.disjoint dst src /\ B.length dst == 16 /\ B.length src == 16) (ensures fun h0 _ h1 -> B.modifies (B.loc_buffer dst) h0 h1 /\ B.live h1 src /\ B.live h1 dst) // B.as_seq h1 dst == B.as_seq h1 src) // by (T.dump "A") (* in case you want to look at the VC *) = IB.inhabited_immutable_buffer_is_distinct_from_buffer (UInt8.uint_to_t 0) src dst; let (x, _) = lowstar_Memcpy_normal_t dst src () in //This is a call to the interop wrapper let h1 = get () in // let v = Vale.Interop.Views.up_view64 in // assert (DV.length_eq (get_downview dst); // DV.length_eq (get_downview src); // Seq.equal (LBV.as_seq h1 (LBV.mk_buffer (get_downview dst) v)) // (LBV.as_seq h1 (LBV.mk_buffer (get_downview src) v))); // lbv_as_seq_eq dst src Vale.Interop.Views.up_view64 h1; //And a lemma to rephrase the Vale postcondition x //with equalities of buffer views //back to equalities of buffers #pop-options module VC = Vale.Lib.X64.Cpuidstdcall [@__reduce__] let empty_list #a : l:list a {List.length l = 0} = [] [@__reduce__] let aesni_dom : IX64.arity_ok_stdcall td = [] (* Need to rearrange the order of arguments *) [@__reduce__] let aesni_pre : VSig.vale_pre aesni_dom = fun (c:V.va_code) (va_s0:V.va_state) -> VC.va_req_Check_aesni_stdcall c va_s0 IA.win [@__reduce__] let aesni_post : VSig.vale_post aesni_dom = fun (c:V.va_code) (va_s0:V.va_state) (va_s1:V.va_state) (f:V.va_fuel) -> VC.va_ens_Check_aesni_stdcall c va_s0 IA.win va_s1 f [@__reduce__] let with_len (l:list 'a) : Pure (list 'a) (requires True) (ensures fun m -> m==l /\ List.length m == normalize_term (List.length l)) = l #set-options "--max_fuel 0 --max_ifuel 1 --z3rlimit_factor 2" (* The vale lemma doesn't quite suffice to prove the modifies clause expected of the interop layer *) [@__reduce__] let aesni_lemma' (code:V.va_code) (_win:bool) (va_s0:V.va_state) : Ghost (V.va_state & V.va_fuel) (requires aesni_pre code va_s0) (ensures (fun (va_s1, f) -> V.eval_code code va_s0 f va_s1 /\ VSig.vale_calling_conventions_stdcall va_s0 va_s1 /\ aesni_post code va_s0 va_s1 f)) = VC.va_lemma_Check_aesni_stdcall code va_s0 IA.win #set-options "--max_fuel 0 --max_ifuel 0 --z3rlimit_factor 2" (* Prove that vm_lemma' has the required type *) let aesni_lemma = as_t #(VSig.vale_sig_stdcall aesni_pre aesni_post) aesni_lemma' let code_aesni = VC.va_code_Check_aesni_stdcall IA.win (* Here's the type expected for the check_aesni wrapper *) [@__reduce__] let lowstar_aesni_t = IX64.as_lowstar_sig_t_weak_stdcall (coerce code_aesni) aesni_dom empty_list _ _ (W.mk_prediction code_aesni aesni_dom [] (aesni_lemma code_aesni IA.win)) (* And here's the check_aesni wrapper itself *) let lowstar_aesni : lowstar_aesni_t = IX64.wrap_weak_stdcall (coerce code_aesni) aesni_dom (W.mk_prediction code_aesni aesni_dom [] (aesni_lemma code_aesni IA.win)) let lowstar_aesni_normal_t //: normal lowstar_aesni_t = as_normal_t #lowstar_aesni_t lowstar_aesni open Vale.X64.CPU_Features_s #set-options "--print_full_names" let aesni_Test () : Stack UInt64.t (requires fun h0 -> True) (ensures fun h0 ret_val h1 -> (UInt64.v ret_val) =!= 0 ==> aesni_enabled /\ pclmulqdq_enabled) // by (T.dump "A") (* in case you want to look at the VC *) = let (x, _) = lowstar_aesni_normal_t () in //This is a call to the interop wrapper x module TA = Vale.Test.X64.Args
{ "checked_file": "/", "dependencies": [ "Vale.X64.State.fsti.checked", "Vale.X64.MemoryAdapters.fsti.checked", "Vale.X64.Memory.fsti.checked", "Vale.X64.Machine_s.fst.checked", "Vale.X64.Decls.fsti.checked", "Vale.X64.CPU_Features_s.fst.checked", "Vale.Test.X64.Vale_memcpy.fsti.checked", "Vale.Test.X64.Args.fsti.checked", "Vale.Lib.X64.Cpuidstdcall.fsti.checked", "Vale.Interop.X64.fsti.checked", "Vale.Interop.Base.fst.checked", "Vale.Interop.Assumptions.fst.checked", "Vale.AsLowStar.Wrapper.fsti.checked", "Vale.AsLowStar.ValeSig.fst.checked", "Vale.AsLowStar.MemoryHelpers.fsti.checked", "Vale.AsLowStar.LowStarSig.fst.checked", "prims.fst.checked", "LowStar.Monotonic.Buffer.fsti.checked", "LowStar.ImmutableBuffer.fst.checked", "LowStar.BufferView.Up.fsti.checked", "LowStar.BufferView.Down.fsti.checked", "LowStar.Buffer.fst.checked", "FStar.UInt8.fsti.checked", "FStar.UInt64.fsti.checked", "FStar.Tactics.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.List.fst.checked", "FStar.HyperStack.ST.fsti.checked" ], "interface_file": false, "source_file": "Vale.AsLowStar.Test.fst" }
[ { "abbrev": true, "full_module": "Vale.Test.X64.Args", "short_module": "TA" }, { "abbrev": false, "full_module": "Vale.X64.CPU_Features_s", "short_module": null }, { "abbrev": true, "full_module": "Vale.Lib.X64.Cpuidstdcall", "short_module": "VC" }, { "abbrev": true, "full_module": "LowStar.BufferView.Down", "short_module": "DV" }, { "abbrev": true, "full_module": "LowStar.BufferView.Up", "short_module": "LBV" }, { "abbrev": true, "full_module": "FStar.Tactics", "short_module": "T" }, { "abbrev": true, "full_module": "Vale.X64.Memory", "short_module": "M" }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": true, "full_module": "LowStar.Monotonic.Buffer", "short_module": "MB" }, { "abbrev": true, "full_module": "LowStar.ImmutableBuffer", "short_module": "IB" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "Vale.X64.State", "short_module": "VS" }, { "abbrev": false, "full_module": "Vale.X64.MemoryAdapters", "short_module": null }, { "abbrev": true, "full_module": "Vale.Test.X64.Vale_memcpy", "short_module": "VM" }, { "abbrev": true, "full_module": "Vale.X64.Machine_s", "short_module": "MS" }, { "abbrev": true, "full_module": "Vale.X64.State", "short_module": "VS" }, { "abbrev": true, "full_module": "Vale.AsLowStar.Wrapper", "short_module": "W" }, { "abbrev": true, "full_module": "Vale.AsLowStar.LowStarSig", "short_module": "LSig" }, { "abbrev": true, "full_module": "Vale.AsLowStar.ValeSig", "short_module": "VSig" }, { "abbrev": true, "full_module": "Vale.Interop.X64", "short_module": "IX64" }, { "abbrev": true, "full_module": "Vale.X64.Decls", "short_module": "V" }, { "abbrev": true, "full_module": "Vale.Interop.Assumptions", "short_module": "IA" }, { "abbrev": true, "full_module": "Vale.X64.Memory", "short_module": "ME" }, { "abbrev": false, "full_module": "Vale.Interop.Base", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.AsLowStar", "short_module": null }, { "abbrev": false, "full_module": "Vale.AsLowStar", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 0, "max_fuel": 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": true, "smtencoding_l_arith_repr": "native", "smtencoding_nl_arith_repr": "wrapped", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [ "smt.arith.nl=false", "smt.QI.EAGER_THRESHOLD=100", "smt.CASE_SPLIT=3" ], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 2, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
ta_dom: Prims.list Vale.Interop.Base.td {FStar.List.Tot.Base.length ta_dom <= 20}
Prims.Tot
[ "total" ]
[]
[ "Prims.unit", "FStar.Pervasives.assert_norm", "Prims.b2t", "Prims.op_Equality", "Prims.int", "FStar.List.Tot.Base.length", "Vale.Interop.Base.td", "Prims.list", "Prims.Cons", "Vale.AsLowStar.Test.t64_imm", "Prims.Nil" ]
[]
false
false
false
false
false
let ta_dom:ta_dom: list td {List.length ta_dom <= 20} =
let y = [t64_imm; t64_imm; t64_imm; t64_imm; t64_imm; t64_imm; t64_imm; t64_imm] in assert_norm (List.length y = 8); y
false
Hacl.Spec.Bignum.MontArithmetic.fst
Hacl.Spec.Bignum.MontArithmetic.mul_zero_lemma
val mul_zero_lemma: n:pos{Euclid.is_prime n} -> x:int -> y:int -> Lemma (x * y % n == 0 <==> (x % n == 0 \/ y % n == 0))
val mul_zero_lemma: n:pos{Euclid.is_prime n} -> x:int -> y:int -> Lemma (x * y % n == 0 <==> (x % n == 0 \/ y % n == 0))
let mul_zero_lemma n x y = assert (0 % n = 0); if x % n = 0 then Math.Lemmas.lemma_mod_mul_distr_l x y n else if y % n = 0 then Math.Lemmas.lemma_mod_mul_distr_r x y n else if x * y % n = 0 then Math.Fermat.mod_mult_congr n x 0 y else ()
{ "file_name": "code/bignum/Hacl.Spec.Bignum.MontArithmetic.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 13, "end_line": 39, "start_col": 0, "start_line": 29 }
module Hacl.Spec.Bignum.MontArithmetic open FStar.Mul open Lib.IntTypes open Lib.Sequence open Hacl.Spec.Bignum.Definitions module M = Hacl.Spec.Montgomery.Lemmas module BM = Hacl.Spec.Bignum.Montgomery module BN = Hacl.Spec.Bignum module BB = Hacl.Spec.Bignum.Base module BL = Hacl.Spec.Bignum.Lib module BIL = Hacl.Spec.Bignum.ModInvLimb module E = Hacl.Spec.Exponentiation.Lemmas module ME = Hacl.Spec.Bignum.MontExponentiation module Euclid = FStar.Math.Euclid module BI = Hacl.Spec.Bignum.ModInv #set-options "--z3rlimit 50 --fuel 0 --ifuel 0" ////////////////////////////////////////// val mul_zero_lemma: n:pos{Euclid.is_prime n} -> x:int -> y:int ->
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "Lib.Sequence.fsti.checked", "Lib.NatMod.fsti.checked", "Lib.IntTypes.fsti.checked", "Hacl.Spec.Montgomery.Lemmas.fst.checked", "Hacl.Spec.Exponentiation.Lemmas.fst.checked", "Hacl.Spec.Bignum.Montgomery.fsti.checked", "Hacl.Spec.Bignum.MontExponentiation.fst.checked", "Hacl.Spec.Bignum.ModInvLimb.fsti.checked", "Hacl.Spec.Bignum.ModInv.fst.checked", "Hacl.Spec.Bignum.Lib.fst.checked", "Hacl.Spec.Bignum.Definitions.fst.checked", "Hacl.Spec.Bignum.Base.fst.checked", "Hacl.Spec.Bignum.fsti.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.Math.Fermat.fsti.checked", "FStar.Math.Euclid.fsti.checked" ], "interface_file": true, "source_file": "Hacl.Spec.Bignum.MontArithmetic.fst" }
[ { "abbrev": true, "full_module": "Hacl.Spec.Bignum.ModInv", "short_module": "BI" }, { "abbrev": true, "full_module": "FStar.Math.Euclid", "short_module": "Euclid" }, { "abbrev": true, "full_module": "Hacl.Spec.Bignum.MontExponentiation", "short_module": "ME" }, { "abbrev": true, "full_module": "Hacl.Spec.Exponentiation.Lemmas", "short_module": "E" }, { "abbrev": true, "full_module": "Hacl.Spec.Bignum.ModInvLimb", "short_module": "BIL" }, { "abbrev": true, "full_module": "Hacl.Spec.Bignum.Lib", "short_module": "BL" }, { "abbrev": true, "full_module": "Hacl.Spec.Bignum.Base", "short_module": "BB" }, { "abbrev": true, "full_module": "Hacl.Spec.Bignum", "short_module": "BN" }, { "abbrev": true, "full_module": "Hacl.Spec.Bignum.Montgomery", "short_module": "BM" }, { "abbrev": true, "full_module": "Hacl.Spec.Montgomery.Lemmas", "short_module": "M" }, { "abbrev": false, "full_module": "Hacl.Spec.Bignum.Definitions", "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": true, "full_module": "Hacl.Spec.Bignum", "short_module": "BN" }, { "abbrev": true, "full_module": "Hacl.Spec.Montgomery.Lemmas", "short_module": "M" }, { "abbrev": true, "full_module": "FStar.Math.Euclid", "short_module": "Euclid" }, { "abbrev": false, "full_module": "Hacl.Spec.Bignum.Definitions", "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.Bignum", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.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 } ]
{ "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" }
false
n: Prims.pos{FStar.Math.Euclid.is_prime n} -> x: Prims.int -> y: Prims.int -> FStar.Pervasives.Lemma (ensures x * y % n == 0 <==> x % n == 0 \/ y % n == 0)
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "Prims.pos", "FStar.Math.Euclid.is_prime", "Prims.int", "Prims.op_Equality", "Prims.op_Modulus", "FStar.Math.Lemmas.lemma_mod_mul_distr_l", "Prims.bool", "FStar.Math.Lemmas.lemma_mod_mul_distr_r", "FStar.Mul.op_Star", "FStar.Math.Fermat.mod_mult_congr", "Prims.unit", "Prims._assert", "Prims.b2t" ]
[]
false
false
true
false
false
let mul_zero_lemma n x y =
assert (0 % n = 0); if x % n = 0 then Math.Lemmas.lemma_mod_mul_distr_l x y n else if y % n = 0 then Math.Lemmas.lemma_mod_mul_distr_r x y n else if x * y % n = 0 then Math.Fermat.mod_mult_congr n x 0 y
false
Vale.AsLowStar.Test.fst
Vale.AsLowStar.Test.test
val test : x: Vale.AsLowStar.Test.b64 -> Prims.unit
let test (x:b64) = assert (V.buffer_length (as_vale_buffer x) == (B.length x * view_n TUInt8) / view_n TUInt64); assert (V.buffer_length (as_vale_buffer x) == B.length x / 8)
{ "file_name": "vale/code/arch/x64/interop/Vale.AsLowStar.Test.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 63, "end_line": 142, "start_col": 0, "start_line": 140 }
module Vale.AsLowStar.Test open FStar.Mul open Vale.Interop.Base module ME = Vale.X64.Memory module IA = Vale.Interop.Assumptions module V = Vale.X64.Decls module IX64 = Vale.Interop.X64 module VSig = Vale.AsLowStar.ValeSig module LSig = Vale.AsLowStar.LowStarSig module W = Vale.AsLowStar.Wrapper module VS = Vale.X64.State module MS = Vale.X64.Machine_s (* A little utility to trigger normalization in types *) let as_t (#a:Type) (x:normal a) : a = x let as_normal_t (#a:Type) (x:a) : normal a = x //////////////////////////////////////////////////////////////////////////////// //First a little standalone, toy experiment [@__reduce__] let b64 = buf_t TUInt8 TUInt64 [@__reduce__] let ib64 = ibuf_t TUInt8 TUInt64 [@__reduce__] let t64_mod = TD_Buffer TUInt8 TUInt64 default_bq [@__reduce__] let t64_no_mod = TD_Buffer TUInt8 TUInt64 ({modified=false; strict_disjointness=false; taint=MS.Secret}) [@__reduce__] let t64_imm = TD_ImmBuffer TUInt8 TUInt64 ({modified=false; strict_disjointness=false; taint=MS.Secret}) [@__reduce__] let (dom : list td{List.length dom <= 20}) = let y = [t64_mod;t64_imm] in assert_norm (List.length y = 2); y assume val pre : VSig.vale_pre dom assume val post : VSig.vale_post dom assume val v: VSig.vale_sig_stdcall pre post assume val c: V.va_code [@__reduce__] let call_c_t = IX64.as_lowstar_sig_t_weak_stdcall c dom [] _ _ (W.mk_prediction c dom [] (v c IA.win)) let call_c : call_c_t = IX64.wrap_weak_stdcall c dom (W.mk_prediction c dom [] (v c IA.win)) let call_c_normal_t : normal call_c_t = as_normal_t #call_c_t call_c //You can ask emacs to show you the type of call_c_normal_t ... //////////////////////////////////////////////////////////////////////////////// //Now memcpy module VM = Vale.Test.X64.Vale_memcpy [@__reduce__] let vm_dom = [t64_mod; t64_imm] open Vale.X64.MemoryAdapters (* Need to rearrange the order of arguments *) [@__reduce__] let vm_pre : VSig.vale_pre vm_dom = fun (c:V.va_code) (dst:b64) (src:ib64) (va_s0:V.va_state) -> VM.va_req_Memcpy c va_s0 IA.win (as_vale_buffer dst) (as_vale_immbuffer src) [@__reduce__] let vm_post : VSig.vale_post vm_dom = fun (c:V.va_code) (dst:b64) (src:ib64) (va_s0:V.va_state) (va_s1:V.va_state) (f:V.va_fuel) -> VM.va_ens_Memcpy c va_s0 IA.win (as_vale_buffer dst) (as_vale_immbuffer src) va_s1 f module VS = Vale.X64.State #reset-options "--print_effect_args --z3rlimit 200" (* The vale lemma doesn't quite suffice to prove the modifies clause expected of the interop layer *) [@__reduce__] let vm_lemma' (code:V.va_code) (_win:bool) (dst:b64) (src:ib64) (va_s0:V.va_state) : Ghost (V.va_state & V.va_fuel) (requires vm_pre code dst src va_s0) (ensures (fun (va_s1, f) -> V.eval_code code va_s0 f va_s1 /\ VSig.vale_calling_conventions_stdcall va_s0 va_s1 /\ vm_post code dst src va_s0 va_s1 f /\ ME.buffer_readable (VS.vs_get_vale_heap va_s1) (as_vale_immbuffer src) /\ ME.buffer_readable (VS.vs_get_vale_heap va_s1) (as_vale_buffer dst) /\ ME.buffer_writeable (as_vale_buffer dst) /\ ME.modifies (ME.loc_union (ME.loc_buffer (as_vale_buffer dst)) ME.loc_none) (VS.vs_get_vale_heap va_s0) (VS.vs_get_vale_heap va_s1) )) = let va_s1, f = VM.va_lemma_Memcpy code va_s0 IA.win (as_vale_buffer dst) (as_vale_immbuffer src) in Vale.AsLowStar.MemoryHelpers.buffer_writeable_reveal ME.TUInt8 ME.TUInt64 dst; (va_s1, f) (* Prove that vm_lemma' has the required type *) let vm_lemma = as_t #(VSig.vale_sig_stdcall vm_pre vm_post) vm_lemma' let code_Memcpy = VM.va_code_Memcpy IA.win (* Here's the type expected for the memcpy wrapper *) [@__reduce__] let lowstar_Memcpy_t = IX64.as_lowstar_sig_t_weak_stdcall code_Memcpy vm_dom [] _ _ (W.mk_prediction code_Memcpy vm_dom [] (vm_lemma code_Memcpy IA.win)) (* And here's the memcpy wrapper itself *) let lowstar_Memcpy : lowstar_Memcpy_t = IX64.wrap_weak_stdcall code_Memcpy vm_dom (W.mk_prediction code_Memcpy vm_dom [] (vm_lemma code_Memcpy IA.win)) let lowstar_Memcpy_normal_t //: normal lowstar_Memcpy_t = as_normal_t #lowstar_Memcpy_t lowstar_Memcpy module B = LowStar.Buffer module IB = LowStar.ImmutableBuffer module MB = LowStar.Monotonic.Buffer open FStar.HyperStack.ST module M = Vale.X64.Memory
{ "checked_file": "/", "dependencies": [ "Vale.X64.State.fsti.checked", "Vale.X64.MemoryAdapters.fsti.checked", "Vale.X64.Memory.fsti.checked", "Vale.X64.Machine_s.fst.checked", "Vale.X64.Decls.fsti.checked", "Vale.X64.CPU_Features_s.fst.checked", "Vale.Test.X64.Vale_memcpy.fsti.checked", "Vale.Test.X64.Args.fsti.checked", "Vale.Lib.X64.Cpuidstdcall.fsti.checked", "Vale.Interop.X64.fsti.checked", "Vale.Interop.Base.fst.checked", "Vale.Interop.Assumptions.fst.checked", "Vale.AsLowStar.Wrapper.fsti.checked", "Vale.AsLowStar.ValeSig.fst.checked", "Vale.AsLowStar.MemoryHelpers.fsti.checked", "Vale.AsLowStar.LowStarSig.fst.checked", "prims.fst.checked", "LowStar.Monotonic.Buffer.fsti.checked", "LowStar.ImmutableBuffer.fst.checked", "LowStar.BufferView.Up.fsti.checked", "LowStar.BufferView.Down.fsti.checked", "LowStar.Buffer.fst.checked", "FStar.UInt8.fsti.checked", "FStar.UInt64.fsti.checked", "FStar.Tactics.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.List.fst.checked", "FStar.HyperStack.ST.fsti.checked" ], "interface_file": false, "source_file": "Vale.AsLowStar.Test.fst" }
[ { "abbrev": true, "full_module": "Vale.X64.Memory", "short_module": "M" }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": true, "full_module": "LowStar.Monotonic.Buffer", "short_module": "MB" }, { "abbrev": true, "full_module": "LowStar.ImmutableBuffer", "short_module": "IB" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "Vale.X64.State", "short_module": "VS" }, { "abbrev": false, "full_module": "Vale.X64.MemoryAdapters", "short_module": null }, { "abbrev": true, "full_module": "Vale.Test.X64.Vale_memcpy", "short_module": "VM" }, { "abbrev": true, "full_module": "Vale.X64.Machine_s", "short_module": "MS" }, { "abbrev": true, "full_module": "Vale.X64.State", "short_module": "VS" }, { "abbrev": true, "full_module": "Vale.AsLowStar.Wrapper", "short_module": "W" }, { "abbrev": true, "full_module": "Vale.AsLowStar.LowStarSig", "short_module": "LSig" }, { "abbrev": true, "full_module": "Vale.AsLowStar.ValeSig", "short_module": "VSig" }, { "abbrev": true, "full_module": "Vale.Interop.X64", "short_module": "IX64" }, { "abbrev": true, "full_module": "Vale.X64.Decls", "short_module": "V" }, { "abbrev": true, "full_module": "Vale.Interop.Assumptions", "short_module": "IA" }, { "abbrev": true, "full_module": "Vale.X64.Memory", "short_module": "ME" }, { "abbrev": false, "full_module": "Vale.Interop.Base", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.AsLowStar", "short_module": null }, { "abbrev": false, "full_module": "Vale.AsLowStar", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 0, "max_fuel": 1, "max_ifuel": 1, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": true, "smtencoding_l_arith_repr": "native", "smtencoding_nl_arith_repr": "wrapped", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [ "smt.arith.nl=false", "smt.QI.EAGER_THRESHOLD=100", "smt.CASE_SPLIT=3" ], "z3refresh": false, "z3rlimit": 200, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
x: Vale.AsLowStar.Test.b64 -> Prims.unit
Prims.Tot
[ "total" ]
[]
[ "Vale.AsLowStar.Test.b64", "Prims._assert", "Prims.eq2", "Prims.int", "Vale.X64.Decls.buffer_length", "Vale.Arch.HeapTypes_s.TUInt64", "Vale.X64.MemoryAdapters.as_vale_buffer", "Vale.Arch.HeapTypes_s.TUInt8", "Prims.op_Division", "LowStar.Monotonic.Buffer.length", "Vale.Interop.Types.base_typ_as_type", "LowStar.Buffer.trivial_preorder", "Prims.unit", "FStar.Mul.op_Star", "Vale.Interop.Types.view_n" ]
[]
false
false
false
true
false
let test (x: b64) =
assert (V.buffer_length (as_vale_buffer x) == (B.length x * view_n TUInt8) / view_n TUInt64); assert (V.buffer_length (as_vale_buffer x) == B.length x / 8)
false
Hacl.Spec.Bignum.MontArithmetic.fst
Hacl.Spec.Bignum.MontArithmetic.bn_from_to_field_lemma
val bn_from_to_field_lemma: #t:limb_t -> k:bn_mont_ctx t{bn_mont_ctx_inv k} -> a:lbignum t k.len -> Lemma (bn_v (bn_from_field k (bn_to_field k a)) == bn_v a % bn_v k.n)
val bn_from_to_field_lemma: #t:limb_t -> k:bn_mont_ctx t{bn_mont_ctx_inv k} -> a:lbignum t k.len -> Lemma (bn_v (bn_from_field k (bn_to_field k a)) == bn_v a % bn_v k.n)
let bn_from_to_field_lemma #t k a = bn_eval_bound a k.len; M.from_to_mont_lemma (bits t) k.len (bn_v k.n) (v k.mu) (bn_v a)
{ "file_name": "code/bignum/Hacl.Spec.Bignum.MontArithmetic.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 66, "end_line": 122, "start_col": 0, "start_line": 120 }
module Hacl.Spec.Bignum.MontArithmetic open FStar.Mul open Lib.IntTypes open Lib.Sequence open Hacl.Spec.Bignum.Definitions module M = Hacl.Spec.Montgomery.Lemmas module BM = Hacl.Spec.Bignum.Montgomery module BN = Hacl.Spec.Bignum module BB = Hacl.Spec.Bignum.Base module BL = Hacl.Spec.Bignum.Lib module BIL = Hacl.Spec.Bignum.ModInvLimb module E = Hacl.Spec.Exponentiation.Lemmas module ME = Hacl.Spec.Bignum.MontExponentiation module Euclid = FStar.Math.Euclid module BI = Hacl.Spec.Bignum.ModInv #set-options "--z3rlimit 50 --fuel 0 --ifuel 0" ////////////////////////////////////////// val mul_zero_lemma: n:pos{Euclid.is_prime n} -> x:int -> y:int -> Lemma (x * y % n == 0 <==> (x % n == 0 \/ y % n == 0)) let mul_zero_lemma n x y = assert (0 % n = 0); if x % n = 0 then Math.Lemmas.lemma_mod_mul_distr_l x y n else if y % n = 0 then Math.Lemmas.lemma_mod_mul_distr_r x y n else if x * y % n = 0 then Math.Fermat.mod_mult_congr n x 0 y else () val mul_nonzero_lemma: n:pos{Euclid.is_prime n} -> x:int -> y:int -> Lemma (requires x % n <> 0 /\ y % n <> 0) (ensures x * y % n <> 0) let mul_nonzero_lemma n x y = mul_zero_lemma n x y val from_mont_lemma_nonzero: pbits:pos -> rLen:pos -> n:pos -> mu:nat -> aM:nat -> Lemma (requires M.mont_pre pbits rLen n mu /\ 0 < aM /\ aM < n /\ Euclid.is_prime n) (ensures (let a = M.from_mont pbits rLen n mu aM in 0 < a /\ a < n)) let from_mont_lemma_nonzero pbits rLen n mu aM = let r = pow2 (pbits * rLen) in let d, _ = M.eea_pow2_odd (pbits * rLen) n in let a = M.from_mont pbits rLen n mu aM in M.from_mont_lemma pbits rLen n mu aM; assert (a == aM * d % n); assert (d <> 0); Math.Lemmas.small_mod aM n; assert (aM % n <> 0); let d1 = -d in assert (0 < d1 /\ d1 < n); Math.Lemmas.lemma_mod_sub_1 d1 n; assert ((-d1) % n == n - (d1 % n)); assert (d % n <> 0); mul_nonzero_lemma n aM d; assert (let a = M.from_mont pbits rLen n mu aM in 0 < a /\ a < n); // For some reason, this makes the proof instant. () /////////////////////////////////////////////// let bn_field_get_len #t k = k.len let bn_field_check_modulus #t #len n = let m = BM.bn_check_modulus n in BB.unsafe_bool_of_limb m let bn_field_init #t #len n = let nBits = bits t * BL.bn_get_top_index n in BL.bn_low_bound_bits_lemma n; BM.bn_precomp_r2_mod_n_lemma nBits n; let r2 = BM.bn_precomp_r2_mod_n nBits n in assert (bn_v r2 == pow2 (2 * bits t * len) % bn_v n); let mu = BIL.mod_inv_limb n.[0] in BIL.bn_mod_inv_limb_lemma n; assert ((1 + bn_v n * v mu) % pow2 (bits t) == 0); bn_eval_bound n len; { len = len; n = n; mu = mu; r2 = r2 } let bn_to_field #t k a = BM.bn_to_mont_lemma k.n k.mu k.r2 a; BM.bn_to_mont k.n k.mu k.r2 a let bn_from_field #t k aM = BM.bn_from_mont_lemma k.n k.mu aM; BM.bn_from_mont k.n k.mu aM
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "Lib.Sequence.fsti.checked", "Lib.NatMod.fsti.checked", "Lib.IntTypes.fsti.checked", "Hacl.Spec.Montgomery.Lemmas.fst.checked", "Hacl.Spec.Exponentiation.Lemmas.fst.checked", "Hacl.Spec.Bignum.Montgomery.fsti.checked", "Hacl.Spec.Bignum.MontExponentiation.fst.checked", "Hacl.Spec.Bignum.ModInvLimb.fsti.checked", "Hacl.Spec.Bignum.ModInv.fst.checked", "Hacl.Spec.Bignum.Lib.fst.checked", "Hacl.Spec.Bignum.Definitions.fst.checked", "Hacl.Spec.Bignum.Base.fst.checked", "Hacl.Spec.Bignum.fsti.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.Math.Fermat.fsti.checked", "FStar.Math.Euclid.fsti.checked" ], "interface_file": true, "source_file": "Hacl.Spec.Bignum.MontArithmetic.fst" }
[ { "abbrev": true, "full_module": "Hacl.Spec.Bignum.ModInv", "short_module": "BI" }, { "abbrev": true, "full_module": "Hacl.Spec.Bignum.MontExponentiation", "short_module": "ME" }, { "abbrev": true, "full_module": "Hacl.Spec.Exponentiation.Lemmas", "short_module": "E" }, { "abbrev": true, "full_module": "Hacl.Spec.Bignum.ModInvLimb", "short_module": "BIL" }, { "abbrev": true, "full_module": "Hacl.Spec.Bignum.Lib", "short_module": "BL" }, { "abbrev": true, "full_module": "Hacl.Spec.Bignum.Base", "short_module": "BB" }, { "abbrev": true, "full_module": "Hacl.Spec.Bignum.Montgomery", "short_module": "BM" }, { "abbrev": true, "full_module": "Hacl.Spec.Bignum", "short_module": "BN" }, { "abbrev": true, "full_module": "Hacl.Spec.Montgomery.Lemmas", "short_module": "M" }, { "abbrev": true, "full_module": "FStar.Math.Euclid", "short_module": "Euclid" }, { "abbrev": false, "full_module": "Hacl.Spec.Bignum.Definitions", "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.Bignum", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.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 } ]
{ "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" }
false
k: Hacl.Spec.Bignum.MontArithmetic.bn_mont_ctx t {Hacl.Spec.Bignum.MontArithmetic.bn_mont_ctx_inv k} -> a: Hacl.Spec.Bignum.Definitions.lbignum t (Mkbn_mont_ctx?.len k) -> FStar.Pervasives.Lemma (ensures Hacl.Spec.Bignum.Definitions.bn_v (Hacl.Spec.Bignum.MontArithmetic.bn_from_field k (Hacl.Spec.Bignum.MontArithmetic.bn_to_field k a)) == Hacl.Spec.Bignum.Definitions.bn_v a % Hacl.Spec.Bignum.Definitions.bn_v (Mkbn_mont_ctx?.n k))
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "Hacl.Spec.Bignum.Definitions.limb_t", "Hacl.Spec.Bignum.MontArithmetic.bn_mont_ctx", "Hacl.Spec.Bignum.MontArithmetic.bn_mont_ctx_inv", "Hacl.Spec.Bignum.Definitions.lbignum", "Hacl.Spec.Bignum.MontArithmetic.__proj__Mkbn_mont_ctx__item__len", "Hacl.Spec.Montgomery.Lemmas.from_to_mont_lemma", "Lib.IntTypes.bits", "Hacl.Spec.Bignum.Definitions.bn_v", "Hacl.Spec.Bignum.MontArithmetic.__proj__Mkbn_mont_ctx__item__n", "Lib.IntTypes.v", "Lib.IntTypes.SEC", "Hacl.Spec.Bignum.MontArithmetic.__proj__Mkbn_mont_ctx__item__mu", "Prims.unit", "Hacl.Spec.Bignum.Definitions.bn_eval_bound" ]
[]
true
false
true
false
false
let bn_from_to_field_lemma #t k a =
bn_eval_bound a k.len; M.from_to_mont_lemma (bits t) k.len (bn_v k.n) (v k.mu) (bn_v a)
false
Vale.AsLowStar.Test.fst
Vale.AsLowStar.Test.vm_lemma
val vm_lemma : Vale.AsLowStar.ValeSig.vale_sig_stdcall Vale.AsLowStar.Test.vm_pre Vale.AsLowStar.Test.vm_post
let vm_lemma = as_t #(VSig.vale_sig_stdcall vm_pre vm_post) vm_lemma'
{ "file_name": "vale/code/arch/x64/interop/Vale.AsLowStar.Test.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 69, "end_line": 108, "start_col": 0, "start_line": 108 }
module Vale.AsLowStar.Test open FStar.Mul open Vale.Interop.Base module ME = Vale.X64.Memory module IA = Vale.Interop.Assumptions module V = Vale.X64.Decls module IX64 = Vale.Interop.X64 module VSig = Vale.AsLowStar.ValeSig module LSig = Vale.AsLowStar.LowStarSig module W = Vale.AsLowStar.Wrapper module VS = Vale.X64.State module MS = Vale.X64.Machine_s (* A little utility to trigger normalization in types *) let as_t (#a:Type) (x:normal a) : a = x let as_normal_t (#a:Type) (x:a) : normal a = x //////////////////////////////////////////////////////////////////////////////// //First a little standalone, toy experiment [@__reduce__] let b64 = buf_t TUInt8 TUInt64 [@__reduce__] let ib64 = ibuf_t TUInt8 TUInt64 [@__reduce__] let t64_mod = TD_Buffer TUInt8 TUInt64 default_bq [@__reduce__] let t64_no_mod = TD_Buffer TUInt8 TUInt64 ({modified=false; strict_disjointness=false; taint=MS.Secret}) [@__reduce__] let t64_imm = TD_ImmBuffer TUInt8 TUInt64 ({modified=false; strict_disjointness=false; taint=MS.Secret}) [@__reduce__] let (dom : list td{List.length dom <= 20}) = let y = [t64_mod;t64_imm] in assert_norm (List.length y = 2); y assume val pre : VSig.vale_pre dom assume val post : VSig.vale_post dom assume val v: VSig.vale_sig_stdcall pre post assume val c: V.va_code [@__reduce__] let call_c_t = IX64.as_lowstar_sig_t_weak_stdcall c dom [] _ _ (W.mk_prediction c dom [] (v c IA.win)) let call_c : call_c_t = IX64.wrap_weak_stdcall c dom (W.mk_prediction c dom [] (v c IA.win)) let call_c_normal_t : normal call_c_t = as_normal_t #call_c_t call_c //You can ask emacs to show you the type of call_c_normal_t ... //////////////////////////////////////////////////////////////////////////////// //Now memcpy module VM = Vale.Test.X64.Vale_memcpy [@__reduce__] let vm_dom = [t64_mod; t64_imm] open Vale.X64.MemoryAdapters (* Need to rearrange the order of arguments *) [@__reduce__] let vm_pre : VSig.vale_pre vm_dom = fun (c:V.va_code) (dst:b64) (src:ib64) (va_s0:V.va_state) -> VM.va_req_Memcpy c va_s0 IA.win (as_vale_buffer dst) (as_vale_immbuffer src) [@__reduce__] let vm_post : VSig.vale_post vm_dom = fun (c:V.va_code) (dst:b64) (src:ib64) (va_s0:V.va_state) (va_s1:V.va_state) (f:V.va_fuel) -> VM.va_ens_Memcpy c va_s0 IA.win (as_vale_buffer dst) (as_vale_immbuffer src) va_s1 f module VS = Vale.X64.State #reset-options "--print_effect_args --z3rlimit 200" (* The vale lemma doesn't quite suffice to prove the modifies clause expected of the interop layer *) [@__reduce__] let vm_lemma' (code:V.va_code) (_win:bool) (dst:b64) (src:ib64) (va_s0:V.va_state) : Ghost (V.va_state & V.va_fuel) (requires vm_pre code dst src va_s0) (ensures (fun (va_s1, f) -> V.eval_code code va_s0 f va_s1 /\ VSig.vale_calling_conventions_stdcall va_s0 va_s1 /\ vm_post code dst src va_s0 va_s1 f /\ ME.buffer_readable (VS.vs_get_vale_heap va_s1) (as_vale_immbuffer src) /\ ME.buffer_readable (VS.vs_get_vale_heap va_s1) (as_vale_buffer dst) /\ ME.buffer_writeable (as_vale_buffer dst) /\ ME.modifies (ME.loc_union (ME.loc_buffer (as_vale_buffer dst)) ME.loc_none) (VS.vs_get_vale_heap va_s0) (VS.vs_get_vale_heap va_s1) )) = let va_s1, f = VM.va_lemma_Memcpy code va_s0 IA.win (as_vale_buffer dst) (as_vale_immbuffer src) in Vale.AsLowStar.MemoryHelpers.buffer_writeable_reveal ME.TUInt8 ME.TUInt64 dst; (va_s1, f)
{ "checked_file": "/", "dependencies": [ "Vale.X64.State.fsti.checked", "Vale.X64.MemoryAdapters.fsti.checked", "Vale.X64.Memory.fsti.checked", "Vale.X64.Machine_s.fst.checked", "Vale.X64.Decls.fsti.checked", "Vale.X64.CPU_Features_s.fst.checked", "Vale.Test.X64.Vale_memcpy.fsti.checked", "Vale.Test.X64.Args.fsti.checked", "Vale.Lib.X64.Cpuidstdcall.fsti.checked", "Vale.Interop.X64.fsti.checked", "Vale.Interop.Base.fst.checked", "Vale.Interop.Assumptions.fst.checked", "Vale.AsLowStar.Wrapper.fsti.checked", "Vale.AsLowStar.ValeSig.fst.checked", "Vale.AsLowStar.MemoryHelpers.fsti.checked", "Vale.AsLowStar.LowStarSig.fst.checked", "prims.fst.checked", "LowStar.Monotonic.Buffer.fsti.checked", "LowStar.ImmutableBuffer.fst.checked", "LowStar.BufferView.Up.fsti.checked", "LowStar.BufferView.Down.fsti.checked", "LowStar.Buffer.fst.checked", "FStar.UInt8.fsti.checked", "FStar.UInt64.fsti.checked", "FStar.Tactics.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.List.fst.checked", "FStar.HyperStack.ST.fsti.checked" ], "interface_file": false, "source_file": "Vale.AsLowStar.Test.fst" }
[ { "abbrev": true, "full_module": "Vale.X64.State", "short_module": "VS" }, { "abbrev": false, "full_module": "Vale.X64.MemoryAdapters", "short_module": null }, { "abbrev": true, "full_module": "Vale.Test.X64.Vale_memcpy", "short_module": "VM" }, { "abbrev": true, "full_module": "Vale.X64.Machine_s", "short_module": "MS" }, { "abbrev": true, "full_module": "Vale.X64.State", "short_module": "VS" }, { "abbrev": true, "full_module": "Vale.AsLowStar.Wrapper", "short_module": "W" }, { "abbrev": true, "full_module": "Vale.AsLowStar.LowStarSig", "short_module": "LSig" }, { "abbrev": true, "full_module": "Vale.AsLowStar.ValeSig", "short_module": "VSig" }, { "abbrev": true, "full_module": "Vale.Interop.X64", "short_module": "IX64" }, { "abbrev": true, "full_module": "Vale.X64.Decls", "short_module": "V" }, { "abbrev": true, "full_module": "Vale.Interop.Assumptions", "short_module": "IA" }, { "abbrev": true, "full_module": "Vale.X64.Memory", "short_module": "ME" }, { "abbrev": false, "full_module": "Vale.Interop.Base", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.AsLowStar", "short_module": null }, { "abbrev": false, "full_module": "Vale.AsLowStar", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 0, "max_fuel": 1, "max_ifuel": 1, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": true, "smtencoding_l_arith_repr": "native", "smtencoding_nl_arith_repr": "wrapped", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [ "smt.arith.nl=false", "smt.QI.EAGER_THRESHOLD=100", "smt.CASE_SPLIT=3" ], "z3refresh": false, "z3rlimit": 200, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
Vale.AsLowStar.ValeSig.vale_sig_stdcall Vale.AsLowStar.Test.vm_pre Vale.AsLowStar.Test.vm_post
Prims.Tot
[ "total" ]
[]
[ "Vale.AsLowStar.Test.as_t", "Vale.AsLowStar.ValeSig.vale_sig_stdcall", "Vale.AsLowStar.Test.vm_dom", "Vale.AsLowStar.Test.vm_pre", "Vale.AsLowStar.Test.vm_post", "Vale.AsLowStar.Test.vm_lemma'" ]
[]
false
false
false
true
false
let vm_lemma =
as_t #(VSig.vale_sig_stdcall vm_pre vm_post) vm_lemma'
false
Hacl.Spec.Bignum.MontArithmetic.fst
Hacl.Spec.Bignum.MontArithmetic.bn_field_one
val bn_field_one: #t:limb_t -> k:bn_mont_ctx t{bn_mont_ctx_inv k} -> Pure (bn_mont_nat k) (requires True) (ensures fun oneM -> bn_v (bn_from_field k oneM) == 1)
val bn_field_one: #t:limb_t -> k:bn_mont_ctx t{bn_mont_ctx_inv k} -> Pure (bn_mont_nat k) (requires True) (ensures fun oneM -> bn_v (bn_from_field k oneM) == 1)
let bn_field_one #t k = BM.bn_mont_one_lemma k.n k.mu k.r2; M.from_mont_one_lemma (bits t) k.len (bn_v k.n) (v k.mu); BM.bn_mont_one k.n k.mu r2
{ "file_name": "code/bignum/Hacl.Spec.Bignum.MontArithmetic.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 28, "end_line": 152, "start_col": 0, "start_line": 149 }
module Hacl.Spec.Bignum.MontArithmetic open FStar.Mul open Lib.IntTypes open Lib.Sequence open Hacl.Spec.Bignum.Definitions module M = Hacl.Spec.Montgomery.Lemmas module BM = Hacl.Spec.Bignum.Montgomery module BN = Hacl.Spec.Bignum module BB = Hacl.Spec.Bignum.Base module BL = Hacl.Spec.Bignum.Lib module BIL = Hacl.Spec.Bignum.ModInvLimb module E = Hacl.Spec.Exponentiation.Lemmas module ME = Hacl.Spec.Bignum.MontExponentiation module Euclid = FStar.Math.Euclid module BI = Hacl.Spec.Bignum.ModInv #set-options "--z3rlimit 50 --fuel 0 --ifuel 0" ////////////////////////////////////////// val mul_zero_lemma: n:pos{Euclid.is_prime n} -> x:int -> y:int -> Lemma (x * y % n == 0 <==> (x % n == 0 \/ y % n == 0)) let mul_zero_lemma n x y = assert (0 % n = 0); if x % n = 0 then Math.Lemmas.lemma_mod_mul_distr_l x y n else if y % n = 0 then Math.Lemmas.lemma_mod_mul_distr_r x y n else if x * y % n = 0 then Math.Fermat.mod_mult_congr n x 0 y else () val mul_nonzero_lemma: n:pos{Euclid.is_prime n} -> x:int -> y:int -> Lemma (requires x % n <> 0 /\ y % n <> 0) (ensures x * y % n <> 0) let mul_nonzero_lemma n x y = mul_zero_lemma n x y val from_mont_lemma_nonzero: pbits:pos -> rLen:pos -> n:pos -> mu:nat -> aM:nat -> Lemma (requires M.mont_pre pbits rLen n mu /\ 0 < aM /\ aM < n /\ Euclid.is_prime n) (ensures (let a = M.from_mont pbits rLen n mu aM in 0 < a /\ a < n)) let from_mont_lemma_nonzero pbits rLen n mu aM = let r = pow2 (pbits * rLen) in let d, _ = M.eea_pow2_odd (pbits * rLen) n in let a = M.from_mont pbits rLen n mu aM in M.from_mont_lemma pbits rLen n mu aM; assert (a == aM * d % n); assert (d <> 0); Math.Lemmas.small_mod aM n; assert (aM % n <> 0); let d1 = -d in assert (0 < d1 /\ d1 < n); Math.Lemmas.lemma_mod_sub_1 d1 n; assert ((-d1) % n == n - (d1 % n)); assert (d % n <> 0); mul_nonzero_lemma n aM d; assert (let a = M.from_mont pbits rLen n mu aM in 0 < a /\ a < n); // For some reason, this makes the proof instant. () /////////////////////////////////////////////// let bn_field_get_len #t k = k.len let bn_field_check_modulus #t #len n = let m = BM.bn_check_modulus n in BB.unsafe_bool_of_limb m let bn_field_init #t #len n = let nBits = bits t * BL.bn_get_top_index n in BL.bn_low_bound_bits_lemma n; BM.bn_precomp_r2_mod_n_lemma nBits n; let r2 = BM.bn_precomp_r2_mod_n nBits n in assert (bn_v r2 == pow2 (2 * bits t * len) % bn_v n); let mu = BIL.mod_inv_limb n.[0] in BIL.bn_mod_inv_limb_lemma n; assert ((1 + bn_v n * v mu) % pow2 (bits t) == 0); bn_eval_bound n len; { len = len; n = n; mu = mu; r2 = r2 } let bn_to_field #t k a = BM.bn_to_mont_lemma k.n k.mu k.r2 a; BM.bn_to_mont k.n k.mu k.r2 a let bn_from_field #t k aM = BM.bn_from_mont_lemma k.n k.mu aM; BM.bn_from_mont k.n k.mu aM let bn_from_to_field_lemma #t k a = bn_eval_bound a k.len; M.from_to_mont_lemma (bits t) k.len (bn_v k.n) (v k.mu) (bn_v a) let bn_field_add #t k aM bM = BN.bn_add_mod_n_lemma k.n aM bM; M.from_mont_add_lemma (bits t) k.len (bn_v k.n) (v k.mu) (bn_v aM) (bn_v bM); BN.bn_add_mod_n k.n aM bM let bn_field_sub #t k aM bM = BN.bn_sub_mod_n_lemma k.n aM bM; M.from_mont_sub_lemma (bits t) k.len (bn_v k.n) (v k.mu) (bn_v aM) (bn_v bM); BN.bn_sub_mod_n k.n aM bM let bn_field_mul #t k aM bM = BM.bn_mont_mul_lemma k.n k.mu aM bM; M.from_mont_mul_lemma (bits t) k.len (bn_v k.n) (v k.mu) (bn_v aM) (bn_v bM); BM.bn_mont_mul k.n k.mu aM bM let bn_field_sqr #t k aM = BM.bn_mont_sqr_lemma k.n k.mu aM; M.from_mont_mul_lemma (bits t) k.len (bn_v k.n) (v k.mu) (bn_v aM) (bn_v aM); BM.bn_mont_sqr k.n k.mu aM
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "Lib.Sequence.fsti.checked", "Lib.NatMod.fsti.checked", "Lib.IntTypes.fsti.checked", "Hacl.Spec.Montgomery.Lemmas.fst.checked", "Hacl.Spec.Exponentiation.Lemmas.fst.checked", "Hacl.Spec.Bignum.Montgomery.fsti.checked", "Hacl.Spec.Bignum.MontExponentiation.fst.checked", "Hacl.Spec.Bignum.ModInvLimb.fsti.checked", "Hacl.Spec.Bignum.ModInv.fst.checked", "Hacl.Spec.Bignum.Lib.fst.checked", "Hacl.Spec.Bignum.Definitions.fst.checked", "Hacl.Spec.Bignum.Base.fst.checked", "Hacl.Spec.Bignum.fsti.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.Math.Fermat.fsti.checked", "FStar.Math.Euclid.fsti.checked" ], "interface_file": true, "source_file": "Hacl.Spec.Bignum.MontArithmetic.fst" }
[ { "abbrev": true, "full_module": "Hacl.Spec.Bignum.ModInv", "short_module": "BI" }, { "abbrev": true, "full_module": "Hacl.Spec.Bignum.MontExponentiation", "short_module": "ME" }, { "abbrev": true, "full_module": "Hacl.Spec.Exponentiation.Lemmas", "short_module": "E" }, { "abbrev": true, "full_module": "Hacl.Spec.Bignum.ModInvLimb", "short_module": "BIL" }, { "abbrev": true, "full_module": "Hacl.Spec.Bignum.Lib", "short_module": "BL" }, { "abbrev": true, "full_module": "Hacl.Spec.Bignum.Base", "short_module": "BB" }, { "abbrev": true, "full_module": "Hacl.Spec.Bignum.Montgomery", "short_module": "BM" }, { "abbrev": true, "full_module": "Hacl.Spec.Bignum", "short_module": "BN" }, { "abbrev": true, "full_module": "Hacl.Spec.Montgomery.Lemmas", "short_module": "M" }, { "abbrev": true, "full_module": "FStar.Math.Euclid", "short_module": "Euclid" }, { "abbrev": false, "full_module": "Hacl.Spec.Bignum.Definitions", "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.Bignum", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.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 } ]
{ "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" }
false
k: Hacl.Spec.Bignum.MontArithmetic.bn_mont_ctx t {Hacl.Spec.Bignum.MontArithmetic.bn_mont_ctx_inv k} -> Prims.Pure (Hacl.Spec.Bignum.MontArithmetic.bn_mont_nat k)
Prims.Pure
[]
[]
[ "Hacl.Spec.Bignum.Definitions.limb_t", "Hacl.Spec.Bignum.MontArithmetic.bn_mont_ctx", "Hacl.Spec.Bignum.MontArithmetic.bn_mont_ctx_inv", "Hacl.Spec.Bignum.Montgomery.bn_mont_one", "Hacl.Spec.Bignum.MontArithmetic.__proj__Mkbn_mont_ctx__item__len", "Hacl.Spec.Bignum.MontArithmetic.__proj__Mkbn_mont_ctx__item__n", "Hacl.Spec.Bignum.MontArithmetic.__proj__Mkbn_mont_ctx__item__mu", "Hacl.Spec.Bignum.MontArithmetic.r2", "Prims.unit", "Hacl.Spec.Montgomery.Lemmas.from_mont_one_lemma", "Lib.IntTypes.bits", "Hacl.Spec.Bignum.Definitions.bn_v", "Lib.IntTypes.v", "Lib.IntTypes.SEC", "Hacl.Spec.Bignum.Montgomery.bn_mont_one_lemma", "Hacl.Spec.Bignum.MontArithmetic.__proj__Mkbn_mont_ctx__item__r2", "Hacl.Spec.Bignum.MontArithmetic.bn_mont_nat" ]
[]
false
false
false
false
false
let bn_field_one #t k =
BM.bn_mont_one_lemma k.n k.mu k.r2; M.from_mont_one_lemma (bits t) k.len (bn_v k.n) (v k.mu); BM.bn_mont_one k.n k.mu r2
false
Vale.AsLowStar.Test.fst
Vale.AsLowStar.Test.lowstar_ta_t
val lowstar_ta_t : Type0
let lowstar_ta_t = IX64.as_lowstar_sig_t_weak_stdcall (coerce code_ta) ta_dom [] _ _ (W.mk_prediction code_ta ta_dom [] (ta_lemma code_ta IA.win))
{ "file_name": "vale/code/arch/x64/interop/Vale.AsLowStar.Test.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 65, "end_line": 386, "start_col": 0, "start_line": 379 }
module Vale.AsLowStar.Test open FStar.Mul open Vale.Interop.Base module ME = Vale.X64.Memory module IA = Vale.Interop.Assumptions module V = Vale.X64.Decls module IX64 = Vale.Interop.X64 module VSig = Vale.AsLowStar.ValeSig module LSig = Vale.AsLowStar.LowStarSig module W = Vale.AsLowStar.Wrapper module VS = Vale.X64.State module MS = Vale.X64.Machine_s (* A little utility to trigger normalization in types *) let as_t (#a:Type) (x:normal a) : a = x let as_normal_t (#a:Type) (x:a) : normal a = x //////////////////////////////////////////////////////////////////////////////// //First a little standalone, toy experiment [@__reduce__] let b64 = buf_t TUInt8 TUInt64 [@__reduce__] let ib64 = ibuf_t TUInt8 TUInt64 [@__reduce__] let t64_mod = TD_Buffer TUInt8 TUInt64 default_bq [@__reduce__] let t64_no_mod = TD_Buffer TUInt8 TUInt64 ({modified=false; strict_disjointness=false; taint=MS.Secret}) [@__reduce__] let t64_imm = TD_ImmBuffer TUInt8 TUInt64 ({modified=false; strict_disjointness=false; taint=MS.Secret}) [@__reduce__] let (dom : list td{List.length dom <= 20}) = let y = [t64_mod;t64_imm] in assert_norm (List.length y = 2); y assume val pre : VSig.vale_pre dom assume val post : VSig.vale_post dom assume val v: VSig.vale_sig_stdcall pre post assume val c: V.va_code [@__reduce__] let call_c_t = IX64.as_lowstar_sig_t_weak_stdcall c dom [] _ _ (W.mk_prediction c dom [] (v c IA.win)) let call_c : call_c_t = IX64.wrap_weak_stdcall c dom (W.mk_prediction c dom [] (v c IA.win)) let call_c_normal_t : normal call_c_t = as_normal_t #call_c_t call_c //You can ask emacs to show you the type of call_c_normal_t ... //////////////////////////////////////////////////////////////////////////////// //Now memcpy module VM = Vale.Test.X64.Vale_memcpy [@__reduce__] let vm_dom = [t64_mod; t64_imm] open Vale.X64.MemoryAdapters (* Need to rearrange the order of arguments *) [@__reduce__] let vm_pre : VSig.vale_pre vm_dom = fun (c:V.va_code) (dst:b64) (src:ib64) (va_s0:V.va_state) -> VM.va_req_Memcpy c va_s0 IA.win (as_vale_buffer dst) (as_vale_immbuffer src) [@__reduce__] let vm_post : VSig.vale_post vm_dom = fun (c:V.va_code) (dst:b64) (src:ib64) (va_s0:V.va_state) (va_s1:V.va_state) (f:V.va_fuel) -> VM.va_ens_Memcpy c va_s0 IA.win (as_vale_buffer dst) (as_vale_immbuffer src) va_s1 f module VS = Vale.X64.State #reset-options "--print_effect_args --z3rlimit 200" (* The vale lemma doesn't quite suffice to prove the modifies clause expected of the interop layer *) [@__reduce__] let vm_lemma' (code:V.va_code) (_win:bool) (dst:b64) (src:ib64) (va_s0:V.va_state) : Ghost (V.va_state & V.va_fuel) (requires vm_pre code dst src va_s0) (ensures (fun (va_s1, f) -> V.eval_code code va_s0 f va_s1 /\ VSig.vale_calling_conventions_stdcall va_s0 va_s1 /\ vm_post code dst src va_s0 va_s1 f /\ ME.buffer_readable (VS.vs_get_vale_heap va_s1) (as_vale_immbuffer src) /\ ME.buffer_readable (VS.vs_get_vale_heap va_s1) (as_vale_buffer dst) /\ ME.buffer_writeable (as_vale_buffer dst) /\ ME.modifies (ME.loc_union (ME.loc_buffer (as_vale_buffer dst)) ME.loc_none) (VS.vs_get_vale_heap va_s0) (VS.vs_get_vale_heap va_s1) )) = let va_s1, f = VM.va_lemma_Memcpy code va_s0 IA.win (as_vale_buffer dst) (as_vale_immbuffer src) in Vale.AsLowStar.MemoryHelpers.buffer_writeable_reveal ME.TUInt8 ME.TUInt64 dst; (va_s1, f) (* Prove that vm_lemma' has the required type *) let vm_lemma = as_t #(VSig.vale_sig_stdcall vm_pre vm_post) vm_lemma' let code_Memcpy = VM.va_code_Memcpy IA.win (* Here's the type expected for the memcpy wrapper *) [@__reduce__] let lowstar_Memcpy_t = IX64.as_lowstar_sig_t_weak_stdcall code_Memcpy vm_dom [] _ _ (W.mk_prediction code_Memcpy vm_dom [] (vm_lemma code_Memcpy IA.win)) (* And here's the memcpy wrapper itself *) let lowstar_Memcpy : lowstar_Memcpy_t = IX64.wrap_weak_stdcall code_Memcpy vm_dom (W.mk_prediction code_Memcpy vm_dom [] (vm_lemma code_Memcpy IA.win)) let lowstar_Memcpy_normal_t //: normal lowstar_Memcpy_t = as_normal_t #lowstar_Memcpy_t lowstar_Memcpy module B = LowStar.Buffer module IB = LowStar.ImmutableBuffer module MB = LowStar.Monotonic.Buffer open FStar.HyperStack.ST module M = Vale.X64.Memory let test (x:b64) = assert (V.buffer_length (as_vale_buffer x) == (B.length x * view_n TUInt8) / view_n TUInt64); assert (V.buffer_length (as_vale_buffer x) == B.length x / 8) let itest (x:ib64) = assert (V.buffer_length (as_vale_immbuffer x) == (B.length x * view_n TUInt8) / view_n TUInt64); assert (V.buffer_length (as_vale_immbuffer x) == B.length x / 8) module T = FStar.Tactics #reset-options "--using_facts_from '* -FStar.Tactics -FStar.Reflection'" module LBV = LowStar.BufferView.Up module DV = LowStar.BufferView.Down #push-options "--ext compat:normalizer_memo_ignore_cfg" let memcpy_Test (dst:B.buffer UInt8.t{B.length dst % 8 == 0}) (src:IB.ibuffer UInt8.t{B.length src % 8 == 0}) : Stack UInt64.t (requires fun h0 -> B.live h0 dst /\ B.live h0 src /\ B.disjoint dst src /\ B.length dst == 16 /\ B.length src == 16) (ensures fun h0 _ h1 -> B.modifies (B.loc_buffer dst) h0 h1 /\ B.live h1 src /\ B.live h1 dst) // B.as_seq h1 dst == B.as_seq h1 src) // by (T.dump "A") (* in case you want to look at the VC *) = IB.inhabited_immutable_buffer_is_distinct_from_buffer (UInt8.uint_to_t 0) src dst; let (x, _) = lowstar_Memcpy_normal_t dst src () in //This is a call to the interop wrapper let h1 = get () in // let v = Vale.Interop.Views.up_view64 in // assert (DV.length_eq (get_downview dst); // DV.length_eq (get_downview src); // Seq.equal (LBV.as_seq h1 (LBV.mk_buffer (get_downview dst) v)) // (LBV.as_seq h1 (LBV.mk_buffer (get_downview src) v))); // lbv_as_seq_eq dst src Vale.Interop.Views.up_view64 h1; //And a lemma to rephrase the Vale postcondition x //with equalities of buffer views //back to equalities of buffers #pop-options module VC = Vale.Lib.X64.Cpuidstdcall [@__reduce__] let empty_list #a : l:list a {List.length l = 0} = [] [@__reduce__] let aesni_dom : IX64.arity_ok_stdcall td = [] (* Need to rearrange the order of arguments *) [@__reduce__] let aesni_pre : VSig.vale_pre aesni_dom = fun (c:V.va_code) (va_s0:V.va_state) -> VC.va_req_Check_aesni_stdcall c va_s0 IA.win [@__reduce__] let aesni_post : VSig.vale_post aesni_dom = fun (c:V.va_code) (va_s0:V.va_state) (va_s1:V.va_state) (f:V.va_fuel) -> VC.va_ens_Check_aesni_stdcall c va_s0 IA.win va_s1 f [@__reduce__] let with_len (l:list 'a) : Pure (list 'a) (requires True) (ensures fun m -> m==l /\ List.length m == normalize_term (List.length l)) = l #set-options "--max_fuel 0 --max_ifuel 1 --z3rlimit_factor 2" (* The vale lemma doesn't quite suffice to prove the modifies clause expected of the interop layer *) [@__reduce__] let aesni_lemma' (code:V.va_code) (_win:bool) (va_s0:V.va_state) : Ghost (V.va_state & V.va_fuel) (requires aesni_pre code va_s0) (ensures (fun (va_s1, f) -> V.eval_code code va_s0 f va_s1 /\ VSig.vale_calling_conventions_stdcall va_s0 va_s1 /\ aesni_post code va_s0 va_s1 f)) = VC.va_lemma_Check_aesni_stdcall code va_s0 IA.win #set-options "--max_fuel 0 --max_ifuel 0 --z3rlimit_factor 2" (* Prove that vm_lemma' has the required type *) let aesni_lemma = as_t #(VSig.vale_sig_stdcall aesni_pre aesni_post) aesni_lemma' let code_aesni = VC.va_code_Check_aesni_stdcall IA.win (* Here's the type expected for the check_aesni wrapper *) [@__reduce__] let lowstar_aesni_t = IX64.as_lowstar_sig_t_weak_stdcall (coerce code_aesni) aesni_dom empty_list _ _ (W.mk_prediction code_aesni aesni_dom [] (aesni_lemma code_aesni IA.win)) (* And here's the check_aesni wrapper itself *) let lowstar_aesni : lowstar_aesni_t = IX64.wrap_weak_stdcall (coerce code_aesni) aesni_dom (W.mk_prediction code_aesni aesni_dom [] (aesni_lemma code_aesni IA.win)) let lowstar_aesni_normal_t //: normal lowstar_aesni_t = as_normal_t #lowstar_aesni_t lowstar_aesni open Vale.X64.CPU_Features_s #set-options "--print_full_names" let aesni_Test () : Stack UInt64.t (requires fun h0 -> True) (ensures fun h0 ret_val h1 -> (UInt64.v ret_val) =!= 0 ==> aesni_enabled /\ pclmulqdq_enabled) // by (T.dump "A") (* in case you want to look at the VC *) = let (x, _) = lowstar_aesni_normal_t () in //This is a call to the interop wrapper x module TA = Vale.Test.X64.Args [@__reduce__] let (ta_dom:list td{List.length ta_dom <= 20}) = let y = [t64_imm; t64_imm; t64_imm; t64_imm; t64_imm; t64_imm; t64_imm; t64_imm] in assert_norm (List.length y = 8); y (* Need to rearrange the order of arguments *) [@__reduce__] let ta_pre : VSig.vale_pre ta_dom = fun (c:V.va_code) (arg0:ib64) (arg1:ib64) (arg2:ib64) (arg3:ib64) (arg4:ib64) (arg5:ib64) (arg6:ib64) (arg7:ib64) (va_s0:V.va_state) -> TA.va_req_Test c va_s0 IA.win (as_vale_immbuffer arg0) (as_vale_immbuffer arg1) (as_vale_immbuffer arg2) (as_vale_immbuffer arg3) (as_vale_immbuffer arg4) (as_vale_immbuffer arg5) (as_vale_immbuffer arg6) (as_vale_immbuffer arg7) [@__reduce__] let ta_post : VSig.vale_post ta_dom = fun (c:V.va_code) (arg0:ib64) (arg1:ib64) (arg2:ib64) (arg3:ib64) (arg4:ib64) (arg5:ib64) (arg6:ib64) (arg7:ib64) (va_s0:V.va_state) (va_s1:V.va_state) (f:V.va_fuel) -> TA.va_ens_Test c va_s0 IA.win (as_vale_immbuffer arg0) (as_vale_immbuffer arg1) (as_vale_immbuffer arg2) (as_vale_immbuffer arg3) (as_vale_immbuffer arg4) (as_vale_immbuffer arg5) (as_vale_immbuffer arg6) (as_vale_immbuffer arg7) va_s1 f #reset-options "--max_fuel 0 --max_ifuel 0 --z3rlimit 100" (* The vale lemma doesn't quite suffice to prove the modifies clause expected of the interop layer *) [@__reduce__] let ta_lemma' (code:V.va_code) (_win:bool) (arg0:ib64) (arg1:ib64) (arg2:ib64) (arg3:ib64) (arg4:ib64) (arg5:ib64) (arg6:ib64) (arg7:ib64) (va_s0:V.va_state) : Ghost (V.va_state & V.va_fuel) (requires ta_pre code arg0 arg1 arg2 arg3 arg4 arg5 arg6 arg7 va_s0) (ensures (fun (va_s1, f) -> V.eval_code code va_s0 f va_s1 /\ VSig.vale_calling_conventions_stdcall va_s0 va_s1 /\ ta_post code arg0 arg1 arg2 arg3 arg4 arg5 arg6 arg7 va_s0 va_s1 f /\ ME.buffer_readable (VS.vs_get_vale_heap va_s1) (as_vale_immbuffer arg0) /\ ME.buffer_readable (VS.vs_get_vale_heap va_s1) (as_vale_immbuffer arg1) /\ ME.buffer_readable (VS.vs_get_vale_heap va_s1) (as_vale_immbuffer arg2) /\ ME.buffer_readable (VS.vs_get_vale_heap va_s1) (as_vale_immbuffer arg3) /\ ME.buffer_readable (VS.vs_get_vale_heap va_s1) (as_vale_immbuffer arg4) /\ ME.buffer_readable (VS.vs_get_vale_heap va_s1) (as_vale_immbuffer arg5) /\ ME.buffer_readable (VS.vs_get_vale_heap va_s1) (as_vale_immbuffer arg6) /\ ME.buffer_readable (VS.vs_get_vale_heap va_s1) (as_vale_immbuffer arg7) /\ ME.modifies ME.loc_none (VS.vs_get_vale_heap va_s0) (VS.vs_get_vale_heap va_s1))) = let va_s1, f = TA.va_lemma_Test code va_s0 IA.win (as_vale_immbuffer arg0) (as_vale_immbuffer arg1) (as_vale_immbuffer arg2) (as_vale_immbuffer arg3) (as_vale_immbuffer arg4) (as_vale_immbuffer arg5) (as_vale_immbuffer arg6) (as_vale_immbuffer arg7) in va_s1, f (* Prove that vm_lemma' has the required type *) let ta_lemma = as_t #(VSig.vale_sig_stdcall ta_pre ta_post) ta_lemma' let code_ta = TA.va_code_Test IA.win (* Here's the type expected for the check_aesni wrapper *)
{ "checked_file": "/", "dependencies": [ "Vale.X64.State.fsti.checked", "Vale.X64.MemoryAdapters.fsti.checked", "Vale.X64.Memory.fsti.checked", "Vale.X64.Machine_s.fst.checked", "Vale.X64.Decls.fsti.checked", "Vale.X64.CPU_Features_s.fst.checked", "Vale.Test.X64.Vale_memcpy.fsti.checked", "Vale.Test.X64.Args.fsti.checked", "Vale.Lib.X64.Cpuidstdcall.fsti.checked", "Vale.Interop.X64.fsti.checked", "Vale.Interop.Base.fst.checked", "Vale.Interop.Assumptions.fst.checked", "Vale.AsLowStar.Wrapper.fsti.checked", "Vale.AsLowStar.ValeSig.fst.checked", "Vale.AsLowStar.MemoryHelpers.fsti.checked", "Vale.AsLowStar.LowStarSig.fst.checked", "prims.fst.checked", "LowStar.Monotonic.Buffer.fsti.checked", "LowStar.ImmutableBuffer.fst.checked", "LowStar.BufferView.Up.fsti.checked", "LowStar.BufferView.Down.fsti.checked", "LowStar.Buffer.fst.checked", "FStar.UInt8.fsti.checked", "FStar.UInt64.fsti.checked", "FStar.Tactics.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.List.fst.checked", "FStar.HyperStack.ST.fsti.checked" ], "interface_file": false, "source_file": "Vale.AsLowStar.Test.fst" }
[ { "abbrev": true, "full_module": "Vale.Test.X64.Args", "short_module": "TA" }, { "abbrev": false, "full_module": "Vale.X64.CPU_Features_s", "short_module": null }, { "abbrev": true, "full_module": "Vale.Lib.X64.Cpuidstdcall", "short_module": "VC" }, { "abbrev": true, "full_module": "LowStar.BufferView.Down", "short_module": "DV" }, { "abbrev": true, "full_module": "LowStar.BufferView.Up", "short_module": "LBV" }, { "abbrev": true, "full_module": "FStar.Tactics", "short_module": "T" }, { "abbrev": true, "full_module": "Vale.X64.Memory", "short_module": "M" }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": true, "full_module": "LowStar.Monotonic.Buffer", "short_module": "MB" }, { "abbrev": true, "full_module": "LowStar.ImmutableBuffer", "short_module": "IB" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "Vale.X64.State", "short_module": "VS" }, { "abbrev": false, "full_module": "Vale.X64.MemoryAdapters", "short_module": null }, { "abbrev": true, "full_module": "Vale.Test.X64.Vale_memcpy", "short_module": "VM" }, { "abbrev": true, "full_module": "Vale.X64.Machine_s", "short_module": "MS" }, { "abbrev": true, "full_module": "Vale.X64.State", "short_module": "VS" }, { "abbrev": true, "full_module": "Vale.AsLowStar.Wrapper", "short_module": "W" }, { "abbrev": true, "full_module": "Vale.AsLowStar.LowStarSig", "short_module": "LSig" }, { "abbrev": true, "full_module": "Vale.AsLowStar.ValeSig", "short_module": "VSig" }, { "abbrev": true, "full_module": "Vale.Interop.X64", "short_module": "IX64" }, { "abbrev": true, "full_module": "Vale.X64.Decls", "short_module": "V" }, { "abbrev": true, "full_module": "Vale.Interop.Assumptions", "short_module": "IA" }, { "abbrev": true, "full_module": "Vale.X64.Memory", "short_module": "ME" }, { "abbrev": false, "full_module": "Vale.Interop.Base", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.AsLowStar", "short_module": null }, { "abbrev": false, "full_module": "Vale.AsLowStar", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 0, "max_fuel": 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": 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" }
false
Type0
Prims.Tot
[ "total" ]
[]
[ "Vale.Interop.X64.as_lowstar_sig_t_weak_stdcall", "Vale.X64.MemoryAdapters.coerce", "Vale.X64.Machine_Semantics_s.code", "Vale.X64.Decls.va_code", "Vale.AsLowStar.Test.code_ta", "Vale.AsLowStar.Test.ta_dom", "Prims.Nil", "Vale.Interop.Base.arg", "Vale.AsLowStar.Wrapper.pre_rel_generic", "Vale.Interop.X64.max_stdcall", "Vale.Interop.X64.arg_reg_stdcall", "Vale.AsLowStar.Test.ta_pre", "Vale.AsLowStar.Wrapper.post_rel_generic", "Vale.AsLowStar.Test.ta_post", "Vale.AsLowStar.Wrapper.mk_prediction", "Vale.Interop.X64.regs_modified_stdcall", "Vale.Interop.X64.xmms_modified_stdcall", "Vale.AsLowStar.Test.ta_lemma", "Vale.Interop.Assumptions.win" ]
[]
false
false
false
true
true
let lowstar_ta_t =
IX64.as_lowstar_sig_t_weak_stdcall (coerce code_ta) ta_dom [] _ _ (W.mk_prediction code_ta ta_dom [] (ta_lemma code_ta IA.win))
false
Hacl.Spec.Bignum.MontArithmetic.fst
Hacl.Spec.Bignum.MontArithmetic.bn_field_mul
val bn_field_mul: #t:limb_t -> k:bn_mont_ctx t{bn_mont_ctx_inv k} -> aM:bn_mont_nat k -> bM:bn_mont_nat k -> Pure (bn_mont_nat k) (requires True) (ensures fun cM -> bn_v (bn_from_field k cM) == bn_v (bn_from_field k aM) * bn_v (bn_from_field k bM) % bn_v k.n)
val bn_field_mul: #t:limb_t -> k:bn_mont_ctx t{bn_mont_ctx_inv k} -> aM:bn_mont_nat k -> bM:bn_mont_nat k -> Pure (bn_mont_nat k) (requires True) (ensures fun cM -> bn_v (bn_from_field k cM) == bn_v (bn_from_field k aM) * bn_v (bn_from_field k bM) % bn_v k.n)
let bn_field_mul #t k aM bM = BM.bn_mont_mul_lemma k.n k.mu aM bM; M.from_mont_mul_lemma (bits t) k.len (bn_v k.n) (v k.mu) (bn_v aM) (bn_v bM); BM.bn_mont_mul k.n k.mu aM bM
{ "file_name": "code/bignum/Hacl.Spec.Bignum.MontArithmetic.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 31, "end_line": 140, "start_col": 0, "start_line": 137 }
module Hacl.Spec.Bignum.MontArithmetic open FStar.Mul open Lib.IntTypes open Lib.Sequence open Hacl.Spec.Bignum.Definitions module M = Hacl.Spec.Montgomery.Lemmas module BM = Hacl.Spec.Bignum.Montgomery module BN = Hacl.Spec.Bignum module BB = Hacl.Spec.Bignum.Base module BL = Hacl.Spec.Bignum.Lib module BIL = Hacl.Spec.Bignum.ModInvLimb module E = Hacl.Spec.Exponentiation.Lemmas module ME = Hacl.Spec.Bignum.MontExponentiation module Euclid = FStar.Math.Euclid module BI = Hacl.Spec.Bignum.ModInv #set-options "--z3rlimit 50 --fuel 0 --ifuel 0" ////////////////////////////////////////// val mul_zero_lemma: n:pos{Euclid.is_prime n} -> x:int -> y:int -> Lemma (x * y % n == 0 <==> (x % n == 0 \/ y % n == 0)) let mul_zero_lemma n x y = assert (0 % n = 0); if x % n = 0 then Math.Lemmas.lemma_mod_mul_distr_l x y n else if y % n = 0 then Math.Lemmas.lemma_mod_mul_distr_r x y n else if x * y % n = 0 then Math.Fermat.mod_mult_congr n x 0 y else () val mul_nonzero_lemma: n:pos{Euclid.is_prime n} -> x:int -> y:int -> Lemma (requires x % n <> 0 /\ y % n <> 0) (ensures x * y % n <> 0) let mul_nonzero_lemma n x y = mul_zero_lemma n x y val from_mont_lemma_nonzero: pbits:pos -> rLen:pos -> n:pos -> mu:nat -> aM:nat -> Lemma (requires M.mont_pre pbits rLen n mu /\ 0 < aM /\ aM < n /\ Euclid.is_prime n) (ensures (let a = M.from_mont pbits rLen n mu aM in 0 < a /\ a < n)) let from_mont_lemma_nonzero pbits rLen n mu aM = let r = pow2 (pbits * rLen) in let d, _ = M.eea_pow2_odd (pbits * rLen) n in let a = M.from_mont pbits rLen n mu aM in M.from_mont_lemma pbits rLen n mu aM; assert (a == aM * d % n); assert (d <> 0); Math.Lemmas.small_mod aM n; assert (aM % n <> 0); let d1 = -d in assert (0 < d1 /\ d1 < n); Math.Lemmas.lemma_mod_sub_1 d1 n; assert ((-d1) % n == n - (d1 % n)); assert (d % n <> 0); mul_nonzero_lemma n aM d; assert (let a = M.from_mont pbits rLen n mu aM in 0 < a /\ a < n); // For some reason, this makes the proof instant. () /////////////////////////////////////////////// let bn_field_get_len #t k = k.len let bn_field_check_modulus #t #len n = let m = BM.bn_check_modulus n in BB.unsafe_bool_of_limb m let bn_field_init #t #len n = let nBits = bits t * BL.bn_get_top_index n in BL.bn_low_bound_bits_lemma n; BM.bn_precomp_r2_mod_n_lemma nBits n; let r2 = BM.bn_precomp_r2_mod_n nBits n in assert (bn_v r2 == pow2 (2 * bits t * len) % bn_v n); let mu = BIL.mod_inv_limb n.[0] in BIL.bn_mod_inv_limb_lemma n; assert ((1 + bn_v n * v mu) % pow2 (bits t) == 0); bn_eval_bound n len; { len = len; n = n; mu = mu; r2 = r2 } let bn_to_field #t k a = BM.bn_to_mont_lemma k.n k.mu k.r2 a; BM.bn_to_mont k.n k.mu k.r2 a let bn_from_field #t k aM = BM.bn_from_mont_lemma k.n k.mu aM; BM.bn_from_mont k.n k.mu aM let bn_from_to_field_lemma #t k a = bn_eval_bound a k.len; M.from_to_mont_lemma (bits t) k.len (bn_v k.n) (v k.mu) (bn_v a) let bn_field_add #t k aM bM = BN.bn_add_mod_n_lemma k.n aM bM; M.from_mont_add_lemma (bits t) k.len (bn_v k.n) (v k.mu) (bn_v aM) (bn_v bM); BN.bn_add_mod_n k.n aM bM let bn_field_sub #t k aM bM = BN.bn_sub_mod_n_lemma k.n aM bM; M.from_mont_sub_lemma (bits t) k.len (bn_v k.n) (v k.mu) (bn_v aM) (bn_v bM); BN.bn_sub_mod_n k.n aM bM
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "Lib.Sequence.fsti.checked", "Lib.NatMod.fsti.checked", "Lib.IntTypes.fsti.checked", "Hacl.Spec.Montgomery.Lemmas.fst.checked", "Hacl.Spec.Exponentiation.Lemmas.fst.checked", "Hacl.Spec.Bignum.Montgomery.fsti.checked", "Hacl.Spec.Bignum.MontExponentiation.fst.checked", "Hacl.Spec.Bignum.ModInvLimb.fsti.checked", "Hacl.Spec.Bignum.ModInv.fst.checked", "Hacl.Spec.Bignum.Lib.fst.checked", "Hacl.Spec.Bignum.Definitions.fst.checked", "Hacl.Spec.Bignum.Base.fst.checked", "Hacl.Spec.Bignum.fsti.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.Math.Fermat.fsti.checked", "FStar.Math.Euclid.fsti.checked" ], "interface_file": true, "source_file": "Hacl.Spec.Bignum.MontArithmetic.fst" }
[ { "abbrev": true, "full_module": "Hacl.Spec.Bignum.ModInv", "short_module": "BI" }, { "abbrev": true, "full_module": "Hacl.Spec.Bignum.MontExponentiation", "short_module": "ME" }, { "abbrev": true, "full_module": "Hacl.Spec.Exponentiation.Lemmas", "short_module": "E" }, { "abbrev": true, "full_module": "Hacl.Spec.Bignum.ModInvLimb", "short_module": "BIL" }, { "abbrev": true, "full_module": "Hacl.Spec.Bignum.Lib", "short_module": "BL" }, { "abbrev": true, "full_module": "Hacl.Spec.Bignum.Base", "short_module": "BB" }, { "abbrev": true, "full_module": "Hacl.Spec.Bignum.Montgomery", "short_module": "BM" }, { "abbrev": true, "full_module": "Hacl.Spec.Bignum", "short_module": "BN" }, { "abbrev": true, "full_module": "Hacl.Spec.Montgomery.Lemmas", "short_module": "M" }, { "abbrev": true, "full_module": "FStar.Math.Euclid", "short_module": "Euclid" }, { "abbrev": false, "full_module": "Hacl.Spec.Bignum.Definitions", "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.Bignum", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.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 } ]
{ "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" }
false
k: Hacl.Spec.Bignum.MontArithmetic.bn_mont_ctx t {Hacl.Spec.Bignum.MontArithmetic.bn_mont_ctx_inv k} -> aM: Hacl.Spec.Bignum.MontArithmetic.bn_mont_nat k -> bM: Hacl.Spec.Bignum.MontArithmetic.bn_mont_nat k -> Prims.Pure (Hacl.Spec.Bignum.MontArithmetic.bn_mont_nat k)
Prims.Pure
[]
[]
[ "Hacl.Spec.Bignum.Definitions.limb_t", "Hacl.Spec.Bignum.MontArithmetic.bn_mont_ctx", "Hacl.Spec.Bignum.MontArithmetic.bn_mont_ctx_inv", "Hacl.Spec.Bignum.MontArithmetic.bn_mont_nat", "Hacl.Spec.Bignum.Montgomery.bn_mont_mul", "Hacl.Spec.Bignum.MontArithmetic.__proj__Mkbn_mont_ctx__item__len", "Hacl.Spec.Bignum.MontArithmetic.__proj__Mkbn_mont_ctx__item__n", "Hacl.Spec.Bignum.MontArithmetic.__proj__Mkbn_mont_ctx__item__mu", "Prims.unit", "Hacl.Spec.Montgomery.Lemmas.from_mont_mul_lemma", "Lib.IntTypes.bits", "Hacl.Spec.Bignum.Definitions.bn_v", "Lib.IntTypes.v", "Lib.IntTypes.SEC", "Hacl.Spec.Bignum.Montgomery.bn_mont_mul_lemma" ]
[]
false
false
false
false
false
let bn_field_mul #t k aM bM =
BM.bn_mont_mul_lemma k.n k.mu aM bM; M.from_mont_mul_lemma (bits t) k.len (bn_v k.n) (v k.mu) (bn_v aM) (bn_v bM); BM.bn_mont_mul k.n k.mu aM bM
false
Hacl.Spec.Bignum.MontArithmetic.fst
Hacl.Spec.Bignum.MontArithmetic.bn_field_add
val bn_field_add: #t:limb_t -> k:bn_mont_ctx t{bn_mont_ctx_inv k} -> aM:bn_mont_nat k -> bM:bn_mont_nat k -> Pure (bn_mont_nat k) (requires True) (ensures fun cM -> bn_v (bn_from_field k cM) == (bn_v (bn_from_field k aM) + bn_v (bn_from_field k bM)) % bn_v k.n)
val bn_field_add: #t:limb_t -> k:bn_mont_ctx t{bn_mont_ctx_inv k} -> aM:bn_mont_nat k -> bM:bn_mont_nat k -> Pure (bn_mont_nat k) (requires True) (ensures fun cM -> bn_v (bn_from_field k cM) == (bn_v (bn_from_field k aM) + bn_v (bn_from_field k bM)) % bn_v k.n)
let bn_field_add #t k aM bM = BN.bn_add_mod_n_lemma k.n aM bM; M.from_mont_add_lemma (bits t) k.len (bn_v k.n) (v k.mu) (bn_v aM) (bn_v bM); BN.bn_add_mod_n k.n aM bM
{ "file_name": "code/bignum/Hacl.Spec.Bignum.MontArithmetic.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 27, "end_line": 128, "start_col": 0, "start_line": 125 }
module Hacl.Spec.Bignum.MontArithmetic open FStar.Mul open Lib.IntTypes open Lib.Sequence open Hacl.Spec.Bignum.Definitions module M = Hacl.Spec.Montgomery.Lemmas module BM = Hacl.Spec.Bignum.Montgomery module BN = Hacl.Spec.Bignum module BB = Hacl.Spec.Bignum.Base module BL = Hacl.Spec.Bignum.Lib module BIL = Hacl.Spec.Bignum.ModInvLimb module E = Hacl.Spec.Exponentiation.Lemmas module ME = Hacl.Spec.Bignum.MontExponentiation module Euclid = FStar.Math.Euclid module BI = Hacl.Spec.Bignum.ModInv #set-options "--z3rlimit 50 --fuel 0 --ifuel 0" ////////////////////////////////////////// val mul_zero_lemma: n:pos{Euclid.is_prime n} -> x:int -> y:int -> Lemma (x * y % n == 0 <==> (x % n == 0 \/ y % n == 0)) let mul_zero_lemma n x y = assert (0 % n = 0); if x % n = 0 then Math.Lemmas.lemma_mod_mul_distr_l x y n else if y % n = 0 then Math.Lemmas.lemma_mod_mul_distr_r x y n else if x * y % n = 0 then Math.Fermat.mod_mult_congr n x 0 y else () val mul_nonzero_lemma: n:pos{Euclid.is_prime n} -> x:int -> y:int -> Lemma (requires x % n <> 0 /\ y % n <> 0) (ensures x * y % n <> 0) let mul_nonzero_lemma n x y = mul_zero_lemma n x y val from_mont_lemma_nonzero: pbits:pos -> rLen:pos -> n:pos -> mu:nat -> aM:nat -> Lemma (requires M.mont_pre pbits rLen n mu /\ 0 < aM /\ aM < n /\ Euclid.is_prime n) (ensures (let a = M.from_mont pbits rLen n mu aM in 0 < a /\ a < n)) let from_mont_lemma_nonzero pbits rLen n mu aM = let r = pow2 (pbits * rLen) in let d, _ = M.eea_pow2_odd (pbits * rLen) n in let a = M.from_mont pbits rLen n mu aM in M.from_mont_lemma pbits rLen n mu aM; assert (a == aM * d % n); assert (d <> 0); Math.Lemmas.small_mod aM n; assert (aM % n <> 0); let d1 = -d in assert (0 < d1 /\ d1 < n); Math.Lemmas.lemma_mod_sub_1 d1 n; assert ((-d1) % n == n - (d1 % n)); assert (d % n <> 0); mul_nonzero_lemma n aM d; assert (let a = M.from_mont pbits rLen n mu aM in 0 < a /\ a < n); // For some reason, this makes the proof instant. () /////////////////////////////////////////////// let bn_field_get_len #t k = k.len let bn_field_check_modulus #t #len n = let m = BM.bn_check_modulus n in BB.unsafe_bool_of_limb m let bn_field_init #t #len n = let nBits = bits t * BL.bn_get_top_index n in BL.bn_low_bound_bits_lemma n; BM.bn_precomp_r2_mod_n_lemma nBits n; let r2 = BM.bn_precomp_r2_mod_n nBits n in assert (bn_v r2 == pow2 (2 * bits t * len) % bn_v n); let mu = BIL.mod_inv_limb n.[0] in BIL.bn_mod_inv_limb_lemma n; assert ((1 + bn_v n * v mu) % pow2 (bits t) == 0); bn_eval_bound n len; { len = len; n = n; mu = mu; r2 = r2 } let bn_to_field #t k a = BM.bn_to_mont_lemma k.n k.mu k.r2 a; BM.bn_to_mont k.n k.mu k.r2 a let bn_from_field #t k aM = BM.bn_from_mont_lemma k.n k.mu aM; BM.bn_from_mont k.n k.mu aM let bn_from_to_field_lemma #t k a = bn_eval_bound a k.len; M.from_to_mont_lemma (bits t) k.len (bn_v k.n) (v k.mu) (bn_v a)
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "Lib.Sequence.fsti.checked", "Lib.NatMod.fsti.checked", "Lib.IntTypes.fsti.checked", "Hacl.Spec.Montgomery.Lemmas.fst.checked", "Hacl.Spec.Exponentiation.Lemmas.fst.checked", "Hacl.Spec.Bignum.Montgomery.fsti.checked", "Hacl.Spec.Bignum.MontExponentiation.fst.checked", "Hacl.Spec.Bignum.ModInvLimb.fsti.checked", "Hacl.Spec.Bignum.ModInv.fst.checked", "Hacl.Spec.Bignum.Lib.fst.checked", "Hacl.Spec.Bignum.Definitions.fst.checked", "Hacl.Spec.Bignum.Base.fst.checked", "Hacl.Spec.Bignum.fsti.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.Math.Fermat.fsti.checked", "FStar.Math.Euclid.fsti.checked" ], "interface_file": true, "source_file": "Hacl.Spec.Bignum.MontArithmetic.fst" }
[ { "abbrev": true, "full_module": "Hacl.Spec.Bignum.ModInv", "short_module": "BI" }, { "abbrev": true, "full_module": "Hacl.Spec.Bignum.MontExponentiation", "short_module": "ME" }, { "abbrev": true, "full_module": "Hacl.Spec.Exponentiation.Lemmas", "short_module": "E" }, { "abbrev": true, "full_module": "Hacl.Spec.Bignum.ModInvLimb", "short_module": "BIL" }, { "abbrev": true, "full_module": "Hacl.Spec.Bignum.Lib", "short_module": "BL" }, { "abbrev": true, "full_module": "Hacl.Spec.Bignum.Base", "short_module": "BB" }, { "abbrev": true, "full_module": "Hacl.Spec.Bignum.Montgomery", "short_module": "BM" }, { "abbrev": true, "full_module": "Hacl.Spec.Bignum", "short_module": "BN" }, { "abbrev": true, "full_module": "Hacl.Spec.Montgomery.Lemmas", "short_module": "M" }, { "abbrev": true, "full_module": "FStar.Math.Euclid", "short_module": "Euclid" }, { "abbrev": false, "full_module": "Hacl.Spec.Bignum.Definitions", "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.Bignum", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.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 } ]
{ "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" }
false
k: Hacl.Spec.Bignum.MontArithmetic.bn_mont_ctx t {Hacl.Spec.Bignum.MontArithmetic.bn_mont_ctx_inv k} -> aM: Hacl.Spec.Bignum.MontArithmetic.bn_mont_nat k -> bM: Hacl.Spec.Bignum.MontArithmetic.bn_mont_nat k -> Prims.Pure (Hacl.Spec.Bignum.MontArithmetic.bn_mont_nat k)
Prims.Pure
[]
[]
[ "Hacl.Spec.Bignum.Definitions.limb_t", "Hacl.Spec.Bignum.MontArithmetic.bn_mont_ctx", "Hacl.Spec.Bignum.MontArithmetic.bn_mont_ctx_inv", "Hacl.Spec.Bignum.MontArithmetic.bn_mont_nat", "Hacl.Spec.Bignum.bn_add_mod_n", "Hacl.Spec.Bignum.MontArithmetic.__proj__Mkbn_mont_ctx__item__len", "Hacl.Spec.Bignum.MontArithmetic.__proj__Mkbn_mont_ctx__item__n", "Prims.unit", "Hacl.Spec.Montgomery.Lemmas.from_mont_add_lemma", "Lib.IntTypes.bits", "Hacl.Spec.Bignum.Definitions.bn_v", "Lib.IntTypes.v", "Lib.IntTypes.SEC", "Hacl.Spec.Bignum.MontArithmetic.__proj__Mkbn_mont_ctx__item__mu", "Hacl.Spec.Bignum.bn_add_mod_n_lemma" ]
[]
false
false
false
false
false
let bn_field_add #t k aM bM =
BN.bn_add_mod_n_lemma k.n aM bM; M.from_mont_add_lemma (bits t) k.len (bn_v k.n) (v k.mu) (bn_v aM) (bn_v bM); BN.bn_add_mod_n k.n aM bM
false
Hacl.Spec.Bignum.MontArithmetic.fst
Hacl.Spec.Bignum.MontArithmetic.bn_field_sub
val bn_field_sub: #t:limb_t -> k:bn_mont_ctx t{bn_mont_ctx_inv k} -> aM:bn_mont_nat k -> bM:bn_mont_nat k -> Pure (bn_mont_nat k) (requires True) (ensures fun cM -> bn_v (bn_from_field k cM) == (bn_v (bn_from_field k aM) - bn_v (bn_from_field k bM)) % bn_v k.n)
val bn_field_sub: #t:limb_t -> k:bn_mont_ctx t{bn_mont_ctx_inv k} -> aM:bn_mont_nat k -> bM:bn_mont_nat k -> Pure (bn_mont_nat k) (requires True) (ensures fun cM -> bn_v (bn_from_field k cM) == (bn_v (bn_from_field k aM) - bn_v (bn_from_field k bM)) % bn_v k.n)
let bn_field_sub #t k aM bM = BN.bn_sub_mod_n_lemma k.n aM bM; M.from_mont_sub_lemma (bits t) k.len (bn_v k.n) (v k.mu) (bn_v aM) (bn_v bM); BN.bn_sub_mod_n k.n aM bM
{ "file_name": "code/bignum/Hacl.Spec.Bignum.MontArithmetic.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 27, "end_line": 134, "start_col": 0, "start_line": 131 }
module Hacl.Spec.Bignum.MontArithmetic open FStar.Mul open Lib.IntTypes open Lib.Sequence open Hacl.Spec.Bignum.Definitions module M = Hacl.Spec.Montgomery.Lemmas module BM = Hacl.Spec.Bignum.Montgomery module BN = Hacl.Spec.Bignum module BB = Hacl.Spec.Bignum.Base module BL = Hacl.Spec.Bignum.Lib module BIL = Hacl.Spec.Bignum.ModInvLimb module E = Hacl.Spec.Exponentiation.Lemmas module ME = Hacl.Spec.Bignum.MontExponentiation module Euclid = FStar.Math.Euclid module BI = Hacl.Spec.Bignum.ModInv #set-options "--z3rlimit 50 --fuel 0 --ifuel 0" ////////////////////////////////////////// val mul_zero_lemma: n:pos{Euclid.is_prime n} -> x:int -> y:int -> Lemma (x * y % n == 0 <==> (x % n == 0 \/ y % n == 0)) let mul_zero_lemma n x y = assert (0 % n = 0); if x % n = 0 then Math.Lemmas.lemma_mod_mul_distr_l x y n else if y % n = 0 then Math.Lemmas.lemma_mod_mul_distr_r x y n else if x * y % n = 0 then Math.Fermat.mod_mult_congr n x 0 y else () val mul_nonzero_lemma: n:pos{Euclid.is_prime n} -> x:int -> y:int -> Lemma (requires x % n <> 0 /\ y % n <> 0) (ensures x * y % n <> 0) let mul_nonzero_lemma n x y = mul_zero_lemma n x y val from_mont_lemma_nonzero: pbits:pos -> rLen:pos -> n:pos -> mu:nat -> aM:nat -> Lemma (requires M.mont_pre pbits rLen n mu /\ 0 < aM /\ aM < n /\ Euclid.is_prime n) (ensures (let a = M.from_mont pbits rLen n mu aM in 0 < a /\ a < n)) let from_mont_lemma_nonzero pbits rLen n mu aM = let r = pow2 (pbits * rLen) in let d, _ = M.eea_pow2_odd (pbits * rLen) n in let a = M.from_mont pbits rLen n mu aM in M.from_mont_lemma pbits rLen n mu aM; assert (a == aM * d % n); assert (d <> 0); Math.Lemmas.small_mod aM n; assert (aM % n <> 0); let d1 = -d in assert (0 < d1 /\ d1 < n); Math.Lemmas.lemma_mod_sub_1 d1 n; assert ((-d1) % n == n - (d1 % n)); assert (d % n <> 0); mul_nonzero_lemma n aM d; assert (let a = M.from_mont pbits rLen n mu aM in 0 < a /\ a < n); // For some reason, this makes the proof instant. () /////////////////////////////////////////////// let bn_field_get_len #t k = k.len let bn_field_check_modulus #t #len n = let m = BM.bn_check_modulus n in BB.unsafe_bool_of_limb m let bn_field_init #t #len n = let nBits = bits t * BL.bn_get_top_index n in BL.bn_low_bound_bits_lemma n; BM.bn_precomp_r2_mod_n_lemma nBits n; let r2 = BM.bn_precomp_r2_mod_n nBits n in assert (bn_v r2 == pow2 (2 * bits t * len) % bn_v n); let mu = BIL.mod_inv_limb n.[0] in BIL.bn_mod_inv_limb_lemma n; assert ((1 + bn_v n * v mu) % pow2 (bits t) == 0); bn_eval_bound n len; { len = len; n = n; mu = mu; r2 = r2 } let bn_to_field #t k a = BM.bn_to_mont_lemma k.n k.mu k.r2 a; BM.bn_to_mont k.n k.mu k.r2 a let bn_from_field #t k aM = BM.bn_from_mont_lemma k.n k.mu aM; BM.bn_from_mont k.n k.mu aM let bn_from_to_field_lemma #t k a = bn_eval_bound a k.len; M.from_to_mont_lemma (bits t) k.len (bn_v k.n) (v k.mu) (bn_v a) let bn_field_add #t k aM bM = BN.bn_add_mod_n_lemma k.n aM bM; M.from_mont_add_lemma (bits t) k.len (bn_v k.n) (v k.mu) (bn_v aM) (bn_v bM); BN.bn_add_mod_n k.n aM bM
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "Lib.Sequence.fsti.checked", "Lib.NatMod.fsti.checked", "Lib.IntTypes.fsti.checked", "Hacl.Spec.Montgomery.Lemmas.fst.checked", "Hacl.Spec.Exponentiation.Lemmas.fst.checked", "Hacl.Spec.Bignum.Montgomery.fsti.checked", "Hacl.Spec.Bignum.MontExponentiation.fst.checked", "Hacl.Spec.Bignum.ModInvLimb.fsti.checked", "Hacl.Spec.Bignum.ModInv.fst.checked", "Hacl.Spec.Bignum.Lib.fst.checked", "Hacl.Spec.Bignum.Definitions.fst.checked", "Hacl.Spec.Bignum.Base.fst.checked", "Hacl.Spec.Bignum.fsti.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.Math.Fermat.fsti.checked", "FStar.Math.Euclid.fsti.checked" ], "interface_file": true, "source_file": "Hacl.Spec.Bignum.MontArithmetic.fst" }
[ { "abbrev": true, "full_module": "Hacl.Spec.Bignum.ModInv", "short_module": "BI" }, { "abbrev": true, "full_module": "Hacl.Spec.Bignum.MontExponentiation", "short_module": "ME" }, { "abbrev": true, "full_module": "Hacl.Spec.Exponentiation.Lemmas", "short_module": "E" }, { "abbrev": true, "full_module": "Hacl.Spec.Bignum.ModInvLimb", "short_module": "BIL" }, { "abbrev": true, "full_module": "Hacl.Spec.Bignum.Lib", "short_module": "BL" }, { "abbrev": true, "full_module": "Hacl.Spec.Bignum.Base", "short_module": "BB" }, { "abbrev": true, "full_module": "Hacl.Spec.Bignum.Montgomery", "short_module": "BM" }, { "abbrev": true, "full_module": "Hacl.Spec.Bignum", "short_module": "BN" }, { "abbrev": true, "full_module": "Hacl.Spec.Montgomery.Lemmas", "short_module": "M" }, { "abbrev": true, "full_module": "FStar.Math.Euclid", "short_module": "Euclid" }, { "abbrev": false, "full_module": "Hacl.Spec.Bignum.Definitions", "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.Bignum", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.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 } ]
{ "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" }
false
k: Hacl.Spec.Bignum.MontArithmetic.bn_mont_ctx t {Hacl.Spec.Bignum.MontArithmetic.bn_mont_ctx_inv k} -> aM: Hacl.Spec.Bignum.MontArithmetic.bn_mont_nat k -> bM: Hacl.Spec.Bignum.MontArithmetic.bn_mont_nat k -> Prims.Pure (Hacl.Spec.Bignum.MontArithmetic.bn_mont_nat k)
Prims.Pure
[]
[]
[ "Hacl.Spec.Bignum.Definitions.limb_t", "Hacl.Spec.Bignum.MontArithmetic.bn_mont_ctx", "Hacl.Spec.Bignum.MontArithmetic.bn_mont_ctx_inv", "Hacl.Spec.Bignum.MontArithmetic.bn_mont_nat", "Hacl.Spec.Bignum.bn_sub_mod_n", "Hacl.Spec.Bignum.MontArithmetic.__proj__Mkbn_mont_ctx__item__len", "Hacl.Spec.Bignum.MontArithmetic.__proj__Mkbn_mont_ctx__item__n", "Prims.unit", "Hacl.Spec.Montgomery.Lemmas.from_mont_sub_lemma", "Lib.IntTypes.bits", "Hacl.Spec.Bignum.Definitions.bn_v", "Lib.IntTypes.v", "Lib.IntTypes.SEC", "Hacl.Spec.Bignum.MontArithmetic.__proj__Mkbn_mont_ctx__item__mu", "Hacl.Spec.Bignum.bn_sub_mod_n_lemma" ]
[]
false
false
false
false
false
let bn_field_sub #t k aM bM =
BN.bn_sub_mod_n_lemma k.n aM bM; M.from_mont_sub_lemma (bits t) k.len (bn_v k.n) (v k.mu) (bn_v aM) (bn_v bM); BN.bn_sub_mod_n k.n aM bM
false
Hacl.Spec.Bignum.MontArithmetic.fst
Hacl.Spec.Bignum.MontArithmetic.bn_from_field
val bn_from_field: #t:limb_t -> k:bn_mont_ctx t{bn_mont_ctx_inv k} -> aM:bn_mont_nat k -> Pure (lbignum t k.len) (requires True) (ensures fun a -> bn_v a < bn_v k.n /\ bn_v a == M.from_mont (bits t) k.len (bn_v k.n) (v k.mu) (bn_v aM))
val bn_from_field: #t:limb_t -> k:bn_mont_ctx t{bn_mont_ctx_inv k} -> aM:bn_mont_nat k -> Pure (lbignum t k.len) (requires True) (ensures fun a -> bn_v a < bn_v k.n /\ bn_v a == M.from_mont (bits t) k.len (bn_v k.n) (v k.mu) (bn_v aM))
let bn_from_field #t k aM = BM.bn_from_mont_lemma k.n k.mu aM; BM.bn_from_mont k.n k.mu aM
{ "file_name": "code/bignum/Hacl.Spec.Bignum.MontArithmetic.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 29, "end_line": 117, "start_col": 0, "start_line": 115 }
module Hacl.Spec.Bignum.MontArithmetic open FStar.Mul open Lib.IntTypes open Lib.Sequence open Hacl.Spec.Bignum.Definitions module M = Hacl.Spec.Montgomery.Lemmas module BM = Hacl.Spec.Bignum.Montgomery module BN = Hacl.Spec.Bignum module BB = Hacl.Spec.Bignum.Base module BL = Hacl.Spec.Bignum.Lib module BIL = Hacl.Spec.Bignum.ModInvLimb module E = Hacl.Spec.Exponentiation.Lemmas module ME = Hacl.Spec.Bignum.MontExponentiation module Euclid = FStar.Math.Euclid module BI = Hacl.Spec.Bignum.ModInv #set-options "--z3rlimit 50 --fuel 0 --ifuel 0" ////////////////////////////////////////// val mul_zero_lemma: n:pos{Euclid.is_prime n} -> x:int -> y:int -> Lemma (x * y % n == 0 <==> (x % n == 0 \/ y % n == 0)) let mul_zero_lemma n x y = assert (0 % n = 0); if x % n = 0 then Math.Lemmas.lemma_mod_mul_distr_l x y n else if y % n = 0 then Math.Lemmas.lemma_mod_mul_distr_r x y n else if x * y % n = 0 then Math.Fermat.mod_mult_congr n x 0 y else () val mul_nonzero_lemma: n:pos{Euclid.is_prime n} -> x:int -> y:int -> Lemma (requires x % n <> 0 /\ y % n <> 0) (ensures x * y % n <> 0) let mul_nonzero_lemma n x y = mul_zero_lemma n x y val from_mont_lemma_nonzero: pbits:pos -> rLen:pos -> n:pos -> mu:nat -> aM:nat -> Lemma (requires M.mont_pre pbits rLen n mu /\ 0 < aM /\ aM < n /\ Euclid.is_prime n) (ensures (let a = M.from_mont pbits rLen n mu aM in 0 < a /\ a < n)) let from_mont_lemma_nonzero pbits rLen n mu aM = let r = pow2 (pbits * rLen) in let d, _ = M.eea_pow2_odd (pbits * rLen) n in let a = M.from_mont pbits rLen n mu aM in M.from_mont_lemma pbits rLen n mu aM; assert (a == aM * d % n); assert (d <> 0); Math.Lemmas.small_mod aM n; assert (aM % n <> 0); let d1 = -d in assert (0 < d1 /\ d1 < n); Math.Lemmas.lemma_mod_sub_1 d1 n; assert ((-d1) % n == n - (d1 % n)); assert (d % n <> 0); mul_nonzero_lemma n aM d; assert (let a = M.from_mont pbits rLen n mu aM in 0 < a /\ a < n); // For some reason, this makes the proof instant. () /////////////////////////////////////////////// let bn_field_get_len #t k = k.len let bn_field_check_modulus #t #len n = let m = BM.bn_check_modulus n in BB.unsafe_bool_of_limb m let bn_field_init #t #len n = let nBits = bits t * BL.bn_get_top_index n in BL.bn_low_bound_bits_lemma n; BM.bn_precomp_r2_mod_n_lemma nBits n; let r2 = BM.bn_precomp_r2_mod_n nBits n in assert (bn_v r2 == pow2 (2 * bits t * len) % bn_v n); let mu = BIL.mod_inv_limb n.[0] in BIL.bn_mod_inv_limb_lemma n; assert ((1 + bn_v n * v mu) % pow2 (bits t) == 0); bn_eval_bound n len; { len = len; n = n; mu = mu; r2 = r2 } let bn_to_field #t k a = BM.bn_to_mont_lemma k.n k.mu k.r2 a; BM.bn_to_mont k.n k.mu k.r2 a
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "Lib.Sequence.fsti.checked", "Lib.NatMod.fsti.checked", "Lib.IntTypes.fsti.checked", "Hacl.Spec.Montgomery.Lemmas.fst.checked", "Hacl.Spec.Exponentiation.Lemmas.fst.checked", "Hacl.Spec.Bignum.Montgomery.fsti.checked", "Hacl.Spec.Bignum.MontExponentiation.fst.checked", "Hacl.Spec.Bignum.ModInvLimb.fsti.checked", "Hacl.Spec.Bignum.ModInv.fst.checked", "Hacl.Spec.Bignum.Lib.fst.checked", "Hacl.Spec.Bignum.Definitions.fst.checked", "Hacl.Spec.Bignum.Base.fst.checked", "Hacl.Spec.Bignum.fsti.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.Math.Fermat.fsti.checked", "FStar.Math.Euclid.fsti.checked" ], "interface_file": true, "source_file": "Hacl.Spec.Bignum.MontArithmetic.fst" }
[ { "abbrev": true, "full_module": "Hacl.Spec.Bignum.ModInv", "short_module": "BI" }, { "abbrev": true, "full_module": "Hacl.Spec.Bignum.MontExponentiation", "short_module": "ME" }, { "abbrev": true, "full_module": "Hacl.Spec.Exponentiation.Lemmas", "short_module": "E" }, { "abbrev": true, "full_module": "Hacl.Spec.Bignum.ModInvLimb", "short_module": "BIL" }, { "abbrev": true, "full_module": "Hacl.Spec.Bignum.Lib", "short_module": "BL" }, { "abbrev": true, "full_module": "Hacl.Spec.Bignum.Base", "short_module": "BB" }, { "abbrev": true, "full_module": "Hacl.Spec.Bignum.Montgomery", "short_module": "BM" }, { "abbrev": true, "full_module": "Hacl.Spec.Bignum", "short_module": "BN" }, { "abbrev": true, "full_module": "Hacl.Spec.Montgomery.Lemmas", "short_module": "M" }, { "abbrev": true, "full_module": "FStar.Math.Euclid", "short_module": "Euclid" }, { "abbrev": false, "full_module": "Hacl.Spec.Bignum.Definitions", "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.Bignum", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.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 } ]
{ "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" }
false
k: Hacl.Spec.Bignum.MontArithmetic.bn_mont_ctx t {Hacl.Spec.Bignum.MontArithmetic.bn_mont_ctx_inv k} -> aM: Hacl.Spec.Bignum.MontArithmetic.bn_mont_nat k -> Prims.Pure (Hacl.Spec.Bignum.Definitions.lbignum t (Mkbn_mont_ctx?.len k))
Prims.Pure
[]
[]
[ "Hacl.Spec.Bignum.Definitions.limb_t", "Hacl.Spec.Bignum.MontArithmetic.bn_mont_ctx", "Hacl.Spec.Bignum.MontArithmetic.bn_mont_ctx_inv", "Hacl.Spec.Bignum.MontArithmetic.bn_mont_nat", "Hacl.Spec.Bignum.Montgomery.bn_from_mont", "Hacl.Spec.Bignum.MontArithmetic.__proj__Mkbn_mont_ctx__item__len", "Hacl.Spec.Bignum.MontArithmetic.__proj__Mkbn_mont_ctx__item__n", "Hacl.Spec.Bignum.MontArithmetic.__proj__Mkbn_mont_ctx__item__mu", "Prims.unit", "Hacl.Spec.Bignum.Montgomery.bn_from_mont_lemma", "Hacl.Spec.Bignum.Definitions.lbignum" ]
[]
false
false
false
false
false
let bn_from_field #t k aM =
BM.bn_from_mont_lemma k.n k.mu aM; BM.bn_from_mont k.n k.mu aM
false
Vale.AsLowStar.Test.fst
Vale.AsLowStar.Test.lowstar_ta
val lowstar_ta:lowstar_ta_t
val lowstar_ta:lowstar_ta_t
let lowstar_ta : lowstar_ta_t = IX64.wrap_weak_stdcall (coerce code_ta) ta_dom (W.mk_prediction code_ta ta_dom [] (ta_lemma code_ta IA.win))
{ "file_name": "vale/code/arch/x64/interop/Vale.AsLowStar.Test.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 65, "end_line": 393, "start_col": 0, "start_line": 389 }
module Vale.AsLowStar.Test open FStar.Mul open Vale.Interop.Base module ME = Vale.X64.Memory module IA = Vale.Interop.Assumptions module V = Vale.X64.Decls module IX64 = Vale.Interop.X64 module VSig = Vale.AsLowStar.ValeSig module LSig = Vale.AsLowStar.LowStarSig module W = Vale.AsLowStar.Wrapper module VS = Vale.X64.State module MS = Vale.X64.Machine_s (* A little utility to trigger normalization in types *) let as_t (#a:Type) (x:normal a) : a = x let as_normal_t (#a:Type) (x:a) : normal a = x //////////////////////////////////////////////////////////////////////////////// //First a little standalone, toy experiment [@__reduce__] let b64 = buf_t TUInt8 TUInt64 [@__reduce__] let ib64 = ibuf_t TUInt8 TUInt64 [@__reduce__] let t64_mod = TD_Buffer TUInt8 TUInt64 default_bq [@__reduce__] let t64_no_mod = TD_Buffer TUInt8 TUInt64 ({modified=false; strict_disjointness=false; taint=MS.Secret}) [@__reduce__] let t64_imm = TD_ImmBuffer TUInt8 TUInt64 ({modified=false; strict_disjointness=false; taint=MS.Secret}) [@__reduce__] let (dom : list td{List.length dom <= 20}) = let y = [t64_mod;t64_imm] in assert_norm (List.length y = 2); y assume val pre : VSig.vale_pre dom assume val post : VSig.vale_post dom assume val v: VSig.vale_sig_stdcall pre post assume val c: V.va_code [@__reduce__] let call_c_t = IX64.as_lowstar_sig_t_weak_stdcall c dom [] _ _ (W.mk_prediction c dom [] (v c IA.win)) let call_c : call_c_t = IX64.wrap_weak_stdcall c dom (W.mk_prediction c dom [] (v c IA.win)) let call_c_normal_t : normal call_c_t = as_normal_t #call_c_t call_c //You can ask emacs to show you the type of call_c_normal_t ... //////////////////////////////////////////////////////////////////////////////// //Now memcpy module VM = Vale.Test.X64.Vale_memcpy [@__reduce__] let vm_dom = [t64_mod; t64_imm] open Vale.X64.MemoryAdapters (* Need to rearrange the order of arguments *) [@__reduce__] let vm_pre : VSig.vale_pre vm_dom = fun (c:V.va_code) (dst:b64) (src:ib64) (va_s0:V.va_state) -> VM.va_req_Memcpy c va_s0 IA.win (as_vale_buffer dst) (as_vale_immbuffer src) [@__reduce__] let vm_post : VSig.vale_post vm_dom = fun (c:V.va_code) (dst:b64) (src:ib64) (va_s0:V.va_state) (va_s1:V.va_state) (f:V.va_fuel) -> VM.va_ens_Memcpy c va_s0 IA.win (as_vale_buffer dst) (as_vale_immbuffer src) va_s1 f module VS = Vale.X64.State #reset-options "--print_effect_args --z3rlimit 200" (* The vale lemma doesn't quite suffice to prove the modifies clause expected of the interop layer *) [@__reduce__] let vm_lemma' (code:V.va_code) (_win:bool) (dst:b64) (src:ib64) (va_s0:V.va_state) : Ghost (V.va_state & V.va_fuel) (requires vm_pre code dst src va_s0) (ensures (fun (va_s1, f) -> V.eval_code code va_s0 f va_s1 /\ VSig.vale_calling_conventions_stdcall va_s0 va_s1 /\ vm_post code dst src va_s0 va_s1 f /\ ME.buffer_readable (VS.vs_get_vale_heap va_s1) (as_vale_immbuffer src) /\ ME.buffer_readable (VS.vs_get_vale_heap va_s1) (as_vale_buffer dst) /\ ME.buffer_writeable (as_vale_buffer dst) /\ ME.modifies (ME.loc_union (ME.loc_buffer (as_vale_buffer dst)) ME.loc_none) (VS.vs_get_vale_heap va_s0) (VS.vs_get_vale_heap va_s1) )) = let va_s1, f = VM.va_lemma_Memcpy code va_s0 IA.win (as_vale_buffer dst) (as_vale_immbuffer src) in Vale.AsLowStar.MemoryHelpers.buffer_writeable_reveal ME.TUInt8 ME.TUInt64 dst; (va_s1, f) (* Prove that vm_lemma' has the required type *) let vm_lemma = as_t #(VSig.vale_sig_stdcall vm_pre vm_post) vm_lemma' let code_Memcpy = VM.va_code_Memcpy IA.win (* Here's the type expected for the memcpy wrapper *) [@__reduce__] let lowstar_Memcpy_t = IX64.as_lowstar_sig_t_weak_stdcall code_Memcpy vm_dom [] _ _ (W.mk_prediction code_Memcpy vm_dom [] (vm_lemma code_Memcpy IA.win)) (* And here's the memcpy wrapper itself *) let lowstar_Memcpy : lowstar_Memcpy_t = IX64.wrap_weak_stdcall code_Memcpy vm_dom (W.mk_prediction code_Memcpy vm_dom [] (vm_lemma code_Memcpy IA.win)) let lowstar_Memcpy_normal_t //: normal lowstar_Memcpy_t = as_normal_t #lowstar_Memcpy_t lowstar_Memcpy module B = LowStar.Buffer module IB = LowStar.ImmutableBuffer module MB = LowStar.Monotonic.Buffer open FStar.HyperStack.ST module M = Vale.X64.Memory let test (x:b64) = assert (V.buffer_length (as_vale_buffer x) == (B.length x * view_n TUInt8) / view_n TUInt64); assert (V.buffer_length (as_vale_buffer x) == B.length x / 8) let itest (x:ib64) = assert (V.buffer_length (as_vale_immbuffer x) == (B.length x * view_n TUInt8) / view_n TUInt64); assert (V.buffer_length (as_vale_immbuffer x) == B.length x / 8) module T = FStar.Tactics #reset-options "--using_facts_from '* -FStar.Tactics -FStar.Reflection'" module LBV = LowStar.BufferView.Up module DV = LowStar.BufferView.Down #push-options "--ext compat:normalizer_memo_ignore_cfg" let memcpy_Test (dst:B.buffer UInt8.t{B.length dst % 8 == 0}) (src:IB.ibuffer UInt8.t{B.length src % 8 == 0}) : Stack UInt64.t (requires fun h0 -> B.live h0 dst /\ B.live h0 src /\ B.disjoint dst src /\ B.length dst == 16 /\ B.length src == 16) (ensures fun h0 _ h1 -> B.modifies (B.loc_buffer dst) h0 h1 /\ B.live h1 src /\ B.live h1 dst) // B.as_seq h1 dst == B.as_seq h1 src) // by (T.dump "A") (* in case you want to look at the VC *) = IB.inhabited_immutable_buffer_is_distinct_from_buffer (UInt8.uint_to_t 0) src dst; let (x, _) = lowstar_Memcpy_normal_t dst src () in //This is a call to the interop wrapper let h1 = get () in // let v = Vale.Interop.Views.up_view64 in // assert (DV.length_eq (get_downview dst); // DV.length_eq (get_downview src); // Seq.equal (LBV.as_seq h1 (LBV.mk_buffer (get_downview dst) v)) // (LBV.as_seq h1 (LBV.mk_buffer (get_downview src) v))); // lbv_as_seq_eq dst src Vale.Interop.Views.up_view64 h1; //And a lemma to rephrase the Vale postcondition x //with equalities of buffer views //back to equalities of buffers #pop-options module VC = Vale.Lib.X64.Cpuidstdcall [@__reduce__] let empty_list #a : l:list a {List.length l = 0} = [] [@__reduce__] let aesni_dom : IX64.arity_ok_stdcall td = [] (* Need to rearrange the order of arguments *) [@__reduce__] let aesni_pre : VSig.vale_pre aesni_dom = fun (c:V.va_code) (va_s0:V.va_state) -> VC.va_req_Check_aesni_stdcall c va_s0 IA.win [@__reduce__] let aesni_post : VSig.vale_post aesni_dom = fun (c:V.va_code) (va_s0:V.va_state) (va_s1:V.va_state) (f:V.va_fuel) -> VC.va_ens_Check_aesni_stdcall c va_s0 IA.win va_s1 f [@__reduce__] let with_len (l:list 'a) : Pure (list 'a) (requires True) (ensures fun m -> m==l /\ List.length m == normalize_term (List.length l)) = l #set-options "--max_fuel 0 --max_ifuel 1 --z3rlimit_factor 2" (* The vale lemma doesn't quite suffice to prove the modifies clause expected of the interop layer *) [@__reduce__] let aesni_lemma' (code:V.va_code) (_win:bool) (va_s0:V.va_state) : Ghost (V.va_state & V.va_fuel) (requires aesni_pre code va_s0) (ensures (fun (va_s1, f) -> V.eval_code code va_s0 f va_s1 /\ VSig.vale_calling_conventions_stdcall va_s0 va_s1 /\ aesni_post code va_s0 va_s1 f)) = VC.va_lemma_Check_aesni_stdcall code va_s0 IA.win #set-options "--max_fuel 0 --max_ifuel 0 --z3rlimit_factor 2" (* Prove that vm_lemma' has the required type *) let aesni_lemma = as_t #(VSig.vale_sig_stdcall aesni_pre aesni_post) aesni_lemma' let code_aesni = VC.va_code_Check_aesni_stdcall IA.win (* Here's the type expected for the check_aesni wrapper *) [@__reduce__] let lowstar_aesni_t = IX64.as_lowstar_sig_t_weak_stdcall (coerce code_aesni) aesni_dom empty_list _ _ (W.mk_prediction code_aesni aesni_dom [] (aesni_lemma code_aesni IA.win)) (* And here's the check_aesni wrapper itself *) let lowstar_aesni : lowstar_aesni_t = IX64.wrap_weak_stdcall (coerce code_aesni) aesni_dom (W.mk_prediction code_aesni aesni_dom [] (aesni_lemma code_aesni IA.win)) let lowstar_aesni_normal_t //: normal lowstar_aesni_t = as_normal_t #lowstar_aesni_t lowstar_aesni open Vale.X64.CPU_Features_s #set-options "--print_full_names" let aesni_Test () : Stack UInt64.t (requires fun h0 -> True) (ensures fun h0 ret_val h1 -> (UInt64.v ret_val) =!= 0 ==> aesni_enabled /\ pclmulqdq_enabled) // by (T.dump "A") (* in case you want to look at the VC *) = let (x, _) = lowstar_aesni_normal_t () in //This is a call to the interop wrapper x module TA = Vale.Test.X64.Args [@__reduce__] let (ta_dom:list td{List.length ta_dom <= 20}) = let y = [t64_imm; t64_imm; t64_imm; t64_imm; t64_imm; t64_imm; t64_imm; t64_imm] in assert_norm (List.length y = 8); y (* Need to rearrange the order of arguments *) [@__reduce__] let ta_pre : VSig.vale_pre ta_dom = fun (c:V.va_code) (arg0:ib64) (arg1:ib64) (arg2:ib64) (arg3:ib64) (arg4:ib64) (arg5:ib64) (arg6:ib64) (arg7:ib64) (va_s0:V.va_state) -> TA.va_req_Test c va_s0 IA.win (as_vale_immbuffer arg0) (as_vale_immbuffer arg1) (as_vale_immbuffer arg2) (as_vale_immbuffer arg3) (as_vale_immbuffer arg4) (as_vale_immbuffer arg5) (as_vale_immbuffer arg6) (as_vale_immbuffer arg7) [@__reduce__] let ta_post : VSig.vale_post ta_dom = fun (c:V.va_code) (arg0:ib64) (arg1:ib64) (arg2:ib64) (arg3:ib64) (arg4:ib64) (arg5:ib64) (arg6:ib64) (arg7:ib64) (va_s0:V.va_state) (va_s1:V.va_state) (f:V.va_fuel) -> TA.va_ens_Test c va_s0 IA.win (as_vale_immbuffer arg0) (as_vale_immbuffer arg1) (as_vale_immbuffer arg2) (as_vale_immbuffer arg3) (as_vale_immbuffer arg4) (as_vale_immbuffer arg5) (as_vale_immbuffer arg6) (as_vale_immbuffer arg7) va_s1 f #reset-options "--max_fuel 0 --max_ifuel 0 --z3rlimit 100" (* The vale lemma doesn't quite suffice to prove the modifies clause expected of the interop layer *) [@__reduce__] let ta_lemma' (code:V.va_code) (_win:bool) (arg0:ib64) (arg1:ib64) (arg2:ib64) (arg3:ib64) (arg4:ib64) (arg5:ib64) (arg6:ib64) (arg7:ib64) (va_s0:V.va_state) : Ghost (V.va_state & V.va_fuel) (requires ta_pre code arg0 arg1 arg2 arg3 arg4 arg5 arg6 arg7 va_s0) (ensures (fun (va_s1, f) -> V.eval_code code va_s0 f va_s1 /\ VSig.vale_calling_conventions_stdcall va_s0 va_s1 /\ ta_post code arg0 arg1 arg2 arg3 arg4 arg5 arg6 arg7 va_s0 va_s1 f /\ ME.buffer_readable (VS.vs_get_vale_heap va_s1) (as_vale_immbuffer arg0) /\ ME.buffer_readable (VS.vs_get_vale_heap va_s1) (as_vale_immbuffer arg1) /\ ME.buffer_readable (VS.vs_get_vale_heap va_s1) (as_vale_immbuffer arg2) /\ ME.buffer_readable (VS.vs_get_vale_heap va_s1) (as_vale_immbuffer arg3) /\ ME.buffer_readable (VS.vs_get_vale_heap va_s1) (as_vale_immbuffer arg4) /\ ME.buffer_readable (VS.vs_get_vale_heap va_s1) (as_vale_immbuffer arg5) /\ ME.buffer_readable (VS.vs_get_vale_heap va_s1) (as_vale_immbuffer arg6) /\ ME.buffer_readable (VS.vs_get_vale_heap va_s1) (as_vale_immbuffer arg7) /\ ME.modifies ME.loc_none (VS.vs_get_vale_heap va_s0) (VS.vs_get_vale_heap va_s1))) = let va_s1, f = TA.va_lemma_Test code va_s0 IA.win (as_vale_immbuffer arg0) (as_vale_immbuffer arg1) (as_vale_immbuffer arg2) (as_vale_immbuffer arg3) (as_vale_immbuffer arg4) (as_vale_immbuffer arg5) (as_vale_immbuffer arg6) (as_vale_immbuffer arg7) in va_s1, f (* Prove that vm_lemma' has the required type *) let ta_lemma = as_t #(VSig.vale_sig_stdcall ta_pre ta_post) ta_lemma' let code_ta = TA.va_code_Test IA.win (* Here's the type expected for the check_aesni wrapper *) [@__reduce__] let lowstar_ta_t = IX64.as_lowstar_sig_t_weak_stdcall (coerce code_ta) ta_dom [] _ _ (W.mk_prediction code_ta ta_dom [] (ta_lemma code_ta IA.win))
{ "checked_file": "/", "dependencies": [ "Vale.X64.State.fsti.checked", "Vale.X64.MemoryAdapters.fsti.checked", "Vale.X64.Memory.fsti.checked", "Vale.X64.Machine_s.fst.checked", "Vale.X64.Decls.fsti.checked", "Vale.X64.CPU_Features_s.fst.checked", "Vale.Test.X64.Vale_memcpy.fsti.checked", "Vale.Test.X64.Args.fsti.checked", "Vale.Lib.X64.Cpuidstdcall.fsti.checked", "Vale.Interop.X64.fsti.checked", "Vale.Interop.Base.fst.checked", "Vale.Interop.Assumptions.fst.checked", "Vale.AsLowStar.Wrapper.fsti.checked", "Vale.AsLowStar.ValeSig.fst.checked", "Vale.AsLowStar.MemoryHelpers.fsti.checked", "Vale.AsLowStar.LowStarSig.fst.checked", "prims.fst.checked", "LowStar.Monotonic.Buffer.fsti.checked", "LowStar.ImmutableBuffer.fst.checked", "LowStar.BufferView.Up.fsti.checked", "LowStar.BufferView.Down.fsti.checked", "LowStar.Buffer.fst.checked", "FStar.UInt8.fsti.checked", "FStar.UInt64.fsti.checked", "FStar.Tactics.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.List.fst.checked", "FStar.HyperStack.ST.fsti.checked" ], "interface_file": false, "source_file": "Vale.AsLowStar.Test.fst" }
[ { "abbrev": true, "full_module": "Vale.Test.X64.Args", "short_module": "TA" }, { "abbrev": false, "full_module": "Vale.X64.CPU_Features_s", "short_module": null }, { "abbrev": true, "full_module": "Vale.Lib.X64.Cpuidstdcall", "short_module": "VC" }, { "abbrev": true, "full_module": "LowStar.BufferView.Down", "short_module": "DV" }, { "abbrev": true, "full_module": "LowStar.BufferView.Up", "short_module": "LBV" }, { "abbrev": true, "full_module": "FStar.Tactics", "short_module": "T" }, { "abbrev": true, "full_module": "Vale.X64.Memory", "short_module": "M" }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": true, "full_module": "LowStar.Monotonic.Buffer", "short_module": "MB" }, { "abbrev": true, "full_module": "LowStar.ImmutableBuffer", "short_module": "IB" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "Vale.X64.State", "short_module": "VS" }, { "abbrev": false, "full_module": "Vale.X64.MemoryAdapters", "short_module": null }, { "abbrev": true, "full_module": "Vale.Test.X64.Vale_memcpy", "short_module": "VM" }, { "abbrev": true, "full_module": "Vale.X64.Machine_s", "short_module": "MS" }, { "abbrev": true, "full_module": "Vale.X64.State", "short_module": "VS" }, { "abbrev": true, "full_module": "Vale.AsLowStar.Wrapper", "short_module": "W" }, { "abbrev": true, "full_module": "Vale.AsLowStar.LowStarSig", "short_module": "LSig" }, { "abbrev": true, "full_module": "Vale.AsLowStar.ValeSig", "short_module": "VSig" }, { "abbrev": true, "full_module": "Vale.Interop.X64", "short_module": "IX64" }, { "abbrev": true, "full_module": "Vale.X64.Decls", "short_module": "V" }, { "abbrev": true, "full_module": "Vale.Interop.Assumptions", "short_module": "IA" }, { "abbrev": true, "full_module": "Vale.X64.Memory", "short_module": "ME" }, { "abbrev": false, "full_module": "Vale.Interop.Base", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.AsLowStar", "short_module": null }, { "abbrev": false, "full_module": "Vale.AsLowStar", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 0, "max_fuel": 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": 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" }
false
Vale.AsLowStar.Test.lowstar_ta_t
Prims.Tot
[ "total" ]
[]
[ "Vale.Interop.X64.wrap_weak_stdcall", "Vale.X64.MemoryAdapters.coerce", "Vale.X64.Machine_Semantics_s.code", "Vale.X64.Decls.va_code", "Vale.AsLowStar.Test.code_ta", "Vale.AsLowStar.Test.ta_dom", "Vale.AsLowStar.Wrapper.pre_rel_generic", "Vale.Interop.X64.max_stdcall", "Vale.Interop.X64.arg_reg_stdcall", "Prims.Nil", "Vale.Interop.Base.arg", "Vale.AsLowStar.Test.ta_pre", "Vale.AsLowStar.Wrapper.post_rel_generic", "Vale.AsLowStar.Test.ta_post", "Vale.AsLowStar.Wrapper.mk_prediction", "Vale.Interop.X64.regs_modified_stdcall", "Vale.Interop.X64.xmms_modified_stdcall", "Vale.AsLowStar.Test.ta_lemma", "Vale.Interop.Assumptions.win" ]
[]
false
false
false
true
false
let lowstar_ta:lowstar_ta_t =
IX64.wrap_weak_stdcall (coerce code_ta) ta_dom (W.mk_prediction code_ta ta_dom [] (ta_lemma code_ta IA.win))
false
Vale.AsLowStar.Test.fst
Vale.AsLowStar.Test.lowstar_aesni_t
val lowstar_aesni_t : Type0
let lowstar_aesni_t = IX64.as_lowstar_sig_t_weak_stdcall (coerce code_aesni) aesni_dom empty_list _ _ (W.mk_prediction code_aesni aesni_dom [] (aesni_lemma code_aesni IA.win))
{ "file_name": "vale/code/arch/x64/interop/Vale.AsLowStar.Test.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 77, "end_line": 245, "start_col": 0, "start_line": 238 }
module Vale.AsLowStar.Test open FStar.Mul open Vale.Interop.Base module ME = Vale.X64.Memory module IA = Vale.Interop.Assumptions module V = Vale.X64.Decls module IX64 = Vale.Interop.X64 module VSig = Vale.AsLowStar.ValeSig module LSig = Vale.AsLowStar.LowStarSig module W = Vale.AsLowStar.Wrapper module VS = Vale.X64.State module MS = Vale.X64.Machine_s (* A little utility to trigger normalization in types *) let as_t (#a:Type) (x:normal a) : a = x let as_normal_t (#a:Type) (x:a) : normal a = x //////////////////////////////////////////////////////////////////////////////// //First a little standalone, toy experiment [@__reduce__] let b64 = buf_t TUInt8 TUInt64 [@__reduce__] let ib64 = ibuf_t TUInt8 TUInt64 [@__reduce__] let t64_mod = TD_Buffer TUInt8 TUInt64 default_bq [@__reduce__] let t64_no_mod = TD_Buffer TUInt8 TUInt64 ({modified=false; strict_disjointness=false; taint=MS.Secret}) [@__reduce__] let t64_imm = TD_ImmBuffer TUInt8 TUInt64 ({modified=false; strict_disjointness=false; taint=MS.Secret}) [@__reduce__] let (dom : list td{List.length dom <= 20}) = let y = [t64_mod;t64_imm] in assert_norm (List.length y = 2); y assume val pre : VSig.vale_pre dom assume val post : VSig.vale_post dom assume val v: VSig.vale_sig_stdcall pre post assume val c: V.va_code [@__reduce__] let call_c_t = IX64.as_lowstar_sig_t_weak_stdcall c dom [] _ _ (W.mk_prediction c dom [] (v c IA.win)) let call_c : call_c_t = IX64.wrap_weak_stdcall c dom (W.mk_prediction c dom [] (v c IA.win)) let call_c_normal_t : normal call_c_t = as_normal_t #call_c_t call_c //You can ask emacs to show you the type of call_c_normal_t ... //////////////////////////////////////////////////////////////////////////////// //Now memcpy module VM = Vale.Test.X64.Vale_memcpy [@__reduce__] let vm_dom = [t64_mod; t64_imm] open Vale.X64.MemoryAdapters (* Need to rearrange the order of arguments *) [@__reduce__] let vm_pre : VSig.vale_pre vm_dom = fun (c:V.va_code) (dst:b64) (src:ib64) (va_s0:V.va_state) -> VM.va_req_Memcpy c va_s0 IA.win (as_vale_buffer dst) (as_vale_immbuffer src) [@__reduce__] let vm_post : VSig.vale_post vm_dom = fun (c:V.va_code) (dst:b64) (src:ib64) (va_s0:V.va_state) (va_s1:V.va_state) (f:V.va_fuel) -> VM.va_ens_Memcpy c va_s0 IA.win (as_vale_buffer dst) (as_vale_immbuffer src) va_s1 f module VS = Vale.X64.State #reset-options "--print_effect_args --z3rlimit 200" (* The vale lemma doesn't quite suffice to prove the modifies clause expected of the interop layer *) [@__reduce__] let vm_lemma' (code:V.va_code) (_win:bool) (dst:b64) (src:ib64) (va_s0:V.va_state) : Ghost (V.va_state & V.va_fuel) (requires vm_pre code dst src va_s0) (ensures (fun (va_s1, f) -> V.eval_code code va_s0 f va_s1 /\ VSig.vale_calling_conventions_stdcall va_s0 va_s1 /\ vm_post code dst src va_s0 va_s1 f /\ ME.buffer_readable (VS.vs_get_vale_heap va_s1) (as_vale_immbuffer src) /\ ME.buffer_readable (VS.vs_get_vale_heap va_s1) (as_vale_buffer dst) /\ ME.buffer_writeable (as_vale_buffer dst) /\ ME.modifies (ME.loc_union (ME.loc_buffer (as_vale_buffer dst)) ME.loc_none) (VS.vs_get_vale_heap va_s0) (VS.vs_get_vale_heap va_s1) )) = let va_s1, f = VM.va_lemma_Memcpy code va_s0 IA.win (as_vale_buffer dst) (as_vale_immbuffer src) in Vale.AsLowStar.MemoryHelpers.buffer_writeable_reveal ME.TUInt8 ME.TUInt64 dst; (va_s1, f) (* Prove that vm_lemma' has the required type *) let vm_lemma = as_t #(VSig.vale_sig_stdcall vm_pre vm_post) vm_lemma' let code_Memcpy = VM.va_code_Memcpy IA.win (* Here's the type expected for the memcpy wrapper *) [@__reduce__] let lowstar_Memcpy_t = IX64.as_lowstar_sig_t_weak_stdcall code_Memcpy vm_dom [] _ _ (W.mk_prediction code_Memcpy vm_dom [] (vm_lemma code_Memcpy IA.win)) (* And here's the memcpy wrapper itself *) let lowstar_Memcpy : lowstar_Memcpy_t = IX64.wrap_weak_stdcall code_Memcpy vm_dom (W.mk_prediction code_Memcpy vm_dom [] (vm_lemma code_Memcpy IA.win)) let lowstar_Memcpy_normal_t //: normal lowstar_Memcpy_t = as_normal_t #lowstar_Memcpy_t lowstar_Memcpy module B = LowStar.Buffer module IB = LowStar.ImmutableBuffer module MB = LowStar.Monotonic.Buffer open FStar.HyperStack.ST module M = Vale.X64.Memory let test (x:b64) = assert (V.buffer_length (as_vale_buffer x) == (B.length x * view_n TUInt8) / view_n TUInt64); assert (V.buffer_length (as_vale_buffer x) == B.length x / 8) let itest (x:ib64) = assert (V.buffer_length (as_vale_immbuffer x) == (B.length x * view_n TUInt8) / view_n TUInt64); assert (V.buffer_length (as_vale_immbuffer x) == B.length x / 8) module T = FStar.Tactics #reset-options "--using_facts_from '* -FStar.Tactics -FStar.Reflection'" module LBV = LowStar.BufferView.Up module DV = LowStar.BufferView.Down #push-options "--ext compat:normalizer_memo_ignore_cfg" let memcpy_Test (dst:B.buffer UInt8.t{B.length dst % 8 == 0}) (src:IB.ibuffer UInt8.t{B.length src % 8 == 0}) : Stack UInt64.t (requires fun h0 -> B.live h0 dst /\ B.live h0 src /\ B.disjoint dst src /\ B.length dst == 16 /\ B.length src == 16) (ensures fun h0 _ h1 -> B.modifies (B.loc_buffer dst) h0 h1 /\ B.live h1 src /\ B.live h1 dst) // B.as_seq h1 dst == B.as_seq h1 src) // by (T.dump "A") (* in case you want to look at the VC *) = IB.inhabited_immutable_buffer_is_distinct_from_buffer (UInt8.uint_to_t 0) src dst; let (x, _) = lowstar_Memcpy_normal_t dst src () in //This is a call to the interop wrapper let h1 = get () in // let v = Vale.Interop.Views.up_view64 in // assert (DV.length_eq (get_downview dst); // DV.length_eq (get_downview src); // Seq.equal (LBV.as_seq h1 (LBV.mk_buffer (get_downview dst) v)) // (LBV.as_seq h1 (LBV.mk_buffer (get_downview src) v))); // lbv_as_seq_eq dst src Vale.Interop.Views.up_view64 h1; //And a lemma to rephrase the Vale postcondition x //with equalities of buffer views //back to equalities of buffers #pop-options module VC = Vale.Lib.X64.Cpuidstdcall [@__reduce__] let empty_list #a : l:list a {List.length l = 0} = [] [@__reduce__] let aesni_dom : IX64.arity_ok_stdcall td = [] (* Need to rearrange the order of arguments *) [@__reduce__] let aesni_pre : VSig.vale_pre aesni_dom = fun (c:V.va_code) (va_s0:V.va_state) -> VC.va_req_Check_aesni_stdcall c va_s0 IA.win [@__reduce__] let aesni_post : VSig.vale_post aesni_dom = fun (c:V.va_code) (va_s0:V.va_state) (va_s1:V.va_state) (f:V.va_fuel) -> VC.va_ens_Check_aesni_stdcall c va_s0 IA.win va_s1 f [@__reduce__] let with_len (l:list 'a) : Pure (list 'a) (requires True) (ensures fun m -> m==l /\ List.length m == normalize_term (List.length l)) = l #set-options "--max_fuel 0 --max_ifuel 1 --z3rlimit_factor 2" (* The vale lemma doesn't quite suffice to prove the modifies clause expected of the interop layer *) [@__reduce__] let aesni_lemma' (code:V.va_code) (_win:bool) (va_s0:V.va_state) : Ghost (V.va_state & V.va_fuel) (requires aesni_pre code va_s0) (ensures (fun (va_s1, f) -> V.eval_code code va_s0 f va_s1 /\ VSig.vale_calling_conventions_stdcall va_s0 va_s1 /\ aesni_post code va_s0 va_s1 f)) = VC.va_lemma_Check_aesni_stdcall code va_s0 IA.win #set-options "--max_fuel 0 --max_ifuel 0 --z3rlimit_factor 2" (* Prove that vm_lemma' has the required type *) let aesni_lemma = as_t #(VSig.vale_sig_stdcall aesni_pre aesni_post) aesni_lemma' let code_aesni = VC.va_code_Check_aesni_stdcall IA.win (* Here's the type expected for the check_aesni wrapper *)
{ "checked_file": "/", "dependencies": [ "Vale.X64.State.fsti.checked", "Vale.X64.MemoryAdapters.fsti.checked", "Vale.X64.Memory.fsti.checked", "Vale.X64.Machine_s.fst.checked", "Vale.X64.Decls.fsti.checked", "Vale.X64.CPU_Features_s.fst.checked", "Vale.Test.X64.Vale_memcpy.fsti.checked", "Vale.Test.X64.Args.fsti.checked", "Vale.Lib.X64.Cpuidstdcall.fsti.checked", "Vale.Interop.X64.fsti.checked", "Vale.Interop.Base.fst.checked", "Vale.Interop.Assumptions.fst.checked", "Vale.AsLowStar.Wrapper.fsti.checked", "Vale.AsLowStar.ValeSig.fst.checked", "Vale.AsLowStar.MemoryHelpers.fsti.checked", "Vale.AsLowStar.LowStarSig.fst.checked", "prims.fst.checked", "LowStar.Monotonic.Buffer.fsti.checked", "LowStar.ImmutableBuffer.fst.checked", "LowStar.BufferView.Up.fsti.checked", "LowStar.BufferView.Down.fsti.checked", "LowStar.Buffer.fst.checked", "FStar.UInt8.fsti.checked", "FStar.UInt64.fsti.checked", "FStar.Tactics.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.List.fst.checked", "FStar.HyperStack.ST.fsti.checked" ], "interface_file": false, "source_file": "Vale.AsLowStar.Test.fst" }
[ { "abbrev": true, "full_module": "Vale.Lib.X64.Cpuidstdcall", "short_module": "VC" }, { "abbrev": true, "full_module": "LowStar.BufferView.Down", "short_module": "DV" }, { "abbrev": true, "full_module": "LowStar.BufferView.Up", "short_module": "LBV" }, { "abbrev": true, "full_module": "FStar.Tactics", "short_module": "T" }, { "abbrev": true, "full_module": "Vale.X64.Memory", "short_module": "M" }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": true, "full_module": "LowStar.Monotonic.Buffer", "short_module": "MB" }, { "abbrev": true, "full_module": "LowStar.ImmutableBuffer", "short_module": "IB" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "Vale.X64.State", "short_module": "VS" }, { "abbrev": false, "full_module": "Vale.X64.MemoryAdapters", "short_module": null }, { "abbrev": true, "full_module": "Vale.Test.X64.Vale_memcpy", "short_module": "VM" }, { "abbrev": true, "full_module": "Vale.X64.Machine_s", "short_module": "MS" }, { "abbrev": true, "full_module": "Vale.X64.State", "short_module": "VS" }, { "abbrev": true, "full_module": "Vale.AsLowStar.Wrapper", "short_module": "W" }, { "abbrev": true, "full_module": "Vale.AsLowStar.LowStarSig", "short_module": "LSig" }, { "abbrev": true, "full_module": "Vale.AsLowStar.ValeSig", "short_module": "VSig" }, { "abbrev": true, "full_module": "Vale.Interop.X64", "short_module": "IX64" }, { "abbrev": true, "full_module": "Vale.X64.Decls", "short_module": "V" }, { "abbrev": true, "full_module": "Vale.Interop.Assumptions", "short_module": "IA" }, { "abbrev": true, "full_module": "Vale.X64.Memory", "short_module": "ME" }, { "abbrev": false, "full_module": "Vale.Interop.Base", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.AsLowStar", "short_module": null }, { "abbrev": false, "full_module": "Vale.AsLowStar", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 0, "max_fuel": 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": true, "smtencoding_l_arith_repr": "native", "smtencoding_nl_arith_repr": "wrapped", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [ "smt.arith.nl=false", "smt.QI.EAGER_THRESHOLD=100", "smt.CASE_SPLIT=3" ], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 2, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
Type0
Prims.Tot
[ "total" ]
[]
[ "Vale.Interop.X64.as_lowstar_sig_t_weak_stdcall", "Vale.X64.MemoryAdapters.coerce", "Vale.X64.Machine_Semantics_s.code", "Vale.X64.Decls.va_code", "Vale.AsLowStar.Test.code_aesni", "Vale.AsLowStar.Test.aesni_dom", "Vale.AsLowStar.Test.empty_list", "Vale.Interop.Base.arg", "Vale.AsLowStar.Wrapper.pre_rel_generic", "Vale.Interop.X64.max_stdcall", "Vale.Interop.X64.arg_reg_stdcall", "Prims.Nil", "Vale.AsLowStar.Test.aesni_pre", "Vale.AsLowStar.Wrapper.post_rel_generic", "Vale.AsLowStar.Test.aesni_post", "Vale.AsLowStar.Wrapper.mk_prediction", "Vale.Interop.X64.regs_modified_stdcall", "Vale.Interop.X64.xmms_modified_stdcall", "Vale.AsLowStar.Test.aesni_lemma", "Vale.Interop.Assumptions.win" ]
[]
false
false
false
true
true
let lowstar_aesni_t =
IX64.as_lowstar_sig_t_weak_stdcall (coerce code_aesni) aesni_dom empty_list _ _ (W.mk_prediction code_aesni aesni_dom [] (aesni_lemma code_aesni IA.win))
false
Vale.AsLowStar.Test.fst
Vale.AsLowStar.Test.aesni_Test
val aesni_Test: Prims.unit -> Stack UInt64.t (requires fun h0 -> True) (ensures fun h0 ret_val h1 -> (UInt64.v ret_val) =!= 0 ==> aesni_enabled /\ pclmulqdq_enabled)
val aesni_Test: Prims.unit -> Stack UInt64.t (requires fun h0 -> True) (ensures fun h0 ret_val h1 -> (UInt64.v ret_val) =!= 0 ==> aesni_enabled /\ pclmulqdq_enabled)
let aesni_Test () : Stack UInt64.t (requires fun h0 -> True) (ensures fun h0 ret_val h1 -> (UInt64.v ret_val) =!= 0 ==> aesni_enabled /\ pclmulqdq_enabled) // by (T.dump "A") (* in case you want to look at the VC *) = let (x, _) = lowstar_aesni_normal_t () in //This is a call to the interop wrapper x
{ "file_name": "vale/code/arch/x64/interop/Vale.AsLowStar.Test.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 3, "end_line": 268, "start_col": 0, "start_line": 261 }
module Vale.AsLowStar.Test open FStar.Mul open Vale.Interop.Base module ME = Vale.X64.Memory module IA = Vale.Interop.Assumptions module V = Vale.X64.Decls module IX64 = Vale.Interop.X64 module VSig = Vale.AsLowStar.ValeSig module LSig = Vale.AsLowStar.LowStarSig module W = Vale.AsLowStar.Wrapper module VS = Vale.X64.State module MS = Vale.X64.Machine_s (* A little utility to trigger normalization in types *) let as_t (#a:Type) (x:normal a) : a = x let as_normal_t (#a:Type) (x:a) : normal a = x //////////////////////////////////////////////////////////////////////////////// //First a little standalone, toy experiment [@__reduce__] let b64 = buf_t TUInt8 TUInt64 [@__reduce__] let ib64 = ibuf_t TUInt8 TUInt64 [@__reduce__] let t64_mod = TD_Buffer TUInt8 TUInt64 default_bq [@__reduce__] let t64_no_mod = TD_Buffer TUInt8 TUInt64 ({modified=false; strict_disjointness=false; taint=MS.Secret}) [@__reduce__] let t64_imm = TD_ImmBuffer TUInt8 TUInt64 ({modified=false; strict_disjointness=false; taint=MS.Secret}) [@__reduce__] let (dom : list td{List.length dom <= 20}) = let y = [t64_mod;t64_imm] in assert_norm (List.length y = 2); y assume val pre : VSig.vale_pre dom assume val post : VSig.vale_post dom assume val v: VSig.vale_sig_stdcall pre post assume val c: V.va_code [@__reduce__] let call_c_t = IX64.as_lowstar_sig_t_weak_stdcall c dom [] _ _ (W.mk_prediction c dom [] (v c IA.win)) let call_c : call_c_t = IX64.wrap_weak_stdcall c dom (W.mk_prediction c dom [] (v c IA.win)) let call_c_normal_t : normal call_c_t = as_normal_t #call_c_t call_c //You can ask emacs to show you the type of call_c_normal_t ... //////////////////////////////////////////////////////////////////////////////// //Now memcpy module VM = Vale.Test.X64.Vale_memcpy [@__reduce__] let vm_dom = [t64_mod; t64_imm] open Vale.X64.MemoryAdapters (* Need to rearrange the order of arguments *) [@__reduce__] let vm_pre : VSig.vale_pre vm_dom = fun (c:V.va_code) (dst:b64) (src:ib64) (va_s0:V.va_state) -> VM.va_req_Memcpy c va_s0 IA.win (as_vale_buffer dst) (as_vale_immbuffer src) [@__reduce__] let vm_post : VSig.vale_post vm_dom = fun (c:V.va_code) (dst:b64) (src:ib64) (va_s0:V.va_state) (va_s1:V.va_state) (f:V.va_fuel) -> VM.va_ens_Memcpy c va_s0 IA.win (as_vale_buffer dst) (as_vale_immbuffer src) va_s1 f module VS = Vale.X64.State #reset-options "--print_effect_args --z3rlimit 200" (* The vale lemma doesn't quite suffice to prove the modifies clause expected of the interop layer *) [@__reduce__] let vm_lemma' (code:V.va_code) (_win:bool) (dst:b64) (src:ib64) (va_s0:V.va_state) : Ghost (V.va_state & V.va_fuel) (requires vm_pre code dst src va_s0) (ensures (fun (va_s1, f) -> V.eval_code code va_s0 f va_s1 /\ VSig.vale_calling_conventions_stdcall va_s0 va_s1 /\ vm_post code dst src va_s0 va_s1 f /\ ME.buffer_readable (VS.vs_get_vale_heap va_s1) (as_vale_immbuffer src) /\ ME.buffer_readable (VS.vs_get_vale_heap va_s1) (as_vale_buffer dst) /\ ME.buffer_writeable (as_vale_buffer dst) /\ ME.modifies (ME.loc_union (ME.loc_buffer (as_vale_buffer dst)) ME.loc_none) (VS.vs_get_vale_heap va_s0) (VS.vs_get_vale_heap va_s1) )) = let va_s1, f = VM.va_lemma_Memcpy code va_s0 IA.win (as_vale_buffer dst) (as_vale_immbuffer src) in Vale.AsLowStar.MemoryHelpers.buffer_writeable_reveal ME.TUInt8 ME.TUInt64 dst; (va_s1, f) (* Prove that vm_lemma' has the required type *) let vm_lemma = as_t #(VSig.vale_sig_stdcall vm_pre vm_post) vm_lemma' let code_Memcpy = VM.va_code_Memcpy IA.win (* Here's the type expected for the memcpy wrapper *) [@__reduce__] let lowstar_Memcpy_t = IX64.as_lowstar_sig_t_weak_stdcall code_Memcpy vm_dom [] _ _ (W.mk_prediction code_Memcpy vm_dom [] (vm_lemma code_Memcpy IA.win)) (* And here's the memcpy wrapper itself *) let lowstar_Memcpy : lowstar_Memcpy_t = IX64.wrap_weak_stdcall code_Memcpy vm_dom (W.mk_prediction code_Memcpy vm_dom [] (vm_lemma code_Memcpy IA.win)) let lowstar_Memcpy_normal_t //: normal lowstar_Memcpy_t = as_normal_t #lowstar_Memcpy_t lowstar_Memcpy module B = LowStar.Buffer module IB = LowStar.ImmutableBuffer module MB = LowStar.Monotonic.Buffer open FStar.HyperStack.ST module M = Vale.X64.Memory let test (x:b64) = assert (V.buffer_length (as_vale_buffer x) == (B.length x * view_n TUInt8) / view_n TUInt64); assert (V.buffer_length (as_vale_buffer x) == B.length x / 8) let itest (x:ib64) = assert (V.buffer_length (as_vale_immbuffer x) == (B.length x * view_n TUInt8) / view_n TUInt64); assert (V.buffer_length (as_vale_immbuffer x) == B.length x / 8) module T = FStar.Tactics #reset-options "--using_facts_from '* -FStar.Tactics -FStar.Reflection'" module LBV = LowStar.BufferView.Up module DV = LowStar.BufferView.Down #push-options "--ext compat:normalizer_memo_ignore_cfg" let memcpy_Test (dst:B.buffer UInt8.t{B.length dst % 8 == 0}) (src:IB.ibuffer UInt8.t{B.length src % 8 == 0}) : Stack UInt64.t (requires fun h0 -> B.live h0 dst /\ B.live h0 src /\ B.disjoint dst src /\ B.length dst == 16 /\ B.length src == 16) (ensures fun h0 _ h1 -> B.modifies (B.loc_buffer dst) h0 h1 /\ B.live h1 src /\ B.live h1 dst) // B.as_seq h1 dst == B.as_seq h1 src) // by (T.dump "A") (* in case you want to look at the VC *) = IB.inhabited_immutable_buffer_is_distinct_from_buffer (UInt8.uint_to_t 0) src dst; let (x, _) = lowstar_Memcpy_normal_t dst src () in //This is a call to the interop wrapper let h1 = get () in // let v = Vale.Interop.Views.up_view64 in // assert (DV.length_eq (get_downview dst); // DV.length_eq (get_downview src); // Seq.equal (LBV.as_seq h1 (LBV.mk_buffer (get_downview dst) v)) // (LBV.as_seq h1 (LBV.mk_buffer (get_downview src) v))); // lbv_as_seq_eq dst src Vale.Interop.Views.up_view64 h1; //And a lemma to rephrase the Vale postcondition x //with equalities of buffer views //back to equalities of buffers #pop-options module VC = Vale.Lib.X64.Cpuidstdcall [@__reduce__] let empty_list #a : l:list a {List.length l = 0} = [] [@__reduce__] let aesni_dom : IX64.arity_ok_stdcall td = [] (* Need to rearrange the order of arguments *) [@__reduce__] let aesni_pre : VSig.vale_pre aesni_dom = fun (c:V.va_code) (va_s0:V.va_state) -> VC.va_req_Check_aesni_stdcall c va_s0 IA.win [@__reduce__] let aesni_post : VSig.vale_post aesni_dom = fun (c:V.va_code) (va_s0:V.va_state) (va_s1:V.va_state) (f:V.va_fuel) -> VC.va_ens_Check_aesni_stdcall c va_s0 IA.win va_s1 f [@__reduce__] let with_len (l:list 'a) : Pure (list 'a) (requires True) (ensures fun m -> m==l /\ List.length m == normalize_term (List.length l)) = l #set-options "--max_fuel 0 --max_ifuel 1 --z3rlimit_factor 2" (* The vale lemma doesn't quite suffice to prove the modifies clause expected of the interop layer *) [@__reduce__] let aesni_lemma' (code:V.va_code) (_win:bool) (va_s0:V.va_state) : Ghost (V.va_state & V.va_fuel) (requires aesni_pre code va_s0) (ensures (fun (va_s1, f) -> V.eval_code code va_s0 f va_s1 /\ VSig.vale_calling_conventions_stdcall va_s0 va_s1 /\ aesni_post code va_s0 va_s1 f)) = VC.va_lemma_Check_aesni_stdcall code va_s0 IA.win #set-options "--max_fuel 0 --max_ifuel 0 --z3rlimit_factor 2" (* Prove that vm_lemma' has the required type *) let aesni_lemma = as_t #(VSig.vale_sig_stdcall aesni_pre aesni_post) aesni_lemma' let code_aesni = VC.va_code_Check_aesni_stdcall IA.win (* Here's the type expected for the check_aesni wrapper *) [@__reduce__] let lowstar_aesni_t = IX64.as_lowstar_sig_t_weak_stdcall (coerce code_aesni) aesni_dom empty_list _ _ (W.mk_prediction code_aesni aesni_dom [] (aesni_lemma code_aesni IA.win)) (* And here's the check_aesni wrapper itself *) let lowstar_aesni : lowstar_aesni_t = IX64.wrap_weak_stdcall (coerce code_aesni) aesni_dom (W.mk_prediction code_aesni aesni_dom [] (aesni_lemma code_aesni IA.win)) let lowstar_aesni_normal_t //: normal lowstar_aesni_t = as_normal_t #lowstar_aesni_t lowstar_aesni open Vale.X64.CPU_Features_s #set-options "--print_full_names"
{ "checked_file": "/", "dependencies": [ "Vale.X64.State.fsti.checked", "Vale.X64.MemoryAdapters.fsti.checked", "Vale.X64.Memory.fsti.checked", "Vale.X64.Machine_s.fst.checked", "Vale.X64.Decls.fsti.checked", "Vale.X64.CPU_Features_s.fst.checked", "Vale.Test.X64.Vale_memcpy.fsti.checked", "Vale.Test.X64.Args.fsti.checked", "Vale.Lib.X64.Cpuidstdcall.fsti.checked", "Vale.Interop.X64.fsti.checked", "Vale.Interop.Base.fst.checked", "Vale.Interop.Assumptions.fst.checked", "Vale.AsLowStar.Wrapper.fsti.checked", "Vale.AsLowStar.ValeSig.fst.checked", "Vale.AsLowStar.MemoryHelpers.fsti.checked", "Vale.AsLowStar.LowStarSig.fst.checked", "prims.fst.checked", "LowStar.Monotonic.Buffer.fsti.checked", "LowStar.ImmutableBuffer.fst.checked", "LowStar.BufferView.Up.fsti.checked", "LowStar.BufferView.Down.fsti.checked", "LowStar.Buffer.fst.checked", "FStar.UInt8.fsti.checked", "FStar.UInt64.fsti.checked", "FStar.Tactics.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.List.fst.checked", "FStar.HyperStack.ST.fsti.checked" ], "interface_file": false, "source_file": "Vale.AsLowStar.Test.fst" }
[ { "abbrev": false, "full_module": "Vale.X64.CPU_Features_s", "short_module": null }, { "abbrev": true, "full_module": "Vale.Lib.X64.Cpuidstdcall", "short_module": "VC" }, { "abbrev": true, "full_module": "LowStar.BufferView.Down", "short_module": "DV" }, { "abbrev": true, "full_module": "LowStar.BufferView.Up", "short_module": "LBV" }, { "abbrev": true, "full_module": "FStar.Tactics", "short_module": "T" }, { "abbrev": true, "full_module": "Vale.X64.Memory", "short_module": "M" }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": true, "full_module": "LowStar.Monotonic.Buffer", "short_module": "MB" }, { "abbrev": true, "full_module": "LowStar.ImmutableBuffer", "short_module": "IB" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "Vale.X64.State", "short_module": "VS" }, { "abbrev": false, "full_module": "Vale.X64.MemoryAdapters", "short_module": null }, { "abbrev": true, "full_module": "Vale.Test.X64.Vale_memcpy", "short_module": "VM" }, { "abbrev": true, "full_module": "Vale.X64.Machine_s", "short_module": "MS" }, { "abbrev": true, "full_module": "Vale.X64.State", "short_module": "VS" }, { "abbrev": true, "full_module": "Vale.AsLowStar.Wrapper", "short_module": "W" }, { "abbrev": true, "full_module": "Vale.AsLowStar.LowStarSig", "short_module": "LSig" }, { "abbrev": true, "full_module": "Vale.AsLowStar.ValeSig", "short_module": "VSig" }, { "abbrev": true, "full_module": "Vale.Interop.X64", "short_module": "IX64" }, { "abbrev": true, "full_module": "Vale.X64.Decls", "short_module": "V" }, { "abbrev": true, "full_module": "Vale.Interop.Assumptions", "short_module": "IA" }, { "abbrev": true, "full_module": "Vale.X64.Memory", "short_module": "ME" }, { "abbrev": false, "full_module": "Vale.Interop.Base", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.AsLowStar", "short_module": null }, { "abbrev": false, "full_module": "Vale.AsLowStar", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 0, "max_fuel": 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": true, "smtencoding_l_arith_repr": "native", "smtencoding_nl_arith_repr": "wrapped", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [ "smt.arith.nl=false", "smt.QI.EAGER_THRESHOLD=100", "smt.CASE_SPLIT=3" ], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 2, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
_: Prims.unit -> FStar.HyperStack.ST.Stack FStar.UInt64.t
FStar.HyperStack.ST.Stack
[]
[]
[ "Prims.unit", "FStar.UInt64.t", "FStar.Ghost.erased", "Vale.Interop.X64.as_lowstar_sig_ret", "Vale.Interop.X64.als_ret", "Vale.AsLowStar.Test.lowstar_aesni_normal_t", "FStar.Monotonic.HyperStack.mem", "Prims.l_True", "Prims.l_imp", "Prims.l_not", "Prims.eq2", "Prims.int", "FStar.UInt64.v", "Prims.l_and", "Prims.b2t", "Vale.X64.CPU_Features_s.aesni_enabled", "Vale.X64.CPU_Features_s.pclmulqdq_enabled" ]
[]
false
true
false
false
false
let aesni_Test () : Stack UInt64.t (requires fun h0 -> True) (ensures fun h0 ret_val h1 -> (UInt64.v ret_val) =!= 0 ==> aesni_enabled /\ pclmulqdq_enabled) =
let x, _ = lowstar_aesni_normal_t () in x
false
Vale.AsLowStar.Test.fst
Vale.AsLowStar.Test.with_len
val with_len (l: list 'a) : Pure (list 'a) (requires True) (ensures fun m -> m == l /\ List.length m == normalize_term (List.length l))
val with_len (l: list 'a) : Pure (list 'a) (requires True) (ensures fun m -> m == l /\ List.length m == normalize_term (List.length l))
let with_len (l:list 'a) : Pure (list 'a) (requires True) (ensures fun m -> m==l /\ List.length m == normalize_term (List.length l)) = l
{ "file_name": "vale/code/arch/x64/interop/Vale.AsLowStar.Test.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 5, "end_line": 210, "start_col": 0, "start_line": 206 }
module Vale.AsLowStar.Test open FStar.Mul open Vale.Interop.Base module ME = Vale.X64.Memory module IA = Vale.Interop.Assumptions module V = Vale.X64.Decls module IX64 = Vale.Interop.X64 module VSig = Vale.AsLowStar.ValeSig module LSig = Vale.AsLowStar.LowStarSig module W = Vale.AsLowStar.Wrapper module VS = Vale.X64.State module MS = Vale.X64.Machine_s (* A little utility to trigger normalization in types *) let as_t (#a:Type) (x:normal a) : a = x let as_normal_t (#a:Type) (x:a) : normal a = x //////////////////////////////////////////////////////////////////////////////// //First a little standalone, toy experiment [@__reduce__] let b64 = buf_t TUInt8 TUInt64 [@__reduce__] let ib64 = ibuf_t TUInt8 TUInt64 [@__reduce__] let t64_mod = TD_Buffer TUInt8 TUInt64 default_bq [@__reduce__] let t64_no_mod = TD_Buffer TUInt8 TUInt64 ({modified=false; strict_disjointness=false; taint=MS.Secret}) [@__reduce__] let t64_imm = TD_ImmBuffer TUInt8 TUInt64 ({modified=false; strict_disjointness=false; taint=MS.Secret}) [@__reduce__] let (dom : list td{List.length dom <= 20}) = let y = [t64_mod;t64_imm] in assert_norm (List.length y = 2); y assume val pre : VSig.vale_pre dom assume val post : VSig.vale_post dom assume val v: VSig.vale_sig_stdcall pre post assume val c: V.va_code [@__reduce__] let call_c_t = IX64.as_lowstar_sig_t_weak_stdcall c dom [] _ _ (W.mk_prediction c dom [] (v c IA.win)) let call_c : call_c_t = IX64.wrap_weak_stdcall c dom (W.mk_prediction c dom [] (v c IA.win)) let call_c_normal_t : normal call_c_t = as_normal_t #call_c_t call_c //You can ask emacs to show you the type of call_c_normal_t ... //////////////////////////////////////////////////////////////////////////////// //Now memcpy module VM = Vale.Test.X64.Vale_memcpy [@__reduce__] let vm_dom = [t64_mod; t64_imm] open Vale.X64.MemoryAdapters (* Need to rearrange the order of arguments *) [@__reduce__] let vm_pre : VSig.vale_pre vm_dom = fun (c:V.va_code) (dst:b64) (src:ib64) (va_s0:V.va_state) -> VM.va_req_Memcpy c va_s0 IA.win (as_vale_buffer dst) (as_vale_immbuffer src) [@__reduce__] let vm_post : VSig.vale_post vm_dom = fun (c:V.va_code) (dst:b64) (src:ib64) (va_s0:V.va_state) (va_s1:V.va_state) (f:V.va_fuel) -> VM.va_ens_Memcpy c va_s0 IA.win (as_vale_buffer dst) (as_vale_immbuffer src) va_s1 f module VS = Vale.X64.State #reset-options "--print_effect_args --z3rlimit 200" (* The vale lemma doesn't quite suffice to prove the modifies clause expected of the interop layer *) [@__reduce__] let vm_lemma' (code:V.va_code) (_win:bool) (dst:b64) (src:ib64) (va_s0:V.va_state) : Ghost (V.va_state & V.va_fuel) (requires vm_pre code dst src va_s0) (ensures (fun (va_s1, f) -> V.eval_code code va_s0 f va_s1 /\ VSig.vale_calling_conventions_stdcall va_s0 va_s1 /\ vm_post code dst src va_s0 va_s1 f /\ ME.buffer_readable (VS.vs_get_vale_heap va_s1) (as_vale_immbuffer src) /\ ME.buffer_readable (VS.vs_get_vale_heap va_s1) (as_vale_buffer dst) /\ ME.buffer_writeable (as_vale_buffer dst) /\ ME.modifies (ME.loc_union (ME.loc_buffer (as_vale_buffer dst)) ME.loc_none) (VS.vs_get_vale_heap va_s0) (VS.vs_get_vale_heap va_s1) )) = let va_s1, f = VM.va_lemma_Memcpy code va_s0 IA.win (as_vale_buffer dst) (as_vale_immbuffer src) in Vale.AsLowStar.MemoryHelpers.buffer_writeable_reveal ME.TUInt8 ME.TUInt64 dst; (va_s1, f) (* Prove that vm_lemma' has the required type *) let vm_lemma = as_t #(VSig.vale_sig_stdcall vm_pre vm_post) vm_lemma' let code_Memcpy = VM.va_code_Memcpy IA.win (* Here's the type expected for the memcpy wrapper *) [@__reduce__] let lowstar_Memcpy_t = IX64.as_lowstar_sig_t_weak_stdcall code_Memcpy vm_dom [] _ _ (W.mk_prediction code_Memcpy vm_dom [] (vm_lemma code_Memcpy IA.win)) (* And here's the memcpy wrapper itself *) let lowstar_Memcpy : lowstar_Memcpy_t = IX64.wrap_weak_stdcall code_Memcpy vm_dom (W.mk_prediction code_Memcpy vm_dom [] (vm_lemma code_Memcpy IA.win)) let lowstar_Memcpy_normal_t //: normal lowstar_Memcpy_t = as_normal_t #lowstar_Memcpy_t lowstar_Memcpy module B = LowStar.Buffer module IB = LowStar.ImmutableBuffer module MB = LowStar.Monotonic.Buffer open FStar.HyperStack.ST module M = Vale.X64.Memory let test (x:b64) = assert (V.buffer_length (as_vale_buffer x) == (B.length x * view_n TUInt8) / view_n TUInt64); assert (V.buffer_length (as_vale_buffer x) == B.length x / 8) let itest (x:ib64) = assert (V.buffer_length (as_vale_immbuffer x) == (B.length x * view_n TUInt8) / view_n TUInt64); assert (V.buffer_length (as_vale_immbuffer x) == B.length x / 8) module T = FStar.Tactics #reset-options "--using_facts_from '* -FStar.Tactics -FStar.Reflection'" module LBV = LowStar.BufferView.Up module DV = LowStar.BufferView.Down #push-options "--ext compat:normalizer_memo_ignore_cfg" let memcpy_Test (dst:B.buffer UInt8.t{B.length dst % 8 == 0}) (src:IB.ibuffer UInt8.t{B.length src % 8 == 0}) : Stack UInt64.t (requires fun h0 -> B.live h0 dst /\ B.live h0 src /\ B.disjoint dst src /\ B.length dst == 16 /\ B.length src == 16) (ensures fun h0 _ h1 -> B.modifies (B.loc_buffer dst) h0 h1 /\ B.live h1 src /\ B.live h1 dst) // B.as_seq h1 dst == B.as_seq h1 src) // by (T.dump "A") (* in case you want to look at the VC *) = IB.inhabited_immutable_buffer_is_distinct_from_buffer (UInt8.uint_to_t 0) src dst; let (x, _) = lowstar_Memcpy_normal_t dst src () in //This is a call to the interop wrapper let h1 = get () in // let v = Vale.Interop.Views.up_view64 in // assert (DV.length_eq (get_downview dst); // DV.length_eq (get_downview src); // Seq.equal (LBV.as_seq h1 (LBV.mk_buffer (get_downview dst) v)) // (LBV.as_seq h1 (LBV.mk_buffer (get_downview src) v))); // lbv_as_seq_eq dst src Vale.Interop.Views.up_view64 h1; //And a lemma to rephrase the Vale postcondition x //with equalities of buffer views //back to equalities of buffers #pop-options module VC = Vale.Lib.X64.Cpuidstdcall [@__reduce__] let empty_list #a : l:list a {List.length l = 0} = [] [@__reduce__] let aesni_dom : IX64.arity_ok_stdcall td = [] (* Need to rearrange the order of arguments *) [@__reduce__] let aesni_pre : VSig.vale_pre aesni_dom = fun (c:V.va_code) (va_s0:V.va_state) -> VC.va_req_Check_aesni_stdcall c va_s0 IA.win [@__reduce__] let aesni_post : VSig.vale_post aesni_dom = fun (c:V.va_code) (va_s0:V.va_state) (va_s1:V.va_state) (f:V.va_fuel) -> VC.va_ens_Check_aesni_stdcall c va_s0 IA.win va_s1 f
{ "checked_file": "/", "dependencies": [ "Vale.X64.State.fsti.checked", "Vale.X64.MemoryAdapters.fsti.checked", "Vale.X64.Memory.fsti.checked", "Vale.X64.Machine_s.fst.checked", "Vale.X64.Decls.fsti.checked", "Vale.X64.CPU_Features_s.fst.checked", "Vale.Test.X64.Vale_memcpy.fsti.checked", "Vale.Test.X64.Args.fsti.checked", "Vale.Lib.X64.Cpuidstdcall.fsti.checked", "Vale.Interop.X64.fsti.checked", "Vale.Interop.Base.fst.checked", "Vale.Interop.Assumptions.fst.checked", "Vale.AsLowStar.Wrapper.fsti.checked", "Vale.AsLowStar.ValeSig.fst.checked", "Vale.AsLowStar.MemoryHelpers.fsti.checked", "Vale.AsLowStar.LowStarSig.fst.checked", "prims.fst.checked", "LowStar.Monotonic.Buffer.fsti.checked", "LowStar.ImmutableBuffer.fst.checked", "LowStar.BufferView.Up.fsti.checked", "LowStar.BufferView.Down.fsti.checked", "LowStar.Buffer.fst.checked", "FStar.UInt8.fsti.checked", "FStar.UInt64.fsti.checked", "FStar.Tactics.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.List.fst.checked", "FStar.HyperStack.ST.fsti.checked" ], "interface_file": false, "source_file": "Vale.AsLowStar.Test.fst" }
[ { "abbrev": true, "full_module": "Vale.Lib.X64.Cpuidstdcall", "short_module": "VC" }, { "abbrev": true, "full_module": "LowStar.BufferView.Down", "short_module": "DV" }, { "abbrev": true, "full_module": "LowStar.BufferView.Up", "short_module": "LBV" }, { "abbrev": true, "full_module": "FStar.Tactics", "short_module": "T" }, { "abbrev": true, "full_module": "Vale.X64.Memory", "short_module": "M" }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": true, "full_module": "LowStar.Monotonic.Buffer", "short_module": "MB" }, { "abbrev": true, "full_module": "LowStar.ImmutableBuffer", "short_module": "IB" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "Vale.X64.State", "short_module": "VS" }, { "abbrev": false, "full_module": "Vale.X64.MemoryAdapters", "short_module": null }, { "abbrev": true, "full_module": "Vale.Test.X64.Vale_memcpy", "short_module": "VM" }, { "abbrev": true, "full_module": "Vale.X64.Machine_s", "short_module": "MS" }, { "abbrev": true, "full_module": "Vale.X64.State", "short_module": "VS" }, { "abbrev": true, "full_module": "Vale.AsLowStar.Wrapper", "short_module": "W" }, { "abbrev": true, "full_module": "Vale.AsLowStar.LowStarSig", "short_module": "LSig" }, { "abbrev": true, "full_module": "Vale.AsLowStar.ValeSig", "short_module": "VSig" }, { "abbrev": true, "full_module": "Vale.Interop.X64", "short_module": "IX64" }, { "abbrev": true, "full_module": "Vale.X64.Decls", "short_module": "V" }, { "abbrev": true, "full_module": "Vale.Interop.Assumptions", "short_module": "IA" }, { "abbrev": true, "full_module": "Vale.X64.Memory", "short_module": "ME" }, { "abbrev": false, "full_module": "Vale.Interop.Base", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.AsLowStar", "short_module": null }, { "abbrev": false, "full_module": "Vale.AsLowStar", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 0, "max_fuel": 1, "max_ifuel": 1, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": true, "smtencoding_l_arith_repr": "native", "smtencoding_nl_arith_repr": "wrapped", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [ "smt.arith.nl=false", "smt.QI.EAGER_THRESHOLD=100", "smt.CASE_SPLIT=3" ], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
l: Prims.list 'a -> Prims.Pure (Prims.list 'a)
Prims.Pure
[]
[]
[ "Prims.list", "Prims.l_True", "Prims.l_and", "Prims.eq2", "Prims.nat", "FStar.List.Tot.Base.length", "FStar.Pervasives.normalize_term" ]
[]
false
false
false
false
false
let with_len (l: list 'a) : Pure (list 'a) (requires True) (ensures fun m -> m == l /\ List.length m == normalize_term (List.length l)) =
l
false
Hacl.Spec.Bignum.MontArithmetic.fst
Hacl.Spec.Bignum.MontArithmetic.bn_to_field
val bn_to_field: #t:limb_t -> k:bn_mont_ctx t{bn_mont_ctx_inv k} -> a:lbignum t k.len -> Pure (bn_mont_nat k) (requires True) (ensures fun aM -> bn_v aM == M.to_mont (bits t) k.len (bn_v k.n) (v k.mu) (bn_v a))
val bn_to_field: #t:limb_t -> k:bn_mont_ctx t{bn_mont_ctx_inv k} -> a:lbignum t k.len -> Pure (bn_mont_nat k) (requires True) (ensures fun aM -> bn_v aM == M.to_mont (bits t) k.len (bn_v k.n) (v k.mu) (bn_v a))
let bn_to_field #t k a = BM.bn_to_mont_lemma k.n k.mu k.r2 a; BM.bn_to_mont k.n k.mu k.r2 a
{ "file_name": "code/bignum/Hacl.Spec.Bignum.MontArithmetic.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 31, "end_line": 112, "start_col": 0, "start_line": 110 }
module Hacl.Spec.Bignum.MontArithmetic open FStar.Mul open Lib.IntTypes open Lib.Sequence open Hacl.Spec.Bignum.Definitions module M = Hacl.Spec.Montgomery.Lemmas module BM = Hacl.Spec.Bignum.Montgomery module BN = Hacl.Spec.Bignum module BB = Hacl.Spec.Bignum.Base module BL = Hacl.Spec.Bignum.Lib module BIL = Hacl.Spec.Bignum.ModInvLimb module E = Hacl.Spec.Exponentiation.Lemmas module ME = Hacl.Spec.Bignum.MontExponentiation module Euclid = FStar.Math.Euclid module BI = Hacl.Spec.Bignum.ModInv #set-options "--z3rlimit 50 --fuel 0 --ifuel 0" ////////////////////////////////////////// val mul_zero_lemma: n:pos{Euclid.is_prime n} -> x:int -> y:int -> Lemma (x * y % n == 0 <==> (x % n == 0 \/ y % n == 0)) let mul_zero_lemma n x y = assert (0 % n = 0); if x % n = 0 then Math.Lemmas.lemma_mod_mul_distr_l x y n else if y % n = 0 then Math.Lemmas.lemma_mod_mul_distr_r x y n else if x * y % n = 0 then Math.Fermat.mod_mult_congr n x 0 y else () val mul_nonzero_lemma: n:pos{Euclid.is_prime n} -> x:int -> y:int -> Lemma (requires x % n <> 0 /\ y % n <> 0) (ensures x * y % n <> 0) let mul_nonzero_lemma n x y = mul_zero_lemma n x y val from_mont_lemma_nonzero: pbits:pos -> rLen:pos -> n:pos -> mu:nat -> aM:nat -> Lemma (requires M.mont_pre pbits rLen n mu /\ 0 < aM /\ aM < n /\ Euclid.is_prime n) (ensures (let a = M.from_mont pbits rLen n mu aM in 0 < a /\ a < n)) let from_mont_lemma_nonzero pbits rLen n mu aM = let r = pow2 (pbits * rLen) in let d, _ = M.eea_pow2_odd (pbits * rLen) n in let a = M.from_mont pbits rLen n mu aM in M.from_mont_lemma pbits rLen n mu aM; assert (a == aM * d % n); assert (d <> 0); Math.Lemmas.small_mod aM n; assert (aM % n <> 0); let d1 = -d in assert (0 < d1 /\ d1 < n); Math.Lemmas.lemma_mod_sub_1 d1 n; assert ((-d1) % n == n - (d1 % n)); assert (d % n <> 0); mul_nonzero_lemma n aM d; assert (let a = M.from_mont pbits rLen n mu aM in 0 < a /\ a < n); // For some reason, this makes the proof instant. () /////////////////////////////////////////////// let bn_field_get_len #t k = k.len let bn_field_check_modulus #t #len n = let m = BM.bn_check_modulus n in BB.unsafe_bool_of_limb m let bn_field_init #t #len n = let nBits = bits t * BL.bn_get_top_index n in BL.bn_low_bound_bits_lemma n; BM.bn_precomp_r2_mod_n_lemma nBits n; let r2 = BM.bn_precomp_r2_mod_n nBits n in assert (bn_v r2 == pow2 (2 * bits t * len) % bn_v n); let mu = BIL.mod_inv_limb n.[0] in BIL.bn_mod_inv_limb_lemma n; assert ((1 + bn_v n * v mu) % pow2 (bits t) == 0); bn_eval_bound n len; { len = len; n = n; mu = mu; r2 = r2 }
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "Lib.Sequence.fsti.checked", "Lib.NatMod.fsti.checked", "Lib.IntTypes.fsti.checked", "Hacl.Spec.Montgomery.Lemmas.fst.checked", "Hacl.Spec.Exponentiation.Lemmas.fst.checked", "Hacl.Spec.Bignum.Montgomery.fsti.checked", "Hacl.Spec.Bignum.MontExponentiation.fst.checked", "Hacl.Spec.Bignum.ModInvLimb.fsti.checked", "Hacl.Spec.Bignum.ModInv.fst.checked", "Hacl.Spec.Bignum.Lib.fst.checked", "Hacl.Spec.Bignum.Definitions.fst.checked", "Hacl.Spec.Bignum.Base.fst.checked", "Hacl.Spec.Bignum.fsti.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.Math.Fermat.fsti.checked", "FStar.Math.Euclid.fsti.checked" ], "interface_file": true, "source_file": "Hacl.Spec.Bignum.MontArithmetic.fst" }
[ { "abbrev": true, "full_module": "Hacl.Spec.Bignum.ModInv", "short_module": "BI" }, { "abbrev": true, "full_module": "Hacl.Spec.Bignum.MontExponentiation", "short_module": "ME" }, { "abbrev": true, "full_module": "Hacl.Spec.Exponentiation.Lemmas", "short_module": "E" }, { "abbrev": true, "full_module": "Hacl.Spec.Bignum.ModInvLimb", "short_module": "BIL" }, { "abbrev": true, "full_module": "Hacl.Spec.Bignum.Lib", "short_module": "BL" }, { "abbrev": true, "full_module": "Hacl.Spec.Bignum.Base", "short_module": "BB" }, { "abbrev": true, "full_module": "Hacl.Spec.Bignum.Montgomery", "short_module": "BM" }, { "abbrev": true, "full_module": "Hacl.Spec.Bignum", "short_module": "BN" }, { "abbrev": true, "full_module": "Hacl.Spec.Montgomery.Lemmas", "short_module": "M" }, { "abbrev": true, "full_module": "FStar.Math.Euclid", "short_module": "Euclid" }, { "abbrev": false, "full_module": "Hacl.Spec.Bignum.Definitions", "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.Bignum", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.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 } ]
{ "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" }
false
k: Hacl.Spec.Bignum.MontArithmetic.bn_mont_ctx t {Hacl.Spec.Bignum.MontArithmetic.bn_mont_ctx_inv k} -> a: Hacl.Spec.Bignum.Definitions.lbignum t (Mkbn_mont_ctx?.len k) -> Prims.Pure (Hacl.Spec.Bignum.MontArithmetic.bn_mont_nat k)
Prims.Pure
[]
[]
[ "Hacl.Spec.Bignum.Definitions.limb_t", "Hacl.Spec.Bignum.MontArithmetic.bn_mont_ctx", "Hacl.Spec.Bignum.MontArithmetic.bn_mont_ctx_inv", "Hacl.Spec.Bignum.Definitions.lbignum", "Hacl.Spec.Bignum.MontArithmetic.__proj__Mkbn_mont_ctx__item__len", "Hacl.Spec.Bignum.Montgomery.bn_to_mont", "Hacl.Spec.Bignum.MontArithmetic.__proj__Mkbn_mont_ctx__item__n", "Hacl.Spec.Bignum.MontArithmetic.__proj__Mkbn_mont_ctx__item__mu", "Hacl.Spec.Bignum.MontArithmetic.__proj__Mkbn_mont_ctx__item__r2", "Prims.unit", "Hacl.Spec.Bignum.Montgomery.bn_to_mont_lemma", "Hacl.Spec.Bignum.MontArithmetic.bn_mont_nat" ]
[]
false
false
false
false
false
let bn_to_field #t k a =
BM.bn_to_mont_lemma k.n k.mu k.r2 a; BM.bn_to_mont k.n k.mu k.r2 a
false
Hacl.Spec.Bignum.MontArithmetic.fst
Hacl.Spec.Bignum.MontArithmetic.bn_field_exp_vartime
val bn_field_exp_vartime: #t:limb_t -> k:bn_mont_ctx t{bn_mont_ctx_inv k} -> bn_field_exp_st t k
val bn_field_exp_vartime: #t:limb_t -> k:bn_mont_ctx t{bn_mont_ctx_inv k} -> bn_field_exp_st t k
let bn_field_exp_vartime #t k aM bBits b = E.from_mont_exp_lemma (bits t) k.len (bn_v k.n) (v k.mu) (bn_v aM) (bn_v b); ME.bn_exp_mont_vartime k.n k.mu aM bBits b
{ "file_name": "code/bignum/Hacl.Spec.Bignum.MontArithmetic.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 44, "end_line": 162, "start_col": 0, "start_line": 160 }
module Hacl.Spec.Bignum.MontArithmetic open FStar.Mul open Lib.IntTypes open Lib.Sequence open Hacl.Spec.Bignum.Definitions module M = Hacl.Spec.Montgomery.Lemmas module BM = Hacl.Spec.Bignum.Montgomery module BN = Hacl.Spec.Bignum module BB = Hacl.Spec.Bignum.Base module BL = Hacl.Spec.Bignum.Lib module BIL = Hacl.Spec.Bignum.ModInvLimb module E = Hacl.Spec.Exponentiation.Lemmas module ME = Hacl.Spec.Bignum.MontExponentiation module Euclid = FStar.Math.Euclid module BI = Hacl.Spec.Bignum.ModInv #set-options "--z3rlimit 50 --fuel 0 --ifuel 0" ////////////////////////////////////////// val mul_zero_lemma: n:pos{Euclid.is_prime n} -> x:int -> y:int -> Lemma (x * y % n == 0 <==> (x % n == 0 \/ y % n == 0)) let mul_zero_lemma n x y = assert (0 % n = 0); if x % n = 0 then Math.Lemmas.lemma_mod_mul_distr_l x y n else if y % n = 0 then Math.Lemmas.lemma_mod_mul_distr_r x y n else if x * y % n = 0 then Math.Fermat.mod_mult_congr n x 0 y else () val mul_nonzero_lemma: n:pos{Euclid.is_prime n} -> x:int -> y:int -> Lemma (requires x % n <> 0 /\ y % n <> 0) (ensures x * y % n <> 0) let mul_nonzero_lemma n x y = mul_zero_lemma n x y val from_mont_lemma_nonzero: pbits:pos -> rLen:pos -> n:pos -> mu:nat -> aM:nat -> Lemma (requires M.mont_pre pbits rLen n mu /\ 0 < aM /\ aM < n /\ Euclid.is_prime n) (ensures (let a = M.from_mont pbits rLen n mu aM in 0 < a /\ a < n)) let from_mont_lemma_nonzero pbits rLen n mu aM = let r = pow2 (pbits * rLen) in let d, _ = M.eea_pow2_odd (pbits * rLen) n in let a = M.from_mont pbits rLen n mu aM in M.from_mont_lemma pbits rLen n mu aM; assert (a == aM * d % n); assert (d <> 0); Math.Lemmas.small_mod aM n; assert (aM % n <> 0); let d1 = -d in assert (0 < d1 /\ d1 < n); Math.Lemmas.lemma_mod_sub_1 d1 n; assert ((-d1) % n == n - (d1 % n)); assert (d % n <> 0); mul_nonzero_lemma n aM d; assert (let a = M.from_mont pbits rLen n mu aM in 0 < a /\ a < n); // For some reason, this makes the proof instant. () /////////////////////////////////////////////// let bn_field_get_len #t k = k.len let bn_field_check_modulus #t #len n = let m = BM.bn_check_modulus n in BB.unsafe_bool_of_limb m let bn_field_init #t #len n = let nBits = bits t * BL.bn_get_top_index n in BL.bn_low_bound_bits_lemma n; BM.bn_precomp_r2_mod_n_lemma nBits n; let r2 = BM.bn_precomp_r2_mod_n nBits n in assert (bn_v r2 == pow2 (2 * bits t * len) % bn_v n); let mu = BIL.mod_inv_limb n.[0] in BIL.bn_mod_inv_limb_lemma n; assert ((1 + bn_v n * v mu) % pow2 (bits t) == 0); bn_eval_bound n len; { len = len; n = n; mu = mu; r2 = r2 } let bn_to_field #t k a = BM.bn_to_mont_lemma k.n k.mu k.r2 a; BM.bn_to_mont k.n k.mu k.r2 a let bn_from_field #t k aM = BM.bn_from_mont_lemma k.n k.mu aM; BM.bn_from_mont k.n k.mu aM let bn_from_to_field_lemma #t k a = bn_eval_bound a k.len; M.from_to_mont_lemma (bits t) k.len (bn_v k.n) (v k.mu) (bn_v a) let bn_field_add #t k aM bM = BN.bn_add_mod_n_lemma k.n aM bM; M.from_mont_add_lemma (bits t) k.len (bn_v k.n) (v k.mu) (bn_v aM) (bn_v bM); BN.bn_add_mod_n k.n aM bM let bn_field_sub #t k aM bM = BN.bn_sub_mod_n_lemma k.n aM bM; M.from_mont_sub_lemma (bits t) k.len (bn_v k.n) (v k.mu) (bn_v aM) (bn_v bM); BN.bn_sub_mod_n k.n aM bM let bn_field_mul #t k aM bM = BM.bn_mont_mul_lemma k.n k.mu aM bM; M.from_mont_mul_lemma (bits t) k.len (bn_v k.n) (v k.mu) (bn_v aM) (bn_v bM); BM.bn_mont_mul k.n k.mu aM bM let bn_field_sqr #t k aM = BM.bn_mont_sqr_lemma k.n k.mu aM; M.from_mont_mul_lemma (bits t) k.len (bn_v k.n) (v k.mu) (bn_v aM) (bn_v aM); BM.bn_mont_sqr k.n k.mu aM let bn_field_one #t k = BM.bn_mont_one_lemma k.n k.mu k.r2; M.from_mont_one_lemma (bits t) k.len (bn_v k.n) (v k.mu); BM.bn_mont_one k.n k.mu r2 let bn_field_exp_consttime #t k aM bBits b = E.from_mont_exp_lemma (bits t) k.len (bn_v k.n) (v k.mu) (bn_v aM) (bn_v b); ME.bn_exp_mont_consttime k.n k.mu aM bBits b
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "Lib.Sequence.fsti.checked", "Lib.NatMod.fsti.checked", "Lib.IntTypes.fsti.checked", "Hacl.Spec.Montgomery.Lemmas.fst.checked", "Hacl.Spec.Exponentiation.Lemmas.fst.checked", "Hacl.Spec.Bignum.Montgomery.fsti.checked", "Hacl.Spec.Bignum.MontExponentiation.fst.checked", "Hacl.Spec.Bignum.ModInvLimb.fsti.checked", "Hacl.Spec.Bignum.ModInv.fst.checked", "Hacl.Spec.Bignum.Lib.fst.checked", "Hacl.Spec.Bignum.Definitions.fst.checked", "Hacl.Spec.Bignum.Base.fst.checked", "Hacl.Spec.Bignum.fsti.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.Math.Fermat.fsti.checked", "FStar.Math.Euclid.fsti.checked" ], "interface_file": true, "source_file": "Hacl.Spec.Bignum.MontArithmetic.fst" }
[ { "abbrev": true, "full_module": "Hacl.Spec.Bignum.ModInv", "short_module": "BI" }, { "abbrev": true, "full_module": "Hacl.Spec.Bignum.MontExponentiation", "short_module": "ME" }, { "abbrev": true, "full_module": "Hacl.Spec.Exponentiation.Lemmas", "short_module": "E" }, { "abbrev": true, "full_module": "Hacl.Spec.Bignum.ModInvLimb", "short_module": "BIL" }, { "abbrev": true, "full_module": "Hacl.Spec.Bignum.Lib", "short_module": "BL" }, { "abbrev": true, "full_module": "Hacl.Spec.Bignum.Base", "short_module": "BB" }, { "abbrev": true, "full_module": "Hacl.Spec.Bignum.Montgomery", "short_module": "BM" }, { "abbrev": true, "full_module": "Hacl.Spec.Bignum", "short_module": "BN" }, { "abbrev": true, "full_module": "Hacl.Spec.Montgomery.Lemmas", "short_module": "M" }, { "abbrev": true, "full_module": "FStar.Math.Euclid", "short_module": "Euclid" }, { "abbrev": false, "full_module": "Hacl.Spec.Bignum.Definitions", "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.Bignum", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.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 } ]
{ "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" }
false
k: Hacl.Spec.Bignum.MontArithmetic.bn_mont_ctx t {Hacl.Spec.Bignum.MontArithmetic.bn_mont_ctx_inv k} -> Hacl.Spec.Bignum.MontArithmetic.bn_field_exp_st t k
Prims.Tot
[ "total" ]
[]
[ "Hacl.Spec.Bignum.Definitions.limb_t", "Hacl.Spec.Bignum.MontArithmetic.bn_mont_ctx", "Hacl.Spec.Bignum.MontArithmetic.bn_mont_ctx_inv", "Hacl.Spec.Bignum.MontArithmetic.bn_mont_nat", "Lib.IntTypes.size_nat", "Hacl.Spec.Bignum.Definitions.lbignum", "Hacl.Spec.Bignum.Definitions.blocks0", "Lib.IntTypes.bits", "Hacl.Spec.Bignum.MontExponentiation.bn_exp_mont_vartime", "Hacl.Spec.Bignum.MontArithmetic.__proj__Mkbn_mont_ctx__item__len", "Hacl.Spec.Bignum.MontArithmetic.__proj__Mkbn_mont_ctx__item__n", "Hacl.Spec.Bignum.MontArithmetic.__proj__Mkbn_mont_ctx__item__mu", "Prims.unit", "Hacl.Spec.Exponentiation.Lemmas.from_mont_exp_lemma", "Hacl.Spec.Bignum.Definitions.bn_v", "Lib.IntTypes.v", "Lib.IntTypes.SEC" ]
[]
false
false
false
false
false
let bn_field_exp_vartime #t k aM bBits b =
E.from_mont_exp_lemma (bits t) k.len (bn_v k.n) (v k.mu) (bn_v aM) (bn_v b); ME.bn_exp_mont_vartime k.n k.mu aM bBits b
false
LowParseWriters.LowParse.fsti
LowParseWriters.LowParse.valid_frame
val valid_frame (p: parser) (h: HS.mem) (b: B.buffer U8.t) (pos pos': U32.t) (l: B.loc) (h': HS.mem) : Lemma (requires (B.live h b /\ (valid_pos p h b pos pos' \/ valid_pos p h' b pos pos') /\ B.modifies l h h' /\ B.loc_disjoint l (B.loc_buffer_from_to b pos pos'))) (ensures (valid_pos p h b pos pos' /\ valid_pos p h' b pos pos' /\ contents p h' b pos pos' == contents p h b pos pos'))
val valid_frame (p: parser) (h: HS.mem) (b: B.buffer U8.t) (pos pos': U32.t) (l: B.loc) (h': HS.mem) : Lemma (requires (B.live h b /\ (valid_pos p h b pos pos' \/ valid_pos p h' b pos pos') /\ B.modifies l h h' /\ B.loc_disjoint l (B.loc_buffer_from_to b pos pos'))) (ensures (valid_pos p h b pos pos' /\ valid_pos p h' b pos pos' /\ contents p h' b pos pos' == contents p h b pos pos'))
let valid_frame (p: parser) (h: HS.mem) (b: B.buffer U8.t) (pos: U32.t) (pos' : U32.t) (l: B.loc) (h' : HS.mem) : Lemma (requires ( B.live h b /\ (valid_pos p h b pos pos' \/ valid_pos p h' b pos pos') /\ B.modifies l h h' /\ B.loc_disjoint l (B.loc_buffer_from_to b pos pos') )) (ensures ( valid_pos p h b pos pos' /\ valid_pos p h' b pos pos' /\ contents p h' b pos pos' == contents p h b pos pos' )) = B.loc_buffer_mgsub_eq (B.trivial_preorder _) b pos (pos' `U32.sub` pos); Classical.move_requires (valid_ext p h b pos pos' h' b pos) pos'; Classical.move_requires (valid_ext p h' b pos pos' h b pos) pos'
{ "file_name": "examples/layeredeffects/LowParseWriters.LowParse.fsti", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 66, "end_line": 173, "start_col": 0, "start_line": 151 }
module LowParseWriters.LowParse module HS = FStar.HyperStack module B = LowStar.Buffer module U8 = FStar.UInt8 module U32 = FStar.UInt32 module HST = FStar.HyperStack.ST type u8 : Type0 = U8.t val parser' (t: Type0) : Type u#1 inline_for_extraction noextract noeq type parser = | Parser: t: Type -> p: parser' t -> parser val valid_pos (p: parser) (h: HS.mem) (b: B.buffer U8.t) (pos: U32.t) (pos' : U32.t) : GTot Type0 val valid_pos_post (p: parser) (h: HS.mem) (b: B.buffer U8.t) (pos: U32.t) (pos' : U32.t) : Lemma (requires (valid_pos p h b pos pos')) (ensures ( B.live h b /\ U32.v pos <= U32.v pos' /\ U32.v pos' <= B.length b )) [SMTPat (valid_pos p h b pos pos')] val contents (p: parser) (h: HS.mem) (b: B.buffer U8.t) (pos: U32.t) (pos' : U32.t) : Ghost (Parser?.t p) (requires (valid_pos p h b pos pos')) (ensures (fun _ -> True)) val size (p: parser) (x: Parser?.t p) : GTot nat val contents_size (p: parser) (h: HS.mem) (b: B.buffer U8.t) (pos: U32.t) (pos' : U32.t) : Lemma (requires (valid_pos p h b pos pos')) (ensures ( valid_pos p h b pos pos' /\ size p (contents p h b pos pos') == U32.v pos' - U32.v pos )) [SMTPat (contents p h b pos pos')] inline_for_extraction val parse_empty' : parser' unit inline_for_extraction let parse_empty : parser = Parser unit parse_empty' val valid_parse_empty (h: HS.mem) (b: B.buffer u8) (pos: U32.t) (pos' : U32.t) : Lemma ( valid_pos parse_empty h b pos pos' <==> ( B.live h b /\ U32.v pos <= B.length b /\ U32.v pos' == U32.v pos )) [SMTPat (valid_pos parse_empty h b pos pos')] val size_parse_empty : squash (size parse_empty () == 0) inline_for_extraction val parse_pair' (#t1 #t2: Type) (p1: parser' t1) (p2: parser' t2) : Tot (parser' (t1 & t2)) inline_for_extraction let parse_pair (p1 p2: parser) : Tot parser = Parser (Parser?.t p1 & Parser?.t p2) (parse_pair' (Parser?.p p1) (Parser?.p p2)) val valid_parse_pair (p1 p2: parser) (h: HS.mem) (b: B.buffer U8.t) (pos1 pos2 pos3: U32.t) : Lemma (requires ( valid_pos p1 h b pos1 pos2 /\ valid_pos p2 h b pos2 pos3 )) (ensures ( valid_pos p1 h b pos1 pos2 /\ valid_pos p2 h b pos2 pos3 /\ valid_pos (p1 `parse_pair` p2) h b pos1 pos3 /\ contents (p1 `parse_pair` p2) h b pos1 pos3 == (contents p1 h b pos1 pos2, contents p2 h b pos2 pos3) )) val size_parse_pair (p1 p2: parser) (x1: Parser?.t p1) (x2: Parser?.t p2) : Lemma (size (p1 `parse_pair` p2) (x1, x2) == size p1 x1 + size p2 x2) [SMTPat (size (p1 `parse_pair` p2) (x1, x2))] val valid_ext (p: parser) (h1: HS.mem) (b1: B.buffer U8.t) (pos1: U32.t) (pos1' : U32.t) (h2: HS.mem) (b2: B.buffer U8.t) (pos2: U32.t) (pos2' : U32.t) : Lemma (requires ( valid_pos p h1 b1 pos1 pos1' /\ U32.v pos2 <= U32.v pos2' /\ U32.v pos2' <= B.length b2 /\ B.live h2 b2 /\ B.as_seq h2 (B.gsub b2 pos2 (pos2' `U32.sub` pos2)) `Seq.equal` B.as_seq h1 (B.gsub b1 pos1 (pos1' `U32.sub` pos1)) )) (ensures ( valid_pos p h1 b1 pos1 pos1' /\ valid_pos p h2 b2 pos2 pos2' /\ contents p h2 b2 pos2 pos2' == contents p h1 b1 pos1 pos1' ))
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowStar.Buffer.fst.checked", "FStar.UInt8.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Classical.fsti.checked" ], "interface_file": false, "source_file": "LowParseWriters.LowParse.fsti" }
[ { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": false, "full_module": "LowParseWriters", "short_module": null }, { "abbrev": false, "full_module": "LowParseWriters", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
p: LowParseWriters.LowParse.parser -> h: FStar.Monotonic.HyperStack.mem -> b: LowStar.Buffer.buffer FStar.UInt8.t -> pos: FStar.UInt32.t -> pos': FStar.UInt32.t -> l: LowStar.Monotonic.Buffer.loc -> h': FStar.Monotonic.HyperStack.mem -> FStar.Pervasives.Lemma (requires LowStar.Monotonic.Buffer.live h b /\ (LowParseWriters.LowParse.valid_pos p h b pos pos' \/ LowParseWriters.LowParse.valid_pos p h' b pos pos') /\ LowStar.Monotonic.Buffer.modifies l h h' /\ LowStar.Monotonic.Buffer.loc_disjoint l (LowStar.Monotonic.Buffer.loc_buffer_from_to b pos pos')) (ensures LowParseWriters.LowParse.valid_pos p h b pos pos' /\ LowParseWriters.LowParse.valid_pos p h' b pos pos' /\ LowParseWriters.LowParse.contents p h' b pos pos' == LowParseWriters.LowParse.contents p h b pos pos')
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "LowParseWriters.LowParse.parser", "FStar.Monotonic.HyperStack.mem", "LowStar.Buffer.buffer", "FStar.UInt8.t", "FStar.UInt32.t", "LowStar.Monotonic.Buffer.loc", "FStar.Classical.move_requires", "Prims.l_and", "LowParseWriters.LowParse.valid_pos", "Prims.b2t", "Prims.op_LessThanOrEqual", "FStar.UInt32.v", "LowStar.Monotonic.Buffer.length", "LowStar.Buffer.trivial_preorder", "LowStar.Monotonic.Buffer.live", "FStar.Seq.Base.equal", "LowStar.Monotonic.Buffer.as_seq", "LowStar.Buffer.gsub", "FStar.UInt32.sub", "Prims.eq2", "LowParseWriters.LowParse.__proj__Parser__item__t", "LowParseWriters.LowParse.contents", "LowParseWriters.LowParse.valid_ext", "Prims.unit", "LowStar.Monotonic.Buffer.loc_buffer_mgsub_eq", "Prims.l_or", "LowStar.Monotonic.Buffer.modifies", "LowStar.Monotonic.Buffer.loc_disjoint", "LowStar.Monotonic.Buffer.loc_buffer_from_to", "Prims.squash", "Prims.Nil", "FStar.Pervasives.pattern" ]
[]
false
false
true
false
false
let valid_frame (p: parser) (h: HS.mem) (b: B.buffer U8.t) (pos pos': U32.t) (l: B.loc) (h': HS.mem) : Lemma (requires (B.live h b /\ (valid_pos p h b pos pos' \/ valid_pos p h' b pos pos') /\ B.modifies l h h' /\ B.loc_disjoint l (B.loc_buffer_from_to b pos pos'))) (ensures (valid_pos p h b pos pos' /\ valid_pos p h' b pos pos' /\ contents p h' b pos pos' == contents p h b pos pos')) =
B.loc_buffer_mgsub_eq (B.trivial_preorder _) b pos (pos' `U32.sub` pos); Classical.move_requires (valid_ext p h b pos pos' h' b pos) pos'; Classical.move_requires (valid_ext p h' b pos pos' h b pos) pos'
false
Vale.AsLowStar.Test.fst
Vale.AsLowStar.Test.aesni_lemma
val aesni_lemma : Vale.AsLowStar.ValeSig.vale_sig_stdcall Vale.AsLowStar.Test.aesni_pre Vale.AsLowStar.Test.aesni_post
let aesni_lemma = as_t #(VSig.vale_sig_stdcall aesni_pre aesni_post) aesni_lemma'
{ "file_name": "vale/code/arch/x64/interop/Vale.AsLowStar.Test.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 81, "end_line": 232, "start_col": 0, "start_line": 232 }
module Vale.AsLowStar.Test open FStar.Mul open Vale.Interop.Base module ME = Vale.X64.Memory module IA = Vale.Interop.Assumptions module V = Vale.X64.Decls module IX64 = Vale.Interop.X64 module VSig = Vale.AsLowStar.ValeSig module LSig = Vale.AsLowStar.LowStarSig module W = Vale.AsLowStar.Wrapper module VS = Vale.X64.State module MS = Vale.X64.Machine_s (* A little utility to trigger normalization in types *) let as_t (#a:Type) (x:normal a) : a = x let as_normal_t (#a:Type) (x:a) : normal a = x //////////////////////////////////////////////////////////////////////////////// //First a little standalone, toy experiment [@__reduce__] let b64 = buf_t TUInt8 TUInt64 [@__reduce__] let ib64 = ibuf_t TUInt8 TUInt64 [@__reduce__] let t64_mod = TD_Buffer TUInt8 TUInt64 default_bq [@__reduce__] let t64_no_mod = TD_Buffer TUInt8 TUInt64 ({modified=false; strict_disjointness=false; taint=MS.Secret}) [@__reduce__] let t64_imm = TD_ImmBuffer TUInt8 TUInt64 ({modified=false; strict_disjointness=false; taint=MS.Secret}) [@__reduce__] let (dom : list td{List.length dom <= 20}) = let y = [t64_mod;t64_imm] in assert_norm (List.length y = 2); y assume val pre : VSig.vale_pre dom assume val post : VSig.vale_post dom assume val v: VSig.vale_sig_stdcall pre post assume val c: V.va_code [@__reduce__] let call_c_t = IX64.as_lowstar_sig_t_weak_stdcall c dom [] _ _ (W.mk_prediction c dom [] (v c IA.win)) let call_c : call_c_t = IX64.wrap_weak_stdcall c dom (W.mk_prediction c dom [] (v c IA.win)) let call_c_normal_t : normal call_c_t = as_normal_t #call_c_t call_c //You can ask emacs to show you the type of call_c_normal_t ... //////////////////////////////////////////////////////////////////////////////// //Now memcpy module VM = Vale.Test.X64.Vale_memcpy [@__reduce__] let vm_dom = [t64_mod; t64_imm] open Vale.X64.MemoryAdapters (* Need to rearrange the order of arguments *) [@__reduce__] let vm_pre : VSig.vale_pre vm_dom = fun (c:V.va_code) (dst:b64) (src:ib64) (va_s0:V.va_state) -> VM.va_req_Memcpy c va_s0 IA.win (as_vale_buffer dst) (as_vale_immbuffer src) [@__reduce__] let vm_post : VSig.vale_post vm_dom = fun (c:V.va_code) (dst:b64) (src:ib64) (va_s0:V.va_state) (va_s1:V.va_state) (f:V.va_fuel) -> VM.va_ens_Memcpy c va_s0 IA.win (as_vale_buffer dst) (as_vale_immbuffer src) va_s1 f module VS = Vale.X64.State #reset-options "--print_effect_args --z3rlimit 200" (* The vale lemma doesn't quite suffice to prove the modifies clause expected of the interop layer *) [@__reduce__] let vm_lemma' (code:V.va_code) (_win:bool) (dst:b64) (src:ib64) (va_s0:V.va_state) : Ghost (V.va_state & V.va_fuel) (requires vm_pre code dst src va_s0) (ensures (fun (va_s1, f) -> V.eval_code code va_s0 f va_s1 /\ VSig.vale_calling_conventions_stdcall va_s0 va_s1 /\ vm_post code dst src va_s0 va_s1 f /\ ME.buffer_readable (VS.vs_get_vale_heap va_s1) (as_vale_immbuffer src) /\ ME.buffer_readable (VS.vs_get_vale_heap va_s1) (as_vale_buffer dst) /\ ME.buffer_writeable (as_vale_buffer dst) /\ ME.modifies (ME.loc_union (ME.loc_buffer (as_vale_buffer dst)) ME.loc_none) (VS.vs_get_vale_heap va_s0) (VS.vs_get_vale_heap va_s1) )) = let va_s1, f = VM.va_lemma_Memcpy code va_s0 IA.win (as_vale_buffer dst) (as_vale_immbuffer src) in Vale.AsLowStar.MemoryHelpers.buffer_writeable_reveal ME.TUInt8 ME.TUInt64 dst; (va_s1, f) (* Prove that vm_lemma' has the required type *) let vm_lemma = as_t #(VSig.vale_sig_stdcall vm_pre vm_post) vm_lemma' let code_Memcpy = VM.va_code_Memcpy IA.win (* Here's the type expected for the memcpy wrapper *) [@__reduce__] let lowstar_Memcpy_t = IX64.as_lowstar_sig_t_weak_stdcall code_Memcpy vm_dom [] _ _ (W.mk_prediction code_Memcpy vm_dom [] (vm_lemma code_Memcpy IA.win)) (* And here's the memcpy wrapper itself *) let lowstar_Memcpy : lowstar_Memcpy_t = IX64.wrap_weak_stdcall code_Memcpy vm_dom (W.mk_prediction code_Memcpy vm_dom [] (vm_lemma code_Memcpy IA.win)) let lowstar_Memcpy_normal_t //: normal lowstar_Memcpy_t = as_normal_t #lowstar_Memcpy_t lowstar_Memcpy module B = LowStar.Buffer module IB = LowStar.ImmutableBuffer module MB = LowStar.Monotonic.Buffer open FStar.HyperStack.ST module M = Vale.X64.Memory let test (x:b64) = assert (V.buffer_length (as_vale_buffer x) == (B.length x * view_n TUInt8) / view_n TUInt64); assert (V.buffer_length (as_vale_buffer x) == B.length x / 8) let itest (x:ib64) = assert (V.buffer_length (as_vale_immbuffer x) == (B.length x * view_n TUInt8) / view_n TUInt64); assert (V.buffer_length (as_vale_immbuffer x) == B.length x / 8) module T = FStar.Tactics #reset-options "--using_facts_from '* -FStar.Tactics -FStar.Reflection'" module LBV = LowStar.BufferView.Up module DV = LowStar.BufferView.Down #push-options "--ext compat:normalizer_memo_ignore_cfg" let memcpy_Test (dst:B.buffer UInt8.t{B.length dst % 8 == 0}) (src:IB.ibuffer UInt8.t{B.length src % 8 == 0}) : Stack UInt64.t (requires fun h0 -> B.live h0 dst /\ B.live h0 src /\ B.disjoint dst src /\ B.length dst == 16 /\ B.length src == 16) (ensures fun h0 _ h1 -> B.modifies (B.loc_buffer dst) h0 h1 /\ B.live h1 src /\ B.live h1 dst) // B.as_seq h1 dst == B.as_seq h1 src) // by (T.dump "A") (* in case you want to look at the VC *) = IB.inhabited_immutable_buffer_is_distinct_from_buffer (UInt8.uint_to_t 0) src dst; let (x, _) = lowstar_Memcpy_normal_t dst src () in //This is a call to the interop wrapper let h1 = get () in // let v = Vale.Interop.Views.up_view64 in // assert (DV.length_eq (get_downview dst); // DV.length_eq (get_downview src); // Seq.equal (LBV.as_seq h1 (LBV.mk_buffer (get_downview dst) v)) // (LBV.as_seq h1 (LBV.mk_buffer (get_downview src) v))); // lbv_as_seq_eq dst src Vale.Interop.Views.up_view64 h1; //And a lemma to rephrase the Vale postcondition x //with equalities of buffer views //back to equalities of buffers #pop-options module VC = Vale.Lib.X64.Cpuidstdcall [@__reduce__] let empty_list #a : l:list a {List.length l = 0} = [] [@__reduce__] let aesni_dom : IX64.arity_ok_stdcall td = [] (* Need to rearrange the order of arguments *) [@__reduce__] let aesni_pre : VSig.vale_pre aesni_dom = fun (c:V.va_code) (va_s0:V.va_state) -> VC.va_req_Check_aesni_stdcall c va_s0 IA.win [@__reduce__] let aesni_post : VSig.vale_post aesni_dom = fun (c:V.va_code) (va_s0:V.va_state) (va_s1:V.va_state) (f:V.va_fuel) -> VC.va_ens_Check_aesni_stdcall c va_s0 IA.win va_s1 f [@__reduce__] let with_len (l:list 'a) : Pure (list 'a) (requires True) (ensures fun m -> m==l /\ List.length m == normalize_term (List.length l)) = l #set-options "--max_fuel 0 --max_ifuel 1 --z3rlimit_factor 2" (* The vale lemma doesn't quite suffice to prove the modifies clause expected of the interop layer *) [@__reduce__] let aesni_lemma' (code:V.va_code) (_win:bool) (va_s0:V.va_state) : Ghost (V.va_state & V.va_fuel) (requires aesni_pre code va_s0) (ensures (fun (va_s1, f) -> V.eval_code code va_s0 f va_s1 /\ VSig.vale_calling_conventions_stdcall va_s0 va_s1 /\ aesni_post code va_s0 va_s1 f)) = VC.va_lemma_Check_aesni_stdcall code va_s0 IA.win #set-options "--max_fuel 0 --max_ifuel 0 --z3rlimit_factor 2"
{ "checked_file": "/", "dependencies": [ "Vale.X64.State.fsti.checked", "Vale.X64.MemoryAdapters.fsti.checked", "Vale.X64.Memory.fsti.checked", "Vale.X64.Machine_s.fst.checked", "Vale.X64.Decls.fsti.checked", "Vale.X64.CPU_Features_s.fst.checked", "Vale.Test.X64.Vale_memcpy.fsti.checked", "Vale.Test.X64.Args.fsti.checked", "Vale.Lib.X64.Cpuidstdcall.fsti.checked", "Vale.Interop.X64.fsti.checked", "Vale.Interop.Base.fst.checked", "Vale.Interop.Assumptions.fst.checked", "Vale.AsLowStar.Wrapper.fsti.checked", "Vale.AsLowStar.ValeSig.fst.checked", "Vale.AsLowStar.MemoryHelpers.fsti.checked", "Vale.AsLowStar.LowStarSig.fst.checked", "prims.fst.checked", "LowStar.Monotonic.Buffer.fsti.checked", "LowStar.ImmutableBuffer.fst.checked", "LowStar.BufferView.Up.fsti.checked", "LowStar.BufferView.Down.fsti.checked", "LowStar.Buffer.fst.checked", "FStar.UInt8.fsti.checked", "FStar.UInt64.fsti.checked", "FStar.Tactics.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.List.fst.checked", "FStar.HyperStack.ST.fsti.checked" ], "interface_file": false, "source_file": "Vale.AsLowStar.Test.fst" }
[ { "abbrev": true, "full_module": "Vale.Lib.X64.Cpuidstdcall", "short_module": "VC" }, { "abbrev": true, "full_module": "LowStar.BufferView.Down", "short_module": "DV" }, { "abbrev": true, "full_module": "LowStar.BufferView.Up", "short_module": "LBV" }, { "abbrev": true, "full_module": "FStar.Tactics", "short_module": "T" }, { "abbrev": true, "full_module": "Vale.X64.Memory", "short_module": "M" }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": true, "full_module": "LowStar.Monotonic.Buffer", "short_module": "MB" }, { "abbrev": true, "full_module": "LowStar.ImmutableBuffer", "short_module": "IB" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "Vale.X64.State", "short_module": "VS" }, { "abbrev": false, "full_module": "Vale.X64.MemoryAdapters", "short_module": null }, { "abbrev": true, "full_module": "Vale.Test.X64.Vale_memcpy", "short_module": "VM" }, { "abbrev": true, "full_module": "Vale.X64.Machine_s", "short_module": "MS" }, { "abbrev": true, "full_module": "Vale.X64.State", "short_module": "VS" }, { "abbrev": true, "full_module": "Vale.AsLowStar.Wrapper", "short_module": "W" }, { "abbrev": true, "full_module": "Vale.AsLowStar.LowStarSig", "short_module": "LSig" }, { "abbrev": true, "full_module": "Vale.AsLowStar.ValeSig", "short_module": "VSig" }, { "abbrev": true, "full_module": "Vale.Interop.X64", "short_module": "IX64" }, { "abbrev": true, "full_module": "Vale.X64.Decls", "short_module": "V" }, { "abbrev": true, "full_module": "Vale.Interop.Assumptions", "short_module": "IA" }, { "abbrev": true, "full_module": "Vale.X64.Memory", "short_module": "ME" }, { "abbrev": false, "full_module": "Vale.Interop.Base", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.AsLowStar", "short_module": null }, { "abbrev": false, "full_module": "Vale.AsLowStar", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 0, "max_fuel": 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": true, "smtencoding_l_arith_repr": "native", "smtencoding_nl_arith_repr": "wrapped", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [ "smt.arith.nl=false", "smt.QI.EAGER_THRESHOLD=100", "smt.CASE_SPLIT=3" ], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 2, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
Vale.AsLowStar.ValeSig.vale_sig_stdcall Vale.AsLowStar.Test.aesni_pre Vale.AsLowStar.Test.aesni_post
Prims.Tot
[ "total" ]
[]
[ "Vale.AsLowStar.Test.as_t", "Vale.AsLowStar.ValeSig.vale_sig_stdcall", "Vale.AsLowStar.Test.aesni_dom", "Vale.AsLowStar.Test.aesni_pre", "Vale.AsLowStar.Test.aesni_post", "Vale.AsLowStar.Test.aesni_lemma'" ]
[]
false
false
false
true
false
let aesni_lemma =
as_t #(VSig.vale_sig_stdcall aesni_pre aesni_post) aesni_lemma'
false
Pulse.Soundness.fst
Pulse.Soundness.frame_soundness
val frame_soundness (g: stt_env) (t: st_term) (c: comp) (d: st_typing g t c {T_Frame? d}) (soundness: soundness_t d) : GTot (RT.tot_typing (elab_env g) (elab_st_typing d) (elab_comp c))
val frame_soundness (g: stt_env) (t: st_term) (c: comp) (d: st_typing g t c {T_Frame? d}) (soundness: soundness_t d) : GTot (RT.tot_typing (elab_env g) (elab_st_typing d) (elab_comp c))
let frame_soundness (g:stt_env) (t:st_term) (c:comp) (d:st_typing g t c{T_Frame? d}) (soundness:soundness_t d) : GTot (RT.tot_typing (elab_env g) (elab_st_typing d) (elab_comp c)) = let T_Frame _ e c frame frame_typing e_typing = d in let r_e_typing = soundness _ _ _ e_typing in LN.st_typing_ln e_typing; Frame.elab_frame_typing g _ _ frame frame_typing r_e_typing
{ "file_name": "lib/steel/pulse/Pulse.Soundness.fst", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 61, "end_line": 107, "start_col": 0, "start_line": 96 }
(* Copyright 2023 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module Pulse.Soundness module RT = FStar.Reflection.Typing module R = FStar.Reflection.V2 module L = FStar.List.Tot module T = FStar.Tactics.V2 open FStar.List.Tot open Pulse.Syntax open Pulse.Reflection.Util open Pulse.Typing open Pulse.Elaborate open Pulse.Soundness.Common module Bind = Pulse.Soundness.Bind module Lift = Pulse.Soundness.Lift module Frame = Pulse.Soundness.Frame module STEquiv = Pulse.Soundness.STEquiv module Return = Pulse.Soundness.Return module Exists = Pulse.Soundness.Exists module While = Pulse.Soundness.While module Admit = Pulse.Soundness.Admit module Par = Pulse.Soundness.Par module WithLocal = Pulse.Soundness.WithLocal module WithLocalArray = Pulse.Soundness.WithLocalArray module Rewrite = Pulse.Soundness.Rewrite module Comp = Pulse.Soundness.Comp module LN = Pulse.Typing.LN module FV = Pulse.Typing.FV module STT = Pulse.Soundness.STT module Sub = Pulse.Soundness.Sub module RU = Pulse.RuntimeUtils module Typing = Pulse.Typing module EPure = Pulse.Elaborate.Pure module WT= Pulse.Steel.Wrapper.Typing let tabs_t (d:'a) = #g:stt_env -> #u:universe -> #ty:term -> q:option qualifier -> ppname:ppname -> t_typing:tot_typing g ty (tm_type u) { t_typing << d } -> #body:st_term -> #x:var { None? (lookup g x) /\ ~(x `Set.mem` freevars_st body) } -> #c:comp -> body_typing:st_typing (push_binding g x ppname ty) (open_st_term body x) c { body_typing << d } -> GTot (RT.tot_typing (elab_env g) (mk_abs_with_name ppname.name (elab_term ty) (elab_qual q) (RT.close_term (elab_st_typing body_typing) x)) (elab_term (tm_arrow (mk_binder_ppname ty ppname) q (close_comp c x)))) #push-options "--z3rlimit_factor 4 --split_queries no" let lift_soundness (g:stt_env) (t:st_term) (c:comp) (d:st_typing g t c{T_Lift? d}) (soundness:soundness_t d) : GTot (RT.tot_typing (elab_env g) (elab_st_typing d) (elab_comp c)) = LN.st_typing_ln d; let T_Lift _ e c1 c2 e_typing lc = d in LN.st_typing_ln e_typing; match lc with | Lift_STAtomic_ST _ _ -> Lift.elab_lift_stt_atomic_st_typing g c1 c2 _ (soundness _ _ _ e_typing) lc | Lift_Ghost_Neutral _ _ w -> let (| reveal_a, reveal_a_typing |) = w in Lift.elab_lift_ghost_neutral_typing g c1 c2 _ (soundness _ _ _ e_typing) lc _ (tot_typing_soundness reveal_a_typing) | Lift_Neutral_Ghost _ _ -> Lift.elab_lift_neutral_ghost_typing g c1 c2 _ (soundness _ _ _ e_typing) lc | Lift_Observability _ _ _ -> Lift.elab_lift_observability_typing g c1 c2 _ (soundness _ _ _ e_typing) lc #pop-options
{ "checked_file": "/", "dependencies": [ "Pulse.Typing.LN.fsti.checked", "Pulse.Typing.FV.fsti.checked", "Pulse.Typing.fst.checked", "Pulse.Syntax.fst.checked", "Pulse.Steel.Wrapper.Typing.fsti.checked", "Pulse.Soundness.WithLocalArray.fsti.checked", "Pulse.Soundness.WithLocal.fsti.checked", "Pulse.Soundness.While.fsti.checked", "Pulse.Soundness.Sub.fsti.checked", "Pulse.Soundness.STT.fsti.checked", "Pulse.Soundness.STEquiv.fsti.checked", "Pulse.Soundness.Rewrite.fsti.checked", "Pulse.Soundness.Return.fsti.checked", "Pulse.Soundness.Par.fsti.checked", "Pulse.Soundness.Match.fsti.checked", "Pulse.Soundness.Lift.fsti.checked", "Pulse.Soundness.Frame.fsti.checked", "Pulse.Soundness.Exists.fsti.checked", "Pulse.Soundness.Comp.fsti.checked", "Pulse.Soundness.Common.fst.checked", "Pulse.Soundness.Bind.fsti.checked", "Pulse.Soundness.Admit.fsti.checked", "Pulse.RuntimeUtils.fsti.checked", "Pulse.Reflection.Util.fst.checked", "Pulse.Elaborate.Pure.fst.checked", "Pulse.Elaborate.fsti.checked", "prims.fst.checked", "FStar.Tactics.V2.fst.checked", "FStar.Squash.fsti.checked", "FStar.Set.fsti.checked", "FStar.Reflection.V2.fst.checked", "FStar.Reflection.Typing.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked" ], "interface_file": true, "source_file": "Pulse.Soundness.fst" }
[ { "abbrev": true, "full_module": "Pulse.Steel.Wrapper.Typing", "short_module": "WT" }, { "abbrev": true, "full_module": "Pulse.Elaborate.Pure", "short_module": "EPure" }, { "abbrev": true, "full_module": "Pulse.Typing", "short_module": "Typing" }, { "abbrev": true, "full_module": "Pulse.RuntimeUtils", "short_module": "RU" }, { "abbrev": true, "full_module": "Pulse.Soundness.Sub", "short_module": "Sub" }, { "abbrev": true, "full_module": "Pulse.Soundness.STT", "short_module": "STT" }, { "abbrev": true, "full_module": "Pulse.Typing.FV", "short_module": "FV" }, { "abbrev": true, "full_module": "Pulse.Typing.LN", "short_module": "LN" }, { "abbrev": true, "full_module": "Pulse.Soundness.Comp", "short_module": "Comp" }, { "abbrev": true, "full_module": "Pulse.Soundness.Rewrite", "short_module": "Rewrite" }, { "abbrev": true, "full_module": "Pulse.Soundness.WithLocalArray", "short_module": "WithLocalArray" }, { "abbrev": true, "full_module": "Pulse.Soundness.WithLocal", "short_module": "WithLocal" }, { "abbrev": true, "full_module": "Pulse.Soundness.Par", "short_module": "Par" }, { "abbrev": true, "full_module": "Pulse.Soundness.Admit", "short_module": "Admit" }, { "abbrev": true, "full_module": "Pulse.Soundness.While", "short_module": "While" }, { "abbrev": true, "full_module": "Pulse.Soundness.Exists", "short_module": "Exists" }, { "abbrev": true, "full_module": "Pulse.Soundness.Return", "short_module": "Return" }, { "abbrev": true, "full_module": "Pulse.Soundness.STEquiv", "short_module": "STEquiv" }, { "abbrev": true, "full_module": "Pulse.Soundness.Frame", "short_module": "Frame" }, { "abbrev": true, "full_module": "Pulse.Soundness.Lift", "short_module": "Lift" }, { "abbrev": true, "full_module": "Pulse.Soundness.Bind", "short_module": "Bind" }, { "abbrev": false, "full_module": "Pulse.Soundness.Common", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Elaborate", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Typing", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Reflection.Util", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Syntax", "short_module": null }, { "abbrev": false, "full_module": "FStar.List.Tot", "short_module": null }, { "abbrev": true, "full_module": "FStar.Tactics.V2", "short_module": "T" }, { "abbrev": true, "full_module": "FStar.List.Tot", "short_module": "L" }, { "abbrev": true, "full_module": "FStar.Reflection.V2", "short_module": "R" }, { "abbrev": true, "full_module": "FStar.Reflection.Typing", "short_module": "RT" }, { "abbrev": false, "full_module": "Pulse.Soundness.Common", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Elaborate", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Typing", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Reflection.Util", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Syntax", "short_module": null }, { "abbrev": false, "full_module": "FStar.List.Tot", "short_module": null }, { "abbrev": true, "full_module": "FStar.Tactics.V2", "short_module": "T" }, { "abbrev": true, "full_module": "FStar.List.Tot", "short_module": "L" }, { "abbrev": true, "full_module": "FStar.Reflection.V2", "short_module": "R" }, { "abbrev": true, "full_module": "FStar.Reflection.Typing", "short_module": "RT" }, { "abbrev": false, "full_module": "Pulse", "short_module": null }, { "abbrev": false, "full_module": "Pulse", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
g: Pulse.Soundness.Common.stt_env -> t: Pulse.Syntax.Base.st_term -> c: Pulse.Syntax.Base.comp -> d: Pulse.Typing.st_typing g t c {T_Frame? d} -> soundness: Pulse.Soundness.Common.soundness_t d -> Prims.GTot (FStar.Reflection.Typing.tot_typing (Pulse.Typing.elab_env g) (Pulse.Elaborate.Core.elab_st_typing d) (Pulse.Elaborate.Pure.elab_comp c))
Prims.GTot
[ "sometrivial" ]
[]
[ "Pulse.Soundness.Common.stt_env", "Pulse.Syntax.Base.st_term", "Pulse.Syntax.Base.comp", "Pulse.Typing.st_typing", "Prims.b2t", "Pulse.Typing.uu___is_T_Frame", "Pulse.Soundness.Common.soundness_t", "Pulse.Typing.Env.env", "Pulse.Syntax.Base.comp_st", "Pulse.Syntax.Base.term", "Pulse.Typing.tot_typing", "Pulse.Syntax.Base.tm_vprop", "Pulse.Soundness.Frame.elab_frame_typing", "Pulse.Elaborate.Core.elab_st_typing", "Prims.unit", "Pulse.Typing.LN.st_typing_ln", "FStar.Reflection.Typing.tot_typing", "Pulse.Typing.elab_env", "Pulse.Elaborate.Pure.elab_comp" ]
[]
false
false
false
false
false
let frame_soundness (g: stt_env) (t: st_term) (c: comp) (d: st_typing g t c {T_Frame? d}) (soundness: soundness_t d) : GTot (RT.tot_typing (elab_env g) (elab_st_typing d) (elab_comp c)) =
let T_Frame _ e c frame frame_typing e_typing = d in let r_e_typing = soundness _ _ _ e_typing in LN.st_typing_ln e_typing; Frame.elab_frame_typing g _ _ frame frame_typing r_e_typing
false
Pulse.Soundness.fst
Pulse.Soundness.tabs_t
val tabs_t : d: 'a -> Type0
let tabs_t (d:'a) = #g:stt_env -> #u:universe -> #ty:term -> q:option qualifier -> ppname:ppname -> t_typing:tot_typing g ty (tm_type u) { t_typing << d } -> #body:st_term -> #x:var { None? (lookup g x) /\ ~(x `Set.mem` freevars_st body) } -> #c:comp -> body_typing:st_typing (push_binding g x ppname ty) (open_st_term body x) c { body_typing << d } -> GTot (RT.tot_typing (elab_env g) (mk_abs_with_name ppname.name (elab_term ty) (elab_qual q) (RT.close_term (elab_st_typing body_typing) x)) (elab_term (tm_arrow (mk_binder_ppname ty ppname) q (close_comp c x))))
{ "file_name": "lib/steel/pulse/Pulse.Soundness.fst", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 83, "end_line": 63, "start_col": 0, "start_line": 50 }
(* Copyright 2023 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module Pulse.Soundness module RT = FStar.Reflection.Typing module R = FStar.Reflection.V2 module L = FStar.List.Tot module T = FStar.Tactics.V2 open FStar.List.Tot open Pulse.Syntax open Pulse.Reflection.Util open Pulse.Typing open Pulse.Elaborate open Pulse.Soundness.Common module Bind = Pulse.Soundness.Bind module Lift = Pulse.Soundness.Lift module Frame = Pulse.Soundness.Frame module STEquiv = Pulse.Soundness.STEquiv module Return = Pulse.Soundness.Return module Exists = Pulse.Soundness.Exists module While = Pulse.Soundness.While module Admit = Pulse.Soundness.Admit module Par = Pulse.Soundness.Par module WithLocal = Pulse.Soundness.WithLocal module WithLocalArray = Pulse.Soundness.WithLocalArray module Rewrite = Pulse.Soundness.Rewrite module Comp = Pulse.Soundness.Comp module LN = Pulse.Typing.LN module FV = Pulse.Typing.FV module STT = Pulse.Soundness.STT module Sub = Pulse.Soundness.Sub module RU = Pulse.RuntimeUtils module Typing = Pulse.Typing module EPure = Pulse.Elaborate.Pure module WT= Pulse.Steel.Wrapper.Typing
{ "checked_file": "/", "dependencies": [ "Pulse.Typing.LN.fsti.checked", "Pulse.Typing.FV.fsti.checked", "Pulse.Typing.fst.checked", "Pulse.Syntax.fst.checked", "Pulse.Steel.Wrapper.Typing.fsti.checked", "Pulse.Soundness.WithLocalArray.fsti.checked", "Pulse.Soundness.WithLocal.fsti.checked", "Pulse.Soundness.While.fsti.checked", "Pulse.Soundness.Sub.fsti.checked", "Pulse.Soundness.STT.fsti.checked", "Pulse.Soundness.STEquiv.fsti.checked", "Pulse.Soundness.Rewrite.fsti.checked", "Pulse.Soundness.Return.fsti.checked", "Pulse.Soundness.Par.fsti.checked", "Pulse.Soundness.Match.fsti.checked", "Pulse.Soundness.Lift.fsti.checked", "Pulse.Soundness.Frame.fsti.checked", "Pulse.Soundness.Exists.fsti.checked", "Pulse.Soundness.Comp.fsti.checked", "Pulse.Soundness.Common.fst.checked", "Pulse.Soundness.Bind.fsti.checked", "Pulse.Soundness.Admit.fsti.checked", "Pulse.RuntimeUtils.fsti.checked", "Pulse.Reflection.Util.fst.checked", "Pulse.Elaborate.Pure.fst.checked", "Pulse.Elaborate.fsti.checked", "prims.fst.checked", "FStar.Tactics.V2.fst.checked", "FStar.Squash.fsti.checked", "FStar.Set.fsti.checked", "FStar.Reflection.V2.fst.checked", "FStar.Reflection.Typing.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked" ], "interface_file": true, "source_file": "Pulse.Soundness.fst" }
[ { "abbrev": true, "full_module": "Pulse.Steel.Wrapper.Typing", "short_module": "WT" }, { "abbrev": true, "full_module": "Pulse.Elaborate.Pure", "short_module": "EPure" }, { "abbrev": true, "full_module": "Pulse.Typing", "short_module": "Typing" }, { "abbrev": true, "full_module": "Pulse.RuntimeUtils", "short_module": "RU" }, { "abbrev": true, "full_module": "Pulse.Soundness.Sub", "short_module": "Sub" }, { "abbrev": true, "full_module": "Pulse.Soundness.STT", "short_module": "STT" }, { "abbrev": true, "full_module": "Pulse.Typing.FV", "short_module": "FV" }, { "abbrev": true, "full_module": "Pulse.Typing.LN", "short_module": "LN" }, { "abbrev": true, "full_module": "Pulse.Soundness.Comp", "short_module": "Comp" }, { "abbrev": true, "full_module": "Pulse.Soundness.Rewrite", "short_module": "Rewrite" }, { "abbrev": true, "full_module": "Pulse.Soundness.WithLocalArray", "short_module": "WithLocalArray" }, { "abbrev": true, "full_module": "Pulse.Soundness.WithLocal", "short_module": "WithLocal" }, { "abbrev": true, "full_module": "Pulse.Soundness.Par", "short_module": "Par" }, { "abbrev": true, "full_module": "Pulse.Soundness.Admit", "short_module": "Admit" }, { "abbrev": true, "full_module": "Pulse.Soundness.While", "short_module": "While" }, { "abbrev": true, "full_module": "Pulse.Soundness.Exists", "short_module": "Exists" }, { "abbrev": true, "full_module": "Pulse.Soundness.Return", "short_module": "Return" }, { "abbrev": true, "full_module": "Pulse.Soundness.STEquiv", "short_module": "STEquiv" }, { "abbrev": true, "full_module": "Pulse.Soundness.Frame", "short_module": "Frame" }, { "abbrev": true, "full_module": "Pulse.Soundness.Lift", "short_module": "Lift" }, { "abbrev": true, "full_module": "Pulse.Soundness.Bind", "short_module": "Bind" }, { "abbrev": false, "full_module": "Pulse.Soundness.Common", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Elaborate", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Typing", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Reflection.Util", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Syntax", "short_module": null }, { "abbrev": false, "full_module": "FStar.List.Tot", "short_module": null }, { "abbrev": true, "full_module": "FStar.Tactics.V2", "short_module": "T" }, { "abbrev": true, "full_module": "FStar.List.Tot", "short_module": "L" }, { "abbrev": true, "full_module": "FStar.Reflection.V2", "short_module": "R" }, { "abbrev": true, "full_module": "FStar.Reflection.Typing", "short_module": "RT" }, { "abbrev": false, "full_module": "Pulse.Soundness.Common", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Elaborate", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Typing", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Reflection.Util", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Syntax", "short_module": null }, { "abbrev": false, "full_module": "FStar.List.Tot", "short_module": null }, { "abbrev": true, "full_module": "FStar.Tactics.V2", "short_module": "T" }, { "abbrev": true, "full_module": "FStar.List.Tot", "short_module": "L" }, { "abbrev": true, "full_module": "FStar.Reflection.V2", "short_module": "R" }, { "abbrev": true, "full_module": "FStar.Reflection.Typing", "short_module": "RT" }, { "abbrev": false, "full_module": "Pulse", "short_module": null }, { "abbrev": false, "full_module": "Pulse", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
d: 'a -> Type0
Prims.Tot
[ "total" ]
[]
[ "Pulse.Soundness.Common.stt_env", "Pulse.Syntax.Base.universe", "Pulse.Syntax.Base.term", "FStar.Pervasives.Native.option", "Pulse.Syntax.Base.qualifier", "Pulse.Syntax.Base.ppname", "Pulse.Typing.tot_typing", "Pulse.Syntax.Pure.tm_type", "Prims.precedes", "Pulse.Syntax.Base.st_term", "Pulse.Syntax.Base.var", "Prims.l_and", "Prims.b2t", "FStar.Pervasives.Native.uu___is_None", "Pulse.Syntax.Base.typ", "Pulse.Typing.Env.lookup", "Prims.l_not", "FStar.Set.mem", "Pulse.Syntax.Naming.freevars_st", "Pulse.Syntax.Base.comp", "Pulse.Typing.st_typing", "Pulse.Typing.Env.push_binding", "Pulse.Syntax.Naming.open_st_term", "FStar.Reflection.Typing.tot_typing", "Pulse.Typing.elab_env", "Pulse.Reflection.Util.mk_abs_with_name", "Pulse.Syntax.Base.__proj__Mkppname__item__name", "Pulse.Elaborate.Pure.elab_term", "Pulse.Elaborate.Pure.elab_qual", "FStar.Reflection.Typing.close_term", "Pulse.Elaborate.Core.elab_st_typing", "Pulse.Syntax.Pure.tm_arrow", "Pulse.Syntax.Base.mk_binder_ppname", "Pulse.Syntax.Naming.close_comp" ]
[]
false
false
false
true
true
let tabs_t (d: 'a) =
#g: stt_env -> #u: universe -> #ty: term -> q: option qualifier -> ppname: ppname -> t_typing: tot_typing g ty (tm_type u) {t_typing << d} -> #body: st_term -> #x: var{None? (lookup g x) /\ ~(x `Set.mem` (freevars_st body))} -> #c: comp -> body_typing: st_typing (push_binding g x ppname ty) (open_st_term body x) c {body_typing << d} -> GTot (RT.tot_typing (elab_env g) (mk_abs_with_name ppname.name (elab_term ty) (elab_qual q) (RT.close_term (elab_st_typing body_typing) x)) (elab_term (tm_arrow (mk_binder_ppname ty ppname) q (close_comp c x))))
false
LowParseWriters.LowParse.fsti
LowParseWriters.LowParse.valid_gsub_intro
val valid_gsub_intro (p: parser) (h: HS.mem) (b: B.buffer U8.t) (pos0 pos1 pos2 len: U32.t) : Lemma (requires (U32.v pos0 + U32.v len <= B.length b /\ U32.v pos1 <= U32.v pos2 /\ U32.v pos2 <= U32.v len /\ valid_pos p h b (pos0 `U32.add` pos1) (pos0 `U32.add` pos2))) (ensures (valid_pos p h (B.gsub b pos0 len) pos1 pos2 /\ contents p h b (pos0 `U32.add` pos1) (pos0 `U32.add` pos2) == contents p h (B.gsub b pos0 len) pos1 pos2)) [SMTPat (valid_pos p h (B.gsub b pos0 len) pos1 pos2)]
val valid_gsub_intro (p: parser) (h: HS.mem) (b: B.buffer U8.t) (pos0 pos1 pos2 len: U32.t) : Lemma (requires (U32.v pos0 + U32.v len <= B.length b /\ U32.v pos1 <= U32.v pos2 /\ U32.v pos2 <= U32.v len /\ valid_pos p h b (pos0 `U32.add` pos1) (pos0 `U32.add` pos2))) (ensures (valid_pos p h (B.gsub b pos0 len) pos1 pos2 /\ contents p h b (pos0 `U32.add` pos1) (pos0 `U32.add` pos2) == contents p h (B.gsub b pos0 len) pos1 pos2)) [SMTPat (valid_pos p h (B.gsub b pos0 len) pos1 pos2)]
let valid_gsub_intro (p: parser) (h: HS.mem) (b: B.buffer U8.t) (pos0 pos1 pos2: U32.t) (len: U32.t) : Lemma (requires ( U32.v pos0 + U32.v len <= B.length b /\ U32.v pos1 <= U32.v pos2 /\ U32.v pos2 <= U32.v len /\ valid_pos p h b (pos0 `U32.add` pos1) (pos0 `U32.add` pos2) )) (ensures ( valid_pos p h (B.gsub b pos0 len) pos1 pos2 /\ contents p h b (pos0 `U32.add` pos1) (pos0 `U32.add` pos2) == contents p h (B.gsub b pos0 len) pos1 pos2 )) [SMTPat (valid_pos p h (B.gsub b pos0 len) pos1 pos2)] = valid_ext p h b (pos0 `U32.add` pos1) (pos0 `U32.add` pos2) h (B.gsub b pos0 len) pos1 pos2
{ "file_name": "examples/layeredeffects/LowParseWriters.LowParse.fsti", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 93, "end_line": 216, "start_col": 0, "start_line": 197 }
module LowParseWriters.LowParse module HS = FStar.HyperStack module B = LowStar.Buffer module U8 = FStar.UInt8 module U32 = FStar.UInt32 module HST = FStar.HyperStack.ST type u8 : Type0 = U8.t val parser' (t: Type0) : Type u#1 inline_for_extraction noextract noeq type parser = | Parser: t: Type -> p: parser' t -> parser val valid_pos (p: parser) (h: HS.mem) (b: B.buffer U8.t) (pos: U32.t) (pos' : U32.t) : GTot Type0 val valid_pos_post (p: parser) (h: HS.mem) (b: B.buffer U8.t) (pos: U32.t) (pos' : U32.t) : Lemma (requires (valid_pos p h b pos pos')) (ensures ( B.live h b /\ U32.v pos <= U32.v pos' /\ U32.v pos' <= B.length b )) [SMTPat (valid_pos p h b pos pos')] val contents (p: parser) (h: HS.mem) (b: B.buffer U8.t) (pos: U32.t) (pos' : U32.t) : Ghost (Parser?.t p) (requires (valid_pos p h b pos pos')) (ensures (fun _ -> True)) val size (p: parser) (x: Parser?.t p) : GTot nat val contents_size (p: parser) (h: HS.mem) (b: B.buffer U8.t) (pos: U32.t) (pos' : U32.t) : Lemma (requires (valid_pos p h b pos pos')) (ensures ( valid_pos p h b pos pos' /\ size p (contents p h b pos pos') == U32.v pos' - U32.v pos )) [SMTPat (contents p h b pos pos')] inline_for_extraction val parse_empty' : parser' unit inline_for_extraction let parse_empty : parser = Parser unit parse_empty' val valid_parse_empty (h: HS.mem) (b: B.buffer u8) (pos: U32.t) (pos' : U32.t) : Lemma ( valid_pos parse_empty h b pos pos' <==> ( B.live h b /\ U32.v pos <= B.length b /\ U32.v pos' == U32.v pos )) [SMTPat (valid_pos parse_empty h b pos pos')] val size_parse_empty : squash (size parse_empty () == 0) inline_for_extraction val parse_pair' (#t1 #t2: Type) (p1: parser' t1) (p2: parser' t2) : Tot (parser' (t1 & t2)) inline_for_extraction let parse_pair (p1 p2: parser) : Tot parser = Parser (Parser?.t p1 & Parser?.t p2) (parse_pair' (Parser?.p p1) (Parser?.p p2)) val valid_parse_pair (p1 p2: parser) (h: HS.mem) (b: B.buffer U8.t) (pos1 pos2 pos3: U32.t) : Lemma (requires ( valid_pos p1 h b pos1 pos2 /\ valid_pos p2 h b pos2 pos3 )) (ensures ( valid_pos p1 h b pos1 pos2 /\ valid_pos p2 h b pos2 pos3 /\ valid_pos (p1 `parse_pair` p2) h b pos1 pos3 /\ contents (p1 `parse_pair` p2) h b pos1 pos3 == (contents p1 h b pos1 pos2, contents p2 h b pos2 pos3) )) val size_parse_pair (p1 p2: parser) (x1: Parser?.t p1) (x2: Parser?.t p2) : Lemma (size (p1 `parse_pair` p2) (x1, x2) == size p1 x1 + size p2 x2) [SMTPat (size (p1 `parse_pair` p2) (x1, x2))] val valid_ext (p: parser) (h1: HS.mem) (b1: B.buffer U8.t) (pos1: U32.t) (pos1' : U32.t) (h2: HS.mem) (b2: B.buffer U8.t) (pos2: U32.t) (pos2' : U32.t) : Lemma (requires ( valid_pos p h1 b1 pos1 pos1' /\ U32.v pos2 <= U32.v pos2' /\ U32.v pos2' <= B.length b2 /\ B.live h2 b2 /\ B.as_seq h2 (B.gsub b2 pos2 (pos2' `U32.sub` pos2)) `Seq.equal` B.as_seq h1 (B.gsub b1 pos1 (pos1' `U32.sub` pos1)) )) (ensures ( valid_pos p h1 b1 pos1 pos1' /\ valid_pos p h2 b2 pos2 pos2' /\ contents p h2 b2 pos2 pos2' == contents p h1 b1 pos1 pos1' )) let valid_frame (p: parser) (h: HS.mem) (b: B.buffer U8.t) (pos: U32.t) (pos' : U32.t) (l: B.loc) (h' : HS.mem) : Lemma (requires ( B.live h b /\ (valid_pos p h b pos pos' \/ valid_pos p h' b pos pos') /\ B.modifies l h h' /\ B.loc_disjoint l (B.loc_buffer_from_to b pos pos') )) (ensures ( valid_pos p h b pos pos' /\ valid_pos p h' b pos pos' /\ contents p h' b pos pos' == contents p h b pos pos' )) = B.loc_buffer_mgsub_eq (B.trivial_preorder _) b pos (pos' `U32.sub` pos); Classical.move_requires (valid_ext p h b pos pos' h' b pos) pos'; Classical.move_requires (valid_ext p h' b pos pos' h b pos) pos' let valid_gsub_elim (p: parser) (h: HS.mem) (b: B.buffer U8.t) (pos0 pos1 pos2: U32.t) (len: U32.t) : Lemma (requires ( U32.v pos0 + U32.v len <= B.length b /\ valid_pos p h (B.gsub b pos0 len) pos1 pos2 /\ B.live h b )) (ensures ( U32.v pos0 + U32.v pos2 <= B.length b /\ valid_pos p h (B.gsub b pos0 len) pos1 pos2 /\ valid_pos p h b (pos0 `U32.add` pos1) (pos0 `U32.add` pos2) /\ contents p h b (pos0 `U32.add` pos1) (pos0 `U32.add` pos2) == contents p h (B.gsub b pos0 len) pos1 pos2 )) [SMTPat (valid_pos p h (B.gsub b pos0 len) pos1 pos2)] = valid_ext p h (B.gsub b pos0 len) pos1 pos2 h b (pos0 `U32.add` pos1) (pos0 `U32.add` pos2)
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowStar.Buffer.fst.checked", "FStar.UInt8.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Classical.fsti.checked" ], "interface_file": false, "source_file": "LowParseWriters.LowParse.fsti" }
[ { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": false, "full_module": "LowParseWriters", "short_module": null }, { "abbrev": false, "full_module": "LowParseWriters", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
p: LowParseWriters.LowParse.parser -> h: FStar.Monotonic.HyperStack.mem -> b: LowStar.Buffer.buffer FStar.UInt8.t -> pos0: FStar.UInt32.t -> pos1: FStar.UInt32.t -> pos2: FStar.UInt32.t -> len: FStar.UInt32.t -> FStar.Pervasives.Lemma (requires FStar.UInt32.v pos0 + FStar.UInt32.v len <= LowStar.Monotonic.Buffer.length b /\ FStar.UInt32.v pos1 <= FStar.UInt32.v pos2 /\ FStar.UInt32.v pos2 <= FStar.UInt32.v len /\ LowParseWriters.LowParse.valid_pos p h b (FStar.UInt32.add pos0 pos1) (FStar.UInt32.add pos0 pos2)) (ensures LowParseWriters.LowParse.valid_pos p h (LowStar.Buffer.gsub b pos0 len) pos1 pos2 /\ LowParseWriters.LowParse.contents p h b (FStar.UInt32.add pos0 pos1) (FStar.UInt32.add pos0 pos2) == LowParseWriters.LowParse.contents p h (LowStar.Buffer.gsub b pos0 len) pos1 pos2) [SMTPat (LowParseWriters.LowParse.valid_pos p h (LowStar.Buffer.gsub b pos0 len) pos1 pos2)]
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "LowParseWriters.LowParse.parser", "FStar.Monotonic.HyperStack.mem", "LowStar.Buffer.buffer", "FStar.UInt8.t", "FStar.UInt32.t", "LowParseWriters.LowParse.valid_ext", "FStar.UInt32.add", "LowStar.Buffer.gsub", "Prims.unit", "Prims.l_and", "Prims.b2t", "Prims.op_LessThanOrEqual", "Prims.op_Addition", "FStar.UInt32.v", "LowStar.Monotonic.Buffer.length", "LowStar.Buffer.trivial_preorder", "LowParseWriters.LowParse.valid_pos", "Prims.squash", "Prims.eq2", "LowParseWriters.LowParse.__proj__Parser__item__t", "LowParseWriters.LowParse.contents", "Prims.Cons", "FStar.Pervasives.pattern", "FStar.Pervasives.smt_pat", "Prims.Nil" ]
[]
true
false
true
false
false
let valid_gsub_intro (p: parser) (h: HS.mem) (b: B.buffer U8.t) (pos0 pos1 pos2 len: U32.t) : Lemma (requires (U32.v pos0 + U32.v len <= B.length b /\ U32.v pos1 <= U32.v pos2 /\ U32.v pos2 <= U32.v len /\ valid_pos p h b (pos0 `U32.add` pos1) (pos0 `U32.add` pos2))) (ensures (valid_pos p h (B.gsub b pos0 len) pos1 pos2 /\ contents p h b (pos0 `U32.add` pos1) (pos0 `U32.add` pos2) == contents p h (B.gsub b pos0 len) pos1 pos2)) [SMTPat (valid_pos p h (B.gsub b pos0 len) pos1 pos2)] =
valid_ext p h b (pos0 `U32.add` pos1) (pos0 `U32.add` pos2) h (B.gsub b pos0 len) pos1 pos2
false
LowParseWriters.LowParse.fsti
LowParseWriters.LowParse.valid_gsub_elim
val valid_gsub_elim (p: parser) (h: HS.mem) (b: B.buffer U8.t) (pos0 pos1 pos2 len: U32.t) : Lemma (requires (U32.v pos0 + U32.v len <= B.length b /\ valid_pos p h (B.gsub b pos0 len) pos1 pos2 /\ B.live h b)) (ensures (U32.v pos0 + U32.v pos2 <= B.length b /\ valid_pos p h (B.gsub b pos0 len) pos1 pos2 /\ valid_pos p h b (pos0 `U32.add` pos1) (pos0 `U32.add` pos2) /\ contents p h b (pos0 `U32.add` pos1) (pos0 `U32.add` pos2) == contents p h (B.gsub b pos0 len) pos1 pos2)) [SMTPat (valid_pos p h (B.gsub b pos0 len) pos1 pos2)]
val valid_gsub_elim (p: parser) (h: HS.mem) (b: B.buffer U8.t) (pos0 pos1 pos2 len: U32.t) : Lemma (requires (U32.v pos0 + U32.v len <= B.length b /\ valid_pos p h (B.gsub b pos0 len) pos1 pos2 /\ B.live h b)) (ensures (U32.v pos0 + U32.v pos2 <= B.length b /\ valid_pos p h (B.gsub b pos0 len) pos1 pos2 /\ valid_pos p h b (pos0 `U32.add` pos1) (pos0 `U32.add` pos2) /\ contents p h b (pos0 `U32.add` pos1) (pos0 `U32.add` pos2) == contents p h (B.gsub b pos0 len) pos1 pos2)) [SMTPat (valid_pos p h (B.gsub b pos0 len) pos1 pos2)]
let valid_gsub_elim (p: parser) (h: HS.mem) (b: B.buffer U8.t) (pos0 pos1 pos2: U32.t) (len: U32.t) : Lemma (requires ( U32.v pos0 + U32.v len <= B.length b /\ valid_pos p h (B.gsub b pos0 len) pos1 pos2 /\ B.live h b )) (ensures ( U32.v pos0 + U32.v pos2 <= B.length b /\ valid_pos p h (B.gsub b pos0 len) pos1 pos2 /\ valid_pos p h b (pos0 `U32.add` pos1) (pos0 `U32.add` pos2) /\ contents p h b (pos0 `U32.add` pos1) (pos0 `U32.add` pos2) == contents p h (B.gsub b pos0 len) pos1 pos2 )) [SMTPat (valid_pos p h (B.gsub b pos0 len) pos1 pos2)] = valid_ext p h (B.gsub b pos0 len) pos1 pos2 h b (pos0 `U32.add` pos1) (pos0 `U32.add` pos2)
{ "file_name": "examples/layeredeffects/LowParseWriters.LowParse.fsti", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 93, "end_line": 195, "start_col": 0, "start_line": 175 }
module LowParseWriters.LowParse module HS = FStar.HyperStack module B = LowStar.Buffer module U8 = FStar.UInt8 module U32 = FStar.UInt32 module HST = FStar.HyperStack.ST type u8 : Type0 = U8.t val parser' (t: Type0) : Type u#1 inline_for_extraction noextract noeq type parser = | Parser: t: Type -> p: parser' t -> parser val valid_pos (p: parser) (h: HS.mem) (b: B.buffer U8.t) (pos: U32.t) (pos' : U32.t) : GTot Type0 val valid_pos_post (p: parser) (h: HS.mem) (b: B.buffer U8.t) (pos: U32.t) (pos' : U32.t) : Lemma (requires (valid_pos p h b pos pos')) (ensures ( B.live h b /\ U32.v pos <= U32.v pos' /\ U32.v pos' <= B.length b )) [SMTPat (valid_pos p h b pos pos')] val contents (p: parser) (h: HS.mem) (b: B.buffer U8.t) (pos: U32.t) (pos' : U32.t) : Ghost (Parser?.t p) (requires (valid_pos p h b pos pos')) (ensures (fun _ -> True)) val size (p: parser) (x: Parser?.t p) : GTot nat val contents_size (p: parser) (h: HS.mem) (b: B.buffer U8.t) (pos: U32.t) (pos' : U32.t) : Lemma (requires (valid_pos p h b pos pos')) (ensures ( valid_pos p h b pos pos' /\ size p (contents p h b pos pos') == U32.v pos' - U32.v pos )) [SMTPat (contents p h b pos pos')] inline_for_extraction val parse_empty' : parser' unit inline_for_extraction let parse_empty : parser = Parser unit parse_empty' val valid_parse_empty (h: HS.mem) (b: B.buffer u8) (pos: U32.t) (pos' : U32.t) : Lemma ( valid_pos parse_empty h b pos pos' <==> ( B.live h b /\ U32.v pos <= B.length b /\ U32.v pos' == U32.v pos )) [SMTPat (valid_pos parse_empty h b pos pos')] val size_parse_empty : squash (size parse_empty () == 0) inline_for_extraction val parse_pair' (#t1 #t2: Type) (p1: parser' t1) (p2: parser' t2) : Tot (parser' (t1 & t2)) inline_for_extraction let parse_pair (p1 p2: parser) : Tot parser = Parser (Parser?.t p1 & Parser?.t p2) (parse_pair' (Parser?.p p1) (Parser?.p p2)) val valid_parse_pair (p1 p2: parser) (h: HS.mem) (b: B.buffer U8.t) (pos1 pos2 pos3: U32.t) : Lemma (requires ( valid_pos p1 h b pos1 pos2 /\ valid_pos p2 h b pos2 pos3 )) (ensures ( valid_pos p1 h b pos1 pos2 /\ valid_pos p2 h b pos2 pos3 /\ valid_pos (p1 `parse_pair` p2) h b pos1 pos3 /\ contents (p1 `parse_pair` p2) h b pos1 pos3 == (contents p1 h b pos1 pos2, contents p2 h b pos2 pos3) )) val size_parse_pair (p1 p2: parser) (x1: Parser?.t p1) (x2: Parser?.t p2) : Lemma (size (p1 `parse_pair` p2) (x1, x2) == size p1 x1 + size p2 x2) [SMTPat (size (p1 `parse_pair` p2) (x1, x2))] val valid_ext (p: parser) (h1: HS.mem) (b1: B.buffer U8.t) (pos1: U32.t) (pos1' : U32.t) (h2: HS.mem) (b2: B.buffer U8.t) (pos2: U32.t) (pos2' : U32.t) : Lemma (requires ( valid_pos p h1 b1 pos1 pos1' /\ U32.v pos2 <= U32.v pos2' /\ U32.v pos2' <= B.length b2 /\ B.live h2 b2 /\ B.as_seq h2 (B.gsub b2 pos2 (pos2' `U32.sub` pos2)) `Seq.equal` B.as_seq h1 (B.gsub b1 pos1 (pos1' `U32.sub` pos1)) )) (ensures ( valid_pos p h1 b1 pos1 pos1' /\ valid_pos p h2 b2 pos2 pos2' /\ contents p h2 b2 pos2 pos2' == contents p h1 b1 pos1 pos1' )) let valid_frame (p: parser) (h: HS.mem) (b: B.buffer U8.t) (pos: U32.t) (pos' : U32.t) (l: B.loc) (h' : HS.mem) : Lemma (requires ( B.live h b /\ (valid_pos p h b pos pos' \/ valid_pos p h' b pos pos') /\ B.modifies l h h' /\ B.loc_disjoint l (B.loc_buffer_from_to b pos pos') )) (ensures ( valid_pos p h b pos pos' /\ valid_pos p h' b pos pos' /\ contents p h' b pos pos' == contents p h b pos pos' )) = B.loc_buffer_mgsub_eq (B.trivial_preorder _) b pos (pos' `U32.sub` pos); Classical.move_requires (valid_ext p h b pos pos' h' b pos) pos'; Classical.move_requires (valid_ext p h' b pos pos' h b pos) pos'
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowStar.Buffer.fst.checked", "FStar.UInt8.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Classical.fsti.checked" ], "interface_file": false, "source_file": "LowParseWriters.LowParse.fsti" }
[ { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": false, "full_module": "LowParseWriters", "short_module": null }, { "abbrev": false, "full_module": "LowParseWriters", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
p: LowParseWriters.LowParse.parser -> h: FStar.Monotonic.HyperStack.mem -> b: LowStar.Buffer.buffer FStar.UInt8.t -> pos0: FStar.UInt32.t -> pos1: FStar.UInt32.t -> pos2: FStar.UInt32.t -> len: FStar.UInt32.t -> FStar.Pervasives.Lemma (requires FStar.UInt32.v pos0 + FStar.UInt32.v len <= LowStar.Monotonic.Buffer.length b /\ LowParseWriters.LowParse.valid_pos p h (LowStar.Buffer.gsub b pos0 len) pos1 pos2 /\ LowStar.Monotonic.Buffer.live h b) (ensures FStar.UInt32.v pos0 + FStar.UInt32.v pos2 <= LowStar.Monotonic.Buffer.length b /\ LowParseWriters.LowParse.valid_pos p h (LowStar.Buffer.gsub b pos0 len) pos1 pos2 /\ LowParseWriters.LowParse.valid_pos p h b (FStar.UInt32.add pos0 pos1) (FStar.UInt32.add pos0 pos2) /\ LowParseWriters.LowParse.contents p h b (FStar.UInt32.add pos0 pos1) (FStar.UInt32.add pos0 pos2) == LowParseWriters.LowParse.contents p h (LowStar.Buffer.gsub b pos0 len) pos1 pos2) [SMTPat (LowParseWriters.LowParse.valid_pos p h (LowStar.Buffer.gsub b pos0 len) pos1 pos2)]
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "LowParseWriters.LowParse.parser", "FStar.Monotonic.HyperStack.mem", "LowStar.Buffer.buffer", "FStar.UInt8.t", "FStar.UInt32.t", "LowParseWriters.LowParse.valid_ext", "LowStar.Buffer.gsub", "FStar.UInt32.add", "Prims.unit", "Prims.l_and", "Prims.b2t", "Prims.op_LessThanOrEqual", "Prims.op_Addition", "FStar.UInt32.v", "LowStar.Monotonic.Buffer.length", "LowStar.Buffer.trivial_preorder", "LowParseWriters.LowParse.valid_pos", "LowStar.Monotonic.Buffer.live", "Prims.squash", "Prims.eq2", "LowParseWriters.LowParse.__proj__Parser__item__t", "LowParseWriters.LowParse.contents", "Prims.Cons", "FStar.Pervasives.pattern", "FStar.Pervasives.smt_pat", "Prims.Nil" ]
[]
true
false
true
false
false
let valid_gsub_elim (p: parser) (h: HS.mem) (b: B.buffer U8.t) (pos0 pos1 pos2 len: U32.t) : Lemma (requires (U32.v pos0 + U32.v len <= B.length b /\ valid_pos p h (B.gsub b pos0 len) pos1 pos2 /\ B.live h b)) (ensures (U32.v pos0 + U32.v pos2 <= B.length b /\ valid_pos p h (B.gsub b pos0 len) pos1 pos2 /\ valid_pos p h b (pos0 `U32.add` pos1) (pos0 `U32.add` pos2) /\ contents p h b (pos0 `U32.add` pos1) (pos0 `U32.add` pos2) == contents p h (B.gsub b pos0 len) pos1 pos2)) [SMTPat (valid_pos p h (B.gsub b pos0 len) pos1 pos2)] =
valid_ext p h (B.gsub b pos0 len) pos1 pos2 h b (pos0 `U32.add` pos1) (pos0 `U32.add` pos2)
false
Vale.AsLowStar.Test.fst
Vale.AsLowStar.Test.vm_lemma'
val vm_lemma' (code: V.va_code) (_win: bool) (dst: b64) (src: ib64) (va_s0: V.va_state) : Ghost (V.va_state & V.va_fuel) (requires vm_pre code dst src va_s0) (ensures (fun (va_s1, f) -> V.eval_code code va_s0 f va_s1 /\ VSig.vale_calling_conventions_stdcall va_s0 va_s1 /\ vm_post code dst src va_s0 va_s1 f /\ ME.buffer_readable (VS.vs_get_vale_heap va_s1) (as_vale_immbuffer src) /\ ME.buffer_readable (VS.vs_get_vale_heap va_s1) (as_vale_buffer dst) /\ ME.buffer_writeable (as_vale_buffer dst) /\ ME.modifies (ME.loc_union (ME.loc_buffer (as_vale_buffer dst)) ME.loc_none) (VS.vs_get_vale_heap va_s0) (VS.vs_get_vale_heap va_s1)))
val vm_lemma' (code: V.va_code) (_win: bool) (dst: b64) (src: ib64) (va_s0: V.va_state) : Ghost (V.va_state & V.va_fuel) (requires vm_pre code dst src va_s0) (ensures (fun (va_s1, f) -> V.eval_code code va_s0 f va_s1 /\ VSig.vale_calling_conventions_stdcall va_s0 va_s1 /\ vm_post code dst src va_s0 va_s1 f /\ ME.buffer_readable (VS.vs_get_vale_heap va_s1) (as_vale_immbuffer src) /\ ME.buffer_readable (VS.vs_get_vale_heap va_s1) (as_vale_buffer dst) /\ ME.buffer_writeable (as_vale_buffer dst) /\ ME.modifies (ME.loc_union (ME.loc_buffer (as_vale_buffer dst)) ME.loc_none) (VS.vs_get_vale_heap va_s0) (VS.vs_get_vale_heap va_s1)))
let vm_lemma' (code:V.va_code) (_win:bool) (dst:b64) (src:ib64) (va_s0:V.va_state) : Ghost (V.va_state & V.va_fuel) (requires vm_pre code dst src va_s0) (ensures (fun (va_s1, f) -> V.eval_code code va_s0 f va_s1 /\ VSig.vale_calling_conventions_stdcall va_s0 va_s1 /\ vm_post code dst src va_s0 va_s1 f /\ ME.buffer_readable (VS.vs_get_vale_heap va_s1) (as_vale_immbuffer src) /\ ME.buffer_readable (VS.vs_get_vale_heap va_s1) (as_vale_buffer dst) /\ ME.buffer_writeable (as_vale_buffer dst) /\ ME.modifies (ME.loc_union (ME.loc_buffer (as_vale_buffer dst)) ME.loc_none) (VS.vs_get_vale_heap va_s0) (VS.vs_get_vale_heap va_s1) )) = let va_s1, f = VM.va_lemma_Memcpy code va_s0 IA.win (as_vale_buffer dst) (as_vale_immbuffer src) in Vale.AsLowStar.MemoryHelpers.buffer_writeable_reveal ME.TUInt8 ME.TUInt64 dst; (va_s1, f)
{ "file_name": "vale/code/arch/x64/interop/Vale.AsLowStar.Test.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 12, "end_line": 105, "start_col": 0, "start_line": 83 }
module Vale.AsLowStar.Test open FStar.Mul open Vale.Interop.Base module ME = Vale.X64.Memory module IA = Vale.Interop.Assumptions module V = Vale.X64.Decls module IX64 = Vale.Interop.X64 module VSig = Vale.AsLowStar.ValeSig module LSig = Vale.AsLowStar.LowStarSig module W = Vale.AsLowStar.Wrapper module VS = Vale.X64.State module MS = Vale.X64.Machine_s (* A little utility to trigger normalization in types *) let as_t (#a:Type) (x:normal a) : a = x let as_normal_t (#a:Type) (x:a) : normal a = x //////////////////////////////////////////////////////////////////////////////// //First a little standalone, toy experiment [@__reduce__] let b64 = buf_t TUInt8 TUInt64 [@__reduce__] let ib64 = ibuf_t TUInt8 TUInt64 [@__reduce__] let t64_mod = TD_Buffer TUInt8 TUInt64 default_bq [@__reduce__] let t64_no_mod = TD_Buffer TUInt8 TUInt64 ({modified=false; strict_disjointness=false; taint=MS.Secret}) [@__reduce__] let t64_imm = TD_ImmBuffer TUInt8 TUInt64 ({modified=false; strict_disjointness=false; taint=MS.Secret}) [@__reduce__] let (dom : list td{List.length dom <= 20}) = let y = [t64_mod;t64_imm] in assert_norm (List.length y = 2); y assume val pre : VSig.vale_pre dom assume val post : VSig.vale_post dom assume val v: VSig.vale_sig_stdcall pre post assume val c: V.va_code [@__reduce__] let call_c_t = IX64.as_lowstar_sig_t_weak_stdcall c dom [] _ _ (W.mk_prediction c dom [] (v c IA.win)) let call_c : call_c_t = IX64.wrap_weak_stdcall c dom (W.mk_prediction c dom [] (v c IA.win)) let call_c_normal_t : normal call_c_t = as_normal_t #call_c_t call_c //You can ask emacs to show you the type of call_c_normal_t ... //////////////////////////////////////////////////////////////////////////////// //Now memcpy module VM = Vale.Test.X64.Vale_memcpy [@__reduce__] let vm_dom = [t64_mod; t64_imm] open Vale.X64.MemoryAdapters (* Need to rearrange the order of arguments *) [@__reduce__] let vm_pre : VSig.vale_pre vm_dom = fun (c:V.va_code) (dst:b64) (src:ib64) (va_s0:V.va_state) -> VM.va_req_Memcpy c va_s0 IA.win (as_vale_buffer dst) (as_vale_immbuffer src) [@__reduce__] let vm_post : VSig.vale_post vm_dom = fun (c:V.va_code) (dst:b64) (src:ib64) (va_s0:V.va_state) (va_s1:V.va_state) (f:V.va_fuel) -> VM.va_ens_Memcpy c va_s0 IA.win (as_vale_buffer dst) (as_vale_immbuffer src) va_s1 f module VS = Vale.X64.State #reset-options "--print_effect_args --z3rlimit 200" (* The vale lemma doesn't quite suffice to prove the modifies clause expected of the interop layer *)
{ "checked_file": "/", "dependencies": [ "Vale.X64.State.fsti.checked", "Vale.X64.MemoryAdapters.fsti.checked", "Vale.X64.Memory.fsti.checked", "Vale.X64.Machine_s.fst.checked", "Vale.X64.Decls.fsti.checked", "Vale.X64.CPU_Features_s.fst.checked", "Vale.Test.X64.Vale_memcpy.fsti.checked", "Vale.Test.X64.Args.fsti.checked", "Vale.Lib.X64.Cpuidstdcall.fsti.checked", "Vale.Interop.X64.fsti.checked", "Vale.Interop.Base.fst.checked", "Vale.Interop.Assumptions.fst.checked", "Vale.AsLowStar.Wrapper.fsti.checked", "Vale.AsLowStar.ValeSig.fst.checked", "Vale.AsLowStar.MemoryHelpers.fsti.checked", "Vale.AsLowStar.LowStarSig.fst.checked", "prims.fst.checked", "LowStar.Monotonic.Buffer.fsti.checked", "LowStar.ImmutableBuffer.fst.checked", "LowStar.BufferView.Up.fsti.checked", "LowStar.BufferView.Down.fsti.checked", "LowStar.Buffer.fst.checked", "FStar.UInt8.fsti.checked", "FStar.UInt64.fsti.checked", "FStar.Tactics.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.List.fst.checked", "FStar.HyperStack.ST.fsti.checked" ], "interface_file": false, "source_file": "Vale.AsLowStar.Test.fst" }
[ { "abbrev": true, "full_module": "Vale.X64.State", "short_module": "VS" }, { "abbrev": false, "full_module": "Vale.X64.MemoryAdapters", "short_module": null }, { "abbrev": true, "full_module": "Vale.Test.X64.Vale_memcpy", "short_module": "VM" }, { "abbrev": true, "full_module": "Vale.X64.Machine_s", "short_module": "MS" }, { "abbrev": true, "full_module": "Vale.X64.State", "short_module": "VS" }, { "abbrev": true, "full_module": "Vale.AsLowStar.Wrapper", "short_module": "W" }, { "abbrev": true, "full_module": "Vale.AsLowStar.LowStarSig", "short_module": "LSig" }, { "abbrev": true, "full_module": "Vale.AsLowStar.ValeSig", "short_module": "VSig" }, { "abbrev": true, "full_module": "Vale.Interop.X64", "short_module": "IX64" }, { "abbrev": true, "full_module": "Vale.X64.Decls", "short_module": "V" }, { "abbrev": true, "full_module": "Vale.Interop.Assumptions", "short_module": "IA" }, { "abbrev": true, "full_module": "Vale.X64.Memory", "short_module": "ME" }, { "abbrev": false, "full_module": "Vale.Interop.Base", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.AsLowStar", "short_module": null }, { "abbrev": false, "full_module": "Vale.AsLowStar", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 0, "max_fuel": 1, "max_ifuel": 1, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": true, "smtencoding_l_arith_repr": "native", "smtencoding_nl_arith_repr": "wrapped", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [ "smt.arith.nl=false", "smt.QI.EAGER_THRESHOLD=100", "smt.CASE_SPLIT=3" ], "z3refresh": false, "z3rlimit": 200, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
code: Vale.X64.Decls.va_code -> _win: Prims.bool -> dst: Vale.AsLowStar.Test.b64 -> src: Vale.AsLowStar.Test.ib64 -> va_s0: Vale.X64.Decls.va_state -> Prims.Ghost (Vale.X64.Decls.va_state * Vale.X64.Decls.va_fuel)
Prims.Ghost
[]
[]
[ "Vale.X64.Decls.va_code", "Prims.bool", "Vale.AsLowStar.Test.b64", "Vale.AsLowStar.Test.ib64", "Vale.X64.Decls.va_state", "Vale.X64.Decls.va_fuel", "FStar.Pervasives.Native.Mktuple2", "Prims.unit", "Vale.AsLowStar.MemoryHelpers.buffer_writeable_reveal", "Vale.Arch.HeapTypes_s.TUInt8", "Vale.Arch.HeapTypes_s.TUInt64", "FStar.Pervasives.Native.tuple2", "Vale.X64.State.vale_state", "Vale.Test.X64.Vale_memcpy.va_lemma_Memcpy", "Vale.Interop.Assumptions.win", "Vale.X64.MemoryAdapters.as_vale_buffer", "Vale.X64.MemoryAdapters.as_vale_immbuffer", "Vale.AsLowStar.Test.vm_pre", "Prims.l_and", "Vale.X64.Decls.eval_code", "Vale.AsLowStar.ValeSig.vale_calling_conventions_stdcall", "Vale.AsLowStar.Test.vm_post", "Vale.X64.Memory.buffer_readable", "Vale.X64.State.vs_get_vale_heap", "Vale.X64.Memory.buffer_writeable", "Vale.X64.Memory.modifies", "Vale.X64.Memory.loc_union", "Vale.X64.Memory.loc_buffer", "Vale.X64.Memory.loc_none" ]
[]
false
false
false
false
false
let vm_lemma' (code: V.va_code) (_win: bool) (dst: b64) (src: ib64) (va_s0: V.va_state) : Ghost (V.va_state & V.va_fuel) (requires vm_pre code dst src va_s0) (ensures (fun (va_s1, f) -> V.eval_code code va_s0 f va_s1 /\ VSig.vale_calling_conventions_stdcall va_s0 va_s1 /\ vm_post code dst src va_s0 va_s1 f /\ ME.buffer_readable (VS.vs_get_vale_heap va_s1) (as_vale_immbuffer src) /\ ME.buffer_readable (VS.vs_get_vale_heap va_s1) (as_vale_buffer dst) /\ ME.buffer_writeable (as_vale_buffer dst) /\ ME.modifies (ME.loc_union (ME.loc_buffer (as_vale_buffer dst)) ME.loc_none) (VS.vs_get_vale_heap va_s0) (VS.vs_get_vale_heap va_s1))) =
let va_s1, f = VM.va_lemma_Memcpy code va_s0 IA.win (as_vale_buffer dst) (as_vale_immbuffer src) in Vale.AsLowStar.MemoryHelpers.buffer_writeable_reveal ME.TUInt8 ME.TUInt64 dst; (va_s1, f)
false
Vale.AsLowStar.Test.fst
Vale.AsLowStar.Test.lowstar_ta_normal_t
val lowstar_ta_normal_t : Vale.Interop.Base.normal Vale.AsLowStar.Test.lowstar_ta_t
let lowstar_ta_normal_t //: normal lowstar_ta_t = as_normal_t #lowstar_ta_t lowstar_ta
{ "file_name": "vale/code/arch/x64/interop/Vale.AsLowStar.Test.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 40, "end_line": 396, "start_col": 0, "start_line": 395 }
module Vale.AsLowStar.Test open FStar.Mul open Vale.Interop.Base module ME = Vale.X64.Memory module IA = Vale.Interop.Assumptions module V = Vale.X64.Decls module IX64 = Vale.Interop.X64 module VSig = Vale.AsLowStar.ValeSig module LSig = Vale.AsLowStar.LowStarSig module W = Vale.AsLowStar.Wrapper module VS = Vale.X64.State module MS = Vale.X64.Machine_s (* A little utility to trigger normalization in types *) let as_t (#a:Type) (x:normal a) : a = x let as_normal_t (#a:Type) (x:a) : normal a = x //////////////////////////////////////////////////////////////////////////////// //First a little standalone, toy experiment [@__reduce__] let b64 = buf_t TUInt8 TUInt64 [@__reduce__] let ib64 = ibuf_t TUInt8 TUInt64 [@__reduce__] let t64_mod = TD_Buffer TUInt8 TUInt64 default_bq [@__reduce__] let t64_no_mod = TD_Buffer TUInt8 TUInt64 ({modified=false; strict_disjointness=false; taint=MS.Secret}) [@__reduce__] let t64_imm = TD_ImmBuffer TUInt8 TUInt64 ({modified=false; strict_disjointness=false; taint=MS.Secret}) [@__reduce__] let (dom : list td{List.length dom <= 20}) = let y = [t64_mod;t64_imm] in assert_norm (List.length y = 2); y assume val pre : VSig.vale_pre dom assume val post : VSig.vale_post dom assume val v: VSig.vale_sig_stdcall pre post assume val c: V.va_code [@__reduce__] let call_c_t = IX64.as_lowstar_sig_t_weak_stdcall c dom [] _ _ (W.mk_prediction c dom [] (v c IA.win)) let call_c : call_c_t = IX64.wrap_weak_stdcall c dom (W.mk_prediction c dom [] (v c IA.win)) let call_c_normal_t : normal call_c_t = as_normal_t #call_c_t call_c //You can ask emacs to show you the type of call_c_normal_t ... //////////////////////////////////////////////////////////////////////////////// //Now memcpy module VM = Vale.Test.X64.Vale_memcpy [@__reduce__] let vm_dom = [t64_mod; t64_imm] open Vale.X64.MemoryAdapters (* Need to rearrange the order of arguments *) [@__reduce__] let vm_pre : VSig.vale_pre vm_dom = fun (c:V.va_code) (dst:b64) (src:ib64) (va_s0:V.va_state) -> VM.va_req_Memcpy c va_s0 IA.win (as_vale_buffer dst) (as_vale_immbuffer src) [@__reduce__] let vm_post : VSig.vale_post vm_dom = fun (c:V.va_code) (dst:b64) (src:ib64) (va_s0:V.va_state) (va_s1:V.va_state) (f:V.va_fuel) -> VM.va_ens_Memcpy c va_s0 IA.win (as_vale_buffer dst) (as_vale_immbuffer src) va_s1 f module VS = Vale.X64.State #reset-options "--print_effect_args --z3rlimit 200" (* The vale lemma doesn't quite suffice to prove the modifies clause expected of the interop layer *) [@__reduce__] let vm_lemma' (code:V.va_code) (_win:bool) (dst:b64) (src:ib64) (va_s0:V.va_state) : Ghost (V.va_state & V.va_fuel) (requires vm_pre code dst src va_s0) (ensures (fun (va_s1, f) -> V.eval_code code va_s0 f va_s1 /\ VSig.vale_calling_conventions_stdcall va_s0 va_s1 /\ vm_post code dst src va_s0 va_s1 f /\ ME.buffer_readable (VS.vs_get_vale_heap va_s1) (as_vale_immbuffer src) /\ ME.buffer_readable (VS.vs_get_vale_heap va_s1) (as_vale_buffer dst) /\ ME.buffer_writeable (as_vale_buffer dst) /\ ME.modifies (ME.loc_union (ME.loc_buffer (as_vale_buffer dst)) ME.loc_none) (VS.vs_get_vale_heap va_s0) (VS.vs_get_vale_heap va_s1) )) = let va_s1, f = VM.va_lemma_Memcpy code va_s0 IA.win (as_vale_buffer dst) (as_vale_immbuffer src) in Vale.AsLowStar.MemoryHelpers.buffer_writeable_reveal ME.TUInt8 ME.TUInt64 dst; (va_s1, f) (* Prove that vm_lemma' has the required type *) let vm_lemma = as_t #(VSig.vale_sig_stdcall vm_pre vm_post) vm_lemma' let code_Memcpy = VM.va_code_Memcpy IA.win (* Here's the type expected for the memcpy wrapper *) [@__reduce__] let lowstar_Memcpy_t = IX64.as_lowstar_sig_t_weak_stdcall code_Memcpy vm_dom [] _ _ (W.mk_prediction code_Memcpy vm_dom [] (vm_lemma code_Memcpy IA.win)) (* And here's the memcpy wrapper itself *) let lowstar_Memcpy : lowstar_Memcpy_t = IX64.wrap_weak_stdcall code_Memcpy vm_dom (W.mk_prediction code_Memcpy vm_dom [] (vm_lemma code_Memcpy IA.win)) let lowstar_Memcpy_normal_t //: normal lowstar_Memcpy_t = as_normal_t #lowstar_Memcpy_t lowstar_Memcpy module B = LowStar.Buffer module IB = LowStar.ImmutableBuffer module MB = LowStar.Monotonic.Buffer open FStar.HyperStack.ST module M = Vale.X64.Memory let test (x:b64) = assert (V.buffer_length (as_vale_buffer x) == (B.length x * view_n TUInt8) / view_n TUInt64); assert (V.buffer_length (as_vale_buffer x) == B.length x / 8) let itest (x:ib64) = assert (V.buffer_length (as_vale_immbuffer x) == (B.length x * view_n TUInt8) / view_n TUInt64); assert (V.buffer_length (as_vale_immbuffer x) == B.length x / 8) module T = FStar.Tactics #reset-options "--using_facts_from '* -FStar.Tactics -FStar.Reflection'" module LBV = LowStar.BufferView.Up module DV = LowStar.BufferView.Down #push-options "--ext compat:normalizer_memo_ignore_cfg" let memcpy_Test (dst:B.buffer UInt8.t{B.length dst % 8 == 0}) (src:IB.ibuffer UInt8.t{B.length src % 8 == 0}) : Stack UInt64.t (requires fun h0 -> B.live h0 dst /\ B.live h0 src /\ B.disjoint dst src /\ B.length dst == 16 /\ B.length src == 16) (ensures fun h0 _ h1 -> B.modifies (B.loc_buffer dst) h0 h1 /\ B.live h1 src /\ B.live h1 dst) // B.as_seq h1 dst == B.as_seq h1 src) // by (T.dump "A") (* in case you want to look at the VC *) = IB.inhabited_immutable_buffer_is_distinct_from_buffer (UInt8.uint_to_t 0) src dst; let (x, _) = lowstar_Memcpy_normal_t dst src () in //This is a call to the interop wrapper let h1 = get () in // let v = Vale.Interop.Views.up_view64 in // assert (DV.length_eq (get_downview dst); // DV.length_eq (get_downview src); // Seq.equal (LBV.as_seq h1 (LBV.mk_buffer (get_downview dst) v)) // (LBV.as_seq h1 (LBV.mk_buffer (get_downview src) v))); // lbv_as_seq_eq dst src Vale.Interop.Views.up_view64 h1; //And a lemma to rephrase the Vale postcondition x //with equalities of buffer views //back to equalities of buffers #pop-options module VC = Vale.Lib.X64.Cpuidstdcall [@__reduce__] let empty_list #a : l:list a {List.length l = 0} = [] [@__reduce__] let aesni_dom : IX64.arity_ok_stdcall td = [] (* Need to rearrange the order of arguments *) [@__reduce__] let aesni_pre : VSig.vale_pre aesni_dom = fun (c:V.va_code) (va_s0:V.va_state) -> VC.va_req_Check_aesni_stdcall c va_s0 IA.win [@__reduce__] let aesni_post : VSig.vale_post aesni_dom = fun (c:V.va_code) (va_s0:V.va_state) (va_s1:V.va_state) (f:V.va_fuel) -> VC.va_ens_Check_aesni_stdcall c va_s0 IA.win va_s1 f [@__reduce__] let with_len (l:list 'a) : Pure (list 'a) (requires True) (ensures fun m -> m==l /\ List.length m == normalize_term (List.length l)) = l #set-options "--max_fuel 0 --max_ifuel 1 --z3rlimit_factor 2" (* The vale lemma doesn't quite suffice to prove the modifies clause expected of the interop layer *) [@__reduce__] let aesni_lemma' (code:V.va_code) (_win:bool) (va_s0:V.va_state) : Ghost (V.va_state & V.va_fuel) (requires aesni_pre code va_s0) (ensures (fun (va_s1, f) -> V.eval_code code va_s0 f va_s1 /\ VSig.vale_calling_conventions_stdcall va_s0 va_s1 /\ aesni_post code va_s0 va_s1 f)) = VC.va_lemma_Check_aesni_stdcall code va_s0 IA.win #set-options "--max_fuel 0 --max_ifuel 0 --z3rlimit_factor 2" (* Prove that vm_lemma' has the required type *) let aesni_lemma = as_t #(VSig.vale_sig_stdcall aesni_pre aesni_post) aesni_lemma' let code_aesni = VC.va_code_Check_aesni_stdcall IA.win (* Here's the type expected for the check_aesni wrapper *) [@__reduce__] let lowstar_aesni_t = IX64.as_lowstar_sig_t_weak_stdcall (coerce code_aesni) aesni_dom empty_list _ _ (W.mk_prediction code_aesni aesni_dom [] (aesni_lemma code_aesni IA.win)) (* And here's the check_aesni wrapper itself *) let lowstar_aesni : lowstar_aesni_t = IX64.wrap_weak_stdcall (coerce code_aesni) aesni_dom (W.mk_prediction code_aesni aesni_dom [] (aesni_lemma code_aesni IA.win)) let lowstar_aesni_normal_t //: normal lowstar_aesni_t = as_normal_t #lowstar_aesni_t lowstar_aesni open Vale.X64.CPU_Features_s #set-options "--print_full_names" let aesni_Test () : Stack UInt64.t (requires fun h0 -> True) (ensures fun h0 ret_val h1 -> (UInt64.v ret_val) =!= 0 ==> aesni_enabled /\ pclmulqdq_enabled) // by (T.dump "A") (* in case you want to look at the VC *) = let (x, _) = lowstar_aesni_normal_t () in //This is a call to the interop wrapper x module TA = Vale.Test.X64.Args [@__reduce__] let (ta_dom:list td{List.length ta_dom <= 20}) = let y = [t64_imm; t64_imm; t64_imm; t64_imm; t64_imm; t64_imm; t64_imm; t64_imm] in assert_norm (List.length y = 8); y (* Need to rearrange the order of arguments *) [@__reduce__] let ta_pre : VSig.vale_pre ta_dom = fun (c:V.va_code) (arg0:ib64) (arg1:ib64) (arg2:ib64) (arg3:ib64) (arg4:ib64) (arg5:ib64) (arg6:ib64) (arg7:ib64) (va_s0:V.va_state) -> TA.va_req_Test c va_s0 IA.win (as_vale_immbuffer arg0) (as_vale_immbuffer arg1) (as_vale_immbuffer arg2) (as_vale_immbuffer arg3) (as_vale_immbuffer arg4) (as_vale_immbuffer arg5) (as_vale_immbuffer arg6) (as_vale_immbuffer arg7) [@__reduce__] let ta_post : VSig.vale_post ta_dom = fun (c:V.va_code) (arg0:ib64) (arg1:ib64) (arg2:ib64) (arg3:ib64) (arg4:ib64) (arg5:ib64) (arg6:ib64) (arg7:ib64) (va_s0:V.va_state) (va_s1:V.va_state) (f:V.va_fuel) -> TA.va_ens_Test c va_s0 IA.win (as_vale_immbuffer arg0) (as_vale_immbuffer arg1) (as_vale_immbuffer arg2) (as_vale_immbuffer arg3) (as_vale_immbuffer arg4) (as_vale_immbuffer arg5) (as_vale_immbuffer arg6) (as_vale_immbuffer arg7) va_s1 f #reset-options "--max_fuel 0 --max_ifuel 0 --z3rlimit 100" (* The vale lemma doesn't quite suffice to prove the modifies clause expected of the interop layer *) [@__reduce__] let ta_lemma' (code:V.va_code) (_win:bool) (arg0:ib64) (arg1:ib64) (arg2:ib64) (arg3:ib64) (arg4:ib64) (arg5:ib64) (arg6:ib64) (arg7:ib64) (va_s0:V.va_state) : Ghost (V.va_state & V.va_fuel) (requires ta_pre code arg0 arg1 arg2 arg3 arg4 arg5 arg6 arg7 va_s0) (ensures (fun (va_s1, f) -> V.eval_code code va_s0 f va_s1 /\ VSig.vale_calling_conventions_stdcall va_s0 va_s1 /\ ta_post code arg0 arg1 arg2 arg3 arg4 arg5 arg6 arg7 va_s0 va_s1 f /\ ME.buffer_readable (VS.vs_get_vale_heap va_s1) (as_vale_immbuffer arg0) /\ ME.buffer_readable (VS.vs_get_vale_heap va_s1) (as_vale_immbuffer arg1) /\ ME.buffer_readable (VS.vs_get_vale_heap va_s1) (as_vale_immbuffer arg2) /\ ME.buffer_readable (VS.vs_get_vale_heap va_s1) (as_vale_immbuffer arg3) /\ ME.buffer_readable (VS.vs_get_vale_heap va_s1) (as_vale_immbuffer arg4) /\ ME.buffer_readable (VS.vs_get_vale_heap va_s1) (as_vale_immbuffer arg5) /\ ME.buffer_readable (VS.vs_get_vale_heap va_s1) (as_vale_immbuffer arg6) /\ ME.buffer_readable (VS.vs_get_vale_heap va_s1) (as_vale_immbuffer arg7) /\ ME.modifies ME.loc_none (VS.vs_get_vale_heap va_s0) (VS.vs_get_vale_heap va_s1))) = let va_s1, f = TA.va_lemma_Test code va_s0 IA.win (as_vale_immbuffer arg0) (as_vale_immbuffer arg1) (as_vale_immbuffer arg2) (as_vale_immbuffer arg3) (as_vale_immbuffer arg4) (as_vale_immbuffer arg5) (as_vale_immbuffer arg6) (as_vale_immbuffer arg7) in va_s1, f (* Prove that vm_lemma' has the required type *) let ta_lemma = as_t #(VSig.vale_sig_stdcall ta_pre ta_post) ta_lemma' let code_ta = TA.va_code_Test IA.win (* Here's the type expected for the check_aesni wrapper *) [@__reduce__] let lowstar_ta_t = IX64.as_lowstar_sig_t_weak_stdcall (coerce code_ta) ta_dom [] _ _ (W.mk_prediction code_ta ta_dom [] (ta_lemma code_ta IA.win)) (* And here's the check_aesni wrapper itself *) let lowstar_ta : lowstar_ta_t = IX64.wrap_weak_stdcall (coerce code_ta) ta_dom (W.mk_prediction code_ta ta_dom [] (ta_lemma code_ta IA.win))
{ "checked_file": "/", "dependencies": [ "Vale.X64.State.fsti.checked", "Vale.X64.MemoryAdapters.fsti.checked", "Vale.X64.Memory.fsti.checked", "Vale.X64.Machine_s.fst.checked", "Vale.X64.Decls.fsti.checked", "Vale.X64.CPU_Features_s.fst.checked", "Vale.Test.X64.Vale_memcpy.fsti.checked", "Vale.Test.X64.Args.fsti.checked", "Vale.Lib.X64.Cpuidstdcall.fsti.checked", "Vale.Interop.X64.fsti.checked", "Vale.Interop.Base.fst.checked", "Vale.Interop.Assumptions.fst.checked", "Vale.AsLowStar.Wrapper.fsti.checked", "Vale.AsLowStar.ValeSig.fst.checked", "Vale.AsLowStar.MemoryHelpers.fsti.checked", "Vale.AsLowStar.LowStarSig.fst.checked", "prims.fst.checked", "LowStar.Monotonic.Buffer.fsti.checked", "LowStar.ImmutableBuffer.fst.checked", "LowStar.BufferView.Up.fsti.checked", "LowStar.BufferView.Down.fsti.checked", "LowStar.Buffer.fst.checked", "FStar.UInt8.fsti.checked", "FStar.UInt64.fsti.checked", "FStar.Tactics.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.List.fst.checked", "FStar.HyperStack.ST.fsti.checked" ], "interface_file": false, "source_file": "Vale.AsLowStar.Test.fst" }
[ { "abbrev": true, "full_module": "Vale.Test.X64.Args", "short_module": "TA" }, { "abbrev": false, "full_module": "Vale.X64.CPU_Features_s", "short_module": null }, { "abbrev": true, "full_module": "Vale.Lib.X64.Cpuidstdcall", "short_module": "VC" }, { "abbrev": true, "full_module": "LowStar.BufferView.Down", "short_module": "DV" }, { "abbrev": true, "full_module": "LowStar.BufferView.Up", "short_module": "LBV" }, { "abbrev": true, "full_module": "FStar.Tactics", "short_module": "T" }, { "abbrev": true, "full_module": "Vale.X64.Memory", "short_module": "M" }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": true, "full_module": "LowStar.Monotonic.Buffer", "short_module": "MB" }, { "abbrev": true, "full_module": "LowStar.ImmutableBuffer", "short_module": "IB" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "Vale.X64.State", "short_module": "VS" }, { "abbrev": false, "full_module": "Vale.X64.MemoryAdapters", "short_module": null }, { "abbrev": true, "full_module": "Vale.Test.X64.Vale_memcpy", "short_module": "VM" }, { "abbrev": true, "full_module": "Vale.X64.Machine_s", "short_module": "MS" }, { "abbrev": true, "full_module": "Vale.X64.State", "short_module": "VS" }, { "abbrev": true, "full_module": "Vale.AsLowStar.Wrapper", "short_module": "W" }, { "abbrev": true, "full_module": "Vale.AsLowStar.LowStarSig", "short_module": "LSig" }, { "abbrev": true, "full_module": "Vale.AsLowStar.ValeSig", "short_module": "VSig" }, { "abbrev": true, "full_module": "Vale.Interop.X64", "short_module": "IX64" }, { "abbrev": true, "full_module": "Vale.X64.Decls", "short_module": "V" }, { "abbrev": true, "full_module": "Vale.Interop.Assumptions", "short_module": "IA" }, { "abbrev": true, "full_module": "Vale.X64.Memory", "short_module": "ME" }, { "abbrev": false, "full_module": "Vale.Interop.Base", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.AsLowStar", "short_module": null }, { "abbrev": false, "full_module": "Vale.AsLowStar", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 0, "max_fuel": 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": 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" }
false
Vale.Interop.Base.normal Vale.AsLowStar.Test.lowstar_ta_t
Prims.Tot
[ "total" ]
[]
[ "Vale.AsLowStar.Test.as_normal_t", "Vale.AsLowStar.Test.lowstar_ta_t", "Vale.AsLowStar.Test.lowstar_ta" ]
[]
false
false
false
true
false
let lowstar_ta_normal_t =
as_normal_t #lowstar_ta_t lowstar_ta
false
Hacl.Spec.Bignum.MontArithmetic.fst
Hacl.Spec.Bignum.MontArithmetic.bn_field_sqr
val bn_field_sqr: #t:limb_t -> k:bn_mont_ctx t{bn_mont_ctx_inv k} -> aM:bn_mont_nat k -> Pure (bn_mont_nat k) (requires True) (ensures fun cM -> bn_v (bn_from_field k cM) == bn_v (bn_from_field k aM) * bn_v (bn_from_field k aM) % bn_v k.n)
val bn_field_sqr: #t:limb_t -> k:bn_mont_ctx t{bn_mont_ctx_inv k} -> aM:bn_mont_nat k -> Pure (bn_mont_nat k) (requires True) (ensures fun cM -> bn_v (bn_from_field k cM) == bn_v (bn_from_field k aM) * bn_v (bn_from_field k aM) % bn_v k.n)
let bn_field_sqr #t k aM = BM.bn_mont_sqr_lemma k.n k.mu aM; M.from_mont_mul_lemma (bits t) k.len (bn_v k.n) (v k.mu) (bn_v aM) (bn_v aM); BM.bn_mont_sqr k.n k.mu aM
{ "file_name": "code/bignum/Hacl.Spec.Bignum.MontArithmetic.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 28, "end_line": 146, "start_col": 0, "start_line": 143 }
module Hacl.Spec.Bignum.MontArithmetic open FStar.Mul open Lib.IntTypes open Lib.Sequence open Hacl.Spec.Bignum.Definitions module M = Hacl.Spec.Montgomery.Lemmas module BM = Hacl.Spec.Bignum.Montgomery module BN = Hacl.Spec.Bignum module BB = Hacl.Spec.Bignum.Base module BL = Hacl.Spec.Bignum.Lib module BIL = Hacl.Spec.Bignum.ModInvLimb module E = Hacl.Spec.Exponentiation.Lemmas module ME = Hacl.Spec.Bignum.MontExponentiation module Euclid = FStar.Math.Euclid module BI = Hacl.Spec.Bignum.ModInv #set-options "--z3rlimit 50 --fuel 0 --ifuel 0" ////////////////////////////////////////// val mul_zero_lemma: n:pos{Euclid.is_prime n} -> x:int -> y:int -> Lemma (x * y % n == 0 <==> (x % n == 0 \/ y % n == 0)) let mul_zero_lemma n x y = assert (0 % n = 0); if x % n = 0 then Math.Lemmas.lemma_mod_mul_distr_l x y n else if y % n = 0 then Math.Lemmas.lemma_mod_mul_distr_r x y n else if x * y % n = 0 then Math.Fermat.mod_mult_congr n x 0 y else () val mul_nonzero_lemma: n:pos{Euclid.is_prime n} -> x:int -> y:int -> Lemma (requires x % n <> 0 /\ y % n <> 0) (ensures x * y % n <> 0) let mul_nonzero_lemma n x y = mul_zero_lemma n x y val from_mont_lemma_nonzero: pbits:pos -> rLen:pos -> n:pos -> mu:nat -> aM:nat -> Lemma (requires M.mont_pre pbits rLen n mu /\ 0 < aM /\ aM < n /\ Euclid.is_prime n) (ensures (let a = M.from_mont pbits rLen n mu aM in 0 < a /\ a < n)) let from_mont_lemma_nonzero pbits rLen n mu aM = let r = pow2 (pbits * rLen) in let d, _ = M.eea_pow2_odd (pbits * rLen) n in let a = M.from_mont pbits rLen n mu aM in M.from_mont_lemma pbits rLen n mu aM; assert (a == aM * d % n); assert (d <> 0); Math.Lemmas.small_mod aM n; assert (aM % n <> 0); let d1 = -d in assert (0 < d1 /\ d1 < n); Math.Lemmas.lemma_mod_sub_1 d1 n; assert ((-d1) % n == n - (d1 % n)); assert (d % n <> 0); mul_nonzero_lemma n aM d; assert (let a = M.from_mont pbits rLen n mu aM in 0 < a /\ a < n); // For some reason, this makes the proof instant. () /////////////////////////////////////////////// let bn_field_get_len #t k = k.len let bn_field_check_modulus #t #len n = let m = BM.bn_check_modulus n in BB.unsafe_bool_of_limb m let bn_field_init #t #len n = let nBits = bits t * BL.bn_get_top_index n in BL.bn_low_bound_bits_lemma n; BM.bn_precomp_r2_mod_n_lemma nBits n; let r2 = BM.bn_precomp_r2_mod_n nBits n in assert (bn_v r2 == pow2 (2 * bits t * len) % bn_v n); let mu = BIL.mod_inv_limb n.[0] in BIL.bn_mod_inv_limb_lemma n; assert ((1 + bn_v n * v mu) % pow2 (bits t) == 0); bn_eval_bound n len; { len = len; n = n; mu = mu; r2 = r2 } let bn_to_field #t k a = BM.bn_to_mont_lemma k.n k.mu k.r2 a; BM.bn_to_mont k.n k.mu k.r2 a let bn_from_field #t k aM = BM.bn_from_mont_lemma k.n k.mu aM; BM.bn_from_mont k.n k.mu aM let bn_from_to_field_lemma #t k a = bn_eval_bound a k.len; M.from_to_mont_lemma (bits t) k.len (bn_v k.n) (v k.mu) (bn_v a) let bn_field_add #t k aM bM = BN.bn_add_mod_n_lemma k.n aM bM; M.from_mont_add_lemma (bits t) k.len (bn_v k.n) (v k.mu) (bn_v aM) (bn_v bM); BN.bn_add_mod_n k.n aM bM let bn_field_sub #t k aM bM = BN.bn_sub_mod_n_lemma k.n aM bM; M.from_mont_sub_lemma (bits t) k.len (bn_v k.n) (v k.mu) (bn_v aM) (bn_v bM); BN.bn_sub_mod_n k.n aM bM let bn_field_mul #t k aM bM = BM.bn_mont_mul_lemma k.n k.mu aM bM; M.from_mont_mul_lemma (bits t) k.len (bn_v k.n) (v k.mu) (bn_v aM) (bn_v bM); BM.bn_mont_mul k.n k.mu aM bM
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "Lib.Sequence.fsti.checked", "Lib.NatMod.fsti.checked", "Lib.IntTypes.fsti.checked", "Hacl.Spec.Montgomery.Lemmas.fst.checked", "Hacl.Spec.Exponentiation.Lemmas.fst.checked", "Hacl.Spec.Bignum.Montgomery.fsti.checked", "Hacl.Spec.Bignum.MontExponentiation.fst.checked", "Hacl.Spec.Bignum.ModInvLimb.fsti.checked", "Hacl.Spec.Bignum.ModInv.fst.checked", "Hacl.Spec.Bignum.Lib.fst.checked", "Hacl.Spec.Bignum.Definitions.fst.checked", "Hacl.Spec.Bignum.Base.fst.checked", "Hacl.Spec.Bignum.fsti.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.Math.Fermat.fsti.checked", "FStar.Math.Euclid.fsti.checked" ], "interface_file": true, "source_file": "Hacl.Spec.Bignum.MontArithmetic.fst" }
[ { "abbrev": true, "full_module": "Hacl.Spec.Bignum.ModInv", "short_module": "BI" }, { "abbrev": true, "full_module": "Hacl.Spec.Bignum.MontExponentiation", "short_module": "ME" }, { "abbrev": true, "full_module": "Hacl.Spec.Exponentiation.Lemmas", "short_module": "E" }, { "abbrev": true, "full_module": "Hacl.Spec.Bignum.ModInvLimb", "short_module": "BIL" }, { "abbrev": true, "full_module": "Hacl.Spec.Bignum.Lib", "short_module": "BL" }, { "abbrev": true, "full_module": "Hacl.Spec.Bignum.Base", "short_module": "BB" }, { "abbrev": true, "full_module": "Hacl.Spec.Bignum.Montgomery", "short_module": "BM" }, { "abbrev": true, "full_module": "Hacl.Spec.Bignum", "short_module": "BN" }, { "abbrev": true, "full_module": "Hacl.Spec.Montgomery.Lemmas", "short_module": "M" }, { "abbrev": true, "full_module": "FStar.Math.Euclid", "short_module": "Euclid" }, { "abbrev": false, "full_module": "Hacl.Spec.Bignum.Definitions", "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.Bignum", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.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 } ]
{ "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" }
false
k: Hacl.Spec.Bignum.MontArithmetic.bn_mont_ctx t {Hacl.Spec.Bignum.MontArithmetic.bn_mont_ctx_inv k} -> aM: Hacl.Spec.Bignum.MontArithmetic.bn_mont_nat k -> Prims.Pure (Hacl.Spec.Bignum.MontArithmetic.bn_mont_nat k)
Prims.Pure
[]
[]
[ "Hacl.Spec.Bignum.Definitions.limb_t", "Hacl.Spec.Bignum.MontArithmetic.bn_mont_ctx", "Hacl.Spec.Bignum.MontArithmetic.bn_mont_ctx_inv", "Hacl.Spec.Bignum.MontArithmetic.bn_mont_nat", "Hacl.Spec.Bignum.Montgomery.bn_mont_sqr", "Hacl.Spec.Bignum.MontArithmetic.__proj__Mkbn_mont_ctx__item__len", "Hacl.Spec.Bignum.MontArithmetic.__proj__Mkbn_mont_ctx__item__n", "Hacl.Spec.Bignum.MontArithmetic.__proj__Mkbn_mont_ctx__item__mu", "Prims.unit", "Hacl.Spec.Montgomery.Lemmas.from_mont_mul_lemma", "Lib.IntTypes.bits", "Hacl.Spec.Bignum.Definitions.bn_v", "Lib.IntTypes.v", "Lib.IntTypes.SEC", "Hacl.Spec.Bignum.Montgomery.bn_mont_sqr_lemma" ]
[]
false
false
false
false
false
let bn_field_sqr #t k aM =
BM.bn_mont_sqr_lemma k.n k.mu aM; M.from_mont_mul_lemma (bits t) k.len (bn_v k.n) (v k.mu) (bn_v aM) (bn_v aM); BM.bn_mont_sqr k.n k.mu aM
false
LowParseWriters.LowParse.fsti
LowParseWriters.LowParse.buffer_contents
val buffer_contents (p: parser) (h: HS.mem) (b: B.buffer U8.t) : Ghost (Parser?.t p) (requires (valid_buffer p h b)) (ensures (fun _ -> True))
val buffer_contents (p: parser) (h: HS.mem) (b: B.buffer U8.t) : Ghost (Parser?.t p) (requires (valid_buffer p h b)) (ensures (fun _ -> True))
let buffer_contents (p: parser) (h: HS.mem) (b: B.buffer U8.t) : Ghost (Parser?.t p) (requires (valid_buffer p h b)) (ensures (fun _ -> True)) = contents p h b 0ul (B.len b)
{ "file_name": "examples/layeredeffects/LowParseWriters.LowParse.fsti", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 30, "end_line": 288, "start_col": 0, "start_line": 281 }
module LowParseWriters.LowParse module HS = FStar.HyperStack module B = LowStar.Buffer module U8 = FStar.UInt8 module U32 = FStar.UInt32 module HST = FStar.HyperStack.ST type u8 : Type0 = U8.t val parser' (t: Type0) : Type u#1 inline_for_extraction noextract noeq type parser = | Parser: t: Type -> p: parser' t -> parser val valid_pos (p: parser) (h: HS.mem) (b: B.buffer U8.t) (pos: U32.t) (pos' : U32.t) : GTot Type0 val valid_pos_post (p: parser) (h: HS.mem) (b: B.buffer U8.t) (pos: U32.t) (pos' : U32.t) : Lemma (requires (valid_pos p h b pos pos')) (ensures ( B.live h b /\ U32.v pos <= U32.v pos' /\ U32.v pos' <= B.length b )) [SMTPat (valid_pos p h b pos pos')] val contents (p: parser) (h: HS.mem) (b: B.buffer U8.t) (pos: U32.t) (pos' : U32.t) : Ghost (Parser?.t p) (requires (valid_pos p h b pos pos')) (ensures (fun _ -> True)) val size (p: parser) (x: Parser?.t p) : GTot nat val contents_size (p: parser) (h: HS.mem) (b: B.buffer U8.t) (pos: U32.t) (pos' : U32.t) : Lemma (requires (valid_pos p h b pos pos')) (ensures ( valid_pos p h b pos pos' /\ size p (contents p h b pos pos') == U32.v pos' - U32.v pos )) [SMTPat (contents p h b pos pos')] inline_for_extraction val parse_empty' : parser' unit inline_for_extraction let parse_empty : parser = Parser unit parse_empty' val valid_parse_empty (h: HS.mem) (b: B.buffer u8) (pos: U32.t) (pos' : U32.t) : Lemma ( valid_pos parse_empty h b pos pos' <==> ( B.live h b /\ U32.v pos <= B.length b /\ U32.v pos' == U32.v pos )) [SMTPat (valid_pos parse_empty h b pos pos')] val size_parse_empty : squash (size parse_empty () == 0) inline_for_extraction val parse_pair' (#t1 #t2: Type) (p1: parser' t1) (p2: parser' t2) : Tot (parser' (t1 & t2)) inline_for_extraction let parse_pair (p1 p2: parser) : Tot parser = Parser (Parser?.t p1 & Parser?.t p2) (parse_pair' (Parser?.p p1) (Parser?.p p2)) val valid_parse_pair (p1 p2: parser) (h: HS.mem) (b: B.buffer U8.t) (pos1 pos2 pos3: U32.t) : Lemma (requires ( valid_pos p1 h b pos1 pos2 /\ valid_pos p2 h b pos2 pos3 )) (ensures ( valid_pos p1 h b pos1 pos2 /\ valid_pos p2 h b pos2 pos3 /\ valid_pos (p1 `parse_pair` p2) h b pos1 pos3 /\ contents (p1 `parse_pair` p2) h b pos1 pos3 == (contents p1 h b pos1 pos2, contents p2 h b pos2 pos3) )) val size_parse_pair (p1 p2: parser) (x1: Parser?.t p1) (x2: Parser?.t p2) : Lemma (size (p1 `parse_pair` p2) (x1, x2) == size p1 x1 + size p2 x2) [SMTPat (size (p1 `parse_pair` p2) (x1, x2))] val valid_ext (p: parser) (h1: HS.mem) (b1: B.buffer U8.t) (pos1: U32.t) (pos1' : U32.t) (h2: HS.mem) (b2: B.buffer U8.t) (pos2: U32.t) (pos2' : U32.t) : Lemma (requires ( valid_pos p h1 b1 pos1 pos1' /\ U32.v pos2 <= U32.v pos2' /\ U32.v pos2' <= B.length b2 /\ B.live h2 b2 /\ B.as_seq h2 (B.gsub b2 pos2 (pos2' `U32.sub` pos2)) `Seq.equal` B.as_seq h1 (B.gsub b1 pos1 (pos1' `U32.sub` pos1)) )) (ensures ( valid_pos p h1 b1 pos1 pos1' /\ valid_pos p h2 b2 pos2 pos2' /\ contents p h2 b2 pos2 pos2' == contents p h1 b1 pos1 pos1' )) let valid_frame (p: parser) (h: HS.mem) (b: B.buffer U8.t) (pos: U32.t) (pos' : U32.t) (l: B.loc) (h' : HS.mem) : Lemma (requires ( B.live h b /\ (valid_pos p h b pos pos' \/ valid_pos p h' b pos pos') /\ B.modifies l h h' /\ B.loc_disjoint l (B.loc_buffer_from_to b pos pos') )) (ensures ( valid_pos p h b pos pos' /\ valid_pos p h' b pos pos' /\ contents p h' b pos pos' == contents p h b pos pos' )) = B.loc_buffer_mgsub_eq (B.trivial_preorder _) b pos (pos' `U32.sub` pos); Classical.move_requires (valid_ext p h b pos pos' h' b pos) pos'; Classical.move_requires (valid_ext p h' b pos pos' h b pos) pos' let valid_gsub_elim (p: parser) (h: HS.mem) (b: B.buffer U8.t) (pos0 pos1 pos2: U32.t) (len: U32.t) : Lemma (requires ( U32.v pos0 + U32.v len <= B.length b /\ valid_pos p h (B.gsub b pos0 len) pos1 pos2 /\ B.live h b )) (ensures ( U32.v pos0 + U32.v pos2 <= B.length b /\ valid_pos p h (B.gsub b pos0 len) pos1 pos2 /\ valid_pos p h b (pos0 `U32.add` pos1) (pos0 `U32.add` pos2) /\ contents p h b (pos0 `U32.add` pos1) (pos0 `U32.add` pos2) == contents p h (B.gsub b pos0 len) pos1 pos2 )) [SMTPat (valid_pos p h (B.gsub b pos0 len) pos1 pos2)] = valid_ext p h (B.gsub b pos0 len) pos1 pos2 h b (pos0 `U32.add` pos1) (pos0 `U32.add` pos2) let valid_gsub_intro (p: parser) (h: HS.mem) (b: B.buffer U8.t) (pos0 pos1 pos2: U32.t) (len: U32.t) : Lemma (requires ( U32.v pos0 + U32.v len <= B.length b /\ U32.v pos1 <= U32.v pos2 /\ U32.v pos2 <= U32.v len /\ valid_pos p h b (pos0 `U32.add` pos1) (pos0 `U32.add` pos2) )) (ensures ( valid_pos p h (B.gsub b pos0 len) pos1 pos2 /\ contents p h b (pos0 `U32.add` pos1) (pos0 `U32.add` pos2) == contents p h (B.gsub b pos0 len) pos1 pos2 )) [SMTPat (valid_pos p h (B.gsub b pos0 len) pos1 pos2)] = valid_ext p h b (pos0 `U32.add` pos1) (pos0 `U32.add` pos2) h (B.gsub b pos0 len) pos1 pos2 inline_for_extraction let leaf_writer (p: parser) : Tot Type = (b: B.buffer U8.t) -> (len: U32.t { len == B.len b }) -> (x: Parser?.t p) -> HST.Stack (option U32.t) (requires (fun h -> B.live h b)) (ensures (fun h res h' -> match res with | None -> B.modifies (B.loc_buffer b) h h' /\ size p x > B.length b | Some xlen -> U32.v xlen <= B.length b /\ B.modifies (B.loc_buffer_from_to b 0ul xlen) h h' /\ valid_pos p h' b 0ul xlen /\ contents p h' b 0ul xlen == x /\ size p x == U32.v xlen )) val valid_parse_pair_inv_spec (h: HS.mem) (p1 p2: parser) (b: B.buffer U8.t) (pos1 pos3: U32.t) : Ghost U32.t (requires ( valid_pos (p1 `parse_pair` p2) h b pos1 pos3 )) (ensures (fun pos2 -> valid_pos p1 h b pos1 pos2 /\ valid_pos p2 h b pos2 pos3 /\ contents (p1 `parse_pair` p2) h b pos1 pos3 == (contents p1 h b pos1 pos2, contents p2 h b pos2 pos3) )) inline_for_extraction val valid_parse_pair_inv (p1 p2: parser) (b: B.buffer U8.t) (len: U32.t { len == B.len b }) (pos1 pos3: U32.t) : HST.Stack U32.t (requires (fun h -> valid_pos (p1 `parse_pair` p2) h b pos1 pos3 )) (ensures (fun h pos2 h' -> B.modifies B.loc_none h h' /\ pos2 == valid_parse_pair_inv_spec h p1 p2 b pos1 pos3 /\ valid_pos p1 h b pos1 pos2 /\ valid_pos p2 h b pos2 pos3 /\ contents (p1 `parse_pair` p2) h b pos1 pos3 == (contents p1 h b pos1 pos2, contents p2 h b pos2 pos3) )) let valid_buffer (p: parser) (h: HS.mem) (b: B.buffer U8.t) : GTot Type0 = valid_pos p h b 0ul (B.len b)
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowStar.Buffer.fst.checked", "FStar.UInt8.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Classical.fsti.checked" ], "interface_file": false, "source_file": "LowParseWriters.LowParse.fsti" }
[ { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": false, "full_module": "LowParseWriters", "short_module": null }, { "abbrev": false, "full_module": "LowParseWriters", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
p: LowParseWriters.LowParse.parser -> h: FStar.Monotonic.HyperStack.mem -> b: LowStar.Buffer.buffer FStar.UInt8.t -> Prims.Ghost (Parser?.t p)
Prims.Ghost
[]
[]
[ "LowParseWriters.LowParse.parser", "FStar.Monotonic.HyperStack.mem", "LowStar.Buffer.buffer", "FStar.UInt8.t", "LowParseWriters.LowParse.contents", "FStar.UInt32.__uint_to_t", "LowStar.Monotonic.Buffer.len", "LowStar.Buffer.trivial_preorder", "LowParseWriters.LowParse.__proj__Parser__item__t", "LowParseWriters.LowParse.valid_buffer", "Prims.l_True" ]
[]
false
false
false
false
false
let buffer_contents (p: parser) (h: HS.mem) (b: B.buffer U8.t) : Ghost (Parser?.t p) (requires (valid_buffer p h b)) (ensures (fun _ -> True)) =
contents p h b 0ul (B.len b)
false
Hacl.Spec.Bignum.MontArithmetic.fst
Hacl.Spec.Bignum.MontArithmetic.bn_field_exp_consttime
val bn_field_exp_consttime: #t:limb_t -> k:bn_mont_ctx t{bn_mont_ctx_inv k} -> bn_field_exp_st t k
val bn_field_exp_consttime: #t:limb_t -> k:bn_mont_ctx t{bn_mont_ctx_inv k} -> bn_field_exp_st t k
let bn_field_exp_consttime #t k aM bBits b = E.from_mont_exp_lemma (bits t) k.len (bn_v k.n) (v k.mu) (bn_v aM) (bn_v b); ME.bn_exp_mont_consttime k.n k.mu aM bBits b
{ "file_name": "code/bignum/Hacl.Spec.Bignum.MontArithmetic.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 46, "end_line": 157, "start_col": 0, "start_line": 155 }
module Hacl.Spec.Bignum.MontArithmetic open FStar.Mul open Lib.IntTypes open Lib.Sequence open Hacl.Spec.Bignum.Definitions module M = Hacl.Spec.Montgomery.Lemmas module BM = Hacl.Spec.Bignum.Montgomery module BN = Hacl.Spec.Bignum module BB = Hacl.Spec.Bignum.Base module BL = Hacl.Spec.Bignum.Lib module BIL = Hacl.Spec.Bignum.ModInvLimb module E = Hacl.Spec.Exponentiation.Lemmas module ME = Hacl.Spec.Bignum.MontExponentiation module Euclid = FStar.Math.Euclid module BI = Hacl.Spec.Bignum.ModInv #set-options "--z3rlimit 50 --fuel 0 --ifuel 0" ////////////////////////////////////////// val mul_zero_lemma: n:pos{Euclid.is_prime n} -> x:int -> y:int -> Lemma (x * y % n == 0 <==> (x % n == 0 \/ y % n == 0)) let mul_zero_lemma n x y = assert (0 % n = 0); if x % n = 0 then Math.Lemmas.lemma_mod_mul_distr_l x y n else if y % n = 0 then Math.Lemmas.lemma_mod_mul_distr_r x y n else if x * y % n = 0 then Math.Fermat.mod_mult_congr n x 0 y else () val mul_nonzero_lemma: n:pos{Euclid.is_prime n} -> x:int -> y:int -> Lemma (requires x % n <> 0 /\ y % n <> 0) (ensures x * y % n <> 0) let mul_nonzero_lemma n x y = mul_zero_lemma n x y val from_mont_lemma_nonzero: pbits:pos -> rLen:pos -> n:pos -> mu:nat -> aM:nat -> Lemma (requires M.mont_pre pbits rLen n mu /\ 0 < aM /\ aM < n /\ Euclid.is_prime n) (ensures (let a = M.from_mont pbits rLen n mu aM in 0 < a /\ a < n)) let from_mont_lemma_nonzero pbits rLen n mu aM = let r = pow2 (pbits * rLen) in let d, _ = M.eea_pow2_odd (pbits * rLen) n in let a = M.from_mont pbits rLen n mu aM in M.from_mont_lemma pbits rLen n mu aM; assert (a == aM * d % n); assert (d <> 0); Math.Lemmas.small_mod aM n; assert (aM % n <> 0); let d1 = -d in assert (0 < d1 /\ d1 < n); Math.Lemmas.lemma_mod_sub_1 d1 n; assert ((-d1) % n == n - (d1 % n)); assert (d % n <> 0); mul_nonzero_lemma n aM d; assert (let a = M.from_mont pbits rLen n mu aM in 0 < a /\ a < n); // For some reason, this makes the proof instant. () /////////////////////////////////////////////// let bn_field_get_len #t k = k.len let bn_field_check_modulus #t #len n = let m = BM.bn_check_modulus n in BB.unsafe_bool_of_limb m let bn_field_init #t #len n = let nBits = bits t * BL.bn_get_top_index n in BL.bn_low_bound_bits_lemma n; BM.bn_precomp_r2_mod_n_lemma nBits n; let r2 = BM.bn_precomp_r2_mod_n nBits n in assert (bn_v r2 == pow2 (2 * bits t * len) % bn_v n); let mu = BIL.mod_inv_limb n.[0] in BIL.bn_mod_inv_limb_lemma n; assert ((1 + bn_v n * v mu) % pow2 (bits t) == 0); bn_eval_bound n len; { len = len; n = n; mu = mu; r2 = r2 } let bn_to_field #t k a = BM.bn_to_mont_lemma k.n k.mu k.r2 a; BM.bn_to_mont k.n k.mu k.r2 a let bn_from_field #t k aM = BM.bn_from_mont_lemma k.n k.mu aM; BM.bn_from_mont k.n k.mu aM let bn_from_to_field_lemma #t k a = bn_eval_bound a k.len; M.from_to_mont_lemma (bits t) k.len (bn_v k.n) (v k.mu) (bn_v a) let bn_field_add #t k aM bM = BN.bn_add_mod_n_lemma k.n aM bM; M.from_mont_add_lemma (bits t) k.len (bn_v k.n) (v k.mu) (bn_v aM) (bn_v bM); BN.bn_add_mod_n k.n aM bM let bn_field_sub #t k aM bM = BN.bn_sub_mod_n_lemma k.n aM bM; M.from_mont_sub_lemma (bits t) k.len (bn_v k.n) (v k.mu) (bn_v aM) (bn_v bM); BN.bn_sub_mod_n k.n aM bM let bn_field_mul #t k aM bM = BM.bn_mont_mul_lemma k.n k.mu aM bM; M.from_mont_mul_lemma (bits t) k.len (bn_v k.n) (v k.mu) (bn_v aM) (bn_v bM); BM.bn_mont_mul k.n k.mu aM bM let bn_field_sqr #t k aM = BM.bn_mont_sqr_lemma k.n k.mu aM; M.from_mont_mul_lemma (bits t) k.len (bn_v k.n) (v k.mu) (bn_v aM) (bn_v aM); BM.bn_mont_sqr k.n k.mu aM let bn_field_one #t k = BM.bn_mont_one_lemma k.n k.mu k.r2; M.from_mont_one_lemma (bits t) k.len (bn_v k.n) (v k.mu); BM.bn_mont_one k.n k.mu r2
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "Lib.Sequence.fsti.checked", "Lib.NatMod.fsti.checked", "Lib.IntTypes.fsti.checked", "Hacl.Spec.Montgomery.Lemmas.fst.checked", "Hacl.Spec.Exponentiation.Lemmas.fst.checked", "Hacl.Spec.Bignum.Montgomery.fsti.checked", "Hacl.Spec.Bignum.MontExponentiation.fst.checked", "Hacl.Spec.Bignum.ModInvLimb.fsti.checked", "Hacl.Spec.Bignum.ModInv.fst.checked", "Hacl.Spec.Bignum.Lib.fst.checked", "Hacl.Spec.Bignum.Definitions.fst.checked", "Hacl.Spec.Bignum.Base.fst.checked", "Hacl.Spec.Bignum.fsti.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.Math.Fermat.fsti.checked", "FStar.Math.Euclid.fsti.checked" ], "interface_file": true, "source_file": "Hacl.Spec.Bignum.MontArithmetic.fst" }
[ { "abbrev": true, "full_module": "Hacl.Spec.Bignum.ModInv", "short_module": "BI" }, { "abbrev": true, "full_module": "Hacl.Spec.Bignum.MontExponentiation", "short_module": "ME" }, { "abbrev": true, "full_module": "Hacl.Spec.Exponentiation.Lemmas", "short_module": "E" }, { "abbrev": true, "full_module": "Hacl.Spec.Bignum.ModInvLimb", "short_module": "BIL" }, { "abbrev": true, "full_module": "Hacl.Spec.Bignum.Lib", "short_module": "BL" }, { "abbrev": true, "full_module": "Hacl.Spec.Bignum.Base", "short_module": "BB" }, { "abbrev": true, "full_module": "Hacl.Spec.Bignum.Montgomery", "short_module": "BM" }, { "abbrev": true, "full_module": "Hacl.Spec.Bignum", "short_module": "BN" }, { "abbrev": true, "full_module": "Hacl.Spec.Montgomery.Lemmas", "short_module": "M" }, { "abbrev": true, "full_module": "FStar.Math.Euclid", "short_module": "Euclid" }, { "abbrev": false, "full_module": "Hacl.Spec.Bignum.Definitions", "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.Bignum", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.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 } ]
{ "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" }
false
k: Hacl.Spec.Bignum.MontArithmetic.bn_mont_ctx t {Hacl.Spec.Bignum.MontArithmetic.bn_mont_ctx_inv k} -> Hacl.Spec.Bignum.MontArithmetic.bn_field_exp_st t k
Prims.Tot
[ "total" ]
[]
[ "Hacl.Spec.Bignum.Definitions.limb_t", "Hacl.Spec.Bignum.MontArithmetic.bn_mont_ctx", "Hacl.Spec.Bignum.MontArithmetic.bn_mont_ctx_inv", "Hacl.Spec.Bignum.MontArithmetic.bn_mont_nat", "Lib.IntTypes.size_nat", "Hacl.Spec.Bignum.Definitions.lbignum", "Hacl.Spec.Bignum.Definitions.blocks0", "Lib.IntTypes.bits", "Hacl.Spec.Bignum.MontExponentiation.bn_exp_mont_consttime", "Hacl.Spec.Bignum.MontArithmetic.__proj__Mkbn_mont_ctx__item__len", "Hacl.Spec.Bignum.MontArithmetic.__proj__Mkbn_mont_ctx__item__n", "Hacl.Spec.Bignum.MontArithmetic.__proj__Mkbn_mont_ctx__item__mu", "Prims.unit", "Hacl.Spec.Exponentiation.Lemmas.from_mont_exp_lemma", "Hacl.Spec.Bignum.Definitions.bn_v", "Lib.IntTypes.v", "Lib.IntTypes.SEC" ]
[]
false
false
false
false
false
let bn_field_exp_consttime #t k aM bBits b =
E.from_mont_exp_lemma (bits t) k.len (bn_v k.n) (v k.mu) (bn_v aM) (bn_v b); ME.bn_exp_mont_consttime k.n k.mu aM bBits b
false
Pulse.Soundness.fst
Pulse.Soundness.stapp_soundness
val stapp_soundness (g: stt_env) (t: st_term) (c: comp) (d: st_typing g t c {T_STApp? d}) (soundness: soundness_t d) : GTot (RT.tot_typing (elab_env g) (elab_st_typing d) (elab_comp c))
val stapp_soundness (g: stt_env) (t: st_term) (c: comp) (d: st_typing g t c {T_STApp? d}) (soundness: soundness_t d) : GTot (RT.tot_typing (elab_env g) (elab_st_typing d) (elab_comp c))
let stapp_soundness (g:stt_env) (t:st_term) (c:comp) (d:st_typing g t c{T_STApp? d}) (soundness:soundness_t d) : GTot (RT.tot_typing (elab_env g) (elab_st_typing d) (elab_comp c)) = let T_STApp _ head formal q res arg head_typing arg_typing = d in let r_head = elab_term head in let r_arg = elab_term arg in let r_head_typing : RT.tot_typing _ r_head (elab_term (tm_arrow (mk_binder_ppname formal ppname_default) q res)) = tot_typing_soundness head_typing in let r_arg_typing = tot_typing_soundness arg_typing in RT.T_App _ _ _ (binder_of_t_q_s (elab_term formal) (elab_qual q) RT.pp_name_default) (elab_comp res) _ r_head_typing r_arg_typing
{ "file_name": "lib/steel/pulse/Pulse.Soundness.fst", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 29, "end_line": 130, "start_col": 0, "start_line": 109 }
(* Copyright 2023 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module Pulse.Soundness module RT = FStar.Reflection.Typing module R = FStar.Reflection.V2 module L = FStar.List.Tot module T = FStar.Tactics.V2 open FStar.List.Tot open Pulse.Syntax open Pulse.Reflection.Util open Pulse.Typing open Pulse.Elaborate open Pulse.Soundness.Common module Bind = Pulse.Soundness.Bind module Lift = Pulse.Soundness.Lift module Frame = Pulse.Soundness.Frame module STEquiv = Pulse.Soundness.STEquiv module Return = Pulse.Soundness.Return module Exists = Pulse.Soundness.Exists module While = Pulse.Soundness.While module Admit = Pulse.Soundness.Admit module Par = Pulse.Soundness.Par module WithLocal = Pulse.Soundness.WithLocal module WithLocalArray = Pulse.Soundness.WithLocalArray module Rewrite = Pulse.Soundness.Rewrite module Comp = Pulse.Soundness.Comp module LN = Pulse.Typing.LN module FV = Pulse.Typing.FV module STT = Pulse.Soundness.STT module Sub = Pulse.Soundness.Sub module RU = Pulse.RuntimeUtils module Typing = Pulse.Typing module EPure = Pulse.Elaborate.Pure module WT= Pulse.Steel.Wrapper.Typing let tabs_t (d:'a) = #g:stt_env -> #u:universe -> #ty:term -> q:option qualifier -> ppname:ppname -> t_typing:tot_typing g ty (tm_type u) { t_typing << d } -> #body:st_term -> #x:var { None? (lookup g x) /\ ~(x `Set.mem` freevars_st body) } -> #c:comp -> body_typing:st_typing (push_binding g x ppname ty) (open_st_term body x) c { body_typing << d } -> GTot (RT.tot_typing (elab_env g) (mk_abs_with_name ppname.name (elab_term ty) (elab_qual q) (RT.close_term (elab_st_typing body_typing) x)) (elab_term (tm_arrow (mk_binder_ppname ty ppname) q (close_comp c x)))) #push-options "--z3rlimit_factor 4 --split_queries no" let lift_soundness (g:stt_env) (t:st_term) (c:comp) (d:st_typing g t c{T_Lift? d}) (soundness:soundness_t d) : GTot (RT.tot_typing (elab_env g) (elab_st_typing d) (elab_comp c)) = LN.st_typing_ln d; let T_Lift _ e c1 c2 e_typing lc = d in LN.st_typing_ln e_typing; match lc with | Lift_STAtomic_ST _ _ -> Lift.elab_lift_stt_atomic_st_typing g c1 c2 _ (soundness _ _ _ e_typing) lc | Lift_Ghost_Neutral _ _ w -> let (| reveal_a, reveal_a_typing |) = w in Lift.elab_lift_ghost_neutral_typing g c1 c2 _ (soundness _ _ _ e_typing) lc _ (tot_typing_soundness reveal_a_typing) | Lift_Neutral_Ghost _ _ -> Lift.elab_lift_neutral_ghost_typing g c1 c2 _ (soundness _ _ _ e_typing) lc | Lift_Observability _ _ _ -> Lift.elab_lift_observability_typing g c1 c2 _ (soundness _ _ _ e_typing) lc #pop-options let frame_soundness (g:stt_env) (t:st_term) (c:comp) (d:st_typing g t c{T_Frame? d}) (soundness:soundness_t d) : GTot (RT.tot_typing (elab_env g) (elab_st_typing d) (elab_comp c)) = let T_Frame _ e c frame frame_typing e_typing = d in let r_e_typing = soundness _ _ _ e_typing in LN.st_typing_ln e_typing; Frame.elab_frame_typing g _ _ frame frame_typing r_e_typing
{ "checked_file": "/", "dependencies": [ "Pulse.Typing.LN.fsti.checked", "Pulse.Typing.FV.fsti.checked", "Pulse.Typing.fst.checked", "Pulse.Syntax.fst.checked", "Pulse.Steel.Wrapper.Typing.fsti.checked", "Pulse.Soundness.WithLocalArray.fsti.checked", "Pulse.Soundness.WithLocal.fsti.checked", "Pulse.Soundness.While.fsti.checked", "Pulse.Soundness.Sub.fsti.checked", "Pulse.Soundness.STT.fsti.checked", "Pulse.Soundness.STEquiv.fsti.checked", "Pulse.Soundness.Rewrite.fsti.checked", "Pulse.Soundness.Return.fsti.checked", "Pulse.Soundness.Par.fsti.checked", "Pulse.Soundness.Match.fsti.checked", "Pulse.Soundness.Lift.fsti.checked", "Pulse.Soundness.Frame.fsti.checked", "Pulse.Soundness.Exists.fsti.checked", "Pulse.Soundness.Comp.fsti.checked", "Pulse.Soundness.Common.fst.checked", "Pulse.Soundness.Bind.fsti.checked", "Pulse.Soundness.Admit.fsti.checked", "Pulse.RuntimeUtils.fsti.checked", "Pulse.Reflection.Util.fst.checked", "Pulse.Elaborate.Pure.fst.checked", "Pulse.Elaborate.fsti.checked", "prims.fst.checked", "FStar.Tactics.V2.fst.checked", "FStar.Squash.fsti.checked", "FStar.Set.fsti.checked", "FStar.Reflection.V2.fst.checked", "FStar.Reflection.Typing.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked" ], "interface_file": true, "source_file": "Pulse.Soundness.fst" }
[ { "abbrev": true, "full_module": "Pulse.Steel.Wrapper.Typing", "short_module": "WT" }, { "abbrev": true, "full_module": "Pulse.Elaborate.Pure", "short_module": "EPure" }, { "abbrev": true, "full_module": "Pulse.Typing", "short_module": "Typing" }, { "abbrev": true, "full_module": "Pulse.RuntimeUtils", "short_module": "RU" }, { "abbrev": true, "full_module": "Pulse.Soundness.Sub", "short_module": "Sub" }, { "abbrev": true, "full_module": "Pulse.Soundness.STT", "short_module": "STT" }, { "abbrev": true, "full_module": "Pulse.Typing.FV", "short_module": "FV" }, { "abbrev": true, "full_module": "Pulse.Typing.LN", "short_module": "LN" }, { "abbrev": true, "full_module": "Pulse.Soundness.Comp", "short_module": "Comp" }, { "abbrev": true, "full_module": "Pulse.Soundness.Rewrite", "short_module": "Rewrite" }, { "abbrev": true, "full_module": "Pulse.Soundness.WithLocalArray", "short_module": "WithLocalArray" }, { "abbrev": true, "full_module": "Pulse.Soundness.WithLocal", "short_module": "WithLocal" }, { "abbrev": true, "full_module": "Pulse.Soundness.Par", "short_module": "Par" }, { "abbrev": true, "full_module": "Pulse.Soundness.Admit", "short_module": "Admit" }, { "abbrev": true, "full_module": "Pulse.Soundness.While", "short_module": "While" }, { "abbrev": true, "full_module": "Pulse.Soundness.Exists", "short_module": "Exists" }, { "abbrev": true, "full_module": "Pulse.Soundness.Return", "short_module": "Return" }, { "abbrev": true, "full_module": "Pulse.Soundness.STEquiv", "short_module": "STEquiv" }, { "abbrev": true, "full_module": "Pulse.Soundness.Frame", "short_module": "Frame" }, { "abbrev": true, "full_module": "Pulse.Soundness.Lift", "short_module": "Lift" }, { "abbrev": true, "full_module": "Pulse.Soundness.Bind", "short_module": "Bind" }, { "abbrev": false, "full_module": "Pulse.Soundness.Common", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Elaborate", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Typing", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Reflection.Util", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Syntax", "short_module": null }, { "abbrev": false, "full_module": "FStar.List.Tot", "short_module": null }, { "abbrev": true, "full_module": "FStar.Tactics.V2", "short_module": "T" }, { "abbrev": true, "full_module": "FStar.List.Tot", "short_module": "L" }, { "abbrev": true, "full_module": "FStar.Reflection.V2", "short_module": "R" }, { "abbrev": true, "full_module": "FStar.Reflection.Typing", "short_module": "RT" }, { "abbrev": false, "full_module": "Pulse.Soundness.Common", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Elaborate", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Typing", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Reflection.Util", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Syntax", "short_module": null }, { "abbrev": false, "full_module": "FStar.List.Tot", "short_module": null }, { "abbrev": true, "full_module": "FStar.Tactics.V2", "short_module": "T" }, { "abbrev": true, "full_module": "FStar.List.Tot", "short_module": "L" }, { "abbrev": true, "full_module": "FStar.Reflection.V2", "short_module": "R" }, { "abbrev": true, "full_module": "FStar.Reflection.Typing", "short_module": "RT" }, { "abbrev": false, "full_module": "Pulse", "short_module": null }, { "abbrev": false, "full_module": "Pulse", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
g: Pulse.Soundness.Common.stt_env -> t: Pulse.Syntax.Base.st_term -> c: Pulse.Syntax.Base.comp -> d: Pulse.Typing.st_typing g t c {T_STApp? d} -> soundness: Pulse.Soundness.Common.soundness_t d -> Prims.GTot (FStar.Reflection.Typing.tot_typing (Pulse.Typing.elab_env g) (Pulse.Elaborate.Core.elab_st_typing d) (Pulse.Elaborate.Pure.elab_comp c))
Prims.GTot
[ "sometrivial" ]
[]
[ "Pulse.Soundness.Common.stt_env", "Pulse.Syntax.Base.st_term", "Pulse.Syntax.Base.comp", "Pulse.Typing.st_typing", "Prims.b2t", "Pulse.Typing.uu___is_T_STApp", "Pulse.Soundness.Common.soundness_t", "Pulse.Typing.Env.env", "Pulse.Syntax.Base.term", "FStar.Pervasives.Native.option", "Pulse.Syntax.Base.qualifier", "Pulse.Syntax.Base.comp_st", "Pulse.Typing.tot_typing", "Pulse.Syntax.Pure.tm_arrow", "Pulse.Syntax.Base.as_binder", "FStar.Reflection.Typing.T_App", "Pulse.Typing.elab_env", "Pulse.Elaborate.Pure.elab_term", "Pulse.Reflection.Util.binder_of_t_q_s", "Pulse.Elaborate.Pure.elab_qual", "FStar.Reflection.Typing.pp_name_default", "Pulse.Elaborate.Pure.elab_comp", "FStar.Stubs.TypeChecker.Core.E_Total", "FStar.Reflection.Typing.tot_typing", "Pulse.Soundness.Common.tot_typing_soundness", "Pulse.Syntax.Base.mk_binder_ppname", "Pulse.Syntax.Base.ppname_default", "FStar.Stubs.Reflection.Types.term", "Pulse.Elaborate.Core.elab_st_typing" ]
[]
false
false
false
false
false
let stapp_soundness (g: stt_env) (t: st_term) (c: comp) (d: st_typing g t c {T_STApp? d}) (soundness: soundness_t d) : GTot (RT.tot_typing (elab_env g) (elab_st_typing d) (elab_comp c)) =
let T_STApp _ head formal q res arg head_typing arg_typing = d in let r_head = elab_term head in let r_arg = elab_term arg in let r_head_typing:RT.tot_typing _ r_head (elab_term (tm_arrow (mk_binder_ppname formal ppname_default) q res)) = tot_typing_soundness head_typing in let r_arg_typing = tot_typing_soundness arg_typing in RT.T_App _ _ _ (binder_of_t_q_s (elab_term formal) (elab_qual q) RT.pp_name_default) (elab_comp res) _ r_head_typing r_arg_typing
false
Pulse.Soundness.fst
Pulse.Soundness.soundness_lemma
val soundness_lemma (g:stt_env) (t:st_term) (c:comp) (d:st_typing g t c) : Lemma (ensures RT.tot_typing (elab_env g) (elab_st_typing d) (elab_comp c))
val soundness_lemma (g:stt_env) (t:st_term) (c:comp) (d:st_typing g t c) : Lemma (ensures RT.tot_typing (elab_env g) (elab_st_typing d) (elab_comp c))
let soundness_lemma (g:stt_env) (t:st_term) (c:comp) (d:st_typing g t c) : Lemma (ensures RT.tot_typing (elab_env g) (elab_st_typing d) (elab_comp c)) = FStar.Squash.bind_squash #(st_typing g t c) () (fun dd -> FStar.Squash.return_squash (soundness g t c d))
{ "file_name": "lib/steel/pulse/Pulse.Soundness.fst", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 64, "end_line": 431, "start_col": 0, "start_line": 420 }
(* Copyright 2023 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module Pulse.Soundness module RT = FStar.Reflection.Typing module R = FStar.Reflection.V2 module L = FStar.List.Tot module T = FStar.Tactics.V2 open FStar.List.Tot open Pulse.Syntax open Pulse.Reflection.Util open Pulse.Typing open Pulse.Elaborate open Pulse.Soundness.Common module Bind = Pulse.Soundness.Bind module Lift = Pulse.Soundness.Lift module Frame = Pulse.Soundness.Frame module STEquiv = Pulse.Soundness.STEquiv module Return = Pulse.Soundness.Return module Exists = Pulse.Soundness.Exists module While = Pulse.Soundness.While module Admit = Pulse.Soundness.Admit module Par = Pulse.Soundness.Par module WithLocal = Pulse.Soundness.WithLocal module WithLocalArray = Pulse.Soundness.WithLocalArray module Rewrite = Pulse.Soundness.Rewrite module Comp = Pulse.Soundness.Comp module LN = Pulse.Typing.LN module FV = Pulse.Typing.FV module STT = Pulse.Soundness.STT module Sub = Pulse.Soundness.Sub module RU = Pulse.RuntimeUtils module Typing = Pulse.Typing module EPure = Pulse.Elaborate.Pure module WT= Pulse.Steel.Wrapper.Typing let tabs_t (d:'a) = #g:stt_env -> #u:universe -> #ty:term -> q:option qualifier -> ppname:ppname -> t_typing:tot_typing g ty (tm_type u) { t_typing << d } -> #body:st_term -> #x:var { None? (lookup g x) /\ ~(x `Set.mem` freevars_st body) } -> #c:comp -> body_typing:st_typing (push_binding g x ppname ty) (open_st_term body x) c { body_typing << d } -> GTot (RT.tot_typing (elab_env g) (mk_abs_with_name ppname.name (elab_term ty) (elab_qual q) (RT.close_term (elab_st_typing body_typing) x)) (elab_term (tm_arrow (mk_binder_ppname ty ppname) q (close_comp c x)))) #push-options "--z3rlimit_factor 4 --split_queries no" let lift_soundness (g:stt_env) (t:st_term) (c:comp) (d:st_typing g t c{T_Lift? d}) (soundness:soundness_t d) : GTot (RT.tot_typing (elab_env g) (elab_st_typing d) (elab_comp c)) = LN.st_typing_ln d; let T_Lift _ e c1 c2 e_typing lc = d in LN.st_typing_ln e_typing; match lc with | Lift_STAtomic_ST _ _ -> Lift.elab_lift_stt_atomic_st_typing g c1 c2 _ (soundness _ _ _ e_typing) lc | Lift_Ghost_Neutral _ _ w -> let (| reveal_a, reveal_a_typing |) = w in Lift.elab_lift_ghost_neutral_typing g c1 c2 _ (soundness _ _ _ e_typing) lc _ (tot_typing_soundness reveal_a_typing) | Lift_Neutral_Ghost _ _ -> Lift.elab_lift_neutral_ghost_typing g c1 c2 _ (soundness _ _ _ e_typing) lc | Lift_Observability _ _ _ -> Lift.elab_lift_observability_typing g c1 c2 _ (soundness _ _ _ e_typing) lc #pop-options let frame_soundness (g:stt_env) (t:st_term) (c:comp) (d:st_typing g t c{T_Frame? d}) (soundness:soundness_t d) : GTot (RT.tot_typing (elab_env g) (elab_st_typing d) (elab_comp c)) = let T_Frame _ e c frame frame_typing e_typing = d in let r_e_typing = soundness _ _ _ e_typing in LN.st_typing_ln e_typing; Frame.elab_frame_typing g _ _ frame frame_typing r_e_typing let stapp_soundness (g:stt_env) (t:st_term) (c:comp) (d:st_typing g t c{T_STApp? d}) (soundness:soundness_t d) : GTot (RT.tot_typing (elab_env g) (elab_st_typing d) (elab_comp c)) = let T_STApp _ head formal q res arg head_typing arg_typing = d in let r_head = elab_term head in let r_arg = elab_term arg in let r_head_typing : RT.tot_typing _ r_head (elab_term (tm_arrow (mk_binder_ppname formal ppname_default) q res)) = tot_typing_soundness head_typing in let r_arg_typing = tot_typing_soundness arg_typing in RT.T_App _ _ _ (binder_of_t_q_s (elab_term formal) (elab_qual q) RT.pp_name_default) (elab_comp res) _ r_head_typing r_arg_typing // // We have G |- head : Ghost (x:t -> Total res) -- (1) // G |- arg : Ghost t -- (2) // G,x:t |- non_informative (open res x) -- (3) // // We first lift (1) to G |- head : Ghost (x:t -> Ghost res) // Then apply T_App in reflection typing to derive // G |- head arg : Ghost (open res arg) -- (4) // and then promote (4) to Total using a substitution lemma on (3) // let stghostapp_soundness (g:stt_env) (t:st_term) (c:comp) (d:st_typing g t c{T_STGhostApp? d}) (soundness:soundness_t d) : GTot (RT.tot_typing (elab_env g) (elab_st_typing d) (elab_comp c)) = let T_STGhostApp _ head formal q res arg x head_typing d_non_info arg_typing = d in let r_head = elab_term head in let r_arg = elab_term arg in let r_binder = mk_binder_ppname formal ppname_default in let head_t = tm_arrow r_binder q res in let r_head_t = mk_arrow_with_name ppname_default.name (elab_term formal, elab_qual q) (elab_comp res) in let r_head_typing : RT.ghost_typing _ r_head r_head_t = ghost_typing_soundness head_typing in let r_arg_typing = ghost_typing_soundness arg_typing in assume (elab_env (push_binding g x ppname_default formal) == RT.extend_env (elab_env g) x (elab_term formal)); assume ((T.E_Total, elab_comp (open_comp_with res (null_var x))) == RT.open_comp_typ (T.E_Total, elab_comp res) x); assume ((T.E_Ghost, elab_comp (open_comp_with res (null_var x))) == RT.open_comp_typ (T.E_Ghost, elab_comp res) x); let d_rel_comp : RT.related_comp (elab_env (push_binding g x ppname_default formal)) (T.E_Total, elab_comp (open_comp_with res (null_var x))) RT.R_Sub (T.E_Ghost, elab_comp (open_comp_with res (null_var x))) = RT.Relc_total_ghost _ _ in let r_head_t_ghost = mk_ghost_arrow_with_name ppname_default.name (elab_term formal, elab_qual q) (elab_comp res) in assert (r_head_t == RT.mk_arrow_ct (elab_term formal) (elab_qual q) (T.E_Total, elab_comp res)); assert (r_head_t_ghost == RT.mk_arrow_ct (elab_term formal) (elab_qual q) (T.E_Ghost, elab_comp res)); assume (None? (RT.lookup_bvar (elab_env g) x) /\ ~ (x `Set.mem` ((RT.freevars_comp_typ (T.E_Total, elab_comp res)) `Set.union` (RT.freevars_comp_typ (T.E_Ghost, elab_comp res))))); let d_rel_t_arrow : RT.related (elab_env g) r_head_t RT.R_Sub r_head_t_ghost = RT.Rel_arrow _ (elab_term formal) (elab_term formal) (elab_qual q) (T.E_Total, elab_comp res) (T.E_Ghost, elab_comp res) RT.R_Sub x (RT.Rel_equiv _ _ _ _ (RT.Rel_refl _ _ _)) d_rel_comp in let r_head_typing : RT.ghost_typing _ r_head r_head_t_ghost = RT.T_Sub _ _ _ _ r_head_typing (RT.Relc_typ _ _ _ T.E_Ghost _ d_rel_t_arrow) in let d : RT.typing (elab_env g) (elab_st_typing d) (T.E_Ghost, elab_comp (open_comp_with res arg)) = RT.T_App _ _ _ (binder_of_t_q_s (elab_term formal) (elab_qual q) RT.pp_name_default) (elab_comp res) _ r_head_typing r_arg_typing in let E d_non_info = d_non_info in let d_non_info : RT.non_informative (elab_env (push_binding g x ppname_default formal)) (elab_comp (open_comp_with res (null_var x))) = d_non_info in // TODO: substitution lemma in RT for non_informative judgment let d_non_info : RT.non_informative (elab_env g) (elab_comp (open_comp_with res arg)) = RU.magic () in RT.T_Sub _ _ _ _ d (RT.Relc_ghost_total _ _ d_non_info) let stequiv_soundness (g:stt_env) (t:st_term) (c:comp) (d:st_typing g t c{T_Equiv? d}) (soundness:soundness_t d) : GTot (RT.tot_typing (elab_env g) (elab_st_typing d) (elab_comp c)) = let T_Equiv _ e c c' e_typing equiv = d in LN.st_typing_ln d; LN.st_typing_ln e_typing; let r_e_typing = soundness _ _ _ e_typing in match equiv with | ST_TotEquiv _ t1 t2 _ _ eq -> let r_e_typing : RT.tot_typing (elab_env g) (elab_st_typing e_typing) (elab_term t1) = r_e_typing in let eq = RT.Rel_equiv _ _ _ RT.R_Sub eq in RT.T_Sub _ _ _ _ r_e_typing (RT.Relc_typ _ _ _ _ _ eq) | _ -> STEquiv.st_equiv_soundness _ _ _ equiv _ r_e_typing #push-options "--query_stats --fuel 2 --ifuel 2 --z3rlimit_factor 30" let bind_soundness (#g:stt_env) (#t:st_term) (#c:comp) (d:st_typing g t c{T_Bind? d}) (soundness: soundness_t d) (mk_t_abs: tabs_t d) : GTot (RT.tot_typing (elab_env g) (elab_st_typing d) (elab_comp c)) = let T_Bind _ e1 e2 c1 c2 _ x c e1_typing t_typing e2_typing bc = d in LN.st_typing_ln e1_typing; LN.st_typing_ln e2_typing; FV.st_typing_freevars_inv e1_typing x; let r1_typing : RT.tot_typing _ _ (elab_comp c1) = soundness _ _ _ e1_typing in let r2_typing : RT.tot_typing _ _ (elab_term (tm_arrow (null_binder (comp_res c1)) None (close_comp c2 x))) = mk_t_abs None _ t_typing e2_typing in match bc with | Bind_comp _ _ _ _ t2_typing y post2_typing -> Bind.elab_bind_typing g _ _ _ x _ r1_typing _ r2_typing bc (tot_typing_soundness t2_typing) (mk_t_abs_tot _ ppname_default t2_typing post2_typing) #pop-options #push-options "--z3rlimit_factor 4 --fuel 4 --ifuel 2" let if_soundness (g:stt_env) (t:st_term) (c:comp) (d:st_typing g t c{T_If? d}) (soundness:soundness_t d) (ct_soundness: (g:stt_env -> c:comp -> uc:universe -> d':comp_typing g c uc{d' << d} -> GTot (RT.tot_typing (elab_env g) (elab_comp c) (RT.tm_type uc)))) : GTot (RT.tot_typing (elab_env g) (elab_st_typing d) (elab_comp c)) = let T_If _ b e1 e2 _ hyp b_typing e1_typing e2_typing (E c_typing) = d in let rb_typing : RT.tot_typing (elab_env g) (elab_term b) RT.bool_ty = tot_typing_soundness b_typing in let g_then = push_binding g hyp ppname_default (mk_eq2 u0 tm_bool b tm_true) in elab_push_binding g hyp (mk_eq2 u0 tm_bool b tm_true); let re1_typing : RT.tot_typing (RT.extend_env (elab_env g) hyp (RT.eq2 (R.pack_universe R.Uv_Zero) RT.bool_ty (elab_term b) RT.true_bool)) (elab_st_typing e1_typing) (elab_comp c) = soundness g_then e1 c e1_typing in let g_else = push_binding g hyp ppname_default (mk_eq2 u0 tm_bool b tm_false) in elab_push_binding g hyp (mk_eq2 u0 tm_bool b tm_false); let re2_typing : RT.tot_typing (RT.extend_env (elab_env g) hyp (RT.eq2 (R.pack_universe R.Uv_Zero) RT.bool_ty (elab_term b) RT.false_bool)) (elab_st_typing e2_typing) (elab_comp c) = soundness g_else e2 c e2_typing in let c_typing = ct_soundness _ _ _ c_typing in assume (~(hyp `Set.mem` RT.freevars (elab_st_typing e1_typing))); assume (~(hyp `Set.mem` RT.freevars (elab_st_typing e2_typing))); RT.T_If _ _ _ _ _ _ _ _ _ rb_typing re1_typing re2_typing c_typing #pop-options #push-options "--query_stats --fuel 2 --ifuel 2" let rec soundness (g:stt_env) (t:st_term) (c:comp) (d:st_typing g t c) : GTot (RT.tot_typing (elab_env g) (elab_st_typing d) (elab_comp c)) (decreases d) = let mk_t_abs (#g:stt_env) (#u:universe) (#ty:term) (q:option qualifier) (ppname:ppname) (t_typing:tot_typing g ty (tm_type u) { t_typing << d }) (#body:st_term) (#x:var { None? (lookup g x) /\ ~(x `Set.mem` freevars_st body) }) (#c:comp) (body_typing:st_typing (push_binding g x ppname ty) (open_st_term body x) c { body_typing << d }) : GTot (RT.tot_typing (elab_env g) (mk_abs_with_name ppname.name (elab_term ty) (elab_qual q) (RT.close_term (elab_st_typing body_typing) x)) (elab_term (tm_arrow (mk_binder_ppname ty ppname) q (close_comp c x)))) = let r_t_typing = tot_typing_soundness t_typing in let r_body_typing = soundness _ _ _ body_typing in mk_t_abs g #_ #_ #_ #t_typing ppname r_t_typing r_body_typing in LN.st_typing_ln d; match d with | T_Lift _ _ _ _ _ _ -> lift_soundness _ _ _ d soundness | T_Frame _ _ _ _ _ _ -> frame_soundness _ _ _ d soundness | T_Abs _ x q ty u body c t_typing body_typing -> mk_t_abs q ppname_default t_typing body_typing | T_STApp _ _ _ _ _ _ _ _ -> stapp_soundness _ _ _ d soundness | T_STGhostApp _ _ _ _ _ _ _ _ _ _ -> stghostapp_soundness _ _ _ d soundness | T_Bind _ _e1 _e2 _c1 _c2 _b _x _c _e1_typing _t_typing _e2_typing _bc -> bind_soundness d soundness mk_t_abs | T_BindFn _ _ _ _ _ _ _ _ _ _ _ _ -> Bind.bind_fn_typing d soundness | T_Equiv _ _ _ _ _ _ -> stequiv_soundness _ _ _ d soundness | T_Return _ _ _ _ _ _ _ _ _ _ _ -> Return.return_soundness d | T_If _ _ _ _ _ _ _ _ _ _-> let ct_soundness g c uc (d':_ {d' << d}) = Comp.comp_typing_soundness g c uc d' in if_soundness _ _ _ d soundness ct_soundness | T_Match _ _ _ _ _ _ _ _ _ _ _ -> let ct_soundness g c uc (d':_ {d' << d}) = Comp.comp_typing_soundness g c uc d' in Pulse.Soundness.Match.match_soundness _ _ _ d soundness ct_soundness | T_IntroPure _ _ _ _ -> admit() | T_ElimExists _ _ _ _ _ _ _ -> Exists.elim_exists_soundness d | T_IntroExists _ _ _ _ _ _ _ _ -> Exists.intro_exists_soundness d | T_While _ _ _ _ _ _ _ -> While.while_soundness d soundness | T_Par _ _ _ _ _ _ _ _ _ _ -> Par.par_soundness d soundness | T_WithLocal _ _ _ _ _ _ _ _ _ _ _ -> WithLocal.withlocal_soundness d soundness | T_WithLocalArray _ _ _ _ _ _ _ _ _ _ _ _ _ -> WithLocalArray.withlocalarray_soundness d soundness | T_Rewrite _ _ _ _ _ -> Rewrite.rewrite_soundness d | T_Admit _ _ _ _ -> Admit.admit_soundess d | T_Unreachable _ _ _ _ _ -> RU.magic() | T_Sub _ _ _ _ _ _ -> Sub.sub_soundness d soundness | T_WithInv _ _ _ _ _ _ _ _ _ -> RU.magic() // IOU #pop-options
{ "checked_file": "/", "dependencies": [ "Pulse.Typing.LN.fsti.checked", "Pulse.Typing.FV.fsti.checked", "Pulse.Typing.fst.checked", "Pulse.Syntax.fst.checked", "Pulse.Steel.Wrapper.Typing.fsti.checked", "Pulse.Soundness.WithLocalArray.fsti.checked", "Pulse.Soundness.WithLocal.fsti.checked", "Pulse.Soundness.While.fsti.checked", "Pulse.Soundness.Sub.fsti.checked", "Pulse.Soundness.STT.fsti.checked", "Pulse.Soundness.STEquiv.fsti.checked", "Pulse.Soundness.Rewrite.fsti.checked", "Pulse.Soundness.Return.fsti.checked", "Pulse.Soundness.Par.fsti.checked", "Pulse.Soundness.Match.fsti.checked", "Pulse.Soundness.Lift.fsti.checked", "Pulse.Soundness.Frame.fsti.checked", "Pulse.Soundness.Exists.fsti.checked", "Pulse.Soundness.Comp.fsti.checked", "Pulse.Soundness.Common.fst.checked", "Pulse.Soundness.Bind.fsti.checked", "Pulse.Soundness.Admit.fsti.checked", "Pulse.RuntimeUtils.fsti.checked", "Pulse.Reflection.Util.fst.checked", "Pulse.Elaborate.Pure.fst.checked", "Pulse.Elaborate.fsti.checked", "prims.fst.checked", "FStar.Tactics.V2.fst.checked", "FStar.Squash.fsti.checked", "FStar.Set.fsti.checked", "FStar.Reflection.V2.fst.checked", "FStar.Reflection.Typing.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked" ], "interface_file": true, "source_file": "Pulse.Soundness.fst" }
[ { "abbrev": true, "full_module": "Pulse.Steel.Wrapper.Typing", "short_module": "WT" }, { "abbrev": true, "full_module": "Pulse.Elaborate.Pure", "short_module": "EPure" }, { "abbrev": true, "full_module": "Pulse.Typing", "short_module": "Typing" }, { "abbrev": true, "full_module": "Pulse.RuntimeUtils", "short_module": "RU" }, { "abbrev": true, "full_module": "Pulse.Soundness.Sub", "short_module": "Sub" }, { "abbrev": true, "full_module": "Pulse.Soundness.STT", "short_module": "STT" }, { "abbrev": true, "full_module": "Pulse.Typing.FV", "short_module": "FV" }, { "abbrev": true, "full_module": "Pulse.Typing.LN", "short_module": "LN" }, { "abbrev": true, "full_module": "Pulse.Soundness.Comp", "short_module": "Comp" }, { "abbrev": true, "full_module": "Pulse.Soundness.Rewrite", "short_module": "Rewrite" }, { "abbrev": true, "full_module": "Pulse.Soundness.WithLocalArray", "short_module": "WithLocalArray" }, { "abbrev": true, "full_module": "Pulse.Soundness.WithLocal", "short_module": "WithLocal" }, { "abbrev": true, "full_module": "Pulse.Soundness.Par", "short_module": "Par" }, { "abbrev": true, "full_module": "Pulse.Soundness.Admit", "short_module": "Admit" }, { "abbrev": true, "full_module": "Pulse.Soundness.While", "short_module": "While" }, { "abbrev": true, "full_module": "Pulse.Soundness.Exists", "short_module": "Exists" }, { "abbrev": true, "full_module": "Pulse.Soundness.Return", "short_module": "Return" }, { "abbrev": true, "full_module": "Pulse.Soundness.STEquiv", "short_module": "STEquiv" }, { "abbrev": true, "full_module": "Pulse.Soundness.Frame", "short_module": "Frame" }, { "abbrev": true, "full_module": "Pulse.Soundness.Lift", "short_module": "Lift" }, { "abbrev": true, "full_module": "Pulse.Soundness.Bind", "short_module": "Bind" }, { "abbrev": false, "full_module": "Pulse.Soundness.Common", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Elaborate", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Typing", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Reflection.Util", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Syntax", "short_module": null }, { "abbrev": false, "full_module": "FStar.List.Tot", "short_module": null }, { "abbrev": true, "full_module": "FStar.Tactics.V2", "short_module": "T" }, { "abbrev": true, "full_module": "FStar.List.Tot", "short_module": "L" }, { "abbrev": true, "full_module": "FStar.Reflection.V2", "short_module": "R" }, { "abbrev": true, "full_module": "FStar.Reflection.Typing", "short_module": "RT" }, { "abbrev": false, "full_module": "Pulse", "short_module": null }, { "abbrev": false, "full_module": "Pulse", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
g: Pulse.Soundness.Common.stt_env -> t: Pulse.Syntax.Base.st_term -> c: Pulse.Syntax.Base.comp -> d: Pulse.Typing.st_typing g t c -> FStar.Pervasives.Lemma (ensures FStar.Reflection.Typing.tot_typing (Pulse.Typing.elab_env g) (Pulse.Elaborate.Core.elab_st_typing d) (Pulse.Elaborate.Pure.elab_comp c))
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "Pulse.Soundness.Common.stt_env", "Pulse.Syntax.Base.st_term", "Pulse.Syntax.Base.comp", "Pulse.Typing.st_typing", "FStar.Squash.bind_squash", "FStar.Reflection.Typing.tot_typing", "Pulse.Typing.elab_env", "Pulse.Elaborate.Core.elab_st_typing", "Pulse.Elaborate.Pure.elab_comp", "FStar.Squash.return_squash", "Pulse.Soundness.soundness", "Prims.squash", "Prims.unit", "Prims.l_True", "Prims.Nil", "FStar.Pervasives.pattern" ]
[]
false
false
true
false
false
let soundness_lemma (g: stt_env) (t: st_term) (c: comp) (d: st_typing g t c) : Lemma (ensures RT.tot_typing (elab_env g) (elab_st_typing d) (elab_comp c)) =
FStar.Squash.bind_squash #(st_typing g t c) () (fun dd -> FStar.Squash.return_squash (soundness g t c d))
false
Hacl.Spec.Bignum.MontArithmetic.fst
Hacl.Spec.Bignum.MontArithmetic.bn_field_inv
val bn_field_inv: #t:limb_t -> k:bn_mont_ctx t{bn_mont_ctx_inv k} -> aM:bn_mont_nat k -> Pure (bn_mont_nat k) (requires 0 < bn_v aM /\ Euclid.is_prime (bn_v k.n)) (ensures fun aInvM -> bn_v (bn_from_field k aInvM) * bn_v (bn_from_field k aM) % bn_v k.n == 1)
val bn_field_inv: #t:limb_t -> k:bn_mont_ctx t{bn_mont_ctx_inv k} -> aM:bn_mont_nat k -> Pure (bn_mont_nat k) (requires 0 < bn_v aM /\ Euclid.is_prime (bn_v k.n)) (ensures fun aInvM -> bn_v (bn_from_field k aInvM) * bn_v (bn_from_field k aM) % bn_v k.n == 1)
let bn_field_inv #t k aM = let n2 = BI.bn_mod_inv_prime_n2 k.n in assert (bn_v n2 == bn_v k.n - 2); let aInvM = bn_field_exp_vartime #t k aM (k.len * bits t) n2 in assert (bn_v (bn_from_field k aInvM) == Lib.NatMod.pow_mod #(bn_v k.n) (bn_v (bn_from_field k aM)) (bn_v n2)); from_mont_lemma_nonzero (bits t) k.len (bn_v k.n) (v k.mu) (bn_v aM); assert (0 < bn_v (bn_from_field k aM)); BI.mod_inv_prime_lemma (bn_v k.n) (bn_v (bn_from_field k aM)); aInvM
{ "file_name": "code/bignum/Hacl.Spec.Bignum.MontArithmetic.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 7, "end_line": 173, "start_col": 0, "start_line": 165 }
module Hacl.Spec.Bignum.MontArithmetic open FStar.Mul open Lib.IntTypes open Lib.Sequence open Hacl.Spec.Bignum.Definitions module M = Hacl.Spec.Montgomery.Lemmas module BM = Hacl.Spec.Bignum.Montgomery module BN = Hacl.Spec.Bignum module BB = Hacl.Spec.Bignum.Base module BL = Hacl.Spec.Bignum.Lib module BIL = Hacl.Spec.Bignum.ModInvLimb module E = Hacl.Spec.Exponentiation.Lemmas module ME = Hacl.Spec.Bignum.MontExponentiation module Euclid = FStar.Math.Euclid module BI = Hacl.Spec.Bignum.ModInv #set-options "--z3rlimit 50 --fuel 0 --ifuel 0" ////////////////////////////////////////// val mul_zero_lemma: n:pos{Euclid.is_prime n} -> x:int -> y:int -> Lemma (x * y % n == 0 <==> (x % n == 0 \/ y % n == 0)) let mul_zero_lemma n x y = assert (0 % n = 0); if x % n = 0 then Math.Lemmas.lemma_mod_mul_distr_l x y n else if y % n = 0 then Math.Lemmas.lemma_mod_mul_distr_r x y n else if x * y % n = 0 then Math.Fermat.mod_mult_congr n x 0 y else () val mul_nonzero_lemma: n:pos{Euclid.is_prime n} -> x:int -> y:int -> Lemma (requires x % n <> 0 /\ y % n <> 0) (ensures x * y % n <> 0) let mul_nonzero_lemma n x y = mul_zero_lemma n x y val from_mont_lemma_nonzero: pbits:pos -> rLen:pos -> n:pos -> mu:nat -> aM:nat -> Lemma (requires M.mont_pre pbits rLen n mu /\ 0 < aM /\ aM < n /\ Euclid.is_prime n) (ensures (let a = M.from_mont pbits rLen n mu aM in 0 < a /\ a < n)) let from_mont_lemma_nonzero pbits rLen n mu aM = let r = pow2 (pbits * rLen) in let d, _ = M.eea_pow2_odd (pbits * rLen) n in let a = M.from_mont pbits rLen n mu aM in M.from_mont_lemma pbits rLen n mu aM; assert (a == aM * d % n); assert (d <> 0); Math.Lemmas.small_mod aM n; assert (aM % n <> 0); let d1 = -d in assert (0 < d1 /\ d1 < n); Math.Lemmas.lemma_mod_sub_1 d1 n; assert ((-d1) % n == n - (d1 % n)); assert (d % n <> 0); mul_nonzero_lemma n aM d; assert (let a = M.from_mont pbits rLen n mu aM in 0 < a /\ a < n); // For some reason, this makes the proof instant. () /////////////////////////////////////////////// let bn_field_get_len #t k = k.len let bn_field_check_modulus #t #len n = let m = BM.bn_check_modulus n in BB.unsafe_bool_of_limb m let bn_field_init #t #len n = let nBits = bits t * BL.bn_get_top_index n in BL.bn_low_bound_bits_lemma n; BM.bn_precomp_r2_mod_n_lemma nBits n; let r2 = BM.bn_precomp_r2_mod_n nBits n in assert (bn_v r2 == pow2 (2 * bits t * len) % bn_v n); let mu = BIL.mod_inv_limb n.[0] in BIL.bn_mod_inv_limb_lemma n; assert ((1 + bn_v n * v mu) % pow2 (bits t) == 0); bn_eval_bound n len; { len = len; n = n; mu = mu; r2 = r2 } let bn_to_field #t k a = BM.bn_to_mont_lemma k.n k.mu k.r2 a; BM.bn_to_mont k.n k.mu k.r2 a let bn_from_field #t k aM = BM.bn_from_mont_lemma k.n k.mu aM; BM.bn_from_mont k.n k.mu aM let bn_from_to_field_lemma #t k a = bn_eval_bound a k.len; M.from_to_mont_lemma (bits t) k.len (bn_v k.n) (v k.mu) (bn_v a) let bn_field_add #t k aM bM = BN.bn_add_mod_n_lemma k.n aM bM; M.from_mont_add_lemma (bits t) k.len (bn_v k.n) (v k.mu) (bn_v aM) (bn_v bM); BN.bn_add_mod_n k.n aM bM let bn_field_sub #t k aM bM = BN.bn_sub_mod_n_lemma k.n aM bM; M.from_mont_sub_lemma (bits t) k.len (bn_v k.n) (v k.mu) (bn_v aM) (bn_v bM); BN.bn_sub_mod_n k.n aM bM let bn_field_mul #t k aM bM = BM.bn_mont_mul_lemma k.n k.mu aM bM; M.from_mont_mul_lemma (bits t) k.len (bn_v k.n) (v k.mu) (bn_v aM) (bn_v bM); BM.bn_mont_mul k.n k.mu aM bM let bn_field_sqr #t k aM = BM.bn_mont_sqr_lemma k.n k.mu aM; M.from_mont_mul_lemma (bits t) k.len (bn_v k.n) (v k.mu) (bn_v aM) (bn_v aM); BM.bn_mont_sqr k.n k.mu aM let bn_field_one #t k = BM.bn_mont_one_lemma k.n k.mu k.r2; M.from_mont_one_lemma (bits t) k.len (bn_v k.n) (v k.mu); BM.bn_mont_one k.n k.mu r2 let bn_field_exp_consttime #t k aM bBits b = E.from_mont_exp_lemma (bits t) k.len (bn_v k.n) (v k.mu) (bn_v aM) (bn_v b); ME.bn_exp_mont_consttime k.n k.mu aM bBits b let bn_field_exp_vartime #t k aM bBits b = E.from_mont_exp_lemma (bits t) k.len (bn_v k.n) (v k.mu) (bn_v aM) (bn_v b); ME.bn_exp_mont_vartime k.n k.mu aM bBits b
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "Lib.Sequence.fsti.checked", "Lib.NatMod.fsti.checked", "Lib.IntTypes.fsti.checked", "Hacl.Spec.Montgomery.Lemmas.fst.checked", "Hacl.Spec.Exponentiation.Lemmas.fst.checked", "Hacl.Spec.Bignum.Montgomery.fsti.checked", "Hacl.Spec.Bignum.MontExponentiation.fst.checked", "Hacl.Spec.Bignum.ModInvLimb.fsti.checked", "Hacl.Spec.Bignum.ModInv.fst.checked", "Hacl.Spec.Bignum.Lib.fst.checked", "Hacl.Spec.Bignum.Definitions.fst.checked", "Hacl.Spec.Bignum.Base.fst.checked", "Hacl.Spec.Bignum.fsti.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.Math.Fermat.fsti.checked", "FStar.Math.Euclid.fsti.checked" ], "interface_file": true, "source_file": "Hacl.Spec.Bignum.MontArithmetic.fst" }
[ { "abbrev": true, "full_module": "Hacl.Spec.Bignum.ModInv", "short_module": "BI" }, { "abbrev": true, "full_module": "Hacl.Spec.Bignum.MontExponentiation", "short_module": "ME" }, { "abbrev": true, "full_module": "Hacl.Spec.Exponentiation.Lemmas", "short_module": "E" }, { "abbrev": true, "full_module": "Hacl.Spec.Bignum.ModInvLimb", "short_module": "BIL" }, { "abbrev": true, "full_module": "Hacl.Spec.Bignum.Lib", "short_module": "BL" }, { "abbrev": true, "full_module": "Hacl.Spec.Bignum.Base", "short_module": "BB" }, { "abbrev": true, "full_module": "Hacl.Spec.Bignum.Montgomery", "short_module": "BM" }, { "abbrev": true, "full_module": "Hacl.Spec.Bignum", "short_module": "BN" }, { "abbrev": true, "full_module": "Hacl.Spec.Montgomery.Lemmas", "short_module": "M" }, { "abbrev": true, "full_module": "FStar.Math.Euclid", "short_module": "Euclid" }, { "abbrev": false, "full_module": "Hacl.Spec.Bignum.Definitions", "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.Bignum", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.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 } ]
{ "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" }
false
k: Hacl.Spec.Bignum.MontArithmetic.bn_mont_ctx t {Hacl.Spec.Bignum.MontArithmetic.bn_mont_ctx_inv k} -> aM: Hacl.Spec.Bignum.MontArithmetic.bn_mont_nat k -> Prims.Pure (Hacl.Spec.Bignum.MontArithmetic.bn_mont_nat k)
Prims.Pure
[]
[]
[ "Hacl.Spec.Bignum.Definitions.limb_t", "Hacl.Spec.Bignum.MontArithmetic.bn_mont_ctx", "Hacl.Spec.Bignum.MontArithmetic.bn_mont_ctx_inv", "Hacl.Spec.Bignum.MontArithmetic.bn_mont_nat", "Prims.unit", "Hacl.Spec.Bignum.ModInv.mod_inv_prime_lemma", "Hacl.Spec.Bignum.Definitions.bn_v", "Hacl.Spec.Bignum.MontArithmetic.__proj__Mkbn_mont_ctx__item__len", "Hacl.Spec.Bignum.MontArithmetic.__proj__Mkbn_mont_ctx__item__n", "Hacl.Spec.Bignum.MontArithmetic.bn_from_field", "Prims._assert", "Prims.b2t", "Prims.op_LessThan", "Hacl.Spec.Bignum.MontArithmetic.from_mont_lemma_nonzero", "Lib.IntTypes.bits", "Lib.IntTypes.v", "Lib.IntTypes.SEC", "Hacl.Spec.Bignum.MontArithmetic.__proj__Mkbn_mont_ctx__item__mu", "Prims.eq2", "Prims.nat", "Lib.NatMod.pow_mod", "Hacl.Spec.Bignum.MontArithmetic.bn_field_exp_vartime", "FStar.Mul.op_Star", "Prims.int", "Prims.op_Subtraction", "Hacl.Spec.Bignum.Definitions.lbignum", "Hacl.Spec.Bignum.ModInv.bn_mod_inv_prime_n2" ]
[]
false
false
false
false
false
let bn_field_inv #t k aM =
let n2 = BI.bn_mod_inv_prime_n2 k.n in assert (bn_v n2 == bn_v k.n - 2); let aInvM = bn_field_exp_vartime #t k aM (k.len * bits t) n2 in assert (bn_v (bn_from_field k aInvM) == Lib.NatMod.pow_mod #(bn_v k.n) (bn_v (bn_from_field k aM)) (bn_v n2)); from_mont_lemma_nonzero (bits t) k.len (bn_v k.n) (v k.mu) (bn_v aM); assert (0 < bn_v (bn_from_field k aM)); BI.mod_inv_prime_lemma (bn_v k.n) (bn_v (bn_from_field k aM)); aInvM
false
Vale.AsLowStar.Test.fst
Vale.AsLowStar.Test.ta_lemma
val ta_lemma : Vale.AsLowStar.ValeSig.vale_sig_stdcall Vale.AsLowStar.Test.ta_pre Vale.AsLowStar.Test.ta_post
let ta_lemma = as_t #(VSig.vale_sig_stdcall ta_pre ta_post) ta_lemma'
{ "file_name": "vale/code/arch/x64/interop/Vale.AsLowStar.Test.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 69, "end_line": 373, "start_col": 0, "start_line": 373 }
module Vale.AsLowStar.Test open FStar.Mul open Vale.Interop.Base module ME = Vale.X64.Memory module IA = Vale.Interop.Assumptions module V = Vale.X64.Decls module IX64 = Vale.Interop.X64 module VSig = Vale.AsLowStar.ValeSig module LSig = Vale.AsLowStar.LowStarSig module W = Vale.AsLowStar.Wrapper module VS = Vale.X64.State module MS = Vale.X64.Machine_s (* A little utility to trigger normalization in types *) let as_t (#a:Type) (x:normal a) : a = x let as_normal_t (#a:Type) (x:a) : normal a = x //////////////////////////////////////////////////////////////////////////////// //First a little standalone, toy experiment [@__reduce__] let b64 = buf_t TUInt8 TUInt64 [@__reduce__] let ib64 = ibuf_t TUInt8 TUInt64 [@__reduce__] let t64_mod = TD_Buffer TUInt8 TUInt64 default_bq [@__reduce__] let t64_no_mod = TD_Buffer TUInt8 TUInt64 ({modified=false; strict_disjointness=false; taint=MS.Secret}) [@__reduce__] let t64_imm = TD_ImmBuffer TUInt8 TUInt64 ({modified=false; strict_disjointness=false; taint=MS.Secret}) [@__reduce__] let (dom : list td{List.length dom <= 20}) = let y = [t64_mod;t64_imm] in assert_norm (List.length y = 2); y assume val pre : VSig.vale_pre dom assume val post : VSig.vale_post dom assume val v: VSig.vale_sig_stdcall pre post assume val c: V.va_code [@__reduce__] let call_c_t = IX64.as_lowstar_sig_t_weak_stdcall c dom [] _ _ (W.mk_prediction c dom [] (v c IA.win)) let call_c : call_c_t = IX64.wrap_weak_stdcall c dom (W.mk_prediction c dom [] (v c IA.win)) let call_c_normal_t : normal call_c_t = as_normal_t #call_c_t call_c //You can ask emacs to show you the type of call_c_normal_t ... //////////////////////////////////////////////////////////////////////////////// //Now memcpy module VM = Vale.Test.X64.Vale_memcpy [@__reduce__] let vm_dom = [t64_mod; t64_imm] open Vale.X64.MemoryAdapters (* Need to rearrange the order of arguments *) [@__reduce__] let vm_pre : VSig.vale_pre vm_dom = fun (c:V.va_code) (dst:b64) (src:ib64) (va_s0:V.va_state) -> VM.va_req_Memcpy c va_s0 IA.win (as_vale_buffer dst) (as_vale_immbuffer src) [@__reduce__] let vm_post : VSig.vale_post vm_dom = fun (c:V.va_code) (dst:b64) (src:ib64) (va_s0:V.va_state) (va_s1:V.va_state) (f:V.va_fuel) -> VM.va_ens_Memcpy c va_s0 IA.win (as_vale_buffer dst) (as_vale_immbuffer src) va_s1 f module VS = Vale.X64.State #reset-options "--print_effect_args --z3rlimit 200" (* The vale lemma doesn't quite suffice to prove the modifies clause expected of the interop layer *) [@__reduce__] let vm_lemma' (code:V.va_code) (_win:bool) (dst:b64) (src:ib64) (va_s0:V.va_state) : Ghost (V.va_state & V.va_fuel) (requires vm_pre code dst src va_s0) (ensures (fun (va_s1, f) -> V.eval_code code va_s0 f va_s1 /\ VSig.vale_calling_conventions_stdcall va_s0 va_s1 /\ vm_post code dst src va_s0 va_s1 f /\ ME.buffer_readable (VS.vs_get_vale_heap va_s1) (as_vale_immbuffer src) /\ ME.buffer_readable (VS.vs_get_vale_heap va_s1) (as_vale_buffer dst) /\ ME.buffer_writeable (as_vale_buffer dst) /\ ME.modifies (ME.loc_union (ME.loc_buffer (as_vale_buffer dst)) ME.loc_none) (VS.vs_get_vale_heap va_s0) (VS.vs_get_vale_heap va_s1) )) = let va_s1, f = VM.va_lemma_Memcpy code va_s0 IA.win (as_vale_buffer dst) (as_vale_immbuffer src) in Vale.AsLowStar.MemoryHelpers.buffer_writeable_reveal ME.TUInt8 ME.TUInt64 dst; (va_s1, f) (* Prove that vm_lemma' has the required type *) let vm_lemma = as_t #(VSig.vale_sig_stdcall vm_pre vm_post) vm_lemma' let code_Memcpy = VM.va_code_Memcpy IA.win (* Here's the type expected for the memcpy wrapper *) [@__reduce__] let lowstar_Memcpy_t = IX64.as_lowstar_sig_t_weak_stdcall code_Memcpy vm_dom [] _ _ (W.mk_prediction code_Memcpy vm_dom [] (vm_lemma code_Memcpy IA.win)) (* And here's the memcpy wrapper itself *) let lowstar_Memcpy : lowstar_Memcpy_t = IX64.wrap_weak_stdcall code_Memcpy vm_dom (W.mk_prediction code_Memcpy vm_dom [] (vm_lemma code_Memcpy IA.win)) let lowstar_Memcpy_normal_t //: normal lowstar_Memcpy_t = as_normal_t #lowstar_Memcpy_t lowstar_Memcpy module B = LowStar.Buffer module IB = LowStar.ImmutableBuffer module MB = LowStar.Monotonic.Buffer open FStar.HyperStack.ST module M = Vale.X64.Memory let test (x:b64) = assert (V.buffer_length (as_vale_buffer x) == (B.length x * view_n TUInt8) / view_n TUInt64); assert (V.buffer_length (as_vale_buffer x) == B.length x / 8) let itest (x:ib64) = assert (V.buffer_length (as_vale_immbuffer x) == (B.length x * view_n TUInt8) / view_n TUInt64); assert (V.buffer_length (as_vale_immbuffer x) == B.length x / 8) module T = FStar.Tactics #reset-options "--using_facts_from '* -FStar.Tactics -FStar.Reflection'" module LBV = LowStar.BufferView.Up module DV = LowStar.BufferView.Down #push-options "--ext compat:normalizer_memo_ignore_cfg" let memcpy_Test (dst:B.buffer UInt8.t{B.length dst % 8 == 0}) (src:IB.ibuffer UInt8.t{B.length src % 8 == 0}) : Stack UInt64.t (requires fun h0 -> B.live h0 dst /\ B.live h0 src /\ B.disjoint dst src /\ B.length dst == 16 /\ B.length src == 16) (ensures fun h0 _ h1 -> B.modifies (B.loc_buffer dst) h0 h1 /\ B.live h1 src /\ B.live h1 dst) // B.as_seq h1 dst == B.as_seq h1 src) // by (T.dump "A") (* in case you want to look at the VC *) = IB.inhabited_immutable_buffer_is_distinct_from_buffer (UInt8.uint_to_t 0) src dst; let (x, _) = lowstar_Memcpy_normal_t dst src () in //This is a call to the interop wrapper let h1 = get () in // let v = Vale.Interop.Views.up_view64 in // assert (DV.length_eq (get_downview dst); // DV.length_eq (get_downview src); // Seq.equal (LBV.as_seq h1 (LBV.mk_buffer (get_downview dst) v)) // (LBV.as_seq h1 (LBV.mk_buffer (get_downview src) v))); // lbv_as_seq_eq dst src Vale.Interop.Views.up_view64 h1; //And a lemma to rephrase the Vale postcondition x //with equalities of buffer views //back to equalities of buffers #pop-options module VC = Vale.Lib.X64.Cpuidstdcall [@__reduce__] let empty_list #a : l:list a {List.length l = 0} = [] [@__reduce__] let aesni_dom : IX64.arity_ok_stdcall td = [] (* Need to rearrange the order of arguments *) [@__reduce__] let aesni_pre : VSig.vale_pre aesni_dom = fun (c:V.va_code) (va_s0:V.va_state) -> VC.va_req_Check_aesni_stdcall c va_s0 IA.win [@__reduce__] let aesni_post : VSig.vale_post aesni_dom = fun (c:V.va_code) (va_s0:V.va_state) (va_s1:V.va_state) (f:V.va_fuel) -> VC.va_ens_Check_aesni_stdcall c va_s0 IA.win va_s1 f [@__reduce__] let with_len (l:list 'a) : Pure (list 'a) (requires True) (ensures fun m -> m==l /\ List.length m == normalize_term (List.length l)) = l #set-options "--max_fuel 0 --max_ifuel 1 --z3rlimit_factor 2" (* The vale lemma doesn't quite suffice to prove the modifies clause expected of the interop layer *) [@__reduce__] let aesni_lemma' (code:V.va_code) (_win:bool) (va_s0:V.va_state) : Ghost (V.va_state & V.va_fuel) (requires aesni_pre code va_s0) (ensures (fun (va_s1, f) -> V.eval_code code va_s0 f va_s1 /\ VSig.vale_calling_conventions_stdcall va_s0 va_s1 /\ aesni_post code va_s0 va_s1 f)) = VC.va_lemma_Check_aesni_stdcall code va_s0 IA.win #set-options "--max_fuel 0 --max_ifuel 0 --z3rlimit_factor 2" (* Prove that vm_lemma' has the required type *) let aesni_lemma = as_t #(VSig.vale_sig_stdcall aesni_pre aesni_post) aesni_lemma' let code_aesni = VC.va_code_Check_aesni_stdcall IA.win (* Here's the type expected for the check_aesni wrapper *) [@__reduce__] let lowstar_aesni_t = IX64.as_lowstar_sig_t_weak_stdcall (coerce code_aesni) aesni_dom empty_list _ _ (W.mk_prediction code_aesni aesni_dom [] (aesni_lemma code_aesni IA.win)) (* And here's the check_aesni wrapper itself *) let lowstar_aesni : lowstar_aesni_t = IX64.wrap_weak_stdcall (coerce code_aesni) aesni_dom (W.mk_prediction code_aesni aesni_dom [] (aesni_lemma code_aesni IA.win)) let lowstar_aesni_normal_t //: normal lowstar_aesni_t = as_normal_t #lowstar_aesni_t lowstar_aesni open Vale.X64.CPU_Features_s #set-options "--print_full_names" let aesni_Test () : Stack UInt64.t (requires fun h0 -> True) (ensures fun h0 ret_val h1 -> (UInt64.v ret_val) =!= 0 ==> aesni_enabled /\ pclmulqdq_enabled) // by (T.dump "A") (* in case you want to look at the VC *) = let (x, _) = lowstar_aesni_normal_t () in //This is a call to the interop wrapper x module TA = Vale.Test.X64.Args [@__reduce__] let (ta_dom:list td{List.length ta_dom <= 20}) = let y = [t64_imm; t64_imm; t64_imm; t64_imm; t64_imm; t64_imm; t64_imm; t64_imm] in assert_norm (List.length y = 8); y (* Need to rearrange the order of arguments *) [@__reduce__] let ta_pre : VSig.vale_pre ta_dom = fun (c:V.va_code) (arg0:ib64) (arg1:ib64) (arg2:ib64) (arg3:ib64) (arg4:ib64) (arg5:ib64) (arg6:ib64) (arg7:ib64) (va_s0:V.va_state) -> TA.va_req_Test c va_s0 IA.win (as_vale_immbuffer arg0) (as_vale_immbuffer arg1) (as_vale_immbuffer arg2) (as_vale_immbuffer arg3) (as_vale_immbuffer arg4) (as_vale_immbuffer arg5) (as_vale_immbuffer arg6) (as_vale_immbuffer arg7) [@__reduce__] let ta_post : VSig.vale_post ta_dom = fun (c:V.va_code) (arg0:ib64) (arg1:ib64) (arg2:ib64) (arg3:ib64) (arg4:ib64) (arg5:ib64) (arg6:ib64) (arg7:ib64) (va_s0:V.va_state) (va_s1:V.va_state) (f:V.va_fuel) -> TA.va_ens_Test c va_s0 IA.win (as_vale_immbuffer arg0) (as_vale_immbuffer arg1) (as_vale_immbuffer arg2) (as_vale_immbuffer arg3) (as_vale_immbuffer arg4) (as_vale_immbuffer arg5) (as_vale_immbuffer arg6) (as_vale_immbuffer arg7) va_s1 f #reset-options "--max_fuel 0 --max_ifuel 0 --z3rlimit 100" (* The vale lemma doesn't quite suffice to prove the modifies clause expected of the interop layer *) [@__reduce__] let ta_lemma' (code:V.va_code) (_win:bool) (arg0:ib64) (arg1:ib64) (arg2:ib64) (arg3:ib64) (arg4:ib64) (arg5:ib64) (arg6:ib64) (arg7:ib64) (va_s0:V.va_state) : Ghost (V.va_state & V.va_fuel) (requires ta_pre code arg0 arg1 arg2 arg3 arg4 arg5 arg6 arg7 va_s0) (ensures (fun (va_s1, f) -> V.eval_code code va_s0 f va_s1 /\ VSig.vale_calling_conventions_stdcall va_s0 va_s1 /\ ta_post code arg0 arg1 arg2 arg3 arg4 arg5 arg6 arg7 va_s0 va_s1 f /\ ME.buffer_readable (VS.vs_get_vale_heap va_s1) (as_vale_immbuffer arg0) /\ ME.buffer_readable (VS.vs_get_vale_heap va_s1) (as_vale_immbuffer arg1) /\ ME.buffer_readable (VS.vs_get_vale_heap va_s1) (as_vale_immbuffer arg2) /\ ME.buffer_readable (VS.vs_get_vale_heap va_s1) (as_vale_immbuffer arg3) /\ ME.buffer_readable (VS.vs_get_vale_heap va_s1) (as_vale_immbuffer arg4) /\ ME.buffer_readable (VS.vs_get_vale_heap va_s1) (as_vale_immbuffer arg5) /\ ME.buffer_readable (VS.vs_get_vale_heap va_s1) (as_vale_immbuffer arg6) /\ ME.buffer_readable (VS.vs_get_vale_heap va_s1) (as_vale_immbuffer arg7) /\ ME.modifies ME.loc_none (VS.vs_get_vale_heap va_s0) (VS.vs_get_vale_heap va_s1))) = let va_s1, f = TA.va_lemma_Test code va_s0 IA.win (as_vale_immbuffer arg0) (as_vale_immbuffer arg1) (as_vale_immbuffer arg2) (as_vale_immbuffer arg3) (as_vale_immbuffer arg4) (as_vale_immbuffer arg5) (as_vale_immbuffer arg6) (as_vale_immbuffer arg7) in va_s1, f
{ "checked_file": "/", "dependencies": [ "Vale.X64.State.fsti.checked", "Vale.X64.MemoryAdapters.fsti.checked", "Vale.X64.Memory.fsti.checked", "Vale.X64.Machine_s.fst.checked", "Vale.X64.Decls.fsti.checked", "Vale.X64.CPU_Features_s.fst.checked", "Vale.Test.X64.Vale_memcpy.fsti.checked", "Vale.Test.X64.Args.fsti.checked", "Vale.Lib.X64.Cpuidstdcall.fsti.checked", "Vale.Interop.X64.fsti.checked", "Vale.Interop.Base.fst.checked", "Vale.Interop.Assumptions.fst.checked", "Vale.AsLowStar.Wrapper.fsti.checked", "Vale.AsLowStar.ValeSig.fst.checked", "Vale.AsLowStar.MemoryHelpers.fsti.checked", "Vale.AsLowStar.LowStarSig.fst.checked", "prims.fst.checked", "LowStar.Monotonic.Buffer.fsti.checked", "LowStar.ImmutableBuffer.fst.checked", "LowStar.BufferView.Up.fsti.checked", "LowStar.BufferView.Down.fsti.checked", "LowStar.Buffer.fst.checked", "FStar.UInt8.fsti.checked", "FStar.UInt64.fsti.checked", "FStar.Tactics.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.List.fst.checked", "FStar.HyperStack.ST.fsti.checked" ], "interface_file": false, "source_file": "Vale.AsLowStar.Test.fst" }
[ { "abbrev": true, "full_module": "Vale.Test.X64.Args", "short_module": "TA" }, { "abbrev": false, "full_module": "Vale.X64.CPU_Features_s", "short_module": null }, { "abbrev": true, "full_module": "Vale.Lib.X64.Cpuidstdcall", "short_module": "VC" }, { "abbrev": true, "full_module": "LowStar.BufferView.Down", "short_module": "DV" }, { "abbrev": true, "full_module": "LowStar.BufferView.Up", "short_module": "LBV" }, { "abbrev": true, "full_module": "FStar.Tactics", "short_module": "T" }, { "abbrev": true, "full_module": "Vale.X64.Memory", "short_module": "M" }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": true, "full_module": "LowStar.Monotonic.Buffer", "short_module": "MB" }, { "abbrev": true, "full_module": "LowStar.ImmutableBuffer", "short_module": "IB" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "Vale.X64.State", "short_module": "VS" }, { "abbrev": false, "full_module": "Vale.X64.MemoryAdapters", "short_module": null }, { "abbrev": true, "full_module": "Vale.Test.X64.Vale_memcpy", "short_module": "VM" }, { "abbrev": true, "full_module": "Vale.X64.Machine_s", "short_module": "MS" }, { "abbrev": true, "full_module": "Vale.X64.State", "short_module": "VS" }, { "abbrev": true, "full_module": "Vale.AsLowStar.Wrapper", "short_module": "W" }, { "abbrev": true, "full_module": "Vale.AsLowStar.LowStarSig", "short_module": "LSig" }, { "abbrev": true, "full_module": "Vale.AsLowStar.ValeSig", "short_module": "VSig" }, { "abbrev": true, "full_module": "Vale.Interop.X64", "short_module": "IX64" }, { "abbrev": true, "full_module": "Vale.X64.Decls", "short_module": "V" }, { "abbrev": true, "full_module": "Vale.Interop.Assumptions", "short_module": "IA" }, { "abbrev": true, "full_module": "Vale.X64.Memory", "short_module": "ME" }, { "abbrev": false, "full_module": "Vale.Interop.Base", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.AsLowStar", "short_module": null }, { "abbrev": false, "full_module": "Vale.AsLowStar", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 0, "max_fuel": 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": 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" }
false
Vale.AsLowStar.ValeSig.vale_sig_stdcall Vale.AsLowStar.Test.ta_pre Vale.AsLowStar.Test.ta_post
Prims.Tot
[ "total" ]
[]
[ "Vale.AsLowStar.Test.as_t", "Vale.AsLowStar.ValeSig.vale_sig_stdcall", "Vale.AsLowStar.Test.ta_dom", "Vale.AsLowStar.Test.ta_pre", "Vale.AsLowStar.Test.ta_post", "Vale.AsLowStar.Test.ta_lemma'" ]
[]
false
false
false
true
false
let ta_lemma =
as_t #(VSig.vale_sig_stdcall ta_pre ta_post) ta_lemma'
false
Pulse.Soundness.fst
Pulse.Soundness.stequiv_soundness
val stequiv_soundness (g: stt_env) (t: st_term) (c: comp) (d: st_typing g t c {T_Equiv? d}) (soundness: soundness_t d) : GTot (RT.tot_typing (elab_env g) (elab_st_typing d) (elab_comp c))
val stequiv_soundness (g: stt_env) (t: st_term) (c: comp) (d: st_typing g t c {T_Equiv? d}) (soundness: soundness_t d) : GTot (RT.tot_typing (elab_env g) (elab_st_typing d) (elab_comp c))
let stequiv_soundness (g:stt_env) (t:st_term) (c:comp) (d:st_typing g t c{T_Equiv? d}) (soundness:soundness_t d) : GTot (RT.tot_typing (elab_env g) (elab_st_typing d) (elab_comp c)) = let T_Equiv _ e c c' e_typing equiv = d in LN.st_typing_ln d; LN.st_typing_ln e_typing; let r_e_typing = soundness _ _ _ e_typing in match equiv with | ST_TotEquiv _ t1 t2 _ _ eq -> let r_e_typing : RT.tot_typing (elab_env g) (elab_st_typing e_typing) (elab_term t1) = r_e_typing in let eq = RT.Rel_equiv _ _ _ RT.R_Sub eq in RT.T_Sub _ _ _ _ r_e_typing (RT.Relc_typ _ _ _ _ _ eq) | _ -> STEquiv.st_equiv_soundness _ _ _ equiv _ r_e_typing
{ "file_name": "lib/steel/pulse/Pulse.Soundness.fst", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 55, "end_line": 235, "start_col": 0, "start_line": 215 }
(* Copyright 2023 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module Pulse.Soundness module RT = FStar.Reflection.Typing module R = FStar.Reflection.V2 module L = FStar.List.Tot module T = FStar.Tactics.V2 open FStar.List.Tot open Pulse.Syntax open Pulse.Reflection.Util open Pulse.Typing open Pulse.Elaborate open Pulse.Soundness.Common module Bind = Pulse.Soundness.Bind module Lift = Pulse.Soundness.Lift module Frame = Pulse.Soundness.Frame module STEquiv = Pulse.Soundness.STEquiv module Return = Pulse.Soundness.Return module Exists = Pulse.Soundness.Exists module While = Pulse.Soundness.While module Admit = Pulse.Soundness.Admit module Par = Pulse.Soundness.Par module WithLocal = Pulse.Soundness.WithLocal module WithLocalArray = Pulse.Soundness.WithLocalArray module Rewrite = Pulse.Soundness.Rewrite module Comp = Pulse.Soundness.Comp module LN = Pulse.Typing.LN module FV = Pulse.Typing.FV module STT = Pulse.Soundness.STT module Sub = Pulse.Soundness.Sub module RU = Pulse.RuntimeUtils module Typing = Pulse.Typing module EPure = Pulse.Elaborate.Pure module WT= Pulse.Steel.Wrapper.Typing let tabs_t (d:'a) = #g:stt_env -> #u:universe -> #ty:term -> q:option qualifier -> ppname:ppname -> t_typing:tot_typing g ty (tm_type u) { t_typing << d } -> #body:st_term -> #x:var { None? (lookup g x) /\ ~(x `Set.mem` freevars_st body) } -> #c:comp -> body_typing:st_typing (push_binding g x ppname ty) (open_st_term body x) c { body_typing << d } -> GTot (RT.tot_typing (elab_env g) (mk_abs_with_name ppname.name (elab_term ty) (elab_qual q) (RT.close_term (elab_st_typing body_typing) x)) (elab_term (tm_arrow (mk_binder_ppname ty ppname) q (close_comp c x)))) #push-options "--z3rlimit_factor 4 --split_queries no" let lift_soundness (g:stt_env) (t:st_term) (c:comp) (d:st_typing g t c{T_Lift? d}) (soundness:soundness_t d) : GTot (RT.tot_typing (elab_env g) (elab_st_typing d) (elab_comp c)) = LN.st_typing_ln d; let T_Lift _ e c1 c2 e_typing lc = d in LN.st_typing_ln e_typing; match lc with | Lift_STAtomic_ST _ _ -> Lift.elab_lift_stt_atomic_st_typing g c1 c2 _ (soundness _ _ _ e_typing) lc | Lift_Ghost_Neutral _ _ w -> let (| reveal_a, reveal_a_typing |) = w in Lift.elab_lift_ghost_neutral_typing g c1 c2 _ (soundness _ _ _ e_typing) lc _ (tot_typing_soundness reveal_a_typing) | Lift_Neutral_Ghost _ _ -> Lift.elab_lift_neutral_ghost_typing g c1 c2 _ (soundness _ _ _ e_typing) lc | Lift_Observability _ _ _ -> Lift.elab_lift_observability_typing g c1 c2 _ (soundness _ _ _ e_typing) lc #pop-options let frame_soundness (g:stt_env) (t:st_term) (c:comp) (d:st_typing g t c{T_Frame? d}) (soundness:soundness_t d) : GTot (RT.tot_typing (elab_env g) (elab_st_typing d) (elab_comp c)) = let T_Frame _ e c frame frame_typing e_typing = d in let r_e_typing = soundness _ _ _ e_typing in LN.st_typing_ln e_typing; Frame.elab_frame_typing g _ _ frame frame_typing r_e_typing let stapp_soundness (g:stt_env) (t:st_term) (c:comp) (d:st_typing g t c{T_STApp? d}) (soundness:soundness_t d) : GTot (RT.tot_typing (elab_env g) (elab_st_typing d) (elab_comp c)) = let T_STApp _ head formal q res arg head_typing arg_typing = d in let r_head = elab_term head in let r_arg = elab_term arg in let r_head_typing : RT.tot_typing _ r_head (elab_term (tm_arrow (mk_binder_ppname formal ppname_default) q res)) = tot_typing_soundness head_typing in let r_arg_typing = tot_typing_soundness arg_typing in RT.T_App _ _ _ (binder_of_t_q_s (elab_term formal) (elab_qual q) RT.pp_name_default) (elab_comp res) _ r_head_typing r_arg_typing // // We have G |- head : Ghost (x:t -> Total res) -- (1) // G |- arg : Ghost t -- (2) // G,x:t |- non_informative (open res x) -- (3) // // We first lift (1) to G |- head : Ghost (x:t -> Ghost res) // Then apply T_App in reflection typing to derive // G |- head arg : Ghost (open res arg) -- (4) // and then promote (4) to Total using a substitution lemma on (3) // let stghostapp_soundness (g:stt_env) (t:st_term) (c:comp) (d:st_typing g t c{T_STGhostApp? d}) (soundness:soundness_t d) : GTot (RT.tot_typing (elab_env g) (elab_st_typing d) (elab_comp c)) = let T_STGhostApp _ head formal q res arg x head_typing d_non_info arg_typing = d in let r_head = elab_term head in let r_arg = elab_term arg in let r_binder = mk_binder_ppname formal ppname_default in let head_t = tm_arrow r_binder q res in let r_head_t = mk_arrow_with_name ppname_default.name (elab_term formal, elab_qual q) (elab_comp res) in let r_head_typing : RT.ghost_typing _ r_head r_head_t = ghost_typing_soundness head_typing in let r_arg_typing = ghost_typing_soundness arg_typing in assume (elab_env (push_binding g x ppname_default formal) == RT.extend_env (elab_env g) x (elab_term formal)); assume ((T.E_Total, elab_comp (open_comp_with res (null_var x))) == RT.open_comp_typ (T.E_Total, elab_comp res) x); assume ((T.E_Ghost, elab_comp (open_comp_with res (null_var x))) == RT.open_comp_typ (T.E_Ghost, elab_comp res) x); let d_rel_comp : RT.related_comp (elab_env (push_binding g x ppname_default formal)) (T.E_Total, elab_comp (open_comp_with res (null_var x))) RT.R_Sub (T.E_Ghost, elab_comp (open_comp_with res (null_var x))) = RT.Relc_total_ghost _ _ in let r_head_t_ghost = mk_ghost_arrow_with_name ppname_default.name (elab_term formal, elab_qual q) (elab_comp res) in assert (r_head_t == RT.mk_arrow_ct (elab_term formal) (elab_qual q) (T.E_Total, elab_comp res)); assert (r_head_t_ghost == RT.mk_arrow_ct (elab_term formal) (elab_qual q) (T.E_Ghost, elab_comp res)); assume (None? (RT.lookup_bvar (elab_env g) x) /\ ~ (x `Set.mem` ((RT.freevars_comp_typ (T.E_Total, elab_comp res)) `Set.union` (RT.freevars_comp_typ (T.E_Ghost, elab_comp res))))); let d_rel_t_arrow : RT.related (elab_env g) r_head_t RT.R_Sub r_head_t_ghost = RT.Rel_arrow _ (elab_term formal) (elab_term formal) (elab_qual q) (T.E_Total, elab_comp res) (T.E_Ghost, elab_comp res) RT.R_Sub x (RT.Rel_equiv _ _ _ _ (RT.Rel_refl _ _ _)) d_rel_comp in let r_head_typing : RT.ghost_typing _ r_head r_head_t_ghost = RT.T_Sub _ _ _ _ r_head_typing (RT.Relc_typ _ _ _ T.E_Ghost _ d_rel_t_arrow) in let d : RT.typing (elab_env g) (elab_st_typing d) (T.E_Ghost, elab_comp (open_comp_with res arg)) = RT.T_App _ _ _ (binder_of_t_q_s (elab_term formal) (elab_qual q) RT.pp_name_default) (elab_comp res) _ r_head_typing r_arg_typing in let E d_non_info = d_non_info in let d_non_info : RT.non_informative (elab_env (push_binding g x ppname_default formal)) (elab_comp (open_comp_with res (null_var x))) = d_non_info in // TODO: substitution lemma in RT for non_informative judgment let d_non_info : RT.non_informative (elab_env g) (elab_comp (open_comp_with res arg)) = RU.magic () in RT.T_Sub _ _ _ _ d (RT.Relc_ghost_total _ _ d_non_info)
{ "checked_file": "/", "dependencies": [ "Pulse.Typing.LN.fsti.checked", "Pulse.Typing.FV.fsti.checked", "Pulse.Typing.fst.checked", "Pulse.Syntax.fst.checked", "Pulse.Steel.Wrapper.Typing.fsti.checked", "Pulse.Soundness.WithLocalArray.fsti.checked", "Pulse.Soundness.WithLocal.fsti.checked", "Pulse.Soundness.While.fsti.checked", "Pulse.Soundness.Sub.fsti.checked", "Pulse.Soundness.STT.fsti.checked", "Pulse.Soundness.STEquiv.fsti.checked", "Pulse.Soundness.Rewrite.fsti.checked", "Pulse.Soundness.Return.fsti.checked", "Pulse.Soundness.Par.fsti.checked", "Pulse.Soundness.Match.fsti.checked", "Pulse.Soundness.Lift.fsti.checked", "Pulse.Soundness.Frame.fsti.checked", "Pulse.Soundness.Exists.fsti.checked", "Pulse.Soundness.Comp.fsti.checked", "Pulse.Soundness.Common.fst.checked", "Pulse.Soundness.Bind.fsti.checked", "Pulse.Soundness.Admit.fsti.checked", "Pulse.RuntimeUtils.fsti.checked", "Pulse.Reflection.Util.fst.checked", "Pulse.Elaborate.Pure.fst.checked", "Pulse.Elaborate.fsti.checked", "prims.fst.checked", "FStar.Tactics.V2.fst.checked", "FStar.Squash.fsti.checked", "FStar.Set.fsti.checked", "FStar.Reflection.V2.fst.checked", "FStar.Reflection.Typing.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked" ], "interface_file": true, "source_file": "Pulse.Soundness.fst" }
[ { "abbrev": true, "full_module": "Pulse.Steel.Wrapper.Typing", "short_module": "WT" }, { "abbrev": true, "full_module": "Pulse.Elaborate.Pure", "short_module": "EPure" }, { "abbrev": true, "full_module": "Pulse.Typing", "short_module": "Typing" }, { "abbrev": true, "full_module": "Pulse.RuntimeUtils", "short_module": "RU" }, { "abbrev": true, "full_module": "Pulse.Soundness.Sub", "short_module": "Sub" }, { "abbrev": true, "full_module": "Pulse.Soundness.STT", "short_module": "STT" }, { "abbrev": true, "full_module": "Pulse.Typing.FV", "short_module": "FV" }, { "abbrev": true, "full_module": "Pulse.Typing.LN", "short_module": "LN" }, { "abbrev": true, "full_module": "Pulse.Soundness.Comp", "short_module": "Comp" }, { "abbrev": true, "full_module": "Pulse.Soundness.Rewrite", "short_module": "Rewrite" }, { "abbrev": true, "full_module": "Pulse.Soundness.WithLocalArray", "short_module": "WithLocalArray" }, { "abbrev": true, "full_module": "Pulse.Soundness.WithLocal", "short_module": "WithLocal" }, { "abbrev": true, "full_module": "Pulse.Soundness.Par", "short_module": "Par" }, { "abbrev": true, "full_module": "Pulse.Soundness.Admit", "short_module": "Admit" }, { "abbrev": true, "full_module": "Pulse.Soundness.While", "short_module": "While" }, { "abbrev": true, "full_module": "Pulse.Soundness.Exists", "short_module": "Exists" }, { "abbrev": true, "full_module": "Pulse.Soundness.Return", "short_module": "Return" }, { "abbrev": true, "full_module": "Pulse.Soundness.STEquiv", "short_module": "STEquiv" }, { "abbrev": true, "full_module": "Pulse.Soundness.Frame", "short_module": "Frame" }, { "abbrev": true, "full_module": "Pulse.Soundness.Lift", "short_module": "Lift" }, { "abbrev": true, "full_module": "Pulse.Soundness.Bind", "short_module": "Bind" }, { "abbrev": false, "full_module": "Pulse.Soundness.Common", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Elaborate", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Typing", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Reflection.Util", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Syntax", "short_module": null }, { "abbrev": false, "full_module": "FStar.List.Tot", "short_module": null }, { "abbrev": true, "full_module": "FStar.Tactics.V2", "short_module": "T" }, { "abbrev": true, "full_module": "FStar.List.Tot", "short_module": "L" }, { "abbrev": true, "full_module": "FStar.Reflection.V2", "short_module": "R" }, { "abbrev": true, "full_module": "FStar.Reflection.Typing", "short_module": "RT" }, { "abbrev": false, "full_module": "Pulse.Soundness.Common", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Elaborate", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Typing", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Reflection.Util", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Syntax", "short_module": null }, { "abbrev": false, "full_module": "FStar.List.Tot", "short_module": null }, { "abbrev": true, "full_module": "FStar.Tactics.V2", "short_module": "T" }, { "abbrev": true, "full_module": "FStar.List.Tot", "short_module": "L" }, { "abbrev": true, "full_module": "FStar.Reflection.V2", "short_module": "R" }, { "abbrev": true, "full_module": "FStar.Reflection.Typing", "short_module": "RT" }, { "abbrev": false, "full_module": "Pulse", "short_module": null }, { "abbrev": false, "full_module": "Pulse", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
g: Pulse.Soundness.Common.stt_env -> t: Pulse.Syntax.Base.st_term -> c: Pulse.Syntax.Base.comp -> d: Pulse.Typing.st_typing g t c {T_Equiv? d} -> soundness: Pulse.Soundness.Common.soundness_t d -> Prims.GTot (FStar.Reflection.Typing.tot_typing (Pulse.Typing.elab_env g) (Pulse.Elaborate.Core.elab_st_typing d) (Pulse.Elaborate.Pure.elab_comp c))
Prims.GTot
[ "sometrivial" ]
[]
[ "Pulse.Soundness.Common.stt_env", "Pulse.Syntax.Base.st_term", "Pulse.Syntax.Base.comp", "Pulse.Typing.st_typing", "Prims.b2t", "Pulse.Typing.uu___is_T_Equiv", "Pulse.Soundness.Common.soundness_t", "Pulse.Typing.Env.env", "Pulse.Typing.st_equiv", "Pulse.Syntax.Base.term", "Pulse.Syntax.Base.universe", "Pulse.Typing.universe_of", "FStar.Ghost.erased", "FStar.Reflection.Typing.equiv", "Pulse.Typing.elab_env", "Pulse.Elaborate.Pure.elab_term", "FStar.Reflection.Typing.T_Sub", "Pulse.Elaborate.Core.elab_st_typing", "FStar.Pervasives.Native.Mktuple2", "FStar.Stubs.TypeChecker.Core.tot_or_ghost", "FStar.Stubs.Reflection.Types.typ", "FStar.Stubs.TypeChecker.Core.E_Total", "FStar.Reflection.Typing.Relc_typ", "FStar.Reflection.Typing.R_Sub", "FStar.Reflection.Typing.related", "FStar.Reflection.Typing.Rel_equiv", "FStar.Ghost.reveal", "FStar.Reflection.Typing.tot_typing", "Pulse.Soundness.STEquiv.st_equiv_soundness", "Pulse.Elaborate.Pure.elab_comp", "Prims.unit", "Pulse.Typing.LN.st_typing_ln" ]
[]
false
false
false
false
false
let stequiv_soundness (g: stt_env) (t: st_term) (c: comp) (d: st_typing g t c {T_Equiv? d}) (soundness: soundness_t d) : GTot (RT.tot_typing (elab_env g) (elab_st_typing d) (elab_comp c)) =
let T_Equiv _ e c c' e_typing equiv = d in LN.st_typing_ln d; LN.st_typing_ln e_typing; let r_e_typing = soundness _ _ _ e_typing in match equiv with | ST_TotEquiv _ t1 t2 _ _ eq -> let r_e_typing:RT.tot_typing (elab_env g) (elab_st_typing e_typing) (elab_term t1) = r_e_typing in let eq = RT.Rel_equiv _ _ _ RT.R_Sub eq in RT.T_Sub _ _ _ _ r_e_typing (RT.Relc_typ _ _ _ _ _ eq) | _ -> STEquiv.st_equiv_soundness _ _ _ equiv _ r_e_typing
false
Vale.AsLowStar.Test.fst
Vale.AsLowStar.Test.aesni_lemma'
val aesni_lemma' (code: V.va_code) (_win: bool) (va_s0: V.va_state) : Ghost (V.va_state & V.va_fuel) (requires aesni_pre code va_s0) (ensures (fun (va_s1, f) -> V.eval_code code va_s0 f va_s1 /\ VSig.vale_calling_conventions_stdcall va_s0 va_s1 /\ aesni_post code va_s0 va_s1 f))
val aesni_lemma' (code: V.va_code) (_win: bool) (va_s0: V.va_state) : Ghost (V.va_state & V.va_fuel) (requires aesni_pre code va_s0) (ensures (fun (va_s1, f) -> V.eval_code code va_s0 f va_s1 /\ VSig.vale_calling_conventions_stdcall va_s0 va_s1 /\ aesni_post code va_s0 va_s1 f))
let aesni_lemma' (code:V.va_code) (_win:bool) (va_s0:V.va_state) : Ghost (V.va_state & V.va_fuel) (requires aesni_pre code va_s0) (ensures (fun (va_s1, f) -> V.eval_code code va_s0 f va_s1 /\ VSig.vale_calling_conventions_stdcall va_s0 va_s1 /\ aesni_post code va_s0 va_s1 f)) = VC.va_lemma_Check_aesni_stdcall code va_s0 IA.win
{ "file_name": "vale/code/arch/x64/interop/Vale.AsLowStar.Test.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 52, "end_line": 227, "start_col": 0, "start_line": 216 }
module Vale.AsLowStar.Test open FStar.Mul open Vale.Interop.Base module ME = Vale.X64.Memory module IA = Vale.Interop.Assumptions module V = Vale.X64.Decls module IX64 = Vale.Interop.X64 module VSig = Vale.AsLowStar.ValeSig module LSig = Vale.AsLowStar.LowStarSig module W = Vale.AsLowStar.Wrapper module VS = Vale.X64.State module MS = Vale.X64.Machine_s (* A little utility to trigger normalization in types *) let as_t (#a:Type) (x:normal a) : a = x let as_normal_t (#a:Type) (x:a) : normal a = x //////////////////////////////////////////////////////////////////////////////// //First a little standalone, toy experiment [@__reduce__] let b64 = buf_t TUInt8 TUInt64 [@__reduce__] let ib64 = ibuf_t TUInt8 TUInt64 [@__reduce__] let t64_mod = TD_Buffer TUInt8 TUInt64 default_bq [@__reduce__] let t64_no_mod = TD_Buffer TUInt8 TUInt64 ({modified=false; strict_disjointness=false; taint=MS.Secret}) [@__reduce__] let t64_imm = TD_ImmBuffer TUInt8 TUInt64 ({modified=false; strict_disjointness=false; taint=MS.Secret}) [@__reduce__] let (dom : list td{List.length dom <= 20}) = let y = [t64_mod;t64_imm] in assert_norm (List.length y = 2); y assume val pre : VSig.vale_pre dom assume val post : VSig.vale_post dom assume val v: VSig.vale_sig_stdcall pre post assume val c: V.va_code [@__reduce__] let call_c_t = IX64.as_lowstar_sig_t_weak_stdcall c dom [] _ _ (W.mk_prediction c dom [] (v c IA.win)) let call_c : call_c_t = IX64.wrap_weak_stdcall c dom (W.mk_prediction c dom [] (v c IA.win)) let call_c_normal_t : normal call_c_t = as_normal_t #call_c_t call_c //You can ask emacs to show you the type of call_c_normal_t ... //////////////////////////////////////////////////////////////////////////////// //Now memcpy module VM = Vale.Test.X64.Vale_memcpy [@__reduce__] let vm_dom = [t64_mod; t64_imm] open Vale.X64.MemoryAdapters (* Need to rearrange the order of arguments *) [@__reduce__] let vm_pre : VSig.vale_pre vm_dom = fun (c:V.va_code) (dst:b64) (src:ib64) (va_s0:V.va_state) -> VM.va_req_Memcpy c va_s0 IA.win (as_vale_buffer dst) (as_vale_immbuffer src) [@__reduce__] let vm_post : VSig.vale_post vm_dom = fun (c:V.va_code) (dst:b64) (src:ib64) (va_s0:V.va_state) (va_s1:V.va_state) (f:V.va_fuel) -> VM.va_ens_Memcpy c va_s0 IA.win (as_vale_buffer dst) (as_vale_immbuffer src) va_s1 f module VS = Vale.X64.State #reset-options "--print_effect_args --z3rlimit 200" (* The vale lemma doesn't quite suffice to prove the modifies clause expected of the interop layer *) [@__reduce__] let vm_lemma' (code:V.va_code) (_win:bool) (dst:b64) (src:ib64) (va_s0:V.va_state) : Ghost (V.va_state & V.va_fuel) (requires vm_pre code dst src va_s0) (ensures (fun (va_s1, f) -> V.eval_code code va_s0 f va_s1 /\ VSig.vale_calling_conventions_stdcall va_s0 va_s1 /\ vm_post code dst src va_s0 va_s1 f /\ ME.buffer_readable (VS.vs_get_vale_heap va_s1) (as_vale_immbuffer src) /\ ME.buffer_readable (VS.vs_get_vale_heap va_s1) (as_vale_buffer dst) /\ ME.buffer_writeable (as_vale_buffer dst) /\ ME.modifies (ME.loc_union (ME.loc_buffer (as_vale_buffer dst)) ME.loc_none) (VS.vs_get_vale_heap va_s0) (VS.vs_get_vale_heap va_s1) )) = let va_s1, f = VM.va_lemma_Memcpy code va_s0 IA.win (as_vale_buffer dst) (as_vale_immbuffer src) in Vale.AsLowStar.MemoryHelpers.buffer_writeable_reveal ME.TUInt8 ME.TUInt64 dst; (va_s1, f) (* Prove that vm_lemma' has the required type *) let vm_lemma = as_t #(VSig.vale_sig_stdcall vm_pre vm_post) vm_lemma' let code_Memcpy = VM.va_code_Memcpy IA.win (* Here's the type expected for the memcpy wrapper *) [@__reduce__] let lowstar_Memcpy_t = IX64.as_lowstar_sig_t_weak_stdcall code_Memcpy vm_dom [] _ _ (W.mk_prediction code_Memcpy vm_dom [] (vm_lemma code_Memcpy IA.win)) (* And here's the memcpy wrapper itself *) let lowstar_Memcpy : lowstar_Memcpy_t = IX64.wrap_weak_stdcall code_Memcpy vm_dom (W.mk_prediction code_Memcpy vm_dom [] (vm_lemma code_Memcpy IA.win)) let lowstar_Memcpy_normal_t //: normal lowstar_Memcpy_t = as_normal_t #lowstar_Memcpy_t lowstar_Memcpy module B = LowStar.Buffer module IB = LowStar.ImmutableBuffer module MB = LowStar.Monotonic.Buffer open FStar.HyperStack.ST module M = Vale.X64.Memory let test (x:b64) = assert (V.buffer_length (as_vale_buffer x) == (B.length x * view_n TUInt8) / view_n TUInt64); assert (V.buffer_length (as_vale_buffer x) == B.length x / 8) let itest (x:ib64) = assert (V.buffer_length (as_vale_immbuffer x) == (B.length x * view_n TUInt8) / view_n TUInt64); assert (V.buffer_length (as_vale_immbuffer x) == B.length x / 8) module T = FStar.Tactics #reset-options "--using_facts_from '* -FStar.Tactics -FStar.Reflection'" module LBV = LowStar.BufferView.Up module DV = LowStar.BufferView.Down #push-options "--ext compat:normalizer_memo_ignore_cfg" let memcpy_Test (dst:B.buffer UInt8.t{B.length dst % 8 == 0}) (src:IB.ibuffer UInt8.t{B.length src % 8 == 0}) : Stack UInt64.t (requires fun h0 -> B.live h0 dst /\ B.live h0 src /\ B.disjoint dst src /\ B.length dst == 16 /\ B.length src == 16) (ensures fun h0 _ h1 -> B.modifies (B.loc_buffer dst) h0 h1 /\ B.live h1 src /\ B.live h1 dst) // B.as_seq h1 dst == B.as_seq h1 src) // by (T.dump "A") (* in case you want to look at the VC *) = IB.inhabited_immutable_buffer_is_distinct_from_buffer (UInt8.uint_to_t 0) src dst; let (x, _) = lowstar_Memcpy_normal_t dst src () in //This is a call to the interop wrapper let h1 = get () in // let v = Vale.Interop.Views.up_view64 in // assert (DV.length_eq (get_downview dst); // DV.length_eq (get_downview src); // Seq.equal (LBV.as_seq h1 (LBV.mk_buffer (get_downview dst) v)) // (LBV.as_seq h1 (LBV.mk_buffer (get_downview src) v))); // lbv_as_seq_eq dst src Vale.Interop.Views.up_view64 h1; //And a lemma to rephrase the Vale postcondition x //with equalities of buffer views //back to equalities of buffers #pop-options module VC = Vale.Lib.X64.Cpuidstdcall [@__reduce__] let empty_list #a : l:list a {List.length l = 0} = [] [@__reduce__] let aesni_dom : IX64.arity_ok_stdcall td = [] (* Need to rearrange the order of arguments *) [@__reduce__] let aesni_pre : VSig.vale_pre aesni_dom = fun (c:V.va_code) (va_s0:V.va_state) -> VC.va_req_Check_aesni_stdcall c va_s0 IA.win [@__reduce__] let aesni_post : VSig.vale_post aesni_dom = fun (c:V.va_code) (va_s0:V.va_state) (va_s1:V.va_state) (f:V.va_fuel) -> VC.va_ens_Check_aesni_stdcall c va_s0 IA.win va_s1 f [@__reduce__] let with_len (l:list 'a) : Pure (list 'a) (requires True) (ensures fun m -> m==l /\ List.length m == normalize_term (List.length l)) = l #set-options "--max_fuel 0 --max_ifuel 1 --z3rlimit_factor 2" (* The vale lemma doesn't quite suffice to prove the modifies clause expected of the interop layer *)
{ "checked_file": "/", "dependencies": [ "Vale.X64.State.fsti.checked", "Vale.X64.MemoryAdapters.fsti.checked", "Vale.X64.Memory.fsti.checked", "Vale.X64.Machine_s.fst.checked", "Vale.X64.Decls.fsti.checked", "Vale.X64.CPU_Features_s.fst.checked", "Vale.Test.X64.Vale_memcpy.fsti.checked", "Vale.Test.X64.Args.fsti.checked", "Vale.Lib.X64.Cpuidstdcall.fsti.checked", "Vale.Interop.X64.fsti.checked", "Vale.Interop.Base.fst.checked", "Vale.Interop.Assumptions.fst.checked", "Vale.AsLowStar.Wrapper.fsti.checked", "Vale.AsLowStar.ValeSig.fst.checked", "Vale.AsLowStar.MemoryHelpers.fsti.checked", "Vale.AsLowStar.LowStarSig.fst.checked", "prims.fst.checked", "LowStar.Monotonic.Buffer.fsti.checked", "LowStar.ImmutableBuffer.fst.checked", "LowStar.BufferView.Up.fsti.checked", "LowStar.BufferView.Down.fsti.checked", "LowStar.Buffer.fst.checked", "FStar.UInt8.fsti.checked", "FStar.UInt64.fsti.checked", "FStar.Tactics.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.List.fst.checked", "FStar.HyperStack.ST.fsti.checked" ], "interface_file": false, "source_file": "Vale.AsLowStar.Test.fst" }
[ { "abbrev": true, "full_module": "Vale.Lib.X64.Cpuidstdcall", "short_module": "VC" }, { "abbrev": true, "full_module": "LowStar.BufferView.Down", "short_module": "DV" }, { "abbrev": true, "full_module": "LowStar.BufferView.Up", "short_module": "LBV" }, { "abbrev": true, "full_module": "FStar.Tactics", "short_module": "T" }, { "abbrev": true, "full_module": "Vale.X64.Memory", "short_module": "M" }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": true, "full_module": "LowStar.Monotonic.Buffer", "short_module": "MB" }, { "abbrev": true, "full_module": "LowStar.ImmutableBuffer", "short_module": "IB" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "Vale.X64.State", "short_module": "VS" }, { "abbrev": false, "full_module": "Vale.X64.MemoryAdapters", "short_module": null }, { "abbrev": true, "full_module": "Vale.Test.X64.Vale_memcpy", "short_module": "VM" }, { "abbrev": true, "full_module": "Vale.X64.Machine_s", "short_module": "MS" }, { "abbrev": true, "full_module": "Vale.X64.State", "short_module": "VS" }, { "abbrev": true, "full_module": "Vale.AsLowStar.Wrapper", "short_module": "W" }, { "abbrev": true, "full_module": "Vale.AsLowStar.LowStarSig", "short_module": "LSig" }, { "abbrev": true, "full_module": "Vale.AsLowStar.ValeSig", "short_module": "VSig" }, { "abbrev": true, "full_module": "Vale.Interop.X64", "short_module": "IX64" }, { "abbrev": true, "full_module": "Vale.X64.Decls", "short_module": "V" }, { "abbrev": true, "full_module": "Vale.Interop.Assumptions", "short_module": "IA" }, { "abbrev": true, "full_module": "Vale.X64.Memory", "short_module": "ME" }, { "abbrev": false, "full_module": "Vale.Interop.Base", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.AsLowStar", "short_module": null }, { "abbrev": false, "full_module": "Vale.AsLowStar", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 0, "max_fuel": 0, "max_ifuel": 1, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": true, "smtencoding_l_arith_repr": "native", "smtencoding_nl_arith_repr": "wrapped", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [ "smt.arith.nl=false", "smt.QI.EAGER_THRESHOLD=100", "smt.CASE_SPLIT=3" ], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 2, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
code: Vale.X64.Decls.va_code -> _win: Prims.bool -> va_s0: Vale.X64.Decls.va_state -> Prims.Ghost (Vale.X64.Decls.va_state * Vale.X64.Decls.va_fuel)
Prims.Ghost
[]
[]
[ "Vale.X64.Decls.va_code", "Prims.bool", "Vale.X64.Decls.va_state", "Vale.Lib.X64.Cpuidstdcall.va_lemma_Check_aesni_stdcall", "Vale.Interop.Assumptions.win", "FStar.Pervasives.Native.tuple2", "Vale.X64.Decls.va_fuel", "Vale.AsLowStar.Test.aesni_pre", "Prims.l_and", "Vale.X64.Decls.eval_code", "Vale.AsLowStar.ValeSig.vale_calling_conventions_stdcall", "Vale.AsLowStar.Test.aesni_post" ]
[]
false
false
false
false
false
let aesni_lemma' (code: V.va_code) (_win: bool) (va_s0: V.va_state) : Ghost (V.va_state & V.va_fuel) (requires aesni_pre code va_s0) (ensures (fun (va_s1, f) -> V.eval_code code va_s0 f va_s1 /\ VSig.vale_calling_conventions_stdcall va_s0 va_s1 /\ aesni_post code va_s0 va_s1 f)) =
VC.va_lemma_Check_aesni_stdcall code va_s0 IA.win
false
Pulse.Soundness.fst
Pulse.Soundness.lift_soundness
val lift_soundness (g: stt_env) (t: st_term) (c: comp) (d: st_typing g t c {T_Lift? d}) (soundness: soundness_t d) : GTot (RT.tot_typing (elab_env g) (elab_st_typing d) (elab_comp c))
val lift_soundness (g: stt_env) (t: st_term) (c: comp) (d: st_typing g t c {T_Lift? d}) (soundness: soundness_t d) : GTot (RT.tot_typing (elab_env g) (elab_st_typing d) (elab_comp c))
let lift_soundness (g:stt_env) (t:st_term) (c:comp) (d:st_typing g t c{T_Lift? d}) (soundness:soundness_t d) : GTot (RT.tot_typing (elab_env g) (elab_st_typing d) (elab_comp c)) = LN.st_typing_ln d; let T_Lift _ e c1 c2 e_typing lc = d in LN.st_typing_ln e_typing; match lc with | Lift_STAtomic_ST _ _ -> Lift.elab_lift_stt_atomic_st_typing g c1 c2 _ (soundness _ _ _ e_typing) lc | Lift_Ghost_Neutral _ _ w -> let (| reveal_a, reveal_a_typing |) = w in Lift.elab_lift_ghost_neutral_typing g c1 c2 _ (soundness _ _ _ e_typing) lc _ (tot_typing_soundness reveal_a_typing) | Lift_Neutral_Ghost _ _ -> Lift.elab_lift_neutral_ghost_typing g c1 c2 _ (soundness _ _ _ e_typing) lc | Lift_Observability _ _ _ -> Lift.elab_lift_observability_typing g c1 c2 _ (soundness _ _ _ e_typing) lc
{ "file_name": "lib/steel/pulse/Pulse.Soundness.fst", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 43, "end_line": 93, "start_col": 0, "start_line": 66 }
(* Copyright 2023 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module Pulse.Soundness module RT = FStar.Reflection.Typing module R = FStar.Reflection.V2 module L = FStar.List.Tot module T = FStar.Tactics.V2 open FStar.List.Tot open Pulse.Syntax open Pulse.Reflection.Util open Pulse.Typing open Pulse.Elaborate open Pulse.Soundness.Common module Bind = Pulse.Soundness.Bind module Lift = Pulse.Soundness.Lift module Frame = Pulse.Soundness.Frame module STEquiv = Pulse.Soundness.STEquiv module Return = Pulse.Soundness.Return module Exists = Pulse.Soundness.Exists module While = Pulse.Soundness.While module Admit = Pulse.Soundness.Admit module Par = Pulse.Soundness.Par module WithLocal = Pulse.Soundness.WithLocal module WithLocalArray = Pulse.Soundness.WithLocalArray module Rewrite = Pulse.Soundness.Rewrite module Comp = Pulse.Soundness.Comp module LN = Pulse.Typing.LN module FV = Pulse.Typing.FV module STT = Pulse.Soundness.STT module Sub = Pulse.Soundness.Sub module RU = Pulse.RuntimeUtils module Typing = Pulse.Typing module EPure = Pulse.Elaborate.Pure module WT= Pulse.Steel.Wrapper.Typing let tabs_t (d:'a) = #g:stt_env -> #u:universe -> #ty:term -> q:option qualifier -> ppname:ppname -> t_typing:tot_typing g ty (tm_type u) { t_typing << d } -> #body:st_term -> #x:var { None? (lookup g x) /\ ~(x `Set.mem` freevars_st body) } -> #c:comp -> body_typing:st_typing (push_binding g x ppname ty) (open_st_term body x) c { body_typing << d } -> GTot (RT.tot_typing (elab_env g) (mk_abs_with_name ppname.name (elab_term ty) (elab_qual q) (RT.close_term (elab_st_typing body_typing) x)) (elab_term (tm_arrow (mk_binder_ppname ty ppname) q (close_comp c x))))
{ "checked_file": "/", "dependencies": [ "Pulse.Typing.LN.fsti.checked", "Pulse.Typing.FV.fsti.checked", "Pulse.Typing.fst.checked", "Pulse.Syntax.fst.checked", "Pulse.Steel.Wrapper.Typing.fsti.checked", "Pulse.Soundness.WithLocalArray.fsti.checked", "Pulse.Soundness.WithLocal.fsti.checked", "Pulse.Soundness.While.fsti.checked", "Pulse.Soundness.Sub.fsti.checked", "Pulse.Soundness.STT.fsti.checked", "Pulse.Soundness.STEquiv.fsti.checked", "Pulse.Soundness.Rewrite.fsti.checked", "Pulse.Soundness.Return.fsti.checked", "Pulse.Soundness.Par.fsti.checked", "Pulse.Soundness.Match.fsti.checked", "Pulse.Soundness.Lift.fsti.checked", "Pulse.Soundness.Frame.fsti.checked", "Pulse.Soundness.Exists.fsti.checked", "Pulse.Soundness.Comp.fsti.checked", "Pulse.Soundness.Common.fst.checked", "Pulse.Soundness.Bind.fsti.checked", "Pulse.Soundness.Admit.fsti.checked", "Pulse.RuntimeUtils.fsti.checked", "Pulse.Reflection.Util.fst.checked", "Pulse.Elaborate.Pure.fst.checked", "Pulse.Elaborate.fsti.checked", "prims.fst.checked", "FStar.Tactics.V2.fst.checked", "FStar.Squash.fsti.checked", "FStar.Set.fsti.checked", "FStar.Reflection.V2.fst.checked", "FStar.Reflection.Typing.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked" ], "interface_file": true, "source_file": "Pulse.Soundness.fst" }
[ { "abbrev": true, "full_module": "Pulse.Steel.Wrapper.Typing", "short_module": "WT" }, { "abbrev": true, "full_module": "Pulse.Elaborate.Pure", "short_module": "EPure" }, { "abbrev": true, "full_module": "Pulse.Typing", "short_module": "Typing" }, { "abbrev": true, "full_module": "Pulse.RuntimeUtils", "short_module": "RU" }, { "abbrev": true, "full_module": "Pulse.Soundness.Sub", "short_module": "Sub" }, { "abbrev": true, "full_module": "Pulse.Soundness.STT", "short_module": "STT" }, { "abbrev": true, "full_module": "Pulse.Typing.FV", "short_module": "FV" }, { "abbrev": true, "full_module": "Pulse.Typing.LN", "short_module": "LN" }, { "abbrev": true, "full_module": "Pulse.Soundness.Comp", "short_module": "Comp" }, { "abbrev": true, "full_module": "Pulse.Soundness.Rewrite", "short_module": "Rewrite" }, { "abbrev": true, "full_module": "Pulse.Soundness.WithLocalArray", "short_module": "WithLocalArray" }, { "abbrev": true, "full_module": "Pulse.Soundness.WithLocal", "short_module": "WithLocal" }, { "abbrev": true, "full_module": "Pulse.Soundness.Par", "short_module": "Par" }, { "abbrev": true, "full_module": "Pulse.Soundness.Admit", "short_module": "Admit" }, { "abbrev": true, "full_module": "Pulse.Soundness.While", "short_module": "While" }, { "abbrev": true, "full_module": "Pulse.Soundness.Exists", "short_module": "Exists" }, { "abbrev": true, "full_module": "Pulse.Soundness.Return", "short_module": "Return" }, { "abbrev": true, "full_module": "Pulse.Soundness.STEquiv", "short_module": "STEquiv" }, { "abbrev": true, "full_module": "Pulse.Soundness.Frame", "short_module": "Frame" }, { "abbrev": true, "full_module": "Pulse.Soundness.Lift", "short_module": "Lift" }, { "abbrev": true, "full_module": "Pulse.Soundness.Bind", "short_module": "Bind" }, { "abbrev": false, "full_module": "Pulse.Soundness.Common", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Elaborate", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Typing", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Reflection.Util", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Syntax", "short_module": null }, { "abbrev": false, "full_module": "FStar.List.Tot", "short_module": null }, { "abbrev": true, "full_module": "FStar.Tactics.V2", "short_module": "T" }, { "abbrev": true, "full_module": "FStar.List.Tot", "short_module": "L" }, { "abbrev": true, "full_module": "FStar.Reflection.V2", "short_module": "R" }, { "abbrev": true, "full_module": "FStar.Reflection.Typing", "short_module": "RT" }, { "abbrev": false, "full_module": "Pulse.Soundness.Common", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Elaborate", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Typing", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Reflection.Util", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Syntax", "short_module": null }, { "abbrev": false, "full_module": "FStar.List.Tot", "short_module": null }, { "abbrev": true, "full_module": "FStar.Tactics.V2", "short_module": "T" }, { "abbrev": true, "full_module": "FStar.List.Tot", "short_module": "L" }, { "abbrev": true, "full_module": "FStar.Reflection.V2", "short_module": "R" }, { "abbrev": true, "full_module": "FStar.Reflection.Typing", "short_module": "RT" }, { "abbrev": false, "full_module": "Pulse", "short_module": null }, { "abbrev": false, "full_module": "Pulse", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 4, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
g: Pulse.Soundness.Common.stt_env -> t: Pulse.Syntax.Base.st_term -> c: Pulse.Syntax.Base.comp -> d: Pulse.Typing.st_typing g t c {T_Lift? d} -> soundness: Pulse.Soundness.Common.soundness_t d -> Prims.GTot (FStar.Reflection.Typing.tot_typing (Pulse.Typing.elab_env g) (Pulse.Elaborate.Core.elab_st_typing d) (Pulse.Elaborate.Pure.elab_comp c))
Prims.GTot
[ "sometrivial" ]
[]
[ "Pulse.Soundness.Common.stt_env", "Pulse.Syntax.Base.st_term", "Pulse.Syntax.Base.comp", "Pulse.Typing.st_typing", "Prims.b2t", "Pulse.Typing.uu___is_T_Lift", "Pulse.Soundness.Common.soundness_t", "Pulse.Typing.Env.env", "Pulse.Syntax.Base.comp_st", "Pulse.Typing.lift_comp", "Pulse.Syntax.Base.uu___is_C_STAtomic", "Pulse.Soundness.Lift.elab_lift_stt_atomic_st_typing", "Pulse.Elaborate.Core.elab_st_typing", "Pulse.Syntax.Base.uu___is_C_STGhost", "Pulse.Typing.non_informative_c", "Pulse.Syntax.Base.term", "Pulse.Typing.tot_typing", "Pulse.Typing.non_informative_witness_t", "Pulse.Syntax.Base.comp_u", "Pulse.Syntax.Base.comp_res", "Pulse.Soundness.Lift.elab_lift_ghost_neutral_typing", "Pulse.Elaborate.Pure.elab_term", "Pulse.Soundness.Common.tot_typing_soundness", "FStar.Reflection.Typing.tot_typing", "Pulse.Typing.elab_env", "Pulse.Elaborate.Pure.elab_comp", "Prims.l_and", "Prims.eq2", "Pulse.Syntax.Base.observability", "Pulse.Syntax.Base.__proj__C_STAtomic__item__obs", "Pulse.Syntax.Base.Neutral", "Pulse.Soundness.Lift.elab_lift_neutral_ghost_typing", "Pulse.Typing.sub_observability", "Pulse.Soundness.Lift.elab_lift_observability_typing", "Prims.unit", "Pulse.Typing.LN.st_typing_ln" ]
[]
false
false
false
false
false
let lift_soundness (g: stt_env) (t: st_term) (c: comp) (d: st_typing g t c {T_Lift? d}) (soundness: soundness_t d) : GTot (RT.tot_typing (elab_env g) (elab_st_typing d) (elab_comp c)) =
LN.st_typing_ln d; let T_Lift _ e c1 c2 e_typing lc = d in LN.st_typing_ln e_typing; match lc with | Lift_STAtomic_ST _ _ -> Lift.elab_lift_stt_atomic_st_typing g c1 c2 _ (soundness _ _ _ e_typing) lc | Lift_Ghost_Neutral _ _ w -> let (| reveal_a , reveal_a_typing |) = w in Lift.elab_lift_ghost_neutral_typing g c1 c2 _ (soundness _ _ _ e_typing) lc _ (tot_typing_soundness reveal_a_typing) | Lift_Neutral_Ghost _ _ -> Lift.elab_lift_neutral_ghost_typing g c1 c2 _ (soundness _ _ _ e_typing) lc | Lift_Observability _ _ _ -> Lift.elab_lift_observability_typing g c1 c2 _ (soundness _ _ _ e_typing) lc
false
Steel.ST.HigherArray.fsti
Steel.ST.HigherArray.blit
val blit (#t: _) (#p0: perm) (#s0 #s1: Ghost.erased (Seq.seq t)) (src: array t) (idx_src: US.t) (dst: array t) (idx_dst len: US.t) : ST unit ((pts_to src p0 s0) `star` (pts_to dst full_perm s1)) (fun _ -> (pts_to src p0 s0) `star` (exists_ (fun s1' -> (pts_to dst full_perm s1') `star` (pure (blit_post s0 s1 src idx_src dst idx_dst len s1'))))) (US.v idx_src + US.v len <= length src /\ US.v idx_dst + US.v len <= length dst) (fun _ -> True)
val blit (#t: _) (#p0: perm) (#s0 #s1: Ghost.erased (Seq.seq t)) (src: array t) (idx_src: US.t) (dst: array t) (idx_dst len: US.t) : ST unit ((pts_to src p0 s0) `star` (pts_to dst full_perm s1)) (fun _ -> (pts_to src p0 s0) `star` (exists_ (fun s1' -> (pts_to dst full_perm s1') `star` (pure (blit_post s0 s1 src idx_src dst idx_dst len s1'))))) (US.v idx_src + US.v len <= length src /\ US.v idx_dst + US.v len <= length dst) (fun _ -> True)
let blit (#t:_) (#p0:perm) (#s0 #s1:Ghost.erased (Seq.seq t)) (src:array t) (idx_src: US.t) (dst:array t) (idx_dst: US.t) (len: US.t) : ST unit (pts_to src p0 s0 `star` pts_to dst full_perm s1) (fun _ -> pts_to src p0 s0 `star` exists_ (fun s1' -> pts_to dst full_perm s1' `star` pure (blit_post s0 s1 src idx_src dst idx_dst len s1') )) ( US.v idx_src + US.v len <= length src /\ US.v idx_dst + US.v len <= length dst ) (fun _ -> True) = let (| p_src, len_src |) = src in vpattern_rewrite #_ #_ #src (fun src -> pts_to src p0 _) (| p_src, len_src |); let (| p_dst, len_dst |) = dst in vpattern_rewrite #_ #_ #dst (fun dst -> pts_to dst full_perm _) (| p_dst, len_dst |); blit_ptr p_src len_src idx_src p_dst len_dst idx_dst len; let _ = elim_exists () in elim_pure _; vpattern_rewrite #_ #_ #(| p_src, _ |) (fun src -> pts_to src p0 _) src; vpattern_rewrite #_ #_ #(| p_dst, _ |) (fun dst -> pts_to dst full_perm _) dst; noop ()
{ "file_name": "lib/steel/Steel.ST.HigherArray.fsti", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 9, "end_line": 547, "start_col": 0, "start_line": 521 }
(* Copyright 2022 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module Steel.ST.HigherArray /// C arrays of universe 1 elements. /// /// - Due to a limitation on the universe for selectors, no selector /// version can be defined for universe 1. /// - Due to F* universes not being cumulative, arrays of universe 0 /// elements need to be defined in a separate module. module P = Steel.FractionalPermission module US = FStar.SizeT module UP = FStar.PtrdiffT open Steel.ST.Util /// NOTE: This module is slated to have primitive Karamel extraction /// (except for definitions meant to be inlined.) /// An abstract type to represent a base array (whole allocation /// unit), exposed for proof purposes only [@@erasable] val base_t (elt: Type u#a) : Tot Type0 val base_len (#elt: Type) (b: base_t elt) : GTot nat /// An abstract type to represent a C pointer, as a base and an offset /// into its base [@@noextract_to "krml"] // primitive val ptr ([@@@unused] elt: Type u#a) : Type0 [@@noextract_to "krml"] val null_ptr (elt: Type u#a) : ptr elt // TODO: turn into a stateful operation to avoid comparing dangling pointers [@@noextract_to "krml"] val is_null_ptr (#elt: Type u#a) (p: ptr elt) : Pure bool (requires True) (ensures (fun res -> res == true <==> p == null_ptr elt)) val base (#elt: Type) (p: ptr elt) : Tot (base_t elt) val offset (#elt: Type) (p: ptr elt) : Ghost nat (requires True) (ensures (fun offset -> offset <= base_len (base p))) val ptr_base_offset_inj (#elt: Type) (p1 p2: ptr elt) : Lemma (requires ( base p1 == base p2 /\ offset p1 == offset p2 )) (ensures ( p1 == p2 )) val base_len_null_ptr (elt: Type u#a) : Lemma (base_len (base (null_ptr elt)) == 0) [SMTPat (base_len (base (null_ptr elt)))] /// A concrete type to represent a C array, as a C pointer and a ghost /// array length. By virtue of the length being ghost, Karamel will /// extract this type as just ptr, but to inline the definition of /// this type, we use standard dependent pairs instead of a custom /// record type. inline_for_extraction [@@noextract_to "krml"] let array ([@@@strictly_positive] elt: Type u#a) : Tot Type0 = (p: ptr elt & (length: Ghost.erased nat {offset p + length <= base_len (base p)})) inline_for_extraction [@@noextract_to "krml"] let null (#a: Type u#a) : array a = (| null_ptr a, Ghost.hide 0 |) /// This will extract to "let p = a" inline_for_extraction [@@noextract_to "krml"] let ptr_of (#elt: Type) (a: array elt) : Tot (ptr elt) = match a with // dfst is not marked inline_for_extraction, so we need to reimplement it | (| p, _ |) -> p inline_for_extraction [@@noextract_to "krml"] let is_null (#a: Type u#a) (p: array a) : Pure bool (requires True) (ensures (fun res -> res == true <==> p == null)) = is_null_ptr (ptr_of p) let length (#elt: Type) (a: array elt) : GTot nat = dsnd a val length_fits (#elt: Type) (a: array elt) : Lemma (US.fits (length a)) /// A Steel separation logic heap predicate to describe that an array /// a points to some element sequence s with some permission p. vprop /// limits the universe to at most 1 (because of the universe of the /// heap.) val pts_to (#elt: Type u#1) (a: array elt) (p: P.perm) ([@@@ smt_fallback ] s: Seq.seq elt) : Tot vprop /// A stateful lemma to relate the size of an array with the size /// of the element sequence it points to val pts_to_length (#opened: _) (#elt: Type u#1) (#p: P.perm) (a: array elt) (s: Seq.seq elt) : STGhost unit opened (pts_to a p s) (fun _ -> pts_to a p s) (True) (fun _ -> Seq.length s == length a) val pts_to_not_null (#opened: _) (#elt: Type u#1) (#p: P.perm) (a: array elt) (s: Seq.seq elt) : STGhost unit opened (pts_to a p s) (fun _ -> pts_to a p s) (True) (fun _ -> a =!= null) /// An injectivity property, needed only to define a selector. Such a /// selector can be only defined in universe 0, and universes are not /// cumulative, so we need to define a separate module for arrays of /// universe 0 elements with selectors, reusing definitions from this /// interface, but we do not want to use `friend`. val pts_to_inj (#elt: Type u#1) (a: array elt) (p1: P.perm) (s1: Seq.seq elt) (p2: P.perm) (s2: Seq.seq elt) (m: mem) : Lemma (requires ( interp (hp_of (pts_to a p1 s1)) m /\ interp (hp_of (pts_to a p2 s2)) m )) (ensures ( s1 == s2 )) /// Allocating a new array of size n, where each cell is initialized /// with value x. We expose a pointer version for extraction purposes [@@noextract_to "krml"] // primitive val malloc_ptr (#elt: Type) (x: elt) (n: US.t) : STT(a: ptr elt { base_len (base a) == US.v n /\ offset a == 0 }) emp (fun a -> pts_to (| a, Ghost.hide (US.v n) |) P.full_perm (Seq.create (US.v n) x)) /// Allocating a new array of size n, where each cell is initialized /// with value x let is_full_array (#elt: Type) (a: array elt) : Tot prop = length a == base_len (base (ptr_of a)) inline_for_extraction [@@noextract_to "krml"] let malloc (#elt: Type) (x: elt) (n: US.t) : ST (array elt) emp (fun a -> pts_to a P.full_perm (Seq.create (US.v n) x)) (True) (fun a -> length a == US.v n /\ is_full_array a ) = let p = malloc_ptr x n in let a : array elt = (| p, Ghost.hide (US.v n) |) in rewrite (pts_to _ _ _) (pts_to a _ _); return a /// Freeing a full array. Same here, we expose a ptr version for extraction purposes only [@@ noextract_to "krml"; // primitive warn_on_use "Steel.HigherArray.free is currently unsound in the presence of zero-size subarrays, have you collected them all?"] val free_ptr (#elt: Type) (#s: Ghost.erased (Seq.seq elt)) (a: ptr elt { offset a == 0 }) : STT unit (pts_to (| a, Ghost.hide #nat (base_len (base a)) |) P.full_perm s) (fun _ -> emp) inline_for_extraction [@@ noextract_to "krml"; warn_on_use "Steel.HigherArray.free is currently unsound in the presence of zero-size subarrays, have you collected them all?"] let free (#elt: Type) (a: array elt) : ST unit (exists_ (pts_to a P.full_perm)) (fun _ -> emp) ( is_full_array a ) (fun _ -> True) = let (| p, v |) = a in let _ : squash (offset p == 0) = () in let s = elim_exists () in rewrite (pts_to _ _ _) (pts_to (| p, Ghost.hide (base_len (base p)) |) full_perm s); free_ptr p /// Sharing and gathering permissions on an array. Those only /// manipulate permissions, so they are nothing more than stateful /// lemmas. val share (#opened: _) (#elt: Type) (#x: Seq.seq elt) (a: array elt) (p p1 p2: P.perm) : STGhost unit opened (pts_to a p x) (fun _ -> pts_to a p1 x `star` pts_to a p2 x) (p == p1 `P.sum_perm` p2) (fun _ -> True) val gather (#opened: _) (#elt: Type) (a: array elt) (#x1: Seq.seq elt) (p1: P.perm) (#x2: Seq.seq elt) (p2: P.perm) : STGhost unit opened (pts_to a p1 x1 `star` pts_to a p2 x2) (fun _ -> pts_to a (p1 `P.sum_perm` p2) x1) (True) (fun _ -> x1 == x2) /// Reading the i-th element of an array a. /// TODO: we should also provide an atomic version for small types. [@@noextract_to "krml"] // primitive val index_ptr (#t: Type) (#p: P.perm) (a: ptr t) (#len: Ghost.erased nat { offset a + len <= base_len (base a) }) (#s: Ghost.erased (Seq.seq t)) (i: US.t) : ST t (pts_to (| a, len |) p s) (fun _ -> pts_to (| a, len |) p s) (US.v i < Ghost.reveal len \/ US.v i < Seq.length s) (fun res -> Seq.length s == Ghost.reveal len /\ US.v i < Seq.length s /\ res == Seq.index s (US.v i)) inline_for_extraction [@@noextract_to "krml"] // primitive let index (#t: Type) (#p: P.perm) (a: array t) (#s: Ghost.erased (Seq.seq t)) (i: US.t) : ST t (pts_to a p s) (fun _ -> pts_to a p s) (US.v i < length a \/ US.v i < Seq.length s) (fun res -> Seq.length s == length a /\ US.v i < Seq.length s /\ res == Seq.index s (US.v i)) = rewrite (pts_to _ _ _) (pts_to (| (ptr_of a), (dsnd a) |) p s); let res = index_ptr (ptr_of a) i in rewrite (pts_to _ _ _) (pts_to a p s); return res /// Writing the value v at the i-th element of an array a. /// TODO: we should also provide an atomic version for small types. [@@noextract_to "krml"] // primitive val upd_ptr (#t: Type) (a: ptr t) (#len: Ghost.erased nat { offset a + len <= base_len (base a) }) (#s: Ghost.erased (Seq.seq t)) (i: US.t { US.v i < Seq.length s }) (v: t) : STT unit (pts_to (| a, len |) P.full_perm s) (fun res -> pts_to (| a, len |) P.full_perm (Seq.upd s (US.v i) v)) inline_for_extraction [@@noextract_to "krml"] let upd (#t: Type) (a: array t) (#s: Ghost.erased (Seq.seq t)) (i: US.t { US.v i < Seq.length s }) (v: t) : STT unit (pts_to a P.full_perm s) (fun res -> pts_to a P.full_perm (Seq.upd s (US.v i) v)) = rewrite (pts_to _ _ _) (pts_to (| ptr_of a, (dsnd a) |) _ s); upd_ptr (ptr_of a) i v; rewrite (pts_to _ _ _) (pts_to _ _ _) /// An array a1 is adjacent to an array a2 if and only if they have /// the same base array and the end of a1 coincides with the beginning /// of a2 let adjacent (#elt: Type) (a1 a2: array elt) : Tot prop = base (ptr_of a1) == base (ptr_of a2) /\ offset (ptr_of a1) + (length a1) == offset (ptr_of a2) /// If two arrays are adjacent, then we can compute their merge, with /// their combined lengths. By virtue of the length being ghost, /// Karamel will extract it as "let y = a1" inline_for_extraction [@@noextract_to "krml"] let merge (#elt: Type) (a1: array elt) (a2: Ghost.erased (array elt)) : Pure (array elt) (requires (adjacent a1 a2)) (ensures (fun y -> length y == length a1 + length a2)) = (| ptr_of a1, Ghost.hide (length a1 + length a2) |) /// Adjacency and merging are associative. let merge_assoc (#elt: Type) (a1 a2 a3: array elt) : Lemma (requires ( (adjacent a1 a2 /\ adjacent a2 a3) \/ (adjacent a1 a2 /\ adjacent (merge a1 a2) a3) \/ (adjacent a2 a3 /\ adjacent a1 (merge a2 a3)) )) (ensures ( adjacent (merge a1 a2) a3 /\ adjacent a1 (merge a2 a3) /\ merge (merge a1 a2) a3 == merge a1 (merge a2 a3) )) = () /// A shortcut to combine adjacency and merging let merge_into (#elt: Type) (a1 a2 a: array elt) : Tot prop = adjacent a1 a2 /\ merge a1 a2 == a /// Spatial merging of two arrays, expressed in terms of `merge`. val ghost_join (#opened: _) (#elt: Type) (#x1 #x2: Seq.seq elt) (#p: P.perm) (a1 a2: array elt) (h: squash (adjacent a1 a2)) : STGhostT unit opened (pts_to a1 p x1 `star` pts_to a2 p x2) (fun res -> pts_to (merge a1 a2) p (x1 `Seq.append` x2)) /// Spatial merging, combining the use of `merge` and the call to the /// stateful lemma. Since the only operations are calls to stateful /// lemmas and pure computations, the overall computation is atomic /// and unobservable, so can be used anywhere in atomic contexts. By /// virtue of the length being ghost, Karamel will extract this to /// "let res = a1" inline_for_extraction // this will extract to "let res = a1" [@@noextract_to "krml"] let join (#opened: _) (#elt: Type) (#x1 #x2: Ghost.erased (Seq.seq elt)) (#p: P.perm) (a1: array elt) (a2: Ghost.erased (array elt)) : STAtomicBase (array elt) false opened Unobservable (pts_to a1 p x1 `star` pts_to a2 p x2) (fun res -> pts_to res p (x1 `Seq.append` x2)) (adjacent a1 a2) (fun res -> merge_into a1 a2 res) = let _ : squash (adjacent a1 a2) = () in ghost_join a1 a2 (); let res = merge a1 a2 in rewrite (pts_to (merge a1 (Ghost.hide (Ghost.reveal a2))) p (x1 `Seq.append` x2)) (pts_to res p (x1 `Seq.append` x2)); return res /// Computing the left-hand-side part of splitting an array a at /// offset i. By virtue of the length being ghost, Karamel will /// extract this to "let y = a" inline_for_extraction // this will extract to "let y = a" [@@noextract_to "krml"] let split_l (#elt: Type) (a: array elt) (i: Ghost.erased US.t) : Pure (array elt) (requires (US.v i <= length a)) (ensures (fun y -> True)) = (| ptr_of a, Ghost.hide (US.v i) |) /// C pointer arithmetic to compute (p+off), shifting a pointer p by /// offset off. TODO: replace this with a Ghost definition and a /// STAtomicBase Unobservable operation with the corresponding /// permission. [@@noextract_to "krml"] // primitive val ptr_shift (#elt: Type) (p: ptr elt) (off: US.t) : Pure (ptr elt) (requires (offset p + US.v off <= base_len (base p))) (ensures (fun p' -> base p' == base p /\ offset p' == offset p + US.v off )) let ptr_shift_zero (#elt: Type) (p: ptr elt) : Lemma (ptr_shift p 0sz == p) = ptr_base_offset_inj (ptr_shift p 0sz) p /// Computing the right-hand-side part of splitting an array a at /// offset i. inline_for_extraction [@@noextract_to "krml"] let split_r (#elt: Type) (a: array elt) (i: US.t) : Pure (array elt) (requires (US.v i <= length a)) (ensures (fun y -> merge_into (split_l a i) y a)) = (| ptr_shift (ptr_of a) i, Ghost.hide (length a - US.v i) |) /// Splitting an array a at offset i, as a stateful lemma expressed in /// terms of split_l, split_r. This stateful lemma returns a proof /// that offset i is in bounds of the value sequence, which is needed to /// typecheck the post-resource. val ghost_split (#opened: _) (#elt: Type) (#x: Seq.seq elt) (#p: P.perm) (a: array elt) (i: US.t) : STGhost (squash (US.v i <= length a /\ US.v i <= Seq.length x)) opened (pts_to a p x) (fun res -> pts_to (split_l a i) p (Seq.slice x 0 (US.v i)) `star` pts_to (split_r a i) p (Seq.slice x (US.v i) (Seq.length x))) (US.v i <= length a) (fun res -> x == Seq.append (Seq.slice x 0 (US.v i)) (Seq.slice x (US.v i) (Seq.length x)) ) /// NOTE: we could implement a STAtomicBase Unobservable "split" /// operation, just like "join", but we don't want it to return a pair /// of arrays. For now we settle on explicit use of split_l, split_r. /// Copies the contents of a0 to a1 let blit_post (#t:_) (s0 s1:Ghost.erased (Seq.seq t)) (src:array t) (idx_src: US.t) (dst:array t) (idx_dst: US.t) (len: US.t) (s1' : Seq.seq t) : Tot prop = US.v idx_src + US.v len <= length src /\ US.v idx_dst + US.v len <= length dst /\ length src == Seq.length s0 /\ length dst == Seq.length s1 /\ Seq.length s1' == Seq.length s1 /\ Seq.slice s1' (US.v idx_dst) (US.v idx_dst + US.v len) `Seq.equal` Seq.slice s0 (US.v idx_src) (US.v idx_src + US.v len) /\ Seq.slice s1' 0 (US.v idx_dst) `Seq.equal` Seq.slice s1 0 (US.v idx_dst) /\ Seq.slice s1' (US.v idx_dst + US.v len) (length dst) `Seq.equal` Seq.slice s1 (US.v idx_dst + US.v len) (length dst) [@@noextract_to "krml"] // primitive val blit_ptr (#t:_) (#p0:perm) (#s0 #s1:Ghost.erased (Seq.seq t)) (src:ptr t) (len_src: Ghost.erased nat { offset src + len_src <= base_len (base src) }) (idx_src: US.t) (dst:ptr t) (len_dst: Ghost.erased nat { offset dst + len_dst <= base_len (base dst) }) (idx_dst: US.t) (len: US.t) : ST unit (pts_to (| src, len_src |) p0 s0 `star` pts_to (| dst, len_dst |) full_perm s1) (fun _ -> pts_to (| src, len_src |) p0 s0 `star` exists_ (fun s1' -> pts_to (| dst, len_dst |) full_perm s1' `star` pure (blit_post s0 s1 (| src, len_src |) idx_src (| dst, len_dst |) idx_dst len s1') )) ( US.v idx_src + US.v len <= len_src /\ US.v idx_dst + US.v len <= len_dst ) (fun _ -> True) inline_for_extraction
{ "checked_file": "/", "dependencies": [ "Steel.ST.Util.fsti.checked", "Steel.FractionalPermission.fst.checked", "prims.fst.checked", "FStar.SizeT.fsti.checked", "FStar.Seq.fst.checked", "FStar.PtrdiffT.fsti.checked", "FStar.Pervasives.fsti.checked", "FStar.Int.fsti.checked", "FStar.Ghost.fsti.checked" ], "interface_file": false, "source_file": "Steel.ST.HigherArray.fsti" }
[ { "abbrev": false, "full_module": "Steel.ST.Util", "short_module": null }, { "abbrev": true, "full_module": "FStar.PtrdiffT", "short_module": "UP" }, { "abbrev": true, "full_module": "FStar.SizeT", "short_module": "US" }, { "abbrev": true, "full_module": "Steel.FractionalPermission", "short_module": "P" }, { "abbrev": false, "full_module": "Steel.ST", "short_module": null }, { "abbrev": false, "full_module": "Steel.ST", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
src: Steel.ST.HigherArray.array t -> idx_src: FStar.SizeT.t -> dst: Steel.ST.HigherArray.array t -> idx_dst: FStar.SizeT.t -> len: FStar.SizeT.t -> Steel.ST.Effect.ST Prims.unit
Steel.ST.Effect.ST
[]
[]
[ "Steel.FractionalPermission.perm", "FStar.Ghost.erased", "FStar.Seq.Base.seq", "Steel.ST.HigherArray.array", "FStar.SizeT.t", "Steel.ST.HigherArray.ptr", "Prims.nat", "Prims.b2t", "Prims.op_LessThanOrEqual", "Prims.op_Addition", "Steel.ST.HigherArray.offset", "FStar.Ghost.reveal", "Steel.ST.HigherArray.base_len", "Steel.ST.HigherArray.base", "Steel.ST.Util.noop", "FStar.Ghost.hide", "FStar.Set.set", "Steel.Memory.iname", "FStar.Set.empty", "Prims.unit", "Steel.ST.Util.vpattern_rewrite", "Prims.Mkdtuple2", "Steel.ST.HigherArray.pts_to", "Steel.FractionalPermission.full_perm", "Steel.Effect.Common.vprop", "Steel.ST.Util.elim_pure", "Steel.ST.HigherArray.blit_post", "Steel.ST.Util.elim_exists", "Steel.Effect.Common.VStar", "Steel.ST.Util.pure", "Steel.ST.HigherArray.blit_ptr", "Steel.Effect.Common.star", "Steel.ST.Util.exists_", "Prims.l_and", "FStar.SizeT.v", "Steel.ST.HigherArray.length", "Prims.l_True" ]
[]
false
true
false
false
false
let blit (#t: _) (#p0: perm) (#s0 #s1: Ghost.erased (Seq.seq t)) (src: array t) (idx_src: US.t) (dst: array t) (idx_dst len: US.t) : ST unit ((pts_to src p0 s0) `star` (pts_to dst full_perm s1)) (fun _ -> (pts_to src p0 s0) `star` (exists_ (fun s1' -> (pts_to dst full_perm s1') `star` (pure (blit_post s0 s1 src idx_src dst idx_dst len s1'))))) (US.v idx_src + US.v len <= length src /\ US.v idx_dst + US.v len <= length dst) (fun _ -> True) =
let (| p_src , len_src |) = src in vpattern_rewrite #_ #_ #src (fun src -> pts_to src p0 _) (| p_src, len_src |); let (| p_dst , len_dst |) = dst in vpattern_rewrite #_ #_ #dst (fun dst -> pts_to dst full_perm _) (| p_dst, len_dst |); blit_ptr p_src len_src idx_src p_dst len_dst idx_dst len; let _ = elim_exists () in elim_pure _; vpattern_rewrite #_ #_ #(| p_src, _ |) (fun src -> pts_to src p0 _) src; vpattern_rewrite #_ #_ #(| p_dst, _ |) (fun dst -> pts_to dst full_perm _) dst; noop ()
false
Pulse.Soundness.fst
Pulse.Soundness.bind_soundness
val bind_soundness (#g: stt_env) (#t: st_term) (#c: comp) (d: st_typing g t c {T_Bind? d}) (soundness: soundness_t d) (mk_t_abs: tabs_t d) : GTot (RT.tot_typing (elab_env g) (elab_st_typing d) (elab_comp c))
val bind_soundness (#g: stt_env) (#t: st_term) (#c: comp) (d: st_typing g t c {T_Bind? d}) (soundness: soundness_t d) (mk_t_abs: tabs_t d) : GTot (RT.tot_typing (elab_env g) (elab_st_typing d) (elab_comp c))
let bind_soundness (#g:stt_env) (#t:st_term) (#c:comp) (d:st_typing g t c{T_Bind? d}) (soundness: soundness_t d) (mk_t_abs: tabs_t d) : GTot (RT.tot_typing (elab_env g) (elab_st_typing d) (elab_comp c)) = let T_Bind _ e1 e2 c1 c2 _ x c e1_typing t_typing e2_typing bc = d in LN.st_typing_ln e1_typing; LN.st_typing_ln e2_typing; FV.st_typing_freevars_inv e1_typing x; let r1_typing : RT.tot_typing _ _ (elab_comp c1) = soundness _ _ _ e1_typing in let r2_typing : RT.tot_typing _ _ (elab_term (tm_arrow (null_binder (comp_res c1)) None (close_comp c2 x))) = mk_t_abs None _ t_typing e2_typing in match bc with | Bind_comp _ _ _ _ t2_typing y post2_typing -> Bind.elab_bind_typing g _ _ _ x _ r1_typing _ r2_typing bc (tot_typing_soundness t2_typing) (mk_t_abs_tot _ ppname_default t2_typing post2_typing)
{ "file_name": "lib/steel/pulse/Pulse.Soundness.fst", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 85, "end_line": 266, "start_col": 0, "start_line": 240 }
(* Copyright 2023 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module Pulse.Soundness module RT = FStar.Reflection.Typing module R = FStar.Reflection.V2 module L = FStar.List.Tot module T = FStar.Tactics.V2 open FStar.List.Tot open Pulse.Syntax open Pulse.Reflection.Util open Pulse.Typing open Pulse.Elaborate open Pulse.Soundness.Common module Bind = Pulse.Soundness.Bind module Lift = Pulse.Soundness.Lift module Frame = Pulse.Soundness.Frame module STEquiv = Pulse.Soundness.STEquiv module Return = Pulse.Soundness.Return module Exists = Pulse.Soundness.Exists module While = Pulse.Soundness.While module Admit = Pulse.Soundness.Admit module Par = Pulse.Soundness.Par module WithLocal = Pulse.Soundness.WithLocal module WithLocalArray = Pulse.Soundness.WithLocalArray module Rewrite = Pulse.Soundness.Rewrite module Comp = Pulse.Soundness.Comp module LN = Pulse.Typing.LN module FV = Pulse.Typing.FV module STT = Pulse.Soundness.STT module Sub = Pulse.Soundness.Sub module RU = Pulse.RuntimeUtils module Typing = Pulse.Typing module EPure = Pulse.Elaborate.Pure module WT= Pulse.Steel.Wrapper.Typing let tabs_t (d:'a) = #g:stt_env -> #u:universe -> #ty:term -> q:option qualifier -> ppname:ppname -> t_typing:tot_typing g ty (tm_type u) { t_typing << d } -> #body:st_term -> #x:var { None? (lookup g x) /\ ~(x `Set.mem` freevars_st body) } -> #c:comp -> body_typing:st_typing (push_binding g x ppname ty) (open_st_term body x) c { body_typing << d } -> GTot (RT.tot_typing (elab_env g) (mk_abs_with_name ppname.name (elab_term ty) (elab_qual q) (RT.close_term (elab_st_typing body_typing) x)) (elab_term (tm_arrow (mk_binder_ppname ty ppname) q (close_comp c x)))) #push-options "--z3rlimit_factor 4 --split_queries no" let lift_soundness (g:stt_env) (t:st_term) (c:comp) (d:st_typing g t c{T_Lift? d}) (soundness:soundness_t d) : GTot (RT.tot_typing (elab_env g) (elab_st_typing d) (elab_comp c)) = LN.st_typing_ln d; let T_Lift _ e c1 c2 e_typing lc = d in LN.st_typing_ln e_typing; match lc with | Lift_STAtomic_ST _ _ -> Lift.elab_lift_stt_atomic_st_typing g c1 c2 _ (soundness _ _ _ e_typing) lc | Lift_Ghost_Neutral _ _ w -> let (| reveal_a, reveal_a_typing |) = w in Lift.elab_lift_ghost_neutral_typing g c1 c2 _ (soundness _ _ _ e_typing) lc _ (tot_typing_soundness reveal_a_typing) | Lift_Neutral_Ghost _ _ -> Lift.elab_lift_neutral_ghost_typing g c1 c2 _ (soundness _ _ _ e_typing) lc | Lift_Observability _ _ _ -> Lift.elab_lift_observability_typing g c1 c2 _ (soundness _ _ _ e_typing) lc #pop-options let frame_soundness (g:stt_env) (t:st_term) (c:comp) (d:st_typing g t c{T_Frame? d}) (soundness:soundness_t d) : GTot (RT.tot_typing (elab_env g) (elab_st_typing d) (elab_comp c)) = let T_Frame _ e c frame frame_typing e_typing = d in let r_e_typing = soundness _ _ _ e_typing in LN.st_typing_ln e_typing; Frame.elab_frame_typing g _ _ frame frame_typing r_e_typing let stapp_soundness (g:stt_env) (t:st_term) (c:comp) (d:st_typing g t c{T_STApp? d}) (soundness:soundness_t d) : GTot (RT.tot_typing (elab_env g) (elab_st_typing d) (elab_comp c)) = let T_STApp _ head formal q res arg head_typing arg_typing = d in let r_head = elab_term head in let r_arg = elab_term arg in let r_head_typing : RT.tot_typing _ r_head (elab_term (tm_arrow (mk_binder_ppname formal ppname_default) q res)) = tot_typing_soundness head_typing in let r_arg_typing = tot_typing_soundness arg_typing in RT.T_App _ _ _ (binder_of_t_q_s (elab_term formal) (elab_qual q) RT.pp_name_default) (elab_comp res) _ r_head_typing r_arg_typing // // We have G |- head : Ghost (x:t -> Total res) -- (1) // G |- arg : Ghost t -- (2) // G,x:t |- non_informative (open res x) -- (3) // // We first lift (1) to G |- head : Ghost (x:t -> Ghost res) // Then apply T_App in reflection typing to derive // G |- head arg : Ghost (open res arg) -- (4) // and then promote (4) to Total using a substitution lemma on (3) // let stghostapp_soundness (g:stt_env) (t:st_term) (c:comp) (d:st_typing g t c{T_STGhostApp? d}) (soundness:soundness_t d) : GTot (RT.tot_typing (elab_env g) (elab_st_typing d) (elab_comp c)) = let T_STGhostApp _ head formal q res arg x head_typing d_non_info arg_typing = d in let r_head = elab_term head in let r_arg = elab_term arg in let r_binder = mk_binder_ppname formal ppname_default in let head_t = tm_arrow r_binder q res in let r_head_t = mk_arrow_with_name ppname_default.name (elab_term formal, elab_qual q) (elab_comp res) in let r_head_typing : RT.ghost_typing _ r_head r_head_t = ghost_typing_soundness head_typing in let r_arg_typing = ghost_typing_soundness arg_typing in assume (elab_env (push_binding g x ppname_default formal) == RT.extend_env (elab_env g) x (elab_term formal)); assume ((T.E_Total, elab_comp (open_comp_with res (null_var x))) == RT.open_comp_typ (T.E_Total, elab_comp res) x); assume ((T.E_Ghost, elab_comp (open_comp_with res (null_var x))) == RT.open_comp_typ (T.E_Ghost, elab_comp res) x); let d_rel_comp : RT.related_comp (elab_env (push_binding g x ppname_default formal)) (T.E_Total, elab_comp (open_comp_with res (null_var x))) RT.R_Sub (T.E_Ghost, elab_comp (open_comp_with res (null_var x))) = RT.Relc_total_ghost _ _ in let r_head_t_ghost = mk_ghost_arrow_with_name ppname_default.name (elab_term formal, elab_qual q) (elab_comp res) in assert (r_head_t == RT.mk_arrow_ct (elab_term formal) (elab_qual q) (T.E_Total, elab_comp res)); assert (r_head_t_ghost == RT.mk_arrow_ct (elab_term formal) (elab_qual q) (T.E_Ghost, elab_comp res)); assume (None? (RT.lookup_bvar (elab_env g) x) /\ ~ (x `Set.mem` ((RT.freevars_comp_typ (T.E_Total, elab_comp res)) `Set.union` (RT.freevars_comp_typ (T.E_Ghost, elab_comp res))))); let d_rel_t_arrow : RT.related (elab_env g) r_head_t RT.R_Sub r_head_t_ghost = RT.Rel_arrow _ (elab_term formal) (elab_term formal) (elab_qual q) (T.E_Total, elab_comp res) (T.E_Ghost, elab_comp res) RT.R_Sub x (RT.Rel_equiv _ _ _ _ (RT.Rel_refl _ _ _)) d_rel_comp in let r_head_typing : RT.ghost_typing _ r_head r_head_t_ghost = RT.T_Sub _ _ _ _ r_head_typing (RT.Relc_typ _ _ _ T.E_Ghost _ d_rel_t_arrow) in let d : RT.typing (elab_env g) (elab_st_typing d) (T.E_Ghost, elab_comp (open_comp_with res arg)) = RT.T_App _ _ _ (binder_of_t_q_s (elab_term formal) (elab_qual q) RT.pp_name_default) (elab_comp res) _ r_head_typing r_arg_typing in let E d_non_info = d_non_info in let d_non_info : RT.non_informative (elab_env (push_binding g x ppname_default formal)) (elab_comp (open_comp_with res (null_var x))) = d_non_info in // TODO: substitution lemma in RT for non_informative judgment let d_non_info : RT.non_informative (elab_env g) (elab_comp (open_comp_with res arg)) = RU.magic () in RT.T_Sub _ _ _ _ d (RT.Relc_ghost_total _ _ d_non_info) let stequiv_soundness (g:stt_env) (t:st_term) (c:comp) (d:st_typing g t c{T_Equiv? d}) (soundness:soundness_t d) : GTot (RT.tot_typing (elab_env g) (elab_st_typing d) (elab_comp c)) = let T_Equiv _ e c c' e_typing equiv = d in LN.st_typing_ln d; LN.st_typing_ln e_typing; let r_e_typing = soundness _ _ _ e_typing in match equiv with | ST_TotEquiv _ t1 t2 _ _ eq -> let r_e_typing : RT.tot_typing (elab_env g) (elab_st_typing e_typing) (elab_term t1) = r_e_typing in let eq = RT.Rel_equiv _ _ _ RT.R_Sub eq in RT.T_Sub _ _ _ _ r_e_typing (RT.Relc_typ _ _ _ _ _ eq) | _ -> STEquiv.st_equiv_soundness _ _ _ equiv _ r_e_typing #push-options "--query_stats --fuel 2 --ifuel 2 --z3rlimit_factor 30"
{ "checked_file": "/", "dependencies": [ "Pulse.Typing.LN.fsti.checked", "Pulse.Typing.FV.fsti.checked", "Pulse.Typing.fst.checked", "Pulse.Syntax.fst.checked", "Pulse.Steel.Wrapper.Typing.fsti.checked", "Pulse.Soundness.WithLocalArray.fsti.checked", "Pulse.Soundness.WithLocal.fsti.checked", "Pulse.Soundness.While.fsti.checked", "Pulse.Soundness.Sub.fsti.checked", "Pulse.Soundness.STT.fsti.checked", "Pulse.Soundness.STEquiv.fsti.checked", "Pulse.Soundness.Rewrite.fsti.checked", "Pulse.Soundness.Return.fsti.checked", "Pulse.Soundness.Par.fsti.checked", "Pulse.Soundness.Match.fsti.checked", "Pulse.Soundness.Lift.fsti.checked", "Pulse.Soundness.Frame.fsti.checked", "Pulse.Soundness.Exists.fsti.checked", "Pulse.Soundness.Comp.fsti.checked", "Pulse.Soundness.Common.fst.checked", "Pulse.Soundness.Bind.fsti.checked", "Pulse.Soundness.Admit.fsti.checked", "Pulse.RuntimeUtils.fsti.checked", "Pulse.Reflection.Util.fst.checked", "Pulse.Elaborate.Pure.fst.checked", "Pulse.Elaborate.fsti.checked", "prims.fst.checked", "FStar.Tactics.V2.fst.checked", "FStar.Squash.fsti.checked", "FStar.Set.fsti.checked", "FStar.Reflection.V2.fst.checked", "FStar.Reflection.Typing.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked" ], "interface_file": true, "source_file": "Pulse.Soundness.fst" }
[ { "abbrev": true, "full_module": "Pulse.Steel.Wrapper.Typing", "short_module": "WT" }, { "abbrev": true, "full_module": "Pulse.Elaborate.Pure", "short_module": "EPure" }, { "abbrev": true, "full_module": "Pulse.Typing", "short_module": "Typing" }, { "abbrev": true, "full_module": "Pulse.RuntimeUtils", "short_module": "RU" }, { "abbrev": true, "full_module": "Pulse.Soundness.Sub", "short_module": "Sub" }, { "abbrev": true, "full_module": "Pulse.Soundness.STT", "short_module": "STT" }, { "abbrev": true, "full_module": "Pulse.Typing.FV", "short_module": "FV" }, { "abbrev": true, "full_module": "Pulse.Typing.LN", "short_module": "LN" }, { "abbrev": true, "full_module": "Pulse.Soundness.Comp", "short_module": "Comp" }, { "abbrev": true, "full_module": "Pulse.Soundness.Rewrite", "short_module": "Rewrite" }, { "abbrev": true, "full_module": "Pulse.Soundness.WithLocalArray", "short_module": "WithLocalArray" }, { "abbrev": true, "full_module": "Pulse.Soundness.WithLocal", "short_module": "WithLocal" }, { "abbrev": true, "full_module": "Pulse.Soundness.Par", "short_module": "Par" }, { "abbrev": true, "full_module": "Pulse.Soundness.Admit", "short_module": "Admit" }, { "abbrev": true, "full_module": "Pulse.Soundness.While", "short_module": "While" }, { "abbrev": true, "full_module": "Pulse.Soundness.Exists", "short_module": "Exists" }, { "abbrev": true, "full_module": "Pulse.Soundness.Return", "short_module": "Return" }, { "abbrev": true, "full_module": "Pulse.Soundness.STEquiv", "short_module": "STEquiv" }, { "abbrev": true, "full_module": "Pulse.Soundness.Frame", "short_module": "Frame" }, { "abbrev": true, "full_module": "Pulse.Soundness.Lift", "short_module": "Lift" }, { "abbrev": true, "full_module": "Pulse.Soundness.Bind", "short_module": "Bind" }, { "abbrev": false, "full_module": "Pulse.Soundness.Common", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Elaborate", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Typing", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Reflection.Util", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Syntax", "short_module": null }, { "abbrev": false, "full_module": "FStar.List.Tot", "short_module": null }, { "abbrev": true, "full_module": "FStar.Tactics.V2", "short_module": "T" }, { "abbrev": true, "full_module": "FStar.List.Tot", "short_module": "L" }, { "abbrev": true, "full_module": "FStar.Reflection.V2", "short_module": "R" }, { "abbrev": true, "full_module": "FStar.Reflection.Typing", "short_module": "RT" }, { "abbrev": false, "full_module": "Pulse.Soundness.Common", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Elaborate", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Typing", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Reflection.Util", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Syntax", "short_module": null }, { "abbrev": false, "full_module": "FStar.List.Tot", "short_module": null }, { "abbrev": true, "full_module": "FStar.Tactics.V2", "short_module": "T" }, { "abbrev": true, "full_module": "FStar.List.Tot", "short_module": "L" }, { "abbrev": true, "full_module": "FStar.Reflection.V2", "short_module": "R" }, { "abbrev": true, "full_module": "FStar.Reflection.Typing", "short_module": "RT" }, { "abbrev": false, "full_module": "Pulse", "short_module": null }, { "abbrev": false, "full_module": "Pulse", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 2, "max_fuel": 2, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 30, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
d: Pulse.Typing.st_typing g t c {T_Bind? d} -> soundness: Pulse.Soundness.Common.soundness_t d -> mk_t_abs: Pulse.Soundness.tabs_t d -> Prims.GTot (FStar.Reflection.Typing.tot_typing (Pulse.Typing.elab_env g) (Pulse.Elaborate.Core.elab_st_typing d) (Pulse.Elaborate.Pure.elab_comp c))
Prims.GTot
[ "sometrivial" ]
[]
[ "Pulse.Soundness.Common.stt_env", "Pulse.Syntax.Base.st_term", "Pulse.Syntax.Base.comp", "Pulse.Typing.st_typing", "Prims.b2t", "Pulse.Typing.uu___is_T_Bind", "Pulse.Soundness.Common.soundness_t", "Pulse.Soundness.tabs_t", "Pulse.Typing.Env.env", "Pulse.Syntax.Base.comp_st", "Pulse.Syntax.Base.binder", "Prims.eq2", "Pulse.Syntax.Base.term", "Pulse.Syntax.Base.__proj__Mkbinder__item__binder_ty", "Pulse.Syntax.Base.comp_res", "Pulse.Syntax.Base.var", "Prims.l_and", "FStar.Pervasives.Native.uu___is_None", "Pulse.Syntax.Base.typ", "Pulse.Typing.Env.lookup", "Prims.l_not", "FStar.Set.mem", "Pulse.Syntax.Naming.freevars_st", "Pulse.Typing.tot_typing", "Pulse.Syntax.Pure.tm_type", "Pulse.Syntax.Base.comp_u", "Pulse.Typing.Env.push_binding", "Pulse.Syntax.Base.ppname_default", "Pulse.Syntax.Naming.open_st_term_nv", "FStar.Pervasives.Native.Mktuple2", "Pulse.Syntax.Base.ppname", "Pulse.Syntax.Base.__proj__Mkbinder__item__binder_ppname", "Pulse.Typing.bind_comp", "Pulse.Typing.bind_comp_pre", "Pulse.Typing.universe_of", "Pulse.Syntax.Naming.freevars", "Pulse.Syntax.Base.comp_post", "Pulse.Syntax.Naming.open_term", "Pulse.Syntax.Base.tm_vprop", "Pulse.Soundness.Bind.elab_bind_typing", "Pulse.Elaborate.Core.elab_st_typing", "Pulse.Reflection.Util.mk_abs_with_name", "Pulse.Syntax.Base.__proj__Mkppname__item__name", "Pulse.Elaborate.Pure.elab_term", "Pulse.Elaborate.Pure.elab_qual", "FStar.Pervasives.Native.None", "Pulse.Syntax.Base.qualifier", "FStar.Reflection.Typing.close_term", "Pulse.Syntax.Naming.open_st_term", "Pulse.Soundness.Common.tot_typing_soundness", "Pulse.Soundness.Common.mk_t_abs_tot", "FStar.Reflection.Typing.tot_typing", "Pulse.Typing.elab_env", "Pulse.Elaborate.Pure.elab_comp", "Pulse.Syntax.Pure.tm_arrow", "Pulse.Syntax.Base.null_binder", "Pulse.Syntax.Naming.close_comp", "Prims.unit", "Pulse.Typing.FV.st_typing_freevars_inv", "Pulse.Typing.LN.st_typing_ln" ]
[]
false
false
false
false
false
let bind_soundness (#g: stt_env) (#t: st_term) (#c: comp) (d: st_typing g t c {T_Bind? d}) (soundness: soundness_t d) (mk_t_abs: tabs_t d) : GTot (RT.tot_typing (elab_env g) (elab_st_typing d) (elab_comp c)) =
let T_Bind _ e1 e2 c1 c2 _ x c e1_typing t_typing e2_typing bc = d in LN.st_typing_ln e1_typing; LN.st_typing_ln e2_typing; FV.st_typing_freevars_inv e1_typing x; let r1_typing:RT.tot_typing _ _ (elab_comp c1) = soundness _ _ _ e1_typing in let r2_typing:RT.tot_typing _ _ (elab_term (tm_arrow (null_binder (comp_res c1)) None (close_comp c2 x))) = mk_t_abs None _ t_typing e2_typing in match bc with | Bind_comp _ _ _ _ t2_typing y post2_typing -> Bind.elab_bind_typing g _ _ _ x _ r1_typing _ r2_typing bc (tot_typing_soundness t2_typing) (mk_t_abs_tot _ ppname_default t2_typing post2_typing)
false
LowParse.Low.Bytes.fst
LowParse.Low.Bytes.store_bytes
val store_bytes (src: BY.bytes) (src_from src_to: U32.t) (#rrel #rel: _) (dst: B.mbuffer byte rrel rel) (dst_pos: U32.t) : HST.Stack unit (requires (fun h -> B.live h dst /\ U32.v src_from <= U32.v src_to /\ U32.v src_to <= BY.length src /\ U32.v dst_pos + (U32.v src_to - U32.v src_from) <= B.length dst /\ writable dst (U32.v dst_pos) (U32.v dst_pos + (U32.v src_to - U32.v src_from)) h)) (ensures (fun h _ h' -> B.modifies (B.loc_buffer_from_to dst dst_pos (dst_pos `U32.add` (src_to `U32.sub` src_from))) h h' /\ Seq.slice (B.as_seq h' dst) (U32.v dst_pos) (U32.v dst_pos + (U32.v src_to - U32.v src_from)) == Seq.slice (BY.reveal src) (U32.v src_from) (U32.v src_to)))
val store_bytes (src: BY.bytes) (src_from src_to: U32.t) (#rrel #rel: _) (dst: B.mbuffer byte rrel rel) (dst_pos: U32.t) : HST.Stack unit (requires (fun h -> B.live h dst /\ U32.v src_from <= U32.v src_to /\ U32.v src_to <= BY.length src /\ U32.v dst_pos + (U32.v src_to - U32.v src_from) <= B.length dst /\ writable dst (U32.v dst_pos) (U32.v dst_pos + (U32.v src_to - U32.v src_from)) h)) (ensures (fun h _ h' -> B.modifies (B.loc_buffer_from_to dst dst_pos (dst_pos `U32.add` (src_to `U32.sub` src_from))) h h' /\ Seq.slice (B.as_seq h' dst) (U32.v dst_pos) (U32.v dst_pos + (U32.v src_to - U32.v src_from)) == Seq.slice (BY.reveal src) (U32.v src_from) (U32.v src_to)))
let store_bytes (src: BY.bytes) (src_from src_to: U32.t) (#rrel #rel: _) (dst: B.mbuffer byte rrel rel) (dst_pos: U32.t) : HST.Stack unit (requires (fun h -> B.live h dst /\ U32.v src_from <= U32.v src_to /\ U32.v src_to <= BY.length src /\ U32.v dst_pos + (U32.v src_to - U32.v src_from) <= B.length dst /\ writable dst (U32.v dst_pos) (U32.v dst_pos + (U32.v src_to - U32.v src_from)) h )) (ensures (fun h _ h' -> B.modifies (B.loc_buffer_from_to dst dst_pos (dst_pos `U32.add` (src_to `U32.sub` src_from))) h h' /\ Seq.slice (B.as_seq h' dst) (U32.v dst_pos) (U32.v dst_pos + (U32.v src_to - U32.v src_from)) == Seq.slice (BY.reveal src) (U32.v src_from) (U32.v src_to) )) = let h0 = HST.get () in HST.push_frame (); let h1 = HST.get () in let bi = BF.alloca 0ul 1ul in let h2 = HST.get () in let len = src_to `U32.sub` src_from in C.Loops.do_while (fun h stop -> B.modifies (B.loc_union (B.loc_region_only true (HS.get_tip h1)) (B.loc_buffer_from_to dst dst_pos (dst_pos `U32.add` len))) h2 h /\ B.live h bi /\ ( let i = Seq.index (B.as_seq h bi) 0 in U32.v i <= U32.v len /\ writable dst (U32.v dst_pos) (U32.v dst_pos + U32.v len) h /\ Seq.slice (B.as_seq h dst) (U32.v dst_pos) (U32.v dst_pos + U32.v i) `Seq.equal` Seq.slice (BY.reveal src) (U32.v src_from) (U32.v src_from + U32.v i) /\ (stop == true ==> i == len) )) (fun _ -> let i = B.index bi 0ul in if i = len then true else begin let x = BY.get src (src_from `U32.add` i) in mbuffer_upd dst (Ghost.hide (U32.v dst_pos)) (Ghost.hide (U32.v dst_pos + U32.v len)) (dst_pos `U32.add` i) x; let i' = i `U32.add` 1ul in B.upd bi 0ul i'; let h' = HST.get () in Seq.lemma_split (Seq.slice (B.as_seq h' dst) (U32.v dst_pos) (U32.v dst_pos + U32.v i')) (U32.v i); i' = len end ) ; HST.pop_frame ()
{ "file_name": "src/lowparse/LowParse.Low.Bytes.fst", "git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
{ "end_col": 18, "end_line": 223, "start_col": 0, "start_line": 175 }
module LowParse.Low.Bytes include LowParse.Spec.Bytes include LowParse.Low.Combinators include LowParse.Low.VLData include LowParse.Low.VLGen include LowParse.Low.Int module U32 = FStar.UInt32 module HS = FStar.HyperStack module B = LowStar.Monotonic.Buffer module BF = LowStar.Buffer // for local variables in store_bytes module BY = LowParse.Bytes32 module HST = FStar.HyperStack.ST module U8 = FStar.UInt8 module Cast = FStar.Int.Cast module U64 = FStar.UInt64 inline_for_extraction let validate_flbytes (sz: nat) (sz64: U64.t { U64.v sz64 == sz /\ sz < 4294967296 } ) : Tot (validator (parse_flbytes sz)) = validate_total_constant_size (parse_flbytes sz) sz64 () inline_for_extraction let jump_flbytes (sz: nat) (sz32: U32.t { U32.v sz32 == sz } ) : Tot (jumper (parse_flbytes sz)) = jump_constant_size (parse_flbytes sz) sz32 () let valid_flbytes_intro (h: HS.mem) (sz: nat { sz < 4294967296 } ) (#rrel #rel: _) (s: slice rrel rel) (pos: U32.t) : Lemma (requires (U32.v pos + sz <= U32.v s.len /\ live_slice h s)) (ensures ( valid_content_pos (parse_flbytes sz) h s pos (BY.hide (bytes_of_slice_from_to h s pos (pos `U32.add` U32.uint_to_t sz))) (pos `U32.add` U32.uint_to_t sz) )) = valid_facts (parse_flbytes sz) h s pos let valid_pos_flbytes_elim (h: HS.mem) (sz: nat { sz < 4294967296 } ) (#rrel #rel: _) (s: slice rrel rel) (pos pos' : U32.t) : Lemma (requires (valid_pos (parse_flbytes sz) h s pos pos')) (ensures (U32.v pos + sz == U32.v pos')) [SMTPat (valid_pos (parse_flbytes sz) h s pos pos')] = valid_facts (parse_flbytes sz) h s pos let valid_flbytes_elim (h: HS.mem) (sz: nat { sz < 4294967296 } ) (#rrel #rel: _) (s: slice rrel rel) (pos: U32.t) : Lemma (requires (valid (parse_flbytes sz) h s pos)) (ensures ( valid_content_pos (parse_flbytes sz) h s pos (BY.hide (bytes_of_slice_from_to h s pos (pos `U32.add` U32.uint_to_t sz))) (pos `U32.add` U32.uint_to_t sz) )) = valid_flbytes_intro h sz s pos let clens_flbytes_slice (sz: nat) (from: U32.t) (to: U32.t {U32.v from <= U32.v to /\ U32.v to <= sz } ) : Tot (clens (BY.lbytes sz) (BY.lbytes (U32.v to - U32.v from))) = { clens_cond = (fun _ -> True); clens_get = (fun (x: BY.lbytes sz) -> (BY.slice x from to <: BY.lbytes (U32.v to - U32.v from))); } #push-options "--z3rlimit 16" let gaccessor_flbytes_slice' (sz: nat { sz < 4294967296 } ) (from: U32.t) (to: U32.t {U32.v from <= U32.v to /\ U32.v to <= sz } ) : Tot (gaccessor' (parse_flbytes sz) (parse_flbytes (U32.v to - U32.v from)) (clens_flbytes_slice sz from to)) = fun (input: bytes) -> ( begin if Seq.length input < sz then (0) // dummy else (U32.v from) end) let gaccessor_flbytes_slice (sz: nat { sz < 4294967296 } ) (from: U32.t) (to: U32.t {U32.v from <= U32.v to /\ U32.v to <= sz } ) : Tot (gaccessor (parse_flbytes sz) (parse_flbytes (U32.v to - U32.v from)) (clens_flbytes_slice sz from to)) = assert (forall x . gaccessor_pre (parse_flbytes sz) (parse_flbytes (U32.v to - U32.v from)) (clens_flbytes_slice sz from to) x ==> sz <= Seq.length x); gaccessor_prop_equiv (parse_flbytes sz) (parse_flbytes (U32.v to - U32.v from)) (clens_flbytes_slice sz from to) (gaccessor_flbytes_slice' sz from to); gaccessor_flbytes_slice' sz from to inline_for_extraction let accessor_flbytes_slice (sz: nat { sz < 4294967296 } ) (from: U32.t) (to: U32.t {U32.v from <= U32.v to /\ U32.v to <= sz } ) : Tot (accessor (gaccessor_flbytes_slice sz from to)) = fun #rrel #rel input pos -> let h = HST.get () in [@inline_let] let _ = slice_access_eq h (gaccessor_flbytes_slice sz from to) input pos in pos `U32.add` from #pop-options let clens_flbytes_get (sz: nat) (i: U32.t { U32.v i < sz } ) : Tot (clens (BY.lbytes sz) byte) = { clens_cond = (fun _ -> True); clens_get = (fun (x: BY.lbytes sz) -> (BY.get x i <: byte)); } #push-options "--z3rlimit 16 --max_fuel 1" let gaccessor_flbytes_get' (sz: nat { sz < 4294967296 } ) (i: U32.t { U32.v i < sz } ) : Tot (gaccessor' (parse_flbytes sz) (parse_u8) (clens_flbytes_get sz i)) = fun (input: bytes) -> ( begin let res = if Seq.length input < U32.v i then (0) // dummy else (U32.v i) in let g () : Lemma (requires (gaccessor_pre (parse_flbytes sz) parse_u8 (clens_flbytes_get sz i) input)) (ensures (gaccessor_post (parse_flbytes sz) parse_u8 (clens_flbytes_get sz i) input res)) = parser_kind_prop_equiv (get_parser_kind parse_u8) parse_u8; assert (res == (U32.v i)); parse_u8_spec' (Seq.slice input (U32.v i) (U32.v i + 1)); parse_strong_prefix parse_u8 (Seq.slice input (U32.v i) (U32.v i + 1)) (Seq.slice input (U32.v i) (Seq.length input)) in Classical.move_requires g (); res end) #pop-options let gaccessor_flbytes_get (sz: nat { sz < 4294967296 } ) (i: U32.t { U32.v i < sz } ) : Tot (gaccessor (parse_flbytes sz) (parse_u8) (clens_flbytes_get sz i)) = assert (forall x . gaccessor_pre (parse_flbytes sz) (parse_u8) (clens_flbytes_get sz i) x ==> U32.v i <= Seq.length x); gaccessor_prop_equiv (parse_flbytes sz) (parse_u8) (clens_flbytes_get sz i) (gaccessor_flbytes_get' sz i); gaccessor_flbytes_get' sz i inline_for_extraction let accessor_flbytes_get (sz: nat { sz < 4294967296 } ) (i: U32.t { U32.v i < sz } ) : Tot (accessor (gaccessor_flbytes_get sz i)) = fun #rrel #rel input pos -> let h = HST.get () in [@inline_let] let _ = slice_access_eq h (gaccessor_flbytes_get sz i) input pos in pos `U32.add` i (* Temporary: flbytes as leaf values *) (* TODO: convert store_bytes to monotonic buffers, using the "writable" predicate *) #push-options "--z3rlimit 32"
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowStar.Monotonic.Buffer.fsti.checked", "LowStar.Buffer.fst.checked", "LowParse.Spec.Bytes.fst.checked", "LowParse.Low.VLGen.fst.checked", "LowParse.Low.VLData.fst.checked", "LowParse.Low.Int.fsti.checked", "LowParse.Low.Combinators.fsti.checked", "LowParse.Bytes32.fst.checked", "FStar.UInt8.fsti.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Int.Cast.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked", "FStar.Classical.fsti.checked", "C.Loops.fst.checked" ], "interface_file": false, "source_file": "LowParse.Low.Bytes.fst" }
[ { "abbrev": true, "full_module": "LowStar.Buffer // for local variables in store_bytes", "short_module": "BF" }, { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "FStar.Int.Cast", "short_module": "Cast" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "LowParse.Bytes32", "short_module": "BY" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "BF" }, { "abbrev": true, "full_module": "LowStar.Monotonic.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": false, "full_module": "LowParse.Low.Int", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low.VLGen", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low.VLData", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low.Combinators", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec.Bytes", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 32, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
src: FStar.Bytes.bytes -> src_from: FStar.UInt32.t -> src_to: FStar.UInt32.t -> dst: LowStar.Monotonic.Buffer.mbuffer LowParse.Bytes.byte rrel rel -> dst_pos: FStar.UInt32.t -> FStar.HyperStack.ST.Stack Prims.unit
FStar.HyperStack.ST.Stack
[]
[]
[ "FStar.Bytes.bytes", "FStar.UInt32.t", "LowStar.Monotonic.Buffer.srel", "LowParse.Bytes.byte", "LowStar.Monotonic.Buffer.mbuffer", "FStar.HyperStack.ST.pop_frame", "Prims.unit", "C.Loops.do_while", "FStar.Monotonic.HyperStack.mem", "Prims.bool", "Prims.l_and", "LowStar.Monotonic.Buffer.modifies", "LowStar.Monotonic.Buffer.loc_union", "LowStar.Monotonic.Buffer.loc_region_only", "FStar.Monotonic.HyperStack.get_tip", "LowStar.Monotonic.Buffer.loc_buffer_from_to", "FStar.UInt32.add", "LowStar.Monotonic.Buffer.live", "LowStar.Buffer.trivial_preorder", "Prims.b2t", "Prims.op_LessThanOrEqual", "FStar.UInt32.v", "LowParse.Low.Base.writable", "Prims.op_Addition", "FStar.Seq.Base.equal", "FStar.Seq.Base.slice", "LowStar.Monotonic.Buffer.as_seq", "FStar.Bytes.byte", "FStar.Bytes.reveal", "Prims.l_imp", "Prims.eq2", "FStar.Seq.Base.index", "Prims.op_Equality", "FStar.Seq.Properties.lemma_split", "FStar.HyperStack.ST.get", "LowStar.Monotonic.Buffer.upd", "FStar.UInt32.__uint_to_t", "LowParse.Low.Base.mbuffer_upd", "FStar.Ghost.hide", "Prims.nat", "FStar.UInt8.t", "FStar.Bytes.get", "LowStar.Monotonic.Buffer.index", "FStar.UInt32.sub", "LowStar.Monotonic.Buffer.length", "FStar.UInt32.uint_to_t", "Prims.op_Negation", "LowStar.Monotonic.Buffer.g_is_null", "LowStar.Buffer.alloca", "FStar.HyperStack.ST.push_frame", "FStar.Bytes.length", "Prims.op_Subtraction", "FStar.Seq.Base.seq" ]
[]
false
true
false
false
false
let store_bytes (src: BY.bytes) (src_from src_to: U32.t) (#rrel #rel: _) (dst: B.mbuffer byte rrel rel) (dst_pos: U32.t) : HST.Stack unit (requires (fun h -> B.live h dst /\ U32.v src_from <= U32.v src_to /\ U32.v src_to <= BY.length src /\ U32.v dst_pos + (U32.v src_to - U32.v src_from) <= B.length dst /\ writable dst (U32.v dst_pos) (U32.v dst_pos + (U32.v src_to - U32.v src_from)) h)) (ensures (fun h _ h' -> B.modifies (B.loc_buffer_from_to dst dst_pos (dst_pos `U32.add` (src_to `U32.sub` src_from))) h h' /\ Seq.slice (B.as_seq h' dst) (U32.v dst_pos) (U32.v dst_pos + (U32.v src_to - U32.v src_from)) == Seq.slice (BY.reveal src) (U32.v src_from) (U32.v src_to))) =
let h0 = HST.get () in HST.push_frame (); let h1 = HST.get () in let bi = BF.alloca 0ul 1ul in let h2 = HST.get () in let len = src_to `U32.sub` src_from in C.Loops.do_while (fun h stop -> B.modifies (B.loc_union (B.loc_region_only true (HS.get_tip h1)) (B.loc_buffer_from_to dst dst_pos (dst_pos `U32.add` len))) h2 h /\ B.live h bi /\ (let i = Seq.index (B.as_seq h bi) 0 in U32.v i <= U32.v len /\ writable dst (U32.v dst_pos) (U32.v dst_pos + U32.v len) h /\ (Seq.slice (B.as_seq h dst) (U32.v dst_pos) (U32.v dst_pos + U32.v i)) `Seq.equal` (Seq.slice (BY.reveal src) (U32.v src_from) (U32.v src_from + U32.v i)) /\ (stop == true ==> i == len))) (fun _ -> let i = B.index bi 0ul in if i = len then true else let x = BY.get src (src_from `U32.add` i) in mbuffer_upd dst (Ghost.hide (U32.v dst_pos)) (Ghost.hide (U32.v dst_pos + U32.v len)) (dst_pos `U32.add` i) x; let i' = i `U32.add` 1ul in B.upd bi 0ul i'; let h' = HST.get () in Seq.lemma_split (Seq.slice (B.as_seq h' dst) (U32.v dst_pos) (U32.v dst_pos + U32.v i')) (U32.v i); i' = len); HST.pop_frame ()
false
Vale.AsLowStar.Test.fst
Vale.AsLowStar.Test.ta_lemma'
val ta_lemma' (code: V.va_code) (_win: bool) (arg0 arg1 arg2 arg3 arg4 arg5 arg6 arg7: ib64) (va_s0: V.va_state) : Ghost (V.va_state & V.va_fuel) (requires ta_pre code arg0 arg1 arg2 arg3 arg4 arg5 arg6 arg7 va_s0) (ensures (fun (va_s1, f) -> V.eval_code code va_s0 f va_s1 /\ VSig.vale_calling_conventions_stdcall va_s0 va_s1 /\ ta_post code arg0 arg1 arg2 arg3 arg4 arg5 arg6 arg7 va_s0 va_s1 f /\ ME.buffer_readable (VS.vs_get_vale_heap va_s1) (as_vale_immbuffer arg0) /\ ME.buffer_readable (VS.vs_get_vale_heap va_s1) (as_vale_immbuffer arg1) /\ ME.buffer_readable (VS.vs_get_vale_heap va_s1) (as_vale_immbuffer arg2) /\ ME.buffer_readable (VS.vs_get_vale_heap va_s1) (as_vale_immbuffer arg3) /\ ME.buffer_readable (VS.vs_get_vale_heap va_s1) (as_vale_immbuffer arg4) /\ ME.buffer_readable (VS.vs_get_vale_heap va_s1) (as_vale_immbuffer arg5) /\ ME.buffer_readable (VS.vs_get_vale_heap va_s1) (as_vale_immbuffer arg6) /\ ME.buffer_readable (VS.vs_get_vale_heap va_s1) (as_vale_immbuffer arg7) /\ ME.modifies ME.loc_none (VS.vs_get_vale_heap va_s0) (VS.vs_get_vale_heap va_s1)))
val ta_lemma' (code: V.va_code) (_win: bool) (arg0 arg1 arg2 arg3 arg4 arg5 arg6 arg7: ib64) (va_s0: V.va_state) : Ghost (V.va_state & V.va_fuel) (requires ta_pre code arg0 arg1 arg2 arg3 arg4 arg5 arg6 arg7 va_s0) (ensures (fun (va_s1, f) -> V.eval_code code va_s0 f va_s1 /\ VSig.vale_calling_conventions_stdcall va_s0 va_s1 /\ ta_post code arg0 arg1 arg2 arg3 arg4 arg5 arg6 arg7 va_s0 va_s1 f /\ ME.buffer_readable (VS.vs_get_vale_heap va_s1) (as_vale_immbuffer arg0) /\ ME.buffer_readable (VS.vs_get_vale_heap va_s1) (as_vale_immbuffer arg1) /\ ME.buffer_readable (VS.vs_get_vale_heap va_s1) (as_vale_immbuffer arg2) /\ ME.buffer_readable (VS.vs_get_vale_heap va_s1) (as_vale_immbuffer arg3) /\ ME.buffer_readable (VS.vs_get_vale_heap va_s1) (as_vale_immbuffer arg4) /\ ME.buffer_readable (VS.vs_get_vale_heap va_s1) (as_vale_immbuffer arg5) /\ ME.buffer_readable (VS.vs_get_vale_heap va_s1) (as_vale_immbuffer arg6) /\ ME.buffer_readable (VS.vs_get_vale_heap va_s1) (as_vale_immbuffer arg7) /\ ME.modifies ME.loc_none (VS.vs_get_vale_heap va_s0) (VS.vs_get_vale_heap va_s1)))
let ta_lemma' (code:V.va_code) (_win:bool) (arg0:ib64) (arg1:ib64) (arg2:ib64) (arg3:ib64) (arg4:ib64) (arg5:ib64) (arg6:ib64) (arg7:ib64) (va_s0:V.va_state) : Ghost (V.va_state & V.va_fuel) (requires ta_pre code arg0 arg1 arg2 arg3 arg4 arg5 arg6 arg7 va_s0) (ensures (fun (va_s1, f) -> V.eval_code code va_s0 f va_s1 /\ VSig.vale_calling_conventions_stdcall va_s0 va_s1 /\ ta_post code arg0 arg1 arg2 arg3 arg4 arg5 arg6 arg7 va_s0 va_s1 f /\ ME.buffer_readable (VS.vs_get_vale_heap va_s1) (as_vale_immbuffer arg0) /\ ME.buffer_readable (VS.vs_get_vale_heap va_s1) (as_vale_immbuffer arg1) /\ ME.buffer_readable (VS.vs_get_vale_heap va_s1) (as_vale_immbuffer arg2) /\ ME.buffer_readable (VS.vs_get_vale_heap va_s1) (as_vale_immbuffer arg3) /\ ME.buffer_readable (VS.vs_get_vale_heap va_s1) (as_vale_immbuffer arg4) /\ ME.buffer_readable (VS.vs_get_vale_heap va_s1) (as_vale_immbuffer arg5) /\ ME.buffer_readable (VS.vs_get_vale_heap va_s1) (as_vale_immbuffer arg6) /\ ME.buffer_readable (VS.vs_get_vale_heap va_s1) (as_vale_immbuffer arg7) /\ ME.modifies ME.loc_none (VS.vs_get_vale_heap va_s0) (VS.vs_get_vale_heap va_s1))) = let va_s1, f = TA.va_lemma_Test code va_s0 IA.win (as_vale_immbuffer arg0) (as_vale_immbuffer arg1) (as_vale_immbuffer arg2) (as_vale_immbuffer arg3) (as_vale_immbuffer arg4) (as_vale_immbuffer arg5) (as_vale_immbuffer arg6) (as_vale_immbuffer arg7) in va_s1, f
{ "file_name": "vale/code/arch/x64/interop/Vale.AsLowStar.Test.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 12, "end_line": 370, "start_col": 0, "start_line": 331 }
module Vale.AsLowStar.Test open FStar.Mul open Vale.Interop.Base module ME = Vale.X64.Memory module IA = Vale.Interop.Assumptions module V = Vale.X64.Decls module IX64 = Vale.Interop.X64 module VSig = Vale.AsLowStar.ValeSig module LSig = Vale.AsLowStar.LowStarSig module W = Vale.AsLowStar.Wrapper module VS = Vale.X64.State module MS = Vale.X64.Machine_s (* A little utility to trigger normalization in types *) let as_t (#a:Type) (x:normal a) : a = x let as_normal_t (#a:Type) (x:a) : normal a = x //////////////////////////////////////////////////////////////////////////////// //First a little standalone, toy experiment [@__reduce__] let b64 = buf_t TUInt8 TUInt64 [@__reduce__] let ib64 = ibuf_t TUInt8 TUInt64 [@__reduce__] let t64_mod = TD_Buffer TUInt8 TUInt64 default_bq [@__reduce__] let t64_no_mod = TD_Buffer TUInt8 TUInt64 ({modified=false; strict_disjointness=false; taint=MS.Secret}) [@__reduce__] let t64_imm = TD_ImmBuffer TUInt8 TUInt64 ({modified=false; strict_disjointness=false; taint=MS.Secret}) [@__reduce__] let (dom : list td{List.length dom <= 20}) = let y = [t64_mod;t64_imm] in assert_norm (List.length y = 2); y assume val pre : VSig.vale_pre dom assume val post : VSig.vale_post dom assume val v: VSig.vale_sig_stdcall pre post assume val c: V.va_code [@__reduce__] let call_c_t = IX64.as_lowstar_sig_t_weak_stdcall c dom [] _ _ (W.mk_prediction c dom [] (v c IA.win)) let call_c : call_c_t = IX64.wrap_weak_stdcall c dom (W.mk_prediction c dom [] (v c IA.win)) let call_c_normal_t : normal call_c_t = as_normal_t #call_c_t call_c //You can ask emacs to show you the type of call_c_normal_t ... //////////////////////////////////////////////////////////////////////////////// //Now memcpy module VM = Vale.Test.X64.Vale_memcpy [@__reduce__] let vm_dom = [t64_mod; t64_imm] open Vale.X64.MemoryAdapters (* Need to rearrange the order of arguments *) [@__reduce__] let vm_pre : VSig.vale_pre vm_dom = fun (c:V.va_code) (dst:b64) (src:ib64) (va_s0:V.va_state) -> VM.va_req_Memcpy c va_s0 IA.win (as_vale_buffer dst) (as_vale_immbuffer src) [@__reduce__] let vm_post : VSig.vale_post vm_dom = fun (c:V.va_code) (dst:b64) (src:ib64) (va_s0:V.va_state) (va_s1:V.va_state) (f:V.va_fuel) -> VM.va_ens_Memcpy c va_s0 IA.win (as_vale_buffer dst) (as_vale_immbuffer src) va_s1 f module VS = Vale.X64.State #reset-options "--print_effect_args --z3rlimit 200" (* The vale lemma doesn't quite suffice to prove the modifies clause expected of the interop layer *) [@__reduce__] let vm_lemma' (code:V.va_code) (_win:bool) (dst:b64) (src:ib64) (va_s0:V.va_state) : Ghost (V.va_state & V.va_fuel) (requires vm_pre code dst src va_s0) (ensures (fun (va_s1, f) -> V.eval_code code va_s0 f va_s1 /\ VSig.vale_calling_conventions_stdcall va_s0 va_s1 /\ vm_post code dst src va_s0 va_s1 f /\ ME.buffer_readable (VS.vs_get_vale_heap va_s1) (as_vale_immbuffer src) /\ ME.buffer_readable (VS.vs_get_vale_heap va_s1) (as_vale_buffer dst) /\ ME.buffer_writeable (as_vale_buffer dst) /\ ME.modifies (ME.loc_union (ME.loc_buffer (as_vale_buffer dst)) ME.loc_none) (VS.vs_get_vale_heap va_s0) (VS.vs_get_vale_heap va_s1) )) = let va_s1, f = VM.va_lemma_Memcpy code va_s0 IA.win (as_vale_buffer dst) (as_vale_immbuffer src) in Vale.AsLowStar.MemoryHelpers.buffer_writeable_reveal ME.TUInt8 ME.TUInt64 dst; (va_s1, f) (* Prove that vm_lemma' has the required type *) let vm_lemma = as_t #(VSig.vale_sig_stdcall vm_pre vm_post) vm_lemma' let code_Memcpy = VM.va_code_Memcpy IA.win (* Here's the type expected for the memcpy wrapper *) [@__reduce__] let lowstar_Memcpy_t = IX64.as_lowstar_sig_t_weak_stdcall code_Memcpy vm_dom [] _ _ (W.mk_prediction code_Memcpy vm_dom [] (vm_lemma code_Memcpy IA.win)) (* And here's the memcpy wrapper itself *) let lowstar_Memcpy : lowstar_Memcpy_t = IX64.wrap_weak_stdcall code_Memcpy vm_dom (W.mk_prediction code_Memcpy vm_dom [] (vm_lemma code_Memcpy IA.win)) let lowstar_Memcpy_normal_t //: normal lowstar_Memcpy_t = as_normal_t #lowstar_Memcpy_t lowstar_Memcpy module B = LowStar.Buffer module IB = LowStar.ImmutableBuffer module MB = LowStar.Monotonic.Buffer open FStar.HyperStack.ST module M = Vale.X64.Memory let test (x:b64) = assert (V.buffer_length (as_vale_buffer x) == (B.length x * view_n TUInt8) / view_n TUInt64); assert (V.buffer_length (as_vale_buffer x) == B.length x / 8) let itest (x:ib64) = assert (V.buffer_length (as_vale_immbuffer x) == (B.length x * view_n TUInt8) / view_n TUInt64); assert (V.buffer_length (as_vale_immbuffer x) == B.length x / 8) module T = FStar.Tactics #reset-options "--using_facts_from '* -FStar.Tactics -FStar.Reflection'" module LBV = LowStar.BufferView.Up module DV = LowStar.BufferView.Down #push-options "--ext compat:normalizer_memo_ignore_cfg" let memcpy_Test (dst:B.buffer UInt8.t{B.length dst % 8 == 0}) (src:IB.ibuffer UInt8.t{B.length src % 8 == 0}) : Stack UInt64.t (requires fun h0 -> B.live h0 dst /\ B.live h0 src /\ B.disjoint dst src /\ B.length dst == 16 /\ B.length src == 16) (ensures fun h0 _ h1 -> B.modifies (B.loc_buffer dst) h0 h1 /\ B.live h1 src /\ B.live h1 dst) // B.as_seq h1 dst == B.as_seq h1 src) // by (T.dump "A") (* in case you want to look at the VC *) = IB.inhabited_immutable_buffer_is_distinct_from_buffer (UInt8.uint_to_t 0) src dst; let (x, _) = lowstar_Memcpy_normal_t dst src () in //This is a call to the interop wrapper let h1 = get () in // let v = Vale.Interop.Views.up_view64 in // assert (DV.length_eq (get_downview dst); // DV.length_eq (get_downview src); // Seq.equal (LBV.as_seq h1 (LBV.mk_buffer (get_downview dst) v)) // (LBV.as_seq h1 (LBV.mk_buffer (get_downview src) v))); // lbv_as_seq_eq dst src Vale.Interop.Views.up_view64 h1; //And a lemma to rephrase the Vale postcondition x //with equalities of buffer views //back to equalities of buffers #pop-options module VC = Vale.Lib.X64.Cpuidstdcall [@__reduce__] let empty_list #a : l:list a {List.length l = 0} = [] [@__reduce__] let aesni_dom : IX64.arity_ok_stdcall td = [] (* Need to rearrange the order of arguments *) [@__reduce__] let aesni_pre : VSig.vale_pre aesni_dom = fun (c:V.va_code) (va_s0:V.va_state) -> VC.va_req_Check_aesni_stdcall c va_s0 IA.win [@__reduce__] let aesni_post : VSig.vale_post aesni_dom = fun (c:V.va_code) (va_s0:V.va_state) (va_s1:V.va_state) (f:V.va_fuel) -> VC.va_ens_Check_aesni_stdcall c va_s0 IA.win va_s1 f [@__reduce__] let with_len (l:list 'a) : Pure (list 'a) (requires True) (ensures fun m -> m==l /\ List.length m == normalize_term (List.length l)) = l #set-options "--max_fuel 0 --max_ifuel 1 --z3rlimit_factor 2" (* The vale lemma doesn't quite suffice to prove the modifies clause expected of the interop layer *) [@__reduce__] let aesni_lemma' (code:V.va_code) (_win:bool) (va_s0:V.va_state) : Ghost (V.va_state & V.va_fuel) (requires aesni_pre code va_s0) (ensures (fun (va_s1, f) -> V.eval_code code va_s0 f va_s1 /\ VSig.vale_calling_conventions_stdcall va_s0 va_s1 /\ aesni_post code va_s0 va_s1 f)) = VC.va_lemma_Check_aesni_stdcall code va_s0 IA.win #set-options "--max_fuel 0 --max_ifuel 0 --z3rlimit_factor 2" (* Prove that vm_lemma' has the required type *) let aesni_lemma = as_t #(VSig.vale_sig_stdcall aesni_pre aesni_post) aesni_lemma' let code_aesni = VC.va_code_Check_aesni_stdcall IA.win (* Here's the type expected for the check_aesni wrapper *) [@__reduce__] let lowstar_aesni_t = IX64.as_lowstar_sig_t_weak_stdcall (coerce code_aesni) aesni_dom empty_list _ _ (W.mk_prediction code_aesni aesni_dom [] (aesni_lemma code_aesni IA.win)) (* And here's the check_aesni wrapper itself *) let lowstar_aesni : lowstar_aesni_t = IX64.wrap_weak_stdcall (coerce code_aesni) aesni_dom (W.mk_prediction code_aesni aesni_dom [] (aesni_lemma code_aesni IA.win)) let lowstar_aesni_normal_t //: normal lowstar_aesni_t = as_normal_t #lowstar_aesni_t lowstar_aesni open Vale.X64.CPU_Features_s #set-options "--print_full_names" let aesni_Test () : Stack UInt64.t (requires fun h0 -> True) (ensures fun h0 ret_val h1 -> (UInt64.v ret_val) =!= 0 ==> aesni_enabled /\ pclmulqdq_enabled) // by (T.dump "A") (* in case you want to look at the VC *) = let (x, _) = lowstar_aesni_normal_t () in //This is a call to the interop wrapper x module TA = Vale.Test.X64.Args [@__reduce__] let (ta_dom:list td{List.length ta_dom <= 20}) = let y = [t64_imm; t64_imm; t64_imm; t64_imm; t64_imm; t64_imm; t64_imm; t64_imm] in assert_norm (List.length y = 8); y (* Need to rearrange the order of arguments *) [@__reduce__] let ta_pre : VSig.vale_pre ta_dom = fun (c:V.va_code) (arg0:ib64) (arg1:ib64) (arg2:ib64) (arg3:ib64) (arg4:ib64) (arg5:ib64) (arg6:ib64) (arg7:ib64) (va_s0:V.va_state) -> TA.va_req_Test c va_s0 IA.win (as_vale_immbuffer arg0) (as_vale_immbuffer arg1) (as_vale_immbuffer arg2) (as_vale_immbuffer arg3) (as_vale_immbuffer arg4) (as_vale_immbuffer arg5) (as_vale_immbuffer arg6) (as_vale_immbuffer arg7) [@__reduce__] let ta_post : VSig.vale_post ta_dom = fun (c:V.va_code) (arg0:ib64) (arg1:ib64) (arg2:ib64) (arg3:ib64) (arg4:ib64) (arg5:ib64) (arg6:ib64) (arg7:ib64) (va_s0:V.va_state) (va_s1:V.va_state) (f:V.va_fuel) -> TA.va_ens_Test c va_s0 IA.win (as_vale_immbuffer arg0) (as_vale_immbuffer arg1) (as_vale_immbuffer arg2) (as_vale_immbuffer arg3) (as_vale_immbuffer arg4) (as_vale_immbuffer arg5) (as_vale_immbuffer arg6) (as_vale_immbuffer arg7) va_s1 f #reset-options "--max_fuel 0 --max_ifuel 0 --z3rlimit 100" (* The vale lemma doesn't quite suffice to prove the modifies clause expected of the interop layer *)
{ "checked_file": "/", "dependencies": [ "Vale.X64.State.fsti.checked", "Vale.X64.MemoryAdapters.fsti.checked", "Vale.X64.Memory.fsti.checked", "Vale.X64.Machine_s.fst.checked", "Vale.X64.Decls.fsti.checked", "Vale.X64.CPU_Features_s.fst.checked", "Vale.Test.X64.Vale_memcpy.fsti.checked", "Vale.Test.X64.Args.fsti.checked", "Vale.Lib.X64.Cpuidstdcall.fsti.checked", "Vale.Interop.X64.fsti.checked", "Vale.Interop.Base.fst.checked", "Vale.Interop.Assumptions.fst.checked", "Vale.AsLowStar.Wrapper.fsti.checked", "Vale.AsLowStar.ValeSig.fst.checked", "Vale.AsLowStar.MemoryHelpers.fsti.checked", "Vale.AsLowStar.LowStarSig.fst.checked", "prims.fst.checked", "LowStar.Monotonic.Buffer.fsti.checked", "LowStar.ImmutableBuffer.fst.checked", "LowStar.BufferView.Up.fsti.checked", "LowStar.BufferView.Down.fsti.checked", "LowStar.Buffer.fst.checked", "FStar.UInt8.fsti.checked", "FStar.UInt64.fsti.checked", "FStar.Tactics.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.List.fst.checked", "FStar.HyperStack.ST.fsti.checked" ], "interface_file": false, "source_file": "Vale.AsLowStar.Test.fst" }
[ { "abbrev": true, "full_module": "Vale.Test.X64.Args", "short_module": "TA" }, { "abbrev": false, "full_module": "Vale.X64.CPU_Features_s", "short_module": null }, { "abbrev": true, "full_module": "Vale.Lib.X64.Cpuidstdcall", "short_module": "VC" }, { "abbrev": true, "full_module": "LowStar.BufferView.Down", "short_module": "DV" }, { "abbrev": true, "full_module": "LowStar.BufferView.Up", "short_module": "LBV" }, { "abbrev": true, "full_module": "FStar.Tactics", "short_module": "T" }, { "abbrev": true, "full_module": "Vale.X64.Memory", "short_module": "M" }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": true, "full_module": "LowStar.Monotonic.Buffer", "short_module": "MB" }, { "abbrev": true, "full_module": "LowStar.ImmutableBuffer", "short_module": "IB" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "Vale.X64.State", "short_module": "VS" }, { "abbrev": false, "full_module": "Vale.X64.MemoryAdapters", "short_module": null }, { "abbrev": true, "full_module": "Vale.Test.X64.Vale_memcpy", "short_module": "VM" }, { "abbrev": true, "full_module": "Vale.X64.Machine_s", "short_module": "MS" }, { "abbrev": true, "full_module": "Vale.X64.State", "short_module": "VS" }, { "abbrev": true, "full_module": "Vale.AsLowStar.Wrapper", "short_module": "W" }, { "abbrev": true, "full_module": "Vale.AsLowStar.LowStarSig", "short_module": "LSig" }, { "abbrev": true, "full_module": "Vale.AsLowStar.ValeSig", "short_module": "VSig" }, { "abbrev": true, "full_module": "Vale.Interop.X64", "short_module": "IX64" }, { "abbrev": true, "full_module": "Vale.X64.Decls", "short_module": "V" }, { "abbrev": true, "full_module": "Vale.Interop.Assumptions", "short_module": "IA" }, { "abbrev": true, "full_module": "Vale.X64.Memory", "short_module": "ME" }, { "abbrev": false, "full_module": "Vale.Interop.Base", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.AsLowStar", "short_module": null }, { "abbrev": false, "full_module": "Vale.AsLowStar", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 0, "max_fuel": 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": 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" }
false
code: Vale.X64.Decls.va_code -> _win: Prims.bool -> arg0: Vale.AsLowStar.Test.ib64 -> arg1: Vale.AsLowStar.Test.ib64 -> arg2: Vale.AsLowStar.Test.ib64 -> arg3: Vale.AsLowStar.Test.ib64 -> arg4: Vale.AsLowStar.Test.ib64 -> arg5: Vale.AsLowStar.Test.ib64 -> arg6: Vale.AsLowStar.Test.ib64 -> arg7: Vale.AsLowStar.Test.ib64 -> va_s0: Vale.X64.Decls.va_state -> Prims.Ghost (Vale.X64.Decls.va_state * Vale.X64.Decls.va_fuel)
Prims.Ghost
[]
[]
[ "Vale.X64.Decls.va_code", "Prims.bool", "Vale.AsLowStar.Test.ib64", "Vale.X64.Decls.va_state", "Vale.X64.Decls.va_fuel", "FStar.Pervasives.Native.Mktuple2", "FStar.Pervasives.Native.tuple2", "Vale.X64.State.vale_state", "Vale.Test.X64.Args.va_lemma_Test", "Vale.Interop.Assumptions.win", "Vale.X64.MemoryAdapters.as_vale_immbuffer", "Vale.Arch.HeapTypes_s.TUInt8", "Vale.Arch.HeapTypes_s.TUInt64", "Vale.AsLowStar.Test.ta_pre", "Prims.l_and", "Vale.X64.Decls.eval_code", "Vale.AsLowStar.ValeSig.vale_calling_conventions_stdcall", "Vale.AsLowStar.Test.ta_post", "Vale.X64.Memory.buffer_readable", "Vale.X64.State.vs_get_vale_heap", "Vale.X64.Memory.modifies", "Vale.X64.Memory.loc_none" ]
[]
false
false
false
false
false
let ta_lemma' (code: V.va_code) (_win: bool) (arg0 arg1 arg2 arg3 arg4 arg5 arg6 arg7: ib64) (va_s0: V.va_state) : Ghost (V.va_state & V.va_fuel) (requires ta_pre code arg0 arg1 arg2 arg3 arg4 arg5 arg6 arg7 va_s0) (ensures (fun (va_s1, f) -> V.eval_code code va_s0 f va_s1 /\ VSig.vale_calling_conventions_stdcall va_s0 va_s1 /\ ta_post code arg0 arg1 arg2 arg3 arg4 arg5 arg6 arg7 va_s0 va_s1 f /\ ME.buffer_readable (VS.vs_get_vale_heap va_s1) (as_vale_immbuffer arg0) /\ ME.buffer_readable (VS.vs_get_vale_heap va_s1) (as_vale_immbuffer arg1) /\ ME.buffer_readable (VS.vs_get_vale_heap va_s1) (as_vale_immbuffer arg2) /\ ME.buffer_readable (VS.vs_get_vale_heap va_s1) (as_vale_immbuffer arg3) /\ ME.buffer_readable (VS.vs_get_vale_heap va_s1) (as_vale_immbuffer arg4) /\ ME.buffer_readable (VS.vs_get_vale_heap va_s1) (as_vale_immbuffer arg5) /\ ME.buffer_readable (VS.vs_get_vale_heap va_s1) (as_vale_immbuffer arg6) /\ ME.buffer_readable (VS.vs_get_vale_heap va_s1) (as_vale_immbuffer arg7) /\ ME.modifies ME.loc_none (VS.vs_get_vale_heap va_s0) (VS.vs_get_vale_heap va_s1))) =
let va_s1, f = TA.va_lemma_Test code va_s0 IA.win (as_vale_immbuffer arg0) (as_vale_immbuffer arg1) (as_vale_immbuffer arg2) (as_vale_immbuffer arg3) (as_vale_immbuffer arg4) (as_vale_immbuffer arg5) (as_vale_immbuffer arg6) (as_vale_immbuffer arg7) in va_s1, f
false
Vale.AES.GCTR_BE.fsti
Vale.AES.GCTR_BE.make_gctr_plain_BE
val make_gctr_plain_BE (p: seq nat8) : seq nat8
val make_gctr_plain_BE (p: seq nat8) : seq nat8
let make_gctr_plain_BE (p:seq nat8) : seq nat8 = if length p < pow2_32 then p else empty
{ "file_name": "vale/code/crypto/aes/Vale.AES.GCTR_BE.fsti", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 41, "end_line": 16, "start_col": 0, "start_line": 15 }
module Vale.AES.GCTR_BE open Vale.Def.Prop_s open Vale.Def.Opaque_s open Vale.Def.Words_s open Vale.Def.Types_s open Vale.Arch.Types open FStar.Mul open FStar.Seq open Vale.AES.AES_BE_s open Vale.AES.GCTR_BE_s open FStar.Math.Lemmas open Vale.Def.Words.Seq_s
{ "checked_file": "/", "dependencies": [ "Vale.Def.Words_s.fsti.checked", "Vale.Def.Words.Seq_s.fsti.checked", "Vale.Def.Types_s.fst.checked", "Vale.Def.Prop_s.fst.checked", "Vale.Def.Opaque_s.fsti.checked", "Vale.Arch.Types.fsti.checked", "Vale.AES.GCTR_BE_s.fst.checked", "Vale.AES.AES_BE_s.fst.checked", "prims.fst.checked", "FStar.Seq.Properties.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked" ], "interface_file": false, "source_file": "Vale.AES.GCTR_BE.fsti" }
[ { "abbrev": false, "full_module": "Vale.Def.Words.Seq_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Math.Lemmas", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GCTR_BE_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.AES_BE_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Seq", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.Types", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Types_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Opaque_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Prop_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 0, "max_fuel": 1, "max_ifuel": 1, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": true, "smtencoding_l_arith_repr": "native", "smtencoding_nl_arith_repr": "wrapped", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [ "smt.arith.nl=false", "smt.QI.EAGER_THRESHOLD=100", "smt.CASE_SPLIT=3" ], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
p: FStar.Seq.Base.seq Vale.Def.Types_s.nat8 -> FStar.Seq.Base.seq Vale.Def.Types_s.nat8
Prims.Tot
[ "total" ]
[]
[ "FStar.Seq.Base.seq", "Vale.Def.Types_s.nat8", "Prims.op_LessThan", "FStar.Seq.Base.length", "Vale.Def.Words_s.pow2_32", "Prims.bool", "FStar.Seq.Base.empty" ]
[]
false
false
false
true
false
let make_gctr_plain_BE (p: seq nat8) : seq nat8 =
if length p < pow2_32 then p else empty
false
Vale.AES.GCTR_BE.fsti
Vale.AES.GCTR_BE.empty_seq_quad32
val empty_seq_quad32:seq quad32
val empty_seq_quad32:seq quad32
let empty_seq_quad32 : seq quad32 = empty
{ "file_name": "vale/code/crypto/aes/Vale.AES.GCTR_BE.fsti", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 41, "end_line": 26, "start_col": 0, "start_line": 26 }
module Vale.AES.GCTR_BE open Vale.Def.Prop_s open Vale.Def.Opaque_s open Vale.Def.Words_s open Vale.Def.Types_s open Vale.Arch.Types open FStar.Mul open FStar.Seq open Vale.AES.AES_BE_s open Vale.AES.GCTR_BE_s open FStar.Math.Lemmas open Vale.Def.Words.Seq_s let make_gctr_plain_BE (p:seq nat8) : seq nat8 = if length p < pow2_32 then p else empty let inc32lite (cb:quad32) (i:int) : quad32 = if 0 <= i && i < pow2_32 then let sum = cb.lo0 + i in let lo0 = if sum >= pow2_32 then sum - pow2_32 else sum in Mkfour lo0 cb.lo1 cb.hi2 cb.hi3 else Mkfour 42 42 42 42
{ "checked_file": "/", "dependencies": [ "Vale.Def.Words_s.fsti.checked", "Vale.Def.Words.Seq_s.fsti.checked", "Vale.Def.Types_s.fst.checked", "Vale.Def.Prop_s.fst.checked", "Vale.Def.Opaque_s.fsti.checked", "Vale.Arch.Types.fsti.checked", "Vale.AES.GCTR_BE_s.fst.checked", "Vale.AES.AES_BE_s.fst.checked", "prims.fst.checked", "FStar.Seq.Properties.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked" ], "interface_file": false, "source_file": "Vale.AES.GCTR_BE.fsti" }
[ { "abbrev": false, "full_module": "Vale.Def.Words.Seq_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Math.Lemmas", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GCTR_BE_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.AES_BE_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Seq", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.Types", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Types_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Opaque_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Prop_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 0, "max_fuel": 1, "max_ifuel": 1, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": true, "smtencoding_l_arith_repr": "native", "smtencoding_nl_arith_repr": "wrapped", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [ "smt.arith.nl=false", "smt.QI.EAGER_THRESHOLD=100", "smt.CASE_SPLIT=3" ], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
FStar.Seq.Base.seq Vale.Def.Types_s.quad32
Prims.Tot
[ "total" ]
[]
[ "FStar.Seq.Base.empty", "Vale.Def.Types_s.quad32" ]
[]
false
false
false
true
false
let empty_seq_quad32:seq quad32 =
empty
false
Vale.AES.GCTR_BE.fsti
Vale.AES.GCTR_BE.gctr_partial
val gctr_partial : _: Vale.AES.AES_common_s.algorithm -> _: Prims.nat -> _: FStar.Seq.Base.seq Vale.Def.Types_s.quad32 -> _: FStar.Seq.Base.seq Vale.Def.Types_s.quad32 -> _: FStar.Seq.Base.seq Vale.Def.Types_s.nat32 -> _: Vale.Def.Types_s.quad32 -> Vale.Def.Prop_s.prop0
let gctr_partial = opaque_make gctr_partial_def
{ "file_name": "vale/code/crypto/aes/Vale.AES.GCTR_BE.fsti", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 66, "end_line": 58, "start_col": 19, "start_line": 58 }
module Vale.AES.GCTR_BE open Vale.Def.Prop_s open Vale.Def.Opaque_s open Vale.Def.Words_s open Vale.Def.Types_s open Vale.Arch.Types open FStar.Mul open FStar.Seq open Vale.AES.AES_BE_s open Vale.AES.GCTR_BE_s open FStar.Math.Lemmas open Vale.Def.Words.Seq_s let make_gctr_plain_BE (p:seq nat8) : seq nat8 = if length p < pow2_32 then p else empty let inc32lite (cb:quad32) (i:int) : quad32 = if 0 <= i && i < pow2_32 then let sum = cb.lo0 + i in let lo0 = if sum >= pow2_32 then sum - pow2_32 else sum in Mkfour lo0 cb.lo1 cb.hi2 cb.hi3 else Mkfour 42 42 42 42 let empty_seq_quad32 : seq quad32 = empty let partial_seq_agreement (x y:seq quad32) (lo hi:nat) = lo <= hi /\ hi <= length x /\ hi <= length y /\ (forall i . {:pattern (index x i) \/ (index y i)} lo <= i /\ i < hi ==> index x i == index y i) let lemma_eq_reverse_bytes_quad32_seq (s1 s2 s3:seq quad32) (bound:nat) (icb:quad32) (alg:algorithm) (key:seq nat32) : Lemma (requires (is_aes_key_word alg key /\ bound <= length s1 /\ bound <= length s2 /\ bound <= length s3 /\ (forall j . {:pattern (index s2 j)} 0 <= j /\ j < bound ==> index s2 j == quad32_xor (index s3 j) (aes_encrypt_word alg key (inc32 icb j))) /\ (forall j . {:pattern (index s1 j)} 0 <= j /\ j < bound ==> index s1 j == index s2 j))) (ensures (forall j . {:pattern (index s1 j)} 0 <= j /\ j < bound ==> index s1 j == quad32_xor (index s3 j) (aes_encrypt_word alg key (inc32 icb j))) ) = () val gctr_encrypt_block_offset (icb:quad32) (plain:quad32) (alg:algorithm) (key:seq nat32) (i:int) : Lemma (requires is_aes_key_word alg key) (ensures gctr_encrypt_block icb plain alg key i == gctr_encrypt_block (inc32 icb i) plain alg key 0 ) let gctr_partial_def (alg:algorithm) (bound:nat) (plain cipher:seq quad32) (key:seq nat32) (icb:quad32) : prop0 = is_aes_key_word alg key /\ ( let bound = min bound (min (length plain) (length cipher)) in forall j . {:pattern (index cipher j)} 0 <= j /\ j < bound ==>
{ "checked_file": "/", "dependencies": [ "Vale.Def.Words_s.fsti.checked", "Vale.Def.Words.Seq_s.fsti.checked", "Vale.Def.Types_s.fst.checked", "Vale.Def.Prop_s.fst.checked", "Vale.Def.Opaque_s.fsti.checked", "Vale.Arch.Types.fsti.checked", "Vale.AES.GCTR_BE_s.fst.checked", "Vale.AES.AES_BE_s.fst.checked", "prims.fst.checked", "FStar.Seq.Properties.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked" ], "interface_file": false, "source_file": "Vale.AES.GCTR_BE.fsti" }
[ { "abbrev": false, "full_module": "Vale.Def.Words.Seq_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Math.Lemmas", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GCTR_BE_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.AES_BE_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Seq", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.Types", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Types_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Opaque_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Prop_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 0, "max_fuel": 1, "max_ifuel": 1, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": true, "smtencoding_l_arith_repr": "native", "smtencoding_nl_arith_repr": "wrapped", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [ "smt.arith.nl=false", "smt.QI.EAGER_THRESHOLD=100", "smt.CASE_SPLIT=3" ], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
_: Vale.AES.AES_common_s.algorithm -> _: Prims.nat -> _: FStar.Seq.Base.seq Vale.Def.Types_s.quad32 -> _: FStar.Seq.Base.seq Vale.Def.Types_s.quad32 -> _: FStar.Seq.Base.seq Vale.Def.Types_s.nat32 -> _: Vale.Def.Types_s.quad32 -> Vale.Def.Prop_s.prop0
Prims.Tot
[ "total" ]
[]
[ "Vale.Def.Opaque_s.opaque_make", "Vale.AES.AES_common_s.algorithm", "Prims.nat", "FStar.Seq.Base.seq", "Vale.Def.Types_s.quad32", "Vale.Def.Types_s.nat32", "Vale.Def.Prop_s.prop0", "Vale.AES.GCTR_BE.gctr_partial_def" ]
[]
false
false
false
true
false
let gctr_partial =
opaque_make gctr_partial_def
false
Vale.AES.GCTR_BE.fsti
Vale.AES.GCTR_BE.gctr_partial_reveal
val gctr_partial_reveal : _: Prims.unit -> FStar.Pervasives.Lemma (ensures Vale.AES.GCTR_BE.gctr_partial == Vale.AES.GCTR_BE.gctr_partial_def)
let gctr_partial_reveal = opaque_revealer (`%gctr_partial) gctr_partial gctr_partial_def
{ "file_name": "vale/code/crypto/aes/Vale.AES.GCTR_BE.fsti", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 100, "end_line": 59, "start_col": 12, "start_line": 59 }
module Vale.AES.GCTR_BE open Vale.Def.Prop_s open Vale.Def.Opaque_s open Vale.Def.Words_s open Vale.Def.Types_s open Vale.Arch.Types open FStar.Mul open FStar.Seq open Vale.AES.AES_BE_s open Vale.AES.GCTR_BE_s open FStar.Math.Lemmas open Vale.Def.Words.Seq_s let make_gctr_plain_BE (p:seq nat8) : seq nat8 = if length p < pow2_32 then p else empty let inc32lite (cb:quad32) (i:int) : quad32 = if 0 <= i && i < pow2_32 then let sum = cb.lo0 + i in let lo0 = if sum >= pow2_32 then sum - pow2_32 else sum in Mkfour lo0 cb.lo1 cb.hi2 cb.hi3 else Mkfour 42 42 42 42 let empty_seq_quad32 : seq quad32 = empty let partial_seq_agreement (x y:seq quad32) (lo hi:nat) = lo <= hi /\ hi <= length x /\ hi <= length y /\ (forall i . {:pattern (index x i) \/ (index y i)} lo <= i /\ i < hi ==> index x i == index y i) let lemma_eq_reverse_bytes_quad32_seq (s1 s2 s3:seq quad32) (bound:nat) (icb:quad32) (alg:algorithm) (key:seq nat32) : Lemma (requires (is_aes_key_word alg key /\ bound <= length s1 /\ bound <= length s2 /\ bound <= length s3 /\ (forall j . {:pattern (index s2 j)} 0 <= j /\ j < bound ==> index s2 j == quad32_xor (index s3 j) (aes_encrypt_word alg key (inc32 icb j))) /\ (forall j . {:pattern (index s1 j)} 0 <= j /\ j < bound ==> index s1 j == index s2 j))) (ensures (forall j . {:pattern (index s1 j)} 0 <= j /\ j < bound ==> index s1 j == quad32_xor (index s3 j) (aes_encrypt_word alg key (inc32 icb j))) ) = () val gctr_encrypt_block_offset (icb:quad32) (plain:quad32) (alg:algorithm) (key:seq nat32) (i:int) : Lemma (requires is_aes_key_word alg key) (ensures gctr_encrypt_block icb plain alg key i == gctr_encrypt_block (inc32 icb i) plain alg key 0 ) let gctr_partial_def (alg:algorithm) (bound:nat) (plain cipher:seq quad32) (key:seq nat32) (icb:quad32) : prop0 = is_aes_key_word alg key /\ ( let bound = min bound (min (length plain) (length cipher)) in forall j . {:pattern (index cipher j)} 0 <= j /\ j < bound ==> index cipher j == quad32_xor (index plain j) (aes_encrypt_word alg key (inc32 icb j)))
{ "checked_file": "/", "dependencies": [ "Vale.Def.Words_s.fsti.checked", "Vale.Def.Words.Seq_s.fsti.checked", "Vale.Def.Types_s.fst.checked", "Vale.Def.Prop_s.fst.checked", "Vale.Def.Opaque_s.fsti.checked", "Vale.Arch.Types.fsti.checked", "Vale.AES.GCTR_BE_s.fst.checked", "Vale.AES.AES_BE_s.fst.checked", "prims.fst.checked", "FStar.Seq.Properties.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked" ], "interface_file": false, "source_file": "Vale.AES.GCTR_BE.fsti" }
[ { "abbrev": false, "full_module": "Vale.Def.Words.Seq_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Math.Lemmas", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GCTR_BE_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.AES_BE_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Seq", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.Types", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Types_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Opaque_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Prop_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 0, "max_fuel": 1, "max_ifuel": 1, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": true, "smtencoding_l_arith_repr": "native", "smtencoding_nl_arith_repr": "wrapped", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [ "smt.arith.nl=false", "smt.QI.EAGER_THRESHOLD=100", "smt.CASE_SPLIT=3" ], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
_: Prims.unit -> FStar.Pervasives.Lemma (ensures Vale.AES.GCTR_BE.gctr_partial == Vale.AES.GCTR_BE.gctr_partial_def)
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "Vale.Def.Opaque_s.opaque_revealer", "Vale.AES.AES_common_s.algorithm", "Prims.nat", "FStar.Seq.Base.seq", "Vale.Def.Types_s.quad32", "Vale.Def.Types_s.nat32", "Vale.Def.Prop_s.prop0", "Vale.AES.GCTR_BE.gctr_partial", "Vale.AES.GCTR_BE.gctr_partial_def" ]
[]
true
false
true
false
false
let gctr_partial_reveal =
opaque_revealer (`%gctr_partial) gctr_partial gctr_partial_def
false
Vale.AES.GCTR_BE.fsti
Vale.AES.GCTR_BE.gctr_partial_def
val gctr_partial_def (alg: algorithm) (bound: nat) (plain cipher: seq quad32) (key: seq nat32) (icb: quad32) : prop0
val gctr_partial_def (alg: algorithm) (bound: nat) (plain cipher: seq quad32) (key: seq nat32) (icb: quad32) : prop0
let gctr_partial_def (alg:algorithm) (bound:nat) (plain cipher:seq quad32) (key:seq nat32) (icb:quad32) : prop0 = is_aes_key_word alg key /\ ( let bound = min bound (min (length plain) (length cipher)) in forall j . {:pattern (index cipher j)} 0 <= j /\ j < bound ==> index cipher j == quad32_xor (index plain j) (aes_encrypt_word alg key (inc32 icb j)))
{ "file_name": "vale/code/crypto/aes/Vale.AES.GCTR_BE.fsti", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 92, "end_line": 57, "start_col": 0, "start_line": 53 }
module Vale.AES.GCTR_BE open Vale.Def.Prop_s open Vale.Def.Opaque_s open Vale.Def.Words_s open Vale.Def.Types_s open Vale.Arch.Types open FStar.Mul open FStar.Seq open Vale.AES.AES_BE_s open Vale.AES.GCTR_BE_s open FStar.Math.Lemmas open Vale.Def.Words.Seq_s let make_gctr_plain_BE (p:seq nat8) : seq nat8 = if length p < pow2_32 then p else empty let inc32lite (cb:quad32) (i:int) : quad32 = if 0 <= i && i < pow2_32 then let sum = cb.lo0 + i in let lo0 = if sum >= pow2_32 then sum - pow2_32 else sum in Mkfour lo0 cb.lo1 cb.hi2 cb.hi3 else Mkfour 42 42 42 42 let empty_seq_quad32 : seq quad32 = empty let partial_seq_agreement (x y:seq quad32) (lo hi:nat) = lo <= hi /\ hi <= length x /\ hi <= length y /\ (forall i . {:pattern (index x i) \/ (index y i)} lo <= i /\ i < hi ==> index x i == index y i) let lemma_eq_reverse_bytes_quad32_seq (s1 s2 s3:seq quad32) (bound:nat) (icb:quad32) (alg:algorithm) (key:seq nat32) : Lemma (requires (is_aes_key_word alg key /\ bound <= length s1 /\ bound <= length s2 /\ bound <= length s3 /\ (forall j . {:pattern (index s2 j)} 0 <= j /\ j < bound ==> index s2 j == quad32_xor (index s3 j) (aes_encrypt_word alg key (inc32 icb j))) /\ (forall j . {:pattern (index s1 j)} 0 <= j /\ j < bound ==> index s1 j == index s2 j))) (ensures (forall j . {:pattern (index s1 j)} 0 <= j /\ j < bound ==> index s1 j == quad32_xor (index s3 j) (aes_encrypt_word alg key (inc32 icb j))) ) = () val gctr_encrypt_block_offset (icb:quad32) (plain:quad32) (alg:algorithm) (key:seq nat32) (i:int) : Lemma (requires is_aes_key_word alg key) (ensures gctr_encrypt_block icb plain alg key i == gctr_encrypt_block (inc32 icb i) plain alg key 0 )
{ "checked_file": "/", "dependencies": [ "Vale.Def.Words_s.fsti.checked", "Vale.Def.Words.Seq_s.fsti.checked", "Vale.Def.Types_s.fst.checked", "Vale.Def.Prop_s.fst.checked", "Vale.Def.Opaque_s.fsti.checked", "Vale.Arch.Types.fsti.checked", "Vale.AES.GCTR_BE_s.fst.checked", "Vale.AES.AES_BE_s.fst.checked", "prims.fst.checked", "FStar.Seq.Properties.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked" ], "interface_file": false, "source_file": "Vale.AES.GCTR_BE.fsti" }
[ { "abbrev": false, "full_module": "Vale.Def.Words.Seq_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Math.Lemmas", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GCTR_BE_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.AES_BE_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Seq", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.Types", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Types_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Opaque_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Prop_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 0, "max_fuel": 1, "max_ifuel": 1, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": true, "smtencoding_l_arith_repr": "native", "smtencoding_nl_arith_repr": "wrapped", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [ "smt.arith.nl=false", "smt.QI.EAGER_THRESHOLD=100", "smt.CASE_SPLIT=3" ], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
alg: Vale.AES.AES_common_s.algorithm -> bound: Prims.nat -> plain: FStar.Seq.Base.seq Vale.Def.Types_s.quad32 -> cipher: FStar.Seq.Base.seq Vale.Def.Types_s.quad32 -> key: FStar.Seq.Base.seq Vale.Def.Types_s.nat32 -> icb: Vale.Def.Types_s.quad32 -> Vale.Def.Prop_s.prop0
Prims.Tot
[ "total" ]
[]
[ "Vale.AES.AES_common_s.algorithm", "Prims.nat", "FStar.Seq.Base.seq", "Vale.Def.Types_s.quad32", "Vale.Def.Types_s.nat32", "Prims.l_and", "Vale.AES.AES_BE_s.is_aes_key_word", "Prims.l_Forall", "Prims.int", "Prims.b2t", "Prims.op_GreaterThanOrEqual", "Prims.op_LessThan", "FStar.Seq.Base.length", "Prims.l_imp", "Prims.op_LessThanOrEqual", "Prims.eq2", "FStar.Seq.Base.index", "Vale.Def.Types_s.quad32_xor", "Vale.AES.AES_BE_s.aes_encrypt_word", "Vale.AES.GCTR_BE_s.inc32", "Prims.min", "Vale.Def.Prop_s.prop0" ]
[]
false
false
false
true
false
let gctr_partial_def (alg: algorithm) (bound: nat) (plain cipher: seq quad32) (key: seq nat32) (icb: quad32) : prop0 =
is_aes_key_word alg key /\ (let bound = min bound (min (length plain) (length cipher)) in forall j. {:pattern (index cipher j)} 0 <= j /\ j < bound ==> index cipher j == quad32_xor (index plain j) (aes_encrypt_word alg key (inc32 icb j)))
false
Vale.AES.GCTR_BE.fsti
Vale.AES.GCTR_BE.partial_seq_agreement
val partial_seq_agreement : x: FStar.Seq.Base.seq Vale.Def.Types_s.quad32 -> y: FStar.Seq.Base.seq Vale.Def.Types_s.quad32 -> lo: Prims.nat -> hi: Prims.nat -> Prims.logical
let partial_seq_agreement (x y:seq quad32) (lo hi:nat) = lo <= hi /\ hi <= length x /\ hi <= length y /\ (forall i . {:pattern (index x i) \/ (index y i)} lo <= i /\ i < hi ==> index x i == index y i)
{ "file_name": "vale/code/crypto/aes/Vale.AES.GCTR_BE.fsti", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 97, "end_line": 30, "start_col": 0, "start_line": 28 }
module Vale.AES.GCTR_BE open Vale.Def.Prop_s open Vale.Def.Opaque_s open Vale.Def.Words_s open Vale.Def.Types_s open Vale.Arch.Types open FStar.Mul open FStar.Seq open Vale.AES.AES_BE_s open Vale.AES.GCTR_BE_s open FStar.Math.Lemmas open Vale.Def.Words.Seq_s let make_gctr_plain_BE (p:seq nat8) : seq nat8 = if length p < pow2_32 then p else empty let inc32lite (cb:quad32) (i:int) : quad32 = if 0 <= i && i < pow2_32 then let sum = cb.lo0 + i in let lo0 = if sum >= pow2_32 then sum - pow2_32 else sum in Mkfour lo0 cb.lo1 cb.hi2 cb.hi3 else Mkfour 42 42 42 42 let empty_seq_quad32 : seq quad32 = empty
{ "checked_file": "/", "dependencies": [ "Vale.Def.Words_s.fsti.checked", "Vale.Def.Words.Seq_s.fsti.checked", "Vale.Def.Types_s.fst.checked", "Vale.Def.Prop_s.fst.checked", "Vale.Def.Opaque_s.fsti.checked", "Vale.Arch.Types.fsti.checked", "Vale.AES.GCTR_BE_s.fst.checked", "Vale.AES.AES_BE_s.fst.checked", "prims.fst.checked", "FStar.Seq.Properties.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked" ], "interface_file": false, "source_file": "Vale.AES.GCTR_BE.fsti" }
[ { "abbrev": false, "full_module": "Vale.Def.Words.Seq_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Math.Lemmas", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GCTR_BE_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.AES_BE_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Seq", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.Types", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Types_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Opaque_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Prop_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 0, "max_fuel": 1, "max_ifuel": 1, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": true, "smtencoding_l_arith_repr": "native", "smtencoding_nl_arith_repr": "wrapped", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [ "smt.arith.nl=false", "smt.QI.EAGER_THRESHOLD=100", "smt.CASE_SPLIT=3" ], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
x: FStar.Seq.Base.seq Vale.Def.Types_s.quad32 -> y: FStar.Seq.Base.seq Vale.Def.Types_s.quad32 -> lo: Prims.nat -> hi: Prims.nat -> Prims.logical
Prims.Tot
[ "total" ]
[]
[ "FStar.Seq.Base.seq", "Vale.Def.Types_s.quad32", "Prims.nat", "Prims.l_and", "Prims.b2t", "Prims.op_LessThanOrEqual", "FStar.Seq.Base.length", "Prims.l_Forall", "Prims.int", "Prims.op_GreaterThanOrEqual", "Prims.op_LessThan", "Prims.l_imp", "Prims.eq2", "FStar.Seq.Base.index", "Prims.logical" ]
[]
false
false
false
true
true
let partial_seq_agreement (x y: seq quad32) (lo hi: nat) =
lo <= hi /\ hi <= length x /\ hi <= length y /\ (forall i. {:pattern (index x i)\/(index y i)} lo <= i /\ i < hi ==> index x i == index y i)
false
Vale.AES.GCTR_BE.fsti
Vale.AES.GCTR_BE.inc32lite
val inc32lite (cb: quad32) (i: int) : quad32
val inc32lite (cb: quad32) (i: int) : quad32
let inc32lite (cb:quad32) (i:int) : quad32 = if 0 <= i && i < pow2_32 then let sum = cb.lo0 + i in let lo0 = if sum >= pow2_32 then sum - pow2_32 else sum in Mkfour lo0 cb.lo1 cb.hi2 cb.hi3 else Mkfour 42 42 42 42
{ "file_name": "vale/code/crypto/aes/Vale.AES.GCTR_BE.fsti", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 22, "end_line": 24, "start_col": 0, "start_line": 18 }
module Vale.AES.GCTR_BE open Vale.Def.Prop_s open Vale.Def.Opaque_s open Vale.Def.Words_s open Vale.Def.Types_s open Vale.Arch.Types open FStar.Mul open FStar.Seq open Vale.AES.AES_BE_s open Vale.AES.GCTR_BE_s open FStar.Math.Lemmas open Vale.Def.Words.Seq_s let make_gctr_plain_BE (p:seq nat8) : seq nat8 = if length p < pow2_32 then p else empty
{ "checked_file": "/", "dependencies": [ "Vale.Def.Words_s.fsti.checked", "Vale.Def.Words.Seq_s.fsti.checked", "Vale.Def.Types_s.fst.checked", "Vale.Def.Prop_s.fst.checked", "Vale.Def.Opaque_s.fsti.checked", "Vale.Arch.Types.fsti.checked", "Vale.AES.GCTR_BE_s.fst.checked", "Vale.AES.AES_BE_s.fst.checked", "prims.fst.checked", "FStar.Seq.Properties.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked" ], "interface_file": false, "source_file": "Vale.AES.GCTR_BE.fsti" }
[ { "abbrev": false, "full_module": "Vale.Def.Words.Seq_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Math.Lemmas", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GCTR_BE_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.AES_BE_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Seq", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.Types", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Types_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Opaque_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Prop_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 0, "max_fuel": 1, "max_ifuel": 1, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": true, "smtencoding_l_arith_repr": "native", "smtencoding_nl_arith_repr": "wrapped", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [ "smt.arith.nl=false", "smt.QI.EAGER_THRESHOLD=100", "smt.CASE_SPLIT=3" ], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
cb: Vale.Def.Types_s.quad32 -> i: Prims.int -> Vale.Def.Types_s.quad32
Prims.Tot
[ "total" ]
[]
[ "Vale.Def.Types_s.quad32", "Prims.int", "Prims.op_AmpAmp", "Prims.op_LessThanOrEqual", "Prims.op_LessThan", "Vale.Def.Words_s.pow2_32", "Vale.Def.Words_s.Mkfour", "Vale.Def.Types_s.nat32", "Vale.Def.Words_s.__proj__Mkfour__item__lo1", "Vale.Def.Words_s.__proj__Mkfour__item__hi2", "Vale.Def.Words_s.__proj__Mkfour__item__hi3", "Vale.Def.Words_s.nat32", "Prims.op_GreaterThanOrEqual", "Prims.op_Subtraction", "Prims.bool", "Prims.op_Addition", "Vale.Def.Words_s.__proj__Mkfour__item__lo0" ]
[]
false
false
false
true
false
let inc32lite (cb: quad32) (i: int) : quad32 =
if 0 <= i && i < pow2_32 then let sum = cb.lo0 + i in let lo0 = if sum >= pow2_32 then sum - pow2_32 else sum in Mkfour lo0 cb.lo1 cb.hi2 cb.hi3 else Mkfour 42 42 42 42
false
Hacl.HPKE.Curve64_CP32_SHA512.fsti
Hacl.HPKE.Curve64_CP32_SHA512.vale_p
val vale_p : Prims.logical
let vale_p = Vale.X64.CPU_Features_s.(adx_enabled /\ bmi2_enabled)
{ "file_name": "code/hpke/Hacl.HPKE.Curve64_CP32_SHA512.fsti", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 66, "end_line": 13, "start_col": 0, "start_line": 13 }
module Hacl.HPKE.Curve64_CP32_SHA512 open Hacl.Impl.HPKE module S = Spec.Agile.HPKE module DH = Spec.Agile.DH module AEAD = Spec.Agile.AEAD module Hash = Spec.Agile.Hash noextract unfold let cs:S.ciphersuite = (DH.DH_Curve25519, Hash.SHA2_256, S.Seal AEAD.CHACHA20_POLY1305, Hash.SHA2_512)
{ "checked_file": "/", "dependencies": [ "Vale.X64.CPU_Features_s.fst.checked", "Spec.Agile.HPKE.fsti.checked", "Spec.Agile.Hash.fsti.checked", "Spec.Agile.DH.fst.checked", "Spec.Agile.AEAD.fsti.checked", "prims.fst.checked", "Hacl.Impl.HPKE.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked" ], "interface_file": false, "source_file": "Hacl.HPKE.Curve64_CP32_SHA512.fsti" }
[ { "abbrev": true, "full_module": "Spec.Agile.Hash", "short_module": "Hash" }, { "abbrev": true, "full_module": "Spec.Agile.AEAD", "short_module": "AEAD" }, { "abbrev": true, "full_module": "Spec.Agile.DH", "short_module": "DH" }, { "abbrev": true, "full_module": "Spec.Agile.HPKE", "short_module": "S" }, { "abbrev": false, "full_module": "Hacl.Impl.HPKE", "short_module": null }, { "abbrev": false, "full_module": "Hacl.HPKE", "short_module": null }, { "abbrev": false, "full_module": "Hacl.HPKE", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
Prims.logical
Prims.Tot
[ "total" ]
[]
[ "Prims.l_and", "Prims.b2t", "Vale.X64.CPU_Features_s.adx_enabled", "Vale.X64.CPU_Features_s.bmi2_enabled" ]
[]
false
false
false
true
true
let vale_p =
let open Vale.X64.CPU_Features_s in adx_enabled /\ bmi2_enabled
false
DoublyLinkedList.fst
DoublyLinkedList.heap
val heap : Type
let heap = HS.mem
{ "file_name": "examples/doublylinkedlist/DoublyLinkedList.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 24, "end_line": 33, "start_col": 7, "start_line": 33 }
(* Copyright 2008-2019 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module DoublyLinkedList open FStar open FStar.HyperStack.ST open FStar.Ghost open LowStar.ModifiesPat open FStar.List.Tot open FStar.List.Pure open LowStar.BufferOps module Mod = LowStar.Modifies module ST = FStar.HyperStack.ST module HS = FStar.HyperStack module B = LowStar.Buffer /// Convenience renaming
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowStar.ModifiesPat.fst.checked", "LowStar.Modifies.fst.checked", "LowStar.BufferOps.fst.checked", "LowStar.Buffer.fst.checked", "FStar.UInt32.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked", "FStar.List.Pure.Properties.fst.checked", "FStar.List.Pure.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked", "FStar.Classical.fsti.checked" ], "interface_file": false, "source_file": "DoublyLinkedList.fst" }
[ { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": true, "full_module": "LowStar.Modifies", "short_module": "Mod" }, { "abbrev": false, "full_module": "LowStar.BufferOps", "short_module": null }, { "abbrev": false, "full_module": "FStar.List.Pure", "short_module": null }, { "abbrev": false, "full_module": "FStar.List.Tot", "short_module": null }, { "abbrev": false, "full_module": "LowStar.ModifiesPat", "short_module": null }, { "abbrev": false, "full_module": "FStar.Ghost", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
Type
Prims.Tot
[ "total" ]
[]
[ "FStar.Monotonic.HyperStack.mem" ]
[]
false
false
false
true
true
let heap =
HS.mem
false
DoublyLinkedList.fst
DoublyLinkedList.contains
val contains : h: FStar.Monotonic.HyperStack.mem -> b: LowStar.Monotonic.Buffer.mbuffer a rrel rel -> Type0
let contains #a #rrel #rel h b = B.live #a #rrel #rel h b
{ "file_name": "examples/doublylinkedlist/DoublyLinkedList.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 64, "end_line": 34, "start_col": 7, "start_line": 34 }
(* Copyright 2008-2019 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module DoublyLinkedList open FStar open FStar.HyperStack.ST open FStar.Ghost open LowStar.ModifiesPat open FStar.List.Tot open FStar.List.Pure open LowStar.BufferOps module Mod = LowStar.Modifies module ST = FStar.HyperStack.ST module HS = FStar.HyperStack module B = LowStar.Buffer /// Convenience renaming
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowStar.ModifiesPat.fst.checked", "LowStar.Modifies.fst.checked", "LowStar.BufferOps.fst.checked", "LowStar.Buffer.fst.checked", "FStar.UInt32.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked", "FStar.List.Pure.Properties.fst.checked", "FStar.List.Pure.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked", "FStar.Classical.fsti.checked" ], "interface_file": false, "source_file": "DoublyLinkedList.fst" }
[ { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": true, "full_module": "LowStar.Modifies", "short_module": "Mod" }, { "abbrev": false, "full_module": "LowStar.BufferOps", "short_module": null }, { "abbrev": false, "full_module": "FStar.List.Pure", "short_module": null }, { "abbrev": false, "full_module": "FStar.List.Tot", "short_module": null }, { "abbrev": false, "full_module": "LowStar.ModifiesPat", "short_module": null }, { "abbrev": false, "full_module": "FStar.Ghost", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
h: FStar.Monotonic.HyperStack.mem -> b: LowStar.Monotonic.Buffer.mbuffer a rrel rel -> Type0
Prims.Tot
[ "total" ]
[]
[ "LowStar.Monotonic.Buffer.srel", "FStar.Monotonic.HyperStack.mem", "LowStar.Monotonic.Buffer.mbuffer", "LowStar.Monotonic.Buffer.live" ]
[]
false
false
false
false
true
let contains #a #rrel #rel h b =
B.live #a #rrel #rel h b
false
DoublyLinkedList.fst
DoublyLinkedList.dll_contained
val dll_contained (#t: Type) (h0: heap) (d: dll t) : GTot Type0
val dll_contained (#t: Type) (h0: heap) (d: dll t) : GTot Type0
let dll_contained (#t:Type) (h0:heap) (d:dll t) : GTot Type0 = h0 `contains` d.lhead /\ h0 `contains` d.ltail /\ nodelist_contained h0 d.nodes
{ "file_name": "examples/doublylinkedlist/DoublyLinkedList.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 31, "end_line": 172, "start_col": 0, "start_line": 169 }
(* Copyright 2008-2019 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module DoublyLinkedList open FStar open FStar.HyperStack.ST open FStar.Ghost open LowStar.ModifiesPat open FStar.List.Tot open FStar.List.Pure open LowStar.BufferOps module Mod = LowStar.Modifies module ST = FStar.HyperStack.ST module HS = FStar.HyperStack module B = LowStar.Buffer /// Convenience renaming unfold let heap = HS.mem unfold let contains #a #rrel #rel h b = B.live #a #rrel #rel h b /// Convenience patterns let lemma_non_null (#t:Type) (a:pointer_or_null t) : Lemma (requires (a =!= null)) (ensures (len a = 1ul)) [SMTPat (len a)] = null_unique a /// Convenience operators unfold let (.[]) (s:list 'a) (n:nat{n < length s}) = index s n unfold let (~.) (#t:Type) (a:t) : Tot (erased (list t)) = [a] unfold let (^+) (#t:Type) (a:t) (b:erased (list t)) : Tot (erased (list t)) = Cons a b unfold let (+^) (#t:Type) (a:erased (list t)) (b:t) : Tot (erased (list t)) = append a [b] unfold let (^@^) (#t:Type) (a:erased (list t)) (b:erased (list t)) : Tot (erased (list t)) = append a b unfold let (@) (a:pointer 't) (h0:heap) = B.get h0 a 0 unfold let (^@) (a:pointer_or_null 't{a =!= null}) (h0:heap) = B.get h0 a 0 /// All the data structures #set-options "--__no_positivity" unopteq (** Node of a doubly linked list *) type node (t:Type0) = { (* forward link *) flink: pointer_or_null (node t); (* backward link *) blink: pointer_or_null (node t); (* payload *) p: t; } #reset-options private type nodelist t = list (pointer (node t)) unopteq (** Doubly linked list head *) type dll (t:Type0) ={ lhead: pointer_or_null (node t); ltail: pointer_or_null (node t); nodes: erased (nodelist t); } type nonempty_dll t = (h:dll t{h.lhead =!= null /\ h.ltail =!= null}) unopteq private (** An "almost valid" dll *) type piece t = { phead: pointer (node t); ptail: pointer (node t); pnodes: erased (nodelist t); } unopteq private (** An intermediate for when linked lists are being formed or destroyed *) type fragment t = | Frag0 : fragment t | Frag1 : piece t -> fragment t | Frag2 : piece t -> piece t -> fragment t | Frag3 : piece t -> piece t -> piece t -> fragment t /// Some useful empty initializers (** Initialize an element of a doubly linked list *) val empty_node: #t:Type -> payload:t -> node t let empty_node #t payload = { flink = null ; blink = null ; p = payload } (** Initialize a doubly linked list head *) val empty_list: #t:Type -> dll t let empty_list #t = { lhead = null ; ltail = null ; nodes = [] } /// Convenience wrappers for writing properties on fragments let fragment_for_each0 (#t:Type) (pr:piece t -> GTot Type0) (f:fragment t) : GTot Type0 = match f with | Frag0 -> True | Frag1 p1 -> pr p1 | Frag2 p1 p2 -> pr p1 /\ pr p2 | Frag3 p1 p2 p3 -> pr p1 /\ pr p2 /\ pr p3 let fragment_for_each1 (#t:Type) (#u:Type) (pr:u -> piece t -> GTot Type0) (v:u) (f:fragment t) : GTot Type0 = match f with | Frag0 -> True | Frag1 p1 -> pr v p1 | Frag2 p1 p2 -> pr v p1 /\ pr v p2 | Frag3 p1 p2 p3 -> pr v p1 /\ pr v p2 /\ pr v p3 let fragment_length (#t:Type) (f:fragment t) : GTot int = match f with | Frag0 -> 0 | Frag1 _ -> 1 | Frag2 _ _ -> 2 | Frag3 _ _ _ -> 3 /// Ghostly connections let dll_ghostly_connections (#t:Type) (d:dll t) : GTot Type0 = let nodes = d.nodes in match length nodes with | 0 -> d.lhead == null /\ d.ltail == null | _ -> d.lhead =!= null /\ d.ltail =!= null /\ d.lhead == hd nodes /\ d.ltail == last nodes let piece_ghostly_connections (#t:Type) (p:piece t) : GTot Type0 = let nodes = p.pnodes in match length nodes with | 0 -> False | _ -> p.phead == hd nodes /\ p.ptail == last nodes let rec fragment_ghostly_connections (#t:Type) (f:fragment t) : GTot Type0 = fragment_for_each0 piece_ghostly_connections f /// Containment properties /// /// WARNING: [@@] and [^@] require containment to reasonably talk about /// what they do. let rec nodelist_contained0 (#t:Type) (h0:heap) (nl:nodelist t) : GTot Type0 = match nl with | [] -> True | n :: ns -> h0 `contains` n /\ nodelist_contained0 h0 ns let rec nodelist_contained (#t:Type) (h0:heap) (nl:nodelist t) : GTot Type0 = nodelist_contained0 h0 nl
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowStar.ModifiesPat.fst.checked", "LowStar.Modifies.fst.checked", "LowStar.BufferOps.fst.checked", "LowStar.Buffer.fst.checked", "FStar.UInt32.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked", "FStar.List.Pure.Properties.fst.checked", "FStar.List.Pure.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked", "FStar.Classical.fsti.checked" ], "interface_file": false, "source_file": "DoublyLinkedList.fst" }
[ { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": true, "full_module": "LowStar.Modifies", "short_module": "Mod" }, { "abbrev": false, "full_module": "LowStar.BufferOps", "short_module": null }, { "abbrev": false, "full_module": "FStar.List.Pure", "short_module": null }, { "abbrev": false, "full_module": "FStar.List.Tot", "short_module": null }, { "abbrev": false, "full_module": "LowStar.ModifiesPat", "short_module": null }, { "abbrev": false, "full_module": "FStar.Ghost", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
h0: DoublyLinkedList.heap -> d: DoublyLinkedList.dll t -> Prims.GTot Type0
Prims.GTot
[ "sometrivial" ]
[]
[ "DoublyLinkedList.heap", "DoublyLinkedList.dll", "Prims.l_and", "DoublyLinkedList.contains", "DoublyLinkedList.node", "LowStar.Buffer.trivial_preorder", "DoublyLinkedList.__proj__Mkdll__item__lhead", "DoublyLinkedList.__proj__Mkdll__item__ltail", "DoublyLinkedList.nodelist_contained", "FStar.Ghost.reveal", "DoublyLinkedList.nodelist", "DoublyLinkedList.__proj__Mkdll__item__nodes" ]
[]
false
false
false
false
true
let dll_contained (#t: Type) (h0: heap) (d: dll t) : GTot Type0 =
h0 `contains` d.lhead /\ h0 `contains` d.ltail /\ nodelist_contained h0 d.nodes
false
DoublyLinkedList.fst
DoublyLinkedList.fragment_ghostly_connections
val fragment_ghostly_connections (#t: Type) (f: fragment t) : GTot Type0
val fragment_ghostly_connections (#t: Type) (f: fragment t) : GTot Type0
let rec fragment_ghostly_connections (#t:Type) (f:fragment t) : GTot Type0 = fragment_for_each0 piece_ghostly_connections f
{ "file_name": "examples/doublylinkedlist/DoublyLinkedList.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 48, "end_line": 155, "start_col": 0, "start_line": 154 }
(* Copyright 2008-2019 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module DoublyLinkedList open FStar open FStar.HyperStack.ST open FStar.Ghost open LowStar.ModifiesPat open FStar.List.Tot open FStar.List.Pure open LowStar.BufferOps module Mod = LowStar.Modifies module ST = FStar.HyperStack.ST module HS = FStar.HyperStack module B = LowStar.Buffer /// Convenience renaming unfold let heap = HS.mem unfold let contains #a #rrel #rel h b = B.live #a #rrel #rel h b /// Convenience patterns let lemma_non_null (#t:Type) (a:pointer_or_null t) : Lemma (requires (a =!= null)) (ensures (len a = 1ul)) [SMTPat (len a)] = null_unique a /// Convenience operators unfold let (.[]) (s:list 'a) (n:nat{n < length s}) = index s n unfold let (~.) (#t:Type) (a:t) : Tot (erased (list t)) = [a] unfold let (^+) (#t:Type) (a:t) (b:erased (list t)) : Tot (erased (list t)) = Cons a b unfold let (+^) (#t:Type) (a:erased (list t)) (b:t) : Tot (erased (list t)) = append a [b] unfold let (^@^) (#t:Type) (a:erased (list t)) (b:erased (list t)) : Tot (erased (list t)) = append a b unfold let (@) (a:pointer 't) (h0:heap) = B.get h0 a 0 unfold let (^@) (a:pointer_or_null 't{a =!= null}) (h0:heap) = B.get h0 a 0 /// All the data structures #set-options "--__no_positivity" unopteq (** Node of a doubly linked list *) type node (t:Type0) = { (* forward link *) flink: pointer_or_null (node t); (* backward link *) blink: pointer_or_null (node t); (* payload *) p: t; } #reset-options private type nodelist t = list (pointer (node t)) unopteq (** Doubly linked list head *) type dll (t:Type0) ={ lhead: pointer_or_null (node t); ltail: pointer_or_null (node t); nodes: erased (nodelist t); } type nonempty_dll t = (h:dll t{h.lhead =!= null /\ h.ltail =!= null}) unopteq private (** An "almost valid" dll *) type piece t = { phead: pointer (node t); ptail: pointer (node t); pnodes: erased (nodelist t); } unopteq private (** An intermediate for when linked lists are being formed or destroyed *) type fragment t = | Frag0 : fragment t | Frag1 : piece t -> fragment t | Frag2 : piece t -> piece t -> fragment t | Frag3 : piece t -> piece t -> piece t -> fragment t /// Some useful empty initializers (** Initialize an element of a doubly linked list *) val empty_node: #t:Type -> payload:t -> node t let empty_node #t payload = { flink = null ; blink = null ; p = payload } (** Initialize a doubly linked list head *) val empty_list: #t:Type -> dll t let empty_list #t = { lhead = null ; ltail = null ; nodes = [] } /// Convenience wrappers for writing properties on fragments let fragment_for_each0 (#t:Type) (pr:piece t -> GTot Type0) (f:fragment t) : GTot Type0 = match f with | Frag0 -> True | Frag1 p1 -> pr p1 | Frag2 p1 p2 -> pr p1 /\ pr p2 | Frag3 p1 p2 p3 -> pr p1 /\ pr p2 /\ pr p3 let fragment_for_each1 (#t:Type) (#u:Type) (pr:u -> piece t -> GTot Type0) (v:u) (f:fragment t) : GTot Type0 = match f with | Frag0 -> True | Frag1 p1 -> pr v p1 | Frag2 p1 p2 -> pr v p1 /\ pr v p2 | Frag3 p1 p2 p3 -> pr v p1 /\ pr v p2 /\ pr v p3 let fragment_length (#t:Type) (f:fragment t) : GTot int = match f with | Frag0 -> 0 | Frag1 _ -> 1 | Frag2 _ _ -> 2 | Frag3 _ _ _ -> 3 /// Ghostly connections let dll_ghostly_connections (#t:Type) (d:dll t) : GTot Type0 = let nodes = d.nodes in match length nodes with | 0 -> d.lhead == null /\ d.ltail == null | _ -> d.lhead =!= null /\ d.ltail =!= null /\ d.lhead == hd nodes /\ d.ltail == last nodes let piece_ghostly_connections (#t:Type) (p:piece t) : GTot Type0 = let nodes = p.pnodes in match length nodes with | 0 -> False | _ -> p.phead == hd nodes /\ p.ptail == last nodes
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowStar.ModifiesPat.fst.checked", "LowStar.Modifies.fst.checked", "LowStar.BufferOps.fst.checked", "LowStar.Buffer.fst.checked", "FStar.UInt32.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked", "FStar.List.Pure.Properties.fst.checked", "FStar.List.Pure.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked", "FStar.Classical.fsti.checked" ], "interface_file": false, "source_file": "DoublyLinkedList.fst" }
[ { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": true, "full_module": "LowStar.Modifies", "short_module": "Mod" }, { "abbrev": false, "full_module": "LowStar.BufferOps", "short_module": null }, { "abbrev": false, "full_module": "FStar.List.Pure", "short_module": null }, { "abbrev": false, "full_module": "FStar.List.Tot", "short_module": null }, { "abbrev": false, "full_module": "LowStar.ModifiesPat", "short_module": null }, { "abbrev": false, "full_module": "FStar.Ghost", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
f: DoublyLinkedList.fragment t -> Prims.GTot Type0
Prims.GTot
[ "sometrivial" ]
[]
[ "DoublyLinkedList.fragment", "DoublyLinkedList.fragment_for_each0", "DoublyLinkedList.piece_ghostly_connections" ]
[ "recursion" ]
false
false
false
false
true
let rec fragment_ghostly_connections (#t: Type) (f: fragment t) : GTot Type0 =
fragment_for_each0 piece_ghostly_connections f
false
DoublyLinkedList.fst
DoublyLinkedList.piece_contained
val piece_contained (#t: Type) (h0: heap) (p: piece t) : GTot Type0
val piece_contained (#t: Type) (h0: heap) (p: piece t) : GTot Type0
let piece_contained (#t:Type) (h0:heap) (p:piece t) : GTot Type0 = h0 `contains` p.phead /\ h0 `contains` p.ptail /\ nodelist_contained h0 p.pnodes
{ "file_name": "examples/doublylinkedlist/DoublyLinkedList.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 32, "end_line": 177, "start_col": 0, "start_line": 174 }
(* Copyright 2008-2019 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module DoublyLinkedList open FStar open FStar.HyperStack.ST open FStar.Ghost open LowStar.ModifiesPat open FStar.List.Tot open FStar.List.Pure open LowStar.BufferOps module Mod = LowStar.Modifies module ST = FStar.HyperStack.ST module HS = FStar.HyperStack module B = LowStar.Buffer /// Convenience renaming unfold let heap = HS.mem unfold let contains #a #rrel #rel h b = B.live #a #rrel #rel h b /// Convenience patterns let lemma_non_null (#t:Type) (a:pointer_or_null t) : Lemma (requires (a =!= null)) (ensures (len a = 1ul)) [SMTPat (len a)] = null_unique a /// Convenience operators unfold let (.[]) (s:list 'a) (n:nat{n < length s}) = index s n unfold let (~.) (#t:Type) (a:t) : Tot (erased (list t)) = [a] unfold let (^+) (#t:Type) (a:t) (b:erased (list t)) : Tot (erased (list t)) = Cons a b unfold let (+^) (#t:Type) (a:erased (list t)) (b:t) : Tot (erased (list t)) = append a [b] unfold let (^@^) (#t:Type) (a:erased (list t)) (b:erased (list t)) : Tot (erased (list t)) = append a b unfold let (@) (a:pointer 't) (h0:heap) = B.get h0 a 0 unfold let (^@) (a:pointer_or_null 't{a =!= null}) (h0:heap) = B.get h0 a 0 /// All the data structures #set-options "--__no_positivity" unopteq (** Node of a doubly linked list *) type node (t:Type0) = { (* forward link *) flink: pointer_or_null (node t); (* backward link *) blink: pointer_or_null (node t); (* payload *) p: t; } #reset-options private type nodelist t = list (pointer (node t)) unopteq (** Doubly linked list head *) type dll (t:Type0) ={ lhead: pointer_or_null (node t); ltail: pointer_or_null (node t); nodes: erased (nodelist t); } type nonempty_dll t = (h:dll t{h.lhead =!= null /\ h.ltail =!= null}) unopteq private (** An "almost valid" dll *) type piece t = { phead: pointer (node t); ptail: pointer (node t); pnodes: erased (nodelist t); } unopteq private (** An intermediate for when linked lists are being formed or destroyed *) type fragment t = | Frag0 : fragment t | Frag1 : piece t -> fragment t | Frag2 : piece t -> piece t -> fragment t | Frag3 : piece t -> piece t -> piece t -> fragment t /// Some useful empty initializers (** Initialize an element of a doubly linked list *) val empty_node: #t:Type -> payload:t -> node t let empty_node #t payload = { flink = null ; blink = null ; p = payload } (** Initialize a doubly linked list head *) val empty_list: #t:Type -> dll t let empty_list #t = { lhead = null ; ltail = null ; nodes = [] } /// Convenience wrappers for writing properties on fragments let fragment_for_each0 (#t:Type) (pr:piece t -> GTot Type0) (f:fragment t) : GTot Type0 = match f with | Frag0 -> True | Frag1 p1 -> pr p1 | Frag2 p1 p2 -> pr p1 /\ pr p2 | Frag3 p1 p2 p3 -> pr p1 /\ pr p2 /\ pr p3 let fragment_for_each1 (#t:Type) (#u:Type) (pr:u -> piece t -> GTot Type0) (v:u) (f:fragment t) : GTot Type0 = match f with | Frag0 -> True | Frag1 p1 -> pr v p1 | Frag2 p1 p2 -> pr v p1 /\ pr v p2 | Frag3 p1 p2 p3 -> pr v p1 /\ pr v p2 /\ pr v p3 let fragment_length (#t:Type) (f:fragment t) : GTot int = match f with | Frag0 -> 0 | Frag1 _ -> 1 | Frag2 _ _ -> 2 | Frag3 _ _ _ -> 3 /// Ghostly connections let dll_ghostly_connections (#t:Type) (d:dll t) : GTot Type0 = let nodes = d.nodes in match length nodes with | 0 -> d.lhead == null /\ d.ltail == null | _ -> d.lhead =!= null /\ d.ltail =!= null /\ d.lhead == hd nodes /\ d.ltail == last nodes let piece_ghostly_connections (#t:Type) (p:piece t) : GTot Type0 = let nodes = p.pnodes in match length nodes with | 0 -> False | _ -> p.phead == hd nodes /\ p.ptail == last nodes let rec fragment_ghostly_connections (#t:Type) (f:fragment t) : GTot Type0 = fragment_for_each0 piece_ghostly_connections f /// Containment properties /// /// WARNING: [@@] and [^@] require containment to reasonably talk about /// what they do. let rec nodelist_contained0 (#t:Type) (h0:heap) (nl:nodelist t) : GTot Type0 = match nl with | [] -> True | n :: ns -> h0 `contains` n /\ nodelist_contained0 h0 ns let rec nodelist_contained (#t:Type) (h0:heap) (nl:nodelist t) : GTot Type0 = nodelist_contained0 h0 nl let dll_contained (#t:Type) (h0:heap) (d:dll t) : GTot Type0 = h0 `contains` d.lhead /\ h0 `contains` d.ltail /\ nodelist_contained h0 d.nodes
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowStar.ModifiesPat.fst.checked", "LowStar.Modifies.fst.checked", "LowStar.BufferOps.fst.checked", "LowStar.Buffer.fst.checked", "FStar.UInt32.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked", "FStar.List.Pure.Properties.fst.checked", "FStar.List.Pure.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked", "FStar.Classical.fsti.checked" ], "interface_file": false, "source_file": "DoublyLinkedList.fst" }
[ { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": true, "full_module": "LowStar.Modifies", "short_module": "Mod" }, { "abbrev": false, "full_module": "LowStar.BufferOps", "short_module": null }, { "abbrev": false, "full_module": "FStar.List.Pure", "short_module": null }, { "abbrev": false, "full_module": "FStar.List.Tot", "short_module": null }, { "abbrev": false, "full_module": "LowStar.ModifiesPat", "short_module": null }, { "abbrev": false, "full_module": "FStar.Ghost", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
h0: DoublyLinkedList.heap -> p: DoublyLinkedList.piece t -> Prims.GTot Type0
Prims.GTot
[ "sometrivial" ]
[]
[ "DoublyLinkedList.heap", "DoublyLinkedList.piece", "Prims.l_and", "DoublyLinkedList.contains", "DoublyLinkedList.node", "LowStar.Buffer.trivial_preorder", "DoublyLinkedList.__proj__Mkpiece__item__phead", "DoublyLinkedList.__proj__Mkpiece__item__ptail", "DoublyLinkedList.nodelist_contained", "FStar.Ghost.reveal", "DoublyLinkedList.nodelist", "DoublyLinkedList.__proj__Mkpiece__item__pnodes" ]
[]
false
false
false
false
true
let piece_contained (#t: Type) (h0: heap) (p: piece t) : GTot Type0 =
h0 `contains` p.phead /\ h0 `contains` p.ptail /\ nodelist_contained h0 p.pnodes
false
DoublyLinkedList.fst
DoublyLinkedList.lemma_non_null
val lemma_non_null (#t: Type) (a: pointer_or_null t) : Lemma (requires (a =!= null)) (ensures (len a = 1ul)) [SMTPat (len a)]
val lemma_non_null (#t: Type) (a: pointer_or_null t) : Lemma (requires (a =!= null)) (ensures (len a = 1ul)) [SMTPat (len a)]
let lemma_non_null (#t:Type) (a:pointer_or_null t) : Lemma (requires (a =!= null)) (ensures (len a = 1ul)) [SMTPat (len a)] = null_unique a
{ "file_name": "examples/doublylinkedlist/DoublyLinkedList.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 15, "end_line": 43, "start_col": 0, "start_line": 38 }
(* Copyright 2008-2019 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module DoublyLinkedList open FStar open FStar.HyperStack.ST open FStar.Ghost open LowStar.ModifiesPat open FStar.List.Tot open FStar.List.Pure open LowStar.BufferOps module Mod = LowStar.Modifies module ST = FStar.HyperStack.ST module HS = FStar.HyperStack module B = LowStar.Buffer /// Convenience renaming unfold let heap = HS.mem unfold let contains #a #rrel #rel h b = B.live #a #rrel #rel h b /// Convenience patterns
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowStar.ModifiesPat.fst.checked", "LowStar.Modifies.fst.checked", "LowStar.BufferOps.fst.checked", "LowStar.Buffer.fst.checked", "FStar.UInt32.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked", "FStar.List.Pure.Properties.fst.checked", "FStar.List.Pure.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked", "FStar.Classical.fsti.checked" ], "interface_file": false, "source_file": "DoublyLinkedList.fst" }
[ { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": true, "full_module": "LowStar.Modifies", "short_module": "Mod" }, { "abbrev": false, "full_module": "LowStar.BufferOps", "short_module": null }, { "abbrev": false, "full_module": "FStar.List.Pure", "short_module": null }, { "abbrev": false, "full_module": "FStar.List.Tot", "short_module": null }, { "abbrev": false, "full_module": "LowStar.ModifiesPat", "short_module": null }, { "abbrev": false, "full_module": "FStar.Ghost", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
a: LowStar.Buffer.pointer_or_null t -> FStar.Pervasives.Lemma (requires ~(a == LowStar.Buffer.null)) (ensures LowStar.Monotonic.Buffer.len a = 1ul) [SMTPat (LowStar.Monotonic.Buffer.len a)]
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "LowStar.Buffer.pointer_or_null", "LowStar.Monotonic.Buffer.null_unique", "LowStar.Buffer.trivial_preorder", "Prims.unit", "Prims.l_not", "Prims.eq2", "LowStar.Buffer.buffer", "LowStar.Buffer.null", "Prims.squash", "Prims.b2t", "Prims.op_Equality", "FStar.UInt32.t", "LowStar.Monotonic.Buffer.len", "FStar.UInt32.__uint_to_t", "Prims.Cons", "FStar.Pervasives.pattern", "FStar.Pervasives.smt_pat", "Prims.Nil" ]
[]
true
false
true
false
false
let lemma_non_null (#t: Type) (a: pointer_or_null t) : Lemma (requires (a =!= null)) (ensures (len a = 1ul)) [SMTPat (len a)] =
null_unique a
false
DoublyLinkedList.fst
DoublyLinkedList.node_fp_f
val node_fp_f (#t: Type) (n: node t) : GTot Mod.loc
val node_fp_f (#t: Type) (n: node t) : GTot Mod.loc
let node_fp_f (#t:Type) (n:node t) : GTot Mod.loc = Mod.loc_buffer n.flink
{ "file_name": "examples/doublylinkedlist/DoublyLinkedList.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 24, "end_line": 185, "start_col": 0, "start_line": 184 }
(* Copyright 2008-2019 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module DoublyLinkedList open FStar open FStar.HyperStack.ST open FStar.Ghost open LowStar.ModifiesPat open FStar.List.Tot open FStar.List.Pure open LowStar.BufferOps module Mod = LowStar.Modifies module ST = FStar.HyperStack.ST module HS = FStar.HyperStack module B = LowStar.Buffer /// Convenience renaming unfold let heap = HS.mem unfold let contains #a #rrel #rel h b = B.live #a #rrel #rel h b /// Convenience patterns let lemma_non_null (#t:Type) (a:pointer_or_null t) : Lemma (requires (a =!= null)) (ensures (len a = 1ul)) [SMTPat (len a)] = null_unique a /// Convenience operators unfold let (.[]) (s:list 'a) (n:nat{n < length s}) = index s n unfold let (~.) (#t:Type) (a:t) : Tot (erased (list t)) = [a] unfold let (^+) (#t:Type) (a:t) (b:erased (list t)) : Tot (erased (list t)) = Cons a b unfold let (+^) (#t:Type) (a:erased (list t)) (b:t) : Tot (erased (list t)) = append a [b] unfold let (^@^) (#t:Type) (a:erased (list t)) (b:erased (list t)) : Tot (erased (list t)) = append a b unfold let (@) (a:pointer 't) (h0:heap) = B.get h0 a 0 unfold let (^@) (a:pointer_or_null 't{a =!= null}) (h0:heap) = B.get h0 a 0 /// All the data structures #set-options "--__no_positivity" unopteq (** Node of a doubly linked list *) type node (t:Type0) = { (* forward link *) flink: pointer_or_null (node t); (* backward link *) blink: pointer_or_null (node t); (* payload *) p: t; } #reset-options private type nodelist t = list (pointer (node t)) unopteq (** Doubly linked list head *) type dll (t:Type0) ={ lhead: pointer_or_null (node t); ltail: pointer_or_null (node t); nodes: erased (nodelist t); } type nonempty_dll t = (h:dll t{h.lhead =!= null /\ h.ltail =!= null}) unopteq private (** An "almost valid" dll *) type piece t = { phead: pointer (node t); ptail: pointer (node t); pnodes: erased (nodelist t); } unopteq private (** An intermediate for when linked lists are being formed or destroyed *) type fragment t = | Frag0 : fragment t | Frag1 : piece t -> fragment t | Frag2 : piece t -> piece t -> fragment t | Frag3 : piece t -> piece t -> piece t -> fragment t /// Some useful empty initializers (** Initialize an element of a doubly linked list *) val empty_node: #t:Type -> payload:t -> node t let empty_node #t payload = { flink = null ; blink = null ; p = payload } (** Initialize a doubly linked list head *) val empty_list: #t:Type -> dll t let empty_list #t = { lhead = null ; ltail = null ; nodes = [] } /// Convenience wrappers for writing properties on fragments let fragment_for_each0 (#t:Type) (pr:piece t -> GTot Type0) (f:fragment t) : GTot Type0 = match f with | Frag0 -> True | Frag1 p1 -> pr p1 | Frag2 p1 p2 -> pr p1 /\ pr p2 | Frag3 p1 p2 p3 -> pr p1 /\ pr p2 /\ pr p3 let fragment_for_each1 (#t:Type) (#u:Type) (pr:u -> piece t -> GTot Type0) (v:u) (f:fragment t) : GTot Type0 = match f with | Frag0 -> True | Frag1 p1 -> pr v p1 | Frag2 p1 p2 -> pr v p1 /\ pr v p2 | Frag3 p1 p2 p3 -> pr v p1 /\ pr v p2 /\ pr v p3 let fragment_length (#t:Type) (f:fragment t) : GTot int = match f with | Frag0 -> 0 | Frag1 _ -> 1 | Frag2 _ _ -> 2 | Frag3 _ _ _ -> 3 /// Ghostly connections let dll_ghostly_connections (#t:Type) (d:dll t) : GTot Type0 = let nodes = d.nodes in match length nodes with | 0 -> d.lhead == null /\ d.ltail == null | _ -> d.lhead =!= null /\ d.ltail =!= null /\ d.lhead == hd nodes /\ d.ltail == last nodes let piece_ghostly_connections (#t:Type) (p:piece t) : GTot Type0 = let nodes = p.pnodes in match length nodes with | 0 -> False | _ -> p.phead == hd nodes /\ p.ptail == last nodes let rec fragment_ghostly_connections (#t:Type) (f:fragment t) : GTot Type0 = fragment_for_each0 piece_ghostly_connections f /// Containment properties /// /// WARNING: [@@] and [^@] require containment to reasonably talk about /// what they do. let rec nodelist_contained0 (#t:Type) (h0:heap) (nl:nodelist t) : GTot Type0 = match nl with | [] -> True | n :: ns -> h0 `contains` n /\ nodelist_contained0 h0 ns let rec nodelist_contained (#t:Type) (h0:heap) (nl:nodelist t) : GTot Type0 = nodelist_contained0 h0 nl let dll_contained (#t:Type) (h0:heap) (d:dll t) : GTot Type0 = h0 `contains` d.lhead /\ h0 `contains` d.ltail /\ nodelist_contained h0 d.nodes let piece_contained (#t:Type) (h0:heap) (p:piece t) : GTot Type0 = h0 `contains` p.phead /\ h0 `contains` p.ptail /\ nodelist_contained h0 p.pnodes let rec fragment_contained (#t:Type) (h0:heap) (f:fragment t) : GTot Type0 = fragment_for_each1 piece_contained h0 f /// Footprints
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowStar.ModifiesPat.fst.checked", "LowStar.Modifies.fst.checked", "LowStar.BufferOps.fst.checked", "LowStar.Buffer.fst.checked", "FStar.UInt32.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked", "FStar.List.Pure.Properties.fst.checked", "FStar.List.Pure.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked", "FStar.Classical.fsti.checked" ], "interface_file": false, "source_file": "DoublyLinkedList.fst" }
[ { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": true, "full_module": "LowStar.Modifies", "short_module": "Mod" }, { "abbrev": false, "full_module": "LowStar.BufferOps", "short_module": null }, { "abbrev": false, "full_module": "FStar.List.Pure", "short_module": null }, { "abbrev": false, "full_module": "FStar.List.Tot", "short_module": null }, { "abbrev": false, "full_module": "LowStar.ModifiesPat", "short_module": null }, { "abbrev": false, "full_module": "FStar.Ghost", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
n: DoublyLinkedList.node t -> Prims.GTot LowStar.Monotonic.Buffer.loc
Prims.GTot
[ "sometrivial" ]
[]
[ "DoublyLinkedList.node", "LowStar.Monotonic.Buffer.loc_buffer", "LowStar.Buffer.trivial_preorder", "DoublyLinkedList.__proj__Mknode__item__flink", "LowStar.Monotonic.Buffer.loc" ]
[]
false
false
false
false
false
let node_fp_f (#t: Type) (n: node t) : GTot Mod.loc =
Mod.loc_buffer n.flink
false
DoublyLinkedList.fst
DoublyLinkedList.fragment_contained
val fragment_contained (#t: Type) (h0: heap) (f: fragment t) : GTot Type0
val fragment_contained (#t: Type) (h0: heap) (f: fragment t) : GTot Type0
let rec fragment_contained (#t:Type) (h0:heap) (f:fragment t) : GTot Type0 = fragment_for_each1 piece_contained h0 f
{ "file_name": "examples/doublylinkedlist/DoublyLinkedList.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 41, "end_line": 180, "start_col": 0, "start_line": 179 }
(* Copyright 2008-2019 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module DoublyLinkedList open FStar open FStar.HyperStack.ST open FStar.Ghost open LowStar.ModifiesPat open FStar.List.Tot open FStar.List.Pure open LowStar.BufferOps module Mod = LowStar.Modifies module ST = FStar.HyperStack.ST module HS = FStar.HyperStack module B = LowStar.Buffer /// Convenience renaming unfold let heap = HS.mem unfold let contains #a #rrel #rel h b = B.live #a #rrel #rel h b /// Convenience patterns let lemma_non_null (#t:Type) (a:pointer_or_null t) : Lemma (requires (a =!= null)) (ensures (len a = 1ul)) [SMTPat (len a)] = null_unique a /// Convenience operators unfold let (.[]) (s:list 'a) (n:nat{n < length s}) = index s n unfold let (~.) (#t:Type) (a:t) : Tot (erased (list t)) = [a] unfold let (^+) (#t:Type) (a:t) (b:erased (list t)) : Tot (erased (list t)) = Cons a b unfold let (+^) (#t:Type) (a:erased (list t)) (b:t) : Tot (erased (list t)) = append a [b] unfold let (^@^) (#t:Type) (a:erased (list t)) (b:erased (list t)) : Tot (erased (list t)) = append a b unfold let (@) (a:pointer 't) (h0:heap) = B.get h0 a 0 unfold let (^@) (a:pointer_or_null 't{a =!= null}) (h0:heap) = B.get h0 a 0 /// All the data structures #set-options "--__no_positivity" unopteq (** Node of a doubly linked list *) type node (t:Type0) = { (* forward link *) flink: pointer_or_null (node t); (* backward link *) blink: pointer_or_null (node t); (* payload *) p: t; } #reset-options private type nodelist t = list (pointer (node t)) unopteq (** Doubly linked list head *) type dll (t:Type0) ={ lhead: pointer_or_null (node t); ltail: pointer_or_null (node t); nodes: erased (nodelist t); } type nonempty_dll t = (h:dll t{h.lhead =!= null /\ h.ltail =!= null}) unopteq private (** An "almost valid" dll *) type piece t = { phead: pointer (node t); ptail: pointer (node t); pnodes: erased (nodelist t); } unopteq private (** An intermediate for when linked lists are being formed or destroyed *) type fragment t = | Frag0 : fragment t | Frag1 : piece t -> fragment t | Frag2 : piece t -> piece t -> fragment t | Frag3 : piece t -> piece t -> piece t -> fragment t /// Some useful empty initializers (** Initialize an element of a doubly linked list *) val empty_node: #t:Type -> payload:t -> node t let empty_node #t payload = { flink = null ; blink = null ; p = payload } (** Initialize a doubly linked list head *) val empty_list: #t:Type -> dll t let empty_list #t = { lhead = null ; ltail = null ; nodes = [] } /// Convenience wrappers for writing properties on fragments let fragment_for_each0 (#t:Type) (pr:piece t -> GTot Type0) (f:fragment t) : GTot Type0 = match f with | Frag0 -> True | Frag1 p1 -> pr p1 | Frag2 p1 p2 -> pr p1 /\ pr p2 | Frag3 p1 p2 p3 -> pr p1 /\ pr p2 /\ pr p3 let fragment_for_each1 (#t:Type) (#u:Type) (pr:u -> piece t -> GTot Type0) (v:u) (f:fragment t) : GTot Type0 = match f with | Frag0 -> True | Frag1 p1 -> pr v p1 | Frag2 p1 p2 -> pr v p1 /\ pr v p2 | Frag3 p1 p2 p3 -> pr v p1 /\ pr v p2 /\ pr v p3 let fragment_length (#t:Type) (f:fragment t) : GTot int = match f with | Frag0 -> 0 | Frag1 _ -> 1 | Frag2 _ _ -> 2 | Frag3 _ _ _ -> 3 /// Ghostly connections let dll_ghostly_connections (#t:Type) (d:dll t) : GTot Type0 = let nodes = d.nodes in match length nodes with | 0 -> d.lhead == null /\ d.ltail == null | _ -> d.lhead =!= null /\ d.ltail =!= null /\ d.lhead == hd nodes /\ d.ltail == last nodes let piece_ghostly_connections (#t:Type) (p:piece t) : GTot Type0 = let nodes = p.pnodes in match length nodes with | 0 -> False | _ -> p.phead == hd nodes /\ p.ptail == last nodes let rec fragment_ghostly_connections (#t:Type) (f:fragment t) : GTot Type0 = fragment_for_each0 piece_ghostly_connections f /// Containment properties /// /// WARNING: [@@] and [^@] require containment to reasonably talk about /// what they do. let rec nodelist_contained0 (#t:Type) (h0:heap) (nl:nodelist t) : GTot Type0 = match nl with | [] -> True | n :: ns -> h0 `contains` n /\ nodelist_contained0 h0 ns let rec nodelist_contained (#t:Type) (h0:heap) (nl:nodelist t) : GTot Type0 = nodelist_contained0 h0 nl let dll_contained (#t:Type) (h0:heap) (d:dll t) : GTot Type0 = h0 `contains` d.lhead /\ h0 `contains` d.ltail /\ nodelist_contained h0 d.nodes let piece_contained (#t:Type) (h0:heap) (p:piece t) : GTot Type0 = h0 `contains` p.phead /\ h0 `contains` p.ptail /\ nodelist_contained h0 p.pnodes
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowStar.ModifiesPat.fst.checked", "LowStar.Modifies.fst.checked", "LowStar.BufferOps.fst.checked", "LowStar.Buffer.fst.checked", "FStar.UInt32.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked", "FStar.List.Pure.Properties.fst.checked", "FStar.List.Pure.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked", "FStar.Classical.fsti.checked" ], "interface_file": false, "source_file": "DoublyLinkedList.fst" }
[ { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": true, "full_module": "LowStar.Modifies", "short_module": "Mod" }, { "abbrev": false, "full_module": "LowStar.BufferOps", "short_module": null }, { "abbrev": false, "full_module": "FStar.List.Pure", "short_module": null }, { "abbrev": false, "full_module": "FStar.List.Tot", "short_module": null }, { "abbrev": false, "full_module": "LowStar.ModifiesPat", "short_module": null }, { "abbrev": false, "full_module": "FStar.Ghost", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
h0: DoublyLinkedList.heap -> f: DoublyLinkedList.fragment t -> Prims.GTot Type0
Prims.GTot
[ "sometrivial" ]
[]
[ "DoublyLinkedList.heap", "DoublyLinkedList.fragment", "DoublyLinkedList.fragment_for_each1", "DoublyLinkedList.piece_contained" ]
[ "recursion" ]
false
false
false
false
true
let rec fragment_contained (#t: Type) (h0: heap) (f: fragment t) : GTot Type0 =
fragment_for_each1 piece_contained h0 f
false
DoublyLinkedList.fst
DoublyLinkedList.piece_fp_f
val piece_fp_f (#t: Type) (h0: heap) (p: piece t) : GTot Mod.loc
val piece_fp_f (#t: Type) (h0: heap) (p: piece t) : GTot Mod.loc
let piece_fp_f (#t:Type) (h0:heap) (p:piece t) : GTot Mod.loc = Mod.loc_union // ghostly connections should give us this union for // free, but still useful to have (Mod.loc_union (Mod.loc_buffer (p.phead@h0).flink) (Mod.loc_buffer (p.ptail@h0).flink)) (nodelist_fp_f h0 p.pnodes)
{ "file_name": "examples/doublylinkedlist/DoublyLinkedList.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 31, "end_line": 231, "start_col": 0, "start_line": 227 }
(* Copyright 2008-2019 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module DoublyLinkedList open FStar open FStar.HyperStack.ST open FStar.Ghost open LowStar.ModifiesPat open FStar.List.Tot open FStar.List.Pure open LowStar.BufferOps module Mod = LowStar.Modifies module ST = FStar.HyperStack.ST module HS = FStar.HyperStack module B = LowStar.Buffer /// Convenience renaming unfold let heap = HS.mem unfold let contains #a #rrel #rel h b = B.live #a #rrel #rel h b /// Convenience patterns let lemma_non_null (#t:Type) (a:pointer_or_null t) : Lemma (requires (a =!= null)) (ensures (len a = 1ul)) [SMTPat (len a)] = null_unique a /// Convenience operators unfold let (.[]) (s:list 'a) (n:nat{n < length s}) = index s n unfold let (~.) (#t:Type) (a:t) : Tot (erased (list t)) = [a] unfold let (^+) (#t:Type) (a:t) (b:erased (list t)) : Tot (erased (list t)) = Cons a b unfold let (+^) (#t:Type) (a:erased (list t)) (b:t) : Tot (erased (list t)) = append a [b] unfold let (^@^) (#t:Type) (a:erased (list t)) (b:erased (list t)) : Tot (erased (list t)) = append a b unfold let (@) (a:pointer 't) (h0:heap) = B.get h0 a 0 unfold let (^@) (a:pointer_or_null 't{a =!= null}) (h0:heap) = B.get h0 a 0 /// All the data structures #set-options "--__no_positivity" unopteq (** Node of a doubly linked list *) type node (t:Type0) = { (* forward link *) flink: pointer_or_null (node t); (* backward link *) blink: pointer_or_null (node t); (* payload *) p: t; } #reset-options private type nodelist t = list (pointer (node t)) unopteq (** Doubly linked list head *) type dll (t:Type0) ={ lhead: pointer_or_null (node t); ltail: pointer_or_null (node t); nodes: erased (nodelist t); } type nonempty_dll t = (h:dll t{h.lhead =!= null /\ h.ltail =!= null}) unopteq private (** An "almost valid" dll *) type piece t = { phead: pointer (node t); ptail: pointer (node t); pnodes: erased (nodelist t); } unopteq private (** An intermediate for when linked lists are being formed or destroyed *) type fragment t = | Frag0 : fragment t | Frag1 : piece t -> fragment t | Frag2 : piece t -> piece t -> fragment t | Frag3 : piece t -> piece t -> piece t -> fragment t /// Some useful empty initializers (** Initialize an element of a doubly linked list *) val empty_node: #t:Type -> payload:t -> node t let empty_node #t payload = { flink = null ; blink = null ; p = payload } (** Initialize a doubly linked list head *) val empty_list: #t:Type -> dll t let empty_list #t = { lhead = null ; ltail = null ; nodes = [] } /// Convenience wrappers for writing properties on fragments let fragment_for_each0 (#t:Type) (pr:piece t -> GTot Type0) (f:fragment t) : GTot Type0 = match f with | Frag0 -> True | Frag1 p1 -> pr p1 | Frag2 p1 p2 -> pr p1 /\ pr p2 | Frag3 p1 p2 p3 -> pr p1 /\ pr p2 /\ pr p3 let fragment_for_each1 (#t:Type) (#u:Type) (pr:u -> piece t -> GTot Type0) (v:u) (f:fragment t) : GTot Type0 = match f with | Frag0 -> True | Frag1 p1 -> pr v p1 | Frag2 p1 p2 -> pr v p1 /\ pr v p2 | Frag3 p1 p2 p3 -> pr v p1 /\ pr v p2 /\ pr v p3 let fragment_length (#t:Type) (f:fragment t) : GTot int = match f with | Frag0 -> 0 | Frag1 _ -> 1 | Frag2 _ _ -> 2 | Frag3 _ _ _ -> 3 /// Ghostly connections let dll_ghostly_connections (#t:Type) (d:dll t) : GTot Type0 = let nodes = d.nodes in match length nodes with | 0 -> d.lhead == null /\ d.ltail == null | _ -> d.lhead =!= null /\ d.ltail =!= null /\ d.lhead == hd nodes /\ d.ltail == last nodes let piece_ghostly_connections (#t:Type) (p:piece t) : GTot Type0 = let nodes = p.pnodes in match length nodes with | 0 -> False | _ -> p.phead == hd nodes /\ p.ptail == last nodes let rec fragment_ghostly_connections (#t:Type) (f:fragment t) : GTot Type0 = fragment_for_each0 piece_ghostly_connections f /// Containment properties /// /// WARNING: [@@] and [^@] require containment to reasonably talk about /// what they do. let rec nodelist_contained0 (#t:Type) (h0:heap) (nl:nodelist t) : GTot Type0 = match nl with | [] -> True | n :: ns -> h0 `contains` n /\ nodelist_contained0 h0 ns let rec nodelist_contained (#t:Type) (h0:heap) (nl:nodelist t) : GTot Type0 = nodelist_contained0 h0 nl let dll_contained (#t:Type) (h0:heap) (d:dll t) : GTot Type0 = h0 `contains` d.lhead /\ h0 `contains` d.ltail /\ nodelist_contained h0 d.nodes let piece_contained (#t:Type) (h0:heap) (p:piece t) : GTot Type0 = h0 `contains` p.phead /\ h0 `contains` p.ptail /\ nodelist_contained h0 p.pnodes let rec fragment_contained (#t:Type) (h0:heap) (f:fragment t) : GTot Type0 = fragment_for_each1 piece_contained h0 f /// Footprints let node_fp_f (#t:Type) (n:node t) : GTot Mod.loc = Mod.loc_buffer n.flink let node_fp_b (#t:Type) (n:node t) : GTot Mod.loc = Mod.loc_buffer n.blink let rec nodelist_fp0 (#t:Type) (n:nodelist t) : GTot Mod.loc = match n with | [] -> Mod.loc_none | n :: ns -> Mod.loc_union (Mod.loc_buffer n) (nodelist_fp0 ns) let rec nodelist_fp_f (#t:Type) (h0:heap) (n:nodelist t) : GTot Mod.loc = match n with | [] -> Mod.loc_none | n :: ns -> Mod.loc_union (Mod.loc_buffer (n@h0).flink) (nodelist_fp_f h0 ns) let rec nodelist_fp_b (#t:Type) (h0:heap) (n:nodelist t) : GTot Mod.loc = match n with | [] -> Mod.loc_none | n :: ns -> Mod.loc_union (Mod.loc_buffer (n@h0).blink) (nodelist_fp_b h0 ns) let dll_fp0 (#t:Type) (d:dll t) : GTot Mod.loc = Mod.loc_union // ghostly connections should give us this union for // free, but still useful to have (Mod.loc_union (Mod.loc_buffer d.lhead) (Mod.loc_buffer d.ltail)) (nodelist_fp0 d.nodes) let dll_fp_f (#t:Type) (h0:heap) (d:dll t) : GTot Mod.loc = let a = if g_is_null d.lhead then Mod.loc_none else Mod.loc_buffer (d.lhead^@h0).flink in let b = if g_is_null d.ltail then Mod.loc_none else Mod.loc_buffer (d.ltail^@h0).flink in Mod.loc_union // ghostly connections should give us this union for // free, but still useful to have (Mod.loc_union a b) (nodelist_fp_f h0 d.nodes) let dll_fp_b (#t:Type) (h0:heap) (d:dll t) : GTot Mod.loc = let a = if g_is_null d.lhead then Mod.loc_none else Mod.loc_buffer (d.lhead^@h0).blink in let b = if g_is_null d.ltail then Mod.loc_none else Mod.loc_buffer (d.ltail^@h0).blink in Mod.loc_union // ghostly connections should give us this union for // free, but still useful to have (Mod.loc_union a b) (nodelist_fp_b h0 d.nodes) let piece_fp0 (#t:Type) (p:piece t) : GTot Mod.loc = Mod.loc_union // ghostly connections should give us this union for // free, but still useful to have (Mod.loc_union (Mod.loc_buffer p.phead) (Mod.loc_buffer p.ptail))
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowStar.ModifiesPat.fst.checked", "LowStar.Modifies.fst.checked", "LowStar.BufferOps.fst.checked", "LowStar.Buffer.fst.checked", "FStar.UInt32.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked", "FStar.List.Pure.Properties.fst.checked", "FStar.List.Pure.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked", "FStar.Classical.fsti.checked" ], "interface_file": false, "source_file": "DoublyLinkedList.fst" }
[ { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": true, "full_module": "LowStar.Modifies", "short_module": "Mod" }, { "abbrev": false, "full_module": "LowStar.BufferOps", "short_module": null }, { "abbrev": false, "full_module": "FStar.List.Pure", "short_module": null }, { "abbrev": false, "full_module": "FStar.List.Tot", "short_module": null }, { "abbrev": false, "full_module": "LowStar.ModifiesPat", "short_module": null }, { "abbrev": false, "full_module": "FStar.Ghost", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
h0: DoublyLinkedList.heap -> p: DoublyLinkedList.piece t -> Prims.GTot LowStar.Monotonic.Buffer.loc
Prims.GTot
[ "sometrivial" ]
[]
[ "DoublyLinkedList.heap", "DoublyLinkedList.piece", "LowStar.Monotonic.Buffer.loc_union", "LowStar.Monotonic.Buffer.loc_buffer", "DoublyLinkedList.node", "LowStar.Buffer.trivial_preorder", "DoublyLinkedList.__proj__Mknode__item__flink", "DoublyLinkedList.op_At", "DoublyLinkedList.__proj__Mkpiece__item__phead", "DoublyLinkedList.__proj__Mkpiece__item__ptail", "DoublyLinkedList.nodelist_fp_f", "FStar.Ghost.reveal", "DoublyLinkedList.nodelist", "DoublyLinkedList.__proj__Mkpiece__item__pnodes", "LowStar.Monotonic.Buffer.loc" ]
[]
false
false
false
false
false
let piece_fp_f (#t: Type) (h0: heap) (p: piece t) : GTot Mod.loc =
Mod.loc_union (Mod.loc_union (Mod.loc_buffer (p.phead @ h0).flink) (Mod.loc_buffer (p.ptail @ h0).flink)) (nodelist_fp_f h0 p.pnodes)
false
DoublyLinkedList.fst
DoublyLinkedList.nodelist_contained
val nodelist_contained (#t: Type) (h0: heap) (nl: nodelist t) : GTot Type0
val nodelist_contained (#t: Type) (h0: heap) (nl: nodelist t) : GTot Type0
let rec nodelist_contained (#t:Type) (h0:heap) (nl:nodelist t) : GTot Type0 = nodelist_contained0 h0 nl
{ "file_name": "examples/doublylinkedlist/DoublyLinkedList.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 27, "end_line": 167, "start_col": 0, "start_line": 166 }
(* Copyright 2008-2019 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module DoublyLinkedList open FStar open FStar.HyperStack.ST open FStar.Ghost open LowStar.ModifiesPat open FStar.List.Tot open FStar.List.Pure open LowStar.BufferOps module Mod = LowStar.Modifies module ST = FStar.HyperStack.ST module HS = FStar.HyperStack module B = LowStar.Buffer /// Convenience renaming unfold let heap = HS.mem unfold let contains #a #rrel #rel h b = B.live #a #rrel #rel h b /// Convenience patterns let lemma_non_null (#t:Type) (a:pointer_or_null t) : Lemma (requires (a =!= null)) (ensures (len a = 1ul)) [SMTPat (len a)] = null_unique a /// Convenience operators unfold let (.[]) (s:list 'a) (n:nat{n < length s}) = index s n unfold let (~.) (#t:Type) (a:t) : Tot (erased (list t)) = [a] unfold let (^+) (#t:Type) (a:t) (b:erased (list t)) : Tot (erased (list t)) = Cons a b unfold let (+^) (#t:Type) (a:erased (list t)) (b:t) : Tot (erased (list t)) = append a [b] unfold let (^@^) (#t:Type) (a:erased (list t)) (b:erased (list t)) : Tot (erased (list t)) = append a b unfold let (@) (a:pointer 't) (h0:heap) = B.get h0 a 0 unfold let (^@) (a:pointer_or_null 't{a =!= null}) (h0:heap) = B.get h0 a 0 /// All the data structures #set-options "--__no_positivity" unopteq (** Node of a doubly linked list *) type node (t:Type0) = { (* forward link *) flink: pointer_or_null (node t); (* backward link *) blink: pointer_or_null (node t); (* payload *) p: t; } #reset-options private type nodelist t = list (pointer (node t)) unopteq (** Doubly linked list head *) type dll (t:Type0) ={ lhead: pointer_or_null (node t); ltail: pointer_or_null (node t); nodes: erased (nodelist t); } type nonempty_dll t = (h:dll t{h.lhead =!= null /\ h.ltail =!= null}) unopteq private (** An "almost valid" dll *) type piece t = { phead: pointer (node t); ptail: pointer (node t); pnodes: erased (nodelist t); } unopteq private (** An intermediate for when linked lists are being formed or destroyed *) type fragment t = | Frag0 : fragment t | Frag1 : piece t -> fragment t | Frag2 : piece t -> piece t -> fragment t | Frag3 : piece t -> piece t -> piece t -> fragment t /// Some useful empty initializers (** Initialize an element of a doubly linked list *) val empty_node: #t:Type -> payload:t -> node t let empty_node #t payload = { flink = null ; blink = null ; p = payload } (** Initialize a doubly linked list head *) val empty_list: #t:Type -> dll t let empty_list #t = { lhead = null ; ltail = null ; nodes = [] } /// Convenience wrappers for writing properties on fragments let fragment_for_each0 (#t:Type) (pr:piece t -> GTot Type0) (f:fragment t) : GTot Type0 = match f with | Frag0 -> True | Frag1 p1 -> pr p1 | Frag2 p1 p2 -> pr p1 /\ pr p2 | Frag3 p1 p2 p3 -> pr p1 /\ pr p2 /\ pr p3 let fragment_for_each1 (#t:Type) (#u:Type) (pr:u -> piece t -> GTot Type0) (v:u) (f:fragment t) : GTot Type0 = match f with | Frag0 -> True | Frag1 p1 -> pr v p1 | Frag2 p1 p2 -> pr v p1 /\ pr v p2 | Frag3 p1 p2 p3 -> pr v p1 /\ pr v p2 /\ pr v p3 let fragment_length (#t:Type) (f:fragment t) : GTot int = match f with | Frag0 -> 0 | Frag1 _ -> 1 | Frag2 _ _ -> 2 | Frag3 _ _ _ -> 3 /// Ghostly connections let dll_ghostly_connections (#t:Type) (d:dll t) : GTot Type0 = let nodes = d.nodes in match length nodes with | 0 -> d.lhead == null /\ d.ltail == null | _ -> d.lhead =!= null /\ d.ltail =!= null /\ d.lhead == hd nodes /\ d.ltail == last nodes let piece_ghostly_connections (#t:Type) (p:piece t) : GTot Type0 = let nodes = p.pnodes in match length nodes with | 0 -> False | _ -> p.phead == hd nodes /\ p.ptail == last nodes let rec fragment_ghostly_connections (#t:Type) (f:fragment t) : GTot Type0 = fragment_for_each0 piece_ghostly_connections f /// Containment properties /// /// WARNING: [@@] and [^@] require containment to reasonably talk about /// what they do. let rec nodelist_contained0 (#t:Type) (h0:heap) (nl:nodelist t) : GTot Type0 = match nl with | [] -> True
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowStar.ModifiesPat.fst.checked", "LowStar.Modifies.fst.checked", "LowStar.BufferOps.fst.checked", "LowStar.Buffer.fst.checked", "FStar.UInt32.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked", "FStar.List.Pure.Properties.fst.checked", "FStar.List.Pure.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked", "FStar.Classical.fsti.checked" ], "interface_file": false, "source_file": "DoublyLinkedList.fst" }
[ { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": true, "full_module": "LowStar.Modifies", "short_module": "Mod" }, { "abbrev": false, "full_module": "LowStar.BufferOps", "short_module": null }, { "abbrev": false, "full_module": "FStar.List.Pure", "short_module": null }, { "abbrev": false, "full_module": "FStar.List.Tot", "short_module": null }, { "abbrev": false, "full_module": "LowStar.ModifiesPat", "short_module": null }, { "abbrev": false, "full_module": "FStar.Ghost", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
h0: DoublyLinkedList.heap -> nl: DoublyLinkedList.nodelist t -> Prims.GTot Type0
Prims.GTot
[ "sometrivial" ]
[]
[ "DoublyLinkedList.heap", "DoublyLinkedList.nodelist", "DoublyLinkedList.nodelist_contained0" ]
[ "recursion" ]
false
false
false
false
true
let rec nodelist_contained (#t: Type) (h0: heap) (nl: nodelist t) : GTot Type0 =
nodelist_contained0 h0 nl
false
DoublyLinkedList.fst
DoublyLinkedList.dll_fp0
val dll_fp0 (#t: Type) (d: dll t) : GTot Mod.loc
val dll_fp0 (#t: Type) (d: dll t) : GTot Mod.loc
let dll_fp0 (#t:Type) (d:dll t) : GTot Mod.loc = Mod.loc_union // ghostly connections should give us this union for // free, but still useful to have (Mod.loc_union (Mod.loc_buffer d.lhead) (Mod.loc_buffer d.ltail)) (nodelist_fp0 d.nodes)
{ "file_name": "examples/doublylinkedlist/DoublyLinkedList.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 26, "end_line": 206, "start_col": 0, "start_line": 202 }
(* Copyright 2008-2019 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module DoublyLinkedList open FStar open FStar.HyperStack.ST open FStar.Ghost open LowStar.ModifiesPat open FStar.List.Tot open FStar.List.Pure open LowStar.BufferOps module Mod = LowStar.Modifies module ST = FStar.HyperStack.ST module HS = FStar.HyperStack module B = LowStar.Buffer /// Convenience renaming unfold let heap = HS.mem unfold let contains #a #rrel #rel h b = B.live #a #rrel #rel h b /// Convenience patterns let lemma_non_null (#t:Type) (a:pointer_or_null t) : Lemma (requires (a =!= null)) (ensures (len a = 1ul)) [SMTPat (len a)] = null_unique a /// Convenience operators unfold let (.[]) (s:list 'a) (n:nat{n < length s}) = index s n unfold let (~.) (#t:Type) (a:t) : Tot (erased (list t)) = [a] unfold let (^+) (#t:Type) (a:t) (b:erased (list t)) : Tot (erased (list t)) = Cons a b unfold let (+^) (#t:Type) (a:erased (list t)) (b:t) : Tot (erased (list t)) = append a [b] unfold let (^@^) (#t:Type) (a:erased (list t)) (b:erased (list t)) : Tot (erased (list t)) = append a b unfold let (@) (a:pointer 't) (h0:heap) = B.get h0 a 0 unfold let (^@) (a:pointer_or_null 't{a =!= null}) (h0:heap) = B.get h0 a 0 /// All the data structures #set-options "--__no_positivity" unopteq (** Node of a doubly linked list *) type node (t:Type0) = { (* forward link *) flink: pointer_or_null (node t); (* backward link *) blink: pointer_or_null (node t); (* payload *) p: t; } #reset-options private type nodelist t = list (pointer (node t)) unopteq (** Doubly linked list head *) type dll (t:Type0) ={ lhead: pointer_or_null (node t); ltail: pointer_or_null (node t); nodes: erased (nodelist t); } type nonempty_dll t = (h:dll t{h.lhead =!= null /\ h.ltail =!= null}) unopteq private (** An "almost valid" dll *) type piece t = { phead: pointer (node t); ptail: pointer (node t); pnodes: erased (nodelist t); } unopteq private (** An intermediate for when linked lists are being formed or destroyed *) type fragment t = | Frag0 : fragment t | Frag1 : piece t -> fragment t | Frag2 : piece t -> piece t -> fragment t | Frag3 : piece t -> piece t -> piece t -> fragment t /// Some useful empty initializers (** Initialize an element of a doubly linked list *) val empty_node: #t:Type -> payload:t -> node t let empty_node #t payload = { flink = null ; blink = null ; p = payload } (** Initialize a doubly linked list head *) val empty_list: #t:Type -> dll t let empty_list #t = { lhead = null ; ltail = null ; nodes = [] } /// Convenience wrappers for writing properties on fragments let fragment_for_each0 (#t:Type) (pr:piece t -> GTot Type0) (f:fragment t) : GTot Type0 = match f with | Frag0 -> True | Frag1 p1 -> pr p1 | Frag2 p1 p2 -> pr p1 /\ pr p2 | Frag3 p1 p2 p3 -> pr p1 /\ pr p2 /\ pr p3 let fragment_for_each1 (#t:Type) (#u:Type) (pr:u -> piece t -> GTot Type0) (v:u) (f:fragment t) : GTot Type0 = match f with | Frag0 -> True | Frag1 p1 -> pr v p1 | Frag2 p1 p2 -> pr v p1 /\ pr v p2 | Frag3 p1 p2 p3 -> pr v p1 /\ pr v p2 /\ pr v p3 let fragment_length (#t:Type) (f:fragment t) : GTot int = match f with | Frag0 -> 0 | Frag1 _ -> 1 | Frag2 _ _ -> 2 | Frag3 _ _ _ -> 3 /// Ghostly connections let dll_ghostly_connections (#t:Type) (d:dll t) : GTot Type0 = let nodes = d.nodes in match length nodes with | 0 -> d.lhead == null /\ d.ltail == null | _ -> d.lhead =!= null /\ d.ltail =!= null /\ d.lhead == hd nodes /\ d.ltail == last nodes let piece_ghostly_connections (#t:Type) (p:piece t) : GTot Type0 = let nodes = p.pnodes in match length nodes with | 0 -> False | _ -> p.phead == hd nodes /\ p.ptail == last nodes let rec fragment_ghostly_connections (#t:Type) (f:fragment t) : GTot Type0 = fragment_for_each0 piece_ghostly_connections f /// Containment properties /// /// WARNING: [@@] and [^@] require containment to reasonably talk about /// what they do. let rec nodelist_contained0 (#t:Type) (h0:heap) (nl:nodelist t) : GTot Type0 = match nl with | [] -> True | n :: ns -> h0 `contains` n /\ nodelist_contained0 h0 ns let rec nodelist_contained (#t:Type) (h0:heap) (nl:nodelist t) : GTot Type0 = nodelist_contained0 h0 nl let dll_contained (#t:Type) (h0:heap) (d:dll t) : GTot Type0 = h0 `contains` d.lhead /\ h0 `contains` d.ltail /\ nodelist_contained h0 d.nodes let piece_contained (#t:Type) (h0:heap) (p:piece t) : GTot Type0 = h0 `contains` p.phead /\ h0 `contains` p.ptail /\ nodelist_contained h0 p.pnodes let rec fragment_contained (#t:Type) (h0:heap) (f:fragment t) : GTot Type0 = fragment_for_each1 piece_contained h0 f /// Footprints let node_fp_f (#t:Type) (n:node t) : GTot Mod.loc = Mod.loc_buffer n.flink let node_fp_b (#t:Type) (n:node t) : GTot Mod.loc = Mod.loc_buffer n.blink let rec nodelist_fp0 (#t:Type) (n:nodelist t) : GTot Mod.loc = match n with | [] -> Mod.loc_none | n :: ns -> Mod.loc_union (Mod.loc_buffer n) (nodelist_fp0 ns) let rec nodelist_fp_f (#t:Type) (h0:heap) (n:nodelist t) : GTot Mod.loc = match n with | [] -> Mod.loc_none | n :: ns -> Mod.loc_union (Mod.loc_buffer (n@h0).flink) (nodelist_fp_f h0 ns) let rec nodelist_fp_b (#t:Type) (h0:heap) (n:nodelist t) : GTot Mod.loc = match n with | [] -> Mod.loc_none | n :: ns -> Mod.loc_union (Mod.loc_buffer (n@h0).blink) (nodelist_fp_b h0 ns)
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowStar.ModifiesPat.fst.checked", "LowStar.Modifies.fst.checked", "LowStar.BufferOps.fst.checked", "LowStar.Buffer.fst.checked", "FStar.UInt32.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked", "FStar.List.Pure.Properties.fst.checked", "FStar.List.Pure.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked", "FStar.Classical.fsti.checked" ], "interface_file": false, "source_file": "DoublyLinkedList.fst" }
[ { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": true, "full_module": "LowStar.Modifies", "short_module": "Mod" }, { "abbrev": false, "full_module": "LowStar.BufferOps", "short_module": null }, { "abbrev": false, "full_module": "FStar.List.Pure", "short_module": null }, { "abbrev": false, "full_module": "FStar.List.Tot", "short_module": null }, { "abbrev": false, "full_module": "LowStar.ModifiesPat", "short_module": null }, { "abbrev": false, "full_module": "FStar.Ghost", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
d: DoublyLinkedList.dll t -> Prims.GTot LowStar.Monotonic.Buffer.loc
Prims.GTot
[ "sometrivial" ]
[]
[ "DoublyLinkedList.dll", "LowStar.Monotonic.Buffer.loc_union", "LowStar.Monotonic.Buffer.loc_buffer", "DoublyLinkedList.node", "LowStar.Buffer.trivial_preorder", "DoublyLinkedList.__proj__Mkdll__item__lhead", "DoublyLinkedList.__proj__Mkdll__item__ltail", "DoublyLinkedList.nodelist_fp0", "FStar.Ghost.reveal", "DoublyLinkedList.nodelist", "DoublyLinkedList.__proj__Mkdll__item__nodes", "LowStar.Monotonic.Buffer.loc" ]
[]
false
false
false
false
false
let dll_fp0 (#t: Type) (d: dll t) : GTot Mod.loc =
Mod.loc_union (Mod.loc_union (Mod.loc_buffer d.lhead) (Mod.loc_buffer d.ltail)) (nodelist_fp0 d.nodes)
false
DoublyLinkedList.fst
DoublyLinkedList.node_fp_b
val node_fp_b (#t: Type) (n: node t) : GTot Mod.loc
val node_fp_b (#t: Type) (n: node t) : GTot Mod.loc
let node_fp_b (#t:Type) (n:node t) : GTot Mod.loc = Mod.loc_buffer n.blink
{ "file_name": "examples/doublylinkedlist/DoublyLinkedList.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 24, "end_line": 187, "start_col": 0, "start_line": 186 }
(* Copyright 2008-2019 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module DoublyLinkedList open FStar open FStar.HyperStack.ST open FStar.Ghost open LowStar.ModifiesPat open FStar.List.Tot open FStar.List.Pure open LowStar.BufferOps module Mod = LowStar.Modifies module ST = FStar.HyperStack.ST module HS = FStar.HyperStack module B = LowStar.Buffer /// Convenience renaming unfold let heap = HS.mem unfold let contains #a #rrel #rel h b = B.live #a #rrel #rel h b /// Convenience patterns let lemma_non_null (#t:Type) (a:pointer_or_null t) : Lemma (requires (a =!= null)) (ensures (len a = 1ul)) [SMTPat (len a)] = null_unique a /// Convenience operators unfold let (.[]) (s:list 'a) (n:nat{n < length s}) = index s n unfold let (~.) (#t:Type) (a:t) : Tot (erased (list t)) = [a] unfold let (^+) (#t:Type) (a:t) (b:erased (list t)) : Tot (erased (list t)) = Cons a b unfold let (+^) (#t:Type) (a:erased (list t)) (b:t) : Tot (erased (list t)) = append a [b] unfold let (^@^) (#t:Type) (a:erased (list t)) (b:erased (list t)) : Tot (erased (list t)) = append a b unfold let (@) (a:pointer 't) (h0:heap) = B.get h0 a 0 unfold let (^@) (a:pointer_or_null 't{a =!= null}) (h0:heap) = B.get h0 a 0 /// All the data structures #set-options "--__no_positivity" unopteq (** Node of a doubly linked list *) type node (t:Type0) = { (* forward link *) flink: pointer_or_null (node t); (* backward link *) blink: pointer_or_null (node t); (* payload *) p: t; } #reset-options private type nodelist t = list (pointer (node t)) unopteq (** Doubly linked list head *) type dll (t:Type0) ={ lhead: pointer_or_null (node t); ltail: pointer_or_null (node t); nodes: erased (nodelist t); } type nonempty_dll t = (h:dll t{h.lhead =!= null /\ h.ltail =!= null}) unopteq private (** An "almost valid" dll *) type piece t = { phead: pointer (node t); ptail: pointer (node t); pnodes: erased (nodelist t); } unopteq private (** An intermediate for when linked lists are being formed or destroyed *) type fragment t = | Frag0 : fragment t | Frag1 : piece t -> fragment t | Frag2 : piece t -> piece t -> fragment t | Frag3 : piece t -> piece t -> piece t -> fragment t /// Some useful empty initializers (** Initialize an element of a doubly linked list *) val empty_node: #t:Type -> payload:t -> node t let empty_node #t payload = { flink = null ; blink = null ; p = payload } (** Initialize a doubly linked list head *) val empty_list: #t:Type -> dll t let empty_list #t = { lhead = null ; ltail = null ; nodes = [] } /// Convenience wrappers for writing properties on fragments let fragment_for_each0 (#t:Type) (pr:piece t -> GTot Type0) (f:fragment t) : GTot Type0 = match f with | Frag0 -> True | Frag1 p1 -> pr p1 | Frag2 p1 p2 -> pr p1 /\ pr p2 | Frag3 p1 p2 p3 -> pr p1 /\ pr p2 /\ pr p3 let fragment_for_each1 (#t:Type) (#u:Type) (pr:u -> piece t -> GTot Type0) (v:u) (f:fragment t) : GTot Type0 = match f with | Frag0 -> True | Frag1 p1 -> pr v p1 | Frag2 p1 p2 -> pr v p1 /\ pr v p2 | Frag3 p1 p2 p3 -> pr v p1 /\ pr v p2 /\ pr v p3 let fragment_length (#t:Type) (f:fragment t) : GTot int = match f with | Frag0 -> 0 | Frag1 _ -> 1 | Frag2 _ _ -> 2 | Frag3 _ _ _ -> 3 /// Ghostly connections let dll_ghostly_connections (#t:Type) (d:dll t) : GTot Type0 = let nodes = d.nodes in match length nodes with | 0 -> d.lhead == null /\ d.ltail == null | _ -> d.lhead =!= null /\ d.ltail =!= null /\ d.lhead == hd nodes /\ d.ltail == last nodes let piece_ghostly_connections (#t:Type) (p:piece t) : GTot Type0 = let nodes = p.pnodes in match length nodes with | 0 -> False | _ -> p.phead == hd nodes /\ p.ptail == last nodes let rec fragment_ghostly_connections (#t:Type) (f:fragment t) : GTot Type0 = fragment_for_each0 piece_ghostly_connections f /// Containment properties /// /// WARNING: [@@] and [^@] require containment to reasonably talk about /// what they do. let rec nodelist_contained0 (#t:Type) (h0:heap) (nl:nodelist t) : GTot Type0 = match nl with | [] -> True | n :: ns -> h0 `contains` n /\ nodelist_contained0 h0 ns let rec nodelist_contained (#t:Type) (h0:heap) (nl:nodelist t) : GTot Type0 = nodelist_contained0 h0 nl let dll_contained (#t:Type) (h0:heap) (d:dll t) : GTot Type0 = h0 `contains` d.lhead /\ h0 `contains` d.ltail /\ nodelist_contained h0 d.nodes let piece_contained (#t:Type) (h0:heap) (p:piece t) : GTot Type0 = h0 `contains` p.phead /\ h0 `contains` p.ptail /\ nodelist_contained h0 p.pnodes let rec fragment_contained (#t:Type) (h0:heap) (f:fragment t) : GTot Type0 = fragment_for_each1 piece_contained h0 f /// Footprints let node_fp_f (#t:Type) (n:node t) : GTot Mod.loc =
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowStar.ModifiesPat.fst.checked", "LowStar.Modifies.fst.checked", "LowStar.BufferOps.fst.checked", "LowStar.Buffer.fst.checked", "FStar.UInt32.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked", "FStar.List.Pure.Properties.fst.checked", "FStar.List.Pure.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked", "FStar.Classical.fsti.checked" ], "interface_file": false, "source_file": "DoublyLinkedList.fst" }
[ { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": true, "full_module": "LowStar.Modifies", "short_module": "Mod" }, { "abbrev": false, "full_module": "LowStar.BufferOps", "short_module": null }, { "abbrev": false, "full_module": "FStar.List.Pure", "short_module": null }, { "abbrev": false, "full_module": "FStar.List.Tot", "short_module": null }, { "abbrev": false, "full_module": "LowStar.ModifiesPat", "short_module": null }, { "abbrev": false, "full_module": "FStar.Ghost", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
n: DoublyLinkedList.node t -> Prims.GTot LowStar.Monotonic.Buffer.loc
Prims.GTot
[ "sometrivial" ]
[]
[ "DoublyLinkedList.node", "LowStar.Monotonic.Buffer.loc_buffer", "LowStar.Buffer.trivial_preorder", "DoublyLinkedList.__proj__Mknode__item__blink", "LowStar.Monotonic.Buffer.loc" ]
[]
false
false
false
false
false
let node_fp_b (#t: Type) (n: node t) : GTot Mod.loc =
Mod.loc_buffer n.blink
false
DoublyLinkedList.fst
DoublyLinkedList.piece_fp0
val piece_fp0 (#t: Type) (p: piece t) : GTot Mod.loc
val piece_fp0 (#t: Type) (p: piece t) : GTot Mod.loc
let piece_fp0 (#t:Type) (p:piece t) : GTot Mod.loc = Mod.loc_union // ghostly connections should give us this union for // free, but still useful to have (Mod.loc_union (Mod.loc_buffer p.phead) (Mod.loc_buffer p.ptail)) (nodelist_fp0 p.pnodes)
{ "file_name": "examples/doublylinkedlist/DoublyLinkedList.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 27, "end_line": 226, "start_col": 0, "start_line": 222 }
(* Copyright 2008-2019 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module DoublyLinkedList open FStar open FStar.HyperStack.ST open FStar.Ghost open LowStar.ModifiesPat open FStar.List.Tot open FStar.List.Pure open LowStar.BufferOps module Mod = LowStar.Modifies module ST = FStar.HyperStack.ST module HS = FStar.HyperStack module B = LowStar.Buffer /// Convenience renaming unfold let heap = HS.mem unfold let contains #a #rrel #rel h b = B.live #a #rrel #rel h b /// Convenience patterns let lemma_non_null (#t:Type) (a:pointer_or_null t) : Lemma (requires (a =!= null)) (ensures (len a = 1ul)) [SMTPat (len a)] = null_unique a /// Convenience operators unfold let (.[]) (s:list 'a) (n:nat{n < length s}) = index s n unfold let (~.) (#t:Type) (a:t) : Tot (erased (list t)) = [a] unfold let (^+) (#t:Type) (a:t) (b:erased (list t)) : Tot (erased (list t)) = Cons a b unfold let (+^) (#t:Type) (a:erased (list t)) (b:t) : Tot (erased (list t)) = append a [b] unfold let (^@^) (#t:Type) (a:erased (list t)) (b:erased (list t)) : Tot (erased (list t)) = append a b unfold let (@) (a:pointer 't) (h0:heap) = B.get h0 a 0 unfold let (^@) (a:pointer_or_null 't{a =!= null}) (h0:heap) = B.get h0 a 0 /// All the data structures #set-options "--__no_positivity" unopteq (** Node of a doubly linked list *) type node (t:Type0) = { (* forward link *) flink: pointer_or_null (node t); (* backward link *) blink: pointer_or_null (node t); (* payload *) p: t; } #reset-options private type nodelist t = list (pointer (node t)) unopteq (** Doubly linked list head *) type dll (t:Type0) ={ lhead: pointer_or_null (node t); ltail: pointer_or_null (node t); nodes: erased (nodelist t); } type nonempty_dll t = (h:dll t{h.lhead =!= null /\ h.ltail =!= null}) unopteq private (** An "almost valid" dll *) type piece t = { phead: pointer (node t); ptail: pointer (node t); pnodes: erased (nodelist t); } unopteq private (** An intermediate for when linked lists are being formed or destroyed *) type fragment t = | Frag0 : fragment t | Frag1 : piece t -> fragment t | Frag2 : piece t -> piece t -> fragment t | Frag3 : piece t -> piece t -> piece t -> fragment t /// Some useful empty initializers (** Initialize an element of a doubly linked list *) val empty_node: #t:Type -> payload:t -> node t let empty_node #t payload = { flink = null ; blink = null ; p = payload } (** Initialize a doubly linked list head *) val empty_list: #t:Type -> dll t let empty_list #t = { lhead = null ; ltail = null ; nodes = [] } /// Convenience wrappers for writing properties on fragments let fragment_for_each0 (#t:Type) (pr:piece t -> GTot Type0) (f:fragment t) : GTot Type0 = match f with | Frag0 -> True | Frag1 p1 -> pr p1 | Frag2 p1 p2 -> pr p1 /\ pr p2 | Frag3 p1 p2 p3 -> pr p1 /\ pr p2 /\ pr p3 let fragment_for_each1 (#t:Type) (#u:Type) (pr:u -> piece t -> GTot Type0) (v:u) (f:fragment t) : GTot Type0 = match f with | Frag0 -> True | Frag1 p1 -> pr v p1 | Frag2 p1 p2 -> pr v p1 /\ pr v p2 | Frag3 p1 p2 p3 -> pr v p1 /\ pr v p2 /\ pr v p3 let fragment_length (#t:Type) (f:fragment t) : GTot int = match f with | Frag0 -> 0 | Frag1 _ -> 1 | Frag2 _ _ -> 2 | Frag3 _ _ _ -> 3 /// Ghostly connections let dll_ghostly_connections (#t:Type) (d:dll t) : GTot Type0 = let nodes = d.nodes in match length nodes with | 0 -> d.lhead == null /\ d.ltail == null | _ -> d.lhead =!= null /\ d.ltail =!= null /\ d.lhead == hd nodes /\ d.ltail == last nodes let piece_ghostly_connections (#t:Type) (p:piece t) : GTot Type0 = let nodes = p.pnodes in match length nodes with | 0 -> False | _ -> p.phead == hd nodes /\ p.ptail == last nodes let rec fragment_ghostly_connections (#t:Type) (f:fragment t) : GTot Type0 = fragment_for_each0 piece_ghostly_connections f /// Containment properties /// /// WARNING: [@@] and [^@] require containment to reasonably talk about /// what they do. let rec nodelist_contained0 (#t:Type) (h0:heap) (nl:nodelist t) : GTot Type0 = match nl with | [] -> True | n :: ns -> h0 `contains` n /\ nodelist_contained0 h0 ns let rec nodelist_contained (#t:Type) (h0:heap) (nl:nodelist t) : GTot Type0 = nodelist_contained0 h0 nl let dll_contained (#t:Type) (h0:heap) (d:dll t) : GTot Type0 = h0 `contains` d.lhead /\ h0 `contains` d.ltail /\ nodelist_contained h0 d.nodes let piece_contained (#t:Type) (h0:heap) (p:piece t) : GTot Type0 = h0 `contains` p.phead /\ h0 `contains` p.ptail /\ nodelist_contained h0 p.pnodes let rec fragment_contained (#t:Type) (h0:heap) (f:fragment t) : GTot Type0 = fragment_for_each1 piece_contained h0 f /// Footprints let node_fp_f (#t:Type) (n:node t) : GTot Mod.loc = Mod.loc_buffer n.flink let node_fp_b (#t:Type) (n:node t) : GTot Mod.loc = Mod.loc_buffer n.blink let rec nodelist_fp0 (#t:Type) (n:nodelist t) : GTot Mod.loc = match n with | [] -> Mod.loc_none | n :: ns -> Mod.loc_union (Mod.loc_buffer n) (nodelist_fp0 ns) let rec nodelist_fp_f (#t:Type) (h0:heap) (n:nodelist t) : GTot Mod.loc = match n with | [] -> Mod.loc_none | n :: ns -> Mod.loc_union (Mod.loc_buffer (n@h0).flink) (nodelist_fp_f h0 ns) let rec nodelist_fp_b (#t:Type) (h0:heap) (n:nodelist t) : GTot Mod.loc = match n with | [] -> Mod.loc_none | n :: ns -> Mod.loc_union (Mod.loc_buffer (n@h0).blink) (nodelist_fp_b h0 ns) let dll_fp0 (#t:Type) (d:dll t) : GTot Mod.loc = Mod.loc_union // ghostly connections should give us this union for // free, but still useful to have (Mod.loc_union (Mod.loc_buffer d.lhead) (Mod.loc_buffer d.ltail)) (nodelist_fp0 d.nodes) let dll_fp_f (#t:Type) (h0:heap) (d:dll t) : GTot Mod.loc = let a = if g_is_null d.lhead then Mod.loc_none else Mod.loc_buffer (d.lhead^@h0).flink in let b = if g_is_null d.ltail then Mod.loc_none else Mod.loc_buffer (d.ltail^@h0).flink in Mod.loc_union // ghostly connections should give us this union for // free, but still useful to have (Mod.loc_union a b) (nodelist_fp_f h0 d.nodes) let dll_fp_b (#t:Type) (h0:heap) (d:dll t) : GTot Mod.loc = let a = if g_is_null d.lhead then Mod.loc_none else Mod.loc_buffer (d.lhead^@h0).blink in let b = if g_is_null d.ltail then Mod.loc_none else Mod.loc_buffer (d.ltail^@h0).blink in Mod.loc_union // ghostly connections should give us this union for // free, but still useful to have (Mod.loc_union a b) (nodelist_fp_b h0 d.nodes)
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowStar.ModifiesPat.fst.checked", "LowStar.Modifies.fst.checked", "LowStar.BufferOps.fst.checked", "LowStar.Buffer.fst.checked", "FStar.UInt32.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked", "FStar.List.Pure.Properties.fst.checked", "FStar.List.Pure.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked", "FStar.Classical.fsti.checked" ], "interface_file": false, "source_file": "DoublyLinkedList.fst" }
[ { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": true, "full_module": "LowStar.Modifies", "short_module": "Mod" }, { "abbrev": false, "full_module": "LowStar.BufferOps", "short_module": null }, { "abbrev": false, "full_module": "FStar.List.Pure", "short_module": null }, { "abbrev": false, "full_module": "FStar.List.Tot", "short_module": null }, { "abbrev": false, "full_module": "LowStar.ModifiesPat", "short_module": null }, { "abbrev": false, "full_module": "FStar.Ghost", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
p: DoublyLinkedList.piece t -> Prims.GTot LowStar.Monotonic.Buffer.loc
Prims.GTot
[ "sometrivial" ]
[]
[ "DoublyLinkedList.piece", "LowStar.Monotonic.Buffer.loc_union", "LowStar.Monotonic.Buffer.loc_buffer", "DoublyLinkedList.node", "LowStar.Buffer.trivial_preorder", "DoublyLinkedList.__proj__Mkpiece__item__phead", "DoublyLinkedList.__proj__Mkpiece__item__ptail", "DoublyLinkedList.nodelist_fp0", "FStar.Ghost.reveal", "DoublyLinkedList.nodelist", "DoublyLinkedList.__proj__Mkpiece__item__pnodes", "LowStar.Monotonic.Buffer.loc" ]
[]
false
false
false
false
false
let piece_fp0 (#t: Type) (p: piece t) : GTot Mod.loc =
Mod.loc_union (Mod.loc_union (Mod.loc_buffer p.phead) (Mod.loc_buffer p.ptail)) (nodelist_fp0 p.pnodes)
false
DoublyLinkedList.fst
DoublyLinkedList.node_aa
val node_aa (#t: Type) (n: node t) : GTot Type0
val node_aa (#t: Type) (n: node t) : GTot Type0
let node_aa (#t:Type) (n:node t) : GTot Type0 = Mod.loc_disjoint (node_fp_f n) (node_fp_b n)
{ "file_name": "examples/doublylinkedlist/DoublyLinkedList.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 46, "end_line": 312, "start_col": 0, "start_line": 311 }
(* Copyright 2008-2019 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module DoublyLinkedList open FStar open FStar.HyperStack.ST open FStar.Ghost open LowStar.ModifiesPat open FStar.List.Tot open FStar.List.Pure open LowStar.BufferOps module Mod = LowStar.Modifies module ST = FStar.HyperStack.ST module HS = FStar.HyperStack module B = LowStar.Buffer /// Convenience renaming unfold let heap = HS.mem unfold let contains #a #rrel #rel h b = B.live #a #rrel #rel h b /// Convenience patterns let lemma_non_null (#t:Type) (a:pointer_or_null t) : Lemma (requires (a =!= null)) (ensures (len a = 1ul)) [SMTPat (len a)] = null_unique a /// Convenience operators unfold let (.[]) (s:list 'a) (n:nat{n < length s}) = index s n unfold let (~.) (#t:Type) (a:t) : Tot (erased (list t)) = [a] unfold let (^+) (#t:Type) (a:t) (b:erased (list t)) : Tot (erased (list t)) = Cons a b unfold let (+^) (#t:Type) (a:erased (list t)) (b:t) : Tot (erased (list t)) = append a [b] unfold let (^@^) (#t:Type) (a:erased (list t)) (b:erased (list t)) : Tot (erased (list t)) = append a b unfold let (@) (a:pointer 't) (h0:heap) = B.get h0 a 0 unfold let (^@) (a:pointer_or_null 't{a =!= null}) (h0:heap) = B.get h0 a 0 /// All the data structures #set-options "--__no_positivity" unopteq (** Node of a doubly linked list *) type node (t:Type0) = { (* forward link *) flink: pointer_or_null (node t); (* backward link *) blink: pointer_or_null (node t); (* payload *) p: t; } #reset-options private type nodelist t = list (pointer (node t)) unopteq (** Doubly linked list head *) type dll (t:Type0) ={ lhead: pointer_or_null (node t); ltail: pointer_or_null (node t); nodes: erased (nodelist t); } type nonempty_dll t = (h:dll t{h.lhead =!= null /\ h.ltail =!= null}) unopteq private (** An "almost valid" dll *) type piece t = { phead: pointer (node t); ptail: pointer (node t); pnodes: erased (nodelist t); } unopteq private (** An intermediate for when linked lists are being formed or destroyed *) type fragment t = | Frag0 : fragment t | Frag1 : piece t -> fragment t | Frag2 : piece t -> piece t -> fragment t | Frag3 : piece t -> piece t -> piece t -> fragment t /// Some useful empty initializers (** Initialize an element of a doubly linked list *) val empty_node: #t:Type -> payload:t -> node t let empty_node #t payload = { flink = null ; blink = null ; p = payload } (** Initialize a doubly linked list head *) val empty_list: #t:Type -> dll t let empty_list #t = { lhead = null ; ltail = null ; nodes = [] } /// Convenience wrappers for writing properties on fragments let fragment_for_each0 (#t:Type) (pr:piece t -> GTot Type0) (f:fragment t) : GTot Type0 = match f with | Frag0 -> True | Frag1 p1 -> pr p1 | Frag2 p1 p2 -> pr p1 /\ pr p2 | Frag3 p1 p2 p3 -> pr p1 /\ pr p2 /\ pr p3 let fragment_for_each1 (#t:Type) (#u:Type) (pr:u -> piece t -> GTot Type0) (v:u) (f:fragment t) : GTot Type0 = match f with | Frag0 -> True | Frag1 p1 -> pr v p1 | Frag2 p1 p2 -> pr v p1 /\ pr v p2 | Frag3 p1 p2 p3 -> pr v p1 /\ pr v p2 /\ pr v p3 let fragment_length (#t:Type) (f:fragment t) : GTot int = match f with | Frag0 -> 0 | Frag1 _ -> 1 | Frag2 _ _ -> 2 | Frag3 _ _ _ -> 3 /// Ghostly connections let dll_ghostly_connections (#t:Type) (d:dll t) : GTot Type0 = let nodes = d.nodes in match length nodes with | 0 -> d.lhead == null /\ d.ltail == null | _ -> d.lhead =!= null /\ d.ltail =!= null /\ d.lhead == hd nodes /\ d.ltail == last nodes let piece_ghostly_connections (#t:Type) (p:piece t) : GTot Type0 = let nodes = p.pnodes in match length nodes with | 0 -> False | _ -> p.phead == hd nodes /\ p.ptail == last nodes let rec fragment_ghostly_connections (#t:Type) (f:fragment t) : GTot Type0 = fragment_for_each0 piece_ghostly_connections f /// Containment properties /// /// WARNING: [@@] and [^@] require containment to reasonably talk about /// what they do. let rec nodelist_contained0 (#t:Type) (h0:heap) (nl:nodelist t) : GTot Type0 = match nl with | [] -> True | n :: ns -> h0 `contains` n /\ nodelist_contained0 h0 ns let rec nodelist_contained (#t:Type) (h0:heap) (nl:nodelist t) : GTot Type0 = nodelist_contained0 h0 nl let dll_contained (#t:Type) (h0:heap) (d:dll t) : GTot Type0 = h0 `contains` d.lhead /\ h0 `contains` d.ltail /\ nodelist_contained h0 d.nodes let piece_contained (#t:Type) (h0:heap) (p:piece t) : GTot Type0 = h0 `contains` p.phead /\ h0 `contains` p.ptail /\ nodelist_contained h0 p.pnodes let rec fragment_contained (#t:Type) (h0:heap) (f:fragment t) : GTot Type0 = fragment_for_each1 piece_contained h0 f /// Footprints let node_fp_f (#t:Type) (n:node t) : GTot Mod.loc = Mod.loc_buffer n.flink let node_fp_b (#t:Type) (n:node t) : GTot Mod.loc = Mod.loc_buffer n.blink let rec nodelist_fp0 (#t:Type) (n:nodelist t) : GTot Mod.loc = match n with | [] -> Mod.loc_none | n :: ns -> Mod.loc_union (Mod.loc_buffer n) (nodelist_fp0 ns) let rec nodelist_fp_f (#t:Type) (h0:heap) (n:nodelist t) : GTot Mod.loc = match n with | [] -> Mod.loc_none | n :: ns -> Mod.loc_union (Mod.loc_buffer (n@h0).flink) (nodelist_fp_f h0 ns) let rec nodelist_fp_b (#t:Type) (h0:heap) (n:nodelist t) : GTot Mod.loc = match n with | [] -> Mod.loc_none | n :: ns -> Mod.loc_union (Mod.loc_buffer (n@h0).blink) (nodelist_fp_b h0 ns) let dll_fp0 (#t:Type) (d:dll t) : GTot Mod.loc = Mod.loc_union // ghostly connections should give us this union for // free, but still useful to have (Mod.loc_union (Mod.loc_buffer d.lhead) (Mod.loc_buffer d.ltail)) (nodelist_fp0 d.nodes) let dll_fp_f (#t:Type) (h0:heap) (d:dll t) : GTot Mod.loc = let a = if g_is_null d.lhead then Mod.loc_none else Mod.loc_buffer (d.lhead^@h0).flink in let b = if g_is_null d.ltail then Mod.loc_none else Mod.loc_buffer (d.ltail^@h0).flink in Mod.loc_union // ghostly connections should give us this union for // free, but still useful to have (Mod.loc_union a b) (nodelist_fp_f h0 d.nodes) let dll_fp_b (#t:Type) (h0:heap) (d:dll t) : GTot Mod.loc = let a = if g_is_null d.lhead then Mod.loc_none else Mod.loc_buffer (d.lhead^@h0).blink in let b = if g_is_null d.ltail then Mod.loc_none else Mod.loc_buffer (d.ltail^@h0).blink in Mod.loc_union // ghostly connections should give us this union for // free, but still useful to have (Mod.loc_union a b) (nodelist_fp_b h0 d.nodes) let piece_fp0 (#t:Type) (p:piece t) : GTot Mod.loc = Mod.loc_union // ghostly connections should give us this union for // free, but still useful to have (Mod.loc_union (Mod.loc_buffer p.phead) (Mod.loc_buffer p.ptail)) (nodelist_fp0 p.pnodes) let piece_fp_f (#t:Type) (h0:heap) (p:piece t) : GTot Mod.loc = Mod.loc_union // ghostly connections should give us this union for // free, but still useful to have (Mod.loc_union (Mod.loc_buffer (p.phead@h0).flink) (Mod.loc_buffer (p.ptail@h0).flink)) (nodelist_fp_f h0 p.pnodes) let piece_fp_b (#t:Type) (h0:heap) (p:piece t) : GTot Mod.loc = Mod.loc_union // ghostly connections should give us this union for // free, but still useful to have (Mod.loc_union (Mod.loc_buffer (p.phead@h0).blink) (Mod.loc_buffer (p.ptail@h0).blink)) (nodelist_fp_b h0 p.pnodes) let rec fragment_fp0 (#t:Type) (f:fragment t) : GTot Mod.loc = match f with | Frag0 -> Mod.loc_none | Frag1 p1 -> piece_fp0 p1 | Frag2 p1 p2 -> Mod.loc_union (piece_fp0 p1) (piece_fp0 p2) | Frag3 p1 p2 p3 -> Mod.loc_union (piece_fp0 p1) (Mod.loc_union (piece_fp0 p2) (piece_fp0 p3)) /// Helper patterns for footprints let loc_includes_union_l_nodelist_fp0 (#t: Type) (s1 s2:loc) (nl:nodelist t) : Lemma (requires (loc_includes s1 (nodelist_fp0 nl) \/ loc_includes s2 (nodelist_fp0 nl))) (ensures (loc_includes (loc_union s1 s2) (nodelist_fp0 nl))) [SMTPat (loc_includes (loc_union s1 s2) (nodelist_fp0 nl))] = loc_includes_union_l s1 s2 (nodelist_fp0 nl) let loc_includes_union_l_dll_fp0 (#t: Type) (s1 s2:loc) (d:dll t) : Lemma (requires (loc_includes s1 (dll_fp0 d) \/ loc_includes s2 (dll_fp0 d))) (ensures (loc_includes (loc_union s1 s2) (dll_fp0 d))) [SMTPat (loc_includes (loc_union s1 s2) (dll_fp0 d))] = loc_includes_union_l s1 s2 (dll_fp0 d) let loc_includes_union_l_piece_fp0 (#t: Type) (s1 s2:loc) (p:piece t) : Lemma (requires (loc_includes s1 (piece_fp0 p) \/ loc_includes s2 (piece_fp0 p))) (ensures (loc_includes (loc_union s1 s2) (piece_fp0 p))) [SMTPat (loc_includes (loc_union s1 s2) (piece_fp0 p))] = loc_includes_union_l s1 s2 (piece_fp0 p) let loc_includes_union_l_fragment_fp0 (#t: Type) (s1 s2:loc) (f:fragment t) : Lemma (requires (loc_includes s1 (fragment_fp0 f) \/ loc_includes s2 (fragment_fp0 f))) (ensures (loc_includes (loc_union s1 s2) (fragment_fp0 f))) [SMTPat (loc_includes (loc_union s1 s2) (fragment_fp0 f))] = loc_includes_union_l s1 s2 (fragment_fp0 f) /// Equivalence for locations let loc_equiv (a b:Mod.loc) = Mod.loc_includes a b /\ Mod.loc_includes b a let loc_equiv_trans (a b c:Mod.loc) : Lemma (requires (loc_equiv a b /\ loc_equiv b c)) (ensures (loc_equiv a c)) [SMTPat (loc_equiv a b); SMTPat (loc_equiv b c); SMTPat (loc_equiv a c)] = Mod.loc_includes_trans a b c; Mod.loc_includes_trans c b a let loc_equiv_union_union_loc (a b c:Mod.loc) : Lemma (requires (loc_equiv b c)) (ensures (loc_equiv (Mod.loc_union a b) (Mod.loc_union a c))) [SMTPat (loc_equiv (Mod.loc_union a b) (Mod.loc_union a c))] = let incl = Mod.loc_includes in let u = Mod.loc_union in // assert (b `incl` c); Mod.loc_includes_union_l a b c; // assert ((a `u` b) `incl` c); Mod.loc_includes_union_l a b a; // assert ((a `u` b) `incl` a); // assert ((a `u` b) `incl` (a `u` c)); Mod.loc_includes_union_l a c b; Mod.loc_includes_union_l a c a /// Anti aliasing properties
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowStar.ModifiesPat.fst.checked", "LowStar.Modifies.fst.checked", "LowStar.BufferOps.fst.checked", "LowStar.Buffer.fst.checked", "FStar.UInt32.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked", "FStar.List.Pure.Properties.fst.checked", "FStar.List.Pure.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked", "FStar.Classical.fsti.checked" ], "interface_file": false, "source_file": "DoublyLinkedList.fst" }
[ { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": true, "full_module": "LowStar.Modifies", "short_module": "Mod" }, { "abbrev": false, "full_module": "LowStar.BufferOps", "short_module": null }, { "abbrev": false, "full_module": "FStar.List.Pure", "short_module": null }, { "abbrev": false, "full_module": "FStar.List.Tot", "short_module": null }, { "abbrev": false, "full_module": "LowStar.ModifiesPat", "short_module": null }, { "abbrev": false, "full_module": "FStar.Ghost", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
n: DoublyLinkedList.node t -> Prims.GTot Type0
Prims.GTot
[ "sometrivial" ]
[]
[ "DoublyLinkedList.node", "LowStar.Monotonic.Buffer.loc_disjoint", "DoublyLinkedList.node_fp_f", "DoublyLinkedList.node_fp_b" ]
[]
false
false
false
false
true
let node_aa (#t: Type) (n: node t) : GTot Type0 =
Mod.loc_disjoint (node_fp_f n) (node_fp_b n)
false
DoublyLinkedList.fst
DoublyLinkedList.piece_fp_b
val piece_fp_b (#t: Type) (h0: heap) (p: piece t) : GTot Mod.loc
val piece_fp_b (#t: Type) (h0: heap) (p: piece t) : GTot Mod.loc
let piece_fp_b (#t:Type) (h0:heap) (p:piece t) : GTot Mod.loc = Mod.loc_union // ghostly connections should give us this union for // free, but still useful to have (Mod.loc_union (Mod.loc_buffer (p.phead@h0).blink) (Mod.loc_buffer (p.ptail@h0).blink)) (nodelist_fp_b h0 p.pnodes)
{ "file_name": "examples/doublylinkedlist/DoublyLinkedList.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 31, "end_line": 236, "start_col": 0, "start_line": 232 }
(* Copyright 2008-2019 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module DoublyLinkedList open FStar open FStar.HyperStack.ST open FStar.Ghost open LowStar.ModifiesPat open FStar.List.Tot open FStar.List.Pure open LowStar.BufferOps module Mod = LowStar.Modifies module ST = FStar.HyperStack.ST module HS = FStar.HyperStack module B = LowStar.Buffer /// Convenience renaming unfold let heap = HS.mem unfold let contains #a #rrel #rel h b = B.live #a #rrel #rel h b /// Convenience patterns let lemma_non_null (#t:Type) (a:pointer_or_null t) : Lemma (requires (a =!= null)) (ensures (len a = 1ul)) [SMTPat (len a)] = null_unique a /// Convenience operators unfold let (.[]) (s:list 'a) (n:nat{n < length s}) = index s n unfold let (~.) (#t:Type) (a:t) : Tot (erased (list t)) = [a] unfold let (^+) (#t:Type) (a:t) (b:erased (list t)) : Tot (erased (list t)) = Cons a b unfold let (+^) (#t:Type) (a:erased (list t)) (b:t) : Tot (erased (list t)) = append a [b] unfold let (^@^) (#t:Type) (a:erased (list t)) (b:erased (list t)) : Tot (erased (list t)) = append a b unfold let (@) (a:pointer 't) (h0:heap) = B.get h0 a 0 unfold let (^@) (a:pointer_or_null 't{a =!= null}) (h0:heap) = B.get h0 a 0 /// All the data structures #set-options "--__no_positivity" unopteq (** Node of a doubly linked list *) type node (t:Type0) = { (* forward link *) flink: pointer_or_null (node t); (* backward link *) blink: pointer_or_null (node t); (* payload *) p: t; } #reset-options private type nodelist t = list (pointer (node t)) unopteq (** Doubly linked list head *) type dll (t:Type0) ={ lhead: pointer_or_null (node t); ltail: pointer_or_null (node t); nodes: erased (nodelist t); } type nonempty_dll t = (h:dll t{h.lhead =!= null /\ h.ltail =!= null}) unopteq private (** An "almost valid" dll *) type piece t = { phead: pointer (node t); ptail: pointer (node t); pnodes: erased (nodelist t); } unopteq private (** An intermediate for when linked lists are being formed or destroyed *) type fragment t = | Frag0 : fragment t | Frag1 : piece t -> fragment t | Frag2 : piece t -> piece t -> fragment t | Frag3 : piece t -> piece t -> piece t -> fragment t /// Some useful empty initializers (** Initialize an element of a doubly linked list *) val empty_node: #t:Type -> payload:t -> node t let empty_node #t payload = { flink = null ; blink = null ; p = payload } (** Initialize a doubly linked list head *) val empty_list: #t:Type -> dll t let empty_list #t = { lhead = null ; ltail = null ; nodes = [] } /// Convenience wrappers for writing properties on fragments let fragment_for_each0 (#t:Type) (pr:piece t -> GTot Type0) (f:fragment t) : GTot Type0 = match f with | Frag0 -> True | Frag1 p1 -> pr p1 | Frag2 p1 p2 -> pr p1 /\ pr p2 | Frag3 p1 p2 p3 -> pr p1 /\ pr p2 /\ pr p3 let fragment_for_each1 (#t:Type) (#u:Type) (pr:u -> piece t -> GTot Type0) (v:u) (f:fragment t) : GTot Type0 = match f with | Frag0 -> True | Frag1 p1 -> pr v p1 | Frag2 p1 p2 -> pr v p1 /\ pr v p2 | Frag3 p1 p2 p3 -> pr v p1 /\ pr v p2 /\ pr v p3 let fragment_length (#t:Type) (f:fragment t) : GTot int = match f with | Frag0 -> 0 | Frag1 _ -> 1 | Frag2 _ _ -> 2 | Frag3 _ _ _ -> 3 /// Ghostly connections let dll_ghostly_connections (#t:Type) (d:dll t) : GTot Type0 = let nodes = d.nodes in match length nodes with | 0 -> d.lhead == null /\ d.ltail == null | _ -> d.lhead =!= null /\ d.ltail =!= null /\ d.lhead == hd nodes /\ d.ltail == last nodes let piece_ghostly_connections (#t:Type) (p:piece t) : GTot Type0 = let nodes = p.pnodes in match length nodes with | 0 -> False | _ -> p.phead == hd nodes /\ p.ptail == last nodes let rec fragment_ghostly_connections (#t:Type) (f:fragment t) : GTot Type0 = fragment_for_each0 piece_ghostly_connections f /// Containment properties /// /// WARNING: [@@] and [^@] require containment to reasonably talk about /// what they do. let rec nodelist_contained0 (#t:Type) (h0:heap) (nl:nodelist t) : GTot Type0 = match nl with | [] -> True | n :: ns -> h0 `contains` n /\ nodelist_contained0 h0 ns let rec nodelist_contained (#t:Type) (h0:heap) (nl:nodelist t) : GTot Type0 = nodelist_contained0 h0 nl let dll_contained (#t:Type) (h0:heap) (d:dll t) : GTot Type0 = h0 `contains` d.lhead /\ h0 `contains` d.ltail /\ nodelist_contained h0 d.nodes let piece_contained (#t:Type) (h0:heap) (p:piece t) : GTot Type0 = h0 `contains` p.phead /\ h0 `contains` p.ptail /\ nodelist_contained h0 p.pnodes let rec fragment_contained (#t:Type) (h0:heap) (f:fragment t) : GTot Type0 = fragment_for_each1 piece_contained h0 f /// Footprints let node_fp_f (#t:Type) (n:node t) : GTot Mod.loc = Mod.loc_buffer n.flink let node_fp_b (#t:Type) (n:node t) : GTot Mod.loc = Mod.loc_buffer n.blink let rec nodelist_fp0 (#t:Type) (n:nodelist t) : GTot Mod.loc = match n with | [] -> Mod.loc_none | n :: ns -> Mod.loc_union (Mod.loc_buffer n) (nodelist_fp0 ns) let rec nodelist_fp_f (#t:Type) (h0:heap) (n:nodelist t) : GTot Mod.loc = match n with | [] -> Mod.loc_none | n :: ns -> Mod.loc_union (Mod.loc_buffer (n@h0).flink) (nodelist_fp_f h0 ns) let rec nodelist_fp_b (#t:Type) (h0:heap) (n:nodelist t) : GTot Mod.loc = match n with | [] -> Mod.loc_none | n :: ns -> Mod.loc_union (Mod.loc_buffer (n@h0).blink) (nodelist_fp_b h0 ns) let dll_fp0 (#t:Type) (d:dll t) : GTot Mod.loc = Mod.loc_union // ghostly connections should give us this union for // free, but still useful to have (Mod.loc_union (Mod.loc_buffer d.lhead) (Mod.loc_buffer d.ltail)) (nodelist_fp0 d.nodes) let dll_fp_f (#t:Type) (h0:heap) (d:dll t) : GTot Mod.loc = let a = if g_is_null d.lhead then Mod.loc_none else Mod.loc_buffer (d.lhead^@h0).flink in let b = if g_is_null d.ltail then Mod.loc_none else Mod.loc_buffer (d.ltail^@h0).flink in Mod.loc_union // ghostly connections should give us this union for // free, but still useful to have (Mod.loc_union a b) (nodelist_fp_f h0 d.nodes) let dll_fp_b (#t:Type) (h0:heap) (d:dll t) : GTot Mod.loc = let a = if g_is_null d.lhead then Mod.loc_none else Mod.loc_buffer (d.lhead^@h0).blink in let b = if g_is_null d.ltail then Mod.loc_none else Mod.loc_buffer (d.ltail^@h0).blink in Mod.loc_union // ghostly connections should give us this union for // free, but still useful to have (Mod.loc_union a b) (nodelist_fp_b h0 d.nodes) let piece_fp0 (#t:Type) (p:piece t) : GTot Mod.loc = Mod.loc_union // ghostly connections should give us this union for // free, but still useful to have (Mod.loc_union (Mod.loc_buffer p.phead) (Mod.loc_buffer p.ptail)) (nodelist_fp0 p.pnodes) let piece_fp_f (#t:Type) (h0:heap) (p:piece t) : GTot Mod.loc = Mod.loc_union // ghostly connections should give us this union for // free, but still useful to have (Mod.loc_union (Mod.loc_buffer (p.phead@h0).flink) (Mod.loc_buffer (p.ptail@h0).flink))
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowStar.ModifiesPat.fst.checked", "LowStar.Modifies.fst.checked", "LowStar.BufferOps.fst.checked", "LowStar.Buffer.fst.checked", "FStar.UInt32.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked", "FStar.List.Pure.Properties.fst.checked", "FStar.List.Pure.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked", "FStar.Classical.fsti.checked" ], "interface_file": false, "source_file": "DoublyLinkedList.fst" }
[ { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": true, "full_module": "LowStar.Modifies", "short_module": "Mod" }, { "abbrev": false, "full_module": "LowStar.BufferOps", "short_module": null }, { "abbrev": false, "full_module": "FStar.List.Pure", "short_module": null }, { "abbrev": false, "full_module": "FStar.List.Tot", "short_module": null }, { "abbrev": false, "full_module": "LowStar.ModifiesPat", "short_module": null }, { "abbrev": false, "full_module": "FStar.Ghost", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
h0: DoublyLinkedList.heap -> p: DoublyLinkedList.piece t -> Prims.GTot LowStar.Monotonic.Buffer.loc
Prims.GTot
[ "sometrivial" ]
[]
[ "DoublyLinkedList.heap", "DoublyLinkedList.piece", "LowStar.Monotonic.Buffer.loc_union", "LowStar.Monotonic.Buffer.loc_buffer", "DoublyLinkedList.node", "LowStar.Buffer.trivial_preorder", "DoublyLinkedList.__proj__Mknode__item__blink", "DoublyLinkedList.op_At", "DoublyLinkedList.__proj__Mkpiece__item__phead", "DoublyLinkedList.__proj__Mkpiece__item__ptail", "DoublyLinkedList.nodelist_fp_b", "FStar.Ghost.reveal", "DoublyLinkedList.nodelist", "DoublyLinkedList.__proj__Mkpiece__item__pnodes", "LowStar.Monotonic.Buffer.loc" ]
[]
false
false
false
false
false
let piece_fp_b (#t: Type) (h0: heap) (p: piece t) : GTot Mod.loc =
Mod.loc_union (Mod.loc_union (Mod.loc_buffer (p.phead @ h0).blink) (Mod.loc_buffer (p.ptail @ h0).blink)) (nodelist_fp_b h0 p.pnodes)
false
DoublyLinkedList.fst
DoublyLinkedList.fragment_for_each0
val fragment_for_each0 (#t: Type) (pr: (piece t -> GTot Type0)) (f: fragment t) : GTot Type0
val fragment_for_each0 (#t: Type) (pr: (piece t -> GTot Type0)) (f: fragment t) : GTot Type0
let fragment_for_each0 (#t:Type) (pr:piece t -> GTot Type0) (f:fragment t) : GTot Type0 = match f with | Frag0 -> True | Frag1 p1 -> pr p1 | Frag2 p1 p2 -> pr p1 /\ pr p2 | Frag3 p1 p2 p3 -> pr p1 /\ pr p2 /\ pr p3
{ "file_name": "examples/doublylinkedlist/DoublyLinkedList.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 45, "end_line": 121, "start_col": 0, "start_line": 116 }
(* Copyright 2008-2019 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module DoublyLinkedList open FStar open FStar.HyperStack.ST open FStar.Ghost open LowStar.ModifiesPat open FStar.List.Tot open FStar.List.Pure open LowStar.BufferOps module Mod = LowStar.Modifies module ST = FStar.HyperStack.ST module HS = FStar.HyperStack module B = LowStar.Buffer /// Convenience renaming unfold let heap = HS.mem unfold let contains #a #rrel #rel h b = B.live #a #rrel #rel h b /// Convenience patterns let lemma_non_null (#t:Type) (a:pointer_or_null t) : Lemma (requires (a =!= null)) (ensures (len a = 1ul)) [SMTPat (len a)] = null_unique a /// Convenience operators unfold let (.[]) (s:list 'a) (n:nat{n < length s}) = index s n unfold let (~.) (#t:Type) (a:t) : Tot (erased (list t)) = [a] unfold let (^+) (#t:Type) (a:t) (b:erased (list t)) : Tot (erased (list t)) = Cons a b unfold let (+^) (#t:Type) (a:erased (list t)) (b:t) : Tot (erased (list t)) = append a [b] unfold let (^@^) (#t:Type) (a:erased (list t)) (b:erased (list t)) : Tot (erased (list t)) = append a b unfold let (@) (a:pointer 't) (h0:heap) = B.get h0 a 0 unfold let (^@) (a:pointer_or_null 't{a =!= null}) (h0:heap) = B.get h0 a 0 /// All the data structures #set-options "--__no_positivity" unopteq (** Node of a doubly linked list *) type node (t:Type0) = { (* forward link *) flink: pointer_or_null (node t); (* backward link *) blink: pointer_or_null (node t); (* payload *) p: t; } #reset-options private type nodelist t = list (pointer (node t)) unopteq (** Doubly linked list head *) type dll (t:Type0) ={ lhead: pointer_or_null (node t); ltail: pointer_or_null (node t); nodes: erased (nodelist t); } type nonempty_dll t = (h:dll t{h.lhead =!= null /\ h.ltail =!= null}) unopteq private (** An "almost valid" dll *) type piece t = { phead: pointer (node t); ptail: pointer (node t); pnodes: erased (nodelist t); } unopteq private (** An intermediate for when linked lists are being formed or destroyed *) type fragment t = | Frag0 : fragment t | Frag1 : piece t -> fragment t | Frag2 : piece t -> piece t -> fragment t | Frag3 : piece t -> piece t -> piece t -> fragment t /// Some useful empty initializers (** Initialize an element of a doubly linked list *) val empty_node: #t:Type -> payload:t -> node t let empty_node #t payload = { flink = null ; blink = null ; p = payload } (** Initialize a doubly linked list head *) val empty_list: #t:Type -> dll t let empty_list #t = { lhead = null ; ltail = null ; nodes = [] } /// Convenience wrappers for writing properties on fragments
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowStar.ModifiesPat.fst.checked", "LowStar.Modifies.fst.checked", "LowStar.BufferOps.fst.checked", "LowStar.Buffer.fst.checked", "FStar.UInt32.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked", "FStar.List.Pure.Properties.fst.checked", "FStar.List.Pure.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked", "FStar.Classical.fsti.checked" ], "interface_file": false, "source_file": "DoublyLinkedList.fst" }
[ { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": true, "full_module": "LowStar.Modifies", "short_module": "Mod" }, { "abbrev": false, "full_module": "LowStar.BufferOps", "short_module": null }, { "abbrev": false, "full_module": "FStar.List.Pure", "short_module": null }, { "abbrev": false, "full_module": "FStar.List.Tot", "short_module": null }, { "abbrev": false, "full_module": "LowStar.ModifiesPat", "short_module": null }, { "abbrev": false, "full_module": "FStar.Ghost", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
pr: (_: DoublyLinkedList.piece t -> Prims.GTot Type0) -> f: DoublyLinkedList.fragment t -> Prims.GTot Type0
Prims.GTot
[ "sometrivial" ]
[]
[ "DoublyLinkedList.piece", "DoublyLinkedList.fragment", "Prims.l_True", "Prims.l_and" ]
[]
false
false
false
false
true
let fragment_for_each0 (#t: Type) (pr: (piece t -> GTot Type0)) (f: fragment t) : GTot Type0 =
match f with | Frag0 -> True | Frag1 p1 -> pr p1 | Frag2 p1 p2 -> pr p1 /\ pr p2 | Frag3 p1 p2 p3 -> pr p1 /\ pr p2 /\ pr p3
false
DoublyLinkedList.fst
DoublyLinkedList.empty_list
val empty_list: #t:Type -> dll t
val empty_list: #t:Type -> dll t
let empty_list #t = { lhead = null ; ltail = null ; nodes = [] }
{ "file_name": "examples/doublylinkedlist/DoublyLinkedList.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 46, "end_line": 112, "start_col": 0, "start_line": 111 }
(* Copyright 2008-2019 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module DoublyLinkedList open FStar open FStar.HyperStack.ST open FStar.Ghost open LowStar.ModifiesPat open FStar.List.Tot open FStar.List.Pure open LowStar.BufferOps module Mod = LowStar.Modifies module ST = FStar.HyperStack.ST module HS = FStar.HyperStack module B = LowStar.Buffer /// Convenience renaming unfold let heap = HS.mem unfold let contains #a #rrel #rel h b = B.live #a #rrel #rel h b /// Convenience patterns let lemma_non_null (#t:Type) (a:pointer_or_null t) : Lemma (requires (a =!= null)) (ensures (len a = 1ul)) [SMTPat (len a)] = null_unique a /// Convenience operators unfold let (.[]) (s:list 'a) (n:nat{n < length s}) = index s n unfold let (~.) (#t:Type) (a:t) : Tot (erased (list t)) = [a] unfold let (^+) (#t:Type) (a:t) (b:erased (list t)) : Tot (erased (list t)) = Cons a b unfold let (+^) (#t:Type) (a:erased (list t)) (b:t) : Tot (erased (list t)) = append a [b] unfold let (^@^) (#t:Type) (a:erased (list t)) (b:erased (list t)) : Tot (erased (list t)) = append a b unfold let (@) (a:pointer 't) (h0:heap) = B.get h0 a 0 unfold let (^@) (a:pointer_or_null 't{a =!= null}) (h0:heap) = B.get h0 a 0 /// All the data structures #set-options "--__no_positivity" unopteq (** Node of a doubly linked list *) type node (t:Type0) = { (* forward link *) flink: pointer_or_null (node t); (* backward link *) blink: pointer_or_null (node t); (* payload *) p: t; } #reset-options private type nodelist t = list (pointer (node t)) unopteq (** Doubly linked list head *) type dll (t:Type0) ={ lhead: pointer_or_null (node t); ltail: pointer_or_null (node t); nodes: erased (nodelist t); } type nonempty_dll t = (h:dll t{h.lhead =!= null /\ h.ltail =!= null}) unopteq private (** An "almost valid" dll *) type piece t = { phead: pointer (node t); ptail: pointer (node t); pnodes: erased (nodelist t); } unopteq private (** An intermediate for when linked lists are being formed or destroyed *) type fragment t = | Frag0 : fragment t | Frag1 : piece t -> fragment t | Frag2 : piece t -> piece t -> fragment t | Frag3 : piece t -> piece t -> piece t -> fragment t /// Some useful empty initializers (** Initialize an element of a doubly linked list *) val empty_node: #t:Type -> payload:t -> node t let empty_node #t payload = { flink = null ; blink = null ; p = payload } (** Initialize a doubly linked list head *) val empty_list: #t:Type -> dll t
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowStar.ModifiesPat.fst.checked", "LowStar.Modifies.fst.checked", "LowStar.BufferOps.fst.checked", "LowStar.Buffer.fst.checked", "FStar.UInt32.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked", "FStar.List.Pure.Properties.fst.checked", "FStar.List.Pure.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked", "FStar.Classical.fsti.checked" ], "interface_file": false, "source_file": "DoublyLinkedList.fst" }
[ { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": true, "full_module": "LowStar.Modifies", "short_module": "Mod" }, { "abbrev": false, "full_module": "LowStar.BufferOps", "short_module": null }, { "abbrev": false, "full_module": "FStar.List.Pure", "short_module": null }, { "abbrev": false, "full_module": "FStar.List.Tot", "short_module": null }, { "abbrev": false, "full_module": "LowStar.ModifiesPat", "short_module": null }, { "abbrev": false, "full_module": "FStar.Ghost", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
DoublyLinkedList.dll t
Prims.Tot
[ "total" ]
[]
[ "DoublyLinkedList.Mkdll", "LowStar.Buffer.null", "DoublyLinkedList.node", "FStar.Ghost.hide", "DoublyLinkedList.nodelist", "Prims.Nil", "LowStar.Buffer.pointer", "DoublyLinkedList.dll" ]
[]
false
false
false
true
false
let empty_list #t =
{ lhead = null; ltail = null; nodes = [] }
false
DoublyLinkedList.fst
DoublyLinkedList.dll_aa
val dll_aa (#t: Type) (d: dll t) : GTot Type0
val dll_aa (#t: Type) (d: dll t) : GTot Type0
let dll_aa (#t:Type) (d:dll t) : GTot Type0 = nodelist_aa d.nodes
{ "file_name": "examples/doublylinkedlist/DoublyLinkedList.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 21, "end_line": 331, "start_col": 0, "start_line": 330 }
(* Copyright 2008-2019 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module DoublyLinkedList open FStar open FStar.HyperStack.ST open FStar.Ghost open LowStar.ModifiesPat open FStar.List.Tot open FStar.List.Pure open LowStar.BufferOps module Mod = LowStar.Modifies module ST = FStar.HyperStack.ST module HS = FStar.HyperStack module B = LowStar.Buffer /// Convenience renaming unfold let heap = HS.mem unfold let contains #a #rrel #rel h b = B.live #a #rrel #rel h b /// Convenience patterns let lemma_non_null (#t:Type) (a:pointer_or_null t) : Lemma (requires (a =!= null)) (ensures (len a = 1ul)) [SMTPat (len a)] = null_unique a /// Convenience operators unfold let (.[]) (s:list 'a) (n:nat{n < length s}) = index s n unfold let (~.) (#t:Type) (a:t) : Tot (erased (list t)) = [a] unfold let (^+) (#t:Type) (a:t) (b:erased (list t)) : Tot (erased (list t)) = Cons a b unfold let (+^) (#t:Type) (a:erased (list t)) (b:t) : Tot (erased (list t)) = append a [b] unfold let (^@^) (#t:Type) (a:erased (list t)) (b:erased (list t)) : Tot (erased (list t)) = append a b unfold let (@) (a:pointer 't) (h0:heap) = B.get h0 a 0 unfold let (^@) (a:pointer_or_null 't{a =!= null}) (h0:heap) = B.get h0 a 0 /// All the data structures #set-options "--__no_positivity" unopteq (** Node of a doubly linked list *) type node (t:Type0) = { (* forward link *) flink: pointer_or_null (node t); (* backward link *) blink: pointer_or_null (node t); (* payload *) p: t; } #reset-options private type nodelist t = list (pointer (node t)) unopteq (** Doubly linked list head *) type dll (t:Type0) ={ lhead: pointer_or_null (node t); ltail: pointer_or_null (node t); nodes: erased (nodelist t); } type nonempty_dll t = (h:dll t{h.lhead =!= null /\ h.ltail =!= null}) unopteq private (** An "almost valid" dll *) type piece t = { phead: pointer (node t); ptail: pointer (node t); pnodes: erased (nodelist t); } unopteq private (** An intermediate for when linked lists are being formed or destroyed *) type fragment t = | Frag0 : fragment t | Frag1 : piece t -> fragment t | Frag2 : piece t -> piece t -> fragment t | Frag3 : piece t -> piece t -> piece t -> fragment t /// Some useful empty initializers (** Initialize an element of a doubly linked list *) val empty_node: #t:Type -> payload:t -> node t let empty_node #t payload = { flink = null ; blink = null ; p = payload } (** Initialize a doubly linked list head *) val empty_list: #t:Type -> dll t let empty_list #t = { lhead = null ; ltail = null ; nodes = [] } /// Convenience wrappers for writing properties on fragments let fragment_for_each0 (#t:Type) (pr:piece t -> GTot Type0) (f:fragment t) : GTot Type0 = match f with | Frag0 -> True | Frag1 p1 -> pr p1 | Frag2 p1 p2 -> pr p1 /\ pr p2 | Frag3 p1 p2 p3 -> pr p1 /\ pr p2 /\ pr p3 let fragment_for_each1 (#t:Type) (#u:Type) (pr:u -> piece t -> GTot Type0) (v:u) (f:fragment t) : GTot Type0 = match f with | Frag0 -> True | Frag1 p1 -> pr v p1 | Frag2 p1 p2 -> pr v p1 /\ pr v p2 | Frag3 p1 p2 p3 -> pr v p1 /\ pr v p2 /\ pr v p3 let fragment_length (#t:Type) (f:fragment t) : GTot int = match f with | Frag0 -> 0 | Frag1 _ -> 1 | Frag2 _ _ -> 2 | Frag3 _ _ _ -> 3 /// Ghostly connections let dll_ghostly_connections (#t:Type) (d:dll t) : GTot Type0 = let nodes = d.nodes in match length nodes with | 0 -> d.lhead == null /\ d.ltail == null | _ -> d.lhead =!= null /\ d.ltail =!= null /\ d.lhead == hd nodes /\ d.ltail == last nodes let piece_ghostly_connections (#t:Type) (p:piece t) : GTot Type0 = let nodes = p.pnodes in match length nodes with | 0 -> False | _ -> p.phead == hd nodes /\ p.ptail == last nodes let rec fragment_ghostly_connections (#t:Type) (f:fragment t) : GTot Type0 = fragment_for_each0 piece_ghostly_connections f /// Containment properties /// /// WARNING: [@@] and [^@] require containment to reasonably talk about /// what they do. let rec nodelist_contained0 (#t:Type) (h0:heap) (nl:nodelist t) : GTot Type0 = match nl with | [] -> True | n :: ns -> h0 `contains` n /\ nodelist_contained0 h0 ns let rec nodelist_contained (#t:Type) (h0:heap) (nl:nodelist t) : GTot Type0 = nodelist_contained0 h0 nl let dll_contained (#t:Type) (h0:heap) (d:dll t) : GTot Type0 = h0 `contains` d.lhead /\ h0 `contains` d.ltail /\ nodelist_contained h0 d.nodes let piece_contained (#t:Type) (h0:heap) (p:piece t) : GTot Type0 = h0 `contains` p.phead /\ h0 `contains` p.ptail /\ nodelist_contained h0 p.pnodes let rec fragment_contained (#t:Type) (h0:heap) (f:fragment t) : GTot Type0 = fragment_for_each1 piece_contained h0 f /// Footprints let node_fp_f (#t:Type) (n:node t) : GTot Mod.loc = Mod.loc_buffer n.flink let node_fp_b (#t:Type) (n:node t) : GTot Mod.loc = Mod.loc_buffer n.blink let rec nodelist_fp0 (#t:Type) (n:nodelist t) : GTot Mod.loc = match n with | [] -> Mod.loc_none | n :: ns -> Mod.loc_union (Mod.loc_buffer n) (nodelist_fp0 ns) let rec nodelist_fp_f (#t:Type) (h0:heap) (n:nodelist t) : GTot Mod.loc = match n with | [] -> Mod.loc_none | n :: ns -> Mod.loc_union (Mod.loc_buffer (n@h0).flink) (nodelist_fp_f h0 ns) let rec nodelist_fp_b (#t:Type) (h0:heap) (n:nodelist t) : GTot Mod.loc = match n with | [] -> Mod.loc_none | n :: ns -> Mod.loc_union (Mod.loc_buffer (n@h0).blink) (nodelist_fp_b h0 ns) let dll_fp0 (#t:Type) (d:dll t) : GTot Mod.loc = Mod.loc_union // ghostly connections should give us this union for // free, but still useful to have (Mod.loc_union (Mod.loc_buffer d.lhead) (Mod.loc_buffer d.ltail)) (nodelist_fp0 d.nodes) let dll_fp_f (#t:Type) (h0:heap) (d:dll t) : GTot Mod.loc = let a = if g_is_null d.lhead then Mod.loc_none else Mod.loc_buffer (d.lhead^@h0).flink in let b = if g_is_null d.ltail then Mod.loc_none else Mod.loc_buffer (d.ltail^@h0).flink in Mod.loc_union // ghostly connections should give us this union for // free, but still useful to have (Mod.loc_union a b) (nodelist_fp_f h0 d.nodes) let dll_fp_b (#t:Type) (h0:heap) (d:dll t) : GTot Mod.loc = let a = if g_is_null d.lhead then Mod.loc_none else Mod.loc_buffer (d.lhead^@h0).blink in let b = if g_is_null d.ltail then Mod.loc_none else Mod.loc_buffer (d.ltail^@h0).blink in Mod.loc_union // ghostly connections should give us this union for // free, but still useful to have (Mod.loc_union a b) (nodelist_fp_b h0 d.nodes) let piece_fp0 (#t:Type) (p:piece t) : GTot Mod.loc = Mod.loc_union // ghostly connections should give us this union for // free, but still useful to have (Mod.loc_union (Mod.loc_buffer p.phead) (Mod.loc_buffer p.ptail)) (nodelist_fp0 p.pnodes) let piece_fp_f (#t:Type) (h0:heap) (p:piece t) : GTot Mod.loc = Mod.loc_union // ghostly connections should give us this union for // free, but still useful to have (Mod.loc_union (Mod.loc_buffer (p.phead@h0).flink) (Mod.loc_buffer (p.ptail@h0).flink)) (nodelist_fp_f h0 p.pnodes) let piece_fp_b (#t:Type) (h0:heap) (p:piece t) : GTot Mod.loc = Mod.loc_union // ghostly connections should give us this union for // free, but still useful to have (Mod.loc_union (Mod.loc_buffer (p.phead@h0).blink) (Mod.loc_buffer (p.ptail@h0).blink)) (nodelist_fp_b h0 p.pnodes) let rec fragment_fp0 (#t:Type) (f:fragment t) : GTot Mod.loc = match f with | Frag0 -> Mod.loc_none | Frag1 p1 -> piece_fp0 p1 | Frag2 p1 p2 -> Mod.loc_union (piece_fp0 p1) (piece_fp0 p2) | Frag3 p1 p2 p3 -> Mod.loc_union (piece_fp0 p1) (Mod.loc_union (piece_fp0 p2) (piece_fp0 p3)) /// Helper patterns for footprints let loc_includes_union_l_nodelist_fp0 (#t: Type) (s1 s2:loc) (nl:nodelist t) : Lemma (requires (loc_includes s1 (nodelist_fp0 nl) \/ loc_includes s2 (nodelist_fp0 nl))) (ensures (loc_includes (loc_union s1 s2) (nodelist_fp0 nl))) [SMTPat (loc_includes (loc_union s1 s2) (nodelist_fp0 nl))] = loc_includes_union_l s1 s2 (nodelist_fp0 nl) let loc_includes_union_l_dll_fp0 (#t: Type) (s1 s2:loc) (d:dll t) : Lemma (requires (loc_includes s1 (dll_fp0 d) \/ loc_includes s2 (dll_fp0 d))) (ensures (loc_includes (loc_union s1 s2) (dll_fp0 d))) [SMTPat (loc_includes (loc_union s1 s2) (dll_fp0 d))] = loc_includes_union_l s1 s2 (dll_fp0 d) let loc_includes_union_l_piece_fp0 (#t: Type) (s1 s2:loc) (p:piece t) : Lemma (requires (loc_includes s1 (piece_fp0 p) \/ loc_includes s2 (piece_fp0 p))) (ensures (loc_includes (loc_union s1 s2) (piece_fp0 p))) [SMTPat (loc_includes (loc_union s1 s2) (piece_fp0 p))] = loc_includes_union_l s1 s2 (piece_fp0 p) let loc_includes_union_l_fragment_fp0 (#t: Type) (s1 s2:loc) (f:fragment t) : Lemma (requires (loc_includes s1 (fragment_fp0 f) \/ loc_includes s2 (fragment_fp0 f))) (ensures (loc_includes (loc_union s1 s2) (fragment_fp0 f))) [SMTPat (loc_includes (loc_union s1 s2) (fragment_fp0 f))] = loc_includes_union_l s1 s2 (fragment_fp0 f) /// Equivalence for locations let loc_equiv (a b:Mod.loc) = Mod.loc_includes a b /\ Mod.loc_includes b a let loc_equiv_trans (a b c:Mod.loc) : Lemma (requires (loc_equiv a b /\ loc_equiv b c)) (ensures (loc_equiv a c)) [SMTPat (loc_equiv a b); SMTPat (loc_equiv b c); SMTPat (loc_equiv a c)] = Mod.loc_includes_trans a b c; Mod.loc_includes_trans c b a let loc_equiv_union_union_loc (a b c:Mod.loc) : Lemma (requires (loc_equiv b c)) (ensures (loc_equiv (Mod.loc_union a b) (Mod.loc_union a c))) [SMTPat (loc_equiv (Mod.loc_union a b) (Mod.loc_union a c))] = let incl = Mod.loc_includes in let u = Mod.loc_union in // assert (b `incl` c); Mod.loc_includes_union_l a b c; // assert ((a `u` b) `incl` c); Mod.loc_includes_union_l a b a; // assert ((a `u` b) `incl` a); // assert ((a `u` b) `incl` (a `u` c)); Mod.loc_includes_union_l a c b; Mod.loc_includes_union_l a c a /// Anti aliasing properties let node_aa (#t:Type) (n:node t) : GTot Type0 = Mod.loc_disjoint (node_fp_f n) (node_fp_b n) let rec nodelist_aa_r (#t:Type) (nl:nodelist t) : GTot Type0 = match nl with | [] -> True | n :: ns -> Mod.loc_disjoint (Mod.loc_buffer n) (nodelist_fp0 ns) /\ nodelist_aa_r ns let rec nodelist_aa_l (#t:Type) (nl:nodelist t) : GTot Type0 (decreases (length nl)) = match nl with | [] -> True | _ -> let ns, n = unsnoc nl in lemma_unsnoc_length nl; Mod.loc_disjoint (Mod.loc_buffer n) (nodelist_fp0 ns) /\ nodelist_aa_l ns let nodelist_aa (#t:Type) (nl:nodelist t) : GTot Type0 = nodelist_aa_l nl /\ nodelist_aa_r nl
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowStar.ModifiesPat.fst.checked", "LowStar.Modifies.fst.checked", "LowStar.BufferOps.fst.checked", "LowStar.Buffer.fst.checked", "FStar.UInt32.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked", "FStar.List.Pure.Properties.fst.checked", "FStar.List.Pure.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked", "FStar.Classical.fsti.checked" ], "interface_file": false, "source_file": "DoublyLinkedList.fst" }
[ { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": true, "full_module": "LowStar.Modifies", "short_module": "Mod" }, { "abbrev": false, "full_module": "LowStar.BufferOps", "short_module": null }, { "abbrev": false, "full_module": "FStar.List.Pure", "short_module": null }, { "abbrev": false, "full_module": "FStar.List.Tot", "short_module": null }, { "abbrev": false, "full_module": "LowStar.ModifiesPat", "short_module": null }, { "abbrev": false, "full_module": "FStar.Ghost", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
d: DoublyLinkedList.dll t -> Prims.GTot Type0
Prims.GTot
[ "sometrivial" ]
[]
[ "DoublyLinkedList.dll", "DoublyLinkedList.nodelist_aa", "FStar.Ghost.reveal", "DoublyLinkedList.nodelist", "DoublyLinkedList.__proj__Mkdll__item__nodes" ]
[]
false
false
false
false
true
let dll_aa (#t: Type) (d: dll t) : GTot Type0 =
nodelist_aa d.nodes
false
DoublyLinkedList.fst
DoublyLinkedList.nodelist_aa
val nodelist_aa (#t: Type) (nl: nodelist t) : GTot Type0
val nodelist_aa (#t: Type) (nl: nodelist t) : GTot Type0
let nodelist_aa (#t:Type) (nl:nodelist t) : GTot Type0 = nodelist_aa_l nl /\ nodelist_aa_r nl
{ "file_name": "examples/doublylinkedlist/DoublyLinkedList.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 38, "end_line": 328, "start_col": 0, "start_line": 327 }
(* Copyright 2008-2019 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module DoublyLinkedList open FStar open FStar.HyperStack.ST open FStar.Ghost open LowStar.ModifiesPat open FStar.List.Tot open FStar.List.Pure open LowStar.BufferOps module Mod = LowStar.Modifies module ST = FStar.HyperStack.ST module HS = FStar.HyperStack module B = LowStar.Buffer /// Convenience renaming unfold let heap = HS.mem unfold let contains #a #rrel #rel h b = B.live #a #rrel #rel h b /// Convenience patterns let lemma_non_null (#t:Type) (a:pointer_or_null t) : Lemma (requires (a =!= null)) (ensures (len a = 1ul)) [SMTPat (len a)] = null_unique a /// Convenience operators unfold let (.[]) (s:list 'a) (n:nat{n < length s}) = index s n unfold let (~.) (#t:Type) (a:t) : Tot (erased (list t)) = [a] unfold let (^+) (#t:Type) (a:t) (b:erased (list t)) : Tot (erased (list t)) = Cons a b unfold let (+^) (#t:Type) (a:erased (list t)) (b:t) : Tot (erased (list t)) = append a [b] unfold let (^@^) (#t:Type) (a:erased (list t)) (b:erased (list t)) : Tot (erased (list t)) = append a b unfold let (@) (a:pointer 't) (h0:heap) = B.get h0 a 0 unfold let (^@) (a:pointer_or_null 't{a =!= null}) (h0:heap) = B.get h0 a 0 /// All the data structures #set-options "--__no_positivity" unopteq (** Node of a doubly linked list *) type node (t:Type0) = { (* forward link *) flink: pointer_or_null (node t); (* backward link *) blink: pointer_or_null (node t); (* payload *) p: t; } #reset-options private type nodelist t = list (pointer (node t)) unopteq (** Doubly linked list head *) type dll (t:Type0) ={ lhead: pointer_or_null (node t); ltail: pointer_or_null (node t); nodes: erased (nodelist t); } type nonempty_dll t = (h:dll t{h.lhead =!= null /\ h.ltail =!= null}) unopteq private (** An "almost valid" dll *) type piece t = { phead: pointer (node t); ptail: pointer (node t); pnodes: erased (nodelist t); } unopteq private (** An intermediate for when linked lists are being formed or destroyed *) type fragment t = | Frag0 : fragment t | Frag1 : piece t -> fragment t | Frag2 : piece t -> piece t -> fragment t | Frag3 : piece t -> piece t -> piece t -> fragment t /// Some useful empty initializers (** Initialize an element of a doubly linked list *) val empty_node: #t:Type -> payload:t -> node t let empty_node #t payload = { flink = null ; blink = null ; p = payload } (** Initialize a doubly linked list head *) val empty_list: #t:Type -> dll t let empty_list #t = { lhead = null ; ltail = null ; nodes = [] } /// Convenience wrappers for writing properties on fragments let fragment_for_each0 (#t:Type) (pr:piece t -> GTot Type0) (f:fragment t) : GTot Type0 = match f with | Frag0 -> True | Frag1 p1 -> pr p1 | Frag2 p1 p2 -> pr p1 /\ pr p2 | Frag3 p1 p2 p3 -> pr p1 /\ pr p2 /\ pr p3 let fragment_for_each1 (#t:Type) (#u:Type) (pr:u -> piece t -> GTot Type0) (v:u) (f:fragment t) : GTot Type0 = match f with | Frag0 -> True | Frag1 p1 -> pr v p1 | Frag2 p1 p2 -> pr v p1 /\ pr v p2 | Frag3 p1 p2 p3 -> pr v p1 /\ pr v p2 /\ pr v p3 let fragment_length (#t:Type) (f:fragment t) : GTot int = match f with | Frag0 -> 0 | Frag1 _ -> 1 | Frag2 _ _ -> 2 | Frag3 _ _ _ -> 3 /// Ghostly connections let dll_ghostly_connections (#t:Type) (d:dll t) : GTot Type0 = let nodes = d.nodes in match length nodes with | 0 -> d.lhead == null /\ d.ltail == null | _ -> d.lhead =!= null /\ d.ltail =!= null /\ d.lhead == hd nodes /\ d.ltail == last nodes let piece_ghostly_connections (#t:Type) (p:piece t) : GTot Type0 = let nodes = p.pnodes in match length nodes with | 0 -> False | _ -> p.phead == hd nodes /\ p.ptail == last nodes let rec fragment_ghostly_connections (#t:Type) (f:fragment t) : GTot Type0 = fragment_for_each0 piece_ghostly_connections f /// Containment properties /// /// WARNING: [@@] and [^@] require containment to reasonably talk about /// what they do. let rec nodelist_contained0 (#t:Type) (h0:heap) (nl:nodelist t) : GTot Type0 = match nl with | [] -> True | n :: ns -> h0 `contains` n /\ nodelist_contained0 h0 ns let rec nodelist_contained (#t:Type) (h0:heap) (nl:nodelist t) : GTot Type0 = nodelist_contained0 h0 nl let dll_contained (#t:Type) (h0:heap) (d:dll t) : GTot Type0 = h0 `contains` d.lhead /\ h0 `contains` d.ltail /\ nodelist_contained h0 d.nodes let piece_contained (#t:Type) (h0:heap) (p:piece t) : GTot Type0 = h0 `contains` p.phead /\ h0 `contains` p.ptail /\ nodelist_contained h0 p.pnodes let rec fragment_contained (#t:Type) (h0:heap) (f:fragment t) : GTot Type0 = fragment_for_each1 piece_contained h0 f /// Footprints let node_fp_f (#t:Type) (n:node t) : GTot Mod.loc = Mod.loc_buffer n.flink let node_fp_b (#t:Type) (n:node t) : GTot Mod.loc = Mod.loc_buffer n.blink let rec nodelist_fp0 (#t:Type) (n:nodelist t) : GTot Mod.loc = match n with | [] -> Mod.loc_none | n :: ns -> Mod.loc_union (Mod.loc_buffer n) (nodelist_fp0 ns) let rec nodelist_fp_f (#t:Type) (h0:heap) (n:nodelist t) : GTot Mod.loc = match n with | [] -> Mod.loc_none | n :: ns -> Mod.loc_union (Mod.loc_buffer (n@h0).flink) (nodelist_fp_f h0 ns) let rec nodelist_fp_b (#t:Type) (h0:heap) (n:nodelist t) : GTot Mod.loc = match n with | [] -> Mod.loc_none | n :: ns -> Mod.loc_union (Mod.loc_buffer (n@h0).blink) (nodelist_fp_b h0 ns) let dll_fp0 (#t:Type) (d:dll t) : GTot Mod.loc = Mod.loc_union // ghostly connections should give us this union for // free, but still useful to have (Mod.loc_union (Mod.loc_buffer d.lhead) (Mod.loc_buffer d.ltail)) (nodelist_fp0 d.nodes) let dll_fp_f (#t:Type) (h0:heap) (d:dll t) : GTot Mod.loc = let a = if g_is_null d.lhead then Mod.loc_none else Mod.loc_buffer (d.lhead^@h0).flink in let b = if g_is_null d.ltail then Mod.loc_none else Mod.loc_buffer (d.ltail^@h0).flink in Mod.loc_union // ghostly connections should give us this union for // free, but still useful to have (Mod.loc_union a b) (nodelist_fp_f h0 d.nodes) let dll_fp_b (#t:Type) (h0:heap) (d:dll t) : GTot Mod.loc = let a = if g_is_null d.lhead then Mod.loc_none else Mod.loc_buffer (d.lhead^@h0).blink in let b = if g_is_null d.ltail then Mod.loc_none else Mod.loc_buffer (d.ltail^@h0).blink in Mod.loc_union // ghostly connections should give us this union for // free, but still useful to have (Mod.loc_union a b) (nodelist_fp_b h0 d.nodes) let piece_fp0 (#t:Type) (p:piece t) : GTot Mod.loc = Mod.loc_union // ghostly connections should give us this union for // free, but still useful to have (Mod.loc_union (Mod.loc_buffer p.phead) (Mod.loc_buffer p.ptail)) (nodelist_fp0 p.pnodes) let piece_fp_f (#t:Type) (h0:heap) (p:piece t) : GTot Mod.loc = Mod.loc_union // ghostly connections should give us this union for // free, but still useful to have (Mod.loc_union (Mod.loc_buffer (p.phead@h0).flink) (Mod.loc_buffer (p.ptail@h0).flink)) (nodelist_fp_f h0 p.pnodes) let piece_fp_b (#t:Type) (h0:heap) (p:piece t) : GTot Mod.loc = Mod.loc_union // ghostly connections should give us this union for // free, but still useful to have (Mod.loc_union (Mod.loc_buffer (p.phead@h0).blink) (Mod.loc_buffer (p.ptail@h0).blink)) (nodelist_fp_b h0 p.pnodes) let rec fragment_fp0 (#t:Type) (f:fragment t) : GTot Mod.loc = match f with | Frag0 -> Mod.loc_none | Frag1 p1 -> piece_fp0 p1 | Frag2 p1 p2 -> Mod.loc_union (piece_fp0 p1) (piece_fp0 p2) | Frag3 p1 p2 p3 -> Mod.loc_union (piece_fp0 p1) (Mod.loc_union (piece_fp0 p2) (piece_fp0 p3)) /// Helper patterns for footprints let loc_includes_union_l_nodelist_fp0 (#t: Type) (s1 s2:loc) (nl:nodelist t) : Lemma (requires (loc_includes s1 (nodelist_fp0 nl) \/ loc_includes s2 (nodelist_fp0 nl))) (ensures (loc_includes (loc_union s1 s2) (nodelist_fp0 nl))) [SMTPat (loc_includes (loc_union s1 s2) (nodelist_fp0 nl))] = loc_includes_union_l s1 s2 (nodelist_fp0 nl) let loc_includes_union_l_dll_fp0 (#t: Type) (s1 s2:loc) (d:dll t) : Lemma (requires (loc_includes s1 (dll_fp0 d) \/ loc_includes s2 (dll_fp0 d))) (ensures (loc_includes (loc_union s1 s2) (dll_fp0 d))) [SMTPat (loc_includes (loc_union s1 s2) (dll_fp0 d))] = loc_includes_union_l s1 s2 (dll_fp0 d) let loc_includes_union_l_piece_fp0 (#t: Type) (s1 s2:loc) (p:piece t) : Lemma (requires (loc_includes s1 (piece_fp0 p) \/ loc_includes s2 (piece_fp0 p))) (ensures (loc_includes (loc_union s1 s2) (piece_fp0 p))) [SMTPat (loc_includes (loc_union s1 s2) (piece_fp0 p))] = loc_includes_union_l s1 s2 (piece_fp0 p) let loc_includes_union_l_fragment_fp0 (#t: Type) (s1 s2:loc) (f:fragment t) : Lemma (requires (loc_includes s1 (fragment_fp0 f) \/ loc_includes s2 (fragment_fp0 f))) (ensures (loc_includes (loc_union s1 s2) (fragment_fp0 f))) [SMTPat (loc_includes (loc_union s1 s2) (fragment_fp0 f))] = loc_includes_union_l s1 s2 (fragment_fp0 f) /// Equivalence for locations let loc_equiv (a b:Mod.loc) = Mod.loc_includes a b /\ Mod.loc_includes b a let loc_equiv_trans (a b c:Mod.loc) : Lemma (requires (loc_equiv a b /\ loc_equiv b c)) (ensures (loc_equiv a c)) [SMTPat (loc_equiv a b); SMTPat (loc_equiv b c); SMTPat (loc_equiv a c)] = Mod.loc_includes_trans a b c; Mod.loc_includes_trans c b a let loc_equiv_union_union_loc (a b c:Mod.loc) : Lemma (requires (loc_equiv b c)) (ensures (loc_equiv (Mod.loc_union a b) (Mod.loc_union a c))) [SMTPat (loc_equiv (Mod.loc_union a b) (Mod.loc_union a c))] = let incl = Mod.loc_includes in let u = Mod.loc_union in // assert (b `incl` c); Mod.loc_includes_union_l a b c; // assert ((a `u` b) `incl` c); Mod.loc_includes_union_l a b a; // assert ((a `u` b) `incl` a); // assert ((a `u` b) `incl` (a `u` c)); Mod.loc_includes_union_l a c b; Mod.loc_includes_union_l a c a /// Anti aliasing properties let node_aa (#t:Type) (n:node t) : GTot Type0 = Mod.loc_disjoint (node_fp_f n) (node_fp_b n) let rec nodelist_aa_r (#t:Type) (nl:nodelist t) : GTot Type0 = match nl with | [] -> True | n :: ns -> Mod.loc_disjoint (Mod.loc_buffer n) (nodelist_fp0 ns) /\ nodelist_aa_r ns let rec nodelist_aa_l (#t:Type) (nl:nodelist t) : GTot Type0 (decreases (length nl)) = match nl with | [] -> True | _ -> let ns, n = unsnoc nl in lemma_unsnoc_length nl; Mod.loc_disjoint (Mod.loc_buffer n) (nodelist_fp0 ns) /\
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowStar.ModifiesPat.fst.checked", "LowStar.Modifies.fst.checked", "LowStar.BufferOps.fst.checked", "LowStar.Buffer.fst.checked", "FStar.UInt32.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked", "FStar.List.Pure.Properties.fst.checked", "FStar.List.Pure.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked", "FStar.Classical.fsti.checked" ], "interface_file": false, "source_file": "DoublyLinkedList.fst" }
[ { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": true, "full_module": "LowStar.Modifies", "short_module": "Mod" }, { "abbrev": false, "full_module": "LowStar.BufferOps", "short_module": null }, { "abbrev": false, "full_module": "FStar.List.Pure", "short_module": null }, { "abbrev": false, "full_module": "FStar.List.Tot", "short_module": null }, { "abbrev": false, "full_module": "LowStar.ModifiesPat", "short_module": null }, { "abbrev": false, "full_module": "FStar.Ghost", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
nl: DoublyLinkedList.nodelist t -> Prims.GTot Type0
Prims.GTot
[ "sometrivial" ]
[]
[ "DoublyLinkedList.nodelist", "Prims.l_and", "DoublyLinkedList.nodelist_aa_l", "DoublyLinkedList.nodelist_aa_r" ]
[]
false
false
false
false
true
let nodelist_aa (#t: Type) (nl: nodelist t) : GTot Type0 =
nodelist_aa_l nl /\ nodelist_aa_r nl
false
DoublyLinkedList.fst
DoublyLinkedList.loc_equiv
val loc_equiv : a: LowStar.Monotonic.Buffer.loc -> b: LowStar.Monotonic.Buffer.loc -> Prims.logical
let loc_equiv (a b:Mod.loc) = Mod.loc_includes a b /\ Mod.loc_includes b a
{ "file_name": "examples/doublylinkedlist/DoublyLinkedList.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 74, "end_line": 277, "start_col": 0, "start_line": 277 }
(* Copyright 2008-2019 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module DoublyLinkedList open FStar open FStar.HyperStack.ST open FStar.Ghost open LowStar.ModifiesPat open FStar.List.Tot open FStar.List.Pure open LowStar.BufferOps module Mod = LowStar.Modifies module ST = FStar.HyperStack.ST module HS = FStar.HyperStack module B = LowStar.Buffer /// Convenience renaming unfold let heap = HS.mem unfold let contains #a #rrel #rel h b = B.live #a #rrel #rel h b /// Convenience patterns let lemma_non_null (#t:Type) (a:pointer_or_null t) : Lemma (requires (a =!= null)) (ensures (len a = 1ul)) [SMTPat (len a)] = null_unique a /// Convenience operators unfold let (.[]) (s:list 'a) (n:nat{n < length s}) = index s n unfold let (~.) (#t:Type) (a:t) : Tot (erased (list t)) = [a] unfold let (^+) (#t:Type) (a:t) (b:erased (list t)) : Tot (erased (list t)) = Cons a b unfold let (+^) (#t:Type) (a:erased (list t)) (b:t) : Tot (erased (list t)) = append a [b] unfold let (^@^) (#t:Type) (a:erased (list t)) (b:erased (list t)) : Tot (erased (list t)) = append a b unfold let (@) (a:pointer 't) (h0:heap) = B.get h0 a 0 unfold let (^@) (a:pointer_or_null 't{a =!= null}) (h0:heap) = B.get h0 a 0 /// All the data structures #set-options "--__no_positivity" unopteq (** Node of a doubly linked list *) type node (t:Type0) = { (* forward link *) flink: pointer_or_null (node t); (* backward link *) blink: pointer_or_null (node t); (* payload *) p: t; } #reset-options private type nodelist t = list (pointer (node t)) unopteq (** Doubly linked list head *) type dll (t:Type0) ={ lhead: pointer_or_null (node t); ltail: pointer_or_null (node t); nodes: erased (nodelist t); } type nonempty_dll t = (h:dll t{h.lhead =!= null /\ h.ltail =!= null}) unopteq private (** An "almost valid" dll *) type piece t = { phead: pointer (node t); ptail: pointer (node t); pnodes: erased (nodelist t); } unopteq private (** An intermediate for when linked lists are being formed or destroyed *) type fragment t = | Frag0 : fragment t | Frag1 : piece t -> fragment t | Frag2 : piece t -> piece t -> fragment t | Frag3 : piece t -> piece t -> piece t -> fragment t /// Some useful empty initializers (** Initialize an element of a doubly linked list *) val empty_node: #t:Type -> payload:t -> node t let empty_node #t payload = { flink = null ; blink = null ; p = payload } (** Initialize a doubly linked list head *) val empty_list: #t:Type -> dll t let empty_list #t = { lhead = null ; ltail = null ; nodes = [] } /// Convenience wrappers for writing properties on fragments let fragment_for_each0 (#t:Type) (pr:piece t -> GTot Type0) (f:fragment t) : GTot Type0 = match f with | Frag0 -> True | Frag1 p1 -> pr p1 | Frag2 p1 p2 -> pr p1 /\ pr p2 | Frag3 p1 p2 p3 -> pr p1 /\ pr p2 /\ pr p3 let fragment_for_each1 (#t:Type) (#u:Type) (pr:u -> piece t -> GTot Type0) (v:u) (f:fragment t) : GTot Type0 = match f with | Frag0 -> True | Frag1 p1 -> pr v p1 | Frag2 p1 p2 -> pr v p1 /\ pr v p2 | Frag3 p1 p2 p3 -> pr v p1 /\ pr v p2 /\ pr v p3 let fragment_length (#t:Type) (f:fragment t) : GTot int = match f with | Frag0 -> 0 | Frag1 _ -> 1 | Frag2 _ _ -> 2 | Frag3 _ _ _ -> 3 /// Ghostly connections let dll_ghostly_connections (#t:Type) (d:dll t) : GTot Type0 = let nodes = d.nodes in match length nodes with | 0 -> d.lhead == null /\ d.ltail == null | _ -> d.lhead =!= null /\ d.ltail =!= null /\ d.lhead == hd nodes /\ d.ltail == last nodes let piece_ghostly_connections (#t:Type) (p:piece t) : GTot Type0 = let nodes = p.pnodes in match length nodes with | 0 -> False | _ -> p.phead == hd nodes /\ p.ptail == last nodes let rec fragment_ghostly_connections (#t:Type) (f:fragment t) : GTot Type0 = fragment_for_each0 piece_ghostly_connections f /// Containment properties /// /// WARNING: [@@] and [^@] require containment to reasonably talk about /// what they do. let rec nodelist_contained0 (#t:Type) (h0:heap) (nl:nodelist t) : GTot Type0 = match nl with | [] -> True | n :: ns -> h0 `contains` n /\ nodelist_contained0 h0 ns let rec nodelist_contained (#t:Type) (h0:heap) (nl:nodelist t) : GTot Type0 = nodelist_contained0 h0 nl let dll_contained (#t:Type) (h0:heap) (d:dll t) : GTot Type0 = h0 `contains` d.lhead /\ h0 `contains` d.ltail /\ nodelist_contained h0 d.nodes let piece_contained (#t:Type) (h0:heap) (p:piece t) : GTot Type0 = h0 `contains` p.phead /\ h0 `contains` p.ptail /\ nodelist_contained h0 p.pnodes let rec fragment_contained (#t:Type) (h0:heap) (f:fragment t) : GTot Type0 = fragment_for_each1 piece_contained h0 f /// Footprints let node_fp_f (#t:Type) (n:node t) : GTot Mod.loc = Mod.loc_buffer n.flink let node_fp_b (#t:Type) (n:node t) : GTot Mod.loc = Mod.loc_buffer n.blink let rec nodelist_fp0 (#t:Type) (n:nodelist t) : GTot Mod.loc = match n with | [] -> Mod.loc_none | n :: ns -> Mod.loc_union (Mod.loc_buffer n) (nodelist_fp0 ns) let rec nodelist_fp_f (#t:Type) (h0:heap) (n:nodelist t) : GTot Mod.loc = match n with | [] -> Mod.loc_none | n :: ns -> Mod.loc_union (Mod.loc_buffer (n@h0).flink) (nodelist_fp_f h0 ns) let rec nodelist_fp_b (#t:Type) (h0:heap) (n:nodelist t) : GTot Mod.loc = match n with | [] -> Mod.loc_none | n :: ns -> Mod.loc_union (Mod.loc_buffer (n@h0).blink) (nodelist_fp_b h0 ns) let dll_fp0 (#t:Type) (d:dll t) : GTot Mod.loc = Mod.loc_union // ghostly connections should give us this union for // free, but still useful to have (Mod.loc_union (Mod.loc_buffer d.lhead) (Mod.loc_buffer d.ltail)) (nodelist_fp0 d.nodes) let dll_fp_f (#t:Type) (h0:heap) (d:dll t) : GTot Mod.loc = let a = if g_is_null d.lhead then Mod.loc_none else Mod.loc_buffer (d.lhead^@h0).flink in let b = if g_is_null d.ltail then Mod.loc_none else Mod.loc_buffer (d.ltail^@h0).flink in Mod.loc_union // ghostly connections should give us this union for // free, but still useful to have (Mod.loc_union a b) (nodelist_fp_f h0 d.nodes) let dll_fp_b (#t:Type) (h0:heap) (d:dll t) : GTot Mod.loc = let a = if g_is_null d.lhead then Mod.loc_none else Mod.loc_buffer (d.lhead^@h0).blink in let b = if g_is_null d.ltail then Mod.loc_none else Mod.loc_buffer (d.ltail^@h0).blink in Mod.loc_union // ghostly connections should give us this union for // free, but still useful to have (Mod.loc_union a b) (nodelist_fp_b h0 d.nodes) let piece_fp0 (#t:Type) (p:piece t) : GTot Mod.loc = Mod.loc_union // ghostly connections should give us this union for // free, but still useful to have (Mod.loc_union (Mod.loc_buffer p.phead) (Mod.loc_buffer p.ptail)) (nodelist_fp0 p.pnodes) let piece_fp_f (#t:Type) (h0:heap) (p:piece t) : GTot Mod.loc = Mod.loc_union // ghostly connections should give us this union for // free, but still useful to have (Mod.loc_union (Mod.loc_buffer (p.phead@h0).flink) (Mod.loc_buffer (p.ptail@h0).flink)) (nodelist_fp_f h0 p.pnodes) let piece_fp_b (#t:Type) (h0:heap) (p:piece t) : GTot Mod.loc = Mod.loc_union // ghostly connections should give us this union for // free, but still useful to have (Mod.loc_union (Mod.loc_buffer (p.phead@h0).blink) (Mod.loc_buffer (p.ptail@h0).blink)) (nodelist_fp_b h0 p.pnodes) let rec fragment_fp0 (#t:Type) (f:fragment t) : GTot Mod.loc = match f with | Frag0 -> Mod.loc_none | Frag1 p1 -> piece_fp0 p1 | Frag2 p1 p2 -> Mod.loc_union (piece_fp0 p1) (piece_fp0 p2) | Frag3 p1 p2 p3 -> Mod.loc_union (piece_fp0 p1) (Mod.loc_union (piece_fp0 p2) (piece_fp0 p3)) /// Helper patterns for footprints let loc_includes_union_l_nodelist_fp0 (#t: Type) (s1 s2:loc) (nl:nodelist t) : Lemma (requires (loc_includes s1 (nodelist_fp0 nl) \/ loc_includes s2 (nodelist_fp0 nl))) (ensures (loc_includes (loc_union s1 s2) (nodelist_fp0 nl))) [SMTPat (loc_includes (loc_union s1 s2) (nodelist_fp0 nl))] = loc_includes_union_l s1 s2 (nodelist_fp0 nl) let loc_includes_union_l_dll_fp0 (#t: Type) (s1 s2:loc) (d:dll t) : Lemma (requires (loc_includes s1 (dll_fp0 d) \/ loc_includes s2 (dll_fp0 d))) (ensures (loc_includes (loc_union s1 s2) (dll_fp0 d))) [SMTPat (loc_includes (loc_union s1 s2) (dll_fp0 d))] = loc_includes_union_l s1 s2 (dll_fp0 d) let loc_includes_union_l_piece_fp0 (#t: Type) (s1 s2:loc) (p:piece t) : Lemma (requires (loc_includes s1 (piece_fp0 p) \/ loc_includes s2 (piece_fp0 p))) (ensures (loc_includes (loc_union s1 s2) (piece_fp0 p))) [SMTPat (loc_includes (loc_union s1 s2) (piece_fp0 p))] = loc_includes_union_l s1 s2 (piece_fp0 p) let loc_includes_union_l_fragment_fp0 (#t: Type) (s1 s2:loc) (f:fragment t) : Lemma (requires (loc_includes s1 (fragment_fp0 f) \/ loc_includes s2 (fragment_fp0 f))) (ensures (loc_includes (loc_union s1 s2) (fragment_fp0 f))) [SMTPat (loc_includes (loc_union s1 s2) (fragment_fp0 f))] = loc_includes_union_l s1 s2 (fragment_fp0 f) /// Equivalence for locations
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowStar.ModifiesPat.fst.checked", "LowStar.Modifies.fst.checked", "LowStar.BufferOps.fst.checked", "LowStar.Buffer.fst.checked", "FStar.UInt32.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked", "FStar.List.Pure.Properties.fst.checked", "FStar.List.Pure.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked", "FStar.Classical.fsti.checked" ], "interface_file": false, "source_file": "DoublyLinkedList.fst" }
[ { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": true, "full_module": "LowStar.Modifies", "short_module": "Mod" }, { "abbrev": false, "full_module": "LowStar.BufferOps", "short_module": null }, { "abbrev": false, "full_module": "FStar.List.Pure", "short_module": null }, { "abbrev": false, "full_module": "FStar.List.Tot", "short_module": null }, { "abbrev": false, "full_module": "LowStar.ModifiesPat", "short_module": null }, { "abbrev": false, "full_module": "FStar.Ghost", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
a: LowStar.Monotonic.Buffer.loc -> b: LowStar.Monotonic.Buffer.loc -> Prims.logical
Prims.Tot
[ "total" ]
[]
[ "LowStar.Monotonic.Buffer.loc", "Prims.l_and", "LowStar.Monotonic.Buffer.loc_includes", "Prims.logical" ]
[]
false
false
false
true
true
let loc_equiv (a b: Mod.loc) =
Mod.loc_includes a b /\ Mod.loc_includes b a
false
DoublyLinkedList.fst
DoublyLinkedList.empty_node
val empty_node: #t:Type -> payload:t -> node t
val empty_node: #t:Type -> payload:t -> node t
let empty_node #t payload = { flink = null ; blink = null ; p = payload }
{ "file_name": "examples/doublylinkedlist/DoublyLinkedList.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 47, "end_line": 106, "start_col": 0, "start_line": 105 }
(* Copyright 2008-2019 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module DoublyLinkedList open FStar open FStar.HyperStack.ST open FStar.Ghost open LowStar.ModifiesPat open FStar.List.Tot open FStar.List.Pure open LowStar.BufferOps module Mod = LowStar.Modifies module ST = FStar.HyperStack.ST module HS = FStar.HyperStack module B = LowStar.Buffer /// Convenience renaming unfold let heap = HS.mem unfold let contains #a #rrel #rel h b = B.live #a #rrel #rel h b /// Convenience patterns let lemma_non_null (#t:Type) (a:pointer_or_null t) : Lemma (requires (a =!= null)) (ensures (len a = 1ul)) [SMTPat (len a)] = null_unique a /// Convenience operators unfold let (.[]) (s:list 'a) (n:nat{n < length s}) = index s n unfold let (~.) (#t:Type) (a:t) : Tot (erased (list t)) = [a] unfold let (^+) (#t:Type) (a:t) (b:erased (list t)) : Tot (erased (list t)) = Cons a b unfold let (+^) (#t:Type) (a:erased (list t)) (b:t) : Tot (erased (list t)) = append a [b] unfold let (^@^) (#t:Type) (a:erased (list t)) (b:erased (list t)) : Tot (erased (list t)) = append a b unfold let (@) (a:pointer 't) (h0:heap) = B.get h0 a 0 unfold let (^@) (a:pointer_or_null 't{a =!= null}) (h0:heap) = B.get h0 a 0 /// All the data structures #set-options "--__no_positivity" unopteq (** Node of a doubly linked list *) type node (t:Type0) = { (* forward link *) flink: pointer_or_null (node t); (* backward link *) blink: pointer_or_null (node t); (* payload *) p: t; } #reset-options private type nodelist t = list (pointer (node t)) unopteq (** Doubly linked list head *) type dll (t:Type0) ={ lhead: pointer_or_null (node t); ltail: pointer_or_null (node t); nodes: erased (nodelist t); } type nonempty_dll t = (h:dll t{h.lhead =!= null /\ h.ltail =!= null}) unopteq private (** An "almost valid" dll *) type piece t = { phead: pointer (node t); ptail: pointer (node t); pnodes: erased (nodelist t); } unopteq private (** An intermediate for when linked lists are being formed or destroyed *) type fragment t = | Frag0 : fragment t | Frag1 : piece t -> fragment t | Frag2 : piece t -> piece t -> fragment t | Frag3 : piece t -> piece t -> piece t -> fragment t /// Some useful empty initializers (** Initialize an element of a doubly linked list *)
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowStar.ModifiesPat.fst.checked", "LowStar.Modifies.fst.checked", "LowStar.BufferOps.fst.checked", "LowStar.Buffer.fst.checked", "FStar.UInt32.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked", "FStar.List.Pure.Properties.fst.checked", "FStar.List.Pure.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked", "FStar.Classical.fsti.checked" ], "interface_file": false, "source_file": "DoublyLinkedList.fst" }
[ { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": true, "full_module": "LowStar.Modifies", "short_module": "Mod" }, { "abbrev": false, "full_module": "LowStar.BufferOps", "short_module": null }, { "abbrev": false, "full_module": "FStar.List.Pure", "short_module": null }, { "abbrev": false, "full_module": "FStar.List.Tot", "short_module": null }, { "abbrev": false, "full_module": "LowStar.ModifiesPat", "short_module": null }, { "abbrev": false, "full_module": "FStar.Ghost", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
payload: t -> DoublyLinkedList.node t
Prims.Tot
[ "total" ]
[]
[ "DoublyLinkedList.Mknode", "LowStar.Buffer.null", "DoublyLinkedList.node" ]
[]
false
false
false
true
false
let empty_node #t payload =
{ flink = null; blink = null; p = payload }
false
DoublyLinkedList.fst
DoublyLinkedList.piece_aa
val piece_aa (#t: Type) (p: piece t) : GTot Type0
val piece_aa (#t: Type) (p: piece t) : GTot Type0
let piece_aa (#t:Type) (p:piece t) : GTot Type0 = nodelist_aa p.pnodes
{ "file_name": "examples/doublylinkedlist/DoublyLinkedList.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 22, "end_line": 334, "start_col": 0, "start_line": 333 }
(* Copyright 2008-2019 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module DoublyLinkedList open FStar open FStar.HyperStack.ST open FStar.Ghost open LowStar.ModifiesPat open FStar.List.Tot open FStar.List.Pure open LowStar.BufferOps module Mod = LowStar.Modifies module ST = FStar.HyperStack.ST module HS = FStar.HyperStack module B = LowStar.Buffer /// Convenience renaming unfold let heap = HS.mem unfold let contains #a #rrel #rel h b = B.live #a #rrel #rel h b /// Convenience patterns let lemma_non_null (#t:Type) (a:pointer_or_null t) : Lemma (requires (a =!= null)) (ensures (len a = 1ul)) [SMTPat (len a)] = null_unique a /// Convenience operators unfold let (.[]) (s:list 'a) (n:nat{n < length s}) = index s n unfold let (~.) (#t:Type) (a:t) : Tot (erased (list t)) = [a] unfold let (^+) (#t:Type) (a:t) (b:erased (list t)) : Tot (erased (list t)) = Cons a b unfold let (+^) (#t:Type) (a:erased (list t)) (b:t) : Tot (erased (list t)) = append a [b] unfold let (^@^) (#t:Type) (a:erased (list t)) (b:erased (list t)) : Tot (erased (list t)) = append a b unfold let (@) (a:pointer 't) (h0:heap) = B.get h0 a 0 unfold let (^@) (a:pointer_or_null 't{a =!= null}) (h0:heap) = B.get h0 a 0 /// All the data structures #set-options "--__no_positivity" unopteq (** Node of a doubly linked list *) type node (t:Type0) = { (* forward link *) flink: pointer_or_null (node t); (* backward link *) blink: pointer_or_null (node t); (* payload *) p: t; } #reset-options private type nodelist t = list (pointer (node t)) unopteq (** Doubly linked list head *) type dll (t:Type0) ={ lhead: pointer_or_null (node t); ltail: pointer_or_null (node t); nodes: erased (nodelist t); } type nonempty_dll t = (h:dll t{h.lhead =!= null /\ h.ltail =!= null}) unopteq private (** An "almost valid" dll *) type piece t = { phead: pointer (node t); ptail: pointer (node t); pnodes: erased (nodelist t); } unopteq private (** An intermediate for when linked lists are being formed or destroyed *) type fragment t = | Frag0 : fragment t | Frag1 : piece t -> fragment t | Frag2 : piece t -> piece t -> fragment t | Frag3 : piece t -> piece t -> piece t -> fragment t /// Some useful empty initializers (** Initialize an element of a doubly linked list *) val empty_node: #t:Type -> payload:t -> node t let empty_node #t payload = { flink = null ; blink = null ; p = payload } (** Initialize a doubly linked list head *) val empty_list: #t:Type -> dll t let empty_list #t = { lhead = null ; ltail = null ; nodes = [] } /// Convenience wrappers for writing properties on fragments let fragment_for_each0 (#t:Type) (pr:piece t -> GTot Type0) (f:fragment t) : GTot Type0 = match f with | Frag0 -> True | Frag1 p1 -> pr p1 | Frag2 p1 p2 -> pr p1 /\ pr p2 | Frag3 p1 p2 p3 -> pr p1 /\ pr p2 /\ pr p3 let fragment_for_each1 (#t:Type) (#u:Type) (pr:u -> piece t -> GTot Type0) (v:u) (f:fragment t) : GTot Type0 = match f with | Frag0 -> True | Frag1 p1 -> pr v p1 | Frag2 p1 p2 -> pr v p1 /\ pr v p2 | Frag3 p1 p2 p3 -> pr v p1 /\ pr v p2 /\ pr v p3 let fragment_length (#t:Type) (f:fragment t) : GTot int = match f with | Frag0 -> 0 | Frag1 _ -> 1 | Frag2 _ _ -> 2 | Frag3 _ _ _ -> 3 /// Ghostly connections let dll_ghostly_connections (#t:Type) (d:dll t) : GTot Type0 = let nodes = d.nodes in match length nodes with | 0 -> d.lhead == null /\ d.ltail == null | _ -> d.lhead =!= null /\ d.ltail =!= null /\ d.lhead == hd nodes /\ d.ltail == last nodes let piece_ghostly_connections (#t:Type) (p:piece t) : GTot Type0 = let nodes = p.pnodes in match length nodes with | 0 -> False | _ -> p.phead == hd nodes /\ p.ptail == last nodes let rec fragment_ghostly_connections (#t:Type) (f:fragment t) : GTot Type0 = fragment_for_each0 piece_ghostly_connections f /// Containment properties /// /// WARNING: [@@] and [^@] require containment to reasonably talk about /// what they do. let rec nodelist_contained0 (#t:Type) (h0:heap) (nl:nodelist t) : GTot Type0 = match nl with | [] -> True | n :: ns -> h0 `contains` n /\ nodelist_contained0 h0 ns let rec nodelist_contained (#t:Type) (h0:heap) (nl:nodelist t) : GTot Type0 = nodelist_contained0 h0 nl let dll_contained (#t:Type) (h0:heap) (d:dll t) : GTot Type0 = h0 `contains` d.lhead /\ h0 `contains` d.ltail /\ nodelist_contained h0 d.nodes let piece_contained (#t:Type) (h0:heap) (p:piece t) : GTot Type0 = h0 `contains` p.phead /\ h0 `contains` p.ptail /\ nodelist_contained h0 p.pnodes let rec fragment_contained (#t:Type) (h0:heap) (f:fragment t) : GTot Type0 = fragment_for_each1 piece_contained h0 f /// Footprints let node_fp_f (#t:Type) (n:node t) : GTot Mod.loc = Mod.loc_buffer n.flink let node_fp_b (#t:Type) (n:node t) : GTot Mod.loc = Mod.loc_buffer n.blink let rec nodelist_fp0 (#t:Type) (n:nodelist t) : GTot Mod.loc = match n with | [] -> Mod.loc_none | n :: ns -> Mod.loc_union (Mod.loc_buffer n) (nodelist_fp0 ns) let rec nodelist_fp_f (#t:Type) (h0:heap) (n:nodelist t) : GTot Mod.loc = match n with | [] -> Mod.loc_none | n :: ns -> Mod.loc_union (Mod.loc_buffer (n@h0).flink) (nodelist_fp_f h0 ns) let rec nodelist_fp_b (#t:Type) (h0:heap) (n:nodelist t) : GTot Mod.loc = match n with | [] -> Mod.loc_none | n :: ns -> Mod.loc_union (Mod.loc_buffer (n@h0).blink) (nodelist_fp_b h0 ns) let dll_fp0 (#t:Type) (d:dll t) : GTot Mod.loc = Mod.loc_union // ghostly connections should give us this union for // free, but still useful to have (Mod.loc_union (Mod.loc_buffer d.lhead) (Mod.loc_buffer d.ltail)) (nodelist_fp0 d.nodes) let dll_fp_f (#t:Type) (h0:heap) (d:dll t) : GTot Mod.loc = let a = if g_is_null d.lhead then Mod.loc_none else Mod.loc_buffer (d.lhead^@h0).flink in let b = if g_is_null d.ltail then Mod.loc_none else Mod.loc_buffer (d.ltail^@h0).flink in Mod.loc_union // ghostly connections should give us this union for // free, but still useful to have (Mod.loc_union a b) (nodelist_fp_f h0 d.nodes) let dll_fp_b (#t:Type) (h0:heap) (d:dll t) : GTot Mod.loc = let a = if g_is_null d.lhead then Mod.loc_none else Mod.loc_buffer (d.lhead^@h0).blink in let b = if g_is_null d.ltail then Mod.loc_none else Mod.loc_buffer (d.ltail^@h0).blink in Mod.loc_union // ghostly connections should give us this union for // free, but still useful to have (Mod.loc_union a b) (nodelist_fp_b h0 d.nodes) let piece_fp0 (#t:Type) (p:piece t) : GTot Mod.loc = Mod.loc_union // ghostly connections should give us this union for // free, but still useful to have (Mod.loc_union (Mod.loc_buffer p.phead) (Mod.loc_buffer p.ptail)) (nodelist_fp0 p.pnodes) let piece_fp_f (#t:Type) (h0:heap) (p:piece t) : GTot Mod.loc = Mod.loc_union // ghostly connections should give us this union for // free, but still useful to have (Mod.loc_union (Mod.loc_buffer (p.phead@h0).flink) (Mod.loc_buffer (p.ptail@h0).flink)) (nodelist_fp_f h0 p.pnodes) let piece_fp_b (#t:Type) (h0:heap) (p:piece t) : GTot Mod.loc = Mod.loc_union // ghostly connections should give us this union for // free, but still useful to have (Mod.loc_union (Mod.loc_buffer (p.phead@h0).blink) (Mod.loc_buffer (p.ptail@h0).blink)) (nodelist_fp_b h0 p.pnodes) let rec fragment_fp0 (#t:Type) (f:fragment t) : GTot Mod.loc = match f with | Frag0 -> Mod.loc_none | Frag1 p1 -> piece_fp0 p1 | Frag2 p1 p2 -> Mod.loc_union (piece_fp0 p1) (piece_fp0 p2) | Frag3 p1 p2 p3 -> Mod.loc_union (piece_fp0 p1) (Mod.loc_union (piece_fp0 p2) (piece_fp0 p3)) /// Helper patterns for footprints let loc_includes_union_l_nodelist_fp0 (#t: Type) (s1 s2:loc) (nl:nodelist t) : Lemma (requires (loc_includes s1 (nodelist_fp0 nl) \/ loc_includes s2 (nodelist_fp0 nl))) (ensures (loc_includes (loc_union s1 s2) (nodelist_fp0 nl))) [SMTPat (loc_includes (loc_union s1 s2) (nodelist_fp0 nl))] = loc_includes_union_l s1 s2 (nodelist_fp0 nl) let loc_includes_union_l_dll_fp0 (#t: Type) (s1 s2:loc) (d:dll t) : Lemma (requires (loc_includes s1 (dll_fp0 d) \/ loc_includes s2 (dll_fp0 d))) (ensures (loc_includes (loc_union s1 s2) (dll_fp0 d))) [SMTPat (loc_includes (loc_union s1 s2) (dll_fp0 d))] = loc_includes_union_l s1 s2 (dll_fp0 d) let loc_includes_union_l_piece_fp0 (#t: Type) (s1 s2:loc) (p:piece t) : Lemma (requires (loc_includes s1 (piece_fp0 p) \/ loc_includes s2 (piece_fp0 p))) (ensures (loc_includes (loc_union s1 s2) (piece_fp0 p))) [SMTPat (loc_includes (loc_union s1 s2) (piece_fp0 p))] = loc_includes_union_l s1 s2 (piece_fp0 p) let loc_includes_union_l_fragment_fp0 (#t: Type) (s1 s2:loc) (f:fragment t) : Lemma (requires (loc_includes s1 (fragment_fp0 f) \/ loc_includes s2 (fragment_fp0 f))) (ensures (loc_includes (loc_union s1 s2) (fragment_fp0 f))) [SMTPat (loc_includes (loc_union s1 s2) (fragment_fp0 f))] = loc_includes_union_l s1 s2 (fragment_fp0 f) /// Equivalence for locations let loc_equiv (a b:Mod.loc) = Mod.loc_includes a b /\ Mod.loc_includes b a let loc_equiv_trans (a b c:Mod.loc) : Lemma (requires (loc_equiv a b /\ loc_equiv b c)) (ensures (loc_equiv a c)) [SMTPat (loc_equiv a b); SMTPat (loc_equiv b c); SMTPat (loc_equiv a c)] = Mod.loc_includes_trans a b c; Mod.loc_includes_trans c b a let loc_equiv_union_union_loc (a b c:Mod.loc) : Lemma (requires (loc_equiv b c)) (ensures (loc_equiv (Mod.loc_union a b) (Mod.loc_union a c))) [SMTPat (loc_equiv (Mod.loc_union a b) (Mod.loc_union a c))] = let incl = Mod.loc_includes in let u = Mod.loc_union in // assert (b `incl` c); Mod.loc_includes_union_l a b c; // assert ((a `u` b) `incl` c); Mod.loc_includes_union_l a b a; // assert ((a `u` b) `incl` a); // assert ((a `u` b) `incl` (a `u` c)); Mod.loc_includes_union_l a c b; Mod.loc_includes_union_l a c a /// Anti aliasing properties let node_aa (#t:Type) (n:node t) : GTot Type0 = Mod.loc_disjoint (node_fp_f n) (node_fp_b n) let rec nodelist_aa_r (#t:Type) (nl:nodelist t) : GTot Type0 = match nl with | [] -> True | n :: ns -> Mod.loc_disjoint (Mod.loc_buffer n) (nodelist_fp0 ns) /\ nodelist_aa_r ns let rec nodelist_aa_l (#t:Type) (nl:nodelist t) : GTot Type0 (decreases (length nl)) = match nl with | [] -> True | _ -> let ns, n = unsnoc nl in lemma_unsnoc_length nl; Mod.loc_disjoint (Mod.loc_buffer n) (nodelist_fp0 ns) /\ nodelist_aa_l ns let nodelist_aa (#t:Type) (nl:nodelist t) : GTot Type0 = nodelist_aa_l nl /\ nodelist_aa_r nl let dll_aa (#t:Type) (d:dll t) : GTot Type0 = nodelist_aa d.nodes
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowStar.ModifiesPat.fst.checked", "LowStar.Modifies.fst.checked", "LowStar.BufferOps.fst.checked", "LowStar.Buffer.fst.checked", "FStar.UInt32.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked", "FStar.List.Pure.Properties.fst.checked", "FStar.List.Pure.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked", "FStar.Classical.fsti.checked" ], "interface_file": false, "source_file": "DoublyLinkedList.fst" }
[ { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": true, "full_module": "LowStar.Modifies", "short_module": "Mod" }, { "abbrev": false, "full_module": "LowStar.BufferOps", "short_module": null }, { "abbrev": false, "full_module": "FStar.List.Pure", "short_module": null }, { "abbrev": false, "full_module": "FStar.List.Tot", "short_module": null }, { "abbrev": false, "full_module": "LowStar.ModifiesPat", "short_module": null }, { "abbrev": false, "full_module": "FStar.Ghost", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
p: DoublyLinkedList.piece t -> Prims.GTot Type0
Prims.GTot
[ "sometrivial" ]
[]
[ "DoublyLinkedList.piece", "DoublyLinkedList.nodelist_aa", "FStar.Ghost.reveal", "DoublyLinkedList.nodelist", "DoublyLinkedList.__proj__Mkpiece__item__pnodes" ]
[]
false
false
false
false
true
let piece_aa (#t: Type) (p: piece t) : GTot Type0 =
nodelist_aa p.pnodes
false
DoublyLinkedList.fst
DoublyLinkedList.nodelist_fp_b
val nodelist_fp_b (#t: Type) (h0: heap) (n: nodelist t) : GTot Mod.loc
val nodelist_fp_b (#t: Type) (h0: heap) (n: nodelist t) : GTot Mod.loc
let rec nodelist_fp_b (#t:Type) (h0:heap) (n:nodelist t) : GTot Mod.loc = match n with | [] -> Mod.loc_none | n :: ns -> Mod.loc_union (Mod.loc_buffer (n@h0).blink) (nodelist_fp_b h0 ns)
{ "file_name": "examples/doublylinkedlist/DoublyLinkedList.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 80, "end_line": 200, "start_col": 0, "start_line": 197 }
(* Copyright 2008-2019 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module DoublyLinkedList open FStar open FStar.HyperStack.ST open FStar.Ghost open LowStar.ModifiesPat open FStar.List.Tot open FStar.List.Pure open LowStar.BufferOps module Mod = LowStar.Modifies module ST = FStar.HyperStack.ST module HS = FStar.HyperStack module B = LowStar.Buffer /// Convenience renaming unfold let heap = HS.mem unfold let contains #a #rrel #rel h b = B.live #a #rrel #rel h b /// Convenience patterns let lemma_non_null (#t:Type) (a:pointer_or_null t) : Lemma (requires (a =!= null)) (ensures (len a = 1ul)) [SMTPat (len a)] = null_unique a /// Convenience operators unfold let (.[]) (s:list 'a) (n:nat{n < length s}) = index s n unfold let (~.) (#t:Type) (a:t) : Tot (erased (list t)) = [a] unfold let (^+) (#t:Type) (a:t) (b:erased (list t)) : Tot (erased (list t)) = Cons a b unfold let (+^) (#t:Type) (a:erased (list t)) (b:t) : Tot (erased (list t)) = append a [b] unfold let (^@^) (#t:Type) (a:erased (list t)) (b:erased (list t)) : Tot (erased (list t)) = append a b unfold let (@) (a:pointer 't) (h0:heap) = B.get h0 a 0 unfold let (^@) (a:pointer_or_null 't{a =!= null}) (h0:heap) = B.get h0 a 0 /// All the data structures #set-options "--__no_positivity" unopteq (** Node of a doubly linked list *) type node (t:Type0) = { (* forward link *) flink: pointer_or_null (node t); (* backward link *) blink: pointer_or_null (node t); (* payload *) p: t; } #reset-options private type nodelist t = list (pointer (node t)) unopteq (** Doubly linked list head *) type dll (t:Type0) ={ lhead: pointer_or_null (node t); ltail: pointer_or_null (node t); nodes: erased (nodelist t); } type nonempty_dll t = (h:dll t{h.lhead =!= null /\ h.ltail =!= null}) unopteq private (** An "almost valid" dll *) type piece t = { phead: pointer (node t); ptail: pointer (node t); pnodes: erased (nodelist t); } unopteq private (** An intermediate for when linked lists are being formed or destroyed *) type fragment t = | Frag0 : fragment t | Frag1 : piece t -> fragment t | Frag2 : piece t -> piece t -> fragment t | Frag3 : piece t -> piece t -> piece t -> fragment t /// Some useful empty initializers (** Initialize an element of a doubly linked list *) val empty_node: #t:Type -> payload:t -> node t let empty_node #t payload = { flink = null ; blink = null ; p = payload } (** Initialize a doubly linked list head *) val empty_list: #t:Type -> dll t let empty_list #t = { lhead = null ; ltail = null ; nodes = [] } /// Convenience wrappers for writing properties on fragments let fragment_for_each0 (#t:Type) (pr:piece t -> GTot Type0) (f:fragment t) : GTot Type0 = match f with | Frag0 -> True | Frag1 p1 -> pr p1 | Frag2 p1 p2 -> pr p1 /\ pr p2 | Frag3 p1 p2 p3 -> pr p1 /\ pr p2 /\ pr p3 let fragment_for_each1 (#t:Type) (#u:Type) (pr:u -> piece t -> GTot Type0) (v:u) (f:fragment t) : GTot Type0 = match f with | Frag0 -> True | Frag1 p1 -> pr v p1 | Frag2 p1 p2 -> pr v p1 /\ pr v p2 | Frag3 p1 p2 p3 -> pr v p1 /\ pr v p2 /\ pr v p3 let fragment_length (#t:Type) (f:fragment t) : GTot int = match f with | Frag0 -> 0 | Frag1 _ -> 1 | Frag2 _ _ -> 2 | Frag3 _ _ _ -> 3 /// Ghostly connections let dll_ghostly_connections (#t:Type) (d:dll t) : GTot Type0 = let nodes = d.nodes in match length nodes with | 0 -> d.lhead == null /\ d.ltail == null | _ -> d.lhead =!= null /\ d.ltail =!= null /\ d.lhead == hd nodes /\ d.ltail == last nodes let piece_ghostly_connections (#t:Type) (p:piece t) : GTot Type0 = let nodes = p.pnodes in match length nodes with | 0 -> False | _ -> p.phead == hd nodes /\ p.ptail == last nodes let rec fragment_ghostly_connections (#t:Type) (f:fragment t) : GTot Type0 = fragment_for_each0 piece_ghostly_connections f /// Containment properties /// /// WARNING: [@@] and [^@] require containment to reasonably talk about /// what they do. let rec nodelist_contained0 (#t:Type) (h0:heap) (nl:nodelist t) : GTot Type0 = match nl with | [] -> True | n :: ns -> h0 `contains` n /\ nodelist_contained0 h0 ns let rec nodelist_contained (#t:Type) (h0:heap) (nl:nodelist t) : GTot Type0 = nodelist_contained0 h0 nl let dll_contained (#t:Type) (h0:heap) (d:dll t) : GTot Type0 = h0 `contains` d.lhead /\ h0 `contains` d.ltail /\ nodelist_contained h0 d.nodes let piece_contained (#t:Type) (h0:heap) (p:piece t) : GTot Type0 = h0 `contains` p.phead /\ h0 `contains` p.ptail /\ nodelist_contained h0 p.pnodes let rec fragment_contained (#t:Type) (h0:heap) (f:fragment t) : GTot Type0 = fragment_for_each1 piece_contained h0 f /// Footprints let node_fp_f (#t:Type) (n:node t) : GTot Mod.loc = Mod.loc_buffer n.flink let node_fp_b (#t:Type) (n:node t) : GTot Mod.loc = Mod.loc_buffer n.blink let rec nodelist_fp0 (#t:Type) (n:nodelist t) : GTot Mod.loc = match n with | [] -> Mod.loc_none | n :: ns -> Mod.loc_union (Mod.loc_buffer n) (nodelist_fp0 ns) let rec nodelist_fp_f (#t:Type) (h0:heap) (n:nodelist t) : GTot Mod.loc = match n with | [] -> Mod.loc_none
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowStar.ModifiesPat.fst.checked", "LowStar.Modifies.fst.checked", "LowStar.BufferOps.fst.checked", "LowStar.Buffer.fst.checked", "FStar.UInt32.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked", "FStar.List.Pure.Properties.fst.checked", "FStar.List.Pure.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked", "FStar.Classical.fsti.checked" ], "interface_file": false, "source_file": "DoublyLinkedList.fst" }
[ { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": true, "full_module": "LowStar.Modifies", "short_module": "Mod" }, { "abbrev": false, "full_module": "LowStar.BufferOps", "short_module": null }, { "abbrev": false, "full_module": "FStar.List.Pure", "short_module": null }, { "abbrev": false, "full_module": "FStar.List.Tot", "short_module": null }, { "abbrev": false, "full_module": "LowStar.ModifiesPat", "short_module": null }, { "abbrev": false, "full_module": "FStar.Ghost", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
h0: DoublyLinkedList.heap -> n: DoublyLinkedList.nodelist t -> Prims.GTot LowStar.Monotonic.Buffer.loc
Prims.GTot
[ "sometrivial" ]
[]
[ "DoublyLinkedList.heap", "DoublyLinkedList.nodelist", "LowStar.Monotonic.Buffer.loc_none", "LowStar.Buffer.pointer", "DoublyLinkedList.node", "Prims.list", "LowStar.Monotonic.Buffer.loc_union", "LowStar.Monotonic.Buffer.loc_buffer", "LowStar.Buffer.trivial_preorder", "DoublyLinkedList.__proj__Mknode__item__blink", "DoublyLinkedList.op_At", "DoublyLinkedList.nodelist_fp_b", "LowStar.Monotonic.Buffer.loc" ]
[ "recursion" ]
false
false
false
false
false
let rec nodelist_fp_b (#t: Type) (h0: heap) (n: nodelist t) : GTot Mod.loc =
match n with | [] -> Mod.loc_none | n :: ns -> Mod.loc_union (Mod.loc_buffer (n @ h0).blink) (nodelist_fp_b h0 ns)
false
DoublyLinkedList.fst
DoublyLinkedList.fragment_length
val fragment_length (#t: Type) (f: fragment t) : GTot int
val fragment_length (#t: Type) (f: fragment t) : GTot int
let fragment_length (#t:Type) (f:fragment t) : GTot int = match f with | Frag0 -> 0 | Frag1 _ -> 1 | Frag2 _ _ -> 2 | Frag3 _ _ _ -> 3
{ "file_name": "examples/doublylinkedlist/DoublyLinkedList.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 20, "end_line": 135, "start_col": 0, "start_line": 130 }
(* Copyright 2008-2019 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module DoublyLinkedList open FStar open FStar.HyperStack.ST open FStar.Ghost open LowStar.ModifiesPat open FStar.List.Tot open FStar.List.Pure open LowStar.BufferOps module Mod = LowStar.Modifies module ST = FStar.HyperStack.ST module HS = FStar.HyperStack module B = LowStar.Buffer /// Convenience renaming unfold let heap = HS.mem unfold let contains #a #rrel #rel h b = B.live #a #rrel #rel h b /// Convenience patterns let lemma_non_null (#t:Type) (a:pointer_or_null t) : Lemma (requires (a =!= null)) (ensures (len a = 1ul)) [SMTPat (len a)] = null_unique a /// Convenience operators unfold let (.[]) (s:list 'a) (n:nat{n < length s}) = index s n unfold let (~.) (#t:Type) (a:t) : Tot (erased (list t)) = [a] unfold let (^+) (#t:Type) (a:t) (b:erased (list t)) : Tot (erased (list t)) = Cons a b unfold let (+^) (#t:Type) (a:erased (list t)) (b:t) : Tot (erased (list t)) = append a [b] unfold let (^@^) (#t:Type) (a:erased (list t)) (b:erased (list t)) : Tot (erased (list t)) = append a b unfold let (@) (a:pointer 't) (h0:heap) = B.get h0 a 0 unfold let (^@) (a:pointer_or_null 't{a =!= null}) (h0:heap) = B.get h0 a 0 /// All the data structures #set-options "--__no_positivity" unopteq (** Node of a doubly linked list *) type node (t:Type0) = { (* forward link *) flink: pointer_or_null (node t); (* backward link *) blink: pointer_or_null (node t); (* payload *) p: t; } #reset-options private type nodelist t = list (pointer (node t)) unopteq (** Doubly linked list head *) type dll (t:Type0) ={ lhead: pointer_or_null (node t); ltail: pointer_or_null (node t); nodes: erased (nodelist t); } type nonempty_dll t = (h:dll t{h.lhead =!= null /\ h.ltail =!= null}) unopteq private (** An "almost valid" dll *) type piece t = { phead: pointer (node t); ptail: pointer (node t); pnodes: erased (nodelist t); } unopteq private (** An intermediate for when linked lists are being formed or destroyed *) type fragment t = | Frag0 : fragment t | Frag1 : piece t -> fragment t | Frag2 : piece t -> piece t -> fragment t | Frag3 : piece t -> piece t -> piece t -> fragment t /// Some useful empty initializers (** Initialize an element of a doubly linked list *) val empty_node: #t:Type -> payload:t -> node t let empty_node #t payload = { flink = null ; blink = null ; p = payload } (** Initialize a doubly linked list head *) val empty_list: #t:Type -> dll t let empty_list #t = { lhead = null ; ltail = null ; nodes = [] } /// Convenience wrappers for writing properties on fragments let fragment_for_each0 (#t:Type) (pr:piece t -> GTot Type0) (f:fragment t) : GTot Type0 = match f with | Frag0 -> True | Frag1 p1 -> pr p1 | Frag2 p1 p2 -> pr p1 /\ pr p2 | Frag3 p1 p2 p3 -> pr p1 /\ pr p2 /\ pr p3 let fragment_for_each1 (#t:Type) (#u:Type) (pr:u -> piece t -> GTot Type0) (v:u) (f:fragment t) : GTot Type0 = match f with | Frag0 -> True | Frag1 p1 -> pr v p1 | Frag2 p1 p2 -> pr v p1 /\ pr v p2 | Frag3 p1 p2 p3 -> pr v p1 /\ pr v p2 /\ pr v p3
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowStar.ModifiesPat.fst.checked", "LowStar.Modifies.fst.checked", "LowStar.BufferOps.fst.checked", "LowStar.Buffer.fst.checked", "FStar.UInt32.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked", "FStar.List.Pure.Properties.fst.checked", "FStar.List.Pure.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked", "FStar.Classical.fsti.checked" ], "interface_file": false, "source_file": "DoublyLinkedList.fst" }
[ { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": true, "full_module": "LowStar.Modifies", "short_module": "Mod" }, { "abbrev": false, "full_module": "LowStar.BufferOps", "short_module": null }, { "abbrev": false, "full_module": "FStar.List.Pure", "short_module": null }, { "abbrev": false, "full_module": "FStar.List.Tot", "short_module": null }, { "abbrev": false, "full_module": "LowStar.ModifiesPat", "short_module": null }, { "abbrev": false, "full_module": "FStar.Ghost", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
f: DoublyLinkedList.fragment t -> Prims.GTot Prims.int
Prims.GTot
[ "sometrivial" ]
[]
[ "DoublyLinkedList.fragment", "DoublyLinkedList.piece", "Prims.int" ]
[]
false
false
false
false
false
let fragment_length (#t: Type) (f: fragment t) : GTot int =
match f with | Frag0 -> 0 | Frag1 _ -> 1 | Frag2 _ _ -> 2 | Frag3 _ _ _ -> 3
false
DoublyLinkedList.fst
DoublyLinkedList.dll_ghostly_connections
val dll_ghostly_connections (#t: Type) (d: dll t) : GTot Type0
val dll_ghostly_connections (#t: Type) (d: dll t) : GTot Type0
let dll_ghostly_connections (#t:Type) (d:dll t) : GTot Type0 = let nodes = d.nodes in match length nodes with | 0 -> d.lhead == null /\ d.ltail == null | _ -> d.lhead =!= null /\ d.ltail =!= null /\ d.lhead == hd nodes /\ d.ltail == last nodes
{ "file_name": "examples/doublylinkedlist/DoublyLinkedList.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 30, "end_line": 145, "start_col": 0, "start_line": 139 }
(* Copyright 2008-2019 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module DoublyLinkedList open FStar open FStar.HyperStack.ST open FStar.Ghost open LowStar.ModifiesPat open FStar.List.Tot open FStar.List.Pure open LowStar.BufferOps module Mod = LowStar.Modifies module ST = FStar.HyperStack.ST module HS = FStar.HyperStack module B = LowStar.Buffer /// Convenience renaming unfold let heap = HS.mem unfold let contains #a #rrel #rel h b = B.live #a #rrel #rel h b /// Convenience patterns let lemma_non_null (#t:Type) (a:pointer_or_null t) : Lemma (requires (a =!= null)) (ensures (len a = 1ul)) [SMTPat (len a)] = null_unique a /// Convenience operators unfold let (.[]) (s:list 'a) (n:nat{n < length s}) = index s n unfold let (~.) (#t:Type) (a:t) : Tot (erased (list t)) = [a] unfold let (^+) (#t:Type) (a:t) (b:erased (list t)) : Tot (erased (list t)) = Cons a b unfold let (+^) (#t:Type) (a:erased (list t)) (b:t) : Tot (erased (list t)) = append a [b] unfold let (^@^) (#t:Type) (a:erased (list t)) (b:erased (list t)) : Tot (erased (list t)) = append a b unfold let (@) (a:pointer 't) (h0:heap) = B.get h0 a 0 unfold let (^@) (a:pointer_or_null 't{a =!= null}) (h0:heap) = B.get h0 a 0 /// All the data structures #set-options "--__no_positivity" unopteq (** Node of a doubly linked list *) type node (t:Type0) = { (* forward link *) flink: pointer_or_null (node t); (* backward link *) blink: pointer_or_null (node t); (* payload *) p: t; } #reset-options private type nodelist t = list (pointer (node t)) unopteq (** Doubly linked list head *) type dll (t:Type0) ={ lhead: pointer_or_null (node t); ltail: pointer_or_null (node t); nodes: erased (nodelist t); } type nonempty_dll t = (h:dll t{h.lhead =!= null /\ h.ltail =!= null}) unopteq private (** An "almost valid" dll *) type piece t = { phead: pointer (node t); ptail: pointer (node t); pnodes: erased (nodelist t); } unopteq private (** An intermediate for when linked lists are being formed or destroyed *) type fragment t = | Frag0 : fragment t | Frag1 : piece t -> fragment t | Frag2 : piece t -> piece t -> fragment t | Frag3 : piece t -> piece t -> piece t -> fragment t /// Some useful empty initializers (** Initialize an element of a doubly linked list *) val empty_node: #t:Type -> payload:t -> node t let empty_node #t payload = { flink = null ; blink = null ; p = payload } (** Initialize a doubly linked list head *) val empty_list: #t:Type -> dll t let empty_list #t = { lhead = null ; ltail = null ; nodes = [] } /// Convenience wrappers for writing properties on fragments let fragment_for_each0 (#t:Type) (pr:piece t -> GTot Type0) (f:fragment t) : GTot Type0 = match f with | Frag0 -> True | Frag1 p1 -> pr p1 | Frag2 p1 p2 -> pr p1 /\ pr p2 | Frag3 p1 p2 p3 -> pr p1 /\ pr p2 /\ pr p3 let fragment_for_each1 (#t:Type) (#u:Type) (pr:u -> piece t -> GTot Type0) (v:u) (f:fragment t) : GTot Type0 = match f with | Frag0 -> True | Frag1 p1 -> pr v p1 | Frag2 p1 p2 -> pr v p1 /\ pr v p2 | Frag3 p1 p2 p3 -> pr v p1 /\ pr v p2 /\ pr v p3 let fragment_length (#t:Type) (f:fragment t) : GTot int = match f with | Frag0 -> 0 | Frag1 _ -> 1 | Frag2 _ _ -> 2 | Frag3 _ _ _ -> 3 /// Ghostly connections
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowStar.ModifiesPat.fst.checked", "LowStar.Modifies.fst.checked", "LowStar.BufferOps.fst.checked", "LowStar.Buffer.fst.checked", "FStar.UInt32.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked", "FStar.List.Pure.Properties.fst.checked", "FStar.List.Pure.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked", "FStar.Classical.fsti.checked" ], "interface_file": false, "source_file": "DoublyLinkedList.fst" }
[ { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": true, "full_module": "LowStar.Modifies", "short_module": "Mod" }, { "abbrev": false, "full_module": "LowStar.BufferOps", "short_module": null }, { "abbrev": false, "full_module": "FStar.List.Pure", "short_module": null }, { "abbrev": false, "full_module": "FStar.List.Tot", "short_module": null }, { "abbrev": false, "full_module": "LowStar.ModifiesPat", "short_module": null }, { "abbrev": false, "full_module": "FStar.Ghost", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
d: DoublyLinkedList.dll t -> Prims.GTot Type0
Prims.GTot
[ "sometrivial" ]
[]
[ "DoublyLinkedList.dll", "FStar.List.Tot.Base.length", "LowStar.Buffer.pointer", "DoublyLinkedList.node", "FStar.Ghost.reveal", "DoublyLinkedList.nodelist", "Prims.l_and", "Prims.eq2", "LowStar.Buffer.buffer", "DoublyLinkedList.__proj__Mkdll__item__lhead", "LowStar.Buffer.null", "DoublyLinkedList.__proj__Mkdll__item__ltail", "Prims.int", "Prims.l_not", "Prims.l_or", "LowStar.Monotonic.Buffer.length", "LowStar.Buffer.trivial_preorder", "LowStar.Monotonic.Buffer.g_is_null", "Prims.l_True", "Prims.bool", "Prims.logical", "FStar.List.Tot.Base.hd", "FStar.List.Tot.Base.last", "FStar.Ghost.erased", "DoublyLinkedList.__proj__Mkdll__item__nodes" ]
[]
false
false
false
false
true
let dll_ghostly_connections (#t: Type) (d: dll t) : GTot Type0 =
let nodes = d.nodes in match length nodes with | 0 -> d.lhead == null /\ d.ltail == null | _ -> d.lhead =!= null /\ d.ltail =!= null /\ d.lhead == hd nodes /\ d.ltail == last nodes
false
DoublyLinkedList.fst
DoublyLinkedList.fragment_aa0
val fragment_aa0 (#t: Type) (f: fragment t) : GTot Type0
val fragment_aa0 (#t: Type) (f: fragment t) : GTot Type0
let rec fragment_aa0 (#t:Type) (f:fragment t) : GTot Type0 = fragment_for_each0 piece_aa f
{ "file_name": "examples/doublylinkedlist/DoublyLinkedList.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 31, "end_line": 337, "start_col": 0, "start_line": 336 }
(* Copyright 2008-2019 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module DoublyLinkedList open FStar open FStar.HyperStack.ST open FStar.Ghost open LowStar.ModifiesPat open FStar.List.Tot open FStar.List.Pure open LowStar.BufferOps module Mod = LowStar.Modifies module ST = FStar.HyperStack.ST module HS = FStar.HyperStack module B = LowStar.Buffer /// Convenience renaming unfold let heap = HS.mem unfold let contains #a #rrel #rel h b = B.live #a #rrel #rel h b /// Convenience patterns let lemma_non_null (#t:Type) (a:pointer_or_null t) : Lemma (requires (a =!= null)) (ensures (len a = 1ul)) [SMTPat (len a)] = null_unique a /// Convenience operators unfold let (.[]) (s:list 'a) (n:nat{n < length s}) = index s n unfold let (~.) (#t:Type) (a:t) : Tot (erased (list t)) = [a] unfold let (^+) (#t:Type) (a:t) (b:erased (list t)) : Tot (erased (list t)) = Cons a b unfold let (+^) (#t:Type) (a:erased (list t)) (b:t) : Tot (erased (list t)) = append a [b] unfold let (^@^) (#t:Type) (a:erased (list t)) (b:erased (list t)) : Tot (erased (list t)) = append a b unfold let (@) (a:pointer 't) (h0:heap) = B.get h0 a 0 unfold let (^@) (a:pointer_or_null 't{a =!= null}) (h0:heap) = B.get h0 a 0 /// All the data structures #set-options "--__no_positivity" unopteq (** Node of a doubly linked list *) type node (t:Type0) = { (* forward link *) flink: pointer_or_null (node t); (* backward link *) blink: pointer_or_null (node t); (* payload *) p: t; } #reset-options private type nodelist t = list (pointer (node t)) unopteq (** Doubly linked list head *) type dll (t:Type0) ={ lhead: pointer_or_null (node t); ltail: pointer_or_null (node t); nodes: erased (nodelist t); } type nonempty_dll t = (h:dll t{h.lhead =!= null /\ h.ltail =!= null}) unopteq private (** An "almost valid" dll *) type piece t = { phead: pointer (node t); ptail: pointer (node t); pnodes: erased (nodelist t); } unopteq private (** An intermediate for when linked lists are being formed or destroyed *) type fragment t = | Frag0 : fragment t | Frag1 : piece t -> fragment t | Frag2 : piece t -> piece t -> fragment t | Frag3 : piece t -> piece t -> piece t -> fragment t /// Some useful empty initializers (** Initialize an element of a doubly linked list *) val empty_node: #t:Type -> payload:t -> node t let empty_node #t payload = { flink = null ; blink = null ; p = payload } (** Initialize a doubly linked list head *) val empty_list: #t:Type -> dll t let empty_list #t = { lhead = null ; ltail = null ; nodes = [] } /// Convenience wrappers for writing properties on fragments let fragment_for_each0 (#t:Type) (pr:piece t -> GTot Type0) (f:fragment t) : GTot Type0 = match f with | Frag0 -> True | Frag1 p1 -> pr p1 | Frag2 p1 p2 -> pr p1 /\ pr p2 | Frag3 p1 p2 p3 -> pr p1 /\ pr p2 /\ pr p3 let fragment_for_each1 (#t:Type) (#u:Type) (pr:u -> piece t -> GTot Type0) (v:u) (f:fragment t) : GTot Type0 = match f with | Frag0 -> True | Frag1 p1 -> pr v p1 | Frag2 p1 p2 -> pr v p1 /\ pr v p2 | Frag3 p1 p2 p3 -> pr v p1 /\ pr v p2 /\ pr v p3 let fragment_length (#t:Type) (f:fragment t) : GTot int = match f with | Frag0 -> 0 | Frag1 _ -> 1 | Frag2 _ _ -> 2 | Frag3 _ _ _ -> 3 /// Ghostly connections let dll_ghostly_connections (#t:Type) (d:dll t) : GTot Type0 = let nodes = d.nodes in match length nodes with | 0 -> d.lhead == null /\ d.ltail == null | _ -> d.lhead =!= null /\ d.ltail =!= null /\ d.lhead == hd nodes /\ d.ltail == last nodes let piece_ghostly_connections (#t:Type) (p:piece t) : GTot Type0 = let nodes = p.pnodes in match length nodes with | 0 -> False | _ -> p.phead == hd nodes /\ p.ptail == last nodes let rec fragment_ghostly_connections (#t:Type) (f:fragment t) : GTot Type0 = fragment_for_each0 piece_ghostly_connections f /// Containment properties /// /// WARNING: [@@] and [^@] require containment to reasonably talk about /// what they do. let rec nodelist_contained0 (#t:Type) (h0:heap) (nl:nodelist t) : GTot Type0 = match nl with | [] -> True | n :: ns -> h0 `contains` n /\ nodelist_contained0 h0 ns let rec nodelist_contained (#t:Type) (h0:heap) (nl:nodelist t) : GTot Type0 = nodelist_contained0 h0 nl let dll_contained (#t:Type) (h0:heap) (d:dll t) : GTot Type0 = h0 `contains` d.lhead /\ h0 `contains` d.ltail /\ nodelist_contained h0 d.nodes let piece_contained (#t:Type) (h0:heap) (p:piece t) : GTot Type0 = h0 `contains` p.phead /\ h0 `contains` p.ptail /\ nodelist_contained h0 p.pnodes let rec fragment_contained (#t:Type) (h0:heap) (f:fragment t) : GTot Type0 = fragment_for_each1 piece_contained h0 f /// Footprints let node_fp_f (#t:Type) (n:node t) : GTot Mod.loc = Mod.loc_buffer n.flink let node_fp_b (#t:Type) (n:node t) : GTot Mod.loc = Mod.loc_buffer n.blink let rec nodelist_fp0 (#t:Type) (n:nodelist t) : GTot Mod.loc = match n with | [] -> Mod.loc_none | n :: ns -> Mod.loc_union (Mod.loc_buffer n) (nodelist_fp0 ns) let rec nodelist_fp_f (#t:Type) (h0:heap) (n:nodelist t) : GTot Mod.loc = match n with | [] -> Mod.loc_none | n :: ns -> Mod.loc_union (Mod.loc_buffer (n@h0).flink) (nodelist_fp_f h0 ns) let rec nodelist_fp_b (#t:Type) (h0:heap) (n:nodelist t) : GTot Mod.loc = match n with | [] -> Mod.loc_none | n :: ns -> Mod.loc_union (Mod.loc_buffer (n@h0).blink) (nodelist_fp_b h0 ns) let dll_fp0 (#t:Type) (d:dll t) : GTot Mod.loc = Mod.loc_union // ghostly connections should give us this union for // free, but still useful to have (Mod.loc_union (Mod.loc_buffer d.lhead) (Mod.loc_buffer d.ltail)) (nodelist_fp0 d.nodes) let dll_fp_f (#t:Type) (h0:heap) (d:dll t) : GTot Mod.loc = let a = if g_is_null d.lhead then Mod.loc_none else Mod.loc_buffer (d.lhead^@h0).flink in let b = if g_is_null d.ltail then Mod.loc_none else Mod.loc_buffer (d.ltail^@h0).flink in Mod.loc_union // ghostly connections should give us this union for // free, but still useful to have (Mod.loc_union a b) (nodelist_fp_f h0 d.nodes) let dll_fp_b (#t:Type) (h0:heap) (d:dll t) : GTot Mod.loc = let a = if g_is_null d.lhead then Mod.loc_none else Mod.loc_buffer (d.lhead^@h0).blink in let b = if g_is_null d.ltail then Mod.loc_none else Mod.loc_buffer (d.ltail^@h0).blink in Mod.loc_union // ghostly connections should give us this union for // free, but still useful to have (Mod.loc_union a b) (nodelist_fp_b h0 d.nodes) let piece_fp0 (#t:Type) (p:piece t) : GTot Mod.loc = Mod.loc_union // ghostly connections should give us this union for // free, but still useful to have (Mod.loc_union (Mod.loc_buffer p.phead) (Mod.loc_buffer p.ptail)) (nodelist_fp0 p.pnodes) let piece_fp_f (#t:Type) (h0:heap) (p:piece t) : GTot Mod.loc = Mod.loc_union // ghostly connections should give us this union for // free, but still useful to have (Mod.loc_union (Mod.loc_buffer (p.phead@h0).flink) (Mod.loc_buffer (p.ptail@h0).flink)) (nodelist_fp_f h0 p.pnodes) let piece_fp_b (#t:Type) (h0:heap) (p:piece t) : GTot Mod.loc = Mod.loc_union // ghostly connections should give us this union for // free, but still useful to have (Mod.loc_union (Mod.loc_buffer (p.phead@h0).blink) (Mod.loc_buffer (p.ptail@h0).blink)) (nodelist_fp_b h0 p.pnodes) let rec fragment_fp0 (#t:Type) (f:fragment t) : GTot Mod.loc = match f with | Frag0 -> Mod.loc_none | Frag1 p1 -> piece_fp0 p1 | Frag2 p1 p2 -> Mod.loc_union (piece_fp0 p1) (piece_fp0 p2) | Frag3 p1 p2 p3 -> Mod.loc_union (piece_fp0 p1) (Mod.loc_union (piece_fp0 p2) (piece_fp0 p3)) /// Helper patterns for footprints let loc_includes_union_l_nodelist_fp0 (#t: Type) (s1 s2:loc) (nl:nodelist t) : Lemma (requires (loc_includes s1 (nodelist_fp0 nl) \/ loc_includes s2 (nodelist_fp0 nl))) (ensures (loc_includes (loc_union s1 s2) (nodelist_fp0 nl))) [SMTPat (loc_includes (loc_union s1 s2) (nodelist_fp0 nl))] = loc_includes_union_l s1 s2 (nodelist_fp0 nl) let loc_includes_union_l_dll_fp0 (#t: Type) (s1 s2:loc) (d:dll t) : Lemma (requires (loc_includes s1 (dll_fp0 d) \/ loc_includes s2 (dll_fp0 d))) (ensures (loc_includes (loc_union s1 s2) (dll_fp0 d))) [SMTPat (loc_includes (loc_union s1 s2) (dll_fp0 d))] = loc_includes_union_l s1 s2 (dll_fp0 d) let loc_includes_union_l_piece_fp0 (#t: Type) (s1 s2:loc) (p:piece t) : Lemma (requires (loc_includes s1 (piece_fp0 p) \/ loc_includes s2 (piece_fp0 p))) (ensures (loc_includes (loc_union s1 s2) (piece_fp0 p))) [SMTPat (loc_includes (loc_union s1 s2) (piece_fp0 p))] = loc_includes_union_l s1 s2 (piece_fp0 p) let loc_includes_union_l_fragment_fp0 (#t: Type) (s1 s2:loc) (f:fragment t) : Lemma (requires (loc_includes s1 (fragment_fp0 f) \/ loc_includes s2 (fragment_fp0 f))) (ensures (loc_includes (loc_union s1 s2) (fragment_fp0 f))) [SMTPat (loc_includes (loc_union s1 s2) (fragment_fp0 f))] = loc_includes_union_l s1 s2 (fragment_fp0 f) /// Equivalence for locations let loc_equiv (a b:Mod.loc) = Mod.loc_includes a b /\ Mod.loc_includes b a let loc_equiv_trans (a b c:Mod.loc) : Lemma (requires (loc_equiv a b /\ loc_equiv b c)) (ensures (loc_equiv a c)) [SMTPat (loc_equiv a b); SMTPat (loc_equiv b c); SMTPat (loc_equiv a c)] = Mod.loc_includes_trans a b c; Mod.loc_includes_trans c b a let loc_equiv_union_union_loc (a b c:Mod.loc) : Lemma (requires (loc_equiv b c)) (ensures (loc_equiv (Mod.loc_union a b) (Mod.loc_union a c))) [SMTPat (loc_equiv (Mod.loc_union a b) (Mod.loc_union a c))] = let incl = Mod.loc_includes in let u = Mod.loc_union in // assert (b `incl` c); Mod.loc_includes_union_l a b c; // assert ((a `u` b) `incl` c); Mod.loc_includes_union_l a b a; // assert ((a `u` b) `incl` a); // assert ((a `u` b) `incl` (a `u` c)); Mod.loc_includes_union_l a c b; Mod.loc_includes_union_l a c a /// Anti aliasing properties let node_aa (#t:Type) (n:node t) : GTot Type0 = Mod.loc_disjoint (node_fp_f n) (node_fp_b n) let rec nodelist_aa_r (#t:Type) (nl:nodelist t) : GTot Type0 = match nl with | [] -> True | n :: ns -> Mod.loc_disjoint (Mod.loc_buffer n) (nodelist_fp0 ns) /\ nodelist_aa_r ns let rec nodelist_aa_l (#t:Type) (nl:nodelist t) : GTot Type0 (decreases (length nl)) = match nl with | [] -> True | _ -> let ns, n = unsnoc nl in lemma_unsnoc_length nl; Mod.loc_disjoint (Mod.loc_buffer n) (nodelist_fp0 ns) /\ nodelist_aa_l ns let nodelist_aa (#t:Type) (nl:nodelist t) : GTot Type0 = nodelist_aa_l nl /\ nodelist_aa_r nl let dll_aa (#t:Type) (d:dll t) : GTot Type0 = nodelist_aa d.nodes let piece_aa (#t:Type) (p:piece t) : GTot Type0 = nodelist_aa p.pnodes
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowStar.ModifiesPat.fst.checked", "LowStar.Modifies.fst.checked", "LowStar.BufferOps.fst.checked", "LowStar.Buffer.fst.checked", "FStar.UInt32.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked", "FStar.List.Pure.Properties.fst.checked", "FStar.List.Pure.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked", "FStar.Classical.fsti.checked" ], "interface_file": false, "source_file": "DoublyLinkedList.fst" }
[ { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": true, "full_module": "LowStar.Modifies", "short_module": "Mod" }, { "abbrev": false, "full_module": "LowStar.BufferOps", "short_module": null }, { "abbrev": false, "full_module": "FStar.List.Pure", "short_module": null }, { "abbrev": false, "full_module": "FStar.List.Tot", "short_module": null }, { "abbrev": false, "full_module": "LowStar.ModifiesPat", "short_module": null }, { "abbrev": false, "full_module": "FStar.Ghost", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
f: DoublyLinkedList.fragment t -> Prims.GTot Type0
Prims.GTot
[ "sometrivial" ]
[]
[ "DoublyLinkedList.fragment", "DoublyLinkedList.fragment_for_each0", "DoublyLinkedList.piece_aa" ]
[ "recursion" ]
false
false
false
false
true
let rec fragment_aa0 (#t: Type) (f: fragment t) : GTot Type0 =
fragment_for_each0 piece_aa f
false
DoublyLinkedList.fst
DoublyLinkedList.nodelist_contained0
val nodelist_contained0 (#t: Type) (h0: heap) (nl: nodelist t) : GTot Type0
val nodelist_contained0 (#t: Type) (h0: heap) (nl: nodelist t) : GTot Type0
let rec nodelist_contained0 (#t:Type) (h0:heap) (nl:nodelist t) : GTot Type0 = match nl with | [] -> True | n :: ns -> h0 `contains` n /\ nodelist_contained0 h0 ns
{ "file_name": "examples/doublylinkedlist/DoublyLinkedList.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 59, "end_line": 165, "start_col": 0, "start_line": 162 }
(* Copyright 2008-2019 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module DoublyLinkedList open FStar open FStar.HyperStack.ST open FStar.Ghost open LowStar.ModifiesPat open FStar.List.Tot open FStar.List.Pure open LowStar.BufferOps module Mod = LowStar.Modifies module ST = FStar.HyperStack.ST module HS = FStar.HyperStack module B = LowStar.Buffer /// Convenience renaming unfold let heap = HS.mem unfold let contains #a #rrel #rel h b = B.live #a #rrel #rel h b /// Convenience patterns let lemma_non_null (#t:Type) (a:pointer_or_null t) : Lemma (requires (a =!= null)) (ensures (len a = 1ul)) [SMTPat (len a)] = null_unique a /// Convenience operators unfold let (.[]) (s:list 'a) (n:nat{n < length s}) = index s n unfold let (~.) (#t:Type) (a:t) : Tot (erased (list t)) = [a] unfold let (^+) (#t:Type) (a:t) (b:erased (list t)) : Tot (erased (list t)) = Cons a b unfold let (+^) (#t:Type) (a:erased (list t)) (b:t) : Tot (erased (list t)) = append a [b] unfold let (^@^) (#t:Type) (a:erased (list t)) (b:erased (list t)) : Tot (erased (list t)) = append a b unfold let (@) (a:pointer 't) (h0:heap) = B.get h0 a 0 unfold let (^@) (a:pointer_or_null 't{a =!= null}) (h0:heap) = B.get h0 a 0 /// All the data structures #set-options "--__no_positivity" unopteq (** Node of a doubly linked list *) type node (t:Type0) = { (* forward link *) flink: pointer_or_null (node t); (* backward link *) blink: pointer_or_null (node t); (* payload *) p: t; } #reset-options private type nodelist t = list (pointer (node t)) unopteq (** Doubly linked list head *) type dll (t:Type0) ={ lhead: pointer_or_null (node t); ltail: pointer_or_null (node t); nodes: erased (nodelist t); } type nonempty_dll t = (h:dll t{h.lhead =!= null /\ h.ltail =!= null}) unopteq private (** An "almost valid" dll *) type piece t = { phead: pointer (node t); ptail: pointer (node t); pnodes: erased (nodelist t); } unopteq private (** An intermediate for when linked lists are being formed or destroyed *) type fragment t = | Frag0 : fragment t | Frag1 : piece t -> fragment t | Frag2 : piece t -> piece t -> fragment t | Frag3 : piece t -> piece t -> piece t -> fragment t /// Some useful empty initializers (** Initialize an element of a doubly linked list *) val empty_node: #t:Type -> payload:t -> node t let empty_node #t payload = { flink = null ; blink = null ; p = payload } (** Initialize a doubly linked list head *) val empty_list: #t:Type -> dll t let empty_list #t = { lhead = null ; ltail = null ; nodes = [] } /// Convenience wrappers for writing properties on fragments let fragment_for_each0 (#t:Type) (pr:piece t -> GTot Type0) (f:fragment t) : GTot Type0 = match f with | Frag0 -> True | Frag1 p1 -> pr p1 | Frag2 p1 p2 -> pr p1 /\ pr p2 | Frag3 p1 p2 p3 -> pr p1 /\ pr p2 /\ pr p3 let fragment_for_each1 (#t:Type) (#u:Type) (pr:u -> piece t -> GTot Type0) (v:u) (f:fragment t) : GTot Type0 = match f with | Frag0 -> True | Frag1 p1 -> pr v p1 | Frag2 p1 p2 -> pr v p1 /\ pr v p2 | Frag3 p1 p2 p3 -> pr v p1 /\ pr v p2 /\ pr v p3 let fragment_length (#t:Type) (f:fragment t) : GTot int = match f with | Frag0 -> 0 | Frag1 _ -> 1 | Frag2 _ _ -> 2 | Frag3 _ _ _ -> 3 /// Ghostly connections let dll_ghostly_connections (#t:Type) (d:dll t) : GTot Type0 = let nodes = d.nodes in match length nodes with | 0 -> d.lhead == null /\ d.ltail == null | _ -> d.lhead =!= null /\ d.ltail =!= null /\ d.lhead == hd nodes /\ d.ltail == last nodes let piece_ghostly_connections (#t:Type) (p:piece t) : GTot Type0 = let nodes = p.pnodes in match length nodes with | 0 -> False | _ -> p.phead == hd nodes /\ p.ptail == last nodes let rec fragment_ghostly_connections (#t:Type) (f:fragment t) : GTot Type0 = fragment_for_each0 piece_ghostly_connections f /// Containment properties /// /// WARNING: [@@] and [^@] require containment to reasonably talk about /// what they do.
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowStar.ModifiesPat.fst.checked", "LowStar.Modifies.fst.checked", "LowStar.BufferOps.fst.checked", "LowStar.Buffer.fst.checked", "FStar.UInt32.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked", "FStar.List.Pure.Properties.fst.checked", "FStar.List.Pure.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked", "FStar.Classical.fsti.checked" ], "interface_file": false, "source_file": "DoublyLinkedList.fst" }
[ { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": true, "full_module": "LowStar.Modifies", "short_module": "Mod" }, { "abbrev": false, "full_module": "LowStar.BufferOps", "short_module": null }, { "abbrev": false, "full_module": "FStar.List.Pure", "short_module": null }, { "abbrev": false, "full_module": "FStar.List.Tot", "short_module": null }, { "abbrev": false, "full_module": "LowStar.ModifiesPat", "short_module": null }, { "abbrev": false, "full_module": "FStar.Ghost", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
h0: DoublyLinkedList.heap -> nl: DoublyLinkedList.nodelist t -> Prims.GTot Type0
Prims.GTot
[ "sometrivial" ]
[]
[ "DoublyLinkedList.heap", "DoublyLinkedList.nodelist", "Prims.l_True", "LowStar.Buffer.pointer", "DoublyLinkedList.node", "Prims.list", "Prims.l_and", "DoublyLinkedList.contains", "LowStar.Buffer.trivial_preorder", "DoublyLinkedList.nodelist_contained0" ]
[ "recursion" ]
false
false
false
false
true
let rec nodelist_contained0 (#t: Type) (h0: heap) (nl: nodelist t) : GTot Type0 =
match nl with | [] -> True | n :: ns -> h0 `contains` n /\ nodelist_contained0 h0 ns
false
DoublyLinkedList.fst
DoublyLinkedList.nodelist_fp0
val nodelist_fp0 (#t: Type) (n: nodelist t) : GTot Mod.loc
val nodelist_fp0 (#t: Type) (n: nodelist t) : GTot Mod.loc
let rec nodelist_fp0 (#t:Type) (n:nodelist t) : GTot Mod.loc = match n with | [] -> Mod.loc_none | n :: ns -> Mod.loc_union (Mod.loc_buffer n) (nodelist_fp0 ns)
{ "file_name": "examples/doublylinkedlist/DoublyLinkedList.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 65, "end_line": 192, "start_col": 0, "start_line": 189 }
(* Copyright 2008-2019 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module DoublyLinkedList open FStar open FStar.HyperStack.ST open FStar.Ghost open LowStar.ModifiesPat open FStar.List.Tot open FStar.List.Pure open LowStar.BufferOps module Mod = LowStar.Modifies module ST = FStar.HyperStack.ST module HS = FStar.HyperStack module B = LowStar.Buffer /// Convenience renaming unfold let heap = HS.mem unfold let contains #a #rrel #rel h b = B.live #a #rrel #rel h b /// Convenience patterns let lemma_non_null (#t:Type) (a:pointer_or_null t) : Lemma (requires (a =!= null)) (ensures (len a = 1ul)) [SMTPat (len a)] = null_unique a /// Convenience operators unfold let (.[]) (s:list 'a) (n:nat{n < length s}) = index s n unfold let (~.) (#t:Type) (a:t) : Tot (erased (list t)) = [a] unfold let (^+) (#t:Type) (a:t) (b:erased (list t)) : Tot (erased (list t)) = Cons a b unfold let (+^) (#t:Type) (a:erased (list t)) (b:t) : Tot (erased (list t)) = append a [b] unfold let (^@^) (#t:Type) (a:erased (list t)) (b:erased (list t)) : Tot (erased (list t)) = append a b unfold let (@) (a:pointer 't) (h0:heap) = B.get h0 a 0 unfold let (^@) (a:pointer_or_null 't{a =!= null}) (h0:heap) = B.get h0 a 0 /// All the data structures #set-options "--__no_positivity" unopteq (** Node of a doubly linked list *) type node (t:Type0) = { (* forward link *) flink: pointer_or_null (node t); (* backward link *) blink: pointer_or_null (node t); (* payload *) p: t; } #reset-options private type nodelist t = list (pointer (node t)) unopteq (** Doubly linked list head *) type dll (t:Type0) ={ lhead: pointer_or_null (node t); ltail: pointer_or_null (node t); nodes: erased (nodelist t); } type nonempty_dll t = (h:dll t{h.lhead =!= null /\ h.ltail =!= null}) unopteq private (** An "almost valid" dll *) type piece t = { phead: pointer (node t); ptail: pointer (node t); pnodes: erased (nodelist t); } unopteq private (** An intermediate for when linked lists are being formed or destroyed *) type fragment t = | Frag0 : fragment t | Frag1 : piece t -> fragment t | Frag2 : piece t -> piece t -> fragment t | Frag3 : piece t -> piece t -> piece t -> fragment t /// Some useful empty initializers (** Initialize an element of a doubly linked list *) val empty_node: #t:Type -> payload:t -> node t let empty_node #t payload = { flink = null ; blink = null ; p = payload } (** Initialize a doubly linked list head *) val empty_list: #t:Type -> dll t let empty_list #t = { lhead = null ; ltail = null ; nodes = [] } /// Convenience wrappers for writing properties on fragments let fragment_for_each0 (#t:Type) (pr:piece t -> GTot Type0) (f:fragment t) : GTot Type0 = match f with | Frag0 -> True | Frag1 p1 -> pr p1 | Frag2 p1 p2 -> pr p1 /\ pr p2 | Frag3 p1 p2 p3 -> pr p1 /\ pr p2 /\ pr p3 let fragment_for_each1 (#t:Type) (#u:Type) (pr:u -> piece t -> GTot Type0) (v:u) (f:fragment t) : GTot Type0 = match f with | Frag0 -> True | Frag1 p1 -> pr v p1 | Frag2 p1 p2 -> pr v p1 /\ pr v p2 | Frag3 p1 p2 p3 -> pr v p1 /\ pr v p2 /\ pr v p3 let fragment_length (#t:Type) (f:fragment t) : GTot int = match f with | Frag0 -> 0 | Frag1 _ -> 1 | Frag2 _ _ -> 2 | Frag3 _ _ _ -> 3 /// Ghostly connections let dll_ghostly_connections (#t:Type) (d:dll t) : GTot Type0 = let nodes = d.nodes in match length nodes with | 0 -> d.lhead == null /\ d.ltail == null | _ -> d.lhead =!= null /\ d.ltail =!= null /\ d.lhead == hd nodes /\ d.ltail == last nodes let piece_ghostly_connections (#t:Type) (p:piece t) : GTot Type0 = let nodes = p.pnodes in match length nodes with | 0 -> False | _ -> p.phead == hd nodes /\ p.ptail == last nodes let rec fragment_ghostly_connections (#t:Type) (f:fragment t) : GTot Type0 = fragment_for_each0 piece_ghostly_connections f /// Containment properties /// /// WARNING: [@@] and [^@] require containment to reasonably talk about /// what they do. let rec nodelist_contained0 (#t:Type) (h0:heap) (nl:nodelist t) : GTot Type0 = match nl with | [] -> True | n :: ns -> h0 `contains` n /\ nodelist_contained0 h0 ns let rec nodelist_contained (#t:Type) (h0:heap) (nl:nodelist t) : GTot Type0 = nodelist_contained0 h0 nl let dll_contained (#t:Type) (h0:heap) (d:dll t) : GTot Type0 = h0 `contains` d.lhead /\ h0 `contains` d.ltail /\ nodelist_contained h0 d.nodes let piece_contained (#t:Type) (h0:heap) (p:piece t) : GTot Type0 = h0 `contains` p.phead /\ h0 `contains` p.ptail /\ nodelist_contained h0 p.pnodes let rec fragment_contained (#t:Type) (h0:heap) (f:fragment t) : GTot Type0 = fragment_for_each1 piece_contained h0 f /// Footprints let node_fp_f (#t:Type) (n:node t) : GTot Mod.loc = Mod.loc_buffer n.flink let node_fp_b (#t:Type) (n:node t) : GTot Mod.loc = Mod.loc_buffer n.blink
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowStar.ModifiesPat.fst.checked", "LowStar.Modifies.fst.checked", "LowStar.BufferOps.fst.checked", "LowStar.Buffer.fst.checked", "FStar.UInt32.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked", "FStar.List.Pure.Properties.fst.checked", "FStar.List.Pure.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked", "FStar.Classical.fsti.checked" ], "interface_file": false, "source_file": "DoublyLinkedList.fst" }
[ { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": true, "full_module": "LowStar.Modifies", "short_module": "Mod" }, { "abbrev": false, "full_module": "LowStar.BufferOps", "short_module": null }, { "abbrev": false, "full_module": "FStar.List.Pure", "short_module": null }, { "abbrev": false, "full_module": "FStar.List.Tot", "short_module": null }, { "abbrev": false, "full_module": "LowStar.ModifiesPat", "short_module": null }, { "abbrev": false, "full_module": "FStar.Ghost", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
n: DoublyLinkedList.nodelist t -> Prims.GTot LowStar.Monotonic.Buffer.loc
Prims.GTot
[ "sometrivial" ]
[]
[ "DoublyLinkedList.nodelist", "LowStar.Monotonic.Buffer.loc_none", "LowStar.Buffer.pointer", "DoublyLinkedList.node", "Prims.list", "LowStar.Monotonic.Buffer.loc_union", "LowStar.Monotonic.Buffer.loc_buffer", "LowStar.Buffer.trivial_preorder", "DoublyLinkedList.nodelist_fp0", "LowStar.Monotonic.Buffer.loc" ]
[ "recursion" ]
false
false
false
false
false
let rec nodelist_fp0 (#t: Type) (n: nodelist t) : GTot Mod.loc =
match n with | [] -> Mod.loc_none | n :: ns -> Mod.loc_union (Mod.loc_buffer n) (nodelist_fp0 ns)
false
DoublyLinkedList.fst
DoublyLinkedList.fragment_aa
val fragment_aa (#t: Type) (f: fragment t) : GTot Type0
val fragment_aa (#t: Type) (f: fragment t) : GTot Type0
let fragment_aa (#t:Type) (f:fragment t) : GTot Type0 = fragment_aa0 f /\ fragment_aa_lr f
{ "file_name": "examples/doublylinkedlist/DoublyLinkedList.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 36, "end_line": 347, "start_col": 0, "start_line": 346 }
(* Copyright 2008-2019 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module DoublyLinkedList open FStar open FStar.HyperStack.ST open FStar.Ghost open LowStar.ModifiesPat open FStar.List.Tot open FStar.List.Pure open LowStar.BufferOps module Mod = LowStar.Modifies module ST = FStar.HyperStack.ST module HS = FStar.HyperStack module B = LowStar.Buffer /// Convenience renaming unfold let heap = HS.mem unfold let contains #a #rrel #rel h b = B.live #a #rrel #rel h b /// Convenience patterns let lemma_non_null (#t:Type) (a:pointer_or_null t) : Lemma (requires (a =!= null)) (ensures (len a = 1ul)) [SMTPat (len a)] = null_unique a /// Convenience operators unfold let (.[]) (s:list 'a) (n:nat{n < length s}) = index s n unfold let (~.) (#t:Type) (a:t) : Tot (erased (list t)) = [a] unfold let (^+) (#t:Type) (a:t) (b:erased (list t)) : Tot (erased (list t)) = Cons a b unfold let (+^) (#t:Type) (a:erased (list t)) (b:t) : Tot (erased (list t)) = append a [b] unfold let (^@^) (#t:Type) (a:erased (list t)) (b:erased (list t)) : Tot (erased (list t)) = append a b unfold let (@) (a:pointer 't) (h0:heap) = B.get h0 a 0 unfold let (^@) (a:pointer_or_null 't{a =!= null}) (h0:heap) = B.get h0 a 0 /// All the data structures #set-options "--__no_positivity" unopteq (** Node of a doubly linked list *) type node (t:Type0) = { (* forward link *) flink: pointer_or_null (node t); (* backward link *) blink: pointer_or_null (node t); (* payload *) p: t; } #reset-options private type nodelist t = list (pointer (node t)) unopteq (** Doubly linked list head *) type dll (t:Type0) ={ lhead: pointer_or_null (node t); ltail: pointer_or_null (node t); nodes: erased (nodelist t); } type nonempty_dll t = (h:dll t{h.lhead =!= null /\ h.ltail =!= null}) unopteq private (** An "almost valid" dll *) type piece t = { phead: pointer (node t); ptail: pointer (node t); pnodes: erased (nodelist t); } unopteq private (** An intermediate for when linked lists are being formed or destroyed *) type fragment t = | Frag0 : fragment t | Frag1 : piece t -> fragment t | Frag2 : piece t -> piece t -> fragment t | Frag3 : piece t -> piece t -> piece t -> fragment t /// Some useful empty initializers (** Initialize an element of a doubly linked list *) val empty_node: #t:Type -> payload:t -> node t let empty_node #t payload = { flink = null ; blink = null ; p = payload } (** Initialize a doubly linked list head *) val empty_list: #t:Type -> dll t let empty_list #t = { lhead = null ; ltail = null ; nodes = [] } /// Convenience wrappers for writing properties on fragments let fragment_for_each0 (#t:Type) (pr:piece t -> GTot Type0) (f:fragment t) : GTot Type0 = match f with | Frag0 -> True | Frag1 p1 -> pr p1 | Frag2 p1 p2 -> pr p1 /\ pr p2 | Frag3 p1 p2 p3 -> pr p1 /\ pr p2 /\ pr p3 let fragment_for_each1 (#t:Type) (#u:Type) (pr:u -> piece t -> GTot Type0) (v:u) (f:fragment t) : GTot Type0 = match f with | Frag0 -> True | Frag1 p1 -> pr v p1 | Frag2 p1 p2 -> pr v p1 /\ pr v p2 | Frag3 p1 p2 p3 -> pr v p1 /\ pr v p2 /\ pr v p3 let fragment_length (#t:Type) (f:fragment t) : GTot int = match f with | Frag0 -> 0 | Frag1 _ -> 1 | Frag2 _ _ -> 2 | Frag3 _ _ _ -> 3 /// Ghostly connections let dll_ghostly_connections (#t:Type) (d:dll t) : GTot Type0 = let nodes = d.nodes in match length nodes with | 0 -> d.lhead == null /\ d.ltail == null | _ -> d.lhead =!= null /\ d.ltail =!= null /\ d.lhead == hd nodes /\ d.ltail == last nodes let piece_ghostly_connections (#t:Type) (p:piece t) : GTot Type0 = let nodes = p.pnodes in match length nodes with | 0 -> False | _ -> p.phead == hd nodes /\ p.ptail == last nodes let rec fragment_ghostly_connections (#t:Type) (f:fragment t) : GTot Type0 = fragment_for_each0 piece_ghostly_connections f /// Containment properties /// /// WARNING: [@@] and [^@] require containment to reasonably talk about /// what they do. let rec nodelist_contained0 (#t:Type) (h0:heap) (nl:nodelist t) : GTot Type0 = match nl with | [] -> True | n :: ns -> h0 `contains` n /\ nodelist_contained0 h0 ns let rec nodelist_contained (#t:Type) (h0:heap) (nl:nodelist t) : GTot Type0 = nodelist_contained0 h0 nl let dll_contained (#t:Type) (h0:heap) (d:dll t) : GTot Type0 = h0 `contains` d.lhead /\ h0 `contains` d.ltail /\ nodelist_contained h0 d.nodes let piece_contained (#t:Type) (h0:heap) (p:piece t) : GTot Type0 = h0 `contains` p.phead /\ h0 `contains` p.ptail /\ nodelist_contained h0 p.pnodes let rec fragment_contained (#t:Type) (h0:heap) (f:fragment t) : GTot Type0 = fragment_for_each1 piece_contained h0 f /// Footprints let node_fp_f (#t:Type) (n:node t) : GTot Mod.loc = Mod.loc_buffer n.flink let node_fp_b (#t:Type) (n:node t) : GTot Mod.loc = Mod.loc_buffer n.blink let rec nodelist_fp0 (#t:Type) (n:nodelist t) : GTot Mod.loc = match n with | [] -> Mod.loc_none | n :: ns -> Mod.loc_union (Mod.loc_buffer n) (nodelist_fp0 ns) let rec nodelist_fp_f (#t:Type) (h0:heap) (n:nodelist t) : GTot Mod.loc = match n with | [] -> Mod.loc_none | n :: ns -> Mod.loc_union (Mod.loc_buffer (n@h0).flink) (nodelist_fp_f h0 ns) let rec nodelist_fp_b (#t:Type) (h0:heap) (n:nodelist t) : GTot Mod.loc = match n with | [] -> Mod.loc_none | n :: ns -> Mod.loc_union (Mod.loc_buffer (n@h0).blink) (nodelist_fp_b h0 ns) let dll_fp0 (#t:Type) (d:dll t) : GTot Mod.loc = Mod.loc_union // ghostly connections should give us this union for // free, but still useful to have (Mod.loc_union (Mod.loc_buffer d.lhead) (Mod.loc_buffer d.ltail)) (nodelist_fp0 d.nodes) let dll_fp_f (#t:Type) (h0:heap) (d:dll t) : GTot Mod.loc = let a = if g_is_null d.lhead then Mod.loc_none else Mod.loc_buffer (d.lhead^@h0).flink in let b = if g_is_null d.ltail then Mod.loc_none else Mod.loc_buffer (d.ltail^@h0).flink in Mod.loc_union // ghostly connections should give us this union for // free, but still useful to have (Mod.loc_union a b) (nodelist_fp_f h0 d.nodes) let dll_fp_b (#t:Type) (h0:heap) (d:dll t) : GTot Mod.loc = let a = if g_is_null d.lhead then Mod.loc_none else Mod.loc_buffer (d.lhead^@h0).blink in let b = if g_is_null d.ltail then Mod.loc_none else Mod.loc_buffer (d.ltail^@h0).blink in Mod.loc_union // ghostly connections should give us this union for // free, but still useful to have (Mod.loc_union a b) (nodelist_fp_b h0 d.nodes) let piece_fp0 (#t:Type) (p:piece t) : GTot Mod.loc = Mod.loc_union // ghostly connections should give us this union for // free, but still useful to have (Mod.loc_union (Mod.loc_buffer p.phead) (Mod.loc_buffer p.ptail)) (nodelist_fp0 p.pnodes) let piece_fp_f (#t:Type) (h0:heap) (p:piece t) : GTot Mod.loc = Mod.loc_union // ghostly connections should give us this union for // free, but still useful to have (Mod.loc_union (Mod.loc_buffer (p.phead@h0).flink) (Mod.loc_buffer (p.ptail@h0).flink)) (nodelist_fp_f h0 p.pnodes) let piece_fp_b (#t:Type) (h0:heap) (p:piece t) : GTot Mod.loc = Mod.loc_union // ghostly connections should give us this union for // free, but still useful to have (Mod.loc_union (Mod.loc_buffer (p.phead@h0).blink) (Mod.loc_buffer (p.ptail@h0).blink)) (nodelist_fp_b h0 p.pnodes) let rec fragment_fp0 (#t:Type) (f:fragment t) : GTot Mod.loc = match f with | Frag0 -> Mod.loc_none | Frag1 p1 -> piece_fp0 p1 | Frag2 p1 p2 -> Mod.loc_union (piece_fp0 p1) (piece_fp0 p2) | Frag3 p1 p2 p3 -> Mod.loc_union (piece_fp0 p1) (Mod.loc_union (piece_fp0 p2) (piece_fp0 p3)) /// Helper patterns for footprints let loc_includes_union_l_nodelist_fp0 (#t: Type) (s1 s2:loc) (nl:nodelist t) : Lemma (requires (loc_includes s1 (nodelist_fp0 nl) \/ loc_includes s2 (nodelist_fp0 nl))) (ensures (loc_includes (loc_union s1 s2) (nodelist_fp0 nl))) [SMTPat (loc_includes (loc_union s1 s2) (nodelist_fp0 nl))] = loc_includes_union_l s1 s2 (nodelist_fp0 nl) let loc_includes_union_l_dll_fp0 (#t: Type) (s1 s2:loc) (d:dll t) : Lemma (requires (loc_includes s1 (dll_fp0 d) \/ loc_includes s2 (dll_fp0 d))) (ensures (loc_includes (loc_union s1 s2) (dll_fp0 d))) [SMTPat (loc_includes (loc_union s1 s2) (dll_fp0 d))] = loc_includes_union_l s1 s2 (dll_fp0 d) let loc_includes_union_l_piece_fp0 (#t: Type) (s1 s2:loc) (p:piece t) : Lemma (requires (loc_includes s1 (piece_fp0 p) \/ loc_includes s2 (piece_fp0 p))) (ensures (loc_includes (loc_union s1 s2) (piece_fp0 p))) [SMTPat (loc_includes (loc_union s1 s2) (piece_fp0 p))] = loc_includes_union_l s1 s2 (piece_fp0 p) let loc_includes_union_l_fragment_fp0 (#t: Type) (s1 s2:loc) (f:fragment t) : Lemma (requires (loc_includes s1 (fragment_fp0 f) \/ loc_includes s2 (fragment_fp0 f))) (ensures (loc_includes (loc_union s1 s2) (fragment_fp0 f))) [SMTPat (loc_includes (loc_union s1 s2) (fragment_fp0 f))] = loc_includes_union_l s1 s2 (fragment_fp0 f) /// Equivalence for locations let loc_equiv (a b:Mod.loc) = Mod.loc_includes a b /\ Mod.loc_includes b a let loc_equiv_trans (a b c:Mod.loc) : Lemma (requires (loc_equiv a b /\ loc_equiv b c)) (ensures (loc_equiv a c)) [SMTPat (loc_equiv a b); SMTPat (loc_equiv b c); SMTPat (loc_equiv a c)] = Mod.loc_includes_trans a b c; Mod.loc_includes_trans c b a let loc_equiv_union_union_loc (a b c:Mod.loc) : Lemma (requires (loc_equiv b c)) (ensures (loc_equiv (Mod.loc_union a b) (Mod.loc_union a c))) [SMTPat (loc_equiv (Mod.loc_union a b) (Mod.loc_union a c))] = let incl = Mod.loc_includes in let u = Mod.loc_union in // assert (b `incl` c); Mod.loc_includes_union_l a b c; // assert ((a `u` b) `incl` c); Mod.loc_includes_union_l a b a; // assert ((a `u` b) `incl` a); // assert ((a `u` b) `incl` (a `u` c)); Mod.loc_includes_union_l a c b; Mod.loc_includes_union_l a c a /// Anti aliasing properties let node_aa (#t:Type) (n:node t) : GTot Type0 = Mod.loc_disjoint (node_fp_f n) (node_fp_b n) let rec nodelist_aa_r (#t:Type) (nl:nodelist t) : GTot Type0 = match nl with | [] -> True | n :: ns -> Mod.loc_disjoint (Mod.loc_buffer n) (nodelist_fp0 ns) /\ nodelist_aa_r ns let rec nodelist_aa_l (#t:Type) (nl:nodelist t) : GTot Type0 (decreases (length nl)) = match nl with | [] -> True | _ -> let ns, n = unsnoc nl in lemma_unsnoc_length nl; Mod.loc_disjoint (Mod.loc_buffer n) (nodelist_fp0 ns) /\ nodelist_aa_l ns let nodelist_aa (#t:Type) (nl:nodelist t) : GTot Type0 = nodelist_aa_l nl /\ nodelist_aa_r nl let dll_aa (#t:Type) (d:dll t) : GTot Type0 = nodelist_aa d.nodes let piece_aa (#t:Type) (p:piece t) : GTot Type0 = nodelist_aa p.pnodes let rec fragment_aa0 (#t:Type) (f:fragment t) : GTot Type0 = fragment_for_each0 piece_aa f let rec fragment_aa_lr (#t:Type) (f:fragment t) : GTot Type0 = match f with | Frag0 -> True | Frag1 p1 -> True | Frag2 p1 p2 -> Mod.loc_disjoint (piece_fp0 p1) (piece_fp0 p2) | Frag3 p1 p2 p3 -> ((Mod.loc_disjoint (piece_fp0 p1) (piece_fp0 p2)) /\ (Mod.loc_disjoint (piece_fp0 p2) (piece_fp0 p3)) /\
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowStar.ModifiesPat.fst.checked", "LowStar.Modifies.fst.checked", "LowStar.BufferOps.fst.checked", "LowStar.Buffer.fst.checked", "FStar.UInt32.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked", "FStar.List.Pure.Properties.fst.checked", "FStar.List.Pure.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked", "FStar.Classical.fsti.checked" ], "interface_file": false, "source_file": "DoublyLinkedList.fst" }
[ { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": true, "full_module": "LowStar.Modifies", "short_module": "Mod" }, { "abbrev": false, "full_module": "LowStar.BufferOps", "short_module": null }, { "abbrev": false, "full_module": "FStar.List.Pure", "short_module": null }, { "abbrev": false, "full_module": "FStar.List.Tot", "short_module": null }, { "abbrev": false, "full_module": "LowStar.ModifiesPat", "short_module": null }, { "abbrev": false, "full_module": "FStar.Ghost", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
f: DoublyLinkedList.fragment t -> Prims.GTot Type0
Prims.GTot
[ "sometrivial" ]
[]
[ "DoublyLinkedList.fragment", "Prims.l_and", "DoublyLinkedList.fragment_aa0", "DoublyLinkedList.fragment_aa_lr" ]
[]
false
false
false
false
true
let fragment_aa (#t: Type) (f: fragment t) : GTot Type0 =
fragment_aa0 f /\ fragment_aa_lr f
false
DoublyLinkedList.fst
DoublyLinkedList.fragment_for_each1
val fragment_for_each1 (#t #u: Type) (pr: (u -> piece t -> GTot Type0)) (v: u) (f: fragment t) : GTot Type0
val fragment_for_each1 (#t #u: Type) (pr: (u -> piece t -> GTot Type0)) (v: u) (f: fragment t) : GTot Type0
let fragment_for_each1 (#t:Type) (#u:Type) (pr:u -> piece t -> GTot Type0) (v:u) (f:fragment t) : GTot Type0 = match f with | Frag0 -> True | Frag1 p1 -> pr v p1 | Frag2 p1 p2 -> pr v p1 /\ pr v p2 | Frag3 p1 p2 p3 -> pr v p1 /\ pr v p2 /\ pr v p3
{ "file_name": "examples/doublylinkedlist/DoublyLinkedList.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 51, "end_line": 128, "start_col": 0, "start_line": 123 }
(* Copyright 2008-2019 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module DoublyLinkedList open FStar open FStar.HyperStack.ST open FStar.Ghost open LowStar.ModifiesPat open FStar.List.Tot open FStar.List.Pure open LowStar.BufferOps module Mod = LowStar.Modifies module ST = FStar.HyperStack.ST module HS = FStar.HyperStack module B = LowStar.Buffer /// Convenience renaming unfold let heap = HS.mem unfold let contains #a #rrel #rel h b = B.live #a #rrel #rel h b /// Convenience patterns let lemma_non_null (#t:Type) (a:pointer_or_null t) : Lemma (requires (a =!= null)) (ensures (len a = 1ul)) [SMTPat (len a)] = null_unique a /// Convenience operators unfold let (.[]) (s:list 'a) (n:nat{n < length s}) = index s n unfold let (~.) (#t:Type) (a:t) : Tot (erased (list t)) = [a] unfold let (^+) (#t:Type) (a:t) (b:erased (list t)) : Tot (erased (list t)) = Cons a b unfold let (+^) (#t:Type) (a:erased (list t)) (b:t) : Tot (erased (list t)) = append a [b] unfold let (^@^) (#t:Type) (a:erased (list t)) (b:erased (list t)) : Tot (erased (list t)) = append a b unfold let (@) (a:pointer 't) (h0:heap) = B.get h0 a 0 unfold let (^@) (a:pointer_or_null 't{a =!= null}) (h0:heap) = B.get h0 a 0 /// All the data structures #set-options "--__no_positivity" unopteq (** Node of a doubly linked list *) type node (t:Type0) = { (* forward link *) flink: pointer_or_null (node t); (* backward link *) blink: pointer_or_null (node t); (* payload *) p: t; } #reset-options private type nodelist t = list (pointer (node t)) unopteq (** Doubly linked list head *) type dll (t:Type0) ={ lhead: pointer_or_null (node t); ltail: pointer_or_null (node t); nodes: erased (nodelist t); } type nonempty_dll t = (h:dll t{h.lhead =!= null /\ h.ltail =!= null}) unopteq private (** An "almost valid" dll *) type piece t = { phead: pointer (node t); ptail: pointer (node t); pnodes: erased (nodelist t); } unopteq private (** An intermediate for when linked lists are being formed or destroyed *) type fragment t = | Frag0 : fragment t | Frag1 : piece t -> fragment t | Frag2 : piece t -> piece t -> fragment t | Frag3 : piece t -> piece t -> piece t -> fragment t /// Some useful empty initializers (** Initialize an element of a doubly linked list *) val empty_node: #t:Type -> payload:t -> node t let empty_node #t payload = { flink = null ; blink = null ; p = payload } (** Initialize a doubly linked list head *) val empty_list: #t:Type -> dll t let empty_list #t = { lhead = null ; ltail = null ; nodes = [] } /// Convenience wrappers for writing properties on fragments let fragment_for_each0 (#t:Type) (pr:piece t -> GTot Type0) (f:fragment t) : GTot Type0 = match f with | Frag0 -> True | Frag1 p1 -> pr p1 | Frag2 p1 p2 -> pr p1 /\ pr p2 | Frag3 p1 p2 p3 -> pr p1 /\ pr p2 /\ pr p3
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowStar.ModifiesPat.fst.checked", "LowStar.Modifies.fst.checked", "LowStar.BufferOps.fst.checked", "LowStar.Buffer.fst.checked", "FStar.UInt32.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked", "FStar.List.Pure.Properties.fst.checked", "FStar.List.Pure.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked", "FStar.Classical.fsti.checked" ], "interface_file": false, "source_file": "DoublyLinkedList.fst" }
[ { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": true, "full_module": "LowStar.Modifies", "short_module": "Mod" }, { "abbrev": false, "full_module": "LowStar.BufferOps", "short_module": null }, { "abbrev": false, "full_module": "FStar.List.Pure", "short_module": null }, { "abbrev": false, "full_module": "FStar.List.Tot", "short_module": null }, { "abbrev": false, "full_module": "LowStar.ModifiesPat", "short_module": null }, { "abbrev": false, "full_module": "FStar.Ghost", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
pr: (_: u244 -> _: DoublyLinkedList.piece t -> Prims.GTot Type0) -> v: u244 -> f: DoublyLinkedList.fragment t -> Prims.GTot Type0
Prims.GTot
[ "sometrivial" ]
[]
[ "DoublyLinkedList.piece", "DoublyLinkedList.fragment", "Prims.l_True", "Prims.l_and" ]
[]
false
false
false
false
true
let fragment_for_each1 (#t #u: Type) (pr: (u -> piece t -> GTot Type0)) (v: u) (f: fragment t) : GTot Type0 =
match f with | Frag0 -> True | Frag1 p1 -> pr v p1 | Frag2 p1 p2 -> pr v p1 /\ pr v p2 | Frag3 p1 p2 p3 -> pr v p1 /\ pr v p2 /\ pr v p3
false
DoublyLinkedList.fst
DoublyLinkedList.loc_includes_union_l_dll_fp0
val loc_includes_union_l_dll_fp0 (#t: Type) (s1 s2: loc) (d: dll t) : Lemma (requires (loc_includes s1 (dll_fp0 d) \/ loc_includes s2 (dll_fp0 d))) (ensures (loc_includes (loc_union s1 s2) (dll_fp0 d))) [SMTPat (loc_includes (loc_union s1 s2) (dll_fp0 d))]
val loc_includes_union_l_dll_fp0 (#t: Type) (s1 s2: loc) (d: dll t) : Lemma (requires (loc_includes s1 (dll_fp0 d) \/ loc_includes s2 (dll_fp0 d))) (ensures (loc_includes (loc_union s1 s2) (dll_fp0 d))) [SMTPat (loc_includes (loc_union s1 s2) (dll_fp0 d))]
let loc_includes_union_l_dll_fp0 (#t: Type) (s1 s2:loc) (d:dll t) : Lemma (requires (loc_includes s1 (dll_fp0 d) \/ loc_includes s2 (dll_fp0 d))) (ensures (loc_includes (loc_union s1 s2) (dll_fp0 d))) [SMTPat (loc_includes (loc_union s1 s2) (dll_fp0 d))] = loc_includes_union_l s1 s2 (dll_fp0 d)
{ "file_name": "examples/doublylinkedlist/DoublyLinkedList.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 40, "end_line": 259, "start_col": 0, "start_line": 254 }
(* Copyright 2008-2019 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module DoublyLinkedList open FStar open FStar.HyperStack.ST open FStar.Ghost open LowStar.ModifiesPat open FStar.List.Tot open FStar.List.Pure open LowStar.BufferOps module Mod = LowStar.Modifies module ST = FStar.HyperStack.ST module HS = FStar.HyperStack module B = LowStar.Buffer /// Convenience renaming unfold let heap = HS.mem unfold let contains #a #rrel #rel h b = B.live #a #rrel #rel h b /// Convenience patterns let lemma_non_null (#t:Type) (a:pointer_or_null t) : Lemma (requires (a =!= null)) (ensures (len a = 1ul)) [SMTPat (len a)] = null_unique a /// Convenience operators unfold let (.[]) (s:list 'a) (n:nat{n < length s}) = index s n unfold let (~.) (#t:Type) (a:t) : Tot (erased (list t)) = [a] unfold let (^+) (#t:Type) (a:t) (b:erased (list t)) : Tot (erased (list t)) = Cons a b unfold let (+^) (#t:Type) (a:erased (list t)) (b:t) : Tot (erased (list t)) = append a [b] unfold let (^@^) (#t:Type) (a:erased (list t)) (b:erased (list t)) : Tot (erased (list t)) = append a b unfold let (@) (a:pointer 't) (h0:heap) = B.get h0 a 0 unfold let (^@) (a:pointer_or_null 't{a =!= null}) (h0:heap) = B.get h0 a 0 /// All the data structures #set-options "--__no_positivity" unopteq (** Node of a doubly linked list *) type node (t:Type0) = { (* forward link *) flink: pointer_or_null (node t); (* backward link *) blink: pointer_or_null (node t); (* payload *) p: t; } #reset-options private type nodelist t = list (pointer (node t)) unopteq (** Doubly linked list head *) type dll (t:Type0) ={ lhead: pointer_or_null (node t); ltail: pointer_or_null (node t); nodes: erased (nodelist t); } type nonempty_dll t = (h:dll t{h.lhead =!= null /\ h.ltail =!= null}) unopteq private (** An "almost valid" dll *) type piece t = { phead: pointer (node t); ptail: pointer (node t); pnodes: erased (nodelist t); } unopteq private (** An intermediate for when linked lists are being formed or destroyed *) type fragment t = | Frag0 : fragment t | Frag1 : piece t -> fragment t | Frag2 : piece t -> piece t -> fragment t | Frag3 : piece t -> piece t -> piece t -> fragment t /// Some useful empty initializers (** Initialize an element of a doubly linked list *) val empty_node: #t:Type -> payload:t -> node t let empty_node #t payload = { flink = null ; blink = null ; p = payload } (** Initialize a doubly linked list head *) val empty_list: #t:Type -> dll t let empty_list #t = { lhead = null ; ltail = null ; nodes = [] } /// Convenience wrappers for writing properties on fragments let fragment_for_each0 (#t:Type) (pr:piece t -> GTot Type0) (f:fragment t) : GTot Type0 = match f with | Frag0 -> True | Frag1 p1 -> pr p1 | Frag2 p1 p2 -> pr p1 /\ pr p2 | Frag3 p1 p2 p3 -> pr p1 /\ pr p2 /\ pr p3 let fragment_for_each1 (#t:Type) (#u:Type) (pr:u -> piece t -> GTot Type0) (v:u) (f:fragment t) : GTot Type0 = match f with | Frag0 -> True | Frag1 p1 -> pr v p1 | Frag2 p1 p2 -> pr v p1 /\ pr v p2 | Frag3 p1 p2 p3 -> pr v p1 /\ pr v p2 /\ pr v p3 let fragment_length (#t:Type) (f:fragment t) : GTot int = match f with | Frag0 -> 0 | Frag1 _ -> 1 | Frag2 _ _ -> 2 | Frag3 _ _ _ -> 3 /// Ghostly connections let dll_ghostly_connections (#t:Type) (d:dll t) : GTot Type0 = let nodes = d.nodes in match length nodes with | 0 -> d.lhead == null /\ d.ltail == null | _ -> d.lhead =!= null /\ d.ltail =!= null /\ d.lhead == hd nodes /\ d.ltail == last nodes let piece_ghostly_connections (#t:Type) (p:piece t) : GTot Type0 = let nodes = p.pnodes in match length nodes with | 0 -> False | _ -> p.phead == hd nodes /\ p.ptail == last nodes let rec fragment_ghostly_connections (#t:Type) (f:fragment t) : GTot Type0 = fragment_for_each0 piece_ghostly_connections f /// Containment properties /// /// WARNING: [@@] and [^@] require containment to reasonably talk about /// what they do. let rec nodelist_contained0 (#t:Type) (h0:heap) (nl:nodelist t) : GTot Type0 = match nl with | [] -> True | n :: ns -> h0 `contains` n /\ nodelist_contained0 h0 ns let rec nodelist_contained (#t:Type) (h0:heap) (nl:nodelist t) : GTot Type0 = nodelist_contained0 h0 nl let dll_contained (#t:Type) (h0:heap) (d:dll t) : GTot Type0 = h0 `contains` d.lhead /\ h0 `contains` d.ltail /\ nodelist_contained h0 d.nodes let piece_contained (#t:Type) (h0:heap) (p:piece t) : GTot Type0 = h0 `contains` p.phead /\ h0 `contains` p.ptail /\ nodelist_contained h0 p.pnodes let rec fragment_contained (#t:Type) (h0:heap) (f:fragment t) : GTot Type0 = fragment_for_each1 piece_contained h0 f /// Footprints let node_fp_f (#t:Type) (n:node t) : GTot Mod.loc = Mod.loc_buffer n.flink let node_fp_b (#t:Type) (n:node t) : GTot Mod.loc = Mod.loc_buffer n.blink let rec nodelist_fp0 (#t:Type) (n:nodelist t) : GTot Mod.loc = match n with | [] -> Mod.loc_none | n :: ns -> Mod.loc_union (Mod.loc_buffer n) (nodelist_fp0 ns) let rec nodelist_fp_f (#t:Type) (h0:heap) (n:nodelist t) : GTot Mod.loc = match n with | [] -> Mod.loc_none | n :: ns -> Mod.loc_union (Mod.loc_buffer (n@h0).flink) (nodelist_fp_f h0 ns) let rec nodelist_fp_b (#t:Type) (h0:heap) (n:nodelist t) : GTot Mod.loc = match n with | [] -> Mod.loc_none | n :: ns -> Mod.loc_union (Mod.loc_buffer (n@h0).blink) (nodelist_fp_b h0 ns) let dll_fp0 (#t:Type) (d:dll t) : GTot Mod.loc = Mod.loc_union // ghostly connections should give us this union for // free, but still useful to have (Mod.loc_union (Mod.loc_buffer d.lhead) (Mod.loc_buffer d.ltail)) (nodelist_fp0 d.nodes) let dll_fp_f (#t:Type) (h0:heap) (d:dll t) : GTot Mod.loc = let a = if g_is_null d.lhead then Mod.loc_none else Mod.loc_buffer (d.lhead^@h0).flink in let b = if g_is_null d.ltail then Mod.loc_none else Mod.loc_buffer (d.ltail^@h0).flink in Mod.loc_union // ghostly connections should give us this union for // free, but still useful to have (Mod.loc_union a b) (nodelist_fp_f h0 d.nodes) let dll_fp_b (#t:Type) (h0:heap) (d:dll t) : GTot Mod.loc = let a = if g_is_null d.lhead then Mod.loc_none else Mod.loc_buffer (d.lhead^@h0).blink in let b = if g_is_null d.ltail then Mod.loc_none else Mod.loc_buffer (d.ltail^@h0).blink in Mod.loc_union // ghostly connections should give us this union for // free, but still useful to have (Mod.loc_union a b) (nodelist_fp_b h0 d.nodes) let piece_fp0 (#t:Type) (p:piece t) : GTot Mod.loc = Mod.loc_union // ghostly connections should give us this union for // free, but still useful to have (Mod.loc_union (Mod.loc_buffer p.phead) (Mod.loc_buffer p.ptail)) (nodelist_fp0 p.pnodes) let piece_fp_f (#t:Type) (h0:heap) (p:piece t) : GTot Mod.loc = Mod.loc_union // ghostly connections should give us this union for // free, but still useful to have (Mod.loc_union (Mod.loc_buffer (p.phead@h0).flink) (Mod.loc_buffer (p.ptail@h0).flink)) (nodelist_fp_f h0 p.pnodes) let piece_fp_b (#t:Type) (h0:heap) (p:piece t) : GTot Mod.loc = Mod.loc_union // ghostly connections should give us this union for // free, but still useful to have (Mod.loc_union (Mod.loc_buffer (p.phead@h0).blink) (Mod.loc_buffer (p.ptail@h0).blink)) (nodelist_fp_b h0 p.pnodes) let rec fragment_fp0 (#t:Type) (f:fragment t) : GTot Mod.loc = match f with | Frag0 -> Mod.loc_none | Frag1 p1 -> piece_fp0 p1 | Frag2 p1 p2 -> Mod.loc_union (piece_fp0 p1) (piece_fp0 p2) | Frag3 p1 p2 p3 -> Mod.loc_union (piece_fp0 p1) (Mod.loc_union (piece_fp0 p2) (piece_fp0 p3)) /// Helper patterns for footprints let loc_includes_union_l_nodelist_fp0 (#t: Type) (s1 s2:loc) (nl:nodelist t) : Lemma (requires (loc_includes s1 (nodelist_fp0 nl) \/ loc_includes s2 (nodelist_fp0 nl))) (ensures (loc_includes (loc_union s1 s2) (nodelist_fp0 nl))) [SMTPat (loc_includes (loc_union s1 s2) (nodelist_fp0 nl))] = loc_includes_union_l s1 s2 (nodelist_fp0 nl)
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowStar.ModifiesPat.fst.checked", "LowStar.Modifies.fst.checked", "LowStar.BufferOps.fst.checked", "LowStar.Buffer.fst.checked", "FStar.UInt32.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked", "FStar.List.Pure.Properties.fst.checked", "FStar.List.Pure.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked", "FStar.Classical.fsti.checked" ], "interface_file": false, "source_file": "DoublyLinkedList.fst" }
[ { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": true, "full_module": "LowStar.Modifies", "short_module": "Mod" }, { "abbrev": false, "full_module": "LowStar.BufferOps", "short_module": null }, { "abbrev": false, "full_module": "FStar.List.Pure", "short_module": null }, { "abbrev": false, "full_module": "FStar.List.Tot", "short_module": null }, { "abbrev": false, "full_module": "LowStar.ModifiesPat", "short_module": null }, { "abbrev": false, "full_module": "FStar.Ghost", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
s1: LowStar.Monotonic.Buffer.loc -> s2: LowStar.Monotonic.Buffer.loc -> d: DoublyLinkedList.dll t -> FStar.Pervasives.Lemma (requires LowStar.Monotonic.Buffer.loc_includes s1 (DoublyLinkedList.dll_fp0 d) \/ LowStar.Monotonic.Buffer.loc_includes s2 (DoublyLinkedList.dll_fp0 d)) (ensures LowStar.Monotonic.Buffer.loc_includes (LowStar.Monotonic.Buffer.loc_union s1 s2) (DoublyLinkedList.dll_fp0 d)) [ SMTPat (LowStar.Monotonic.Buffer.loc_includes (LowStar.Monotonic.Buffer.loc_union s1 s2) (DoublyLinkedList.dll_fp0 d)) ]
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "LowStar.Monotonic.Buffer.loc", "DoublyLinkedList.dll", "LowStar.Monotonic.Buffer.loc_includes_union_l", "DoublyLinkedList.dll_fp0", "Prims.unit", "Prims.l_or", "LowStar.Monotonic.Buffer.loc_includes", "Prims.squash", "LowStar.Monotonic.Buffer.loc_union", "Prims.Cons", "FStar.Pervasives.pattern", "FStar.Pervasives.smt_pat", "Prims.Nil" ]
[]
true
false
true
false
false
let loc_includes_union_l_dll_fp0 (#t: Type) (s1 s2: loc) (d: dll t) : Lemma (requires (loc_includes s1 (dll_fp0 d) \/ loc_includes s2 (dll_fp0 d))) (ensures (loc_includes (loc_union s1 s2) (dll_fp0 d))) [SMTPat (loc_includes (loc_union s1 s2) (dll_fp0 d))] =
loc_includes_union_l s1 s2 (dll_fp0 d)
false
DoublyLinkedList.fst
DoublyLinkedList.dll_fp_b
val dll_fp_b (#t: Type) (h0: heap) (d: dll t) : GTot Mod.loc
val dll_fp_b (#t: Type) (h0: heap) (d: dll t) : GTot Mod.loc
let dll_fp_b (#t:Type) (h0:heap) (d:dll t) : GTot Mod.loc = let a = if g_is_null d.lhead then Mod.loc_none else Mod.loc_buffer (d.lhead^@h0).blink in let b = if g_is_null d.ltail then Mod.loc_none else Mod.loc_buffer (d.ltail^@h0).blink in Mod.loc_union // ghostly connections should give us this union for // free, but still useful to have (Mod.loc_union a b) (nodelist_fp_b h0 d.nodes)
{ "file_name": "examples/doublylinkedlist/DoublyLinkedList.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 30, "end_line": 220, "start_col": 0, "start_line": 214 }
(* Copyright 2008-2019 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module DoublyLinkedList open FStar open FStar.HyperStack.ST open FStar.Ghost open LowStar.ModifiesPat open FStar.List.Tot open FStar.List.Pure open LowStar.BufferOps module Mod = LowStar.Modifies module ST = FStar.HyperStack.ST module HS = FStar.HyperStack module B = LowStar.Buffer /// Convenience renaming unfold let heap = HS.mem unfold let contains #a #rrel #rel h b = B.live #a #rrel #rel h b /// Convenience patterns let lemma_non_null (#t:Type) (a:pointer_or_null t) : Lemma (requires (a =!= null)) (ensures (len a = 1ul)) [SMTPat (len a)] = null_unique a /// Convenience operators unfold let (.[]) (s:list 'a) (n:nat{n < length s}) = index s n unfold let (~.) (#t:Type) (a:t) : Tot (erased (list t)) = [a] unfold let (^+) (#t:Type) (a:t) (b:erased (list t)) : Tot (erased (list t)) = Cons a b unfold let (+^) (#t:Type) (a:erased (list t)) (b:t) : Tot (erased (list t)) = append a [b] unfold let (^@^) (#t:Type) (a:erased (list t)) (b:erased (list t)) : Tot (erased (list t)) = append a b unfold let (@) (a:pointer 't) (h0:heap) = B.get h0 a 0 unfold let (^@) (a:pointer_or_null 't{a =!= null}) (h0:heap) = B.get h0 a 0 /// All the data structures #set-options "--__no_positivity" unopteq (** Node of a doubly linked list *) type node (t:Type0) = { (* forward link *) flink: pointer_or_null (node t); (* backward link *) blink: pointer_or_null (node t); (* payload *) p: t; } #reset-options private type nodelist t = list (pointer (node t)) unopteq (** Doubly linked list head *) type dll (t:Type0) ={ lhead: pointer_or_null (node t); ltail: pointer_or_null (node t); nodes: erased (nodelist t); } type nonempty_dll t = (h:dll t{h.lhead =!= null /\ h.ltail =!= null}) unopteq private (** An "almost valid" dll *) type piece t = { phead: pointer (node t); ptail: pointer (node t); pnodes: erased (nodelist t); } unopteq private (** An intermediate for when linked lists are being formed or destroyed *) type fragment t = | Frag0 : fragment t | Frag1 : piece t -> fragment t | Frag2 : piece t -> piece t -> fragment t | Frag3 : piece t -> piece t -> piece t -> fragment t /// Some useful empty initializers (** Initialize an element of a doubly linked list *) val empty_node: #t:Type -> payload:t -> node t let empty_node #t payload = { flink = null ; blink = null ; p = payload } (** Initialize a doubly linked list head *) val empty_list: #t:Type -> dll t let empty_list #t = { lhead = null ; ltail = null ; nodes = [] } /// Convenience wrappers for writing properties on fragments let fragment_for_each0 (#t:Type) (pr:piece t -> GTot Type0) (f:fragment t) : GTot Type0 = match f with | Frag0 -> True | Frag1 p1 -> pr p1 | Frag2 p1 p2 -> pr p1 /\ pr p2 | Frag3 p1 p2 p3 -> pr p1 /\ pr p2 /\ pr p3 let fragment_for_each1 (#t:Type) (#u:Type) (pr:u -> piece t -> GTot Type0) (v:u) (f:fragment t) : GTot Type0 = match f with | Frag0 -> True | Frag1 p1 -> pr v p1 | Frag2 p1 p2 -> pr v p1 /\ pr v p2 | Frag3 p1 p2 p3 -> pr v p1 /\ pr v p2 /\ pr v p3 let fragment_length (#t:Type) (f:fragment t) : GTot int = match f with | Frag0 -> 0 | Frag1 _ -> 1 | Frag2 _ _ -> 2 | Frag3 _ _ _ -> 3 /// Ghostly connections let dll_ghostly_connections (#t:Type) (d:dll t) : GTot Type0 = let nodes = d.nodes in match length nodes with | 0 -> d.lhead == null /\ d.ltail == null | _ -> d.lhead =!= null /\ d.ltail =!= null /\ d.lhead == hd nodes /\ d.ltail == last nodes let piece_ghostly_connections (#t:Type) (p:piece t) : GTot Type0 = let nodes = p.pnodes in match length nodes with | 0 -> False | _ -> p.phead == hd nodes /\ p.ptail == last nodes let rec fragment_ghostly_connections (#t:Type) (f:fragment t) : GTot Type0 = fragment_for_each0 piece_ghostly_connections f /// Containment properties /// /// WARNING: [@@] and [^@] require containment to reasonably talk about /// what they do. let rec nodelist_contained0 (#t:Type) (h0:heap) (nl:nodelist t) : GTot Type0 = match nl with | [] -> True | n :: ns -> h0 `contains` n /\ nodelist_contained0 h0 ns let rec nodelist_contained (#t:Type) (h0:heap) (nl:nodelist t) : GTot Type0 = nodelist_contained0 h0 nl let dll_contained (#t:Type) (h0:heap) (d:dll t) : GTot Type0 = h0 `contains` d.lhead /\ h0 `contains` d.ltail /\ nodelist_contained h0 d.nodes let piece_contained (#t:Type) (h0:heap) (p:piece t) : GTot Type0 = h0 `contains` p.phead /\ h0 `contains` p.ptail /\ nodelist_contained h0 p.pnodes let rec fragment_contained (#t:Type) (h0:heap) (f:fragment t) : GTot Type0 = fragment_for_each1 piece_contained h0 f /// Footprints let node_fp_f (#t:Type) (n:node t) : GTot Mod.loc = Mod.loc_buffer n.flink let node_fp_b (#t:Type) (n:node t) : GTot Mod.loc = Mod.loc_buffer n.blink let rec nodelist_fp0 (#t:Type) (n:nodelist t) : GTot Mod.loc = match n with | [] -> Mod.loc_none | n :: ns -> Mod.loc_union (Mod.loc_buffer n) (nodelist_fp0 ns) let rec nodelist_fp_f (#t:Type) (h0:heap) (n:nodelist t) : GTot Mod.loc = match n with | [] -> Mod.loc_none | n :: ns -> Mod.loc_union (Mod.loc_buffer (n@h0).flink) (nodelist_fp_f h0 ns) let rec nodelist_fp_b (#t:Type) (h0:heap) (n:nodelist t) : GTot Mod.loc = match n with | [] -> Mod.loc_none | n :: ns -> Mod.loc_union (Mod.loc_buffer (n@h0).blink) (nodelist_fp_b h0 ns) let dll_fp0 (#t:Type) (d:dll t) : GTot Mod.loc = Mod.loc_union // ghostly connections should give us this union for // free, but still useful to have (Mod.loc_union (Mod.loc_buffer d.lhead) (Mod.loc_buffer d.ltail)) (nodelist_fp0 d.nodes) let dll_fp_f (#t:Type) (h0:heap) (d:dll t) : GTot Mod.loc = let a = if g_is_null d.lhead then Mod.loc_none else Mod.loc_buffer (d.lhead^@h0).flink in let b = if g_is_null d.ltail then Mod.loc_none else Mod.loc_buffer (d.ltail^@h0).flink in Mod.loc_union // ghostly connections should give us this union for // free, but still useful to have (Mod.loc_union a b)
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowStar.ModifiesPat.fst.checked", "LowStar.Modifies.fst.checked", "LowStar.BufferOps.fst.checked", "LowStar.Buffer.fst.checked", "FStar.UInt32.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked", "FStar.List.Pure.Properties.fst.checked", "FStar.List.Pure.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked", "FStar.Classical.fsti.checked" ], "interface_file": false, "source_file": "DoublyLinkedList.fst" }
[ { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": true, "full_module": "LowStar.Modifies", "short_module": "Mod" }, { "abbrev": false, "full_module": "LowStar.BufferOps", "short_module": null }, { "abbrev": false, "full_module": "FStar.List.Pure", "short_module": null }, { "abbrev": false, "full_module": "FStar.List.Tot", "short_module": null }, { "abbrev": false, "full_module": "LowStar.ModifiesPat", "short_module": null }, { "abbrev": false, "full_module": "FStar.Ghost", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
h0: DoublyLinkedList.heap -> d: DoublyLinkedList.dll t -> Prims.GTot LowStar.Monotonic.Buffer.loc
Prims.GTot
[ "sometrivial" ]
[]
[ "DoublyLinkedList.heap", "DoublyLinkedList.dll", "LowStar.Monotonic.Buffer.loc_union", "DoublyLinkedList.nodelist_fp_b", "FStar.Ghost.reveal", "DoublyLinkedList.nodelist", "DoublyLinkedList.__proj__Mkdll__item__nodes", "LowStar.Monotonic.Buffer.loc", "LowStar.Monotonic.Buffer.g_is_null", "DoublyLinkedList.node", "LowStar.Buffer.trivial_preorder", "DoublyLinkedList.__proj__Mkdll__item__ltail", "LowStar.Monotonic.Buffer.loc_none", "Prims.bool", "LowStar.Monotonic.Buffer.loc_buffer", "DoublyLinkedList.__proj__Mknode__item__blink", "DoublyLinkedList.op_Hat_At", "DoublyLinkedList.__proj__Mkdll__item__lhead" ]
[]
false
false
false
false
false
let dll_fp_b (#t: Type) (h0: heap) (d: dll t) : GTot Mod.loc =
let a = if g_is_null d.lhead then Mod.loc_none else Mod.loc_buffer (d.lhead ^@ h0).blink in let b = if g_is_null d.ltail then Mod.loc_none else Mod.loc_buffer (d.ltail ^@ h0).blink in Mod.loc_union (Mod.loc_union a b) (nodelist_fp_b h0 d.nodes)
false
DoublyLinkedList.fst
DoublyLinkedList.piece_valid
val piece_valid (#t: Type) (h0: heap) (p: piece t) : GTot Type0
val piece_valid (#t: Type) (h0: heap) (p: piece t) : GTot Type0
let piece_valid (#t:Type) (h0:heap) (p:piece t) : GTot Type0 = piece_ghostly_connections p /\ piece_contained h0 p /\ piece_aa p /\ piece_conn h0 p
{ "file_name": "examples/doublylinkedlist/DoublyLinkedList.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 17, "end_line": 401, "start_col": 0, "start_line": 397 }
(* Copyright 2008-2019 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module DoublyLinkedList open FStar open FStar.HyperStack.ST open FStar.Ghost open LowStar.ModifiesPat open FStar.List.Tot open FStar.List.Pure open LowStar.BufferOps module Mod = LowStar.Modifies module ST = FStar.HyperStack.ST module HS = FStar.HyperStack module B = LowStar.Buffer /// Convenience renaming unfold let heap = HS.mem unfold let contains #a #rrel #rel h b = B.live #a #rrel #rel h b /// Convenience patterns let lemma_non_null (#t:Type) (a:pointer_or_null t) : Lemma (requires (a =!= null)) (ensures (len a = 1ul)) [SMTPat (len a)] = null_unique a /// Convenience operators unfold let (.[]) (s:list 'a) (n:nat{n < length s}) = index s n unfold let (~.) (#t:Type) (a:t) : Tot (erased (list t)) = [a] unfold let (^+) (#t:Type) (a:t) (b:erased (list t)) : Tot (erased (list t)) = Cons a b unfold let (+^) (#t:Type) (a:erased (list t)) (b:t) : Tot (erased (list t)) = append a [b] unfold let (^@^) (#t:Type) (a:erased (list t)) (b:erased (list t)) : Tot (erased (list t)) = append a b unfold let (@) (a:pointer 't) (h0:heap) = B.get h0 a 0 unfold let (^@) (a:pointer_or_null 't{a =!= null}) (h0:heap) = B.get h0 a 0 /// All the data structures #set-options "--__no_positivity" unopteq (** Node of a doubly linked list *) type node (t:Type0) = { (* forward link *) flink: pointer_or_null (node t); (* backward link *) blink: pointer_or_null (node t); (* payload *) p: t; } #reset-options private type nodelist t = list (pointer (node t)) unopteq (** Doubly linked list head *) type dll (t:Type0) ={ lhead: pointer_or_null (node t); ltail: pointer_or_null (node t); nodes: erased (nodelist t); } type nonempty_dll t = (h:dll t{h.lhead =!= null /\ h.ltail =!= null}) unopteq private (** An "almost valid" dll *) type piece t = { phead: pointer (node t); ptail: pointer (node t); pnodes: erased (nodelist t); } unopteq private (** An intermediate for when linked lists are being formed or destroyed *) type fragment t = | Frag0 : fragment t | Frag1 : piece t -> fragment t | Frag2 : piece t -> piece t -> fragment t | Frag3 : piece t -> piece t -> piece t -> fragment t /// Some useful empty initializers (** Initialize an element of a doubly linked list *) val empty_node: #t:Type -> payload:t -> node t let empty_node #t payload = { flink = null ; blink = null ; p = payload } (** Initialize a doubly linked list head *) val empty_list: #t:Type -> dll t let empty_list #t = { lhead = null ; ltail = null ; nodes = [] } /// Convenience wrappers for writing properties on fragments let fragment_for_each0 (#t:Type) (pr:piece t -> GTot Type0) (f:fragment t) : GTot Type0 = match f with | Frag0 -> True | Frag1 p1 -> pr p1 | Frag2 p1 p2 -> pr p1 /\ pr p2 | Frag3 p1 p2 p3 -> pr p1 /\ pr p2 /\ pr p3 let fragment_for_each1 (#t:Type) (#u:Type) (pr:u -> piece t -> GTot Type0) (v:u) (f:fragment t) : GTot Type0 = match f with | Frag0 -> True | Frag1 p1 -> pr v p1 | Frag2 p1 p2 -> pr v p1 /\ pr v p2 | Frag3 p1 p2 p3 -> pr v p1 /\ pr v p2 /\ pr v p3 let fragment_length (#t:Type) (f:fragment t) : GTot int = match f with | Frag0 -> 0 | Frag1 _ -> 1 | Frag2 _ _ -> 2 | Frag3 _ _ _ -> 3 /// Ghostly connections let dll_ghostly_connections (#t:Type) (d:dll t) : GTot Type0 = let nodes = d.nodes in match length nodes with | 0 -> d.lhead == null /\ d.ltail == null | _ -> d.lhead =!= null /\ d.ltail =!= null /\ d.lhead == hd nodes /\ d.ltail == last nodes let piece_ghostly_connections (#t:Type) (p:piece t) : GTot Type0 = let nodes = p.pnodes in match length nodes with | 0 -> False | _ -> p.phead == hd nodes /\ p.ptail == last nodes let rec fragment_ghostly_connections (#t:Type) (f:fragment t) : GTot Type0 = fragment_for_each0 piece_ghostly_connections f /// Containment properties /// /// WARNING: [@@] and [^@] require containment to reasonably talk about /// what they do. let rec nodelist_contained0 (#t:Type) (h0:heap) (nl:nodelist t) : GTot Type0 = match nl with | [] -> True | n :: ns -> h0 `contains` n /\ nodelist_contained0 h0 ns let rec nodelist_contained (#t:Type) (h0:heap) (nl:nodelist t) : GTot Type0 = nodelist_contained0 h0 nl let dll_contained (#t:Type) (h0:heap) (d:dll t) : GTot Type0 = h0 `contains` d.lhead /\ h0 `contains` d.ltail /\ nodelist_contained h0 d.nodes let piece_contained (#t:Type) (h0:heap) (p:piece t) : GTot Type0 = h0 `contains` p.phead /\ h0 `contains` p.ptail /\ nodelist_contained h0 p.pnodes let rec fragment_contained (#t:Type) (h0:heap) (f:fragment t) : GTot Type0 = fragment_for_each1 piece_contained h0 f /// Footprints let node_fp_f (#t:Type) (n:node t) : GTot Mod.loc = Mod.loc_buffer n.flink let node_fp_b (#t:Type) (n:node t) : GTot Mod.loc = Mod.loc_buffer n.blink let rec nodelist_fp0 (#t:Type) (n:nodelist t) : GTot Mod.loc = match n with | [] -> Mod.loc_none | n :: ns -> Mod.loc_union (Mod.loc_buffer n) (nodelist_fp0 ns) let rec nodelist_fp_f (#t:Type) (h0:heap) (n:nodelist t) : GTot Mod.loc = match n with | [] -> Mod.loc_none | n :: ns -> Mod.loc_union (Mod.loc_buffer (n@h0).flink) (nodelist_fp_f h0 ns) let rec nodelist_fp_b (#t:Type) (h0:heap) (n:nodelist t) : GTot Mod.loc = match n with | [] -> Mod.loc_none | n :: ns -> Mod.loc_union (Mod.loc_buffer (n@h0).blink) (nodelist_fp_b h0 ns) let dll_fp0 (#t:Type) (d:dll t) : GTot Mod.loc = Mod.loc_union // ghostly connections should give us this union for // free, but still useful to have (Mod.loc_union (Mod.loc_buffer d.lhead) (Mod.loc_buffer d.ltail)) (nodelist_fp0 d.nodes) let dll_fp_f (#t:Type) (h0:heap) (d:dll t) : GTot Mod.loc = let a = if g_is_null d.lhead then Mod.loc_none else Mod.loc_buffer (d.lhead^@h0).flink in let b = if g_is_null d.ltail then Mod.loc_none else Mod.loc_buffer (d.ltail^@h0).flink in Mod.loc_union // ghostly connections should give us this union for // free, but still useful to have (Mod.loc_union a b) (nodelist_fp_f h0 d.nodes) let dll_fp_b (#t:Type) (h0:heap) (d:dll t) : GTot Mod.loc = let a = if g_is_null d.lhead then Mod.loc_none else Mod.loc_buffer (d.lhead^@h0).blink in let b = if g_is_null d.ltail then Mod.loc_none else Mod.loc_buffer (d.ltail^@h0).blink in Mod.loc_union // ghostly connections should give us this union for // free, but still useful to have (Mod.loc_union a b) (nodelist_fp_b h0 d.nodes) let piece_fp0 (#t:Type) (p:piece t) : GTot Mod.loc = Mod.loc_union // ghostly connections should give us this union for // free, but still useful to have (Mod.loc_union (Mod.loc_buffer p.phead) (Mod.loc_buffer p.ptail)) (nodelist_fp0 p.pnodes) let piece_fp_f (#t:Type) (h0:heap) (p:piece t) : GTot Mod.loc = Mod.loc_union // ghostly connections should give us this union for // free, but still useful to have (Mod.loc_union (Mod.loc_buffer (p.phead@h0).flink) (Mod.loc_buffer (p.ptail@h0).flink)) (nodelist_fp_f h0 p.pnodes) let piece_fp_b (#t:Type) (h0:heap) (p:piece t) : GTot Mod.loc = Mod.loc_union // ghostly connections should give us this union for // free, but still useful to have (Mod.loc_union (Mod.loc_buffer (p.phead@h0).blink) (Mod.loc_buffer (p.ptail@h0).blink)) (nodelist_fp_b h0 p.pnodes) let rec fragment_fp0 (#t:Type) (f:fragment t) : GTot Mod.loc = match f with | Frag0 -> Mod.loc_none | Frag1 p1 -> piece_fp0 p1 | Frag2 p1 p2 -> Mod.loc_union (piece_fp0 p1) (piece_fp0 p2) | Frag3 p1 p2 p3 -> Mod.loc_union (piece_fp0 p1) (Mod.loc_union (piece_fp0 p2) (piece_fp0 p3)) /// Helper patterns for footprints let loc_includes_union_l_nodelist_fp0 (#t: Type) (s1 s2:loc) (nl:nodelist t) : Lemma (requires (loc_includes s1 (nodelist_fp0 nl) \/ loc_includes s2 (nodelist_fp0 nl))) (ensures (loc_includes (loc_union s1 s2) (nodelist_fp0 nl))) [SMTPat (loc_includes (loc_union s1 s2) (nodelist_fp0 nl))] = loc_includes_union_l s1 s2 (nodelist_fp0 nl) let loc_includes_union_l_dll_fp0 (#t: Type) (s1 s2:loc) (d:dll t) : Lemma (requires (loc_includes s1 (dll_fp0 d) \/ loc_includes s2 (dll_fp0 d))) (ensures (loc_includes (loc_union s1 s2) (dll_fp0 d))) [SMTPat (loc_includes (loc_union s1 s2) (dll_fp0 d))] = loc_includes_union_l s1 s2 (dll_fp0 d) let loc_includes_union_l_piece_fp0 (#t: Type) (s1 s2:loc) (p:piece t) : Lemma (requires (loc_includes s1 (piece_fp0 p) \/ loc_includes s2 (piece_fp0 p))) (ensures (loc_includes (loc_union s1 s2) (piece_fp0 p))) [SMTPat (loc_includes (loc_union s1 s2) (piece_fp0 p))] = loc_includes_union_l s1 s2 (piece_fp0 p) let loc_includes_union_l_fragment_fp0 (#t: Type) (s1 s2:loc) (f:fragment t) : Lemma (requires (loc_includes s1 (fragment_fp0 f) \/ loc_includes s2 (fragment_fp0 f))) (ensures (loc_includes (loc_union s1 s2) (fragment_fp0 f))) [SMTPat (loc_includes (loc_union s1 s2) (fragment_fp0 f))] = loc_includes_union_l s1 s2 (fragment_fp0 f) /// Equivalence for locations let loc_equiv (a b:Mod.loc) = Mod.loc_includes a b /\ Mod.loc_includes b a let loc_equiv_trans (a b c:Mod.loc) : Lemma (requires (loc_equiv a b /\ loc_equiv b c)) (ensures (loc_equiv a c)) [SMTPat (loc_equiv a b); SMTPat (loc_equiv b c); SMTPat (loc_equiv a c)] = Mod.loc_includes_trans a b c; Mod.loc_includes_trans c b a let loc_equiv_union_union_loc (a b c:Mod.loc) : Lemma (requires (loc_equiv b c)) (ensures (loc_equiv (Mod.loc_union a b) (Mod.loc_union a c))) [SMTPat (loc_equiv (Mod.loc_union a b) (Mod.loc_union a c))] = let incl = Mod.loc_includes in let u = Mod.loc_union in // assert (b `incl` c); Mod.loc_includes_union_l a b c; // assert ((a `u` b) `incl` c); Mod.loc_includes_union_l a b a; // assert ((a `u` b) `incl` a); // assert ((a `u` b) `incl` (a `u` c)); Mod.loc_includes_union_l a c b; Mod.loc_includes_union_l a c a /// Anti aliasing properties let node_aa (#t:Type) (n:node t) : GTot Type0 = Mod.loc_disjoint (node_fp_f n) (node_fp_b n) let rec nodelist_aa_r (#t:Type) (nl:nodelist t) : GTot Type0 = match nl with | [] -> True | n :: ns -> Mod.loc_disjoint (Mod.loc_buffer n) (nodelist_fp0 ns) /\ nodelist_aa_r ns let rec nodelist_aa_l (#t:Type) (nl:nodelist t) : GTot Type0 (decreases (length nl)) = match nl with | [] -> True | _ -> let ns, n = unsnoc nl in lemma_unsnoc_length nl; Mod.loc_disjoint (Mod.loc_buffer n) (nodelist_fp0 ns) /\ nodelist_aa_l ns let nodelist_aa (#t:Type) (nl:nodelist t) : GTot Type0 = nodelist_aa_l nl /\ nodelist_aa_r nl let dll_aa (#t:Type) (d:dll t) : GTot Type0 = nodelist_aa d.nodes let piece_aa (#t:Type) (p:piece t) : GTot Type0 = nodelist_aa p.pnodes let rec fragment_aa0 (#t:Type) (f:fragment t) : GTot Type0 = fragment_for_each0 piece_aa f let rec fragment_aa_lr (#t:Type) (f:fragment t) : GTot Type0 = match f with | Frag0 -> True | Frag1 p1 -> True | Frag2 p1 p2 -> Mod.loc_disjoint (piece_fp0 p1) (piece_fp0 p2) | Frag3 p1 p2 p3 -> ((Mod.loc_disjoint (piece_fp0 p1) (piece_fp0 p2)) /\ (Mod.loc_disjoint (piece_fp0 p2) (piece_fp0 p3)) /\ (Mod.loc_disjoint (piece_fp0 p3) (piece_fp0 p1))) let fragment_aa (#t:Type) (f:fragment t) : GTot Type0 = fragment_aa0 f /\ fragment_aa_lr f /// Connectivity properties let ( |>> ) (#t:Type) (a:node t) (b:pointer (node t)) : GTot Type0 = a.flink == b let ( <<| ) (#t:Type) (a:pointer (node t)) (b: node t) : GTot Type0 = b.blink == a let rec nodelist_conn (#t:Type) (h0:heap) (nl:nodelist t) : GTot Type0 (decreases (length nl)) = match nl with | [] -> True | n1 :: rest -> match rest with | [] -> True | n2 :: ns -> n1@h0 |>> n2 /\ n1 <<| n2@h0 /\ nodelist_conn h0 rest let dll_conn (#t:Type) (h0:heap) (d:dll t) : GTot Type0 = nodelist_conn h0 d.nodes /\ (d.lhead =!= null ==> (d.lhead@h0).blink == null) /\ (d.ltail =!= null ==> (d.ltail@h0).flink == null) let piece_conn (#t:Type) (h0:heap) (p:piece t) : GTot Type0 = nodelist_conn h0 p.pnodes let rec fragment_conn (#t:Type) (h0:heap) (f:fragment t) : GTot Type0 = fragment_for_each1 piece_conn h0 f /// Validity properties /// /// These are just a combination of /// + Ghostly connections /// + Containment properties /// + Anti aliasing properties /// + Connectivity properties let nodelist_valid (#t:Type) (h0:heap) (nl:nodelist t) : GTot Type0 = nodelist_contained h0 nl /\ nodelist_aa nl /\ nodelist_conn h0 nl let dll_valid (#t:Type) (h0:heap) (d:dll t) : GTot Type0 = dll_ghostly_connections d /\ dll_contained h0 d /\ dll_aa d /\ dll_conn h0 d
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowStar.ModifiesPat.fst.checked", "LowStar.Modifies.fst.checked", "LowStar.BufferOps.fst.checked", "LowStar.Buffer.fst.checked", "FStar.UInt32.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked", "FStar.List.Pure.Properties.fst.checked", "FStar.List.Pure.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked", "FStar.Classical.fsti.checked" ], "interface_file": false, "source_file": "DoublyLinkedList.fst" }
[ { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": true, "full_module": "LowStar.Modifies", "short_module": "Mod" }, { "abbrev": false, "full_module": "LowStar.BufferOps", "short_module": null }, { "abbrev": false, "full_module": "FStar.List.Pure", "short_module": null }, { "abbrev": false, "full_module": "FStar.List.Tot", "short_module": null }, { "abbrev": false, "full_module": "LowStar.ModifiesPat", "short_module": null }, { "abbrev": false, "full_module": "FStar.Ghost", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
h0: DoublyLinkedList.heap -> p: DoublyLinkedList.piece t -> Prims.GTot Type0
Prims.GTot
[ "sometrivial" ]
[]
[ "DoublyLinkedList.heap", "DoublyLinkedList.piece", "Prims.l_and", "DoublyLinkedList.piece_ghostly_connections", "DoublyLinkedList.piece_contained", "DoublyLinkedList.piece_aa", "DoublyLinkedList.piece_conn" ]
[]
false
false
false
false
true
let piece_valid (#t: Type) (h0: heap) (p: piece t) : GTot Type0 =
piece_ghostly_connections p /\ piece_contained h0 p /\ piece_aa p /\ piece_conn h0 p
false
DoublyLinkedList.fst
DoublyLinkedList.dll_fp_f
val dll_fp_f (#t: Type) (h0: heap) (d: dll t) : GTot Mod.loc
val dll_fp_f (#t: Type) (h0: heap) (d: dll t) : GTot Mod.loc
let dll_fp_f (#t:Type) (h0:heap) (d:dll t) : GTot Mod.loc = let a = if g_is_null d.lhead then Mod.loc_none else Mod.loc_buffer (d.lhead^@h0).flink in let b = if g_is_null d.ltail then Mod.loc_none else Mod.loc_buffer (d.ltail^@h0).flink in Mod.loc_union // ghostly connections should give us this union for // free, but still useful to have (Mod.loc_union a b) (nodelist_fp_f h0 d.nodes)
{ "file_name": "examples/doublylinkedlist/DoublyLinkedList.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 30, "end_line": 213, "start_col": 0, "start_line": 207 }
(* Copyright 2008-2019 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module DoublyLinkedList open FStar open FStar.HyperStack.ST open FStar.Ghost open LowStar.ModifiesPat open FStar.List.Tot open FStar.List.Pure open LowStar.BufferOps module Mod = LowStar.Modifies module ST = FStar.HyperStack.ST module HS = FStar.HyperStack module B = LowStar.Buffer /// Convenience renaming unfold let heap = HS.mem unfold let contains #a #rrel #rel h b = B.live #a #rrel #rel h b /// Convenience patterns let lemma_non_null (#t:Type) (a:pointer_or_null t) : Lemma (requires (a =!= null)) (ensures (len a = 1ul)) [SMTPat (len a)] = null_unique a /// Convenience operators unfold let (.[]) (s:list 'a) (n:nat{n < length s}) = index s n unfold let (~.) (#t:Type) (a:t) : Tot (erased (list t)) = [a] unfold let (^+) (#t:Type) (a:t) (b:erased (list t)) : Tot (erased (list t)) = Cons a b unfold let (+^) (#t:Type) (a:erased (list t)) (b:t) : Tot (erased (list t)) = append a [b] unfold let (^@^) (#t:Type) (a:erased (list t)) (b:erased (list t)) : Tot (erased (list t)) = append a b unfold let (@) (a:pointer 't) (h0:heap) = B.get h0 a 0 unfold let (^@) (a:pointer_or_null 't{a =!= null}) (h0:heap) = B.get h0 a 0 /// All the data structures #set-options "--__no_positivity" unopteq (** Node of a doubly linked list *) type node (t:Type0) = { (* forward link *) flink: pointer_or_null (node t); (* backward link *) blink: pointer_or_null (node t); (* payload *) p: t; } #reset-options private type nodelist t = list (pointer (node t)) unopteq (** Doubly linked list head *) type dll (t:Type0) ={ lhead: pointer_or_null (node t); ltail: pointer_or_null (node t); nodes: erased (nodelist t); } type nonempty_dll t = (h:dll t{h.lhead =!= null /\ h.ltail =!= null}) unopteq private (** An "almost valid" dll *) type piece t = { phead: pointer (node t); ptail: pointer (node t); pnodes: erased (nodelist t); } unopteq private (** An intermediate for when linked lists are being formed or destroyed *) type fragment t = | Frag0 : fragment t | Frag1 : piece t -> fragment t | Frag2 : piece t -> piece t -> fragment t | Frag3 : piece t -> piece t -> piece t -> fragment t /// Some useful empty initializers (** Initialize an element of a doubly linked list *) val empty_node: #t:Type -> payload:t -> node t let empty_node #t payload = { flink = null ; blink = null ; p = payload } (** Initialize a doubly linked list head *) val empty_list: #t:Type -> dll t let empty_list #t = { lhead = null ; ltail = null ; nodes = [] } /// Convenience wrappers for writing properties on fragments let fragment_for_each0 (#t:Type) (pr:piece t -> GTot Type0) (f:fragment t) : GTot Type0 = match f with | Frag0 -> True | Frag1 p1 -> pr p1 | Frag2 p1 p2 -> pr p1 /\ pr p2 | Frag3 p1 p2 p3 -> pr p1 /\ pr p2 /\ pr p3 let fragment_for_each1 (#t:Type) (#u:Type) (pr:u -> piece t -> GTot Type0) (v:u) (f:fragment t) : GTot Type0 = match f with | Frag0 -> True | Frag1 p1 -> pr v p1 | Frag2 p1 p2 -> pr v p1 /\ pr v p2 | Frag3 p1 p2 p3 -> pr v p1 /\ pr v p2 /\ pr v p3 let fragment_length (#t:Type) (f:fragment t) : GTot int = match f with | Frag0 -> 0 | Frag1 _ -> 1 | Frag2 _ _ -> 2 | Frag3 _ _ _ -> 3 /// Ghostly connections let dll_ghostly_connections (#t:Type) (d:dll t) : GTot Type0 = let nodes = d.nodes in match length nodes with | 0 -> d.lhead == null /\ d.ltail == null | _ -> d.lhead =!= null /\ d.ltail =!= null /\ d.lhead == hd nodes /\ d.ltail == last nodes let piece_ghostly_connections (#t:Type) (p:piece t) : GTot Type0 = let nodes = p.pnodes in match length nodes with | 0 -> False | _ -> p.phead == hd nodes /\ p.ptail == last nodes let rec fragment_ghostly_connections (#t:Type) (f:fragment t) : GTot Type0 = fragment_for_each0 piece_ghostly_connections f /// Containment properties /// /// WARNING: [@@] and [^@] require containment to reasonably talk about /// what they do. let rec nodelist_contained0 (#t:Type) (h0:heap) (nl:nodelist t) : GTot Type0 = match nl with | [] -> True | n :: ns -> h0 `contains` n /\ nodelist_contained0 h0 ns let rec nodelist_contained (#t:Type) (h0:heap) (nl:nodelist t) : GTot Type0 = nodelist_contained0 h0 nl let dll_contained (#t:Type) (h0:heap) (d:dll t) : GTot Type0 = h0 `contains` d.lhead /\ h0 `contains` d.ltail /\ nodelist_contained h0 d.nodes let piece_contained (#t:Type) (h0:heap) (p:piece t) : GTot Type0 = h0 `contains` p.phead /\ h0 `contains` p.ptail /\ nodelist_contained h0 p.pnodes let rec fragment_contained (#t:Type) (h0:heap) (f:fragment t) : GTot Type0 = fragment_for_each1 piece_contained h0 f /// Footprints let node_fp_f (#t:Type) (n:node t) : GTot Mod.loc = Mod.loc_buffer n.flink let node_fp_b (#t:Type) (n:node t) : GTot Mod.loc = Mod.loc_buffer n.blink let rec nodelist_fp0 (#t:Type) (n:nodelist t) : GTot Mod.loc = match n with | [] -> Mod.loc_none | n :: ns -> Mod.loc_union (Mod.loc_buffer n) (nodelist_fp0 ns) let rec nodelist_fp_f (#t:Type) (h0:heap) (n:nodelist t) : GTot Mod.loc = match n with | [] -> Mod.loc_none | n :: ns -> Mod.loc_union (Mod.loc_buffer (n@h0).flink) (nodelist_fp_f h0 ns) let rec nodelist_fp_b (#t:Type) (h0:heap) (n:nodelist t) : GTot Mod.loc = match n with | [] -> Mod.loc_none | n :: ns -> Mod.loc_union (Mod.loc_buffer (n@h0).blink) (nodelist_fp_b h0 ns) let dll_fp0 (#t:Type) (d:dll t) : GTot Mod.loc = Mod.loc_union // ghostly connections should give us this union for // free, but still useful to have (Mod.loc_union (Mod.loc_buffer d.lhead) (Mod.loc_buffer d.ltail))
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowStar.ModifiesPat.fst.checked", "LowStar.Modifies.fst.checked", "LowStar.BufferOps.fst.checked", "LowStar.Buffer.fst.checked", "FStar.UInt32.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked", "FStar.List.Pure.Properties.fst.checked", "FStar.List.Pure.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked", "FStar.Classical.fsti.checked" ], "interface_file": false, "source_file": "DoublyLinkedList.fst" }
[ { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": true, "full_module": "LowStar.Modifies", "short_module": "Mod" }, { "abbrev": false, "full_module": "LowStar.BufferOps", "short_module": null }, { "abbrev": false, "full_module": "FStar.List.Pure", "short_module": null }, { "abbrev": false, "full_module": "FStar.List.Tot", "short_module": null }, { "abbrev": false, "full_module": "LowStar.ModifiesPat", "short_module": null }, { "abbrev": false, "full_module": "FStar.Ghost", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
h0: DoublyLinkedList.heap -> d: DoublyLinkedList.dll t -> Prims.GTot LowStar.Monotonic.Buffer.loc
Prims.GTot
[ "sometrivial" ]
[]
[ "DoublyLinkedList.heap", "DoublyLinkedList.dll", "LowStar.Monotonic.Buffer.loc_union", "DoublyLinkedList.nodelist_fp_f", "FStar.Ghost.reveal", "DoublyLinkedList.nodelist", "DoublyLinkedList.__proj__Mkdll__item__nodes", "LowStar.Monotonic.Buffer.loc", "LowStar.Monotonic.Buffer.g_is_null", "DoublyLinkedList.node", "LowStar.Buffer.trivial_preorder", "DoublyLinkedList.__proj__Mkdll__item__ltail", "LowStar.Monotonic.Buffer.loc_none", "Prims.bool", "LowStar.Monotonic.Buffer.loc_buffer", "DoublyLinkedList.__proj__Mknode__item__flink", "DoublyLinkedList.op_Hat_At", "DoublyLinkedList.__proj__Mkdll__item__lhead" ]
[]
false
false
false
false
false
let dll_fp_f (#t: Type) (h0: heap) (d: dll t) : GTot Mod.loc =
let a = if g_is_null d.lhead then Mod.loc_none else Mod.loc_buffer (d.lhead ^@ h0).flink in let b = if g_is_null d.ltail then Mod.loc_none else Mod.loc_buffer (d.ltail ^@ h0).flink in Mod.loc_union (Mod.loc_union a b) (nodelist_fp_f h0 d.nodes)
false
DoublyLinkedList.fst
DoublyLinkedList.dll_valid
val dll_valid (#t: Type) (h0: heap) (d: dll t) : GTot Type0
val dll_valid (#t: Type) (h0: heap) (d: dll t) : GTot Type0
let dll_valid (#t:Type) (h0:heap) (d:dll t) : GTot Type0 = dll_ghostly_connections d /\ dll_contained h0 d /\ dll_aa d /\ dll_conn h0 d
{ "file_name": "examples/doublylinkedlist/DoublyLinkedList.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 15, "end_line": 395, "start_col": 0, "start_line": 391 }
(* Copyright 2008-2019 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module DoublyLinkedList open FStar open FStar.HyperStack.ST open FStar.Ghost open LowStar.ModifiesPat open FStar.List.Tot open FStar.List.Pure open LowStar.BufferOps module Mod = LowStar.Modifies module ST = FStar.HyperStack.ST module HS = FStar.HyperStack module B = LowStar.Buffer /// Convenience renaming unfold let heap = HS.mem unfold let contains #a #rrel #rel h b = B.live #a #rrel #rel h b /// Convenience patterns let lemma_non_null (#t:Type) (a:pointer_or_null t) : Lemma (requires (a =!= null)) (ensures (len a = 1ul)) [SMTPat (len a)] = null_unique a /// Convenience operators unfold let (.[]) (s:list 'a) (n:nat{n < length s}) = index s n unfold let (~.) (#t:Type) (a:t) : Tot (erased (list t)) = [a] unfold let (^+) (#t:Type) (a:t) (b:erased (list t)) : Tot (erased (list t)) = Cons a b unfold let (+^) (#t:Type) (a:erased (list t)) (b:t) : Tot (erased (list t)) = append a [b] unfold let (^@^) (#t:Type) (a:erased (list t)) (b:erased (list t)) : Tot (erased (list t)) = append a b unfold let (@) (a:pointer 't) (h0:heap) = B.get h0 a 0 unfold let (^@) (a:pointer_or_null 't{a =!= null}) (h0:heap) = B.get h0 a 0 /// All the data structures #set-options "--__no_positivity" unopteq (** Node of a doubly linked list *) type node (t:Type0) = { (* forward link *) flink: pointer_or_null (node t); (* backward link *) blink: pointer_or_null (node t); (* payload *) p: t; } #reset-options private type nodelist t = list (pointer (node t)) unopteq (** Doubly linked list head *) type dll (t:Type0) ={ lhead: pointer_or_null (node t); ltail: pointer_or_null (node t); nodes: erased (nodelist t); } type nonempty_dll t = (h:dll t{h.lhead =!= null /\ h.ltail =!= null}) unopteq private (** An "almost valid" dll *) type piece t = { phead: pointer (node t); ptail: pointer (node t); pnodes: erased (nodelist t); } unopteq private (** An intermediate for when linked lists are being formed or destroyed *) type fragment t = | Frag0 : fragment t | Frag1 : piece t -> fragment t | Frag2 : piece t -> piece t -> fragment t | Frag3 : piece t -> piece t -> piece t -> fragment t /// Some useful empty initializers (** Initialize an element of a doubly linked list *) val empty_node: #t:Type -> payload:t -> node t let empty_node #t payload = { flink = null ; blink = null ; p = payload } (** Initialize a doubly linked list head *) val empty_list: #t:Type -> dll t let empty_list #t = { lhead = null ; ltail = null ; nodes = [] } /// Convenience wrappers for writing properties on fragments let fragment_for_each0 (#t:Type) (pr:piece t -> GTot Type0) (f:fragment t) : GTot Type0 = match f with | Frag0 -> True | Frag1 p1 -> pr p1 | Frag2 p1 p2 -> pr p1 /\ pr p2 | Frag3 p1 p2 p3 -> pr p1 /\ pr p2 /\ pr p3 let fragment_for_each1 (#t:Type) (#u:Type) (pr:u -> piece t -> GTot Type0) (v:u) (f:fragment t) : GTot Type0 = match f with | Frag0 -> True | Frag1 p1 -> pr v p1 | Frag2 p1 p2 -> pr v p1 /\ pr v p2 | Frag3 p1 p2 p3 -> pr v p1 /\ pr v p2 /\ pr v p3 let fragment_length (#t:Type) (f:fragment t) : GTot int = match f with | Frag0 -> 0 | Frag1 _ -> 1 | Frag2 _ _ -> 2 | Frag3 _ _ _ -> 3 /// Ghostly connections let dll_ghostly_connections (#t:Type) (d:dll t) : GTot Type0 = let nodes = d.nodes in match length nodes with | 0 -> d.lhead == null /\ d.ltail == null | _ -> d.lhead =!= null /\ d.ltail =!= null /\ d.lhead == hd nodes /\ d.ltail == last nodes let piece_ghostly_connections (#t:Type) (p:piece t) : GTot Type0 = let nodes = p.pnodes in match length nodes with | 0 -> False | _ -> p.phead == hd nodes /\ p.ptail == last nodes let rec fragment_ghostly_connections (#t:Type) (f:fragment t) : GTot Type0 = fragment_for_each0 piece_ghostly_connections f /// Containment properties /// /// WARNING: [@@] and [^@] require containment to reasonably talk about /// what they do. let rec nodelist_contained0 (#t:Type) (h0:heap) (nl:nodelist t) : GTot Type0 = match nl with | [] -> True | n :: ns -> h0 `contains` n /\ nodelist_contained0 h0 ns let rec nodelist_contained (#t:Type) (h0:heap) (nl:nodelist t) : GTot Type0 = nodelist_contained0 h0 nl let dll_contained (#t:Type) (h0:heap) (d:dll t) : GTot Type0 = h0 `contains` d.lhead /\ h0 `contains` d.ltail /\ nodelist_contained h0 d.nodes let piece_contained (#t:Type) (h0:heap) (p:piece t) : GTot Type0 = h0 `contains` p.phead /\ h0 `contains` p.ptail /\ nodelist_contained h0 p.pnodes let rec fragment_contained (#t:Type) (h0:heap) (f:fragment t) : GTot Type0 = fragment_for_each1 piece_contained h0 f /// Footprints let node_fp_f (#t:Type) (n:node t) : GTot Mod.loc = Mod.loc_buffer n.flink let node_fp_b (#t:Type) (n:node t) : GTot Mod.loc = Mod.loc_buffer n.blink let rec nodelist_fp0 (#t:Type) (n:nodelist t) : GTot Mod.loc = match n with | [] -> Mod.loc_none | n :: ns -> Mod.loc_union (Mod.loc_buffer n) (nodelist_fp0 ns) let rec nodelist_fp_f (#t:Type) (h0:heap) (n:nodelist t) : GTot Mod.loc = match n with | [] -> Mod.loc_none | n :: ns -> Mod.loc_union (Mod.loc_buffer (n@h0).flink) (nodelist_fp_f h0 ns) let rec nodelist_fp_b (#t:Type) (h0:heap) (n:nodelist t) : GTot Mod.loc = match n with | [] -> Mod.loc_none | n :: ns -> Mod.loc_union (Mod.loc_buffer (n@h0).blink) (nodelist_fp_b h0 ns) let dll_fp0 (#t:Type) (d:dll t) : GTot Mod.loc = Mod.loc_union // ghostly connections should give us this union for // free, but still useful to have (Mod.loc_union (Mod.loc_buffer d.lhead) (Mod.loc_buffer d.ltail)) (nodelist_fp0 d.nodes) let dll_fp_f (#t:Type) (h0:heap) (d:dll t) : GTot Mod.loc = let a = if g_is_null d.lhead then Mod.loc_none else Mod.loc_buffer (d.lhead^@h0).flink in let b = if g_is_null d.ltail then Mod.loc_none else Mod.loc_buffer (d.ltail^@h0).flink in Mod.loc_union // ghostly connections should give us this union for // free, but still useful to have (Mod.loc_union a b) (nodelist_fp_f h0 d.nodes) let dll_fp_b (#t:Type) (h0:heap) (d:dll t) : GTot Mod.loc = let a = if g_is_null d.lhead then Mod.loc_none else Mod.loc_buffer (d.lhead^@h0).blink in let b = if g_is_null d.ltail then Mod.loc_none else Mod.loc_buffer (d.ltail^@h0).blink in Mod.loc_union // ghostly connections should give us this union for // free, but still useful to have (Mod.loc_union a b) (nodelist_fp_b h0 d.nodes) let piece_fp0 (#t:Type) (p:piece t) : GTot Mod.loc = Mod.loc_union // ghostly connections should give us this union for // free, but still useful to have (Mod.loc_union (Mod.loc_buffer p.phead) (Mod.loc_buffer p.ptail)) (nodelist_fp0 p.pnodes) let piece_fp_f (#t:Type) (h0:heap) (p:piece t) : GTot Mod.loc = Mod.loc_union // ghostly connections should give us this union for // free, but still useful to have (Mod.loc_union (Mod.loc_buffer (p.phead@h0).flink) (Mod.loc_buffer (p.ptail@h0).flink)) (nodelist_fp_f h0 p.pnodes) let piece_fp_b (#t:Type) (h0:heap) (p:piece t) : GTot Mod.loc = Mod.loc_union // ghostly connections should give us this union for // free, but still useful to have (Mod.loc_union (Mod.loc_buffer (p.phead@h0).blink) (Mod.loc_buffer (p.ptail@h0).blink)) (nodelist_fp_b h0 p.pnodes) let rec fragment_fp0 (#t:Type) (f:fragment t) : GTot Mod.loc = match f with | Frag0 -> Mod.loc_none | Frag1 p1 -> piece_fp0 p1 | Frag2 p1 p2 -> Mod.loc_union (piece_fp0 p1) (piece_fp0 p2) | Frag3 p1 p2 p3 -> Mod.loc_union (piece_fp0 p1) (Mod.loc_union (piece_fp0 p2) (piece_fp0 p3)) /// Helper patterns for footprints let loc_includes_union_l_nodelist_fp0 (#t: Type) (s1 s2:loc) (nl:nodelist t) : Lemma (requires (loc_includes s1 (nodelist_fp0 nl) \/ loc_includes s2 (nodelist_fp0 nl))) (ensures (loc_includes (loc_union s1 s2) (nodelist_fp0 nl))) [SMTPat (loc_includes (loc_union s1 s2) (nodelist_fp0 nl))] = loc_includes_union_l s1 s2 (nodelist_fp0 nl) let loc_includes_union_l_dll_fp0 (#t: Type) (s1 s2:loc) (d:dll t) : Lemma (requires (loc_includes s1 (dll_fp0 d) \/ loc_includes s2 (dll_fp0 d))) (ensures (loc_includes (loc_union s1 s2) (dll_fp0 d))) [SMTPat (loc_includes (loc_union s1 s2) (dll_fp0 d))] = loc_includes_union_l s1 s2 (dll_fp0 d) let loc_includes_union_l_piece_fp0 (#t: Type) (s1 s2:loc) (p:piece t) : Lemma (requires (loc_includes s1 (piece_fp0 p) \/ loc_includes s2 (piece_fp0 p))) (ensures (loc_includes (loc_union s1 s2) (piece_fp0 p))) [SMTPat (loc_includes (loc_union s1 s2) (piece_fp0 p))] = loc_includes_union_l s1 s2 (piece_fp0 p) let loc_includes_union_l_fragment_fp0 (#t: Type) (s1 s2:loc) (f:fragment t) : Lemma (requires (loc_includes s1 (fragment_fp0 f) \/ loc_includes s2 (fragment_fp0 f))) (ensures (loc_includes (loc_union s1 s2) (fragment_fp0 f))) [SMTPat (loc_includes (loc_union s1 s2) (fragment_fp0 f))] = loc_includes_union_l s1 s2 (fragment_fp0 f) /// Equivalence for locations let loc_equiv (a b:Mod.loc) = Mod.loc_includes a b /\ Mod.loc_includes b a let loc_equiv_trans (a b c:Mod.loc) : Lemma (requires (loc_equiv a b /\ loc_equiv b c)) (ensures (loc_equiv a c)) [SMTPat (loc_equiv a b); SMTPat (loc_equiv b c); SMTPat (loc_equiv a c)] = Mod.loc_includes_trans a b c; Mod.loc_includes_trans c b a let loc_equiv_union_union_loc (a b c:Mod.loc) : Lemma (requires (loc_equiv b c)) (ensures (loc_equiv (Mod.loc_union a b) (Mod.loc_union a c))) [SMTPat (loc_equiv (Mod.loc_union a b) (Mod.loc_union a c))] = let incl = Mod.loc_includes in let u = Mod.loc_union in // assert (b `incl` c); Mod.loc_includes_union_l a b c; // assert ((a `u` b) `incl` c); Mod.loc_includes_union_l a b a; // assert ((a `u` b) `incl` a); // assert ((a `u` b) `incl` (a `u` c)); Mod.loc_includes_union_l a c b; Mod.loc_includes_union_l a c a /// Anti aliasing properties let node_aa (#t:Type) (n:node t) : GTot Type0 = Mod.loc_disjoint (node_fp_f n) (node_fp_b n) let rec nodelist_aa_r (#t:Type) (nl:nodelist t) : GTot Type0 = match nl with | [] -> True | n :: ns -> Mod.loc_disjoint (Mod.loc_buffer n) (nodelist_fp0 ns) /\ nodelist_aa_r ns let rec nodelist_aa_l (#t:Type) (nl:nodelist t) : GTot Type0 (decreases (length nl)) = match nl with | [] -> True | _ -> let ns, n = unsnoc nl in lemma_unsnoc_length nl; Mod.loc_disjoint (Mod.loc_buffer n) (nodelist_fp0 ns) /\ nodelist_aa_l ns let nodelist_aa (#t:Type) (nl:nodelist t) : GTot Type0 = nodelist_aa_l nl /\ nodelist_aa_r nl let dll_aa (#t:Type) (d:dll t) : GTot Type0 = nodelist_aa d.nodes let piece_aa (#t:Type) (p:piece t) : GTot Type0 = nodelist_aa p.pnodes let rec fragment_aa0 (#t:Type) (f:fragment t) : GTot Type0 = fragment_for_each0 piece_aa f let rec fragment_aa_lr (#t:Type) (f:fragment t) : GTot Type0 = match f with | Frag0 -> True | Frag1 p1 -> True | Frag2 p1 p2 -> Mod.loc_disjoint (piece_fp0 p1) (piece_fp0 p2) | Frag3 p1 p2 p3 -> ((Mod.loc_disjoint (piece_fp0 p1) (piece_fp0 p2)) /\ (Mod.loc_disjoint (piece_fp0 p2) (piece_fp0 p3)) /\ (Mod.loc_disjoint (piece_fp0 p3) (piece_fp0 p1))) let fragment_aa (#t:Type) (f:fragment t) : GTot Type0 = fragment_aa0 f /\ fragment_aa_lr f /// Connectivity properties let ( |>> ) (#t:Type) (a:node t) (b:pointer (node t)) : GTot Type0 = a.flink == b let ( <<| ) (#t:Type) (a:pointer (node t)) (b: node t) : GTot Type0 = b.blink == a let rec nodelist_conn (#t:Type) (h0:heap) (nl:nodelist t) : GTot Type0 (decreases (length nl)) = match nl with | [] -> True | n1 :: rest -> match rest with | [] -> True | n2 :: ns -> n1@h0 |>> n2 /\ n1 <<| n2@h0 /\ nodelist_conn h0 rest let dll_conn (#t:Type) (h0:heap) (d:dll t) : GTot Type0 = nodelist_conn h0 d.nodes /\ (d.lhead =!= null ==> (d.lhead@h0).blink == null) /\ (d.ltail =!= null ==> (d.ltail@h0).flink == null) let piece_conn (#t:Type) (h0:heap) (p:piece t) : GTot Type0 = nodelist_conn h0 p.pnodes let rec fragment_conn (#t:Type) (h0:heap) (f:fragment t) : GTot Type0 = fragment_for_each1 piece_conn h0 f /// Validity properties /// /// These are just a combination of /// + Ghostly connections /// + Containment properties /// + Anti aliasing properties /// + Connectivity properties let nodelist_valid (#t:Type) (h0:heap) (nl:nodelist t) : GTot Type0 = nodelist_contained h0 nl /\ nodelist_aa nl /\ nodelist_conn h0 nl
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowStar.ModifiesPat.fst.checked", "LowStar.Modifies.fst.checked", "LowStar.BufferOps.fst.checked", "LowStar.Buffer.fst.checked", "FStar.UInt32.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked", "FStar.List.Pure.Properties.fst.checked", "FStar.List.Pure.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked", "FStar.Classical.fsti.checked" ], "interface_file": false, "source_file": "DoublyLinkedList.fst" }
[ { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": true, "full_module": "LowStar.Modifies", "short_module": "Mod" }, { "abbrev": false, "full_module": "LowStar.BufferOps", "short_module": null }, { "abbrev": false, "full_module": "FStar.List.Pure", "short_module": null }, { "abbrev": false, "full_module": "FStar.List.Tot", "short_module": null }, { "abbrev": false, "full_module": "LowStar.ModifiesPat", "short_module": null }, { "abbrev": false, "full_module": "FStar.Ghost", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
h0: DoublyLinkedList.heap -> d: DoublyLinkedList.dll t -> Prims.GTot Type0
Prims.GTot
[ "sometrivial" ]
[]
[ "DoublyLinkedList.heap", "DoublyLinkedList.dll", "Prims.l_and", "DoublyLinkedList.dll_ghostly_connections", "DoublyLinkedList.dll_contained", "DoublyLinkedList.dll_aa", "DoublyLinkedList.dll_conn" ]
[]
false
false
false
false
true
let dll_valid (#t: Type) (h0: heap) (d: dll t) : GTot Type0 =
dll_ghostly_connections d /\ dll_contained h0 d /\ dll_aa d /\ dll_conn h0 d
false
DoublyLinkedList.fst
DoublyLinkedList.nodelist_fp_f
val nodelist_fp_f (#t: Type) (h0: heap) (n: nodelist t) : GTot Mod.loc
val nodelist_fp_f (#t: Type) (h0: heap) (n: nodelist t) : GTot Mod.loc
let rec nodelist_fp_f (#t:Type) (h0:heap) (n:nodelist t) : GTot Mod.loc = match n with | [] -> Mod.loc_none | n :: ns -> Mod.loc_union (Mod.loc_buffer (n@h0).flink) (nodelist_fp_f h0 ns)
{ "file_name": "examples/doublylinkedlist/DoublyLinkedList.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 80, "end_line": 196, "start_col": 0, "start_line": 193 }
(* Copyright 2008-2019 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module DoublyLinkedList open FStar open FStar.HyperStack.ST open FStar.Ghost open LowStar.ModifiesPat open FStar.List.Tot open FStar.List.Pure open LowStar.BufferOps module Mod = LowStar.Modifies module ST = FStar.HyperStack.ST module HS = FStar.HyperStack module B = LowStar.Buffer /// Convenience renaming unfold let heap = HS.mem unfold let contains #a #rrel #rel h b = B.live #a #rrel #rel h b /// Convenience patterns let lemma_non_null (#t:Type) (a:pointer_or_null t) : Lemma (requires (a =!= null)) (ensures (len a = 1ul)) [SMTPat (len a)] = null_unique a /// Convenience operators unfold let (.[]) (s:list 'a) (n:nat{n < length s}) = index s n unfold let (~.) (#t:Type) (a:t) : Tot (erased (list t)) = [a] unfold let (^+) (#t:Type) (a:t) (b:erased (list t)) : Tot (erased (list t)) = Cons a b unfold let (+^) (#t:Type) (a:erased (list t)) (b:t) : Tot (erased (list t)) = append a [b] unfold let (^@^) (#t:Type) (a:erased (list t)) (b:erased (list t)) : Tot (erased (list t)) = append a b unfold let (@) (a:pointer 't) (h0:heap) = B.get h0 a 0 unfold let (^@) (a:pointer_or_null 't{a =!= null}) (h0:heap) = B.get h0 a 0 /// All the data structures #set-options "--__no_positivity" unopteq (** Node of a doubly linked list *) type node (t:Type0) = { (* forward link *) flink: pointer_or_null (node t); (* backward link *) blink: pointer_or_null (node t); (* payload *) p: t; } #reset-options private type nodelist t = list (pointer (node t)) unopteq (** Doubly linked list head *) type dll (t:Type0) ={ lhead: pointer_or_null (node t); ltail: pointer_or_null (node t); nodes: erased (nodelist t); } type nonempty_dll t = (h:dll t{h.lhead =!= null /\ h.ltail =!= null}) unopteq private (** An "almost valid" dll *) type piece t = { phead: pointer (node t); ptail: pointer (node t); pnodes: erased (nodelist t); } unopteq private (** An intermediate for when linked lists are being formed or destroyed *) type fragment t = | Frag0 : fragment t | Frag1 : piece t -> fragment t | Frag2 : piece t -> piece t -> fragment t | Frag3 : piece t -> piece t -> piece t -> fragment t /// Some useful empty initializers (** Initialize an element of a doubly linked list *) val empty_node: #t:Type -> payload:t -> node t let empty_node #t payload = { flink = null ; blink = null ; p = payload } (** Initialize a doubly linked list head *) val empty_list: #t:Type -> dll t let empty_list #t = { lhead = null ; ltail = null ; nodes = [] } /// Convenience wrappers for writing properties on fragments let fragment_for_each0 (#t:Type) (pr:piece t -> GTot Type0) (f:fragment t) : GTot Type0 = match f with | Frag0 -> True | Frag1 p1 -> pr p1 | Frag2 p1 p2 -> pr p1 /\ pr p2 | Frag3 p1 p2 p3 -> pr p1 /\ pr p2 /\ pr p3 let fragment_for_each1 (#t:Type) (#u:Type) (pr:u -> piece t -> GTot Type0) (v:u) (f:fragment t) : GTot Type0 = match f with | Frag0 -> True | Frag1 p1 -> pr v p1 | Frag2 p1 p2 -> pr v p1 /\ pr v p2 | Frag3 p1 p2 p3 -> pr v p1 /\ pr v p2 /\ pr v p3 let fragment_length (#t:Type) (f:fragment t) : GTot int = match f with | Frag0 -> 0 | Frag1 _ -> 1 | Frag2 _ _ -> 2 | Frag3 _ _ _ -> 3 /// Ghostly connections let dll_ghostly_connections (#t:Type) (d:dll t) : GTot Type0 = let nodes = d.nodes in match length nodes with | 0 -> d.lhead == null /\ d.ltail == null | _ -> d.lhead =!= null /\ d.ltail =!= null /\ d.lhead == hd nodes /\ d.ltail == last nodes let piece_ghostly_connections (#t:Type) (p:piece t) : GTot Type0 = let nodes = p.pnodes in match length nodes with | 0 -> False | _ -> p.phead == hd nodes /\ p.ptail == last nodes let rec fragment_ghostly_connections (#t:Type) (f:fragment t) : GTot Type0 = fragment_for_each0 piece_ghostly_connections f /// Containment properties /// /// WARNING: [@@] and [^@] require containment to reasonably talk about /// what they do. let rec nodelist_contained0 (#t:Type) (h0:heap) (nl:nodelist t) : GTot Type0 = match nl with | [] -> True | n :: ns -> h0 `contains` n /\ nodelist_contained0 h0 ns let rec nodelist_contained (#t:Type) (h0:heap) (nl:nodelist t) : GTot Type0 = nodelist_contained0 h0 nl let dll_contained (#t:Type) (h0:heap) (d:dll t) : GTot Type0 = h0 `contains` d.lhead /\ h0 `contains` d.ltail /\ nodelist_contained h0 d.nodes let piece_contained (#t:Type) (h0:heap) (p:piece t) : GTot Type0 = h0 `contains` p.phead /\ h0 `contains` p.ptail /\ nodelist_contained h0 p.pnodes let rec fragment_contained (#t:Type) (h0:heap) (f:fragment t) : GTot Type0 = fragment_for_each1 piece_contained h0 f /// Footprints let node_fp_f (#t:Type) (n:node t) : GTot Mod.loc = Mod.loc_buffer n.flink let node_fp_b (#t:Type) (n:node t) : GTot Mod.loc = Mod.loc_buffer n.blink let rec nodelist_fp0 (#t:Type) (n:nodelist t) : GTot Mod.loc = match n with | [] -> Mod.loc_none
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowStar.ModifiesPat.fst.checked", "LowStar.Modifies.fst.checked", "LowStar.BufferOps.fst.checked", "LowStar.Buffer.fst.checked", "FStar.UInt32.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked", "FStar.List.Pure.Properties.fst.checked", "FStar.List.Pure.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked", "FStar.Classical.fsti.checked" ], "interface_file": false, "source_file": "DoublyLinkedList.fst" }
[ { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": true, "full_module": "LowStar.Modifies", "short_module": "Mod" }, { "abbrev": false, "full_module": "LowStar.BufferOps", "short_module": null }, { "abbrev": false, "full_module": "FStar.List.Pure", "short_module": null }, { "abbrev": false, "full_module": "FStar.List.Tot", "short_module": null }, { "abbrev": false, "full_module": "LowStar.ModifiesPat", "short_module": null }, { "abbrev": false, "full_module": "FStar.Ghost", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
h0: DoublyLinkedList.heap -> n: DoublyLinkedList.nodelist t -> Prims.GTot LowStar.Monotonic.Buffer.loc
Prims.GTot
[ "sometrivial" ]
[]
[ "DoublyLinkedList.heap", "DoublyLinkedList.nodelist", "LowStar.Monotonic.Buffer.loc_none", "LowStar.Buffer.pointer", "DoublyLinkedList.node", "Prims.list", "LowStar.Monotonic.Buffer.loc_union", "LowStar.Monotonic.Buffer.loc_buffer", "LowStar.Buffer.trivial_preorder", "DoublyLinkedList.__proj__Mknode__item__flink", "DoublyLinkedList.op_At", "DoublyLinkedList.nodelist_fp_f", "LowStar.Monotonic.Buffer.loc" ]
[ "recursion" ]
false
false
false
false
false
let rec nodelist_fp_f (#t: Type) (h0: heap) (n: nodelist t) : GTot Mod.loc =
match n with | [] -> Mod.loc_none | n :: ns -> Mod.loc_union (Mod.loc_buffer (n @ h0).flink) (nodelist_fp_f h0 ns)
false
DoublyLinkedList.fst
DoublyLinkedList.nodelist_valid
val nodelist_valid (#t: Type) (h0: heap) (nl: nodelist t) : GTot Type0
val nodelist_valid (#t: Type) (h0: heap) (nl: nodelist t) : GTot Type0
let nodelist_valid (#t:Type) (h0:heap) (nl:nodelist t) : GTot Type0 = nodelist_contained h0 nl /\ nodelist_aa nl /\ nodelist_conn h0 nl
{ "file_name": "examples/doublylinkedlist/DoublyLinkedList.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 21, "end_line": 389, "start_col": 0, "start_line": 386 }
(* Copyright 2008-2019 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module DoublyLinkedList open FStar open FStar.HyperStack.ST open FStar.Ghost open LowStar.ModifiesPat open FStar.List.Tot open FStar.List.Pure open LowStar.BufferOps module Mod = LowStar.Modifies module ST = FStar.HyperStack.ST module HS = FStar.HyperStack module B = LowStar.Buffer /// Convenience renaming unfold let heap = HS.mem unfold let contains #a #rrel #rel h b = B.live #a #rrel #rel h b /// Convenience patterns let lemma_non_null (#t:Type) (a:pointer_or_null t) : Lemma (requires (a =!= null)) (ensures (len a = 1ul)) [SMTPat (len a)] = null_unique a /// Convenience operators unfold let (.[]) (s:list 'a) (n:nat{n < length s}) = index s n unfold let (~.) (#t:Type) (a:t) : Tot (erased (list t)) = [a] unfold let (^+) (#t:Type) (a:t) (b:erased (list t)) : Tot (erased (list t)) = Cons a b unfold let (+^) (#t:Type) (a:erased (list t)) (b:t) : Tot (erased (list t)) = append a [b] unfold let (^@^) (#t:Type) (a:erased (list t)) (b:erased (list t)) : Tot (erased (list t)) = append a b unfold let (@) (a:pointer 't) (h0:heap) = B.get h0 a 0 unfold let (^@) (a:pointer_or_null 't{a =!= null}) (h0:heap) = B.get h0 a 0 /// All the data structures #set-options "--__no_positivity" unopteq (** Node of a doubly linked list *) type node (t:Type0) = { (* forward link *) flink: pointer_or_null (node t); (* backward link *) blink: pointer_or_null (node t); (* payload *) p: t; } #reset-options private type nodelist t = list (pointer (node t)) unopteq (** Doubly linked list head *) type dll (t:Type0) ={ lhead: pointer_or_null (node t); ltail: pointer_or_null (node t); nodes: erased (nodelist t); } type nonempty_dll t = (h:dll t{h.lhead =!= null /\ h.ltail =!= null}) unopteq private (** An "almost valid" dll *) type piece t = { phead: pointer (node t); ptail: pointer (node t); pnodes: erased (nodelist t); } unopteq private (** An intermediate for when linked lists are being formed or destroyed *) type fragment t = | Frag0 : fragment t | Frag1 : piece t -> fragment t | Frag2 : piece t -> piece t -> fragment t | Frag3 : piece t -> piece t -> piece t -> fragment t /// Some useful empty initializers (** Initialize an element of a doubly linked list *) val empty_node: #t:Type -> payload:t -> node t let empty_node #t payload = { flink = null ; blink = null ; p = payload } (** Initialize a doubly linked list head *) val empty_list: #t:Type -> dll t let empty_list #t = { lhead = null ; ltail = null ; nodes = [] } /// Convenience wrappers for writing properties on fragments let fragment_for_each0 (#t:Type) (pr:piece t -> GTot Type0) (f:fragment t) : GTot Type0 = match f with | Frag0 -> True | Frag1 p1 -> pr p1 | Frag2 p1 p2 -> pr p1 /\ pr p2 | Frag3 p1 p2 p3 -> pr p1 /\ pr p2 /\ pr p3 let fragment_for_each1 (#t:Type) (#u:Type) (pr:u -> piece t -> GTot Type0) (v:u) (f:fragment t) : GTot Type0 = match f with | Frag0 -> True | Frag1 p1 -> pr v p1 | Frag2 p1 p2 -> pr v p1 /\ pr v p2 | Frag3 p1 p2 p3 -> pr v p1 /\ pr v p2 /\ pr v p3 let fragment_length (#t:Type) (f:fragment t) : GTot int = match f with | Frag0 -> 0 | Frag1 _ -> 1 | Frag2 _ _ -> 2 | Frag3 _ _ _ -> 3 /// Ghostly connections let dll_ghostly_connections (#t:Type) (d:dll t) : GTot Type0 = let nodes = d.nodes in match length nodes with | 0 -> d.lhead == null /\ d.ltail == null | _ -> d.lhead =!= null /\ d.ltail =!= null /\ d.lhead == hd nodes /\ d.ltail == last nodes let piece_ghostly_connections (#t:Type) (p:piece t) : GTot Type0 = let nodes = p.pnodes in match length nodes with | 0 -> False | _ -> p.phead == hd nodes /\ p.ptail == last nodes let rec fragment_ghostly_connections (#t:Type) (f:fragment t) : GTot Type0 = fragment_for_each0 piece_ghostly_connections f /// Containment properties /// /// WARNING: [@@] and [^@] require containment to reasonably talk about /// what they do. let rec nodelist_contained0 (#t:Type) (h0:heap) (nl:nodelist t) : GTot Type0 = match nl with | [] -> True | n :: ns -> h0 `contains` n /\ nodelist_contained0 h0 ns let rec nodelist_contained (#t:Type) (h0:heap) (nl:nodelist t) : GTot Type0 = nodelist_contained0 h0 nl let dll_contained (#t:Type) (h0:heap) (d:dll t) : GTot Type0 = h0 `contains` d.lhead /\ h0 `contains` d.ltail /\ nodelist_contained h0 d.nodes let piece_contained (#t:Type) (h0:heap) (p:piece t) : GTot Type0 = h0 `contains` p.phead /\ h0 `contains` p.ptail /\ nodelist_contained h0 p.pnodes let rec fragment_contained (#t:Type) (h0:heap) (f:fragment t) : GTot Type0 = fragment_for_each1 piece_contained h0 f /// Footprints let node_fp_f (#t:Type) (n:node t) : GTot Mod.loc = Mod.loc_buffer n.flink let node_fp_b (#t:Type) (n:node t) : GTot Mod.loc = Mod.loc_buffer n.blink let rec nodelist_fp0 (#t:Type) (n:nodelist t) : GTot Mod.loc = match n with | [] -> Mod.loc_none | n :: ns -> Mod.loc_union (Mod.loc_buffer n) (nodelist_fp0 ns) let rec nodelist_fp_f (#t:Type) (h0:heap) (n:nodelist t) : GTot Mod.loc = match n with | [] -> Mod.loc_none | n :: ns -> Mod.loc_union (Mod.loc_buffer (n@h0).flink) (nodelist_fp_f h0 ns) let rec nodelist_fp_b (#t:Type) (h0:heap) (n:nodelist t) : GTot Mod.loc = match n with | [] -> Mod.loc_none | n :: ns -> Mod.loc_union (Mod.loc_buffer (n@h0).blink) (nodelist_fp_b h0 ns) let dll_fp0 (#t:Type) (d:dll t) : GTot Mod.loc = Mod.loc_union // ghostly connections should give us this union for // free, but still useful to have (Mod.loc_union (Mod.loc_buffer d.lhead) (Mod.loc_buffer d.ltail)) (nodelist_fp0 d.nodes) let dll_fp_f (#t:Type) (h0:heap) (d:dll t) : GTot Mod.loc = let a = if g_is_null d.lhead then Mod.loc_none else Mod.loc_buffer (d.lhead^@h0).flink in let b = if g_is_null d.ltail then Mod.loc_none else Mod.loc_buffer (d.ltail^@h0).flink in Mod.loc_union // ghostly connections should give us this union for // free, but still useful to have (Mod.loc_union a b) (nodelist_fp_f h0 d.nodes) let dll_fp_b (#t:Type) (h0:heap) (d:dll t) : GTot Mod.loc = let a = if g_is_null d.lhead then Mod.loc_none else Mod.loc_buffer (d.lhead^@h0).blink in let b = if g_is_null d.ltail then Mod.loc_none else Mod.loc_buffer (d.ltail^@h0).blink in Mod.loc_union // ghostly connections should give us this union for // free, but still useful to have (Mod.loc_union a b) (nodelist_fp_b h0 d.nodes) let piece_fp0 (#t:Type) (p:piece t) : GTot Mod.loc = Mod.loc_union // ghostly connections should give us this union for // free, but still useful to have (Mod.loc_union (Mod.loc_buffer p.phead) (Mod.loc_buffer p.ptail)) (nodelist_fp0 p.pnodes) let piece_fp_f (#t:Type) (h0:heap) (p:piece t) : GTot Mod.loc = Mod.loc_union // ghostly connections should give us this union for // free, but still useful to have (Mod.loc_union (Mod.loc_buffer (p.phead@h0).flink) (Mod.loc_buffer (p.ptail@h0).flink)) (nodelist_fp_f h0 p.pnodes) let piece_fp_b (#t:Type) (h0:heap) (p:piece t) : GTot Mod.loc = Mod.loc_union // ghostly connections should give us this union for // free, but still useful to have (Mod.loc_union (Mod.loc_buffer (p.phead@h0).blink) (Mod.loc_buffer (p.ptail@h0).blink)) (nodelist_fp_b h0 p.pnodes) let rec fragment_fp0 (#t:Type) (f:fragment t) : GTot Mod.loc = match f with | Frag0 -> Mod.loc_none | Frag1 p1 -> piece_fp0 p1 | Frag2 p1 p2 -> Mod.loc_union (piece_fp0 p1) (piece_fp0 p2) | Frag3 p1 p2 p3 -> Mod.loc_union (piece_fp0 p1) (Mod.loc_union (piece_fp0 p2) (piece_fp0 p3)) /// Helper patterns for footprints let loc_includes_union_l_nodelist_fp0 (#t: Type) (s1 s2:loc) (nl:nodelist t) : Lemma (requires (loc_includes s1 (nodelist_fp0 nl) \/ loc_includes s2 (nodelist_fp0 nl))) (ensures (loc_includes (loc_union s1 s2) (nodelist_fp0 nl))) [SMTPat (loc_includes (loc_union s1 s2) (nodelist_fp0 nl))] = loc_includes_union_l s1 s2 (nodelist_fp0 nl) let loc_includes_union_l_dll_fp0 (#t: Type) (s1 s2:loc) (d:dll t) : Lemma (requires (loc_includes s1 (dll_fp0 d) \/ loc_includes s2 (dll_fp0 d))) (ensures (loc_includes (loc_union s1 s2) (dll_fp0 d))) [SMTPat (loc_includes (loc_union s1 s2) (dll_fp0 d))] = loc_includes_union_l s1 s2 (dll_fp0 d) let loc_includes_union_l_piece_fp0 (#t: Type) (s1 s2:loc) (p:piece t) : Lemma (requires (loc_includes s1 (piece_fp0 p) \/ loc_includes s2 (piece_fp0 p))) (ensures (loc_includes (loc_union s1 s2) (piece_fp0 p))) [SMTPat (loc_includes (loc_union s1 s2) (piece_fp0 p))] = loc_includes_union_l s1 s2 (piece_fp0 p) let loc_includes_union_l_fragment_fp0 (#t: Type) (s1 s2:loc) (f:fragment t) : Lemma (requires (loc_includes s1 (fragment_fp0 f) \/ loc_includes s2 (fragment_fp0 f))) (ensures (loc_includes (loc_union s1 s2) (fragment_fp0 f))) [SMTPat (loc_includes (loc_union s1 s2) (fragment_fp0 f))] = loc_includes_union_l s1 s2 (fragment_fp0 f) /// Equivalence for locations let loc_equiv (a b:Mod.loc) = Mod.loc_includes a b /\ Mod.loc_includes b a let loc_equiv_trans (a b c:Mod.loc) : Lemma (requires (loc_equiv a b /\ loc_equiv b c)) (ensures (loc_equiv a c)) [SMTPat (loc_equiv a b); SMTPat (loc_equiv b c); SMTPat (loc_equiv a c)] = Mod.loc_includes_trans a b c; Mod.loc_includes_trans c b a let loc_equiv_union_union_loc (a b c:Mod.loc) : Lemma (requires (loc_equiv b c)) (ensures (loc_equiv (Mod.loc_union a b) (Mod.loc_union a c))) [SMTPat (loc_equiv (Mod.loc_union a b) (Mod.loc_union a c))] = let incl = Mod.loc_includes in let u = Mod.loc_union in // assert (b `incl` c); Mod.loc_includes_union_l a b c; // assert ((a `u` b) `incl` c); Mod.loc_includes_union_l a b a; // assert ((a `u` b) `incl` a); // assert ((a `u` b) `incl` (a `u` c)); Mod.loc_includes_union_l a c b; Mod.loc_includes_union_l a c a /// Anti aliasing properties let node_aa (#t:Type) (n:node t) : GTot Type0 = Mod.loc_disjoint (node_fp_f n) (node_fp_b n) let rec nodelist_aa_r (#t:Type) (nl:nodelist t) : GTot Type0 = match nl with | [] -> True | n :: ns -> Mod.loc_disjoint (Mod.loc_buffer n) (nodelist_fp0 ns) /\ nodelist_aa_r ns let rec nodelist_aa_l (#t:Type) (nl:nodelist t) : GTot Type0 (decreases (length nl)) = match nl with | [] -> True | _ -> let ns, n = unsnoc nl in lemma_unsnoc_length nl; Mod.loc_disjoint (Mod.loc_buffer n) (nodelist_fp0 ns) /\ nodelist_aa_l ns let nodelist_aa (#t:Type) (nl:nodelist t) : GTot Type0 = nodelist_aa_l nl /\ nodelist_aa_r nl let dll_aa (#t:Type) (d:dll t) : GTot Type0 = nodelist_aa d.nodes let piece_aa (#t:Type) (p:piece t) : GTot Type0 = nodelist_aa p.pnodes let rec fragment_aa0 (#t:Type) (f:fragment t) : GTot Type0 = fragment_for_each0 piece_aa f let rec fragment_aa_lr (#t:Type) (f:fragment t) : GTot Type0 = match f with | Frag0 -> True | Frag1 p1 -> True | Frag2 p1 p2 -> Mod.loc_disjoint (piece_fp0 p1) (piece_fp0 p2) | Frag3 p1 p2 p3 -> ((Mod.loc_disjoint (piece_fp0 p1) (piece_fp0 p2)) /\ (Mod.loc_disjoint (piece_fp0 p2) (piece_fp0 p3)) /\ (Mod.loc_disjoint (piece_fp0 p3) (piece_fp0 p1))) let fragment_aa (#t:Type) (f:fragment t) : GTot Type0 = fragment_aa0 f /\ fragment_aa_lr f /// Connectivity properties let ( |>> ) (#t:Type) (a:node t) (b:pointer (node t)) : GTot Type0 = a.flink == b let ( <<| ) (#t:Type) (a:pointer (node t)) (b: node t) : GTot Type0 = b.blink == a let rec nodelist_conn (#t:Type) (h0:heap) (nl:nodelist t) : GTot Type0 (decreases (length nl)) = match nl with | [] -> True | n1 :: rest -> match rest with | [] -> True | n2 :: ns -> n1@h0 |>> n2 /\ n1 <<| n2@h0 /\ nodelist_conn h0 rest let dll_conn (#t:Type) (h0:heap) (d:dll t) : GTot Type0 = nodelist_conn h0 d.nodes /\ (d.lhead =!= null ==> (d.lhead@h0).blink == null) /\ (d.ltail =!= null ==> (d.ltail@h0).flink == null) let piece_conn (#t:Type) (h0:heap) (p:piece t) : GTot Type0 = nodelist_conn h0 p.pnodes let rec fragment_conn (#t:Type) (h0:heap) (f:fragment t) : GTot Type0 = fragment_for_each1 piece_conn h0 f /// Validity properties /// /// These are just a combination of /// + Ghostly connections /// + Containment properties /// + Anti aliasing properties /// + Connectivity properties
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowStar.ModifiesPat.fst.checked", "LowStar.Modifies.fst.checked", "LowStar.BufferOps.fst.checked", "LowStar.Buffer.fst.checked", "FStar.UInt32.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked", "FStar.List.Pure.Properties.fst.checked", "FStar.List.Pure.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked", "FStar.Classical.fsti.checked" ], "interface_file": false, "source_file": "DoublyLinkedList.fst" }
[ { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": true, "full_module": "LowStar.Modifies", "short_module": "Mod" }, { "abbrev": false, "full_module": "LowStar.BufferOps", "short_module": null }, { "abbrev": false, "full_module": "FStar.List.Pure", "short_module": null }, { "abbrev": false, "full_module": "FStar.List.Tot", "short_module": null }, { "abbrev": false, "full_module": "LowStar.ModifiesPat", "short_module": null }, { "abbrev": false, "full_module": "FStar.Ghost", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
h0: DoublyLinkedList.heap -> nl: DoublyLinkedList.nodelist t -> Prims.GTot Type0
Prims.GTot
[ "sometrivial" ]
[]
[ "DoublyLinkedList.heap", "DoublyLinkedList.nodelist", "Prims.l_and", "DoublyLinkedList.nodelist_contained", "DoublyLinkedList.nodelist_aa", "DoublyLinkedList.nodelist_conn" ]
[]
false
false
false
false
true
let nodelist_valid (#t: Type) (h0: heap) (nl: nodelist t) : GTot Type0 =
nodelist_contained h0 nl /\ nodelist_aa nl /\ nodelist_conn h0 nl
false
DoublyLinkedList.fst
DoublyLinkedList.piece_conn
val piece_conn (#t: Type) (h0: heap) (p: piece t) : GTot Type0
val piece_conn (#t: Type) (h0: heap) (p: piece t) : GTot Type0
let piece_conn (#t:Type) (h0:heap) (p:piece t) : GTot Type0 = nodelist_conn h0 p.pnodes
{ "file_name": "examples/doublylinkedlist/DoublyLinkedList.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 27, "end_line": 373, "start_col": 0, "start_line": 372 }
(* Copyright 2008-2019 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module DoublyLinkedList open FStar open FStar.HyperStack.ST open FStar.Ghost open LowStar.ModifiesPat open FStar.List.Tot open FStar.List.Pure open LowStar.BufferOps module Mod = LowStar.Modifies module ST = FStar.HyperStack.ST module HS = FStar.HyperStack module B = LowStar.Buffer /// Convenience renaming unfold let heap = HS.mem unfold let contains #a #rrel #rel h b = B.live #a #rrel #rel h b /// Convenience patterns let lemma_non_null (#t:Type) (a:pointer_or_null t) : Lemma (requires (a =!= null)) (ensures (len a = 1ul)) [SMTPat (len a)] = null_unique a /// Convenience operators unfold let (.[]) (s:list 'a) (n:nat{n < length s}) = index s n unfold let (~.) (#t:Type) (a:t) : Tot (erased (list t)) = [a] unfold let (^+) (#t:Type) (a:t) (b:erased (list t)) : Tot (erased (list t)) = Cons a b unfold let (+^) (#t:Type) (a:erased (list t)) (b:t) : Tot (erased (list t)) = append a [b] unfold let (^@^) (#t:Type) (a:erased (list t)) (b:erased (list t)) : Tot (erased (list t)) = append a b unfold let (@) (a:pointer 't) (h0:heap) = B.get h0 a 0 unfold let (^@) (a:pointer_or_null 't{a =!= null}) (h0:heap) = B.get h0 a 0 /// All the data structures #set-options "--__no_positivity" unopteq (** Node of a doubly linked list *) type node (t:Type0) = { (* forward link *) flink: pointer_or_null (node t); (* backward link *) blink: pointer_or_null (node t); (* payload *) p: t; } #reset-options private type nodelist t = list (pointer (node t)) unopteq (** Doubly linked list head *) type dll (t:Type0) ={ lhead: pointer_or_null (node t); ltail: pointer_or_null (node t); nodes: erased (nodelist t); } type nonempty_dll t = (h:dll t{h.lhead =!= null /\ h.ltail =!= null}) unopteq private (** An "almost valid" dll *) type piece t = { phead: pointer (node t); ptail: pointer (node t); pnodes: erased (nodelist t); } unopteq private (** An intermediate for when linked lists are being formed or destroyed *) type fragment t = | Frag0 : fragment t | Frag1 : piece t -> fragment t | Frag2 : piece t -> piece t -> fragment t | Frag3 : piece t -> piece t -> piece t -> fragment t /// Some useful empty initializers (** Initialize an element of a doubly linked list *) val empty_node: #t:Type -> payload:t -> node t let empty_node #t payload = { flink = null ; blink = null ; p = payload } (** Initialize a doubly linked list head *) val empty_list: #t:Type -> dll t let empty_list #t = { lhead = null ; ltail = null ; nodes = [] } /// Convenience wrappers for writing properties on fragments let fragment_for_each0 (#t:Type) (pr:piece t -> GTot Type0) (f:fragment t) : GTot Type0 = match f with | Frag0 -> True | Frag1 p1 -> pr p1 | Frag2 p1 p2 -> pr p1 /\ pr p2 | Frag3 p1 p2 p3 -> pr p1 /\ pr p2 /\ pr p3 let fragment_for_each1 (#t:Type) (#u:Type) (pr:u -> piece t -> GTot Type0) (v:u) (f:fragment t) : GTot Type0 = match f with | Frag0 -> True | Frag1 p1 -> pr v p1 | Frag2 p1 p2 -> pr v p1 /\ pr v p2 | Frag3 p1 p2 p3 -> pr v p1 /\ pr v p2 /\ pr v p3 let fragment_length (#t:Type) (f:fragment t) : GTot int = match f with | Frag0 -> 0 | Frag1 _ -> 1 | Frag2 _ _ -> 2 | Frag3 _ _ _ -> 3 /// Ghostly connections let dll_ghostly_connections (#t:Type) (d:dll t) : GTot Type0 = let nodes = d.nodes in match length nodes with | 0 -> d.lhead == null /\ d.ltail == null | _ -> d.lhead =!= null /\ d.ltail =!= null /\ d.lhead == hd nodes /\ d.ltail == last nodes let piece_ghostly_connections (#t:Type) (p:piece t) : GTot Type0 = let nodes = p.pnodes in match length nodes with | 0 -> False | _ -> p.phead == hd nodes /\ p.ptail == last nodes let rec fragment_ghostly_connections (#t:Type) (f:fragment t) : GTot Type0 = fragment_for_each0 piece_ghostly_connections f /// Containment properties /// /// WARNING: [@@] and [^@] require containment to reasonably talk about /// what they do. let rec nodelist_contained0 (#t:Type) (h0:heap) (nl:nodelist t) : GTot Type0 = match nl with | [] -> True | n :: ns -> h0 `contains` n /\ nodelist_contained0 h0 ns let rec nodelist_contained (#t:Type) (h0:heap) (nl:nodelist t) : GTot Type0 = nodelist_contained0 h0 nl let dll_contained (#t:Type) (h0:heap) (d:dll t) : GTot Type0 = h0 `contains` d.lhead /\ h0 `contains` d.ltail /\ nodelist_contained h0 d.nodes let piece_contained (#t:Type) (h0:heap) (p:piece t) : GTot Type0 = h0 `contains` p.phead /\ h0 `contains` p.ptail /\ nodelist_contained h0 p.pnodes let rec fragment_contained (#t:Type) (h0:heap) (f:fragment t) : GTot Type0 = fragment_for_each1 piece_contained h0 f /// Footprints let node_fp_f (#t:Type) (n:node t) : GTot Mod.loc = Mod.loc_buffer n.flink let node_fp_b (#t:Type) (n:node t) : GTot Mod.loc = Mod.loc_buffer n.blink let rec nodelist_fp0 (#t:Type) (n:nodelist t) : GTot Mod.loc = match n with | [] -> Mod.loc_none | n :: ns -> Mod.loc_union (Mod.loc_buffer n) (nodelist_fp0 ns) let rec nodelist_fp_f (#t:Type) (h0:heap) (n:nodelist t) : GTot Mod.loc = match n with | [] -> Mod.loc_none | n :: ns -> Mod.loc_union (Mod.loc_buffer (n@h0).flink) (nodelist_fp_f h0 ns) let rec nodelist_fp_b (#t:Type) (h0:heap) (n:nodelist t) : GTot Mod.loc = match n with | [] -> Mod.loc_none | n :: ns -> Mod.loc_union (Mod.loc_buffer (n@h0).blink) (nodelist_fp_b h0 ns) let dll_fp0 (#t:Type) (d:dll t) : GTot Mod.loc = Mod.loc_union // ghostly connections should give us this union for // free, but still useful to have (Mod.loc_union (Mod.loc_buffer d.lhead) (Mod.loc_buffer d.ltail)) (nodelist_fp0 d.nodes) let dll_fp_f (#t:Type) (h0:heap) (d:dll t) : GTot Mod.loc = let a = if g_is_null d.lhead then Mod.loc_none else Mod.loc_buffer (d.lhead^@h0).flink in let b = if g_is_null d.ltail then Mod.loc_none else Mod.loc_buffer (d.ltail^@h0).flink in Mod.loc_union // ghostly connections should give us this union for // free, but still useful to have (Mod.loc_union a b) (nodelist_fp_f h0 d.nodes) let dll_fp_b (#t:Type) (h0:heap) (d:dll t) : GTot Mod.loc = let a = if g_is_null d.lhead then Mod.loc_none else Mod.loc_buffer (d.lhead^@h0).blink in let b = if g_is_null d.ltail then Mod.loc_none else Mod.loc_buffer (d.ltail^@h0).blink in Mod.loc_union // ghostly connections should give us this union for // free, but still useful to have (Mod.loc_union a b) (nodelist_fp_b h0 d.nodes) let piece_fp0 (#t:Type) (p:piece t) : GTot Mod.loc = Mod.loc_union // ghostly connections should give us this union for // free, but still useful to have (Mod.loc_union (Mod.loc_buffer p.phead) (Mod.loc_buffer p.ptail)) (nodelist_fp0 p.pnodes) let piece_fp_f (#t:Type) (h0:heap) (p:piece t) : GTot Mod.loc = Mod.loc_union // ghostly connections should give us this union for // free, but still useful to have (Mod.loc_union (Mod.loc_buffer (p.phead@h0).flink) (Mod.loc_buffer (p.ptail@h0).flink)) (nodelist_fp_f h0 p.pnodes) let piece_fp_b (#t:Type) (h0:heap) (p:piece t) : GTot Mod.loc = Mod.loc_union // ghostly connections should give us this union for // free, but still useful to have (Mod.loc_union (Mod.loc_buffer (p.phead@h0).blink) (Mod.loc_buffer (p.ptail@h0).blink)) (nodelist_fp_b h0 p.pnodes) let rec fragment_fp0 (#t:Type) (f:fragment t) : GTot Mod.loc = match f with | Frag0 -> Mod.loc_none | Frag1 p1 -> piece_fp0 p1 | Frag2 p1 p2 -> Mod.loc_union (piece_fp0 p1) (piece_fp0 p2) | Frag3 p1 p2 p3 -> Mod.loc_union (piece_fp0 p1) (Mod.loc_union (piece_fp0 p2) (piece_fp0 p3)) /// Helper patterns for footprints let loc_includes_union_l_nodelist_fp0 (#t: Type) (s1 s2:loc) (nl:nodelist t) : Lemma (requires (loc_includes s1 (nodelist_fp0 nl) \/ loc_includes s2 (nodelist_fp0 nl))) (ensures (loc_includes (loc_union s1 s2) (nodelist_fp0 nl))) [SMTPat (loc_includes (loc_union s1 s2) (nodelist_fp0 nl))] = loc_includes_union_l s1 s2 (nodelist_fp0 nl) let loc_includes_union_l_dll_fp0 (#t: Type) (s1 s2:loc) (d:dll t) : Lemma (requires (loc_includes s1 (dll_fp0 d) \/ loc_includes s2 (dll_fp0 d))) (ensures (loc_includes (loc_union s1 s2) (dll_fp0 d))) [SMTPat (loc_includes (loc_union s1 s2) (dll_fp0 d))] = loc_includes_union_l s1 s2 (dll_fp0 d) let loc_includes_union_l_piece_fp0 (#t: Type) (s1 s2:loc) (p:piece t) : Lemma (requires (loc_includes s1 (piece_fp0 p) \/ loc_includes s2 (piece_fp0 p))) (ensures (loc_includes (loc_union s1 s2) (piece_fp0 p))) [SMTPat (loc_includes (loc_union s1 s2) (piece_fp0 p))] = loc_includes_union_l s1 s2 (piece_fp0 p) let loc_includes_union_l_fragment_fp0 (#t: Type) (s1 s2:loc) (f:fragment t) : Lemma (requires (loc_includes s1 (fragment_fp0 f) \/ loc_includes s2 (fragment_fp0 f))) (ensures (loc_includes (loc_union s1 s2) (fragment_fp0 f))) [SMTPat (loc_includes (loc_union s1 s2) (fragment_fp0 f))] = loc_includes_union_l s1 s2 (fragment_fp0 f) /// Equivalence for locations let loc_equiv (a b:Mod.loc) = Mod.loc_includes a b /\ Mod.loc_includes b a let loc_equiv_trans (a b c:Mod.loc) : Lemma (requires (loc_equiv a b /\ loc_equiv b c)) (ensures (loc_equiv a c)) [SMTPat (loc_equiv a b); SMTPat (loc_equiv b c); SMTPat (loc_equiv a c)] = Mod.loc_includes_trans a b c; Mod.loc_includes_trans c b a let loc_equiv_union_union_loc (a b c:Mod.loc) : Lemma (requires (loc_equiv b c)) (ensures (loc_equiv (Mod.loc_union a b) (Mod.loc_union a c))) [SMTPat (loc_equiv (Mod.loc_union a b) (Mod.loc_union a c))] = let incl = Mod.loc_includes in let u = Mod.loc_union in // assert (b `incl` c); Mod.loc_includes_union_l a b c; // assert ((a `u` b) `incl` c); Mod.loc_includes_union_l a b a; // assert ((a `u` b) `incl` a); // assert ((a `u` b) `incl` (a `u` c)); Mod.loc_includes_union_l a c b; Mod.loc_includes_union_l a c a /// Anti aliasing properties let node_aa (#t:Type) (n:node t) : GTot Type0 = Mod.loc_disjoint (node_fp_f n) (node_fp_b n) let rec nodelist_aa_r (#t:Type) (nl:nodelist t) : GTot Type0 = match nl with | [] -> True | n :: ns -> Mod.loc_disjoint (Mod.loc_buffer n) (nodelist_fp0 ns) /\ nodelist_aa_r ns let rec nodelist_aa_l (#t:Type) (nl:nodelist t) : GTot Type0 (decreases (length nl)) = match nl with | [] -> True | _ -> let ns, n = unsnoc nl in lemma_unsnoc_length nl; Mod.loc_disjoint (Mod.loc_buffer n) (nodelist_fp0 ns) /\ nodelist_aa_l ns let nodelist_aa (#t:Type) (nl:nodelist t) : GTot Type0 = nodelist_aa_l nl /\ nodelist_aa_r nl let dll_aa (#t:Type) (d:dll t) : GTot Type0 = nodelist_aa d.nodes let piece_aa (#t:Type) (p:piece t) : GTot Type0 = nodelist_aa p.pnodes let rec fragment_aa0 (#t:Type) (f:fragment t) : GTot Type0 = fragment_for_each0 piece_aa f let rec fragment_aa_lr (#t:Type) (f:fragment t) : GTot Type0 = match f with | Frag0 -> True | Frag1 p1 -> True | Frag2 p1 p2 -> Mod.loc_disjoint (piece_fp0 p1) (piece_fp0 p2) | Frag3 p1 p2 p3 -> ((Mod.loc_disjoint (piece_fp0 p1) (piece_fp0 p2)) /\ (Mod.loc_disjoint (piece_fp0 p2) (piece_fp0 p3)) /\ (Mod.loc_disjoint (piece_fp0 p3) (piece_fp0 p1))) let fragment_aa (#t:Type) (f:fragment t) : GTot Type0 = fragment_aa0 f /\ fragment_aa_lr f /// Connectivity properties let ( |>> ) (#t:Type) (a:node t) (b:pointer (node t)) : GTot Type0 = a.flink == b let ( <<| ) (#t:Type) (a:pointer (node t)) (b: node t) : GTot Type0 = b.blink == a let rec nodelist_conn (#t:Type) (h0:heap) (nl:nodelist t) : GTot Type0 (decreases (length nl)) = match nl with | [] -> True | n1 :: rest -> match rest with | [] -> True | n2 :: ns -> n1@h0 |>> n2 /\ n1 <<| n2@h0 /\ nodelist_conn h0 rest let dll_conn (#t:Type) (h0:heap) (d:dll t) : GTot Type0 = nodelist_conn h0 d.nodes /\ (d.lhead =!= null ==> (d.lhead@h0).blink == null) /\ (d.ltail =!= null ==> (d.ltail@h0).flink == null)
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowStar.ModifiesPat.fst.checked", "LowStar.Modifies.fst.checked", "LowStar.BufferOps.fst.checked", "LowStar.Buffer.fst.checked", "FStar.UInt32.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked", "FStar.List.Pure.Properties.fst.checked", "FStar.List.Pure.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked", "FStar.Classical.fsti.checked" ], "interface_file": false, "source_file": "DoublyLinkedList.fst" }
[ { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": true, "full_module": "LowStar.Modifies", "short_module": "Mod" }, { "abbrev": false, "full_module": "LowStar.BufferOps", "short_module": null }, { "abbrev": false, "full_module": "FStar.List.Pure", "short_module": null }, { "abbrev": false, "full_module": "FStar.List.Tot", "short_module": null }, { "abbrev": false, "full_module": "LowStar.ModifiesPat", "short_module": null }, { "abbrev": false, "full_module": "FStar.Ghost", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
h0: DoublyLinkedList.heap -> p: DoublyLinkedList.piece t -> Prims.GTot Type0
Prims.GTot
[ "sometrivial" ]
[]
[ "DoublyLinkedList.heap", "DoublyLinkedList.piece", "DoublyLinkedList.nodelist_conn", "FStar.Ghost.reveal", "DoublyLinkedList.nodelist", "DoublyLinkedList.__proj__Mkpiece__item__pnodes" ]
[]
false
false
false
false
true
let piece_conn (#t: Type) (h0: heap) (p: piece t) : GTot Type0 =
nodelist_conn h0 p.pnodes
false
DoublyLinkedList.fst
DoublyLinkedList.fragment_fp0
val fragment_fp0 (#t: Type) (f: fragment t) : GTot Mod.loc
val fragment_fp0 (#t: Type) (f: fragment t) : GTot Mod.loc
let rec fragment_fp0 (#t:Type) (f:fragment t) : GTot Mod.loc = match f with | Frag0 -> Mod.loc_none | Frag1 p1 -> piece_fp0 p1 | Frag2 p1 p2 -> Mod.loc_union (piece_fp0 p1) (piece_fp0 p2) | Frag3 p1 p2 p3 -> Mod.loc_union (piece_fp0 p1) (Mod.loc_union (piece_fp0 p2) (piece_fp0 p3))
{ "file_name": "examples/doublylinkedlist/DoublyLinkedList.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 96, "end_line": 243, "start_col": 0, "start_line": 238 }
(* Copyright 2008-2019 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module DoublyLinkedList open FStar open FStar.HyperStack.ST open FStar.Ghost open LowStar.ModifiesPat open FStar.List.Tot open FStar.List.Pure open LowStar.BufferOps module Mod = LowStar.Modifies module ST = FStar.HyperStack.ST module HS = FStar.HyperStack module B = LowStar.Buffer /// Convenience renaming unfold let heap = HS.mem unfold let contains #a #rrel #rel h b = B.live #a #rrel #rel h b /// Convenience patterns let lemma_non_null (#t:Type) (a:pointer_or_null t) : Lemma (requires (a =!= null)) (ensures (len a = 1ul)) [SMTPat (len a)] = null_unique a /// Convenience operators unfold let (.[]) (s:list 'a) (n:nat{n < length s}) = index s n unfold let (~.) (#t:Type) (a:t) : Tot (erased (list t)) = [a] unfold let (^+) (#t:Type) (a:t) (b:erased (list t)) : Tot (erased (list t)) = Cons a b unfold let (+^) (#t:Type) (a:erased (list t)) (b:t) : Tot (erased (list t)) = append a [b] unfold let (^@^) (#t:Type) (a:erased (list t)) (b:erased (list t)) : Tot (erased (list t)) = append a b unfold let (@) (a:pointer 't) (h0:heap) = B.get h0 a 0 unfold let (^@) (a:pointer_or_null 't{a =!= null}) (h0:heap) = B.get h0 a 0 /// All the data structures #set-options "--__no_positivity" unopteq (** Node of a doubly linked list *) type node (t:Type0) = { (* forward link *) flink: pointer_or_null (node t); (* backward link *) blink: pointer_or_null (node t); (* payload *) p: t; } #reset-options private type nodelist t = list (pointer (node t)) unopteq (** Doubly linked list head *) type dll (t:Type0) ={ lhead: pointer_or_null (node t); ltail: pointer_or_null (node t); nodes: erased (nodelist t); } type nonempty_dll t = (h:dll t{h.lhead =!= null /\ h.ltail =!= null}) unopteq private (** An "almost valid" dll *) type piece t = { phead: pointer (node t); ptail: pointer (node t); pnodes: erased (nodelist t); } unopteq private (** An intermediate for when linked lists are being formed or destroyed *) type fragment t = | Frag0 : fragment t | Frag1 : piece t -> fragment t | Frag2 : piece t -> piece t -> fragment t | Frag3 : piece t -> piece t -> piece t -> fragment t /// Some useful empty initializers (** Initialize an element of a doubly linked list *) val empty_node: #t:Type -> payload:t -> node t let empty_node #t payload = { flink = null ; blink = null ; p = payload } (** Initialize a doubly linked list head *) val empty_list: #t:Type -> dll t let empty_list #t = { lhead = null ; ltail = null ; nodes = [] } /// Convenience wrappers for writing properties on fragments let fragment_for_each0 (#t:Type) (pr:piece t -> GTot Type0) (f:fragment t) : GTot Type0 = match f with | Frag0 -> True | Frag1 p1 -> pr p1 | Frag2 p1 p2 -> pr p1 /\ pr p2 | Frag3 p1 p2 p3 -> pr p1 /\ pr p2 /\ pr p3 let fragment_for_each1 (#t:Type) (#u:Type) (pr:u -> piece t -> GTot Type0) (v:u) (f:fragment t) : GTot Type0 = match f with | Frag0 -> True | Frag1 p1 -> pr v p1 | Frag2 p1 p2 -> pr v p1 /\ pr v p2 | Frag3 p1 p2 p3 -> pr v p1 /\ pr v p2 /\ pr v p3 let fragment_length (#t:Type) (f:fragment t) : GTot int = match f with | Frag0 -> 0 | Frag1 _ -> 1 | Frag2 _ _ -> 2 | Frag3 _ _ _ -> 3 /// Ghostly connections let dll_ghostly_connections (#t:Type) (d:dll t) : GTot Type0 = let nodes = d.nodes in match length nodes with | 0 -> d.lhead == null /\ d.ltail == null | _ -> d.lhead =!= null /\ d.ltail =!= null /\ d.lhead == hd nodes /\ d.ltail == last nodes let piece_ghostly_connections (#t:Type) (p:piece t) : GTot Type0 = let nodes = p.pnodes in match length nodes with | 0 -> False | _ -> p.phead == hd nodes /\ p.ptail == last nodes let rec fragment_ghostly_connections (#t:Type) (f:fragment t) : GTot Type0 = fragment_for_each0 piece_ghostly_connections f /// Containment properties /// /// WARNING: [@@] and [^@] require containment to reasonably talk about /// what they do. let rec nodelist_contained0 (#t:Type) (h0:heap) (nl:nodelist t) : GTot Type0 = match nl with | [] -> True | n :: ns -> h0 `contains` n /\ nodelist_contained0 h0 ns let rec nodelist_contained (#t:Type) (h0:heap) (nl:nodelist t) : GTot Type0 = nodelist_contained0 h0 nl let dll_contained (#t:Type) (h0:heap) (d:dll t) : GTot Type0 = h0 `contains` d.lhead /\ h0 `contains` d.ltail /\ nodelist_contained h0 d.nodes let piece_contained (#t:Type) (h0:heap) (p:piece t) : GTot Type0 = h0 `contains` p.phead /\ h0 `contains` p.ptail /\ nodelist_contained h0 p.pnodes let rec fragment_contained (#t:Type) (h0:heap) (f:fragment t) : GTot Type0 = fragment_for_each1 piece_contained h0 f /// Footprints let node_fp_f (#t:Type) (n:node t) : GTot Mod.loc = Mod.loc_buffer n.flink let node_fp_b (#t:Type) (n:node t) : GTot Mod.loc = Mod.loc_buffer n.blink let rec nodelist_fp0 (#t:Type) (n:nodelist t) : GTot Mod.loc = match n with | [] -> Mod.loc_none | n :: ns -> Mod.loc_union (Mod.loc_buffer n) (nodelist_fp0 ns) let rec nodelist_fp_f (#t:Type) (h0:heap) (n:nodelist t) : GTot Mod.loc = match n with | [] -> Mod.loc_none | n :: ns -> Mod.loc_union (Mod.loc_buffer (n@h0).flink) (nodelist_fp_f h0 ns) let rec nodelist_fp_b (#t:Type) (h0:heap) (n:nodelist t) : GTot Mod.loc = match n with | [] -> Mod.loc_none | n :: ns -> Mod.loc_union (Mod.loc_buffer (n@h0).blink) (nodelist_fp_b h0 ns) let dll_fp0 (#t:Type) (d:dll t) : GTot Mod.loc = Mod.loc_union // ghostly connections should give us this union for // free, but still useful to have (Mod.loc_union (Mod.loc_buffer d.lhead) (Mod.loc_buffer d.ltail)) (nodelist_fp0 d.nodes) let dll_fp_f (#t:Type) (h0:heap) (d:dll t) : GTot Mod.loc = let a = if g_is_null d.lhead then Mod.loc_none else Mod.loc_buffer (d.lhead^@h0).flink in let b = if g_is_null d.ltail then Mod.loc_none else Mod.loc_buffer (d.ltail^@h0).flink in Mod.loc_union // ghostly connections should give us this union for // free, but still useful to have (Mod.loc_union a b) (nodelist_fp_f h0 d.nodes) let dll_fp_b (#t:Type) (h0:heap) (d:dll t) : GTot Mod.loc = let a = if g_is_null d.lhead then Mod.loc_none else Mod.loc_buffer (d.lhead^@h0).blink in let b = if g_is_null d.ltail then Mod.loc_none else Mod.loc_buffer (d.ltail^@h0).blink in Mod.loc_union // ghostly connections should give us this union for // free, but still useful to have (Mod.loc_union a b) (nodelist_fp_b h0 d.nodes) let piece_fp0 (#t:Type) (p:piece t) : GTot Mod.loc = Mod.loc_union // ghostly connections should give us this union for // free, but still useful to have (Mod.loc_union (Mod.loc_buffer p.phead) (Mod.loc_buffer p.ptail)) (nodelist_fp0 p.pnodes) let piece_fp_f (#t:Type) (h0:heap) (p:piece t) : GTot Mod.loc = Mod.loc_union // ghostly connections should give us this union for // free, but still useful to have (Mod.loc_union (Mod.loc_buffer (p.phead@h0).flink) (Mod.loc_buffer (p.ptail@h0).flink)) (nodelist_fp_f h0 p.pnodes) let piece_fp_b (#t:Type) (h0:heap) (p:piece t) : GTot Mod.loc = Mod.loc_union // ghostly connections should give us this union for // free, but still useful to have (Mod.loc_union (Mod.loc_buffer (p.phead@h0).blink) (Mod.loc_buffer (p.ptail@h0).blink)) (nodelist_fp_b h0 p.pnodes)
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowStar.ModifiesPat.fst.checked", "LowStar.Modifies.fst.checked", "LowStar.BufferOps.fst.checked", "LowStar.Buffer.fst.checked", "FStar.UInt32.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked", "FStar.List.Pure.Properties.fst.checked", "FStar.List.Pure.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked", "FStar.Classical.fsti.checked" ], "interface_file": false, "source_file": "DoublyLinkedList.fst" }
[ { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": true, "full_module": "LowStar.Modifies", "short_module": "Mod" }, { "abbrev": false, "full_module": "LowStar.BufferOps", "short_module": null }, { "abbrev": false, "full_module": "FStar.List.Pure", "short_module": null }, { "abbrev": false, "full_module": "FStar.List.Tot", "short_module": null }, { "abbrev": false, "full_module": "LowStar.ModifiesPat", "short_module": null }, { "abbrev": false, "full_module": "FStar.Ghost", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
f: DoublyLinkedList.fragment t -> Prims.GTot LowStar.Monotonic.Buffer.loc
Prims.GTot
[ "sometrivial" ]
[]
[ "DoublyLinkedList.fragment", "LowStar.Monotonic.Buffer.loc_none", "DoublyLinkedList.piece", "DoublyLinkedList.piece_fp0", "LowStar.Monotonic.Buffer.loc_union", "LowStar.Monotonic.Buffer.loc" ]
[ "recursion" ]
false
false
false
false
false
let rec fragment_fp0 (#t: Type) (f: fragment t) : GTot Mod.loc =
match f with | Frag0 -> Mod.loc_none | Frag1 p1 -> piece_fp0 p1 | Frag2 p1 p2 -> Mod.loc_union (piece_fp0 p1) (piece_fp0 p2) | Frag3 p1 p2 p3 -> Mod.loc_union (piece_fp0 p1) (Mod.loc_union (piece_fp0 p2) (piece_fp0 p3))
false
DoublyLinkedList.fst
DoublyLinkedList.loc_equiv_trans
val loc_equiv_trans (a b c: Mod.loc) : Lemma (requires (loc_equiv a b /\ loc_equiv b c)) (ensures (loc_equiv a c)) [SMTPat (loc_equiv a b); SMTPat (loc_equiv b c); SMTPat (loc_equiv a c)]
val loc_equiv_trans (a b c: Mod.loc) : Lemma (requires (loc_equiv a b /\ loc_equiv b c)) (ensures (loc_equiv a c)) [SMTPat (loc_equiv a b); SMTPat (loc_equiv b c); SMTPat (loc_equiv a c)]
let loc_equiv_trans (a b c:Mod.loc) : Lemma (requires (loc_equiv a b /\ loc_equiv b c)) (ensures (loc_equiv a c)) [SMTPat (loc_equiv a b); SMTPat (loc_equiv b c); SMTPat (loc_equiv a c)] = Mod.loc_includes_trans a b c; Mod.loc_includes_trans c b a
{ "file_name": "examples/doublylinkedlist/DoublyLinkedList.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 30, "end_line": 287, "start_col": 0, "start_line": 279 }
(* Copyright 2008-2019 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module DoublyLinkedList open FStar open FStar.HyperStack.ST open FStar.Ghost open LowStar.ModifiesPat open FStar.List.Tot open FStar.List.Pure open LowStar.BufferOps module Mod = LowStar.Modifies module ST = FStar.HyperStack.ST module HS = FStar.HyperStack module B = LowStar.Buffer /// Convenience renaming unfold let heap = HS.mem unfold let contains #a #rrel #rel h b = B.live #a #rrel #rel h b /// Convenience patterns let lemma_non_null (#t:Type) (a:pointer_or_null t) : Lemma (requires (a =!= null)) (ensures (len a = 1ul)) [SMTPat (len a)] = null_unique a /// Convenience operators unfold let (.[]) (s:list 'a) (n:nat{n < length s}) = index s n unfold let (~.) (#t:Type) (a:t) : Tot (erased (list t)) = [a] unfold let (^+) (#t:Type) (a:t) (b:erased (list t)) : Tot (erased (list t)) = Cons a b unfold let (+^) (#t:Type) (a:erased (list t)) (b:t) : Tot (erased (list t)) = append a [b] unfold let (^@^) (#t:Type) (a:erased (list t)) (b:erased (list t)) : Tot (erased (list t)) = append a b unfold let (@) (a:pointer 't) (h0:heap) = B.get h0 a 0 unfold let (^@) (a:pointer_or_null 't{a =!= null}) (h0:heap) = B.get h0 a 0 /// All the data structures #set-options "--__no_positivity" unopteq (** Node of a doubly linked list *) type node (t:Type0) = { (* forward link *) flink: pointer_or_null (node t); (* backward link *) blink: pointer_or_null (node t); (* payload *) p: t; } #reset-options private type nodelist t = list (pointer (node t)) unopteq (** Doubly linked list head *) type dll (t:Type0) ={ lhead: pointer_or_null (node t); ltail: pointer_or_null (node t); nodes: erased (nodelist t); } type nonempty_dll t = (h:dll t{h.lhead =!= null /\ h.ltail =!= null}) unopteq private (** An "almost valid" dll *) type piece t = { phead: pointer (node t); ptail: pointer (node t); pnodes: erased (nodelist t); } unopteq private (** An intermediate for when linked lists are being formed or destroyed *) type fragment t = | Frag0 : fragment t | Frag1 : piece t -> fragment t | Frag2 : piece t -> piece t -> fragment t | Frag3 : piece t -> piece t -> piece t -> fragment t /// Some useful empty initializers (** Initialize an element of a doubly linked list *) val empty_node: #t:Type -> payload:t -> node t let empty_node #t payload = { flink = null ; blink = null ; p = payload } (** Initialize a doubly linked list head *) val empty_list: #t:Type -> dll t let empty_list #t = { lhead = null ; ltail = null ; nodes = [] } /// Convenience wrappers for writing properties on fragments let fragment_for_each0 (#t:Type) (pr:piece t -> GTot Type0) (f:fragment t) : GTot Type0 = match f with | Frag0 -> True | Frag1 p1 -> pr p1 | Frag2 p1 p2 -> pr p1 /\ pr p2 | Frag3 p1 p2 p3 -> pr p1 /\ pr p2 /\ pr p3 let fragment_for_each1 (#t:Type) (#u:Type) (pr:u -> piece t -> GTot Type0) (v:u) (f:fragment t) : GTot Type0 = match f with | Frag0 -> True | Frag1 p1 -> pr v p1 | Frag2 p1 p2 -> pr v p1 /\ pr v p2 | Frag3 p1 p2 p3 -> pr v p1 /\ pr v p2 /\ pr v p3 let fragment_length (#t:Type) (f:fragment t) : GTot int = match f with | Frag0 -> 0 | Frag1 _ -> 1 | Frag2 _ _ -> 2 | Frag3 _ _ _ -> 3 /// Ghostly connections let dll_ghostly_connections (#t:Type) (d:dll t) : GTot Type0 = let nodes = d.nodes in match length nodes with | 0 -> d.lhead == null /\ d.ltail == null | _ -> d.lhead =!= null /\ d.ltail =!= null /\ d.lhead == hd nodes /\ d.ltail == last nodes let piece_ghostly_connections (#t:Type) (p:piece t) : GTot Type0 = let nodes = p.pnodes in match length nodes with | 0 -> False | _ -> p.phead == hd nodes /\ p.ptail == last nodes let rec fragment_ghostly_connections (#t:Type) (f:fragment t) : GTot Type0 = fragment_for_each0 piece_ghostly_connections f /// Containment properties /// /// WARNING: [@@] and [^@] require containment to reasonably talk about /// what they do. let rec nodelist_contained0 (#t:Type) (h0:heap) (nl:nodelist t) : GTot Type0 = match nl with | [] -> True | n :: ns -> h0 `contains` n /\ nodelist_contained0 h0 ns let rec nodelist_contained (#t:Type) (h0:heap) (nl:nodelist t) : GTot Type0 = nodelist_contained0 h0 nl let dll_contained (#t:Type) (h0:heap) (d:dll t) : GTot Type0 = h0 `contains` d.lhead /\ h0 `contains` d.ltail /\ nodelist_contained h0 d.nodes let piece_contained (#t:Type) (h0:heap) (p:piece t) : GTot Type0 = h0 `contains` p.phead /\ h0 `contains` p.ptail /\ nodelist_contained h0 p.pnodes let rec fragment_contained (#t:Type) (h0:heap) (f:fragment t) : GTot Type0 = fragment_for_each1 piece_contained h0 f /// Footprints let node_fp_f (#t:Type) (n:node t) : GTot Mod.loc = Mod.loc_buffer n.flink let node_fp_b (#t:Type) (n:node t) : GTot Mod.loc = Mod.loc_buffer n.blink let rec nodelist_fp0 (#t:Type) (n:nodelist t) : GTot Mod.loc = match n with | [] -> Mod.loc_none | n :: ns -> Mod.loc_union (Mod.loc_buffer n) (nodelist_fp0 ns) let rec nodelist_fp_f (#t:Type) (h0:heap) (n:nodelist t) : GTot Mod.loc = match n with | [] -> Mod.loc_none | n :: ns -> Mod.loc_union (Mod.loc_buffer (n@h0).flink) (nodelist_fp_f h0 ns) let rec nodelist_fp_b (#t:Type) (h0:heap) (n:nodelist t) : GTot Mod.loc = match n with | [] -> Mod.loc_none | n :: ns -> Mod.loc_union (Mod.loc_buffer (n@h0).blink) (nodelist_fp_b h0 ns) let dll_fp0 (#t:Type) (d:dll t) : GTot Mod.loc = Mod.loc_union // ghostly connections should give us this union for // free, but still useful to have (Mod.loc_union (Mod.loc_buffer d.lhead) (Mod.loc_buffer d.ltail)) (nodelist_fp0 d.nodes) let dll_fp_f (#t:Type) (h0:heap) (d:dll t) : GTot Mod.loc = let a = if g_is_null d.lhead then Mod.loc_none else Mod.loc_buffer (d.lhead^@h0).flink in let b = if g_is_null d.ltail then Mod.loc_none else Mod.loc_buffer (d.ltail^@h0).flink in Mod.loc_union // ghostly connections should give us this union for // free, but still useful to have (Mod.loc_union a b) (nodelist_fp_f h0 d.nodes) let dll_fp_b (#t:Type) (h0:heap) (d:dll t) : GTot Mod.loc = let a = if g_is_null d.lhead then Mod.loc_none else Mod.loc_buffer (d.lhead^@h0).blink in let b = if g_is_null d.ltail then Mod.loc_none else Mod.loc_buffer (d.ltail^@h0).blink in Mod.loc_union // ghostly connections should give us this union for // free, but still useful to have (Mod.loc_union a b) (nodelist_fp_b h0 d.nodes) let piece_fp0 (#t:Type) (p:piece t) : GTot Mod.loc = Mod.loc_union // ghostly connections should give us this union for // free, but still useful to have (Mod.loc_union (Mod.loc_buffer p.phead) (Mod.loc_buffer p.ptail)) (nodelist_fp0 p.pnodes) let piece_fp_f (#t:Type) (h0:heap) (p:piece t) : GTot Mod.loc = Mod.loc_union // ghostly connections should give us this union for // free, but still useful to have (Mod.loc_union (Mod.loc_buffer (p.phead@h0).flink) (Mod.loc_buffer (p.ptail@h0).flink)) (nodelist_fp_f h0 p.pnodes) let piece_fp_b (#t:Type) (h0:heap) (p:piece t) : GTot Mod.loc = Mod.loc_union // ghostly connections should give us this union for // free, but still useful to have (Mod.loc_union (Mod.loc_buffer (p.phead@h0).blink) (Mod.loc_buffer (p.ptail@h0).blink)) (nodelist_fp_b h0 p.pnodes) let rec fragment_fp0 (#t:Type) (f:fragment t) : GTot Mod.loc = match f with | Frag0 -> Mod.loc_none | Frag1 p1 -> piece_fp0 p1 | Frag2 p1 p2 -> Mod.loc_union (piece_fp0 p1) (piece_fp0 p2) | Frag3 p1 p2 p3 -> Mod.loc_union (piece_fp0 p1) (Mod.loc_union (piece_fp0 p2) (piece_fp0 p3)) /// Helper patterns for footprints let loc_includes_union_l_nodelist_fp0 (#t: Type) (s1 s2:loc) (nl:nodelist t) : Lemma (requires (loc_includes s1 (nodelist_fp0 nl) \/ loc_includes s2 (nodelist_fp0 nl))) (ensures (loc_includes (loc_union s1 s2) (nodelist_fp0 nl))) [SMTPat (loc_includes (loc_union s1 s2) (nodelist_fp0 nl))] = loc_includes_union_l s1 s2 (nodelist_fp0 nl) let loc_includes_union_l_dll_fp0 (#t: Type) (s1 s2:loc) (d:dll t) : Lemma (requires (loc_includes s1 (dll_fp0 d) \/ loc_includes s2 (dll_fp0 d))) (ensures (loc_includes (loc_union s1 s2) (dll_fp0 d))) [SMTPat (loc_includes (loc_union s1 s2) (dll_fp0 d))] = loc_includes_union_l s1 s2 (dll_fp0 d) let loc_includes_union_l_piece_fp0 (#t: Type) (s1 s2:loc) (p:piece t) : Lemma (requires (loc_includes s1 (piece_fp0 p) \/ loc_includes s2 (piece_fp0 p))) (ensures (loc_includes (loc_union s1 s2) (piece_fp0 p))) [SMTPat (loc_includes (loc_union s1 s2) (piece_fp0 p))] = loc_includes_union_l s1 s2 (piece_fp0 p) let loc_includes_union_l_fragment_fp0 (#t: Type) (s1 s2:loc) (f:fragment t) : Lemma (requires (loc_includes s1 (fragment_fp0 f) \/ loc_includes s2 (fragment_fp0 f))) (ensures (loc_includes (loc_union s1 s2) (fragment_fp0 f))) [SMTPat (loc_includes (loc_union s1 s2) (fragment_fp0 f))] = loc_includes_union_l s1 s2 (fragment_fp0 f) /// Equivalence for locations let loc_equiv (a b:Mod.loc) = Mod.loc_includes a b /\ Mod.loc_includes b a
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowStar.ModifiesPat.fst.checked", "LowStar.Modifies.fst.checked", "LowStar.BufferOps.fst.checked", "LowStar.Buffer.fst.checked", "FStar.UInt32.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked", "FStar.List.Pure.Properties.fst.checked", "FStar.List.Pure.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked", "FStar.Classical.fsti.checked" ], "interface_file": false, "source_file": "DoublyLinkedList.fst" }
[ { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": true, "full_module": "LowStar.Modifies", "short_module": "Mod" }, { "abbrev": false, "full_module": "LowStar.BufferOps", "short_module": null }, { "abbrev": false, "full_module": "FStar.List.Pure", "short_module": null }, { "abbrev": false, "full_module": "FStar.List.Tot", "short_module": null }, { "abbrev": false, "full_module": "LowStar.ModifiesPat", "short_module": null }, { "abbrev": false, "full_module": "FStar.Ghost", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
a: LowStar.Monotonic.Buffer.loc -> b: LowStar.Monotonic.Buffer.loc -> c: LowStar.Monotonic.Buffer.loc -> FStar.Pervasives.Lemma (requires DoublyLinkedList.loc_equiv a b /\ DoublyLinkedList.loc_equiv b c) (ensures DoublyLinkedList.loc_equiv a c) [ SMTPat (DoublyLinkedList.loc_equiv a b); SMTPat (DoublyLinkedList.loc_equiv b c); SMTPat (DoublyLinkedList.loc_equiv a c) ]
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "LowStar.Monotonic.Buffer.loc", "LowStar.Monotonic.Buffer.loc_includes_trans", "Prims.unit", "Prims.l_and", "DoublyLinkedList.loc_equiv", "Prims.squash", "Prims.Cons", "FStar.Pervasives.pattern", "FStar.Pervasives.smt_pat", "Prims.logical", "Prims.Nil" ]
[]
true
false
true
false
false
let loc_equiv_trans (a b c: Mod.loc) : Lemma (requires (loc_equiv a b /\ loc_equiv b c)) (ensures (loc_equiv a c)) [SMTPat (loc_equiv a b); SMTPat (loc_equiv b c); SMTPat (loc_equiv a c)] =
Mod.loc_includes_trans a b c; Mod.loc_includes_trans c b a
false