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
MerkleTree.Low.Datastructures.fst
MerkleTree.Low.Datastructures.hash_r_inv
val hash_r_inv: #hsz:hash_size_t -> h:HS.mem -> v:hash #hsz -> GTot Type0
val hash_r_inv: #hsz:hash_size_t -> h:HS.mem -> v:hash #hsz -> GTot Type0
let hash_r_inv #hsz h v = B.live h v /\ B.freeable v /\ B.len v = hsz
{ "file_name": "src/MerkleTree.Low.Datastructures.fst", "git_rev": "7d7bdc20f2033171e279c176b26e84f9069d23c6", "git_url": "https://github.com/hacl-star/merkle-tree.git", "project_name": "merkle-tree" }
{ "end_col": 15, "end_line": 63, "start_col": 0, "start_line": 61 }
module MerkleTree.Low.Datastructures open FStar.All open FStar.Integers open FStar.Mul open LowStar.Buffer open LowStar.BufferOps open LowStar.Vector open LowStar.Regional open LowStar.RVector open LowStar.Regional.Instances module HS = FStar.HyperStack module HST = FStar.HyperStack.ST module MHS = FStar.Monotonic.HyperStack module HH = FStar.Monotonic.HyperHeap module B = LowStar.Buffer module CB = LowStar.ConstBuffer module V = LowStar.Vector module RV = LowStar.RVector module RVI = LowStar.Regional.Instances module S = FStar.Seq module EHS = EverCrypt.Hash module U32 = FStar.UInt32 module MTH = MerkleTree.New.High open EverCrypt.Helpers open Lib.IntTypes #set-options "--z3rlimit 10 --initial_fuel 0 --max_fuel 0 --initial_ifuel 0 --max_ifuel 0" type hash_size_t = n:uint32_t{n > 0ul} type hash (#hsz:hash_size_t) = b:B.buffer uint8 { B.len b = hsz \/ B.g_is_null b } // We cannot use `Low.RVector.Instances`, where we have some general // typeclass instances of `regional`, e.g., if `rg:regional a` then // `regional (rvector rg)`. In FStar we can use this, but KaRaMeL currently // cannot deal with this and gives a number of errors. // So we temporarily instantiate some `regional`s manually below, which is // extractable to C by KaRaMeL. /// Some instantiations of `regional` used in Merkle tree /// 1. `hash` is regional private noextract val hash_region_of: #hsz:hash_size_t -> v:hash #hsz -> GTot HH.rid let hash_region_of #_ v = B.frameOf v private inline_for_extraction val hash_dummy: #hsz:Ghost.erased hash_size_t -> Tot (hash #hsz) let hash_dummy #_ = B.null private noextract
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "MerkleTree.New.High.fst.checked", "LowStar.Vector.fst.checked", "LowStar.RVector.fst.checked", "LowStar.Regional.Instances.fst.checked", "LowStar.Regional.fst.checked", "LowStar.ConstBuffer.fsti.checked", "LowStar.BufferOps.fst.checked", "LowStar.Buffer.fst.checked", "Lib.IntTypes.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Set.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Monotonic.HyperStack.fsti.checked", "FStar.Monotonic.HyperHeap.fsti.checked", "FStar.Map.fsti.checked", "FStar.Integers.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked", "FStar.All.fst.checked", "EverCrypt.Helpers.fsti.checked", "EverCrypt.Hash.fsti.checked" ], "interface_file": false, "source_file": "MerkleTree.Low.Datastructures.fst" }
[ { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "EverCrypt.Helpers", "short_module": null }, { "abbrev": true, "full_module": "MerkleTree.New.High", "short_module": "MTH" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": true, "full_module": "EverCrypt.Hash", "short_module": "EHS" }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "S" }, { "abbrev": true, "full_module": "LowStar.Regional.Instances", "short_module": "RVI" }, { "abbrev": true, "full_module": "LowStar.RVector", "short_module": "RV" }, { "abbrev": true, "full_module": "LowStar.Vector", "short_module": "V" }, { "abbrev": true, "full_module": "LowStar.ConstBuffer", "short_module": "CB" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.Monotonic.HyperHeap", "short_module": "HH" }, { "abbrev": true, "full_module": "FStar.Monotonic.HyperStack", "short_module": "MHS" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": false, "full_module": "LowStar.Regional.Instances", "short_module": null }, { "abbrev": false, "full_module": "LowStar.RVector", "short_module": null }, { "abbrev": false, "full_module": "LowStar.Regional", "short_module": null }, { "abbrev": false, "full_module": "LowStar.Vector", "short_module": null }, { "abbrev": false, "full_module": "LowStar.BufferOps", "short_module": null }, { "abbrev": false, "full_module": "LowStar.Buffer", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.Integers", "short_module": null }, { "abbrev": false, "full_module": "FStar.All", "short_module": null }, { "abbrev": false, "full_module": "MerkleTree.Low", "short_module": null }, { "abbrev": false, "full_module": "MerkleTree.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": 0, "initial_ifuel": 0, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 10, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
h: FStar.Monotonic.HyperStack.mem -> v: MerkleTree.Low.Datastructures.hash -> Prims.GTot Type0
Prims.GTot
[ "sometrivial" ]
[]
[ "MerkleTree.Low.Datastructures.hash_size_t", "FStar.Monotonic.HyperStack.mem", "MerkleTree.Low.Datastructures.hash", "Prims.l_and", "LowStar.Monotonic.Buffer.live", "Lib.IntTypes.uint8", "LowStar.Buffer.trivial_preorder", "LowStar.Monotonic.Buffer.freeable", "Prims.b2t", "Prims.op_Equality", "FStar.UInt32.t", "LowStar.Monotonic.Buffer.len" ]
[]
false
false
false
false
true
let hash_r_inv #hsz h v =
B.live h v /\ B.freeable v /\ B.len v = hsz
false
Vale.Math.Poly2_s.fst
Vale.Math.Poly2_s.reverse
val reverse (p:poly) (n:nat) : poly
val reverse (p:poly) (n:nat) : poly
let reverse p n = D.reverse p n
{ "file_name": "vale/specs/math/Vale.Math.Poly2_s.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 31, "end_line": 11, "start_col": 0, "start_line": 11 }
module Vale.Math.Poly2_s open FStar.Mul open FStar.Seq let poly = D.poly let degree p = D.degree p let zero = D.zero let one = D.one let monomial n = D.monomial n
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked" ], "interface_file": true, "source_file": "Vale.Math.Poly2_s.fst" }
[ { "abbrev": false, "full_module": "FStar.Seq", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.Seq", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": true, "full_module": "Vale.Math.Poly2.Defs_s", "short_module": "D" }, { "abbrev": false, "full_module": "Vale.Math", "short_module": null }, { "abbrev": false, "full_module": "Vale.Math", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "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: Vale.Math.Poly2_s.poly -> n: Prims.nat -> Vale.Math.Poly2_s.poly
Prims.Tot
[ "total" ]
[]
[ "Vale.Math.Poly2_s.poly", "Prims.nat", "Vale.Math.Poly2.Defs_s.reverse" ]
[]
false
false
false
true
false
let reverse p n =
D.reverse p n
false
Vale.Math.Poly2_s.fst
Vale.Math.Poly2_s.monomial
val monomial (n:nat) : poly
val monomial (n:nat) : poly
let monomial n = D.monomial n
{ "file_name": "vale/specs/math/Vale.Math.Poly2_s.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 29, "end_line": 9, "start_col": 0, "start_line": 9 }
module Vale.Math.Poly2_s open FStar.Mul open FStar.Seq let poly = D.poly let degree p = D.degree p let zero = D.zero
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked" ], "interface_file": true, "source_file": "Vale.Math.Poly2_s.fst" }
[ { "abbrev": false, "full_module": "FStar.Seq", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.Seq", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": true, "full_module": "Vale.Math.Poly2.Defs_s", "short_module": "D" }, { "abbrev": false, "full_module": "Vale.Math", "short_module": null }, { "abbrev": false, "full_module": "Vale.Math", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "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
n: Prims.nat -> Vale.Math.Poly2_s.poly
Prims.Tot
[ "total" ]
[]
[ "Prims.nat", "Vale.Math.Poly2.Defs_s.monomial", "Vale.Math.Poly2_s.poly" ]
[]
false
false
false
true
false
let monomial n =
D.monomial n
false
Vale.Math.Poly2_s.fst
Vale.Math.Poly2_s.shift
val shift (p:poly) (n:int) : poly
val shift (p:poly) (n:int) : poly
let shift p n = D.shift p n
{ "file_name": "vale/specs/math/Vale.Math.Poly2_s.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 27, "end_line": 10, "start_col": 0, "start_line": 10 }
module Vale.Math.Poly2_s open FStar.Mul open FStar.Seq let poly = D.poly let degree p = D.degree p let zero = D.zero let one = D.one
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked" ], "interface_file": true, "source_file": "Vale.Math.Poly2_s.fst" }
[ { "abbrev": false, "full_module": "FStar.Seq", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.Seq", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": true, "full_module": "Vale.Math.Poly2.Defs_s", "short_module": "D" }, { "abbrev": false, "full_module": "Vale.Math", "short_module": null }, { "abbrev": false, "full_module": "Vale.Math", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "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: Vale.Math.Poly2_s.poly -> n: Prims.int -> Vale.Math.Poly2_s.poly
Prims.Tot
[ "total" ]
[]
[ "Vale.Math.Poly2_s.poly", "Prims.int", "Vale.Math.Poly2.Defs_s.shift" ]
[]
false
false
false
true
false
let shift p n =
D.shift p n
false
Hacl.Impl.K256.PointDouble.fst
Hacl.Impl.K256.PointDouble.calc_bzz9_tmp
val calc_bzz9_tmp (yy zz bzz3 bzz9 tmp:felem) : Stack unit (requires fun h -> live h yy /\ live h zz /\ live h bzz3 /\ live h bzz9 /\ live h tmp /\ disjoint yy zz /\ disjoint yy bzz3 /\ disjoint yy bzz9 /\ disjoint yy tmp /\ disjoint zz bzz3 /\ disjoint zz bzz9 /\ disjoint zz tmp /\ disjoint bzz3 bzz9 /\ disjoint bzz3 tmp /\ disjoint bzz9 tmp /\ inv_lazy_reduced2 h yy /\ inv_lazy_reduced2 h zz) (ensures fun h0 _ h1 -> modifies (loc bzz3 |+| loc bzz9 |+| loc tmp) h0 h1 /\ (let bzz3 = S.fmul (S.fmul 3 S.b) (feval h0 zz) in feval h1 bzz9 = S.fsub (feval h0 yy) (S.fmul 3 bzz3) /\ feval h1 tmp = S.fmul (feval h1 bzz9) (S.fadd (feval h0 yy) bzz3) /\ inv_lazy_reduced2 h1 tmp /\ felem_fits5 (as_felem5 h1 bzz9) (13,13,13,13,14)))
val calc_bzz9_tmp (yy zz bzz3 bzz9 tmp:felem) : Stack unit (requires fun h -> live h yy /\ live h zz /\ live h bzz3 /\ live h bzz9 /\ live h tmp /\ disjoint yy zz /\ disjoint yy bzz3 /\ disjoint yy bzz9 /\ disjoint yy tmp /\ disjoint zz bzz3 /\ disjoint zz bzz9 /\ disjoint zz tmp /\ disjoint bzz3 bzz9 /\ disjoint bzz3 tmp /\ disjoint bzz9 tmp /\ inv_lazy_reduced2 h yy /\ inv_lazy_reduced2 h zz) (ensures fun h0 _ h1 -> modifies (loc bzz3 |+| loc bzz9 |+| loc tmp) h0 h1 /\ (let bzz3 = S.fmul (S.fmul 3 S.b) (feval h0 zz) in feval h1 bzz9 = S.fsub (feval h0 yy) (S.fmul 3 bzz3) /\ feval h1 tmp = S.fmul (feval h1 bzz9) (S.fadd (feval h0 yy) bzz3) /\ inv_lazy_reduced2 h1 tmp /\ felem_fits5 (as_felem5 h1 bzz9) (13,13,13,13,14)))
let calc_bzz9_tmp yy zz bzz3 bzz9 tmp = fmul_3b_normalize_weak bzz3 zz; //bzz3 = (3*b)*zz let h1 = ST.get () in //assert (inv_lazy_reduced2 h1 bzz3); fmul_small_num bzz9 bzz3 (u64 3); //bzz9 = 3*bzz3 let h2 = ST.get () in BL.fmul15_lemma (1,1,1,1,2) 3 (as_felem5 h1 bzz3) (u64 3); //assert (felem_fits5 (as_felem5 h2 bzz9) (3,3,3,3,6)); BL.fsub5_lemma (1,1,1,1,2) (3,3,3,3,6) (as_felem5 h1 yy) (as_felem5 h2 bzz9) (u64 6); fsub bzz9 yy bzz9 (u64 6); //bzz9 = yy_m_bzz9 = yy-bzz9 let h3 = ST.get () in //assert (felem_fits5 (as_felem5 h3 bzz9) (13,13,13,13,14)); fadd tmp yy bzz3; //tmp = yy_p_bzz3 = yy+bzz3 let h4 = ST.get () in BL.fadd5_lemma (1,1,1,1,2) (1,1,1,1,2) (as_felem5 h1 yy) (as_felem5 h1 bzz3); //assert (felem_fits5 (as_felem5 h4 tmp) (2,2,2,2,4)); fmul tmp bzz9 tmp
{ "file_name": "code/k256/Hacl.Impl.K256.PointDouble.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 19, "end_line": 81, "start_col": 0, "start_line": 61 }
module Hacl.Impl.K256.PointDouble open FStar.HyperStack open FStar.HyperStack.ST open FStar.Mul open Lib.IntTypes open Lib.Buffer module ST = FStar.HyperStack.ST module S = Spec.K256 module BL = Hacl.Spec.K256.Field52.Lemmas open Hacl.K256.Field open Hacl.Impl.K256.Point #set-options "--z3rlimit 300 --fuel 0 --ifuel 0" inline_for_extraction noextract val calc_z3 (y1 z1 z3 yy tmp:felem) : Stack unit (requires fun h -> live h y1 /\ live h z1 /\ live h z3 /\ live h yy /\ live h tmp /\ disjoint y1 z1 /\ disjoint y1 z3 /\ disjoint y1 yy /\ disjoint y1 tmp /\ eq_or_disjoint z1 z3 /\ disjoint z1 yy /\ disjoint z1 tmp /\ disjoint z3 yy /\ disjoint z3 tmp /\ disjoint yy tmp /\ inv_lazy_reduced2 h y1 /\ inv_lazy_reduced2 h z1 /\ inv_lazy_reduced2 h yy) (ensures fun h0 _ h1 -> modifies (loc tmp |+| loc z3) h0 h1 /\ feval h1 z3 = S.fmul (S.fmul (S.fmul (feval h0 yy) (feval h0 y1)) (feval h0 z1)) 8 /\ inv_lazy_reduced2 h1 z3) let calc_z3 y1 z1 z3 yy tmp = fmul tmp yy y1; //tmp = yy*y fmul z3 tmp z1; //z3 = tmp*z = yy*y*z let h1 = ST.get () in //assert (inv_lazy_reduced2 h1 x3); //assert (inv_lazy_reduced2 h1 tmp); //assert (inv_lazy_reduced2 h1 z3); fmul_8_normalize_weak z3 z3 //z3 = z3*8=yy*y*z*8 inline_for_extraction noextract val calc_bzz9_tmp (yy zz bzz3 bzz9 tmp:felem) : Stack unit (requires fun h -> live h yy /\ live h zz /\ live h bzz3 /\ live h bzz9 /\ live h tmp /\ disjoint yy zz /\ disjoint yy bzz3 /\ disjoint yy bzz9 /\ disjoint yy tmp /\ disjoint zz bzz3 /\ disjoint zz bzz9 /\ disjoint zz tmp /\ disjoint bzz3 bzz9 /\ disjoint bzz3 tmp /\ disjoint bzz9 tmp /\ inv_lazy_reduced2 h yy /\ inv_lazy_reduced2 h zz) (ensures fun h0 _ h1 -> modifies (loc bzz3 |+| loc bzz9 |+| loc tmp) h0 h1 /\ (let bzz3 = S.fmul (S.fmul 3 S.b) (feval h0 zz) in feval h1 bzz9 = S.fsub (feval h0 yy) (S.fmul 3 bzz3) /\ feval h1 tmp = S.fmul (feval h1 bzz9) (S.fadd (feval h0 yy) bzz3) /\ inv_lazy_reduced2 h1 tmp /\ felem_fits5 (as_felem5 h1 bzz9) (13,13,13,13,14)))
{ "checked_file": "/", "dependencies": [ "Spec.K256.fst.checked", "prims.fst.checked", "Lib.IntTypes.fsti.checked", "Lib.Buffer.fsti.checked", "Hacl.Spec.K256.Field52.Lemmas.fsti.checked", "Hacl.K256.Field.fsti.checked", "Hacl.Impl.K256.Point.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked" ], "interface_file": false, "source_file": "Hacl.Impl.K256.PointDouble.fst" }
[ { "abbrev": false, "full_module": "Hacl.Impl.K256.Point", "short_module": null }, { "abbrev": false, "full_module": "Hacl.K256.Field", "short_module": null }, { "abbrev": true, "full_module": "Hacl.Spec.K256.Field52.Lemmas", "short_module": "BL" }, { "abbrev": true, "full_module": "Spec.K256", "short_module": "S" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": false, "full_module": "Lib.Buffer", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Impl.K256", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Impl.K256", "short_module": null }, { "abbrev": 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": 300, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
yy: Hacl.K256.Field.felem -> zz: Hacl.K256.Field.felem -> bzz3: Hacl.K256.Field.felem -> bzz9: Hacl.K256.Field.felem -> tmp: Hacl.K256.Field.felem -> FStar.HyperStack.ST.Stack Prims.unit
FStar.HyperStack.ST.Stack
[]
[]
[ "Hacl.K256.Field.felem", "Hacl.K256.Field.fmul", "Prims.unit", "Hacl.Spec.K256.Field52.Lemmas.fadd5_lemma", "FStar.Pervasives.Native.Mktuple5", "Prims.nat", "Hacl.K256.Field.as_felem5", "FStar.Monotonic.HyperStack.mem", "FStar.HyperStack.ST.get", "Hacl.K256.Field.fadd", "Hacl.K256.Field.fsub", "Lib.IntTypes.u64", "Hacl.Spec.K256.Field52.Lemmas.fsub5_lemma", "Hacl.Spec.K256.Field52.Lemmas.fmul15_lemma", "Hacl.K256.Field.fmul_small_num", "Hacl.K256.Field.fmul_3b_normalize_weak" ]
[]
false
true
false
false
false
let calc_bzz9_tmp yy zz bzz3 bzz9 tmp =
fmul_3b_normalize_weak bzz3 zz; let h1 = ST.get () in fmul_small_num bzz9 bzz3 (u64 3); let h2 = ST.get () in BL.fmul15_lemma (1, 1, 1, 1, 2) 3 (as_felem5 h1 bzz3) (u64 3); BL.fsub5_lemma (1, 1, 1, 1, 2) (3, 3, 3, 3, 6) (as_felem5 h1 yy) (as_felem5 h2 bzz9) (u64 6); fsub bzz9 yy bzz9 (u64 6); let h3 = ST.get () in fadd tmp yy bzz3; let h4 = ST.get () in BL.fadd5_lemma (1, 1, 1, 1, 2) (1, 1, 1, 1, 2) (as_felem5 h1 yy) (as_felem5 h1 bzz3); fmul tmp bzz9 tmp
false
Vale.Math.Poly2_s.fst
Vale.Math.Poly2_s.poly_index
val poly_index (p:poly) (n:int) : bool
val poly_index (p:poly) (n:int) : bool
let poly_index p n = D.poly_index p n
{ "file_name": "vale/specs/math/Vale.Math.Poly2_s.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 37, "end_line": 12, "start_col": 0, "start_line": 12 }
module Vale.Math.Poly2_s open FStar.Mul open FStar.Seq let poly = D.poly let degree p = D.degree p let zero = D.zero let one = D.one let monomial n = D.monomial n let shift p n = D.shift p n
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked" ], "interface_file": true, "source_file": "Vale.Math.Poly2_s.fst" }
[ { "abbrev": false, "full_module": "FStar.Seq", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.Seq", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": true, "full_module": "Vale.Math.Poly2.Defs_s", "short_module": "D" }, { "abbrev": false, "full_module": "Vale.Math", "short_module": null }, { "abbrev": false, "full_module": "Vale.Math", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "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: Vale.Math.Poly2_s.poly -> n: Prims.int -> Prims.bool
Prims.Tot
[ "total" ]
[]
[ "Vale.Math.Poly2_s.poly", "Prims.int", "Vale.Math.Poly2.Defs_s.poly_index", "Prims.bool" ]
[]
false
false
false
true
false
let poly_index p n =
D.poly_index p n
false
Vale.Math.Poly2_s.fst
Vale.Math.Poly2_s.add
val add (a b:poly) : poly
val add (a b:poly) : poly
let add a b = D.add a b
{ "file_name": "vale/specs/math/Vale.Math.Poly2_s.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 23, "end_line": 16, "start_col": 0, "start_line": 16 }
module Vale.Math.Poly2_s open FStar.Mul open FStar.Seq let poly = D.poly let degree p = D.degree p let zero = D.zero let one = D.one let monomial n = D.monomial n let shift p n = D.shift p n let reverse p n = D.reverse p n let poly_index p n = D.poly_index p n let to_seq s n = D.to_seq s n let of_seq s = D.of_seq s
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked" ], "interface_file": true, "source_file": "Vale.Math.Poly2_s.fst" }
[ { "abbrev": false, "full_module": "FStar.Seq", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.Seq", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": true, "full_module": "Vale.Math.Poly2.Defs_s", "short_module": "D" }, { "abbrev": false, "full_module": "Vale.Math", "short_module": null }, { "abbrev": false, "full_module": "Vale.Math", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "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
a: Vale.Math.Poly2_s.poly -> b: Vale.Math.Poly2_s.poly -> Vale.Math.Poly2_s.poly
Prims.Tot
[ "total" ]
[]
[ "Vale.Math.Poly2_s.poly", "Vale.Math.Poly2.Defs_s.add" ]
[]
false
false
false
true
false
let add a b =
D.add a b
false
Vale.Math.Poly2_s.fst
Vale.Math.Poly2_s.mul
val mul (a b:poly) : poly
val mul (a b:poly) : poly
let mul a b = D.mul a b
{ "file_name": "vale/specs/math/Vale.Math.Poly2_s.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 23, "end_line": 17, "start_col": 0, "start_line": 17 }
module Vale.Math.Poly2_s open FStar.Mul open FStar.Seq let poly = D.poly let degree p = D.degree p let zero = D.zero let one = D.one let monomial n = D.monomial n let shift p n = D.shift p n let reverse p n = D.reverse p n let poly_index p n = D.poly_index p n let to_seq s n = D.to_seq s n let of_seq s = D.of_seq s let of_fun len f = D.of_fun len f
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked" ], "interface_file": true, "source_file": "Vale.Math.Poly2_s.fst" }
[ { "abbrev": false, "full_module": "FStar.Seq", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.Seq", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": true, "full_module": "Vale.Math.Poly2.Defs_s", "short_module": "D" }, { "abbrev": false, "full_module": "Vale.Math", "short_module": null }, { "abbrev": false, "full_module": "Vale.Math", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "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
a: Vale.Math.Poly2_s.poly -> b: Vale.Math.Poly2_s.poly -> Vale.Math.Poly2_s.poly
Prims.Tot
[ "total" ]
[]
[ "Vale.Math.Poly2_s.poly", "Vale.Math.Poly2.Defs_s.mul" ]
[]
false
false
false
true
false
let mul a b =
D.mul a b
false
Vale.Math.Poly2_s.fst
Vale.Math.Poly2_s.zero
val zero : poly
val zero : poly
let zero = D.zero
{ "file_name": "vale/specs/math/Vale.Math.Poly2_s.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 17, "end_line": 7, "start_col": 0, "start_line": 7 }
module Vale.Math.Poly2_s open FStar.Mul open FStar.Seq let poly = D.poly
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked" ], "interface_file": true, "source_file": "Vale.Math.Poly2_s.fst" }
[ { "abbrev": false, "full_module": "FStar.Seq", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.Seq", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": true, "full_module": "Vale.Math.Poly2.Defs_s", "short_module": "D" }, { "abbrev": false, "full_module": "Vale.Math", "short_module": null }, { "abbrev": false, "full_module": "Vale.Math", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "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.Math.Poly2_s.poly
Prims.Tot
[ "total" ]
[]
[ "Vale.Math.Poly2.Defs_s.zero" ]
[]
false
false
false
true
false
let zero =
D.zero
false
Vale.Math.Poly2_s.fst
Vale.Math.Poly2_s.poly
val poly : eqtype
val poly : eqtype
let poly = D.poly
{ "file_name": "vale/specs/math/Vale.Math.Poly2_s.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 17, "end_line": 5, "start_col": 0, "start_line": 5 }
module Vale.Math.Poly2_s open FStar.Mul open FStar.Seq
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked" ], "interface_file": true, "source_file": "Vale.Math.Poly2_s.fst" }
[ { "abbrev": false, "full_module": "FStar.Seq", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.Seq", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": true, "full_module": "Vale.Math.Poly2.Defs_s", "short_module": "D" }, { "abbrev": false, "full_module": "Vale.Math", "short_module": null }, { "abbrev": false, "full_module": "Vale.Math", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "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.eqtype
Prims.Tot
[ "total" ]
[]
[ "Vale.Math.Poly2.Defs_s.poly" ]
[]
false
false
false
true
false
let poly =
D.poly
false
FStar.UInt64.fsti
FStar.UInt64.n
val n : Prims.int
let n = 64
{ "file_name": "ulib/FStar.UInt64.fsti", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 17, "end_line": 20, "start_col": 7, "start_line": 20 }
(* 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 FStar.UInt64 (**** THIS MODULE IS GENERATED AUTOMATICALLY USING [mk_int.sh], DO NOT EDIT DIRECTLY ****)
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.UInt32.fsti.checked", "FStar.UInt.fsti.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked" ], "interface_file": false, "source_file": "FStar.UInt64.fsti" }
[ { "abbrev": false, "full_module": "FStar", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
Prims.int
Prims.Tot
[ "total" ]
[]
[]
[]
false
false
false
true
false
let n =
64
false
MerkleTree.Low.Datastructures.fst
MerkleTree.Low.Datastructures.hash_r_alloc_p
val hash_r_alloc_p: #hsz:hash_size_t -> v:hash #hsz -> GTot Type0
val hash_r_alloc_p: #hsz:hash_size_t -> v:hash #hsz -> GTot Type0
let hash_r_alloc_p #_ v = True
{ "file_name": "src/MerkleTree.Low.Datastructures.fst", "git_rev": "7d7bdc20f2033171e279c176b26e84f9069d23c6", "git_url": "https://github.com/hacl-star/merkle-tree.git", "project_name": "merkle-tree" }
{ "end_col": 30, "end_line": 112, "start_col": 0, "start_line": 112 }
module MerkleTree.Low.Datastructures open FStar.All open FStar.Integers open FStar.Mul open LowStar.Buffer open LowStar.BufferOps open LowStar.Vector open LowStar.Regional open LowStar.RVector open LowStar.Regional.Instances module HS = FStar.HyperStack module HST = FStar.HyperStack.ST module MHS = FStar.Monotonic.HyperStack module HH = FStar.Monotonic.HyperHeap module B = LowStar.Buffer module CB = LowStar.ConstBuffer module V = LowStar.Vector module RV = LowStar.RVector module RVI = LowStar.Regional.Instances module S = FStar.Seq module EHS = EverCrypt.Hash module U32 = FStar.UInt32 module MTH = MerkleTree.New.High open EverCrypt.Helpers open Lib.IntTypes #set-options "--z3rlimit 10 --initial_fuel 0 --max_fuel 0 --initial_ifuel 0 --max_ifuel 0" type hash_size_t = n:uint32_t{n > 0ul} type hash (#hsz:hash_size_t) = b:B.buffer uint8 { B.len b = hsz \/ B.g_is_null b } // We cannot use `Low.RVector.Instances`, where we have some general // typeclass instances of `regional`, e.g., if `rg:regional a` then // `regional (rvector rg)`. In FStar we can use this, but KaRaMeL currently // cannot deal with this and gives a number of errors. // So we temporarily instantiate some `regional`s manually below, which is // extractable to C by KaRaMeL. /// Some instantiations of `regional` used in Merkle tree /// 1. `hash` is regional private noextract val hash_region_of: #hsz:hash_size_t -> v:hash #hsz -> GTot HH.rid let hash_region_of #_ v = B.frameOf v private inline_for_extraction val hash_dummy: #hsz:Ghost.erased hash_size_t -> Tot (hash #hsz) let hash_dummy #_ = B.null private noextract val hash_r_inv: #hsz:hash_size_t -> h:HS.mem -> v:hash #hsz -> GTot Type0 let hash_r_inv #hsz h v = B.live h v /\ B.freeable v /\ B.len v = hsz private noextract val hash_r_inv_reg: #hsz:hash_size_t -> h:HS.mem -> v:hash -> Lemma (requires hash_r_inv h v) (ensures MHS.live_region h (hash_region_of #hsz v)) let hash_r_inv_reg #_ h v = () private noextract val hash_repr (#hsz:hash_size_t): Type0 let hash_repr #hsz = MTH.hash #(U32.v hsz) private noextract val hash_r_repr: #hsz:hash_size_t -> h:HS.mem -> v:hash{hash_r_inv #hsz h v} -> GTot (hash_repr #hsz) let hash_r_repr #_ h v = B.as_seq h v private noextract val hash_r_sep: #hsz:hash_size_t -> v:hash #hsz -> p:loc -> h0:HS.mem -> h1:HS.mem -> Lemma (requires hash_r_inv h0 v /\ loc_disjoint (loc_all_regions_from false (hash_region_of v)) p /\ modifies p h0 h1) (ensures hash_r_inv h1 v /\ hash_r_repr h0 v == hash_r_repr h1 v) let hash_r_sep #_ v p h0 h1 = assert (loc_includes (loc_all_regions_from false (hash_region_of v)) (loc_buffer v)); B.modifies_buffer_elim v p h0 h1 private noextract val hash_irepr: #hsz:hash_size_t -> Ghost.erased (hash_repr #hsz) let hash_irepr #hsz = Ghost.hide (S.create (U32.v hsz) (u8 0)) private noextract
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "MerkleTree.New.High.fst.checked", "LowStar.Vector.fst.checked", "LowStar.RVector.fst.checked", "LowStar.Regional.Instances.fst.checked", "LowStar.Regional.fst.checked", "LowStar.ConstBuffer.fsti.checked", "LowStar.BufferOps.fst.checked", "LowStar.Buffer.fst.checked", "Lib.IntTypes.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Set.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Monotonic.HyperStack.fsti.checked", "FStar.Monotonic.HyperHeap.fsti.checked", "FStar.Map.fsti.checked", "FStar.Integers.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked", "FStar.All.fst.checked", "EverCrypt.Helpers.fsti.checked", "EverCrypt.Hash.fsti.checked" ], "interface_file": false, "source_file": "MerkleTree.Low.Datastructures.fst" }
[ { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "EverCrypt.Helpers", "short_module": null }, { "abbrev": true, "full_module": "MerkleTree.New.High", "short_module": "MTH" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": true, "full_module": "EverCrypt.Hash", "short_module": "EHS" }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "S" }, { "abbrev": true, "full_module": "LowStar.Regional.Instances", "short_module": "RVI" }, { "abbrev": true, "full_module": "LowStar.RVector", "short_module": "RV" }, { "abbrev": true, "full_module": "LowStar.Vector", "short_module": "V" }, { "abbrev": true, "full_module": "LowStar.ConstBuffer", "short_module": "CB" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.Monotonic.HyperHeap", "short_module": "HH" }, { "abbrev": true, "full_module": "FStar.Monotonic.HyperStack", "short_module": "MHS" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": false, "full_module": "LowStar.Regional.Instances", "short_module": null }, { "abbrev": false, "full_module": "LowStar.RVector", "short_module": null }, { "abbrev": false, "full_module": "LowStar.Regional", "short_module": null }, { "abbrev": false, "full_module": "LowStar.Vector", "short_module": null }, { "abbrev": false, "full_module": "LowStar.BufferOps", "short_module": null }, { "abbrev": false, "full_module": "LowStar.Buffer", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.Integers", "short_module": null }, { "abbrev": false, "full_module": "FStar.All", "short_module": null }, { "abbrev": false, "full_module": "MerkleTree.Low", "short_module": null }, { "abbrev": false, "full_module": "MerkleTree.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": 0, "initial_ifuel": 0, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 10, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
v: MerkleTree.Low.Datastructures.hash -> Prims.GTot Type0
Prims.GTot
[ "sometrivial" ]
[]
[ "MerkleTree.Low.Datastructures.hash_size_t", "MerkleTree.Low.Datastructures.hash", "Prims.l_True" ]
[]
false
false
false
false
true
let hash_r_alloc_p #_ v =
True
false
Vale.Math.Poly2_s.fst
Vale.Math.Poly2_s.one
val one : poly
val one : poly
let one = D.one
{ "file_name": "vale/specs/math/Vale.Math.Poly2_s.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 15, "end_line": 8, "start_col": 0, "start_line": 8 }
module Vale.Math.Poly2_s open FStar.Mul open FStar.Seq let poly = D.poly let degree p = D.degree p
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked" ], "interface_file": true, "source_file": "Vale.Math.Poly2_s.fst" }
[ { "abbrev": false, "full_module": "FStar.Seq", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.Seq", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": true, "full_module": "Vale.Math.Poly2.Defs_s", "short_module": "D" }, { "abbrev": false, "full_module": "Vale.Math", "short_module": null }, { "abbrev": false, "full_module": "Vale.Math", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "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.Math.Poly2_s.poly
Prims.Tot
[ "total" ]
[]
[ "Vale.Math.Poly2.Defs_s.one" ]
[]
false
false
false
true
false
let one =
D.one
false
FStar.UInt64.fsti
FStar.UInt64.eq
val eq (a b: t) : Tot bool
val eq (a b: t) : Tot bool
let eq (a:t) (b:t) : Tot bool = eq #n (v a) (v b)
{ "file_name": "ulib/FStar.UInt64.fsti", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 49, "end_line": 223, "start_col": 0, "start_line": 223 }
(* 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 FStar.UInt64 (**** THIS MODULE IS GENERATED AUTOMATICALLY USING [mk_int.sh], DO NOT EDIT DIRECTLY ****) unfold let n = 64 /// For FStar.UIntN.fstp: anything that you fix/update here should be /// reflected in [FStar.IntN.fstp], which is mostly a copy-paste of /// this module. /// /// Except, as compared to [FStar.IntN.fstp], here: /// - every occurrence of [int_t] has been replaced with [uint_t] /// - every occurrence of [@%] has been replaced with [%]. /// - some functions (e.g., add_underspec, etc.) are only defined here, not on signed integers /// This module provides an abstract type for machine integers of a /// given signedness and width. The interface is designed to be safe /// with respect to arithmetic underflow and overflow. /// Note, we have attempted several times to re-design this module to /// make it more amenable to normalization and to impose less overhead /// on the SMT solver when reasoning about machine integer /// arithmetic. The following github issue reports on the current /// status of that work. /// /// https://github.com/FStarLang/FStar/issues/1757 open FStar.UInt open FStar.Mul #set-options "--max_fuel 0 --max_ifuel 0" (** Abstract type of machine integers, with an underlying representation using a bounded mathematical integer *) new val t : eqtype (** A coercion that projects a bounded mathematical integer from a machine integer *) val v (x:t) : Tot (uint_t n) (** A coercion that injects a bounded mathematical integers into a machine integer *) val uint_to_t (x:uint_t n) : Pure t (requires True) (ensures (fun y -> v y = x)) (** Injection/projection inverse *) val uv_inv (x : t) : Lemma (ensures (uint_to_t (v x) == x)) [SMTPat (v x)] (** Projection/injection inverse *) val vu_inv (x : uint_t n) : Lemma (ensures (v (uint_to_t x) == x)) [SMTPat (uint_to_t x)] (** An alternate form of the injectivity of the [v] projection *) val v_inj (x1 x2: t): Lemma (requires (v x1 == v x2)) (ensures (x1 == x2)) (** Constants 0 and 1 *) val zero : x:t{v x = 0} val one : x:t{v x = 1} (**** Addition primitives *) (** Bounds-respecting addition The precondition enforces that the sum does not overflow, expressing the bound as an addition on mathematical integers *) val add (a:t) (b:t) : Pure t (requires (size (v a + v b) n)) (ensures (fun c -> v a + v b = v c)) (** Underspecified, possibly overflowing addition: The postcondition only enures that the result is the sum of the arguments in case there is no overflow *) val add_underspec (a:t) (b:t) : Pure t (requires True) (ensures (fun c -> size (v a + v b) n ==> v a + v b = v c)) (** Addition modulo [2^n] Machine integers can always be added, but the postcondition is now in terms of addition modulo [2^n] on mathematical integers *) val add_mod (a:t) (b:t) : Pure t (requires True) (ensures (fun c -> FStar.UInt.add_mod (v a) (v b) = v c)) (**** Subtraction primitives *) (** Bounds-respecting subtraction The precondition enforces that the difference does not underflow, expressing the bound as a difference on mathematical integers *) val sub (a:t) (b:t) : Pure t (requires (size (v a - v b) n)) (ensures (fun c -> v a - v b = v c)) (** Underspecified, possibly overflowing subtraction: The postcondition only enures that the result is the difference of the arguments in case there is no underflow *) val sub_underspec (a:t) (b:t) : Pure t (requires True) (ensures (fun c -> size (v a - v b) n ==> v a - v b = v c)) (** Subtraction modulo [2^n] Machine integers can always be subtractd, but the postcondition is now in terms of subtraction modulo [2^n] on mathematical integers *) val sub_mod (a:t) (b:t) : Pure t (requires True) (ensures (fun c -> FStar.UInt.sub_mod (v a) (v b) = v c)) (**** Multiplication primitives *) (** Bounds-respecting multiplication The precondition enforces that the product does not overflow, expressing the bound as a product on mathematical integers *) val mul (a:t) (b:t) : Pure t (requires (size (v a * v b) n)) (ensures (fun c -> v a * v b = v c)) (** Underspecified, possibly overflowing product The postcondition only enures that the result is the product of the arguments in case there is no overflow *) val mul_underspec (a:t) (b:t) : Pure t (requires True) (ensures (fun c -> size (v a * v b) n ==> v a * v b = v c)) (** Multiplication modulo [2^n] Machine integers can always be multiplied, but the postcondition is now in terms of product modulo [2^n] on mathematical integers *) val mul_mod (a:t) (b:t) : Pure t (requires True) (ensures (fun c -> FStar.UInt.mul_mod (v a) (v b) = v c)) (**** Division primitives *) (** Euclidean division of [a] and [b], with [b] non-zero *) val div (a:t) (b:t{v b <> 0}) : Pure t (requires (True)) (ensures (fun c -> v a / v b = v c)) (**** Modulo primitives *) (** Euclidean remainder The result is the modulus of [a] with respect to a non-zero [b] *) val rem (a:t) (b:t{v b <> 0}) : Pure t (requires True) (ensures (fun c -> FStar.UInt.mod (v a) (v b) = v c)) (**** Bitwise operators *) /// Also see FStar.BV (** Bitwise logical conjunction *) val logand (x:t) (y:t) : Pure t (requires True) (ensures (fun z -> v x `logand` v y = v z)) (** Bitwise logical exclusive-or *) val logxor (x:t) (y:t) : Pure t (requires True) (ensures (fun z -> v x `logxor` v y == v z)) (** Bitwise logical disjunction *) val logor (x:t) (y:t) : Pure t (requires True) (ensures (fun z -> v x `logor` v y == v z)) (** Bitwise logical negation *) val lognot (x:t) : Pure t (requires True) (ensures (fun z -> lognot (v x) == v z)) (**** Shift operators *) (** Shift right with zero fill, shifting at most the integer width *) val shift_right (a:t) (s:UInt32.t) : Pure t (requires (UInt32.v s < n)) (ensures (fun c -> FStar.UInt.shift_right (v a) (UInt32.v s) = v c)) (** Shift left with zero fill, shifting at most the integer width *) val shift_left (a:t) (s:UInt32.t) : Pure t (requires (UInt32.v s < n)) (ensures (fun c -> FStar.UInt.shift_left (v a) (UInt32.v s) = v c)) (**** Comparison operators *) (** Equality Note, it is safe to also use the polymorphic decidable equality
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.UInt32.fsti.checked", "FStar.UInt.fsti.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked" ], "interface_file": false, "source_file": "FStar.UInt64.fsti" }
[ { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.UInt", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.UInt", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
a: FStar.UInt64.t -> b: FStar.UInt64.t -> Prims.bool
Prims.Tot
[ "total" ]
[]
[ "FStar.UInt64.t", "FStar.UInt.eq", "FStar.UInt64.n", "FStar.UInt64.v", "Prims.bool" ]
[]
false
false
false
true
false
let eq (a b: t) : Tot bool =
eq #n (v a) (v b)
false
FStar.UInt64.fsti
FStar.UInt64.gt
val gt (a b: t) : Tot bool
val gt (a b: t) : Tot bool
let gt (a:t) (b:t) : Tot bool = gt #n (v a) (v b)
{ "file_name": "ulib/FStar.UInt64.fsti", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 49, "end_line": 226, "start_col": 0, "start_line": 226 }
(* 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 FStar.UInt64 (**** THIS MODULE IS GENERATED AUTOMATICALLY USING [mk_int.sh], DO NOT EDIT DIRECTLY ****) unfold let n = 64 /// For FStar.UIntN.fstp: anything that you fix/update here should be /// reflected in [FStar.IntN.fstp], which is mostly a copy-paste of /// this module. /// /// Except, as compared to [FStar.IntN.fstp], here: /// - every occurrence of [int_t] has been replaced with [uint_t] /// - every occurrence of [@%] has been replaced with [%]. /// - some functions (e.g., add_underspec, etc.) are only defined here, not on signed integers /// This module provides an abstract type for machine integers of a /// given signedness and width. The interface is designed to be safe /// with respect to arithmetic underflow and overflow. /// Note, we have attempted several times to re-design this module to /// make it more amenable to normalization and to impose less overhead /// on the SMT solver when reasoning about machine integer /// arithmetic. The following github issue reports on the current /// status of that work. /// /// https://github.com/FStarLang/FStar/issues/1757 open FStar.UInt open FStar.Mul #set-options "--max_fuel 0 --max_ifuel 0" (** Abstract type of machine integers, with an underlying representation using a bounded mathematical integer *) new val t : eqtype (** A coercion that projects a bounded mathematical integer from a machine integer *) val v (x:t) : Tot (uint_t n) (** A coercion that injects a bounded mathematical integers into a machine integer *) val uint_to_t (x:uint_t n) : Pure t (requires True) (ensures (fun y -> v y = x)) (** Injection/projection inverse *) val uv_inv (x : t) : Lemma (ensures (uint_to_t (v x) == x)) [SMTPat (v x)] (** Projection/injection inverse *) val vu_inv (x : uint_t n) : Lemma (ensures (v (uint_to_t x) == x)) [SMTPat (uint_to_t x)] (** An alternate form of the injectivity of the [v] projection *) val v_inj (x1 x2: t): Lemma (requires (v x1 == v x2)) (ensures (x1 == x2)) (** Constants 0 and 1 *) val zero : x:t{v x = 0} val one : x:t{v x = 1} (**** Addition primitives *) (** Bounds-respecting addition The precondition enforces that the sum does not overflow, expressing the bound as an addition on mathematical integers *) val add (a:t) (b:t) : Pure t (requires (size (v a + v b) n)) (ensures (fun c -> v a + v b = v c)) (** Underspecified, possibly overflowing addition: The postcondition only enures that the result is the sum of the arguments in case there is no overflow *) val add_underspec (a:t) (b:t) : Pure t (requires True) (ensures (fun c -> size (v a + v b) n ==> v a + v b = v c)) (** Addition modulo [2^n] Machine integers can always be added, but the postcondition is now in terms of addition modulo [2^n] on mathematical integers *) val add_mod (a:t) (b:t) : Pure t (requires True) (ensures (fun c -> FStar.UInt.add_mod (v a) (v b) = v c)) (**** Subtraction primitives *) (** Bounds-respecting subtraction The precondition enforces that the difference does not underflow, expressing the bound as a difference on mathematical integers *) val sub (a:t) (b:t) : Pure t (requires (size (v a - v b) n)) (ensures (fun c -> v a - v b = v c)) (** Underspecified, possibly overflowing subtraction: The postcondition only enures that the result is the difference of the arguments in case there is no underflow *) val sub_underspec (a:t) (b:t) : Pure t (requires True) (ensures (fun c -> size (v a - v b) n ==> v a - v b = v c)) (** Subtraction modulo [2^n] Machine integers can always be subtractd, but the postcondition is now in terms of subtraction modulo [2^n] on mathematical integers *) val sub_mod (a:t) (b:t) : Pure t (requires True) (ensures (fun c -> FStar.UInt.sub_mod (v a) (v b) = v c)) (**** Multiplication primitives *) (** Bounds-respecting multiplication The precondition enforces that the product does not overflow, expressing the bound as a product on mathematical integers *) val mul (a:t) (b:t) : Pure t (requires (size (v a * v b) n)) (ensures (fun c -> v a * v b = v c)) (** Underspecified, possibly overflowing product The postcondition only enures that the result is the product of the arguments in case there is no overflow *) val mul_underspec (a:t) (b:t) : Pure t (requires True) (ensures (fun c -> size (v a * v b) n ==> v a * v b = v c)) (** Multiplication modulo [2^n] Machine integers can always be multiplied, but the postcondition is now in terms of product modulo [2^n] on mathematical integers *) val mul_mod (a:t) (b:t) : Pure t (requires True) (ensures (fun c -> FStar.UInt.mul_mod (v a) (v b) = v c)) (**** Division primitives *) (** Euclidean division of [a] and [b], with [b] non-zero *) val div (a:t) (b:t{v b <> 0}) : Pure t (requires (True)) (ensures (fun c -> v a / v b = v c)) (**** Modulo primitives *) (** Euclidean remainder The result is the modulus of [a] with respect to a non-zero [b] *) val rem (a:t) (b:t{v b <> 0}) : Pure t (requires True) (ensures (fun c -> FStar.UInt.mod (v a) (v b) = v c)) (**** Bitwise operators *) /// Also see FStar.BV (** Bitwise logical conjunction *) val logand (x:t) (y:t) : Pure t (requires True) (ensures (fun z -> v x `logand` v y = v z)) (** Bitwise logical exclusive-or *) val logxor (x:t) (y:t) : Pure t (requires True) (ensures (fun z -> v x `logxor` v y == v z)) (** Bitwise logical disjunction *) val logor (x:t) (y:t) : Pure t (requires True) (ensures (fun z -> v x `logor` v y == v z)) (** Bitwise logical negation *) val lognot (x:t) : Pure t (requires True) (ensures (fun z -> lognot (v x) == v z)) (**** Shift operators *) (** Shift right with zero fill, shifting at most the integer width *) val shift_right (a:t) (s:UInt32.t) : Pure t (requires (UInt32.v s < n)) (ensures (fun c -> FStar.UInt.shift_right (v a) (UInt32.v s) = v c)) (** Shift left with zero fill, shifting at most the integer width *) val shift_left (a:t) (s:UInt32.t) : Pure t (requires (UInt32.v s < n)) (ensures (fun c -> FStar.UInt.shift_left (v a) (UInt32.v s) = v c)) (**** Comparison operators *) (** Equality Note, it is safe to also use the polymorphic decidable equality operator [=] *) let eq (a:t) (b:t) : Tot bool = eq #n (v a) (v b)
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.UInt32.fsti.checked", "FStar.UInt.fsti.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked" ], "interface_file": false, "source_file": "FStar.UInt64.fsti" }
[ { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.UInt", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.UInt", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
a: FStar.UInt64.t -> b: FStar.UInt64.t -> Prims.bool
Prims.Tot
[ "total" ]
[]
[ "FStar.UInt64.t", "FStar.UInt.gt", "FStar.UInt64.n", "FStar.UInt64.v", "Prims.bool" ]
[]
false
false
false
true
false
let gt (a b: t) : Tot bool =
gt #n (v a) (v b)
false
Vale.Math.Poly2_s.fst
Vale.Math.Poly2_s.of_seq
val of_seq (s:seq bool) : Pure poly (requires True) (ensures fun p -> degree p < length s /\ (forall (i:nat).{:pattern (p.[i]) \/ (index s i)} i < length s ==> p.[i] == index s i) )
val of_seq (s:seq bool) : Pure poly (requires True) (ensures fun p -> degree p < length s /\ (forall (i:nat).{:pattern (p.[i]) \/ (index s i)} i < length s ==> p.[i] == index s i) )
let of_seq s = D.of_seq s
{ "file_name": "vale/specs/math/Vale.Math.Poly2_s.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 25, "end_line": 14, "start_col": 0, "start_line": 14 }
module Vale.Math.Poly2_s open FStar.Mul open FStar.Seq let poly = D.poly let degree p = D.degree p let zero = D.zero let one = D.one let monomial n = D.monomial n let shift p n = D.shift p n let reverse p n = D.reverse p n let poly_index p n = D.poly_index p n
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked" ], "interface_file": true, "source_file": "Vale.Math.Poly2_s.fst" }
[ { "abbrev": false, "full_module": "FStar.Seq", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.Seq", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": true, "full_module": "Vale.Math.Poly2.Defs_s", "short_module": "D" }, { "abbrev": false, "full_module": "Vale.Math", "short_module": null }, { "abbrev": false, "full_module": "Vale.Math", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "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
s: FStar.Seq.Base.seq Prims.bool -> Prims.Pure Vale.Math.Poly2_s.poly
Prims.Pure
[]
[]
[ "FStar.Seq.Base.seq", "Prims.bool", "Vale.Math.Poly2.Defs_s.of_seq", "Vale.Math.Poly2_s.poly" ]
[]
false
false
false
false
false
let of_seq s =
D.of_seq s
false
Hacl.Impl.K256.PointDouble.fst
Hacl.Impl.K256.PointDouble.point_double
val point_double (out p:point) : Stack unit (requires fun h -> live h out /\ live h p /\ eq_or_disjoint out p /\ point_inv h p) (ensures fun h0 _ h1 -> modifies (loc out) h0 h1 /\ point_inv h1 out /\ point_eval h1 out == S.point_double (point_eval h0 p))
val point_double (out p:point) : Stack unit (requires fun h -> live h out /\ live h p /\ eq_or_disjoint out p /\ point_inv h p) (ensures fun h0 _ h1 -> modifies (loc out) h0 h1 /\ point_inv h1 out /\ point_eval h1 out == S.point_double (point_eval h0 p))
let point_double out p = push_frame (); let tmp = create (5ul *! nlimb) (u64 0) in point_double_no_alloc out p tmp; pop_frame ()
{ "file_name": "code/k256/Hacl.Impl.K256.PointDouble.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 14, "end_line": 159, "start_col": 0, "start_line": 155 }
module Hacl.Impl.K256.PointDouble open FStar.HyperStack open FStar.HyperStack.ST open FStar.Mul open Lib.IntTypes open Lib.Buffer module ST = FStar.HyperStack.ST module S = Spec.K256 module BL = Hacl.Spec.K256.Field52.Lemmas open Hacl.K256.Field open Hacl.Impl.K256.Point #set-options "--z3rlimit 300 --fuel 0 --ifuel 0" inline_for_extraction noextract val calc_z3 (y1 z1 z3 yy tmp:felem) : Stack unit (requires fun h -> live h y1 /\ live h z1 /\ live h z3 /\ live h yy /\ live h tmp /\ disjoint y1 z1 /\ disjoint y1 z3 /\ disjoint y1 yy /\ disjoint y1 tmp /\ eq_or_disjoint z1 z3 /\ disjoint z1 yy /\ disjoint z1 tmp /\ disjoint z3 yy /\ disjoint z3 tmp /\ disjoint yy tmp /\ inv_lazy_reduced2 h y1 /\ inv_lazy_reduced2 h z1 /\ inv_lazy_reduced2 h yy) (ensures fun h0 _ h1 -> modifies (loc tmp |+| loc z3) h0 h1 /\ feval h1 z3 = S.fmul (S.fmul (S.fmul (feval h0 yy) (feval h0 y1)) (feval h0 z1)) 8 /\ inv_lazy_reduced2 h1 z3) let calc_z3 y1 z1 z3 yy tmp = fmul tmp yy y1; //tmp = yy*y fmul z3 tmp z1; //z3 = tmp*z = yy*y*z let h1 = ST.get () in //assert (inv_lazy_reduced2 h1 x3); //assert (inv_lazy_reduced2 h1 tmp); //assert (inv_lazy_reduced2 h1 z3); fmul_8_normalize_weak z3 z3 //z3 = z3*8=yy*y*z*8 inline_for_extraction noextract val calc_bzz9_tmp (yy zz bzz3 bzz9 tmp:felem) : Stack unit (requires fun h -> live h yy /\ live h zz /\ live h bzz3 /\ live h bzz9 /\ live h tmp /\ disjoint yy zz /\ disjoint yy bzz3 /\ disjoint yy bzz9 /\ disjoint yy tmp /\ disjoint zz bzz3 /\ disjoint zz bzz9 /\ disjoint zz tmp /\ disjoint bzz3 bzz9 /\ disjoint bzz3 tmp /\ disjoint bzz9 tmp /\ inv_lazy_reduced2 h yy /\ inv_lazy_reduced2 h zz) (ensures fun h0 _ h1 -> modifies (loc bzz3 |+| loc bzz9 |+| loc tmp) h0 h1 /\ (let bzz3 = S.fmul (S.fmul 3 S.b) (feval h0 zz) in feval h1 bzz9 = S.fsub (feval h0 yy) (S.fmul 3 bzz3) /\ feval h1 tmp = S.fmul (feval h1 bzz9) (S.fadd (feval h0 yy) bzz3) /\ inv_lazy_reduced2 h1 tmp /\ felem_fits5 (as_felem5 h1 bzz9) (13,13,13,13,14))) let calc_bzz9_tmp yy zz bzz3 bzz9 tmp = fmul_3b_normalize_weak bzz3 zz; //bzz3 = (3*b)*zz let h1 = ST.get () in //assert (inv_lazy_reduced2 h1 bzz3); fmul_small_num bzz9 bzz3 (u64 3); //bzz9 = 3*bzz3 let h2 = ST.get () in BL.fmul15_lemma (1,1,1,1,2) 3 (as_felem5 h1 bzz3) (u64 3); //assert (felem_fits5 (as_felem5 h2 bzz9) (3,3,3,3,6)); BL.fsub5_lemma (1,1,1,1,2) (3,3,3,3,6) (as_felem5 h1 yy) (as_felem5 h2 bzz9) (u64 6); fsub bzz9 yy bzz9 (u64 6); //bzz9 = yy_m_bzz9 = yy-bzz9 let h3 = ST.get () in //assert (felem_fits5 (as_felem5 h3 bzz9) (13,13,13,13,14)); fadd tmp yy bzz3; //tmp = yy_p_bzz3 = yy+bzz3 let h4 = ST.get () in BL.fadd5_lemma (1,1,1,1,2) (1,1,1,1,2) (as_felem5 h1 yy) (as_felem5 h1 bzz3); //assert (felem_fits5 (as_felem5 h4 tmp) (2,2,2,2,4)); fmul tmp bzz9 tmp //tmp = bzz9*tmp = yy_m_bzz9*yy_p_bzz3 inline_for_extraction noextract val calc_y3 (y3 tmp: felem) : Stack unit (requires fun h -> live h y3 /\ live h tmp /\ disjoint y3 tmp /\ inv_lazy_reduced2 h y3 /\ inv_lazy_reduced2 h tmp) (ensures fun h0 _ h1 -> modifies (loc y3) h0 h1 /\ feval h1 y3 = S.fadd (feval h0 tmp) (S.fmul (S.fmul 24 S.b) (feval h0 y3))/\ inv_lazy_reduced2 h1 y3) let calc_y3 y3 tmp = let h0 = ST.get () in fmul_small_num y3 y3 (u64 168); //y3 = t = (24*b)*y3 = (24*b)*yy_zz let h1 = ST.get () in BL.fmul15_lemma (1,1,1,1,2) 168 (as_felem5 h0 y3) (u64 168); //assert (felem_fits5 (as_felem5 h1 y3) (168,168,168,168,336)); fadd y3 tmp y3; //y3 = tmp+y3 = yy_m_bzz9*yy_p_bzz3+t let h2 = ST.get () in BL.fadd5_lemma (1,1,1,1,2) (168,168,168,168,336) (as_felem5 h0 tmp) (as_felem5 h1 y3); //assert (felem_fits5 (as_felem5 h2 y3) (169,169,169,169,338)); fnormalize_weak y3 y3; BL.normalize_weak5_lemma (169,169,169,169,338) (as_felem5 h2 y3) inline_for_extraction noextract val point_double_no_alloc (out p:point) (tmp:lbuffer uint64 (5ul *! nlimb)) : Stack unit (requires fun h -> live h out /\ live h p /\ live h tmp /\ eq_or_disjoint out p /\ disjoint out tmp /\ disjoint p tmp /\ point_inv h p) (ensures fun h0 _ h1 -> modifies (loc out |+| loc tmp) h0 h1 /\ point_inv h1 out /\ point_eval h1 out == S.point_double (point_eval h0 p)) let point_double_no_alloc out p tmp = let x1, y1, z1 = getx p, gety p, getz p in let x3, y3, z3 = getx out, gety out, getz out in let yy = sub tmp 0ul nlimb in let zz = sub tmp nlimb nlimb in let bzz3 = sub tmp (2ul *! nlimb) nlimb in let bzz9 = sub tmp (3ul *! nlimb) nlimb in let tmp = sub tmp (4ul *! nlimb) nlimb in let h0 = ST.get () in fsqr yy y1; //yy = y*y fsqr zz z1; //zz = z*z let h1 = ST.get () in //assert (inv_lazy_reduced2 h1 yy); //assert (inv_lazy_reduced2 h1 zz); fmul_small_num x3 x1 (u64 2); //x3 = 2*x let h2 = ST.get () in BL.fmul15_lemma (1,1,1,1,2) 2 (as_felem5 h1 x1) (u64 2); //assert (felem_fits5 (as_felem5 h2 x3) (2,2,2,2,4)); fmul x3 x3 y1; //x3 = xy2 = x3*y = (2*x)*y calc_z3 y1 z1 z3 yy tmp; calc_bzz9_tmp yy zz bzz3 bzz9 tmp; fmul y3 yy zz; //y3 = yy_zz = yy*zz fmul x3 x3 bzz9; //x3 = x3*bzz9 = xy2*yy_m_bzz9 calc_y3 y3 tmp val point_double (out p:point) : Stack unit (requires fun h -> live h out /\ live h p /\ eq_or_disjoint out p /\ point_inv h p) (ensures fun h0 _ h1 -> modifies (loc out) h0 h1 /\ point_inv h1 out /\ point_eval h1 out == S.point_double (point_eval h0 p))
{ "checked_file": "/", "dependencies": [ "Spec.K256.fst.checked", "prims.fst.checked", "Lib.IntTypes.fsti.checked", "Lib.Buffer.fsti.checked", "Hacl.Spec.K256.Field52.Lemmas.fsti.checked", "Hacl.K256.Field.fsti.checked", "Hacl.Impl.K256.Point.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked" ], "interface_file": false, "source_file": "Hacl.Impl.K256.PointDouble.fst" }
[ { "abbrev": false, "full_module": "Hacl.Impl.K256.Point", "short_module": null }, { "abbrev": false, "full_module": "Hacl.K256.Field", "short_module": null }, { "abbrev": true, "full_module": "Hacl.Spec.K256.Field52.Lemmas", "short_module": "BL" }, { "abbrev": true, "full_module": "Spec.K256", "short_module": "S" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": false, "full_module": "Lib.Buffer", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Impl.K256", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Impl.K256", "short_module": null }, { "abbrev": 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": 300, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
out: Hacl.Impl.K256.Point.point -> p: Hacl.Impl.K256.Point.point -> FStar.HyperStack.ST.Stack Prims.unit
FStar.HyperStack.ST.Stack
[]
[]
[ "Hacl.Impl.K256.Point.point", "FStar.HyperStack.ST.pop_frame", "Prims.unit", "Hacl.Impl.K256.PointDouble.point_double_no_alloc", "Lib.Buffer.lbuffer_t", "Lib.Buffer.MUT", "Lib.IntTypes.int_t", "Lib.IntTypes.U64", "Lib.IntTypes.SEC", "Lib.IntTypes.mul", "Lib.IntTypes.U32", "Lib.IntTypes.PUB", "FStar.UInt32.uint_to_t", "FStar.UInt32.t", "Hacl.K256.Field.nlimb", "Lib.Buffer.create", "Lib.IntTypes.uint64", "Lib.IntTypes.op_Star_Bang", "FStar.UInt32.__uint_to_t", "Lib.IntTypes.u64", "Lib.Buffer.lbuffer", "FStar.HyperStack.ST.push_frame" ]
[]
false
true
false
false
false
let point_double out p =
push_frame (); let tmp = create (5ul *! nlimb) (u64 0) in point_double_no_alloc out p tmp; pop_frame ()
false
Hacl.Impl.K256.PointDouble.fst
Hacl.Impl.K256.PointDouble.calc_y3
val calc_y3 (y3 tmp: felem) : Stack unit (requires fun h -> live h y3 /\ live h tmp /\ disjoint y3 tmp /\ inv_lazy_reduced2 h y3 /\ inv_lazy_reduced2 h tmp) (ensures fun h0 _ h1 -> modifies (loc y3) h0 h1 /\ feval h1 y3 = S.fadd (feval h0 tmp) (S.fmul (S.fmul 24 S.b) (feval h0 y3))/\ inv_lazy_reduced2 h1 y3)
val calc_y3 (y3 tmp: felem) : Stack unit (requires fun h -> live h y3 /\ live h tmp /\ disjoint y3 tmp /\ inv_lazy_reduced2 h y3 /\ inv_lazy_reduced2 h tmp) (ensures fun h0 _ h1 -> modifies (loc y3) h0 h1 /\ feval h1 y3 = S.fadd (feval h0 tmp) (S.fmul (S.fmul 24 S.b) (feval h0 y3))/\ inv_lazy_reduced2 h1 y3)
let calc_y3 y3 tmp = let h0 = ST.get () in fmul_small_num y3 y3 (u64 168); //y3 = t = (24*b)*y3 = (24*b)*yy_zz let h1 = ST.get () in BL.fmul15_lemma (1,1,1,1,2) 168 (as_felem5 h0 y3) (u64 168); //assert (felem_fits5 (as_felem5 h1 y3) (168,168,168,168,336)); fadd y3 tmp y3; //y3 = tmp+y3 = yy_m_bzz9*yy_p_bzz3+t let h2 = ST.get () in BL.fadd5_lemma (1,1,1,1,2) (168,168,168,168,336) (as_felem5 h0 tmp) (as_felem5 h1 y3); //assert (felem_fits5 (as_felem5 h2 y3) (169,169,169,169,338)); fnormalize_weak y3 y3; BL.normalize_weak5_lemma (169,169,169,169,338) (as_felem5 h2 y3)
{ "file_name": "code/k256/Hacl.Impl.K256.PointDouble.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 66, "end_line": 105, "start_col": 0, "start_line": 93 }
module Hacl.Impl.K256.PointDouble open FStar.HyperStack open FStar.HyperStack.ST open FStar.Mul open Lib.IntTypes open Lib.Buffer module ST = FStar.HyperStack.ST module S = Spec.K256 module BL = Hacl.Spec.K256.Field52.Lemmas open Hacl.K256.Field open Hacl.Impl.K256.Point #set-options "--z3rlimit 300 --fuel 0 --ifuel 0" inline_for_extraction noextract val calc_z3 (y1 z1 z3 yy tmp:felem) : Stack unit (requires fun h -> live h y1 /\ live h z1 /\ live h z3 /\ live h yy /\ live h tmp /\ disjoint y1 z1 /\ disjoint y1 z3 /\ disjoint y1 yy /\ disjoint y1 tmp /\ eq_or_disjoint z1 z3 /\ disjoint z1 yy /\ disjoint z1 tmp /\ disjoint z3 yy /\ disjoint z3 tmp /\ disjoint yy tmp /\ inv_lazy_reduced2 h y1 /\ inv_lazy_reduced2 h z1 /\ inv_lazy_reduced2 h yy) (ensures fun h0 _ h1 -> modifies (loc tmp |+| loc z3) h0 h1 /\ feval h1 z3 = S.fmul (S.fmul (S.fmul (feval h0 yy) (feval h0 y1)) (feval h0 z1)) 8 /\ inv_lazy_reduced2 h1 z3) let calc_z3 y1 z1 z3 yy tmp = fmul tmp yy y1; //tmp = yy*y fmul z3 tmp z1; //z3 = tmp*z = yy*y*z let h1 = ST.get () in //assert (inv_lazy_reduced2 h1 x3); //assert (inv_lazy_reduced2 h1 tmp); //assert (inv_lazy_reduced2 h1 z3); fmul_8_normalize_weak z3 z3 //z3 = z3*8=yy*y*z*8 inline_for_extraction noextract val calc_bzz9_tmp (yy zz bzz3 bzz9 tmp:felem) : Stack unit (requires fun h -> live h yy /\ live h zz /\ live h bzz3 /\ live h bzz9 /\ live h tmp /\ disjoint yy zz /\ disjoint yy bzz3 /\ disjoint yy bzz9 /\ disjoint yy tmp /\ disjoint zz bzz3 /\ disjoint zz bzz9 /\ disjoint zz tmp /\ disjoint bzz3 bzz9 /\ disjoint bzz3 tmp /\ disjoint bzz9 tmp /\ inv_lazy_reduced2 h yy /\ inv_lazy_reduced2 h zz) (ensures fun h0 _ h1 -> modifies (loc bzz3 |+| loc bzz9 |+| loc tmp) h0 h1 /\ (let bzz3 = S.fmul (S.fmul 3 S.b) (feval h0 zz) in feval h1 bzz9 = S.fsub (feval h0 yy) (S.fmul 3 bzz3) /\ feval h1 tmp = S.fmul (feval h1 bzz9) (S.fadd (feval h0 yy) bzz3) /\ inv_lazy_reduced2 h1 tmp /\ felem_fits5 (as_felem5 h1 bzz9) (13,13,13,13,14))) let calc_bzz9_tmp yy zz bzz3 bzz9 tmp = fmul_3b_normalize_weak bzz3 zz; //bzz3 = (3*b)*zz let h1 = ST.get () in //assert (inv_lazy_reduced2 h1 bzz3); fmul_small_num bzz9 bzz3 (u64 3); //bzz9 = 3*bzz3 let h2 = ST.get () in BL.fmul15_lemma (1,1,1,1,2) 3 (as_felem5 h1 bzz3) (u64 3); //assert (felem_fits5 (as_felem5 h2 bzz9) (3,3,3,3,6)); BL.fsub5_lemma (1,1,1,1,2) (3,3,3,3,6) (as_felem5 h1 yy) (as_felem5 h2 bzz9) (u64 6); fsub bzz9 yy bzz9 (u64 6); //bzz9 = yy_m_bzz9 = yy-bzz9 let h3 = ST.get () in //assert (felem_fits5 (as_felem5 h3 bzz9) (13,13,13,13,14)); fadd tmp yy bzz3; //tmp = yy_p_bzz3 = yy+bzz3 let h4 = ST.get () in BL.fadd5_lemma (1,1,1,1,2) (1,1,1,1,2) (as_felem5 h1 yy) (as_felem5 h1 bzz3); //assert (felem_fits5 (as_felem5 h4 tmp) (2,2,2,2,4)); fmul tmp bzz9 tmp //tmp = bzz9*tmp = yy_m_bzz9*yy_p_bzz3 inline_for_extraction noextract val calc_y3 (y3 tmp: felem) : Stack unit (requires fun h -> live h y3 /\ live h tmp /\ disjoint y3 tmp /\ inv_lazy_reduced2 h y3 /\ inv_lazy_reduced2 h tmp) (ensures fun h0 _ h1 -> modifies (loc y3) h0 h1 /\ feval h1 y3 = S.fadd (feval h0 tmp) (S.fmul (S.fmul 24 S.b) (feval h0 y3))/\ inv_lazy_reduced2 h1 y3)
{ "checked_file": "/", "dependencies": [ "Spec.K256.fst.checked", "prims.fst.checked", "Lib.IntTypes.fsti.checked", "Lib.Buffer.fsti.checked", "Hacl.Spec.K256.Field52.Lemmas.fsti.checked", "Hacl.K256.Field.fsti.checked", "Hacl.Impl.K256.Point.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked" ], "interface_file": false, "source_file": "Hacl.Impl.K256.PointDouble.fst" }
[ { "abbrev": false, "full_module": "Hacl.Impl.K256.Point", "short_module": null }, { "abbrev": false, "full_module": "Hacl.K256.Field", "short_module": null }, { "abbrev": true, "full_module": "Hacl.Spec.K256.Field52.Lemmas", "short_module": "BL" }, { "abbrev": true, "full_module": "Spec.K256", "short_module": "S" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": false, "full_module": "Lib.Buffer", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Impl.K256", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Impl.K256", "short_module": null }, { "abbrev": 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": 300, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
y3: Hacl.K256.Field.felem -> tmp: Hacl.K256.Field.felem -> FStar.HyperStack.ST.Stack Prims.unit
FStar.HyperStack.ST.Stack
[]
[]
[ "Hacl.K256.Field.felem", "Hacl.Spec.K256.Field52.Lemmas.normalize_weak5_lemma", "FStar.Pervasives.Native.Mktuple5", "Prims.nat", "Hacl.K256.Field.as_felem5", "Prims.unit", "Hacl.K256.Field.fnormalize_weak", "Hacl.Spec.K256.Field52.Lemmas.fadd5_lemma", "FStar.Monotonic.HyperStack.mem", "FStar.HyperStack.ST.get", "Hacl.K256.Field.fadd", "Hacl.Spec.K256.Field52.Lemmas.fmul15_lemma", "Lib.IntTypes.u64", "Hacl.K256.Field.fmul_small_num" ]
[]
false
true
false
false
false
let calc_y3 y3 tmp =
let h0 = ST.get () in fmul_small_num y3 y3 (u64 168); let h1 = ST.get () in BL.fmul15_lemma (1, 1, 1, 1, 2) 168 (as_felem5 h0 y3) (u64 168); fadd y3 tmp y3; let h2 = ST.get () in BL.fadd5_lemma (1, 1, 1, 1, 2) (168, 168, 168, 168, 336) (as_felem5 h0 tmp) (as_felem5 h1 y3); fnormalize_weak y3 y3; BL.normalize_weak5_lemma (169, 169, 169, 169, 338) (as_felem5 h2 y3)
false
FStar.UInt64.fsti
FStar.UInt64.gte
val gte (a b: t) : Tot bool
val gte (a b: t) : Tot bool
let gte (a:t) (b:t) : Tot bool = gte #n (v a) (v b)
{ "file_name": "ulib/FStar.UInt64.fsti", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 51, "end_line": 229, "start_col": 0, "start_line": 229 }
(* 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 FStar.UInt64 (**** THIS MODULE IS GENERATED AUTOMATICALLY USING [mk_int.sh], DO NOT EDIT DIRECTLY ****) unfold let n = 64 /// For FStar.UIntN.fstp: anything that you fix/update here should be /// reflected in [FStar.IntN.fstp], which is mostly a copy-paste of /// this module. /// /// Except, as compared to [FStar.IntN.fstp], here: /// - every occurrence of [int_t] has been replaced with [uint_t] /// - every occurrence of [@%] has been replaced with [%]. /// - some functions (e.g., add_underspec, etc.) are only defined here, not on signed integers /// This module provides an abstract type for machine integers of a /// given signedness and width. The interface is designed to be safe /// with respect to arithmetic underflow and overflow. /// Note, we have attempted several times to re-design this module to /// make it more amenable to normalization and to impose less overhead /// on the SMT solver when reasoning about machine integer /// arithmetic. The following github issue reports on the current /// status of that work. /// /// https://github.com/FStarLang/FStar/issues/1757 open FStar.UInt open FStar.Mul #set-options "--max_fuel 0 --max_ifuel 0" (** Abstract type of machine integers, with an underlying representation using a bounded mathematical integer *) new val t : eqtype (** A coercion that projects a bounded mathematical integer from a machine integer *) val v (x:t) : Tot (uint_t n) (** A coercion that injects a bounded mathematical integers into a machine integer *) val uint_to_t (x:uint_t n) : Pure t (requires True) (ensures (fun y -> v y = x)) (** Injection/projection inverse *) val uv_inv (x : t) : Lemma (ensures (uint_to_t (v x) == x)) [SMTPat (v x)] (** Projection/injection inverse *) val vu_inv (x : uint_t n) : Lemma (ensures (v (uint_to_t x) == x)) [SMTPat (uint_to_t x)] (** An alternate form of the injectivity of the [v] projection *) val v_inj (x1 x2: t): Lemma (requires (v x1 == v x2)) (ensures (x1 == x2)) (** Constants 0 and 1 *) val zero : x:t{v x = 0} val one : x:t{v x = 1} (**** Addition primitives *) (** Bounds-respecting addition The precondition enforces that the sum does not overflow, expressing the bound as an addition on mathematical integers *) val add (a:t) (b:t) : Pure t (requires (size (v a + v b) n)) (ensures (fun c -> v a + v b = v c)) (** Underspecified, possibly overflowing addition: The postcondition only enures that the result is the sum of the arguments in case there is no overflow *) val add_underspec (a:t) (b:t) : Pure t (requires True) (ensures (fun c -> size (v a + v b) n ==> v a + v b = v c)) (** Addition modulo [2^n] Machine integers can always be added, but the postcondition is now in terms of addition modulo [2^n] on mathematical integers *) val add_mod (a:t) (b:t) : Pure t (requires True) (ensures (fun c -> FStar.UInt.add_mod (v a) (v b) = v c)) (**** Subtraction primitives *) (** Bounds-respecting subtraction The precondition enforces that the difference does not underflow, expressing the bound as a difference on mathematical integers *) val sub (a:t) (b:t) : Pure t (requires (size (v a - v b) n)) (ensures (fun c -> v a - v b = v c)) (** Underspecified, possibly overflowing subtraction: The postcondition only enures that the result is the difference of the arguments in case there is no underflow *) val sub_underspec (a:t) (b:t) : Pure t (requires True) (ensures (fun c -> size (v a - v b) n ==> v a - v b = v c)) (** Subtraction modulo [2^n] Machine integers can always be subtractd, but the postcondition is now in terms of subtraction modulo [2^n] on mathematical integers *) val sub_mod (a:t) (b:t) : Pure t (requires True) (ensures (fun c -> FStar.UInt.sub_mod (v a) (v b) = v c)) (**** Multiplication primitives *) (** Bounds-respecting multiplication The precondition enforces that the product does not overflow, expressing the bound as a product on mathematical integers *) val mul (a:t) (b:t) : Pure t (requires (size (v a * v b) n)) (ensures (fun c -> v a * v b = v c)) (** Underspecified, possibly overflowing product The postcondition only enures that the result is the product of the arguments in case there is no overflow *) val mul_underspec (a:t) (b:t) : Pure t (requires True) (ensures (fun c -> size (v a * v b) n ==> v a * v b = v c)) (** Multiplication modulo [2^n] Machine integers can always be multiplied, but the postcondition is now in terms of product modulo [2^n] on mathematical integers *) val mul_mod (a:t) (b:t) : Pure t (requires True) (ensures (fun c -> FStar.UInt.mul_mod (v a) (v b) = v c)) (**** Division primitives *) (** Euclidean division of [a] and [b], with [b] non-zero *) val div (a:t) (b:t{v b <> 0}) : Pure t (requires (True)) (ensures (fun c -> v a / v b = v c)) (**** Modulo primitives *) (** Euclidean remainder The result is the modulus of [a] with respect to a non-zero [b] *) val rem (a:t) (b:t{v b <> 0}) : Pure t (requires True) (ensures (fun c -> FStar.UInt.mod (v a) (v b) = v c)) (**** Bitwise operators *) /// Also see FStar.BV (** Bitwise logical conjunction *) val logand (x:t) (y:t) : Pure t (requires True) (ensures (fun z -> v x `logand` v y = v z)) (** Bitwise logical exclusive-or *) val logxor (x:t) (y:t) : Pure t (requires True) (ensures (fun z -> v x `logxor` v y == v z)) (** Bitwise logical disjunction *) val logor (x:t) (y:t) : Pure t (requires True) (ensures (fun z -> v x `logor` v y == v z)) (** Bitwise logical negation *) val lognot (x:t) : Pure t (requires True) (ensures (fun z -> lognot (v x) == v z)) (**** Shift operators *) (** Shift right with zero fill, shifting at most the integer width *) val shift_right (a:t) (s:UInt32.t) : Pure t (requires (UInt32.v s < n)) (ensures (fun c -> FStar.UInt.shift_right (v a) (UInt32.v s) = v c)) (** Shift left with zero fill, shifting at most the integer width *) val shift_left (a:t) (s:UInt32.t) : Pure t (requires (UInt32.v s < n)) (ensures (fun c -> FStar.UInt.shift_left (v a) (UInt32.v s) = v c)) (**** Comparison operators *) (** Equality Note, it is safe to also use the polymorphic decidable equality operator [=] *) let eq (a:t) (b:t) : Tot bool = eq #n (v a) (v b) (** Greater than *) let gt (a:t) (b:t) : Tot bool = gt #n (v a) (v b)
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.UInt32.fsti.checked", "FStar.UInt.fsti.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked" ], "interface_file": false, "source_file": "FStar.UInt64.fsti" }
[ { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.UInt", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.UInt", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
a: FStar.UInt64.t -> b: FStar.UInt64.t -> Prims.bool
Prims.Tot
[ "total" ]
[]
[ "FStar.UInt64.t", "FStar.UInt.gte", "FStar.UInt64.n", "FStar.UInt64.v", "Prims.bool" ]
[]
false
false
false
true
false
let gte (a b: t) : Tot bool =
gte #n (v a) (v b)
false
Vale.Math.Poly2_s.fst
Vale.Math.Poly2_s.of_fun
val of_fun (len:nat) (f:nat -> bool) : Pure poly (requires True) (ensures fun p -> degree p < len /\ (forall (i:nat).{:pattern p.[i] \/ (f i)} i < len ==> p.[i] == f i) /\ (forall (i:int).{:pattern p.[i]} p.[i] ==> 0 <= i /\ i < len) )
val of_fun (len:nat) (f:nat -> bool) : Pure poly (requires True) (ensures fun p -> degree p < len /\ (forall (i:nat).{:pattern p.[i] \/ (f i)} i < len ==> p.[i] == f i) /\ (forall (i:int).{:pattern p.[i]} p.[i] ==> 0 <= i /\ i < len) )
let of_fun len f = D.of_fun len f
{ "file_name": "vale/specs/math/Vale.Math.Poly2_s.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 33, "end_line": 15, "start_col": 0, "start_line": 15 }
module Vale.Math.Poly2_s open FStar.Mul open FStar.Seq let poly = D.poly let degree p = D.degree p let zero = D.zero let one = D.one let monomial n = D.monomial n let shift p n = D.shift p n let reverse p n = D.reverse p n let poly_index p n = D.poly_index p n let to_seq s n = D.to_seq s n
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked" ], "interface_file": true, "source_file": "Vale.Math.Poly2_s.fst" }
[ { "abbrev": false, "full_module": "FStar.Seq", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.Seq", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": true, "full_module": "Vale.Math.Poly2.Defs_s", "short_module": "D" }, { "abbrev": false, "full_module": "Vale.Math", "short_module": null }, { "abbrev": false, "full_module": "Vale.Math", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "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
len: Prims.nat -> f: (_: Prims.nat -> Prims.bool) -> Prims.Pure Vale.Math.Poly2_s.poly
Prims.Pure
[]
[]
[ "Prims.nat", "Prims.bool", "Vale.Math.Poly2.Defs_s.of_fun", "Vale.Math.Poly2_s.poly" ]
[]
false
false
false
false
false
let of_fun len f =
D.of_fun len f
false
FStar.UInt64.fsti
FStar.UInt64.lt
val lt (a b: t) : Tot bool
val lt (a b: t) : Tot bool
let lt (a:t) (b:t) : Tot bool = lt #n (v a) (v b)
{ "file_name": "ulib/FStar.UInt64.fsti", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 49, "end_line": 232, "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 FStar.UInt64 (**** THIS MODULE IS GENERATED AUTOMATICALLY USING [mk_int.sh], DO NOT EDIT DIRECTLY ****) unfold let n = 64 /// For FStar.UIntN.fstp: anything that you fix/update here should be /// reflected in [FStar.IntN.fstp], which is mostly a copy-paste of /// this module. /// /// Except, as compared to [FStar.IntN.fstp], here: /// - every occurrence of [int_t] has been replaced with [uint_t] /// - every occurrence of [@%] has been replaced with [%]. /// - some functions (e.g., add_underspec, etc.) are only defined here, not on signed integers /// This module provides an abstract type for machine integers of a /// given signedness and width. The interface is designed to be safe /// with respect to arithmetic underflow and overflow. /// Note, we have attempted several times to re-design this module to /// make it more amenable to normalization and to impose less overhead /// on the SMT solver when reasoning about machine integer /// arithmetic. The following github issue reports on the current /// status of that work. /// /// https://github.com/FStarLang/FStar/issues/1757 open FStar.UInt open FStar.Mul #set-options "--max_fuel 0 --max_ifuel 0" (** Abstract type of machine integers, with an underlying representation using a bounded mathematical integer *) new val t : eqtype (** A coercion that projects a bounded mathematical integer from a machine integer *) val v (x:t) : Tot (uint_t n) (** A coercion that injects a bounded mathematical integers into a machine integer *) val uint_to_t (x:uint_t n) : Pure t (requires True) (ensures (fun y -> v y = x)) (** Injection/projection inverse *) val uv_inv (x : t) : Lemma (ensures (uint_to_t (v x) == x)) [SMTPat (v x)] (** Projection/injection inverse *) val vu_inv (x : uint_t n) : Lemma (ensures (v (uint_to_t x) == x)) [SMTPat (uint_to_t x)] (** An alternate form of the injectivity of the [v] projection *) val v_inj (x1 x2: t): Lemma (requires (v x1 == v x2)) (ensures (x1 == x2)) (** Constants 0 and 1 *) val zero : x:t{v x = 0} val one : x:t{v x = 1} (**** Addition primitives *) (** Bounds-respecting addition The precondition enforces that the sum does not overflow, expressing the bound as an addition on mathematical integers *) val add (a:t) (b:t) : Pure t (requires (size (v a + v b) n)) (ensures (fun c -> v a + v b = v c)) (** Underspecified, possibly overflowing addition: The postcondition only enures that the result is the sum of the arguments in case there is no overflow *) val add_underspec (a:t) (b:t) : Pure t (requires True) (ensures (fun c -> size (v a + v b) n ==> v a + v b = v c)) (** Addition modulo [2^n] Machine integers can always be added, but the postcondition is now in terms of addition modulo [2^n] on mathematical integers *) val add_mod (a:t) (b:t) : Pure t (requires True) (ensures (fun c -> FStar.UInt.add_mod (v a) (v b) = v c)) (**** Subtraction primitives *) (** Bounds-respecting subtraction The precondition enforces that the difference does not underflow, expressing the bound as a difference on mathematical integers *) val sub (a:t) (b:t) : Pure t (requires (size (v a - v b) n)) (ensures (fun c -> v a - v b = v c)) (** Underspecified, possibly overflowing subtraction: The postcondition only enures that the result is the difference of the arguments in case there is no underflow *) val sub_underspec (a:t) (b:t) : Pure t (requires True) (ensures (fun c -> size (v a - v b) n ==> v a - v b = v c)) (** Subtraction modulo [2^n] Machine integers can always be subtractd, but the postcondition is now in terms of subtraction modulo [2^n] on mathematical integers *) val sub_mod (a:t) (b:t) : Pure t (requires True) (ensures (fun c -> FStar.UInt.sub_mod (v a) (v b) = v c)) (**** Multiplication primitives *) (** Bounds-respecting multiplication The precondition enforces that the product does not overflow, expressing the bound as a product on mathematical integers *) val mul (a:t) (b:t) : Pure t (requires (size (v a * v b) n)) (ensures (fun c -> v a * v b = v c)) (** Underspecified, possibly overflowing product The postcondition only enures that the result is the product of the arguments in case there is no overflow *) val mul_underspec (a:t) (b:t) : Pure t (requires True) (ensures (fun c -> size (v a * v b) n ==> v a * v b = v c)) (** Multiplication modulo [2^n] Machine integers can always be multiplied, but the postcondition is now in terms of product modulo [2^n] on mathematical integers *) val mul_mod (a:t) (b:t) : Pure t (requires True) (ensures (fun c -> FStar.UInt.mul_mod (v a) (v b) = v c)) (**** Division primitives *) (** Euclidean division of [a] and [b], with [b] non-zero *) val div (a:t) (b:t{v b <> 0}) : Pure t (requires (True)) (ensures (fun c -> v a / v b = v c)) (**** Modulo primitives *) (** Euclidean remainder The result is the modulus of [a] with respect to a non-zero [b] *) val rem (a:t) (b:t{v b <> 0}) : Pure t (requires True) (ensures (fun c -> FStar.UInt.mod (v a) (v b) = v c)) (**** Bitwise operators *) /// Also see FStar.BV (** Bitwise logical conjunction *) val logand (x:t) (y:t) : Pure t (requires True) (ensures (fun z -> v x `logand` v y = v z)) (** Bitwise logical exclusive-or *) val logxor (x:t) (y:t) : Pure t (requires True) (ensures (fun z -> v x `logxor` v y == v z)) (** Bitwise logical disjunction *) val logor (x:t) (y:t) : Pure t (requires True) (ensures (fun z -> v x `logor` v y == v z)) (** Bitwise logical negation *) val lognot (x:t) : Pure t (requires True) (ensures (fun z -> lognot (v x) == v z)) (**** Shift operators *) (** Shift right with zero fill, shifting at most the integer width *) val shift_right (a:t) (s:UInt32.t) : Pure t (requires (UInt32.v s < n)) (ensures (fun c -> FStar.UInt.shift_right (v a) (UInt32.v s) = v c)) (** Shift left with zero fill, shifting at most the integer width *) val shift_left (a:t) (s:UInt32.t) : Pure t (requires (UInt32.v s < n)) (ensures (fun c -> FStar.UInt.shift_left (v a) (UInt32.v s) = v c)) (**** Comparison operators *) (** Equality Note, it is safe to also use the polymorphic decidable equality operator [=] *) let eq (a:t) (b:t) : Tot bool = eq #n (v a) (v b) (** Greater than *) let gt (a:t) (b:t) : Tot bool = gt #n (v a) (v b) (** Greater than or equal *) let gte (a:t) (b:t) : Tot bool = gte #n (v a) (v b)
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.UInt32.fsti.checked", "FStar.UInt.fsti.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked" ], "interface_file": false, "source_file": "FStar.UInt64.fsti" }
[ { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.UInt", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.UInt", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
a: FStar.UInt64.t -> b: FStar.UInt64.t -> Prims.bool
Prims.Tot
[ "total" ]
[]
[ "FStar.UInt64.t", "FStar.UInt.lt", "FStar.UInt64.n", "FStar.UInt64.v", "Prims.bool" ]
[]
false
false
false
true
false
let lt (a b: t) : Tot bool =
lt #n (v a) (v b)
false
MerkleTree.Low.Datastructures.fst
MerkleTree.Low.Datastructures.hash_vec_region_of
val hash_vec_region_of: #hsz:hash_size_t -> v:hash_vec #hsz -> GTot HH.rid
val hash_vec_region_of: #hsz:hash_size_t -> v:hash_vec #hsz -> GTot HH.rid
let hash_vec_region_of #_ v = V.frameOf v
{ "file_name": "src/MerkleTree.Low.Datastructures.fst", "git_rev": "7d7bdc20f2033171e279c176b26e84f9069d23c6", "git_url": "https://github.com/hacl-star/merkle-tree.git", "project_name": "merkle-tree" }
{ "end_col": 41, "end_line": 202, "start_col": 0, "start_line": 202 }
module MerkleTree.Low.Datastructures open FStar.All open FStar.Integers open FStar.Mul open LowStar.Buffer open LowStar.BufferOps open LowStar.Vector open LowStar.Regional open LowStar.RVector open LowStar.Regional.Instances module HS = FStar.HyperStack module HST = FStar.HyperStack.ST module MHS = FStar.Monotonic.HyperStack module HH = FStar.Monotonic.HyperHeap module B = LowStar.Buffer module CB = LowStar.ConstBuffer module V = LowStar.Vector module RV = LowStar.RVector module RVI = LowStar.Regional.Instances module S = FStar.Seq module EHS = EverCrypt.Hash module U32 = FStar.UInt32 module MTH = MerkleTree.New.High open EverCrypt.Helpers open Lib.IntTypes #set-options "--z3rlimit 10 --initial_fuel 0 --max_fuel 0 --initial_ifuel 0 --max_ifuel 0" type hash_size_t = n:uint32_t{n > 0ul} type hash (#hsz:hash_size_t) = b:B.buffer uint8 { B.len b = hsz \/ B.g_is_null b } // We cannot use `Low.RVector.Instances`, where we have some general // typeclass instances of `regional`, e.g., if `rg:regional a` then // `regional (rvector rg)`. In FStar we can use this, but KaRaMeL currently // cannot deal with this and gives a number of errors. // So we temporarily instantiate some `regional`s manually below, which is // extractable to C by KaRaMeL. /// Some instantiations of `regional` used in Merkle tree /// 1. `hash` is regional private noextract val hash_region_of: #hsz:hash_size_t -> v:hash #hsz -> GTot HH.rid let hash_region_of #_ v = B.frameOf v private inline_for_extraction val hash_dummy: #hsz:Ghost.erased hash_size_t -> Tot (hash #hsz) let hash_dummy #_ = B.null private noextract val hash_r_inv: #hsz:hash_size_t -> h:HS.mem -> v:hash #hsz -> GTot Type0 let hash_r_inv #hsz h v = B.live h v /\ B.freeable v /\ B.len v = hsz private noextract val hash_r_inv_reg: #hsz:hash_size_t -> h:HS.mem -> v:hash -> Lemma (requires hash_r_inv h v) (ensures MHS.live_region h (hash_region_of #hsz v)) let hash_r_inv_reg #_ h v = () private noextract val hash_repr (#hsz:hash_size_t): Type0 let hash_repr #hsz = MTH.hash #(U32.v hsz) private noextract val hash_r_repr: #hsz:hash_size_t -> h:HS.mem -> v:hash{hash_r_inv #hsz h v} -> GTot (hash_repr #hsz) let hash_r_repr #_ h v = B.as_seq h v private noextract val hash_r_sep: #hsz:hash_size_t -> v:hash #hsz -> p:loc -> h0:HS.mem -> h1:HS.mem -> Lemma (requires hash_r_inv h0 v /\ loc_disjoint (loc_all_regions_from false (hash_region_of v)) p /\ modifies p h0 h1) (ensures hash_r_inv h1 v /\ hash_r_repr h0 v == hash_r_repr h1 v) let hash_r_sep #_ v p h0 h1 = assert (loc_includes (loc_all_regions_from false (hash_region_of v)) (loc_buffer v)); B.modifies_buffer_elim v p h0 h1 private noextract val hash_irepr: #hsz:hash_size_t -> Ghost.erased (hash_repr #hsz) let hash_irepr #hsz = Ghost.hide (S.create (U32.v hsz) (u8 0)) private noextract val hash_r_alloc_p: #hsz:hash_size_t -> v:hash #hsz -> GTot Type0 let hash_r_alloc_p #_ v = True val hash_r_alloc: #hsz':Ghost.erased hash_size_t -> hsz:hash_size_t { hsz == Ghost.reveal hsz' } -> r:HST.erid -> HST.ST (hash #hsz) (requires (fun h0 -> true)) (ensures (fun h0 v h1 -> Set.subset (Map.domain (MHS.get_hmap h0)) (Map.domain (MHS.get_hmap h1)) /\ modifies loc_none h0 h1 /\ hash_r_alloc_p #hsz v /\ hash_r_inv h1 v /\ hash_region_of v = r /\ hash_r_repr h1 v == Ghost.reveal hash_irepr /\ B.fresh_loc (B.loc_buffer v) h0 h1)) let hash_r_alloc #_ s r = B.malloc r (u8 0) s val hash_r_free: #hsz':Ghost.erased hash_size_t -> hsz:hash_size_t { hsz == Ghost.reveal hsz' } -> v:hash #hsz' -> HST.ST unit (requires fun h0 -> hash_r_inv h0 v) (ensures fun h0 _ h1 -> modifies (loc_all_regions_from false (hash_region_of v)) h0 h1) let hash_r_free #_ _ v = B.free v noextract inline_for_extraction val hreg (hsz:hash_size_t): regional (hash_size_t) (hash #hsz) let hreg hsz = Rgl #(hash_size_t) #(hash #hsz) hsz (hash_region_of #hsz) (B.loc_buffer) (hash_dummy #hsz) (hash_r_inv #hsz) (hash_r_inv_reg #hsz) (hash_repr #hsz) (hash_r_repr #hsz) (hash_r_sep #hsz) (hash_irepr #hsz) (hash_r_alloc_p #hsz) (hash_r_alloc #hsz) (hash_r_free #hsz) private val hash_copy: #s':Ghost.erased hash_size_t -> s:hash_size_t { s == Ghost.reveal s' } -> src:hash #s -> dst:hash #s -> HST.ST unit (requires fun h0 -> hash_r_inv h0 src /\ hash_r_inv h0 dst /\ HH.disjoint (hash_region_of src) (hash_region_of dst)) (ensures fun h0 _ h1 -> modifies (loc_all_regions_from false (hash_region_of dst)) h0 h1 /\ hash_r_inv h1 dst /\ hash_r_repr h1 dst == hash_r_repr h0 src) let hash_copy #_ s src dst = B.blit src 0ul dst 0ul s /// JP: so much stuff happening here. First, single-constructor, single-argument /// elimination takes places and Cpy becomes completely eliminated, in favor of /// just being a type alias for the underlying function. So now, we have a /// function that returns a function pointer. /// /// Next, one might think that the hsz argument is going to be eliminated. It's /// not, because there's a hidden implicit argument to Cpy which is (hreg hsz), /// meaning that hsz is used at run-time even though Cpy is only using this /// argument ghostly. This would be have to be fixed. /// /// Finally, if the inline_for_extraction is removed, there seems to be a /// karamel bug that inserts a void*0. To be fixed. inline_for_extraction val hcpy: hsz:hash_size_t -> copyable #hash_size_t (hash #hsz) (hreg hsz) let hcpy hsz = Cpy (hash_copy #hsz) type hash_vec (#hsz:hash_size_t) = RV.rvector (hreg hsz) /// 2. `rvector hash` is regional type rhst (hsz:hash_size_t) = regional hash_size_t (hash #hsz) private noextract
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "MerkleTree.New.High.fst.checked", "LowStar.Vector.fst.checked", "LowStar.RVector.fst.checked", "LowStar.Regional.Instances.fst.checked", "LowStar.Regional.fst.checked", "LowStar.ConstBuffer.fsti.checked", "LowStar.BufferOps.fst.checked", "LowStar.Buffer.fst.checked", "Lib.IntTypes.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Set.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Monotonic.HyperStack.fsti.checked", "FStar.Monotonic.HyperHeap.fsti.checked", "FStar.Map.fsti.checked", "FStar.Integers.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked", "FStar.All.fst.checked", "EverCrypt.Helpers.fsti.checked", "EverCrypt.Hash.fsti.checked" ], "interface_file": false, "source_file": "MerkleTree.Low.Datastructures.fst" }
[ { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "EverCrypt.Helpers", "short_module": null }, { "abbrev": true, "full_module": "MerkleTree.New.High", "short_module": "MTH" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": true, "full_module": "EverCrypt.Hash", "short_module": "EHS" }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "S" }, { "abbrev": true, "full_module": "LowStar.Regional.Instances", "short_module": "RVI" }, { "abbrev": true, "full_module": "LowStar.RVector", "short_module": "RV" }, { "abbrev": true, "full_module": "LowStar.Vector", "short_module": "V" }, { "abbrev": true, "full_module": "LowStar.ConstBuffer", "short_module": "CB" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.Monotonic.HyperHeap", "short_module": "HH" }, { "abbrev": true, "full_module": "FStar.Monotonic.HyperStack", "short_module": "MHS" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": false, "full_module": "LowStar.Regional.Instances", "short_module": null }, { "abbrev": false, "full_module": "LowStar.RVector", "short_module": null }, { "abbrev": false, "full_module": "LowStar.Regional", "short_module": null }, { "abbrev": false, "full_module": "LowStar.Vector", "short_module": null }, { "abbrev": false, "full_module": "LowStar.BufferOps", "short_module": null }, { "abbrev": false, "full_module": "LowStar.Buffer", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.Integers", "short_module": null }, { "abbrev": false, "full_module": "FStar.All", "short_module": null }, { "abbrev": false, "full_module": "MerkleTree.Low", "short_module": null }, { "abbrev": false, "full_module": "MerkleTree.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": 0, "initial_ifuel": 0, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 10, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
v: MerkleTree.Low.Datastructures.hash_vec -> Prims.GTot FStar.Monotonic.HyperHeap.rid
Prims.GTot
[ "sometrivial" ]
[]
[ "MerkleTree.Low.Datastructures.hash_size_t", "MerkleTree.Low.Datastructures.hash_vec", "LowStar.Vector.frameOf", "MerkleTree.Low.Datastructures.hash", "FStar.Monotonic.HyperHeap.rid" ]
[]
false
false
false
false
false
let hash_vec_region_of #_ v =
V.frameOf v
false
FStar.UInt64.fsti
FStar.UInt64.lte
val lte (a b: t) : Tot bool
val lte (a b: t) : Tot bool
let lte (a:t) (b:t) : Tot bool = lte #n (v a) (v b)
{ "file_name": "ulib/FStar.UInt64.fsti", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 51, "end_line": 235, "start_col": 0, "start_line": 235 }
(* 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 FStar.UInt64 (**** THIS MODULE IS GENERATED AUTOMATICALLY USING [mk_int.sh], DO NOT EDIT DIRECTLY ****) unfold let n = 64 /// For FStar.UIntN.fstp: anything that you fix/update here should be /// reflected in [FStar.IntN.fstp], which is mostly a copy-paste of /// this module. /// /// Except, as compared to [FStar.IntN.fstp], here: /// - every occurrence of [int_t] has been replaced with [uint_t] /// - every occurrence of [@%] has been replaced with [%]. /// - some functions (e.g., add_underspec, etc.) are only defined here, not on signed integers /// This module provides an abstract type for machine integers of a /// given signedness and width. The interface is designed to be safe /// with respect to arithmetic underflow and overflow. /// Note, we have attempted several times to re-design this module to /// make it more amenable to normalization and to impose less overhead /// on the SMT solver when reasoning about machine integer /// arithmetic. The following github issue reports on the current /// status of that work. /// /// https://github.com/FStarLang/FStar/issues/1757 open FStar.UInt open FStar.Mul #set-options "--max_fuel 0 --max_ifuel 0" (** Abstract type of machine integers, with an underlying representation using a bounded mathematical integer *) new val t : eqtype (** A coercion that projects a bounded mathematical integer from a machine integer *) val v (x:t) : Tot (uint_t n) (** A coercion that injects a bounded mathematical integers into a machine integer *) val uint_to_t (x:uint_t n) : Pure t (requires True) (ensures (fun y -> v y = x)) (** Injection/projection inverse *) val uv_inv (x : t) : Lemma (ensures (uint_to_t (v x) == x)) [SMTPat (v x)] (** Projection/injection inverse *) val vu_inv (x : uint_t n) : Lemma (ensures (v (uint_to_t x) == x)) [SMTPat (uint_to_t x)] (** An alternate form of the injectivity of the [v] projection *) val v_inj (x1 x2: t): Lemma (requires (v x1 == v x2)) (ensures (x1 == x2)) (** Constants 0 and 1 *) val zero : x:t{v x = 0} val one : x:t{v x = 1} (**** Addition primitives *) (** Bounds-respecting addition The precondition enforces that the sum does not overflow, expressing the bound as an addition on mathematical integers *) val add (a:t) (b:t) : Pure t (requires (size (v a + v b) n)) (ensures (fun c -> v a + v b = v c)) (** Underspecified, possibly overflowing addition: The postcondition only enures that the result is the sum of the arguments in case there is no overflow *) val add_underspec (a:t) (b:t) : Pure t (requires True) (ensures (fun c -> size (v a + v b) n ==> v a + v b = v c)) (** Addition modulo [2^n] Machine integers can always be added, but the postcondition is now in terms of addition modulo [2^n] on mathematical integers *) val add_mod (a:t) (b:t) : Pure t (requires True) (ensures (fun c -> FStar.UInt.add_mod (v a) (v b) = v c)) (**** Subtraction primitives *) (** Bounds-respecting subtraction The precondition enforces that the difference does not underflow, expressing the bound as a difference on mathematical integers *) val sub (a:t) (b:t) : Pure t (requires (size (v a - v b) n)) (ensures (fun c -> v a - v b = v c)) (** Underspecified, possibly overflowing subtraction: The postcondition only enures that the result is the difference of the arguments in case there is no underflow *) val sub_underspec (a:t) (b:t) : Pure t (requires True) (ensures (fun c -> size (v a - v b) n ==> v a - v b = v c)) (** Subtraction modulo [2^n] Machine integers can always be subtractd, but the postcondition is now in terms of subtraction modulo [2^n] on mathematical integers *) val sub_mod (a:t) (b:t) : Pure t (requires True) (ensures (fun c -> FStar.UInt.sub_mod (v a) (v b) = v c)) (**** Multiplication primitives *) (** Bounds-respecting multiplication The precondition enforces that the product does not overflow, expressing the bound as a product on mathematical integers *) val mul (a:t) (b:t) : Pure t (requires (size (v a * v b) n)) (ensures (fun c -> v a * v b = v c)) (** Underspecified, possibly overflowing product The postcondition only enures that the result is the product of the arguments in case there is no overflow *) val mul_underspec (a:t) (b:t) : Pure t (requires True) (ensures (fun c -> size (v a * v b) n ==> v a * v b = v c)) (** Multiplication modulo [2^n] Machine integers can always be multiplied, but the postcondition is now in terms of product modulo [2^n] on mathematical integers *) val mul_mod (a:t) (b:t) : Pure t (requires True) (ensures (fun c -> FStar.UInt.mul_mod (v a) (v b) = v c)) (**** Division primitives *) (** Euclidean division of [a] and [b], with [b] non-zero *) val div (a:t) (b:t{v b <> 0}) : Pure t (requires (True)) (ensures (fun c -> v a / v b = v c)) (**** Modulo primitives *) (** Euclidean remainder The result is the modulus of [a] with respect to a non-zero [b] *) val rem (a:t) (b:t{v b <> 0}) : Pure t (requires True) (ensures (fun c -> FStar.UInt.mod (v a) (v b) = v c)) (**** Bitwise operators *) /// Also see FStar.BV (** Bitwise logical conjunction *) val logand (x:t) (y:t) : Pure t (requires True) (ensures (fun z -> v x `logand` v y = v z)) (** Bitwise logical exclusive-or *) val logxor (x:t) (y:t) : Pure t (requires True) (ensures (fun z -> v x `logxor` v y == v z)) (** Bitwise logical disjunction *) val logor (x:t) (y:t) : Pure t (requires True) (ensures (fun z -> v x `logor` v y == v z)) (** Bitwise logical negation *) val lognot (x:t) : Pure t (requires True) (ensures (fun z -> lognot (v x) == v z)) (**** Shift operators *) (** Shift right with zero fill, shifting at most the integer width *) val shift_right (a:t) (s:UInt32.t) : Pure t (requires (UInt32.v s < n)) (ensures (fun c -> FStar.UInt.shift_right (v a) (UInt32.v s) = v c)) (** Shift left with zero fill, shifting at most the integer width *) val shift_left (a:t) (s:UInt32.t) : Pure t (requires (UInt32.v s < n)) (ensures (fun c -> FStar.UInt.shift_left (v a) (UInt32.v s) = v c)) (**** Comparison operators *) (** Equality Note, it is safe to also use the polymorphic decidable equality operator [=] *) let eq (a:t) (b:t) : Tot bool = eq #n (v a) (v b) (** Greater than *) let gt (a:t) (b:t) : Tot bool = gt #n (v a) (v b) (** Greater than or equal *) let gte (a:t) (b:t) : Tot bool = gte #n (v a) (v b) (** Less than *) let lt (a:t) (b:t) : Tot bool = lt #n (v a) (v b)
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.UInt32.fsti.checked", "FStar.UInt.fsti.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked" ], "interface_file": false, "source_file": "FStar.UInt64.fsti" }
[ { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.UInt", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.UInt", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
a: FStar.UInt64.t -> b: FStar.UInt64.t -> Prims.bool
Prims.Tot
[ "total" ]
[]
[ "FStar.UInt64.t", "FStar.UInt.lte", "FStar.UInt64.n", "FStar.UInt64.v", "Prims.bool" ]
[]
false
false
false
true
false
let lte (a b: t) : Tot bool =
lte #n (v a) (v b)
false
Vale.Math.Poly2_s.fst
Vale.Math.Poly2_s.to_seq
val to_seq (p:poly) (n:nat) : Pure (seq bool) (requires True) (ensures fun s -> length s == n /\ (forall (i:nat).{:pattern (p.[i]) \/ (index s i)} i < length s ==> p.[i] == index s i) )
val to_seq (p:poly) (n:nat) : Pure (seq bool) (requires True) (ensures fun s -> length s == n /\ (forall (i:nat).{:pattern (p.[i]) \/ (index s i)} i < length s ==> p.[i] == index s i) )
let to_seq s n = D.to_seq s n
{ "file_name": "vale/specs/math/Vale.Math.Poly2_s.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 29, "end_line": 13, "start_col": 0, "start_line": 13 }
module Vale.Math.Poly2_s open FStar.Mul open FStar.Seq let poly = D.poly let degree p = D.degree p let zero = D.zero let one = D.one let monomial n = D.monomial n let shift p n = D.shift p n let reverse p n = D.reverse p n
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked" ], "interface_file": true, "source_file": "Vale.Math.Poly2_s.fst" }
[ { "abbrev": false, "full_module": "FStar.Seq", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.Seq", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": true, "full_module": "Vale.Math.Poly2.Defs_s", "short_module": "D" }, { "abbrev": false, "full_module": "Vale.Math", "short_module": null }, { "abbrev": false, "full_module": "Vale.Math", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "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: Vale.Math.Poly2_s.poly -> n: Prims.nat -> Prims.Pure (FStar.Seq.Base.seq Prims.bool)
Prims.Pure
[]
[]
[ "Vale.Math.Poly2_s.poly", "Prims.nat", "Vale.Math.Poly2.Defs_s.to_seq", "FStar.Seq.Base.seq", "Prims.bool" ]
[]
false
false
false
false
false
let to_seq s n =
D.to_seq s n
false
Vale.Math.Poly2_s.fst
Vale.Math.Poly2_s.div
val div (a b:poly) : poly
val div (a b:poly) : poly
let div a b = if degree b >= 0 then D.div a b else undefined_div_by_zero a
{ "file_name": "vale/specs/math/Vale.Math.Poly2_s.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 74, "end_line": 22, "start_col": 0, "start_line": 22 }
module Vale.Math.Poly2_s open FStar.Mul open FStar.Seq let poly = D.poly let degree p = D.degree p let zero = D.zero let one = D.one let monomial n = D.monomial n let shift p n = D.shift p n let reverse p n = D.reverse p n let poly_index p n = D.poly_index p n let to_seq s n = D.to_seq s n let of_seq s = D.of_seq s let of_fun len f = D.of_fun len f let add a b = D.add a b let mul a b = D.mul a b assume val undefined_div_by_zero (a:poly) : poly assume val undefined_mod_by_zero (a:poly) : poly
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked" ], "interface_file": true, "source_file": "Vale.Math.Poly2_s.fst" }
[ { "abbrev": false, "full_module": "FStar.Seq", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.Seq", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": true, "full_module": "Vale.Math.Poly2.Defs_s", "short_module": "D" }, { "abbrev": false, "full_module": "Vale.Math", "short_module": null }, { "abbrev": false, "full_module": "Vale.Math", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "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
a: Vale.Math.Poly2_s.poly -> b: Vale.Math.Poly2_s.poly -> Vale.Math.Poly2_s.poly
Prims.Tot
[ "total" ]
[]
[ "Vale.Math.Poly2_s.poly", "Prims.op_GreaterThanOrEqual", "Vale.Math.Poly2_s.degree", "Vale.Math.Poly2.Defs_s.div", "Prims.bool", "Vale.Math.Poly2_s.undefined_div_by_zero" ]
[]
false
false
false
true
false
let div a b =
if degree b >= 0 then D.div a b else undefined_div_by_zero a
false
MerkleTree.Low.Datastructures.fst
MerkleTree.Low.Datastructures.hash_vec_dummy
val hash_vec_dummy: (#hsz:Ghost.erased hash_size_t) -> hash_vec #hsz
val hash_vec_dummy: (#hsz:Ghost.erased hash_size_t) -> hash_vec #hsz
let hash_vec_dummy #_ = V.alloc_empty (hash #_)
{ "file_name": "src/MerkleTree.Low.Datastructures.fst", "git_rev": "7d7bdc20f2033171e279c176b26e84f9069d23c6", "git_url": "https://github.com/hacl-star/merkle-tree.git", "project_name": "merkle-tree" }
{ "end_col": 47, "end_line": 206, "start_col": 0, "start_line": 206 }
module MerkleTree.Low.Datastructures open FStar.All open FStar.Integers open FStar.Mul open LowStar.Buffer open LowStar.BufferOps open LowStar.Vector open LowStar.Regional open LowStar.RVector open LowStar.Regional.Instances module HS = FStar.HyperStack module HST = FStar.HyperStack.ST module MHS = FStar.Monotonic.HyperStack module HH = FStar.Monotonic.HyperHeap module B = LowStar.Buffer module CB = LowStar.ConstBuffer module V = LowStar.Vector module RV = LowStar.RVector module RVI = LowStar.Regional.Instances module S = FStar.Seq module EHS = EverCrypt.Hash module U32 = FStar.UInt32 module MTH = MerkleTree.New.High open EverCrypt.Helpers open Lib.IntTypes #set-options "--z3rlimit 10 --initial_fuel 0 --max_fuel 0 --initial_ifuel 0 --max_ifuel 0" type hash_size_t = n:uint32_t{n > 0ul} type hash (#hsz:hash_size_t) = b:B.buffer uint8 { B.len b = hsz \/ B.g_is_null b } // We cannot use `Low.RVector.Instances`, where we have some general // typeclass instances of `regional`, e.g., if `rg:regional a` then // `regional (rvector rg)`. In FStar we can use this, but KaRaMeL currently // cannot deal with this and gives a number of errors. // So we temporarily instantiate some `regional`s manually below, which is // extractable to C by KaRaMeL. /// Some instantiations of `regional` used in Merkle tree /// 1. `hash` is regional private noextract val hash_region_of: #hsz:hash_size_t -> v:hash #hsz -> GTot HH.rid let hash_region_of #_ v = B.frameOf v private inline_for_extraction val hash_dummy: #hsz:Ghost.erased hash_size_t -> Tot (hash #hsz) let hash_dummy #_ = B.null private noextract val hash_r_inv: #hsz:hash_size_t -> h:HS.mem -> v:hash #hsz -> GTot Type0 let hash_r_inv #hsz h v = B.live h v /\ B.freeable v /\ B.len v = hsz private noextract val hash_r_inv_reg: #hsz:hash_size_t -> h:HS.mem -> v:hash -> Lemma (requires hash_r_inv h v) (ensures MHS.live_region h (hash_region_of #hsz v)) let hash_r_inv_reg #_ h v = () private noextract val hash_repr (#hsz:hash_size_t): Type0 let hash_repr #hsz = MTH.hash #(U32.v hsz) private noextract val hash_r_repr: #hsz:hash_size_t -> h:HS.mem -> v:hash{hash_r_inv #hsz h v} -> GTot (hash_repr #hsz) let hash_r_repr #_ h v = B.as_seq h v private noextract val hash_r_sep: #hsz:hash_size_t -> v:hash #hsz -> p:loc -> h0:HS.mem -> h1:HS.mem -> Lemma (requires hash_r_inv h0 v /\ loc_disjoint (loc_all_regions_from false (hash_region_of v)) p /\ modifies p h0 h1) (ensures hash_r_inv h1 v /\ hash_r_repr h0 v == hash_r_repr h1 v) let hash_r_sep #_ v p h0 h1 = assert (loc_includes (loc_all_regions_from false (hash_region_of v)) (loc_buffer v)); B.modifies_buffer_elim v p h0 h1 private noextract val hash_irepr: #hsz:hash_size_t -> Ghost.erased (hash_repr #hsz) let hash_irepr #hsz = Ghost.hide (S.create (U32.v hsz) (u8 0)) private noextract val hash_r_alloc_p: #hsz:hash_size_t -> v:hash #hsz -> GTot Type0 let hash_r_alloc_p #_ v = True val hash_r_alloc: #hsz':Ghost.erased hash_size_t -> hsz:hash_size_t { hsz == Ghost.reveal hsz' } -> r:HST.erid -> HST.ST (hash #hsz) (requires (fun h0 -> true)) (ensures (fun h0 v h1 -> Set.subset (Map.domain (MHS.get_hmap h0)) (Map.domain (MHS.get_hmap h1)) /\ modifies loc_none h0 h1 /\ hash_r_alloc_p #hsz v /\ hash_r_inv h1 v /\ hash_region_of v = r /\ hash_r_repr h1 v == Ghost.reveal hash_irepr /\ B.fresh_loc (B.loc_buffer v) h0 h1)) let hash_r_alloc #_ s r = B.malloc r (u8 0) s val hash_r_free: #hsz':Ghost.erased hash_size_t -> hsz:hash_size_t { hsz == Ghost.reveal hsz' } -> v:hash #hsz' -> HST.ST unit (requires fun h0 -> hash_r_inv h0 v) (ensures fun h0 _ h1 -> modifies (loc_all_regions_from false (hash_region_of v)) h0 h1) let hash_r_free #_ _ v = B.free v noextract inline_for_extraction val hreg (hsz:hash_size_t): regional (hash_size_t) (hash #hsz) let hreg hsz = Rgl #(hash_size_t) #(hash #hsz) hsz (hash_region_of #hsz) (B.loc_buffer) (hash_dummy #hsz) (hash_r_inv #hsz) (hash_r_inv_reg #hsz) (hash_repr #hsz) (hash_r_repr #hsz) (hash_r_sep #hsz) (hash_irepr #hsz) (hash_r_alloc_p #hsz) (hash_r_alloc #hsz) (hash_r_free #hsz) private val hash_copy: #s':Ghost.erased hash_size_t -> s:hash_size_t { s == Ghost.reveal s' } -> src:hash #s -> dst:hash #s -> HST.ST unit (requires fun h0 -> hash_r_inv h0 src /\ hash_r_inv h0 dst /\ HH.disjoint (hash_region_of src) (hash_region_of dst)) (ensures fun h0 _ h1 -> modifies (loc_all_regions_from false (hash_region_of dst)) h0 h1 /\ hash_r_inv h1 dst /\ hash_r_repr h1 dst == hash_r_repr h0 src) let hash_copy #_ s src dst = B.blit src 0ul dst 0ul s /// JP: so much stuff happening here. First, single-constructor, single-argument /// elimination takes places and Cpy becomes completely eliminated, in favor of /// just being a type alias for the underlying function. So now, we have a /// function that returns a function pointer. /// /// Next, one might think that the hsz argument is going to be eliminated. It's /// not, because there's a hidden implicit argument to Cpy which is (hreg hsz), /// meaning that hsz is used at run-time even though Cpy is only using this /// argument ghostly. This would be have to be fixed. /// /// Finally, if the inline_for_extraction is removed, there seems to be a /// karamel bug that inserts a void*0. To be fixed. inline_for_extraction val hcpy: hsz:hash_size_t -> copyable #hash_size_t (hash #hsz) (hreg hsz) let hcpy hsz = Cpy (hash_copy #hsz) type hash_vec (#hsz:hash_size_t) = RV.rvector (hreg hsz) /// 2. `rvector hash` is regional type rhst (hsz:hash_size_t) = regional hash_size_t (hash #hsz) private noextract val hash_vec_region_of: #hsz:hash_size_t -> v:hash_vec #hsz -> GTot HH.rid let hash_vec_region_of #_ v = V.frameOf v private inline_for_extraction
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "MerkleTree.New.High.fst.checked", "LowStar.Vector.fst.checked", "LowStar.RVector.fst.checked", "LowStar.Regional.Instances.fst.checked", "LowStar.Regional.fst.checked", "LowStar.ConstBuffer.fsti.checked", "LowStar.BufferOps.fst.checked", "LowStar.Buffer.fst.checked", "Lib.IntTypes.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Set.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Monotonic.HyperStack.fsti.checked", "FStar.Monotonic.HyperHeap.fsti.checked", "FStar.Map.fsti.checked", "FStar.Integers.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked", "FStar.All.fst.checked", "EverCrypt.Helpers.fsti.checked", "EverCrypt.Hash.fsti.checked" ], "interface_file": false, "source_file": "MerkleTree.Low.Datastructures.fst" }
[ { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "EverCrypt.Helpers", "short_module": null }, { "abbrev": true, "full_module": "MerkleTree.New.High", "short_module": "MTH" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": true, "full_module": "EverCrypt.Hash", "short_module": "EHS" }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "S" }, { "abbrev": true, "full_module": "LowStar.Regional.Instances", "short_module": "RVI" }, { "abbrev": true, "full_module": "LowStar.RVector", "short_module": "RV" }, { "abbrev": true, "full_module": "LowStar.Vector", "short_module": "V" }, { "abbrev": true, "full_module": "LowStar.ConstBuffer", "short_module": "CB" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.Monotonic.HyperHeap", "short_module": "HH" }, { "abbrev": true, "full_module": "FStar.Monotonic.HyperStack", "short_module": "MHS" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": false, "full_module": "LowStar.Regional.Instances", "short_module": null }, { "abbrev": false, "full_module": "LowStar.RVector", "short_module": null }, { "abbrev": false, "full_module": "LowStar.Regional", "short_module": null }, { "abbrev": false, "full_module": "LowStar.Vector", "short_module": null }, { "abbrev": false, "full_module": "LowStar.BufferOps", "short_module": null }, { "abbrev": false, "full_module": "LowStar.Buffer", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.Integers", "short_module": null }, { "abbrev": false, "full_module": "FStar.All", "short_module": null }, { "abbrev": false, "full_module": "MerkleTree.Low", "short_module": null }, { "abbrev": false, "full_module": "MerkleTree.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": 0, "initial_ifuel": 0, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 10, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
MerkleTree.Low.Datastructures.hash_vec
Prims.Tot
[ "total" ]
[]
[ "FStar.Ghost.erased", "MerkleTree.Low.Datastructures.hash_size_t", "LowStar.Vector.alloc_empty", "MerkleTree.Low.Datastructures.hash", "FStar.Ghost.reveal", "MerkleTree.Low.Datastructures.hash_vec" ]
[]
false
false
false
false
false
let hash_vec_dummy #_ =
V.alloc_empty (hash #_)
false
MerkleTree.Low.Datastructures.fst
MerkleTree.Low.Datastructures.hash_vec_r_inv
val hash_vec_r_inv: #hsz:hash_size_t -> h:HS.mem -> v:hash_vec #hsz -> GTot Type0
val hash_vec_r_inv: #hsz:hash_size_t -> h:HS.mem -> v:hash_vec #hsz -> GTot Type0
let hash_vec_r_inv #hsz h v = RV.rv_inv h v
{ "file_name": "src/MerkleTree.Low.Datastructures.fst", "git_rev": "7d7bdc20f2033171e279c176b26e84f9069d23c6", "git_url": "https://github.com/hacl-star/merkle-tree.git", "project_name": "merkle-tree" }
{ "end_col": 43, "end_line": 210, "start_col": 0, "start_line": 210 }
module MerkleTree.Low.Datastructures open FStar.All open FStar.Integers open FStar.Mul open LowStar.Buffer open LowStar.BufferOps open LowStar.Vector open LowStar.Regional open LowStar.RVector open LowStar.Regional.Instances module HS = FStar.HyperStack module HST = FStar.HyperStack.ST module MHS = FStar.Monotonic.HyperStack module HH = FStar.Monotonic.HyperHeap module B = LowStar.Buffer module CB = LowStar.ConstBuffer module V = LowStar.Vector module RV = LowStar.RVector module RVI = LowStar.Regional.Instances module S = FStar.Seq module EHS = EverCrypt.Hash module U32 = FStar.UInt32 module MTH = MerkleTree.New.High open EverCrypt.Helpers open Lib.IntTypes #set-options "--z3rlimit 10 --initial_fuel 0 --max_fuel 0 --initial_ifuel 0 --max_ifuel 0" type hash_size_t = n:uint32_t{n > 0ul} type hash (#hsz:hash_size_t) = b:B.buffer uint8 { B.len b = hsz \/ B.g_is_null b } // We cannot use `Low.RVector.Instances`, where we have some general // typeclass instances of `regional`, e.g., if `rg:regional a` then // `regional (rvector rg)`. In FStar we can use this, but KaRaMeL currently // cannot deal with this and gives a number of errors. // So we temporarily instantiate some `regional`s manually below, which is // extractable to C by KaRaMeL. /// Some instantiations of `regional` used in Merkle tree /// 1. `hash` is regional private noextract val hash_region_of: #hsz:hash_size_t -> v:hash #hsz -> GTot HH.rid let hash_region_of #_ v = B.frameOf v private inline_for_extraction val hash_dummy: #hsz:Ghost.erased hash_size_t -> Tot (hash #hsz) let hash_dummy #_ = B.null private noextract val hash_r_inv: #hsz:hash_size_t -> h:HS.mem -> v:hash #hsz -> GTot Type0 let hash_r_inv #hsz h v = B.live h v /\ B.freeable v /\ B.len v = hsz private noextract val hash_r_inv_reg: #hsz:hash_size_t -> h:HS.mem -> v:hash -> Lemma (requires hash_r_inv h v) (ensures MHS.live_region h (hash_region_of #hsz v)) let hash_r_inv_reg #_ h v = () private noextract val hash_repr (#hsz:hash_size_t): Type0 let hash_repr #hsz = MTH.hash #(U32.v hsz) private noextract val hash_r_repr: #hsz:hash_size_t -> h:HS.mem -> v:hash{hash_r_inv #hsz h v} -> GTot (hash_repr #hsz) let hash_r_repr #_ h v = B.as_seq h v private noextract val hash_r_sep: #hsz:hash_size_t -> v:hash #hsz -> p:loc -> h0:HS.mem -> h1:HS.mem -> Lemma (requires hash_r_inv h0 v /\ loc_disjoint (loc_all_regions_from false (hash_region_of v)) p /\ modifies p h0 h1) (ensures hash_r_inv h1 v /\ hash_r_repr h0 v == hash_r_repr h1 v) let hash_r_sep #_ v p h0 h1 = assert (loc_includes (loc_all_regions_from false (hash_region_of v)) (loc_buffer v)); B.modifies_buffer_elim v p h0 h1 private noextract val hash_irepr: #hsz:hash_size_t -> Ghost.erased (hash_repr #hsz) let hash_irepr #hsz = Ghost.hide (S.create (U32.v hsz) (u8 0)) private noextract val hash_r_alloc_p: #hsz:hash_size_t -> v:hash #hsz -> GTot Type0 let hash_r_alloc_p #_ v = True val hash_r_alloc: #hsz':Ghost.erased hash_size_t -> hsz:hash_size_t { hsz == Ghost.reveal hsz' } -> r:HST.erid -> HST.ST (hash #hsz) (requires (fun h0 -> true)) (ensures (fun h0 v h1 -> Set.subset (Map.domain (MHS.get_hmap h0)) (Map.domain (MHS.get_hmap h1)) /\ modifies loc_none h0 h1 /\ hash_r_alloc_p #hsz v /\ hash_r_inv h1 v /\ hash_region_of v = r /\ hash_r_repr h1 v == Ghost.reveal hash_irepr /\ B.fresh_loc (B.loc_buffer v) h0 h1)) let hash_r_alloc #_ s r = B.malloc r (u8 0) s val hash_r_free: #hsz':Ghost.erased hash_size_t -> hsz:hash_size_t { hsz == Ghost.reveal hsz' } -> v:hash #hsz' -> HST.ST unit (requires fun h0 -> hash_r_inv h0 v) (ensures fun h0 _ h1 -> modifies (loc_all_regions_from false (hash_region_of v)) h0 h1) let hash_r_free #_ _ v = B.free v noextract inline_for_extraction val hreg (hsz:hash_size_t): regional (hash_size_t) (hash #hsz) let hreg hsz = Rgl #(hash_size_t) #(hash #hsz) hsz (hash_region_of #hsz) (B.loc_buffer) (hash_dummy #hsz) (hash_r_inv #hsz) (hash_r_inv_reg #hsz) (hash_repr #hsz) (hash_r_repr #hsz) (hash_r_sep #hsz) (hash_irepr #hsz) (hash_r_alloc_p #hsz) (hash_r_alloc #hsz) (hash_r_free #hsz) private val hash_copy: #s':Ghost.erased hash_size_t -> s:hash_size_t { s == Ghost.reveal s' } -> src:hash #s -> dst:hash #s -> HST.ST unit (requires fun h0 -> hash_r_inv h0 src /\ hash_r_inv h0 dst /\ HH.disjoint (hash_region_of src) (hash_region_of dst)) (ensures fun h0 _ h1 -> modifies (loc_all_regions_from false (hash_region_of dst)) h0 h1 /\ hash_r_inv h1 dst /\ hash_r_repr h1 dst == hash_r_repr h0 src) let hash_copy #_ s src dst = B.blit src 0ul dst 0ul s /// JP: so much stuff happening here. First, single-constructor, single-argument /// elimination takes places and Cpy becomes completely eliminated, in favor of /// just being a type alias for the underlying function. So now, we have a /// function that returns a function pointer. /// /// Next, one might think that the hsz argument is going to be eliminated. It's /// not, because there's a hidden implicit argument to Cpy which is (hreg hsz), /// meaning that hsz is used at run-time even though Cpy is only using this /// argument ghostly. This would be have to be fixed. /// /// Finally, if the inline_for_extraction is removed, there seems to be a /// karamel bug that inserts a void*0. To be fixed. inline_for_extraction val hcpy: hsz:hash_size_t -> copyable #hash_size_t (hash #hsz) (hreg hsz) let hcpy hsz = Cpy (hash_copy #hsz) type hash_vec (#hsz:hash_size_t) = RV.rvector (hreg hsz) /// 2. `rvector hash` is regional type rhst (hsz:hash_size_t) = regional hash_size_t (hash #hsz) private noextract val hash_vec_region_of: #hsz:hash_size_t -> v:hash_vec #hsz -> GTot HH.rid let hash_vec_region_of #_ v = V.frameOf v private inline_for_extraction val hash_vec_dummy: (#hsz:Ghost.erased hash_size_t) -> hash_vec #hsz let hash_vec_dummy #_ = V.alloc_empty (hash #_) noextract
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "MerkleTree.New.High.fst.checked", "LowStar.Vector.fst.checked", "LowStar.RVector.fst.checked", "LowStar.Regional.Instances.fst.checked", "LowStar.Regional.fst.checked", "LowStar.ConstBuffer.fsti.checked", "LowStar.BufferOps.fst.checked", "LowStar.Buffer.fst.checked", "Lib.IntTypes.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Set.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Monotonic.HyperStack.fsti.checked", "FStar.Monotonic.HyperHeap.fsti.checked", "FStar.Map.fsti.checked", "FStar.Integers.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked", "FStar.All.fst.checked", "EverCrypt.Helpers.fsti.checked", "EverCrypt.Hash.fsti.checked" ], "interface_file": false, "source_file": "MerkleTree.Low.Datastructures.fst" }
[ { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "EverCrypt.Helpers", "short_module": null }, { "abbrev": true, "full_module": "MerkleTree.New.High", "short_module": "MTH" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": true, "full_module": "EverCrypt.Hash", "short_module": "EHS" }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "S" }, { "abbrev": true, "full_module": "LowStar.Regional.Instances", "short_module": "RVI" }, { "abbrev": true, "full_module": "LowStar.RVector", "short_module": "RV" }, { "abbrev": true, "full_module": "LowStar.Vector", "short_module": "V" }, { "abbrev": true, "full_module": "LowStar.ConstBuffer", "short_module": "CB" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.Monotonic.HyperHeap", "short_module": "HH" }, { "abbrev": true, "full_module": "FStar.Monotonic.HyperStack", "short_module": "MHS" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": false, "full_module": "LowStar.Regional.Instances", "short_module": null }, { "abbrev": false, "full_module": "LowStar.RVector", "short_module": null }, { "abbrev": false, "full_module": "LowStar.Regional", "short_module": null }, { "abbrev": false, "full_module": "LowStar.Vector", "short_module": null }, { "abbrev": false, "full_module": "LowStar.BufferOps", "short_module": null }, { "abbrev": false, "full_module": "LowStar.Buffer", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.Integers", "short_module": null }, { "abbrev": false, "full_module": "FStar.All", "short_module": null }, { "abbrev": false, "full_module": "MerkleTree.Low", "short_module": null }, { "abbrev": false, "full_module": "MerkleTree.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": 0, "initial_ifuel": 0, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 10, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
h: FStar.Monotonic.HyperStack.mem -> v: MerkleTree.Low.Datastructures.hash_vec -> Prims.GTot Type0
Prims.GTot
[ "sometrivial" ]
[]
[ "MerkleTree.Low.Datastructures.hash_size_t", "FStar.Monotonic.HyperStack.mem", "MerkleTree.Low.Datastructures.hash_vec", "LowStar.RVector.rv_inv", "MerkleTree.Low.Datastructures.hash", "MerkleTree.Low.Datastructures.hreg" ]
[]
false
false
false
false
true
let hash_vec_r_inv #hsz h v =
RV.rv_inv h v
false
Vale.Math.Poly2_s.fst
Vale.Math.Poly2_s.mod
val mod (a b:poly) : poly
val mod (a b:poly) : poly
let mod a b = if degree b >= 0 then D.mod a b else undefined_mod_by_zero a
{ "file_name": "vale/specs/math/Vale.Math.Poly2_s.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 74, "end_line": 23, "start_col": 0, "start_line": 23 }
module Vale.Math.Poly2_s open FStar.Mul open FStar.Seq let poly = D.poly let degree p = D.degree p let zero = D.zero let one = D.one let monomial n = D.monomial n let shift p n = D.shift p n let reverse p n = D.reverse p n let poly_index p n = D.poly_index p n let to_seq s n = D.to_seq s n let of_seq s = D.of_seq s let of_fun len f = D.of_fun len f let add a b = D.add a b let mul a b = D.mul a b assume val undefined_div_by_zero (a:poly) : poly assume val undefined_mod_by_zero (a:poly) : poly
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked" ], "interface_file": true, "source_file": "Vale.Math.Poly2_s.fst" }
[ { "abbrev": false, "full_module": "FStar.Seq", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.Seq", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": true, "full_module": "Vale.Math.Poly2.Defs_s", "short_module": "D" }, { "abbrev": false, "full_module": "Vale.Math", "short_module": null }, { "abbrev": false, "full_module": "Vale.Math", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "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
a: Vale.Math.Poly2_s.poly -> b: Vale.Math.Poly2_s.poly -> Vale.Math.Poly2_s.poly
Prims.Tot
[ "total" ]
[]
[ "Vale.Math.Poly2_s.poly", "Prims.op_GreaterThanOrEqual", "Vale.Math.Poly2_s.degree", "Vale.Math.Poly2.Defs_s.mod", "Prims.bool", "Vale.Math.Poly2_s.undefined_mod_by_zero" ]
[]
false
false
false
true
false
let mod a b =
if degree b >= 0 then D.mod a b else undefined_mod_by_zero a
false
FStar.UInt64.fsti
FStar.UInt64.op_Subtraction_Percent_Hat
val op_Subtraction_Percent_Hat : a: FStar.UInt64.t -> b: FStar.UInt64.t -> Prims.Pure FStar.UInt64.t
let op_Subtraction_Percent_Hat = sub_mod
{ "file_name": "ulib/FStar.UInt64.fsti", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 47, "end_line": 321, "start_col": 7, "start_line": 321 }
(* 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 FStar.UInt64 (**** THIS MODULE IS GENERATED AUTOMATICALLY USING [mk_int.sh], DO NOT EDIT DIRECTLY ****) unfold let n = 64 /// For FStar.UIntN.fstp: anything that you fix/update here should be /// reflected in [FStar.IntN.fstp], which is mostly a copy-paste of /// this module. /// /// Except, as compared to [FStar.IntN.fstp], here: /// - every occurrence of [int_t] has been replaced with [uint_t] /// - every occurrence of [@%] has been replaced with [%]. /// - some functions (e.g., add_underspec, etc.) are only defined here, not on signed integers /// This module provides an abstract type for machine integers of a /// given signedness and width. The interface is designed to be safe /// with respect to arithmetic underflow and overflow. /// Note, we have attempted several times to re-design this module to /// make it more amenable to normalization and to impose less overhead /// on the SMT solver when reasoning about machine integer /// arithmetic. The following github issue reports on the current /// status of that work. /// /// https://github.com/FStarLang/FStar/issues/1757 open FStar.UInt open FStar.Mul #set-options "--max_fuel 0 --max_ifuel 0" (** Abstract type of machine integers, with an underlying representation using a bounded mathematical integer *) new val t : eqtype (** A coercion that projects a bounded mathematical integer from a machine integer *) val v (x:t) : Tot (uint_t n) (** A coercion that injects a bounded mathematical integers into a machine integer *) val uint_to_t (x:uint_t n) : Pure t (requires True) (ensures (fun y -> v y = x)) (** Injection/projection inverse *) val uv_inv (x : t) : Lemma (ensures (uint_to_t (v x) == x)) [SMTPat (v x)] (** Projection/injection inverse *) val vu_inv (x : uint_t n) : Lemma (ensures (v (uint_to_t x) == x)) [SMTPat (uint_to_t x)] (** An alternate form of the injectivity of the [v] projection *) val v_inj (x1 x2: t): Lemma (requires (v x1 == v x2)) (ensures (x1 == x2)) (** Constants 0 and 1 *) val zero : x:t{v x = 0} val one : x:t{v x = 1} (**** Addition primitives *) (** Bounds-respecting addition The precondition enforces that the sum does not overflow, expressing the bound as an addition on mathematical integers *) val add (a:t) (b:t) : Pure t (requires (size (v a + v b) n)) (ensures (fun c -> v a + v b = v c)) (** Underspecified, possibly overflowing addition: The postcondition only enures that the result is the sum of the arguments in case there is no overflow *) val add_underspec (a:t) (b:t) : Pure t (requires True) (ensures (fun c -> size (v a + v b) n ==> v a + v b = v c)) (** Addition modulo [2^n] Machine integers can always be added, but the postcondition is now in terms of addition modulo [2^n] on mathematical integers *) val add_mod (a:t) (b:t) : Pure t (requires True) (ensures (fun c -> FStar.UInt.add_mod (v a) (v b) = v c)) (**** Subtraction primitives *) (** Bounds-respecting subtraction The precondition enforces that the difference does not underflow, expressing the bound as a difference on mathematical integers *) val sub (a:t) (b:t) : Pure t (requires (size (v a - v b) n)) (ensures (fun c -> v a - v b = v c)) (** Underspecified, possibly overflowing subtraction: The postcondition only enures that the result is the difference of the arguments in case there is no underflow *) val sub_underspec (a:t) (b:t) : Pure t (requires True) (ensures (fun c -> size (v a - v b) n ==> v a - v b = v c)) (** Subtraction modulo [2^n] Machine integers can always be subtractd, but the postcondition is now in terms of subtraction modulo [2^n] on mathematical integers *) val sub_mod (a:t) (b:t) : Pure t (requires True) (ensures (fun c -> FStar.UInt.sub_mod (v a) (v b) = v c)) (**** Multiplication primitives *) (** Bounds-respecting multiplication The precondition enforces that the product does not overflow, expressing the bound as a product on mathematical integers *) val mul (a:t) (b:t) : Pure t (requires (size (v a * v b) n)) (ensures (fun c -> v a * v b = v c)) (** Underspecified, possibly overflowing product The postcondition only enures that the result is the product of the arguments in case there is no overflow *) val mul_underspec (a:t) (b:t) : Pure t (requires True) (ensures (fun c -> size (v a * v b) n ==> v a * v b = v c)) (** Multiplication modulo [2^n] Machine integers can always be multiplied, but the postcondition is now in terms of product modulo [2^n] on mathematical integers *) val mul_mod (a:t) (b:t) : Pure t (requires True) (ensures (fun c -> FStar.UInt.mul_mod (v a) (v b) = v c)) (**** Division primitives *) (** Euclidean division of [a] and [b], with [b] non-zero *) val div (a:t) (b:t{v b <> 0}) : Pure t (requires (True)) (ensures (fun c -> v a / v b = v c)) (**** Modulo primitives *) (** Euclidean remainder The result is the modulus of [a] with respect to a non-zero [b] *) val rem (a:t) (b:t{v b <> 0}) : Pure t (requires True) (ensures (fun c -> FStar.UInt.mod (v a) (v b) = v c)) (**** Bitwise operators *) /// Also see FStar.BV (** Bitwise logical conjunction *) val logand (x:t) (y:t) : Pure t (requires True) (ensures (fun z -> v x `logand` v y = v z)) (** Bitwise logical exclusive-or *) val logxor (x:t) (y:t) : Pure t (requires True) (ensures (fun z -> v x `logxor` v y == v z)) (** Bitwise logical disjunction *) val logor (x:t) (y:t) : Pure t (requires True) (ensures (fun z -> v x `logor` v y == v z)) (** Bitwise logical negation *) val lognot (x:t) : Pure t (requires True) (ensures (fun z -> lognot (v x) == v z)) (**** Shift operators *) (** Shift right with zero fill, shifting at most the integer width *) val shift_right (a:t) (s:UInt32.t) : Pure t (requires (UInt32.v s < n)) (ensures (fun c -> FStar.UInt.shift_right (v a) (UInt32.v s) = v c)) (** Shift left with zero fill, shifting at most the integer width *) val shift_left (a:t) (s:UInt32.t) : Pure t (requires (UInt32.v s < n)) (ensures (fun c -> FStar.UInt.shift_left (v a) (UInt32.v s) = v c)) (**** Comparison operators *) (** Equality Note, it is safe to also use the polymorphic decidable equality operator [=] *) let eq (a:t) (b:t) : Tot bool = eq #n (v a) (v b) (** Greater than *) let gt (a:t) (b:t) : Tot bool = gt #n (v a) (v b) (** Greater than or equal *) let gte (a:t) (b:t) : Tot bool = gte #n (v a) (v b) (** Less than *) let lt (a:t) (b:t) : Tot bool = lt #n (v a) (v b) (** Less than or equal *) let lte (a:t) (b:t) : Tot bool = lte #n (v a) (v b) (** Unary negation *) inline_for_extraction let minus (a:t) = add_mod (lognot a) (uint_to_t 1) (** The maximum shift value for this type, i.e. its width minus one, as an UInt32. *) inline_for_extraction let n_minus_one = UInt32.uint_to_t (n - 1) #set-options "--z3rlimit 80 --initial_fuel 1 --max_fuel 1" (** A constant-time way to compute the equality of two machine integers. With inspiration from https://git.zx2c4.com/WireGuard/commit/src/crypto/curve25519-hacl64.h?id=2e60bb395c1f589a398ec606d611132ef9ef764b Note, the branching on [a=b] is just for proof-purposes. *) [@ CNoInline ] let eq_mask (a:t) (b:t) : Pure t (requires True) (ensures (fun c -> (v a = v b ==> v c = pow2 n - 1) /\ (v a <> v b ==> v c = 0))) = let x = logxor a b in let minus_x = minus x in let x_or_minus_x = logor x minus_x in let xnx = shift_right x_or_minus_x n_minus_one in let c = sub_mod xnx (uint_to_t 1) in if a = b then begin logxor_self (v a); lognot_lemma_1 #n; logor_lemma_1 (v x); assert (v x = 0 /\ v minus_x = 0 /\ v x_or_minus_x = 0 /\ v xnx = 0); assert (v c = ones n) end else begin logxor_neq_nonzero (v a) (v b); lemma_msb_pow2 #n (v (lognot x)); lemma_msb_pow2 #n (v minus_x); lemma_minus_zero #n (v x); assert (v c = FStar.UInt.zero n) end; c private val lemma_sub_msbs (a:t) (b:t) : Lemma ((msb (v a) = msb (v b)) ==> (v a < v b <==> msb (v (sub_mod a b)))) (** A constant-time way to compute the [>=] inequality of two machine integers. With inspiration from https://git.zx2c4.com/WireGuard/commit/src/crypto/curve25519-hacl64.h?id=0a483a9b431d87eca1b275463c632f8d5551978a *) [@ CNoInline ] let gte_mask (a:t) (b:t) : Pure t (requires True) (ensures (fun c -> (v a >= v b ==> v c = pow2 n - 1) /\ (v a < v b ==> v c = 0))) = let x = a in let y = b in let x_xor_y = logxor x y in let x_sub_y = sub_mod x y in let x_sub_y_xor_y = logxor x_sub_y y in let q = logor x_xor_y x_sub_y_xor_y in let x_xor_q = logxor x q in let x_xor_q_ = shift_right x_xor_q n_minus_one in let c = sub_mod x_xor_q_ (uint_to_t 1) in lemma_sub_msbs x y; lemma_msb_gte (v x) (v y); lemma_msb_gte (v y) (v x); c #reset-options (*** Infix notations *) unfold let op_Plus_Hat = add unfold let op_Plus_Question_Hat = add_underspec unfold let op_Plus_Percent_Hat = add_mod unfold let op_Subtraction_Hat = sub
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.UInt32.fsti.checked", "FStar.UInt.fsti.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked" ], "interface_file": false, "source_file": "FStar.UInt64.fsti" }
[ { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.UInt", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.UInt", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "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: FStar.UInt64.t -> b: FStar.UInt64.t -> Prims.Pure FStar.UInt64.t
Prims.Pure
[]
[]
[ "FStar.UInt64.sub_mod" ]
[]
false
false
false
false
false
let op_Subtraction_Percent_Hat =
sub_mod
false
MerkleTree.Low.Datastructures.fst
MerkleTree.Low.Datastructures.hash_vec_r_alloc_p
val hash_vec_r_alloc_p: #hsz:hash_size_t -> v:hash_vec #hsz -> GTot Type0
val hash_vec_r_alloc_p: #hsz:hash_size_t -> v:hash_vec #hsz -> GTot Type0
let hash_vec_r_alloc_p #_ v = V.size_of v = 0ul
{ "file_name": "src/MerkleTree.Low.Datastructures.fst", "git_rev": "7d7bdc20f2033171e279c176b26e84f9069d23c6", "git_url": "https://github.com/hacl-star/merkle-tree.git", "project_name": "merkle-tree" }
{ "end_col": 47, "end_line": 253, "start_col": 0, "start_line": 253 }
module MerkleTree.Low.Datastructures open FStar.All open FStar.Integers open FStar.Mul open LowStar.Buffer open LowStar.BufferOps open LowStar.Vector open LowStar.Regional open LowStar.RVector open LowStar.Regional.Instances module HS = FStar.HyperStack module HST = FStar.HyperStack.ST module MHS = FStar.Monotonic.HyperStack module HH = FStar.Monotonic.HyperHeap module B = LowStar.Buffer module CB = LowStar.ConstBuffer module V = LowStar.Vector module RV = LowStar.RVector module RVI = LowStar.Regional.Instances module S = FStar.Seq module EHS = EverCrypt.Hash module U32 = FStar.UInt32 module MTH = MerkleTree.New.High open EverCrypt.Helpers open Lib.IntTypes #set-options "--z3rlimit 10 --initial_fuel 0 --max_fuel 0 --initial_ifuel 0 --max_ifuel 0" type hash_size_t = n:uint32_t{n > 0ul} type hash (#hsz:hash_size_t) = b:B.buffer uint8 { B.len b = hsz \/ B.g_is_null b } // We cannot use `Low.RVector.Instances`, where we have some general // typeclass instances of `regional`, e.g., if `rg:regional a` then // `regional (rvector rg)`. In FStar we can use this, but KaRaMeL currently // cannot deal with this and gives a number of errors. // So we temporarily instantiate some `regional`s manually below, which is // extractable to C by KaRaMeL. /// Some instantiations of `regional` used in Merkle tree /// 1. `hash` is regional private noextract val hash_region_of: #hsz:hash_size_t -> v:hash #hsz -> GTot HH.rid let hash_region_of #_ v = B.frameOf v private inline_for_extraction val hash_dummy: #hsz:Ghost.erased hash_size_t -> Tot (hash #hsz) let hash_dummy #_ = B.null private noextract val hash_r_inv: #hsz:hash_size_t -> h:HS.mem -> v:hash #hsz -> GTot Type0 let hash_r_inv #hsz h v = B.live h v /\ B.freeable v /\ B.len v = hsz private noextract val hash_r_inv_reg: #hsz:hash_size_t -> h:HS.mem -> v:hash -> Lemma (requires hash_r_inv h v) (ensures MHS.live_region h (hash_region_of #hsz v)) let hash_r_inv_reg #_ h v = () private noextract val hash_repr (#hsz:hash_size_t): Type0 let hash_repr #hsz = MTH.hash #(U32.v hsz) private noextract val hash_r_repr: #hsz:hash_size_t -> h:HS.mem -> v:hash{hash_r_inv #hsz h v} -> GTot (hash_repr #hsz) let hash_r_repr #_ h v = B.as_seq h v private noextract val hash_r_sep: #hsz:hash_size_t -> v:hash #hsz -> p:loc -> h0:HS.mem -> h1:HS.mem -> Lemma (requires hash_r_inv h0 v /\ loc_disjoint (loc_all_regions_from false (hash_region_of v)) p /\ modifies p h0 h1) (ensures hash_r_inv h1 v /\ hash_r_repr h0 v == hash_r_repr h1 v) let hash_r_sep #_ v p h0 h1 = assert (loc_includes (loc_all_regions_from false (hash_region_of v)) (loc_buffer v)); B.modifies_buffer_elim v p h0 h1 private noextract val hash_irepr: #hsz:hash_size_t -> Ghost.erased (hash_repr #hsz) let hash_irepr #hsz = Ghost.hide (S.create (U32.v hsz) (u8 0)) private noextract val hash_r_alloc_p: #hsz:hash_size_t -> v:hash #hsz -> GTot Type0 let hash_r_alloc_p #_ v = True val hash_r_alloc: #hsz':Ghost.erased hash_size_t -> hsz:hash_size_t { hsz == Ghost.reveal hsz' } -> r:HST.erid -> HST.ST (hash #hsz) (requires (fun h0 -> true)) (ensures (fun h0 v h1 -> Set.subset (Map.domain (MHS.get_hmap h0)) (Map.domain (MHS.get_hmap h1)) /\ modifies loc_none h0 h1 /\ hash_r_alloc_p #hsz v /\ hash_r_inv h1 v /\ hash_region_of v = r /\ hash_r_repr h1 v == Ghost.reveal hash_irepr /\ B.fresh_loc (B.loc_buffer v) h0 h1)) let hash_r_alloc #_ s r = B.malloc r (u8 0) s val hash_r_free: #hsz':Ghost.erased hash_size_t -> hsz:hash_size_t { hsz == Ghost.reveal hsz' } -> v:hash #hsz' -> HST.ST unit (requires fun h0 -> hash_r_inv h0 v) (ensures fun h0 _ h1 -> modifies (loc_all_regions_from false (hash_region_of v)) h0 h1) let hash_r_free #_ _ v = B.free v noextract inline_for_extraction val hreg (hsz:hash_size_t): regional (hash_size_t) (hash #hsz) let hreg hsz = Rgl #(hash_size_t) #(hash #hsz) hsz (hash_region_of #hsz) (B.loc_buffer) (hash_dummy #hsz) (hash_r_inv #hsz) (hash_r_inv_reg #hsz) (hash_repr #hsz) (hash_r_repr #hsz) (hash_r_sep #hsz) (hash_irepr #hsz) (hash_r_alloc_p #hsz) (hash_r_alloc #hsz) (hash_r_free #hsz) private val hash_copy: #s':Ghost.erased hash_size_t -> s:hash_size_t { s == Ghost.reveal s' } -> src:hash #s -> dst:hash #s -> HST.ST unit (requires fun h0 -> hash_r_inv h0 src /\ hash_r_inv h0 dst /\ HH.disjoint (hash_region_of src) (hash_region_of dst)) (ensures fun h0 _ h1 -> modifies (loc_all_regions_from false (hash_region_of dst)) h0 h1 /\ hash_r_inv h1 dst /\ hash_r_repr h1 dst == hash_r_repr h0 src) let hash_copy #_ s src dst = B.blit src 0ul dst 0ul s /// JP: so much stuff happening here. First, single-constructor, single-argument /// elimination takes places and Cpy becomes completely eliminated, in favor of /// just being a type alias for the underlying function. So now, we have a /// function that returns a function pointer. /// /// Next, one might think that the hsz argument is going to be eliminated. It's /// not, because there's a hidden implicit argument to Cpy which is (hreg hsz), /// meaning that hsz is used at run-time even though Cpy is only using this /// argument ghostly. This would be have to be fixed. /// /// Finally, if the inline_for_extraction is removed, there seems to be a /// karamel bug that inserts a void*0. To be fixed. inline_for_extraction val hcpy: hsz:hash_size_t -> copyable #hash_size_t (hash #hsz) (hreg hsz) let hcpy hsz = Cpy (hash_copy #hsz) type hash_vec (#hsz:hash_size_t) = RV.rvector (hreg hsz) /// 2. `rvector hash` is regional type rhst (hsz:hash_size_t) = regional hash_size_t (hash #hsz) private noextract val hash_vec_region_of: #hsz:hash_size_t -> v:hash_vec #hsz -> GTot HH.rid let hash_vec_region_of #_ v = V.frameOf v private inline_for_extraction val hash_vec_dummy: (#hsz:Ghost.erased hash_size_t) -> hash_vec #hsz let hash_vec_dummy #_ = V.alloc_empty (hash #_) noextract val hash_vec_r_inv: #hsz:hash_size_t -> h:HS.mem -> v:hash_vec #hsz -> GTot Type0 let hash_vec_r_inv #hsz h v = RV.rv_inv h v noextract val hash_vec_r_inv_reg: #hsz:hash_size_t -> h:HS.mem -> v:hash_vec #hsz -> Lemma (requires (hash_vec_r_inv h v)) (ensures (MHS.live_region h (hash_vec_region_of v))) let hash_vec_r_inv_reg #_ h v = () private noextract val hash_vec_repr: #hsz:hash_size_t -> Type0 let hash_vec_repr #hsz = MTH.hashes #(U32.v hsz) noextract val hash_vec_r_repr: #hsz:hash_size_t -> h:HS.mem -> v:hash_vec #hsz {hash_vec_r_inv h v} -> GTot (hash_vec_repr #hsz) let hash_vec_r_repr #_ h v = RV.as_seq h v noextract val hash_vec_r_sep: #hsz:hash_size_t -> v:hash_vec #hsz -> p:loc -> h0:HS.mem -> h1:HS.mem -> Lemma (requires (hash_vec_r_inv h0 v /\ loc_disjoint (loc_all_regions_from false (hash_vec_region_of v)) p /\ modifies p h0 h1)) (ensures (hash_vec_r_inv h1 v /\ hash_vec_r_repr h0 v == hash_vec_r_repr h1 v)) let hash_vec_r_sep #_ v p h0 h1 = RV.rv_inv_preserved v p h0 h1; RV.as_seq_preserved v p h0 h1 noextract val hash_vec_irepr: #hsz:hash_size_t -> Ghost.erased (hash_vec_repr #hsz) let hash_vec_irepr #_ = Ghost.hide S.empty noextract
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "MerkleTree.New.High.fst.checked", "LowStar.Vector.fst.checked", "LowStar.RVector.fst.checked", "LowStar.Regional.Instances.fst.checked", "LowStar.Regional.fst.checked", "LowStar.ConstBuffer.fsti.checked", "LowStar.BufferOps.fst.checked", "LowStar.Buffer.fst.checked", "Lib.IntTypes.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Set.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Monotonic.HyperStack.fsti.checked", "FStar.Monotonic.HyperHeap.fsti.checked", "FStar.Map.fsti.checked", "FStar.Integers.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked", "FStar.All.fst.checked", "EverCrypt.Helpers.fsti.checked", "EverCrypt.Hash.fsti.checked" ], "interface_file": false, "source_file": "MerkleTree.Low.Datastructures.fst" }
[ { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "EverCrypt.Helpers", "short_module": null }, { "abbrev": true, "full_module": "MerkleTree.New.High", "short_module": "MTH" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": true, "full_module": "EverCrypt.Hash", "short_module": "EHS" }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "S" }, { "abbrev": true, "full_module": "LowStar.Regional.Instances", "short_module": "RVI" }, { "abbrev": true, "full_module": "LowStar.RVector", "short_module": "RV" }, { "abbrev": true, "full_module": "LowStar.Vector", "short_module": "V" }, { "abbrev": true, "full_module": "LowStar.ConstBuffer", "short_module": "CB" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.Monotonic.HyperHeap", "short_module": "HH" }, { "abbrev": true, "full_module": "FStar.Monotonic.HyperStack", "short_module": "MHS" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": false, "full_module": "LowStar.Regional.Instances", "short_module": null }, { "abbrev": false, "full_module": "LowStar.RVector", "short_module": null }, { "abbrev": false, "full_module": "LowStar.Regional", "short_module": null }, { "abbrev": false, "full_module": "LowStar.Vector", "short_module": null }, { "abbrev": false, "full_module": "LowStar.BufferOps", "short_module": null }, { "abbrev": false, "full_module": "LowStar.Buffer", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.Integers", "short_module": null }, { "abbrev": false, "full_module": "FStar.All", "short_module": null }, { "abbrev": false, "full_module": "MerkleTree.Low", "short_module": null }, { "abbrev": false, "full_module": "MerkleTree.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": 0, "initial_ifuel": 0, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 10, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
v: MerkleTree.Low.Datastructures.hash_vec -> Prims.GTot Type0
Prims.GTot
[ "sometrivial" ]
[]
[ "MerkleTree.Low.Datastructures.hash_size_t", "MerkleTree.Low.Datastructures.hash_vec", "Prims.b2t", "Prims.op_Equality", "FStar.UInt32.t", "LowStar.Vector.size_of", "MerkleTree.Low.Datastructures.hash", "FStar.UInt32.__uint_to_t" ]
[]
false
false
false
false
true
let hash_vec_r_alloc_p #_ v =
V.size_of v = 0ul
false
FStar.UInt64.fsti
FStar.UInt64.op_Subtraction_Hat
val op_Subtraction_Hat : a: FStar.UInt64.t -> b: FStar.UInt64.t -> Prims.Pure FStar.UInt64.t
let op_Subtraction_Hat = sub
{ "file_name": "ulib/FStar.UInt64.fsti", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 35, "end_line": 319, "start_col": 7, "start_line": 319 }
(* 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 FStar.UInt64 (**** THIS MODULE IS GENERATED AUTOMATICALLY USING [mk_int.sh], DO NOT EDIT DIRECTLY ****) unfold let n = 64 /// For FStar.UIntN.fstp: anything that you fix/update here should be /// reflected in [FStar.IntN.fstp], which is mostly a copy-paste of /// this module. /// /// Except, as compared to [FStar.IntN.fstp], here: /// - every occurrence of [int_t] has been replaced with [uint_t] /// - every occurrence of [@%] has been replaced with [%]. /// - some functions (e.g., add_underspec, etc.) are only defined here, not on signed integers /// This module provides an abstract type for machine integers of a /// given signedness and width. The interface is designed to be safe /// with respect to arithmetic underflow and overflow. /// Note, we have attempted several times to re-design this module to /// make it more amenable to normalization and to impose less overhead /// on the SMT solver when reasoning about machine integer /// arithmetic. The following github issue reports on the current /// status of that work. /// /// https://github.com/FStarLang/FStar/issues/1757 open FStar.UInt open FStar.Mul #set-options "--max_fuel 0 --max_ifuel 0" (** Abstract type of machine integers, with an underlying representation using a bounded mathematical integer *) new val t : eqtype (** A coercion that projects a bounded mathematical integer from a machine integer *) val v (x:t) : Tot (uint_t n) (** A coercion that injects a bounded mathematical integers into a machine integer *) val uint_to_t (x:uint_t n) : Pure t (requires True) (ensures (fun y -> v y = x)) (** Injection/projection inverse *) val uv_inv (x : t) : Lemma (ensures (uint_to_t (v x) == x)) [SMTPat (v x)] (** Projection/injection inverse *) val vu_inv (x : uint_t n) : Lemma (ensures (v (uint_to_t x) == x)) [SMTPat (uint_to_t x)] (** An alternate form of the injectivity of the [v] projection *) val v_inj (x1 x2: t): Lemma (requires (v x1 == v x2)) (ensures (x1 == x2)) (** Constants 0 and 1 *) val zero : x:t{v x = 0} val one : x:t{v x = 1} (**** Addition primitives *) (** Bounds-respecting addition The precondition enforces that the sum does not overflow, expressing the bound as an addition on mathematical integers *) val add (a:t) (b:t) : Pure t (requires (size (v a + v b) n)) (ensures (fun c -> v a + v b = v c)) (** Underspecified, possibly overflowing addition: The postcondition only enures that the result is the sum of the arguments in case there is no overflow *) val add_underspec (a:t) (b:t) : Pure t (requires True) (ensures (fun c -> size (v a + v b) n ==> v a + v b = v c)) (** Addition modulo [2^n] Machine integers can always be added, but the postcondition is now in terms of addition modulo [2^n] on mathematical integers *) val add_mod (a:t) (b:t) : Pure t (requires True) (ensures (fun c -> FStar.UInt.add_mod (v a) (v b) = v c)) (**** Subtraction primitives *) (** Bounds-respecting subtraction The precondition enforces that the difference does not underflow, expressing the bound as a difference on mathematical integers *) val sub (a:t) (b:t) : Pure t (requires (size (v a - v b) n)) (ensures (fun c -> v a - v b = v c)) (** Underspecified, possibly overflowing subtraction: The postcondition only enures that the result is the difference of the arguments in case there is no underflow *) val sub_underspec (a:t) (b:t) : Pure t (requires True) (ensures (fun c -> size (v a - v b) n ==> v a - v b = v c)) (** Subtraction modulo [2^n] Machine integers can always be subtractd, but the postcondition is now in terms of subtraction modulo [2^n] on mathematical integers *) val sub_mod (a:t) (b:t) : Pure t (requires True) (ensures (fun c -> FStar.UInt.sub_mod (v a) (v b) = v c)) (**** Multiplication primitives *) (** Bounds-respecting multiplication The precondition enforces that the product does not overflow, expressing the bound as a product on mathematical integers *) val mul (a:t) (b:t) : Pure t (requires (size (v a * v b) n)) (ensures (fun c -> v a * v b = v c)) (** Underspecified, possibly overflowing product The postcondition only enures that the result is the product of the arguments in case there is no overflow *) val mul_underspec (a:t) (b:t) : Pure t (requires True) (ensures (fun c -> size (v a * v b) n ==> v a * v b = v c)) (** Multiplication modulo [2^n] Machine integers can always be multiplied, but the postcondition is now in terms of product modulo [2^n] on mathematical integers *) val mul_mod (a:t) (b:t) : Pure t (requires True) (ensures (fun c -> FStar.UInt.mul_mod (v a) (v b) = v c)) (**** Division primitives *) (** Euclidean division of [a] and [b], with [b] non-zero *) val div (a:t) (b:t{v b <> 0}) : Pure t (requires (True)) (ensures (fun c -> v a / v b = v c)) (**** Modulo primitives *) (** Euclidean remainder The result is the modulus of [a] with respect to a non-zero [b] *) val rem (a:t) (b:t{v b <> 0}) : Pure t (requires True) (ensures (fun c -> FStar.UInt.mod (v a) (v b) = v c)) (**** Bitwise operators *) /// Also see FStar.BV (** Bitwise logical conjunction *) val logand (x:t) (y:t) : Pure t (requires True) (ensures (fun z -> v x `logand` v y = v z)) (** Bitwise logical exclusive-or *) val logxor (x:t) (y:t) : Pure t (requires True) (ensures (fun z -> v x `logxor` v y == v z)) (** Bitwise logical disjunction *) val logor (x:t) (y:t) : Pure t (requires True) (ensures (fun z -> v x `logor` v y == v z)) (** Bitwise logical negation *) val lognot (x:t) : Pure t (requires True) (ensures (fun z -> lognot (v x) == v z)) (**** Shift operators *) (** Shift right with zero fill, shifting at most the integer width *) val shift_right (a:t) (s:UInt32.t) : Pure t (requires (UInt32.v s < n)) (ensures (fun c -> FStar.UInt.shift_right (v a) (UInt32.v s) = v c)) (** Shift left with zero fill, shifting at most the integer width *) val shift_left (a:t) (s:UInt32.t) : Pure t (requires (UInt32.v s < n)) (ensures (fun c -> FStar.UInt.shift_left (v a) (UInt32.v s) = v c)) (**** Comparison operators *) (** Equality Note, it is safe to also use the polymorphic decidable equality operator [=] *) let eq (a:t) (b:t) : Tot bool = eq #n (v a) (v b) (** Greater than *) let gt (a:t) (b:t) : Tot bool = gt #n (v a) (v b) (** Greater than or equal *) let gte (a:t) (b:t) : Tot bool = gte #n (v a) (v b) (** Less than *) let lt (a:t) (b:t) : Tot bool = lt #n (v a) (v b) (** Less than or equal *) let lte (a:t) (b:t) : Tot bool = lte #n (v a) (v b) (** Unary negation *) inline_for_extraction let minus (a:t) = add_mod (lognot a) (uint_to_t 1) (** The maximum shift value for this type, i.e. its width minus one, as an UInt32. *) inline_for_extraction let n_minus_one = UInt32.uint_to_t (n - 1) #set-options "--z3rlimit 80 --initial_fuel 1 --max_fuel 1" (** A constant-time way to compute the equality of two machine integers. With inspiration from https://git.zx2c4.com/WireGuard/commit/src/crypto/curve25519-hacl64.h?id=2e60bb395c1f589a398ec606d611132ef9ef764b Note, the branching on [a=b] is just for proof-purposes. *) [@ CNoInline ] let eq_mask (a:t) (b:t) : Pure t (requires True) (ensures (fun c -> (v a = v b ==> v c = pow2 n - 1) /\ (v a <> v b ==> v c = 0))) = let x = logxor a b in let minus_x = minus x in let x_or_minus_x = logor x minus_x in let xnx = shift_right x_or_minus_x n_minus_one in let c = sub_mod xnx (uint_to_t 1) in if a = b then begin logxor_self (v a); lognot_lemma_1 #n; logor_lemma_1 (v x); assert (v x = 0 /\ v minus_x = 0 /\ v x_or_minus_x = 0 /\ v xnx = 0); assert (v c = ones n) end else begin logxor_neq_nonzero (v a) (v b); lemma_msb_pow2 #n (v (lognot x)); lemma_msb_pow2 #n (v minus_x); lemma_minus_zero #n (v x); assert (v c = FStar.UInt.zero n) end; c private val lemma_sub_msbs (a:t) (b:t) : Lemma ((msb (v a) = msb (v b)) ==> (v a < v b <==> msb (v (sub_mod a b)))) (** A constant-time way to compute the [>=] inequality of two machine integers. With inspiration from https://git.zx2c4.com/WireGuard/commit/src/crypto/curve25519-hacl64.h?id=0a483a9b431d87eca1b275463c632f8d5551978a *) [@ CNoInline ] let gte_mask (a:t) (b:t) : Pure t (requires True) (ensures (fun c -> (v a >= v b ==> v c = pow2 n - 1) /\ (v a < v b ==> v c = 0))) = let x = a in let y = b in let x_xor_y = logxor x y in let x_sub_y = sub_mod x y in let x_sub_y_xor_y = logxor x_sub_y y in let q = logor x_xor_y x_sub_y_xor_y in let x_xor_q = logxor x q in let x_xor_q_ = shift_right x_xor_q n_minus_one in let c = sub_mod x_xor_q_ (uint_to_t 1) in lemma_sub_msbs x y; lemma_msb_gte (v x) (v y); lemma_msb_gte (v y) (v x); c #reset-options (*** Infix notations *) unfold let op_Plus_Hat = add unfold let op_Plus_Question_Hat = add_underspec
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.UInt32.fsti.checked", "FStar.UInt.fsti.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked" ], "interface_file": false, "source_file": "FStar.UInt64.fsti" }
[ { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.UInt", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.UInt", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "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: FStar.UInt64.t -> b: FStar.UInt64.t -> Prims.Pure FStar.UInt64.t
Prims.Pure
[]
[]
[ "FStar.UInt64.sub" ]
[]
false
false
false
false
false
let op_Subtraction_Hat =
sub
false
FStar.UInt64.fsti
FStar.UInt64.op_Plus_Question_Hat
val op_Plus_Question_Hat : a: FStar.UInt64.t -> b: FStar.UInt64.t -> Prims.Pure FStar.UInt64.t
let op_Plus_Question_Hat = add_underspec
{ "file_name": "ulib/FStar.UInt64.fsti", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 47, "end_line": 317, "start_col": 7, "start_line": 317 }
(* 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 FStar.UInt64 (**** THIS MODULE IS GENERATED AUTOMATICALLY USING [mk_int.sh], DO NOT EDIT DIRECTLY ****) unfold let n = 64 /// For FStar.UIntN.fstp: anything that you fix/update here should be /// reflected in [FStar.IntN.fstp], which is mostly a copy-paste of /// this module. /// /// Except, as compared to [FStar.IntN.fstp], here: /// - every occurrence of [int_t] has been replaced with [uint_t] /// - every occurrence of [@%] has been replaced with [%]. /// - some functions (e.g., add_underspec, etc.) are only defined here, not on signed integers /// This module provides an abstract type for machine integers of a /// given signedness and width. The interface is designed to be safe /// with respect to arithmetic underflow and overflow. /// Note, we have attempted several times to re-design this module to /// make it more amenable to normalization and to impose less overhead /// on the SMT solver when reasoning about machine integer /// arithmetic. The following github issue reports on the current /// status of that work. /// /// https://github.com/FStarLang/FStar/issues/1757 open FStar.UInt open FStar.Mul #set-options "--max_fuel 0 --max_ifuel 0" (** Abstract type of machine integers, with an underlying representation using a bounded mathematical integer *) new val t : eqtype (** A coercion that projects a bounded mathematical integer from a machine integer *) val v (x:t) : Tot (uint_t n) (** A coercion that injects a bounded mathematical integers into a machine integer *) val uint_to_t (x:uint_t n) : Pure t (requires True) (ensures (fun y -> v y = x)) (** Injection/projection inverse *) val uv_inv (x : t) : Lemma (ensures (uint_to_t (v x) == x)) [SMTPat (v x)] (** Projection/injection inverse *) val vu_inv (x : uint_t n) : Lemma (ensures (v (uint_to_t x) == x)) [SMTPat (uint_to_t x)] (** An alternate form of the injectivity of the [v] projection *) val v_inj (x1 x2: t): Lemma (requires (v x1 == v x2)) (ensures (x1 == x2)) (** Constants 0 and 1 *) val zero : x:t{v x = 0} val one : x:t{v x = 1} (**** Addition primitives *) (** Bounds-respecting addition The precondition enforces that the sum does not overflow, expressing the bound as an addition on mathematical integers *) val add (a:t) (b:t) : Pure t (requires (size (v a + v b) n)) (ensures (fun c -> v a + v b = v c)) (** Underspecified, possibly overflowing addition: The postcondition only enures that the result is the sum of the arguments in case there is no overflow *) val add_underspec (a:t) (b:t) : Pure t (requires True) (ensures (fun c -> size (v a + v b) n ==> v a + v b = v c)) (** Addition modulo [2^n] Machine integers can always be added, but the postcondition is now in terms of addition modulo [2^n] on mathematical integers *) val add_mod (a:t) (b:t) : Pure t (requires True) (ensures (fun c -> FStar.UInt.add_mod (v a) (v b) = v c)) (**** Subtraction primitives *) (** Bounds-respecting subtraction The precondition enforces that the difference does not underflow, expressing the bound as a difference on mathematical integers *) val sub (a:t) (b:t) : Pure t (requires (size (v a - v b) n)) (ensures (fun c -> v a - v b = v c)) (** Underspecified, possibly overflowing subtraction: The postcondition only enures that the result is the difference of the arguments in case there is no underflow *) val sub_underspec (a:t) (b:t) : Pure t (requires True) (ensures (fun c -> size (v a - v b) n ==> v a - v b = v c)) (** Subtraction modulo [2^n] Machine integers can always be subtractd, but the postcondition is now in terms of subtraction modulo [2^n] on mathematical integers *) val sub_mod (a:t) (b:t) : Pure t (requires True) (ensures (fun c -> FStar.UInt.sub_mod (v a) (v b) = v c)) (**** Multiplication primitives *) (** Bounds-respecting multiplication The precondition enforces that the product does not overflow, expressing the bound as a product on mathematical integers *) val mul (a:t) (b:t) : Pure t (requires (size (v a * v b) n)) (ensures (fun c -> v a * v b = v c)) (** Underspecified, possibly overflowing product The postcondition only enures that the result is the product of the arguments in case there is no overflow *) val mul_underspec (a:t) (b:t) : Pure t (requires True) (ensures (fun c -> size (v a * v b) n ==> v a * v b = v c)) (** Multiplication modulo [2^n] Machine integers can always be multiplied, but the postcondition is now in terms of product modulo [2^n] on mathematical integers *) val mul_mod (a:t) (b:t) : Pure t (requires True) (ensures (fun c -> FStar.UInt.mul_mod (v a) (v b) = v c)) (**** Division primitives *) (** Euclidean division of [a] and [b], with [b] non-zero *) val div (a:t) (b:t{v b <> 0}) : Pure t (requires (True)) (ensures (fun c -> v a / v b = v c)) (**** Modulo primitives *) (** Euclidean remainder The result is the modulus of [a] with respect to a non-zero [b] *) val rem (a:t) (b:t{v b <> 0}) : Pure t (requires True) (ensures (fun c -> FStar.UInt.mod (v a) (v b) = v c)) (**** Bitwise operators *) /// Also see FStar.BV (** Bitwise logical conjunction *) val logand (x:t) (y:t) : Pure t (requires True) (ensures (fun z -> v x `logand` v y = v z)) (** Bitwise logical exclusive-or *) val logxor (x:t) (y:t) : Pure t (requires True) (ensures (fun z -> v x `logxor` v y == v z)) (** Bitwise logical disjunction *) val logor (x:t) (y:t) : Pure t (requires True) (ensures (fun z -> v x `logor` v y == v z)) (** Bitwise logical negation *) val lognot (x:t) : Pure t (requires True) (ensures (fun z -> lognot (v x) == v z)) (**** Shift operators *) (** Shift right with zero fill, shifting at most the integer width *) val shift_right (a:t) (s:UInt32.t) : Pure t (requires (UInt32.v s < n)) (ensures (fun c -> FStar.UInt.shift_right (v a) (UInt32.v s) = v c)) (** Shift left with zero fill, shifting at most the integer width *) val shift_left (a:t) (s:UInt32.t) : Pure t (requires (UInt32.v s < n)) (ensures (fun c -> FStar.UInt.shift_left (v a) (UInt32.v s) = v c)) (**** Comparison operators *) (** Equality Note, it is safe to also use the polymorphic decidable equality operator [=] *) let eq (a:t) (b:t) : Tot bool = eq #n (v a) (v b) (** Greater than *) let gt (a:t) (b:t) : Tot bool = gt #n (v a) (v b) (** Greater than or equal *) let gte (a:t) (b:t) : Tot bool = gte #n (v a) (v b) (** Less than *) let lt (a:t) (b:t) : Tot bool = lt #n (v a) (v b) (** Less than or equal *) let lte (a:t) (b:t) : Tot bool = lte #n (v a) (v b) (** Unary negation *) inline_for_extraction let minus (a:t) = add_mod (lognot a) (uint_to_t 1) (** The maximum shift value for this type, i.e. its width minus one, as an UInt32. *) inline_for_extraction let n_minus_one = UInt32.uint_to_t (n - 1) #set-options "--z3rlimit 80 --initial_fuel 1 --max_fuel 1" (** A constant-time way to compute the equality of two machine integers. With inspiration from https://git.zx2c4.com/WireGuard/commit/src/crypto/curve25519-hacl64.h?id=2e60bb395c1f589a398ec606d611132ef9ef764b Note, the branching on [a=b] is just for proof-purposes. *) [@ CNoInline ] let eq_mask (a:t) (b:t) : Pure t (requires True) (ensures (fun c -> (v a = v b ==> v c = pow2 n - 1) /\ (v a <> v b ==> v c = 0))) = let x = logxor a b in let minus_x = minus x in let x_or_minus_x = logor x minus_x in let xnx = shift_right x_or_minus_x n_minus_one in let c = sub_mod xnx (uint_to_t 1) in if a = b then begin logxor_self (v a); lognot_lemma_1 #n; logor_lemma_1 (v x); assert (v x = 0 /\ v minus_x = 0 /\ v x_or_minus_x = 0 /\ v xnx = 0); assert (v c = ones n) end else begin logxor_neq_nonzero (v a) (v b); lemma_msb_pow2 #n (v (lognot x)); lemma_msb_pow2 #n (v minus_x); lemma_minus_zero #n (v x); assert (v c = FStar.UInt.zero n) end; c private val lemma_sub_msbs (a:t) (b:t) : Lemma ((msb (v a) = msb (v b)) ==> (v a < v b <==> msb (v (sub_mod a b)))) (** A constant-time way to compute the [>=] inequality of two machine integers. With inspiration from https://git.zx2c4.com/WireGuard/commit/src/crypto/curve25519-hacl64.h?id=0a483a9b431d87eca1b275463c632f8d5551978a *) [@ CNoInline ] let gte_mask (a:t) (b:t) : Pure t (requires True) (ensures (fun c -> (v a >= v b ==> v c = pow2 n - 1) /\ (v a < v b ==> v c = 0))) = let x = a in let y = b in let x_xor_y = logxor x y in let x_sub_y = sub_mod x y in let x_sub_y_xor_y = logxor x_sub_y y in let q = logor x_xor_y x_sub_y_xor_y in let x_xor_q = logxor x q in let x_xor_q_ = shift_right x_xor_q n_minus_one in let c = sub_mod x_xor_q_ (uint_to_t 1) in lemma_sub_msbs x y; lemma_msb_gte (v x) (v y); lemma_msb_gte (v y) (v x); c #reset-options (*** Infix notations *)
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.UInt32.fsti.checked", "FStar.UInt.fsti.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked" ], "interface_file": false, "source_file": "FStar.UInt64.fsti" }
[ { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.UInt", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.UInt", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "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: FStar.UInt64.t -> b: FStar.UInt64.t -> Prims.Pure FStar.UInt64.t
Prims.Pure
[]
[]
[ "FStar.UInt64.add_underspec" ]
[]
false
false
false
false
false
let op_Plus_Question_Hat =
add_underspec
false
FStar.UInt64.fsti
FStar.UInt64.op_Plus_Hat
val op_Plus_Hat : a: FStar.UInt64.t -> b: FStar.UInt64.t -> Prims.Pure FStar.UInt64.t
let op_Plus_Hat = add
{ "file_name": "ulib/FStar.UInt64.fsti", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 28, "end_line": 316, "start_col": 7, "start_line": 316 }
(* 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 FStar.UInt64 (**** THIS MODULE IS GENERATED AUTOMATICALLY USING [mk_int.sh], DO NOT EDIT DIRECTLY ****) unfold let n = 64 /// For FStar.UIntN.fstp: anything that you fix/update here should be /// reflected in [FStar.IntN.fstp], which is mostly a copy-paste of /// this module. /// /// Except, as compared to [FStar.IntN.fstp], here: /// - every occurrence of [int_t] has been replaced with [uint_t] /// - every occurrence of [@%] has been replaced with [%]. /// - some functions (e.g., add_underspec, etc.) are only defined here, not on signed integers /// This module provides an abstract type for machine integers of a /// given signedness and width. The interface is designed to be safe /// with respect to arithmetic underflow and overflow. /// Note, we have attempted several times to re-design this module to /// make it more amenable to normalization and to impose less overhead /// on the SMT solver when reasoning about machine integer /// arithmetic. The following github issue reports on the current /// status of that work. /// /// https://github.com/FStarLang/FStar/issues/1757 open FStar.UInt open FStar.Mul #set-options "--max_fuel 0 --max_ifuel 0" (** Abstract type of machine integers, with an underlying representation using a bounded mathematical integer *) new val t : eqtype (** A coercion that projects a bounded mathematical integer from a machine integer *) val v (x:t) : Tot (uint_t n) (** A coercion that injects a bounded mathematical integers into a machine integer *) val uint_to_t (x:uint_t n) : Pure t (requires True) (ensures (fun y -> v y = x)) (** Injection/projection inverse *) val uv_inv (x : t) : Lemma (ensures (uint_to_t (v x) == x)) [SMTPat (v x)] (** Projection/injection inverse *) val vu_inv (x : uint_t n) : Lemma (ensures (v (uint_to_t x) == x)) [SMTPat (uint_to_t x)] (** An alternate form of the injectivity of the [v] projection *) val v_inj (x1 x2: t): Lemma (requires (v x1 == v x2)) (ensures (x1 == x2)) (** Constants 0 and 1 *) val zero : x:t{v x = 0} val one : x:t{v x = 1} (**** Addition primitives *) (** Bounds-respecting addition The precondition enforces that the sum does not overflow, expressing the bound as an addition on mathematical integers *) val add (a:t) (b:t) : Pure t (requires (size (v a + v b) n)) (ensures (fun c -> v a + v b = v c)) (** Underspecified, possibly overflowing addition: The postcondition only enures that the result is the sum of the arguments in case there is no overflow *) val add_underspec (a:t) (b:t) : Pure t (requires True) (ensures (fun c -> size (v a + v b) n ==> v a + v b = v c)) (** Addition modulo [2^n] Machine integers can always be added, but the postcondition is now in terms of addition modulo [2^n] on mathematical integers *) val add_mod (a:t) (b:t) : Pure t (requires True) (ensures (fun c -> FStar.UInt.add_mod (v a) (v b) = v c)) (**** Subtraction primitives *) (** Bounds-respecting subtraction The precondition enforces that the difference does not underflow, expressing the bound as a difference on mathematical integers *) val sub (a:t) (b:t) : Pure t (requires (size (v a - v b) n)) (ensures (fun c -> v a - v b = v c)) (** Underspecified, possibly overflowing subtraction: The postcondition only enures that the result is the difference of the arguments in case there is no underflow *) val sub_underspec (a:t) (b:t) : Pure t (requires True) (ensures (fun c -> size (v a - v b) n ==> v a - v b = v c)) (** Subtraction modulo [2^n] Machine integers can always be subtractd, but the postcondition is now in terms of subtraction modulo [2^n] on mathematical integers *) val sub_mod (a:t) (b:t) : Pure t (requires True) (ensures (fun c -> FStar.UInt.sub_mod (v a) (v b) = v c)) (**** Multiplication primitives *) (** Bounds-respecting multiplication The precondition enforces that the product does not overflow, expressing the bound as a product on mathematical integers *) val mul (a:t) (b:t) : Pure t (requires (size (v a * v b) n)) (ensures (fun c -> v a * v b = v c)) (** Underspecified, possibly overflowing product The postcondition only enures that the result is the product of the arguments in case there is no overflow *) val mul_underspec (a:t) (b:t) : Pure t (requires True) (ensures (fun c -> size (v a * v b) n ==> v a * v b = v c)) (** Multiplication modulo [2^n] Machine integers can always be multiplied, but the postcondition is now in terms of product modulo [2^n] on mathematical integers *) val mul_mod (a:t) (b:t) : Pure t (requires True) (ensures (fun c -> FStar.UInt.mul_mod (v a) (v b) = v c)) (**** Division primitives *) (** Euclidean division of [a] and [b], with [b] non-zero *) val div (a:t) (b:t{v b <> 0}) : Pure t (requires (True)) (ensures (fun c -> v a / v b = v c)) (**** Modulo primitives *) (** Euclidean remainder The result is the modulus of [a] with respect to a non-zero [b] *) val rem (a:t) (b:t{v b <> 0}) : Pure t (requires True) (ensures (fun c -> FStar.UInt.mod (v a) (v b) = v c)) (**** Bitwise operators *) /// Also see FStar.BV (** Bitwise logical conjunction *) val logand (x:t) (y:t) : Pure t (requires True) (ensures (fun z -> v x `logand` v y = v z)) (** Bitwise logical exclusive-or *) val logxor (x:t) (y:t) : Pure t (requires True) (ensures (fun z -> v x `logxor` v y == v z)) (** Bitwise logical disjunction *) val logor (x:t) (y:t) : Pure t (requires True) (ensures (fun z -> v x `logor` v y == v z)) (** Bitwise logical negation *) val lognot (x:t) : Pure t (requires True) (ensures (fun z -> lognot (v x) == v z)) (**** Shift operators *) (** Shift right with zero fill, shifting at most the integer width *) val shift_right (a:t) (s:UInt32.t) : Pure t (requires (UInt32.v s < n)) (ensures (fun c -> FStar.UInt.shift_right (v a) (UInt32.v s) = v c)) (** Shift left with zero fill, shifting at most the integer width *) val shift_left (a:t) (s:UInt32.t) : Pure t (requires (UInt32.v s < n)) (ensures (fun c -> FStar.UInt.shift_left (v a) (UInt32.v s) = v c)) (**** Comparison operators *) (** Equality Note, it is safe to also use the polymorphic decidable equality operator [=] *) let eq (a:t) (b:t) : Tot bool = eq #n (v a) (v b) (** Greater than *) let gt (a:t) (b:t) : Tot bool = gt #n (v a) (v b) (** Greater than or equal *) let gte (a:t) (b:t) : Tot bool = gte #n (v a) (v b) (** Less than *) let lt (a:t) (b:t) : Tot bool = lt #n (v a) (v b) (** Less than or equal *) let lte (a:t) (b:t) : Tot bool = lte #n (v a) (v b) (** Unary negation *) inline_for_extraction let minus (a:t) = add_mod (lognot a) (uint_to_t 1) (** The maximum shift value for this type, i.e. its width minus one, as an UInt32. *) inline_for_extraction let n_minus_one = UInt32.uint_to_t (n - 1) #set-options "--z3rlimit 80 --initial_fuel 1 --max_fuel 1" (** A constant-time way to compute the equality of two machine integers. With inspiration from https://git.zx2c4.com/WireGuard/commit/src/crypto/curve25519-hacl64.h?id=2e60bb395c1f589a398ec606d611132ef9ef764b Note, the branching on [a=b] is just for proof-purposes. *) [@ CNoInline ] let eq_mask (a:t) (b:t) : Pure t (requires True) (ensures (fun c -> (v a = v b ==> v c = pow2 n - 1) /\ (v a <> v b ==> v c = 0))) = let x = logxor a b in let minus_x = minus x in let x_or_minus_x = logor x minus_x in let xnx = shift_right x_or_minus_x n_minus_one in let c = sub_mod xnx (uint_to_t 1) in if a = b then begin logxor_self (v a); lognot_lemma_1 #n; logor_lemma_1 (v x); assert (v x = 0 /\ v minus_x = 0 /\ v x_or_minus_x = 0 /\ v xnx = 0); assert (v c = ones n) end else begin logxor_neq_nonzero (v a) (v b); lemma_msb_pow2 #n (v (lognot x)); lemma_msb_pow2 #n (v minus_x); lemma_minus_zero #n (v x); assert (v c = FStar.UInt.zero n) end; c private val lemma_sub_msbs (a:t) (b:t) : Lemma ((msb (v a) = msb (v b)) ==> (v a < v b <==> msb (v (sub_mod a b)))) (** A constant-time way to compute the [>=] inequality of two machine integers. With inspiration from https://git.zx2c4.com/WireGuard/commit/src/crypto/curve25519-hacl64.h?id=0a483a9b431d87eca1b275463c632f8d5551978a *) [@ CNoInline ] let gte_mask (a:t) (b:t) : Pure t (requires True) (ensures (fun c -> (v a >= v b ==> v c = pow2 n - 1) /\ (v a < v b ==> v c = 0))) = let x = a in let y = b in let x_xor_y = logxor x y in let x_sub_y = sub_mod x y in let x_sub_y_xor_y = logxor x_sub_y y in let q = logor x_xor_y x_sub_y_xor_y in let x_xor_q = logxor x q in let x_xor_q_ = shift_right x_xor_q n_minus_one in let c = sub_mod x_xor_q_ (uint_to_t 1) in lemma_sub_msbs x y; lemma_msb_gte (v x) (v y); lemma_msb_gte (v y) (v x); c #reset-options
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.UInt32.fsti.checked", "FStar.UInt.fsti.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked" ], "interface_file": false, "source_file": "FStar.UInt64.fsti" }
[ { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.UInt", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.UInt", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "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: FStar.UInt64.t -> b: FStar.UInt64.t -> Prims.Pure FStar.UInt64.t
Prims.Pure
[]
[]
[ "FStar.UInt64.add" ]
[]
false
false
false
false
false
let op_Plus_Hat =
add
false
FStar.UInt64.fsti
FStar.UInt64.op_Plus_Percent_Hat
val op_Plus_Percent_Hat : a: FStar.UInt64.t -> b: FStar.UInt64.t -> Prims.Pure FStar.UInt64.t
let op_Plus_Percent_Hat = add_mod
{ "file_name": "ulib/FStar.UInt64.fsti", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 40, "end_line": 318, "start_col": 7, "start_line": 318 }
(* 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 FStar.UInt64 (**** THIS MODULE IS GENERATED AUTOMATICALLY USING [mk_int.sh], DO NOT EDIT DIRECTLY ****) unfold let n = 64 /// For FStar.UIntN.fstp: anything that you fix/update here should be /// reflected in [FStar.IntN.fstp], which is mostly a copy-paste of /// this module. /// /// Except, as compared to [FStar.IntN.fstp], here: /// - every occurrence of [int_t] has been replaced with [uint_t] /// - every occurrence of [@%] has been replaced with [%]. /// - some functions (e.g., add_underspec, etc.) are only defined here, not on signed integers /// This module provides an abstract type for machine integers of a /// given signedness and width. The interface is designed to be safe /// with respect to arithmetic underflow and overflow. /// Note, we have attempted several times to re-design this module to /// make it more amenable to normalization and to impose less overhead /// on the SMT solver when reasoning about machine integer /// arithmetic. The following github issue reports on the current /// status of that work. /// /// https://github.com/FStarLang/FStar/issues/1757 open FStar.UInt open FStar.Mul #set-options "--max_fuel 0 --max_ifuel 0" (** Abstract type of machine integers, with an underlying representation using a bounded mathematical integer *) new val t : eqtype (** A coercion that projects a bounded mathematical integer from a machine integer *) val v (x:t) : Tot (uint_t n) (** A coercion that injects a bounded mathematical integers into a machine integer *) val uint_to_t (x:uint_t n) : Pure t (requires True) (ensures (fun y -> v y = x)) (** Injection/projection inverse *) val uv_inv (x : t) : Lemma (ensures (uint_to_t (v x) == x)) [SMTPat (v x)] (** Projection/injection inverse *) val vu_inv (x : uint_t n) : Lemma (ensures (v (uint_to_t x) == x)) [SMTPat (uint_to_t x)] (** An alternate form of the injectivity of the [v] projection *) val v_inj (x1 x2: t): Lemma (requires (v x1 == v x2)) (ensures (x1 == x2)) (** Constants 0 and 1 *) val zero : x:t{v x = 0} val one : x:t{v x = 1} (**** Addition primitives *) (** Bounds-respecting addition The precondition enforces that the sum does not overflow, expressing the bound as an addition on mathematical integers *) val add (a:t) (b:t) : Pure t (requires (size (v a + v b) n)) (ensures (fun c -> v a + v b = v c)) (** Underspecified, possibly overflowing addition: The postcondition only enures that the result is the sum of the arguments in case there is no overflow *) val add_underspec (a:t) (b:t) : Pure t (requires True) (ensures (fun c -> size (v a + v b) n ==> v a + v b = v c)) (** Addition modulo [2^n] Machine integers can always be added, but the postcondition is now in terms of addition modulo [2^n] on mathematical integers *) val add_mod (a:t) (b:t) : Pure t (requires True) (ensures (fun c -> FStar.UInt.add_mod (v a) (v b) = v c)) (**** Subtraction primitives *) (** Bounds-respecting subtraction The precondition enforces that the difference does not underflow, expressing the bound as a difference on mathematical integers *) val sub (a:t) (b:t) : Pure t (requires (size (v a - v b) n)) (ensures (fun c -> v a - v b = v c)) (** Underspecified, possibly overflowing subtraction: The postcondition only enures that the result is the difference of the arguments in case there is no underflow *) val sub_underspec (a:t) (b:t) : Pure t (requires True) (ensures (fun c -> size (v a - v b) n ==> v a - v b = v c)) (** Subtraction modulo [2^n] Machine integers can always be subtractd, but the postcondition is now in terms of subtraction modulo [2^n] on mathematical integers *) val sub_mod (a:t) (b:t) : Pure t (requires True) (ensures (fun c -> FStar.UInt.sub_mod (v a) (v b) = v c)) (**** Multiplication primitives *) (** Bounds-respecting multiplication The precondition enforces that the product does not overflow, expressing the bound as a product on mathematical integers *) val mul (a:t) (b:t) : Pure t (requires (size (v a * v b) n)) (ensures (fun c -> v a * v b = v c)) (** Underspecified, possibly overflowing product The postcondition only enures that the result is the product of the arguments in case there is no overflow *) val mul_underspec (a:t) (b:t) : Pure t (requires True) (ensures (fun c -> size (v a * v b) n ==> v a * v b = v c)) (** Multiplication modulo [2^n] Machine integers can always be multiplied, but the postcondition is now in terms of product modulo [2^n] on mathematical integers *) val mul_mod (a:t) (b:t) : Pure t (requires True) (ensures (fun c -> FStar.UInt.mul_mod (v a) (v b) = v c)) (**** Division primitives *) (** Euclidean division of [a] and [b], with [b] non-zero *) val div (a:t) (b:t{v b <> 0}) : Pure t (requires (True)) (ensures (fun c -> v a / v b = v c)) (**** Modulo primitives *) (** Euclidean remainder The result is the modulus of [a] with respect to a non-zero [b] *) val rem (a:t) (b:t{v b <> 0}) : Pure t (requires True) (ensures (fun c -> FStar.UInt.mod (v a) (v b) = v c)) (**** Bitwise operators *) /// Also see FStar.BV (** Bitwise logical conjunction *) val logand (x:t) (y:t) : Pure t (requires True) (ensures (fun z -> v x `logand` v y = v z)) (** Bitwise logical exclusive-or *) val logxor (x:t) (y:t) : Pure t (requires True) (ensures (fun z -> v x `logxor` v y == v z)) (** Bitwise logical disjunction *) val logor (x:t) (y:t) : Pure t (requires True) (ensures (fun z -> v x `logor` v y == v z)) (** Bitwise logical negation *) val lognot (x:t) : Pure t (requires True) (ensures (fun z -> lognot (v x) == v z)) (**** Shift operators *) (** Shift right with zero fill, shifting at most the integer width *) val shift_right (a:t) (s:UInt32.t) : Pure t (requires (UInt32.v s < n)) (ensures (fun c -> FStar.UInt.shift_right (v a) (UInt32.v s) = v c)) (** Shift left with zero fill, shifting at most the integer width *) val shift_left (a:t) (s:UInt32.t) : Pure t (requires (UInt32.v s < n)) (ensures (fun c -> FStar.UInt.shift_left (v a) (UInt32.v s) = v c)) (**** Comparison operators *) (** Equality Note, it is safe to also use the polymorphic decidable equality operator [=] *) let eq (a:t) (b:t) : Tot bool = eq #n (v a) (v b) (** Greater than *) let gt (a:t) (b:t) : Tot bool = gt #n (v a) (v b) (** Greater than or equal *) let gte (a:t) (b:t) : Tot bool = gte #n (v a) (v b) (** Less than *) let lt (a:t) (b:t) : Tot bool = lt #n (v a) (v b) (** Less than or equal *) let lte (a:t) (b:t) : Tot bool = lte #n (v a) (v b) (** Unary negation *) inline_for_extraction let minus (a:t) = add_mod (lognot a) (uint_to_t 1) (** The maximum shift value for this type, i.e. its width minus one, as an UInt32. *) inline_for_extraction let n_minus_one = UInt32.uint_to_t (n - 1) #set-options "--z3rlimit 80 --initial_fuel 1 --max_fuel 1" (** A constant-time way to compute the equality of two machine integers. With inspiration from https://git.zx2c4.com/WireGuard/commit/src/crypto/curve25519-hacl64.h?id=2e60bb395c1f589a398ec606d611132ef9ef764b Note, the branching on [a=b] is just for proof-purposes. *) [@ CNoInline ] let eq_mask (a:t) (b:t) : Pure t (requires True) (ensures (fun c -> (v a = v b ==> v c = pow2 n - 1) /\ (v a <> v b ==> v c = 0))) = let x = logxor a b in let minus_x = minus x in let x_or_minus_x = logor x minus_x in let xnx = shift_right x_or_minus_x n_minus_one in let c = sub_mod xnx (uint_to_t 1) in if a = b then begin logxor_self (v a); lognot_lemma_1 #n; logor_lemma_1 (v x); assert (v x = 0 /\ v minus_x = 0 /\ v x_or_minus_x = 0 /\ v xnx = 0); assert (v c = ones n) end else begin logxor_neq_nonzero (v a) (v b); lemma_msb_pow2 #n (v (lognot x)); lemma_msb_pow2 #n (v minus_x); lemma_minus_zero #n (v x); assert (v c = FStar.UInt.zero n) end; c private val lemma_sub_msbs (a:t) (b:t) : Lemma ((msb (v a) = msb (v b)) ==> (v a < v b <==> msb (v (sub_mod a b)))) (** A constant-time way to compute the [>=] inequality of two machine integers. With inspiration from https://git.zx2c4.com/WireGuard/commit/src/crypto/curve25519-hacl64.h?id=0a483a9b431d87eca1b275463c632f8d5551978a *) [@ CNoInline ] let gte_mask (a:t) (b:t) : Pure t (requires True) (ensures (fun c -> (v a >= v b ==> v c = pow2 n - 1) /\ (v a < v b ==> v c = 0))) = let x = a in let y = b in let x_xor_y = logxor x y in let x_sub_y = sub_mod x y in let x_sub_y_xor_y = logxor x_sub_y y in let q = logor x_xor_y x_sub_y_xor_y in let x_xor_q = logxor x q in let x_xor_q_ = shift_right x_xor_q n_minus_one in let c = sub_mod x_xor_q_ (uint_to_t 1) in lemma_sub_msbs x y; lemma_msb_gte (v x) (v y); lemma_msb_gte (v y) (v x); c #reset-options (*** Infix notations *) unfold let op_Plus_Hat = add
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.UInt32.fsti.checked", "FStar.UInt.fsti.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked" ], "interface_file": false, "source_file": "FStar.UInt64.fsti" }
[ { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.UInt", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.UInt", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "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: FStar.UInt64.t -> b: FStar.UInt64.t -> Prims.Pure FStar.UInt64.t
Prims.Pure
[]
[]
[ "FStar.UInt64.add_mod" ]
[]
false
false
false
false
false
let op_Plus_Percent_Hat =
add_mod
false
FStar.UInt64.fsti
FStar.UInt64.op_Subtraction_Question_Hat
val op_Subtraction_Question_Hat : a: FStar.UInt64.t -> b: FStar.UInt64.t -> Prims.Pure FStar.UInt64.t
let op_Subtraction_Question_Hat = sub_underspec
{ "file_name": "ulib/FStar.UInt64.fsti", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 54, "end_line": 320, "start_col": 7, "start_line": 320 }
(* 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 FStar.UInt64 (**** THIS MODULE IS GENERATED AUTOMATICALLY USING [mk_int.sh], DO NOT EDIT DIRECTLY ****) unfold let n = 64 /// For FStar.UIntN.fstp: anything that you fix/update here should be /// reflected in [FStar.IntN.fstp], which is mostly a copy-paste of /// this module. /// /// Except, as compared to [FStar.IntN.fstp], here: /// - every occurrence of [int_t] has been replaced with [uint_t] /// - every occurrence of [@%] has been replaced with [%]. /// - some functions (e.g., add_underspec, etc.) are only defined here, not on signed integers /// This module provides an abstract type for machine integers of a /// given signedness and width. The interface is designed to be safe /// with respect to arithmetic underflow and overflow. /// Note, we have attempted several times to re-design this module to /// make it more amenable to normalization and to impose less overhead /// on the SMT solver when reasoning about machine integer /// arithmetic. The following github issue reports on the current /// status of that work. /// /// https://github.com/FStarLang/FStar/issues/1757 open FStar.UInt open FStar.Mul #set-options "--max_fuel 0 --max_ifuel 0" (** Abstract type of machine integers, with an underlying representation using a bounded mathematical integer *) new val t : eqtype (** A coercion that projects a bounded mathematical integer from a machine integer *) val v (x:t) : Tot (uint_t n) (** A coercion that injects a bounded mathematical integers into a machine integer *) val uint_to_t (x:uint_t n) : Pure t (requires True) (ensures (fun y -> v y = x)) (** Injection/projection inverse *) val uv_inv (x : t) : Lemma (ensures (uint_to_t (v x) == x)) [SMTPat (v x)] (** Projection/injection inverse *) val vu_inv (x : uint_t n) : Lemma (ensures (v (uint_to_t x) == x)) [SMTPat (uint_to_t x)] (** An alternate form of the injectivity of the [v] projection *) val v_inj (x1 x2: t): Lemma (requires (v x1 == v x2)) (ensures (x1 == x2)) (** Constants 0 and 1 *) val zero : x:t{v x = 0} val one : x:t{v x = 1} (**** Addition primitives *) (** Bounds-respecting addition The precondition enforces that the sum does not overflow, expressing the bound as an addition on mathematical integers *) val add (a:t) (b:t) : Pure t (requires (size (v a + v b) n)) (ensures (fun c -> v a + v b = v c)) (** Underspecified, possibly overflowing addition: The postcondition only enures that the result is the sum of the arguments in case there is no overflow *) val add_underspec (a:t) (b:t) : Pure t (requires True) (ensures (fun c -> size (v a + v b) n ==> v a + v b = v c)) (** Addition modulo [2^n] Machine integers can always be added, but the postcondition is now in terms of addition modulo [2^n] on mathematical integers *) val add_mod (a:t) (b:t) : Pure t (requires True) (ensures (fun c -> FStar.UInt.add_mod (v a) (v b) = v c)) (**** Subtraction primitives *) (** Bounds-respecting subtraction The precondition enforces that the difference does not underflow, expressing the bound as a difference on mathematical integers *) val sub (a:t) (b:t) : Pure t (requires (size (v a - v b) n)) (ensures (fun c -> v a - v b = v c)) (** Underspecified, possibly overflowing subtraction: The postcondition only enures that the result is the difference of the arguments in case there is no underflow *) val sub_underspec (a:t) (b:t) : Pure t (requires True) (ensures (fun c -> size (v a - v b) n ==> v a - v b = v c)) (** Subtraction modulo [2^n] Machine integers can always be subtractd, but the postcondition is now in terms of subtraction modulo [2^n] on mathematical integers *) val sub_mod (a:t) (b:t) : Pure t (requires True) (ensures (fun c -> FStar.UInt.sub_mod (v a) (v b) = v c)) (**** Multiplication primitives *) (** Bounds-respecting multiplication The precondition enforces that the product does not overflow, expressing the bound as a product on mathematical integers *) val mul (a:t) (b:t) : Pure t (requires (size (v a * v b) n)) (ensures (fun c -> v a * v b = v c)) (** Underspecified, possibly overflowing product The postcondition only enures that the result is the product of the arguments in case there is no overflow *) val mul_underspec (a:t) (b:t) : Pure t (requires True) (ensures (fun c -> size (v a * v b) n ==> v a * v b = v c)) (** Multiplication modulo [2^n] Machine integers can always be multiplied, but the postcondition is now in terms of product modulo [2^n] on mathematical integers *) val mul_mod (a:t) (b:t) : Pure t (requires True) (ensures (fun c -> FStar.UInt.mul_mod (v a) (v b) = v c)) (**** Division primitives *) (** Euclidean division of [a] and [b], with [b] non-zero *) val div (a:t) (b:t{v b <> 0}) : Pure t (requires (True)) (ensures (fun c -> v a / v b = v c)) (**** Modulo primitives *) (** Euclidean remainder The result is the modulus of [a] with respect to a non-zero [b] *) val rem (a:t) (b:t{v b <> 0}) : Pure t (requires True) (ensures (fun c -> FStar.UInt.mod (v a) (v b) = v c)) (**** Bitwise operators *) /// Also see FStar.BV (** Bitwise logical conjunction *) val logand (x:t) (y:t) : Pure t (requires True) (ensures (fun z -> v x `logand` v y = v z)) (** Bitwise logical exclusive-or *) val logxor (x:t) (y:t) : Pure t (requires True) (ensures (fun z -> v x `logxor` v y == v z)) (** Bitwise logical disjunction *) val logor (x:t) (y:t) : Pure t (requires True) (ensures (fun z -> v x `logor` v y == v z)) (** Bitwise logical negation *) val lognot (x:t) : Pure t (requires True) (ensures (fun z -> lognot (v x) == v z)) (**** Shift operators *) (** Shift right with zero fill, shifting at most the integer width *) val shift_right (a:t) (s:UInt32.t) : Pure t (requires (UInt32.v s < n)) (ensures (fun c -> FStar.UInt.shift_right (v a) (UInt32.v s) = v c)) (** Shift left with zero fill, shifting at most the integer width *) val shift_left (a:t) (s:UInt32.t) : Pure t (requires (UInt32.v s < n)) (ensures (fun c -> FStar.UInt.shift_left (v a) (UInt32.v s) = v c)) (**** Comparison operators *) (** Equality Note, it is safe to also use the polymorphic decidable equality operator [=] *) let eq (a:t) (b:t) : Tot bool = eq #n (v a) (v b) (** Greater than *) let gt (a:t) (b:t) : Tot bool = gt #n (v a) (v b) (** Greater than or equal *) let gte (a:t) (b:t) : Tot bool = gte #n (v a) (v b) (** Less than *) let lt (a:t) (b:t) : Tot bool = lt #n (v a) (v b) (** Less than or equal *) let lte (a:t) (b:t) : Tot bool = lte #n (v a) (v b) (** Unary negation *) inline_for_extraction let minus (a:t) = add_mod (lognot a) (uint_to_t 1) (** The maximum shift value for this type, i.e. its width minus one, as an UInt32. *) inline_for_extraction let n_minus_one = UInt32.uint_to_t (n - 1) #set-options "--z3rlimit 80 --initial_fuel 1 --max_fuel 1" (** A constant-time way to compute the equality of two machine integers. With inspiration from https://git.zx2c4.com/WireGuard/commit/src/crypto/curve25519-hacl64.h?id=2e60bb395c1f589a398ec606d611132ef9ef764b Note, the branching on [a=b] is just for proof-purposes. *) [@ CNoInline ] let eq_mask (a:t) (b:t) : Pure t (requires True) (ensures (fun c -> (v a = v b ==> v c = pow2 n - 1) /\ (v a <> v b ==> v c = 0))) = let x = logxor a b in let minus_x = minus x in let x_or_minus_x = logor x minus_x in let xnx = shift_right x_or_minus_x n_minus_one in let c = sub_mod xnx (uint_to_t 1) in if a = b then begin logxor_self (v a); lognot_lemma_1 #n; logor_lemma_1 (v x); assert (v x = 0 /\ v minus_x = 0 /\ v x_or_minus_x = 0 /\ v xnx = 0); assert (v c = ones n) end else begin logxor_neq_nonzero (v a) (v b); lemma_msb_pow2 #n (v (lognot x)); lemma_msb_pow2 #n (v minus_x); lemma_minus_zero #n (v x); assert (v c = FStar.UInt.zero n) end; c private val lemma_sub_msbs (a:t) (b:t) : Lemma ((msb (v a) = msb (v b)) ==> (v a < v b <==> msb (v (sub_mod a b)))) (** A constant-time way to compute the [>=] inequality of two machine integers. With inspiration from https://git.zx2c4.com/WireGuard/commit/src/crypto/curve25519-hacl64.h?id=0a483a9b431d87eca1b275463c632f8d5551978a *) [@ CNoInline ] let gte_mask (a:t) (b:t) : Pure t (requires True) (ensures (fun c -> (v a >= v b ==> v c = pow2 n - 1) /\ (v a < v b ==> v c = 0))) = let x = a in let y = b in let x_xor_y = logxor x y in let x_sub_y = sub_mod x y in let x_sub_y_xor_y = logxor x_sub_y y in let q = logor x_xor_y x_sub_y_xor_y in let x_xor_q = logxor x q in let x_xor_q_ = shift_right x_xor_q n_minus_one in let c = sub_mod x_xor_q_ (uint_to_t 1) in lemma_sub_msbs x y; lemma_msb_gte (v x) (v y); lemma_msb_gte (v y) (v x); c #reset-options (*** Infix notations *) unfold let op_Plus_Hat = add unfold let op_Plus_Question_Hat = add_underspec unfold let op_Plus_Percent_Hat = add_mod
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.UInt32.fsti.checked", "FStar.UInt.fsti.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked" ], "interface_file": false, "source_file": "FStar.UInt64.fsti" }
[ { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.UInt", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.UInt", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "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: FStar.UInt64.t -> b: FStar.UInt64.t -> Prims.Pure FStar.UInt64.t
Prims.Pure
[]
[]
[ "FStar.UInt64.sub_underspec" ]
[]
false
false
false
false
false
let op_Subtraction_Question_Hat =
sub_underspec
false
FStar.UInt64.fsti
FStar.UInt64.op_Star_Question_Hat
val op_Star_Question_Hat : a: FStar.UInt64.t -> b: FStar.UInt64.t -> Prims.Pure FStar.UInt64.t
let op_Star_Question_Hat = mul_underspec
{ "file_name": "ulib/FStar.UInt64.fsti", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 47, "end_line": 323, "start_col": 7, "start_line": 323 }
(* 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 FStar.UInt64 (**** THIS MODULE IS GENERATED AUTOMATICALLY USING [mk_int.sh], DO NOT EDIT DIRECTLY ****) unfold let n = 64 /// For FStar.UIntN.fstp: anything that you fix/update here should be /// reflected in [FStar.IntN.fstp], which is mostly a copy-paste of /// this module. /// /// Except, as compared to [FStar.IntN.fstp], here: /// - every occurrence of [int_t] has been replaced with [uint_t] /// - every occurrence of [@%] has been replaced with [%]. /// - some functions (e.g., add_underspec, etc.) are only defined here, not on signed integers /// This module provides an abstract type for machine integers of a /// given signedness and width. The interface is designed to be safe /// with respect to arithmetic underflow and overflow. /// Note, we have attempted several times to re-design this module to /// make it more amenable to normalization and to impose less overhead /// on the SMT solver when reasoning about machine integer /// arithmetic. The following github issue reports on the current /// status of that work. /// /// https://github.com/FStarLang/FStar/issues/1757 open FStar.UInt open FStar.Mul #set-options "--max_fuel 0 --max_ifuel 0" (** Abstract type of machine integers, with an underlying representation using a bounded mathematical integer *) new val t : eqtype (** A coercion that projects a bounded mathematical integer from a machine integer *) val v (x:t) : Tot (uint_t n) (** A coercion that injects a bounded mathematical integers into a machine integer *) val uint_to_t (x:uint_t n) : Pure t (requires True) (ensures (fun y -> v y = x)) (** Injection/projection inverse *) val uv_inv (x : t) : Lemma (ensures (uint_to_t (v x) == x)) [SMTPat (v x)] (** Projection/injection inverse *) val vu_inv (x : uint_t n) : Lemma (ensures (v (uint_to_t x) == x)) [SMTPat (uint_to_t x)] (** An alternate form of the injectivity of the [v] projection *) val v_inj (x1 x2: t): Lemma (requires (v x1 == v x2)) (ensures (x1 == x2)) (** Constants 0 and 1 *) val zero : x:t{v x = 0} val one : x:t{v x = 1} (**** Addition primitives *) (** Bounds-respecting addition The precondition enforces that the sum does not overflow, expressing the bound as an addition on mathematical integers *) val add (a:t) (b:t) : Pure t (requires (size (v a + v b) n)) (ensures (fun c -> v a + v b = v c)) (** Underspecified, possibly overflowing addition: The postcondition only enures that the result is the sum of the arguments in case there is no overflow *) val add_underspec (a:t) (b:t) : Pure t (requires True) (ensures (fun c -> size (v a + v b) n ==> v a + v b = v c)) (** Addition modulo [2^n] Machine integers can always be added, but the postcondition is now in terms of addition modulo [2^n] on mathematical integers *) val add_mod (a:t) (b:t) : Pure t (requires True) (ensures (fun c -> FStar.UInt.add_mod (v a) (v b) = v c)) (**** Subtraction primitives *) (** Bounds-respecting subtraction The precondition enforces that the difference does not underflow, expressing the bound as a difference on mathematical integers *) val sub (a:t) (b:t) : Pure t (requires (size (v a - v b) n)) (ensures (fun c -> v a - v b = v c)) (** Underspecified, possibly overflowing subtraction: The postcondition only enures that the result is the difference of the arguments in case there is no underflow *) val sub_underspec (a:t) (b:t) : Pure t (requires True) (ensures (fun c -> size (v a - v b) n ==> v a - v b = v c)) (** Subtraction modulo [2^n] Machine integers can always be subtractd, but the postcondition is now in terms of subtraction modulo [2^n] on mathematical integers *) val sub_mod (a:t) (b:t) : Pure t (requires True) (ensures (fun c -> FStar.UInt.sub_mod (v a) (v b) = v c)) (**** Multiplication primitives *) (** Bounds-respecting multiplication The precondition enforces that the product does not overflow, expressing the bound as a product on mathematical integers *) val mul (a:t) (b:t) : Pure t (requires (size (v a * v b) n)) (ensures (fun c -> v a * v b = v c)) (** Underspecified, possibly overflowing product The postcondition only enures that the result is the product of the arguments in case there is no overflow *) val mul_underspec (a:t) (b:t) : Pure t (requires True) (ensures (fun c -> size (v a * v b) n ==> v a * v b = v c)) (** Multiplication modulo [2^n] Machine integers can always be multiplied, but the postcondition is now in terms of product modulo [2^n] on mathematical integers *) val mul_mod (a:t) (b:t) : Pure t (requires True) (ensures (fun c -> FStar.UInt.mul_mod (v a) (v b) = v c)) (**** Division primitives *) (** Euclidean division of [a] and [b], with [b] non-zero *) val div (a:t) (b:t{v b <> 0}) : Pure t (requires (True)) (ensures (fun c -> v a / v b = v c)) (**** Modulo primitives *) (** Euclidean remainder The result is the modulus of [a] with respect to a non-zero [b] *) val rem (a:t) (b:t{v b <> 0}) : Pure t (requires True) (ensures (fun c -> FStar.UInt.mod (v a) (v b) = v c)) (**** Bitwise operators *) /// Also see FStar.BV (** Bitwise logical conjunction *) val logand (x:t) (y:t) : Pure t (requires True) (ensures (fun z -> v x `logand` v y = v z)) (** Bitwise logical exclusive-or *) val logxor (x:t) (y:t) : Pure t (requires True) (ensures (fun z -> v x `logxor` v y == v z)) (** Bitwise logical disjunction *) val logor (x:t) (y:t) : Pure t (requires True) (ensures (fun z -> v x `logor` v y == v z)) (** Bitwise logical negation *) val lognot (x:t) : Pure t (requires True) (ensures (fun z -> lognot (v x) == v z)) (**** Shift operators *) (** Shift right with zero fill, shifting at most the integer width *) val shift_right (a:t) (s:UInt32.t) : Pure t (requires (UInt32.v s < n)) (ensures (fun c -> FStar.UInt.shift_right (v a) (UInt32.v s) = v c)) (** Shift left with zero fill, shifting at most the integer width *) val shift_left (a:t) (s:UInt32.t) : Pure t (requires (UInt32.v s < n)) (ensures (fun c -> FStar.UInt.shift_left (v a) (UInt32.v s) = v c)) (**** Comparison operators *) (** Equality Note, it is safe to also use the polymorphic decidable equality operator [=] *) let eq (a:t) (b:t) : Tot bool = eq #n (v a) (v b) (** Greater than *) let gt (a:t) (b:t) : Tot bool = gt #n (v a) (v b) (** Greater than or equal *) let gte (a:t) (b:t) : Tot bool = gte #n (v a) (v b) (** Less than *) let lt (a:t) (b:t) : Tot bool = lt #n (v a) (v b) (** Less than or equal *) let lte (a:t) (b:t) : Tot bool = lte #n (v a) (v b) (** Unary negation *) inline_for_extraction let minus (a:t) = add_mod (lognot a) (uint_to_t 1) (** The maximum shift value for this type, i.e. its width minus one, as an UInt32. *) inline_for_extraction let n_minus_one = UInt32.uint_to_t (n - 1) #set-options "--z3rlimit 80 --initial_fuel 1 --max_fuel 1" (** A constant-time way to compute the equality of two machine integers. With inspiration from https://git.zx2c4.com/WireGuard/commit/src/crypto/curve25519-hacl64.h?id=2e60bb395c1f589a398ec606d611132ef9ef764b Note, the branching on [a=b] is just for proof-purposes. *) [@ CNoInline ] let eq_mask (a:t) (b:t) : Pure t (requires True) (ensures (fun c -> (v a = v b ==> v c = pow2 n - 1) /\ (v a <> v b ==> v c = 0))) = let x = logxor a b in let minus_x = minus x in let x_or_minus_x = logor x minus_x in let xnx = shift_right x_or_minus_x n_minus_one in let c = sub_mod xnx (uint_to_t 1) in if a = b then begin logxor_self (v a); lognot_lemma_1 #n; logor_lemma_1 (v x); assert (v x = 0 /\ v minus_x = 0 /\ v x_or_minus_x = 0 /\ v xnx = 0); assert (v c = ones n) end else begin logxor_neq_nonzero (v a) (v b); lemma_msb_pow2 #n (v (lognot x)); lemma_msb_pow2 #n (v minus_x); lemma_minus_zero #n (v x); assert (v c = FStar.UInt.zero n) end; c private val lemma_sub_msbs (a:t) (b:t) : Lemma ((msb (v a) = msb (v b)) ==> (v a < v b <==> msb (v (sub_mod a b)))) (** A constant-time way to compute the [>=] inequality of two machine integers. With inspiration from https://git.zx2c4.com/WireGuard/commit/src/crypto/curve25519-hacl64.h?id=0a483a9b431d87eca1b275463c632f8d5551978a *) [@ CNoInline ] let gte_mask (a:t) (b:t) : Pure t (requires True) (ensures (fun c -> (v a >= v b ==> v c = pow2 n - 1) /\ (v a < v b ==> v c = 0))) = let x = a in let y = b in let x_xor_y = logxor x y in let x_sub_y = sub_mod x y in let x_sub_y_xor_y = logxor x_sub_y y in let q = logor x_xor_y x_sub_y_xor_y in let x_xor_q = logxor x q in let x_xor_q_ = shift_right x_xor_q n_minus_one in let c = sub_mod x_xor_q_ (uint_to_t 1) in lemma_sub_msbs x y; lemma_msb_gte (v x) (v y); lemma_msb_gte (v y) (v x); c #reset-options (*** Infix notations *) unfold let op_Plus_Hat = add unfold let op_Plus_Question_Hat = add_underspec unfold let op_Plus_Percent_Hat = add_mod unfold let op_Subtraction_Hat = sub unfold let op_Subtraction_Question_Hat = sub_underspec unfold let op_Subtraction_Percent_Hat = sub_mod
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.UInt32.fsti.checked", "FStar.UInt.fsti.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked" ], "interface_file": false, "source_file": "FStar.UInt64.fsti" }
[ { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.UInt", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.UInt", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "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: FStar.UInt64.t -> b: FStar.UInt64.t -> Prims.Pure FStar.UInt64.t
Prims.Pure
[]
[]
[ "FStar.UInt64.mul_underspec" ]
[]
false
false
false
false
false
let op_Star_Question_Hat =
mul_underspec
false
FStar.UInt64.fsti
FStar.UInt64.op_Star_Hat
val op_Star_Hat : a: FStar.UInt64.t -> b: FStar.UInt64.t -> Prims.Pure FStar.UInt64.t
let op_Star_Hat = mul
{ "file_name": "ulib/FStar.UInt64.fsti", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 28, "end_line": 322, "start_col": 7, "start_line": 322 }
(* 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 FStar.UInt64 (**** THIS MODULE IS GENERATED AUTOMATICALLY USING [mk_int.sh], DO NOT EDIT DIRECTLY ****) unfold let n = 64 /// For FStar.UIntN.fstp: anything that you fix/update here should be /// reflected in [FStar.IntN.fstp], which is mostly a copy-paste of /// this module. /// /// Except, as compared to [FStar.IntN.fstp], here: /// - every occurrence of [int_t] has been replaced with [uint_t] /// - every occurrence of [@%] has been replaced with [%]. /// - some functions (e.g., add_underspec, etc.) are only defined here, not on signed integers /// This module provides an abstract type for machine integers of a /// given signedness and width. The interface is designed to be safe /// with respect to arithmetic underflow and overflow. /// Note, we have attempted several times to re-design this module to /// make it more amenable to normalization and to impose less overhead /// on the SMT solver when reasoning about machine integer /// arithmetic. The following github issue reports on the current /// status of that work. /// /// https://github.com/FStarLang/FStar/issues/1757 open FStar.UInt open FStar.Mul #set-options "--max_fuel 0 --max_ifuel 0" (** Abstract type of machine integers, with an underlying representation using a bounded mathematical integer *) new val t : eqtype (** A coercion that projects a bounded mathematical integer from a machine integer *) val v (x:t) : Tot (uint_t n) (** A coercion that injects a bounded mathematical integers into a machine integer *) val uint_to_t (x:uint_t n) : Pure t (requires True) (ensures (fun y -> v y = x)) (** Injection/projection inverse *) val uv_inv (x : t) : Lemma (ensures (uint_to_t (v x) == x)) [SMTPat (v x)] (** Projection/injection inverse *) val vu_inv (x : uint_t n) : Lemma (ensures (v (uint_to_t x) == x)) [SMTPat (uint_to_t x)] (** An alternate form of the injectivity of the [v] projection *) val v_inj (x1 x2: t): Lemma (requires (v x1 == v x2)) (ensures (x1 == x2)) (** Constants 0 and 1 *) val zero : x:t{v x = 0} val one : x:t{v x = 1} (**** Addition primitives *) (** Bounds-respecting addition The precondition enforces that the sum does not overflow, expressing the bound as an addition on mathematical integers *) val add (a:t) (b:t) : Pure t (requires (size (v a + v b) n)) (ensures (fun c -> v a + v b = v c)) (** Underspecified, possibly overflowing addition: The postcondition only enures that the result is the sum of the arguments in case there is no overflow *) val add_underspec (a:t) (b:t) : Pure t (requires True) (ensures (fun c -> size (v a + v b) n ==> v a + v b = v c)) (** Addition modulo [2^n] Machine integers can always be added, but the postcondition is now in terms of addition modulo [2^n] on mathematical integers *) val add_mod (a:t) (b:t) : Pure t (requires True) (ensures (fun c -> FStar.UInt.add_mod (v a) (v b) = v c)) (**** Subtraction primitives *) (** Bounds-respecting subtraction The precondition enforces that the difference does not underflow, expressing the bound as a difference on mathematical integers *) val sub (a:t) (b:t) : Pure t (requires (size (v a - v b) n)) (ensures (fun c -> v a - v b = v c)) (** Underspecified, possibly overflowing subtraction: The postcondition only enures that the result is the difference of the arguments in case there is no underflow *) val sub_underspec (a:t) (b:t) : Pure t (requires True) (ensures (fun c -> size (v a - v b) n ==> v a - v b = v c)) (** Subtraction modulo [2^n] Machine integers can always be subtractd, but the postcondition is now in terms of subtraction modulo [2^n] on mathematical integers *) val sub_mod (a:t) (b:t) : Pure t (requires True) (ensures (fun c -> FStar.UInt.sub_mod (v a) (v b) = v c)) (**** Multiplication primitives *) (** Bounds-respecting multiplication The precondition enforces that the product does not overflow, expressing the bound as a product on mathematical integers *) val mul (a:t) (b:t) : Pure t (requires (size (v a * v b) n)) (ensures (fun c -> v a * v b = v c)) (** Underspecified, possibly overflowing product The postcondition only enures that the result is the product of the arguments in case there is no overflow *) val mul_underspec (a:t) (b:t) : Pure t (requires True) (ensures (fun c -> size (v a * v b) n ==> v a * v b = v c)) (** Multiplication modulo [2^n] Machine integers can always be multiplied, but the postcondition is now in terms of product modulo [2^n] on mathematical integers *) val mul_mod (a:t) (b:t) : Pure t (requires True) (ensures (fun c -> FStar.UInt.mul_mod (v a) (v b) = v c)) (**** Division primitives *) (** Euclidean division of [a] and [b], with [b] non-zero *) val div (a:t) (b:t{v b <> 0}) : Pure t (requires (True)) (ensures (fun c -> v a / v b = v c)) (**** Modulo primitives *) (** Euclidean remainder The result is the modulus of [a] with respect to a non-zero [b] *) val rem (a:t) (b:t{v b <> 0}) : Pure t (requires True) (ensures (fun c -> FStar.UInt.mod (v a) (v b) = v c)) (**** Bitwise operators *) /// Also see FStar.BV (** Bitwise logical conjunction *) val logand (x:t) (y:t) : Pure t (requires True) (ensures (fun z -> v x `logand` v y = v z)) (** Bitwise logical exclusive-or *) val logxor (x:t) (y:t) : Pure t (requires True) (ensures (fun z -> v x `logxor` v y == v z)) (** Bitwise logical disjunction *) val logor (x:t) (y:t) : Pure t (requires True) (ensures (fun z -> v x `logor` v y == v z)) (** Bitwise logical negation *) val lognot (x:t) : Pure t (requires True) (ensures (fun z -> lognot (v x) == v z)) (**** Shift operators *) (** Shift right with zero fill, shifting at most the integer width *) val shift_right (a:t) (s:UInt32.t) : Pure t (requires (UInt32.v s < n)) (ensures (fun c -> FStar.UInt.shift_right (v a) (UInt32.v s) = v c)) (** Shift left with zero fill, shifting at most the integer width *) val shift_left (a:t) (s:UInt32.t) : Pure t (requires (UInt32.v s < n)) (ensures (fun c -> FStar.UInt.shift_left (v a) (UInt32.v s) = v c)) (**** Comparison operators *) (** Equality Note, it is safe to also use the polymorphic decidable equality operator [=] *) let eq (a:t) (b:t) : Tot bool = eq #n (v a) (v b) (** Greater than *) let gt (a:t) (b:t) : Tot bool = gt #n (v a) (v b) (** Greater than or equal *) let gte (a:t) (b:t) : Tot bool = gte #n (v a) (v b) (** Less than *) let lt (a:t) (b:t) : Tot bool = lt #n (v a) (v b) (** Less than or equal *) let lte (a:t) (b:t) : Tot bool = lte #n (v a) (v b) (** Unary negation *) inline_for_extraction let minus (a:t) = add_mod (lognot a) (uint_to_t 1) (** The maximum shift value for this type, i.e. its width minus one, as an UInt32. *) inline_for_extraction let n_minus_one = UInt32.uint_to_t (n - 1) #set-options "--z3rlimit 80 --initial_fuel 1 --max_fuel 1" (** A constant-time way to compute the equality of two machine integers. With inspiration from https://git.zx2c4.com/WireGuard/commit/src/crypto/curve25519-hacl64.h?id=2e60bb395c1f589a398ec606d611132ef9ef764b Note, the branching on [a=b] is just for proof-purposes. *) [@ CNoInline ] let eq_mask (a:t) (b:t) : Pure t (requires True) (ensures (fun c -> (v a = v b ==> v c = pow2 n - 1) /\ (v a <> v b ==> v c = 0))) = let x = logxor a b in let minus_x = minus x in let x_or_minus_x = logor x minus_x in let xnx = shift_right x_or_minus_x n_minus_one in let c = sub_mod xnx (uint_to_t 1) in if a = b then begin logxor_self (v a); lognot_lemma_1 #n; logor_lemma_1 (v x); assert (v x = 0 /\ v minus_x = 0 /\ v x_or_minus_x = 0 /\ v xnx = 0); assert (v c = ones n) end else begin logxor_neq_nonzero (v a) (v b); lemma_msb_pow2 #n (v (lognot x)); lemma_msb_pow2 #n (v minus_x); lemma_minus_zero #n (v x); assert (v c = FStar.UInt.zero n) end; c private val lemma_sub_msbs (a:t) (b:t) : Lemma ((msb (v a) = msb (v b)) ==> (v a < v b <==> msb (v (sub_mod a b)))) (** A constant-time way to compute the [>=] inequality of two machine integers. With inspiration from https://git.zx2c4.com/WireGuard/commit/src/crypto/curve25519-hacl64.h?id=0a483a9b431d87eca1b275463c632f8d5551978a *) [@ CNoInline ] let gte_mask (a:t) (b:t) : Pure t (requires True) (ensures (fun c -> (v a >= v b ==> v c = pow2 n - 1) /\ (v a < v b ==> v c = 0))) = let x = a in let y = b in let x_xor_y = logxor x y in let x_sub_y = sub_mod x y in let x_sub_y_xor_y = logxor x_sub_y y in let q = logor x_xor_y x_sub_y_xor_y in let x_xor_q = logxor x q in let x_xor_q_ = shift_right x_xor_q n_minus_one in let c = sub_mod x_xor_q_ (uint_to_t 1) in lemma_sub_msbs x y; lemma_msb_gte (v x) (v y); lemma_msb_gte (v y) (v x); c #reset-options (*** Infix notations *) unfold let op_Plus_Hat = add unfold let op_Plus_Question_Hat = add_underspec unfold let op_Plus_Percent_Hat = add_mod unfold let op_Subtraction_Hat = sub unfold let op_Subtraction_Question_Hat = sub_underspec
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.UInt32.fsti.checked", "FStar.UInt.fsti.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked" ], "interface_file": false, "source_file": "FStar.UInt64.fsti" }
[ { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.UInt", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.UInt", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "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: FStar.UInt64.t -> b: FStar.UInt64.t -> Prims.Pure FStar.UInt64.t
Prims.Pure
[]
[]
[ "FStar.UInt64.mul" ]
[]
false
false
false
false
false
let op_Star_Hat =
mul
false
LowParse.Low.BCVLI.fst
LowParse.Low.BCVLI.write_bcvli
val write_bcvli:leaf_writer_strong serialize_bcvli
val write_bcvli:leaf_writer_strong serialize_bcvli
let write_bcvli : leaf_writer_strong serialize_bcvli = leaf_writer_strong_of_serializer32 serialize32_bcvli ()
{ "file_name": "src/lowparse/LowParse.Low.BCVLI.fst", "git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
{ "end_col": 57, "end_line": 177, "start_col": 0, "start_line": 176 }
module LowParse.Low.BCVLI include LowParse.Spec.BCVLI include LowParse.Low.Combinators include LowParse.Low.BoundedInt module B = LowStar.Buffer module HST = FStar.HyperStack.ST module Cast = FStar.Int.Cast module U32 = FStar.UInt32 module U64 = FStar.UInt64 #reset-options "--z3cliopt smt.arith.nl=false --max_fuel 0" #push-options "--z3rlimit 16" let validate_bcvli : validator parse_bcvli = fun #rrel #rel input pos -> let h = HST.get () in [@inline_let] let _ = valid_facts parse_bcvli h input (uint64_to_uint32 pos); parse_bcvli_eq (bytes_of_slice_from h input (uint64_to_uint32 pos)); valid_facts (parse_bounded_integer_le 1) h input (uint64_to_uint32 pos) in let pos1 = validate_total_constant_size (parse_bounded_integer_le 1) 1uL () input pos in if is_error pos1 then pos1 else [@inline_let] let _ = valid_facts (parse_bounded_integer_le 2) h input (uint64_to_uint32 pos1); valid_facts (parse_bounded_integer_le 4) h input (uint64_to_uint32 pos1) in let r = read_bounded_integer_le_1 input (uint64_to_uint32 pos) in if r `U32.lt` 253ul then pos1 else if r = 253ul then let pos2 = validate_total_constant_size (parse_bounded_integer_le 2) 2uL () input pos1 in if is_error pos2 then pos2 else (* because of the non-malleability constraint, I need to actually read the value and check whether it is not a lower integer *) let r = read_bounded_integer_le_2 input (uint64_to_uint32 pos1) in if r `U32.lt` 253ul then validator_error_generic else pos2 else if r = 254ul then let pos2 = validate_total_constant_size (parse_bounded_integer_le 4) 4uL () input pos1 in if is_error pos2 then pos2 else (* because of the non-malleability constraint, I need to actually read the value and check whether it is not a lower integer *) let r = read_bounded_integer_le_4 input (uint64_to_uint32 pos1) in if r `U32.lt` 65536ul then validator_error_generic else pos2 else validator_error_generic let jump_bcvli : jumper parse_bcvli = fun #rrel #rel input pos -> let h = HST.get () in [@inline_let] let _ = valid_facts parse_bcvli h input pos; parse_bcvli_eq (bytes_of_slice_from h input pos); valid_facts (parse_bounded_integer_le 1) h input pos in let pos1 = jump_constant_size (parse_bounded_integer_le 1) 1ul () input pos in [@inline_let] let _ = valid_facts (parse_bounded_integer_le 2) h input pos1; valid_facts (parse_bounded_integer_le 4) h input pos1 in let r = read_bounded_integer_le_1 input pos in if r `U32.lt` 253ul then pos1 else if r = 253ul then jump_constant_size (parse_bounded_integer_le 2) 2ul () input pos1 else jump_constant_size (parse_bounded_integer_le 4) 4ul () input pos1 let read_bcvli : leaf_reader parse_bcvli = fun #rrel #rel input pos -> let h = HST.get () in [@inline_let] let _ = valid_facts parse_bcvli h input pos; parse_bcvli_eq (bytes_of_slice_from h input pos); valid_facts (parse_bounded_integer_le 1) h input pos in let r = read_bounded_integer_le_1 input pos in if r `U32.lt` 253ul then (r <: U32.t) else let pos1 = jump_constant_size (parse_bounded_integer_le 1) 1ul () input pos in [@inline_let] let _ = valid_facts (parse_bounded_integer_le 2) h input pos1; valid_facts (parse_bounded_integer_le 4) h input pos1 in if r = 253ul then read_bounded_integer_le_2 input pos1 <: U32.t else read_bounded_integer_le_4 input pos1 <: U32.t #pop-options module U8 = FStar.UInt8 #push-options "--z3rlimit 32" inline_for_extraction let serialize32_bcvli' (x: U32.t) (#rrel #rel: _) (b: B.mbuffer U8.t rrel rel) (pos: U32.t) : HST.Stack U32.t (requires (fun h -> let len = Seq.length (serialize serialize_bcvli x) in B.live h b /\ U32.v pos + len <= B.length b /\ writable b (U32.v pos) (U32.v pos + len) h )) (ensures (fun h len h' -> Seq.length (serialize serialize_bcvli x) == U32.v len /\ ( B.modifies (B.loc_buffer_from_to b pos (pos `U32.add` len)) h h' /\ B.live h b /\ Seq.slice (B.as_seq h' b) (U32.v pos) (U32.v pos + U32.v len) `Seq.equal` serialize serialize_bcvli x ))) = // [@inline_let] let _ = serialize_bcvli_eq x ; // in let c : bounded_integer 1 = if x `U32.lt` 253ul then x else if x `U32.lt` 65536ul then 253ul else 254ul in [@inline_let] let pos' = Ghost.hide (U32.v pos + Seq.length (serialize serialize_bcvli x)) in let h = HST.get () in [@inline_let] let _ = writable_weaken b (U32.v pos) (Ghost.reveal pos') h (U32.v pos) (U32.v pos + 1) in let len1 = serialize32_bounded_integer_le_1 c b pos in let h1 = HST.get () in [@inline_let] let _ = writable_modifies b (U32.v pos) (Ghost.reveal pos') h B.loc_none h1 in if c `U32.lt` 253ul then begin len1 end else if c = 253ul then begin [@inline_let] let _ = assert (U32.v x < 65536) in [@inline_let] let _ = writable_weaken b (U32.v pos) (Ghost.reveal pos') h1 (U32.v pos + U32.v len1) ((U32.v pos + U32.v len1) + 2) in let len2 = serialize32_bounded_integer_le_2 x b (pos `U32.add` len1) in let h' = HST.get () in [@inline_let] let len = len1 `U32.add` len2 in B.modifies_buffer_from_to_elim b pos (pos `U32.add` len1) (B.loc_buffer_from_to b (pos `U32.add` len1) (pos `U32.add` len)) h1 h'; len end else begin [@inline_let] let _ = writable_weaken b (U32.v pos) (Ghost.reveal pos') h1 (U32.v pos + U32.v len1) ((U32.v pos + U32.v len1) + 4) in let len2 = serialize32_bounded_integer_le_4 x b (pos `U32.add` len1) in let h' = HST.get () in [@inline_let] let len = len1 `U32.add` len2 in B.modifies_buffer_from_to_elim b pos (pos `U32.add` len1) (B.loc_buffer_from_to b (pos `U32.add` len1) (pos `U32.add` len)) h1 h'; len end inline_for_extraction let serialize32_bcvli : serializer32 serialize_bcvli = fun (x: U32.t) #rrel #rel b pos -> serialize32_bcvli' x b pos
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowStar.Buffer.fst.checked", "LowParse.Spec.BCVLI.fsti.checked", "LowParse.Low.Combinators.fsti.checked", "LowParse.Low.BoundedInt.fsti.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.Ghost.fsti.checked" ], "interface_file": false, "source_file": "LowParse.Low.BCVLI.fst" }
[ { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": true, "full_module": "FStar.Int.Cast", "short_module": "Cast" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": false, "full_module": "LowParse.Low.BoundedInt", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low.Combinators", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec.BCVLI", "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": 0, "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": [ "smt.arith.nl=false" ], "z3refresh": false, "z3rlimit": 32, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
LowParse.Low.Base.leaf_writer_strong LowParse.Spec.BCVLI.serialize_bcvli
Prims.Tot
[ "total" ]
[]
[ "LowParse.Low.Base.leaf_writer_strong_of_serializer32", "LowParse.Spec.BCVLI.parse_bcvli_kind", "FStar.UInt32.t", "LowParse.Spec.BCVLI.parse_bcvli", "LowParse.Spec.BCVLI.serialize_bcvli", "LowParse.Low.BCVLI.serialize32_bcvli" ]
[]
false
false
false
true
false
let write_bcvli:leaf_writer_strong serialize_bcvli =
leaf_writer_strong_of_serializer32 serialize32_bcvli ()
false
FStar.UInt64.fsti
FStar.UInt64.op_Less_Less_Hat
val op_Less_Less_Hat : a: FStar.UInt64.t -> s: FStar.UInt32.t -> Prims.Pure FStar.UInt64.t
let op_Less_Less_Hat = shift_left
{ "file_name": "ulib/FStar.UInt64.fsti", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 40, "end_line": 330, "start_col": 7, "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 FStar.UInt64 (**** THIS MODULE IS GENERATED AUTOMATICALLY USING [mk_int.sh], DO NOT EDIT DIRECTLY ****) unfold let n = 64 /// For FStar.UIntN.fstp: anything that you fix/update here should be /// reflected in [FStar.IntN.fstp], which is mostly a copy-paste of /// this module. /// /// Except, as compared to [FStar.IntN.fstp], here: /// - every occurrence of [int_t] has been replaced with [uint_t] /// - every occurrence of [@%] has been replaced with [%]. /// - some functions (e.g., add_underspec, etc.) are only defined here, not on signed integers /// This module provides an abstract type for machine integers of a /// given signedness and width. The interface is designed to be safe /// with respect to arithmetic underflow and overflow. /// Note, we have attempted several times to re-design this module to /// make it more amenable to normalization and to impose less overhead /// on the SMT solver when reasoning about machine integer /// arithmetic. The following github issue reports on the current /// status of that work. /// /// https://github.com/FStarLang/FStar/issues/1757 open FStar.UInt open FStar.Mul #set-options "--max_fuel 0 --max_ifuel 0" (** Abstract type of machine integers, with an underlying representation using a bounded mathematical integer *) new val t : eqtype (** A coercion that projects a bounded mathematical integer from a machine integer *) val v (x:t) : Tot (uint_t n) (** A coercion that injects a bounded mathematical integers into a machine integer *) val uint_to_t (x:uint_t n) : Pure t (requires True) (ensures (fun y -> v y = x)) (** Injection/projection inverse *) val uv_inv (x : t) : Lemma (ensures (uint_to_t (v x) == x)) [SMTPat (v x)] (** Projection/injection inverse *) val vu_inv (x : uint_t n) : Lemma (ensures (v (uint_to_t x) == x)) [SMTPat (uint_to_t x)] (** An alternate form of the injectivity of the [v] projection *) val v_inj (x1 x2: t): Lemma (requires (v x1 == v x2)) (ensures (x1 == x2)) (** Constants 0 and 1 *) val zero : x:t{v x = 0} val one : x:t{v x = 1} (**** Addition primitives *) (** Bounds-respecting addition The precondition enforces that the sum does not overflow, expressing the bound as an addition on mathematical integers *) val add (a:t) (b:t) : Pure t (requires (size (v a + v b) n)) (ensures (fun c -> v a + v b = v c)) (** Underspecified, possibly overflowing addition: The postcondition only enures that the result is the sum of the arguments in case there is no overflow *) val add_underspec (a:t) (b:t) : Pure t (requires True) (ensures (fun c -> size (v a + v b) n ==> v a + v b = v c)) (** Addition modulo [2^n] Machine integers can always be added, but the postcondition is now in terms of addition modulo [2^n] on mathematical integers *) val add_mod (a:t) (b:t) : Pure t (requires True) (ensures (fun c -> FStar.UInt.add_mod (v a) (v b) = v c)) (**** Subtraction primitives *) (** Bounds-respecting subtraction The precondition enforces that the difference does not underflow, expressing the bound as a difference on mathematical integers *) val sub (a:t) (b:t) : Pure t (requires (size (v a - v b) n)) (ensures (fun c -> v a - v b = v c)) (** Underspecified, possibly overflowing subtraction: The postcondition only enures that the result is the difference of the arguments in case there is no underflow *) val sub_underspec (a:t) (b:t) : Pure t (requires True) (ensures (fun c -> size (v a - v b) n ==> v a - v b = v c)) (** Subtraction modulo [2^n] Machine integers can always be subtractd, but the postcondition is now in terms of subtraction modulo [2^n] on mathematical integers *) val sub_mod (a:t) (b:t) : Pure t (requires True) (ensures (fun c -> FStar.UInt.sub_mod (v a) (v b) = v c)) (**** Multiplication primitives *) (** Bounds-respecting multiplication The precondition enforces that the product does not overflow, expressing the bound as a product on mathematical integers *) val mul (a:t) (b:t) : Pure t (requires (size (v a * v b) n)) (ensures (fun c -> v a * v b = v c)) (** Underspecified, possibly overflowing product The postcondition only enures that the result is the product of the arguments in case there is no overflow *) val mul_underspec (a:t) (b:t) : Pure t (requires True) (ensures (fun c -> size (v a * v b) n ==> v a * v b = v c)) (** Multiplication modulo [2^n] Machine integers can always be multiplied, but the postcondition is now in terms of product modulo [2^n] on mathematical integers *) val mul_mod (a:t) (b:t) : Pure t (requires True) (ensures (fun c -> FStar.UInt.mul_mod (v a) (v b) = v c)) (**** Division primitives *) (** Euclidean division of [a] and [b], with [b] non-zero *) val div (a:t) (b:t{v b <> 0}) : Pure t (requires (True)) (ensures (fun c -> v a / v b = v c)) (**** Modulo primitives *) (** Euclidean remainder The result is the modulus of [a] with respect to a non-zero [b] *) val rem (a:t) (b:t{v b <> 0}) : Pure t (requires True) (ensures (fun c -> FStar.UInt.mod (v a) (v b) = v c)) (**** Bitwise operators *) /// Also see FStar.BV (** Bitwise logical conjunction *) val logand (x:t) (y:t) : Pure t (requires True) (ensures (fun z -> v x `logand` v y = v z)) (** Bitwise logical exclusive-or *) val logxor (x:t) (y:t) : Pure t (requires True) (ensures (fun z -> v x `logxor` v y == v z)) (** Bitwise logical disjunction *) val logor (x:t) (y:t) : Pure t (requires True) (ensures (fun z -> v x `logor` v y == v z)) (** Bitwise logical negation *) val lognot (x:t) : Pure t (requires True) (ensures (fun z -> lognot (v x) == v z)) (**** Shift operators *) (** Shift right with zero fill, shifting at most the integer width *) val shift_right (a:t) (s:UInt32.t) : Pure t (requires (UInt32.v s < n)) (ensures (fun c -> FStar.UInt.shift_right (v a) (UInt32.v s) = v c)) (** Shift left with zero fill, shifting at most the integer width *) val shift_left (a:t) (s:UInt32.t) : Pure t (requires (UInt32.v s < n)) (ensures (fun c -> FStar.UInt.shift_left (v a) (UInt32.v s) = v c)) (**** Comparison operators *) (** Equality Note, it is safe to also use the polymorphic decidable equality operator [=] *) let eq (a:t) (b:t) : Tot bool = eq #n (v a) (v b) (** Greater than *) let gt (a:t) (b:t) : Tot bool = gt #n (v a) (v b) (** Greater than or equal *) let gte (a:t) (b:t) : Tot bool = gte #n (v a) (v b) (** Less than *) let lt (a:t) (b:t) : Tot bool = lt #n (v a) (v b) (** Less than or equal *) let lte (a:t) (b:t) : Tot bool = lte #n (v a) (v b) (** Unary negation *) inline_for_extraction let minus (a:t) = add_mod (lognot a) (uint_to_t 1) (** The maximum shift value for this type, i.e. its width minus one, as an UInt32. *) inline_for_extraction let n_minus_one = UInt32.uint_to_t (n - 1) #set-options "--z3rlimit 80 --initial_fuel 1 --max_fuel 1" (** A constant-time way to compute the equality of two machine integers. With inspiration from https://git.zx2c4.com/WireGuard/commit/src/crypto/curve25519-hacl64.h?id=2e60bb395c1f589a398ec606d611132ef9ef764b Note, the branching on [a=b] is just for proof-purposes. *) [@ CNoInline ] let eq_mask (a:t) (b:t) : Pure t (requires True) (ensures (fun c -> (v a = v b ==> v c = pow2 n - 1) /\ (v a <> v b ==> v c = 0))) = let x = logxor a b in let minus_x = minus x in let x_or_minus_x = logor x minus_x in let xnx = shift_right x_or_minus_x n_minus_one in let c = sub_mod xnx (uint_to_t 1) in if a = b then begin logxor_self (v a); lognot_lemma_1 #n; logor_lemma_1 (v x); assert (v x = 0 /\ v minus_x = 0 /\ v x_or_minus_x = 0 /\ v xnx = 0); assert (v c = ones n) end else begin logxor_neq_nonzero (v a) (v b); lemma_msb_pow2 #n (v (lognot x)); lemma_msb_pow2 #n (v minus_x); lemma_minus_zero #n (v x); assert (v c = FStar.UInt.zero n) end; c private val lemma_sub_msbs (a:t) (b:t) : Lemma ((msb (v a) = msb (v b)) ==> (v a < v b <==> msb (v (sub_mod a b)))) (** A constant-time way to compute the [>=] inequality of two machine integers. With inspiration from https://git.zx2c4.com/WireGuard/commit/src/crypto/curve25519-hacl64.h?id=0a483a9b431d87eca1b275463c632f8d5551978a *) [@ CNoInline ] let gte_mask (a:t) (b:t) : Pure t (requires True) (ensures (fun c -> (v a >= v b ==> v c = pow2 n - 1) /\ (v a < v b ==> v c = 0))) = let x = a in let y = b in let x_xor_y = logxor x y in let x_sub_y = sub_mod x y in let x_sub_y_xor_y = logxor x_sub_y y in let q = logor x_xor_y x_sub_y_xor_y in let x_xor_q = logxor x q in let x_xor_q_ = shift_right x_xor_q n_minus_one in let c = sub_mod x_xor_q_ (uint_to_t 1) in lemma_sub_msbs x y; lemma_msb_gte (v x) (v y); lemma_msb_gte (v y) (v x); c #reset-options (*** Infix notations *) unfold let op_Plus_Hat = add unfold let op_Plus_Question_Hat = add_underspec unfold let op_Plus_Percent_Hat = add_mod unfold let op_Subtraction_Hat = sub unfold let op_Subtraction_Question_Hat = sub_underspec unfold let op_Subtraction_Percent_Hat = sub_mod unfold let op_Star_Hat = mul unfold let op_Star_Question_Hat = mul_underspec unfold let op_Star_Percent_Hat = mul_mod unfold let op_Slash_Hat = div unfold let op_Percent_Hat = rem unfold let op_Hat_Hat = logxor unfold let op_Amp_Hat = logand
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.UInt32.fsti.checked", "FStar.UInt.fsti.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked" ], "interface_file": false, "source_file": "FStar.UInt64.fsti" }
[ { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.UInt", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.UInt", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "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: FStar.UInt64.t -> s: FStar.UInt32.t -> Prims.Pure FStar.UInt64.t
Prims.Pure
[]
[]
[ "FStar.UInt64.shift_left" ]
[]
false
false
false
false
false
let op_Less_Less_Hat =
shift_left
false
FStar.UInt64.fsti
FStar.UInt64.op_Slash_Hat
val op_Slash_Hat : a: FStar.UInt64.t -> b: FStar.UInt64.t{FStar.UInt64.v b <> 0} -> Prims.Pure FStar.UInt64.t
let op_Slash_Hat = div
{ "file_name": "ulib/FStar.UInt64.fsti", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 29, "end_line": 325, "start_col": 7, "start_line": 325 }
(* 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 FStar.UInt64 (**** THIS MODULE IS GENERATED AUTOMATICALLY USING [mk_int.sh], DO NOT EDIT DIRECTLY ****) unfold let n = 64 /// For FStar.UIntN.fstp: anything that you fix/update here should be /// reflected in [FStar.IntN.fstp], which is mostly a copy-paste of /// this module. /// /// Except, as compared to [FStar.IntN.fstp], here: /// - every occurrence of [int_t] has been replaced with [uint_t] /// - every occurrence of [@%] has been replaced with [%]. /// - some functions (e.g., add_underspec, etc.) are only defined here, not on signed integers /// This module provides an abstract type for machine integers of a /// given signedness and width. The interface is designed to be safe /// with respect to arithmetic underflow and overflow. /// Note, we have attempted several times to re-design this module to /// make it more amenable to normalization and to impose less overhead /// on the SMT solver when reasoning about machine integer /// arithmetic. The following github issue reports on the current /// status of that work. /// /// https://github.com/FStarLang/FStar/issues/1757 open FStar.UInt open FStar.Mul #set-options "--max_fuel 0 --max_ifuel 0" (** Abstract type of machine integers, with an underlying representation using a bounded mathematical integer *) new val t : eqtype (** A coercion that projects a bounded mathematical integer from a machine integer *) val v (x:t) : Tot (uint_t n) (** A coercion that injects a bounded mathematical integers into a machine integer *) val uint_to_t (x:uint_t n) : Pure t (requires True) (ensures (fun y -> v y = x)) (** Injection/projection inverse *) val uv_inv (x : t) : Lemma (ensures (uint_to_t (v x) == x)) [SMTPat (v x)] (** Projection/injection inverse *) val vu_inv (x : uint_t n) : Lemma (ensures (v (uint_to_t x) == x)) [SMTPat (uint_to_t x)] (** An alternate form of the injectivity of the [v] projection *) val v_inj (x1 x2: t): Lemma (requires (v x1 == v x2)) (ensures (x1 == x2)) (** Constants 0 and 1 *) val zero : x:t{v x = 0} val one : x:t{v x = 1} (**** Addition primitives *) (** Bounds-respecting addition The precondition enforces that the sum does not overflow, expressing the bound as an addition on mathematical integers *) val add (a:t) (b:t) : Pure t (requires (size (v a + v b) n)) (ensures (fun c -> v a + v b = v c)) (** Underspecified, possibly overflowing addition: The postcondition only enures that the result is the sum of the arguments in case there is no overflow *) val add_underspec (a:t) (b:t) : Pure t (requires True) (ensures (fun c -> size (v a + v b) n ==> v a + v b = v c)) (** Addition modulo [2^n] Machine integers can always be added, but the postcondition is now in terms of addition modulo [2^n] on mathematical integers *) val add_mod (a:t) (b:t) : Pure t (requires True) (ensures (fun c -> FStar.UInt.add_mod (v a) (v b) = v c)) (**** Subtraction primitives *) (** Bounds-respecting subtraction The precondition enforces that the difference does not underflow, expressing the bound as a difference on mathematical integers *) val sub (a:t) (b:t) : Pure t (requires (size (v a - v b) n)) (ensures (fun c -> v a - v b = v c)) (** Underspecified, possibly overflowing subtraction: The postcondition only enures that the result is the difference of the arguments in case there is no underflow *) val sub_underspec (a:t) (b:t) : Pure t (requires True) (ensures (fun c -> size (v a - v b) n ==> v a - v b = v c)) (** Subtraction modulo [2^n] Machine integers can always be subtractd, but the postcondition is now in terms of subtraction modulo [2^n] on mathematical integers *) val sub_mod (a:t) (b:t) : Pure t (requires True) (ensures (fun c -> FStar.UInt.sub_mod (v a) (v b) = v c)) (**** Multiplication primitives *) (** Bounds-respecting multiplication The precondition enforces that the product does not overflow, expressing the bound as a product on mathematical integers *) val mul (a:t) (b:t) : Pure t (requires (size (v a * v b) n)) (ensures (fun c -> v a * v b = v c)) (** Underspecified, possibly overflowing product The postcondition only enures that the result is the product of the arguments in case there is no overflow *) val mul_underspec (a:t) (b:t) : Pure t (requires True) (ensures (fun c -> size (v a * v b) n ==> v a * v b = v c)) (** Multiplication modulo [2^n] Machine integers can always be multiplied, but the postcondition is now in terms of product modulo [2^n] on mathematical integers *) val mul_mod (a:t) (b:t) : Pure t (requires True) (ensures (fun c -> FStar.UInt.mul_mod (v a) (v b) = v c)) (**** Division primitives *) (** Euclidean division of [a] and [b], with [b] non-zero *) val div (a:t) (b:t{v b <> 0}) : Pure t (requires (True)) (ensures (fun c -> v a / v b = v c)) (**** Modulo primitives *) (** Euclidean remainder The result is the modulus of [a] with respect to a non-zero [b] *) val rem (a:t) (b:t{v b <> 0}) : Pure t (requires True) (ensures (fun c -> FStar.UInt.mod (v a) (v b) = v c)) (**** Bitwise operators *) /// Also see FStar.BV (** Bitwise logical conjunction *) val logand (x:t) (y:t) : Pure t (requires True) (ensures (fun z -> v x `logand` v y = v z)) (** Bitwise logical exclusive-or *) val logxor (x:t) (y:t) : Pure t (requires True) (ensures (fun z -> v x `logxor` v y == v z)) (** Bitwise logical disjunction *) val logor (x:t) (y:t) : Pure t (requires True) (ensures (fun z -> v x `logor` v y == v z)) (** Bitwise logical negation *) val lognot (x:t) : Pure t (requires True) (ensures (fun z -> lognot (v x) == v z)) (**** Shift operators *) (** Shift right with zero fill, shifting at most the integer width *) val shift_right (a:t) (s:UInt32.t) : Pure t (requires (UInt32.v s < n)) (ensures (fun c -> FStar.UInt.shift_right (v a) (UInt32.v s) = v c)) (** Shift left with zero fill, shifting at most the integer width *) val shift_left (a:t) (s:UInt32.t) : Pure t (requires (UInt32.v s < n)) (ensures (fun c -> FStar.UInt.shift_left (v a) (UInt32.v s) = v c)) (**** Comparison operators *) (** Equality Note, it is safe to also use the polymorphic decidable equality operator [=] *) let eq (a:t) (b:t) : Tot bool = eq #n (v a) (v b) (** Greater than *) let gt (a:t) (b:t) : Tot bool = gt #n (v a) (v b) (** Greater than or equal *) let gte (a:t) (b:t) : Tot bool = gte #n (v a) (v b) (** Less than *) let lt (a:t) (b:t) : Tot bool = lt #n (v a) (v b) (** Less than or equal *) let lte (a:t) (b:t) : Tot bool = lte #n (v a) (v b) (** Unary negation *) inline_for_extraction let minus (a:t) = add_mod (lognot a) (uint_to_t 1) (** The maximum shift value for this type, i.e. its width minus one, as an UInt32. *) inline_for_extraction let n_minus_one = UInt32.uint_to_t (n - 1) #set-options "--z3rlimit 80 --initial_fuel 1 --max_fuel 1" (** A constant-time way to compute the equality of two machine integers. With inspiration from https://git.zx2c4.com/WireGuard/commit/src/crypto/curve25519-hacl64.h?id=2e60bb395c1f589a398ec606d611132ef9ef764b Note, the branching on [a=b] is just for proof-purposes. *) [@ CNoInline ] let eq_mask (a:t) (b:t) : Pure t (requires True) (ensures (fun c -> (v a = v b ==> v c = pow2 n - 1) /\ (v a <> v b ==> v c = 0))) = let x = logxor a b in let minus_x = minus x in let x_or_minus_x = logor x minus_x in let xnx = shift_right x_or_minus_x n_minus_one in let c = sub_mod xnx (uint_to_t 1) in if a = b then begin logxor_self (v a); lognot_lemma_1 #n; logor_lemma_1 (v x); assert (v x = 0 /\ v minus_x = 0 /\ v x_or_minus_x = 0 /\ v xnx = 0); assert (v c = ones n) end else begin logxor_neq_nonzero (v a) (v b); lemma_msb_pow2 #n (v (lognot x)); lemma_msb_pow2 #n (v minus_x); lemma_minus_zero #n (v x); assert (v c = FStar.UInt.zero n) end; c private val lemma_sub_msbs (a:t) (b:t) : Lemma ((msb (v a) = msb (v b)) ==> (v a < v b <==> msb (v (sub_mod a b)))) (** A constant-time way to compute the [>=] inequality of two machine integers. With inspiration from https://git.zx2c4.com/WireGuard/commit/src/crypto/curve25519-hacl64.h?id=0a483a9b431d87eca1b275463c632f8d5551978a *) [@ CNoInline ] let gte_mask (a:t) (b:t) : Pure t (requires True) (ensures (fun c -> (v a >= v b ==> v c = pow2 n - 1) /\ (v a < v b ==> v c = 0))) = let x = a in let y = b in let x_xor_y = logxor x y in let x_sub_y = sub_mod x y in let x_sub_y_xor_y = logxor x_sub_y y in let q = logor x_xor_y x_sub_y_xor_y in let x_xor_q = logxor x q in let x_xor_q_ = shift_right x_xor_q n_minus_one in let c = sub_mod x_xor_q_ (uint_to_t 1) in lemma_sub_msbs x y; lemma_msb_gte (v x) (v y); lemma_msb_gte (v y) (v x); c #reset-options (*** Infix notations *) unfold let op_Plus_Hat = add unfold let op_Plus_Question_Hat = add_underspec unfold let op_Plus_Percent_Hat = add_mod unfold let op_Subtraction_Hat = sub unfold let op_Subtraction_Question_Hat = sub_underspec unfold let op_Subtraction_Percent_Hat = sub_mod unfold let op_Star_Hat = mul unfold let op_Star_Question_Hat = mul_underspec
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.UInt32.fsti.checked", "FStar.UInt.fsti.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked" ], "interface_file": false, "source_file": "FStar.UInt64.fsti" }
[ { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.UInt", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.UInt", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "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: FStar.UInt64.t -> b: FStar.UInt64.t{FStar.UInt64.v b <> 0} -> Prims.Pure FStar.UInt64.t
Prims.Pure
[]
[]
[ "FStar.UInt64.div" ]
[]
false
false
false
false
false
let op_Slash_Hat =
div
false
LowParse.Low.BCVLI.fst
LowParse.Low.BCVLI.validate_bounded_bcvli
val validate_bounded_bcvli (min: nat) (min32: U32.t{U32.v min32 == min}) (max: nat{min <= max}) (max32: U32.t{U32.v max32 == max}) : Tot (validator (parse_bounded_bcvli min max))
val validate_bounded_bcvli (min: nat) (min32: U32.t{U32.v min32 == min}) (max: nat{min <= max}) (max32: U32.t{U32.v max32 == max}) : Tot (validator (parse_bounded_bcvli min max))
let validate_bounded_bcvli (min: nat) (min32: U32.t { U32.v min32 == min }) (max: nat { min <= max }) (max32: U32.t { U32.v max32 == max }) : Tot (validator (parse_bounded_bcvli min max)) = validate_bounded_bcvli' min32 max32
{ "file_name": "src/lowparse/LowParse.Low.BCVLI.fst", "git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
{ "end_col": 37, "end_line": 241, "start_col": 0, "start_line": 235 }
module LowParse.Low.BCVLI include LowParse.Spec.BCVLI include LowParse.Low.Combinators include LowParse.Low.BoundedInt module B = LowStar.Buffer module HST = FStar.HyperStack.ST module Cast = FStar.Int.Cast module U32 = FStar.UInt32 module U64 = FStar.UInt64 #reset-options "--z3cliopt smt.arith.nl=false --max_fuel 0" #push-options "--z3rlimit 16" let validate_bcvli : validator parse_bcvli = fun #rrel #rel input pos -> let h = HST.get () in [@inline_let] let _ = valid_facts parse_bcvli h input (uint64_to_uint32 pos); parse_bcvli_eq (bytes_of_slice_from h input (uint64_to_uint32 pos)); valid_facts (parse_bounded_integer_le 1) h input (uint64_to_uint32 pos) in let pos1 = validate_total_constant_size (parse_bounded_integer_le 1) 1uL () input pos in if is_error pos1 then pos1 else [@inline_let] let _ = valid_facts (parse_bounded_integer_le 2) h input (uint64_to_uint32 pos1); valid_facts (parse_bounded_integer_le 4) h input (uint64_to_uint32 pos1) in let r = read_bounded_integer_le_1 input (uint64_to_uint32 pos) in if r `U32.lt` 253ul then pos1 else if r = 253ul then let pos2 = validate_total_constant_size (parse_bounded_integer_le 2) 2uL () input pos1 in if is_error pos2 then pos2 else (* because of the non-malleability constraint, I need to actually read the value and check whether it is not a lower integer *) let r = read_bounded_integer_le_2 input (uint64_to_uint32 pos1) in if r `U32.lt` 253ul then validator_error_generic else pos2 else if r = 254ul then let pos2 = validate_total_constant_size (parse_bounded_integer_le 4) 4uL () input pos1 in if is_error pos2 then pos2 else (* because of the non-malleability constraint, I need to actually read the value and check whether it is not a lower integer *) let r = read_bounded_integer_le_4 input (uint64_to_uint32 pos1) in if r `U32.lt` 65536ul then validator_error_generic else pos2 else validator_error_generic let jump_bcvli : jumper parse_bcvli = fun #rrel #rel input pos -> let h = HST.get () in [@inline_let] let _ = valid_facts parse_bcvli h input pos; parse_bcvli_eq (bytes_of_slice_from h input pos); valid_facts (parse_bounded_integer_le 1) h input pos in let pos1 = jump_constant_size (parse_bounded_integer_le 1) 1ul () input pos in [@inline_let] let _ = valid_facts (parse_bounded_integer_le 2) h input pos1; valid_facts (parse_bounded_integer_le 4) h input pos1 in let r = read_bounded_integer_le_1 input pos in if r `U32.lt` 253ul then pos1 else if r = 253ul then jump_constant_size (parse_bounded_integer_le 2) 2ul () input pos1 else jump_constant_size (parse_bounded_integer_le 4) 4ul () input pos1 let read_bcvli : leaf_reader parse_bcvli = fun #rrel #rel input pos -> let h = HST.get () in [@inline_let] let _ = valid_facts parse_bcvli h input pos; parse_bcvli_eq (bytes_of_slice_from h input pos); valid_facts (parse_bounded_integer_le 1) h input pos in let r = read_bounded_integer_le_1 input pos in if r `U32.lt` 253ul then (r <: U32.t) else let pos1 = jump_constant_size (parse_bounded_integer_le 1) 1ul () input pos in [@inline_let] let _ = valid_facts (parse_bounded_integer_le 2) h input pos1; valid_facts (parse_bounded_integer_le 4) h input pos1 in if r = 253ul then read_bounded_integer_le_2 input pos1 <: U32.t else read_bounded_integer_le_4 input pos1 <: U32.t #pop-options module U8 = FStar.UInt8 #push-options "--z3rlimit 32" inline_for_extraction let serialize32_bcvli' (x: U32.t) (#rrel #rel: _) (b: B.mbuffer U8.t rrel rel) (pos: U32.t) : HST.Stack U32.t (requires (fun h -> let len = Seq.length (serialize serialize_bcvli x) in B.live h b /\ U32.v pos + len <= B.length b /\ writable b (U32.v pos) (U32.v pos + len) h )) (ensures (fun h len h' -> Seq.length (serialize serialize_bcvli x) == U32.v len /\ ( B.modifies (B.loc_buffer_from_to b pos (pos `U32.add` len)) h h' /\ B.live h b /\ Seq.slice (B.as_seq h' b) (U32.v pos) (U32.v pos + U32.v len) `Seq.equal` serialize serialize_bcvli x ))) = // [@inline_let] let _ = serialize_bcvli_eq x ; // in let c : bounded_integer 1 = if x `U32.lt` 253ul then x else if x `U32.lt` 65536ul then 253ul else 254ul in [@inline_let] let pos' = Ghost.hide (U32.v pos + Seq.length (serialize serialize_bcvli x)) in let h = HST.get () in [@inline_let] let _ = writable_weaken b (U32.v pos) (Ghost.reveal pos') h (U32.v pos) (U32.v pos + 1) in let len1 = serialize32_bounded_integer_le_1 c b pos in let h1 = HST.get () in [@inline_let] let _ = writable_modifies b (U32.v pos) (Ghost.reveal pos') h B.loc_none h1 in if c `U32.lt` 253ul then begin len1 end else if c = 253ul then begin [@inline_let] let _ = assert (U32.v x < 65536) in [@inline_let] let _ = writable_weaken b (U32.v pos) (Ghost.reveal pos') h1 (U32.v pos + U32.v len1) ((U32.v pos + U32.v len1) + 2) in let len2 = serialize32_bounded_integer_le_2 x b (pos `U32.add` len1) in let h' = HST.get () in [@inline_let] let len = len1 `U32.add` len2 in B.modifies_buffer_from_to_elim b pos (pos `U32.add` len1) (B.loc_buffer_from_to b (pos `U32.add` len1) (pos `U32.add` len)) h1 h'; len end else begin [@inline_let] let _ = writable_weaken b (U32.v pos) (Ghost.reveal pos') h1 (U32.v pos + U32.v len1) ((U32.v pos + U32.v len1) + 4) in let len2 = serialize32_bounded_integer_le_4 x b (pos `U32.add` len1) in let h' = HST.get () in [@inline_let] let len = len1 `U32.add` len2 in B.modifies_buffer_from_to_elim b pos (pos `U32.add` len1) (B.loc_buffer_from_to b (pos `U32.add` len1) (pos `U32.add` len)) h1 h'; len end inline_for_extraction let serialize32_bcvli : serializer32 serialize_bcvli = fun (x: U32.t) #rrel #rel b pos -> serialize32_bcvli' x b pos let write_bcvli : leaf_writer_strong serialize_bcvli = leaf_writer_strong_of_serializer32 serialize32_bcvli () let validate_bounded_bcvli' (min32: U32.t) (max32: U32.t { U32.v min32 <= U32.v max32 }) : Tot (validator (parse_bounded_bcvli (U32.v min32) (U32.v max32))) = fun #rrel #rel input pos -> let h = HST.get () in [@inline_let] let _ = valid_facts (parse_bounded_bcvli (U32.v min32) (U32.v max32)) h input (uint64_to_uint32 pos); parse_bounded_bcvli_eq (U32.v min32) (U32.v max32) (bytes_of_slice_from h input (uint64_to_uint32 pos)); parse_bcvli_eq (bytes_of_slice_from h input (uint64_to_uint32 pos)); valid_facts (parse_bounded_integer_le 1) h input (uint64_to_uint32 pos) in let pos1 = validate_total_constant_size (parse_bounded_integer_le 1) 1uL () input pos in if is_error pos1 then pos1 else [@inline_let] let _ = valid_facts (parse_bounded_integer_le 2) h input (uint64_to_uint32 pos1); valid_facts (parse_bounded_integer_le 4) h input (uint64_to_uint32 pos1) in let r = read_bounded_integer_le_1 input (uint64_to_uint32 pos) in if r `U32.lt` 253ul && min32 `U32.lte` r && r `U32.lte` max32 then pos1 else if max32 `U32.lt` 253ul then validator_error_generic else if r = 253ul then if 65536ul `U32.lte` min32 then validator_error_generic else let pos2 = validate_total_constant_size (parse_bounded_integer_le 2) 2uL () input pos1 in if is_error pos2 then pos2 else (* because of the non-malleability constraint, I need to actually read the value and check whether it is not a lower integer *) let r = read_bounded_integer_le_2 input (uint64_to_uint32 pos1) in if r `U32.lt` 253ul || r `U32.lt` min32 || max32 `U32.lt` r then validator_error_generic else pos2 else if max32 `U32.lt` 65536ul then validator_error_generic else if r = 254ul then let pos2 = validate_total_constant_size (parse_bounded_integer_le 4) 4uL () input pos1 in if is_error pos2 then pos2 else (* because of the non-malleability constraint, I need to actually read the value and check whether it is not a lower integer *) let r = read_bounded_integer_le_4 input (uint64_to_uint32 pos1) in if r `U32.lt` 65536ul || r `U32.lt` min32 || max32 `U32.lt` r then validator_error_generic else pos2 else validator_error_generic inline_for_extraction
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowStar.Buffer.fst.checked", "LowParse.Spec.BCVLI.fsti.checked", "LowParse.Low.Combinators.fsti.checked", "LowParse.Low.BoundedInt.fsti.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.Ghost.fsti.checked" ], "interface_file": false, "source_file": "LowParse.Low.BCVLI.fst" }
[ { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": true, "full_module": "FStar.Int.Cast", "short_module": "Cast" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": false, "full_module": "LowParse.Low.BoundedInt", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low.Combinators", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec.BCVLI", "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": 0, "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": [ "smt.arith.nl=false" ], "z3refresh": false, "z3rlimit": 32, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
min: Prims.nat -> min32: FStar.UInt32.t{FStar.UInt32.v min32 == min} -> max: Prims.nat{min <= max} -> max32: FStar.UInt32.t{FStar.UInt32.v max32 == max} -> LowParse.Low.Base.validator (LowParse.Spec.BCVLI.parse_bounded_bcvli min max)
Prims.Tot
[ "total" ]
[]
[ "Prims.nat", "FStar.UInt32.t", "Prims.eq2", "Prims.int", "Prims.l_or", "FStar.UInt.size", "FStar.UInt32.n", "Prims.b2t", "Prims.op_GreaterThanOrEqual", "FStar.UInt32.v", "Prims.op_LessThanOrEqual", "Prims.l_and", "LowParse.Low.BCVLI.validate_bounded_bcvli'", "LowParse.Low.Base.validator", "LowParse.Spec.BCVLI.parse_bounded_bcvli_kind", "LowParse.Spec.BoundedInt.bounded_int32", "LowParse.Spec.BCVLI.parse_bounded_bcvli" ]
[]
false
false
false
false
false
let validate_bounded_bcvli (min: nat) (min32: U32.t{U32.v min32 == min}) (max: nat{min <= max}) (max32: U32.t{U32.v max32 == max}) : Tot (validator (parse_bounded_bcvli min max)) =
validate_bounded_bcvli' min32 max32
false
FStar.UInt64.fsti
FStar.UInt64.op_Hat_Hat
val op_Hat_Hat : x: FStar.UInt64.t -> y: FStar.UInt64.t -> Prims.Pure FStar.UInt64.t
let op_Hat_Hat = logxor
{ "file_name": "ulib/FStar.UInt64.fsti", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 30, "end_line": 327, "start_col": 7, "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 FStar.UInt64 (**** THIS MODULE IS GENERATED AUTOMATICALLY USING [mk_int.sh], DO NOT EDIT DIRECTLY ****) unfold let n = 64 /// For FStar.UIntN.fstp: anything that you fix/update here should be /// reflected in [FStar.IntN.fstp], which is mostly a copy-paste of /// this module. /// /// Except, as compared to [FStar.IntN.fstp], here: /// - every occurrence of [int_t] has been replaced with [uint_t] /// - every occurrence of [@%] has been replaced with [%]. /// - some functions (e.g., add_underspec, etc.) are only defined here, not on signed integers /// This module provides an abstract type for machine integers of a /// given signedness and width. The interface is designed to be safe /// with respect to arithmetic underflow and overflow. /// Note, we have attempted several times to re-design this module to /// make it more amenable to normalization and to impose less overhead /// on the SMT solver when reasoning about machine integer /// arithmetic. The following github issue reports on the current /// status of that work. /// /// https://github.com/FStarLang/FStar/issues/1757 open FStar.UInt open FStar.Mul #set-options "--max_fuel 0 --max_ifuel 0" (** Abstract type of machine integers, with an underlying representation using a bounded mathematical integer *) new val t : eqtype (** A coercion that projects a bounded mathematical integer from a machine integer *) val v (x:t) : Tot (uint_t n) (** A coercion that injects a bounded mathematical integers into a machine integer *) val uint_to_t (x:uint_t n) : Pure t (requires True) (ensures (fun y -> v y = x)) (** Injection/projection inverse *) val uv_inv (x : t) : Lemma (ensures (uint_to_t (v x) == x)) [SMTPat (v x)] (** Projection/injection inverse *) val vu_inv (x : uint_t n) : Lemma (ensures (v (uint_to_t x) == x)) [SMTPat (uint_to_t x)] (** An alternate form of the injectivity of the [v] projection *) val v_inj (x1 x2: t): Lemma (requires (v x1 == v x2)) (ensures (x1 == x2)) (** Constants 0 and 1 *) val zero : x:t{v x = 0} val one : x:t{v x = 1} (**** Addition primitives *) (** Bounds-respecting addition The precondition enforces that the sum does not overflow, expressing the bound as an addition on mathematical integers *) val add (a:t) (b:t) : Pure t (requires (size (v a + v b) n)) (ensures (fun c -> v a + v b = v c)) (** Underspecified, possibly overflowing addition: The postcondition only enures that the result is the sum of the arguments in case there is no overflow *) val add_underspec (a:t) (b:t) : Pure t (requires True) (ensures (fun c -> size (v a + v b) n ==> v a + v b = v c)) (** Addition modulo [2^n] Machine integers can always be added, but the postcondition is now in terms of addition modulo [2^n] on mathematical integers *) val add_mod (a:t) (b:t) : Pure t (requires True) (ensures (fun c -> FStar.UInt.add_mod (v a) (v b) = v c)) (**** Subtraction primitives *) (** Bounds-respecting subtraction The precondition enforces that the difference does not underflow, expressing the bound as a difference on mathematical integers *) val sub (a:t) (b:t) : Pure t (requires (size (v a - v b) n)) (ensures (fun c -> v a - v b = v c)) (** Underspecified, possibly overflowing subtraction: The postcondition only enures that the result is the difference of the arguments in case there is no underflow *) val sub_underspec (a:t) (b:t) : Pure t (requires True) (ensures (fun c -> size (v a - v b) n ==> v a - v b = v c)) (** Subtraction modulo [2^n] Machine integers can always be subtractd, but the postcondition is now in terms of subtraction modulo [2^n] on mathematical integers *) val sub_mod (a:t) (b:t) : Pure t (requires True) (ensures (fun c -> FStar.UInt.sub_mod (v a) (v b) = v c)) (**** Multiplication primitives *) (** Bounds-respecting multiplication The precondition enforces that the product does not overflow, expressing the bound as a product on mathematical integers *) val mul (a:t) (b:t) : Pure t (requires (size (v a * v b) n)) (ensures (fun c -> v a * v b = v c)) (** Underspecified, possibly overflowing product The postcondition only enures that the result is the product of the arguments in case there is no overflow *) val mul_underspec (a:t) (b:t) : Pure t (requires True) (ensures (fun c -> size (v a * v b) n ==> v a * v b = v c)) (** Multiplication modulo [2^n] Machine integers can always be multiplied, but the postcondition is now in terms of product modulo [2^n] on mathematical integers *) val mul_mod (a:t) (b:t) : Pure t (requires True) (ensures (fun c -> FStar.UInt.mul_mod (v a) (v b) = v c)) (**** Division primitives *) (** Euclidean division of [a] and [b], with [b] non-zero *) val div (a:t) (b:t{v b <> 0}) : Pure t (requires (True)) (ensures (fun c -> v a / v b = v c)) (**** Modulo primitives *) (** Euclidean remainder The result is the modulus of [a] with respect to a non-zero [b] *) val rem (a:t) (b:t{v b <> 0}) : Pure t (requires True) (ensures (fun c -> FStar.UInt.mod (v a) (v b) = v c)) (**** Bitwise operators *) /// Also see FStar.BV (** Bitwise logical conjunction *) val logand (x:t) (y:t) : Pure t (requires True) (ensures (fun z -> v x `logand` v y = v z)) (** Bitwise logical exclusive-or *) val logxor (x:t) (y:t) : Pure t (requires True) (ensures (fun z -> v x `logxor` v y == v z)) (** Bitwise logical disjunction *) val logor (x:t) (y:t) : Pure t (requires True) (ensures (fun z -> v x `logor` v y == v z)) (** Bitwise logical negation *) val lognot (x:t) : Pure t (requires True) (ensures (fun z -> lognot (v x) == v z)) (**** Shift operators *) (** Shift right with zero fill, shifting at most the integer width *) val shift_right (a:t) (s:UInt32.t) : Pure t (requires (UInt32.v s < n)) (ensures (fun c -> FStar.UInt.shift_right (v a) (UInt32.v s) = v c)) (** Shift left with zero fill, shifting at most the integer width *) val shift_left (a:t) (s:UInt32.t) : Pure t (requires (UInt32.v s < n)) (ensures (fun c -> FStar.UInt.shift_left (v a) (UInt32.v s) = v c)) (**** Comparison operators *) (** Equality Note, it is safe to also use the polymorphic decidable equality operator [=] *) let eq (a:t) (b:t) : Tot bool = eq #n (v a) (v b) (** Greater than *) let gt (a:t) (b:t) : Tot bool = gt #n (v a) (v b) (** Greater than or equal *) let gte (a:t) (b:t) : Tot bool = gte #n (v a) (v b) (** Less than *) let lt (a:t) (b:t) : Tot bool = lt #n (v a) (v b) (** Less than or equal *) let lte (a:t) (b:t) : Tot bool = lte #n (v a) (v b) (** Unary negation *) inline_for_extraction let minus (a:t) = add_mod (lognot a) (uint_to_t 1) (** The maximum shift value for this type, i.e. its width minus one, as an UInt32. *) inline_for_extraction let n_minus_one = UInt32.uint_to_t (n - 1) #set-options "--z3rlimit 80 --initial_fuel 1 --max_fuel 1" (** A constant-time way to compute the equality of two machine integers. With inspiration from https://git.zx2c4.com/WireGuard/commit/src/crypto/curve25519-hacl64.h?id=2e60bb395c1f589a398ec606d611132ef9ef764b Note, the branching on [a=b] is just for proof-purposes. *) [@ CNoInline ] let eq_mask (a:t) (b:t) : Pure t (requires True) (ensures (fun c -> (v a = v b ==> v c = pow2 n - 1) /\ (v a <> v b ==> v c = 0))) = let x = logxor a b in let minus_x = minus x in let x_or_minus_x = logor x minus_x in let xnx = shift_right x_or_minus_x n_minus_one in let c = sub_mod xnx (uint_to_t 1) in if a = b then begin logxor_self (v a); lognot_lemma_1 #n; logor_lemma_1 (v x); assert (v x = 0 /\ v minus_x = 0 /\ v x_or_minus_x = 0 /\ v xnx = 0); assert (v c = ones n) end else begin logxor_neq_nonzero (v a) (v b); lemma_msb_pow2 #n (v (lognot x)); lemma_msb_pow2 #n (v minus_x); lemma_minus_zero #n (v x); assert (v c = FStar.UInt.zero n) end; c private val lemma_sub_msbs (a:t) (b:t) : Lemma ((msb (v a) = msb (v b)) ==> (v a < v b <==> msb (v (sub_mod a b)))) (** A constant-time way to compute the [>=] inequality of two machine integers. With inspiration from https://git.zx2c4.com/WireGuard/commit/src/crypto/curve25519-hacl64.h?id=0a483a9b431d87eca1b275463c632f8d5551978a *) [@ CNoInline ] let gte_mask (a:t) (b:t) : Pure t (requires True) (ensures (fun c -> (v a >= v b ==> v c = pow2 n - 1) /\ (v a < v b ==> v c = 0))) = let x = a in let y = b in let x_xor_y = logxor x y in let x_sub_y = sub_mod x y in let x_sub_y_xor_y = logxor x_sub_y y in let q = logor x_xor_y x_sub_y_xor_y in let x_xor_q = logxor x q in let x_xor_q_ = shift_right x_xor_q n_minus_one in let c = sub_mod x_xor_q_ (uint_to_t 1) in lemma_sub_msbs x y; lemma_msb_gte (v x) (v y); lemma_msb_gte (v y) (v x); c #reset-options (*** Infix notations *) unfold let op_Plus_Hat = add unfold let op_Plus_Question_Hat = add_underspec unfold let op_Plus_Percent_Hat = add_mod unfold let op_Subtraction_Hat = sub unfold let op_Subtraction_Question_Hat = sub_underspec unfold let op_Subtraction_Percent_Hat = sub_mod unfold let op_Star_Hat = mul unfold let op_Star_Question_Hat = mul_underspec unfold let op_Star_Percent_Hat = mul_mod unfold let op_Slash_Hat = div
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.UInt32.fsti.checked", "FStar.UInt.fsti.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked" ], "interface_file": false, "source_file": "FStar.UInt64.fsti" }
[ { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.UInt", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.UInt", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
x: FStar.UInt64.t -> y: FStar.UInt64.t -> Prims.Pure FStar.UInt64.t
Prims.Pure
[]
[]
[ "FStar.UInt64.logxor" ]
[]
false
false
false
false
false
let op_Hat_Hat =
logxor
false
FStar.UInt64.fsti
FStar.UInt64.op_Percent_Hat
val op_Percent_Hat : a: FStar.UInt64.t -> b: FStar.UInt64.t{FStar.UInt64.v b <> 0} -> Prims.Pure FStar.UInt64.t
let op_Percent_Hat = rem
{ "file_name": "ulib/FStar.UInt64.fsti", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 31, "end_line": 326, "start_col": 7, "start_line": 326 }
(* 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 FStar.UInt64 (**** THIS MODULE IS GENERATED AUTOMATICALLY USING [mk_int.sh], DO NOT EDIT DIRECTLY ****) unfold let n = 64 /// For FStar.UIntN.fstp: anything that you fix/update here should be /// reflected in [FStar.IntN.fstp], which is mostly a copy-paste of /// this module. /// /// Except, as compared to [FStar.IntN.fstp], here: /// - every occurrence of [int_t] has been replaced with [uint_t] /// - every occurrence of [@%] has been replaced with [%]. /// - some functions (e.g., add_underspec, etc.) are only defined here, not on signed integers /// This module provides an abstract type for machine integers of a /// given signedness and width. The interface is designed to be safe /// with respect to arithmetic underflow and overflow. /// Note, we have attempted several times to re-design this module to /// make it more amenable to normalization and to impose less overhead /// on the SMT solver when reasoning about machine integer /// arithmetic. The following github issue reports on the current /// status of that work. /// /// https://github.com/FStarLang/FStar/issues/1757 open FStar.UInt open FStar.Mul #set-options "--max_fuel 0 --max_ifuel 0" (** Abstract type of machine integers, with an underlying representation using a bounded mathematical integer *) new val t : eqtype (** A coercion that projects a bounded mathematical integer from a machine integer *) val v (x:t) : Tot (uint_t n) (** A coercion that injects a bounded mathematical integers into a machine integer *) val uint_to_t (x:uint_t n) : Pure t (requires True) (ensures (fun y -> v y = x)) (** Injection/projection inverse *) val uv_inv (x : t) : Lemma (ensures (uint_to_t (v x) == x)) [SMTPat (v x)] (** Projection/injection inverse *) val vu_inv (x : uint_t n) : Lemma (ensures (v (uint_to_t x) == x)) [SMTPat (uint_to_t x)] (** An alternate form of the injectivity of the [v] projection *) val v_inj (x1 x2: t): Lemma (requires (v x1 == v x2)) (ensures (x1 == x2)) (** Constants 0 and 1 *) val zero : x:t{v x = 0} val one : x:t{v x = 1} (**** Addition primitives *) (** Bounds-respecting addition The precondition enforces that the sum does not overflow, expressing the bound as an addition on mathematical integers *) val add (a:t) (b:t) : Pure t (requires (size (v a + v b) n)) (ensures (fun c -> v a + v b = v c)) (** Underspecified, possibly overflowing addition: The postcondition only enures that the result is the sum of the arguments in case there is no overflow *) val add_underspec (a:t) (b:t) : Pure t (requires True) (ensures (fun c -> size (v a + v b) n ==> v a + v b = v c)) (** Addition modulo [2^n] Machine integers can always be added, but the postcondition is now in terms of addition modulo [2^n] on mathematical integers *) val add_mod (a:t) (b:t) : Pure t (requires True) (ensures (fun c -> FStar.UInt.add_mod (v a) (v b) = v c)) (**** Subtraction primitives *) (** Bounds-respecting subtraction The precondition enforces that the difference does not underflow, expressing the bound as a difference on mathematical integers *) val sub (a:t) (b:t) : Pure t (requires (size (v a - v b) n)) (ensures (fun c -> v a - v b = v c)) (** Underspecified, possibly overflowing subtraction: The postcondition only enures that the result is the difference of the arguments in case there is no underflow *) val sub_underspec (a:t) (b:t) : Pure t (requires True) (ensures (fun c -> size (v a - v b) n ==> v a - v b = v c)) (** Subtraction modulo [2^n] Machine integers can always be subtractd, but the postcondition is now in terms of subtraction modulo [2^n] on mathematical integers *) val sub_mod (a:t) (b:t) : Pure t (requires True) (ensures (fun c -> FStar.UInt.sub_mod (v a) (v b) = v c)) (**** Multiplication primitives *) (** Bounds-respecting multiplication The precondition enforces that the product does not overflow, expressing the bound as a product on mathematical integers *) val mul (a:t) (b:t) : Pure t (requires (size (v a * v b) n)) (ensures (fun c -> v a * v b = v c)) (** Underspecified, possibly overflowing product The postcondition only enures that the result is the product of the arguments in case there is no overflow *) val mul_underspec (a:t) (b:t) : Pure t (requires True) (ensures (fun c -> size (v a * v b) n ==> v a * v b = v c)) (** Multiplication modulo [2^n] Machine integers can always be multiplied, but the postcondition is now in terms of product modulo [2^n] on mathematical integers *) val mul_mod (a:t) (b:t) : Pure t (requires True) (ensures (fun c -> FStar.UInt.mul_mod (v a) (v b) = v c)) (**** Division primitives *) (** Euclidean division of [a] and [b], with [b] non-zero *) val div (a:t) (b:t{v b <> 0}) : Pure t (requires (True)) (ensures (fun c -> v a / v b = v c)) (**** Modulo primitives *) (** Euclidean remainder The result is the modulus of [a] with respect to a non-zero [b] *) val rem (a:t) (b:t{v b <> 0}) : Pure t (requires True) (ensures (fun c -> FStar.UInt.mod (v a) (v b) = v c)) (**** Bitwise operators *) /// Also see FStar.BV (** Bitwise logical conjunction *) val logand (x:t) (y:t) : Pure t (requires True) (ensures (fun z -> v x `logand` v y = v z)) (** Bitwise logical exclusive-or *) val logxor (x:t) (y:t) : Pure t (requires True) (ensures (fun z -> v x `logxor` v y == v z)) (** Bitwise logical disjunction *) val logor (x:t) (y:t) : Pure t (requires True) (ensures (fun z -> v x `logor` v y == v z)) (** Bitwise logical negation *) val lognot (x:t) : Pure t (requires True) (ensures (fun z -> lognot (v x) == v z)) (**** Shift operators *) (** Shift right with zero fill, shifting at most the integer width *) val shift_right (a:t) (s:UInt32.t) : Pure t (requires (UInt32.v s < n)) (ensures (fun c -> FStar.UInt.shift_right (v a) (UInt32.v s) = v c)) (** Shift left with zero fill, shifting at most the integer width *) val shift_left (a:t) (s:UInt32.t) : Pure t (requires (UInt32.v s < n)) (ensures (fun c -> FStar.UInt.shift_left (v a) (UInt32.v s) = v c)) (**** Comparison operators *) (** Equality Note, it is safe to also use the polymorphic decidable equality operator [=] *) let eq (a:t) (b:t) : Tot bool = eq #n (v a) (v b) (** Greater than *) let gt (a:t) (b:t) : Tot bool = gt #n (v a) (v b) (** Greater than or equal *) let gte (a:t) (b:t) : Tot bool = gte #n (v a) (v b) (** Less than *) let lt (a:t) (b:t) : Tot bool = lt #n (v a) (v b) (** Less than or equal *) let lte (a:t) (b:t) : Tot bool = lte #n (v a) (v b) (** Unary negation *) inline_for_extraction let minus (a:t) = add_mod (lognot a) (uint_to_t 1) (** The maximum shift value for this type, i.e. its width minus one, as an UInt32. *) inline_for_extraction let n_minus_one = UInt32.uint_to_t (n - 1) #set-options "--z3rlimit 80 --initial_fuel 1 --max_fuel 1" (** A constant-time way to compute the equality of two machine integers. With inspiration from https://git.zx2c4.com/WireGuard/commit/src/crypto/curve25519-hacl64.h?id=2e60bb395c1f589a398ec606d611132ef9ef764b Note, the branching on [a=b] is just for proof-purposes. *) [@ CNoInline ] let eq_mask (a:t) (b:t) : Pure t (requires True) (ensures (fun c -> (v a = v b ==> v c = pow2 n - 1) /\ (v a <> v b ==> v c = 0))) = let x = logxor a b in let minus_x = minus x in let x_or_minus_x = logor x minus_x in let xnx = shift_right x_or_minus_x n_minus_one in let c = sub_mod xnx (uint_to_t 1) in if a = b then begin logxor_self (v a); lognot_lemma_1 #n; logor_lemma_1 (v x); assert (v x = 0 /\ v minus_x = 0 /\ v x_or_minus_x = 0 /\ v xnx = 0); assert (v c = ones n) end else begin logxor_neq_nonzero (v a) (v b); lemma_msb_pow2 #n (v (lognot x)); lemma_msb_pow2 #n (v minus_x); lemma_minus_zero #n (v x); assert (v c = FStar.UInt.zero n) end; c private val lemma_sub_msbs (a:t) (b:t) : Lemma ((msb (v a) = msb (v b)) ==> (v a < v b <==> msb (v (sub_mod a b)))) (** A constant-time way to compute the [>=] inequality of two machine integers. With inspiration from https://git.zx2c4.com/WireGuard/commit/src/crypto/curve25519-hacl64.h?id=0a483a9b431d87eca1b275463c632f8d5551978a *) [@ CNoInline ] let gte_mask (a:t) (b:t) : Pure t (requires True) (ensures (fun c -> (v a >= v b ==> v c = pow2 n - 1) /\ (v a < v b ==> v c = 0))) = let x = a in let y = b in let x_xor_y = logxor x y in let x_sub_y = sub_mod x y in let x_sub_y_xor_y = logxor x_sub_y y in let q = logor x_xor_y x_sub_y_xor_y in let x_xor_q = logxor x q in let x_xor_q_ = shift_right x_xor_q n_minus_one in let c = sub_mod x_xor_q_ (uint_to_t 1) in lemma_sub_msbs x y; lemma_msb_gte (v x) (v y); lemma_msb_gte (v y) (v x); c #reset-options (*** Infix notations *) unfold let op_Plus_Hat = add unfold let op_Plus_Question_Hat = add_underspec unfold let op_Plus_Percent_Hat = add_mod unfold let op_Subtraction_Hat = sub unfold let op_Subtraction_Question_Hat = sub_underspec unfold let op_Subtraction_Percent_Hat = sub_mod unfold let op_Star_Hat = mul unfold let op_Star_Question_Hat = mul_underspec unfold let op_Star_Percent_Hat = mul_mod
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.UInt32.fsti.checked", "FStar.UInt.fsti.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked" ], "interface_file": false, "source_file": "FStar.UInt64.fsti" }
[ { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.UInt", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.UInt", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "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: FStar.UInt64.t -> b: FStar.UInt64.t{FStar.UInt64.v b <> 0} -> Prims.Pure FStar.UInt64.t
Prims.Pure
[]
[]
[ "FStar.UInt64.rem" ]
[]
false
false
false
false
false
let op_Percent_Hat =
rem
false
FStar.UInt64.fsti
FStar.UInt64.op_Amp_Hat
val op_Amp_Hat : x: FStar.UInt64.t -> y: FStar.UInt64.t -> Prims.Pure FStar.UInt64.t
let op_Amp_Hat = logand
{ "file_name": "ulib/FStar.UInt64.fsti", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 30, "end_line": 328, "start_col": 7, "start_line": 328 }
(* 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 FStar.UInt64 (**** THIS MODULE IS GENERATED AUTOMATICALLY USING [mk_int.sh], DO NOT EDIT DIRECTLY ****) unfold let n = 64 /// For FStar.UIntN.fstp: anything that you fix/update here should be /// reflected in [FStar.IntN.fstp], which is mostly a copy-paste of /// this module. /// /// Except, as compared to [FStar.IntN.fstp], here: /// - every occurrence of [int_t] has been replaced with [uint_t] /// - every occurrence of [@%] has been replaced with [%]. /// - some functions (e.g., add_underspec, etc.) are only defined here, not on signed integers /// This module provides an abstract type for machine integers of a /// given signedness and width. The interface is designed to be safe /// with respect to arithmetic underflow and overflow. /// Note, we have attempted several times to re-design this module to /// make it more amenable to normalization and to impose less overhead /// on the SMT solver when reasoning about machine integer /// arithmetic. The following github issue reports on the current /// status of that work. /// /// https://github.com/FStarLang/FStar/issues/1757 open FStar.UInt open FStar.Mul #set-options "--max_fuel 0 --max_ifuel 0" (** Abstract type of machine integers, with an underlying representation using a bounded mathematical integer *) new val t : eqtype (** A coercion that projects a bounded mathematical integer from a machine integer *) val v (x:t) : Tot (uint_t n) (** A coercion that injects a bounded mathematical integers into a machine integer *) val uint_to_t (x:uint_t n) : Pure t (requires True) (ensures (fun y -> v y = x)) (** Injection/projection inverse *) val uv_inv (x : t) : Lemma (ensures (uint_to_t (v x) == x)) [SMTPat (v x)] (** Projection/injection inverse *) val vu_inv (x : uint_t n) : Lemma (ensures (v (uint_to_t x) == x)) [SMTPat (uint_to_t x)] (** An alternate form of the injectivity of the [v] projection *) val v_inj (x1 x2: t): Lemma (requires (v x1 == v x2)) (ensures (x1 == x2)) (** Constants 0 and 1 *) val zero : x:t{v x = 0} val one : x:t{v x = 1} (**** Addition primitives *) (** Bounds-respecting addition The precondition enforces that the sum does not overflow, expressing the bound as an addition on mathematical integers *) val add (a:t) (b:t) : Pure t (requires (size (v a + v b) n)) (ensures (fun c -> v a + v b = v c)) (** Underspecified, possibly overflowing addition: The postcondition only enures that the result is the sum of the arguments in case there is no overflow *) val add_underspec (a:t) (b:t) : Pure t (requires True) (ensures (fun c -> size (v a + v b) n ==> v a + v b = v c)) (** Addition modulo [2^n] Machine integers can always be added, but the postcondition is now in terms of addition modulo [2^n] on mathematical integers *) val add_mod (a:t) (b:t) : Pure t (requires True) (ensures (fun c -> FStar.UInt.add_mod (v a) (v b) = v c)) (**** Subtraction primitives *) (** Bounds-respecting subtraction The precondition enforces that the difference does not underflow, expressing the bound as a difference on mathematical integers *) val sub (a:t) (b:t) : Pure t (requires (size (v a - v b) n)) (ensures (fun c -> v a - v b = v c)) (** Underspecified, possibly overflowing subtraction: The postcondition only enures that the result is the difference of the arguments in case there is no underflow *) val sub_underspec (a:t) (b:t) : Pure t (requires True) (ensures (fun c -> size (v a - v b) n ==> v a - v b = v c)) (** Subtraction modulo [2^n] Machine integers can always be subtractd, but the postcondition is now in terms of subtraction modulo [2^n] on mathematical integers *) val sub_mod (a:t) (b:t) : Pure t (requires True) (ensures (fun c -> FStar.UInt.sub_mod (v a) (v b) = v c)) (**** Multiplication primitives *) (** Bounds-respecting multiplication The precondition enforces that the product does not overflow, expressing the bound as a product on mathematical integers *) val mul (a:t) (b:t) : Pure t (requires (size (v a * v b) n)) (ensures (fun c -> v a * v b = v c)) (** Underspecified, possibly overflowing product The postcondition only enures that the result is the product of the arguments in case there is no overflow *) val mul_underspec (a:t) (b:t) : Pure t (requires True) (ensures (fun c -> size (v a * v b) n ==> v a * v b = v c)) (** Multiplication modulo [2^n] Machine integers can always be multiplied, but the postcondition is now in terms of product modulo [2^n] on mathematical integers *) val mul_mod (a:t) (b:t) : Pure t (requires True) (ensures (fun c -> FStar.UInt.mul_mod (v a) (v b) = v c)) (**** Division primitives *) (** Euclidean division of [a] and [b], with [b] non-zero *) val div (a:t) (b:t{v b <> 0}) : Pure t (requires (True)) (ensures (fun c -> v a / v b = v c)) (**** Modulo primitives *) (** Euclidean remainder The result is the modulus of [a] with respect to a non-zero [b] *) val rem (a:t) (b:t{v b <> 0}) : Pure t (requires True) (ensures (fun c -> FStar.UInt.mod (v a) (v b) = v c)) (**** Bitwise operators *) /// Also see FStar.BV (** Bitwise logical conjunction *) val logand (x:t) (y:t) : Pure t (requires True) (ensures (fun z -> v x `logand` v y = v z)) (** Bitwise logical exclusive-or *) val logxor (x:t) (y:t) : Pure t (requires True) (ensures (fun z -> v x `logxor` v y == v z)) (** Bitwise logical disjunction *) val logor (x:t) (y:t) : Pure t (requires True) (ensures (fun z -> v x `logor` v y == v z)) (** Bitwise logical negation *) val lognot (x:t) : Pure t (requires True) (ensures (fun z -> lognot (v x) == v z)) (**** Shift operators *) (** Shift right with zero fill, shifting at most the integer width *) val shift_right (a:t) (s:UInt32.t) : Pure t (requires (UInt32.v s < n)) (ensures (fun c -> FStar.UInt.shift_right (v a) (UInt32.v s) = v c)) (** Shift left with zero fill, shifting at most the integer width *) val shift_left (a:t) (s:UInt32.t) : Pure t (requires (UInt32.v s < n)) (ensures (fun c -> FStar.UInt.shift_left (v a) (UInt32.v s) = v c)) (**** Comparison operators *) (** Equality Note, it is safe to also use the polymorphic decidable equality operator [=] *) let eq (a:t) (b:t) : Tot bool = eq #n (v a) (v b) (** Greater than *) let gt (a:t) (b:t) : Tot bool = gt #n (v a) (v b) (** Greater than or equal *) let gte (a:t) (b:t) : Tot bool = gte #n (v a) (v b) (** Less than *) let lt (a:t) (b:t) : Tot bool = lt #n (v a) (v b) (** Less than or equal *) let lte (a:t) (b:t) : Tot bool = lte #n (v a) (v b) (** Unary negation *) inline_for_extraction let minus (a:t) = add_mod (lognot a) (uint_to_t 1) (** The maximum shift value for this type, i.e. its width minus one, as an UInt32. *) inline_for_extraction let n_minus_one = UInt32.uint_to_t (n - 1) #set-options "--z3rlimit 80 --initial_fuel 1 --max_fuel 1" (** A constant-time way to compute the equality of two machine integers. With inspiration from https://git.zx2c4.com/WireGuard/commit/src/crypto/curve25519-hacl64.h?id=2e60bb395c1f589a398ec606d611132ef9ef764b Note, the branching on [a=b] is just for proof-purposes. *) [@ CNoInline ] let eq_mask (a:t) (b:t) : Pure t (requires True) (ensures (fun c -> (v a = v b ==> v c = pow2 n - 1) /\ (v a <> v b ==> v c = 0))) = let x = logxor a b in let minus_x = minus x in let x_or_minus_x = logor x minus_x in let xnx = shift_right x_or_minus_x n_minus_one in let c = sub_mod xnx (uint_to_t 1) in if a = b then begin logxor_self (v a); lognot_lemma_1 #n; logor_lemma_1 (v x); assert (v x = 0 /\ v minus_x = 0 /\ v x_or_minus_x = 0 /\ v xnx = 0); assert (v c = ones n) end else begin logxor_neq_nonzero (v a) (v b); lemma_msb_pow2 #n (v (lognot x)); lemma_msb_pow2 #n (v minus_x); lemma_minus_zero #n (v x); assert (v c = FStar.UInt.zero n) end; c private val lemma_sub_msbs (a:t) (b:t) : Lemma ((msb (v a) = msb (v b)) ==> (v a < v b <==> msb (v (sub_mod a b)))) (** A constant-time way to compute the [>=] inequality of two machine integers. With inspiration from https://git.zx2c4.com/WireGuard/commit/src/crypto/curve25519-hacl64.h?id=0a483a9b431d87eca1b275463c632f8d5551978a *) [@ CNoInline ] let gte_mask (a:t) (b:t) : Pure t (requires True) (ensures (fun c -> (v a >= v b ==> v c = pow2 n - 1) /\ (v a < v b ==> v c = 0))) = let x = a in let y = b in let x_xor_y = logxor x y in let x_sub_y = sub_mod x y in let x_sub_y_xor_y = logxor x_sub_y y in let q = logor x_xor_y x_sub_y_xor_y in let x_xor_q = logxor x q in let x_xor_q_ = shift_right x_xor_q n_minus_one in let c = sub_mod x_xor_q_ (uint_to_t 1) in lemma_sub_msbs x y; lemma_msb_gte (v x) (v y); lemma_msb_gte (v y) (v x); c #reset-options (*** Infix notations *) unfold let op_Plus_Hat = add unfold let op_Plus_Question_Hat = add_underspec unfold let op_Plus_Percent_Hat = add_mod unfold let op_Subtraction_Hat = sub unfold let op_Subtraction_Question_Hat = sub_underspec unfold let op_Subtraction_Percent_Hat = sub_mod unfold let op_Star_Hat = mul unfold let op_Star_Question_Hat = mul_underspec unfold let op_Star_Percent_Hat = mul_mod unfold let op_Slash_Hat = div unfold let op_Percent_Hat = rem
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.UInt32.fsti.checked", "FStar.UInt.fsti.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked" ], "interface_file": false, "source_file": "FStar.UInt64.fsti" }
[ { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.UInt", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.UInt", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
x: FStar.UInt64.t -> y: FStar.UInt64.t -> Prims.Pure FStar.UInt64.t
Prims.Pure
[]
[]
[ "FStar.UInt64.logand" ]
[]
false
false
false
false
false
let op_Amp_Hat =
logand
false
FStar.UInt64.fsti
FStar.UInt64.op_Greater_Greater_Hat
val op_Greater_Greater_Hat : a: FStar.UInt64.t -> s: FStar.UInt32.t -> Prims.Pure FStar.UInt64.t
let op_Greater_Greater_Hat = shift_right
{ "file_name": "ulib/FStar.UInt64.fsti", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 47, "end_line": 331, "start_col": 7, "start_line": 331 }
(* 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 FStar.UInt64 (**** THIS MODULE IS GENERATED AUTOMATICALLY USING [mk_int.sh], DO NOT EDIT DIRECTLY ****) unfold let n = 64 /// For FStar.UIntN.fstp: anything that you fix/update here should be /// reflected in [FStar.IntN.fstp], which is mostly a copy-paste of /// this module. /// /// Except, as compared to [FStar.IntN.fstp], here: /// - every occurrence of [int_t] has been replaced with [uint_t] /// - every occurrence of [@%] has been replaced with [%]. /// - some functions (e.g., add_underspec, etc.) are only defined here, not on signed integers /// This module provides an abstract type for machine integers of a /// given signedness and width. The interface is designed to be safe /// with respect to arithmetic underflow and overflow. /// Note, we have attempted several times to re-design this module to /// make it more amenable to normalization and to impose less overhead /// on the SMT solver when reasoning about machine integer /// arithmetic. The following github issue reports on the current /// status of that work. /// /// https://github.com/FStarLang/FStar/issues/1757 open FStar.UInt open FStar.Mul #set-options "--max_fuel 0 --max_ifuel 0" (** Abstract type of machine integers, with an underlying representation using a bounded mathematical integer *) new val t : eqtype (** A coercion that projects a bounded mathematical integer from a machine integer *) val v (x:t) : Tot (uint_t n) (** A coercion that injects a bounded mathematical integers into a machine integer *) val uint_to_t (x:uint_t n) : Pure t (requires True) (ensures (fun y -> v y = x)) (** Injection/projection inverse *) val uv_inv (x : t) : Lemma (ensures (uint_to_t (v x) == x)) [SMTPat (v x)] (** Projection/injection inverse *) val vu_inv (x : uint_t n) : Lemma (ensures (v (uint_to_t x) == x)) [SMTPat (uint_to_t x)] (** An alternate form of the injectivity of the [v] projection *) val v_inj (x1 x2: t): Lemma (requires (v x1 == v x2)) (ensures (x1 == x2)) (** Constants 0 and 1 *) val zero : x:t{v x = 0} val one : x:t{v x = 1} (**** Addition primitives *) (** Bounds-respecting addition The precondition enforces that the sum does not overflow, expressing the bound as an addition on mathematical integers *) val add (a:t) (b:t) : Pure t (requires (size (v a + v b) n)) (ensures (fun c -> v a + v b = v c)) (** Underspecified, possibly overflowing addition: The postcondition only enures that the result is the sum of the arguments in case there is no overflow *) val add_underspec (a:t) (b:t) : Pure t (requires True) (ensures (fun c -> size (v a + v b) n ==> v a + v b = v c)) (** Addition modulo [2^n] Machine integers can always be added, but the postcondition is now in terms of addition modulo [2^n] on mathematical integers *) val add_mod (a:t) (b:t) : Pure t (requires True) (ensures (fun c -> FStar.UInt.add_mod (v a) (v b) = v c)) (**** Subtraction primitives *) (** Bounds-respecting subtraction The precondition enforces that the difference does not underflow, expressing the bound as a difference on mathematical integers *) val sub (a:t) (b:t) : Pure t (requires (size (v a - v b) n)) (ensures (fun c -> v a - v b = v c)) (** Underspecified, possibly overflowing subtraction: The postcondition only enures that the result is the difference of the arguments in case there is no underflow *) val sub_underspec (a:t) (b:t) : Pure t (requires True) (ensures (fun c -> size (v a - v b) n ==> v a - v b = v c)) (** Subtraction modulo [2^n] Machine integers can always be subtractd, but the postcondition is now in terms of subtraction modulo [2^n] on mathematical integers *) val sub_mod (a:t) (b:t) : Pure t (requires True) (ensures (fun c -> FStar.UInt.sub_mod (v a) (v b) = v c)) (**** Multiplication primitives *) (** Bounds-respecting multiplication The precondition enforces that the product does not overflow, expressing the bound as a product on mathematical integers *) val mul (a:t) (b:t) : Pure t (requires (size (v a * v b) n)) (ensures (fun c -> v a * v b = v c)) (** Underspecified, possibly overflowing product The postcondition only enures that the result is the product of the arguments in case there is no overflow *) val mul_underspec (a:t) (b:t) : Pure t (requires True) (ensures (fun c -> size (v a * v b) n ==> v a * v b = v c)) (** Multiplication modulo [2^n] Machine integers can always be multiplied, but the postcondition is now in terms of product modulo [2^n] on mathematical integers *) val mul_mod (a:t) (b:t) : Pure t (requires True) (ensures (fun c -> FStar.UInt.mul_mod (v a) (v b) = v c)) (**** Division primitives *) (** Euclidean division of [a] and [b], with [b] non-zero *) val div (a:t) (b:t{v b <> 0}) : Pure t (requires (True)) (ensures (fun c -> v a / v b = v c)) (**** Modulo primitives *) (** Euclidean remainder The result is the modulus of [a] with respect to a non-zero [b] *) val rem (a:t) (b:t{v b <> 0}) : Pure t (requires True) (ensures (fun c -> FStar.UInt.mod (v a) (v b) = v c)) (**** Bitwise operators *) /// Also see FStar.BV (** Bitwise logical conjunction *) val logand (x:t) (y:t) : Pure t (requires True) (ensures (fun z -> v x `logand` v y = v z)) (** Bitwise logical exclusive-or *) val logxor (x:t) (y:t) : Pure t (requires True) (ensures (fun z -> v x `logxor` v y == v z)) (** Bitwise logical disjunction *) val logor (x:t) (y:t) : Pure t (requires True) (ensures (fun z -> v x `logor` v y == v z)) (** Bitwise logical negation *) val lognot (x:t) : Pure t (requires True) (ensures (fun z -> lognot (v x) == v z)) (**** Shift operators *) (** Shift right with zero fill, shifting at most the integer width *) val shift_right (a:t) (s:UInt32.t) : Pure t (requires (UInt32.v s < n)) (ensures (fun c -> FStar.UInt.shift_right (v a) (UInt32.v s) = v c)) (** Shift left with zero fill, shifting at most the integer width *) val shift_left (a:t) (s:UInt32.t) : Pure t (requires (UInt32.v s < n)) (ensures (fun c -> FStar.UInt.shift_left (v a) (UInt32.v s) = v c)) (**** Comparison operators *) (** Equality Note, it is safe to also use the polymorphic decidable equality operator [=] *) let eq (a:t) (b:t) : Tot bool = eq #n (v a) (v b) (** Greater than *) let gt (a:t) (b:t) : Tot bool = gt #n (v a) (v b) (** Greater than or equal *) let gte (a:t) (b:t) : Tot bool = gte #n (v a) (v b) (** Less than *) let lt (a:t) (b:t) : Tot bool = lt #n (v a) (v b) (** Less than or equal *) let lte (a:t) (b:t) : Tot bool = lte #n (v a) (v b) (** Unary negation *) inline_for_extraction let minus (a:t) = add_mod (lognot a) (uint_to_t 1) (** The maximum shift value for this type, i.e. its width minus one, as an UInt32. *) inline_for_extraction let n_minus_one = UInt32.uint_to_t (n - 1) #set-options "--z3rlimit 80 --initial_fuel 1 --max_fuel 1" (** A constant-time way to compute the equality of two machine integers. With inspiration from https://git.zx2c4.com/WireGuard/commit/src/crypto/curve25519-hacl64.h?id=2e60bb395c1f589a398ec606d611132ef9ef764b Note, the branching on [a=b] is just for proof-purposes. *) [@ CNoInline ] let eq_mask (a:t) (b:t) : Pure t (requires True) (ensures (fun c -> (v a = v b ==> v c = pow2 n - 1) /\ (v a <> v b ==> v c = 0))) = let x = logxor a b in let minus_x = minus x in let x_or_minus_x = logor x minus_x in let xnx = shift_right x_or_minus_x n_minus_one in let c = sub_mod xnx (uint_to_t 1) in if a = b then begin logxor_self (v a); lognot_lemma_1 #n; logor_lemma_1 (v x); assert (v x = 0 /\ v minus_x = 0 /\ v x_or_minus_x = 0 /\ v xnx = 0); assert (v c = ones n) end else begin logxor_neq_nonzero (v a) (v b); lemma_msb_pow2 #n (v (lognot x)); lemma_msb_pow2 #n (v minus_x); lemma_minus_zero #n (v x); assert (v c = FStar.UInt.zero n) end; c private val lemma_sub_msbs (a:t) (b:t) : Lemma ((msb (v a) = msb (v b)) ==> (v a < v b <==> msb (v (sub_mod a b)))) (** A constant-time way to compute the [>=] inequality of two machine integers. With inspiration from https://git.zx2c4.com/WireGuard/commit/src/crypto/curve25519-hacl64.h?id=0a483a9b431d87eca1b275463c632f8d5551978a *) [@ CNoInline ] let gte_mask (a:t) (b:t) : Pure t (requires True) (ensures (fun c -> (v a >= v b ==> v c = pow2 n - 1) /\ (v a < v b ==> v c = 0))) = let x = a in let y = b in let x_xor_y = logxor x y in let x_sub_y = sub_mod x y in let x_sub_y_xor_y = logxor x_sub_y y in let q = logor x_xor_y x_sub_y_xor_y in let x_xor_q = logxor x q in let x_xor_q_ = shift_right x_xor_q n_minus_one in let c = sub_mod x_xor_q_ (uint_to_t 1) in lemma_sub_msbs x y; lemma_msb_gte (v x) (v y); lemma_msb_gte (v y) (v x); c #reset-options (*** Infix notations *) unfold let op_Plus_Hat = add unfold let op_Plus_Question_Hat = add_underspec unfold let op_Plus_Percent_Hat = add_mod unfold let op_Subtraction_Hat = sub unfold let op_Subtraction_Question_Hat = sub_underspec unfold let op_Subtraction_Percent_Hat = sub_mod unfold let op_Star_Hat = mul unfold let op_Star_Question_Hat = mul_underspec unfold let op_Star_Percent_Hat = mul_mod unfold let op_Slash_Hat = div unfold let op_Percent_Hat = rem unfold let op_Hat_Hat = logxor unfold let op_Amp_Hat = logand unfold let op_Bar_Hat = logor
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.UInt32.fsti.checked", "FStar.UInt.fsti.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked" ], "interface_file": false, "source_file": "FStar.UInt64.fsti" }
[ { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.UInt", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.UInt", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "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: FStar.UInt64.t -> s: FStar.UInt32.t -> Prims.Pure FStar.UInt64.t
Prims.Pure
[]
[]
[ "FStar.UInt64.shift_right" ]
[]
false
false
false
false
false
let op_Greater_Greater_Hat =
shift_right
false
FStar.UInt64.fsti
FStar.UInt64.op_Star_Percent_Hat
val op_Star_Percent_Hat : a: FStar.UInt64.t -> b: FStar.UInt64.t -> Prims.Pure FStar.UInt64.t
let op_Star_Percent_Hat = mul_mod
{ "file_name": "ulib/FStar.UInt64.fsti", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 40, "end_line": 324, "start_col": 7, "start_line": 324 }
(* 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 FStar.UInt64 (**** THIS MODULE IS GENERATED AUTOMATICALLY USING [mk_int.sh], DO NOT EDIT DIRECTLY ****) unfold let n = 64 /// For FStar.UIntN.fstp: anything that you fix/update here should be /// reflected in [FStar.IntN.fstp], which is mostly a copy-paste of /// this module. /// /// Except, as compared to [FStar.IntN.fstp], here: /// - every occurrence of [int_t] has been replaced with [uint_t] /// - every occurrence of [@%] has been replaced with [%]. /// - some functions (e.g., add_underspec, etc.) are only defined here, not on signed integers /// This module provides an abstract type for machine integers of a /// given signedness and width. The interface is designed to be safe /// with respect to arithmetic underflow and overflow. /// Note, we have attempted several times to re-design this module to /// make it more amenable to normalization and to impose less overhead /// on the SMT solver when reasoning about machine integer /// arithmetic. The following github issue reports on the current /// status of that work. /// /// https://github.com/FStarLang/FStar/issues/1757 open FStar.UInt open FStar.Mul #set-options "--max_fuel 0 --max_ifuel 0" (** Abstract type of machine integers, with an underlying representation using a bounded mathematical integer *) new val t : eqtype (** A coercion that projects a bounded mathematical integer from a machine integer *) val v (x:t) : Tot (uint_t n) (** A coercion that injects a bounded mathematical integers into a machine integer *) val uint_to_t (x:uint_t n) : Pure t (requires True) (ensures (fun y -> v y = x)) (** Injection/projection inverse *) val uv_inv (x : t) : Lemma (ensures (uint_to_t (v x) == x)) [SMTPat (v x)] (** Projection/injection inverse *) val vu_inv (x : uint_t n) : Lemma (ensures (v (uint_to_t x) == x)) [SMTPat (uint_to_t x)] (** An alternate form of the injectivity of the [v] projection *) val v_inj (x1 x2: t): Lemma (requires (v x1 == v x2)) (ensures (x1 == x2)) (** Constants 0 and 1 *) val zero : x:t{v x = 0} val one : x:t{v x = 1} (**** Addition primitives *) (** Bounds-respecting addition The precondition enforces that the sum does not overflow, expressing the bound as an addition on mathematical integers *) val add (a:t) (b:t) : Pure t (requires (size (v a + v b) n)) (ensures (fun c -> v a + v b = v c)) (** Underspecified, possibly overflowing addition: The postcondition only enures that the result is the sum of the arguments in case there is no overflow *) val add_underspec (a:t) (b:t) : Pure t (requires True) (ensures (fun c -> size (v a + v b) n ==> v a + v b = v c)) (** Addition modulo [2^n] Machine integers can always be added, but the postcondition is now in terms of addition modulo [2^n] on mathematical integers *) val add_mod (a:t) (b:t) : Pure t (requires True) (ensures (fun c -> FStar.UInt.add_mod (v a) (v b) = v c)) (**** Subtraction primitives *) (** Bounds-respecting subtraction The precondition enforces that the difference does not underflow, expressing the bound as a difference on mathematical integers *) val sub (a:t) (b:t) : Pure t (requires (size (v a - v b) n)) (ensures (fun c -> v a - v b = v c)) (** Underspecified, possibly overflowing subtraction: The postcondition only enures that the result is the difference of the arguments in case there is no underflow *) val sub_underspec (a:t) (b:t) : Pure t (requires True) (ensures (fun c -> size (v a - v b) n ==> v a - v b = v c)) (** Subtraction modulo [2^n] Machine integers can always be subtractd, but the postcondition is now in terms of subtraction modulo [2^n] on mathematical integers *) val sub_mod (a:t) (b:t) : Pure t (requires True) (ensures (fun c -> FStar.UInt.sub_mod (v a) (v b) = v c)) (**** Multiplication primitives *) (** Bounds-respecting multiplication The precondition enforces that the product does not overflow, expressing the bound as a product on mathematical integers *) val mul (a:t) (b:t) : Pure t (requires (size (v a * v b) n)) (ensures (fun c -> v a * v b = v c)) (** Underspecified, possibly overflowing product The postcondition only enures that the result is the product of the arguments in case there is no overflow *) val mul_underspec (a:t) (b:t) : Pure t (requires True) (ensures (fun c -> size (v a * v b) n ==> v a * v b = v c)) (** Multiplication modulo [2^n] Machine integers can always be multiplied, but the postcondition is now in terms of product modulo [2^n] on mathematical integers *) val mul_mod (a:t) (b:t) : Pure t (requires True) (ensures (fun c -> FStar.UInt.mul_mod (v a) (v b) = v c)) (**** Division primitives *) (** Euclidean division of [a] and [b], with [b] non-zero *) val div (a:t) (b:t{v b <> 0}) : Pure t (requires (True)) (ensures (fun c -> v a / v b = v c)) (**** Modulo primitives *) (** Euclidean remainder The result is the modulus of [a] with respect to a non-zero [b] *) val rem (a:t) (b:t{v b <> 0}) : Pure t (requires True) (ensures (fun c -> FStar.UInt.mod (v a) (v b) = v c)) (**** Bitwise operators *) /// Also see FStar.BV (** Bitwise logical conjunction *) val logand (x:t) (y:t) : Pure t (requires True) (ensures (fun z -> v x `logand` v y = v z)) (** Bitwise logical exclusive-or *) val logxor (x:t) (y:t) : Pure t (requires True) (ensures (fun z -> v x `logxor` v y == v z)) (** Bitwise logical disjunction *) val logor (x:t) (y:t) : Pure t (requires True) (ensures (fun z -> v x `logor` v y == v z)) (** Bitwise logical negation *) val lognot (x:t) : Pure t (requires True) (ensures (fun z -> lognot (v x) == v z)) (**** Shift operators *) (** Shift right with zero fill, shifting at most the integer width *) val shift_right (a:t) (s:UInt32.t) : Pure t (requires (UInt32.v s < n)) (ensures (fun c -> FStar.UInt.shift_right (v a) (UInt32.v s) = v c)) (** Shift left with zero fill, shifting at most the integer width *) val shift_left (a:t) (s:UInt32.t) : Pure t (requires (UInt32.v s < n)) (ensures (fun c -> FStar.UInt.shift_left (v a) (UInt32.v s) = v c)) (**** Comparison operators *) (** Equality Note, it is safe to also use the polymorphic decidable equality operator [=] *) let eq (a:t) (b:t) : Tot bool = eq #n (v a) (v b) (** Greater than *) let gt (a:t) (b:t) : Tot bool = gt #n (v a) (v b) (** Greater than or equal *) let gte (a:t) (b:t) : Tot bool = gte #n (v a) (v b) (** Less than *) let lt (a:t) (b:t) : Tot bool = lt #n (v a) (v b) (** Less than or equal *) let lte (a:t) (b:t) : Tot bool = lte #n (v a) (v b) (** Unary negation *) inline_for_extraction let minus (a:t) = add_mod (lognot a) (uint_to_t 1) (** The maximum shift value for this type, i.e. its width minus one, as an UInt32. *) inline_for_extraction let n_minus_one = UInt32.uint_to_t (n - 1) #set-options "--z3rlimit 80 --initial_fuel 1 --max_fuel 1" (** A constant-time way to compute the equality of two machine integers. With inspiration from https://git.zx2c4.com/WireGuard/commit/src/crypto/curve25519-hacl64.h?id=2e60bb395c1f589a398ec606d611132ef9ef764b Note, the branching on [a=b] is just for proof-purposes. *) [@ CNoInline ] let eq_mask (a:t) (b:t) : Pure t (requires True) (ensures (fun c -> (v a = v b ==> v c = pow2 n - 1) /\ (v a <> v b ==> v c = 0))) = let x = logxor a b in let minus_x = minus x in let x_or_minus_x = logor x minus_x in let xnx = shift_right x_or_minus_x n_minus_one in let c = sub_mod xnx (uint_to_t 1) in if a = b then begin logxor_self (v a); lognot_lemma_1 #n; logor_lemma_1 (v x); assert (v x = 0 /\ v minus_x = 0 /\ v x_or_minus_x = 0 /\ v xnx = 0); assert (v c = ones n) end else begin logxor_neq_nonzero (v a) (v b); lemma_msb_pow2 #n (v (lognot x)); lemma_msb_pow2 #n (v minus_x); lemma_minus_zero #n (v x); assert (v c = FStar.UInt.zero n) end; c private val lemma_sub_msbs (a:t) (b:t) : Lemma ((msb (v a) = msb (v b)) ==> (v a < v b <==> msb (v (sub_mod a b)))) (** A constant-time way to compute the [>=] inequality of two machine integers. With inspiration from https://git.zx2c4.com/WireGuard/commit/src/crypto/curve25519-hacl64.h?id=0a483a9b431d87eca1b275463c632f8d5551978a *) [@ CNoInline ] let gte_mask (a:t) (b:t) : Pure t (requires True) (ensures (fun c -> (v a >= v b ==> v c = pow2 n - 1) /\ (v a < v b ==> v c = 0))) = let x = a in let y = b in let x_xor_y = logxor x y in let x_sub_y = sub_mod x y in let x_sub_y_xor_y = logxor x_sub_y y in let q = logor x_xor_y x_sub_y_xor_y in let x_xor_q = logxor x q in let x_xor_q_ = shift_right x_xor_q n_minus_one in let c = sub_mod x_xor_q_ (uint_to_t 1) in lemma_sub_msbs x y; lemma_msb_gte (v x) (v y); lemma_msb_gte (v y) (v x); c #reset-options (*** Infix notations *) unfold let op_Plus_Hat = add unfold let op_Plus_Question_Hat = add_underspec unfold let op_Plus_Percent_Hat = add_mod unfold let op_Subtraction_Hat = sub unfold let op_Subtraction_Question_Hat = sub_underspec unfold let op_Subtraction_Percent_Hat = sub_mod unfold let op_Star_Hat = mul
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.UInt32.fsti.checked", "FStar.UInt.fsti.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked" ], "interface_file": false, "source_file": "FStar.UInt64.fsti" }
[ { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.UInt", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.UInt", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "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: FStar.UInt64.t -> b: FStar.UInt64.t -> Prims.Pure FStar.UInt64.t
Prims.Pure
[]
[]
[ "FStar.UInt64.mul_mod" ]
[]
false
false
false
false
false
let op_Star_Percent_Hat =
mul_mod
false
LowParse.Low.BCVLI.fst
LowParse.Low.BCVLI.jump_bounded_bcvli
val jump_bounded_bcvli (min: nat) (max: nat{min <= max}) : Tot (jumper (parse_bounded_bcvli min max))
val jump_bounded_bcvli (min: nat) (max: nat{min <= max}) : Tot (jumper (parse_bounded_bcvli min max))
let jump_bounded_bcvli (min: nat) (max: nat { min <= max }) : Tot (jumper (parse_bounded_bcvli min max)) = fun #rrel #rel input pos -> let h = HST.get () in [@inline_let] let _ = valid_facts (parse_bounded_bcvli min max) h input pos; parse_bounded_bcvli_eq min max (bytes_of_slice_from h input pos); valid_facts parse_bcvli h input pos in jump_bcvli input pos
{ "file_name": "src/lowparse/LowParse.Low.BCVLI.fst", "git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
{ "end_col": 24, "end_line": 257, "start_col": 0, "start_line": 245 }
module LowParse.Low.BCVLI include LowParse.Spec.BCVLI include LowParse.Low.Combinators include LowParse.Low.BoundedInt module B = LowStar.Buffer module HST = FStar.HyperStack.ST module Cast = FStar.Int.Cast module U32 = FStar.UInt32 module U64 = FStar.UInt64 #reset-options "--z3cliopt smt.arith.nl=false --max_fuel 0" #push-options "--z3rlimit 16" let validate_bcvli : validator parse_bcvli = fun #rrel #rel input pos -> let h = HST.get () in [@inline_let] let _ = valid_facts parse_bcvli h input (uint64_to_uint32 pos); parse_bcvli_eq (bytes_of_slice_from h input (uint64_to_uint32 pos)); valid_facts (parse_bounded_integer_le 1) h input (uint64_to_uint32 pos) in let pos1 = validate_total_constant_size (parse_bounded_integer_le 1) 1uL () input pos in if is_error pos1 then pos1 else [@inline_let] let _ = valid_facts (parse_bounded_integer_le 2) h input (uint64_to_uint32 pos1); valid_facts (parse_bounded_integer_le 4) h input (uint64_to_uint32 pos1) in let r = read_bounded_integer_le_1 input (uint64_to_uint32 pos) in if r `U32.lt` 253ul then pos1 else if r = 253ul then let pos2 = validate_total_constant_size (parse_bounded_integer_le 2) 2uL () input pos1 in if is_error pos2 then pos2 else (* because of the non-malleability constraint, I need to actually read the value and check whether it is not a lower integer *) let r = read_bounded_integer_le_2 input (uint64_to_uint32 pos1) in if r `U32.lt` 253ul then validator_error_generic else pos2 else if r = 254ul then let pos2 = validate_total_constant_size (parse_bounded_integer_le 4) 4uL () input pos1 in if is_error pos2 then pos2 else (* because of the non-malleability constraint, I need to actually read the value and check whether it is not a lower integer *) let r = read_bounded_integer_le_4 input (uint64_to_uint32 pos1) in if r `U32.lt` 65536ul then validator_error_generic else pos2 else validator_error_generic let jump_bcvli : jumper parse_bcvli = fun #rrel #rel input pos -> let h = HST.get () in [@inline_let] let _ = valid_facts parse_bcvli h input pos; parse_bcvli_eq (bytes_of_slice_from h input pos); valid_facts (parse_bounded_integer_le 1) h input pos in let pos1 = jump_constant_size (parse_bounded_integer_le 1) 1ul () input pos in [@inline_let] let _ = valid_facts (parse_bounded_integer_le 2) h input pos1; valid_facts (parse_bounded_integer_le 4) h input pos1 in let r = read_bounded_integer_le_1 input pos in if r `U32.lt` 253ul then pos1 else if r = 253ul then jump_constant_size (parse_bounded_integer_le 2) 2ul () input pos1 else jump_constant_size (parse_bounded_integer_le 4) 4ul () input pos1 let read_bcvli : leaf_reader parse_bcvli = fun #rrel #rel input pos -> let h = HST.get () in [@inline_let] let _ = valid_facts parse_bcvli h input pos; parse_bcvli_eq (bytes_of_slice_from h input pos); valid_facts (parse_bounded_integer_le 1) h input pos in let r = read_bounded_integer_le_1 input pos in if r `U32.lt` 253ul then (r <: U32.t) else let pos1 = jump_constant_size (parse_bounded_integer_le 1) 1ul () input pos in [@inline_let] let _ = valid_facts (parse_bounded_integer_le 2) h input pos1; valid_facts (parse_bounded_integer_le 4) h input pos1 in if r = 253ul then read_bounded_integer_le_2 input pos1 <: U32.t else read_bounded_integer_le_4 input pos1 <: U32.t #pop-options module U8 = FStar.UInt8 #push-options "--z3rlimit 32" inline_for_extraction let serialize32_bcvli' (x: U32.t) (#rrel #rel: _) (b: B.mbuffer U8.t rrel rel) (pos: U32.t) : HST.Stack U32.t (requires (fun h -> let len = Seq.length (serialize serialize_bcvli x) in B.live h b /\ U32.v pos + len <= B.length b /\ writable b (U32.v pos) (U32.v pos + len) h )) (ensures (fun h len h' -> Seq.length (serialize serialize_bcvli x) == U32.v len /\ ( B.modifies (B.loc_buffer_from_to b pos (pos `U32.add` len)) h h' /\ B.live h b /\ Seq.slice (B.as_seq h' b) (U32.v pos) (U32.v pos + U32.v len) `Seq.equal` serialize serialize_bcvli x ))) = // [@inline_let] let _ = serialize_bcvli_eq x ; // in let c : bounded_integer 1 = if x `U32.lt` 253ul then x else if x `U32.lt` 65536ul then 253ul else 254ul in [@inline_let] let pos' = Ghost.hide (U32.v pos + Seq.length (serialize serialize_bcvli x)) in let h = HST.get () in [@inline_let] let _ = writable_weaken b (U32.v pos) (Ghost.reveal pos') h (U32.v pos) (U32.v pos + 1) in let len1 = serialize32_bounded_integer_le_1 c b pos in let h1 = HST.get () in [@inline_let] let _ = writable_modifies b (U32.v pos) (Ghost.reveal pos') h B.loc_none h1 in if c `U32.lt` 253ul then begin len1 end else if c = 253ul then begin [@inline_let] let _ = assert (U32.v x < 65536) in [@inline_let] let _ = writable_weaken b (U32.v pos) (Ghost.reveal pos') h1 (U32.v pos + U32.v len1) ((U32.v pos + U32.v len1) + 2) in let len2 = serialize32_bounded_integer_le_2 x b (pos `U32.add` len1) in let h' = HST.get () in [@inline_let] let len = len1 `U32.add` len2 in B.modifies_buffer_from_to_elim b pos (pos `U32.add` len1) (B.loc_buffer_from_to b (pos `U32.add` len1) (pos `U32.add` len)) h1 h'; len end else begin [@inline_let] let _ = writable_weaken b (U32.v pos) (Ghost.reveal pos') h1 (U32.v pos + U32.v len1) ((U32.v pos + U32.v len1) + 4) in let len2 = serialize32_bounded_integer_le_4 x b (pos `U32.add` len1) in let h' = HST.get () in [@inline_let] let len = len1 `U32.add` len2 in B.modifies_buffer_from_to_elim b pos (pos `U32.add` len1) (B.loc_buffer_from_to b (pos `U32.add` len1) (pos `U32.add` len)) h1 h'; len end inline_for_extraction let serialize32_bcvli : serializer32 serialize_bcvli = fun (x: U32.t) #rrel #rel b pos -> serialize32_bcvli' x b pos let write_bcvli : leaf_writer_strong serialize_bcvli = leaf_writer_strong_of_serializer32 serialize32_bcvli () let validate_bounded_bcvli' (min32: U32.t) (max32: U32.t { U32.v min32 <= U32.v max32 }) : Tot (validator (parse_bounded_bcvli (U32.v min32) (U32.v max32))) = fun #rrel #rel input pos -> let h = HST.get () in [@inline_let] let _ = valid_facts (parse_bounded_bcvli (U32.v min32) (U32.v max32)) h input (uint64_to_uint32 pos); parse_bounded_bcvli_eq (U32.v min32) (U32.v max32) (bytes_of_slice_from h input (uint64_to_uint32 pos)); parse_bcvli_eq (bytes_of_slice_from h input (uint64_to_uint32 pos)); valid_facts (parse_bounded_integer_le 1) h input (uint64_to_uint32 pos) in let pos1 = validate_total_constant_size (parse_bounded_integer_le 1) 1uL () input pos in if is_error pos1 then pos1 else [@inline_let] let _ = valid_facts (parse_bounded_integer_le 2) h input (uint64_to_uint32 pos1); valid_facts (parse_bounded_integer_le 4) h input (uint64_to_uint32 pos1) in let r = read_bounded_integer_le_1 input (uint64_to_uint32 pos) in if r `U32.lt` 253ul && min32 `U32.lte` r && r `U32.lte` max32 then pos1 else if max32 `U32.lt` 253ul then validator_error_generic else if r = 253ul then if 65536ul `U32.lte` min32 then validator_error_generic else let pos2 = validate_total_constant_size (parse_bounded_integer_le 2) 2uL () input pos1 in if is_error pos2 then pos2 else (* because of the non-malleability constraint, I need to actually read the value and check whether it is not a lower integer *) let r = read_bounded_integer_le_2 input (uint64_to_uint32 pos1) in if r `U32.lt` 253ul || r `U32.lt` min32 || max32 `U32.lt` r then validator_error_generic else pos2 else if max32 `U32.lt` 65536ul then validator_error_generic else if r = 254ul then let pos2 = validate_total_constant_size (parse_bounded_integer_le 4) 4uL () input pos1 in if is_error pos2 then pos2 else (* because of the non-malleability constraint, I need to actually read the value and check whether it is not a lower integer *) let r = read_bounded_integer_le_4 input (uint64_to_uint32 pos1) in if r `U32.lt` 65536ul || r `U32.lt` min32 || max32 `U32.lt` r then validator_error_generic else pos2 else validator_error_generic inline_for_extraction noextract let validate_bounded_bcvli (min: nat) (min32: U32.t { U32.v min32 == min }) (max: nat { min <= max }) (max32: U32.t { U32.v max32 == max }) : Tot (validator (parse_bounded_bcvli min max)) = validate_bounded_bcvli' min32 max32 inline_for_extraction
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowStar.Buffer.fst.checked", "LowParse.Spec.BCVLI.fsti.checked", "LowParse.Low.Combinators.fsti.checked", "LowParse.Low.BoundedInt.fsti.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.Ghost.fsti.checked" ], "interface_file": false, "source_file": "LowParse.Low.BCVLI.fst" }
[ { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": true, "full_module": "FStar.Int.Cast", "short_module": "Cast" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": false, "full_module": "LowParse.Low.BoundedInt", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low.Combinators", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec.BCVLI", "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": 0, "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": [ "smt.arith.nl=false" ], "z3refresh": false, "z3rlimit": 32, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
min: Prims.nat -> max: Prims.nat{min <= max} -> LowParse.Low.Base.jumper (LowParse.Spec.BCVLI.parse_bounded_bcvli min max)
Prims.Tot
[ "total" ]
[]
[ "Prims.nat", "Prims.b2t", "Prims.op_LessThanOrEqual", "LowParse.Slice.srel", "LowParse.Bytes.byte", "LowParse.Slice.slice", "FStar.UInt32.t", "LowParse.Low.BCVLI.jump_bcvli", "Prims.unit", "LowParse.Low.Base.Spec.valid_facts", "LowParse.Spec.BCVLI.parse_bcvli_kind", "LowParse.Spec.BCVLI.parse_bcvli", "LowParse.Spec.BCVLI.parse_bounded_bcvli_eq", "LowParse.Slice.bytes_of_slice_from", "LowParse.Spec.BCVLI.parse_bounded_bcvli_kind", "LowParse.Spec.BoundedInt.bounded_int32", "LowParse.Spec.BCVLI.parse_bounded_bcvli", "FStar.Monotonic.HyperStack.mem", "FStar.HyperStack.ST.get", "LowParse.Low.Base.jumper" ]
[]
false
false
false
false
false
let jump_bounded_bcvli (min: nat) (max: nat{min <= max}) : Tot (jumper (parse_bounded_bcvli min max)) =
fun #rrel #rel input pos -> let h = HST.get () in [@@ inline_let ]let _ = valid_facts (parse_bounded_bcvli min max) h input pos; parse_bounded_bcvli_eq min max (bytes_of_slice_from h input pos); valid_facts parse_bcvli h input pos in jump_bcvli input pos
false
FStar.UInt64.fsti
FStar.UInt64.minus
val minus : a: FStar.UInt64.t -> FStar.UInt64.t
let minus (a:t) = add_mod (lognot a) (uint_to_t 1)
{ "file_name": "ulib/FStar.UInt64.fsti", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 50, "end_line": 239, "start_col": 0, "start_line": 239 }
(* 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 FStar.UInt64 (**** THIS MODULE IS GENERATED AUTOMATICALLY USING [mk_int.sh], DO NOT EDIT DIRECTLY ****) unfold let n = 64 /// For FStar.UIntN.fstp: anything that you fix/update here should be /// reflected in [FStar.IntN.fstp], which is mostly a copy-paste of /// this module. /// /// Except, as compared to [FStar.IntN.fstp], here: /// - every occurrence of [int_t] has been replaced with [uint_t] /// - every occurrence of [@%] has been replaced with [%]. /// - some functions (e.g., add_underspec, etc.) are only defined here, not on signed integers /// This module provides an abstract type for machine integers of a /// given signedness and width. The interface is designed to be safe /// with respect to arithmetic underflow and overflow. /// Note, we have attempted several times to re-design this module to /// make it more amenable to normalization and to impose less overhead /// on the SMT solver when reasoning about machine integer /// arithmetic. The following github issue reports on the current /// status of that work. /// /// https://github.com/FStarLang/FStar/issues/1757 open FStar.UInt open FStar.Mul #set-options "--max_fuel 0 --max_ifuel 0" (** Abstract type of machine integers, with an underlying representation using a bounded mathematical integer *) new val t : eqtype (** A coercion that projects a bounded mathematical integer from a machine integer *) val v (x:t) : Tot (uint_t n) (** A coercion that injects a bounded mathematical integers into a machine integer *) val uint_to_t (x:uint_t n) : Pure t (requires True) (ensures (fun y -> v y = x)) (** Injection/projection inverse *) val uv_inv (x : t) : Lemma (ensures (uint_to_t (v x) == x)) [SMTPat (v x)] (** Projection/injection inverse *) val vu_inv (x : uint_t n) : Lemma (ensures (v (uint_to_t x) == x)) [SMTPat (uint_to_t x)] (** An alternate form of the injectivity of the [v] projection *) val v_inj (x1 x2: t): Lemma (requires (v x1 == v x2)) (ensures (x1 == x2)) (** Constants 0 and 1 *) val zero : x:t{v x = 0} val one : x:t{v x = 1} (**** Addition primitives *) (** Bounds-respecting addition The precondition enforces that the sum does not overflow, expressing the bound as an addition on mathematical integers *) val add (a:t) (b:t) : Pure t (requires (size (v a + v b) n)) (ensures (fun c -> v a + v b = v c)) (** Underspecified, possibly overflowing addition: The postcondition only enures that the result is the sum of the arguments in case there is no overflow *) val add_underspec (a:t) (b:t) : Pure t (requires True) (ensures (fun c -> size (v a + v b) n ==> v a + v b = v c)) (** Addition modulo [2^n] Machine integers can always be added, but the postcondition is now in terms of addition modulo [2^n] on mathematical integers *) val add_mod (a:t) (b:t) : Pure t (requires True) (ensures (fun c -> FStar.UInt.add_mod (v a) (v b) = v c)) (**** Subtraction primitives *) (** Bounds-respecting subtraction The precondition enforces that the difference does not underflow, expressing the bound as a difference on mathematical integers *) val sub (a:t) (b:t) : Pure t (requires (size (v a - v b) n)) (ensures (fun c -> v a - v b = v c)) (** Underspecified, possibly overflowing subtraction: The postcondition only enures that the result is the difference of the arguments in case there is no underflow *) val sub_underspec (a:t) (b:t) : Pure t (requires True) (ensures (fun c -> size (v a - v b) n ==> v a - v b = v c)) (** Subtraction modulo [2^n] Machine integers can always be subtractd, but the postcondition is now in terms of subtraction modulo [2^n] on mathematical integers *) val sub_mod (a:t) (b:t) : Pure t (requires True) (ensures (fun c -> FStar.UInt.sub_mod (v a) (v b) = v c)) (**** Multiplication primitives *) (** Bounds-respecting multiplication The precondition enforces that the product does not overflow, expressing the bound as a product on mathematical integers *) val mul (a:t) (b:t) : Pure t (requires (size (v a * v b) n)) (ensures (fun c -> v a * v b = v c)) (** Underspecified, possibly overflowing product The postcondition only enures that the result is the product of the arguments in case there is no overflow *) val mul_underspec (a:t) (b:t) : Pure t (requires True) (ensures (fun c -> size (v a * v b) n ==> v a * v b = v c)) (** Multiplication modulo [2^n] Machine integers can always be multiplied, but the postcondition is now in terms of product modulo [2^n] on mathematical integers *) val mul_mod (a:t) (b:t) : Pure t (requires True) (ensures (fun c -> FStar.UInt.mul_mod (v a) (v b) = v c)) (**** Division primitives *) (** Euclidean division of [a] and [b], with [b] non-zero *) val div (a:t) (b:t{v b <> 0}) : Pure t (requires (True)) (ensures (fun c -> v a / v b = v c)) (**** Modulo primitives *) (** Euclidean remainder The result is the modulus of [a] with respect to a non-zero [b] *) val rem (a:t) (b:t{v b <> 0}) : Pure t (requires True) (ensures (fun c -> FStar.UInt.mod (v a) (v b) = v c)) (**** Bitwise operators *) /// Also see FStar.BV (** Bitwise logical conjunction *) val logand (x:t) (y:t) : Pure t (requires True) (ensures (fun z -> v x `logand` v y = v z)) (** Bitwise logical exclusive-or *) val logxor (x:t) (y:t) : Pure t (requires True) (ensures (fun z -> v x `logxor` v y == v z)) (** Bitwise logical disjunction *) val logor (x:t) (y:t) : Pure t (requires True) (ensures (fun z -> v x `logor` v y == v z)) (** Bitwise logical negation *) val lognot (x:t) : Pure t (requires True) (ensures (fun z -> lognot (v x) == v z)) (**** Shift operators *) (** Shift right with zero fill, shifting at most the integer width *) val shift_right (a:t) (s:UInt32.t) : Pure t (requires (UInt32.v s < n)) (ensures (fun c -> FStar.UInt.shift_right (v a) (UInt32.v s) = v c)) (** Shift left with zero fill, shifting at most the integer width *) val shift_left (a:t) (s:UInt32.t) : Pure t (requires (UInt32.v s < n)) (ensures (fun c -> FStar.UInt.shift_left (v a) (UInt32.v s) = v c)) (**** Comparison operators *) (** Equality Note, it is safe to also use the polymorphic decidable equality operator [=] *) let eq (a:t) (b:t) : Tot bool = eq #n (v a) (v b) (** Greater than *) let gt (a:t) (b:t) : Tot bool = gt #n (v a) (v b) (** Greater than or equal *) let gte (a:t) (b:t) : Tot bool = gte #n (v a) (v b) (** Less than *) let lt (a:t) (b:t) : Tot bool = lt #n (v a) (v b) (** Less than or equal *) let lte (a:t) (b:t) : Tot bool = lte #n (v a) (v b) (** Unary negation *)
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.UInt32.fsti.checked", "FStar.UInt.fsti.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked" ], "interface_file": false, "source_file": "FStar.UInt64.fsti" }
[ { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.UInt", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.UInt", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
a: FStar.UInt64.t -> FStar.UInt64.t
Prims.Tot
[ "total" ]
[]
[ "FStar.UInt64.t", "FStar.UInt64.add_mod", "FStar.UInt64.lognot", "FStar.UInt64.uint_to_t" ]
[]
false
false
false
true
false
let minus (a: t) =
add_mod (lognot a) (uint_to_t 1)
false
FStar.UInt64.fsti
FStar.UInt64.op_Bar_Hat
val op_Bar_Hat : x: FStar.UInt64.t -> y: FStar.UInt64.t -> Prims.Pure FStar.UInt64.t
let op_Bar_Hat = logor
{ "file_name": "ulib/FStar.UInt64.fsti", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 29, "end_line": 329, "start_col": 7, "start_line": 329 }
(* 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 FStar.UInt64 (**** THIS MODULE IS GENERATED AUTOMATICALLY USING [mk_int.sh], DO NOT EDIT DIRECTLY ****) unfold let n = 64 /// For FStar.UIntN.fstp: anything that you fix/update here should be /// reflected in [FStar.IntN.fstp], which is mostly a copy-paste of /// this module. /// /// Except, as compared to [FStar.IntN.fstp], here: /// - every occurrence of [int_t] has been replaced with [uint_t] /// - every occurrence of [@%] has been replaced with [%]. /// - some functions (e.g., add_underspec, etc.) are only defined here, not on signed integers /// This module provides an abstract type for machine integers of a /// given signedness and width. The interface is designed to be safe /// with respect to arithmetic underflow and overflow. /// Note, we have attempted several times to re-design this module to /// make it more amenable to normalization and to impose less overhead /// on the SMT solver when reasoning about machine integer /// arithmetic. The following github issue reports on the current /// status of that work. /// /// https://github.com/FStarLang/FStar/issues/1757 open FStar.UInt open FStar.Mul #set-options "--max_fuel 0 --max_ifuel 0" (** Abstract type of machine integers, with an underlying representation using a bounded mathematical integer *) new val t : eqtype (** A coercion that projects a bounded mathematical integer from a machine integer *) val v (x:t) : Tot (uint_t n) (** A coercion that injects a bounded mathematical integers into a machine integer *) val uint_to_t (x:uint_t n) : Pure t (requires True) (ensures (fun y -> v y = x)) (** Injection/projection inverse *) val uv_inv (x : t) : Lemma (ensures (uint_to_t (v x) == x)) [SMTPat (v x)] (** Projection/injection inverse *) val vu_inv (x : uint_t n) : Lemma (ensures (v (uint_to_t x) == x)) [SMTPat (uint_to_t x)] (** An alternate form of the injectivity of the [v] projection *) val v_inj (x1 x2: t): Lemma (requires (v x1 == v x2)) (ensures (x1 == x2)) (** Constants 0 and 1 *) val zero : x:t{v x = 0} val one : x:t{v x = 1} (**** Addition primitives *) (** Bounds-respecting addition The precondition enforces that the sum does not overflow, expressing the bound as an addition on mathematical integers *) val add (a:t) (b:t) : Pure t (requires (size (v a + v b) n)) (ensures (fun c -> v a + v b = v c)) (** Underspecified, possibly overflowing addition: The postcondition only enures that the result is the sum of the arguments in case there is no overflow *) val add_underspec (a:t) (b:t) : Pure t (requires True) (ensures (fun c -> size (v a + v b) n ==> v a + v b = v c)) (** Addition modulo [2^n] Machine integers can always be added, but the postcondition is now in terms of addition modulo [2^n] on mathematical integers *) val add_mod (a:t) (b:t) : Pure t (requires True) (ensures (fun c -> FStar.UInt.add_mod (v a) (v b) = v c)) (**** Subtraction primitives *) (** Bounds-respecting subtraction The precondition enforces that the difference does not underflow, expressing the bound as a difference on mathematical integers *) val sub (a:t) (b:t) : Pure t (requires (size (v a - v b) n)) (ensures (fun c -> v a - v b = v c)) (** Underspecified, possibly overflowing subtraction: The postcondition only enures that the result is the difference of the arguments in case there is no underflow *) val sub_underspec (a:t) (b:t) : Pure t (requires True) (ensures (fun c -> size (v a - v b) n ==> v a - v b = v c)) (** Subtraction modulo [2^n] Machine integers can always be subtractd, but the postcondition is now in terms of subtraction modulo [2^n] on mathematical integers *) val sub_mod (a:t) (b:t) : Pure t (requires True) (ensures (fun c -> FStar.UInt.sub_mod (v a) (v b) = v c)) (**** Multiplication primitives *) (** Bounds-respecting multiplication The precondition enforces that the product does not overflow, expressing the bound as a product on mathematical integers *) val mul (a:t) (b:t) : Pure t (requires (size (v a * v b) n)) (ensures (fun c -> v a * v b = v c)) (** Underspecified, possibly overflowing product The postcondition only enures that the result is the product of the arguments in case there is no overflow *) val mul_underspec (a:t) (b:t) : Pure t (requires True) (ensures (fun c -> size (v a * v b) n ==> v a * v b = v c)) (** Multiplication modulo [2^n] Machine integers can always be multiplied, but the postcondition is now in terms of product modulo [2^n] on mathematical integers *) val mul_mod (a:t) (b:t) : Pure t (requires True) (ensures (fun c -> FStar.UInt.mul_mod (v a) (v b) = v c)) (**** Division primitives *) (** Euclidean division of [a] and [b], with [b] non-zero *) val div (a:t) (b:t{v b <> 0}) : Pure t (requires (True)) (ensures (fun c -> v a / v b = v c)) (**** Modulo primitives *) (** Euclidean remainder The result is the modulus of [a] with respect to a non-zero [b] *) val rem (a:t) (b:t{v b <> 0}) : Pure t (requires True) (ensures (fun c -> FStar.UInt.mod (v a) (v b) = v c)) (**** Bitwise operators *) /// Also see FStar.BV (** Bitwise logical conjunction *) val logand (x:t) (y:t) : Pure t (requires True) (ensures (fun z -> v x `logand` v y = v z)) (** Bitwise logical exclusive-or *) val logxor (x:t) (y:t) : Pure t (requires True) (ensures (fun z -> v x `logxor` v y == v z)) (** Bitwise logical disjunction *) val logor (x:t) (y:t) : Pure t (requires True) (ensures (fun z -> v x `logor` v y == v z)) (** Bitwise logical negation *) val lognot (x:t) : Pure t (requires True) (ensures (fun z -> lognot (v x) == v z)) (**** Shift operators *) (** Shift right with zero fill, shifting at most the integer width *) val shift_right (a:t) (s:UInt32.t) : Pure t (requires (UInt32.v s < n)) (ensures (fun c -> FStar.UInt.shift_right (v a) (UInt32.v s) = v c)) (** Shift left with zero fill, shifting at most the integer width *) val shift_left (a:t) (s:UInt32.t) : Pure t (requires (UInt32.v s < n)) (ensures (fun c -> FStar.UInt.shift_left (v a) (UInt32.v s) = v c)) (**** Comparison operators *) (** Equality Note, it is safe to also use the polymorphic decidable equality operator [=] *) let eq (a:t) (b:t) : Tot bool = eq #n (v a) (v b) (** Greater than *) let gt (a:t) (b:t) : Tot bool = gt #n (v a) (v b) (** Greater than or equal *) let gte (a:t) (b:t) : Tot bool = gte #n (v a) (v b) (** Less than *) let lt (a:t) (b:t) : Tot bool = lt #n (v a) (v b) (** Less than or equal *) let lte (a:t) (b:t) : Tot bool = lte #n (v a) (v b) (** Unary negation *) inline_for_extraction let minus (a:t) = add_mod (lognot a) (uint_to_t 1) (** The maximum shift value for this type, i.e. its width minus one, as an UInt32. *) inline_for_extraction let n_minus_one = UInt32.uint_to_t (n - 1) #set-options "--z3rlimit 80 --initial_fuel 1 --max_fuel 1" (** A constant-time way to compute the equality of two machine integers. With inspiration from https://git.zx2c4.com/WireGuard/commit/src/crypto/curve25519-hacl64.h?id=2e60bb395c1f589a398ec606d611132ef9ef764b Note, the branching on [a=b] is just for proof-purposes. *) [@ CNoInline ] let eq_mask (a:t) (b:t) : Pure t (requires True) (ensures (fun c -> (v a = v b ==> v c = pow2 n - 1) /\ (v a <> v b ==> v c = 0))) = let x = logxor a b in let minus_x = minus x in let x_or_minus_x = logor x minus_x in let xnx = shift_right x_or_minus_x n_minus_one in let c = sub_mod xnx (uint_to_t 1) in if a = b then begin logxor_self (v a); lognot_lemma_1 #n; logor_lemma_1 (v x); assert (v x = 0 /\ v minus_x = 0 /\ v x_or_minus_x = 0 /\ v xnx = 0); assert (v c = ones n) end else begin logxor_neq_nonzero (v a) (v b); lemma_msb_pow2 #n (v (lognot x)); lemma_msb_pow2 #n (v minus_x); lemma_minus_zero #n (v x); assert (v c = FStar.UInt.zero n) end; c private val lemma_sub_msbs (a:t) (b:t) : Lemma ((msb (v a) = msb (v b)) ==> (v a < v b <==> msb (v (sub_mod a b)))) (** A constant-time way to compute the [>=] inequality of two machine integers. With inspiration from https://git.zx2c4.com/WireGuard/commit/src/crypto/curve25519-hacl64.h?id=0a483a9b431d87eca1b275463c632f8d5551978a *) [@ CNoInline ] let gte_mask (a:t) (b:t) : Pure t (requires True) (ensures (fun c -> (v a >= v b ==> v c = pow2 n - 1) /\ (v a < v b ==> v c = 0))) = let x = a in let y = b in let x_xor_y = logxor x y in let x_sub_y = sub_mod x y in let x_sub_y_xor_y = logxor x_sub_y y in let q = logor x_xor_y x_sub_y_xor_y in let x_xor_q = logxor x q in let x_xor_q_ = shift_right x_xor_q n_minus_one in let c = sub_mod x_xor_q_ (uint_to_t 1) in lemma_sub_msbs x y; lemma_msb_gte (v x) (v y); lemma_msb_gte (v y) (v x); c #reset-options (*** Infix notations *) unfold let op_Plus_Hat = add unfold let op_Plus_Question_Hat = add_underspec unfold let op_Plus_Percent_Hat = add_mod unfold let op_Subtraction_Hat = sub unfold let op_Subtraction_Question_Hat = sub_underspec unfold let op_Subtraction_Percent_Hat = sub_mod unfold let op_Star_Hat = mul unfold let op_Star_Question_Hat = mul_underspec unfold let op_Star_Percent_Hat = mul_mod unfold let op_Slash_Hat = div unfold let op_Percent_Hat = rem unfold let op_Hat_Hat = logxor
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.UInt32.fsti.checked", "FStar.UInt.fsti.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked" ], "interface_file": false, "source_file": "FStar.UInt64.fsti" }
[ { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.UInt", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.UInt", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
x: FStar.UInt64.t -> y: FStar.UInt64.t -> Prims.Pure FStar.UInt64.t
Prims.Pure
[]
[]
[ "FStar.UInt64.logor" ]
[]
false
false
false
false
false
let op_Bar_Hat =
logor
false
FStar.UInt64.fsti
FStar.UInt64.n_minus_one
val n_minus_one : FStar.UInt32.t
let n_minus_one = UInt32.uint_to_t (n - 1)
{ "file_name": "ulib/FStar.UInt64.fsti", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 42, "end_line": 244, "start_col": 0, "start_line": 244 }
(* 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 FStar.UInt64 (**** THIS MODULE IS GENERATED AUTOMATICALLY USING [mk_int.sh], DO NOT EDIT DIRECTLY ****) unfold let n = 64 /// For FStar.UIntN.fstp: anything that you fix/update here should be /// reflected in [FStar.IntN.fstp], which is mostly a copy-paste of /// this module. /// /// Except, as compared to [FStar.IntN.fstp], here: /// - every occurrence of [int_t] has been replaced with [uint_t] /// - every occurrence of [@%] has been replaced with [%]. /// - some functions (e.g., add_underspec, etc.) are only defined here, not on signed integers /// This module provides an abstract type for machine integers of a /// given signedness and width. The interface is designed to be safe /// with respect to arithmetic underflow and overflow. /// Note, we have attempted several times to re-design this module to /// make it more amenable to normalization and to impose less overhead /// on the SMT solver when reasoning about machine integer /// arithmetic. The following github issue reports on the current /// status of that work. /// /// https://github.com/FStarLang/FStar/issues/1757 open FStar.UInt open FStar.Mul #set-options "--max_fuel 0 --max_ifuel 0" (** Abstract type of machine integers, with an underlying representation using a bounded mathematical integer *) new val t : eqtype (** A coercion that projects a bounded mathematical integer from a machine integer *) val v (x:t) : Tot (uint_t n) (** A coercion that injects a bounded mathematical integers into a machine integer *) val uint_to_t (x:uint_t n) : Pure t (requires True) (ensures (fun y -> v y = x)) (** Injection/projection inverse *) val uv_inv (x : t) : Lemma (ensures (uint_to_t (v x) == x)) [SMTPat (v x)] (** Projection/injection inverse *) val vu_inv (x : uint_t n) : Lemma (ensures (v (uint_to_t x) == x)) [SMTPat (uint_to_t x)] (** An alternate form of the injectivity of the [v] projection *) val v_inj (x1 x2: t): Lemma (requires (v x1 == v x2)) (ensures (x1 == x2)) (** Constants 0 and 1 *) val zero : x:t{v x = 0} val one : x:t{v x = 1} (**** Addition primitives *) (** Bounds-respecting addition The precondition enforces that the sum does not overflow, expressing the bound as an addition on mathematical integers *) val add (a:t) (b:t) : Pure t (requires (size (v a + v b) n)) (ensures (fun c -> v a + v b = v c)) (** Underspecified, possibly overflowing addition: The postcondition only enures that the result is the sum of the arguments in case there is no overflow *) val add_underspec (a:t) (b:t) : Pure t (requires True) (ensures (fun c -> size (v a + v b) n ==> v a + v b = v c)) (** Addition modulo [2^n] Machine integers can always be added, but the postcondition is now in terms of addition modulo [2^n] on mathematical integers *) val add_mod (a:t) (b:t) : Pure t (requires True) (ensures (fun c -> FStar.UInt.add_mod (v a) (v b) = v c)) (**** Subtraction primitives *) (** Bounds-respecting subtraction The precondition enforces that the difference does not underflow, expressing the bound as a difference on mathematical integers *) val sub (a:t) (b:t) : Pure t (requires (size (v a - v b) n)) (ensures (fun c -> v a - v b = v c)) (** Underspecified, possibly overflowing subtraction: The postcondition only enures that the result is the difference of the arguments in case there is no underflow *) val sub_underspec (a:t) (b:t) : Pure t (requires True) (ensures (fun c -> size (v a - v b) n ==> v a - v b = v c)) (** Subtraction modulo [2^n] Machine integers can always be subtractd, but the postcondition is now in terms of subtraction modulo [2^n] on mathematical integers *) val sub_mod (a:t) (b:t) : Pure t (requires True) (ensures (fun c -> FStar.UInt.sub_mod (v a) (v b) = v c)) (**** Multiplication primitives *) (** Bounds-respecting multiplication The precondition enforces that the product does not overflow, expressing the bound as a product on mathematical integers *) val mul (a:t) (b:t) : Pure t (requires (size (v a * v b) n)) (ensures (fun c -> v a * v b = v c)) (** Underspecified, possibly overflowing product The postcondition only enures that the result is the product of the arguments in case there is no overflow *) val mul_underspec (a:t) (b:t) : Pure t (requires True) (ensures (fun c -> size (v a * v b) n ==> v a * v b = v c)) (** Multiplication modulo [2^n] Machine integers can always be multiplied, but the postcondition is now in terms of product modulo [2^n] on mathematical integers *) val mul_mod (a:t) (b:t) : Pure t (requires True) (ensures (fun c -> FStar.UInt.mul_mod (v a) (v b) = v c)) (**** Division primitives *) (** Euclidean division of [a] and [b], with [b] non-zero *) val div (a:t) (b:t{v b <> 0}) : Pure t (requires (True)) (ensures (fun c -> v a / v b = v c)) (**** Modulo primitives *) (** Euclidean remainder The result is the modulus of [a] with respect to a non-zero [b] *) val rem (a:t) (b:t{v b <> 0}) : Pure t (requires True) (ensures (fun c -> FStar.UInt.mod (v a) (v b) = v c)) (**** Bitwise operators *) /// Also see FStar.BV (** Bitwise logical conjunction *) val logand (x:t) (y:t) : Pure t (requires True) (ensures (fun z -> v x `logand` v y = v z)) (** Bitwise logical exclusive-or *) val logxor (x:t) (y:t) : Pure t (requires True) (ensures (fun z -> v x `logxor` v y == v z)) (** Bitwise logical disjunction *) val logor (x:t) (y:t) : Pure t (requires True) (ensures (fun z -> v x `logor` v y == v z)) (** Bitwise logical negation *) val lognot (x:t) : Pure t (requires True) (ensures (fun z -> lognot (v x) == v z)) (**** Shift operators *) (** Shift right with zero fill, shifting at most the integer width *) val shift_right (a:t) (s:UInt32.t) : Pure t (requires (UInt32.v s < n)) (ensures (fun c -> FStar.UInt.shift_right (v a) (UInt32.v s) = v c)) (** Shift left with zero fill, shifting at most the integer width *) val shift_left (a:t) (s:UInt32.t) : Pure t (requires (UInt32.v s < n)) (ensures (fun c -> FStar.UInt.shift_left (v a) (UInt32.v s) = v c)) (**** Comparison operators *) (** Equality Note, it is safe to also use the polymorphic decidable equality operator [=] *) let eq (a:t) (b:t) : Tot bool = eq #n (v a) (v b) (** Greater than *) let gt (a:t) (b:t) : Tot bool = gt #n (v a) (v b) (** Greater than or equal *) let gte (a:t) (b:t) : Tot bool = gte #n (v a) (v b) (** Less than *) let lt (a:t) (b:t) : Tot bool = lt #n (v a) (v b) (** Less than or equal *) let lte (a:t) (b:t) : Tot bool = lte #n (v a) (v b) (** Unary negation *) inline_for_extraction let minus (a:t) = add_mod (lognot a) (uint_to_t 1) (** The maximum shift value for this type, i.e. its width minus one, as an UInt32. *)
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.UInt32.fsti.checked", "FStar.UInt.fsti.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked" ], "interface_file": false, "source_file": "FStar.UInt64.fsti" }
[ { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.UInt", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.UInt", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
FStar.UInt32.t
Prims.Tot
[ "total" ]
[]
[ "FStar.UInt32.uint_to_t", "Prims.op_Subtraction", "FStar.UInt64.n" ]
[]
false
false
false
true
false
let n_minus_one =
UInt32.uint_to_t (n - 1)
false
LowParse.Low.BCVLI.fst
LowParse.Low.BCVLI.write_bounded_bcvli
val write_bounded_bcvli (min: nat) (max: nat{min <= max}) : Tot (leaf_writer_strong (serialize_bounded_bcvli min max))
val write_bounded_bcvli (min: nat) (max: nat{min <= max}) : Tot (leaf_writer_strong (serialize_bounded_bcvli min max))
let write_bounded_bcvli (min: nat) (max: nat { min <= max }) : Tot (leaf_writer_strong (serialize_bounded_bcvli min max)) = leaf_writer_strong_of_serializer32 (serialize32_bounded_bcvli min max) ()
{ "file_name": "src/lowparse/LowParse.Low.BCVLI.fst", "git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
{ "end_col": 75, "end_line": 292, "start_col": 0, "start_line": 288 }
module LowParse.Low.BCVLI include LowParse.Spec.BCVLI include LowParse.Low.Combinators include LowParse.Low.BoundedInt module B = LowStar.Buffer module HST = FStar.HyperStack.ST module Cast = FStar.Int.Cast module U32 = FStar.UInt32 module U64 = FStar.UInt64 #reset-options "--z3cliopt smt.arith.nl=false --max_fuel 0" #push-options "--z3rlimit 16" let validate_bcvli : validator parse_bcvli = fun #rrel #rel input pos -> let h = HST.get () in [@inline_let] let _ = valid_facts parse_bcvli h input (uint64_to_uint32 pos); parse_bcvli_eq (bytes_of_slice_from h input (uint64_to_uint32 pos)); valid_facts (parse_bounded_integer_le 1) h input (uint64_to_uint32 pos) in let pos1 = validate_total_constant_size (parse_bounded_integer_le 1) 1uL () input pos in if is_error pos1 then pos1 else [@inline_let] let _ = valid_facts (parse_bounded_integer_le 2) h input (uint64_to_uint32 pos1); valid_facts (parse_bounded_integer_le 4) h input (uint64_to_uint32 pos1) in let r = read_bounded_integer_le_1 input (uint64_to_uint32 pos) in if r `U32.lt` 253ul then pos1 else if r = 253ul then let pos2 = validate_total_constant_size (parse_bounded_integer_le 2) 2uL () input pos1 in if is_error pos2 then pos2 else (* because of the non-malleability constraint, I need to actually read the value and check whether it is not a lower integer *) let r = read_bounded_integer_le_2 input (uint64_to_uint32 pos1) in if r `U32.lt` 253ul then validator_error_generic else pos2 else if r = 254ul then let pos2 = validate_total_constant_size (parse_bounded_integer_le 4) 4uL () input pos1 in if is_error pos2 then pos2 else (* because of the non-malleability constraint, I need to actually read the value and check whether it is not a lower integer *) let r = read_bounded_integer_le_4 input (uint64_to_uint32 pos1) in if r `U32.lt` 65536ul then validator_error_generic else pos2 else validator_error_generic let jump_bcvli : jumper parse_bcvli = fun #rrel #rel input pos -> let h = HST.get () in [@inline_let] let _ = valid_facts parse_bcvli h input pos; parse_bcvli_eq (bytes_of_slice_from h input pos); valid_facts (parse_bounded_integer_le 1) h input pos in let pos1 = jump_constant_size (parse_bounded_integer_le 1) 1ul () input pos in [@inline_let] let _ = valid_facts (parse_bounded_integer_le 2) h input pos1; valid_facts (parse_bounded_integer_le 4) h input pos1 in let r = read_bounded_integer_le_1 input pos in if r `U32.lt` 253ul then pos1 else if r = 253ul then jump_constant_size (parse_bounded_integer_le 2) 2ul () input pos1 else jump_constant_size (parse_bounded_integer_le 4) 4ul () input pos1 let read_bcvli : leaf_reader parse_bcvli = fun #rrel #rel input pos -> let h = HST.get () in [@inline_let] let _ = valid_facts parse_bcvli h input pos; parse_bcvli_eq (bytes_of_slice_from h input pos); valid_facts (parse_bounded_integer_le 1) h input pos in let r = read_bounded_integer_le_1 input pos in if r `U32.lt` 253ul then (r <: U32.t) else let pos1 = jump_constant_size (parse_bounded_integer_le 1) 1ul () input pos in [@inline_let] let _ = valid_facts (parse_bounded_integer_le 2) h input pos1; valid_facts (parse_bounded_integer_le 4) h input pos1 in if r = 253ul then read_bounded_integer_le_2 input pos1 <: U32.t else read_bounded_integer_le_4 input pos1 <: U32.t #pop-options module U8 = FStar.UInt8 #push-options "--z3rlimit 32" inline_for_extraction let serialize32_bcvli' (x: U32.t) (#rrel #rel: _) (b: B.mbuffer U8.t rrel rel) (pos: U32.t) : HST.Stack U32.t (requires (fun h -> let len = Seq.length (serialize serialize_bcvli x) in B.live h b /\ U32.v pos + len <= B.length b /\ writable b (U32.v pos) (U32.v pos + len) h )) (ensures (fun h len h' -> Seq.length (serialize serialize_bcvli x) == U32.v len /\ ( B.modifies (B.loc_buffer_from_to b pos (pos `U32.add` len)) h h' /\ B.live h b /\ Seq.slice (B.as_seq h' b) (U32.v pos) (U32.v pos + U32.v len) `Seq.equal` serialize serialize_bcvli x ))) = // [@inline_let] let _ = serialize_bcvli_eq x ; // in let c : bounded_integer 1 = if x `U32.lt` 253ul then x else if x `U32.lt` 65536ul then 253ul else 254ul in [@inline_let] let pos' = Ghost.hide (U32.v pos + Seq.length (serialize serialize_bcvli x)) in let h = HST.get () in [@inline_let] let _ = writable_weaken b (U32.v pos) (Ghost.reveal pos') h (U32.v pos) (U32.v pos + 1) in let len1 = serialize32_bounded_integer_le_1 c b pos in let h1 = HST.get () in [@inline_let] let _ = writable_modifies b (U32.v pos) (Ghost.reveal pos') h B.loc_none h1 in if c `U32.lt` 253ul then begin len1 end else if c = 253ul then begin [@inline_let] let _ = assert (U32.v x < 65536) in [@inline_let] let _ = writable_weaken b (U32.v pos) (Ghost.reveal pos') h1 (U32.v pos + U32.v len1) ((U32.v pos + U32.v len1) + 2) in let len2 = serialize32_bounded_integer_le_2 x b (pos `U32.add` len1) in let h' = HST.get () in [@inline_let] let len = len1 `U32.add` len2 in B.modifies_buffer_from_to_elim b pos (pos `U32.add` len1) (B.loc_buffer_from_to b (pos `U32.add` len1) (pos `U32.add` len)) h1 h'; len end else begin [@inline_let] let _ = writable_weaken b (U32.v pos) (Ghost.reveal pos') h1 (U32.v pos + U32.v len1) ((U32.v pos + U32.v len1) + 4) in let len2 = serialize32_bounded_integer_le_4 x b (pos `U32.add` len1) in let h' = HST.get () in [@inline_let] let len = len1 `U32.add` len2 in B.modifies_buffer_from_to_elim b pos (pos `U32.add` len1) (B.loc_buffer_from_to b (pos `U32.add` len1) (pos `U32.add` len)) h1 h'; len end inline_for_extraction let serialize32_bcvli : serializer32 serialize_bcvli = fun (x: U32.t) #rrel #rel b pos -> serialize32_bcvli' x b pos let write_bcvli : leaf_writer_strong serialize_bcvli = leaf_writer_strong_of_serializer32 serialize32_bcvli () let validate_bounded_bcvli' (min32: U32.t) (max32: U32.t { U32.v min32 <= U32.v max32 }) : Tot (validator (parse_bounded_bcvli (U32.v min32) (U32.v max32))) = fun #rrel #rel input pos -> let h = HST.get () in [@inline_let] let _ = valid_facts (parse_bounded_bcvli (U32.v min32) (U32.v max32)) h input (uint64_to_uint32 pos); parse_bounded_bcvli_eq (U32.v min32) (U32.v max32) (bytes_of_slice_from h input (uint64_to_uint32 pos)); parse_bcvli_eq (bytes_of_slice_from h input (uint64_to_uint32 pos)); valid_facts (parse_bounded_integer_le 1) h input (uint64_to_uint32 pos) in let pos1 = validate_total_constant_size (parse_bounded_integer_le 1) 1uL () input pos in if is_error pos1 then pos1 else [@inline_let] let _ = valid_facts (parse_bounded_integer_le 2) h input (uint64_to_uint32 pos1); valid_facts (parse_bounded_integer_le 4) h input (uint64_to_uint32 pos1) in let r = read_bounded_integer_le_1 input (uint64_to_uint32 pos) in if r `U32.lt` 253ul && min32 `U32.lte` r && r `U32.lte` max32 then pos1 else if max32 `U32.lt` 253ul then validator_error_generic else if r = 253ul then if 65536ul `U32.lte` min32 then validator_error_generic else let pos2 = validate_total_constant_size (parse_bounded_integer_le 2) 2uL () input pos1 in if is_error pos2 then pos2 else (* because of the non-malleability constraint, I need to actually read the value and check whether it is not a lower integer *) let r = read_bounded_integer_le_2 input (uint64_to_uint32 pos1) in if r `U32.lt` 253ul || r `U32.lt` min32 || max32 `U32.lt` r then validator_error_generic else pos2 else if max32 `U32.lt` 65536ul then validator_error_generic else if r = 254ul then let pos2 = validate_total_constant_size (parse_bounded_integer_le 4) 4uL () input pos1 in if is_error pos2 then pos2 else (* because of the non-malleability constraint, I need to actually read the value and check whether it is not a lower integer *) let r = read_bounded_integer_le_4 input (uint64_to_uint32 pos1) in if r `U32.lt` 65536ul || r `U32.lt` min32 || max32 `U32.lt` r then validator_error_generic else pos2 else validator_error_generic inline_for_extraction noextract let validate_bounded_bcvli (min: nat) (min32: U32.t { U32.v min32 == min }) (max: nat { min <= max }) (max32: U32.t { U32.v max32 == max }) : Tot (validator (parse_bounded_bcvli min max)) = validate_bounded_bcvli' min32 max32 inline_for_extraction noextract let jump_bounded_bcvli (min: nat) (max: nat { min <= max }) : Tot (jumper (parse_bounded_bcvli min max)) = fun #rrel #rel input pos -> let h = HST.get () in [@inline_let] let _ = valid_facts (parse_bounded_bcvli min max) h input pos; parse_bounded_bcvli_eq min max (bytes_of_slice_from h input pos); valid_facts parse_bcvli h input pos in jump_bcvli input pos inline_for_extraction noextract let read_bounded_bcvli (min: nat) (max: nat { min <= max }) : Tot (leaf_reader (parse_bounded_bcvli min max)) = fun #rrel #rel input pos -> let h = HST.get () in [@inline_let] let _ = valid_facts (parse_bounded_bcvli min max) h input pos; parse_bounded_bcvli_eq min max (bytes_of_slice_from h input pos); valid_facts parse_bcvli h input pos in read_bcvli input pos <: bounded_int32 min max inline_for_extraction noextract let serialize32_bounded_bcvli (min: nat) (max: nat { min <= max }) : Tot (serializer32 (serialize_bounded_bcvli min max)) = fun (x: bounded_int32 min max) #rrel #rel b pos -> [@inline_let] let _ = serialize_bounded_bcvli_eq min max x in serialize32_bcvli x b pos inline_for_extraction
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowStar.Buffer.fst.checked", "LowParse.Spec.BCVLI.fsti.checked", "LowParse.Low.Combinators.fsti.checked", "LowParse.Low.BoundedInt.fsti.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.Ghost.fsti.checked" ], "interface_file": false, "source_file": "LowParse.Low.BCVLI.fst" }
[ { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": true, "full_module": "FStar.Int.Cast", "short_module": "Cast" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": false, "full_module": "LowParse.Low.BoundedInt", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low.Combinators", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec.BCVLI", "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": 0, "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": [ "smt.arith.nl=false" ], "z3refresh": false, "z3rlimit": 32, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
min: Prims.nat -> max: Prims.nat{min <= max} -> LowParse.Low.Base.leaf_writer_strong (LowParse.Spec.BCVLI.serialize_bounded_bcvli min max)
Prims.Tot
[ "total" ]
[]
[ "Prims.nat", "Prims.b2t", "Prims.op_LessThanOrEqual", "LowParse.Low.Base.leaf_writer_strong_of_serializer32", "LowParse.Spec.BCVLI.parse_bounded_bcvli_kind", "LowParse.Spec.BoundedInt.bounded_int32", "LowParse.Spec.BCVLI.parse_bounded_bcvli", "LowParse.Spec.BCVLI.serialize_bounded_bcvli", "LowParse.Low.BCVLI.serialize32_bounded_bcvli", "LowParse.Low.Base.leaf_writer_strong" ]
[]
false
false
false
false
false
let write_bounded_bcvli (min: nat) (max: nat{min <= max}) : Tot (leaf_writer_strong (serialize_bounded_bcvli min max)) =
leaf_writer_strong_of_serializer32 (serialize32_bounded_bcvli min max) ()
false
LowParse.Low.BCVLI.fst
LowParse.Low.BCVLI.serialize32_bcvli
val serialize32_bcvli:serializer32 serialize_bcvli
val serialize32_bcvli:serializer32 serialize_bcvli
let serialize32_bcvli : serializer32 serialize_bcvli = fun (x: U32.t) #rrel #rel b pos -> serialize32_bcvli' x b pos
{ "file_name": "src/lowparse/LowParse.Low.BCVLI.fst", "git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
{ "end_col": 63, "end_line": 174, "start_col": 0, "start_line": 173 }
module LowParse.Low.BCVLI include LowParse.Spec.BCVLI include LowParse.Low.Combinators include LowParse.Low.BoundedInt module B = LowStar.Buffer module HST = FStar.HyperStack.ST module Cast = FStar.Int.Cast module U32 = FStar.UInt32 module U64 = FStar.UInt64 #reset-options "--z3cliopt smt.arith.nl=false --max_fuel 0" #push-options "--z3rlimit 16" let validate_bcvli : validator parse_bcvli = fun #rrel #rel input pos -> let h = HST.get () in [@inline_let] let _ = valid_facts parse_bcvli h input (uint64_to_uint32 pos); parse_bcvli_eq (bytes_of_slice_from h input (uint64_to_uint32 pos)); valid_facts (parse_bounded_integer_le 1) h input (uint64_to_uint32 pos) in let pos1 = validate_total_constant_size (parse_bounded_integer_le 1) 1uL () input pos in if is_error pos1 then pos1 else [@inline_let] let _ = valid_facts (parse_bounded_integer_le 2) h input (uint64_to_uint32 pos1); valid_facts (parse_bounded_integer_le 4) h input (uint64_to_uint32 pos1) in let r = read_bounded_integer_le_1 input (uint64_to_uint32 pos) in if r `U32.lt` 253ul then pos1 else if r = 253ul then let pos2 = validate_total_constant_size (parse_bounded_integer_le 2) 2uL () input pos1 in if is_error pos2 then pos2 else (* because of the non-malleability constraint, I need to actually read the value and check whether it is not a lower integer *) let r = read_bounded_integer_le_2 input (uint64_to_uint32 pos1) in if r `U32.lt` 253ul then validator_error_generic else pos2 else if r = 254ul then let pos2 = validate_total_constant_size (parse_bounded_integer_le 4) 4uL () input pos1 in if is_error pos2 then pos2 else (* because of the non-malleability constraint, I need to actually read the value and check whether it is not a lower integer *) let r = read_bounded_integer_le_4 input (uint64_to_uint32 pos1) in if r `U32.lt` 65536ul then validator_error_generic else pos2 else validator_error_generic let jump_bcvli : jumper parse_bcvli = fun #rrel #rel input pos -> let h = HST.get () in [@inline_let] let _ = valid_facts parse_bcvli h input pos; parse_bcvli_eq (bytes_of_slice_from h input pos); valid_facts (parse_bounded_integer_le 1) h input pos in let pos1 = jump_constant_size (parse_bounded_integer_le 1) 1ul () input pos in [@inline_let] let _ = valid_facts (parse_bounded_integer_le 2) h input pos1; valid_facts (parse_bounded_integer_le 4) h input pos1 in let r = read_bounded_integer_le_1 input pos in if r `U32.lt` 253ul then pos1 else if r = 253ul then jump_constant_size (parse_bounded_integer_le 2) 2ul () input pos1 else jump_constant_size (parse_bounded_integer_le 4) 4ul () input pos1 let read_bcvli : leaf_reader parse_bcvli = fun #rrel #rel input pos -> let h = HST.get () in [@inline_let] let _ = valid_facts parse_bcvli h input pos; parse_bcvli_eq (bytes_of_slice_from h input pos); valid_facts (parse_bounded_integer_le 1) h input pos in let r = read_bounded_integer_le_1 input pos in if r `U32.lt` 253ul then (r <: U32.t) else let pos1 = jump_constant_size (parse_bounded_integer_le 1) 1ul () input pos in [@inline_let] let _ = valid_facts (parse_bounded_integer_le 2) h input pos1; valid_facts (parse_bounded_integer_le 4) h input pos1 in if r = 253ul then read_bounded_integer_le_2 input pos1 <: U32.t else read_bounded_integer_le_4 input pos1 <: U32.t #pop-options module U8 = FStar.UInt8 #push-options "--z3rlimit 32" inline_for_extraction let serialize32_bcvli' (x: U32.t) (#rrel #rel: _) (b: B.mbuffer U8.t rrel rel) (pos: U32.t) : HST.Stack U32.t (requires (fun h -> let len = Seq.length (serialize serialize_bcvli x) in B.live h b /\ U32.v pos + len <= B.length b /\ writable b (U32.v pos) (U32.v pos + len) h )) (ensures (fun h len h' -> Seq.length (serialize serialize_bcvli x) == U32.v len /\ ( B.modifies (B.loc_buffer_from_to b pos (pos `U32.add` len)) h h' /\ B.live h b /\ Seq.slice (B.as_seq h' b) (U32.v pos) (U32.v pos + U32.v len) `Seq.equal` serialize serialize_bcvli x ))) = // [@inline_let] let _ = serialize_bcvli_eq x ; // in let c : bounded_integer 1 = if x `U32.lt` 253ul then x else if x `U32.lt` 65536ul then 253ul else 254ul in [@inline_let] let pos' = Ghost.hide (U32.v pos + Seq.length (serialize serialize_bcvli x)) in let h = HST.get () in [@inline_let] let _ = writable_weaken b (U32.v pos) (Ghost.reveal pos') h (U32.v pos) (U32.v pos + 1) in let len1 = serialize32_bounded_integer_le_1 c b pos in let h1 = HST.get () in [@inline_let] let _ = writable_modifies b (U32.v pos) (Ghost.reveal pos') h B.loc_none h1 in if c `U32.lt` 253ul then begin len1 end else if c = 253ul then begin [@inline_let] let _ = assert (U32.v x < 65536) in [@inline_let] let _ = writable_weaken b (U32.v pos) (Ghost.reveal pos') h1 (U32.v pos + U32.v len1) ((U32.v pos + U32.v len1) + 2) in let len2 = serialize32_bounded_integer_le_2 x b (pos `U32.add` len1) in let h' = HST.get () in [@inline_let] let len = len1 `U32.add` len2 in B.modifies_buffer_from_to_elim b pos (pos `U32.add` len1) (B.loc_buffer_from_to b (pos `U32.add` len1) (pos `U32.add` len)) h1 h'; len end else begin [@inline_let] let _ = writable_weaken b (U32.v pos) (Ghost.reveal pos') h1 (U32.v pos + U32.v len1) ((U32.v pos + U32.v len1) + 4) in let len2 = serialize32_bounded_integer_le_4 x b (pos `U32.add` len1) in let h' = HST.get () in [@inline_let] let len = len1 `U32.add` len2 in B.modifies_buffer_from_to_elim b pos (pos `U32.add` len1) (B.loc_buffer_from_to b (pos `U32.add` len1) (pos `U32.add` len)) h1 h'; len end
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowStar.Buffer.fst.checked", "LowParse.Spec.BCVLI.fsti.checked", "LowParse.Low.Combinators.fsti.checked", "LowParse.Low.BoundedInt.fsti.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.Ghost.fsti.checked" ], "interface_file": false, "source_file": "LowParse.Low.BCVLI.fst" }
[ { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": true, "full_module": "FStar.Int.Cast", "short_module": "Cast" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": false, "full_module": "LowParse.Low.BoundedInt", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low.Combinators", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec.BCVLI", "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": 0, "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": [ "smt.arith.nl=false" ], "z3refresh": false, "z3rlimit": 32, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
LowParse.Low.Base.serializer32 LowParse.Spec.BCVLI.serialize_bcvli
Prims.Tot
[ "total" ]
[]
[ "FStar.UInt32.t", "LowStar.Monotonic.Buffer.srel", "LowParse.Bytes.byte", "LowStar.Monotonic.Buffer.mbuffer", "LowParse.Low.BCVLI.serialize32_bcvli'" ]
[]
false
false
false
true
false
let serialize32_bcvli:serializer32 serialize_bcvli =
fun (x: U32.t) #rrel #rel b pos -> serialize32_bcvli' x b pos
false
LowParse.Low.BCVLI.fst
LowParse.Low.BCVLI.serialize32_bounded_bcvli
val serialize32_bounded_bcvli (min: nat) (max: nat{min <= max}) : Tot (serializer32 (serialize_bounded_bcvli min max))
val serialize32_bounded_bcvli (min: nat) (max: nat{min <= max}) : Tot (serializer32 (serialize_bounded_bcvli min max))
let serialize32_bounded_bcvli (min: nat) (max: nat { min <= max }) : Tot (serializer32 (serialize_bounded_bcvli min max)) = fun (x: bounded_int32 min max) #rrel #rel b pos -> [@inline_let] let _ = serialize_bounded_bcvli_eq min max x in serialize32_bcvli x b pos
{ "file_name": "src/lowparse/LowParse.Low.BCVLI.fst", "git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
{ "end_col": 29, "end_line": 284, "start_col": 0, "start_line": 277 }
module LowParse.Low.BCVLI include LowParse.Spec.BCVLI include LowParse.Low.Combinators include LowParse.Low.BoundedInt module B = LowStar.Buffer module HST = FStar.HyperStack.ST module Cast = FStar.Int.Cast module U32 = FStar.UInt32 module U64 = FStar.UInt64 #reset-options "--z3cliopt smt.arith.nl=false --max_fuel 0" #push-options "--z3rlimit 16" let validate_bcvli : validator parse_bcvli = fun #rrel #rel input pos -> let h = HST.get () in [@inline_let] let _ = valid_facts parse_bcvli h input (uint64_to_uint32 pos); parse_bcvli_eq (bytes_of_slice_from h input (uint64_to_uint32 pos)); valid_facts (parse_bounded_integer_le 1) h input (uint64_to_uint32 pos) in let pos1 = validate_total_constant_size (parse_bounded_integer_le 1) 1uL () input pos in if is_error pos1 then pos1 else [@inline_let] let _ = valid_facts (parse_bounded_integer_le 2) h input (uint64_to_uint32 pos1); valid_facts (parse_bounded_integer_le 4) h input (uint64_to_uint32 pos1) in let r = read_bounded_integer_le_1 input (uint64_to_uint32 pos) in if r `U32.lt` 253ul then pos1 else if r = 253ul then let pos2 = validate_total_constant_size (parse_bounded_integer_le 2) 2uL () input pos1 in if is_error pos2 then pos2 else (* because of the non-malleability constraint, I need to actually read the value and check whether it is not a lower integer *) let r = read_bounded_integer_le_2 input (uint64_to_uint32 pos1) in if r `U32.lt` 253ul then validator_error_generic else pos2 else if r = 254ul then let pos2 = validate_total_constant_size (parse_bounded_integer_le 4) 4uL () input pos1 in if is_error pos2 then pos2 else (* because of the non-malleability constraint, I need to actually read the value and check whether it is not a lower integer *) let r = read_bounded_integer_le_4 input (uint64_to_uint32 pos1) in if r `U32.lt` 65536ul then validator_error_generic else pos2 else validator_error_generic let jump_bcvli : jumper parse_bcvli = fun #rrel #rel input pos -> let h = HST.get () in [@inline_let] let _ = valid_facts parse_bcvli h input pos; parse_bcvli_eq (bytes_of_slice_from h input pos); valid_facts (parse_bounded_integer_le 1) h input pos in let pos1 = jump_constant_size (parse_bounded_integer_le 1) 1ul () input pos in [@inline_let] let _ = valid_facts (parse_bounded_integer_le 2) h input pos1; valid_facts (parse_bounded_integer_le 4) h input pos1 in let r = read_bounded_integer_le_1 input pos in if r `U32.lt` 253ul then pos1 else if r = 253ul then jump_constant_size (parse_bounded_integer_le 2) 2ul () input pos1 else jump_constant_size (parse_bounded_integer_le 4) 4ul () input pos1 let read_bcvli : leaf_reader parse_bcvli = fun #rrel #rel input pos -> let h = HST.get () in [@inline_let] let _ = valid_facts parse_bcvli h input pos; parse_bcvli_eq (bytes_of_slice_from h input pos); valid_facts (parse_bounded_integer_le 1) h input pos in let r = read_bounded_integer_le_1 input pos in if r `U32.lt` 253ul then (r <: U32.t) else let pos1 = jump_constant_size (parse_bounded_integer_le 1) 1ul () input pos in [@inline_let] let _ = valid_facts (parse_bounded_integer_le 2) h input pos1; valid_facts (parse_bounded_integer_le 4) h input pos1 in if r = 253ul then read_bounded_integer_le_2 input pos1 <: U32.t else read_bounded_integer_le_4 input pos1 <: U32.t #pop-options module U8 = FStar.UInt8 #push-options "--z3rlimit 32" inline_for_extraction let serialize32_bcvli' (x: U32.t) (#rrel #rel: _) (b: B.mbuffer U8.t rrel rel) (pos: U32.t) : HST.Stack U32.t (requires (fun h -> let len = Seq.length (serialize serialize_bcvli x) in B.live h b /\ U32.v pos + len <= B.length b /\ writable b (U32.v pos) (U32.v pos + len) h )) (ensures (fun h len h' -> Seq.length (serialize serialize_bcvli x) == U32.v len /\ ( B.modifies (B.loc_buffer_from_to b pos (pos `U32.add` len)) h h' /\ B.live h b /\ Seq.slice (B.as_seq h' b) (U32.v pos) (U32.v pos + U32.v len) `Seq.equal` serialize serialize_bcvli x ))) = // [@inline_let] let _ = serialize_bcvli_eq x ; // in let c : bounded_integer 1 = if x `U32.lt` 253ul then x else if x `U32.lt` 65536ul then 253ul else 254ul in [@inline_let] let pos' = Ghost.hide (U32.v pos + Seq.length (serialize serialize_bcvli x)) in let h = HST.get () in [@inline_let] let _ = writable_weaken b (U32.v pos) (Ghost.reveal pos') h (U32.v pos) (U32.v pos + 1) in let len1 = serialize32_bounded_integer_le_1 c b pos in let h1 = HST.get () in [@inline_let] let _ = writable_modifies b (U32.v pos) (Ghost.reveal pos') h B.loc_none h1 in if c `U32.lt` 253ul then begin len1 end else if c = 253ul then begin [@inline_let] let _ = assert (U32.v x < 65536) in [@inline_let] let _ = writable_weaken b (U32.v pos) (Ghost.reveal pos') h1 (U32.v pos + U32.v len1) ((U32.v pos + U32.v len1) + 2) in let len2 = serialize32_bounded_integer_le_2 x b (pos `U32.add` len1) in let h' = HST.get () in [@inline_let] let len = len1 `U32.add` len2 in B.modifies_buffer_from_to_elim b pos (pos `U32.add` len1) (B.loc_buffer_from_to b (pos `U32.add` len1) (pos `U32.add` len)) h1 h'; len end else begin [@inline_let] let _ = writable_weaken b (U32.v pos) (Ghost.reveal pos') h1 (U32.v pos + U32.v len1) ((U32.v pos + U32.v len1) + 4) in let len2 = serialize32_bounded_integer_le_4 x b (pos `U32.add` len1) in let h' = HST.get () in [@inline_let] let len = len1 `U32.add` len2 in B.modifies_buffer_from_to_elim b pos (pos `U32.add` len1) (B.loc_buffer_from_to b (pos `U32.add` len1) (pos `U32.add` len)) h1 h'; len end inline_for_extraction let serialize32_bcvli : serializer32 serialize_bcvli = fun (x: U32.t) #rrel #rel b pos -> serialize32_bcvli' x b pos let write_bcvli : leaf_writer_strong serialize_bcvli = leaf_writer_strong_of_serializer32 serialize32_bcvli () let validate_bounded_bcvli' (min32: U32.t) (max32: U32.t { U32.v min32 <= U32.v max32 }) : Tot (validator (parse_bounded_bcvli (U32.v min32) (U32.v max32))) = fun #rrel #rel input pos -> let h = HST.get () in [@inline_let] let _ = valid_facts (parse_bounded_bcvli (U32.v min32) (U32.v max32)) h input (uint64_to_uint32 pos); parse_bounded_bcvli_eq (U32.v min32) (U32.v max32) (bytes_of_slice_from h input (uint64_to_uint32 pos)); parse_bcvli_eq (bytes_of_slice_from h input (uint64_to_uint32 pos)); valid_facts (parse_bounded_integer_le 1) h input (uint64_to_uint32 pos) in let pos1 = validate_total_constant_size (parse_bounded_integer_le 1) 1uL () input pos in if is_error pos1 then pos1 else [@inline_let] let _ = valid_facts (parse_bounded_integer_le 2) h input (uint64_to_uint32 pos1); valid_facts (parse_bounded_integer_le 4) h input (uint64_to_uint32 pos1) in let r = read_bounded_integer_le_1 input (uint64_to_uint32 pos) in if r `U32.lt` 253ul && min32 `U32.lte` r && r `U32.lte` max32 then pos1 else if max32 `U32.lt` 253ul then validator_error_generic else if r = 253ul then if 65536ul `U32.lte` min32 then validator_error_generic else let pos2 = validate_total_constant_size (parse_bounded_integer_le 2) 2uL () input pos1 in if is_error pos2 then pos2 else (* because of the non-malleability constraint, I need to actually read the value and check whether it is not a lower integer *) let r = read_bounded_integer_le_2 input (uint64_to_uint32 pos1) in if r `U32.lt` 253ul || r `U32.lt` min32 || max32 `U32.lt` r then validator_error_generic else pos2 else if max32 `U32.lt` 65536ul then validator_error_generic else if r = 254ul then let pos2 = validate_total_constant_size (parse_bounded_integer_le 4) 4uL () input pos1 in if is_error pos2 then pos2 else (* because of the non-malleability constraint, I need to actually read the value and check whether it is not a lower integer *) let r = read_bounded_integer_le_4 input (uint64_to_uint32 pos1) in if r `U32.lt` 65536ul || r `U32.lt` min32 || max32 `U32.lt` r then validator_error_generic else pos2 else validator_error_generic inline_for_extraction noextract let validate_bounded_bcvli (min: nat) (min32: U32.t { U32.v min32 == min }) (max: nat { min <= max }) (max32: U32.t { U32.v max32 == max }) : Tot (validator (parse_bounded_bcvli min max)) = validate_bounded_bcvli' min32 max32 inline_for_extraction noextract let jump_bounded_bcvli (min: nat) (max: nat { min <= max }) : Tot (jumper (parse_bounded_bcvli min max)) = fun #rrel #rel input pos -> let h = HST.get () in [@inline_let] let _ = valid_facts (parse_bounded_bcvli min max) h input pos; parse_bounded_bcvli_eq min max (bytes_of_slice_from h input pos); valid_facts parse_bcvli h input pos in jump_bcvli input pos inline_for_extraction noextract let read_bounded_bcvli (min: nat) (max: nat { min <= max }) : Tot (leaf_reader (parse_bounded_bcvli min max)) = fun #rrel #rel input pos -> let h = HST.get () in [@inline_let] let _ = valid_facts (parse_bounded_bcvli min max) h input pos; parse_bounded_bcvli_eq min max (bytes_of_slice_from h input pos); valid_facts parse_bcvli h input pos in read_bcvli input pos <: bounded_int32 min max inline_for_extraction
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowStar.Buffer.fst.checked", "LowParse.Spec.BCVLI.fsti.checked", "LowParse.Low.Combinators.fsti.checked", "LowParse.Low.BoundedInt.fsti.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.Ghost.fsti.checked" ], "interface_file": false, "source_file": "LowParse.Low.BCVLI.fst" }
[ { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": true, "full_module": "FStar.Int.Cast", "short_module": "Cast" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": false, "full_module": "LowParse.Low.BoundedInt", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low.Combinators", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec.BCVLI", "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": 0, "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": [ "smt.arith.nl=false" ], "z3refresh": false, "z3rlimit": 32, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
min: Prims.nat -> max: Prims.nat{min <= max} -> LowParse.Low.Base.serializer32 (LowParse.Spec.BCVLI.serialize_bounded_bcvli min max)
Prims.Tot
[ "total" ]
[]
[ "Prims.nat", "Prims.b2t", "Prims.op_LessThanOrEqual", "LowParse.Spec.BoundedInt.bounded_int32", "LowStar.Monotonic.Buffer.srel", "LowParse.Bytes.byte", "LowStar.Monotonic.Buffer.mbuffer", "FStar.UInt32.t", "LowParse.Low.BCVLI.serialize32_bcvli", "Prims.unit", "LowParse.Spec.BCVLI.serialize_bounded_bcvli_eq", "LowParse.Low.Base.serializer32", "LowParse.Spec.BCVLI.parse_bounded_bcvli_kind", "LowParse.Spec.BCVLI.parse_bounded_bcvli", "LowParse.Spec.BCVLI.serialize_bounded_bcvli" ]
[]
false
false
false
false
false
let serialize32_bounded_bcvli (min: nat) (max: nat{min <= max}) : Tot (serializer32 (serialize_bounded_bcvli min max)) =
fun (x: bounded_int32 min max) #rrel #rel b pos -> [@@ inline_let ]let _ = serialize_bounded_bcvli_eq min max x in serialize32_bcvli x b pos
false
MerkleTree.Low.Datastructures.fst
MerkleTree.Low.Datastructures.hvvreg
val hvvreg (hsz:hash_size_t): regional (regional hash_size_t (hash_vec #hsz)) (hash_vv hsz)
val hvvreg (hsz:hash_size_t): regional (regional hash_size_t (hash_vec #hsz)) (hash_vv hsz)
let hvvreg hsz = RVI.vector_regional (hvreg hsz)
{ "file_name": "src/MerkleTree.Low.Datastructures.fst", "git_rev": "7d7bdc20f2033171e279c176b26e84f9069d23c6", "git_url": "https://github.com/hacl-star/merkle-tree.git", "project_name": "merkle-tree" }
{ "end_col": 48, "end_line": 322, "start_col": 0, "start_line": 322 }
module MerkleTree.Low.Datastructures open FStar.All open FStar.Integers open FStar.Mul open LowStar.Buffer open LowStar.BufferOps open LowStar.Vector open LowStar.Regional open LowStar.RVector open LowStar.Regional.Instances module HS = FStar.HyperStack module HST = FStar.HyperStack.ST module MHS = FStar.Monotonic.HyperStack module HH = FStar.Monotonic.HyperHeap module B = LowStar.Buffer module CB = LowStar.ConstBuffer module V = LowStar.Vector module RV = LowStar.RVector module RVI = LowStar.Regional.Instances module S = FStar.Seq module EHS = EverCrypt.Hash module U32 = FStar.UInt32 module MTH = MerkleTree.New.High open EverCrypt.Helpers open Lib.IntTypes #set-options "--z3rlimit 10 --initial_fuel 0 --max_fuel 0 --initial_ifuel 0 --max_ifuel 0" type hash_size_t = n:uint32_t{n > 0ul} type hash (#hsz:hash_size_t) = b:B.buffer uint8 { B.len b = hsz \/ B.g_is_null b } // We cannot use `Low.RVector.Instances`, where we have some general // typeclass instances of `regional`, e.g., if `rg:regional a` then // `regional (rvector rg)`. In FStar we can use this, but KaRaMeL currently // cannot deal with this and gives a number of errors. // So we temporarily instantiate some `regional`s manually below, which is // extractable to C by KaRaMeL. /// Some instantiations of `regional` used in Merkle tree /// 1. `hash` is regional private noextract val hash_region_of: #hsz:hash_size_t -> v:hash #hsz -> GTot HH.rid let hash_region_of #_ v = B.frameOf v private inline_for_extraction val hash_dummy: #hsz:Ghost.erased hash_size_t -> Tot (hash #hsz) let hash_dummy #_ = B.null private noextract val hash_r_inv: #hsz:hash_size_t -> h:HS.mem -> v:hash #hsz -> GTot Type0 let hash_r_inv #hsz h v = B.live h v /\ B.freeable v /\ B.len v = hsz private noextract val hash_r_inv_reg: #hsz:hash_size_t -> h:HS.mem -> v:hash -> Lemma (requires hash_r_inv h v) (ensures MHS.live_region h (hash_region_of #hsz v)) let hash_r_inv_reg #_ h v = () private noextract val hash_repr (#hsz:hash_size_t): Type0 let hash_repr #hsz = MTH.hash #(U32.v hsz) private noextract val hash_r_repr: #hsz:hash_size_t -> h:HS.mem -> v:hash{hash_r_inv #hsz h v} -> GTot (hash_repr #hsz) let hash_r_repr #_ h v = B.as_seq h v private noextract val hash_r_sep: #hsz:hash_size_t -> v:hash #hsz -> p:loc -> h0:HS.mem -> h1:HS.mem -> Lemma (requires hash_r_inv h0 v /\ loc_disjoint (loc_all_regions_from false (hash_region_of v)) p /\ modifies p h0 h1) (ensures hash_r_inv h1 v /\ hash_r_repr h0 v == hash_r_repr h1 v) let hash_r_sep #_ v p h0 h1 = assert (loc_includes (loc_all_regions_from false (hash_region_of v)) (loc_buffer v)); B.modifies_buffer_elim v p h0 h1 private noextract val hash_irepr: #hsz:hash_size_t -> Ghost.erased (hash_repr #hsz) let hash_irepr #hsz = Ghost.hide (S.create (U32.v hsz) (u8 0)) private noextract val hash_r_alloc_p: #hsz:hash_size_t -> v:hash #hsz -> GTot Type0 let hash_r_alloc_p #_ v = True val hash_r_alloc: #hsz':Ghost.erased hash_size_t -> hsz:hash_size_t { hsz == Ghost.reveal hsz' } -> r:HST.erid -> HST.ST (hash #hsz) (requires (fun h0 -> true)) (ensures (fun h0 v h1 -> Set.subset (Map.domain (MHS.get_hmap h0)) (Map.domain (MHS.get_hmap h1)) /\ modifies loc_none h0 h1 /\ hash_r_alloc_p #hsz v /\ hash_r_inv h1 v /\ hash_region_of v = r /\ hash_r_repr h1 v == Ghost.reveal hash_irepr /\ B.fresh_loc (B.loc_buffer v) h0 h1)) let hash_r_alloc #_ s r = B.malloc r (u8 0) s val hash_r_free: #hsz':Ghost.erased hash_size_t -> hsz:hash_size_t { hsz == Ghost.reveal hsz' } -> v:hash #hsz' -> HST.ST unit (requires fun h0 -> hash_r_inv h0 v) (ensures fun h0 _ h1 -> modifies (loc_all_regions_from false (hash_region_of v)) h0 h1) let hash_r_free #_ _ v = B.free v noextract inline_for_extraction val hreg (hsz:hash_size_t): regional (hash_size_t) (hash #hsz) let hreg hsz = Rgl #(hash_size_t) #(hash #hsz) hsz (hash_region_of #hsz) (B.loc_buffer) (hash_dummy #hsz) (hash_r_inv #hsz) (hash_r_inv_reg #hsz) (hash_repr #hsz) (hash_r_repr #hsz) (hash_r_sep #hsz) (hash_irepr #hsz) (hash_r_alloc_p #hsz) (hash_r_alloc #hsz) (hash_r_free #hsz) private val hash_copy: #s':Ghost.erased hash_size_t -> s:hash_size_t { s == Ghost.reveal s' } -> src:hash #s -> dst:hash #s -> HST.ST unit (requires fun h0 -> hash_r_inv h0 src /\ hash_r_inv h0 dst /\ HH.disjoint (hash_region_of src) (hash_region_of dst)) (ensures fun h0 _ h1 -> modifies (loc_all_regions_from false (hash_region_of dst)) h0 h1 /\ hash_r_inv h1 dst /\ hash_r_repr h1 dst == hash_r_repr h0 src) let hash_copy #_ s src dst = B.blit src 0ul dst 0ul s /// JP: so much stuff happening here. First, single-constructor, single-argument /// elimination takes places and Cpy becomes completely eliminated, in favor of /// just being a type alias for the underlying function. So now, we have a /// function that returns a function pointer. /// /// Next, one might think that the hsz argument is going to be eliminated. It's /// not, because there's a hidden implicit argument to Cpy which is (hreg hsz), /// meaning that hsz is used at run-time even though Cpy is only using this /// argument ghostly. This would be have to be fixed. /// /// Finally, if the inline_for_extraction is removed, there seems to be a /// karamel bug that inserts a void*0. To be fixed. inline_for_extraction val hcpy: hsz:hash_size_t -> copyable #hash_size_t (hash #hsz) (hreg hsz) let hcpy hsz = Cpy (hash_copy #hsz) type hash_vec (#hsz:hash_size_t) = RV.rvector (hreg hsz) /// 2. `rvector hash` is regional type rhst (hsz:hash_size_t) = regional hash_size_t (hash #hsz) private noextract val hash_vec_region_of: #hsz:hash_size_t -> v:hash_vec #hsz -> GTot HH.rid let hash_vec_region_of #_ v = V.frameOf v private inline_for_extraction val hash_vec_dummy: (#hsz:Ghost.erased hash_size_t) -> hash_vec #hsz let hash_vec_dummy #_ = V.alloc_empty (hash #_) noextract val hash_vec_r_inv: #hsz:hash_size_t -> h:HS.mem -> v:hash_vec #hsz -> GTot Type0 let hash_vec_r_inv #hsz h v = RV.rv_inv h v noextract val hash_vec_r_inv_reg: #hsz:hash_size_t -> h:HS.mem -> v:hash_vec #hsz -> Lemma (requires (hash_vec_r_inv h v)) (ensures (MHS.live_region h (hash_vec_region_of v))) let hash_vec_r_inv_reg #_ h v = () private noextract val hash_vec_repr: #hsz:hash_size_t -> Type0 let hash_vec_repr #hsz = MTH.hashes #(U32.v hsz) noextract val hash_vec_r_repr: #hsz:hash_size_t -> h:HS.mem -> v:hash_vec #hsz {hash_vec_r_inv h v} -> GTot (hash_vec_repr #hsz) let hash_vec_r_repr #_ h v = RV.as_seq h v noextract val hash_vec_r_sep: #hsz:hash_size_t -> v:hash_vec #hsz -> p:loc -> h0:HS.mem -> h1:HS.mem -> Lemma (requires (hash_vec_r_inv h0 v /\ loc_disjoint (loc_all_regions_from false (hash_vec_region_of v)) p /\ modifies p h0 h1)) (ensures (hash_vec_r_inv h1 v /\ hash_vec_r_repr h0 v == hash_vec_r_repr h1 v)) let hash_vec_r_sep #_ v p h0 h1 = RV.rv_inv_preserved v p h0 h1; RV.as_seq_preserved v p h0 h1 noextract val hash_vec_irepr: #hsz:hash_size_t -> Ghost.erased (hash_vec_repr #hsz) let hash_vec_irepr #_ = Ghost.hide S.empty noextract val hash_vec_r_alloc_p: #hsz:hash_size_t -> v:hash_vec #hsz -> GTot Type0 let hash_vec_r_alloc_p #_ v = V.size_of v = 0ul #push-options "--initial_fuel 1 --max_fuel 1" val hash_vec_r_alloc: #hsz':Ghost.erased hash_size_t -> hsz:hash_size_t { hsz == Ghost.reveal hsz' } -> r:HST.erid -> HST.ST (hash_vec #hsz) (requires (fun h0 -> true)) (ensures (fun h0 v h1 -> Set.subset (Map.domain (MHS.get_hmap h0)) (Map.domain (MHS.get_hmap h1)) /\ modifies loc_none h0 h1 /\ hash_vec_r_alloc_p v /\ hash_vec_r_inv h1 v /\ hash_vec_region_of v = r /\ hash_vec_r_repr h1 v == Ghost.reveal hash_vec_irepr /\ B.fresh_loc (V.loc_vector v) h0 h1)) let hash_vec_r_alloc #_ hsz r = let nrid = HST.new_region r in // Note: here we are not creating a generic parameterized regional, we are // creating a specialized regional vector of hashes, so we don't need to go // through a run-time indirection to figure out what the dummy default element // is; we know it's the one for hashes V.alloc_reserve 1ul (hash_dummy #hsz) r #pop-options val hash_vec_r_free: #hsz':Ghost.erased hash_size_t -> hsz:hash_size_t { hsz == Ghost.reveal hsz' } -> v:hash_vec #hsz -> HST.ST unit (requires (fun h0 -> hash_vec_r_inv h0 v)) (ensures (fun h0 _ h1 -> modifies (loc_all_regions_from false (hash_vec_region_of #hsz v)) h0 h1)) let hash_vec_r_free #_ hsz v = RV.free v /// This is nice because the only piece of state that we are keeping is one /// word, the hash size, since we are implementing a specialized instance of /// RVector over hashes of a known length. We could also, for genericity, make /// this a mere application of RVector over hreg, which would be less /// implementation effort, at the expense of a bigger run-time cost since there /// would be extra space in the struct (which is passed by value!) and also a /// run-time indirection to do the lookup of the type class instance for the /// elements of the rvector. noextract inline_for_extraction val hvreg (hsz:hash_size_t): regional hash_size_t (hash_vec #hsz) let hvreg hsz = Rgl hsz (hash_vec_region_of #hsz) V.loc_vector (hash_vec_dummy #hsz) (hash_vec_r_inv #hsz) (hash_vec_r_inv_reg #hsz) (hash_vec_repr #hsz) (hash_vec_r_repr #hsz) (hash_vec_r_sep #hsz) (hash_vec_irepr #hsz) (hash_vec_r_alloc_p #hsz) (hash_vec_r_alloc #hsz) (hash_vec_r_free #hsz) /// 3. A vector of hash vectors is also regional type hash_vv (hsz:hash_size_t) = RV.rvector (hvreg hsz) noextract inline_for_extraction
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "MerkleTree.New.High.fst.checked", "LowStar.Vector.fst.checked", "LowStar.RVector.fst.checked", "LowStar.Regional.Instances.fst.checked", "LowStar.Regional.fst.checked", "LowStar.ConstBuffer.fsti.checked", "LowStar.BufferOps.fst.checked", "LowStar.Buffer.fst.checked", "Lib.IntTypes.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Set.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Monotonic.HyperStack.fsti.checked", "FStar.Monotonic.HyperHeap.fsti.checked", "FStar.Map.fsti.checked", "FStar.Integers.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked", "FStar.All.fst.checked", "EverCrypt.Helpers.fsti.checked", "EverCrypt.Hash.fsti.checked" ], "interface_file": false, "source_file": "MerkleTree.Low.Datastructures.fst" }
[ { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "EverCrypt.Helpers", "short_module": null }, { "abbrev": true, "full_module": "MerkleTree.New.High", "short_module": "MTH" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": true, "full_module": "EverCrypt.Hash", "short_module": "EHS" }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "S" }, { "abbrev": true, "full_module": "LowStar.Regional.Instances", "short_module": "RVI" }, { "abbrev": true, "full_module": "LowStar.RVector", "short_module": "RV" }, { "abbrev": true, "full_module": "LowStar.Vector", "short_module": "V" }, { "abbrev": true, "full_module": "LowStar.ConstBuffer", "short_module": "CB" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.Monotonic.HyperHeap", "short_module": "HH" }, { "abbrev": true, "full_module": "FStar.Monotonic.HyperStack", "short_module": "MHS" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": false, "full_module": "LowStar.Regional.Instances", "short_module": null }, { "abbrev": false, "full_module": "LowStar.RVector", "short_module": null }, { "abbrev": false, "full_module": "LowStar.Regional", "short_module": null }, { "abbrev": false, "full_module": "LowStar.Vector", "short_module": null }, { "abbrev": false, "full_module": "LowStar.BufferOps", "short_module": null }, { "abbrev": false, "full_module": "LowStar.Buffer", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.Integers", "short_module": null }, { "abbrev": false, "full_module": "FStar.All", "short_module": null }, { "abbrev": false, "full_module": "MerkleTree.Low", "short_module": null }, { "abbrev": false, "full_module": "MerkleTree.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": 0, "initial_ifuel": 0, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 10, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
hsz: MerkleTree.Low.Datastructures.hash_size_t -> LowStar.Regional.regional (LowStar.Regional.regional MerkleTree.Low.Datastructures.hash_size_t MerkleTree.Low.Datastructures.hash_vec) (MerkleTree.Low.Datastructures.hash_vv hsz)
Prims.Tot
[ "total" ]
[]
[ "MerkleTree.Low.Datastructures.hash_size_t", "LowStar.Regional.Instances.vector_regional", "MerkleTree.Low.Datastructures.hash_vec", "MerkleTree.Low.Datastructures.hvreg", "LowStar.Regional.regional", "MerkleTree.Low.Datastructures.hash_vv" ]
[]
false
false
false
false
false
let hvvreg hsz =
RVI.vector_regional (hvreg hsz)
false
FStar.UInt64.fsti
FStar.UInt64.op_Less_Equals_Hat
val op_Less_Equals_Hat : a: FStar.UInt64.t -> b: FStar.UInt64.t -> Prims.bool
let op_Less_Equals_Hat = lte
{ "file_name": "ulib/FStar.UInt64.fsti", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 35, "end_line": 336, "start_col": 7, "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 FStar.UInt64 (**** THIS MODULE IS GENERATED AUTOMATICALLY USING [mk_int.sh], DO NOT EDIT DIRECTLY ****) unfold let n = 64 /// For FStar.UIntN.fstp: anything that you fix/update here should be /// reflected in [FStar.IntN.fstp], which is mostly a copy-paste of /// this module. /// /// Except, as compared to [FStar.IntN.fstp], here: /// - every occurrence of [int_t] has been replaced with [uint_t] /// - every occurrence of [@%] has been replaced with [%]. /// - some functions (e.g., add_underspec, etc.) are only defined here, not on signed integers /// This module provides an abstract type for machine integers of a /// given signedness and width. The interface is designed to be safe /// with respect to arithmetic underflow and overflow. /// Note, we have attempted several times to re-design this module to /// make it more amenable to normalization and to impose less overhead /// on the SMT solver when reasoning about machine integer /// arithmetic. The following github issue reports on the current /// status of that work. /// /// https://github.com/FStarLang/FStar/issues/1757 open FStar.UInt open FStar.Mul #set-options "--max_fuel 0 --max_ifuel 0" (** Abstract type of machine integers, with an underlying representation using a bounded mathematical integer *) new val t : eqtype (** A coercion that projects a bounded mathematical integer from a machine integer *) val v (x:t) : Tot (uint_t n) (** A coercion that injects a bounded mathematical integers into a machine integer *) val uint_to_t (x:uint_t n) : Pure t (requires True) (ensures (fun y -> v y = x)) (** Injection/projection inverse *) val uv_inv (x : t) : Lemma (ensures (uint_to_t (v x) == x)) [SMTPat (v x)] (** Projection/injection inverse *) val vu_inv (x : uint_t n) : Lemma (ensures (v (uint_to_t x) == x)) [SMTPat (uint_to_t x)] (** An alternate form of the injectivity of the [v] projection *) val v_inj (x1 x2: t): Lemma (requires (v x1 == v x2)) (ensures (x1 == x2)) (** Constants 0 and 1 *) val zero : x:t{v x = 0} val one : x:t{v x = 1} (**** Addition primitives *) (** Bounds-respecting addition The precondition enforces that the sum does not overflow, expressing the bound as an addition on mathematical integers *) val add (a:t) (b:t) : Pure t (requires (size (v a + v b) n)) (ensures (fun c -> v a + v b = v c)) (** Underspecified, possibly overflowing addition: The postcondition only enures that the result is the sum of the arguments in case there is no overflow *) val add_underspec (a:t) (b:t) : Pure t (requires True) (ensures (fun c -> size (v a + v b) n ==> v a + v b = v c)) (** Addition modulo [2^n] Machine integers can always be added, but the postcondition is now in terms of addition modulo [2^n] on mathematical integers *) val add_mod (a:t) (b:t) : Pure t (requires True) (ensures (fun c -> FStar.UInt.add_mod (v a) (v b) = v c)) (**** Subtraction primitives *) (** Bounds-respecting subtraction The precondition enforces that the difference does not underflow, expressing the bound as a difference on mathematical integers *) val sub (a:t) (b:t) : Pure t (requires (size (v a - v b) n)) (ensures (fun c -> v a - v b = v c)) (** Underspecified, possibly overflowing subtraction: The postcondition only enures that the result is the difference of the arguments in case there is no underflow *) val sub_underspec (a:t) (b:t) : Pure t (requires True) (ensures (fun c -> size (v a - v b) n ==> v a - v b = v c)) (** Subtraction modulo [2^n] Machine integers can always be subtractd, but the postcondition is now in terms of subtraction modulo [2^n] on mathematical integers *) val sub_mod (a:t) (b:t) : Pure t (requires True) (ensures (fun c -> FStar.UInt.sub_mod (v a) (v b) = v c)) (**** Multiplication primitives *) (** Bounds-respecting multiplication The precondition enforces that the product does not overflow, expressing the bound as a product on mathematical integers *) val mul (a:t) (b:t) : Pure t (requires (size (v a * v b) n)) (ensures (fun c -> v a * v b = v c)) (** Underspecified, possibly overflowing product The postcondition only enures that the result is the product of the arguments in case there is no overflow *) val mul_underspec (a:t) (b:t) : Pure t (requires True) (ensures (fun c -> size (v a * v b) n ==> v a * v b = v c)) (** Multiplication modulo [2^n] Machine integers can always be multiplied, but the postcondition is now in terms of product modulo [2^n] on mathematical integers *) val mul_mod (a:t) (b:t) : Pure t (requires True) (ensures (fun c -> FStar.UInt.mul_mod (v a) (v b) = v c)) (**** Division primitives *) (** Euclidean division of [a] and [b], with [b] non-zero *) val div (a:t) (b:t{v b <> 0}) : Pure t (requires (True)) (ensures (fun c -> v a / v b = v c)) (**** Modulo primitives *) (** Euclidean remainder The result is the modulus of [a] with respect to a non-zero [b] *) val rem (a:t) (b:t{v b <> 0}) : Pure t (requires True) (ensures (fun c -> FStar.UInt.mod (v a) (v b) = v c)) (**** Bitwise operators *) /// Also see FStar.BV (** Bitwise logical conjunction *) val logand (x:t) (y:t) : Pure t (requires True) (ensures (fun z -> v x `logand` v y = v z)) (** Bitwise logical exclusive-or *) val logxor (x:t) (y:t) : Pure t (requires True) (ensures (fun z -> v x `logxor` v y == v z)) (** Bitwise logical disjunction *) val logor (x:t) (y:t) : Pure t (requires True) (ensures (fun z -> v x `logor` v y == v z)) (** Bitwise logical negation *) val lognot (x:t) : Pure t (requires True) (ensures (fun z -> lognot (v x) == v z)) (**** Shift operators *) (** Shift right with zero fill, shifting at most the integer width *) val shift_right (a:t) (s:UInt32.t) : Pure t (requires (UInt32.v s < n)) (ensures (fun c -> FStar.UInt.shift_right (v a) (UInt32.v s) = v c)) (** Shift left with zero fill, shifting at most the integer width *) val shift_left (a:t) (s:UInt32.t) : Pure t (requires (UInt32.v s < n)) (ensures (fun c -> FStar.UInt.shift_left (v a) (UInt32.v s) = v c)) (**** Comparison operators *) (** Equality Note, it is safe to also use the polymorphic decidable equality operator [=] *) let eq (a:t) (b:t) : Tot bool = eq #n (v a) (v b) (** Greater than *) let gt (a:t) (b:t) : Tot bool = gt #n (v a) (v b) (** Greater than or equal *) let gte (a:t) (b:t) : Tot bool = gte #n (v a) (v b) (** Less than *) let lt (a:t) (b:t) : Tot bool = lt #n (v a) (v b) (** Less than or equal *) let lte (a:t) (b:t) : Tot bool = lte #n (v a) (v b) (** Unary negation *) inline_for_extraction let minus (a:t) = add_mod (lognot a) (uint_to_t 1) (** The maximum shift value for this type, i.e. its width minus one, as an UInt32. *) inline_for_extraction let n_minus_one = UInt32.uint_to_t (n - 1) #set-options "--z3rlimit 80 --initial_fuel 1 --max_fuel 1" (** A constant-time way to compute the equality of two machine integers. With inspiration from https://git.zx2c4.com/WireGuard/commit/src/crypto/curve25519-hacl64.h?id=2e60bb395c1f589a398ec606d611132ef9ef764b Note, the branching on [a=b] is just for proof-purposes. *) [@ CNoInline ] let eq_mask (a:t) (b:t) : Pure t (requires True) (ensures (fun c -> (v a = v b ==> v c = pow2 n - 1) /\ (v a <> v b ==> v c = 0))) = let x = logxor a b in let minus_x = minus x in let x_or_minus_x = logor x minus_x in let xnx = shift_right x_or_minus_x n_minus_one in let c = sub_mod xnx (uint_to_t 1) in if a = b then begin logxor_self (v a); lognot_lemma_1 #n; logor_lemma_1 (v x); assert (v x = 0 /\ v minus_x = 0 /\ v x_or_minus_x = 0 /\ v xnx = 0); assert (v c = ones n) end else begin logxor_neq_nonzero (v a) (v b); lemma_msb_pow2 #n (v (lognot x)); lemma_msb_pow2 #n (v minus_x); lemma_minus_zero #n (v x); assert (v c = FStar.UInt.zero n) end; c private val lemma_sub_msbs (a:t) (b:t) : Lemma ((msb (v a) = msb (v b)) ==> (v a < v b <==> msb (v (sub_mod a b)))) (** A constant-time way to compute the [>=] inequality of two machine integers. With inspiration from https://git.zx2c4.com/WireGuard/commit/src/crypto/curve25519-hacl64.h?id=0a483a9b431d87eca1b275463c632f8d5551978a *) [@ CNoInline ] let gte_mask (a:t) (b:t) : Pure t (requires True) (ensures (fun c -> (v a >= v b ==> v c = pow2 n - 1) /\ (v a < v b ==> v c = 0))) = let x = a in let y = b in let x_xor_y = logxor x y in let x_sub_y = sub_mod x y in let x_sub_y_xor_y = logxor x_sub_y y in let q = logor x_xor_y x_sub_y_xor_y in let x_xor_q = logxor x q in let x_xor_q_ = shift_right x_xor_q n_minus_one in let c = sub_mod x_xor_q_ (uint_to_t 1) in lemma_sub_msbs x y; lemma_msb_gte (v x) (v y); lemma_msb_gte (v y) (v x); c #reset-options (*** Infix notations *) unfold let op_Plus_Hat = add unfold let op_Plus_Question_Hat = add_underspec unfold let op_Plus_Percent_Hat = add_mod unfold let op_Subtraction_Hat = sub unfold let op_Subtraction_Question_Hat = sub_underspec unfold let op_Subtraction_Percent_Hat = sub_mod unfold let op_Star_Hat = mul unfold let op_Star_Question_Hat = mul_underspec unfold let op_Star_Percent_Hat = mul_mod unfold let op_Slash_Hat = div unfold let op_Percent_Hat = rem unfold let op_Hat_Hat = logxor unfold let op_Amp_Hat = logand unfold let op_Bar_Hat = logor unfold let op_Less_Less_Hat = shift_left unfold let op_Greater_Greater_Hat = shift_right unfold let op_Equals_Hat = eq unfold let op_Greater_Hat = gt unfold let op_Greater_Equals_Hat = gte
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.UInt32.fsti.checked", "FStar.UInt.fsti.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked" ], "interface_file": false, "source_file": "FStar.UInt64.fsti" }
[ { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.UInt", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.UInt", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "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: FStar.UInt64.t -> b: FStar.UInt64.t -> Prims.bool
Prims.Tot
[ "total" ]
[]
[ "FStar.UInt64.lte" ]
[]
false
false
false
true
false
let op_Less_Equals_Hat =
lte
false
FStar.UInt64.fsti
FStar.UInt64.op_Equals_Hat
val op_Equals_Hat : a: FStar.UInt64.t -> b: FStar.UInt64.t -> Prims.bool
let op_Equals_Hat = eq
{ "file_name": "ulib/FStar.UInt64.fsti", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 29, "end_line": 332, "start_col": 7, "start_line": 332 }
(* 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 FStar.UInt64 (**** THIS MODULE IS GENERATED AUTOMATICALLY USING [mk_int.sh], DO NOT EDIT DIRECTLY ****) unfold let n = 64 /// For FStar.UIntN.fstp: anything that you fix/update here should be /// reflected in [FStar.IntN.fstp], which is mostly a copy-paste of /// this module. /// /// Except, as compared to [FStar.IntN.fstp], here: /// - every occurrence of [int_t] has been replaced with [uint_t] /// - every occurrence of [@%] has been replaced with [%]. /// - some functions (e.g., add_underspec, etc.) are only defined here, not on signed integers /// This module provides an abstract type for machine integers of a /// given signedness and width. The interface is designed to be safe /// with respect to arithmetic underflow and overflow. /// Note, we have attempted several times to re-design this module to /// make it more amenable to normalization and to impose less overhead /// on the SMT solver when reasoning about machine integer /// arithmetic. The following github issue reports on the current /// status of that work. /// /// https://github.com/FStarLang/FStar/issues/1757 open FStar.UInt open FStar.Mul #set-options "--max_fuel 0 --max_ifuel 0" (** Abstract type of machine integers, with an underlying representation using a bounded mathematical integer *) new val t : eqtype (** A coercion that projects a bounded mathematical integer from a machine integer *) val v (x:t) : Tot (uint_t n) (** A coercion that injects a bounded mathematical integers into a machine integer *) val uint_to_t (x:uint_t n) : Pure t (requires True) (ensures (fun y -> v y = x)) (** Injection/projection inverse *) val uv_inv (x : t) : Lemma (ensures (uint_to_t (v x) == x)) [SMTPat (v x)] (** Projection/injection inverse *) val vu_inv (x : uint_t n) : Lemma (ensures (v (uint_to_t x) == x)) [SMTPat (uint_to_t x)] (** An alternate form of the injectivity of the [v] projection *) val v_inj (x1 x2: t): Lemma (requires (v x1 == v x2)) (ensures (x1 == x2)) (** Constants 0 and 1 *) val zero : x:t{v x = 0} val one : x:t{v x = 1} (**** Addition primitives *) (** Bounds-respecting addition The precondition enforces that the sum does not overflow, expressing the bound as an addition on mathematical integers *) val add (a:t) (b:t) : Pure t (requires (size (v a + v b) n)) (ensures (fun c -> v a + v b = v c)) (** Underspecified, possibly overflowing addition: The postcondition only enures that the result is the sum of the arguments in case there is no overflow *) val add_underspec (a:t) (b:t) : Pure t (requires True) (ensures (fun c -> size (v a + v b) n ==> v a + v b = v c)) (** Addition modulo [2^n] Machine integers can always be added, but the postcondition is now in terms of addition modulo [2^n] on mathematical integers *) val add_mod (a:t) (b:t) : Pure t (requires True) (ensures (fun c -> FStar.UInt.add_mod (v a) (v b) = v c)) (**** Subtraction primitives *) (** Bounds-respecting subtraction The precondition enforces that the difference does not underflow, expressing the bound as a difference on mathematical integers *) val sub (a:t) (b:t) : Pure t (requires (size (v a - v b) n)) (ensures (fun c -> v a - v b = v c)) (** Underspecified, possibly overflowing subtraction: The postcondition only enures that the result is the difference of the arguments in case there is no underflow *) val sub_underspec (a:t) (b:t) : Pure t (requires True) (ensures (fun c -> size (v a - v b) n ==> v a - v b = v c)) (** Subtraction modulo [2^n] Machine integers can always be subtractd, but the postcondition is now in terms of subtraction modulo [2^n] on mathematical integers *) val sub_mod (a:t) (b:t) : Pure t (requires True) (ensures (fun c -> FStar.UInt.sub_mod (v a) (v b) = v c)) (**** Multiplication primitives *) (** Bounds-respecting multiplication The precondition enforces that the product does not overflow, expressing the bound as a product on mathematical integers *) val mul (a:t) (b:t) : Pure t (requires (size (v a * v b) n)) (ensures (fun c -> v a * v b = v c)) (** Underspecified, possibly overflowing product The postcondition only enures that the result is the product of the arguments in case there is no overflow *) val mul_underspec (a:t) (b:t) : Pure t (requires True) (ensures (fun c -> size (v a * v b) n ==> v a * v b = v c)) (** Multiplication modulo [2^n] Machine integers can always be multiplied, but the postcondition is now in terms of product modulo [2^n] on mathematical integers *) val mul_mod (a:t) (b:t) : Pure t (requires True) (ensures (fun c -> FStar.UInt.mul_mod (v a) (v b) = v c)) (**** Division primitives *) (** Euclidean division of [a] and [b], with [b] non-zero *) val div (a:t) (b:t{v b <> 0}) : Pure t (requires (True)) (ensures (fun c -> v a / v b = v c)) (**** Modulo primitives *) (** Euclidean remainder The result is the modulus of [a] with respect to a non-zero [b] *) val rem (a:t) (b:t{v b <> 0}) : Pure t (requires True) (ensures (fun c -> FStar.UInt.mod (v a) (v b) = v c)) (**** Bitwise operators *) /// Also see FStar.BV (** Bitwise logical conjunction *) val logand (x:t) (y:t) : Pure t (requires True) (ensures (fun z -> v x `logand` v y = v z)) (** Bitwise logical exclusive-or *) val logxor (x:t) (y:t) : Pure t (requires True) (ensures (fun z -> v x `logxor` v y == v z)) (** Bitwise logical disjunction *) val logor (x:t) (y:t) : Pure t (requires True) (ensures (fun z -> v x `logor` v y == v z)) (** Bitwise logical negation *) val lognot (x:t) : Pure t (requires True) (ensures (fun z -> lognot (v x) == v z)) (**** Shift operators *) (** Shift right with zero fill, shifting at most the integer width *) val shift_right (a:t) (s:UInt32.t) : Pure t (requires (UInt32.v s < n)) (ensures (fun c -> FStar.UInt.shift_right (v a) (UInt32.v s) = v c)) (** Shift left with zero fill, shifting at most the integer width *) val shift_left (a:t) (s:UInt32.t) : Pure t (requires (UInt32.v s < n)) (ensures (fun c -> FStar.UInt.shift_left (v a) (UInt32.v s) = v c)) (**** Comparison operators *) (** Equality Note, it is safe to also use the polymorphic decidable equality operator [=] *) let eq (a:t) (b:t) : Tot bool = eq #n (v a) (v b) (** Greater than *) let gt (a:t) (b:t) : Tot bool = gt #n (v a) (v b) (** Greater than or equal *) let gte (a:t) (b:t) : Tot bool = gte #n (v a) (v b) (** Less than *) let lt (a:t) (b:t) : Tot bool = lt #n (v a) (v b) (** Less than or equal *) let lte (a:t) (b:t) : Tot bool = lte #n (v a) (v b) (** Unary negation *) inline_for_extraction let minus (a:t) = add_mod (lognot a) (uint_to_t 1) (** The maximum shift value for this type, i.e. its width minus one, as an UInt32. *) inline_for_extraction let n_minus_one = UInt32.uint_to_t (n - 1) #set-options "--z3rlimit 80 --initial_fuel 1 --max_fuel 1" (** A constant-time way to compute the equality of two machine integers. With inspiration from https://git.zx2c4.com/WireGuard/commit/src/crypto/curve25519-hacl64.h?id=2e60bb395c1f589a398ec606d611132ef9ef764b Note, the branching on [a=b] is just for proof-purposes. *) [@ CNoInline ] let eq_mask (a:t) (b:t) : Pure t (requires True) (ensures (fun c -> (v a = v b ==> v c = pow2 n - 1) /\ (v a <> v b ==> v c = 0))) = let x = logxor a b in let minus_x = minus x in let x_or_minus_x = logor x minus_x in let xnx = shift_right x_or_minus_x n_minus_one in let c = sub_mod xnx (uint_to_t 1) in if a = b then begin logxor_self (v a); lognot_lemma_1 #n; logor_lemma_1 (v x); assert (v x = 0 /\ v minus_x = 0 /\ v x_or_minus_x = 0 /\ v xnx = 0); assert (v c = ones n) end else begin logxor_neq_nonzero (v a) (v b); lemma_msb_pow2 #n (v (lognot x)); lemma_msb_pow2 #n (v minus_x); lemma_minus_zero #n (v x); assert (v c = FStar.UInt.zero n) end; c private val lemma_sub_msbs (a:t) (b:t) : Lemma ((msb (v a) = msb (v b)) ==> (v a < v b <==> msb (v (sub_mod a b)))) (** A constant-time way to compute the [>=] inequality of two machine integers. With inspiration from https://git.zx2c4.com/WireGuard/commit/src/crypto/curve25519-hacl64.h?id=0a483a9b431d87eca1b275463c632f8d5551978a *) [@ CNoInline ] let gte_mask (a:t) (b:t) : Pure t (requires True) (ensures (fun c -> (v a >= v b ==> v c = pow2 n - 1) /\ (v a < v b ==> v c = 0))) = let x = a in let y = b in let x_xor_y = logxor x y in let x_sub_y = sub_mod x y in let x_sub_y_xor_y = logxor x_sub_y y in let q = logor x_xor_y x_sub_y_xor_y in let x_xor_q = logxor x q in let x_xor_q_ = shift_right x_xor_q n_minus_one in let c = sub_mod x_xor_q_ (uint_to_t 1) in lemma_sub_msbs x y; lemma_msb_gte (v x) (v y); lemma_msb_gte (v y) (v x); c #reset-options (*** Infix notations *) unfold let op_Plus_Hat = add unfold let op_Plus_Question_Hat = add_underspec unfold let op_Plus_Percent_Hat = add_mod unfold let op_Subtraction_Hat = sub unfold let op_Subtraction_Question_Hat = sub_underspec unfold let op_Subtraction_Percent_Hat = sub_mod unfold let op_Star_Hat = mul unfold let op_Star_Question_Hat = mul_underspec unfold let op_Star_Percent_Hat = mul_mod unfold let op_Slash_Hat = div unfold let op_Percent_Hat = rem unfold let op_Hat_Hat = logxor unfold let op_Amp_Hat = logand unfold let op_Bar_Hat = logor unfold let op_Less_Less_Hat = shift_left
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.UInt32.fsti.checked", "FStar.UInt.fsti.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked" ], "interface_file": false, "source_file": "FStar.UInt64.fsti" }
[ { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.UInt", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.UInt", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "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: FStar.UInt64.t -> b: FStar.UInt64.t -> Prims.bool
Prims.Tot
[ "total" ]
[]
[ "FStar.UInt64.eq" ]
[]
false
false
false
true
false
let op_Equals_Hat =
eq
false
FStar.UInt64.fsti
FStar.UInt64.op_Less_Hat
val op_Less_Hat : a: FStar.UInt64.t -> b: FStar.UInt64.t -> Prims.bool
let op_Less_Hat = lt
{ "file_name": "ulib/FStar.UInt64.fsti", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 27, "end_line": 335, "start_col": 7, "start_line": 335 }
(* 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 FStar.UInt64 (**** THIS MODULE IS GENERATED AUTOMATICALLY USING [mk_int.sh], DO NOT EDIT DIRECTLY ****) unfold let n = 64 /// For FStar.UIntN.fstp: anything that you fix/update here should be /// reflected in [FStar.IntN.fstp], which is mostly a copy-paste of /// this module. /// /// Except, as compared to [FStar.IntN.fstp], here: /// - every occurrence of [int_t] has been replaced with [uint_t] /// - every occurrence of [@%] has been replaced with [%]. /// - some functions (e.g., add_underspec, etc.) are only defined here, not on signed integers /// This module provides an abstract type for machine integers of a /// given signedness and width. The interface is designed to be safe /// with respect to arithmetic underflow and overflow. /// Note, we have attempted several times to re-design this module to /// make it more amenable to normalization and to impose less overhead /// on the SMT solver when reasoning about machine integer /// arithmetic. The following github issue reports on the current /// status of that work. /// /// https://github.com/FStarLang/FStar/issues/1757 open FStar.UInt open FStar.Mul #set-options "--max_fuel 0 --max_ifuel 0" (** Abstract type of machine integers, with an underlying representation using a bounded mathematical integer *) new val t : eqtype (** A coercion that projects a bounded mathematical integer from a machine integer *) val v (x:t) : Tot (uint_t n) (** A coercion that injects a bounded mathematical integers into a machine integer *) val uint_to_t (x:uint_t n) : Pure t (requires True) (ensures (fun y -> v y = x)) (** Injection/projection inverse *) val uv_inv (x : t) : Lemma (ensures (uint_to_t (v x) == x)) [SMTPat (v x)] (** Projection/injection inverse *) val vu_inv (x : uint_t n) : Lemma (ensures (v (uint_to_t x) == x)) [SMTPat (uint_to_t x)] (** An alternate form of the injectivity of the [v] projection *) val v_inj (x1 x2: t): Lemma (requires (v x1 == v x2)) (ensures (x1 == x2)) (** Constants 0 and 1 *) val zero : x:t{v x = 0} val one : x:t{v x = 1} (**** Addition primitives *) (** Bounds-respecting addition The precondition enforces that the sum does not overflow, expressing the bound as an addition on mathematical integers *) val add (a:t) (b:t) : Pure t (requires (size (v a + v b) n)) (ensures (fun c -> v a + v b = v c)) (** Underspecified, possibly overflowing addition: The postcondition only enures that the result is the sum of the arguments in case there is no overflow *) val add_underspec (a:t) (b:t) : Pure t (requires True) (ensures (fun c -> size (v a + v b) n ==> v a + v b = v c)) (** Addition modulo [2^n] Machine integers can always be added, but the postcondition is now in terms of addition modulo [2^n] on mathematical integers *) val add_mod (a:t) (b:t) : Pure t (requires True) (ensures (fun c -> FStar.UInt.add_mod (v a) (v b) = v c)) (**** Subtraction primitives *) (** Bounds-respecting subtraction The precondition enforces that the difference does not underflow, expressing the bound as a difference on mathematical integers *) val sub (a:t) (b:t) : Pure t (requires (size (v a - v b) n)) (ensures (fun c -> v a - v b = v c)) (** Underspecified, possibly overflowing subtraction: The postcondition only enures that the result is the difference of the arguments in case there is no underflow *) val sub_underspec (a:t) (b:t) : Pure t (requires True) (ensures (fun c -> size (v a - v b) n ==> v a - v b = v c)) (** Subtraction modulo [2^n] Machine integers can always be subtractd, but the postcondition is now in terms of subtraction modulo [2^n] on mathematical integers *) val sub_mod (a:t) (b:t) : Pure t (requires True) (ensures (fun c -> FStar.UInt.sub_mod (v a) (v b) = v c)) (**** Multiplication primitives *) (** Bounds-respecting multiplication The precondition enforces that the product does not overflow, expressing the bound as a product on mathematical integers *) val mul (a:t) (b:t) : Pure t (requires (size (v a * v b) n)) (ensures (fun c -> v a * v b = v c)) (** Underspecified, possibly overflowing product The postcondition only enures that the result is the product of the arguments in case there is no overflow *) val mul_underspec (a:t) (b:t) : Pure t (requires True) (ensures (fun c -> size (v a * v b) n ==> v a * v b = v c)) (** Multiplication modulo [2^n] Machine integers can always be multiplied, but the postcondition is now in terms of product modulo [2^n] on mathematical integers *) val mul_mod (a:t) (b:t) : Pure t (requires True) (ensures (fun c -> FStar.UInt.mul_mod (v a) (v b) = v c)) (**** Division primitives *) (** Euclidean division of [a] and [b], with [b] non-zero *) val div (a:t) (b:t{v b <> 0}) : Pure t (requires (True)) (ensures (fun c -> v a / v b = v c)) (**** Modulo primitives *) (** Euclidean remainder The result is the modulus of [a] with respect to a non-zero [b] *) val rem (a:t) (b:t{v b <> 0}) : Pure t (requires True) (ensures (fun c -> FStar.UInt.mod (v a) (v b) = v c)) (**** Bitwise operators *) /// Also see FStar.BV (** Bitwise logical conjunction *) val logand (x:t) (y:t) : Pure t (requires True) (ensures (fun z -> v x `logand` v y = v z)) (** Bitwise logical exclusive-or *) val logxor (x:t) (y:t) : Pure t (requires True) (ensures (fun z -> v x `logxor` v y == v z)) (** Bitwise logical disjunction *) val logor (x:t) (y:t) : Pure t (requires True) (ensures (fun z -> v x `logor` v y == v z)) (** Bitwise logical negation *) val lognot (x:t) : Pure t (requires True) (ensures (fun z -> lognot (v x) == v z)) (**** Shift operators *) (** Shift right with zero fill, shifting at most the integer width *) val shift_right (a:t) (s:UInt32.t) : Pure t (requires (UInt32.v s < n)) (ensures (fun c -> FStar.UInt.shift_right (v a) (UInt32.v s) = v c)) (** Shift left with zero fill, shifting at most the integer width *) val shift_left (a:t) (s:UInt32.t) : Pure t (requires (UInt32.v s < n)) (ensures (fun c -> FStar.UInt.shift_left (v a) (UInt32.v s) = v c)) (**** Comparison operators *) (** Equality Note, it is safe to also use the polymorphic decidable equality operator [=] *) let eq (a:t) (b:t) : Tot bool = eq #n (v a) (v b) (** Greater than *) let gt (a:t) (b:t) : Tot bool = gt #n (v a) (v b) (** Greater than or equal *) let gte (a:t) (b:t) : Tot bool = gte #n (v a) (v b) (** Less than *) let lt (a:t) (b:t) : Tot bool = lt #n (v a) (v b) (** Less than or equal *) let lte (a:t) (b:t) : Tot bool = lte #n (v a) (v b) (** Unary negation *) inline_for_extraction let minus (a:t) = add_mod (lognot a) (uint_to_t 1) (** The maximum shift value for this type, i.e. its width minus one, as an UInt32. *) inline_for_extraction let n_minus_one = UInt32.uint_to_t (n - 1) #set-options "--z3rlimit 80 --initial_fuel 1 --max_fuel 1" (** A constant-time way to compute the equality of two machine integers. With inspiration from https://git.zx2c4.com/WireGuard/commit/src/crypto/curve25519-hacl64.h?id=2e60bb395c1f589a398ec606d611132ef9ef764b Note, the branching on [a=b] is just for proof-purposes. *) [@ CNoInline ] let eq_mask (a:t) (b:t) : Pure t (requires True) (ensures (fun c -> (v a = v b ==> v c = pow2 n - 1) /\ (v a <> v b ==> v c = 0))) = let x = logxor a b in let minus_x = minus x in let x_or_minus_x = logor x minus_x in let xnx = shift_right x_or_minus_x n_minus_one in let c = sub_mod xnx (uint_to_t 1) in if a = b then begin logxor_self (v a); lognot_lemma_1 #n; logor_lemma_1 (v x); assert (v x = 0 /\ v minus_x = 0 /\ v x_or_minus_x = 0 /\ v xnx = 0); assert (v c = ones n) end else begin logxor_neq_nonzero (v a) (v b); lemma_msb_pow2 #n (v (lognot x)); lemma_msb_pow2 #n (v minus_x); lemma_minus_zero #n (v x); assert (v c = FStar.UInt.zero n) end; c private val lemma_sub_msbs (a:t) (b:t) : Lemma ((msb (v a) = msb (v b)) ==> (v a < v b <==> msb (v (sub_mod a b)))) (** A constant-time way to compute the [>=] inequality of two machine integers. With inspiration from https://git.zx2c4.com/WireGuard/commit/src/crypto/curve25519-hacl64.h?id=0a483a9b431d87eca1b275463c632f8d5551978a *) [@ CNoInline ] let gte_mask (a:t) (b:t) : Pure t (requires True) (ensures (fun c -> (v a >= v b ==> v c = pow2 n - 1) /\ (v a < v b ==> v c = 0))) = let x = a in let y = b in let x_xor_y = logxor x y in let x_sub_y = sub_mod x y in let x_sub_y_xor_y = logxor x_sub_y y in let q = logor x_xor_y x_sub_y_xor_y in let x_xor_q = logxor x q in let x_xor_q_ = shift_right x_xor_q n_minus_one in let c = sub_mod x_xor_q_ (uint_to_t 1) in lemma_sub_msbs x y; lemma_msb_gte (v x) (v y); lemma_msb_gte (v y) (v x); c #reset-options (*** Infix notations *) unfold let op_Plus_Hat = add unfold let op_Plus_Question_Hat = add_underspec unfold let op_Plus_Percent_Hat = add_mod unfold let op_Subtraction_Hat = sub unfold let op_Subtraction_Question_Hat = sub_underspec unfold let op_Subtraction_Percent_Hat = sub_mod unfold let op_Star_Hat = mul unfold let op_Star_Question_Hat = mul_underspec unfold let op_Star_Percent_Hat = mul_mod unfold let op_Slash_Hat = div unfold let op_Percent_Hat = rem unfold let op_Hat_Hat = logxor unfold let op_Amp_Hat = logand unfold let op_Bar_Hat = logor unfold let op_Less_Less_Hat = shift_left unfold let op_Greater_Greater_Hat = shift_right unfold let op_Equals_Hat = eq unfold let op_Greater_Hat = gt
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.UInt32.fsti.checked", "FStar.UInt.fsti.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked" ], "interface_file": false, "source_file": "FStar.UInt64.fsti" }
[ { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.UInt", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.UInt", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "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: FStar.UInt64.t -> b: FStar.UInt64.t -> Prims.bool
Prims.Tot
[ "total" ]
[]
[ "FStar.UInt64.lt" ]
[]
false
false
false
true
false
let op_Less_Hat =
lt
false
FStar.UInt64.fsti
FStar.UInt64.op_Greater_Equals_Hat
val op_Greater_Equals_Hat : a: FStar.UInt64.t -> b: FStar.UInt64.t -> Prims.bool
let op_Greater_Equals_Hat = gte
{ "file_name": "ulib/FStar.UInt64.fsti", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 38, "end_line": 334, "start_col": 7, "start_line": 334 }
(* 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 FStar.UInt64 (**** THIS MODULE IS GENERATED AUTOMATICALLY USING [mk_int.sh], DO NOT EDIT DIRECTLY ****) unfold let n = 64 /// For FStar.UIntN.fstp: anything that you fix/update here should be /// reflected in [FStar.IntN.fstp], which is mostly a copy-paste of /// this module. /// /// Except, as compared to [FStar.IntN.fstp], here: /// - every occurrence of [int_t] has been replaced with [uint_t] /// - every occurrence of [@%] has been replaced with [%]. /// - some functions (e.g., add_underspec, etc.) are only defined here, not on signed integers /// This module provides an abstract type for machine integers of a /// given signedness and width. The interface is designed to be safe /// with respect to arithmetic underflow and overflow. /// Note, we have attempted several times to re-design this module to /// make it more amenable to normalization and to impose less overhead /// on the SMT solver when reasoning about machine integer /// arithmetic. The following github issue reports on the current /// status of that work. /// /// https://github.com/FStarLang/FStar/issues/1757 open FStar.UInt open FStar.Mul #set-options "--max_fuel 0 --max_ifuel 0" (** Abstract type of machine integers, with an underlying representation using a bounded mathematical integer *) new val t : eqtype (** A coercion that projects a bounded mathematical integer from a machine integer *) val v (x:t) : Tot (uint_t n) (** A coercion that injects a bounded mathematical integers into a machine integer *) val uint_to_t (x:uint_t n) : Pure t (requires True) (ensures (fun y -> v y = x)) (** Injection/projection inverse *) val uv_inv (x : t) : Lemma (ensures (uint_to_t (v x) == x)) [SMTPat (v x)] (** Projection/injection inverse *) val vu_inv (x : uint_t n) : Lemma (ensures (v (uint_to_t x) == x)) [SMTPat (uint_to_t x)] (** An alternate form of the injectivity of the [v] projection *) val v_inj (x1 x2: t): Lemma (requires (v x1 == v x2)) (ensures (x1 == x2)) (** Constants 0 and 1 *) val zero : x:t{v x = 0} val one : x:t{v x = 1} (**** Addition primitives *) (** Bounds-respecting addition The precondition enforces that the sum does not overflow, expressing the bound as an addition on mathematical integers *) val add (a:t) (b:t) : Pure t (requires (size (v a + v b) n)) (ensures (fun c -> v a + v b = v c)) (** Underspecified, possibly overflowing addition: The postcondition only enures that the result is the sum of the arguments in case there is no overflow *) val add_underspec (a:t) (b:t) : Pure t (requires True) (ensures (fun c -> size (v a + v b) n ==> v a + v b = v c)) (** Addition modulo [2^n] Machine integers can always be added, but the postcondition is now in terms of addition modulo [2^n] on mathematical integers *) val add_mod (a:t) (b:t) : Pure t (requires True) (ensures (fun c -> FStar.UInt.add_mod (v a) (v b) = v c)) (**** Subtraction primitives *) (** Bounds-respecting subtraction The precondition enforces that the difference does not underflow, expressing the bound as a difference on mathematical integers *) val sub (a:t) (b:t) : Pure t (requires (size (v a - v b) n)) (ensures (fun c -> v a - v b = v c)) (** Underspecified, possibly overflowing subtraction: The postcondition only enures that the result is the difference of the arguments in case there is no underflow *) val sub_underspec (a:t) (b:t) : Pure t (requires True) (ensures (fun c -> size (v a - v b) n ==> v a - v b = v c)) (** Subtraction modulo [2^n] Machine integers can always be subtractd, but the postcondition is now in terms of subtraction modulo [2^n] on mathematical integers *) val sub_mod (a:t) (b:t) : Pure t (requires True) (ensures (fun c -> FStar.UInt.sub_mod (v a) (v b) = v c)) (**** Multiplication primitives *) (** Bounds-respecting multiplication The precondition enforces that the product does not overflow, expressing the bound as a product on mathematical integers *) val mul (a:t) (b:t) : Pure t (requires (size (v a * v b) n)) (ensures (fun c -> v a * v b = v c)) (** Underspecified, possibly overflowing product The postcondition only enures that the result is the product of the arguments in case there is no overflow *) val mul_underspec (a:t) (b:t) : Pure t (requires True) (ensures (fun c -> size (v a * v b) n ==> v a * v b = v c)) (** Multiplication modulo [2^n] Machine integers can always be multiplied, but the postcondition is now in terms of product modulo [2^n] on mathematical integers *) val mul_mod (a:t) (b:t) : Pure t (requires True) (ensures (fun c -> FStar.UInt.mul_mod (v a) (v b) = v c)) (**** Division primitives *) (** Euclidean division of [a] and [b], with [b] non-zero *) val div (a:t) (b:t{v b <> 0}) : Pure t (requires (True)) (ensures (fun c -> v a / v b = v c)) (**** Modulo primitives *) (** Euclidean remainder The result is the modulus of [a] with respect to a non-zero [b] *) val rem (a:t) (b:t{v b <> 0}) : Pure t (requires True) (ensures (fun c -> FStar.UInt.mod (v a) (v b) = v c)) (**** Bitwise operators *) /// Also see FStar.BV (** Bitwise logical conjunction *) val logand (x:t) (y:t) : Pure t (requires True) (ensures (fun z -> v x `logand` v y = v z)) (** Bitwise logical exclusive-or *) val logxor (x:t) (y:t) : Pure t (requires True) (ensures (fun z -> v x `logxor` v y == v z)) (** Bitwise logical disjunction *) val logor (x:t) (y:t) : Pure t (requires True) (ensures (fun z -> v x `logor` v y == v z)) (** Bitwise logical negation *) val lognot (x:t) : Pure t (requires True) (ensures (fun z -> lognot (v x) == v z)) (**** Shift operators *) (** Shift right with zero fill, shifting at most the integer width *) val shift_right (a:t) (s:UInt32.t) : Pure t (requires (UInt32.v s < n)) (ensures (fun c -> FStar.UInt.shift_right (v a) (UInt32.v s) = v c)) (** Shift left with zero fill, shifting at most the integer width *) val shift_left (a:t) (s:UInt32.t) : Pure t (requires (UInt32.v s < n)) (ensures (fun c -> FStar.UInt.shift_left (v a) (UInt32.v s) = v c)) (**** Comparison operators *) (** Equality Note, it is safe to also use the polymorphic decidable equality operator [=] *) let eq (a:t) (b:t) : Tot bool = eq #n (v a) (v b) (** Greater than *) let gt (a:t) (b:t) : Tot bool = gt #n (v a) (v b) (** Greater than or equal *) let gte (a:t) (b:t) : Tot bool = gte #n (v a) (v b) (** Less than *) let lt (a:t) (b:t) : Tot bool = lt #n (v a) (v b) (** Less than or equal *) let lte (a:t) (b:t) : Tot bool = lte #n (v a) (v b) (** Unary negation *) inline_for_extraction let minus (a:t) = add_mod (lognot a) (uint_to_t 1) (** The maximum shift value for this type, i.e. its width minus one, as an UInt32. *) inline_for_extraction let n_minus_one = UInt32.uint_to_t (n - 1) #set-options "--z3rlimit 80 --initial_fuel 1 --max_fuel 1" (** A constant-time way to compute the equality of two machine integers. With inspiration from https://git.zx2c4.com/WireGuard/commit/src/crypto/curve25519-hacl64.h?id=2e60bb395c1f589a398ec606d611132ef9ef764b Note, the branching on [a=b] is just for proof-purposes. *) [@ CNoInline ] let eq_mask (a:t) (b:t) : Pure t (requires True) (ensures (fun c -> (v a = v b ==> v c = pow2 n - 1) /\ (v a <> v b ==> v c = 0))) = let x = logxor a b in let minus_x = minus x in let x_or_minus_x = logor x minus_x in let xnx = shift_right x_or_minus_x n_minus_one in let c = sub_mod xnx (uint_to_t 1) in if a = b then begin logxor_self (v a); lognot_lemma_1 #n; logor_lemma_1 (v x); assert (v x = 0 /\ v minus_x = 0 /\ v x_or_minus_x = 0 /\ v xnx = 0); assert (v c = ones n) end else begin logxor_neq_nonzero (v a) (v b); lemma_msb_pow2 #n (v (lognot x)); lemma_msb_pow2 #n (v minus_x); lemma_minus_zero #n (v x); assert (v c = FStar.UInt.zero n) end; c private val lemma_sub_msbs (a:t) (b:t) : Lemma ((msb (v a) = msb (v b)) ==> (v a < v b <==> msb (v (sub_mod a b)))) (** A constant-time way to compute the [>=] inequality of two machine integers. With inspiration from https://git.zx2c4.com/WireGuard/commit/src/crypto/curve25519-hacl64.h?id=0a483a9b431d87eca1b275463c632f8d5551978a *) [@ CNoInline ] let gte_mask (a:t) (b:t) : Pure t (requires True) (ensures (fun c -> (v a >= v b ==> v c = pow2 n - 1) /\ (v a < v b ==> v c = 0))) = let x = a in let y = b in let x_xor_y = logxor x y in let x_sub_y = sub_mod x y in let x_sub_y_xor_y = logxor x_sub_y y in let q = logor x_xor_y x_sub_y_xor_y in let x_xor_q = logxor x q in let x_xor_q_ = shift_right x_xor_q n_minus_one in let c = sub_mod x_xor_q_ (uint_to_t 1) in lemma_sub_msbs x y; lemma_msb_gte (v x) (v y); lemma_msb_gte (v y) (v x); c #reset-options (*** Infix notations *) unfold let op_Plus_Hat = add unfold let op_Plus_Question_Hat = add_underspec unfold let op_Plus_Percent_Hat = add_mod unfold let op_Subtraction_Hat = sub unfold let op_Subtraction_Question_Hat = sub_underspec unfold let op_Subtraction_Percent_Hat = sub_mod unfold let op_Star_Hat = mul unfold let op_Star_Question_Hat = mul_underspec unfold let op_Star_Percent_Hat = mul_mod unfold let op_Slash_Hat = div unfold let op_Percent_Hat = rem unfold let op_Hat_Hat = logxor unfold let op_Amp_Hat = logand unfold let op_Bar_Hat = logor unfold let op_Less_Less_Hat = shift_left unfold let op_Greater_Greater_Hat = shift_right unfold let op_Equals_Hat = eq
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.UInt32.fsti.checked", "FStar.UInt.fsti.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked" ], "interface_file": false, "source_file": "FStar.UInt64.fsti" }
[ { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.UInt", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.UInt", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "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: FStar.UInt64.t -> b: FStar.UInt64.t -> Prims.bool
Prims.Tot
[ "total" ]
[]
[ "FStar.UInt64.gte" ]
[]
false
false
false
true
false
let op_Greater_Equals_Hat =
gte
false
LowParse.Low.BCVLI.fst
LowParse.Low.BCVLI.read_bounded_bcvli
val read_bounded_bcvli (min: nat) (max: nat{min <= max}) : Tot (leaf_reader (parse_bounded_bcvli min max))
val read_bounded_bcvli (min: nat) (max: nat{min <= max}) : Tot (leaf_reader (parse_bounded_bcvli min max))
let read_bounded_bcvli (min: nat) (max: nat { min <= max }) : Tot (leaf_reader (parse_bounded_bcvli min max)) = fun #rrel #rel input pos -> let h = HST.get () in [@inline_let] let _ = valid_facts (parse_bounded_bcvli min max) h input pos; parse_bounded_bcvli_eq min max (bytes_of_slice_from h input pos); valid_facts parse_bcvli h input pos in read_bcvli input pos <: bounded_int32 min max
{ "file_name": "src/lowparse/LowParse.Low.BCVLI.fst", "git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
{ "end_col": 49, "end_line": 273, "start_col": 0, "start_line": 261 }
module LowParse.Low.BCVLI include LowParse.Spec.BCVLI include LowParse.Low.Combinators include LowParse.Low.BoundedInt module B = LowStar.Buffer module HST = FStar.HyperStack.ST module Cast = FStar.Int.Cast module U32 = FStar.UInt32 module U64 = FStar.UInt64 #reset-options "--z3cliopt smt.arith.nl=false --max_fuel 0" #push-options "--z3rlimit 16" let validate_bcvli : validator parse_bcvli = fun #rrel #rel input pos -> let h = HST.get () in [@inline_let] let _ = valid_facts parse_bcvli h input (uint64_to_uint32 pos); parse_bcvli_eq (bytes_of_slice_from h input (uint64_to_uint32 pos)); valid_facts (parse_bounded_integer_le 1) h input (uint64_to_uint32 pos) in let pos1 = validate_total_constant_size (parse_bounded_integer_le 1) 1uL () input pos in if is_error pos1 then pos1 else [@inline_let] let _ = valid_facts (parse_bounded_integer_le 2) h input (uint64_to_uint32 pos1); valid_facts (parse_bounded_integer_le 4) h input (uint64_to_uint32 pos1) in let r = read_bounded_integer_le_1 input (uint64_to_uint32 pos) in if r `U32.lt` 253ul then pos1 else if r = 253ul then let pos2 = validate_total_constant_size (parse_bounded_integer_le 2) 2uL () input pos1 in if is_error pos2 then pos2 else (* because of the non-malleability constraint, I need to actually read the value and check whether it is not a lower integer *) let r = read_bounded_integer_le_2 input (uint64_to_uint32 pos1) in if r `U32.lt` 253ul then validator_error_generic else pos2 else if r = 254ul then let pos2 = validate_total_constant_size (parse_bounded_integer_le 4) 4uL () input pos1 in if is_error pos2 then pos2 else (* because of the non-malleability constraint, I need to actually read the value and check whether it is not a lower integer *) let r = read_bounded_integer_le_4 input (uint64_to_uint32 pos1) in if r `U32.lt` 65536ul then validator_error_generic else pos2 else validator_error_generic let jump_bcvli : jumper parse_bcvli = fun #rrel #rel input pos -> let h = HST.get () in [@inline_let] let _ = valid_facts parse_bcvli h input pos; parse_bcvli_eq (bytes_of_slice_from h input pos); valid_facts (parse_bounded_integer_le 1) h input pos in let pos1 = jump_constant_size (parse_bounded_integer_le 1) 1ul () input pos in [@inline_let] let _ = valid_facts (parse_bounded_integer_le 2) h input pos1; valid_facts (parse_bounded_integer_le 4) h input pos1 in let r = read_bounded_integer_le_1 input pos in if r `U32.lt` 253ul then pos1 else if r = 253ul then jump_constant_size (parse_bounded_integer_le 2) 2ul () input pos1 else jump_constant_size (parse_bounded_integer_le 4) 4ul () input pos1 let read_bcvli : leaf_reader parse_bcvli = fun #rrel #rel input pos -> let h = HST.get () in [@inline_let] let _ = valid_facts parse_bcvli h input pos; parse_bcvli_eq (bytes_of_slice_from h input pos); valid_facts (parse_bounded_integer_le 1) h input pos in let r = read_bounded_integer_le_1 input pos in if r `U32.lt` 253ul then (r <: U32.t) else let pos1 = jump_constant_size (parse_bounded_integer_le 1) 1ul () input pos in [@inline_let] let _ = valid_facts (parse_bounded_integer_le 2) h input pos1; valid_facts (parse_bounded_integer_le 4) h input pos1 in if r = 253ul then read_bounded_integer_le_2 input pos1 <: U32.t else read_bounded_integer_le_4 input pos1 <: U32.t #pop-options module U8 = FStar.UInt8 #push-options "--z3rlimit 32" inline_for_extraction let serialize32_bcvli' (x: U32.t) (#rrel #rel: _) (b: B.mbuffer U8.t rrel rel) (pos: U32.t) : HST.Stack U32.t (requires (fun h -> let len = Seq.length (serialize serialize_bcvli x) in B.live h b /\ U32.v pos + len <= B.length b /\ writable b (U32.v pos) (U32.v pos + len) h )) (ensures (fun h len h' -> Seq.length (serialize serialize_bcvli x) == U32.v len /\ ( B.modifies (B.loc_buffer_from_to b pos (pos `U32.add` len)) h h' /\ B.live h b /\ Seq.slice (B.as_seq h' b) (U32.v pos) (U32.v pos + U32.v len) `Seq.equal` serialize serialize_bcvli x ))) = // [@inline_let] let _ = serialize_bcvli_eq x ; // in let c : bounded_integer 1 = if x `U32.lt` 253ul then x else if x `U32.lt` 65536ul then 253ul else 254ul in [@inline_let] let pos' = Ghost.hide (U32.v pos + Seq.length (serialize serialize_bcvli x)) in let h = HST.get () in [@inline_let] let _ = writable_weaken b (U32.v pos) (Ghost.reveal pos') h (U32.v pos) (U32.v pos + 1) in let len1 = serialize32_bounded_integer_le_1 c b pos in let h1 = HST.get () in [@inline_let] let _ = writable_modifies b (U32.v pos) (Ghost.reveal pos') h B.loc_none h1 in if c `U32.lt` 253ul then begin len1 end else if c = 253ul then begin [@inline_let] let _ = assert (U32.v x < 65536) in [@inline_let] let _ = writable_weaken b (U32.v pos) (Ghost.reveal pos') h1 (U32.v pos + U32.v len1) ((U32.v pos + U32.v len1) + 2) in let len2 = serialize32_bounded_integer_le_2 x b (pos `U32.add` len1) in let h' = HST.get () in [@inline_let] let len = len1 `U32.add` len2 in B.modifies_buffer_from_to_elim b pos (pos `U32.add` len1) (B.loc_buffer_from_to b (pos `U32.add` len1) (pos `U32.add` len)) h1 h'; len end else begin [@inline_let] let _ = writable_weaken b (U32.v pos) (Ghost.reveal pos') h1 (U32.v pos + U32.v len1) ((U32.v pos + U32.v len1) + 4) in let len2 = serialize32_bounded_integer_le_4 x b (pos `U32.add` len1) in let h' = HST.get () in [@inline_let] let len = len1 `U32.add` len2 in B.modifies_buffer_from_to_elim b pos (pos `U32.add` len1) (B.loc_buffer_from_to b (pos `U32.add` len1) (pos `U32.add` len)) h1 h'; len end inline_for_extraction let serialize32_bcvli : serializer32 serialize_bcvli = fun (x: U32.t) #rrel #rel b pos -> serialize32_bcvli' x b pos let write_bcvli : leaf_writer_strong serialize_bcvli = leaf_writer_strong_of_serializer32 serialize32_bcvli () let validate_bounded_bcvli' (min32: U32.t) (max32: U32.t { U32.v min32 <= U32.v max32 }) : Tot (validator (parse_bounded_bcvli (U32.v min32) (U32.v max32))) = fun #rrel #rel input pos -> let h = HST.get () in [@inline_let] let _ = valid_facts (parse_bounded_bcvli (U32.v min32) (U32.v max32)) h input (uint64_to_uint32 pos); parse_bounded_bcvli_eq (U32.v min32) (U32.v max32) (bytes_of_slice_from h input (uint64_to_uint32 pos)); parse_bcvli_eq (bytes_of_slice_from h input (uint64_to_uint32 pos)); valid_facts (parse_bounded_integer_le 1) h input (uint64_to_uint32 pos) in let pos1 = validate_total_constant_size (parse_bounded_integer_le 1) 1uL () input pos in if is_error pos1 then pos1 else [@inline_let] let _ = valid_facts (parse_bounded_integer_le 2) h input (uint64_to_uint32 pos1); valid_facts (parse_bounded_integer_le 4) h input (uint64_to_uint32 pos1) in let r = read_bounded_integer_le_1 input (uint64_to_uint32 pos) in if r `U32.lt` 253ul && min32 `U32.lte` r && r `U32.lte` max32 then pos1 else if max32 `U32.lt` 253ul then validator_error_generic else if r = 253ul then if 65536ul `U32.lte` min32 then validator_error_generic else let pos2 = validate_total_constant_size (parse_bounded_integer_le 2) 2uL () input pos1 in if is_error pos2 then pos2 else (* because of the non-malleability constraint, I need to actually read the value and check whether it is not a lower integer *) let r = read_bounded_integer_le_2 input (uint64_to_uint32 pos1) in if r `U32.lt` 253ul || r `U32.lt` min32 || max32 `U32.lt` r then validator_error_generic else pos2 else if max32 `U32.lt` 65536ul then validator_error_generic else if r = 254ul then let pos2 = validate_total_constant_size (parse_bounded_integer_le 4) 4uL () input pos1 in if is_error pos2 then pos2 else (* because of the non-malleability constraint, I need to actually read the value and check whether it is not a lower integer *) let r = read_bounded_integer_le_4 input (uint64_to_uint32 pos1) in if r `U32.lt` 65536ul || r `U32.lt` min32 || max32 `U32.lt` r then validator_error_generic else pos2 else validator_error_generic inline_for_extraction noextract let validate_bounded_bcvli (min: nat) (min32: U32.t { U32.v min32 == min }) (max: nat { min <= max }) (max32: U32.t { U32.v max32 == max }) : Tot (validator (parse_bounded_bcvli min max)) = validate_bounded_bcvli' min32 max32 inline_for_extraction noextract let jump_bounded_bcvli (min: nat) (max: nat { min <= max }) : Tot (jumper (parse_bounded_bcvli min max)) = fun #rrel #rel input pos -> let h = HST.get () in [@inline_let] let _ = valid_facts (parse_bounded_bcvli min max) h input pos; parse_bounded_bcvli_eq min max (bytes_of_slice_from h input pos); valid_facts parse_bcvli h input pos in jump_bcvli input pos inline_for_extraction
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowStar.Buffer.fst.checked", "LowParse.Spec.BCVLI.fsti.checked", "LowParse.Low.Combinators.fsti.checked", "LowParse.Low.BoundedInt.fsti.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.Ghost.fsti.checked" ], "interface_file": false, "source_file": "LowParse.Low.BCVLI.fst" }
[ { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": true, "full_module": "FStar.Int.Cast", "short_module": "Cast" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": false, "full_module": "LowParse.Low.BoundedInt", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low.Combinators", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec.BCVLI", "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": 0, "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": [ "smt.arith.nl=false" ], "z3refresh": false, "z3rlimit": 32, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
min: Prims.nat -> max: Prims.nat{min <= max} -> LowParse.Low.Base.leaf_reader (LowParse.Spec.BCVLI.parse_bounded_bcvli min max)
Prims.Tot
[ "total" ]
[]
[ "Prims.nat", "Prims.b2t", "Prims.op_LessThanOrEqual", "LowParse.Slice.srel", "LowParse.Bytes.byte", "LowParse.Slice.slice", "FStar.UInt32.t", "LowParse.Low.BCVLI.read_bcvli", "LowParse.Spec.BoundedInt.bounded_int32", "Prims.unit", "LowParse.Low.Base.Spec.valid_facts", "LowParse.Spec.BCVLI.parse_bcvli_kind", "LowParse.Spec.BCVLI.parse_bcvli", "LowParse.Spec.BCVLI.parse_bounded_bcvli_eq", "LowParse.Slice.bytes_of_slice_from", "LowParse.Spec.BCVLI.parse_bounded_bcvli_kind", "LowParse.Spec.BCVLI.parse_bounded_bcvli", "FStar.Monotonic.HyperStack.mem", "FStar.HyperStack.ST.get", "LowParse.Low.Base.leaf_reader" ]
[]
false
false
false
false
false
let read_bounded_bcvli (min: nat) (max: nat{min <= max}) : Tot (leaf_reader (parse_bounded_bcvli min max)) =
fun #rrel #rel input pos -> let h = HST.get () in [@@ inline_let ]let _ = valid_facts (parse_bounded_bcvli min max) h input pos; parse_bounded_bcvli_eq min max (bytes_of_slice_from h input pos); valid_facts parse_bcvli h input pos in read_bcvli input pos <: bounded_int32 min max
false
FStar.UInt64.fsti
FStar.UInt64.op_Greater_Hat
val op_Greater_Hat : a: FStar.UInt64.t -> b: FStar.UInt64.t -> Prims.bool
let op_Greater_Hat = gt
{ "file_name": "ulib/FStar.UInt64.fsti", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 30, "end_line": 333, "start_col": 7, "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 FStar.UInt64 (**** THIS MODULE IS GENERATED AUTOMATICALLY USING [mk_int.sh], DO NOT EDIT DIRECTLY ****) unfold let n = 64 /// For FStar.UIntN.fstp: anything that you fix/update here should be /// reflected in [FStar.IntN.fstp], which is mostly a copy-paste of /// this module. /// /// Except, as compared to [FStar.IntN.fstp], here: /// - every occurrence of [int_t] has been replaced with [uint_t] /// - every occurrence of [@%] has been replaced with [%]. /// - some functions (e.g., add_underspec, etc.) are only defined here, not on signed integers /// This module provides an abstract type for machine integers of a /// given signedness and width. The interface is designed to be safe /// with respect to arithmetic underflow and overflow. /// Note, we have attempted several times to re-design this module to /// make it more amenable to normalization and to impose less overhead /// on the SMT solver when reasoning about machine integer /// arithmetic. The following github issue reports on the current /// status of that work. /// /// https://github.com/FStarLang/FStar/issues/1757 open FStar.UInt open FStar.Mul #set-options "--max_fuel 0 --max_ifuel 0" (** Abstract type of machine integers, with an underlying representation using a bounded mathematical integer *) new val t : eqtype (** A coercion that projects a bounded mathematical integer from a machine integer *) val v (x:t) : Tot (uint_t n) (** A coercion that injects a bounded mathematical integers into a machine integer *) val uint_to_t (x:uint_t n) : Pure t (requires True) (ensures (fun y -> v y = x)) (** Injection/projection inverse *) val uv_inv (x : t) : Lemma (ensures (uint_to_t (v x) == x)) [SMTPat (v x)] (** Projection/injection inverse *) val vu_inv (x : uint_t n) : Lemma (ensures (v (uint_to_t x) == x)) [SMTPat (uint_to_t x)] (** An alternate form of the injectivity of the [v] projection *) val v_inj (x1 x2: t): Lemma (requires (v x1 == v x2)) (ensures (x1 == x2)) (** Constants 0 and 1 *) val zero : x:t{v x = 0} val one : x:t{v x = 1} (**** Addition primitives *) (** Bounds-respecting addition The precondition enforces that the sum does not overflow, expressing the bound as an addition on mathematical integers *) val add (a:t) (b:t) : Pure t (requires (size (v a + v b) n)) (ensures (fun c -> v a + v b = v c)) (** Underspecified, possibly overflowing addition: The postcondition only enures that the result is the sum of the arguments in case there is no overflow *) val add_underspec (a:t) (b:t) : Pure t (requires True) (ensures (fun c -> size (v a + v b) n ==> v a + v b = v c)) (** Addition modulo [2^n] Machine integers can always be added, but the postcondition is now in terms of addition modulo [2^n] on mathematical integers *) val add_mod (a:t) (b:t) : Pure t (requires True) (ensures (fun c -> FStar.UInt.add_mod (v a) (v b) = v c)) (**** Subtraction primitives *) (** Bounds-respecting subtraction The precondition enforces that the difference does not underflow, expressing the bound as a difference on mathematical integers *) val sub (a:t) (b:t) : Pure t (requires (size (v a - v b) n)) (ensures (fun c -> v a - v b = v c)) (** Underspecified, possibly overflowing subtraction: The postcondition only enures that the result is the difference of the arguments in case there is no underflow *) val sub_underspec (a:t) (b:t) : Pure t (requires True) (ensures (fun c -> size (v a - v b) n ==> v a - v b = v c)) (** Subtraction modulo [2^n] Machine integers can always be subtractd, but the postcondition is now in terms of subtraction modulo [2^n] on mathematical integers *) val sub_mod (a:t) (b:t) : Pure t (requires True) (ensures (fun c -> FStar.UInt.sub_mod (v a) (v b) = v c)) (**** Multiplication primitives *) (** Bounds-respecting multiplication The precondition enforces that the product does not overflow, expressing the bound as a product on mathematical integers *) val mul (a:t) (b:t) : Pure t (requires (size (v a * v b) n)) (ensures (fun c -> v a * v b = v c)) (** Underspecified, possibly overflowing product The postcondition only enures that the result is the product of the arguments in case there is no overflow *) val mul_underspec (a:t) (b:t) : Pure t (requires True) (ensures (fun c -> size (v a * v b) n ==> v a * v b = v c)) (** Multiplication modulo [2^n] Machine integers can always be multiplied, but the postcondition is now in terms of product modulo [2^n] on mathematical integers *) val mul_mod (a:t) (b:t) : Pure t (requires True) (ensures (fun c -> FStar.UInt.mul_mod (v a) (v b) = v c)) (**** Division primitives *) (** Euclidean division of [a] and [b], with [b] non-zero *) val div (a:t) (b:t{v b <> 0}) : Pure t (requires (True)) (ensures (fun c -> v a / v b = v c)) (**** Modulo primitives *) (** Euclidean remainder The result is the modulus of [a] with respect to a non-zero [b] *) val rem (a:t) (b:t{v b <> 0}) : Pure t (requires True) (ensures (fun c -> FStar.UInt.mod (v a) (v b) = v c)) (**** Bitwise operators *) /// Also see FStar.BV (** Bitwise logical conjunction *) val logand (x:t) (y:t) : Pure t (requires True) (ensures (fun z -> v x `logand` v y = v z)) (** Bitwise logical exclusive-or *) val logxor (x:t) (y:t) : Pure t (requires True) (ensures (fun z -> v x `logxor` v y == v z)) (** Bitwise logical disjunction *) val logor (x:t) (y:t) : Pure t (requires True) (ensures (fun z -> v x `logor` v y == v z)) (** Bitwise logical negation *) val lognot (x:t) : Pure t (requires True) (ensures (fun z -> lognot (v x) == v z)) (**** Shift operators *) (** Shift right with zero fill, shifting at most the integer width *) val shift_right (a:t) (s:UInt32.t) : Pure t (requires (UInt32.v s < n)) (ensures (fun c -> FStar.UInt.shift_right (v a) (UInt32.v s) = v c)) (** Shift left with zero fill, shifting at most the integer width *) val shift_left (a:t) (s:UInt32.t) : Pure t (requires (UInt32.v s < n)) (ensures (fun c -> FStar.UInt.shift_left (v a) (UInt32.v s) = v c)) (**** Comparison operators *) (** Equality Note, it is safe to also use the polymorphic decidable equality operator [=] *) let eq (a:t) (b:t) : Tot bool = eq #n (v a) (v b) (** Greater than *) let gt (a:t) (b:t) : Tot bool = gt #n (v a) (v b) (** Greater than or equal *) let gte (a:t) (b:t) : Tot bool = gte #n (v a) (v b) (** Less than *) let lt (a:t) (b:t) : Tot bool = lt #n (v a) (v b) (** Less than or equal *) let lte (a:t) (b:t) : Tot bool = lte #n (v a) (v b) (** Unary negation *) inline_for_extraction let minus (a:t) = add_mod (lognot a) (uint_to_t 1) (** The maximum shift value for this type, i.e. its width minus one, as an UInt32. *) inline_for_extraction let n_minus_one = UInt32.uint_to_t (n - 1) #set-options "--z3rlimit 80 --initial_fuel 1 --max_fuel 1" (** A constant-time way to compute the equality of two machine integers. With inspiration from https://git.zx2c4.com/WireGuard/commit/src/crypto/curve25519-hacl64.h?id=2e60bb395c1f589a398ec606d611132ef9ef764b Note, the branching on [a=b] is just for proof-purposes. *) [@ CNoInline ] let eq_mask (a:t) (b:t) : Pure t (requires True) (ensures (fun c -> (v a = v b ==> v c = pow2 n - 1) /\ (v a <> v b ==> v c = 0))) = let x = logxor a b in let minus_x = minus x in let x_or_minus_x = logor x minus_x in let xnx = shift_right x_or_minus_x n_minus_one in let c = sub_mod xnx (uint_to_t 1) in if a = b then begin logxor_self (v a); lognot_lemma_1 #n; logor_lemma_1 (v x); assert (v x = 0 /\ v minus_x = 0 /\ v x_or_minus_x = 0 /\ v xnx = 0); assert (v c = ones n) end else begin logxor_neq_nonzero (v a) (v b); lemma_msb_pow2 #n (v (lognot x)); lemma_msb_pow2 #n (v minus_x); lemma_minus_zero #n (v x); assert (v c = FStar.UInt.zero n) end; c private val lemma_sub_msbs (a:t) (b:t) : Lemma ((msb (v a) = msb (v b)) ==> (v a < v b <==> msb (v (sub_mod a b)))) (** A constant-time way to compute the [>=] inequality of two machine integers. With inspiration from https://git.zx2c4.com/WireGuard/commit/src/crypto/curve25519-hacl64.h?id=0a483a9b431d87eca1b275463c632f8d5551978a *) [@ CNoInline ] let gte_mask (a:t) (b:t) : Pure t (requires True) (ensures (fun c -> (v a >= v b ==> v c = pow2 n - 1) /\ (v a < v b ==> v c = 0))) = let x = a in let y = b in let x_xor_y = logxor x y in let x_sub_y = sub_mod x y in let x_sub_y_xor_y = logxor x_sub_y y in let q = logor x_xor_y x_sub_y_xor_y in let x_xor_q = logxor x q in let x_xor_q_ = shift_right x_xor_q n_minus_one in let c = sub_mod x_xor_q_ (uint_to_t 1) in lemma_sub_msbs x y; lemma_msb_gte (v x) (v y); lemma_msb_gte (v y) (v x); c #reset-options (*** Infix notations *) unfold let op_Plus_Hat = add unfold let op_Plus_Question_Hat = add_underspec unfold let op_Plus_Percent_Hat = add_mod unfold let op_Subtraction_Hat = sub unfold let op_Subtraction_Question_Hat = sub_underspec unfold let op_Subtraction_Percent_Hat = sub_mod unfold let op_Star_Hat = mul unfold let op_Star_Question_Hat = mul_underspec unfold let op_Star_Percent_Hat = mul_mod unfold let op_Slash_Hat = div unfold let op_Percent_Hat = rem unfold let op_Hat_Hat = logxor unfold let op_Amp_Hat = logand unfold let op_Bar_Hat = logor unfold let op_Less_Less_Hat = shift_left unfold let op_Greater_Greater_Hat = shift_right
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.UInt32.fsti.checked", "FStar.UInt.fsti.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked" ], "interface_file": false, "source_file": "FStar.UInt64.fsti" }
[ { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.UInt", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.UInt", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "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: FStar.UInt64.t -> b: FStar.UInt64.t -> Prims.bool
Prims.Tot
[ "total" ]
[]
[ "FStar.UInt64.gt" ]
[]
false
false
false
true
false
let op_Greater_Hat =
gt
false
MerkleTree.New.High.Correct.Rhs.fst
MerkleTree.New.High.Correct.Rhs.construct_rhs_inv_ok
val construct_rhs_inv_ok: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> lv:nat{lv <= 32} -> i:nat -> j:nat{j > 0 /\ i <= j /\ j < pow2 (32 - lv)} -> olds:hashess #hsz {S.length olds = 32 /\ mt_olds_inv #hsz lv i olds} -> hs:hashess #hsz {S.length hs = 32 /\ hs_wf_elts lv hs i j} -> rhs:hashes #hsz {S.length rhs = 32} -> acc:hash #hsz -> actd:bool -> Lemma (requires (mt_olds_hs_lth_inv_ok #_ #f lv i j olds hs; mt_hashes_inv #_ #f lv j (merge_hs #_ #f olds hs))) (ensures (log2c_bound j (32 - lv); mt_olds_hs_lth_inv_ok #_ #f lv i j olds hs; (let crhs = construct_rhs #_ #f lv hs rhs i j acc actd in mt_rhs_inv #_ #f j (hash_seq_spec_full #_ #f (S.index (merge_hs #_ #f olds hs) lv) acc actd) (S.slice (fst crhs) lv (lv + log2c j)) actd /\ MTS.mt_get_root #_ #f #(log2c j) (hash_seq_spec_full #_ #f (S.index (merge_hs #_ #f olds hs) lv) acc actd) == MTS.HRaw (snd crhs))))
val construct_rhs_inv_ok: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> lv:nat{lv <= 32} -> i:nat -> j:nat{j > 0 /\ i <= j /\ j < pow2 (32 - lv)} -> olds:hashess #hsz {S.length olds = 32 /\ mt_olds_inv #hsz lv i olds} -> hs:hashess #hsz {S.length hs = 32 /\ hs_wf_elts lv hs i j} -> rhs:hashes #hsz {S.length rhs = 32} -> acc:hash #hsz -> actd:bool -> Lemma (requires (mt_olds_hs_lth_inv_ok #_ #f lv i j olds hs; mt_hashes_inv #_ #f lv j (merge_hs #_ #f olds hs))) (ensures (log2c_bound j (32 - lv); mt_olds_hs_lth_inv_ok #_ #f lv i j olds hs; (let crhs = construct_rhs #_ #f lv hs rhs i j acc actd in mt_rhs_inv #_ #f j (hash_seq_spec_full #_ #f (S.index (merge_hs #_ #f olds hs) lv) acc actd) (S.slice (fst crhs) lv (lv + log2c j)) actd /\ MTS.mt_get_root #_ #f #(log2c j) (hash_seq_spec_full #_ #f (S.index (merge_hs #_ #f olds hs) lv) acc actd) == MTS.HRaw (snd crhs))))
let construct_rhs_inv_ok #hsz #f lv i j olds hs rhs acc actd = log2c_div j; log2c_bound j (32 - lv); mt_olds_hs_lth_inv_ok #_ #f lv i j olds hs; mt_hashes_lth_inv_log_converted_ #_ #f lv j (merge_hs #_ #f olds hs); mt_hashes_inv_log_converted_ #_ #f lv j (merge_hs #_ #f olds hs); let crhs = construct_rhs #_ #f lv hs rhs i j acc actd in let crhsf = construct_rhs_acc #_ #f j (S.slice (merge_hs #_ #f olds hs) lv (lv + log2c j)) acc actd in construct_rhs_acc_consistent #_ #f lv i j olds hs rhs acc actd; construct_rhs_acc_inv_ok #_ #f j (S.slice (merge_hs #_ #f olds hs) lv (lv + log2c j)) acc actd; rhs_equiv_inv_preserved #_ #f j (hash_seq_spec_full #_ #f (S.index (merge_hs #_ #f olds hs) lv) acc actd) (fst crhsf) (S.slice (fst crhs) lv (lv + log2c j)) actd
{ "file_name": "src/MerkleTree.New.High.Correct.Rhs.fst", "git_rev": "7d7bdc20f2033171e279c176b26e84f9069d23c6", "git_url": "https://github.com/hacl-star/merkle-tree.git", "project_name": "merkle-tree" }
{ "end_col": 59, "end_line": 351, "start_col": 0, "start_line": 338 }
module MerkleTree.New.High.Correct.Rhs open FStar.Classical open FStar.Ghost open FStar.Seq module S = FStar.Seq module MTS = MerkleTree.Spec open MerkleTree.New.High open MerkleTree.New.High.Correct.Base #set-options "--z3rlimit 10 --initial_fuel 1 --max_fuel 1 --initial_ifuel 0 --max_ifuel 0" /// Correctness of rightmost hashes // Another version of `construct_rhs` that recursively // accumulates rightmost hashes. val construct_rhs_acc: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> j:nat -> fhs:hashess #hsz { S.length fhs = log2c j /\ mt_hashes_lth_inv_log #hsz j fhs} -> acc:hash #hsz -> actd:bool -> GTot (rhs:hashes #hsz {S.length rhs = log2c j} * hash #hsz) (decreases j) let rec construct_rhs_acc #_ #f j fhs acc actd = if j = 0 then (S.empty, acc) else begin if j % 2 = 0 then (let nrhsh = construct_rhs_acc #_ #f(j / 2) (S.tail fhs) acc actd in (S.cons hash_init (fst nrhsh), snd nrhsh)) else (let rhd = if actd then acc else hash_init in let nacc = if actd then f (S.last (S.head fhs)) acc else S.last (S.head fhs) in let nrhsh = construct_rhs_acc #_ #f (j / 2) (S.tail fhs) nacc true in (S.cons rhd (fst nrhsh), snd nrhsh)) end #push-options "--initial_ifuel 1 --max_ifuel 1" val construct_rhs_acc_odd: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> j:nat -> fhs:hashess #hsz { S.length fhs = log2c j /\ mt_hashes_lth_inv_log #hsz j fhs} -> acc:hash #hsz -> actd:bool -> Lemma (requires (j % 2 <> 0)) (ensures (let rrf = construct_rhs_acc #_ #f j fhs acc actd in let nacc = if actd then f (S.last (S.head fhs)) acc else S.last (S.head fhs) in let nrrf = construct_rhs_acc #_ #f (j / 2) (S.tail fhs) nacc true in S.equal (S.tail (fst rrf)) (fst nrrf) /\ snd rrf == snd nrrf)) let construct_rhs_acc_odd #_ #f j fhs acc actd = () #pop-options #push-options "--initial_fuel 2 --max_fuel 2" val construct_rhs_acc_inv_ok_0: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> fhs:hashess #hsz { S.length fhs = 1 /\ mt_hashes_lth_inv_log #hsz 1 fhs /\ mt_hashes_inv_log #_ #f 1 fhs} -> acc:hash #hsz -> actd:bool -> Lemma (requires True) (ensures (let crhs = construct_rhs_acc #_ #f 1 fhs acc actd in mt_rhs_inv #_ #f 1 (hash_seq_spec_full #_ #f (S.head fhs) acc actd) (fst crhs) actd /\ MTS.mt_get_root #_ #f #1 (hash_seq_spec_full #_ #f (S.head fhs) acc actd) == MTS.HRaw #hsz (snd crhs))) let construct_rhs_acc_inv_ok_0 #_ #f fhs acc actd = () #pop-options #push-options "--z3rlimit 300" #restart-solver val construct_rhs_acc_inv_ok: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> j:nat{j > 0} -> fhs:hashess #hsz { S.length fhs = log2c j /\ mt_hashes_lth_inv_log #hsz j fhs /\ mt_hashes_inv_log #_ #f j fhs} -> acc:hash #hsz -> actd:bool -> Lemma (requires True) (ensures (let crhs = construct_rhs_acc #_ #f j fhs acc actd in mt_rhs_inv #_ #f j (hash_seq_spec_full #_ #f (S.head fhs) acc actd) (fst crhs) actd /\ MTS.mt_get_root #_ #f #(log2c j) (hash_seq_spec_full #_ #f (S.head fhs) acc actd) == MTS.HRaw (snd crhs))) (decreases j) let rec construct_rhs_acc_inv_ok #hsz #f j fhs acc actd = if j = 1 then construct_rhs_acc_inv_ok_0 #_ #f fhs acc actd else if j % 2 = 0 then begin construct_rhs_acc_inv_ok #_ #f (j / 2) (S.tail fhs) acc actd; let rcrhs = construct_rhs_acc #_ #f (j / 2) (S.tail fhs) acc actd in assert (mt_rhs_inv #_ #f (j / 2) (hash_seq_spec_full #_ #f (S.head (S.tail fhs)) acc actd) (fst rcrhs) actd); assert (MTS.mt_get_root #_ #f #(log2c j - 1) (hash_seq_spec_full #_ #f (S.head (S.tail fhs)) acc actd) == MTS.HRaw (snd rcrhs)); let crhs = (S.cons hash_init (fst rcrhs), snd rcrhs) in mt_hashes_lth_inv_log_next #_ #f j fhs; hash_seq_spec_full_even_next #_ #f j (S.head fhs) (S.head (S.tail fhs)) acc actd; assert (mt_rhs_inv #_ #f (j / 2) (MTS.mt_next_lv #_ #f #(log2c j) (hash_seq_spec_full #_ #f (S.head fhs) acc actd)) (fst rcrhs) actd); assert (mt_rhs_inv #_ #f j (hash_seq_spec_full #_ #f (S.head fhs) acc actd) (fst crhs) actd); assert (MTS.mt_get_root #_ #f #(log2c j) (hash_seq_spec_full #_ #f (S.head fhs) acc actd) == MTS.HRaw (snd rcrhs)) end else begin let rhd = if actd then acc else hash_init #hsz in let nacc = if actd then f (S.last (S.head fhs)) acc else S.last (S.head fhs) in construct_rhs_acc_inv_ok #_ #f (j / 2) (S.tail fhs) nacc true; let rcrhs = construct_rhs_acc #_ #f (j / 2) (S.tail fhs) nacc true in assert (mt_rhs_inv #_ #f (j / 2) (hash_seq_spec_full #_ #f (S.head (S.tail fhs)) nacc true) (fst rcrhs) true); assert (MTS.mt_get_root #_ #f #(log2c j - 1) (hash_seq_spec_full #_ #f (S.head (S.tail fhs)) nacc true) == MTS.HRaw (snd rcrhs)); let crhs = (S.cons rhd (fst rcrhs), snd rcrhs) in mt_hashes_lth_inv_log_next #_ #f j fhs; hash_seq_spec_full_odd_next #_ #f j (S.head fhs) (S.head (S.tail fhs)) acc actd nacc; (if actd then hash_seq_spec_full_case_true #_ #f (S.head fhs) acc); assert (if actd then (S.index (hash_seq_spec_full #_ #f (S.head fhs) acc actd) j == MTS.HRaw rhd) else true); assert (mt_rhs_inv #_ #f (j / 2) (MTS.mt_next_lv #_ #f #(log2c j) (hash_seq_spec_full #_ #f (S.head fhs) acc actd)) (fst rcrhs) true); assert (mt_rhs_inv #_ #f j (hash_seq_spec_full #_ #f (S.head fhs) acc actd) (fst crhs) actd); assert (MTS.mt_get_root #_ #f #(log2c j) (hash_seq_spec_full #_ #f (S.head fhs) acc actd) == MTS.HRaw (snd crhs)) end #pop-options val rhs_equiv: #hsz:pos -> j:nat -> rhs1:hashes #hsz {S.length rhs1 = log2c j} -> rhs2:hashes #hsz {S.length rhs2 = log2c j} -> actd:bool -> GTot Type0 (decreases j) let rec rhs_equiv #hsz j rhs1 rhs2 actd = if j = 0 then true else if j % 2 = 0 then rhs_equiv #hsz (j / 2) (S.tail rhs1) (S.tail rhs2) actd else ((if actd then S.head rhs1 == S.head rhs2 else true) /\ rhs_equiv #hsz (j / 2) (S.tail rhs1) (S.tail rhs2) true) val rhs_equiv_inv_preserved: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> j:nat -> smt:MTS.merkle_tree (log2c j) -> rhs1:hashes #hsz {S.length rhs1 = log2c j} -> rhs2:hashes #hsz {S.length rhs2 = log2c j} -> actd:bool -> Lemma (requires (mt_rhs_inv #_ #f j smt rhs1 actd /\ rhs_equiv #hsz j rhs1 rhs2 actd)) (ensures (mt_rhs_inv #_ #f j smt rhs2 actd)) (decreases j) let rec rhs_equiv_inv_preserved #_ #f j smt rhs1 rhs2 actd = if j = 0 then () else if j % 2 = 0 then rhs_equiv_inv_preserved #_ #f (j / 2) (MTS.mt_next_lv #_ #f #(log2c j) smt) (S.tail rhs1) (S.tail rhs2) actd else begin (if actd then (assert (S.index smt j == MTS.HRaw (S.head rhs1)); assert (S.head rhs1 == S.head rhs2)) else ()); rhs_equiv_inv_preserved #_ #f (j / 2) (MTS.mt_next_lv #_ #f #(log2c j) smt) (S.tail rhs1) (S.tail rhs2) true end val construct_rhs_acc_consistent: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> lv:nat{lv <= 32} -> i:nat -> j:nat{i <= j /\ j < pow2 (32 - lv)} -> olds:hashess #hsz {S.length olds = 32 /\ mt_olds_inv #hsz lv i olds} -> hs:hashess #hsz {S.length hs = 32 /\ hs_wf_elts lv hs i j} -> rhs:hashes #hsz {S.length rhs = 32} -> acc:hash #hsz -> actd:bool -> Lemma (requires True) (ensures (log2c_bound j (32 - lv); mt_olds_hs_lth_inv_ok #_ #f lv i j olds hs; mt_hashes_lth_inv_log_converted_ #_ #f lv j (merge_hs #_ #f olds hs); (let rrf = construct_rhs_acc #_ #f j (S.slice (merge_hs #_ #f olds hs) lv (lv + log2c j)) acc actd in let rr = construct_rhs #_ #f lv hs rhs i j acc actd in rhs_equiv #hsz j (fst rrf) (S.slice (fst rr) lv (lv + log2c j)) actd /\ snd rrf == snd rr))) (decreases j) #push-options "--z3rlimit 300 --ifuel 1" #push-options "--retry 3" let rec construct_rhs_acc_consistent #hsz #f lv i j olds hs rhs acc actd = assert (j < pow2 (32 - lv)); assert (j <> 0 ==> j / 2 < pow2 (32 - (lv + 1))); log2c_bound j (32 - lv); mt_olds_hs_lth_inv_ok #_ #f lv i j olds hs; mt_hashes_lth_inv_log_converted_ #_ #f lv j (merge_hs #_ #f olds hs); let rrf = construct_rhs_acc #_ #f j (S.slice (merge_hs #_ #f olds hs) lv (lv + log2c j)) acc actd in let rr = construct_rhs #_ #f lv hs rhs i j acc actd in construct_rhs_unchanged #_ #f lv hs rhs i j acc actd; assert (S.equal (S.slice rhs 0 lv) (S.slice (fst rr) 0 lv)); if j = 0 then () else begin log2c_div j; assert (32 - (lv + 1) >= 0); log2c_bound (j / 2) (32 - (lv + 1)); mt_olds_hs_lth_inv_ok #_ #f (lv + 1) (i / 2) (j / 2) olds hs; mt_hashes_lth_inv_log_converted_ #_ #f (lv + 1) (j / 2) (merge_hs #_ #f olds hs); if j % 2 = 0 then begin construct_rhs_acc_consistent #_ #f (lv + 1) (i / 2) (j / 2) olds hs rhs acc actd; log2c_bound (j/2) (32 - (lv + 1)); mt_olds_hs_lth_inv_ok #hsz #f (lv+1) (i/2) (j/2) olds hs; mt_hashes_lth_inv_log_converted_ #_ #f lv j (merge_hs #_ #f olds hs); let rrf = construct_rhs_acc #_ #f j (S.slice (merge_hs #_ #f olds hs) lv (lv + log2c j)) acc actd in let rr = construct_rhs #_ #f lv hs rhs i j acc actd in assert (rhs_equiv #hsz j (fst rrf) (S.slice (fst rr) lv (lv + log2c j)) actd); assert (snd rrf == snd rr) end else begin let rhd = if actd then acc else hash_init in let nacc = if actd then f (S.last (S.index hs lv)) acc else S.last (S.index hs lv) in assert (S.equal (S.tail (S.slice (merge_hs #_ #f olds hs) lv (lv + log2c j))) (S.slice (merge_hs #_ #f olds hs) (lv + 1) (lv + 1 + log2c (j / 2)))); // Recursion step for `construct_rhs_acc` let nrrf = construct_rhs_acc #_ #f (j / 2) (S.slice (merge_hs #_ #f olds hs) (lv + 1) (lv + 1 + (log2c (j / 2)))) nacc true in construct_rhs_acc_odd #_ #f j (S.slice (merge_hs #_ #f olds hs) lv (lv + log2c j)) acc actd; // Recursion step for `construct_rhs` assert (hs_wf_elts (lv + 1) hs (i / 2) (j / 2)); let nrhs = if actd then S.upd rhs lv acc else rhs in let nrr = construct_rhs #_ #f (lv + 1) hs nrhs (i / 2) (j / 2) nacc true in construct_rhs_odd #_ #f lv hs rhs i j acc actd; construct_rhs_unchanged #_ #f (lv + 1) hs nrhs (i / 2) (j / 2) nacc true; assert (S.equal (S.slice nrhs 0 (lv + 1)) (S.slice (fst nrr) 0 (lv + 1))); assert (S.index (fst nrr) lv == S.index nrhs lv); // Recursion for the proof construct_rhs_acc_consistent #_ #f (lv + 1) (i / 2) (j / 2) olds hs nrhs nacc true; assert (rhs_equiv #hsz (j / 2) (fst nrrf) (S.slice (fst nrr) (lv + 1) (lv + 1 + log2c (j / 2))) true); assert (snd nrrf == snd nrr); // All together (if actd then (assert (S.head (fst rrf) == rhd); assert (rhd == acc); assert (S.index (fst rr) lv == S.index nrhs lv); assert (S.index nrhs lv == acc); assert (S.head (fst rrf) == S.index (fst rr) lv)) else ()); assert (if actd then S.head (fst rrf) == S.index (fst rr) lv else true); assert (rhs_equiv #hsz (j / 2) (S.tail (fst rrf)) (S.slice (fst rr) (lv + 1) (lv + 1 + log2c (j / 2))) true); assert (rhs_equiv #hsz j (fst rrf) (S.slice (fst rr) lv (lv + log2c j)) actd); assert (snd rrf == snd rr) end end #pop-options val construct_rhs_inv_ok: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> lv:nat{lv <= 32} -> i:nat -> j:nat{j > 0 /\ i <= j /\ j < pow2 (32 - lv)} -> olds:hashess #hsz {S.length olds = 32 /\ mt_olds_inv #hsz lv i olds} -> hs:hashess #hsz {S.length hs = 32 /\ hs_wf_elts lv hs i j} -> rhs:hashes #hsz {S.length rhs = 32} -> acc:hash #hsz -> actd:bool -> Lemma (requires (mt_olds_hs_lth_inv_ok #_ #f lv i j olds hs; mt_hashes_inv #_ #f lv j (merge_hs #_ #f olds hs))) (ensures (log2c_bound j (32 - lv); mt_olds_hs_lth_inv_ok #_ #f lv i j olds hs; (let crhs = construct_rhs #_ #f lv hs rhs i j acc actd in mt_rhs_inv #_ #f j (hash_seq_spec_full #_ #f (S.index (merge_hs #_ #f olds hs) lv) acc actd) (S.slice (fst crhs) lv (lv + log2c j)) actd /\ MTS.mt_get_root #_ #f #(log2c j) (hash_seq_spec_full #_ #f (S.index (merge_hs #_ #f olds hs) lv) acc actd) ==
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "MerkleTree.Spec.fst.checked", "MerkleTree.New.High.Correct.Base.fst.checked", "MerkleTree.New.High.fst.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Ghost.fsti.checked", "FStar.Classical.fsti.checked" ], "interface_file": false, "source_file": "MerkleTree.New.High.Correct.Rhs.fst" }
[ { "abbrev": false, "full_module": "MerkleTree.New.High.Correct.Base", "short_module": null }, { "abbrev": false, "full_module": "MerkleTree.New.High", "short_module": null }, { "abbrev": true, "full_module": "MerkleTree.Spec", "short_module": "MTS" }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "S" }, { "abbrev": false, "full_module": "FStar.Seq", "short_module": null }, { "abbrev": false, "full_module": "FStar.Ghost", "short_module": null }, { "abbrev": false, "full_module": "FStar.Classical", "short_module": null }, { "abbrev": false, "full_module": "MerkleTree.New.High.Correct", "short_module": null }, { "abbrev": false, "full_module": "MerkleTree.New.High.Correct", "short_module": null }, { "abbrev": 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": 1, "initial_ifuel": 1, "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": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 300, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
lv: Prims.nat{lv <= 32} -> i: Prims.nat -> j: Prims.nat{j > 0 /\ i <= j /\ j < Prims.pow2 (32 - lv)} -> olds: MerkleTree.New.High.hashess {FStar.Seq.Base.length olds = 32 /\ MerkleTree.New.High.Correct.Base.mt_olds_inv lv i olds} -> hs: MerkleTree.New.High.hashess {FStar.Seq.Base.length hs = 32 /\ MerkleTree.New.High.hs_wf_elts lv hs i j} -> rhs: MerkleTree.New.High.hashes{FStar.Seq.Base.length rhs = 32} -> acc: MerkleTree.New.High.hash -> actd: Prims.bool -> FStar.Pervasives.Lemma (requires (MerkleTree.New.High.Correct.Base.mt_olds_hs_lth_inv_ok lv i j olds hs; MerkleTree.New.High.Correct.Base.mt_hashes_inv lv j (MerkleTree.New.High.Correct.Base.merge_hs olds hs))) (ensures (MerkleTree.New.High.Correct.Base.log2c_bound j (32 - lv); MerkleTree.New.High.Correct.Base.mt_olds_hs_lth_inv_ok lv i j olds hs; let crhs = MerkleTree.New.High.construct_rhs lv hs rhs i j acc actd in MerkleTree.New.High.Correct.Base.mt_rhs_inv j (MerkleTree.New.High.Correct.Base.hash_seq_spec_full (FStar.Seq.Base.index (MerkleTree.New.High.Correct.Base.merge_hs olds hs) lv) acc actd) (FStar.Seq.Base.slice (FStar.Pervasives.Native.fst crhs) lv (lv + MerkleTree.New.High.Correct.Base.log2c j)) actd /\ MerkleTree.Spec.mt_get_root (MerkleTree.New.High.Correct.Base.hash_seq_spec_full (FStar.Seq.Base.index (MerkleTree.New.High.Correct.Base.merge_hs olds hs) lv) acc actd) == MerkleTree.Spec.HRaw (FStar.Pervasives.Native.snd crhs)))
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "Prims.pos", "MerkleTree.Spec.hash_fun_t", "Prims.nat", "Prims.b2t", "Prims.op_LessThanOrEqual", "Prims.l_and", "Prims.op_GreaterThan", "Prims.op_LessThan", "Prims.pow2", "Prims.op_Subtraction", "MerkleTree.New.High.hashess", "Prims.op_Equality", "Prims.int", "FStar.Seq.Base.length", "MerkleTree.New.High.hashes", "MerkleTree.New.High.Correct.Base.mt_olds_inv", "MerkleTree.New.High.hs_wf_elts", "MerkleTree.New.High.hash", "Prims.bool", "MerkleTree.New.High.Correct.Rhs.rhs_equiv_inv_preserved", "MerkleTree.New.High.Correct.Base.hash_seq_spec_full", "FStar.Seq.Base.index", "MerkleTree.New.High.Correct.Base.merge_hs", "FStar.Pervasives.Native.fst", "MerkleTree.New.High.Correct.Base.log2c", "FStar.Seq.Base.slice", "Prims.op_Addition", "Prims.unit", "MerkleTree.New.High.Correct.Rhs.construct_rhs_acc_inv_ok", "MerkleTree.New.High.Correct.Rhs.construct_rhs_acc_consistent", "FStar.Pervasives.Native.tuple2", "MerkleTree.New.High.Correct.Rhs.construct_rhs_acc", "MerkleTree.New.High.construct_rhs", "MerkleTree.New.High.Correct.Base.mt_hashes_inv_log_converted_", "MerkleTree.New.High.Correct.Base.mt_hashes_lth_inv_log_converted_", "MerkleTree.New.High.Correct.Base.mt_olds_hs_lth_inv_ok", "MerkleTree.New.High.Correct.Base.log2c_bound", "MerkleTree.New.High.Correct.Base.log2c_div" ]
[]
true
false
true
false
false
let construct_rhs_inv_ok #hsz #f lv i j olds hs rhs acc actd =
log2c_div j; log2c_bound j (32 - lv); mt_olds_hs_lth_inv_ok #_ #f lv i j olds hs; mt_hashes_lth_inv_log_converted_ #_ #f lv j (merge_hs #_ #f olds hs); mt_hashes_inv_log_converted_ #_ #f lv j (merge_hs #_ #f olds hs); let crhs = construct_rhs #_ #f lv hs rhs i j acc actd in let crhsf = construct_rhs_acc #_ #f j (S.slice (merge_hs #_ #f olds hs) lv (lv + log2c j)) acc actd in construct_rhs_acc_consistent #_ #f lv i j olds hs rhs acc actd; construct_rhs_acc_inv_ok #_ #f j (S.slice (merge_hs #_ #f olds hs) lv (lv + log2c j)) acc actd; rhs_equiv_inv_preserved #_ #f j (hash_seq_spec_full #_ #f (S.index (merge_hs #_ #f olds hs) lv) acc actd) (fst crhsf) (S.slice (fst crhs) lv (lv + log2c j)) actd
false
MerkleTree.Low.Datastructures.fst
MerkleTree.Low.Datastructures.hash_r_repr
val hash_r_repr: #hsz:hash_size_t -> h:HS.mem -> v:hash{hash_r_inv #hsz h v} -> GTot (hash_repr #hsz)
val hash_r_repr: #hsz:hash_size_t -> h:HS.mem -> v:hash{hash_r_inv #hsz h v} -> GTot (hash_repr #hsz)
let hash_r_repr #_ h v = B.as_seq h v
{ "file_name": "src/MerkleTree.Low.Datastructures.fst", "git_rev": "7d7bdc20f2033171e279c176b26e84f9069d23c6", "git_url": "https://github.com/hacl-star/merkle-tree.git", "project_name": "merkle-tree" }
{ "end_col": 37, "end_line": 82, "start_col": 0, "start_line": 82 }
module MerkleTree.Low.Datastructures open FStar.All open FStar.Integers open FStar.Mul open LowStar.Buffer open LowStar.BufferOps open LowStar.Vector open LowStar.Regional open LowStar.RVector open LowStar.Regional.Instances module HS = FStar.HyperStack module HST = FStar.HyperStack.ST module MHS = FStar.Monotonic.HyperStack module HH = FStar.Monotonic.HyperHeap module B = LowStar.Buffer module CB = LowStar.ConstBuffer module V = LowStar.Vector module RV = LowStar.RVector module RVI = LowStar.Regional.Instances module S = FStar.Seq module EHS = EverCrypt.Hash module U32 = FStar.UInt32 module MTH = MerkleTree.New.High open EverCrypt.Helpers open Lib.IntTypes #set-options "--z3rlimit 10 --initial_fuel 0 --max_fuel 0 --initial_ifuel 0 --max_ifuel 0" type hash_size_t = n:uint32_t{n > 0ul} type hash (#hsz:hash_size_t) = b:B.buffer uint8 { B.len b = hsz \/ B.g_is_null b } // We cannot use `Low.RVector.Instances`, where we have some general // typeclass instances of `regional`, e.g., if `rg:regional a` then // `regional (rvector rg)`. In FStar we can use this, but KaRaMeL currently // cannot deal with this and gives a number of errors. // So we temporarily instantiate some `regional`s manually below, which is // extractable to C by KaRaMeL. /// Some instantiations of `regional` used in Merkle tree /// 1. `hash` is regional private noextract val hash_region_of: #hsz:hash_size_t -> v:hash #hsz -> GTot HH.rid let hash_region_of #_ v = B.frameOf v private inline_for_extraction val hash_dummy: #hsz:Ghost.erased hash_size_t -> Tot (hash #hsz) let hash_dummy #_ = B.null private noextract val hash_r_inv: #hsz:hash_size_t -> h:HS.mem -> v:hash #hsz -> GTot Type0 let hash_r_inv #hsz h v = B.live h v /\ B.freeable v /\ B.len v = hsz private noextract val hash_r_inv_reg: #hsz:hash_size_t -> h:HS.mem -> v:hash -> Lemma (requires hash_r_inv h v) (ensures MHS.live_region h (hash_region_of #hsz v)) let hash_r_inv_reg #_ h v = () private noextract val hash_repr (#hsz:hash_size_t): Type0 let hash_repr #hsz = MTH.hash #(U32.v hsz) private noextract
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "MerkleTree.New.High.fst.checked", "LowStar.Vector.fst.checked", "LowStar.RVector.fst.checked", "LowStar.Regional.Instances.fst.checked", "LowStar.Regional.fst.checked", "LowStar.ConstBuffer.fsti.checked", "LowStar.BufferOps.fst.checked", "LowStar.Buffer.fst.checked", "Lib.IntTypes.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Set.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Monotonic.HyperStack.fsti.checked", "FStar.Monotonic.HyperHeap.fsti.checked", "FStar.Map.fsti.checked", "FStar.Integers.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked", "FStar.All.fst.checked", "EverCrypt.Helpers.fsti.checked", "EverCrypt.Hash.fsti.checked" ], "interface_file": false, "source_file": "MerkleTree.Low.Datastructures.fst" }
[ { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "EverCrypt.Helpers", "short_module": null }, { "abbrev": true, "full_module": "MerkleTree.New.High", "short_module": "MTH" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": true, "full_module": "EverCrypt.Hash", "short_module": "EHS" }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "S" }, { "abbrev": true, "full_module": "LowStar.Regional.Instances", "short_module": "RVI" }, { "abbrev": true, "full_module": "LowStar.RVector", "short_module": "RV" }, { "abbrev": true, "full_module": "LowStar.Vector", "short_module": "V" }, { "abbrev": true, "full_module": "LowStar.ConstBuffer", "short_module": "CB" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.Monotonic.HyperHeap", "short_module": "HH" }, { "abbrev": true, "full_module": "FStar.Monotonic.HyperStack", "short_module": "MHS" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": false, "full_module": "LowStar.Regional.Instances", "short_module": null }, { "abbrev": false, "full_module": "LowStar.RVector", "short_module": null }, { "abbrev": false, "full_module": "LowStar.Regional", "short_module": null }, { "abbrev": false, "full_module": "LowStar.Vector", "short_module": null }, { "abbrev": false, "full_module": "LowStar.BufferOps", "short_module": null }, { "abbrev": false, "full_module": "LowStar.Buffer", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.Integers", "short_module": null }, { "abbrev": false, "full_module": "FStar.All", "short_module": null }, { "abbrev": false, "full_module": "MerkleTree.Low", "short_module": null }, { "abbrev": false, "full_module": "MerkleTree.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": 0, "initial_ifuel": 0, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 10, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
h: FStar.Monotonic.HyperStack.mem -> v: MerkleTree.Low.Datastructures.hash{MerkleTree.Low.Datastructures.hash_r_inv h v} -> Prims.GTot MerkleTree.Low.Datastructures.hash_repr
Prims.GTot
[ "sometrivial" ]
[]
[ "MerkleTree.Low.Datastructures.hash_size_t", "FStar.Monotonic.HyperStack.mem", "MerkleTree.Low.Datastructures.hash", "MerkleTree.Low.Datastructures.hash_r_inv", "LowStar.Monotonic.Buffer.as_seq", "Lib.IntTypes.uint8", "LowStar.Buffer.trivial_preorder", "MerkleTree.Low.Datastructures.hash_repr" ]
[]
false
false
false
false
false
let hash_r_repr #_ h v =
B.as_seq h v
false
MerkleTree.Low.Datastructures.fst
MerkleTree.Low.Datastructures.hash_r_free
val hash_r_free: #hsz':Ghost.erased hash_size_t -> hsz:hash_size_t { hsz == Ghost.reveal hsz' } -> v:hash #hsz' -> HST.ST unit (requires fun h0 -> hash_r_inv h0 v) (ensures fun h0 _ h1 -> modifies (loc_all_regions_from false (hash_region_of v)) h0 h1)
val hash_r_free: #hsz':Ghost.erased hash_size_t -> hsz:hash_size_t { hsz == Ghost.reveal hsz' } -> v:hash #hsz' -> HST.ST unit (requires fun h0 -> hash_r_inv h0 v) (ensures fun h0 _ h1 -> modifies (loc_all_regions_from false (hash_region_of v)) h0 h1)
let hash_r_free #_ _ v = B.free v
{ "file_name": "src/MerkleTree.Low.Datastructures.fst", "git_rev": "7d7bdc20f2033171e279c176b26e84f9069d23c6", "git_url": "https://github.com/hacl-star/merkle-tree.git", "project_name": "merkle-tree" }
{ "end_col": 10, "end_line": 141, "start_col": 0, "start_line": 140 }
module MerkleTree.Low.Datastructures open FStar.All open FStar.Integers open FStar.Mul open LowStar.Buffer open LowStar.BufferOps open LowStar.Vector open LowStar.Regional open LowStar.RVector open LowStar.Regional.Instances module HS = FStar.HyperStack module HST = FStar.HyperStack.ST module MHS = FStar.Monotonic.HyperStack module HH = FStar.Monotonic.HyperHeap module B = LowStar.Buffer module CB = LowStar.ConstBuffer module V = LowStar.Vector module RV = LowStar.RVector module RVI = LowStar.Regional.Instances module S = FStar.Seq module EHS = EverCrypt.Hash module U32 = FStar.UInt32 module MTH = MerkleTree.New.High open EverCrypt.Helpers open Lib.IntTypes #set-options "--z3rlimit 10 --initial_fuel 0 --max_fuel 0 --initial_ifuel 0 --max_ifuel 0" type hash_size_t = n:uint32_t{n > 0ul} type hash (#hsz:hash_size_t) = b:B.buffer uint8 { B.len b = hsz \/ B.g_is_null b } // We cannot use `Low.RVector.Instances`, where we have some general // typeclass instances of `regional`, e.g., if `rg:regional a` then // `regional (rvector rg)`. In FStar we can use this, but KaRaMeL currently // cannot deal with this and gives a number of errors. // So we temporarily instantiate some `regional`s manually below, which is // extractable to C by KaRaMeL. /// Some instantiations of `regional` used in Merkle tree /// 1. `hash` is regional private noextract val hash_region_of: #hsz:hash_size_t -> v:hash #hsz -> GTot HH.rid let hash_region_of #_ v = B.frameOf v private inline_for_extraction val hash_dummy: #hsz:Ghost.erased hash_size_t -> Tot (hash #hsz) let hash_dummy #_ = B.null private noextract val hash_r_inv: #hsz:hash_size_t -> h:HS.mem -> v:hash #hsz -> GTot Type0 let hash_r_inv #hsz h v = B.live h v /\ B.freeable v /\ B.len v = hsz private noextract val hash_r_inv_reg: #hsz:hash_size_t -> h:HS.mem -> v:hash -> Lemma (requires hash_r_inv h v) (ensures MHS.live_region h (hash_region_of #hsz v)) let hash_r_inv_reg #_ h v = () private noextract val hash_repr (#hsz:hash_size_t): Type0 let hash_repr #hsz = MTH.hash #(U32.v hsz) private noextract val hash_r_repr: #hsz:hash_size_t -> h:HS.mem -> v:hash{hash_r_inv #hsz h v} -> GTot (hash_repr #hsz) let hash_r_repr #_ h v = B.as_seq h v private noextract val hash_r_sep: #hsz:hash_size_t -> v:hash #hsz -> p:loc -> h0:HS.mem -> h1:HS.mem -> Lemma (requires hash_r_inv h0 v /\ loc_disjoint (loc_all_regions_from false (hash_region_of v)) p /\ modifies p h0 h1) (ensures hash_r_inv h1 v /\ hash_r_repr h0 v == hash_r_repr h1 v) let hash_r_sep #_ v p h0 h1 = assert (loc_includes (loc_all_regions_from false (hash_region_of v)) (loc_buffer v)); B.modifies_buffer_elim v p h0 h1 private noextract val hash_irepr: #hsz:hash_size_t -> Ghost.erased (hash_repr #hsz) let hash_irepr #hsz = Ghost.hide (S.create (U32.v hsz) (u8 0)) private noextract val hash_r_alloc_p: #hsz:hash_size_t -> v:hash #hsz -> GTot Type0 let hash_r_alloc_p #_ v = True val hash_r_alloc: #hsz':Ghost.erased hash_size_t -> hsz:hash_size_t { hsz == Ghost.reveal hsz' } -> r:HST.erid -> HST.ST (hash #hsz) (requires (fun h0 -> true)) (ensures (fun h0 v h1 -> Set.subset (Map.domain (MHS.get_hmap h0)) (Map.domain (MHS.get_hmap h1)) /\ modifies loc_none h0 h1 /\ hash_r_alloc_p #hsz v /\ hash_r_inv h1 v /\ hash_region_of v = r /\ hash_r_repr h1 v == Ghost.reveal hash_irepr /\ B.fresh_loc (B.loc_buffer v) h0 h1)) let hash_r_alloc #_ s r = B.malloc r (u8 0) s val hash_r_free: #hsz':Ghost.erased hash_size_t -> hsz:hash_size_t { hsz == Ghost.reveal hsz' } -> v:hash #hsz' -> HST.ST unit (requires fun h0 -> hash_r_inv h0 v) (ensures fun h0 _ h1 ->
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "MerkleTree.New.High.fst.checked", "LowStar.Vector.fst.checked", "LowStar.RVector.fst.checked", "LowStar.Regional.Instances.fst.checked", "LowStar.Regional.fst.checked", "LowStar.ConstBuffer.fsti.checked", "LowStar.BufferOps.fst.checked", "LowStar.Buffer.fst.checked", "Lib.IntTypes.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Set.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Monotonic.HyperStack.fsti.checked", "FStar.Monotonic.HyperHeap.fsti.checked", "FStar.Map.fsti.checked", "FStar.Integers.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked", "FStar.All.fst.checked", "EverCrypt.Helpers.fsti.checked", "EverCrypt.Hash.fsti.checked" ], "interface_file": false, "source_file": "MerkleTree.Low.Datastructures.fst" }
[ { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "EverCrypt.Helpers", "short_module": null }, { "abbrev": true, "full_module": "MerkleTree.New.High", "short_module": "MTH" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": true, "full_module": "EverCrypt.Hash", "short_module": "EHS" }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "S" }, { "abbrev": true, "full_module": "LowStar.Regional.Instances", "short_module": "RVI" }, { "abbrev": true, "full_module": "LowStar.RVector", "short_module": "RV" }, { "abbrev": true, "full_module": "LowStar.Vector", "short_module": "V" }, { "abbrev": true, "full_module": "LowStar.ConstBuffer", "short_module": "CB" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.Monotonic.HyperHeap", "short_module": "HH" }, { "abbrev": true, "full_module": "FStar.Monotonic.HyperStack", "short_module": "MHS" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": false, "full_module": "LowStar.Regional.Instances", "short_module": null }, { "abbrev": false, "full_module": "LowStar.RVector", "short_module": null }, { "abbrev": false, "full_module": "LowStar.Regional", "short_module": null }, { "abbrev": false, "full_module": "LowStar.Vector", "short_module": null }, { "abbrev": false, "full_module": "LowStar.BufferOps", "short_module": null }, { "abbrev": false, "full_module": "LowStar.Buffer", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.Integers", "short_module": null }, { "abbrev": false, "full_module": "FStar.All", "short_module": null }, { "abbrev": false, "full_module": "MerkleTree.Low", "short_module": null }, { "abbrev": false, "full_module": "MerkleTree.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": 0, "initial_ifuel": 0, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 10, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
hsz: MerkleTree.Low.Datastructures.hash_size_t{hsz == FStar.Ghost.reveal hsz'} -> v: MerkleTree.Low.Datastructures.hash -> FStar.HyperStack.ST.ST Prims.unit
FStar.HyperStack.ST.ST
[]
[]
[ "FStar.Ghost.erased", "MerkleTree.Low.Datastructures.hash_size_t", "Prims.eq2", "FStar.Ghost.reveal", "MerkleTree.Low.Datastructures.hash", "LowStar.Monotonic.Buffer.free", "Lib.IntTypes.uint8", "LowStar.Buffer.trivial_preorder", "Prims.unit" ]
[]
false
true
false
false
false
let hash_r_free #_ _ v =
B.free v
false
LowParse.Low.BCVLI.fst
LowParse.Low.BCVLI.read_bcvli
val read_bcvli:leaf_reader parse_bcvli
val read_bcvli:leaf_reader parse_bcvli
let read_bcvli : leaf_reader parse_bcvli = fun #rrel #rel input pos -> let h = HST.get () in [@inline_let] let _ = valid_facts parse_bcvli h input pos; parse_bcvli_eq (bytes_of_slice_from h input pos); valid_facts (parse_bounded_integer_le 1) h input pos in let r = read_bounded_integer_le_1 input pos in if r `U32.lt` 253ul then (r <: U32.t) else let pos1 = jump_constant_size (parse_bounded_integer_le 1) 1ul () input pos in [@inline_let] let _ = valid_facts (parse_bounded_integer_le 2) h input pos1; valid_facts (parse_bounded_integer_le 4) h input pos1 in if r = 253ul then read_bounded_integer_le_2 input pos1 <: U32.t else read_bounded_integer_le_4 input pos1 <: U32.t
{ "file_name": "src/lowparse/LowParse.Low.BCVLI.fst", "git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
{ "end_col": 54, "end_line": 100, "start_col": 0, "start_line": 81 }
module LowParse.Low.BCVLI include LowParse.Spec.BCVLI include LowParse.Low.Combinators include LowParse.Low.BoundedInt module B = LowStar.Buffer module HST = FStar.HyperStack.ST module Cast = FStar.Int.Cast module U32 = FStar.UInt32 module U64 = FStar.UInt64 #reset-options "--z3cliopt smt.arith.nl=false --max_fuel 0" #push-options "--z3rlimit 16" let validate_bcvli : validator parse_bcvli = fun #rrel #rel input pos -> let h = HST.get () in [@inline_let] let _ = valid_facts parse_bcvli h input (uint64_to_uint32 pos); parse_bcvli_eq (bytes_of_slice_from h input (uint64_to_uint32 pos)); valid_facts (parse_bounded_integer_le 1) h input (uint64_to_uint32 pos) in let pos1 = validate_total_constant_size (parse_bounded_integer_le 1) 1uL () input pos in if is_error pos1 then pos1 else [@inline_let] let _ = valid_facts (parse_bounded_integer_le 2) h input (uint64_to_uint32 pos1); valid_facts (parse_bounded_integer_le 4) h input (uint64_to_uint32 pos1) in let r = read_bounded_integer_le_1 input (uint64_to_uint32 pos) in if r `U32.lt` 253ul then pos1 else if r = 253ul then let pos2 = validate_total_constant_size (parse_bounded_integer_le 2) 2uL () input pos1 in if is_error pos2 then pos2 else (* because of the non-malleability constraint, I need to actually read the value and check whether it is not a lower integer *) let r = read_bounded_integer_le_2 input (uint64_to_uint32 pos1) in if r `U32.lt` 253ul then validator_error_generic else pos2 else if r = 254ul then let pos2 = validate_total_constant_size (parse_bounded_integer_le 4) 4uL () input pos1 in if is_error pos2 then pos2 else (* because of the non-malleability constraint, I need to actually read the value and check whether it is not a lower integer *) let r = read_bounded_integer_le_4 input (uint64_to_uint32 pos1) in if r `U32.lt` 65536ul then validator_error_generic else pos2 else validator_error_generic let jump_bcvli : jumper parse_bcvli = fun #rrel #rel input pos -> let h = HST.get () in [@inline_let] let _ = valid_facts parse_bcvli h input pos; parse_bcvli_eq (bytes_of_slice_from h input pos); valid_facts (parse_bounded_integer_le 1) h input pos in let pos1 = jump_constant_size (parse_bounded_integer_le 1) 1ul () input pos in [@inline_let] let _ = valid_facts (parse_bounded_integer_le 2) h input pos1; valid_facts (parse_bounded_integer_le 4) h input pos1 in let r = read_bounded_integer_le_1 input pos in if r `U32.lt` 253ul then pos1 else if r = 253ul then jump_constant_size (parse_bounded_integer_le 2) 2ul () input pos1 else jump_constant_size (parse_bounded_integer_le 4) 4ul () input pos1
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowStar.Buffer.fst.checked", "LowParse.Spec.BCVLI.fsti.checked", "LowParse.Low.Combinators.fsti.checked", "LowParse.Low.BoundedInt.fsti.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.Ghost.fsti.checked" ], "interface_file": false, "source_file": "LowParse.Low.BCVLI.fst" }
[ { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": true, "full_module": "FStar.Int.Cast", "short_module": "Cast" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": false, "full_module": "LowParse.Low.BoundedInt", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low.Combinators", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec.BCVLI", "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": 0, "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": [ "smt.arith.nl=false" ], "z3refresh": false, "z3rlimit": 16, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
LowParse.Low.Base.leaf_reader LowParse.Spec.BCVLI.parse_bcvli
Prims.Tot
[ "total" ]
[]
[ "LowParse.Slice.srel", "LowParse.Bytes.byte", "LowParse.Slice.slice", "FStar.UInt32.t", "FStar.UInt32.lt", "FStar.UInt32.__uint_to_t", "Prims.bool", "Prims.op_Equality", "LowParse.Low.BoundedInt.read_bounded_integer_le_2", "LowParse.Spec.BoundedInt.bounded_integer", "LowParse.Low.BoundedInt.read_bounded_integer_le_4", "Prims.unit", "LowParse.Low.Base.Spec.valid_facts", "LowParse.Spec.BoundedInt.parse_bounded_integer_kind", "LowParse.Spec.BoundedInt.parse_bounded_integer_le", "LowParse.Low.Base.jump_constant_size", "LowParse.Low.BoundedInt.read_bounded_integer_le_1", "LowParse.Spec.BCVLI.parse_bcvli_eq", "LowParse.Slice.bytes_of_slice_from", "LowParse.Spec.BCVLI.parse_bcvli_kind", "LowParse.Spec.BCVLI.parse_bcvli", "FStar.Monotonic.HyperStack.mem", "FStar.HyperStack.ST.get" ]
[]
false
false
false
true
false
let read_bcvli:leaf_reader parse_bcvli =
fun #rrel #rel input pos -> let h = HST.get () in [@@ inline_let ]let _ = valid_facts parse_bcvli h input pos; parse_bcvli_eq (bytes_of_slice_from h input pos); valid_facts (parse_bounded_integer_le 1) h input pos in let r = read_bounded_integer_le_1 input pos in if r `U32.lt` 253ul then (r <: U32.t) else let pos1 = jump_constant_size (parse_bounded_integer_le 1) 1ul () input pos in [@@ inline_let ]let _ = valid_facts (parse_bounded_integer_le 2) h input pos1; valid_facts (parse_bounded_integer_le 4) h input pos1 in if r = 253ul then read_bounded_integer_le_2 input pos1 <: U32.t else read_bounded_integer_le_4 input pos1 <: U32.t
false
MerkleTree.Low.Datastructures.fst
MerkleTree.Low.Datastructures.hash_repr
val hash_repr (#hsz:hash_size_t): Type0
val hash_repr (#hsz:hash_size_t): Type0
let hash_repr #hsz = MTH.hash #(U32.v hsz)
{ "file_name": "src/MerkleTree.Low.Datastructures.fst", "git_rev": "7d7bdc20f2033171e279c176b26e84f9069d23c6", "git_url": "https://github.com/hacl-star/merkle-tree.git", "project_name": "merkle-tree" }
{ "end_col": 42, "end_line": 77, "start_col": 0, "start_line": 77 }
module MerkleTree.Low.Datastructures open FStar.All open FStar.Integers open FStar.Mul open LowStar.Buffer open LowStar.BufferOps open LowStar.Vector open LowStar.Regional open LowStar.RVector open LowStar.Regional.Instances module HS = FStar.HyperStack module HST = FStar.HyperStack.ST module MHS = FStar.Monotonic.HyperStack module HH = FStar.Monotonic.HyperHeap module B = LowStar.Buffer module CB = LowStar.ConstBuffer module V = LowStar.Vector module RV = LowStar.RVector module RVI = LowStar.Regional.Instances module S = FStar.Seq module EHS = EverCrypt.Hash module U32 = FStar.UInt32 module MTH = MerkleTree.New.High open EverCrypt.Helpers open Lib.IntTypes #set-options "--z3rlimit 10 --initial_fuel 0 --max_fuel 0 --initial_ifuel 0 --max_ifuel 0" type hash_size_t = n:uint32_t{n > 0ul} type hash (#hsz:hash_size_t) = b:B.buffer uint8 { B.len b = hsz \/ B.g_is_null b } // We cannot use `Low.RVector.Instances`, where we have some general // typeclass instances of `regional`, e.g., if `rg:regional a` then // `regional (rvector rg)`. In FStar we can use this, but KaRaMeL currently // cannot deal with this and gives a number of errors. // So we temporarily instantiate some `regional`s manually below, which is // extractable to C by KaRaMeL. /// Some instantiations of `regional` used in Merkle tree /// 1. `hash` is regional private noextract val hash_region_of: #hsz:hash_size_t -> v:hash #hsz -> GTot HH.rid let hash_region_of #_ v = B.frameOf v private inline_for_extraction val hash_dummy: #hsz:Ghost.erased hash_size_t -> Tot (hash #hsz) let hash_dummy #_ = B.null private noextract val hash_r_inv: #hsz:hash_size_t -> h:HS.mem -> v:hash #hsz -> GTot Type0 let hash_r_inv #hsz h v = B.live h v /\ B.freeable v /\ B.len v = hsz private noextract val hash_r_inv_reg: #hsz:hash_size_t -> h:HS.mem -> v:hash -> Lemma (requires hash_r_inv h v) (ensures MHS.live_region h (hash_region_of #hsz v)) let hash_r_inv_reg #_ h v = () private noextract
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "MerkleTree.New.High.fst.checked", "LowStar.Vector.fst.checked", "LowStar.RVector.fst.checked", "LowStar.Regional.Instances.fst.checked", "LowStar.Regional.fst.checked", "LowStar.ConstBuffer.fsti.checked", "LowStar.BufferOps.fst.checked", "LowStar.Buffer.fst.checked", "Lib.IntTypes.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Set.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Monotonic.HyperStack.fsti.checked", "FStar.Monotonic.HyperHeap.fsti.checked", "FStar.Map.fsti.checked", "FStar.Integers.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked", "FStar.All.fst.checked", "EverCrypt.Helpers.fsti.checked", "EverCrypt.Hash.fsti.checked" ], "interface_file": false, "source_file": "MerkleTree.Low.Datastructures.fst" }
[ { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "EverCrypt.Helpers", "short_module": null }, { "abbrev": true, "full_module": "MerkleTree.New.High", "short_module": "MTH" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": true, "full_module": "EverCrypt.Hash", "short_module": "EHS" }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "S" }, { "abbrev": true, "full_module": "LowStar.Regional.Instances", "short_module": "RVI" }, { "abbrev": true, "full_module": "LowStar.RVector", "short_module": "RV" }, { "abbrev": true, "full_module": "LowStar.Vector", "short_module": "V" }, { "abbrev": true, "full_module": "LowStar.ConstBuffer", "short_module": "CB" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.Monotonic.HyperHeap", "short_module": "HH" }, { "abbrev": true, "full_module": "FStar.Monotonic.HyperStack", "short_module": "MHS" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": false, "full_module": "LowStar.Regional.Instances", "short_module": null }, { "abbrev": false, "full_module": "LowStar.RVector", "short_module": null }, { "abbrev": false, "full_module": "LowStar.Regional", "short_module": null }, { "abbrev": false, "full_module": "LowStar.Vector", "short_module": null }, { "abbrev": false, "full_module": "LowStar.BufferOps", "short_module": null }, { "abbrev": false, "full_module": "LowStar.Buffer", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.Integers", "short_module": null }, { "abbrev": false, "full_module": "FStar.All", "short_module": null }, { "abbrev": false, "full_module": "MerkleTree.Low", "short_module": null }, { "abbrev": false, "full_module": "MerkleTree.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": 0, "initial_ifuel": 0, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 10, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
Type0
Prims.Tot
[ "total" ]
[]
[ "MerkleTree.Low.Datastructures.hash_size_t", "MerkleTree.New.High.hash", "FStar.UInt32.v" ]
[]
false
false
false
true
true
let hash_repr #hsz =
MTH.hash #(U32.v hsz)
false
MerkleTree.Low.Datastructures.fst
MerkleTree.Low.Datastructures.hash_dummy
val hash_dummy: #hsz:Ghost.erased hash_size_t -> Tot (hash #hsz)
val hash_dummy: #hsz:Ghost.erased hash_size_t -> Tot (hash #hsz)
let hash_dummy #_ = B.null
{ "file_name": "src/MerkleTree.Low.Datastructures.fst", "git_rev": "7d7bdc20f2033171e279c176b26e84f9069d23c6", "git_url": "https://github.com/hacl-star/merkle-tree.git", "project_name": "merkle-tree" }
{ "end_col": 26, "end_line": 56, "start_col": 0, "start_line": 56 }
module MerkleTree.Low.Datastructures open FStar.All open FStar.Integers open FStar.Mul open LowStar.Buffer open LowStar.BufferOps open LowStar.Vector open LowStar.Regional open LowStar.RVector open LowStar.Regional.Instances module HS = FStar.HyperStack module HST = FStar.HyperStack.ST module MHS = FStar.Monotonic.HyperStack module HH = FStar.Monotonic.HyperHeap module B = LowStar.Buffer module CB = LowStar.ConstBuffer module V = LowStar.Vector module RV = LowStar.RVector module RVI = LowStar.Regional.Instances module S = FStar.Seq module EHS = EverCrypt.Hash module U32 = FStar.UInt32 module MTH = MerkleTree.New.High open EverCrypt.Helpers open Lib.IntTypes #set-options "--z3rlimit 10 --initial_fuel 0 --max_fuel 0 --initial_ifuel 0 --max_ifuel 0" type hash_size_t = n:uint32_t{n > 0ul} type hash (#hsz:hash_size_t) = b:B.buffer uint8 { B.len b = hsz \/ B.g_is_null b } // We cannot use `Low.RVector.Instances`, where we have some general // typeclass instances of `regional`, e.g., if `rg:regional a` then // `regional (rvector rg)`. In FStar we can use this, but KaRaMeL currently // cannot deal with this and gives a number of errors. // So we temporarily instantiate some `regional`s manually below, which is // extractable to C by KaRaMeL. /// Some instantiations of `regional` used in Merkle tree /// 1. `hash` is regional private noextract val hash_region_of: #hsz:hash_size_t -> v:hash #hsz -> GTot HH.rid let hash_region_of #_ v = B.frameOf v private inline_for_extraction
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "MerkleTree.New.High.fst.checked", "LowStar.Vector.fst.checked", "LowStar.RVector.fst.checked", "LowStar.Regional.Instances.fst.checked", "LowStar.Regional.fst.checked", "LowStar.ConstBuffer.fsti.checked", "LowStar.BufferOps.fst.checked", "LowStar.Buffer.fst.checked", "Lib.IntTypes.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Set.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Monotonic.HyperStack.fsti.checked", "FStar.Monotonic.HyperHeap.fsti.checked", "FStar.Map.fsti.checked", "FStar.Integers.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked", "FStar.All.fst.checked", "EverCrypt.Helpers.fsti.checked", "EverCrypt.Hash.fsti.checked" ], "interface_file": false, "source_file": "MerkleTree.Low.Datastructures.fst" }
[ { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "EverCrypt.Helpers", "short_module": null }, { "abbrev": true, "full_module": "MerkleTree.New.High", "short_module": "MTH" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": true, "full_module": "EverCrypt.Hash", "short_module": "EHS" }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "S" }, { "abbrev": true, "full_module": "LowStar.Regional.Instances", "short_module": "RVI" }, { "abbrev": true, "full_module": "LowStar.RVector", "short_module": "RV" }, { "abbrev": true, "full_module": "LowStar.Vector", "short_module": "V" }, { "abbrev": true, "full_module": "LowStar.ConstBuffer", "short_module": "CB" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.Monotonic.HyperHeap", "short_module": "HH" }, { "abbrev": true, "full_module": "FStar.Monotonic.HyperStack", "short_module": "MHS" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": false, "full_module": "LowStar.Regional.Instances", "short_module": null }, { "abbrev": false, "full_module": "LowStar.RVector", "short_module": null }, { "abbrev": false, "full_module": "LowStar.Regional", "short_module": null }, { "abbrev": false, "full_module": "LowStar.Vector", "short_module": null }, { "abbrev": false, "full_module": "LowStar.BufferOps", "short_module": null }, { "abbrev": false, "full_module": "LowStar.Buffer", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.Integers", "short_module": null }, { "abbrev": false, "full_module": "FStar.All", "short_module": null }, { "abbrev": false, "full_module": "MerkleTree.Low", "short_module": null }, { "abbrev": false, "full_module": "MerkleTree.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": 0, "initial_ifuel": 0, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 10, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
MerkleTree.Low.Datastructures.hash
Prims.Tot
[ "total" ]
[]
[ "FStar.Ghost.erased", "MerkleTree.Low.Datastructures.hash_size_t", "LowStar.Buffer.null", "Lib.IntTypes.uint8", "MerkleTree.Low.Datastructures.hash", "FStar.Ghost.reveal" ]
[]
false
false
false
false
false
let hash_dummy #_ =
B.null
false
LowParse.Low.BCVLI.fst
LowParse.Low.BCVLI.jump_bcvli
val jump_bcvli:jumper parse_bcvli
val jump_bcvli:jumper parse_bcvli
let jump_bcvli : jumper parse_bcvli = fun #rrel #rel input pos -> let h = HST.get () in [@inline_let] let _ = valid_facts parse_bcvli h input pos; parse_bcvli_eq (bytes_of_slice_from h input pos); valid_facts (parse_bounded_integer_le 1) h input pos in let pos1 = jump_constant_size (parse_bounded_integer_le 1) 1ul () input pos in [@inline_let] let _ = valid_facts (parse_bounded_integer_le 2) h input pos1; valid_facts (parse_bounded_integer_le 4) h input pos1 in let r = read_bounded_integer_le_1 input pos in if r `U32.lt` 253ul then pos1 else if r = 253ul then jump_constant_size (parse_bounded_integer_le 2) 2ul () input pos1 else jump_constant_size (parse_bounded_integer_le 4) 4ul () input pos1
{ "file_name": "src/lowparse/LowParse.Low.BCVLI.fst", "git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
{ "end_col": 69, "end_line": 79, "start_col": 0, "start_line": 59 }
module LowParse.Low.BCVLI include LowParse.Spec.BCVLI include LowParse.Low.Combinators include LowParse.Low.BoundedInt module B = LowStar.Buffer module HST = FStar.HyperStack.ST module Cast = FStar.Int.Cast module U32 = FStar.UInt32 module U64 = FStar.UInt64 #reset-options "--z3cliopt smt.arith.nl=false --max_fuel 0" #push-options "--z3rlimit 16" let validate_bcvli : validator parse_bcvli = fun #rrel #rel input pos -> let h = HST.get () in [@inline_let] let _ = valid_facts parse_bcvli h input (uint64_to_uint32 pos); parse_bcvli_eq (bytes_of_slice_from h input (uint64_to_uint32 pos)); valid_facts (parse_bounded_integer_le 1) h input (uint64_to_uint32 pos) in let pos1 = validate_total_constant_size (parse_bounded_integer_le 1) 1uL () input pos in if is_error pos1 then pos1 else [@inline_let] let _ = valid_facts (parse_bounded_integer_le 2) h input (uint64_to_uint32 pos1); valid_facts (parse_bounded_integer_le 4) h input (uint64_to_uint32 pos1) in let r = read_bounded_integer_le_1 input (uint64_to_uint32 pos) in if r `U32.lt` 253ul then pos1 else if r = 253ul then let pos2 = validate_total_constant_size (parse_bounded_integer_le 2) 2uL () input pos1 in if is_error pos2 then pos2 else (* because of the non-malleability constraint, I need to actually read the value and check whether it is not a lower integer *) let r = read_bounded_integer_le_2 input (uint64_to_uint32 pos1) in if r `U32.lt` 253ul then validator_error_generic else pos2 else if r = 254ul then let pos2 = validate_total_constant_size (parse_bounded_integer_le 4) 4uL () input pos1 in if is_error pos2 then pos2 else (* because of the non-malleability constraint, I need to actually read the value and check whether it is not a lower integer *) let r = read_bounded_integer_le_4 input (uint64_to_uint32 pos1) in if r `U32.lt` 65536ul then validator_error_generic else pos2 else validator_error_generic
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowStar.Buffer.fst.checked", "LowParse.Spec.BCVLI.fsti.checked", "LowParse.Low.Combinators.fsti.checked", "LowParse.Low.BoundedInt.fsti.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.Ghost.fsti.checked" ], "interface_file": false, "source_file": "LowParse.Low.BCVLI.fst" }
[ { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": true, "full_module": "FStar.Int.Cast", "short_module": "Cast" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": false, "full_module": "LowParse.Low.BoundedInt", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low.Combinators", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec.BCVLI", "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": 0, "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": [ "smt.arith.nl=false" ], "z3refresh": false, "z3rlimit": 16, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
LowParse.Low.Base.jumper LowParse.Spec.BCVLI.parse_bcvli
Prims.Tot
[ "total" ]
[]
[ "LowParse.Slice.srel", "LowParse.Bytes.byte", "LowParse.Slice.slice", "FStar.UInt32.t", "FStar.UInt32.lt", "FStar.UInt32.__uint_to_t", "Prims.bool", "Prims.op_Equality", "LowParse.Low.Base.jump_constant_size", "LowParse.Spec.BoundedInt.parse_bounded_integer_kind", "LowParse.Spec.BoundedInt.bounded_integer", "LowParse.Spec.BoundedInt.parse_bounded_integer_le", "LowParse.Low.BoundedInt.read_bounded_integer_le_1", "Prims.unit", "LowParse.Low.Base.Spec.valid_facts", "LowParse.Spec.BCVLI.parse_bcvli_eq", "LowParse.Slice.bytes_of_slice_from", "LowParse.Spec.BCVLI.parse_bcvli_kind", "LowParse.Spec.BCVLI.parse_bcvli", "FStar.Monotonic.HyperStack.mem", "FStar.HyperStack.ST.get" ]
[]
false
false
false
true
false
let jump_bcvli:jumper parse_bcvli =
fun #rrel #rel input pos -> let h = HST.get () in [@@ inline_let ]let _ = valid_facts parse_bcvli h input pos; parse_bcvli_eq (bytes_of_slice_from h input pos); valid_facts (parse_bounded_integer_le 1) h input pos in let pos1 = jump_constant_size (parse_bounded_integer_le 1) 1ul () input pos in [@@ inline_let ]let _ = valid_facts (parse_bounded_integer_le 2) h input pos1; valid_facts (parse_bounded_integer_le 4) h input pos1 in let r = read_bounded_integer_le_1 input pos in if r `U32.lt` 253ul then pos1 else if r = 253ul then jump_constant_size (parse_bounded_integer_le 2) 2ul () input pos1 else jump_constant_size (parse_bounded_integer_le 4) 4ul () input pos1
false
MerkleTree.Low.Datastructures.fst
MerkleTree.Low.Datastructures.hash_r_sep
val hash_r_sep: #hsz:hash_size_t -> v:hash #hsz -> p:loc -> h0:HS.mem -> h1:HS.mem -> Lemma (requires hash_r_inv h0 v /\ loc_disjoint (loc_all_regions_from false (hash_region_of v)) p /\ modifies p h0 h1) (ensures hash_r_inv h1 v /\ hash_r_repr h0 v == hash_r_repr h1 v)
val hash_r_sep: #hsz:hash_size_t -> v:hash #hsz -> p:loc -> h0:HS.mem -> h1:HS.mem -> Lemma (requires hash_r_inv h0 v /\ loc_disjoint (loc_all_regions_from false (hash_region_of v)) p /\ modifies p h0 h1) (ensures hash_r_inv h1 v /\ hash_r_repr h0 v == hash_r_repr h1 v)
let hash_r_sep #_ v p h0 h1 = assert (loc_includes (loc_all_regions_from false (hash_region_of v)) (loc_buffer v)); B.modifies_buffer_elim v p h0 h1
{ "file_name": "src/MerkleTree.Low.Datastructures.fst", "git_rev": "7d7bdc20f2033171e279c176b26e84f9069d23c6", "git_url": "https://github.com/hacl-star/merkle-tree.git", "project_name": "merkle-tree" }
{ "end_col": 34, "end_line": 101, "start_col": 0, "start_line": 98 }
module MerkleTree.Low.Datastructures open FStar.All open FStar.Integers open FStar.Mul open LowStar.Buffer open LowStar.BufferOps open LowStar.Vector open LowStar.Regional open LowStar.RVector open LowStar.Regional.Instances module HS = FStar.HyperStack module HST = FStar.HyperStack.ST module MHS = FStar.Monotonic.HyperStack module HH = FStar.Monotonic.HyperHeap module B = LowStar.Buffer module CB = LowStar.ConstBuffer module V = LowStar.Vector module RV = LowStar.RVector module RVI = LowStar.Regional.Instances module S = FStar.Seq module EHS = EverCrypt.Hash module U32 = FStar.UInt32 module MTH = MerkleTree.New.High open EverCrypt.Helpers open Lib.IntTypes #set-options "--z3rlimit 10 --initial_fuel 0 --max_fuel 0 --initial_ifuel 0 --max_ifuel 0" type hash_size_t = n:uint32_t{n > 0ul} type hash (#hsz:hash_size_t) = b:B.buffer uint8 { B.len b = hsz \/ B.g_is_null b } // We cannot use `Low.RVector.Instances`, where we have some general // typeclass instances of `regional`, e.g., if `rg:regional a` then // `regional (rvector rg)`. In FStar we can use this, but KaRaMeL currently // cannot deal with this and gives a number of errors. // So we temporarily instantiate some `regional`s manually below, which is // extractable to C by KaRaMeL. /// Some instantiations of `regional` used in Merkle tree /// 1. `hash` is regional private noextract val hash_region_of: #hsz:hash_size_t -> v:hash #hsz -> GTot HH.rid let hash_region_of #_ v = B.frameOf v private inline_for_extraction val hash_dummy: #hsz:Ghost.erased hash_size_t -> Tot (hash #hsz) let hash_dummy #_ = B.null private noextract val hash_r_inv: #hsz:hash_size_t -> h:HS.mem -> v:hash #hsz -> GTot Type0 let hash_r_inv #hsz h v = B.live h v /\ B.freeable v /\ B.len v = hsz private noextract val hash_r_inv_reg: #hsz:hash_size_t -> h:HS.mem -> v:hash -> Lemma (requires hash_r_inv h v) (ensures MHS.live_region h (hash_region_of #hsz v)) let hash_r_inv_reg #_ h v = () private noextract val hash_repr (#hsz:hash_size_t): Type0 let hash_repr #hsz = MTH.hash #(U32.v hsz) private noextract val hash_r_repr: #hsz:hash_size_t -> h:HS.mem -> v:hash{hash_r_inv #hsz h v} -> GTot (hash_repr #hsz) let hash_r_repr #_ h v = B.as_seq h v private noextract val hash_r_sep: #hsz:hash_size_t -> v:hash #hsz -> p:loc -> h0:HS.mem -> h1:HS.mem -> Lemma (requires hash_r_inv h0 v /\ loc_disjoint (loc_all_regions_from false (hash_region_of v)) p /\ modifies p h0 h1) (ensures hash_r_inv h1 v /\
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "MerkleTree.New.High.fst.checked", "LowStar.Vector.fst.checked", "LowStar.RVector.fst.checked", "LowStar.Regional.Instances.fst.checked", "LowStar.Regional.fst.checked", "LowStar.ConstBuffer.fsti.checked", "LowStar.BufferOps.fst.checked", "LowStar.Buffer.fst.checked", "Lib.IntTypes.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Set.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Monotonic.HyperStack.fsti.checked", "FStar.Monotonic.HyperHeap.fsti.checked", "FStar.Map.fsti.checked", "FStar.Integers.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked", "FStar.All.fst.checked", "EverCrypt.Helpers.fsti.checked", "EverCrypt.Hash.fsti.checked" ], "interface_file": false, "source_file": "MerkleTree.Low.Datastructures.fst" }
[ { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "EverCrypt.Helpers", "short_module": null }, { "abbrev": true, "full_module": "MerkleTree.New.High", "short_module": "MTH" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": true, "full_module": "EverCrypt.Hash", "short_module": "EHS" }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "S" }, { "abbrev": true, "full_module": "LowStar.Regional.Instances", "short_module": "RVI" }, { "abbrev": true, "full_module": "LowStar.RVector", "short_module": "RV" }, { "abbrev": true, "full_module": "LowStar.Vector", "short_module": "V" }, { "abbrev": true, "full_module": "LowStar.ConstBuffer", "short_module": "CB" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.Monotonic.HyperHeap", "short_module": "HH" }, { "abbrev": true, "full_module": "FStar.Monotonic.HyperStack", "short_module": "MHS" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": false, "full_module": "LowStar.Regional.Instances", "short_module": null }, { "abbrev": false, "full_module": "LowStar.RVector", "short_module": null }, { "abbrev": false, "full_module": "LowStar.Regional", "short_module": null }, { "abbrev": false, "full_module": "LowStar.Vector", "short_module": null }, { "abbrev": false, "full_module": "LowStar.BufferOps", "short_module": null }, { "abbrev": false, "full_module": "LowStar.Buffer", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.Integers", "short_module": null }, { "abbrev": false, "full_module": "FStar.All", "short_module": null }, { "abbrev": false, "full_module": "MerkleTree.Low", "short_module": null }, { "abbrev": false, "full_module": "MerkleTree.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": 0, "initial_ifuel": 0, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 10, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
v: MerkleTree.Low.Datastructures.hash -> p: LowStar.Monotonic.Buffer.loc -> h0: FStar.Monotonic.HyperStack.mem -> h1: FStar.Monotonic.HyperStack.mem -> FStar.Pervasives.Lemma (requires MerkleTree.Low.Datastructures.hash_r_inv h0 v /\ LowStar.Monotonic.Buffer.loc_disjoint (LowStar.Monotonic.Buffer.loc_all_regions_from false (MerkleTree.Low.Datastructures.hash_region_of v)) p /\ LowStar.Monotonic.Buffer.modifies p h0 h1) (ensures MerkleTree.Low.Datastructures.hash_r_inv h1 v /\ MerkleTree.Low.Datastructures.hash_r_repr h0 v == MerkleTree.Low.Datastructures.hash_r_repr h1 v)
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "MerkleTree.Low.Datastructures.hash_size_t", "MerkleTree.Low.Datastructures.hash", "LowStar.Monotonic.Buffer.loc", "FStar.Monotonic.HyperStack.mem", "LowStar.Monotonic.Buffer.modifies_buffer_elim", "Lib.IntTypes.uint8", "LowStar.Buffer.trivial_preorder", "Prims.unit", "Prims._assert", "LowStar.Monotonic.Buffer.loc_includes", "LowStar.Monotonic.Buffer.loc_all_regions_from", "MerkleTree.Low.Datastructures.hash_region_of", "LowStar.Monotonic.Buffer.loc_buffer" ]
[]
true
false
true
false
false
let hash_r_sep #_ v p h0 h1 =
assert (loc_includes (loc_all_regions_from false (hash_region_of v)) (loc_buffer v)); B.modifies_buffer_elim v p h0 h1
false
MerkleTree.Low.Datastructures.fst
MerkleTree.Low.Datastructures.hash_irepr
val hash_irepr: #hsz:hash_size_t -> Ghost.erased (hash_repr #hsz)
val hash_irepr: #hsz:hash_size_t -> Ghost.erased (hash_repr #hsz)
let hash_irepr #hsz = Ghost.hide (S.create (U32.v hsz) (u8 0))
{ "file_name": "src/MerkleTree.Low.Datastructures.fst", "git_rev": "7d7bdc20f2033171e279c176b26e84f9069d23c6", "git_url": "https://github.com/hacl-star/merkle-tree.git", "project_name": "merkle-tree" }
{ "end_col": 42, "end_line": 107, "start_col": 0, "start_line": 106 }
module MerkleTree.Low.Datastructures open FStar.All open FStar.Integers open FStar.Mul open LowStar.Buffer open LowStar.BufferOps open LowStar.Vector open LowStar.Regional open LowStar.RVector open LowStar.Regional.Instances module HS = FStar.HyperStack module HST = FStar.HyperStack.ST module MHS = FStar.Monotonic.HyperStack module HH = FStar.Monotonic.HyperHeap module B = LowStar.Buffer module CB = LowStar.ConstBuffer module V = LowStar.Vector module RV = LowStar.RVector module RVI = LowStar.Regional.Instances module S = FStar.Seq module EHS = EverCrypt.Hash module U32 = FStar.UInt32 module MTH = MerkleTree.New.High open EverCrypt.Helpers open Lib.IntTypes #set-options "--z3rlimit 10 --initial_fuel 0 --max_fuel 0 --initial_ifuel 0 --max_ifuel 0" type hash_size_t = n:uint32_t{n > 0ul} type hash (#hsz:hash_size_t) = b:B.buffer uint8 { B.len b = hsz \/ B.g_is_null b } // We cannot use `Low.RVector.Instances`, where we have some general // typeclass instances of `regional`, e.g., if `rg:regional a` then // `regional (rvector rg)`. In FStar we can use this, but KaRaMeL currently // cannot deal with this and gives a number of errors. // So we temporarily instantiate some `regional`s manually below, which is // extractable to C by KaRaMeL. /// Some instantiations of `regional` used in Merkle tree /// 1. `hash` is regional private noextract val hash_region_of: #hsz:hash_size_t -> v:hash #hsz -> GTot HH.rid let hash_region_of #_ v = B.frameOf v private inline_for_extraction val hash_dummy: #hsz:Ghost.erased hash_size_t -> Tot (hash #hsz) let hash_dummy #_ = B.null private noextract val hash_r_inv: #hsz:hash_size_t -> h:HS.mem -> v:hash #hsz -> GTot Type0 let hash_r_inv #hsz h v = B.live h v /\ B.freeable v /\ B.len v = hsz private noextract val hash_r_inv_reg: #hsz:hash_size_t -> h:HS.mem -> v:hash -> Lemma (requires hash_r_inv h v) (ensures MHS.live_region h (hash_region_of #hsz v)) let hash_r_inv_reg #_ h v = () private noextract val hash_repr (#hsz:hash_size_t): Type0 let hash_repr #hsz = MTH.hash #(U32.v hsz) private noextract val hash_r_repr: #hsz:hash_size_t -> h:HS.mem -> v:hash{hash_r_inv #hsz h v} -> GTot (hash_repr #hsz) let hash_r_repr #_ h v = B.as_seq h v private noextract val hash_r_sep: #hsz:hash_size_t -> v:hash #hsz -> p:loc -> h0:HS.mem -> h1:HS.mem -> Lemma (requires hash_r_inv h0 v /\ loc_disjoint (loc_all_regions_from false (hash_region_of v)) p /\ modifies p h0 h1) (ensures hash_r_inv h1 v /\ hash_r_repr h0 v == hash_r_repr h1 v) let hash_r_sep #_ v p h0 h1 = assert (loc_includes (loc_all_regions_from false (hash_region_of v)) (loc_buffer v)); B.modifies_buffer_elim v p h0 h1 private noextract
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "MerkleTree.New.High.fst.checked", "LowStar.Vector.fst.checked", "LowStar.RVector.fst.checked", "LowStar.Regional.Instances.fst.checked", "LowStar.Regional.fst.checked", "LowStar.ConstBuffer.fsti.checked", "LowStar.BufferOps.fst.checked", "LowStar.Buffer.fst.checked", "Lib.IntTypes.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Set.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Monotonic.HyperStack.fsti.checked", "FStar.Monotonic.HyperHeap.fsti.checked", "FStar.Map.fsti.checked", "FStar.Integers.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked", "FStar.All.fst.checked", "EverCrypt.Helpers.fsti.checked", "EverCrypt.Hash.fsti.checked" ], "interface_file": false, "source_file": "MerkleTree.Low.Datastructures.fst" }
[ { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "EverCrypt.Helpers", "short_module": null }, { "abbrev": true, "full_module": "MerkleTree.New.High", "short_module": "MTH" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": true, "full_module": "EverCrypt.Hash", "short_module": "EHS" }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "S" }, { "abbrev": true, "full_module": "LowStar.Regional.Instances", "short_module": "RVI" }, { "abbrev": true, "full_module": "LowStar.RVector", "short_module": "RV" }, { "abbrev": true, "full_module": "LowStar.Vector", "short_module": "V" }, { "abbrev": true, "full_module": "LowStar.ConstBuffer", "short_module": "CB" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.Monotonic.HyperHeap", "short_module": "HH" }, { "abbrev": true, "full_module": "FStar.Monotonic.HyperStack", "short_module": "MHS" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": false, "full_module": "LowStar.Regional.Instances", "short_module": null }, { "abbrev": false, "full_module": "LowStar.RVector", "short_module": null }, { "abbrev": false, "full_module": "LowStar.Regional", "short_module": null }, { "abbrev": false, "full_module": "LowStar.Vector", "short_module": null }, { "abbrev": false, "full_module": "LowStar.BufferOps", "short_module": null }, { "abbrev": false, "full_module": "LowStar.Buffer", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.Integers", "short_module": null }, { "abbrev": false, "full_module": "FStar.All", "short_module": null }, { "abbrev": false, "full_module": "MerkleTree.Low", "short_module": null }, { "abbrev": false, "full_module": "MerkleTree.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": 0, "initial_ifuel": 0, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 10, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
FStar.Ghost.erased MerkleTree.Low.Datastructures.hash_repr
Prims.Tot
[ "total" ]
[]
[ "MerkleTree.Low.Datastructures.hash_size_t", "FStar.Ghost.hide", "MerkleTree.Low.Datastructures.hash_repr", "FStar.Seq.Base.create", "Lib.IntTypes.uint8", "FStar.UInt32.v", "Lib.IntTypes.u8", "FStar.Ghost.erased" ]
[]
false
false
false
false
false
let hash_irepr #hsz =
Ghost.hide (S.create (U32.v hsz) (u8 0))
false
MerkleTree.Low.Datastructures.fst
MerkleTree.Low.Datastructures.hreg
val hreg (hsz:hash_size_t): regional (hash_size_t) (hash #hsz)
val hreg (hsz:hash_size_t): regional (hash_size_t) (hash #hsz)
let hreg hsz = Rgl #(hash_size_t) #(hash #hsz) hsz (hash_region_of #hsz) (B.loc_buffer) (hash_dummy #hsz) (hash_r_inv #hsz) (hash_r_inv_reg #hsz) (hash_repr #hsz) (hash_r_repr #hsz) (hash_r_sep #hsz) (hash_irepr #hsz) (hash_r_alloc_p #hsz) (hash_r_alloc #hsz) (hash_r_free #hsz)
{ "file_name": "src/MerkleTree.Low.Datastructures.fst", "git_rev": "7d7bdc20f2033171e279c176b26e84f9069d23c6", "git_url": "https://github.com/hacl-star/merkle-tree.git", "project_name": "merkle-tree" }
{ "end_col": 24, "end_line": 158, "start_col": 0, "start_line": 145 }
module MerkleTree.Low.Datastructures open FStar.All open FStar.Integers open FStar.Mul open LowStar.Buffer open LowStar.BufferOps open LowStar.Vector open LowStar.Regional open LowStar.RVector open LowStar.Regional.Instances module HS = FStar.HyperStack module HST = FStar.HyperStack.ST module MHS = FStar.Monotonic.HyperStack module HH = FStar.Monotonic.HyperHeap module B = LowStar.Buffer module CB = LowStar.ConstBuffer module V = LowStar.Vector module RV = LowStar.RVector module RVI = LowStar.Regional.Instances module S = FStar.Seq module EHS = EverCrypt.Hash module U32 = FStar.UInt32 module MTH = MerkleTree.New.High open EverCrypt.Helpers open Lib.IntTypes #set-options "--z3rlimit 10 --initial_fuel 0 --max_fuel 0 --initial_ifuel 0 --max_ifuel 0" type hash_size_t = n:uint32_t{n > 0ul} type hash (#hsz:hash_size_t) = b:B.buffer uint8 { B.len b = hsz \/ B.g_is_null b } // We cannot use `Low.RVector.Instances`, where we have some general // typeclass instances of `regional`, e.g., if `rg:regional a` then // `regional (rvector rg)`. In FStar we can use this, but KaRaMeL currently // cannot deal with this and gives a number of errors. // So we temporarily instantiate some `regional`s manually below, which is // extractable to C by KaRaMeL. /// Some instantiations of `regional` used in Merkle tree /// 1. `hash` is regional private noextract val hash_region_of: #hsz:hash_size_t -> v:hash #hsz -> GTot HH.rid let hash_region_of #_ v = B.frameOf v private inline_for_extraction val hash_dummy: #hsz:Ghost.erased hash_size_t -> Tot (hash #hsz) let hash_dummy #_ = B.null private noextract val hash_r_inv: #hsz:hash_size_t -> h:HS.mem -> v:hash #hsz -> GTot Type0 let hash_r_inv #hsz h v = B.live h v /\ B.freeable v /\ B.len v = hsz private noextract val hash_r_inv_reg: #hsz:hash_size_t -> h:HS.mem -> v:hash -> Lemma (requires hash_r_inv h v) (ensures MHS.live_region h (hash_region_of #hsz v)) let hash_r_inv_reg #_ h v = () private noextract val hash_repr (#hsz:hash_size_t): Type0 let hash_repr #hsz = MTH.hash #(U32.v hsz) private noextract val hash_r_repr: #hsz:hash_size_t -> h:HS.mem -> v:hash{hash_r_inv #hsz h v} -> GTot (hash_repr #hsz) let hash_r_repr #_ h v = B.as_seq h v private noextract val hash_r_sep: #hsz:hash_size_t -> v:hash #hsz -> p:loc -> h0:HS.mem -> h1:HS.mem -> Lemma (requires hash_r_inv h0 v /\ loc_disjoint (loc_all_regions_from false (hash_region_of v)) p /\ modifies p h0 h1) (ensures hash_r_inv h1 v /\ hash_r_repr h0 v == hash_r_repr h1 v) let hash_r_sep #_ v p h0 h1 = assert (loc_includes (loc_all_regions_from false (hash_region_of v)) (loc_buffer v)); B.modifies_buffer_elim v p h0 h1 private noextract val hash_irepr: #hsz:hash_size_t -> Ghost.erased (hash_repr #hsz) let hash_irepr #hsz = Ghost.hide (S.create (U32.v hsz) (u8 0)) private noextract val hash_r_alloc_p: #hsz:hash_size_t -> v:hash #hsz -> GTot Type0 let hash_r_alloc_p #_ v = True val hash_r_alloc: #hsz':Ghost.erased hash_size_t -> hsz:hash_size_t { hsz == Ghost.reveal hsz' } -> r:HST.erid -> HST.ST (hash #hsz) (requires (fun h0 -> true)) (ensures (fun h0 v h1 -> Set.subset (Map.domain (MHS.get_hmap h0)) (Map.domain (MHS.get_hmap h1)) /\ modifies loc_none h0 h1 /\ hash_r_alloc_p #hsz v /\ hash_r_inv h1 v /\ hash_region_of v = r /\ hash_r_repr h1 v == Ghost.reveal hash_irepr /\ B.fresh_loc (B.loc_buffer v) h0 h1)) let hash_r_alloc #_ s r = B.malloc r (u8 0) s val hash_r_free: #hsz':Ghost.erased hash_size_t -> hsz:hash_size_t { hsz == Ghost.reveal hsz' } -> v:hash #hsz' -> HST.ST unit (requires fun h0 -> hash_r_inv h0 v) (ensures fun h0 _ h1 -> modifies (loc_all_regions_from false (hash_region_of v)) h0 h1) let hash_r_free #_ _ v = B.free v noextract inline_for_extraction
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "MerkleTree.New.High.fst.checked", "LowStar.Vector.fst.checked", "LowStar.RVector.fst.checked", "LowStar.Regional.Instances.fst.checked", "LowStar.Regional.fst.checked", "LowStar.ConstBuffer.fsti.checked", "LowStar.BufferOps.fst.checked", "LowStar.Buffer.fst.checked", "Lib.IntTypes.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Set.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Monotonic.HyperStack.fsti.checked", "FStar.Monotonic.HyperHeap.fsti.checked", "FStar.Map.fsti.checked", "FStar.Integers.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked", "FStar.All.fst.checked", "EverCrypt.Helpers.fsti.checked", "EverCrypt.Hash.fsti.checked" ], "interface_file": false, "source_file": "MerkleTree.Low.Datastructures.fst" }
[ { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "EverCrypt.Helpers", "short_module": null }, { "abbrev": true, "full_module": "MerkleTree.New.High", "short_module": "MTH" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": true, "full_module": "EverCrypt.Hash", "short_module": "EHS" }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "S" }, { "abbrev": true, "full_module": "LowStar.Regional.Instances", "short_module": "RVI" }, { "abbrev": true, "full_module": "LowStar.RVector", "short_module": "RV" }, { "abbrev": true, "full_module": "LowStar.Vector", "short_module": "V" }, { "abbrev": true, "full_module": "LowStar.ConstBuffer", "short_module": "CB" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.Monotonic.HyperHeap", "short_module": "HH" }, { "abbrev": true, "full_module": "FStar.Monotonic.HyperStack", "short_module": "MHS" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": false, "full_module": "LowStar.Regional.Instances", "short_module": null }, { "abbrev": false, "full_module": "LowStar.RVector", "short_module": null }, { "abbrev": false, "full_module": "LowStar.Regional", "short_module": null }, { "abbrev": false, "full_module": "LowStar.Vector", "short_module": null }, { "abbrev": false, "full_module": "LowStar.BufferOps", "short_module": null }, { "abbrev": false, "full_module": "LowStar.Buffer", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.Integers", "short_module": null }, { "abbrev": false, "full_module": "FStar.All", "short_module": null }, { "abbrev": false, "full_module": "MerkleTree.Low", "short_module": null }, { "abbrev": false, "full_module": "MerkleTree.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": 0, "initial_ifuel": 0, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 10, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
hsz: MerkleTree.Low.Datastructures.hash_size_t -> LowStar.Regional.regional MerkleTree.Low.Datastructures.hash_size_t MerkleTree.Low.Datastructures.hash
Prims.Tot
[ "total" ]
[]
[ "MerkleTree.Low.Datastructures.hash_size_t", "LowStar.Regional.Rgl", "MerkleTree.Low.Datastructures.hash", "MerkleTree.Low.Datastructures.hash_region_of", "LowStar.Monotonic.Buffer.loc_buffer", "Lib.IntTypes.uint8", "LowStar.Buffer.trivial_preorder", "MerkleTree.Low.Datastructures.hash_dummy", "FStar.Ghost.hide", "MerkleTree.Low.Datastructures.hash_r_inv", "MerkleTree.Low.Datastructures.hash_r_inv_reg", "MerkleTree.Low.Datastructures.hash_repr", "MerkleTree.Low.Datastructures.hash_r_repr", "MerkleTree.Low.Datastructures.hash_r_sep", "MerkleTree.Low.Datastructures.hash_irepr", "MerkleTree.Low.Datastructures.hash_r_alloc_p", "MerkleTree.Low.Datastructures.hash_r_alloc", "MerkleTree.Low.Datastructures.hash_r_free", "LowStar.Regional.regional" ]
[]
false
false
false
false
false
let hreg hsz =
Rgl #(hash_size_t) #(hash #hsz) hsz (hash_region_of #hsz) (B.loc_buffer) (hash_dummy #hsz) (hash_r_inv #hsz) (hash_r_inv_reg #hsz) (hash_repr #hsz) (hash_r_repr #hsz) (hash_r_sep #hsz) (hash_irepr #hsz) (hash_r_alloc_p #hsz) (hash_r_alloc #hsz) (hash_r_free #hsz)
false
EverParse3d.InputStream.Buffer.Aux.fst
EverParse3d.InputStream.Buffer.Aux.t
val t : Type0
let t = input_buffer
{ "file_name": "src/3d/prelude/buffer/EverParse3d.InputStream.Buffer.Aux.fst", "git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
{ "end_col": 20, "end_line": 35, "start_col": 0, "start_line": 35 }
module EverParse3d.InputStream.Buffer.Aux (* This module is here to break circularity in KaRaMeL bundles (because Prims must be in the EverParse bundle because of the string type, as opposed to C,FStar,LowStar.) *) module IB = EverParse3d.InputBuffer module IR = EverParse3d.Readable module LP = LowParse.Low.Base module B = LowStar.Buffer module U8 = FStar.UInt8 module U32 = FStar.UInt32 module U64 = FStar.UInt64 module HS = FStar.HyperStack module HST = FStar.HyperStack.ST noeq type input_buffer = { len0: Ghost.erased U32.t; buf: IB.input_buffer_t len0; perm_of: IR.perm (IB.slice_of buf).LP.base; len: Ghost.erased U32.t; pos: B.pointer (Ghost.erased U32.t); g_all_buf: Ghost.erased (Seq.seq U8.t); g_all: Ghost.erased (Seq.seq U8.t); prf: squash ( U32.v len <= U32.v len0 /\ Seq.length g_all == U32.v len /\ B.loc_disjoint (B.loc_buffer (IB.slice_of buf).LP.base `B.loc_union` IR.loc_perm perm_of) (B.loc_buffer pos) /\ Seq.length g_all_buf == U32.v len0 /\ Ghost.reveal g_all == Seq.slice g_all_buf 0 (U32.v len) ); } inline_for_extraction
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowStar.BufferOps.fst.checked", "LowStar.Buffer.fst.checked", "LowParse.Low.Base.fst.checked", "FStar.UInt8.fsti.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked", "EverParse3d.Readable.fsti.checked", "EverParse3d.InputBuffer.fsti.checked", "EverParse3d.ErrorCode.fst.checked" ], "interface_file": false, "source_file": "EverParse3d.InputStream.Buffer.Aux.fst" }
[ { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "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": "LowParse.Low.Base", "short_module": "LP" }, { "abbrev": true, "full_module": "EverParse3d.Readable", "short_module": "IR" }, { "abbrev": true, "full_module": "EverParse3d.InputBuffer", "short_module": "IB" }, { "abbrev": false, "full_module": "EverParse3d.InputStream.Buffer", "short_module": null }, { "abbrev": false, "full_module": "EverParse3d.InputStream.Buffer", "short_module": null }, { "abbrev": 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": 0, "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": [ "smt.qi.eager_threshold=100" ], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 8, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
Type0
Prims.Tot
[ "total" ]
[]
[ "EverParse3d.InputStream.Buffer.Aux.input_buffer" ]
[]
false
false
false
true
true
let t =
input_buffer
false
MerkleTree.Low.Datastructures.fst
MerkleTree.Low.Datastructures.hash_vec_repr
val hash_vec_repr: #hsz:hash_size_t -> Type0
val hash_vec_repr: #hsz:hash_size_t -> Type0
let hash_vec_repr #hsz = MTH.hashes #(U32.v hsz)
{ "file_name": "src/MerkleTree.Low.Datastructures.fst", "git_rev": "7d7bdc20f2033171e279c176b26e84f9069d23c6", "git_url": "https://github.com/hacl-star/merkle-tree.git", "project_name": "merkle-tree" }
{ "end_col": 48, "end_line": 223, "start_col": 0, "start_line": 223 }
module MerkleTree.Low.Datastructures open FStar.All open FStar.Integers open FStar.Mul open LowStar.Buffer open LowStar.BufferOps open LowStar.Vector open LowStar.Regional open LowStar.RVector open LowStar.Regional.Instances module HS = FStar.HyperStack module HST = FStar.HyperStack.ST module MHS = FStar.Monotonic.HyperStack module HH = FStar.Monotonic.HyperHeap module B = LowStar.Buffer module CB = LowStar.ConstBuffer module V = LowStar.Vector module RV = LowStar.RVector module RVI = LowStar.Regional.Instances module S = FStar.Seq module EHS = EverCrypt.Hash module U32 = FStar.UInt32 module MTH = MerkleTree.New.High open EverCrypt.Helpers open Lib.IntTypes #set-options "--z3rlimit 10 --initial_fuel 0 --max_fuel 0 --initial_ifuel 0 --max_ifuel 0" type hash_size_t = n:uint32_t{n > 0ul} type hash (#hsz:hash_size_t) = b:B.buffer uint8 { B.len b = hsz \/ B.g_is_null b } // We cannot use `Low.RVector.Instances`, where we have some general // typeclass instances of `regional`, e.g., if `rg:regional a` then // `regional (rvector rg)`. In FStar we can use this, but KaRaMeL currently // cannot deal with this and gives a number of errors. // So we temporarily instantiate some `regional`s manually below, which is // extractable to C by KaRaMeL. /// Some instantiations of `regional` used in Merkle tree /// 1. `hash` is regional private noextract val hash_region_of: #hsz:hash_size_t -> v:hash #hsz -> GTot HH.rid let hash_region_of #_ v = B.frameOf v private inline_for_extraction val hash_dummy: #hsz:Ghost.erased hash_size_t -> Tot (hash #hsz) let hash_dummy #_ = B.null private noextract val hash_r_inv: #hsz:hash_size_t -> h:HS.mem -> v:hash #hsz -> GTot Type0 let hash_r_inv #hsz h v = B.live h v /\ B.freeable v /\ B.len v = hsz private noextract val hash_r_inv_reg: #hsz:hash_size_t -> h:HS.mem -> v:hash -> Lemma (requires hash_r_inv h v) (ensures MHS.live_region h (hash_region_of #hsz v)) let hash_r_inv_reg #_ h v = () private noextract val hash_repr (#hsz:hash_size_t): Type0 let hash_repr #hsz = MTH.hash #(U32.v hsz) private noextract val hash_r_repr: #hsz:hash_size_t -> h:HS.mem -> v:hash{hash_r_inv #hsz h v} -> GTot (hash_repr #hsz) let hash_r_repr #_ h v = B.as_seq h v private noextract val hash_r_sep: #hsz:hash_size_t -> v:hash #hsz -> p:loc -> h0:HS.mem -> h1:HS.mem -> Lemma (requires hash_r_inv h0 v /\ loc_disjoint (loc_all_regions_from false (hash_region_of v)) p /\ modifies p h0 h1) (ensures hash_r_inv h1 v /\ hash_r_repr h0 v == hash_r_repr h1 v) let hash_r_sep #_ v p h0 h1 = assert (loc_includes (loc_all_regions_from false (hash_region_of v)) (loc_buffer v)); B.modifies_buffer_elim v p h0 h1 private noextract val hash_irepr: #hsz:hash_size_t -> Ghost.erased (hash_repr #hsz) let hash_irepr #hsz = Ghost.hide (S.create (U32.v hsz) (u8 0)) private noextract val hash_r_alloc_p: #hsz:hash_size_t -> v:hash #hsz -> GTot Type0 let hash_r_alloc_p #_ v = True val hash_r_alloc: #hsz':Ghost.erased hash_size_t -> hsz:hash_size_t { hsz == Ghost.reveal hsz' } -> r:HST.erid -> HST.ST (hash #hsz) (requires (fun h0 -> true)) (ensures (fun h0 v h1 -> Set.subset (Map.domain (MHS.get_hmap h0)) (Map.domain (MHS.get_hmap h1)) /\ modifies loc_none h0 h1 /\ hash_r_alloc_p #hsz v /\ hash_r_inv h1 v /\ hash_region_of v = r /\ hash_r_repr h1 v == Ghost.reveal hash_irepr /\ B.fresh_loc (B.loc_buffer v) h0 h1)) let hash_r_alloc #_ s r = B.malloc r (u8 0) s val hash_r_free: #hsz':Ghost.erased hash_size_t -> hsz:hash_size_t { hsz == Ghost.reveal hsz' } -> v:hash #hsz' -> HST.ST unit (requires fun h0 -> hash_r_inv h0 v) (ensures fun h0 _ h1 -> modifies (loc_all_regions_from false (hash_region_of v)) h0 h1) let hash_r_free #_ _ v = B.free v noextract inline_for_extraction val hreg (hsz:hash_size_t): regional (hash_size_t) (hash #hsz) let hreg hsz = Rgl #(hash_size_t) #(hash #hsz) hsz (hash_region_of #hsz) (B.loc_buffer) (hash_dummy #hsz) (hash_r_inv #hsz) (hash_r_inv_reg #hsz) (hash_repr #hsz) (hash_r_repr #hsz) (hash_r_sep #hsz) (hash_irepr #hsz) (hash_r_alloc_p #hsz) (hash_r_alloc #hsz) (hash_r_free #hsz) private val hash_copy: #s':Ghost.erased hash_size_t -> s:hash_size_t { s == Ghost.reveal s' } -> src:hash #s -> dst:hash #s -> HST.ST unit (requires fun h0 -> hash_r_inv h0 src /\ hash_r_inv h0 dst /\ HH.disjoint (hash_region_of src) (hash_region_of dst)) (ensures fun h0 _ h1 -> modifies (loc_all_regions_from false (hash_region_of dst)) h0 h1 /\ hash_r_inv h1 dst /\ hash_r_repr h1 dst == hash_r_repr h0 src) let hash_copy #_ s src dst = B.blit src 0ul dst 0ul s /// JP: so much stuff happening here. First, single-constructor, single-argument /// elimination takes places and Cpy becomes completely eliminated, in favor of /// just being a type alias for the underlying function. So now, we have a /// function that returns a function pointer. /// /// Next, one might think that the hsz argument is going to be eliminated. It's /// not, because there's a hidden implicit argument to Cpy which is (hreg hsz), /// meaning that hsz is used at run-time even though Cpy is only using this /// argument ghostly. This would be have to be fixed. /// /// Finally, if the inline_for_extraction is removed, there seems to be a /// karamel bug that inserts a void*0. To be fixed. inline_for_extraction val hcpy: hsz:hash_size_t -> copyable #hash_size_t (hash #hsz) (hreg hsz) let hcpy hsz = Cpy (hash_copy #hsz) type hash_vec (#hsz:hash_size_t) = RV.rvector (hreg hsz) /// 2. `rvector hash` is regional type rhst (hsz:hash_size_t) = regional hash_size_t (hash #hsz) private noextract val hash_vec_region_of: #hsz:hash_size_t -> v:hash_vec #hsz -> GTot HH.rid let hash_vec_region_of #_ v = V.frameOf v private inline_for_extraction val hash_vec_dummy: (#hsz:Ghost.erased hash_size_t) -> hash_vec #hsz let hash_vec_dummy #_ = V.alloc_empty (hash #_) noextract val hash_vec_r_inv: #hsz:hash_size_t -> h:HS.mem -> v:hash_vec #hsz -> GTot Type0 let hash_vec_r_inv #hsz h v = RV.rv_inv h v noextract val hash_vec_r_inv_reg: #hsz:hash_size_t -> h:HS.mem -> v:hash_vec #hsz -> Lemma (requires (hash_vec_r_inv h v)) (ensures (MHS.live_region h (hash_vec_region_of v))) let hash_vec_r_inv_reg #_ h v = () private noextract
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "MerkleTree.New.High.fst.checked", "LowStar.Vector.fst.checked", "LowStar.RVector.fst.checked", "LowStar.Regional.Instances.fst.checked", "LowStar.Regional.fst.checked", "LowStar.ConstBuffer.fsti.checked", "LowStar.BufferOps.fst.checked", "LowStar.Buffer.fst.checked", "Lib.IntTypes.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Set.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Monotonic.HyperStack.fsti.checked", "FStar.Monotonic.HyperHeap.fsti.checked", "FStar.Map.fsti.checked", "FStar.Integers.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked", "FStar.All.fst.checked", "EverCrypt.Helpers.fsti.checked", "EverCrypt.Hash.fsti.checked" ], "interface_file": false, "source_file": "MerkleTree.Low.Datastructures.fst" }
[ { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "EverCrypt.Helpers", "short_module": null }, { "abbrev": true, "full_module": "MerkleTree.New.High", "short_module": "MTH" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": true, "full_module": "EverCrypt.Hash", "short_module": "EHS" }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "S" }, { "abbrev": true, "full_module": "LowStar.Regional.Instances", "short_module": "RVI" }, { "abbrev": true, "full_module": "LowStar.RVector", "short_module": "RV" }, { "abbrev": true, "full_module": "LowStar.Vector", "short_module": "V" }, { "abbrev": true, "full_module": "LowStar.ConstBuffer", "short_module": "CB" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.Monotonic.HyperHeap", "short_module": "HH" }, { "abbrev": true, "full_module": "FStar.Monotonic.HyperStack", "short_module": "MHS" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": false, "full_module": "LowStar.Regional.Instances", "short_module": null }, { "abbrev": false, "full_module": "LowStar.RVector", "short_module": null }, { "abbrev": false, "full_module": "LowStar.Regional", "short_module": null }, { "abbrev": false, "full_module": "LowStar.Vector", "short_module": null }, { "abbrev": false, "full_module": "LowStar.BufferOps", "short_module": null }, { "abbrev": false, "full_module": "LowStar.Buffer", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.Integers", "short_module": null }, { "abbrev": false, "full_module": "FStar.All", "short_module": null }, { "abbrev": false, "full_module": "MerkleTree.Low", "short_module": null }, { "abbrev": false, "full_module": "MerkleTree.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": 0, "initial_ifuel": 0, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 10, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
Type0
Prims.Tot
[ "total" ]
[]
[ "MerkleTree.Low.Datastructures.hash_size_t", "MerkleTree.New.High.hashes", "FStar.UInt32.v" ]
[]
false
false
false
true
true
let hash_vec_repr #hsz =
MTH.hashes #(U32.v hsz)
false
MerkleTree.New.High.Correct.Rhs.fst
MerkleTree.New.High.Correct.Rhs.construct_rhs_acc_inv_ok
val construct_rhs_acc_inv_ok: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> j:nat{j > 0} -> fhs:hashess #hsz { S.length fhs = log2c j /\ mt_hashes_lth_inv_log #hsz j fhs /\ mt_hashes_inv_log #_ #f j fhs} -> acc:hash #hsz -> actd:bool -> Lemma (requires True) (ensures (let crhs = construct_rhs_acc #_ #f j fhs acc actd in mt_rhs_inv #_ #f j (hash_seq_spec_full #_ #f (S.head fhs) acc actd) (fst crhs) actd /\ MTS.mt_get_root #_ #f #(log2c j) (hash_seq_spec_full #_ #f (S.head fhs) acc actd) == MTS.HRaw (snd crhs))) (decreases j)
val construct_rhs_acc_inv_ok: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> j:nat{j > 0} -> fhs:hashess #hsz { S.length fhs = log2c j /\ mt_hashes_lth_inv_log #hsz j fhs /\ mt_hashes_inv_log #_ #f j fhs} -> acc:hash #hsz -> actd:bool -> Lemma (requires True) (ensures (let crhs = construct_rhs_acc #_ #f j fhs acc actd in mt_rhs_inv #_ #f j (hash_seq_spec_full #_ #f (S.head fhs) acc actd) (fst crhs) actd /\ MTS.mt_get_root #_ #f #(log2c j) (hash_seq_spec_full #_ #f (S.head fhs) acc actd) == MTS.HRaw (snd crhs))) (decreases j)
let rec construct_rhs_acc_inv_ok #hsz #f j fhs acc actd = if j = 1 then construct_rhs_acc_inv_ok_0 #_ #f fhs acc actd else if j % 2 = 0 then begin construct_rhs_acc_inv_ok #_ #f (j / 2) (S.tail fhs) acc actd; let rcrhs = construct_rhs_acc #_ #f (j / 2) (S.tail fhs) acc actd in assert (mt_rhs_inv #_ #f (j / 2) (hash_seq_spec_full #_ #f (S.head (S.tail fhs)) acc actd) (fst rcrhs) actd); assert (MTS.mt_get_root #_ #f #(log2c j - 1) (hash_seq_spec_full #_ #f (S.head (S.tail fhs)) acc actd) == MTS.HRaw (snd rcrhs)); let crhs = (S.cons hash_init (fst rcrhs), snd rcrhs) in mt_hashes_lth_inv_log_next #_ #f j fhs; hash_seq_spec_full_even_next #_ #f j (S.head fhs) (S.head (S.tail fhs)) acc actd; assert (mt_rhs_inv #_ #f (j / 2) (MTS.mt_next_lv #_ #f #(log2c j) (hash_seq_spec_full #_ #f (S.head fhs) acc actd)) (fst rcrhs) actd); assert (mt_rhs_inv #_ #f j (hash_seq_spec_full #_ #f (S.head fhs) acc actd) (fst crhs) actd); assert (MTS.mt_get_root #_ #f #(log2c j) (hash_seq_spec_full #_ #f (S.head fhs) acc actd) == MTS.HRaw (snd rcrhs)) end else begin let rhd = if actd then acc else hash_init #hsz in let nacc = if actd then f (S.last (S.head fhs)) acc else S.last (S.head fhs) in construct_rhs_acc_inv_ok #_ #f (j / 2) (S.tail fhs) nacc true; let rcrhs = construct_rhs_acc #_ #f (j / 2) (S.tail fhs) nacc true in assert (mt_rhs_inv #_ #f (j / 2) (hash_seq_spec_full #_ #f (S.head (S.tail fhs)) nacc true) (fst rcrhs) true); assert (MTS.mt_get_root #_ #f #(log2c j - 1) (hash_seq_spec_full #_ #f (S.head (S.tail fhs)) nacc true) == MTS.HRaw (snd rcrhs)); let crhs = (S.cons rhd (fst rcrhs), snd rcrhs) in mt_hashes_lth_inv_log_next #_ #f j fhs; hash_seq_spec_full_odd_next #_ #f j (S.head fhs) (S.head (S.tail fhs)) acc actd nacc; (if actd then hash_seq_spec_full_case_true #_ #f (S.head fhs) acc); assert (if actd then (S.index (hash_seq_spec_full #_ #f (S.head fhs) acc actd) j == MTS.HRaw rhd) else true); assert (mt_rhs_inv #_ #f (j / 2) (MTS.mt_next_lv #_ #f #(log2c j) (hash_seq_spec_full #_ #f (S.head fhs) acc actd)) (fst rcrhs) true); assert (mt_rhs_inv #_ #f j (hash_seq_spec_full #_ #f (S.head fhs) acc actd) (fst crhs) actd); assert (MTS.mt_get_root #_ #f #(log2c j) (hash_seq_spec_full #_ #f (S.head fhs) acc actd) == MTS.HRaw (snd crhs)) end
{ "file_name": "src/MerkleTree.New.High.Correct.Rhs.fst", "git_rev": "7d7bdc20f2033171e279c176b26e84f9069d23c6", "git_url": "https://github.com/hacl-star/merkle-tree.git", "project_name": "merkle-tree" }
{ "end_col": 5, "end_line": 168, "start_col": 0, "start_line": 104 }
module MerkleTree.New.High.Correct.Rhs open FStar.Classical open FStar.Ghost open FStar.Seq module S = FStar.Seq module MTS = MerkleTree.Spec open MerkleTree.New.High open MerkleTree.New.High.Correct.Base #set-options "--z3rlimit 10 --initial_fuel 1 --max_fuel 1 --initial_ifuel 0 --max_ifuel 0" /// Correctness of rightmost hashes // Another version of `construct_rhs` that recursively // accumulates rightmost hashes. val construct_rhs_acc: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> j:nat -> fhs:hashess #hsz { S.length fhs = log2c j /\ mt_hashes_lth_inv_log #hsz j fhs} -> acc:hash #hsz -> actd:bool -> GTot (rhs:hashes #hsz {S.length rhs = log2c j} * hash #hsz) (decreases j) let rec construct_rhs_acc #_ #f j fhs acc actd = if j = 0 then (S.empty, acc) else begin if j % 2 = 0 then (let nrhsh = construct_rhs_acc #_ #f(j / 2) (S.tail fhs) acc actd in (S.cons hash_init (fst nrhsh), snd nrhsh)) else (let rhd = if actd then acc else hash_init in let nacc = if actd then f (S.last (S.head fhs)) acc else S.last (S.head fhs) in let nrhsh = construct_rhs_acc #_ #f (j / 2) (S.tail fhs) nacc true in (S.cons rhd (fst nrhsh), snd nrhsh)) end #push-options "--initial_ifuel 1 --max_ifuel 1" val construct_rhs_acc_odd: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> j:nat -> fhs:hashess #hsz { S.length fhs = log2c j /\ mt_hashes_lth_inv_log #hsz j fhs} -> acc:hash #hsz -> actd:bool -> Lemma (requires (j % 2 <> 0)) (ensures (let rrf = construct_rhs_acc #_ #f j fhs acc actd in let nacc = if actd then f (S.last (S.head fhs)) acc else S.last (S.head fhs) in let nrrf = construct_rhs_acc #_ #f (j / 2) (S.tail fhs) nacc true in S.equal (S.tail (fst rrf)) (fst nrrf) /\ snd rrf == snd nrrf)) let construct_rhs_acc_odd #_ #f j fhs acc actd = () #pop-options #push-options "--initial_fuel 2 --max_fuel 2" val construct_rhs_acc_inv_ok_0: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> fhs:hashess #hsz { S.length fhs = 1 /\ mt_hashes_lth_inv_log #hsz 1 fhs /\ mt_hashes_inv_log #_ #f 1 fhs} -> acc:hash #hsz -> actd:bool -> Lemma (requires True) (ensures (let crhs = construct_rhs_acc #_ #f 1 fhs acc actd in mt_rhs_inv #_ #f 1 (hash_seq_spec_full #_ #f (S.head fhs) acc actd) (fst crhs) actd /\ MTS.mt_get_root #_ #f #1 (hash_seq_spec_full #_ #f (S.head fhs) acc actd) == MTS.HRaw #hsz (snd crhs))) let construct_rhs_acc_inv_ok_0 #_ #f fhs acc actd = () #pop-options #push-options "--z3rlimit 300" #restart-solver val construct_rhs_acc_inv_ok: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> j:nat{j > 0} -> fhs:hashess #hsz { S.length fhs = log2c j /\ mt_hashes_lth_inv_log #hsz j fhs /\ mt_hashes_inv_log #_ #f j fhs} -> acc:hash #hsz -> actd:bool -> Lemma (requires True) (ensures (let crhs = construct_rhs_acc #_ #f j fhs acc actd in mt_rhs_inv #_ #f j (hash_seq_spec_full #_ #f (S.head fhs) acc actd) (fst crhs) actd /\ MTS.mt_get_root #_ #f #(log2c j) (hash_seq_spec_full #_ #f (S.head fhs) acc actd) == MTS.HRaw (snd crhs)))
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "MerkleTree.Spec.fst.checked", "MerkleTree.New.High.Correct.Base.fst.checked", "MerkleTree.New.High.fst.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Ghost.fsti.checked", "FStar.Classical.fsti.checked" ], "interface_file": false, "source_file": "MerkleTree.New.High.Correct.Rhs.fst" }
[ { "abbrev": false, "full_module": "MerkleTree.New.High.Correct.Base", "short_module": null }, { "abbrev": false, "full_module": "MerkleTree.New.High", "short_module": null }, { "abbrev": true, "full_module": "MerkleTree.Spec", "short_module": "MTS" }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "S" }, { "abbrev": false, "full_module": "FStar.Seq", "short_module": null }, { "abbrev": false, "full_module": "FStar.Ghost", "short_module": null }, { "abbrev": false, "full_module": "FStar.Classical", "short_module": null }, { "abbrev": false, "full_module": "MerkleTree.New.High.Correct", "short_module": null }, { "abbrev": false, "full_module": "MerkleTree.New.High.Correct", "short_module": null }, { "abbrev": 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": 1, "initial_ifuel": 0, "max_fuel": 1, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 300, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
j: Prims.nat{j > 0} -> fhs: MerkleTree.New.High.hashess { FStar.Seq.Base.length fhs = MerkleTree.New.High.Correct.Base.log2c j /\ MerkleTree.New.High.Correct.Base.mt_hashes_lth_inv_log j fhs /\ MerkleTree.New.High.Correct.Base.mt_hashes_inv_log j fhs } -> acc: MerkleTree.New.High.hash -> actd: Prims.bool -> FStar.Pervasives.Lemma (ensures (let crhs = MerkleTree.New.High.Correct.Rhs.construct_rhs_acc j fhs acc actd in MerkleTree.New.High.Correct.Base.mt_rhs_inv j (MerkleTree.New.High.Correct.Base.hash_seq_spec_full (FStar.Seq.Properties.head fhs) acc actd) (FStar.Pervasives.Native.fst crhs) actd /\ MerkleTree.Spec.mt_get_root (MerkleTree.New.High.Correct.Base.hash_seq_spec_full (FStar.Seq.Properties.head fhs) acc actd) == MerkleTree.Spec.HRaw (FStar.Pervasives.Native.snd crhs))) (decreases j)
FStar.Pervasives.Lemma
[ "lemma", "" ]
[]
[ "Prims.pos", "MerkleTree.Spec.hash_fun_t", "Prims.nat", "Prims.b2t", "Prims.op_GreaterThan", "MerkleTree.New.High.hashess", "Prims.l_and", "Prims.op_Equality", "FStar.Seq.Base.length", "MerkleTree.New.High.hashes", "MerkleTree.New.High.Correct.Base.log2c", "MerkleTree.New.High.Correct.Base.mt_hashes_lth_inv_log", "MerkleTree.New.High.Correct.Base.mt_hashes_inv_log", "MerkleTree.New.High.hash", "Prims.bool", "Prims.int", "MerkleTree.New.High.Correct.Rhs.construct_rhs_acc_inv_ok_0", "Prims.op_Modulus", "Prims._assert", "Prims.eq2", "MerkleTree.Spec.padded_hash", "MerkleTree.Spec.mt_get_root", "MerkleTree.New.High.Correct.Base.hash_seq_spec_full", "FStar.Seq.Properties.head", "MerkleTree.Spec.HRaw", "FStar.Pervasives.Native.snd", "Prims.op_Division", "Prims.unit", "MerkleTree.New.High.Correct.Base.mt_rhs_inv", "FStar.Pervasives.Native.fst", "MerkleTree.Spec.mt_next_lv", "MerkleTree.New.High.Correct.Base.hash_seq_spec_full_even_next", "FStar.Seq.Properties.tail", "MerkleTree.New.High.Correct.Base.mt_hashes_lth_inv_log_next", "FStar.Pervasives.Native.tuple2", "FStar.Pervasives.Native.Mktuple2", "FStar.Seq.Base.cons", "MerkleTree.New.High.hash_init", "Prims.op_Subtraction", "MerkleTree.New.High.Correct.Rhs.construct_rhs_acc", "MerkleTree.New.High.Correct.Rhs.construct_rhs_acc_inv_ok", "MerkleTree.Spec.hash", "FStar.Seq.Base.index", "MerkleTree.New.High.Correct.Base.hash_seq_spec_full_case_true", "MerkleTree.New.High.Correct.Base.hash_seq_spec_full_odd_next", "FStar.Seq.Properties.last", "Spec.Hash.Definitions.bytes", "Prims.l_or", "Prims.op_GreaterThanOrEqual", "Lib.IntTypes.int_t", "Lib.IntTypes.U8", "Lib.IntTypes.SEC", "Lib.IntTypes.uint8" ]
[ "recursion" ]
false
false
true
false
false
let rec construct_rhs_acc_inv_ok #hsz #f j fhs acc actd =
if j = 1 then construct_rhs_acc_inv_ok_0 #_ #f fhs acc actd else if j % 2 = 0 then (construct_rhs_acc_inv_ok #_ #f (j / 2) (S.tail fhs) acc actd; let rcrhs = construct_rhs_acc #_ #f (j / 2) (S.tail fhs) acc actd in assert (mt_rhs_inv #_ #f (j / 2) (hash_seq_spec_full #_ #f (S.head (S.tail fhs)) acc actd) (fst rcrhs) actd); assert (MTS.mt_get_root #_ #f #(log2c j - 1) (hash_seq_spec_full #_ #f (S.head (S.tail fhs)) acc actd) == MTS.HRaw (snd rcrhs)); let crhs = (S.cons hash_init (fst rcrhs), snd rcrhs) in mt_hashes_lth_inv_log_next #_ #f j fhs; hash_seq_spec_full_even_next #_ #f j (S.head fhs) (S.head (S.tail fhs)) acc actd; assert (mt_rhs_inv #_ #f (j / 2) (MTS.mt_next_lv #_ #f #(log2c j) (hash_seq_spec_full #_ #f (S.head fhs) acc actd)) (fst rcrhs) actd); assert (mt_rhs_inv #_ #f j (hash_seq_spec_full #_ #f (S.head fhs) acc actd) (fst crhs) actd); assert (MTS.mt_get_root #_ #f #(log2c j) (hash_seq_spec_full #_ #f (S.head fhs) acc actd) == MTS.HRaw (snd rcrhs))) else let rhd = if actd then acc else hash_init #hsz in let nacc = if actd then f (S.last (S.head fhs)) acc else S.last (S.head fhs) in construct_rhs_acc_inv_ok #_ #f (j / 2) (S.tail fhs) nacc true; let rcrhs = construct_rhs_acc #_ #f (j / 2) (S.tail fhs) nacc true in assert (mt_rhs_inv #_ #f (j / 2) (hash_seq_spec_full #_ #f (S.head (S.tail fhs)) nacc true) (fst rcrhs) true); assert (MTS.mt_get_root #_ #f #(log2c j - 1) (hash_seq_spec_full #_ #f (S.head (S.tail fhs)) nacc true) == MTS.HRaw (snd rcrhs)); let crhs = (S.cons rhd (fst rcrhs), snd rcrhs) in mt_hashes_lth_inv_log_next #_ #f j fhs; hash_seq_spec_full_odd_next #_ #f j (S.head fhs) (S.head (S.tail fhs)) acc actd nacc; (if actd then hash_seq_spec_full_case_true #_ #f (S.head fhs) acc); assert (if actd then (S.index (hash_seq_spec_full #_ #f (S.head fhs) acc actd) j == MTS.HRaw rhd) else true); assert (mt_rhs_inv #_ #f (j / 2) (MTS.mt_next_lv #_ #f #(log2c j) (hash_seq_spec_full #_ #f (S.head fhs) acc actd)) (fst rcrhs) true); assert (mt_rhs_inv #_ #f j (hash_seq_spec_full #_ #f (S.head fhs) acc actd) (fst crhs) actd); assert (MTS.mt_get_root #_ #f #(log2c j) (hash_seq_spec_full #_ #f (S.head fhs) acc actd) == MTS.HRaw (snd crhs))
false
LowParse.Low.BCVLI.fst
LowParse.Low.BCVLI.serialize32_bcvli'
val serialize32_bcvli' (x: U32.t) (#rrel #rel: _) (b: B.mbuffer U8.t rrel rel) (pos: U32.t) : HST.Stack U32.t (requires (fun h -> let len = Seq.length (serialize serialize_bcvli x) in B.live h b /\ U32.v pos + len <= B.length b /\ writable b (U32.v pos) (U32.v pos + len) h)) (ensures (fun h len h' -> Seq.length (serialize serialize_bcvli x) == U32.v len /\ (B.modifies (B.loc_buffer_from_to b pos (pos `U32.add` len)) h h' /\ B.live h b /\ (Seq.slice (B.as_seq h' b) (U32.v pos) (U32.v pos + U32.v len)) `Seq.equal` (serialize serialize_bcvli x))))
val serialize32_bcvli' (x: U32.t) (#rrel #rel: _) (b: B.mbuffer U8.t rrel rel) (pos: U32.t) : HST.Stack U32.t (requires (fun h -> let len = Seq.length (serialize serialize_bcvli x) in B.live h b /\ U32.v pos + len <= B.length b /\ writable b (U32.v pos) (U32.v pos + len) h)) (ensures (fun h len h' -> Seq.length (serialize serialize_bcvli x) == U32.v len /\ (B.modifies (B.loc_buffer_from_to b pos (pos `U32.add` len)) h h' /\ B.live h b /\ (Seq.slice (B.as_seq h' b) (U32.v pos) (U32.v pos + U32.v len)) `Seq.equal` (serialize serialize_bcvli x))))
let serialize32_bcvli' (x: U32.t) (#rrel #rel: _) (b: B.mbuffer U8.t rrel rel) (pos: U32.t) : HST.Stack U32.t (requires (fun h -> let len = Seq.length (serialize serialize_bcvli x) in B.live h b /\ U32.v pos + len <= B.length b /\ writable b (U32.v pos) (U32.v pos + len) h )) (ensures (fun h len h' -> Seq.length (serialize serialize_bcvli x) == U32.v len /\ ( B.modifies (B.loc_buffer_from_to b pos (pos `U32.add` len)) h h' /\ B.live h b /\ Seq.slice (B.as_seq h' b) (U32.v pos) (U32.v pos + U32.v len) `Seq.equal` serialize serialize_bcvli x ))) = // [@inline_let] let _ = serialize_bcvli_eq x ; // in let c : bounded_integer 1 = if x `U32.lt` 253ul then x else if x `U32.lt` 65536ul then 253ul else 254ul in [@inline_let] let pos' = Ghost.hide (U32.v pos + Seq.length (serialize serialize_bcvli x)) in let h = HST.get () in [@inline_let] let _ = writable_weaken b (U32.v pos) (Ghost.reveal pos') h (U32.v pos) (U32.v pos + 1) in let len1 = serialize32_bounded_integer_le_1 c b pos in let h1 = HST.get () in [@inline_let] let _ = writable_modifies b (U32.v pos) (Ghost.reveal pos') h B.loc_none h1 in if c `U32.lt` 253ul then begin len1 end else if c = 253ul then begin [@inline_let] let _ = assert (U32.v x < 65536) in [@inline_let] let _ = writable_weaken b (U32.v pos) (Ghost.reveal pos') h1 (U32.v pos + U32.v len1) ((U32.v pos + U32.v len1) + 2) in let len2 = serialize32_bounded_integer_le_2 x b (pos `U32.add` len1) in let h' = HST.get () in [@inline_let] let len = len1 `U32.add` len2 in B.modifies_buffer_from_to_elim b pos (pos `U32.add` len1) (B.loc_buffer_from_to b (pos `U32.add` len1) (pos `U32.add` len)) h1 h'; len end else begin [@inline_let] let _ = writable_weaken b (U32.v pos) (Ghost.reveal pos') h1 (U32.v pos + U32.v len1) ((U32.v pos + U32.v len1) + 4) in let len2 = serialize32_bounded_integer_le_4 x b (pos `U32.add` len1) in let h' = HST.get () in [@inline_let] let len = len1 `U32.add` len2 in B.modifies_buffer_from_to_elim b pos (pos `U32.add` len1) (B.loc_buffer_from_to b (pos `U32.add` len1) (pos `U32.add` len)) h1 h'; len end
{ "file_name": "src/lowparse/LowParse.Low.BCVLI.fst", "git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
{ "end_col": 5, "end_line": 170, "start_col": 0, "start_line": 109 }
module LowParse.Low.BCVLI include LowParse.Spec.BCVLI include LowParse.Low.Combinators include LowParse.Low.BoundedInt module B = LowStar.Buffer module HST = FStar.HyperStack.ST module Cast = FStar.Int.Cast module U32 = FStar.UInt32 module U64 = FStar.UInt64 #reset-options "--z3cliopt smt.arith.nl=false --max_fuel 0" #push-options "--z3rlimit 16" let validate_bcvli : validator parse_bcvli = fun #rrel #rel input pos -> let h = HST.get () in [@inline_let] let _ = valid_facts parse_bcvli h input (uint64_to_uint32 pos); parse_bcvli_eq (bytes_of_slice_from h input (uint64_to_uint32 pos)); valid_facts (parse_bounded_integer_le 1) h input (uint64_to_uint32 pos) in let pos1 = validate_total_constant_size (parse_bounded_integer_le 1) 1uL () input pos in if is_error pos1 then pos1 else [@inline_let] let _ = valid_facts (parse_bounded_integer_le 2) h input (uint64_to_uint32 pos1); valid_facts (parse_bounded_integer_le 4) h input (uint64_to_uint32 pos1) in let r = read_bounded_integer_le_1 input (uint64_to_uint32 pos) in if r `U32.lt` 253ul then pos1 else if r = 253ul then let pos2 = validate_total_constant_size (parse_bounded_integer_le 2) 2uL () input pos1 in if is_error pos2 then pos2 else (* because of the non-malleability constraint, I need to actually read the value and check whether it is not a lower integer *) let r = read_bounded_integer_le_2 input (uint64_to_uint32 pos1) in if r `U32.lt` 253ul then validator_error_generic else pos2 else if r = 254ul then let pos2 = validate_total_constant_size (parse_bounded_integer_le 4) 4uL () input pos1 in if is_error pos2 then pos2 else (* because of the non-malleability constraint, I need to actually read the value and check whether it is not a lower integer *) let r = read_bounded_integer_le_4 input (uint64_to_uint32 pos1) in if r `U32.lt` 65536ul then validator_error_generic else pos2 else validator_error_generic let jump_bcvli : jumper parse_bcvli = fun #rrel #rel input pos -> let h = HST.get () in [@inline_let] let _ = valid_facts parse_bcvli h input pos; parse_bcvli_eq (bytes_of_slice_from h input pos); valid_facts (parse_bounded_integer_le 1) h input pos in let pos1 = jump_constant_size (parse_bounded_integer_le 1) 1ul () input pos in [@inline_let] let _ = valid_facts (parse_bounded_integer_le 2) h input pos1; valid_facts (parse_bounded_integer_le 4) h input pos1 in let r = read_bounded_integer_le_1 input pos in if r `U32.lt` 253ul then pos1 else if r = 253ul then jump_constant_size (parse_bounded_integer_le 2) 2ul () input pos1 else jump_constant_size (parse_bounded_integer_le 4) 4ul () input pos1 let read_bcvli : leaf_reader parse_bcvli = fun #rrel #rel input pos -> let h = HST.get () in [@inline_let] let _ = valid_facts parse_bcvli h input pos; parse_bcvli_eq (bytes_of_slice_from h input pos); valid_facts (parse_bounded_integer_le 1) h input pos in let r = read_bounded_integer_le_1 input pos in if r `U32.lt` 253ul then (r <: U32.t) else let pos1 = jump_constant_size (parse_bounded_integer_le 1) 1ul () input pos in [@inline_let] let _ = valid_facts (parse_bounded_integer_le 2) h input pos1; valid_facts (parse_bounded_integer_le 4) h input pos1 in if r = 253ul then read_bounded_integer_le_2 input pos1 <: U32.t else read_bounded_integer_le_4 input pos1 <: U32.t #pop-options module U8 = FStar.UInt8 #push-options "--z3rlimit 32"
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowStar.Buffer.fst.checked", "LowParse.Spec.BCVLI.fsti.checked", "LowParse.Low.Combinators.fsti.checked", "LowParse.Low.BoundedInt.fsti.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.Ghost.fsti.checked" ], "interface_file": false, "source_file": "LowParse.Low.BCVLI.fst" }
[ { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": true, "full_module": "FStar.Int.Cast", "short_module": "Cast" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": false, "full_module": "LowParse.Low.BoundedInt", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low.Combinators", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec.BCVLI", "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": 0, "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": [ "smt.arith.nl=false" ], "z3refresh": false, "z3rlimit": 32, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
x: FStar.UInt32.t -> b: LowStar.Monotonic.Buffer.mbuffer FStar.UInt8.t rrel rel -> pos: FStar.UInt32.t -> FStar.HyperStack.ST.Stack FStar.UInt32.t
FStar.HyperStack.ST.Stack
[]
[]
[ "FStar.UInt32.t", "LowStar.Monotonic.Buffer.srel", "FStar.UInt8.t", "LowStar.Monotonic.Buffer.mbuffer", "FStar.UInt32.lt", "FStar.UInt32.__uint_to_t", "Prims.bool", "Prims.op_Equality", "Prims.unit", "LowStar.Monotonic.Buffer.modifies_buffer_from_to_elim", "FStar.UInt32.add", "LowStar.Monotonic.Buffer.loc_buffer_from_to", "FStar.Monotonic.HyperStack.mem", "FStar.HyperStack.ST.get", "LowParse.Low.BoundedInt.serialize32_bounded_integer_le_2", "LowParse.Low.Base.writable_weaken", "FStar.UInt32.v", "FStar.Ghost.reveal", "Prims.nat", "Prims.op_Addition", "Prims._assert", "Prims.b2t", "Prims.op_LessThan", "LowParse.Low.BoundedInt.serialize32_bounded_integer_le_4", "LowParse.Low.Base.writable_modifies", "LowStar.Monotonic.Buffer.loc_none", "LowParse.Low.BoundedInt.serialize32_bounded_integer_le_1", "FStar.Ghost.erased", "FStar.Ghost.hide", "FStar.Seq.Base.length", "LowParse.Bytes.byte", "LowParse.Spec.Base.serialize", "LowParse.Spec.BCVLI.parse_bcvli_kind", "LowParse.Spec.BCVLI.parse_bcvli", "LowParse.Spec.BCVLI.serialize_bcvli", "LowParse.Spec.BoundedInt.bounded_integer", "LowParse.Spec.BCVLI.serialize_bcvli_eq", "Prims.l_and", "LowStar.Monotonic.Buffer.live", "Prims.op_LessThanOrEqual", "LowStar.Monotonic.Buffer.length", "LowParse.Low.Base.writable", "Prims.eq2", "Prims.int", "Prims.l_or", "Prims.op_GreaterThanOrEqual", "FStar.UInt.size", "FStar.UInt32.n", "LowStar.Monotonic.Buffer.modifies", "FStar.Seq.Base.equal", "FStar.Seq.Base.slice", "LowStar.Monotonic.Buffer.as_seq" ]
[]
false
true
false
false
false
let serialize32_bcvli' (x: U32.t) (#rrel #rel: _) (b: B.mbuffer U8.t rrel rel) (pos: U32.t) : HST.Stack U32.t (requires (fun h -> let len = Seq.length (serialize serialize_bcvli x) in B.live h b /\ U32.v pos + len <= B.length b /\ writable b (U32.v pos) (U32.v pos + len) h)) (ensures (fun h len h' -> Seq.length (serialize serialize_bcvli x) == U32.v len /\ (B.modifies (B.loc_buffer_from_to b pos (pos `U32.add` len)) h h' /\ B.live h b /\ (Seq.slice (B.as_seq h' b) (U32.v pos) (U32.v pos + U32.v len)) `Seq.equal` (serialize serialize_bcvli x)))) =
serialize_bcvli_eq x; let c:bounded_integer 1 = if x `U32.lt` 253ul then x else if x `U32.lt` 65536ul then 253ul else 254ul in [@@ inline_let ]let pos' = Ghost.hide (U32.v pos + Seq.length (serialize serialize_bcvli x)) in let h = HST.get () in [@@ inline_let ]let _ = writable_weaken b (U32.v pos) (Ghost.reveal pos') h (U32.v pos) (U32.v pos + 1) in let len1 = serialize32_bounded_integer_le_1 c b pos in let h1 = HST.get () in [@@ inline_let ]let _ = writable_modifies b (U32.v pos) (Ghost.reveal pos') h B.loc_none h1 in if c `U32.lt` 253ul then len1 else if c = 253ul then [@@ inline_let ]let _ = assert (U32.v x < 65536) in [@@ inline_let ]let _ = writable_weaken b (U32.v pos) (Ghost.reveal pos') h1 (U32.v pos + U32.v len1) ((U32.v pos + U32.v len1) + 2) in let len2 = serialize32_bounded_integer_le_2 x b (pos `U32.add` len1) in let h' = HST.get () in [@@ inline_let ]let len = len1 `U32.add` len2 in B.modifies_buffer_from_to_elim b pos (pos `U32.add` len1) (B.loc_buffer_from_to b (pos `U32.add` len1) (pos `U32.add` len)) h1 h'; len else [@@ inline_let ]let _ = writable_weaken b (U32.v pos) (Ghost.reveal pos') h1 (U32.v pos + U32.v len1) ((U32.v pos + U32.v len1) + 4) in let len2 = serialize32_bounded_integer_le_4 x b (pos `U32.add` len1) in let h' = HST.get () in [@@ inline_let ]let len = len1 `U32.add` len2 in B.modifies_buffer_from_to_elim b pos (pos `U32.add` len1) (B.loc_buffer_from_to b (pos `U32.add` len1) (pos `U32.add` len)) h1 h'; len
false
MerkleTree.Low.Datastructures.fst
MerkleTree.Low.Datastructures.hcpy
val hcpy: hsz:hash_size_t -> copyable #hash_size_t (hash #hsz) (hreg hsz)
val hcpy: hsz:hash_size_t -> copyable #hash_size_t (hash #hsz) (hreg hsz)
let hcpy hsz = Cpy (hash_copy #hsz)
{ "file_name": "src/MerkleTree.Low.Datastructures.fst", "git_rev": "7d7bdc20f2033171e279c176b26e84f9069d23c6", "git_url": "https://github.com/hacl-star/merkle-tree.git", "project_name": "merkle-tree" }
{ "end_col": 22, "end_line": 191, "start_col": 0, "start_line": 190 }
module MerkleTree.Low.Datastructures open FStar.All open FStar.Integers open FStar.Mul open LowStar.Buffer open LowStar.BufferOps open LowStar.Vector open LowStar.Regional open LowStar.RVector open LowStar.Regional.Instances module HS = FStar.HyperStack module HST = FStar.HyperStack.ST module MHS = FStar.Monotonic.HyperStack module HH = FStar.Monotonic.HyperHeap module B = LowStar.Buffer module CB = LowStar.ConstBuffer module V = LowStar.Vector module RV = LowStar.RVector module RVI = LowStar.Regional.Instances module S = FStar.Seq module EHS = EverCrypt.Hash module U32 = FStar.UInt32 module MTH = MerkleTree.New.High open EverCrypt.Helpers open Lib.IntTypes #set-options "--z3rlimit 10 --initial_fuel 0 --max_fuel 0 --initial_ifuel 0 --max_ifuel 0" type hash_size_t = n:uint32_t{n > 0ul} type hash (#hsz:hash_size_t) = b:B.buffer uint8 { B.len b = hsz \/ B.g_is_null b } // We cannot use `Low.RVector.Instances`, where we have some general // typeclass instances of `regional`, e.g., if `rg:regional a` then // `regional (rvector rg)`. In FStar we can use this, but KaRaMeL currently // cannot deal with this and gives a number of errors. // So we temporarily instantiate some `regional`s manually below, which is // extractable to C by KaRaMeL. /// Some instantiations of `regional` used in Merkle tree /// 1. `hash` is regional private noextract val hash_region_of: #hsz:hash_size_t -> v:hash #hsz -> GTot HH.rid let hash_region_of #_ v = B.frameOf v private inline_for_extraction val hash_dummy: #hsz:Ghost.erased hash_size_t -> Tot (hash #hsz) let hash_dummy #_ = B.null private noextract val hash_r_inv: #hsz:hash_size_t -> h:HS.mem -> v:hash #hsz -> GTot Type0 let hash_r_inv #hsz h v = B.live h v /\ B.freeable v /\ B.len v = hsz private noextract val hash_r_inv_reg: #hsz:hash_size_t -> h:HS.mem -> v:hash -> Lemma (requires hash_r_inv h v) (ensures MHS.live_region h (hash_region_of #hsz v)) let hash_r_inv_reg #_ h v = () private noextract val hash_repr (#hsz:hash_size_t): Type0 let hash_repr #hsz = MTH.hash #(U32.v hsz) private noextract val hash_r_repr: #hsz:hash_size_t -> h:HS.mem -> v:hash{hash_r_inv #hsz h v} -> GTot (hash_repr #hsz) let hash_r_repr #_ h v = B.as_seq h v private noextract val hash_r_sep: #hsz:hash_size_t -> v:hash #hsz -> p:loc -> h0:HS.mem -> h1:HS.mem -> Lemma (requires hash_r_inv h0 v /\ loc_disjoint (loc_all_regions_from false (hash_region_of v)) p /\ modifies p h0 h1) (ensures hash_r_inv h1 v /\ hash_r_repr h0 v == hash_r_repr h1 v) let hash_r_sep #_ v p h0 h1 = assert (loc_includes (loc_all_regions_from false (hash_region_of v)) (loc_buffer v)); B.modifies_buffer_elim v p h0 h1 private noextract val hash_irepr: #hsz:hash_size_t -> Ghost.erased (hash_repr #hsz) let hash_irepr #hsz = Ghost.hide (S.create (U32.v hsz) (u8 0)) private noextract val hash_r_alloc_p: #hsz:hash_size_t -> v:hash #hsz -> GTot Type0 let hash_r_alloc_p #_ v = True val hash_r_alloc: #hsz':Ghost.erased hash_size_t -> hsz:hash_size_t { hsz == Ghost.reveal hsz' } -> r:HST.erid -> HST.ST (hash #hsz) (requires (fun h0 -> true)) (ensures (fun h0 v h1 -> Set.subset (Map.domain (MHS.get_hmap h0)) (Map.domain (MHS.get_hmap h1)) /\ modifies loc_none h0 h1 /\ hash_r_alloc_p #hsz v /\ hash_r_inv h1 v /\ hash_region_of v = r /\ hash_r_repr h1 v == Ghost.reveal hash_irepr /\ B.fresh_loc (B.loc_buffer v) h0 h1)) let hash_r_alloc #_ s r = B.malloc r (u8 0) s val hash_r_free: #hsz':Ghost.erased hash_size_t -> hsz:hash_size_t { hsz == Ghost.reveal hsz' } -> v:hash #hsz' -> HST.ST unit (requires fun h0 -> hash_r_inv h0 v) (ensures fun h0 _ h1 -> modifies (loc_all_regions_from false (hash_region_of v)) h0 h1) let hash_r_free #_ _ v = B.free v noextract inline_for_extraction val hreg (hsz:hash_size_t): regional (hash_size_t) (hash #hsz) let hreg hsz = Rgl #(hash_size_t) #(hash #hsz) hsz (hash_region_of #hsz) (B.loc_buffer) (hash_dummy #hsz) (hash_r_inv #hsz) (hash_r_inv_reg #hsz) (hash_repr #hsz) (hash_r_repr #hsz) (hash_r_sep #hsz) (hash_irepr #hsz) (hash_r_alloc_p #hsz) (hash_r_alloc #hsz) (hash_r_free #hsz) private val hash_copy: #s':Ghost.erased hash_size_t -> s:hash_size_t { s == Ghost.reveal s' } -> src:hash #s -> dst:hash #s -> HST.ST unit (requires fun h0 -> hash_r_inv h0 src /\ hash_r_inv h0 dst /\ HH.disjoint (hash_region_of src) (hash_region_of dst)) (ensures fun h0 _ h1 -> modifies (loc_all_regions_from false (hash_region_of dst)) h0 h1 /\ hash_r_inv h1 dst /\ hash_r_repr h1 dst == hash_r_repr h0 src) let hash_copy #_ s src dst = B.blit src 0ul dst 0ul s /// JP: so much stuff happening here. First, single-constructor, single-argument /// elimination takes places and Cpy becomes completely eliminated, in favor of /// just being a type alias for the underlying function. So now, we have a /// function that returns a function pointer. /// /// Next, one might think that the hsz argument is going to be eliminated. It's /// not, because there's a hidden implicit argument to Cpy which is (hreg hsz), /// meaning that hsz is used at run-time even though Cpy is only using this /// argument ghostly. This would be have to be fixed. /// /// Finally, if the inline_for_extraction is removed, there seems to be a /// karamel bug that inserts a void*0. To be fixed. inline_for_extraction
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "MerkleTree.New.High.fst.checked", "LowStar.Vector.fst.checked", "LowStar.RVector.fst.checked", "LowStar.Regional.Instances.fst.checked", "LowStar.Regional.fst.checked", "LowStar.ConstBuffer.fsti.checked", "LowStar.BufferOps.fst.checked", "LowStar.Buffer.fst.checked", "Lib.IntTypes.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Set.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Monotonic.HyperStack.fsti.checked", "FStar.Monotonic.HyperHeap.fsti.checked", "FStar.Map.fsti.checked", "FStar.Integers.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked", "FStar.All.fst.checked", "EverCrypt.Helpers.fsti.checked", "EverCrypt.Hash.fsti.checked" ], "interface_file": false, "source_file": "MerkleTree.Low.Datastructures.fst" }
[ { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "EverCrypt.Helpers", "short_module": null }, { "abbrev": true, "full_module": "MerkleTree.New.High", "short_module": "MTH" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": true, "full_module": "EverCrypt.Hash", "short_module": "EHS" }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "S" }, { "abbrev": true, "full_module": "LowStar.Regional.Instances", "short_module": "RVI" }, { "abbrev": true, "full_module": "LowStar.RVector", "short_module": "RV" }, { "abbrev": true, "full_module": "LowStar.Vector", "short_module": "V" }, { "abbrev": true, "full_module": "LowStar.ConstBuffer", "short_module": "CB" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.Monotonic.HyperHeap", "short_module": "HH" }, { "abbrev": true, "full_module": "FStar.Monotonic.HyperStack", "short_module": "MHS" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": false, "full_module": "LowStar.Regional.Instances", "short_module": null }, { "abbrev": false, "full_module": "LowStar.RVector", "short_module": null }, { "abbrev": false, "full_module": "LowStar.Regional", "short_module": null }, { "abbrev": false, "full_module": "LowStar.Vector", "short_module": null }, { "abbrev": false, "full_module": "LowStar.BufferOps", "short_module": null }, { "abbrev": false, "full_module": "LowStar.Buffer", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.Integers", "short_module": null }, { "abbrev": false, "full_module": "FStar.All", "short_module": null }, { "abbrev": false, "full_module": "MerkleTree.Low", "short_module": null }, { "abbrev": false, "full_module": "MerkleTree.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": 0, "initial_ifuel": 0, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 10, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
hsz: MerkleTree.Low.Datastructures.hash_size_t -> LowStar.RVector.copyable MerkleTree.Low.Datastructures.hash (MerkleTree.Low.Datastructures.hreg hsz)
Prims.Tot
[ "total" ]
[]
[ "MerkleTree.Low.Datastructures.hash_size_t", "LowStar.RVector.Cpy", "MerkleTree.Low.Datastructures.hash", "MerkleTree.Low.Datastructures.hreg", "MerkleTree.Low.Datastructures.hash_copy", "FStar.Ghost.hide", "LowStar.RVector.copyable" ]
[]
false
false
false
false
false
let hcpy hsz =
Cpy (hash_copy #hsz)
false
MerkleTree.Low.Datastructures.fst
MerkleTree.Low.Datastructures.hash_vec_r_sep
val hash_vec_r_sep: #hsz:hash_size_t -> v:hash_vec #hsz -> p:loc -> h0:HS.mem -> h1:HS.mem -> Lemma (requires (hash_vec_r_inv h0 v /\ loc_disjoint (loc_all_regions_from false (hash_vec_region_of v)) p /\ modifies p h0 h1)) (ensures (hash_vec_r_inv h1 v /\ hash_vec_r_repr h0 v == hash_vec_r_repr h1 v))
val hash_vec_r_sep: #hsz:hash_size_t -> v:hash_vec #hsz -> p:loc -> h0:HS.mem -> h1:HS.mem -> Lemma (requires (hash_vec_r_inv h0 v /\ loc_disjoint (loc_all_regions_from false (hash_vec_region_of v)) p /\ modifies p h0 h1)) (ensures (hash_vec_r_inv h1 v /\ hash_vec_r_repr h0 v == hash_vec_r_repr h1 v))
let hash_vec_r_sep #_ v p h0 h1 = RV.rv_inv_preserved v p h0 h1; RV.as_seq_preserved v p h0 h1
{ "file_name": "src/MerkleTree.Low.Datastructures.fst", "git_rev": "7d7bdc20f2033171e279c176b26e84f9069d23c6", "git_url": "https://github.com/hacl-star/merkle-tree.git", "project_name": "merkle-tree" }
{ "end_col": 31, "end_line": 245, "start_col": 0, "start_line": 243 }
module MerkleTree.Low.Datastructures open FStar.All open FStar.Integers open FStar.Mul open LowStar.Buffer open LowStar.BufferOps open LowStar.Vector open LowStar.Regional open LowStar.RVector open LowStar.Regional.Instances module HS = FStar.HyperStack module HST = FStar.HyperStack.ST module MHS = FStar.Monotonic.HyperStack module HH = FStar.Monotonic.HyperHeap module B = LowStar.Buffer module CB = LowStar.ConstBuffer module V = LowStar.Vector module RV = LowStar.RVector module RVI = LowStar.Regional.Instances module S = FStar.Seq module EHS = EverCrypt.Hash module U32 = FStar.UInt32 module MTH = MerkleTree.New.High open EverCrypt.Helpers open Lib.IntTypes #set-options "--z3rlimit 10 --initial_fuel 0 --max_fuel 0 --initial_ifuel 0 --max_ifuel 0" type hash_size_t = n:uint32_t{n > 0ul} type hash (#hsz:hash_size_t) = b:B.buffer uint8 { B.len b = hsz \/ B.g_is_null b } // We cannot use `Low.RVector.Instances`, where we have some general // typeclass instances of `regional`, e.g., if `rg:regional a` then // `regional (rvector rg)`. In FStar we can use this, but KaRaMeL currently // cannot deal with this and gives a number of errors. // So we temporarily instantiate some `regional`s manually below, which is // extractable to C by KaRaMeL. /// Some instantiations of `regional` used in Merkle tree /// 1. `hash` is regional private noextract val hash_region_of: #hsz:hash_size_t -> v:hash #hsz -> GTot HH.rid let hash_region_of #_ v = B.frameOf v private inline_for_extraction val hash_dummy: #hsz:Ghost.erased hash_size_t -> Tot (hash #hsz) let hash_dummy #_ = B.null private noextract val hash_r_inv: #hsz:hash_size_t -> h:HS.mem -> v:hash #hsz -> GTot Type0 let hash_r_inv #hsz h v = B.live h v /\ B.freeable v /\ B.len v = hsz private noextract val hash_r_inv_reg: #hsz:hash_size_t -> h:HS.mem -> v:hash -> Lemma (requires hash_r_inv h v) (ensures MHS.live_region h (hash_region_of #hsz v)) let hash_r_inv_reg #_ h v = () private noextract val hash_repr (#hsz:hash_size_t): Type0 let hash_repr #hsz = MTH.hash #(U32.v hsz) private noextract val hash_r_repr: #hsz:hash_size_t -> h:HS.mem -> v:hash{hash_r_inv #hsz h v} -> GTot (hash_repr #hsz) let hash_r_repr #_ h v = B.as_seq h v private noextract val hash_r_sep: #hsz:hash_size_t -> v:hash #hsz -> p:loc -> h0:HS.mem -> h1:HS.mem -> Lemma (requires hash_r_inv h0 v /\ loc_disjoint (loc_all_regions_from false (hash_region_of v)) p /\ modifies p h0 h1) (ensures hash_r_inv h1 v /\ hash_r_repr h0 v == hash_r_repr h1 v) let hash_r_sep #_ v p h0 h1 = assert (loc_includes (loc_all_regions_from false (hash_region_of v)) (loc_buffer v)); B.modifies_buffer_elim v p h0 h1 private noextract val hash_irepr: #hsz:hash_size_t -> Ghost.erased (hash_repr #hsz) let hash_irepr #hsz = Ghost.hide (S.create (U32.v hsz) (u8 0)) private noextract val hash_r_alloc_p: #hsz:hash_size_t -> v:hash #hsz -> GTot Type0 let hash_r_alloc_p #_ v = True val hash_r_alloc: #hsz':Ghost.erased hash_size_t -> hsz:hash_size_t { hsz == Ghost.reveal hsz' } -> r:HST.erid -> HST.ST (hash #hsz) (requires (fun h0 -> true)) (ensures (fun h0 v h1 -> Set.subset (Map.domain (MHS.get_hmap h0)) (Map.domain (MHS.get_hmap h1)) /\ modifies loc_none h0 h1 /\ hash_r_alloc_p #hsz v /\ hash_r_inv h1 v /\ hash_region_of v = r /\ hash_r_repr h1 v == Ghost.reveal hash_irepr /\ B.fresh_loc (B.loc_buffer v) h0 h1)) let hash_r_alloc #_ s r = B.malloc r (u8 0) s val hash_r_free: #hsz':Ghost.erased hash_size_t -> hsz:hash_size_t { hsz == Ghost.reveal hsz' } -> v:hash #hsz' -> HST.ST unit (requires fun h0 -> hash_r_inv h0 v) (ensures fun h0 _ h1 -> modifies (loc_all_regions_from false (hash_region_of v)) h0 h1) let hash_r_free #_ _ v = B.free v noextract inline_for_extraction val hreg (hsz:hash_size_t): regional (hash_size_t) (hash #hsz) let hreg hsz = Rgl #(hash_size_t) #(hash #hsz) hsz (hash_region_of #hsz) (B.loc_buffer) (hash_dummy #hsz) (hash_r_inv #hsz) (hash_r_inv_reg #hsz) (hash_repr #hsz) (hash_r_repr #hsz) (hash_r_sep #hsz) (hash_irepr #hsz) (hash_r_alloc_p #hsz) (hash_r_alloc #hsz) (hash_r_free #hsz) private val hash_copy: #s':Ghost.erased hash_size_t -> s:hash_size_t { s == Ghost.reveal s' } -> src:hash #s -> dst:hash #s -> HST.ST unit (requires fun h0 -> hash_r_inv h0 src /\ hash_r_inv h0 dst /\ HH.disjoint (hash_region_of src) (hash_region_of dst)) (ensures fun h0 _ h1 -> modifies (loc_all_regions_from false (hash_region_of dst)) h0 h1 /\ hash_r_inv h1 dst /\ hash_r_repr h1 dst == hash_r_repr h0 src) let hash_copy #_ s src dst = B.blit src 0ul dst 0ul s /// JP: so much stuff happening here. First, single-constructor, single-argument /// elimination takes places and Cpy becomes completely eliminated, in favor of /// just being a type alias for the underlying function. So now, we have a /// function that returns a function pointer. /// /// Next, one might think that the hsz argument is going to be eliminated. It's /// not, because there's a hidden implicit argument to Cpy which is (hreg hsz), /// meaning that hsz is used at run-time even though Cpy is only using this /// argument ghostly. This would be have to be fixed. /// /// Finally, if the inline_for_extraction is removed, there seems to be a /// karamel bug that inserts a void*0. To be fixed. inline_for_extraction val hcpy: hsz:hash_size_t -> copyable #hash_size_t (hash #hsz) (hreg hsz) let hcpy hsz = Cpy (hash_copy #hsz) type hash_vec (#hsz:hash_size_t) = RV.rvector (hreg hsz) /// 2. `rvector hash` is regional type rhst (hsz:hash_size_t) = regional hash_size_t (hash #hsz) private noextract val hash_vec_region_of: #hsz:hash_size_t -> v:hash_vec #hsz -> GTot HH.rid let hash_vec_region_of #_ v = V.frameOf v private inline_for_extraction val hash_vec_dummy: (#hsz:Ghost.erased hash_size_t) -> hash_vec #hsz let hash_vec_dummy #_ = V.alloc_empty (hash #_) noextract val hash_vec_r_inv: #hsz:hash_size_t -> h:HS.mem -> v:hash_vec #hsz -> GTot Type0 let hash_vec_r_inv #hsz h v = RV.rv_inv h v noextract val hash_vec_r_inv_reg: #hsz:hash_size_t -> h:HS.mem -> v:hash_vec #hsz -> Lemma (requires (hash_vec_r_inv h v)) (ensures (MHS.live_region h (hash_vec_region_of v))) let hash_vec_r_inv_reg #_ h v = () private noextract val hash_vec_repr: #hsz:hash_size_t -> Type0 let hash_vec_repr #hsz = MTH.hashes #(U32.v hsz) noextract val hash_vec_r_repr: #hsz:hash_size_t -> h:HS.mem -> v:hash_vec #hsz {hash_vec_r_inv h v} -> GTot (hash_vec_repr #hsz) let hash_vec_r_repr #_ h v = RV.as_seq h v noextract val hash_vec_r_sep: #hsz:hash_size_t -> v:hash_vec #hsz -> p:loc -> h0:HS.mem -> h1:HS.mem -> Lemma (requires (hash_vec_r_inv h0 v /\ loc_disjoint (loc_all_regions_from false (hash_vec_region_of v)) p /\ modifies p h0 h1)) (ensures (hash_vec_r_inv h1 v /\
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "MerkleTree.New.High.fst.checked", "LowStar.Vector.fst.checked", "LowStar.RVector.fst.checked", "LowStar.Regional.Instances.fst.checked", "LowStar.Regional.fst.checked", "LowStar.ConstBuffer.fsti.checked", "LowStar.BufferOps.fst.checked", "LowStar.Buffer.fst.checked", "Lib.IntTypes.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Set.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Monotonic.HyperStack.fsti.checked", "FStar.Monotonic.HyperHeap.fsti.checked", "FStar.Map.fsti.checked", "FStar.Integers.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked", "FStar.All.fst.checked", "EverCrypt.Helpers.fsti.checked", "EverCrypt.Hash.fsti.checked" ], "interface_file": false, "source_file": "MerkleTree.Low.Datastructures.fst" }
[ { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "EverCrypt.Helpers", "short_module": null }, { "abbrev": true, "full_module": "MerkleTree.New.High", "short_module": "MTH" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": true, "full_module": "EverCrypt.Hash", "short_module": "EHS" }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "S" }, { "abbrev": true, "full_module": "LowStar.Regional.Instances", "short_module": "RVI" }, { "abbrev": true, "full_module": "LowStar.RVector", "short_module": "RV" }, { "abbrev": true, "full_module": "LowStar.Vector", "short_module": "V" }, { "abbrev": true, "full_module": "LowStar.ConstBuffer", "short_module": "CB" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.Monotonic.HyperHeap", "short_module": "HH" }, { "abbrev": true, "full_module": "FStar.Monotonic.HyperStack", "short_module": "MHS" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": false, "full_module": "LowStar.Regional.Instances", "short_module": null }, { "abbrev": false, "full_module": "LowStar.RVector", "short_module": null }, { "abbrev": false, "full_module": "LowStar.Regional", "short_module": null }, { "abbrev": false, "full_module": "LowStar.Vector", "short_module": null }, { "abbrev": false, "full_module": "LowStar.BufferOps", "short_module": null }, { "abbrev": false, "full_module": "LowStar.Buffer", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.Integers", "short_module": null }, { "abbrev": false, "full_module": "FStar.All", "short_module": null }, { "abbrev": false, "full_module": "MerkleTree.Low", "short_module": null }, { "abbrev": false, "full_module": "MerkleTree.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": 0, "initial_ifuel": 0, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 10, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
v: MerkleTree.Low.Datastructures.hash_vec -> p: LowStar.Monotonic.Buffer.loc -> h0: FStar.Monotonic.HyperStack.mem -> h1: FStar.Monotonic.HyperStack.mem -> FStar.Pervasives.Lemma (requires MerkleTree.Low.Datastructures.hash_vec_r_inv h0 v /\ LowStar.Monotonic.Buffer.loc_disjoint (LowStar.Monotonic.Buffer.loc_all_regions_from false (MerkleTree.Low.Datastructures.hash_vec_region_of v)) p /\ LowStar.Monotonic.Buffer.modifies p h0 h1) (ensures MerkleTree.Low.Datastructures.hash_vec_r_inv h1 v /\ MerkleTree.Low.Datastructures.hash_vec_r_repr h0 v == MerkleTree.Low.Datastructures.hash_vec_r_repr h1 v)
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "MerkleTree.Low.Datastructures.hash_size_t", "MerkleTree.Low.Datastructures.hash_vec", "LowStar.Monotonic.Buffer.loc", "FStar.Monotonic.HyperStack.mem", "LowStar.RVector.as_seq_preserved", "MerkleTree.Low.Datastructures.hash", "MerkleTree.Low.Datastructures.hreg", "Prims.unit", "LowStar.RVector.rv_inv_preserved" ]
[]
true
false
true
false
false
let hash_vec_r_sep #_ v p h0 h1 =
RV.rv_inv_preserved v p h0 h1; RV.as_seq_preserved v p h0 h1
false
MerkleTree.Low.Datastructures.fst
MerkleTree.Low.Datastructures.hash_vec_r_repr
val hash_vec_r_repr: #hsz:hash_size_t -> h:HS.mem -> v:hash_vec #hsz {hash_vec_r_inv h v} -> GTot (hash_vec_repr #hsz)
val hash_vec_r_repr: #hsz:hash_size_t -> h:HS.mem -> v:hash_vec #hsz {hash_vec_r_inv h v} -> GTot (hash_vec_repr #hsz)
let hash_vec_r_repr #_ h v = RV.as_seq h v
{ "file_name": "src/MerkleTree.Low.Datastructures.fst", "git_rev": "7d7bdc20f2033171e279c176b26e84f9069d23c6", "git_url": "https://github.com/hacl-star/merkle-tree.git", "project_name": "merkle-tree" }
{ "end_col": 15, "end_line": 230, "start_col": 0, "start_line": 229 }
module MerkleTree.Low.Datastructures open FStar.All open FStar.Integers open FStar.Mul open LowStar.Buffer open LowStar.BufferOps open LowStar.Vector open LowStar.Regional open LowStar.RVector open LowStar.Regional.Instances module HS = FStar.HyperStack module HST = FStar.HyperStack.ST module MHS = FStar.Monotonic.HyperStack module HH = FStar.Monotonic.HyperHeap module B = LowStar.Buffer module CB = LowStar.ConstBuffer module V = LowStar.Vector module RV = LowStar.RVector module RVI = LowStar.Regional.Instances module S = FStar.Seq module EHS = EverCrypt.Hash module U32 = FStar.UInt32 module MTH = MerkleTree.New.High open EverCrypt.Helpers open Lib.IntTypes #set-options "--z3rlimit 10 --initial_fuel 0 --max_fuel 0 --initial_ifuel 0 --max_ifuel 0" type hash_size_t = n:uint32_t{n > 0ul} type hash (#hsz:hash_size_t) = b:B.buffer uint8 { B.len b = hsz \/ B.g_is_null b } // We cannot use `Low.RVector.Instances`, where we have some general // typeclass instances of `regional`, e.g., if `rg:regional a` then // `regional (rvector rg)`. In FStar we can use this, but KaRaMeL currently // cannot deal with this and gives a number of errors. // So we temporarily instantiate some `regional`s manually below, which is // extractable to C by KaRaMeL. /// Some instantiations of `regional` used in Merkle tree /// 1. `hash` is regional private noextract val hash_region_of: #hsz:hash_size_t -> v:hash #hsz -> GTot HH.rid let hash_region_of #_ v = B.frameOf v private inline_for_extraction val hash_dummy: #hsz:Ghost.erased hash_size_t -> Tot (hash #hsz) let hash_dummy #_ = B.null private noextract val hash_r_inv: #hsz:hash_size_t -> h:HS.mem -> v:hash #hsz -> GTot Type0 let hash_r_inv #hsz h v = B.live h v /\ B.freeable v /\ B.len v = hsz private noextract val hash_r_inv_reg: #hsz:hash_size_t -> h:HS.mem -> v:hash -> Lemma (requires hash_r_inv h v) (ensures MHS.live_region h (hash_region_of #hsz v)) let hash_r_inv_reg #_ h v = () private noextract val hash_repr (#hsz:hash_size_t): Type0 let hash_repr #hsz = MTH.hash #(U32.v hsz) private noextract val hash_r_repr: #hsz:hash_size_t -> h:HS.mem -> v:hash{hash_r_inv #hsz h v} -> GTot (hash_repr #hsz) let hash_r_repr #_ h v = B.as_seq h v private noextract val hash_r_sep: #hsz:hash_size_t -> v:hash #hsz -> p:loc -> h0:HS.mem -> h1:HS.mem -> Lemma (requires hash_r_inv h0 v /\ loc_disjoint (loc_all_regions_from false (hash_region_of v)) p /\ modifies p h0 h1) (ensures hash_r_inv h1 v /\ hash_r_repr h0 v == hash_r_repr h1 v) let hash_r_sep #_ v p h0 h1 = assert (loc_includes (loc_all_regions_from false (hash_region_of v)) (loc_buffer v)); B.modifies_buffer_elim v p h0 h1 private noextract val hash_irepr: #hsz:hash_size_t -> Ghost.erased (hash_repr #hsz) let hash_irepr #hsz = Ghost.hide (S.create (U32.v hsz) (u8 0)) private noextract val hash_r_alloc_p: #hsz:hash_size_t -> v:hash #hsz -> GTot Type0 let hash_r_alloc_p #_ v = True val hash_r_alloc: #hsz':Ghost.erased hash_size_t -> hsz:hash_size_t { hsz == Ghost.reveal hsz' } -> r:HST.erid -> HST.ST (hash #hsz) (requires (fun h0 -> true)) (ensures (fun h0 v h1 -> Set.subset (Map.domain (MHS.get_hmap h0)) (Map.domain (MHS.get_hmap h1)) /\ modifies loc_none h0 h1 /\ hash_r_alloc_p #hsz v /\ hash_r_inv h1 v /\ hash_region_of v = r /\ hash_r_repr h1 v == Ghost.reveal hash_irepr /\ B.fresh_loc (B.loc_buffer v) h0 h1)) let hash_r_alloc #_ s r = B.malloc r (u8 0) s val hash_r_free: #hsz':Ghost.erased hash_size_t -> hsz:hash_size_t { hsz == Ghost.reveal hsz' } -> v:hash #hsz' -> HST.ST unit (requires fun h0 -> hash_r_inv h0 v) (ensures fun h0 _ h1 -> modifies (loc_all_regions_from false (hash_region_of v)) h0 h1) let hash_r_free #_ _ v = B.free v noextract inline_for_extraction val hreg (hsz:hash_size_t): regional (hash_size_t) (hash #hsz) let hreg hsz = Rgl #(hash_size_t) #(hash #hsz) hsz (hash_region_of #hsz) (B.loc_buffer) (hash_dummy #hsz) (hash_r_inv #hsz) (hash_r_inv_reg #hsz) (hash_repr #hsz) (hash_r_repr #hsz) (hash_r_sep #hsz) (hash_irepr #hsz) (hash_r_alloc_p #hsz) (hash_r_alloc #hsz) (hash_r_free #hsz) private val hash_copy: #s':Ghost.erased hash_size_t -> s:hash_size_t { s == Ghost.reveal s' } -> src:hash #s -> dst:hash #s -> HST.ST unit (requires fun h0 -> hash_r_inv h0 src /\ hash_r_inv h0 dst /\ HH.disjoint (hash_region_of src) (hash_region_of dst)) (ensures fun h0 _ h1 -> modifies (loc_all_regions_from false (hash_region_of dst)) h0 h1 /\ hash_r_inv h1 dst /\ hash_r_repr h1 dst == hash_r_repr h0 src) let hash_copy #_ s src dst = B.blit src 0ul dst 0ul s /// JP: so much stuff happening here. First, single-constructor, single-argument /// elimination takes places and Cpy becomes completely eliminated, in favor of /// just being a type alias for the underlying function. So now, we have a /// function that returns a function pointer. /// /// Next, one might think that the hsz argument is going to be eliminated. It's /// not, because there's a hidden implicit argument to Cpy which is (hreg hsz), /// meaning that hsz is used at run-time even though Cpy is only using this /// argument ghostly. This would be have to be fixed. /// /// Finally, if the inline_for_extraction is removed, there seems to be a /// karamel bug that inserts a void*0. To be fixed. inline_for_extraction val hcpy: hsz:hash_size_t -> copyable #hash_size_t (hash #hsz) (hreg hsz) let hcpy hsz = Cpy (hash_copy #hsz) type hash_vec (#hsz:hash_size_t) = RV.rvector (hreg hsz) /// 2. `rvector hash` is regional type rhst (hsz:hash_size_t) = regional hash_size_t (hash #hsz) private noextract val hash_vec_region_of: #hsz:hash_size_t -> v:hash_vec #hsz -> GTot HH.rid let hash_vec_region_of #_ v = V.frameOf v private inline_for_extraction val hash_vec_dummy: (#hsz:Ghost.erased hash_size_t) -> hash_vec #hsz let hash_vec_dummy #_ = V.alloc_empty (hash #_) noextract val hash_vec_r_inv: #hsz:hash_size_t -> h:HS.mem -> v:hash_vec #hsz -> GTot Type0 let hash_vec_r_inv #hsz h v = RV.rv_inv h v noextract val hash_vec_r_inv_reg: #hsz:hash_size_t -> h:HS.mem -> v:hash_vec #hsz -> Lemma (requires (hash_vec_r_inv h v)) (ensures (MHS.live_region h (hash_vec_region_of v))) let hash_vec_r_inv_reg #_ h v = () private noextract val hash_vec_repr: #hsz:hash_size_t -> Type0 let hash_vec_repr #hsz = MTH.hashes #(U32.v hsz) noextract val hash_vec_r_repr: #hsz:hash_size_t ->
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "MerkleTree.New.High.fst.checked", "LowStar.Vector.fst.checked", "LowStar.RVector.fst.checked", "LowStar.Regional.Instances.fst.checked", "LowStar.Regional.fst.checked", "LowStar.ConstBuffer.fsti.checked", "LowStar.BufferOps.fst.checked", "LowStar.Buffer.fst.checked", "Lib.IntTypes.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Set.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Monotonic.HyperStack.fsti.checked", "FStar.Monotonic.HyperHeap.fsti.checked", "FStar.Map.fsti.checked", "FStar.Integers.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked", "FStar.All.fst.checked", "EverCrypt.Helpers.fsti.checked", "EverCrypt.Hash.fsti.checked" ], "interface_file": false, "source_file": "MerkleTree.Low.Datastructures.fst" }
[ { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "EverCrypt.Helpers", "short_module": null }, { "abbrev": true, "full_module": "MerkleTree.New.High", "short_module": "MTH" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": true, "full_module": "EverCrypt.Hash", "short_module": "EHS" }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "S" }, { "abbrev": true, "full_module": "LowStar.Regional.Instances", "short_module": "RVI" }, { "abbrev": true, "full_module": "LowStar.RVector", "short_module": "RV" }, { "abbrev": true, "full_module": "LowStar.Vector", "short_module": "V" }, { "abbrev": true, "full_module": "LowStar.ConstBuffer", "short_module": "CB" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.Monotonic.HyperHeap", "short_module": "HH" }, { "abbrev": true, "full_module": "FStar.Monotonic.HyperStack", "short_module": "MHS" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": false, "full_module": "LowStar.Regional.Instances", "short_module": null }, { "abbrev": false, "full_module": "LowStar.RVector", "short_module": null }, { "abbrev": false, "full_module": "LowStar.Regional", "short_module": null }, { "abbrev": false, "full_module": "LowStar.Vector", "short_module": null }, { "abbrev": false, "full_module": "LowStar.BufferOps", "short_module": null }, { "abbrev": false, "full_module": "LowStar.Buffer", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.Integers", "short_module": null }, { "abbrev": false, "full_module": "FStar.All", "short_module": null }, { "abbrev": false, "full_module": "MerkleTree.Low", "short_module": null }, { "abbrev": false, "full_module": "MerkleTree.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": 0, "initial_ifuel": 0, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 10, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
h: FStar.Monotonic.HyperStack.mem -> v: MerkleTree.Low.Datastructures.hash_vec{MerkleTree.Low.Datastructures.hash_vec_r_inv h v} -> Prims.GTot MerkleTree.Low.Datastructures.hash_vec_repr
Prims.GTot
[ "sometrivial" ]
[]
[ "MerkleTree.Low.Datastructures.hash_size_t", "FStar.Monotonic.HyperStack.mem", "MerkleTree.Low.Datastructures.hash_vec", "MerkleTree.Low.Datastructures.hash_vec_r_inv", "LowStar.RVector.as_seq", "MerkleTree.Low.Datastructures.hash", "MerkleTree.Low.Datastructures.hreg", "MerkleTree.Low.Datastructures.hash_vec_repr" ]
[]
false
false
false
false
false
let hash_vec_r_repr #_ h v =
RV.as_seq h v
false
MerkleTree.Low.Datastructures.fst
MerkleTree.Low.Datastructures.hash_r_alloc
val hash_r_alloc: #hsz':Ghost.erased hash_size_t -> hsz:hash_size_t { hsz == Ghost.reveal hsz' } -> r:HST.erid -> HST.ST (hash #hsz) (requires (fun h0 -> true)) (ensures (fun h0 v h1 -> Set.subset (Map.domain (MHS.get_hmap h0)) (Map.domain (MHS.get_hmap h1)) /\ modifies loc_none h0 h1 /\ hash_r_alloc_p #hsz v /\ hash_r_inv h1 v /\ hash_region_of v = r /\ hash_r_repr h1 v == Ghost.reveal hash_irepr /\ B.fresh_loc (B.loc_buffer v) h0 h1))
val hash_r_alloc: #hsz':Ghost.erased hash_size_t -> hsz:hash_size_t { hsz == Ghost.reveal hsz' } -> r:HST.erid -> HST.ST (hash #hsz) (requires (fun h0 -> true)) (ensures (fun h0 v h1 -> Set.subset (Map.domain (MHS.get_hmap h0)) (Map.domain (MHS.get_hmap h1)) /\ modifies loc_none h0 h1 /\ hash_r_alloc_p #hsz v /\ hash_r_inv h1 v /\ hash_region_of v = r /\ hash_r_repr h1 v == Ghost.reveal hash_irepr /\ B.fresh_loc (B.loc_buffer v) h0 h1))
let hash_r_alloc #_ s r = B.malloc r (u8 0) s
{ "file_name": "src/MerkleTree.Low.Datastructures.fst", "git_rev": "7d7bdc20f2033171e279c176b26e84f9069d23c6", "git_url": "https://github.com/hacl-star/merkle-tree.git", "project_name": "merkle-tree" }
{ "end_col": 21, "end_line": 130, "start_col": 0, "start_line": 129 }
module MerkleTree.Low.Datastructures open FStar.All open FStar.Integers open FStar.Mul open LowStar.Buffer open LowStar.BufferOps open LowStar.Vector open LowStar.Regional open LowStar.RVector open LowStar.Regional.Instances module HS = FStar.HyperStack module HST = FStar.HyperStack.ST module MHS = FStar.Monotonic.HyperStack module HH = FStar.Monotonic.HyperHeap module B = LowStar.Buffer module CB = LowStar.ConstBuffer module V = LowStar.Vector module RV = LowStar.RVector module RVI = LowStar.Regional.Instances module S = FStar.Seq module EHS = EverCrypt.Hash module U32 = FStar.UInt32 module MTH = MerkleTree.New.High open EverCrypt.Helpers open Lib.IntTypes #set-options "--z3rlimit 10 --initial_fuel 0 --max_fuel 0 --initial_ifuel 0 --max_ifuel 0" type hash_size_t = n:uint32_t{n > 0ul} type hash (#hsz:hash_size_t) = b:B.buffer uint8 { B.len b = hsz \/ B.g_is_null b } // We cannot use `Low.RVector.Instances`, where we have some general // typeclass instances of `regional`, e.g., if `rg:regional a` then // `regional (rvector rg)`. In FStar we can use this, but KaRaMeL currently // cannot deal with this and gives a number of errors. // So we temporarily instantiate some `regional`s manually below, which is // extractable to C by KaRaMeL. /// Some instantiations of `regional` used in Merkle tree /// 1. `hash` is regional private noextract val hash_region_of: #hsz:hash_size_t -> v:hash #hsz -> GTot HH.rid let hash_region_of #_ v = B.frameOf v private inline_for_extraction val hash_dummy: #hsz:Ghost.erased hash_size_t -> Tot (hash #hsz) let hash_dummy #_ = B.null private noextract val hash_r_inv: #hsz:hash_size_t -> h:HS.mem -> v:hash #hsz -> GTot Type0 let hash_r_inv #hsz h v = B.live h v /\ B.freeable v /\ B.len v = hsz private noextract val hash_r_inv_reg: #hsz:hash_size_t -> h:HS.mem -> v:hash -> Lemma (requires hash_r_inv h v) (ensures MHS.live_region h (hash_region_of #hsz v)) let hash_r_inv_reg #_ h v = () private noextract val hash_repr (#hsz:hash_size_t): Type0 let hash_repr #hsz = MTH.hash #(U32.v hsz) private noextract val hash_r_repr: #hsz:hash_size_t -> h:HS.mem -> v:hash{hash_r_inv #hsz h v} -> GTot (hash_repr #hsz) let hash_r_repr #_ h v = B.as_seq h v private noextract val hash_r_sep: #hsz:hash_size_t -> v:hash #hsz -> p:loc -> h0:HS.mem -> h1:HS.mem -> Lemma (requires hash_r_inv h0 v /\ loc_disjoint (loc_all_regions_from false (hash_region_of v)) p /\ modifies p h0 h1) (ensures hash_r_inv h1 v /\ hash_r_repr h0 v == hash_r_repr h1 v) let hash_r_sep #_ v p h0 h1 = assert (loc_includes (loc_all_regions_from false (hash_region_of v)) (loc_buffer v)); B.modifies_buffer_elim v p h0 h1 private noextract val hash_irepr: #hsz:hash_size_t -> Ghost.erased (hash_repr #hsz) let hash_irepr #hsz = Ghost.hide (S.create (U32.v hsz) (u8 0)) private noextract val hash_r_alloc_p: #hsz:hash_size_t -> v:hash #hsz -> GTot Type0 let hash_r_alloc_p #_ v = True val hash_r_alloc: #hsz':Ghost.erased hash_size_t -> hsz:hash_size_t { hsz == Ghost.reveal hsz' } -> r:HST.erid -> HST.ST (hash #hsz) (requires (fun h0 -> true)) (ensures (fun h0 v h1 -> Set.subset (Map.domain (MHS.get_hmap h0)) (Map.domain (MHS.get_hmap h1)) /\ modifies loc_none h0 h1 /\ hash_r_alloc_p #hsz v /\ hash_r_inv h1 v /\ hash_region_of v = r /\ hash_r_repr h1 v == Ghost.reveal hash_irepr /\
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "MerkleTree.New.High.fst.checked", "LowStar.Vector.fst.checked", "LowStar.RVector.fst.checked", "LowStar.Regional.Instances.fst.checked", "LowStar.Regional.fst.checked", "LowStar.ConstBuffer.fsti.checked", "LowStar.BufferOps.fst.checked", "LowStar.Buffer.fst.checked", "Lib.IntTypes.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Set.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Monotonic.HyperStack.fsti.checked", "FStar.Monotonic.HyperHeap.fsti.checked", "FStar.Map.fsti.checked", "FStar.Integers.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked", "FStar.All.fst.checked", "EverCrypt.Helpers.fsti.checked", "EverCrypt.Hash.fsti.checked" ], "interface_file": false, "source_file": "MerkleTree.Low.Datastructures.fst" }
[ { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "EverCrypt.Helpers", "short_module": null }, { "abbrev": true, "full_module": "MerkleTree.New.High", "short_module": "MTH" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": true, "full_module": "EverCrypt.Hash", "short_module": "EHS" }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "S" }, { "abbrev": true, "full_module": "LowStar.Regional.Instances", "short_module": "RVI" }, { "abbrev": true, "full_module": "LowStar.RVector", "short_module": "RV" }, { "abbrev": true, "full_module": "LowStar.Vector", "short_module": "V" }, { "abbrev": true, "full_module": "LowStar.ConstBuffer", "short_module": "CB" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.Monotonic.HyperHeap", "short_module": "HH" }, { "abbrev": true, "full_module": "FStar.Monotonic.HyperStack", "short_module": "MHS" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": false, "full_module": "LowStar.Regional.Instances", "short_module": null }, { "abbrev": false, "full_module": "LowStar.RVector", "short_module": null }, { "abbrev": false, "full_module": "LowStar.Regional", "short_module": null }, { "abbrev": false, "full_module": "LowStar.Vector", "short_module": null }, { "abbrev": false, "full_module": "LowStar.BufferOps", "short_module": null }, { "abbrev": false, "full_module": "LowStar.Buffer", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.Integers", "short_module": null }, { "abbrev": false, "full_module": "FStar.All", "short_module": null }, { "abbrev": false, "full_module": "MerkleTree.Low", "short_module": null }, { "abbrev": false, "full_module": "MerkleTree.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": 0, "initial_ifuel": 0, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 10, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
hsz: MerkleTree.Low.Datastructures.hash_size_t{hsz == FStar.Ghost.reveal hsz'} -> r: FStar.HyperStack.ST.erid -> FStar.HyperStack.ST.ST MerkleTree.Low.Datastructures.hash
FStar.HyperStack.ST.ST
[]
[]
[ "FStar.Ghost.erased", "MerkleTree.Low.Datastructures.hash_size_t", "Prims.eq2", "FStar.Ghost.reveal", "FStar.HyperStack.ST.erid", "LowStar.Buffer.malloc", "Lib.IntTypes.uint8", "Lib.IntTypes.u8", "LowStar.Monotonic.Buffer.mbuffer", "LowStar.Buffer.trivial_preorder", "Prims.l_and", "Prims.nat", "LowStar.Monotonic.Buffer.length", "FStar.UInt32.v", "Prims.b2t", "Prims.op_Negation", "LowStar.Monotonic.Buffer.g_is_null", "FStar.Monotonic.HyperHeap.rid", "LowStar.Monotonic.Buffer.frameOf", "LowStar.Monotonic.Buffer.freeable", "MerkleTree.Low.Datastructures.hash" ]
[]
false
true
false
false
false
let hash_r_alloc #_ s r =
B.malloc r (u8 0) s
false
MerkleTree.Low.Datastructures.fst
MerkleTree.Low.Datastructures.hash_vec_r_free
val hash_vec_r_free: #hsz':Ghost.erased hash_size_t -> hsz:hash_size_t { hsz == Ghost.reveal hsz' } -> v:hash_vec #hsz -> HST.ST unit (requires (fun h0 -> hash_vec_r_inv h0 v)) (ensures (fun h0 _ h1 -> modifies (loc_all_regions_from false (hash_vec_region_of #hsz v)) h0 h1))
val hash_vec_r_free: #hsz':Ghost.erased hash_size_t -> hsz:hash_size_t { hsz == Ghost.reveal hsz' } -> v:hash_vec #hsz -> HST.ST unit (requires (fun h0 -> hash_vec_r_inv h0 v)) (ensures (fun h0 _ h1 -> modifies (loc_all_regions_from false (hash_vec_region_of #hsz v)) h0 h1))
let hash_vec_r_free #_ hsz v = RV.free v
{ "file_name": "src/MerkleTree.Low.Datastructures.fst", "git_rev": "7d7bdc20f2033171e279c176b26e84f9069d23c6", "git_url": "https://github.com/hacl-star/merkle-tree.git", "project_name": "merkle-tree" }
{ "end_col": 11, "end_line": 289, "start_col": 0, "start_line": 288 }
module MerkleTree.Low.Datastructures open FStar.All open FStar.Integers open FStar.Mul open LowStar.Buffer open LowStar.BufferOps open LowStar.Vector open LowStar.Regional open LowStar.RVector open LowStar.Regional.Instances module HS = FStar.HyperStack module HST = FStar.HyperStack.ST module MHS = FStar.Monotonic.HyperStack module HH = FStar.Monotonic.HyperHeap module B = LowStar.Buffer module CB = LowStar.ConstBuffer module V = LowStar.Vector module RV = LowStar.RVector module RVI = LowStar.Regional.Instances module S = FStar.Seq module EHS = EverCrypt.Hash module U32 = FStar.UInt32 module MTH = MerkleTree.New.High open EverCrypt.Helpers open Lib.IntTypes #set-options "--z3rlimit 10 --initial_fuel 0 --max_fuel 0 --initial_ifuel 0 --max_ifuel 0" type hash_size_t = n:uint32_t{n > 0ul} type hash (#hsz:hash_size_t) = b:B.buffer uint8 { B.len b = hsz \/ B.g_is_null b } // We cannot use `Low.RVector.Instances`, where we have some general // typeclass instances of `regional`, e.g., if `rg:regional a` then // `regional (rvector rg)`. In FStar we can use this, but KaRaMeL currently // cannot deal with this and gives a number of errors. // So we temporarily instantiate some `regional`s manually below, which is // extractable to C by KaRaMeL. /// Some instantiations of `regional` used in Merkle tree /// 1. `hash` is regional private noextract val hash_region_of: #hsz:hash_size_t -> v:hash #hsz -> GTot HH.rid let hash_region_of #_ v = B.frameOf v private inline_for_extraction val hash_dummy: #hsz:Ghost.erased hash_size_t -> Tot (hash #hsz) let hash_dummy #_ = B.null private noextract val hash_r_inv: #hsz:hash_size_t -> h:HS.mem -> v:hash #hsz -> GTot Type0 let hash_r_inv #hsz h v = B.live h v /\ B.freeable v /\ B.len v = hsz private noextract val hash_r_inv_reg: #hsz:hash_size_t -> h:HS.mem -> v:hash -> Lemma (requires hash_r_inv h v) (ensures MHS.live_region h (hash_region_of #hsz v)) let hash_r_inv_reg #_ h v = () private noextract val hash_repr (#hsz:hash_size_t): Type0 let hash_repr #hsz = MTH.hash #(U32.v hsz) private noextract val hash_r_repr: #hsz:hash_size_t -> h:HS.mem -> v:hash{hash_r_inv #hsz h v} -> GTot (hash_repr #hsz) let hash_r_repr #_ h v = B.as_seq h v private noextract val hash_r_sep: #hsz:hash_size_t -> v:hash #hsz -> p:loc -> h0:HS.mem -> h1:HS.mem -> Lemma (requires hash_r_inv h0 v /\ loc_disjoint (loc_all_regions_from false (hash_region_of v)) p /\ modifies p h0 h1) (ensures hash_r_inv h1 v /\ hash_r_repr h0 v == hash_r_repr h1 v) let hash_r_sep #_ v p h0 h1 = assert (loc_includes (loc_all_regions_from false (hash_region_of v)) (loc_buffer v)); B.modifies_buffer_elim v p h0 h1 private noextract val hash_irepr: #hsz:hash_size_t -> Ghost.erased (hash_repr #hsz) let hash_irepr #hsz = Ghost.hide (S.create (U32.v hsz) (u8 0)) private noextract val hash_r_alloc_p: #hsz:hash_size_t -> v:hash #hsz -> GTot Type0 let hash_r_alloc_p #_ v = True val hash_r_alloc: #hsz':Ghost.erased hash_size_t -> hsz:hash_size_t { hsz == Ghost.reveal hsz' } -> r:HST.erid -> HST.ST (hash #hsz) (requires (fun h0 -> true)) (ensures (fun h0 v h1 -> Set.subset (Map.domain (MHS.get_hmap h0)) (Map.domain (MHS.get_hmap h1)) /\ modifies loc_none h0 h1 /\ hash_r_alloc_p #hsz v /\ hash_r_inv h1 v /\ hash_region_of v = r /\ hash_r_repr h1 v == Ghost.reveal hash_irepr /\ B.fresh_loc (B.loc_buffer v) h0 h1)) let hash_r_alloc #_ s r = B.malloc r (u8 0) s val hash_r_free: #hsz':Ghost.erased hash_size_t -> hsz:hash_size_t { hsz == Ghost.reveal hsz' } -> v:hash #hsz' -> HST.ST unit (requires fun h0 -> hash_r_inv h0 v) (ensures fun h0 _ h1 -> modifies (loc_all_regions_from false (hash_region_of v)) h0 h1) let hash_r_free #_ _ v = B.free v noextract inline_for_extraction val hreg (hsz:hash_size_t): regional (hash_size_t) (hash #hsz) let hreg hsz = Rgl #(hash_size_t) #(hash #hsz) hsz (hash_region_of #hsz) (B.loc_buffer) (hash_dummy #hsz) (hash_r_inv #hsz) (hash_r_inv_reg #hsz) (hash_repr #hsz) (hash_r_repr #hsz) (hash_r_sep #hsz) (hash_irepr #hsz) (hash_r_alloc_p #hsz) (hash_r_alloc #hsz) (hash_r_free #hsz) private val hash_copy: #s':Ghost.erased hash_size_t -> s:hash_size_t { s == Ghost.reveal s' } -> src:hash #s -> dst:hash #s -> HST.ST unit (requires fun h0 -> hash_r_inv h0 src /\ hash_r_inv h0 dst /\ HH.disjoint (hash_region_of src) (hash_region_of dst)) (ensures fun h0 _ h1 -> modifies (loc_all_regions_from false (hash_region_of dst)) h0 h1 /\ hash_r_inv h1 dst /\ hash_r_repr h1 dst == hash_r_repr h0 src) let hash_copy #_ s src dst = B.blit src 0ul dst 0ul s /// JP: so much stuff happening here. First, single-constructor, single-argument /// elimination takes places and Cpy becomes completely eliminated, in favor of /// just being a type alias for the underlying function. So now, we have a /// function that returns a function pointer. /// /// Next, one might think that the hsz argument is going to be eliminated. It's /// not, because there's a hidden implicit argument to Cpy which is (hreg hsz), /// meaning that hsz is used at run-time even though Cpy is only using this /// argument ghostly. This would be have to be fixed. /// /// Finally, if the inline_for_extraction is removed, there seems to be a /// karamel bug that inserts a void*0. To be fixed. inline_for_extraction val hcpy: hsz:hash_size_t -> copyable #hash_size_t (hash #hsz) (hreg hsz) let hcpy hsz = Cpy (hash_copy #hsz) type hash_vec (#hsz:hash_size_t) = RV.rvector (hreg hsz) /// 2. `rvector hash` is regional type rhst (hsz:hash_size_t) = regional hash_size_t (hash #hsz) private noextract val hash_vec_region_of: #hsz:hash_size_t -> v:hash_vec #hsz -> GTot HH.rid let hash_vec_region_of #_ v = V.frameOf v private inline_for_extraction val hash_vec_dummy: (#hsz:Ghost.erased hash_size_t) -> hash_vec #hsz let hash_vec_dummy #_ = V.alloc_empty (hash #_) noextract val hash_vec_r_inv: #hsz:hash_size_t -> h:HS.mem -> v:hash_vec #hsz -> GTot Type0 let hash_vec_r_inv #hsz h v = RV.rv_inv h v noextract val hash_vec_r_inv_reg: #hsz:hash_size_t -> h:HS.mem -> v:hash_vec #hsz -> Lemma (requires (hash_vec_r_inv h v)) (ensures (MHS.live_region h (hash_vec_region_of v))) let hash_vec_r_inv_reg #_ h v = () private noextract val hash_vec_repr: #hsz:hash_size_t -> Type0 let hash_vec_repr #hsz = MTH.hashes #(U32.v hsz) noextract val hash_vec_r_repr: #hsz:hash_size_t -> h:HS.mem -> v:hash_vec #hsz {hash_vec_r_inv h v} -> GTot (hash_vec_repr #hsz) let hash_vec_r_repr #_ h v = RV.as_seq h v noextract val hash_vec_r_sep: #hsz:hash_size_t -> v:hash_vec #hsz -> p:loc -> h0:HS.mem -> h1:HS.mem -> Lemma (requires (hash_vec_r_inv h0 v /\ loc_disjoint (loc_all_regions_from false (hash_vec_region_of v)) p /\ modifies p h0 h1)) (ensures (hash_vec_r_inv h1 v /\ hash_vec_r_repr h0 v == hash_vec_r_repr h1 v)) let hash_vec_r_sep #_ v p h0 h1 = RV.rv_inv_preserved v p h0 h1; RV.as_seq_preserved v p h0 h1 noextract val hash_vec_irepr: #hsz:hash_size_t -> Ghost.erased (hash_vec_repr #hsz) let hash_vec_irepr #_ = Ghost.hide S.empty noextract val hash_vec_r_alloc_p: #hsz:hash_size_t -> v:hash_vec #hsz -> GTot Type0 let hash_vec_r_alloc_p #_ v = V.size_of v = 0ul #push-options "--initial_fuel 1 --max_fuel 1" val hash_vec_r_alloc: #hsz':Ghost.erased hash_size_t -> hsz:hash_size_t { hsz == Ghost.reveal hsz' } -> r:HST.erid -> HST.ST (hash_vec #hsz) (requires (fun h0 -> true)) (ensures (fun h0 v h1 -> Set.subset (Map.domain (MHS.get_hmap h0)) (Map.domain (MHS.get_hmap h1)) /\ modifies loc_none h0 h1 /\ hash_vec_r_alloc_p v /\ hash_vec_r_inv h1 v /\ hash_vec_region_of v = r /\ hash_vec_r_repr h1 v == Ghost.reveal hash_vec_irepr /\ B.fresh_loc (V.loc_vector v) h0 h1)) let hash_vec_r_alloc #_ hsz r = let nrid = HST.new_region r in // Note: here we are not creating a generic parameterized regional, we are // creating a specialized regional vector of hashes, so we don't need to go // through a run-time indirection to figure out what the dummy default element // is; we know it's the one for hashes V.alloc_reserve 1ul (hash_dummy #hsz) r #pop-options val hash_vec_r_free: #hsz':Ghost.erased hash_size_t -> hsz:hash_size_t { hsz == Ghost.reveal hsz' } -> v:hash_vec #hsz -> HST.ST unit (requires (fun h0 -> hash_vec_r_inv h0 v)) (ensures (fun h0 _ h1 ->
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "MerkleTree.New.High.fst.checked", "LowStar.Vector.fst.checked", "LowStar.RVector.fst.checked", "LowStar.Regional.Instances.fst.checked", "LowStar.Regional.fst.checked", "LowStar.ConstBuffer.fsti.checked", "LowStar.BufferOps.fst.checked", "LowStar.Buffer.fst.checked", "Lib.IntTypes.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Set.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Monotonic.HyperStack.fsti.checked", "FStar.Monotonic.HyperHeap.fsti.checked", "FStar.Map.fsti.checked", "FStar.Integers.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked", "FStar.All.fst.checked", "EverCrypt.Helpers.fsti.checked", "EverCrypt.Hash.fsti.checked" ], "interface_file": false, "source_file": "MerkleTree.Low.Datastructures.fst" }
[ { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "EverCrypt.Helpers", "short_module": null }, { "abbrev": true, "full_module": "MerkleTree.New.High", "short_module": "MTH" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": true, "full_module": "EverCrypt.Hash", "short_module": "EHS" }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "S" }, { "abbrev": true, "full_module": "LowStar.Regional.Instances", "short_module": "RVI" }, { "abbrev": true, "full_module": "LowStar.RVector", "short_module": "RV" }, { "abbrev": true, "full_module": "LowStar.Vector", "short_module": "V" }, { "abbrev": true, "full_module": "LowStar.ConstBuffer", "short_module": "CB" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.Monotonic.HyperHeap", "short_module": "HH" }, { "abbrev": true, "full_module": "FStar.Monotonic.HyperStack", "short_module": "MHS" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": false, "full_module": "LowStar.Regional.Instances", "short_module": null }, { "abbrev": false, "full_module": "LowStar.RVector", "short_module": null }, { "abbrev": false, "full_module": "LowStar.Regional", "short_module": null }, { "abbrev": false, "full_module": "LowStar.Vector", "short_module": null }, { "abbrev": false, "full_module": "LowStar.BufferOps", "short_module": null }, { "abbrev": false, "full_module": "LowStar.Buffer", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.Integers", "short_module": null }, { "abbrev": false, "full_module": "FStar.All", "short_module": null }, { "abbrev": false, "full_module": "MerkleTree.Low", "short_module": null }, { "abbrev": false, "full_module": "MerkleTree.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": 0, "initial_ifuel": 0, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 10, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
hsz: MerkleTree.Low.Datastructures.hash_size_t{hsz == FStar.Ghost.reveal hsz'} -> v: MerkleTree.Low.Datastructures.hash_vec -> FStar.HyperStack.ST.ST Prims.unit
FStar.HyperStack.ST.ST
[]
[]
[ "FStar.Ghost.erased", "MerkleTree.Low.Datastructures.hash_size_t", "Prims.eq2", "FStar.Ghost.reveal", "MerkleTree.Low.Datastructures.hash_vec", "LowStar.RVector.free", "MerkleTree.Low.Datastructures.hash", "MerkleTree.Low.Datastructures.hreg", "Prims.unit" ]
[]
false
true
false
false
false
let hash_vec_r_free #_ hsz v =
RV.free v
false
Vale.AES.X64.GCMdecryptOpt.fsti
Vale.AES.X64.GCMdecryptOpt.va_req_Gcm_blocks_decrypt_stdcall
val va_req_Gcm_blocks_decrypt_stdcall (va_b0: va_code) (va_s0: va_state) (win: bool) (alg: algorithm) (auth_b: buffer128) (auth_bytes auth_num: nat64) (keys_b iv_b: buffer128) (iv: supported_iv_LE) (hkeys_b abytes_b in128x6_b out128x6_b: buffer128) (len128x6_num: nat64) (in128_b out128_b: buffer128) (len128_num: nat64) (inout_b: buffer128) (cipher_num: nat64) (scratch_b tag_b: buffer128) (key: (seq nat32)) : prop
val va_req_Gcm_blocks_decrypt_stdcall (va_b0: va_code) (va_s0: va_state) (win: bool) (alg: algorithm) (auth_b: buffer128) (auth_bytes auth_num: nat64) (keys_b iv_b: buffer128) (iv: supported_iv_LE) (hkeys_b abytes_b in128x6_b out128x6_b: buffer128) (len128x6_num: nat64) (in128_b out128_b: buffer128) (len128_num: nat64) (inout_b: buffer128) (cipher_num: nat64) (scratch_b tag_b: buffer128) (key: (seq nat32)) : prop
let va_req_Gcm_blocks_decrypt_stdcall (va_b0:va_code) (va_s0:va_state) (win:bool) (alg:algorithm) (auth_b:buffer128) (auth_bytes:nat64) (auth_num:nat64) (keys_b:buffer128) (iv_b:buffer128) (iv:supported_iv_LE) (hkeys_b:buffer128) (abytes_b:buffer128) (in128x6_b:buffer128) (out128x6_b:buffer128) (len128x6_num:nat64) (in128_b:buffer128) (out128_b:buffer128) (len128_num:nat64) (inout_b:buffer128) (cipher_num:nat64) (scratch_b:buffer128) (tag_b:buffer128) (key:(seq nat32)) : prop = (va_require_total va_b0 (va_code_Gcm_blocks_decrypt_stdcall win alg) va_s0 /\ va_get_ok va_s0 /\ (let (auth_ptr:(va_int_range 0 18446744073709551615)) = (if win then va_get_reg64 rRcx va_s0 else va_get_reg64 rRdi va_s0) in let (auth_num_bytes:(va_int_range 0 18446744073709551615)) = (if win then va_get_reg64 rRdx va_s0 else va_get_reg64 rRsi va_s0) in let (auth_len:(va_int_range 0 18446744073709551615)) = (if win then va_get_reg64 rR8 va_s0 else va_get_reg64 rRdx va_s0) in let (keys_ptr:(va_int_range 0 18446744073709551615)) = (if win then va_get_reg64 rR9 va_s0 else va_get_reg64 rRcx va_s0) in let (iv_ptr:(va_int_range 0 18446744073709551615)) = (if win then Vale.X64.Stack_i.load_stack64 (va_get_reg64 rRsp va_s0 + 32 + 8 + 0) (va_get_stack va_s0) else va_get_reg64 rR8 va_s0) in let (xip:(va_int_range 0 18446744073709551615)) = (if win then Vale.X64.Stack_i.load_stack64 (va_get_reg64 rRsp va_s0 + 32 + 8 + 8) (va_get_stack va_s0) else va_get_reg64 rR9 va_s0) in let (abytes_ptr:(va_int_range 0 18446744073709551615)) = (if win then Vale.X64.Stack_i.load_stack64 (va_get_reg64 rRsp va_s0 + 40 + 16) (va_get_stack va_s0) else Vale.X64.Stack_i.load_stack64 (va_get_reg64 rRsp va_s0 + 8 + 0) (va_get_stack va_s0)) in let (in128x6_ptr:(va_int_range 0 18446744073709551615)) = (if win then Vale.X64.Stack_i.load_stack64 (va_get_reg64 rRsp va_s0 + 40 + 24) (va_get_stack va_s0) else Vale.X64.Stack_i.load_stack64 (va_get_reg64 rRsp va_s0 + 8 + 8) (va_get_stack va_s0)) in let (out128x6_ptr:(va_int_range 0 18446744073709551615)) = (if win then Vale.X64.Stack_i.load_stack64 (va_get_reg64 rRsp va_s0 + 40 + 32) (va_get_stack va_s0) else Vale.X64.Stack_i.load_stack64 (va_get_reg64 rRsp va_s0 + 8 + 16) (va_get_stack va_s0)) in let (len128x6:(va_int_range 0 18446744073709551615)) = (if win then Vale.X64.Stack_i.load_stack64 (va_get_reg64 rRsp va_s0 + 40 + 40) (va_get_stack va_s0) else Vale.X64.Stack_i.load_stack64 (va_get_reg64 rRsp va_s0 + 8 + 24) (va_get_stack va_s0)) in let (in128_ptr:(va_int_range 0 18446744073709551615)) = (if win then Vale.X64.Stack_i.load_stack64 (va_get_reg64 rRsp va_s0 + 40 + 48) (va_get_stack va_s0) else Vale.X64.Stack_i.load_stack64 (va_get_reg64 rRsp va_s0 + 8 + 32) (va_get_stack va_s0)) in let (out128_ptr:(va_int_range 0 18446744073709551615)) = (if win then Vale.X64.Stack_i.load_stack64 (va_get_reg64 rRsp va_s0 + 40 + 56) (va_get_stack va_s0) else Vale.X64.Stack_i.load_stack64 (va_get_reg64 rRsp va_s0 + 8 + 40) (va_get_stack va_s0)) in let (len128:(va_int_range 0 18446744073709551615)) = (if win then Vale.X64.Stack_i.load_stack64 (va_get_reg64 rRsp va_s0 + 40 + 64) (va_get_stack va_s0) else Vale.X64.Stack_i.load_stack64 (va_get_reg64 rRsp va_s0 + 8 + 48) (va_get_stack va_s0)) in let (inout_ptr:(va_int_range 0 18446744073709551615)) = (if win then Vale.X64.Stack_i.load_stack64 (va_get_reg64 rRsp va_s0 + 40 + 72) (va_get_stack va_s0) else Vale.X64.Stack_i.load_stack64 (va_get_reg64 rRsp va_s0 + 8 + 56) (va_get_stack va_s0)) in let (cipher_num_bytes:(va_int_range 0 18446744073709551615)) = (if win then Vale.X64.Stack_i.load_stack64 (va_get_reg64 rRsp va_s0 + 40 + 80) (va_get_stack va_s0) else Vale.X64.Stack_i.load_stack64 (va_get_reg64 rRsp va_s0 + 8 + 64) (va_get_stack va_s0)) in let (scratch_ptr:(va_int_range 0 18446744073709551615)) = (if win then Vale.X64.Stack_i.load_stack64 (va_get_reg64 rRsp va_s0 + 40 + 88) (va_get_stack va_s0) else Vale.X64.Stack_i.load_stack64 (va_get_reg64 rRsp va_s0 + 8 + 72) (va_get_stack va_s0)) in let (tag_ptr:(va_int_range 0 18446744073709551615)) = (if win then Vale.X64.Stack_i.load_stack64 (va_get_reg64 rRsp va_s0 + 40 + 96) (va_get_stack va_s0) else Vale.X64.Stack_i.load_stack64 (va_get_reg64 rRsp va_s0 + 8 + 80) (va_get_stack va_s0)) in sse_enabled /\ movbe_enabled /\ va_get_reg64 rRsp va_s0 == Vale.X64.Stack_i.init_rsp (va_get_stack va_s0) /\ Vale.X64.Memory.is_initial_heap (va_get_mem_layout va_s0) (va_get_mem va_s0) /\ (~win ==> Vale.X64.Stack_i.valid_stack_slot64 (va_get_reg64 rRsp va_s0 + 8 + 0) (va_get_stack va_s0) Public (va_get_stackTaint va_s0)) /\ (~win ==> Vale.X64.Stack_i.valid_stack_slot64 (va_get_reg64 rRsp va_s0 + 8 + 8) (va_get_stack va_s0) Public (va_get_stackTaint va_s0)) /\ (~win ==> Vale.X64.Stack_i.valid_stack_slot64 (va_get_reg64 rRsp va_s0 + 8 + 16) (va_get_stack va_s0) Public (va_get_stackTaint va_s0)) /\ (~win ==> Vale.X64.Stack_i.valid_stack_slot64 (va_get_reg64 rRsp va_s0 + 8 + 24) (va_get_stack va_s0) Public (va_get_stackTaint va_s0)) /\ (~win ==> Vale.X64.Stack_i.valid_stack_slot64 (va_get_reg64 rRsp va_s0 + 8 + 32) (va_get_stack va_s0) Public (va_get_stackTaint va_s0)) /\ (~win ==> Vale.X64.Stack_i.valid_stack_slot64 (va_get_reg64 rRsp va_s0 + 8 + 40) (va_get_stack va_s0) Public (va_get_stackTaint va_s0)) /\ (~win ==> Vale.X64.Stack_i.valid_stack_slot64 (va_get_reg64 rRsp va_s0 + 8 + 48) (va_get_stack va_s0) Public (va_get_stackTaint va_s0)) /\ (~win ==> Vale.X64.Stack_i.valid_stack_slot64 (va_get_reg64 rRsp va_s0 + 8 + 56) (va_get_stack va_s0) Public (va_get_stackTaint va_s0)) /\ (~win ==> Vale.X64.Stack_i.valid_stack_slot64 (va_get_reg64 rRsp va_s0 + 8 + 64) (va_get_stack va_s0) Public (va_get_stackTaint va_s0)) /\ (~win ==> Vale.X64.Stack_i.valid_stack_slot64 (va_get_reg64 rRsp va_s0 + 8 + 72) (va_get_stack va_s0) Public (va_get_stackTaint va_s0)) /\ (~win ==> Vale.X64.Stack_i.valid_stack_slot64 (va_get_reg64 rRsp va_s0 + 8 + 80) (va_get_stack va_s0) Public (va_get_stackTaint va_s0)) /\ (win ==> Vale.X64.Stack_i.valid_stack_slot64 (va_get_reg64 rRsp va_s0 + 40 + 0) (va_get_stack va_s0) Public (va_get_stackTaint va_s0)) /\ (win ==> Vale.X64.Stack_i.valid_stack_slot64 (va_get_reg64 rRsp va_s0 + 40 + 8) (va_get_stack va_s0) Public (va_get_stackTaint va_s0)) /\ (win ==> Vale.X64.Stack_i.valid_stack_slot64 (va_get_reg64 rRsp va_s0 + 40 + 16) (va_get_stack va_s0) Public (va_get_stackTaint va_s0)) /\ (win ==> Vale.X64.Stack_i.valid_stack_slot64 (va_get_reg64 rRsp va_s0 + 40 + 24) (va_get_stack va_s0) Public (va_get_stackTaint va_s0)) /\ (win ==> Vale.X64.Stack_i.valid_stack_slot64 (va_get_reg64 rRsp va_s0 + 40 + 32) (va_get_stack va_s0) Public (va_get_stackTaint va_s0)) /\ (win ==> Vale.X64.Stack_i.valid_stack_slot64 (va_get_reg64 rRsp va_s0 + 40 + 40) (va_get_stack va_s0) Public (va_get_stackTaint va_s0)) /\ (win ==> Vale.X64.Stack_i.valid_stack_slot64 (va_get_reg64 rRsp va_s0 + 40 + 48) (va_get_stack va_s0) Public (va_get_stackTaint va_s0)) /\ (win ==> Vale.X64.Stack_i.valid_stack_slot64 (va_get_reg64 rRsp va_s0 + 40 + 56) (va_get_stack va_s0) Public (va_get_stackTaint va_s0)) /\ (win ==> Vale.X64.Stack_i.valid_stack_slot64 (va_get_reg64 rRsp va_s0 + 40 + 64) (va_get_stack va_s0) Public (va_get_stackTaint va_s0)) /\ (win ==> Vale.X64.Stack_i.valid_stack_slot64 (va_get_reg64 rRsp va_s0 + 40 + 72) (va_get_stack va_s0) Public (va_get_stackTaint va_s0)) /\ (win ==> Vale.X64.Stack_i.valid_stack_slot64 (va_get_reg64 rRsp va_s0 + 40 + 80) (va_get_stack va_s0) Public (va_get_stackTaint va_s0)) /\ (win ==> Vale.X64.Stack_i.valid_stack_slot64 (va_get_reg64 rRsp va_s0 + 40 + 88) (va_get_stack va_s0) Public (va_get_stackTaint va_s0)) /\ (win ==> Vale.X64.Stack_i.valid_stack_slot64 (va_get_reg64 rRsp va_s0 + 40 + 96) (va_get_stack va_s0) Public (va_get_stackTaint va_s0)) /\ auth_len == auth_num /\ auth_num_bytes == auth_bytes /\ len128x6 == len128x6_num /\ len128 == len128_num /\ cipher_num_bytes == cipher_num /\ Vale.X64.Decls.validSrcAddrs128 (va_get_mem va_s0) auth_ptr auth_b auth_len (va_get_mem_layout va_s0) Secret /\ Vale.X64.Decls.validSrcAddrs128 (va_get_mem va_s0) abytes_ptr abytes_b 1 (va_get_mem_layout va_s0) Secret /\ Vale.X64.Decls.validDstAddrs128 (va_get_mem va_s0) iv_ptr iv_b 1 (va_get_mem_layout va_s0) Public /\ Vale.X64.Decls.validSrcAddrs128 (va_get_mem va_s0) in128x6_ptr in128x6_b len128x6 (va_get_mem_layout va_s0) Secret /\ Vale.X64.Decls.validDstAddrs128 (va_get_mem va_s0) out128x6_ptr out128x6_b len128x6 (va_get_mem_layout va_s0) Secret /\ Vale.X64.Decls.validSrcAddrs128 (va_get_mem va_s0) in128_ptr in128_b len128 (va_get_mem_layout va_s0) Secret /\ Vale.X64.Decls.validDstAddrs128 (va_get_mem va_s0) out128_ptr out128_b len128 (va_get_mem_layout va_s0) Secret /\ Vale.X64.Decls.validDstAddrs128 (va_get_mem va_s0) inout_ptr inout_b 1 (va_get_mem_layout va_s0) Secret /\ Vale.X64.Decls.validDstAddrs128 (va_get_mem va_s0) scratch_ptr scratch_b 9 (va_get_mem_layout va_s0) Secret /\ Vale.X64.Decls.validSrcAddrs128 (va_get_mem va_s0) xip hkeys_b 8 (va_get_mem_layout va_s0) Secret /\ Vale.X64.Decls.validDstAddrs128 (va_get_mem va_s0) tag_ptr tag_b 1 (va_get_mem_layout va_s0) Secret /\ Vale.X64.Decls.buffer_disjoints128 tag_b ([auth_b; abytes_b; iv_b; in128x6_b; out128x6_b; in128_b; out128_b; inout_b; scratch_b]) /\ Vale.X64.Decls.buffer_disjoints128 iv_b ([keys_b; auth_b; abytes_b; in128x6_b; out128x6_b; in128_b; out128_b; inout_b; scratch_b; hkeys_b]) /\ Vale.X64.Decls.buffer_disjoints128 scratch_b ([keys_b; auth_b; abytes_b; in128x6_b; out128x6_b; in128_b; out128_b; inout_b; hkeys_b]) /\ Vale.X64.Decls.buffer_disjoints128 inout_b ([keys_b; auth_b; abytes_b; in128x6_b; out128x6_b; in128_b; out128_b; hkeys_b]) /\ Vale.X64.Decls.buffer_disjoints128 auth_b ([keys_b; abytes_b; hkeys_b]) /\ Vale.X64.Decls.buffer_disjoints128 abytes_b ([keys_b; hkeys_b]) /\ Vale.X64.Decls.buffer_disjoints128 out128x6_b ([keys_b; auth_b; abytes_b; hkeys_b; in128_b; inout_b]) /\ Vale.X64.Decls.buffer_disjoints128 in128x6_b ([keys_b; auth_b; abytes_b; hkeys_b; in128_b; inout_b]) /\ Vale.X64.Decls.buffer_disjoints128 out128_b ([keys_b; auth_b; abytes_b; hkeys_b; in128x6_b; out128x6_b; inout_b]) /\ Vale.X64.Decls.buffer_disjoints128 in128_b ([keys_b; auth_b; abytes_b; hkeys_b; in128x6_b; out128x6_b; inout_b]) /\ (Vale.X64.Decls.buffers_disjoint128 in128x6_b out128x6_b \/ in128x6_b == out128x6_b) /\ (Vale.X64.Decls.buffers_disjoint128 in128_b out128_b \/ in128_b == out128_b) /\ auth_ptr + 16 `op_Multiply` auth_len < pow2_64 /\ in128x6_ptr + 16 `op_Multiply` len128x6 < pow2_64 /\ out128x6_ptr + 16 `op_Multiply` len128x6 < pow2_64 /\ in128_ptr + 16 `op_Multiply` len128 < pow2_64 /\ out128_ptr + 16 `op_Multiply` len128 < pow2_64 /\ inout_ptr + 16 < pow2_64 /\ Vale.X64.Decls.buffer_length #Vale.X64.Memory.vuint128 auth_b == auth_len /\ Vale.X64.Decls.buffer_length #Vale.X64.Memory.vuint128 abytes_b == 1 /\ Vale.X64.Decls.buffer_length #Vale.X64.Memory.vuint128 in128x6_b == Vale.X64.Decls.buffer_length #Vale.X64.Memory.vuint128 out128x6_b /\ Vale.X64.Decls.buffer_length #Vale.X64.Memory.vuint128 in128_b == Vale.X64.Decls.buffer_length #Vale.X64.Memory.vuint128 out128_b /\ Vale.X64.Decls.buffer_length #Vale.X64.Memory.vuint128 in128x6_b == len128x6 /\ Vale.X64.Decls.buffer_length #Vale.X64.Memory.vuint128 in128_b == len128 /\ Vale.X64.Decls.buffer_length #Vale.X64.Memory.vuint128 inout_b == 1 /\ cipher_num_bytes < pow2_32 /\ auth_num_bytes < pow2_32 /\ xip + 32 < pow2_64 /\ Vale.X64.Memory.buffer_addr #Vale.X64.Memory.vuint128 keys_b (va_get_mem va_s0) + 128 < pow2_64 /\ len128x6 `op_Modulus` 6 == 0 /\ (len128x6 > 0 ==> len128x6 >= 6) /\ 12 + len128x6 + 6 < pow2_32 /\ (va_mul_nat len128x6 (128 `op_Division` 8) + va_mul_nat len128 (128 `op_Division` 8) <= cipher_num_bytes /\ cipher_num_bytes < va_mul_nat len128x6 (128 `op_Division` 8) + va_mul_nat len128 (128 `op_Division` 8) + 128 `op_Division` 8) /\ (va_mul_nat auth_len (128 `op_Division` 8) <= auth_num_bytes /\ auth_num_bytes < va_mul_nat auth_len (128 `op_Division` 8) + 128 `op_Division` 8) /\ aes_reqs alg key (Vale.X64.Decls.buffer128_as_seq (va_get_mem va_s0) keys_b) keys_b keys_ptr (va_get_mem va_s0) (va_get_mem_layout va_s0) /\ pclmulqdq_enabled /\ Vale.AES.OptPublic.hkeys_reqs_pub (Vale.X64.Decls.s128 (va_get_mem va_s0) hkeys_b) (Vale.Def.Types_s.reverse_bytes_quad32 (Vale.AES.AES_s.aes_encrypt_LE alg key (Vale.Def.Words_s.Mkfour #Vale.Def.Types_s.nat32 0 0 0 0))) /\ (let h_LE = Vale.AES.AES_s.aes_encrypt_LE alg key (Vale.Def.Words_s.Mkfour #Vale.Def.Types_s.nat32 0 0 0 0) in let iv_BE = Vale.X64.Decls.buffer128_read iv_b 0 (va_get_mem va_s0) in iv_BE == Vale.AES.GCM_s.compute_iv_BE h_LE iv)))
{ "file_name": "obj/Vale.AES.X64.GCMdecryptOpt.fsti", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 43, "end_line": 203, "start_col": 0, "start_line": 63 }
module Vale.AES.X64.GCMdecryptOpt open Vale.Def.Prop_s open Vale.Def.Opaque_s open FStar.Seq open Vale.Def.Words_s open Vale.Def.Words.Seq_s open Vale.Def.Types_s open Vale.Arch.Types open Vale.Arch.HeapImpl open Vale.AES.AES_s open Vale.AES.GCTR_s open Vale.AES.GCTR open Vale.AES.GCM open Vale.AES.GHash_s open Vale.AES.GHash open Vale.AES.GCM_s open Vale.AES.X64.AES open Vale.AES.GF128_s open Vale.AES.GF128 open Vale.Poly1305.Math open Vale.AES.GCM_helpers open Vale.AES.X64.GHash open Vale.AES.X64.GCTR open Vale.X64.Machine_s open Vale.X64.Memory open Vale.X64.Stack_i open Vale.X64.State open Vale.X64.Decls open Vale.X64.InsBasic open Vale.X64.InsMem open Vale.X64.InsVector open Vale.X64.InsStack open Vale.X64.InsAes open Vale.X64.QuickCode open Vale.X64.QuickCodes open Vale.AES.X64.GF128_Mul open Vale.X64.Stack open Vale.X64.CPU_Features_s open Vale.Math.Poly2.Bits_s open Vale.AES.X64.AESopt open Vale.AES.X64.AESGCM open Vale.AES.X64.AESopt2 open Vale.Lib.Meta open Vale.AES.X64.GCMencryptOpt open Vale.AES.OptPublic let aes_reqs (alg:algorithm) (key:seq nat32) (round_keys:seq quad32) (keys_b:buffer128) (key_ptr:int) (heap0:vale_heap) (layout:vale_heap_layout) : prop0 = aesni_enabled /\ avx_enabled /\ (alg = AES_128 \/ alg = AES_256) /\ is_aes_key_LE alg key /\ length(round_keys) == nr(alg) + 1 /\ round_keys == key_to_round_keys_LE alg key /\ validSrcAddrs128 heap0 key_ptr keys_b (nr alg + 1) layout Secret /\ s128 heap0 keys_b == round_keys #reset-options "--z3rlimit 100 --max_ifuel 0" //-- Gcm_blocks_decrypt_stdcall val va_code_Gcm_blocks_decrypt_stdcall : win:bool -> alg:algorithm -> Tot va_code
{ "checked_file": "/", "dependencies": [ "Vale.X64.State.fsti.checked", "Vale.X64.Stack_i.fsti.checked", "Vale.X64.Stack.fsti.checked", "Vale.X64.QuickCodes.fsti.checked", "Vale.X64.QuickCode.fst.checked", "Vale.X64.Memory.fsti.checked", "Vale.X64.Machine_s.fst.checked", "Vale.X64.InsVector.fsti.checked", "Vale.X64.InsStack.fsti.checked", "Vale.X64.InsMem.fsti.checked", "Vale.X64.InsBasic.fsti.checked", "Vale.X64.InsAes.fsti.checked", "Vale.X64.Flags.fsti.checked", "Vale.X64.Decls.fsti.checked", "Vale.X64.CPU_Features_s.fst.checked", "Vale.Poly1305.Math.fsti.checked", "Vale.Math.Poly2.Bits_s.fsti.checked", "Vale.Lib.Meta.fsti.checked", "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.Arch.HeapImpl.fsti.checked", "Vale.AES.X64.GHash.fsti.checked", "Vale.AES.X64.GF128_Mul.fsti.checked", "Vale.AES.X64.GCTR.fsti.checked", "Vale.AES.X64.GCMencryptOpt.fsti.checked", "Vale.AES.X64.AESopt2.fsti.checked", "Vale.AES.X64.AESopt.fsti.checked", "Vale.AES.X64.AESGCM.fsti.checked", "Vale.AES.X64.AES.fsti.checked", "Vale.AES.OptPublic.fsti.checked", "Vale.AES.GHash_s.fst.checked", "Vale.AES.GHash.fsti.checked", "Vale.AES.GF128_s.fsti.checked", "Vale.AES.GF128.fsti.checked", "Vale.AES.GCTR_s.fst.checked", "Vale.AES.GCTR.fsti.checked", "Vale.AES.GCM_s.fst.checked", "Vale.AES.GCM_helpers.fsti.checked", "Vale.AES.GCM.fsti.checked", "Vale.AES.AES_s.fst.checked", "Vale.AES.AES_common_s.fst.checked", "prims.fst.checked", "FStar.Seq.Base.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked" ], "interface_file": false, "source_file": "Vale.AES.X64.GCMdecryptOpt.fsti" }
[ { "abbrev": false, "full_module": "Vale.Lib.Basic", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.OptPublic", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.X64.GCMencryptOpt", "short_module": null }, { "abbrev": false, "full_module": "Vale.Lib.Meta", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.X64.AESopt2", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.X64.AESGCM", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.X64.AESopt", "short_module": null }, { "abbrev": false, "full_module": "Vale.Math.Poly2.Bits_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.CPU_Features_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Stack", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.X64.GF128_Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.QuickCodes", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.QuickCode", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.InsAes", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.InsStack", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.InsVector", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.InsMem", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.InsBasic", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Decls", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.State", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Stack_i", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Memory", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Machine_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.X64.GCTR", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.X64.GHash", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GCM_helpers", "short_module": null }, { "abbrev": false, "full_module": "Vale.Poly1305.Math", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GF128", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GF128_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.X64.AES", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GCM_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GHash", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GHash_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GCM", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GCTR", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GCTR_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.AES_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.HeapImpl", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.Types", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Types_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Seq_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Seq", "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.OptPublic", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.X64.GCMencryptOpt", "short_module": null }, { "abbrev": false, "full_module": "Vale.Lib.Meta", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.X64.AESopt2", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.X64.AESGCM", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.X64.AESopt", "short_module": null }, { "abbrev": false, "full_module": "Vale.Math.Poly2.Bits_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.CPU_Features_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Stack", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.X64.GF128_Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.QuickCodes", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.QuickCode", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.InsAes", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.InsStack", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.InsVector", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.InsMem", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.InsBasic", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Decls", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.State", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Stack_i", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Memory", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Machine_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.X64.GCTR", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.X64.GHash", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GCM_helpers", "short_module": null }, { "abbrev": false, "full_module": "Vale.Poly1305.Math", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GF128", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GF128_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.X64.AES", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GCM_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GHash", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GHash_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GCM", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GCTR", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GCTR_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.AES_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.HeapImpl", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.Types", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Types_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Seq_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Seq", "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.X64", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.X64", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 0, "max_fuel": 1, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": true, "smtencoding_l_arith_repr": "native", "smtencoding_nl_arith_repr": "wrapped", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [ "smt.arith.nl=false", "smt.QI.EAGER_THRESHOLD=100", "smt.CASE_SPLIT=3" ], "z3refresh": false, "z3rlimit": 100, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
va_b0: Vale.X64.Decls.va_code -> va_s0: Vale.X64.Decls.va_state -> win: Prims.bool -> alg: Vale.AES.AES_common_s.algorithm -> auth_b: Vale.X64.Memory.buffer128 -> auth_bytes: Vale.X64.Memory.nat64 -> auth_num: Vale.X64.Memory.nat64 -> keys_b: Vale.X64.Memory.buffer128 -> iv_b: Vale.X64.Memory.buffer128 -> iv: Vale.AES.GCM_s.supported_iv_LE -> hkeys_b: Vale.X64.Memory.buffer128 -> abytes_b: Vale.X64.Memory.buffer128 -> in128x6_b: Vale.X64.Memory.buffer128 -> out128x6_b: Vale.X64.Memory.buffer128 -> len128x6_num: Vale.X64.Memory.nat64 -> in128_b: Vale.X64.Memory.buffer128 -> out128_b: Vale.X64.Memory.buffer128 -> len128_num: Vale.X64.Memory.nat64 -> inout_b: Vale.X64.Memory.buffer128 -> cipher_num: Vale.X64.Memory.nat64 -> scratch_b: Vale.X64.Memory.buffer128 -> tag_b: Vale.X64.Memory.buffer128 -> key: FStar.Seq.Base.seq Vale.X64.Memory.nat32 -> Prims.prop
Prims.Tot
[ "total" ]
[]
[ "Vale.X64.Decls.va_code", "Vale.X64.Decls.va_state", "Prims.bool", "Vale.AES.AES_common_s.algorithm", "Vale.X64.Memory.buffer128", "Vale.X64.Memory.nat64", "Vale.AES.GCM_s.supported_iv_LE", "FStar.Seq.Base.seq", "Vale.X64.Memory.nat32", "Prims.l_and", "Vale.X64.Decls.va_require_total", "Vale.AES.X64.GCMdecryptOpt.va_code_Gcm_blocks_decrypt_stdcall", "Prims.b2t", "Vale.X64.Decls.va_get_ok", "Vale.X64.CPU_Features_s.sse_enabled", "Vale.X64.CPU_Features_s.movbe_enabled", "Prims.eq2", "Vale.Def.Words_s.nat64", "Vale.X64.Decls.va_get_reg64", "Vale.X64.Machine_s.rRsp", "Vale.X64.Stack_i.init_rsp", "Vale.X64.Decls.va_get_stack", "Vale.X64.Memory.is_initial_heap", "Vale.X64.Decls.va_get_mem_layout", "Vale.X64.Decls.va_get_mem", "Prims.l_imp", "Prims.l_not", "Vale.X64.Stack_i.valid_stack_slot64", "Prims.op_Addition", "Vale.Arch.HeapTypes_s.Public", "Vale.X64.Decls.va_get_stackTaint", "Prims.int", "Prims.l_or", "Prims.op_GreaterThanOrEqual", "Prims.op_LessThan", "Vale.Def.Words_s.pow2_64", "Prims.op_LessThanOrEqual", "Vale.X64.Decls.validSrcAddrs128", "Vale.Arch.HeapTypes_s.Secret", "Vale.X64.Decls.validDstAddrs128", "Vale.X64.Decls.buffer_disjoints128", "Prims.Cons", "Prims.Nil", "Vale.X64.Decls.buffers_disjoint128", "Prims.op_Multiply", "Vale.X64.Machine_s.pow2_64", "Vale.X64.Decls.buffer_length", "Vale.X64.Memory.vuint128", "Prims.nat", "Vale.X64.Machine_s.pow2_32", "Vale.X64.Memory.buffer_addr", "Prims.op_Modulus", "Prims.op_GreaterThan", "Vale.X64.Decls.va_mul_nat", "Prims.op_Division", "Vale.AES.X64.GCMdecryptOpt.aes_reqs", "Vale.X64.Decls.buffer128_as_seq", "Vale.X64.CPU_Features_s.pclmulqdq_enabled", "Vale.AES.OptPublic.hkeys_reqs_pub", "Vale.X64.Decls.s128", "Vale.Def.Types_s.reverse_bytes_quad32", "Vale.AES.AES_s.aes_encrypt_LE", "Vale.Def.Words_s.Mkfour", "Vale.Def.Types_s.nat32", "Vale.Def.Types_s.quad32", "Vale.AES.GCM_s.compute_iv_BE", "Vale.X64.Decls.buffer128_read", "Vale.X64.Decls.va_int_range", "Vale.X64.Stack_i.load_stack64", "Vale.X64.Machine_s.rR9", "Vale.X64.Machine_s.rR8", "Vale.X64.Machine_s.rRcx", "Vale.X64.Machine_s.rRdx", "Vale.X64.Machine_s.rRsi", "Vale.X64.Machine_s.rRdi", "Prims.prop" ]
[]
false
false
false
true
true
let va_req_Gcm_blocks_decrypt_stdcall (va_b0: va_code) (va_s0: va_state) (win: bool) (alg: algorithm) (auth_b: buffer128) (auth_bytes auth_num: nat64) (keys_b iv_b: buffer128) (iv: supported_iv_LE) (hkeys_b abytes_b in128x6_b out128x6_b: buffer128) (len128x6_num: nat64) (in128_b out128_b: buffer128) (len128_num: nat64) (inout_b: buffer128) (cipher_num: nat64) (scratch_b tag_b: buffer128) (key: (seq nat32)) : prop =
(va_require_total va_b0 (va_code_Gcm_blocks_decrypt_stdcall win alg) va_s0 /\ va_get_ok va_s0 /\ (let auth_ptr:(va_int_range 0 18446744073709551615) = (if win then va_get_reg64 rRcx va_s0 else va_get_reg64 rRdi va_s0) in let auth_num_bytes:(va_int_range 0 18446744073709551615) = (if win then va_get_reg64 rRdx va_s0 else va_get_reg64 rRsi va_s0) in let auth_len:(va_int_range 0 18446744073709551615) = (if win then va_get_reg64 rR8 va_s0 else va_get_reg64 rRdx va_s0) in let keys_ptr:(va_int_range 0 18446744073709551615) = (if win then va_get_reg64 rR9 va_s0 else va_get_reg64 rRcx va_s0) in let iv_ptr:(va_int_range 0 18446744073709551615) = (if win then Vale.X64.Stack_i.load_stack64 (va_get_reg64 rRsp va_s0 + 32 + 8 + 0) (va_get_stack va_s0) else va_get_reg64 rR8 va_s0) in let xip:(va_int_range 0 18446744073709551615) = (if win then Vale.X64.Stack_i.load_stack64 (va_get_reg64 rRsp va_s0 + 32 + 8 + 8) (va_get_stack va_s0) else va_get_reg64 rR9 va_s0) in let abytes_ptr:(va_int_range 0 18446744073709551615) = (if win then Vale.X64.Stack_i.load_stack64 (va_get_reg64 rRsp va_s0 + 40 + 16) (va_get_stack va_s0) else Vale.X64.Stack_i.load_stack64 (va_get_reg64 rRsp va_s0 + 8 + 0) (va_get_stack va_s0)) in let in128x6_ptr:(va_int_range 0 18446744073709551615) = (if win then Vale.X64.Stack_i.load_stack64 (va_get_reg64 rRsp va_s0 + 40 + 24) (va_get_stack va_s0) else Vale.X64.Stack_i.load_stack64 (va_get_reg64 rRsp va_s0 + 8 + 8) (va_get_stack va_s0)) in let out128x6_ptr:(va_int_range 0 18446744073709551615) = (if win then Vale.X64.Stack_i.load_stack64 (va_get_reg64 rRsp va_s0 + 40 + 32) (va_get_stack va_s0) else Vale.X64.Stack_i.load_stack64 (va_get_reg64 rRsp va_s0 + 8 + 16) (va_get_stack va_s0)) in let len128x6:(va_int_range 0 18446744073709551615) = (if win then Vale.X64.Stack_i.load_stack64 (va_get_reg64 rRsp va_s0 + 40 + 40) (va_get_stack va_s0) else Vale.X64.Stack_i.load_stack64 (va_get_reg64 rRsp va_s0 + 8 + 24) (va_get_stack va_s0)) in let in128_ptr:(va_int_range 0 18446744073709551615) = (if win then Vale.X64.Stack_i.load_stack64 (va_get_reg64 rRsp va_s0 + 40 + 48) (va_get_stack va_s0) else Vale.X64.Stack_i.load_stack64 (va_get_reg64 rRsp va_s0 + 8 + 32) (va_get_stack va_s0)) in let out128_ptr:(va_int_range 0 18446744073709551615) = (if win then Vale.X64.Stack_i.load_stack64 (va_get_reg64 rRsp va_s0 + 40 + 56) (va_get_stack va_s0) else Vale.X64.Stack_i.load_stack64 (va_get_reg64 rRsp va_s0 + 8 + 40) (va_get_stack va_s0)) in let len128:(va_int_range 0 18446744073709551615) = (if win then Vale.X64.Stack_i.load_stack64 (va_get_reg64 rRsp va_s0 + 40 + 64) (va_get_stack va_s0) else Vale.X64.Stack_i.load_stack64 (va_get_reg64 rRsp va_s0 + 8 + 48) (va_get_stack va_s0)) in let inout_ptr:(va_int_range 0 18446744073709551615) = (if win then Vale.X64.Stack_i.load_stack64 (va_get_reg64 rRsp va_s0 + 40 + 72) (va_get_stack va_s0) else Vale.X64.Stack_i.load_stack64 (va_get_reg64 rRsp va_s0 + 8 + 56) (va_get_stack va_s0)) in let cipher_num_bytes:(va_int_range 0 18446744073709551615) = (if win then Vale.X64.Stack_i.load_stack64 (va_get_reg64 rRsp va_s0 + 40 + 80) (va_get_stack va_s0) else Vale.X64.Stack_i.load_stack64 (va_get_reg64 rRsp va_s0 + 8 + 64) (va_get_stack va_s0)) in let scratch_ptr:(va_int_range 0 18446744073709551615) = (if win then Vale.X64.Stack_i.load_stack64 (va_get_reg64 rRsp va_s0 + 40 + 88) (va_get_stack va_s0) else Vale.X64.Stack_i.load_stack64 (va_get_reg64 rRsp va_s0 + 8 + 72) (va_get_stack va_s0)) in let tag_ptr:(va_int_range 0 18446744073709551615) = (if win then Vale.X64.Stack_i.load_stack64 (va_get_reg64 rRsp va_s0 + 40 + 96) (va_get_stack va_s0) else Vale.X64.Stack_i.load_stack64 (va_get_reg64 rRsp va_s0 + 8 + 80) (va_get_stack va_s0)) in sse_enabled /\ movbe_enabled /\ va_get_reg64 rRsp va_s0 == Vale.X64.Stack_i.init_rsp (va_get_stack va_s0) /\ Vale.X64.Memory.is_initial_heap (va_get_mem_layout va_s0) (va_get_mem va_s0) /\ (~win ==> Vale.X64.Stack_i.valid_stack_slot64 (va_get_reg64 rRsp va_s0 + 8 + 0) (va_get_stack va_s0) Public (va_get_stackTaint va_s0)) /\ (~win ==> Vale.X64.Stack_i.valid_stack_slot64 (va_get_reg64 rRsp va_s0 + 8 + 8) (va_get_stack va_s0) Public (va_get_stackTaint va_s0)) /\ (~win ==> Vale.X64.Stack_i.valid_stack_slot64 (va_get_reg64 rRsp va_s0 + 8 + 16) (va_get_stack va_s0) Public (va_get_stackTaint va_s0)) /\ (~win ==> Vale.X64.Stack_i.valid_stack_slot64 (va_get_reg64 rRsp va_s0 + 8 + 24) (va_get_stack va_s0) Public (va_get_stackTaint va_s0)) /\ (~win ==> Vale.X64.Stack_i.valid_stack_slot64 (va_get_reg64 rRsp va_s0 + 8 + 32) (va_get_stack va_s0) Public (va_get_stackTaint va_s0)) /\ (~win ==> Vale.X64.Stack_i.valid_stack_slot64 (va_get_reg64 rRsp va_s0 + 8 + 40) (va_get_stack va_s0) Public (va_get_stackTaint va_s0)) /\ (~win ==> Vale.X64.Stack_i.valid_stack_slot64 (va_get_reg64 rRsp va_s0 + 8 + 48) (va_get_stack va_s0) Public (va_get_stackTaint va_s0)) /\ (~win ==> Vale.X64.Stack_i.valid_stack_slot64 (va_get_reg64 rRsp va_s0 + 8 + 56) (va_get_stack va_s0) Public (va_get_stackTaint va_s0)) /\ (~win ==> Vale.X64.Stack_i.valid_stack_slot64 (va_get_reg64 rRsp va_s0 + 8 + 64) (va_get_stack va_s0) Public (va_get_stackTaint va_s0)) /\ (~win ==> Vale.X64.Stack_i.valid_stack_slot64 (va_get_reg64 rRsp va_s0 + 8 + 72) (va_get_stack va_s0) Public (va_get_stackTaint va_s0)) /\ (~win ==> Vale.X64.Stack_i.valid_stack_slot64 (va_get_reg64 rRsp va_s0 + 8 + 80) (va_get_stack va_s0) Public (va_get_stackTaint va_s0)) /\ (win ==> Vale.X64.Stack_i.valid_stack_slot64 (va_get_reg64 rRsp va_s0 + 40 + 0) (va_get_stack va_s0) Public (va_get_stackTaint va_s0)) /\ (win ==> Vale.X64.Stack_i.valid_stack_slot64 (va_get_reg64 rRsp va_s0 + 40 + 8) (va_get_stack va_s0) Public (va_get_stackTaint va_s0)) /\ (win ==> Vale.X64.Stack_i.valid_stack_slot64 (va_get_reg64 rRsp va_s0 + 40 + 16) (va_get_stack va_s0) Public (va_get_stackTaint va_s0)) /\ (win ==> Vale.X64.Stack_i.valid_stack_slot64 (va_get_reg64 rRsp va_s0 + 40 + 24) (va_get_stack va_s0) Public (va_get_stackTaint va_s0)) /\ (win ==> Vale.X64.Stack_i.valid_stack_slot64 (va_get_reg64 rRsp va_s0 + 40 + 32) (va_get_stack va_s0) Public (va_get_stackTaint va_s0)) /\ (win ==> Vale.X64.Stack_i.valid_stack_slot64 (va_get_reg64 rRsp va_s0 + 40 + 40) (va_get_stack va_s0) Public (va_get_stackTaint va_s0)) /\ (win ==> Vale.X64.Stack_i.valid_stack_slot64 (va_get_reg64 rRsp va_s0 + 40 + 48) (va_get_stack va_s0) Public (va_get_stackTaint va_s0)) /\ (win ==> Vale.X64.Stack_i.valid_stack_slot64 (va_get_reg64 rRsp va_s0 + 40 + 56) (va_get_stack va_s0) Public (va_get_stackTaint va_s0)) /\ (win ==> Vale.X64.Stack_i.valid_stack_slot64 (va_get_reg64 rRsp va_s0 + 40 + 64) (va_get_stack va_s0) Public (va_get_stackTaint va_s0)) /\ (win ==> Vale.X64.Stack_i.valid_stack_slot64 (va_get_reg64 rRsp va_s0 + 40 + 72) (va_get_stack va_s0) Public (va_get_stackTaint va_s0)) /\ (win ==> Vale.X64.Stack_i.valid_stack_slot64 (va_get_reg64 rRsp va_s0 + 40 + 80) (va_get_stack va_s0) Public (va_get_stackTaint va_s0)) /\ (win ==> Vale.X64.Stack_i.valid_stack_slot64 (va_get_reg64 rRsp va_s0 + 40 + 88) (va_get_stack va_s0) Public (va_get_stackTaint va_s0)) /\ (win ==> Vale.X64.Stack_i.valid_stack_slot64 (va_get_reg64 rRsp va_s0 + 40 + 96) (va_get_stack va_s0) Public (va_get_stackTaint va_s0)) /\ auth_len == auth_num /\ auth_num_bytes == auth_bytes /\ len128x6 == len128x6_num /\ len128 == len128_num /\ cipher_num_bytes == cipher_num /\ Vale.X64.Decls.validSrcAddrs128 (va_get_mem va_s0) auth_ptr auth_b auth_len (va_get_mem_layout va_s0) Secret /\ Vale.X64.Decls.validSrcAddrs128 (va_get_mem va_s0) abytes_ptr abytes_b 1 (va_get_mem_layout va_s0) Secret /\ Vale.X64.Decls.validDstAddrs128 (va_get_mem va_s0) iv_ptr iv_b 1 (va_get_mem_layout va_s0) Public /\ Vale.X64.Decls.validSrcAddrs128 (va_get_mem va_s0) in128x6_ptr in128x6_b len128x6 (va_get_mem_layout va_s0) Secret /\ Vale.X64.Decls.validDstAddrs128 (va_get_mem va_s0) out128x6_ptr out128x6_b len128x6 (va_get_mem_layout va_s0) Secret /\ Vale.X64.Decls.validSrcAddrs128 (va_get_mem va_s0) in128_ptr in128_b len128 (va_get_mem_layout va_s0) Secret /\ Vale.X64.Decls.validDstAddrs128 (va_get_mem va_s0) out128_ptr out128_b len128 (va_get_mem_layout va_s0) Secret /\ Vale.X64.Decls.validDstAddrs128 (va_get_mem va_s0) inout_ptr inout_b 1 (va_get_mem_layout va_s0) Secret /\ Vale.X64.Decls.validDstAddrs128 (va_get_mem va_s0) scratch_ptr scratch_b 9 (va_get_mem_layout va_s0) Secret /\ Vale.X64.Decls.validSrcAddrs128 (va_get_mem va_s0) xip hkeys_b 8 (va_get_mem_layout va_s0) Secret /\ Vale.X64.Decls.validDstAddrs128 (va_get_mem va_s0) tag_ptr tag_b 1 (va_get_mem_layout va_s0) Secret /\ Vale.X64.Decls.buffer_disjoints128 tag_b ([auth_b; abytes_b; iv_b; in128x6_b; out128x6_b; in128_b; out128_b; inout_b; scratch_b]) /\ Vale.X64.Decls.buffer_disjoints128 iv_b ([ keys_b; auth_b; abytes_b; in128x6_b; out128x6_b; in128_b; out128_b; inout_b; scratch_b; hkeys_b ]) /\ Vale.X64.Decls.buffer_disjoints128 scratch_b ([keys_b; auth_b; abytes_b; in128x6_b; out128x6_b; in128_b; out128_b; inout_b; hkeys_b]) /\ Vale.X64.Decls.buffer_disjoints128 inout_b ([keys_b; auth_b; abytes_b; in128x6_b; out128x6_b; in128_b; out128_b; hkeys_b]) /\ Vale.X64.Decls.buffer_disjoints128 auth_b ([keys_b; abytes_b; hkeys_b]) /\ Vale.X64.Decls.buffer_disjoints128 abytes_b ([keys_b; hkeys_b]) /\ Vale.X64.Decls.buffer_disjoints128 out128x6_b ([keys_b; auth_b; abytes_b; hkeys_b; in128_b; inout_b]) /\ Vale.X64.Decls.buffer_disjoints128 in128x6_b ([keys_b; auth_b; abytes_b; hkeys_b; in128_b; inout_b]) /\ Vale.X64.Decls.buffer_disjoints128 out128_b ([keys_b; auth_b; abytes_b; hkeys_b; in128x6_b; out128x6_b; inout_b]) /\ Vale.X64.Decls.buffer_disjoints128 in128_b ([keys_b; auth_b; abytes_b; hkeys_b; in128x6_b; out128x6_b; inout_b]) /\ (Vale.X64.Decls.buffers_disjoint128 in128x6_b out128x6_b \/ in128x6_b == out128x6_b) /\ (Vale.X64.Decls.buffers_disjoint128 in128_b out128_b \/ in128_b == out128_b) /\ auth_ptr + 16 `op_Multiply` auth_len < pow2_64 /\ in128x6_ptr + 16 `op_Multiply` len128x6 < pow2_64 /\ out128x6_ptr + 16 `op_Multiply` len128x6 < pow2_64 /\ in128_ptr + 16 `op_Multiply` len128 < pow2_64 /\ out128_ptr + 16 `op_Multiply` len128 < pow2_64 /\ inout_ptr + 16 < pow2_64 /\ Vale.X64.Decls.buffer_length #Vale.X64.Memory.vuint128 auth_b == auth_len /\ Vale.X64.Decls.buffer_length #Vale.X64.Memory.vuint128 abytes_b == 1 /\ Vale.X64.Decls.buffer_length #Vale.X64.Memory.vuint128 in128x6_b == Vale.X64.Decls.buffer_length #Vale.X64.Memory.vuint128 out128x6_b /\ Vale.X64.Decls.buffer_length #Vale.X64.Memory.vuint128 in128_b == Vale.X64.Decls.buffer_length #Vale.X64.Memory.vuint128 out128_b /\ Vale.X64.Decls.buffer_length #Vale.X64.Memory.vuint128 in128x6_b == len128x6 /\ Vale.X64.Decls.buffer_length #Vale.X64.Memory.vuint128 in128_b == len128 /\ Vale.X64.Decls.buffer_length #Vale.X64.Memory.vuint128 inout_b == 1 /\ cipher_num_bytes < pow2_32 /\ auth_num_bytes < pow2_32 /\ xip + 32 < pow2_64 /\ Vale.X64.Memory.buffer_addr #Vale.X64.Memory.vuint128 keys_b (va_get_mem va_s0) + 128 < pow2_64 /\ len128x6 `op_Modulus` 6 == 0 /\ (len128x6 > 0 ==> len128x6 >= 6) /\ 12 + len128x6 + 6 < pow2_32 /\ (va_mul_nat len128x6 (128 `op_Division` 8) + va_mul_nat len128 (128 `op_Division` 8) <= cipher_num_bytes /\ cipher_num_bytes < va_mul_nat len128x6 (128 `op_Division` 8) + va_mul_nat len128 (128 `op_Division` 8) + 128 `op_Division` 8) /\ (va_mul_nat auth_len (128 `op_Division` 8) <= auth_num_bytes /\ auth_num_bytes < va_mul_nat auth_len (128 `op_Division` 8) + 128 `op_Division` 8) /\ aes_reqs alg key (Vale.X64.Decls.buffer128_as_seq (va_get_mem va_s0) keys_b) keys_b keys_ptr (va_get_mem va_s0) (va_get_mem_layout va_s0) /\ pclmulqdq_enabled /\ Vale.AES.OptPublic.hkeys_reqs_pub (Vale.X64.Decls.s128 (va_get_mem va_s0) hkeys_b) (Vale.Def.Types_s.reverse_bytes_quad32 (Vale.AES.AES_s.aes_encrypt_LE alg key (Vale.Def.Words_s.Mkfour #Vale.Def.Types_s.nat32 0 0 0 0))) /\ (let h_LE = Vale.AES.AES_s.aes_encrypt_LE alg key (Vale.Def.Words_s.Mkfour #Vale.Def.Types_s.nat32 0 0 0 0) in let iv_BE = Vale.X64.Decls.buffer128_read iv_b 0 (va_get_mem va_s0) in iv_BE == Vale.AES.GCM_s.compute_iv_BE h_LE iv)))
false
MerkleTree.Low.Datastructures.fst
MerkleTree.Low.Datastructures.hash_vec_irepr
val hash_vec_irepr: #hsz:hash_size_t -> Ghost.erased (hash_vec_repr #hsz)
val hash_vec_irepr: #hsz:hash_size_t -> Ghost.erased (hash_vec_repr #hsz)
let hash_vec_irepr #_ = Ghost.hide S.empty
{ "file_name": "src/MerkleTree.Low.Datastructures.fst", "git_rev": "7d7bdc20f2033171e279c176b26e84f9069d23c6", "git_url": "https://github.com/hacl-star/merkle-tree.git", "project_name": "merkle-tree" }
{ "end_col": 42, "end_line": 249, "start_col": 0, "start_line": 249 }
module MerkleTree.Low.Datastructures open FStar.All open FStar.Integers open FStar.Mul open LowStar.Buffer open LowStar.BufferOps open LowStar.Vector open LowStar.Regional open LowStar.RVector open LowStar.Regional.Instances module HS = FStar.HyperStack module HST = FStar.HyperStack.ST module MHS = FStar.Monotonic.HyperStack module HH = FStar.Monotonic.HyperHeap module B = LowStar.Buffer module CB = LowStar.ConstBuffer module V = LowStar.Vector module RV = LowStar.RVector module RVI = LowStar.Regional.Instances module S = FStar.Seq module EHS = EverCrypt.Hash module U32 = FStar.UInt32 module MTH = MerkleTree.New.High open EverCrypt.Helpers open Lib.IntTypes #set-options "--z3rlimit 10 --initial_fuel 0 --max_fuel 0 --initial_ifuel 0 --max_ifuel 0" type hash_size_t = n:uint32_t{n > 0ul} type hash (#hsz:hash_size_t) = b:B.buffer uint8 { B.len b = hsz \/ B.g_is_null b } // We cannot use `Low.RVector.Instances`, where we have some general // typeclass instances of `regional`, e.g., if `rg:regional a` then // `regional (rvector rg)`. In FStar we can use this, but KaRaMeL currently // cannot deal with this and gives a number of errors. // So we temporarily instantiate some `regional`s manually below, which is // extractable to C by KaRaMeL. /// Some instantiations of `regional` used in Merkle tree /// 1. `hash` is regional private noextract val hash_region_of: #hsz:hash_size_t -> v:hash #hsz -> GTot HH.rid let hash_region_of #_ v = B.frameOf v private inline_for_extraction val hash_dummy: #hsz:Ghost.erased hash_size_t -> Tot (hash #hsz) let hash_dummy #_ = B.null private noextract val hash_r_inv: #hsz:hash_size_t -> h:HS.mem -> v:hash #hsz -> GTot Type0 let hash_r_inv #hsz h v = B.live h v /\ B.freeable v /\ B.len v = hsz private noextract val hash_r_inv_reg: #hsz:hash_size_t -> h:HS.mem -> v:hash -> Lemma (requires hash_r_inv h v) (ensures MHS.live_region h (hash_region_of #hsz v)) let hash_r_inv_reg #_ h v = () private noextract val hash_repr (#hsz:hash_size_t): Type0 let hash_repr #hsz = MTH.hash #(U32.v hsz) private noextract val hash_r_repr: #hsz:hash_size_t -> h:HS.mem -> v:hash{hash_r_inv #hsz h v} -> GTot (hash_repr #hsz) let hash_r_repr #_ h v = B.as_seq h v private noextract val hash_r_sep: #hsz:hash_size_t -> v:hash #hsz -> p:loc -> h0:HS.mem -> h1:HS.mem -> Lemma (requires hash_r_inv h0 v /\ loc_disjoint (loc_all_regions_from false (hash_region_of v)) p /\ modifies p h0 h1) (ensures hash_r_inv h1 v /\ hash_r_repr h0 v == hash_r_repr h1 v) let hash_r_sep #_ v p h0 h1 = assert (loc_includes (loc_all_regions_from false (hash_region_of v)) (loc_buffer v)); B.modifies_buffer_elim v p h0 h1 private noextract val hash_irepr: #hsz:hash_size_t -> Ghost.erased (hash_repr #hsz) let hash_irepr #hsz = Ghost.hide (S.create (U32.v hsz) (u8 0)) private noextract val hash_r_alloc_p: #hsz:hash_size_t -> v:hash #hsz -> GTot Type0 let hash_r_alloc_p #_ v = True val hash_r_alloc: #hsz':Ghost.erased hash_size_t -> hsz:hash_size_t { hsz == Ghost.reveal hsz' } -> r:HST.erid -> HST.ST (hash #hsz) (requires (fun h0 -> true)) (ensures (fun h0 v h1 -> Set.subset (Map.domain (MHS.get_hmap h0)) (Map.domain (MHS.get_hmap h1)) /\ modifies loc_none h0 h1 /\ hash_r_alloc_p #hsz v /\ hash_r_inv h1 v /\ hash_region_of v = r /\ hash_r_repr h1 v == Ghost.reveal hash_irepr /\ B.fresh_loc (B.loc_buffer v) h0 h1)) let hash_r_alloc #_ s r = B.malloc r (u8 0) s val hash_r_free: #hsz':Ghost.erased hash_size_t -> hsz:hash_size_t { hsz == Ghost.reveal hsz' } -> v:hash #hsz' -> HST.ST unit (requires fun h0 -> hash_r_inv h0 v) (ensures fun h0 _ h1 -> modifies (loc_all_regions_from false (hash_region_of v)) h0 h1) let hash_r_free #_ _ v = B.free v noextract inline_for_extraction val hreg (hsz:hash_size_t): regional (hash_size_t) (hash #hsz) let hreg hsz = Rgl #(hash_size_t) #(hash #hsz) hsz (hash_region_of #hsz) (B.loc_buffer) (hash_dummy #hsz) (hash_r_inv #hsz) (hash_r_inv_reg #hsz) (hash_repr #hsz) (hash_r_repr #hsz) (hash_r_sep #hsz) (hash_irepr #hsz) (hash_r_alloc_p #hsz) (hash_r_alloc #hsz) (hash_r_free #hsz) private val hash_copy: #s':Ghost.erased hash_size_t -> s:hash_size_t { s == Ghost.reveal s' } -> src:hash #s -> dst:hash #s -> HST.ST unit (requires fun h0 -> hash_r_inv h0 src /\ hash_r_inv h0 dst /\ HH.disjoint (hash_region_of src) (hash_region_of dst)) (ensures fun h0 _ h1 -> modifies (loc_all_regions_from false (hash_region_of dst)) h0 h1 /\ hash_r_inv h1 dst /\ hash_r_repr h1 dst == hash_r_repr h0 src) let hash_copy #_ s src dst = B.blit src 0ul dst 0ul s /// JP: so much stuff happening here. First, single-constructor, single-argument /// elimination takes places and Cpy becomes completely eliminated, in favor of /// just being a type alias for the underlying function. So now, we have a /// function that returns a function pointer. /// /// Next, one might think that the hsz argument is going to be eliminated. It's /// not, because there's a hidden implicit argument to Cpy which is (hreg hsz), /// meaning that hsz is used at run-time even though Cpy is only using this /// argument ghostly. This would be have to be fixed. /// /// Finally, if the inline_for_extraction is removed, there seems to be a /// karamel bug that inserts a void*0. To be fixed. inline_for_extraction val hcpy: hsz:hash_size_t -> copyable #hash_size_t (hash #hsz) (hreg hsz) let hcpy hsz = Cpy (hash_copy #hsz) type hash_vec (#hsz:hash_size_t) = RV.rvector (hreg hsz) /// 2. `rvector hash` is regional type rhst (hsz:hash_size_t) = regional hash_size_t (hash #hsz) private noextract val hash_vec_region_of: #hsz:hash_size_t -> v:hash_vec #hsz -> GTot HH.rid let hash_vec_region_of #_ v = V.frameOf v private inline_for_extraction val hash_vec_dummy: (#hsz:Ghost.erased hash_size_t) -> hash_vec #hsz let hash_vec_dummy #_ = V.alloc_empty (hash #_) noextract val hash_vec_r_inv: #hsz:hash_size_t -> h:HS.mem -> v:hash_vec #hsz -> GTot Type0 let hash_vec_r_inv #hsz h v = RV.rv_inv h v noextract val hash_vec_r_inv_reg: #hsz:hash_size_t -> h:HS.mem -> v:hash_vec #hsz -> Lemma (requires (hash_vec_r_inv h v)) (ensures (MHS.live_region h (hash_vec_region_of v))) let hash_vec_r_inv_reg #_ h v = () private noextract val hash_vec_repr: #hsz:hash_size_t -> Type0 let hash_vec_repr #hsz = MTH.hashes #(U32.v hsz) noextract val hash_vec_r_repr: #hsz:hash_size_t -> h:HS.mem -> v:hash_vec #hsz {hash_vec_r_inv h v} -> GTot (hash_vec_repr #hsz) let hash_vec_r_repr #_ h v = RV.as_seq h v noextract val hash_vec_r_sep: #hsz:hash_size_t -> v:hash_vec #hsz -> p:loc -> h0:HS.mem -> h1:HS.mem -> Lemma (requires (hash_vec_r_inv h0 v /\ loc_disjoint (loc_all_regions_from false (hash_vec_region_of v)) p /\ modifies p h0 h1)) (ensures (hash_vec_r_inv h1 v /\ hash_vec_r_repr h0 v == hash_vec_r_repr h1 v)) let hash_vec_r_sep #_ v p h0 h1 = RV.rv_inv_preserved v p h0 h1; RV.as_seq_preserved v p h0 h1 noextract
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "MerkleTree.New.High.fst.checked", "LowStar.Vector.fst.checked", "LowStar.RVector.fst.checked", "LowStar.Regional.Instances.fst.checked", "LowStar.Regional.fst.checked", "LowStar.ConstBuffer.fsti.checked", "LowStar.BufferOps.fst.checked", "LowStar.Buffer.fst.checked", "Lib.IntTypes.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Set.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Monotonic.HyperStack.fsti.checked", "FStar.Monotonic.HyperHeap.fsti.checked", "FStar.Map.fsti.checked", "FStar.Integers.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked", "FStar.All.fst.checked", "EverCrypt.Helpers.fsti.checked", "EverCrypt.Hash.fsti.checked" ], "interface_file": false, "source_file": "MerkleTree.Low.Datastructures.fst" }
[ { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "EverCrypt.Helpers", "short_module": null }, { "abbrev": true, "full_module": "MerkleTree.New.High", "short_module": "MTH" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": true, "full_module": "EverCrypt.Hash", "short_module": "EHS" }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "S" }, { "abbrev": true, "full_module": "LowStar.Regional.Instances", "short_module": "RVI" }, { "abbrev": true, "full_module": "LowStar.RVector", "short_module": "RV" }, { "abbrev": true, "full_module": "LowStar.Vector", "short_module": "V" }, { "abbrev": true, "full_module": "LowStar.ConstBuffer", "short_module": "CB" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.Monotonic.HyperHeap", "short_module": "HH" }, { "abbrev": true, "full_module": "FStar.Monotonic.HyperStack", "short_module": "MHS" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": false, "full_module": "LowStar.Regional.Instances", "short_module": null }, { "abbrev": false, "full_module": "LowStar.RVector", "short_module": null }, { "abbrev": false, "full_module": "LowStar.Regional", "short_module": null }, { "abbrev": false, "full_module": "LowStar.Vector", "short_module": null }, { "abbrev": false, "full_module": "LowStar.BufferOps", "short_module": null }, { "abbrev": false, "full_module": "LowStar.Buffer", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.Integers", "short_module": null }, { "abbrev": false, "full_module": "FStar.All", "short_module": null }, { "abbrev": false, "full_module": "MerkleTree.Low", "short_module": null }, { "abbrev": false, "full_module": "MerkleTree.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": 0, "initial_ifuel": 0, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 10, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
FStar.Ghost.erased MerkleTree.Low.Datastructures.hash_vec_repr
Prims.Tot
[ "total" ]
[]
[ "MerkleTree.Low.Datastructures.hash_size_t", "FStar.Ghost.hide", "MerkleTree.Low.Datastructures.hash_vec_repr", "FStar.Seq.Base.empty", "MerkleTree.New.High.hash", "FStar.UInt32.v", "FStar.Ghost.erased" ]
[]
false
false
false
false
false
let hash_vec_irepr #_ =
Ghost.hide S.empty
false
MerkleTree.Low.Datastructures.fst
MerkleTree.Low.Datastructures.hvreg
val hvreg (hsz:hash_size_t): regional hash_size_t (hash_vec #hsz)
val hvreg (hsz:hash_size_t): regional hash_size_t (hash_vec #hsz)
let hvreg hsz = Rgl hsz (hash_vec_region_of #hsz) V.loc_vector (hash_vec_dummy #hsz) (hash_vec_r_inv #hsz) (hash_vec_r_inv_reg #hsz) (hash_vec_repr #hsz) (hash_vec_r_repr #hsz) (hash_vec_r_sep #hsz) (hash_vec_irepr #hsz) (hash_vec_r_alloc_p #hsz) (hash_vec_r_alloc #hsz) (hash_vec_r_free #hsz)
{ "file_name": "src/MerkleTree.Low.Datastructures.fst", "git_rev": "7d7bdc20f2033171e279c176b26e84f9069d23c6", "git_url": "https://github.com/hacl-star/merkle-tree.git", "project_name": "merkle-tree" }
{ "end_col": 28, "end_line": 314, "start_col": 0, "start_line": 301 }
module MerkleTree.Low.Datastructures open FStar.All open FStar.Integers open FStar.Mul open LowStar.Buffer open LowStar.BufferOps open LowStar.Vector open LowStar.Regional open LowStar.RVector open LowStar.Regional.Instances module HS = FStar.HyperStack module HST = FStar.HyperStack.ST module MHS = FStar.Monotonic.HyperStack module HH = FStar.Monotonic.HyperHeap module B = LowStar.Buffer module CB = LowStar.ConstBuffer module V = LowStar.Vector module RV = LowStar.RVector module RVI = LowStar.Regional.Instances module S = FStar.Seq module EHS = EverCrypt.Hash module U32 = FStar.UInt32 module MTH = MerkleTree.New.High open EverCrypt.Helpers open Lib.IntTypes #set-options "--z3rlimit 10 --initial_fuel 0 --max_fuel 0 --initial_ifuel 0 --max_ifuel 0" type hash_size_t = n:uint32_t{n > 0ul} type hash (#hsz:hash_size_t) = b:B.buffer uint8 { B.len b = hsz \/ B.g_is_null b } // We cannot use `Low.RVector.Instances`, where we have some general // typeclass instances of `regional`, e.g., if `rg:regional a` then // `regional (rvector rg)`. In FStar we can use this, but KaRaMeL currently // cannot deal with this and gives a number of errors. // So we temporarily instantiate some `regional`s manually below, which is // extractable to C by KaRaMeL. /// Some instantiations of `regional` used in Merkle tree /// 1. `hash` is regional private noextract val hash_region_of: #hsz:hash_size_t -> v:hash #hsz -> GTot HH.rid let hash_region_of #_ v = B.frameOf v private inline_for_extraction val hash_dummy: #hsz:Ghost.erased hash_size_t -> Tot (hash #hsz) let hash_dummy #_ = B.null private noextract val hash_r_inv: #hsz:hash_size_t -> h:HS.mem -> v:hash #hsz -> GTot Type0 let hash_r_inv #hsz h v = B.live h v /\ B.freeable v /\ B.len v = hsz private noextract val hash_r_inv_reg: #hsz:hash_size_t -> h:HS.mem -> v:hash -> Lemma (requires hash_r_inv h v) (ensures MHS.live_region h (hash_region_of #hsz v)) let hash_r_inv_reg #_ h v = () private noextract val hash_repr (#hsz:hash_size_t): Type0 let hash_repr #hsz = MTH.hash #(U32.v hsz) private noextract val hash_r_repr: #hsz:hash_size_t -> h:HS.mem -> v:hash{hash_r_inv #hsz h v} -> GTot (hash_repr #hsz) let hash_r_repr #_ h v = B.as_seq h v private noextract val hash_r_sep: #hsz:hash_size_t -> v:hash #hsz -> p:loc -> h0:HS.mem -> h1:HS.mem -> Lemma (requires hash_r_inv h0 v /\ loc_disjoint (loc_all_regions_from false (hash_region_of v)) p /\ modifies p h0 h1) (ensures hash_r_inv h1 v /\ hash_r_repr h0 v == hash_r_repr h1 v) let hash_r_sep #_ v p h0 h1 = assert (loc_includes (loc_all_regions_from false (hash_region_of v)) (loc_buffer v)); B.modifies_buffer_elim v p h0 h1 private noextract val hash_irepr: #hsz:hash_size_t -> Ghost.erased (hash_repr #hsz) let hash_irepr #hsz = Ghost.hide (S.create (U32.v hsz) (u8 0)) private noextract val hash_r_alloc_p: #hsz:hash_size_t -> v:hash #hsz -> GTot Type0 let hash_r_alloc_p #_ v = True val hash_r_alloc: #hsz':Ghost.erased hash_size_t -> hsz:hash_size_t { hsz == Ghost.reveal hsz' } -> r:HST.erid -> HST.ST (hash #hsz) (requires (fun h0 -> true)) (ensures (fun h0 v h1 -> Set.subset (Map.domain (MHS.get_hmap h0)) (Map.domain (MHS.get_hmap h1)) /\ modifies loc_none h0 h1 /\ hash_r_alloc_p #hsz v /\ hash_r_inv h1 v /\ hash_region_of v = r /\ hash_r_repr h1 v == Ghost.reveal hash_irepr /\ B.fresh_loc (B.loc_buffer v) h0 h1)) let hash_r_alloc #_ s r = B.malloc r (u8 0) s val hash_r_free: #hsz':Ghost.erased hash_size_t -> hsz:hash_size_t { hsz == Ghost.reveal hsz' } -> v:hash #hsz' -> HST.ST unit (requires fun h0 -> hash_r_inv h0 v) (ensures fun h0 _ h1 -> modifies (loc_all_regions_from false (hash_region_of v)) h0 h1) let hash_r_free #_ _ v = B.free v noextract inline_for_extraction val hreg (hsz:hash_size_t): regional (hash_size_t) (hash #hsz) let hreg hsz = Rgl #(hash_size_t) #(hash #hsz) hsz (hash_region_of #hsz) (B.loc_buffer) (hash_dummy #hsz) (hash_r_inv #hsz) (hash_r_inv_reg #hsz) (hash_repr #hsz) (hash_r_repr #hsz) (hash_r_sep #hsz) (hash_irepr #hsz) (hash_r_alloc_p #hsz) (hash_r_alloc #hsz) (hash_r_free #hsz) private val hash_copy: #s':Ghost.erased hash_size_t -> s:hash_size_t { s == Ghost.reveal s' } -> src:hash #s -> dst:hash #s -> HST.ST unit (requires fun h0 -> hash_r_inv h0 src /\ hash_r_inv h0 dst /\ HH.disjoint (hash_region_of src) (hash_region_of dst)) (ensures fun h0 _ h1 -> modifies (loc_all_regions_from false (hash_region_of dst)) h0 h1 /\ hash_r_inv h1 dst /\ hash_r_repr h1 dst == hash_r_repr h0 src) let hash_copy #_ s src dst = B.blit src 0ul dst 0ul s /// JP: so much stuff happening here. First, single-constructor, single-argument /// elimination takes places and Cpy becomes completely eliminated, in favor of /// just being a type alias for the underlying function. So now, we have a /// function that returns a function pointer. /// /// Next, one might think that the hsz argument is going to be eliminated. It's /// not, because there's a hidden implicit argument to Cpy which is (hreg hsz), /// meaning that hsz is used at run-time even though Cpy is only using this /// argument ghostly. This would be have to be fixed. /// /// Finally, if the inline_for_extraction is removed, there seems to be a /// karamel bug that inserts a void*0. To be fixed. inline_for_extraction val hcpy: hsz:hash_size_t -> copyable #hash_size_t (hash #hsz) (hreg hsz) let hcpy hsz = Cpy (hash_copy #hsz) type hash_vec (#hsz:hash_size_t) = RV.rvector (hreg hsz) /// 2. `rvector hash` is regional type rhst (hsz:hash_size_t) = regional hash_size_t (hash #hsz) private noextract val hash_vec_region_of: #hsz:hash_size_t -> v:hash_vec #hsz -> GTot HH.rid let hash_vec_region_of #_ v = V.frameOf v private inline_for_extraction val hash_vec_dummy: (#hsz:Ghost.erased hash_size_t) -> hash_vec #hsz let hash_vec_dummy #_ = V.alloc_empty (hash #_) noextract val hash_vec_r_inv: #hsz:hash_size_t -> h:HS.mem -> v:hash_vec #hsz -> GTot Type0 let hash_vec_r_inv #hsz h v = RV.rv_inv h v noextract val hash_vec_r_inv_reg: #hsz:hash_size_t -> h:HS.mem -> v:hash_vec #hsz -> Lemma (requires (hash_vec_r_inv h v)) (ensures (MHS.live_region h (hash_vec_region_of v))) let hash_vec_r_inv_reg #_ h v = () private noextract val hash_vec_repr: #hsz:hash_size_t -> Type0 let hash_vec_repr #hsz = MTH.hashes #(U32.v hsz) noextract val hash_vec_r_repr: #hsz:hash_size_t -> h:HS.mem -> v:hash_vec #hsz {hash_vec_r_inv h v} -> GTot (hash_vec_repr #hsz) let hash_vec_r_repr #_ h v = RV.as_seq h v noextract val hash_vec_r_sep: #hsz:hash_size_t -> v:hash_vec #hsz -> p:loc -> h0:HS.mem -> h1:HS.mem -> Lemma (requires (hash_vec_r_inv h0 v /\ loc_disjoint (loc_all_regions_from false (hash_vec_region_of v)) p /\ modifies p h0 h1)) (ensures (hash_vec_r_inv h1 v /\ hash_vec_r_repr h0 v == hash_vec_r_repr h1 v)) let hash_vec_r_sep #_ v p h0 h1 = RV.rv_inv_preserved v p h0 h1; RV.as_seq_preserved v p h0 h1 noextract val hash_vec_irepr: #hsz:hash_size_t -> Ghost.erased (hash_vec_repr #hsz) let hash_vec_irepr #_ = Ghost.hide S.empty noextract val hash_vec_r_alloc_p: #hsz:hash_size_t -> v:hash_vec #hsz -> GTot Type0 let hash_vec_r_alloc_p #_ v = V.size_of v = 0ul #push-options "--initial_fuel 1 --max_fuel 1" val hash_vec_r_alloc: #hsz':Ghost.erased hash_size_t -> hsz:hash_size_t { hsz == Ghost.reveal hsz' } -> r:HST.erid -> HST.ST (hash_vec #hsz) (requires (fun h0 -> true)) (ensures (fun h0 v h1 -> Set.subset (Map.domain (MHS.get_hmap h0)) (Map.domain (MHS.get_hmap h1)) /\ modifies loc_none h0 h1 /\ hash_vec_r_alloc_p v /\ hash_vec_r_inv h1 v /\ hash_vec_region_of v = r /\ hash_vec_r_repr h1 v == Ghost.reveal hash_vec_irepr /\ B.fresh_loc (V.loc_vector v) h0 h1)) let hash_vec_r_alloc #_ hsz r = let nrid = HST.new_region r in // Note: here we are not creating a generic parameterized regional, we are // creating a specialized regional vector of hashes, so we don't need to go // through a run-time indirection to figure out what the dummy default element // is; we know it's the one for hashes V.alloc_reserve 1ul (hash_dummy #hsz) r #pop-options val hash_vec_r_free: #hsz':Ghost.erased hash_size_t -> hsz:hash_size_t { hsz == Ghost.reveal hsz' } -> v:hash_vec #hsz -> HST.ST unit (requires (fun h0 -> hash_vec_r_inv h0 v)) (ensures (fun h0 _ h1 -> modifies (loc_all_regions_from false (hash_vec_region_of #hsz v)) h0 h1)) let hash_vec_r_free #_ hsz v = RV.free v /// This is nice because the only piece of state that we are keeping is one /// word, the hash size, since we are implementing a specialized instance of /// RVector over hashes of a known length. We could also, for genericity, make /// this a mere application of RVector over hreg, which would be less /// implementation effort, at the expense of a bigger run-time cost since there /// would be extra space in the struct (which is passed by value!) and also a /// run-time indirection to do the lookup of the type class instance for the /// elements of the rvector. noextract inline_for_extraction
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "MerkleTree.New.High.fst.checked", "LowStar.Vector.fst.checked", "LowStar.RVector.fst.checked", "LowStar.Regional.Instances.fst.checked", "LowStar.Regional.fst.checked", "LowStar.ConstBuffer.fsti.checked", "LowStar.BufferOps.fst.checked", "LowStar.Buffer.fst.checked", "Lib.IntTypes.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Set.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Monotonic.HyperStack.fsti.checked", "FStar.Monotonic.HyperHeap.fsti.checked", "FStar.Map.fsti.checked", "FStar.Integers.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked", "FStar.All.fst.checked", "EverCrypt.Helpers.fsti.checked", "EverCrypt.Hash.fsti.checked" ], "interface_file": false, "source_file": "MerkleTree.Low.Datastructures.fst" }
[ { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "EverCrypt.Helpers", "short_module": null }, { "abbrev": true, "full_module": "MerkleTree.New.High", "short_module": "MTH" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": true, "full_module": "EverCrypt.Hash", "short_module": "EHS" }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "S" }, { "abbrev": true, "full_module": "LowStar.Regional.Instances", "short_module": "RVI" }, { "abbrev": true, "full_module": "LowStar.RVector", "short_module": "RV" }, { "abbrev": true, "full_module": "LowStar.Vector", "short_module": "V" }, { "abbrev": true, "full_module": "LowStar.ConstBuffer", "short_module": "CB" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.Monotonic.HyperHeap", "short_module": "HH" }, { "abbrev": true, "full_module": "FStar.Monotonic.HyperStack", "short_module": "MHS" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": false, "full_module": "LowStar.Regional.Instances", "short_module": null }, { "abbrev": false, "full_module": "LowStar.RVector", "short_module": null }, { "abbrev": false, "full_module": "LowStar.Regional", "short_module": null }, { "abbrev": false, "full_module": "LowStar.Vector", "short_module": null }, { "abbrev": false, "full_module": "LowStar.BufferOps", "short_module": null }, { "abbrev": false, "full_module": "LowStar.Buffer", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.Integers", "short_module": null }, { "abbrev": false, "full_module": "FStar.All", "short_module": null }, { "abbrev": false, "full_module": "MerkleTree.Low", "short_module": null }, { "abbrev": false, "full_module": "MerkleTree.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": 0, "initial_ifuel": 0, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 10, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
hsz: MerkleTree.Low.Datastructures.hash_size_t -> LowStar.Regional.regional MerkleTree.Low.Datastructures.hash_size_t MerkleTree.Low.Datastructures.hash_vec
Prims.Tot
[ "total" ]
[]
[ "MerkleTree.Low.Datastructures.hash_size_t", "LowStar.Regional.Rgl", "MerkleTree.Low.Datastructures.hash_vec", "MerkleTree.Low.Datastructures.hash_vec_region_of", "LowStar.Vector.loc_vector", "MerkleTree.Low.Datastructures.hash", "MerkleTree.Low.Datastructures.hash_vec_dummy", "FStar.Ghost.hide", "MerkleTree.Low.Datastructures.hash_vec_r_inv", "MerkleTree.Low.Datastructures.hash_vec_r_inv_reg", "MerkleTree.Low.Datastructures.hash_vec_repr", "MerkleTree.Low.Datastructures.hash_vec_r_repr", "MerkleTree.Low.Datastructures.hash_vec_r_sep", "MerkleTree.Low.Datastructures.hash_vec_irepr", "MerkleTree.Low.Datastructures.hash_vec_r_alloc_p", "MerkleTree.Low.Datastructures.hash_vec_r_alloc", "MerkleTree.Low.Datastructures.hash_vec_r_free", "LowStar.Regional.regional" ]
[]
false
false
false
false
false
let hvreg hsz =
Rgl hsz (hash_vec_region_of #hsz) V.loc_vector (hash_vec_dummy #hsz) (hash_vec_r_inv #hsz) (hash_vec_r_inv_reg #hsz) (hash_vec_repr #hsz) (hash_vec_r_repr #hsz) (hash_vec_r_sep #hsz) (hash_vec_irepr #hsz) (hash_vec_r_alloc_p #hsz) (hash_vec_r_alloc #hsz) (hash_vec_r_free #hsz)
false
MerkleTree.Low.Datastructures.fst
MerkleTree.Low.Datastructures.hash_copy
val hash_copy: #s':Ghost.erased hash_size_t -> s:hash_size_t { s == Ghost.reveal s' } -> src:hash #s -> dst:hash #s -> HST.ST unit (requires fun h0 -> hash_r_inv h0 src /\ hash_r_inv h0 dst /\ HH.disjoint (hash_region_of src) (hash_region_of dst)) (ensures fun h0 _ h1 -> modifies (loc_all_regions_from false (hash_region_of dst)) h0 h1 /\ hash_r_inv h1 dst /\ hash_r_repr h1 dst == hash_r_repr h0 src)
val hash_copy: #s':Ghost.erased hash_size_t -> s:hash_size_t { s == Ghost.reveal s' } -> src:hash #s -> dst:hash #s -> HST.ST unit (requires fun h0 -> hash_r_inv h0 src /\ hash_r_inv h0 dst /\ HH.disjoint (hash_region_of src) (hash_region_of dst)) (ensures fun h0 _ h1 -> modifies (loc_all_regions_from false (hash_region_of dst)) h0 h1 /\ hash_r_inv h1 dst /\ hash_r_repr h1 dst == hash_r_repr h0 src)
let hash_copy #_ s src dst = B.blit src 0ul dst 0ul s
{ "file_name": "src/MerkleTree.Low.Datastructures.fst", "git_rev": "7d7bdc20f2033171e279c176b26e84f9069d23c6", "git_url": "https://github.com/hacl-star/merkle-tree.git", "project_name": "merkle-tree" }
{ "end_col": 26, "end_line": 174, "start_col": 0, "start_line": 173 }
module MerkleTree.Low.Datastructures open FStar.All open FStar.Integers open FStar.Mul open LowStar.Buffer open LowStar.BufferOps open LowStar.Vector open LowStar.Regional open LowStar.RVector open LowStar.Regional.Instances module HS = FStar.HyperStack module HST = FStar.HyperStack.ST module MHS = FStar.Monotonic.HyperStack module HH = FStar.Monotonic.HyperHeap module B = LowStar.Buffer module CB = LowStar.ConstBuffer module V = LowStar.Vector module RV = LowStar.RVector module RVI = LowStar.Regional.Instances module S = FStar.Seq module EHS = EverCrypt.Hash module U32 = FStar.UInt32 module MTH = MerkleTree.New.High open EverCrypt.Helpers open Lib.IntTypes #set-options "--z3rlimit 10 --initial_fuel 0 --max_fuel 0 --initial_ifuel 0 --max_ifuel 0" type hash_size_t = n:uint32_t{n > 0ul} type hash (#hsz:hash_size_t) = b:B.buffer uint8 { B.len b = hsz \/ B.g_is_null b } // We cannot use `Low.RVector.Instances`, where we have some general // typeclass instances of `regional`, e.g., if `rg:regional a` then // `regional (rvector rg)`. In FStar we can use this, but KaRaMeL currently // cannot deal with this and gives a number of errors. // So we temporarily instantiate some `regional`s manually below, which is // extractable to C by KaRaMeL. /// Some instantiations of `regional` used in Merkle tree /// 1. `hash` is regional private noextract val hash_region_of: #hsz:hash_size_t -> v:hash #hsz -> GTot HH.rid let hash_region_of #_ v = B.frameOf v private inline_for_extraction val hash_dummy: #hsz:Ghost.erased hash_size_t -> Tot (hash #hsz) let hash_dummy #_ = B.null private noextract val hash_r_inv: #hsz:hash_size_t -> h:HS.mem -> v:hash #hsz -> GTot Type0 let hash_r_inv #hsz h v = B.live h v /\ B.freeable v /\ B.len v = hsz private noextract val hash_r_inv_reg: #hsz:hash_size_t -> h:HS.mem -> v:hash -> Lemma (requires hash_r_inv h v) (ensures MHS.live_region h (hash_region_of #hsz v)) let hash_r_inv_reg #_ h v = () private noextract val hash_repr (#hsz:hash_size_t): Type0 let hash_repr #hsz = MTH.hash #(U32.v hsz) private noextract val hash_r_repr: #hsz:hash_size_t -> h:HS.mem -> v:hash{hash_r_inv #hsz h v} -> GTot (hash_repr #hsz) let hash_r_repr #_ h v = B.as_seq h v private noextract val hash_r_sep: #hsz:hash_size_t -> v:hash #hsz -> p:loc -> h0:HS.mem -> h1:HS.mem -> Lemma (requires hash_r_inv h0 v /\ loc_disjoint (loc_all_regions_from false (hash_region_of v)) p /\ modifies p h0 h1) (ensures hash_r_inv h1 v /\ hash_r_repr h0 v == hash_r_repr h1 v) let hash_r_sep #_ v p h0 h1 = assert (loc_includes (loc_all_regions_from false (hash_region_of v)) (loc_buffer v)); B.modifies_buffer_elim v p h0 h1 private noextract val hash_irepr: #hsz:hash_size_t -> Ghost.erased (hash_repr #hsz) let hash_irepr #hsz = Ghost.hide (S.create (U32.v hsz) (u8 0)) private noextract val hash_r_alloc_p: #hsz:hash_size_t -> v:hash #hsz -> GTot Type0 let hash_r_alloc_p #_ v = True val hash_r_alloc: #hsz':Ghost.erased hash_size_t -> hsz:hash_size_t { hsz == Ghost.reveal hsz' } -> r:HST.erid -> HST.ST (hash #hsz) (requires (fun h0 -> true)) (ensures (fun h0 v h1 -> Set.subset (Map.domain (MHS.get_hmap h0)) (Map.domain (MHS.get_hmap h1)) /\ modifies loc_none h0 h1 /\ hash_r_alloc_p #hsz v /\ hash_r_inv h1 v /\ hash_region_of v = r /\ hash_r_repr h1 v == Ghost.reveal hash_irepr /\ B.fresh_loc (B.loc_buffer v) h0 h1)) let hash_r_alloc #_ s r = B.malloc r (u8 0) s val hash_r_free: #hsz':Ghost.erased hash_size_t -> hsz:hash_size_t { hsz == Ghost.reveal hsz' } -> v:hash #hsz' -> HST.ST unit (requires fun h0 -> hash_r_inv h0 v) (ensures fun h0 _ h1 -> modifies (loc_all_regions_from false (hash_region_of v)) h0 h1) let hash_r_free #_ _ v = B.free v noextract inline_for_extraction val hreg (hsz:hash_size_t): regional (hash_size_t) (hash #hsz) let hreg hsz = Rgl #(hash_size_t) #(hash #hsz) hsz (hash_region_of #hsz) (B.loc_buffer) (hash_dummy #hsz) (hash_r_inv #hsz) (hash_r_inv_reg #hsz) (hash_repr #hsz) (hash_r_repr #hsz) (hash_r_sep #hsz) (hash_irepr #hsz) (hash_r_alloc_p #hsz) (hash_r_alloc #hsz) (hash_r_free #hsz) private val hash_copy: #s':Ghost.erased hash_size_t -> s:hash_size_t { s == Ghost.reveal s' } -> src:hash #s -> dst:hash #s -> HST.ST unit (requires fun h0 -> hash_r_inv h0 src /\ hash_r_inv h0 dst /\ HH.disjoint (hash_region_of src) (hash_region_of dst)) (ensures fun h0 _ h1 -> modifies (loc_all_regions_from false (hash_region_of dst)) h0 h1 /\ hash_r_inv h1 dst /\
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "MerkleTree.New.High.fst.checked", "LowStar.Vector.fst.checked", "LowStar.RVector.fst.checked", "LowStar.Regional.Instances.fst.checked", "LowStar.Regional.fst.checked", "LowStar.ConstBuffer.fsti.checked", "LowStar.BufferOps.fst.checked", "LowStar.Buffer.fst.checked", "Lib.IntTypes.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Set.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Monotonic.HyperStack.fsti.checked", "FStar.Monotonic.HyperHeap.fsti.checked", "FStar.Map.fsti.checked", "FStar.Integers.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked", "FStar.All.fst.checked", "EverCrypt.Helpers.fsti.checked", "EverCrypt.Hash.fsti.checked" ], "interface_file": false, "source_file": "MerkleTree.Low.Datastructures.fst" }
[ { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "EverCrypt.Helpers", "short_module": null }, { "abbrev": true, "full_module": "MerkleTree.New.High", "short_module": "MTH" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": true, "full_module": "EverCrypt.Hash", "short_module": "EHS" }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "S" }, { "abbrev": true, "full_module": "LowStar.Regional.Instances", "short_module": "RVI" }, { "abbrev": true, "full_module": "LowStar.RVector", "short_module": "RV" }, { "abbrev": true, "full_module": "LowStar.Vector", "short_module": "V" }, { "abbrev": true, "full_module": "LowStar.ConstBuffer", "short_module": "CB" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.Monotonic.HyperHeap", "short_module": "HH" }, { "abbrev": true, "full_module": "FStar.Monotonic.HyperStack", "short_module": "MHS" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": false, "full_module": "LowStar.Regional.Instances", "short_module": null }, { "abbrev": false, "full_module": "LowStar.RVector", "short_module": null }, { "abbrev": false, "full_module": "LowStar.Regional", "short_module": null }, { "abbrev": false, "full_module": "LowStar.Vector", "short_module": null }, { "abbrev": false, "full_module": "LowStar.BufferOps", "short_module": null }, { "abbrev": false, "full_module": "LowStar.Buffer", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.Integers", "short_module": null }, { "abbrev": false, "full_module": "FStar.All", "short_module": null }, { "abbrev": false, "full_module": "MerkleTree.Low", "short_module": null }, { "abbrev": false, "full_module": "MerkleTree.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": 0, "initial_ifuel": 0, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 10, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
s: MerkleTree.Low.Datastructures.hash_size_t{s == FStar.Ghost.reveal s'} -> src: MerkleTree.Low.Datastructures.hash -> dst: MerkleTree.Low.Datastructures.hash -> FStar.HyperStack.ST.ST Prims.unit
FStar.HyperStack.ST.ST
[]
[]
[ "FStar.Ghost.erased", "MerkleTree.Low.Datastructures.hash_size_t", "Prims.eq2", "FStar.Ghost.reveal", "MerkleTree.Low.Datastructures.hash", "LowStar.Monotonic.Buffer.blit", "Lib.IntTypes.uint8", "LowStar.Buffer.trivial_preorder", "FStar.UInt32.__uint_to_t", "Prims.unit" ]
[]
false
true
false
false
false
let hash_copy #_ s src dst =
B.blit src 0ul dst 0ul s
false
C.fst
C._zero_for_deref
val _zero_for_deref:FStar.UInt32.t
val _zero_for_deref:FStar.UInt32.t
let _zero_for_deref : FStar.UInt32.t = 0ul
{ "file_name": "krmllib/C.fst", "git_rev": "da1e941b2fcb196aa5d1e34941aa00b4c67ac321", "git_url": "https://github.com/FStarLang/karamel.git", "project_name": "karamel" }
{ "end_col": 42, "end_line": 65, "start_col": 0, "start_line": 65 }
module C open FStar.HyperStack.ST module HS = FStar.HyperStack module U8 = FStar.UInt8 // This module contains a series of bindings that already exist in C. It receives // a special treatment in Karamel (no prefixes, no .c/.h generated). // - If a value already exists (e.g. char or srand), then it is defined via the // default #includes. // - If a value doesn't exist, it is defined in krmllib.h and implemented in // krmllib.c (e.g. exit_success, instead of EXIT_SUCCESS). // The C standard library assume val srand: UInt32.t -> Stack unit (requires (fun _ -> true)) (ensures (fun h0 _ h1 -> h0 == h1)) assume val rand: unit -> Stack Int32.t (requires (fun _ -> true)) (ensures (fun h0 _ h1 -> h0 == h1)) assume val exit: Int32.t -> Stack unit (requires (fun _ -> True)) (ensures (fun h0 _ h1 -> False)) // Re-routed to KRML_HOST_EXIT for environments which don't have a libc assume val portable_exit: Int32.t -> Stack unit (requires (fun _ -> True)) (ensures (fun h0 _ h1 -> False)) assume type channel assume val stdout: channel assume val stderr: channel assume val fflush: channel -> St Int32.t // Abstract char type, with explicit conversions to/from uint8 assume val char: Type0 assume HasEq_char: hasEq char assume val char_of_uint8: U8.t -> char assume val uint8_of_char: char -> U8.t assume val char_uint8 (c: char): Lemma (ensures (char_of_uint8 (uint8_of_char c) = c)) [ SMTPat (uint8_of_char c) ] assume val uint8_char (u: U8.t): Lemma (ensures (uint8_of_char (char_of_uint8 u) = u)) [ SMTPat (char_of_uint8 u) ] // Clocks assume val int: Type0 assume val clock_t: Type0 assume val clock: unit -> Stack clock_t (requires (fun _ -> true)) (ensures (fun h0 _ h1 -> modifies_none h0 h1)) // C stdlib; the order of these constructors matters for Wasm. When emitting C // code, this type gets a special case and is not emitted to C. type exit_code = | EXIT_SUCCESS | EXIT_FAILURE // Debugging assume val print_bytes: b:LowStar.Buffer.buffer UInt8.t -> len:UInt32.t{UInt32.v len <= LowStar.Buffer.length b} -> Stack unit (requires (fun h -> LowStar.Buffer.live h b)) (ensures (fun h0 _ h1 -> h0 == h1)) // An index to be used as argument to Buffer.index so that // b[_zero_for_deref] is turned into *b // Special treatment: marked to not be emitted to C
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowStar.Buffer.fst.checked", "FStar.UInt8.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Pervasives.fsti.checked", "FStar.Int32.fsti.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked" ], "interface_file": false, "source_file": "C.fst" }
[ { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": false, "full_module": "FStar.HyperStack.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
FStar.UInt32.t
Prims.Tot
[ "total" ]
[]
[ "FStar.UInt32.__uint_to_t" ]
[]
false
false
false
true
false
let _zero_for_deref:FStar.UInt32.t =
0ul
false
LowStar.Regional.fst
LowStar.Regional.rg_dummy
val rg_dummy (#a #rst: _) (rg: regional rst a) : Tot a
val rg_dummy (#a #rst: _) (rg: regional rst a) : Tot a
let rg_dummy #a #rst (rg:regional rst a) : Tot a = Rgl?.dummy rg
{ "file_name": "ulib/LowStar.Regional.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 15, "end_line": 144, "start_col": 0, "start_line": 142 }
(* Copyright 2008-2018 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module LowStar.Regional (** * This module defines what is conceptually a typeclass called * `regional` (although it is not syntactically marked as a `class` * yet). * * `regional a` is the the class of types whose values have explicit * memory allocations confined spatially within a single heap region * in the hyperstack memory model. * * Being confined to a region, values of regional types support a * natural framing principles: state mutations that do not overlap * with a regional value's region are noninterfering. * * Instances of regional types are given for buffers and vectors: * See LowStar.Regional.Instances, LowStar.RVector for samples. * *) open LowStar.Modifies module HS = FStar.HyperStack module HST = FStar.HyperStack.ST /// Regionality /// Motivation: we want to ensure that all stateful operations for a value of /// type `a` are within the `region_of` the value. /// /// Furthermore, we would like regional to be parameterized over another type class /// that elements can have. However, we are also trying to extract to C, meaning /// that we can't incur any run-time lookups and indirections. In essence, we'd /// like for members of a regional to potentially be partial applications where /// the first argument may be an agility parameter, an extra type class for the /// elements, etc. etc. except that partial applications are not allowed in C. /// /// We therefore add an "st" type, which is a piece of (pure) state (hence more /// like a parameter) that functions are allowed to capture. Currently, only /// ``r_alloc`` needs that extra parameter. The parameter is stored within the /// type class, so that clients are not required to manage that piece of state /// themselves. This is, in effect, closure-conversion for ``r_alloc`` where the /// closure state is lifted and stored in the regional itself. As such, the only /// piece of state that ``r_alloc`` may receive is the exact value that was /// captured. /// /// Several alternative designs exist, e.g. making ``a`` at type ``st -> Type0`` /// (won't extract); instantiating ``st`` as a singleton type and dropping the /// refinement (also works, but doesn't make the intent of closure-conversion /// explicit); dropping the refinement and leaving it up to the user to store /// the refinement in ``r_inv`` (which would then take ``state`` as an /// argument)... noeq type regional (st:Type) (a:Type0) = | Rgl: // This is not really a piece of state, but more like a parameter. state: st -> // The target type should have a region where it belongs. region_of: (a -> GTot HS.rid) -> //loc_of for the underlying a loc_of: (a -> GTot loc) -> // A parameterless value of type `a`. // It does not have to satisfy the invariant `r_inv` described below. dummy: a -> // An invariant we want to maintain for each operation. // For example, it may include `live` and `freeable` properties // for related objects. r_inv: (HS.mem -> a -> GTot Type0) -> r_inv_reg: (h:HS.mem -> v:a -> Lemma (requires (r_inv h v)) (ensures (HS.live_region h (region_of v)))) -> // A representation type of `a` and a corresponding conversion function repr: Type0 -> r_repr: (h:HS.mem -> v:a{r_inv h v} -> GTot repr) -> // A core separation lemma, saying that the invariant and representation are // preserved when an orthogonal state transition happens. r_sep: (v:a -> p:loc -> h:HS.mem -> h':HS.mem -> Lemma (requires (r_inv h v /\ loc_disjoint (loc_all_regions_from false (region_of v)) p /\ modifies p h h')) (ensures (r_inv h' v /\ r_repr h v == r_repr h' v))) -> /// Allocation // The representation for the initial value of type `a` irepr: Ghost.erased repr -> // A property that should hold for all initial values of type `a`. r_alloc_p: (a -> GTot Type0) -> // An allocation operation. We might have several ways of initializing a // given target type `a`; then multiple typeclass instances should be // defined, and each of them can be used properly. r_alloc: ((s:st { s == state }) -> r:HST.erid -> HST.ST a (requires (fun h0 -> True)) (ensures (fun h0 v h1 -> Set.subset (Map.domain (HS.get_hmap h0)) (Map.domain (HS.get_hmap h1)) /\ modifies loc_none h0 h1 /\ fresh_loc (loc_of v) h0 h1 /\ //the underlying loc is fresh r_alloc_p v /\ r_inv h1 v /\ region_of v == r /\ r_repr h1 v == Ghost.reveal irepr))) -> // Destruction: note that it allows to `modify` all the regions, including // its subregions. It is fair when we want to `free` a vector and its // elements as well, assuming the elements belong to subregions. r_free: ((s:st { s == state }) -> v:a -> HST.ST unit (requires (fun h0 -> r_inv h0 v)) (ensures (fun h0 _ h1 -> modifies (loc_all_regions_from false (region_of v)) h0 h1))) -> regional st a let rg_inv #a #rst (rg: regional rst a) = Rgl?.r_inv rg
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowStar.Modifies.fst.checked", "FStar.Set.fsti.checked", "FStar.Pervasives.fsti.checked", "FStar.Map.fsti.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked" ], "interface_file": false, "source_file": "LowStar.Regional.fst" }
[ { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": false, "full_module": "LowStar.Modifies", "short_module": null }, { "abbrev": false, "full_module": "LowStar", "short_module": null }, { "abbrev": false, "full_module": "LowStar", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
rg: LowStar.Regional.regional rst a -> a
Prims.Tot
[ "total" ]
[]
[ "LowStar.Regional.regional", "LowStar.Regional.__proj__Rgl__item__dummy" ]
[]
false
false
false
true
false
let rg_dummy #a #rst (rg: regional rst a) : Tot a =
Rgl?.dummy rg
false
LowStar.Regional.fst
LowStar.Regional.rg_inv
val rg_inv : rg: LowStar.Regional.regional rst a -> _: FStar.Monotonic.HyperStack.mem -> _: a -> Prims.GTot Type0
let rg_inv #a #rst (rg: regional rst a) = Rgl?.r_inv rg
{ "file_name": "ulib/LowStar.Regional.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 15, "end_line": 139, "start_col": 0, "start_line": 138 }
(* Copyright 2008-2018 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module LowStar.Regional (** * This module defines what is conceptually a typeclass called * `regional` (although it is not syntactically marked as a `class` * yet). * * `regional a` is the the class of types whose values have explicit * memory allocations confined spatially within a single heap region * in the hyperstack memory model. * * Being confined to a region, values of regional types support a * natural framing principles: state mutations that do not overlap * with a regional value's region are noninterfering. * * Instances of regional types are given for buffers and vectors: * See LowStar.Regional.Instances, LowStar.RVector for samples. * *) open LowStar.Modifies module HS = FStar.HyperStack module HST = FStar.HyperStack.ST /// Regionality /// Motivation: we want to ensure that all stateful operations for a value of /// type `a` are within the `region_of` the value. /// /// Furthermore, we would like regional to be parameterized over another type class /// that elements can have. However, we are also trying to extract to C, meaning /// that we can't incur any run-time lookups and indirections. In essence, we'd /// like for members of a regional to potentially be partial applications where /// the first argument may be an agility parameter, an extra type class for the /// elements, etc. etc. except that partial applications are not allowed in C. /// /// We therefore add an "st" type, which is a piece of (pure) state (hence more /// like a parameter) that functions are allowed to capture. Currently, only /// ``r_alloc`` needs that extra parameter. The parameter is stored within the /// type class, so that clients are not required to manage that piece of state /// themselves. This is, in effect, closure-conversion for ``r_alloc`` where the /// closure state is lifted and stored in the regional itself. As such, the only /// piece of state that ``r_alloc`` may receive is the exact value that was /// captured. /// /// Several alternative designs exist, e.g. making ``a`` at type ``st -> Type0`` /// (won't extract); instantiating ``st`` as a singleton type and dropping the /// refinement (also works, but doesn't make the intent of closure-conversion /// explicit); dropping the refinement and leaving it up to the user to store /// the refinement in ``r_inv`` (which would then take ``state`` as an /// argument)... noeq type regional (st:Type) (a:Type0) = | Rgl: // This is not really a piece of state, but more like a parameter. state: st -> // The target type should have a region where it belongs. region_of: (a -> GTot HS.rid) -> //loc_of for the underlying a loc_of: (a -> GTot loc) -> // A parameterless value of type `a`. // It does not have to satisfy the invariant `r_inv` described below. dummy: a -> // An invariant we want to maintain for each operation. // For example, it may include `live` and `freeable` properties // for related objects. r_inv: (HS.mem -> a -> GTot Type0) -> r_inv_reg: (h:HS.mem -> v:a -> Lemma (requires (r_inv h v)) (ensures (HS.live_region h (region_of v)))) -> // A representation type of `a` and a corresponding conversion function repr: Type0 -> r_repr: (h:HS.mem -> v:a{r_inv h v} -> GTot repr) -> // A core separation lemma, saying that the invariant and representation are // preserved when an orthogonal state transition happens. r_sep: (v:a -> p:loc -> h:HS.mem -> h':HS.mem -> Lemma (requires (r_inv h v /\ loc_disjoint (loc_all_regions_from false (region_of v)) p /\ modifies p h h')) (ensures (r_inv h' v /\ r_repr h v == r_repr h' v))) -> /// Allocation // The representation for the initial value of type `a` irepr: Ghost.erased repr -> // A property that should hold for all initial values of type `a`. r_alloc_p: (a -> GTot Type0) -> // An allocation operation. We might have several ways of initializing a // given target type `a`; then multiple typeclass instances should be // defined, and each of them can be used properly. r_alloc: ((s:st { s == state }) -> r:HST.erid -> HST.ST a (requires (fun h0 -> True)) (ensures (fun h0 v h1 -> Set.subset (Map.domain (HS.get_hmap h0)) (Map.domain (HS.get_hmap h1)) /\ modifies loc_none h0 h1 /\ fresh_loc (loc_of v) h0 h1 /\ //the underlying loc is fresh r_alloc_p v /\ r_inv h1 v /\ region_of v == r /\ r_repr h1 v == Ghost.reveal irepr))) -> // Destruction: note that it allows to `modify` all the regions, including // its subregions. It is fair when we want to `free` a vector and its // elements as well, assuming the elements belong to subregions. r_free: ((s:st { s == state }) -> v:a -> HST.ST unit (requires (fun h0 -> r_inv h0 v)) (ensures (fun h0 _ h1 -> modifies (loc_all_regions_from false (region_of v)) h0 h1))) -> regional st a
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowStar.Modifies.fst.checked", "FStar.Set.fsti.checked", "FStar.Pervasives.fsti.checked", "FStar.Map.fsti.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked" ], "interface_file": false, "source_file": "LowStar.Regional.fst" }
[ { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": false, "full_module": "LowStar.Modifies", "short_module": null }, { "abbrev": false, "full_module": "LowStar", "short_module": null }, { "abbrev": false, "full_module": "LowStar", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
rg: LowStar.Regional.regional rst a -> _: FStar.Monotonic.HyperStack.mem -> _: a -> Prims.GTot Type0
Prims.GTot
[ "sometrivial" ]
[]
[ "LowStar.Regional.regional", "LowStar.Regional.__proj__Rgl__item__r_inv", "FStar.Monotonic.HyperStack.mem" ]
[]
false
false
false
false
true
let rg_inv #a #rst (rg: regional rst a) =
Rgl?.r_inv rg
false
MerkleTree.Low.Datastructures.fst
MerkleTree.Low.Datastructures.hash_vec_r_alloc
val hash_vec_r_alloc: #hsz':Ghost.erased hash_size_t -> hsz:hash_size_t { hsz == Ghost.reveal hsz' } -> r:HST.erid -> HST.ST (hash_vec #hsz) (requires (fun h0 -> true)) (ensures (fun h0 v h1 -> Set.subset (Map.domain (MHS.get_hmap h0)) (Map.domain (MHS.get_hmap h1)) /\ modifies loc_none h0 h1 /\ hash_vec_r_alloc_p v /\ hash_vec_r_inv h1 v /\ hash_vec_region_of v = r /\ hash_vec_r_repr h1 v == Ghost.reveal hash_vec_irepr /\ B.fresh_loc (V.loc_vector v) h0 h1))
val hash_vec_r_alloc: #hsz':Ghost.erased hash_size_t -> hsz:hash_size_t { hsz == Ghost.reveal hsz' } -> r:HST.erid -> HST.ST (hash_vec #hsz) (requires (fun h0 -> true)) (ensures (fun h0 v h1 -> Set.subset (Map.domain (MHS.get_hmap h0)) (Map.domain (MHS.get_hmap h1)) /\ modifies loc_none h0 h1 /\ hash_vec_r_alloc_p v /\ hash_vec_r_inv h1 v /\ hash_vec_region_of v = r /\ hash_vec_r_repr h1 v == Ghost.reveal hash_vec_irepr /\ B.fresh_loc (V.loc_vector v) h0 h1))
let hash_vec_r_alloc #_ hsz r = let nrid = HST.new_region r in // Note: here we are not creating a generic parameterized regional, we are // creating a specialized regional vector of hashes, so we don't need to go // through a run-time indirection to figure out what the dummy default element // is; we know it's the one for hashes V.alloc_reserve 1ul (hash_dummy #hsz) r
{ "file_name": "src/MerkleTree.Low.Datastructures.fst", "git_rev": "7d7bdc20f2033171e279c176b26e84f9069d23c6", "git_url": "https://github.com/hacl-star/merkle-tree.git", "project_name": "merkle-tree" }
{ "end_col": 41, "end_line": 277, "start_col": 0, "start_line": 271 }
module MerkleTree.Low.Datastructures open FStar.All open FStar.Integers open FStar.Mul open LowStar.Buffer open LowStar.BufferOps open LowStar.Vector open LowStar.Regional open LowStar.RVector open LowStar.Regional.Instances module HS = FStar.HyperStack module HST = FStar.HyperStack.ST module MHS = FStar.Monotonic.HyperStack module HH = FStar.Monotonic.HyperHeap module B = LowStar.Buffer module CB = LowStar.ConstBuffer module V = LowStar.Vector module RV = LowStar.RVector module RVI = LowStar.Regional.Instances module S = FStar.Seq module EHS = EverCrypt.Hash module U32 = FStar.UInt32 module MTH = MerkleTree.New.High open EverCrypt.Helpers open Lib.IntTypes #set-options "--z3rlimit 10 --initial_fuel 0 --max_fuel 0 --initial_ifuel 0 --max_ifuel 0" type hash_size_t = n:uint32_t{n > 0ul} type hash (#hsz:hash_size_t) = b:B.buffer uint8 { B.len b = hsz \/ B.g_is_null b } // We cannot use `Low.RVector.Instances`, where we have some general // typeclass instances of `regional`, e.g., if `rg:regional a` then // `regional (rvector rg)`. In FStar we can use this, but KaRaMeL currently // cannot deal with this and gives a number of errors. // So we temporarily instantiate some `regional`s manually below, which is // extractable to C by KaRaMeL. /// Some instantiations of `regional` used in Merkle tree /// 1. `hash` is regional private noextract val hash_region_of: #hsz:hash_size_t -> v:hash #hsz -> GTot HH.rid let hash_region_of #_ v = B.frameOf v private inline_for_extraction val hash_dummy: #hsz:Ghost.erased hash_size_t -> Tot (hash #hsz) let hash_dummy #_ = B.null private noextract val hash_r_inv: #hsz:hash_size_t -> h:HS.mem -> v:hash #hsz -> GTot Type0 let hash_r_inv #hsz h v = B.live h v /\ B.freeable v /\ B.len v = hsz private noextract val hash_r_inv_reg: #hsz:hash_size_t -> h:HS.mem -> v:hash -> Lemma (requires hash_r_inv h v) (ensures MHS.live_region h (hash_region_of #hsz v)) let hash_r_inv_reg #_ h v = () private noextract val hash_repr (#hsz:hash_size_t): Type0 let hash_repr #hsz = MTH.hash #(U32.v hsz) private noextract val hash_r_repr: #hsz:hash_size_t -> h:HS.mem -> v:hash{hash_r_inv #hsz h v} -> GTot (hash_repr #hsz) let hash_r_repr #_ h v = B.as_seq h v private noextract val hash_r_sep: #hsz:hash_size_t -> v:hash #hsz -> p:loc -> h0:HS.mem -> h1:HS.mem -> Lemma (requires hash_r_inv h0 v /\ loc_disjoint (loc_all_regions_from false (hash_region_of v)) p /\ modifies p h0 h1) (ensures hash_r_inv h1 v /\ hash_r_repr h0 v == hash_r_repr h1 v) let hash_r_sep #_ v p h0 h1 = assert (loc_includes (loc_all_regions_from false (hash_region_of v)) (loc_buffer v)); B.modifies_buffer_elim v p h0 h1 private noextract val hash_irepr: #hsz:hash_size_t -> Ghost.erased (hash_repr #hsz) let hash_irepr #hsz = Ghost.hide (S.create (U32.v hsz) (u8 0)) private noextract val hash_r_alloc_p: #hsz:hash_size_t -> v:hash #hsz -> GTot Type0 let hash_r_alloc_p #_ v = True val hash_r_alloc: #hsz':Ghost.erased hash_size_t -> hsz:hash_size_t { hsz == Ghost.reveal hsz' } -> r:HST.erid -> HST.ST (hash #hsz) (requires (fun h0 -> true)) (ensures (fun h0 v h1 -> Set.subset (Map.domain (MHS.get_hmap h0)) (Map.domain (MHS.get_hmap h1)) /\ modifies loc_none h0 h1 /\ hash_r_alloc_p #hsz v /\ hash_r_inv h1 v /\ hash_region_of v = r /\ hash_r_repr h1 v == Ghost.reveal hash_irepr /\ B.fresh_loc (B.loc_buffer v) h0 h1)) let hash_r_alloc #_ s r = B.malloc r (u8 0) s val hash_r_free: #hsz':Ghost.erased hash_size_t -> hsz:hash_size_t { hsz == Ghost.reveal hsz' } -> v:hash #hsz' -> HST.ST unit (requires fun h0 -> hash_r_inv h0 v) (ensures fun h0 _ h1 -> modifies (loc_all_regions_from false (hash_region_of v)) h0 h1) let hash_r_free #_ _ v = B.free v noextract inline_for_extraction val hreg (hsz:hash_size_t): regional (hash_size_t) (hash #hsz) let hreg hsz = Rgl #(hash_size_t) #(hash #hsz) hsz (hash_region_of #hsz) (B.loc_buffer) (hash_dummy #hsz) (hash_r_inv #hsz) (hash_r_inv_reg #hsz) (hash_repr #hsz) (hash_r_repr #hsz) (hash_r_sep #hsz) (hash_irepr #hsz) (hash_r_alloc_p #hsz) (hash_r_alloc #hsz) (hash_r_free #hsz) private val hash_copy: #s':Ghost.erased hash_size_t -> s:hash_size_t { s == Ghost.reveal s' } -> src:hash #s -> dst:hash #s -> HST.ST unit (requires fun h0 -> hash_r_inv h0 src /\ hash_r_inv h0 dst /\ HH.disjoint (hash_region_of src) (hash_region_of dst)) (ensures fun h0 _ h1 -> modifies (loc_all_regions_from false (hash_region_of dst)) h0 h1 /\ hash_r_inv h1 dst /\ hash_r_repr h1 dst == hash_r_repr h0 src) let hash_copy #_ s src dst = B.blit src 0ul dst 0ul s /// JP: so much stuff happening here. First, single-constructor, single-argument /// elimination takes places and Cpy becomes completely eliminated, in favor of /// just being a type alias for the underlying function. So now, we have a /// function that returns a function pointer. /// /// Next, one might think that the hsz argument is going to be eliminated. It's /// not, because there's a hidden implicit argument to Cpy which is (hreg hsz), /// meaning that hsz is used at run-time even though Cpy is only using this /// argument ghostly. This would be have to be fixed. /// /// Finally, if the inline_for_extraction is removed, there seems to be a /// karamel bug that inserts a void*0. To be fixed. inline_for_extraction val hcpy: hsz:hash_size_t -> copyable #hash_size_t (hash #hsz) (hreg hsz) let hcpy hsz = Cpy (hash_copy #hsz) type hash_vec (#hsz:hash_size_t) = RV.rvector (hreg hsz) /// 2. `rvector hash` is regional type rhst (hsz:hash_size_t) = regional hash_size_t (hash #hsz) private noextract val hash_vec_region_of: #hsz:hash_size_t -> v:hash_vec #hsz -> GTot HH.rid let hash_vec_region_of #_ v = V.frameOf v private inline_for_extraction val hash_vec_dummy: (#hsz:Ghost.erased hash_size_t) -> hash_vec #hsz let hash_vec_dummy #_ = V.alloc_empty (hash #_) noextract val hash_vec_r_inv: #hsz:hash_size_t -> h:HS.mem -> v:hash_vec #hsz -> GTot Type0 let hash_vec_r_inv #hsz h v = RV.rv_inv h v noextract val hash_vec_r_inv_reg: #hsz:hash_size_t -> h:HS.mem -> v:hash_vec #hsz -> Lemma (requires (hash_vec_r_inv h v)) (ensures (MHS.live_region h (hash_vec_region_of v))) let hash_vec_r_inv_reg #_ h v = () private noextract val hash_vec_repr: #hsz:hash_size_t -> Type0 let hash_vec_repr #hsz = MTH.hashes #(U32.v hsz) noextract val hash_vec_r_repr: #hsz:hash_size_t -> h:HS.mem -> v:hash_vec #hsz {hash_vec_r_inv h v} -> GTot (hash_vec_repr #hsz) let hash_vec_r_repr #_ h v = RV.as_seq h v noextract val hash_vec_r_sep: #hsz:hash_size_t -> v:hash_vec #hsz -> p:loc -> h0:HS.mem -> h1:HS.mem -> Lemma (requires (hash_vec_r_inv h0 v /\ loc_disjoint (loc_all_regions_from false (hash_vec_region_of v)) p /\ modifies p h0 h1)) (ensures (hash_vec_r_inv h1 v /\ hash_vec_r_repr h0 v == hash_vec_r_repr h1 v)) let hash_vec_r_sep #_ v p h0 h1 = RV.rv_inv_preserved v p h0 h1; RV.as_seq_preserved v p h0 h1 noextract val hash_vec_irepr: #hsz:hash_size_t -> Ghost.erased (hash_vec_repr #hsz) let hash_vec_irepr #_ = Ghost.hide S.empty noextract val hash_vec_r_alloc_p: #hsz:hash_size_t -> v:hash_vec #hsz -> GTot Type0 let hash_vec_r_alloc_p #_ v = V.size_of v = 0ul #push-options "--initial_fuel 1 --max_fuel 1" val hash_vec_r_alloc: #hsz':Ghost.erased hash_size_t -> hsz:hash_size_t { hsz == Ghost.reveal hsz' } -> r:HST.erid -> HST.ST (hash_vec #hsz) (requires (fun h0 -> true)) (ensures (fun h0 v h1 -> Set.subset (Map.domain (MHS.get_hmap h0)) (Map.domain (MHS.get_hmap h1)) /\ modifies loc_none h0 h1 /\ hash_vec_r_alloc_p v /\ hash_vec_r_inv h1 v /\ hash_vec_region_of v = r /\ hash_vec_r_repr h1 v == Ghost.reveal hash_vec_irepr /\
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "MerkleTree.New.High.fst.checked", "LowStar.Vector.fst.checked", "LowStar.RVector.fst.checked", "LowStar.Regional.Instances.fst.checked", "LowStar.Regional.fst.checked", "LowStar.ConstBuffer.fsti.checked", "LowStar.BufferOps.fst.checked", "LowStar.Buffer.fst.checked", "Lib.IntTypes.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Set.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Monotonic.HyperStack.fsti.checked", "FStar.Monotonic.HyperHeap.fsti.checked", "FStar.Map.fsti.checked", "FStar.Integers.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked", "FStar.All.fst.checked", "EverCrypt.Helpers.fsti.checked", "EverCrypt.Hash.fsti.checked" ], "interface_file": false, "source_file": "MerkleTree.Low.Datastructures.fst" }
[ { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "EverCrypt.Helpers", "short_module": null }, { "abbrev": true, "full_module": "MerkleTree.New.High", "short_module": "MTH" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": true, "full_module": "EverCrypt.Hash", "short_module": "EHS" }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "S" }, { "abbrev": true, "full_module": "LowStar.Regional.Instances", "short_module": "RVI" }, { "abbrev": true, "full_module": "LowStar.RVector", "short_module": "RV" }, { "abbrev": true, "full_module": "LowStar.Vector", "short_module": "V" }, { "abbrev": true, "full_module": "LowStar.ConstBuffer", "short_module": "CB" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.Monotonic.HyperHeap", "short_module": "HH" }, { "abbrev": true, "full_module": "FStar.Monotonic.HyperStack", "short_module": "MHS" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": false, "full_module": "LowStar.Regional.Instances", "short_module": null }, { "abbrev": false, "full_module": "LowStar.RVector", "short_module": null }, { "abbrev": false, "full_module": "LowStar.Regional", "short_module": null }, { "abbrev": false, "full_module": "LowStar.Vector", "short_module": null }, { "abbrev": false, "full_module": "LowStar.BufferOps", "short_module": null }, { "abbrev": false, "full_module": "LowStar.Buffer", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.Integers", "short_module": null }, { "abbrev": false, "full_module": "FStar.All", "short_module": null }, { "abbrev": false, "full_module": "MerkleTree.Low", "short_module": null }, { "abbrev": false, "full_module": "MerkleTree.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": 1, "initial_ifuel": 0, "max_fuel": 1, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 10, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
hsz: MerkleTree.Low.Datastructures.hash_size_t{hsz == FStar.Ghost.reveal hsz'} -> r: FStar.HyperStack.ST.erid -> FStar.HyperStack.ST.ST MerkleTree.Low.Datastructures.hash_vec
FStar.HyperStack.ST.ST
[]
[]
[ "FStar.Ghost.erased", "MerkleTree.Low.Datastructures.hash_size_t", "Prims.eq2", "FStar.Ghost.reveal", "FStar.HyperStack.ST.erid", "LowStar.Vector.alloc_reserve", "MerkleTree.Low.Datastructures.hash", "FStar.UInt32.__uint_to_t", "MerkleTree.Low.Datastructures.hash_dummy", "FStar.Ghost.hide", "LowStar.Vector.vector", "FStar.Monotonic.HyperHeap.rid", "FStar.HyperStack.ST.new_region", "MerkleTree.Low.Datastructures.hash_vec" ]
[]
false
true
false
false
false
let hash_vec_r_alloc #_ hsz r =
let nrid = HST.new_region r in V.alloc_reserve 1ul (hash_dummy #hsz) r
false
EverParse3d.InputStream.Buffer.Aux.fst
EverParse3d.InputStream.Buffer.Aux._footprint
val _footprint (x: t) : Ghost B.loc (requires True) (ensures (fun y -> B.address_liveness_insensitive_locs `B.loc_includes` y))
val _footprint (x: t) : Ghost B.loc (requires True) (ensures (fun y -> B.address_liveness_insensitive_locs `B.loc_includes` y))
let _footprint (x: t) : Ghost B.loc (requires True) (ensures (fun y -> B.address_liveness_insensitive_locs `B.loc_includes` y)) = B.loc_buffer (IB.slice_of x.buf).LP.base `B.loc_union` IR.loc_perm x.perm_of `B.loc_union` B.loc_buffer x.pos
{ "file_name": "src/3d/prelude/buffer/EverParse3d.InputStream.Buffer.Aux.fst", "git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
{ "end_col": 111, "end_line": 56, "start_col": 0, "start_line": 51 }
module EverParse3d.InputStream.Buffer.Aux (* This module is here to break circularity in KaRaMeL bundles (because Prims must be in the EverParse bundle because of the string type, as opposed to C,FStar,LowStar.) *) module IB = EverParse3d.InputBuffer module IR = EverParse3d.Readable module LP = LowParse.Low.Base module B = LowStar.Buffer module U8 = FStar.UInt8 module U32 = FStar.UInt32 module U64 = FStar.UInt64 module HS = FStar.HyperStack module HST = FStar.HyperStack.ST noeq type input_buffer = { len0: Ghost.erased U32.t; buf: IB.input_buffer_t len0; perm_of: IR.perm (IB.slice_of buf).LP.base; len: Ghost.erased U32.t; pos: B.pointer (Ghost.erased U32.t); g_all_buf: Ghost.erased (Seq.seq U8.t); g_all: Ghost.erased (Seq.seq U8.t); prf: squash ( U32.v len <= U32.v len0 /\ Seq.length g_all == U32.v len /\ B.loc_disjoint (B.loc_buffer (IB.slice_of buf).LP.base `B.loc_union` IR.loc_perm perm_of) (B.loc_buffer pos) /\ Seq.length g_all_buf == U32.v len0 /\ Ghost.reveal g_all == Seq.slice g_all_buf 0 (U32.v len) ); } inline_for_extraction noextract let t = input_buffer unfold let _live (x: t) (h: HS.mem) : Tot prop = IB.live_input_buffer h x.buf x.perm_of /\ B.live h x.pos /\ U32.v (B.deref h x.pos) <= U32.v x.len /\ B.as_seq h (IB.slice_of x.buf).LP.base == Ghost.reveal x.g_all_buf /\ IR.unreadable h x.perm_of 0ul (B.deref h x.pos) /\ IR.readable h x.perm_of (B.deref h x.pos) x.len0 /\ Seq.slice (B.as_seq h (IB.slice_of x.buf).LP.base) 0 (U32.v x.len) == Ghost.reveal x.g_all
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowStar.BufferOps.fst.checked", "LowStar.Buffer.fst.checked", "LowParse.Low.Base.fst.checked", "FStar.UInt8.fsti.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked", "EverParse3d.Readable.fsti.checked", "EverParse3d.InputBuffer.fsti.checked", "EverParse3d.ErrorCode.fst.checked" ], "interface_file": false, "source_file": "EverParse3d.InputStream.Buffer.Aux.fst" }
[ { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "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": "LowParse.Low.Base", "short_module": "LP" }, { "abbrev": true, "full_module": "EverParse3d.Readable", "short_module": "IR" }, { "abbrev": true, "full_module": "EverParse3d.InputBuffer", "short_module": "IB" }, { "abbrev": false, "full_module": "EverParse3d.InputStream.Buffer", "short_module": null }, { "abbrev": false, "full_module": "EverParse3d.InputStream.Buffer", "short_module": null }, { "abbrev": 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": 0, "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": [ "smt.qi.eager_threshold=100" ], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 8, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
x: EverParse3d.InputStream.Buffer.Aux.t -> Prims.Ghost LowStar.Monotonic.Buffer.loc
Prims.Ghost
[]
[]
[ "EverParse3d.InputStream.Buffer.Aux.t", "LowStar.Monotonic.Buffer.loc_union", "LowStar.Monotonic.Buffer.loc_buffer", "LowParse.Bytes.byte", "LowParse.Slice.buffer_srel_of_srel", "EverParse3d.InputBuffer.triv", "LowParse.Slice.__proj__Mkslice__item__base", "EverParse3d.InputBuffer.slice_of", "FStar.Ghost.reveal", "FStar.UInt32.t", "EverParse3d.InputStream.Buffer.Aux.__proj__Mkinput_buffer__item__len0", "EverParse3d.InputStream.Buffer.Aux.__proj__Mkinput_buffer__item__buf", "EverParse3d.Readable.loc_perm", "EverParse3d.InputStream.Buffer.Aux.__proj__Mkinput_buffer__item__perm_of", "FStar.Ghost.erased", "LowStar.Buffer.trivial_preorder", "EverParse3d.InputStream.Buffer.Aux.__proj__Mkinput_buffer__item__pos", "LowStar.Monotonic.Buffer.loc", "Prims.l_True", "LowStar.Monotonic.Buffer.loc_includes", "LowStar.Monotonic.Buffer.address_liveness_insensitive_locs" ]
[]
false
false
false
false
false
let _footprint (x: t) : Ghost B.loc (requires True) (ensures (fun y -> B.address_liveness_insensitive_locs `B.loc_includes` y)) =
((B.loc_buffer (IB.slice_of x.buf).LP.base) `B.loc_union` (IR.loc_perm x.perm_of)) `B.loc_union` (B.loc_buffer x.pos)
false
LowParse.Low.BCVLI.fst
LowParse.Low.BCVLI.validate_bcvli
val validate_bcvli:validator parse_bcvli
val validate_bcvli:validator parse_bcvli
let validate_bcvli : validator parse_bcvli = fun #rrel #rel input pos -> let h = HST.get () in [@inline_let] let _ = valid_facts parse_bcvli h input (uint64_to_uint32 pos); parse_bcvli_eq (bytes_of_slice_from h input (uint64_to_uint32 pos)); valid_facts (parse_bounded_integer_le 1) h input (uint64_to_uint32 pos) in let pos1 = validate_total_constant_size (parse_bounded_integer_le 1) 1uL () input pos in if is_error pos1 then pos1 else [@inline_let] let _ = valid_facts (parse_bounded_integer_le 2) h input (uint64_to_uint32 pos1); valid_facts (parse_bounded_integer_le 4) h input (uint64_to_uint32 pos1) in let r = read_bounded_integer_le_1 input (uint64_to_uint32 pos) in if r `U32.lt` 253ul then pos1 else if r = 253ul then let pos2 = validate_total_constant_size (parse_bounded_integer_le 2) 2uL () input pos1 in if is_error pos2 then pos2 else (* because of the non-malleability constraint, I need to actually read the value and check whether it is not a lower integer *) let r = read_bounded_integer_le_2 input (uint64_to_uint32 pos1) in if r `U32.lt` 253ul then validator_error_generic else pos2 else if r = 254ul then let pos2 = validate_total_constant_size (parse_bounded_integer_le 4) 4uL () input pos1 in if is_error pos2 then pos2 else (* because of the non-malleability constraint, I need to actually read the value and check whether it is not a lower integer *) let r = read_bounded_integer_le_4 input (uint64_to_uint32 pos1) in if r `U32.lt` 65536ul then validator_error_generic else pos2 else validator_error_generic
{ "file_name": "src/lowparse/LowParse.Low.BCVLI.fst", "git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
{ "end_col": 32, "end_line": 57, "start_col": 0, "start_line": 16 }
module LowParse.Low.BCVLI include LowParse.Spec.BCVLI include LowParse.Low.Combinators include LowParse.Low.BoundedInt module B = LowStar.Buffer module HST = FStar.HyperStack.ST module Cast = FStar.Int.Cast module U32 = FStar.UInt32 module U64 = FStar.UInt64 #reset-options "--z3cliopt smt.arith.nl=false --max_fuel 0" #push-options "--z3rlimit 16"
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowStar.Buffer.fst.checked", "LowParse.Spec.BCVLI.fsti.checked", "LowParse.Low.Combinators.fsti.checked", "LowParse.Low.BoundedInt.fsti.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.Ghost.fsti.checked" ], "interface_file": false, "source_file": "LowParse.Low.BCVLI.fst" }
[ { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": true, "full_module": "FStar.Int.Cast", "short_module": "Cast" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": false, "full_module": "LowParse.Low.BoundedInt", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low.Combinators", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec.BCVLI", "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": 0, "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": [ "smt.arith.nl=false" ], "z3refresh": false, "z3rlimit": 16, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
LowParse.Low.Base.validator LowParse.Spec.BCVLI.parse_bcvli
Prims.Tot
[ "total" ]
[]
[ "LowParse.Slice.srel", "LowParse.Bytes.byte", "LowParse.Slice.slice", "FStar.UInt64.t", "LowParse.Low.ErrorCode.is_error", "Prims.bool", "FStar.UInt32.lt", "FStar.UInt32.__uint_to_t", "Prims.op_Equality", "FStar.UInt32.t", "LowParse.Low.ErrorCode.validator_error_generic", "LowParse.Spec.BoundedInt.bounded_integer", "LowParse.Low.BoundedInt.read_bounded_integer_le_2", "LowParse.Low.ErrorCode.uint64_to_uint32", "LowParse.Low.Base.validate_total_constant_size", "LowParse.Spec.BoundedInt.parse_bounded_integer_kind", "LowParse.Spec.BoundedInt.parse_bounded_integer_le", "FStar.UInt64.__uint_to_t", "LowParse.Low.BoundedInt.read_bounded_integer_le_4", "LowParse.Low.BoundedInt.read_bounded_integer_le_1", "Prims.unit", "LowParse.Low.Base.Spec.valid_facts", "LowParse.Spec.BCVLI.parse_bcvli_eq", "LowParse.Slice.bytes_of_slice_from", "LowParse.Spec.BCVLI.parse_bcvli_kind", "LowParse.Spec.BCVLI.parse_bcvli", "FStar.Monotonic.HyperStack.mem", "FStar.HyperStack.ST.get" ]
[]
false
false
false
true
false
let validate_bcvli:validator parse_bcvli =
fun #rrel #rel input pos -> let h = HST.get () in [@@ inline_let ]let _ = valid_facts parse_bcvli h input (uint64_to_uint32 pos); parse_bcvli_eq (bytes_of_slice_from h input (uint64_to_uint32 pos)); valid_facts (parse_bounded_integer_le 1) h input (uint64_to_uint32 pos) in let pos1 = validate_total_constant_size (parse_bounded_integer_le 1) 1uL () input pos in if is_error pos1 then pos1 else [@@ inline_let ]let _ = valid_facts (parse_bounded_integer_le 2) h input (uint64_to_uint32 pos1); valid_facts (parse_bounded_integer_le 4) h input (uint64_to_uint32 pos1) in let r = read_bounded_integer_le_1 input (uint64_to_uint32 pos) in if r `U32.lt` 253ul then pos1 else if r = 253ul then let pos2 = validate_total_constant_size (parse_bounded_integer_le 2) 2uL () input pos1 in if is_error pos2 then pos2 else let r = read_bounded_integer_le_2 input (uint64_to_uint32 pos1) in if r `U32.lt` 253ul then validator_error_generic else pos2 else if r = 254ul then let pos2 = validate_total_constant_size (parse_bounded_integer_le 4) 4uL () input pos1 in if is_error pos2 then pos2 else let r = read_bounded_integer_le_4 input (uint64_to_uint32 pos1) in if r `U32.lt` 65536ul then validator_error_generic else pos2 else validator_error_generic
false
FStar.UInt64.fsti
FStar.UInt64.eq_mask
val eq_mask (a b: t) : Pure t (requires True) (ensures (fun c -> (v a = v b ==> v c = pow2 n - 1) /\ (v a <> v b ==> v c = 0)))
val eq_mask (a b: t) : Pure t (requires True) (ensures (fun c -> (v a = v b ==> v c = pow2 n - 1) /\ (v a <> v b ==> v c = 0)))
let eq_mask (a:t) (b:t) : Pure t (requires True) (ensures (fun c -> (v a = v b ==> v c = pow2 n - 1) /\ (v a <> v b ==> v c = 0))) = let x = logxor a b in let minus_x = minus x in let x_or_minus_x = logor x minus_x in let xnx = shift_right x_or_minus_x n_minus_one in let c = sub_mod xnx (uint_to_t 1) in if a = b then begin logxor_self (v a); lognot_lemma_1 #n; logor_lemma_1 (v x); assert (v x = 0 /\ v minus_x = 0 /\ v x_or_minus_x = 0 /\ v xnx = 0); assert (v c = ones n) end else begin logxor_neq_nonzero (v a) (v b); lemma_msb_pow2 #n (v (lognot x)); lemma_msb_pow2 #n (v minus_x); lemma_minus_zero #n (v x); assert (v c = FStar.UInt.zero n) end; c
{ "file_name": "ulib/FStar.UInt64.fsti", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 5, "end_line": 283, "start_col": 0, "start_line": 256 }
(* 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 FStar.UInt64 (**** THIS MODULE IS GENERATED AUTOMATICALLY USING [mk_int.sh], DO NOT EDIT DIRECTLY ****) unfold let n = 64 /// For FStar.UIntN.fstp: anything that you fix/update here should be /// reflected in [FStar.IntN.fstp], which is mostly a copy-paste of /// this module. /// /// Except, as compared to [FStar.IntN.fstp], here: /// - every occurrence of [int_t] has been replaced with [uint_t] /// - every occurrence of [@%] has been replaced with [%]. /// - some functions (e.g., add_underspec, etc.) are only defined here, not on signed integers /// This module provides an abstract type for machine integers of a /// given signedness and width. The interface is designed to be safe /// with respect to arithmetic underflow and overflow. /// Note, we have attempted several times to re-design this module to /// make it more amenable to normalization and to impose less overhead /// on the SMT solver when reasoning about machine integer /// arithmetic. The following github issue reports on the current /// status of that work. /// /// https://github.com/FStarLang/FStar/issues/1757 open FStar.UInt open FStar.Mul #set-options "--max_fuel 0 --max_ifuel 0" (** Abstract type of machine integers, with an underlying representation using a bounded mathematical integer *) new val t : eqtype (** A coercion that projects a bounded mathematical integer from a machine integer *) val v (x:t) : Tot (uint_t n) (** A coercion that injects a bounded mathematical integers into a machine integer *) val uint_to_t (x:uint_t n) : Pure t (requires True) (ensures (fun y -> v y = x)) (** Injection/projection inverse *) val uv_inv (x : t) : Lemma (ensures (uint_to_t (v x) == x)) [SMTPat (v x)] (** Projection/injection inverse *) val vu_inv (x : uint_t n) : Lemma (ensures (v (uint_to_t x) == x)) [SMTPat (uint_to_t x)] (** An alternate form of the injectivity of the [v] projection *) val v_inj (x1 x2: t): Lemma (requires (v x1 == v x2)) (ensures (x1 == x2)) (** Constants 0 and 1 *) val zero : x:t{v x = 0} val one : x:t{v x = 1} (**** Addition primitives *) (** Bounds-respecting addition The precondition enforces that the sum does not overflow, expressing the bound as an addition on mathematical integers *) val add (a:t) (b:t) : Pure t (requires (size (v a + v b) n)) (ensures (fun c -> v a + v b = v c)) (** Underspecified, possibly overflowing addition: The postcondition only enures that the result is the sum of the arguments in case there is no overflow *) val add_underspec (a:t) (b:t) : Pure t (requires True) (ensures (fun c -> size (v a + v b) n ==> v a + v b = v c)) (** Addition modulo [2^n] Machine integers can always be added, but the postcondition is now in terms of addition modulo [2^n] on mathematical integers *) val add_mod (a:t) (b:t) : Pure t (requires True) (ensures (fun c -> FStar.UInt.add_mod (v a) (v b) = v c)) (**** Subtraction primitives *) (** Bounds-respecting subtraction The precondition enforces that the difference does not underflow, expressing the bound as a difference on mathematical integers *) val sub (a:t) (b:t) : Pure t (requires (size (v a - v b) n)) (ensures (fun c -> v a - v b = v c)) (** Underspecified, possibly overflowing subtraction: The postcondition only enures that the result is the difference of the arguments in case there is no underflow *) val sub_underspec (a:t) (b:t) : Pure t (requires True) (ensures (fun c -> size (v a - v b) n ==> v a - v b = v c)) (** Subtraction modulo [2^n] Machine integers can always be subtractd, but the postcondition is now in terms of subtraction modulo [2^n] on mathematical integers *) val sub_mod (a:t) (b:t) : Pure t (requires True) (ensures (fun c -> FStar.UInt.sub_mod (v a) (v b) = v c)) (**** Multiplication primitives *) (** Bounds-respecting multiplication The precondition enforces that the product does not overflow, expressing the bound as a product on mathematical integers *) val mul (a:t) (b:t) : Pure t (requires (size (v a * v b) n)) (ensures (fun c -> v a * v b = v c)) (** Underspecified, possibly overflowing product The postcondition only enures that the result is the product of the arguments in case there is no overflow *) val mul_underspec (a:t) (b:t) : Pure t (requires True) (ensures (fun c -> size (v a * v b) n ==> v a * v b = v c)) (** Multiplication modulo [2^n] Machine integers can always be multiplied, but the postcondition is now in terms of product modulo [2^n] on mathematical integers *) val mul_mod (a:t) (b:t) : Pure t (requires True) (ensures (fun c -> FStar.UInt.mul_mod (v a) (v b) = v c)) (**** Division primitives *) (** Euclidean division of [a] and [b], with [b] non-zero *) val div (a:t) (b:t{v b <> 0}) : Pure t (requires (True)) (ensures (fun c -> v a / v b = v c)) (**** Modulo primitives *) (** Euclidean remainder The result is the modulus of [a] with respect to a non-zero [b] *) val rem (a:t) (b:t{v b <> 0}) : Pure t (requires True) (ensures (fun c -> FStar.UInt.mod (v a) (v b) = v c)) (**** Bitwise operators *) /// Also see FStar.BV (** Bitwise logical conjunction *) val logand (x:t) (y:t) : Pure t (requires True) (ensures (fun z -> v x `logand` v y = v z)) (** Bitwise logical exclusive-or *) val logxor (x:t) (y:t) : Pure t (requires True) (ensures (fun z -> v x `logxor` v y == v z)) (** Bitwise logical disjunction *) val logor (x:t) (y:t) : Pure t (requires True) (ensures (fun z -> v x `logor` v y == v z)) (** Bitwise logical negation *) val lognot (x:t) : Pure t (requires True) (ensures (fun z -> lognot (v x) == v z)) (**** Shift operators *) (** Shift right with zero fill, shifting at most the integer width *) val shift_right (a:t) (s:UInt32.t) : Pure t (requires (UInt32.v s < n)) (ensures (fun c -> FStar.UInt.shift_right (v a) (UInt32.v s) = v c)) (** Shift left with zero fill, shifting at most the integer width *) val shift_left (a:t) (s:UInt32.t) : Pure t (requires (UInt32.v s < n)) (ensures (fun c -> FStar.UInt.shift_left (v a) (UInt32.v s) = v c)) (**** Comparison operators *) (** Equality Note, it is safe to also use the polymorphic decidable equality operator [=] *) let eq (a:t) (b:t) : Tot bool = eq #n (v a) (v b) (** Greater than *) let gt (a:t) (b:t) : Tot bool = gt #n (v a) (v b) (** Greater than or equal *) let gte (a:t) (b:t) : Tot bool = gte #n (v a) (v b) (** Less than *) let lt (a:t) (b:t) : Tot bool = lt #n (v a) (v b) (** Less than or equal *) let lte (a:t) (b:t) : Tot bool = lte #n (v a) (v b) (** Unary negation *) inline_for_extraction let minus (a:t) = add_mod (lognot a) (uint_to_t 1) (** The maximum shift value for this type, i.e. its width minus one, as an UInt32. *) inline_for_extraction let n_minus_one = UInt32.uint_to_t (n - 1) #set-options "--z3rlimit 80 --initial_fuel 1 --max_fuel 1" (** A constant-time way to compute the equality of two machine integers. With inspiration from https://git.zx2c4.com/WireGuard/commit/src/crypto/curve25519-hacl64.h?id=2e60bb395c1f589a398ec606d611132ef9ef764b Note, the branching on [a=b] is just for proof-purposes. *)
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.UInt32.fsti.checked", "FStar.UInt.fsti.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked" ], "interface_file": false, "source_file": "FStar.UInt64.fsti" }
[ { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.UInt", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.UInt", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 1, "initial_ifuel": 1, "max_fuel": 1, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 80, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
a: FStar.UInt64.t -> b: FStar.UInt64.t -> Prims.Pure FStar.UInt64.t
Prims.Pure
[]
[]
[ "FStar.UInt64.t", "Prims.unit", "Prims.op_Equality", "Prims._assert", "Prims.b2t", "FStar.UInt.uint_t", "FStar.UInt64.n", "FStar.UInt64.v", "FStar.UInt.ones", "Prims.l_and", "Prims.int", "FStar.UInt.logor_lemma_1", "FStar.UInt.lognot_lemma_1", "FStar.UInt.logxor_self", "Prims.bool", "FStar.UInt.zero", "FStar.UInt.lemma_minus_zero", "FStar.UInt.lemma_msb_pow2", "FStar.UInt64.lognot", "FStar.UInt.logxor_neq_nonzero", "FStar.UInt64.sub_mod", "FStar.UInt64.uint_to_t", "FStar.UInt64.shift_right", "FStar.UInt64.n_minus_one", "FStar.UInt64.logor", "FStar.UInt64.minus", "FStar.UInt64.logxor", "Prims.l_True", "Prims.l_imp", "Prims.op_Subtraction", "Prims.pow2", "Prims.op_disEquality" ]
[]
false
false
false
false
false
let eq_mask (a b: t) : Pure t (requires True) (ensures (fun c -> (v a = v b ==> v c = pow2 n - 1) /\ (v a <> v b ==> v c = 0))) =
let x = logxor a b in let minus_x = minus x in let x_or_minus_x = logor x minus_x in let xnx = shift_right x_or_minus_x n_minus_one in let c = sub_mod xnx (uint_to_t 1) in if a = b then (logxor_self (v a); lognot_lemma_1 #n; logor_lemma_1 (v x); assert (v x = 0 /\ v minus_x = 0 /\ v x_or_minus_x = 0 /\ v xnx = 0); assert (v c = ones n)) else (logxor_neq_nonzero (v a) (v b); lemma_msb_pow2 #n (v (lognot x)); lemma_msb_pow2 #n (v minus_x); lemma_minus_zero #n (v x); assert (v c = FStar.UInt.zero n)); c
false
EverParse3d.InputStream.Buffer.Aux.fst
EverParse3d.InputStream.Buffer.Aux._live
val _live (x: t) (h: HS.mem) : Tot prop
val _live (x: t) (h: HS.mem) : Tot prop
let _live (x: t) (h: HS.mem) : Tot prop = IB.live_input_buffer h x.buf x.perm_of /\ B.live h x.pos /\ U32.v (B.deref h x.pos) <= U32.v x.len /\ B.as_seq h (IB.slice_of x.buf).LP.base == Ghost.reveal x.g_all_buf /\ IR.unreadable h x.perm_of 0ul (B.deref h x.pos) /\ IR.readable h x.perm_of (B.deref h x.pos) x.len0 /\ Seq.slice (B.as_seq h (IB.slice_of x.buf).LP.base) 0 (U32.v x.len) == Ghost.reveal x.g_all
{ "file_name": "src/3d/prelude/buffer/EverParse3d.InputStream.Buffer.Aux.fst", "git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
{ "end_col": 92, "end_line": 49, "start_col": 0, "start_line": 38 }
module EverParse3d.InputStream.Buffer.Aux (* This module is here to break circularity in KaRaMeL bundles (because Prims must be in the EverParse bundle because of the string type, as opposed to C,FStar,LowStar.) *) module IB = EverParse3d.InputBuffer module IR = EverParse3d.Readable module LP = LowParse.Low.Base module B = LowStar.Buffer module U8 = FStar.UInt8 module U32 = FStar.UInt32 module U64 = FStar.UInt64 module HS = FStar.HyperStack module HST = FStar.HyperStack.ST noeq type input_buffer = { len0: Ghost.erased U32.t; buf: IB.input_buffer_t len0; perm_of: IR.perm (IB.slice_of buf).LP.base; len: Ghost.erased U32.t; pos: B.pointer (Ghost.erased U32.t); g_all_buf: Ghost.erased (Seq.seq U8.t); g_all: Ghost.erased (Seq.seq U8.t); prf: squash ( U32.v len <= U32.v len0 /\ Seq.length g_all == U32.v len /\ B.loc_disjoint (B.loc_buffer (IB.slice_of buf).LP.base `B.loc_union` IR.loc_perm perm_of) (B.loc_buffer pos) /\ Seq.length g_all_buf == U32.v len0 /\ Ghost.reveal g_all == Seq.slice g_all_buf 0 (U32.v len) ); } inline_for_extraction noextract let t = input_buffer
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowStar.BufferOps.fst.checked", "LowStar.Buffer.fst.checked", "LowParse.Low.Base.fst.checked", "FStar.UInt8.fsti.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked", "EverParse3d.Readable.fsti.checked", "EverParse3d.InputBuffer.fsti.checked", "EverParse3d.ErrorCode.fst.checked" ], "interface_file": false, "source_file": "EverParse3d.InputStream.Buffer.Aux.fst" }
[ { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "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": "LowParse.Low.Base", "short_module": "LP" }, { "abbrev": true, "full_module": "EverParse3d.Readable", "short_module": "IR" }, { "abbrev": true, "full_module": "EverParse3d.InputBuffer", "short_module": "IB" }, { "abbrev": false, "full_module": "EverParse3d.InputStream.Buffer", "short_module": null }, { "abbrev": false, "full_module": "EverParse3d.InputStream.Buffer", "short_module": null }, { "abbrev": 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": 0, "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": [ "smt.qi.eager_threshold=100" ], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 8, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
x: EverParse3d.InputStream.Buffer.Aux.t -> h: FStar.Monotonic.HyperStack.mem -> Prims.prop
Prims.Tot
[ "total" ]
[]
[ "EverParse3d.InputStream.Buffer.Aux.t", "FStar.Monotonic.HyperStack.mem", "Prims.l_and", "EverParse3d.InputBuffer.live_input_buffer", "FStar.Ghost.reveal", "FStar.UInt32.t", "EverParse3d.InputStream.Buffer.Aux.__proj__Mkinput_buffer__item__len0", "EverParse3d.InputStream.Buffer.Aux.__proj__Mkinput_buffer__item__buf", "EverParse3d.InputStream.Buffer.Aux.__proj__Mkinput_buffer__item__perm_of", "LowStar.Monotonic.Buffer.live", "FStar.Ghost.erased", "LowStar.Buffer.trivial_preorder", "EverParse3d.InputStream.Buffer.Aux.__proj__Mkinput_buffer__item__pos", "Prims.b2t", "Prims.op_LessThanOrEqual", "FStar.UInt32.v", "LowStar.Monotonic.Buffer.deref", "EverParse3d.InputStream.Buffer.Aux.__proj__Mkinput_buffer__item__len", "Prims.eq2", "FStar.Seq.Base.seq", "LowParse.Bytes.byte", "LowStar.Monotonic.Buffer.as_seq", "LowParse.Slice.buffer_srel_of_srel", "EverParse3d.InputBuffer.triv", "LowParse.Slice.__proj__Mkslice__item__base", "EverParse3d.InputBuffer.slice_of", "FStar.UInt8.t", "EverParse3d.InputStream.Buffer.Aux.__proj__Mkinput_buffer__item__g_all_buf", "EverParse3d.Readable.unreadable", "FStar.UInt32.__uint_to_t", "EverParse3d.Readable.readable", "FStar.Seq.Base.slice", "EverParse3d.InputStream.Buffer.Aux.__proj__Mkinput_buffer__item__g_all", "Prims.prop" ]
[]
false
false
false
true
true
let _live (x: t) (h: HS.mem) : Tot prop =
IB.live_input_buffer h x.buf x.perm_of /\ B.live h x.pos /\ U32.v (B.deref h x.pos) <= U32.v x.len /\ B.as_seq h (IB.slice_of x.buf).LP.base == Ghost.reveal x.g_all_buf /\ IR.unreadable h x.perm_of 0ul (B.deref h x.pos) /\ IR.readable h x.perm_of (B.deref h x.pos) x.len0 /\ Seq.slice (B.as_seq h (IB.slice_of x.buf).LP.base) 0 (U32.v x.len) == Ghost.reveal x.g_all
false
EverParse3d.InputStream.Buffer.Aux.fst
EverParse3d.InputStream.Buffer.Aux._get_remaining
val _get_remaining (x: t) (h: HS.mem) : Ghost (Seq.seq U8.t) (requires (_live x h)) (ensures (fun y -> Seq.length y <= U32.v x.len))
val _get_remaining (x: t) (h: HS.mem) : Ghost (Seq.seq U8.t) (requires (_live x h)) (ensures (fun y -> Seq.length y <= U32.v x.len))
let _get_remaining (x: t) (h: HS.mem) : Ghost (Seq.seq U8.t) (requires (_live x h)) (ensures (fun y -> Seq.length y <= U32.v x.len)) = let i = U32.v (B.deref h x.pos) in Seq.slice x.g_all i (Seq.length x.g_all)
{ "file_name": "src/3d/prelude/buffer/EverParse3d.InputStream.Buffer.Aux.fst", "git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
{ "end_col": 42, "end_line": 73, "start_col": 0, "start_line": 65 }
module EverParse3d.InputStream.Buffer.Aux (* This module is here to break circularity in KaRaMeL bundles (because Prims must be in the EverParse bundle because of the string type, as opposed to C,FStar,LowStar.) *) module IB = EverParse3d.InputBuffer module IR = EverParse3d.Readable module LP = LowParse.Low.Base module B = LowStar.Buffer module U8 = FStar.UInt8 module U32 = FStar.UInt32 module U64 = FStar.UInt64 module HS = FStar.HyperStack module HST = FStar.HyperStack.ST noeq type input_buffer = { len0: Ghost.erased U32.t; buf: IB.input_buffer_t len0; perm_of: IR.perm (IB.slice_of buf).LP.base; len: Ghost.erased U32.t; pos: B.pointer (Ghost.erased U32.t); g_all_buf: Ghost.erased (Seq.seq U8.t); g_all: Ghost.erased (Seq.seq U8.t); prf: squash ( U32.v len <= U32.v len0 /\ Seq.length g_all == U32.v len /\ B.loc_disjoint (B.loc_buffer (IB.slice_of buf).LP.base `B.loc_union` IR.loc_perm perm_of) (B.loc_buffer pos) /\ Seq.length g_all_buf == U32.v len0 /\ Ghost.reveal g_all == Seq.slice g_all_buf 0 (U32.v len) ); } inline_for_extraction noextract let t = input_buffer unfold let _live (x: t) (h: HS.mem) : Tot prop = IB.live_input_buffer h x.buf x.perm_of /\ B.live h x.pos /\ U32.v (B.deref h x.pos) <= U32.v x.len /\ B.as_seq h (IB.slice_of x.buf).LP.base == Ghost.reveal x.g_all_buf /\ IR.unreadable h x.perm_of 0ul (B.deref h x.pos) /\ IR.readable h x.perm_of (B.deref h x.pos) x.len0 /\ Seq.slice (B.as_seq h (IB.slice_of x.buf).LP.base) 0 (U32.v x.len) == Ghost.reveal x.g_all let _footprint (x: t) : Ghost B.loc (requires True) (ensures (fun y -> B.address_liveness_insensitive_locs `B.loc_includes` y)) = B.loc_buffer (IB.slice_of x.buf).LP.base `B.loc_union` IR.loc_perm x.perm_of `B.loc_union` B.loc_buffer x.pos let _perm_footprint (x: t) : Ghost B.loc (requires True) (ensures (fun y -> _footprint x `B.loc_includes` y)) = IR.loc_perm x.perm_of `B.loc_union` B.loc_buffer x.pos
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowStar.BufferOps.fst.checked", "LowStar.Buffer.fst.checked", "LowParse.Low.Base.fst.checked", "FStar.UInt8.fsti.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked", "EverParse3d.Readable.fsti.checked", "EverParse3d.InputBuffer.fsti.checked", "EverParse3d.ErrorCode.fst.checked" ], "interface_file": false, "source_file": "EverParse3d.InputStream.Buffer.Aux.fst" }
[ { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "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": "LowParse.Low.Base", "short_module": "LP" }, { "abbrev": true, "full_module": "EverParse3d.Readable", "short_module": "IR" }, { "abbrev": true, "full_module": "EverParse3d.InputBuffer", "short_module": "IB" }, { "abbrev": false, "full_module": "EverParse3d.InputStream.Buffer", "short_module": null }, { "abbrev": false, "full_module": "EverParse3d.InputStream.Buffer", "short_module": null }, { "abbrev": 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": 0, "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": [ "smt.qi.eager_threshold=100" ], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 8, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
x: EverParse3d.InputStream.Buffer.Aux.t -> h: FStar.Monotonic.HyperStack.mem -> Prims.Ghost (FStar.Seq.Base.seq FStar.UInt8.t)
Prims.Ghost
[]
[]
[ "EverParse3d.InputStream.Buffer.Aux.t", "FStar.Monotonic.HyperStack.mem", "FStar.Seq.Base.slice", "FStar.UInt8.t", "FStar.Ghost.reveal", "FStar.Seq.Base.seq", "EverParse3d.InputStream.Buffer.Aux.__proj__Mkinput_buffer__item__g_all", "FStar.Seq.Base.length", "FStar.UInt.uint_t", "FStar.UInt32.v", "FStar.UInt32.t", "LowStar.Monotonic.Buffer.deref", "FStar.Ghost.erased", "LowStar.Buffer.trivial_preorder", "EverParse3d.InputStream.Buffer.Aux.__proj__Mkinput_buffer__item__pos", "EverParse3d.InputStream.Buffer.Aux._live", "Prims.b2t", "Prims.op_LessThanOrEqual", "EverParse3d.InputStream.Buffer.Aux.__proj__Mkinput_buffer__item__len" ]
[]
false
false
false
false
false
let _get_remaining (x: t) (h: HS.mem) : Ghost (Seq.seq U8.t) (requires (_live x h)) (ensures (fun y -> Seq.length y <= U32.v x.len)) =
let i = U32.v (B.deref h x.pos) in Seq.slice x.g_all i (Seq.length x.g_all)
false
EverParse3d.InputStream.Buffer.Aux.fst
EverParse3d.InputStream.Buffer.Aux._perm_footprint
val _perm_footprint (x: t) : Ghost B.loc (requires True) (ensures (fun y -> (_footprint x) `B.loc_includes` y))
val _perm_footprint (x: t) : Ghost B.loc (requires True) (ensures (fun y -> (_footprint x) `B.loc_includes` y))
let _perm_footprint (x: t) : Ghost B.loc (requires True) (ensures (fun y -> _footprint x `B.loc_includes` y)) = IR.loc_perm x.perm_of `B.loc_union` B.loc_buffer x.pos
{ "file_name": "src/3d/prelude/buffer/EverParse3d.InputStream.Buffer.Aux.fst", "git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
{ "end_col": 56, "end_line": 63, "start_col": 0, "start_line": 58 }
module EverParse3d.InputStream.Buffer.Aux (* This module is here to break circularity in KaRaMeL bundles (because Prims must be in the EverParse bundle because of the string type, as opposed to C,FStar,LowStar.) *) module IB = EverParse3d.InputBuffer module IR = EverParse3d.Readable module LP = LowParse.Low.Base module B = LowStar.Buffer module U8 = FStar.UInt8 module U32 = FStar.UInt32 module U64 = FStar.UInt64 module HS = FStar.HyperStack module HST = FStar.HyperStack.ST noeq type input_buffer = { len0: Ghost.erased U32.t; buf: IB.input_buffer_t len0; perm_of: IR.perm (IB.slice_of buf).LP.base; len: Ghost.erased U32.t; pos: B.pointer (Ghost.erased U32.t); g_all_buf: Ghost.erased (Seq.seq U8.t); g_all: Ghost.erased (Seq.seq U8.t); prf: squash ( U32.v len <= U32.v len0 /\ Seq.length g_all == U32.v len /\ B.loc_disjoint (B.loc_buffer (IB.slice_of buf).LP.base `B.loc_union` IR.loc_perm perm_of) (B.loc_buffer pos) /\ Seq.length g_all_buf == U32.v len0 /\ Ghost.reveal g_all == Seq.slice g_all_buf 0 (U32.v len) ); } inline_for_extraction noextract let t = input_buffer unfold let _live (x: t) (h: HS.mem) : Tot prop = IB.live_input_buffer h x.buf x.perm_of /\ B.live h x.pos /\ U32.v (B.deref h x.pos) <= U32.v x.len /\ B.as_seq h (IB.slice_of x.buf).LP.base == Ghost.reveal x.g_all_buf /\ IR.unreadable h x.perm_of 0ul (B.deref h x.pos) /\ IR.readable h x.perm_of (B.deref h x.pos) x.len0 /\ Seq.slice (B.as_seq h (IB.slice_of x.buf).LP.base) 0 (U32.v x.len) == Ghost.reveal x.g_all let _footprint (x: t) : Ghost B.loc (requires True) (ensures (fun y -> B.address_liveness_insensitive_locs `B.loc_includes` y)) = B.loc_buffer (IB.slice_of x.buf).LP.base `B.loc_union` IR.loc_perm x.perm_of `B.loc_union` B.loc_buffer x.pos
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowStar.BufferOps.fst.checked", "LowStar.Buffer.fst.checked", "LowParse.Low.Base.fst.checked", "FStar.UInt8.fsti.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked", "EverParse3d.Readable.fsti.checked", "EverParse3d.InputBuffer.fsti.checked", "EverParse3d.ErrorCode.fst.checked" ], "interface_file": false, "source_file": "EverParse3d.InputStream.Buffer.Aux.fst" }
[ { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "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": "LowParse.Low.Base", "short_module": "LP" }, { "abbrev": true, "full_module": "EverParse3d.Readable", "short_module": "IR" }, { "abbrev": true, "full_module": "EverParse3d.InputBuffer", "short_module": "IB" }, { "abbrev": false, "full_module": "EverParse3d.InputStream.Buffer", "short_module": null }, { "abbrev": false, "full_module": "EverParse3d.InputStream.Buffer", "short_module": null }, { "abbrev": 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": 0, "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": [ "smt.qi.eager_threshold=100" ], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 8, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
x: EverParse3d.InputStream.Buffer.Aux.t -> Prims.Ghost LowStar.Monotonic.Buffer.loc
Prims.Ghost
[]
[]
[ "EverParse3d.InputStream.Buffer.Aux.t", "LowStar.Monotonic.Buffer.loc_union", "EverParse3d.Readable.loc_perm", "LowParse.Bytes.byte", "LowParse.Slice.__proj__Mkslice__item__base", "EverParse3d.InputBuffer.triv", "EverParse3d.InputBuffer.slice_of", "FStar.Ghost.reveal", "FStar.UInt32.t", "EverParse3d.InputStream.Buffer.Aux.__proj__Mkinput_buffer__item__len0", "EverParse3d.InputStream.Buffer.Aux.__proj__Mkinput_buffer__item__buf", "EverParse3d.InputStream.Buffer.Aux.__proj__Mkinput_buffer__item__perm_of", "LowStar.Monotonic.Buffer.loc_buffer", "FStar.Ghost.erased", "LowStar.Buffer.trivial_preorder", "EverParse3d.InputStream.Buffer.Aux.__proj__Mkinput_buffer__item__pos", "LowStar.Monotonic.Buffer.loc", "Prims.l_True", "LowStar.Monotonic.Buffer.loc_includes", "EverParse3d.InputStream.Buffer.Aux._footprint" ]
[]
false
false
false
false
false
let _perm_footprint (x: t) : Ghost B.loc (requires True) (ensures (fun y -> (_footprint x) `B.loc_includes` y)) =
(IR.loc_perm x.perm_of) `B.loc_union` (B.loc_buffer x.pos)
false
LowStar.Regional.fst
LowStar.Regional.rg_free
val rg_free (#a #rst: _) (rg: regional rst a) (v: a) : HST.ST unit (requires (fun h0 -> rg_inv rg h0 v)) (ensures (fun h0 _ h1 -> modifies (loc_all_regions_from false (Rgl?.region_of rg v)) h0 h1))
val rg_free (#a #rst: _) (rg: regional rst a) (v: a) : HST.ST unit (requires (fun h0 -> rg_inv rg h0 v)) (ensures (fun h0 _ h1 -> modifies (loc_all_regions_from false (Rgl?.region_of rg v)) h0 h1))
let rg_free #a #rst (rg:regional rst a) (v:a) : HST.ST unit (requires (fun h0 -> rg_inv rg h0 v)) (ensures (fun h0 _ h1 -> modifies (loc_all_regions_from false (Rgl?.region_of rg v)) h0 h1)) = (Rgl?.r_free rg) (Rgl?.state rg) v
{ "file_name": "ulib/LowStar.Regional.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 36, "end_line": 165, "start_col": 0, "start_line": 160 }
(* Copyright 2008-2018 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module LowStar.Regional (** * This module defines what is conceptually a typeclass called * `regional` (although it is not syntactically marked as a `class` * yet). * * `regional a` is the the class of types whose values have explicit * memory allocations confined spatially within a single heap region * in the hyperstack memory model. * * Being confined to a region, values of regional types support a * natural framing principles: state mutations that do not overlap * with a regional value's region are noninterfering. * * Instances of regional types are given for buffers and vectors: * See LowStar.Regional.Instances, LowStar.RVector for samples. * *) open LowStar.Modifies module HS = FStar.HyperStack module HST = FStar.HyperStack.ST /// Regionality /// Motivation: we want to ensure that all stateful operations for a value of /// type `a` are within the `region_of` the value. /// /// Furthermore, we would like regional to be parameterized over another type class /// that elements can have. However, we are also trying to extract to C, meaning /// that we can't incur any run-time lookups and indirections. In essence, we'd /// like for members of a regional to potentially be partial applications where /// the first argument may be an agility parameter, an extra type class for the /// elements, etc. etc. except that partial applications are not allowed in C. /// /// We therefore add an "st" type, which is a piece of (pure) state (hence more /// like a parameter) that functions are allowed to capture. Currently, only /// ``r_alloc`` needs that extra parameter. The parameter is stored within the /// type class, so that clients are not required to manage that piece of state /// themselves. This is, in effect, closure-conversion for ``r_alloc`` where the /// closure state is lifted and stored in the regional itself. As such, the only /// piece of state that ``r_alloc`` may receive is the exact value that was /// captured. /// /// Several alternative designs exist, e.g. making ``a`` at type ``st -> Type0`` /// (won't extract); instantiating ``st`` as a singleton type and dropping the /// refinement (also works, but doesn't make the intent of closure-conversion /// explicit); dropping the refinement and leaving it up to the user to store /// the refinement in ``r_inv`` (which would then take ``state`` as an /// argument)... noeq type regional (st:Type) (a:Type0) = | Rgl: // This is not really a piece of state, but more like a parameter. state: st -> // The target type should have a region where it belongs. region_of: (a -> GTot HS.rid) -> //loc_of for the underlying a loc_of: (a -> GTot loc) -> // A parameterless value of type `a`. // It does not have to satisfy the invariant `r_inv` described below. dummy: a -> // An invariant we want to maintain for each operation. // For example, it may include `live` and `freeable` properties // for related objects. r_inv: (HS.mem -> a -> GTot Type0) -> r_inv_reg: (h:HS.mem -> v:a -> Lemma (requires (r_inv h v)) (ensures (HS.live_region h (region_of v)))) -> // A representation type of `a` and a corresponding conversion function repr: Type0 -> r_repr: (h:HS.mem -> v:a{r_inv h v} -> GTot repr) -> // A core separation lemma, saying that the invariant and representation are // preserved when an orthogonal state transition happens. r_sep: (v:a -> p:loc -> h:HS.mem -> h':HS.mem -> Lemma (requires (r_inv h v /\ loc_disjoint (loc_all_regions_from false (region_of v)) p /\ modifies p h h')) (ensures (r_inv h' v /\ r_repr h v == r_repr h' v))) -> /// Allocation // The representation for the initial value of type `a` irepr: Ghost.erased repr -> // A property that should hold for all initial values of type `a`. r_alloc_p: (a -> GTot Type0) -> // An allocation operation. We might have several ways of initializing a // given target type `a`; then multiple typeclass instances should be // defined, and each of them can be used properly. r_alloc: ((s:st { s == state }) -> r:HST.erid -> HST.ST a (requires (fun h0 -> True)) (ensures (fun h0 v h1 -> Set.subset (Map.domain (HS.get_hmap h0)) (Map.domain (HS.get_hmap h1)) /\ modifies loc_none h0 h1 /\ fresh_loc (loc_of v) h0 h1 /\ //the underlying loc is fresh r_alloc_p v /\ r_inv h1 v /\ region_of v == r /\ r_repr h1 v == Ghost.reveal irepr))) -> // Destruction: note that it allows to `modify` all the regions, including // its subregions. It is fair when we want to `free` a vector and its // elements as well, assuming the elements belong to subregions. r_free: ((s:st { s == state }) -> v:a -> HST.ST unit (requires (fun h0 -> r_inv h0 v)) (ensures (fun h0 _ h1 -> modifies (loc_all_regions_from false (region_of v)) h0 h1))) -> regional st a let rg_inv #a #rst (rg: regional rst a) = Rgl?.r_inv rg inline_for_extraction let rg_dummy #a #rst (rg:regional rst a) : Tot a = Rgl?.dummy rg inline_for_extraction let rg_alloc #a #rst (rg:regional rst a) (r:HST.erid) : HST.ST a (requires (fun h0 -> True)) (ensures (fun h0 v h1 -> Set.subset (Map.domain (HS.get_hmap h0)) (Map.domain (HS.get_hmap h1)) /\ modifies loc_none h0 h1 /\ fresh_loc (Rgl?.loc_of rg v) h0 h1 /\ (Rgl?.r_alloc_p rg) v /\ rg_inv rg h1 v /\ (Rgl?.region_of rg) v == r /\ (Rgl?.r_repr rg) h1 v == Ghost.reveal (Rgl?.irepr rg))) = Rgl?.r_alloc rg (Rgl?.state rg) r
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowStar.Modifies.fst.checked", "FStar.Set.fsti.checked", "FStar.Pervasives.fsti.checked", "FStar.Map.fsti.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked" ], "interface_file": false, "source_file": "LowStar.Regional.fst" }
[ { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": false, "full_module": "LowStar.Modifies", "short_module": null }, { "abbrev": false, "full_module": "LowStar", "short_module": null }, { "abbrev": false, "full_module": "LowStar", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
rg: LowStar.Regional.regional rst a -> v: a -> FStar.HyperStack.ST.ST Prims.unit
FStar.HyperStack.ST.ST
[]
[]
[ "LowStar.Regional.regional", "LowStar.Regional.__proj__Rgl__item__r_free", "LowStar.Regional.__proj__Rgl__item__state", "Prims.unit", "FStar.Monotonic.HyperStack.mem", "LowStar.Regional.rg_inv", "LowStar.Monotonic.Buffer.modifies", "LowStar.Monotonic.Buffer.loc_all_regions_from", "LowStar.Regional.__proj__Rgl__item__region_of" ]
[]
false
true
false
false
false
let rg_free #a #rst (rg: regional rst a) (v: a) : HST.ST unit (requires (fun h0 -> rg_inv rg h0 v)) (ensures (fun h0 _ h1 -> modifies (loc_all_regions_from false (Rgl?.region_of rg v)) h0 h1)) =
(Rgl?.r_free rg) (Rgl?.state rg) v
false
LowStar.Regional.fst
LowStar.Regional.rg_alloc
val rg_alloc (#a #rst: _) (rg: regional rst a) (r: HST.erid) : HST.ST a (requires (fun h0 -> True)) (ensures (fun h0 v h1 -> Set.subset (Map.domain (HS.get_hmap h0)) (Map.domain (HS.get_hmap h1)) /\ modifies loc_none h0 h1 /\ fresh_loc (Rgl?.loc_of rg v) h0 h1 /\ (Rgl?.r_alloc_p rg) v /\ rg_inv rg h1 v /\ (Rgl?.region_of rg) v == r /\ (Rgl?.r_repr rg) h1 v == Ghost.reveal (Rgl?.irepr rg)))
val rg_alloc (#a #rst: _) (rg: regional rst a) (r: HST.erid) : HST.ST a (requires (fun h0 -> True)) (ensures (fun h0 v h1 -> Set.subset (Map.domain (HS.get_hmap h0)) (Map.domain (HS.get_hmap h1)) /\ modifies loc_none h0 h1 /\ fresh_loc (Rgl?.loc_of rg v) h0 h1 /\ (Rgl?.r_alloc_p rg) v /\ rg_inv rg h1 v /\ (Rgl?.region_of rg) v == r /\ (Rgl?.r_repr rg) h1 v == Ghost.reveal (Rgl?.irepr rg)))
let rg_alloc #a #rst (rg:regional rst a) (r:HST.erid) : HST.ST a (requires (fun h0 -> True)) (ensures (fun h0 v h1 -> Set.subset (Map.domain (HS.get_hmap h0)) (Map.domain (HS.get_hmap h1)) /\ modifies loc_none h0 h1 /\ fresh_loc (Rgl?.loc_of rg v) h0 h1 /\ (Rgl?.r_alloc_p rg) v /\ rg_inv rg h1 v /\ (Rgl?.region_of rg) v == r /\ (Rgl?.r_repr rg) h1 v == Ghost.reveal (Rgl?.irepr rg))) = Rgl?.r_alloc rg (Rgl?.state rg) r
{ "file_name": "ulib/LowStar.Regional.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 35, "end_line": 157, "start_col": 0, "start_line": 147 }
(* Copyright 2008-2018 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module LowStar.Regional (** * This module defines what is conceptually a typeclass called * `regional` (although it is not syntactically marked as a `class` * yet). * * `regional a` is the the class of types whose values have explicit * memory allocations confined spatially within a single heap region * in the hyperstack memory model. * * Being confined to a region, values of regional types support a * natural framing principles: state mutations that do not overlap * with a regional value's region are noninterfering. * * Instances of regional types are given for buffers and vectors: * See LowStar.Regional.Instances, LowStar.RVector for samples. * *) open LowStar.Modifies module HS = FStar.HyperStack module HST = FStar.HyperStack.ST /// Regionality /// Motivation: we want to ensure that all stateful operations for a value of /// type `a` are within the `region_of` the value. /// /// Furthermore, we would like regional to be parameterized over another type class /// that elements can have. However, we are also trying to extract to C, meaning /// that we can't incur any run-time lookups and indirections. In essence, we'd /// like for members of a regional to potentially be partial applications where /// the first argument may be an agility parameter, an extra type class for the /// elements, etc. etc. except that partial applications are not allowed in C. /// /// We therefore add an "st" type, which is a piece of (pure) state (hence more /// like a parameter) that functions are allowed to capture. Currently, only /// ``r_alloc`` needs that extra parameter. The parameter is stored within the /// type class, so that clients are not required to manage that piece of state /// themselves. This is, in effect, closure-conversion for ``r_alloc`` where the /// closure state is lifted and stored in the regional itself. As such, the only /// piece of state that ``r_alloc`` may receive is the exact value that was /// captured. /// /// Several alternative designs exist, e.g. making ``a`` at type ``st -> Type0`` /// (won't extract); instantiating ``st`` as a singleton type and dropping the /// refinement (also works, but doesn't make the intent of closure-conversion /// explicit); dropping the refinement and leaving it up to the user to store /// the refinement in ``r_inv`` (which would then take ``state`` as an /// argument)... noeq type regional (st:Type) (a:Type0) = | Rgl: // This is not really a piece of state, but more like a parameter. state: st -> // The target type should have a region where it belongs. region_of: (a -> GTot HS.rid) -> //loc_of for the underlying a loc_of: (a -> GTot loc) -> // A parameterless value of type `a`. // It does not have to satisfy the invariant `r_inv` described below. dummy: a -> // An invariant we want to maintain for each operation. // For example, it may include `live` and `freeable` properties // for related objects. r_inv: (HS.mem -> a -> GTot Type0) -> r_inv_reg: (h:HS.mem -> v:a -> Lemma (requires (r_inv h v)) (ensures (HS.live_region h (region_of v)))) -> // A representation type of `a` and a corresponding conversion function repr: Type0 -> r_repr: (h:HS.mem -> v:a{r_inv h v} -> GTot repr) -> // A core separation lemma, saying that the invariant and representation are // preserved when an orthogonal state transition happens. r_sep: (v:a -> p:loc -> h:HS.mem -> h':HS.mem -> Lemma (requires (r_inv h v /\ loc_disjoint (loc_all_regions_from false (region_of v)) p /\ modifies p h h')) (ensures (r_inv h' v /\ r_repr h v == r_repr h' v))) -> /// Allocation // The representation for the initial value of type `a` irepr: Ghost.erased repr -> // A property that should hold for all initial values of type `a`. r_alloc_p: (a -> GTot Type0) -> // An allocation operation. We might have several ways of initializing a // given target type `a`; then multiple typeclass instances should be // defined, and each of them can be used properly. r_alloc: ((s:st { s == state }) -> r:HST.erid -> HST.ST a (requires (fun h0 -> True)) (ensures (fun h0 v h1 -> Set.subset (Map.domain (HS.get_hmap h0)) (Map.domain (HS.get_hmap h1)) /\ modifies loc_none h0 h1 /\ fresh_loc (loc_of v) h0 h1 /\ //the underlying loc is fresh r_alloc_p v /\ r_inv h1 v /\ region_of v == r /\ r_repr h1 v == Ghost.reveal irepr))) -> // Destruction: note that it allows to `modify` all the regions, including // its subregions. It is fair when we want to `free` a vector and its // elements as well, assuming the elements belong to subregions. r_free: ((s:st { s == state }) -> v:a -> HST.ST unit (requires (fun h0 -> r_inv h0 v)) (ensures (fun h0 _ h1 -> modifies (loc_all_regions_from false (region_of v)) h0 h1))) -> regional st a let rg_inv #a #rst (rg: regional rst a) = Rgl?.r_inv rg inline_for_extraction let rg_dummy #a #rst (rg:regional rst a) : Tot a = Rgl?.dummy rg
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowStar.Modifies.fst.checked", "FStar.Set.fsti.checked", "FStar.Pervasives.fsti.checked", "FStar.Map.fsti.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked" ], "interface_file": false, "source_file": "LowStar.Regional.fst" }
[ { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": false, "full_module": "LowStar.Modifies", "short_module": null }, { "abbrev": false, "full_module": "LowStar", "short_module": null }, { "abbrev": false, "full_module": "LowStar", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
rg: LowStar.Regional.regional rst a -> r: FStar.HyperStack.ST.erid -> FStar.HyperStack.ST.ST a
FStar.HyperStack.ST.ST
[]
[]
[ "LowStar.Regional.regional", "FStar.HyperStack.ST.erid", "LowStar.Regional.__proj__Rgl__item__r_alloc", "LowStar.Regional.__proj__Rgl__item__state", "FStar.Monotonic.HyperStack.mem", "Prims.l_True", "Prims.l_and", "FStar.Set.subset", "FStar.Monotonic.HyperHeap.rid", "FStar.Map.domain", "FStar.Monotonic.Heap.heap", "FStar.Monotonic.HyperStack.get_hmap", "LowStar.Monotonic.Buffer.modifies", "LowStar.Monotonic.Buffer.loc_none", "LowStar.Monotonic.Buffer.fresh_loc", "LowStar.Regional.__proj__Rgl__item__loc_of", "LowStar.Regional.__proj__Rgl__item__r_alloc_p", "LowStar.Regional.rg_inv", "Prims.eq2", "LowStar.Regional.__proj__Rgl__item__region_of", "LowStar.Regional.__proj__Rgl__item__repr", "LowStar.Regional.__proj__Rgl__item__r_repr", "FStar.Ghost.reveal", "LowStar.Regional.__proj__Rgl__item__irepr" ]
[]
false
true
false
false
false
let rg_alloc #a #rst (rg: regional rst a) (r: HST.erid) : HST.ST a (requires (fun h0 -> True)) (ensures (fun h0 v h1 -> Set.subset (Map.domain (HS.get_hmap h0)) (Map.domain (HS.get_hmap h1)) /\ modifies loc_none h0 h1 /\ fresh_loc (Rgl?.loc_of rg v) h0 h1 /\ (Rgl?.r_alloc_p rg) v /\ rg_inv rg h1 v /\ (Rgl?.region_of rg) v == r /\ (Rgl?.r_repr rg) h1 v == Ghost.reveal (Rgl?.irepr rg))) =
Rgl?.r_alloc rg (Rgl?.state rg) r
false
FStar.UInt64.fsti
FStar.UInt64.gte_mask
val gte_mask (a b: t) : Pure t (requires True) (ensures (fun c -> (v a >= v b ==> v c = pow2 n - 1) /\ (v a < v b ==> v c = 0)))
val gte_mask (a b: t) : Pure t (requires True) (ensures (fun c -> (v a >= v b ==> v c = pow2 n - 1) /\ (v a < v b ==> v c = 0)))
let gte_mask (a:t) (b:t) : Pure t (requires True) (ensures (fun c -> (v a >= v b ==> v c = pow2 n - 1) /\ (v a < v b ==> v c = 0))) = let x = a in let y = b in let x_xor_y = logxor x y in let x_sub_y = sub_mod x y in let x_sub_y_xor_y = logxor x_sub_y y in let q = logor x_xor_y x_sub_y_xor_y in let x_xor_q = logxor x q in let x_xor_q_ = shift_right x_xor_q n_minus_one in let c = sub_mod x_xor_q_ (uint_to_t 1) in lemma_sub_msbs x y; lemma_msb_gte (v x) (v y); lemma_msb_gte (v y) (v x); c
{ "file_name": "ulib/FStar.UInt64.fsti", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 5, "end_line": 312, "start_col": 0, "start_line": 295 }
(* 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 FStar.UInt64 (**** THIS MODULE IS GENERATED AUTOMATICALLY USING [mk_int.sh], DO NOT EDIT DIRECTLY ****) unfold let n = 64 /// For FStar.UIntN.fstp: anything that you fix/update here should be /// reflected in [FStar.IntN.fstp], which is mostly a copy-paste of /// this module. /// /// Except, as compared to [FStar.IntN.fstp], here: /// - every occurrence of [int_t] has been replaced with [uint_t] /// - every occurrence of [@%] has been replaced with [%]. /// - some functions (e.g., add_underspec, etc.) are only defined here, not on signed integers /// This module provides an abstract type for machine integers of a /// given signedness and width. The interface is designed to be safe /// with respect to arithmetic underflow and overflow. /// Note, we have attempted several times to re-design this module to /// make it more amenable to normalization and to impose less overhead /// on the SMT solver when reasoning about machine integer /// arithmetic. The following github issue reports on the current /// status of that work. /// /// https://github.com/FStarLang/FStar/issues/1757 open FStar.UInt open FStar.Mul #set-options "--max_fuel 0 --max_ifuel 0" (** Abstract type of machine integers, with an underlying representation using a bounded mathematical integer *) new val t : eqtype (** A coercion that projects a bounded mathematical integer from a machine integer *) val v (x:t) : Tot (uint_t n) (** A coercion that injects a bounded mathematical integers into a machine integer *) val uint_to_t (x:uint_t n) : Pure t (requires True) (ensures (fun y -> v y = x)) (** Injection/projection inverse *) val uv_inv (x : t) : Lemma (ensures (uint_to_t (v x) == x)) [SMTPat (v x)] (** Projection/injection inverse *) val vu_inv (x : uint_t n) : Lemma (ensures (v (uint_to_t x) == x)) [SMTPat (uint_to_t x)] (** An alternate form of the injectivity of the [v] projection *) val v_inj (x1 x2: t): Lemma (requires (v x1 == v x2)) (ensures (x1 == x2)) (** Constants 0 and 1 *) val zero : x:t{v x = 0} val one : x:t{v x = 1} (**** Addition primitives *) (** Bounds-respecting addition The precondition enforces that the sum does not overflow, expressing the bound as an addition on mathematical integers *) val add (a:t) (b:t) : Pure t (requires (size (v a + v b) n)) (ensures (fun c -> v a + v b = v c)) (** Underspecified, possibly overflowing addition: The postcondition only enures that the result is the sum of the arguments in case there is no overflow *) val add_underspec (a:t) (b:t) : Pure t (requires True) (ensures (fun c -> size (v a + v b) n ==> v a + v b = v c)) (** Addition modulo [2^n] Machine integers can always be added, but the postcondition is now in terms of addition modulo [2^n] on mathematical integers *) val add_mod (a:t) (b:t) : Pure t (requires True) (ensures (fun c -> FStar.UInt.add_mod (v a) (v b) = v c)) (**** Subtraction primitives *) (** Bounds-respecting subtraction The precondition enforces that the difference does not underflow, expressing the bound as a difference on mathematical integers *) val sub (a:t) (b:t) : Pure t (requires (size (v a - v b) n)) (ensures (fun c -> v a - v b = v c)) (** Underspecified, possibly overflowing subtraction: The postcondition only enures that the result is the difference of the arguments in case there is no underflow *) val sub_underspec (a:t) (b:t) : Pure t (requires True) (ensures (fun c -> size (v a - v b) n ==> v a - v b = v c)) (** Subtraction modulo [2^n] Machine integers can always be subtractd, but the postcondition is now in terms of subtraction modulo [2^n] on mathematical integers *) val sub_mod (a:t) (b:t) : Pure t (requires True) (ensures (fun c -> FStar.UInt.sub_mod (v a) (v b) = v c)) (**** Multiplication primitives *) (** Bounds-respecting multiplication The precondition enforces that the product does not overflow, expressing the bound as a product on mathematical integers *) val mul (a:t) (b:t) : Pure t (requires (size (v a * v b) n)) (ensures (fun c -> v a * v b = v c)) (** Underspecified, possibly overflowing product The postcondition only enures that the result is the product of the arguments in case there is no overflow *) val mul_underspec (a:t) (b:t) : Pure t (requires True) (ensures (fun c -> size (v a * v b) n ==> v a * v b = v c)) (** Multiplication modulo [2^n] Machine integers can always be multiplied, but the postcondition is now in terms of product modulo [2^n] on mathematical integers *) val mul_mod (a:t) (b:t) : Pure t (requires True) (ensures (fun c -> FStar.UInt.mul_mod (v a) (v b) = v c)) (**** Division primitives *) (** Euclidean division of [a] and [b], with [b] non-zero *) val div (a:t) (b:t{v b <> 0}) : Pure t (requires (True)) (ensures (fun c -> v a / v b = v c)) (**** Modulo primitives *) (** Euclidean remainder The result is the modulus of [a] with respect to a non-zero [b] *) val rem (a:t) (b:t{v b <> 0}) : Pure t (requires True) (ensures (fun c -> FStar.UInt.mod (v a) (v b) = v c)) (**** Bitwise operators *) /// Also see FStar.BV (** Bitwise logical conjunction *) val logand (x:t) (y:t) : Pure t (requires True) (ensures (fun z -> v x `logand` v y = v z)) (** Bitwise logical exclusive-or *) val logxor (x:t) (y:t) : Pure t (requires True) (ensures (fun z -> v x `logxor` v y == v z)) (** Bitwise logical disjunction *) val logor (x:t) (y:t) : Pure t (requires True) (ensures (fun z -> v x `logor` v y == v z)) (** Bitwise logical negation *) val lognot (x:t) : Pure t (requires True) (ensures (fun z -> lognot (v x) == v z)) (**** Shift operators *) (** Shift right with zero fill, shifting at most the integer width *) val shift_right (a:t) (s:UInt32.t) : Pure t (requires (UInt32.v s < n)) (ensures (fun c -> FStar.UInt.shift_right (v a) (UInt32.v s) = v c)) (** Shift left with zero fill, shifting at most the integer width *) val shift_left (a:t) (s:UInt32.t) : Pure t (requires (UInt32.v s < n)) (ensures (fun c -> FStar.UInt.shift_left (v a) (UInt32.v s) = v c)) (**** Comparison operators *) (** Equality Note, it is safe to also use the polymorphic decidable equality operator [=] *) let eq (a:t) (b:t) : Tot bool = eq #n (v a) (v b) (** Greater than *) let gt (a:t) (b:t) : Tot bool = gt #n (v a) (v b) (** Greater than or equal *) let gte (a:t) (b:t) : Tot bool = gte #n (v a) (v b) (** Less than *) let lt (a:t) (b:t) : Tot bool = lt #n (v a) (v b) (** Less than or equal *) let lte (a:t) (b:t) : Tot bool = lte #n (v a) (v b) (** Unary negation *) inline_for_extraction let minus (a:t) = add_mod (lognot a) (uint_to_t 1) (** The maximum shift value for this type, i.e. its width minus one, as an UInt32. *) inline_for_extraction let n_minus_one = UInt32.uint_to_t (n - 1) #set-options "--z3rlimit 80 --initial_fuel 1 --max_fuel 1" (** A constant-time way to compute the equality of two machine integers. With inspiration from https://git.zx2c4.com/WireGuard/commit/src/crypto/curve25519-hacl64.h?id=2e60bb395c1f589a398ec606d611132ef9ef764b Note, the branching on [a=b] is just for proof-purposes. *) [@ CNoInline ] let eq_mask (a:t) (b:t) : Pure t (requires True) (ensures (fun c -> (v a = v b ==> v c = pow2 n - 1) /\ (v a <> v b ==> v c = 0))) = let x = logxor a b in let minus_x = minus x in let x_or_minus_x = logor x minus_x in let xnx = shift_right x_or_minus_x n_minus_one in let c = sub_mod xnx (uint_to_t 1) in if a = b then begin logxor_self (v a); lognot_lemma_1 #n; logor_lemma_1 (v x); assert (v x = 0 /\ v minus_x = 0 /\ v x_or_minus_x = 0 /\ v xnx = 0); assert (v c = ones n) end else begin logxor_neq_nonzero (v a) (v b); lemma_msb_pow2 #n (v (lognot x)); lemma_msb_pow2 #n (v minus_x); lemma_minus_zero #n (v x); assert (v c = FStar.UInt.zero n) end; c private val lemma_sub_msbs (a:t) (b:t) : Lemma ((msb (v a) = msb (v b)) ==> (v a < v b <==> msb (v (sub_mod a b)))) (** A constant-time way to compute the [>=] inequality of two machine integers. With inspiration from https://git.zx2c4.com/WireGuard/commit/src/crypto/curve25519-hacl64.h?id=0a483a9b431d87eca1b275463c632f8d5551978a *)
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.UInt32.fsti.checked", "FStar.UInt.fsti.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked" ], "interface_file": false, "source_file": "FStar.UInt64.fsti" }
[ { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.UInt", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.UInt", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 1, "initial_ifuel": 1, "max_fuel": 1, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 80, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
a: FStar.UInt64.t -> b: FStar.UInt64.t -> Prims.Pure FStar.UInt64.t
Prims.Pure
[]
[]
[ "FStar.UInt64.t", "Prims.unit", "FStar.UInt.lemma_msb_gte", "FStar.UInt64.n", "FStar.UInt64.v", "FStar.UInt64.lemma_sub_msbs", "FStar.UInt64.sub_mod", "FStar.UInt64.uint_to_t", "FStar.UInt64.shift_right", "FStar.UInt64.n_minus_one", "FStar.UInt64.logxor", "FStar.UInt64.logor", "Prims.l_True", "Prims.l_and", "Prims.l_imp", "Prims.b2t", "Prims.op_GreaterThanOrEqual", "Prims.op_Equality", "Prims.int", "Prims.op_Subtraction", "Prims.pow2", "Prims.op_LessThan" ]
[]
false
false
false
false
false
let gte_mask (a b: t) : Pure t (requires True) (ensures (fun c -> (v a >= v b ==> v c = pow2 n - 1) /\ (v a < v b ==> v c = 0))) =
let x = a in let y = b in let x_xor_y = logxor x y in let x_sub_y = sub_mod x y in let x_sub_y_xor_y = logxor x_sub_y y in let q = logor x_xor_y x_sub_y_xor_y in let x_xor_q = logxor x q in let x_xor_q_ = shift_right x_xor_q n_minus_one in let c = sub_mod x_xor_q_ (uint_to_t 1) in lemma_sub_msbs x y; lemma_msb_gte (v x) (v y); lemma_msb_gte (v y) (v x); c
false
EverParse3d.InputStream.Buffer.Aux.fst
EverParse3d.InputStream.Buffer.Aux.default_error_handler
val default_error_handler (typename_s fieldname reason: string) (error_code: U64.t) (context: B.pointer EverParse3d.ErrorCode.error_frame) (input: input_buffer) (start_pos: U64.t) : HST.Stack unit (requires (fun h -> B.live h context)) (ensures (fun h _ h' -> B.modifies (B.loc_buffer context) h h'))
val default_error_handler (typename_s fieldname reason: string) (error_code: U64.t) (context: B.pointer EverParse3d.ErrorCode.error_frame) (input: input_buffer) (start_pos: U64.t) : HST.Stack unit (requires (fun h -> B.live h context)) (ensures (fun h _ h' -> B.modifies (B.loc_buffer context) h h'))
let default_error_handler (typename_s: string) (fieldname: string) (reason: string) (error_code: U64.t) (context: B.pointer EverParse3d.ErrorCode.error_frame) (input: input_buffer) (start_pos: U64.t) : HST.Stack unit (requires (fun h -> B.live h context)) (ensures (fun h _ h' -> B.modifies (B.loc_buffer context) h h')) = if not ( !* context ).EverParse3d.ErrorCode.filled then begin context *= { EverParse3d.ErrorCode.filled = true; EverParse3d.ErrorCode.start_pos = start_pos; EverParse3d.ErrorCode.typename_s = typename_s; EverParse3d.ErrorCode.fieldname = fieldname; EverParse3d.ErrorCode.reason = reason; EverParse3d.ErrorCode.error_code = error_code; } end
{ "file_name": "src/3d/prelude/buffer/EverParse3d.InputStream.Buffer.Aux.fst", "git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
{ "end_col": 5, "end_line": 100, "start_col": 0, "start_line": 79 }
module EverParse3d.InputStream.Buffer.Aux (* This module is here to break circularity in KaRaMeL bundles (because Prims must be in the EverParse bundle because of the string type, as opposed to C,FStar,LowStar.) *) module IB = EverParse3d.InputBuffer module IR = EverParse3d.Readable module LP = LowParse.Low.Base module B = LowStar.Buffer module U8 = FStar.UInt8 module U32 = FStar.UInt32 module U64 = FStar.UInt64 module HS = FStar.HyperStack module HST = FStar.HyperStack.ST noeq type input_buffer = { len0: Ghost.erased U32.t; buf: IB.input_buffer_t len0; perm_of: IR.perm (IB.slice_of buf).LP.base; len: Ghost.erased U32.t; pos: B.pointer (Ghost.erased U32.t); g_all_buf: Ghost.erased (Seq.seq U8.t); g_all: Ghost.erased (Seq.seq U8.t); prf: squash ( U32.v len <= U32.v len0 /\ Seq.length g_all == U32.v len /\ B.loc_disjoint (B.loc_buffer (IB.slice_of buf).LP.base `B.loc_union` IR.loc_perm perm_of) (B.loc_buffer pos) /\ Seq.length g_all_buf == U32.v len0 /\ Ghost.reveal g_all == Seq.slice g_all_buf 0 (U32.v len) ); } inline_for_extraction noextract let t = input_buffer unfold let _live (x: t) (h: HS.mem) : Tot prop = IB.live_input_buffer h x.buf x.perm_of /\ B.live h x.pos /\ U32.v (B.deref h x.pos) <= U32.v x.len /\ B.as_seq h (IB.slice_of x.buf).LP.base == Ghost.reveal x.g_all_buf /\ IR.unreadable h x.perm_of 0ul (B.deref h x.pos) /\ IR.readable h x.perm_of (B.deref h x.pos) x.len0 /\ Seq.slice (B.as_seq h (IB.slice_of x.buf).LP.base) 0 (U32.v x.len) == Ghost.reveal x.g_all let _footprint (x: t) : Ghost B.loc (requires True) (ensures (fun y -> B.address_liveness_insensitive_locs `B.loc_includes` y)) = B.loc_buffer (IB.slice_of x.buf).LP.base `B.loc_union` IR.loc_perm x.perm_of `B.loc_union` B.loc_buffer x.pos let _perm_footprint (x: t) : Ghost B.loc (requires True) (ensures (fun y -> _footprint x `B.loc_includes` y)) = IR.loc_perm x.perm_of `B.loc_union` B.loc_buffer x.pos let _get_remaining (x: t) (h: HS.mem) : Ghost (Seq.seq U8.t) (requires (_live x h)) (ensures (fun y -> Seq.length y <= U32.v x.len)) = let i = U32.v (B.deref h x.pos) in Seq.slice x.g_all i (Seq.length x.g_all) (* default error handler *) open LowStar.BufferOps
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowStar.BufferOps.fst.checked", "LowStar.Buffer.fst.checked", "LowParse.Low.Base.fst.checked", "FStar.UInt8.fsti.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked", "EverParse3d.Readable.fsti.checked", "EverParse3d.InputBuffer.fsti.checked", "EverParse3d.ErrorCode.fst.checked" ], "interface_file": false, "source_file": "EverParse3d.InputStream.Buffer.Aux.fst" }
[ { "abbrev": false, "full_module": "LowStar.BufferOps", "short_module": null }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "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": "LowParse.Low.Base", "short_module": "LP" }, { "abbrev": true, "full_module": "EverParse3d.Readable", "short_module": "IR" }, { "abbrev": true, "full_module": "EverParse3d.InputBuffer", "short_module": "IB" }, { "abbrev": false, "full_module": "EverParse3d.InputStream.Buffer", "short_module": null }, { "abbrev": false, "full_module": "EverParse3d.InputStream.Buffer", "short_module": null }, { "abbrev": 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": 0, "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": [ "smt.qi.eager_threshold=100" ], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 8, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
typename_s: Prims.string -> fieldname: Prims.string -> reason: Prims.string -> error_code: FStar.UInt64.t -> context: LowStar.Buffer.pointer EverParse3d.ErrorCode.error_frame -> input: EverParse3d.InputStream.Buffer.Aux.input_buffer -> start_pos: FStar.UInt64.t -> FStar.HyperStack.ST.Stack Prims.unit
FStar.HyperStack.ST.Stack
[]
[]
[ "Prims.string", "FStar.UInt64.t", "LowStar.Buffer.pointer", "EverParse3d.ErrorCode.error_frame", "EverParse3d.InputStream.Buffer.Aux.input_buffer", "LowStar.BufferOps.op_Star_Equals", "LowStar.Buffer.trivial_preorder", "EverParse3d.ErrorCode.Mkerror_frame", "Prims.unit", "Prims.bool", "Prims.op_Negation", "EverParse3d.ErrorCode.__proj__Mkerror_frame__item__filled", "LowStar.BufferOps.op_Bang_Star", "FStar.Monotonic.HyperStack.mem", "LowStar.Monotonic.Buffer.live", "LowStar.Monotonic.Buffer.modifies", "LowStar.Monotonic.Buffer.loc_buffer" ]
[]
false
true
false
false
false
let default_error_handler (typename_s fieldname reason: string) (error_code: U64.t) (context: B.pointer EverParse3d.ErrorCode.error_frame) (input: input_buffer) (start_pos: U64.t) : HST.Stack unit (requires (fun h -> B.live h context)) (ensures (fun h _ h' -> B.modifies (B.loc_buffer context) h h')) =
if not (!*context).EverParse3d.ErrorCode.filled then context *= { EverParse3d.ErrorCode.filled = true; EverParse3d.ErrorCode.start_pos = start_pos; EverParse3d.ErrorCode.typename_s = typename_s; EverParse3d.ErrorCode.fieldname = fieldname; EverParse3d.ErrorCode.reason = reason; EverParse3d.ErrorCode.error_code = error_code }
false
LowParse.BitFields.fst
LowParse.BitFields.bitfield_mask_eq
val bitfield_mask_eq (tot: pos) (lo: nat) (hi: nat{lo <= hi /\ hi <= tot}) : Lemma (0 <= pow2 (hi - lo) - 1 /\ pow2 (hi - lo) - 1 < pow2 tot /\ bitfield_mask tot lo hi == U.shift_left #tot (pow2 (hi - lo) - 1) lo)
val bitfield_mask_eq (tot: pos) (lo: nat) (hi: nat{lo <= hi /\ hi <= tot}) : Lemma (0 <= pow2 (hi - lo) - 1 /\ pow2 (hi - lo) - 1 < pow2 tot /\ bitfield_mask tot lo hi == U.shift_left #tot (pow2 (hi - lo) - 1) lo)
let bitfield_mask_eq (tot: pos) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) : Lemma ( 0 <= pow2 (hi - lo) - 1 /\ pow2 (hi - lo) - 1 < pow2 tot /\ bitfield_mask tot lo hi == U.shift_left #tot (pow2 (hi - lo) - 1) lo ) = M.pow2_le_compat tot (hi - lo); U.shift_left_value_lemma #tot (pow2 (hi - lo) - 1) lo; M.pow2_le_compat tot hi; M.pow2_plus (hi - lo) lo; M.lemma_mult_nat (pow2 (hi - lo) - 1) (pow2 lo); M.lemma_mult_lt' (pow2 lo) (pow2 (hi - lo) - 1) (pow2 (hi - lo)); M.swap_mul (pow2 (hi - lo)) (pow2 lo); M.swap_mul (pow2 (hi - lo) - 1) (pow2 lo); M.modulo_lemma ((pow2 (hi - lo) - 1) * pow2 lo) (pow2 tot)
{ "file_name": "src/lowparse/LowParse.BitFields.fst", "git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
{ "end_col": 60, "end_line": 30, "start_col": 0, "start_line": 15 }
module LowParse.BitFields module U = FStar.UInt module M = LowParse.Math open FStar.Mul inline_for_extraction let bitfield_mask (tot: pos) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) : Tot (U.uint_t tot) = [@inline_let] let _ = M.pow2_le_compat tot hi; M.pow2_plus (hi - lo) lo in normalize_term ((pow2 (hi - lo) - 1) * pow2 lo)
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowParse.Math.fst.checked", "FStar.UInt8.fsti.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.UInt16.fsti.checked", "FStar.UInt.fsti.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Classical.fsti.checked" ], "interface_file": true, "source_file": "LowParse.BitFields.fst" }
[ { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": true, "full_module": "LowParse.Math", "short_module": "M" }, { "abbrev": true, "full_module": "FStar.UInt", "short_module": "U" }, { "abbrev": true, "full_module": "FStar.UInt", "short_module": "U" }, { "abbrev": false, "full_module": "LowParse", "short_module": null }, { "abbrev": false, "full_module": "LowParse", "short_module": null }, { "abbrev": 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
tot: Prims.pos -> lo: Prims.nat -> hi: Prims.nat{lo <= hi /\ hi <= tot} -> FStar.Pervasives.Lemma (ensures 0 <= Prims.pow2 (hi - lo) - 1 /\ Prims.pow2 (hi - lo) - 1 < Prims.pow2 tot /\ LowParse.BitFields.bitfield_mask tot lo hi == FStar.UInt.shift_left (Prims.pow2 (hi - lo) - 1) lo)
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "Prims.pos", "Prims.nat", "Prims.l_and", "Prims.b2t", "Prims.op_LessThanOrEqual", "FStar.Math.Lemmas.modulo_lemma", "FStar.Mul.op_Star", "Prims.op_Subtraction", "Prims.pow2", "Prims.unit", "FStar.Math.Lemmas.swap_mul", "LowParse.Math.lemma_mult_lt'", "LowParse.Math.lemma_mult_nat", "FStar.Math.Lemmas.pow2_plus", "FStar.Math.Lemmas.pow2_le_compat", "FStar.UInt.shift_left_value_lemma", "Prims.l_True", "Prims.squash", "Prims.op_LessThan", "Prims.eq2", "FStar.UInt.uint_t", "LowParse.BitFields.bitfield_mask", "FStar.UInt.shift_left", "Prims.Nil", "FStar.Pervasives.pattern" ]
[]
true
false
true
false
false
let bitfield_mask_eq (tot: pos) (lo: nat) (hi: nat{lo <= hi /\ hi <= tot}) : Lemma (0 <= pow2 (hi - lo) - 1 /\ pow2 (hi - lo) - 1 < pow2 tot /\ bitfield_mask tot lo hi == U.shift_left #tot (pow2 (hi - lo) - 1) lo) =
M.pow2_le_compat tot (hi - lo); U.shift_left_value_lemma #tot (pow2 (hi - lo) - 1) lo; M.pow2_le_compat tot hi; M.pow2_plus (hi - lo) lo; M.lemma_mult_nat (pow2 (hi - lo) - 1) (pow2 lo); M.lemma_mult_lt' (pow2 lo) (pow2 (hi - lo) - 1) (pow2 (hi - lo)); M.swap_mul (pow2 (hi - lo)) (pow2 lo); M.swap_mul (pow2 (hi - lo) - 1) (pow2 lo); M.modulo_lemma ((pow2 (hi - lo) - 1) * pow2 lo) (pow2 tot)
false
LowParse.Low.BCVLI.fst
LowParse.Low.BCVLI.validate_bounded_bcvli'
val validate_bounded_bcvli' (min32: U32.t) (max32: U32.t{U32.v min32 <= U32.v max32}) : Tot (validator (parse_bounded_bcvli (U32.v min32) (U32.v max32)))
val validate_bounded_bcvli' (min32: U32.t) (max32: U32.t{U32.v min32 <= U32.v max32}) : Tot (validator (parse_bounded_bcvli (U32.v min32) (U32.v max32)))
let validate_bounded_bcvli' (min32: U32.t) (max32: U32.t { U32.v min32 <= U32.v max32 }) : Tot (validator (parse_bounded_bcvli (U32.v min32) (U32.v max32))) = fun #rrel #rel input pos -> let h = HST.get () in [@inline_let] let _ = valid_facts (parse_bounded_bcvli (U32.v min32) (U32.v max32)) h input (uint64_to_uint32 pos); parse_bounded_bcvli_eq (U32.v min32) (U32.v max32) (bytes_of_slice_from h input (uint64_to_uint32 pos)); parse_bcvli_eq (bytes_of_slice_from h input (uint64_to_uint32 pos)); valid_facts (parse_bounded_integer_le 1) h input (uint64_to_uint32 pos) in let pos1 = validate_total_constant_size (parse_bounded_integer_le 1) 1uL () input pos in if is_error pos1 then pos1 else [@inline_let] let _ = valid_facts (parse_bounded_integer_le 2) h input (uint64_to_uint32 pos1); valid_facts (parse_bounded_integer_le 4) h input (uint64_to_uint32 pos1) in let r = read_bounded_integer_le_1 input (uint64_to_uint32 pos) in if r `U32.lt` 253ul && min32 `U32.lte` r && r `U32.lte` max32 then pos1 else if max32 `U32.lt` 253ul then validator_error_generic else if r = 253ul then if 65536ul `U32.lte` min32 then validator_error_generic else let pos2 = validate_total_constant_size (parse_bounded_integer_le 2) 2uL () input pos1 in if is_error pos2 then pos2 else (* because of the non-malleability constraint, I need to actually read the value and check whether it is not a lower integer *) let r = read_bounded_integer_le_2 input (uint64_to_uint32 pos1) in if r `U32.lt` 253ul || r `U32.lt` min32 || max32 `U32.lt` r then validator_error_generic else pos2 else if max32 `U32.lt` 65536ul then validator_error_generic else if r = 254ul then let pos2 = validate_total_constant_size (parse_bounded_integer_le 4) 4uL () input pos1 in if is_error pos2 then pos2 else (* because of the non-malleability constraint, I need to actually read the value and check whether it is not a lower integer *) let r = read_bounded_integer_le_4 input (uint64_to_uint32 pos1) in if r `U32.lt` 65536ul || r `U32.lt` min32 || max32 `U32.lt` r then validator_error_generic else pos2 else validator_error_generic
{ "file_name": "src/lowparse/LowParse.Low.BCVLI.fst", "git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
{ "end_col": 32, "end_line": 231, "start_col": 0, "start_line": 179 }
module LowParse.Low.BCVLI include LowParse.Spec.BCVLI include LowParse.Low.Combinators include LowParse.Low.BoundedInt module B = LowStar.Buffer module HST = FStar.HyperStack.ST module Cast = FStar.Int.Cast module U32 = FStar.UInt32 module U64 = FStar.UInt64 #reset-options "--z3cliopt smt.arith.nl=false --max_fuel 0" #push-options "--z3rlimit 16" let validate_bcvli : validator parse_bcvli = fun #rrel #rel input pos -> let h = HST.get () in [@inline_let] let _ = valid_facts parse_bcvli h input (uint64_to_uint32 pos); parse_bcvli_eq (bytes_of_slice_from h input (uint64_to_uint32 pos)); valid_facts (parse_bounded_integer_le 1) h input (uint64_to_uint32 pos) in let pos1 = validate_total_constant_size (parse_bounded_integer_le 1) 1uL () input pos in if is_error pos1 then pos1 else [@inline_let] let _ = valid_facts (parse_bounded_integer_le 2) h input (uint64_to_uint32 pos1); valid_facts (parse_bounded_integer_le 4) h input (uint64_to_uint32 pos1) in let r = read_bounded_integer_le_1 input (uint64_to_uint32 pos) in if r `U32.lt` 253ul then pos1 else if r = 253ul then let pos2 = validate_total_constant_size (parse_bounded_integer_le 2) 2uL () input pos1 in if is_error pos2 then pos2 else (* because of the non-malleability constraint, I need to actually read the value and check whether it is not a lower integer *) let r = read_bounded_integer_le_2 input (uint64_to_uint32 pos1) in if r `U32.lt` 253ul then validator_error_generic else pos2 else if r = 254ul then let pos2 = validate_total_constant_size (parse_bounded_integer_le 4) 4uL () input pos1 in if is_error pos2 then pos2 else (* because of the non-malleability constraint, I need to actually read the value and check whether it is not a lower integer *) let r = read_bounded_integer_le_4 input (uint64_to_uint32 pos1) in if r `U32.lt` 65536ul then validator_error_generic else pos2 else validator_error_generic let jump_bcvli : jumper parse_bcvli = fun #rrel #rel input pos -> let h = HST.get () in [@inline_let] let _ = valid_facts parse_bcvli h input pos; parse_bcvli_eq (bytes_of_slice_from h input pos); valid_facts (parse_bounded_integer_le 1) h input pos in let pos1 = jump_constant_size (parse_bounded_integer_le 1) 1ul () input pos in [@inline_let] let _ = valid_facts (parse_bounded_integer_le 2) h input pos1; valid_facts (parse_bounded_integer_le 4) h input pos1 in let r = read_bounded_integer_le_1 input pos in if r `U32.lt` 253ul then pos1 else if r = 253ul then jump_constant_size (parse_bounded_integer_le 2) 2ul () input pos1 else jump_constant_size (parse_bounded_integer_le 4) 4ul () input pos1 let read_bcvli : leaf_reader parse_bcvli = fun #rrel #rel input pos -> let h = HST.get () in [@inline_let] let _ = valid_facts parse_bcvli h input pos; parse_bcvli_eq (bytes_of_slice_from h input pos); valid_facts (parse_bounded_integer_le 1) h input pos in let r = read_bounded_integer_le_1 input pos in if r `U32.lt` 253ul then (r <: U32.t) else let pos1 = jump_constant_size (parse_bounded_integer_le 1) 1ul () input pos in [@inline_let] let _ = valid_facts (parse_bounded_integer_le 2) h input pos1; valid_facts (parse_bounded_integer_le 4) h input pos1 in if r = 253ul then read_bounded_integer_le_2 input pos1 <: U32.t else read_bounded_integer_le_4 input pos1 <: U32.t #pop-options module U8 = FStar.UInt8 #push-options "--z3rlimit 32" inline_for_extraction let serialize32_bcvli' (x: U32.t) (#rrel #rel: _) (b: B.mbuffer U8.t rrel rel) (pos: U32.t) : HST.Stack U32.t (requires (fun h -> let len = Seq.length (serialize serialize_bcvli x) in B.live h b /\ U32.v pos + len <= B.length b /\ writable b (U32.v pos) (U32.v pos + len) h )) (ensures (fun h len h' -> Seq.length (serialize serialize_bcvli x) == U32.v len /\ ( B.modifies (B.loc_buffer_from_to b pos (pos `U32.add` len)) h h' /\ B.live h b /\ Seq.slice (B.as_seq h' b) (U32.v pos) (U32.v pos + U32.v len) `Seq.equal` serialize serialize_bcvli x ))) = // [@inline_let] let _ = serialize_bcvli_eq x ; // in let c : bounded_integer 1 = if x `U32.lt` 253ul then x else if x `U32.lt` 65536ul then 253ul else 254ul in [@inline_let] let pos' = Ghost.hide (U32.v pos + Seq.length (serialize serialize_bcvli x)) in let h = HST.get () in [@inline_let] let _ = writable_weaken b (U32.v pos) (Ghost.reveal pos') h (U32.v pos) (U32.v pos + 1) in let len1 = serialize32_bounded_integer_le_1 c b pos in let h1 = HST.get () in [@inline_let] let _ = writable_modifies b (U32.v pos) (Ghost.reveal pos') h B.loc_none h1 in if c `U32.lt` 253ul then begin len1 end else if c = 253ul then begin [@inline_let] let _ = assert (U32.v x < 65536) in [@inline_let] let _ = writable_weaken b (U32.v pos) (Ghost.reveal pos') h1 (U32.v pos + U32.v len1) ((U32.v pos + U32.v len1) + 2) in let len2 = serialize32_bounded_integer_le_2 x b (pos `U32.add` len1) in let h' = HST.get () in [@inline_let] let len = len1 `U32.add` len2 in B.modifies_buffer_from_to_elim b pos (pos `U32.add` len1) (B.loc_buffer_from_to b (pos `U32.add` len1) (pos `U32.add` len)) h1 h'; len end else begin [@inline_let] let _ = writable_weaken b (U32.v pos) (Ghost.reveal pos') h1 (U32.v pos + U32.v len1) ((U32.v pos + U32.v len1) + 4) in let len2 = serialize32_bounded_integer_le_4 x b (pos `U32.add` len1) in let h' = HST.get () in [@inline_let] let len = len1 `U32.add` len2 in B.modifies_buffer_from_to_elim b pos (pos `U32.add` len1) (B.loc_buffer_from_to b (pos `U32.add` len1) (pos `U32.add` len)) h1 h'; len end inline_for_extraction let serialize32_bcvli : serializer32 serialize_bcvli = fun (x: U32.t) #rrel #rel b pos -> serialize32_bcvli' x b pos let write_bcvli : leaf_writer_strong serialize_bcvli = leaf_writer_strong_of_serializer32 serialize32_bcvli ()
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowStar.Buffer.fst.checked", "LowParse.Spec.BCVLI.fsti.checked", "LowParse.Low.Combinators.fsti.checked", "LowParse.Low.BoundedInt.fsti.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.Ghost.fsti.checked" ], "interface_file": false, "source_file": "LowParse.Low.BCVLI.fst" }
[ { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": true, "full_module": "FStar.Int.Cast", "short_module": "Cast" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": false, "full_module": "LowParse.Low.BoundedInt", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low.Combinators", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec.BCVLI", "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": 0, "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": [ "smt.arith.nl=false" ], "z3refresh": false, "z3rlimit": 32, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
min32: FStar.UInt32.t -> max32: FStar.UInt32.t{FStar.UInt32.v min32 <= FStar.UInt32.v max32} -> LowParse.Low.Base.validator (LowParse.Spec.BCVLI.parse_bounded_bcvli (FStar.UInt32.v min32) (FStar.UInt32.v max32))
Prims.Tot
[ "total" ]
[]
[ "FStar.UInt32.t", "Prims.b2t", "Prims.op_LessThanOrEqual", "FStar.UInt32.v", "LowParse.Slice.srel", "LowParse.Bytes.byte", "LowParse.Slice.slice", "FStar.UInt64.t", "LowParse.Low.ErrorCode.is_error", "Prims.bool", "Prims.op_AmpAmp", "FStar.UInt32.lt", "FStar.UInt32.__uint_to_t", "FStar.UInt32.lte", "LowParse.Low.ErrorCode.validator_error_generic", "Prims.op_Equality", "Prims.op_BarBar", "LowParse.Spec.BoundedInt.bounded_integer", "LowParse.Low.BoundedInt.read_bounded_integer_le_2", "LowParse.Low.ErrorCode.uint64_to_uint32", "LowParse.Low.Base.validate_total_constant_size", "LowParse.Spec.BoundedInt.parse_bounded_integer_kind", "LowParse.Spec.BoundedInt.parse_bounded_integer_le", "FStar.UInt64.__uint_to_t", "LowParse.Low.BoundedInt.read_bounded_integer_le_4", "LowParse.Low.BoundedInt.read_bounded_integer_le_1", "Prims.unit", "LowParse.Low.Base.Spec.valid_facts", "LowParse.Spec.BCVLI.parse_bcvli_eq", "LowParse.Slice.bytes_of_slice_from", "LowParse.Spec.BCVLI.parse_bounded_bcvli_eq", "LowParse.Spec.BCVLI.parse_bounded_bcvli_kind", "LowParse.Spec.BoundedInt.bounded_int32", "LowParse.Spec.BCVLI.parse_bounded_bcvli", "FStar.Monotonic.HyperStack.mem", "FStar.HyperStack.ST.get", "LowParse.Low.Base.validator" ]
[]
false
false
false
false
false
let validate_bounded_bcvli' (min32: U32.t) (max32: U32.t{U32.v min32 <= U32.v max32}) : Tot (validator (parse_bounded_bcvli (U32.v min32) (U32.v max32))) =
fun #rrel #rel input pos -> let h = HST.get () in [@@ inline_let ]let _ = valid_facts (parse_bounded_bcvli (U32.v min32) (U32.v max32)) h input (uint64_to_uint32 pos); parse_bounded_bcvli_eq (U32.v min32) (U32.v max32) (bytes_of_slice_from h input (uint64_to_uint32 pos)); parse_bcvli_eq (bytes_of_slice_from h input (uint64_to_uint32 pos)); valid_facts (parse_bounded_integer_le 1) h input (uint64_to_uint32 pos) in let pos1 = validate_total_constant_size (parse_bounded_integer_le 1) 1uL () input pos in if is_error pos1 then pos1 else [@@ inline_let ]let _ = valid_facts (parse_bounded_integer_le 2) h input (uint64_to_uint32 pos1); valid_facts (parse_bounded_integer_le 4) h input (uint64_to_uint32 pos1) in let r = read_bounded_integer_le_1 input (uint64_to_uint32 pos) in if r `U32.lt` 253ul && min32 `U32.lte` r && r `U32.lte` max32 then pos1 else if max32 `U32.lt` 253ul then validator_error_generic else if r = 253ul then if 65536ul `U32.lte` min32 then validator_error_generic else let pos2 = validate_total_constant_size (parse_bounded_integer_le 2) 2uL () input pos1 in if is_error pos2 then pos2 else let r = read_bounded_integer_le_2 input (uint64_to_uint32 pos1) in if r `U32.lt` 253ul || r `U32.lt` min32 || max32 `U32.lt` r then validator_error_generic else pos2 else if max32 `U32.lt` 65536ul then validator_error_generic else if r = 254ul then let pos2 = validate_total_constant_size (parse_bounded_integer_le 4) 4uL () input pos1 in if is_error pos2 then pos2 else let r = read_bounded_integer_le_4 input (uint64_to_uint32 pos1) in if r `U32.lt` 65536ul || r `U32.lt` min32 || max32 `U32.lt` r then validator_error_generic else pos2 else validator_error_generic
false
MerkleTree.Low.Datastructures.fst
MerkleTree.Low.Datastructures.hash_vv_rv_inv_disjoint
val hash_vv_rv_inv_disjoint: #hsz:hash_size_t -> h:HS.mem -> hvv:hash_vv hsz -> i:uint32_t -> j:uint32_t -> drid:HH.rid -> Lemma (requires (RV.rv_inv h hvv /\ i < V.size_of hvv /\ j < V.size_of (V.get h hvv i) /\ HH.disjoint (Rgl?.region_of (hvvreg hsz) hvv) drid)) (ensures (HH.disjoint (Rgl?.region_of (hreg hsz) (V.get h (V.get h hvv i) j)) drid))
val hash_vv_rv_inv_disjoint: #hsz:hash_size_t -> h:HS.mem -> hvv:hash_vv hsz -> i:uint32_t -> j:uint32_t -> drid:HH.rid -> Lemma (requires (RV.rv_inv h hvv /\ i < V.size_of hvv /\ j < V.size_of (V.get h hvv i) /\ HH.disjoint (Rgl?.region_of (hvvreg hsz) hvv) drid)) (ensures (HH.disjoint (Rgl?.region_of (hreg hsz) (V.get h (V.get h hvv i) j)) drid))
let hash_vv_rv_inv_disjoint #hsz h hvv i j drid = assert (HH.disjoint (Rgl?.region_of (hvreg hsz) (V.get h hvv i)) drid); assert (RV.rv_inv h (V.get h hvv i)); assert (HH.disjoint (Rgl?.region_of (hreg hsz) (V.get h (V.get h hvv i) j)) drid)
{ "file_name": "src/MerkleTree.Low.Datastructures.fst", "git_rev": "7d7bdc20f2033171e279c176b26e84f9069d23c6", "git_url": "https://github.com/hacl-star/merkle-tree.git", "project_name": "merkle-tree" }
{ "end_col": 83, "end_line": 354, "start_col": 0, "start_line": 351 }
module MerkleTree.Low.Datastructures open FStar.All open FStar.Integers open FStar.Mul open LowStar.Buffer open LowStar.BufferOps open LowStar.Vector open LowStar.Regional open LowStar.RVector open LowStar.Regional.Instances module HS = FStar.HyperStack module HST = FStar.HyperStack.ST module MHS = FStar.Monotonic.HyperStack module HH = FStar.Monotonic.HyperHeap module B = LowStar.Buffer module CB = LowStar.ConstBuffer module V = LowStar.Vector module RV = LowStar.RVector module RVI = LowStar.Regional.Instances module S = FStar.Seq module EHS = EverCrypt.Hash module U32 = FStar.UInt32 module MTH = MerkleTree.New.High open EverCrypt.Helpers open Lib.IntTypes #set-options "--z3rlimit 10 --initial_fuel 0 --max_fuel 0 --initial_ifuel 0 --max_ifuel 0" type hash_size_t = n:uint32_t{n > 0ul} type hash (#hsz:hash_size_t) = b:B.buffer uint8 { B.len b = hsz \/ B.g_is_null b } // We cannot use `Low.RVector.Instances`, where we have some general // typeclass instances of `regional`, e.g., if `rg:regional a` then // `regional (rvector rg)`. In FStar we can use this, but KaRaMeL currently // cannot deal with this and gives a number of errors. // So we temporarily instantiate some `regional`s manually below, which is // extractable to C by KaRaMeL. /// Some instantiations of `regional` used in Merkle tree /// 1. `hash` is regional private noextract val hash_region_of: #hsz:hash_size_t -> v:hash #hsz -> GTot HH.rid let hash_region_of #_ v = B.frameOf v private inline_for_extraction val hash_dummy: #hsz:Ghost.erased hash_size_t -> Tot (hash #hsz) let hash_dummy #_ = B.null private noextract val hash_r_inv: #hsz:hash_size_t -> h:HS.mem -> v:hash #hsz -> GTot Type0 let hash_r_inv #hsz h v = B.live h v /\ B.freeable v /\ B.len v = hsz private noextract val hash_r_inv_reg: #hsz:hash_size_t -> h:HS.mem -> v:hash -> Lemma (requires hash_r_inv h v) (ensures MHS.live_region h (hash_region_of #hsz v)) let hash_r_inv_reg #_ h v = () private noextract val hash_repr (#hsz:hash_size_t): Type0 let hash_repr #hsz = MTH.hash #(U32.v hsz) private noextract val hash_r_repr: #hsz:hash_size_t -> h:HS.mem -> v:hash{hash_r_inv #hsz h v} -> GTot (hash_repr #hsz) let hash_r_repr #_ h v = B.as_seq h v private noextract val hash_r_sep: #hsz:hash_size_t -> v:hash #hsz -> p:loc -> h0:HS.mem -> h1:HS.mem -> Lemma (requires hash_r_inv h0 v /\ loc_disjoint (loc_all_regions_from false (hash_region_of v)) p /\ modifies p h0 h1) (ensures hash_r_inv h1 v /\ hash_r_repr h0 v == hash_r_repr h1 v) let hash_r_sep #_ v p h0 h1 = assert (loc_includes (loc_all_regions_from false (hash_region_of v)) (loc_buffer v)); B.modifies_buffer_elim v p h0 h1 private noextract val hash_irepr: #hsz:hash_size_t -> Ghost.erased (hash_repr #hsz) let hash_irepr #hsz = Ghost.hide (S.create (U32.v hsz) (u8 0)) private noextract val hash_r_alloc_p: #hsz:hash_size_t -> v:hash #hsz -> GTot Type0 let hash_r_alloc_p #_ v = True val hash_r_alloc: #hsz':Ghost.erased hash_size_t -> hsz:hash_size_t { hsz == Ghost.reveal hsz' } -> r:HST.erid -> HST.ST (hash #hsz) (requires (fun h0 -> true)) (ensures (fun h0 v h1 -> Set.subset (Map.domain (MHS.get_hmap h0)) (Map.domain (MHS.get_hmap h1)) /\ modifies loc_none h0 h1 /\ hash_r_alloc_p #hsz v /\ hash_r_inv h1 v /\ hash_region_of v = r /\ hash_r_repr h1 v == Ghost.reveal hash_irepr /\ B.fresh_loc (B.loc_buffer v) h0 h1)) let hash_r_alloc #_ s r = B.malloc r (u8 0) s val hash_r_free: #hsz':Ghost.erased hash_size_t -> hsz:hash_size_t { hsz == Ghost.reveal hsz' } -> v:hash #hsz' -> HST.ST unit (requires fun h0 -> hash_r_inv h0 v) (ensures fun h0 _ h1 -> modifies (loc_all_regions_from false (hash_region_of v)) h0 h1) let hash_r_free #_ _ v = B.free v noextract inline_for_extraction val hreg (hsz:hash_size_t): regional (hash_size_t) (hash #hsz) let hreg hsz = Rgl #(hash_size_t) #(hash #hsz) hsz (hash_region_of #hsz) (B.loc_buffer) (hash_dummy #hsz) (hash_r_inv #hsz) (hash_r_inv_reg #hsz) (hash_repr #hsz) (hash_r_repr #hsz) (hash_r_sep #hsz) (hash_irepr #hsz) (hash_r_alloc_p #hsz) (hash_r_alloc #hsz) (hash_r_free #hsz) private val hash_copy: #s':Ghost.erased hash_size_t -> s:hash_size_t { s == Ghost.reveal s' } -> src:hash #s -> dst:hash #s -> HST.ST unit (requires fun h0 -> hash_r_inv h0 src /\ hash_r_inv h0 dst /\ HH.disjoint (hash_region_of src) (hash_region_of dst)) (ensures fun h0 _ h1 -> modifies (loc_all_regions_from false (hash_region_of dst)) h0 h1 /\ hash_r_inv h1 dst /\ hash_r_repr h1 dst == hash_r_repr h0 src) let hash_copy #_ s src dst = B.blit src 0ul dst 0ul s /// JP: so much stuff happening here. First, single-constructor, single-argument /// elimination takes places and Cpy becomes completely eliminated, in favor of /// just being a type alias for the underlying function. So now, we have a /// function that returns a function pointer. /// /// Next, one might think that the hsz argument is going to be eliminated. It's /// not, because there's a hidden implicit argument to Cpy which is (hreg hsz), /// meaning that hsz is used at run-time even though Cpy is only using this /// argument ghostly. This would be have to be fixed. /// /// Finally, if the inline_for_extraction is removed, there seems to be a /// karamel bug that inserts a void*0. To be fixed. inline_for_extraction val hcpy: hsz:hash_size_t -> copyable #hash_size_t (hash #hsz) (hreg hsz) let hcpy hsz = Cpy (hash_copy #hsz) type hash_vec (#hsz:hash_size_t) = RV.rvector (hreg hsz) /// 2. `rvector hash` is regional type rhst (hsz:hash_size_t) = regional hash_size_t (hash #hsz) private noextract val hash_vec_region_of: #hsz:hash_size_t -> v:hash_vec #hsz -> GTot HH.rid let hash_vec_region_of #_ v = V.frameOf v private inline_for_extraction val hash_vec_dummy: (#hsz:Ghost.erased hash_size_t) -> hash_vec #hsz let hash_vec_dummy #_ = V.alloc_empty (hash #_) noextract val hash_vec_r_inv: #hsz:hash_size_t -> h:HS.mem -> v:hash_vec #hsz -> GTot Type0 let hash_vec_r_inv #hsz h v = RV.rv_inv h v noextract val hash_vec_r_inv_reg: #hsz:hash_size_t -> h:HS.mem -> v:hash_vec #hsz -> Lemma (requires (hash_vec_r_inv h v)) (ensures (MHS.live_region h (hash_vec_region_of v))) let hash_vec_r_inv_reg #_ h v = () private noextract val hash_vec_repr: #hsz:hash_size_t -> Type0 let hash_vec_repr #hsz = MTH.hashes #(U32.v hsz) noextract val hash_vec_r_repr: #hsz:hash_size_t -> h:HS.mem -> v:hash_vec #hsz {hash_vec_r_inv h v} -> GTot (hash_vec_repr #hsz) let hash_vec_r_repr #_ h v = RV.as_seq h v noextract val hash_vec_r_sep: #hsz:hash_size_t -> v:hash_vec #hsz -> p:loc -> h0:HS.mem -> h1:HS.mem -> Lemma (requires (hash_vec_r_inv h0 v /\ loc_disjoint (loc_all_regions_from false (hash_vec_region_of v)) p /\ modifies p h0 h1)) (ensures (hash_vec_r_inv h1 v /\ hash_vec_r_repr h0 v == hash_vec_r_repr h1 v)) let hash_vec_r_sep #_ v p h0 h1 = RV.rv_inv_preserved v p h0 h1; RV.as_seq_preserved v p h0 h1 noextract val hash_vec_irepr: #hsz:hash_size_t -> Ghost.erased (hash_vec_repr #hsz) let hash_vec_irepr #_ = Ghost.hide S.empty noextract val hash_vec_r_alloc_p: #hsz:hash_size_t -> v:hash_vec #hsz -> GTot Type0 let hash_vec_r_alloc_p #_ v = V.size_of v = 0ul #push-options "--initial_fuel 1 --max_fuel 1" val hash_vec_r_alloc: #hsz':Ghost.erased hash_size_t -> hsz:hash_size_t { hsz == Ghost.reveal hsz' } -> r:HST.erid -> HST.ST (hash_vec #hsz) (requires (fun h0 -> true)) (ensures (fun h0 v h1 -> Set.subset (Map.domain (MHS.get_hmap h0)) (Map.domain (MHS.get_hmap h1)) /\ modifies loc_none h0 h1 /\ hash_vec_r_alloc_p v /\ hash_vec_r_inv h1 v /\ hash_vec_region_of v = r /\ hash_vec_r_repr h1 v == Ghost.reveal hash_vec_irepr /\ B.fresh_loc (V.loc_vector v) h0 h1)) let hash_vec_r_alloc #_ hsz r = let nrid = HST.new_region r in // Note: here we are not creating a generic parameterized regional, we are // creating a specialized regional vector of hashes, so we don't need to go // through a run-time indirection to figure out what the dummy default element // is; we know it's the one for hashes V.alloc_reserve 1ul (hash_dummy #hsz) r #pop-options val hash_vec_r_free: #hsz':Ghost.erased hash_size_t -> hsz:hash_size_t { hsz == Ghost.reveal hsz' } -> v:hash_vec #hsz -> HST.ST unit (requires (fun h0 -> hash_vec_r_inv h0 v)) (ensures (fun h0 _ h1 -> modifies (loc_all_regions_from false (hash_vec_region_of #hsz v)) h0 h1)) let hash_vec_r_free #_ hsz v = RV.free v /// This is nice because the only piece of state that we are keeping is one /// word, the hash size, since we are implementing a specialized instance of /// RVector over hashes of a known length. We could also, for genericity, make /// this a mere application of RVector over hreg, which would be less /// implementation effort, at the expense of a bigger run-time cost since there /// would be extra space in the struct (which is passed by value!) and also a /// run-time indirection to do the lookup of the type class instance for the /// elements of the rvector. noextract inline_for_extraction val hvreg (hsz:hash_size_t): regional hash_size_t (hash_vec #hsz) let hvreg hsz = Rgl hsz (hash_vec_region_of #hsz) V.loc_vector (hash_vec_dummy #hsz) (hash_vec_r_inv #hsz) (hash_vec_r_inv_reg #hsz) (hash_vec_repr #hsz) (hash_vec_r_repr #hsz) (hash_vec_r_sep #hsz) (hash_vec_irepr #hsz) (hash_vec_r_alloc_p #hsz) (hash_vec_r_alloc #hsz) (hash_vec_r_free #hsz) /// 3. A vector of hash vectors is also regional type hash_vv (hsz:hash_size_t) = RV.rvector (hvreg hsz) noextract inline_for_extraction val hvvreg (hsz:hash_size_t): regional (regional hash_size_t (hash_vec #hsz)) (hash_vv hsz) let hvvreg hsz = RVI.vector_regional (hvreg hsz) val hash_vec_rv_inv_r_inv: #hsz:hash_size_t -> h:HS.mem -> hv:hash_vec #hsz -> i:uint32_t{i < V.size_of hv} -> Lemma (requires RV.rv_inv h hv) (ensures Rgl?.r_inv (hreg hsz) h (V.get h hv i)) let hash_vec_rv_inv_r_inv #_ h hv i = () val hash_vv_rv_inv_r_inv: #hsz:hash_size_t -> h:HS.mem -> hvv:hash_vv hsz -> i:uint32_t -> j:uint32_t -> Lemma (requires RV.rv_inv h hvv /\ i < V.size_of hvv /\ j < V.size_of (V.get h hvv i)) (ensures Rgl?.r_inv (hvreg hsz) h (V.get h hvv i) /\ Rgl?.r_inv (hreg hsz) h (V.get h (V.get h hvv i) j)) let hash_vv_rv_inv_r_inv #_ h hvv i j = () val hash_vv_rv_inv_disjoint: #hsz:hash_size_t -> h:HS.mem -> hvv:hash_vv hsz -> i:uint32_t -> j:uint32_t -> drid:HH.rid -> Lemma (requires (RV.rv_inv h hvv /\ i < V.size_of hvv /\ j < V.size_of (V.get h hvv i) /\ HH.disjoint (Rgl?.region_of (hvvreg hsz) hvv) drid))
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "MerkleTree.New.High.fst.checked", "LowStar.Vector.fst.checked", "LowStar.RVector.fst.checked", "LowStar.Regional.Instances.fst.checked", "LowStar.Regional.fst.checked", "LowStar.ConstBuffer.fsti.checked", "LowStar.BufferOps.fst.checked", "LowStar.Buffer.fst.checked", "Lib.IntTypes.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Set.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Monotonic.HyperStack.fsti.checked", "FStar.Monotonic.HyperHeap.fsti.checked", "FStar.Map.fsti.checked", "FStar.Integers.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked", "FStar.All.fst.checked", "EverCrypt.Helpers.fsti.checked", "EverCrypt.Hash.fsti.checked" ], "interface_file": false, "source_file": "MerkleTree.Low.Datastructures.fst" }
[ { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "EverCrypt.Helpers", "short_module": null }, { "abbrev": true, "full_module": "MerkleTree.New.High", "short_module": "MTH" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": true, "full_module": "EverCrypt.Hash", "short_module": "EHS" }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "S" }, { "abbrev": true, "full_module": "LowStar.Regional.Instances", "short_module": "RVI" }, { "abbrev": true, "full_module": "LowStar.RVector", "short_module": "RV" }, { "abbrev": true, "full_module": "LowStar.Vector", "short_module": "V" }, { "abbrev": true, "full_module": "LowStar.ConstBuffer", "short_module": "CB" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.Monotonic.HyperHeap", "short_module": "HH" }, { "abbrev": true, "full_module": "FStar.Monotonic.HyperStack", "short_module": "MHS" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": false, "full_module": "LowStar.Regional.Instances", "short_module": null }, { "abbrev": false, "full_module": "LowStar.RVector", "short_module": null }, { "abbrev": false, "full_module": "LowStar.Regional", "short_module": null }, { "abbrev": false, "full_module": "LowStar.Vector", "short_module": null }, { "abbrev": false, "full_module": "LowStar.BufferOps", "short_module": null }, { "abbrev": false, "full_module": "LowStar.Buffer", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.Integers", "short_module": null }, { "abbrev": false, "full_module": "FStar.All", "short_module": null }, { "abbrev": false, "full_module": "MerkleTree.Low", "short_module": null }, { "abbrev": false, "full_module": "MerkleTree.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": 0, "initial_ifuel": 0, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 10, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
h: FStar.Monotonic.HyperStack.mem -> hvv: MerkleTree.Low.Datastructures.hash_vv hsz -> i: EverCrypt.Helpers.uint32_t -> j: EverCrypt.Helpers.uint32_t -> drid: FStar.Monotonic.HyperHeap.rid -> FStar.Pervasives.Lemma (requires LowStar.RVector.rv_inv h hvv /\ i < LowStar.Vector.size_of hvv /\ j < LowStar.Vector.size_of (LowStar.Vector.get h hvv i) /\ FStar.Monotonic.HyperHeap.disjoint (Rgl?.region_of (MerkleTree.Low.Datastructures.hvvreg hsz ) hvv) drid) (ensures FStar.Monotonic.HyperHeap.disjoint (Rgl?.region_of (MerkleTree.Low.Datastructures.hreg hsz) (LowStar.Vector.get h (LowStar.Vector.get h hvv i) j)) drid)
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "MerkleTree.Low.Datastructures.hash_size_t", "FStar.Monotonic.HyperStack.mem", "MerkleTree.Low.Datastructures.hash_vv", "EverCrypt.Helpers.uint32_t", "FStar.Monotonic.HyperHeap.rid", "Prims._assert", "Prims.b2t", "FStar.Monotonic.HyperHeap.disjoint", "LowStar.Regional.__proj__Rgl__item__region_of", "MerkleTree.Low.Datastructures.hash", "MerkleTree.Low.Datastructures.hreg", "LowStar.Vector.get", "MerkleTree.Low.Datastructures.hash_vec", "Prims.unit", "LowStar.RVector.rv_inv", "MerkleTree.Low.Datastructures.hvreg" ]
[]
true
false
true
false
false
let hash_vv_rv_inv_disjoint #hsz h hvv i j drid =
assert (HH.disjoint (Rgl?.region_of (hvreg hsz) (V.get h hvv i)) drid); assert (RV.rv_inv h (V.get h hvv i)); assert (HH.disjoint (Rgl?.region_of (hreg hsz) (V.get h (V.get h hvv i) j)) drid)
false