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.New.High.Correct.Base.fst
MerkleTree.New.High.Correct.Base.mt_hashes_lth_inv_equiv
val mt_hashes_lth_inv_equiv: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> lv:nat{lv < 32} -> j:nat{j < pow2 (32 - lv)} -> fhs1:hashess{S.length fhs1 = 32} -> fhs2:hashess{S.length fhs2 = 32} -> Lemma (requires mt_hashes_lth_inv lv j fhs1 /\ S.equal (S.slice fhs1 lv 32) (S.slice fhs2 lv 32)) (ensures mt_hashes_lth_inv #hsz lv j fhs2) (decreases (32 - lv))
val mt_hashes_lth_inv_equiv: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> lv:nat{lv < 32} -> j:nat{j < pow2 (32 - lv)} -> fhs1:hashess{S.length fhs1 = 32} -> fhs2:hashess{S.length fhs2 = 32} -> Lemma (requires mt_hashes_lth_inv lv j fhs1 /\ S.equal (S.slice fhs1 lv 32) (S.slice fhs2 lv 32)) (ensures mt_hashes_lth_inv #hsz lv j fhs2) (decreases (32 - lv))
let rec mt_hashes_lth_inv_equiv #hsz #f lv j fhs1 fhs2 = if lv = 31 then () else (assert (S.index fhs1 lv == S.index fhs2 lv); mt_hashes_lth_inv_equiv #_ #f (lv + 1) (j / 2) fhs1 fhs2)
{ "file_name": "src/MerkleTree.New.High.Correct.Base.fst", "git_rev": "7d7bdc20f2033171e279c176b26e84f9069d23c6", "git_url": "https://github.com/hacl-star/merkle-tree.git", "project_name": "merkle-tree" }
{ "end_col": 64, "end_line": 127, "start_col": 0, "start_line": 124 }
module MerkleTree.New.High.Correct.Base open FStar.Classical open FStar.Ghost open FStar.Seq module S = FStar.Seq module MTS = MerkleTree.Spec open MerkleTree.New.High #set-options "--z3rlimit 40 --max_fuel 0 --max_ifuel 0" /// Sequence helpers val seq_prefix: #a:Type -> s1:S.seq a -> s2:S.seq a{S.length s1 <= S.length s2} -> GTot Type0 let seq_prefix #a s1 s2 = S.equal s1 (S.slice s2 0 (S.length s1)) val seq_head_cons: #a:Type -> x:a -> s:S.seq a -> Lemma (S.head (S.cons x s) == x) [SMTPat (S.cons x s)] let seq_head_cons #a x s = () val seq_tail_cons: #a:Type -> x:a -> s:S.seq a -> Lemma (S.equal (S.tail (S.cons x s)) s) [SMTPat (S.cons x s)] let seq_tail_cons #a x s = () /// Invariants and simulation relation of high-level Merkle tree design // Invariants of internal hashes val empty_hashes: (#hsz:pos) -> (len:nat) -> GTot (hs:hashess #hsz {S.length hs = len}) let empty_hashes #hsz len = S.create len S.empty val empty_hashes_head: #hsz:pos -> len:nat{len > 0} -> Lemma (S.head (empty_hashes #hsz len) == S.empty) let empty_hashes_head #_ _ = () val empty_hashes_tail: #hsz:pos -> len:nat{len > 0} -> Lemma (S.equal (S.tail (empty_hashes len)) (empty_hashes #hsz (len - 1))) let empty_hashes_tail #_ _ = () #push-options "--max_fuel 1" val mt_hashes_lth_inv: #hsz:pos -> lv:nat{lv <= 32} -> j:nat{j < pow2 (32 - lv)} -> fhs:hashess #hsz {S.length fhs = 32} -> GTot Type0 (decreases (32 - lv)) let rec mt_hashes_lth_inv #hsz lv j fhs = if lv = 32 then true else (S.length (S.index fhs lv) == j /\ mt_hashes_lth_inv (lv + 1) (j / 2) fhs) val mt_hashes_lth_inv_empty: #hsz:pos -> lv:nat{lv <= 32} -> Lemma (requires True) (ensures mt_hashes_lth_inv lv 0 (empty_hashes #hsz 32)) (decreases (32 - lv)) let rec mt_hashes_lth_inv_empty #hsz lv = if lv = 32 then () else mt_hashes_lth_inv_empty #hsz (lv + 1) val mt_hashes_next_rel: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> j:nat -> hs:hashes #hsz {S.length hs = j} -> nhs:hashes #hsz {S.length nhs = j / 2} -> GTot Type0 let mt_hashes_next_rel #hsz #f j hs nhs = forall (i:nat{i < j / 2}). S.index nhs i == f (S.index hs (op_Multiply 2 i)) (S.index hs (op_Multiply 2 i + 1)) #pop-options #push-options "--max_fuel 2" val mt_hashes_inv: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> lv:nat{lv < 32} -> j:nat{j < pow2 (32 - lv)} -> fhs:hashess #hsz {S.length fhs = 32 /\ mt_hashes_lth_inv lv j fhs} -> GTot Type0 (decreases (32 - lv)) let rec mt_hashes_inv #hsz #f lv j fhs = if lv = 31 then true else (mt_hashes_next_rel #_ #f j (S.index fhs lv) (S.index fhs (lv + 1)) /\ mt_hashes_inv #_ #f (lv + 1) (j / 2) fhs) val mt_hashes_inv_empty: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> lv:nat{lv < 32} -> Lemma (requires True) (ensures (mt_hashes_lth_inv_empty #hsz lv; mt_hashes_inv #hsz #f lv 0 (empty_hashes #hsz 32))) (decreases (32 - lv)) let rec mt_hashes_inv_empty #hsz #f lv = if lv = 31 then () else (mt_hashes_lth_inv_empty #hsz (lv + 1); mt_hashes_inv_empty #_ #f (lv + 1)) val mt_hashes_lth_inv_equiv: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> lv:nat{lv < 32} -> j:nat{j < pow2 (32 - lv)} -> fhs1:hashess{S.length fhs1 = 32} -> fhs2:hashess{S.length fhs2 = 32} -> Lemma (requires mt_hashes_lth_inv lv j fhs1 /\ S.equal (S.slice fhs1 lv 32) (S.slice fhs2 lv 32)) (ensures mt_hashes_lth_inv #hsz lv j fhs2)
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "MerkleTree.Spec.fst.checked", "MerkleTree.New.High.fst.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Ghost.fsti.checked", "FStar.Classical.fsti.checked" ], "interface_file": false, "source_file": "MerkleTree.New.High.Correct.Base.fst" }
[ { "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": 2, "initial_ifuel": 1, "max_fuel": 2, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 40, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
lv: Prims.nat{lv < 32} -> j: Prims.nat{j < Prims.pow2 (32 - lv)} -> fhs1: MerkleTree.New.High.hashess{FStar.Seq.Base.length fhs1 = 32} -> fhs2: MerkleTree.New.High.hashess{FStar.Seq.Base.length fhs2 = 32} -> FStar.Pervasives.Lemma (requires MerkleTree.New.High.Correct.Base.mt_hashes_lth_inv lv j fhs1 /\ FStar.Seq.Base.equal (FStar.Seq.Base.slice fhs1 lv 32) (FStar.Seq.Base.slice fhs2 lv 32)) (ensures MerkleTree.New.High.Correct.Base.mt_hashes_lth_inv lv j fhs2) (decreases 32 - lv)
FStar.Pervasives.Lemma
[ "lemma", "" ]
[]
[ "Prims.pos", "MerkleTree.Spec.hash_fun_t", "Prims.nat", "Prims.b2t", "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", "Prims.bool", "MerkleTree.New.High.Correct.Base.mt_hashes_lth_inv_equiv", "Prims.op_Addition", "Prims.op_Division", "Prims.unit", "Prims._assert", "Prims.eq2", "FStar.Seq.Base.index" ]
[ "recursion" ]
false
false
true
false
false
let rec mt_hashes_lth_inv_equiv #hsz #f lv j fhs1 fhs2 =
if lv = 31 then () else (assert (S.index fhs1 lv == S.index fhs2 lv); mt_hashes_lth_inv_equiv #_ #f (lv + 1) (j / 2) fhs1 fhs2)
false
Hacl.Spec.K256.Scalar.fst
Hacl.Spec.K256.Scalar.qmul_shift_384
val qmul_shift_384 (a b: qelem_lseq) : qelem_lseq
val qmul_shift_384 (a b: qelem_lseq) : qelem_lseq
let qmul_shift_384 (a b:qelem_lseq) : qelem_lseq = let l = SB.bn_mul a b in let res_b = SB.bn_rshift l 6 in let res_b_padded = create 4 (u64 0) in let res_b_padded = update_sub res_b_padded 0 2 res_b in let _, res1_b = SB.bn_add1 res_b_padded (u64 1) in let flag = l.[5] >>. 63ul in let mask = u64 0 -. flag in // mask = if flag is set then ones_v U64 else 0 map2 (BB.mask_select mask) res1_b res_b_padded
{ "file_name": "code/k256/Hacl.Spec.K256.Scalar.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 48, "end_line": 191, "start_col": 0, "start_line": 182 }
module Hacl.Spec.K256.Scalar open FStar.Mul open Lib.IntTypes open Lib.Sequence module BSeq = Lib.ByteSequence module SB = Hacl.Spec.Bignum module BB = Hacl.Spec.Bignum.Base module S = Spec.K256 #set-options "--z3rlimit 50 --fuel 0 --ifuel 0" inline_for_extraction noextract let qelem4 = uint64 & uint64 & uint64 & uint64 inline_for_extraction noextract let qelem_lseq = lseq uint64 4 noextract let qas_nat4 (f:qelem4) = let (f0, f1, f2, f3) = f in v f0 + v f1 * pow2 64 + v f2 * pow2 128 + v f3 * pow2 192 inline_for_extraction noextract val make_pow2_256_minus_order_k256: unit -> Pure qelem4 (requires True) (ensures fun r -> qas_nat4 r = pow2 256 - S.q) let make_pow2_256_minus_order_k256 () = [@inline_let] let r = (u64 0x402da1732fc9bebf, u64 0x4551231950b75fc4, u64 0x1, u64 0x0) in assert_norm (qas_nat4 r = pow2 256 - S.q); r inline_for_extraction noextract let is_qelem_zero_vartime4 ((f0,f1,f2,f3): qelem4) : bool = let open Lib.RawIntTypes in u64_to_UInt64 f0 =. 0uL && u64_to_UInt64 f1 =. 0uL && u64_to_UInt64 f2 =. 0uL && u64_to_UInt64 f3 =. 0uL inline_for_extraction noextract let is_qelem_lt_q_vartime4 ((a0,a1,a2,a3): qelem4) : bool = let open Lib.RawIntTypes in if u64_to_UInt64 a3 <. 0xffffffffffffffffuL then true else begin if u64_to_UInt64 a2 <. 0xfffffffffffffffeuL then true else begin if u64_to_UInt64 a2 >. 0xfffffffffffffffeuL then false else begin if u64_to_UInt64 a1 <. 0xbaaedce6af48a03buL then true else begin if u64_to_UInt64 a1 >. 0xbaaedce6af48a03buL then false else u64_to_UInt64 a0 <. 0xbfd25e8cd0364141uL end end end end inline_for_extraction noextract let is_qelem_le_q_halved_vartime4 ((a0,a1,a2,a3): qelem4) : bool = let open Lib.RawIntTypes in if u64_to_UInt64 a3 <. 0x7fffffffffffffffuL then true else begin if u64_to_UInt64 a3 >. 0x7fffffffffffffffuL then false else begin if u64_to_UInt64 a2 <. 0xffffffffffffffffuL then true else begin if u64_to_UInt64 a2 >. 0xffffffffffffffffuL then false else begin if u64_to_UInt64 a1 <. 0x5d576e7357a4501duL then true else begin if u64_to_UInt64 a1 >. 0x5d576e7357a4501duL then false else u64_to_UInt64 a0 <=. 0xdfe92f46681b20a0uL end end end end end inline_for_extraction noextract let is_qelem_eq_vartime4 ((a0,a1,a2,a3): qelem4) ((b0,b1,b2,b3): qelem4) : bool = let open Lib.RawIntTypes in u64_to_UInt64 a0 =. u64_to_UInt64 b0 && u64_to_UInt64 a1 =. u64_to_UInt64 b1 && u64_to_UInt64 a2 =. u64_to_UInt64 b2 && u64_to_UInt64 a3 =. u64_to_UInt64 b3 inline_for_extraction noextract let is_qelem_lt_pow2_128_vartime4 ((a0,a1,a2,a3): qelem4) : bool = let open Lib.RawIntTypes in u64_to_UInt64 a2 =. 0uL && u64_to_UInt64 a3 =. 0uL noextract val mod_short_lseq: a:qelem_lseq -> qelem_lseq let mod_short_lseq a = let (t0,t1,t2,t3) = make_pow2_256_minus_order_k256 () in let tmp = create4 t0 t1 t2 t3 in let c, out = SB.bn_add a tmp in let mask = u64 0 -. c in map2 (BB.mask_select mask) out a noextract val mul_pow2_256_minus_q_lseq: len:size_nat -> resLen:size_nat{2 + len <= resLen} -> a:lseq uint64 len -> BB.carry U64 & lseq uint64 resLen let mul_pow2_256_minus_q_lseq len resLen a = let t0 = u64 0x402da1732fc9bebf in let t1 = u64 0x4551231950b75fc4 in let t01 = create2 t0 t1 in let m0 = SB.bn_mul a t01 in // a * t01 let m1 = create resLen (u64 0) in let m1 = update_sub m1 2 len a in // a * t2 * pow2 128 SB.bn_add m1 m0 // a * SECP256K1_N_C noextract val mul_pow2_256_minus_q_lseq_add: len:size_nat -> resLen:size_nat{2 + len <= resLen /\ 4 <= resLen} -> a:lseq uint64 len -> e:lseq uint64 4 -> BB.carry U64 & lseq uint64 resLen let mul_pow2_256_minus_q_lseq_add len resLen a e = let _, m = mul_pow2_256_minus_q_lseq len resLen a in // a * SECP256K1_N_C SB.bn_add m e // e + a * SECP256K1_N_C noextract val mod_lseq_before_final: a:lseq uint64 8 -> BB.carry U64 & qelem_lseq let mod_lseq_before_final a = // Reduce 512 bits into 385. // m[0..6] = a[0..3] + a[4..7] * SECP256K1_N_C. // Reduce 385 bits into 258. // p[0..4] = m[0..3] + m[4..6] * SECP256K1_N_C. // Reduce 258 bits into 256. // c, r[0..3] = p[0..3] + p[4] * SECP256K1_N_C. // Final reduction of r. // secp256k1_scalar_reduce(r, c + secp256k1_scalar_check_overflow(r)); // 385 // 64 = 7 let _, m = mul_pow2_256_minus_q_lseq_add 4 7 (sub a 4 4) (sub a 0 4) in // a[0..3] + a[4..7] * SECP256K1_N_C // 258 // 64 = 5 let _, p = mul_pow2_256_minus_q_lseq_add 3 5 (sub m 4 3) (sub m 0 4) in // m[0..3] + m[4..6] * SECP256K1_N_C mul_pow2_256_minus_q_lseq_add 1 4 (sub p 4 1) (sub p 0 4) // p[0..3] + p[4] * SECP256K1_N_C noextract val mod_lseq: a:lseq uint64 8 -> qelem_lseq let mod_lseq a = let c0, r = mod_lseq_before_final a in let (t0,t1,t2,t3) = make_pow2_256_minus_order_k256 () in let tmp = create4 t0 t1 t2 t3 in let c1, out = SB.bn_add r tmp in let mask = u64 0 -. (c0 +. c1) in map2 (BB.mask_select mask) out r
{ "checked_file": "/", "dependencies": [ "Spec.K256.fst.checked", "prims.fst.checked", "Lib.Sequence.fsti.checked", "Lib.RawIntTypes.fsti.checked", "Lib.IntTypes.fsti.checked", "Lib.ByteSequence.fsti.checked", "Hacl.Spec.Bignum.Base.fst.checked", "Hacl.Spec.Bignum.fsti.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked" ], "interface_file": false, "source_file": "Hacl.Spec.K256.Scalar.fst" }
[ { "abbrev": true, "full_module": "Spec.K256", "short_module": "S" }, { "abbrev": true, "full_module": "Hacl.Spec.Bignum.Base", "short_module": "BB" }, { "abbrev": true, "full_module": "Hacl.Spec.Bignum", "short_module": "SB" }, { "abbrev": true, "full_module": "Lib.ByteSequence", "short_module": "BSeq" }, { "abbrev": false, "full_module": "Lib.Sequence", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.K256", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.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": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
a: Hacl.Spec.K256.Scalar.qelem_lseq -> b: Hacl.Spec.K256.Scalar.qelem_lseq -> Hacl.Spec.K256.Scalar.qelem_lseq
Prims.Tot
[ "total" ]
[]
[ "Hacl.Spec.K256.Scalar.qelem_lseq", "Hacl.Spec.Bignum.Base.carry", "Lib.IntTypes.U64", "Hacl.Spec.Bignum.Definitions.lbignum", "Lib.Sequence.map2", "Hacl.Spec.Bignum.Definitions.limb", "Lib.IntTypes.uint64", "Hacl.Spec.Bignum.Base.mask_select", "Lib.IntTypes.int_t", "Lib.IntTypes.SEC", "Lib.IntTypes.op_Subtraction_Dot", "Lib.IntTypes.u64", "Lib.IntTypes.op_Greater_Greater_Dot", "Lib.Sequence.op_String_Access", "FStar.UInt32.__uint_to_t", "FStar.Pervasives.Native.tuple2", "Hacl.Spec.Bignum.bn_add1", "Lib.Sequence.lseq", "Prims.l_and", "Prims.eq2", "Lib.Sequence.sub", "Prims.l_Forall", "Prims.nat", "Prims.l_or", "Prims.b2t", "Prims.op_LessThanOrEqual", "Prims.op_LessThan", "Prims.op_Addition", "FStar.Seq.Base.index", "Lib.Sequence.to_seq", "Lib.Sequence.index", "Lib.Sequence.update_sub", "FStar.Seq.Base.seq", "FStar.Seq.Base.create", "Lib.IntTypes.mk_int", "Prims.l_imp", "Lib.Sequence.create", "Prims.op_Subtraction", "Hacl.Spec.Bignum.bn_rshift", "Hacl.Spec.Bignum.bn_mul" ]
[]
false
false
false
true
false
let qmul_shift_384 (a b: qelem_lseq) : qelem_lseq =
let l = SB.bn_mul a b in let res_b = SB.bn_rshift l 6 in let res_b_padded = create 4 (u64 0) in let res_b_padded = update_sub res_b_padded 0 2 res_b in let _, res1_b = SB.bn_add1 res_b_padded (u64 1) in let flag = l.[ 5 ] >>. 63ul in let mask = u64 0 -. flag in map2 (BB.mask_select mask) res1_b res_b_padded
false
MerkleTree.New.High.Correct.Base.fst
MerkleTree.New.High.Correct.Base.mt_hashes_inv_empty
val mt_hashes_inv_empty: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> lv:nat{lv < 32} -> Lemma (requires True) (ensures (mt_hashes_lth_inv_empty #hsz lv; mt_hashes_inv #hsz #f lv 0 (empty_hashes #hsz 32))) (decreases (32 - lv))
val mt_hashes_inv_empty: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> lv:nat{lv < 32} -> Lemma (requires True) (ensures (mt_hashes_lth_inv_empty #hsz lv; mt_hashes_inv #hsz #f lv 0 (empty_hashes #hsz 32))) (decreases (32 - lv))
let rec mt_hashes_inv_empty #hsz #f lv = if lv = 31 then () else (mt_hashes_lth_inv_empty #hsz (lv + 1); mt_hashes_inv_empty #_ #f (lv + 1))
{ "file_name": "src/MerkleTree.New.High.Correct.Base.fst", "git_rev": "7d7bdc20f2033171e279c176b26e84f9069d23c6", "git_url": "https://github.com/hacl-star/merkle-tree.git", "project_name": "merkle-tree" }
{ "end_col": 43, "end_line": 112, "start_col": 0, "start_line": 109 }
module MerkleTree.New.High.Correct.Base open FStar.Classical open FStar.Ghost open FStar.Seq module S = FStar.Seq module MTS = MerkleTree.Spec open MerkleTree.New.High #set-options "--z3rlimit 40 --max_fuel 0 --max_ifuel 0" /// Sequence helpers val seq_prefix: #a:Type -> s1:S.seq a -> s2:S.seq a{S.length s1 <= S.length s2} -> GTot Type0 let seq_prefix #a s1 s2 = S.equal s1 (S.slice s2 0 (S.length s1)) val seq_head_cons: #a:Type -> x:a -> s:S.seq a -> Lemma (S.head (S.cons x s) == x) [SMTPat (S.cons x s)] let seq_head_cons #a x s = () val seq_tail_cons: #a:Type -> x:a -> s:S.seq a -> Lemma (S.equal (S.tail (S.cons x s)) s) [SMTPat (S.cons x s)] let seq_tail_cons #a x s = () /// Invariants and simulation relation of high-level Merkle tree design // Invariants of internal hashes val empty_hashes: (#hsz:pos) -> (len:nat) -> GTot (hs:hashess #hsz {S.length hs = len}) let empty_hashes #hsz len = S.create len S.empty val empty_hashes_head: #hsz:pos -> len:nat{len > 0} -> Lemma (S.head (empty_hashes #hsz len) == S.empty) let empty_hashes_head #_ _ = () val empty_hashes_tail: #hsz:pos -> len:nat{len > 0} -> Lemma (S.equal (S.tail (empty_hashes len)) (empty_hashes #hsz (len - 1))) let empty_hashes_tail #_ _ = () #push-options "--max_fuel 1" val mt_hashes_lth_inv: #hsz:pos -> lv:nat{lv <= 32} -> j:nat{j < pow2 (32 - lv)} -> fhs:hashess #hsz {S.length fhs = 32} -> GTot Type0 (decreases (32 - lv)) let rec mt_hashes_lth_inv #hsz lv j fhs = if lv = 32 then true else (S.length (S.index fhs lv) == j /\ mt_hashes_lth_inv (lv + 1) (j / 2) fhs) val mt_hashes_lth_inv_empty: #hsz:pos -> lv:nat{lv <= 32} -> Lemma (requires True) (ensures mt_hashes_lth_inv lv 0 (empty_hashes #hsz 32)) (decreases (32 - lv)) let rec mt_hashes_lth_inv_empty #hsz lv = if lv = 32 then () else mt_hashes_lth_inv_empty #hsz (lv + 1) val mt_hashes_next_rel: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> j:nat -> hs:hashes #hsz {S.length hs = j} -> nhs:hashes #hsz {S.length nhs = j / 2} -> GTot Type0 let mt_hashes_next_rel #hsz #f j hs nhs = forall (i:nat{i < j / 2}). S.index nhs i == f (S.index hs (op_Multiply 2 i)) (S.index hs (op_Multiply 2 i + 1)) #pop-options #push-options "--max_fuel 2" val mt_hashes_inv: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> lv:nat{lv < 32} -> j:nat{j < pow2 (32 - lv)} -> fhs:hashess #hsz {S.length fhs = 32 /\ mt_hashes_lth_inv lv j fhs} -> GTot Type0 (decreases (32 - lv)) let rec mt_hashes_inv #hsz #f lv j fhs = if lv = 31 then true else (mt_hashes_next_rel #_ #f j (S.index fhs lv) (S.index fhs (lv + 1)) /\ mt_hashes_inv #_ #f (lv + 1) (j / 2) fhs) val mt_hashes_inv_empty: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> lv:nat{lv < 32} -> Lemma (requires True) (ensures (mt_hashes_lth_inv_empty #hsz lv; mt_hashes_inv #hsz #f lv 0 (empty_hashes #hsz 32)))
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "MerkleTree.Spec.fst.checked", "MerkleTree.New.High.fst.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Ghost.fsti.checked", "FStar.Classical.fsti.checked" ], "interface_file": false, "source_file": "MerkleTree.New.High.Correct.Base.fst" }
[ { "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": 2, "initial_ifuel": 1, "max_fuel": 2, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 40, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
lv: Prims.nat{lv < 32} -> FStar.Pervasives.Lemma (ensures (MerkleTree.New.High.Correct.Base.mt_hashes_lth_inv_empty lv; MerkleTree.New.High.Correct.Base.mt_hashes_inv lv 0 (MerkleTree.New.High.Correct.Base.empty_hashes 32))) (decreases 32 - lv)
FStar.Pervasives.Lemma
[ "lemma", "" ]
[]
[ "Prims.pos", "MerkleTree.Spec.hash_fun_t", "Prims.nat", "Prims.b2t", "Prims.op_LessThan", "Prims.op_Equality", "Prims.int", "Prims.bool", "MerkleTree.New.High.Correct.Base.mt_hashes_inv_empty", "Prims.op_Addition", "Prims.unit", "MerkleTree.New.High.Correct.Base.mt_hashes_lth_inv_empty" ]
[ "recursion" ]
false
false
true
false
false
let rec mt_hashes_inv_empty #hsz #f lv =
if lv = 31 then () else (mt_hashes_lth_inv_empty #hsz (lv + 1); mt_hashes_inv_empty #_ #f (lv + 1))
false
MerkleTree.New.High.Correct.Base.fst
MerkleTree.New.High.Correct.Base.merge_hs
val merge_hs: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> hs1:hashess #hsz -> hs2:hashess #hsz {S.length hs1 = S.length hs2} -> GTot (mhs:hashess #hsz {S.length mhs = S.length hs1}) (decreases (S.length hs1))
val merge_hs: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> hs1:hashess #hsz -> hs2:hashess #hsz {S.length hs1 = S.length hs2} -> GTot (mhs:hashess #hsz {S.length mhs = S.length hs1}) (decreases (S.length hs1))
let rec merge_hs #hsz #f hs1 hs2 = if S.length hs1 = 0 then S.empty else (S.cons (S.append (S.head hs1) (S.head hs2)) (merge_hs #_ #f (S.tail hs1) (S.tail hs2)))
{ "file_name": "src/MerkleTree.New.High.Correct.Base.fst", "git_rev": "7d7bdc20f2033171e279c176b26e84f9069d23c6", "git_url": "https://github.com/hacl-star/merkle-tree.git", "project_name": "merkle-tree" }
{ "end_col": 58, "end_line": 156, "start_col": 0, "start_line": 153 }
module MerkleTree.New.High.Correct.Base open FStar.Classical open FStar.Ghost open FStar.Seq module S = FStar.Seq module MTS = MerkleTree.Spec open MerkleTree.New.High #set-options "--z3rlimit 40 --max_fuel 0 --max_ifuel 0" /// Sequence helpers val seq_prefix: #a:Type -> s1:S.seq a -> s2:S.seq a{S.length s1 <= S.length s2} -> GTot Type0 let seq_prefix #a s1 s2 = S.equal s1 (S.slice s2 0 (S.length s1)) val seq_head_cons: #a:Type -> x:a -> s:S.seq a -> Lemma (S.head (S.cons x s) == x) [SMTPat (S.cons x s)] let seq_head_cons #a x s = () val seq_tail_cons: #a:Type -> x:a -> s:S.seq a -> Lemma (S.equal (S.tail (S.cons x s)) s) [SMTPat (S.cons x s)] let seq_tail_cons #a x s = () /// Invariants and simulation relation of high-level Merkle tree design // Invariants of internal hashes val empty_hashes: (#hsz:pos) -> (len:nat) -> GTot (hs:hashess #hsz {S.length hs = len}) let empty_hashes #hsz len = S.create len S.empty val empty_hashes_head: #hsz:pos -> len:nat{len > 0} -> Lemma (S.head (empty_hashes #hsz len) == S.empty) let empty_hashes_head #_ _ = () val empty_hashes_tail: #hsz:pos -> len:nat{len > 0} -> Lemma (S.equal (S.tail (empty_hashes len)) (empty_hashes #hsz (len - 1))) let empty_hashes_tail #_ _ = () #push-options "--max_fuel 1" val mt_hashes_lth_inv: #hsz:pos -> lv:nat{lv <= 32} -> j:nat{j < pow2 (32 - lv)} -> fhs:hashess #hsz {S.length fhs = 32} -> GTot Type0 (decreases (32 - lv)) let rec mt_hashes_lth_inv #hsz lv j fhs = if lv = 32 then true else (S.length (S.index fhs lv) == j /\ mt_hashes_lth_inv (lv + 1) (j / 2) fhs) val mt_hashes_lth_inv_empty: #hsz:pos -> lv:nat{lv <= 32} -> Lemma (requires True) (ensures mt_hashes_lth_inv lv 0 (empty_hashes #hsz 32)) (decreases (32 - lv)) let rec mt_hashes_lth_inv_empty #hsz lv = if lv = 32 then () else mt_hashes_lth_inv_empty #hsz (lv + 1) val mt_hashes_next_rel: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> j:nat -> hs:hashes #hsz {S.length hs = j} -> nhs:hashes #hsz {S.length nhs = j / 2} -> GTot Type0 let mt_hashes_next_rel #hsz #f j hs nhs = forall (i:nat{i < j / 2}). S.index nhs i == f (S.index hs (op_Multiply 2 i)) (S.index hs (op_Multiply 2 i + 1)) #pop-options #push-options "--max_fuel 2" val mt_hashes_inv: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> lv:nat{lv < 32} -> j:nat{j < pow2 (32 - lv)} -> fhs:hashess #hsz {S.length fhs = 32 /\ mt_hashes_lth_inv lv j fhs} -> GTot Type0 (decreases (32 - lv)) let rec mt_hashes_inv #hsz #f lv j fhs = if lv = 31 then true else (mt_hashes_next_rel #_ #f j (S.index fhs lv) (S.index fhs (lv + 1)) /\ mt_hashes_inv #_ #f (lv + 1) (j / 2) fhs) val mt_hashes_inv_empty: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> lv:nat{lv < 32} -> Lemma (requires True) (ensures (mt_hashes_lth_inv_empty #hsz lv; mt_hashes_inv #hsz #f lv 0 (empty_hashes #hsz 32))) (decreases (32 - lv)) let rec mt_hashes_inv_empty #hsz #f lv = if lv = 31 then () else (mt_hashes_lth_inv_empty #hsz (lv + 1); mt_hashes_inv_empty #_ #f (lv + 1)) val mt_hashes_lth_inv_equiv: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> lv:nat{lv < 32} -> j:nat{j < pow2 (32 - lv)} -> fhs1:hashess{S.length fhs1 = 32} -> fhs2:hashess{S.length fhs2 = 32} -> Lemma (requires mt_hashes_lth_inv lv j fhs1 /\ S.equal (S.slice fhs1 lv 32) (S.slice fhs2 lv 32)) (ensures mt_hashes_lth_inv #hsz lv j fhs2) (decreases (32 - lv)) let rec mt_hashes_lth_inv_equiv #hsz #f lv j fhs1 fhs2 = if lv = 31 then () else (assert (S.index fhs1 lv == S.index fhs2 lv); mt_hashes_lth_inv_equiv #_ #f (lv + 1) (j / 2) fhs1 fhs2) #pop-options #push-options "--max_fuel 1" val mt_hashes_inv_equiv: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> lv:nat{lv < 32} -> j:nat{j < pow2 (32 - lv)} -> fhs1:hashess #hsz {S.length fhs1 = 32 /\ mt_hashes_lth_inv lv j fhs1} -> fhs2:hashess #hsz {S.length fhs2 = 32 /\ mt_hashes_lth_inv lv j fhs2} -> Lemma (requires mt_hashes_inv #_ #f lv j fhs1 /\ S.equal (S.slice fhs1 lv 32) (S.slice fhs2 lv 32)) (ensures mt_hashes_inv #_ #f lv j fhs2) (decreases (32 - lv)) let rec mt_hashes_inv_equiv #hsz #f lv j fhs1 fhs2 = if lv = 31 then () else (assert (S.index fhs1 lv == S.index fhs2 lv); assert (S.index fhs1 (lv + 1) == S.index fhs2 (lv + 1)); mt_hashes_inv_equiv #_ #f (lv + 1) (j / 2) fhs1 fhs2) val merge_hs: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> hs1:hashess #hsz -> hs2:hashess #hsz {S.length hs1 = S.length hs2} -> GTot (mhs:hashess #hsz {S.length mhs = S.length hs1})
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "MerkleTree.Spec.fst.checked", "MerkleTree.New.High.fst.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Ghost.fsti.checked", "FStar.Classical.fsti.checked" ], "interface_file": false, "source_file": "MerkleTree.New.High.Correct.Base.fst" }
[ { "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": 2, "initial_ifuel": 1, "max_fuel": 1, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 40, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
hs1: MerkleTree.New.High.hashess -> hs2: MerkleTree.New.High.hashess{FStar.Seq.Base.length hs1 = FStar.Seq.Base.length hs2} -> Prims.GTot (mhs: MerkleTree.New.High.hashess{FStar.Seq.Base.length mhs = FStar.Seq.Base.length hs1})
Prims.GTot
[ "sometrivial", "" ]
[]
[ "Prims.pos", "MerkleTree.Spec.hash_fun_t", "MerkleTree.New.High.hashess", "Prims.b2t", "Prims.op_Equality", "Prims.nat", "FStar.Seq.Base.length", "MerkleTree.New.High.hashes", "Prims.int", "FStar.Seq.Base.empty", "Prims.bool", "FStar.Seq.Base.cons", "FStar.Seq.Base.append", "MerkleTree.New.High.hash", "FStar.Seq.Properties.head", "MerkleTree.New.High.Correct.Base.merge_hs", "FStar.Seq.Properties.tail" ]
[ "recursion" ]
false
false
false
false
false
let rec merge_hs #hsz #f hs1 hs2 =
if S.length hs1 = 0 then S.empty else (S.cons (S.append (S.head hs1) (S.head hs2)) (merge_hs #_ #f (S.tail hs1) (S.tail hs2)))
false
Vale.Stdcalls.X64.GCTR.fst
Vale.Stdcalls.X64.GCTR.lowstar_gctr256_t
val lowstar_gctr256_t : s: FStar.Ghost.erased (FStar.Seq.Base.seq Vale.Def.Types_s.nat32) -> Type0
let lowstar_gctr256_t (s:Ghost.erased (Seq.seq nat32)) = assert_norm (List.length dom + List.length ([]<:list arg) <= 20); IX64.as_lowstar_sig_t_weak_stdcall code_gctr256 dom [] _ _ (W.mk_prediction code_gctr256 dom [] ((gctr256_lemma s) code_gctr256 IA.win))
{ "file_name": "vale/code/arch/x64/interop/Vale.Stdcalls.X64.GCTR.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 81, "end_line": 245, "start_col": 0, "start_line": 237 }
module Vale.Stdcalls.X64.GCTR open FStar.HyperStack.ST module B = LowStar.Buffer module HS = FStar.HyperStack open FStar.Mul module DV = LowStar.BufferView.Down module UV = LowStar.BufferView.Up open Vale.Def.Types_s open Vale.Interop.Base module IX64 = Vale.Interop.X64 module VSig = Vale.AsLowStar.ValeSig module LSig = Vale.AsLowStar.LowStarSig module ME = Vale.X64.Memory module V = Vale.X64.Decls module IA = Vale.Interop.Assumptions module W = Vale.AsLowStar.Wrapper open Vale.X64.MemoryAdapters module VS = Vale.X64.State module MS = Vale.X64.Machine_s open Vale.AES.AES_s module GC = Vale.AES.X64.GCTR let uint64 = UInt64.t (* A little utility to trigger normalization in types *) noextract let as_t (#a:Type) (x:normal a) : a = x noextract let as_normal_t (#a:Type) (x:a) : normal a = x [@__reduce__] noextract let b128 = buf_t TUInt8 TUInt128 [@__reduce__] noextract let t128_mod = TD_Buffer TUInt8 TUInt128 default_bq [@__reduce__] noextract let t128_no_mod = TD_Buffer TUInt8 TUInt128 ({modified=false; strict_disjointness=false; taint=MS.Secret}) [@__reduce__] noextract let tuint64 = TD_Base TUInt64 [@__reduce__] noextract let (dom: list td{List.length dom <= 20}) = let y = [t128_no_mod; tuint64; t128_mod; t128_mod; t128_no_mod; t128_no_mod; tuint64] in assert_norm (List.length y = 7); y (* Need to rearrange the order of arguments *) [@__reduce__] noextract let gctr128_pre : (Ghost.erased (Seq.seq nat32)) -> VSig.vale_pre dom = fun (s:Ghost.erased (Seq.seq nat32)) (c:V.va_code) (in_b:b128) (num_bytes:uint64) (out_b:b128) (inout_b:b128) (keys_b:b128) (ctr_b:b128) (num_blocks:uint64) (va_s0:V.va_state) -> GC.va_req_Gctr_bytes_stdcall c va_s0 IA.win AES_128 (as_vale_buffer in_b) (UInt64.v num_bytes) (as_vale_buffer out_b) (as_vale_buffer inout_b) (as_vale_buffer keys_b) (as_vale_buffer ctr_b) (UInt64.v num_blocks) (Ghost.reveal s) (* Need to rearrange the order of arguments *) [@__reduce__] noextract let gctr128_post : (Ghost.erased (Seq.seq nat32)) -> VSig.vale_post dom = fun (s:Ghost.erased (Seq.seq nat32)) (c:V.va_code) (in_b:b128) (num_bytes:uint64) (out_b:b128) (inout_b:b128) (keys_b:b128) (ctr_b:b128) (num_blocks:uint64) (va_s0:V.va_state) (va_s1:V.va_state) (f:V.va_fuel) -> GC.va_ens_Gctr_bytes_stdcall c va_s0 IA.win AES_128 (as_vale_buffer in_b) (UInt64.v num_bytes) (as_vale_buffer out_b) (as_vale_buffer inout_b) (as_vale_buffer keys_b) (as_vale_buffer ctr_b) (UInt64.v num_blocks) (Ghost.reveal s) va_s1 f #set-options "--z3rlimit 20" [@__reduce__] noextract let gctr128_lemma' (s:Ghost.erased (Seq.seq nat32)) (code:V.va_code) (_win:bool) (in_b:b128) (num_bytes:uint64) (out_b:b128) (inout_b:b128) (keys_b:b128) (ctr_b:b128) (num_blocks:uint64) (va_s0:V.va_state) : Ghost (V.va_state & V.va_fuel) (requires gctr128_pre s code in_b num_bytes out_b inout_b keys_b ctr_b num_blocks va_s0) (ensures (fun (va_s1, f) -> V.eval_code code va_s0 f va_s1 /\ VSig.vale_calling_conventions_stdcall va_s0 va_s1 /\ gctr128_post s code in_b num_bytes out_b inout_b keys_b ctr_b num_blocks va_s0 va_s1 f /\ ME.buffer_writeable (as_vale_buffer in_b) /\ ME.buffer_writeable (as_vale_buffer keys_b) /\ ME.buffer_writeable (as_vale_buffer ctr_b) /\ ME.buffer_writeable (as_vale_buffer inout_b) /\ ME.buffer_writeable (as_vale_buffer out_b) )) = let va_s1, f = GC.va_lemma_Gctr_bytes_stdcall code va_s0 IA.win AES_128 (as_vale_buffer in_b) (UInt64.v num_bytes) (as_vale_buffer out_b) (as_vale_buffer inout_b) (as_vale_buffer keys_b) (as_vale_buffer ctr_b) (UInt64.v num_blocks) (Ghost.reveal s) in Vale.AsLowStar.MemoryHelpers.buffer_writeable_reveal ME.TUInt8 ME.TUInt128 in_b; Vale.AsLowStar.MemoryHelpers.buffer_writeable_reveal ME.TUInt8 ME.TUInt128 out_b; Vale.AsLowStar.MemoryHelpers.buffer_writeable_reveal ME.TUInt8 ME.TUInt128 inout_b; Vale.AsLowStar.MemoryHelpers.buffer_writeable_reveal ME.TUInt8 ME.TUInt128 keys_b; Vale.AsLowStar.MemoryHelpers.buffer_writeable_reveal ME.TUInt8 ME.TUInt128 ctr_b; (va_s1, f) noextract let gctr128_lemma (s:Ghost.erased (Seq.seq nat32)) = as_t #(VSig.vale_sig_stdcall (gctr128_pre s) (gctr128_post s)) (gctr128_lemma' s) noextract let code_gctr128 = GC.va_code_Gctr_bytes_stdcall IA.win AES_128 [@__reduce__] noextract let lowstar_gctr128_t (s:Ghost.erased (Seq.seq nat32)) = assert_norm (List.length dom + List.length ([]<:list arg) <= 20); IX64.as_lowstar_sig_t_weak_stdcall code_gctr128 dom [] _ _ (W.mk_prediction code_gctr128 dom [] ((gctr128_lemma s) code_gctr128 IA.win)) (* And here's the gcm wrapper itself *) noextract let lowstar_gctr128 (s:Ghost.erased (Seq.seq nat32)) : lowstar_gctr128_t s = assert_norm (List.length dom + List.length ([]<:list arg) <= 20); IX64.wrap_weak_stdcall code_gctr128 dom (W.mk_prediction code_gctr128 dom [] ((gctr128_lemma s) code_gctr128 IA.win)) (* Need to rearrange the order of arguments *) [@__reduce__] noextract let gctr256_pre : (Ghost.erased (Seq.seq nat32)) -> VSig.vale_pre dom = fun (s:Ghost.erased (Seq.seq nat32)) (c:V.va_code) (in_b:b128) (num_bytes:uint64) (out_b:b128) (inout_b:b128) (keys_b:b128) (ctr_b:b128) (num_blocks:uint64) (va_s0:V.va_state) -> GC.va_req_Gctr_bytes_stdcall c va_s0 IA.win AES_256 (as_vale_buffer in_b) (UInt64.v num_bytes) (as_vale_buffer out_b) (as_vale_buffer inout_b) (as_vale_buffer keys_b) (as_vale_buffer ctr_b) (UInt64.v num_blocks) (Ghost.reveal s) (* Need to rearrange the order of arguments *) [@__reduce__] noextract let gctr256_post : (Ghost.erased (Seq.seq nat32)) -> VSig.vale_post dom = fun (s:Ghost.erased (Seq.seq nat32)) (c:V.va_code) (in_b:b128) (num_bytes:uint64) (out_b:b128) (inout_b:b128) (keys_b:b128) (ctr_b:b128) (num_blocks:uint64) (va_s0:V.va_state) (va_s1:V.va_state) (f:V.va_fuel) -> GC.va_ens_Gctr_bytes_stdcall c va_s0 IA.win AES_256 (as_vale_buffer in_b) (UInt64.v num_bytes) (as_vale_buffer out_b) (as_vale_buffer inout_b) (as_vale_buffer keys_b) (as_vale_buffer ctr_b) (UInt64.v num_blocks) (Ghost.reveal s) va_s1 f #set-options "--z3rlimit 20" [@__reduce__] noextract let gctr256_lemma' (s:Ghost.erased (Seq.seq nat32)) (code:V.va_code) (_win:bool) (in_b:b128) (num_bytes:uint64) (out_b:b128) (inout_b:b128) (keys_b:b128) (ctr_b:b128) (num_blocks:uint64) (va_s0:V.va_state) : Ghost (V.va_state & V.va_fuel) (requires gctr256_pre s code in_b num_bytes out_b inout_b keys_b ctr_b num_blocks va_s0) (ensures (fun (va_s1, f) -> V.eval_code code va_s0 f va_s1 /\ VSig.vale_calling_conventions_stdcall va_s0 va_s1 /\ gctr256_post s code in_b num_bytes out_b inout_b keys_b ctr_b num_blocks va_s0 va_s1 f /\ ME.buffer_writeable (as_vale_buffer in_b) /\ ME.buffer_writeable (as_vale_buffer keys_b) /\ ME.buffer_writeable (as_vale_buffer ctr_b) /\ ME.buffer_writeable (as_vale_buffer inout_b) /\ ME.buffer_writeable (as_vale_buffer out_b) )) = let va_s1, f = GC.va_lemma_Gctr_bytes_stdcall code va_s0 IA.win AES_256 (as_vale_buffer in_b) (UInt64.v num_bytes) (as_vale_buffer out_b) (as_vale_buffer inout_b) (as_vale_buffer keys_b) (as_vale_buffer ctr_b) (UInt64.v num_blocks) (Ghost.reveal s) in Vale.AsLowStar.MemoryHelpers.buffer_writeable_reveal ME.TUInt8 ME.TUInt128 in_b; Vale.AsLowStar.MemoryHelpers.buffer_writeable_reveal ME.TUInt8 ME.TUInt128 out_b; Vale.AsLowStar.MemoryHelpers.buffer_writeable_reveal ME.TUInt8 ME.TUInt128 inout_b; Vale.AsLowStar.MemoryHelpers.buffer_writeable_reveal ME.TUInt8 ME.TUInt128 keys_b; Vale.AsLowStar.MemoryHelpers.buffer_writeable_reveal ME.TUInt8 ME.TUInt128 ctr_b; (va_s1, f) noextract let gctr256_lemma (s:Ghost.erased (Seq.seq nat32)) = as_t #(VSig.vale_sig_stdcall (gctr256_pre s) (gctr256_post s)) (gctr256_lemma' s) noextract let code_gctr256 = GC.va_code_Gctr_bytes_stdcall IA.win AES_256
{ "checked_file": "/", "dependencies": [ "Vale.X64.State.fsti.checked", "Vale.X64.MemoryAdapters.fsti.checked", "Vale.X64.Memory.fsti.checked", "Vale.X64.Machine_s.fst.checked", "Vale.X64.Decls.fsti.checked", "Vale.Interop.X64.fsti.checked", "Vale.Interop.Base.fst.checked", "Vale.Interop.Assumptions.fst.checked", "Vale.Def.Types_s.fst.checked", "Vale.AsLowStar.Wrapper.fsti.checked", "Vale.AsLowStar.ValeSig.fst.checked", "Vale.AsLowStar.MemoryHelpers.fsti.checked", "Vale.AsLowStar.LowStarSig.fst.checked", "Vale.AES.X64.GCTR.fsti.checked", "Vale.AES.AES_s.fst.checked", "prims.fst.checked", "LowStar.BufferView.Up.fsti.checked", "LowStar.BufferView.Down.fsti.checked", "LowStar.Buffer.fst.checked", "FStar.UInt64.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.List.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked" ], "interface_file": false, "source_file": "Vale.Stdcalls.X64.GCTR.fst" }
[ { "abbrev": true, "full_module": "Vale.AES.X64.GCTR", "short_module": "GC" }, { "abbrev": false, "full_module": "Vale.AES.AES_s", "short_module": null }, { "abbrev": true, "full_module": "Vale.X64.Machine_s", "short_module": "MS" }, { "abbrev": true, "full_module": "Vale.X64.State", "short_module": "VS" }, { "abbrev": false, "full_module": "Vale.X64.MemoryAdapters", "short_module": null }, { "abbrev": true, "full_module": "Vale.AsLowStar.Wrapper", "short_module": "W" }, { "abbrev": true, "full_module": "Vale.Interop.Assumptions", "short_module": "IA" }, { "abbrev": true, "full_module": "Vale.X64.Decls", "short_module": "V" }, { "abbrev": true, "full_module": "Vale.X64.Memory", "short_module": "ME" }, { "abbrev": true, "full_module": "Vale.AsLowStar.LowStarSig", "short_module": "LSig" }, { "abbrev": true, "full_module": "Vale.AsLowStar.ValeSig", "short_module": "VSig" }, { "abbrev": true, "full_module": "Vale.Interop.X64", "short_module": "IX64" }, { "abbrev": false, "full_module": "Vale.Interop.Base", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Types_s", "short_module": null }, { "abbrev": true, "full_module": "LowStar.BufferView.Up", "short_module": "UV" }, { "abbrev": true, "full_module": "LowStar.BufferView.Down", "short_module": "DV" }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": false, "full_module": "Vale.Stdcalls.X64", "short_module": null }, { "abbrev": false, "full_module": "Vale.Stdcalls.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": 1, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": true, "smtencoding_l_arith_repr": "native", "smtencoding_nl_arith_repr": "wrapped", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [ "smt.arith.nl=false", "smt.QI.EAGER_THRESHOLD=100", "smt.CASE_SPLIT=3" ], "z3refresh": false, "z3rlimit": 20, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
s: FStar.Ghost.erased (FStar.Seq.Base.seq Vale.Def.Types_s.nat32) -> Type0
Prims.Tot
[ "total" ]
[]
[ "FStar.Ghost.erased", "FStar.Seq.Base.seq", "Vale.Def.Types_s.nat32", "Vale.Interop.X64.as_lowstar_sig_t_weak_stdcall", "Vale.Stdcalls.X64.GCTR.code_gctr256", "Vale.Stdcalls.X64.GCTR.dom", "Prims.Nil", "Vale.Interop.Base.arg", "Vale.AsLowStar.Wrapper.pre_rel_generic", "Vale.Interop.X64.max_stdcall", "Vale.Interop.X64.arg_reg_stdcall", "Vale.Stdcalls.X64.GCTR.gctr256_pre", "Vale.AsLowStar.Wrapper.post_rel_generic", "Vale.Stdcalls.X64.GCTR.gctr256_post", "Vale.AsLowStar.Wrapper.mk_prediction", "Vale.Interop.X64.regs_modified_stdcall", "Vale.Interop.X64.xmms_modified_stdcall", "Vale.Stdcalls.X64.GCTR.gctr256_lemma", "Vale.Interop.Assumptions.win", "Prims.unit", "FStar.Pervasives.assert_norm", "Prims.b2t", "Prims.op_LessThanOrEqual", "Prims.op_Addition", "FStar.List.Tot.Base.length", "Vale.Interop.Base.td", "Prims.list" ]
[]
false
false
false
true
true
let lowstar_gctr256_t (s: Ghost.erased (Seq.seq nat32)) =
assert_norm (List.length dom + List.length ([] <: list arg) <= 20); IX64.as_lowstar_sig_t_weak_stdcall code_gctr256 dom [] _ _ (W.mk_prediction code_gctr256 dom [] ((gctr256_lemma s) code_gctr256 IA.win))
false
Hacl.Spec.K256.Scalar.fst
Hacl.Spec.K256.Scalar.mod_lseq_before_final
val mod_lseq_before_final: a:lseq uint64 8 -> BB.carry U64 & qelem_lseq
val mod_lseq_before_final: a:lseq uint64 8 -> BB.carry U64 & qelem_lseq
let mod_lseq_before_final a = // Reduce 512 bits into 385. // m[0..6] = a[0..3] + a[4..7] * SECP256K1_N_C. // Reduce 385 bits into 258. // p[0..4] = m[0..3] + m[4..6] * SECP256K1_N_C. // Reduce 258 bits into 256. // c, r[0..3] = p[0..3] + p[4] * SECP256K1_N_C. // Final reduction of r. // secp256k1_scalar_reduce(r, c + secp256k1_scalar_check_overflow(r)); // 385 // 64 = 7 let _, m = mul_pow2_256_minus_q_lseq_add 4 7 (sub a 4 4) (sub a 0 4) in // a[0..3] + a[4..7] * SECP256K1_N_C // 258 // 64 = 5 let _, p = mul_pow2_256_minus_q_lseq_add 3 5 (sub m 4 3) (sub m 0 4) in // m[0..3] + m[4..6] * SECP256K1_N_C mul_pow2_256_minus_q_lseq_add 1 4 (sub p 4 1) (sub p 0 4)
{ "file_name": "code/k256/Hacl.Spec.K256.Scalar.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 59, "end_line": 165, "start_col": 0, "start_line": 148 }
module Hacl.Spec.K256.Scalar open FStar.Mul open Lib.IntTypes open Lib.Sequence module BSeq = Lib.ByteSequence module SB = Hacl.Spec.Bignum module BB = Hacl.Spec.Bignum.Base module S = Spec.K256 #set-options "--z3rlimit 50 --fuel 0 --ifuel 0" inline_for_extraction noextract let qelem4 = uint64 & uint64 & uint64 & uint64 inline_for_extraction noextract let qelem_lseq = lseq uint64 4 noextract let qas_nat4 (f:qelem4) = let (f0, f1, f2, f3) = f in v f0 + v f1 * pow2 64 + v f2 * pow2 128 + v f3 * pow2 192 inline_for_extraction noextract val make_pow2_256_minus_order_k256: unit -> Pure qelem4 (requires True) (ensures fun r -> qas_nat4 r = pow2 256 - S.q) let make_pow2_256_minus_order_k256 () = [@inline_let] let r = (u64 0x402da1732fc9bebf, u64 0x4551231950b75fc4, u64 0x1, u64 0x0) in assert_norm (qas_nat4 r = pow2 256 - S.q); r inline_for_extraction noextract let is_qelem_zero_vartime4 ((f0,f1,f2,f3): qelem4) : bool = let open Lib.RawIntTypes in u64_to_UInt64 f0 =. 0uL && u64_to_UInt64 f1 =. 0uL && u64_to_UInt64 f2 =. 0uL && u64_to_UInt64 f3 =. 0uL inline_for_extraction noextract let is_qelem_lt_q_vartime4 ((a0,a1,a2,a3): qelem4) : bool = let open Lib.RawIntTypes in if u64_to_UInt64 a3 <. 0xffffffffffffffffuL then true else begin if u64_to_UInt64 a2 <. 0xfffffffffffffffeuL then true else begin if u64_to_UInt64 a2 >. 0xfffffffffffffffeuL then false else begin if u64_to_UInt64 a1 <. 0xbaaedce6af48a03buL then true else begin if u64_to_UInt64 a1 >. 0xbaaedce6af48a03buL then false else u64_to_UInt64 a0 <. 0xbfd25e8cd0364141uL end end end end inline_for_extraction noextract let is_qelem_le_q_halved_vartime4 ((a0,a1,a2,a3): qelem4) : bool = let open Lib.RawIntTypes in if u64_to_UInt64 a3 <. 0x7fffffffffffffffuL then true else begin if u64_to_UInt64 a3 >. 0x7fffffffffffffffuL then false else begin if u64_to_UInt64 a2 <. 0xffffffffffffffffuL then true else begin if u64_to_UInt64 a2 >. 0xffffffffffffffffuL then false else begin if u64_to_UInt64 a1 <. 0x5d576e7357a4501duL then true else begin if u64_to_UInt64 a1 >. 0x5d576e7357a4501duL then false else u64_to_UInt64 a0 <=. 0xdfe92f46681b20a0uL end end end end end inline_for_extraction noextract let is_qelem_eq_vartime4 ((a0,a1,a2,a3): qelem4) ((b0,b1,b2,b3): qelem4) : bool = let open Lib.RawIntTypes in u64_to_UInt64 a0 =. u64_to_UInt64 b0 && u64_to_UInt64 a1 =. u64_to_UInt64 b1 && u64_to_UInt64 a2 =. u64_to_UInt64 b2 && u64_to_UInt64 a3 =. u64_to_UInt64 b3 inline_for_extraction noextract let is_qelem_lt_pow2_128_vartime4 ((a0,a1,a2,a3): qelem4) : bool = let open Lib.RawIntTypes in u64_to_UInt64 a2 =. 0uL && u64_to_UInt64 a3 =. 0uL noextract val mod_short_lseq: a:qelem_lseq -> qelem_lseq let mod_short_lseq a = let (t0,t1,t2,t3) = make_pow2_256_minus_order_k256 () in let tmp = create4 t0 t1 t2 t3 in let c, out = SB.bn_add a tmp in let mask = u64 0 -. c in map2 (BB.mask_select mask) out a noextract val mul_pow2_256_minus_q_lseq: len:size_nat -> resLen:size_nat{2 + len <= resLen} -> a:lseq uint64 len -> BB.carry U64 & lseq uint64 resLen let mul_pow2_256_minus_q_lseq len resLen a = let t0 = u64 0x402da1732fc9bebf in let t1 = u64 0x4551231950b75fc4 in let t01 = create2 t0 t1 in let m0 = SB.bn_mul a t01 in // a * t01 let m1 = create resLen (u64 0) in let m1 = update_sub m1 2 len a in // a * t2 * pow2 128 SB.bn_add m1 m0 // a * SECP256K1_N_C noextract val mul_pow2_256_minus_q_lseq_add: len:size_nat -> resLen:size_nat{2 + len <= resLen /\ 4 <= resLen} -> a:lseq uint64 len -> e:lseq uint64 4 -> BB.carry U64 & lseq uint64 resLen let mul_pow2_256_minus_q_lseq_add len resLen a e = let _, m = mul_pow2_256_minus_q_lseq len resLen a in // a * SECP256K1_N_C SB.bn_add m e // e + a * SECP256K1_N_C noextract
{ "checked_file": "/", "dependencies": [ "Spec.K256.fst.checked", "prims.fst.checked", "Lib.Sequence.fsti.checked", "Lib.RawIntTypes.fsti.checked", "Lib.IntTypes.fsti.checked", "Lib.ByteSequence.fsti.checked", "Hacl.Spec.Bignum.Base.fst.checked", "Hacl.Spec.Bignum.fsti.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked" ], "interface_file": false, "source_file": "Hacl.Spec.K256.Scalar.fst" }
[ { "abbrev": true, "full_module": "Spec.K256", "short_module": "S" }, { "abbrev": true, "full_module": "Hacl.Spec.Bignum.Base", "short_module": "BB" }, { "abbrev": true, "full_module": "Hacl.Spec.Bignum", "short_module": "SB" }, { "abbrev": true, "full_module": "Lib.ByteSequence", "short_module": "BSeq" }, { "abbrev": false, "full_module": "Lib.Sequence", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.K256", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.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": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
a: Lib.Sequence.lseq Lib.IntTypes.uint64 8 -> Hacl.Spec.Bignum.Base.carry Lib.IntTypes.U64 * Hacl.Spec.K256.Scalar.qelem_lseq
Prims.Tot
[ "total" ]
[]
[ "Lib.Sequence.lseq", "Lib.IntTypes.uint64", "Hacl.Spec.Bignum.Base.carry", "Lib.IntTypes.U64", "Hacl.Spec.K256.Scalar.mul_pow2_256_minus_q_lseq_add", "Lib.Sequence.sub", "FStar.Pervasives.Native.tuple2", "Hacl.Spec.K256.Scalar.qelem_lseq", "Lib.IntTypes.int_t", "Lib.IntTypes.SEC" ]
[]
false
false
false
false
false
let mod_lseq_before_final a =
let _, m = mul_pow2_256_minus_q_lseq_add 4 7 (sub a 4 4) (sub a 0 4) in let _, p = mul_pow2_256_minus_q_lseq_add 3 5 (sub m 4 3) (sub m 0 4) in mul_pow2_256_minus_q_lseq_add 1 4 (sub p 4 1) (sub p 0 4)
false
Vale.Stdcalls.X64.GCTR.fst
Vale.Stdcalls.X64.GCTR.gctr256_post
val gctr256_post: (Ghost.erased (Seq.seq nat32)) -> VSig.vale_post dom
val gctr256_post: (Ghost.erased (Seq.seq nat32)) -> VSig.vale_post dom
let gctr256_post : (Ghost.erased (Seq.seq nat32)) -> VSig.vale_post dom = fun (s:Ghost.erased (Seq.seq nat32)) (c:V.va_code) (in_b:b128) (num_bytes:uint64) (out_b:b128) (inout_b:b128) (keys_b:b128) (ctr_b:b128) (num_blocks:uint64) (va_s0:V.va_state) (va_s1:V.va_state) (f:V.va_fuel) -> GC.va_ens_Gctr_bytes_stdcall c va_s0 IA.win AES_256 (as_vale_buffer in_b) (UInt64.v num_bytes) (as_vale_buffer out_b) (as_vale_buffer inout_b) (as_vale_buffer keys_b) (as_vale_buffer ctr_b) (UInt64.v num_blocks) (Ghost.reveal s) va_s1 f
{ "file_name": "vale/code/arch/x64/interop/Vale.Stdcalls.X64.GCTR.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 77, "end_line": 189, "start_col": 0, "start_line": 173 }
module Vale.Stdcalls.X64.GCTR open FStar.HyperStack.ST module B = LowStar.Buffer module HS = FStar.HyperStack open FStar.Mul module DV = LowStar.BufferView.Down module UV = LowStar.BufferView.Up open Vale.Def.Types_s open Vale.Interop.Base module IX64 = Vale.Interop.X64 module VSig = Vale.AsLowStar.ValeSig module LSig = Vale.AsLowStar.LowStarSig module ME = Vale.X64.Memory module V = Vale.X64.Decls module IA = Vale.Interop.Assumptions module W = Vale.AsLowStar.Wrapper open Vale.X64.MemoryAdapters module VS = Vale.X64.State module MS = Vale.X64.Machine_s open Vale.AES.AES_s module GC = Vale.AES.X64.GCTR let uint64 = UInt64.t (* A little utility to trigger normalization in types *) noextract let as_t (#a:Type) (x:normal a) : a = x noextract let as_normal_t (#a:Type) (x:a) : normal a = x [@__reduce__] noextract let b128 = buf_t TUInt8 TUInt128 [@__reduce__] noextract let t128_mod = TD_Buffer TUInt8 TUInt128 default_bq [@__reduce__] noextract let t128_no_mod = TD_Buffer TUInt8 TUInt128 ({modified=false; strict_disjointness=false; taint=MS.Secret}) [@__reduce__] noextract let tuint64 = TD_Base TUInt64 [@__reduce__] noextract let (dom: list td{List.length dom <= 20}) = let y = [t128_no_mod; tuint64; t128_mod; t128_mod; t128_no_mod; t128_no_mod; tuint64] in assert_norm (List.length y = 7); y (* Need to rearrange the order of arguments *) [@__reduce__] noextract let gctr128_pre : (Ghost.erased (Seq.seq nat32)) -> VSig.vale_pre dom = fun (s:Ghost.erased (Seq.seq nat32)) (c:V.va_code) (in_b:b128) (num_bytes:uint64) (out_b:b128) (inout_b:b128) (keys_b:b128) (ctr_b:b128) (num_blocks:uint64) (va_s0:V.va_state) -> GC.va_req_Gctr_bytes_stdcall c va_s0 IA.win AES_128 (as_vale_buffer in_b) (UInt64.v num_bytes) (as_vale_buffer out_b) (as_vale_buffer inout_b) (as_vale_buffer keys_b) (as_vale_buffer ctr_b) (UInt64.v num_blocks) (Ghost.reveal s) (* Need to rearrange the order of arguments *) [@__reduce__] noextract let gctr128_post : (Ghost.erased (Seq.seq nat32)) -> VSig.vale_post dom = fun (s:Ghost.erased (Seq.seq nat32)) (c:V.va_code) (in_b:b128) (num_bytes:uint64) (out_b:b128) (inout_b:b128) (keys_b:b128) (ctr_b:b128) (num_blocks:uint64) (va_s0:V.va_state) (va_s1:V.va_state) (f:V.va_fuel) -> GC.va_ens_Gctr_bytes_stdcall c va_s0 IA.win AES_128 (as_vale_buffer in_b) (UInt64.v num_bytes) (as_vale_buffer out_b) (as_vale_buffer inout_b) (as_vale_buffer keys_b) (as_vale_buffer ctr_b) (UInt64.v num_blocks) (Ghost.reveal s) va_s1 f #set-options "--z3rlimit 20" [@__reduce__] noextract let gctr128_lemma' (s:Ghost.erased (Seq.seq nat32)) (code:V.va_code) (_win:bool) (in_b:b128) (num_bytes:uint64) (out_b:b128) (inout_b:b128) (keys_b:b128) (ctr_b:b128) (num_blocks:uint64) (va_s0:V.va_state) : Ghost (V.va_state & V.va_fuel) (requires gctr128_pre s code in_b num_bytes out_b inout_b keys_b ctr_b num_blocks va_s0) (ensures (fun (va_s1, f) -> V.eval_code code va_s0 f va_s1 /\ VSig.vale_calling_conventions_stdcall va_s0 va_s1 /\ gctr128_post s code in_b num_bytes out_b inout_b keys_b ctr_b num_blocks va_s0 va_s1 f /\ ME.buffer_writeable (as_vale_buffer in_b) /\ ME.buffer_writeable (as_vale_buffer keys_b) /\ ME.buffer_writeable (as_vale_buffer ctr_b) /\ ME.buffer_writeable (as_vale_buffer inout_b) /\ ME.buffer_writeable (as_vale_buffer out_b) )) = let va_s1, f = GC.va_lemma_Gctr_bytes_stdcall code va_s0 IA.win AES_128 (as_vale_buffer in_b) (UInt64.v num_bytes) (as_vale_buffer out_b) (as_vale_buffer inout_b) (as_vale_buffer keys_b) (as_vale_buffer ctr_b) (UInt64.v num_blocks) (Ghost.reveal s) in Vale.AsLowStar.MemoryHelpers.buffer_writeable_reveal ME.TUInt8 ME.TUInt128 in_b; Vale.AsLowStar.MemoryHelpers.buffer_writeable_reveal ME.TUInt8 ME.TUInt128 out_b; Vale.AsLowStar.MemoryHelpers.buffer_writeable_reveal ME.TUInt8 ME.TUInt128 inout_b; Vale.AsLowStar.MemoryHelpers.buffer_writeable_reveal ME.TUInt8 ME.TUInt128 keys_b; Vale.AsLowStar.MemoryHelpers.buffer_writeable_reveal ME.TUInt8 ME.TUInt128 ctr_b; (va_s1, f) noextract let gctr128_lemma (s:Ghost.erased (Seq.seq nat32)) = as_t #(VSig.vale_sig_stdcall (gctr128_pre s) (gctr128_post s)) (gctr128_lemma' s) noextract let code_gctr128 = GC.va_code_Gctr_bytes_stdcall IA.win AES_128 [@__reduce__] noextract let lowstar_gctr128_t (s:Ghost.erased (Seq.seq nat32)) = assert_norm (List.length dom + List.length ([]<:list arg) <= 20); IX64.as_lowstar_sig_t_weak_stdcall code_gctr128 dom [] _ _ (W.mk_prediction code_gctr128 dom [] ((gctr128_lemma s) code_gctr128 IA.win)) (* And here's the gcm wrapper itself *) noextract let lowstar_gctr128 (s:Ghost.erased (Seq.seq nat32)) : lowstar_gctr128_t s = assert_norm (List.length dom + List.length ([]<:list arg) <= 20); IX64.wrap_weak_stdcall code_gctr128 dom (W.mk_prediction code_gctr128 dom [] ((gctr128_lemma s) code_gctr128 IA.win)) (* Need to rearrange the order of arguments *) [@__reduce__] noextract let gctr256_pre : (Ghost.erased (Seq.seq nat32)) -> VSig.vale_pre dom = fun (s:Ghost.erased (Seq.seq nat32)) (c:V.va_code) (in_b:b128) (num_bytes:uint64) (out_b:b128) (inout_b:b128) (keys_b:b128) (ctr_b:b128) (num_blocks:uint64) (va_s0:V.va_state) -> GC.va_req_Gctr_bytes_stdcall c va_s0 IA.win AES_256 (as_vale_buffer in_b) (UInt64.v num_bytes) (as_vale_buffer out_b) (as_vale_buffer inout_b) (as_vale_buffer keys_b) (as_vale_buffer ctr_b) (UInt64.v num_blocks) (Ghost.reveal s) (* Need to rearrange the order of arguments *)
{ "checked_file": "/", "dependencies": [ "Vale.X64.State.fsti.checked", "Vale.X64.MemoryAdapters.fsti.checked", "Vale.X64.Memory.fsti.checked", "Vale.X64.Machine_s.fst.checked", "Vale.X64.Decls.fsti.checked", "Vale.Interop.X64.fsti.checked", "Vale.Interop.Base.fst.checked", "Vale.Interop.Assumptions.fst.checked", "Vale.Def.Types_s.fst.checked", "Vale.AsLowStar.Wrapper.fsti.checked", "Vale.AsLowStar.ValeSig.fst.checked", "Vale.AsLowStar.MemoryHelpers.fsti.checked", "Vale.AsLowStar.LowStarSig.fst.checked", "Vale.AES.X64.GCTR.fsti.checked", "Vale.AES.AES_s.fst.checked", "prims.fst.checked", "LowStar.BufferView.Up.fsti.checked", "LowStar.BufferView.Down.fsti.checked", "LowStar.Buffer.fst.checked", "FStar.UInt64.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.List.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked" ], "interface_file": false, "source_file": "Vale.Stdcalls.X64.GCTR.fst" }
[ { "abbrev": true, "full_module": "Vale.AES.X64.GCTR", "short_module": "GC" }, { "abbrev": false, "full_module": "Vale.AES.AES_s", "short_module": null }, { "abbrev": true, "full_module": "Vale.X64.Machine_s", "short_module": "MS" }, { "abbrev": true, "full_module": "Vale.X64.State", "short_module": "VS" }, { "abbrev": false, "full_module": "Vale.X64.MemoryAdapters", "short_module": null }, { "abbrev": true, "full_module": "Vale.AsLowStar.Wrapper", "short_module": "W" }, { "abbrev": true, "full_module": "Vale.Interop.Assumptions", "short_module": "IA" }, { "abbrev": true, "full_module": "Vale.X64.Decls", "short_module": "V" }, { "abbrev": true, "full_module": "Vale.X64.Memory", "short_module": "ME" }, { "abbrev": true, "full_module": "Vale.AsLowStar.LowStarSig", "short_module": "LSig" }, { "abbrev": true, "full_module": "Vale.AsLowStar.ValeSig", "short_module": "VSig" }, { "abbrev": true, "full_module": "Vale.Interop.X64", "short_module": "IX64" }, { "abbrev": false, "full_module": "Vale.Interop.Base", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Types_s", "short_module": null }, { "abbrev": true, "full_module": "LowStar.BufferView.Up", "short_module": "UV" }, { "abbrev": true, "full_module": "LowStar.BufferView.Down", "short_module": "DV" }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": false, "full_module": "Vale.Stdcalls.X64", "short_module": null }, { "abbrev": false, "full_module": "Vale.Stdcalls.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": 1, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": true, "smtencoding_l_arith_repr": "native", "smtencoding_nl_arith_repr": "wrapped", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [ "smt.arith.nl=false", "smt.QI.EAGER_THRESHOLD=100", "smt.CASE_SPLIT=3" ], "z3refresh": false, "z3rlimit": 20, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
s: FStar.Ghost.erased (FStar.Seq.Base.seq Vale.Def.Words_s.nat32) -> Vale.AsLowStar.ValeSig.vale_post Vale.Stdcalls.X64.GCTR.dom
Prims.Tot
[ "total" ]
[]
[ "FStar.Ghost.erased", "FStar.Seq.Base.seq", "Vale.Def.Types_s.nat32", "Vale.X64.Decls.va_code", "Vale.Stdcalls.X64.GCTR.b128", "Vale.Stdcalls.X64.GCTR.uint64", "Vale.X64.Decls.va_state", "Vale.X64.Decls.va_fuel", "Vale.AES.X64.GCTR.va_ens_Gctr_bytes_stdcall", "Vale.Interop.Assumptions.win", "Vale.AES.AES_common_s.AES_256", "Vale.X64.MemoryAdapters.as_vale_buffer", "Vale.Arch.HeapTypes_s.TUInt8", "Vale.Arch.HeapTypes_s.TUInt128", "FStar.UInt64.v", "FStar.Ghost.reveal", "Prims.prop" ]
[]
false
false
false
true
false
let gctr256_post: (Ghost.erased (Seq.seq nat32)) -> VSig.vale_post dom =
fun (s: Ghost.erased (Seq.seq nat32)) (c: V.va_code) (in_b: b128) (num_bytes: uint64) (out_b: b128) (inout_b: b128) (keys_b: b128) (ctr_b: b128) (num_blocks: uint64) (va_s0: V.va_state) (va_s1: V.va_state) (f: V.va_fuel) -> GC.va_ens_Gctr_bytes_stdcall c va_s0 IA.win AES_256 (as_vale_buffer in_b) (UInt64.v num_bytes) (as_vale_buffer out_b) (as_vale_buffer inout_b) (as_vale_buffer keys_b) (as_vale_buffer ctr_b) (UInt64.v num_blocks) (Ghost.reveal s) va_s1 f
false
MerkleTree.New.High.Correct.Base.fst
MerkleTree.New.High.Correct.Base.mt_hashes_inv
val mt_hashes_inv: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> lv:nat{lv < 32} -> j:nat{j < pow2 (32 - lv)} -> fhs:hashess #hsz {S.length fhs = 32 /\ mt_hashes_lth_inv lv j fhs} -> GTot Type0 (decreases (32 - lv))
val mt_hashes_inv: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> lv:nat{lv < 32} -> j:nat{j < pow2 (32 - lv)} -> fhs:hashess #hsz {S.length fhs = 32 /\ mt_hashes_lth_inv lv j fhs} -> GTot Type0 (decreases (32 - lv))
let rec mt_hashes_inv #hsz #f lv j fhs = if lv = 31 then true else (mt_hashes_next_rel #_ #f j (S.index fhs lv) (S.index fhs (lv + 1)) /\ mt_hashes_inv #_ #f (lv + 1) (j / 2) fhs)
{ "file_name": "src/MerkleTree.New.High.Correct.Base.fst", "git_rev": "7d7bdc20f2033171e279c176b26e84f9069d23c6", "git_url": "https://github.com/hacl-star/merkle-tree.git", "project_name": "merkle-tree" }
{ "end_col": 48, "end_line": 100, "start_col": 0, "start_line": 97 }
module MerkleTree.New.High.Correct.Base open FStar.Classical open FStar.Ghost open FStar.Seq module S = FStar.Seq module MTS = MerkleTree.Spec open MerkleTree.New.High #set-options "--z3rlimit 40 --max_fuel 0 --max_ifuel 0" /// Sequence helpers val seq_prefix: #a:Type -> s1:S.seq a -> s2:S.seq a{S.length s1 <= S.length s2} -> GTot Type0 let seq_prefix #a s1 s2 = S.equal s1 (S.slice s2 0 (S.length s1)) val seq_head_cons: #a:Type -> x:a -> s:S.seq a -> Lemma (S.head (S.cons x s) == x) [SMTPat (S.cons x s)] let seq_head_cons #a x s = () val seq_tail_cons: #a:Type -> x:a -> s:S.seq a -> Lemma (S.equal (S.tail (S.cons x s)) s) [SMTPat (S.cons x s)] let seq_tail_cons #a x s = () /// Invariants and simulation relation of high-level Merkle tree design // Invariants of internal hashes val empty_hashes: (#hsz:pos) -> (len:nat) -> GTot (hs:hashess #hsz {S.length hs = len}) let empty_hashes #hsz len = S.create len S.empty val empty_hashes_head: #hsz:pos -> len:nat{len > 0} -> Lemma (S.head (empty_hashes #hsz len) == S.empty) let empty_hashes_head #_ _ = () val empty_hashes_tail: #hsz:pos -> len:nat{len > 0} -> Lemma (S.equal (S.tail (empty_hashes len)) (empty_hashes #hsz (len - 1))) let empty_hashes_tail #_ _ = () #push-options "--max_fuel 1" val mt_hashes_lth_inv: #hsz:pos -> lv:nat{lv <= 32} -> j:nat{j < pow2 (32 - lv)} -> fhs:hashess #hsz {S.length fhs = 32} -> GTot Type0 (decreases (32 - lv)) let rec mt_hashes_lth_inv #hsz lv j fhs = if lv = 32 then true else (S.length (S.index fhs lv) == j /\ mt_hashes_lth_inv (lv + 1) (j / 2) fhs) val mt_hashes_lth_inv_empty: #hsz:pos -> lv:nat{lv <= 32} -> Lemma (requires True) (ensures mt_hashes_lth_inv lv 0 (empty_hashes #hsz 32)) (decreases (32 - lv)) let rec mt_hashes_lth_inv_empty #hsz lv = if lv = 32 then () else mt_hashes_lth_inv_empty #hsz (lv + 1) val mt_hashes_next_rel: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> j:nat -> hs:hashes #hsz {S.length hs = j} -> nhs:hashes #hsz {S.length nhs = j / 2} -> GTot Type0 let mt_hashes_next_rel #hsz #f j hs nhs = forall (i:nat{i < j / 2}). S.index nhs i == f (S.index hs (op_Multiply 2 i)) (S.index hs (op_Multiply 2 i + 1)) #pop-options #push-options "--max_fuel 2" val mt_hashes_inv: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> lv:nat{lv < 32} -> j:nat{j < pow2 (32 - lv)} -> fhs:hashess #hsz {S.length fhs = 32 /\ mt_hashes_lth_inv lv j fhs} ->
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "MerkleTree.Spec.fst.checked", "MerkleTree.New.High.fst.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Ghost.fsti.checked", "FStar.Classical.fsti.checked" ], "interface_file": false, "source_file": "MerkleTree.New.High.Correct.Base.fst" }
[ { "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": 2, "initial_ifuel": 1, "max_fuel": 2, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 40, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
lv: Prims.nat{lv < 32} -> j: Prims.nat{j < Prims.pow2 (32 - lv)} -> fhs: MerkleTree.New.High.hashess { FStar.Seq.Base.length fhs = 32 /\ MerkleTree.New.High.Correct.Base.mt_hashes_lth_inv lv j fhs } -> Prims.GTot Type0
Prims.GTot
[ "sometrivial", "" ]
[]
[ "Prims.pos", "MerkleTree.Spec.hash_fun_t", "Prims.nat", "Prims.b2t", "Prims.op_LessThan", "Prims.pow2", "Prims.op_Subtraction", "MerkleTree.New.High.hashess", "Prims.l_and", "Prims.op_Equality", "Prims.int", "FStar.Seq.Base.length", "MerkleTree.New.High.hashes", "MerkleTree.New.High.Correct.Base.mt_hashes_lth_inv", "Prims.bool", "MerkleTree.New.High.Correct.Base.mt_hashes_next_rel", "FStar.Seq.Base.index", "Prims.op_Addition", "MerkleTree.New.High.Correct.Base.mt_hashes_inv", "Prims.op_Division" ]
[ "recursion" ]
false
false
false
false
true
let rec mt_hashes_inv #hsz #f lv j fhs =
if lv = 31 then true else (mt_hashes_next_rel #_ #f j (S.index fhs lv) (S.index fhs (lv + 1)) /\ mt_hashes_inv #_ #f (lv + 1) (j / 2) fhs)
false
Vale.Stdcalls.X64.GCTR.fst
Vale.Stdcalls.X64.GCTR.gctr256_bytes
val gctr256_bytes : Vale.Interop.Base.normal (s: FStar.Ghost.erased (FStar.Seq.Base.seq Vale.Def.Types_s.nat32) -> Vale.Stdcalls.X64.GCTR.lowstar_gctr256_t s)
let gctr256_bytes //: normal ((s:Ghost.erased (Seq.seq nat32)) -> lowstar_gctr256_t s) = as_normal_t #((s:Ghost.erased (Seq.seq nat32)) -> lowstar_gctr256_t s) (fun (s:Ghost.erased (Seq.seq nat32)) -> lowstar_gctr256 s)
{ "file_name": "vale/code/arch/x64/interop/Vale.Stdcalls.X64.GCTR.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 134, "end_line": 262, "start_col": 0, "start_line": 261 }
module Vale.Stdcalls.X64.GCTR open FStar.HyperStack.ST module B = LowStar.Buffer module HS = FStar.HyperStack open FStar.Mul module DV = LowStar.BufferView.Down module UV = LowStar.BufferView.Up open Vale.Def.Types_s open Vale.Interop.Base module IX64 = Vale.Interop.X64 module VSig = Vale.AsLowStar.ValeSig module LSig = Vale.AsLowStar.LowStarSig module ME = Vale.X64.Memory module V = Vale.X64.Decls module IA = Vale.Interop.Assumptions module W = Vale.AsLowStar.Wrapper open Vale.X64.MemoryAdapters module VS = Vale.X64.State module MS = Vale.X64.Machine_s open Vale.AES.AES_s module GC = Vale.AES.X64.GCTR let uint64 = UInt64.t (* A little utility to trigger normalization in types *) noextract let as_t (#a:Type) (x:normal a) : a = x noextract let as_normal_t (#a:Type) (x:a) : normal a = x [@__reduce__] noextract let b128 = buf_t TUInt8 TUInt128 [@__reduce__] noextract let t128_mod = TD_Buffer TUInt8 TUInt128 default_bq [@__reduce__] noextract let t128_no_mod = TD_Buffer TUInt8 TUInt128 ({modified=false; strict_disjointness=false; taint=MS.Secret}) [@__reduce__] noextract let tuint64 = TD_Base TUInt64 [@__reduce__] noextract let (dom: list td{List.length dom <= 20}) = let y = [t128_no_mod; tuint64; t128_mod; t128_mod; t128_no_mod; t128_no_mod; tuint64] in assert_norm (List.length y = 7); y (* Need to rearrange the order of arguments *) [@__reduce__] noextract let gctr128_pre : (Ghost.erased (Seq.seq nat32)) -> VSig.vale_pre dom = fun (s:Ghost.erased (Seq.seq nat32)) (c:V.va_code) (in_b:b128) (num_bytes:uint64) (out_b:b128) (inout_b:b128) (keys_b:b128) (ctr_b:b128) (num_blocks:uint64) (va_s0:V.va_state) -> GC.va_req_Gctr_bytes_stdcall c va_s0 IA.win AES_128 (as_vale_buffer in_b) (UInt64.v num_bytes) (as_vale_buffer out_b) (as_vale_buffer inout_b) (as_vale_buffer keys_b) (as_vale_buffer ctr_b) (UInt64.v num_blocks) (Ghost.reveal s) (* Need to rearrange the order of arguments *) [@__reduce__] noextract let gctr128_post : (Ghost.erased (Seq.seq nat32)) -> VSig.vale_post dom = fun (s:Ghost.erased (Seq.seq nat32)) (c:V.va_code) (in_b:b128) (num_bytes:uint64) (out_b:b128) (inout_b:b128) (keys_b:b128) (ctr_b:b128) (num_blocks:uint64) (va_s0:V.va_state) (va_s1:V.va_state) (f:V.va_fuel) -> GC.va_ens_Gctr_bytes_stdcall c va_s0 IA.win AES_128 (as_vale_buffer in_b) (UInt64.v num_bytes) (as_vale_buffer out_b) (as_vale_buffer inout_b) (as_vale_buffer keys_b) (as_vale_buffer ctr_b) (UInt64.v num_blocks) (Ghost.reveal s) va_s1 f #set-options "--z3rlimit 20" [@__reduce__] noextract let gctr128_lemma' (s:Ghost.erased (Seq.seq nat32)) (code:V.va_code) (_win:bool) (in_b:b128) (num_bytes:uint64) (out_b:b128) (inout_b:b128) (keys_b:b128) (ctr_b:b128) (num_blocks:uint64) (va_s0:V.va_state) : Ghost (V.va_state & V.va_fuel) (requires gctr128_pre s code in_b num_bytes out_b inout_b keys_b ctr_b num_blocks va_s0) (ensures (fun (va_s1, f) -> V.eval_code code va_s0 f va_s1 /\ VSig.vale_calling_conventions_stdcall va_s0 va_s1 /\ gctr128_post s code in_b num_bytes out_b inout_b keys_b ctr_b num_blocks va_s0 va_s1 f /\ ME.buffer_writeable (as_vale_buffer in_b) /\ ME.buffer_writeable (as_vale_buffer keys_b) /\ ME.buffer_writeable (as_vale_buffer ctr_b) /\ ME.buffer_writeable (as_vale_buffer inout_b) /\ ME.buffer_writeable (as_vale_buffer out_b) )) = let va_s1, f = GC.va_lemma_Gctr_bytes_stdcall code va_s0 IA.win AES_128 (as_vale_buffer in_b) (UInt64.v num_bytes) (as_vale_buffer out_b) (as_vale_buffer inout_b) (as_vale_buffer keys_b) (as_vale_buffer ctr_b) (UInt64.v num_blocks) (Ghost.reveal s) in Vale.AsLowStar.MemoryHelpers.buffer_writeable_reveal ME.TUInt8 ME.TUInt128 in_b; Vale.AsLowStar.MemoryHelpers.buffer_writeable_reveal ME.TUInt8 ME.TUInt128 out_b; Vale.AsLowStar.MemoryHelpers.buffer_writeable_reveal ME.TUInt8 ME.TUInt128 inout_b; Vale.AsLowStar.MemoryHelpers.buffer_writeable_reveal ME.TUInt8 ME.TUInt128 keys_b; Vale.AsLowStar.MemoryHelpers.buffer_writeable_reveal ME.TUInt8 ME.TUInt128 ctr_b; (va_s1, f) noextract let gctr128_lemma (s:Ghost.erased (Seq.seq nat32)) = as_t #(VSig.vale_sig_stdcall (gctr128_pre s) (gctr128_post s)) (gctr128_lemma' s) noextract let code_gctr128 = GC.va_code_Gctr_bytes_stdcall IA.win AES_128 [@__reduce__] noextract let lowstar_gctr128_t (s:Ghost.erased (Seq.seq nat32)) = assert_norm (List.length dom + List.length ([]<:list arg) <= 20); IX64.as_lowstar_sig_t_weak_stdcall code_gctr128 dom [] _ _ (W.mk_prediction code_gctr128 dom [] ((gctr128_lemma s) code_gctr128 IA.win)) (* And here's the gcm wrapper itself *) noextract let lowstar_gctr128 (s:Ghost.erased (Seq.seq nat32)) : lowstar_gctr128_t s = assert_norm (List.length dom + List.length ([]<:list arg) <= 20); IX64.wrap_weak_stdcall code_gctr128 dom (W.mk_prediction code_gctr128 dom [] ((gctr128_lemma s) code_gctr128 IA.win)) (* Need to rearrange the order of arguments *) [@__reduce__] noextract let gctr256_pre : (Ghost.erased (Seq.seq nat32)) -> VSig.vale_pre dom = fun (s:Ghost.erased (Seq.seq nat32)) (c:V.va_code) (in_b:b128) (num_bytes:uint64) (out_b:b128) (inout_b:b128) (keys_b:b128) (ctr_b:b128) (num_blocks:uint64) (va_s0:V.va_state) -> GC.va_req_Gctr_bytes_stdcall c va_s0 IA.win AES_256 (as_vale_buffer in_b) (UInt64.v num_bytes) (as_vale_buffer out_b) (as_vale_buffer inout_b) (as_vale_buffer keys_b) (as_vale_buffer ctr_b) (UInt64.v num_blocks) (Ghost.reveal s) (* Need to rearrange the order of arguments *) [@__reduce__] noextract let gctr256_post : (Ghost.erased (Seq.seq nat32)) -> VSig.vale_post dom = fun (s:Ghost.erased (Seq.seq nat32)) (c:V.va_code) (in_b:b128) (num_bytes:uint64) (out_b:b128) (inout_b:b128) (keys_b:b128) (ctr_b:b128) (num_blocks:uint64) (va_s0:V.va_state) (va_s1:V.va_state) (f:V.va_fuel) -> GC.va_ens_Gctr_bytes_stdcall c va_s0 IA.win AES_256 (as_vale_buffer in_b) (UInt64.v num_bytes) (as_vale_buffer out_b) (as_vale_buffer inout_b) (as_vale_buffer keys_b) (as_vale_buffer ctr_b) (UInt64.v num_blocks) (Ghost.reveal s) va_s1 f #set-options "--z3rlimit 20" [@__reduce__] noextract let gctr256_lemma' (s:Ghost.erased (Seq.seq nat32)) (code:V.va_code) (_win:bool) (in_b:b128) (num_bytes:uint64) (out_b:b128) (inout_b:b128) (keys_b:b128) (ctr_b:b128) (num_blocks:uint64) (va_s0:V.va_state) : Ghost (V.va_state & V.va_fuel) (requires gctr256_pre s code in_b num_bytes out_b inout_b keys_b ctr_b num_blocks va_s0) (ensures (fun (va_s1, f) -> V.eval_code code va_s0 f va_s1 /\ VSig.vale_calling_conventions_stdcall va_s0 va_s1 /\ gctr256_post s code in_b num_bytes out_b inout_b keys_b ctr_b num_blocks va_s0 va_s1 f /\ ME.buffer_writeable (as_vale_buffer in_b) /\ ME.buffer_writeable (as_vale_buffer keys_b) /\ ME.buffer_writeable (as_vale_buffer ctr_b) /\ ME.buffer_writeable (as_vale_buffer inout_b) /\ ME.buffer_writeable (as_vale_buffer out_b) )) = let va_s1, f = GC.va_lemma_Gctr_bytes_stdcall code va_s0 IA.win AES_256 (as_vale_buffer in_b) (UInt64.v num_bytes) (as_vale_buffer out_b) (as_vale_buffer inout_b) (as_vale_buffer keys_b) (as_vale_buffer ctr_b) (UInt64.v num_blocks) (Ghost.reveal s) in Vale.AsLowStar.MemoryHelpers.buffer_writeable_reveal ME.TUInt8 ME.TUInt128 in_b; Vale.AsLowStar.MemoryHelpers.buffer_writeable_reveal ME.TUInt8 ME.TUInt128 out_b; Vale.AsLowStar.MemoryHelpers.buffer_writeable_reveal ME.TUInt8 ME.TUInt128 inout_b; Vale.AsLowStar.MemoryHelpers.buffer_writeable_reveal ME.TUInt8 ME.TUInt128 keys_b; Vale.AsLowStar.MemoryHelpers.buffer_writeable_reveal ME.TUInt8 ME.TUInt128 ctr_b; (va_s1, f) noextract let gctr256_lemma (s:Ghost.erased (Seq.seq nat32)) = as_t #(VSig.vale_sig_stdcall (gctr256_pre s) (gctr256_post s)) (gctr256_lemma' s) noextract let code_gctr256 = GC.va_code_Gctr_bytes_stdcall IA.win AES_256 [@__reduce__] noextract let lowstar_gctr256_t (s:Ghost.erased (Seq.seq nat32)) = assert_norm (List.length dom + List.length ([]<:list arg) <= 20); IX64.as_lowstar_sig_t_weak_stdcall code_gctr256 dom [] _ _ (W.mk_prediction code_gctr256 dom [] ((gctr256_lemma s) code_gctr256 IA.win)) (* And here's the gcm wrapper itself *) noextract let lowstar_gctr256 (s:Ghost.erased (Seq.seq nat32)) : lowstar_gctr256_t s = assert_norm (List.length dom + List.length ([]<:list arg) <= 20); IX64.wrap_weak_stdcall code_gctr256 dom (W.mk_prediction code_gctr256 dom [] ((gctr256_lemma s) code_gctr256 IA.win)) [@ (CCConv "stdcall") ] let gctr128_bytes //: normal ((s:Ghost.erased (Seq.seq nat32)) -> lowstar_gctr128_t s) = as_normal_t #((s:Ghost.erased (Seq.seq nat32)) -> lowstar_gctr128_t s) (fun (s:Ghost.erased (Seq.seq nat32)) -> lowstar_gctr128 s)
{ "checked_file": "/", "dependencies": [ "Vale.X64.State.fsti.checked", "Vale.X64.MemoryAdapters.fsti.checked", "Vale.X64.Memory.fsti.checked", "Vale.X64.Machine_s.fst.checked", "Vale.X64.Decls.fsti.checked", "Vale.Interop.X64.fsti.checked", "Vale.Interop.Base.fst.checked", "Vale.Interop.Assumptions.fst.checked", "Vale.Def.Types_s.fst.checked", "Vale.AsLowStar.Wrapper.fsti.checked", "Vale.AsLowStar.ValeSig.fst.checked", "Vale.AsLowStar.MemoryHelpers.fsti.checked", "Vale.AsLowStar.LowStarSig.fst.checked", "Vale.AES.X64.GCTR.fsti.checked", "Vale.AES.AES_s.fst.checked", "prims.fst.checked", "LowStar.BufferView.Up.fsti.checked", "LowStar.BufferView.Down.fsti.checked", "LowStar.Buffer.fst.checked", "FStar.UInt64.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.List.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked" ], "interface_file": false, "source_file": "Vale.Stdcalls.X64.GCTR.fst" }
[ { "abbrev": true, "full_module": "Vale.AES.X64.GCTR", "short_module": "GC" }, { "abbrev": false, "full_module": "Vale.AES.AES_s", "short_module": null }, { "abbrev": true, "full_module": "Vale.X64.Machine_s", "short_module": "MS" }, { "abbrev": true, "full_module": "Vale.X64.State", "short_module": "VS" }, { "abbrev": false, "full_module": "Vale.X64.MemoryAdapters", "short_module": null }, { "abbrev": true, "full_module": "Vale.AsLowStar.Wrapper", "short_module": "W" }, { "abbrev": true, "full_module": "Vale.Interop.Assumptions", "short_module": "IA" }, { "abbrev": true, "full_module": "Vale.X64.Decls", "short_module": "V" }, { "abbrev": true, "full_module": "Vale.X64.Memory", "short_module": "ME" }, { "abbrev": true, "full_module": "Vale.AsLowStar.LowStarSig", "short_module": "LSig" }, { "abbrev": true, "full_module": "Vale.AsLowStar.ValeSig", "short_module": "VSig" }, { "abbrev": true, "full_module": "Vale.Interop.X64", "short_module": "IX64" }, { "abbrev": false, "full_module": "Vale.Interop.Base", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Types_s", "short_module": null }, { "abbrev": true, "full_module": "LowStar.BufferView.Up", "short_module": "UV" }, { "abbrev": true, "full_module": "LowStar.BufferView.Down", "short_module": "DV" }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": false, "full_module": "Vale.Stdcalls.X64", "short_module": null }, { "abbrev": false, "full_module": "Vale.Stdcalls.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": 1, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": true, "smtencoding_l_arith_repr": "native", "smtencoding_nl_arith_repr": "wrapped", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [ "smt.arith.nl=false", "smt.QI.EAGER_THRESHOLD=100", "smt.CASE_SPLIT=3" ], "z3refresh": false, "z3rlimit": 20, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
Vale.Interop.Base.normal (s: FStar.Ghost.erased (FStar.Seq.Base.seq Vale.Def.Types_s.nat32) -> Vale.Stdcalls.X64.GCTR.lowstar_gctr256_t s)
Prims.Tot
[ "total" ]
[]
[ "Vale.Stdcalls.X64.GCTR.as_normal_t", "FStar.Ghost.erased", "FStar.Seq.Base.seq", "Vale.Def.Types_s.nat32", "Vale.Stdcalls.X64.GCTR.lowstar_gctr256_t", "Vale.Stdcalls.X64.GCTR.lowstar_gctr256" ]
[]
false
false
false
false
false
let gctr256_bytes =
as_normal_t #(s: Ghost.erased (Seq.seq nat32) -> lowstar_gctr256_t s) (fun (s: Ghost.erased (Seq.seq nat32)) -> lowstar_gctr256 s)
false
MerkleTree.New.High.Correct.Base.fst
MerkleTree.New.High.Correct.Base.mt_olds_inv
val mt_olds_inv: #hsz:pos -> lv:nat{lv <= 32} -> i:nat -> olds:hashess #hsz {S.length olds = 32} -> GTot Type0 (decreases (32 - lv))
val mt_olds_inv: #hsz:pos -> lv:nat{lv <= 32} -> i:nat -> olds:hashess #hsz {S.length olds = 32} -> GTot Type0 (decreases (32 - lv))
let rec mt_olds_inv #hsz lv i olds = if lv = 32 then true else (let ofs = offset_of i in S.length (S.index olds lv) == ofs /\ mt_olds_inv #hsz (lv + 1) (i / 2) olds)
{ "file_name": "src/MerkleTree.New.High.Correct.Base.fst", "git_rev": "7d7bdc20f2033171e279c176b26e84f9069d23c6", "git_url": "https://github.com/hacl-star/merkle-tree.git", "project_name": "merkle-tree" }
{ "end_col": 46, "end_line": 234, "start_col": 0, "start_line": 230 }
module MerkleTree.New.High.Correct.Base open FStar.Classical open FStar.Ghost open FStar.Seq module S = FStar.Seq module MTS = MerkleTree.Spec open MerkleTree.New.High #set-options "--z3rlimit 40 --max_fuel 0 --max_ifuel 0" /// Sequence helpers val seq_prefix: #a:Type -> s1:S.seq a -> s2:S.seq a{S.length s1 <= S.length s2} -> GTot Type0 let seq_prefix #a s1 s2 = S.equal s1 (S.slice s2 0 (S.length s1)) val seq_head_cons: #a:Type -> x:a -> s:S.seq a -> Lemma (S.head (S.cons x s) == x) [SMTPat (S.cons x s)] let seq_head_cons #a x s = () val seq_tail_cons: #a:Type -> x:a -> s:S.seq a -> Lemma (S.equal (S.tail (S.cons x s)) s) [SMTPat (S.cons x s)] let seq_tail_cons #a x s = () /// Invariants and simulation relation of high-level Merkle tree design // Invariants of internal hashes val empty_hashes: (#hsz:pos) -> (len:nat) -> GTot (hs:hashess #hsz {S.length hs = len}) let empty_hashes #hsz len = S.create len S.empty val empty_hashes_head: #hsz:pos -> len:nat{len > 0} -> Lemma (S.head (empty_hashes #hsz len) == S.empty) let empty_hashes_head #_ _ = () val empty_hashes_tail: #hsz:pos -> len:nat{len > 0} -> Lemma (S.equal (S.tail (empty_hashes len)) (empty_hashes #hsz (len - 1))) let empty_hashes_tail #_ _ = () #push-options "--max_fuel 1" val mt_hashes_lth_inv: #hsz:pos -> lv:nat{lv <= 32} -> j:nat{j < pow2 (32 - lv)} -> fhs:hashess #hsz {S.length fhs = 32} -> GTot Type0 (decreases (32 - lv)) let rec mt_hashes_lth_inv #hsz lv j fhs = if lv = 32 then true else (S.length (S.index fhs lv) == j /\ mt_hashes_lth_inv (lv + 1) (j / 2) fhs) val mt_hashes_lth_inv_empty: #hsz:pos -> lv:nat{lv <= 32} -> Lemma (requires True) (ensures mt_hashes_lth_inv lv 0 (empty_hashes #hsz 32)) (decreases (32 - lv)) let rec mt_hashes_lth_inv_empty #hsz lv = if lv = 32 then () else mt_hashes_lth_inv_empty #hsz (lv + 1) val mt_hashes_next_rel: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> j:nat -> hs:hashes #hsz {S.length hs = j} -> nhs:hashes #hsz {S.length nhs = j / 2} -> GTot Type0 let mt_hashes_next_rel #hsz #f j hs nhs = forall (i:nat{i < j / 2}). S.index nhs i == f (S.index hs (op_Multiply 2 i)) (S.index hs (op_Multiply 2 i + 1)) #pop-options #push-options "--max_fuel 2" val mt_hashes_inv: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> lv:nat{lv < 32} -> j:nat{j < pow2 (32 - lv)} -> fhs:hashess #hsz {S.length fhs = 32 /\ mt_hashes_lth_inv lv j fhs} -> GTot Type0 (decreases (32 - lv)) let rec mt_hashes_inv #hsz #f lv j fhs = if lv = 31 then true else (mt_hashes_next_rel #_ #f j (S.index fhs lv) (S.index fhs (lv + 1)) /\ mt_hashes_inv #_ #f (lv + 1) (j / 2) fhs) val mt_hashes_inv_empty: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> lv:nat{lv < 32} -> Lemma (requires True) (ensures (mt_hashes_lth_inv_empty #hsz lv; mt_hashes_inv #hsz #f lv 0 (empty_hashes #hsz 32))) (decreases (32 - lv)) let rec mt_hashes_inv_empty #hsz #f lv = if lv = 31 then () else (mt_hashes_lth_inv_empty #hsz (lv + 1); mt_hashes_inv_empty #_ #f (lv + 1)) val mt_hashes_lth_inv_equiv: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> lv:nat{lv < 32} -> j:nat{j < pow2 (32 - lv)} -> fhs1:hashess{S.length fhs1 = 32} -> fhs2:hashess{S.length fhs2 = 32} -> Lemma (requires mt_hashes_lth_inv lv j fhs1 /\ S.equal (S.slice fhs1 lv 32) (S.slice fhs2 lv 32)) (ensures mt_hashes_lth_inv #hsz lv j fhs2) (decreases (32 - lv)) let rec mt_hashes_lth_inv_equiv #hsz #f lv j fhs1 fhs2 = if lv = 31 then () else (assert (S.index fhs1 lv == S.index fhs2 lv); mt_hashes_lth_inv_equiv #_ #f (lv + 1) (j / 2) fhs1 fhs2) #pop-options #push-options "--max_fuel 1" val mt_hashes_inv_equiv: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> lv:nat{lv < 32} -> j:nat{j < pow2 (32 - lv)} -> fhs1:hashess #hsz {S.length fhs1 = 32 /\ mt_hashes_lth_inv lv j fhs1} -> fhs2:hashess #hsz {S.length fhs2 = 32 /\ mt_hashes_lth_inv lv j fhs2} -> Lemma (requires mt_hashes_inv #_ #f lv j fhs1 /\ S.equal (S.slice fhs1 lv 32) (S.slice fhs2 lv 32)) (ensures mt_hashes_inv #_ #f lv j fhs2) (decreases (32 - lv)) let rec mt_hashes_inv_equiv #hsz #f lv j fhs1 fhs2 = if lv = 31 then () else (assert (S.index fhs1 lv == S.index fhs2 lv); assert (S.index fhs1 (lv + 1) == S.index fhs2 (lv + 1)); mt_hashes_inv_equiv #_ #f (lv + 1) (j / 2) fhs1 fhs2) val merge_hs: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> hs1:hashess #hsz -> hs2:hashess #hsz {S.length hs1 = S.length hs2} -> GTot (mhs:hashess #hsz {S.length mhs = S.length hs1}) (decreases (S.length hs1)) let rec merge_hs #hsz #f hs1 hs2 = if S.length hs1 = 0 then S.empty else (S.cons (S.append (S.head hs1) (S.head hs2)) (merge_hs #_ #f (S.tail hs1) (S.tail hs2))) val merge_hs_empty: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> len:nat -> Lemma (S.equal (merge_hs #_ #f (empty_hashes #hsz len) (empty_hashes #hsz len)) (empty_hashes #hsz len)) let rec merge_hs_empty #hsz #f len = if len = 0 then () else (empty_hashes_head #hsz len; empty_hashes_tail #hsz len; assert (S.equal (S.append #(hash #hsz) S.empty S.empty) (S.empty #(hash #hsz))); assert (S.equal (merge_hs #_ #f (empty_hashes len) (empty_hashes len)) (S.cons S.empty (merge_hs #_ #f (empty_hashes (len - 1)) (empty_hashes (len - 1))))); merge_hs_empty #_ #f (len - 1)) val merge_hs_index: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> hs1:hashess -> hs2:hashess{S.length hs1 = S.length hs2} -> i:nat{i < S.length hs1} -> Lemma (requires True) (ensures S.equal (S.index (merge_hs #_ #f hs1 hs2) i) (S.append (S.index hs1 i) (S.index hs2 i))) (decreases (S.length hs1)) [SMTPat (S.index (merge_hs #_ #f hs1 hs2) i)] let rec merge_hs_index #hsz #f hs1 hs2 i = if S.length hs1 = 0 then () else if i = 0 then () else merge_hs_index #_ #f (S.tail hs1) (S.tail hs2) (i - 1) val merge_hs_slice_equal: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> ahs1:hashess #hsz -> ahs2:hashess #hsz {S.length ahs1 = S.length ahs2} -> bhs1:hashess #hsz -> bhs2:hashess #hsz {S.length bhs1 = S.length bhs2} -> i:nat -> j:nat{i <= j && j <= S.length ahs1 && j <= S.length bhs1} -> Lemma (requires S.equal (S.slice ahs1 i j) (S.slice bhs1 i j) /\ S.equal (S.slice ahs2 i j) (S.slice bhs2 i j)) (ensures S.equal (S.slice (merge_hs #_ #f ahs1 ahs2) i j) (S.slice (merge_hs #_ #f bhs1 bhs2) i j)) (decreases (j - i)) let rec merge_hs_slice_equal #_ #f ahs1 ahs2 bhs1 bhs2 i j = if i = j then () else (assert (S.index ahs1 i == S.index bhs1 i); assert (S.index ahs2 i == S.index bhs2 i); merge_hs_slice_equal #_ #f ahs1 ahs2 bhs1 bhs2 (i + 1) j) val merge_hs_upd: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> hs1:hashess #hsz -> hs2:hashess #hsz {S.length hs1 = S.length hs2} -> i:nat{i < S.length hs1} -> v1:hashes #hsz -> v2:hashes #hsz -> Lemma (requires S.equal (S.append (S.index hs1 i) (S.index hs2 i)) (S.append v1 v2)) (ensures S.equal (merge_hs #_ #f hs1 hs2) (merge_hs #_ #f (S.upd hs1 i v1) (S.upd hs2 i v2))) (decreases i) let rec merge_hs_upd #_ #f hs1 hs2 i v1 v2 = if S.length hs1 = 0 then () else if i = 0 then () else merge_hs_upd #_ #f (S.tail hs1) (S.tail hs2) (i - 1) v1 v2 val mt_olds_inv: #hsz:pos -> lv:nat{lv <= 32} -> i:nat -> olds:hashess #hsz {S.length olds = 32} ->
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "MerkleTree.Spec.fst.checked", "MerkleTree.New.High.fst.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Ghost.fsti.checked", "FStar.Classical.fsti.checked" ], "interface_file": false, "source_file": "MerkleTree.New.High.Correct.Base.fst" }
[ { "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": 2, "initial_ifuel": 1, "max_fuel": 1, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 40, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
lv: Prims.nat{lv <= 32} -> i: Prims.nat -> olds: MerkleTree.New.High.hashess{FStar.Seq.Base.length olds = 32} -> Prims.GTot Type0
Prims.GTot
[ "sometrivial", "" ]
[]
[ "Prims.pos", "Prims.nat", "Prims.b2t", "Prims.op_LessThanOrEqual", "MerkleTree.New.High.hashess", "Prims.op_Equality", "Prims.int", "FStar.Seq.Base.length", "MerkleTree.New.High.hashes", "Prims.bool", "Prims.l_and", "Prims.eq2", "MerkleTree.New.High.hash", "FStar.Seq.Base.index", "MerkleTree.New.High.Correct.Base.mt_olds_inv", "Prims.op_Addition", "Prims.op_Division", "MerkleTree.New.High.offset_of" ]
[ "recursion" ]
false
false
false
false
true
let rec mt_olds_inv #hsz lv i olds =
if lv = 32 then true else (let ofs = offset_of i in S.length (S.index olds lv) == ofs /\ mt_olds_inv #hsz (lv + 1) (i / 2) olds)
false
MerkleTree.New.High.Correct.Base.fst
MerkleTree.New.High.Correct.Base.mt_hashes_inv_equiv
val mt_hashes_inv_equiv: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> lv:nat{lv < 32} -> j:nat{j < pow2 (32 - lv)} -> fhs1:hashess #hsz {S.length fhs1 = 32 /\ mt_hashes_lth_inv lv j fhs1} -> fhs2:hashess #hsz {S.length fhs2 = 32 /\ mt_hashes_lth_inv lv j fhs2} -> Lemma (requires mt_hashes_inv #_ #f lv j fhs1 /\ S.equal (S.slice fhs1 lv 32) (S.slice fhs2 lv 32)) (ensures mt_hashes_inv #_ #f lv j fhs2) (decreases (32 - lv))
val mt_hashes_inv_equiv: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> lv:nat{lv < 32} -> j:nat{j < pow2 (32 - lv)} -> fhs1:hashess #hsz {S.length fhs1 = 32 /\ mt_hashes_lth_inv lv j fhs1} -> fhs2:hashess #hsz {S.length fhs2 = 32 /\ mt_hashes_lth_inv lv j fhs2} -> Lemma (requires mt_hashes_inv #_ #f lv j fhs1 /\ S.equal (S.slice fhs1 lv 32) (S.slice fhs2 lv 32)) (ensures mt_hashes_inv #_ #f lv j fhs2) (decreases (32 - lv))
let rec mt_hashes_inv_equiv #hsz #f lv j fhs1 fhs2 = if lv = 31 then () else (assert (S.index fhs1 lv == S.index fhs2 lv); assert (S.index fhs1 (lv + 1) == S.index fhs2 (lv + 1)); mt_hashes_inv_equiv #_ #f (lv + 1) (j / 2) fhs1 fhs2)
{ "file_name": "src/MerkleTree.New.High.Correct.Base.fst", "git_rev": "7d7bdc20f2033171e279c176b26e84f9069d23c6", "git_url": "https://github.com/hacl-star/merkle-tree.git", "project_name": "merkle-tree" }
{ "end_col": 60, "end_line": 145, "start_col": 0, "start_line": 141 }
module MerkleTree.New.High.Correct.Base open FStar.Classical open FStar.Ghost open FStar.Seq module S = FStar.Seq module MTS = MerkleTree.Spec open MerkleTree.New.High #set-options "--z3rlimit 40 --max_fuel 0 --max_ifuel 0" /// Sequence helpers val seq_prefix: #a:Type -> s1:S.seq a -> s2:S.seq a{S.length s1 <= S.length s2} -> GTot Type0 let seq_prefix #a s1 s2 = S.equal s1 (S.slice s2 0 (S.length s1)) val seq_head_cons: #a:Type -> x:a -> s:S.seq a -> Lemma (S.head (S.cons x s) == x) [SMTPat (S.cons x s)] let seq_head_cons #a x s = () val seq_tail_cons: #a:Type -> x:a -> s:S.seq a -> Lemma (S.equal (S.tail (S.cons x s)) s) [SMTPat (S.cons x s)] let seq_tail_cons #a x s = () /// Invariants and simulation relation of high-level Merkle tree design // Invariants of internal hashes val empty_hashes: (#hsz:pos) -> (len:nat) -> GTot (hs:hashess #hsz {S.length hs = len}) let empty_hashes #hsz len = S.create len S.empty val empty_hashes_head: #hsz:pos -> len:nat{len > 0} -> Lemma (S.head (empty_hashes #hsz len) == S.empty) let empty_hashes_head #_ _ = () val empty_hashes_tail: #hsz:pos -> len:nat{len > 0} -> Lemma (S.equal (S.tail (empty_hashes len)) (empty_hashes #hsz (len - 1))) let empty_hashes_tail #_ _ = () #push-options "--max_fuel 1" val mt_hashes_lth_inv: #hsz:pos -> lv:nat{lv <= 32} -> j:nat{j < pow2 (32 - lv)} -> fhs:hashess #hsz {S.length fhs = 32} -> GTot Type0 (decreases (32 - lv)) let rec mt_hashes_lth_inv #hsz lv j fhs = if lv = 32 then true else (S.length (S.index fhs lv) == j /\ mt_hashes_lth_inv (lv + 1) (j / 2) fhs) val mt_hashes_lth_inv_empty: #hsz:pos -> lv:nat{lv <= 32} -> Lemma (requires True) (ensures mt_hashes_lth_inv lv 0 (empty_hashes #hsz 32)) (decreases (32 - lv)) let rec mt_hashes_lth_inv_empty #hsz lv = if lv = 32 then () else mt_hashes_lth_inv_empty #hsz (lv + 1) val mt_hashes_next_rel: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> j:nat -> hs:hashes #hsz {S.length hs = j} -> nhs:hashes #hsz {S.length nhs = j / 2} -> GTot Type0 let mt_hashes_next_rel #hsz #f j hs nhs = forall (i:nat{i < j / 2}). S.index nhs i == f (S.index hs (op_Multiply 2 i)) (S.index hs (op_Multiply 2 i + 1)) #pop-options #push-options "--max_fuel 2" val mt_hashes_inv: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> lv:nat{lv < 32} -> j:nat{j < pow2 (32 - lv)} -> fhs:hashess #hsz {S.length fhs = 32 /\ mt_hashes_lth_inv lv j fhs} -> GTot Type0 (decreases (32 - lv)) let rec mt_hashes_inv #hsz #f lv j fhs = if lv = 31 then true else (mt_hashes_next_rel #_ #f j (S.index fhs lv) (S.index fhs (lv + 1)) /\ mt_hashes_inv #_ #f (lv + 1) (j / 2) fhs) val mt_hashes_inv_empty: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> lv:nat{lv < 32} -> Lemma (requires True) (ensures (mt_hashes_lth_inv_empty #hsz lv; mt_hashes_inv #hsz #f lv 0 (empty_hashes #hsz 32))) (decreases (32 - lv)) let rec mt_hashes_inv_empty #hsz #f lv = if lv = 31 then () else (mt_hashes_lth_inv_empty #hsz (lv + 1); mt_hashes_inv_empty #_ #f (lv + 1)) val mt_hashes_lth_inv_equiv: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> lv:nat{lv < 32} -> j:nat{j < pow2 (32 - lv)} -> fhs1:hashess{S.length fhs1 = 32} -> fhs2:hashess{S.length fhs2 = 32} -> Lemma (requires mt_hashes_lth_inv lv j fhs1 /\ S.equal (S.slice fhs1 lv 32) (S.slice fhs2 lv 32)) (ensures mt_hashes_lth_inv #hsz lv j fhs2) (decreases (32 - lv)) let rec mt_hashes_lth_inv_equiv #hsz #f lv j fhs1 fhs2 = if lv = 31 then () else (assert (S.index fhs1 lv == S.index fhs2 lv); mt_hashes_lth_inv_equiv #_ #f (lv + 1) (j / 2) fhs1 fhs2) #pop-options #push-options "--max_fuel 1" val mt_hashes_inv_equiv: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> lv:nat{lv < 32} -> j:nat{j < pow2 (32 - lv)} -> fhs1:hashess #hsz {S.length fhs1 = 32 /\ mt_hashes_lth_inv lv j fhs1} -> fhs2:hashess #hsz {S.length fhs2 = 32 /\ mt_hashes_lth_inv lv j fhs2} -> Lemma (requires mt_hashes_inv #_ #f lv j fhs1 /\ S.equal (S.slice fhs1 lv 32) (S.slice fhs2 lv 32)) (ensures mt_hashes_inv #_ #f lv j fhs2)
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "MerkleTree.Spec.fst.checked", "MerkleTree.New.High.fst.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Ghost.fsti.checked", "FStar.Classical.fsti.checked" ], "interface_file": false, "source_file": "MerkleTree.New.High.Correct.Base.fst" }
[ { "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": 2, "initial_ifuel": 1, "max_fuel": 1, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 40, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
lv: Prims.nat{lv < 32} -> j: Prims.nat{j < Prims.pow2 (32 - lv)} -> fhs1: MerkleTree.New.High.hashess { FStar.Seq.Base.length fhs1 = 32 /\ MerkleTree.New.High.Correct.Base.mt_hashes_lth_inv lv j fhs1 } -> fhs2: MerkleTree.New.High.hashess { FStar.Seq.Base.length fhs2 = 32 /\ MerkleTree.New.High.Correct.Base.mt_hashes_lth_inv lv j fhs2 } -> FStar.Pervasives.Lemma (requires MerkleTree.New.High.Correct.Base.mt_hashes_inv lv j fhs1 /\ FStar.Seq.Base.equal (FStar.Seq.Base.slice fhs1 lv 32) (FStar.Seq.Base.slice fhs2 lv 32)) (ensures MerkleTree.New.High.Correct.Base.mt_hashes_inv lv j fhs2) (decreases 32 - lv)
FStar.Pervasives.Lemma
[ "lemma", "" ]
[]
[ "Prims.pos", "MerkleTree.Spec.hash_fun_t", "Prims.nat", "Prims.b2t", "Prims.op_LessThan", "Prims.pow2", "Prims.op_Subtraction", "MerkleTree.New.High.hashess", "Prims.l_and", "Prims.op_Equality", "Prims.int", "FStar.Seq.Base.length", "MerkleTree.New.High.hashes", "MerkleTree.New.High.Correct.Base.mt_hashes_lth_inv", "Prims.bool", "MerkleTree.New.High.Correct.Base.mt_hashes_inv_equiv", "Prims.op_Addition", "Prims.op_Division", "Prims.unit", "Prims._assert", "Prims.eq2", "FStar.Seq.Base.index" ]
[ "recursion" ]
false
false
true
false
false
let rec mt_hashes_inv_equiv #hsz #f lv j fhs1 fhs2 =
if lv = 31 then () else (assert (S.index fhs1 lv == S.index fhs2 lv); assert (S.index fhs1 (lv + 1) == S.index fhs2 (lv + 1)); mt_hashes_inv_equiv #_ #f (lv + 1) (j / 2) fhs1 fhs2)
false
MerkleTree.New.High.Correct.Base.fst
MerkleTree.New.High.Correct.Base.merge_hs_slice_equal
val merge_hs_slice_equal: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> ahs1:hashess #hsz -> ahs2:hashess #hsz {S.length ahs1 = S.length ahs2} -> bhs1:hashess #hsz -> bhs2:hashess #hsz {S.length bhs1 = S.length bhs2} -> i:nat -> j:nat{i <= j && j <= S.length ahs1 && j <= S.length bhs1} -> Lemma (requires S.equal (S.slice ahs1 i j) (S.slice bhs1 i j) /\ S.equal (S.slice ahs2 i j) (S.slice bhs2 i j)) (ensures S.equal (S.slice (merge_hs #_ #f ahs1 ahs2) i j) (S.slice (merge_hs #_ #f bhs1 bhs2) i j)) (decreases (j - i))
val merge_hs_slice_equal: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> ahs1:hashess #hsz -> ahs2:hashess #hsz {S.length ahs1 = S.length ahs2} -> bhs1:hashess #hsz -> bhs2:hashess #hsz {S.length bhs1 = S.length bhs2} -> i:nat -> j:nat{i <= j && j <= S.length ahs1 && j <= S.length bhs1} -> Lemma (requires S.equal (S.slice ahs1 i j) (S.slice bhs1 i j) /\ S.equal (S.slice ahs2 i j) (S.slice bhs2 i j)) (ensures S.equal (S.slice (merge_hs #_ #f ahs1 ahs2) i j) (S.slice (merge_hs #_ #f bhs1 bhs2) i j)) (decreases (j - i))
let rec merge_hs_slice_equal #_ #f ahs1 ahs2 bhs1 bhs2 i j = if i = j then () else (assert (S.index ahs1 i == S.index bhs1 i); assert (S.index ahs2 i == S.index bhs2 i); merge_hs_slice_equal #_ #f ahs1 ahs2 bhs1 bhs2 (i + 1) j)
{ "file_name": "src/MerkleTree.New.High.Correct.Base.fst", "git_rev": "7d7bdc20f2033171e279c176b26e84f9069d23c6", "git_url": "https://github.com/hacl-star/merkle-tree.git", "project_name": "merkle-tree" }
{ "end_col": 64, "end_line": 206, "start_col": 0, "start_line": 202 }
module MerkleTree.New.High.Correct.Base open FStar.Classical open FStar.Ghost open FStar.Seq module S = FStar.Seq module MTS = MerkleTree.Spec open MerkleTree.New.High #set-options "--z3rlimit 40 --max_fuel 0 --max_ifuel 0" /// Sequence helpers val seq_prefix: #a:Type -> s1:S.seq a -> s2:S.seq a{S.length s1 <= S.length s2} -> GTot Type0 let seq_prefix #a s1 s2 = S.equal s1 (S.slice s2 0 (S.length s1)) val seq_head_cons: #a:Type -> x:a -> s:S.seq a -> Lemma (S.head (S.cons x s) == x) [SMTPat (S.cons x s)] let seq_head_cons #a x s = () val seq_tail_cons: #a:Type -> x:a -> s:S.seq a -> Lemma (S.equal (S.tail (S.cons x s)) s) [SMTPat (S.cons x s)] let seq_tail_cons #a x s = () /// Invariants and simulation relation of high-level Merkle tree design // Invariants of internal hashes val empty_hashes: (#hsz:pos) -> (len:nat) -> GTot (hs:hashess #hsz {S.length hs = len}) let empty_hashes #hsz len = S.create len S.empty val empty_hashes_head: #hsz:pos -> len:nat{len > 0} -> Lemma (S.head (empty_hashes #hsz len) == S.empty) let empty_hashes_head #_ _ = () val empty_hashes_tail: #hsz:pos -> len:nat{len > 0} -> Lemma (S.equal (S.tail (empty_hashes len)) (empty_hashes #hsz (len - 1))) let empty_hashes_tail #_ _ = () #push-options "--max_fuel 1" val mt_hashes_lth_inv: #hsz:pos -> lv:nat{lv <= 32} -> j:nat{j < pow2 (32 - lv)} -> fhs:hashess #hsz {S.length fhs = 32} -> GTot Type0 (decreases (32 - lv)) let rec mt_hashes_lth_inv #hsz lv j fhs = if lv = 32 then true else (S.length (S.index fhs lv) == j /\ mt_hashes_lth_inv (lv + 1) (j / 2) fhs) val mt_hashes_lth_inv_empty: #hsz:pos -> lv:nat{lv <= 32} -> Lemma (requires True) (ensures mt_hashes_lth_inv lv 0 (empty_hashes #hsz 32)) (decreases (32 - lv)) let rec mt_hashes_lth_inv_empty #hsz lv = if lv = 32 then () else mt_hashes_lth_inv_empty #hsz (lv + 1) val mt_hashes_next_rel: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> j:nat -> hs:hashes #hsz {S.length hs = j} -> nhs:hashes #hsz {S.length nhs = j / 2} -> GTot Type0 let mt_hashes_next_rel #hsz #f j hs nhs = forall (i:nat{i < j / 2}). S.index nhs i == f (S.index hs (op_Multiply 2 i)) (S.index hs (op_Multiply 2 i + 1)) #pop-options #push-options "--max_fuel 2" val mt_hashes_inv: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> lv:nat{lv < 32} -> j:nat{j < pow2 (32 - lv)} -> fhs:hashess #hsz {S.length fhs = 32 /\ mt_hashes_lth_inv lv j fhs} -> GTot Type0 (decreases (32 - lv)) let rec mt_hashes_inv #hsz #f lv j fhs = if lv = 31 then true else (mt_hashes_next_rel #_ #f j (S.index fhs lv) (S.index fhs (lv + 1)) /\ mt_hashes_inv #_ #f (lv + 1) (j / 2) fhs) val mt_hashes_inv_empty: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> lv:nat{lv < 32} -> Lemma (requires True) (ensures (mt_hashes_lth_inv_empty #hsz lv; mt_hashes_inv #hsz #f lv 0 (empty_hashes #hsz 32))) (decreases (32 - lv)) let rec mt_hashes_inv_empty #hsz #f lv = if lv = 31 then () else (mt_hashes_lth_inv_empty #hsz (lv + 1); mt_hashes_inv_empty #_ #f (lv + 1)) val mt_hashes_lth_inv_equiv: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> lv:nat{lv < 32} -> j:nat{j < pow2 (32 - lv)} -> fhs1:hashess{S.length fhs1 = 32} -> fhs2:hashess{S.length fhs2 = 32} -> Lemma (requires mt_hashes_lth_inv lv j fhs1 /\ S.equal (S.slice fhs1 lv 32) (S.slice fhs2 lv 32)) (ensures mt_hashes_lth_inv #hsz lv j fhs2) (decreases (32 - lv)) let rec mt_hashes_lth_inv_equiv #hsz #f lv j fhs1 fhs2 = if lv = 31 then () else (assert (S.index fhs1 lv == S.index fhs2 lv); mt_hashes_lth_inv_equiv #_ #f (lv + 1) (j / 2) fhs1 fhs2) #pop-options #push-options "--max_fuel 1" val mt_hashes_inv_equiv: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> lv:nat{lv < 32} -> j:nat{j < pow2 (32 - lv)} -> fhs1:hashess #hsz {S.length fhs1 = 32 /\ mt_hashes_lth_inv lv j fhs1} -> fhs2:hashess #hsz {S.length fhs2 = 32 /\ mt_hashes_lth_inv lv j fhs2} -> Lemma (requires mt_hashes_inv #_ #f lv j fhs1 /\ S.equal (S.slice fhs1 lv 32) (S.slice fhs2 lv 32)) (ensures mt_hashes_inv #_ #f lv j fhs2) (decreases (32 - lv)) let rec mt_hashes_inv_equiv #hsz #f lv j fhs1 fhs2 = if lv = 31 then () else (assert (S.index fhs1 lv == S.index fhs2 lv); assert (S.index fhs1 (lv + 1) == S.index fhs2 (lv + 1)); mt_hashes_inv_equiv #_ #f (lv + 1) (j / 2) fhs1 fhs2) val merge_hs: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> hs1:hashess #hsz -> hs2:hashess #hsz {S.length hs1 = S.length hs2} -> GTot (mhs:hashess #hsz {S.length mhs = S.length hs1}) (decreases (S.length hs1)) let rec merge_hs #hsz #f hs1 hs2 = if S.length hs1 = 0 then S.empty else (S.cons (S.append (S.head hs1) (S.head hs2)) (merge_hs #_ #f (S.tail hs1) (S.tail hs2))) val merge_hs_empty: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> len:nat -> Lemma (S.equal (merge_hs #_ #f (empty_hashes #hsz len) (empty_hashes #hsz len)) (empty_hashes #hsz len)) let rec merge_hs_empty #hsz #f len = if len = 0 then () else (empty_hashes_head #hsz len; empty_hashes_tail #hsz len; assert (S.equal (S.append #(hash #hsz) S.empty S.empty) (S.empty #(hash #hsz))); assert (S.equal (merge_hs #_ #f (empty_hashes len) (empty_hashes len)) (S.cons S.empty (merge_hs #_ #f (empty_hashes (len - 1)) (empty_hashes (len - 1))))); merge_hs_empty #_ #f (len - 1)) val merge_hs_index: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> hs1:hashess -> hs2:hashess{S.length hs1 = S.length hs2} -> i:nat{i < S.length hs1} -> Lemma (requires True) (ensures S.equal (S.index (merge_hs #_ #f hs1 hs2) i) (S.append (S.index hs1 i) (S.index hs2 i))) (decreases (S.length hs1)) [SMTPat (S.index (merge_hs #_ #f hs1 hs2) i)] let rec merge_hs_index #hsz #f hs1 hs2 i = if S.length hs1 = 0 then () else if i = 0 then () else merge_hs_index #_ #f (S.tail hs1) (S.tail hs2) (i - 1) val merge_hs_slice_equal: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> ahs1:hashess #hsz -> ahs2:hashess #hsz {S.length ahs1 = S.length ahs2} -> bhs1:hashess #hsz -> bhs2:hashess #hsz {S.length bhs1 = S.length bhs2} -> i:nat -> j:nat{i <= j && j <= S.length ahs1 && j <= S.length bhs1} -> Lemma (requires S.equal (S.slice ahs1 i j) (S.slice bhs1 i j) /\ S.equal (S.slice ahs2 i j) (S.slice bhs2 i j)) (ensures S.equal (S.slice (merge_hs #_ #f ahs1 ahs2) i j) (S.slice (merge_hs #_ #f bhs1 bhs2) i j))
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "MerkleTree.Spec.fst.checked", "MerkleTree.New.High.fst.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Ghost.fsti.checked", "FStar.Classical.fsti.checked" ], "interface_file": false, "source_file": "MerkleTree.New.High.Correct.Base.fst" }
[ { "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": 2, "initial_ifuel": 1, "max_fuel": 1, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 40, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
ahs1: MerkleTree.New.High.hashess -> ahs2: MerkleTree.New.High.hashess{FStar.Seq.Base.length ahs1 = FStar.Seq.Base.length ahs2} -> bhs1: MerkleTree.New.High.hashess -> bhs2: MerkleTree.New.High.hashess{FStar.Seq.Base.length bhs1 = FStar.Seq.Base.length bhs2} -> i: Prims.nat -> j: Prims.nat{i <= j && j <= FStar.Seq.Base.length ahs1 && j <= FStar.Seq.Base.length bhs1} -> FStar.Pervasives.Lemma (requires FStar.Seq.Base.equal (FStar.Seq.Base.slice ahs1 i j) (FStar.Seq.Base.slice bhs1 i j) /\ FStar.Seq.Base.equal (FStar.Seq.Base.slice ahs2 i j) (FStar.Seq.Base.slice bhs2 i j)) (ensures FStar.Seq.Base.equal (FStar.Seq.Base.slice (MerkleTree.New.High.Correct.Base.merge_hs ahs1 ahs2) i j) (FStar.Seq.Base.slice (MerkleTree.New.High.Correct.Base.merge_hs bhs1 bhs2) i j)) (decreases j - i)
FStar.Pervasives.Lemma
[ "lemma", "" ]
[]
[ "Prims.pos", "MerkleTree.Spec.hash_fun_t", "MerkleTree.New.High.hashess", "Prims.b2t", "Prims.op_Equality", "Prims.nat", "FStar.Seq.Base.length", "MerkleTree.New.High.hashes", "Prims.op_AmpAmp", "Prims.op_LessThanOrEqual", "Prims.bool", "MerkleTree.New.High.Correct.Base.merge_hs_slice_equal", "Prims.op_Addition", "Prims.unit", "Prims._assert", "Prims.eq2", "FStar.Seq.Base.index" ]
[ "recursion" ]
false
false
true
false
false
let rec merge_hs_slice_equal #_ #f ahs1 ahs2 bhs1 bhs2 i j =
if i = j then () else (assert (S.index ahs1 i == S.index bhs1 i); assert (S.index ahs2 i == S.index bhs2 i); merge_hs_slice_equal #_ #f ahs1 ahs2 bhs1 bhs2 (i + 1) j)
false
MerkleTree.New.High.Correct.Base.fst
MerkleTree.New.High.Correct.Base.merge_hs_upd
val merge_hs_upd: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> hs1:hashess #hsz -> hs2:hashess #hsz {S.length hs1 = S.length hs2} -> i:nat{i < S.length hs1} -> v1:hashes #hsz -> v2:hashes #hsz -> Lemma (requires S.equal (S.append (S.index hs1 i) (S.index hs2 i)) (S.append v1 v2)) (ensures S.equal (merge_hs #_ #f hs1 hs2) (merge_hs #_ #f (S.upd hs1 i v1) (S.upd hs2 i v2))) (decreases i)
val merge_hs_upd: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> hs1:hashess #hsz -> hs2:hashess #hsz {S.length hs1 = S.length hs2} -> i:nat{i < S.length hs1} -> v1:hashes #hsz -> v2:hashes #hsz -> Lemma (requires S.equal (S.append (S.index hs1 i) (S.index hs2 i)) (S.append v1 v2)) (ensures S.equal (merge_hs #_ #f hs1 hs2) (merge_hs #_ #f (S.upd hs1 i v1) (S.upd hs2 i v2))) (decreases i)
let rec merge_hs_upd #_ #f hs1 hs2 i v1 v2 = if S.length hs1 = 0 then () else if i = 0 then () else merge_hs_upd #_ #f (S.tail hs1) (S.tail hs2) (i - 1) v1 v2
{ "file_name": "src/MerkleTree.New.High.Correct.Base.fst", "git_rev": "7d7bdc20f2033171e279c176b26e84f9069d23c6", "git_url": "https://github.com/hacl-star/merkle-tree.git", "project_name": "merkle-tree" }
{ "end_col": 65, "end_line": 222, "start_col": 0, "start_line": 219 }
module MerkleTree.New.High.Correct.Base open FStar.Classical open FStar.Ghost open FStar.Seq module S = FStar.Seq module MTS = MerkleTree.Spec open MerkleTree.New.High #set-options "--z3rlimit 40 --max_fuel 0 --max_ifuel 0" /// Sequence helpers val seq_prefix: #a:Type -> s1:S.seq a -> s2:S.seq a{S.length s1 <= S.length s2} -> GTot Type0 let seq_prefix #a s1 s2 = S.equal s1 (S.slice s2 0 (S.length s1)) val seq_head_cons: #a:Type -> x:a -> s:S.seq a -> Lemma (S.head (S.cons x s) == x) [SMTPat (S.cons x s)] let seq_head_cons #a x s = () val seq_tail_cons: #a:Type -> x:a -> s:S.seq a -> Lemma (S.equal (S.tail (S.cons x s)) s) [SMTPat (S.cons x s)] let seq_tail_cons #a x s = () /// Invariants and simulation relation of high-level Merkle tree design // Invariants of internal hashes val empty_hashes: (#hsz:pos) -> (len:nat) -> GTot (hs:hashess #hsz {S.length hs = len}) let empty_hashes #hsz len = S.create len S.empty val empty_hashes_head: #hsz:pos -> len:nat{len > 0} -> Lemma (S.head (empty_hashes #hsz len) == S.empty) let empty_hashes_head #_ _ = () val empty_hashes_tail: #hsz:pos -> len:nat{len > 0} -> Lemma (S.equal (S.tail (empty_hashes len)) (empty_hashes #hsz (len - 1))) let empty_hashes_tail #_ _ = () #push-options "--max_fuel 1" val mt_hashes_lth_inv: #hsz:pos -> lv:nat{lv <= 32} -> j:nat{j < pow2 (32 - lv)} -> fhs:hashess #hsz {S.length fhs = 32} -> GTot Type0 (decreases (32 - lv)) let rec mt_hashes_lth_inv #hsz lv j fhs = if lv = 32 then true else (S.length (S.index fhs lv) == j /\ mt_hashes_lth_inv (lv + 1) (j / 2) fhs) val mt_hashes_lth_inv_empty: #hsz:pos -> lv:nat{lv <= 32} -> Lemma (requires True) (ensures mt_hashes_lth_inv lv 0 (empty_hashes #hsz 32)) (decreases (32 - lv)) let rec mt_hashes_lth_inv_empty #hsz lv = if lv = 32 then () else mt_hashes_lth_inv_empty #hsz (lv + 1) val mt_hashes_next_rel: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> j:nat -> hs:hashes #hsz {S.length hs = j} -> nhs:hashes #hsz {S.length nhs = j / 2} -> GTot Type0 let mt_hashes_next_rel #hsz #f j hs nhs = forall (i:nat{i < j / 2}). S.index nhs i == f (S.index hs (op_Multiply 2 i)) (S.index hs (op_Multiply 2 i + 1)) #pop-options #push-options "--max_fuel 2" val mt_hashes_inv: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> lv:nat{lv < 32} -> j:nat{j < pow2 (32 - lv)} -> fhs:hashess #hsz {S.length fhs = 32 /\ mt_hashes_lth_inv lv j fhs} -> GTot Type0 (decreases (32 - lv)) let rec mt_hashes_inv #hsz #f lv j fhs = if lv = 31 then true else (mt_hashes_next_rel #_ #f j (S.index fhs lv) (S.index fhs (lv + 1)) /\ mt_hashes_inv #_ #f (lv + 1) (j / 2) fhs) val mt_hashes_inv_empty: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> lv:nat{lv < 32} -> Lemma (requires True) (ensures (mt_hashes_lth_inv_empty #hsz lv; mt_hashes_inv #hsz #f lv 0 (empty_hashes #hsz 32))) (decreases (32 - lv)) let rec mt_hashes_inv_empty #hsz #f lv = if lv = 31 then () else (mt_hashes_lth_inv_empty #hsz (lv + 1); mt_hashes_inv_empty #_ #f (lv + 1)) val mt_hashes_lth_inv_equiv: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> lv:nat{lv < 32} -> j:nat{j < pow2 (32 - lv)} -> fhs1:hashess{S.length fhs1 = 32} -> fhs2:hashess{S.length fhs2 = 32} -> Lemma (requires mt_hashes_lth_inv lv j fhs1 /\ S.equal (S.slice fhs1 lv 32) (S.slice fhs2 lv 32)) (ensures mt_hashes_lth_inv #hsz lv j fhs2) (decreases (32 - lv)) let rec mt_hashes_lth_inv_equiv #hsz #f lv j fhs1 fhs2 = if lv = 31 then () else (assert (S.index fhs1 lv == S.index fhs2 lv); mt_hashes_lth_inv_equiv #_ #f (lv + 1) (j / 2) fhs1 fhs2) #pop-options #push-options "--max_fuel 1" val mt_hashes_inv_equiv: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> lv:nat{lv < 32} -> j:nat{j < pow2 (32 - lv)} -> fhs1:hashess #hsz {S.length fhs1 = 32 /\ mt_hashes_lth_inv lv j fhs1} -> fhs2:hashess #hsz {S.length fhs2 = 32 /\ mt_hashes_lth_inv lv j fhs2} -> Lemma (requires mt_hashes_inv #_ #f lv j fhs1 /\ S.equal (S.slice fhs1 lv 32) (S.slice fhs2 lv 32)) (ensures mt_hashes_inv #_ #f lv j fhs2) (decreases (32 - lv)) let rec mt_hashes_inv_equiv #hsz #f lv j fhs1 fhs2 = if lv = 31 then () else (assert (S.index fhs1 lv == S.index fhs2 lv); assert (S.index fhs1 (lv + 1) == S.index fhs2 (lv + 1)); mt_hashes_inv_equiv #_ #f (lv + 1) (j / 2) fhs1 fhs2) val merge_hs: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> hs1:hashess #hsz -> hs2:hashess #hsz {S.length hs1 = S.length hs2} -> GTot (mhs:hashess #hsz {S.length mhs = S.length hs1}) (decreases (S.length hs1)) let rec merge_hs #hsz #f hs1 hs2 = if S.length hs1 = 0 then S.empty else (S.cons (S.append (S.head hs1) (S.head hs2)) (merge_hs #_ #f (S.tail hs1) (S.tail hs2))) val merge_hs_empty: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> len:nat -> Lemma (S.equal (merge_hs #_ #f (empty_hashes #hsz len) (empty_hashes #hsz len)) (empty_hashes #hsz len)) let rec merge_hs_empty #hsz #f len = if len = 0 then () else (empty_hashes_head #hsz len; empty_hashes_tail #hsz len; assert (S.equal (S.append #(hash #hsz) S.empty S.empty) (S.empty #(hash #hsz))); assert (S.equal (merge_hs #_ #f (empty_hashes len) (empty_hashes len)) (S.cons S.empty (merge_hs #_ #f (empty_hashes (len - 1)) (empty_hashes (len - 1))))); merge_hs_empty #_ #f (len - 1)) val merge_hs_index: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> hs1:hashess -> hs2:hashess{S.length hs1 = S.length hs2} -> i:nat{i < S.length hs1} -> Lemma (requires True) (ensures S.equal (S.index (merge_hs #_ #f hs1 hs2) i) (S.append (S.index hs1 i) (S.index hs2 i))) (decreases (S.length hs1)) [SMTPat (S.index (merge_hs #_ #f hs1 hs2) i)] let rec merge_hs_index #hsz #f hs1 hs2 i = if S.length hs1 = 0 then () else if i = 0 then () else merge_hs_index #_ #f (S.tail hs1) (S.tail hs2) (i - 1) val merge_hs_slice_equal: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> ahs1:hashess #hsz -> ahs2:hashess #hsz {S.length ahs1 = S.length ahs2} -> bhs1:hashess #hsz -> bhs2:hashess #hsz {S.length bhs1 = S.length bhs2} -> i:nat -> j:nat{i <= j && j <= S.length ahs1 && j <= S.length bhs1} -> Lemma (requires S.equal (S.slice ahs1 i j) (S.slice bhs1 i j) /\ S.equal (S.slice ahs2 i j) (S.slice bhs2 i j)) (ensures S.equal (S.slice (merge_hs #_ #f ahs1 ahs2) i j) (S.slice (merge_hs #_ #f bhs1 bhs2) i j)) (decreases (j - i)) let rec merge_hs_slice_equal #_ #f ahs1 ahs2 bhs1 bhs2 i j = if i = j then () else (assert (S.index ahs1 i == S.index bhs1 i); assert (S.index ahs2 i == S.index bhs2 i); merge_hs_slice_equal #_ #f ahs1 ahs2 bhs1 bhs2 (i + 1) j) val merge_hs_upd: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> hs1:hashess #hsz -> hs2:hashess #hsz {S.length hs1 = S.length hs2} -> i:nat{i < S.length hs1} -> v1:hashes #hsz -> v2:hashes #hsz -> Lemma (requires S.equal (S.append (S.index hs1 i) (S.index hs2 i)) (S.append v1 v2)) (ensures S.equal (merge_hs #_ #f hs1 hs2) (merge_hs #_ #f (S.upd hs1 i v1) (S.upd hs2 i v2)))
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "MerkleTree.Spec.fst.checked", "MerkleTree.New.High.fst.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Ghost.fsti.checked", "FStar.Classical.fsti.checked" ], "interface_file": false, "source_file": "MerkleTree.New.High.Correct.Base.fst" }
[ { "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": 2, "initial_ifuel": 1, "max_fuel": 1, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 40, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
hs1: MerkleTree.New.High.hashess -> hs2: MerkleTree.New.High.hashess{FStar.Seq.Base.length hs1 = FStar.Seq.Base.length hs2} -> i: Prims.nat{i < FStar.Seq.Base.length hs1} -> v1: MerkleTree.New.High.hashes -> v2: MerkleTree.New.High.hashes -> FStar.Pervasives.Lemma (requires FStar.Seq.Base.equal (FStar.Seq.Base.append (FStar.Seq.Base.index hs1 i) (FStar.Seq.Base.index hs2 i)) (FStar.Seq.Base.append v1 v2)) (ensures FStar.Seq.Base.equal (MerkleTree.New.High.Correct.Base.merge_hs hs1 hs2) (MerkleTree.New.High.Correct.Base.merge_hs (FStar.Seq.Base.upd hs1 i v1) (FStar.Seq.Base.upd hs2 i v2))) (decreases i)
FStar.Pervasives.Lemma
[ "lemma", "" ]
[]
[ "Prims.pos", "MerkleTree.Spec.hash_fun_t", "MerkleTree.New.High.hashess", "Prims.b2t", "Prims.op_Equality", "Prims.nat", "FStar.Seq.Base.length", "MerkleTree.New.High.hashes", "Prims.op_LessThan", "Prims.int", "Prims.bool", "MerkleTree.New.High.Correct.Base.merge_hs_upd", "FStar.Seq.Properties.tail", "Prims.op_Subtraction", "Prims.unit" ]
[ "recursion" ]
false
false
true
false
false
let rec merge_hs_upd #_ #f hs1 hs2 i v1 v2 =
if S.length hs1 = 0 then () else if i = 0 then () else merge_hs_upd #_ #f (S.tail hs1) (S.tail hs2) (i - 1) v1 v2
false
MerkleTree.New.High.Correct.Base.fst
MerkleTree.New.High.Correct.Base.mt_olds_hs_inv
val mt_olds_hs_inv: #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 #hsz lv hs i j} -> GTot Type0
val mt_olds_hs_inv: #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 #hsz lv hs i j} -> GTot Type0
let mt_olds_hs_inv #hsz #f lv i j olds hs = mt_olds_hs_lth_inv_ok #_ #f lv i j olds hs; mt_hashes_inv #_ #f lv j (merge_hs #_ #f olds hs)
{ "file_name": "src/MerkleTree.New.High.Correct.Base.fst", "git_rev": "7d7bdc20f2033171e279c176b26e84f9069d23c6", "git_url": "https://github.com/hacl-star/merkle-tree.git", "project_name": "merkle-tree" }
{ "end_col": 51, "end_line": 275, "start_col": 0, "start_line": 273 }
module MerkleTree.New.High.Correct.Base open FStar.Classical open FStar.Ghost open FStar.Seq module S = FStar.Seq module MTS = MerkleTree.Spec open MerkleTree.New.High #set-options "--z3rlimit 40 --max_fuel 0 --max_ifuel 0" /// Sequence helpers val seq_prefix: #a:Type -> s1:S.seq a -> s2:S.seq a{S.length s1 <= S.length s2} -> GTot Type0 let seq_prefix #a s1 s2 = S.equal s1 (S.slice s2 0 (S.length s1)) val seq_head_cons: #a:Type -> x:a -> s:S.seq a -> Lemma (S.head (S.cons x s) == x) [SMTPat (S.cons x s)] let seq_head_cons #a x s = () val seq_tail_cons: #a:Type -> x:a -> s:S.seq a -> Lemma (S.equal (S.tail (S.cons x s)) s) [SMTPat (S.cons x s)] let seq_tail_cons #a x s = () /// Invariants and simulation relation of high-level Merkle tree design // Invariants of internal hashes val empty_hashes: (#hsz:pos) -> (len:nat) -> GTot (hs:hashess #hsz {S.length hs = len}) let empty_hashes #hsz len = S.create len S.empty val empty_hashes_head: #hsz:pos -> len:nat{len > 0} -> Lemma (S.head (empty_hashes #hsz len) == S.empty) let empty_hashes_head #_ _ = () val empty_hashes_tail: #hsz:pos -> len:nat{len > 0} -> Lemma (S.equal (S.tail (empty_hashes len)) (empty_hashes #hsz (len - 1))) let empty_hashes_tail #_ _ = () #push-options "--max_fuel 1" val mt_hashes_lth_inv: #hsz:pos -> lv:nat{lv <= 32} -> j:nat{j < pow2 (32 - lv)} -> fhs:hashess #hsz {S.length fhs = 32} -> GTot Type0 (decreases (32 - lv)) let rec mt_hashes_lth_inv #hsz lv j fhs = if lv = 32 then true else (S.length (S.index fhs lv) == j /\ mt_hashes_lth_inv (lv + 1) (j / 2) fhs) val mt_hashes_lth_inv_empty: #hsz:pos -> lv:nat{lv <= 32} -> Lemma (requires True) (ensures mt_hashes_lth_inv lv 0 (empty_hashes #hsz 32)) (decreases (32 - lv)) let rec mt_hashes_lth_inv_empty #hsz lv = if lv = 32 then () else mt_hashes_lth_inv_empty #hsz (lv + 1) val mt_hashes_next_rel: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> j:nat -> hs:hashes #hsz {S.length hs = j} -> nhs:hashes #hsz {S.length nhs = j / 2} -> GTot Type0 let mt_hashes_next_rel #hsz #f j hs nhs = forall (i:nat{i < j / 2}). S.index nhs i == f (S.index hs (op_Multiply 2 i)) (S.index hs (op_Multiply 2 i + 1)) #pop-options #push-options "--max_fuel 2" val mt_hashes_inv: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> lv:nat{lv < 32} -> j:nat{j < pow2 (32 - lv)} -> fhs:hashess #hsz {S.length fhs = 32 /\ mt_hashes_lth_inv lv j fhs} -> GTot Type0 (decreases (32 - lv)) let rec mt_hashes_inv #hsz #f lv j fhs = if lv = 31 then true else (mt_hashes_next_rel #_ #f j (S.index fhs lv) (S.index fhs (lv + 1)) /\ mt_hashes_inv #_ #f (lv + 1) (j / 2) fhs) val mt_hashes_inv_empty: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> lv:nat{lv < 32} -> Lemma (requires True) (ensures (mt_hashes_lth_inv_empty #hsz lv; mt_hashes_inv #hsz #f lv 0 (empty_hashes #hsz 32))) (decreases (32 - lv)) let rec mt_hashes_inv_empty #hsz #f lv = if lv = 31 then () else (mt_hashes_lth_inv_empty #hsz (lv + 1); mt_hashes_inv_empty #_ #f (lv + 1)) val mt_hashes_lth_inv_equiv: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> lv:nat{lv < 32} -> j:nat{j < pow2 (32 - lv)} -> fhs1:hashess{S.length fhs1 = 32} -> fhs2:hashess{S.length fhs2 = 32} -> Lemma (requires mt_hashes_lth_inv lv j fhs1 /\ S.equal (S.slice fhs1 lv 32) (S.slice fhs2 lv 32)) (ensures mt_hashes_lth_inv #hsz lv j fhs2) (decreases (32 - lv)) let rec mt_hashes_lth_inv_equiv #hsz #f lv j fhs1 fhs2 = if lv = 31 then () else (assert (S.index fhs1 lv == S.index fhs2 lv); mt_hashes_lth_inv_equiv #_ #f (lv + 1) (j / 2) fhs1 fhs2) #pop-options #push-options "--max_fuel 1" val mt_hashes_inv_equiv: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> lv:nat{lv < 32} -> j:nat{j < pow2 (32 - lv)} -> fhs1:hashess #hsz {S.length fhs1 = 32 /\ mt_hashes_lth_inv lv j fhs1} -> fhs2:hashess #hsz {S.length fhs2 = 32 /\ mt_hashes_lth_inv lv j fhs2} -> Lemma (requires mt_hashes_inv #_ #f lv j fhs1 /\ S.equal (S.slice fhs1 lv 32) (S.slice fhs2 lv 32)) (ensures mt_hashes_inv #_ #f lv j fhs2) (decreases (32 - lv)) let rec mt_hashes_inv_equiv #hsz #f lv j fhs1 fhs2 = if lv = 31 then () else (assert (S.index fhs1 lv == S.index fhs2 lv); assert (S.index fhs1 (lv + 1) == S.index fhs2 (lv + 1)); mt_hashes_inv_equiv #_ #f (lv + 1) (j / 2) fhs1 fhs2) val merge_hs: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> hs1:hashess #hsz -> hs2:hashess #hsz {S.length hs1 = S.length hs2} -> GTot (mhs:hashess #hsz {S.length mhs = S.length hs1}) (decreases (S.length hs1)) let rec merge_hs #hsz #f hs1 hs2 = if S.length hs1 = 0 then S.empty else (S.cons (S.append (S.head hs1) (S.head hs2)) (merge_hs #_ #f (S.tail hs1) (S.tail hs2))) val merge_hs_empty: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> len:nat -> Lemma (S.equal (merge_hs #_ #f (empty_hashes #hsz len) (empty_hashes #hsz len)) (empty_hashes #hsz len)) let rec merge_hs_empty #hsz #f len = if len = 0 then () else (empty_hashes_head #hsz len; empty_hashes_tail #hsz len; assert (S.equal (S.append #(hash #hsz) S.empty S.empty) (S.empty #(hash #hsz))); assert (S.equal (merge_hs #_ #f (empty_hashes len) (empty_hashes len)) (S.cons S.empty (merge_hs #_ #f (empty_hashes (len - 1)) (empty_hashes (len - 1))))); merge_hs_empty #_ #f (len - 1)) val merge_hs_index: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> hs1:hashess -> hs2:hashess{S.length hs1 = S.length hs2} -> i:nat{i < S.length hs1} -> Lemma (requires True) (ensures S.equal (S.index (merge_hs #_ #f hs1 hs2) i) (S.append (S.index hs1 i) (S.index hs2 i))) (decreases (S.length hs1)) [SMTPat (S.index (merge_hs #_ #f hs1 hs2) i)] let rec merge_hs_index #hsz #f hs1 hs2 i = if S.length hs1 = 0 then () else if i = 0 then () else merge_hs_index #_ #f (S.tail hs1) (S.tail hs2) (i - 1) val merge_hs_slice_equal: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> ahs1:hashess #hsz -> ahs2:hashess #hsz {S.length ahs1 = S.length ahs2} -> bhs1:hashess #hsz -> bhs2:hashess #hsz {S.length bhs1 = S.length bhs2} -> i:nat -> j:nat{i <= j && j <= S.length ahs1 && j <= S.length bhs1} -> Lemma (requires S.equal (S.slice ahs1 i j) (S.slice bhs1 i j) /\ S.equal (S.slice ahs2 i j) (S.slice bhs2 i j)) (ensures S.equal (S.slice (merge_hs #_ #f ahs1 ahs2) i j) (S.slice (merge_hs #_ #f bhs1 bhs2) i j)) (decreases (j - i)) let rec merge_hs_slice_equal #_ #f ahs1 ahs2 bhs1 bhs2 i j = if i = j then () else (assert (S.index ahs1 i == S.index bhs1 i); assert (S.index ahs2 i == S.index bhs2 i); merge_hs_slice_equal #_ #f ahs1 ahs2 bhs1 bhs2 (i + 1) j) val merge_hs_upd: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> hs1:hashess #hsz -> hs2:hashess #hsz {S.length hs1 = S.length hs2} -> i:nat{i < S.length hs1} -> v1:hashes #hsz -> v2:hashes #hsz -> Lemma (requires S.equal (S.append (S.index hs1 i) (S.index hs2 i)) (S.append v1 v2)) (ensures S.equal (merge_hs #_ #f hs1 hs2) (merge_hs #_ #f (S.upd hs1 i v1) (S.upd hs2 i v2))) (decreases i) let rec merge_hs_upd #_ #f hs1 hs2 i v1 v2 = if S.length hs1 = 0 then () else if i = 0 then () else merge_hs_upd #_ #f (S.tail hs1) (S.tail hs2) (i - 1) v1 v2 val mt_olds_inv: #hsz:pos -> lv:nat{lv <= 32} -> i:nat -> olds:hashess #hsz {S.length olds = 32} -> GTot Type0 (decreases (32 - lv)) let rec mt_olds_inv #hsz lv i olds = if lv = 32 then true else (let ofs = offset_of i in S.length (S.index olds lv) == ofs /\ mt_olds_inv #hsz (lv + 1) (i / 2) olds) val mt_olds_inv_equiv: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> lv:nat{lv <= 32} -> i:nat -> olds1:hashess #hsz {S.length olds1 = 32} -> olds2:hashess #hsz {S.length olds2 = 32} -> Lemma (requires mt_olds_inv #hsz lv i olds1 /\ S.equal (S.slice olds1 lv 32) (S.slice olds2 lv 32)) (ensures mt_olds_inv #hsz lv i olds2) (decreases (32 - lv)) let rec mt_olds_inv_equiv #hsz #f lv i olds1 olds2 = if lv = 32 then () else (assert (S.index olds1 lv == S.index olds2 lv); mt_olds_inv_equiv #_ #f (lv + 1) (i / 2) olds1 olds2) val mt_olds_hs_lth_inv_ok: #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 #hsz lv hs i j} -> Lemma (requires True) (ensures mt_hashes_lth_inv #hsz lv j (merge_hs #_ #f olds hs)) (decreases (32 - lv)) let rec mt_olds_hs_lth_inv_ok #hsz #f lv i j olds hs = if lv = 32 then () else (mt_olds_hs_lth_inv_ok #_ #f (lv + 1) (i / 2) (j / 2) olds hs) val mt_olds_hs_inv: #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 #hsz lv hs i j} ->
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "MerkleTree.Spec.fst.checked", "MerkleTree.New.High.fst.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Ghost.fsti.checked", "FStar.Classical.fsti.checked" ], "interface_file": false, "source_file": "MerkleTree.New.High.Correct.Base.fst" }
[ { "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": 2, "initial_ifuel": 1, "max_fuel": 1, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 40, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
lv: Prims.nat{lv < 32} -> i: Prims.nat -> j: Prims.nat{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} -> Prims.GTot Type0
Prims.GTot
[ "sometrivial" ]
[]
[ "Prims.pos", "MerkleTree.Spec.hash_fun_t", "Prims.nat", "Prims.b2t", "Prims.op_LessThan", "Prims.l_and", "Prims.op_LessThanOrEqual", "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.Correct.Base.mt_hashes_inv", "MerkleTree.New.High.Correct.Base.merge_hs", "Prims.unit", "MerkleTree.New.High.Correct.Base.mt_olds_hs_lth_inv_ok" ]
[]
false
false
false
false
true
let mt_olds_hs_inv #hsz #f lv i j olds hs =
mt_olds_hs_lth_inv_ok #_ #f lv i j olds hs; mt_hashes_inv #_ #f lv j (merge_hs #_ #f olds hs)
false
Vale.Stdcalls.X64.GCTR.fst
Vale.Stdcalls.X64.GCTR.gctr128_lemma
val gctr128_lemma : s: FStar.Ghost.erased (FStar.Seq.Base.seq Vale.Def.Types_s.nat32) -> Vale.AsLowStar.ValeSig.vale_sig_stdcall (Vale.Stdcalls.X64.GCTR.gctr128_pre s) (Vale.Stdcalls.X64.GCTR.gctr128_post s)
let gctr128_lemma (s:Ghost.erased (Seq.seq nat32)) = as_t #(VSig.vale_sig_stdcall (gctr128_pre s) (gctr128_post s)) (gctr128_lemma' s)
{ "file_name": "vale/code/arch/x64/interop/Vale.Stdcalls.X64.GCTR.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 135, "end_line": 128, "start_col": 0, "start_line": 128 }
module Vale.Stdcalls.X64.GCTR open FStar.HyperStack.ST module B = LowStar.Buffer module HS = FStar.HyperStack open FStar.Mul module DV = LowStar.BufferView.Down module UV = LowStar.BufferView.Up open Vale.Def.Types_s open Vale.Interop.Base module IX64 = Vale.Interop.X64 module VSig = Vale.AsLowStar.ValeSig module LSig = Vale.AsLowStar.LowStarSig module ME = Vale.X64.Memory module V = Vale.X64.Decls module IA = Vale.Interop.Assumptions module W = Vale.AsLowStar.Wrapper open Vale.X64.MemoryAdapters module VS = Vale.X64.State module MS = Vale.X64.Machine_s open Vale.AES.AES_s module GC = Vale.AES.X64.GCTR let uint64 = UInt64.t (* A little utility to trigger normalization in types *) noextract let as_t (#a:Type) (x:normal a) : a = x noextract let as_normal_t (#a:Type) (x:a) : normal a = x [@__reduce__] noextract let b128 = buf_t TUInt8 TUInt128 [@__reduce__] noextract let t128_mod = TD_Buffer TUInt8 TUInt128 default_bq [@__reduce__] noextract let t128_no_mod = TD_Buffer TUInt8 TUInt128 ({modified=false; strict_disjointness=false; taint=MS.Secret}) [@__reduce__] noextract let tuint64 = TD_Base TUInt64 [@__reduce__] noextract let (dom: list td{List.length dom <= 20}) = let y = [t128_no_mod; tuint64; t128_mod; t128_mod; t128_no_mod; t128_no_mod; tuint64] in assert_norm (List.length y = 7); y (* Need to rearrange the order of arguments *) [@__reduce__] noextract let gctr128_pre : (Ghost.erased (Seq.seq nat32)) -> VSig.vale_pre dom = fun (s:Ghost.erased (Seq.seq nat32)) (c:V.va_code) (in_b:b128) (num_bytes:uint64) (out_b:b128) (inout_b:b128) (keys_b:b128) (ctr_b:b128) (num_blocks:uint64) (va_s0:V.va_state) -> GC.va_req_Gctr_bytes_stdcall c va_s0 IA.win AES_128 (as_vale_buffer in_b) (UInt64.v num_bytes) (as_vale_buffer out_b) (as_vale_buffer inout_b) (as_vale_buffer keys_b) (as_vale_buffer ctr_b) (UInt64.v num_blocks) (Ghost.reveal s) (* Need to rearrange the order of arguments *) [@__reduce__] noextract let gctr128_post : (Ghost.erased (Seq.seq nat32)) -> VSig.vale_post dom = fun (s:Ghost.erased (Seq.seq nat32)) (c:V.va_code) (in_b:b128) (num_bytes:uint64) (out_b:b128) (inout_b:b128) (keys_b:b128) (ctr_b:b128) (num_blocks:uint64) (va_s0:V.va_state) (va_s1:V.va_state) (f:V.va_fuel) -> GC.va_ens_Gctr_bytes_stdcall c va_s0 IA.win AES_128 (as_vale_buffer in_b) (UInt64.v num_bytes) (as_vale_buffer out_b) (as_vale_buffer inout_b) (as_vale_buffer keys_b) (as_vale_buffer ctr_b) (UInt64.v num_blocks) (Ghost.reveal s) va_s1 f #set-options "--z3rlimit 20" [@__reduce__] noextract let gctr128_lemma' (s:Ghost.erased (Seq.seq nat32)) (code:V.va_code) (_win:bool) (in_b:b128) (num_bytes:uint64) (out_b:b128) (inout_b:b128) (keys_b:b128) (ctr_b:b128) (num_blocks:uint64) (va_s0:V.va_state) : Ghost (V.va_state & V.va_fuel) (requires gctr128_pre s code in_b num_bytes out_b inout_b keys_b ctr_b num_blocks va_s0) (ensures (fun (va_s1, f) -> V.eval_code code va_s0 f va_s1 /\ VSig.vale_calling_conventions_stdcall va_s0 va_s1 /\ gctr128_post s code in_b num_bytes out_b inout_b keys_b ctr_b num_blocks va_s0 va_s1 f /\ ME.buffer_writeable (as_vale_buffer in_b) /\ ME.buffer_writeable (as_vale_buffer keys_b) /\ ME.buffer_writeable (as_vale_buffer ctr_b) /\ ME.buffer_writeable (as_vale_buffer inout_b) /\ ME.buffer_writeable (as_vale_buffer out_b) )) = let va_s1, f = GC.va_lemma_Gctr_bytes_stdcall code va_s0 IA.win AES_128 (as_vale_buffer in_b) (UInt64.v num_bytes) (as_vale_buffer out_b) (as_vale_buffer inout_b) (as_vale_buffer keys_b) (as_vale_buffer ctr_b) (UInt64.v num_blocks) (Ghost.reveal s) in Vale.AsLowStar.MemoryHelpers.buffer_writeable_reveal ME.TUInt8 ME.TUInt128 in_b; Vale.AsLowStar.MemoryHelpers.buffer_writeable_reveal ME.TUInt8 ME.TUInt128 out_b; Vale.AsLowStar.MemoryHelpers.buffer_writeable_reveal ME.TUInt8 ME.TUInt128 inout_b; Vale.AsLowStar.MemoryHelpers.buffer_writeable_reveal ME.TUInt8 ME.TUInt128 keys_b; Vale.AsLowStar.MemoryHelpers.buffer_writeable_reveal ME.TUInt8 ME.TUInt128 ctr_b; (va_s1, f)
{ "checked_file": "/", "dependencies": [ "Vale.X64.State.fsti.checked", "Vale.X64.MemoryAdapters.fsti.checked", "Vale.X64.Memory.fsti.checked", "Vale.X64.Machine_s.fst.checked", "Vale.X64.Decls.fsti.checked", "Vale.Interop.X64.fsti.checked", "Vale.Interop.Base.fst.checked", "Vale.Interop.Assumptions.fst.checked", "Vale.Def.Types_s.fst.checked", "Vale.AsLowStar.Wrapper.fsti.checked", "Vale.AsLowStar.ValeSig.fst.checked", "Vale.AsLowStar.MemoryHelpers.fsti.checked", "Vale.AsLowStar.LowStarSig.fst.checked", "Vale.AES.X64.GCTR.fsti.checked", "Vale.AES.AES_s.fst.checked", "prims.fst.checked", "LowStar.BufferView.Up.fsti.checked", "LowStar.BufferView.Down.fsti.checked", "LowStar.Buffer.fst.checked", "FStar.UInt64.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.List.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked" ], "interface_file": false, "source_file": "Vale.Stdcalls.X64.GCTR.fst" }
[ { "abbrev": true, "full_module": "Vale.AES.X64.GCTR", "short_module": "GC" }, { "abbrev": false, "full_module": "Vale.AES.AES_s", "short_module": null }, { "abbrev": true, "full_module": "Vale.X64.Machine_s", "short_module": "MS" }, { "abbrev": true, "full_module": "Vale.X64.State", "short_module": "VS" }, { "abbrev": false, "full_module": "Vale.X64.MemoryAdapters", "short_module": null }, { "abbrev": true, "full_module": "Vale.AsLowStar.Wrapper", "short_module": "W" }, { "abbrev": true, "full_module": "Vale.Interop.Assumptions", "short_module": "IA" }, { "abbrev": true, "full_module": "Vale.X64.Decls", "short_module": "V" }, { "abbrev": true, "full_module": "Vale.X64.Memory", "short_module": "ME" }, { "abbrev": true, "full_module": "Vale.AsLowStar.LowStarSig", "short_module": "LSig" }, { "abbrev": true, "full_module": "Vale.AsLowStar.ValeSig", "short_module": "VSig" }, { "abbrev": true, "full_module": "Vale.Interop.X64", "short_module": "IX64" }, { "abbrev": false, "full_module": "Vale.Interop.Base", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Types_s", "short_module": null }, { "abbrev": true, "full_module": "LowStar.BufferView.Up", "short_module": "UV" }, { "abbrev": true, "full_module": "LowStar.BufferView.Down", "short_module": "DV" }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": false, "full_module": "Vale.Stdcalls.X64", "short_module": null }, { "abbrev": false, "full_module": "Vale.Stdcalls.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": 1, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": true, "smtencoding_l_arith_repr": "native", "smtencoding_nl_arith_repr": "wrapped", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [ "smt.arith.nl=false", "smt.QI.EAGER_THRESHOLD=100", "smt.CASE_SPLIT=3" ], "z3refresh": false, "z3rlimit": 20, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
s: FStar.Ghost.erased (FStar.Seq.Base.seq Vale.Def.Types_s.nat32) -> Vale.AsLowStar.ValeSig.vale_sig_stdcall (Vale.Stdcalls.X64.GCTR.gctr128_pre s) (Vale.Stdcalls.X64.GCTR.gctr128_post s)
Prims.Tot
[ "total" ]
[]
[ "FStar.Ghost.erased", "FStar.Seq.Base.seq", "Vale.Def.Types_s.nat32", "Vale.Stdcalls.X64.GCTR.as_t", "Vale.AsLowStar.ValeSig.vale_sig_stdcall", "Vale.Stdcalls.X64.GCTR.dom", "Vale.Stdcalls.X64.GCTR.gctr128_pre", "Vale.Stdcalls.X64.GCTR.gctr128_post", "Vale.Stdcalls.X64.GCTR.gctr128_lemma'" ]
[]
false
false
false
false
false
let gctr128_lemma (s: Ghost.erased (Seq.seq nat32)) =
as_t #(VSig.vale_sig_stdcall (gctr128_pre s) (gctr128_post s)) (gctr128_lemma' s)
false
MerkleTree.New.High.Correct.Base.fst
MerkleTree.New.High.Correct.Base.mt_olds_inv_equiv
val mt_olds_inv_equiv: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> lv:nat{lv <= 32} -> i:nat -> olds1:hashess #hsz {S.length olds1 = 32} -> olds2:hashess #hsz {S.length olds2 = 32} -> Lemma (requires mt_olds_inv #hsz lv i olds1 /\ S.equal (S.slice olds1 lv 32) (S.slice olds2 lv 32)) (ensures mt_olds_inv #hsz lv i olds2) (decreases (32 - lv))
val mt_olds_inv_equiv: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> lv:nat{lv <= 32} -> i:nat -> olds1:hashess #hsz {S.length olds1 = 32} -> olds2:hashess #hsz {S.length olds2 = 32} -> Lemma (requires mt_olds_inv #hsz lv i olds1 /\ S.equal (S.slice olds1 lv 32) (S.slice olds2 lv 32)) (ensures mt_olds_inv #hsz lv i olds2) (decreases (32 - lv))
let rec mt_olds_inv_equiv #hsz #f lv i olds1 olds2 = if lv = 32 then () else (assert (S.index olds1 lv == S.index olds2 lv); mt_olds_inv_equiv #_ #f (lv + 1) (i / 2) olds1 olds2)
{ "file_name": "src/MerkleTree.New.High.Correct.Base.fst", "git_rev": "7d7bdc20f2033171e279c176b26e84f9069d23c6", "git_url": "https://github.com/hacl-star/merkle-tree.git", "project_name": "merkle-tree" }
{ "end_col": 60, "end_line": 249, "start_col": 0, "start_line": 246 }
module MerkleTree.New.High.Correct.Base open FStar.Classical open FStar.Ghost open FStar.Seq module S = FStar.Seq module MTS = MerkleTree.Spec open MerkleTree.New.High #set-options "--z3rlimit 40 --max_fuel 0 --max_ifuel 0" /// Sequence helpers val seq_prefix: #a:Type -> s1:S.seq a -> s2:S.seq a{S.length s1 <= S.length s2} -> GTot Type0 let seq_prefix #a s1 s2 = S.equal s1 (S.slice s2 0 (S.length s1)) val seq_head_cons: #a:Type -> x:a -> s:S.seq a -> Lemma (S.head (S.cons x s) == x) [SMTPat (S.cons x s)] let seq_head_cons #a x s = () val seq_tail_cons: #a:Type -> x:a -> s:S.seq a -> Lemma (S.equal (S.tail (S.cons x s)) s) [SMTPat (S.cons x s)] let seq_tail_cons #a x s = () /// Invariants and simulation relation of high-level Merkle tree design // Invariants of internal hashes val empty_hashes: (#hsz:pos) -> (len:nat) -> GTot (hs:hashess #hsz {S.length hs = len}) let empty_hashes #hsz len = S.create len S.empty val empty_hashes_head: #hsz:pos -> len:nat{len > 0} -> Lemma (S.head (empty_hashes #hsz len) == S.empty) let empty_hashes_head #_ _ = () val empty_hashes_tail: #hsz:pos -> len:nat{len > 0} -> Lemma (S.equal (S.tail (empty_hashes len)) (empty_hashes #hsz (len - 1))) let empty_hashes_tail #_ _ = () #push-options "--max_fuel 1" val mt_hashes_lth_inv: #hsz:pos -> lv:nat{lv <= 32} -> j:nat{j < pow2 (32 - lv)} -> fhs:hashess #hsz {S.length fhs = 32} -> GTot Type0 (decreases (32 - lv)) let rec mt_hashes_lth_inv #hsz lv j fhs = if lv = 32 then true else (S.length (S.index fhs lv) == j /\ mt_hashes_lth_inv (lv + 1) (j / 2) fhs) val mt_hashes_lth_inv_empty: #hsz:pos -> lv:nat{lv <= 32} -> Lemma (requires True) (ensures mt_hashes_lth_inv lv 0 (empty_hashes #hsz 32)) (decreases (32 - lv)) let rec mt_hashes_lth_inv_empty #hsz lv = if lv = 32 then () else mt_hashes_lth_inv_empty #hsz (lv + 1) val mt_hashes_next_rel: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> j:nat -> hs:hashes #hsz {S.length hs = j} -> nhs:hashes #hsz {S.length nhs = j / 2} -> GTot Type0 let mt_hashes_next_rel #hsz #f j hs nhs = forall (i:nat{i < j / 2}). S.index nhs i == f (S.index hs (op_Multiply 2 i)) (S.index hs (op_Multiply 2 i + 1)) #pop-options #push-options "--max_fuel 2" val mt_hashes_inv: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> lv:nat{lv < 32} -> j:nat{j < pow2 (32 - lv)} -> fhs:hashess #hsz {S.length fhs = 32 /\ mt_hashes_lth_inv lv j fhs} -> GTot Type0 (decreases (32 - lv)) let rec mt_hashes_inv #hsz #f lv j fhs = if lv = 31 then true else (mt_hashes_next_rel #_ #f j (S.index fhs lv) (S.index fhs (lv + 1)) /\ mt_hashes_inv #_ #f (lv + 1) (j / 2) fhs) val mt_hashes_inv_empty: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> lv:nat{lv < 32} -> Lemma (requires True) (ensures (mt_hashes_lth_inv_empty #hsz lv; mt_hashes_inv #hsz #f lv 0 (empty_hashes #hsz 32))) (decreases (32 - lv)) let rec mt_hashes_inv_empty #hsz #f lv = if lv = 31 then () else (mt_hashes_lth_inv_empty #hsz (lv + 1); mt_hashes_inv_empty #_ #f (lv + 1)) val mt_hashes_lth_inv_equiv: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> lv:nat{lv < 32} -> j:nat{j < pow2 (32 - lv)} -> fhs1:hashess{S.length fhs1 = 32} -> fhs2:hashess{S.length fhs2 = 32} -> Lemma (requires mt_hashes_lth_inv lv j fhs1 /\ S.equal (S.slice fhs1 lv 32) (S.slice fhs2 lv 32)) (ensures mt_hashes_lth_inv #hsz lv j fhs2) (decreases (32 - lv)) let rec mt_hashes_lth_inv_equiv #hsz #f lv j fhs1 fhs2 = if lv = 31 then () else (assert (S.index fhs1 lv == S.index fhs2 lv); mt_hashes_lth_inv_equiv #_ #f (lv + 1) (j / 2) fhs1 fhs2) #pop-options #push-options "--max_fuel 1" val mt_hashes_inv_equiv: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> lv:nat{lv < 32} -> j:nat{j < pow2 (32 - lv)} -> fhs1:hashess #hsz {S.length fhs1 = 32 /\ mt_hashes_lth_inv lv j fhs1} -> fhs2:hashess #hsz {S.length fhs2 = 32 /\ mt_hashes_lth_inv lv j fhs2} -> Lemma (requires mt_hashes_inv #_ #f lv j fhs1 /\ S.equal (S.slice fhs1 lv 32) (S.slice fhs2 lv 32)) (ensures mt_hashes_inv #_ #f lv j fhs2) (decreases (32 - lv)) let rec mt_hashes_inv_equiv #hsz #f lv j fhs1 fhs2 = if lv = 31 then () else (assert (S.index fhs1 lv == S.index fhs2 lv); assert (S.index fhs1 (lv + 1) == S.index fhs2 (lv + 1)); mt_hashes_inv_equiv #_ #f (lv + 1) (j / 2) fhs1 fhs2) val merge_hs: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> hs1:hashess #hsz -> hs2:hashess #hsz {S.length hs1 = S.length hs2} -> GTot (mhs:hashess #hsz {S.length mhs = S.length hs1}) (decreases (S.length hs1)) let rec merge_hs #hsz #f hs1 hs2 = if S.length hs1 = 0 then S.empty else (S.cons (S.append (S.head hs1) (S.head hs2)) (merge_hs #_ #f (S.tail hs1) (S.tail hs2))) val merge_hs_empty: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> len:nat -> Lemma (S.equal (merge_hs #_ #f (empty_hashes #hsz len) (empty_hashes #hsz len)) (empty_hashes #hsz len)) let rec merge_hs_empty #hsz #f len = if len = 0 then () else (empty_hashes_head #hsz len; empty_hashes_tail #hsz len; assert (S.equal (S.append #(hash #hsz) S.empty S.empty) (S.empty #(hash #hsz))); assert (S.equal (merge_hs #_ #f (empty_hashes len) (empty_hashes len)) (S.cons S.empty (merge_hs #_ #f (empty_hashes (len - 1)) (empty_hashes (len - 1))))); merge_hs_empty #_ #f (len - 1)) val merge_hs_index: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> hs1:hashess -> hs2:hashess{S.length hs1 = S.length hs2} -> i:nat{i < S.length hs1} -> Lemma (requires True) (ensures S.equal (S.index (merge_hs #_ #f hs1 hs2) i) (S.append (S.index hs1 i) (S.index hs2 i))) (decreases (S.length hs1)) [SMTPat (S.index (merge_hs #_ #f hs1 hs2) i)] let rec merge_hs_index #hsz #f hs1 hs2 i = if S.length hs1 = 0 then () else if i = 0 then () else merge_hs_index #_ #f (S.tail hs1) (S.tail hs2) (i - 1) val merge_hs_slice_equal: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> ahs1:hashess #hsz -> ahs2:hashess #hsz {S.length ahs1 = S.length ahs2} -> bhs1:hashess #hsz -> bhs2:hashess #hsz {S.length bhs1 = S.length bhs2} -> i:nat -> j:nat{i <= j && j <= S.length ahs1 && j <= S.length bhs1} -> Lemma (requires S.equal (S.slice ahs1 i j) (S.slice bhs1 i j) /\ S.equal (S.slice ahs2 i j) (S.slice bhs2 i j)) (ensures S.equal (S.slice (merge_hs #_ #f ahs1 ahs2) i j) (S.slice (merge_hs #_ #f bhs1 bhs2) i j)) (decreases (j - i)) let rec merge_hs_slice_equal #_ #f ahs1 ahs2 bhs1 bhs2 i j = if i = j then () else (assert (S.index ahs1 i == S.index bhs1 i); assert (S.index ahs2 i == S.index bhs2 i); merge_hs_slice_equal #_ #f ahs1 ahs2 bhs1 bhs2 (i + 1) j) val merge_hs_upd: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> hs1:hashess #hsz -> hs2:hashess #hsz {S.length hs1 = S.length hs2} -> i:nat{i < S.length hs1} -> v1:hashes #hsz -> v2:hashes #hsz -> Lemma (requires S.equal (S.append (S.index hs1 i) (S.index hs2 i)) (S.append v1 v2)) (ensures S.equal (merge_hs #_ #f hs1 hs2) (merge_hs #_ #f (S.upd hs1 i v1) (S.upd hs2 i v2))) (decreases i) let rec merge_hs_upd #_ #f hs1 hs2 i v1 v2 = if S.length hs1 = 0 then () else if i = 0 then () else merge_hs_upd #_ #f (S.tail hs1) (S.tail hs2) (i - 1) v1 v2 val mt_olds_inv: #hsz:pos -> lv:nat{lv <= 32} -> i:nat -> olds:hashess #hsz {S.length olds = 32} -> GTot Type0 (decreases (32 - lv)) let rec mt_olds_inv #hsz lv i olds = if lv = 32 then true else (let ofs = offset_of i in S.length (S.index olds lv) == ofs /\ mt_olds_inv #hsz (lv + 1) (i / 2) olds) val mt_olds_inv_equiv: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> lv:nat{lv <= 32} -> i:nat -> olds1:hashess #hsz {S.length olds1 = 32} -> olds2:hashess #hsz {S.length olds2 = 32} -> Lemma (requires mt_olds_inv #hsz lv i olds1 /\ S.equal (S.slice olds1 lv 32) (S.slice olds2 lv 32)) (ensures mt_olds_inv #hsz lv i olds2)
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "MerkleTree.Spec.fst.checked", "MerkleTree.New.High.fst.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Ghost.fsti.checked", "FStar.Classical.fsti.checked" ], "interface_file": false, "source_file": "MerkleTree.New.High.Correct.Base.fst" }
[ { "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": 2, "initial_ifuel": 1, "max_fuel": 1, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 40, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
lv: Prims.nat{lv <= 32} -> i: Prims.nat -> olds1: MerkleTree.New.High.hashess{FStar.Seq.Base.length olds1 = 32} -> olds2: MerkleTree.New.High.hashess{FStar.Seq.Base.length olds2 = 32} -> FStar.Pervasives.Lemma (requires MerkleTree.New.High.Correct.Base.mt_olds_inv lv i olds1 /\ FStar.Seq.Base.equal (FStar.Seq.Base.slice olds1 lv 32) (FStar.Seq.Base.slice olds2 lv 32)) (ensures MerkleTree.New.High.Correct.Base.mt_olds_inv lv i olds2) (decreases 32 - lv)
FStar.Pervasives.Lemma
[ "lemma", "" ]
[]
[ "Prims.pos", "MerkleTree.Spec.hash_fun_t", "Prims.nat", "Prims.b2t", "Prims.op_LessThanOrEqual", "MerkleTree.New.High.hashess", "Prims.op_Equality", "Prims.int", "FStar.Seq.Base.length", "MerkleTree.New.High.hashes", "Prims.bool", "MerkleTree.New.High.Correct.Base.mt_olds_inv_equiv", "Prims.op_Addition", "Prims.op_Division", "Prims.unit", "Prims._assert", "Prims.eq2", "FStar.Seq.Base.index" ]
[ "recursion" ]
false
false
true
false
false
let rec mt_olds_inv_equiv #hsz #f lv i olds1 olds2 =
if lv = 32 then () else (assert (S.index olds1 lv == S.index olds2 lv); mt_olds_inv_equiv #_ #f (lv + 1) (i / 2) olds1 olds2)
false
MerkleTree.New.High.Correct.Base.fst
MerkleTree.New.High.Correct.Base.merge_hs_index
val merge_hs_index: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> hs1:hashess -> hs2:hashess{S.length hs1 = S.length hs2} -> i:nat{i < S.length hs1} -> Lemma (requires True) (ensures S.equal (S.index (merge_hs #_ #f hs1 hs2) i) (S.append (S.index hs1 i) (S.index hs2 i))) (decreases (S.length hs1)) [SMTPat (S.index (merge_hs #_ #f hs1 hs2) i)]
val merge_hs_index: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> hs1:hashess -> hs2:hashess{S.length hs1 = S.length hs2} -> i:nat{i < S.length hs1} -> Lemma (requires True) (ensures S.equal (S.index (merge_hs #_ #f hs1 hs2) i) (S.append (S.index hs1 i) (S.index hs2 i))) (decreases (S.length hs1)) [SMTPat (S.index (merge_hs #_ #f hs1 hs2) i)]
let rec merge_hs_index #hsz #f hs1 hs2 i = if S.length hs1 = 0 then () else if i = 0 then () else merge_hs_index #_ #f (S.tail hs1) (S.tail hs2) (i - 1)
{ "file_name": "src/MerkleTree.New.High.Correct.Base.fst", "git_rev": "7d7bdc20f2033171e279c176b26e84f9069d23c6", "git_url": "https://github.com/hacl-star/merkle-tree.git", "project_name": "merkle-tree" }
{ "end_col": 61, "end_line": 188, "start_col": 0, "start_line": 185 }
module MerkleTree.New.High.Correct.Base open FStar.Classical open FStar.Ghost open FStar.Seq module S = FStar.Seq module MTS = MerkleTree.Spec open MerkleTree.New.High #set-options "--z3rlimit 40 --max_fuel 0 --max_ifuel 0" /// Sequence helpers val seq_prefix: #a:Type -> s1:S.seq a -> s2:S.seq a{S.length s1 <= S.length s2} -> GTot Type0 let seq_prefix #a s1 s2 = S.equal s1 (S.slice s2 0 (S.length s1)) val seq_head_cons: #a:Type -> x:a -> s:S.seq a -> Lemma (S.head (S.cons x s) == x) [SMTPat (S.cons x s)] let seq_head_cons #a x s = () val seq_tail_cons: #a:Type -> x:a -> s:S.seq a -> Lemma (S.equal (S.tail (S.cons x s)) s) [SMTPat (S.cons x s)] let seq_tail_cons #a x s = () /// Invariants and simulation relation of high-level Merkle tree design // Invariants of internal hashes val empty_hashes: (#hsz:pos) -> (len:nat) -> GTot (hs:hashess #hsz {S.length hs = len}) let empty_hashes #hsz len = S.create len S.empty val empty_hashes_head: #hsz:pos -> len:nat{len > 0} -> Lemma (S.head (empty_hashes #hsz len) == S.empty) let empty_hashes_head #_ _ = () val empty_hashes_tail: #hsz:pos -> len:nat{len > 0} -> Lemma (S.equal (S.tail (empty_hashes len)) (empty_hashes #hsz (len - 1))) let empty_hashes_tail #_ _ = () #push-options "--max_fuel 1" val mt_hashes_lth_inv: #hsz:pos -> lv:nat{lv <= 32} -> j:nat{j < pow2 (32 - lv)} -> fhs:hashess #hsz {S.length fhs = 32} -> GTot Type0 (decreases (32 - lv)) let rec mt_hashes_lth_inv #hsz lv j fhs = if lv = 32 then true else (S.length (S.index fhs lv) == j /\ mt_hashes_lth_inv (lv + 1) (j / 2) fhs) val mt_hashes_lth_inv_empty: #hsz:pos -> lv:nat{lv <= 32} -> Lemma (requires True) (ensures mt_hashes_lth_inv lv 0 (empty_hashes #hsz 32)) (decreases (32 - lv)) let rec mt_hashes_lth_inv_empty #hsz lv = if lv = 32 then () else mt_hashes_lth_inv_empty #hsz (lv + 1) val mt_hashes_next_rel: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> j:nat -> hs:hashes #hsz {S.length hs = j} -> nhs:hashes #hsz {S.length nhs = j / 2} -> GTot Type0 let mt_hashes_next_rel #hsz #f j hs nhs = forall (i:nat{i < j / 2}). S.index nhs i == f (S.index hs (op_Multiply 2 i)) (S.index hs (op_Multiply 2 i + 1)) #pop-options #push-options "--max_fuel 2" val mt_hashes_inv: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> lv:nat{lv < 32} -> j:nat{j < pow2 (32 - lv)} -> fhs:hashess #hsz {S.length fhs = 32 /\ mt_hashes_lth_inv lv j fhs} -> GTot Type0 (decreases (32 - lv)) let rec mt_hashes_inv #hsz #f lv j fhs = if lv = 31 then true else (mt_hashes_next_rel #_ #f j (S.index fhs lv) (S.index fhs (lv + 1)) /\ mt_hashes_inv #_ #f (lv + 1) (j / 2) fhs) val mt_hashes_inv_empty: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> lv:nat{lv < 32} -> Lemma (requires True) (ensures (mt_hashes_lth_inv_empty #hsz lv; mt_hashes_inv #hsz #f lv 0 (empty_hashes #hsz 32))) (decreases (32 - lv)) let rec mt_hashes_inv_empty #hsz #f lv = if lv = 31 then () else (mt_hashes_lth_inv_empty #hsz (lv + 1); mt_hashes_inv_empty #_ #f (lv + 1)) val mt_hashes_lth_inv_equiv: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> lv:nat{lv < 32} -> j:nat{j < pow2 (32 - lv)} -> fhs1:hashess{S.length fhs1 = 32} -> fhs2:hashess{S.length fhs2 = 32} -> Lemma (requires mt_hashes_lth_inv lv j fhs1 /\ S.equal (S.slice fhs1 lv 32) (S.slice fhs2 lv 32)) (ensures mt_hashes_lth_inv #hsz lv j fhs2) (decreases (32 - lv)) let rec mt_hashes_lth_inv_equiv #hsz #f lv j fhs1 fhs2 = if lv = 31 then () else (assert (S.index fhs1 lv == S.index fhs2 lv); mt_hashes_lth_inv_equiv #_ #f (lv + 1) (j / 2) fhs1 fhs2) #pop-options #push-options "--max_fuel 1" val mt_hashes_inv_equiv: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> lv:nat{lv < 32} -> j:nat{j < pow2 (32 - lv)} -> fhs1:hashess #hsz {S.length fhs1 = 32 /\ mt_hashes_lth_inv lv j fhs1} -> fhs2:hashess #hsz {S.length fhs2 = 32 /\ mt_hashes_lth_inv lv j fhs2} -> Lemma (requires mt_hashes_inv #_ #f lv j fhs1 /\ S.equal (S.slice fhs1 lv 32) (S.slice fhs2 lv 32)) (ensures mt_hashes_inv #_ #f lv j fhs2) (decreases (32 - lv)) let rec mt_hashes_inv_equiv #hsz #f lv j fhs1 fhs2 = if lv = 31 then () else (assert (S.index fhs1 lv == S.index fhs2 lv); assert (S.index fhs1 (lv + 1) == S.index fhs2 (lv + 1)); mt_hashes_inv_equiv #_ #f (lv + 1) (j / 2) fhs1 fhs2) val merge_hs: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> hs1:hashess #hsz -> hs2:hashess #hsz {S.length hs1 = S.length hs2} -> GTot (mhs:hashess #hsz {S.length mhs = S.length hs1}) (decreases (S.length hs1)) let rec merge_hs #hsz #f hs1 hs2 = if S.length hs1 = 0 then S.empty else (S.cons (S.append (S.head hs1) (S.head hs2)) (merge_hs #_ #f (S.tail hs1) (S.tail hs2))) val merge_hs_empty: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> len:nat -> Lemma (S.equal (merge_hs #_ #f (empty_hashes #hsz len) (empty_hashes #hsz len)) (empty_hashes #hsz len)) let rec merge_hs_empty #hsz #f len = if len = 0 then () else (empty_hashes_head #hsz len; empty_hashes_tail #hsz len; assert (S.equal (S.append #(hash #hsz) S.empty S.empty) (S.empty #(hash #hsz))); assert (S.equal (merge_hs #_ #f (empty_hashes len) (empty_hashes len)) (S.cons S.empty (merge_hs #_ #f (empty_hashes (len - 1)) (empty_hashes (len - 1))))); merge_hs_empty #_ #f (len - 1)) val merge_hs_index: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> hs1:hashess -> hs2:hashess{S.length hs1 = S.length hs2} -> i:nat{i < S.length hs1} -> Lemma (requires True) (ensures S.equal (S.index (merge_hs #_ #f hs1 hs2) i) (S.append (S.index hs1 i) (S.index hs2 i))) (decreases (S.length hs1))
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "MerkleTree.Spec.fst.checked", "MerkleTree.New.High.fst.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Ghost.fsti.checked", "FStar.Classical.fsti.checked" ], "interface_file": false, "source_file": "MerkleTree.New.High.Correct.Base.fst" }
[ { "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": 2, "initial_ifuel": 1, "max_fuel": 1, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 40, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
hs1: MerkleTree.New.High.hashess -> hs2: MerkleTree.New.High.hashess{FStar.Seq.Base.length hs1 = FStar.Seq.Base.length hs2} -> i: Prims.nat{i < FStar.Seq.Base.length hs1} -> FStar.Pervasives.Lemma (ensures FStar.Seq.Base.equal (FStar.Seq.Base.index (MerkleTree.New.High.Correct.Base.merge_hs hs1 hs2) i) (FStar.Seq.Base.append (FStar.Seq.Base.index hs1 i) (FStar.Seq.Base.index hs2 i))) (decreases FStar.Seq.Base.length hs1) [SMTPat (FStar.Seq.Base.index (MerkleTree.New.High.Correct.Base.merge_hs hs1 hs2) i)]
FStar.Pervasives.Lemma
[ "lemma", "" ]
[]
[ "Prims.pos", "MerkleTree.Spec.hash_fun_t", "MerkleTree.New.High.hashess", "Prims.b2t", "Prims.op_Equality", "Prims.nat", "FStar.Seq.Base.length", "MerkleTree.New.High.hashes", "Prims.op_LessThan", "Prims.int", "Prims.bool", "MerkleTree.New.High.Correct.Base.merge_hs_index", "FStar.Seq.Properties.tail", "Prims.op_Subtraction", "Prims.unit" ]
[ "recursion" ]
false
false
true
false
false
let rec merge_hs_index #hsz #f hs1 hs2 i =
if S.length hs1 = 0 then () else if i = 0 then () else merge_hs_index #_ #f (S.tail hs1) (S.tail hs2) (i - 1)
false
MerkleTree.New.High.Correct.Base.fst
MerkleTree.New.High.Correct.Base.log2c_bound
val log2c_bound: n:nat -> c:nat{n < pow2 c} -> Lemma (log2c n <= c)
val log2c_bound: n:nat -> c:nat{n < pow2 c} -> Lemma (log2c n <= c)
let rec log2c_bound n c = if n = 0 then () else log2c_bound (n / 2) (c - 1)
{ "file_name": "src/MerkleTree.New.High.Correct.Base.fst", "git_rev": "7d7bdc20f2033171e279c176b26e84f9069d23c6", "git_url": "https://github.com/hacl-star/merkle-tree.git", "project_name": "merkle-tree" }
{ "end_col": 34, "end_line": 316, "start_col": 0, "start_line": 314 }
module MerkleTree.New.High.Correct.Base open FStar.Classical open FStar.Ghost open FStar.Seq module S = FStar.Seq module MTS = MerkleTree.Spec open MerkleTree.New.High #set-options "--z3rlimit 40 --max_fuel 0 --max_ifuel 0" /// Sequence helpers val seq_prefix: #a:Type -> s1:S.seq a -> s2:S.seq a{S.length s1 <= S.length s2} -> GTot Type0 let seq_prefix #a s1 s2 = S.equal s1 (S.slice s2 0 (S.length s1)) val seq_head_cons: #a:Type -> x:a -> s:S.seq a -> Lemma (S.head (S.cons x s) == x) [SMTPat (S.cons x s)] let seq_head_cons #a x s = () val seq_tail_cons: #a:Type -> x:a -> s:S.seq a -> Lemma (S.equal (S.tail (S.cons x s)) s) [SMTPat (S.cons x s)] let seq_tail_cons #a x s = () /// Invariants and simulation relation of high-level Merkle tree design // Invariants of internal hashes val empty_hashes: (#hsz:pos) -> (len:nat) -> GTot (hs:hashess #hsz {S.length hs = len}) let empty_hashes #hsz len = S.create len S.empty val empty_hashes_head: #hsz:pos -> len:nat{len > 0} -> Lemma (S.head (empty_hashes #hsz len) == S.empty) let empty_hashes_head #_ _ = () val empty_hashes_tail: #hsz:pos -> len:nat{len > 0} -> Lemma (S.equal (S.tail (empty_hashes len)) (empty_hashes #hsz (len - 1))) let empty_hashes_tail #_ _ = () #push-options "--max_fuel 1" val mt_hashes_lth_inv: #hsz:pos -> lv:nat{lv <= 32} -> j:nat{j < pow2 (32 - lv)} -> fhs:hashess #hsz {S.length fhs = 32} -> GTot Type0 (decreases (32 - lv)) let rec mt_hashes_lth_inv #hsz lv j fhs = if lv = 32 then true else (S.length (S.index fhs lv) == j /\ mt_hashes_lth_inv (lv + 1) (j / 2) fhs) val mt_hashes_lth_inv_empty: #hsz:pos -> lv:nat{lv <= 32} -> Lemma (requires True) (ensures mt_hashes_lth_inv lv 0 (empty_hashes #hsz 32)) (decreases (32 - lv)) let rec mt_hashes_lth_inv_empty #hsz lv = if lv = 32 then () else mt_hashes_lth_inv_empty #hsz (lv + 1) val mt_hashes_next_rel: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> j:nat -> hs:hashes #hsz {S.length hs = j} -> nhs:hashes #hsz {S.length nhs = j / 2} -> GTot Type0 let mt_hashes_next_rel #hsz #f j hs nhs = forall (i:nat{i < j / 2}). S.index nhs i == f (S.index hs (op_Multiply 2 i)) (S.index hs (op_Multiply 2 i + 1)) #pop-options #push-options "--max_fuel 2" val mt_hashes_inv: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> lv:nat{lv < 32} -> j:nat{j < pow2 (32 - lv)} -> fhs:hashess #hsz {S.length fhs = 32 /\ mt_hashes_lth_inv lv j fhs} -> GTot Type0 (decreases (32 - lv)) let rec mt_hashes_inv #hsz #f lv j fhs = if lv = 31 then true else (mt_hashes_next_rel #_ #f j (S.index fhs lv) (S.index fhs (lv + 1)) /\ mt_hashes_inv #_ #f (lv + 1) (j / 2) fhs) val mt_hashes_inv_empty: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> lv:nat{lv < 32} -> Lemma (requires True) (ensures (mt_hashes_lth_inv_empty #hsz lv; mt_hashes_inv #hsz #f lv 0 (empty_hashes #hsz 32))) (decreases (32 - lv)) let rec mt_hashes_inv_empty #hsz #f lv = if lv = 31 then () else (mt_hashes_lth_inv_empty #hsz (lv + 1); mt_hashes_inv_empty #_ #f (lv + 1)) val mt_hashes_lth_inv_equiv: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> lv:nat{lv < 32} -> j:nat{j < pow2 (32 - lv)} -> fhs1:hashess{S.length fhs1 = 32} -> fhs2:hashess{S.length fhs2 = 32} -> Lemma (requires mt_hashes_lth_inv lv j fhs1 /\ S.equal (S.slice fhs1 lv 32) (S.slice fhs2 lv 32)) (ensures mt_hashes_lth_inv #hsz lv j fhs2) (decreases (32 - lv)) let rec mt_hashes_lth_inv_equiv #hsz #f lv j fhs1 fhs2 = if lv = 31 then () else (assert (S.index fhs1 lv == S.index fhs2 lv); mt_hashes_lth_inv_equiv #_ #f (lv + 1) (j / 2) fhs1 fhs2) #pop-options #push-options "--max_fuel 1" val mt_hashes_inv_equiv: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> lv:nat{lv < 32} -> j:nat{j < pow2 (32 - lv)} -> fhs1:hashess #hsz {S.length fhs1 = 32 /\ mt_hashes_lth_inv lv j fhs1} -> fhs2:hashess #hsz {S.length fhs2 = 32 /\ mt_hashes_lth_inv lv j fhs2} -> Lemma (requires mt_hashes_inv #_ #f lv j fhs1 /\ S.equal (S.slice fhs1 lv 32) (S.slice fhs2 lv 32)) (ensures mt_hashes_inv #_ #f lv j fhs2) (decreases (32 - lv)) let rec mt_hashes_inv_equiv #hsz #f lv j fhs1 fhs2 = if lv = 31 then () else (assert (S.index fhs1 lv == S.index fhs2 lv); assert (S.index fhs1 (lv + 1) == S.index fhs2 (lv + 1)); mt_hashes_inv_equiv #_ #f (lv + 1) (j / 2) fhs1 fhs2) val merge_hs: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> hs1:hashess #hsz -> hs2:hashess #hsz {S.length hs1 = S.length hs2} -> GTot (mhs:hashess #hsz {S.length mhs = S.length hs1}) (decreases (S.length hs1)) let rec merge_hs #hsz #f hs1 hs2 = if S.length hs1 = 0 then S.empty else (S.cons (S.append (S.head hs1) (S.head hs2)) (merge_hs #_ #f (S.tail hs1) (S.tail hs2))) val merge_hs_empty: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> len:nat -> Lemma (S.equal (merge_hs #_ #f (empty_hashes #hsz len) (empty_hashes #hsz len)) (empty_hashes #hsz len)) let rec merge_hs_empty #hsz #f len = if len = 0 then () else (empty_hashes_head #hsz len; empty_hashes_tail #hsz len; assert (S.equal (S.append #(hash #hsz) S.empty S.empty) (S.empty #(hash #hsz))); assert (S.equal (merge_hs #_ #f (empty_hashes len) (empty_hashes len)) (S.cons S.empty (merge_hs #_ #f (empty_hashes (len - 1)) (empty_hashes (len - 1))))); merge_hs_empty #_ #f (len - 1)) val merge_hs_index: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> hs1:hashess -> hs2:hashess{S.length hs1 = S.length hs2} -> i:nat{i < S.length hs1} -> Lemma (requires True) (ensures S.equal (S.index (merge_hs #_ #f hs1 hs2) i) (S.append (S.index hs1 i) (S.index hs2 i))) (decreases (S.length hs1)) [SMTPat (S.index (merge_hs #_ #f hs1 hs2) i)] let rec merge_hs_index #hsz #f hs1 hs2 i = if S.length hs1 = 0 then () else if i = 0 then () else merge_hs_index #_ #f (S.tail hs1) (S.tail hs2) (i - 1) val merge_hs_slice_equal: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> ahs1:hashess #hsz -> ahs2:hashess #hsz {S.length ahs1 = S.length ahs2} -> bhs1:hashess #hsz -> bhs2:hashess #hsz {S.length bhs1 = S.length bhs2} -> i:nat -> j:nat{i <= j && j <= S.length ahs1 && j <= S.length bhs1} -> Lemma (requires S.equal (S.slice ahs1 i j) (S.slice bhs1 i j) /\ S.equal (S.slice ahs2 i j) (S.slice bhs2 i j)) (ensures S.equal (S.slice (merge_hs #_ #f ahs1 ahs2) i j) (S.slice (merge_hs #_ #f bhs1 bhs2) i j)) (decreases (j - i)) let rec merge_hs_slice_equal #_ #f ahs1 ahs2 bhs1 bhs2 i j = if i = j then () else (assert (S.index ahs1 i == S.index bhs1 i); assert (S.index ahs2 i == S.index bhs2 i); merge_hs_slice_equal #_ #f ahs1 ahs2 bhs1 bhs2 (i + 1) j) val merge_hs_upd: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> hs1:hashess #hsz -> hs2:hashess #hsz {S.length hs1 = S.length hs2} -> i:nat{i < S.length hs1} -> v1:hashes #hsz -> v2:hashes #hsz -> Lemma (requires S.equal (S.append (S.index hs1 i) (S.index hs2 i)) (S.append v1 v2)) (ensures S.equal (merge_hs #_ #f hs1 hs2) (merge_hs #_ #f (S.upd hs1 i v1) (S.upd hs2 i v2))) (decreases i) let rec merge_hs_upd #_ #f hs1 hs2 i v1 v2 = if S.length hs1 = 0 then () else if i = 0 then () else merge_hs_upd #_ #f (S.tail hs1) (S.tail hs2) (i - 1) v1 v2 val mt_olds_inv: #hsz:pos -> lv:nat{lv <= 32} -> i:nat -> olds:hashess #hsz {S.length olds = 32} -> GTot Type0 (decreases (32 - lv)) let rec mt_olds_inv #hsz lv i olds = if lv = 32 then true else (let ofs = offset_of i in S.length (S.index olds lv) == ofs /\ mt_olds_inv #hsz (lv + 1) (i / 2) olds) val mt_olds_inv_equiv: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> lv:nat{lv <= 32} -> i:nat -> olds1:hashess #hsz {S.length olds1 = 32} -> olds2:hashess #hsz {S.length olds2 = 32} -> Lemma (requires mt_olds_inv #hsz lv i olds1 /\ S.equal (S.slice olds1 lv 32) (S.slice olds2 lv 32)) (ensures mt_olds_inv #hsz lv i olds2) (decreases (32 - lv)) let rec mt_olds_inv_equiv #hsz #f lv i olds1 olds2 = if lv = 32 then () else (assert (S.index olds1 lv == S.index olds2 lv); mt_olds_inv_equiv #_ #f (lv + 1) (i / 2) olds1 olds2) val mt_olds_hs_lth_inv_ok: #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 #hsz lv hs i j} -> Lemma (requires True) (ensures mt_hashes_lth_inv #hsz lv j (merge_hs #_ #f olds hs)) (decreases (32 - lv)) let rec mt_olds_hs_lth_inv_ok #hsz #f lv i j olds hs = if lv = 32 then () else (mt_olds_hs_lth_inv_ok #_ #f (lv + 1) (i / 2) (j / 2) olds hs) val mt_olds_hs_inv: #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 #hsz lv hs i j} -> GTot Type0 let mt_olds_hs_inv #hsz #f lv i j olds hs = mt_olds_hs_lth_inv_ok #_ #f lv i j olds hs; mt_hashes_inv #_ #f lv j (merge_hs #_ #f olds hs) // Relation between valid internal hashes (satisfying `mt_olds_hs_inv`) and // the spec. While giving such relation, all rightmost hashes are recovered. // Note that `MT?.rhs` after `construct_rhs` does NOT contain all rightmost // hashes; it has partial rightmost hashes that are enough to calculate // Merkle paths. val log2: n:nat{n > 0} -> GTot (c:nat{pow2 c <= n && n < pow2 (c+1)}) let rec log2 n = if n = 1 then 0 else 1 + log2 (n / 2) val log2_bound: n:nat{n > 0} -> c:nat{n < pow2 c} -> Lemma (log2 n <= c-1) let rec log2_bound n c = if n = 1 then () else log2_bound (n / 2) (c - 1) val log2_div: n:nat{n > 1} -> Lemma (log2 (n / 2) = log2 n - 1) let log2_div n = () val log2c: n:nat -> GTot (c:nat{c = 0 || (pow2 (c-1) <= n && n < pow2 c)}) let log2c n = if n = 0 then 0 else (log2 n + 1) val log2c_div: n:nat{n > 0} -> Lemma (log2c (n / 2) = log2c n - 1) let log2c_div n = () val log2c_bound: n:nat -> c:nat{n < pow2 c} ->
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "MerkleTree.Spec.fst.checked", "MerkleTree.New.High.fst.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Ghost.fsti.checked", "FStar.Classical.fsti.checked" ], "interface_file": false, "source_file": "MerkleTree.New.High.Correct.Base.fst" }
[ { "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": 2, "initial_ifuel": 1, "max_fuel": 1, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 40, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
n: Prims.nat -> c: Prims.nat{n < Prims.pow2 c} -> FStar.Pervasives.Lemma (ensures MerkleTree.New.High.Correct.Base.log2c n <= c)
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "Prims.nat", "Prims.b2t", "Prims.op_LessThan", "Prims.pow2", "Prims.op_Equality", "Prims.int", "Prims.bool", "MerkleTree.New.High.Correct.Base.log2c_bound", "Prims.op_Division", "Prims.op_Subtraction", "Prims.unit" ]
[ "recursion" ]
false
false
true
false
false
let rec log2c_bound n c =
if n = 0 then () else log2c_bound (n / 2) (c - 1)
false
Vale.Stdcalls.X64.GCTR.fst
Vale.Stdcalls.X64.GCTR.gctr256_lemma
val gctr256_lemma : s: FStar.Ghost.erased (FStar.Seq.Base.seq Vale.Def.Types_s.nat32) -> Vale.AsLowStar.ValeSig.vale_sig_stdcall (Vale.Stdcalls.X64.GCTR.gctr256_pre s) (Vale.Stdcalls.X64.GCTR.gctr256_post s)
let gctr256_lemma (s:Ghost.erased (Seq.seq nat32)) = as_t #(VSig.vale_sig_stdcall (gctr256_pre s) (gctr256_post s)) (gctr256_lemma' s)
{ "file_name": "vale/code/arch/x64/interop/Vale.Stdcalls.X64.GCTR.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 135, "end_line": 231, "start_col": 0, "start_line": 231 }
module Vale.Stdcalls.X64.GCTR open FStar.HyperStack.ST module B = LowStar.Buffer module HS = FStar.HyperStack open FStar.Mul module DV = LowStar.BufferView.Down module UV = LowStar.BufferView.Up open Vale.Def.Types_s open Vale.Interop.Base module IX64 = Vale.Interop.X64 module VSig = Vale.AsLowStar.ValeSig module LSig = Vale.AsLowStar.LowStarSig module ME = Vale.X64.Memory module V = Vale.X64.Decls module IA = Vale.Interop.Assumptions module W = Vale.AsLowStar.Wrapper open Vale.X64.MemoryAdapters module VS = Vale.X64.State module MS = Vale.X64.Machine_s open Vale.AES.AES_s module GC = Vale.AES.X64.GCTR let uint64 = UInt64.t (* A little utility to trigger normalization in types *) noextract let as_t (#a:Type) (x:normal a) : a = x noextract let as_normal_t (#a:Type) (x:a) : normal a = x [@__reduce__] noextract let b128 = buf_t TUInt8 TUInt128 [@__reduce__] noextract let t128_mod = TD_Buffer TUInt8 TUInt128 default_bq [@__reduce__] noextract let t128_no_mod = TD_Buffer TUInt8 TUInt128 ({modified=false; strict_disjointness=false; taint=MS.Secret}) [@__reduce__] noextract let tuint64 = TD_Base TUInt64 [@__reduce__] noextract let (dom: list td{List.length dom <= 20}) = let y = [t128_no_mod; tuint64; t128_mod; t128_mod; t128_no_mod; t128_no_mod; tuint64] in assert_norm (List.length y = 7); y (* Need to rearrange the order of arguments *) [@__reduce__] noextract let gctr128_pre : (Ghost.erased (Seq.seq nat32)) -> VSig.vale_pre dom = fun (s:Ghost.erased (Seq.seq nat32)) (c:V.va_code) (in_b:b128) (num_bytes:uint64) (out_b:b128) (inout_b:b128) (keys_b:b128) (ctr_b:b128) (num_blocks:uint64) (va_s0:V.va_state) -> GC.va_req_Gctr_bytes_stdcall c va_s0 IA.win AES_128 (as_vale_buffer in_b) (UInt64.v num_bytes) (as_vale_buffer out_b) (as_vale_buffer inout_b) (as_vale_buffer keys_b) (as_vale_buffer ctr_b) (UInt64.v num_blocks) (Ghost.reveal s) (* Need to rearrange the order of arguments *) [@__reduce__] noextract let gctr128_post : (Ghost.erased (Seq.seq nat32)) -> VSig.vale_post dom = fun (s:Ghost.erased (Seq.seq nat32)) (c:V.va_code) (in_b:b128) (num_bytes:uint64) (out_b:b128) (inout_b:b128) (keys_b:b128) (ctr_b:b128) (num_blocks:uint64) (va_s0:V.va_state) (va_s1:V.va_state) (f:V.va_fuel) -> GC.va_ens_Gctr_bytes_stdcall c va_s0 IA.win AES_128 (as_vale_buffer in_b) (UInt64.v num_bytes) (as_vale_buffer out_b) (as_vale_buffer inout_b) (as_vale_buffer keys_b) (as_vale_buffer ctr_b) (UInt64.v num_blocks) (Ghost.reveal s) va_s1 f #set-options "--z3rlimit 20" [@__reduce__] noextract let gctr128_lemma' (s:Ghost.erased (Seq.seq nat32)) (code:V.va_code) (_win:bool) (in_b:b128) (num_bytes:uint64) (out_b:b128) (inout_b:b128) (keys_b:b128) (ctr_b:b128) (num_blocks:uint64) (va_s0:V.va_state) : Ghost (V.va_state & V.va_fuel) (requires gctr128_pre s code in_b num_bytes out_b inout_b keys_b ctr_b num_blocks va_s0) (ensures (fun (va_s1, f) -> V.eval_code code va_s0 f va_s1 /\ VSig.vale_calling_conventions_stdcall va_s0 va_s1 /\ gctr128_post s code in_b num_bytes out_b inout_b keys_b ctr_b num_blocks va_s0 va_s1 f /\ ME.buffer_writeable (as_vale_buffer in_b) /\ ME.buffer_writeable (as_vale_buffer keys_b) /\ ME.buffer_writeable (as_vale_buffer ctr_b) /\ ME.buffer_writeable (as_vale_buffer inout_b) /\ ME.buffer_writeable (as_vale_buffer out_b) )) = let va_s1, f = GC.va_lemma_Gctr_bytes_stdcall code va_s0 IA.win AES_128 (as_vale_buffer in_b) (UInt64.v num_bytes) (as_vale_buffer out_b) (as_vale_buffer inout_b) (as_vale_buffer keys_b) (as_vale_buffer ctr_b) (UInt64.v num_blocks) (Ghost.reveal s) in Vale.AsLowStar.MemoryHelpers.buffer_writeable_reveal ME.TUInt8 ME.TUInt128 in_b; Vale.AsLowStar.MemoryHelpers.buffer_writeable_reveal ME.TUInt8 ME.TUInt128 out_b; Vale.AsLowStar.MemoryHelpers.buffer_writeable_reveal ME.TUInt8 ME.TUInt128 inout_b; Vale.AsLowStar.MemoryHelpers.buffer_writeable_reveal ME.TUInt8 ME.TUInt128 keys_b; Vale.AsLowStar.MemoryHelpers.buffer_writeable_reveal ME.TUInt8 ME.TUInt128 ctr_b; (va_s1, f) noextract let gctr128_lemma (s:Ghost.erased (Seq.seq nat32)) = as_t #(VSig.vale_sig_stdcall (gctr128_pre s) (gctr128_post s)) (gctr128_lemma' s) noextract let code_gctr128 = GC.va_code_Gctr_bytes_stdcall IA.win AES_128 [@__reduce__] noextract let lowstar_gctr128_t (s:Ghost.erased (Seq.seq nat32)) = assert_norm (List.length dom + List.length ([]<:list arg) <= 20); IX64.as_lowstar_sig_t_weak_stdcall code_gctr128 dom [] _ _ (W.mk_prediction code_gctr128 dom [] ((gctr128_lemma s) code_gctr128 IA.win)) (* And here's the gcm wrapper itself *) noextract let lowstar_gctr128 (s:Ghost.erased (Seq.seq nat32)) : lowstar_gctr128_t s = assert_norm (List.length dom + List.length ([]<:list arg) <= 20); IX64.wrap_weak_stdcall code_gctr128 dom (W.mk_prediction code_gctr128 dom [] ((gctr128_lemma s) code_gctr128 IA.win)) (* Need to rearrange the order of arguments *) [@__reduce__] noextract let gctr256_pre : (Ghost.erased (Seq.seq nat32)) -> VSig.vale_pre dom = fun (s:Ghost.erased (Seq.seq nat32)) (c:V.va_code) (in_b:b128) (num_bytes:uint64) (out_b:b128) (inout_b:b128) (keys_b:b128) (ctr_b:b128) (num_blocks:uint64) (va_s0:V.va_state) -> GC.va_req_Gctr_bytes_stdcall c va_s0 IA.win AES_256 (as_vale_buffer in_b) (UInt64.v num_bytes) (as_vale_buffer out_b) (as_vale_buffer inout_b) (as_vale_buffer keys_b) (as_vale_buffer ctr_b) (UInt64.v num_blocks) (Ghost.reveal s) (* Need to rearrange the order of arguments *) [@__reduce__] noextract let gctr256_post : (Ghost.erased (Seq.seq nat32)) -> VSig.vale_post dom = fun (s:Ghost.erased (Seq.seq nat32)) (c:V.va_code) (in_b:b128) (num_bytes:uint64) (out_b:b128) (inout_b:b128) (keys_b:b128) (ctr_b:b128) (num_blocks:uint64) (va_s0:V.va_state) (va_s1:V.va_state) (f:V.va_fuel) -> GC.va_ens_Gctr_bytes_stdcall c va_s0 IA.win AES_256 (as_vale_buffer in_b) (UInt64.v num_bytes) (as_vale_buffer out_b) (as_vale_buffer inout_b) (as_vale_buffer keys_b) (as_vale_buffer ctr_b) (UInt64.v num_blocks) (Ghost.reveal s) va_s1 f #set-options "--z3rlimit 20" [@__reduce__] noextract let gctr256_lemma' (s:Ghost.erased (Seq.seq nat32)) (code:V.va_code) (_win:bool) (in_b:b128) (num_bytes:uint64) (out_b:b128) (inout_b:b128) (keys_b:b128) (ctr_b:b128) (num_blocks:uint64) (va_s0:V.va_state) : Ghost (V.va_state & V.va_fuel) (requires gctr256_pre s code in_b num_bytes out_b inout_b keys_b ctr_b num_blocks va_s0) (ensures (fun (va_s1, f) -> V.eval_code code va_s0 f va_s1 /\ VSig.vale_calling_conventions_stdcall va_s0 va_s1 /\ gctr256_post s code in_b num_bytes out_b inout_b keys_b ctr_b num_blocks va_s0 va_s1 f /\ ME.buffer_writeable (as_vale_buffer in_b) /\ ME.buffer_writeable (as_vale_buffer keys_b) /\ ME.buffer_writeable (as_vale_buffer ctr_b) /\ ME.buffer_writeable (as_vale_buffer inout_b) /\ ME.buffer_writeable (as_vale_buffer out_b) )) = let va_s1, f = GC.va_lemma_Gctr_bytes_stdcall code va_s0 IA.win AES_256 (as_vale_buffer in_b) (UInt64.v num_bytes) (as_vale_buffer out_b) (as_vale_buffer inout_b) (as_vale_buffer keys_b) (as_vale_buffer ctr_b) (UInt64.v num_blocks) (Ghost.reveal s) in Vale.AsLowStar.MemoryHelpers.buffer_writeable_reveal ME.TUInt8 ME.TUInt128 in_b; Vale.AsLowStar.MemoryHelpers.buffer_writeable_reveal ME.TUInt8 ME.TUInt128 out_b; Vale.AsLowStar.MemoryHelpers.buffer_writeable_reveal ME.TUInt8 ME.TUInt128 inout_b; Vale.AsLowStar.MemoryHelpers.buffer_writeable_reveal ME.TUInt8 ME.TUInt128 keys_b; Vale.AsLowStar.MemoryHelpers.buffer_writeable_reveal ME.TUInt8 ME.TUInt128 ctr_b; (va_s1, f)
{ "checked_file": "/", "dependencies": [ "Vale.X64.State.fsti.checked", "Vale.X64.MemoryAdapters.fsti.checked", "Vale.X64.Memory.fsti.checked", "Vale.X64.Machine_s.fst.checked", "Vale.X64.Decls.fsti.checked", "Vale.Interop.X64.fsti.checked", "Vale.Interop.Base.fst.checked", "Vale.Interop.Assumptions.fst.checked", "Vale.Def.Types_s.fst.checked", "Vale.AsLowStar.Wrapper.fsti.checked", "Vale.AsLowStar.ValeSig.fst.checked", "Vale.AsLowStar.MemoryHelpers.fsti.checked", "Vale.AsLowStar.LowStarSig.fst.checked", "Vale.AES.X64.GCTR.fsti.checked", "Vale.AES.AES_s.fst.checked", "prims.fst.checked", "LowStar.BufferView.Up.fsti.checked", "LowStar.BufferView.Down.fsti.checked", "LowStar.Buffer.fst.checked", "FStar.UInt64.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.List.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked" ], "interface_file": false, "source_file": "Vale.Stdcalls.X64.GCTR.fst" }
[ { "abbrev": true, "full_module": "Vale.AES.X64.GCTR", "short_module": "GC" }, { "abbrev": false, "full_module": "Vale.AES.AES_s", "short_module": null }, { "abbrev": true, "full_module": "Vale.X64.Machine_s", "short_module": "MS" }, { "abbrev": true, "full_module": "Vale.X64.State", "short_module": "VS" }, { "abbrev": false, "full_module": "Vale.X64.MemoryAdapters", "short_module": null }, { "abbrev": true, "full_module": "Vale.AsLowStar.Wrapper", "short_module": "W" }, { "abbrev": true, "full_module": "Vale.Interop.Assumptions", "short_module": "IA" }, { "abbrev": true, "full_module": "Vale.X64.Decls", "short_module": "V" }, { "abbrev": true, "full_module": "Vale.X64.Memory", "short_module": "ME" }, { "abbrev": true, "full_module": "Vale.AsLowStar.LowStarSig", "short_module": "LSig" }, { "abbrev": true, "full_module": "Vale.AsLowStar.ValeSig", "short_module": "VSig" }, { "abbrev": true, "full_module": "Vale.Interop.X64", "short_module": "IX64" }, { "abbrev": false, "full_module": "Vale.Interop.Base", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Types_s", "short_module": null }, { "abbrev": true, "full_module": "LowStar.BufferView.Up", "short_module": "UV" }, { "abbrev": true, "full_module": "LowStar.BufferView.Down", "short_module": "DV" }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": false, "full_module": "Vale.Stdcalls.X64", "short_module": null }, { "abbrev": false, "full_module": "Vale.Stdcalls.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": 1, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": true, "smtencoding_l_arith_repr": "native", "smtencoding_nl_arith_repr": "wrapped", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [ "smt.arith.nl=false", "smt.QI.EAGER_THRESHOLD=100", "smt.CASE_SPLIT=3" ], "z3refresh": false, "z3rlimit": 20, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
s: FStar.Ghost.erased (FStar.Seq.Base.seq Vale.Def.Types_s.nat32) -> Vale.AsLowStar.ValeSig.vale_sig_stdcall (Vale.Stdcalls.X64.GCTR.gctr256_pre s) (Vale.Stdcalls.X64.GCTR.gctr256_post s)
Prims.Tot
[ "total" ]
[]
[ "FStar.Ghost.erased", "FStar.Seq.Base.seq", "Vale.Def.Types_s.nat32", "Vale.Stdcalls.X64.GCTR.as_t", "Vale.AsLowStar.ValeSig.vale_sig_stdcall", "Vale.Stdcalls.X64.GCTR.dom", "Vale.Stdcalls.X64.GCTR.gctr256_pre", "Vale.Stdcalls.X64.GCTR.gctr256_post", "Vale.Stdcalls.X64.GCTR.gctr256_lemma'" ]
[]
false
false
false
false
false
let gctr256_lemma (s: Ghost.erased (Seq.seq nat32)) =
as_t #(VSig.vale_sig_stdcall (gctr256_pre s) (gctr256_post s)) (gctr256_lemma' s)
false
MerkleTree.New.High.Correct.Base.fst
MerkleTree.New.High.Correct.Base.log2_bound
val log2_bound: n:nat{n > 0} -> c:nat{n < pow2 c} -> Lemma (log2 n <= c-1)
val log2_bound: n:nat{n > 0} -> c:nat{n < pow2 c} -> Lemma (log2 n <= c-1)
let rec log2_bound n c = if n = 1 then () else log2_bound (n / 2) (c - 1)
{ "file_name": "src/MerkleTree.New.High.Correct.Base.fst", "git_rev": "7d7bdc20f2033171e279c176b26e84f9069d23c6", "git_url": "https://github.com/hacl-star/merkle-tree.git", "project_name": "merkle-tree" }
{ "end_col": 33, "end_line": 293, "start_col": 0, "start_line": 291 }
module MerkleTree.New.High.Correct.Base open FStar.Classical open FStar.Ghost open FStar.Seq module S = FStar.Seq module MTS = MerkleTree.Spec open MerkleTree.New.High #set-options "--z3rlimit 40 --max_fuel 0 --max_ifuel 0" /// Sequence helpers val seq_prefix: #a:Type -> s1:S.seq a -> s2:S.seq a{S.length s1 <= S.length s2} -> GTot Type0 let seq_prefix #a s1 s2 = S.equal s1 (S.slice s2 0 (S.length s1)) val seq_head_cons: #a:Type -> x:a -> s:S.seq a -> Lemma (S.head (S.cons x s) == x) [SMTPat (S.cons x s)] let seq_head_cons #a x s = () val seq_tail_cons: #a:Type -> x:a -> s:S.seq a -> Lemma (S.equal (S.tail (S.cons x s)) s) [SMTPat (S.cons x s)] let seq_tail_cons #a x s = () /// Invariants and simulation relation of high-level Merkle tree design // Invariants of internal hashes val empty_hashes: (#hsz:pos) -> (len:nat) -> GTot (hs:hashess #hsz {S.length hs = len}) let empty_hashes #hsz len = S.create len S.empty val empty_hashes_head: #hsz:pos -> len:nat{len > 0} -> Lemma (S.head (empty_hashes #hsz len) == S.empty) let empty_hashes_head #_ _ = () val empty_hashes_tail: #hsz:pos -> len:nat{len > 0} -> Lemma (S.equal (S.tail (empty_hashes len)) (empty_hashes #hsz (len - 1))) let empty_hashes_tail #_ _ = () #push-options "--max_fuel 1" val mt_hashes_lth_inv: #hsz:pos -> lv:nat{lv <= 32} -> j:nat{j < pow2 (32 - lv)} -> fhs:hashess #hsz {S.length fhs = 32} -> GTot Type0 (decreases (32 - lv)) let rec mt_hashes_lth_inv #hsz lv j fhs = if lv = 32 then true else (S.length (S.index fhs lv) == j /\ mt_hashes_lth_inv (lv + 1) (j / 2) fhs) val mt_hashes_lth_inv_empty: #hsz:pos -> lv:nat{lv <= 32} -> Lemma (requires True) (ensures mt_hashes_lth_inv lv 0 (empty_hashes #hsz 32)) (decreases (32 - lv)) let rec mt_hashes_lth_inv_empty #hsz lv = if lv = 32 then () else mt_hashes_lth_inv_empty #hsz (lv + 1) val mt_hashes_next_rel: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> j:nat -> hs:hashes #hsz {S.length hs = j} -> nhs:hashes #hsz {S.length nhs = j / 2} -> GTot Type0 let mt_hashes_next_rel #hsz #f j hs nhs = forall (i:nat{i < j / 2}). S.index nhs i == f (S.index hs (op_Multiply 2 i)) (S.index hs (op_Multiply 2 i + 1)) #pop-options #push-options "--max_fuel 2" val mt_hashes_inv: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> lv:nat{lv < 32} -> j:nat{j < pow2 (32 - lv)} -> fhs:hashess #hsz {S.length fhs = 32 /\ mt_hashes_lth_inv lv j fhs} -> GTot Type0 (decreases (32 - lv)) let rec mt_hashes_inv #hsz #f lv j fhs = if lv = 31 then true else (mt_hashes_next_rel #_ #f j (S.index fhs lv) (S.index fhs (lv + 1)) /\ mt_hashes_inv #_ #f (lv + 1) (j / 2) fhs) val mt_hashes_inv_empty: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> lv:nat{lv < 32} -> Lemma (requires True) (ensures (mt_hashes_lth_inv_empty #hsz lv; mt_hashes_inv #hsz #f lv 0 (empty_hashes #hsz 32))) (decreases (32 - lv)) let rec mt_hashes_inv_empty #hsz #f lv = if lv = 31 then () else (mt_hashes_lth_inv_empty #hsz (lv + 1); mt_hashes_inv_empty #_ #f (lv + 1)) val mt_hashes_lth_inv_equiv: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> lv:nat{lv < 32} -> j:nat{j < pow2 (32 - lv)} -> fhs1:hashess{S.length fhs1 = 32} -> fhs2:hashess{S.length fhs2 = 32} -> Lemma (requires mt_hashes_lth_inv lv j fhs1 /\ S.equal (S.slice fhs1 lv 32) (S.slice fhs2 lv 32)) (ensures mt_hashes_lth_inv #hsz lv j fhs2) (decreases (32 - lv)) let rec mt_hashes_lth_inv_equiv #hsz #f lv j fhs1 fhs2 = if lv = 31 then () else (assert (S.index fhs1 lv == S.index fhs2 lv); mt_hashes_lth_inv_equiv #_ #f (lv + 1) (j / 2) fhs1 fhs2) #pop-options #push-options "--max_fuel 1" val mt_hashes_inv_equiv: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> lv:nat{lv < 32} -> j:nat{j < pow2 (32 - lv)} -> fhs1:hashess #hsz {S.length fhs1 = 32 /\ mt_hashes_lth_inv lv j fhs1} -> fhs2:hashess #hsz {S.length fhs2 = 32 /\ mt_hashes_lth_inv lv j fhs2} -> Lemma (requires mt_hashes_inv #_ #f lv j fhs1 /\ S.equal (S.slice fhs1 lv 32) (S.slice fhs2 lv 32)) (ensures mt_hashes_inv #_ #f lv j fhs2) (decreases (32 - lv)) let rec mt_hashes_inv_equiv #hsz #f lv j fhs1 fhs2 = if lv = 31 then () else (assert (S.index fhs1 lv == S.index fhs2 lv); assert (S.index fhs1 (lv + 1) == S.index fhs2 (lv + 1)); mt_hashes_inv_equiv #_ #f (lv + 1) (j / 2) fhs1 fhs2) val merge_hs: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> hs1:hashess #hsz -> hs2:hashess #hsz {S.length hs1 = S.length hs2} -> GTot (mhs:hashess #hsz {S.length mhs = S.length hs1}) (decreases (S.length hs1)) let rec merge_hs #hsz #f hs1 hs2 = if S.length hs1 = 0 then S.empty else (S.cons (S.append (S.head hs1) (S.head hs2)) (merge_hs #_ #f (S.tail hs1) (S.tail hs2))) val merge_hs_empty: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> len:nat -> Lemma (S.equal (merge_hs #_ #f (empty_hashes #hsz len) (empty_hashes #hsz len)) (empty_hashes #hsz len)) let rec merge_hs_empty #hsz #f len = if len = 0 then () else (empty_hashes_head #hsz len; empty_hashes_tail #hsz len; assert (S.equal (S.append #(hash #hsz) S.empty S.empty) (S.empty #(hash #hsz))); assert (S.equal (merge_hs #_ #f (empty_hashes len) (empty_hashes len)) (S.cons S.empty (merge_hs #_ #f (empty_hashes (len - 1)) (empty_hashes (len - 1))))); merge_hs_empty #_ #f (len - 1)) val merge_hs_index: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> hs1:hashess -> hs2:hashess{S.length hs1 = S.length hs2} -> i:nat{i < S.length hs1} -> Lemma (requires True) (ensures S.equal (S.index (merge_hs #_ #f hs1 hs2) i) (S.append (S.index hs1 i) (S.index hs2 i))) (decreases (S.length hs1)) [SMTPat (S.index (merge_hs #_ #f hs1 hs2) i)] let rec merge_hs_index #hsz #f hs1 hs2 i = if S.length hs1 = 0 then () else if i = 0 then () else merge_hs_index #_ #f (S.tail hs1) (S.tail hs2) (i - 1) val merge_hs_slice_equal: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> ahs1:hashess #hsz -> ahs2:hashess #hsz {S.length ahs1 = S.length ahs2} -> bhs1:hashess #hsz -> bhs2:hashess #hsz {S.length bhs1 = S.length bhs2} -> i:nat -> j:nat{i <= j && j <= S.length ahs1 && j <= S.length bhs1} -> Lemma (requires S.equal (S.slice ahs1 i j) (S.slice bhs1 i j) /\ S.equal (S.slice ahs2 i j) (S.slice bhs2 i j)) (ensures S.equal (S.slice (merge_hs #_ #f ahs1 ahs2) i j) (S.slice (merge_hs #_ #f bhs1 bhs2) i j)) (decreases (j - i)) let rec merge_hs_slice_equal #_ #f ahs1 ahs2 bhs1 bhs2 i j = if i = j then () else (assert (S.index ahs1 i == S.index bhs1 i); assert (S.index ahs2 i == S.index bhs2 i); merge_hs_slice_equal #_ #f ahs1 ahs2 bhs1 bhs2 (i + 1) j) val merge_hs_upd: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> hs1:hashess #hsz -> hs2:hashess #hsz {S.length hs1 = S.length hs2} -> i:nat{i < S.length hs1} -> v1:hashes #hsz -> v2:hashes #hsz -> Lemma (requires S.equal (S.append (S.index hs1 i) (S.index hs2 i)) (S.append v1 v2)) (ensures S.equal (merge_hs #_ #f hs1 hs2) (merge_hs #_ #f (S.upd hs1 i v1) (S.upd hs2 i v2))) (decreases i) let rec merge_hs_upd #_ #f hs1 hs2 i v1 v2 = if S.length hs1 = 0 then () else if i = 0 then () else merge_hs_upd #_ #f (S.tail hs1) (S.tail hs2) (i - 1) v1 v2 val mt_olds_inv: #hsz:pos -> lv:nat{lv <= 32} -> i:nat -> olds:hashess #hsz {S.length olds = 32} -> GTot Type0 (decreases (32 - lv)) let rec mt_olds_inv #hsz lv i olds = if lv = 32 then true else (let ofs = offset_of i in S.length (S.index olds lv) == ofs /\ mt_olds_inv #hsz (lv + 1) (i / 2) olds) val mt_olds_inv_equiv: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> lv:nat{lv <= 32} -> i:nat -> olds1:hashess #hsz {S.length olds1 = 32} -> olds2:hashess #hsz {S.length olds2 = 32} -> Lemma (requires mt_olds_inv #hsz lv i olds1 /\ S.equal (S.slice olds1 lv 32) (S.slice olds2 lv 32)) (ensures mt_olds_inv #hsz lv i olds2) (decreases (32 - lv)) let rec mt_olds_inv_equiv #hsz #f lv i olds1 olds2 = if lv = 32 then () else (assert (S.index olds1 lv == S.index olds2 lv); mt_olds_inv_equiv #_ #f (lv + 1) (i / 2) olds1 olds2) val mt_olds_hs_lth_inv_ok: #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 #hsz lv hs i j} -> Lemma (requires True) (ensures mt_hashes_lth_inv #hsz lv j (merge_hs #_ #f olds hs)) (decreases (32 - lv)) let rec mt_olds_hs_lth_inv_ok #hsz #f lv i j olds hs = if lv = 32 then () else (mt_olds_hs_lth_inv_ok #_ #f (lv + 1) (i / 2) (j / 2) olds hs) val mt_olds_hs_inv: #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 #hsz lv hs i j} -> GTot Type0 let mt_olds_hs_inv #hsz #f lv i j olds hs = mt_olds_hs_lth_inv_ok #_ #f lv i j olds hs; mt_hashes_inv #_ #f lv j (merge_hs #_ #f olds hs) // Relation between valid internal hashes (satisfying `mt_olds_hs_inv`) and // the spec. While giving such relation, all rightmost hashes are recovered. // Note that `MT?.rhs` after `construct_rhs` does NOT contain all rightmost // hashes; it has partial rightmost hashes that are enough to calculate // Merkle paths. val log2: n:nat{n > 0} -> GTot (c:nat{pow2 c <= n && n < pow2 (c+1)}) let rec log2 n = if n = 1 then 0 else 1 + log2 (n / 2) val log2_bound: n:nat{n > 0} -> c:nat{n < pow2 c} ->
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "MerkleTree.Spec.fst.checked", "MerkleTree.New.High.fst.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Ghost.fsti.checked", "FStar.Classical.fsti.checked" ], "interface_file": false, "source_file": "MerkleTree.New.High.Correct.Base.fst" }
[ { "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": 2, "initial_ifuel": 1, "max_fuel": 1, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 40, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
n: Prims.nat{n > 0} -> c: Prims.nat{n < Prims.pow2 c} -> FStar.Pervasives.Lemma (ensures MerkleTree.New.High.Correct.Base.log2 n <= c - 1)
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "Prims.nat", "Prims.b2t", "Prims.op_GreaterThan", "Prims.op_LessThan", "Prims.pow2", "Prims.op_Equality", "Prims.int", "Prims.bool", "MerkleTree.New.High.Correct.Base.log2_bound", "Prims.op_Division", "Prims.op_Subtraction", "Prims.unit" ]
[ "recursion" ]
false
false
true
false
false
let rec log2_bound n c =
if n = 1 then () else log2_bound (n / 2) (c - 1)
false
MerkleTree.New.High.Correct.Base.fst
MerkleTree.New.High.Correct.Base.mt_root_inv
val mt_root_inv: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> hs0:hashes #hsz {S.length hs0 > 0} -> acc:hash #hsz -> actd:bool -> rt:hash #hsz -> GTot Type0
val mt_root_inv: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> hs0:hashes #hsz {S.length hs0 > 0} -> acc:hash #hsz -> actd:bool -> rt:hash #hsz -> GTot Type0
let mt_root_inv #_ #f hs0 acc actd rt = MTS.mt_get_root #_ #f #(log2c (S.length hs0)) (hash_seq_spec_full #_ #f hs0 acc actd) == MTS.HRaw rt
{ "file_name": "src/MerkleTree.New.High.Correct.Base.fst", "git_rev": "7d7bdc20f2033171e279c176b26e84f9069d23c6", "git_url": "https://github.com/hacl-star/merkle-tree.git", "project_name": "merkle-tree" }
{ "end_col": 58, "end_line": 622, "start_col": 0, "start_line": 620 }
module MerkleTree.New.High.Correct.Base open FStar.Classical open FStar.Ghost open FStar.Seq module S = FStar.Seq module MTS = MerkleTree.Spec open MerkleTree.New.High #set-options "--z3rlimit 40 --max_fuel 0 --max_ifuel 0" /// Sequence helpers val seq_prefix: #a:Type -> s1:S.seq a -> s2:S.seq a{S.length s1 <= S.length s2} -> GTot Type0 let seq_prefix #a s1 s2 = S.equal s1 (S.slice s2 0 (S.length s1)) val seq_head_cons: #a:Type -> x:a -> s:S.seq a -> Lemma (S.head (S.cons x s) == x) [SMTPat (S.cons x s)] let seq_head_cons #a x s = () val seq_tail_cons: #a:Type -> x:a -> s:S.seq a -> Lemma (S.equal (S.tail (S.cons x s)) s) [SMTPat (S.cons x s)] let seq_tail_cons #a x s = () /// Invariants and simulation relation of high-level Merkle tree design // Invariants of internal hashes val empty_hashes: (#hsz:pos) -> (len:nat) -> GTot (hs:hashess #hsz {S.length hs = len}) let empty_hashes #hsz len = S.create len S.empty val empty_hashes_head: #hsz:pos -> len:nat{len > 0} -> Lemma (S.head (empty_hashes #hsz len) == S.empty) let empty_hashes_head #_ _ = () val empty_hashes_tail: #hsz:pos -> len:nat{len > 0} -> Lemma (S.equal (S.tail (empty_hashes len)) (empty_hashes #hsz (len - 1))) let empty_hashes_tail #_ _ = () #push-options "--max_fuel 1" val mt_hashes_lth_inv: #hsz:pos -> lv:nat{lv <= 32} -> j:nat{j < pow2 (32 - lv)} -> fhs:hashess #hsz {S.length fhs = 32} -> GTot Type0 (decreases (32 - lv)) let rec mt_hashes_lth_inv #hsz lv j fhs = if lv = 32 then true else (S.length (S.index fhs lv) == j /\ mt_hashes_lth_inv (lv + 1) (j / 2) fhs) val mt_hashes_lth_inv_empty: #hsz:pos -> lv:nat{lv <= 32} -> Lemma (requires True) (ensures mt_hashes_lth_inv lv 0 (empty_hashes #hsz 32)) (decreases (32 - lv)) let rec mt_hashes_lth_inv_empty #hsz lv = if lv = 32 then () else mt_hashes_lth_inv_empty #hsz (lv + 1) val mt_hashes_next_rel: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> j:nat -> hs:hashes #hsz {S.length hs = j} -> nhs:hashes #hsz {S.length nhs = j / 2} -> GTot Type0 let mt_hashes_next_rel #hsz #f j hs nhs = forall (i:nat{i < j / 2}). S.index nhs i == f (S.index hs (op_Multiply 2 i)) (S.index hs (op_Multiply 2 i + 1)) #pop-options #push-options "--max_fuel 2" val mt_hashes_inv: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> lv:nat{lv < 32} -> j:nat{j < pow2 (32 - lv)} -> fhs:hashess #hsz {S.length fhs = 32 /\ mt_hashes_lth_inv lv j fhs} -> GTot Type0 (decreases (32 - lv)) let rec mt_hashes_inv #hsz #f lv j fhs = if lv = 31 then true else (mt_hashes_next_rel #_ #f j (S.index fhs lv) (S.index fhs (lv + 1)) /\ mt_hashes_inv #_ #f (lv + 1) (j / 2) fhs) val mt_hashes_inv_empty: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> lv:nat{lv < 32} -> Lemma (requires True) (ensures (mt_hashes_lth_inv_empty #hsz lv; mt_hashes_inv #hsz #f lv 0 (empty_hashes #hsz 32))) (decreases (32 - lv)) let rec mt_hashes_inv_empty #hsz #f lv = if lv = 31 then () else (mt_hashes_lth_inv_empty #hsz (lv + 1); mt_hashes_inv_empty #_ #f (lv + 1)) val mt_hashes_lth_inv_equiv: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> lv:nat{lv < 32} -> j:nat{j < pow2 (32 - lv)} -> fhs1:hashess{S.length fhs1 = 32} -> fhs2:hashess{S.length fhs2 = 32} -> Lemma (requires mt_hashes_lth_inv lv j fhs1 /\ S.equal (S.slice fhs1 lv 32) (S.slice fhs2 lv 32)) (ensures mt_hashes_lth_inv #hsz lv j fhs2) (decreases (32 - lv)) let rec mt_hashes_lth_inv_equiv #hsz #f lv j fhs1 fhs2 = if lv = 31 then () else (assert (S.index fhs1 lv == S.index fhs2 lv); mt_hashes_lth_inv_equiv #_ #f (lv + 1) (j / 2) fhs1 fhs2) #pop-options #push-options "--max_fuel 1" val mt_hashes_inv_equiv: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> lv:nat{lv < 32} -> j:nat{j < pow2 (32 - lv)} -> fhs1:hashess #hsz {S.length fhs1 = 32 /\ mt_hashes_lth_inv lv j fhs1} -> fhs2:hashess #hsz {S.length fhs2 = 32 /\ mt_hashes_lth_inv lv j fhs2} -> Lemma (requires mt_hashes_inv #_ #f lv j fhs1 /\ S.equal (S.slice fhs1 lv 32) (S.slice fhs2 lv 32)) (ensures mt_hashes_inv #_ #f lv j fhs2) (decreases (32 - lv)) let rec mt_hashes_inv_equiv #hsz #f lv j fhs1 fhs2 = if lv = 31 then () else (assert (S.index fhs1 lv == S.index fhs2 lv); assert (S.index fhs1 (lv + 1) == S.index fhs2 (lv + 1)); mt_hashes_inv_equiv #_ #f (lv + 1) (j / 2) fhs1 fhs2) val merge_hs: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> hs1:hashess #hsz -> hs2:hashess #hsz {S.length hs1 = S.length hs2} -> GTot (mhs:hashess #hsz {S.length mhs = S.length hs1}) (decreases (S.length hs1)) let rec merge_hs #hsz #f hs1 hs2 = if S.length hs1 = 0 then S.empty else (S.cons (S.append (S.head hs1) (S.head hs2)) (merge_hs #_ #f (S.tail hs1) (S.tail hs2))) val merge_hs_empty: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> len:nat -> Lemma (S.equal (merge_hs #_ #f (empty_hashes #hsz len) (empty_hashes #hsz len)) (empty_hashes #hsz len)) let rec merge_hs_empty #hsz #f len = if len = 0 then () else (empty_hashes_head #hsz len; empty_hashes_tail #hsz len; assert (S.equal (S.append #(hash #hsz) S.empty S.empty) (S.empty #(hash #hsz))); assert (S.equal (merge_hs #_ #f (empty_hashes len) (empty_hashes len)) (S.cons S.empty (merge_hs #_ #f (empty_hashes (len - 1)) (empty_hashes (len - 1))))); merge_hs_empty #_ #f (len - 1)) val merge_hs_index: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> hs1:hashess -> hs2:hashess{S.length hs1 = S.length hs2} -> i:nat{i < S.length hs1} -> Lemma (requires True) (ensures S.equal (S.index (merge_hs #_ #f hs1 hs2) i) (S.append (S.index hs1 i) (S.index hs2 i))) (decreases (S.length hs1)) [SMTPat (S.index (merge_hs #_ #f hs1 hs2) i)] let rec merge_hs_index #hsz #f hs1 hs2 i = if S.length hs1 = 0 then () else if i = 0 then () else merge_hs_index #_ #f (S.tail hs1) (S.tail hs2) (i - 1) val merge_hs_slice_equal: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> ahs1:hashess #hsz -> ahs2:hashess #hsz {S.length ahs1 = S.length ahs2} -> bhs1:hashess #hsz -> bhs2:hashess #hsz {S.length bhs1 = S.length bhs2} -> i:nat -> j:nat{i <= j && j <= S.length ahs1 && j <= S.length bhs1} -> Lemma (requires S.equal (S.slice ahs1 i j) (S.slice bhs1 i j) /\ S.equal (S.slice ahs2 i j) (S.slice bhs2 i j)) (ensures S.equal (S.slice (merge_hs #_ #f ahs1 ahs2) i j) (S.slice (merge_hs #_ #f bhs1 bhs2) i j)) (decreases (j - i)) let rec merge_hs_slice_equal #_ #f ahs1 ahs2 bhs1 bhs2 i j = if i = j then () else (assert (S.index ahs1 i == S.index bhs1 i); assert (S.index ahs2 i == S.index bhs2 i); merge_hs_slice_equal #_ #f ahs1 ahs2 bhs1 bhs2 (i + 1) j) val merge_hs_upd: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> hs1:hashess #hsz -> hs2:hashess #hsz {S.length hs1 = S.length hs2} -> i:nat{i < S.length hs1} -> v1:hashes #hsz -> v2:hashes #hsz -> Lemma (requires S.equal (S.append (S.index hs1 i) (S.index hs2 i)) (S.append v1 v2)) (ensures S.equal (merge_hs #_ #f hs1 hs2) (merge_hs #_ #f (S.upd hs1 i v1) (S.upd hs2 i v2))) (decreases i) let rec merge_hs_upd #_ #f hs1 hs2 i v1 v2 = if S.length hs1 = 0 then () else if i = 0 then () else merge_hs_upd #_ #f (S.tail hs1) (S.tail hs2) (i - 1) v1 v2 val mt_olds_inv: #hsz:pos -> lv:nat{lv <= 32} -> i:nat -> olds:hashess #hsz {S.length olds = 32} -> GTot Type0 (decreases (32 - lv)) let rec mt_olds_inv #hsz lv i olds = if lv = 32 then true else (let ofs = offset_of i in S.length (S.index olds lv) == ofs /\ mt_olds_inv #hsz (lv + 1) (i / 2) olds) val mt_olds_inv_equiv: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> lv:nat{lv <= 32} -> i:nat -> olds1:hashess #hsz {S.length olds1 = 32} -> olds2:hashess #hsz {S.length olds2 = 32} -> Lemma (requires mt_olds_inv #hsz lv i olds1 /\ S.equal (S.slice olds1 lv 32) (S.slice olds2 lv 32)) (ensures mt_olds_inv #hsz lv i olds2) (decreases (32 - lv)) let rec mt_olds_inv_equiv #hsz #f lv i olds1 olds2 = if lv = 32 then () else (assert (S.index olds1 lv == S.index olds2 lv); mt_olds_inv_equiv #_ #f (lv + 1) (i / 2) olds1 olds2) val mt_olds_hs_lth_inv_ok: #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 #hsz lv hs i j} -> Lemma (requires True) (ensures mt_hashes_lth_inv #hsz lv j (merge_hs #_ #f olds hs)) (decreases (32 - lv)) let rec mt_olds_hs_lth_inv_ok #hsz #f lv i j olds hs = if lv = 32 then () else (mt_olds_hs_lth_inv_ok #_ #f (lv + 1) (i / 2) (j / 2) olds hs) val mt_olds_hs_inv: #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 #hsz lv hs i j} -> GTot Type0 let mt_olds_hs_inv #hsz #f lv i j olds hs = mt_olds_hs_lth_inv_ok #_ #f lv i j olds hs; mt_hashes_inv #_ #f lv j (merge_hs #_ #f olds hs) // Relation between valid internal hashes (satisfying `mt_olds_hs_inv`) and // the spec. While giving such relation, all rightmost hashes are recovered. // Note that `MT?.rhs` after `construct_rhs` does NOT contain all rightmost // hashes; it has partial rightmost hashes that are enough to calculate // Merkle paths. val log2: n:nat{n > 0} -> GTot (c:nat{pow2 c <= n && n < pow2 (c+1)}) let rec log2 n = if n = 1 then 0 else 1 + log2 (n / 2) val log2_bound: n:nat{n > 0} -> c:nat{n < pow2 c} -> Lemma (log2 n <= c-1) let rec log2_bound n c = if n = 1 then () else log2_bound (n / 2) (c - 1) val log2_div: n:nat{n > 1} -> Lemma (log2 (n / 2) = log2 n - 1) let log2_div n = () val log2c: n:nat -> GTot (c:nat{c = 0 || (pow2 (c-1) <= n && n < pow2 c)}) let log2c n = if n = 0 then 0 else (log2 n + 1) val log2c_div: n:nat{n > 0} -> Lemma (log2c (n / 2) = log2c n - 1) let log2c_div n = () val log2c_bound: n:nat -> c:nat{n < pow2 c} -> Lemma (log2c n <= c) let rec log2c_bound n c = if n = 0 then () else log2c_bound (n / 2) (c - 1) val mt_hashes_lth_inv_log: #hsz:pos -> j:nat -> fhs:hashess #hsz {S.length fhs = log2c j} -> GTot Type0 (decreases j) let rec mt_hashes_lth_inv_log #hsz j fhs = if j = 0 then true else (S.length (S.head fhs) == j /\ mt_hashes_lth_inv_log #hsz (j / 2) (S.tail fhs)) #pop-options #push-options "--max_fuel 2" val mt_hashes_lth_inv_log_next: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> j:nat{j > 1} -> fhs:hashess #hsz {S.length fhs = log2c j} -> Lemma (requires mt_hashes_lth_inv_log #hsz j fhs) (ensures S.length (S.head fhs) == j /\ S.length (S.head (S.tail fhs)) == j / 2) let mt_hashes_lth_inv_log_next #_ #_ _ _ = () val mt_hashes_inv_log: #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} -> GTot Type0 (decreases j) let rec mt_hashes_inv_log #hsz #f j fhs = if j <= 1 then true else (mt_hashes_next_rel #_ #f j (S.index fhs 0) (S.index fhs 1) /\ mt_hashes_inv_log #_ #f (j / 2) (S.tail fhs)) val mt_hashes_lth_inv_log_converted_: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> lv:nat{lv <= 32} -> j:nat{j < pow2 (32 - lv)} -> fhs:hashess #hsz {S.length fhs = 32} -> Lemma (requires mt_hashes_lth_inv #hsz lv j fhs) (ensures (log2c_bound j (32 - lv); mt_hashes_lth_inv_log #hsz j (S.slice fhs lv (lv + log2c j)))) (decreases j) let rec mt_hashes_lth_inv_log_converted_ #_ #f lv j fhs = if j = 0 then () else (log2c_bound (j / 2) (32 - (lv + 1)); mt_hashes_lth_inv_log_converted_ #_ #f (lv + 1) (j / 2) fhs) val mt_hashes_lth_inv_log_converted: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> j:nat{j < pow2 32} -> fhs:hashess #hsz {S.length fhs = 32} -> Lemma (requires mt_hashes_lth_inv #hsz 0 j fhs) (ensures (log2c_bound j 32; mt_hashes_lth_inv_log #hsz j (S.slice fhs 0 (log2c j)))) let mt_hashes_lth_inv_log_converted #_ #f j fhs = mt_hashes_lth_inv_log_converted_ #_ #f 0 j fhs val mt_hashes_inv_log_converted_: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> lv:nat{lv <= 32} -> j:nat{j > 0 && j < pow2 (32 - lv)} -> fhs:hashess #hsz {S.length fhs = 32 /\ mt_hashes_lth_inv #hsz lv j fhs} -> Lemma (requires mt_hashes_inv #_ #f lv j fhs) (ensures (log2c_bound j (32 - lv); mt_hashes_lth_inv_log_converted_ #_ #f lv j fhs; mt_hashes_inv_log #_ #f j (S.slice fhs lv (lv + log2c j)))) (decreases j) #pop-options #push-options "--z3rlimit 100 --initial_fuel 2 --max_fuel 2" let rec mt_hashes_inv_log_converted_ #_ #f lv j fhs = if j = 1 then () else (log2c_bound (j / 2) (32 - (lv + 1)); mt_hashes_lth_inv_log_converted_ #_ #f (lv + 1) (j / 2) fhs; mt_hashes_inv_log_converted_ #_ #f (lv + 1) (j / 2) fhs) #pop-options val mt_hashes_inv_log_converted: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> j:nat{j > 0 && j < pow2 32} -> fhs:hashess #hsz {S.length fhs = 32 /\ mt_hashes_lth_inv #hsz 0 j fhs} -> Lemma (requires mt_hashes_inv #_ #f 0 j fhs) (ensures (log2c_bound j 32; mt_hashes_lth_inv_log_converted_ #_ #f 0 j fhs; mt_hashes_inv_log #_ #f j (S.slice fhs 0 (log2c j)))) let mt_hashes_inv_log_converted #_ #f j fhs = mt_hashes_inv_log_converted_ #_ #f 0 j fhs val hash_seq_lift: #hsz:pos -> hs:hashes #hsz -> GTot (shs:MTS.hashes #hsz {S.length shs = S.length hs}) (decreases (S.length hs)) let rec hash_seq_lift #hsz hs = if S.length hs = 0 then S.empty else S.cons (MTS.HRaw (S.head hs)) (hash_seq_lift #hsz (S.tail hs)) #push-options "--z3rlimit 50 --initial_fuel 2 --max_fuel 2" val hash_seq_lift_index: #hsz:pos -> hs:hashes #hsz -> Lemma (requires True) (ensures forall (i:nat{i < S.length hs}). S.index (hash_seq_lift #hsz hs) i == MTS.HRaw (S.index hs i)) (decreases (S.length hs)) let rec hash_seq_lift_index #hsz hs = if S.length hs = 0 then () else hash_seq_lift_index #hsz (S.tail hs) #pop-options val create_pads: #hsz:pos -> len:nat -> GTot (pads:MTS.hashes #hsz {S.length pads = len}) let create_pads #hsz len = S.create len (MTS.HPad #hsz) val hash_seq_spec: #hsz:pos -> hs:hashes #hsz {S.length hs > 0} -> GTot (MTS.merkle_tree #hsz (log2c (S.length hs))) let hash_seq_spec #hsz hs = S.append (hash_seq_lift #hsz hs) (create_pads (pow2 (log2c (S.length hs)) - S.length hs)) val hash_seq_spec_index_raw: #hsz:pos -> hs:hashes #hsz {S.length hs > 0} -> i:nat{i < S.length hs} -> Lemma (S.index (hash_seq_spec #hsz hs) i == MTS.HRaw #hsz (S.index hs i)) let hash_seq_spec_index_raw #hsz hs i = hash_seq_lift_index #hsz hs // Now about recovering rightmost hashes #push-options "--z3rlimit 50 --initial_fuel 1 --max_fuel 1" val mt_hashes_next_rel_lift_even: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> j:nat{j > 1} -> hs:hashes #hsz {S.length hs = j} -> nhs:hashes #hsz {S.length nhs = j / 2} -> Lemma (requires j % 2 = 0 /\ mt_hashes_next_rel #_ #f j hs nhs) (ensures MTS.mt_next_rel #_ #f (log2c j) (hash_seq_spec #hsz hs) (hash_seq_spec #hsz nhs)) let mt_hashes_next_rel_lift_even #hsz #_ j hs nhs = hash_seq_lift_index #hsz hs; hash_seq_lift_index #hsz nhs val mt_hashes_next_rel_lift_odd: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> j:nat{j > 1} -> hs:hashes #hsz {S.length hs = j} -> nhs:hashes #hsz {S.length nhs = j / 2} -> Lemma (requires j % 2 = 1 /\ mt_hashes_next_rel #_ #f j hs nhs) (ensures MTS.mt_next_rel #_ #f (log2c j) (hash_seq_spec #hsz hs) (S.upd (hash_seq_spec #hsz nhs) (S.length nhs) (MTS.HRaw (S.last hs)))) let mt_hashes_next_rel_lift_odd #hsz #_ j hs nhs = log2c_div j; hash_seq_lift_index #hsz hs; hash_seq_lift_index #hsz nhs val mt_hashes_next_rel_next_even: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> j:nat{j > 1} -> hs:hashes #hsz {S.length hs = j} -> nhs:hashes #hsz {S.length nhs = j / 2} -> Lemma (requires j % 2 = 0 /\ mt_hashes_next_rel #_ #f j hs nhs) (ensures S.equal (hash_seq_spec #hsz nhs) (MTS.mt_next_lv #_ #f #(log2c j) (hash_seq_spec #hsz hs))) let mt_hashes_next_rel_next_even #hsz #f j hs nhs = log2c_div j; mt_hashes_next_rel_lift_even #_ #f j hs nhs; MTS.mt_next_rel_next_lv #_ #f (log2c j) (hash_seq_spec #hsz hs) (hash_seq_spec #hsz nhs) val hash_seq_spec_full: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> hs:hashes #hsz {S.length hs > 0} -> acc:hash #hsz -> actd:bool -> GTot (MTS.merkle_tree #hsz (log2c (S.length hs))) let hash_seq_spec_full #hsz #f hs acc actd = if actd then (S.upd (hash_seq_spec #hsz hs) (S.length hs) (MTS.HRaw acc)) else hash_seq_spec #hsz hs val hash_seq_spec_full_index_raw: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> hs:hashes #hsz {S.length hs > 0} -> acc:hash #hsz -> actd:bool -> i:nat{i < S.length hs} -> Lemma (S.index (hash_seq_spec_full #_ #f hs acc actd) i == MTS.HRaw (S.index hs i)) let hash_seq_spec_full_index_raw #hsz #_ hs acc actd i = hash_seq_spec_index_raw #hsz hs i val hash_seq_spec_full_case_true: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> hs:hashes #hsz {S.length hs > 0} -> acc:hash #hsz -> Lemma (S.index (hash_seq_spec_full #_ #f hs acc true) (S.length hs) == MTS.HRaw acc) let hash_seq_spec_full_case_true #_ #_ _ _ = () val hash_seq_spec_full_even_next: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> j:nat{j > 0} -> hs:hashes #hsz {S.length hs = j} -> nhs:hashes #hsz {S.length nhs = j / 2} -> acc:hash #hsz -> actd:bool -> Lemma (requires j % 2 = 0 /\ mt_hashes_next_rel #_ #f j hs nhs) (ensures S.equal (hash_seq_spec_full #_ #f nhs acc actd) (MTS.mt_next_lv #_ #f #(log2c j) (hash_seq_spec_full #_ #f hs acc actd))) #restart-solver #push-options "--quake 1/3 --z3rlimit 100 --fuel 2 --ifuel 1" let hash_seq_spec_full_even_next #hsz #f j hs nhs acc actd = log2c_div j; mt_hashes_next_rel_lift_even #_ #f j hs nhs; if actd then begin MTS.mt_next_rel_upd_even_pad #_ #f (log2c j) (hash_seq_spec #hsz hs) (hash_seq_spec #hsz nhs) (S.length hs / 2) (MTS.HRaw acc); let n = log2c j in let mt = S.upd (hash_seq_spec #hsz hs) (S.length hs) (MTS.HRaw acc) in let nmt = S.upd (hash_seq_spec #hsz nhs) (S.length nhs) (MTS.HRaw acc) in // assume (MTS.mt_next_rel #_ #f n mt nmt); MTS.mt_next_rel_next_lv #_ #f n mt nmt end else MTS.mt_next_rel_next_lv #_ #f (log2c j) (hash_seq_spec_full #_ #f hs acc actd) (hash_seq_spec_full #_ #f nhs acc actd) #pop-options #push-options "--z3rlimit 80" val hash_seq_spec_full_odd_next: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> j:nat{j > 1} -> hs:hashes #hsz {S.length hs = j} -> nhs:hashes #hsz {S.length nhs = j / 2} -> acc:hash #hsz -> actd:bool -> nacc:hash #hsz -> Lemma (requires j % 2 = 1 /\ mt_hashes_next_rel #_ #f j hs nhs /\ nacc == (if actd then f (S.last hs) acc else S.last hs)) (ensures S.equal (hash_seq_spec_full #_ #f nhs nacc true) (MTS.mt_next_lv #_ #f #(log2c j) (hash_seq_spec_full #_ #f hs acc actd))) let hash_seq_spec_full_odd_next #hsz #f j hs nhs acc actd nacc = log2c_div j; mt_hashes_next_rel_lift_odd #_ #f j hs nhs; if actd then begin MTS.mt_next_rel_upd_odd #_ #f (log2c j) (hash_seq_spec #hsz hs) (S.upd (hash_seq_spec #hsz nhs) (S.length nhs) (MTS.HRaw (S.last hs))) (S.length nhs) (MTS.HRaw acc); MTS.mt_next_rel_next_lv #_ #f (log2c j) (S.upd (hash_seq_spec #hsz hs) (S.length hs) (MTS.HRaw acc)) (S.upd (hash_seq_spec #hsz nhs) (S.length nhs) (MTS.HRaw (f (S.last hs) acc))) end else MTS.mt_next_rel_next_lv #_ #f (log2c j) (hash_seq_spec_full #_ #f hs acc actd) (hash_seq_spec_full #_ #f nhs nacc true) #pop-options val hash_seq_spec_full_next: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> j:nat{j > 1} -> hs:hashes #hsz {S.length hs = j} -> nhs:hashes #hsz {S.length nhs = j / 2} -> acc:hash #hsz -> actd:bool -> nacc:hash #hsz -> nactd:bool -> Lemma (requires mt_hashes_next_rel #_ #f j hs nhs /\ nacc == (if j % 2 = 0 then acc else if actd then f (S.last hs) acc else S.last hs) /\ nactd == (actd || j % 2 = 1)) (ensures S.equal (hash_seq_spec_full #_ #f nhs nacc nactd) (MTS.mt_next_lv #_ #f #(log2c j) (hash_seq_spec_full #_ #f hs acc actd))) let hash_seq_spec_full_next #_ #f j hs nhs acc actd nacc nactd = if j % 2 = 0 then hash_seq_spec_full_even_next #_ #f j hs nhs acc actd else hash_seq_spec_full_odd_next #_ #f j hs nhs acc actd nacc val mt_rhs_inv: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> j:nat -> smt:MTS.merkle_tree #hsz (log2c j) -> rhs:hashes #hsz {S.length rhs = log2c j} -> actd:bool -> GTot Type0 (decreases j) let rec mt_rhs_inv #_ #f j smt rhs actd = if j = 0 then true else begin (if j % 2 = 1 && actd then (S.index smt j == MTS.HRaw (S.head rhs)) else true) /\ mt_rhs_inv #_ #f (j / 2) (MTS.mt_next_lv #_ #f #(log2c j) smt) (S.tail rhs) (actd || (j % 2 = 1)) end val mt_root_inv: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> hs0:hashes #hsz {S.length hs0 > 0} -> acc:hash #hsz -> actd:bool -> rt:hash #hsz ->
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "MerkleTree.Spec.fst.checked", "MerkleTree.New.High.fst.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Ghost.fsti.checked", "FStar.Classical.fsti.checked" ], "interface_file": false, "source_file": "MerkleTree.New.High.Correct.Base.fst" }
[ { "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": 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": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
hs0: MerkleTree.New.High.hashes{FStar.Seq.Base.length hs0 > 0} -> acc: MerkleTree.New.High.hash -> actd: Prims.bool -> rt: MerkleTree.New.High.hash -> Prims.GTot Type0
Prims.GTot
[ "sometrivial" ]
[]
[ "Prims.pos", "MerkleTree.Spec.hash_fun_t", "MerkleTree.New.High.hashes", "Prims.b2t", "Prims.op_GreaterThan", "FStar.Seq.Base.length", "MerkleTree.New.High.hash", "Prims.bool", "Prims.eq2", "MerkleTree.Spec.padded_hash", "MerkleTree.Spec.mt_get_root", "MerkleTree.New.High.Correct.Base.log2c", "MerkleTree.New.High.Correct.Base.hash_seq_spec_full", "MerkleTree.Spec.HRaw" ]
[]
false
false
false
false
true
let mt_root_inv #_ #f hs0 acc actd rt =
MTS.mt_get_root #_ #f #(log2c (S.length hs0)) (hash_seq_spec_full #_ #f hs0 acc actd) == MTS.HRaw rt
false
MerkleTree.New.High.Correct.Base.fst
MerkleTree.New.High.Correct.Base.mt_hashes_lth_inv_log
val mt_hashes_lth_inv_log: #hsz:pos -> j:nat -> fhs:hashess #hsz {S.length fhs = log2c j} -> GTot Type0 (decreases j)
val mt_hashes_lth_inv_log: #hsz:pos -> j:nat -> fhs:hashess #hsz {S.length fhs = log2c j} -> GTot Type0 (decreases j)
let rec mt_hashes_lth_inv_log #hsz j fhs = if j = 0 then true else (S.length (S.head fhs) == j /\ mt_hashes_lth_inv_log #hsz (j / 2) (S.tail fhs))
{ "file_name": "src/MerkleTree.New.High.Correct.Base.fst", "git_rev": "7d7bdc20f2033171e279c176b26e84f9069d23c6", "git_url": "https://github.com/hacl-star/merkle-tree.git", "project_name": "merkle-tree" }
{ "end_col": 55, "end_line": 326, "start_col": 0, "start_line": 323 }
module MerkleTree.New.High.Correct.Base open FStar.Classical open FStar.Ghost open FStar.Seq module S = FStar.Seq module MTS = MerkleTree.Spec open MerkleTree.New.High #set-options "--z3rlimit 40 --max_fuel 0 --max_ifuel 0" /// Sequence helpers val seq_prefix: #a:Type -> s1:S.seq a -> s2:S.seq a{S.length s1 <= S.length s2} -> GTot Type0 let seq_prefix #a s1 s2 = S.equal s1 (S.slice s2 0 (S.length s1)) val seq_head_cons: #a:Type -> x:a -> s:S.seq a -> Lemma (S.head (S.cons x s) == x) [SMTPat (S.cons x s)] let seq_head_cons #a x s = () val seq_tail_cons: #a:Type -> x:a -> s:S.seq a -> Lemma (S.equal (S.tail (S.cons x s)) s) [SMTPat (S.cons x s)] let seq_tail_cons #a x s = () /// Invariants and simulation relation of high-level Merkle tree design // Invariants of internal hashes val empty_hashes: (#hsz:pos) -> (len:nat) -> GTot (hs:hashess #hsz {S.length hs = len}) let empty_hashes #hsz len = S.create len S.empty val empty_hashes_head: #hsz:pos -> len:nat{len > 0} -> Lemma (S.head (empty_hashes #hsz len) == S.empty) let empty_hashes_head #_ _ = () val empty_hashes_tail: #hsz:pos -> len:nat{len > 0} -> Lemma (S.equal (S.tail (empty_hashes len)) (empty_hashes #hsz (len - 1))) let empty_hashes_tail #_ _ = () #push-options "--max_fuel 1" val mt_hashes_lth_inv: #hsz:pos -> lv:nat{lv <= 32} -> j:nat{j < pow2 (32 - lv)} -> fhs:hashess #hsz {S.length fhs = 32} -> GTot Type0 (decreases (32 - lv)) let rec mt_hashes_lth_inv #hsz lv j fhs = if lv = 32 then true else (S.length (S.index fhs lv) == j /\ mt_hashes_lth_inv (lv + 1) (j / 2) fhs) val mt_hashes_lth_inv_empty: #hsz:pos -> lv:nat{lv <= 32} -> Lemma (requires True) (ensures mt_hashes_lth_inv lv 0 (empty_hashes #hsz 32)) (decreases (32 - lv)) let rec mt_hashes_lth_inv_empty #hsz lv = if lv = 32 then () else mt_hashes_lth_inv_empty #hsz (lv + 1) val mt_hashes_next_rel: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> j:nat -> hs:hashes #hsz {S.length hs = j} -> nhs:hashes #hsz {S.length nhs = j / 2} -> GTot Type0 let mt_hashes_next_rel #hsz #f j hs nhs = forall (i:nat{i < j / 2}). S.index nhs i == f (S.index hs (op_Multiply 2 i)) (S.index hs (op_Multiply 2 i + 1)) #pop-options #push-options "--max_fuel 2" val mt_hashes_inv: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> lv:nat{lv < 32} -> j:nat{j < pow2 (32 - lv)} -> fhs:hashess #hsz {S.length fhs = 32 /\ mt_hashes_lth_inv lv j fhs} -> GTot Type0 (decreases (32 - lv)) let rec mt_hashes_inv #hsz #f lv j fhs = if lv = 31 then true else (mt_hashes_next_rel #_ #f j (S.index fhs lv) (S.index fhs (lv + 1)) /\ mt_hashes_inv #_ #f (lv + 1) (j / 2) fhs) val mt_hashes_inv_empty: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> lv:nat{lv < 32} -> Lemma (requires True) (ensures (mt_hashes_lth_inv_empty #hsz lv; mt_hashes_inv #hsz #f lv 0 (empty_hashes #hsz 32))) (decreases (32 - lv)) let rec mt_hashes_inv_empty #hsz #f lv = if lv = 31 then () else (mt_hashes_lth_inv_empty #hsz (lv + 1); mt_hashes_inv_empty #_ #f (lv + 1)) val mt_hashes_lth_inv_equiv: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> lv:nat{lv < 32} -> j:nat{j < pow2 (32 - lv)} -> fhs1:hashess{S.length fhs1 = 32} -> fhs2:hashess{S.length fhs2 = 32} -> Lemma (requires mt_hashes_lth_inv lv j fhs1 /\ S.equal (S.slice fhs1 lv 32) (S.slice fhs2 lv 32)) (ensures mt_hashes_lth_inv #hsz lv j fhs2) (decreases (32 - lv)) let rec mt_hashes_lth_inv_equiv #hsz #f lv j fhs1 fhs2 = if lv = 31 then () else (assert (S.index fhs1 lv == S.index fhs2 lv); mt_hashes_lth_inv_equiv #_ #f (lv + 1) (j / 2) fhs1 fhs2) #pop-options #push-options "--max_fuel 1" val mt_hashes_inv_equiv: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> lv:nat{lv < 32} -> j:nat{j < pow2 (32 - lv)} -> fhs1:hashess #hsz {S.length fhs1 = 32 /\ mt_hashes_lth_inv lv j fhs1} -> fhs2:hashess #hsz {S.length fhs2 = 32 /\ mt_hashes_lth_inv lv j fhs2} -> Lemma (requires mt_hashes_inv #_ #f lv j fhs1 /\ S.equal (S.slice fhs1 lv 32) (S.slice fhs2 lv 32)) (ensures mt_hashes_inv #_ #f lv j fhs2) (decreases (32 - lv)) let rec mt_hashes_inv_equiv #hsz #f lv j fhs1 fhs2 = if lv = 31 then () else (assert (S.index fhs1 lv == S.index fhs2 lv); assert (S.index fhs1 (lv + 1) == S.index fhs2 (lv + 1)); mt_hashes_inv_equiv #_ #f (lv + 1) (j / 2) fhs1 fhs2) val merge_hs: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> hs1:hashess #hsz -> hs2:hashess #hsz {S.length hs1 = S.length hs2} -> GTot (mhs:hashess #hsz {S.length mhs = S.length hs1}) (decreases (S.length hs1)) let rec merge_hs #hsz #f hs1 hs2 = if S.length hs1 = 0 then S.empty else (S.cons (S.append (S.head hs1) (S.head hs2)) (merge_hs #_ #f (S.tail hs1) (S.tail hs2))) val merge_hs_empty: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> len:nat -> Lemma (S.equal (merge_hs #_ #f (empty_hashes #hsz len) (empty_hashes #hsz len)) (empty_hashes #hsz len)) let rec merge_hs_empty #hsz #f len = if len = 0 then () else (empty_hashes_head #hsz len; empty_hashes_tail #hsz len; assert (S.equal (S.append #(hash #hsz) S.empty S.empty) (S.empty #(hash #hsz))); assert (S.equal (merge_hs #_ #f (empty_hashes len) (empty_hashes len)) (S.cons S.empty (merge_hs #_ #f (empty_hashes (len - 1)) (empty_hashes (len - 1))))); merge_hs_empty #_ #f (len - 1)) val merge_hs_index: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> hs1:hashess -> hs2:hashess{S.length hs1 = S.length hs2} -> i:nat{i < S.length hs1} -> Lemma (requires True) (ensures S.equal (S.index (merge_hs #_ #f hs1 hs2) i) (S.append (S.index hs1 i) (S.index hs2 i))) (decreases (S.length hs1)) [SMTPat (S.index (merge_hs #_ #f hs1 hs2) i)] let rec merge_hs_index #hsz #f hs1 hs2 i = if S.length hs1 = 0 then () else if i = 0 then () else merge_hs_index #_ #f (S.tail hs1) (S.tail hs2) (i - 1) val merge_hs_slice_equal: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> ahs1:hashess #hsz -> ahs2:hashess #hsz {S.length ahs1 = S.length ahs2} -> bhs1:hashess #hsz -> bhs2:hashess #hsz {S.length bhs1 = S.length bhs2} -> i:nat -> j:nat{i <= j && j <= S.length ahs1 && j <= S.length bhs1} -> Lemma (requires S.equal (S.slice ahs1 i j) (S.slice bhs1 i j) /\ S.equal (S.slice ahs2 i j) (S.slice bhs2 i j)) (ensures S.equal (S.slice (merge_hs #_ #f ahs1 ahs2) i j) (S.slice (merge_hs #_ #f bhs1 bhs2) i j)) (decreases (j - i)) let rec merge_hs_slice_equal #_ #f ahs1 ahs2 bhs1 bhs2 i j = if i = j then () else (assert (S.index ahs1 i == S.index bhs1 i); assert (S.index ahs2 i == S.index bhs2 i); merge_hs_slice_equal #_ #f ahs1 ahs2 bhs1 bhs2 (i + 1) j) val merge_hs_upd: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> hs1:hashess #hsz -> hs2:hashess #hsz {S.length hs1 = S.length hs2} -> i:nat{i < S.length hs1} -> v1:hashes #hsz -> v2:hashes #hsz -> Lemma (requires S.equal (S.append (S.index hs1 i) (S.index hs2 i)) (S.append v1 v2)) (ensures S.equal (merge_hs #_ #f hs1 hs2) (merge_hs #_ #f (S.upd hs1 i v1) (S.upd hs2 i v2))) (decreases i) let rec merge_hs_upd #_ #f hs1 hs2 i v1 v2 = if S.length hs1 = 0 then () else if i = 0 then () else merge_hs_upd #_ #f (S.tail hs1) (S.tail hs2) (i - 1) v1 v2 val mt_olds_inv: #hsz:pos -> lv:nat{lv <= 32} -> i:nat -> olds:hashess #hsz {S.length olds = 32} -> GTot Type0 (decreases (32 - lv)) let rec mt_olds_inv #hsz lv i olds = if lv = 32 then true else (let ofs = offset_of i in S.length (S.index olds lv) == ofs /\ mt_olds_inv #hsz (lv + 1) (i / 2) olds) val mt_olds_inv_equiv: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> lv:nat{lv <= 32} -> i:nat -> olds1:hashess #hsz {S.length olds1 = 32} -> olds2:hashess #hsz {S.length olds2 = 32} -> Lemma (requires mt_olds_inv #hsz lv i olds1 /\ S.equal (S.slice olds1 lv 32) (S.slice olds2 lv 32)) (ensures mt_olds_inv #hsz lv i olds2) (decreases (32 - lv)) let rec mt_olds_inv_equiv #hsz #f lv i olds1 olds2 = if lv = 32 then () else (assert (S.index olds1 lv == S.index olds2 lv); mt_olds_inv_equiv #_ #f (lv + 1) (i / 2) olds1 olds2) val mt_olds_hs_lth_inv_ok: #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 #hsz lv hs i j} -> Lemma (requires True) (ensures mt_hashes_lth_inv #hsz lv j (merge_hs #_ #f olds hs)) (decreases (32 - lv)) let rec mt_olds_hs_lth_inv_ok #hsz #f lv i j olds hs = if lv = 32 then () else (mt_olds_hs_lth_inv_ok #_ #f (lv + 1) (i / 2) (j / 2) olds hs) val mt_olds_hs_inv: #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 #hsz lv hs i j} -> GTot Type0 let mt_olds_hs_inv #hsz #f lv i j olds hs = mt_olds_hs_lth_inv_ok #_ #f lv i j olds hs; mt_hashes_inv #_ #f lv j (merge_hs #_ #f olds hs) // Relation between valid internal hashes (satisfying `mt_olds_hs_inv`) and // the spec. While giving such relation, all rightmost hashes are recovered. // Note that `MT?.rhs` after `construct_rhs` does NOT contain all rightmost // hashes; it has partial rightmost hashes that are enough to calculate // Merkle paths. val log2: n:nat{n > 0} -> GTot (c:nat{pow2 c <= n && n < pow2 (c+1)}) let rec log2 n = if n = 1 then 0 else 1 + log2 (n / 2) val log2_bound: n:nat{n > 0} -> c:nat{n < pow2 c} -> Lemma (log2 n <= c-1) let rec log2_bound n c = if n = 1 then () else log2_bound (n / 2) (c - 1) val log2_div: n:nat{n > 1} -> Lemma (log2 (n / 2) = log2 n - 1) let log2_div n = () val log2c: n:nat -> GTot (c:nat{c = 0 || (pow2 (c-1) <= n && n < pow2 c)}) let log2c n = if n = 0 then 0 else (log2 n + 1) val log2c_div: n:nat{n > 0} -> Lemma (log2c (n / 2) = log2c n - 1) let log2c_div n = () val log2c_bound: n:nat -> c:nat{n < pow2 c} -> Lemma (log2c n <= c) let rec log2c_bound n c = if n = 0 then () else log2c_bound (n / 2) (c - 1) val mt_hashes_lth_inv_log: #hsz:pos -> j:nat -> fhs:hashess #hsz {S.length fhs = log2c j} ->
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "MerkleTree.Spec.fst.checked", "MerkleTree.New.High.fst.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Ghost.fsti.checked", "FStar.Classical.fsti.checked" ], "interface_file": false, "source_file": "MerkleTree.New.High.Correct.Base.fst" }
[ { "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": 2, "initial_ifuel": 1, "max_fuel": 1, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 40, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
j: Prims.nat -> fhs: MerkleTree.New.High.hashess {FStar.Seq.Base.length fhs = MerkleTree.New.High.Correct.Base.log2c j} -> Prims.GTot Type0
Prims.GTot
[ "sometrivial", "" ]
[]
[ "Prims.pos", "Prims.nat", "MerkleTree.New.High.hashess", "Prims.b2t", "Prims.op_Equality", "FStar.Seq.Base.length", "MerkleTree.New.High.hashes", "MerkleTree.New.High.Correct.Base.log2c", "Prims.int", "Prims.bool", "Prims.l_and", "Prims.eq2", "MerkleTree.New.High.hash", "FStar.Seq.Properties.head", "MerkleTree.New.High.Correct.Base.mt_hashes_lth_inv_log", "Prims.op_Division", "FStar.Seq.Properties.tail" ]
[ "recursion" ]
false
false
false
false
true
let rec mt_hashes_lth_inv_log #hsz j fhs =
if j = 0 then true else (S.length (S.head fhs) == j /\ mt_hashes_lth_inv_log #hsz (j / 2) (S.tail fhs))
false
MerkleTree.New.High.Correct.Base.fst
MerkleTree.New.High.Correct.Base.log2c
val log2c: n:nat -> GTot (c:nat{c = 0 || (pow2 (c-1) <= n && n < pow2 c)})
val log2c: n:nat -> GTot (c:nat{c = 0 || (pow2 (c-1) <= n && n < pow2 c)})
let log2c n = if n = 0 then 0 else (log2 n + 1)
{ "file_name": "src/MerkleTree.New.High.Correct.Base.fst", "git_rev": "7d7bdc20f2033171e279c176b26e84f9069d23c6", "git_url": "https://github.com/hacl-star/merkle-tree.git", "project_name": "merkle-tree" }
{ "end_col": 35, "end_line": 304, "start_col": 0, "start_line": 303 }
module MerkleTree.New.High.Correct.Base open FStar.Classical open FStar.Ghost open FStar.Seq module S = FStar.Seq module MTS = MerkleTree.Spec open MerkleTree.New.High #set-options "--z3rlimit 40 --max_fuel 0 --max_ifuel 0" /// Sequence helpers val seq_prefix: #a:Type -> s1:S.seq a -> s2:S.seq a{S.length s1 <= S.length s2} -> GTot Type0 let seq_prefix #a s1 s2 = S.equal s1 (S.slice s2 0 (S.length s1)) val seq_head_cons: #a:Type -> x:a -> s:S.seq a -> Lemma (S.head (S.cons x s) == x) [SMTPat (S.cons x s)] let seq_head_cons #a x s = () val seq_tail_cons: #a:Type -> x:a -> s:S.seq a -> Lemma (S.equal (S.tail (S.cons x s)) s) [SMTPat (S.cons x s)] let seq_tail_cons #a x s = () /// Invariants and simulation relation of high-level Merkle tree design // Invariants of internal hashes val empty_hashes: (#hsz:pos) -> (len:nat) -> GTot (hs:hashess #hsz {S.length hs = len}) let empty_hashes #hsz len = S.create len S.empty val empty_hashes_head: #hsz:pos -> len:nat{len > 0} -> Lemma (S.head (empty_hashes #hsz len) == S.empty) let empty_hashes_head #_ _ = () val empty_hashes_tail: #hsz:pos -> len:nat{len > 0} -> Lemma (S.equal (S.tail (empty_hashes len)) (empty_hashes #hsz (len - 1))) let empty_hashes_tail #_ _ = () #push-options "--max_fuel 1" val mt_hashes_lth_inv: #hsz:pos -> lv:nat{lv <= 32} -> j:nat{j < pow2 (32 - lv)} -> fhs:hashess #hsz {S.length fhs = 32} -> GTot Type0 (decreases (32 - lv)) let rec mt_hashes_lth_inv #hsz lv j fhs = if lv = 32 then true else (S.length (S.index fhs lv) == j /\ mt_hashes_lth_inv (lv + 1) (j / 2) fhs) val mt_hashes_lth_inv_empty: #hsz:pos -> lv:nat{lv <= 32} -> Lemma (requires True) (ensures mt_hashes_lth_inv lv 0 (empty_hashes #hsz 32)) (decreases (32 - lv)) let rec mt_hashes_lth_inv_empty #hsz lv = if lv = 32 then () else mt_hashes_lth_inv_empty #hsz (lv + 1) val mt_hashes_next_rel: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> j:nat -> hs:hashes #hsz {S.length hs = j} -> nhs:hashes #hsz {S.length nhs = j / 2} -> GTot Type0 let mt_hashes_next_rel #hsz #f j hs nhs = forall (i:nat{i < j / 2}). S.index nhs i == f (S.index hs (op_Multiply 2 i)) (S.index hs (op_Multiply 2 i + 1)) #pop-options #push-options "--max_fuel 2" val mt_hashes_inv: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> lv:nat{lv < 32} -> j:nat{j < pow2 (32 - lv)} -> fhs:hashess #hsz {S.length fhs = 32 /\ mt_hashes_lth_inv lv j fhs} -> GTot Type0 (decreases (32 - lv)) let rec mt_hashes_inv #hsz #f lv j fhs = if lv = 31 then true else (mt_hashes_next_rel #_ #f j (S.index fhs lv) (S.index fhs (lv + 1)) /\ mt_hashes_inv #_ #f (lv + 1) (j / 2) fhs) val mt_hashes_inv_empty: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> lv:nat{lv < 32} -> Lemma (requires True) (ensures (mt_hashes_lth_inv_empty #hsz lv; mt_hashes_inv #hsz #f lv 0 (empty_hashes #hsz 32))) (decreases (32 - lv)) let rec mt_hashes_inv_empty #hsz #f lv = if lv = 31 then () else (mt_hashes_lth_inv_empty #hsz (lv + 1); mt_hashes_inv_empty #_ #f (lv + 1)) val mt_hashes_lth_inv_equiv: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> lv:nat{lv < 32} -> j:nat{j < pow2 (32 - lv)} -> fhs1:hashess{S.length fhs1 = 32} -> fhs2:hashess{S.length fhs2 = 32} -> Lemma (requires mt_hashes_lth_inv lv j fhs1 /\ S.equal (S.slice fhs1 lv 32) (S.slice fhs2 lv 32)) (ensures mt_hashes_lth_inv #hsz lv j fhs2) (decreases (32 - lv)) let rec mt_hashes_lth_inv_equiv #hsz #f lv j fhs1 fhs2 = if lv = 31 then () else (assert (S.index fhs1 lv == S.index fhs2 lv); mt_hashes_lth_inv_equiv #_ #f (lv + 1) (j / 2) fhs1 fhs2) #pop-options #push-options "--max_fuel 1" val mt_hashes_inv_equiv: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> lv:nat{lv < 32} -> j:nat{j < pow2 (32 - lv)} -> fhs1:hashess #hsz {S.length fhs1 = 32 /\ mt_hashes_lth_inv lv j fhs1} -> fhs2:hashess #hsz {S.length fhs2 = 32 /\ mt_hashes_lth_inv lv j fhs2} -> Lemma (requires mt_hashes_inv #_ #f lv j fhs1 /\ S.equal (S.slice fhs1 lv 32) (S.slice fhs2 lv 32)) (ensures mt_hashes_inv #_ #f lv j fhs2) (decreases (32 - lv)) let rec mt_hashes_inv_equiv #hsz #f lv j fhs1 fhs2 = if lv = 31 then () else (assert (S.index fhs1 lv == S.index fhs2 lv); assert (S.index fhs1 (lv + 1) == S.index fhs2 (lv + 1)); mt_hashes_inv_equiv #_ #f (lv + 1) (j / 2) fhs1 fhs2) val merge_hs: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> hs1:hashess #hsz -> hs2:hashess #hsz {S.length hs1 = S.length hs2} -> GTot (mhs:hashess #hsz {S.length mhs = S.length hs1}) (decreases (S.length hs1)) let rec merge_hs #hsz #f hs1 hs2 = if S.length hs1 = 0 then S.empty else (S.cons (S.append (S.head hs1) (S.head hs2)) (merge_hs #_ #f (S.tail hs1) (S.tail hs2))) val merge_hs_empty: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> len:nat -> Lemma (S.equal (merge_hs #_ #f (empty_hashes #hsz len) (empty_hashes #hsz len)) (empty_hashes #hsz len)) let rec merge_hs_empty #hsz #f len = if len = 0 then () else (empty_hashes_head #hsz len; empty_hashes_tail #hsz len; assert (S.equal (S.append #(hash #hsz) S.empty S.empty) (S.empty #(hash #hsz))); assert (S.equal (merge_hs #_ #f (empty_hashes len) (empty_hashes len)) (S.cons S.empty (merge_hs #_ #f (empty_hashes (len - 1)) (empty_hashes (len - 1))))); merge_hs_empty #_ #f (len - 1)) val merge_hs_index: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> hs1:hashess -> hs2:hashess{S.length hs1 = S.length hs2} -> i:nat{i < S.length hs1} -> Lemma (requires True) (ensures S.equal (S.index (merge_hs #_ #f hs1 hs2) i) (S.append (S.index hs1 i) (S.index hs2 i))) (decreases (S.length hs1)) [SMTPat (S.index (merge_hs #_ #f hs1 hs2) i)] let rec merge_hs_index #hsz #f hs1 hs2 i = if S.length hs1 = 0 then () else if i = 0 then () else merge_hs_index #_ #f (S.tail hs1) (S.tail hs2) (i - 1) val merge_hs_slice_equal: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> ahs1:hashess #hsz -> ahs2:hashess #hsz {S.length ahs1 = S.length ahs2} -> bhs1:hashess #hsz -> bhs2:hashess #hsz {S.length bhs1 = S.length bhs2} -> i:nat -> j:nat{i <= j && j <= S.length ahs1 && j <= S.length bhs1} -> Lemma (requires S.equal (S.slice ahs1 i j) (S.slice bhs1 i j) /\ S.equal (S.slice ahs2 i j) (S.slice bhs2 i j)) (ensures S.equal (S.slice (merge_hs #_ #f ahs1 ahs2) i j) (S.slice (merge_hs #_ #f bhs1 bhs2) i j)) (decreases (j - i)) let rec merge_hs_slice_equal #_ #f ahs1 ahs2 bhs1 bhs2 i j = if i = j then () else (assert (S.index ahs1 i == S.index bhs1 i); assert (S.index ahs2 i == S.index bhs2 i); merge_hs_slice_equal #_ #f ahs1 ahs2 bhs1 bhs2 (i + 1) j) val merge_hs_upd: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> hs1:hashess #hsz -> hs2:hashess #hsz {S.length hs1 = S.length hs2} -> i:nat{i < S.length hs1} -> v1:hashes #hsz -> v2:hashes #hsz -> Lemma (requires S.equal (S.append (S.index hs1 i) (S.index hs2 i)) (S.append v1 v2)) (ensures S.equal (merge_hs #_ #f hs1 hs2) (merge_hs #_ #f (S.upd hs1 i v1) (S.upd hs2 i v2))) (decreases i) let rec merge_hs_upd #_ #f hs1 hs2 i v1 v2 = if S.length hs1 = 0 then () else if i = 0 then () else merge_hs_upd #_ #f (S.tail hs1) (S.tail hs2) (i - 1) v1 v2 val mt_olds_inv: #hsz:pos -> lv:nat{lv <= 32} -> i:nat -> olds:hashess #hsz {S.length olds = 32} -> GTot Type0 (decreases (32 - lv)) let rec mt_olds_inv #hsz lv i olds = if lv = 32 then true else (let ofs = offset_of i in S.length (S.index olds lv) == ofs /\ mt_olds_inv #hsz (lv + 1) (i / 2) olds) val mt_olds_inv_equiv: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> lv:nat{lv <= 32} -> i:nat -> olds1:hashess #hsz {S.length olds1 = 32} -> olds2:hashess #hsz {S.length olds2 = 32} -> Lemma (requires mt_olds_inv #hsz lv i olds1 /\ S.equal (S.slice olds1 lv 32) (S.slice olds2 lv 32)) (ensures mt_olds_inv #hsz lv i olds2) (decreases (32 - lv)) let rec mt_olds_inv_equiv #hsz #f lv i olds1 olds2 = if lv = 32 then () else (assert (S.index olds1 lv == S.index olds2 lv); mt_olds_inv_equiv #_ #f (lv + 1) (i / 2) olds1 olds2) val mt_olds_hs_lth_inv_ok: #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 #hsz lv hs i j} -> Lemma (requires True) (ensures mt_hashes_lth_inv #hsz lv j (merge_hs #_ #f olds hs)) (decreases (32 - lv)) let rec mt_olds_hs_lth_inv_ok #hsz #f lv i j olds hs = if lv = 32 then () else (mt_olds_hs_lth_inv_ok #_ #f (lv + 1) (i / 2) (j / 2) olds hs) val mt_olds_hs_inv: #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 #hsz lv hs i j} -> GTot Type0 let mt_olds_hs_inv #hsz #f lv i j olds hs = mt_olds_hs_lth_inv_ok #_ #f lv i j olds hs; mt_hashes_inv #_ #f lv j (merge_hs #_ #f olds hs) // Relation between valid internal hashes (satisfying `mt_olds_hs_inv`) and // the spec. While giving such relation, all rightmost hashes are recovered. // Note that `MT?.rhs` after `construct_rhs` does NOT contain all rightmost // hashes; it has partial rightmost hashes that are enough to calculate // Merkle paths. val log2: n:nat{n > 0} -> GTot (c:nat{pow2 c <= n && n < pow2 (c+1)}) let rec log2 n = if n = 1 then 0 else 1 + log2 (n / 2) val log2_bound: n:nat{n > 0} -> c:nat{n < pow2 c} -> Lemma (log2 n <= c-1) let rec log2_bound n c = if n = 1 then () else log2_bound (n / 2) (c - 1) val log2_div: n:nat{n > 1} -> Lemma (log2 (n / 2) = log2 n - 1) let log2_div n = () val log2c: n:nat ->
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "MerkleTree.Spec.fst.checked", "MerkleTree.New.High.fst.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Ghost.fsti.checked", "FStar.Classical.fsti.checked" ], "interface_file": false, "source_file": "MerkleTree.New.High.Correct.Base.fst" }
[ { "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": 2, "initial_ifuel": 1, "max_fuel": 1, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 40, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
n: Prims.nat -> Prims.GTot (c: Prims.nat{c = 0 || Prims.pow2 (c - 1) <= n && n < Prims.pow2 c})
Prims.GTot
[ "sometrivial" ]
[]
[ "Prims.nat", "Prims.op_Equality", "Prims.int", "Prims.bool", "Prims.op_Addition", "MerkleTree.New.High.Correct.Base.log2", "Prims.b2t", "Prims.op_BarBar", "Prims.op_AmpAmp", "Prims.op_LessThanOrEqual", "Prims.pow2", "Prims.op_Subtraction", "Prims.op_LessThan" ]
[]
false
false
false
false
false
let log2c n =
if n = 0 then 0 else (log2 n + 1)
false
MerkleTree.New.High.Correct.Base.fst
MerkleTree.New.High.Correct.Base.log2
val log2: n:nat{n > 0} -> GTot (c:nat{pow2 c <= n && n < pow2 (c+1)})
val log2: n:nat{n > 0} -> GTot (c:nat{pow2 c <= n && n < pow2 (c+1)})
let rec log2 n = if n = 1 then 0 else 1 + log2 (n / 2)
{ "file_name": "src/MerkleTree.New.High.Correct.Base.fst", "git_rev": "7d7bdc20f2033171e279c176b26e84f9069d23c6", "git_url": "https://github.com/hacl-star/merkle-tree.git", "project_name": "merkle-tree" }
{ "end_col": 23, "end_line": 286, "start_col": 0, "start_line": 284 }
module MerkleTree.New.High.Correct.Base open FStar.Classical open FStar.Ghost open FStar.Seq module S = FStar.Seq module MTS = MerkleTree.Spec open MerkleTree.New.High #set-options "--z3rlimit 40 --max_fuel 0 --max_ifuel 0" /// Sequence helpers val seq_prefix: #a:Type -> s1:S.seq a -> s2:S.seq a{S.length s1 <= S.length s2} -> GTot Type0 let seq_prefix #a s1 s2 = S.equal s1 (S.slice s2 0 (S.length s1)) val seq_head_cons: #a:Type -> x:a -> s:S.seq a -> Lemma (S.head (S.cons x s) == x) [SMTPat (S.cons x s)] let seq_head_cons #a x s = () val seq_tail_cons: #a:Type -> x:a -> s:S.seq a -> Lemma (S.equal (S.tail (S.cons x s)) s) [SMTPat (S.cons x s)] let seq_tail_cons #a x s = () /// Invariants and simulation relation of high-level Merkle tree design // Invariants of internal hashes val empty_hashes: (#hsz:pos) -> (len:nat) -> GTot (hs:hashess #hsz {S.length hs = len}) let empty_hashes #hsz len = S.create len S.empty val empty_hashes_head: #hsz:pos -> len:nat{len > 0} -> Lemma (S.head (empty_hashes #hsz len) == S.empty) let empty_hashes_head #_ _ = () val empty_hashes_tail: #hsz:pos -> len:nat{len > 0} -> Lemma (S.equal (S.tail (empty_hashes len)) (empty_hashes #hsz (len - 1))) let empty_hashes_tail #_ _ = () #push-options "--max_fuel 1" val mt_hashes_lth_inv: #hsz:pos -> lv:nat{lv <= 32} -> j:nat{j < pow2 (32 - lv)} -> fhs:hashess #hsz {S.length fhs = 32} -> GTot Type0 (decreases (32 - lv)) let rec mt_hashes_lth_inv #hsz lv j fhs = if lv = 32 then true else (S.length (S.index fhs lv) == j /\ mt_hashes_lth_inv (lv + 1) (j / 2) fhs) val mt_hashes_lth_inv_empty: #hsz:pos -> lv:nat{lv <= 32} -> Lemma (requires True) (ensures mt_hashes_lth_inv lv 0 (empty_hashes #hsz 32)) (decreases (32 - lv)) let rec mt_hashes_lth_inv_empty #hsz lv = if lv = 32 then () else mt_hashes_lth_inv_empty #hsz (lv + 1) val mt_hashes_next_rel: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> j:nat -> hs:hashes #hsz {S.length hs = j} -> nhs:hashes #hsz {S.length nhs = j / 2} -> GTot Type0 let mt_hashes_next_rel #hsz #f j hs nhs = forall (i:nat{i < j / 2}). S.index nhs i == f (S.index hs (op_Multiply 2 i)) (S.index hs (op_Multiply 2 i + 1)) #pop-options #push-options "--max_fuel 2" val mt_hashes_inv: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> lv:nat{lv < 32} -> j:nat{j < pow2 (32 - lv)} -> fhs:hashess #hsz {S.length fhs = 32 /\ mt_hashes_lth_inv lv j fhs} -> GTot Type0 (decreases (32 - lv)) let rec mt_hashes_inv #hsz #f lv j fhs = if lv = 31 then true else (mt_hashes_next_rel #_ #f j (S.index fhs lv) (S.index fhs (lv + 1)) /\ mt_hashes_inv #_ #f (lv + 1) (j / 2) fhs) val mt_hashes_inv_empty: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> lv:nat{lv < 32} -> Lemma (requires True) (ensures (mt_hashes_lth_inv_empty #hsz lv; mt_hashes_inv #hsz #f lv 0 (empty_hashes #hsz 32))) (decreases (32 - lv)) let rec mt_hashes_inv_empty #hsz #f lv = if lv = 31 then () else (mt_hashes_lth_inv_empty #hsz (lv + 1); mt_hashes_inv_empty #_ #f (lv + 1)) val mt_hashes_lth_inv_equiv: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> lv:nat{lv < 32} -> j:nat{j < pow2 (32 - lv)} -> fhs1:hashess{S.length fhs1 = 32} -> fhs2:hashess{S.length fhs2 = 32} -> Lemma (requires mt_hashes_lth_inv lv j fhs1 /\ S.equal (S.slice fhs1 lv 32) (S.slice fhs2 lv 32)) (ensures mt_hashes_lth_inv #hsz lv j fhs2) (decreases (32 - lv)) let rec mt_hashes_lth_inv_equiv #hsz #f lv j fhs1 fhs2 = if lv = 31 then () else (assert (S.index fhs1 lv == S.index fhs2 lv); mt_hashes_lth_inv_equiv #_ #f (lv + 1) (j / 2) fhs1 fhs2) #pop-options #push-options "--max_fuel 1" val mt_hashes_inv_equiv: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> lv:nat{lv < 32} -> j:nat{j < pow2 (32 - lv)} -> fhs1:hashess #hsz {S.length fhs1 = 32 /\ mt_hashes_lth_inv lv j fhs1} -> fhs2:hashess #hsz {S.length fhs2 = 32 /\ mt_hashes_lth_inv lv j fhs2} -> Lemma (requires mt_hashes_inv #_ #f lv j fhs1 /\ S.equal (S.slice fhs1 lv 32) (S.slice fhs2 lv 32)) (ensures mt_hashes_inv #_ #f lv j fhs2) (decreases (32 - lv)) let rec mt_hashes_inv_equiv #hsz #f lv j fhs1 fhs2 = if lv = 31 then () else (assert (S.index fhs1 lv == S.index fhs2 lv); assert (S.index fhs1 (lv + 1) == S.index fhs2 (lv + 1)); mt_hashes_inv_equiv #_ #f (lv + 1) (j / 2) fhs1 fhs2) val merge_hs: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> hs1:hashess #hsz -> hs2:hashess #hsz {S.length hs1 = S.length hs2} -> GTot (mhs:hashess #hsz {S.length mhs = S.length hs1}) (decreases (S.length hs1)) let rec merge_hs #hsz #f hs1 hs2 = if S.length hs1 = 0 then S.empty else (S.cons (S.append (S.head hs1) (S.head hs2)) (merge_hs #_ #f (S.tail hs1) (S.tail hs2))) val merge_hs_empty: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> len:nat -> Lemma (S.equal (merge_hs #_ #f (empty_hashes #hsz len) (empty_hashes #hsz len)) (empty_hashes #hsz len)) let rec merge_hs_empty #hsz #f len = if len = 0 then () else (empty_hashes_head #hsz len; empty_hashes_tail #hsz len; assert (S.equal (S.append #(hash #hsz) S.empty S.empty) (S.empty #(hash #hsz))); assert (S.equal (merge_hs #_ #f (empty_hashes len) (empty_hashes len)) (S.cons S.empty (merge_hs #_ #f (empty_hashes (len - 1)) (empty_hashes (len - 1))))); merge_hs_empty #_ #f (len - 1)) val merge_hs_index: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> hs1:hashess -> hs2:hashess{S.length hs1 = S.length hs2} -> i:nat{i < S.length hs1} -> Lemma (requires True) (ensures S.equal (S.index (merge_hs #_ #f hs1 hs2) i) (S.append (S.index hs1 i) (S.index hs2 i))) (decreases (S.length hs1)) [SMTPat (S.index (merge_hs #_ #f hs1 hs2) i)] let rec merge_hs_index #hsz #f hs1 hs2 i = if S.length hs1 = 0 then () else if i = 0 then () else merge_hs_index #_ #f (S.tail hs1) (S.tail hs2) (i - 1) val merge_hs_slice_equal: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> ahs1:hashess #hsz -> ahs2:hashess #hsz {S.length ahs1 = S.length ahs2} -> bhs1:hashess #hsz -> bhs2:hashess #hsz {S.length bhs1 = S.length bhs2} -> i:nat -> j:nat{i <= j && j <= S.length ahs1 && j <= S.length bhs1} -> Lemma (requires S.equal (S.slice ahs1 i j) (S.slice bhs1 i j) /\ S.equal (S.slice ahs2 i j) (S.slice bhs2 i j)) (ensures S.equal (S.slice (merge_hs #_ #f ahs1 ahs2) i j) (S.slice (merge_hs #_ #f bhs1 bhs2) i j)) (decreases (j - i)) let rec merge_hs_slice_equal #_ #f ahs1 ahs2 bhs1 bhs2 i j = if i = j then () else (assert (S.index ahs1 i == S.index bhs1 i); assert (S.index ahs2 i == S.index bhs2 i); merge_hs_slice_equal #_ #f ahs1 ahs2 bhs1 bhs2 (i + 1) j) val merge_hs_upd: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> hs1:hashess #hsz -> hs2:hashess #hsz {S.length hs1 = S.length hs2} -> i:nat{i < S.length hs1} -> v1:hashes #hsz -> v2:hashes #hsz -> Lemma (requires S.equal (S.append (S.index hs1 i) (S.index hs2 i)) (S.append v1 v2)) (ensures S.equal (merge_hs #_ #f hs1 hs2) (merge_hs #_ #f (S.upd hs1 i v1) (S.upd hs2 i v2))) (decreases i) let rec merge_hs_upd #_ #f hs1 hs2 i v1 v2 = if S.length hs1 = 0 then () else if i = 0 then () else merge_hs_upd #_ #f (S.tail hs1) (S.tail hs2) (i - 1) v1 v2 val mt_olds_inv: #hsz:pos -> lv:nat{lv <= 32} -> i:nat -> olds:hashess #hsz {S.length olds = 32} -> GTot Type0 (decreases (32 - lv)) let rec mt_olds_inv #hsz lv i olds = if lv = 32 then true else (let ofs = offset_of i in S.length (S.index olds lv) == ofs /\ mt_olds_inv #hsz (lv + 1) (i / 2) olds) val mt_olds_inv_equiv: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> lv:nat{lv <= 32} -> i:nat -> olds1:hashess #hsz {S.length olds1 = 32} -> olds2:hashess #hsz {S.length olds2 = 32} -> Lemma (requires mt_olds_inv #hsz lv i olds1 /\ S.equal (S.slice olds1 lv 32) (S.slice olds2 lv 32)) (ensures mt_olds_inv #hsz lv i olds2) (decreases (32 - lv)) let rec mt_olds_inv_equiv #hsz #f lv i olds1 olds2 = if lv = 32 then () else (assert (S.index olds1 lv == S.index olds2 lv); mt_olds_inv_equiv #_ #f (lv + 1) (i / 2) olds1 olds2) val mt_olds_hs_lth_inv_ok: #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 #hsz lv hs i j} -> Lemma (requires True) (ensures mt_hashes_lth_inv #hsz lv j (merge_hs #_ #f olds hs)) (decreases (32 - lv)) let rec mt_olds_hs_lth_inv_ok #hsz #f lv i j olds hs = if lv = 32 then () else (mt_olds_hs_lth_inv_ok #_ #f (lv + 1) (i / 2) (j / 2) olds hs) val mt_olds_hs_inv: #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 #hsz lv hs i j} -> GTot Type0 let mt_olds_hs_inv #hsz #f lv i j olds hs = mt_olds_hs_lth_inv_ok #_ #f lv i j olds hs; mt_hashes_inv #_ #f lv j (merge_hs #_ #f olds hs) // Relation between valid internal hashes (satisfying `mt_olds_hs_inv`) and // the spec. While giving such relation, all rightmost hashes are recovered. // Note that `MT?.rhs` after `construct_rhs` does NOT contain all rightmost // hashes; it has partial rightmost hashes that are enough to calculate // Merkle paths.
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "MerkleTree.Spec.fst.checked", "MerkleTree.New.High.fst.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Ghost.fsti.checked", "FStar.Classical.fsti.checked" ], "interface_file": false, "source_file": "MerkleTree.New.High.Correct.Base.fst" }
[ { "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": 2, "initial_ifuel": 1, "max_fuel": 1, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 40, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
n: Prims.nat{n > 0} -> Prims.GTot (c: Prims.nat{Prims.pow2 c <= n && n < Prims.pow2 (c + 1)})
Prims.GTot
[ "sometrivial" ]
[]
[ "Prims.nat", "Prims.b2t", "Prims.op_GreaterThan", "Prims.op_Equality", "Prims.int", "Prims.bool", "Prims.op_Addition", "MerkleTree.New.High.Correct.Base.log2", "Prims.op_Division", "Prims.op_AmpAmp", "Prims.op_LessThanOrEqual", "Prims.pow2", "Prims.op_LessThan" ]
[ "recursion" ]
false
false
false
false
false
let rec log2 n =
if n = 1 then 0 else 1 + log2 (n / 2)
false
MerkleTree.New.High.Correct.Base.fst
MerkleTree.New.High.Correct.Base.create_pads
val create_pads: #hsz:pos -> len:nat -> GTot (pads:MTS.hashes #hsz {S.length pads = len})
val create_pads: #hsz:pos -> len:nat -> GTot (pads:MTS.hashes #hsz {S.length pads = len})
let create_pads #hsz len = S.create len (MTS.HPad #hsz)
{ "file_name": "src/MerkleTree.New.High.Correct.Base.fst", "git_rev": "7d7bdc20f2033171e279c176b26e84f9069d23c6", "git_url": "https://github.com/hacl-star/merkle-tree.git", "project_name": "merkle-tree" }
{ "end_col": 55, "end_line": 427, "start_col": 0, "start_line": 427 }
module MerkleTree.New.High.Correct.Base open FStar.Classical open FStar.Ghost open FStar.Seq module S = FStar.Seq module MTS = MerkleTree.Spec open MerkleTree.New.High #set-options "--z3rlimit 40 --max_fuel 0 --max_ifuel 0" /// Sequence helpers val seq_prefix: #a:Type -> s1:S.seq a -> s2:S.seq a{S.length s1 <= S.length s2} -> GTot Type0 let seq_prefix #a s1 s2 = S.equal s1 (S.slice s2 0 (S.length s1)) val seq_head_cons: #a:Type -> x:a -> s:S.seq a -> Lemma (S.head (S.cons x s) == x) [SMTPat (S.cons x s)] let seq_head_cons #a x s = () val seq_tail_cons: #a:Type -> x:a -> s:S.seq a -> Lemma (S.equal (S.tail (S.cons x s)) s) [SMTPat (S.cons x s)] let seq_tail_cons #a x s = () /// Invariants and simulation relation of high-level Merkle tree design // Invariants of internal hashes val empty_hashes: (#hsz:pos) -> (len:nat) -> GTot (hs:hashess #hsz {S.length hs = len}) let empty_hashes #hsz len = S.create len S.empty val empty_hashes_head: #hsz:pos -> len:nat{len > 0} -> Lemma (S.head (empty_hashes #hsz len) == S.empty) let empty_hashes_head #_ _ = () val empty_hashes_tail: #hsz:pos -> len:nat{len > 0} -> Lemma (S.equal (S.tail (empty_hashes len)) (empty_hashes #hsz (len - 1))) let empty_hashes_tail #_ _ = () #push-options "--max_fuel 1" val mt_hashes_lth_inv: #hsz:pos -> lv:nat{lv <= 32} -> j:nat{j < pow2 (32 - lv)} -> fhs:hashess #hsz {S.length fhs = 32} -> GTot Type0 (decreases (32 - lv)) let rec mt_hashes_lth_inv #hsz lv j fhs = if lv = 32 then true else (S.length (S.index fhs lv) == j /\ mt_hashes_lth_inv (lv + 1) (j / 2) fhs) val mt_hashes_lth_inv_empty: #hsz:pos -> lv:nat{lv <= 32} -> Lemma (requires True) (ensures mt_hashes_lth_inv lv 0 (empty_hashes #hsz 32)) (decreases (32 - lv)) let rec mt_hashes_lth_inv_empty #hsz lv = if lv = 32 then () else mt_hashes_lth_inv_empty #hsz (lv + 1) val mt_hashes_next_rel: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> j:nat -> hs:hashes #hsz {S.length hs = j} -> nhs:hashes #hsz {S.length nhs = j / 2} -> GTot Type0 let mt_hashes_next_rel #hsz #f j hs nhs = forall (i:nat{i < j / 2}). S.index nhs i == f (S.index hs (op_Multiply 2 i)) (S.index hs (op_Multiply 2 i + 1)) #pop-options #push-options "--max_fuel 2" val mt_hashes_inv: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> lv:nat{lv < 32} -> j:nat{j < pow2 (32 - lv)} -> fhs:hashess #hsz {S.length fhs = 32 /\ mt_hashes_lth_inv lv j fhs} -> GTot Type0 (decreases (32 - lv)) let rec mt_hashes_inv #hsz #f lv j fhs = if lv = 31 then true else (mt_hashes_next_rel #_ #f j (S.index fhs lv) (S.index fhs (lv + 1)) /\ mt_hashes_inv #_ #f (lv + 1) (j / 2) fhs) val mt_hashes_inv_empty: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> lv:nat{lv < 32} -> Lemma (requires True) (ensures (mt_hashes_lth_inv_empty #hsz lv; mt_hashes_inv #hsz #f lv 0 (empty_hashes #hsz 32))) (decreases (32 - lv)) let rec mt_hashes_inv_empty #hsz #f lv = if lv = 31 then () else (mt_hashes_lth_inv_empty #hsz (lv + 1); mt_hashes_inv_empty #_ #f (lv + 1)) val mt_hashes_lth_inv_equiv: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> lv:nat{lv < 32} -> j:nat{j < pow2 (32 - lv)} -> fhs1:hashess{S.length fhs1 = 32} -> fhs2:hashess{S.length fhs2 = 32} -> Lemma (requires mt_hashes_lth_inv lv j fhs1 /\ S.equal (S.slice fhs1 lv 32) (S.slice fhs2 lv 32)) (ensures mt_hashes_lth_inv #hsz lv j fhs2) (decreases (32 - lv)) let rec mt_hashes_lth_inv_equiv #hsz #f lv j fhs1 fhs2 = if lv = 31 then () else (assert (S.index fhs1 lv == S.index fhs2 lv); mt_hashes_lth_inv_equiv #_ #f (lv + 1) (j / 2) fhs1 fhs2) #pop-options #push-options "--max_fuel 1" val mt_hashes_inv_equiv: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> lv:nat{lv < 32} -> j:nat{j < pow2 (32 - lv)} -> fhs1:hashess #hsz {S.length fhs1 = 32 /\ mt_hashes_lth_inv lv j fhs1} -> fhs2:hashess #hsz {S.length fhs2 = 32 /\ mt_hashes_lth_inv lv j fhs2} -> Lemma (requires mt_hashes_inv #_ #f lv j fhs1 /\ S.equal (S.slice fhs1 lv 32) (S.slice fhs2 lv 32)) (ensures mt_hashes_inv #_ #f lv j fhs2) (decreases (32 - lv)) let rec mt_hashes_inv_equiv #hsz #f lv j fhs1 fhs2 = if lv = 31 then () else (assert (S.index fhs1 lv == S.index fhs2 lv); assert (S.index fhs1 (lv + 1) == S.index fhs2 (lv + 1)); mt_hashes_inv_equiv #_ #f (lv + 1) (j / 2) fhs1 fhs2) val merge_hs: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> hs1:hashess #hsz -> hs2:hashess #hsz {S.length hs1 = S.length hs2} -> GTot (mhs:hashess #hsz {S.length mhs = S.length hs1}) (decreases (S.length hs1)) let rec merge_hs #hsz #f hs1 hs2 = if S.length hs1 = 0 then S.empty else (S.cons (S.append (S.head hs1) (S.head hs2)) (merge_hs #_ #f (S.tail hs1) (S.tail hs2))) val merge_hs_empty: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> len:nat -> Lemma (S.equal (merge_hs #_ #f (empty_hashes #hsz len) (empty_hashes #hsz len)) (empty_hashes #hsz len)) let rec merge_hs_empty #hsz #f len = if len = 0 then () else (empty_hashes_head #hsz len; empty_hashes_tail #hsz len; assert (S.equal (S.append #(hash #hsz) S.empty S.empty) (S.empty #(hash #hsz))); assert (S.equal (merge_hs #_ #f (empty_hashes len) (empty_hashes len)) (S.cons S.empty (merge_hs #_ #f (empty_hashes (len - 1)) (empty_hashes (len - 1))))); merge_hs_empty #_ #f (len - 1)) val merge_hs_index: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> hs1:hashess -> hs2:hashess{S.length hs1 = S.length hs2} -> i:nat{i < S.length hs1} -> Lemma (requires True) (ensures S.equal (S.index (merge_hs #_ #f hs1 hs2) i) (S.append (S.index hs1 i) (S.index hs2 i))) (decreases (S.length hs1)) [SMTPat (S.index (merge_hs #_ #f hs1 hs2) i)] let rec merge_hs_index #hsz #f hs1 hs2 i = if S.length hs1 = 0 then () else if i = 0 then () else merge_hs_index #_ #f (S.tail hs1) (S.tail hs2) (i - 1) val merge_hs_slice_equal: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> ahs1:hashess #hsz -> ahs2:hashess #hsz {S.length ahs1 = S.length ahs2} -> bhs1:hashess #hsz -> bhs2:hashess #hsz {S.length bhs1 = S.length bhs2} -> i:nat -> j:nat{i <= j && j <= S.length ahs1 && j <= S.length bhs1} -> Lemma (requires S.equal (S.slice ahs1 i j) (S.slice bhs1 i j) /\ S.equal (S.slice ahs2 i j) (S.slice bhs2 i j)) (ensures S.equal (S.slice (merge_hs #_ #f ahs1 ahs2) i j) (S.slice (merge_hs #_ #f bhs1 bhs2) i j)) (decreases (j - i)) let rec merge_hs_slice_equal #_ #f ahs1 ahs2 bhs1 bhs2 i j = if i = j then () else (assert (S.index ahs1 i == S.index bhs1 i); assert (S.index ahs2 i == S.index bhs2 i); merge_hs_slice_equal #_ #f ahs1 ahs2 bhs1 bhs2 (i + 1) j) val merge_hs_upd: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> hs1:hashess #hsz -> hs2:hashess #hsz {S.length hs1 = S.length hs2} -> i:nat{i < S.length hs1} -> v1:hashes #hsz -> v2:hashes #hsz -> Lemma (requires S.equal (S.append (S.index hs1 i) (S.index hs2 i)) (S.append v1 v2)) (ensures S.equal (merge_hs #_ #f hs1 hs2) (merge_hs #_ #f (S.upd hs1 i v1) (S.upd hs2 i v2))) (decreases i) let rec merge_hs_upd #_ #f hs1 hs2 i v1 v2 = if S.length hs1 = 0 then () else if i = 0 then () else merge_hs_upd #_ #f (S.tail hs1) (S.tail hs2) (i - 1) v1 v2 val mt_olds_inv: #hsz:pos -> lv:nat{lv <= 32} -> i:nat -> olds:hashess #hsz {S.length olds = 32} -> GTot Type0 (decreases (32 - lv)) let rec mt_olds_inv #hsz lv i olds = if lv = 32 then true else (let ofs = offset_of i in S.length (S.index olds lv) == ofs /\ mt_olds_inv #hsz (lv + 1) (i / 2) olds) val mt_olds_inv_equiv: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> lv:nat{lv <= 32} -> i:nat -> olds1:hashess #hsz {S.length olds1 = 32} -> olds2:hashess #hsz {S.length olds2 = 32} -> Lemma (requires mt_olds_inv #hsz lv i olds1 /\ S.equal (S.slice olds1 lv 32) (S.slice olds2 lv 32)) (ensures mt_olds_inv #hsz lv i olds2) (decreases (32 - lv)) let rec mt_olds_inv_equiv #hsz #f lv i olds1 olds2 = if lv = 32 then () else (assert (S.index olds1 lv == S.index olds2 lv); mt_olds_inv_equiv #_ #f (lv + 1) (i / 2) olds1 olds2) val mt_olds_hs_lth_inv_ok: #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 #hsz lv hs i j} -> Lemma (requires True) (ensures mt_hashes_lth_inv #hsz lv j (merge_hs #_ #f olds hs)) (decreases (32 - lv)) let rec mt_olds_hs_lth_inv_ok #hsz #f lv i j olds hs = if lv = 32 then () else (mt_olds_hs_lth_inv_ok #_ #f (lv + 1) (i / 2) (j / 2) olds hs) val mt_olds_hs_inv: #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 #hsz lv hs i j} -> GTot Type0 let mt_olds_hs_inv #hsz #f lv i j olds hs = mt_olds_hs_lth_inv_ok #_ #f lv i j olds hs; mt_hashes_inv #_ #f lv j (merge_hs #_ #f olds hs) // Relation between valid internal hashes (satisfying `mt_olds_hs_inv`) and // the spec. While giving such relation, all rightmost hashes are recovered. // Note that `MT?.rhs` after `construct_rhs` does NOT contain all rightmost // hashes; it has partial rightmost hashes that are enough to calculate // Merkle paths. val log2: n:nat{n > 0} -> GTot (c:nat{pow2 c <= n && n < pow2 (c+1)}) let rec log2 n = if n = 1 then 0 else 1 + log2 (n / 2) val log2_bound: n:nat{n > 0} -> c:nat{n < pow2 c} -> Lemma (log2 n <= c-1) let rec log2_bound n c = if n = 1 then () else log2_bound (n / 2) (c - 1) val log2_div: n:nat{n > 1} -> Lemma (log2 (n / 2) = log2 n - 1) let log2_div n = () val log2c: n:nat -> GTot (c:nat{c = 0 || (pow2 (c-1) <= n && n < pow2 c)}) let log2c n = if n = 0 then 0 else (log2 n + 1) val log2c_div: n:nat{n > 0} -> Lemma (log2c (n / 2) = log2c n - 1) let log2c_div n = () val log2c_bound: n:nat -> c:nat{n < pow2 c} -> Lemma (log2c n <= c) let rec log2c_bound n c = if n = 0 then () else log2c_bound (n / 2) (c - 1) val mt_hashes_lth_inv_log: #hsz:pos -> j:nat -> fhs:hashess #hsz {S.length fhs = log2c j} -> GTot Type0 (decreases j) let rec mt_hashes_lth_inv_log #hsz j fhs = if j = 0 then true else (S.length (S.head fhs) == j /\ mt_hashes_lth_inv_log #hsz (j / 2) (S.tail fhs)) #pop-options #push-options "--max_fuel 2" val mt_hashes_lth_inv_log_next: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> j:nat{j > 1} -> fhs:hashess #hsz {S.length fhs = log2c j} -> Lemma (requires mt_hashes_lth_inv_log #hsz j fhs) (ensures S.length (S.head fhs) == j /\ S.length (S.head (S.tail fhs)) == j / 2) let mt_hashes_lth_inv_log_next #_ #_ _ _ = () val mt_hashes_inv_log: #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} -> GTot Type0 (decreases j) let rec mt_hashes_inv_log #hsz #f j fhs = if j <= 1 then true else (mt_hashes_next_rel #_ #f j (S.index fhs 0) (S.index fhs 1) /\ mt_hashes_inv_log #_ #f (j / 2) (S.tail fhs)) val mt_hashes_lth_inv_log_converted_: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> lv:nat{lv <= 32} -> j:nat{j < pow2 (32 - lv)} -> fhs:hashess #hsz {S.length fhs = 32} -> Lemma (requires mt_hashes_lth_inv #hsz lv j fhs) (ensures (log2c_bound j (32 - lv); mt_hashes_lth_inv_log #hsz j (S.slice fhs lv (lv + log2c j)))) (decreases j) let rec mt_hashes_lth_inv_log_converted_ #_ #f lv j fhs = if j = 0 then () else (log2c_bound (j / 2) (32 - (lv + 1)); mt_hashes_lth_inv_log_converted_ #_ #f (lv + 1) (j / 2) fhs) val mt_hashes_lth_inv_log_converted: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> j:nat{j < pow2 32} -> fhs:hashess #hsz {S.length fhs = 32} -> Lemma (requires mt_hashes_lth_inv #hsz 0 j fhs) (ensures (log2c_bound j 32; mt_hashes_lth_inv_log #hsz j (S.slice fhs 0 (log2c j)))) let mt_hashes_lth_inv_log_converted #_ #f j fhs = mt_hashes_lth_inv_log_converted_ #_ #f 0 j fhs val mt_hashes_inv_log_converted_: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> lv:nat{lv <= 32} -> j:nat{j > 0 && j < pow2 (32 - lv)} -> fhs:hashess #hsz {S.length fhs = 32 /\ mt_hashes_lth_inv #hsz lv j fhs} -> Lemma (requires mt_hashes_inv #_ #f lv j fhs) (ensures (log2c_bound j (32 - lv); mt_hashes_lth_inv_log_converted_ #_ #f lv j fhs; mt_hashes_inv_log #_ #f j (S.slice fhs lv (lv + log2c j)))) (decreases j) #pop-options #push-options "--z3rlimit 100 --initial_fuel 2 --max_fuel 2" let rec mt_hashes_inv_log_converted_ #_ #f lv j fhs = if j = 1 then () else (log2c_bound (j / 2) (32 - (lv + 1)); mt_hashes_lth_inv_log_converted_ #_ #f (lv + 1) (j / 2) fhs; mt_hashes_inv_log_converted_ #_ #f (lv + 1) (j / 2) fhs) #pop-options val mt_hashes_inv_log_converted: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> j:nat{j > 0 && j < pow2 32} -> fhs:hashess #hsz {S.length fhs = 32 /\ mt_hashes_lth_inv #hsz 0 j fhs} -> Lemma (requires mt_hashes_inv #_ #f 0 j fhs) (ensures (log2c_bound j 32; mt_hashes_lth_inv_log_converted_ #_ #f 0 j fhs; mt_hashes_inv_log #_ #f j (S.slice fhs 0 (log2c j)))) let mt_hashes_inv_log_converted #_ #f j fhs = mt_hashes_inv_log_converted_ #_ #f 0 j fhs val hash_seq_lift: #hsz:pos -> hs:hashes #hsz -> GTot (shs:MTS.hashes #hsz {S.length shs = S.length hs}) (decreases (S.length hs)) let rec hash_seq_lift #hsz hs = if S.length hs = 0 then S.empty else S.cons (MTS.HRaw (S.head hs)) (hash_seq_lift #hsz (S.tail hs)) #push-options "--z3rlimit 50 --initial_fuel 2 --max_fuel 2" val hash_seq_lift_index: #hsz:pos -> hs:hashes #hsz -> Lemma (requires True) (ensures forall (i:nat{i < S.length hs}). S.index (hash_seq_lift #hsz hs) i == MTS.HRaw (S.index hs i)) (decreases (S.length hs)) let rec hash_seq_lift_index #hsz hs = if S.length hs = 0 then () else hash_seq_lift_index #hsz (S.tail hs) #pop-options
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "MerkleTree.Spec.fst.checked", "MerkleTree.New.High.fst.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Ghost.fsti.checked", "FStar.Classical.fsti.checked" ], "interface_file": false, "source_file": "MerkleTree.New.High.Correct.Base.fst" }
[ { "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": 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": 40, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
len: Prims.nat -> Prims.GTot (pads: MerkleTree.Spec.hashes{FStar.Seq.Base.length pads = len})
Prims.GTot
[ "sometrivial" ]
[]
[ "Prims.pos", "Prims.nat", "FStar.Seq.Base.create", "MerkleTree.Spec.padded_hash", "MerkleTree.Spec.HPad", "MerkleTree.Spec.hashes", "Prims.b2t", "Prims.op_Equality", "FStar.Seq.Base.length" ]
[]
false
false
false
false
false
let create_pads #hsz len =
S.create len (MTS.HPad #hsz)
false
MerkleTree.New.High.Correct.Base.fst
MerkleTree.New.High.Correct.Base.mt_hashes_lth_inv_log_converted
val mt_hashes_lth_inv_log_converted: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> j:nat{j < pow2 32} -> fhs:hashess #hsz {S.length fhs = 32} -> Lemma (requires mt_hashes_lth_inv #hsz 0 j fhs) (ensures (log2c_bound j 32; mt_hashes_lth_inv_log #hsz j (S.slice fhs 0 (log2c j))))
val mt_hashes_lth_inv_log_converted: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> j:nat{j < pow2 32} -> fhs:hashess #hsz {S.length fhs = 32} -> Lemma (requires mt_hashes_lth_inv #hsz 0 j fhs) (ensures (log2c_bound j 32; mt_hashes_lth_inv_log #hsz j (S.slice fhs 0 (log2c j))))
let mt_hashes_lth_inv_log_converted #_ #f j fhs = mt_hashes_lth_inv_log_converted_ #_ #f 0 j fhs
{ "file_name": "src/MerkleTree.New.High.Correct.Base.fst", "git_rev": "7d7bdc20f2033171e279c176b26e84f9069d23c6", "git_url": "https://github.com/hacl-star/merkle-tree.git", "project_name": "merkle-tree" }
{ "end_col": 48, "end_line": 371, "start_col": 0, "start_line": 370 }
module MerkleTree.New.High.Correct.Base open FStar.Classical open FStar.Ghost open FStar.Seq module S = FStar.Seq module MTS = MerkleTree.Spec open MerkleTree.New.High #set-options "--z3rlimit 40 --max_fuel 0 --max_ifuel 0" /// Sequence helpers val seq_prefix: #a:Type -> s1:S.seq a -> s2:S.seq a{S.length s1 <= S.length s2} -> GTot Type0 let seq_prefix #a s1 s2 = S.equal s1 (S.slice s2 0 (S.length s1)) val seq_head_cons: #a:Type -> x:a -> s:S.seq a -> Lemma (S.head (S.cons x s) == x) [SMTPat (S.cons x s)] let seq_head_cons #a x s = () val seq_tail_cons: #a:Type -> x:a -> s:S.seq a -> Lemma (S.equal (S.tail (S.cons x s)) s) [SMTPat (S.cons x s)] let seq_tail_cons #a x s = () /// Invariants and simulation relation of high-level Merkle tree design // Invariants of internal hashes val empty_hashes: (#hsz:pos) -> (len:nat) -> GTot (hs:hashess #hsz {S.length hs = len}) let empty_hashes #hsz len = S.create len S.empty val empty_hashes_head: #hsz:pos -> len:nat{len > 0} -> Lemma (S.head (empty_hashes #hsz len) == S.empty) let empty_hashes_head #_ _ = () val empty_hashes_tail: #hsz:pos -> len:nat{len > 0} -> Lemma (S.equal (S.tail (empty_hashes len)) (empty_hashes #hsz (len - 1))) let empty_hashes_tail #_ _ = () #push-options "--max_fuel 1" val mt_hashes_lth_inv: #hsz:pos -> lv:nat{lv <= 32} -> j:nat{j < pow2 (32 - lv)} -> fhs:hashess #hsz {S.length fhs = 32} -> GTot Type0 (decreases (32 - lv)) let rec mt_hashes_lth_inv #hsz lv j fhs = if lv = 32 then true else (S.length (S.index fhs lv) == j /\ mt_hashes_lth_inv (lv + 1) (j / 2) fhs) val mt_hashes_lth_inv_empty: #hsz:pos -> lv:nat{lv <= 32} -> Lemma (requires True) (ensures mt_hashes_lth_inv lv 0 (empty_hashes #hsz 32)) (decreases (32 - lv)) let rec mt_hashes_lth_inv_empty #hsz lv = if lv = 32 then () else mt_hashes_lth_inv_empty #hsz (lv + 1) val mt_hashes_next_rel: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> j:nat -> hs:hashes #hsz {S.length hs = j} -> nhs:hashes #hsz {S.length nhs = j / 2} -> GTot Type0 let mt_hashes_next_rel #hsz #f j hs nhs = forall (i:nat{i < j / 2}). S.index nhs i == f (S.index hs (op_Multiply 2 i)) (S.index hs (op_Multiply 2 i + 1)) #pop-options #push-options "--max_fuel 2" val mt_hashes_inv: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> lv:nat{lv < 32} -> j:nat{j < pow2 (32 - lv)} -> fhs:hashess #hsz {S.length fhs = 32 /\ mt_hashes_lth_inv lv j fhs} -> GTot Type0 (decreases (32 - lv)) let rec mt_hashes_inv #hsz #f lv j fhs = if lv = 31 then true else (mt_hashes_next_rel #_ #f j (S.index fhs lv) (S.index fhs (lv + 1)) /\ mt_hashes_inv #_ #f (lv + 1) (j / 2) fhs) val mt_hashes_inv_empty: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> lv:nat{lv < 32} -> Lemma (requires True) (ensures (mt_hashes_lth_inv_empty #hsz lv; mt_hashes_inv #hsz #f lv 0 (empty_hashes #hsz 32))) (decreases (32 - lv)) let rec mt_hashes_inv_empty #hsz #f lv = if lv = 31 then () else (mt_hashes_lth_inv_empty #hsz (lv + 1); mt_hashes_inv_empty #_ #f (lv + 1)) val mt_hashes_lth_inv_equiv: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> lv:nat{lv < 32} -> j:nat{j < pow2 (32 - lv)} -> fhs1:hashess{S.length fhs1 = 32} -> fhs2:hashess{S.length fhs2 = 32} -> Lemma (requires mt_hashes_lth_inv lv j fhs1 /\ S.equal (S.slice fhs1 lv 32) (S.slice fhs2 lv 32)) (ensures mt_hashes_lth_inv #hsz lv j fhs2) (decreases (32 - lv)) let rec mt_hashes_lth_inv_equiv #hsz #f lv j fhs1 fhs2 = if lv = 31 then () else (assert (S.index fhs1 lv == S.index fhs2 lv); mt_hashes_lth_inv_equiv #_ #f (lv + 1) (j / 2) fhs1 fhs2) #pop-options #push-options "--max_fuel 1" val mt_hashes_inv_equiv: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> lv:nat{lv < 32} -> j:nat{j < pow2 (32 - lv)} -> fhs1:hashess #hsz {S.length fhs1 = 32 /\ mt_hashes_lth_inv lv j fhs1} -> fhs2:hashess #hsz {S.length fhs2 = 32 /\ mt_hashes_lth_inv lv j fhs2} -> Lemma (requires mt_hashes_inv #_ #f lv j fhs1 /\ S.equal (S.slice fhs1 lv 32) (S.slice fhs2 lv 32)) (ensures mt_hashes_inv #_ #f lv j fhs2) (decreases (32 - lv)) let rec mt_hashes_inv_equiv #hsz #f lv j fhs1 fhs2 = if lv = 31 then () else (assert (S.index fhs1 lv == S.index fhs2 lv); assert (S.index fhs1 (lv + 1) == S.index fhs2 (lv + 1)); mt_hashes_inv_equiv #_ #f (lv + 1) (j / 2) fhs1 fhs2) val merge_hs: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> hs1:hashess #hsz -> hs2:hashess #hsz {S.length hs1 = S.length hs2} -> GTot (mhs:hashess #hsz {S.length mhs = S.length hs1}) (decreases (S.length hs1)) let rec merge_hs #hsz #f hs1 hs2 = if S.length hs1 = 0 then S.empty else (S.cons (S.append (S.head hs1) (S.head hs2)) (merge_hs #_ #f (S.tail hs1) (S.tail hs2))) val merge_hs_empty: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> len:nat -> Lemma (S.equal (merge_hs #_ #f (empty_hashes #hsz len) (empty_hashes #hsz len)) (empty_hashes #hsz len)) let rec merge_hs_empty #hsz #f len = if len = 0 then () else (empty_hashes_head #hsz len; empty_hashes_tail #hsz len; assert (S.equal (S.append #(hash #hsz) S.empty S.empty) (S.empty #(hash #hsz))); assert (S.equal (merge_hs #_ #f (empty_hashes len) (empty_hashes len)) (S.cons S.empty (merge_hs #_ #f (empty_hashes (len - 1)) (empty_hashes (len - 1))))); merge_hs_empty #_ #f (len - 1)) val merge_hs_index: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> hs1:hashess -> hs2:hashess{S.length hs1 = S.length hs2} -> i:nat{i < S.length hs1} -> Lemma (requires True) (ensures S.equal (S.index (merge_hs #_ #f hs1 hs2) i) (S.append (S.index hs1 i) (S.index hs2 i))) (decreases (S.length hs1)) [SMTPat (S.index (merge_hs #_ #f hs1 hs2) i)] let rec merge_hs_index #hsz #f hs1 hs2 i = if S.length hs1 = 0 then () else if i = 0 then () else merge_hs_index #_ #f (S.tail hs1) (S.tail hs2) (i - 1) val merge_hs_slice_equal: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> ahs1:hashess #hsz -> ahs2:hashess #hsz {S.length ahs1 = S.length ahs2} -> bhs1:hashess #hsz -> bhs2:hashess #hsz {S.length bhs1 = S.length bhs2} -> i:nat -> j:nat{i <= j && j <= S.length ahs1 && j <= S.length bhs1} -> Lemma (requires S.equal (S.slice ahs1 i j) (S.slice bhs1 i j) /\ S.equal (S.slice ahs2 i j) (S.slice bhs2 i j)) (ensures S.equal (S.slice (merge_hs #_ #f ahs1 ahs2) i j) (S.slice (merge_hs #_ #f bhs1 bhs2) i j)) (decreases (j - i)) let rec merge_hs_slice_equal #_ #f ahs1 ahs2 bhs1 bhs2 i j = if i = j then () else (assert (S.index ahs1 i == S.index bhs1 i); assert (S.index ahs2 i == S.index bhs2 i); merge_hs_slice_equal #_ #f ahs1 ahs2 bhs1 bhs2 (i + 1) j) val merge_hs_upd: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> hs1:hashess #hsz -> hs2:hashess #hsz {S.length hs1 = S.length hs2} -> i:nat{i < S.length hs1} -> v1:hashes #hsz -> v2:hashes #hsz -> Lemma (requires S.equal (S.append (S.index hs1 i) (S.index hs2 i)) (S.append v1 v2)) (ensures S.equal (merge_hs #_ #f hs1 hs2) (merge_hs #_ #f (S.upd hs1 i v1) (S.upd hs2 i v2))) (decreases i) let rec merge_hs_upd #_ #f hs1 hs2 i v1 v2 = if S.length hs1 = 0 then () else if i = 0 then () else merge_hs_upd #_ #f (S.tail hs1) (S.tail hs2) (i - 1) v1 v2 val mt_olds_inv: #hsz:pos -> lv:nat{lv <= 32} -> i:nat -> olds:hashess #hsz {S.length olds = 32} -> GTot Type0 (decreases (32 - lv)) let rec mt_olds_inv #hsz lv i olds = if lv = 32 then true else (let ofs = offset_of i in S.length (S.index olds lv) == ofs /\ mt_olds_inv #hsz (lv + 1) (i / 2) olds) val mt_olds_inv_equiv: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> lv:nat{lv <= 32} -> i:nat -> olds1:hashess #hsz {S.length olds1 = 32} -> olds2:hashess #hsz {S.length olds2 = 32} -> Lemma (requires mt_olds_inv #hsz lv i olds1 /\ S.equal (S.slice olds1 lv 32) (S.slice olds2 lv 32)) (ensures mt_olds_inv #hsz lv i olds2) (decreases (32 - lv)) let rec mt_olds_inv_equiv #hsz #f lv i olds1 olds2 = if lv = 32 then () else (assert (S.index olds1 lv == S.index olds2 lv); mt_olds_inv_equiv #_ #f (lv + 1) (i / 2) olds1 olds2) val mt_olds_hs_lth_inv_ok: #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 #hsz lv hs i j} -> Lemma (requires True) (ensures mt_hashes_lth_inv #hsz lv j (merge_hs #_ #f olds hs)) (decreases (32 - lv)) let rec mt_olds_hs_lth_inv_ok #hsz #f lv i j olds hs = if lv = 32 then () else (mt_olds_hs_lth_inv_ok #_ #f (lv + 1) (i / 2) (j / 2) olds hs) val mt_olds_hs_inv: #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 #hsz lv hs i j} -> GTot Type0 let mt_olds_hs_inv #hsz #f lv i j olds hs = mt_olds_hs_lth_inv_ok #_ #f lv i j olds hs; mt_hashes_inv #_ #f lv j (merge_hs #_ #f olds hs) // Relation between valid internal hashes (satisfying `mt_olds_hs_inv`) and // the spec. While giving such relation, all rightmost hashes are recovered. // Note that `MT?.rhs` after `construct_rhs` does NOT contain all rightmost // hashes; it has partial rightmost hashes that are enough to calculate // Merkle paths. val log2: n:nat{n > 0} -> GTot (c:nat{pow2 c <= n && n < pow2 (c+1)}) let rec log2 n = if n = 1 then 0 else 1 + log2 (n / 2) val log2_bound: n:nat{n > 0} -> c:nat{n < pow2 c} -> Lemma (log2 n <= c-1) let rec log2_bound n c = if n = 1 then () else log2_bound (n / 2) (c - 1) val log2_div: n:nat{n > 1} -> Lemma (log2 (n / 2) = log2 n - 1) let log2_div n = () val log2c: n:nat -> GTot (c:nat{c = 0 || (pow2 (c-1) <= n && n < pow2 c)}) let log2c n = if n = 0 then 0 else (log2 n + 1) val log2c_div: n:nat{n > 0} -> Lemma (log2c (n / 2) = log2c n - 1) let log2c_div n = () val log2c_bound: n:nat -> c:nat{n < pow2 c} -> Lemma (log2c n <= c) let rec log2c_bound n c = if n = 0 then () else log2c_bound (n / 2) (c - 1) val mt_hashes_lth_inv_log: #hsz:pos -> j:nat -> fhs:hashess #hsz {S.length fhs = log2c j} -> GTot Type0 (decreases j) let rec mt_hashes_lth_inv_log #hsz j fhs = if j = 0 then true else (S.length (S.head fhs) == j /\ mt_hashes_lth_inv_log #hsz (j / 2) (S.tail fhs)) #pop-options #push-options "--max_fuel 2" val mt_hashes_lth_inv_log_next: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> j:nat{j > 1} -> fhs:hashess #hsz {S.length fhs = log2c j} -> Lemma (requires mt_hashes_lth_inv_log #hsz j fhs) (ensures S.length (S.head fhs) == j /\ S.length (S.head (S.tail fhs)) == j / 2) let mt_hashes_lth_inv_log_next #_ #_ _ _ = () val mt_hashes_inv_log: #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} -> GTot Type0 (decreases j) let rec mt_hashes_inv_log #hsz #f j fhs = if j <= 1 then true else (mt_hashes_next_rel #_ #f j (S.index fhs 0) (S.index fhs 1) /\ mt_hashes_inv_log #_ #f (j / 2) (S.tail fhs)) val mt_hashes_lth_inv_log_converted_: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> lv:nat{lv <= 32} -> j:nat{j < pow2 (32 - lv)} -> fhs:hashess #hsz {S.length fhs = 32} -> Lemma (requires mt_hashes_lth_inv #hsz lv j fhs) (ensures (log2c_bound j (32 - lv); mt_hashes_lth_inv_log #hsz j (S.slice fhs lv (lv + log2c j)))) (decreases j) let rec mt_hashes_lth_inv_log_converted_ #_ #f lv j fhs = if j = 0 then () else (log2c_bound (j / 2) (32 - (lv + 1)); mt_hashes_lth_inv_log_converted_ #_ #f (lv + 1) (j / 2) fhs) val mt_hashes_lth_inv_log_converted: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> j:nat{j < pow2 32} -> fhs:hashess #hsz {S.length fhs = 32} -> Lemma (requires mt_hashes_lth_inv #hsz 0 j fhs) (ensures (log2c_bound j 32;
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "MerkleTree.Spec.fst.checked", "MerkleTree.New.High.fst.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Ghost.fsti.checked", "FStar.Classical.fsti.checked" ], "interface_file": false, "source_file": "MerkleTree.New.High.Correct.Base.fst" }
[ { "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": 2, "initial_ifuel": 1, "max_fuel": 2, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 40, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
j: Prims.nat{j < Prims.pow2 32} -> fhs: MerkleTree.New.High.hashess{FStar.Seq.Base.length fhs = 32} -> FStar.Pervasives.Lemma (requires MerkleTree.New.High.Correct.Base.mt_hashes_lth_inv 0 j fhs) (ensures (MerkleTree.New.High.Correct.Base.log2c_bound j 32; MerkleTree.New.High.Correct.Base.mt_hashes_lth_inv_log j (FStar.Seq.Base.slice fhs 0 (MerkleTree.New.High.Correct.Base.log2c j))))
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "Prims.pos", "MerkleTree.Spec.hash_fun_t", "Prims.nat", "Prims.b2t", "Prims.op_LessThan", "Prims.pow2", "MerkleTree.New.High.hashess", "Prims.op_Equality", "Prims.int", "FStar.Seq.Base.length", "MerkleTree.New.High.hashes", "MerkleTree.New.High.Correct.Base.mt_hashes_lth_inv_log_converted_", "Prims.unit" ]
[]
true
false
true
false
false
let mt_hashes_lth_inv_log_converted #_ #f j fhs =
mt_hashes_lth_inv_log_converted_ #_ #f 0 j fhs
false
MerkleTree.New.High.Correct.Base.fst
MerkleTree.New.High.Correct.Base.mt_hashes_inv_log_converted
val mt_hashes_inv_log_converted: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> j:nat{j > 0 && j < pow2 32} -> fhs:hashess #hsz {S.length fhs = 32 /\ mt_hashes_lth_inv #hsz 0 j fhs} -> Lemma (requires mt_hashes_inv #_ #f 0 j fhs) (ensures (log2c_bound j 32; mt_hashes_lth_inv_log_converted_ #_ #f 0 j fhs; mt_hashes_inv_log #_ #f j (S.slice fhs 0 (log2c j))))
val mt_hashes_inv_log_converted: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> j:nat{j > 0 && j < pow2 32} -> fhs:hashess #hsz {S.length fhs = 32 /\ mt_hashes_lth_inv #hsz 0 j fhs} -> Lemma (requires mt_hashes_inv #_ #f 0 j fhs) (ensures (log2c_bound j 32; mt_hashes_lth_inv_log_converted_ #_ #f 0 j fhs; mt_hashes_inv_log #_ #f j (S.slice fhs 0 (log2c j))))
let mt_hashes_inv_log_converted #_ #f j fhs = mt_hashes_inv_log_converted_ #_ #f 0 j fhs
{ "file_name": "src/MerkleTree.New.High.Correct.Base.fst", "git_rev": "7d7bdc20f2033171e279c176b26e84f9069d23c6", "git_url": "https://github.com/hacl-star/merkle-tree.git", "project_name": "merkle-tree" }
{ "end_col": 44, "end_line": 402, "start_col": 0, "start_line": 401 }
module MerkleTree.New.High.Correct.Base open FStar.Classical open FStar.Ghost open FStar.Seq module S = FStar.Seq module MTS = MerkleTree.Spec open MerkleTree.New.High #set-options "--z3rlimit 40 --max_fuel 0 --max_ifuel 0" /// Sequence helpers val seq_prefix: #a:Type -> s1:S.seq a -> s2:S.seq a{S.length s1 <= S.length s2} -> GTot Type0 let seq_prefix #a s1 s2 = S.equal s1 (S.slice s2 0 (S.length s1)) val seq_head_cons: #a:Type -> x:a -> s:S.seq a -> Lemma (S.head (S.cons x s) == x) [SMTPat (S.cons x s)] let seq_head_cons #a x s = () val seq_tail_cons: #a:Type -> x:a -> s:S.seq a -> Lemma (S.equal (S.tail (S.cons x s)) s) [SMTPat (S.cons x s)] let seq_tail_cons #a x s = () /// Invariants and simulation relation of high-level Merkle tree design // Invariants of internal hashes val empty_hashes: (#hsz:pos) -> (len:nat) -> GTot (hs:hashess #hsz {S.length hs = len}) let empty_hashes #hsz len = S.create len S.empty val empty_hashes_head: #hsz:pos -> len:nat{len > 0} -> Lemma (S.head (empty_hashes #hsz len) == S.empty) let empty_hashes_head #_ _ = () val empty_hashes_tail: #hsz:pos -> len:nat{len > 0} -> Lemma (S.equal (S.tail (empty_hashes len)) (empty_hashes #hsz (len - 1))) let empty_hashes_tail #_ _ = () #push-options "--max_fuel 1" val mt_hashes_lth_inv: #hsz:pos -> lv:nat{lv <= 32} -> j:nat{j < pow2 (32 - lv)} -> fhs:hashess #hsz {S.length fhs = 32} -> GTot Type0 (decreases (32 - lv)) let rec mt_hashes_lth_inv #hsz lv j fhs = if lv = 32 then true else (S.length (S.index fhs lv) == j /\ mt_hashes_lth_inv (lv + 1) (j / 2) fhs) val mt_hashes_lth_inv_empty: #hsz:pos -> lv:nat{lv <= 32} -> Lemma (requires True) (ensures mt_hashes_lth_inv lv 0 (empty_hashes #hsz 32)) (decreases (32 - lv)) let rec mt_hashes_lth_inv_empty #hsz lv = if lv = 32 then () else mt_hashes_lth_inv_empty #hsz (lv + 1) val mt_hashes_next_rel: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> j:nat -> hs:hashes #hsz {S.length hs = j} -> nhs:hashes #hsz {S.length nhs = j / 2} -> GTot Type0 let mt_hashes_next_rel #hsz #f j hs nhs = forall (i:nat{i < j / 2}). S.index nhs i == f (S.index hs (op_Multiply 2 i)) (S.index hs (op_Multiply 2 i + 1)) #pop-options #push-options "--max_fuel 2" val mt_hashes_inv: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> lv:nat{lv < 32} -> j:nat{j < pow2 (32 - lv)} -> fhs:hashess #hsz {S.length fhs = 32 /\ mt_hashes_lth_inv lv j fhs} -> GTot Type0 (decreases (32 - lv)) let rec mt_hashes_inv #hsz #f lv j fhs = if lv = 31 then true else (mt_hashes_next_rel #_ #f j (S.index fhs lv) (S.index fhs (lv + 1)) /\ mt_hashes_inv #_ #f (lv + 1) (j / 2) fhs) val mt_hashes_inv_empty: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> lv:nat{lv < 32} -> Lemma (requires True) (ensures (mt_hashes_lth_inv_empty #hsz lv; mt_hashes_inv #hsz #f lv 0 (empty_hashes #hsz 32))) (decreases (32 - lv)) let rec mt_hashes_inv_empty #hsz #f lv = if lv = 31 then () else (mt_hashes_lth_inv_empty #hsz (lv + 1); mt_hashes_inv_empty #_ #f (lv + 1)) val mt_hashes_lth_inv_equiv: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> lv:nat{lv < 32} -> j:nat{j < pow2 (32 - lv)} -> fhs1:hashess{S.length fhs1 = 32} -> fhs2:hashess{S.length fhs2 = 32} -> Lemma (requires mt_hashes_lth_inv lv j fhs1 /\ S.equal (S.slice fhs1 lv 32) (S.slice fhs2 lv 32)) (ensures mt_hashes_lth_inv #hsz lv j fhs2) (decreases (32 - lv)) let rec mt_hashes_lth_inv_equiv #hsz #f lv j fhs1 fhs2 = if lv = 31 then () else (assert (S.index fhs1 lv == S.index fhs2 lv); mt_hashes_lth_inv_equiv #_ #f (lv + 1) (j / 2) fhs1 fhs2) #pop-options #push-options "--max_fuel 1" val mt_hashes_inv_equiv: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> lv:nat{lv < 32} -> j:nat{j < pow2 (32 - lv)} -> fhs1:hashess #hsz {S.length fhs1 = 32 /\ mt_hashes_lth_inv lv j fhs1} -> fhs2:hashess #hsz {S.length fhs2 = 32 /\ mt_hashes_lth_inv lv j fhs2} -> Lemma (requires mt_hashes_inv #_ #f lv j fhs1 /\ S.equal (S.slice fhs1 lv 32) (S.slice fhs2 lv 32)) (ensures mt_hashes_inv #_ #f lv j fhs2) (decreases (32 - lv)) let rec mt_hashes_inv_equiv #hsz #f lv j fhs1 fhs2 = if lv = 31 then () else (assert (S.index fhs1 lv == S.index fhs2 lv); assert (S.index fhs1 (lv + 1) == S.index fhs2 (lv + 1)); mt_hashes_inv_equiv #_ #f (lv + 1) (j / 2) fhs1 fhs2) val merge_hs: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> hs1:hashess #hsz -> hs2:hashess #hsz {S.length hs1 = S.length hs2} -> GTot (mhs:hashess #hsz {S.length mhs = S.length hs1}) (decreases (S.length hs1)) let rec merge_hs #hsz #f hs1 hs2 = if S.length hs1 = 0 then S.empty else (S.cons (S.append (S.head hs1) (S.head hs2)) (merge_hs #_ #f (S.tail hs1) (S.tail hs2))) val merge_hs_empty: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> len:nat -> Lemma (S.equal (merge_hs #_ #f (empty_hashes #hsz len) (empty_hashes #hsz len)) (empty_hashes #hsz len)) let rec merge_hs_empty #hsz #f len = if len = 0 then () else (empty_hashes_head #hsz len; empty_hashes_tail #hsz len; assert (S.equal (S.append #(hash #hsz) S.empty S.empty) (S.empty #(hash #hsz))); assert (S.equal (merge_hs #_ #f (empty_hashes len) (empty_hashes len)) (S.cons S.empty (merge_hs #_ #f (empty_hashes (len - 1)) (empty_hashes (len - 1))))); merge_hs_empty #_ #f (len - 1)) val merge_hs_index: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> hs1:hashess -> hs2:hashess{S.length hs1 = S.length hs2} -> i:nat{i < S.length hs1} -> Lemma (requires True) (ensures S.equal (S.index (merge_hs #_ #f hs1 hs2) i) (S.append (S.index hs1 i) (S.index hs2 i))) (decreases (S.length hs1)) [SMTPat (S.index (merge_hs #_ #f hs1 hs2) i)] let rec merge_hs_index #hsz #f hs1 hs2 i = if S.length hs1 = 0 then () else if i = 0 then () else merge_hs_index #_ #f (S.tail hs1) (S.tail hs2) (i - 1) val merge_hs_slice_equal: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> ahs1:hashess #hsz -> ahs2:hashess #hsz {S.length ahs1 = S.length ahs2} -> bhs1:hashess #hsz -> bhs2:hashess #hsz {S.length bhs1 = S.length bhs2} -> i:nat -> j:nat{i <= j && j <= S.length ahs1 && j <= S.length bhs1} -> Lemma (requires S.equal (S.slice ahs1 i j) (S.slice bhs1 i j) /\ S.equal (S.slice ahs2 i j) (S.slice bhs2 i j)) (ensures S.equal (S.slice (merge_hs #_ #f ahs1 ahs2) i j) (S.slice (merge_hs #_ #f bhs1 bhs2) i j)) (decreases (j - i)) let rec merge_hs_slice_equal #_ #f ahs1 ahs2 bhs1 bhs2 i j = if i = j then () else (assert (S.index ahs1 i == S.index bhs1 i); assert (S.index ahs2 i == S.index bhs2 i); merge_hs_slice_equal #_ #f ahs1 ahs2 bhs1 bhs2 (i + 1) j) val merge_hs_upd: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> hs1:hashess #hsz -> hs2:hashess #hsz {S.length hs1 = S.length hs2} -> i:nat{i < S.length hs1} -> v1:hashes #hsz -> v2:hashes #hsz -> Lemma (requires S.equal (S.append (S.index hs1 i) (S.index hs2 i)) (S.append v1 v2)) (ensures S.equal (merge_hs #_ #f hs1 hs2) (merge_hs #_ #f (S.upd hs1 i v1) (S.upd hs2 i v2))) (decreases i) let rec merge_hs_upd #_ #f hs1 hs2 i v1 v2 = if S.length hs1 = 0 then () else if i = 0 then () else merge_hs_upd #_ #f (S.tail hs1) (S.tail hs2) (i - 1) v1 v2 val mt_olds_inv: #hsz:pos -> lv:nat{lv <= 32} -> i:nat -> olds:hashess #hsz {S.length olds = 32} -> GTot Type0 (decreases (32 - lv)) let rec mt_olds_inv #hsz lv i olds = if lv = 32 then true else (let ofs = offset_of i in S.length (S.index olds lv) == ofs /\ mt_olds_inv #hsz (lv + 1) (i / 2) olds) val mt_olds_inv_equiv: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> lv:nat{lv <= 32} -> i:nat -> olds1:hashess #hsz {S.length olds1 = 32} -> olds2:hashess #hsz {S.length olds2 = 32} -> Lemma (requires mt_olds_inv #hsz lv i olds1 /\ S.equal (S.slice olds1 lv 32) (S.slice olds2 lv 32)) (ensures mt_olds_inv #hsz lv i olds2) (decreases (32 - lv)) let rec mt_olds_inv_equiv #hsz #f lv i olds1 olds2 = if lv = 32 then () else (assert (S.index olds1 lv == S.index olds2 lv); mt_olds_inv_equiv #_ #f (lv + 1) (i / 2) olds1 olds2) val mt_olds_hs_lth_inv_ok: #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 #hsz lv hs i j} -> Lemma (requires True) (ensures mt_hashes_lth_inv #hsz lv j (merge_hs #_ #f olds hs)) (decreases (32 - lv)) let rec mt_olds_hs_lth_inv_ok #hsz #f lv i j olds hs = if lv = 32 then () else (mt_olds_hs_lth_inv_ok #_ #f (lv + 1) (i / 2) (j / 2) olds hs) val mt_olds_hs_inv: #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 #hsz lv hs i j} -> GTot Type0 let mt_olds_hs_inv #hsz #f lv i j olds hs = mt_olds_hs_lth_inv_ok #_ #f lv i j olds hs; mt_hashes_inv #_ #f lv j (merge_hs #_ #f olds hs) // Relation between valid internal hashes (satisfying `mt_olds_hs_inv`) and // the spec. While giving such relation, all rightmost hashes are recovered. // Note that `MT?.rhs` after `construct_rhs` does NOT contain all rightmost // hashes; it has partial rightmost hashes that are enough to calculate // Merkle paths. val log2: n:nat{n > 0} -> GTot (c:nat{pow2 c <= n && n < pow2 (c+1)}) let rec log2 n = if n = 1 then 0 else 1 + log2 (n / 2) val log2_bound: n:nat{n > 0} -> c:nat{n < pow2 c} -> Lemma (log2 n <= c-1) let rec log2_bound n c = if n = 1 then () else log2_bound (n / 2) (c - 1) val log2_div: n:nat{n > 1} -> Lemma (log2 (n / 2) = log2 n - 1) let log2_div n = () val log2c: n:nat -> GTot (c:nat{c = 0 || (pow2 (c-1) <= n && n < pow2 c)}) let log2c n = if n = 0 then 0 else (log2 n + 1) val log2c_div: n:nat{n > 0} -> Lemma (log2c (n / 2) = log2c n - 1) let log2c_div n = () val log2c_bound: n:nat -> c:nat{n < pow2 c} -> Lemma (log2c n <= c) let rec log2c_bound n c = if n = 0 then () else log2c_bound (n / 2) (c - 1) val mt_hashes_lth_inv_log: #hsz:pos -> j:nat -> fhs:hashess #hsz {S.length fhs = log2c j} -> GTot Type0 (decreases j) let rec mt_hashes_lth_inv_log #hsz j fhs = if j = 0 then true else (S.length (S.head fhs) == j /\ mt_hashes_lth_inv_log #hsz (j / 2) (S.tail fhs)) #pop-options #push-options "--max_fuel 2" val mt_hashes_lth_inv_log_next: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> j:nat{j > 1} -> fhs:hashess #hsz {S.length fhs = log2c j} -> Lemma (requires mt_hashes_lth_inv_log #hsz j fhs) (ensures S.length (S.head fhs) == j /\ S.length (S.head (S.tail fhs)) == j / 2) let mt_hashes_lth_inv_log_next #_ #_ _ _ = () val mt_hashes_inv_log: #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} -> GTot Type0 (decreases j) let rec mt_hashes_inv_log #hsz #f j fhs = if j <= 1 then true else (mt_hashes_next_rel #_ #f j (S.index fhs 0) (S.index fhs 1) /\ mt_hashes_inv_log #_ #f (j / 2) (S.tail fhs)) val mt_hashes_lth_inv_log_converted_: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> lv:nat{lv <= 32} -> j:nat{j < pow2 (32 - lv)} -> fhs:hashess #hsz {S.length fhs = 32} -> Lemma (requires mt_hashes_lth_inv #hsz lv j fhs) (ensures (log2c_bound j (32 - lv); mt_hashes_lth_inv_log #hsz j (S.slice fhs lv (lv + log2c j)))) (decreases j) let rec mt_hashes_lth_inv_log_converted_ #_ #f lv j fhs = if j = 0 then () else (log2c_bound (j / 2) (32 - (lv + 1)); mt_hashes_lth_inv_log_converted_ #_ #f (lv + 1) (j / 2) fhs) val mt_hashes_lth_inv_log_converted: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> j:nat{j < pow2 32} -> fhs:hashess #hsz {S.length fhs = 32} -> Lemma (requires mt_hashes_lth_inv #hsz 0 j fhs) (ensures (log2c_bound j 32; mt_hashes_lth_inv_log #hsz j (S.slice fhs 0 (log2c j)))) let mt_hashes_lth_inv_log_converted #_ #f j fhs = mt_hashes_lth_inv_log_converted_ #_ #f 0 j fhs val mt_hashes_inv_log_converted_: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> lv:nat{lv <= 32} -> j:nat{j > 0 && j < pow2 (32 - lv)} -> fhs:hashess #hsz {S.length fhs = 32 /\ mt_hashes_lth_inv #hsz lv j fhs} -> Lemma (requires mt_hashes_inv #_ #f lv j fhs) (ensures (log2c_bound j (32 - lv); mt_hashes_lth_inv_log_converted_ #_ #f lv j fhs; mt_hashes_inv_log #_ #f j (S.slice fhs lv (lv + log2c j)))) (decreases j) #pop-options #push-options "--z3rlimit 100 --initial_fuel 2 --max_fuel 2" let rec mt_hashes_inv_log_converted_ #_ #f lv j fhs = if j = 1 then () else (log2c_bound (j / 2) (32 - (lv + 1)); mt_hashes_lth_inv_log_converted_ #_ #f (lv + 1) (j / 2) fhs; mt_hashes_inv_log_converted_ #_ #f (lv + 1) (j / 2) fhs) #pop-options val mt_hashes_inv_log_converted: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> j:nat{j > 0 && j < pow2 32} -> fhs:hashess #hsz {S.length fhs = 32 /\ mt_hashes_lth_inv #hsz 0 j fhs} -> Lemma (requires mt_hashes_inv #_ #f 0 j fhs) (ensures (log2c_bound j 32; mt_hashes_lth_inv_log_converted_ #_ #f 0 j fhs;
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "MerkleTree.Spec.fst.checked", "MerkleTree.New.High.fst.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Ghost.fsti.checked", "FStar.Classical.fsti.checked" ], "interface_file": false, "source_file": "MerkleTree.New.High.Correct.Base.fst" }
[ { "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": 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": 40, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
j: Prims.nat{j > 0 && j < Prims.pow2 32} -> fhs: MerkleTree.New.High.hashess { FStar.Seq.Base.length fhs = 32 /\ MerkleTree.New.High.Correct.Base.mt_hashes_lth_inv 0 j fhs } -> FStar.Pervasives.Lemma (requires MerkleTree.New.High.Correct.Base.mt_hashes_inv 0 j fhs) (ensures (MerkleTree.New.High.Correct.Base.log2c_bound j 32; MerkleTree.New.High.Correct.Base.mt_hashes_lth_inv_log_converted_ 0 j fhs; MerkleTree.New.High.Correct.Base.mt_hashes_inv_log j (FStar.Seq.Base.slice fhs 0 (MerkleTree.New.High.Correct.Base.log2c j))))
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "Prims.pos", "MerkleTree.Spec.hash_fun_t", "Prims.nat", "Prims.b2t", "Prims.op_AmpAmp", "Prims.op_GreaterThan", "Prims.op_LessThan", "Prims.pow2", "MerkleTree.New.High.hashess", "Prims.l_and", "Prims.op_Equality", "Prims.int", "FStar.Seq.Base.length", "MerkleTree.New.High.hashes", "MerkleTree.New.High.Correct.Base.mt_hashes_lth_inv", "MerkleTree.New.High.Correct.Base.mt_hashes_inv_log_converted_", "Prims.unit" ]
[]
true
false
true
false
false
let mt_hashes_inv_log_converted #_ #f j fhs =
mt_hashes_inv_log_converted_ #_ #f 0 j fhs
false
MerkleTree.New.High.Correct.Base.fst
MerkleTree.New.High.Correct.Base.mt_olds_hs_lth_inv_ok
val mt_olds_hs_lth_inv_ok: #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 #hsz lv hs i j} -> Lemma (requires True) (ensures mt_hashes_lth_inv #hsz lv j (merge_hs #_ #f olds hs)) (decreases (32 - lv))
val mt_olds_hs_lth_inv_ok: #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 #hsz lv hs i j} -> Lemma (requires True) (ensures mt_hashes_lth_inv #hsz lv j (merge_hs #_ #f olds hs)) (decreases (32 - lv))
let rec mt_olds_hs_lth_inv_ok #hsz #f lv i j olds hs = if lv = 32 then () else (mt_olds_hs_lth_inv_ok #_ #f (lv + 1) (i / 2) (j / 2) olds hs)
{ "file_name": "src/MerkleTree.New.High.Correct.Base.fst", "git_rev": "7d7bdc20f2033171e279c176b26e84f9069d23c6", "git_url": "https://github.com/hacl-star/merkle-tree.git", "project_name": "merkle-tree" }
{ "end_col": 69, "end_line": 263, "start_col": 0, "start_line": 261 }
module MerkleTree.New.High.Correct.Base open FStar.Classical open FStar.Ghost open FStar.Seq module S = FStar.Seq module MTS = MerkleTree.Spec open MerkleTree.New.High #set-options "--z3rlimit 40 --max_fuel 0 --max_ifuel 0" /// Sequence helpers val seq_prefix: #a:Type -> s1:S.seq a -> s2:S.seq a{S.length s1 <= S.length s2} -> GTot Type0 let seq_prefix #a s1 s2 = S.equal s1 (S.slice s2 0 (S.length s1)) val seq_head_cons: #a:Type -> x:a -> s:S.seq a -> Lemma (S.head (S.cons x s) == x) [SMTPat (S.cons x s)] let seq_head_cons #a x s = () val seq_tail_cons: #a:Type -> x:a -> s:S.seq a -> Lemma (S.equal (S.tail (S.cons x s)) s) [SMTPat (S.cons x s)] let seq_tail_cons #a x s = () /// Invariants and simulation relation of high-level Merkle tree design // Invariants of internal hashes val empty_hashes: (#hsz:pos) -> (len:nat) -> GTot (hs:hashess #hsz {S.length hs = len}) let empty_hashes #hsz len = S.create len S.empty val empty_hashes_head: #hsz:pos -> len:nat{len > 0} -> Lemma (S.head (empty_hashes #hsz len) == S.empty) let empty_hashes_head #_ _ = () val empty_hashes_tail: #hsz:pos -> len:nat{len > 0} -> Lemma (S.equal (S.tail (empty_hashes len)) (empty_hashes #hsz (len - 1))) let empty_hashes_tail #_ _ = () #push-options "--max_fuel 1" val mt_hashes_lth_inv: #hsz:pos -> lv:nat{lv <= 32} -> j:nat{j < pow2 (32 - lv)} -> fhs:hashess #hsz {S.length fhs = 32} -> GTot Type0 (decreases (32 - lv)) let rec mt_hashes_lth_inv #hsz lv j fhs = if lv = 32 then true else (S.length (S.index fhs lv) == j /\ mt_hashes_lth_inv (lv + 1) (j / 2) fhs) val mt_hashes_lth_inv_empty: #hsz:pos -> lv:nat{lv <= 32} -> Lemma (requires True) (ensures mt_hashes_lth_inv lv 0 (empty_hashes #hsz 32)) (decreases (32 - lv)) let rec mt_hashes_lth_inv_empty #hsz lv = if lv = 32 then () else mt_hashes_lth_inv_empty #hsz (lv + 1) val mt_hashes_next_rel: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> j:nat -> hs:hashes #hsz {S.length hs = j} -> nhs:hashes #hsz {S.length nhs = j / 2} -> GTot Type0 let mt_hashes_next_rel #hsz #f j hs nhs = forall (i:nat{i < j / 2}). S.index nhs i == f (S.index hs (op_Multiply 2 i)) (S.index hs (op_Multiply 2 i + 1)) #pop-options #push-options "--max_fuel 2" val mt_hashes_inv: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> lv:nat{lv < 32} -> j:nat{j < pow2 (32 - lv)} -> fhs:hashess #hsz {S.length fhs = 32 /\ mt_hashes_lth_inv lv j fhs} -> GTot Type0 (decreases (32 - lv)) let rec mt_hashes_inv #hsz #f lv j fhs = if lv = 31 then true else (mt_hashes_next_rel #_ #f j (S.index fhs lv) (S.index fhs (lv + 1)) /\ mt_hashes_inv #_ #f (lv + 1) (j / 2) fhs) val mt_hashes_inv_empty: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> lv:nat{lv < 32} -> Lemma (requires True) (ensures (mt_hashes_lth_inv_empty #hsz lv; mt_hashes_inv #hsz #f lv 0 (empty_hashes #hsz 32))) (decreases (32 - lv)) let rec mt_hashes_inv_empty #hsz #f lv = if lv = 31 then () else (mt_hashes_lth_inv_empty #hsz (lv + 1); mt_hashes_inv_empty #_ #f (lv + 1)) val mt_hashes_lth_inv_equiv: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> lv:nat{lv < 32} -> j:nat{j < pow2 (32 - lv)} -> fhs1:hashess{S.length fhs1 = 32} -> fhs2:hashess{S.length fhs2 = 32} -> Lemma (requires mt_hashes_lth_inv lv j fhs1 /\ S.equal (S.slice fhs1 lv 32) (S.slice fhs2 lv 32)) (ensures mt_hashes_lth_inv #hsz lv j fhs2) (decreases (32 - lv)) let rec mt_hashes_lth_inv_equiv #hsz #f lv j fhs1 fhs2 = if lv = 31 then () else (assert (S.index fhs1 lv == S.index fhs2 lv); mt_hashes_lth_inv_equiv #_ #f (lv + 1) (j / 2) fhs1 fhs2) #pop-options #push-options "--max_fuel 1" val mt_hashes_inv_equiv: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> lv:nat{lv < 32} -> j:nat{j < pow2 (32 - lv)} -> fhs1:hashess #hsz {S.length fhs1 = 32 /\ mt_hashes_lth_inv lv j fhs1} -> fhs2:hashess #hsz {S.length fhs2 = 32 /\ mt_hashes_lth_inv lv j fhs2} -> Lemma (requires mt_hashes_inv #_ #f lv j fhs1 /\ S.equal (S.slice fhs1 lv 32) (S.slice fhs2 lv 32)) (ensures mt_hashes_inv #_ #f lv j fhs2) (decreases (32 - lv)) let rec mt_hashes_inv_equiv #hsz #f lv j fhs1 fhs2 = if lv = 31 then () else (assert (S.index fhs1 lv == S.index fhs2 lv); assert (S.index fhs1 (lv + 1) == S.index fhs2 (lv + 1)); mt_hashes_inv_equiv #_ #f (lv + 1) (j / 2) fhs1 fhs2) val merge_hs: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> hs1:hashess #hsz -> hs2:hashess #hsz {S.length hs1 = S.length hs2} -> GTot (mhs:hashess #hsz {S.length mhs = S.length hs1}) (decreases (S.length hs1)) let rec merge_hs #hsz #f hs1 hs2 = if S.length hs1 = 0 then S.empty else (S.cons (S.append (S.head hs1) (S.head hs2)) (merge_hs #_ #f (S.tail hs1) (S.tail hs2))) val merge_hs_empty: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> len:nat -> Lemma (S.equal (merge_hs #_ #f (empty_hashes #hsz len) (empty_hashes #hsz len)) (empty_hashes #hsz len)) let rec merge_hs_empty #hsz #f len = if len = 0 then () else (empty_hashes_head #hsz len; empty_hashes_tail #hsz len; assert (S.equal (S.append #(hash #hsz) S.empty S.empty) (S.empty #(hash #hsz))); assert (S.equal (merge_hs #_ #f (empty_hashes len) (empty_hashes len)) (S.cons S.empty (merge_hs #_ #f (empty_hashes (len - 1)) (empty_hashes (len - 1))))); merge_hs_empty #_ #f (len - 1)) val merge_hs_index: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> hs1:hashess -> hs2:hashess{S.length hs1 = S.length hs2} -> i:nat{i < S.length hs1} -> Lemma (requires True) (ensures S.equal (S.index (merge_hs #_ #f hs1 hs2) i) (S.append (S.index hs1 i) (S.index hs2 i))) (decreases (S.length hs1)) [SMTPat (S.index (merge_hs #_ #f hs1 hs2) i)] let rec merge_hs_index #hsz #f hs1 hs2 i = if S.length hs1 = 0 then () else if i = 0 then () else merge_hs_index #_ #f (S.tail hs1) (S.tail hs2) (i - 1) val merge_hs_slice_equal: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> ahs1:hashess #hsz -> ahs2:hashess #hsz {S.length ahs1 = S.length ahs2} -> bhs1:hashess #hsz -> bhs2:hashess #hsz {S.length bhs1 = S.length bhs2} -> i:nat -> j:nat{i <= j && j <= S.length ahs1 && j <= S.length bhs1} -> Lemma (requires S.equal (S.slice ahs1 i j) (S.slice bhs1 i j) /\ S.equal (S.slice ahs2 i j) (S.slice bhs2 i j)) (ensures S.equal (S.slice (merge_hs #_ #f ahs1 ahs2) i j) (S.slice (merge_hs #_ #f bhs1 bhs2) i j)) (decreases (j - i)) let rec merge_hs_slice_equal #_ #f ahs1 ahs2 bhs1 bhs2 i j = if i = j then () else (assert (S.index ahs1 i == S.index bhs1 i); assert (S.index ahs2 i == S.index bhs2 i); merge_hs_slice_equal #_ #f ahs1 ahs2 bhs1 bhs2 (i + 1) j) val merge_hs_upd: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> hs1:hashess #hsz -> hs2:hashess #hsz {S.length hs1 = S.length hs2} -> i:nat{i < S.length hs1} -> v1:hashes #hsz -> v2:hashes #hsz -> Lemma (requires S.equal (S.append (S.index hs1 i) (S.index hs2 i)) (S.append v1 v2)) (ensures S.equal (merge_hs #_ #f hs1 hs2) (merge_hs #_ #f (S.upd hs1 i v1) (S.upd hs2 i v2))) (decreases i) let rec merge_hs_upd #_ #f hs1 hs2 i v1 v2 = if S.length hs1 = 0 then () else if i = 0 then () else merge_hs_upd #_ #f (S.tail hs1) (S.tail hs2) (i - 1) v1 v2 val mt_olds_inv: #hsz:pos -> lv:nat{lv <= 32} -> i:nat -> olds:hashess #hsz {S.length olds = 32} -> GTot Type0 (decreases (32 - lv)) let rec mt_olds_inv #hsz lv i olds = if lv = 32 then true else (let ofs = offset_of i in S.length (S.index olds lv) == ofs /\ mt_olds_inv #hsz (lv + 1) (i / 2) olds) val mt_olds_inv_equiv: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> lv:nat{lv <= 32} -> i:nat -> olds1:hashess #hsz {S.length olds1 = 32} -> olds2:hashess #hsz {S.length olds2 = 32} -> Lemma (requires mt_olds_inv #hsz lv i olds1 /\ S.equal (S.slice olds1 lv 32) (S.slice olds2 lv 32)) (ensures mt_olds_inv #hsz lv i olds2) (decreases (32 - lv)) let rec mt_olds_inv_equiv #hsz #f lv i olds1 olds2 = if lv = 32 then () else (assert (S.index olds1 lv == S.index olds2 lv); mt_olds_inv_equiv #_ #f (lv + 1) (i / 2) olds1 olds2) val mt_olds_hs_lth_inv_ok: #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 #hsz lv hs i j} -> Lemma (requires True) (ensures mt_hashes_lth_inv #hsz lv j (merge_hs #_ #f olds hs))
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "MerkleTree.Spec.fst.checked", "MerkleTree.New.High.fst.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Ghost.fsti.checked", "FStar.Classical.fsti.checked" ], "interface_file": false, "source_file": "MerkleTree.New.High.Correct.Base.fst" }
[ { "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": 2, "initial_ifuel": 1, "max_fuel": 1, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 40, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
lv: Prims.nat{lv <= 32} -> i: Prims.nat -> j: Prims.nat{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} -> FStar.Pervasives.Lemma (ensures MerkleTree.New.High.Correct.Base.mt_hashes_lth_inv lv j (MerkleTree.New.High.Correct.Base.merge_hs olds hs)) (decreases 32 - lv)
FStar.Pervasives.Lemma
[ "lemma", "" ]
[]
[ "Prims.pos", "MerkleTree.Spec.hash_fun_t", "Prims.nat", "Prims.b2t", "Prims.op_LessThanOrEqual", "Prims.l_and", "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", "Prims.bool", "MerkleTree.New.High.Correct.Base.mt_olds_hs_lth_inv_ok", "Prims.op_Addition", "Prims.op_Division", "Prims.unit" ]
[ "recursion" ]
false
false
true
false
false
let rec mt_olds_hs_lth_inv_ok #hsz #f lv i j olds hs =
if lv = 32 then () else (mt_olds_hs_lth_inv_ok #_ #f (lv + 1) (i / 2) (j / 2) olds hs)
false
MerkleTree.New.High.Correct.Base.fst
MerkleTree.New.High.Correct.Base.hash_seq_lift
val hash_seq_lift: #hsz:pos -> hs:hashes #hsz -> GTot (shs:MTS.hashes #hsz {S.length shs = S.length hs}) (decreases (S.length hs))
val hash_seq_lift: #hsz:pos -> hs:hashes #hsz -> GTot (shs:MTS.hashes #hsz {S.length shs = S.length hs}) (decreases (S.length hs))
let rec hash_seq_lift #hsz hs = if S.length hs = 0 then S.empty else S.cons (MTS.HRaw (S.head hs)) (hash_seq_lift #hsz (S.tail hs))
{ "file_name": "src/MerkleTree.New.High.Correct.Base.fst", "git_rev": "7d7bdc20f2033171e279c176b26e84f9069d23c6", "git_url": "https://github.com/hacl-star/merkle-tree.git", "project_name": "merkle-tree" }
{ "end_col": 69, "end_line": 411, "start_col": 0, "start_line": 409 }
module MerkleTree.New.High.Correct.Base open FStar.Classical open FStar.Ghost open FStar.Seq module S = FStar.Seq module MTS = MerkleTree.Spec open MerkleTree.New.High #set-options "--z3rlimit 40 --max_fuel 0 --max_ifuel 0" /// Sequence helpers val seq_prefix: #a:Type -> s1:S.seq a -> s2:S.seq a{S.length s1 <= S.length s2} -> GTot Type0 let seq_prefix #a s1 s2 = S.equal s1 (S.slice s2 0 (S.length s1)) val seq_head_cons: #a:Type -> x:a -> s:S.seq a -> Lemma (S.head (S.cons x s) == x) [SMTPat (S.cons x s)] let seq_head_cons #a x s = () val seq_tail_cons: #a:Type -> x:a -> s:S.seq a -> Lemma (S.equal (S.tail (S.cons x s)) s) [SMTPat (S.cons x s)] let seq_tail_cons #a x s = () /// Invariants and simulation relation of high-level Merkle tree design // Invariants of internal hashes val empty_hashes: (#hsz:pos) -> (len:nat) -> GTot (hs:hashess #hsz {S.length hs = len}) let empty_hashes #hsz len = S.create len S.empty val empty_hashes_head: #hsz:pos -> len:nat{len > 0} -> Lemma (S.head (empty_hashes #hsz len) == S.empty) let empty_hashes_head #_ _ = () val empty_hashes_tail: #hsz:pos -> len:nat{len > 0} -> Lemma (S.equal (S.tail (empty_hashes len)) (empty_hashes #hsz (len - 1))) let empty_hashes_tail #_ _ = () #push-options "--max_fuel 1" val mt_hashes_lth_inv: #hsz:pos -> lv:nat{lv <= 32} -> j:nat{j < pow2 (32 - lv)} -> fhs:hashess #hsz {S.length fhs = 32} -> GTot Type0 (decreases (32 - lv)) let rec mt_hashes_lth_inv #hsz lv j fhs = if lv = 32 then true else (S.length (S.index fhs lv) == j /\ mt_hashes_lth_inv (lv + 1) (j / 2) fhs) val mt_hashes_lth_inv_empty: #hsz:pos -> lv:nat{lv <= 32} -> Lemma (requires True) (ensures mt_hashes_lth_inv lv 0 (empty_hashes #hsz 32)) (decreases (32 - lv)) let rec mt_hashes_lth_inv_empty #hsz lv = if lv = 32 then () else mt_hashes_lth_inv_empty #hsz (lv + 1) val mt_hashes_next_rel: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> j:nat -> hs:hashes #hsz {S.length hs = j} -> nhs:hashes #hsz {S.length nhs = j / 2} -> GTot Type0 let mt_hashes_next_rel #hsz #f j hs nhs = forall (i:nat{i < j / 2}). S.index nhs i == f (S.index hs (op_Multiply 2 i)) (S.index hs (op_Multiply 2 i + 1)) #pop-options #push-options "--max_fuel 2" val mt_hashes_inv: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> lv:nat{lv < 32} -> j:nat{j < pow2 (32 - lv)} -> fhs:hashess #hsz {S.length fhs = 32 /\ mt_hashes_lth_inv lv j fhs} -> GTot Type0 (decreases (32 - lv)) let rec mt_hashes_inv #hsz #f lv j fhs = if lv = 31 then true else (mt_hashes_next_rel #_ #f j (S.index fhs lv) (S.index fhs (lv + 1)) /\ mt_hashes_inv #_ #f (lv + 1) (j / 2) fhs) val mt_hashes_inv_empty: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> lv:nat{lv < 32} -> Lemma (requires True) (ensures (mt_hashes_lth_inv_empty #hsz lv; mt_hashes_inv #hsz #f lv 0 (empty_hashes #hsz 32))) (decreases (32 - lv)) let rec mt_hashes_inv_empty #hsz #f lv = if lv = 31 then () else (mt_hashes_lth_inv_empty #hsz (lv + 1); mt_hashes_inv_empty #_ #f (lv + 1)) val mt_hashes_lth_inv_equiv: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> lv:nat{lv < 32} -> j:nat{j < pow2 (32 - lv)} -> fhs1:hashess{S.length fhs1 = 32} -> fhs2:hashess{S.length fhs2 = 32} -> Lemma (requires mt_hashes_lth_inv lv j fhs1 /\ S.equal (S.slice fhs1 lv 32) (S.slice fhs2 lv 32)) (ensures mt_hashes_lth_inv #hsz lv j fhs2) (decreases (32 - lv)) let rec mt_hashes_lth_inv_equiv #hsz #f lv j fhs1 fhs2 = if lv = 31 then () else (assert (S.index fhs1 lv == S.index fhs2 lv); mt_hashes_lth_inv_equiv #_ #f (lv + 1) (j / 2) fhs1 fhs2) #pop-options #push-options "--max_fuel 1" val mt_hashes_inv_equiv: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> lv:nat{lv < 32} -> j:nat{j < pow2 (32 - lv)} -> fhs1:hashess #hsz {S.length fhs1 = 32 /\ mt_hashes_lth_inv lv j fhs1} -> fhs2:hashess #hsz {S.length fhs2 = 32 /\ mt_hashes_lth_inv lv j fhs2} -> Lemma (requires mt_hashes_inv #_ #f lv j fhs1 /\ S.equal (S.slice fhs1 lv 32) (S.slice fhs2 lv 32)) (ensures mt_hashes_inv #_ #f lv j fhs2) (decreases (32 - lv)) let rec mt_hashes_inv_equiv #hsz #f lv j fhs1 fhs2 = if lv = 31 then () else (assert (S.index fhs1 lv == S.index fhs2 lv); assert (S.index fhs1 (lv + 1) == S.index fhs2 (lv + 1)); mt_hashes_inv_equiv #_ #f (lv + 1) (j / 2) fhs1 fhs2) val merge_hs: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> hs1:hashess #hsz -> hs2:hashess #hsz {S.length hs1 = S.length hs2} -> GTot (mhs:hashess #hsz {S.length mhs = S.length hs1}) (decreases (S.length hs1)) let rec merge_hs #hsz #f hs1 hs2 = if S.length hs1 = 0 then S.empty else (S.cons (S.append (S.head hs1) (S.head hs2)) (merge_hs #_ #f (S.tail hs1) (S.tail hs2))) val merge_hs_empty: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> len:nat -> Lemma (S.equal (merge_hs #_ #f (empty_hashes #hsz len) (empty_hashes #hsz len)) (empty_hashes #hsz len)) let rec merge_hs_empty #hsz #f len = if len = 0 then () else (empty_hashes_head #hsz len; empty_hashes_tail #hsz len; assert (S.equal (S.append #(hash #hsz) S.empty S.empty) (S.empty #(hash #hsz))); assert (S.equal (merge_hs #_ #f (empty_hashes len) (empty_hashes len)) (S.cons S.empty (merge_hs #_ #f (empty_hashes (len - 1)) (empty_hashes (len - 1))))); merge_hs_empty #_ #f (len - 1)) val merge_hs_index: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> hs1:hashess -> hs2:hashess{S.length hs1 = S.length hs2} -> i:nat{i < S.length hs1} -> Lemma (requires True) (ensures S.equal (S.index (merge_hs #_ #f hs1 hs2) i) (S.append (S.index hs1 i) (S.index hs2 i))) (decreases (S.length hs1)) [SMTPat (S.index (merge_hs #_ #f hs1 hs2) i)] let rec merge_hs_index #hsz #f hs1 hs2 i = if S.length hs1 = 0 then () else if i = 0 then () else merge_hs_index #_ #f (S.tail hs1) (S.tail hs2) (i - 1) val merge_hs_slice_equal: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> ahs1:hashess #hsz -> ahs2:hashess #hsz {S.length ahs1 = S.length ahs2} -> bhs1:hashess #hsz -> bhs2:hashess #hsz {S.length bhs1 = S.length bhs2} -> i:nat -> j:nat{i <= j && j <= S.length ahs1 && j <= S.length bhs1} -> Lemma (requires S.equal (S.slice ahs1 i j) (S.slice bhs1 i j) /\ S.equal (S.slice ahs2 i j) (S.slice bhs2 i j)) (ensures S.equal (S.slice (merge_hs #_ #f ahs1 ahs2) i j) (S.slice (merge_hs #_ #f bhs1 bhs2) i j)) (decreases (j - i)) let rec merge_hs_slice_equal #_ #f ahs1 ahs2 bhs1 bhs2 i j = if i = j then () else (assert (S.index ahs1 i == S.index bhs1 i); assert (S.index ahs2 i == S.index bhs2 i); merge_hs_slice_equal #_ #f ahs1 ahs2 bhs1 bhs2 (i + 1) j) val merge_hs_upd: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> hs1:hashess #hsz -> hs2:hashess #hsz {S.length hs1 = S.length hs2} -> i:nat{i < S.length hs1} -> v1:hashes #hsz -> v2:hashes #hsz -> Lemma (requires S.equal (S.append (S.index hs1 i) (S.index hs2 i)) (S.append v1 v2)) (ensures S.equal (merge_hs #_ #f hs1 hs2) (merge_hs #_ #f (S.upd hs1 i v1) (S.upd hs2 i v2))) (decreases i) let rec merge_hs_upd #_ #f hs1 hs2 i v1 v2 = if S.length hs1 = 0 then () else if i = 0 then () else merge_hs_upd #_ #f (S.tail hs1) (S.tail hs2) (i - 1) v1 v2 val mt_olds_inv: #hsz:pos -> lv:nat{lv <= 32} -> i:nat -> olds:hashess #hsz {S.length olds = 32} -> GTot Type0 (decreases (32 - lv)) let rec mt_olds_inv #hsz lv i olds = if lv = 32 then true else (let ofs = offset_of i in S.length (S.index olds lv) == ofs /\ mt_olds_inv #hsz (lv + 1) (i / 2) olds) val mt_olds_inv_equiv: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> lv:nat{lv <= 32} -> i:nat -> olds1:hashess #hsz {S.length olds1 = 32} -> olds2:hashess #hsz {S.length olds2 = 32} -> Lemma (requires mt_olds_inv #hsz lv i olds1 /\ S.equal (S.slice olds1 lv 32) (S.slice olds2 lv 32)) (ensures mt_olds_inv #hsz lv i olds2) (decreases (32 - lv)) let rec mt_olds_inv_equiv #hsz #f lv i olds1 olds2 = if lv = 32 then () else (assert (S.index olds1 lv == S.index olds2 lv); mt_olds_inv_equiv #_ #f (lv + 1) (i / 2) olds1 olds2) val mt_olds_hs_lth_inv_ok: #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 #hsz lv hs i j} -> Lemma (requires True) (ensures mt_hashes_lth_inv #hsz lv j (merge_hs #_ #f olds hs)) (decreases (32 - lv)) let rec mt_olds_hs_lth_inv_ok #hsz #f lv i j olds hs = if lv = 32 then () else (mt_olds_hs_lth_inv_ok #_ #f (lv + 1) (i / 2) (j / 2) olds hs) val mt_olds_hs_inv: #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 #hsz lv hs i j} -> GTot Type0 let mt_olds_hs_inv #hsz #f lv i j olds hs = mt_olds_hs_lth_inv_ok #_ #f lv i j olds hs; mt_hashes_inv #_ #f lv j (merge_hs #_ #f olds hs) // Relation between valid internal hashes (satisfying `mt_olds_hs_inv`) and // the spec. While giving such relation, all rightmost hashes are recovered. // Note that `MT?.rhs` after `construct_rhs` does NOT contain all rightmost // hashes; it has partial rightmost hashes that are enough to calculate // Merkle paths. val log2: n:nat{n > 0} -> GTot (c:nat{pow2 c <= n && n < pow2 (c+1)}) let rec log2 n = if n = 1 then 0 else 1 + log2 (n / 2) val log2_bound: n:nat{n > 0} -> c:nat{n < pow2 c} -> Lemma (log2 n <= c-1) let rec log2_bound n c = if n = 1 then () else log2_bound (n / 2) (c - 1) val log2_div: n:nat{n > 1} -> Lemma (log2 (n / 2) = log2 n - 1) let log2_div n = () val log2c: n:nat -> GTot (c:nat{c = 0 || (pow2 (c-1) <= n && n < pow2 c)}) let log2c n = if n = 0 then 0 else (log2 n + 1) val log2c_div: n:nat{n > 0} -> Lemma (log2c (n / 2) = log2c n - 1) let log2c_div n = () val log2c_bound: n:nat -> c:nat{n < pow2 c} -> Lemma (log2c n <= c) let rec log2c_bound n c = if n = 0 then () else log2c_bound (n / 2) (c - 1) val mt_hashes_lth_inv_log: #hsz:pos -> j:nat -> fhs:hashess #hsz {S.length fhs = log2c j} -> GTot Type0 (decreases j) let rec mt_hashes_lth_inv_log #hsz j fhs = if j = 0 then true else (S.length (S.head fhs) == j /\ mt_hashes_lth_inv_log #hsz (j / 2) (S.tail fhs)) #pop-options #push-options "--max_fuel 2" val mt_hashes_lth_inv_log_next: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> j:nat{j > 1} -> fhs:hashess #hsz {S.length fhs = log2c j} -> Lemma (requires mt_hashes_lth_inv_log #hsz j fhs) (ensures S.length (S.head fhs) == j /\ S.length (S.head (S.tail fhs)) == j / 2) let mt_hashes_lth_inv_log_next #_ #_ _ _ = () val mt_hashes_inv_log: #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} -> GTot Type0 (decreases j) let rec mt_hashes_inv_log #hsz #f j fhs = if j <= 1 then true else (mt_hashes_next_rel #_ #f j (S.index fhs 0) (S.index fhs 1) /\ mt_hashes_inv_log #_ #f (j / 2) (S.tail fhs)) val mt_hashes_lth_inv_log_converted_: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> lv:nat{lv <= 32} -> j:nat{j < pow2 (32 - lv)} -> fhs:hashess #hsz {S.length fhs = 32} -> Lemma (requires mt_hashes_lth_inv #hsz lv j fhs) (ensures (log2c_bound j (32 - lv); mt_hashes_lth_inv_log #hsz j (S.slice fhs lv (lv + log2c j)))) (decreases j) let rec mt_hashes_lth_inv_log_converted_ #_ #f lv j fhs = if j = 0 then () else (log2c_bound (j / 2) (32 - (lv + 1)); mt_hashes_lth_inv_log_converted_ #_ #f (lv + 1) (j / 2) fhs) val mt_hashes_lth_inv_log_converted: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> j:nat{j < pow2 32} -> fhs:hashess #hsz {S.length fhs = 32} -> Lemma (requires mt_hashes_lth_inv #hsz 0 j fhs) (ensures (log2c_bound j 32; mt_hashes_lth_inv_log #hsz j (S.slice fhs 0 (log2c j)))) let mt_hashes_lth_inv_log_converted #_ #f j fhs = mt_hashes_lth_inv_log_converted_ #_ #f 0 j fhs val mt_hashes_inv_log_converted_: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> lv:nat{lv <= 32} -> j:nat{j > 0 && j < pow2 (32 - lv)} -> fhs:hashess #hsz {S.length fhs = 32 /\ mt_hashes_lth_inv #hsz lv j fhs} -> Lemma (requires mt_hashes_inv #_ #f lv j fhs) (ensures (log2c_bound j (32 - lv); mt_hashes_lth_inv_log_converted_ #_ #f lv j fhs; mt_hashes_inv_log #_ #f j (S.slice fhs lv (lv + log2c j)))) (decreases j) #pop-options #push-options "--z3rlimit 100 --initial_fuel 2 --max_fuel 2" let rec mt_hashes_inv_log_converted_ #_ #f lv j fhs = if j = 1 then () else (log2c_bound (j / 2) (32 - (lv + 1)); mt_hashes_lth_inv_log_converted_ #_ #f (lv + 1) (j / 2) fhs; mt_hashes_inv_log_converted_ #_ #f (lv + 1) (j / 2) fhs) #pop-options val mt_hashes_inv_log_converted: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> j:nat{j > 0 && j < pow2 32} -> fhs:hashess #hsz {S.length fhs = 32 /\ mt_hashes_lth_inv #hsz 0 j fhs} -> Lemma (requires mt_hashes_inv #_ #f 0 j fhs) (ensures (log2c_bound j 32; mt_hashes_lth_inv_log_converted_ #_ #f 0 j fhs; mt_hashes_inv_log #_ #f j (S.slice fhs 0 (log2c j)))) let mt_hashes_inv_log_converted #_ #f j fhs = mt_hashes_inv_log_converted_ #_ #f 0 j fhs val hash_seq_lift: #hsz:pos -> hs:hashes #hsz -> GTot (shs:MTS.hashes #hsz {S.length shs = S.length hs})
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "MerkleTree.Spec.fst.checked", "MerkleTree.New.High.fst.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Ghost.fsti.checked", "FStar.Classical.fsti.checked" ], "interface_file": false, "source_file": "MerkleTree.New.High.Correct.Base.fst" }
[ { "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": 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": 40, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
hs: MerkleTree.New.High.hashes -> Prims.GTot (shs: MerkleTree.Spec.hashes{FStar.Seq.Base.length shs = FStar.Seq.Base.length hs})
Prims.GTot
[ "sometrivial", "" ]
[]
[ "Prims.pos", "MerkleTree.New.High.hashes", "Prims.op_Equality", "Prims.int", "FStar.Seq.Base.length", "MerkleTree.New.High.hash", "FStar.Seq.Base.empty", "MerkleTree.Spec.padded_hash", "Prims.bool", "FStar.Seq.Base.cons", "MerkleTree.Spec.HRaw", "FStar.Seq.Properties.head", "MerkleTree.New.High.Correct.Base.hash_seq_lift", "FStar.Seq.Properties.tail", "MerkleTree.Spec.hashes", "Prims.b2t", "Prims.nat" ]
[ "recursion" ]
false
false
false
false
false
let rec hash_seq_lift #hsz hs =
if S.length hs = 0 then S.empty else S.cons (MTS.HRaw (S.head hs)) (hash_seq_lift #hsz (S.tail hs))
false
MerkleTree.New.High.Correct.Base.fst
MerkleTree.New.High.Correct.Base.hash_seq_spec
val hash_seq_spec: #hsz:pos -> hs:hashes #hsz {S.length hs > 0} -> GTot (MTS.merkle_tree #hsz (log2c (S.length hs)))
val hash_seq_spec: #hsz:pos -> hs:hashes #hsz {S.length hs > 0} -> GTot (MTS.merkle_tree #hsz (log2c (S.length hs)))
let hash_seq_spec #hsz hs = S.append (hash_seq_lift #hsz hs) (create_pads (pow2 (log2c (S.length hs)) - S.length hs))
{ "file_name": "src/MerkleTree.New.High.Correct.Base.fst", "git_rev": "7d7bdc20f2033171e279c176b26e84f9069d23c6", "git_url": "https://github.com/hacl-star/merkle-tree.git", "project_name": "merkle-tree" }
{ "end_col": 67, "end_line": 435, "start_col": 0, "start_line": 433 }
module MerkleTree.New.High.Correct.Base open FStar.Classical open FStar.Ghost open FStar.Seq module S = FStar.Seq module MTS = MerkleTree.Spec open MerkleTree.New.High #set-options "--z3rlimit 40 --max_fuel 0 --max_ifuel 0" /// Sequence helpers val seq_prefix: #a:Type -> s1:S.seq a -> s2:S.seq a{S.length s1 <= S.length s2} -> GTot Type0 let seq_prefix #a s1 s2 = S.equal s1 (S.slice s2 0 (S.length s1)) val seq_head_cons: #a:Type -> x:a -> s:S.seq a -> Lemma (S.head (S.cons x s) == x) [SMTPat (S.cons x s)] let seq_head_cons #a x s = () val seq_tail_cons: #a:Type -> x:a -> s:S.seq a -> Lemma (S.equal (S.tail (S.cons x s)) s) [SMTPat (S.cons x s)] let seq_tail_cons #a x s = () /// Invariants and simulation relation of high-level Merkle tree design // Invariants of internal hashes val empty_hashes: (#hsz:pos) -> (len:nat) -> GTot (hs:hashess #hsz {S.length hs = len}) let empty_hashes #hsz len = S.create len S.empty val empty_hashes_head: #hsz:pos -> len:nat{len > 0} -> Lemma (S.head (empty_hashes #hsz len) == S.empty) let empty_hashes_head #_ _ = () val empty_hashes_tail: #hsz:pos -> len:nat{len > 0} -> Lemma (S.equal (S.tail (empty_hashes len)) (empty_hashes #hsz (len - 1))) let empty_hashes_tail #_ _ = () #push-options "--max_fuel 1" val mt_hashes_lth_inv: #hsz:pos -> lv:nat{lv <= 32} -> j:nat{j < pow2 (32 - lv)} -> fhs:hashess #hsz {S.length fhs = 32} -> GTot Type0 (decreases (32 - lv)) let rec mt_hashes_lth_inv #hsz lv j fhs = if lv = 32 then true else (S.length (S.index fhs lv) == j /\ mt_hashes_lth_inv (lv + 1) (j / 2) fhs) val mt_hashes_lth_inv_empty: #hsz:pos -> lv:nat{lv <= 32} -> Lemma (requires True) (ensures mt_hashes_lth_inv lv 0 (empty_hashes #hsz 32)) (decreases (32 - lv)) let rec mt_hashes_lth_inv_empty #hsz lv = if lv = 32 then () else mt_hashes_lth_inv_empty #hsz (lv + 1) val mt_hashes_next_rel: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> j:nat -> hs:hashes #hsz {S.length hs = j} -> nhs:hashes #hsz {S.length nhs = j / 2} -> GTot Type0 let mt_hashes_next_rel #hsz #f j hs nhs = forall (i:nat{i < j / 2}). S.index nhs i == f (S.index hs (op_Multiply 2 i)) (S.index hs (op_Multiply 2 i + 1)) #pop-options #push-options "--max_fuel 2" val mt_hashes_inv: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> lv:nat{lv < 32} -> j:nat{j < pow2 (32 - lv)} -> fhs:hashess #hsz {S.length fhs = 32 /\ mt_hashes_lth_inv lv j fhs} -> GTot Type0 (decreases (32 - lv)) let rec mt_hashes_inv #hsz #f lv j fhs = if lv = 31 then true else (mt_hashes_next_rel #_ #f j (S.index fhs lv) (S.index fhs (lv + 1)) /\ mt_hashes_inv #_ #f (lv + 1) (j / 2) fhs) val mt_hashes_inv_empty: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> lv:nat{lv < 32} -> Lemma (requires True) (ensures (mt_hashes_lth_inv_empty #hsz lv; mt_hashes_inv #hsz #f lv 0 (empty_hashes #hsz 32))) (decreases (32 - lv)) let rec mt_hashes_inv_empty #hsz #f lv = if lv = 31 then () else (mt_hashes_lth_inv_empty #hsz (lv + 1); mt_hashes_inv_empty #_ #f (lv + 1)) val mt_hashes_lth_inv_equiv: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> lv:nat{lv < 32} -> j:nat{j < pow2 (32 - lv)} -> fhs1:hashess{S.length fhs1 = 32} -> fhs2:hashess{S.length fhs2 = 32} -> Lemma (requires mt_hashes_lth_inv lv j fhs1 /\ S.equal (S.slice fhs1 lv 32) (S.slice fhs2 lv 32)) (ensures mt_hashes_lth_inv #hsz lv j fhs2) (decreases (32 - lv)) let rec mt_hashes_lth_inv_equiv #hsz #f lv j fhs1 fhs2 = if lv = 31 then () else (assert (S.index fhs1 lv == S.index fhs2 lv); mt_hashes_lth_inv_equiv #_ #f (lv + 1) (j / 2) fhs1 fhs2) #pop-options #push-options "--max_fuel 1" val mt_hashes_inv_equiv: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> lv:nat{lv < 32} -> j:nat{j < pow2 (32 - lv)} -> fhs1:hashess #hsz {S.length fhs1 = 32 /\ mt_hashes_lth_inv lv j fhs1} -> fhs2:hashess #hsz {S.length fhs2 = 32 /\ mt_hashes_lth_inv lv j fhs2} -> Lemma (requires mt_hashes_inv #_ #f lv j fhs1 /\ S.equal (S.slice fhs1 lv 32) (S.slice fhs2 lv 32)) (ensures mt_hashes_inv #_ #f lv j fhs2) (decreases (32 - lv)) let rec mt_hashes_inv_equiv #hsz #f lv j fhs1 fhs2 = if lv = 31 then () else (assert (S.index fhs1 lv == S.index fhs2 lv); assert (S.index fhs1 (lv + 1) == S.index fhs2 (lv + 1)); mt_hashes_inv_equiv #_ #f (lv + 1) (j / 2) fhs1 fhs2) val merge_hs: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> hs1:hashess #hsz -> hs2:hashess #hsz {S.length hs1 = S.length hs2} -> GTot (mhs:hashess #hsz {S.length mhs = S.length hs1}) (decreases (S.length hs1)) let rec merge_hs #hsz #f hs1 hs2 = if S.length hs1 = 0 then S.empty else (S.cons (S.append (S.head hs1) (S.head hs2)) (merge_hs #_ #f (S.tail hs1) (S.tail hs2))) val merge_hs_empty: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> len:nat -> Lemma (S.equal (merge_hs #_ #f (empty_hashes #hsz len) (empty_hashes #hsz len)) (empty_hashes #hsz len)) let rec merge_hs_empty #hsz #f len = if len = 0 then () else (empty_hashes_head #hsz len; empty_hashes_tail #hsz len; assert (S.equal (S.append #(hash #hsz) S.empty S.empty) (S.empty #(hash #hsz))); assert (S.equal (merge_hs #_ #f (empty_hashes len) (empty_hashes len)) (S.cons S.empty (merge_hs #_ #f (empty_hashes (len - 1)) (empty_hashes (len - 1))))); merge_hs_empty #_ #f (len - 1)) val merge_hs_index: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> hs1:hashess -> hs2:hashess{S.length hs1 = S.length hs2} -> i:nat{i < S.length hs1} -> Lemma (requires True) (ensures S.equal (S.index (merge_hs #_ #f hs1 hs2) i) (S.append (S.index hs1 i) (S.index hs2 i))) (decreases (S.length hs1)) [SMTPat (S.index (merge_hs #_ #f hs1 hs2) i)] let rec merge_hs_index #hsz #f hs1 hs2 i = if S.length hs1 = 0 then () else if i = 0 then () else merge_hs_index #_ #f (S.tail hs1) (S.tail hs2) (i - 1) val merge_hs_slice_equal: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> ahs1:hashess #hsz -> ahs2:hashess #hsz {S.length ahs1 = S.length ahs2} -> bhs1:hashess #hsz -> bhs2:hashess #hsz {S.length bhs1 = S.length bhs2} -> i:nat -> j:nat{i <= j && j <= S.length ahs1 && j <= S.length bhs1} -> Lemma (requires S.equal (S.slice ahs1 i j) (S.slice bhs1 i j) /\ S.equal (S.slice ahs2 i j) (S.slice bhs2 i j)) (ensures S.equal (S.slice (merge_hs #_ #f ahs1 ahs2) i j) (S.slice (merge_hs #_ #f bhs1 bhs2) i j)) (decreases (j - i)) let rec merge_hs_slice_equal #_ #f ahs1 ahs2 bhs1 bhs2 i j = if i = j then () else (assert (S.index ahs1 i == S.index bhs1 i); assert (S.index ahs2 i == S.index bhs2 i); merge_hs_slice_equal #_ #f ahs1 ahs2 bhs1 bhs2 (i + 1) j) val merge_hs_upd: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> hs1:hashess #hsz -> hs2:hashess #hsz {S.length hs1 = S.length hs2} -> i:nat{i < S.length hs1} -> v1:hashes #hsz -> v2:hashes #hsz -> Lemma (requires S.equal (S.append (S.index hs1 i) (S.index hs2 i)) (S.append v1 v2)) (ensures S.equal (merge_hs #_ #f hs1 hs2) (merge_hs #_ #f (S.upd hs1 i v1) (S.upd hs2 i v2))) (decreases i) let rec merge_hs_upd #_ #f hs1 hs2 i v1 v2 = if S.length hs1 = 0 then () else if i = 0 then () else merge_hs_upd #_ #f (S.tail hs1) (S.tail hs2) (i - 1) v1 v2 val mt_olds_inv: #hsz:pos -> lv:nat{lv <= 32} -> i:nat -> olds:hashess #hsz {S.length olds = 32} -> GTot Type0 (decreases (32 - lv)) let rec mt_olds_inv #hsz lv i olds = if lv = 32 then true else (let ofs = offset_of i in S.length (S.index olds lv) == ofs /\ mt_olds_inv #hsz (lv + 1) (i / 2) olds) val mt_olds_inv_equiv: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> lv:nat{lv <= 32} -> i:nat -> olds1:hashess #hsz {S.length olds1 = 32} -> olds2:hashess #hsz {S.length olds2 = 32} -> Lemma (requires mt_olds_inv #hsz lv i olds1 /\ S.equal (S.slice olds1 lv 32) (S.slice olds2 lv 32)) (ensures mt_olds_inv #hsz lv i olds2) (decreases (32 - lv)) let rec mt_olds_inv_equiv #hsz #f lv i olds1 olds2 = if lv = 32 then () else (assert (S.index olds1 lv == S.index olds2 lv); mt_olds_inv_equiv #_ #f (lv + 1) (i / 2) olds1 olds2) val mt_olds_hs_lth_inv_ok: #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 #hsz lv hs i j} -> Lemma (requires True) (ensures mt_hashes_lth_inv #hsz lv j (merge_hs #_ #f olds hs)) (decreases (32 - lv)) let rec mt_olds_hs_lth_inv_ok #hsz #f lv i j olds hs = if lv = 32 then () else (mt_olds_hs_lth_inv_ok #_ #f (lv + 1) (i / 2) (j / 2) olds hs) val mt_olds_hs_inv: #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 #hsz lv hs i j} -> GTot Type0 let mt_olds_hs_inv #hsz #f lv i j olds hs = mt_olds_hs_lth_inv_ok #_ #f lv i j olds hs; mt_hashes_inv #_ #f lv j (merge_hs #_ #f olds hs) // Relation between valid internal hashes (satisfying `mt_olds_hs_inv`) and // the spec. While giving such relation, all rightmost hashes are recovered. // Note that `MT?.rhs` after `construct_rhs` does NOT contain all rightmost // hashes; it has partial rightmost hashes that are enough to calculate // Merkle paths. val log2: n:nat{n > 0} -> GTot (c:nat{pow2 c <= n && n < pow2 (c+1)}) let rec log2 n = if n = 1 then 0 else 1 + log2 (n / 2) val log2_bound: n:nat{n > 0} -> c:nat{n < pow2 c} -> Lemma (log2 n <= c-1) let rec log2_bound n c = if n = 1 then () else log2_bound (n / 2) (c - 1) val log2_div: n:nat{n > 1} -> Lemma (log2 (n / 2) = log2 n - 1) let log2_div n = () val log2c: n:nat -> GTot (c:nat{c = 0 || (pow2 (c-1) <= n && n < pow2 c)}) let log2c n = if n = 0 then 0 else (log2 n + 1) val log2c_div: n:nat{n > 0} -> Lemma (log2c (n / 2) = log2c n - 1) let log2c_div n = () val log2c_bound: n:nat -> c:nat{n < pow2 c} -> Lemma (log2c n <= c) let rec log2c_bound n c = if n = 0 then () else log2c_bound (n / 2) (c - 1) val mt_hashes_lth_inv_log: #hsz:pos -> j:nat -> fhs:hashess #hsz {S.length fhs = log2c j} -> GTot Type0 (decreases j) let rec mt_hashes_lth_inv_log #hsz j fhs = if j = 0 then true else (S.length (S.head fhs) == j /\ mt_hashes_lth_inv_log #hsz (j / 2) (S.tail fhs)) #pop-options #push-options "--max_fuel 2" val mt_hashes_lth_inv_log_next: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> j:nat{j > 1} -> fhs:hashess #hsz {S.length fhs = log2c j} -> Lemma (requires mt_hashes_lth_inv_log #hsz j fhs) (ensures S.length (S.head fhs) == j /\ S.length (S.head (S.tail fhs)) == j / 2) let mt_hashes_lth_inv_log_next #_ #_ _ _ = () val mt_hashes_inv_log: #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} -> GTot Type0 (decreases j) let rec mt_hashes_inv_log #hsz #f j fhs = if j <= 1 then true else (mt_hashes_next_rel #_ #f j (S.index fhs 0) (S.index fhs 1) /\ mt_hashes_inv_log #_ #f (j / 2) (S.tail fhs)) val mt_hashes_lth_inv_log_converted_: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> lv:nat{lv <= 32} -> j:nat{j < pow2 (32 - lv)} -> fhs:hashess #hsz {S.length fhs = 32} -> Lemma (requires mt_hashes_lth_inv #hsz lv j fhs) (ensures (log2c_bound j (32 - lv); mt_hashes_lth_inv_log #hsz j (S.slice fhs lv (lv + log2c j)))) (decreases j) let rec mt_hashes_lth_inv_log_converted_ #_ #f lv j fhs = if j = 0 then () else (log2c_bound (j / 2) (32 - (lv + 1)); mt_hashes_lth_inv_log_converted_ #_ #f (lv + 1) (j / 2) fhs) val mt_hashes_lth_inv_log_converted: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> j:nat{j < pow2 32} -> fhs:hashess #hsz {S.length fhs = 32} -> Lemma (requires mt_hashes_lth_inv #hsz 0 j fhs) (ensures (log2c_bound j 32; mt_hashes_lth_inv_log #hsz j (S.slice fhs 0 (log2c j)))) let mt_hashes_lth_inv_log_converted #_ #f j fhs = mt_hashes_lth_inv_log_converted_ #_ #f 0 j fhs val mt_hashes_inv_log_converted_: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> lv:nat{lv <= 32} -> j:nat{j > 0 && j < pow2 (32 - lv)} -> fhs:hashess #hsz {S.length fhs = 32 /\ mt_hashes_lth_inv #hsz lv j fhs} -> Lemma (requires mt_hashes_inv #_ #f lv j fhs) (ensures (log2c_bound j (32 - lv); mt_hashes_lth_inv_log_converted_ #_ #f lv j fhs; mt_hashes_inv_log #_ #f j (S.slice fhs lv (lv + log2c j)))) (decreases j) #pop-options #push-options "--z3rlimit 100 --initial_fuel 2 --max_fuel 2" let rec mt_hashes_inv_log_converted_ #_ #f lv j fhs = if j = 1 then () else (log2c_bound (j / 2) (32 - (lv + 1)); mt_hashes_lth_inv_log_converted_ #_ #f (lv + 1) (j / 2) fhs; mt_hashes_inv_log_converted_ #_ #f (lv + 1) (j / 2) fhs) #pop-options val mt_hashes_inv_log_converted: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> j:nat{j > 0 && j < pow2 32} -> fhs:hashess #hsz {S.length fhs = 32 /\ mt_hashes_lth_inv #hsz 0 j fhs} -> Lemma (requires mt_hashes_inv #_ #f 0 j fhs) (ensures (log2c_bound j 32; mt_hashes_lth_inv_log_converted_ #_ #f 0 j fhs; mt_hashes_inv_log #_ #f j (S.slice fhs 0 (log2c j)))) let mt_hashes_inv_log_converted #_ #f j fhs = mt_hashes_inv_log_converted_ #_ #f 0 j fhs val hash_seq_lift: #hsz:pos -> hs:hashes #hsz -> GTot (shs:MTS.hashes #hsz {S.length shs = S.length hs}) (decreases (S.length hs)) let rec hash_seq_lift #hsz hs = if S.length hs = 0 then S.empty else S.cons (MTS.HRaw (S.head hs)) (hash_seq_lift #hsz (S.tail hs)) #push-options "--z3rlimit 50 --initial_fuel 2 --max_fuel 2" val hash_seq_lift_index: #hsz:pos -> hs:hashes #hsz -> Lemma (requires True) (ensures forall (i:nat{i < S.length hs}). S.index (hash_seq_lift #hsz hs) i == MTS.HRaw (S.index hs i)) (decreases (S.length hs)) let rec hash_seq_lift_index #hsz hs = if S.length hs = 0 then () else hash_seq_lift_index #hsz (S.tail hs) #pop-options val create_pads: #hsz:pos -> len:nat -> GTot (pads:MTS.hashes #hsz {S.length pads = len}) let create_pads #hsz len = S.create len (MTS.HPad #hsz) val hash_seq_spec: #hsz:pos -> hs:hashes #hsz {S.length hs > 0} ->
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "MerkleTree.Spec.fst.checked", "MerkleTree.New.High.fst.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Ghost.fsti.checked", "FStar.Classical.fsti.checked" ], "interface_file": false, "source_file": "MerkleTree.New.High.Correct.Base.fst" }
[ { "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": 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": 40, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
hs: MerkleTree.New.High.hashes{FStar.Seq.Base.length hs > 0} -> Prims.GTot (MerkleTree.Spec.merkle_tree (MerkleTree.New.High.Correct.Base.log2c (FStar.Seq.Base.length hs)) )
Prims.GTot
[ "sometrivial" ]
[]
[ "Prims.pos", "MerkleTree.New.High.hashes", "Prims.b2t", "Prims.op_GreaterThan", "FStar.Seq.Base.length", "MerkleTree.New.High.hash", "FStar.Seq.Base.append", "MerkleTree.Spec.padded_hash", "MerkleTree.New.High.Correct.Base.hash_seq_lift", "MerkleTree.New.High.Correct.Base.create_pads", "Prims.op_Subtraction", "Prims.pow2", "MerkleTree.New.High.Correct.Base.log2c", "MerkleTree.Spec.merkle_tree" ]
[]
false
false
false
false
false
let hash_seq_spec #hsz hs =
S.append (hash_seq_lift #hsz hs) (create_pads (pow2 (log2c (S.length hs)) - S.length hs))
false
MerkleTree.New.High.Correct.Base.fst
MerkleTree.New.High.Correct.Base.hash_seq_spec_full
val hash_seq_spec_full: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> hs:hashes #hsz {S.length hs > 0} -> acc:hash #hsz -> actd:bool -> GTot (MTS.merkle_tree #hsz (log2c (S.length hs)))
val hash_seq_spec_full: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> hs:hashes #hsz {S.length hs > 0} -> acc:hash #hsz -> actd:bool -> GTot (MTS.merkle_tree #hsz (log2c (S.length hs)))
let hash_seq_spec_full #hsz #f hs acc actd = if actd then (S.upd (hash_seq_spec #hsz hs) (S.length hs) (MTS.HRaw acc)) else hash_seq_spec #hsz hs
{ "file_name": "src/MerkleTree.New.High.Correct.Base.fst", "git_rev": "7d7bdc20f2033171e279c176b26e84f9069d23c6", "git_url": "https://github.com/hacl-star/merkle-tree.git", "project_name": "merkle-tree" }
{ "end_col": 28, "end_line": 497, "start_col": 0, "start_line": 494 }
module MerkleTree.New.High.Correct.Base open FStar.Classical open FStar.Ghost open FStar.Seq module S = FStar.Seq module MTS = MerkleTree.Spec open MerkleTree.New.High #set-options "--z3rlimit 40 --max_fuel 0 --max_ifuel 0" /// Sequence helpers val seq_prefix: #a:Type -> s1:S.seq a -> s2:S.seq a{S.length s1 <= S.length s2} -> GTot Type0 let seq_prefix #a s1 s2 = S.equal s1 (S.slice s2 0 (S.length s1)) val seq_head_cons: #a:Type -> x:a -> s:S.seq a -> Lemma (S.head (S.cons x s) == x) [SMTPat (S.cons x s)] let seq_head_cons #a x s = () val seq_tail_cons: #a:Type -> x:a -> s:S.seq a -> Lemma (S.equal (S.tail (S.cons x s)) s) [SMTPat (S.cons x s)] let seq_tail_cons #a x s = () /// Invariants and simulation relation of high-level Merkle tree design // Invariants of internal hashes val empty_hashes: (#hsz:pos) -> (len:nat) -> GTot (hs:hashess #hsz {S.length hs = len}) let empty_hashes #hsz len = S.create len S.empty val empty_hashes_head: #hsz:pos -> len:nat{len > 0} -> Lemma (S.head (empty_hashes #hsz len) == S.empty) let empty_hashes_head #_ _ = () val empty_hashes_tail: #hsz:pos -> len:nat{len > 0} -> Lemma (S.equal (S.tail (empty_hashes len)) (empty_hashes #hsz (len - 1))) let empty_hashes_tail #_ _ = () #push-options "--max_fuel 1" val mt_hashes_lth_inv: #hsz:pos -> lv:nat{lv <= 32} -> j:nat{j < pow2 (32 - lv)} -> fhs:hashess #hsz {S.length fhs = 32} -> GTot Type0 (decreases (32 - lv)) let rec mt_hashes_lth_inv #hsz lv j fhs = if lv = 32 then true else (S.length (S.index fhs lv) == j /\ mt_hashes_lth_inv (lv + 1) (j / 2) fhs) val mt_hashes_lth_inv_empty: #hsz:pos -> lv:nat{lv <= 32} -> Lemma (requires True) (ensures mt_hashes_lth_inv lv 0 (empty_hashes #hsz 32)) (decreases (32 - lv)) let rec mt_hashes_lth_inv_empty #hsz lv = if lv = 32 then () else mt_hashes_lth_inv_empty #hsz (lv + 1) val mt_hashes_next_rel: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> j:nat -> hs:hashes #hsz {S.length hs = j} -> nhs:hashes #hsz {S.length nhs = j / 2} -> GTot Type0 let mt_hashes_next_rel #hsz #f j hs nhs = forall (i:nat{i < j / 2}). S.index nhs i == f (S.index hs (op_Multiply 2 i)) (S.index hs (op_Multiply 2 i + 1)) #pop-options #push-options "--max_fuel 2" val mt_hashes_inv: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> lv:nat{lv < 32} -> j:nat{j < pow2 (32 - lv)} -> fhs:hashess #hsz {S.length fhs = 32 /\ mt_hashes_lth_inv lv j fhs} -> GTot Type0 (decreases (32 - lv)) let rec mt_hashes_inv #hsz #f lv j fhs = if lv = 31 then true else (mt_hashes_next_rel #_ #f j (S.index fhs lv) (S.index fhs (lv + 1)) /\ mt_hashes_inv #_ #f (lv + 1) (j / 2) fhs) val mt_hashes_inv_empty: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> lv:nat{lv < 32} -> Lemma (requires True) (ensures (mt_hashes_lth_inv_empty #hsz lv; mt_hashes_inv #hsz #f lv 0 (empty_hashes #hsz 32))) (decreases (32 - lv)) let rec mt_hashes_inv_empty #hsz #f lv = if lv = 31 then () else (mt_hashes_lth_inv_empty #hsz (lv + 1); mt_hashes_inv_empty #_ #f (lv + 1)) val mt_hashes_lth_inv_equiv: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> lv:nat{lv < 32} -> j:nat{j < pow2 (32 - lv)} -> fhs1:hashess{S.length fhs1 = 32} -> fhs2:hashess{S.length fhs2 = 32} -> Lemma (requires mt_hashes_lth_inv lv j fhs1 /\ S.equal (S.slice fhs1 lv 32) (S.slice fhs2 lv 32)) (ensures mt_hashes_lth_inv #hsz lv j fhs2) (decreases (32 - lv)) let rec mt_hashes_lth_inv_equiv #hsz #f lv j fhs1 fhs2 = if lv = 31 then () else (assert (S.index fhs1 lv == S.index fhs2 lv); mt_hashes_lth_inv_equiv #_ #f (lv + 1) (j / 2) fhs1 fhs2) #pop-options #push-options "--max_fuel 1" val mt_hashes_inv_equiv: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> lv:nat{lv < 32} -> j:nat{j < pow2 (32 - lv)} -> fhs1:hashess #hsz {S.length fhs1 = 32 /\ mt_hashes_lth_inv lv j fhs1} -> fhs2:hashess #hsz {S.length fhs2 = 32 /\ mt_hashes_lth_inv lv j fhs2} -> Lemma (requires mt_hashes_inv #_ #f lv j fhs1 /\ S.equal (S.slice fhs1 lv 32) (S.slice fhs2 lv 32)) (ensures mt_hashes_inv #_ #f lv j fhs2) (decreases (32 - lv)) let rec mt_hashes_inv_equiv #hsz #f lv j fhs1 fhs2 = if lv = 31 then () else (assert (S.index fhs1 lv == S.index fhs2 lv); assert (S.index fhs1 (lv + 1) == S.index fhs2 (lv + 1)); mt_hashes_inv_equiv #_ #f (lv + 1) (j / 2) fhs1 fhs2) val merge_hs: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> hs1:hashess #hsz -> hs2:hashess #hsz {S.length hs1 = S.length hs2} -> GTot (mhs:hashess #hsz {S.length mhs = S.length hs1}) (decreases (S.length hs1)) let rec merge_hs #hsz #f hs1 hs2 = if S.length hs1 = 0 then S.empty else (S.cons (S.append (S.head hs1) (S.head hs2)) (merge_hs #_ #f (S.tail hs1) (S.tail hs2))) val merge_hs_empty: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> len:nat -> Lemma (S.equal (merge_hs #_ #f (empty_hashes #hsz len) (empty_hashes #hsz len)) (empty_hashes #hsz len)) let rec merge_hs_empty #hsz #f len = if len = 0 then () else (empty_hashes_head #hsz len; empty_hashes_tail #hsz len; assert (S.equal (S.append #(hash #hsz) S.empty S.empty) (S.empty #(hash #hsz))); assert (S.equal (merge_hs #_ #f (empty_hashes len) (empty_hashes len)) (S.cons S.empty (merge_hs #_ #f (empty_hashes (len - 1)) (empty_hashes (len - 1))))); merge_hs_empty #_ #f (len - 1)) val merge_hs_index: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> hs1:hashess -> hs2:hashess{S.length hs1 = S.length hs2} -> i:nat{i < S.length hs1} -> Lemma (requires True) (ensures S.equal (S.index (merge_hs #_ #f hs1 hs2) i) (S.append (S.index hs1 i) (S.index hs2 i))) (decreases (S.length hs1)) [SMTPat (S.index (merge_hs #_ #f hs1 hs2) i)] let rec merge_hs_index #hsz #f hs1 hs2 i = if S.length hs1 = 0 then () else if i = 0 then () else merge_hs_index #_ #f (S.tail hs1) (S.tail hs2) (i - 1) val merge_hs_slice_equal: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> ahs1:hashess #hsz -> ahs2:hashess #hsz {S.length ahs1 = S.length ahs2} -> bhs1:hashess #hsz -> bhs2:hashess #hsz {S.length bhs1 = S.length bhs2} -> i:nat -> j:nat{i <= j && j <= S.length ahs1 && j <= S.length bhs1} -> Lemma (requires S.equal (S.slice ahs1 i j) (S.slice bhs1 i j) /\ S.equal (S.slice ahs2 i j) (S.slice bhs2 i j)) (ensures S.equal (S.slice (merge_hs #_ #f ahs1 ahs2) i j) (S.slice (merge_hs #_ #f bhs1 bhs2) i j)) (decreases (j - i)) let rec merge_hs_slice_equal #_ #f ahs1 ahs2 bhs1 bhs2 i j = if i = j then () else (assert (S.index ahs1 i == S.index bhs1 i); assert (S.index ahs2 i == S.index bhs2 i); merge_hs_slice_equal #_ #f ahs1 ahs2 bhs1 bhs2 (i + 1) j) val merge_hs_upd: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> hs1:hashess #hsz -> hs2:hashess #hsz {S.length hs1 = S.length hs2} -> i:nat{i < S.length hs1} -> v1:hashes #hsz -> v2:hashes #hsz -> Lemma (requires S.equal (S.append (S.index hs1 i) (S.index hs2 i)) (S.append v1 v2)) (ensures S.equal (merge_hs #_ #f hs1 hs2) (merge_hs #_ #f (S.upd hs1 i v1) (S.upd hs2 i v2))) (decreases i) let rec merge_hs_upd #_ #f hs1 hs2 i v1 v2 = if S.length hs1 = 0 then () else if i = 0 then () else merge_hs_upd #_ #f (S.tail hs1) (S.tail hs2) (i - 1) v1 v2 val mt_olds_inv: #hsz:pos -> lv:nat{lv <= 32} -> i:nat -> olds:hashess #hsz {S.length olds = 32} -> GTot Type0 (decreases (32 - lv)) let rec mt_olds_inv #hsz lv i olds = if lv = 32 then true else (let ofs = offset_of i in S.length (S.index olds lv) == ofs /\ mt_olds_inv #hsz (lv + 1) (i / 2) olds) val mt_olds_inv_equiv: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> lv:nat{lv <= 32} -> i:nat -> olds1:hashess #hsz {S.length olds1 = 32} -> olds2:hashess #hsz {S.length olds2 = 32} -> Lemma (requires mt_olds_inv #hsz lv i olds1 /\ S.equal (S.slice olds1 lv 32) (S.slice olds2 lv 32)) (ensures mt_olds_inv #hsz lv i olds2) (decreases (32 - lv)) let rec mt_olds_inv_equiv #hsz #f lv i olds1 olds2 = if lv = 32 then () else (assert (S.index olds1 lv == S.index olds2 lv); mt_olds_inv_equiv #_ #f (lv + 1) (i / 2) olds1 olds2) val mt_olds_hs_lth_inv_ok: #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 #hsz lv hs i j} -> Lemma (requires True) (ensures mt_hashes_lth_inv #hsz lv j (merge_hs #_ #f olds hs)) (decreases (32 - lv)) let rec mt_olds_hs_lth_inv_ok #hsz #f lv i j olds hs = if lv = 32 then () else (mt_olds_hs_lth_inv_ok #_ #f (lv + 1) (i / 2) (j / 2) olds hs) val mt_olds_hs_inv: #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 #hsz lv hs i j} -> GTot Type0 let mt_olds_hs_inv #hsz #f lv i j olds hs = mt_olds_hs_lth_inv_ok #_ #f lv i j olds hs; mt_hashes_inv #_ #f lv j (merge_hs #_ #f olds hs) // Relation between valid internal hashes (satisfying `mt_olds_hs_inv`) and // the spec. While giving such relation, all rightmost hashes are recovered. // Note that `MT?.rhs` after `construct_rhs` does NOT contain all rightmost // hashes; it has partial rightmost hashes that are enough to calculate // Merkle paths. val log2: n:nat{n > 0} -> GTot (c:nat{pow2 c <= n && n < pow2 (c+1)}) let rec log2 n = if n = 1 then 0 else 1 + log2 (n / 2) val log2_bound: n:nat{n > 0} -> c:nat{n < pow2 c} -> Lemma (log2 n <= c-1) let rec log2_bound n c = if n = 1 then () else log2_bound (n / 2) (c - 1) val log2_div: n:nat{n > 1} -> Lemma (log2 (n / 2) = log2 n - 1) let log2_div n = () val log2c: n:nat -> GTot (c:nat{c = 0 || (pow2 (c-1) <= n && n < pow2 c)}) let log2c n = if n = 0 then 0 else (log2 n + 1) val log2c_div: n:nat{n > 0} -> Lemma (log2c (n / 2) = log2c n - 1) let log2c_div n = () val log2c_bound: n:nat -> c:nat{n < pow2 c} -> Lemma (log2c n <= c) let rec log2c_bound n c = if n = 0 then () else log2c_bound (n / 2) (c - 1) val mt_hashes_lth_inv_log: #hsz:pos -> j:nat -> fhs:hashess #hsz {S.length fhs = log2c j} -> GTot Type0 (decreases j) let rec mt_hashes_lth_inv_log #hsz j fhs = if j = 0 then true else (S.length (S.head fhs) == j /\ mt_hashes_lth_inv_log #hsz (j / 2) (S.tail fhs)) #pop-options #push-options "--max_fuel 2" val mt_hashes_lth_inv_log_next: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> j:nat{j > 1} -> fhs:hashess #hsz {S.length fhs = log2c j} -> Lemma (requires mt_hashes_lth_inv_log #hsz j fhs) (ensures S.length (S.head fhs) == j /\ S.length (S.head (S.tail fhs)) == j / 2) let mt_hashes_lth_inv_log_next #_ #_ _ _ = () val mt_hashes_inv_log: #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} -> GTot Type0 (decreases j) let rec mt_hashes_inv_log #hsz #f j fhs = if j <= 1 then true else (mt_hashes_next_rel #_ #f j (S.index fhs 0) (S.index fhs 1) /\ mt_hashes_inv_log #_ #f (j / 2) (S.tail fhs)) val mt_hashes_lth_inv_log_converted_: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> lv:nat{lv <= 32} -> j:nat{j < pow2 (32 - lv)} -> fhs:hashess #hsz {S.length fhs = 32} -> Lemma (requires mt_hashes_lth_inv #hsz lv j fhs) (ensures (log2c_bound j (32 - lv); mt_hashes_lth_inv_log #hsz j (S.slice fhs lv (lv + log2c j)))) (decreases j) let rec mt_hashes_lth_inv_log_converted_ #_ #f lv j fhs = if j = 0 then () else (log2c_bound (j / 2) (32 - (lv + 1)); mt_hashes_lth_inv_log_converted_ #_ #f (lv + 1) (j / 2) fhs) val mt_hashes_lth_inv_log_converted: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> j:nat{j < pow2 32} -> fhs:hashess #hsz {S.length fhs = 32} -> Lemma (requires mt_hashes_lth_inv #hsz 0 j fhs) (ensures (log2c_bound j 32; mt_hashes_lth_inv_log #hsz j (S.slice fhs 0 (log2c j)))) let mt_hashes_lth_inv_log_converted #_ #f j fhs = mt_hashes_lth_inv_log_converted_ #_ #f 0 j fhs val mt_hashes_inv_log_converted_: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> lv:nat{lv <= 32} -> j:nat{j > 0 && j < pow2 (32 - lv)} -> fhs:hashess #hsz {S.length fhs = 32 /\ mt_hashes_lth_inv #hsz lv j fhs} -> Lemma (requires mt_hashes_inv #_ #f lv j fhs) (ensures (log2c_bound j (32 - lv); mt_hashes_lth_inv_log_converted_ #_ #f lv j fhs; mt_hashes_inv_log #_ #f j (S.slice fhs lv (lv + log2c j)))) (decreases j) #pop-options #push-options "--z3rlimit 100 --initial_fuel 2 --max_fuel 2" let rec mt_hashes_inv_log_converted_ #_ #f lv j fhs = if j = 1 then () else (log2c_bound (j / 2) (32 - (lv + 1)); mt_hashes_lth_inv_log_converted_ #_ #f (lv + 1) (j / 2) fhs; mt_hashes_inv_log_converted_ #_ #f (lv + 1) (j / 2) fhs) #pop-options val mt_hashes_inv_log_converted: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> j:nat{j > 0 && j < pow2 32} -> fhs:hashess #hsz {S.length fhs = 32 /\ mt_hashes_lth_inv #hsz 0 j fhs} -> Lemma (requires mt_hashes_inv #_ #f 0 j fhs) (ensures (log2c_bound j 32; mt_hashes_lth_inv_log_converted_ #_ #f 0 j fhs; mt_hashes_inv_log #_ #f j (S.slice fhs 0 (log2c j)))) let mt_hashes_inv_log_converted #_ #f j fhs = mt_hashes_inv_log_converted_ #_ #f 0 j fhs val hash_seq_lift: #hsz:pos -> hs:hashes #hsz -> GTot (shs:MTS.hashes #hsz {S.length shs = S.length hs}) (decreases (S.length hs)) let rec hash_seq_lift #hsz hs = if S.length hs = 0 then S.empty else S.cons (MTS.HRaw (S.head hs)) (hash_seq_lift #hsz (S.tail hs)) #push-options "--z3rlimit 50 --initial_fuel 2 --max_fuel 2" val hash_seq_lift_index: #hsz:pos -> hs:hashes #hsz -> Lemma (requires True) (ensures forall (i:nat{i < S.length hs}). S.index (hash_seq_lift #hsz hs) i == MTS.HRaw (S.index hs i)) (decreases (S.length hs)) let rec hash_seq_lift_index #hsz hs = if S.length hs = 0 then () else hash_seq_lift_index #hsz (S.tail hs) #pop-options val create_pads: #hsz:pos -> len:nat -> GTot (pads:MTS.hashes #hsz {S.length pads = len}) let create_pads #hsz len = S.create len (MTS.HPad #hsz) val hash_seq_spec: #hsz:pos -> hs:hashes #hsz {S.length hs > 0} -> GTot (MTS.merkle_tree #hsz (log2c (S.length hs))) let hash_seq_spec #hsz hs = S.append (hash_seq_lift #hsz hs) (create_pads (pow2 (log2c (S.length hs)) - S.length hs)) val hash_seq_spec_index_raw: #hsz:pos -> hs:hashes #hsz {S.length hs > 0} -> i:nat{i < S.length hs} -> Lemma (S.index (hash_seq_spec #hsz hs) i == MTS.HRaw #hsz (S.index hs i)) let hash_seq_spec_index_raw #hsz hs i = hash_seq_lift_index #hsz hs // Now about recovering rightmost hashes #push-options "--z3rlimit 50 --initial_fuel 1 --max_fuel 1" val mt_hashes_next_rel_lift_even: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> j:nat{j > 1} -> hs:hashes #hsz {S.length hs = j} -> nhs:hashes #hsz {S.length nhs = j / 2} -> Lemma (requires j % 2 = 0 /\ mt_hashes_next_rel #_ #f j hs nhs) (ensures MTS.mt_next_rel #_ #f (log2c j) (hash_seq_spec #hsz hs) (hash_seq_spec #hsz nhs)) let mt_hashes_next_rel_lift_even #hsz #_ j hs nhs = hash_seq_lift_index #hsz hs; hash_seq_lift_index #hsz nhs val mt_hashes_next_rel_lift_odd: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> j:nat{j > 1} -> hs:hashes #hsz {S.length hs = j} -> nhs:hashes #hsz {S.length nhs = j / 2} -> Lemma (requires j % 2 = 1 /\ mt_hashes_next_rel #_ #f j hs nhs) (ensures MTS.mt_next_rel #_ #f (log2c j) (hash_seq_spec #hsz hs) (S.upd (hash_seq_spec #hsz nhs) (S.length nhs) (MTS.HRaw (S.last hs)))) let mt_hashes_next_rel_lift_odd #hsz #_ j hs nhs = log2c_div j; hash_seq_lift_index #hsz hs; hash_seq_lift_index #hsz nhs val mt_hashes_next_rel_next_even: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> j:nat{j > 1} -> hs:hashes #hsz {S.length hs = j} -> nhs:hashes #hsz {S.length nhs = j / 2} -> Lemma (requires j % 2 = 0 /\ mt_hashes_next_rel #_ #f j hs nhs) (ensures S.equal (hash_seq_spec #hsz nhs) (MTS.mt_next_lv #_ #f #(log2c j) (hash_seq_spec #hsz hs))) let mt_hashes_next_rel_next_even #hsz #f j hs nhs = log2c_div j; mt_hashes_next_rel_lift_even #_ #f j hs nhs; MTS.mt_next_rel_next_lv #_ #f (log2c j) (hash_seq_spec #hsz hs) (hash_seq_spec #hsz nhs) val hash_seq_spec_full: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> hs:hashes #hsz {S.length hs > 0} -> acc:hash #hsz -> actd:bool ->
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "MerkleTree.Spec.fst.checked", "MerkleTree.New.High.fst.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Ghost.fsti.checked", "FStar.Classical.fsti.checked" ], "interface_file": false, "source_file": "MerkleTree.New.High.Correct.Base.fst" }
[ { "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": 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": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
hs: MerkleTree.New.High.hashes{FStar.Seq.Base.length hs > 0} -> acc: MerkleTree.New.High.hash -> actd: Prims.bool -> Prims.GTot (MerkleTree.Spec.merkle_tree (MerkleTree.New.High.Correct.Base.log2c (FStar.Seq.Base.length hs)) )
Prims.GTot
[ "sometrivial" ]
[]
[ "Prims.pos", "MerkleTree.Spec.hash_fun_t", "MerkleTree.New.High.hashes", "Prims.b2t", "Prims.op_GreaterThan", "FStar.Seq.Base.length", "MerkleTree.New.High.hash", "Prims.bool", "FStar.Seq.Base.upd", "MerkleTree.Spec.padded_hash", "MerkleTree.New.High.Correct.Base.hash_seq_spec", "MerkleTree.Spec.HRaw", "MerkleTree.Spec.merkle_tree", "MerkleTree.New.High.Correct.Base.log2c" ]
[]
false
false
false
false
false
let hash_seq_spec_full #hsz #f hs acc actd =
if actd then (S.upd (hash_seq_spec #hsz hs) (S.length hs) (MTS.HRaw acc)) else hash_seq_spec #hsz hs
false
MerkleTree.New.High.Correct.Base.fst
MerkleTree.New.High.Correct.Base.hash_seq_spec_index_raw
val hash_seq_spec_index_raw: #hsz:pos -> hs:hashes #hsz {S.length hs > 0} -> i:nat{i < S.length hs} -> Lemma (S.index (hash_seq_spec #hsz hs) i == MTS.HRaw #hsz (S.index hs i))
val hash_seq_spec_index_raw: #hsz:pos -> hs:hashes #hsz {S.length hs > 0} -> i:nat{i < S.length hs} -> Lemma (S.index (hash_seq_spec #hsz hs) i == MTS.HRaw #hsz (S.index hs i))
let hash_seq_spec_index_raw #hsz hs i = hash_seq_lift_index #hsz hs
{ "file_name": "src/MerkleTree.New.High.Correct.Base.fst", "git_rev": "7d7bdc20f2033171e279c176b26e84f9069d23c6", "git_url": "https://github.com/hacl-star/merkle-tree.git", "project_name": "merkle-tree" }
{ "end_col": 29, "end_line": 443, "start_col": 0, "start_line": 442 }
module MerkleTree.New.High.Correct.Base open FStar.Classical open FStar.Ghost open FStar.Seq module S = FStar.Seq module MTS = MerkleTree.Spec open MerkleTree.New.High #set-options "--z3rlimit 40 --max_fuel 0 --max_ifuel 0" /// Sequence helpers val seq_prefix: #a:Type -> s1:S.seq a -> s2:S.seq a{S.length s1 <= S.length s2} -> GTot Type0 let seq_prefix #a s1 s2 = S.equal s1 (S.slice s2 0 (S.length s1)) val seq_head_cons: #a:Type -> x:a -> s:S.seq a -> Lemma (S.head (S.cons x s) == x) [SMTPat (S.cons x s)] let seq_head_cons #a x s = () val seq_tail_cons: #a:Type -> x:a -> s:S.seq a -> Lemma (S.equal (S.tail (S.cons x s)) s) [SMTPat (S.cons x s)] let seq_tail_cons #a x s = () /// Invariants and simulation relation of high-level Merkle tree design // Invariants of internal hashes val empty_hashes: (#hsz:pos) -> (len:nat) -> GTot (hs:hashess #hsz {S.length hs = len}) let empty_hashes #hsz len = S.create len S.empty val empty_hashes_head: #hsz:pos -> len:nat{len > 0} -> Lemma (S.head (empty_hashes #hsz len) == S.empty) let empty_hashes_head #_ _ = () val empty_hashes_tail: #hsz:pos -> len:nat{len > 0} -> Lemma (S.equal (S.tail (empty_hashes len)) (empty_hashes #hsz (len - 1))) let empty_hashes_tail #_ _ = () #push-options "--max_fuel 1" val mt_hashes_lth_inv: #hsz:pos -> lv:nat{lv <= 32} -> j:nat{j < pow2 (32 - lv)} -> fhs:hashess #hsz {S.length fhs = 32} -> GTot Type0 (decreases (32 - lv)) let rec mt_hashes_lth_inv #hsz lv j fhs = if lv = 32 then true else (S.length (S.index fhs lv) == j /\ mt_hashes_lth_inv (lv + 1) (j / 2) fhs) val mt_hashes_lth_inv_empty: #hsz:pos -> lv:nat{lv <= 32} -> Lemma (requires True) (ensures mt_hashes_lth_inv lv 0 (empty_hashes #hsz 32)) (decreases (32 - lv)) let rec mt_hashes_lth_inv_empty #hsz lv = if lv = 32 then () else mt_hashes_lth_inv_empty #hsz (lv + 1) val mt_hashes_next_rel: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> j:nat -> hs:hashes #hsz {S.length hs = j} -> nhs:hashes #hsz {S.length nhs = j / 2} -> GTot Type0 let mt_hashes_next_rel #hsz #f j hs nhs = forall (i:nat{i < j / 2}). S.index nhs i == f (S.index hs (op_Multiply 2 i)) (S.index hs (op_Multiply 2 i + 1)) #pop-options #push-options "--max_fuel 2" val mt_hashes_inv: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> lv:nat{lv < 32} -> j:nat{j < pow2 (32 - lv)} -> fhs:hashess #hsz {S.length fhs = 32 /\ mt_hashes_lth_inv lv j fhs} -> GTot Type0 (decreases (32 - lv)) let rec mt_hashes_inv #hsz #f lv j fhs = if lv = 31 then true else (mt_hashes_next_rel #_ #f j (S.index fhs lv) (S.index fhs (lv + 1)) /\ mt_hashes_inv #_ #f (lv + 1) (j / 2) fhs) val mt_hashes_inv_empty: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> lv:nat{lv < 32} -> Lemma (requires True) (ensures (mt_hashes_lth_inv_empty #hsz lv; mt_hashes_inv #hsz #f lv 0 (empty_hashes #hsz 32))) (decreases (32 - lv)) let rec mt_hashes_inv_empty #hsz #f lv = if lv = 31 then () else (mt_hashes_lth_inv_empty #hsz (lv + 1); mt_hashes_inv_empty #_ #f (lv + 1)) val mt_hashes_lth_inv_equiv: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> lv:nat{lv < 32} -> j:nat{j < pow2 (32 - lv)} -> fhs1:hashess{S.length fhs1 = 32} -> fhs2:hashess{S.length fhs2 = 32} -> Lemma (requires mt_hashes_lth_inv lv j fhs1 /\ S.equal (S.slice fhs1 lv 32) (S.slice fhs2 lv 32)) (ensures mt_hashes_lth_inv #hsz lv j fhs2) (decreases (32 - lv)) let rec mt_hashes_lth_inv_equiv #hsz #f lv j fhs1 fhs2 = if lv = 31 then () else (assert (S.index fhs1 lv == S.index fhs2 lv); mt_hashes_lth_inv_equiv #_ #f (lv + 1) (j / 2) fhs1 fhs2) #pop-options #push-options "--max_fuel 1" val mt_hashes_inv_equiv: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> lv:nat{lv < 32} -> j:nat{j < pow2 (32 - lv)} -> fhs1:hashess #hsz {S.length fhs1 = 32 /\ mt_hashes_lth_inv lv j fhs1} -> fhs2:hashess #hsz {S.length fhs2 = 32 /\ mt_hashes_lth_inv lv j fhs2} -> Lemma (requires mt_hashes_inv #_ #f lv j fhs1 /\ S.equal (S.slice fhs1 lv 32) (S.slice fhs2 lv 32)) (ensures mt_hashes_inv #_ #f lv j fhs2) (decreases (32 - lv)) let rec mt_hashes_inv_equiv #hsz #f lv j fhs1 fhs2 = if lv = 31 then () else (assert (S.index fhs1 lv == S.index fhs2 lv); assert (S.index fhs1 (lv + 1) == S.index fhs2 (lv + 1)); mt_hashes_inv_equiv #_ #f (lv + 1) (j / 2) fhs1 fhs2) val merge_hs: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> hs1:hashess #hsz -> hs2:hashess #hsz {S.length hs1 = S.length hs2} -> GTot (mhs:hashess #hsz {S.length mhs = S.length hs1}) (decreases (S.length hs1)) let rec merge_hs #hsz #f hs1 hs2 = if S.length hs1 = 0 then S.empty else (S.cons (S.append (S.head hs1) (S.head hs2)) (merge_hs #_ #f (S.tail hs1) (S.tail hs2))) val merge_hs_empty: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> len:nat -> Lemma (S.equal (merge_hs #_ #f (empty_hashes #hsz len) (empty_hashes #hsz len)) (empty_hashes #hsz len)) let rec merge_hs_empty #hsz #f len = if len = 0 then () else (empty_hashes_head #hsz len; empty_hashes_tail #hsz len; assert (S.equal (S.append #(hash #hsz) S.empty S.empty) (S.empty #(hash #hsz))); assert (S.equal (merge_hs #_ #f (empty_hashes len) (empty_hashes len)) (S.cons S.empty (merge_hs #_ #f (empty_hashes (len - 1)) (empty_hashes (len - 1))))); merge_hs_empty #_ #f (len - 1)) val merge_hs_index: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> hs1:hashess -> hs2:hashess{S.length hs1 = S.length hs2} -> i:nat{i < S.length hs1} -> Lemma (requires True) (ensures S.equal (S.index (merge_hs #_ #f hs1 hs2) i) (S.append (S.index hs1 i) (S.index hs2 i))) (decreases (S.length hs1)) [SMTPat (S.index (merge_hs #_ #f hs1 hs2) i)] let rec merge_hs_index #hsz #f hs1 hs2 i = if S.length hs1 = 0 then () else if i = 0 then () else merge_hs_index #_ #f (S.tail hs1) (S.tail hs2) (i - 1) val merge_hs_slice_equal: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> ahs1:hashess #hsz -> ahs2:hashess #hsz {S.length ahs1 = S.length ahs2} -> bhs1:hashess #hsz -> bhs2:hashess #hsz {S.length bhs1 = S.length bhs2} -> i:nat -> j:nat{i <= j && j <= S.length ahs1 && j <= S.length bhs1} -> Lemma (requires S.equal (S.slice ahs1 i j) (S.slice bhs1 i j) /\ S.equal (S.slice ahs2 i j) (S.slice bhs2 i j)) (ensures S.equal (S.slice (merge_hs #_ #f ahs1 ahs2) i j) (S.slice (merge_hs #_ #f bhs1 bhs2) i j)) (decreases (j - i)) let rec merge_hs_slice_equal #_ #f ahs1 ahs2 bhs1 bhs2 i j = if i = j then () else (assert (S.index ahs1 i == S.index bhs1 i); assert (S.index ahs2 i == S.index bhs2 i); merge_hs_slice_equal #_ #f ahs1 ahs2 bhs1 bhs2 (i + 1) j) val merge_hs_upd: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> hs1:hashess #hsz -> hs2:hashess #hsz {S.length hs1 = S.length hs2} -> i:nat{i < S.length hs1} -> v1:hashes #hsz -> v2:hashes #hsz -> Lemma (requires S.equal (S.append (S.index hs1 i) (S.index hs2 i)) (S.append v1 v2)) (ensures S.equal (merge_hs #_ #f hs1 hs2) (merge_hs #_ #f (S.upd hs1 i v1) (S.upd hs2 i v2))) (decreases i) let rec merge_hs_upd #_ #f hs1 hs2 i v1 v2 = if S.length hs1 = 0 then () else if i = 0 then () else merge_hs_upd #_ #f (S.tail hs1) (S.tail hs2) (i - 1) v1 v2 val mt_olds_inv: #hsz:pos -> lv:nat{lv <= 32} -> i:nat -> olds:hashess #hsz {S.length olds = 32} -> GTot Type0 (decreases (32 - lv)) let rec mt_olds_inv #hsz lv i olds = if lv = 32 then true else (let ofs = offset_of i in S.length (S.index olds lv) == ofs /\ mt_olds_inv #hsz (lv + 1) (i / 2) olds) val mt_olds_inv_equiv: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> lv:nat{lv <= 32} -> i:nat -> olds1:hashess #hsz {S.length olds1 = 32} -> olds2:hashess #hsz {S.length olds2 = 32} -> Lemma (requires mt_olds_inv #hsz lv i olds1 /\ S.equal (S.slice olds1 lv 32) (S.slice olds2 lv 32)) (ensures mt_olds_inv #hsz lv i olds2) (decreases (32 - lv)) let rec mt_olds_inv_equiv #hsz #f lv i olds1 olds2 = if lv = 32 then () else (assert (S.index olds1 lv == S.index olds2 lv); mt_olds_inv_equiv #_ #f (lv + 1) (i / 2) olds1 olds2) val mt_olds_hs_lth_inv_ok: #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 #hsz lv hs i j} -> Lemma (requires True) (ensures mt_hashes_lth_inv #hsz lv j (merge_hs #_ #f olds hs)) (decreases (32 - lv)) let rec mt_olds_hs_lth_inv_ok #hsz #f lv i j olds hs = if lv = 32 then () else (mt_olds_hs_lth_inv_ok #_ #f (lv + 1) (i / 2) (j / 2) olds hs) val mt_olds_hs_inv: #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 #hsz lv hs i j} -> GTot Type0 let mt_olds_hs_inv #hsz #f lv i j olds hs = mt_olds_hs_lth_inv_ok #_ #f lv i j olds hs; mt_hashes_inv #_ #f lv j (merge_hs #_ #f olds hs) // Relation between valid internal hashes (satisfying `mt_olds_hs_inv`) and // the spec. While giving such relation, all rightmost hashes are recovered. // Note that `MT?.rhs` after `construct_rhs` does NOT contain all rightmost // hashes; it has partial rightmost hashes that are enough to calculate // Merkle paths. val log2: n:nat{n > 0} -> GTot (c:nat{pow2 c <= n && n < pow2 (c+1)}) let rec log2 n = if n = 1 then 0 else 1 + log2 (n / 2) val log2_bound: n:nat{n > 0} -> c:nat{n < pow2 c} -> Lemma (log2 n <= c-1) let rec log2_bound n c = if n = 1 then () else log2_bound (n / 2) (c - 1) val log2_div: n:nat{n > 1} -> Lemma (log2 (n / 2) = log2 n - 1) let log2_div n = () val log2c: n:nat -> GTot (c:nat{c = 0 || (pow2 (c-1) <= n && n < pow2 c)}) let log2c n = if n = 0 then 0 else (log2 n + 1) val log2c_div: n:nat{n > 0} -> Lemma (log2c (n / 2) = log2c n - 1) let log2c_div n = () val log2c_bound: n:nat -> c:nat{n < pow2 c} -> Lemma (log2c n <= c) let rec log2c_bound n c = if n = 0 then () else log2c_bound (n / 2) (c - 1) val mt_hashes_lth_inv_log: #hsz:pos -> j:nat -> fhs:hashess #hsz {S.length fhs = log2c j} -> GTot Type0 (decreases j) let rec mt_hashes_lth_inv_log #hsz j fhs = if j = 0 then true else (S.length (S.head fhs) == j /\ mt_hashes_lth_inv_log #hsz (j / 2) (S.tail fhs)) #pop-options #push-options "--max_fuel 2" val mt_hashes_lth_inv_log_next: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> j:nat{j > 1} -> fhs:hashess #hsz {S.length fhs = log2c j} -> Lemma (requires mt_hashes_lth_inv_log #hsz j fhs) (ensures S.length (S.head fhs) == j /\ S.length (S.head (S.tail fhs)) == j / 2) let mt_hashes_lth_inv_log_next #_ #_ _ _ = () val mt_hashes_inv_log: #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} -> GTot Type0 (decreases j) let rec mt_hashes_inv_log #hsz #f j fhs = if j <= 1 then true else (mt_hashes_next_rel #_ #f j (S.index fhs 0) (S.index fhs 1) /\ mt_hashes_inv_log #_ #f (j / 2) (S.tail fhs)) val mt_hashes_lth_inv_log_converted_: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> lv:nat{lv <= 32} -> j:nat{j < pow2 (32 - lv)} -> fhs:hashess #hsz {S.length fhs = 32} -> Lemma (requires mt_hashes_lth_inv #hsz lv j fhs) (ensures (log2c_bound j (32 - lv); mt_hashes_lth_inv_log #hsz j (S.slice fhs lv (lv + log2c j)))) (decreases j) let rec mt_hashes_lth_inv_log_converted_ #_ #f lv j fhs = if j = 0 then () else (log2c_bound (j / 2) (32 - (lv + 1)); mt_hashes_lth_inv_log_converted_ #_ #f (lv + 1) (j / 2) fhs) val mt_hashes_lth_inv_log_converted: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> j:nat{j < pow2 32} -> fhs:hashess #hsz {S.length fhs = 32} -> Lemma (requires mt_hashes_lth_inv #hsz 0 j fhs) (ensures (log2c_bound j 32; mt_hashes_lth_inv_log #hsz j (S.slice fhs 0 (log2c j)))) let mt_hashes_lth_inv_log_converted #_ #f j fhs = mt_hashes_lth_inv_log_converted_ #_ #f 0 j fhs val mt_hashes_inv_log_converted_: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> lv:nat{lv <= 32} -> j:nat{j > 0 && j < pow2 (32 - lv)} -> fhs:hashess #hsz {S.length fhs = 32 /\ mt_hashes_lth_inv #hsz lv j fhs} -> Lemma (requires mt_hashes_inv #_ #f lv j fhs) (ensures (log2c_bound j (32 - lv); mt_hashes_lth_inv_log_converted_ #_ #f lv j fhs; mt_hashes_inv_log #_ #f j (S.slice fhs lv (lv + log2c j)))) (decreases j) #pop-options #push-options "--z3rlimit 100 --initial_fuel 2 --max_fuel 2" let rec mt_hashes_inv_log_converted_ #_ #f lv j fhs = if j = 1 then () else (log2c_bound (j / 2) (32 - (lv + 1)); mt_hashes_lth_inv_log_converted_ #_ #f (lv + 1) (j / 2) fhs; mt_hashes_inv_log_converted_ #_ #f (lv + 1) (j / 2) fhs) #pop-options val mt_hashes_inv_log_converted: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> j:nat{j > 0 && j < pow2 32} -> fhs:hashess #hsz {S.length fhs = 32 /\ mt_hashes_lth_inv #hsz 0 j fhs} -> Lemma (requires mt_hashes_inv #_ #f 0 j fhs) (ensures (log2c_bound j 32; mt_hashes_lth_inv_log_converted_ #_ #f 0 j fhs; mt_hashes_inv_log #_ #f j (S.slice fhs 0 (log2c j)))) let mt_hashes_inv_log_converted #_ #f j fhs = mt_hashes_inv_log_converted_ #_ #f 0 j fhs val hash_seq_lift: #hsz:pos -> hs:hashes #hsz -> GTot (shs:MTS.hashes #hsz {S.length shs = S.length hs}) (decreases (S.length hs)) let rec hash_seq_lift #hsz hs = if S.length hs = 0 then S.empty else S.cons (MTS.HRaw (S.head hs)) (hash_seq_lift #hsz (S.tail hs)) #push-options "--z3rlimit 50 --initial_fuel 2 --max_fuel 2" val hash_seq_lift_index: #hsz:pos -> hs:hashes #hsz -> Lemma (requires True) (ensures forall (i:nat{i < S.length hs}). S.index (hash_seq_lift #hsz hs) i == MTS.HRaw (S.index hs i)) (decreases (S.length hs)) let rec hash_seq_lift_index #hsz hs = if S.length hs = 0 then () else hash_seq_lift_index #hsz (S.tail hs) #pop-options val create_pads: #hsz:pos -> len:nat -> GTot (pads:MTS.hashes #hsz {S.length pads = len}) let create_pads #hsz len = S.create len (MTS.HPad #hsz) val hash_seq_spec: #hsz:pos -> hs:hashes #hsz {S.length hs > 0} -> GTot (MTS.merkle_tree #hsz (log2c (S.length hs))) let hash_seq_spec #hsz hs = S.append (hash_seq_lift #hsz hs) (create_pads (pow2 (log2c (S.length hs)) - S.length hs)) val hash_seq_spec_index_raw: #hsz:pos -> hs:hashes #hsz {S.length hs > 0} -> i:nat{i < S.length hs} ->
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "MerkleTree.Spec.fst.checked", "MerkleTree.New.High.fst.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Ghost.fsti.checked", "FStar.Classical.fsti.checked" ], "interface_file": false, "source_file": "MerkleTree.New.High.Correct.Base.fst" }
[ { "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": 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": 40, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
hs: MerkleTree.New.High.hashes{FStar.Seq.Base.length hs > 0} -> i: Prims.nat{i < FStar.Seq.Base.length hs} -> FStar.Pervasives.Lemma (ensures FStar.Seq.Base.index (MerkleTree.New.High.Correct.Base.hash_seq_spec hs) i == MerkleTree.Spec.HRaw (FStar.Seq.Base.index hs i))
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "Prims.pos", "MerkleTree.New.High.hashes", "Prims.b2t", "Prims.op_GreaterThan", "FStar.Seq.Base.length", "MerkleTree.New.High.hash", "Prims.nat", "Prims.op_LessThan", "MerkleTree.New.High.Correct.Base.hash_seq_lift_index", "Prims.unit" ]
[]
true
false
true
false
false
let hash_seq_spec_index_raw #hsz hs i =
hash_seq_lift_index #hsz hs
false
MerkleTree.New.High.Correct.Base.fst
MerkleTree.New.High.Correct.Base.mt_hashes_next_rel_next_even
val mt_hashes_next_rel_next_even: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> j:nat{j > 1} -> hs:hashes #hsz {S.length hs = j} -> nhs:hashes #hsz {S.length nhs = j / 2} -> Lemma (requires j % 2 = 0 /\ mt_hashes_next_rel #_ #f j hs nhs) (ensures S.equal (hash_seq_spec #hsz nhs) (MTS.mt_next_lv #_ #f #(log2c j) (hash_seq_spec #hsz hs)))
val mt_hashes_next_rel_next_even: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> j:nat{j > 1} -> hs:hashes #hsz {S.length hs = j} -> nhs:hashes #hsz {S.length nhs = j / 2} -> Lemma (requires j % 2 = 0 /\ mt_hashes_next_rel #_ #f j hs nhs) (ensures S.equal (hash_seq_spec #hsz nhs) (MTS.mt_next_lv #_ #f #(log2c j) (hash_seq_spec #hsz hs)))
let mt_hashes_next_rel_next_even #hsz #f j hs nhs = log2c_div j; mt_hashes_next_rel_lift_even #_ #f j hs nhs; MTS.mt_next_rel_next_lv #_ #f (log2c j) (hash_seq_spec #hsz hs) (hash_seq_spec #hsz nhs)
{ "file_name": "src/MerkleTree.New.High.Correct.Base.fst", "git_rev": "7d7bdc20f2033171e279c176b26e84f9069d23c6", "git_url": "https://github.com/hacl-star/merkle-tree.git", "project_name": "merkle-tree" }
{ "end_col": 52, "end_line": 487, "start_col": 0, "start_line": 483 }
module MerkleTree.New.High.Correct.Base open FStar.Classical open FStar.Ghost open FStar.Seq module S = FStar.Seq module MTS = MerkleTree.Spec open MerkleTree.New.High #set-options "--z3rlimit 40 --max_fuel 0 --max_ifuel 0" /// Sequence helpers val seq_prefix: #a:Type -> s1:S.seq a -> s2:S.seq a{S.length s1 <= S.length s2} -> GTot Type0 let seq_prefix #a s1 s2 = S.equal s1 (S.slice s2 0 (S.length s1)) val seq_head_cons: #a:Type -> x:a -> s:S.seq a -> Lemma (S.head (S.cons x s) == x) [SMTPat (S.cons x s)] let seq_head_cons #a x s = () val seq_tail_cons: #a:Type -> x:a -> s:S.seq a -> Lemma (S.equal (S.tail (S.cons x s)) s) [SMTPat (S.cons x s)] let seq_tail_cons #a x s = () /// Invariants and simulation relation of high-level Merkle tree design // Invariants of internal hashes val empty_hashes: (#hsz:pos) -> (len:nat) -> GTot (hs:hashess #hsz {S.length hs = len}) let empty_hashes #hsz len = S.create len S.empty val empty_hashes_head: #hsz:pos -> len:nat{len > 0} -> Lemma (S.head (empty_hashes #hsz len) == S.empty) let empty_hashes_head #_ _ = () val empty_hashes_tail: #hsz:pos -> len:nat{len > 0} -> Lemma (S.equal (S.tail (empty_hashes len)) (empty_hashes #hsz (len - 1))) let empty_hashes_tail #_ _ = () #push-options "--max_fuel 1" val mt_hashes_lth_inv: #hsz:pos -> lv:nat{lv <= 32} -> j:nat{j < pow2 (32 - lv)} -> fhs:hashess #hsz {S.length fhs = 32} -> GTot Type0 (decreases (32 - lv)) let rec mt_hashes_lth_inv #hsz lv j fhs = if lv = 32 then true else (S.length (S.index fhs lv) == j /\ mt_hashes_lth_inv (lv + 1) (j / 2) fhs) val mt_hashes_lth_inv_empty: #hsz:pos -> lv:nat{lv <= 32} -> Lemma (requires True) (ensures mt_hashes_lth_inv lv 0 (empty_hashes #hsz 32)) (decreases (32 - lv)) let rec mt_hashes_lth_inv_empty #hsz lv = if lv = 32 then () else mt_hashes_lth_inv_empty #hsz (lv + 1) val mt_hashes_next_rel: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> j:nat -> hs:hashes #hsz {S.length hs = j} -> nhs:hashes #hsz {S.length nhs = j / 2} -> GTot Type0 let mt_hashes_next_rel #hsz #f j hs nhs = forall (i:nat{i < j / 2}). S.index nhs i == f (S.index hs (op_Multiply 2 i)) (S.index hs (op_Multiply 2 i + 1)) #pop-options #push-options "--max_fuel 2" val mt_hashes_inv: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> lv:nat{lv < 32} -> j:nat{j < pow2 (32 - lv)} -> fhs:hashess #hsz {S.length fhs = 32 /\ mt_hashes_lth_inv lv j fhs} -> GTot Type0 (decreases (32 - lv)) let rec mt_hashes_inv #hsz #f lv j fhs = if lv = 31 then true else (mt_hashes_next_rel #_ #f j (S.index fhs lv) (S.index fhs (lv + 1)) /\ mt_hashes_inv #_ #f (lv + 1) (j / 2) fhs) val mt_hashes_inv_empty: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> lv:nat{lv < 32} -> Lemma (requires True) (ensures (mt_hashes_lth_inv_empty #hsz lv; mt_hashes_inv #hsz #f lv 0 (empty_hashes #hsz 32))) (decreases (32 - lv)) let rec mt_hashes_inv_empty #hsz #f lv = if lv = 31 then () else (mt_hashes_lth_inv_empty #hsz (lv + 1); mt_hashes_inv_empty #_ #f (lv + 1)) val mt_hashes_lth_inv_equiv: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> lv:nat{lv < 32} -> j:nat{j < pow2 (32 - lv)} -> fhs1:hashess{S.length fhs1 = 32} -> fhs2:hashess{S.length fhs2 = 32} -> Lemma (requires mt_hashes_lth_inv lv j fhs1 /\ S.equal (S.slice fhs1 lv 32) (S.slice fhs2 lv 32)) (ensures mt_hashes_lth_inv #hsz lv j fhs2) (decreases (32 - lv)) let rec mt_hashes_lth_inv_equiv #hsz #f lv j fhs1 fhs2 = if lv = 31 then () else (assert (S.index fhs1 lv == S.index fhs2 lv); mt_hashes_lth_inv_equiv #_ #f (lv + 1) (j / 2) fhs1 fhs2) #pop-options #push-options "--max_fuel 1" val mt_hashes_inv_equiv: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> lv:nat{lv < 32} -> j:nat{j < pow2 (32 - lv)} -> fhs1:hashess #hsz {S.length fhs1 = 32 /\ mt_hashes_lth_inv lv j fhs1} -> fhs2:hashess #hsz {S.length fhs2 = 32 /\ mt_hashes_lth_inv lv j fhs2} -> Lemma (requires mt_hashes_inv #_ #f lv j fhs1 /\ S.equal (S.slice fhs1 lv 32) (S.slice fhs2 lv 32)) (ensures mt_hashes_inv #_ #f lv j fhs2) (decreases (32 - lv)) let rec mt_hashes_inv_equiv #hsz #f lv j fhs1 fhs2 = if lv = 31 then () else (assert (S.index fhs1 lv == S.index fhs2 lv); assert (S.index fhs1 (lv + 1) == S.index fhs2 (lv + 1)); mt_hashes_inv_equiv #_ #f (lv + 1) (j / 2) fhs1 fhs2) val merge_hs: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> hs1:hashess #hsz -> hs2:hashess #hsz {S.length hs1 = S.length hs2} -> GTot (mhs:hashess #hsz {S.length mhs = S.length hs1}) (decreases (S.length hs1)) let rec merge_hs #hsz #f hs1 hs2 = if S.length hs1 = 0 then S.empty else (S.cons (S.append (S.head hs1) (S.head hs2)) (merge_hs #_ #f (S.tail hs1) (S.tail hs2))) val merge_hs_empty: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> len:nat -> Lemma (S.equal (merge_hs #_ #f (empty_hashes #hsz len) (empty_hashes #hsz len)) (empty_hashes #hsz len)) let rec merge_hs_empty #hsz #f len = if len = 0 then () else (empty_hashes_head #hsz len; empty_hashes_tail #hsz len; assert (S.equal (S.append #(hash #hsz) S.empty S.empty) (S.empty #(hash #hsz))); assert (S.equal (merge_hs #_ #f (empty_hashes len) (empty_hashes len)) (S.cons S.empty (merge_hs #_ #f (empty_hashes (len - 1)) (empty_hashes (len - 1))))); merge_hs_empty #_ #f (len - 1)) val merge_hs_index: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> hs1:hashess -> hs2:hashess{S.length hs1 = S.length hs2} -> i:nat{i < S.length hs1} -> Lemma (requires True) (ensures S.equal (S.index (merge_hs #_ #f hs1 hs2) i) (S.append (S.index hs1 i) (S.index hs2 i))) (decreases (S.length hs1)) [SMTPat (S.index (merge_hs #_ #f hs1 hs2) i)] let rec merge_hs_index #hsz #f hs1 hs2 i = if S.length hs1 = 0 then () else if i = 0 then () else merge_hs_index #_ #f (S.tail hs1) (S.tail hs2) (i - 1) val merge_hs_slice_equal: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> ahs1:hashess #hsz -> ahs2:hashess #hsz {S.length ahs1 = S.length ahs2} -> bhs1:hashess #hsz -> bhs2:hashess #hsz {S.length bhs1 = S.length bhs2} -> i:nat -> j:nat{i <= j && j <= S.length ahs1 && j <= S.length bhs1} -> Lemma (requires S.equal (S.slice ahs1 i j) (S.slice bhs1 i j) /\ S.equal (S.slice ahs2 i j) (S.slice bhs2 i j)) (ensures S.equal (S.slice (merge_hs #_ #f ahs1 ahs2) i j) (S.slice (merge_hs #_ #f bhs1 bhs2) i j)) (decreases (j - i)) let rec merge_hs_slice_equal #_ #f ahs1 ahs2 bhs1 bhs2 i j = if i = j then () else (assert (S.index ahs1 i == S.index bhs1 i); assert (S.index ahs2 i == S.index bhs2 i); merge_hs_slice_equal #_ #f ahs1 ahs2 bhs1 bhs2 (i + 1) j) val merge_hs_upd: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> hs1:hashess #hsz -> hs2:hashess #hsz {S.length hs1 = S.length hs2} -> i:nat{i < S.length hs1} -> v1:hashes #hsz -> v2:hashes #hsz -> Lemma (requires S.equal (S.append (S.index hs1 i) (S.index hs2 i)) (S.append v1 v2)) (ensures S.equal (merge_hs #_ #f hs1 hs2) (merge_hs #_ #f (S.upd hs1 i v1) (S.upd hs2 i v2))) (decreases i) let rec merge_hs_upd #_ #f hs1 hs2 i v1 v2 = if S.length hs1 = 0 then () else if i = 0 then () else merge_hs_upd #_ #f (S.tail hs1) (S.tail hs2) (i - 1) v1 v2 val mt_olds_inv: #hsz:pos -> lv:nat{lv <= 32} -> i:nat -> olds:hashess #hsz {S.length olds = 32} -> GTot Type0 (decreases (32 - lv)) let rec mt_olds_inv #hsz lv i olds = if lv = 32 then true else (let ofs = offset_of i in S.length (S.index olds lv) == ofs /\ mt_olds_inv #hsz (lv + 1) (i / 2) olds) val mt_olds_inv_equiv: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> lv:nat{lv <= 32} -> i:nat -> olds1:hashess #hsz {S.length olds1 = 32} -> olds2:hashess #hsz {S.length olds2 = 32} -> Lemma (requires mt_olds_inv #hsz lv i olds1 /\ S.equal (S.slice olds1 lv 32) (S.slice olds2 lv 32)) (ensures mt_olds_inv #hsz lv i olds2) (decreases (32 - lv)) let rec mt_olds_inv_equiv #hsz #f lv i olds1 olds2 = if lv = 32 then () else (assert (S.index olds1 lv == S.index olds2 lv); mt_olds_inv_equiv #_ #f (lv + 1) (i / 2) olds1 olds2) val mt_olds_hs_lth_inv_ok: #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 #hsz lv hs i j} -> Lemma (requires True) (ensures mt_hashes_lth_inv #hsz lv j (merge_hs #_ #f olds hs)) (decreases (32 - lv)) let rec mt_olds_hs_lth_inv_ok #hsz #f lv i j olds hs = if lv = 32 then () else (mt_olds_hs_lth_inv_ok #_ #f (lv + 1) (i / 2) (j / 2) olds hs) val mt_olds_hs_inv: #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 #hsz lv hs i j} -> GTot Type0 let mt_olds_hs_inv #hsz #f lv i j olds hs = mt_olds_hs_lth_inv_ok #_ #f lv i j olds hs; mt_hashes_inv #_ #f lv j (merge_hs #_ #f olds hs) // Relation between valid internal hashes (satisfying `mt_olds_hs_inv`) and // the spec. While giving such relation, all rightmost hashes are recovered. // Note that `MT?.rhs` after `construct_rhs` does NOT contain all rightmost // hashes; it has partial rightmost hashes that are enough to calculate // Merkle paths. val log2: n:nat{n > 0} -> GTot (c:nat{pow2 c <= n && n < pow2 (c+1)}) let rec log2 n = if n = 1 then 0 else 1 + log2 (n / 2) val log2_bound: n:nat{n > 0} -> c:nat{n < pow2 c} -> Lemma (log2 n <= c-1) let rec log2_bound n c = if n = 1 then () else log2_bound (n / 2) (c - 1) val log2_div: n:nat{n > 1} -> Lemma (log2 (n / 2) = log2 n - 1) let log2_div n = () val log2c: n:nat -> GTot (c:nat{c = 0 || (pow2 (c-1) <= n && n < pow2 c)}) let log2c n = if n = 0 then 0 else (log2 n + 1) val log2c_div: n:nat{n > 0} -> Lemma (log2c (n / 2) = log2c n - 1) let log2c_div n = () val log2c_bound: n:nat -> c:nat{n < pow2 c} -> Lemma (log2c n <= c) let rec log2c_bound n c = if n = 0 then () else log2c_bound (n / 2) (c - 1) val mt_hashes_lth_inv_log: #hsz:pos -> j:nat -> fhs:hashess #hsz {S.length fhs = log2c j} -> GTot Type0 (decreases j) let rec mt_hashes_lth_inv_log #hsz j fhs = if j = 0 then true else (S.length (S.head fhs) == j /\ mt_hashes_lth_inv_log #hsz (j / 2) (S.tail fhs)) #pop-options #push-options "--max_fuel 2" val mt_hashes_lth_inv_log_next: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> j:nat{j > 1} -> fhs:hashess #hsz {S.length fhs = log2c j} -> Lemma (requires mt_hashes_lth_inv_log #hsz j fhs) (ensures S.length (S.head fhs) == j /\ S.length (S.head (S.tail fhs)) == j / 2) let mt_hashes_lth_inv_log_next #_ #_ _ _ = () val mt_hashes_inv_log: #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} -> GTot Type0 (decreases j) let rec mt_hashes_inv_log #hsz #f j fhs = if j <= 1 then true else (mt_hashes_next_rel #_ #f j (S.index fhs 0) (S.index fhs 1) /\ mt_hashes_inv_log #_ #f (j / 2) (S.tail fhs)) val mt_hashes_lth_inv_log_converted_: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> lv:nat{lv <= 32} -> j:nat{j < pow2 (32 - lv)} -> fhs:hashess #hsz {S.length fhs = 32} -> Lemma (requires mt_hashes_lth_inv #hsz lv j fhs) (ensures (log2c_bound j (32 - lv); mt_hashes_lth_inv_log #hsz j (S.slice fhs lv (lv + log2c j)))) (decreases j) let rec mt_hashes_lth_inv_log_converted_ #_ #f lv j fhs = if j = 0 then () else (log2c_bound (j / 2) (32 - (lv + 1)); mt_hashes_lth_inv_log_converted_ #_ #f (lv + 1) (j / 2) fhs) val mt_hashes_lth_inv_log_converted: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> j:nat{j < pow2 32} -> fhs:hashess #hsz {S.length fhs = 32} -> Lemma (requires mt_hashes_lth_inv #hsz 0 j fhs) (ensures (log2c_bound j 32; mt_hashes_lth_inv_log #hsz j (S.slice fhs 0 (log2c j)))) let mt_hashes_lth_inv_log_converted #_ #f j fhs = mt_hashes_lth_inv_log_converted_ #_ #f 0 j fhs val mt_hashes_inv_log_converted_: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> lv:nat{lv <= 32} -> j:nat{j > 0 && j < pow2 (32 - lv)} -> fhs:hashess #hsz {S.length fhs = 32 /\ mt_hashes_lth_inv #hsz lv j fhs} -> Lemma (requires mt_hashes_inv #_ #f lv j fhs) (ensures (log2c_bound j (32 - lv); mt_hashes_lth_inv_log_converted_ #_ #f lv j fhs; mt_hashes_inv_log #_ #f j (S.slice fhs lv (lv + log2c j)))) (decreases j) #pop-options #push-options "--z3rlimit 100 --initial_fuel 2 --max_fuel 2" let rec mt_hashes_inv_log_converted_ #_ #f lv j fhs = if j = 1 then () else (log2c_bound (j / 2) (32 - (lv + 1)); mt_hashes_lth_inv_log_converted_ #_ #f (lv + 1) (j / 2) fhs; mt_hashes_inv_log_converted_ #_ #f (lv + 1) (j / 2) fhs) #pop-options val mt_hashes_inv_log_converted: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> j:nat{j > 0 && j < pow2 32} -> fhs:hashess #hsz {S.length fhs = 32 /\ mt_hashes_lth_inv #hsz 0 j fhs} -> Lemma (requires mt_hashes_inv #_ #f 0 j fhs) (ensures (log2c_bound j 32; mt_hashes_lth_inv_log_converted_ #_ #f 0 j fhs; mt_hashes_inv_log #_ #f j (S.slice fhs 0 (log2c j)))) let mt_hashes_inv_log_converted #_ #f j fhs = mt_hashes_inv_log_converted_ #_ #f 0 j fhs val hash_seq_lift: #hsz:pos -> hs:hashes #hsz -> GTot (shs:MTS.hashes #hsz {S.length shs = S.length hs}) (decreases (S.length hs)) let rec hash_seq_lift #hsz hs = if S.length hs = 0 then S.empty else S.cons (MTS.HRaw (S.head hs)) (hash_seq_lift #hsz (S.tail hs)) #push-options "--z3rlimit 50 --initial_fuel 2 --max_fuel 2" val hash_seq_lift_index: #hsz:pos -> hs:hashes #hsz -> Lemma (requires True) (ensures forall (i:nat{i < S.length hs}). S.index (hash_seq_lift #hsz hs) i == MTS.HRaw (S.index hs i)) (decreases (S.length hs)) let rec hash_seq_lift_index #hsz hs = if S.length hs = 0 then () else hash_seq_lift_index #hsz (S.tail hs) #pop-options val create_pads: #hsz:pos -> len:nat -> GTot (pads:MTS.hashes #hsz {S.length pads = len}) let create_pads #hsz len = S.create len (MTS.HPad #hsz) val hash_seq_spec: #hsz:pos -> hs:hashes #hsz {S.length hs > 0} -> GTot (MTS.merkle_tree #hsz (log2c (S.length hs))) let hash_seq_spec #hsz hs = S.append (hash_seq_lift #hsz hs) (create_pads (pow2 (log2c (S.length hs)) - S.length hs)) val hash_seq_spec_index_raw: #hsz:pos -> hs:hashes #hsz {S.length hs > 0} -> i:nat{i < S.length hs} -> Lemma (S.index (hash_seq_spec #hsz hs) i == MTS.HRaw #hsz (S.index hs i)) let hash_seq_spec_index_raw #hsz hs i = hash_seq_lift_index #hsz hs // Now about recovering rightmost hashes #push-options "--z3rlimit 50 --initial_fuel 1 --max_fuel 1" val mt_hashes_next_rel_lift_even: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> j:nat{j > 1} -> hs:hashes #hsz {S.length hs = j} -> nhs:hashes #hsz {S.length nhs = j / 2} -> Lemma (requires j % 2 = 0 /\ mt_hashes_next_rel #_ #f j hs nhs) (ensures MTS.mt_next_rel #_ #f (log2c j) (hash_seq_spec #hsz hs) (hash_seq_spec #hsz nhs)) let mt_hashes_next_rel_lift_even #hsz #_ j hs nhs = hash_seq_lift_index #hsz hs; hash_seq_lift_index #hsz nhs val mt_hashes_next_rel_lift_odd: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> j:nat{j > 1} -> hs:hashes #hsz {S.length hs = j} -> nhs:hashes #hsz {S.length nhs = j / 2} -> Lemma (requires j % 2 = 1 /\ mt_hashes_next_rel #_ #f j hs nhs) (ensures MTS.mt_next_rel #_ #f (log2c j) (hash_seq_spec #hsz hs) (S.upd (hash_seq_spec #hsz nhs) (S.length nhs) (MTS.HRaw (S.last hs)))) let mt_hashes_next_rel_lift_odd #hsz #_ j hs nhs = log2c_div j; hash_seq_lift_index #hsz hs; hash_seq_lift_index #hsz nhs val mt_hashes_next_rel_next_even: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> j:nat{j > 1} -> hs:hashes #hsz {S.length hs = j} -> nhs:hashes #hsz {S.length nhs = j / 2} -> Lemma (requires j % 2 = 0 /\ mt_hashes_next_rel #_ #f j hs nhs) (ensures S.equal (hash_seq_spec #hsz nhs)
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "MerkleTree.Spec.fst.checked", "MerkleTree.New.High.fst.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Ghost.fsti.checked", "FStar.Classical.fsti.checked" ], "interface_file": false, "source_file": "MerkleTree.New.High.Correct.Base.fst" }
[ { "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": 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": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
j: Prims.nat{j > 1} -> hs: MerkleTree.New.High.hashes{FStar.Seq.Base.length hs = j} -> nhs: MerkleTree.New.High.hashes{FStar.Seq.Base.length nhs = j / 2} -> FStar.Pervasives.Lemma (requires j % 2 = 0 /\ MerkleTree.New.High.Correct.Base.mt_hashes_next_rel j hs nhs) (ensures FStar.Seq.Base.equal (MerkleTree.New.High.Correct.Base.hash_seq_spec nhs) (MerkleTree.Spec.mt_next_lv (MerkleTree.New.High.Correct.Base.hash_seq_spec hs)))
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "Prims.pos", "MerkleTree.Spec.hash_fun_t", "Prims.nat", "Prims.b2t", "Prims.op_GreaterThan", "MerkleTree.New.High.hashes", "Prims.op_Equality", "FStar.Seq.Base.length", "MerkleTree.New.High.hash", "Prims.int", "Prims.op_Division", "MerkleTree.Spec.mt_next_rel_next_lv", "MerkleTree.New.High.Correct.Base.log2c", "MerkleTree.New.High.Correct.Base.hash_seq_spec", "Prims.unit", "MerkleTree.New.High.Correct.Base.mt_hashes_next_rel_lift_even", "MerkleTree.New.High.Correct.Base.log2c_div" ]
[]
true
false
true
false
false
let mt_hashes_next_rel_next_even #hsz #f j hs nhs =
log2c_div j; mt_hashes_next_rel_lift_even #_ #f j hs nhs; MTS.mt_next_rel_next_lv #_ #f (log2c j) (hash_seq_spec #hsz hs) (hash_seq_spec #hsz nhs)
false
MerkleTree.New.High.Correct.Base.fst
MerkleTree.New.High.Correct.Base.mt_spec
val mt_spec: #hsz:pos -> mt:merkle_tree #hsz {mt_wf_elts mt /\ MT?.j mt > 0} -> olds:hashess{S.length olds = 32 /\ mt_olds_inv #hsz 0 (MT?.i mt) olds} -> GTot (MTS.merkle_tree #hsz (log2c (MT?.j mt)))
val mt_spec: #hsz:pos -> mt:merkle_tree #hsz {mt_wf_elts mt /\ MT?.j mt > 0} -> olds:hashess{S.length olds = 32 /\ mt_olds_inv #hsz 0 (MT?.i mt) olds} -> GTot (MTS.merkle_tree #hsz (log2c (MT?.j mt)))
let mt_spec #hsz mt olds = hash_seq_spec #_ (mt_base mt olds)
{ "file_name": "src/MerkleTree.New.High.Correct.Base.fst", "git_rev": "7d7bdc20f2033171e279c176b26e84f9069d23c6", "git_url": "https://github.com/hacl-star/merkle-tree.git", "project_name": "merkle-tree" }
{ "end_col": 36, "end_line": 640, "start_col": 0, "start_line": 639 }
module MerkleTree.New.High.Correct.Base open FStar.Classical open FStar.Ghost open FStar.Seq module S = FStar.Seq module MTS = MerkleTree.Spec open MerkleTree.New.High #set-options "--z3rlimit 40 --max_fuel 0 --max_ifuel 0" /// Sequence helpers val seq_prefix: #a:Type -> s1:S.seq a -> s2:S.seq a{S.length s1 <= S.length s2} -> GTot Type0 let seq_prefix #a s1 s2 = S.equal s1 (S.slice s2 0 (S.length s1)) val seq_head_cons: #a:Type -> x:a -> s:S.seq a -> Lemma (S.head (S.cons x s) == x) [SMTPat (S.cons x s)] let seq_head_cons #a x s = () val seq_tail_cons: #a:Type -> x:a -> s:S.seq a -> Lemma (S.equal (S.tail (S.cons x s)) s) [SMTPat (S.cons x s)] let seq_tail_cons #a x s = () /// Invariants and simulation relation of high-level Merkle tree design // Invariants of internal hashes val empty_hashes: (#hsz:pos) -> (len:nat) -> GTot (hs:hashess #hsz {S.length hs = len}) let empty_hashes #hsz len = S.create len S.empty val empty_hashes_head: #hsz:pos -> len:nat{len > 0} -> Lemma (S.head (empty_hashes #hsz len) == S.empty) let empty_hashes_head #_ _ = () val empty_hashes_tail: #hsz:pos -> len:nat{len > 0} -> Lemma (S.equal (S.tail (empty_hashes len)) (empty_hashes #hsz (len - 1))) let empty_hashes_tail #_ _ = () #push-options "--max_fuel 1" val mt_hashes_lth_inv: #hsz:pos -> lv:nat{lv <= 32} -> j:nat{j < pow2 (32 - lv)} -> fhs:hashess #hsz {S.length fhs = 32} -> GTot Type0 (decreases (32 - lv)) let rec mt_hashes_lth_inv #hsz lv j fhs = if lv = 32 then true else (S.length (S.index fhs lv) == j /\ mt_hashes_lth_inv (lv + 1) (j / 2) fhs) val mt_hashes_lth_inv_empty: #hsz:pos -> lv:nat{lv <= 32} -> Lemma (requires True) (ensures mt_hashes_lth_inv lv 0 (empty_hashes #hsz 32)) (decreases (32 - lv)) let rec mt_hashes_lth_inv_empty #hsz lv = if lv = 32 then () else mt_hashes_lth_inv_empty #hsz (lv + 1) val mt_hashes_next_rel: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> j:nat -> hs:hashes #hsz {S.length hs = j} -> nhs:hashes #hsz {S.length nhs = j / 2} -> GTot Type0 let mt_hashes_next_rel #hsz #f j hs nhs = forall (i:nat{i < j / 2}). S.index nhs i == f (S.index hs (op_Multiply 2 i)) (S.index hs (op_Multiply 2 i + 1)) #pop-options #push-options "--max_fuel 2" val mt_hashes_inv: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> lv:nat{lv < 32} -> j:nat{j < pow2 (32 - lv)} -> fhs:hashess #hsz {S.length fhs = 32 /\ mt_hashes_lth_inv lv j fhs} -> GTot Type0 (decreases (32 - lv)) let rec mt_hashes_inv #hsz #f lv j fhs = if lv = 31 then true else (mt_hashes_next_rel #_ #f j (S.index fhs lv) (S.index fhs (lv + 1)) /\ mt_hashes_inv #_ #f (lv + 1) (j / 2) fhs) val mt_hashes_inv_empty: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> lv:nat{lv < 32} -> Lemma (requires True) (ensures (mt_hashes_lth_inv_empty #hsz lv; mt_hashes_inv #hsz #f lv 0 (empty_hashes #hsz 32))) (decreases (32 - lv)) let rec mt_hashes_inv_empty #hsz #f lv = if lv = 31 then () else (mt_hashes_lth_inv_empty #hsz (lv + 1); mt_hashes_inv_empty #_ #f (lv + 1)) val mt_hashes_lth_inv_equiv: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> lv:nat{lv < 32} -> j:nat{j < pow2 (32 - lv)} -> fhs1:hashess{S.length fhs1 = 32} -> fhs2:hashess{S.length fhs2 = 32} -> Lemma (requires mt_hashes_lth_inv lv j fhs1 /\ S.equal (S.slice fhs1 lv 32) (S.slice fhs2 lv 32)) (ensures mt_hashes_lth_inv #hsz lv j fhs2) (decreases (32 - lv)) let rec mt_hashes_lth_inv_equiv #hsz #f lv j fhs1 fhs2 = if lv = 31 then () else (assert (S.index fhs1 lv == S.index fhs2 lv); mt_hashes_lth_inv_equiv #_ #f (lv + 1) (j / 2) fhs1 fhs2) #pop-options #push-options "--max_fuel 1" val mt_hashes_inv_equiv: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> lv:nat{lv < 32} -> j:nat{j < pow2 (32 - lv)} -> fhs1:hashess #hsz {S.length fhs1 = 32 /\ mt_hashes_lth_inv lv j fhs1} -> fhs2:hashess #hsz {S.length fhs2 = 32 /\ mt_hashes_lth_inv lv j fhs2} -> Lemma (requires mt_hashes_inv #_ #f lv j fhs1 /\ S.equal (S.slice fhs1 lv 32) (S.slice fhs2 lv 32)) (ensures mt_hashes_inv #_ #f lv j fhs2) (decreases (32 - lv)) let rec mt_hashes_inv_equiv #hsz #f lv j fhs1 fhs2 = if lv = 31 then () else (assert (S.index fhs1 lv == S.index fhs2 lv); assert (S.index fhs1 (lv + 1) == S.index fhs2 (lv + 1)); mt_hashes_inv_equiv #_ #f (lv + 1) (j / 2) fhs1 fhs2) val merge_hs: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> hs1:hashess #hsz -> hs2:hashess #hsz {S.length hs1 = S.length hs2} -> GTot (mhs:hashess #hsz {S.length mhs = S.length hs1}) (decreases (S.length hs1)) let rec merge_hs #hsz #f hs1 hs2 = if S.length hs1 = 0 then S.empty else (S.cons (S.append (S.head hs1) (S.head hs2)) (merge_hs #_ #f (S.tail hs1) (S.tail hs2))) val merge_hs_empty: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> len:nat -> Lemma (S.equal (merge_hs #_ #f (empty_hashes #hsz len) (empty_hashes #hsz len)) (empty_hashes #hsz len)) let rec merge_hs_empty #hsz #f len = if len = 0 then () else (empty_hashes_head #hsz len; empty_hashes_tail #hsz len; assert (S.equal (S.append #(hash #hsz) S.empty S.empty) (S.empty #(hash #hsz))); assert (S.equal (merge_hs #_ #f (empty_hashes len) (empty_hashes len)) (S.cons S.empty (merge_hs #_ #f (empty_hashes (len - 1)) (empty_hashes (len - 1))))); merge_hs_empty #_ #f (len - 1)) val merge_hs_index: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> hs1:hashess -> hs2:hashess{S.length hs1 = S.length hs2} -> i:nat{i < S.length hs1} -> Lemma (requires True) (ensures S.equal (S.index (merge_hs #_ #f hs1 hs2) i) (S.append (S.index hs1 i) (S.index hs2 i))) (decreases (S.length hs1)) [SMTPat (S.index (merge_hs #_ #f hs1 hs2) i)] let rec merge_hs_index #hsz #f hs1 hs2 i = if S.length hs1 = 0 then () else if i = 0 then () else merge_hs_index #_ #f (S.tail hs1) (S.tail hs2) (i - 1) val merge_hs_slice_equal: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> ahs1:hashess #hsz -> ahs2:hashess #hsz {S.length ahs1 = S.length ahs2} -> bhs1:hashess #hsz -> bhs2:hashess #hsz {S.length bhs1 = S.length bhs2} -> i:nat -> j:nat{i <= j && j <= S.length ahs1 && j <= S.length bhs1} -> Lemma (requires S.equal (S.slice ahs1 i j) (S.slice bhs1 i j) /\ S.equal (S.slice ahs2 i j) (S.slice bhs2 i j)) (ensures S.equal (S.slice (merge_hs #_ #f ahs1 ahs2) i j) (S.slice (merge_hs #_ #f bhs1 bhs2) i j)) (decreases (j - i)) let rec merge_hs_slice_equal #_ #f ahs1 ahs2 bhs1 bhs2 i j = if i = j then () else (assert (S.index ahs1 i == S.index bhs1 i); assert (S.index ahs2 i == S.index bhs2 i); merge_hs_slice_equal #_ #f ahs1 ahs2 bhs1 bhs2 (i + 1) j) val merge_hs_upd: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> hs1:hashess #hsz -> hs2:hashess #hsz {S.length hs1 = S.length hs2} -> i:nat{i < S.length hs1} -> v1:hashes #hsz -> v2:hashes #hsz -> Lemma (requires S.equal (S.append (S.index hs1 i) (S.index hs2 i)) (S.append v1 v2)) (ensures S.equal (merge_hs #_ #f hs1 hs2) (merge_hs #_ #f (S.upd hs1 i v1) (S.upd hs2 i v2))) (decreases i) let rec merge_hs_upd #_ #f hs1 hs2 i v1 v2 = if S.length hs1 = 0 then () else if i = 0 then () else merge_hs_upd #_ #f (S.tail hs1) (S.tail hs2) (i - 1) v1 v2 val mt_olds_inv: #hsz:pos -> lv:nat{lv <= 32} -> i:nat -> olds:hashess #hsz {S.length olds = 32} -> GTot Type0 (decreases (32 - lv)) let rec mt_olds_inv #hsz lv i olds = if lv = 32 then true else (let ofs = offset_of i in S.length (S.index olds lv) == ofs /\ mt_olds_inv #hsz (lv + 1) (i / 2) olds) val mt_olds_inv_equiv: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> lv:nat{lv <= 32} -> i:nat -> olds1:hashess #hsz {S.length olds1 = 32} -> olds2:hashess #hsz {S.length olds2 = 32} -> Lemma (requires mt_olds_inv #hsz lv i olds1 /\ S.equal (S.slice olds1 lv 32) (S.slice olds2 lv 32)) (ensures mt_olds_inv #hsz lv i olds2) (decreases (32 - lv)) let rec mt_olds_inv_equiv #hsz #f lv i olds1 olds2 = if lv = 32 then () else (assert (S.index olds1 lv == S.index olds2 lv); mt_olds_inv_equiv #_ #f (lv + 1) (i / 2) olds1 olds2) val mt_olds_hs_lth_inv_ok: #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 #hsz lv hs i j} -> Lemma (requires True) (ensures mt_hashes_lth_inv #hsz lv j (merge_hs #_ #f olds hs)) (decreases (32 - lv)) let rec mt_olds_hs_lth_inv_ok #hsz #f lv i j olds hs = if lv = 32 then () else (mt_olds_hs_lth_inv_ok #_ #f (lv + 1) (i / 2) (j / 2) olds hs) val mt_olds_hs_inv: #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 #hsz lv hs i j} -> GTot Type0 let mt_olds_hs_inv #hsz #f lv i j olds hs = mt_olds_hs_lth_inv_ok #_ #f lv i j olds hs; mt_hashes_inv #_ #f lv j (merge_hs #_ #f olds hs) // Relation between valid internal hashes (satisfying `mt_olds_hs_inv`) and // the spec. While giving such relation, all rightmost hashes are recovered. // Note that `MT?.rhs` after `construct_rhs` does NOT contain all rightmost // hashes; it has partial rightmost hashes that are enough to calculate // Merkle paths. val log2: n:nat{n > 0} -> GTot (c:nat{pow2 c <= n && n < pow2 (c+1)}) let rec log2 n = if n = 1 then 0 else 1 + log2 (n / 2) val log2_bound: n:nat{n > 0} -> c:nat{n < pow2 c} -> Lemma (log2 n <= c-1) let rec log2_bound n c = if n = 1 then () else log2_bound (n / 2) (c - 1) val log2_div: n:nat{n > 1} -> Lemma (log2 (n / 2) = log2 n - 1) let log2_div n = () val log2c: n:nat -> GTot (c:nat{c = 0 || (pow2 (c-1) <= n && n < pow2 c)}) let log2c n = if n = 0 then 0 else (log2 n + 1) val log2c_div: n:nat{n > 0} -> Lemma (log2c (n / 2) = log2c n - 1) let log2c_div n = () val log2c_bound: n:nat -> c:nat{n < pow2 c} -> Lemma (log2c n <= c) let rec log2c_bound n c = if n = 0 then () else log2c_bound (n / 2) (c - 1) val mt_hashes_lth_inv_log: #hsz:pos -> j:nat -> fhs:hashess #hsz {S.length fhs = log2c j} -> GTot Type0 (decreases j) let rec mt_hashes_lth_inv_log #hsz j fhs = if j = 0 then true else (S.length (S.head fhs) == j /\ mt_hashes_lth_inv_log #hsz (j / 2) (S.tail fhs)) #pop-options #push-options "--max_fuel 2" val mt_hashes_lth_inv_log_next: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> j:nat{j > 1} -> fhs:hashess #hsz {S.length fhs = log2c j} -> Lemma (requires mt_hashes_lth_inv_log #hsz j fhs) (ensures S.length (S.head fhs) == j /\ S.length (S.head (S.tail fhs)) == j / 2) let mt_hashes_lth_inv_log_next #_ #_ _ _ = () val mt_hashes_inv_log: #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} -> GTot Type0 (decreases j) let rec mt_hashes_inv_log #hsz #f j fhs = if j <= 1 then true else (mt_hashes_next_rel #_ #f j (S.index fhs 0) (S.index fhs 1) /\ mt_hashes_inv_log #_ #f (j / 2) (S.tail fhs)) val mt_hashes_lth_inv_log_converted_: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> lv:nat{lv <= 32} -> j:nat{j < pow2 (32 - lv)} -> fhs:hashess #hsz {S.length fhs = 32} -> Lemma (requires mt_hashes_lth_inv #hsz lv j fhs) (ensures (log2c_bound j (32 - lv); mt_hashes_lth_inv_log #hsz j (S.slice fhs lv (lv + log2c j)))) (decreases j) let rec mt_hashes_lth_inv_log_converted_ #_ #f lv j fhs = if j = 0 then () else (log2c_bound (j / 2) (32 - (lv + 1)); mt_hashes_lth_inv_log_converted_ #_ #f (lv + 1) (j / 2) fhs) val mt_hashes_lth_inv_log_converted: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> j:nat{j < pow2 32} -> fhs:hashess #hsz {S.length fhs = 32} -> Lemma (requires mt_hashes_lth_inv #hsz 0 j fhs) (ensures (log2c_bound j 32; mt_hashes_lth_inv_log #hsz j (S.slice fhs 0 (log2c j)))) let mt_hashes_lth_inv_log_converted #_ #f j fhs = mt_hashes_lth_inv_log_converted_ #_ #f 0 j fhs val mt_hashes_inv_log_converted_: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> lv:nat{lv <= 32} -> j:nat{j > 0 && j < pow2 (32 - lv)} -> fhs:hashess #hsz {S.length fhs = 32 /\ mt_hashes_lth_inv #hsz lv j fhs} -> Lemma (requires mt_hashes_inv #_ #f lv j fhs) (ensures (log2c_bound j (32 - lv); mt_hashes_lth_inv_log_converted_ #_ #f lv j fhs; mt_hashes_inv_log #_ #f j (S.slice fhs lv (lv + log2c j)))) (decreases j) #pop-options #push-options "--z3rlimit 100 --initial_fuel 2 --max_fuel 2" let rec mt_hashes_inv_log_converted_ #_ #f lv j fhs = if j = 1 then () else (log2c_bound (j / 2) (32 - (lv + 1)); mt_hashes_lth_inv_log_converted_ #_ #f (lv + 1) (j / 2) fhs; mt_hashes_inv_log_converted_ #_ #f (lv + 1) (j / 2) fhs) #pop-options val mt_hashes_inv_log_converted: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> j:nat{j > 0 && j < pow2 32} -> fhs:hashess #hsz {S.length fhs = 32 /\ mt_hashes_lth_inv #hsz 0 j fhs} -> Lemma (requires mt_hashes_inv #_ #f 0 j fhs) (ensures (log2c_bound j 32; mt_hashes_lth_inv_log_converted_ #_ #f 0 j fhs; mt_hashes_inv_log #_ #f j (S.slice fhs 0 (log2c j)))) let mt_hashes_inv_log_converted #_ #f j fhs = mt_hashes_inv_log_converted_ #_ #f 0 j fhs val hash_seq_lift: #hsz:pos -> hs:hashes #hsz -> GTot (shs:MTS.hashes #hsz {S.length shs = S.length hs}) (decreases (S.length hs)) let rec hash_seq_lift #hsz hs = if S.length hs = 0 then S.empty else S.cons (MTS.HRaw (S.head hs)) (hash_seq_lift #hsz (S.tail hs)) #push-options "--z3rlimit 50 --initial_fuel 2 --max_fuel 2" val hash_seq_lift_index: #hsz:pos -> hs:hashes #hsz -> Lemma (requires True) (ensures forall (i:nat{i < S.length hs}). S.index (hash_seq_lift #hsz hs) i == MTS.HRaw (S.index hs i)) (decreases (S.length hs)) let rec hash_seq_lift_index #hsz hs = if S.length hs = 0 then () else hash_seq_lift_index #hsz (S.tail hs) #pop-options val create_pads: #hsz:pos -> len:nat -> GTot (pads:MTS.hashes #hsz {S.length pads = len}) let create_pads #hsz len = S.create len (MTS.HPad #hsz) val hash_seq_spec: #hsz:pos -> hs:hashes #hsz {S.length hs > 0} -> GTot (MTS.merkle_tree #hsz (log2c (S.length hs))) let hash_seq_spec #hsz hs = S.append (hash_seq_lift #hsz hs) (create_pads (pow2 (log2c (S.length hs)) - S.length hs)) val hash_seq_spec_index_raw: #hsz:pos -> hs:hashes #hsz {S.length hs > 0} -> i:nat{i < S.length hs} -> Lemma (S.index (hash_seq_spec #hsz hs) i == MTS.HRaw #hsz (S.index hs i)) let hash_seq_spec_index_raw #hsz hs i = hash_seq_lift_index #hsz hs // Now about recovering rightmost hashes #push-options "--z3rlimit 50 --initial_fuel 1 --max_fuel 1" val mt_hashes_next_rel_lift_even: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> j:nat{j > 1} -> hs:hashes #hsz {S.length hs = j} -> nhs:hashes #hsz {S.length nhs = j / 2} -> Lemma (requires j % 2 = 0 /\ mt_hashes_next_rel #_ #f j hs nhs) (ensures MTS.mt_next_rel #_ #f (log2c j) (hash_seq_spec #hsz hs) (hash_seq_spec #hsz nhs)) let mt_hashes_next_rel_lift_even #hsz #_ j hs nhs = hash_seq_lift_index #hsz hs; hash_seq_lift_index #hsz nhs val mt_hashes_next_rel_lift_odd: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> j:nat{j > 1} -> hs:hashes #hsz {S.length hs = j} -> nhs:hashes #hsz {S.length nhs = j / 2} -> Lemma (requires j % 2 = 1 /\ mt_hashes_next_rel #_ #f j hs nhs) (ensures MTS.mt_next_rel #_ #f (log2c j) (hash_seq_spec #hsz hs) (S.upd (hash_seq_spec #hsz nhs) (S.length nhs) (MTS.HRaw (S.last hs)))) let mt_hashes_next_rel_lift_odd #hsz #_ j hs nhs = log2c_div j; hash_seq_lift_index #hsz hs; hash_seq_lift_index #hsz nhs val mt_hashes_next_rel_next_even: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> j:nat{j > 1} -> hs:hashes #hsz {S.length hs = j} -> nhs:hashes #hsz {S.length nhs = j / 2} -> Lemma (requires j % 2 = 0 /\ mt_hashes_next_rel #_ #f j hs nhs) (ensures S.equal (hash_seq_spec #hsz nhs) (MTS.mt_next_lv #_ #f #(log2c j) (hash_seq_spec #hsz hs))) let mt_hashes_next_rel_next_even #hsz #f j hs nhs = log2c_div j; mt_hashes_next_rel_lift_even #_ #f j hs nhs; MTS.mt_next_rel_next_lv #_ #f (log2c j) (hash_seq_spec #hsz hs) (hash_seq_spec #hsz nhs) val hash_seq_spec_full: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> hs:hashes #hsz {S.length hs > 0} -> acc:hash #hsz -> actd:bool -> GTot (MTS.merkle_tree #hsz (log2c (S.length hs))) let hash_seq_spec_full #hsz #f hs acc actd = if actd then (S.upd (hash_seq_spec #hsz hs) (S.length hs) (MTS.HRaw acc)) else hash_seq_spec #hsz hs val hash_seq_spec_full_index_raw: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> hs:hashes #hsz {S.length hs > 0} -> acc:hash #hsz -> actd:bool -> i:nat{i < S.length hs} -> Lemma (S.index (hash_seq_spec_full #_ #f hs acc actd) i == MTS.HRaw (S.index hs i)) let hash_seq_spec_full_index_raw #hsz #_ hs acc actd i = hash_seq_spec_index_raw #hsz hs i val hash_seq_spec_full_case_true: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> hs:hashes #hsz {S.length hs > 0} -> acc:hash #hsz -> Lemma (S.index (hash_seq_spec_full #_ #f hs acc true) (S.length hs) == MTS.HRaw acc) let hash_seq_spec_full_case_true #_ #_ _ _ = () val hash_seq_spec_full_even_next: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> j:nat{j > 0} -> hs:hashes #hsz {S.length hs = j} -> nhs:hashes #hsz {S.length nhs = j / 2} -> acc:hash #hsz -> actd:bool -> Lemma (requires j % 2 = 0 /\ mt_hashes_next_rel #_ #f j hs nhs) (ensures S.equal (hash_seq_spec_full #_ #f nhs acc actd) (MTS.mt_next_lv #_ #f #(log2c j) (hash_seq_spec_full #_ #f hs acc actd))) #restart-solver #push-options "--quake 1/3 --z3rlimit 100 --fuel 2 --ifuel 1" let hash_seq_spec_full_even_next #hsz #f j hs nhs acc actd = log2c_div j; mt_hashes_next_rel_lift_even #_ #f j hs nhs; if actd then begin MTS.mt_next_rel_upd_even_pad #_ #f (log2c j) (hash_seq_spec #hsz hs) (hash_seq_spec #hsz nhs) (S.length hs / 2) (MTS.HRaw acc); let n = log2c j in let mt = S.upd (hash_seq_spec #hsz hs) (S.length hs) (MTS.HRaw acc) in let nmt = S.upd (hash_seq_spec #hsz nhs) (S.length nhs) (MTS.HRaw acc) in // assume (MTS.mt_next_rel #_ #f n mt nmt); MTS.mt_next_rel_next_lv #_ #f n mt nmt end else MTS.mt_next_rel_next_lv #_ #f (log2c j) (hash_seq_spec_full #_ #f hs acc actd) (hash_seq_spec_full #_ #f nhs acc actd) #pop-options #push-options "--z3rlimit 80" val hash_seq_spec_full_odd_next: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> j:nat{j > 1} -> hs:hashes #hsz {S.length hs = j} -> nhs:hashes #hsz {S.length nhs = j / 2} -> acc:hash #hsz -> actd:bool -> nacc:hash #hsz -> Lemma (requires j % 2 = 1 /\ mt_hashes_next_rel #_ #f j hs nhs /\ nacc == (if actd then f (S.last hs) acc else S.last hs)) (ensures S.equal (hash_seq_spec_full #_ #f nhs nacc true) (MTS.mt_next_lv #_ #f #(log2c j) (hash_seq_spec_full #_ #f hs acc actd))) let hash_seq_spec_full_odd_next #hsz #f j hs nhs acc actd nacc = log2c_div j; mt_hashes_next_rel_lift_odd #_ #f j hs nhs; if actd then begin MTS.mt_next_rel_upd_odd #_ #f (log2c j) (hash_seq_spec #hsz hs) (S.upd (hash_seq_spec #hsz nhs) (S.length nhs) (MTS.HRaw (S.last hs))) (S.length nhs) (MTS.HRaw acc); MTS.mt_next_rel_next_lv #_ #f (log2c j) (S.upd (hash_seq_spec #hsz hs) (S.length hs) (MTS.HRaw acc)) (S.upd (hash_seq_spec #hsz nhs) (S.length nhs) (MTS.HRaw (f (S.last hs) acc))) end else MTS.mt_next_rel_next_lv #_ #f (log2c j) (hash_seq_spec_full #_ #f hs acc actd) (hash_seq_spec_full #_ #f nhs nacc true) #pop-options val hash_seq_spec_full_next: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> j:nat{j > 1} -> hs:hashes #hsz {S.length hs = j} -> nhs:hashes #hsz {S.length nhs = j / 2} -> acc:hash #hsz -> actd:bool -> nacc:hash #hsz -> nactd:bool -> Lemma (requires mt_hashes_next_rel #_ #f j hs nhs /\ nacc == (if j % 2 = 0 then acc else if actd then f (S.last hs) acc else S.last hs) /\ nactd == (actd || j % 2 = 1)) (ensures S.equal (hash_seq_spec_full #_ #f nhs nacc nactd) (MTS.mt_next_lv #_ #f #(log2c j) (hash_seq_spec_full #_ #f hs acc actd))) let hash_seq_spec_full_next #_ #f j hs nhs acc actd nacc nactd = if j % 2 = 0 then hash_seq_spec_full_even_next #_ #f j hs nhs acc actd else hash_seq_spec_full_odd_next #_ #f j hs nhs acc actd nacc val mt_rhs_inv: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> j:nat -> smt:MTS.merkle_tree #hsz (log2c j) -> rhs:hashes #hsz {S.length rhs = log2c j} -> actd:bool -> GTot Type0 (decreases j) let rec mt_rhs_inv #_ #f j smt rhs actd = if j = 0 then true else begin (if j % 2 = 1 && actd then (S.index smt j == MTS.HRaw (S.head rhs)) else true) /\ mt_rhs_inv #_ #f (j / 2) (MTS.mt_next_lv #_ #f #(log2c j) smt) (S.tail rhs) (actd || (j % 2 = 1)) end val mt_root_inv: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> hs0:hashes #hsz {S.length hs0 > 0} -> acc:hash #hsz -> actd:bool -> rt:hash #hsz -> GTot Type0 let mt_root_inv #_ #f hs0 acc actd rt = MTS.mt_get_root #_ #f #(log2c (S.length hs0)) (hash_seq_spec_full #_ #f hs0 acc actd) == MTS.HRaw rt val mt_base: #hsz:pos -> mt:merkle_tree #hsz {mt_wf_elts mt} -> olds:hashess #hsz {S.length olds = 32 /\ mt_olds_inv #hsz 0 (MT?.i mt) olds} -> GTot (bhs:hashes #hsz {S.length bhs = MT?.j mt}) let mt_base #hsz mt olds = S.head (merge_hs #hsz #(MT?.hash_fun mt) olds (MT?.hs mt)) #pop-options // --max_fuel 1 val mt_spec: #hsz:pos -> mt:merkle_tree #hsz {mt_wf_elts mt /\ MT?.j mt > 0} -> olds:hashess{S.length olds = 32 /\ mt_olds_inv #hsz 0 (MT?.i mt) olds} ->
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "MerkleTree.Spec.fst.checked", "MerkleTree.New.High.fst.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Ghost.fsti.checked", "FStar.Classical.fsti.checked" ], "interface_file": false, "source_file": "MerkleTree.New.High.Correct.Base.fst" }
[ { "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": 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": 40, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
mt: MerkleTree.New.High.merkle_tree{MerkleTree.New.High.mt_wf_elts mt /\ MT?.j mt > 0} -> olds: MerkleTree.New.High.hashess { FStar.Seq.Base.length olds = 32 /\ MerkleTree.New.High.Correct.Base.mt_olds_inv 0 (MT?.i mt) olds } -> Prims.GTot (MerkleTree.Spec.merkle_tree (MerkleTree.New.High.Correct.Base.log2c (MT?.j mt)))
Prims.GTot
[ "sometrivial" ]
[]
[ "Prims.pos", "MerkleTree.New.High.merkle_tree", "Prims.l_and", "MerkleTree.New.High.mt_wf_elts", "Prims.b2t", "Prims.op_GreaterThan", "MerkleTree.New.High.__proj__MT__item__j", "MerkleTree.New.High.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.__proj__MT__item__i", "MerkleTree.New.High.Correct.Base.hash_seq_spec", "MerkleTree.New.High.Correct.Base.mt_base", "MerkleTree.Spec.merkle_tree", "MerkleTree.New.High.Correct.Base.log2c" ]
[]
false
false
false
false
false
let mt_spec #hsz mt olds =
hash_seq_spec #_ (mt_base mt olds)
false
MerkleTree.New.High.Correct.Base.fst
MerkleTree.New.High.Correct.Base.mt_inv
val mt_inv: #hsz:pos -> mt:merkle_tree #hsz {mt_wf_elts mt} -> olds:hashess{S.length olds = 32 /\ mt_olds_inv #hsz 0 (MT?.i mt) olds} -> GTot Type0
val mt_inv: #hsz:pos -> mt:merkle_tree #hsz {mt_wf_elts mt} -> olds:hashess{S.length olds = 32 /\ mt_olds_inv #hsz 0 (MT?.i mt) olds} -> GTot Type0
let mt_inv #hsz mt olds = let i = MT?.i mt in let j = MT?.j mt in let hs = MT?.hs mt in let rhs = MT?.rhs mt in let f = MT?.hash_fun mt in let fhs = merge_hs #hsz #f olds hs in let rt = MT?.mroot mt in log2c_bound j 32; mt_olds_hs_inv #_ #f 0 i j olds hs /\ (if j > 0 && MT?.rhs_ok mt then (mt_olds_hs_lth_inv_ok #_ #f 0 i j olds hs; mt_hashes_lth_inv_log_converted #_ #f j fhs; (mt_rhs_inv #_ #f j (mt_spec mt olds) (S.slice rhs 0 (log2c j)) false /\ mt_root_inv #_ #f (mt_base mt olds) hash_init false rt)) else true)
{ "file_name": "src/MerkleTree.New.High.Correct.Base.fst", "git_rev": "7d7bdc20f2033171e279c176b26e84f9069d23c6", "git_url": "https://github.com/hacl-star/merkle-tree.git", "project_name": "merkle-tree" }
{ "end_col": 12, "end_line": 662, "start_col": 0, "start_line": 647 }
module MerkleTree.New.High.Correct.Base open FStar.Classical open FStar.Ghost open FStar.Seq module S = FStar.Seq module MTS = MerkleTree.Spec open MerkleTree.New.High #set-options "--z3rlimit 40 --max_fuel 0 --max_ifuel 0" /// Sequence helpers val seq_prefix: #a:Type -> s1:S.seq a -> s2:S.seq a{S.length s1 <= S.length s2} -> GTot Type0 let seq_prefix #a s1 s2 = S.equal s1 (S.slice s2 0 (S.length s1)) val seq_head_cons: #a:Type -> x:a -> s:S.seq a -> Lemma (S.head (S.cons x s) == x) [SMTPat (S.cons x s)] let seq_head_cons #a x s = () val seq_tail_cons: #a:Type -> x:a -> s:S.seq a -> Lemma (S.equal (S.tail (S.cons x s)) s) [SMTPat (S.cons x s)] let seq_tail_cons #a x s = () /// Invariants and simulation relation of high-level Merkle tree design // Invariants of internal hashes val empty_hashes: (#hsz:pos) -> (len:nat) -> GTot (hs:hashess #hsz {S.length hs = len}) let empty_hashes #hsz len = S.create len S.empty val empty_hashes_head: #hsz:pos -> len:nat{len > 0} -> Lemma (S.head (empty_hashes #hsz len) == S.empty) let empty_hashes_head #_ _ = () val empty_hashes_tail: #hsz:pos -> len:nat{len > 0} -> Lemma (S.equal (S.tail (empty_hashes len)) (empty_hashes #hsz (len - 1))) let empty_hashes_tail #_ _ = () #push-options "--max_fuel 1" val mt_hashes_lth_inv: #hsz:pos -> lv:nat{lv <= 32} -> j:nat{j < pow2 (32 - lv)} -> fhs:hashess #hsz {S.length fhs = 32} -> GTot Type0 (decreases (32 - lv)) let rec mt_hashes_lth_inv #hsz lv j fhs = if lv = 32 then true else (S.length (S.index fhs lv) == j /\ mt_hashes_lth_inv (lv + 1) (j / 2) fhs) val mt_hashes_lth_inv_empty: #hsz:pos -> lv:nat{lv <= 32} -> Lemma (requires True) (ensures mt_hashes_lth_inv lv 0 (empty_hashes #hsz 32)) (decreases (32 - lv)) let rec mt_hashes_lth_inv_empty #hsz lv = if lv = 32 then () else mt_hashes_lth_inv_empty #hsz (lv + 1) val mt_hashes_next_rel: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> j:nat -> hs:hashes #hsz {S.length hs = j} -> nhs:hashes #hsz {S.length nhs = j / 2} -> GTot Type0 let mt_hashes_next_rel #hsz #f j hs nhs = forall (i:nat{i < j / 2}). S.index nhs i == f (S.index hs (op_Multiply 2 i)) (S.index hs (op_Multiply 2 i + 1)) #pop-options #push-options "--max_fuel 2" val mt_hashes_inv: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> lv:nat{lv < 32} -> j:nat{j < pow2 (32 - lv)} -> fhs:hashess #hsz {S.length fhs = 32 /\ mt_hashes_lth_inv lv j fhs} -> GTot Type0 (decreases (32 - lv)) let rec mt_hashes_inv #hsz #f lv j fhs = if lv = 31 then true else (mt_hashes_next_rel #_ #f j (S.index fhs lv) (S.index fhs (lv + 1)) /\ mt_hashes_inv #_ #f (lv + 1) (j / 2) fhs) val mt_hashes_inv_empty: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> lv:nat{lv < 32} -> Lemma (requires True) (ensures (mt_hashes_lth_inv_empty #hsz lv; mt_hashes_inv #hsz #f lv 0 (empty_hashes #hsz 32))) (decreases (32 - lv)) let rec mt_hashes_inv_empty #hsz #f lv = if lv = 31 then () else (mt_hashes_lth_inv_empty #hsz (lv + 1); mt_hashes_inv_empty #_ #f (lv + 1)) val mt_hashes_lth_inv_equiv: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> lv:nat{lv < 32} -> j:nat{j < pow2 (32 - lv)} -> fhs1:hashess{S.length fhs1 = 32} -> fhs2:hashess{S.length fhs2 = 32} -> Lemma (requires mt_hashes_lth_inv lv j fhs1 /\ S.equal (S.slice fhs1 lv 32) (S.slice fhs2 lv 32)) (ensures mt_hashes_lth_inv #hsz lv j fhs2) (decreases (32 - lv)) let rec mt_hashes_lth_inv_equiv #hsz #f lv j fhs1 fhs2 = if lv = 31 then () else (assert (S.index fhs1 lv == S.index fhs2 lv); mt_hashes_lth_inv_equiv #_ #f (lv + 1) (j / 2) fhs1 fhs2) #pop-options #push-options "--max_fuel 1" val mt_hashes_inv_equiv: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> lv:nat{lv < 32} -> j:nat{j < pow2 (32 - lv)} -> fhs1:hashess #hsz {S.length fhs1 = 32 /\ mt_hashes_lth_inv lv j fhs1} -> fhs2:hashess #hsz {S.length fhs2 = 32 /\ mt_hashes_lth_inv lv j fhs2} -> Lemma (requires mt_hashes_inv #_ #f lv j fhs1 /\ S.equal (S.slice fhs1 lv 32) (S.slice fhs2 lv 32)) (ensures mt_hashes_inv #_ #f lv j fhs2) (decreases (32 - lv)) let rec mt_hashes_inv_equiv #hsz #f lv j fhs1 fhs2 = if lv = 31 then () else (assert (S.index fhs1 lv == S.index fhs2 lv); assert (S.index fhs1 (lv + 1) == S.index fhs2 (lv + 1)); mt_hashes_inv_equiv #_ #f (lv + 1) (j / 2) fhs1 fhs2) val merge_hs: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> hs1:hashess #hsz -> hs2:hashess #hsz {S.length hs1 = S.length hs2} -> GTot (mhs:hashess #hsz {S.length mhs = S.length hs1}) (decreases (S.length hs1)) let rec merge_hs #hsz #f hs1 hs2 = if S.length hs1 = 0 then S.empty else (S.cons (S.append (S.head hs1) (S.head hs2)) (merge_hs #_ #f (S.tail hs1) (S.tail hs2))) val merge_hs_empty: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> len:nat -> Lemma (S.equal (merge_hs #_ #f (empty_hashes #hsz len) (empty_hashes #hsz len)) (empty_hashes #hsz len)) let rec merge_hs_empty #hsz #f len = if len = 0 then () else (empty_hashes_head #hsz len; empty_hashes_tail #hsz len; assert (S.equal (S.append #(hash #hsz) S.empty S.empty) (S.empty #(hash #hsz))); assert (S.equal (merge_hs #_ #f (empty_hashes len) (empty_hashes len)) (S.cons S.empty (merge_hs #_ #f (empty_hashes (len - 1)) (empty_hashes (len - 1))))); merge_hs_empty #_ #f (len - 1)) val merge_hs_index: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> hs1:hashess -> hs2:hashess{S.length hs1 = S.length hs2} -> i:nat{i < S.length hs1} -> Lemma (requires True) (ensures S.equal (S.index (merge_hs #_ #f hs1 hs2) i) (S.append (S.index hs1 i) (S.index hs2 i))) (decreases (S.length hs1)) [SMTPat (S.index (merge_hs #_ #f hs1 hs2) i)] let rec merge_hs_index #hsz #f hs1 hs2 i = if S.length hs1 = 0 then () else if i = 0 then () else merge_hs_index #_ #f (S.tail hs1) (S.tail hs2) (i - 1) val merge_hs_slice_equal: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> ahs1:hashess #hsz -> ahs2:hashess #hsz {S.length ahs1 = S.length ahs2} -> bhs1:hashess #hsz -> bhs2:hashess #hsz {S.length bhs1 = S.length bhs2} -> i:nat -> j:nat{i <= j && j <= S.length ahs1 && j <= S.length bhs1} -> Lemma (requires S.equal (S.slice ahs1 i j) (S.slice bhs1 i j) /\ S.equal (S.slice ahs2 i j) (S.slice bhs2 i j)) (ensures S.equal (S.slice (merge_hs #_ #f ahs1 ahs2) i j) (S.slice (merge_hs #_ #f bhs1 bhs2) i j)) (decreases (j - i)) let rec merge_hs_slice_equal #_ #f ahs1 ahs2 bhs1 bhs2 i j = if i = j then () else (assert (S.index ahs1 i == S.index bhs1 i); assert (S.index ahs2 i == S.index bhs2 i); merge_hs_slice_equal #_ #f ahs1 ahs2 bhs1 bhs2 (i + 1) j) val merge_hs_upd: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> hs1:hashess #hsz -> hs2:hashess #hsz {S.length hs1 = S.length hs2} -> i:nat{i < S.length hs1} -> v1:hashes #hsz -> v2:hashes #hsz -> Lemma (requires S.equal (S.append (S.index hs1 i) (S.index hs2 i)) (S.append v1 v2)) (ensures S.equal (merge_hs #_ #f hs1 hs2) (merge_hs #_ #f (S.upd hs1 i v1) (S.upd hs2 i v2))) (decreases i) let rec merge_hs_upd #_ #f hs1 hs2 i v1 v2 = if S.length hs1 = 0 then () else if i = 0 then () else merge_hs_upd #_ #f (S.tail hs1) (S.tail hs2) (i - 1) v1 v2 val mt_olds_inv: #hsz:pos -> lv:nat{lv <= 32} -> i:nat -> olds:hashess #hsz {S.length olds = 32} -> GTot Type0 (decreases (32 - lv)) let rec mt_olds_inv #hsz lv i olds = if lv = 32 then true else (let ofs = offset_of i in S.length (S.index olds lv) == ofs /\ mt_olds_inv #hsz (lv + 1) (i / 2) olds) val mt_olds_inv_equiv: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> lv:nat{lv <= 32} -> i:nat -> olds1:hashess #hsz {S.length olds1 = 32} -> olds2:hashess #hsz {S.length olds2 = 32} -> Lemma (requires mt_olds_inv #hsz lv i olds1 /\ S.equal (S.slice olds1 lv 32) (S.slice olds2 lv 32)) (ensures mt_olds_inv #hsz lv i olds2) (decreases (32 - lv)) let rec mt_olds_inv_equiv #hsz #f lv i olds1 olds2 = if lv = 32 then () else (assert (S.index olds1 lv == S.index olds2 lv); mt_olds_inv_equiv #_ #f (lv + 1) (i / 2) olds1 olds2) val mt_olds_hs_lth_inv_ok: #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 #hsz lv hs i j} -> Lemma (requires True) (ensures mt_hashes_lth_inv #hsz lv j (merge_hs #_ #f olds hs)) (decreases (32 - lv)) let rec mt_olds_hs_lth_inv_ok #hsz #f lv i j olds hs = if lv = 32 then () else (mt_olds_hs_lth_inv_ok #_ #f (lv + 1) (i / 2) (j / 2) olds hs) val mt_olds_hs_inv: #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 #hsz lv hs i j} -> GTot Type0 let mt_olds_hs_inv #hsz #f lv i j olds hs = mt_olds_hs_lth_inv_ok #_ #f lv i j olds hs; mt_hashes_inv #_ #f lv j (merge_hs #_ #f olds hs) // Relation between valid internal hashes (satisfying `mt_olds_hs_inv`) and // the spec. While giving such relation, all rightmost hashes are recovered. // Note that `MT?.rhs` after `construct_rhs` does NOT contain all rightmost // hashes; it has partial rightmost hashes that are enough to calculate // Merkle paths. val log2: n:nat{n > 0} -> GTot (c:nat{pow2 c <= n && n < pow2 (c+1)}) let rec log2 n = if n = 1 then 0 else 1 + log2 (n / 2) val log2_bound: n:nat{n > 0} -> c:nat{n < pow2 c} -> Lemma (log2 n <= c-1) let rec log2_bound n c = if n = 1 then () else log2_bound (n / 2) (c - 1) val log2_div: n:nat{n > 1} -> Lemma (log2 (n / 2) = log2 n - 1) let log2_div n = () val log2c: n:nat -> GTot (c:nat{c = 0 || (pow2 (c-1) <= n && n < pow2 c)}) let log2c n = if n = 0 then 0 else (log2 n + 1) val log2c_div: n:nat{n > 0} -> Lemma (log2c (n / 2) = log2c n - 1) let log2c_div n = () val log2c_bound: n:nat -> c:nat{n < pow2 c} -> Lemma (log2c n <= c) let rec log2c_bound n c = if n = 0 then () else log2c_bound (n / 2) (c - 1) val mt_hashes_lth_inv_log: #hsz:pos -> j:nat -> fhs:hashess #hsz {S.length fhs = log2c j} -> GTot Type0 (decreases j) let rec mt_hashes_lth_inv_log #hsz j fhs = if j = 0 then true else (S.length (S.head fhs) == j /\ mt_hashes_lth_inv_log #hsz (j / 2) (S.tail fhs)) #pop-options #push-options "--max_fuel 2" val mt_hashes_lth_inv_log_next: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> j:nat{j > 1} -> fhs:hashess #hsz {S.length fhs = log2c j} -> Lemma (requires mt_hashes_lth_inv_log #hsz j fhs) (ensures S.length (S.head fhs) == j /\ S.length (S.head (S.tail fhs)) == j / 2) let mt_hashes_lth_inv_log_next #_ #_ _ _ = () val mt_hashes_inv_log: #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} -> GTot Type0 (decreases j) let rec mt_hashes_inv_log #hsz #f j fhs = if j <= 1 then true else (mt_hashes_next_rel #_ #f j (S.index fhs 0) (S.index fhs 1) /\ mt_hashes_inv_log #_ #f (j / 2) (S.tail fhs)) val mt_hashes_lth_inv_log_converted_: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> lv:nat{lv <= 32} -> j:nat{j < pow2 (32 - lv)} -> fhs:hashess #hsz {S.length fhs = 32} -> Lemma (requires mt_hashes_lth_inv #hsz lv j fhs) (ensures (log2c_bound j (32 - lv); mt_hashes_lth_inv_log #hsz j (S.slice fhs lv (lv + log2c j)))) (decreases j) let rec mt_hashes_lth_inv_log_converted_ #_ #f lv j fhs = if j = 0 then () else (log2c_bound (j / 2) (32 - (lv + 1)); mt_hashes_lth_inv_log_converted_ #_ #f (lv + 1) (j / 2) fhs) val mt_hashes_lth_inv_log_converted: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> j:nat{j < pow2 32} -> fhs:hashess #hsz {S.length fhs = 32} -> Lemma (requires mt_hashes_lth_inv #hsz 0 j fhs) (ensures (log2c_bound j 32; mt_hashes_lth_inv_log #hsz j (S.slice fhs 0 (log2c j)))) let mt_hashes_lth_inv_log_converted #_ #f j fhs = mt_hashes_lth_inv_log_converted_ #_ #f 0 j fhs val mt_hashes_inv_log_converted_: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> lv:nat{lv <= 32} -> j:nat{j > 0 && j < pow2 (32 - lv)} -> fhs:hashess #hsz {S.length fhs = 32 /\ mt_hashes_lth_inv #hsz lv j fhs} -> Lemma (requires mt_hashes_inv #_ #f lv j fhs) (ensures (log2c_bound j (32 - lv); mt_hashes_lth_inv_log_converted_ #_ #f lv j fhs; mt_hashes_inv_log #_ #f j (S.slice fhs lv (lv + log2c j)))) (decreases j) #pop-options #push-options "--z3rlimit 100 --initial_fuel 2 --max_fuel 2" let rec mt_hashes_inv_log_converted_ #_ #f lv j fhs = if j = 1 then () else (log2c_bound (j / 2) (32 - (lv + 1)); mt_hashes_lth_inv_log_converted_ #_ #f (lv + 1) (j / 2) fhs; mt_hashes_inv_log_converted_ #_ #f (lv + 1) (j / 2) fhs) #pop-options val mt_hashes_inv_log_converted: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> j:nat{j > 0 && j < pow2 32} -> fhs:hashess #hsz {S.length fhs = 32 /\ mt_hashes_lth_inv #hsz 0 j fhs} -> Lemma (requires mt_hashes_inv #_ #f 0 j fhs) (ensures (log2c_bound j 32; mt_hashes_lth_inv_log_converted_ #_ #f 0 j fhs; mt_hashes_inv_log #_ #f j (S.slice fhs 0 (log2c j)))) let mt_hashes_inv_log_converted #_ #f j fhs = mt_hashes_inv_log_converted_ #_ #f 0 j fhs val hash_seq_lift: #hsz:pos -> hs:hashes #hsz -> GTot (shs:MTS.hashes #hsz {S.length shs = S.length hs}) (decreases (S.length hs)) let rec hash_seq_lift #hsz hs = if S.length hs = 0 then S.empty else S.cons (MTS.HRaw (S.head hs)) (hash_seq_lift #hsz (S.tail hs)) #push-options "--z3rlimit 50 --initial_fuel 2 --max_fuel 2" val hash_seq_lift_index: #hsz:pos -> hs:hashes #hsz -> Lemma (requires True) (ensures forall (i:nat{i < S.length hs}). S.index (hash_seq_lift #hsz hs) i == MTS.HRaw (S.index hs i)) (decreases (S.length hs)) let rec hash_seq_lift_index #hsz hs = if S.length hs = 0 then () else hash_seq_lift_index #hsz (S.tail hs) #pop-options val create_pads: #hsz:pos -> len:nat -> GTot (pads:MTS.hashes #hsz {S.length pads = len}) let create_pads #hsz len = S.create len (MTS.HPad #hsz) val hash_seq_spec: #hsz:pos -> hs:hashes #hsz {S.length hs > 0} -> GTot (MTS.merkle_tree #hsz (log2c (S.length hs))) let hash_seq_spec #hsz hs = S.append (hash_seq_lift #hsz hs) (create_pads (pow2 (log2c (S.length hs)) - S.length hs)) val hash_seq_spec_index_raw: #hsz:pos -> hs:hashes #hsz {S.length hs > 0} -> i:nat{i < S.length hs} -> Lemma (S.index (hash_seq_spec #hsz hs) i == MTS.HRaw #hsz (S.index hs i)) let hash_seq_spec_index_raw #hsz hs i = hash_seq_lift_index #hsz hs // Now about recovering rightmost hashes #push-options "--z3rlimit 50 --initial_fuel 1 --max_fuel 1" val mt_hashes_next_rel_lift_even: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> j:nat{j > 1} -> hs:hashes #hsz {S.length hs = j} -> nhs:hashes #hsz {S.length nhs = j / 2} -> Lemma (requires j % 2 = 0 /\ mt_hashes_next_rel #_ #f j hs nhs) (ensures MTS.mt_next_rel #_ #f (log2c j) (hash_seq_spec #hsz hs) (hash_seq_spec #hsz nhs)) let mt_hashes_next_rel_lift_even #hsz #_ j hs nhs = hash_seq_lift_index #hsz hs; hash_seq_lift_index #hsz nhs val mt_hashes_next_rel_lift_odd: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> j:nat{j > 1} -> hs:hashes #hsz {S.length hs = j} -> nhs:hashes #hsz {S.length nhs = j / 2} -> Lemma (requires j % 2 = 1 /\ mt_hashes_next_rel #_ #f j hs nhs) (ensures MTS.mt_next_rel #_ #f (log2c j) (hash_seq_spec #hsz hs) (S.upd (hash_seq_spec #hsz nhs) (S.length nhs) (MTS.HRaw (S.last hs)))) let mt_hashes_next_rel_lift_odd #hsz #_ j hs nhs = log2c_div j; hash_seq_lift_index #hsz hs; hash_seq_lift_index #hsz nhs val mt_hashes_next_rel_next_even: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> j:nat{j > 1} -> hs:hashes #hsz {S.length hs = j} -> nhs:hashes #hsz {S.length nhs = j / 2} -> Lemma (requires j % 2 = 0 /\ mt_hashes_next_rel #_ #f j hs nhs) (ensures S.equal (hash_seq_spec #hsz nhs) (MTS.mt_next_lv #_ #f #(log2c j) (hash_seq_spec #hsz hs))) let mt_hashes_next_rel_next_even #hsz #f j hs nhs = log2c_div j; mt_hashes_next_rel_lift_even #_ #f j hs nhs; MTS.mt_next_rel_next_lv #_ #f (log2c j) (hash_seq_spec #hsz hs) (hash_seq_spec #hsz nhs) val hash_seq_spec_full: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> hs:hashes #hsz {S.length hs > 0} -> acc:hash #hsz -> actd:bool -> GTot (MTS.merkle_tree #hsz (log2c (S.length hs))) let hash_seq_spec_full #hsz #f hs acc actd = if actd then (S.upd (hash_seq_spec #hsz hs) (S.length hs) (MTS.HRaw acc)) else hash_seq_spec #hsz hs val hash_seq_spec_full_index_raw: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> hs:hashes #hsz {S.length hs > 0} -> acc:hash #hsz -> actd:bool -> i:nat{i < S.length hs} -> Lemma (S.index (hash_seq_spec_full #_ #f hs acc actd) i == MTS.HRaw (S.index hs i)) let hash_seq_spec_full_index_raw #hsz #_ hs acc actd i = hash_seq_spec_index_raw #hsz hs i val hash_seq_spec_full_case_true: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> hs:hashes #hsz {S.length hs > 0} -> acc:hash #hsz -> Lemma (S.index (hash_seq_spec_full #_ #f hs acc true) (S.length hs) == MTS.HRaw acc) let hash_seq_spec_full_case_true #_ #_ _ _ = () val hash_seq_spec_full_even_next: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> j:nat{j > 0} -> hs:hashes #hsz {S.length hs = j} -> nhs:hashes #hsz {S.length nhs = j / 2} -> acc:hash #hsz -> actd:bool -> Lemma (requires j % 2 = 0 /\ mt_hashes_next_rel #_ #f j hs nhs) (ensures S.equal (hash_seq_spec_full #_ #f nhs acc actd) (MTS.mt_next_lv #_ #f #(log2c j) (hash_seq_spec_full #_ #f hs acc actd))) #restart-solver #push-options "--quake 1/3 --z3rlimit 100 --fuel 2 --ifuel 1" let hash_seq_spec_full_even_next #hsz #f j hs nhs acc actd = log2c_div j; mt_hashes_next_rel_lift_even #_ #f j hs nhs; if actd then begin MTS.mt_next_rel_upd_even_pad #_ #f (log2c j) (hash_seq_spec #hsz hs) (hash_seq_spec #hsz nhs) (S.length hs / 2) (MTS.HRaw acc); let n = log2c j in let mt = S.upd (hash_seq_spec #hsz hs) (S.length hs) (MTS.HRaw acc) in let nmt = S.upd (hash_seq_spec #hsz nhs) (S.length nhs) (MTS.HRaw acc) in // assume (MTS.mt_next_rel #_ #f n mt nmt); MTS.mt_next_rel_next_lv #_ #f n mt nmt end else MTS.mt_next_rel_next_lv #_ #f (log2c j) (hash_seq_spec_full #_ #f hs acc actd) (hash_seq_spec_full #_ #f nhs acc actd) #pop-options #push-options "--z3rlimit 80" val hash_seq_spec_full_odd_next: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> j:nat{j > 1} -> hs:hashes #hsz {S.length hs = j} -> nhs:hashes #hsz {S.length nhs = j / 2} -> acc:hash #hsz -> actd:bool -> nacc:hash #hsz -> Lemma (requires j % 2 = 1 /\ mt_hashes_next_rel #_ #f j hs nhs /\ nacc == (if actd then f (S.last hs) acc else S.last hs)) (ensures S.equal (hash_seq_spec_full #_ #f nhs nacc true) (MTS.mt_next_lv #_ #f #(log2c j) (hash_seq_spec_full #_ #f hs acc actd))) let hash_seq_spec_full_odd_next #hsz #f j hs nhs acc actd nacc = log2c_div j; mt_hashes_next_rel_lift_odd #_ #f j hs nhs; if actd then begin MTS.mt_next_rel_upd_odd #_ #f (log2c j) (hash_seq_spec #hsz hs) (S.upd (hash_seq_spec #hsz nhs) (S.length nhs) (MTS.HRaw (S.last hs))) (S.length nhs) (MTS.HRaw acc); MTS.mt_next_rel_next_lv #_ #f (log2c j) (S.upd (hash_seq_spec #hsz hs) (S.length hs) (MTS.HRaw acc)) (S.upd (hash_seq_spec #hsz nhs) (S.length nhs) (MTS.HRaw (f (S.last hs) acc))) end else MTS.mt_next_rel_next_lv #_ #f (log2c j) (hash_seq_spec_full #_ #f hs acc actd) (hash_seq_spec_full #_ #f nhs nacc true) #pop-options val hash_seq_spec_full_next: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> j:nat{j > 1} -> hs:hashes #hsz {S.length hs = j} -> nhs:hashes #hsz {S.length nhs = j / 2} -> acc:hash #hsz -> actd:bool -> nacc:hash #hsz -> nactd:bool -> Lemma (requires mt_hashes_next_rel #_ #f j hs nhs /\ nacc == (if j % 2 = 0 then acc else if actd then f (S.last hs) acc else S.last hs) /\ nactd == (actd || j % 2 = 1)) (ensures S.equal (hash_seq_spec_full #_ #f nhs nacc nactd) (MTS.mt_next_lv #_ #f #(log2c j) (hash_seq_spec_full #_ #f hs acc actd))) let hash_seq_spec_full_next #_ #f j hs nhs acc actd nacc nactd = if j % 2 = 0 then hash_seq_spec_full_even_next #_ #f j hs nhs acc actd else hash_seq_spec_full_odd_next #_ #f j hs nhs acc actd nacc val mt_rhs_inv: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> j:nat -> smt:MTS.merkle_tree #hsz (log2c j) -> rhs:hashes #hsz {S.length rhs = log2c j} -> actd:bool -> GTot Type0 (decreases j) let rec mt_rhs_inv #_ #f j smt rhs actd = if j = 0 then true else begin (if j % 2 = 1 && actd then (S.index smt j == MTS.HRaw (S.head rhs)) else true) /\ mt_rhs_inv #_ #f (j / 2) (MTS.mt_next_lv #_ #f #(log2c j) smt) (S.tail rhs) (actd || (j % 2 = 1)) end val mt_root_inv: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> hs0:hashes #hsz {S.length hs0 > 0} -> acc:hash #hsz -> actd:bool -> rt:hash #hsz -> GTot Type0 let mt_root_inv #_ #f hs0 acc actd rt = MTS.mt_get_root #_ #f #(log2c (S.length hs0)) (hash_seq_spec_full #_ #f hs0 acc actd) == MTS.HRaw rt val mt_base: #hsz:pos -> mt:merkle_tree #hsz {mt_wf_elts mt} -> olds:hashess #hsz {S.length olds = 32 /\ mt_olds_inv #hsz 0 (MT?.i mt) olds} -> GTot (bhs:hashes #hsz {S.length bhs = MT?.j mt}) let mt_base #hsz mt olds = S.head (merge_hs #hsz #(MT?.hash_fun mt) olds (MT?.hs mt)) #pop-options // --max_fuel 1 val mt_spec: #hsz:pos -> mt:merkle_tree #hsz {mt_wf_elts mt /\ MT?.j mt > 0} -> olds:hashess{S.length olds = 32 /\ mt_olds_inv #hsz 0 (MT?.i mt) olds} -> GTot (MTS.merkle_tree #hsz (log2c (MT?.j mt))) let mt_spec #hsz mt olds = hash_seq_spec #_ (mt_base mt olds) val mt_inv: #hsz:pos -> mt:merkle_tree #hsz {mt_wf_elts mt} -> olds:hashess{S.length olds = 32 /\ mt_olds_inv #hsz 0 (MT?.i mt) olds} ->
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "MerkleTree.Spec.fst.checked", "MerkleTree.New.High.fst.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Ghost.fsti.checked", "FStar.Classical.fsti.checked" ], "interface_file": false, "source_file": "MerkleTree.New.High.Correct.Base.fst" }
[ { "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": 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": 40, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
mt: MerkleTree.New.High.merkle_tree{MerkleTree.New.High.mt_wf_elts mt} -> olds: MerkleTree.New.High.hashess { FStar.Seq.Base.length olds = 32 /\ MerkleTree.New.High.Correct.Base.mt_olds_inv 0 (MT?.i mt) olds } -> Prims.GTot Type0
Prims.GTot
[ "sometrivial" ]
[]
[ "Prims.pos", "MerkleTree.New.High.merkle_tree", "MerkleTree.New.High.mt_wf_elts", "MerkleTree.New.High.hashess", "Prims.l_and", "Prims.b2t", "Prims.op_Equality", "Prims.int", "FStar.Seq.Base.length", "MerkleTree.New.High.hashes", "MerkleTree.New.High.Correct.Base.mt_olds_inv", "MerkleTree.New.High.__proj__MT__item__i", "MerkleTree.New.High.Correct.Base.mt_olds_hs_inv", "Prims.op_AmpAmp", "Prims.op_GreaterThan", "MerkleTree.New.High.__proj__MT__item__rhs_ok", "MerkleTree.New.High.Correct.Base.mt_rhs_inv", "MerkleTree.New.High.Correct.Base.mt_spec", "FStar.Seq.Base.slice", "MerkleTree.New.High.hash", "MerkleTree.New.High.Correct.Base.log2c", "MerkleTree.New.High.Correct.Base.mt_root_inv", "MerkleTree.New.High.Correct.Base.mt_base", "MerkleTree.New.High.hash_init", "Prims.unit", "MerkleTree.New.High.Correct.Base.mt_hashes_lth_inv_log_converted", "MerkleTree.New.High.Correct.Base.mt_olds_hs_lth_inv_ok", "Prims.bool", "Prims.logical", "MerkleTree.New.High.Correct.Base.log2c_bound", "MerkleTree.New.High.__proj__MT__item__mroot", "Prims.nat", "MerkleTree.New.High.Correct.Base.merge_hs", "MerkleTree.Spec.hash_fun_t", "MerkleTree.New.High.__proj__MT__item__hash_fun", "MerkleTree.New.High.__proj__MT__item__rhs", "MerkleTree.New.High.__proj__MT__item__hs", "Prims.op_LessThanOrEqual", "Prims.op_LessThan", "Prims.pow2", "MerkleTree.New.High.__proj__MT__item__j" ]
[]
false
false
false
false
true
let mt_inv #hsz mt olds =
let i = MT?.i mt in let j = MT?.j mt in let hs = MT?.hs mt in let rhs = MT?.rhs mt in let f = MT?.hash_fun mt in let fhs = merge_hs #hsz #f olds hs in let rt = MT?.mroot mt in log2c_bound j 32; mt_olds_hs_inv #_ #f 0 i j olds hs /\ (if j > 0 && MT?.rhs_ok mt then (mt_olds_hs_lth_inv_ok #_ #f 0 i j olds hs; mt_hashes_lth_inv_log_converted #_ #f j fhs; (mt_rhs_inv #_ #f j (mt_spec mt olds) (S.slice rhs 0 (log2c j)) false /\ mt_root_inv #_ #f (mt_base mt olds) hash_init false rt)) else true)
false
MerkleTree.New.High.Correct.Base.fst
MerkleTree.New.High.Correct.Base.hash_seq_spec_full_index_raw
val hash_seq_spec_full_index_raw: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> hs:hashes #hsz {S.length hs > 0} -> acc:hash #hsz -> actd:bool -> i:nat{i < S.length hs} -> Lemma (S.index (hash_seq_spec_full #_ #f hs acc actd) i == MTS.HRaw (S.index hs i))
val hash_seq_spec_full_index_raw: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> hs:hashes #hsz {S.length hs > 0} -> acc:hash #hsz -> actd:bool -> i:nat{i < S.length hs} -> Lemma (S.index (hash_seq_spec_full #_ #f hs acc actd) i == MTS.HRaw (S.index hs i))
let hash_seq_spec_full_index_raw #hsz #_ hs acc actd i = hash_seq_spec_index_raw #hsz hs i
{ "file_name": "src/MerkleTree.New.High.Correct.Base.fst", "git_rev": "7d7bdc20f2033171e279c176b26e84f9069d23c6", "git_url": "https://github.com/hacl-star/merkle-tree.git", "project_name": "merkle-tree" }
{ "end_col": 35, "end_line": 506, "start_col": 0, "start_line": 505 }
module MerkleTree.New.High.Correct.Base open FStar.Classical open FStar.Ghost open FStar.Seq module S = FStar.Seq module MTS = MerkleTree.Spec open MerkleTree.New.High #set-options "--z3rlimit 40 --max_fuel 0 --max_ifuel 0" /// Sequence helpers val seq_prefix: #a:Type -> s1:S.seq a -> s2:S.seq a{S.length s1 <= S.length s2} -> GTot Type0 let seq_prefix #a s1 s2 = S.equal s1 (S.slice s2 0 (S.length s1)) val seq_head_cons: #a:Type -> x:a -> s:S.seq a -> Lemma (S.head (S.cons x s) == x) [SMTPat (S.cons x s)] let seq_head_cons #a x s = () val seq_tail_cons: #a:Type -> x:a -> s:S.seq a -> Lemma (S.equal (S.tail (S.cons x s)) s) [SMTPat (S.cons x s)] let seq_tail_cons #a x s = () /// Invariants and simulation relation of high-level Merkle tree design // Invariants of internal hashes val empty_hashes: (#hsz:pos) -> (len:nat) -> GTot (hs:hashess #hsz {S.length hs = len}) let empty_hashes #hsz len = S.create len S.empty val empty_hashes_head: #hsz:pos -> len:nat{len > 0} -> Lemma (S.head (empty_hashes #hsz len) == S.empty) let empty_hashes_head #_ _ = () val empty_hashes_tail: #hsz:pos -> len:nat{len > 0} -> Lemma (S.equal (S.tail (empty_hashes len)) (empty_hashes #hsz (len - 1))) let empty_hashes_tail #_ _ = () #push-options "--max_fuel 1" val mt_hashes_lth_inv: #hsz:pos -> lv:nat{lv <= 32} -> j:nat{j < pow2 (32 - lv)} -> fhs:hashess #hsz {S.length fhs = 32} -> GTot Type0 (decreases (32 - lv)) let rec mt_hashes_lth_inv #hsz lv j fhs = if lv = 32 then true else (S.length (S.index fhs lv) == j /\ mt_hashes_lth_inv (lv + 1) (j / 2) fhs) val mt_hashes_lth_inv_empty: #hsz:pos -> lv:nat{lv <= 32} -> Lemma (requires True) (ensures mt_hashes_lth_inv lv 0 (empty_hashes #hsz 32)) (decreases (32 - lv)) let rec mt_hashes_lth_inv_empty #hsz lv = if lv = 32 then () else mt_hashes_lth_inv_empty #hsz (lv + 1) val mt_hashes_next_rel: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> j:nat -> hs:hashes #hsz {S.length hs = j} -> nhs:hashes #hsz {S.length nhs = j / 2} -> GTot Type0 let mt_hashes_next_rel #hsz #f j hs nhs = forall (i:nat{i < j / 2}). S.index nhs i == f (S.index hs (op_Multiply 2 i)) (S.index hs (op_Multiply 2 i + 1)) #pop-options #push-options "--max_fuel 2" val mt_hashes_inv: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> lv:nat{lv < 32} -> j:nat{j < pow2 (32 - lv)} -> fhs:hashess #hsz {S.length fhs = 32 /\ mt_hashes_lth_inv lv j fhs} -> GTot Type0 (decreases (32 - lv)) let rec mt_hashes_inv #hsz #f lv j fhs = if lv = 31 then true else (mt_hashes_next_rel #_ #f j (S.index fhs lv) (S.index fhs (lv + 1)) /\ mt_hashes_inv #_ #f (lv + 1) (j / 2) fhs) val mt_hashes_inv_empty: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> lv:nat{lv < 32} -> Lemma (requires True) (ensures (mt_hashes_lth_inv_empty #hsz lv; mt_hashes_inv #hsz #f lv 0 (empty_hashes #hsz 32))) (decreases (32 - lv)) let rec mt_hashes_inv_empty #hsz #f lv = if lv = 31 then () else (mt_hashes_lth_inv_empty #hsz (lv + 1); mt_hashes_inv_empty #_ #f (lv + 1)) val mt_hashes_lth_inv_equiv: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> lv:nat{lv < 32} -> j:nat{j < pow2 (32 - lv)} -> fhs1:hashess{S.length fhs1 = 32} -> fhs2:hashess{S.length fhs2 = 32} -> Lemma (requires mt_hashes_lth_inv lv j fhs1 /\ S.equal (S.slice fhs1 lv 32) (S.slice fhs2 lv 32)) (ensures mt_hashes_lth_inv #hsz lv j fhs2) (decreases (32 - lv)) let rec mt_hashes_lth_inv_equiv #hsz #f lv j fhs1 fhs2 = if lv = 31 then () else (assert (S.index fhs1 lv == S.index fhs2 lv); mt_hashes_lth_inv_equiv #_ #f (lv + 1) (j / 2) fhs1 fhs2) #pop-options #push-options "--max_fuel 1" val mt_hashes_inv_equiv: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> lv:nat{lv < 32} -> j:nat{j < pow2 (32 - lv)} -> fhs1:hashess #hsz {S.length fhs1 = 32 /\ mt_hashes_lth_inv lv j fhs1} -> fhs2:hashess #hsz {S.length fhs2 = 32 /\ mt_hashes_lth_inv lv j fhs2} -> Lemma (requires mt_hashes_inv #_ #f lv j fhs1 /\ S.equal (S.slice fhs1 lv 32) (S.slice fhs2 lv 32)) (ensures mt_hashes_inv #_ #f lv j fhs2) (decreases (32 - lv)) let rec mt_hashes_inv_equiv #hsz #f lv j fhs1 fhs2 = if lv = 31 then () else (assert (S.index fhs1 lv == S.index fhs2 lv); assert (S.index fhs1 (lv + 1) == S.index fhs2 (lv + 1)); mt_hashes_inv_equiv #_ #f (lv + 1) (j / 2) fhs1 fhs2) val merge_hs: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> hs1:hashess #hsz -> hs2:hashess #hsz {S.length hs1 = S.length hs2} -> GTot (mhs:hashess #hsz {S.length mhs = S.length hs1}) (decreases (S.length hs1)) let rec merge_hs #hsz #f hs1 hs2 = if S.length hs1 = 0 then S.empty else (S.cons (S.append (S.head hs1) (S.head hs2)) (merge_hs #_ #f (S.tail hs1) (S.tail hs2))) val merge_hs_empty: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> len:nat -> Lemma (S.equal (merge_hs #_ #f (empty_hashes #hsz len) (empty_hashes #hsz len)) (empty_hashes #hsz len)) let rec merge_hs_empty #hsz #f len = if len = 0 then () else (empty_hashes_head #hsz len; empty_hashes_tail #hsz len; assert (S.equal (S.append #(hash #hsz) S.empty S.empty) (S.empty #(hash #hsz))); assert (S.equal (merge_hs #_ #f (empty_hashes len) (empty_hashes len)) (S.cons S.empty (merge_hs #_ #f (empty_hashes (len - 1)) (empty_hashes (len - 1))))); merge_hs_empty #_ #f (len - 1)) val merge_hs_index: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> hs1:hashess -> hs2:hashess{S.length hs1 = S.length hs2} -> i:nat{i < S.length hs1} -> Lemma (requires True) (ensures S.equal (S.index (merge_hs #_ #f hs1 hs2) i) (S.append (S.index hs1 i) (S.index hs2 i))) (decreases (S.length hs1)) [SMTPat (S.index (merge_hs #_ #f hs1 hs2) i)] let rec merge_hs_index #hsz #f hs1 hs2 i = if S.length hs1 = 0 then () else if i = 0 then () else merge_hs_index #_ #f (S.tail hs1) (S.tail hs2) (i - 1) val merge_hs_slice_equal: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> ahs1:hashess #hsz -> ahs2:hashess #hsz {S.length ahs1 = S.length ahs2} -> bhs1:hashess #hsz -> bhs2:hashess #hsz {S.length bhs1 = S.length bhs2} -> i:nat -> j:nat{i <= j && j <= S.length ahs1 && j <= S.length bhs1} -> Lemma (requires S.equal (S.slice ahs1 i j) (S.slice bhs1 i j) /\ S.equal (S.slice ahs2 i j) (S.slice bhs2 i j)) (ensures S.equal (S.slice (merge_hs #_ #f ahs1 ahs2) i j) (S.slice (merge_hs #_ #f bhs1 bhs2) i j)) (decreases (j - i)) let rec merge_hs_slice_equal #_ #f ahs1 ahs2 bhs1 bhs2 i j = if i = j then () else (assert (S.index ahs1 i == S.index bhs1 i); assert (S.index ahs2 i == S.index bhs2 i); merge_hs_slice_equal #_ #f ahs1 ahs2 bhs1 bhs2 (i + 1) j) val merge_hs_upd: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> hs1:hashess #hsz -> hs2:hashess #hsz {S.length hs1 = S.length hs2} -> i:nat{i < S.length hs1} -> v1:hashes #hsz -> v2:hashes #hsz -> Lemma (requires S.equal (S.append (S.index hs1 i) (S.index hs2 i)) (S.append v1 v2)) (ensures S.equal (merge_hs #_ #f hs1 hs2) (merge_hs #_ #f (S.upd hs1 i v1) (S.upd hs2 i v2))) (decreases i) let rec merge_hs_upd #_ #f hs1 hs2 i v1 v2 = if S.length hs1 = 0 then () else if i = 0 then () else merge_hs_upd #_ #f (S.tail hs1) (S.tail hs2) (i - 1) v1 v2 val mt_olds_inv: #hsz:pos -> lv:nat{lv <= 32} -> i:nat -> olds:hashess #hsz {S.length olds = 32} -> GTot Type0 (decreases (32 - lv)) let rec mt_olds_inv #hsz lv i olds = if lv = 32 then true else (let ofs = offset_of i in S.length (S.index olds lv) == ofs /\ mt_olds_inv #hsz (lv + 1) (i / 2) olds) val mt_olds_inv_equiv: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> lv:nat{lv <= 32} -> i:nat -> olds1:hashess #hsz {S.length olds1 = 32} -> olds2:hashess #hsz {S.length olds2 = 32} -> Lemma (requires mt_olds_inv #hsz lv i olds1 /\ S.equal (S.slice olds1 lv 32) (S.slice olds2 lv 32)) (ensures mt_olds_inv #hsz lv i olds2) (decreases (32 - lv)) let rec mt_olds_inv_equiv #hsz #f lv i olds1 olds2 = if lv = 32 then () else (assert (S.index olds1 lv == S.index olds2 lv); mt_olds_inv_equiv #_ #f (lv + 1) (i / 2) olds1 olds2) val mt_olds_hs_lth_inv_ok: #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 #hsz lv hs i j} -> Lemma (requires True) (ensures mt_hashes_lth_inv #hsz lv j (merge_hs #_ #f olds hs)) (decreases (32 - lv)) let rec mt_olds_hs_lth_inv_ok #hsz #f lv i j olds hs = if lv = 32 then () else (mt_olds_hs_lth_inv_ok #_ #f (lv + 1) (i / 2) (j / 2) olds hs) val mt_olds_hs_inv: #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 #hsz lv hs i j} -> GTot Type0 let mt_olds_hs_inv #hsz #f lv i j olds hs = mt_olds_hs_lth_inv_ok #_ #f lv i j olds hs; mt_hashes_inv #_ #f lv j (merge_hs #_ #f olds hs) // Relation between valid internal hashes (satisfying `mt_olds_hs_inv`) and // the spec. While giving such relation, all rightmost hashes are recovered. // Note that `MT?.rhs` after `construct_rhs` does NOT contain all rightmost // hashes; it has partial rightmost hashes that are enough to calculate // Merkle paths. val log2: n:nat{n > 0} -> GTot (c:nat{pow2 c <= n && n < pow2 (c+1)}) let rec log2 n = if n = 1 then 0 else 1 + log2 (n / 2) val log2_bound: n:nat{n > 0} -> c:nat{n < pow2 c} -> Lemma (log2 n <= c-1) let rec log2_bound n c = if n = 1 then () else log2_bound (n / 2) (c - 1) val log2_div: n:nat{n > 1} -> Lemma (log2 (n / 2) = log2 n - 1) let log2_div n = () val log2c: n:nat -> GTot (c:nat{c = 0 || (pow2 (c-1) <= n && n < pow2 c)}) let log2c n = if n = 0 then 0 else (log2 n + 1) val log2c_div: n:nat{n > 0} -> Lemma (log2c (n / 2) = log2c n - 1) let log2c_div n = () val log2c_bound: n:nat -> c:nat{n < pow2 c} -> Lemma (log2c n <= c) let rec log2c_bound n c = if n = 0 then () else log2c_bound (n / 2) (c - 1) val mt_hashes_lth_inv_log: #hsz:pos -> j:nat -> fhs:hashess #hsz {S.length fhs = log2c j} -> GTot Type0 (decreases j) let rec mt_hashes_lth_inv_log #hsz j fhs = if j = 0 then true else (S.length (S.head fhs) == j /\ mt_hashes_lth_inv_log #hsz (j / 2) (S.tail fhs)) #pop-options #push-options "--max_fuel 2" val mt_hashes_lth_inv_log_next: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> j:nat{j > 1} -> fhs:hashess #hsz {S.length fhs = log2c j} -> Lemma (requires mt_hashes_lth_inv_log #hsz j fhs) (ensures S.length (S.head fhs) == j /\ S.length (S.head (S.tail fhs)) == j / 2) let mt_hashes_lth_inv_log_next #_ #_ _ _ = () val mt_hashes_inv_log: #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} -> GTot Type0 (decreases j) let rec mt_hashes_inv_log #hsz #f j fhs = if j <= 1 then true else (mt_hashes_next_rel #_ #f j (S.index fhs 0) (S.index fhs 1) /\ mt_hashes_inv_log #_ #f (j / 2) (S.tail fhs)) val mt_hashes_lth_inv_log_converted_: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> lv:nat{lv <= 32} -> j:nat{j < pow2 (32 - lv)} -> fhs:hashess #hsz {S.length fhs = 32} -> Lemma (requires mt_hashes_lth_inv #hsz lv j fhs) (ensures (log2c_bound j (32 - lv); mt_hashes_lth_inv_log #hsz j (S.slice fhs lv (lv + log2c j)))) (decreases j) let rec mt_hashes_lth_inv_log_converted_ #_ #f lv j fhs = if j = 0 then () else (log2c_bound (j / 2) (32 - (lv + 1)); mt_hashes_lth_inv_log_converted_ #_ #f (lv + 1) (j / 2) fhs) val mt_hashes_lth_inv_log_converted: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> j:nat{j < pow2 32} -> fhs:hashess #hsz {S.length fhs = 32} -> Lemma (requires mt_hashes_lth_inv #hsz 0 j fhs) (ensures (log2c_bound j 32; mt_hashes_lth_inv_log #hsz j (S.slice fhs 0 (log2c j)))) let mt_hashes_lth_inv_log_converted #_ #f j fhs = mt_hashes_lth_inv_log_converted_ #_ #f 0 j fhs val mt_hashes_inv_log_converted_: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> lv:nat{lv <= 32} -> j:nat{j > 0 && j < pow2 (32 - lv)} -> fhs:hashess #hsz {S.length fhs = 32 /\ mt_hashes_lth_inv #hsz lv j fhs} -> Lemma (requires mt_hashes_inv #_ #f lv j fhs) (ensures (log2c_bound j (32 - lv); mt_hashes_lth_inv_log_converted_ #_ #f lv j fhs; mt_hashes_inv_log #_ #f j (S.slice fhs lv (lv + log2c j)))) (decreases j) #pop-options #push-options "--z3rlimit 100 --initial_fuel 2 --max_fuel 2" let rec mt_hashes_inv_log_converted_ #_ #f lv j fhs = if j = 1 then () else (log2c_bound (j / 2) (32 - (lv + 1)); mt_hashes_lth_inv_log_converted_ #_ #f (lv + 1) (j / 2) fhs; mt_hashes_inv_log_converted_ #_ #f (lv + 1) (j / 2) fhs) #pop-options val mt_hashes_inv_log_converted: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> j:nat{j > 0 && j < pow2 32} -> fhs:hashess #hsz {S.length fhs = 32 /\ mt_hashes_lth_inv #hsz 0 j fhs} -> Lemma (requires mt_hashes_inv #_ #f 0 j fhs) (ensures (log2c_bound j 32; mt_hashes_lth_inv_log_converted_ #_ #f 0 j fhs; mt_hashes_inv_log #_ #f j (S.slice fhs 0 (log2c j)))) let mt_hashes_inv_log_converted #_ #f j fhs = mt_hashes_inv_log_converted_ #_ #f 0 j fhs val hash_seq_lift: #hsz:pos -> hs:hashes #hsz -> GTot (shs:MTS.hashes #hsz {S.length shs = S.length hs}) (decreases (S.length hs)) let rec hash_seq_lift #hsz hs = if S.length hs = 0 then S.empty else S.cons (MTS.HRaw (S.head hs)) (hash_seq_lift #hsz (S.tail hs)) #push-options "--z3rlimit 50 --initial_fuel 2 --max_fuel 2" val hash_seq_lift_index: #hsz:pos -> hs:hashes #hsz -> Lemma (requires True) (ensures forall (i:nat{i < S.length hs}). S.index (hash_seq_lift #hsz hs) i == MTS.HRaw (S.index hs i)) (decreases (S.length hs)) let rec hash_seq_lift_index #hsz hs = if S.length hs = 0 then () else hash_seq_lift_index #hsz (S.tail hs) #pop-options val create_pads: #hsz:pos -> len:nat -> GTot (pads:MTS.hashes #hsz {S.length pads = len}) let create_pads #hsz len = S.create len (MTS.HPad #hsz) val hash_seq_spec: #hsz:pos -> hs:hashes #hsz {S.length hs > 0} -> GTot (MTS.merkle_tree #hsz (log2c (S.length hs))) let hash_seq_spec #hsz hs = S.append (hash_seq_lift #hsz hs) (create_pads (pow2 (log2c (S.length hs)) - S.length hs)) val hash_seq_spec_index_raw: #hsz:pos -> hs:hashes #hsz {S.length hs > 0} -> i:nat{i < S.length hs} -> Lemma (S.index (hash_seq_spec #hsz hs) i == MTS.HRaw #hsz (S.index hs i)) let hash_seq_spec_index_raw #hsz hs i = hash_seq_lift_index #hsz hs // Now about recovering rightmost hashes #push-options "--z3rlimit 50 --initial_fuel 1 --max_fuel 1" val mt_hashes_next_rel_lift_even: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> j:nat{j > 1} -> hs:hashes #hsz {S.length hs = j} -> nhs:hashes #hsz {S.length nhs = j / 2} -> Lemma (requires j % 2 = 0 /\ mt_hashes_next_rel #_ #f j hs nhs) (ensures MTS.mt_next_rel #_ #f (log2c j) (hash_seq_spec #hsz hs) (hash_seq_spec #hsz nhs)) let mt_hashes_next_rel_lift_even #hsz #_ j hs nhs = hash_seq_lift_index #hsz hs; hash_seq_lift_index #hsz nhs val mt_hashes_next_rel_lift_odd: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> j:nat{j > 1} -> hs:hashes #hsz {S.length hs = j} -> nhs:hashes #hsz {S.length nhs = j / 2} -> Lemma (requires j % 2 = 1 /\ mt_hashes_next_rel #_ #f j hs nhs) (ensures MTS.mt_next_rel #_ #f (log2c j) (hash_seq_spec #hsz hs) (S.upd (hash_seq_spec #hsz nhs) (S.length nhs) (MTS.HRaw (S.last hs)))) let mt_hashes_next_rel_lift_odd #hsz #_ j hs nhs = log2c_div j; hash_seq_lift_index #hsz hs; hash_seq_lift_index #hsz nhs val mt_hashes_next_rel_next_even: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> j:nat{j > 1} -> hs:hashes #hsz {S.length hs = j} -> nhs:hashes #hsz {S.length nhs = j / 2} -> Lemma (requires j % 2 = 0 /\ mt_hashes_next_rel #_ #f j hs nhs) (ensures S.equal (hash_seq_spec #hsz nhs) (MTS.mt_next_lv #_ #f #(log2c j) (hash_seq_spec #hsz hs))) let mt_hashes_next_rel_next_even #hsz #f j hs nhs = log2c_div j; mt_hashes_next_rel_lift_even #_ #f j hs nhs; MTS.mt_next_rel_next_lv #_ #f (log2c j) (hash_seq_spec #hsz hs) (hash_seq_spec #hsz nhs) val hash_seq_spec_full: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> hs:hashes #hsz {S.length hs > 0} -> acc:hash #hsz -> actd:bool -> GTot (MTS.merkle_tree #hsz (log2c (S.length hs))) let hash_seq_spec_full #hsz #f hs acc actd = if actd then (S.upd (hash_seq_spec #hsz hs) (S.length hs) (MTS.HRaw acc)) else hash_seq_spec #hsz hs val hash_seq_spec_full_index_raw: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> hs:hashes #hsz {S.length hs > 0} -> acc:hash #hsz -> actd:bool -> i:nat{i < S.length hs} -> Lemma (S.index (hash_seq_spec_full #_ #f hs acc actd) i ==
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "MerkleTree.Spec.fst.checked", "MerkleTree.New.High.fst.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Ghost.fsti.checked", "FStar.Classical.fsti.checked" ], "interface_file": false, "source_file": "MerkleTree.New.High.Correct.Base.fst" }
[ { "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": 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": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
hs: MerkleTree.New.High.hashes{FStar.Seq.Base.length hs > 0} -> acc: MerkleTree.New.High.hash -> actd: Prims.bool -> i: Prims.nat{i < FStar.Seq.Base.length hs} -> FStar.Pervasives.Lemma (ensures FStar.Seq.Base.index (MerkleTree.New.High.Correct.Base.hash_seq_spec_full hs acc actd) i == MerkleTree.Spec.HRaw (FStar.Seq.Base.index hs i))
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "Prims.pos", "MerkleTree.Spec.hash_fun_t", "MerkleTree.New.High.hashes", "Prims.b2t", "Prims.op_GreaterThan", "FStar.Seq.Base.length", "MerkleTree.New.High.hash", "Prims.bool", "Prims.nat", "Prims.op_LessThan", "MerkleTree.New.High.Correct.Base.hash_seq_spec_index_raw", "Prims.unit" ]
[]
true
false
true
false
false
let hash_seq_spec_full_index_raw #hsz #_ hs acc actd i =
hash_seq_spec_index_raw #hsz hs i
false
MerkleTree.New.High.Correct.Base.fst
MerkleTree.New.High.Correct.Base.mt_hashes_inv_log
val mt_hashes_inv_log: #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} -> GTot Type0 (decreases j)
val mt_hashes_inv_log: #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} -> GTot Type0 (decreases j)
let rec mt_hashes_inv_log #hsz #f j fhs = if j <= 1 then true else (mt_hashes_next_rel #_ #f j (S.index fhs 0) (S.index fhs 1) /\ mt_hashes_inv_log #_ #f (j / 2) (S.tail fhs))
{ "file_name": "src/MerkleTree.New.High.Correct.Base.fst", "git_rev": "7d7bdc20f2033171e279c176b26e84f9069d23c6", "git_url": "https://github.com/hacl-star/merkle-tree.git", "project_name": "merkle-tree" }
{ "end_col": 52, "end_line": 347, "start_col": 0, "start_line": 344 }
module MerkleTree.New.High.Correct.Base open FStar.Classical open FStar.Ghost open FStar.Seq module S = FStar.Seq module MTS = MerkleTree.Spec open MerkleTree.New.High #set-options "--z3rlimit 40 --max_fuel 0 --max_ifuel 0" /// Sequence helpers val seq_prefix: #a:Type -> s1:S.seq a -> s2:S.seq a{S.length s1 <= S.length s2} -> GTot Type0 let seq_prefix #a s1 s2 = S.equal s1 (S.slice s2 0 (S.length s1)) val seq_head_cons: #a:Type -> x:a -> s:S.seq a -> Lemma (S.head (S.cons x s) == x) [SMTPat (S.cons x s)] let seq_head_cons #a x s = () val seq_tail_cons: #a:Type -> x:a -> s:S.seq a -> Lemma (S.equal (S.tail (S.cons x s)) s) [SMTPat (S.cons x s)] let seq_tail_cons #a x s = () /// Invariants and simulation relation of high-level Merkle tree design // Invariants of internal hashes val empty_hashes: (#hsz:pos) -> (len:nat) -> GTot (hs:hashess #hsz {S.length hs = len}) let empty_hashes #hsz len = S.create len S.empty val empty_hashes_head: #hsz:pos -> len:nat{len > 0} -> Lemma (S.head (empty_hashes #hsz len) == S.empty) let empty_hashes_head #_ _ = () val empty_hashes_tail: #hsz:pos -> len:nat{len > 0} -> Lemma (S.equal (S.tail (empty_hashes len)) (empty_hashes #hsz (len - 1))) let empty_hashes_tail #_ _ = () #push-options "--max_fuel 1" val mt_hashes_lth_inv: #hsz:pos -> lv:nat{lv <= 32} -> j:nat{j < pow2 (32 - lv)} -> fhs:hashess #hsz {S.length fhs = 32} -> GTot Type0 (decreases (32 - lv)) let rec mt_hashes_lth_inv #hsz lv j fhs = if lv = 32 then true else (S.length (S.index fhs lv) == j /\ mt_hashes_lth_inv (lv + 1) (j / 2) fhs) val mt_hashes_lth_inv_empty: #hsz:pos -> lv:nat{lv <= 32} -> Lemma (requires True) (ensures mt_hashes_lth_inv lv 0 (empty_hashes #hsz 32)) (decreases (32 - lv)) let rec mt_hashes_lth_inv_empty #hsz lv = if lv = 32 then () else mt_hashes_lth_inv_empty #hsz (lv + 1) val mt_hashes_next_rel: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> j:nat -> hs:hashes #hsz {S.length hs = j} -> nhs:hashes #hsz {S.length nhs = j / 2} -> GTot Type0 let mt_hashes_next_rel #hsz #f j hs nhs = forall (i:nat{i < j / 2}). S.index nhs i == f (S.index hs (op_Multiply 2 i)) (S.index hs (op_Multiply 2 i + 1)) #pop-options #push-options "--max_fuel 2" val mt_hashes_inv: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> lv:nat{lv < 32} -> j:nat{j < pow2 (32 - lv)} -> fhs:hashess #hsz {S.length fhs = 32 /\ mt_hashes_lth_inv lv j fhs} -> GTot Type0 (decreases (32 - lv)) let rec mt_hashes_inv #hsz #f lv j fhs = if lv = 31 then true else (mt_hashes_next_rel #_ #f j (S.index fhs lv) (S.index fhs (lv + 1)) /\ mt_hashes_inv #_ #f (lv + 1) (j / 2) fhs) val mt_hashes_inv_empty: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> lv:nat{lv < 32} -> Lemma (requires True) (ensures (mt_hashes_lth_inv_empty #hsz lv; mt_hashes_inv #hsz #f lv 0 (empty_hashes #hsz 32))) (decreases (32 - lv)) let rec mt_hashes_inv_empty #hsz #f lv = if lv = 31 then () else (mt_hashes_lth_inv_empty #hsz (lv + 1); mt_hashes_inv_empty #_ #f (lv + 1)) val mt_hashes_lth_inv_equiv: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> lv:nat{lv < 32} -> j:nat{j < pow2 (32 - lv)} -> fhs1:hashess{S.length fhs1 = 32} -> fhs2:hashess{S.length fhs2 = 32} -> Lemma (requires mt_hashes_lth_inv lv j fhs1 /\ S.equal (S.slice fhs1 lv 32) (S.slice fhs2 lv 32)) (ensures mt_hashes_lth_inv #hsz lv j fhs2) (decreases (32 - lv)) let rec mt_hashes_lth_inv_equiv #hsz #f lv j fhs1 fhs2 = if lv = 31 then () else (assert (S.index fhs1 lv == S.index fhs2 lv); mt_hashes_lth_inv_equiv #_ #f (lv + 1) (j / 2) fhs1 fhs2) #pop-options #push-options "--max_fuel 1" val mt_hashes_inv_equiv: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> lv:nat{lv < 32} -> j:nat{j < pow2 (32 - lv)} -> fhs1:hashess #hsz {S.length fhs1 = 32 /\ mt_hashes_lth_inv lv j fhs1} -> fhs2:hashess #hsz {S.length fhs2 = 32 /\ mt_hashes_lth_inv lv j fhs2} -> Lemma (requires mt_hashes_inv #_ #f lv j fhs1 /\ S.equal (S.slice fhs1 lv 32) (S.slice fhs2 lv 32)) (ensures mt_hashes_inv #_ #f lv j fhs2) (decreases (32 - lv)) let rec mt_hashes_inv_equiv #hsz #f lv j fhs1 fhs2 = if lv = 31 then () else (assert (S.index fhs1 lv == S.index fhs2 lv); assert (S.index fhs1 (lv + 1) == S.index fhs2 (lv + 1)); mt_hashes_inv_equiv #_ #f (lv + 1) (j / 2) fhs1 fhs2) val merge_hs: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> hs1:hashess #hsz -> hs2:hashess #hsz {S.length hs1 = S.length hs2} -> GTot (mhs:hashess #hsz {S.length mhs = S.length hs1}) (decreases (S.length hs1)) let rec merge_hs #hsz #f hs1 hs2 = if S.length hs1 = 0 then S.empty else (S.cons (S.append (S.head hs1) (S.head hs2)) (merge_hs #_ #f (S.tail hs1) (S.tail hs2))) val merge_hs_empty: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> len:nat -> Lemma (S.equal (merge_hs #_ #f (empty_hashes #hsz len) (empty_hashes #hsz len)) (empty_hashes #hsz len)) let rec merge_hs_empty #hsz #f len = if len = 0 then () else (empty_hashes_head #hsz len; empty_hashes_tail #hsz len; assert (S.equal (S.append #(hash #hsz) S.empty S.empty) (S.empty #(hash #hsz))); assert (S.equal (merge_hs #_ #f (empty_hashes len) (empty_hashes len)) (S.cons S.empty (merge_hs #_ #f (empty_hashes (len - 1)) (empty_hashes (len - 1))))); merge_hs_empty #_ #f (len - 1)) val merge_hs_index: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> hs1:hashess -> hs2:hashess{S.length hs1 = S.length hs2} -> i:nat{i < S.length hs1} -> Lemma (requires True) (ensures S.equal (S.index (merge_hs #_ #f hs1 hs2) i) (S.append (S.index hs1 i) (S.index hs2 i))) (decreases (S.length hs1)) [SMTPat (S.index (merge_hs #_ #f hs1 hs2) i)] let rec merge_hs_index #hsz #f hs1 hs2 i = if S.length hs1 = 0 then () else if i = 0 then () else merge_hs_index #_ #f (S.tail hs1) (S.tail hs2) (i - 1) val merge_hs_slice_equal: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> ahs1:hashess #hsz -> ahs2:hashess #hsz {S.length ahs1 = S.length ahs2} -> bhs1:hashess #hsz -> bhs2:hashess #hsz {S.length bhs1 = S.length bhs2} -> i:nat -> j:nat{i <= j && j <= S.length ahs1 && j <= S.length bhs1} -> Lemma (requires S.equal (S.slice ahs1 i j) (S.slice bhs1 i j) /\ S.equal (S.slice ahs2 i j) (S.slice bhs2 i j)) (ensures S.equal (S.slice (merge_hs #_ #f ahs1 ahs2) i j) (S.slice (merge_hs #_ #f bhs1 bhs2) i j)) (decreases (j - i)) let rec merge_hs_slice_equal #_ #f ahs1 ahs2 bhs1 bhs2 i j = if i = j then () else (assert (S.index ahs1 i == S.index bhs1 i); assert (S.index ahs2 i == S.index bhs2 i); merge_hs_slice_equal #_ #f ahs1 ahs2 bhs1 bhs2 (i + 1) j) val merge_hs_upd: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> hs1:hashess #hsz -> hs2:hashess #hsz {S.length hs1 = S.length hs2} -> i:nat{i < S.length hs1} -> v1:hashes #hsz -> v2:hashes #hsz -> Lemma (requires S.equal (S.append (S.index hs1 i) (S.index hs2 i)) (S.append v1 v2)) (ensures S.equal (merge_hs #_ #f hs1 hs2) (merge_hs #_ #f (S.upd hs1 i v1) (S.upd hs2 i v2))) (decreases i) let rec merge_hs_upd #_ #f hs1 hs2 i v1 v2 = if S.length hs1 = 0 then () else if i = 0 then () else merge_hs_upd #_ #f (S.tail hs1) (S.tail hs2) (i - 1) v1 v2 val mt_olds_inv: #hsz:pos -> lv:nat{lv <= 32} -> i:nat -> olds:hashess #hsz {S.length olds = 32} -> GTot Type0 (decreases (32 - lv)) let rec mt_olds_inv #hsz lv i olds = if lv = 32 then true else (let ofs = offset_of i in S.length (S.index olds lv) == ofs /\ mt_olds_inv #hsz (lv + 1) (i / 2) olds) val mt_olds_inv_equiv: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> lv:nat{lv <= 32} -> i:nat -> olds1:hashess #hsz {S.length olds1 = 32} -> olds2:hashess #hsz {S.length olds2 = 32} -> Lemma (requires mt_olds_inv #hsz lv i olds1 /\ S.equal (S.slice olds1 lv 32) (S.slice olds2 lv 32)) (ensures mt_olds_inv #hsz lv i olds2) (decreases (32 - lv)) let rec mt_olds_inv_equiv #hsz #f lv i olds1 olds2 = if lv = 32 then () else (assert (S.index olds1 lv == S.index olds2 lv); mt_olds_inv_equiv #_ #f (lv + 1) (i / 2) olds1 olds2) val mt_olds_hs_lth_inv_ok: #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 #hsz lv hs i j} -> Lemma (requires True) (ensures mt_hashes_lth_inv #hsz lv j (merge_hs #_ #f olds hs)) (decreases (32 - lv)) let rec mt_olds_hs_lth_inv_ok #hsz #f lv i j olds hs = if lv = 32 then () else (mt_olds_hs_lth_inv_ok #_ #f (lv + 1) (i / 2) (j / 2) olds hs) val mt_olds_hs_inv: #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 #hsz lv hs i j} -> GTot Type0 let mt_olds_hs_inv #hsz #f lv i j olds hs = mt_olds_hs_lth_inv_ok #_ #f lv i j olds hs; mt_hashes_inv #_ #f lv j (merge_hs #_ #f olds hs) // Relation between valid internal hashes (satisfying `mt_olds_hs_inv`) and // the spec. While giving such relation, all rightmost hashes are recovered. // Note that `MT?.rhs` after `construct_rhs` does NOT contain all rightmost // hashes; it has partial rightmost hashes that are enough to calculate // Merkle paths. val log2: n:nat{n > 0} -> GTot (c:nat{pow2 c <= n && n < pow2 (c+1)}) let rec log2 n = if n = 1 then 0 else 1 + log2 (n / 2) val log2_bound: n:nat{n > 0} -> c:nat{n < pow2 c} -> Lemma (log2 n <= c-1) let rec log2_bound n c = if n = 1 then () else log2_bound (n / 2) (c - 1) val log2_div: n:nat{n > 1} -> Lemma (log2 (n / 2) = log2 n - 1) let log2_div n = () val log2c: n:nat -> GTot (c:nat{c = 0 || (pow2 (c-1) <= n && n < pow2 c)}) let log2c n = if n = 0 then 0 else (log2 n + 1) val log2c_div: n:nat{n > 0} -> Lemma (log2c (n / 2) = log2c n - 1) let log2c_div n = () val log2c_bound: n:nat -> c:nat{n < pow2 c} -> Lemma (log2c n <= c) let rec log2c_bound n c = if n = 0 then () else log2c_bound (n / 2) (c - 1) val mt_hashes_lth_inv_log: #hsz:pos -> j:nat -> fhs:hashess #hsz {S.length fhs = log2c j} -> GTot Type0 (decreases j) let rec mt_hashes_lth_inv_log #hsz j fhs = if j = 0 then true else (S.length (S.head fhs) == j /\ mt_hashes_lth_inv_log #hsz (j / 2) (S.tail fhs)) #pop-options #push-options "--max_fuel 2" val mt_hashes_lth_inv_log_next: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> j:nat{j > 1} -> fhs:hashess #hsz {S.length fhs = log2c j} -> Lemma (requires mt_hashes_lth_inv_log #hsz j fhs) (ensures S.length (S.head fhs) == j /\ S.length (S.head (S.tail fhs)) == j / 2) let mt_hashes_lth_inv_log_next #_ #_ _ _ = () val mt_hashes_inv_log: #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} ->
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "MerkleTree.Spec.fst.checked", "MerkleTree.New.High.fst.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Ghost.fsti.checked", "FStar.Classical.fsti.checked" ], "interface_file": false, "source_file": "MerkleTree.New.High.Correct.Base.fst" }
[ { "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": 2, "initial_ifuel": 1, "max_fuel": 2, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 40, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
j: Prims.nat -> 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 } -> Prims.GTot Type0
Prims.GTot
[ "sometrivial", "" ]
[]
[ "Prims.pos", "MerkleTree.Spec.hash_fun_t", "Prims.nat", "MerkleTree.New.High.hashess", "Prims.l_and", "Prims.b2t", "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", "Prims.op_LessThanOrEqual", "Prims.bool", "MerkleTree.New.High.Correct.Base.mt_hashes_next_rel", "FStar.Seq.Base.index", "MerkleTree.New.High.Correct.Base.mt_hashes_inv_log", "Prims.op_Division", "FStar.Seq.Properties.tail" ]
[ "recursion" ]
false
false
false
false
true
let rec mt_hashes_inv_log #hsz #f j fhs =
if j <= 1 then true else (mt_hashes_next_rel #_ #f j (S.index fhs 0) (S.index fhs 1) /\ mt_hashes_inv_log #_ #f (j / 2) (S.tail fhs))
false
MerkleTree.New.High.Correct.Base.fst
MerkleTree.New.High.Correct.Base.hash_seq_lift_index
val hash_seq_lift_index: #hsz:pos -> hs:hashes #hsz -> Lemma (requires True) (ensures forall (i:nat{i < S.length hs}). S.index (hash_seq_lift #hsz hs) i == MTS.HRaw (S.index hs i)) (decreases (S.length hs))
val hash_seq_lift_index: #hsz:pos -> hs:hashes #hsz -> Lemma (requires True) (ensures forall (i:nat{i < S.length hs}). S.index (hash_seq_lift #hsz hs) i == MTS.HRaw (S.index hs i)) (decreases (S.length hs))
let rec hash_seq_lift_index #hsz hs = if S.length hs = 0 then () else hash_seq_lift_index #hsz (S.tail hs)
{ "file_name": "src/MerkleTree.New.High.Correct.Base.fst", "git_rev": "7d7bdc20f2033171e279c176b26e84f9069d23c6", "git_url": "https://github.com/hacl-star/merkle-tree.git", "project_name": "merkle-tree" }
{ "end_col": 43, "end_line": 423, "start_col": 0, "start_line": 421 }
module MerkleTree.New.High.Correct.Base open FStar.Classical open FStar.Ghost open FStar.Seq module S = FStar.Seq module MTS = MerkleTree.Spec open MerkleTree.New.High #set-options "--z3rlimit 40 --max_fuel 0 --max_ifuel 0" /// Sequence helpers val seq_prefix: #a:Type -> s1:S.seq a -> s2:S.seq a{S.length s1 <= S.length s2} -> GTot Type0 let seq_prefix #a s1 s2 = S.equal s1 (S.slice s2 0 (S.length s1)) val seq_head_cons: #a:Type -> x:a -> s:S.seq a -> Lemma (S.head (S.cons x s) == x) [SMTPat (S.cons x s)] let seq_head_cons #a x s = () val seq_tail_cons: #a:Type -> x:a -> s:S.seq a -> Lemma (S.equal (S.tail (S.cons x s)) s) [SMTPat (S.cons x s)] let seq_tail_cons #a x s = () /// Invariants and simulation relation of high-level Merkle tree design // Invariants of internal hashes val empty_hashes: (#hsz:pos) -> (len:nat) -> GTot (hs:hashess #hsz {S.length hs = len}) let empty_hashes #hsz len = S.create len S.empty val empty_hashes_head: #hsz:pos -> len:nat{len > 0} -> Lemma (S.head (empty_hashes #hsz len) == S.empty) let empty_hashes_head #_ _ = () val empty_hashes_tail: #hsz:pos -> len:nat{len > 0} -> Lemma (S.equal (S.tail (empty_hashes len)) (empty_hashes #hsz (len - 1))) let empty_hashes_tail #_ _ = () #push-options "--max_fuel 1" val mt_hashes_lth_inv: #hsz:pos -> lv:nat{lv <= 32} -> j:nat{j < pow2 (32 - lv)} -> fhs:hashess #hsz {S.length fhs = 32} -> GTot Type0 (decreases (32 - lv)) let rec mt_hashes_lth_inv #hsz lv j fhs = if lv = 32 then true else (S.length (S.index fhs lv) == j /\ mt_hashes_lth_inv (lv + 1) (j / 2) fhs) val mt_hashes_lth_inv_empty: #hsz:pos -> lv:nat{lv <= 32} -> Lemma (requires True) (ensures mt_hashes_lth_inv lv 0 (empty_hashes #hsz 32)) (decreases (32 - lv)) let rec mt_hashes_lth_inv_empty #hsz lv = if lv = 32 then () else mt_hashes_lth_inv_empty #hsz (lv + 1) val mt_hashes_next_rel: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> j:nat -> hs:hashes #hsz {S.length hs = j} -> nhs:hashes #hsz {S.length nhs = j / 2} -> GTot Type0 let mt_hashes_next_rel #hsz #f j hs nhs = forall (i:nat{i < j / 2}). S.index nhs i == f (S.index hs (op_Multiply 2 i)) (S.index hs (op_Multiply 2 i + 1)) #pop-options #push-options "--max_fuel 2" val mt_hashes_inv: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> lv:nat{lv < 32} -> j:nat{j < pow2 (32 - lv)} -> fhs:hashess #hsz {S.length fhs = 32 /\ mt_hashes_lth_inv lv j fhs} -> GTot Type0 (decreases (32 - lv)) let rec mt_hashes_inv #hsz #f lv j fhs = if lv = 31 then true else (mt_hashes_next_rel #_ #f j (S.index fhs lv) (S.index fhs (lv + 1)) /\ mt_hashes_inv #_ #f (lv + 1) (j / 2) fhs) val mt_hashes_inv_empty: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> lv:nat{lv < 32} -> Lemma (requires True) (ensures (mt_hashes_lth_inv_empty #hsz lv; mt_hashes_inv #hsz #f lv 0 (empty_hashes #hsz 32))) (decreases (32 - lv)) let rec mt_hashes_inv_empty #hsz #f lv = if lv = 31 then () else (mt_hashes_lth_inv_empty #hsz (lv + 1); mt_hashes_inv_empty #_ #f (lv + 1)) val mt_hashes_lth_inv_equiv: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> lv:nat{lv < 32} -> j:nat{j < pow2 (32 - lv)} -> fhs1:hashess{S.length fhs1 = 32} -> fhs2:hashess{S.length fhs2 = 32} -> Lemma (requires mt_hashes_lth_inv lv j fhs1 /\ S.equal (S.slice fhs1 lv 32) (S.slice fhs2 lv 32)) (ensures mt_hashes_lth_inv #hsz lv j fhs2) (decreases (32 - lv)) let rec mt_hashes_lth_inv_equiv #hsz #f lv j fhs1 fhs2 = if lv = 31 then () else (assert (S.index fhs1 lv == S.index fhs2 lv); mt_hashes_lth_inv_equiv #_ #f (lv + 1) (j / 2) fhs1 fhs2) #pop-options #push-options "--max_fuel 1" val mt_hashes_inv_equiv: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> lv:nat{lv < 32} -> j:nat{j < pow2 (32 - lv)} -> fhs1:hashess #hsz {S.length fhs1 = 32 /\ mt_hashes_lth_inv lv j fhs1} -> fhs2:hashess #hsz {S.length fhs2 = 32 /\ mt_hashes_lth_inv lv j fhs2} -> Lemma (requires mt_hashes_inv #_ #f lv j fhs1 /\ S.equal (S.slice fhs1 lv 32) (S.slice fhs2 lv 32)) (ensures mt_hashes_inv #_ #f lv j fhs2) (decreases (32 - lv)) let rec mt_hashes_inv_equiv #hsz #f lv j fhs1 fhs2 = if lv = 31 then () else (assert (S.index fhs1 lv == S.index fhs2 lv); assert (S.index fhs1 (lv + 1) == S.index fhs2 (lv + 1)); mt_hashes_inv_equiv #_ #f (lv + 1) (j / 2) fhs1 fhs2) val merge_hs: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> hs1:hashess #hsz -> hs2:hashess #hsz {S.length hs1 = S.length hs2} -> GTot (mhs:hashess #hsz {S.length mhs = S.length hs1}) (decreases (S.length hs1)) let rec merge_hs #hsz #f hs1 hs2 = if S.length hs1 = 0 then S.empty else (S.cons (S.append (S.head hs1) (S.head hs2)) (merge_hs #_ #f (S.tail hs1) (S.tail hs2))) val merge_hs_empty: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> len:nat -> Lemma (S.equal (merge_hs #_ #f (empty_hashes #hsz len) (empty_hashes #hsz len)) (empty_hashes #hsz len)) let rec merge_hs_empty #hsz #f len = if len = 0 then () else (empty_hashes_head #hsz len; empty_hashes_tail #hsz len; assert (S.equal (S.append #(hash #hsz) S.empty S.empty) (S.empty #(hash #hsz))); assert (S.equal (merge_hs #_ #f (empty_hashes len) (empty_hashes len)) (S.cons S.empty (merge_hs #_ #f (empty_hashes (len - 1)) (empty_hashes (len - 1))))); merge_hs_empty #_ #f (len - 1)) val merge_hs_index: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> hs1:hashess -> hs2:hashess{S.length hs1 = S.length hs2} -> i:nat{i < S.length hs1} -> Lemma (requires True) (ensures S.equal (S.index (merge_hs #_ #f hs1 hs2) i) (S.append (S.index hs1 i) (S.index hs2 i))) (decreases (S.length hs1)) [SMTPat (S.index (merge_hs #_ #f hs1 hs2) i)] let rec merge_hs_index #hsz #f hs1 hs2 i = if S.length hs1 = 0 then () else if i = 0 then () else merge_hs_index #_ #f (S.tail hs1) (S.tail hs2) (i - 1) val merge_hs_slice_equal: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> ahs1:hashess #hsz -> ahs2:hashess #hsz {S.length ahs1 = S.length ahs2} -> bhs1:hashess #hsz -> bhs2:hashess #hsz {S.length bhs1 = S.length bhs2} -> i:nat -> j:nat{i <= j && j <= S.length ahs1 && j <= S.length bhs1} -> Lemma (requires S.equal (S.slice ahs1 i j) (S.slice bhs1 i j) /\ S.equal (S.slice ahs2 i j) (S.slice bhs2 i j)) (ensures S.equal (S.slice (merge_hs #_ #f ahs1 ahs2) i j) (S.slice (merge_hs #_ #f bhs1 bhs2) i j)) (decreases (j - i)) let rec merge_hs_slice_equal #_ #f ahs1 ahs2 bhs1 bhs2 i j = if i = j then () else (assert (S.index ahs1 i == S.index bhs1 i); assert (S.index ahs2 i == S.index bhs2 i); merge_hs_slice_equal #_ #f ahs1 ahs2 bhs1 bhs2 (i + 1) j) val merge_hs_upd: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> hs1:hashess #hsz -> hs2:hashess #hsz {S.length hs1 = S.length hs2} -> i:nat{i < S.length hs1} -> v1:hashes #hsz -> v2:hashes #hsz -> Lemma (requires S.equal (S.append (S.index hs1 i) (S.index hs2 i)) (S.append v1 v2)) (ensures S.equal (merge_hs #_ #f hs1 hs2) (merge_hs #_ #f (S.upd hs1 i v1) (S.upd hs2 i v2))) (decreases i) let rec merge_hs_upd #_ #f hs1 hs2 i v1 v2 = if S.length hs1 = 0 then () else if i = 0 then () else merge_hs_upd #_ #f (S.tail hs1) (S.tail hs2) (i - 1) v1 v2 val mt_olds_inv: #hsz:pos -> lv:nat{lv <= 32} -> i:nat -> olds:hashess #hsz {S.length olds = 32} -> GTot Type0 (decreases (32 - lv)) let rec mt_olds_inv #hsz lv i olds = if lv = 32 then true else (let ofs = offset_of i in S.length (S.index olds lv) == ofs /\ mt_olds_inv #hsz (lv + 1) (i / 2) olds) val mt_olds_inv_equiv: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> lv:nat{lv <= 32} -> i:nat -> olds1:hashess #hsz {S.length olds1 = 32} -> olds2:hashess #hsz {S.length olds2 = 32} -> Lemma (requires mt_olds_inv #hsz lv i olds1 /\ S.equal (S.slice olds1 lv 32) (S.slice olds2 lv 32)) (ensures mt_olds_inv #hsz lv i olds2) (decreases (32 - lv)) let rec mt_olds_inv_equiv #hsz #f lv i olds1 olds2 = if lv = 32 then () else (assert (S.index olds1 lv == S.index olds2 lv); mt_olds_inv_equiv #_ #f (lv + 1) (i / 2) olds1 olds2) val mt_olds_hs_lth_inv_ok: #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 #hsz lv hs i j} -> Lemma (requires True) (ensures mt_hashes_lth_inv #hsz lv j (merge_hs #_ #f olds hs)) (decreases (32 - lv)) let rec mt_olds_hs_lth_inv_ok #hsz #f lv i j olds hs = if lv = 32 then () else (mt_olds_hs_lth_inv_ok #_ #f (lv + 1) (i / 2) (j / 2) olds hs) val mt_olds_hs_inv: #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 #hsz lv hs i j} -> GTot Type0 let mt_olds_hs_inv #hsz #f lv i j olds hs = mt_olds_hs_lth_inv_ok #_ #f lv i j olds hs; mt_hashes_inv #_ #f lv j (merge_hs #_ #f olds hs) // Relation between valid internal hashes (satisfying `mt_olds_hs_inv`) and // the spec. While giving such relation, all rightmost hashes are recovered. // Note that `MT?.rhs` after `construct_rhs` does NOT contain all rightmost // hashes; it has partial rightmost hashes that are enough to calculate // Merkle paths. val log2: n:nat{n > 0} -> GTot (c:nat{pow2 c <= n && n < pow2 (c+1)}) let rec log2 n = if n = 1 then 0 else 1 + log2 (n / 2) val log2_bound: n:nat{n > 0} -> c:nat{n < pow2 c} -> Lemma (log2 n <= c-1) let rec log2_bound n c = if n = 1 then () else log2_bound (n / 2) (c - 1) val log2_div: n:nat{n > 1} -> Lemma (log2 (n / 2) = log2 n - 1) let log2_div n = () val log2c: n:nat -> GTot (c:nat{c = 0 || (pow2 (c-1) <= n && n < pow2 c)}) let log2c n = if n = 0 then 0 else (log2 n + 1) val log2c_div: n:nat{n > 0} -> Lemma (log2c (n / 2) = log2c n - 1) let log2c_div n = () val log2c_bound: n:nat -> c:nat{n < pow2 c} -> Lemma (log2c n <= c) let rec log2c_bound n c = if n = 0 then () else log2c_bound (n / 2) (c - 1) val mt_hashes_lth_inv_log: #hsz:pos -> j:nat -> fhs:hashess #hsz {S.length fhs = log2c j} -> GTot Type0 (decreases j) let rec mt_hashes_lth_inv_log #hsz j fhs = if j = 0 then true else (S.length (S.head fhs) == j /\ mt_hashes_lth_inv_log #hsz (j / 2) (S.tail fhs)) #pop-options #push-options "--max_fuel 2" val mt_hashes_lth_inv_log_next: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> j:nat{j > 1} -> fhs:hashess #hsz {S.length fhs = log2c j} -> Lemma (requires mt_hashes_lth_inv_log #hsz j fhs) (ensures S.length (S.head fhs) == j /\ S.length (S.head (S.tail fhs)) == j / 2) let mt_hashes_lth_inv_log_next #_ #_ _ _ = () val mt_hashes_inv_log: #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} -> GTot Type0 (decreases j) let rec mt_hashes_inv_log #hsz #f j fhs = if j <= 1 then true else (mt_hashes_next_rel #_ #f j (S.index fhs 0) (S.index fhs 1) /\ mt_hashes_inv_log #_ #f (j / 2) (S.tail fhs)) val mt_hashes_lth_inv_log_converted_: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> lv:nat{lv <= 32} -> j:nat{j < pow2 (32 - lv)} -> fhs:hashess #hsz {S.length fhs = 32} -> Lemma (requires mt_hashes_lth_inv #hsz lv j fhs) (ensures (log2c_bound j (32 - lv); mt_hashes_lth_inv_log #hsz j (S.slice fhs lv (lv + log2c j)))) (decreases j) let rec mt_hashes_lth_inv_log_converted_ #_ #f lv j fhs = if j = 0 then () else (log2c_bound (j / 2) (32 - (lv + 1)); mt_hashes_lth_inv_log_converted_ #_ #f (lv + 1) (j / 2) fhs) val mt_hashes_lth_inv_log_converted: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> j:nat{j < pow2 32} -> fhs:hashess #hsz {S.length fhs = 32} -> Lemma (requires mt_hashes_lth_inv #hsz 0 j fhs) (ensures (log2c_bound j 32; mt_hashes_lth_inv_log #hsz j (S.slice fhs 0 (log2c j)))) let mt_hashes_lth_inv_log_converted #_ #f j fhs = mt_hashes_lth_inv_log_converted_ #_ #f 0 j fhs val mt_hashes_inv_log_converted_: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> lv:nat{lv <= 32} -> j:nat{j > 0 && j < pow2 (32 - lv)} -> fhs:hashess #hsz {S.length fhs = 32 /\ mt_hashes_lth_inv #hsz lv j fhs} -> Lemma (requires mt_hashes_inv #_ #f lv j fhs) (ensures (log2c_bound j (32 - lv); mt_hashes_lth_inv_log_converted_ #_ #f lv j fhs; mt_hashes_inv_log #_ #f j (S.slice fhs lv (lv + log2c j)))) (decreases j) #pop-options #push-options "--z3rlimit 100 --initial_fuel 2 --max_fuel 2" let rec mt_hashes_inv_log_converted_ #_ #f lv j fhs = if j = 1 then () else (log2c_bound (j / 2) (32 - (lv + 1)); mt_hashes_lth_inv_log_converted_ #_ #f (lv + 1) (j / 2) fhs; mt_hashes_inv_log_converted_ #_ #f (lv + 1) (j / 2) fhs) #pop-options val mt_hashes_inv_log_converted: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> j:nat{j > 0 && j < pow2 32} -> fhs:hashess #hsz {S.length fhs = 32 /\ mt_hashes_lth_inv #hsz 0 j fhs} -> Lemma (requires mt_hashes_inv #_ #f 0 j fhs) (ensures (log2c_bound j 32; mt_hashes_lth_inv_log_converted_ #_ #f 0 j fhs; mt_hashes_inv_log #_ #f j (S.slice fhs 0 (log2c j)))) let mt_hashes_inv_log_converted #_ #f j fhs = mt_hashes_inv_log_converted_ #_ #f 0 j fhs val hash_seq_lift: #hsz:pos -> hs:hashes #hsz -> GTot (shs:MTS.hashes #hsz {S.length shs = S.length hs}) (decreases (S.length hs)) let rec hash_seq_lift #hsz hs = if S.length hs = 0 then S.empty else S.cons (MTS.HRaw (S.head hs)) (hash_seq_lift #hsz (S.tail hs)) #push-options "--z3rlimit 50 --initial_fuel 2 --max_fuel 2" val hash_seq_lift_index: #hsz:pos -> hs:hashes #hsz -> Lemma (requires True) (ensures forall (i:nat{i < S.length hs}). S.index (hash_seq_lift #hsz hs) i == MTS.HRaw (S.index hs i))
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "MerkleTree.Spec.fst.checked", "MerkleTree.New.High.fst.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Ghost.fsti.checked", "FStar.Classical.fsti.checked" ], "interface_file": false, "source_file": "MerkleTree.New.High.Correct.Base.fst" }
[ { "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": 2, "initial_ifuel": 1, "max_fuel": 2, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
hs: MerkleTree.New.High.hashes -> FStar.Pervasives.Lemma (ensures forall (i: Prims.nat{i < FStar.Seq.Base.length hs}). FStar.Seq.Base.index (MerkleTree.New.High.Correct.Base.hash_seq_lift hs) i == MerkleTree.Spec.HRaw (FStar.Seq.Base.index hs i)) (decreases FStar.Seq.Base.length hs)
FStar.Pervasives.Lemma
[ "lemma", "" ]
[]
[ "Prims.pos", "MerkleTree.New.High.hashes", "Prims.op_Equality", "Prims.int", "FStar.Seq.Base.length", "MerkleTree.New.High.hash", "Prims.bool", "MerkleTree.New.High.Correct.Base.hash_seq_lift_index", "FStar.Seq.Properties.tail", "Prims.unit" ]
[ "recursion" ]
false
false
true
false
false
let rec hash_seq_lift_index #hsz hs =
if S.length hs = 0 then () else hash_seq_lift_index #hsz (S.tail hs)
false
MerkleTree.New.High.Correct.Base.fst
MerkleTree.New.High.Correct.Base.mt_base
val mt_base: #hsz:pos -> mt:merkle_tree #hsz {mt_wf_elts mt} -> olds:hashess #hsz {S.length olds = 32 /\ mt_olds_inv #hsz 0 (MT?.i mt) olds} -> GTot (bhs:hashes #hsz {S.length bhs = MT?.j mt})
val mt_base: #hsz:pos -> mt:merkle_tree #hsz {mt_wf_elts mt} -> olds:hashess #hsz {S.length olds = 32 /\ mt_olds_inv #hsz 0 (MT?.i mt) olds} -> GTot (bhs:hashes #hsz {S.length bhs = MT?.j mt})
let mt_base #hsz mt olds = S.head (merge_hs #hsz #(MT?.hash_fun mt) olds (MT?.hs mt))
{ "file_name": "src/MerkleTree.New.High.Correct.Base.fst", "git_rev": "7d7bdc20f2033171e279c176b26e84f9069d23c6", "git_url": "https://github.com/hacl-star/merkle-tree.git", "project_name": "merkle-tree" }
{ "end_col": 60, "end_line": 630, "start_col": 0, "start_line": 629 }
module MerkleTree.New.High.Correct.Base open FStar.Classical open FStar.Ghost open FStar.Seq module S = FStar.Seq module MTS = MerkleTree.Spec open MerkleTree.New.High #set-options "--z3rlimit 40 --max_fuel 0 --max_ifuel 0" /// Sequence helpers val seq_prefix: #a:Type -> s1:S.seq a -> s2:S.seq a{S.length s1 <= S.length s2} -> GTot Type0 let seq_prefix #a s1 s2 = S.equal s1 (S.slice s2 0 (S.length s1)) val seq_head_cons: #a:Type -> x:a -> s:S.seq a -> Lemma (S.head (S.cons x s) == x) [SMTPat (S.cons x s)] let seq_head_cons #a x s = () val seq_tail_cons: #a:Type -> x:a -> s:S.seq a -> Lemma (S.equal (S.tail (S.cons x s)) s) [SMTPat (S.cons x s)] let seq_tail_cons #a x s = () /// Invariants and simulation relation of high-level Merkle tree design // Invariants of internal hashes val empty_hashes: (#hsz:pos) -> (len:nat) -> GTot (hs:hashess #hsz {S.length hs = len}) let empty_hashes #hsz len = S.create len S.empty val empty_hashes_head: #hsz:pos -> len:nat{len > 0} -> Lemma (S.head (empty_hashes #hsz len) == S.empty) let empty_hashes_head #_ _ = () val empty_hashes_tail: #hsz:pos -> len:nat{len > 0} -> Lemma (S.equal (S.tail (empty_hashes len)) (empty_hashes #hsz (len - 1))) let empty_hashes_tail #_ _ = () #push-options "--max_fuel 1" val mt_hashes_lth_inv: #hsz:pos -> lv:nat{lv <= 32} -> j:nat{j < pow2 (32 - lv)} -> fhs:hashess #hsz {S.length fhs = 32} -> GTot Type0 (decreases (32 - lv)) let rec mt_hashes_lth_inv #hsz lv j fhs = if lv = 32 then true else (S.length (S.index fhs lv) == j /\ mt_hashes_lth_inv (lv + 1) (j / 2) fhs) val mt_hashes_lth_inv_empty: #hsz:pos -> lv:nat{lv <= 32} -> Lemma (requires True) (ensures mt_hashes_lth_inv lv 0 (empty_hashes #hsz 32)) (decreases (32 - lv)) let rec mt_hashes_lth_inv_empty #hsz lv = if lv = 32 then () else mt_hashes_lth_inv_empty #hsz (lv + 1) val mt_hashes_next_rel: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> j:nat -> hs:hashes #hsz {S.length hs = j} -> nhs:hashes #hsz {S.length nhs = j / 2} -> GTot Type0 let mt_hashes_next_rel #hsz #f j hs nhs = forall (i:nat{i < j / 2}). S.index nhs i == f (S.index hs (op_Multiply 2 i)) (S.index hs (op_Multiply 2 i + 1)) #pop-options #push-options "--max_fuel 2" val mt_hashes_inv: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> lv:nat{lv < 32} -> j:nat{j < pow2 (32 - lv)} -> fhs:hashess #hsz {S.length fhs = 32 /\ mt_hashes_lth_inv lv j fhs} -> GTot Type0 (decreases (32 - lv)) let rec mt_hashes_inv #hsz #f lv j fhs = if lv = 31 then true else (mt_hashes_next_rel #_ #f j (S.index fhs lv) (S.index fhs (lv + 1)) /\ mt_hashes_inv #_ #f (lv + 1) (j / 2) fhs) val mt_hashes_inv_empty: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> lv:nat{lv < 32} -> Lemma (requires True) (ensures (mt_hashes_lth_inv_empty #hsz lv; mt_hashes_inv #hsz #f lv 0 (empty_hashes #hsz 32))) (decreases (32 - lv)) let rec mt_hashes_inv_empty #hsz #f lv = if lv = 31 then () else (mt_hashes_lth_inv_empty #hsz (lv + 1); mt_hashes_inv_empty #_ #f (lv + 1)) val mt_hashes_lth_inv_equiv: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> lv:nat{lv < 32} -> j:nat{j < pow2 (32 - lv)} -> fhs1:hashess{S.length fhs1 = 32} -> fhs2:hashess{S.length fhs2 = 32} -> Lemma (requires mt_hashes_lth_inv lv j fhs1 /\ S.equal (S.slice fhs1 lv 32) (S.slice fhs2 lv 32)) (ensures mt_hashes_lth_inv #hsz lv j fhs2) (decreases (32 - lv)) let rec mt_hashes_lth_inv_equiv #hsz #f lv j fhs1 fhs2 = if lv = 31 then () else (assert (S.index fhs1 lv == S.index fhs2 lv); mt_hashes_lth_inv_equiv #_ #f (lv + 1) (j / 2) fhs1 fhs2) #pop-options #push-options "--max_fuel 1" val mt_hashes_inv_equiv: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> lv:nat{lv < 32} -> j:nat{j < pow2 (32 - lv)} -> fhs1:hashess #hsz {S.length fhs1 = 32 /\ mt_hashes_lth_inv lv j fhs1} -> fhs2:hashess #hsz {S.length fhs2 = 32 /\ mt_hashes_lth_inv lv j fhs2} -> Lemma (requires mt_hashes_inv #_ #f lv j fhs1 /\ S.equal (S.slice fhs1 lv 32) (S.slice fhs2 lv 32)) (ensures mt_hashes_inv #_ #f lv j fhs2) (decreases (32 - lv)) let rec mt_hashes_inv_equiv #hsz #f lv j fhs1 fhs2 = if lv = 31 then () else (assert (S.index fhs1 lv == S.index fhs2 lv); assert (S.index fhs1 (lv + 1) == S.index fhs2 (lv + 1)); mt_hashes_inv_equiv #_ #f (lv + 1) (j / 2) fhs1 fhs2) val merge_hs: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> hs1:hashess #hsz -> hs2:hashess #hsz {S.length hs1 = S.length hs2} -> GTot (mhs:hashess #hsz {S.length mhs = S.length hs1}) (decreases (S.length hs1)) let rec merge_hs #hsz #f hs1 hs2 = if S.length hs1 = 0 then S.empty else (S.cons (S.append (S.head hs1) (S.head hs2)) (merge_hs #_ #f (S.tail hs1) (S.tail hs2))) val merge_hs_empty: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> len:nat -> Lemma (S.equal (merge_hs #_ #f (empty_hashes #hsz len) (empty_hashes #hsz len)) (empty_hashes #hsz len)) let rec merge_hs_empty #hsz #f len = if len = 0 then () else (empty_hashes_head #hsz len; empty_hashes_tail #hsz len; assert (S.equal (S.append #(hash #hsz) S.empty S.empty) (S.empty #(hash #hsz))); assert (S.equal (merge_hs #_ #f (empty_hashes len) (empty_hashes len)) (S.cons S.empty (merge_hs #_ #f (empty_hashes (len - 1)) (empty_hashes (len - 1))))); merge_hs_empty #_ #f (len - 1)) val merge_hs_index: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> hs1:hashess -> hs2:hashess{S.length hs1 = S.length hs2} -> i:nat{i < S.length hs1} -> Lemma (requires True) (ensures S.equal (S.index (merge_hs #_ #f hs1 hs2) i) (S.append (S.index hs1 i) (S.index hs2 i))) (decreases (S.length hs1)) [SMTPat (S.index (merge_hs #_ #f hs1 hs2) i)] let rec merge_hs_index #hsz #f hs1 hs2 i = if S.length hs1 = 0 then () else if i = 0 then () else merge_hs_index #_ #f (S.tail hs1) (S.tail hs2) (i - 1) val merge_hs_slice_equal: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> ahs1:hashess #hsz -> ahs2:hashess #hsz {S.length ahs1 = S.length ahs2} -> bhs1:hashess #hsz -> bhs2:hashess #hsz {S.length bhs1 = S.length bhs2} -> i:nat -> j:nat{i <= j && j <= S.length ahs1 && j <= S.length bhs1} -> Lemma (requires S.equal (S.slice ahs1 i j) (S.slice bhs1 i j) /\ S.equal (S.slice ahs2 i j) (S.slice bhs2 i j)) (ensures S.equal (S.slice (merge_hs #_ #f ahs1 ahs2) i j) (S.slice (merge_hs #_ #f bhs1 bhs2) i j)) (decreases (j - i)) let rec merge_hs_slice_equal #_ #f ahs1 ahs2 bhs1 bhs2 i j = if i = j then () else (assert (S.index ahs1 i == S.index bhs1 i); assert (S.index ahs2 i == S.index bhs2 i); merge_hs_slice_equal #_ #f ahs1 ahs2 bhs1 bhs2 (i + 1) j) val merge_hs_upd: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> hs1:hashess #hsz -> hs2:hashess #hsz {S.length hs1 = S.length hs2} -> i:nat{i < S.length hs1} -> v1:hashes #hsz -> v2:hashes #hsz -> Lemma (requires S.equal (S.append (S.index hs1 i) (S.index hs2 i)) (S.append v1 v2)) (ensures S.equal (merge_hs #_ #f hs1 hs2) (merge_hs #_ #f (S.upd hs1 i v1) (S.upd hs2 i v2))) (decreases i) let rec merge_hs_upd #_ #f hs1 hs2 i v1 v2 = if S.length hs1 = 0 then () else if i = 0 then () else merge_hs_upd #_ #f (S.tail hs1) (S.tail hs2) (i - 1) v1 v2 val mt_olds_inv: #hsz:pos -> lv:nat{lv <= 32} -> i:nat -> olds:hashess #hsz {S.length olds = 32} -> GTot Type0 (decreases (32 - lv)) let rec mt_olds_inv #hsz lv i olds = if lv = 32 then true else (let ofs = offset_of i in S.length (S.index olds lv) == ofs /\ mt_olds_inv #hsz (lv + 1) (i / 2) olds) val mt_olds_inv_equiv: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> lv:nat{lv <= 32} -> i:nat -> olds1:hashess #hsz {S.length olds1 = 32} -> olds2:hashess #hsz {S.length olds2 = 32} -> Lemma (requires mt_olds_inv #hsz lv i olds1 /\ S.equal (S.slice olds1 lv 32) (S.slice olds2 lv 32)) (ensures mt_olds_inv #hsz lv i olds2) (decreases (32 - lv)) let rec mt_olds_inv_equiv #hsz #f lv i olds1 olds2 = if lv = 32 then () else (assert (S.index olds1 lv == S.index olds2 lv); mt_olds_inv_equiv #_ #f (lv + 1) (i / 2) olds1 olds2) val mt_olds_hs_lth_inv_ok: #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 #hsz lv hs i j} -> Lemma (requires True) (ensures mt_hashes_lth_inv #hsz lv j (merge_hs #_ #f olds hs)) (decreases (32 - lv)) let rec mt_olds_hs_lth_inv_ok #hsz #f lv i j olds hs = if lv = 32 then () else (mt_olds_hs_lth_inv_ok #_ #f (lv + 1) (i / 2) (j / 2) olds hs) val mt_olds_hs_inv: #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 #hsz lv hs i j} -> GTot Type0 let mt_olds_hs_inv #hsz #f lv i j olds hs = mt_olds_hs_lth_inv_ok #_ #f lv i j olds hs; mt_hashes_inv #_ #f lv j (merge_hs #_ #f olds hs) // Relation between valid internal hashes (satisfying `mt_olds_hs_inv`) and // the spec. While giving such relation, all rightmost hashes are recovered. // Note that `MT?.rhs` after `construct_rhs` does NOT contain all rightmost // hashes; it has partial rightmost hashes that are enough to calculate // Merkle paths. val log2: n:nat{n > 0} -> GTot (c:nat{pow2 c <= n && n < pow2 (c+1)}) let rec log2 n = if n = 1 then 0 else 1 + log2 (n / 2) val log2_bound: n:nat{n > 0} -> c:nat{n < pow2 c} -> Lemma (log2 n <= c-1) let rec log2_bound n c = if n = 1 then () else log2_bound (n / 2) (c - 1) val log2_div: n:nat{n > 1} -> Lemma (log2 (n / 2) = log2 n - 1) let log2_div n = () val log2c: n:nat -> GTot (c:nat{c = 0 || (pow2 (c-1) <= n && n < pow2 c)}) let log2c n = if n = 0 then 0 else (log2 n + 1) val log2c_div: n:nat{n > 0} -> Lemma (log2c (n / 2) = log2c n - 1) let log2c_div n = () val log2c_bound: n:nat -> c:nat{n < pow2 c} -> Lemma (log2c n <= c) let rec log2c_bound n c = if n = 0 then () else log2c_bound (n / 2) (c - 1) val mt_hashes_lth_inv_log: #hsz:pos -> j:nat -> fhs:hashess #hsz {S.length fhs = log2c j} -> GTot Type0 (decreases j) let rec mt_hashes_lth_inv_log #hsz j fhs = if j = 0 then true else (S.length (S.head fhs) == j /\ mt_hashes_lth_inv_log #hsz (j / 2) (S.tail fhs)) #pop-options #push-options "--max_fuel 2" val mt_hashes_lth_inv_log_next: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> j:nat{j > 1} -> fhs:hashess #hsz {S.length fhs = log2c j} -> Lemma (requires mt_hashes_lth_inv_log #hsz j fhs) (ensures S.length (S.head fhs) == j /\ S.length (S.head (S.tail fhs)) == j / 2) let mt_hashes_lth_inv_log_next #_ #_ _ _ = () val mt_hashes_inv_log: #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} -> GTot Type0 (decreases j) let rec mt_hashes_inv_log #hsz #f j fhs = if j <= 1 then true else (mt_hashes_next_rel #_ #f j (S.index fhs 0) (S.index fhs 1) /\ mt_hashes_inv_log #_ #f (j / 2) (S.tail fhs)) val mt_hashes_lth_inv_log_converted_: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> lv:nat{lv <= 32} -> j:nat{j < pow2 (32 - lv)} -> fhs:hashess #hsz {S.length fhs = 32} -> Lemma (requires mt_hashes_lth_inv #hsz lv j fhs) (ensures (log2c_bound j (32 - lv); mt_hashes_lth_inv_log #hsz j (S.slice fhs lv (lv + log2c j)))) (decreases j) let rec mt_hashes_lth_inv_log_converted_ #_ #f lv j fhs = if j = 0 then () else (log2c_bound (j / 2) (32 - (lv + 1)); mt_hashes_lth_inv_log_converted_ #_ #f (lv + 1) (j / 2) fhs) val mt_hashes_lth_inv_log_converted: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> j:nat{j < pow2 32} -> fhs:hashess #hsz {S.length fhs = 32} -> Lemma (requires mt_hashes_lth_inv #hsz 0 j fhs) (ensures (log2c_bound j 32; mt_hashes_lth_inv_log #hsz j (S.slice fhs 0 (log2c j)))) let mt_hashes_lth_inv_log_converted #_ #f j fhs = mt_hashes_lth_inv_log_converted_ #_ #f 0 j fhs val mt_hashes_inv_log_converted_: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> lv:nat{lv <= 32} -> j:nat{j > 0 && j < pow2 (32 - lv)} -> fhs:hashess #hsz {S.length fhs = 32 /\ mt_hashes_lth_inv #hsz lv j fhs} -> Lemma (requires mt_hashes_inv #_ #f lv j fhs) (ensures (log2c_bound j (32 - lv); mt_hashes_lth_inv_log_converted_ #_ #f lv j fhs; mt_hashes_inv_log #_ #f j (S.slice fhs lv (lv + log2c j)))) (decreases j) #pop-options #push-options "--z3rlimit 100 --initial_fuel 2 --max_fuel 2" let rec mt_hashes_inv_log_converted_ #_ #f lv j fhs = if j = 1 then () else (log2c_bound (j / 2) (32 - (lv + 1)); mt_hashes_lth_inv_log_converted_ #_ #f (lv + 1) (j / 2) fhs; mt_hashes_inv_log_converted_ #_ #f (lv + 1) (j / 2) fhs) #pop-options val mt_hashes_inv_log_converted: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> j:nat{j > 0 && j < pow2 32} -> fhs:hashess #hsz {S.length fhs = 32 /\ mt_hashes_lth_inv #hsz 0 j fhs} -> Lemma (requires mt_hashes_inv #_ #f 0 j fhs) (ensures (log2c_bound j 32; mt_hashes_lth_inv_log_converted_ #_ #f 0 j fhs; mt_hashes_inv_log #_ #f j (S.slice fhs 0 (log2c j)))) let mt_hashes_inv_log_converted #_ #f j fhs = mt_hashes_inv_log_converted_ #_ #f 0 j fhs val hash_seq_lift: #hsz:pos -> hs:hashes #hsz -> GTot (shs:MTS.hashes #hsz {S.length shs = S.length hs}) (decreases (S.length hs)) let rec hash_seq_lift #hsz hs = if S.length hs = 0 then S.empty else S.cons (MTS.HRaw (S.head hs)) (hash_seq_lift #hsz (S.tail hs)) #push-options "--z3rlimit 50 --initial_fuel 2 --max_fuel 2" val hash_seq_lift_index: #hsz:pos -> hs:hashes #hsz -> Lemma (requires True) (ensures forall (i:nat{i < S.length hs}). S.index (hash_seq_lift #hsz hs) i == MTS.HRaw (S.index hs i)) (decreases (S.length hs)) let rec hash_seq_lift_index #hsz hs = if S.length hs = 0 then () else hash_seq_lift_index #hsz (S.tail hs) #pop-options val create_pads: #hsz:pos -> len:nat -> GTot (pads:MTS.hashes #hsz {S.length pads = len}) let create_pads #hsz len = S.create len (MTS.HPad #hsz) val hash_seq_spec: #hsz:pos -> hs:hashes #hsz {S.length hs > 0} -> GTot (MTS.merkle_tree #hsz (log2c (S.length hs))) let hash_seq_spec #hsz hs = S.append (hash_seq_lift #hsz hs) (create_pads (pow2 (log2c (S.length hs)) - S.length hs)) val hash_seq_spec_index_raw: #hsz:pos -> hs:hashes #hsz {S.length hs > 0} -> i:nat{i < S.length hs} -> Lemma (S.index (hash_seq_spec #hsz hs) i == MTS.HRaw #hsz (S.index hs i)) let hash_seq_spec_index_raw #hsz hs i = hash_seq_lift_index #hsz hs // Now about recovering rightmost hashes #push-options "--z3rlimit 50 --initial_fuel 1 --max_fuel 1" val mt_hashes_next_rel_lift_even: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> j:nat{j > 1} -> hs:hashes #hsz {S.length hs = j} -> nhs:hashes #hsz {S.length nhs = j / 2} -> Lemma (requires j % 2 = 0 /\ mt_hashes_next_rel #_ #f j hs nhs) (ensures MTS.mt_next_rel #_ #f (log2c j) (hash_seq_spec #hsz hs) (hash_seq_spec #hsz nhs)) let mt_hashes_next_rel_lift_even #hsz #_ j hs nhs = hash_seq_lift_index #hsz hs; hash_seq_lift_index #hsz nhs val mt_hashes_next_rel_lift_odd: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> j:nat{j > 1} -> hs:hashes #hsz {S.length hs = j} -> nhs:hashes #hsz {S.length nhs = j / 2} -> Lemma (requires j % 2 = 1 /\ mt_hashes_next_rel #_ #f j hs nhs) (ensures MTS.mt_next_rel #_ #f (log2c j) (hash_seq_spec #hsz hs) (S.upd (hash_seq_spec #hsz nhs) (S.length nhs) (MTS.HRaw (S.last hs)))) let mt_hashes_next_rel_lift_odd #hsz #_ j hs nhs = log2c_div j; hash_seq_lift_index #hsz hs; hash_seq_lift_index #hsz nhs val mt_hashes_next_rel_next_even: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> j:nat{j > 1} -> hs:hashes #hsz {S.length hs = j} -> nhs:hashes #hsz {S.length nhs = j / 2} -> Lemma (requires j % 2 = 0 /\ mt_hashes_next_rel #_ #f j hs nhs) (ensures S.equal (hash_seq_spec #hsz nhs) (MTS.mt_next_lv #_ #f #(log2c j) (hash_seq_spec #hsz hs))) let mt_hashes_next_rel_next_even #hsz #f j hs nhs = log2c_div j; mt_hashes_next_rel_lift_even #_ #f j hs nhs; MTS.mt_next_rel_next_lv #_ #f (log2c j) (hash_seq_spec #hsz hs) (hash_seq_spec #hsz nhs) val hash_seq_spec_full: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> hs:hashes #hsz {S.length hs > 0} -> acc:hash #hsz -> actd:bool -> GTot (MTS.merkle_tree #hsz (log2c (S.length hs))) let hash_seq_spec_full #hsz #f hs acc actd = if actd then (S.upd (hash_seq_spec #hsz hs) (S.length hs) (MTS.HRaw acc)) else hash_seq_spec #hsz hs val hash_seq_spec_full_index_raw: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> hs:hashes #hsz {S.length hs > 0} -> acc:hash #hsz -> actd:bool -> i:nat{i < S.length hs} -> Lemma (S.index (hash_seq_spec_full #_ #f hs acc actd) i == MTS.HRaw (S.index hs i)) let hash_seq_spec_full_index_raw #hsz #_ hs acc actd i = hash_seq_spec_index_raw #hsz hs i val hash_seq_spec_full_case_true: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> hs:hashes #hsz {S.length hs > 0} -> acc:hash #hsz -> Lemma (S.index (hash_seq_spec_full #_ #f hs acc true) (S.length hs) == MTS.HRaw acc) let hash_seq_spec_full_case_true #_ #_ _ _ = () val hash_seq_spec_full_even_next: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> j:nat{j > 0} -> hs:hashes #hsz {S.length hs = j} -> nhs:hashes #hsz {S.length nhs = j / 2} -> acc:hash #hsz -> actd:bool -> Lemma (requires j % 2 = 0 /\ mt_hashes_next_rel #_ #f j hs nhs) (ensures S.equal (hash_seq_spec_full #_ #f nhs acc actd) (MTS.mt_next_lv #_ #f #(log2c j) (hash_seq_spec_full #_ #f hs acc actd))) #restart-solver #push-options "--quake 1/3 --z3rlimit 100 --fuel 2 --ifuel 1" let hash_seq_spec_full_even_next #hsz #f j hs nhs acc actd = log2c_div j; mt_hashes_next_rel_lift_even #_ #f j hs nhs; if actd then begin MTS.mt_next_rel_upd_even_pad #_ #f (log2c j) (hash_seq_spec #hsz hs) (hash_seq_spec #hsz nhs) (S.length hs / 2) (MTS.HRaw acc); let n = log2c j in let mt = S.upd (hash_seq_spec #hsz hs) (S.length hs) (MTS.HRaw acc) in let nmt = S.upd (hash_seq_spec #hsz nhs) (S.length nhs) (MTS.HRaw acc) in // assume (MTS.mt_next_rel #_ #f n mt nmt); MTS.mt_next_rel_next_lv #_ #f n mt nmt end else MTS.mt_next_rel_next_lv #_ #f (log2c j) (hash_seq_spec_full #_ #f hs acc actd) (hash_seq_spec_full #_ #f nhs acc actd) #pop-options #push-options "--z3rlimit 80" val hash_seq_spec_full_odd_next: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> j:nat{j > 1} -> hs:hashes #hsz {S.length hs = j} -> nhs:hashes #hsz {S.length nhs = j / 2} -> acc:hash #hsz -> actd:bool -> nacc:hash #hsz -> Lemma (requires j % 2 = 1 /\ mt_hashes_next_rel #_ #f j hs nhs /\ nacc == (if actd then f (S.last hs) acc else S.last hs)) (ensures S.equal (hash_seq_spec_full #_ #f nhs nacc true) (MTS.mt_next_lv #_ #f #(log2c j) (hash_seq_spec_full #_ #f hs acc actd))) let hash_seq_spec_full_odd_next #hsz #f j hs nhs acc actd nacc = log2c_div j; mt_hashes_next_rel_lift_odd #_ #f j hs nhs; if actd then begin MTS.mt_next_rel_upd_odd #_ #f (log2c j) (hash_seq_spec #hsz hs) (S.upd (hash_seq_spec #hsz nhs) (S.length nhs) (MTS.HRaw (S.last hs))) (S.length nhs) (MTS.HRaw acc); MTS.mt_next_rel_next_lv #_ #f (log2c j) (S.upd (hash_seq_spec #hsz hs) (S.length hs) (MTS.HRaw acc)) (S.upd (hash_seq_spec #hsz nhs) (S.length nhs) (MTS.HRaw (f (S.last hs) acc))) end else MTS.mt_next_rel_next_lv #_ #f (log2c j) (hash_seq_spec_full #_ #f hs acc actd) (hash_seq_spec_full #_ #f nhs nacc true) #pop-options val hash_seq_spec_full_next: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> j:nat{j > 1} -> hs:hashes #hsz {S.length hs = j} -> nhs:hashes #hsz {S.length nhs = j / 2} -> acc:hash #hsz -> actd:bool -> nacc:hash #hsz -> nactd:bool -> Lemma (requires mt_hashes_next_rel #_ #f j hs nhs /\ nacc == (if j % 2 = 0 then acc else if actd then f (S.last hs) acc else S.last hs) /\ nactd == (actd || j % 2 = 1)) (ensures S.equal (hash_seq_spec_full #_ #f nhs nacc nactd) (MTS.mt_next_lv #_ #f #(log2c j) (hash_seq_spec_full #_ #f hs acc actd))) let hash_seq_spec_full_next #_ #f j hs nhs acc actd nacc nactd = if j % 2 = 0 then hash_seq_spec_full_even_next #_ #f j hs nhs acc actd else hash_seq_spec_full_odd_next #_ #f j hs nhs acc actd nacc val mt_rhs_inv: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> j:nat -> smt:MTS.merkle_tree #hsz (log2c j) -> rhs:hashes #hsz {S.length rhs = log2c j} -> actd:bool -> GTot Type0 (decreases j) let rec mt_rhs_inv #_ #f j smt rhs actd = if j = 0 then true else begin (if j % 2 = 1 && actd then (S.index smt j == MTS.HRaw (S.head rhs)) else true) /\ mt_rhs_inv #_ #f (j / 2) (MTS.mt_next_lv #_ #f #(log2c j) smt) (S.tail rhs) (actd || (j % 2 = 1)) end val mt_root_inv: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> hs0:hashes #hsz {S.length hs0 > 0} -> acc:hash #hsz -> actd:bool -> rt:hash #hsz -> GTot Type0 let mt_root_inv #_ #f hs0 acc actd rt = MTS.mt_get_root #_ #f #(log2c (S.length hs0)) (hash_seq_spec_full #_ #f hs0 acc actd) == MTS.HRaw rt val mt_base: #hsz:pos -> mt:merkle_tree #hsz {mt_wf_elts mt} -> olds:hashess #hsz {S.length olds = 32 /\ mt_olds_inv #hsz 0 (MT?.i mt) olds} ->
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "MerkleTree.Spec.fst.checked", "MerkleTree.New.High.fst.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Ghost.fsti.checked", "FStar.Classical.fsti.checked" ], "interface_file": false, "source_file": "MerkleTree.New.High.Correct.Base.fst" }
[ { "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": 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": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
mt: MerkleTree.New.High.merkle_tree{MerkleTree.New.High.mt_wf_elts mt} -> olds: MerkleTree.New.High.hashess { FStar.Seq.Base.length olds = 32 /\ MerkleTree.New.High.Correct.Base.mt_olds_inv 0 (MT?.i mt) olds } -> Prims.GTot (bhs: MerkleTree.New.High.hashes{FStar.Seq.Base.length bhs = MT?.j mt})
Prims.GTot
[ "sometrivial" ]
[]
[ "Prims.pos", "MerkleTree.New.High.merkle_tree", "MerkleTree.New.High.mt_wf_elts", "MerkleTree.New.High.hashess", "Prims.l_and", "Prims.b2t", "Prims.op_Equality", "Prims.int", "FStar.Seq.Base.length", "MerkleTree.New.High.hashes", "MerkleTree.New.High.Correct.Base.mt_olds_inv", "MerkleTree.New.High.__proj__MT__item__i", "FStar.Seq.Properties.head", "MerkleTree.New.High.Correct.Base.merge_hs", "MerkleTree.New.High.__proj__MT__item__hash_fun", "MerkleTree.New.High.__proj__MT__item__hs", "Prims.nat", "MerkleTree.New.High.hash", "MerkleTree.New.High.__proj__MT__item__j" ]
[]
false
false
false
false
false
let mt_base #hsz mt olds =
S.head (merge_hs #hsz #(MT?.hash_fun mt) olds (MT?.hs mt))
false
MerkleTree.New.High.Correct.Base.fst
MerkleTree.New.High.Correct.Base.mt_rhs_inv
val mt_rhs_inv: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> j:nat -> smt:MTS.merkle_tree #hsz (log2c j) -> rhs:hashes #hsz {S.length rhs = log2c j} -> actd:bool -> GTot Type0 (decreases j)
val mt_rhs_inv: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> j:nat -> smt:MTS.merkle_tree #hsz (log2c j) -> rhs:hashes #hsz {S.length rhs = log2c j} -> actd:bool -> GTot Type0 (decreases j)
let rec mt_rhs_inv #_ #f j smt rhs actd = if j = 0 then true else begin (if j % 2 = 1 && actd then (S.index smt j == MTS.HRaw (S.head rhs)) else true) /\ mt_rhs_inv #_ #f (j / 2) (MTS.mt_next_lv #_ #f #(log2c j) smt) (S.tail rhs) (actd || (j % 2 = 1)) end
{ "file_name": "src/MerkleTree.New.High.Correct.Base.fst", "git_rev": "7d7bdc20f2033171e279c176b26e84f9069d23c6", "git_url": "https://github.com/hacl-star/merkle-tree.git", "project_name": "merkle-tree" }
{ "end_col": 5, "end_line": 612, "start_col": 0, "start_line": 604 }
module MerkleTree.New.High.Correct.Base open FStar.Classical open FStar.Ghost open FStar.Seq module S = FStar.Seq module MTS = MerkleTree.Spec open MerkleTree.New.High #set-options "--z3rlimit 40 --max_fuel 0 --max_ifuel 0" /// Sequence helpers val seq_prefix: #a:Type -> s1:S.seq a -> s2:S.seq a{S.length s1 <= S.length s2} -> GTot Type0 let seq_prefix #a s1 s2 = S.equal s1 (S.slice s2 0 (S.length s1)) val seq_head_cons: #a:Type -> x:a -> s:S.seq a -> Lemma (S.head (S.cons x s) == x) [SMTPat (S.cons x s)] let seq_head_cons #a x s = () val seq_tail_cons: #a:Type -> x:a -> s:S.seq a -> Lemma (S.equal (S.tail (S.cons x s)) s) [SMTPat (S.cons x s)] let seq_tail_cons #a x s = () /// Invariants and simulation relation of high-level Merkle tree design // Invariants of internal hashes val empty_hashes: (#hsz:pos) -> (len:nat) -> GTot (hs:hashess #hsz {S.length hs = len}) let empty_hashes #hsz len = S.create len S.empty val empty_hashes_head: #hsz:pos -> len:nat{len > 0} -> Lemma (S.head (empty_hashes #hsz len) == S.empty) let empty_hashes_head #_ _ = () val empty_hashes_tail: #hsz:pos -> len:nat{len > 0} -> Lemma (S.equal (S.tail (empty_hashes len)) (empty_hashes #hsz (len - 1))) let empty_hashes_tail #_ _ = () #push-options "--max_fuel 1" val mt_hashes_lth_inv: #hsz:pos -> lv:nat{lv <= 32} -> j:nat{j < pow2 (32 - lv)} -> fhs:hashess #hsz {S.length fhs = 32} -> GTot Type0 (decreases (32 - lv)) let rec mt_hashes_lth_inv #hsz lv j fhs = if lv = 32 then true else (S.length (S.index fhs lv) == j /\ mt_hashes_lth_inv (lv + 1) (j / 2) fhs) val mt_hashes_lth_inv_empty: #hsz:pos -> lv:nat{lv <= 32} -> Lemma (requires True) (ensures mt_hashes_lth_inv lv 0 (empty_hashes #hsz 32)) (decreases (32 - lv)) let rec mt_hashes_lth_inv_empty #hsz lv = if lv = 32 then () else mt_hashes_lth_inv_empty #hsz (lv + 1) val mt_hashes_next_rel: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> j:nat -> hs:hashes #hsz {S.length hs = j} -> nhs:hashes #hsz {S.length nhs = j / 2} -> GTot Type0 let mt_hashes_next_rel #hsz #f j hs nhs = forall (i:nat{i < j / 2}). S.index nhs i == f (S.index hs (op_Multiply 2 i)) (S.index hs (op_Multiply 2 i + 1)) #pop-options #push-options "--max_fuel 2" val mt_hashes_inv: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> lv:nat{lv < 32} -> j:nat{j < pow2 (32 - lv)} -> fhs:hashess #hsz {S.length fhs = 32 /\ mt_hashes_lth_inv lv j fhs} -> GTot Type0 (decreases (32 - lv)) let rec mt_hashes_inv #hsz #f lv j fhs = if lv = 31 then true else (mt_hashes_next_rel #_ #f j (S.index fhs lv) (S.index fhs (lv + 1)) /\ mt_hashes_inv #_ #f (lv + 1) (j / 2) fhs) val mt_hashes_inv_empty: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> lv:nat{lv < 32} -> Lemma (requires True) (ensures (mt_hashes_lth_inv_empty #hsz lv; mt_hashes_inv #hsz #f lv 0 (empty_hashes #hsz 32))) (decreases (32 - lv)) let rec mt_hashes_inv_empty #hsz #f lv = if lv = 31 then () else (mt_hashes_lth_inv_empty #hsz (lv + 1); mt_hashes_inv_empty #_ #f (lv + 1)) val mt_hashes_lth_inv_equiv: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> lv:nat{lv < 32} -> j:nat{j < pow2 (32 - lv)} -> fhs1:hashess{S.length fhs1 = 32} -> fhs2:hashess{S.length fhs2 = 32} -> Lemma (requires mt_hashes_lth_inv lv j fhs1 /\ S.equal (S.slice fhs1 lv 32) (S.slice fhs2 lv 32)) (ensures mt_hashes_lth_inv #hsz lv j fhs2) (decreases (32 - lv)) let rec mt_hashes_lth_inv_equiv #hsz #f lv j fhs1 fhs2 = if lv = 31 then () else (assert (S.index fhs1 lv == S.index fhs2 lv); mt_hashes_lth_inv_equiv #_ #f (lv + 1) (j / 2) fhs1 fhs2) #pop-options #push-options "--max_fuel 1" val mt_hashes_inv_equiv: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> lv:nat{lv < 32} -> j:nat{j < pow2 (32 - lv)} -> fhs1:hashess #hsz {S.length fhs1 = 32 /\ mt_hashes_lth_inv lv j fhs1} -> fhs2:hashess #hsz {S.length fhs2 = 32 /\ mt_hashes_lth_inv lv j fhs2} -> Lemma (requires mt_hashes_inv #_ #f lv j fhs1 /\ S.equal (S.slice fhs1 lv 32) (S.slice fhs2 lv 32)) (ensures mt_hashes_inv #_ #f lv j fhs2) (decreases (32 - lv)) let rec mt_hashes_inv_equiv #hsz #f lv j fhs1 fhs2 = if lv = 31 then () else (assert (S.index fhs1 lv == S.index fhs2 lv); assert (S.index fhs1 (lv + 1) == S.index fhs2 (lv + 1)); mt_hashes_inv_equiv #_ #f (lv + 1) (j / 2) fhs1 fhs2) val merge_hs: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> hs1:hashess #hsz -> hs2:hashess #hsz {S.length hs1 = S.length hs2} -> GTot (mhs:hashess #hsz {S.length mhs = S.length hs1}) (decreases (S.length hs1)) let rec merge_hs #hsz #f hs1 hs2 = if S.length hs1 = 0 then S.empty else (S.cons (S.append (S.head hs1) (S.head hs2)) (merge_hs #_ #f (S.tail hs1) (S.tail hs2))) val merge_hs_empty: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> len:nat -> Lemma (S.equal (merge_hs #_ #f (empty_hashes #hsz len) (empty_hashes #hsz len)) (empty_hashes #hsz len)) let rec merge_hs_empty #hsz #f len = if len = 0 then () else (empty_hashes_head #hsz len; empty_hashes_tail #hsz len; assert (S.equal (S.append #(hash #hsz) S.empty S.empty) (S.empty #(hash #hsz))); assert (S.equal (merge_hs #_ #f (empty_hashes len) (empty_hashes len)) (S.cons S.empty (merge_hs #_ #f (empty_hashes (len - 1)) (empty_hashes (len - 1))))); merge_hs_empty #_ #f (len - 1)) val merge_hs_index: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> hs1:hashess -> hs2:hashess{S.length hs1 = S.length hs2} -> i:nat{i < S.length hs1} -> Lemma (requires True) (ensures S.equal (S.index (merge_hs #_ #f hs1 hs2) i) (S.append (S.index hs1 i) (S.index hs2 i))) (decreases (S.length hs1)) [SMTPat (S.index (merge_hs #_ #f hs1 hs2) i)] let rec merge_hs_index #hsz #f hs1 hs2 i = if S.length hs1 = 0 then () else if i = 0 then () else merge_hs_index #_ #f (S.tail hs1) (S.tail hs2) (i - 1) val merge_hs_slice_equal: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> ahs1:hashess #hsz -> ahs2:hashess #hsz {S.length ahs1 = S.length ahs2} -> bhs1:hashess #hsz -> bhs2:hashess #hsz {S.length bhs1 = S.length bhs2} -> i:nat -> j:nat{i <= j && j <= S.length ahs1 && j <= S.length bhs1} -> Lemma (requires S.equal (S.slice ahs1 i j) (S.slice bhs1 i j) /\ S.equal (S.slice ahs2 i j) (S.slice bhs2 i j)) (ensures S.equal (S.slice (merge_hs #_ #f ahs1 ahs2) i j) (S.slice (merge_hs #_ #f bhs1 bhs2) i j)) (decreases (j - i)) let rec merge_hs_slice_equal #_ #f ahs1 ahs2 bhs1 bhs2 i j = if i = j then () else (assert (S.index ahs1 i == S.index bhs1 i); assert (S.index ahs2 i == S.index bhs2 i); merge_hs_slice_equal #_ #f ahs1 ahs2 bhs1 bhs2 (i + 1) j) val merge_hs_upd: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> hs1:hashess #hsz -> hs2:hashess #hsz {S.length hs1 = S.length hs2} -> i:nat{i < S.length hs1} -> v1:hashes #hsz -> v2:hashes #hsz -> Lemma (requires S.equal (S.append (S.index hs1 i) (S.index hs2 i)) (S.append v1 v2)) (ensures S.equal (merge_hs #_ #f hs1 hs2) (merge_hs #_ #f (S.upd hs1 i v1) (S.upd hs2 i v2))) (decreases i) let rec merge_hs_upd #_ #f hs1 hs2 i v1 v2 = if S.length hs1 = 0 then () else if i = 0 then () else merge_hs_upd #_ #f (S.tail hs1) (S.tail hs2) (i - 1) v1 v2 val mt_olds_inv: #hsz:pos -> lv:nat{lv <= 32} -> i:nat -> olds:hashess #hsz {S.length olds = 32} -> GTot Type0 (decreases (32 - lv)) let rec mt_olds_inv #hsz lv i olds = if lv = 32 then true else (let ofs = offset_of i in S.length (S.index olds lv) == ofs /\ mt_olds_inv #hsz (lv + 1) (i / 2) olds) val mt_olds_inv_equiv: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> lv:nat{lv <= 32} -> i:nat -> olds1:hashess #hsz {S.length olds1 = 32} -> olds2:hashess #hsz {S.length olds2 = 32} -> Lemma (requires mt_olds_inv #hsz lv i olds1 /\ S.equal (S.slice olds1 lv 32) (S.slice olds2 lv 32)) (ensures mt_olds_inv #hsz lv i olds2) (decreases (32 - lv)) let rec mt_olds_inv_equiv #hsz #f lv i olds1 olds2 = if lv = 32 then () else (assert (S.index olds1 lv == S.index olds2 lv); mt_olds_inv_equiv #_ #f (lv + 1) (i / 2) olds1 olds2) val mt_olds_hs_lth_inv_ok: #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 #hsz lv hs i j} -> Lemma (requires True) (ensures mt_hashes_lth_inv #hsz lv j (merge_hs #_ #f olds hs)) (decreases (32 - lv)) let rec mt_olds_hs_lth_inv_ok #hsz #f lv i j olds hs = if lv = 32 then () else (mt_olds_hs_lth_inv_ok #_ #f (lv + 1) (i / 2) (j / 2) olds hs) val mt_olds_hs_inv: #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 #hsz lv hs i j} -> GTot Type0 let mt_olds_hs_inv #hsz #f lv i j olds hs = mt_olds_hs_lth_inv_ok #_ #f lv i j olds hs; mt_hashes_inv #_ #f lv j (merge_hs #_ #f olds hs) // Relation between valid internal hashes (satisfying `mt_olds_hs_inv`) and // the spec. While giving such relation, all rightmost hashes are recovered. // Note that `MT?.rhs` after `construct_rhs` does NOT contain all rightmost // hashes; it has partial rightmost hashes that are enough to calculate // Merkle paths. val log2: n:nat{n > 0} -> GTot (c:nat{pow2 c <= n && n < pow2 (c+1)}) let rec log2 n = if n = 1 then 0 else 1 + log2 (n / 2) val log2_bound: n:nat{n > 0} -> c:nat{n < pow2 c} -> Lemma (log2 n <= c-1) let rec log2_bound n c = if n = 1 then () else log2_bound (n / 2) (c - 1) val log2_div: n:nat{n > 1} -> Lemma (log2 (n / 2) = log2 n - 1) let log2_div n = () val log2c: n:nat -> GTot (c:nat{c = 0 || (pow2 (c-1) <= n && n < pow2 c)}) let log2c n = if n = 0 then 0 else (log2 n + 1) val log2c_div: n:nat{n > 0} -> Lemma (log2c (n / 2) = log2c n - 1) let log2c_div n = () val log2c_bound: n:nat -> c:nat{n < pow2 c} -> Lemma (log2c n <= c) let rec log2c_bound n c = if n = 0 then () else log2c_bound (n / 2) (c - 1) val mt_hashes_lth_inv_log: #hsz:pos -> j:nat -> fhs:hashess #hsz {S.length fhs = log2c j} -> GTot Type0 (decreases j) let rec mt_hashes_lth_inv_log #hsz j fhs = if j = 0 then true else (S.length (S.head fhs) == j /\ mt_hashes_lth_inv_log #hsz (j / 2) (S.tail fhs)) #pop-options #push-options "--max_fuel 2" val mt_hashes_lth_inv_log_next: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> j:nat{j > 1} -> fhs:hashess #hsz {S.length fhs = log2c j} -> Lemma (requires mt_hashes_lth_inv_log #hsz j fhs) (ensures S.length (S.head fhs) == j /\ S.length (S.head (S.tail fhs)) == j / 2) let mt_hashes_lth_inv_log_next #_ #_ _ _ = () val mt_hashes_inv_log: #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} -> GTot Type0 (decreases j) let rec mt_hashes_inv_log #hsz #f j fhs = if j <= 1 then true else (mt_hashes_next_rel #_ #f j (S.index fhs 0) (S.index fhs 1) /\ mt_hashes_inv_log #_ #f (j / 2) (S.tail fhs)) val mt_hashes_lth_inv_log_converted_: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> lv:nat{lv <= 32} -> j:nat{j < pow2 (32 - lv)} -> fhs:hashess #hsz {S.length fhs = 32} -> Lemma (requires mt_hashes_lth_inv #hsz lv j fhs) (ensures (log2c_bound j (32 - lv); mt_hashes_lth_inv_log #hsz j (S.slice fhs lv (lv + log2c j)))) (decreases j) let rec mt_hashes_lth_inv_log_converted_ #_ #f lv j fhs = if j = 0 then () else (log2c_bound (j / 2) (32 - (lv + 1)); mt_hashes_lth_inv_log_converted_ #_ #f (lv + 1) (j / 2) fhs) val mt_hashes_lth_inv_log_converted: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> j:nat{j < pow2 32} -> fhs:hashess #hsz {S.length fhs = 32} -> Lemma (requires mt_hashes_lth_inv #hsz 0 j fhs) (ensures (log2c_bound j 32; mt_hashes_lth_inv_log #hsz j (S.slice fhs 0 (log2c j)))) let mt_hashes_lth_inv_log_converted #_ #f j fhs = mt_hashes_lth_inv_log_converted_ #_ #f 0 j fhs val mt_hashes_inv_log_converted_: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> lv:nat{lv <= 32} -> j:nat{j > 0 && j < pow2 (32 - lv)} -> fhs:hashess #hsz {S.length fhs = 32 /\ mt_hashes_lth_inv #hsz lv j fhs} -> Lemma (requires mt_hashes_inv #_ #f lv j fhs) (ensures (log2c_bound j (32 - lv); mt_hashes_lth_inv_log_converted_ #_ #f lv j fhs; mt_hashes_inv_log #_ #f j (S.slice fhs lv (lv + log2c j)))) (decreases j) #pop-options #push-options "--z3rlimit 100 --initial_fuel 2 --max_fuel 2" let rec mt_hashes_inv_log_converted_ #_ #f lv j fhs = if j = 1 then () else (log2c_bound (j / 2) (32 - (lv + 1)); mt_hashes_lth_inv_log_converted_ #_ #f (lv + 1) (j / 2) fhs; mt_hashes_inv_log_converted_ #_ #f (lv + 1) (j / 2) fhs) #pop-options val mt_hashes_inv_log_converted: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> j:nat{j > 0 && j < pow2 32} -> fhs:hashess #hsz {S.length fhs = 32 /\ mt_hashes_lth_inv #hsz 0 j fhs} -> Lemma (requires mt_hashes_inv #_ #f 0 j fhs) (ensures (log2c_bound j 32; mt_hashes_lth_inv_log_converted_ #_ #f 0 j fhs; mt_hashes_inv_log #_ #f j (S.slice fhs 0 (log2c j)))) let mt_hashes_inv_log_converted #_ #f j fhs = mt_hashes_inv_log_converted_ #_ #f 0 j fhs val hash_seq_lift: #hsz:pos -> hs:hashes #hsz -> GTot (shs:MTS.hashes #hsz {S.length shs = S.length hs}) (decreases (S.length hs)) let rec hash_seq_lift #hsz hs = if S.length hs = 0 then S.empty else S.cons (MTS.HRaw (S.head hs)) (hash_seq_lift #hsz (S.tail hs)) #push-options "--z3rlimit 50 --initial_fuel 2 --max_fuel 2" val hash_seq_lift_index: #hsz:pos -> hs:hashes #hsz -> Lemma (requires True) (ensures forall (i:nat{i < S.length hs}). S.index (hash_seq_lift #hsz hs) i == MTS.HRaw (S.index hs i)) (decreases (S.length hs)) let rec hash_seq_lift_index #hsz hs = if S.length hs = 0 then () else hash_seq_lift_index #hsz (S.tail hs) #pop-options val create_pads: #hsz:pos -> len:nat -> GTot (pads:MTS.hashes #hsz {S.length pads = len}) let create_pads #hsz len = S.create len (MTS.HPad #hsz) val hash_seq_spec: #hsz:pos -> hs:hashes #hsz {S.length hs > 0} -> GTot (MTS.merkle_tree #hsz (log2c (S.length hs))) let hash_seq_spec #hsz hs = S.append (hash_seq_lift #hsz hs) (create_pads (pow2 (log2c (S.length hs)) - S.length hs)) val hash_seq_spec_index_raw: #hsz:pos -> hs:hashes #hsz {S.length hs > 0} -> i:nat{i < S.length hs} -> Lemma (S.index (hash_seq_spec #hsz hs) i == MTS.HRaw #hsz (S.index hs i)) let hash_seq_spec_index_raw #hsz hs i = hash_seq_lift_index #hsz hs // Now about recovering rightmost hashes #push-options "--z3rlimit 50 --initial_fuel 1 --max_fuel 1" val mt_hashes_next_rel_lift_even: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> j:nat{j > 1} -> hs:hashes #hsz {S.length hs = j} -> nhs:hashes #hsz {S.length nhs = j / 2} -> Lemma (requires j % 2 = 0 /\ mt_hashes_next_rel #_ #f j hs nhs) (ensures MTS.mt_next_rel #_ #f (log2c j) (hash_seq_spec #hsz hs) (hash_seq_spec #hsz nhs)) let mt_hashes_next_rel_lift_even #hsz #_ j hs nhs = hash_seq_lift_index #hsz hs; hash_seq_lift_index #hsz nhs val mt_hashes_next_rel_lift_odd: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> j:nat{j > 1} -> hs:hashes #hsz {S.length hs = j} -> nhs:hashes #hsz {S.length nhs = j / 2} -> Lemma (requires j % 2 = 1 /\ mt_hashes_next_rel #_ #f j hs nhs) (ensures MTS.mt_next_rel #_ #f (log2c j) (hash_seq_spec #hsz hs) (S.upd (hash_seq_spec #hsz nhs) (S.length nhs) (MTS.HRaw (S.last hs)))) let mt_hashes_next_rel_lift_odd #hsz #_ j hs nhs = log2c_div j; hash_seq_lift_index #hsz hs; hash_seq_lift_index #hsz nhs val mt_hashes_next_rel_next_even: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> j:nat{j > 1} -> hs:hashes #hsz {S.length hs = j} -> nhs:hashes #hsz {S.length nhs = j / 2} -> Lemma (requires j % 2 = 0 /\ mt_hashes_next_rel #_ #f j hs nhs) (ensures S.equal (hash_seq_spec #hsz nhs) (MTS.mt_next_lv #_ #f #(log2c j) (hash_seq_spec #hsz hs))) let mt_hashes_next_rel_next_even #hsz #f j hs nhs = log2c_div j; mt_hashes_next_rel_lift_even #_ #f j hs nhs; MTS.mt_next_rel_next_lv #_ #f (log2c j) (hash_seq_spec #hsz hs) (hash_seq_spec #hsz nhs) val hash_seq_spec_full: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> hs:hashes #hsz {S.length hs > 0} -> acc:hash #hsz -> actd:bool -> GTot (MTS.merkle_tree #hsz (log2c (S.length hs))) let hash_seq_spec_full #hsz #f hs acc actd = if actd then (S.upd (hash_seq_spec #hsz hs) (S.length hs) (MTS.HRaw acc)) else hash_seq_spec #hsz hs val hash_seq_spec_full_index_raw: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> hs:hashes #hsz {S.length hs > 0} -> acc:hash #hsz -> actd:bool -> i:nat{i < S.length hs} -> Lemma (S.index (hash_seq_spec_full #_ #f hs acc actd) i == MTS.HRaw (S.index hs i)) let hash_seq_spec_full_index_raw #hsz #_ hs acc actd i = hash_seq_spec_index_raw #hsz hs i val hash_seq_spec_full_case_true: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> hs:hashes #hsz {S.length hs > 0} -> acc:hash #hsz -> Lemma (S.index (hash_seq_spec_full #_ #f hs acc true) (S.length hs) == MTS.HRaw acc) let hash_seq_spec_full_case_true #_ #_ _ _ = () val hash_seq_spec_full_even_next: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> j:nat{j > 0} -> hs:hashes #hsz {S.length hs = j} -> nhs:hashes #hsz {S.length nhs = j / 2} -> acc:hash #hsz -> actd:bool -> Lemma (requires j % 2 = 0 /\ mt_hashes_next_rel #_ #f j hs nhs) (ensures S.equal (hash_seq_spec_full #_ #f nhs acc actd) (MTS.mt_next_lv #_ #f #(log2c j) (hash_seq_spec_full #_ #f hs acc actd))) #restart-solver #push-options "--quake 1/3 --z3rlimit 100 --fuel 2 --ifuel 1" let hash_seq_spec_full_even_next #hsz #f j hs nhs acc actd = log2c_div j; mt_hashes_next_rel_lift_even #_ #f j hs nhs; if actd then begin MTS.mt_next_rel_upd_even_pad #_ #f (log2c j) (hash_seq_spec #hsz hs) (hash_seq_spec #hsz nhs) (S.length hs / 2) (MTS.HRaw acc); let n = log2c j in let mt = S.upd (hash_seq_spec #hsz hs) (S.length hs) (MTS.HRaw acc) in let nmt = S.upd (hash_seq_spec #hsz nhs) (S.length nhs) (MTS.HRaw acc) in // assume (MTS.mt_next_rel #_ #f n mt nmt); MTS.mt_next_rel_next_lv #_ #f n mt nmt end else MTS.mt_next_rel_next_lv #_ #f (log2c j) (hash_seq_spec_full #_ #f hs acc actd) (hash_seq_spec_full #_ #f nhs acc actd) #pop-options #push-options "--z3rlimit 80" val hash_seq_spec_full_odd_next: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> j:nat{j > 1} -> hs:hashes #hsz {S.length hs = j} -> nhs:hashes #hsz {S.length nhs = j / 2} -> acc:hash #hsz -> actd:bool -> nacc:hash #hsz -> Lemma (requires j % 2 = 1 /\ mt_hashes_next_rel #_ #f j hs nhs /\ nacc == (if actd then f (S.last hs) acc else S.last hs)) (ensures S.equal (hash_seq_spec_full #_ #f nhs nacc true) (MTS.mt_next_lv #_ #f #(log2c j) (hash_seq_spec_full #_ #f hs acc actd))) let hash_seq_spec_full_odd_next #hsz #f j hs nhs acc actd nacc = log2c_div j; mt_hashes_next_rel_lift_odd #_ #f j hs nhs; if actd then begin MTS.mt_next_rel_upd_odd #_ #f (log2c j) (hash_seq_spec #hsz hs) (S.upd (hash_seq_spec #hsz nhs) (S.length nhs) (MTS.HRaw (S.last hs))) (S.length nhs) (MTS.HRaw acc); MTS.mt_next_rel_next_lv #_ #f (log2c j) (S.upd (hash_seq_spec #hsz hs) (S.length hs) (MTS.HRaw acc)) (S.upd (hash_seq_spec #hsz nhs) (S.length nhs) (MTS.HRaw (f (S.last hs) acc))) end else MTS.mt_next_rel_next_lv #_ #f (log2c j) (hash_seq_spec_full #_ #f hs acc actd) (hash_seq_spec_full #_ #f nhs nacc true) #pop-options val hash_seq_spec_full_next: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> j:nat{j > 1} -> hs:hashes #hsz {S.length hs = j} -> nhs:hashes #hsz {S.length nhs = j / 2} -> acc:hash #hsz -> actd:bool -> nacc:hash #hsz -> nactd:bool -> Lemma (requires mt_hashes_next_rel #_ #f j hs nhs /\ nacc == (if j % 2 = 0 then acc else if actd then f (S.last hs) acc else S.last hs) /\ nactd == (actd || j % 2 = 1)) (ensures S.equal (hash_seq_spec_full #_ #f nhs nacc nactd) (MTS.mt_next_lv #_ #f #(log2c j) (hash_seq_spec_full #_ #f hs acc actd))) let hash_seq_spec_full_next #_ #f j hs nhs acc actd nacc nactd = if j % 2 = 0 then hash_seq_spec_full_even_next #_ #f j hs nhs acc actd else hash_seq_spec_full_odd_next #_ #f j hs nhs acc actd nacc val mt_rhs_inv: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> j:nat -> smt:MTS.merkle_tree #hsz (log2c j) -> rhs:hashes #hsz {S.length rhs = log2c j} -> actd:bool ->
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "MerkleTree.Spec.fst.checked", "MerkleTree.New.High.fst.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Ghost.fsti.checked", "FStar.Classical.fsti.checked" ], "interface_file": false, "source_file": "MerkleTree.New.High.Correct.Base.fst" }
[ { "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": 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": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
j: Prims.nat -> smt: MerkleTree.Spec.merkle_tree (MerkleTree.New.High.Correct.Base.log2c j) -> rhs: MerkleTree.New.High.hashes {FStar.Seq.Base.length rhs = MerkleTree.New.High.Correct.Base.log2c j} -> actd: Prims.bool -> Prims.GTot Type0
Prims.GTot
[ "sometrivial", "" ]
[]
[ "Prims.pos", "MerkleTree.Spec.hash_fun_t", "Prims.nat", "MerkleTree.Spec.merkle_tree", "MerkleTree.New.High.Correct.Base.log2c", "MerkleTree.New.High.hashes", "Prims.b2t", "Prims.op_Equality", "FStar.Seq.Base.length", "MerkleTree.New.High.hash", "Prims.bool", "Prims.int", "Prims.l_and", "Prims.op_AmpAmp", "Prims.op_Modulus", "Prims.eq2", "MerkleTree.Spec.padded_hash", "FStar.Seq.Base.index", "MerkleTree.Spec.HRaw", "FStar.Seq.Properties.head", "Prims.logical", "MerkleTree.New.High.Correct.Base.mt_rhs_inv", "Prims.op_Division", "MerkleTree.Spec.mt_next_lv", "FStar.Seq.Properties.tail", "Prims.op_BarBar" ]
[ "recursion" ]
false
false
false
false
true
let rec mt_rhs_inv #_ #f j smt rhs actd =
if j = 0 then true else (if j % 2 = 1 && actd then (S.index smt j == MTS.HRaw (S.head rhs)) else true) /\ mt_rhs_inv #_ #f (j / 2) (MTS.mt_next_lv #_ #f #(log2c j) smt) (S.tail rhs) (actd || (j % 2 = 1))
false
MerkleTree.New.High.Correct.Base.fst
MerkleTree.New.High.Correct.Base.mt_hashes_next_rel_lift_even
val mt_hashes_next_rel_lift_even: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> j:nat{j > 1} -> hs:hashes #hsz {S.length hs = j} -> nhs:hashes #hsz {S.length nhs = j / 2} -> Lemma (requires j % 2 = 0 /\ mt_hashes_next_rel #_ #f j hs nhs) (ensures MTS.mt_next_rel #_ #f (log2c j) (hash_seq_spec #hsz hs) (hash_seq_spec #hsz nhs))
val mt_hashes_next_rel_lift_even: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> j:nat{j > 1} -> hs:hashes #hsz {S.length hs = j} -> nhs:hashes #hsz {S.length nhs = j / 2} -> Lemma (requires j % 2 = 0 /\ mt_hashes_next_rel #_ #f j hs nhs) (ensures MTS.mt_next_rel #_ #f (log2c j) (hash_seq_spec #hsz hs) (hash_seq_spec #hsz nhs))
let mt_hashes_next_rel_lift_even #hsz #_ j hs nhs = hash_seq_lift_index #hsz hs; hash_seq_lift_index #hsz nhs
{ "file_name": "src/MerkleTree.New.High.Correct.Base.fst", "git_rev": "7d7bdc20f2033171e279c176b26e84f9069d23c6", "git_url": "https://github.com/hacl-star/merkle-tree.git", "project_name": "merkle-tree" }
{ "end_col": 30, "end_line": 458, "start_col": 0, "start_line": 456 }
module MerkleTree.New.High.Correct.Base open FStar.Classical open FStar.Ghost open FStar.Seq module S = FStar.Seq module MTS = MerkleTree.Spec open MerkleTree.New.High #set-options "--z3rlimit 40 --max_fuel 0 --max_ifuel 0" /// Sequence helpers val seq_prefix: #a:Type -> s1:S.seq a -> s2:S.seq a{S.length s1 <= S.length s2} -> GTot Type0 let seq_prefix #a s1 s2 = S.equal s1 (S.slice s2 0 (S.length s1)) val seq_head_cons: #a:Type -> x:a -> s:S.seq a -> Lemma (S.head (S.cons x s) == x) [SMTPat (S.cons x s)] let seq_head_cons #a x s = () val seq_tail_cons: #a:Type -> x:a -> s:S.seq a -> Lemma (S.equal (S.tail (S.cons x s)) s) [SMTPat (S.cons x s)] let seq_tail_cons #a x s = () /// Invariants and simulation relation of high-level Merkle tree design // Invariants of internal hashes val empty_hashes: (#hsz:pos) -> (len:nat) -> GTot (hs:hashess #hsz {S.length hs = len}) let empty_hashes #hsz len = S.create len S.empty val empty_hashes_head: #hsz:pos -> len:nat{len > 0} -> Lemma (S.head (empty_hashes #hsz len) == S.empty) let empty_hashes_head #_ _ = () val empty_hashes_tail: #hsz:pos -> len:nat{len > 0} -> Lemma (S.equal (S.tail (empty_hashes len)) (empty_hashes #hsz (len - 1))) let empty_hashes_tail #_ _ = () #push-options "--max_fuel 1" val mt_hashes_lth_inv: #hsz:pos -> lv:nat{lv <= 32} -> j:nat{j < pow2 (32 - lv)} -> fhs:hashess #hsz {S.length fhs = 32} -> GTot Type0 (decreases (32 - lv)) let rec mt_hashes_lth_inv #hsz lv j fhs = if lv = 32 then true else (S.length (S.index fhs lv) == j /\ mt_hashes_lth_inv (lv + 1) (j / 2) fhs) val mt_hashes_lth_inv_empty: #hsz:pos -> lv:nat{lv <= 32} -> Lemma (requires True) (ensures mt_hashes_lth_inv lv 0 (empty_hashes #hsz 32)) (decreases (32 - lv)) let rec mt_hashes_lth_inv_empty #hsz lv = if lv = 32 then () else mt_hashes_lth_inv_empty #hsz (lv + 1) val mt_hashes_next_rel: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> j:nat -> hs:hashes #hsz {S.length hs = j} -> nhs:hashes #hsz {S.length nhs = j / 2} -> GTot Type0 let mt_hashes_next_rel #hsz #f j hs nhs = forall (i:nat{i < j / 2}). S.index nhs i == f (S.index hs (op_Multiply 2 i)) (S.index hs (op_Multiply 2 i + 1)) #pop-options #push-options "--max_fuel 2" val mt_hashes_inv: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> lv:nat{lv < 32} -> j:nat{j < pow2 (32 - lv)} -> fhs:hashess #hsz {S.length fhs = 32 /\ mt_hashes_lth_inv lv j fhs} -> GTot Type0 (decreases (32 - lv)) let rec mt_hashes_inv #hsz #f lv j fhs = if lv = 31 then true else (mt_hashes_next_rel #_ #f j (S.index fhs lv) (S.index fhs (lv + 1)) /\ mt_hashes_inv #_ #f (lv + 1) (j / 2) fhs) val mt_hashes_inv_empty: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> lv:nat{lv < 32} -> Lemma (requires True) (ensures (mt_hashes_lth_inv_empty #hsz lv; mt_hashes_inv #hsz #f lv 0 (empty_hashes #hsz 32))) (decreases (32 - lv)) let rec mt_hashes_inv_empty #hsz #f lv = if lv = 31 then () else (mt_hashes_lth_inv_empty #hsz (lv + 1); mt_hashes_inv_empty #_ #f (lv + 1)) val mt_hashes_lth_inv_equiv: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> lv:nat{lv < 32} -> j:nat{j < pow2 (32 - lv)} -> fhs1:hashess{S.length fhs1 = 32} -> fhs2:hashess{S.length fhs2 = 32} -> Lemma (requires mt_hashes_lth_inv lv j fhs1 /\ S.equal (S.slice fhs1 lv 32) (S.slice fhs2 lv 32)) (ensures mt_hashes_lth_inv #hsz lv j fhs2) (decreases (32 - lv)) let rec mt_hashes_lth_inv_equiv #hsz #f lv j fhs1 fhs2 = if lv = 31 then () else (assert (S.index fhs1 lv == S.index fhs2 lv); mt_hashes_lth_inv_equiv #_ #f (lv + 1) (j / 2) fhs1 fhs2) #pop-options #push-options "--max_fuel 1" val mt_hashes_inv_equiv: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> lv:nat{lv < 32} -> j:nat{j < pow2 (32 - lv)} -> fhs1:hashess #hsz {S.length fhs1 = 32 /\ mt_hashes_lth_inv lv j fhs1} -> fhs2:hashess #hsz {S.length fhs2 = 32 /\ mt_hashes_lth_inv lv j fhs2} -> Lemma (requires mt_hashes_inv #_ #f lv j fhs1 /\ S.equal (S.slice fhs1 lv 32) (S.slice fhs2 lv 32)) (ensures mt_hashes_inv #_ #f lv j fhs2) (decreases (32 - lv)) let rec mt_hashes_inv_equiv #hsz #f lv j fhs1 fhs2 = if lv = 31 then () else (assert (S.index fhs1 lv == S.index fhs2 lv); assert (S.index fhs1 (lv + 1) == S.index fhs2 (lv + 1)); mt_hashes_inv_equiv #_ #f (lv + 1) (j / 2) fhs1 fhs2) val merge_hs: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> hs1:hashess #hsz -> hs2:hashess #hsz {S.length hs1 = S.length hs2} -> GTot (mhs:hashess #hsz {S.length mhs = S.length hs1}) (decreases (S.length hs1)) let rec merge_hs #hsz #f hs1 hs2 = if S.length hs1 = 0 then S.empty else (S.cons (S.append (S.head hs1) (S.head hs2)) (merge_hs #_ #f (S.tail hs1) (S.tail hs2))) val merge_hs_empty: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> len:nat -> Lemma (S.equal (merge_hs #_ #f (empty_hashes #hsz len) (empty_hashes #hsz len)) (empty_hashes #hsz len)) let rec merge_hs_empty #hsz #f len = if len = 0 then () else (empty_hashes_head #hsz len; empty_hashes_tail #hsz len; assert (S.equal (S.append #(hash #hsz) S.empty S.empty) (S.empty #(hash #hsz))); assert (S.equal (merge_hs #_ #f (empty_hashes len) (empty_hashes len)) (S.cons S.empty (merge_hs #_ #f (empty_hashes (len - 1)) (empty_hashes (len - 1))))); merge_hs_empty #_ #f (len - 1)) val merge_hs_index: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> hs1:hashess -> hs2:hashess{S.length hs1 = S.length hs2} -> i:nat{i < S.length hs1} -> Lemma (requires True) (ensures S.equal (S.index (merge_hs #_ #f hs1 hs2) i) (S.append (S.index hs1 i) (S.index hs2 i))) (decreases (S.length hs1)) [SMTPat (S.index (merge_hs #_ #f hs1 hs2) i)] let rec merge_hs_index #hsz #f hs1 hs2 i = if S.length hs1 = 0 then () else if i = 0 then () else merge_hs_index #_ #f (S.tail hs1) (S.tail hs2) (i - 1) val merge_hs_slice_equal: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> ahs1:hashess #hsz -> ahs2:hashess #hsz {S.length ahs1 = S.length ahs2} -> bhs1:hashess #hsz -> bhs2:hashess #hsz {S.length bhs1 = S.length bhs2} -> i:nat -> j:nat{i <= j && j <= S.length ahs1 && j <= S.length bhs1} -> Lemma (requires S.equal (S.slice ahs1 i j) (S.slice bhs1 i j) /\ S.equal (S.slice ahs2 i j) (S.slice bhs2 i j)) (ensures S.equal (S.slice (merge_hs #_ #f ahs1 ahs2) i j) (S.slice (merge_hs #_ #f bhs1 bhs2) i j)) (decreases (j - i)) let rec merge_hs_slice_equal #_ #f ahs1 ahs2 bhs1 bhs2 i j = if i = j then () else (assert (S.index ahs1 i == S.index bhs1 i); assert (S.index ahs2 i == S.index bhs2 i); merge_hs_slice_equal #_ #f ahs1 ahs2 bhs1 bhs2 (i + 1) j) val merge_hs_upd: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> hs1:hashess #hsz -> hs2:hashess #hsz {S.length hs1 = S.length hs2} -> i:nat{i < S.length hs1} -> v1:hashes #hsz -> v2:hashes #hsz -> Lemma (requires S.equal (S.append (S.index hs1 i) (S.index hs2 i)) (S.append v1 v2)) (ensures S.equal (merge_hs #_ #f hs1 hs2) (merge_hs #_ #f (S.upd hs1 i v1) (S.upd hs2 i v2))) (decreases i) let rec merge_hs_upd #_ #f hs1 hs2 i v1 v2 = if S.length hs1 = 0 then () else if i = 0 then () else merge_hs_upd #_ #f (S.tail hs1) (S.tail hs2) (i - 1) v1 v2 val mt_olds_inv: #hsz:pos -> lv:nat{lv <= 32} -> i:nat -> olds:hashess #hsz {S.length olds = 32} -> GTot Type0 (decreases (32 - lv)) let rec mt_olds_inv #hsz lv i olds = if lv = 32 then true else (let ofs = offset_of i in S.length (S.index olds lv) == ofs /\ mt_olds_inv #hsz (lv + 1) (i / 2) olds) val mt_olds_inv_equiv: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> lv:nat{lv <= 32} -> i:nat -> olds1:hashess #hsz {S.length olds1 = 32} -> olds2:hashess #hsz {S.length olds2 = 32} -> Lemma (requires mt_olds_inv #hsz lv i olds1 /\ S.equal (S.slice olds1 lv 32) (S.slice olds2 lv 32)) (ensures mt_olds_inv #hsz lv i olds2) (decreases (32 - lv)) let rec mt_olds_inv_equiv #hsz #f lv i olds1 olds2 = if lv = 32 then () else (assert (S.index olds1 lv == S.index olds2 lv); mt_olds_inv_equiv #_ #f (lv + 1) (i / 2) olds1 olds2) val mt_olds_hs_lth_inv_ok: #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 #hsz lv hs i j} -> Lemma (requires True) (ensures mt_hashes_lth_inv #hsz lv j (merge_hs #_ #f olds hs)) (decreases (32 - lv)) let rec mt_olds_hs_lth_inv_ok #hsz #f lv i j olds hs = if lv = 32 then () else (mt_olds_hs_lth_inv_ok #_ #f (lv + 1) (i / 2) (j / 2) olds hs) val mt_olds_hs_inv: #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 #hsz lv hs i j} -> GTot Type0 let mt_olds_hs_inv #hsz #f lv i j olds hs = mt_olds_hs_lth_inv_ok #_ #f lv i j olds hs; mt_hashes_inv #_ #f lv j (merge_hs #_ #f olds hs) // Relation between valid internal hashes (satisfying `mt_olds_hs_inv`) and // the spec. While giving such relation, all rightmost hashes are recovered. // Note that `MT?.rhs` after `construct_rhs` does NOT contain all rightmost // hashes; it has partial rightmost hashes that are enough to calculate // Merkle paths. val log2: n:nat{n > 0} -> GTot (c:nat{pow2 c <= n && n < pow2 (c+1)}) let rec log2 n = if n = 1 then 0 else 1 + log2 (n / 2) val log2_bound: n:nat{n > 0} -> c:nat{n < pow2 c} -> Lemma (log2 n <= c-1) let rec log2_bound n c = if n = 1 then () else log2_bound (n / 2) (c - 1) val log2_div: n:nat{n > 1} -> Lemma (log2 (n / 2) = log2 n - 1) let log2_div n = () val log2c: n:nat -> GTot (c:nat{c = 0 || (pow2 (c-1) <= n && n < pow2 c)}) let log2c n = if n = 0 then 0 else (log2 n + 1) val log2c_div: n:nat{n > 0} -> Lemma (log2c (n / 2) = log2c n - 1) let log2c_div n = () val log2c_bound: n:nat -> c:nat{n < pow2 c} -> Lemma (log2c n <= c) let rec log2c_bound n c = if n = 0 then () else log2c_bound (n / 2) (c - 1) val mt_hashes_lth_inv_log: #hsz:pos -> j:nat -> fhs:hashess #hsz {S.length fhs = log2c j} -> GTot Type0 (decreases j) let rec mt_hashes_lth_inv_log #hsz j fhs = if j = 0 then true else (S.length (S.head fhs) == j /\ mt_hashes_lth_inv_log #hsz (j / 2) (S.tail fhs)) #pop-options #push-options "--max_fuel 2" val mt_hashes_lth_inv_log_next: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> j:nat{j > 1} -> fhs:hashess #hsz {S.length fhs = log2c j} -> Lemma (requires mt_hashes_lth_inv_log #hsz j fhs) (ensures S.length (S.head fhs) == j /\ S.length (S.head (S.tail fhs)) == j / 2) let mt_hashes_lth_inv_log_next #_ #_ _ _ = () val mt_hashes_inv_log: #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} -> GTot Type0 (decreases j) let rec mt_hashes_inv_log #hsz #f j fhs = if j <= 1 then true else (mt_hashes_next_rel #_ #f j (S.index fhs 0) (S.index fhs 1) /\ mt_hashes_inv_log #_ #f (j / 2) (S.tail fhs)) val mt_hashes_lth_inv_log_converted_: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> lv:nat{lv <= 32} -> j:nat{j < pow2 (32 - lv)} -> fhs:hashess #hsz {S.length fhs = 32} -> Lemma (requires mt_hashes_lth_inv #hsz lv j fhs) (ensures (log2c_bound j (32 - lv); mt_hashes_lth_inv_log #hsz j (S.slice fhs lv (lv + log2c j)))) (decreases j) let rec mt_hashes_lth_inv_log_converted_ #_ #f lv j fhs = if j = 0 then () else (log2c_bound (j / 2) (32 - (lv + 1)); mt_hashes_lth_inv_log_converted_ #_ #f (lv + 1) (j / 2) fhs) val mt_hashes_lth_inv_log_converted: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> j:nat{j < pow2 32} -> fhs:hashess #hsz {S.length fhs = 32} -> Lemma (requires mt_hashes_lth_inv #hsz 0 j fhs) (ensures (log2c_bound j 32; mt_hashes_lth_inv_log #hsz j (S.slice fhs 0 (log2c j)))) let mt_hashes_lth_inv_log_converted #_ #f j fhs = mt_hashes_lth_inv_log_converted_ #_ #f 0 j fhs val mt_hashes_inv_log_converted_: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> lv:nat{lv <= 32} -> j:nat{j > 0 && j < pow2 (32 - lv)} -> fhs:hashess #hsz {S.length fhs = 32 /\ mt_hashes_lth_inv #hsz lv j fhs} -> Lemma (requires mt_hashes_inv #_ #f lv j fhs) (ensures (log2c_bound j (32 - lv); mt_hashes_lth_inv_log_converted_ #_ #f lv j fhs; mt_hashes_inv_log #_ #f j (S.slice fhs lv (lv + log2c j)))) (decreases j) #pop-options #push-options "--z3rlimit 100 --initial_fuel 2 --max_fuel 2" let rec mt_hashes_inv_log_converted_ #_ #f lv j fhs = if j = 1 then () else (log2c_bound (j / 2) (32 - (lv + 1)); mt_hashes_lth_inv_log_converted_ #_ #f (lv + 1) (j / 2) fhs; mt_hashes_inv_log_converted_ #_ #f (lv + 1) (j / 2) fhs) #pop-options val mt_hashes_inv_log_converted: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> j:nat{j > 0 && j < pow2 32} -> fhs:hashess #hsz {S.length fhs = 32 /\ mt_hashes_lth_inv #hsz 0 j fhs} -> Lemma (requires mt_hashes_inv #_ #f 0 j fhs) (ensures (log2c_bound j 32; mt_hashes_lth_inv_log_converted_ #_ #f 0 j fhs; mt_hashes_inv_log #_ #f j (S.slice fhs 0 (log2c j)))) let mt_hashes_inv_log_converted #_ #f j fhs = mt_hashes_inv_log_converted_ #_ #f 0 j fhs val hash_seq_lift: #hsz:pos -> hs:hashes #hsz -> GTot (shs:MTS.hashes #hsz {S.length shs = S.length hs}) (decreases (S.length hs)) let rec hash_seq_lift #hsz hs = if S.length hs = 0 then S.empty else S.cons (MTS.HRaw (S.head hs)) (hash_seq_lift #hsz (S.tail hs)) #push-options "--z3rlimit 50 --initial_fuel 2 --max_fuel 2" val hash_seq_lift_index: #hsz:pos -> hs:hashes #hsz -> Lemma (requires True) (ensures forall (i:nat{i < S.length hs}). S.index (hash_seq_lift #hsz hs) i == MTS.HRaw (S.index hs i)) (decreases (S.length hs)) let rec hash_seq_lift_index #hsz hs = if S.length hs = 0 then () else hash_seq_lift_index #hsz (S.tail hs) #pop-options val create_pads: #hsz:pos -> len:nat -> GTot (pads:MTS.hashes #hsz {S.length pads = len}) let create_pads #hsz len = S.create len (MTS.HPad #hsz) val hash_seq_spec: #hsz:pos -> hs:hashes #hsz {S.length hs > 0} -> GTot (MTS.merkle_tree #hsz (log2c (S.length hs))) let hash_seq_spec #hsz hs = S.append (hash_seq_lift #hsz hs) (create_pads (pow2 (log2c (S.length hs)) - S.length hs)) val hash_seq_spec_index_raw: #hsz:pos -> hs:hashes #hsz {S.length hs > 0} -> i:nat{i < S.length hs} -> Lemma (S.index (hash_seq_spec #hsz hs) i == MTS.HRaw #hsz (S.index hs i)) let hash_seq_spec_index_raw #hsz hs i = hash_seq_lift_index #hsz hs // Now about recovering rightmost hashes #push-options "--z3rlimit 50 --initial_fuel 1 --max_fuel 1" val mt_hashes_next_rel_lift_even: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> j:nat{j > 1} -> hs:hashes #hsz {S.length hs = j} -> nhs:hashes #hsz {S.length nhs = j / 2} -> Lemma (requires j % 2 = 0 /\ mt_hashes_next_rel #_ #f j hs nhs) (ensures MTS.mt_next_rel #_ #f (log2c j)
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "MerkleTree.Spec.fst.checked", "MerkleTree.New.High.fst.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Ghost.fsti.checked", "FStar.Classical.fsti.checked" ], "interface_file": false, "source_file": "MerkleTree.New.High.Correct.Base.fst" }
[ { "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": 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": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
j: Prims.nat{j > 1} -> hs: MerkleTree.New.High.hashes{FStar.Seq.Base.length hs = j} -> nhs: MerkleTree.New.High.hashes{FStar.Seq.Base.length nhs = j / 2} -> FStar.Pervasives.Lemma (requires j % 2 = 0 /\ MerkleTree.New.High.Correct.Base.mt_hashes_next_rel j hs nhs) (ensures MerkleTree.Spec.mt_next_rel (MerkleTree.New.High.Correct.Base.log2c j) (MerkleTree.New.High.Correct.Base.hash_seq_spec hs) (MerkleTree.New.High.Correct.Base.hash_seq_spec nhs))
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "Prims.pos", "MerkleTree.Spec.hash_fun_t", "Prims.nat", "Prims.b2t", "Prims.op_GreaterThan", "MerkleTree.New.High.hashes", "Prims.op_Equality", "FStar.Seq.Base.length", "MerkleTree.New.High.hash", "Prims.int", "Prims.op_Division", "MerkleTree.New.High.Correct.Base.hash_seq_lift_index", "Prims.unit" ]
[]
true
false
true
false
false
let mt_hashes_next_rel_lift_even #hsz #_ j hs nhs =
hash_seq_lift_index #hsz hs; hash_seq_lift_index #hsz nhs
false
MerkleTree.New.High.Correct.Base.fst
MerkleTree.New.High.Correct.Base.hash_seq_spec_full_next
val hash_seq_spec_full_next: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> j:nat{j > 1} -> hs:hashes #hsz {S.length hs = j} -> nhs:hashes #hsz {S.length nhs = j / 2} -> acc:hash #hsz -> actd:bool -> nacc:hash #hsz -> nactd:bool -> Lemma (requires mt_hashes_next_rel #_ #f j hs nhs /\ nacc == (if j % 2 = 0 then acc else if actd then f (S.last hs) acc else S.last hs) /\ nactd == (actd || j % 2 = 1)) (ensures S.equal (hash_seq_spec_full #_ #f nhs nacc nactd) (MTS.mt_next_lv #_ #f #(log2c j) (hash_seq_spec_full #_ #f hs acc actd)))
val hash_seq_spec_full_next: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> j:nat{j > 1} -> hs:hashes #hsz {S.length hs = j} -> nhs:hashes #hsz {S.length nhs = j / 2} -> acc:hash #hsz -> actd:bool -> nacc:hash #hsz -> nactd:bool -> Lemma (requires mt_hashes_next_rel #_ #f j hs nhs /\ nacc == (if j % 2 = 0 then acc else if actd then f (S.last hs) acc else S.last hs) /\ nactd == (actd || j % 2 = 1)) (ensures S.equal (hash_seq_spec_full #_ #f nhs nacc nactd) (MTS.mt_next_lv #_ #f #(log2c j) (hash_seq_spec_full #_ #f hs acc actd)))
let hash_seq_spec_full_next #_ #f j hs nhs acc actd nacc nactd = if j % 2 = 0 then hash_seq_spec_full_even_next #_ #f j hs nhs acc actd else hash_seq_spec_full_odd_next #_ #f j hs nhs acc actd nacc
{ "file_name": "src/MerkleTree.New.High.Correct.Base.fst", "git_rev": "7d7bdc20f2033171e279c176b26e84f9069d23c6", "git_url": "https://github.com/hacl-star/merkle-tree.git", "project_name": "merkle-tree" }
{ "end_col": 63, "end_line": 595, "start_col": 0, "start_line": 592 }
module MerkleTree.New.High.Correct.Base open FStar.Classical open FStar.Ghost open FStar.Seq module S = FStar.Seq module MTS = MerkleTree.Spec open MerkleTree.New.High #set-options "--z3rlimit 40 --max_fuel 0 --max_ifuel 0" /// Sequence helpers val seq_prefix: #a:Type -> s1:S.seq a -> s2:S.seq a{S.length s1 <= S.length s2} -> GTot Type0 let seq_prefix #a s1 s2 = S.equal s1 (S.slice s2 0 (S.length s1)) val seq_head_cons: #a:Type -> x:a -> s:S.seq a -> Lemma (S.head (S.cons x s) == x) [SMTPat (S.cons x s)] let seq_head_cons #a x s = () val seq_tail_cons: #a:Type -> x:a -> s:S.seq a -> Lemma (S.equal (S.tail (S.cons x s)) s) [SMTPat (S.cons x s)] let seq_tail_cons #a x s = () /// Invariants and simulation relation of high-level Merkle tree design // Invariants of internal hashes val empty_hashes: (#hsz:pos) -> (len:nat) -> GTot (hs:hashess #hsz {S.length hs = len}) let empty_hashes #hsz len = S.create len S.empty val empty_hashes_head: #hsz:pos -> len:nat{len > 0} -> Lemma (S.head (empty_hashes #hsz len) == S.empty) let empty_hashes_head #_ _ = () val empty_hashes_tail: #hsz:pos -> len:nat{len > 0} -> Lemma (S.equal (S.tail (empty_hashes len)) (empty_hashes #hsz (len - 1))) let empty_hashes_tail #_ _ = () #push-options "--max_fuel 1" val mt_hashes_lth_inv: #hsz:pos -> lv:nat{lv <= 32} -> j:nat{j < pow2 (32 - lv)} -> fhs:hashess #hsz {S.length fhs = 32} -> GTot Type0 (decreases (32 - lv)) let rec mt_hashes_lth_inv #hsz lv j fhs = if lv = 32 then true else (S.length (S.index fhs lv) == j /\ mt_hashes_lth_inv (lv + 1) (j / 2) fhs) val mt_hashes_lth_inv_empty: #hsz:pos -> lv:nat{lv <= 32} -> Lemma (requires True) (ensures mt_hashes_lth_inv lv 0 (empty_hashes #hsz 32)) (decreases (32 - lv)) let rec mt_hashes_lth_inv_empty #hsz lv = if lv = 32 then () else mt_hashes_lth_inv_empty #hsz (lv + 1) val mt_hashes_next_rel: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> j:nat -> hs:hashes #hsz {S.length hs = j} -> nhs:hashes #hsz {S.length nhs = j / 2} -> GTot Type0 let mt_hashes_next_rel #hsz #f j hs nhs = forall (i:nat{i < j / 2}). S.index nhs i == f (S.index hs (op_Multiply 2 i)) (S.index hs (op_Multiply 2 i + 1)) #pop-options #push-options "--max_fuel 2" val mt_hashes_inv: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> lv:nat{lv < 32} -> j:nat{j < pow2 (32 - lv)} -> fhs:hashess #hsz {S.length fhs = 32 /\ mt_hashes_lth_inv lv j fhs} -> GTot Type0 (decreases (32 - lv)) let rec mt_hashes_inv #hsz #f lv j fhs = if lv = 31 then true else (mt_hashes_next_rel #_ #f j (S.index fhs lv) (S.index fhs (lv + 1)) /\ mt_hashes_inv #_ #f (lv + 1) (j / 2) fhs) val mt_hashes_inv_empty: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> lv:nat{lv < 32} -> Lemma (requires True) (ensures (mt_hashes_lth_inv_empty #hsz lv; mt_hashes_inv #hsz #f lv 0 (empty_hashes #hsz 32))) (decreases (32 - lv)) let rec mt_hashes_inv_empty #hsz #f lv = if lv = 31 then () else (mt_hashes_lth_inv_empty #hsz (lv + 1); mt_hashes_inv_empty #_ #f (lv + 1)) val mt_hashes_lth_inv_equiv: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> lv:nat{lv < 32} -> j:nat{j < pow2 (32 - lv)} -> fhs1:hashess{S.length fhs1 = 32} -> fhs2:hashess{S.length fhs2 = 32} -> Lemma (requires mt_hashes_lth_inv lv j fhs1 /\ S.equal (S.slice fhs1 lv 32) (S.slice fhs2 lv 32)) (ensures mt_hashes_lth_inv #hsz lv j fhs2) (decreases (32 - lv)) let rec mt_hashes_lth_inv_equiv #hsz #f lv j fhs1 fhs2 = if lv = 31 then () else (assert (S.index fhs1 lv == S.index fhs2 lv); mt_hashes_lth_inv_equiv #_ #f (lv + 1) (j / 2) fhs1 fhs2) #pop-options #push-options "--max_fuel 1" val mt_hashes_inv_equiv: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> lv:nat{lv < 32} -> j:nat{j < pow2 (32 - lv)} -> fhs1:hashess #hsz {S.length fhs1 = 32 /\ mt_hashes_lth_inv lv j fhs1} -> fhs2:hashess #hsz {S.length fhs2 = 32 /\ mt_hashes_lth_inv lv j fhs2} -> Lemma (requires mt_hashes_inv #_ #f lv j fhs1 /\ S.equal (S.slice fhs1 lv 32) (S.slice fhs2 lv 32)) (ensures mt_hashes_inv #_ #f lv j fhs2) (decreases (32 - lv)) let rec mt_hashes_inv_equiv #hsz #f lv j fhs1 fhs2 = if lv = 31 then () else (assert (S.index fhs1 lv == S.index fhs2 lv); assert (S.index fhs1 (lv + 1) == S.index fhs2 (lv + 1)); mt_hashes_inv_equiv #_ #f (lv + 1) (j / 2) fhs1 fhs2) val merge_hs: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> hs1:hashess #hsz -> hs2:hashess #hsz {S.length hs1 = S.length hs2} -> GTot (mhs:hashess #hsz {S.length mhs = S.length hs1}) (decreases (S.length hs1)) let rec merge_hs #hsz #f hs1 hs2 = if S.length hs1 = 0 then S.empty else (S.cons (S.append (S.head hs1) (S.head hs2)) (merge_hs #_ #f (S.tail hs1) (S.tail hs2))) val merge_hs_empty: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> len:nat -> Lemma (S.equal (merge_hs #_ #f (empty_hashes #hsz len) (empty_hashes #hsz len)) (empty_hashes #hsz len)) let rec merge_hs_empty #hsz #f len = if len = 0 then () else (empty_hashes_head #hsz len; empty_hashes_tail #hsz len; assert (S.equal (S.append #(hash #hsz) S.empty S.empty) (S.empty #(hash #hsz))); assert (S.equal (merge_hs #_ #f (empty_hashes len) (empty_hashes len)) (S.cons S.empty (merge_hs #_ #f (empty_hashes (len - 1)) (empty_hashes (len - 1))))); merge_hs_empty #_ #f (len - 1)) val merge_hs_index: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> hs1:hashess -> hs2:hashess{S.length hs1 = S.length hs2} -> i:nat{i < S.length hs1} -> Lemma (requires True) (ensures S.equal (S.index (merge_hs #_ #f hs1 hs2) i) (S.append (S.index hs1 i) (S.index hs2 i))) (decreases (S.length hs1)) [SMTPat (S.index (merge_hs #_ #f hs1 hs2) i)] let rec merge_hs_index #hsz #f hs1 hs2 i = if S.length hs1 = 0 then () else if i = 0 then () else merge_hs_index #_ #f (S.tail hs1) (S.tail hs2) (i - 1) val merge_hs_slice_equal: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> ahs1:hashess #hsz -> ahs2:hashess #hsz {S.length ahs1 = S.length ahs2} -> bhs1:hashess #hsz -> bhs2:hashess #hsz {S.length bhs1 = S.length bhs2} -> i:nat -> j:nat{i <= j && j <= S.length ahs1 && j <= S.length bhs1} -> Lemma (requires S.equal (S.slice ahs1 i j) (S.slice bhs1 i j) /\ S.equal (S.slice ahs2 i j) (S.slice bhs2 i j)) (ensures S.equal (S.slice (merge_hs #_ #f ahs1 ahs2) i j) (S.slice (merge_hs #_ #f bhs1 bhs2) i j)) (decreases (j - i)) let rec merge_hs_slice_equal #_ #f ahs1 ahs2 bhs1 bhs2 i j = if i = j then () else (assert (S.index ahs1 i == S.index bhs1 i); assert (S.index ahs2 i == S.index bhs2 i); merge_hs_slice_equal #_ #f ahs1 ahs2 bhs1 bhs2 (i + 1) j) val merge_hs_upd: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> hs1:hashess #hsz -> hs2:hashess #hsz {S.length hs1 = S.length hs2} -> i:nat{i < S.length hs1} -> v1:hashes #hsz -> v2:hashes #hsz -> Lemma (requires S.equal (S.append (S.index hs1 i) (S.index hs2 i)) (S.append v1 v2)) (ensures S.equal (merge_hs #_ #f hs1 hs2) (merge_hs #_ #f (S.upd hs1 i v1) (S.upd hs2 i v2))) (decreases i) let rec merge_hs_upd #_ #f hs1 hs2 i v1 v2 = if S.length hs1 = 0 then () else if i = 0 then () else merge_hs_upd #_ #f (S.tail hs1) (S.tail hs2) (i - 1) v1 v2 val mt_olds_inv: #hsz:pos -> lv:nat{lv <= 32} -> i:nat -> olds:hashess #hsz {S.length olds = 32} -> GTot Type0 (decreases (32 - lv)) let rec mt_olds_inv #hsz lv i olds = if lv = 32 then true else (let ofs = offset_of i in S.length (S.index olds lv) == ofs /\ mt_olds_inv #hsz (lv + 1) (i / 2) olds) val mt_olds_inv_equiv: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> lv:nat{lv <= 32} -> i:nat -> olds1:hashess #hsz {S.length olds1 = 32} -> olds2:hashess #hsz {S.length olds2 = 32} -> Lemma (requires mt_olds_inv #hsz lv i olds1 /\ S.equal (S.slice olds1 lv 32) (S.slice olds2 lv 32)) (ensures mt_olds_inv #hsz lv i olds2) (decreases (32 - lv)) let rec mt_olds_inv_equiv #hsz #f lv i olds1 olds2 = if lv = 32 then () else (assert (S.index olds1 lv == S.index olds2 lv); mt_olds_inv_equiv #_ #f (lv + 1) (i / 2) olds1 olds2) val mt_olds_hs_lth_inv_ok: #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 #hsz lv hs i j} -> Lemma (requires True) (ensures mt_hashes_lth_inv #hsz lv j (merge_hs #_ #f olds hs)) (decreases (32 - lv)) let rec mt_olds_hs_lth_inv_ok #hsz #f lv i j olds hs = if lv = 32 then () else (mt_olds_hs_lth_inv_ok #_ #f (lv + 1) (i / 2) (j / 2) olds hs) val mt_olds_hs_inv: #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 #hsz lv hs i j} -> GTot Type0 let mt_olds_hs_inv #hsz #f lv i j olds hs = mt_olds_hs_lth_inv_ok #_ #f lv i j olds hs; mt_hashes_inv #_ #f lv j (merge_hs #_ #f olds hs) // Relation between valid internal hashes (satisfying `mt_olds_hs_inv`) and // the spec. While giving such relation, all rightmost hashes are recovered. // Note that `MT?.rhs` after `construct_rhs` does NOT contain all rightmost // hashes; it has partial rightmost hashes that are enough to calculate // Merkle paths. val log2: n:nat{n > 0} -> GTot (c:nat{pow2 c <= n && n < pow2 (c+1)}) let rec log2 n = if n = 1 then 0 else 1 + log2 (n / 2) val log2_bound: n:nat{n > 0} -> c:nat{n < pow2 c} -> Lemma (log2 n <= c-1) let rec log2_bound n c = if n = 1 then () else log2_bound (n / 2) (c - 1) val log2_div: n:nat{n > 1} -> Lemma (log2 (n / 2) = log2 n - 1) let log2_div n = () val log2c: n:nat -> GTot (c:nat{c = 0 || (pow2 (c-1) <= n && n < pow2 c)}) let log2c n = if n = 0 then 0 else (log2 n + 1) val log2c_div: n:nat{n > 0} -> Lemma (log2c (n / 2) = log2c n - 1) let log2c_div n = () val log2c_bound: n:nat -> c:nat{n < pow2 c} -> Lemma (log2c n <= c) let rec log2c_bound n c = if n = 0 then () else log2c_bound (n / 2) (c - 1) val mt_hashes_lth_inv_log: #hsz:pos -> j:nat -> fhs:hashess #hsz {S.length fhs = log2c j} -> GTot Type0 (decreases j) let rec mt_hashes_lth_inv_log #hsz j fhs = if j = 0 then true else (S.length (S.head fhs) == j /\ mt_hashes_lth_inv_log #hsz (j / 2) (S.tail fhs)) #pop-options #push-options "--max_fuel 2" val mt_hashes_lth_inv_log_next: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> j:nat{j > 1} -> fhs:hashess #hsz {S.length fhs = log2c j} -> Lemma (requires mt_hashes_lth_inv_log #hsz j fhs) (ensures S.length (S.head fhs) == j /\ S.length (S.head (S.tail fhs)) == j / 2) let mt_hashes_lth_inv_log_next #_ #_ _ _ = () val mt_hashes_inv_log: #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} -> GTot Type0 (decreases j) let rec mt_hashes_inv_log #hsz #f j fhs = if j <= 1 then true else (mt_hashes_next_rel #_ #f j (S.index fhs 0) (S.index fhs 1) /\ mt_hashes_inv_log #_ #f (j / 2) (S.tail fhs)) val mt_hashes_lth_inv_log_converted_: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> lv:nat{lv <= 32} -> j:nat{j < pow2 (32 - lv)} -> fhs:hashess #hsz {S.length fhs = 32} -> Lemma (requires mt_hashes_lth_inv #hsz lv j fhs) (ensures (log2c_bound j (32 - lv); mt_hashes_lth_inv_log #hsz j (S.slice fhs lv (lv + log2c j)))) (decreases j) let rec mt_hashes_lth_inv_log_converted_ #_ #f lv j fhs = if j = 0 then () else (log2c_bound (j / 2) (32 - (lv + 1)); mt_hashes_lth_inv_log_converted_ #_ #f (lv + 1) (j / 2) fhs) val mt_hashes_lth_inv_log_converted: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> j:nat{j < pow2 32} -> fhs:hashess #hsz {S.length fhs = 32} -> Lemma (requires mt_hashes_lth_inv #hsz 0 j fhs) (ensures (log2c_bound j 32; mt_hashes_lth_inv_log #hsz j (S.slice fhs 0 (log2c j)))) let mt_hashes_lth_inv_log_converted #_ #f j fhs = mt_hashes_lth_inv_log_converted_ #_ #f 0 j fhs val mt_hashes_inv_log_converted_: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> lv:nat{lv <= 32} -> j:nat{j > 0 && j < pow2 (32 - lv)} -> fhs:hashess #hsz {S.length fhs = 32 /\ mt_hashes_lth_inv #hsz lv j fhs} -> Lemma (requires mt_hashes_inv #_ #f lv j fhs) (ensures (log2c_bound j (32 - lv); mt_hashes_lth_inv_log_converted_ #_ #f lv j fhs; mt_hashes_inv_log #_ #f j (S.slice fhs lv (lv + log2c j)))) (decreases j) #pop-options #push-options "--z3rlimit 100 --initial_fuel 2 --max_fuel 2" let rec mt_hashes_inv_log_converted_ #_ #f lv j fhs = if j = 1 then () else (log2c_bound (j / 2) (32 - (lv + 1)); mt_hashes_lth_inv_log_converted_ #_ #f (lv + 1) (j / 2) fhs; mt_hashes_inv_log_converted_ #_ #f (lv + 1) (j / 2) fhs) #pop-options val mt_hashes_inv_log_converted: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> j:nat{j > 0 && j < pow2 32} -> fhs:hashess #hsz {S.length fhs = 32 /\ mt_hashes_lth_inv #hsz 0 j fhs} -> Lemma (requires mt_hashes_inv #_ #f 0 j fhs) (ensures (log2c_bound j 32; mt_hashes_lth_inv_log_converted_ #_ #f 0 j fhs; mt_hashes_inv_log #_ #f j (S.slice fhs 0 (log2c j)))) let mt_hashes_inv_log_converted #_ #f j fhs = mt_hashes_inv_log_converted_ #_ #f 0 j fhs val hash_seq_lift: #hsz:pos -> hs:hashes #hsz -> GTot (shs:MTS.hashes #hsz {S.length shs = S.length hs}) (decreases (S.length hs)) let rec hash_seq_lift #hsz hs = if S.length hs = 0 then S.empty else S.cons (MTS.HRaw (S.head hs)) (hash_seq_lift #hsz (S.tail hs)) #push-options "--z3rlimit 50 --initial_fuel 2 --max_fuel 2" val hash_seq_lift_index: #hsz:pos -> hs:hashes #hsz -> Lemma (requires True) (ensures forall (i:nat{i < S.length hs}). S.index (hash_seq_lift #hsz hs) i == MTS.HRaw (S.index hs i)) (decreases (S.length hs)) let rec hash_seq_lift_index #hsz hs = if S.length hs = 0 then () else hash_seq_lift_index #hsz (S.tail hs) #pop-options val create_pads: #hsz:pos -> len:nat -> GTot (pads:MTS.hashes #hsz {S.length pads = len}) let create_pads #hsz len = S.create len (MTS.HPad #hsz) val hash_seq_spec: #hsz:pos -> hs:hashes #hsz {S.length hs > 0} -> GTot (MTS.merkle_tree #hsz (log2c (S.length hs))) let hash_seq_spec #hsz hs = S.append (hash_seq_lift #hsz hs) (create_pads (pow2 (log2c (S.length hs)) - S.length hs)) val hash_seq_spec_index_raw: #hsz:pos -> hs:hashes #hsz {S.length hs > 0} -> i:nat{i < S.length hs} -> Lemma (S.index (hash_seq_spec #hsz hs) i == MTS.HRaw #hsz (S.index hs i)) let hash_seq_spec_index_raw #hsz hs i = hash_seq_lift_index #hsz hs // Now about recovering rightmost hashes #push-options "--z3rlimit 50 --initial_fuel 1 --max_fuel 1" val mt_hashes_next_rel_lift_even: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> j:nat{j > 1} -> hs:hashes #hsz {S.length hs = j} -> nhs:hashes #hsz {S.length nhs = j / 2} -> Lemma (requires j % 2 = 0 /\ mt_hashes_next_rel #_ #f j hs nhs) (ensures MTS.mt_next_rel #_ #f (log2c j) (hash_seq_spec #hsz hs) (hash_seq_spec #hsz nhs)) let mt_hashes_next_rel_lift_even #hsz #_ j hs nhs = hash_seq_lift_index #hsz hs; hash_seq_lift_index #hsz nhs val mt_hashes_next_rel_lift_odd: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> j:nat{j > 1} -> hs:hashes #hsz {S.length hs = j} -> nhs:hashes #hsz {S.length nhs = j / 2} -> Lemma (requires j % 2 = 1 /\ mt_hashes_next_rel #_ #f j hs nhs) (ensures MTS.mt_next_rel #_ #f (log2c j) (hash_seq_spec #hsz hs) (S.upd (hash_seq_spec #hsz nhs) (S.length nhs) (MTS.HRaw (S.last hs)))) let mt_hashes_next_rel_lift_odd #hsz #_ j hs nhs = log2c_div j; hash_seq_lift_index #hsz hs; hash_seq_lift_index #hsz nhs val mt_hashes_next_rel_next_even: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> j:nat{j > 1} -> hs:hashes #hsz {S.length hs = j} -> nhs:hashes #hsz {S.length nhs = j / 2} -> Lemma (requires j % 2 = 0 /\ mt_hashes_next_rel #_ #f j hs nhs) (ensures S.equal (hash_seq_spec #hsz nhs) (MTS.mt_next_lv #_ #f #(log2c j) (hash_seq_spec #hsz hs))) let mt_hashes_next_rel_next_even #hsz #f j hs nhs = log2c_div j; mt_hashes_next_rel_lift_even #_ #f j hs nhs; MTS.mt_next_rel_next_lv #_ #f (log2c j) (hash_seq_spec #hsz hs) (hash_seq_spec #hsz nhs) val hash_seq_spec_full: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> hs:hashes #hsz {S.length hs > 0} -> acc:hash #hsz -> actd:bool -> GTot (MTS.merkle_tree #hsz (log2c (S.length hs))) let hash_seq_spec_full #hsz #f hs acc actd = if actd then (S.upd (hash_seq_spec #hsz hs) (S.length hs) (MTS.HRaw acc)) else hash_seq_spec #hsz hs val hash_seq_spec_full_index_raw: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> hs:hashes #hsz {S.length hs > 0} -> acc:hash #hsz -> actd:bool -> i:nat{i < S.length hs} -> Lemma (S.index (hash_seq_spec_full #_ #f hs acc actd) i == MTS.HRaw (S.index hs i)) let hash_seq_spec_full_index_raw #hsz #_ hs acc actd i = hash_seq_spec_index_raw #hsz hs i val hash_seq_spec_full_case_true: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> hs:hashes #hsz {S.length hs > 0} -> acc:hash #hsz -> Lemma (S.index (hash_seq_spec_full #_ #f hs acc true) (S.length hs) == MTS.HRaw acc) let hash_seq_spec_full_case_true #_ #_ _ _ = () val hash_seq_spec_full_even_next: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> j:nat{j > 0} -> hs:hashes #hsz {S.length hs = j} -> nhs:hashes #hsz {S.length nhs = j / 2} -> acc:hash #hsz -> actd:bool -> Lemma (requires j % 2 = 0 /\ mt_hashes_next_rel #_ #f j hs nhs) (ensures S.equal (hash_seq_spec_full #_ #f nhs acc actd) (MTS.mt_next_lv #_ #f #(log2c j) (hash_seq_spec_full #_ #f hs acc actd))) #restart-solver #push-options "--quake 1/3 --z3rlimit 100 --fuel 2 --ifuel 1" let hash_seq_spec_full_even_next #hsz #f j hs nhs acc actd = log2c_div j; mt_hashes_next_rel_lift_even #_ #f j hs nhs; if actd then begin MTS.mt_next_rel_upd_even_pad #_ #f (log2c j) (hash_seq_spec #hsz hs) (hash_seq_spec #hsz nhs) (S.length hs / 2) (MTS.HRaw acc); let n = log2c j in let mt = S.upd (hash_seq_spec #hsz hs) (S.length hs) (MTS.HRaw acc) in let nmt = S.upd (hash_seq_spec #hsz nhs) (S.length nhs) (MTS.HRaw acc) in // assume (MTS.mt_next_rel #_ #f n mt nmt); MTS.mt_next_rel_next_lv #_ #f n mt nmt end else MTS.mt_next_rel_next_lv #_ #f (log2c j) (hash_seq_spec_full #_ #f hs acc actd) (hash_seq_spec_full #_ #f nhs acc actd) #pop-options #push-options "--z3rlimit 80" val hash_seq_spec_full_odd_next: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> j:nat{j > 1} -> hs:hashes #hsz {S.length hs = j} -> nhs:hashes #hsz {S.length nhs = j / 2} -> acc:hash #hsz -> actd:bool -> nacc:hash #hsz -> Lemma (requires j % 2 = 1 /\ mt_hashes_next_rel #_ #f j hs nhs /\ nacc == (if actd then f (S.last hs) acc else S.last hs)) (ensures S.equal (hash_seq_spec_full #_ #f nhs nacc true) (MTS.mt_next_lv #_ #f #(log2c j) (hash_seq_spec_full #_ #f hs acc actd))) let hash_seq_spec_full_odd_next #hsz #f j hs nhs acc actd nacc = log2c_div j; mt_hashes_next_rel_lift_odd #_ #f j hs nhs; if actd then begin MTS.mt_next_rel_upd_odd #_ #f (log2c j) (hash_seq_spec #hsz hs) (S.upd (hash_seq_spec #hsz nhs) (S.length nhs) (MTS.HRaw (S.last hs))) (S.length nhs) (MTS.HRaw acc); MTS.mt_next_rel_next_lv #_ #f (log2c j) (S.upd (hash_seq_spec #hsz hs) (S.length hs) (MTS.HRaw acc)) (S.upd (hash_seq_spec #hsz nhs) (S.length nhs) (MTS.HRaw (f (S.last hs) acc))) end else MTS.mt_next_rel_next_lv #_ #f (log2c j) (hash_seq_spec_full #_ #f hs acc actd) (hash_seq_spec_full #_ #f nhs nacc true) #pop-options val hash_seq_spec_full_next: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> j:nat{j > 1} -> hs:hashes #hsz {S.length hs = j} -> nhs:hashes #hsz {S.length nhs = j / 2} -> acc:hash #hsz -> actd:bool -> nacc:hash #hsz -> nactd:bool -> Lemma (requires mt_hashes_next_rel #_ #f j hs nhs /\ nacc == (if j % 2 = 0 then acc else if actd then f (S.last hs) acc else S.last hs) /\ nactd == (actd || j % 2 = 1)) (ensures S.equal (hash_seq_spec_full #_ #f nhs nacc nactd)
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "MerkleTree.Spec.fst.checked", "MerkleTree.New.High.fst.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Ghost.fsti.checked", "FStar.Classical.fsti.checked" ], "interface_file": false, "source_file": "MerkleTree.New.High.Correct.Base.fst" }
[ { "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": 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": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
j: Prims.nat{j > 1} -> hs: MerkleTree.New.High.hashes{FStar.Seq.Base.length hs = j} -> nhs: MerkleTree.New.High.hashes{FStar.Seq.Base.length nhs = j / 2} -> acc: MerkleTree.New.High.hash -> actd: Prims.bool -> nacc: MerkleTree.New.High.hash -> nactd: Prims.bool -> FStar.Pervasives.Lemma (requires MerkleTree.New.High.Correct.Base.mt_hashes_next_rel j hs nhs /\ nacc == (match j % 2 = 0 with | true -> acc | _ -> (match actd with | true -> f (FStar.Seq.Properties.last hs) acc | _ -> FStar.Seq.Properties.last hs) <: b: Spec.Hash.Definitions.bytes { FStar.Seq.Base.length b = hsz \/ FStar.Seq.Base.length b = hsz \/ FStar.Seq.Base.length b = hsz }) /\ nactd == (actd || j % 2 = 1)) (ensures FStar.Seq.Base.equal (MerkleTree.New.High.Correct.Base.hash_seq_spec_full nhs nacc nactd) (MerkleTree.Spec.mt_next_lv (MerkleTree.New.High.Correct.Base.hash_seq_spec_full hs acc actd)))
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "Prims.pos", "MerkleTree.Spec.hash_fun_t", "Prims.nat", "Prims.b2t", "Prims.op_GreaterThan", "MerkleTree.New.High.hashes", "Prims.op_Equality", "FStar.Seq.Base.length", "MerkleTree.New.High.hash", "Prims.int", "Prims.op_Division", "Prims.bool", "Prims.op_Modulus", "MerkleTree.New.High.Correct.Base.hash_seq_spec_full_even_next", "MerkleTree.New.High.Correct.Base.hash_seq_spec_full_odd_next", "Prims.unit" ]
[]
false
false
true
false
false
let hash_seq_spec_full_next #_ #f j hs nhs acc actd nacc nactd =
if j % 2 = 0 then hash_seq_spec_full_even_next #_ #f j hs nhs acc actd else hash_seq_spec_full_odd_next #_ #f j hs nhs acc actd nacc
false
MerkleTree.New.High.Correct.Base.fst
MerkleTree.New.High.Correct.Base.mt_hashes_next_rel_lift_odd
val mt_hashes_next_rel_lift_odd: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> j:nat{j > 1} -> hs:hashes #hsz {S.length hs = j} -> nhs:hashes #hsz {S.length nhs = j / 2} -> Lemma (requires j % 2 = 1 /\ mt_hashes_next_rel #_ #f j hs nhs) (ensures MTS.mt_next_rel #_ #f (log2c j) (hash_seq_spec #hsz hs) (S.upd (hash_seq_spec #hsz nhs) (S.length nhs) (MTS.HRaw (S.last hs))))
val mt_hashes_next_rel_lift_odd: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> j:nat{j > 1} -> hs:hashes #hsz {S.length hs = j} -> nhs:hashes #hsz {S.length nhs = j / 2} -> Lemma (requires j % 2 = 1 /\ mt_hashes_next_rel #_ #f j hs nhs) (ensures MTS.mt_next_rel #_ #f (log2c j) (hash_seq_spec #hsz hs) (S.upd (hash_seq_spec #hsz nhs) (S.length nhs) (MTS.HRaw (S.last hs))))
let mt_hashes_next_rel_lift_odd #hsz #_ j hs nhs = log2c_div j; hash_seq_lift_index #hsz hs; hash_seq_lift_index #hsz nhs
{ "file_name": "src/MerkleTree.New.High.Correct.Base.fst", "git_rev": "7d7bdc20f2033171e279c176b26e84f9069d23c6", "git_url": "https://github.com/hacl-star/merkle-tree.git", "project_name": "merkle-tree" }
{ "end_col": 30, "end_line": 473, "start_col": 0, "start_line": 470 }
module MerkleTree.New.High.Correct.Base open FStar.Classical open FStar.Ghost open FStar.Seq module S = FStar.Seq module MTS = MerkleTree.Spec open MerkleTree.New.High #set-options "--z3rlimit 40 --max_fuel 0 --max_ifuel 0" /// Sequence helpers val seq_prefix: #a:Type -> s1:S.seq a -> s2:S.seq a{S.length s1 <= S.length s2} -> GTot Type0 let seq_prefix #a s1 s2 = S.equal s1 (S.slice s2 0 (S.length s1)) val seq_head_cons: #a:Type -> x:a -> s:S.seq a -> Lemma (S.head (S.cons x s) == x) [SMTPat (S.cons x s)] let seq_head_cons #a x s = () val seq_tail_cons: #a:Type -> x:a -> s:S.seq a -> Lemma (S.equal (S.tail (S.cons x s)) s) [SMTPat (S.cons x s)] let seq_tail_cons #a x s = () /// Invariants and simulation relation of high-level Merkle tree design // Invariants of internal hashes val empty_hashes: (#hsz:pos) -> (len:nat) -> GTot (hs:hashess #hsz {S.length hs = len}) let empty_hashes #hsz len = S.create len S.empty val empty_hashes_head: #hsz:pos -> len:nat{len > 0} -> Lemma (S.head (empty_hashes #hsz len) == S.empty) let empty_hashes_head #_ _ = () val empty_hashes_tail: #hsz:pos -> len:nat{len > 0} -> Lemma (S.equal (S.tail (empty_hashes len)) (empty_hashes #hsz (len - 1))) let empty_hashes_tail #_ _ = () #push-options "--max_fuel 1" val mt_hashes_lth_inv: #hsz:pos -> lv:nat{lv <= 32} -> j:nat{j < pow2 (32 - lv)} -> fhs:hashess #hsz {S.length fhs = 32} -> GTot Type0 (decreases (32 - lv)) let rec mt_hashes_lth_inv #hsz lv j fhs = if lv = 32 then true else (S.length (S.index fhs lv) == j /\ mt_hashes_lth_inv (lv + 1) (j / 2) fhs) val mt_hashes_lth_inv_empty: #hsz:pos -> lv:nat{lv <= 32} -> Lemma (requires True) (ensures mt_hashes_lth_inv lv 0 (empty_hashes #hsz 32)) (decreases (32 - lv)) let rec mt_hashes_lth_inv_empty #hsz lv = if lv = 32 then () else mt_hashes_lth_inv_empty #hsz (lv + 1) val mt_hashes_next_rel: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> j:nat -> hs:hashes #hsz {S.length hs = j} -> nhs:hashes #hsz {S.length nhs = j / 2} -> GTot Type0 let mt_hashes_next_rel #hsz #f j hs nhs = forall (i:nat{i < j / 2}). S.index nhs i == f (S.index hs (op_Multiply 2 i)) (S.index hs (op_Multiply 2 i + 1)) #pop-options #push-options "--max_fuel 2" val mt_hashes_inv: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> lv:nat{lv < 32} -> j:nat{j < pow2 (32 - lv)} -> fhs:hashess #hsz {S.length fhs = 32 /\ mt_hashes_lth_inv lv j fhs} -> GTot Type0 (decreases (32 - lv)) let rec mt_hashes_inv #hsz #f lv j fhs = if lv = 31 then true else (mt_hashes_next_rel #_ #f j (S.index fhs lv) (S.index fhs (lv + 1)) /\ mt_hashes_inv #_ #f (lv + 1) (j / 2) fhs) val mt_hashes_inv_empty: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> lv:nat{lv < 32} -> Lemma (requires True) (ensures (mt_hashes_lth_inv_empty #hsz lv; mt_hashes_inv #hsz #f lv 0 (empty_hashes #hsz 32))) (decreases (32 - lv)) let rec mt_hashes_inv_empty #hsz #f lv = if lv = 31 then () else (mt_hashes_lth_inv_empty #hsz (lv + 1); mt_hashes_inv_empty #_ #f (lv + 1)) val mt_hashes_lth_inv_equiv: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> lv:nat{lv < 32} -> j:nat{j < pow2 (32 - lv)} -> fhs1:hashess{S.length fhs1 = 32} -> fhs2:hashess{S.length fhs2 = 32} -> Lemma (requires mt_hashes_lth_inv lv j fhs1 /\ S.equal (S.slice fhs1 lv 32) (S.slice fhs2 lv 32)) (ensures mt_hashes_lth_inv #hsz lv j fhs2) (decreases (32 - lv)) let rec mt_hashes_lth_inv_equiv #hsz #f lv j fhs1 fhs2 = if lv = 31 then () else (assert (S.index fhs1 lv == S.index fhs2 lv); mt_hashes_lth_inv_equiv #_ #f (lv + 1) (j / 2) fhs1 fhs2) #pop-options #push-options "--max_fuel 1" val mt_hashes_inv_equiv: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> lv:nat{lv < 32} -> j:nat{j < pow2 (32 - lv)} -> fhs1:hashess #hsz {S.length fhs1 = 32 /\ mt_hashes_lth_inv lv j fhs1} -> fhs2:hashess #hsz {S.length fhs2 = 32 /\ mt_hashes_lth_inv lv j fhs2} -> Lemma (requires mt_hashes_inv #_ #f lv j fhs1 /\ S.equal (S.slice fhs1 lv 32) (S.slice fhs2 lv 32)) (ensures mt_hashes_inv #_ #f lv j fhs2) (decreases (32 - lv)) let rec mt_hashes_inv_equiv #hsz #f lv j fhs1 fhs2 = if lv = 31 then () else (assert (S.index fhs1 lv == S.index fhs2 lv); assert (S.index fhs1 (lv + 1) == S.index fhs2 (lv + 1)); mt_hashes_inv_equiv #_ #f (lv + 1) (j / 2) fhs1 fhs2) val merge_hs: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> hs1:hashess #hsz -> hs2:hashess #hsz {S.length hs1 = S.length hs2} -> GTot (mhs:hashess #hsz {S.length mhs = S.length hs1}) (decreases (S.length hs1)) let rec merge_hs #hsz #f hs1 hs2 = if S.length hs1 = 0 then S.empty else (S.cons (S.append (S.head hs1) (S.head hs2)) (merge_hs #_ #f (S.tail hs1) (S.tail hs2))) val merge_hs_empty: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> len:nat -> Lemma (S.equal (merge_hs #_ #f (empty_hashes #hsz len) (empty_hashes #hsz len)) (empty_hashes #hsz len)) let rec merge_hs_empty #hsz #f len = if len = 0 then () else (empty_hashes_head #hsz len; empty_hashes_tail #hsz len; assert (S.equal (S.append #(hash #hsz) S.empty S.empty) (S.empty #(hash #hsz))); assert (S.equal (merge_hs #_ #f (empty_hashes len) (empty_hashes len)) (S.cons S.empty (merge_hs #_ #f (empty_hashes (len - 1)) (empty_hashes (len - 1))))); merge_hs_empty #_ #f (len - 1)) val merge_hs_index: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> hs1:hashess -> hs2:hashess{S.length hs1 = S.length hs2} -> i:nat{i < S.length hs1} -> Lemma (requires True) (ensures S.equal (S.index (merge_hs #_ #f hs1 hs2) i) (S.append (S.index hs1 i) (S.index hs2 i))) (decreases (S.length hs1)) [SMTPat (S.index (merge_hs #_ #f hs1 hs2) i)] let rec merge_hs_index #hsz #f hs1 hs2 i = if S.length hs1 = 0 then () else if i = 0 then () else merge_hs_index #_ #f (S.tail hs1) (S.tail hs2) (i - 1) val merge_hs_slice_equal: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> ahs1:hashess #hsz -> ahs2:hashess #hsz {S.length ahs1 = S.length ahs2} -> bhs1:hashess #hsz -> bhs2:hashess #hsz {S.length bhs1 = S.length bhs2} -> i:nat -> j:nat{i <= j && j <= S.length ahs1 && j <= S.length bhs1} -> Lemma (requires S.equal (S.slice ahs1 i j) (S.slice bhs1 i j) /\ S.equal (S.slice ahs2 i j) (S.slice bhs2 i j)) (ensures S.equal (S.slice (merge_hs #_ #f ahs1 ahs2) i j) (S.slice (merge_hs #_ #f bhs1 bhs2) i j)) (decreases (j - i)) let rec merge_hs_slice_equal #_ #f ahs1 ahs2 bhs1 bhs2 i j = if i = j then () else (assert (S.index ahs1 i == S.index bhs1 i); assert (S.index ahs2 i == S.index bhs2 i); merge_hs_slice_equal #_ #f ahs1 ahs2 bhs1 bhs2 (i + 1) j) val merge_hs_upd: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> hs1:hashess #hsz -> hs2:hashess #hsz {S.length hs1 = S.length hs2} -> i:nat{i < S.length hs1} -> v1:hashes #hsz -> v2:hashes #hsz -> Lemma (requires S.equal (S.append (S.index hs1 i) (S.index hs2 i)) (S.append v1 v2)) (ensures S.equal (merge_hs #_ #f hs1 hs2) (merge_hs #_ #f (S.upd hs1 i v1) (S.upd hs2 i v2))) (decreases i) let rec merge_hs_upd #_ #f hs1 hs2 i v1 v2 = if S.length hs1 = 0 then () else if i = 0 then () else merge_hs_upd #_ #f (S.tail hs1) (S.tail hs2) (i - 1) v1 v2 val mt_olds_inv: #hsz:pos -> lv:nat{lv <= 32} -> i:nat -> olds:hashess #hsz {S.length olds = 32} -> GTot Type0 (decreases (32 - lv)) let rec mt_olds_inv #hsz lv i olds = if lv = 32 then true else (let ofs = offset_of i in S.length (S.index olds lv) == ofs /\ mt_olds_inv #hsz (lv + 1) (i / 2) olds) val mt_olds_inv_equiv: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> lv:nat{lv <= 32} -> i:nat -> olds1:hashess #hsz {S.length olds1 = 32} -> olds2:hashess #hsz {S.length olds2 = 32} -> Lemma (requires mt_olds_inv #hsz lv i olds1 /\ S.equal (S.slice olds1 lv 32) (S.slice olds2 lv 32)) (ensures mt_olds_inv #hsz lv i olds2) (decreases (32 - lv)) let rec mt_olds_inv_equiv #hsz #f lv i olds1 olds2 = if lv = 32 then () else (assert (S.index olds1 lv == S.index olds2 lv); mt_olds_inv_equiv #_ #f (lv + 1) (i / 2) olds1 olds2) val mt_olds_hs_lth_inv_ok: #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 #hsz lv hs i j} -> Lemma (requires True) (ensures mt_hashes_lth_inv #hsz lv j (merge_hs #_ #f olds hs)) (decreases (32 - lv)) let rec mt_olds_hs_lth_inv_ok #hsz #f lv i j olds hs = if lv = 32 then () else (mt_olds_hs_lth_inv_ok #_ #f (lv + 1) (i / 2) (j / 2) olds hs) val mt_olds_hs_inv: #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 #hsz lv hs i j} -> GTot Type0 let mt_olds_hs_inv #hsz #f lv i j olds hs = mt_olds_hs_lth_inv_ok #_ #f lv i j olds hs; mt_hashes_inv #_ #f lv j (merge_hs #_ #f olds hs) // Relation between valid internal hashes (satisfying `mt_olds_hs_inv`) and // the spec. While giving such relation, all rightmost hashes are recovered. // Note that `MT?.rhs` after `construct_rhs` does NOT contain all rightmost // hashes; it has partial rightmost hashes that are enough to calculate // Merkle paths. val log2: n:nat{n > 0} -> GTot (c:nat{pow2 c <= n && n < pow2 (c+1)}) let rec log2 n = if n = 1 then 0 else 1 + log2 (n / 2) val log2_bound: n:nat{n > 0} -> c:nat{n < pow2 c} -> Lemma (log2 n <= c-1) let rec log2_bound n c = if n = 1 then () else log2_bound (n / 2) (c - 1) val log2_div: n:nat{n > 1} -> Lemma (log2 (n / 2) = log2 n - 1) let log2_div n = () val log2c: n:nat -> GTot (c:nat{c = 0 || (pow2 (c-1) <= n && n < pow2 c)}) let log2c n = if n = 0 then 0 else (log2 n + 1) val log2c_div: n:nat{n > 0} -> Lemma (log2c (n / 2) = log2c n - 1) let log2c_div n = () val log2c_bound: n:nat -> c:nat{n < pow2 c} -> Lemma (log2c n <= c) let rec log2c_bound n c = if n = 0 then () else log2c_bound (n / 2) (c - 1) val mt_hashes_lth_inv_log: #hsz:pos -> j:nat -> fhs:hashess #hsz {S.length fhs = log2c j} -> GTot Type0 (decreases j) let rec mt_hashes_lth_inv_log #hsz j fhs = if j = 0 then true else (S.length (S.head fhs) == j /\ mt_hashes_lth_inv_log #hsz (j / 2) (S.tail fhs)) #pop-options #push-options "--max_fuel 2" val mt_hashes_lth_inv_log_next: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> j:nat{j > 1} -> fhs:hashess #hsz {S.length fhs = log2c j} -> Lemma (requires mt_hashes_lth_inv_log #hsz j fhs) (ensures S.length (S.head fhs) == j /\ S.length (S.head (S.tail fhs)) == j / 2) let mt_hashes_lth_inv_log_next #_ #_ _ _ = () val mt_hashes_inv_log: #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} -> GTot Type0 (decreases j) let rec mt_hashes_inv_log #hsz #f j fhs = if j <= 1 then true else (mt_hashes_next_rel #_ #f j (S.index fhs 0) (S.index fhs 1) /\ mt_hashes_inv_log #_ #f (j / 2) (S.tail fhs)) val mt_hashes_lth_inv_log_converted_: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> lv:nat{lv <= 32} -> j:nat{j < pow2 (32 - lv)} -> fhs:hashess #hsz {S.length fhs = 32} -> Lemma (requires mt_hashes_lth_inv #hsz lv j fhs) (ensures (log2c_bound j (32 - lv); mt_hashes_lth_inv_log #hsz j (S.slice fhs lv (lv + log2c j)))) (decreases j) let rec mt_hashes_lth_inv_log_converted_ #_ #f lv j fhs = if j = 0 then () else (log2c_bound (j / 2) (32 - (lv + 1)); mt_hashes_lth_inv_log_converted_ #_ #f (lv + 1) (j / 2) fhs) val mt_hashes_lth_inv_log_converted: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> j:nat{j < pow2 32} -> fhs:hashess #hsz {S.length fhs = 32} -> Lemma (requires mt_hashes_lth_inv #hsz 0 j fhs) (ensures (log2c_bound j 32; mt_hashes_lth_inv_log #hsz j (S.slice fhs 0 (log2c j)))) let mt_hashes_lth_inv_log_converted #_ #f j fhs = mt_hashes_lth_inv_log_converted_ #_ #f 0 j fhs val mt_hashes_inv_log_converted_: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> lv:nat{lv <= 32} -> j:nat{j > 0 && j < pow2 (32 - lv)} -> fhs:hashess #hsz {S.length fhs = 32 /\ mt_hashes_lth_inv #hsz lv j fhs} -> Lemma (requires mt_hashes_inv #_ #f lv j fhs) (ensures (log2c_bound j (32 - lv); mt_hashes_lth_inv_log_converted_ #_ #f lv j fhs; mt_hashes_inv_log #_ #f j (S.slice fhs lv (lv + log2c j)))) (decreases j) #pop-options #push-options "--z3rlimit 100 --initial_fuel 2 --max_fuel 2" let rec mt_hashes_inv_log_converted_ #_ #f lv j fhs = if j = 1 then () else (log2c_bound (j / 2) (32 - (lv + 1)); mt_hashes_lth_inv_log_converted_ #_ #f (lv + 1) (j / 2) fhs; mt_hashes_inv_log_converted_ #_ #f (lv + 1) (j / 2) fhs) #pop-options val mt_hashes_inv_log_converted: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> j:nat{j > 0 && j < pow2 32} -> fhs:hashess #hsz {S.length fhs = 32 /\ mt_hashes_lth_inv #hsz 0 j fhs} -> Lemma (requires mt_hashes_inv #_ #f 0 j fhs) (ensures (log2c_bound j 32; mt_hashes_lth_inv_log_converted_ #_ #f 0 j fhs; mt_hashes_inv_log #_ #f j (S.slice fhs 0 (log2c j)))) let mt_hashes_inv_log_converted #_ #f j fhs = mt_hashes_inv_log_converted_ #_ #f 0 j fhs val hash_seq_lift: #hsz:pos -> hs:hashes #hsz -> GTot (shs:MTS.hashes #hsz {S.length shs = S.length hs}) (decreases (S.length hs)) let rec hash_seq_lift #hsz hs = if S.length hs = 0 then S.empty else S.cons (MTS.HRaw (S.head hs)) (hash_seq_lift #hsz (S.tail hs)) #push-options "--z3rlimit 50 --initial_fuel 2 --max_fuel 2" val hash_seq_lift_index: #hsz:pos -> hs:hashes #hsz -> Lemma (requires True) (ensures forall (i:nat{i < S.length hs}). S.index (hash_seq_lift #hsz hs) i == MTS.HRaw (S.index hs i)) (decreases (S.length hs)) let rec hash_seq_lift_index #hsz hs = if S.length hs = 0 then () else hash_seq_lift_index #hsz (S.tail hs) #pop-options val create_pads: #hsz:pos -> len:nat -> GTot (pads:MTS.hashes #hsz {S.length pads = len}) let create_pads #hsz len = S.create len (MTS.HPad #hsz) val hash_seq_spec: #hsz:pos -> hs:hashes #hsz {S.length hs > 0} -> GTot (MTS.merkle_tree #hsz (log2c (S.length hs))) let hash_seq_spec #hsz hs = S.append (hash_seq_lift #hsz hs) (create_pads (pow2 (log2c (S.length hs)) - S.length hs)) val hash_seq_spec_index_raw: #hsz:pos -> hs:hashes #hsz {S.length hs > 0} -> i:nat{i < S.length hs} -> Lemma (S.index (hash_seq_spec #hsz hs) i == MTS.HRaw #hsz (S.index hs i)) let hash_seq_spec_index_raw #hsz hs i = hash_seq_lift_index #hsz hs // Now about recovering rightmost hashes #push-options "--z3rlimit 50 --initial_fuel 1 --max_fuel 1" val mt_hashes_next_rel_lift_even: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> j:nat{j > 1} -> hs:hashes #hsz {S.length hs = j} -> nhs:hashes #hsz {S.length nhs = j / 2} -> Lemma (requires j % 2 = 0 /\ mt_hashes_next_rel #_ #f j hs nhs) (ensures MTS.mt_next_rel #_ #f (log2c j) (hash_seq_spec #hsz hs) (hash_seq_spec #hsz nhs)) let mt_hashes_next_rel_lift_even #hsz #_ j hs nhs = hash_seq_lift_index #hsz hs; hash_seq_lift_index #hsz nhs val mt_hashes_next_rel_lift_odd: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> j:nat{j > 1} -> hs:hashes #hsz {S.length hs = j} -> nhs:hashes #hsz {S.length nhs = j / 2} -> Lemma (requires j % 2 = 1 /\ mt_hashes_next_rel #_ #f j hs nhs) (ensures MTS.mt_next_rel #_ #f (log2c j) (hash_seq_spec #hsz hs) (S.upd (hash_seq_spec #hsz nhs)
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "MerkleTree.Spec.fst.checked", "MerkleTree.New.High.fst.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Ghost.fsti.checked", "FStar.Classical.fsti.checked" ], "interface_file": false, "source_file": "MerkleTree.New.High.Correct.Base.fst" }
[ { "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": 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": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
j: Prims.nat{j > 1} -> hs: MerkleTree.New.High.hashes{FStar.Seq.Base.length hs = j} -> nhs: MerkleTree.New.High.hashes{FStar.Seq.Base.length nhs = j / 2} -> FStar.Pervasives.Lemma (requires j % 2 = 1 /\ MerkleTree.New.High.Correct.Base.mt_hashes_next_rel j hs nhs) (ensures MerkleTree.Spec.mt_next_rel (MerkleTree.New.High.Correct.Base.log2c j) (MerkleTree.New.High.Correct.Base.hash_seq_spec hs) (FStar.Seq.Base.upd (MerkleTree.New.High.Correct.Base.hash_seq_spec nhs) (FStar.Seq.Base.length nhs) (MerkleTree.Spec.HRaw (FStar.Seq.Properties.last hs))))
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "Prims.pos", "MerkleTree.Spec.hash_fun_t", "Prims.nat", "Prims.b2t", "Prims.op_GreaterThan", "MerkleTree.New.High.hashes", "Prims.op_Equality", "FStar.Seq.Base.length", "MerkleTree.New.High.hash", "Prims.int", "Prims.op_Division", "MerkleTree.New.High.Correct.Base.hash_seq_lift_index", "Prims.unit", "MerkleTree.New.High.Correct.Base.log2c_div" ]
[]
true
false
true
false
false
let mt_hashes_next_rel_lift_odd #hsz #_ j hs nhs =
log2c_div j; hash_seq_lift_index #hsz hs; hash_seq_lift_index #hsz nhs
false
MerkleTree.New.High.Correct.Base.fst
MerkleTree.New.High.Correct.Base.mt_hashes_lth_inv_log_converted_
val mt_hashes_lth_inv_log_converted_: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> lv:nat{lv <= 32} -> j:nat{j < pow2 (32 - lv)} -> fhs:hashess #hsz {S.length fhs = 32} -> Lemma (requires mt_hashes_lth_inv #hsz lv j fhs) (ensures (log2c_bound j (32 - lv); mt_hashes_lth_inv_log #hsz j (S.slice fhs lv (lv + log2c j)))) (decreases j)
val mt_hashes_lth_inv_log_converted_: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> lv:nat{lv <= 32} -> j:nat{j < pow2 (32 - lv)} -> fhs:hashess #hsz {S.length fhs = 32} -> Lemma (requires mt_hashes_lth_inv #hsz lv j fhs) (ensures (log2c_bound j (32 - lv); mt_hashes_lth_inv_log #hsz j (S.slice fhs lv (lv + log2c j)))) (decreases j)
let rec mt_hashes_lth_inv_log_converted_ #_ #f lv j fhs = if j = 0 then () else (log2c_bound (j / 2) (32 - (lv + 1)); mt_hashes_lth_inv_log_converted_ #_ #f (lv + 1) (j / 2) fhs)
{ "file_name": "src/MerkleTree.New.High.Correct.Base.fst", "git_rev": "7d7bdc20f2033171e279c176b26e84f9069d23c6", "git_url": "https://github.com/hacl-star/merkle-tree.git", "project_name": "merkle-tree" }
{ "end_col": 67, "end_line": 361, "start_col": 0, "start_line": 358 }
module MerkleTree.New.High.Correct.Base open FStar.Classical open FStar.Ghost open FStar.Seq module S = FStar.Seq module MTS = MerkleTree.Spec open MerkleTree.New.High #set-options "--z3rlimit 40 --max_fuel 0 --max_ifuel 0" /// Sequence helpers val seq_prefix: #a:Type -> s1:S.seq a -> s2:S.seq a{S.length s1 <= S.length s2} -> GTot Type0 let seq_prefix #a s1 s2 = S.equal s1 (S.slice s2 0 (S.length s1)) val seq_head_cons: #a:Type -> x:a -> s:S.seq a -> Lemma (S.head (S.cons x s) == x) [SMTPat (S.cons x s)] let seq_head_cons #a x s = () val seq_tail_cons: #a:Type -> x:a -> s:S.seq a -> Lemma (S.equal (S.tail (S.cons x s)) s) [SMTPat (S.cons x s)] let seq_tail_cons #a x s = () /// Invariants and simulation relation of high-level Merkle tree design // Invariants of internal hashes val empty_hashes: (#hsz:pos) -> (len:nat) -> GTot (hs:hashess #hsz {S.length hs = len}) let empty_hashes #hsz len = S.create len S.empty val empty_hashes_head: #hsz:pos -> len:nat{len > 0} -> Lemma (S.head (empty_hashes #hsz len) == S.empty) let empty_hashes_head #_ _ = () val empty_hashes_tail: #hsz:pos -> len:nat{len > 0} -> Lemma (S.equal (S.tail (empty_hashes len)) (empty_hashes #hsz (len - 1))) let empty_hashes_tail #_ _ = () #push-options "--max_fuel 1" val mt_hashes_lth_inv: #hsz:pos -> lv:nat{lv <= 32} -> j:nat{j < pow2 (32 - lv)} -> fhs:hashess #hsz {S.length fhs = 32} -> GTot Type0 (decreases (32 - lv)) let rec mt_hashes_lth_inv #hsz lv j fhs = if lv = 32 then true else (S.length (S.index fhs lv) == j /\ mt_hashes_lth_inv (lv + 1) (j / 2) fhs) val mt_hashes_lth_inv_empty: #hsz:pos -> lv:nat{lv <= 32} -> Lemma (requires True) (ensures mt_hashes_lth_inv lv 0 (empty_hashes #hsz 32)) (decreases (32 - lv)) let rec mt_hashes_lth_inv_empty #hsz lv = if lv = 32 then () else mt_hashes_lth_inv_empty #hsz (lv + 1) val mt_hashes_next_rel: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> j:nat -> hs:hashes #hsz {S.length hs = j} -> nhs:hashes #hsz {S.length nhs = j / 2} -> GTot Type0 let mt_hashes_next_rel #hsz #f j hs nhs = forall (i:nat{i < j / 2}). S.index nhs i == f (S.index hs (op_Multiply 2 i)) (S.index hs (op_Multiply 2 i + 1)) #pop-options #push-options "--max_fuel 2" val mt_hashes_inv: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> lv:nat{lv < 32} -> j:nat{j < pow2 (32 - lv)} -> fhs:hashess #hsz {S.length fhs = 32 /\ mt_hashes_lth_inv lv j fhs} -> GTot Type0 (decreases (32 - lv)) let rec mt_hashes_inv #hsz #f lv j fhs = if lv = 31 then true else (mt_hashes_next_rel #_ #f j (S.index fhs lv) (S.index fhs (lv + 1)) /\ mt_hashes_inv #_ #f (lv + 1) (j / 2) fhs) val mt_hashes_inv_empty: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> lv:nat{lv < 32} -> Lemma (requires True) (ensures (mt_hashes_lth_inv_empty #hsz lv; mt_hashes_inv #hsz #f lv 0 (empty_hashes #hsz 32))) (decreases (32 - lv)) let rec mt_hashes_inv_empty #hsz #f lv = if lv = 31 then () else (mt_hashes_lth_inv_empty #hsz (lv + 1); mt_hashes_inv_empty #_ #f (lv + 1)) val mt_hashes_lth_inv_equiv: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> lv:nat{lv < 32} -> j:nat{j < pow2 (32 - lv)} -> fhs1:hashess{S.length fhs1 = 32} -> fhs2:hashess{S.length fhs2 = 32} -> Lemma (requires mt_hashes_lth_inv lv j fhs1 /\ S.equal (S.slice fhs1 lv 32) (S.slice fhs2 lv 32)) (ensures mt_hashes_lth_inv #hsz lv j fhs2) (decreases (32 - lv)) let rec mt_hashes_lth_inv_equiv #hsz #f lv j fhs1 fhs2 = if lv = 31 then () else (assert (S.index fhs1 lv == S.index fhs2 lv); mt_hashes_lth_inv_equiv #_ #f (lv + 1) (j / 2) fhs1 fhs2) #pop-options #push-options "--max_fuel 1" val mt_hashes_inv_equiv: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> lv:nat{lv < 32} -> j:nat{j < pow2 (32 - lv)} -> fhs1:hashess #hsz {S.length fhs1 = 32 /\ mt_hashes_lth_inv lv j fhs1} -> fhs2:hashess #hsz {S.length fhs2 = 32 /\ mt_hashes_lth_inv lv j fhs2} -> Lemma (requires mt_hashes_inv #_ #f lv j fhs1 /\ S.equal (S.slice fhs1 lv 32) (S.slice fhs2 lv 32)) (ensures mt_hashes_inv #_ #f lv j fhs2) (decreases (32 - lv)) let rec mt_hashes_inv_equiv #hsz #f lv j fhs1 fhs2 = if lv = 31 then () else (assert (S.index fhs1 lv == S.index fhs2 lv); assert (S.index fhs1 (lv + 1) == S.index fhs2 (lv + 1)); mt_hashes_inv_equiv #_ #f (lv + 1) (j / 2) fhs1 fhs2) val merge_hs: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> hs1:hashess #hsz -> hs2:hashess #hsz {S.length hs1 = S.length hs2} -> GTot (mhs:hashess #hsz {S.length mhs = S.length hs1}) (decreases (S.length hs1)) let rec merge_hs #hsz #f hs1 hs2 = if S.length hs1 = 0 then S.empty else (S.cons (S.append (S.head hs1) (S.head hs2)) (merge_hs #_ #f (S.tail hs1) (S.tail hs2))) val merge_hs_empty: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> len:nat -> Lemma (S.equal (merge_hs #_ #f (empty_hashes #hsz len) (empty_hashes #hsz len)) (empty_hashes #hsz len)) let rec merge_hs_empty #hsz #f len = if len = 0 then () else (empty_hashes_head #hsz len; empty_hashes_tail #hsz len; assert (S.equal (S.append #(hash #hsz) S.empty S.empty) (S.empty #(hash #hsz))); assert (S.equal (merge_hs #_ #f (empty_hashes len) (empty_hashes len)) (S.cons S.empty (merge_hs #_ #f (empty_hashes (len - 1)) (empty_hashes (len - 1))))); merge_hs_empty #_ #f (len - 1)) val merge_hs_index: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> hs1:hashess -> hs2:hashess{S.length hs1 = S.length hs2} -> i:nat{i < S.length hs1} -> Lemma (requires True) (ensures S.equal (S.index (merge_hs #_ #f hs1 hs2) i) (S.append (S.index hs1 i) (S.index hs2 i))) (decreases (S.length hs1)) [SMTPat (S.index (merge_hs #_ #f hs1 hs2) i)] let rec merge_hs_index #hsz #f hs1 hs2 i = if S.length hs1 = 0 then () else if i = 0 then () else merge_hs_index #_ #f (S.tail hs1) (S.tail hs2) (i - 1) val merge_hs_slice_equal: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> ahs1:hashess #hsz -> ahs2:hashess #hsz {S.length ahs1 = S.length ahs2} -> bhs1:hashess #hsz -> bhs2:hashess #hsz {S.length bhs1 = S.length bhs2} -> i:nat -> j:nat{i <= j && j <= S.length ahs1 && j <= S.length bhs1} -> Lemma (requires S.equal (S.slice ahs1 i j) (S.slice bhs1 i j) /\ S.equal (S.slice ahs2 i j) (S.slice bhs2 i j)) (ensures S.equal (S.slice (merge_hs #_ #f ahs1 ahs2) i j) (S.slice (merge_hs #_ #f bhs1 bhs2) i j)) (decreases (j - i)) let rec merge_hs_slice_equal #_ #f ahs1 ahs2 bhs1 bhs2 i j = if i = j then () else (assert (S.index ahs1 i == S.index bhs1 i); assert (S.index ahs2 i == S.index bhs2 i); merge_hs_slice_equal #_ #f ahs1 ahs2 bhs1 bhs2 (i + 1) j) val merge_hs_upd: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> hs1:hashess #hsz -> hs2:hashess #hsz {S.length hs1 = S.length hs2} -> i:nat{i < S.length hs1} -> v1:hashes #hsz -> v2:hashes #hsz -> Lemma (requires S.equal (S.append (S.index hs1 i) (S.index hs2 i)) (S.append v1 v2)) (ensures S.equal (merge_hs #_ #f hs1 hs2) (merge_hs #_ #f (S.upd hs1 i v1) (S.upd hs2 i v2))) (decreases i) let rec merge_hs_upd #_ #f hs1 hs2 i v1 v2 = if S.length hs1 = 0 then () else if i = 0 then () else merge_hs_upd #_ #f (S.tail hs1) (S.tail hs2) (i - 1) v1 v2 val mt_olds_inv: #hsz:pos -> lv:nat{lv <= 32} -> i:nat -> olds:hashess #hsz {S.length olds = 32} -> GTot Type0 (decreases (32 - lv)) let rec mt_olds_inv #hsz lv i olds = if lv = 32 then true else (let ofs = offset_of i in S.length (S.index olds lv) == ofs /\ mt_olds_inv #hsz (lv + 1) (i / 2) olds) val mt_olds_inv_equiv: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> lv:nat{lv <= 32} -> i:nat -> olds1:hashess #hsz {S.length olds1 = 32} -> olds2:hashess #hsz {S.length olds2 = 32} -> Lemma (requires mt_olds_inv #hsz lv i olds1 /\ S.equal (S.slice olds1 lv 32) (S.slice olds2 lv 32)) (ensures mt_olds_inv #hsz lv i olds2) (decreases (32 - lv)) let rec mt_olds_inv_equiv #hsz #f lv i olds1 olds2 = if lv = 32 then () else (assert (S.index olds1 lv == S.index olds2 lv); mt_olds_inv_equiv #_ #f (lv + 1) (i / 2) olds1 olds2) val mt_olds_hs_lth_inv_ok: #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 #hsz lv hs i j} -> Lemma (requires True) (ensures mt_hashes_lth_inv #hsz lv j (merge_hs #_ #f olds hs)) (decreases (32 - lv)) let rec mt_olds_hs_lth_inv_ok #hsz #f lv i j olds hs = if lv = 32 then () else (mt_olds_hs_lth_inv_ok #_ #f (lv + 1) (i / 2) (j / 2) olds hs) val mt_olds_hs_inv: #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 #hsz lv hs i j} -> GTot Type0 let mt_olds_hs_inv #hsz #f lv i j olds hs = mt_olds_hs_lth_inv_ok #_ #f lv i j olds hs; mt_hashes_inv #_ #f lv j (merge_hs #_ #f olds hs) // Relation between valid internal hashes (satisfying `mt_olds_hs_inv`) and // the spec. While giving such relation, all rightmost hashes are recovered. // Note that `MT?.rhs` after `construct_rhs` does NOT contain all rightmost // hashes; it has partial rightmost hashes that are enough to calculate // Merkle paths. val log2: n:nat{n > 0} -> GTot (c:nat{pow2 c <= n && n < pow2 (c+1)}) let rec log2 n = if n = 1 then 0 else 1 + log2 (n / 2) val log2_bound: n:nat{n > 0} -> c:nat{n < pow2 c} -> Lemma (log2 n <= c-1) let rec log2_bound n c = if n = 1 then () else log2_bound (n / 2) (c - 1) val log2_div: n:nat{n > 1} -> Lemma (log2 (n / 2) = log2 n - 1) let log2_div n = () val log2c: n:nat -> GTot (c:nat{c = 0 || (pow2 (c-1) <= n && n < pow2 c)}) let log2c n = if n = 0 then 0 else (log2 n + 1) val log2c_div: n:nat{n > 0} -> Lemma (log2c (n / 2) = log2c n - 1) let log2c_div n = () val log2c_bound: n:nat -> c:nat{n < pow2 c} -> Lemma (log2c n <= c) let rec log2c_bound n c = if n = 0 then () else log2c_bound (n / 2) (c - 1) val mt_hashes_lth_inv_log: #hsz:pos -> j:nat -> fhs:hashess #hsz {S.length fhs = log2c j} -> GTot Type0 (decreases j) let rec mt_hashes_lth_inv_log #hsz j fhs = if j = 0 then true else (S.length (S.head fhs) == j /\ mt_hashes_lth_inv_log #hsz (j / 2) (S.tail fhs)) #pop-options #push-options "--max_fuel 2" val mt_hashes_lth_inv_log_next: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> j:nat{j > 1} -> fhs:hashess #hsz {S.length fhs = log2c j} -> Lemma (requires mt_hashes_lth_inv_log #hsz j fhs) (ensures S.length (S.head fhs) == j /\ S.length (S.head (S.tail fhs)) == j / 2) let mt_hashes_lth_inv_log_next #_ #_ _ _ = () val mt_hashes_inv_log: #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} -> GTot Type0 (decreases j) let rec mt_hashes_inv_log #hsz #f j fhs = if j <= 1 then true else (mt_hashes_next_rel #_ #f j (S.index fhs 0) (S.index fhs 1) /\ mt_hashes_inv_log #_ #f (j / 2) (S.tail fhs)) val mt_hashes_lth_inv_log_converted_: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> lv:nat{lv <= 32} -> j:nat{j < pow2 (32 - lv)} -> fhs:hashess #hsz {S.length fhs = 32} -> Lemma (requires mt_hashes_lth_inv #hsz lv j fhs) (ensures (log2c_bound j (32 - lv); mt_hashes_lth_inv_log #hsz j (S.slice fhs lv (lv + log2c j))))
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "MerkleTree.Spec.fst.checked", "MerkleTree.New.High.fst.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Ghost.fsti.checked", "FStar.Classical.fsti.checked" ], "interface_file": false, "source_file": "MerkleTree.New.High.Correct.Base.fst" }
[ { "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": 2, "initial_ifuel": 1, "max_fuel": 2, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 40, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
lv: Prims.nat{lv <= 32} -> j: Prims.nat{j < Prims.pow2 (32 - lv)} -> fhs: MerkleTree.New.High.hashess{FStar.Seq.Base.length fhs = 32} -> FStar.Pervasives.Lemma (requires MerkleTree.New.High.Correct.Base.mt_hashes_lth_inv lv j fhs) (ensures (MerkleTree.New.High.Correct.Base.log2c_bound j (32 - lv); MerkleTree.New.High.Correct.Base.mt_hashes_lth_inv_log j (FStar.Seq.Base.slice fhs lv (lv + MerkleTree.New.High.Correct.Base.log2c j)))) (decreases j)
FStar.Pervasives.Lemma
[ "lemma", "" ]
[]
[ "Prims.pos", "MerkleTree.Spec.hash_fun_t", "Prims.nat", "Prims.b2t", "Prims.op_LessThanOrEqual", "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", "Prims.bool", "MerkleTree.New.High.Correct.Base.mt_hashes_lth_inv_log_converted_", "Prims.op_Addition", "Prims.op_Division", "Prims.unit", "MerkleTree.New.High.Correct.Base.log2c_bound" ]
[ "recursion" ]
false
false
true
false
false
let rec mt_hashes_lth_inv_log_converted_ #_ #f lv j fhs =
if j = 0 then () else (log2c_bound (j / 2) (32 - (lv + 1)); mt_hashes_lth_inv_log_converted_ #_ #f (lv + 1) (j / 2) fhs)
false
MerkleTree.New.High.Correct.Base.fst
MerkleTree.New.High.Correct.Base.hash_seq_spec_full_odd_next
val hash_seq_spec_full_odd_next: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> j:nat{j > 1} -> hs:hashes #hsz {S.length hs = j} -> nhs:hashes #hsz {S.length nhs = j / 2} -> acc:hash #hsz -> actd:bool -> nacc:hash #hsz -> Lemma (requires j % 2 = 1 /\ mt_hashes_next_rel #_ #f j hs nhs /\ nacc == (if actd then f (S.last hs) acc else S.last hs)) (ensures S.equal (hash_seq_spec_full #_ #f nhs nacc true) (MTS.mt_next_lv #_ #f #(log2c j) (hash_seq_spec_full #_ #f hs acc actd)))
val hash_seq_spec_full_odd_next: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> j:nat{j > 1} -> hs:hashes #hsz {S.length hs = j} -> nhs:hashes #hsz {S.length nhs = j / 2} -> acc:hash #hsz -> actd:bool -> nacc:hash #hsz -> Lemma (requires j % 2 = 1 /\ mt_hashes_next_rel #_ #f j hs nhs /\ nacc == (if actd then f (S.last hs) acc else S.last hs)) (ensures S.equal (hash_seq_spec_full #_ #f nhs nacc true) (MTS.mt_next_lv #_ #f #(log2c j) (hash_seq_spec_full #_ #f hs acc actd)))
let hash_seq_spec_full_odd_next #hsz #f j hs nhs acc actd nacc = log2c_div j; mt_hashes_next_rel_lift_odd #_ #f j hs nhs; if actd then begin MTS.mt_next_rel_upd_odd #_ #f (log2c j) (hash_seq_spec #hsz hs) (S.upd (hash_seq_spec #hsz nhs) (S.length nhs) (MTS.HRaw (S.last hs))) (S.length nhs) (MTS.HRaw acc); MTS.mt_next_rel_next_lv #_ #f (log2c j) (S.upd (hash_seq_spec #hsz hs) (S.length hs) (MTS.HRaw acc)) (S.upd (hash_seq_spec #hsz nhs) (S.length nhs) (MTS.HRaw (f (S.last hs) acc))) end else MTS.mt_next_rel_next_lv #_ #f (log2c j) (hash_seq_spec_full #_ #f hs acc actd) (hash_seq_spec_full #_ #f nhs nacc true)
{ "file_name": "src/MerkleTree.New.High.Correct.Base.fst", "git_rev": "7d7bdc20f2033171e279c176b26e84f9069d23c6", "git_url": "https://github.com/hacl-star/merkle-tree.git", "project_name": "merkle-tree" }
{ "end_col": 49, "end_line": 573, "start_col": 0, "start_line": 558 }
module MerkleTree.New.High.Correct.Base open FStar.Classical open FStar.Ghost open FStar.Seq module S = FStar.Seq module MTS = MerkleTree.Spec open MerkleTree.New.High #set-options "--z3rlimit 40 --max_fuel 0 --max_ifuel 0" /// Sequence helpers val seq_prefix: #a:Type -> s1:S.seq a -> s2:S.seq a{S.length s1 <= S.length s2} -> GTot Type0 let seq_prefix #a s1 s2 = S.equal s1 (S.slice s2 0 (S.length s1)) val seq_head_cons: #a:Type -> x:a -> s:S.seq a -> Lemma (S.head (S.cons x s) == x) [SMTPat (S.cons x s)] let seq_head_cons #a x s = () val seq_tail_cons: #a:Type -> x:a -> s:S.seq a -> Lemma (S.equal (S.tail (S.cons x s)) s) [SMTPat (S.cons x s)] let seq_tail_cons #a x s = () /// Invariants and simulation relation of high-level Merkle tree design // Invariants of internal hashes val empty_hashes: (#hsz:pos) -> (len:nat) -> GTot (hs:hashess #hsz {S.length hs = len}) let empty_hashes #hsz len = S.create len S.empty val empty_hashes_head: #hsz:pos -> len:nat{len > 0} -> Lemma (S.head (empty_hashes #hsz len) == S.empty) let empty_hashes_head #_ _ = () val empty_hashes_tail: #hsz:pos -> len:nat{len > 0} -> Lemma (S.equal (S.tail (empty_hashes len)) (empty_hashes #hsz (len - 1))) let empty_hashes_tail #_ _ = () #push-options "--max_fuel 1" val mt_hashes_lth_inv: #hsz:pos -> lv:nat{lv <= 32} -> j:nat{j < pow2 (32 - lv)} -> fhs:hashess #hsz {S.length fhs = 32} -> GTot Type0 (decreases (32 - lv)) let rec mt_hashes_lth_inv #hsz lv j fhs = if lv = 32 then true else (S.length (S.index fhs lv) == j /\ mt_hashes_lth_inv (lv + 1) (j / 2) fhs) val mt_hashes_lth_inv_empty: #hsz:pos -> lv:nat{lv <= 32} -> Lemma (requires True) (ensures mt_hashes_lth_inv lv 0 (empty_hashes #hsz 32)) (decreases (32 - lv)) let rec mt_hashes_lth_inv_empty #hsz lv = if lv = 32 then () else mt_hashes_lth_inv_empty #hsz (lv + 1) val mt_hashes_next_rel: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> j:nat -> hs:hashes #hsz {S.length hs = j} -> nhs:hashes #hsz {S.length nhs = j / 2} -> GTot Type0 let mt_hashes_next_rel #hsz #f j hs nhs = forall (i:nat{i < j / 2}). S.index nhs i == f (S.index hs (op_Multiply 2 i)) (S.index hs (op_Multiply 2 i + 1)) #pop-options #push-options "--max_fuel 2" val mt_hashes_inv: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> lv:nat{lv < 32} -> j:nat{j < pow2 (32 - lv)} -> fhs:hashess #hsz {S.length fhs = 32 /\ mt_hashes_lth_inv lv j fhs} -> GTot Type0 (decreases (32 - lv)) let rec mt_hashes_inv #hsz #f lv j fhs = if lv = 31 then true else (mt_hashes_next_rel #_ #f j (S.index fhs lv) (S.index fhs (lv + 1)) /\ mt_hashes_inv #_ #f (lv + 1) (j / 2) fhs) val mt_hashes_inv_empty: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> lv:nat{lv < 32} -> Lemma (requires True) (ensures (mt_hashes_lth_inv_empty #hsz lv; mt_hashes_inv #hsz #f lv 0 (empty_hashes #hsz 32))) (decreases (32 - lv)) let rec mt_hashes_inv_empty #hsz #f lv = if lv = 31 then () else (mt_hashes_lth_inv_empty #hsz (lv + 1); mt_hashes_inv_empty #_ #f (lv + 1)) val mt_hashes_lth_inv_equiv: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> lv:nat{lv < 32} -> j:nat{j < pow2 (32 - lv)} -> fhs1:hashess{S.length fhs1 = 32} -> fhs2:hashess{S.length fhs2 = 32} -> Lemma (requires mt_hashes_lth_inv lv j fhs1 /\ S.equal (S.slice fhs1 lv 32) (S.slice fhs2 lv 32)) (ensures mt_hashes_lth_inv #hsz lv j fhs2) (decreases (32 - lv)) let rec mt_hashes_lth_inv_equiv #hsz #f lv j fhs1 fhs2 = if lv = 31 then () else (assert (S.index fhs1 lv == S.index fhs2 lv); mt_hashes_lth_inv_equiv #_ #f (lv + 1) (j / 2) fhs1 fhs2) #pop-options #push-options "--max_fuel 1" val mt_hashes_inv_equiv: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> lv:nat{lv < 32} -> j:nat{j < pow2 (32 - lv)} -> fhs1:hashess #hsz {S.length fhs1 = 32 /\ mt_hashes_lth_inv lv j fhs1} -> fhs2:hashess #hsz {S.length fhs2 = 32 /\ mt_hashes_lth_inv lv j fhs2} -> Lemma (requires mt_hashes_inv #_ #f lv j fhs1 /\ S.equal (S.slice fhs1 lv 32) (S.slice fhs2 lv 32)) (ensures mt_hashes_inv #_ #f lv j fhs2) (decreases (32 - lv)) let rec mt_hashes_inv_equiv #hsz #f lv j fhs1 fhs2 = if lv = 31 then () else (assert (S.index fhs1 lv == S.index fhs2 lv); assert (S.index fhs1 (lv + 1) == S.index fhs2 (lv + 1)); mt_hashes_inv_equiv #_ #f (lv + 1) (j / 2) fhs1 fhs2) val merge_hs: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> hs1:hashess #hsz -> hs2:hashess #hsz {S.length hs1 = S.length hs2} -> GTot (mhs:hashess #hsz {S.length mhs = S.length hs1}) (decreases (S.length hs1)) let rec merge_hs #hsz #f hs1 hs2 = if S.length hs1 = 0 then S.empty else (S.cons (S.append (S.head hs1) (S.head hs2)) (merge_hs #_ #f (S.tail hs1) (S.tail hs2))) val merge_hs_empty: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> len:nat -> Lemma (S.equal (merge_hs #_ #f (empty_hashes #hsz len) (empty_hashes #hsz len)) (empty_hashes #hsz len)) let rec merge_hs_empty #hsz #f len = if len = 0 then () else (empty_hashes_head #hsz len; empty_hashes_tail #hsz len; assert (S.equal (S.append #(hash #hsz) S.empty S.empty) (S.empty #(hash #hsz))); assert (S.equal (merge_hs #_ #f (empty_hashes len) (empty_hashes len)) (S.cons S.empty (merge_hs #_ #f (empty_hashes (len - 1)) (empty_hashes (len - 1))))); merge_hs_empty #_ #f (len - 1)) val merge_hs_index: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> hs1:hashess -> hs2:hashess{S.length hs1 = S.length hs2} -> i:nat{i < S.length hs1} -> Lemma (requires True) (ensures S.equal (S.index (merge_hs #_ #f hs1 hs2) i) (S.append (S.index hs1 i) (S.index hs2 i))) (decreases (S.length hs1)) [SMTPat (S.index (merge_hs #_ #f hs1 hs2) i)] let rec merge_hs_index #hsz #f hs1 hs2 i = if S.length hs1 = 0 then () else if i = 0 then () else merge_hs_index #_ #f (S.tail hs1) (S.tail hs2) (i - 1) val merge_hs_slice_equal: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> ahs1:hashess #hsz -> ahs2:hashess #hsz {S.length ahs1 = S.length ahs2} -> bhs1:hashess #hsz -> bhs2:hashess #hsz {S.length bhs1 = S.length bhs2} -> i:nat -> j:nat{i <= j && j <= S.length ahs1 && j <= S.length bhs1} -> Lemma (requires S.equal (S.slice ahs1 i j) (S.slice bhs1 i j) /\ S.equal (S.slice ahs2 i j) (S.slice bhs2 i j)) (ensures S.equal (S.slice (merge_hs #_ #f ahs1 ahs2) i j) (S.slice (merge_hs #_ #f bhs1 bhs2) i j)) (decreases (j - i)) let rec merge_hs_slice_equal #_ #f ahs1 ahs2 bhs1 bhs2 i j = if i = j then () else (assert (S.index ahs1 i == S.index bhs1 i); assert (S.index ahs2 i == S.index bhs2 i); merge_hs_slice_equal #_ #f ahs1 ahs2 bhs1 bhs2 (i + 1) j) val merge_hs_upd: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> hs1:hashess #hsz -> hs2:hashess #hsz {S.length hs1 = S.length hs2} -> i:nat{i < S.length hs1} -> v1:hashes #hsz -> v2:hashes #hsz -> Lemma (requires S.equal (S.append (S.index hs1 i) (S.index hs2 i)) (S.append v1 v2)) (ensures S.equal (merge_hs #_ #f hs1 hs2) (merge_hs #_ #f (S.upd hs1 i v1) (S.upd hs2 i v2))) (decreases i) let rec merge_hs_upd #_ #f hs1 hs2 i v1 v2 = if S.length hs1 = 0 then () else if i = 0 then () else merge_hs_upd #_ #f (S.tail hs1) (S.tail hs2) (i - 1) v1 v2 val mt_olds_inv: #hsz:pos -> lv:nat{lv <= 32} -> i:nat -> olds:hashess #hsz {S.length olds = 32} -> GTot Type0 (decreases (32 - lv)) let rec mt_olds_inv #hsz lv i olds = if lv = 32 then true else (let ofs = offset_of i in S.length (S.index olds lv) == ofs /\ mt_olds_inv #hsz (lv + 1) (i / 2) olds) val mt_olds_inv_equiv: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> lv:nat{lv <= 32} -> i:nat -> olds1:hashess #hsz {S.length olds1 = 32} -> olds2:hashess #hsz {S.length olds2 = 32} -> Lemma (requires mt_olds_inv #hsz lv i olds1 /\ S.equal (S.slice olds1 lv 32) (S.slice olds2 lv 32)) (ensures mt_olds_inv #hsz lv i olds2) (decreases (32 - lv)) let rec mt_olds_inv_equiv #hsz #f lv i olds1 olds2 = if lv = 32 then () else (assert (S.index olds1 lv == S.index olds2 lv); mt_olds_inv_equiv #_ #f (lv + 1) (i / 2) olds1 olds2) val mt_olds_hs_lth_inv_ok: #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 #hsz lv hs i j} -> Lemma (requires True) (ensures mt_hashes_lth_inv #hsz lv j (merge_hs #_ #f olds hs)) (decreases (32 - lv)) let rec mt_olds_hs_lth_inv_ok #hsz #f lv i j olds hs = if lv = 32 then () else (mt_olds_hs_lth_inv_ok #_ #f (lv + 1) (i / 2) (j / 2) olds hs) val mt_olds_hs_inv: #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 #hsz lv hs i j} -> GTot Type0 let mt_olds_hs_inv #hsz #f lv i j olds hs = mt_olds_hs_lth_inv_ok #_ #f lv i j olds hs; mt_hashes_inv #_ #f lv j (merge_hs #_ #f olds hs) // Relation between valid internal hashes (satisfying `mt_olds_hs_inv`) and // the spec. While giving such relation, all rightmost hashes are recovered. // Note that `MT?.rhs` after `construct_rhs` does NOT contain all rightmost // hashes; it has partial rightmost hashes that are enough to calculate // Merkle paths. val log2: n:nat{n > 0} -> GTot (c:nat{pow2 c <= n && n < pow2 (c+1)}) let rec log2 n = if n = 1 then 0 else 1 + log2 (n / 2) val log2_bound: n:nat{n > 0} -> c:nat{n < pow2 c} -> Lemma (log2 n <= c-1) let rec log2_bound n c = if n = 1 then () else log2_bound (n / 2) (c - 1) val log2_div: n:nat{n > 1} -> Lemma (log2 (n / 2) = log2 n - 1) let log2_div n = () val log2c: n:nat -> GTot (c:nat{c = 0 || (pow2 (c-1) <= n && n < pow2 c)}) let log2c n = if n = 0 then 0 else (log2 n + 1) val log2c_div: n:nat{n > 0} -> Lemma (log2c (n / 2) = log2c n - 1) let log2c_div n = () val log2c_bound: n:nat -> c:nat{n < pow2 c} -> Lemma (log2c n <= c) let rec log2c_bound n c = if n = 0 then () else log2c_bound (n / 2) (c - 1) val mt_hashes_lth_inv_log: #hsz:pos -> j:nat -> fhs:hashess #hsz {S.length fhs = log2c j} -> GTot Type0 (decreases j) let rec mt_hashes_lth_inv_log #hsz j fhs = if j = 0 then true else (S.length (S.head fhs) == j /\ mt_hashes_lth_inv_log #hsz (j / 2) (S.tail fhs)) #pop-options #push-options "--max_fuel 2" val mt_hashes_lth_inv_log_next: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> j:nat{j > 1} -> fhs:hashess #hsz {S.length fhs = log2c j} -> Lemma (requires mt_hashes_lth_inv_log #hsz j fhs) (ensures S.length (S.head fhs) == j /\ S.length (S.head (S.tail fhs)) == j / 2) let mt_hashes_lth_inv_log_next #_ #_ _ _ = () val mt_hashes_inv_log: #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} -> GTot Type0 (decreases j) let rec mt_hashes_inv_log #hsz #f j fhs = if j <= 1 then true else (mt_hashes_next_rel #_ #f j (S.index fhs 0) (S.index fhs 1) /\ mt_hashes_inv_log #_ #f (j / 2) (S.tail fhs)) val mt_hashes_lth_inv_log_converted_: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> lv:nat{lv <= 32} -> j:nat{j < pow2 (32 - lv)} -> fhs:hashess #hsz {S.length fhs = 32} -> Lemma (requires mt_hashes_lth_inv #hsz lv j fhs) (ensures (log2c_bound j (32 - lv); mt_hashes_lth_inv_log #hsz j (S.slice fhs lv (lv + log2c j)))) (decreases j) let rec mt_hashes_lth_inv_log_converted_ #_ #f lv j fhs = if j = 0 then () else (log2c_bound (j / 2) (32 - (lv + 1)); mt_hashes_lth_inv_log_converted_ #_ #f (lv + 1) (j / 2) fhs) val mt_hashes_lth_inv_log_converted: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> j:nat{j < pow2 32} -> fhs:hashess #hsz {S.length fhs = 32} -> Lemma (requires mt_hashes_lth_inv #hsz 0 j fhs) (ensures (log2c_bound j 32; mt_hashes_lth_inv_log #hsz j (S.slice fhs 0 (log2c j)))) let mt_hashes_lth_inv_log_converted #_ #f j fhs = mt_hashes_lth_inv_log_converted_ #_ #f 0 j fhs val mt_hashes_inv_log_converted_: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> lv:nat{lv <= 32} -> j:nat{j > 0 && j < pow2 (32 - lv)} -> fhs:hashess #hsz {S.length fhs = 32 /\ mt_hashes_lth_inv #hsz lv j fhs} -> Lemma (requires mt_hashes_inv #_ #f lv j fhs) (ensures (log2c_bound j (32 - lv); mt_hashes_lth_inv_log_converted_ #_ #f lv j fhs; mt_hashes_inv_log #_ #f j (S.slice fhs lv (lv + log2c j)))) (decreases j) #pop-options #push-options "--z3rlimit 100 --initial_fuel 2 --max_fuel 2" let rec mt_hashes_inv_log_converted_ #_ #f lv j fhs = if j = 1 then () else (log2c_bound (j / 2) (32 - (lv + 1)); mt_hashes_lth_inv_log_converted_ #_ #f (lv + 1) (j / 2) fhs; mt_hashes_inv_log_converted_ #_ #f (lv + 1) (j / 2) fhs) #pop-options val mt_hashes_inv_log_converted: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> j:nat{j > 0 && j < pow2 32} -> fhs:hashess #hsz {S.length fhs = 32 /\ mt_hashes_lth_inv #hsz 0 j fhs} -> Lemma (requires mt_hashes_inv #_ #f 0 j fhs) (ensures (log2c_bound j 32; mt_hashes_lth_inv_log_converted_ #_ #f 0 j fhs; mt_hashes_inv_log #_ #f j (S.slice fhs 0 (log2c j)))) let mt_hashes_inv_log_converted #_ #f j fhs = mt_hashes_inv_log_converted_ #_ #f 0 j fhs val hash_seq_lift: #hsz:pos -> hs:hashes #hsz -> GTot (shs:MTS.hashes #hsz {S.length shs = S.length hs}) (decreases (S.length hs)) let rec hash_seq_lift #hsz hs = if S.length hs = 0 then S.empty else S.cons (MTS.HRaw (S.head hs)) (hash_seq_lift #hsz (S.tail hs)) #push-options "--z3rlimit 50 --initial_fuel 2 --max_fuel 2" val hash_seq_lift_index: #hsz:pos -> hs:hashes #hsz -> Lemma (requires True) (ensures forall (i:nat{i < S.length hs}). S.index (hash_seq_lift #hsz hs) i == MTS.HRaw (S.index hs i)) (decreases (S.length hs)) let rec hash_seq_lift_index #hsz hs = if S.length hs = 0 then () else hash_seq_lift_index #hsz (S.tail hs) #pop-options val create_pads: #hsz:pos -> len:nat -> GTot (pads:MTS.hashes #hsz {S.length pads = len}) let create_pads #hsz len = S.create len (MTS.HPad #hsz) val hash_seq_spec: #hsz:pos -> hs:hashes #hsz {S.length hs > 0} -> GTot (MTS.merkle_tree #hsz (log2c (S.length hs))) let hash_seq_spec #hsz hs = S.append (hash_seq_lift #hsz hs) (create_pads (pow2 (log2c (S.length hs)) - S.length hs)) val hash_seq_spec_index_raw: #hsz:pos -> hs:hashes #hsz {S.length hs > 0} -> i:nat{i < S.length hs} -> Lemma (S.index (hash_seq_spec #hsz hs) i == MTS.HRaw #hsz (S.index hs i)) let hash_seq_spec_index_raw #hsz hs i = hash_seq_lift_index #hsz hs // Now about recovering rightmost hashes #push-options "--z3rlimit 50 --initial_fuel 1 --max_fuel 1" val mt_hashes_next_rel_lift_even: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> j:nat{j > 1} -> hs:hashes #hsz {S.length hs = j} -> nhs:hashes #hsz {S.length nhs = j / 2} -> Lemma (requires j % 2 = 0 /\ mt_hashes_next_rel #_ #f j hs nhs) (ensures MTS.mt_next_rel #_ #f (log2c j) (hash_seq_spec #hsz hs) (hash_seq_spec #hsz nhs)) let mt_hashes_next_rel_lift_even #hsz #_ j hs nhs = hash_seq_lift_index #hsz hs; hash_seq_lift_index #hsz nhs val mt_hashes_next_rel_lift_odd: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> j:nat{j > 1} -> hs:hashes #hsz {S.length hs = j} -> nhs:hashes #hsz {S.length nhs = j / 2} -> Lemma (requires j % 2 = 1 /\ mt_hashes_next_rel #_ #f j hs nhs) (ensures MTS.mt_next_rel #_ #f (log2c j) (hash_seq_spec #hsz hs) (S.upd (hash_seq_spec #hsz nhs) (S.length nhs) (MTS.HRaw (S.last hs)))) let mt_hashes_next_rel_lift_odd #hsz #_ j hs nhs = log2c_div j; hash_seq_lift_index #hsz hs; hash_seq_lift_index #hsz nhs val mt_hashes_next_rel_next_even: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> j:nat{j > 1} -> hs:hashes #hsz {S.length hs = j} -> nhs:hashes #hsz {S.length nhs = j / 2} -> Lemma (requires j % 2 = 0 /\ mt_hashes_next_rel #_ #f j hs nhs) (ensures S.equal (hash_seq_spec #hsz nhs) (MTS.mt_next_lv #_ #f #(log2c j) (hash_seq_spec #hsz hs))) let mt_hashes_next_rel_next_even #hsz #f j hs nhs = log2c_div j; mt_hashes_next_rel_lift_even #_ #f j hs nhs; MTS.mt_next_rel_next_lv #_ #f (log2c j) (hash_seq_spec #hsz hs) (hash_seq_spec #hsz nhs) val hash_seq_spec_full: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> hs:hashes #hsz {S.length hs > 0} -> acc:hash #hsz -> actd:bool -> GTot (MTS.merkle_tree #hsz (log2c (S.length hs))) let hash_seq_spec_full #hsz #f hs acc actd = if actd then (S.upd (hash_seq_spec #hsz hs) (S.length hs) (MTS.HRaw acc)) else hash_seq_spec #hsz hs val hash_seq_spec_full_index_raw: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> hs:hashes #hsz {S.length hs > 0} -> acc:hash #hsz -> actd:bool -> i:nat{i < S.length hs} -> Lemma (S.index (hash_seq_spec_full #_ #f hs acc actd) i == MTS.HRaw (S.index hs i)) let hash_seq_spec_full_index_raw #hsz #_ hs acc actd i = hash_seq_spec_index_raw #hsz hs i val hash_seq_spec_full_case_true: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> hs:hashes #hsz {S.length hs > 0} -> acc:hash #hsz -> Lemma (S.index (hash_seq_spec_full #_ #f hs acc true) (S.length hs) == MTS.HRaw acc) let hash_seq_spec_full_case_true #_ #_ _ _ = () val hash_seq_spec_full_even_next: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> j:nat{j > 0} -> hs:hashes #hsz {S.length hs = j} -> nhs:hashes #hsz {S.length nhs = j / 2} -> acc:hash #hsz -> actd:bool -> Lemma (requires j % 2 = 0 /\ mt_hashes_next_rel #_ #f j hs nhs) (ensures S.equal (hash_seq_spec_full #_ #f nhs acc actd) (MTS.mt_next_lv #_ #f #(log2c j) (hash_seq_spec_full #_ #f hs acc actd))) #restart-solver #push-options "--quake 1/3 --z3rlimit 100 --fuel 2 --ifuel 1" let hash_seq_spec_full_even_next #hsz #f j hs nhs acc actd = log2c_div j; mt_hashes_next_rel_lift_even #_ #f j hs nhs; if actd then begin MTS.mt_next_rel_upd_even_pad #_ #f (log2c j) (hash_seq_spec #hsz hs) (hash_seq_spec #hsz nhs) (S.length hs / 2) (MTS.HRaw acc); let n = log2c j in let mt = S.upd (hash_seq_spec #hsz hs) (S.length hs) (MTS.HRaw acc) in let nmt = S.upd (hash_seq_spec #hsz nhs) (S.length nhs) (MTS.HRaw acc) in // assume (MTS.mt_next_rel #_ #f n mt nmt); MTS.mt_next_rel_next_lv #_ #f n mt nmt end else MTS.mt_next_rel_next_lv #_ #f (log2c j) (hash_seq_spec_full #_ #f hs acc actd) (hash_seq_spec_full #_ #f nhs acc actd) #pop-options #push-options "--z3rlimit 80" val hash_seq_spec_full_odd_next: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> j:nat{j > 1} -> hs:hashes #hsz {S.length hs = j} -> nhs:hashes #hsz {S.length nhs = j / 2} -> acc:hash #hsz -> actd:bool -> nacc:hash #hsz -> Lemma (requires j % 2 = 1 /\ mt_hashes_next_rel #_ #f j hs nhs /\ nacc == (if actd then f (S.last hs) acc else S.last hs)) (ensures S.equal (hash_seq_spec_full #_ #f nhs nacc true)
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "MerkleTree.Spec.fst.checked", "MerkleTree.New.High.fst.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Ghost.fsti.checked", "FStar.Classical.fsti.checked" ], "interface_file": false, "source_file": "MerkleTree.New.High.Correct.Base.fst" }
[ { "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": 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
j: Prims.nat{j > 1} -> hs: MerkleTree.New.High.hashes{FStar.Seq.Base.length hs = j} -> nhs: MerkleTree.New.High.hashes{FStar.Seq.Base.length nhs = j / 2} -> acc: MerkleTree.New.High.hash -> actd: Prims.bool -> nacc: MerkleTree.New.High.hash -> FStar.Pervasives.Lemma (requires j % 2 = 1 /\ MerkleTree.New.High.Correct.Base.mt_hashes_next_rel j hs nhs /\ nacc == (match actd with | true -> f (FStar.Seq.Properties.last hs) acc | _ -> FStar.Seq.Properties.last hs)) (ensures FStar.Seq.Base.equal (MerkleTree.New.High.Correct.Base.hash_seq_spec_full nhs nacc true) (MerkleTree.Spec.mt_next_lv (MerkleTree.New.High.Correct.Base.hash_seq_spec_full hs acc actd)))
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "Prims.pos", "MerkleTree.Spec.hash_fun_t", "Prims.nat", "Prims.b2t", "Prims.op_GreaterThan", "MerkleTree.New.High.hashes", "Prims.op_Equality", "FStar.Seq.Base.length", "MerkleTree.New.High.hash", "Prims.int", "Prims.op_Division", "Prims.bool", "MerkleTree.Spec.mt_next_rel_next_lv", "MerkleTree.New.High.Correct.Base.log2c", "FStar.Seq.Base.upd", "MerkleTree.Spec.padded_hash", "MerkleTree.New.High.Correct.Base.hash_seq_spec", "MerkleTree.Spec.HRaw", "FStar.Seq.Properties.last", "Prims.unit", "MerkleTree.Spec.mt_next_rel_upd_odd", "MerkleTree.New.High.Correct.Base.hash_seq_spec_full", "MerkleTree.New.High.Correct.Base.mt_hashes_next_rel_lift_odd", "MerkleTree.New.High.Correct.Base.log2c_div" ]
[]
false
false
true
false
false
let hash_seq_spec_full_odd_next #hsz #f j hs nhs acc actd nacc =
log2c_div j; mt_hashes_next_rel_lift_odd #_ #f j hs nhs; if actd then (MTS.mt_next_rel_upd_odd #_ #f (log2c j) (hash_seq_spec #hsz hs) (S.upd (hash_seq_spec #hsz nhs) (S.length nhs) (MTS.HRaw (S.last hs))) (S.length nhs) (MTS.HRaw acc); MTS.mt_next_rel_next_lv #_ #f (log2c j) (S.upd (hash_seq_spec #hsz hs) (S.length hs) (MTS.HRaw acc)) (S.upd (hash_seq_spec #hsz nhs) (S.length nhs) (MTS.HRaw (f (S.last hs) acc)))) else MTS.mt_next_rel_next_lv #_ #f (log2c j) (hash_seq_spec_full #_ #f hs acc actd) (hash_seq_spec_full #_ #f nhs nacc true)
false
LowParse.Low.Bytes.fst
LowParse.Low.Bytes.clens_flbytes_get
val clens_flbytes_get (sz: nat) (i: U32.t{U32.v i < sz}) : Tot (clens (BY.lbytes sz) byte)
val clens_flbytes_get (sz: nat) (i: U32.t{U32.v i < sz}) : Tot (clens (BY.lbytes sz) byte)
let clens_flbytes_get (sz: nat) (i: U32.t { U32.v i < sz } ) : Tot (clens (BY.lbytes sz) byte) = { clens_cond = (fun _ -> True); clens_get = (fun (x: BY.lbytes sz) -> (BY.get x i <: byte)); }
{ "file_name": "src/lowparse/LowParse.Low.Bytes.fst", "git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
{ "end_col": 1, "end_line": 123, "start_col": 0, "start_line": 116 }
module LowParse.Low.Bytes include LowParse.Spec.Bytes include LowParse.Low.Combinators include LowParse.Low.VLData include LowParse.Low.VLGen include LowParse.Low.Int module U32 = FStar.UInt32 module HS = FStar.HyperStack module B = LowStar.Monotonic.Buffer module BF = LowStar.Buffer // for local variables in store_bytes module BY = LowParse.Bytes32 module HST = FStar.HyperStack.ST module U8 = FStar.UInt8 module Cast = FStar.Int.Cast module U64 = FStar.UInt64 inline_for_extraction let validate_flbytes (sz: nat) (sz64: U64.t { U64.v sz64 == sz /\ sz < 4294967296 } ) : Tot (validator (parse_flbytes sz)) = validate_total_constant_size (parse_flbytes sz) sz64 () inline_for_extraction let jump_flbytes (sz: nat) (sz32: U32.t { U32.v sz32 == sz } ) : Tot (jumper (parse_flbytes sz)) = jump_constant_size (parse_flbytes sz) sz32 () let valid_flbytes_intro (h: HS.mem) (sz: nat { sz < 4294967296 } ) (#rrel #rel: _) (s: slice rrel rel) (pos: U32.t) : Lemma (requires (U32.v pos + sz <= U32.v s.len /\ live_slice h s)) (ensures ( valid_content_pos (parse_flbytes sz) h s pos (BY.hide (bytes_of_slice_from_to h s pos (pos `U32.add` U32.uint_to_t sz))) (pos `U32.add` U32.uint_to_t sz) )) = valid_facts (parse_flbytes sz) h s pos let valid_pos_flbytes_elim (h: HS.mem) (sz: nat { sz < 4294967296 } ) (#rrel #rel: _) (s: slice rrel rel) (pos pos' : U32.t) : Lemma (requires (valid_pos (parse_flbytes sz) h s pos pos')) (ensures (U32.v pos + sz == U32.v pos')) [SMTPat (valid_pos (parse_flbytes sz) h s pos pos')] = valid_facts (parse_flbytes sz) h s pos let valid_flbytes_elim (h: HS.mem) (sz: nat { sz < 4294967296 } ) (#rrel #rel: _) (s: slice rrel rel) (pos: U32.t) : Lemma (requires (valid (parse_flbytes sz) h s pos)) (ensures ( valid_content_pos (parse_flbytes sz) h s pos (BY.hide (bytes_of_slice_from_to h s pos (pos `U32.add` U32.uint_to_t sz))) (pos `U32.add` U32.uint_to_t sz) )) = valid_flbytes_intro h sz s pos let clens_flbytes_slice (sz: nat) (from: U32.t) (to: U32.t {U32.v from <= U32.v to /\ U32.v to <= sz } ) : Tot (clens (BY.lbytes sz) (BY.lbytes (U32.v to - U32.v from))) = { clens_cond = (fun _ -> True); clens_get = (fun (x: BY.lbytes sz) -> (BY.slice x from to <: BY.lbytes (U32.v to - U32.v from))); } #push-options "--z3rlimit 16" let gaccessor_flbytes_slice' (sz: nat { sz < 4294967296 } ) (from: U32.t) (to: U32.t {U32.v from <= U32.v to /\ U32.v to <= sz } ) : Tot (gaccessor' (parse_flbytes sz) (parse_flbytes (U32.v to - U32.v from)) (clens_flbytes_slice sz from to)) = fun (input: bytes) -> ( begin if Seq.length input < sz then (0) // dummy else (U32.v from) end) let gaccessor_flbytes_slice (sz: nat { sz < 4294967296 } ) (from: U32.t) (to: U32.t {U32.v from <= U32.v to /\ U32.v to <= sz } ) : Tot (gaccessor (parse_flbytes sz) (parse_flbytes (U32.v to - U32.v from)) (clens_flbytes_slice sz from to)) = assert (forall x . gaccessor_pre (parse_flbytes sz) (parse_flbytes (U32.v to - U32.v from)) (clens_flbytes_slice sz from to) x ==> sz <= Seq.length x); gaccessor_prop_equiv (parse_flbytes sz) (parse_flbytes (U32.v to - U32.v from)) (clens_flbytes_slice sz from to) (gaccessor_flbytes_slice' sz from to); gaccessor_flbytes_slice' sz from to inline_for_extraction let accessor_flbytes_slice (sz: nat { sz < 4294967296 } ) (from: U32.t) (to: U32.t {U32.v from <= U32.v to /\ U32.v to <= sz } ) : Tot (accessor (gaccessor_flbytes_slice sz from to)) = fun #rrel #rel input pos -> let h = HST.get () in [@inline_let] let _ = slice_access_eq h (gaccessor_flbytes_slice sz from to) input pos in pos `U32.add` from #pop-options
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowStar.Monotonic.Buffer.fsti.checked", "LowStar.Buffer.fst.checked", "LowParse.Spec.Bytes.fst.checked", "LowParse.Low.VLGen.fst.checked", "LowParse.Low.VLData.fst.checked", "LowParse.Low.Int.fsti.checked", "LowParse.Low.Combinators.fsti.checked", "LowParse.Bytes32.fst.checked", "FStar.UInt8.fsti.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Int.Cast.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked", "FStar.Classical.fsti.checked", "C.Loops.fst.checked" ], "interface_file": false, "source_file": "LowParse.Low.Bytes.fst" }
[ { "abbrev": true, "full_module": "LowStar.Buffer // for local variables in store_bytes", "short_module": "BF" }, { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "FStar.Int.Cast", "short_module": "Cast" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "LowParse.Bytes32", "short_module": "BY" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "BF" }, { "abbrev": true, "full_module": "LowStar.Monotonic.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": false, "full_module": "LowParse.Low.Int", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low.VLGen", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low.VLData", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low.Combinators", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec.Bytes", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
sz: Prims.nat -> i: FStar.UInt32.t{FStar.UInt32.v i < sz} -> LowParse.Low.Base.Spec.clens (FStar.Bytes.lbytes sz) LowParse.Bytes.byte
Prims.Tot
[ "total" ]
[]
[ "Prims.nat", "FStar.UInt32.t", "Prims.b2t", "Prims.op_LessThan", "FStar.UInt32.v", "LowParse.Low.Base.Spec.Mkclens", "FStar.Bytes.lbytes", "LowParse.Bytes.byte", "Prims.l_True", "FStar.Bytes.get", "LowParse.Low.Base.Spec.clens" ]
[]
false
false
false
false
false
let clens_flbytes_get (sz: nat) (i: U32.t{U32.v i < sz}) : Tot (clens (BY.lbytes sz) byte) =
{ clens_cond = (fun _ -> True); clens_get = (fun (x: BY.lbytes sz) -> (BY.get x i <: byte)) }
false
LowParse.Low.Bytes.fst
LowParse.Low.Bytes.clens_flbytes_slice
val clens_flbytes_slice (sz: nat) (from: U32.t) (to: U32.t{U32.v from <= U32.v to /\ U32.v to <= sz}) : Tot (clens (BY.lbytes sz) (BY.lbytes (U32.v to - U32.v from)))
val clens_flbytes_slice (sz: nat) (from: U32.t) (to: U32.t{U32.v from <= U32.v to /\ U32.v to <= sz}) : Tot (clens (BY.lbytes sz) (BY.lbytes (U32.v to - U32.v from)))
let clens_flbytes_slice (sz: nat) (from: U32.t) (to: U32.t {U32.v from <= U32.v to /\ U32.v to <= sz } ) : Tot (clens (BY.lbytes sz) (BY.lbytes (U32.v to - U32.v from))) = { clens_cond = (fun _ -> True); clens_get = (fun (x: BY.lbytes sz) -> (BY.slice x from to <: BY.lbytes (U32.v to - U32.v from))); }
{ "file_name": "src/lowparse/LowParse.Low.Bytes.fst", "git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
{ "end_col": 1, "end_line": 78, "start_col": 0, "start_line": 70 }
module LowParse.Low.Bytes include LowParse.Spec.Bytes include LowParse.Low.Combinators include LowParse.Low.VLData include LowParse.Low.VLGen include LowParse.Low.Int module U32 = FStar.UInt32 module HS = FStar.HyperStack module B = LowStar.Monotonic.Buffer module BF = LowStar.Buffer // for local variables in store_bytes module BY = LowParse.Bytes32 module HST = FStar.HyperStack.ST module U8 = FStar.UInt8 module Cast = FStar.Int.Cast module U64 = FStar.UInt64 inline_for_extraction let validate_flbytes (sz: nat) (sz64: U64.t { U64.v sz64 == sz /\ sz < 4294967296 } ) : Tot (validator (parse_flbytes sz)) = validate_total_constant_size (parse_flbytes sz) sz64 () inline_for_extraction let jump_flbytes (sz: nat) (sz32: U32.t { U32.v sz32 == sz } ) : Tot (jumper (parse_flbytes sz)) = jump_constant_size (parse_flbytes sz) sz32 () let valid_flbytes_intro (h: HS.mem) (sz: nat { sz < 4294967296 } ) (#rrel #rel: _) (s: slice rrel rel) (pos: U32.t) : Lemma (requires (U32.v pos + sz <= U32.v s.len /\ live_slice h s)) (ensures ( valid_content_pos (parse_flbytes sz) h s pos (BY.hide (bytes_of_slice_from_to h s pos (pos `U32.add` U32.uint_to_t sz))) (pos `U32.add` U32.uint_to_t sz) )) = valid_facts (parse_flbytes sz) h s pos let valid_pos_flbytes_elim (h: HS.mem) (sz: nat { sz < 4294967296 } ) (#rrel #rel: _) (s: slice rrel rel) (pos pos' : U32.t) : Lemma (requires (valid_pos (parse_flbytes sz) h s pos pos')) (ensures (U32.v pos + sz == U32.v pos')) [SMTPat (valid_pos (parse_flbytes sz) h s pos pos')] = valid_facts (parse_flbytes sz) h s pos let valid_flbytes_elim (h: HS.mem) (sz: nat { sz < 4294967296 } ) (#rrel #rel: _) (s: slice rrel rel) (pos: U32.t) : Lemma (requires (valid (parse_flbytes sz) h s pos)) (ensures ( valid_content_pos (parse_flbytes sz) h s pos (BY.hide (bytes_of_slice_from_to h s pos (pos `U32.add` U32.uint_to_t sz))) (pos `U32.add` U32.uint_to_t sz) )) = valid_flbytes_intro h sz s pos
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowStar.Monotonic.Buffer.fsti.checked", "LowStar.Buffer.fst.checked", "LowParse.Spec.Bytes.fst.checked", "LowParse.Low.VLGen.fst.checked", "LowParse.Low.VLData.fst.checked", "LowParse.Low.Int.fsti.checked", "LowParse.Low.Combinators.fsti.checked", "LowParse.Bytes32.fst.checked", "FStar.UInt8.fsti.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Int.Cast.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked", "FStar.Classical.fsti.checked", "C.Loops.fst.checked" ], "interface_file": false, "source_file": "LowParse.Low.Bytes.fst" }
[ { "abbrev": true, "full_module": "LowStar.Buffer // for local variables in store_bytes", "short_module": "BF" }, { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "FStar.Int.Cast", "short_module": "Cast" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "LowParse.Bytes32", "short_module": "BY" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "BF" }, { "abbrev": true, "full_module": "LowStar.Monotonic.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": false, "full_module": "LowParse.Low.Int", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low.VLGen", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low.VLData", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low.Combinators", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec.Bytes", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
sz: Prims.nat -> from: FStar.UInt32.t -> to: FStar.UInt32.t{FStar.UInt32.v from <= FStar.UInt32.v to /\ FStar.UInt32.v to <= sz} -> LowParse.Low.Base.Spec.clens (FStar.Bytes.lbytes sz) (FStar.Bytes.lbytes (FStar.UInt32.v to - FStar.UInt32.v from))
Prims.Tot
[ "total" ]
[]
[ "Prims.nat", "FStar.UInt32.t", "Prims.l_and", "Prims.b2t", "Prims.op_LessThanOrEqual", "FStar.UInt32.v", "LowParse.Low.Base.Spec.Mkclens", "FStar.Bytes.lbytes", "Prims.op_Subtraction", "Prims.l_True", "FStar.Bytes.slice", "LowParse.Low.Base.Spec.clens" ]
[]
false
false
false
false
false
let clens_flbytes_slice (sz: nat) (from: U32.t) (to: U32.t{U32.v from <= U32.v to /\ U32.v to <= sz}) : Tot (clens (BY.lbytes sz) (BY.lbytes (U32.v to - U32.v from))) =
{ clens_cond = (fun _ -> True); clens_get = (fun (x: BY.lbytes sz) -> (BY.slice x from to <: BY.lbytes (U32.v to - U32.v from))) }
false
LowParse.Low.Bytes.fst
LowParse.Low.Bytes.valid_pos_flbytes_elim
val valid_pos_flbytes_elim (h: HS.mem) (sz: nat{sz < 4294967296}) (#rrel #rel: _) (s: slice rrel rel) (pos pos': U32.t) : Lemma (requires (valid_pos (parse_flbytes sz) h s pos pos')) (ensures (U32.v pos + sz == U32.v pos')) [SMTPat (valid_pos (parse_flbytes sz) h s pos pos')]
val valid_pos_flbytes_elim (h: HS.mem) (sz: nat{sz < 4294967296}) (#rrel #rel: _) (s: slice rrel rel) (pos pos': U32.t) : Lemma (requires (valid_pos (parse_flbytes sz) h s pos pos')) (ensures (U32.v pos + sz == U32.v pos')) [SMTPat (valid_pos (parse_flbytes sz) h s pos pos')]
let valid_pos_flbytes_elim (h: HS.mem) (sz: nat { sz < 4294967296 } ) (#rrel #rel: _) (s: slice rrel rel) (pos pos' : U32.t) : Lemma (requires (valid_pos (parse_flbytes sz) h s pos pos')) (ensures (U32.v pos + sz == U32.v pos')) [SMTPat (valid_pos (parse_flbytes sz) h s pos pos')] = valid_facts (parse_flbytes sz) h s pos
{ "file_name": "src/lowparse/LowParse.Low.Bytes.fst", "git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
{ "end_col": 40, "end_line": 55, "start_col": 0, "start_line": 45 }
module LowParse.Low.Bytes include LowParse.Spec.Bytes include LowParse.Low.Combinators include LowParse.Low.VLData include LowParse.Low.VLGen include LowParse.Low.Int module U32 = FStar.UInt32 module HS = FStar.HyperStack module B = LowStar.Monotonic.Buffer module BF = LowStar.Buffer // for local variables in store_bytes module BY = LowParse.Bytes32 module HST = FStar.HyperStack.ST module U8 = FStar.UInt8 module Cast = FStar.Int.Cast module U64 = FStar.UInt64 inline_for_extraction let validate_flbytes (sz: nat) (sz64: U64.t { U64.v sz64 == sz /\ sz < 4294967296 } ) : Tot (validator (parse_flbytes sz)) = validate_total_constant_size (parse_flbytes sz) sz64 () inline_for_extraction let jump_flbytes (sz: nat) (sz32: U32.t { U32.v sz32 == sz } ) : Tot (jumper (parse_flbytes sz)) = jump_constant_size (parse_flbytes sz) sz32 () let valid_flbytes_intro (h: HS.mem) (sz: nat { sz < 4294967296 } ) (#rrel #rel: _) (s: slice rrel rel) (pos: U32.t) : Lemma (requires (U32.v pos + sz <= U32.v s.len /\ live_slice h s)) (ensures ( valid_content_pos (parse_flbytes sz) h s pos (BY.hide (bytes_of_slice_from_to h s pos (pos `U32.add` U32.uint_to_t sz))) (pos `U32.add` U32.uint_to_t sz) )) = valid_facts (parse_flbytes sz) h s pos
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowStar.Monotonic.Buffer.fsti.checked", "LowStar.Buffer.fst.checked", "LowParse.Spec.Bytes.fst.checked", "LowParse.Low.VLGen.fst.checked", "LowParse.Low.VLData.fst.checked", "LowParse.Low.Int.fsti.checked", "LowParse.Low.Combinators.fsti.checked", "LowParse.Bytes32.fst.checked", "FStar.UInt8.fsti.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Int.Cast.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked", "FStar.Classical.fsti.checked", "C.Loops.fst.checked" ], "interface_file": false, "source_file": "LowParse.Low.Bytes.fst" }
[ { "abbrev": true, "full_module": "LowStar.Buffer // for local variables in store_bytes", "short_module": "BF" }, { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "FStar.Int.Cast", "short_module": "Cast" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "LowParse.Bytes32", "short_module": "BY" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "BF" }, { "abbrev": true, "full_module": "LowStar.Monotonic.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": false, "full_module": "LowParse.Low.Int", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low.VLGen", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low.VLData", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low.Combinators", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec.Bytes", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
h: FStar.Monotonic.HyperStack.mem -> sz: Prims.nat{sz < 4294967296} -> s: LowParse.Slice.slice rrel rel -> pos: FStar.UInt32.t -> pos': FStar.UInt32.t -> FStar.Pervasives.Lemma (requires LowParse.Low.Base.Spec.valid_pos (LowParse.Spec.Bytes.parse_flbytes sz) h s pos pos' ) (ensures FStar.UInt32.v pos + sz == FStar.UInt32.v pos') [ SMTPat (LowParse.Low.Base.Spec.valid_pos (LowParse.Spec.Bytes.parse_flbytes sz) h s pos pos' ) ]
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "FStar.Monotonic.HyperStack.mem", "Prims.nat", "Prims.b2t", "Prims.op_LessThan", "LowParse.Slice.srel", "LowParse.Bytes.byte", "LowParse.Slice.slice", "FStar.UInt32.t", "LowParse.Low.Base.Spec.valid_facts", "LowParse.Spec.Base.total_constant_size_parser_kind", "FStar.Bytes.lbytes", "LowParse.Spec.Bytes.parse_flbytes", "Prims.unit", "LowParse.Low.Base.Spec.valid_pos", "Prims.squash", "Prims.eq2", "Prims.int", "Prims.op_Addition", "FStar.UInt32.v", "Prims.Cons", "FStar.Pervasives.pattern", "FStar.Pervasives.smt_pat", "Prims.logical", "Prims.Nil" ]
[]
true
false
true
false
false
let valid_pos_flbytes_elim (h: HS.mem) (sz: nat{sz < 4294967296}) (#rrel #rel: _) (s: slice rrel rel) (pos pos': U32.t) : Lemma (requires (valid_pos (parse_flbytes sz) h s pos pos')) (ensures (U32.v pos + sz == U32.v pos')) [SMTPat (valid_pos (parse_flbytes sz) h s pos pos')] =
valid_facts (parse_flbytes sz) h s pos
false
LowParse.Low.Bytes.fst
LowParse.Low.Bytes.validate_flbytes
val validate_flbytes (sz: nat) (sz64: U64.t{U64.v sz64 == sz /\ sz < 4294967296}) : Tot (validator (parse_flbytes sz))
val validate_flbytes (sz: nat) (sz64: U64.t{U64.v sz64 == sz /\ sz < 4294967296}) : Tot (validator (parse_flbytes sz))
let validate_flbytes (sz: nat) (sz64: U64.t { U64.v sz64 == sz /\ sz < 4294967296 } ) : Tot (validator (parse_flbytes sz)) = validate_total_constant_size (parse_flbytes sz) sz64 ()
{ "file_name": "src/lowparse/LowParse.Low.Bytes.fst", "git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
{ "end_col": 57, "end_line": 23, "start_col": 0, "start_line": 19 }
module LowParse.Low.Bytes include LowParse.Spec.Bytes include LowParse.Low.Combinators include LowParse.Low.VLData include LowParse.Low.VLGen include LowParse.Low.Int module U32 = FStar.UInt32 module HS = FStar.HyperStack module B = LowStar.Monotonic.Buffer module BF = LowStar.Buffer // for local variables in store_bytes module BY = LowParse.Bytes32 module HST = FStar.HyperStack.ST module U8 = FStar.UInt8 module Cast = FStar.Int.Cast module U64 = FStar.UInt64
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowStar.Monotonic.Buffer.fsti.checked", "LowStar.Buffer.fst.checked", "LowParse.Spec.Bytes.fst.checked", "LowParse.Low.VLGen.fst.checked", "LowParse.Low.VLData.fst.checked", "LowParse.Low.Int.fsti.checked", "LowParse.Low.Combinators.fsti.checked", "LowParse.Bytes32.fst.checked", "FStar.UInt8.fsti.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Int.Cast.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked", "FStar.Classical.fsti.checked", "C.Loops.fst.checked" ], "interface_file": false, "source_file": "LowParse.Low.Bytes.fst" }
[ { "abbrev": true, "full_module": "LowStar.Buffer // for local variables in store_bytes", "short_module": "BF" }, { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "FStar.Int.Cast", "short_module": "Cast" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "LowParse.Bytes32", "short_module": "BY" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "BF" }, { "abbrev": true, "full_module": "LowStar.Monotonic.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": false, "full_module": "LowParse.Low.Int", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low.VLGen", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low.VLData", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low.Combinators", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec.Bytes", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
sz: Prims.nat -> sz64: FStar.UInt64.t{FStar.UInt64.v sz64 == sz /\ sz < 4294967296} -> LowParse.Low.Base.validator (LowParse.Spec.Bytes.parse_flbytes sz)
Prims.Tot
[ "total" ]
[]
[ "Prims.nat", "FStar.UInt64.t", "Prims.l_and", "Prims.eq2", "Prims.int", "Prims.l_or", "FStar.UInt.size", "FStar.UInt64.n", "Prims.b2t", "Prims.op_GreaterThanOrEqual", "FStar.UInt64.v", "Prims.op_LessThan", "LowParse.Low.Base.validate_total_constant_size", "LowParse.Spec.Base.total_constant_size_parser_kind", "FStar.Bytes.lbytes", "LowParse.Spec.Bytes.parse_flbytes", "LowParse.Low.Base.validator" ]
[]
false
false
false
false
false
let validate_flbytes (sz: nat) (sz64: U64.t{U64.v sz64 == sz /\ sz < 4294967296}) : Tot (validator (parse_flbytes sz)) =
validate_total_constant_size (parse_flbytes sz) sz64 ()
false
LowParse.Low.Bytes.fst
LowParse.Low.Bytes.jump_flbytes
val jump_flbytes (sz: nat) (sz32: U32.t{U32.v sz32 == sz}) : Tot (jumper (parse_flbytes sz))
val jump_flbytes (sz: nat) (sz32: U32.t{U32.v sz32 == sz}) : Tot (jumper (parse_flbytes sz))
let jump_flbytes (sz: nat) (sz32: U32.t { U32.v sz32 == sz } ) : Tot (jumper (parse_flbytes sz)) = jump_constant_size (parse_flbytes sz) sz32 ()
{ "file_name": "src/lowparse/LowParse.Low.Bytes.fst", "git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
{ "end_col": 47, "end_line": 30, "start_col": 0, "start_line": 26 }
module LowParse.Low.Bytes include LowParse.Spec.Bytes include LowParse.Low.Combinators include LowParse.Low.VLData include LowParse.Low.VLGen include LowParse.Low.Int module U32 = FStar.UInt32 module HS = FStar.HyperStack module B = LowStar.Monotonic.Buffer module BF = LowStar.Buffer // for local variables in store_bytes module BY = LowParse.Bytes32 module HST = FStar.HyperStack.ST module U8 = FStar.UInt8 module Cast = FStar.Int.Cast module U64 = FStar.UInt64 inline_for_extraction let validate_flbytes (sz: nat) (sz64: U64.t { U64.v sz64 == sz /\ sz < 4294967296 } ) : Tot (validator (parse_flbytes sz)) = validate_total_constant_size (parse_flbytes sz) sz64 ()
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowStar.Monotonic.Buffer.fsti.checked", "LowStar.Buffer.fst.checked", "LowParse.Spec.Bytes.fst.checked", "LowParse.Low.VLGen.fst.checked", "LowParse.Low.VLData.fst.checked", "LowParse.Low.Int.fsti.checked", "LowParse.Low.Combinators.fsti.checked", "LowParse.Bytes32.fst.checked", "FStar.UInt8.fsti.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Int.Cast.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked", "FStar.Classical.fsti.checked", "C.Loops.fst.checked" ], "interface_file": false, "source_file": "LowParse.Low.Bytes.fst" }
[ { "abbrev": true, "full_module": "LowStar.Buffer // for local variables in store_bytes", "short_module": "BF" }, { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "FStar.Int.Cast", "short_module": "Cast" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "LowParse.Bytes32", "short_module": "BY" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "BF" }, { "abbrev": true, "full_module": "LowStar.Monotonic.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": false, "full_module": "LowParse.Low.Int", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low.VLGen", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low.VLData", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low.Combinators", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec.Bytes", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
sz: Prims.nat -> sz32: FStar.UInt32.t{FStar.UInt32.v sz32 == sz} -> LowParse.Low.Base.jumper (LowParse.Spec.Bytes.parse_flbytes sz)
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", "LowParse.Low.Base.jump_constant_size", "LowParse.Spec.Base.total_constant_size_parser_kind", "FStar.Bytes.lbytes", "LowParse.Spec.Bytes.parse_flbytes", "LowParse.Low.Base.jumper" ]
[]
false
false
false
false
false
let jump_flbytes (sz: nat) (sz32: U32.t{U32.v sz32 == sz}) : Tot (jumper (parse_flbytes sz)) =
jump_constant_size (parse_flbytes sz) sz32 ()
false
LowParse.Low.Bytes.fst
LowParse.Low.Bytes.gaccessor_flbytes_get
val gaccessor_flbytes_get (sz: nat{sz < 4294967296}) (i: U32.t{U32.v i < sz}) : Tot (gaccessor (parse_flbytes sz) (parse_u8) (clens_flbytes_get sz i))
val gaccessor_flbytes_get (sz: nat{sz < 4294967296}) (i: U32.t{U32.v i < sz}) : Tot (gaccessor (parse_flbytes sz) (parse_u8) (clens_flbytes_get sz i))
let gaccessor_flbytes_get (sz: nat { sz < 4294967296 } ) (i: U32.t { U32.v i < sz } ) : Tot (gaccessor (parse_flbytes sz) (parse_u8) (clens_flbytes_get sz i)) = assert (forall x . gaccessor_pre (parse_flbytes sz) (parse_u8) (clens_flbytes_get sz i) x ==> U32.v i <= Seq.length x); gaccessor_prop_equiv (parse_flbytes sz) (parse_u8) (clens_flbytes_get sz i) (gaccessor_flbytes_get' sz i); gaccessor_flbytes_get' sz i
{ "file_name": "src/lowparse/LowParse.Low.Bytes.fst", "git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
{ "end_col": 29, "end_line": 156, "start_col": 0, "start_line": 150 }
module LowParse.Low.Bytes include LowParse.Spec.Bytes include LowParse.Low.Combinators include LowParse.Low.VLData include LowParse.Low.VLGen include LowParse.Low.Int module U32 = FStar.UInt32 module HS = FStar.HyperStack module B = LowStar.Monotonic.Buffer module BF = LowStar.Buffer // for local variables in store_bytes module BY = LowParse.Bytes32 module HST = FStar.HyperStack.ST module U8 = FStar.UInt8 module Cast = FStar.Int.Cast module U64 = FStar.UInt64 inline_for_extraction let validate_flbytes (sz: nat) (sz64: U64.t { U64.v sz64 == sz /\ sz < 4294967296 } ) : Tot (validator (parse_flbytes sz)) = validate_total_constant_size (parse_flbytes sz) sz64 () inline_for_extraction let jump_flbytes (sz: nat) (sz32: U32.t { U32.v sz32 == sz } ) : Tot (jumper (parse_flbytes sz)) = jump_constant_size (parse_flbytes sz) sz32 () let valid_flbytes_intro (h: HS.mem) (sz: nat { sz < 4294967296 } ) (#rrel #rel: _) (s: slice rrel rel) (pos: U32.t) : Lemma (requires (U32.v pos + sz <= U32.v s.len /\ live_slice h s)) (ensures ( valid_content_pos (parse_flbytes sz) h s pos (BY.hide (bytes_of_slice_from_to h s pos (pos `U32.add` U32.uint_to_t sz))) (pos `U32.add` U32.uint_to_t sz) )) = valid_facts (parse_flbytes sz) h s pos let valid_pos_flbytes_elim (h: HS.mem) (sz: nat { sz < 4294967296 } ) (#rrel #rel: _) (s: slice rrel rel) (pos pos' : U32.t) : Lemma (requires (valid_pos (parse_flbytes sz) h s pos pos')) (ensures (U32.v pos + sz == U32.v pos')) [SMTPat (valid_pos (parse_flbytes sz) h s pos pos')] = valid_facts (parse_flbytes sz) h s pos let valid_flbytes_elim (h: HS.mem) (sz: nat { sz < 4294967296 } ) (#rrel #rel: _) (s: slice rrel rel) (pos: U32.t) : Lemma (requires (valid (parse_flbytes sz) h s pos)) (ensures ( valid_content_pos (parse_flbytes sz) h s pos (BY.hide (bytes_of_slice_from_to h s pos (pos `U32.add` U32.uint_to_t sz))) (pos `U32.add` U32.uint_to_t sz) )) = valid_flbytes_intro h sz s pos let clens_flbytes_slice (sz: nat) (from: U32.t) (to: U32.t {U32.v from <= U32.v to /\ U32.v to <= sz } ) : Tot (clens (BY.lbytes sz) (BY.lbytes (U32.v to - U32.v from))) = { clens_cond = (fun _ -> True); clens_get = (fun (x: BY.lbytes sz) -> (BY.slice x from to <: BY.lbytes (U32.v to - U32.v from))); } #push-options "--z3rlimit 16" let gaccessor_flbytes_slice' (sz: nat { sz < 4294967296 } ) (from: U32.t) (to: U32.t {U32.v from <= U32.v to /\ U32.v to <= sz } ) : Tot (gaccessor' (parse_flbytes sz) (parse_flbytes (U32.v to - U32.v from)) (clens_flbytes_slice sz from to)) = fun (input: bytes) -> ( begin if Seq.length input < sz then (0) // dummy else (U32.v from) end) let gaccessor_flbytes_slice (sz: nat { sz < 4294967296 } ) (from: U32.t) (to: U32.t {U32.v from <= U32.v to /\ U32.v to <= sz } ) : Tot (gaccessor (parse_flbytes sz) (parse_flbytes (U32.v to - U32.v from)) (clens_flbytes_slice sz from to)) = assert (forall x . gaccessor_pre (parse_flbytes sz) (parse_flbytes (U32.v to - U32.v from)) (clens_flbytes_slice sz from to) x ==> sz <= Seq.length x); gaccessor_prop_equiv (parse_flbytes sz) (parse_flbytes (U32.v to - U32.v from)) (clens_flbytes_slice sz from to) (gaccessor_flbytes_slice' sz from to); gaccessor_flbytes_slice' sz from to inline_for_extraction let accessor_flbytes_slice (sz: nat { sz < 4294967296 } ) (from: U32.t) (to: U32.t {U32.v from <= U32.v to /\ U32.v to <= sz } ) : Tot (accessor (gaccessor_flbytes_slice sz from to)) = fun #rrel #rel input pos -> let h = HST.get () in [@inline_let] let _ = slice_access_eq h (gaccessor_flbytes_slice sz from to) input pos in pos `U32.add` from #pop-options let clens_flbytes_get (sz: nat) (i: U32.t { U32.v i < sz } ) : Tot (clens (BY.lbytes sz) byte) = { clens_cond = (fun _ -> True); clens_get = (fun (x: BY.lbytes sz) -> (BY.get x i <: byte)); } #push-options "--z3rlimit 16 --max_fuel 1" let gaccessor_flbytes_get' (sz: nat { sz < 4294967296 } ) (i: U32.t { U32.v i < sz } ) : Tot (gaccessor' (parse_flbytes sz) (parse_u8) (clens_flbytes_get sz i)) = fun (input: bytes) -> ( begin let res = if Seq.length input < U32.v i then (0) // dummy else (U32.v i) in let g () : Lemma (requires (gaccessor_pre (parse_flbytes sz) parse_u8 (clens_flbytes_get sz i) input)) (ensures (gaccessor_post (parse_flbytes sz) parse_u8 (clens_flbytes_get sz i) input res)) = parser_kind_prop_equiv (get_parser_kind parse_u8) parse_u8; assert (res == (U32.v i)); parse_u8_spec' (Seq.slice input (U32.v i) (U32.v i + 1)); parse_strong_prefix parse_u8 (Seq.slice input (U32.v i) (U32.v i + 1)) (Seq.slice input (U32.v i) (Seq.length input)) in Classical.move_requires g (); res end) #pop-options
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowStar.Monotonic.Buffer.fsti.checked", "LowStar.Buffer.fst.checked", "LowParse.Spec.Bytes.fst.checked", "LowParse.Low.VLGen.fst.checked", "LowParse.Low.VLData.fst.checked", "LowParse.Low.Int.fsti.checked", "LowParse.Low.Combinators.fsti.checked", "LowParse.Bytes32.fst.checked", "FStar.UInt8.fsti.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Int.Cast.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked", "FStar.Classical.fsti.checked", "C.Loops.fst.checked" ], "interface_file": false, "source_file": "LowParse.Low.Bytes.fst" }
[ { "abbrev": true, "full_module": "LowStar.Buffer // for local variables in store_bytes", "short_module": "BF" }, { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "FStar.Int.Cast", "short_module": "Cast" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "LowParse.Bytes32", "short_module": "BY" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "BF" }, { "abbrev": true, "full_module": "LowStar.Monotonic.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": false, "full_module": "LowParse.Low.Int", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low.VLGen", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low.VLData", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low.Combinators", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec.Bytes", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
sz: Prims.nat{sz < 4294967296} -> i: FStar.UInt32.t{FStar.UInt32.v i < sz} -> LowParse.Low.Base.Spec.gaccessor (LowParse.Spec.Bytes.parse_flbytes sz) LowParse.Spec.Int.parse_u8 (LowParse.Low.Bytes.clens_flbytes_get sz i)
Prims.Tot
[ "total" ]
[]
[ "Prims.nat", "Prims.b2t", "Prims.op_LessThan", "FStar.UInt32.t", "FStar.UInt32.v", "LowParse.Low.Bytes.gaccessor_flbytes_get'", "Prims.unit", "LowParse.Low.Base.Spec.gaccessor_prop_equiv", "LowParse.Spec.Base.total_constant_size_parser_kind", "FStar.Bytes.lbytes", "LowParse.Spec.Bytes.parse_flbytes", "LowParse.Spec.Int.parse_u8_kind", "FStar.UInt8.t", "LowParse.Spec.Int.parse_u8", "LowParse.Low.Bytes.clens_flbytes_get", "Prims._assert", "Prims.l_Forall", "FStar.Seq.Base.seq", "LowParse.Bytes.byte", "Prims.l_imp", "LowParse.Low.Base.Spec.gaccessor_pre", "Prims.op_LessThanOrEqual", "FStar.Seq.Base.length", "LowParse.Low.Base.Spec.gaccessor" ]
[]
false
false
false
false
false
let gaccessor_flbytes_get (sz: nat{sz < 4294967296}) (i: U32.t{U32.v i < sz}) : Tot (gaccessor (parse_flbytes sz) (parse_u8) (clens_flbytes_get sz i)) =
assert (forall x. gaccessor_pre (parse_flbytes sz) (parse_u8) (clens_flbytes_get sz i) x ==> U32.v i <= Seq.length x); gaccessor_prop_equiv (parse_flbytes sz) (parse_u8) (clens_flbytes_get sz i) (gaccessor_flbytes_get' sz i); gaccessor_flbytes_get' sz i
false
LowParse.Low.Bytes.fst
LowParse.Low.Bytes.accessor_flbytes_get
val accessor_flbytes_get (sz: nat{sz < 4294967296}) (i: U32.t{U32.v i < sz}) : Tot (accessor (gaccessor_flbytes_get sz i))
val accessor_flbytes_get (sz: nat{sz < 4294967296}) (i: U32.t{U32.v i < sz}) : Tot (accessor (gaccessor_flbytes_get sz i))
let accessor_flbytes_get (sz: nat { sz < 4294967296 } ) (i: U32.t { U32.v i < sz } ) : Tot (accessor (gaccessor_flbytes_get sz i)) = fun #rrel #rel input pos -> let h = HST.get () in [@inline_let] let _ = slice_access_eq h (gaccessor_flbytes_get sz i) input pos in pos `U32.add` i
{ "file_name": "src/lowparse/LowParse.Low.Bytes.fst", "git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
{ "end_col": 17, "end_line": 166, "start_col": 0, "start_line": 159 }
module LowParse.Low.Bytes include LowParse.Spec.Bytes include LowParse.Low.Combinators include LowParse.Low.VLData include LowParse.Low.VLGen include LowParse.Low.Int module U32 = FStar.UInt32 module HS = FStar.HyperStack module B = LowStar.Monotonic.Buffer module BF = LowStar.Buffer // for local variables in store_bytes module BY = LowParse.Bytes32 module HST = FStar.HyperStack.ST module U8 = FStar.UInt8 module Cast = FStar.Int.Cast module U64 = FStar.UInt64 inline_for_extraction let validate_flbytes (sz: nat) (sz64: U64.t { U64.v sz64 == sz /\ sz < 4294967296 } ) : Tot (validator (parse_flbytes sz)) = validate_total_constant_size (parse_flbytes sz) sz64 () inline_for_extraction let jump_flbytes (sz: nat) (sz32: U32.t { U32.v sz32 == sz } ) : Tot (jumper (parse_flbytes sz)) = jump_constant_size (parse_flbytes sz) sz32 () let valid_flbytes_intro (h: HS.mem) (sz: nat { sz < 4294967296 } ) (#rrel #rel: _) (s: slice rrel rel) (pos: U32.t) : Lemma (requires (U32.v pos + sz <= U32.v s.len /\ live_slice h s)) (ensures ( valid_content_pos (parse_flbytes sz) h s pos (BY.hide (bytes_of_slice_from_to h s pos (pos `U32.add` U32.uint_to_t sz))) (pos `U32.add` U32.uint_to_t sz) )) = valid_facts (parse_flbytes sz) h s pos let valid_pos_flbytes_elim (h: HS.mem) (sz: nat { sz < 4294967296 } ) (#rrel #rel: _) (s: slice rrel rel) (pos pos' : U32.t) : Lemma (requires (valid_pos (parse_flbytes sz) h s pos pos')) (ensures (U32.v pos + sz == U32.v pos')) [SMTPat (valid_pos (parse_flbytes sz) h s pos pos')] = valid_facts (parse_flbytes sz) h s pos let valid_flbytes_elim (h: HS.mem) (sz: nat { sz < 4294967296 } ) (#rrel #rel: _) (s: slice rrel rel) (pos: U32.t) : Lemma (requires (valid (parse_flbytes sz) h s pos)) (ensures ( valid_content_pos (parse_flbytes sz) h s pos (BY.hide (bytes_of_slice_from_to h s pos (pos `U32.add` U32.uint_to_t sz))) (pos `U32.add` U32.uint_to_t sz) )) = valid_flbytes_intro h sz s pos let clens_flbytes_slice (sz: nat) (from: U32.t) (to: U32.t {U32.v from <= U32.v to /\ U32.v to <= sz } ) : Tot (clens (BY.lbytes sz) (BY.lbytes (U32.v to - U32.v from))) = { clens_cond = (fun _ -> True); clens_get = (fun (x: BY.lbytes sz) -> (BY.slice x from to <: BY.lbytes (U32.v to - U32.v from))); } #push-options "--z3rlimit 16" let gaccessor_flbytes_slice' (sz: nat { sz < 4294967296 } ) (from: U32.t) (to: U32.t {U32.v from <= U32.v to /\ U32.v to <= sz } ) : Tot (gaccessor' (parse_flbytes sz) (parse_flbytes (U32.v to - U32.v from)) (clens_flbytes_slice sz from to)) = fun (input: bytes) -> ( begin if Seq.length input < sz then (0) // dummy else (U32.v from) end) let gaccessor_flbytes_slice (sz: nat { sz < 4294967296 } ) (from: U32.t) (to: U32.t {U32.v from <= U32.v to /\ U32.v to <= sz } ) : Tot (gaccessor (parse_flbytes sz) (parse_flbytes (U32.v to - U32.v from)) (clens_flbytes_slice sz from to)) = assert (forall x . gaccessor_pre (parse_flbytes sz) (parse_flbytes (U32.v to - U32.v from)) (clens_flbytes_slice sz from to) x ==> sz <= Seq.length x); gaccessor_prop_equiv (parse_flbytes sz) (parse_flbytes (U32.v to - U32.v from)) (clens_flbytes_slice sz from to) (gaccessor_flbytes_slice' sz from to); gaccessor_flbytes_slice' sz from to inline_for_extraction let accessor_flbytes_slice (sz: nat { sz < 4294967296 } ) (from: U32.t) (to: U32.t {U32.v from <= U32.v to /\ U32.v to <= sz } ) : Tot (accessor (gaccessor_flbytes_slice sz from to)) = fun #rrel #rel input pos -> let h = HST.get () in [@inline_let] let _ = slice_access_eq h (gaccessor_flbytes_slice sz from to) input pos in pos `U32.add` from #pop-options let clens_flbytes_get (sz: nat) (i: U32.t { U32.v i < sz } ) : Tot (clens (BY.lbytes sz) byte) = { clens_cond = (fun _ -> True); clens_get = (fun (x: BY.lbytes sz) -> (BY.get x i <: byte)); } #push-options "--z3rlimit 16 --max_fuel 1" let gaccessor_flbytes_get' (sz: nat { sz < 4294967296 } ) (i: U32.t { U32.v i < sz } ) : Tot (gaccessor' (parse_flbytes sz) (parse_u8) (clens_flbytes_get sz i)) = fun (input: bytes) -> ( begin let res = if Seq.length input < U32.v i then (0) // dummy else (U32.v i) in let g () : Lemma (requires (gaccessor_pre (parse_flbytes sz) parse_u8 (clens_flbytes_get sz i) input)) (ensures (gaccessor_post (parse_flbytes sz) parse_u8 (clens_flbytes_get sz i) input res)) = parser_kind_prop_equiv (get_parser_kind parse_u8) parse_u8; assert (res == (U32.v i)); parse_u8_spec' (Seq.slice input (U32.v i) (U32.v i + 1)); parse_strong_prefix parse_u8 (Seq.slice input (U32.v i) (U32.v i + 1)) (Seq.slice input (U32.v i) (Seq.length input)) in Classical.move_requires g (); res end) #pop-options let gaccessor_flbytes_get (sz: nat { sz < 4294967296 } ) (i: U32.t { U32.v i < sz } ) : Tot (gaccessor (parse_flbytes sz) (parse_u8) (clens_flbytes_get sz i)) = assert (forall x . gaccessor_pre (parse_flbytes sz) (parse_u8) (clens_flbytes_get sz i) x ==> U32.v i <= Seq.length x); gaccessor_prop_equiv (parse_flbytes sz) (parse_u8) (clens_flbytes_get sz i) (gaccessor_flbytes_get' sz i); gaccessor_flbytes_get' sz i
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowStar.Monotonic.Buffer.fsti.checked", "LowStar.Buffer.fst.checked", "LowParse.Spec.Bytes.fst.checked", "LowParse.Low.VLGen.fst.checked", "LowParse.Low.VLData.fst.checked", "LowParse.Low.Int.fsti.checked", "LowParse.Low.Combinators.fsti.checked", "LowParse.Bytes32.fst.checked", "FStar.UInt8.fsti.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Int.Cast.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked", "FStar.Classical.fsti.checked", "C.Loops.fst.checked" ], "interface_file": false, "source_file": "LowParse.Low.Bytes.fst" }
[ { "abbrev": true, "full_module": "LowStar.Buffer // for local variables in store_bytes", "short_module": "BF" }, { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "FStar.Int.Cast", "short_module": "Cast" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "LowParse.Bytes32", "short_module": "BY" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "BF" }, { "abbrev": true, "full_module": "LowStar.Monotonic.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": false, "full_module": "LowParse.Low.Int", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low.VLGen", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low.VLData", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low.Combinators", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec.Bytes", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
sz: Prims.nat{sz < 4294967296} -> i: FStar.UInt32.t{FStar.UInt32.v i < sz} -> LowParse.Low.Base.accessor (LowParse.Low.Bytes.gaccessor_flbytes_get sz i)
Prims.Tot
[ "total" ]
[]
[ "Prims.nat", "Prims.b2t", "Prims.op_LessThan", "FStar.UInt32.t", "FStar.UInt32.v", "LowParse.Slice.srel", "LowParse.Bytes.byte", "LowParse.Slice.slice", "FStar.UInt32.add", "Prims.unit", "LowParse.Low.Base.Spec.slice_access_eq", "LowParse.Spec.Base.total_constant_size_parser_kind", "FStar.Bytes.lbytes", "LowParse.Spec.Bytes.parse_flbytes", "LowParse.Spec.Int.parse_u8_kind", "FStar.UInt8.t", "LowParse.Spec.Int.parse_u8", "LowParse.Low.Bytes.clens_flbytes_get", "LowParse.Low.Bytes.gaccessor_flbytes_get", "FStar.Monotonic.HyperStack.mem", "FStar.HyperStack.ST.get", "LowParse.Low.Base.accessor" ]
[]
false
false
false
false
false
let accessor_flbytes_get (sz: nat{sz < 4294967296}) (i: U32.t{U32.v i < sz}) : Tot (accessor (gaccessor_flbytes_get sz i)) =
fun #rrel #rel input pos -> let h = HST.get () in [@@ inline_let ]let _ = slice_access_eq h (gaccessor_flbytes_get sz i) input pos in pos `U32.add` i
false
MerkleTree.New.High.Correct.Base.fst
MerkleTree.New.High.Correct.Base.mt_hashes_inv_log_converted_
val mt_hashes_inv_log_converted_: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> lv:nat{lv <= 32} -> j:nat{j > 0 && j < pow2 (32 - lv)} -> fhs:hashess #hsz {S.length fhs = 32 /\ mt_hashes_lth_inv #hsz lv j fhs} -> Lemma (requires mt_hashes_inv #_ #f lv j fhs) (ensures (log2c_bound j (32 - lv); mt_hashes_lth_inv_log_converted_ #_ #f lv j fhs; mt_hashes_inv_log #_ #f j (S.slice fhs lv (lv + log2c j)))) (decreases j)
val mt_hashes_inv_log_converted_: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> lv:nat{lv <= 32} -> j:nat{j > 0 && j < pow2 (32 - lv)} -> fhs:hashess #hsz {S.length fhs = 32 /\ mt_hashes_lth_inv #hsz lv j fhs} -> Lemma (requires mt_hashes_inv #_ #f lv j fhs) (ensures (log2c_bound j (32 - lv); mt_hashes_lth_inv_log_converted_ #_ #f lv j fhs; mt_hashes_inv_log #_ #f j (S.slice fhs lv (lv + log2c j)))) (decreases j)
let rec mt_hashes_inv_log_converted_ #_ #f lv j fhs = if j = 1 then () else (log2c_bound (j / 2) (32 - (lv + 1)); mt_hashes_lth_inv_log_converted_ #_ #f (lv + 1) (j / 2) fhs; mt_hashes_inv_log_converted_ #_ #f (lv + 1) (j / 2) fhs)
{ "file_name": "src/MerkleTree.New.High.Correct.Base.fst", "git_rev": "7d7bdc20f2033171e279c176b26e84f9069d23c6", "git_url": "https://github.com/hacl-star/merkle-tree.git", "project_name": "merkle-tree" }
{ "end_col": 64, "end_line": 390, "start_col": 0, "start_line": 386 }
module MerkleTree.New.High.Correct.Base open FStar.Classical open FStar.Ghost open FStar.Seq module S = FStar.Seq module MTS = MerkleTree.Spec open MerkleTree.New.High #set-options "--z3rlimit 40 --max_fuel 0 --max_ifuel 0" /// Sequence helpers val seq_prefix: #a:Type -> s1:S.seq a -> s2:S.seq a{S.length s1 <= S.length s2} -> GTot Type0 let seq_prefix #a s1 s2 = S.equal s1 (S.slice s2 0 (S.length s1)) val seq_head_cons: #a:Type -> x:a -> s:S.seq a -> Lemma (S.head (S.cons x s) == x) [SMTPat (S.cons x s)] let seq_head_cons #a x s = () val seq_tail_cons: #a:Type -> x:a -> s:S.seq a -> Lemma (S.equal (S.tail (S.cons x s)) s) [SMTPat (S.cons x s)] let seq_tail_cons #a x s = () /// Invariants and simulation relation of high-level Merkle tree design // Invariants of internal hashes val empty_hashes: (#hsz:pos) -> (len:nat) -> GTot (hs:hashess #hsz {S.length hs = len}) let empty_hashes #hsz len = S.create len S.empty val empty_hashes_head: #hsz:pos -> len:nat{len > 0} -> Lemma (S.head (empty_hashes #hsz len) == S.empty) let empty_hashes_head #_ _ = () val empty_hashes_tail: #hsz:pos -> len:nat{len > 0} -> Lemma (S.equal (S.tail (empty_hashes len)) (empty_hashes #hsz (len - 1))) let empty_hashes_tail #_ _ = () #push-options "--max_fuel 1" val mt_hashes_lth_inv: #hsz:pos -> lv:nat{lv <= 32} -> j:nat{j < pow2 (32 - lv)} -> fhs:hashess #hsz {S.length fhs = 32} -> GTot Type0 (decreases (32 - lv)) let rec mt_hashes_lth_inv #hsz lv j fhs = if lv = 32 then true else (S.length (S.index fhs lv) == j /\ mt_hashes_lth_inv (lv + 1) (j / 2) fhs) val mt_hashes_lth_inv_empty: #hsz:pos -> lv:nat{lv <= 32} -> Lemma (requires True) (ensures mt_hashes_lth_inv lv 0 (empty_hashes #hsz 32)) (decreases (32 - lv)) let rec mt_hashes_lth_inv_empty #hsz lv = if lv = 32 then () else mt_hashes_lth_inv_empty #hsz (lv + 1) val mt_hashes_next_rel: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> j:nat -> hs:hashes #hsz {S.length hs = j} -> nhs:hashes #hsz {S.length nhs = j / 2} -> GTot Type0 let mt_hashes_next_rel #hsz #f j hs nhs = forall (i:nat{i < j / 2}). S.index nhs i == f (S.index hs (op_Multiply 2 i)) (S.index hs (op_Multiply 2 i + 1)) #pop-options #push-options "--max_fuel 2" val mt_hashes_inv: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> lv:nat{lv < 32} -> j:nat{j < pow2 (32 - lv)} -> fhs:hashess #hsz {S.length fhs = 32 /\ mt_hashes_lth_inv lv j fhs} -> GTot Type0 (decreases (32 - lv)) let rec mt_hashes_inv #hsz #f lv j fhs = if lv = 31 then true else (mt_hashes_next_rel #_ #f j (S.index fhs lv) (S.index fhs (lv + 1)) /\ mt_hashes_inv #_ #f (lv + 1) (j / 2) fhs) val mt_hashes_inv_empty: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> lv:nat{lv < 32} -> Lemma (requires True) (ensures (mt_hashes_lth_inv_empty #hsz lv; mt_hashes_inv #hsz #f lv 0 (empty_hashes #hsz 32))) (decreases (32 - lv)) let rec mt_hashes_inv_empty #hsz #f lv = if lv = 31 then () else (mt_hashes_lth_inv_empty #hsz (lv + 1); mt_hashes_inv_empty #_ #f (lv + 1)) val mt_hashes_lth_inv_equiv: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> lv:nat{lv < 32} -> j:nat{j < pow2 (32 - lv)} -> fhs1:hashess{S.length fhs1 = 32} -> fhs2:hashess{S.length fhs2 = 32} -> Lemma (requires mt_hashes_lth_inv lv j fhs1 /\ S.equal (S.slice fhs1 lv 32) (S.slice fhs2 lv 32)) (ensures mt_hashes_lth_inv #hsz lv j fhs2) (decreases (32 - lv)) let rec mt_hashes_lth_inv_equiv #hsz #f lv j fhs1 fhs2 = if lv = 31 then () else (assert (S.index fhs1 lv == S.index fhs2 lv); mt_hashes_lth_inv_equiv #_ #f (lv + 1) (j / 2) fhs1 fhs2) #pop-options #push-options "--max_fuel 1" val mt_hashes_inv_equiv: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> lv:nat{lv < 32} -> j:nat{j < pow2 (32 - lv)} -> fhs1:hashess #hsz {S.length fhs1 = 32 /\ mt_hashes_lth_inv lv j fhs1} -> fhs2:hashess #hsz {S.length fhs2 = 32 /\ mt_hashes_lth_inv lv j fhs2} -> Lemma (requires mt_hashes_inv #_ #f lv j fhs1 /\ S.equal (S.slice fhs1 lv 32) (S.slice fhs2 lv 32)) (ensures mt_hashes_inv #_ #f lv j fhs2) (decreases (32 - lv)) let rec mt_hashes_inv_equiv #hsz #f lv j fhs1 fhs2 = if lv = 31 then () else (assert (S.index fhs1 lv == S.index fhs2 lv); assert (S.index fhs1 (lv + 1) == S.index fhs2 (lv + 1)); mt_hashes_inv_equiv #_ #f (lv + 1) (j / 2) fhs1 fhs2) val merge_hs: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> hs1:hashess #hsz -> hs2:hashess #hsz {S.length hs1 = S.length hs2} -> GTot (mhs:hashess #hsz {S.length mhs = S.length hs1}) (decreases (S.length hs1)) let rec merge_hs #hsz #f hs1 hs2 = if S.length hs1 = 0 then S.empty else (S.cons (S.append (S.head hs1) (S.head hs2)) (merge_hs #_ #f (S.tail hs1) (S.tail hs2))) val merge_hs_empty: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> len:nat -> Lemma (S.equal (merge_hs #_ #f (empty_hashes #hsz len) (empty_hashes #hsz len)) (empty_hashes #hsz len)) let rec merge_hs_empty #hsz #f len = if len = 0 then () else (empty_hashes_head #hsz len; empty_hashes_tail #hsz len; assert (S.equal (S.append #(hash #hsz) S.empty S.empty) (S.empty #(hash #hsz))); assert (S.equal (merge_hs #_ #f (empty_hashes len) (empty_hashes len)) (S.cons S.empty (merge_hs #_ #f (empty_hashes (len - 1)) (empty_hashes (len - 1))))); merge_hs_empty #_ #f (len - 1)) val merge_hs_index: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> hs1:hashess -> hs2:hashess{S.length hs1 = S.length hs2} -> i:nat{i < S.length hs1} -> Lemma (requires True) (ensures S.equal (S.index (merge_hs #_ #f hs1 hs2) i) (S.append (S.index hs1 i) (S.index hs2 i))) (decreases (S.length hs1)) [SMTPat (S.index (merge_hs #_ #f hs1 hs2) i)] let rec merge_hs_index #hsz #f hs1 hs2 i = if S.length hs1 = 0 then () else if i = 0 then () else merge_hs_index #_ #f (S.tail hs1) (S.tail hs2) (i - 1) val merge_hs_slice_equal: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> ahs1:hashess #hsz -> ahs2:hashess #hsz {S.length ahs1 = S.length ahs2} -> bhs1:hashess #hsz -> bhs2:hashess #hsz {S.length bhs1 = S.length bhs2} -> i:nat -> j:nat{i <= j && j <= S.length ahs1 && j <= S.length bhs1} -> Lemma (requires S.equal (S.slice ahs1 i j) (S.slice bhs1 i j) /\ S.equal (S.slice ahs2 i j) (S.slice bhs2 i j)) (ensures S.equal (S.slice (merge_hs #_ #f ahs1 ahs2) i j) (S.slice (merge_hs #_ #f bhs1 bhs2) i j)) (decreases (j - i)) let rec merge_hs_slice_equal #_ #f ahs1 ahs2 bhs1 bhs2 i j = if i = j then () else (assert (S.index ahs1 i == S.index bhs1 i); assert (S.index ahs2 i == S.index bhs2 i); merge_hs_slice_equal #_ #f ahs1 ahs2 bhs1 bhs2 (i + 1) j) val merge_hs_upd: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> hs1:hashess #hsz -> hs2:hashess #hsz {S.length hs1 = S.length hs2} -> i:nat{i < S.length hs1} -> v1:hashes #hsz -> v2:hashes #hsz -> Lemma (requires S.equal (S.append (S.index hs1 i) (S.index hs2 i)) (S.append v1 v2)) (ensures S.equal (merge_hs #_ #f hs1 hs2) (merge_hs #_ #f (S.upd hs1 i v1) (S.upd hs2 i v2))) (decreases i) let rec merge_hs_upd #_ #f hs1 hs2 i v1 v2 = if S.length hs1 = 0 then () else if i = 0 then () else merge_hs_upd #_ #f (S.tail hs1) (S.tail hs2) (i - 1) v1 v2 val mt_olds_inv: #hsz:pos -> lv:nat{lv <= 32} -> i:nat -> olds:hashess #hsz {S.length olds = 32} -> GTot Type0 (decreases (32 - lv)) let rec mt_olds_inv #hsz lv i olds = if lv = 32 then true else (let ofs = offset_of i in S.length (S.index olds lv) == ofs /\ mt_olds_inv #hsz (lv + 1) (i / 2) olds) val mt_olds_inv_equiv: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> lv:nat{lv <= 32} -> i:nat -> olds1:hashess #hsz {S.length olds1 = 32} -> olds2:hashess #hsz {S.length olds2 = 32} -> Lemma (requires mt_olds_inv #hsz lv i olds1 /\ S.equal (S.slice olds1 lv 32) (S.slice olds2 lv 32)) (ensures mt_olds_inv #hsz lv i olds2) (decreases (32 - lv)) let rec mt_olds_inv_equiv #hsz #f lv i olds1 olds2 = if lv = 32 then () else (assert (S.index olds1 lv == S.index olds2 lv); mt_olds_inv_equiv #_ #f (lv + 1) (i / 2) olds1 olds2) val mt_olds_hs_lth_inv_ok: #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 #hsz lv hs i j} -> Lemma (requires True) (ensures mt_hashes_lth_inv #hsz lv j (merge_hs #_ #f olds hs)) (decreases (32 - lv)) let rec mt_olds_hs_lth_inv_ok #hsz #f lv i j olds hs = if lv = 32 then () else (mt_olds_hs_lth_inv_ok #_ #f (lv + 1) (i / 2) (j / 2) olds hs) val mt_olds_hs_inv: #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 #hsz lv hs i j} -> GTot Type0 let mt_olds_hs_inv #hsz #f lv i j olds hs = mt_olds_hs_lth_inv_ok #_ #f lv i j olds hs; mt_hashes_inv #_ #f lv j (merge_hs #_ #f olds hs) // Relation between valid internal hashes (satisfying `mt_olds_hs_inv`) and // the spec. While giving such relation, all rightmost hashes are recovered. // Note that `MT?.rhs` after `construct_rhs` does NOT contain all rightmost // hashes; it has partial rightmost hashes that are enough to calculate // Merkle paths. val log2: n:nat{n > 0} -> GTot (c:nat{pow2 c <= n && n < pow2 (c+1)}) let rec log2 n = if n = 1 then 0 else 1 + log2 (n / 2) val log2_bound: n:nat{n > 0} -> c:nat{n < pow2 c} -> Lemma (log2 n <= c-1) let rec log2_bound n c = if n = 1 then () else log2_bound (n / 2) (c - 1) val log2_div: n:nat{n > 1} -> Lemma (log2 (n / 2) = log2 n - 1) let log2_div n = () val log2c: n:nat -> GTot (c:nat{c = 0 || (pow2 (c-1) <= n && n < pow2 c)}) let log2c n = if n = 0 then 0 else (log2 n + 1) val log2c_div: n:nat{n > 0} -> Lemma (log2c (n / 2) = log2c n - 1) let log2c_div n = () val log2c_bound: n:nat -> c:nat{n < pow2 c} -> Lemma (log2c n <= c) let rec log2c_bound n c = if n = 0 then () else log2c_bound (n / 2) (c - 1) val mt_hashes_lth_inv_log: #hsz:pos -> j:nat -> fhs:hashess #hsz {S.length fhs = log2c j} -> GTot Type0 (decreases j) let rec mt_hashes_lth_inv_log #hsz j fhs = if j = 0 then true else (S.length (S.head fhs) == j /\ mt_hashes_lth_inv_log #hsz (j / 2) (S.tail fhs)) #pop-options #push-options "--max_fuel 2" val mt_hashes_lth_inv_log_next: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> j:nat{j > 1} -> fhs:hashess #hsz {S.length fhs = log2c j} -> Lemma (requires mt_hashes_lth_inv_log #hsz j fhs) (ensures S.length (S.head fhs) == j /\ S.length (S.head (S.tail fhs)) == j / 2) let mt_hashes_lth_inv_log_next #_ #_ _ _ = () val mt_hashes_inv_log: #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} -> GTot Type0 (decreases j) let rec mt_hashes_inv_log #hsz #f j fhs = if j <= 1 then true else (mt_hashes_next_rel #_ #f j (S.index fhs 0) (S.index fhs 1) /\ mt_hashes_inv_log #_ #f (j / 2) (S.tail fhs)) val mt_hashes_lth_inv_log_converted_: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> lv:nat{lv <= 32} -> j:nat{j < pow2 (32 - lv)} -> fhs:hashess #hsz {S.length fhs = 32} -> Lemma (requires mt_hashes_lth_inv #hsz lv j fhs) (ensures (log2c_bound j (32 - lv); mt_hashes_lth_inv_log #hsz j (S.slice fhs lv (lv + log2c j)))) (decreases j) let rec mt_hashes_lth_inv_log_converted_ #_ #f lv j fhs = if j = 0 then () else (log2c_bound (j / 2) (32 - (lv + 1)); mt_hashes_lth_inv_log_converted_ #_ #f (lv + 1) (j / 2) fhs) val mt_hashes_lth_inv_log_converted: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> j:nat{j < pow2 32} -> fhs:hashess #hsz {S.length fhs = 32} -> Lemma (requires mt_hashes_lth_inv #hsz 0 j fhs) (ensures (log2c_bound j 32; mt_hashes_lth_inv_log #hsz j (S.slice fhs 0 (log2c j)))) let mt_hashes_lth_inv_log_converted #_ #f j fhs = mt_hashes_lth_inv_log_converted_ #_ #f 0 j fhs val mt_hashes_inv_log_converted_: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> lv:nat{lv <= 32} -> j:nat{j > 0 && j < pow2 (32 - lv)} -> fhs:hashess #hsz {S.length fhs = 32 /\ mt_hashes_lth_inv #hsz lv j fhs} -> Lemma (requires mt_hashes_inv #_ #f lv j fhs) (ensures (log2c_bound j (32 - lv); mt_hashes_lth_inv_log_converted_ #_ #f lv j fhs; mt_hashes_inv_log #_ #f j (S.slice fhs lv (lv + log2c j)))) (decreases j) #pop-options
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "MerkleTree.Spec.fst.checked", "MerkleTree.New.High.fst.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Ghost.fsti.checked", "FStar.Classical.fsti.checked" ], "interface_file": false, "source_file": "MerkleTree.New.High.Correct.Base.fst" }
[ { "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": 2, "initial_ifuel": 1, "max_fuel": 2, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 100, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
lv: Prims.nat{lv <= 32} -> j: Prims.nat{j > 0 && j < Prims.pow2 (32 - lv)} -> fhs: MerkleTree.New.High.hashess { FStar.Seq.Base.length fhs = 32 /\ MerkleTree.New.High.Correct.Base.mt_hashes_lth_inv lv j fhs } -> FStar.Pervasives.Lemma (requires MerkleTree.New.High.Correct.Base.mt_hashes_inv lv j fhs) (ensures (MerkleTree.New.High.Correct.Base.log2c_bound j (32 - lv); MerkleTree.New.High.Correct.Base.mt_hashes_lth_inv_log_converted_ lv j fhs; MerkleTree.New.High.Correct.Base.mt_hashes_inv_log j (FStar.Seq.Base.slice fhs lv (lv + MerkleTree.New.High.Correct.Base.log2c j)))) (decreases j)
FStar.Pervasives.Lemma
[ "lemma", "" ]
[]
[ "Prims.pos", "MerkleTree.Spec.hash_fun_t", "Prims.nat", "Prims.b2t", "Prims.op_LessThanOrEqual", "Prims.op_AmpAmp", "Prims.op_GreaterThan", "Prims.op_LessThan", "Prims.pow2", "Prims.op_Subtraction", "MerkleTree.New.High.hashess", "Prims.l_and", "Prims.op_Equality", "Prims.int", "FStar.Seq.Base.length", "MerkleTree.New.High.hashes", "MerkleTree.New.High.Correct.Base.mt_hashes_lth_inv", "Prims.bool", "MerkleTree.New.High.Correct.Base.mt_hashes_inv_log_converted_", "Prims.op_Addition", "Prims.op_Division", "Prims.unit", "MerkleTree.New.High.Correct.Base.mt_hashes_lth_inv_log_converted_", "MerkleTree.New.High.Correct.Base.log2c_bound" ]
[ "recursion" ]
false
false
true
false
false
let rec mt_hashes_inv_log_converted_ #_ #f lv j fhs =
if j = 1 then () else (log2c_bound (j / 2) (32 - (lv + 1)); mt_hashes_lth_inv_log_converted_ #_ #f (lv + 1) (j / 2) fhs; mt_hashes_inv_log_converted_ #_ #f (lv + 1) (j / 2) fhs)
false
LowParse.Low.Bytes.fst
LowParse.Low.Bytes.gaccessor_flbytes_slice
val gaccessor_flbytes_slice (sz: nat{sz < 4294967296}) (from: U32.t) (to: U32.t{U32.v from <= U32.v to /\ U32.v to <= sz}) : Tot (gaccessor (parse_flbytes sz) (parse_flbytes (U32.v to - U32.v from)) (clens_flbytes_slice sz from to))
val gaccessor_flbytes_slice (sz: nat{sz < 4294967296}) (from: U32.t) (to: U32.t{U32.v from <= U32.v to /\ U32.v to <= sz}) : Tot (gaccessor (parse_flbytes sz) (parse_flbytes (U32.v to - U32.v from)) (clens_flbytes_slice sz from to))
let gaccessor_flbytes_slice (sz: nat { sz < 4294967296 } ) (from: U32.t) (to: U32.t {U32.v from <= U32.v to /\ U32.v to <= sz } ) : Tot (gaccessor (parse_flbytes sz) (parse_flbytes (U32.v to - U32.v from)) (clens_flbytes_slice sz from to)) = assert (forall x . gaccessor_pre (parse_flbytes sz) (parse_flbytes (U32.v to - U32.v from)) (clens_flbytes_slice sz from to) x ==> sz <= Seq.length x); gaccessor_prop_equiv (parse_flbytes sz) (parse_flbytes (U32.v to - U32.v from)) (clens_flbytes_slice sz from to) (gaccessor_flbytes_slice' sz from to); gaccessor_flbytes_slice' sz from to
{ "file_name": "src/lowparse/LowParse.Low.Bytes.fst", "git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
{ "end_col": 37, "end_line": 101, "start_col": 0, "start_line": 94 }
module LowParse.Low.Bytes include LowParse.Spec.Bytes include LowParse.Low.Combinators include LowParse.Low.VLData include LowParse.Low.VLGen include LowParse.Low.Int module U32 = FStar.UInt32 module HS = FStar.HyperStack module B = LowStar.Monotonic.Buffer module BF = LowStar.Buffer // for local variables in store_bytes module BY = LowParse.Bytes32 module HST = FStar.HyperStack.ST module U8 = FStar.UInt8 module Cast = FStar.Int.Cast module U64 = FStar.UInt64 inline_for_extraction let validate_flbytes (sz: nat) (sz64: U64.t { U64.v sz64 == sz /\ sz < 4294967296 } ) : Tot (validator (parse_flbytes sz)) = validate_total_constant_size (parse_flbytes sz) sz64 () inline_for_extraction let jump_flbytes (sz: nat) (sz32: U32.t { U32.v sz32 == sz } ) : Tot (jumper (parse_flbytes sz)) = jump_constant_size (parse_flbytes sz) sz32 () let valid_flbytes_intro (h: HS.mem) (sz: nat { sz < 4294967296 } ) (#rrel #rel: _) (s: slice rrel rel) (pos: U32.t) : Lemma (requires (U32.v pos + sz <= U32.v s.len /\ live_slice h s)) (ensures ( valid_content_pos (parse_flbytes sz) h s pos (BY.hide (bytes_of_slice_from_to h s pos (pos `U32.add` U32.uint_to_t sz))) (pos `U32.add` U32.uint_to_t sz) )) = valid_facts (parse_flbytes sz) h s pos let valid_pos_flbytes_elim (h: HS.mem) (sz: nat { sz < 4294967296 } ) (#rrel #rel: _) (s: slice rrel rel) (pos pos' : U32.t) : Lemma (requires (valid_pos (parse_flbytes sz) h s pos pos')) (ensures (U32.v pos + sz == U32.v pos')) [SMTPat (valid_pos (parse_flbytes sz) h s pos pos')] = valid_facts (parse_flbytes sz) h s pos let valid_flbytes_elim (h: HS.mem) (sz: nat { sz < 4294967296 } ) (#rrel #rel: _) (s: slice rrel rel) (pos: U32.t) : Lemma (requires (valid (parse_flbytes sz) h s pos)) (ensures ( valid_content_pos (parse_flbytes sz) h s pos (BY.hide (bytes_of_slice_from_to h s pos (pos `U32.add` U32.uint_to_t sz))) (pos `U32.add` U32.uint_to_t sz) )) = valid_flbytes_intro h sz s pos let clens_flbytes_slice (sz: nat) (from: U32.t) (to: U32.t {U32.v from <= U32.v to /\ U32.v to <= sz } ) : Tot (clens (BY.lbytes sz) (BY.lbytes (U32.v to - U32.v from))) = { clens_cond = (fun _ -> True); clens_get = (fun (x: BY.lbytes sz) -> (BY.slice x from to <: BY.lbytes (U32.v to - U32.v from))); } #push-options "--z3rlimit 16" let gaccessor_flbytes_slice' (sz: nat { sz < 4294967296 } ) (from: U32.t) (to: U32.t {U32.v from <= U32.v to /\ U32.v to <= sz } ) : Tot (gaccessor' (parse_flbytes sz) (parse_flbytes (U32.v to - U32.v from)) (clens_flbytes_slice sz from to)) = fun (input: bytes) -> ( begin if Seq.length input < sz then (0) // dummy else (U32.v from) end)
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowStar.Monotonic.Buffer.fsti.checked", "LowStar.Buffer.fst.checked", "LowParse.Spec.Bytes.fst.checked", "LowParse.Low.VLGen.fst.checked", "LowParse.Low.VLData.fst.checked", "LowParse.Low.Int.fsti.checked", "LowParse.Low.Combinators.fsti.checked", "LowParse.Bytes32.fst.checked", "FStar.UInt8.fsti.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Int.Cast.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked", "FStar.Classical.fsti.checked", "C.Loops.fst.checked" ], "interface_file": false, "source_file": "LowParse.Low.Bytes.fst" }
[ { "abbrev": true, "full_module": "LowStar.Buffer // for local variables in store_bytes", "short_module": "BF" }, { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "FStar.Int.Cast", "short_module": "Cast" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "LowParse.Bytes32", "short_module": "BY" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "BF" }, { "abbrev": true, "full_module": "LowStar.Monotonic.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": false, "full_module": "LowParse.Low.Int", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low.VLGen", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low.VLData", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low.Combinators", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec.Bytes", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 16, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
sz: Prims.nat{sz < 4294967296} -> from: FStar.UInt32.t -> to: FStar.UInt32.t{FStar.UInt32.v from <= FStar.UInt32.v to /\ FStar.UInt32.v to <= sz} -> LowParse.Low.Base.Spec.gaccessor (LowParse.Spec.Bytes.parse_flbytes sz) (LowParse.Spec.Bytes.parse_flbytes (FStar.UInt32.v to - FStar.UInt32.v from)) (LowParse.Low.Bytes.clens_flbytes_slice sz from to)
Prims.Tot
[ "total" ]
[]
[ "Prims.nat", "Prims.b2t", "Prims.op_LessThan", "FStar.UInt32.t", "Prims.l_and", "Prims.op_LessThanOrEqual", "FStar.UInt32.v", "LowParse.Low.Bytes.gaccessor_flbytes_slice'", "Prims.unit", "LowParse.Low.Base.Spec.gaccessor_prop_equiv", "LowParse.Spec.Base.total_constant_size_parser_kind", "FStar.Bytes.lbytes", "LowParse.Spec.Bytes.parse_flbytes", "Prims.op_Subtraction", "LowParse.Low.Bytes.clens_flbytes_slice", "Prims._assert", "Prims.l_Forall", "FStar.Seq.Base.seq", "LowParse.Bytes.byte", "Prims.l_imp", "LowParse.Low.Base.Spec.gaccessor_pre", "FStar.Seq.Base.length", "LowParse.Low.Base.Spec.gaccessor" ]
[]
false
false
false
false
false
let gaccessor_flbytes_slice (sz: nat{sz < 4294967296}) (from: U32.t) (to: U32.t{U32.v from <= U32.v to /\ U32.v to <= sz}) : Tot (gaccessor (parse_flbytes sz) (parse_flbytes (U32.v to - U32.v from)) (clens_flbytes_slice sz from to)) =
assert (forall x. gaccessor_pre (parse_flbytes sz) (parse_flbytes (U32.v to - U32.v from)) (clens_flbytes_slice sz from to) x ==> sz <= Seq.length x); gaccessor_prop_equiv (parse_flbytes sz) (parse_flbytes (U32.v to - U32.v from)) (clens_flbytes_slice sz from to) (gaccessor_flbytes_slice' sz from to); gaccessor_flbytes_slice' sz from to
false
LowParse.Low.Bytes.fst
LowParse.Low.Bytes.write_flbytes_weak
val write_flbytes_weak (sz32: U32.t{U32.v sz32 < 4294967295}) : Tot (leaf_writer_weak (serialize_flbytes (U32.v sz32)))
val write_flbytes_weak (sz32: U32.t{U32.v sz32 < 4294967295}) : Tot (leaf_writer_weak (serialize_flbytes (U32.v sz32)))
let write_flbytes_weak (sz32: U32.t { U32.v sz32 < 4294967295 } ) // need to return that value if output buffer is too small : Tot (leaf_writer_weak (serialize_flbytes (U32.v sz32))) = leaf_writer_weak_of_strong_constant_size (write_flbytes sz32) sz32 ()
{ "file_name": "src/lowparse/LowParse.Low.Bytes.fst", "git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
{ "end_col": 71, "end_line": 245, "start_col": 0, "start_line": 242 }
module LowParse.Low.Bytes include LowParse.Spec.Bytes include LowParse.Low.Combinators include LowParse.Low.VLData include LowParse.Low.VLGen include LowParse.Low.Int module U32 = FStar.UInt32 module HS = FStar.HyperStack module B = LowStar.Monotonic.Buffer module BF = LowStar.Buffer // for local variables in store_bytes module BY = LowParse.Bytes32 module HST = FStar.HyperStack.ST module U8 = FStar.UInt8 module Cast = FStar.Int.Cast module U64 = FStar.UInt64 inline_for_extraction let validate_flbytes (sz: nat) (sz64: U64.t { U64.v sz64 == sz /\ sz < 4294967296 } ) : Tot (validator (parse_flbytes sz)) = validate_total_constant_size (parse_flbytes sz) sz64 () inline_for_extraction let jump_flbytes (sz: nat) (sz32: U32.t { U32.v sz32 == sz } ) : Tot (jumper (parse_flbytes sz)) = jump_constant_size (parse_flbytes sz) sz32 () let valid_flbytes_intro (h: HS.mem) (sz: nat { sz < 4294967296 } ) (#rrel #rel: _) (s: slice rrel rel) (pos: U32.t) : Lemma (requires (U32.v pos + sz <= U32.v s.len /\ live_slice h s)) (ensures ( valid_content_pos (parse_flbytes sz) h s pos (BY.hide (bytes_of_slice_from_to h s pos (pos `U32.add` U32.uint_to_t sz))) (pos `U32.add` U32.uint_to_t sz) )) = valid_facts (parse_flbytes sz) h s pos let valid_pos_flbytes_elim (h: HS.mem) (sz: nat { sz < 4294967296 } ) (#rrel #rel: _) (s: slice rrel rel) (pos pos' : U32.t) : Lemma (requires (valid_pos (parse_flbytes sz) h s pos pos')) (ensures (U32.v pos + sz == U32.v pos')) [SMTPat (valid_pos (parse_flbytes sz) h s pos pos')] = valid_facts (parse_flbytes sz) h s pos let valid_flbytes_elim (h: HS.mem) (sz: nat { sz < 4294967296 } ) (#rrel #rel: _) (s: slice rrel rel) (pos: U32.t) : Lemma (requires (valid (parse_flbytes sz) h s pos)) (ensures ( valid_content_pos (parse_flbytes sz) h s pos (BY.hide (bytes_of_slice_from_to h s pos (pos `U32.add` U32.uint_to_t sz))) (pos `U32.add` U32.uint_to_t sz) )) = valid_flbytes_intro h sz s pos let clens_flbytes_slice (sz: nat) (from: U32.t) (to: U32.t {U32.v from <= U32.v to /\ U32.v to <= sz } ) : Tot (clens (BY.lbytes sz) (BY.lbytes (U32.v to - U32.v from))) = { clens_cond = (fun _ -> True); clens_get = (fun (x: BY.lbytes sz) -> (BY.slice x from to <: BY.lbytes (U32.v to - U32.v from))); } #push-options "--z3rlimit 16" let gaccessor_flbytes_slice' (sz: nat { sz < 4294967296 } ) (from: U32.t) (to: U32.t {U32.v from <= U32.v to /\ U32.v to <= sz } ) : Tot (gaccessor' (parse_flbytes sz) (parse_flbytes (U32.v to - U32.v from)) (clens_flbytes_slice sz from to)) = fun (input: bytes) -> ( begin if Seq.length input < sz then (0) // dummy else (U32.v from) end) let gaccessor_flbytes_slice (sz: nat { sz < 4294967296 } ) (from: U32.t) (to: U32.t {U32.v from <= U32.v to /\ U32.v to <= sz } ) : Tot (gaccessor (parse_flbytes sz) (parse_flbytes (U32.v to - U32.v from)) (clens_flbytes_slice sz from to)) = assert (forall x . gaccessor_pre (parse_flbytes sz) (parse_flbytes (U32.v to - U32.v from)) (clens_flbytes_slice sz from to) x ==> sz <= Seq.length x); gaccessor_prop_equiv (parse_flbytes sz) (parse_flbytes (U32.v to - U32.v from)) (clens_flbytes_slice sz from to) (gaccessor_flbytes_slice' sz from to); gaccessor_flbytes_slice' sz from to inline_for_extraction let accessor_flbytes_slice (sz: nat { sz < 4294967296 } ) (from: U32.t) (to: U32.t {U32.v from <= U32.v to /\ U32.v to <= sz } ) : Tot (accessor (gaccessor_flbytes_slice sz from to)) = fun #rrel #rel input pos -> let h = HST.get () in [@inline_let] let _ = slice_access_eq h (gaccessor_flbytes_slice sz from to) input pos in pos `U32.add` from #pop-options let clens_flbytes_get (sz: nat) (i: U32.t { U32.v i < sz } ) : Tot (clens (BY.lbytes sz) byte) = { clens_cond = (fun _ -> True); clens_get = (fun (x: BY.lbytes sz) -> (BY.get x i <: byte)); } #push-options "--z3rlimit 16 --max_fuel 1" let gaccessor_flbytes_get' (sz: nat { sz < 4294967296 } ) (i: U32.t { U32.v i < sz } ) : Tot (gaccessor' (parse_flbytes sz) (parse_u8) (clens_flbytes_get sz i)) = fun (input: bytes) -> ( begin let res = if Seq.length input < U32.v i then (0) // dummy else (U32.v i) in let g () : Lemma (requires (gaccessor_pre (parse_flbytes sz) parse_u8 (clens_flbytes_get sz i) input)) (ensures (gaccessor_post (parse_flbytes sz) parse_u8 (clens_flbytes_get sz i) input res)) = parser_kind_prop_equiv (get_parser_kind parse_u8) parse_u8; assert (res == (U32.v i)); parse_u8_spec' (Seq.slice input (U32.v i) (U32.v i + 1)); parse_strong_prefix parse_u8 (Seq.slice input (U32.v i) (U32.v i + 1)) (Seq.slice input (U32.v i) (Seq.length input)) in Classical.move_requires g (); res end) #pop-options let gaccessor_flbytes_get (sz: nat { sz < 4294967296 } ) (i: U32.t { U32.v i < sz } ) : Tot (gaccessor (parse_flbytes sz) (parse_u8) (clens_flbytes_get sz i)) = assert (forall x . gaccessor_pre (parse_flbytes sz) (parse_u8) (clens_flbytes_get sz i) x ==> U32.v i <= Seq.length x); gaccessor_prop_equiv (parse_flbytes sz) (parse_u8) (clens_flbytes_get sz i) (gaccessor_flbytes_get' sz i); gaccessor_flbytes_get' sz i inline_for_extraction let accessor_flbytes_get (sz: nat { sz < 4294967296 } ) (i: U32.t { U32.v i < sz } ) : Tot (accessor (gaccessor_flbytes_get sz i)) = fun #rrel #rel input pos -> let h = HST.get () in [@inline_let] let _ = slice_access_eq h (gaccessor_flbytes_get sz i) input pos in pos `U32.add` i (* Temporary: flbytes as leaf values *) (* TODO: convert store_bytes to monotonic buffers, using the "writable" predicate *) #push-options "--z3rlimit 32" inline_for_extraction let store_bytes (src: BY.bytes) (src_from src_to: U32.t) (#rrel #rel: _) (dst: B.mbuffer byte rrel rel) (dst_pos: U32.t) : HST.Stack unit (requires (fun h -> B.live h dst /\ U32.v src_from <= U32.v src_to /\ U32.v src_to <= BY.length src /\ U32.v dst_pos + (U32.v src_to - U32.v src_from) <= B.length dst /\ writable dst (U32.v dst_pos) (U32.v dst_pos + (U32.v src_to - U32.v src_from)) h )) (ensures (fun h _ h' -> B.modifies (B.loc_buffer_from_to dst dst_pos (dst_pos `U32.add` (src_to `U32.sub` src_from))) h h' /\ Seq.slice (B.as_seq h' dst) (U32.v dst_pos) (U32.v dst_pos + (U32.v src_to - U32.v src_from)) == Seq.slice (BY.reveal src) (U32.v src_from) (U32.v src_to) )) = let h0 = HST.get () in HST.push_frame (); let h1 = HST.get () in let bi = BF.alloca 0ul 1ul in let h2 = HST.get () in let len = src_to `U32.sub` src_from in C.Loops.do_while (fun h stop -> B.modifies (B.loc_union (B.loc_region_only true (HS.get_tip h1)) (B.loc_buffer_from_to dst dst_pos (dst_pos `U32.add` len))) h2 h /\ B.live h bi /\ ( let i = Seq.index (B.as_seq h bi) 0 in U32.v i <= U32.v len /\ writable dst (U32.v dst_pos) (U32.v dst_pos + U32.v len) h /\ Seq.slice (B.as_seq h dst) (U32.v dst_pos) (U32.v dst_pos + U32.v i) `Seq.equal` Seq.slice (BY.reveal src) (U32.v src_from) (U32.v src_from + U32.v i) /\ (stop == true ==> i == len) )) (fun _ -> let i = B.index bi 0ul in if i = len then true else begin let x = BY.get src (src_from `U32.add` i) in mbuffer_upd dst (Ghost.hide (U32.v dst_pos)) (Ghost.hide (U32.v dst_pos + U32.v len)) (dst_pos `U32.add` i) x; let i' = i `U32.add` 1ul in B.upd bi 0ul i'; let h' = HST.get () in Seq.lemma_split (Seq.slice (B.as_seq h' dst) (U32.v dst_pos) (U32.v dst_pos + U32.v i')) (U32.v i); i' = len end ) ; HST.pop_frame () #pop-options inline_for_extraction let serialize32_flbytes (sz32: U32.t) : Tot (serializer32 (serialize_flbytes (U32.v sz32))) = fun (x: BY.lbytes (U32.v sz32)) #rrel #rel b pos -> let _ = store_bytes x 0ul sz32 b pos in sz32 inline_for_extraction let write_flbytes (sz32: U32.t) : Tot (leaf_writer_strong (serialize_flbytes (U32.v sz32))) = leaf_writer_strong_of_serializer32 (serialize32_flbytes sz32) ()
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowStar.Monotonic.Buffer.fsti.checked", "LowStar.Buffer.fst.checked", "LowParse.Spec.Bytes.fst.checked", "LowParse.Low.VLGen.fst.checked", "LowParse.Low.VLData.fst.checked", "LowParse.Low.Int.fsti.checked", "LowParse.Low.Combinators.fsti.checked", "LowParse.Bytes32.fst.checked", "FStar.UInt8.fsti.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Int.Cast.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked", "FStar.Classical.fsti.checked", "C.Loops.fst.checked" ], "interface_file": false, "source_file": "LowParse.Low.Bytes.fst" }
[ { "abbrev": true, "full_module": "LowStar.Buffer // for local variables in store_bytes", "short_module": "BF" }, { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "FStar.Int.Cast", "short_module": "Cast" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "LowParse.Bytes32", "short_module": "BY" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "BF" }, { "abbrev": true, "full_module": "LowStar.Monotonic.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": false, "full_module": "LowParse.Low.Int", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low.VLGen", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low.VLData", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low.Combinators", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec.Bytes", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
sz32: FStar.UInt32.t{FStar.UInt32.v sz32 < 4294967295} -> LowParse.Low.Base.leaf_writer_weak (LowParse.Spec.Bytes.serialize_flbytes (FStar.UInt32.v sz32) )
Prims.Tot
[ "total" ]
[]
[ "FStar.UInt32.t", "Prims.b2t", "Prims.op_LessThan", "FStar.UInt32.v", "LowParse.Low.Base.leaf_writer_weak_of_strong_constant_size", "LowParse.Spec.Base.total_constant_size_parser_kind", "FStar.Bytes.lbytes", "LowParse.Spec.Bytes.parse_flbytes", "LowParse.Spec.Bytes.serialize_flbytes", "LowParse.Low.Bytes.write_flbytes", "LowParse.Low.Base.leaf_writer_weak" ]
[]
false
false
false
false
false
let write_flbytes_weak (sz32: U32.t{U32.v sz32 < 4294967295}) : Tot (leaf_writer_weak (serialize_flbytes (U32.v sz32))) =
leaf_writer_weak_of_strong_constant_size (write_flbytes sz32) sz32 ()
false
LowParse.Low.Bytes.fst
LowParse.Low.Bytes.write_flbytes
val write_flbytes (sz32: U32.t) : Tot (leaf_writer_strong (serialize_flbytes (U32.v sz32)))
val write_flbytes (sz32: U32.t) : Tot (leaf_writer_strong (serialize_flbytes (U32.v sz32)))
let write_flbytes (sz32: U32.t) : Tot (leaf_writer_strong (serialize_flbytes (U32.v sz32))) = leaf_writer_strong_of_serializer32 (serialize32_flbytes sz32) ()
{ "file_name": "src/lowparse/LowParse.Low.Bytes.fst", "git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
{ "end_col": 66, "end_line": 239, "start_col": 0, "start_line": 236 }
module LowParse.Low.Bytes include LowParse.Spec.Bytes include LowParse.Low.Combinators include LowParse.Low.VLData include LowParse.Low.VLGen include LowParse.Low.Int module U32 = FStar.UInt32 module HS = FStar.HyperStack module B = LowStar.Monotonic.Buffer module BF = LowStar.Buffer // for local variables in store_bytes module BY = LowParse.Bytes32 module HST = FStar.HyperStack.ST module U8 = FStar.UInt8 module Cast = FStar.Int.Cast module U64 = FStar.UInt64 inline_for_extraction let validate_flbytes (sz: nat) (sz64: U64.t { U64.v sz64 == sz /\ sz < 4294967296 } ) : Tot (validator (parse_flbytes sz)) = validate_total_constant_size (parse_flbytes sz) sz64 () inline_for_extraction let jump_flbytes (sz: nat) (sz32: U32.t { U32.v sz32 == sz } ) : Tot (jumper (parse_flbytes sz)) = jump_constant_size (parse_flbytes sz) sz32 () let valid_flbytes_intro (h: HS.mem) (sz: nat { sz < 4294967296 } ) (#rrel #rel: _) (s: slice rrel rel) (pos: U32.t) : Lemma (requires (U32.v pos + sz <= U32.v s.len /\ live_slice h s)) (ensures ( valid_content_pos (parse_flbytes sz) h s pos (BY.hide (bytes_of_slice_from_to h s pos (pos `U32.add` U32.uint_to_t sz))) (pos `U32.add` U32.uint_to_t sz) )) = valid_facts (parse_flbytes sz) h s pos let valid_pos_flbytes_elim (h: HS.mem) (sz: nat { sz < 4294967296 } ) (#rrel #rel: _) (s: slice rrel rel) (pos pos' : U32.t) : Lemma (requires (valid_pos (parse_flbytes sz) h s pos pos')) (ensures (U32.v pos + sz == U32.v pos')) [SMTPat (valid_pos (parse_flbytes sz) h s pos pos')] = valid_facts (parse_flbytes sz) h s pos let valid_flbytes_elim (h: HS.mem) (sz: nat { sz < 4294967296 } ) (#rrel #rel: _) (s: slice rrel rel) (pos: U32.t) : Lemma (requires (valid (parse_flbytes sz) h s pos)) (ensures ( valid_content_pos (parse_flbytes sz) h s pos (BY.hide (bytes_of_slice_from_to h s pos (pos `U32.add` U32.uint_to_t sz))) (pos `U32.add` U32.uint_to_t sz) )) = valid_flbytes_intro h sz s pos let clens_flbytes_slice (sz: nat) (from: U32.t) (to: U32.t {U32.v from <= U32.v to /\ U32.v to <= sz } ) : Tot (clens (BY.lbytes sz) (BY.lbytes (U32.v to - U32.v from))) = { clens_cond = (fun _ -> True); clens_get = (fun (x: BY.lbytes sz) -> (BY.slice x from to <: BY.lbytes (U32.v to - U32.v from))); } #push-options "--z3rlimit 16" let gaccessor_flbytes_slice' (sz: nat { sz < 4294967296 } ) (from: U32.t) (to: U32.t {U32.v from <= U32.v to /\ U32.v to <= sz } ) : Tot (gaccessor' (parse_flbytes sz) (parse_flbytes (U32.v to - U32.v from)) (clens_flbytes_slice sz from to)) = fun (input: bytes) -> ( begin if Seq.length input < sz then (0) // dummy else (U32.v from) end) let gaccessor_flbytes_slice (sz: nat { sz < 4294967296 } ) (from: U32.t) (to: U32.t {U32.v from <= U32.v to /\ U32.v to <= sz } ) : Tot (gaccessor (parse_flbytes sz) (parse_flbytes (U32.v to - U32.v from)) (clens_flbytes_slice sz from to)) = assert (forall x . gaccessor_pre (parse_flbytes sz) (parse_flbytes (U32.v to - U32.v from)) (clens_flbytes_slice sz from to) x ==> sz <= Seq.length x); gaccessor_prop_equiv (parse_flbytes sz) (parse_flbytes (U32.v to - U32.v from)) (clens_flbytes_slice sz from to) (gaccessor_flbytes_slice' sz from to); gaccessor_flbytes_slice' sz from to inline_for_extraction let accessor_flbytes_slice (sz: nat { sz < 4294967296 } ) (from: U32.t) (to: U32.t {U32.v from <= U32.v to /\ U32.v to <= sz } ) : Tot (accessor (gaccessor_flbytes_slice sz from to)) = fun #rrel #rel input pos -> let h = HST.get () in [@inline_let] let _ = slice_access_eq h (gaccessor_flbytes_slice sz from to) input pos in pos `U32.add` from #pop-options let clens_flbytes_get (sz: nat) (i: U32.t { U32.v i < sz } ) : Tot (clens (BY.lbytes sz) byte) = { clens_cond = (fun _ -> True); clens_get = (fun (x: BY.lbytes sz) -> (BY.get x i <: byte)); } #push-options "--z3rlimit 16 --max_fuel 1" let gaccessor_flbytes_get' (sz: nat { sz < 4294967296 } ) (i: U32.t { U32.v i < sz } ) : Tot (gaccessor' (parse_flbytes sz) (parse_u8) (clens_flbytes_get sz i)) = fun (input: bytes) -> ( begin let res = if Seq.length input < U32.v i then (0) // dummy else (U32.v i) in let g () : Lemma (requires (gaccessor_pre (parse_flbytes sz) parse_u8 (clens_flbytes_get sz i) input)) (ensures (gaccessor_post (parse_flbytes sz) parse_u8 (clens_flbytes_get sz i) input res)) = parser_kind_prop_equiv (get_parser_kind parse_u8) parse_u8; assert (res == (U32.v i)); parse_u8_spec' (Seq.slice input (U32.v i) (U32.v i + 1)); parse_strong_prefix parse_u8 (Seq.slice input (U32.v i) (U32.v i + 1)) (Seq.slice input (U32.v i) (Seq.length input)) in Classical.move_requires g (); res end) #pop-options let gaccessor_flbytes_get (sz: nat { sz < 4294967296 } ) (i: U32.t { U32.v i < sz } ) : Tot (gaccessor (parse_flbytes sz) (parse_u8) (clens_flbytes_get sz i)) = assert (forall x . gaccessor_pre (parse_flbytes sz) (parse_u8) (clens_flbytes_get sz i) x ==> U32.v i <= Seq.length x); gaccessor_prop_equiv (parse_flbytes sz) (parse_u8) (clens_flbytes_get sz i) (gaccessor_flbytes_get' sz i); gaccessor_flbytes_get' sz i inline_for_extraction let accessor_flbytes_get (sz: nat { sz < 4294967296 } ) (i: U32.t { U32.v i < sz } ) : Tot (accessor (gaccessor_flbytes_get sz i)) = fun #rrel #rel input pos -> let h = HST.get () in [@inline_let] let _ = slice_access_eq h (gaccessor_flbytes_get sz i) input pos in pos `U32.add` i (* Temporary: flbytes as leaf values *) (* TODO: convert store_bytes to monotonic buffers, using the "writable" predicate *) #push-options "--z3rlimit 32" inline_for_extraction let store_bytes (src: BY.bytes) (src_from src_to: U32.t) (#rrel #rel: _) (dst: B.mbuffer byte rrel rel) (dst_pos: U32.t) : HST.Stack unit (requires (fun h -> B.live h dst /\ U32.v src_from <= U32.v src_to /\ U32.v src_to <= BY.length src /\ U32.v dst_pos + (U32.v src_to - U32.v src_from) <= B.length dst /\ writable dst (U32.v dst_pos) (U32.v dst_pos + (U32.v src_to - U32.v src_from)) h )) (ensures (fun h _ h' -> B.modifies (B.loc_buffer_from_to dst dst_pos (dst_pos `U32.add` (src_to `U32.sub` src_from))) h h' /\ Seq.slice (B.as_seq h' dst) (U32.v dst_pos) (U32.v dst_pos + (U32.v src_to - U32.v src_from)) == Seq.slice (BY.reveal src) (U32.v src_from) (U32.v src_to) )) = let h0 = HST.get () in HST.push_frame (); let h1 = HST.get () in let bi = BF.alloca 0ul 1ul in let h2 = HST.get () in let len = src_to `U32.sub` src_from in C.Loops.do_while (fun h stop -> B.modifies (B.loc_union (B.loc_region_only true (HS.get_tip h1)) (B.loc_buffer_from_to dst dst_pos (dst_pos `U32.add` len))) h2 h /\ B.live h bi /\ ( let i = Seq.index (B.as_seq h bi) 0 in U32.v i <= U32.v len /\ writable dst (U32.v dst_pos) (U32.v dst_pos + U32.v len) h /\ Seq.slice (B.as_seq h dst) (U32.v dst_pos) (U32.v dst_pos + U32.v i) `Seq.equal` Seq.slice (BY.reveal src) (U32.v src_from) (U32.v src_from + U32.v i) /\ (stop == true ==> i == len) )) (fun _ -> let i = B.index bi 0ul in if i = len then true else begin let x = BY.get src (src_from `U32.add` i) in mbuffer_upd dst (Ghost.hide (U32.v dst_pos)) (Ghost.hide (U32.v dst_pos + U32.v len)) (dst_pos `U32.add` i) x; let i' = i `U32.add` 1ul in B.upd bi 0ul i'; let h' = HST.get () in Seq.lemma_split (Seq.slice (B.as_seq h' dst) (U32.v dst_pos) (U32.v dst_pos + U32.v i')) (U32.v i); i' = len end ) ; HST.pop_frame () #pop-options inline_for_extraction let serialize32_flbytes (sz32: U32.t) : Tot (serializer32 (serialize_flbytes (U32.v sz32))) = fun (x: BY.lbytes (U32.v sz32)) #rrel #rel b pos -> let _ = store_bytes x 0ul sz32 b pos in sz32
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowStar.Monotonic.Buffer.fsti.checked", "LowStar.Buffer.fst.checked", "LowParse.Spec.Bytes.fst.checked", "LowParse.Low.VLGen.fst.checked", "LowParse.Low.VLData.fst.checked", "LowParse.Low.Int.fsti.checked", "LowParse.Low.Combinators.fsti.checked", "LowParse.Bytes32.fst.checked", "FStar.UInt8.fsti.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Int.Cast.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked", "FStar.Classical.fsti.checked", "C.Loops.fst.checked" ], "interface_file": false, "source_file": "LowParse.Low.Bytes.fst" }
[ { "abbrev": true, "full_module": "LowStar.Buffer // for local variables in store_bytes", "short_module": "BF" }, { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "FStar.Int.Cast", "short_module": "Cast" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "LowParse.Bytes32", "short_module": "BY" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "BF" }, { "abbrev": true, "full_module": "LowStar.Monotonic.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": false, "full_module": "LowParse.Low.Int", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low.VLGen", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low.VLData", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low.Combinators", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec.Bytes", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
sz32: FStar.UInt32.t -> LowParse.Low.Base.leaf_writer_strong (LowParse.Spec.Bytes.serialize_flbytes (FStar.UInt32.v sz32 ))
Prims.Tot
[ "total" ]
[]
[ "FStar.UInt32.t", "LowParse.Low.Base.leaf_writer_strong_of_serializer32", "LowParse.Spec.Base.total_constant_size_parser_kind", "FStar.UInt32.v", "FStar.Bytes.lbytes", "LowParse.Spec.Bytes.parse_flbytes", "LowParse.Spec.Bytes.serialize_flbytes", "LowParse.Low.Bytes.serialize32_flbytes", "LowParse.Low.Base.leaf_writer_strong" ]
[]
false
false
false
false
false
let write_flbytes (sz32: U32.t) : Tot (leaf_writer_strong (serialize_flbytes (U32.v sz32))) =
leaf_writer_strong_of_serializer32 (serialize32_flbytes sz32) ()
false
LowParse.Low.Bytes.fst
LowParse.Low.Bytes.serialize32_flbytes
val serialize32_flbytes (sz32: U32.t) : Tot (serializer32 (serialize_flbytes (U32.v sz32)))
val serialize32_flbytes (sz32: U32.t) : Tot (serializer32 (serialize_flbytes (U32.v sz32)))
let serialize32_flbytes (sz32: U32.t) : Tot (serializer32 (serialize_flbytes (U32.v sz32))) = fun (x: BY.lbytes (U32.v sz32)) #rrel #rel b pos -> let _ = store_bytes x 0ul sz32 b pos in sz32
{ "file_name": "src/lowparse/LowParse.Low.Bytes.fst", "git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
{ "end_col": 6, "end_line": 233, "start_col": 0, "start_line": 228 }
module LowParse.Low.Bytes include LowParse.Spec.Bytes include LowParse.Low.Combinators include LowParse.Low.VLData include LowParse.Low.VLGen include LowParse.Low.Int module U32 = FStar.UInt32 module HS = FStar.HyperStack module B = LowStar.Monotonic.Buffer module BF = LowStar.Buffer // for local variables in store_bytes module BY = LowParse.Bytes32 module HST = FStar.HyperStack.ST module U8 = FStar.UInt8 module Cast = FStar.Int.Cast module U64 = FStar.UInt64 inline_for_extraction let validate_flbytes (sz: nat) (sz64: U64.t { U64.v sz64 == sz /\ sz < 4294967296 } ) : Tot (validator (parse_flbytes sz)) = validate_total_constant_size (parse_flbytes sz) sz64 () inline_for_extraction let jump_flbytes (sz: nat) (sz32: U32.t { U32.v sz32 == sz } ) : Tot (jumper (parse_flbytes sz)) = jump_constant_size (parse_flbytes sz) sz32 () let valid_flbytes_intro (h: HS.mem) (sz: nat { sz < 4294967296 } ) (#rrel #rel: _) (s: slice rrel rel) (pos: U32.t) : Lemma (requires (U32.v pos + sz <= U32.v s.len /\ live_slice h s)) (ensures ( valid_content_pos (parse_flbytes sz) h s pos (BY.hide (bytes_of_slice_from_to h s pos (pos `U32.add` U32.uint_to_t sz))) (pos `U32.add` U32.uint_to_t sz) )) = valid_facts (parse_flbytes sz) h s pos let valid_pos_flbytes_elim (h: HS.mem) (sz: nat { sz < 4294967296 } ) (#rrel #rel: _) (s: slice rrel rel) (pos pos' : U32.t) : Lemma (requires (valid_pos (parse_flbytes sz) h s pos pos')) (ensures (U32.v pos + sz == U32.v pos')) [SMTPat (valid_pos (parse_flbytes sz) h s pos pos')] = valid_facts (parse_flbytes sz) h s pos let valid_flbytes_elim (h: HS.mem) (sz: nat { sz < 4294967296 } ) (#rrel #rel: _) (s: slice rrel rel) (pos: U32.t) : Lemma (requires (valid (parse_flbytes sz) h s pos)) (ensures ( valid_content_pos (parse_flbytes sz) h s pos (BY.hide (bytes_of_slice_from_to h s pos (pos `U32.add` U32.uint_to_t sz))) (pos `U32.add` U32.uint_to_t sz) )) = valid_flbytes_intro h sz s pos let clens_flbytes_slice (sz: nat) (from: U32.t) (to: U32.t {U32.v from <= U32.v to /\ U32.v to <= sz } ) : Tot (clens (BY.lbytes sz) (BY.lbytes (U32.v to - U32.v from))) = { clens_cond = (fun _ -> True); clens_get = (fun (x: BY.lbytes sz) -> (BY.slice x from to <: BY.lbytes (U32.v to - U32.v from))); } #push-options "--z3rlimit 16" let gaccessor_flbytes_slice' (sz: nat { sz < 4294967296 } ) (from: U32.t) (to: U32.t {U32.v from <= U32.v to /\ U32.v to <= sz } ) : Tot (gaccessor' (parse_flbytes sz) (parse_flbytes (U32.v to - U32.v from)) (clens_flbytes_slice sz from to)) = fun (input: bytes) -> ( begin if Seq.length input < sz then (0) // dummy else (U32.v from) end) let gaccessor_flbytes_slice (sz: nat { sz < 4294967296 } ) (from: U32.t) (to: U32.t {U32.v from <= U32.v to /\ U32.v to <= sz } ) : Tot (gaccessor (parse_flbytes sz) (parse_flbytes (U32.v to - U32.v from)) (clens_flbytes_slice sz from to)) = assert (forall x . gaccessor_pre (parse_flbytes sz) (parse_flbytes (U32.v to - U32.v from)) (clens_flbytes_slice sz from to) x ==> sz <= Seq.length x); gaccessor_prop_equiv (parse_flbytes sz) (parse_flbytes (U32.v to - U32.v from)) (clens_flbytes_slice sz from to) (gaccessor_flbytes_slice' sz from to); gaccessor_flbytes_slice' sz from to inline_for_extraction let accessor_flbytes_slice (sz: nat { sz < 4294967296 } ) (from: U32.t) (to: U32.t {U32.v from <= U32.v to /\ U32.v to <= sz } ) : Tot (accessor (gaccessor_flbytes_slice sz from to)) = fun #rrel #rel input pos -> let h = HST.get () in [@inline_let] let _ = slice_access_eq h (gaccessor_flbytes_slice sz from to) input pos in pos `U32.add` from #pop-options let clens_flbytes_get (sz: nat) (i: U32.t { U32.v i < sz } ) : Tot (clens (BY.lbytes sz) byte) = { clens_cond = (fun _ -> True); clens_get = (fun (x: BY.lbytes sz) -> (BY.get x i <: byte)); } #push-options "--z3rlimit 16 --max_fuel 1" let gaccessor_flbytes_get' (sz: nat { sz < 4294967296 } ) (i: U32.t { U32.v i < sz } ) : Tot (gaccessor' (parse_flbytes sz) (parse_u8) (clens_flbytes_get sz i)) = fun (input: bytes) -> ( begin let res = if Seq.length input < U32.v i then (0) // dummy else (U32.v i) in let g () : Lemma (requires (gaccessor_pre (parse_flbytes sz) parse_u8 (clens_flbytes_get sz i) input)) (ensures (gaccessor_post (parse_flbytes sz) parse_u8 (clens_flbytes_get sz i) input res)) = parser_kind_prop_equiv (get_parser_kind parse_u8) parse_u8; assert (res == (U32.v i)); parse_u8_spec' (Seq.slice input (U32.v i) (U32.v i + 1)); parse_strong_prefix parse_u8 (Seq.slice input (U32.v i) (U32.v i + 1)) (Seq.slice input (U32.v i) (Seq.length input)) in Classical.move_requires g (); res end) #pop-options let gaccessor_flbytes_get (sz: nat { sz < 4294967296 } ) (i: U32.t { U32.v i < sz } ) : Tot (gaccessor (parse_flbytes sz) (parse_u8) (clens_flbytes_get sz i)) = assert (forall x . gaccessor_pre (parse_flbytes sz) (parse_u8) (clens_flbytes_get sz i) x ==> U32.v i <= Seq.length x); gaccessor_prop_equiv (parse_flbytes sz) (parse_u8) (clens_flbytes_get sz i) (gaccessor_flbytes_get' sz i); gaccessor_flbytes_get' sz i inline_for_extraction let accessor_flbytes_get (sz: nat { sz < 4294967296 } ) (i: U32.t { U32.v i < sz } ) : Tot (accessor (gaccessor_flbytes_get sz i)) = fun #rrel #rel input pos -> let h = HST.get () in [@inline_let] let _ = slice_access_eq h (gaccessor_flbytes_get sz i) input pos in pos `U32.add` i (* Temporary: flbytes as leaf values *) (* TODO: convert store_bytes to monotonic buffers, using the "writable" predicate *) #push-options "--z3rlimit 32" inline_for_extraction let store_bytes (src: BY.bytes) (src_from src_to: U32.t) (#rrel #rel: _) (dst: B.mbuffer byte rrel rel) (dst_pos: U32.t) : HST.Stack unit (requires (fun h -> B.live h dst /\ U32.v src_from <= U32.v src_to /\ U32.v src_to <= BY.length src /\ U32.v dst_pos + (U32.v src_to - U32.v src_from) <= B.length dst /\ writable dst (U32.v dst_pos) (U32.v dst_pos + (U32.v src_to - U32.v src_from)) h )) (ensures (fun h _ h' -> B.modifies (B.loc_buffer_from_to dst dst_pos (dst_pos `U32.add` (src_to `U32.sub` src_from))) h h' /\ Seq.slice (B.as_seq h' dst) (U32.v dst_pos) (U32.v dst_pos + (U32.v src_to - U32.v src_from)) == Seq.slice (BY.reveal src) (U32.v src_from) (U32.v src_to) )) = let h0 = HST.get () in HST.push_frame (); let h1 = HST.get () in let bi = BF.alloca 0ul 1ul in let h2 = HST.get () in let len = src_to `U32.sub` src_from in C.Loops.do_while (fun h stop -> B.modifies (B.loc_union (B.loc_region_only true (HS.get_tip h1)) (B.loc_buffer_from_to dst dst_pos (dst_pos `U32.add` len))) h2 h /\ B.live h bi /\ ( let i = Seq.index (B.as_seq h bi) 0 in U32.v i <= U32.v len /\ writable dst (U32.v dst_pos) (U32.v dst_pos + U32.v len) h /\ Seq.slice (B.as_seq h dst) (U32.v dst_pos) (U32.v dst_pos + U32.v i) `Seq.equal` Seq.slice (BY.reveal src) (U32.v src_from) (U32.v src_from + U32.v i) /\ (stop == true ==> i == len) )) (fun _ -> let i = B.index bi 0ul in if i = len then true else begin let x = BY.get src (src_from `U32.add` i) in mbuffer_upd dst (Ghost.hide (U32.v dst_pos)) (Ghost.hide (U32.v dst_pos + U32.v len)) (dst_pos `U32.add` i) x; let i' = i `U32.add` 1ul in B.upd bi 0ul i'; let h' = HST.get () in Seq.lemma_split (Seq.slice (B.as_seq h' dst) (U32.v dst_pos) (U32.v dst_pos + U32.v i')) (U32.v i); i' = len end ) ; HST.pop_frame () #pop-options
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowStar.Monotonic.Buffer.fsti.checked", "LowStar.Buffer.fst.checked", "LowParse.Spec.Bytes.fst.checked", "LowParse.Low.VLGen.fst.checked", "LowParse.Low.VLData.fst.checked", "LowParse.Low.Int.fsti.checked", "LowParse.Low.Combinators.fsti.checked", "LowParse.Bytes32.fst.checked", "FStar.UInt8.fsti.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Int.Cast.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked", "FStar.Classical.fsti.checked", "C.Loops.fst.checked" ], "interface_file": false, "source_file": "LowParse.Low.Bytes.fst" }
[ { "abbrev": true, "full_module": "LowStar.Buffer // for local variables in store_bytes", "short_module": "BF" }, { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "FStar.Int.Cast", "short_module": "Cast" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "LowParse.Bytes32", "short_module": "BY" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "BF" }, { "abbrev": true, "full_module": "LowStar.Monotonic.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": false, "full_module": "LowParse.Low.Int", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low.VLGen", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low.VLData", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low.Combinators", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec.Bytes", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
sz32: FStar.UInt32.t -> LowParse.Low.Base.serializer32 (LowParse.Spec.Bytes.serialize_flbytes (FStar.UInt32.v sz32))
Prims.Tot
[ "total" ]
[]
[ "FStar.UInt32.t", "FStar.Bytes.lbytes", "FStar.UInt32.v", "LowStar.Monotonic.Buffer.srel", "LowParse.Bytes.byte", "LowStar.Monotonic.Buffer.mbuffer", "Prims.unit", "LowParse.Low.Bytes.store_bytes", "FStar.UInt32.__uint_to_t", "LowParse.Low.Base.serializer32", "LowParse.Spec.Base.total_constant_size_parser_kind", "LowParse.Spec.Bytes.parse_flbytes", "LowParse.Spec.Bytes.serialize_flbytes" ]
[]
false
false
false
false
false
let serialize32_flbytes (sz32: U32.t) : Tot (serializer32 (serialize_flbytes (U32.v sz32))) =
fun (x: BY.lbytes (U32.v sz32)) #rrel #rel b pos -> let _ = store_bytes x 0ul sz32 b pos in sz32
false
LowParse.Low.Bytes.fst
LowParse.Low.Bytes.jump_bounded_vlbytes
val jump_bounded_vlbytes (min: nat) (max: nat{min <= max /\ max > 0 /\ max < 4294967296}) : Tot (jumper (parse_bounded_vlbytes min max))
val jump_bounded_vlbytes (min: nat) (max: nat{min <= max /\ max > 0 /\ max < 4294967296}) : Tot (jumper (parse_bounded_vlbytes min max))
let jump_bounded_vlbytes (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) : Tot (jumper (parse_bounded_vlbytes min max)) = jump_bounded_vlbytes' min max (log256' max)
{ "file_name": "src/lowparse/LowParse.Low.Bytes.fst", "git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
{ "end_col": 45, "end_line": 396, "start_col": 0, "start_line": 392 }
module LowParse.Low.Bytes include LowParse.Spec.Bytes include LowParse.Low.Combinators include LowParse.Low.VLData include LowParse.Low.VLGen include LowParse.Low.Int module U32 = FStar.UInt32 module HS = FStar.HyperStack module B = LowStar.Monotonic.Buffer module BF = LowStar.Buffer // for local variables in store_bytes module BY = LowParse.Bytes32 module HST = FStar.HyperStack.ST module U8 = FStar.UInt8 module Cast = FStar.Int.Cast module U64 = FStar.UInt64 inline_for_extraction let validate_flbytes (sz: nat) (sz64: U64.t { U64.v sz64 == sz /\ sz < 4294967296 } ) : Tot (validator (parse_flbytes sz)) = validate_total_constant_size (parse_flbytes sz) sz64 () inline_for_extraction let jump_flbytes (sz: nat) (sz32: U32.t { U32.v sz32 == sz } ) : Tot (jumper (parse_flbytes sz)) = jump_constant_size (parse_flbytes sz) sz32 () let valid_flbytes_intro (h: HS.mem) (sz: nat { sz < 4294967296 } ) (#rrel #rel: _) (s: slice rrel rel) (pos: U32.t) : Lemma (requires (U32.v pos + sz <= U32.v s.len /\ live_slice h s)) (ensures ( valid_content_pos (parse_flbytes sz) h s pos (BY.hide (bytes_of_slice_from_to h s pos (pos `U32.add` U32.uint_to_t sz))) (pos `U32.add` U32.uint_to_t sz) )) = valid_facts (parse_flbytes sz) h s pos let valid_pos_flbytes_elim (h: HS.mem) (sz: nat { sz < 4294967296 } ) (#rrel #rel: _) (s: slice rrel rel) (pos pos' : U32.t) : Lemma (requires (valid_pos (parse_flbytes sz) h s pos pos')) (ensures (U32.v pos + sz == U32.v pos')) [SMTPat (valid_pos (parse_flbytes sz) h s pos pos')] = valid_facts (parse_flbytes sz) h s pos let valid_flbytes_elim (h: HS.mem) (sz: nat { sz < 4294967296 } ) (#rrel #rel: _) (s: slice rrel rel) (pos: U32.t) : Lemma (requires (valid (parse_flbytes sz) h s pos)) (ensures ( valid_content_pos (parse_flbytes sz) h s pos (BY.hide (bytes_of_slice_from_to h s pos (pos `U32.add` U32.uint_to_t sz))) (pos `U32.add` U32.uint_to_t sz) )) = valid_flbytes_intro h sz s pos let clens_flbytes_slice (sz: nat) (from: U32.t) (to: U32.t {U32.v from <= U32.v to /\ U32.v to <= sz } ) : Tot (clens (BY.lbytes sz) (BY.lbytes (U32.v to - U32.v from))) = { clens_cond = (fun _ -> True); clens_get = (fun (x: BY.lbytes sz) -> (BY.slice x from to <: BY.lbytes (U32.v to - U32.v from))); } #push-options "--z3rlimit 16" let gaccessor_flbytes_slice' (sz: nat { sz < 4294967296 } ) (from: U32.t) (to: U32.t {U32.v from <= U32.v to /\ U32.v to <= sz } ) : Tot (gaccessor' (parse_flbytes sz) (parse_flbytes (U32.v to - U32.v from)) (clens_flbytes_slice sz from to)) = fun (input: bytes) -> ( begin if Seq.length input < sz then (0) // dummy else (U32.v from) end) let gaccessor_flbytes_slice (sz: nat { sz < 4294967296 } ) (from: U32.t) (to: U32.t {U32.v from <= U32.v to /\ U32.v to <= sz } ) : Tot (gaccessor (parse_flbytes sz) (parse_flbytes (U32.v to - U32.v from)) (clens_flbytes_slice sz from to)) = assert (forall x . gaccessor_pre (parse_flbytes sz) (parse_flbytes (U32.v to - U32.v from)) (clens_flbytes_slice sz from to) x ==> sz <= Seq.length x); gaccessor_prop_equiv (parse_flbytes sz) (parse_flbytes (U32.v to - U32.v from)) (clens_flbytes_slice sz from to) (gaccessor_flbytes_slice' sz from to); gaccessor_flbytes_slice' sz from to inline_for_extraction let accessor_flbytes_slice (sz: nat { sz < 4294967296 } ) (from: U32.t) (to: U32.t {U32.v from <= U32.v to /\ U32.v to <= sz } ) : Tot (accessor (gaccessor_flbytes_slice sz from to)) = fun #rrel #rel input pos -> let h = HST.get () in [@inline_let] let _ = slice_access_eq h (gaccessor_flbytes_slice sz from to) input pos in pos `U32.add` from #pop-options let clens_flbytes_get (sz: nat) (i: U32.t { U32.v i < sz } ) : Tot (clens (BY.lbytes sz) byte) = { clens_cond = (fun _ -> True); clens_get = (fun (x: BY.lbytes sz) -> (BY.get x i <: byte)); } #push-options "--z3rlimit 16 --max_fuel 1" let gaccessor_flbytes_get' (sz: nat { sz < 4294967296 } ) (i: U32.t { U32.v i < sz } ) : Tot (gaccessor' (parse_flbytes sz) (parse_u8) (clens_flbytes_get sz i)) = fun (input: bytes) -> ( begin let res = if Seq.length input < U32.v i then (0) // dummy else (U32.v i) in let g () : Lemma (requires (gaccessor_pre (parse_flbytes sz) parse_u8 (clens_flbytes_get sz i) input)) (ensures (gaccessor_post (parse_flbytes sz) parse_u8 (clens_flbytes_get sz i) input res)) = parser_kind_prop_equiv (get_parser_kind parse_u8) parse_u8; assert (res == (U32.v i)); parse_u8_spec' (Seq.slice input (U32.v i) (U32.v i + 1)); parse_strong_prefix parse_u8 (Seq.slice input (U32.v i) (U32.v i + 1)) (Seq.slice input (U32.v i) (Seq.length input)) in Classical.move_requires g (); res end) #pop-options let gaccessor_flbytes_get (sz: nat { sz < 4294967296 } ) (i: U32.t { U32.v i < sz } ) : Tot (gaccessor (parse_flbytes sz) (parse_u8) (clens_flbytes_get sz i)) = assert (forall x . gaccessor_pre (parse_flbytes sz) (parse_u8) (clens_flbytes_get sz i) x ==> U32.v i <= Seq.length x); gaccessor_prop_equiv (parse_flbytes sz) (parse_u8) (clens_flbytes_get sz i) (gaccessor_flbytes_get' sz i); gaccessor_flbytes_get' sz i inline_for_extraction let accessor_flbytes_get (sz: nat { sz < 4294967296 } ) (i: U32.t { U32.v i < sz } ) : Tot (accessor (gaccessor_flbytes_get sz i)) = fun #rrel #rel input pos -> let h = HST.get () in [@inline_let] let _ = slice_access_eq h (gaccessor_flbytes_get sz i) input pos in pos `U32.add` i (* Temporary: flbytes as leaf values *) (* TODO: convert store_bytes to monotonic buffers, using the "writable" predicate *) #push-options "--z3rlimit 32" inline_for_extraction let store_bytes (src: BY.bytes) (src_from src_to: U32.t) (#rrel #rel: _) (dst: B.mbuffer byte rrel rel) (dst_pos: U32.t) : HST.Stack unit (requires (fun h -> B.live h dst /\ U32.v src_from <= U32.v src_to /\ U32.v src_to <= BY.length src /\ U32.v dst_pos + (U32.v src_to - U32.v src_from) <= B.length dst /\ writable dst (U32.v dst_pos) (U32.v dst_pos + (U32.v src_to - U32.v src_from)) h )) (ensures (fun h _ h' -> B.modifies (B.loc_buffer_from_to dst dst_pos (dst_pos `U32.add` (src_to `U32.sub` src_from))) h h' /\ Seq.slice (B.as_seq h' dst) (U32.v dst_pos) (U32.v dst_pos + (U32.v src_to - U32.v src_from)) == Seq.slice (BY.reveal src) (U32.v src_from) (U32.v src_to) )) = let h0 = HST.get () in HST.push_frame (); let h1 = HST.get () in let bi = BF.alloca 0ul 1ul in let h2 = HST.get () in let len = src_to `U32.sub` src_from in C.Loops.do_while (fun h stop -> B.modifies (B.loc_union (B.loc_region_only true (HS.get_tip h1)) (B.loc_buffer_from_to dst dst_pos (dst_pos `U32.add` len))) h2 h /\ B.live h bi /\ ( let i = Seq.index (B.as_seq h bi) 0 in U32.v i <= U32.v len /\ writable dst (U32.v dst_pos) (U32.v dst_pos + U32.v len) h /\ Seq.slice (B.as_seq h dst) (U32.v dst_pos) (U32.v dst_pos + U32.v i) `Seq.equal` Seq.slice (BY.reveal src) (U32.v src_from) (U32.v src_from + U32.v i) /\ (stop == true ==> i == len) )) (fun _ -> let i = B.index bi 0ul in if i = len then true else begin let x = BY.get src (src_from `U32.add` i) in mbuffer_upd dst (Ghost.hide (U32.v dst_pos)) (Ghost.hide (U32.v dst_pos + U32.v len)) (dst_pos `U32.add` i) x; let i' = i `U32.add` 1ul in B.upd bi 0ul i'; let h' = HST.get () in Seq.lemma_split (Seq.slice (B.as_seq h' dst) (U32.v dst_pos) (U32.v dst_pos + U32.v i')) (U32.v i); i' = len end ) ; HST.pop_frame () #pop-options inline_for_extraction let serialize32_flbytes (sz32: U32.t) : Tot (serializer32 (serialize_flbytes (U32.v sz32))) = fun (x: BY.lbytes (U32.v sz32)) #rrel #rel b pos -> let _ = store_bytes x 0ul sz32 b pos in sz32 inline_for_extraction let write_flbytes (sz32: U32.t) : Tot (leaf_writer_strong (serialize_flbytes (U32.v sz32))) = leaf_writer_strong_of_serializer32 (serialize32_flbytes sz32) () inline_for_extraction let write_flbytes_weak (sz32: U32.t { U32.v sz32 < 4294967295 } ) // need to return that value if output buffer is too small : Tot (leaf_writer_weak (serialize_flbytes (U32.v sz32))) = leaf_writer_weak_of_strong_constant_size (write_flbytes sz32) sz32 () (* // TODO: remove, since nobody is using this inline_for_extraction let read_flbytes (sz32: U32.t) : Tot (leaf_reader (parse_flbytes (U32.v sz32))) = fun input pos -> let h = HST.get () in [@inline_let] let _ = valid_facts (parse_flbytes (U32.v sz32)) h input pos in BY.of_buffer sz32 (B.sub input.base pos sz32) *) (* Equality test between a vlbytes and a constant lbytes *) #push-options "--z3rlimit 32" inline_for_extraction let buffer_equals_bytes (const: BY.bytes) (#rrel #rel: _) (b: B.mbuffer byte rrel rel) (pos: U32.t) : HST.Stack bool (requires (fun h -> B.live h b /\ U32.v pos + BY.length const <= B.length b )) (ensures (fun h res h' -> B.modifies B.loc_none h h' /\ (res == true <==> Seq.slice (B.as_seq h b) (U32.v pos) (U32.v pos + BY.length const) == BY.reveal const) )) = let h0 = HST.get () in HST.push_frame (); let len = BY.len const in let bi = BF.alloca 0ul 1ul in let bres = BF.alloca true 1ul in let h1 = HST.get () in [@inline_let] let inv (h: HS.mem) (stop: bool) : GTot Type0 = B.modifies (B.loc_union (B.loc_buffer bi) (B.loc_buffer bres)) h1 h /\ ( let length = U32.v len in let i32 = (Seq.index (B.as_seq h bi) 0) in let i = U32.v i32 in let res = Seq.index (B.as_seq h bres) 0 in i <= length /\ (stop == false ==> res == true) /\ ((stop == true /\ res == true) ==> i == length) /\ (res == true <==> Seq.slice (B.as_seq h b) (U32.v pos) (U32.v pos + i) `Seq.equal` Seq.slice (BY.reveal const) 0 i) ) in C.Loops.do_while inv (fun _ -> let i = B.index bi 0ul in if i = len then true else begin let i' = i `U32.add` 1ul in [@inline_let] let _ = let s1 = (Seq.slice (B.as_seq h0 b) (U32.v pos) (U32.v pos + U32.v i)) in let c1 = (B.get h0 b (U32.v pos + U32.v i)) in let s2 = (Seq.slice (BY.reveal const) 0 (U32.v i)) in let c2 = (BY.index const (U32.v i)) in assert (Seq.slice (B.as_seq h0 b) (U32.v pos) (U32.v pos + U32.v i') `Seq.equal` Seq.snoc s1 c1); assert (Seq.slice (BY.reveal const) 0 (U32.v i') `Seq.equal` Seq.snoc s2 c2); Classical.move_requires (Seq.lemma_snoc_inj s1 s2 c1) c2 in let res = B.index b (pos `U32.add` i) = BY.get const i in B.upd bres 0ul res; B.upd bi 0ul i'; not res end ); let res = B.index bres 0ul in HST.pop_frame (); res #pop-options inline_for_extraction let valid_slice_equals_bytes (const: BY.bytes) (#rrel #rel: _) (input: slice rrel rel) (pos: U32.t) : HST.Stack bool (requires (fun h -> valid (parse_flbytes (BY.length const)) h input pos )) (ensures (fun h res h' -> B.modifies B.loc_none h h' /\ (res == true <==> contents (parse_flbytes (BY.length const)) h input pos == const ))) = let h = HST.get () in [@inline_let] let _ = valid_facts (parse_flbytes (BY.length const)) h input pos in buffer_equals_bytes const input.base pos inline_for_extraction let validate_all_bytes () : Tot (validator parse_all_bytes) = fun #rrel #rel input pos -> let h = HST.get () in [@inline_let] let _ = valid_facts parse_all_bytes h input (uint64_to_uint32 pos) in Cast.uint32_to_uint64 input.len inline_for_extraction let validate_bounded_vlbytes' (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (l: nat { l >= log256' max /\ l <= 4 } ) : Tot (validator (parse_bounded_vlbytes' min max l)) = validate_synth (validate_bounded_vldata_strong' min max l serialize_all_bytes (validate_all_bytes ())) (synth_bounded_vlbytes min max) () inline_for_extraction let validate_bounded_vlbytes (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) : Tot (validator (parse_bounded_vlbytes min max)) = validate_bounded_vlbytes' min max (log256' max) inline_for_extraction let jump_all_bytes () : Tot (jumper parse_all_bytes) = fun #rrel #rel input pos -> let h = HST.get () in [@inline_let] let _ = valid_facts parse_all_bytes h input pos in input.len inline_for_extraction let jump_bounded_vlbytes' (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (l: nat { l >= log256' max /\ l <= 4 } ) : Tot (jumper (parse_bounded_vlbytes' min max l)) = jump_synth (jump_bounded_vldata_strong' min max l serialize_all_bytes) (synth_bounded_vlbytes min max) ()
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowStar.Monotonic.Buffer.fsti.checked", "LowStar.Buffer.fst.checked", "LowParse.Spec.Bytes.fst.checked", "LowParse.Low.VLGen.fst.checked", "LowParse.Low.VLData.fst.checked", "LowParse.Low.Int.fsti.checked", "LowParse.Low.Combinators.fsti.checked", "LowParse.Bytes32.fst.checked", "FStar.UInt8.fsti.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Int.Cast.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked", "FStar.Classical.fsti.checked", "C.Loops.fst.checked" ], "interface_file": false, "source_file": "LowParse.Low.Bytes.fst" }
[ { "abbrev": true, "full_module": "LowStar.Buffer // for local variables in store_bytes", "short_module": "BF" }, { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "FStar.Int.Cast", "short_module": "Cast" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "LowParse.Bytes32", "short_module": "BY" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "BF" }, { "abbrev": true, "full_module": "LowStar.Monotonic.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": false, "full_module": "LowParse.Low.Int", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low.VLGen", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low.VLData", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low.Combinators", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec.Bytes", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
min: Prims.nat -> max: Prims.nat{min <= max /\ max > 0 /\ max < 4294967296} -> LowParse.Low.Base.jumper (LowParse.Spec.Bytes.parse_bounded_vlbytes min max)
Prims.Tot
[ "total" ]
[]
[ "Prims.nat", "Prims.l_and", "Prims.b2t", "Prims.op_LessThanOrEqual", "Prims.op_GreaterThan", "Prims.op_LessThan", "LowParse.Low.Bytes.jump_bounded_vlbytes'", "LowParse.Spec.BoundedInt.log256'", "LowParse.Low.Base.jumper", "LowParse.Spec.VLData.parse_bounded_vldata_strong_kind", "LowParse.Spec.Bytes.parse_all_bytes_kind", "LowParse.Spec.Bytes.parse_bounded_vlbytes_t", "LowParse.Spec.Bytes.parse_bounded_vlbytes" ]
[]
false
false
false
false
false
let jump_bounded_vlbytes (min: nat) (max: nat{min <= max /\ max > 0 /\ max < 4294967296}) : Tot (jumper (parse_bounded_vlbytes min max)) =
jump_bounded_vlbytes' min max (log256' max)
false
LowParse.Low.Bytes.fst
LowParse.Low.Bytes.accessor_flbytes_slice
val accessor_flbytes_slice (sz: nat{sz < 4294967296}) (from: U32.t) (to: U32.t{U32.v from <= U32.v to /\ U32.v to <= sz}) : Tot (accessor (gaccessor_flbytes_slice sz from to))
val accessor_flbytes_slice (sz: nat{sz < 4294967296}) (from: U32.t) (to: U32.t{U32.v from <= U32.v to /\ U32.v to <= sz}) : Tot (accessor (gaccessor_flbytes_slice sz from to))
let accessor_flbytes_slice (sz: nat { sz < 4294967296 } ) (from: U32.t) (to: U32.t {U32.v from <= U32.v to /\ U32.v to <= sz } ) : Tot (accessor (gaccessor_flbytes_slice sz from to)) = fun #rrel #rel input pos -> let h = HST.get () in [@inline_let] let _ = slice_access_eq h (gaccessor_flbytes_slice sz from to) input pos in pos `U32.add` from
{ "file_name": "src/lowparse/LowParse.Low.Bytes.fst", "git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
{ "end_col": 20, "end_line": 112, "start_col": 0, "start_line": 104 }
module LowParse.Low.Bytes include LowParse.Spec.Bytes include LowParse.Low.Combinators include LowParse.Low.VLData include LowParse.Low.VLGen include LowParse.Low.Int module U32 = FStar.UInt32 module HS = FStar.HyperStack module B = LowStar.Monotonic.Buffer module BF = LowStar.Buffer // for local variables in store_bytes module BY = LowParse.Bytes32 module HST = FStar.HyperStack.ST module U8 = FStar.UInt8 module Cast = FStar.Int.Cast module U64 = FStar.UInt64 inline_for_extraction let validate_flbytes (sz: nat) (sz64: U64.t { U64.v sz64 == sz /\ sz < 4294967296 } ) : Tot (validator (parse_flbytes sz)) = validate_total_constant_size (parse_flbytes sz) sz64 () inline_for_extraction let jump_flbytes (sz: nat) (sz32: U32.t { U32.v sz32 == sz } ) : Tot (jumper (parse_flbytes sz)) = jump_constant_size (parse_flbytes sz) sz32 () let valid_flbytes_intro (h: HS.mem) (sz: nat { sz < 4294967296 } ) (#rrel #rel: _) (s: slice rrel rel) (pos: U32.t) : Lemma (requires (U32.v pos + sz <= U32.v s.len /\ live_slice h s)) (ensures ( valid_content_pos (parse_flbytes sz) h s pos (BY.hide (bytes_of_slice_from_to h s pos (pos `U32.add` U32.uint_to_t sz))) (pos `U32.add` U32.uint_to_t sz) )) = valid_facts (parse_flbytes sz) h s pos let valid_pos_flbytes_elim (h: HS.mem) (sz: nat { sz < 4294967296 } ) (#rrel #rel: _) (s: slice rrel rel) (pos pos' : U32.t) : Lemma (requires (valid_pos (parse_flbytes sz) h s pos pos')) (ensures (U32.v pos + sz == U32.v pos')) [SMTPat (valid_pos (parse_flbytes sz) h s pos pos')] = valid_facts (parse_flbytes sz) h s pos let valid_flbytes_elim (h: HS.mem) (sz: nat { sz < 4294967296 } ) (#rrel #rel: _) (s: slice rrel rel) (pos: U32.t) : Lemma (requires (valid (parse_flbytes sz) h s pos)) (ensures ( valid_content_pos (parse_flbytes sz) h s pos (BY.hide (bytes_of_slice_from_to h s pos (pos `U32.add` U32.uint_to_t sz))) (pos `U32.add` U32.uint_to_t sz) )) = valid_flbytes_intro h sz s pos let clens_flbytes_slice (sz: nat) (from: U32.t) (to: U32.t {U32.v from <= U32.v to /\ U32.v to <= sz } ) : Tot (clens (BY.lbytes sz) (BY.lbytes (U32.v to - U32.v from))) = { clens_cond = (fun _ -> True); clens_get = (fun (x: BY.lbytes sz) -> (BY.slice x from to <: BY.lbytes (U32.v to - U32.v from))); } #push-options "--z3rlimit 16" let gaccessor_flbytes_slice' (sz: nat { sz < 4294967296 } ) (from: U32.t) (to: U32.t {U32.v from <= U32.v to /\ U32.v to <= sz } ) : Tot (gaccessor' (parse_flbytes sz) (parse_flbytes (U32.v to - U32.v from)) (clens_flbytes_slice sz from to)) = fun (input: bytes) -> ( begin if Seq.length input < sz then (0) // dummy else (U32.v from) end) let gaccessor_flbytes_slice (sz: nat { sz < 4294967296 } ) (from: U32.t) (to: U32.t {U32.v from <= U32.v to /\ U32.v to <= sz } ) : Tot (gaccessor (parse_flbytes sz) (parse_flbytes (U32.v to - U32.v from)) (clens_flbytes_slice sz from to)) = assert (forall x . gaccessor_pre (parse_flbytes sz) (parse_flbytes (U32.v to - U32.v from)) (clens_flbytes_slice sz from to) x ==> sz <= Seq.length x); gaccessor_prop_equiv (parse_flbytes sz) (parse_flbytes (U32.v to - U32.v from)) (clens_flbytes_slice sz from to) (gaccessor_flbytes_slice' sz from to); gaccessor_flbytes_slice' sz from to
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowStar.Monotonic.Buffer.fsti.checked", "LowStar.Buffer.fst.checked", "LowParse.Spec.Bytes.fst.checked", "LowParse.Low.VLGen.fst.checked", "LowParse.Low.VLData.fst.checked", "LowParse.Low.Int.fsti.checked", "LowParse.Low.Combinators.fsti.checked", "LowParse.Bytes32.fst.checked", "FStar.UInt8.fsti.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Int.Cast.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked", "FStar.Classical.fsti.checked", "C.Loops.fst.checked" ], "interface_file": false, "source_file": "LowParse.Low.Bytes.fst" }
[ { "abbrev": true, "full_module": "LowStar.Buffer // for local variables in store_bytes", "short_module": "BF" }, { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "FStar.Int.Cast", "short_module": "Cast" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "LowParse.Bytes32", "short_module": "BY" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "BF" }, { "abbrev": true, "full_module": "LowStar.Monotonic.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": false, "full_module": "LowParse.Low.Int", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low.VLGen", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low.VLData", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low.Combinators", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec.Bytes", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 16, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
sz: Prims.nat{sz < 4294967296} -> from: FStar.UInt32.t -> to: FStar.UInt32.t{FStar.UInt32.v from <= FStar.UInt32.v to /\ FStar.UInt32.v to <= sz} -> LowParse.Low.Base.accessor (LowParse.Low.Bytes.gaccessor_flbytes_slice sz from to)
Prims.Tot
[ "total" ]
[]
[ "Prims.nat", "Prims.b2t", "Prims.op_LessThan", "FStar.UInt32.t", "Prims.l_and", "Prims.op_LessThanOrEqual", "FStar.UInt32.v", "LowParse.Slice.srel", "LowParse.Bytes.byte", "LowParse.Slice.slice", "FStar.UInt32.add", "Prims.unit", "LowParse.Low.Base.Spec.slice_access_eq", "LowParse.Spec.Base.total_constant_size_parser_kind", "FStar.Bytes.lbytes", "LowParse.Spec.Bytes.parse_flbytes", "Prims.op_Subtraction", "LowParse.Low.Bytes.clens_flbytes_slice", "LowParse.Low.Bytes.gaccessor_flbytes_slice", "FStar.Monotonic.HyperStack.mem", "FStar.HyperStack.ST.get", "LowParse.Low.Base.accessor" ]
[]
false
false
false
false
false
let accessor_flbytes_slice (sz: nat{sz < 4294967296}) (from: U32.t) (to: U32.t{U32.v from <= U32.v to /\ U32.v to <= sz}) : Tot (accessor (gaccessor_flbytes_slice sz from to)) =
fun #rrel #rel input pos -> let h = HST.get () in [@@ inline_let ]let _ = slice_access_eq h (gaccessor_flbytes_slice sz from to) input pos in pos `U32.add` from
false
LowParse.Low.Bytes.fst
LowParse.Low.Bytes.validate_bounded_vlbytes
val validate_bounded_vlbytes (min: nat) (max: nat{min <= max /\ max > 0 /\ max < 4294967296}) : Tot (validator (parse_bounded_vlbytes min max))
val validate_bounded_vlbytes (min: nat) (max: nat{min <= max /\ max > 0 /\ max < 4294967296}) : Tot (validator (parse_bounded_vlbytes min max))
let validate_bounded_vlbytes (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) : Tot (validator (parse_bounded_vlbytes min max)) = validate_bounded_vlbytes' min max (log256' max)
{ "file_name": "src/lowparse/LowParse.Low.Bytes.fst", "git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
{ "end_col": 49, "end_line": 369, "start_col": 0, "start_line": 365 }
module LowParse.Low.Bytes include LowParse.Spec.Bytes include LowParse.Low.Combinators include LowParse.Low.VLData include LowParse.Low.VLGen include LowParse.Low.Int module U32 = FStar.UInt32 module HS = FStar.HyperStack module B = LowStar.Monotonic.Buffer module BF = LowStar.Buffer // for local variables in store_bytes module BY = LowParse.Bytes32 module HST = FStar.HyperStack.ST module U8 = FStar.UInt8 module Cast = FStar.Int.Cast module U64 = FStar.UInt64 inline_for_extraction let validate_flbytes (sz: nat) (sz64: U64.t { U64.v sz64 == sz /\ sz < 4294967296 } ) : Tot (validator (parse_flbytes sz)) = validate_total_constant_size (parse_flbytes sz) sz64 () inline_for_extraction let jump_flbytes (sz: nat) (sz32: U32.t { U32.v sz32 == sz } ) : Tot (jumper (parse_flbytes sz)) = jump_constant_size (parse_flbytes sz) sz32 () let valid_flbytes_intro (h: HS.mem) (sz: nat { sz < 4294967296 } ) (#rrel #rel: _) (s: slice rrel rel) (pos: U32.t) : Lemma (requires (U32.v pos + sz <= U32.v s.len /\ live_slice h s)) (ensures ( valid_content_pos (parse_flbytes sz) h s pos (BY.hide (bytes_of_slice_from_to h s pos (pos `U32.add` U32.uint_to_t sz))) (pos `U32.add` U32.uint_to_t sz) )) = valid_facts (parse_flbytes sz) h s pos let valid_pos_flbytes_elim (h: HS.mem) (sz: nat { sz < 4294967296 } ) (#rrel #rel: _) (s: slice rrel rel) (pos pos' : U32.t) : Lemma (requires (valid_pos (parse_flbytes sz) h s pos pos')) (ensures (U32.v pos + sz == U32.v pos')) [SMTPat (valid_pos (parse_flbytes sz) h s pos pos')] = valid_facts (parse_flbytes sz) h s pos let valid_flbytes_elim (h: HS.mem) (sz: nat { sz < 4294967296 } ) (#rrel #rel: _) (s: slice rrel rel) (pos: U32.t) : Lemma (requires (valid (parse_flbytes sz) h s pos)) (ensures ( valid_content_pos (parse_flbytes sz) h s pos (BY.hide (bytes_of_slice_from_to h s pos (pos `U32.add` U32.uint_to_t sz))) (pos `U32.add` U32.uint_to_t sz) )) = valid_flbytes_intro h sz s pos let clens_flbytes_slice (sz: nat) (from: U32.t) (to: U32.t {U32.v from <= U32.v to /\ U32.v to <= sz } ) : Tot (clens (BY.lbytes sz) (BY.lbytes (U32.v to - U32.v from))) = { clens_cond = (fun _ -> True); clens_get = (fun (x: BY.lbytes sz) -> (BY.slice x from to <: BY.lbytes (U32.v to - U32.v from))); } #push-options "--z3rlimit 16" let gaccessor_flbytes_slice' (sz: nat { sz < 4294967296 } ) (from: U32.t) (to: U32.t {U32.v from <= U32.v to /\ U32.v to <= sz } ) : Tot (gaccessor' (parse_flbytes sz) (parse_flbytes (U32.v to - U32.v from)) (clens_flbytes_slice sz from to)) = fun (input: bytes) -> ( begin if Seq.length input < sz then (0) // dummy else (U32.v from) end) let gaccessor_flbytes_slice (sz: nat { sz < 4294967296 } ) (from: U32.t) (to: U32.t {U32.v from <= U32.v to /\ U32.v to <= sz } ) : Tot (gaccessor (parse_flbytes sz) (parse_flbytes (U32.v to - U32.v from)) (clens_flbytes_slice sz from to)) = assert (forall x . gaccessor_pre (parse_flbytes sz) (parse_flbytes (U32.v to - U32.v from)) (clens_flbytes_slice sz from to) x ==> sz <= Seq.length x); gaccessor_prop_equiv (parse_flbytes sz) (parse_flbytes (U32.v to - U32.v from)) (clens_flbytes_slice sz from to) (gaccessor_flbytes_slice' sz from to); gaccessor_flbytes_slice' sz from to inline_for_extraction let accessor_flbytes_slice (sz: nat { sz < 4294967296 } ) (from: U32.t) (to: U32.t {U32.v from <= U32.v to /\ U32.v to <= sz } ) : Tot (accessor (gaccessor_flbytes_slice sz from to)) = fun #rrel #rel input pos -> let h = HST.get () in [@inline_let] let _ = slice_access_eq h (gaccessor_flbytes_slice sz from to) input pos in pos `U32.add` from #pop-options let clens_flbytes_get (sz: nat) (i: U32.t { U32.v i < sz } ) : Tot (clens (BY.lbytes sz) byte) = { clens_cond = (fun _ -> True); clens_get = (fun (x: BY.lbytes sz) -> (BY.get x i <: byte)); } #push-options "--z3rlimit 16 --max_fuel 1" let gaccessor_flbytes_get' (sz: nat { sz < 4294967296 } ) (i: U32.t { U32.v i < sz } ) : Tot (gaccessor' (parse_flbytes sz) (parse_u8) (clens_flbytes_get sz i)) = fun (input: bytes) -> ( begin let res = if Seq.length input < U32.v i then (0) // dummy else (U32.v i) in let g () : Lemma (requires (gaccessor_pre (parse_flbytes sz) parse_u8 (clens_flbytes_get sz i) input)) (ensures (gaccessor_post (parse_flbytes sz) parse_u8 (clens_flbytes_get sz i) input res)) = parser_kind_prop_equiv (get_parser_kind parse_u8) parse_u8; assert (res == (U32.v i)); parse_u8_spec' (Seq.slice input (U32.v i) (U32.v i + 1)); parse_strong_prefix parse_u8 (Seq.slice input (U32.v i) (U32.v i + 1)) (Seq.slice input (U32.v i) (Seq.length input)) in Classical.move_requires g (); res end) #pop-options let gaccessor_flbytes_get (sz: nat { sz < 4294967296 } ) (i: U32.t { U32.v i < sz } ) : Tot (gaccessor (parse_flbytes sz) (parse_u8) (clens_flbytes_get sz i)) = assert (forall x . gaccessor_pre (parse_flbytes sz) (parse_u8) (clens_flbytes_get sz i) x ==> U32.v i <= Seq.length x); gaccessor_prop_equiv (parse_flbytes sz) (parse_u8) (clens_flbytes_get sz i) (gaccessor_flbytes_get' sz i); gaccessor_flbytes_get' sz i inline_for_extraction let accessor_flbytes_get (sz: nat { sz < 4294967296 } ) (i: U32.t { U32.v i < sz } ) : Tot (accessor (gaccessor_flbytes_get sz i)) = fun #rrel #rel input pos -> let h = HST.get () in [@inline_let] let _ = slice_access_eq h (gaccessor_flbytes_get sz i) input pos in pos `U32.add` i (* Temporary: flbytes as leaf values *) (* TODO: convert store_bytes to monotonic buffers, using the "writable" predicate *) #push-options "--z3rlimit 32" inline_for_extraction let store_bytes (src: BY.bytes) (src_from src_to: U32.t) (#rrel #rel: _) (dst: B.mbuffer byte rrel rel) (dst_pos: U32.t) : HST.Stack unit (requires (fun h -> B.live h dst /\ U32.v src_from <= U32.v src_to /\ U32.v src_to <= BY.length src /\ U32.v dst_pos + (U32.v src_to - U32.v src_from) <= B.length dst /\ writable dst (U32.v dst_pos) (U32.v dst_pos + (U32.v src_to - U32.v src_from)) h )) (ensures (fun h _ h' -> B.modifies (B.loc_buffer_from_to dst dst_pos (dst_pos `U32.add` (src_to `U32.sub` src_from))) h h' /\ Seq.slice (B.as_seq h' dst) (U32.v dst_pos) (U32.v dst_pos + (U32.v src_to - U32.v src_from)) == Seq.slice (BY.reveal src) (U32.v src_from) (U32.v src_to) )) = let h0 = HST.get () in HST.push_frame (); let h1 = HST.get () in let bi = BF.alloca 0ul 1ul in let h2 = HST.get () in let len = src_to `U32.sub` src_from in C.Loops.do_while (fun h stop -> B.modifies (B.loc_union (B.loc_region_only true (HS.get_tip h1)) (B.loc_buffer_from_to dst dst_pos (dst_pos `U32.add` len))) h2 h /\ B.live h bi /\ ( let i = Seq.index (B.as_seq h bi) 0 in U32.v i <= U32.v len /\ writable dst (U32.v dst_pos) (U32.v dst_pos + U32.v len) h /\ Seq.slice (B.as_seq h dst) (U32.v dst_pos) (U32.v dst_pos + U32.v i) `Seq.equal` Seq.slice (BY.reveal src) (U32.v src_from) (U32.v src_from + U32.v i) /\ (stop == true ==> i == len) )) (fun _ -> let i = B.index bi 0ul in if i = len then true else begin let x = BY.get src (src_from `U32.add` i) in mbuffer_upd dst (Ghost.hide (U32.v dst_pos)) (Ghost.hide (U32.v dst_pos + U32.v len)) (dst_pos `U32.add` i) x; let i' = i `U32.add` 1ul in B.upd bi 0ul i'; let h' = HST.get () in Seq.lemma_split (Seq.slice (B.as_seq h' dst) (U32.v dst_pos) (U32.v dst_pos + U32.v i')) (U32.v i); i' = len end ) ; HST.pop_frame () #pop-options inline_for_extraction let serialize32_flbytes (sz32: U32.t) : Tot (serializer32 (serialize_flbytes (U32.v sz32))) = fun (x: BY.lbytes (U32.v sz32)) #rrel #rel b pos -> let _ = store_bytes x 0ul sz32 b pos in sz32 inline_for_extraction let write_flbytes (sz32: U32.t) : Tot (leaf_writer_strong (serialize_flbytes (U32.v sz32))) = leaf_writer_strong_of_serializer32 (serialize32_flbytes sz32) () inline_for_extraction let write_flbytes_weak (sz32: U32.t { U32.v sz32 < 4294967295 } ) // need to return that value if output buffer is too small : Tot (leaf_writer_weak (serialize_flbytes (U32.v sz32))) = leaf_writer_weak_of_strong_constant_size (write_flbytes sz32) sz32 () (* // TODO: remove, since nobody is using this inline_for_extraction let read_flbytes (sz32: U32.t) : Tot (leaf_reader (parse_flbytes (U32.v sz32))) = fun input pos -> let h = HST.get () in [@inline_let] let _ = valid_facts (parse_flbytes (U32.v sz32)) h input pos in BY.of_buffer sz32 (B.sub input.base pos sz32) *) (* Equality test between a vlbytes and a constant lbytes *) #push-options "--z3rlimit 32" inline_for_extraction let buffer_equals_bytes (const: BY.bytes) (#rrel #rel: _) (b: B.mbuffer byte rrel rel) (pos: U32.t) : HST.Stack bool (requires (fun h -> B.live h b /\ U32.v pos + BY.length const <= B.length b )) (ensures (fun h res h' -> B.modifies B.loc_none h h' /\ (res == true <==> Seq.slice (B.as_seq h b) (U32.v pos) (U32.v pos + BY.length const) == BY.reveal const) )) = let h0 = HST.get () in HST.push_frame (); let len = BY.len const in let bi = BF.alloca 0ul 1ul in let bres = BF.alloca true 1ul in let h1 = HST.get () in [@inline_let] let inv (h: HS.mem) (stop: bool) : GTot Type0 = B.modifies (B.loc_union (B.loc_buffer bi) (B.loc_buffer bres)) h1 h /\ ( let length = U32.v len in let i32 = (Seq.index (B.as_seq h bi) 0) in let i = U32.v i32 in let res = Seq.index (B.as_seq h bres) 0 in i <= length /\ (stop == false ==> res == true) /\ ((stop == true /\ res == true) ==> i == length) /\ (res == true <==> Seq.slice (B.as_seq h b) (U32.v pos) (U32.v pos + i) `Seq.equal` Seq.slice (BY.reveal const) 0 i) ) in C.Loops.do_while inv (fun _ -> let i = B.index bi 0ul in if i = len then true else begin let i' = i `U32.add` 1ul in [@inline_let] let _ = let s1 = (Seq.slice (B.as_seq h0 b) (U32.v pos) (U32.v pos + U32.v i)) in let c1 = (B.get h0 b (U32.v pos + U32.v i)) in let s2 = (Seq.slice (BY.reveal const) 0 (U32.v i)) in let c2 = (BY.index const (U32.v i)) in assert (Seq.slice (B.as_seq h0 b) (U32.v pos) (U32.v pos + U32.v i') `Seq.equal` Seq.snoc s1 c1); assert (Seq.slice (BY.reveal const) 0 (U32.v i') `Seq.equal` Seq.snoc s2 c2); Classical.move_requires (Seq.lemma_snoc_inj s1 s2 c1) c2 in let res = B.index b (pos `U32.add` i) = BY.get const i in B.upd bres 0ul res; B.upd bi 0ul i'; not res end ); let res = B.index bres 0ul in HST.pop_frame (); res #pop-options inline_for_extraction let valid_slice_equals_bytes (const: BY.bytes) (#rrel #rel: _) (input: slice rrel rel) (pos: U32.t) : HST.Stack bool (requires (fun h -> valid (parse_flbytes (BY.length const)) h input pos )) (ensures (fun h res h' -> B.modifies B.loc_none h h' /\ (res == true <==> contents (parse_flbytes (BY.length const)) h input pos == const ))) = let h = HST.get () in [@inline_let] let _ = valid_facts (parse_flbytes (BY.length const)) h input pos in buffer_equals_bytes const input.base pos inline_for_extraction let validate_all_bytes () : Tot (validator parse_all_bytes) = fun #rrel #rel input pos -> let h = HST.get () in [@inline_let] let _ = valid_facts parse_all_bytes h input (uint64_to_uint32 pos) in Cast.uint32_to_uint64 input.len inline_for_extraction let validate_bounded_vlbytes' (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (l: nat { l >= log256' max /\ l <= 4 } ) : Tot (validator (parse_bounded_vlbytes' min max l)) = validate_synth (validate_bounded_vldata_strong' min max l serialize_all_bytes (validate_all_bytes ())) (synth_bounded_vlbytes min max) ()
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowStar.Monotonic.Buffer.fsti.checked", "LowStar.Buffer.fst.checked", "LowParse.Spec.Bytes.fst.checked", "LowParse.Low.VLGen.fst.checked", "LowParse.Low.VLData.fst.checked", "LowParse.Low.Int.fsti.checked", "LowParse.Low.Combinators.fsti.checked", "LowParse.Bytes32.fst.checked", "FStar.UInt8.fsti.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Int.Cast.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked", "FStar.Classical.fsti.checked", "C.Loops.fst.checked" ], "interface_file": false, "source_file": "LowParse.Low.Bytes.fst" }
[ { "abbrev": true, "full_module": "LowStar.Buffer // for local variables in store_bytes", "short_module": "BF" }, { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "FStar.Int.Cast", "short_module": "Cast" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "LowParse.Bytes32", "short_module": "BY" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "BF" }, { "abbrev": true, "full_module": "LowStar.Monotonic.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": false, "full_module": "LowParse.Low.Int", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low.VLGen", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low.VLData", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low.Combinators", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec.Bytes", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
min: Prims.nat -> max: Prims.nat{min <= max /\ max > 0 /\ max < 4294967296} -> LowParse.Low.Base.validator (LowParse.Spec.Bytes.parse_bounded_vlbytes min max)
Prims.Tot
[ "total" ]
[]
[ "Prims.nat", "Prims.l_and", "Prims.b2t", "Prims.op_LessThanOrEqual", "Prims.op_GreaterThan", "Prims.op_LessThan", "LowParse.Low.Bytes.validate_bounded_vlbytes'", "LowParse.Spec.BoundedInt.log256'", "LowParse.Low.Base.validator", "LowParse.Spec.VLData.parse_bounded_vldata_strong_kind", "LowParse.Spec.Bytes.parse_all_bytes_kind", "LowParse.Spec.Bytes.parse_bounded_vlbytes_t", "LowParse.Spec.Bytes.parse_bounded_vlbytes" ]
[]
false
false
false
false
false
let validate_bounded_vlbytes (min: nat) (max: nat{min <= max /\ max > 0 /\ max < 4294967296}) : Tot (validator (parse_bounded_vlbytes min max)) =
validate_bounded_vlbytes' min max (log256' max)
false
LowParse.Low.Bytes.fst
LowParse.Low.Bytes.gaccessor_flbytes_get'
val gaccessor_flbytes_get' (sz: nat{sz < 4294967296}) (i: U32.t{U32.v i < sz}) : Tot (gaccessor' (parse_flbytes sz) (parse_u8) (clens_flbytes_get sz i))
val gaccessor_flbytes_get' (sz: nat{sz < 4294967296}) (i: U32.t{U32.v i < sz}) : Tot (gaccessor' (parse_flbytes sz) (parse_u8) (clens_flbytes_get sz i))
let gaccessor_flbytes_get' (sz: nat { sz < 4294967296 } ) (i: U32.t { U32.v i < sz } ) : Tot (gaccessor' (parse_flbytes sz) (parse_u8) (clens_flbytes_get sz i)) = fun (input: bytes) -> ( begin let res = if Seq.length input < U32.v i then (0) // dummy else (U32.v i) in let g () : Lemma (requires (gaccessor_pre (parse_flbytes sz) parse_u8 (clens_flbytes_get sz i) input)) (ensures (gaccessor_post (parse_flbytes sz) parse_u8 (clens_flbytes_get sz i) input res)) = parser_kind_prop_equiv (get_parser_kind parse_u8) parse_u8; assert (res == (U32.v i)); parse_u8_spec' (Seq.slice input (U32.v i) (U32.v i + 1)); parse_strong_prefix parse_u8 (Seq.slice input (U32.v i) (U32.v i + 1)) (Seq.slice input (U32.v i) (Seq.length input)) in Classical.move_requires g (); res end)
{ "file_name": "src/lowparse/LowParse.Low.Bytes.fst", "git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
{ "end_col": 6, "end_line": 147, "start_col": 0, "start_line": 126 }
module LowParse.Low.Bytes include LowParse.Spec.Bytes include LowParse.Low.Combinators include LowParse.Low.VLData include LowParse.Low.VLGen include LowParse.Low.Int module U32 = FStar.UInt32 module HS = FStar.HyperStack module B = LowStar.Monotonic.Buffer module BF = LowStar.Buffer // for local variables in store_bytes module BY = LowParse.Bytes32 module HST = FStar.HyperStack.ST module U8 = FStar.UInt8 module Cast = FStar.Int.Cast module U64 = FStar.UInt64 inline_for_extraction let validate_flbytes (sz: nat) (sz64: U64.t { U64.v sz64 == sz /\ sz < 4294967296 } ) : Tot (validator (parse_flbytes sz)) = validate_total_constant_size (parse_flbytes sz) sz64 () inline_for_extraction let jump_flbytes (sz: nat) (sz32: U32.t { U32.v sz32 == sz } ) : Tot (jumper (parse_flbytes sz)) = jump_constant_size (parse_flbytes sz) sz32 () let valid_flbytes_intro (h: HS.mem) (sz: nat { sz < 4294967296 } ) (#rrel #rel: _) (s: slice rrel rel) (pos: U32.t) : Lemma (requires (U32.v pos + sz <= U32.v s.len /\ live_slice h s)) (ensures ( valid_content_pos (parse_flbytes sz) h s pos (BY.hide (bytes_of_slice_from_to h s pos (pos `U32.add` U32.uint_to_t sz))) (pos `U32.add` U32.uint_to_t sz) )) = valid_facts (parse_flbytes sz) h s pos let valid_pos_flbytes_elim (h: HS.mem) (sz: nat { sz < 4294967296 } ) (#rrel #rel: _) (s: slice rrel rel) (pos pos' : U32.t) : Lemma (requires (valid_pos (parse_flbytes sz) h s pos pos')) (ensures (U32.v pos + sz == U32.v pos')) [SMTPat (valid_pos (parse_flbytes sz) h s pos pos')] = valid_facts (parse_flbytes sz) h s pos let valid_flbytes_elim (h: HS.mem) (sz: nat { sz < 4294967296 } ) (#rrel #rel: _) (s: slice rrel rel) (pos: U32.t) : Lemma (requires (valid (parse_flbytes sz) h s pos)) (ensures ( valid_content_pos (parse_flbytes sz) h s pos (BY.hide (bytes_of_slice_from_to h s pos (pos `U32.add` U32.uint_to_t sz))) (pos `U32.add` U32.uint_to_t sz) )) = valid_flbytes_intro h sz s pos let clens_flbytes_slice (sz: nat) (from: U32.t) (to: U32.t {U32.v from <= U32.v to /\ U32.v to <= sz } ) : Tot (clens (BY.lbytes sz) (BY.lbytes (U32.v to - U32.v from))) = { clens_cond = (fun _ -> True); clens_get = (fun (x: BY.lbytes sz) -> (BY.slice x from to <: BY.lbytes (U32.v to - U32.v from))); } #push-options "--z3rlimit 16" let gaccessor_flbytes_slice' (sz: nat { sz < 4294967296 } ) (from: U32.t) (to: U32.t {U32.v from <= U32.v to /\ U32.v to <= sz } ) : Tot (gaccessor' (parse_flbytes sz) (parse_flbytes (U32.v to - U32.v from)) (clens_flbytes_slice sz from to)) = fun (input: bytes) -> ( begin if Seq.length input < sz then (0) // dummy else (U32.v from) end) let gaccessor_flbytes_slice (sz: nat { sz < 4294967296 } ) (from: U32.t) (to: U32.t {U32.v from <= U32.v to /\ U32.v to <= sz } ) : Tot (gaccessor (parse_flbytes sz) (parse_flbytes (U32.v to - U32.v from)) (clens_flbytes_slice sz from to)) = assert (forall x . gaccessor_pre (parse_flbytes sz) (parse_flbytes (U32.v to - U32.v from)) (clens_flbytes_slice sz from to) x ==> sz <= Seq.length x); gaccessor_prop_equiv (parse_flbytes sz) (parse_flbytes (U32.v to - U32.v from)) (clens_flbytes_slice sz from to) (gaccessor_flbytes_slice' sz from to); gaccessor_flbytes_slice' sz from to inline_for_extraction let accessor_flbytes_slice (sz: nat { sz < 4294967296 } ) (from: U32.t) (to: U32.t {U32.v from <= U32.v to /\ U32.v to <= sz } ) : Tot (accessor (gaccessor_flbytes_slice sz from to)) = fun #rrel #rel input pos -> let h = HST.get () in [@inline_let] let _ = slice_access_eq h (gaccessor_flbytes_slice sz from to) input pos in pos `U32.add` from #pop-options let clens_flbytes_get (sz: nat) (i: U32.t { U32.v i < sz } ) : Tot (clens (BY.lbytes sz) byte) = { clens_cond = (fun _ -> True); clens_get = (fun (x: BY.lbytes sz) -> (BY.get x i <: byte)); }
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowStar.Monotonic.Buffer.fsti.checked", "LowStar.Buffer.fst.checked", "LowParse.Spec.Bytes.fst.checked", "LowParse.Low.VLGen.fst.checked", "LowParse.Low.VLData.fst.checked", "LowParse.Low.Int.fsti.checked", "LowParse.Low.Combinators.fsti.checked", "LowParse.Bytes32.fst.checked", "FStar.UInt8.fsti.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Int.Cast.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked", "FStar.Classical.fsti.checked", "C.Loops.fst.checked" ], "interface_file": false, "source_file": "LowParse.Low.Bytes.fst" }
[ { "abbrev": true, "full_module": "LowStar.Buffer // for local variables in store_bytes", "short_module": "BF" }, { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "FStar.Int.Cast", "short_module": "Cast" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "LowParse.Bytes32", "short_module": "BY" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "BF" }, { "abbrev": true, "full_module": "LowStar.Monotonic.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": false, "full_module": "LowParse.Low.Int", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low.VLGen", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low.VLData", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low.Combinators", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec.Bytes", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 1, "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": 16, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
sz: Prims.nat{sz < 4294967296} -> i: FStar.UInt32.t{FStar.UInt32.v i < sz} -> LowParse.Low.Base.Spec.gaccessor' (LowParse.Spec.Bytes.parse_flbytes sz) LowParse.Spec.Int.parse_u8 (LowParse.Low.Bytes.clens_flbytes_get sz i)
Prims.Tot
[ "total" ]
[]
[ "Prims.nat", "Prims.b2t", "Prims.op_LessThan", "FStar.UInt32.t", "FStar.UInt32.v", "LowParse.Bytes.bytes", "Prims.unit", "FStar.Classical.move_requires", "LowParse.Low.Base.Spec.gaccessor_pre", "LowParse.Spec.Base.total_constant_size_parser_kind", "FStar.Bytes.lbytes", "LowParse.Spec.Bytes.parse_flbytes", "LowParse.Spec.Int.parse_u8_kind", "FStar.UInt8.t", "LowParse.Spec.Int.parse_u8", "LowParse.Low.Bytes.clens_flbytes_get", "LowParse.Low.Base.Spec.gaccessor_post", "Prims.squash", "Prims.Nil", "FStar.Pervasives.pattern", "LowParse.Spec.Base.parse_strong_prefix", "FStar.Seq.Base.slice", "LowParse.Bytes.byte", "Prims.op_Addition", "FStar.Seq.Base.length", "LowParse.Spec.Int.parse_u8_spec'", "Prims._assert", "Prims.eq2", "Prims.int", "Prims.l_or", "Prims.op_GreaterThanOrEqual", "FStar.UInt.size", "FStar.UInt32.n", "LowParse.Spec.Base.parser_kind_prop_equiv", "LowParse.Spec.Base.get_parser_kind", "Prims.bool", "LowParse.Low.Base.Spec.gaccessor'" ]
[]
false
false
false
false
false
let gaccessor_flbytes_get' (sz: nat{sz < 4294967296}) (i: U32.t{U32.v i < sz}) : Tot (gaccessor' (parse_flbytes sz) (parse_u8) (clens_flbytes_get sz i)) =
fun (input: bytes) -> (let res = if Seq.length input < U32.v i then (0) else (U32.v i) in let g () : Lemma (requires (gaccessor_pre (parse_flbytes sz) parse_u8 (clens_flbytes_get sz i) input)) (ensures (gaccessor_post (parse_flbytes sz) parse_u8 (clens_flbytes_get sz i) input res)) = parser_kind_prop_equiv (get_parser_kind parse_u8) parse_u8; assert (res == (U32.v i)); parse_u8_spec' (Seq.slice input (U32.v i) (U32.v i + 1)); parse_strong_prefix parse_u8 (Seq.slice input (U32.v i) (U32.v i + 1)) (Seq.slice input (U32.v i) (Seq.length input)) in Classical.move_requires g (); res)
false
LowParse.Low.Bytes.fst
LowParse.Low.Bytes.valid_flbytes_elim
val valid_flbytes_elim (h: HS.mem) (sz: nat{sz < 4294967296}) (#rrel #rel: _) (s: slice rrel rel) (pos: U32.t) : Lemma (requires (valid (parse_flbytes sz) h s pos)) (ensures (valid_content_pos (parse_flbytes sz) h s pos (BY.hide (bytes_of_slice_from_to h s pos (pos `U32.add` (U32.uint_to_t sz)))) (pos `U32.add` (U32.uint_to_t sz))))
val valid_flbytes_elim (h: HS.mem) (sz: nat{sz < 4294967296}) (#rrel #rel: _) (s: slice rrel rel) (pos: U32.t) : Lemma (requires (valid (parse_flbytes sz) h s pos)) (ensures (valid_content_pos (parse_flbytes sz) h s pos (BY.hide (bytes_of_slice_from_to h s pos (pos `U32.add` (U32.uint_to_t sz)))) (pos `U32.add` (U32.uint_to_t sz))))
let valid_flbytes_elim (h: HS.mem) (sz: nat { sz < 4294967296 } ) (#rrel #rel: _) (s: slice rrel rel) (pos: U32.t) : Lemma (requires (valid (parse_flbytes sz) h s pos)) (ensures ( valid_content_pos (parse_flbytes sz) h s pos (BY.hide (bytes_of_slice_from_to h s pos (pos `U32.add` U32.uint_to_t sz))) (pos `U32.add` U32.uint_to_t sz) )) = valid_flbytes_intro h sz s pos
{ "file_name": "src/lowparse/LowParse.Low.Bytes.fst", "git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
{ "end_col": 32, "end_line": 68, "start_col": 0, "start_line": 57 }
module LowParse.Low.Bytes include LowParse.Spec.Bytes include LowParse.Low.Combinators include LowParse.Low.VLData include LowParse.Low.VLGen include LowParse.Low.Int module U32 = FStar.UInt32 module HS = FStar.HyperStack module B = LowStar.Monotonic.Buffer module BF = LowStar.Buffer // for local variables in store_bytes module BY = LowParse.Bytes32 module HST = FStar.HyperStack.ST module U8 = FStar.UInt8 module Cast = FStar.Int.Cast module U64 = FStar.UInt64 inline_for_extraction let validate_flbytes (sz: nat) (sz64: U64.t { U64.v sz64 == sz /\ sz < 4294967296 } ) : Tot (validator (parse_flbytes sz)) = validate_total_constant_size (parse_flbytes sz) sz64 () inline_for_extraction let jump_flbytes (sz: nat) (sz32: U32.t { U32.v sz32 == sz } ) : Tot (jumper (parse_flbytes sz)) = jump_constant_size (parse_flbytes sz) sz32 () let valid_flbytes_intro (h: HS.mem) (sz: nat { sz < 4294967296 } ) (#rrel #rel: _) (s: slice rrel rel) (pos: U32.t) : Lemma (requires (U32.v pos + sz <= U32.v s.len /\ live_slice h s)) (ensures ( valid_content_pos (parse_flbytes sz) h s pos (BY.hide (bytes_of_slice_from_to h s pos (pos `U32.add` U32.uint_to_t sz))) (pos `U32.add` U32.uint_to_t sz) )) = valid_facts (parse_flbytes sz) h s pos let valid_pos_flbytes_elim (h: HS.mem) (sz: nat { sz < 4294967296 } ) (#rrel #rel: _) (s: slice rrel rel) (pos pos' : U32.t) : Lemma (requires (valid_pos (parse_flbytes sz) h s pos pos')) (ensures (U32.v pos + sz == U32.v pos')) [SMTPat (valid_pos (parse_flbytes sz) h s pos pos')] = valid_facts (parse_flbytes sz) h s pos
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowStar.Monotonic.Buffer.fsti.checked", "LowStar.Buffer.fst.checked", "LowParse.Spec.Bytes.fst.checked", "LowParse.Low.VLGen.fst.checked", "LowParse.Low.VLData.fst.checked", "LowParse.Low.Int.fsti.checked", "LowParse.Low.Combinators.fsti.checked", "LowParse.Bytes32.fst.checked", "FStar.UInt8.fsti.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Int.Cast.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked", "FStar.Classical.fsti.checked", "C.Loops.fst.checked" ], "interface_file": false, "source_file": "LowParse.Low.Bytes.fst" }
[ { "abbrev": true, "full_module": "LowStar.Buffer // for local variables in store_bytes", "short_module": "BF" }, { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "FStar.Int.Cast", "short_module": "Cast" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "LowParse.Bytes32", "short_module": "BY" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "BF" }, { "abbrev": true, "full_module": "LowStar.Monotonic.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": false, "full_module": "LowParse.Low.Int", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low.VLGen", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low.VLData", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low.Combinators", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec.Bytes", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
h: FStar.Monotonic.HyperStack.mem -> sz: Prims.nat{sz < 4294967296} -> s: LowParse.Slice.slice rrel rel -> pos: FStar.UInt32.t -> FStar.Pervasives.Lemma (requires LowParse.Low.Base.Spec.valid (LowParse.Spec.Bytes.parse_flbytes sz) h s pos) (ensures LowParse.Low.Base.Spec.valid_content_pos (LowParse.Spec.Bytes.parse_flbytes sz) h s pos (FStar.Bytes.hide (LowParse.Low.Base.Spec.bytes_of_slice_from_to h s pos (FStar.UInt32.add pos (FStar.UInt32.uint_to_t sz)))) (FStar.UInt32.add pos (FStar.UInt32.uint_to_t sz)))
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "FStar.Monotonic.HyperStack.mem", "Prims.nat", "Prims.b2t", "Prims.op_LessThan", "LowParse.Slice.srel", "LowParse.Bytes.byte", "LowParse.Slice.slice", "FStar.UInt32.t", "LowParse.Low.Bytes.valid_flbytes_intro", "Prims.unit", "LowParse.Low.Base.Spec.valid", "LowParse.Spec.Base.total_constant_size_parser_kind", "FStar.Bytes.lbytes", "LowParse.Spec.Bytes.parse_flbytes", "Prims.squash", "LowParse.Low.Base.Spec.valid_content_pos", "FStar.Bytes.hide", "LowParse.Low.Base.Spec.bytes_of_slice_from_to", "FStar.UInt32.add", "FStar.UInt32.uint_to_t", "Prims.Nil", "FStar.Pervasives.pattern" ]
[]
true
false
true
false
false
let valid_flbytes_elim (h: HS.mem) (sz: nat{sz < 4294967296}) (#rrel #rel: _) (s: slice rrel rel) (pos: U32.t) : Lemma (requires (valid (parse_flbytes sz) h s pos)) (ensures (valid_content_pos (parse_flbytes sz) h s pos (BY.hide (bytes_of_slice_from_to h s pos (pos `U32.add` (U32.uint_to_t sz)))) (pos `U32.add` (U32.uint_to_t sz)))) =
valid_flbytes_intro h sz s pos
false
LowParse.Low.Bytes.fst
LowParse.Low.Bytes.valid_flbytes_intro
val valid_flbytes_intro (h: HS.mem) (sz: nat{sz < 4294967296}) (#rrel #rel: _) (s: slice rrel rel) (pos: U32.t) : Lemma (requires (U32.v pos + sz <= U32.v s.len /\ live_slice h s)) (ensures (valid_content_pos (parse_flbytes sz) h s pos (BY.hide (bytes_of_slice_from_to h s pos (pos `U32.add` (U32.uint_to_t sz)))) (pos `U32.add` (U32.uint_to_t sz))))
val valid_flbytes_intro (h: HS.mem) (sz: nat{sz < 4294967296}) (#rrel #rel: _) (s: slice rrel rel) (pos: U32.t) : Lemma (requires (U32.v pos + sz <= U32.v s.len /\ live_slice h s)) (ensures (valid_content_pos (parse_flbytes sz) h s pos (BY.hide (bytes_of_slice_from_to h s pos (pos `U32.add` (U32.uint_to_t sz)))) (pos `U32.add` (U32.uint_to_t sz))))
let valid_flbytes_intro (h: HS.mem) (sz: nat { sz < 4294967296 } ) (#rrel #rel: _) (s: slice rrel rel) (pos: U32.t) : Lemma (requires (U32.v pos + sz <= U32.v s.len /\ live_slice h s)) (ensures ( valid_content_pos (parse_flbytes sz) h s pos (BY.hide (bytes_of_slice_from_to h s pos (pos `U32.add` U32.uint_to_t sz))) (pos `U32.add` U32.uint_to_t sz) )) = valid_facts (parse_flbytes sz) h s pos
{ "file_name": "src/lowparse/LowParse.Low.Bytes.fst", "git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
{ "end_col": 40, "end_line": 43, "start_col": 0, "start_line": 32 }
module LowParse.Low.Bytes include LowParse.Spec.Bytes include LowParse.Low.Combinators include LowParse.Low.VLData include LowParse.Low.VLGen include LowParse.Low.Int module U32 = FStar.UInt32 module HS = FStar.HyperStack module B = LowStar.Monotonic.Buffer module BF = LowStar.Buffer // for local variables in store_bytes module BY = LowParse.Bytes32 module HST = FStar.HyperStack.ST module U8 = FStar.UInt8 module Cast = FStar.Int.Cast module U64 = FStar.UInt64 inline_for_extraction let validate_flbytes (sz: nat) (sz64: U64.t { U64.v sz64 == sz /\ sz < 4294967296 } ) : Tot (validator (parse_flbytes sz)) = validate_total_constant_size (parse_flbytes sz) sz64 () inline_for_extraction let jump_flbytes (sz: nat) (sz32: U32.t { U32.v sz32 == sz } ) : Tot (jumper (parse_flbytes sz)) = jump_constant_size (parse_flbytes sz) sz32 ()
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowStar.Monotonic.Buffer.fsti.checked", "LowStar.Buffer.fst.checked", "LowParse.Spec.Bytes.fst.checked", "LowParse.Low.VLGen.fst.checked", "LowParse.Low.VLData.fst.checked", "LowParse.Low.Int.fsti.checked", "LowParse.Low.Combinators.fsti.checked", "LowParse.Bytes32.fst.checked", "FStar.UInt8.fsti.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Int.Cast.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked", "FStar.Classical.fsti.checked", "C.Loops.fst.checked" ], "interface_file": false, "source_file": "LowParse.Low.Bytes.fst" }
[ { "abbrev": true, "full_module": "LowStar.Buffer // for local variables in store_bytes", "short_module": "BF" }, { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "FStar.Int.Cast", "short_module": "Cast" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "LowParse.Bytes32", "short_module": "BY" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "BF" }, { "abbrev": true, "full_module": "LowStar.Monotonic.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": false, "full_module": "LowParse.Low.Int", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low.VLGen", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low.VLData", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low.Combinators", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec.Bytes", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
h: FStar.Monotonic.HyperStack.mem -> sz: Prims.nat{sz < 4294967296} -> s: LowParse.Slice.slice rrel rel -> pos: FStar.UInt32.t -> FStar.Pervasives.Lemma (requires FStar.UInt32.v pos + sz <= FStar.UInt32.v (Mkslice?.len s) /\ LowParse.Slice.live_slice h s) (ensures LowParse.Low.Base.Spec.valid_content_pos (LowParse.Spec.Bytes.parse_flbytes sz) h s pos (FStar.Bytes.hide (LowParse.Low.Base.Spec.bytes_of_slice_from_to h s pos (FStar.UInt32.add pos (FStar.UInt32.uint_to_t sz)))) (FStar.UInt32.add pos (FStar.UInt32.uint_to_t sz)))
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "FStar.Monotonic.HyperStack.mem", "Prims.nat", "Prims.b2t", "Prims.op_LessThan", "LowParse.Slice.srel", "LowParse.Bytes.byte", "LowParse.Slice.slice", "FStar.UInt32.t", "LowParse.Low.Base.Spec.valid_facts", "LowParse.Spec.Base.total_constant_size_parser_kind", "FStar.Bytes.lbytes", "LowParse.Spec.Bytes.parse_flbytes", "Prims.unit", "Prims.l_and", "Prims.op_LessThanOrEqual", "Prims.op_Addition", "FStar.UInt32.v", "LowParse.Slice.__proj__Mkslice__item__len", "LowParse.Slice.live_slice", "Prims.squash", "LowParse.Low.Base.Spec.valid_content_pos", "FStar.Bytes.hide", "LowParse.Low.Base.Spec.bytes_of_slice_from_to", "FStar.UInt32.add", "FStar.UInt32.uint_to_t", "Prims.Nil", "FStar.Pervasives.pattern" ]
[]
true
false
true
false
false
let valid_flbytes_intro (h: HS.mem) (sz: nat{sz < 4294967296}) (#rrel #rel: _) (s: slice rrel rel) (pos: U32.t) : Lemma (requires (U32.v pos + sz <= U32.v s.len /\ live_slice h s)) (ensures (valid_content_pos (parse_flbytes sz) h s pos (BY.hide (bytes_of_slice_from_to h s pos (pos `U32.add` (U32.uint_to_t sz)))) (pos `U32.add` (U32.uint_to_t sz)))) =
valid_facts (parse_flbytes sz) h s pos
false
LowParse.Low.Bytes.fst
LowParse.Low.Bytes.clens_vlbytes_cond
val clens_vlbytes_cond (min: nat) (max: nat{min <= max /\ max > 0 /\ max < 4294967296}) (length: nat) (x: parse_bounded_vlbytes_t min max) : GTot Type0
val clens_vlbytes_cond (min: nat) (max: nat{min <= max /\ max > 0 /\ max < 4294967296}) (length: nat) (x: parse_bounded_vlbytes_t min max) : GTot Type0
let clens_vlbytes_cond (min: nat) (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (length: nat) (x: parse_bounded_vlbytes_t min max) : GTot Type0 = BY.length x == length
{ "file_name": "src/lowparse/LowParse.Low.Bytes.fst", "git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
{ "end_col": 23, "end_line": 598, "start_col": 0, "start_line": 592 }
module LowParse.Low.Bytes include LowParse.Spec.Bytes include LowParse.Low.Combinators include LowParse.Low.VLData include LowParse.Low.VLGen include LowParse.Low.Int module U32 = FStar.UInt32 module HS = FStar.HyperStack module B = LowStar.Monotonic.Buffer module BF = LowStar.Buffer // for local variables in store_bytes module BY = LowParse.Bytes32 module HST = FStar.HyperStack.ST module U8 = FStar.UInt8 module Cast = FStar.Int.Cast module U64 = FStar.UInt64 inline_for_extraction let validate_flbytes (sz: nat) (sz64: U64.t { U64.v sz64 == sz /\ sz < 4294967296 } ) : Tot (validator (parse_flbytes sz)) = validate_total_constant_size (parse_flbytes sz) sz64 () inline_for_extraction let jump_flbytes (sz: nat) (sz32: U32.t { U32.v sz32 == sz } ) : Tot (jumper (parse_flbytes sz)) = jump_constant_size (parse_flbytes sz) sz32 () let valid_flbytes_intro (h: HS.mem) (sz: nat { sz < 4294967296 } ) (#rrel #rel: _) (s: slice rrel rel) (pos: U32.t) : Lemma (requires (U32.v pos + sz <= U32.v s.len /\ live_slice h s)) (ensures ( valid_content_pos (parse_flbytes sz) h s pos (BY.hide (bytes_of_slice_from_to h s pos (pos `U32.add` U32.uint_to_t sz))) (pos `U32.add` U32.uint_to_t sz) )) = valid_facts (parse_flbytes sz) h s pos let valid_pos_flbytes_elim (h: HS.mem) (sz: nat { sz < 4294967296 } ) (#rrel #rel: _) (s: slice rrel rel) (pos pos' : U32.t) : Lemma (requires (valid_pos (parse_flbytes sz) h s pos pos')) (ensures (U32.v pos + sz == U32.v pos')) [SMTPat (valid_pos (parse_flbytes sz) h s pos pos')] = valid_facts (parse_flbytes sz) h s pos let valid_flbytes_elim (h: HS.mem) (sz: nat { sz < 4294967296 } ) (#rrel #rel: _) (s: slice rrel rel) (pos: U32.t) : Lemma (requires (valid (parse_flbytes sz) h s pos)) (ensures ( valid_content_pos (parse_flbytes sz) h s pos (BY.hide (bytes_of_slice_from_to h s pos (pos `U32.add` U32.uint_to_t sz))) (pos `U32.add` U32.uint_to_t sz) )) = valid_flbytes_intro h sz s pos let clens_flbytes_slice (sz: nat) (from: U32.t) (to: U32.t {U32.v from <= U32.v to /\ U32.v to <= sz } ) : Tot (clens (BY.lbytes sz) (BY.lbytes (U32.v to - U32.v from))) = { clens_cond = (fun _ -> True); clens_get = (fun (x: BY.lbytes sz) -> (BY.slice x from to <: BY.lbytes (U32.v to - U32.v from))); } #push-options "--z3rlimit 16" let gaccessor_flbytes_slice' (sz: nat { sz < 4294967296 } ) (from: U32.t) (to: U32.t {U32.v from <= U32.v to /\ U32.v to <= sz } ) : Tot (gaccessor' (parse_flbytes sz) (parse_flbytes (U32.v to - U32.v from)) (clens_flbytes_slice sz from to)) = fun (input: bytes) -> ( begin if Seq.length input < sz then (0) // dummy else (U32.v from) end) let gaccessor_flbytes_slice (sz: nat { sz < 4294967296 } ) (from: U32.t) (to: U32.t {U32.v from <= U32.v to /\ U32.v to <= sz } ) : Tot (gaccessor (parse_flbytes sz) (parse_flbytes (U32.v to - U32.v from)) (clens_flbytes_slice sz from to)) = assert (forall x . gaccessor_pre (parse_flbytes sz) (parse_flbytes (U32.v to - U32.v from)) (clens_flbytes_slice sz from to) x ==> sz <= Seq.length x); gaccessor_prop_equiv (parse_flbytes sz) (parse_flbytes (U32.v to - U32.v from)) (clens_flbytes_slice sz from to) (gaccessor_flbytes_slice' sz from to); gaccessor_flbytes_slice' sz from to inline_for_extraction let accessor_flbytes_slice (sz: nat { sz < 4294967296 } ) (from: U32.t) (to: U32.t {U32.v from <= U32.v to /\ U32.v to <= sz } ) : Tot (accessor (gaccessor_flbytes_slice sz from to)) = fun #rrel #rel input pos -> let h = HST.get () in [@inline_let] let _ = slice_access_eq h (gaccessor_flbytes_slice sz from to) input pos in pos `U32.add` from #pop-options let clens_flbytes_get (sz: nat) (i: U32.t { U32.v i < sz } ) : Tot (clens (BY.lbytes sz) byte) = { clens_cond = (fun _ -> True); clens_get = (fun (x: BY.lbytes sz) -> (BY.get x i <: byte)); } #push-options "--z3rlimit 16 --max_fuel 1" let gaccessor_flbytes_get' (sz: nat { sz < 4294967296 } ) (i: U32.t { U32.v i < sz } ) : Tot (gaccessor' (parse_flbytes sz) (parse_u8) (clens_flbytes_get sz i)) = fun (input: bytes) -> ( begin let res = if Seq.length input < U32.v i then (0) // dummy else (U32.v i) in let g () : Lemma (requires (gaccessor_pre (parse_flbytes sz) parse_u8 (clens_flbytes_get sz i) input)) (ensures (gaccessor_post (parse_flbytes sz) parse_u8 (clens_flbytes_get sz i) input res)) = parser_kind_prop_equiv (get_parser_kind parse_u8) parse_u8; assert (res == (U32.v i)); parse_u8_spec' (Seq.slice input (U32.v i) (U32.v i + 1)); parse_strong_prefix parse_u8 (Seq.slice input (U32.v i) (U32.v i + 1)) (Seq.slice input (U32.v i) (Seq.length input)) in Classical.move_requires g (); res end) #pop-options let gaccessor_flbytes_get (sz: nat { sz < 4294967296 } ) (i: U32.t { U32.v i < sz } ) : Tot (gaccessor (parse_flbytes sz) (parse_u8) (clens_flbytes_get sz i)) = assert (forall x . gaccessor_pre (parse_flbytes sz) (parse_u8) (clens_flbytes_get sz i) x ==> U32.v i <= Seq.length x); gaccessor_prop_equiv (parse_flbytes sz) (parse_u8) (clens_flbytes_get sz i) (gaccessor_flbytes_get' sz i); gaccessor_flbytes_get' sz i inline_for_extraction let accessor_flbytes_get (sz: nat { sz < 4294967296 } ) (i: U32.t { U32.v i < sz } ) : Tot (accessor (gaccessor_flbytes_get sz i)) = fun #rrel #rel input pos -> let h = HST.get () in [@inline_let] let _ = slice_access_eq h (gaccessor_flbytes_get sz i) input pos in pos `U32.add` i (* Temporary: flbytes as leaf values *) (* TODO: convert store_bytes to monotonic buffers, using the "writable" predicate *) #push-options "--z3rlimit 32" inline_for_extraction let store_bytes (src: BY.bytes) (src_from src_to: U32.t) (#rrel #rel: _) (dst: B.mbuffer byte rrel rel) (dst_pos: U32.t) : HST.Stack unit (requires (fun h -> B.live h dst /\ U32.v src_from <= U32.v src_to /\ U32.v src_to <= BY.length src /\ U32.v dst_pos + (U32.v src_to - U32.v src_from) <= B.length dst /\ writable dst (U32.v dst_pos) (U32.v dst_pos + (U32.v src_to - U32.v src_from)) h )) (ensures (fun h _ h' -> B.modifies (B.loc_buffer_from_to dst dst_pos (dst_pos `U32.add` (src_to `U32.sub` src_from))) h h' /\ Seq.slice (B.as_seq h' dst) (U32.v dst_pos) (U32.v dst_pos + (U32.v src_to - U32.v src_from)) == Seq.slice (BY.reveal src) (U32.v src_from) (U32.v src_to) )) = let h0 = HST.get () in HST.push_frame (); let h1 = HST.get () in let bi = BF.alloca 0ul 1ul in let h2 = HST.get () in let len = src_to `U32.sub` src_from in C.Loops.do_while (fun h stop -> B.modifies (B.loc_union (B.loc_region_only true (HS.get_tip h1)) (B.loc_buffer_from_to dst dst_pos (dst_pos `U32.add` len))) h2 h /\ B.live h bi /\ ( let i = Seq.index (B.as_seq h bi) 0 in U32.v i <= U32.v len /\ writable dst (U32.v dst_pos) (U32.v dst_pos + U32.v len) h /\ Seq.slice (B.as_seq h dst) (U32.v dst_pos) (U32.v dst_pos + U32.v i) `Seq.equal` Seq.slice (BY.reveal src) (U32.v src_from) (U32.v src_from + U32.v i) /\ (stop == true ==> i == len) )) (fun _ -> let i = B.index bi 0ul in if i = len then true else begin let x = BY.get src (src_from `U32.add` i) in mbuffer_upd dst (Ghost.hide (U32.v dst_pos)) (Ghost.hide (U32.v dst_pos + U32.v len)) (dst_pos `U32.add` i) x; let i' = i `U32.add` 1ul in B.upd bi 0ul i'; let h' = HST.get () in Seq.lemma_split (Seq.slice (B.as_seq h' dst) (U32.v dst_pos) (U32.v dst_pos + U32.v i')) (U32.v i); i' = len end ) ; HST.pop_frame () #pop-options inline_for_extraction let serialize32_flbytes (sz32: U32.t) : Tot (serializer32 (serialize_flbytes (U32.v sz32))) = fun (x: BY.lbytes (U32.v sz32)) #rrel #rel b pos -> let _ = store_bytes x 0ul sz32 b pos in sz32 inline_for_extraction let write_flbytes (sz32: U32.t) : Tot (leaf_writer_strong (serialize_flbytes (U32.v sz32))) = leaf_writer_strong_of_serializer32 (serialize32_flbytes sz32) () inline_for_extraction let write_flbytes_weak (sz32: U32.t { U32.v sz32 < 4294967295 } ) // need to return that value if output buffer is too small : Tot (leaf_writer_weak (serialize_flbytes (U32.v sz32))) = leaf_writer_weak_of_strong_constant_size (write_flbytes sz32) sz32 () (* // TODO: remove, since nobody is using this inline_for_extraction let read_flbytes (sz32: U32.t) : Tot (leaf_reader (parse_flbytes (U32.v sz32))) = fun input pos -> let h = HST.get () in [@inline_let] let _ = valid_facts (parse_flbytes (U32.v sz32)) h input pos in BY.of_buffer sz32 (B.sub input.base pos sz32) *) (* Equality test between a vlbytes and a constant lbytes *) #push-options "--z3rlimit 32" inline_for_extraction let buffer_equals_bytes (const: BY.bytes) (#rrel #rel: _) (b: B.mbuffer byte rrel rel) (pos: U32.t) : HST.Stack bool (requires (fun h -> B.live h b /\ U32.v pos + BY.length const <= B.length b )) (ensures (fun h res h' -> B.modifies B.loc_none h h' /\ (res == true <==> Seq.slice (B.as_seq h b) (U32.v pos) (U32.v pos + BY.length const) == BY.reveal const) )) = let h0 = HST.get () in HST.push_frame (); let len = BY.len const in let bi = BF.alloca 0ul 1ul in let bres = BF.alloca true 1ul in let h1 = HST.get () in [@inline_let] let inv (h: HS.mem) (stop: bool) : GTot Type0 = B.modifies (B.loc_union (B.loc_buffer bi) (B.loc_buffer bres)) h1 h /\ ( let length = U32.v len in let i32 = (Seq.index (B.as_seq h bi) 0) in let i = U32.v i32 in let res = Seq.index (B.as_seq h bres) 0 in i <= length /\ (stop == false ==> res == true) /\ ((stop == true /\ res == true) ==> i == length) /\ (res == true <==> Seq.slice (B.as_seq h b) (U32.v pos) (U32.v pos + i) `Seq.equal` Seq.slice (BY.reveal const) 0 i) ) in C.Loops.do_while inv (fun _ -> let i = B.index bi 0ul in if i = len then true else begin let i' = i `U32.add` 1ul in [@inline_let] let _ = let s1 = (Seq.slice (B.as_seq h0 b) (U32.v pos) (U32.v pos + U32.v i)) in let c1 = (B.get h0 b (U32.v pos + U32.v i)) in let s2 = (Seq.slice (BY.reveal const) 0 (U32.v i)) in let c2 = (BY.index const (U32.v i)) in assert (Seq.slice (B.as_seq h0 b) (U32.v pos) (U32.v pos + U32.v i') `Seq.equal` Seq.snoc s1 c1); assert (Seq.slice (BY.reveal const) 0 (U32.v i') `Seq.equal` Seq.snoc s2 c2); Classical.move_requires (Seq.lemma_snoc_inj s1 s2 c1) c2 in let res = B.index b (pos `U32.add` i) = BY.get const i in B.upd bres 0ul res; B.upd bi 0ul i'; not res end ); let res = B.index bres 0ul in HST.pop_frame (); res #pop-options inline_for_extraction let valid_slice_equals_bytes (const: BY.bytes) (#rrel #rel: _) (input: slice rrel rel) (pos: U32.t) : HST.Stack bool (requires (fun h -> valid (parse_flbytes (BY.length const)) h input pos )) (ensures (fun h res h' -> B.modifies B.loc_none h h' /\ (res == true <==> contents (parse_flbytes (BY.length const)) h input pos == const ))) = let h = HST.get () in [@inline_let] let _ = valid_facts (parse_flbytes (BY.length const)) h input pos in buffer_equals_bytes const input.base pos inline_for_extraction let validate_all_bytes () : Tot (validator parse_all_bytes) = fun #rrel #rel input pos -> let h = HST.get () in [@inline_let] let _ = valid_facts parse_all_bytes h input (uint64_to_uint32 pos) in Cast.uint32_to_uint64 input.len inline_for_extraction let validate_bounded_vlbytes' (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (l: nat { l >= log256' max /\ l <= 4 } ) : Tot (validator (parse_bounded_vlbytes' min max l)) = validate_synth (validate_bounded_vldata_strong' min max l serialize_all_bytes (validate_all_bytes ())) (synth_bounded_vlbytes min max) () inline_for_extraction let validate_bounded_vlbytes (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) : Tot (validator (parse_bounded_vlbytes min max)) = validate_bounded_vlbytes' min max (log256' max) inline_for_extraction let jump_all_bytes () : Tot (jumper parse_all_bytes) = fun #rrel #rel input pos -> let h = HST.get () in [@inline_let] let _ = valid_facts parse_all_bytes h input pos in input.len inline_for_extraction let jump_bounded_vlbytes' (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (l: nat { l >= log256' max /\ l <= 4 } ) : Tot (jumper (parse_bounded_vlbytes' min max l)) = jump_synth (jump_bounded_vldata_strong' min max l serialize_all_bytes) (synth_bounded_vlbytes min max) () inline_for_extraction let jump_bounded_vlbytes (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) : Tot (jumper (parse_bounded_vlbytes min max)) = jump_bounded_vlbytes' min max (log256' max) let valid_exact_all_bytes_elim (h: HS.mem) (#rrel #rel: _) (input: slice rrel rel) (pos pos' : U32.t) : Lemma (requires (valid_exact parse_all_bytes h input pos pos')) (ensures ( let x = contents_exact parse_all_bytes h input pos pos' in let length = U32.v pos' - U32.v pos in BY.length x == length /\ valid_content_pos (parse_flbytes length) h input pos x pos' )) = valid_exact_equiv parse_all_bytes h input pos pos' ; contents_exact_eq parse_all_bytes h input pos pos' ; let length = U32.v pos' - U32.v pos in valid_facts (parse_flbytes length) h input pos ; assert (no_lookahead_on (parse_flbytes length) (bytes_of_slice_from_to h input pos pos') (bytes_of_slice_from h input pos)); assert (injective_postcond (parse_flbytes length) (bytes_of_slice_from_to h input pos pos') (bytes_of_slice_from h input pos)) #push-options "--z3rlimit 32" let valid_bounded_vlbytes'_elim (h: HS.mem) (min: nat) (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (l: nat { l >= log256' max /\ l <= 4 } ) (#rrel #rel: _) (input: slice rrel rel) (pos: U32.t) : Lemma (requires ( valid (parse_bounded_vlbytes' min max l) h input pos )) (ensures ( let sz = l in valid (parse_bounded_integer sz) h input pos /\ ( let len_payload = contents (parse_bounded_integer sz) h input pos in min <= U32.v len_payload /\ U32.v len_payload <= max /\ sz + U32.v len_payload == content_length (parse_bounded_vlbytes' min max l) h input pos /\ ( let pos_payload = pos `U32.add` U32.uint_to_t sz in let x = contents (parse_bounded_vlbytes' min max l) h input pos in BY.len x == len_payload /\ valid_pos (parse_bounded_vlbytes' min max l) h input pos (pos_payload `U32.add` len_payload) /\ valid_content_pos (parse_flbytes (U32.v len_payload)) h input pos_payload x (pos_payload `U32.add` len_payload) )))) = valid_synth h (parse_bounded_vlbytes_aux min max l) (synth_bounded_vlbytes min max) input pos; valid_bounded_vldata_strong'_elim h min max l serialize_all_bytes input pos; let sz = l in let len_payload = contents (parse_bounded_integer sz) h input pos in let pos_payload = pos `U32.add` U32.uint_to_t sz in valid_exact_all_bytes_elim h input pos_payload (pos_payload `U32.add` len_payload); () #pop-options let valid_bounded_vlbytes_elim (h: HS.mem) (min: nat) (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (#rrel #rel: _) (input: slice rrel rel) (pos: U32.t) : Lemma (requires ( valid (parse_bounded_vlbytes min max) h input pos )) (ensures ( let sz = log256' max in valid (parse_bounded_integer sz) h input pos /\ ( let len_payload = contents (parse_bounded_integer sz) h input pos in min <= U32.v len_payload /\ U32.v len_payload <= max /\ sz + U32.v len_payload == content_length (parse_bounded_vlbytes min max) h input pos /\ ( let pos_payload = pos `U32.add` U32.uint_to_t sz in let x = contents (parse_bounded_vlbytes min max) h input pos in BY.len x == len_payload /\ valid_pos (parse_bounded_vlbytes min max) h input pos (pos_payload `U32.add` len_payload) /\ valid_content_pos (parse_flbytes (U32.v len_payload)) h input pos_payload x (pos_payload `U32.add` len_payload) )))) = valid_bounded_vlbytes'_elim h min max (log256' max) input pos let valid_bounded_vlbytes_elim_length (h: HS.mem) (min: nat) (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (#rrel #rel: _) (input: slice rrel rel) (pos: U32.t) : Lemma (requires ( valid (parse_bounded_vlbytes min max) h input pos )) (ensures ( content_length (parse_bounded_vlbytes min max) h input pos == log256' max + BY.length (contents (parse_bounded_vlbytes min max) h input pos) )) [SMTPat (valid (parse_bounded_vlbytes min max) h input pos)] = valid_bounded_vlbytes_elim h min max input pos inline_for_extraction let bounded_vlbytes'_payload_length (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (l: nat { l >= log256' max /\ l <= 4 } ) (#rrel #rel: _) (input: slice rrel rel) (pos: U32.t) : HST.Stack U32.t (requires (fun h -> valid (parse_bounded_vlbytes' min max l) h input pos)) (ensures (fun h len h' -> B.modifies B.loc_none h h' /\ U32.v pos + l + U32.v len <= U32.v input.len /\ ( let x = contents (parse_bounded_vlbytes' min max l) h input pos in let pos' = get_valid_pos (parse_bounded_vlbytes' min max l) h input pos in BY.len x == len /\ valid_content_pos (parse_flbytes (U32.v len)) h input (pos `U32.add` U32.uint_to_t l) x pos' /\ bytes_of_slice_from_to h input (pos `U32.add` U32.uint_to_t l) pos' == BY.reveal x ))) = let h = HST.get () in [@inline_let] let _ = valid_bounded_vlbytes'_elim h min max l input pos in let len = read_bounded_integer l input pos in [@inline_let] let _ = valid_flbytes_elim h (U32.v len) input (pos `U32.add` U32.uint_to_t l) in len inline_for_extraction let bounded_vlbytes_payload_length (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (#rrel #rel: _) (input: slice rrel rel) (pos: U32.t) : HST.Stack U32.t (requires (fun h -> valid (parse_bounded_vlbytes min max) h input pos)) (ensures (fun h len h' -> B.modifies B.loc_none h h' /\ U32.v pos + log256' max + U32.v len <= U32.v input.len /\ ( let x = contents (parse_bounded_vlbytes min max) h input pos in let pos' = get_valid_pos (parse_bounded_vlbytes min max) h input pos in BY.len x == len /\ valid_content_pos (parse_flbytes (U32.v len)) h input (pos `U32.add` U32.uint_to_t (log256' max)) x pos' /\ bytes_of_slice_from_to h input (pos `U32.add` U32.uint_to_t (log256' max)) pos' == BY.reveal x ))) = bounded_vlbytes'_payload_length min max (log256' max) input pos (* Get the content buffer (with trivial buffers only, not generalizable to monotonicity) *) #push-options "--z3rlimit 32" inline_for_extraction let get_vlbytes'_contents (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (l: nat { l >= log256' max /\ l <= 4 } ) (input: slice (srel_of_buffer_srel (BF.trivial_preorder _)) (srel_of_buffer_srel (BF.trivial_preorder _))) (pos: U32.t) : HST.Stack (BF.buffer byte) (requires (fun h -> valid (parse_bounded_vlbytes' min max l) h input pos)) (ensures (fun h b h' -> let x = contents (parse_bounded_vlbytes' min max l) h input pos in B.modifies B.loc_none h h' /\ U32.v pos + l + BY.length x <= U32.v input.len /\ b == BF.gsub input.base (pos `U32.add` U32.uint_to_t l) (BY.len x) /\ B.as_seq h b == BY.reveal x )) = let h = HST.get () in [@inline_let] let _ = valid_bounded_vlbytes'_elim h min max l input pos in let len = read_bounded_integer l input pos in [@inline_let] let _ = valid_facts (parse_flbytes (U32.v len)) h input (pos `U32.add` U32.uint_to_t l) in BF.sub input.base (pos `U32.add` U32.uint_to_t l) len #pop-options inline_for_extraction let get_vlbytes_contents (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (input: slice (srel_of_buffer_srel (BF.trivial_preorder _)) (srel_of_buffer_srel (BF.trivial_preorder _))) (pos: U32.t) : HST.Stack (BF.buffer byte) (requires (fun h -> valid (parse_bounded_vlbytes min max) h input pos)) (ensures (fun h b h' -> let l = log256' max in let x = contents (parse_bounded_vlbytes min max) h input pos in B.modifies B.loc_none h h' /\ U32.v pos + l + BY.length x <= U32.v input.len /\ b == BF.gsub input.base (pos `U32.add` U32.uint_to_t l) (BY.len x) /\ B.as_seq h b == BY.reveal x )) = get_vlbytes'_contents min max (log256' max) input pos (* In fact, the following accessors are not useful in practice, because users would need to have the flbytes parser combinator in their scope *)
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowStar.Monotonic.Buffer.fsti.checked", "LowStar.Buffer.fst.checked", "LowParse.Spec.Bytes.fst.checked", "LowParse.Low.VLGen.fst.checked", "LowParse.Low.VLData.fst.checked", "LowParse.Low.Int.fsti.checked", "LowParse.Low.Combinators.fsti.checked", "LowParse.Bytes32.fst.checked", "FStar.UInt8.fsti.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Int.Cast.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked", "FStar.Classical.fsti.checked", "C.Loops.fst.checked" ], "interface_file": false, "source_file": "LowParse.Low.Bytes.fst" }
[ { "abbrev": true, "full_module": "LowStar.Buffer // for local variables in store_bytes", "short_module": "BF" }, { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "FStar.Int.Cast", "short_module": "Cast" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "LowParse.Bytes32", "short_module": "BY" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "BF" }, { "abbrev": true, "full_module": "LowStar.Monotonic.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": false, "full_module": "LowParse.Low.Int", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low.VLGen", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low.VLData", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low.Combinators", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec.Bytes", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
min: Prims.nat -> max: Prims.nat{min <= max /\ max > 0 /\ max < 4294967296} -> length: Prims.nat -> x: LowParse.Spec.Bytes.parse_bounded_vlbytes_t min max -> Prims.GTot Type0
Prims.GTot
[ "sometrivial" ]
[]
[ "Prims.nat", "Prims.l_and", "Prims.b2t", "Prims.op_LessThanOrEqual", "Prims.op_GreaterThan", "Prims.op_LessThan", "LowParse.Spec.Bytes.parse_bounded_vlbytes_t", "Prims.eq2", "Prims.int", "Prims.l_or", "FStar.UInt.size", "Prims.op_GreaterThanOrEqual", "FStar.Bytes.length" ]
[]
false
false
false
false
true
let clens_vlbytes_cond (min: nat) (max: nat{min <= max /\ max > 0 /\ max < 4294967296}) (length: nat) (x: parse_bounded_vlbytes_t min max) : GTot Type0 =
BY.length x == length
false
LowParse.Low.Bytes.fst
LowParse.Low.Bytes.validate_bounded_vlbytes'
val validate_bounded_vlbytes' (min: nat) (max: nat{min <= max /\ max > 0 /\ max < 4294967296}) (l: nat{l >= log256' max /\ l <= 4}) : Tot (validator (parse_bounded_vlbytes' min max l))
val validate_bounded_vlbytes' (min: nat) (max: nat{min <= max /\ max > 0 /\ max < 4294967296}) (l: nat{l >= log256' max /\ l <= 4}) : Tot (validator (parse_bounded_vlbytes' min max l))
let validate_bounded_vlbytes' (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (l: nat { l >= log256' max /\ l <= 4 } ) : Tot (validator (parse_bounded_vlbytes' min max l)) = validate_synth (validate_bounded_vldata_strong' min max l serialize_all_bytes (validate_all_bytes ())) (synth_bounded_vlbytes min max) ()
{ "file_name": "src/lowparse/LowParse.Low.Bytes.fst", "git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
{ "end_col": 6, "end_line": 362, "start_col": 0, "start_line": 354 }
module LowParse.Low.Bytes include LowParse.Spec.Bytes include LowParse.Low.Combinators include LowParse.Low.VLData include LowParse.Low.VLGen include LowParse.Low.Int module U32 = FStar.UInt32 module HS = FStar.HyperStack module B = LowStar.Monotonic.Buffer module BF = LowStar.Buffer // for local variables in store_bytes module BY = LowParse.Bytes32 module HST = FStar.HyperStack.ST module U8 = FStar.UInt8 module Cast = FStar.Int.Cast module U64 = FStar.UInt64 inline_for_extraction let validate_flbytes (sz: nat) (sz64: U64.t { U64.v sz64 == sz /\ sz < 4294967296 } ) : Tot (validator (parse_flbytes sz)) = validate_total_constant_size (parse_flbytes sz) sz64 () inline_for_extraction let jump_flbytes (sz: nat) (sz32: U32.t { U32.v sz32 == sz } ) : Tot (jumper (parse_flbytes sz)) = jump_constant_size (parse_flbytes sz) sz32 () let valid_flbytes_intro (h: HS.mem) (sz: nat { sz < 4294967296 } ) (#rrel #rel: _) (s: slice rrel rel) (pos: U32.t) : Lemma (requires (U32.v pos + sz <= U32.v s.len /\ live_slice h s)) (ensures ( valid_content_pos (parse_flbytes sz) h s pos (BY.hide (bytes_of_slice_from_to h s pos (pos `U32.add` U32.uint_to_t sz))) (pos `U32.add` U32.uint_to_t sz) )) = valid_facts (parse_flbytes sz) h s pos let valid_pos_flbytes_elim (h: HS.mem) (sz: nat { sz < 4294967296 } ) (#rrel #rel: _) (s: slice rrel rel) (pos pos' : U32.t) : Lemma (requires (valid_pos (parse_flbytes sz) h s pos pos')) (ensures (U32.v pos + sz == U32.v pos')) [SMTPat (valid_pos (parse_flbytes sz) h s pos pos')] = valid_facts (parse_flbytes sz) h s pos let valid_flbytes_elim (h: HS.mem) (sz: nat { sz < 4294967296 } ) (#rrel #rel: _) (s: slice rrel rel) (pos: U32.t) : Lemma (requires (valid (parse_flbytes sz) h s pos)) (ensures ( valid_content_pos (parse_flbytes sz) h s pos (BY.hide (bytes_of_slice_from_to h s pos (pos `U32.add` U32.uint_to_t sz))) (pos `U32.add` U32.uint_to_t sz) )) = valid_flbytes_intro h sz s pos let clens_flbytes_slice (sz: nat) (from: U32.t) (to: U32.t {U32.v from <= U32.v to /\ U32.v to <= sz } ) : Tot (clens (BY.lbytes sz) (BY.lbytes (U32.v to - U32.v from))) = { clens_cond = (fun _ -> True); clens_get = (fun (x: BY.lbytes sz) -> (BY.slice x from to <: BY.lbytes (U32.v to - U32.v from))); } #push-options "--z3rlimit 16" let gaccessor_flbytes_slice' (sz: nat { sz < 4294967296 } ) (from: U32.t) (to: U32.t {U32.v from <= U32.v to /\ U32.v to <= sz } ) : Tot (gaccessor' (parse_flbytes sz) (parse_flbytes (U32.v to - U32.v from)) (clens_flbytes_slice sz from to)) = fun (input: bytes) -> ( begin if Seq.length input < sz then (0) // dummy else (U32.v from) end) let gaccessor_flbytes_slice (sz: nat { sz < 4294967296 } ) (from: U32.t) (to: U32.t {U32.v from <= U32.v to /\ U32.v to <= sz } ) : Tot (gaccessor (parse_flbytes sz) (parse_flbytes (U32.v to - U32.v from)) (clens_flbytes_slice sz from to)) = assert (forall x . gaccessor_pre (parse_flbytes sz) (parse_flbytes (U32.v to - U32.v from)) (clens_flbytes_slice sz from to) x ==> sz <= Seq.length x); gaccessor_prop_equiv (parse_flbytes sz) (parse_flbytes (U32.v to - U32.v from)) (clens_flbytes_slice sz from to) (gaccessor_flbytes_slice' sz from to); gaccessor_flbytes_slice' sz from to inline_for_extraction let accessor_flbytes_slice (sz: nat { sz < 4294967296 } ) (from: U32.t) (to: U32.t {U32.v from <= U32.v to /\ U32.v to <= sz } ) : Tot (accessor (gaccessor_flbytes_slice sz from to)) = fun #rrel #rel input pos -> let h = HST.get () in [@inline_let] let _ = slice_access_eq h (gaccessor_flbytes_slice sz from to) input pos in pos `U32.add` from #pop-options let clens_flbytes_get (sz: nat) (i: U32.t { U32.v i < sz } ) : Tot (clens (BY.lbytes sz) byte) = { clens_cond = (fun _ -> True); clens_get = (fun (x: BY.lbytes sz) -> (BY.get x i <: byte)); } #push-options "--z3rlimit 16 --max_fuel 1" let gaccessor_flbytes_get' (sz: nat { sz < 4294967296 } ) (i: U32.t { U32.v i < sz } ) : Tot (gaccessor' (parse_flbytes sz) (parse_u8) (clens_flbytes_get sz i)) = fun (input: bytes) -> ( begin let res = if Seq.length input < U32.v i then (0) // dummy else (U32.v i) in let g () : Lemma (requires (gaccessor_pre (parse_flbytes sz) parse_u8 (clens_flbytes_get sz i) input)) (ensures (gaccessor_post (parse_flbytes sz) parse_u8 (clens_flbytes_get sz i) input res)) = parser_kind_prop_equiv (get_parser_kind parse_u8) parse_u8; assert (res == (U32.v i)); parse_u8_spec' (Seq.slice input (U32.v i) (U32.v i + 1)); parse_strong_prefix parse_u8 (Seq.slice input (U32.v i) (U32.v i + 1)) (Seq.slice input (U32.v i) (Seq.length input)) in Classical.move_requires g (); res end) #pop-options let gaccessor_flbytes_get (sz: nat { sz < 4294967296 } ) (i: U32.t { U32.v i < sz } ) : Tot (gaccessor (parse_flbytes sz) (parse_u8) (clens_flbytes_get sz i)) = assert (forall x . gaccessor_pre (parse_flbytes sz) (parse_u8) (clens_flbytes_get sz i) x ==> U32.v i <= Seq.length x); gaccessor_prop_equiv (parse_flbytes sz) (parse_u8) (clens_flbytes_get sz i) (gaccessor_flbytes_get' sz i); gaccessor_flbytes_get' sz i inline_for_extraction let accessor_flbytes_get (sz: nat { sz < 4294967296 } ) (i: U32.t { U32.v i < sz } ) : Tot (accessor (gaccessor_flbytes_get sz i)) = fun #rrel #rel input pos -> let h = HST.get () in [@inline_let] let _ = slice_access_eq h (gaccessor_flbytes_get sz i) input pos in pos `U32.add` i (* Temporary: flbytes as leaf values *) (* TODO: convert store_bytes to monotonic buffers, using the "writable" predicate *) #push-options "--z3rlimit 32" inline_for_extraction let store_bytes (src: BY.bytes) (src_from src_to: U32.t) (#rrel #rel: _) (dst: B.mbuffer byte rrel rel) (dst_pos: U32.t) : HST.Stack unit (requires (fun h -> B.live h dst /\ U32.v src_from <= U32.v src_to /\ U32.v src_to <= BY.length src /\ U32.v dst_pos + (U32.v src_to - U32.v src_from) <= B.length dst /\ writable dst (U32.v dst_pos) (U32.v dst_pos + (U32.v src_to - U32.v src_from)) h )) (ensures (fun h _ h' -> B.modifies (B.loc_buffer_from_to dst dst_pos (dst_pos `U32.add` (src_to `U32.sub` src_from))) h h' /\ Seq.slice (B.as_seq h' dst) (U32.v dst_pos) (U32.v dst_pos + (U32.v src_to - U32.v src_from)) == Seq.slice (BY.reveal src) (U32.v src_from) (U32.v src_to) )) = let h0 = HST.get () in HST.push_frame (); let h1 = HST.get () in let bi = BF.alloca 0ul 1ul in let h2 = HST.get () in let len = src_to `U32.sub` src_from in C.Loops.do_while (fun h stop -> B.modifies (B.loc_union (B.loc_region_only true (HS.get_tip h1)) (B.loc_buffer_from_to dst dst_pos (dst_pos `U32.add` len))) h2 h /\ B.live h bi /\ ( let i = Seq.index (B.as_seq h bi) 0 in U32.v i <= U32.v len /\ writable dst (U32.v dst_pos) (U32.v dst_pos + U32.v len) h /\ Seq.slice (B.as_seq h dst) (U32.v dst_pos) (U32.v dst_pos + U32.v i) `Seq.equal` Seq.slice (BY.reveal src) (U32.v src_from) (U32.v src_from + U32.v i) /\ (stop == true ==> i == len) )) (fun _ -> let i = B.index bi 0ul in if i = len then true else begin let x = BY.get src (src_from `U32.add` i) in mbuffer_upd dst (Ghost.hide (U32.v dst_pos)) (Ghost.hide (U32.v dst_pos + U32.v len)) (dst_pos `U32.add` i) x; let i' = i `U32.add` 1ul in B.upd bi 0ul i'; let h' = HST.get () in Seq.lemma_split (Seq.slice (B.as_seq h' dst) (U32.v dst_pos) (U32.v dst_pos + U32.v i')) (U32.v i); i' = len end ) ; HST.pop_frame () #pop-options inline_for_extraction let serialize32_flbytes (sz32: U32.t) : Tot (serializer32 (serialize_flbytes (U32.v sz32))) = fun (x: BY.lbytes (U32.v sz32)) #rrel #rel b pos -> let _ = store_bytes x 0ul sz32 b pos in sz32 inline_for_extraction let write_flbytes (sz32: U32.t) : Tot (leaf_writer_strong (serialize_flbytes (U32.v sz32))) = leaf_writer_strong_of_serializer32 (serialize32_flbytes sz32) () inline_for_extraction let write_flbytes_weak (sz32: U32.t { U32.v sz32 < 4294967295 } ) // need to return that value if output buffer is too small : Tot (leaf_writer_weak (serialize_flbytes (U32.v sz32))) = leaf_writer_weak_of_strong_constant_size (write_flbytes sz32) sz32 () (* // TODO: remove, since nobody is using this inline_for_extraction let read_flbytes (sz32: U32.t) : Tot (leaf_reader (parse_flbytes (U32.v sz32))) = fun input pos -> let h = HST.get () in [@inline_let] let _ = valid_facts (parse_flbytes (U32.v sz32)) h input pos in BY.of_buffer sz32 (B.sub input.base pos sz32) *) (* Equality test between a vlbytes and a constant lbytes *) #push-options "--z3rlimit 32" inline_for_extraction let buffer_equals_bytes (const: BY.bytes) (#rrel #rel: _) (b: B.mbuffer byte rrel rel) (pos: U32.t) : HST.Stack bool (requires (fun h -> B.live h b /\ U32.v pos + BY.length const <= B.length b )) (ensures (fun h res h' -> B.modifies B.loc_none h h' /\ (res == true <==> Seq.slice (B.as_seq h b) (U32.v pos) (U32.v pos + BY.length const) == BY.reveal const) )) = let h0 = HST.get () in HST.push_frame (); let len = BY.len const in let bi = BF.alloca 0ul 1ul in let bres = BF.alloca true 1ul in let h1 = HST.get () in [@inline_let] let inv (h: HS.mem) (stop: bool) : GTot Type0 = B.modifies (B.loc_union (B.loc_buffer bi) (B.loc_buffer bres)) h1 h /\ ( let length = U32.v len in let i32 = (Seq.index (B.as_seq h bi) 0) in let i = U32.v i32 in let res = Seq.index (B.as_seq h bres) 0 in i <= length /\ (stop == false ==> res == true) /\ ((stop == true /\ res == true) ==> i == length) /\ (res == true <==> Seq.slice (B.as_seq h b) (U32.v pos) (U32.v pos + i) `Seq.equal` Seq.slice (BY.reveal const) 0 i) ) in C.Loops.do_while inv (fun _ -> let i = B.index bi 0ul in if i = len then true else begin let i' = i `U32.add` 1ul in [@inline_let] let _ = let s1 = (Seq.slice (B.as_seq h0 b) (U32.v pos) (U32.v pos + U32.v i)) in let c1 = (B.get h0 b (U32.v pos + U32.v i)) in let s2 = (Seq.slice (BY.reveal const) 0 (U32.v i)) in let c2 = (BY.index const (U32.v i)) in assert (Seq.slice (B.as_seq h0 b) (U32.v pos) (U32.v pos + U32.v i') `Seq.equal` Seq.snoc s1 c1); assert (Seq.slice (BY.reveal const) 0 (U32.v i') `Seq.equal` Seq.snoc s2 c2); Classical.move_requires (Seq.lemma_snoc_inj s1 s2 c1) c2 in let res = B.index b (pos `U32.add` i) = BY.get const i in B.upd bres 0ul res; B.upd bi 0ul i'; not res end ); let res = B.index bres 0ul in HST.pop_frame (); res #pop-options inline_for_extraction let valid_slice_equals_bytes (const: BY.bytes) (#rrel #rel: _) (input: slice rrel rel) (pos: U32.t) : HST.Stack bool (requires (fun h -> valid (parse_flbytes (BY.length const)) h input pos )) (ensures (fun h res h' -> B.modifies B.loc_none h h' /\ (res == true <==> contents (parse_flbytes (BY.length const)) h input pos == const ))) = let h = HST.get () in [@inline_let] let _ = valid_facts (parse_flbytes (BY.length const)) h input pos in buffer_equals_bytes const input.base pos inline_for_extraction let validate_all_bytes () : Tot (validator parse_all_bytes) = fun #rrel #rel input pos -> let h = HST.get () in [@inline_let] let _ = valid_facts parse_all_bytes h input (uint64_to_uint32 pos) in Cast.uint32_to_uint64 input.len
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowStar.Monotonic.Buffer.fsti.checked", "LowStar.Buffer.fst.checked", "LowParse.Spec.Bytes.fst.checked", "LowParse.Low.VLGen.fst.checked", "LowParse.Low.VLData.fst.checked", "LowParse.Low.Int.fsti.checked", "LowParse.Low.Combinators.fsti.checked", "LowParse.Bytes32.fst.checked", "FStar.UInt8.fsti.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Int.Cast.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked", "FStar.Classical.fsti.checked", "C.Loops.fst.checked" ], "interface_file": false, "source_file": "LowParse.Low.Bytes.fst" }
[ { "abbrev": true, "full_module": "LowStar.Buffer // for local variables in store_bytes", "short_module": "BF" }, { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "FStar.Int.Cast", "short_module": "Cast" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "LowParse.Bytes32", "short_module": "BY" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "BF" }, { "abbrev": true, "full_module": "LowStar.Monotonic.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": false, "full_module": "LowParse.Low.Int", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low.VLGen", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low.VLData", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low.Combinators", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec.Bytes", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
min: Prims.nat -> max: Prims.nat{min <= max /\ max > 0 /\ max < 4294967296} -> l: Prims.nat{l >= LowParse.Spec.BoundedInt.log256' max /\ l <= 4} -> LowParse.Low.Base.validator (LowParse.Spec.Bytes.parse_bounded_vlbytes' min max l)
Prims.Tot
[ "total" ]
[]
[ "Prims.nat", "Prims.l_and", "Prims.b2t", "Prims.op_LessThanOrEqual", "Prims.op_GreaterThan", "Prims.op_LessThan", "Prims.op_GreaterThanOrEqual", "LowParse.Spec.BoundedInt.log256'", "LowParse.Low.Combinators.validate_synth", "LowParse.Spec.VLData.parse_bounded_vldata_strong_kind", "LowParse.Spec.Bytes.parse_all_bytes_kind", "LowParse.Spec.VLData.parse_bounded_vldata_strong_t", "FStar.Bytes.bytes", "LowParse.Spec.Bytes.parse_all_bytes", "LowParse.Spec.Bytes.serialize_all_bytes", "LowParse.Spec.Bytes.parse_bounded_vlbytes_t", "LowParse.Spec.VLData.parse_bounded_vldata_strong'", "LowParse.Low.VLData.validate_bounded_vldata_strong'", "LowParse.Low.Bytes.validate_all_bytes", "LowParse.Spec.Bytes.synth_bounded_vlbytes", "LowParse.Low.Base.validator", "LowParse.Spec.Bytes.parse_bounded_vlbytes'" ]
[]
false
false
false
false
false
let validate_bounded_vlbytes' (min: nat) (max: nat{min <= max /\ max > 0 /\ max < 4294967296}) (l: nat{l >= log256' max /\ l <= 4}) : Tot (validator (parse_bounded_vlbytes' min max l)) =
validate_synth (validate_bounded_vldata_strong' min max l serialize_all_bytes (validate_all_bytes ())) (synth_bounded_vlbytes min max) ()
false
LowParse.Low.Bytes.fst
LowParse.Low.Bytes.jump_all_bytes
val jump_all_bytes: Prims.unit -> Tot (jumper parse_all_bytes)
val jump_all_bytes: Prims.unit -> Tot (jumper parse_all_bytes)
let jump_all_bytes () : Tot (jumper parse_all_bytes) = fun #rrel #rel input pos -> let h = HST.get () in [@inline_let] let _ = valid_facts parse_all_bytes h input pos in input.len
{ "file_name": "src/lowparse/LowParse.Low.Bytes.fst", "git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
{ "end_col": 11, "end_line": 378, "start_col": 0, "start_line": 372 }
module LowParse.Low.Bytes include LowParse.Spec.Bytes include LowParse.Low.Combinators include LowParse.Low.VLData include LowParse.Low.VLGen include LowParse.Low.Int module U32 = FStar.UInt32 module HS = FStar.HyperStack module B = LowStar.Monotonic.Buffer module BF = LowStar.Buffer // for local variables in store_bytes module BY = LowParse.Bytes32 module HST = FStar.HyperStack.ST module U8 = FStar.UInt8 module Cast = FStar.Int.Cast module U64 = FStar.UInt64 inline_for_extraction let validate_flbytes (sz: nat) (sz64: U64.t { U64.v sz64 == sz /\ sz < 4294967296 } ) : Tot (validator (parse_flbytes sz)) = validate_total_constant_size (parse_flbytes sz) sz64 () inline_for_extraction let jump_flbytes (sz: nat) (sz32: U32.t { U32.v sz32 == sz } ) : Tot (jumper (parse_flbytes sz)) = jump_constant_size (parse_flbytes sz) sz32 () let valid_flbytes_intro (h: HS.mem) (sz: nat { sz < 4294967296 } ) (#rrel #rel: _) (s: slice rrel rel) (pos: U32.t) : Lemma (requires (U32.v pos + sz <= U32.v s.len /\ live_slice h s)) (ensures ( valid_content_pos (parse_flbytes sz) h s pos (BY.hide (bytes_of_slice_from_to h s pos (pos `U32.add` U32.uint_to_t sz))) (pos `U32.add` U32.uint_to_t sz) )) = valid_facts (parse_flbytes sz) h s pos let valid_pos_flbytes_elim (h: HS.mem) (sz: nat { sz < 4294967296 } ) (#rrel #rel: _) (s: slice rrel rel) (pos pos' : U32.t) : Lemma (requires (valid_pos (parse_flbytes sz) h s pos pos')) (ensures (U32.v pos + sz == U32.v pos')) [SMTPat (valid_pos (parse_flbytes sz) h s pos pos')] = valid_facts (parse_flbytes sz) h s pos let valid_flbytes_elim (h: HS.mem) (sz: nat { sz < 4294967296 } ) (#rrel #rel: _) (s: slice rrel rel) (pos: U32.t) : Lemma (requires (valid (parse_flbytes sz) h s pos)) (ensures ( valid_content_pos (parse_flbytes sz) h s pos (BY.hide (bytes_of_slice_from_to h s pos (pos `U32.add` U32.uint_to_t sz))) (pos `U32.add` U32.uint_to_t sz) )) = valid_flbytes_intro h sz s pos let clens_flbytes_slice (sz: nat) (from: U32.t) (to: U32.t {U32.v from <= U32.v to /\ U32.v to <= sz } ) : Tot (clens (BY.lbytes sz) (BY.lbytes (U32.v to - U32.v from))) = { clens_cond = (fun _ -> True); clens_get = (fun (x: BY.lbytes sz) -> (BY.slice x from to <: BY.lbytes (U32.v to - U32.v from))); } #push-options "--z3rlimit 16" let gaccessor_flbytes_slice' (sz: nat { sz < 4294967296 } ) (from: U32.t) (to: U32.t {U32.v from <= U32.v to /\ U32.v to <= sz } ) : Tot (gaccessor' (parse_flbytes sz) (parse_flbytes (U32.v to - U32.v from)) (clens_flbytes_slice sz from to)) = fun (input: bytes) -> ( begin if Seq.length input < sz then (0) // dummy else (U32.v from) end) let gaccessor_flbytes_slice (sz: nat { sz < 4294967296 } ) (from: U32.t) (to: U32.t {U32.v from <= U32.v to /\ U32.v to <= sz } ) : Tot (gaccessor (parse_flbytes sz) (parse_flbytes (U32.v to - U32.v from)) (clens_flbytes_slice sz from to)) = assert (forall x . gaccessor_pre (parse_flbytes sz) (parse_flbytes (U32.v to - U32.v from)) (clens_flbytes_slice sz from to) x ==> sz <= Seq.length x); gaccessor_prop_equiv (parse_flbytes sz) (parse_flbytes (U32.v to - U32.v from)) (clens_flbytes_slice sz from to) (gaccessor_flbytes_slice' sz from to); gaccessor_flbytes_slice' sz from to inline_for_extraction let accessor_flbytes_slice (sz: nat { sz < 4294967296 } ) (from: U32.t) (to: U32.t {U32.v from <= U32.v to /\ U32.v to <= sz } ) : Tot (accessor (gaccessor_flbytes_slice sz from to)) = fun #rrel #rel input pos -> let h = HST.get () in [@inline_let] let _ = slice_access_eq h (gaccessor_flbytes_slice sz from to) input pos in pos `U32.add` from #pop-options let clens_flbytes_get (sz: nat) (i: U32.t { U32.v i < sz } ) : Tot (clens (BY.lbytes sz) byte) = { clens_cond = (fun _ -> True); clens_get = (fun (x: BY.lbytes sz) -> (BY.get x i <: byte)); } #push-options "--z3rlimit 16 --max_fuel 1" let gaccessor_flbytes_get' (sz: nat { sz < 4294967296 } ) (i: U32.t { U32.v i < sz } ) : Tot (gaccessor' (parse_flbytes sz) (parse_u8) (clens_flbytes_get sz i)) = fun (input: bytes) -> ( begin let res = if Seq.length input < U32.v i then (0) // dummy else (U32.v i) in let g () : Lemma (requires (gaccessor_pre (parse_flbytes sz) parse_u8 (clens_flbytes_get sz i) input)) (ensures (gaccessor_post (parse_flbytes sz) parse_u8 (clens_flbytes_get sz i) input res)) = parser_kind_prop_equiv (get_parser_kind parse_u8) parse_u8; assert (res == (U32.v i)); parse_u8_spec' (Seq.slice input (U32.v i) (U32.v i + 1)); parse_strong_prefix parse_u8 (Seq.slice input (U32.v i) (U32.v i + 1)) (Seq.slice input (U32.v i) (Seq.length input)) in Classical.move_requires g (); res end) #pop-options let gaccessor_flbytes_get (sz: nat { sz < 4294967296 } ) (i: U32.t { U32.v i < sz } ) : Tot (gaccessor (parse_flbytes sz) (parse_u8) (clens_flbytes_get sz i)) = assert (forall x . gaccessor_pre (parse_flbytes sz) (parse_u8) (clens_flbytes_get sz i) x ==> U32.v i <= Seq.length x); gaccessor_prop_equiv (parse_flbytes sz) (parse_u8) (clens_flbytes_get sz i) (gaccessor_flbytes_get' sz i); gaccessor_flbytes_get' sz i inline_for_extraction let accessor_flbytes_get (sz: nat { sz < 4294967296 } ) (i: U32.t { U32.v i < sz } ) : Tot (accessor (gaccessor_flbytes_get sz i)) = fun #rrel #rel input pos -> let h = HST.get () in [@inline_let] let _ = slice_access_eq h (gaccessor_flbytes_get sz i) input pos in pos `U32.add` i (* Temporary: flbytes as leaf values *) (* TODO: convert store_bytes to monotonic buffers, using the "writable" predicate *) #push-options "--z3rlimit 32" inline_for_extraction let store_bytes (src: BY.bytes) (src_from src_to: U32.t) (#rrel #rel: _) (dst: B.mbuffer byte rrel rel) (dst_pos: U32.t) : HST.Stack unit (requires (fun h -> B.live h dst /\ U32.v src_from <= U32.v src_to /\ U32.v src_to <= BY.length src /\ U32.v dst_pos + (U32.v src_to - U32.v src_from) <= B.length dst /\ writable dst (U32.v dst_pos) (U32.v dst_pos + (U32.v src_to - U32.v src_from)) h )) (ensures (fun h _ h' -> B.modifies (B.loc_buffer_from_to dst dst_pos (dst_pos `U32.add` (src_to `U32.sub` src_from))) h h' /\ Seq.slice (B.as_seq h' dst) (U32.v dst_pos) (U32.v dst_pos + (U32.v src_to - U32.v src_from)) == Seq.slice (BY.reveal src) (U32.v src_from) (U32.v src_to) )) = let h0 = HST.get () in HST.push_frame (); let h1 = HST.get () in let bi = BF.alloca 0ul 1ul in let h2 = HST.get () in let len = src_to `U32.sub` src_from in C.Loops.do_while (fun h stop -> B.modifies (B.loc_union (B.loc_region_only true (HS.get_tip h1)) (B.loc_buffer_from_to dst dst_pos (dst_pos `U32.add` len))) h2 h /\ B.live h bi /\ ( let i = Seq.index (B.as_seq h bi) 0 in U32.v i <= U32.v len /\ writable dst (U32.v dst_pos) (U32.v dst_pos + U32.v len) h /\ Seq.slice (B.as_seq h dst) (U32.v dst_pos) (U32.v dst_pos + U32.v i) `Seq.equal` Seq.slice (BY.reveal src) (U32.v src_from) (U32.v src_from + U32.v i) /\ (stop == true ==> i == len) )) (fun _ -> let i = B.index bi 0ul in if i = len then true else begin let x = BY.get src (src_from `U32.add` i) in mbuffer_upd dst (Ghost.hide (U32.v dst_pos)) (Ghost.hide (U32.v dst_pos + U32.v len)) (dst_pos `U32.add` i) x; let i' = i `U32.add` 1ul in B.upd bi 0ul i'; let h' = HST.get () in Seq.lemma_split (Seq.slice (B.as_seq h' dst) (U32.v dst_pos) (U32.v dst_pos + U32.v i')) (U32.v i); i' = len end ) ; HST.pop_frame () #pop-options inline_for_extraction let serialize32_flbytes (sz32: U32.t) : Tot (serializer32 (serialize_flbytes (U32.v sz32))) = fun (x: BY.lbytes (U32.v sz32)) #rrel #rel b pos -> let _ = store_bytes x 0ul sz32 b pos in sz32 inline_for_extraction let write_flbytes (sz32: U32.t) : Tot (leaf_writer_strong (serialize_flbytes (U32.v sz32))) = leaf_writer_strong_of_serializer32 (serialize32_flbytes sz32) () inline_for_extraction let write_flbytes_weak (sz32: U32.t { U32.v sz32 < 4294967295 } ) // need to return that value if output buffer is too small : Tot (leaf_writer_weak (serialize_flbytes (U32.v sz32))) = leaf_writer_weak_of_strong_constant_size (write_flbytes sz32) sz32 () (* // TODO: remove, since nobody is using this inline_for_extraction let read_flbytes (sz32: U32.t) : Tot (leaf_reader (parse_flbytes (U32.v sz32))) = fun input pos -> let h = HST.get () in [@inline_let] let _ = valid_facts (parse_flbytes (U32.v sz32)) h input pos in BY.of_buffer sz32 (B.sub input.base pos sz32) *) (* Equality test between a vlbytes and a constant lbytes *) #push-options "--z3rlimit 32" inline_for_extraction let buffer_equals_bytes (const: BY.bytes) (#rrel #rel: _) (b: B.mbuffer byte rrel rel) (pos: U32.t) : HST.Stack bool (requires (fun h -> B.live h b /\ U32.v pos + BY.length const <= B.length b )) (ensures (fun h res h' -> B.modifies B.loc_none h h' /\ (res == true <==> Seq.slice (B.as_seq h b) (U32.v pos) (U32.v pos + BY.length const) == BY.reveal const) )) = let h0 = HST.get () in HST.push_frame (); let len = BY.len const in let bi = BF.alloca 0ul 1ul in let bres = BF.alloca true 1ul in let h1 = HST.get () in [@inline_let] let inv (h: HS.mem) (stop: bool) : GTot Type0 = B.modifies (B.loc_union (B.loc_buffer bi) (B.loc_buffer bres)) h1 h /\ ( let length = U32.v len in let i32 = (Seq.index (B.as_seq h bi) 0) in let i = U32.v i32 in let res = Seq.index (B.as_seq h bres) 0 in i <= length /\ (stop == false ==> res == true) /\ ((stop == true /\ res == true) ==> i == length) /\ (res == true <==> Seq.slice (B.as_seq h b) (U32.v pos) (U32.v pos + i) `Seq.equal` Seq.slice (BY.reveal const) 0 i) ) in C.Loops.do_while inv (fun _ -> let i = B.index bi 0ul in if i = len then true else begin let i' = i `U32.add` 1ul in [@inline_let] let _ = let s1 = (Seq.slice (B.as_seq h0 b) (U32.v pos) (U32.v pos + U32.v i)) in let c1 = (B.get h0 b (U32.v pos + U32.v i)) in let s2 = (Seq.slice (BY.reveal const) 0 (U32.v i)) in let c2 = (BY.index const (U32.v i)) in assert (Seq.slice (B.as_seq h0 b) (U32.v pos) (U32.v pos + U32.v i') `Seq.equal` Seq.snoc s1 c1); assert (Seq.slice (BY.reveal const) 0 (U32.v i') `Seq.equal` Seq.snoc s2 c2); Classical.move_requires (Seq.lemma_snoc_inj s1 s2 c1) c2 in let res = B.index b (pos `U32.add` i) = BY.get const i in B.upd bres 0ul res; B.upd bi 0ul i'; not res end ); let res = B.index bres 0ul in HST.pop_frame (); res #pop-options inline_for_extraction let valid_slice_equals_bytes (const: BY.bytes) (#rrel #rel: _) (input: slice rrel rel) (pos: U32.t) : HST.Stack bool (requires (fun h -> valid (parse_flbytes (BY.length const)) h input pos )) (ensures (fun h res h' -> B.modifies B.loc_none h h' /\ (res == true <==> contents (parse_flbytes (BY.length const)) h input pos == const ))) = let h = HST.get () in [@inline_let] let _ = valid_facts (parse_flbytes (BY.length const)) h input pos in buffer_equals_bytes const input.base pos inline_for_extraction let validate_all_bytes () : Tot (validator parse_all_bytes) = fun #rrel #rel input pos -> let h = HST.get () in [@inline_let] let _ = valid_facts parse_all_bytes h input (uint64_to_uint32 pos) in Cast.uint32_to_uint64 input.len inline_for_extraction let validate_bounded_vlbytes' (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (l: nat { l >= log256' max /\ l <= 4 } ) : Tot (validator (parse_bounded_vlbytes' min max l)) = validate_synth (validate_bounded_vldata_strong' min max l serialize_all_bytes (validate_all_bytes ())) (synth_bounded_vlbytes min max) () inline_for_extraction let validate_bounded_vlbytes (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) : Tot (validator (parse_bounded_vlbytes min max)) = validate_bounded_vlbytes' min max (log256' max)
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowStar.Monotonic.Buffer.fsti.checked", "LowStar.Buffer.fst.checked", "LowParse.Spec.Bytes.fst.checked", "LowParse.Low.VLGen.fst.checked", "LowParse.Low.VLData.fst.checked", "LowParse.Low.Int.fsti.checked", "LowParse.Low.Combinators.fsti.checked", "LowParse.Bytes32.fst.checked", "FStar.UInt8.fsti.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Int.Cast.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked", "FStar.Classical.fsti.checked", "C.Loops.fst.checked" ], "interface_file": false, "source_file": "LowParse.Low.Bytes.fst" }
[ { "abbrev": true, "full_module": "LowStar.Buffer // for local variables in store_bytes", "short_module": "BF" }, { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "FStar.Int.Cast", "short_module": "Cast" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "LowParse.Bytes32", "short_module": "BY" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "BF" }, { "abbrev": true, "full_module": "LowStar.Monotonic.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": false, "full_module": "LowParse.Low.Int", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low.VLGen", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low.VLData", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low.Combinators", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec.Bytes", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
_: Prims.unit -> LowParse.Low.Base.jumper LowParse.Spec.Bytes.parse_all_bytes
Prims.Tot
[ "total" ]
[]
[ "Prims.unit", "LowParse.Slice.srel", "LowParse.Bytes.byte", "LowParse.Slice.slice", "FStar.UInt32.t", "LowParse.Slice.__proj__Mkslice__item__len", "LowParse.Low.Base.Spec.valid_facts", "LowParse.Spec.Bytes.parse_all_bytes_kind", "FStar.Bytes.bytes", "LowParse.Spec.Bytes.parse_all_bytes", "FStar.Monotonic.HyperStack.mem", "FStar.HyperStack.ST.get", "LowParse.Low.Base.jumper" ]
[]
false
false
false
true
false
let jump_all_bytes () : Tot (jumper parse_all_bytes) =
fun #rrel #rel input pos -> let h = HST.get () in [@@ inline_let ]let _ = valid_facts parse_all_bytes h input pos in input.len
false
LowParse.Low.Bytes.fst
LowParse.Low.Bytes.valid_bounded_vlbytes_elim_length
val valid_bounded_vlbytes_elim_length (h: HS.mem) (min: nat) (max: nat{min <= max /\ max > 0 /\ max < 4294967296}) (#rrel #rel: _) (input: slice rrel rel) (pos: U32.t) : Lemma (requires (valid (parse_bounded_vlbytes min max) h input pos)) (ensures (content_length (parse_bounded_vlbytes min max) h input pos == log256' max + BY.length (contents (parse_bounded_vlbytes min max) h input pos))) [SMTPat (valid (parse_bounded_vlbytes min max) h input pos)]
val valid_bounded_vlbytes_elim_length (h: HS.mem) (min: nat) (max: nat{min <= max /\ max > 0 /\ max < 4294967296}) (#rrel #rel: _) (input: slice rrel rel) (pos: U32.t) : Lemma (requires (valid (parse_bounded_vlbytes min max) h input pos)) (ensures (content_length (parse_bounded_vlbytes min max) h input pos == log256' max + BY.length (contents (parse_bounded_vlbytes min max) h input pos))) [SMTPat (valid (parse_bounded_vlbytes min max) h input pos)]
let valid_bounded_vlbytes_elim_length (h: HS.mem) (min: nat) (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (#rrel #rel: _) (input: slice rrel rel) (pos: U32.t) : Lemma (requires ( valid (parse_bounded_vlbytes min max) h input pos )) (ensures ( content_length (parse_bounded_vlbytes min max) h input pos == log256' max + BY.length (contents (parse_bounded_vlbytes min max) h input pos) )) [SMTPat (valid (parse_bounded_vlbytes min max) h input pos)] = valid_bounded_vlbytes_elim h min max input pos
{ "file_name": "src/lowparse/LowParse.Low.Bytes.fst", "git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
{ "end_col": 48, "end_line": 494, "start_col": 0, "start_line": 479 }
module LowParse.Low.Bytes include LowParse.Spec.Bytes include LowParse.Low.Combinators include LowParse.Low.VLData include LowParse.Low.VLGen include LowParse.Low.Int module U32 = FStar.UInt32 module HS = FStar.HyperStack module B = LowStar.Monotonic.Buffer module BF = LowStar.Buffer // for local variables in store_bytes module BY = LowParse.Bytes32 module HST = FStar.HyperStack.ST module U8 = FStar.UInt8 module Cast = FStar.Int.Cast module U64 = FStar.UInt64 inline_for_extraction let validate_flbytes (sz: nat) (sz64: U64.t { U64.v sz64 == sz /\ sz < 4294967296 } ) : Tot (validator (parse_flbytes sz)) = validate_total_constant_size (parse_flbytes sz) sz64 () inline_for_extraction let jump_flbytes (sz: nat) (sz32: U32.t { U32.v sz32 == sz } ) : Tot (jumper (parse_flbytes sz)) = jump_constant_size (parse_flbytes sz) sz32 () let valid_flbytes_intro (h: HS.mem) (sz: nat { sz < 4294967296 } ) (#rrel #rel: _) (s: slice rrel rel) (pos: U32.t) : Lemma (requires (U32.v pos + sz <= U32.v s.len /\ live_slice h s)) (ensures ( valid_content_pos (parse_flbytes sz) h s pos (BY.hide (bytes_of_slice_from_to h s pos (pos `U32.add` U32.uint_to_t sz))) (pos `U32.add` U32.uint_to_t sz) )) = valid_facts (parse_flbytes sz) h s pos let valid_pos_flbytes_elim (h: HS.mem) (sz: nat { sz < 4294967296 } ) (#rrel #rel: _) (s: slice rrel rel) (pos pos' : U32.t) : Lemma (requires (valid_pos (parse_flbytes sz) h s pos pos')) (ensures (U32.v pos + sz == U32.v pos')) [SMTPat (valid_pos (parse_flbytes sz) h s pos pos')] = valid_facts (parse_flbytes sz) h s pos let valid_flbytes_elim (h: HS.mem) (sz: nat { sz < 4294967296 } ) (#rrel #rel: _) (s: slice rrel rel) (pos: U32.t) : Lemma (requires (valid (parse_flbytes sz) h s pos)) (ensures ( valid_content_pos (parse_flbytes sz) h s pos (BY.hide (bytes_of_slice_from_to h s pos (pos `U32.add` U32.uint_to_t sz))) (pos `U32.add` U32.uint_to_t sz) )) = valid_flbytes_intro h sz s pos let clens_flbytes_slice (sz: nat) (from: U32.t) (to: U32.t {U32.v from <= U32.v to /\ U32.v to <= sz } ) : Tot (clens (BY.lbytes sz) (BY.lbytes (U32.v to - U32.v from))) = { clens_cond = (fun _ -> True); clens_get = (fun (x: BY.lbytes sz) -> (BY.slice x from to <: BY.lbytes (U32.v to - U32.v from))); } #push-options "--z3rlimit 16" let gaccessor_flbytes_slice' (sz: nat { sz < 4294967296 } ) (from: U32.t) (to: U32.t {U32.v from <= U32.v to /\ U32.v to <= sz } ) : Tot (gaccessor' (parse_flbytes sz) (parse_flbytes (U32.v to - U32.v from)) (clens_flbytes_slice sz from to)) = fun (input: bytes) -> ( begin if Seq.length input < sz then (0) // dummy else (U32.v from) end) let gaccessor_flbytes_slice (sz: nat { sz < 4294967296 } ) (from: U32.t) (to: U32.t {U32.v from <= U32.v to /\ U32.v to <= sz } ) : Tot (gaccessor (parse_flbytes sz) (parse_flbytes (U32.v to - U32.v from)) (clens_flbytes_slice sz from to)) = assert (forall x . gaccessor_pre (parse_flbytes sz) (parse_flbytes (U32.v to - U32.v from)) (clens_flbytes_slice sz from to) x ==> sz <= Seq.length x); gaccessor_prop_equiv (parse_flbytes sz) (parse_flbytes (U32.v to - U32.v from)) (clens_flbytes_slice sz from to) (gaccessor_flbytes_slice' sz from to); gaccessor_flbytes_slice' sz from to inline_for_extraction let accessor_flbytes_slice (sz: nat { sz < 4294967296 } ) (from: U32.t) (to: U32.t {U32.v from <= U32.v to /\ U32.v to <= sz } ) : Tot (accessor (gaccessor_flbytes_slice sz from to)) = fun #rrel #rel input pos -> let h = HST.get () in [@inline_let] let _ = slice_access_eq h (gaccessor_flbytes_slice sz from to) input pos in pos `U32.add` from #pop-options let clens_flbytes_get (sz: nat) (i: U32.t { U32.v i < sz } ) : Tot (clens (BY.lbytes sz) byte) = { clens_cond = (fun _ -> True); clens_get = (fun (x: BY.lbytes sz) -> (BY.get x i <: byte)); } #push-options "--z3rlimit 16 --max_fuel 1" let gaccessor_flbytes_get' (sz: nat { sz < 4294967296 } ) (i: U32.t { U32.v i < sz } ) : Tot (gaccessor' (parse_flbytes sz) (parse_u8) (clens_flbytes_get sz i)) = fun (input: bytes) -> ( begin let res = if Seq.length input < U32.v i then (0) // dummy else (U32.v i) in let g () : Lemma (requires (gaccessor_pre (parse_flbytes sz) parse_u8 (clens_flbytes_get sz i) input)) (ensures (gaccessor_post (parse_flbytes sz) parse_u8 (clens_flbytes_get sz i) input res)) = parser_kind_prop_equiv (get_parser_kind parse_u8) parse_u8; assert (res == (U32.v i)); parse_u8_spec' (Seq.slice input (U32.v i) (U32.v i + 1)); parse_strong_prefix parse_u8 (Seq.slice input (U32.v i) (U32.v i + 1)) (Seq.slice input (U32.v i) (Seq.length input)) in Classical.move_requires g (); res end) #pop-options let gaccessor_flbytes_get (sz: nat { sz < 4294967296 } ) (i: U32.t { U32.v i < sz } ) : Tot (gaccessor (parse_flbytes sz) (parse_u8) (clens_flbytes_get sz i)) = assert (forall x . gaccessor_pre (parse_flbytes sz) (parse_u8) (clens_flbytes_get sz i) x ==> U32.v i <= Seq.length x); gaccessor_prop_equiv (parse_flbytes sz) (parse_u8) (clens_flbytes_get sz i) (gaccessor_flbytes_get' sz i); gaccessor_flbytes_get' sz i inline_for_extraction let accessor_flbytes_get (sz: nat { sz < 4294967296 } ) (i: U32.t { U32.v i < sz } ) : Tot (accessor (gaccessor_flbytes_get sz i)) = fun #rrel #rel input pos -> let h = HST.get () in [@inline_let] let _ = slice_access_eq h (gaccessor_flbytes_get sz i) input pos in pos `U32.add` i (* Temporary: flbytes as leaf values *) (* TODO: convert store_bytes to monotonic buffers, using the "writable" predicate *) #push-options "--z3rlimit 32" inline_for_extraction let store_bytes (src: BY.bytes) (src_from src_to: U32.t) (#rrel #rel: _) (dst: B.mbuffer byte rrel rel) (dst_pos: U32.t) : HST.Stack unit (requires (fun h -> B.live h dst /\ U32.v src_from <= U32.v src_to /\ U32.v src_to <= BY.length src /\ U32.v dst_pos + (U32.v src_to - U32.v src_from) <= B.length dst /\ writable dst (U32.v dst_pos) (U32.v dst_pos + (U32.v src_to - U32.v src_from)) h )) (ensures (fun h _ h' -> B.modifies (B.loc_buffer_from_to dst dst_pos (dst_pos `U32.add` (src_to `U32.sub` src_from))) h h' /\ Seq.slice (B.as_seq h' dst) (U32.v dst_pos) (U32.v dst_pos + (U32.v src_to - U32.v src_from)) == Seq.slice (BY.reveal src) (U32.v src_from) (U32.v src_to) )) = let h0 = HST.get () in HST.push_frame (); let h1 = HST.get () in let bi = BF.alloca 0ul 1ul in let h2 = HST.get () in let len = src_to `U32.sub` src_from in C.Loops.do_while (fun h stop -> B.modifies (B.loc_union (B.loc_region_only true (HS.get_tip h1)) (B.loc_buffer_from_to dst dst_pos (dst_pos `U32.add` len))) h2 h /\ B.live h bi /\ ( let i = Seq.index (B.as_seq h bi) 0 in U32.v i <= U32.v len /\ writable dst (U32.v dst_pos) (U32.v dst_pos + U32.v len) h /\ Seq.slice (B.as_seq h dst) (U32.v dst_pos) (U32.v dst_pos + U32.v i) `Seq.equal` Seq.slice (BY.reveal src) (U32.v src_from) (U32.v src_from + U32.v i) /\ (stop == true ==> i == len) )) (fun _ -> let i = B.index bi 0ul in if i = len then true else begin let x = BY.get src (src_from `U32.add` i) in mbuffer_upd dst (Ghost.hide (U32.v dst_pos)) (Ghost.hide (U32.v dst_pos + U32.v len)) (dst_pos `U32.add` i) x; let i' = i `U32.add` 1ul in B.upd bi 0ul i'; let h' = HST.get () in Seq.lemma_split (Seq.slice (B.as_seq h' dst) (U32.v dst_pos) (U32.v dst_pos + U32.v i')) (U32.v i); i' = len end ) ; HST.pop_frame () #pop-options inline_for_extraction let serialize32_flbytes (sz32: U32.t) : Tot (serializer32 (serialize_flbytes (U32.v sz32))) = fun (x: BY.lbytes (U32.v sz32)) #rrel #rel b pos -> let _ = store_bytes x 0ul sz32 b pos in sz32 inline_for_extraction let write_flbytes (sz32: U32.t) : Tot (leaf_writer_strong (serialize_flbytes (U32.v sz32))) = leaf_writer_strong_of_serializer32 (serialize32_flbytes sz32) () inline_for_extraction let write_flbytes_weak (sz32: U32.t { U32.v sz32 < 4294967295 } ) // need to return that value if output buffer is too small : Tot (leaf_writer_weak (serialize_flbytes (U32.v sz32))) = leaf_writer_weak_of_strong_constant_size (write_flbytes sz32) sz32 () (* // TODO: remove, since nobody is using this inline_for_extraction let read_flbytes (sz32: U32.t) : Tot (leaf_reader (parse_flbytes (U32.v sz32))) = fun input pos -> let h = HST.get () in [@inline_let] let _ = valid_facts (parse_flbytes (U32.v sz32)) h input pos in BY.of_buffer sz32 (B.sub input.base pos sz32) *) (* Equality test between a vlbytes and a constant lbytes *) #push-options "--z3rlimit 32" inline_for_extraction let buffer_equals_bytes (const: BY.bytes) (#rrel #rel: _) (b: B.mbuffer byte rrel rel) (pos: U32.t) : HST.Stack bool (requires (fun h -> B.live h b /\ U32.v pos + BY.length const <= B.length b )) (ensures (fun h res h' -> B.modifies B.loc_none h h' /\ (res == true <==> Seq.slice (B.as_seq h b) (U32.v pos) (U32.v pos + BY.length const) == BY.reveal const) )) = let h0 = HST.get () in HST.push_frame (); let len = BY.len const in let bi = BF.alloca 0ul 1ul in let bres = BF.alloca true 1ul in let h1 = HST.get () in [@inline_let] let inv (h: HS.mem) (stop: bool) : GTot Type0 = B.modifies (B.loc_union (B.loc_buffer bi) (B.loc_buffer bres)) h1 h /\ ( let length = U32.v len in let i32 = (Seq.index (B.as_seq h bi) 0) in let i = U32.v i32 in let res = Seq.index (B.as_seq h bres) 0 in i <= length /\ (stop == false ==> res == true) /\ ((stop == true /\ res == true) ==> i == length) /\ (res == true <==> Seq.slice (B.as_seq h b) (U32.v pos) (U32.v pos + i) `Seq.equal` Seq.slice (BY.reveal const) 0 i) ) in C.Loops.do_while inv (fun _ -> let i = B.index bi 0ul in if i = len then true else begin let i' = i `U32.add` 1ul in [@inline_let] let _ = let s1 = (Seq.slice (B.as_seq h0 b) (U32.v pos) (U32.v pos + U32.v i)) in let c1 = (B.get h0 b (U32.v pos + U32.v i)) in let s2 = (Seq.slice (BY.reveal const) 0 (U32.v i)) in let c2 = (BY.index const (U32.v i)) in assert (Seq.slice (B.as_seq h0 b) (U32.v pos) (U32.v pos + U32.v i') `Seq.equal` Seq.snoc s1 c1); assert (Seq.slice (BY.reveal const) 0 (U32.v i') `Seq.equal` Seq.snoc s2 c2); Classical.move_requires (Seq.lemma_snoc_inj s1 s2 c1) c2 in let res = B.index b (pos `U32.add` i) = BY.get const i in B.upd bres 0ul res; B.upd bi 0ul i'; not res end ); let res = B.index bres 0ul in HST.pop_frame (); res #pop-options inline_for_extraction let valid_slice_equals_bytes (const: BY.bytes) (#rrel #rel: _) (input: slice rrel rel) (pos: U32.t) : HST.Stack bool (requires (fun h -> valid (parse_flbytes (BY.length const)) h input pos )) (ensures (fun h res h' -> B.modifies B.loc_none h h' /\ (res == true <==> contents (parse_flbytes (BY.length const)) h input pos == const ))) = let h = HST.get () in [@inline_let] let _ = valid_facts (parse_flbytes (BY.length const)) h input pos in buffer_equals_bytes const input.base pos inline_for_extraction let validate_all_bytes () : Tot (validator parse_all_bytes) = fun #rrel #rel input pos -> let h = HST.get () in [@inline_let] let _ = valid_facts parse_all_bytes h input (uint64_to_uint32 pos) in Cast.uint32_to_uint64 input.len inline_for_extraction let validate_bounded_vlbytes' (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (l: nat { l >= log256' max /\ l <= 4 } ) : Tot (validator (parse_bounded_vlbytes' min max l)) = validate_synth (validate_bounded_vldata_strong' min max l serialize_all_bytes (validate_all_bytes ())) (synth_bounded_vlbytes min max) () inline_for_extraction let validate_bounded_vlbytes (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) : Tot (validator (parse_bounded_vlbytes min max)) = validate_bounded_vlbytes' min max (log256' max) inline_for_extraction let jump_all_bytes () : Tot (jumper parse_all_bytes) = fun #rrel #rel input pos -> let h = HST.get () in [@inline_let] let _ = valid_facts parse_all_bytes h input pos in input.len inline_for_extraction let jump_bounded_vlbytes' (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (l: nat { l >= log256' max /\ l <= 4 } ) : Tot (jumper (parse_bounded_vlbytes' min max l)) = jump_synth (jump_bounded_vldata_strong' min max l serialize_all_bytes) (synth_bounded_vlbytes min max) () inline_for_extraction let jump_bounded_vlbytes (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) : Tot (jumper (parse_bounded_vlbytes min max)) = jump_bounded_vlbytes' min max (log256' max) let valid_exact_all_bytes_elim (h: HS.mem) (#rrel #rel: _) (input: slice rrel rel) (pos pos' : U32.t) : Lemma (requires (valid_exact parse_all_bytes h input pos pos')) (ensures ( let x = contents_exact parse_all_bytes h input pos pos' in let length = U32.v pos' - U32.v pos in BY.length x == length /\ valid_content_pos (parse_flbytes length) h input pos x pos' )) = valid_exact_equiv parse_all_bytes h input pos pos' ; contents_exact_eq parse_all_bytes h input pos pos' ; let length = U32.v pos' - U32.v pos in valid_facts (parse_flbytes length) h input pos ; assert (no_lookahead_on (parse_flbytes length) (bytes_of_slice_from_to h input pos pos') (bytes_of_slice_from h input pos)); assert (injective_postcond (parse_flbytes length) (bytes_of_slice_from_to h input pos pos') (bytes_of_slice_from h input pos)) #push-options "--z3rlimit 32" let valid_bounded_vlbytes'_elim (h: HS.mem) (min: nat) (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (l: nat { l >= log256' max /\ l <= 4 } ) (#rrel #rel: _) (input: slice rrel rel) (pos: U32.t) : Lemma (requires ( valid (parse_bounded_vlbytes' min max l) h input pos )) (ensures ( let sz = l in valid (parse_bounded_integer sz) h input pos /\ ( let len_payload = contents (parse_bounded_integer sz) h input pos in min <= U32.v len_payload /\ U32.v len_payload <= max /\ sz + U32.v len_payload == content_length (parse_bounded_vlbytes' min max l) h input pos /\ ( let pos_payload = pos `U32.add` U32.uint_to_t sz in let x = contents (parse_bounded_vlbytes' min max l) h input pos in BY.len x == len_payload /\ valid_pos (parse_bounded_vlbytes' min max l) h input pos (pos_payload `U32.add` len_payload) /\ valid_content_pos (parse_flbytes (U32.v len_payload)) h input pos_payload x (pos_payload `U32.add` len_payload) )))) = valid_synth h (parse_bounded_vlbytes_aux min max l) (synth_bounded_vlbytes min max) input pos; valid_bounded_vldata_strong'_elim h min max l serialize_all_bytes input pos; let sz = l in let len_payload = contents (parse_bounded_integer sz) h input pos in let pos_payload = pos `U32.add` U32.uint_to_t sz in valid_exact_all_bytes_elim h input pos_payload (pos_payload `U32.add` len_payload); () #pop-options let valid_bounded_vlbytes_elim (h: HS.mem) (min: nat) (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (#rrel #rel: _) (input: slice rrel rel) (pos: U32.t) : Lemma (requires ( valid (parse_bounded_vlbytes min max) h input pos )) (ensures ( let sz = log256' max in valid (parse_bounded_integer sz) h input pos /\ ( let len_payload = contents (parse_bounded_integer sz) h input pos in min <= U32.v len_payload /\ U32.v len_payload <= max /\ sz + U32.v len_payload == content_length (parse_bounded_vlbytes min max) h input pos /\ ( let pos_payload = pos `U32.add` U32.uint_to_t sz in let x = contents (parse_bounded_vlbytes min max) h input pos in BY.len x == len_payload /\ valid_pos (parse_bounded_vlbytes min max) h input pos (pos_payload `U32.add` len_payload) /\ valid_content_pos (parse_flbytes (U32.v len_payload)) h input pos_payload x (pos_payload `U32.add` len_payload) )))) = valid_bounded_vlbytes'_elim h min max (log256' max) input pos
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowStar.Monotonic.Buffer.fsti.checked", "LowStar.Buffer.fst.checked", "LowParse.Spec.Bytes.fst.checked", "LowParse.Low.VLGen.fst.checked", "LowParse.Low.VLData.fst.checked", "LowParse.Low.Int.fsti.checked", "LowParse.Low.Combinators.fsti.checked", "LowParse.Bytes32.fst.checked", "FStar.UInt8.fsti.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Int.Cast.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked", "FStar.Classical.fsti.checked", "C.Loops.fst.checked" ], "interface_file": false, "source_file": "LowParse.Low.Bytes.fst" }
[ { "abbrev": true, "full_module": "LowStar.Buffer // for local variables in store_bytes", "short_module": "BF" }, { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "FStar.Int.Cast", "short_module": "Cast" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "LowParse.Bytes32", "short_module": "BY" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "BF" }, { "abbrev": true, "full_module": "LowStar.Monotonic.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": false, "full_module": "LowParse.Low.Int", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low.VLGen", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low.VLData", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low.Combinators", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec.Bytes", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
h: FStar.Monotonic.HyperStack.mem -> min: Prims.nat -> max: Prims.nat{min <= max /\ max > 0 /\ max < 4294967296} -> input: LowParse.Slice.slice rrel rel -> pos: FStar.UInt32.t -> FStar.Pervasives.Lemma (requires LowParse.Low.Base.Spec.valid (LowParse.Spec.Bytes.parse_bounded_vlbytes min max) h input pos ) (ensures LowParse.Low.Base.Spec.content_length (LowParse.Spec.Bytes.parse_bounded_vlbytes min max) h input pos == LowParse.Spec.BoundedInt.log256' max + FStar.Bytes.length (LowParse.Low.Base.Spec.contents (LowParse.Spec.Bytes.parse_bounded_vlbytes min max) h input pos)) [ SMTPat (LowParse.Low.Base.Spec.valid (LowParse.Spec.Bytes.parse_bounded_vlbytes min max) h input pos) ]
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "FStar.Monotonic.HyperStack.mem", "Prims.nat", "Prims.l_and", "Prims.b2t", "Prims.op_LessThanOrEqual", "Prims.op_GreaterThan", "Prims.op_LessThan", "LowParse.Slice.srel", "LowParse.Bytes.byte", "LowParse.Slice.slice", "FStar.UInt32.t", "LowParse.Low.Bytes.valid_bounded_vlbytes_elim", "Prims.unit", "LowParse.Low.Base.Spec.valid", "LowParse.Spec.VLData.parse_bounded_vldata_strong_kind", "LowParse.Spec.BoundedInt.log256'", "LowParse.Spec.Bytes.parse_all_bytes_kind", "LowParse.Spec.Bytes.parse_bounded_vlbytes_t", "LowParse.Spec.Bytes.parse_bounded_vlbytes", "Prims.squash", "Prims.eq2", "Prims.int", "LowParse.Low.Base.Spec.content_length", "Prims.op_Addition", "FStar.Bytes.length", "LowParse.Low.Base.Spec.contents", "Prims.Cons", "FStar.Pervasives.pattern", "FStar.Pervasives.smt_pat", "Prims.Nil" ]
[]
true
false
true
false
false
let valid_bounded_vlbytes_elim_length (h: HS.mem) (min: nat) (max: nat{min <= max /\ max > 0 /\ max < 4294967296}) (#rrel #rel: _) (input: slice rrel rel) (pos: U32.t) : Lemma (requires (valid (parse_bounded_vlbytes min max) h input pos)) (ensures (content_length (parse_bounded_vlbytes min max) h input pos == log256' max + BY.length (contents (parse_bounded_vlbytes min max) h input pos))) [SMTPat (valid (parse_bounded_vlbytes min max) h input pos)] =
valid_bounded_vlbytes_elim h min max input pos
false
LowParse.Low.Bytes.fst
LowParse.Low.Bytes.gaccessor_flbytes_slice'
val gaccessor_flbytes_slice' (sz: nat{sz < 4294967296}) (from: U32.t) (to: U32.t{U32.v from <= U32.v to /\ U32.v to <= sz}) : Tot (gaccessor' (parse_flbytes sz) (parse_flbytes (U32.v to - U32.v from)) (clens_flbytes_slice sz from to))
val gaccessor_flbytes_slice' (sz: nat{sz < 4294967296}) (from: U32.t) (to: U32.t{U32.v from <= U32.v to /\ U32.v to <= sz}) : Tot (gaccessor' (parse_flbytes sz) (parse_flbytes (U32.v to - U32.v from)) (clens_flbytes_slice sz from to))
let gaccessor_flbytes_slice' (sz: nat { sz < 4294967296 } ) (from: U32.t) (to: U32.t {U32.v from <= U32.v to /\ U32.v to <= sz } ) : Tot (gaccessor' (parse_flbytes sz) (parse_flbytes (U32.v to - U32.v from)) (clens_flbytes_slice sz from to)) = fun (input: bytes) -> ( begin if Seq.length input < sz then (0) // dummy else (U32.v from) end)
{ "file_name": "src/lowparse/LowParse.Low.Bytes.fst", "git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
{ "end_col": 6, "end_line": 92, "start_col": 0, "start_line": 82 }
module LowParse.Low.Bytes include LowParse.Spec.Bytes include LowParse.Low.Combinators include LowParse.Low.VLData include LowParse.Low.VLGen include LowParse.Low.Int module U32 = FStar.UInt32 module HS = FStar.HyperStack module B = LowStar.Monotonic.Buffer module BF = LowStar.Buffer // for local variables in store_bytes module BY = LowParse.Bytes32 module HST = FStar.HyperStack.ST module U8 = FStar.UInt8 module Cast = FStar.Int.Cast module U64 = FStar.UInt64 inline_for_extraction let validate_flbytes (sz: nat) (sz64: U64.t { U64.v sz64 == sz /\ sz < 4294967296 } ) : Tot (validator (parse_flbytes sz)) = validate_total_constant_size (parse_flbytes sz) sz64 () inline_for_extraction let jump_flbytes (sz: nat) (sz32: U32.t { U32.v sz32 == sz } ) : Tot (jumper (parse_flbytes sz)) = jump_constant_size (parse_flbytes sz) sz32 () let valid_flbytes_intro (h: HS.mem) (sz: nat { sz < 4294967296 } ) (#rrel #rel: _) (s: slice rrel rel) (pos: U32.t) : Lemma (requires (U32.v pos + sz <= U32.v s.len /\ live_slice h s)) (ensures ( valid_content_pos (parse_flbytes sz) h s pos (BY.hide (bytes_of_slice_from_to h s pos (pos `U32.add` U32.uint_to_t sz))) (pos `U32.add` U32.uint_to_t sz) )) = valid_facts (parse_flbytes sz) h s pos let valid_pos_flbytes_elim (h: HS.mem) (sz: nat { sz < 4294967296 } ) (#rrel #rel: _) (s: slice rrel rel) (pos pos' : U32.t) : Lemma (requires (valid_pos (parse_flbytes sz) h s pos pos')) (ensures (U32.v pos + sz == U32.v pos')) [SMTPat (valid_pos (parse_flbytes sz) h s pos pos')] = valid_facts (parse_flbytes sz) h s pos let valid_flbytes_elim (h: HS.mem) (sz: nat { sz < 4294967296 } ) (#rrel #rel: _) (s: slice rrel rel) (pos: U32.t) : Lemma (requires (valid (parse_flbytes sz) h s pos)) (ensures ( valid_content_pos (parse_flbytes sz) h s pos (BY.hide (bytes_of_slice_from_to h s pos (pos `U32.add` U32.uint_to_t sz))) (pos `U32.add` U32.uint_to_t sz) )) = valid_flbytes_intro h sz s pos let clens_flbytes_slice (sz: nat) (from: U32.t) (to: U32.t {U32.v from <= U32.v to /\ U32.v to <= sz } ) : Tot (clens (BY.lbytes sz) (BY.lbytes (U32.v to - U32.v from))) = { clens_cond = (fun _ -> True); clens_get = (fun (x: BY.lbytes sz) -> (BY.slice x from to <: BY.lbytes (U32.v to - U32.v from))); } #push-options "--z3rlimit 16"
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowStar.Monotonic.Buffer.fsti.checked", "LowStar.Buffer.fst.checked", "LowParse.Spec.Bytes.fst.checked", "LowParse.Low.VLGen.fst.checked", "LowParse.Low.VLData.fst.checked", "LowParse.Low.Int.fsti.checked", "LowParse.Low.Combinators.fsti.checked", "LowParse.Bytes32.fst.checked", "FStar.UInt8.fsti.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Int.Cast.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked", "FStar.Classical.fsti.checked", "C.Loops.fst.checked" ], "interface_file": false, "source_file": "LowParse.Low.Bytes.fst" }
[ { "abbrev": true, "full_module": "LowStar.Buffer // for local variables in store_bytes", "short_module": "BF" }, { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "FStar.Int.Cast", "short_module": "Cast" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "LowParse.Bytes32", "short_module": "BY" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "BF" }, { "abbrev": true, "full_module": "LowStar.Monotonic.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": false, "full_module": "LowParse.Low.Int", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low.VLGen", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low.VLData", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low.Combinators", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec.Bytes", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 16, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
sz: Prims.nat{sz < 4294967296} -> from: FStar.UInt32.t -> to: FStar.UInt32.t{FStar.UInt32.v from <= FStar.UInt32.v to /\ FStar.UInt32.v to <= sz} -> LowParse.Low.Base.Spec.gaccessor' (LowParse.Spec.Bytes.parse_flbytes sz) (LowParse.Spec.Bytes.parse_flbytes (FStar.UInt32.v to - FStar.UInt32.v from)) (LowParse.Low.Bytes.clens_flbytes_slice sz from to)
Prims.Tot
[ "total" ]
[]
[ "Prims.nat", "Prims.b2t", "Prims.op_LessThan", "FStar.UInt32.t", "Prims.l_and", "Prims.op_LessThanOrEqual", "FStar.UInt32.v", "LowParse.Bytes.bytes", "FStar.Seq.Base.length", "LowParse.Bytes.byte", "Prims.bool", "LowParse.Low.Base.Spec.gaccessor'", "LowParse.Spec.Base.total_constant_size_parser_kind", "FStar.Bytes.lbytes", "LowParse.Spec.Bytes.parse_flbytes", "Prims.op_Subtraction", "LowParse.Low.Bytes.clens_flbytes_slice" ]
[]
false
false
false
false
false
let gaccessor_flbytes_slice' (sz: nat{sz < 4294967296}) (from: U32.t) (to: U32.t{U32.v from <= U32.v to /\ U32.v to <= sz}) : Tot (gaccessor' (parse_flbytes sz) (parse_flbytes (U32.v to - U32.v from)) (clens_flbytes_slice sz from to)) =
fun (input: bytes) -> (if Seq.length input < sz then (0) else (U32.v from))
false
LowParse.Low.Bytes.fst
LowParse.Low.Bytes.validate_all_bytes
val validate_all_bytes: Prims.unit -> Tot (validator parse_all_bytes)
val validate_all_bytes: Prims.unit -> Tot (validator parse_all_bytes)
let validate_all_bytes () : Tot (validator parse_all_bytes) = fun #rrel #rel input pos -> let h = HST.get () in [@inline_let] let _ = valid_facts parse_all_bytes h input (uint64_to_uint32 pos) in Cast.uint32_to_uint64 input.len
{ "file_name": "src/lowparse/LowParse.Low.Bytes.fst", "git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
{ "end_col": 33, "end_line": 351, "start_col": 0, "start_line": 345 }
module LowParse.Low.Bytes include LowParse.Spec.Bytes include LowParse.Low.Combinators include LowParse.Low.VLData include LowParse.Low.VLGen include LowParse.Low.Int module U32 = FStar.UInt32 module HS = FStar.HyperStack module B = LowStar.Monotonic.Buffer module BF = LowStar.Buffer // for local variables in store_bytes module BY = LowParse.Bytes32 module HST = FStar.HyperStack.ST module U8 = FStar.UInt8 module Cast = FStar.Int.Cast module U64 = FStar.UInt64 inline_for_extraction let validate_flbytes (sz: nat) (sz64: U64.t { U64.v sz64 == sz /\ sz < 4294967296 } ) : Tot (validator (parse_flbytes sz)) = validate_total_constant_size (parse_flbytes sz) sz64 () inline_for_extraction let jump_flbytes (sz: nat) (sz32: U32.t { U32.v sz32 == sz } ) : Tot (jumper (parse_flbytes sz)) = jump_constant_size (parse_flbytes sz) sz32 () let valid_flbytes_intro (h: HS.mem) (sz: nat { sz < 4294967296 } ) (#rrel #rel: _) (s: slice rrel rel) (pos: U32.t) : Lemma (requires (U32.v pos + sz <= U32.v s.len /\ live_slice h s)) (ensures ( valid_content_pos (parse_flbytes sz) h s pos (BY.hide (bytes_of_slice_from_to h s pos (pos `U32.add` U32.uint_to_t sz))) (pos `U32.add` U32.uint_to_t sz) )) = valid_facts (parse_flbytes sz) h s pos let valid_pos_flbytes_elim (h: HS.mem) (sz: nat { sz < 4294967296 } ) (#rrel #rel: _) (s: slice rrel rel) (pos pos' : U32.t) : Lemma (requires (valid_pos (parse_flbytes sz) h s pos pos')) (ensures (U32.v pos + sz == U32.v pos')) [SMTPat (valid_pos (parse_flbytes sz) h s pos pos')] = valid_facts (parse_flbytes sz) h s pos let valid_flbytes_elim (h: HS.mem) (sz: nat { sz < 4294967296 } ) (#rrel #rel: _) (s: slice rrel rel) (pos: U32.t) : Lemma (requires (valid (parse_flbytes sz) h s pos)) (ensures ( valid_content_pos (parse_flbytes sz) h s pos (BY.hide (bytes_of_slice_from_to h s pos (pos `U32.add` U32.uint_to_t sz))) (pos `U32.add` U32.uint_to_t sz) )) = valid_flbytes_intro h sz s pos let clens_flbytes_slice (sz: nat) (from: U32.t) (to: U32.t {U32.v from <= U32.v to /\ U32.v to <= sz } ) : Tot (clens (BY.lbytes sz) (BY.lbytes (U32.v to - U32.v from))) = { clens_cond = (fun _ -> True); clens_get = (fun (x: BY.lbytes sz) -> (BY.slice x from to <: BY.lbytes (U32.v to - U32.v from))); } #push-options "--z3rlimit 16" let gaccessor_flbytes_slice' (sz: nat { sz < 4294967296 } ) (from: U32.t) (to: U32.t {U32.v from <= U32.v to /\ U32.v to <= sz } ) : Tot (gaccessor' (parse_flbytes sz) (parse_flbytes (U32.v to - U32.v from)) (clens_flbytes_slice sz from to)) = fun (input: bytes) -> ( begin if Seq.length input < sz then (0) // dummy else (U32.v from) end) let gaccessor_flbytes_slice (sz: nat { sz < 4294967296 } ) (from: U32.t) (to: U32.t {U32.v from <= U32.v to /\ U32.v to <= sz } ) : Tot (gaccessor (parse_flbytes sz) (parse_flbytes (U32.v to - U32.v from)) (clens_flbytes_slice sz from to)) = assert (forall x . gaccessor_pre (parse_flbytes sz) (parse_flbytes (U32.v to - U32.v from)) (clens_flbytes_slice sz from to) x ==> sz <= Seq.length x); gaccessor_prop_equiv (parse_flbytes sz) (parse_flbytes (U32.v to - U32.v from)) (clens_flbytes_slice sz from to) (gaccessor_flbytes_slice' sz from to); gaccessor_flbytes_slice' sz from to inline_for_extraction let accessor_flbytes_slice (sz: nat { sz < 4294967296 } ) (from: U32.t) (to: U32.t {U32.v from <= U32.v to /\ U32.v to <= sz } ) : Tot (accessor (gaccessor_flbytes_slice sz from to)) = fun #rrel #rel input pos -> let h = HST.get () in [@inline_let] let _ = slice_access_eq h (gaccessor_flbytes_slice sz from to) input pos in pos `U32.add` from #pop-options let clens_flbytes_get (sz: nat) (i: U32.t { U32.v i < sz } ) : Tot (clens (BY.lbytes sz) byte) = { clens_cond = (fun _ -> True); clens_get = (fun (x: BY.lbytes sz) -> (BY.get x i <: byte)); } #push-options "--z3rlimit 16 --max_fuel 1" let gaccessor_flbytes_get' (sz: nat { sz < 4294967296 } ) (i: U32.t { U32.v i < sz } ) : Tot (gaccessor' (parse_flbytes sz) (parse_u8) (clens_flbytes_get sz i)) = fun (input: bytes) -> ( begin let res = if Seq.length input < U32.v i then (0) // dummy else (U32.v i) in let g () : Lemma (requires (gaccessor_pre (parse_flbytes sz) parse_u8 (clens_flbytes_get sz i) input)) (ensures (gaccessor_post (parse_flbytes sz) parse_u8 (clens_flbytes_get sz i) input res)) = parser_kind_prop_equiv (get_parser_kind parse_u8) parse_u8; assert (res == (U32.v i)); parse_u8_spec' (Seq.slice input (U32.v i) (U32.v i + 1)); parse_strong_prefix parse_u8 (Seq.slice input (U32.v i) (U32.v i + 1)) (Seq.slice input (U32.v i) (Seq.length input)) in Classical.move_requires g (); res end) #pop-options let gaccessor_flbytes_get (sz: nat { sz < 4294967296 } ) (i: U32.t { U32.v i < sz } ) : Tot (gaccessor (parse_flbytes sz) (parse_u8) (clens_flbytes_get sz i)) = assert (forall x . gaccessor_pre (parse_flbytes sz) (parse_u8) (clens_flbytes_get sz i) x ==> U32.v i <= Seq.length x); gaccessor_prop_equiv (parse_flbytes sz) (parse_u8) (clens_flbytes_get sz i) (gaccessor_flbytes_get' sz i); gaccessor_flbytes_get' sz i inline_for_extraction let accessor_flbytes_get (sz: nat { sz < 4294967296 } ) (i: U32.t { U32.v i < sz } ) : Tot (accessor (gaccessor_flbytes_get sz i)) = fun #rrel #rel input pos -> let h = HST.get () in [@inline_let] let _ = slice_access_eq h (gaccessor_flbytes_get sz i) input pos in pos `U32.add` i (* Temporary: flbytes as leaf values *) (* TODO: convert store_bytes to monotonic buffers, using the "writable" predicate *) #push-options "--z3rlimit 32" inline_for_extraction let store_bytes (src: BY.bytes) (src_from src_to: U32.t) (#rrel #rel: _) (dst: B.mbuffer byte rrel rel) (dst_pos: U32.t) : HST.Stack unit (requires (fun h -> B.live h dst /\ U32.v src_from <= U32.v src_to /\ U32.v src_to <= BY.length src /\ U32.v dst_pos + (U32.v src_to - U32.v src_from) <= B.length dst /\ writable dst (U32.v dst_pos) (U32.v dst_pos + (U32.v src_to - U32.v src_from)) h )) (ensures (fun h _ h' -> B.modifies (B.loc_buffer_from_to dst dst_pos (dst_pos `U32.add` (src_to `U32.sub` src_from))) h h' /\ Seq.slice (B.as_seq h' dst) (U32.v dst_pos) (U32.v dst_pos + (U32.v src_to - U32.v src_from)) == Seq.slice (BY.reveal src) (U32.v src_from) (U32.v src_to) )) = let h0 = HST.get () in HST.push_frame (); let h1 = HST.get () in let bi = BF.alloca 0ul 1ul in let h2 = HST.get () in let len = src_to `U32.sub` src_from in C.Loops.do_while (fun h stop -> B.modifies (B.loc_union (B.loc_region_only true (HS.get_tip h1)) (B.loc_buffer_from_to dst dst_pos (dst_pos `U32.add` len))) h2 h /\ B.live h bi /\ ( let i = Seq.index (B.as_seq h bi) 0 in U32.v i <= U32.v len /\ writable dst (U32.v dst_pos) (U32.v dst_pos + U32.v len) h /\ Seq.slice (B.as_seq h dst) (U32.v dst_pos) (U32.v dst_pos + U32.v i) `Seq.equal` Seq.slice (BY.reveal src) (U32.v src_from) (U32.v src_from + U32.v i) /\ (stop == true ==> i == len) )) (fun _ -> let i = B.index bi 0ul in if i = len then true else begin let x = BY.get src (src_from `U32.add` i) in mbuffer_upd dst (Ghost.hide (U32.v dst_pos)) (Ghost.hide (U32.v dst_pos + U32.v len)) (dst_pos `U32.add` i) x; let i' = i `U32.add` 1ul in B.upd bi 0ul i'; let h' = HST.get () in Seq.lemma_split (Seq.slice (B.as_seq h' dst) (U32.v dst_pos) (U32.v dst_pos + U32.v i')) (U32.v i); i' = len end ) ; HST.pop_frame () #pop-options inline_for_extraction let serialize32_flbytes (sz32: U32.t) : Tot (serializer32 (serialize_flbytes (U32.v sz32))) = fun (x: BY.lbytes (U32.v sz32)) #rrel #rel b pos -> let _ = store_bytes x 0ul sz32 b pos in sz32 inline_for_extraction let write_flbytes (sz32: U32.t) : Tot (leaf_writer_strong (serialize_flbytes (U32.v sz32))) = leaf_writer_strong_of_serializer32 (serialize32_flbytes sz32) () inline_for_extraction let write_flbytes_weak (sz32: U32.t { U32.v sz32 < 4294967295 } ) // need to return that value if output buffer is too small : Tot (leaf_writer_weak (serialize_flbytes (U32.v sz32))) = leaf_writer_weak_of_strong_constant_size (write_flbytes sz32) sz32 () (* // TODO: remove, since nobody is using this inline_for_extraction let read_flbytes (sz32: U32.t) : Tot (leaf_reader (parse_flbytes (U32.v sz32))) = fun input pos -> let h = HST.get () in [@inline_let] let _ = valid_facts (parse_flbytes (U32.v sz32)) h input pos in BY.of_buffer sz32 (B.sub input.base pos sz32) *) (* Equality test between a vlbytes and a constant lbytes *) #push-options "--z3rlimit 32" inline_for_extraction let buffer_equals_bytes (const: BY.bytes) (#rrel #rel: _) (b: B.mbuffer byte rrel rel) (pos: U32.t) : HST.Stack bool (requires (fun h -> B.live h b /\ U32.v pos + BY.length const <= B.length b )) (ensures (fun h res h' -> B.modifies B.loc_none h h' /\ (res == true <==> Seq.slice (B.as_seq h b) (U32.v pos) (U32.v pos + BY.length const) == BY.reveal const) )) = let h0 = HST.get () in HST.push_frame (); let len = BY.len const in let bi = BF.alloca 0ul 1ul in let bres = BF.alloca true 1ul in let h1 = HST.get () in [@inline_let] let inv (h: HS.mem) (stop: bool) : GTot Type0 = B.modifies (B.loc_union (B.loc_buffer bi) (B.loc_buffer bres)) h1 h /\ ( let length = U32.v len in let i32 = (Seq.index (B.as_seq h bi) 0) in let i = U32.v i32 in let res = Seq.index (B.as_seq h bres) 0 in i <= length /\ (stop == false ==> res == true) /\ ((stop == true /\ res == true) ==> i == length) /\ (res == true <==> Seq.slice (B.as_seq h b) (U32.v pos) (U32.v pos + i) `Seq.equal` Seq.slice (BY.reveal const) 0 i) ) in C.Loops.do_while inv (fun _ -> let i = B.index bi 0ul in if i = len then true else begin let i' = i `U32.add` 1ul in [@inline_let] let _ = let s1 = (Seq.slice (B.as_seq h0 b) (U32.v pos) (U32.v pos + U32.v i)) in let c1 = (B.get h0 b (U32.v pos + U32.v i)) in let s2 = (Seq.slice (BY.reveal const) 0 (U32.v i)) in let c2 = (BY.index const (U32.v i)) in assert (Seq.slice (B.as_seq h0 b) (U32.v pos) (U32.v pos + U32.v i') `Seq.equal` Seq.snoc s1 c1); assert (Seq.slice (BY.reveal const) 0 (U32.v i') `Seq.equal` Seq.snoc s2 c2); Classical.move_requires (Seq.lemma_snoc_inj s1 s2 c1) c2 in let res = B.index b (pos `U32.add` i) = BY.get const i in B.upd bres 0ul res; B.upd bi 0ul i'; not res end ); let res = B.index bres 0ul in HST.pop_frame (); res #pop-options inline_for_extraction let valid_slice_equals_bytes (const: BY.bytes) (#rrel #rel: _) (input: slice rrel rel) (pos: U32.t) : HST.Stack bool (requires (fun h -> valid (parse_flbytes (BY.length const)) h input pos )) (ensures (fun h res h' -> B.modifies B.loc_none h h' /\ (res == true <==> contents (parse_flbytes (BY.length const)) h input pos == const ))) = let h = HST.get () in [@inline_let] let _ = valid_facts (parse_flbytes (BY.length const)) h input pos in buffer_equals_bytes const input.base pos
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowStar.Monotonic.Buffer.fsti.checked", "LowStar.Buffer.fst.checked", "LowParse.Spec.Bytes.fst.checked", "LowParse.Low.VLGen.fst.checked", "LowParse.Low.VLData.fst.checked", "LowParse.Low.Int.fsti.checked", "LowParse.Low.Combinators.fsti.checked", "LowParse.Bytes32.fst.checked", "FStar.UInt8.fsti.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Int.Cast.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked", "FStar.Classical.fsti.checked", "C.Loops.fst.checked" ], "interface_file": false, "source_file": "LowParse.Low.Bytes.fst" }
[ { "abbrev": true, "full_module": "LowStar.Buffer // for local variables in store_bytes", "short_module": "BF" }, { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "FStar.Int.Cast", "short_module": "Cast" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "LowParse.Bytes32", "short_module": "BY" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "BF" }, { "abbrev": true, "full_module": "LowStar.Monotonic.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": false, "full_module": "LowParse.Low.Int", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low.VLGen", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low.VLData", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low.Combinators", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec.Bytes", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
_: Prims.unit -> LowParse.Low.Base.validator LowParse.Spec.Bytes.parse_all_bytes
Prims.Tot
[ "total" ]
[]
[ "Prims.unit", "LowParse.Slice.srel", "LowParse.Bytes.byte", "LowParse.Slice.slice", "FStar.UInt64.t", "FStar.Int.Cast.uint32_to_uint64", "LowParse.Slice.__proj__Mkslice__item__len", "LowParse.Low.Base.Spec.valid_facts", "LowParse.Spec.Bytes.parse_all_bytes_kind", "FStar.Bytes.bytes", "LowParse.Spec.Bytes.parse_all_bytes", "LowParse.Low.ErrorCode.uint64_to_uint32", "FStar.Monotonic.HyperStack.mem", "FStar.HyperStack.ST.get", "LowParse.Low.Base.validator" ]
[]
false
false
false
true
false
let validate_all_bytes () : Tot (validator parse_all_bytes) =
fun #rrel #rel input pos -> let h = HST.get () in [@@ inline_let ]let _ = valid_facts parse_all_bytes h input (uint64_to_uint32 pos) in Cast.uint32_to_uint64 input.len
false
LowParse.Low.Bytes.fst
LowParse.Low.Bytes.valid_slice_equals_bytes
val valid_slice_equals_bytes (const: BY.bytes) (#rrel #rel: _) (input: slice rrel rel) (pos: U32.t) : HST.Stack bool (requires (fun h -> valid (parse_flbytes (BY.length const)) h input pos)) (ensures (fun h res h' -> B.modifies B.loc_none h h' /\ (res == true <==> contents (parse_flbytes (BY.length const)) h input pos == const)))
val valid_slice_equals_bytes (const: BY.bytes) (#rrel #rel: _) (input: slice rrel rel) (pos: U32.t) : HST.Stack bool (requires (fun h -> valid (parse_flbytes (BY.length const)) h input pos)) (ensures (fun h res h' -> B.modifies B.loc_none h h' /\ (res == true <==> contents (parse_flbytes (BY.length const)) h input pos == const)))
let valid_slice_equals_bytes (const: BY.bytes) (#rrel #rel: _) (input: slice rrel rel) (pos: U32.t) : HST.Stack bool (requires (fun h -> valid (parse_flbytes (BY.length const)) h input pos )) (ensures (fun h res h' -> B.modifies B.loc_none h h' /\ (res == true <==> contents (parse_flbytes (BY.length const)) h input pos == const ))) = let h = HST.get () in [@inline_let] let _ = valid_facts (parse_flbytes (BY.length const)) h input pos in buffer_equals_bytes const input.base pos
{ "file_name": "src/lowparse/LowParse.Low.Bytes.fst", "git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
{ "end_col": 42, "end_line": 342, "start_col": 0, "start_line": 327 }
module LowParse.Low.Bytes include LowParse.Spec.Bytes include LowParse.Low.Combinators include LowParse.Low.VLData include LowParse.Low.VLGen include LowParse.Low.Int module U32 = FStar.UInt32 module HS = FStar.HyperStack module B = LowStar.Monotonic.Buffer module BF = LowStar.Buffer // for local variables in store_bytes module BY = LowParse.Bytes32 module HST = FStar.HyperStack.ST module U8 = FStar.UInt8 module Cast = FStar.Int.Cast module U64 = FStar.UInt64 inline_for_extraction let validate_flbytes (sz: nat) (sz64: U64.t { U64.v sz64 == sz /\ sz < 4294967296 } ) : Tot (validator (parse_flbytes sz)) = validate_total_constant_size (parse_flbytes sz) sz64 () inline_for_extraction let jump_flbytes (sz: nat) (sz32: U32.t { U32.v sz32 == sz } ) : Tot (jumper (parse_flbytes sz)) = jump_constant_size (parse_flbytes sz) sz32 () let valid_flbytes_intro (h: HS.mem) (sz: nat { sz < 4294967296 } ) (#rrel #rel: _) (s: slice rrel rel) (pos: U32.t) : Lemma (requires (U32.v pos + sz <= U32.v s.len /\ live_slice h s)) (ensures ( valid_content_pos (parse_flbytes sz) h s pos (BY.hide (bytes_of_slice_from_to h s pos (pos `U32.add` U32.uint_to_t sz))) (pos `U32.add` U32.uint_to_t sz) )) = valid_facts (parse_flbytes sz) h s pos let valid_pos_flbytes_elim (h: HS.mem) (sz: nat { sz < 4294967296 } ) (#rrel #rel: _) (s: slice rrel rel) (pos pos' : U32.t) : Lemma (requires (valid_pos (parse_flbytes sz) h s pos pos')) (ensures (U32.v pos + sz == U32.v pos')) [SMTPat (valid_pos (parse_flbytes sz) h s pos pos')] = valid_facts (parse_flbytes sz) h s pos let valid_flbytes_elim (h: HS.mem) (sz: nat { sz < 4294967296 } ) (#rrel #rel: _) (s: slice rrel rel) (pos: U32.t) : Lemma (requires (valid (parse_flbytes sz) h s pos)) (ensures ( valid_content_pos (parse_flbytes sz) h s pos (BY.hide (bytes_of_slice_from_to h s pos (pos `U32.add` U32.uint_to_t sz))) (pos `U32.add` U32.uint_to_t sz) )) = valid_flbytes_intro h sz s pos let clens_flbytes_slice (sz: nat) (from: U32.t) (to: U32.t {U32.v from <= U32.v to /\ U32.v to <= sz } ) : Tot (clens (BY.lbytes sz) (BY.lbytes (U32.v to - U32.v from))) = { clens_cond = (fun _ -> True); clens_get = (fun (x: BY.lbytes sz) -> (BY.slice x from to <: BY.lbytes (U32.v to - U32.v from))); } #push-options "--z3rlimit 16" let gaccessor_flbytes_slice' (sz: nat { sz < 4294967296 } ) (from: U32.t) (to: U32.t {U32.v from <= U32.v to /\ U32.v to <= sz } ) : Tot (gaccessor' (parse_flbytes sz) (parse_flbytes (U32.v to - U32.v from)) (clens_flbytes_slice sz from to)) = fun (input: bytes) -> ( begin if Seq.length input < sz then (0) // dummy else (U32.v from) end) let gaccessor_flbytes_slice (sz: nat { sz < 4294967296 } ) (from: U32.t) (to: U32.t {U32.v from <= U32.v to /\ U32.v to <= sz } ) : Tot (gaccessor (parse_flbytes sz) (parse_flbytes (U32.v to - U32.v from)) (clens_flbytes_slice sz from to)) = assert (forall x . gaccessor_pre (parse_flbytes sz) (parse_flbytes (U32.v to - U32.v from)) (clens_flbytes_slice sz from to) x ==> sz <= Seq.length x); gaccessor_prop_equiv (parse_flbytes sz) (parse_flbytes (U32.v to - U32.v from)) (clens_flbytes_slice sz from to) (gaccessor_flbytes_slice' sz from to); gaccessor_flbytes_slice' sz from to inline_for_extraction let accessor_flbytes_slice (sz: nat { sz < 4294967296 } ) (from: U32.t) (to: U32.t {U32.v from <= U32.v to /\ U32.v to <= sz } ) : Tot (accessor (gaccessor_flbytes_slice sz from to)) = fun #rrel #rel input pos -> let h = HST.get () in [@inline_let] let _ = slice_access_eq h (gaccessor_flbytes_slice sz from to) input pos in pos `U32.add` from #pop-options let clens_flbytes_get (sz: nat) (i: U32.t { U32.v i < sz } ) : Tot (clens (BY.lbytes sz) byte) = { clens_cond = (fun _ -> True); clens_get = (fun (x: BY.lbytes sz) -> (BY.get x i <: byte)); } #push-options "--z3rlimit 16 --max_fuel 1" let gaccessor_flbytes_get' (sz: nat { sz < 4294967296 } ) (i: U32.t { U32.v i < sz } ) : Tot (gaccessor' (parse_flbytes sz) (parse_u8) (clens_flbytes_get sz i)) = fun (input: bytes) -> ( begin let res = if Seq.length input < U32.v i then (0) // dummy else (U32.v i) in let g () : Lemma (requires (gaccessor_pre (parse_flbytes sz) parse_u8 (clens_flbytes_get sz i) input)) (ensures (gaccessor_post (parse_flbytes sz) parse_u8 (clens_flbytes_get sz i) input res)) = parser_kind_prop_equiv (get_parser_kind parse_u8) parse_u8; assert (res == (U32.v i)); parse_u8_spec' (Seq.slice input (U32.v i) (U32.v i + 1)); parse_strong_prefix parse_u8 (Seq.slice input (U32.v i) (U32.v i + 1)) (Seq.slice input (U32.v i) (Seq.length input)) in Classical.move_requires g (); res end) #pop-options let gaccessor_flbytes_get (sz: nat { sz < 4294967296 } ) (i: U32.t { U32.v i < sz } ) : Tot (gaccessor (parse_flbytes sz) (parse_u8) (clens_flbytes_get sz i)) = assert (forall x . gaccessor_pre (parse_flbytes sz) (parse_u8) (clens_flbytes_get sz i) x ==> U32.v i <= Seq.length x); gaccessor_prop_equiv (parse_flbytes sz) (parse_u8) (clens_flbytes_get sz i) (gaccessor_flbytes_get' sz i); gaccessor_flbytes_get' sz i inline_for_extraction let accessor_flbytes_get (sz: nat { sz < 4294967296 } ) (i: U32.t { U32.v i < sz } ) : Tot (accessor (gaccessor_flbytes_get sz i)) = fun #rrel #rel input pos -> let h = HST.get () in [@inline_let] let _ = slice_access_eq h (gaccessor_flbytes_get sz i) input pos in pos `U32.add` i (* Temporary: flbytes as leaf values *) (* TODO: convert store_bytes to monotonic buffers, using the "writable" predicate *) #push-options "--z3rlimit 32" inline_for_extraction let store_bytes (src: BY.bytes) (src_from src_to: U32.t) (#rrel #rel: _) (dst: B.mbuffer byte rrel rel) (dst_pos: U32.t) : HST.Stack unit (requires (fun h -> B.live h dst /\ U32.v src_from <= U32.v src_to /\ U32.v src_to <= BY.length src /\ U32.v dst_pos + (U32.v src_to - U32.v src_from) <= B.length dst /\ writable dst (U32.v dst_pos) (U32.v dst_pos + (U32.v src_to - U32.v src_from)) h )) (ensures (fun h _ h' -> B.modifies (B.loc_buffer_from_to dst dst_pos (dst_pos `U32.add` (src_to `U32.sub` src_from))) h h' /\ Seq.slice (B.as_seq h' dst) (U32.v dst_pos) (U32.v dst_pos + (U32.v src_to - U32.v src_from)) == Seq.slice (BY.reveal src) (U32.v src_from) (U32.v src_to) )) = let h0 = HST.get () in HST.push_frame (); let h1 = HST.get () in let bi = BF.alloca 0ul 1ul in let h2 = HST.get () in let len = src_to `U32.sub` src_from in C.Loops.do_while (fun h stop -> B.modifies (B.loc_union (B.loc_region_only true (HS.get_tip h1)) (B.loc_buffer_from_to dst dst_pos (dst_pos `U32.add` len))) h2 h /\ B.live h bi /\ ( let i = Seq.index (B.as_seq h bi) 0 in U32.v i <= U32.v len /\ writable dst (U32.v dst_pos) (U32.v dst_pos + U32.v len) h /\ Seq.slice (B.as_seq h dst) (U32.v dst_pos) (U32.v dst_pos + U32.v i) `Seq.equal` Seq.slice (BY.reveal src) (U32.v src_from) (U32.v src_from + U32.v i) /\ (stop == true ==> i == len) )) (fun _ -> let i = B.index bi 0ul in if i = len then true else begin let x = BY.get src (src_from `U32.add` i) in mbuffer_upd dst (Ghost.hide (U32.v dst_pos)) (Ghost.hide (U32.v dst_pos + U32.v len)) (dst_pos `U32.add` i) x; let i' = i `U32.add` 1ul in B.upd bi 0ul i'; let h' = HST.get () in Seq.lemma_split (Seq.slice (B.as_seq h' dst) (U32.v dst_pos) (U32.v dst_pos + U32.v i')) (U32.v i); i' = len end ) ; HST.pop_frame () #pop-options inline_for_extraction let serialize32_flbytes (sz32: U32.t) : Tot (serializer32 (serialize_flbytes (U32.v sz32))) = fun (x: BY.lbytes (U32.v sz32)) #rrel #rel b pos -> let _ = store_bytes x 0ul sz32 b pos in sz32 inline_for_extraction let write_flbytes (sz32: U32.t) : Tot (leaf_writer_strong (serialize_flbytes (U32.v sz32))) = leaf_writer_strong_of_serializer32 (serialize32_flbytes sz32) () inline_for_extraction let write_flbytes_weak (sz32: U32.t { U32.v sz32 < 4294967295 } ) // need to return that value if output buffer is too small : Tot (leaf_writer_weak (serialize_flbytes (U32.v sz32))) = leaf_writer_weak_of_strong_constant_size (write_flbytes sz32) sz32 () (* // TODO: remove, since nobody is using this inline_for_extraction let read_flbytes (sz32: U32.t) : Tot (leaf_reader (parse_flbytes (U32.v sz32))) = fun input pos -> let h = HST.get () in [@inline_let] let _ = valid_facts (parse_flbytes (U32.v sz32)) h input pos in BY.of_buffer sz32 (B.sub input.base pos sz32) *) (* Equality test between a vlbytes and a constant lbytes *) #push-options "--z3rlimit 32" inline_for_extraction let buffer_equals_bytes (const: BY.bytes) (#rrel #rel: _) (b: B.mbuffer byte rrel rel) (pos: U32.t) : HST.Stack bool (requires (fun h -> B.live h b /\ U32.v pos + BY.length const <= B.length b )) (ensures (fun h res h' -> B.modifies B.loc_none h h' /\ (res == true <==> Seq.slice (B.as_seq h b) (U32.v pos) (U32.v pos + BY.length const) == BY.reveal const) )) = let h0 = HST.get () in HST.push_frame (); let len = BY.len const in let bi = BF.alloca 0ul 1ul in let bres = BF.alloca true 1ul in let h1 = HST.get () in [@inline_let] let inv (h: HS.mem) (stop: bool) : GTot Type0 = B.modifies (B.loc_union (B.loc_buffer bi) (B.loc_buffer bres)) h1 h /\ ( let length = U32.v len in let i32 = (Seq.index (B.as_seq h bi) 0) in let i = U32.v i32 in let res = Seq.index (B.as_seq h bres) 0 in i <= length /\ (stop == false ==> res == true) /\ ((stop == true /\ res == true) ==> i == length) /\ (res == true <==> Seq.slice (B.as_seq h b) (U32.v pos) (U32.v pos + i) `Seq.equal` Seq.slice (BY.reveal const) 0 i) ) in C.Loops.do_while inv (fun _ -> let i = B.index bi 0ul in if i = len then true else begin let i' = i `U32.add` 1ul in [@inline_let] let _ = let s1 = (Seq.slice (B.as_seq h0 b) (U32.v pos) (U32.v pos + U32.v i)) in let c1 = (B.get h0 b (U32.v pos + U32.v i)) in let s2 = (Seq.slice (BY.reveal const) 0 (U32.v i)) in let c2 = (BY.index const (U32.v i)) in assert (Seq.slice (B.as_seq h0 b) (U32.v pos) (U32.v pos + U32.v i') `Seq.equal` Seq.snoc s1 c1); assert (Seq.slice (BY.reveal const) 0 (U32.v i') `Seq.equal` Seq.snoc s2 c2); Classical.move_requires (Seq.lemma_snoc_inj s1 s2 c1) c2 in let res = B.index b (pos `U32.add` i) = BY.get const i in B.upd bres 0ul res; B.upd bi 0ul i'; not res end ); let res = B.index bres 0ul in HST.pop_frame (); res #pop-options
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowStar.Monotonic.Buffer.fsti.checked", "LowStar.Buffer.fst.checked", "LowParse.Spec.Bytes.fst.checked", "LowParse.Low.VLGen.fst.checked", "LowParse.Low.VLData.fst.checked", "LowParse.Low.Int.fsti.checked", "LowParse.Low.Combinators.fsti.checked", "LowParse.Bytes32.fst.checked", "FStar.UInt8.fsti.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Int.Cast.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked", "FStar.Classical.fsti.checked", "C.Loops.fst.checked" ], "interface_file": false, "source_file": "LowParse.Low.Bytes.fst" }
[ { "abbrev": true, "full_module": "LowStar.Buffer // for local variables in store_bytes", "short_module": "BF" }, { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "FStar.Int.Cast", "short_module": "Cast" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "LowParse.Bytes32", "short_module": "BY" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "BF" }, { "abbrev": true, "full_module": "LowStar.Monotonic.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": false, "full_module": "LowParse.Low.Int", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low.VLGen", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low.VLData", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low.Combinators", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec.Bytes", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
const: FStar.Bytes.bytes -> input: LowParse.Slice.slice rrel rel -> pos: FStar.UInt32.t -> FStar.HyperStack.ST.Stack Prims.bool
FStar.HyperStack.ST.Stack
[]
[]
[ "FStar.Bytes.bytes", "LowParse.Slice.srel", "LowParse.Bytes.byte", "LowParse.Slice.slice", "FStar.UInt32.t", "LowParse.Low.Bytes.buffer_equals_bytes", "LowParse.Slice.buffer_srel_of_srel", "LowParse.Slice.__proj__Mkslice__item__base", "Prims.bool", "Prims.unit", "LowParse.Low.Base.Spec.valid_facts", "LowParse.Spec.Base.total_constant_size_parser_kind", "FStar.Bytes.length", "FStar.Bytes.lbytes", "LowParse.Spec.Bytes.parse_flbytes", "FStar.Monotonic.HyperStack.mem", "FStar.HyperStack.ST.get", "LowParse.Low.Base.Spec.valid", "Prims.l_and", "LowStar.Monotonic.Buffer.modifies", "LowStar.Monotonic.Buffer.loc_none", "Prims.l_iff", "Prims.eq2", "LowParse.Low.Base.Spec.contents" ]
[]
false
true
false
false
false
let valid_slice_equals_bytes (const: BY.bytes) (#rrel #rel: _) (input: slice rrel rel) (pos: U32.t) : HST.Stack bool (requires (fun h -> valid (parse_flbytes (BY.length const)) h input pos)) (ensures (fun h res h' -> B.modifies B.loc_none h h' /\ (res == true <==> contents (parse_flbytes (BY.length const)) h input pos == const))) =
let h = HST.get () in [@@ inline_let ]let _ = valid_facts (parse_flbytes (BY.length const)) h input pos in buffer_equals_bytes const input.base pos
false
LowParse.Low.Bytes.fst
LowParse.Low.Bytes.clens_vlbytes
val clens_vlbytes (min: nat) (max: nat{min <= max /\ max > 0 /\ max < 4294967296}) (length: nat) : Tot (clens (parse_bounded_vlbytes_t min max) (BY.lbytes length))
val clens_vlbytes (min: nat) (max: nat{min <= max /\ max > 0 /\ max < 4294967296}) (length: nat) : Tot (clens (parse_bounded_vlbytes_t min max) (BY.lbytes length))
let clens_vlbytes (min: nat) (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (length: nat) : Tot (clens (parse_bounded_vlbytes_t min max) (BY.lbytes length)) = { clens_cond = (clens_vlbytes_cond min max length); clens_get = (fun (x: parse_bounded_vlbytes_t min max) -> (x <: Ghost (BY.lbytes length) (requires (clens_vlbytes_cond min max length x)) (ensures (fun _ -> True)))); }
{ "file_name": "src/lowparse/LowParse.Low.Bytes.fst", "git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
{ "end_col": 1, "end_line": 608, "start_col": 0, "start_line": 600 }
module LowParse.Low.Bytes include LowParse.Spec.Bytes include LowParse.Low.Combinators include LowParse.Low.VLData include LowParse.Low.VLGen include LowParse.Low.Int module U32 = FStar.UInt32 module HS = FStar.HyperStack module B = LowStar.Monotonic.Buffer module BF = LowStar.Buffer // for local variables in store_bytes module BY = LowParse.Bytes32 module HST = FStar.HyperStack.ST module U8 = FStar.UInt8 module Cast = FStar.Int.Cast module U64 = FStar.UInt64 inline_for_extraction let validate_flbytes (sz: nat) (sz64: U64.t { U64.v sz64 == sz /\ sz < 4294967296 } ) : Tot (validator (parse_flbytes sz)) = validate_total_constant_size (parse_flbytes sz) sz64 () inline_for_extraction let jump_flbytes (sz: nat) (sz32: U32.t { U32.v sz32 == sz } ) : Tot (jumper (parse_flbytes sz)) = jump_constant_size (parse_flbytes sz) sz32 () let valid_flbytes_intro (h: HS.mem) (sz: nat { sz < 4294967296 } ) (#rrel #rel: _) (s: slice rrel rel) (pos: U32.t) : Lemma (requires (U32.v pos + sz <= U32.v s.len /\ live_slice h s)) (ensures ( valid_content_pos (parse_flbytes sz) h s pos (BY.hide (bytes_of_slice_from_to h s pos (pos `U32.add` U32.uint_to_t sz))) (pos `U32.add` U32.uint_to_t sz) )) = valid_facts (parse_flbytes sz) h s pos let valid_pos_flbytes_elim (h: HS.mem) (sz: nat { sz < 4294967296 } ) (#rrel #rel: _) (s: slice rrel rel) (pos pos' : U32.t) : Lemma (requires (valid_pos (parse_flbytes sz) h s pos pos')) (ensures (U32.v pos + sz == U32.v pos')) [SMTPat (valid_pos (parse_flbytes sz) h s pos pos')] = valid_facts (parse_flbytes sz) h s pos let valid_flbytes_elim (h: HS.mem) (sz: nat { sz < 4294967296 } ) (#rrel #rel: _) (s: slice rrel rel) (pos: U32.t) : Lemma (requires (valid (parse_flbytes sz) h s pos)) (ensures ( valid_content_pos (parse_flbytes sz) h s pos (BY.hide (bytes_of_slice_from_to h s pos (pos `U32.add` U32.uint_to_t sz))) (pos `U32.add` U32.uint_to_t sz) )) = valid_flbytes_intro h sz s pos let clens_flbytes_slice (sz: nat) (from: U32.t) (to: U32.t {U32.v from <= U32.v to /\ U32.v to <= sz } ) : Tot (clens (BY.lbytes sz) (BY.lbytes (U32.v to - U32.v from))) = { clens_cond = (fun _ -> True); clens_get = (fun (x: BY.lbytes sz) -> (BY.slice x from to <: BY.lbytes (U32.v to - U32.v from))); } #push-options "--z3rlimit 16" let gaccessor_flbytes_slice' (sz: nat { sz < 4294967296 } ) (from: U32.t) (to: U32.t {U32.v from <= U32.v to /\ U32.v to <= sz } ) : Tot (gaccessor' (parse_flbytes sz) (parse_flbytes (U32.v to - U32.v from)) (clens_flbytes_slice sz from to)) = fun (input: bytes) -> ( begin if Seq.length input < sz then (0) // dummy else (U32.v from) end) let gaccessor_flbytes_slice (sz: nat { sz < 4294967296 } ) (from: U32.t) (to: U32.t {U32.v from <= U32.v to /\ U32.v to <= sz } ) : Tot (gaccessor (parse_flbytes sz) (parse_flbytes (U32.v to - U32.v from)) (clens_flbytes_slice sz from to)) = assert (forall x . gaccessor_pre (parse_flbytes sz) (parse_flbytes (U32.v to - U32.v from)) (clens_flbytes_slice sz from to) x ==> sz <= Seq.length x); gaccessor_prop_equiv (parse_flbytes sz) (parse_flbytes (U32.v to - U32.v from)) (clens_flbytes_slice sz from to) (gaccessor_flbytes_slice' sz from to); gaccessor_flbytes_slice' sz from to inline_for_extraction let accessor_flbytes_slice (sz: nat { sz < 4294967296 } ) (from: U32.t) (to: U32.t {U32.v from <= U32.v to /\ U32.v to <= sz } ) : Tot (accessor (gaccessor_flbytes_slice sz from to)) = fun #rrel #rel input pos -> let h = HST.get () in [@inline_let] let _ = slice_access_eq h (gaccessor_flbytes_slice sz from to) input pos in pos `U32.add` from #pop-options let clens_flbytes_get (sz: nat) (i: U32.t { U32.v i < sz } ) : Tot (clens (BY.lbytes sz) byte) = { clens_cond = (fun _ -> True); clens_get = (fun (x: BY.lbytes sz) -> (BY.get x i <: byte)); } #push-options "--z3rlimit 16 --max_fuel 1" let gaccessor_flbytes_get' (sz: nat { sz < 4294967296 } ) (i: U32.t { U32.v i < sz } ) : Tot (gaccessor' (parse_flbytes sz) (parse_u8) (clens_flbytes_get sz i)) = fun (input: bytes) -> ( begin let res = if Seq.length input < U32.v i then (0) // dummy else (U32.v i) in let g () : Lemma (requires (gaccessor_pre (parse_flbytes sz) parse_u8 (clens_flbytes_get sz i) input)) (ensures (gaccessor_post (parse_flbytes sz) parse_u8 (clens_flbytes_get sz i) input res)) = parser_kind_prop_equiv (get_parser_kind parse_u8) parse_u8; assert (res == (U32.v i)); parse_u8_spec' (Seq.slice input (U32.v i) (U32.v i + 1)); parse_strong_prefix parse_u8 (Seq.slice input (U32.v i) (U32.v i + 1)) (Seq.slice input (U32.v i) (Seq.length input)) in Classical.move_requires g (); res end) #pop-options let gaccessor_flbytes_get (sz: nat { sz < 4294967296 } ) (i: U32.t { U32.v i < sz } ) : Tot (gaccessor (parse_flbytes sz) (parse_u8) (clens_flbytes_get sz i)) = assert (forall x . gaccessor_pre (parse_flbytes sz) (parse_u8) (clens_flbytes_get sz i) x ==> U32.v i <= Seq.length x); gaccessor_prop_equiv (parse_flbytes sz) (parse_u8) (clens_flbytes_get sz i) (gaccessor_flbytes_get' sz i); gaccessor_flbytes_get' sz i inline_for_extraction let accessor_flbytes_get (sz: nat { sz < 4294967296 } ) (i: U32.t { U32.v i < sz } ) : Tot (accessor (gaccessor_flbytes_get sz i)) = fun #rrel #rel input pos -> let h = HST.get () in [@inline_let] let _ = slice_access_eq h (gaccessor_flbytes_get sz i) input pos in pos `U32.add` i (* Temporary: flbytes as leaf values *) (* TODO: convert store_bytes to monotonic buffers, using the "writable" predicate *) #push-options "--z3rlimit 32" inline_for_extraction let store_bytes (src: BY.bytes) (src_from src_to: U32.t) (#rrel #rel: _) (dst: B.mbuffer byte rrel rel) (dst_pos: U32.t) : HST.Stack unit (requires (fun h -> B.live h dst /\ U32.v src_from <= U32.v src_to /\ U32.v src_to <= BY.length src /\ U32.v dst_pos + (U32.v src_to - U32.v src_from) <= B.length dst /\ writable dst (U32.v dst_pos) (U32.v dst_pos + (U32.v src_to - U32.v src_from)) h )) (ensures (fun h _ h' -> B.modifies (B.loc_buffer_from_to dst dst_pos (dst_pos `U32.add` (src_to `U32.sub` src_from))) h h' /\ Seq.slice (B.as_seq h' dst) (U32.v dst_pos) (U32.v dst_pos + (U32.v src_to - U32.v src_from)) == Seq.slice (BY.reveal src) (U32.v src_from) (U32.v src_to) )) = let h0 = HST.get () in HST.push_frame (); let h1 = HST.get () in let bi = BF.alloca 0ul 1ul in let h2 = HST.get () in let len = src_to `U32.sub` src_from in C.Loops.do_while (fun h stop -> B.modifies (B.loc_union (B.loc_region_only true (HS.get_tip h1)) (B.loc_buffer_from_to dst dst_pos (dst_pos `U32.add` len))) h2 h /\ B.live h bi /\ ( let i = Seq.index (B.as_seq h bi) 0 in U32.v i <= U32.v len /\ writable dst (U32.v dst_pos) (U32.v dst_pos + U32.v len) h /\ Seq.slice (B.as_seq h dst) (U32.v dst_pos) (U32.v dst_pos + U32.v i) `Seq.equal` Seq.slice (BY.reveal src) (U32.v src_from) (U32.v src_from + U32.v i) /\ (stop == true ==> i == len) )) (fun _ -> let i = B.index bi 0ul in if i = len then true else begin let x = BY.get src (src_from `U32.add` i) in mbuffer_upd dst (Ghost.hide (U32.v dst_pos)) (Ghost.hide (U32.v dst_pos + U32.v len)) (dst_pos `U32.add` i) x; let i' = i `U32.add` 1ul in B.upd bi 0ul i'; let h' = HST.get () in Seq.lemma_split (Seq.slice (B.as_seq h' dst) (U32.v dst_pos) (U32.v dst_pos + U32.v i')) (U32.v i); i' = len end ) ; HST.pop_frame () #pop-options inline_for_extraction let serialize32_flbytes (sz32: U32.t) : Tot (serializer32 (serialize_flbytes (U32.v sz32))) = fun (x: BY.lbytes (U32.v sz32)) #rrel #rel b pos -> let _ = store_bytes x 0ul sz32 b pos in sz32 inline_for_extraction let write_flbytes (sz32: U32.t) : Tot (leaf_writer_strong (serialize_flbytes (U32.v sz32))) = leaf_writer_strong_of_serializer32 (serialize32_flbytes sz32) () inline_for_extraction let write_flbytes_weak (sz32: U32.t { U32.v sz32 < 4294967295 } ) // need to return that value if output buffer is too small : Tot (leaf_writer_weak (serialize_flbytes (U32.v sz32))) = leaf_writer_weak_of_strong_constant_size (write_flbytes sz32) sz32 () (* // TODO: remove, since nobody is using this inline_for_extraction let read_flbytes (sz32: U32.t) : Tot (leaf_reader (parse_flbytes (U32.v sz32))) = fun input pos -> let h = HST.get () in [@inline_let] let _ = valid_facts (parse_flbytes (U32.v sz32)) h input pos in BY.of_buffer sz32 (B.sub input.base pos sz32) *) (* Equality test between a vlbytes and a constant lbytes *) #push-options "--z3rlimit 32" inline_for_extraction let buffer_equals_bytes (const: BY.bytes) (#rrel #rel: _) (b: B.mbuffer byte rrel rel) (pos: U32.t) : HST.Stack bool (requires (fun h -> B.live h b /\ U32.v pos + BY.length const <= B.length b )) (ensures (fun h res h' -> B.modifies B.loc_none h h' /\ (res == true <==> Seq.slice (B.as_seq h b) (U32.v pos) (U32.v pos + BY.length const) == BY.reveal const) )) = let h0 = HST.get () in HST.push_frame (); let len = BY.len const in let bi = BF.alloca 0ul 1ul in let bres = BF.alloca true 1ul in let h1 = HST.get () in [@inline_let] let inv (h: HS.mem) (stop: bool) : GTot Type0 = B.modifies (B.loc_union (B.loc_buffer bi) (B.loc_buffer bres)) h1 h /\ ( let length = U32.v len in let i32 = (Seq.index (B.as_seq h bi) 0) in let i = U32.v i32 in let res = Seq.index (B.as_seq h bres) 0 in i <= length /\ (stop == false ==> res == true) /\ ((stop == true /\ res == true) ==> i == length) /\ (res == true <==> Seq.slice (B.as_seq h b) (U32.v pos) (U32.v pos + i) `Seq.equal` Seq.slice (BY.reveal const) 0 i) ) in C.Loops.do_while inv (fun _ -> let i = B.index bi 0ul in if i = len then true else begin let i' = i `U32.add` 1ul in [@inline_let] let _ = let s1 = (Seq.slice (B.as_seq h0 b) (U32.v pos) (U32.v pos + U32.v i)) in let c1 = (B.get h0 b (U32.v pos + U32.v i)) in let s2 = (Seq.slice (BY.reveal const) 0 (U32.v i)) in let c2 = (BY.index const (U32.v i)) in assert (Seq.slice (B.as_seq h0 b) (U32.v pos) (U32.v pos + U32.v i') `Seq.equal` Seq.snoc s1 c1); assert (Seq.slice (BY.reveal const) 0 (U32.v i') `Seq.equal` Seq.snoc s2 c2); Classical.move_requires (Seq.lemma_snoc_inj s1 s2 c1) c2 in let res = B.index b (pos `U32.add` i) = BY.get const i in B.upd bres 0ul res; B.upd bi 0ul i'; not res end ); let res = B.index bres 0ul in HST.pop_frame (); res #pop-options inline_for_extraction let valid_slice_equals_bytes (const: BY.bytes) (#rrel #rel: _) (input: slice rrel rel) (pos: U32.t) : HST.Stack bool (requires (fun h -> valid (parse_flbytes (BY.length const)) h input pos )) (ensures (fun h res h' -> B.modifies B.loc_none h h' /\ (res == true <==> contents (parse_flbytes (BY.length const)) h input pos == const ))) = let h = HST.get () in [@inline_let] let _ = valid_facts (parse_flbytes (BY.length const)) h input pos in buffer_equals_bytes const input.base pos inline_for_extraction let validate_all_bytes () : Tot (validator parse_all_bytes) = fun #rrel #rel input pos -> let h = HST.get () in [@inline_let] let _ = valid_facts parse_all_bytes h input (uint64_to_uint32 pos) in Cast.uint32_to_uint64 input.len inline_for_extraction let validate_bounded_vlbytes' (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (l: nat { l >= log256' max /\ l <= 4 } ) : Tot (validator (parse_bounded_vlbytes' min max l)) = validate_synth (validate_bounded_vldata_strong' min max l serialize_all_bytes (validate_all_bytes ())) (synth_bounded_vlbytes min max) () inline_for_extraction let validate_bounded_vlbytes (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) : Tot (validator (parse_bounded_vlbytes min max)) = validate_bounded_vlbytes' min max (log256' max) inline_for_extraction let jump_all_bytes () : Tot (jumper parse_all_bytes) = fun #rrel #rel input pos -> let h = HST.get () in [@inline_let] let _ = valid_facts parse_all_bytes h input pos in input.len inline_for_extraction let jump_bounded_vlbytes' (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (l: nat { l >= log256' max /\ l <= 4 } ) : Tot (jumper (parse_bounded_vlbytes' min max l)) = jump_synth (jump_bounded_vldata_strong' min max l serialize_all_bytes) (synth_bounded_vlbytes min max) () inline_for_extraction let jump_bounded_vlbytes (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) : Tot (jumper (parse_bounded_vlbytes min max)) = jump_bounded_vlbytes' min max (log256' max) let valid_exact_all_bytes_elim (h: HS.mem) (#rrel #rel: _) (input: slice rrel rel) (pos pos' : U32.t) : Lemma (requires (valid_exact parse_all_bytes h input pos pos')) (ensures ( let x = contents_exact parse_all_bytes h input pos pos' in let length = U32.v pos' - U32.v pos in BY.length x == length /\ valid_content_pos (parse_flbytes length) h input pos x pos' )) = valid_exact_equiv parse_all_bytes h input pos pos' ; contents_exact_eq parse_all_bytes h input pos pos' ; let length = U32.v pos' - U32.v pos in valid_facts (parse_flbytes length) h input pos ; assert (no_lookahead_on (parse_flbytes length) (bytes_of_slice_from_to h input pos pos') (bytes_of_slice_from h input pos)); assert (injective_postcond (parse_flbytes length) (bytes_of_slice_from_to h input pos pos') (bytes_of_slice_from h input pos)) #push-options "--z3rlimit 32" let valid_bounded_vlbytes'_elim (h: HS.mem) (min: nat) (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (l: nat { l >= log256' max /\ l <= 4 } ) (#rrel #rel: _) (input: slice rrel rel) (pos: U32.t) : Lemma (requires ( valid (parse_bounded_vlbytes' min max l) h input pos )) (ensures ( let sz = l in valid (parse_bounded_integer sz) h input pos /\ ( let len_payload = contents (parse_bounded_integer sz) h input pos in min <= U32.v len_payload /\ U32.v len_payload <= max /\ sz + U32.v len_payload == content_length (parse_bounded_vlbytes' min max l) h input pos /\ ( let pos_payload = pos `U32.add` U32.uint_to_t sz in let x = contents (parse_bounded_vlbytes' min max l) h input pos in BY.len x == len_payload /\ valid_pos (parse_bounded_vlbytes' min max l) h input pos (pos_payload `U32.add` len_payload) /\ valid_content_pos (parse_flbytes (U32.v len_payload)) h input pos_payload x (pos_payload `U32.add` len_payload) )))) = valid_synth h (parse_bounded_vlbytes_aux min max l) (synth_bounded_vlbytes min max) input pos; valid_bounded_vldata_strong'_elim h min max l serialize_all_bytes input pos; let sz = l in let len_payload = contents (parse_bounded_integer sz) h input pos in let pos_payload = pos `U32.add` U32.uint_to_t sz in valid_exact_all_bytes_elim h input pos_payload (pos_payload `U32.add` len_payload); () #pop-options let valid_bounded_vlbytes_elim (h: HS.mem) (min: nat) (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (#rrel #rel: _) (input: slice rrel rel) (pos: U32.t) : Lemma (requires ( valid (parse_bounded_vlbytes min max) h input pos )) (ensures ( let sz = log256' max in valid (parse_bounded_integer sz) h input pos /\ ( let len_payload = contents (parse_bounded_integer sz) h input pos in min <= U32.v len_payload /\ U32.v len_payload <= max /\ sz + U32.v len_payload == content_length (parse_bounded_vlbytes min max) h input pos /\ ( let pos_payload = pos `U32.add` U32.uint_to_t sz in let x = contents (parse_bounded_vlbytes min max) h input pos in BY.len x == len_payload /\ valid_pos (parse_bounded_vlbytes min max) h input pos (pos_payload `U32.add` len_payload) /\ valid_content_pos (parse_flbytes (U32.v len_payload)) h input pos_payload x (pos_payload `U32.add` len_payload) )))) = valid_bounded_vlbytes'_elim h min max (log256' max) input pos let valid_bounded_vlbytes_elim_length (h: HS.mem) (min: nat) (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (#rrel #rel: _) (input: slice rrel rel) (pos: U32.t) : Lemma (requires ( valid (parse_bounded_vlbytes min max) h input pos )) (ensures ( content_length (parse_bounded_vlbytes min max) h input pos == log256' max + BY.length (contents (parse_bounded_vlbytes min max) h input pos) )) [SMTPat (valid (parse_bounded_vlbytes min max) h input pos)] = valid_bounded_vlbytes_elim h min max input pos inline_for_extraction let bounded_vlbytes'_payload_length (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (l: nat { l >= log256' max /\ l <= 4 } ) (#rrel #rel: _) (input: slice rrel rel) (pos: U32.t) : HST.Stack U32.t (requires (fun h -> valid (parse_bounded_vlbytes' min max l) h input pos)) (ensures (fun h len h' -> B.modifies B.loc_none h h' /\ U32.v pos + l + U32.v len <= U32.v input.len /\ ( let x = contents (parse_bounded_vlbytes' min max l) h input pos in let pos' = get_valid_pos (parse_bounded_vlbytes' min max l) h input pos in BY.len x == len /\ valid_content_pos (parse_flbytes (U32.v len)) h input (pos `U32.add` U32.uint_to_t l) x pos' /\ bytes_of_slice_from_to h input (pos `U32.add` U32.uint_to_t l) pos' == BY.reveal x ))) = let h = HST.get () in [@inline_let] let _ = valid_bounded_vlbytes'_elim h min max l input pos in let len = read_bounded_integer l input pos in [@inline_let] let _ = valid_flbytes_elim h (U32.v len) input (pos `U32.add` U32.uint_to_t l) in len inline_for_extraction let bounded_vlbytes_payload_length (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (#rrel #rel: _) (input: slice rrel rel) (pos: U32.t) : HST.Stack U32.t (requires (fun h -> valid (parse_bounded_vlbytes min max) h input pos)) (ensures (fun h len h' -> B.modifies B.loc_none h h' /\ U32.v pos + log256' max + U32.v len <= U32.v input.len /\ ( let x = contents (parse_bounded_vlbytes min max) h input pos in let pos' = get_valid_pos (parse_bounded_vlbytes min max) h input pos in BY.len x == len /\ valid_content_pos (parse_flbytes (U32.v len)) h input (pos `U32.add` U32.uint_to_t (log256' max)) x pos' /\ bytes_of_slice_from_to h input (pos `U32.add` U32.uint_to_t (log256' max)) pos' == BY.reveal x ))) = bounded_vlbytes'_payload_length min max (log256' max) input pos (* Get the content buffer (with trivial buffers only, not generalizable to monotonicity) *) #push-options "--z3rlimit 32" inline_for_extraction let get_vlbytes'_contents (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (l: nat { l >= log256' max /\ l <= 4 } ) (input: slice (srel_of_buffer_srel (BF.trivial_preorder _)) (srel_of_buffer_srel (BF.trivial_preorder _))) (pos: U32.t) : HST.Stack (BF.buffer byte) (requires (fun h -> valid (parse_bounded_vlbytes' min max l) h input pos)) (ensures (fun h b h' -> let x = contents (parse_bounded_vlbytes' min max l) h input pos in B.modifies B.loc_none h h' /\ U32.v pos + l + BY.length x <= U32.v input.len /\ b == BF.gsub input.base (pos `U32.add` U32.uint_to_t l) (BY.len x) /\ B.as_seq h b == BY.reveal x )) = let h = HST.get () in [@inline_let] let _ = valid_bounded_vlbytes'_elim h min max l input pos in let len = read_bounded_integer l input pos in [@inline_let] let _ = valid_facts (parse_flbytes (U32.v len)) h input (pos `U32.add` U32.uint_to_t l) in BF.sub input.base (pos `U32.add` U32.uint_to_t l) len #pop-options inline_for_extraction let get_vlbytes_contents (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (input: slice (srel_of_buffer_srel (BF.trivial_preorder _)) (srel_of_buffer_srel (BF.trivial_preorder _))) (pos: U32.t) : HST.Stack (BF.buffer byte) (requires (fun h -> valid (parse_bounded_vlbytes min max) h input pos)) (ensures (fun h b h' -> let l = log256' max in let x = contents (parse_bounded_vlbytes min max) h input pos in B.modifies B.loc_none h h' /\ U32.v pos + l + BY.length x <= U32.v input.len /\ b == BF.gsub input.base (pos `U32.add` U32.uint_to_t l) (BY.len x) /\ B.as_seq h b == BY.reveal x )) = get_vlbytes'_contents min max (log256' max) input pos (* In fact, the following accessors are not useful in practice, because users would need to have the flbytes parser combinator in their scope *) let clens_vlbytes_cond (min: nat) (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (length: nat) (x: parse_bounded_vlbytes_t min max) : GTot Type0 = BY.length x == length
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowStar.Monotonic.Buffer.fsti.checked", "LowStar.Buffer.fst.checked", "LowParse.Spec.Bytes.fst.checked", "LowParse.Low.VLGen.fst.checked", "LowParse.Low.VLData.fst.checked", "LowParse.Low.Int.fsti.checked", "LowParse.Low.Combinators.fsti.checked", "LowParse.Bytes32.fst.checked", "FStar.UInt8.fsti.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Int.Cast.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked", "FStar.Classical.fsti.checked", "C.Loops.fst.checked" ], "interface_file": false, "source_file": "LowParse.Low.Bytes.fst" }
[ { "abbrev": true, "full_module": "LowStar.Buffer // for local variables in store_bytes", "short_module": "BF" }, { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "FStar.Int.Cast", "short_module": "Cast" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "LowParse.Bytes32", "short_module": "BY" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "BF" }, { "abbrev": true, "full_module": "LowStar.Monotonic.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": false, "full_module": "LowParse.Low.Int", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low.VLGen", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low.VLData", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low.Combinators", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec.Bytes", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
min: Prims.nat -> max: Prims.nat{min <= max /\ max > 0 /\ max < 4294967296} -> length: Prims.nat -> LowParse.Low.Base.Spec.clens (LowParse.Spec.Bytes.parse_bounded_vlbytes_t min max) (FStar.Bytes.lbytes length)
Prims.Tot
[ "total" ]
[]
[ "Prims.nat", "Prims.l_and", "Prims.b2t", "Prims.op_LessThanOrEqual", "Prims.op_GreaterThan", "Prims.op_LessThan", "LowParse.Low.Base.Spec.Mkclens", "LowParse.Spec.Bytes.parse_bounded_vlbytes_t", "FStar.Bytes.lbytes", "LowParse.Low.Bytes.clens_vlbytes_cond", "Prims.l_True", "LowParse.Low.Base.Spec.clens" ]
[]
false
false
false
false
false
let clens_vlbytes (min: nat) (max: nat{min <= max /\ max > 0 /\ max < 4294967296}) (length: nat) : Tot (clens (parse_bounded_vlbytes_t min max) (BY.lbytes length)) =
{ clens_cond = (clens_vlbytes_cond min max length); clens_get = (fun (x: parse_bounded_vlbytes_t min max) -> (x <: Ghost (BY.lbytes length) (requires (clens_vlbytes_cond min max length x)) (ensures (fun _ -> True)))) }
false
LowParse.Low.Bytes.fst
LowParse.Low.Bytes.clens_vlbytes_slice
val clens_vlbytes_slice (min: nat) (max: nat{min <= max /\ max > 0 /\ max < 4294967296}) (from: U32.t) (to: U32.t{U32.v from <= U32.v to /\ U32.v to <= max}) : Tot (clens (parse_bounded_vlbytes_t min max) (BY.lbytes (U32.v to - U32.v from)))
val clens_vlbytes_slice (min: nat) (max: nat{min <= max /\ max > 0 /\ max < 4294967296}) (from: U32.t) (to: U32.t{U32.v from <= U32.v to /\ U32.v to <= max}) : Tot (clens (parse_bounded_vlbytes_t min max) (BY.lbytes (U32.v to - U32.v from)))
let clens_vlbytes_slice (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (from: U32.t) (to: U32.t {U32.v from <= U32.v to /\ U32.v to <= max } ) : Tot (clens (parse_bounded_vlbytes_t min max) (BY.lbytes (U32.v to - U32.v from))) = { clens_cond = (fun (x: parse_bounded_vlbytes_t min max) -> U32.v to <= BY.length x); clens_get = (fun (x: parse_bounded_vlbytes_t min max) -> (BY.slice x from to <: BY.lbytes (U32.v to - U32.v from))); }
{ "file_name": "src/lowparse/LowParse.Low.Bytes.fst", "git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
{ "end_col": 1, "end_line": 692, "start_col": 0, "start_line": 683 }
module LowParse.Low.Bytes include LowParse.Spec.Bytes include LowParse.Low.Combinators include LowParse.Low.VLData include LowParse.Low.VLGen include LowParse.Low.Int module U32 = FStar.UInt32 module HS = FStar.HyperStack module B = LowStar.Monotonic.Buffer module BF = LowStar.Buffer // for local variables in store_bytes module BY = LowParse.Bytes32 module HST = FStar.HyperStack.ST module U8 = FStar.UInt8 module Cast = FStar.Int.Cast module U64 = FStar.UInt64 inline_for_extraction let validate_flbytes (sz: nat) (sz64: U64.t { U64.v sz64 == sz /\ sz < 4294967296 } ) : Tot (validator (parse_flbytes sz)) = validate_total_constant_size (parse_flbytes sz) sz64 () inline_for_extraction let jump_flbytes (sz: nat) (sz32: U32.t { U32.v sz32 == sz } ) : Tot (jumper (parse_flbytes sz)) = jump_constant_size (parse_flbytes sz) sz32 () let valid_flbytes_intro (h: HS.mem) (sz: nat { sz < 4294967296 } ) (#rrel #rel: _) (s: slice rrel rel) (pos: U32.t) : Lemma (requires (U32.v pos + sz <= U32.v s.len /\ live_slice h s)) (ensures ( valid_content_pos (parse_flbytes sz) h s pos (BY.hide (bytes_of_slice_from_to h s pos (pos `U32.add` U32.uint_to_t sz))) (pos `U32.add` U32.uint_to_t sz) )) = valid_facts (parse_flbytes sz) h s pos let valid_pos_flbytes_elim (h: HS.mem) (sz: nat { sz < 4294967296 } ) (#rrel #rel: _) (s: slice rrel rel) (pos pos' : U32.t) : Lemma (requires (valid_pos (parse_flbytes sz) h s pos pos')) (ensures (U32.v pos + sz == U32.v pos')) [SMTPat (valid_pos (parse_flbytes sz) h s pos pos')] = valid_facts (parse_flbytes sz) h s pos let valid_flbytes_elim (h: HS.mem) (sz: nat { sz < 4294967296 } ) (#rrel #rel: _) (s: slice rrel rel) (pos: U32.t) : Lemma (requires (valid (parse_flbytes sz) h s pos)) (ensures ( valid_content_pos (parse_flbytes sz) h s pos (BY.hide (bytes_of_slice_from_to h s pos (pos `U32.add` U32.uint_to_t sz))) (pos `U32.add` U32.uint_to_t sz) )) = valid_flbytes_intro h sz s pos let clens_flbytes_slice (sz: nat) (from: U32.t) (to: U32.t {U32.v from <= U32.v to /\ U32.v to <= sz } ) : Tot (clens (BY.lbytes sz) (BY.lbytes (U32.v to - U32.v from))) = { clens_cond = (fun _ -> True); clens_get = (fun (x: BY.lbytes sz) -> (BY.slice x from to <: BY.lbytes (U32.v to - U32.v from))); } #push-options "--z3rlimit 16" let gaccessor_flbytes_slice' (sz: nat { sz < 4294967296 } ) (from: U32.t) (to: U32.t {U32.v from <= U32.v to /\ U32.v to <= sz } ) : Tot (gaccessor' (parse_flbytes sz) (parse_flbytes (U32.v to - U32.v from)) (clens_flbytes_slice sz from to)) = fun (input: bytes) -> ( begin if Seq.length input < sz then (0) // dummy else (U32.v from) end) let gaccessor_flbytes_slice (sz: nat { sz < 4294967296 } ) (from: U32.t) (to: U32.t {U32.v from <= U32.v to /\ U32.v to <= sz } ) : Tot (gaccessor (parse_flbytes sz) (parse_flbytes (U32.v to - U32.v from)) (clens_flbytes_slice sz from to)) = assert (forall x . gaccessor_pre (parse_flbytes sz) (parse_flbytes (U32.v to - U32.v from)) (clens_flbytes_slice sz from to) x ==> sz <= Seq.length x); gaccessor_prop_equiv (parse_flbytes sz) (parse_flbytes (U32.v to - U32.v from)) (clens_flbytes_slice sz from to) (gaccessor_flbytes_slice' sz from to); gaccessor_flbytes_slice' sz from to inline_for_extraction let accessor_flbytes_slice (sz: nat { sz < 4294967296 } ) (from: U32.t) (to: U32.t {U32.v from <= U32.v to /\ U32.v to <= sz } ) : Tot (accessor (gaccessor_flbytes_slice sz from to)) = fun #rrel #rel input pos -> let h = HST.get () in [@inline_let] let _ = slice_access_eq h (gaccessor_flbytes_slice sz from to) input pos in pos `U32.add` from #pop-options let clens_flbytes_get (sz: nat) (i: U32.t { U32.v i < sz } ) : Tot (clens (BY.lbytes sz) byte) = { clens_cond = (fun _ -> True); clens_get = (fun (x: BY.lbytes sz) -> (BY.get x i <: byte)); } #push-options "--z3rlimit 16 --max_fuel 1" let gaccessor_flbytes_get' (sz: nat { sz < 4294967296 } ) (i: U32.t { U32.v i < sz } ) : Tot (gaccessor' (parse_flbytes sz) (parse_u8) (clens_flbytes_get sz i)) = fun (input: bytes) -> ( begin let res = if Seq.length input < U32.v i then (0) // dummy else (U32.v i) in let g () : Lemma (requires (gaccessor_pre (parse_flbytes sz) parse_u8 (clens_flbytes_get sz i) input)) (ensures (gaccessor_post (parse_flbytes sz) parse_u8 (clens_flbytes_get sz i) input res)) = parser_kind_prop_equiv (get_parser_kind parse_u8) parse_u8; assert (res == (U32.v i)); parse_u8_spec' (Seq.slice input (U32.v i) (U32.v i + 1)); parse_strong_prefix parse_u8 (Seq.slice input (U32.v i) (U32.v i + 1)) (Seq.slice input (U32.v i) (Seq.length input)) in Classical.move_requires g (); res end) #pop-options let gaccessor_flbytes_get (sz: nat { sz < 4294967296 } ) (i: U32.t { U32.v i < sz } ) : Tot (gaccessor (parse_flbytes sz) (parse_u8) (clens_flbytes_get sz i)) = assert (forall x . gaccessor_pre (parse_flbytes sz) (parse_u8) (clens_flbytes_get sz i) x ==> U32.v i <= Seq.length x); gaccessor_prop_equiv (parse_flbytes sz) (parse_u8) (clens_flbytes_get sz i) (gaccessor_flbytes_get' sz i); gaccessor_flbytes_get' sz i inline_for_extraction let accessor_flbytes_get (sz: nat { sz < 4294967296 } ) (i: U32.t { U32.v i < sz } ) : Tot (accessor (gaccessor_flbytes_get sz i)) = fun #rrel #rel input pos -> let h = HST.get () in [@inline_let] let _ = slice_access_eq h (gaccessor_flbytes_get sz i) input pos in pos `U32.add` i (* Temporary: flbytes as leaf values *) (* TODO: convert store_bytes to monotonic buffers, using the "writable" predicate *) #push-options "--z3rlimit 32" inline_for_extraction let store_bytes (src: BY.bytes) (src_from src_to: U32.t) (#rrel #rel: _) (dst: B.mbuffer byte rrel rel) (dst_pos: U32.t) : HST.Stack unit (requires (fun h -> B.live h dst /\ U32.v src_from <= U32.v src_to /\ U32.v src_to <= BY.length src /\ U32.v dst_pos + (U32.v src_to - U32.v src_from) <= B.length dst /\ writable dst (U32.v dst_pos) (U32.v dst_pos + (U32.v src_to - U32.v src_from)) h )) (ensures (fun h _ h' -> B.modifies (B.loc_buffer_from_to dst dst_pos (dst_pos `U32.add` (src_to `U32.sub` src_from))) h h' /\ Seq.slice (B.as_seq h' dst) (U32.v dst_pos) (U32.v dst_pos + (U32.v src_to - U32.v src_from)) == Seq.slice (BY.reveal src) (U32.v src_from) (U32.v src_to) )) = let h0 = HST.get () in HST.push_frame (); let h1 = HST.get () in let bi = BF.alloca 0ul 1ul in let h2 = HST.get () in let len = src_to `U32.sub` src_from in C.Loops.do_while (fun h stop -> B.modifies (B.loc_union (B.loc_region_only true (HS.get_tip h1)) (B.loc_buffer_from_to dst dst_pos (dst_pos `U32.add` len))) h2 h /\ B.live h bi /\ ( let i = Seq.index (B.as_seq h bi) 0 in U32.v i <= U32.v len /\ writable dst (U32.v dst_pos) (U32.v dst_pos + U32.v len) h /\ Seq.slice (B.as_seq h dst) (U32.v dst_pos) (U32.v dst_pos + U32.v i) `Seq.equal` Seq.slice (BY.reveal src) (U32.v src_from) (U32.v src_from + U32.v i) /\ (stop == true ==> i == len) )) (fun _ -> let i = B.index bi 0ul in if i = len then true else begin let x = BY.get src (src_from `U32.add` i) in mbuffer_upd dst (Ghost.hide (U32.v dst_pos)) (Ghost.hide (U32.v dst_pos + U32.v len)) (dst_pos `U32.add` i) x; let i' = i `U32.add` 1ul in B.upd bi 0ul i'; let h' = HST.get () in Seq.lemma_split (Seq.slice (B.as_seq h' dst) (U32.v dst_pos) (U32.v dst_pos + U32.v i')) (U32.v i); i' = len end ) ; HST.pop_frame () #pop-options inline_for_extraction let serialize32_flbytes (sz32: U32.t) : Tot (serializer32 (serialize_flbytes (U32.v sz32))) = fun (x: BY.lbytes (U32.v sz32)) #rrel #rel b pos -> let _ = store_bytes x 0ul sz32 b pos in sz32 inline_for_extraction let write_flbytes (sz32: U32.t) : Tot (leaf_writer_strong (serialize_flbytes (U32.v sz32))) = leaf_writer_strong_of_serializer32 (serialize32_flbytes sz32) () inline_for_extraction let write_flbytes_weak (sz32: U32.t { U32.v sz32 < 4294967295 } ) // need to return that value if output buffer is too small : Tot (leaf_writer_weak (serialize_flbytes (U32.v sz32))) = leaf_writer_weak_of_strong_constant_size (write_flbytes sz32) sz32 () (* // TODO: remove, since nobody is using this inline_for_extraction let read_flbytes (sz32: U32.t) : Tot (leaf_reader (parse_flbytes (U32.v sz32))) = fun input pos -> let h = HST.get () in [@inline_let] let _ = valid_facts (parse_flbytes (U32.v sz32)) h input pos in BY.of_buffer sz32 (B.sub input.base pos sz32) *) (* Equality test between a vlbytes and a constant lbytes *) #push-options "--z3rlimit 32" inline_for_extraction let buffer_equals_bytes (const: BY.bytes) (#rrel #rel: _) (b: B.mbuffer byte rrel rel) (pos: U32.t) : HST.Stack bool (requires (fun h -> B.live h b /\ U32.v pos + BY.length const <= B.length b )) (ensures (fun h res h' -> B.modifies B.loc_none h h' /\ (res == true <==> Seq.slice (B.as_seq h b) (U32.v pos) (U32.v pos + BY.length const) == BY.reveal const) )) = let h0 = HST.get () in HST.push_frame (); let len = BY.len const in let bi = BF.alloca 0ul 1ul in let bres = BF.alloca true 1ul in let h1 = HST.get () in [@inline_let] let inv (h: HS.mem) (stop: bool) : GTot Type0 = B.modifies (B.loc_union (B.loc_buffer bi) (B.loc_buffer bres)) h1 h /\ ( let length = U32.v len in let i32 = (Seq.index (B.as_seq h bi) 0) in let i = U32.v i32 in let res = Seq.index (B.as_seq h bres) 0 in i <= length /\ (stop == false ==> res == true) /\ ((stop == true /\ res == true) ==> i == length) /\ (res == true <==> Seq.slice (B.as_seq h b) (U32.v pos) (U32.v pos + i) `Seq.equal` Seq.slice (BY.reveal const) 0 i) ) in C.Loops.do_while inv (fun _ -> let i = B.index bi 0ul in if i = len then true else begin let i' = i `U32.add` 1ul in [@inline_let] let _ = let s1 = (Seq.slice (B.as_seq h0 b) (U32.v pos) (U32.v pos + U32.v i)) in let c1 = (B.get h0 b (U32.v pos + U32.v i)) in let s2 = (Seq.slice (BY.reveal const) 0 (U32.v i)) in let c2 = (BY.index const (U32.v i)) in assert (Seq.slice (B.as_seq h0 b) (U32.v pos) (U32.v pos + U32.v i') `Seq.equal` Seq.snoc s1 c1); assert (Seq.slice (BY.reveal const) 0 (U32.v i') `Seq.equal` Seq.snoc s2 c2); Classical.move_requires (Seq.lemma_snoc_inj s1 s2 c1) c2 in let res = B.index b (pos `U32.add` i) = BY.get const i in B.upd bres 0ul res; B.upd bi 0ul i'; not res end ); let res = B.index bres 0ul in HST.pop_frame (); res #pop-options inline_for_extraction let valid_slice_equals_bytes (const: BY.bytes) (#rrel #rel: _) (input: slice rrel rel) (pos: U32.t) : HST.Stack bool (requires (fun h -> valid (parse_flbytes (BY.length const)) h input pos )) (ensures (fun h res h' -> B.modifies B.loc_none h h' /\ (res == true <==> contents (parse_flbytes (BY.length const)) h input pos == const ))) = let h = HST.get () in [@inline_let] let _ = valid_facts (parse_flbytes (BY.length const)) h input pos in buffer_equals_bytes const input.base pos inline_for_extraction let validate_all_bytes () : Tot (validator parse_all_bytes) = fun #rrel #rel input pos -> let h = HST.get () in [@inline_let] let _ = valid_facts parse_all_bytes h input (uint64_to_uint32 pos) in Cast.uint32_to_uint64 input.len inline_for_extraction let validate_bounded_vlbytes' (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (l: nat { l >= log256' max /\ l <= 4 } ) : Tot (validator (parse_bounded_vlbytes' min max l)) = validate_synth (validate_bounded_vldata_strong' min max l serialize_all_bytes (validate_all_bytes ())) (synth_bounded_vlbytes min max) () inline_for_extraction let validate_bounded_vlbytes (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) : Tot (validator (parse_bounded_vlbytes min max)) = validate_bounded_vlbytes' min max (log256' max) inline_for_extraction let jump_all_bytes () : Tot (jumper parse_all_bytes) = fun #rrel #rel input pos -> let h = HST.get () in [@inline_let] let _ = valid_facts parse_all_bytes h input pos in input.len inline_for_extraction let jump_bounded_vlbytes' (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (l: nat { l >= log256' max /\ l <= 4 } ) : Tot (jumper (parse_bounded_vlbytes' min max l)) = jump_synth (jump_bounded_vldata_strong' min max l serialize_all_bytes) (synth_bounded_vlbytes min max) () inline_for_extraction let jump_bounded_vlbytes (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) : Tot (jumper (parse_bounded_vlbytes min max)) = jump_bounded_vlbytes' min max (log256' max) let valid_exact_all_bytes_elim (h: HS.mem) (#rrel #rel: _) (input: slice rrel rel) (pos pos' : U32.t) : Lemma (requires (valid_exact parse_all_bytes h input pos pos')) (ensures ( let x = contents_exact parse_all_bytes h input pos pos' in let length = U32.v pos' - U32.v pos in BY.length x == length /\ valid_content_pos (parse_flbytes length) h input pos x pos' )) = valid_exact_equiv parse_all_bytes h input pos pos' ; contents_exact_eq parse_all_bytes h input pos pos' ; let length = U32.v pos' - U32.v pos in valid_facts (parse_flbytes length) h input pos ; assert (no_lookahead_on (parse_flbytes length) (bytes_of_slice_from_to h input pos pos') (bytes_of_slice_from h input pos)); assert (injective_postcond (parse_flbytes length) (bytes_of_slice_from_to h input pos pos') (bytes_of_slice_from h input pos)) #push-options "--z3rlimit 32" let valid_bounded_vlbytes'_elim (h: HS.mem) (min: nat) (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (l: nat { l >= log256' max /\ l <= 4 } ) (#rrel #rel: _) (input: slice rrel rel) (pos: U32.t) : Lemma (requires ( valid (parse_bounded_vlbytes' min max l) h input pos )) (ensures ( let sz = l in valid (parse_bounded_integer sz) h input pos /\ ( let len_payload = contents (parse_bounded_integer sz) h input pos in min <= U32.v len_payload /\ U32.v len_payload <= max /\ sz + U32.v len_payload == content_length (parse_bounded_vlbytes' min max l) h input pos /\ ( let pos_payload = pos `U32.add` U32.uint_to_t sz in let x = contents (parse_bounded_vlbytes' min max l) h input pos in BY.len x == len_payload /\ valid_pos (parse_bounded_vlbytes' min max l) h input pos (pos_payload `U32.add` len_payload) /\ valid_content_pos (parse_flbytes (U32.v len_payload)) h input pos_payload x (pos_payload `U32.add` len_payload) )))) = valid_synth h (parse_bounded_vlbytes_aux min max l) (synth_bounded_vlbytes min max) input pos; valid_bounded_vldata_strong'_elim h min max l serialize_all_bytes input pos; let sz = l in let len_payload = contents (parse_bounded_integer sz) h input pos in let pos_payload = pos `U32.add` U32.uint_to_t sz in valid_exact_all_bytes_elim h input pos_payload (pos_payload `U32.add` len_payload); () #pop-options let valid_bounded_vlbytes_elim (h: HS.mem) (min: nat) (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (#rrel #rel: _) (input: slice rrel rel) (pos: U32.t) : Lemma (requires ( valid (parse_bounded_vlbytes min max) h input pos )) (ensures ( let sz = log256' max in valid (parse_bounded_integer sz) h input pos /\ ( let len_payload = contents (parse_bounded_integer sz) h input pos in min <= U32.v len_payload /\ U32.v len_payload <= max /\ sz + U32.v len_payload == content_length (parse_bounded_vlbytes min max) h input pos /\ ( let pos_payload = pos `U32.add` U32.uint_to_t sz in let x = contents (parse_bounded_vlbytes min max) h input pos in BY.len x == len_payload /\ valid_pos (parse_bounded_vlbytes min max) h input pos (pos_payload `U32.add` len_payload) /\ valid_content_pos (parse_flbytes (U32.v len_payload)) h input pos_payload x (pos_payload `U32.add` len_payload) )))) = valid_bounded_vlbytes'_elim h min max (log256' max) input pos let valid_bounded_vlbytes_elim_length (h: HS.mem) (min: nat) (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (#rrel #rel: _) (input: slice rrel rel) (pos: U32.t) : Lemma (requires ( valid (parse_bounded_vlbytes min max) h input pos )) (ensures ( content_length (parse_bounded_vlbytes min max) h input pos == log256' max + BY.length (contents (parse_bounded_vlbytes min max) h input pos) )) [SMTPat (valid (parse_bounded_vlbytes min max) h input pos)] = valid_bounded_vlbytes_elim h min max input pos inline_for_extraction let bounded_vlbytes'_payload_length (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (l: nat { l >= log256' max /\ l <= 4 } ) (#rrel #rel: _) (input: slice rrel rel) (pos: U32.t) : HST.Stack U32.t (requires (fun h -> valid (parse_bounded_vlbytes' min max l) h input pos)) (ensures (fun h len h' -> B.modifies B.loc_none h h' /\ U32.v pos + l + U32.v len <= U32.v input.len /\ ( let x = contents (parse_bounded_vlbytes' min max l) h input pos in let pos' = get_valid_pos (parse_bounded_vlbytes' min max l) h input pos in BY.len x == len /\ valid_content_pos (parse_flbytes (U32.v len)) h input (pos `U32.add` U32.uint_to_t l) x pos' /\ bytes_of_slice_from_to h input (pos `U32.add` U32.uint_to_t l) pos' == BY.reveal x ))) = let h = HST.get () in [@inline_let] let _ = valid_bounded_vlbytes'_elim h min max l input pos in let len = read_bounded_integer l input pos in [@inline_let] let _ = valid_flbytes_elim h (U32.v len) input (pos `U32.add` U32.uint_to_t l) in len inline_for_extraction let bounded_vlbytes_payload_length (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (#rrel #rel: _) (input: slice rrel rel) (pos: U32.t) : HST.Stack U32.t (requires (fun h -> valid (parse_bounded_vlbytes min max) h input pos)) (ensures (fun h len h' -> B.modifies B.loc_none h h' /\ U32.v pos + log256' max + U32.v len <= U32.v input.len /\ ( let x = contents (parse_bounded_vlbytes min max) h input pos in let pos' = get_valid_pos (parse_bounded_vlbytes min max) h input pos in BY.len x == len /\ valid_content_pos (parse_flbytes (U32.v len)) h input (pos `U32.add` U32.uint_to_t (log256' max)) x pos' /\ bytes_of_slice_from_to h input (pos `U32.add` U32.uint_to_t (log256' max)) pos' == BY.reveal x ))) = bounded_vlbytes'_payload_length min max (log256' max) input pos (* Get the content buffer (with trivial buffers only, not generalizable to monotonicity) *) #push-options "--z3rlimit 32" inline_for_extraction let get_vlbytes'_contents (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (l: nat { l >= log256' max /\ l <= 4 } ) (input: slice (srel_of_buffer_srel (BF.trivial_preorder _)) (srel_of_buffer_srel (BF.trivial_preorder _))) (pos: U32.t) : HST.Stack (BF.buffer byte) (requires (fun h -> valid (parse_bounded_vlbytes' min max l) h input pos)) (ensures (fun h b h' -> let x = contents (parse_bounded_vlbytes' min max l) h input pos in B.modifies B.loc_none h h' /\ U32.v pos + l + BY.length x <= U32.v input.len /\ b == BF.gsub input.base (pos `U32.add` U32.uint_to_t l) (BY.len x) /\ B.as_seq h b == BY.reveal x )) = let h = HST.get () in [@inline_let] let _ = valid_bounded_vlbytes'_elim h min max l input pos in let len = read_bounded_integer l input pos in [@inline_let] let _ = valid_facts (parse_flbytes (U32.v len)) h input (pos `U32.add` U32.uint_to_t l) in BF.sub input.base (pos `U32.add` U32.uint_to_t l) len #pop-options inline_for_extraction let get_vlbytes_contents (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (input: slice (srel_of_buffer_srel (BF.trivial_preorder _)) (srel_of_buffer_srel (BF.trivial_preorder _))) (pos: U32.t) : HST.Stack (BF.buffer byte) (requires (fun h -> valid (parse_bounded_vlbytes min max) h input pos)) (ensures (fun h b h' -> let l = log256' max in let x = contents (parse_bounded_vlbytes min max) h input pos in B.modifies B.loc_none h h' /\ U32.v pos + l + BY.length x <= U32.v input.len /\ b == BF.gsub input.base (pos `U32.add` U32.uint_to_t l) (BY.len x) /\ B.as_seq h b == BY.reveal x )) = get_vlbytes'_contents min max (log256' max) input pos (* In fact, the following accessors are not useful in practice, because users would need to have the flbytes parser combinator in their scope *) let clens_vlbytes_cond (min: nat) (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (length: nat) (x: parse_bounded_vlbytes_t min max) : GTot Type0 = BY.length x == length let clens_vlbytes (min: nat) (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (length: nat) : Tot (clens (parse_bounded_vlbytes_t min max) (BY.lbytes length)) = { clens_cond = (clens_vlbytes_cond min max length); clens_get = (fun (x: parse_bounded_vlbytes_t min max) -> (x <: Ghost (BY.lbytes length) (requires (clens_vlbytes_cond min max length x)) (ensures (fun _ -> True)))); } #push-options "--z3rlimit 16 --max_fuel 2 --initial_fuel 2 --max_ifuel 6 --initial_ifuel 6" let gaccessor_vlbytes'_aux (min: nat) (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (l: nat { l >= log256' max /\ l <= 4 } ) (length: nat { length < 4294967296 } ) : Tot (gaccessor' (parse_bounded_vlbytes' min max l) (parse_flbytes length) (clens_vlbytes min max length)) = fun (input: bytes) -> (begin let res = if Seq.length input >= l then (l) else (0) in let g () : Lemma (requires (gaccessor_pre (parse_bounded_vlbytes' min max l) (parse_flbytes length) (clens_vlbytes min max length) input)) (ensures (gaccessor_post (parse_bounded_vlbytes' min max l) (parse_flbytes length) (clens_vlbytes min max length) input res)) = parse_bounded_vlbytes_eq min max l input; parse_strong_prefix (parse_flbytes length) (Seq.slice input l (l + length)) (Seq.slice input l (Seq.length input)) in Classical.move_requires g (); res end) let gaccessor_vlbytes' (min: nat) (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (l: nat { l >= log256' max /\ l <= 4 } ) (length: nat { length < 4294967296 } ) : Tot (gaccessor (parse_bounded_vlbytes' min max l) (parse_flbytes length) (clens_vlbytes min max length)) = parser_kind_prop_equiv (parse_bounded_vldata_strong_kind min max l parse_all_bytes_kind) (parse_bounded_vlbytes' min max l); assert (forall x . gaccessor_pre (parse_bounded_vlbytes' min max l) (parse_flbytes length) (clens_vlbytes min max length) x ==> Seq.length x >= l); gaccessor_prop_equiv (parse_bounded_vlbytes' min max l) (parse_flbytes length) (clens_vlbytes min max length) (gaccessor_vlbytes'_aux min max l length); gaccessor_vlbytes'_aux min max l length #pop-options let gaccessor_vlbytes (min: nat) (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (length: nat { length < 4294967296 } ) : Tot (gaccessor (parse_bounded_vlbytes min max) (parse_flbytes length) (clens_vlbytes min max length)) = gaccessor_vlbytes' min max (log256' max) length #push-options "--z3rlimit 64 --max_fuel 2 --initial_fuel 2 --max_ifuel 6 --initial_ifuel 6" inline_for_extraction let accessor_vlbytes' (min: nat) (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (l: nat { l >= log256' max /\ l <= 4 } ) (length: U32.t) : Tot (accessor (gaccessor_vlbytes' min max l (U32.v length))) = fun #rrel #rel sl pos -> let h = HST.get () in [@inline_let] let _ = slice_access_eq h (gaccessor_vlbytes' min max l (U32.v length)) sl pos; valid_bounded_vlbytes'_elim h min max l sl pos; parse_bounded_vlbytes_eq min max l (bytes_of_slice_from h sl pos) in pos `U32.add` U32.uint_to_t l #pop-options inline_for_extraction let accessor_vlbytes (min: nat) (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (length: U32.t) : Tot (accessor (gaccessor_vlbytes min max (U32.v length))) = accessor_vlbytes' min max (log256' max) length
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowStar.Monotonic.Buffer.fsti.checked", "LowStar.Buffer.fst.checked", "LowParse.Spec.Bytes.fst.checked", "LowParse.Low.VLGen.fst.checked", "LowParse.Low.VLData.fst.checked", "LowParse.Low.Int.fsti.checked", "LowParse.Low.Combinators.fsti.checked", "LowParse.Bytes32.fst.checked", "FStar.UInt8.fsti.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Int.Cast.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked", "FStar.Classical.fsti.checked", "C.Loops.fst.checked" ], "interface_file": false, "source_file": "LowParse.Low.Bytes.fst" }
[ { "abbrev": true, "full_module": "LowStar.Buffer // for local variables in store_bytes", "short_module": "BF" }, { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "FStar.Int.Cast", "short_module": "Cast" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "LowParse.Bytes32", "short_module": "BY" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "BF" }, { "abbrev": true, "full_module": "LowStar.Monotonic.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": false, "full_module": "LowParse.Low.Int", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low.VLGen", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low.VLData", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low.Combinators", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec.Bytes", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
min: Prims.nat -> max: Prims.nat{min <= max /\ max > 0 /\ max < 4294967296} -> from: FStar.UInt32.t -> to: FStar.UInt32.t{FStar.UInt32.v from <= FStar.UInt32.v to /\ FStar.UInt32.v to <= max} -> LowParse.Low.Base.Spec.clens (LowParse.Spec.Bytes.parse_bounded_vlbytes_t min max) (FStar.Bytes.lbytes (FStar.UInt32.v to - FStar.UInt32.v from))
Prims.Tot
[ "total" ]
[]
[ "Prims.nat", "Prims.l_and", "Prims.b2t", "Prims.op_LessThanOrEqual", "Prims.op_GreaterThan", "Prims.op_LessThan", "FStar.UInt32.t", "FStar.UInt32.v", "LowParse.Low.Base.Spec.Mkclens", "LowParse.Spec.Bytes.parse_bounded_vlbytes_t", "FStar.Bytes.lbytes", "Prims.op_Subtraction", "FStar.Bytes.length", "FStar.Bytes.slice", "LowParse.Low.Base.Spec.clens" ]
[]
false
false
false
false
false
let clens_vlbytes_slice (min: nat) (max: nat{min <= max /\ max > 0 /\ max < 4294967296}) (from: U32.t) (to: U32.t{U32.v from <= U32.v to /\ U32.v to <= max}) : Tot (clens (parse_bounded_vlbytes_t min max) (BY.lbytes (U32.v to - U32.v from))) =
{ clens_cond = (fun (x: parse_bounded_vlbytes_t min max) -> U32.v to <= BY.length x); clens_get = (fun (x: parse_bounded_vlbytes_t min max) -> (BY.slice x from to <: BY.lbytes (U32.v to - U32.v from))) }
false
LowParse.Low.Bytes.fst
LowParse.Low.Bytes.gaccessor_vlbytes
val gaccessor_vlbytes (min: nat) (max: nat{min <= max /\ max > 0 /\ max < 4294967296}) (length: nat{length < 4294967296}) : Tot (gaccessor (parse_bounded_vlbytes min max) (parse_flbytes length) (clens_vlbytes min max length) )
val gaccessor_vlbytes (min: nat) (max: nat{min <= max /\ max > 0 /\ max < 4294967296}) (length: nat{length < 4294967296}) : Tot (gaccessor (parse_bounded_vlbytes min max) (parse_flbytes length) (clens_vlbytes min max length) )
let gaccessor_vlbytes (min: nat) (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (length: nat { length < 4294967296 } ) : Tot (gaccessor (parse_bounded_vlbytes min max) (parse_flbytes length) (clens_vlbytes min max length)) = gaccessor_vlbytes' min max (log256' max) length
{ "file_name": "src/lowparse/LowParse.Low.Bytes.fst", "git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
{ "end_col": 49, "end_line": 652, "start_col": 0, "start_line": 647 }
module LowParse.Low.Bytes include LowParse.Spec.Bytes include LowParse.Low.Combinators include LowParse.Low.VLData include LowParse.Low.VLGen include LowParse.Low.Int module U32 = FStar.UInt32 module HS = FStar.HyperStack module B = LowStar.Monotonic.Buffer module BF = LowStar.Buffer // for local variables in store_bytes module BY = LowParse.Bytes32 module HST = FStar.HyperStack.ST module U8 = FStar.UInt8 module Cast = FStar.Int.Cast module U64 = FStar.UInt64 inline_for_extraction let validate_flbytes (sz: nat) (sz64: U64.t { U64.v sz64 == sz /\ sz < 4294967296 } ) : Tot (validator (parse_flbytes sz)) = validate_total_constant_size (parse_flbytes sz) sz64 () inline_for_extraction let jump_flbytes (sz: nat) (sz32: U32.t { U32.v sz32 == sz } ) : Tot (jumper (parse_flbytes sz)) = jump_constant_size (parse_flbytes sz) sz32 () let valid_flbytes_intro (h: HS.mem) (sz: nat { sz < 4294967296 } ) (#rrel #rel: _) (s: slice rrel rel) (pos: U32.t) : Lemma (requires (U32.v pos + sz <= U32.v s.len /\ live_slice h s)) (ensures ( valid_content_pos (parse_flbytes sz) h s pos (BY.hide (bytes_of_slice_from_to h s pos (pos `U32.add` U32.uint_to_t sz))) (pos `U32.add` U32.uint_to_t sz) )) = valid_facts (parse_flbytes sz) h s pos let valid_pos_flbytes_elim (h: HS.mem) (sz: nat { sz < 4294967296 } ) (#rrel #rel: _) (s: slice rrel rel) (pos pos' : U32.t) : Lemma (requires (valid_pos (parse_flbytes sz) h s pos pos')) (ensures (U32.v pos + sz == U32.v pos')) [SMTPat (valid_pos (parse_flbytes sz) h s pos pos')] = valid_facts (parse_flbytes sz) h s pos let valid_flbytes_elim (h: HS.mem) (sz: nat { sz < 4294967296 } ) (#rrel #rel: _) (s: slice rrel rel) (pos: U32.t) : Lemma (requires (valid (parse_flbytes sz) h s pos)) (ensures ( valid_content_pos (parse_flbytes sz) h s pos (BY.hide (bytes_of_slice_from_to h s pos (pos `U32.add` U32.uint_to_t sz))) (pos `U32.add` U32.uint_to_t sz) )) = valid_flbytes_intro h sz s pos let clens_flbytes_slice (sz: nat) (from: U32.t) (to: U32.t {U32.v from <= U32.v to /\ U32.v to <= sz } ) : Tot (clens (BY.lbytes sz) (BY.lbytes (U32.v to - U32.v from))) = { clens_cond = (fun _ -> True); clens_get = (fun (x: BY.lbytes sz) -> (BY.slice x from to <: BY.lbytes (U32.v to - U32.v from))); } #push-options "--z3rlimit 16" let gaccessor_flbytes_slice' (sz: nat { sz < 4294967296 } ) (from: U32.t) (to: U32.t {U32.v from <= U32.v to /\ U32.v to <= sz } ) : Tot (gaccessor' (parse_flbytes sz) (parse_flbytes (U32.v to - U32.v from)) (clens_flbytes_slice sz from to)) = fun (input: bytes) -> ( begin if Seq.length input < sz then (0) // dummy else (U32.v from) end) let gaccessor_flbytes_slice (sz: nat { sz < 4294967296 } ) (from: U32.t) (to: U32.t {U32.v from <= U32.v to /\ U32.v to <= sz } ) : Tot (gaccessor (parse_flbytes sz) (parse_flbytes (U32.v to - U32.v from)) (clens_flbytes_slice sz from to)) = assert (forall x . gaccessor_pre (parse_flbytes sz) (parse_flbytes (U32.v to - U32.v from)) (clens_flbytes_slice sz from to) x ==> sz <= Seq.length x); gaccessor_prop_equiv (parse_flbytes sz) (parse_flbytes (U32.v to - U32.v from)) (clens_flbytes_slice sz from to) (gaccessor_flbytes_slice' sz from to); gaccessor_flbytes_slice' sz from to inline_for_extraction let accessor_flbytes_slice (sz: nat { sz < 4294967296 } ) (from: U32.t) (to: U32.t {U32.v from <= U32.v to /\ U32.v to <= sz } ) : Tot (accessor (gaccessor_flbytes_slice sz from to)) = fun #rrel #rel input pos -> let h = HST.get () in [@inline_let] let _ = slice_access_eq h (gaccessor_flbytes_slice sz from to) input pos in pos `U32.add` from #pop-options let clens_flbytes_get (sz: nat) (i: U32.t { U32.v i < sz } ) : Tot (clens (BY.lbytes sz) byte) = { clens_cond = (fun _ -> True); clens_get = (fun (x: BY.lbytes sz) -> (BY.get x i <: byte)); } #push-options "--z3rlimit 16 --max_fuel 1" let gaccessor_flbytes_get' (sz: nat { sz < 4294967296 } ) (i: U32.t { U32.v i < sz } ) : Tot (gaccessor' (parse_flbytes sz) (parse_u8) (clens_flbytes_get sz i)) = fun (input: bytes) -> ( begin let res = if Seq.length input < U32.v i then (0) // dummy else (U32.v i) in let g () : Lemma (requires (gaccessor_pre (parse_flbytes sz) parse_u8 (clens_flbytes_get sz i) input)) (ensures (gaccessor_post (parse_flbytes sz) parse_u8 (clens_flbytes_get sz i) input res)) = parser_kind_prop_equiv (get_parser_kind parse_u8) parse_u8; assert (res == (U32.v i)); parse_u8_spec' (Seq.slice input (U32.v i) (U32.v i + 1)); parse_strong_prefix parse_u8 (Seq.slice input (U32.v i) (U32.v i + 1)) (Seq.slice input (U32.v i) (Seq.length input)) in Classical.move_requires g (); res end) #pop-options let gaccessor_flbytes_get (sz: nat { sz < 4294967296 } ) (i: U32.t { U32.v i < sz } ) : Tot (gaccessor (parse_flbytes sz) (parse_u8) (clens_flbytes_get sz i)) = assert (forall x . gaccessor_pre (parse_flbytes sz) (parse_u8) (clens_flbytes_get sz i) x ==> U32.v i <= Seq.length x); gaccessor_prop_equiv (parse_flbytes sz) (parse_u8) (clens_flbytes_get sz i) (gaccessor_flbytes_get' sz i); gaccessor_flbytes_get' sz i inline_for_extraction let accessor_flbytes_get (sz: nat { sz < 4294967296 } ) (i: U32.t { U32.v i < sz } ) : Tot (accessor (gaccessor_flbytes_get sz i)) = fun #rrel #rel input pos -> let h = HST.get () in [@inline_let] let _ = slice_access_eq h (gaccessor_flbytes_get sz i) input pos in pos `U32.add` i (* Temporary: flbytes as leaf values *) (* TODO: convert store_bytes to monotonic buffers, using the "writable" predicate *) #push-options "--z3rlimit 32" inline_for_extraction let store_bytes (src: BY.bytes) (src_from src_to: U32.t) (#rrel #rel: _) (dst: B.mbuffer byte rrel rel) (dst_pos: U32.t) : HST.Stack unit (requires (fun h -> B.live h dst /\ U32.v src_from <= U32.v src_to /\ U32.v src_to <= BY.length src /\ U32.v dst_pos + (U32.v src_to - U32.v src_from) <= B.length dst /\ writable dst (U32.v dst_pos) (U32.v dst_pos + (U32.v src_to - U32.v src_from)) h )) (ensures (fun h _ h' -> B.modifies (B.loc_buffer_from_to dst dst_pos (dst_pos `U32.add` (src_to `U32.sub` src_from))) h h' /\ Seq.slice (B.as_seq h' dst) (U32.v dst_pos) (U32.v dst_pos + (U32.v src_to - U32.v src_from)) == Seq.slice (BY.reveal src) (U32.v src_from) (U32.v src_to) )) = let h0 = HST.get () in HST.push_frame (); let h1 = HST.get () in let bi = BF.alloca 0ul 1ul in let h2 = HST.get () in let len = src_to `U32.sub` src_from in C.Loops.do_while (fun h stop -> B.modifies (B.loc_union (B.loc_region_only true (HS.get_tip h1)) (B.loc_buffer_from_to dst dst_pos (dst_pos `U32.add` len))) h2 h /\ B.live h bi /\ ( let i = Seq.index (B.as_seq h bi) 0 in U32.v i <= U32.v len /\ writable dst (U32.v dst_pos) (U32.v dst_pos + U32.v len) h /\ Seq.slice (B.as_seq h dst) (U32.v dst_pos) (U32.v dst_pos + U32.v i) `Seq.equal` Seq.slice (BY.reveal src) (U32.v src_from) (U32.v src_from + U32.v i) /\ (stop == true ==> i == len) )) (fun _ -> let i = B.index bi 0ul in if i = len then true else begin let x = BY.get src (src_from `U32.add` i) in mbuffer_upd dst (Ghost.hide (U32.v dst_pos)) (Ghost.hide (U32.v dst_pos + U32.v len)) (dst_pos `U32.add` i) x; let i' = i `U32.add` 1ul in B.upd bi 0ul i'; let h' = HST.get () in Seq.lemma_split (Seq.slice (B.as_seq h' dst) (U32.v dst_pos) (U32.v dst_pos + U32.v i')) (U32.v i); i' = len end ) ; HST.pop_frame () #pop-options inline_for_extraction let serialize32_flbytes (sz32: U32.t) : Tot (serializer32 (serialize_flbytes (U32.v sz32))) = fun (x: BY.lbytes (U32.v sz32)) #rrel #rel b pos -> let _ = store_bytes x 0ul sz32 b pos in sz32 inline_for_extraction let write_flbytes (sz32: U32.t) : Tot (leaf_writer_strong (serialize_flbytes (U32.v sz32))) = leaf_writer_strong_of_serializer32 (serialize32_flbytes sz32) () inline_for_extraction let write_flbytes_weak (sz32: U32.t { U32.v sz32 < 4294967295 } ) // need to return that value if output buffer is too small : Tot (leaf_writer_weak (serialize_flbytes (U32.v sz32))) = leaf_writer_weak_of_strong_constant_size (write_flbytes sz32) sz32 () (* // TODO: remove, since nobody is using this inline_for_extraction let read_flbytes (sz32: U32.t) : Tot (leaf_reader (parse_flbytes (U32.v sz32))) = fun input pos -> let h = HST.get () in [@inline_let] let _ = valid_facts (parse_flbytes (U32.v sz32)) h input pos in BY.of_buffer sz32 (B.sub input.base pos sz32) *) (* Equality test between a vlbytes and a constant lbytes *) #push-options "--z3rlimit 32" inline_for_extraction let buffer_equals_bytes (const: BY.bytes) (#rrel #rel: _) (b: B.mbuffer byte rrel rel) (pos: U32.t) : HST.Stack bool (requires (fun h -> B.live h b /\ U32.v pos + BY.length const <= B.length b )) (ensures (fun h res h' -> B.modifies B.loc_none h h' /\ (res == true <==> Seq.slice (B.as_seq h b) (U32.v pos) (U32.v pos + BY.length const) == BY.reveal const) )) = let h0 = HST.get () in HST.push_frame (); let len = BY.len const in let bi = BF.alloca 0ul 1ul in let bres = BF.alloca true 1ul in let h1 = HST.get () in [@inline_let] let inv (h: HS.mem) (stop: bool) : GTot Type0 = B.modifies (B.loc_union (B.loc_buffer bi) (B.loc_buffer bres)) h1 h /\ ( let length = U32.v len in let i32 = (Seq.index (B.as_seq h bi) 0) in let i = U32.v i32 in let res = Seq.index (B.as_seq h bres) 0 in i <= length /\ (stop == false ==> res == true) /\ ((stop == true /\ res == true) ==> i == length) /\ (res == true <==> Seq.slice (B.as_seq h b) (U32.v pos) (U32.v pos + i) `Seq.equal` Seq.slice (BY.reveal const) 0 i) ) in C.Loops.do_while inv (fun _ -> let i = B.index bi 0ul in if i = len then true else begin let i' = i `U32.add` 1ul in [@inline_let] let _ = let s1 = (Seq.slice (B.as_seq h0 b) (U32.v pos) (U32.v pos + U32.v i)) in let c1 = (B.get h0 b (U32.v pos + U32.v i)) in let s2 = (Seq.slice (BY.reveal const) 0 (U32.v i)) in let c2 = (BY.index const (U32.v i)) in assert (Seq.slice (B.as_seq h0 b) (U32.v pos) (U32.v pos + U32.v i') `Seq.equal` Seq.snoc s1 c1); assert (Seq.slice (BY.reveal const) 0 (U32.v i') `Seq.equal` Seq.snoc s2 c2); Classical.move_requires (Seq.lemma_snoc_inj s1 s2 c1) c2 in let res = B.index b (pos `U32.add` i) = BY.get const i in B.upd bres 0ul res; B.upd bi 0ul i'; not res end ); let res = B.index bres 0ul in HST.pop_frame (); res #pop-options inline_for_extraction let valid_slice_equals_bytes (const: BY.bytes) (#rrel #rel: _) (input: slice rrel rel) (pos: U32.t) : HST.Stack bool (requires (fun h -> valid (parse_flbytes (BY.length const)) h input pos )) (ensures (fun h res h' -> B.modifies B.loc_none h h' /\ (res == true <==> contents (parse_flbytes (BY.length const)) h input pos == const ))) = let h = HST.get () in [@inline_let] let _ = valid_facts (parse_flbytes (BY.length const)) h input pos in buffer_equals_bytes const input.base pos inline_for_extraction let validate_all_bytes () : Tot (validator parse_all_bytes) = fun #rrel #rel input pos -> let h = HST.get () in [@inline_let] let _ = valid_facts parse_all_bytes h input (uint64_to_uint32 pos) in Cast.uint32_to_uint64 input.len inline_for_extraction let validate_bounded_vlbytes' (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (l: nat { l >= log256' max /\ l <= 4 } ) : Tot (validator (parse_bounded_vlbytes' min max l)) = validate_synth (validate_bounded_vldata_strong' min max l serialize_all_bytes (validate_all_bytes ())) (synth_bounded_vlbytes min max) () inline_for_extraction let validate_bounded_vlbytes (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) : Tot (validator (parse_bounded_vlbytes min max)) = validate_bounded_vlbytes' min max (log256' max) inline_for_extraction let jump_all_bytes () : Tot (jumper parse_all_bytes) = fun #rrel #rel input pos -> let h = HST.get () in [@inline_let] let _ = valid_facts parse_all_bytes h input pos in input.len inline_for_extraction let jump_bounded_vlbytes' (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (l: nat { l >= log256' max /\ l <= 4 } ) : Tot (jumper (parse_bounded_vlbytes' min max l)) = jump_synth (jump_bounded_vldata_strong' min max l serialize_all_bytes) (synth_bounded_vlbytes min max) () inline_for_extraction let jump_bounded_vlbytes (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) : Tot (jumper (parse_bounded_vlbytes min max)) = jump_bounded_vlbytes' min max (log256' max) let valid_exact_all_bytes_elim (h: HS.mem) (#rrel #rel: _) (input: slice rrel rel) (pos pos' : U32.t) : Lemma (requires (valid_exact parse_all_bytes h input pos pos')) (ensures ( let x = contents_exact parse_all_bytes h input pos pos' in let length = U32.v pos' - U32.v pos in BY.length x == length /\ valid_content_pos (parse_flbytes length) h input pos x pos' )) = valid_exact_equiv parse_all_bytes h input pos pos' ; contents_exact_eq parse_all_bytes h input pos pos' ; let length = U32.v pos' - U32.v pos in valid_facts (parse_flbytes length) h input pos ; assert (no_lookahead_on (parse_flbytes length) (bytes_of_slice_from_to h input pos pos') (bytes_of_slice_from h input pos)); assert (injective_postcond (parse_flbytes length) (bytes_of_slice_from_to h input pos pos') (bytes_of_slice_from h input pos)) #push-options "--z3rlimit 32" let valid_bounded_vlbytes'_elim (h: HS.mem) (min: nat) (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (l: nat { l >= log256' max /\ l <= 4 } ) (#rrel #rel: _) (input: slice rrel rel) (pos: U32.t) : Lemma (requires ( valid (parse_bounded_vlbytes' min max l) h input pos )) (ensures ( let sz = l in valid (parse_bounded_integer sz) h input pos /\ ( let len_payload = contents (parse_bounded_integer sz) h input pos in min <= U32.v len_payload /\ U32.v len_payload <= max /\ sz + U32.v len_payload == content_length (parse_bounded_vlbytes' min max l) h input pos /\ ( let pos_payload = pos `U32.add` U32.uint_to_t sz in let x = contents (parse_bounded_vlbytes' min max l) h input pos in BY.len x == len_payload /\ valid_pos (parse_bounded_vlbytes' min max l) h input pos (pos_payload `U32.add` len_payload) /\ valid_content_pos (parse_flbytes (U32.v len_payload)) h input pos_payload x (pos_payload `U32.add` len_payload) )))) = valid_synth h (parse_bounded_vlbytes_aux min max l) (synth_bounded_vlbytes min max) input pos; valid_bounded_vldata_strong'_elim h min max l serialize_all_bytes input pos; let sz = l in let len_payload = contents (parse_bounded_integer sz) h input pos in let pos_payload = pos `U32.add` U32.uint_to_t sz in valid_exact_all_bytes_elim h input pos_payload (pos_payload `U32.add` len_payload); () #pop-options let valid_bounded_vlbytes_elim (h: HS.mem) (min: nat) (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (#rrel #rel: _) (input: slice rrel rel) (pos: U32.t) : Lemma (requires ( valid (parse_bounded_vlbytes min max) h input pos )) (ensures ( let sz = log256' max in valid (parse_bounded_integer sz) h input pos /\ ( let len_payload = contents (parse_bounded_integer sz) h input pos in min <= U32.v len_payload /\ U32.v len_payload <= max /\ sz + U32.v len_payload == content_length (parse_bounded_vlbytes min max) h input pos /\ ( let pos_payload = pos `U32.add` U32.uint_to_t sz in let x = contents (parse_bounded_vlbytes min max) h input pos in BY.len x == len_payload /\ valid_pos (parse_bounded_vlbytes min max) h input pos (pos_payload `U32.add` len_payload) /\ valid_content_pos (parse_flbytes (U32.v len_payload)) h input pos_payload x (pos_payload `U32.add` len_payload) )))) = valid_bounded_vlbytes'_elim h min max (log256' max) input pos let valid_bounded_vlbytes_elim_length (h: HS.mem) (min: nat) (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (#rrel #rel: _) (input: slice rrel rel) (pos: U32.t) : Lemma (requires ( valid (parse_bounded_vlbytes min max) h input pos )) (ensures ( content_length (parse_bounded_vlbytes min max) h input pos == log256' max + BY.length (contents (parse_bounded_vlbytes min max) h input pos) )) [SMTPat (valid (parse_bounded_vlbytes min max) h input pos)] = valid_bounded_vlbytes_elim h min max input pos inline_for_extraction let bounded_vlbytes'_payload_length (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (l: nat { l >= log256' max /\ l <= 4 } ) (#rrel #rel: _) (input: slice rrel rel) (pos: U32.t) : HST.Stack U32.t (requires (fun h -> valid (parse_bounded_vlbytes' min max l) h input pos)) (ensures (fun h len h' -> B.modifies B.loc_none h h' /\ U32.v pos + l + U32.v len <= U32.v input.len /\ ( let x = contents (parse_bounded_vlbytes' min max l) h input pos in let pos' = get_valid_pos (parse_bounded_vlbytes' min max l) h input pos in BY.len x == len /\ valid_content_pos (parse_flbytes (U32.v len)) h input (pos `U32.add` U32.uint_to_t l) x pos' /\ bytes_of_slice_from_to h input (pos `U32.add` U32.uint_to_t l) pos' == BY.reveal x ))) = let h = HST.get () in [@inline_let] let _ = valid_bounded_vlbytes'_elim h min max l input pos in let len = read_bounded_integer l input pos in [@inline_let] let _ = valid_flbytes_elim h (U32.v len) input (pos `U32.add` U32.uint_to_t l) in len inline_for_extraction let bounded_vlbytes_payload_length (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (#rrel #rel: _) (input: slice rrel rel) (pos: U32.t) : HST.Stack U32.t (requires (fun h -> valid (parse_bounded_vlbytes min max) h input pos)) (ensures (fun h len h' -> B.modifies B.loc_none h h' /\ U32.v pos + log256' max + U32.v len <= U32.v input.len /\ ( let x = contents (parse_bounded_vlbytes min max) h input pos in let pos' = get_valid_pos (parse_bounded_vlbytes min max) h input pos in BY.len x == len /\ valid_content_pos (parse_flbytes (U32.v len)) h input (pos `U32.add` U32.uint_to_t (log256' max)) x pos' /\ bytes_of_slice_from_to h input (pos `U32.add` U32.uint_to_t (log256' max)) pos' == BY.reveal x ))) = bounded_vlbytes'_payload_length min max (log256' max) input pos (* Get the content buffer (with trivial buffers only, not generalizable to monotonicity) *) #push-options "--z3rlimit 32" inline_for_extraction let get_vlbytes'_contents (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (l: nat { l >= log256' max /\ l <= 4 } ) (input: slice (srel_of_buffer_srel (BF.trivial_preorder _)) (srel_of_buffer_srel (BF.trivial_preorder _))) (pos: U32.t) : HST.Stack (BF.buffer byte) (requires (fun h -> valid (parse_bounded_vlbytes' min max l) h input pos)) (ensures (fun h b h' -> let x = contents (parse_bounded_vlbytes' min max l) h input pos in B.modifies B.loc_none h h' /\ U32.v pos + l + BY.length x <= U32.v input.len /\ b == BF.gsub input.base (pos `U32.add` U32.uint_to_t l) (BY.len x) /\ B.as_seq h b == BY.reveal x )) = let h = HST.get () in [@inline_let] let _ = valid_bounded_vlbytes'_elim h min max l input pos in let len = read_bounded_integer l input pos in [@inline_let] let _ = valid_facts (parse_flbytes (U32.v len)) h input (pos `U32.add` U32.uint_to_t l) in BF.sub input.base (pos `U32.add` U32.uint_to_t l) len #pop-options inline_for_extraction let get_vlbytes_contents (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (input: slice (srel_of_buffer_srel (BF.trivial_preorder _)) (srel_of_buffer_srel (BF.trivial_preorder _))) (pos: U32.t) : HST.Stack (BF.buffer byte) (requires (fun h -> valid (parse_bounded_vlbytes min max) h input pos)) (ensures (fun h b h' -> let l = log256' max in let x = contents (parse_bounded_vlbytes min max) h input pos in B.modifies B.loc_none h h' /\ U32.v pos + l + BY.length x <= U32.v input.len /\ b == BF.gsub input.base (pos `U32.add` U32.uint_to_t l) (BY.len x) /\ B.as_seq h b == BY.reveal x )) = get_vlbytes'_contents min max (log256' max) input pos (* In fact, the following accessors are not useful in practice, because users would need to have the flbytes parser combinator in their scope *) let clens_vlbytes_cond (min: nat) (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (length: nat) (x: parse_bounded_vlbytes_t min max) : GTot Type0 = BY.length x == length let clens_vlbytes (min: nat) (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (length: nat) : Tot (clens (parse_bounded_vlbytes_t min max) (BY.lbytes length)) = { clens_cond = (clens_vlbytes_cond min max length); clens_get = (fun (x: parse_bounded_vlbytes_t min max) -> (x <: Ghost (BY.lbytes length) (requires (clens_vlbytes_cond min max length x)) (ensures (fun _ -> True)))); } #push-options "--z3rlimit 16 --max_fuel 2 --initial_fuel 2 --max_ifuel 6 --initial_ifuel 6" let gaccessor_vlbytes'_aux (min: nat) (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (l: nat { l >= log256' max /\ l <= 4 } ) (length: nat { length < 4294967296 } ) : Tot (gaccessor' (parse_bounded_vlbytes' min max l) (parse_flbytes length) (clens_vlbytes min max length)) = fun (input: bytes) -> (begin let res = if Seq.length input >= l then (l) else (0) in let g () : Lemma (requires (gaccessor_pre (parse_bounded_vlbytes' min max l) (parse_flbytes length) (clens_vlbytes min max length) input)) (ensures (gaccessor_post (parse_bounded_vlbytes' min max l) (parse_flbytes length) (clens_vlbytes min max length) input res)) = parse_bounded_vlbytes_eq min max l input; parse_strong_prefix (parse_flbytes length) (Seq.slice input l (l + length)) (Seq.slice input l (Seq.length input)) in Classical.move_requires g (); res end) let gaccessor_vlbytes' (min: nat) (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (l: nat { l >= log256' max /\ l <= 4 } ) (length: nat { length < 4294967296 } ) : Tot (gaccessor (parse_bounded_vlbytes' min max l) (parse_flbytes length) (clens_vlbytes min max length)) = parser_kind_prop_equiv (parse_bounded_vldata_strong_kind min max l parse_all_bytes_kind) (parse_bounded_vlbytes' min max l); assert (forall x . gaccessor_pre (parse_bounded_vlbytes' min max l) (parse_flbytes length) (clens_vlbytes min max length) x ==> Seq.length x >= l); gaccessor_prop_equiv (parse_bounded_vlbytes' min max l) (parse_flbytes length) (clens_vlbytes min max length) (gaccessor_vlbytes'_aux min max l length); gaccessor_vlbytes'_aux min max l length #pop-options
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowStar.Monotonic.Buffer.fsti.checked", "LowStar.Buffer.fst.checked", "LowParse.Spec.Bytes.fst.checked", "LowParse.Low.VLGen.fst.checked", "LowParse.Low.VLData.fst.checked", "LowParse.Low.Int.fsti.checked", "LowParse.Low.Combinators.fsti.checked", "LowParse.Bytes32.fst.checked", "FStar.UInt8.fsti.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Int.Cast.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked", "FStar.Classical.fsti.checked", "C.Loops.fst.checked" ], "interface_file": false, "source_file": "LowParse.Low.Bytes.fst" }
[ { "abbrev": true, "full_module": "LowStar.Buffer // for local variables in store_bytes", "short_module": "BF" }, { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "FStar.Int.Cast", "short_module": "Cast" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "LowParse.Bytes32", "short_module": "BY" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "BF" }, { "abbrev": true, "full_module": "LowStar.Monotonic.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": false, "full_module": "LowParse.Low.Int", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low.VLGen", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low.VLData", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low.Combinators", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec.Bytes", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
min: Prims.nat -> max: Prims.nat{min <= max /\ max > 0 /\ max < 4294967296} -> length: Prims.nat{length < 4294967296} -> LowParse.Low.Base.Spec.gaccessor (LowParse.Spec.Bytes.parse_bounded_vlbytes min max) (LowParse.Spec.Bytes.parse_flbytes length) (LowParse.Low.Bytes.clens_vlbytes min max length)
Prims.Tot
[ "total" ]
[]
[ "Prims.nat", "Prims.l_and", "Prims.b2t", "Prims.op_LessThanOrEqual", "Prims.op_GreaterThan", "Prims.op_LessThan", "LowParse.Low.Bytes.gaccessor_vlbytes'", "LowParse.Spec.BoundedInt.log256'", "LowParse.Low.Base.Spec.gaccessor", "LowParse.Spec.VLData.parse_bounded_vldata_strong_kind", "LowParse.Spec.Bytes.parse_all_bytes_kind", "LowParse.Spec.Bytes.parse_bounded_vlbytes_t", "LowParse.Spec.Bytes.parse_bounded_vlbytes", "LowParse.Spec.Base.total_constant_size_parser_kind", "FStar.Bytes.lbytes", "LowParse.Spec.Bytes.parse_flbytes", "LowParse.Low.Bytes.clens_vlbytes" ]
[]
false
false
false
false
false
let gaccessor_vlbytes (min: nat) (max: nat{min <= max /\ max > 0 /\ max < 4294967296}) (length: nat{length < 4294967296}) : Tot (gaccessor (parse_bounded_vlbytes min max) (parse_flbytes length) (clens_vlbytes min max length) ) =
gaccessor_vlbytes' min max (log256' max) length
false
Pulse.Syntax.Base.fsti
Pulse.Syntax.Base.range_singleton_trigger
val range_singleton_trigger : r: FStar.Range.range -> Prims.logical
let range_singleton_trigger (r:FStar.Range.range) = True
{ "file_name": "lib/steel/pulse/Pulse.Syntax.Base.fsti", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 56, "end_line": 33, "start_col": 0, "start_line": 33 }
(* Copyright 2023 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module Pulse.Syntax.Base module RTB = FStar.Reflection.Typing.Builtins module RT = FStar.Reflection.Typing module R = FStar.Reflection.V2 module RU = Pulse.RuntimeUtils module T = FStar.Tactics.V2 open FStar.List.Tot type constant = R.vconst let var = nat let index = nat type universe = R.universe
{ "checked_file": "/", "dependencies": [ "Pulse.RuntimeUtils.fsti.checked", "Pulse.Reflection.Util.fst.checked", "prims.fst.checked", "FStar.Tactics.V2.fst.checked", "FStar.Sealed.Inhabited.fst.checked", "FStar.Sealed.fsti.checked", "FStar.Reflection.V2.fst.checked", "FStar.Reflection.Typing.Builtins.fsti.checked", "FStar.Reflection.Typing.fsti.checked", "FStar.Range.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked" ], "interface_file": false, "source_file": "Pulse.Syntax.Base.fsti" }
[ { "abbrev": false, "full_module": "FStar.List.Tot", "short_module": null }, { "abbrev": true, "full_module": "FStar.Tactics.V2", "short_module": "T" }, { "abbrev": true, "full_module": "Pulse.RuntimeUtils", "short_module": "RU" }, { "abbrev": true, "full_module": "FStar.Reflection.V2", "short_module": "R" }, { "abbrev": true, "full_module": "FStar.Reflection.Typing", "short_module": "RT" }, { "abbrev": true, "full_module": "FStar.Reflection.Typing.Builtins", "short_module": "RTB" }, { "abbrev": false, "full_module": "Pulse.Syntax", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Syntax", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
r: FStar.Range.range -> Prims.logical
Prims.Tot
[ "total" ]
[]
[ "FStar.Range.range", "Prims.l_True", "Prims.logical" ]
[]
false
false
false
true
true
let range_singleton_trigger (r: FStar.Range.range) =
True
false
Pulse.Syntax.Base.fsti
Pulse.Syntax.Base.var
val var : Type0
let var = nat
{ "file_name": "lib/steel/pulse/Pulse.Syntax.Base.fsti", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 13, "end_line": 27, "start_col": 0, "start_line": 27 }
(* Copyright 2023 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module Pulse.Syntax.Base module RTB = FStar.Reflection.Typing.Builtins module RT = FStar.Reflection.Typing module R = FStar.Reflection.V2 module RU = Pulse.RuntimeUtils module T = FStar.Tactics.V2 open FStar.List.Tot type constant = R.vconst
{ "checked_file": "/", "dependencies": [ "Pulse.RuntimeUtils.fsti.checked", "Pulse.Reflection.Util.fst.checked", "prims.fst.checked", "FStar.Tactics.V2.fst.checked", "FStar.Sealed.Inhabited.fst.checked", "FStar.Sealed.fsti.checked", "FStar.Reflection.V2.fst.checked", "FStar.Reflection.Typing.Builtins.fsti.checked", "FStar.Reflection.Typing.fsti.checked", "FStar.Range.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked" ], "interface_file": false, "source_file": "Pulse.Syntax.Base.fsti" }
[ { "abbrev": false, "full_module": "FStar.List.Tot", "short_module": null }, { "abbrev": true, "full_module": "FStar.Tactics.V2", "short_module": "T" }, { "abbrev": true, "full_module": "Pulse.RuntimeUtils", "short_module": "RU" }, { "abbrev": true, "full_module": "FStar.Reflection.V2", "short_module": "R" }, { "abbrev": true, "full_module": "FStar.Reflection.Typing", "short_module": "RT" }, { "abbrev": true, "full_module": "FStar.Reflection.Typing.Builtins", "short_module": "RTB" }, { "abbrev": false, "full_module": "Pulse.Syntax", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Syntax", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": 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
Type0
Prims.Tot
[ "total" ]
[]
[ "Prims.nat" ]
[]
false
false
false
true
true
let var =
nat
false
Pulse.Syntax.Base.fsti
Pulse.Syntax.Base.index
val index : Type0
let index = nat
{ "file_name": "lib/steel/pulse/Pulse.Syntax.Base.fsti", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 15, "end_line": 28, "start_col": 0, "start_line": 28 }
(* Copyright 2023 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module Pulse.Syntax.Base module RTB = FStar.Reflection.Typing.Builtins module RT = FStar.Reflection.Typing module R = FStar.Reflection.V2 module RU = Pulse.RuntimeUtils module T = FStar.Tactics.V2 open FStar.List.Tot type constant = R.vconst
{ "checked_file": "/", "dependencies": [ "Pulse.RuntimeUtils.fsti.checked", "Pulse.Reflection.Util.fst.checked", "prims.fst.checked", "FStar.Tactics.V2.fst.checked", "FStar.Sealed.Inhabited.fst.checked", "FStar.Sealed.fsti.checked", "FStar.Reflection.V2.fst.checked", "FStar.Reflection.Typing.Builtins.fsti.checked", "FStar.Reflection.Typing.fsti.checked", "FStar.Range.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked" ], "interface_file": false, "source_file": "Pulse.Syntax.Base.fsti" }
[ { "abbrev": false, "full_module": "FStar.List.Tot", "short_module": null }, { "abbrev": true, "full_module": "FStar.Tactics.V2", "short_module": "T" }, { "abbrev": true, "full_module": "Pulse.RuntimeUtils", "short_module": "RU" }, { "abbrev": true, "full_module": "FStar.Reflection.V2", "short_module": "R" }, { "abbrev": true, "full_module": "FStar.Reflection.Typing", "short_module": "RT" }, { "abbrev": true, "full_module": "FStar.Reflection.Typing.Builtins", "short_module": "RTB" }, { "abbrev": false, "full_module": "Pulse.Syntax", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Syntax", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": 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
Type0
Prims.Tot
[ "total" ]
[]
[ "Prims.nat" ]
[]
false
false
false
true
true
let index =
nat
false
Vale.Stdcalls.X64.GCTR.fst
Vale.Stdcalls.X64.GCTR.gctr256_lemma'
val gctr256_lemma' (s: Ghost.erased (Seq.seq nat32)) (code: V.va_code) (_win: bool) (in_b: b128) (num_bytes: uint64) (out_b inout_b keys_b ctr_b: b128) (num_blocks: uint64) (va_s0: V.va_state) : Ghost (V.va_state & V.va_fuel) (requires gctr256_pre s code in_b num_bytes out_b inout_b keys_b ctr_b num_blocks va_s0) (ensures (fun (va_s1, f) -> V.eval_code code va_s0 f va_s1 /\ VSig.vale_calling_conventions_stdcall va_s0 va_s1 /\ gctr256_post s code in_b num_bytes out_b inout_b keys_b ctr_b num_blocks va_s0 va_s1 f /\ ME.buffer_writeable (as_vale_buffer in_b) /\ ME.buffer_writeable (as_vale_buffer keys_b) /\ ME.buffer_writeable (as_vale_buffer ctr_b) /\ ME.buffer_writeable (as_vale_buffer inout_b) /\ ME.buffer_writeable (as_vale_buffer out_b)))
val gctr256_lemma' (s: Ghost.erased (Seq.seq nat32)) (code: V.va_code) (_win: bool) (in_b: b128) (num_bytes: uint64) (out_b inout_b keys_b ctr_b: b128) (num_blocks: uint64) (va_s0: V.va_state) : Ghost (V.va_state & V.va_fuel) (requires gctr256_pre s code in_b num_bytes out_b inout_b keys_b ctr_b num_blocks va_s0) (ensures (fun (va_s1, f) -> V.eval_code code va_s0 f va_s1 /\ VSig.vale_calling_conventions_stdcall va_s0 va_s1 /\ gctr256_post s code in_b num_bytes out_b inout_b keys_b ctr_b num_blocks va_s0 va_s1 f /\ ME.buffer_writeable (as_vale_buffer in_b) /\ ME.buffer_writeable (as_vale_buffer keys_b) /\ ME.buffer_writeable (as_vale_buffer ctr_b) /\ ME.buffer_writeable (as_vale_buffer inout_b) /\ ME.buffer_writeable (as_vale_buffer out_b)))
let gctr256_lemma' (s:Ghost.erased (Seq.seq nat32)) (code:V.va_code) (_win:bool) (in_b:b128) (num_bytes:uint64) (out_b:b128) (inout_b:b128) (keys_b:b128) (ctr_b:b128) (num_blocks:uint64) (va_s0:V.va_state) : Ghost (V.va_state & V.va_fuel) (requires gctr256_pre s code in_b num_bytes out_b inout_b keys_b ctr_b num_blocks va_s0) (ensures (fun (va_s1, f) -> V.eval_code code va_s0 f va_s1 /\ VSig.vale_calling_conventions_stdcall va_s0 va_s1 /\ gctr256_post s code in_b num_bytes out_b inout_b keys_b ctr_b num_blocks va_s0 va_s1 f /\ ME.buffer_writeable (as_vale_buffer in_b) /\ ME.buffer_writeable (as_vale_buffer keys_b) /\ ME.buffer_writeable (as_vale_buffer ctr_b) /\ ME.buffer_writeable (as_vale_buffer inout_b) /\ ME.buffer_writeable (as_vale_buffer out_b) )) = let va_s1, f = GC.va_lemma_Gctr_bytes_stdcall code va_s0 IA.win AES_256 (as_vale_buffer in_b) (UInt64.v num_bytes) (as_vale_buffer out_b) (as_vale_buffer inout_b) (as_vale_buffer keys_b) (as_vale_buffer ctr_b) (UInt64.v num_blocks) (Ghost.reveal s) in Vale.AsLowStar.MemoryHelpers.buffer_writeable_reveal ME.TUInt8 ME.TUInt128 in_b; Vale.AsLowStar.MemoryHelpers.buffer_writeable_reveal ME.TUInt8 ME.TUInt128 out_b; Vale.AsLowStar.MemoryHelpers.buffer_writeable_reveal ME.TUInt8 ME.TUInt128 inout_b; Vale.AsLowStar.MemoryHelpers.buffer_writeable_reveal ME.TUInt8 ME.TUInt128 keys_b; Vale.AsLowStar.MemoryHelpers.buffer_writeable_reveal ME.TUInt8 ME.TUInt128 ctr_b; (va_s1, f)
{ "file_name": "vale/code/arch/x64/interop/Vale.Stdcalls.X64.GCTR.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 13, "end_line": 228, "start_col": 0, "start_line": 194 }
module Vale.Stdcalls.X64.GCTR open FStar.HyperStack.ST module B = LowStar.Buffer module HS = FStar.HyperStack open FStar.Mul module DV = LowStar.BufferView.Down module UV = LowStar.BufferView.Up open Vale.Def.Types_s open Vale.Interop.Base module IX64 = Vale.Interop.X64 module VSig = Vale.AsLowStar.ValeSig module LSig = Vale.AsLowStar.LowStarSig module ME = Vale.X64.Memory module V = Vale.X64.Decls module IA = Vale.Interop.Assumptions module W = Vale.AsLowStar.Wrapper open Vale.X64.MemoryAdapters module VS = Vale.X64.State module MS = Vale.X64.Machine_s open Vale.AES.AES_s module GC = Vale.AES.X64.GCTR let uint64 = UInt64.t (* A little utility to trigger normalization in types *) noextract let as_t (#a:Type) (x:normal a) : a = x noextract let as_normal_t (#a:Type) (x:a) : normal a = x [@__reduce__] noextract let b128 = buf_t TUInt8 TUInt128 [@__reduce__] noextract let t128_mod = TD_Buffer TUInt8 TUInt128 default_bq [@__reduce__] noextract let t128_no_mod = TD_Buffer TUInt8 TUInt128 ({modified=false; strict_disjointness=false; taint=MS.Secret}) [@__reduce__] noextract let tuint64 = TD_Base TUInt64 [@__reduce__] noextract let (dom: list td{List.length dom <= 20}) = let y = [t128_no_mod; tuint64; t128_mod; t128_mod; t128_no_mod; t128_no_mod; tuint64] in assert_norm (List.length y = 7); y (* Need to rearrange the order of arguments *) [@__reduce__] noextract let gctr128_pre : (Ghost.erased (Seq.seq nat32)) -> VSig.vale_pre dom = fun (s:Ghost.erased (Seq.seq nat32)) (c:V.va_code) (in_b:b128) (num_bytes:uint64) (out_b:b128) (inout_b:b128) (keys_b:b128) (ctr_b:b128) (num_blocks:uint64) (va_s0:V.va_state) -> GC.va_req_Gctr_bytes_stdcall c va_s0 IA.win AES_128 (as_vale_buffer in_b) (UInt64.v num_bytes) (as_vale_buffer out_b) (as_vale_buffer inout_b) (as_vale_buffer keys_b) (as_vale_buffer ctr_b) (UInt64.v num_blocks) (Ghost.reveal s) (* Need to rearrange the order of arguments *) [@__reduce__] noextract let gctr128_post : (Ghost.erased (Seq.seq nat32)) -> VSig.vale_post dom = fun (s:Ghost.erased (Seq.seq nat32)) (c:V.va_code) (in_b:b128) (num_bytes:uint64) (out_b:b128) (inout_b:b128) (keys_b:b128) (ctr_b:b128) (num_blocks:uint64) (va_s0:V.va_state) (va_s1:V.va_state) (f:V.va_fuel) -> GC.va_ens_Gctr_bytes_stdcall c va_s0 IA.win AES_128 (as_vale_buffer in_b) (UInt64.v num_bytes) (as_vale_buffer out_b) (as_vale_buffer inout_b) (as_vale_buffer keys_b) (as_vale_buffer ctr_b) (UInt64.v num_blocks) (Ghost.reveal s) va_s1 f #set-options "--z3rlimit 20" [@__reduce__] noextract let gctr128_lemma' (s:Ghost.erased (Seq.seq nat32)) (code:V.va_code) (_win:bool) (in_b:b128) (num_bytes:uint64) (out_b:b128) (inout_b:b128) (keys_b:b128) (ctr_b:b128) (num_blocks:uint64) (va_s0:V.va_state) : Ghost (V.va_state & V.va_fuel) (requires gctr128_pre s code in_b num_bytes out_b inout_b keys_b ctr_b num_blocks va_s0) (ensures (fun (va_s1, f) -> V.eval_code code va_s0 f va_s1 /\ VSig.vale_calling_conventions_stdcall va_s0 va_s1 /\ gctr128_post s code in_b num_bytes out_b inout_b keys_b ctr_b num_blocks va_s0 va_s1 f /\ ME.buffer_writeable (as_vale_buffer in_b) /\ ME.buffer_writeable (as_vale_buffer keys_b) /\ ME.buffer_writeable (as_vale_buffer ctr_b) /\ ME.buffer_writeable (as_vale_buffer inout_b) /\ ME.buffer_writeable (as_vale_buffer out_b) )) = let va_s1, f = GC.va_lemma_Gctr_bytes_stdcall code va_s0 IA.win AES_128 (as_vale_buffer in_b) (UInt64.v num_bytes) (as_vale_buffer out_b) (as_vale_buffer inout_b) (as_vale_buffer keys_b) (as_vale_buffer ctr_b) (UInt64.v num_blocks) (Ghost.reveal s) in Vale.AsLowStar.MemoryHelpers.buffer_writeable_reveal ME.TUInt8 ME.TUInt128 in_b; Vale.AsLowStar.MemoryHelpers.buffer_writeable_reveal ME.TUInt8 ME.TUInt128 out_b; Vale.AsLowStar.MemoryHelpers.buffer_writeable_reveal ME.TUInt8 ME.TUInt128 inout_b; Vale.AsLowStar.MemoryHelpers.buffer_writeable_reveal ME.TUInt8 ME.TUInt128 keys_b; Vale.AsLowStar.MemoryHelpers.buffer_writeable_reveal ME.TUInt8 ME.TUInt128 ctr_b; (va_s1, f) noextract let gctr128_lemma (s:Ghost.erased (Seq.seq nat32)) = as_t #(VSig.vale_sig_stdcall (gctr128_pre s) (gctr128_post s)) (gctr128_lemma' s) noextract let code_gctr128 = GC.va_code_Gctr_bytes_stdcall IA.win AES_128 [@__reduce__] noextract let lowstar_gctr128_t (s:Ghost.erased (Seq.seq nat32)) = assert_norm (List.length dom + List.length ([]<:list arg) <= 20); IX64.as_lowstar_sig_t_weak_stdcall code_gctr128 dom [] _ _ (W.mk_prediction code_gctr128 dom [] ((gctr128_lemma s) code_gctr128 IA.win)) (* And here's the gcm wrapper itself *) noextract let lowstar_gctr128 (s:Ghost.erased (Seq.seq nat32)) : lowstar_gctr128_t s = assert_norm (List.length dom + List.length ([]<:list arg) <= 20); IX64.wrap_weak_stdcall code_gctr128 dom (W.mk_prediction code_gctr128 dom [] ((gctr128_lemma s) code_gctr128 IA.win)) (* Need to rearrange the order of arguments *) [@__reduce__] noextract let gctr256_pre : (Ghost.erased (Seq.seq nat32)) -> VSig.vale_pre dom = fun (s:Ghost.erased (Seq.seq nat32)) (c:V.va_code) (in_b:b128) (num_bytes:uint64) (out_b:b128) (inout_b:b128) (keys_b:b128) (ctr_b:b128) (num_blocks:uint64) (va_s0:V.va_state) -> GC.va_req_Gctr_bytes_stdcall c va_s0 IA.win AES_256 (as_vale_buffer in_b) (UInt64.v num_bytes) (as_vale_buffer out_b) (as_vale_buffer inout_b) (as_vale_buffer keys_b) (as_vale_buffer ctr_b) (UInt64.v num_blocks) (Ghost.reveal s) (* Need to rearrange the order of arguments *) [@__reduce__] noextract let gctr256_post : (Ghost.erased (Seq.seq nat32)) -> VSig.vale_post dom = fun (s:Ghost.erased (Seq.seq nat32)) (c:V.va_code) (in_b:b128) (num_bytes:uint64) (out_b:b128) (inout_b:b128) (keys_b:b128) (ctr_b:b128) (num_blocks:uint64) (va_s0:V.va_state) (va_s1:V.va_state) (f:V.va_fuel) -> GC.va_ens_Gctr_bytes_stdcall c va_s0 IA.win AES_256 (as_vale_buffer in_b) (UInt64.v num_bytes) (as_vale_buffer out_b) (as_vale_buffer inout_b) (as_vale_buffer keys_b) (as_vale_buffer ctr_b) (UInt64.v num_blocks) (Ghost.reveal s) va_s1 f #set-options "--z3rlimit 20"
{ "checked_file": "/", "dependencies": [ "Vale.X64.State.fsti.checked", "Vale.X64.MemoryAdapters.fsti.checked", "Vale.X64.Memory.fsti.checked", "Vale.X64.Machine_s.fst.checked", "Vale.X64.Decls.fsti.checked", "Vale.Interop.X64.fsti.checked", "Vale.Interop.Base.fst.checked", "Vale.Interop.Assumptions.fst.checked", "Vale.Def.Types_s.fst.checked", "Vale.AsLowStar.Wrapper.fsti.checked", "Vale.AsLowStar.ValeSig.fst.checked", "Vale.AsLowStar.MemoryHelpers.fsti.checked", "Vale.AsLowStar.LowStarSig.fst.checked", "Vale.AES.X64.GCTR.fsti.checked", "Vale.AES.AES_s.fst.checked", "prims.fst.checked", "LowStar.BufferView.Up.fsti.checked", "LowStar.BufferView.Down.fsti.checked", "LowStar.Buffer.fst.checked", "FStar.UInt64.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.List.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked" ], "interface_file": false, "source_file": "Vale.Stdcalls.X64.GCTR.fst" }
[ { "abbrev": true, "full_module": "Vale.AES.X64.GCTR", "short_module": "GC" }, { "abbrev": false, "full_module": "Vale.AES.AES_s", "short_module": null }, { "abbrev": true, "full_module": "Vale.X64.Machine_s", "short_module": "MS" }, { "abbrev": true, "full_module": "Vale.X64.State", "short_module": "VS" }, { "abbrev": false, "full_module": "Vale.X64.MemoryAdapters", "short_module": null }, { "abbrev": true, "full_module": "Vale.AsLowStar.Wrapper", "short_module": "W" }, { "abbrev": true, "full_module": "Vale.Interop.Assumptions", "short_module": "IA" }, { "abbrev": true, "full_module": "Vale.X64.Decls", "short_module": "V" }, { "abbrev": true, "full_module": "Vale.X64.Memory", "short_module": "ME" }, { "abbrev": true, "full_module": "Vale.AsLowStar.LowStarSig", "short_module": "LSig" }, { "abbrev": true, "full_module": "Vale.AsLowStar.ValeSig", "short_module": "VSig" }, { "abbrev": true, "full_module": "Vale.Interop.X64", "short_module": "IX64" }, { "abbrev": false, "full_module": "Vale.Interop.Base", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Types_s", "short_module": null }, { "abbrev": true, "full_module": "LowStar.BufferView.Up", "short_module": "UV" }, { "abbrev": true, "full_module": "LowStar.BufferView.Down", "short_module": "DV" }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": false, "full_module": "Vale.Stdcalls.X64", "short_module": null }, { "abbrev": false, "full_module": "Vale.Stdcalls.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": 1, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": true, "smtencoding_l_arith_repr": "native", "smtencoding_nl_arith_repr": "wrapped", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [ "smt.arith.nl=false", "smt.QI.EAGER_THRESHOLD=100", "smt.CASE_SPLIT=3" ], "z3refresh": false, "z3rlimit": 20, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
s: FStar.Ghost.erased (FStar.Seq.Base.seq Vale.Def.Types_s.nat32) -> code: Vale.X64.Decls.va_code -> _win: Prims.bool -> in_b: Vale.Stdcalls.X64.GCTR.b128 -> num_bytes: Vale.Stdcalls.X64.GCTR.uint64 -> out_b: Vale.Stdcalls.X64.GCTR.b128 -> inout_b: Vale.Stdcalls.X64.GCTR.b128 -> keys_b: Vale.Stdcalls.X64.GCTR.b128 -> ctr_b: Vale.Stdcalls.X64.GCTR.b128 -> num_blocks: Vale.Stdcalls.X64.GCTR.uint64 -> va_s0: Vale.X64.Decls.va_state -> Prims.Ghost (Vale.X64.Decls.va_state * Vale.X64.Decls.va_fuel)
Prims.Ghost
[]
[]
[ "FStar.Ghost.erased", "FStar.Seq.Base.seq", "Vale.Def.Types_s.nat32", "Vale.X64.Decls.va_code", "Prims.bool", "Vale.Stdcalls.X64.GCTR.b128", "Vale.Stdcalls.X64.GCTR.uint64", "Vale.X64.Decls.va_state", "Vale.X64.Decls.va_fuel", "FStar.Pervasives.Native.Mktuple2", "Prims.unit", "Vale.AsLowStar.MemoryHelpers.buffer_writeable_reveal", "Vale.Arch.HeapTypes_s.TUInt8", "Vale.Arch.HeapTypes_s.TUInt128", "FStar.Pervasives.Native.tuple2", "Vale.X64.State.vale_state", "Vale.AES.X64.GCTR.va_lemma_Gctr_bytes_stdcall", "Vale.Interop.Assumptions.win", "Vale.AES.AES_common_s.AES_256", "Vale.X64.MemoryAdapters.as_vale_buffer", "FStar.UInt64.v", "FStar.Ghost.reveal", "Vale.Stdcalls.X64.GCTR.gctr256_pre", "Prims.l_and", "Vale.X64.Decls.eval_code", "Vale.AsLowStar.ValeSig.vale_calling_conventions_stdcall", "Vale.Stdcalls.X64.GCTR.gctr256_post", "Vale.X64.Memory.buffer_writeable" ]
[]
false
false
false
false
false
let gctr256_lemma' (s: Ghost.erased (Seq.seq nat32)) (code: V.va_code) (_win: bool) (in_b: b128) (num_bytes: uint64) (out_b inout_b keys_b ctr_b: b128) (num_blocks: uint64) (va_s0: V.va_state) : Ghost (V.va_state & V.va_fuel) (requires gctr256_pre s code in_b num_bytes out_b inout_b keys_b ctr_b num_blocks va_s0) (ensures (fun (va_s1, f) -> V.eval_code code va_s0 f va_s1 /\ VSig.vale_calling_conventions_stdcall va_s0 va_s1 /\ gctr256_post s code in_b num_bytes out_b inout_b keys_b ctr_b num_blocks va_s0 va_s1 f /\ ME.buffer_writeable (as_vale_buffer in_b) /\ ME.buffer_writeable (as_vale_buffer keys_b) /\ ME.buffer_writeable (as_vale_buffer ctr_b) /\ ME.buffer_writeable (as_vale_buffer inout_b) /\ ME.buffer_writeable (as_vale_buffer out_b))) =
let va_s1, f = GC.va_lemma_Gctr_bytes_stdcall code va_s0 IA.win AES_256 (as_vale_buffer in_b) (UInt64.v num_bytes) (as_vale_buffer out_b) (as_vale_buffer inout_b) (as_vale_buffer keys_b) (as_vale_buffer ctr_b) (UInt64.v num_blocks) (Ghost.reveal s) in Vale.AsLowStar.MemoryHelpers.buffer_writeable_reveal ME.TUInt8 ME.TUInt128 in_b; Vale.AsLowStar.MemoryHelpers.buffer_writeable_reveal ME.TUInt8 ME.TUInt128 out_b; Vale.AsLowStar.MemoryHelpers.buffer_writeable_reveal ME.TUInt8 ME.TUInt128 inout_b; Vale.AsLowStar.MemoryHelpers.buffer_writeable_reveal ME.TUInt8 ME.TUInt128 keys_b; Vale.AsLowStar.MemoryHelpers.buffer_writeable_reveal ME.TUInt8 ME.TUInt128 ctr_b; (va_s1, f)
false
LowParse.Low.Bytes.fst
LowParse.Low.Bytes.jump_bounded_vlbytes'
val jump_bounded_vlbytes' (min: nat) (max: nat{min <= max /\ max > 0 /\ max < 4294967296}) (l: nat{l >= log256' max /\ l <= 4}) : Tot (jumper (parse_bounded_vlbytes' min max l))
val jump_bounded_vlbytes' (min: nat) (max: nat{min <= max /\ max > 0 /\ max < 4294967296}) (l: nat{l >= log256' max /\ l <= 4}) : Tot (jumper (parse_bounded_vlbytes' min max l))
let jump_bounded_vlbytes' (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (l: nat { l >= log256' max /\ l <= 4 } ) : Tot (jumper (parse_bounded_vlbytes' min max l)) = jump_synth (jump_bounded_vldata_strong' min max l serialize_all_bytes) (synth_bounded_vlbytes min max) ()
{ "file_name": "src/lowparse/LowParse.Low.Bytes.fst", "git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
{ "end_col": 6, "end_line": 389, "start_col": 0, "start_line": 381 }
module LowParse.Low.Bytes include LowParse.Spec.Bytes include LowParse.Low.Combinators include LowParse.Low.VLData include LowParse.Low.VLGen include LowParse.Low.Int module U32 = FStar.UInt32 module HS = FStar.HyperStack module B = LowStar.Monotonic.Buffer module BF = LowStar.Buffer // for local variables in store_bytes module BY = LowParse.Bytes32 module HST = FStar.HyperStack.ST module U8 = FStar.UInt8 module Cast = FStar.Int.Cast module U64 = FStar.UInt64 inline_for_extraction let validate_flbytes (sz: nat) (sz64: U64.t { U64.v sz64 == sz /\ sz < 4294967296 } ) : Tot (validator (parse_flbytes sz)) = validate_total_constant_size (parse_flbytes sz) sz64 () inline_for_extraction let jump_flbytes (sz: nat) (sz32: U32.t { U32.v sz32 == sz } ) : Tot (jumper (parse_flbytes sz)) = jump_constant_size (parse_flbytes sz) sz32 () let valid_flbytes_intro (h: HS.mem) (sz: nat { sz < 4294967296 } ) (#rrel #rel: _) (s: slice rrel rel) (pos: U32.t) : Lemma (requires (U32.v pos + sz <= U32.v s.len /\ live_slice h s)) (ensures ( valid_content_pos (parse_flbytes sz) h s pos (BY.hide (bytes_of_slice_from_to h s pos (pos `U32.add` U32.uint_to_t sz))) (pos `U32.add` U32.uint_to_t sz) )) = valid_facts (parse_flbytes sz) h s pos let valid_pos_flbytes_elim (h: HS.mem) (sz: nat { sz < 4294967296 } ) (#rrel #rel: _) (s: slice rrel rel) (pos pos' : U32.t) : Lemma (requires (valid_pos (parse_flbytes sz) h s pos pos')) (ensures (U32.v pos + sz == U32.v pos')) [SMTPat (valid_pos (parse_flbytes sz) h s pos pos')] = valid_facts (parse_flbytes sz) h s pos let valid_flbytes_elim (h: HS.mem) (sz: nat { sz < 4294967296 } ) (#rrel #rel: _) (s: slice rrel rel) (pos: U32.t) : Lemma (requires (valid (parse_flbytes sz) h s pos)) (ensures ( valid_content_pos (parse_flbytes sz) h s pos (BY.hide (bytes_of_slice_from_to h s pos (pos `U32.add` U32.uint_to_t sz))) (pos `U32.add` U32.uint_to_t sz) )) = valid_flbytes_intro h sz s pos let clens_flbytes_slice (sz: nat) (from: U32.t) (to: U32.t {U32.v from <= U32.v to /\ U32.v to <= sz } ) : Tot (clens (BY.lbytes sz) (BY.lbytes (U32.v to - U32.v from))) = { clens_cond = (fun _ -> True); clens_get = (fun (x: BY.lbytes sz) -> (BY.slice x from to <: BY.lbytes (U32.v to - U32.v from))); } #push-options "--z3rlimit 16" let gaccessor_flbytes_slice' (sz: nat { sz < 4294967296 } ) (from: U32.t) (to: U32.t {U32.v from <= U32.v to /\ U32.v to <= sz } ) : Tot (gaccessor' (parse_flbytes sz) (parse_flbytes (U32.v to - U32.v from)) (clens_flbytes_slice sz from to)) = fun (input: bytes) -> ( begin if Seq.length input < sz then (0) // dummy else (U32.v from) end) let gaccessor_flbytes_slice (sz: nat { sz < 4294967296 } ) (from: U32.t) (to: U32.t {U32.v from <= U32.v to /\ U32.v to <= sz } ) : Tot (gaccessor (parse_flbytes sz) (parse_flbytes (U32.v to - U32.v from)) (clens_flbytes_slice sz from to)) = assert (forall x . gaccessor_pre (parse_flbytes sz) (parse_flbytes (U32.v to - U32.v from)) (clens_flbytes_slice sz from to) x ==> sz <= Seq.length x); gaccessor_prop_equiv (parse_flbytes sz) (parse_flbytes (U32.v to - U32.v from)) (clens_flbytes_slice sz from to) (gaccessor_flbytes_slice' sz from to); gaccessor_flbytes_slice' sz from to inline_for_extraction let accessor_flbytes_slice (sz: nat { sz < 4294967296 } ) (from: U32.t) (to: U32.t {U32.v from <= U32.v to /\ U32.v to <= sz } ) : Tot (accessor (gaccessor_flbytes_slice sz from to)) = fun #rrel #rel input pos -> let h = HST.get () in [@inline_let] let _ = slice_access_eq h (gaccessor_flbytes_slice sz from to) input pos in pos `U32.add` from #pop-options let clens_flbytes_get (sz: nat) (i: U32.t { U32.v i < sz } ) : Tot (clens (BY.lbytes sz) byte) = { clens_cond = (fun _ -> True); clens_get = (fun (x: BY.lbytes sz) -> (BY.get x i <: byte)); } #push-options "--z3rlimit 16 --max_fuel 1" let gaccessor_flbytes_get' (sz: nat { sz < 4294967296 } ) (i: U32.t { U32.v i < sz } ) : Tot (gaccessor' (parse_flbytes sz) (parse_u8) (clens_flbytes_get sz i)) = fun (input: bytes) -> ( begin let res = if Seq.length input < U32.v i then (0) // dummy else (U32.v i) in let g () : Lemma (requires (gaccessor_pre (parse_flbytes sz) parse_u8 (clens_flbytes_get sz i) input)) (ensures (gaccessor_post (parse_flbytes sz) parse_u8 (clens_flbytes_get sz i) input res)) = parser_kind_prop_equiv (get_parser_kind parse_u8) parse_u8; assert (res == (U32.v i)); parse_u8_spec' (Seq.slice input (U32.v i) (U32.v i + 1)); parse_strong_prefix parse_u8 (Seq.slice input (U32.v i) (U32.v i + 1)) (Seq.slice input (U32.v i) (Seq.length input)) in Classical.move_requires g (); res end) #pop-options let gaccessor_flbytes_get (sz: nat { sz < 4294967296 } ) (i: U32.t { U32.v i < sz } ) : Tot (gaccessor (parse_flbytes sz) (parse_u8) (clens_flbytes_get sz i)) = assert (forall x . gaccessor_pre (parse_flbytes sz) (parse_u8) (clens_flbytes_get sz i) x ==> U32.v i <= Seq.length x); gaccessor_prop_equiv (parse_flbytes sz) (parse_u8) (clens_flbytes_get sz i) (gaccessor_flbytes_get' sz i); gaccessor_flbytes_get' sz i inline_for_extraction let accessor_flbytes_get (sz: nat { sz < 4294967296 } ) (i: U32.t { U32.v i < sz } ) : Tot (accessor (gaccessor_flbytes_get sz i)) = fun #rrel #rel input pos -> let h = HST.get () in [@inline_let] let _ = slice_access_eq h (gaccessor_flbytes_get sz i) input pos in pos `U32.add` i (* Temporary: flbytes as leaf values *) (* TODO: convert store_bytes to monotonic buffers, using the "writable" predicate *) #push-options "--z3rlimit 32" inline_for_extraction let store_bytes (src: BY.bytes) (src_from src_to: U32.t) (#rrel #rel: _) (dst: B.mbuffer byte rrel rel) (dst_pos: U32.t) : HST.Stack unit (requires (fun h -> B.live h dst /\ U32.v src_from <= U32.v src_to /\ U32.v src_to <= BY.length src /\ U32.v dst_pos + (U32.v src_to - U32.v src_from) <= B.length dst /\ writable dst (U32.v dst_pos) (U32.v dst_pos + (U32.v src_to - U32.v src_from)) h )) (ensures (fun h _ h' -> B.modifies (B.loc_buffer_from_to dst dst_pos (dst_pos `U32.add` (src_to `U32.sub` src_from))) h h' /\ Seq.slice (B.as_seq h' dst) (U32.v dst_pos) (U32.v dst_pos + (U32.v src_to - U32.v src_from)) == Seq.slice (BY.reveal src) (U32.v src_from) (U32.v src_to) )) = let h0 = HST.get () in HST.push_frame (); let h1 = HST.get () in let bi = BF.alloca 0ul 1ul in let h2 = HST.get () in let len = src_to `U32.sub` src_from in C.Loops.do_while (fun h stop -> B.modifies (B.loc_union (B.loc_region_only true (HS.get_tip h1)) (B.loc_buffer_from_to dst dst_pos (dst_pos `U32.add` len))) h2 h /\ B.live h bi /\ ( let i = Seq.index (B.as_seq h bi) 0 in U32.v i <= U32.v len /\ writable dst (U32.v dst_pos) (U32.v dst_pos + U32.v len) h /\ Seq.slice (B.as_seq h dst) (U32.v dst_pos) (U32.v dst_pos + U32.v i) `Seq.equal` Seq.slice (BY.reveal src) (U32.v src_from) (U32.v src_from + U32.v i) /\ (stop == true ==> i == len) )) (fun _ -> let i = B.index bi 0ul in if i = len then true else begin let x = BY.get src (src_from `U32.add` i) in mbuffer_upd dst (Ghost.hide (U32.v dst_pos)) (Ghost.hide (U32.v dst_pos + U32.v len)) (dst_pos `U32.add` i) x; let i' = i `U32.add` 1ul in B.upd bi 0ul i'; let h' = HST.get () in Seq.lemma_split (Seq.slice (B.as_seq h' dst) (U32.v dst_pos) (U32.v dst_pos + U32.v i')) (U32.v i); i' = len end ) ; HST.pop_frame () #pop-options inline_for_extraction let serialize32_flbytes (sz32: U32.t) : Tot (serializer32 (serialize_flbytes (U32.v sz32))) = fun (x: BY.lbytes (U32.v sz32)) #rrel #rel b pos -> let _ = store_bytes x 0ul sz32 b pos in sz32 inline_for_extraction let write_flbytes (sz32: U32.t) : Tot (leaf_writer_strong (serialize_flbytes (U32.v sz32))) = leaf_writer_strong_of_serializer32 (serialize32_flbytes sz32) () inline_for_extraction let write_flbytes_weak (sz32: U32.t { U32.v sz32 < 4294967295 } ) // need to return that value if output buffer is too small : Tot (leaf_writer_weak (serialize_flbytes (U32.v sz32))) = leaf_writer_weak_of_strong_constant_size (write_flbytes sz32) sz32 () (* // TODO: remove, since nobody is using this inline_for_extraction let read_flbytes (sz32: U32.t) : Tot (leaf_reader (parse_flbytes (U32.v sz32))) = fun input pos -> let h = HST.get () in [@inline_let] let _ = valid_facts (parse_flbytes (U32.v sz32)) h input pos in BY.of_buffer sz32 (B.sub input.base pos sz32) *) (* Equality test between a vlbytes and a constant lbytes *) #push-options "--z3rlimit 32" inline_for_extraction let buffer_equals_bytes (const: BY.bytes) (#rrel #rel: _) (b: B.mbuffer byte rrel rel) (pos: U32.t) : HST.Stack bool (requires (fun h -> B.live h b /\ U32.v pos + BY.length const <= B.length b )) (ensures (fun h res h' -> B.modifies B.loc_none h h' /\ (res == true <==> Seq.slice (B.as_seq h b) (U32.v pos) (U32.v pos + BY.length const) == BY.reveal const) )) = let h0 = HST.get () in HST.push_frame (); let len = BY.len const in let bi = BF.alloca 0ul 1ul in let bres = BF.alloca true 1ul in let h1 = HST.get () in [@inline_let] let inv (h: HS.mem) (stop: bool) : GTot Type0 = B.modifies (B.loc_union (B.loc_buffer bi) (B.loc_buffer bres)) h1 h /\ ( let length = U32.v len in let i32 = (Seq.index (B.as_seq h bi) 0) in let i = U32.v i32 in let res = Seq.index (B.as_seq h bres) 0 in i <= length /\ (stop == false ==> res == true) /\ ((stop == true /\ res == true) ==> i == length) /\ (res == true <==> Seq.slice (B.as_seq h b) (U32.v pos) (U32.v pos + i) `Seq.equal` Seq.slice (BY.reveal const) 0 i) ) in C.Loops.do_while inv (fun _ -> let i = B.index bi 0ul in if i = len then true else begin let i' = i `U32.add` 1ul in [@inline_let] let _ = let s1 = (Seq.slice (B.as_seq h0 b) (U32.v pos) (U32.v pos + U32.v i)) in let c1 = (B.get h0 b (U32.v pos + U32.v i)) in let s2 = (Seq.slice (BY.reveal const) 0 (U32.v i)) in let c2 = (BY.index const (U32.v i)) in assert (Seq.slice (B.as_seq h0 b) (U32.v pos) (U32.v pos + U32.v i') `Seq.equal` Seq.snoc s1 c1); assert (Seq.slice (BY.reveal const) 0 (U32.v i') `Seq.equal` Seq.snoc s2 c2); Classical.move_requires (Seq.lemma_snoc_inj s1 s2 c1) c2 in let res = B.index b (pos `U32.add` i) = BY.get const i in B.upd bres 0ul res; B.upd bi 0ul i'; not res end ); let res = B.index bres 0ul in HST.pop_frame (); res #pop-options inline_for_extraction let valid_slice_equals_bytes (const: BY.bytes) (#rrel #rel: _) (input: slice rrel rel) (pos: U32.t) : HST.Stack bool (requires (fun h -> valid (parse_flbytes (BY.length const)) h input pos )) (ensures (fun h res h' -> B.modifies B.loc_none h h' /\ (res == true <==> contents (parse_flbytes (BY.length const)) h input pos == const ))) = let h = HST.get () in [@inline_let] let _ = valid_facts (parse_flbytes (BY.length const)) h input pos in buffer_equals_bytes const input.base pos inline_for_extraction let validate_all_bytes () : Tot (validator parse_all_bytes) = fun #rrel #rel input pos -> let h = HST.get () in [@inline_let] let _ = valid_facts parse_all_bytes h input (uint64_to_uint32 pos) in Cast.uint32_to_uint64 input.len inline_for_extraction let validate_bounded_vlbytes' (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (l: nat { l >= log256' max /\ l <= 4 } ) : Tot (validator (parse_bounded_vlbytes' min max l)) = validate_synth (validate_bounded_vldata_strong' min max l serialize_all_bytes (validate_all_bytes ())) (synth_bounded_vlbytes min max) () inline_for_extraction let validate_bounded_vlbytes (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) : Tot (validator (parse_bounded_vlbytes min max)) = validate_bounded_vlbytes' min max (log256' max) inline_for_extraction let jump_all_bytes () : Tot (jumper parse_all_bytes) = fun #rrel #rel input pos -> let h = HST.get () in [@inline_let] let _ = valid_facts parse_all_bytes h input pos in input.len
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowStar.Monotonic.Buffer.fsti.checked", "LowStar.Buffer.fst.checked", "LowParse.Spec.Bytes.fst.checked", "LowParse.Low.VLGen.fst.checked", "LowParse.Low.VLData.fst.checked", "LowParse.Low.Int.fsti.checked", "LowParse.Low.Combinators.fsti.checked", "LowParse.Bytes32.fst.checked", "FStar.UInt8.fsti.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Int.Cast.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked", "FStar.Classical.fsti.checked", "C.Loops.fst.checked" ], "interface_file": false, "source_file": "LowParse.Low.Bytes.fst" }
[ { "abbrev": true, "full_module": "LowStar.Buffer // for local variables in store_bytes", "short_module": "BF" }, { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "FStar.Int.Cast", "short_module": "Cast" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "LowParse.Bytes32", "short_module": "BY" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "BF" }, { "abbrev": true, "full_module": "LowStar.Monotonic.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": false, "full_module": "LowParse.Low.Int", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low.VLGen", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low.VLData", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low.Combinators", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec.Bytes", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
min: Prims.nat -> max: Prims.nat{min <= max /\ max > 0 /\ max < 4294967296} -> l: Prims.nat{l >= LowParse.Spec.BoundedInt.log256' max /\ l <= 4} -> LowParse.Low.Base.jumper (LowParse.Spec.Bytes.parse_bounded_vlbytes' min max l)
Prims.Tot
[ "total" ]
[]
[ "Prims.nat", "Prims.l_and", "Prims.b2t", "Prims.op_LessThanOrEqual", "Prims.op_GreaterThan", "Prims.op_LessThan", "Prims.op_GreaterThanOrEqual", "LowParse.Spec.BoundedInt.log256'", "LowParse.Low.Combinators.jump_synth", "LowParse.Spec.VLData.parse_bounded_vldata_strong_kind", "LowParse.Spec.Bytes.parse_all_bytes_kind", "LowParse.Spec.VLData.parse_bounded_vldata_strong_t", "FStar.Bytes.bytes", "LowParse.Spec.Bytes.parse_all_bytes", "LowParse.Spec.Bytes.serialize_all_bytes", "LowParse.Spec.Bytes.parse_bounded_vlbytes_t", "LowParse.Spec.VLData.parse_bounded_vldata_strong'", "LowParse.Low.VLData.jump_bounded_vldata_strong'", "LowParse.Spec.Bytes.synth_bounded_vlbytes", "LowParse.Low.Base.jumper", "LowParse.Spec.Bytes.parse_bounded_vlbytes'" ]
[]
false
false
false
false
false
let jump_bounded_vlbytes' (min: nat) (max: nat{min <= max /\ max > 0 /\ max < 4294967296}) (l: nat{l >= log256' max /\ l <= 4}) : Tot (jumper (parse_bounded_vlbytes' min max l)) =
jump_synth (jump_bounded_vldata_strong' min max l serialize_all_bytes) (synth_bounded_vlbytes min max) ()
false
Pulse.Syntax.Base.fsti
Pulse.Syntax.Base.range
val range : Type0
let range = r:FStar.Range.range { range_singleton_trigger r }
{ "file_name": "lib/steel/pulse/Pulse.Syntax.Base.fsti", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 61, "end_line": 34, "start_col": 0, "start_line": 34 }
(* Copyright 2023 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module Pulse.Syntax.Base module RTB = FStar.Reflection.Typing.Builtins module RT = FStar.Reflection.Typing module R = FStar.Reflection.V2 module RU = Pulse.RuntimeUtils module T = FStar.Tactics.V2 open FStar.List.Tot type constant = R.vconst let var = nat let index = nat type universe = R.universe (* locally nameless. *)
{ "checked_file": "/", "dependencies": [ "Pulse.RuntimeUtils.fsti.checked", "Pulse.Reflection.Util.fst.checked", "prims.fst.checked", "FStar.Tactics.V2.fst.checked", "FStar.Sealed.Inhabited.fst.checked", "FStar.Sealed.fsti.checked", "FStar.Reflection.V2.fst.checked", "FStar.Reflection.Typing.Builtins.fsti.checked", "FStar.Reflection.Typing.fsti.checked", "FStar.Range.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked" ], "interface_file": false, "source_file": "Pulse.Syntax.Base.fsti" }
[ { "abbrev": false, "full_module": "FStar.List.Tot", "short_module": null }, { "abbrev": true, "full_module": "FStar.Tactics.V2", "short_module": "T" }, { "abbrev": true, "full_module": "Pulse.RuntimeUtils", "short_module": "RU" }, { "abbrev": true, "full_module": "FStar.Reflection.V2", "short_module": "R" }, { "abbrev": true, "full_module": "FStar.Reflection.Typing", "short_module": "RT" }, { "abbrev": true, "full_module": "FStar.Reflection.Typing.Builtins", "short_module": "RTB" }, { "abbrev": false, "full_module": "Pulse.Syntax", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Syntax", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": 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
Type0
Prims.Tot
[ "total" ]
[]
[ "FStar.Range.range", "Pulse.Syntax.Base.range_singleton_trigger" ]
[]
false
false
false
true
true
let range =
r: FStar.Range.range{range_singleton_trigger r}
false
LowParse.Low.Bytes.fst
LowParse.Low.Bytes.gaccessor_vlbytes'
val gaccessor_vlbytes' (min: nat) (max: nat{min <= max /\ max > 0 /\ max < 4294967296}) (l: nat{l >= log256' max /\ l <= 4}) (length: nat{length < 4294967296}) : Tot (gaccessor (parse_bounded_vlbytes' min max l) (parse_flbytes length) (clens_vlbytes min max length))
val gaccessor_vlbytes' (min: nat) (max: nat{min <= max /\ max > 0 /\ max < 4294967296}) (l: nat{l >= log256' max /\ l <= 4}) (length: nat{length < 4294967296}) : Tot (gaccessor (parse_bounded_vlbytes' min max l) (parse_flbytes length) (clens_vlbytes min max length))
let gaccessor_vlbytes' (min: nat) (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (l: nat { l >= log256' max /\ l <= 4 } ) (length: nat { length < 4294967296 } ) : Tot (gaccessor (parse_bounded_vlbytes' min max l) (parse_flbytes length) (clens_vlbytes min max length)) = parser_kind_prop_equiv (parse_bounded_vldata_strong_kind min max l parse_all_bytes_kind) (parse_bounded_vlbytes' min max l); assert (forall x . gaccessor_pre (parse_bounded_vlbytes' min max l) (parse_flbytes length) (clens_vlbytes min max length) x ==> Seq.length x >= l); gaccessor_prop_equiv (parse_bounded_vlbytes' min max l) (parse_flbytes length) (clens_vlbytes min max length) (gaccessor_vlbytes'_aux min max l length); gaccessor_vlbytes'_aux min max l length
{ "file_name": "src/lowparse/LowParse.Low.Bytes.fst", "git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
{ "end_col": 41, "end_line": 643, "start_col": 0, "start_line": 634 }
module LowParse.Low.Bytes include LowParse.Spec.Bytes include LowParse.Low.Combinators include LowParse.Low.VLData include LowParse.Low.VLGen include LowParse.Low.Int module U32 = FStar.UInt32 module HS = FStar.HyperStack module B = LowStar.Monotonic.Buffer module BF = LowStar.Buffer // for local variables in store_bytes module BY = LowParse.Bytes32 module HST = FStar.HyperStack.ST module U8 = FStar.UInt8 module Cast = FStar.Int.Cast module U64 = FStar.UInt64 inline_for_extraction let validate_flbytes (sz: nat) (sz64: U64.t { U64.v sz64 == sz /\ sz < 4294967296 } ) : Tot (validator (parse_flbytes sz)) = validate_total_constant_size (parse_flbytes sz) sz64 () inline_for_extraction let jump_flbytes (sz: nat) (sz32: U32.t { U32.v sz32 == sz } ) : Tot (jumper (parse_flbytes sz)) = jump_constant_size (parse_flbytes sz) sz32 () let valid_flbytes_intro (h: HS.mem) (sz: nat { sz < 4294967296 } ) (#rrel #rel: _) (s: slice rrel rel) (pos: U32.t) : Lemma (requires (U32.v pos + sz <= U32.v s.len /\ live_slice h s)) (ensures ( valid_content_pos (parse_flbytes sz) h s pos (BY.hide (bytes_of_slice_from_to h s pos (pos `U32.add` U32.uint_to_t sz))) (pos `U32.add` U32.uint_to_t sz) )) = valid_facts (parse_flbytes sz) h s pos let valid_pos_flbytes_elim (h: HS.mem) (sz: nat { sz < 4294967296 } ) (#rrel #rel: _) (s: slice rrel rel) (pos pos' : U32.t) : Lemma (requires (valid_pos (parse_flbytes sz) h s pos pos')) (ensures (U32.v pos + sz == U32.v pos')) [SMTPat (valid_pos (parse_flbytes sz) h s pos pos')] = valid_facts (parse_flbytes sz) h s pos let valid_flbytes_elim (h: HS.mem) (sz: nat { sz < 4294967296 } ) (#rrel #rel: _) (s: slice rrel rel) (pos: U32.t) : Lemma (requires (valid (parse_flbytes sz) h s pos)) (ensures ( valid_content_pos (parse_flbytes sz) h s pos (BY.hide (bytes_of_slice_from_to h s pos (pos `U32.add` U32.uint_to_t sz))) (pos `U32.add` U32.uint_to_t sz) )) = valid_flbytes_intro h sz s pos let clens_flbytes_slice (sz: nat) (from: U32.t) (to: U32.t {U32.v from <= U32.v to /\ U32.v to <= sz } ) : Tot (clens (BY.lbytes sz) (BY.lbytes (U32.v to - U32.v from))) = { clens_cond = (fun _ -> True); clens_get = (fun (x: BY.lbytes sz) -> (BY.slice x from to <: BY.lbytes (U32.v to - U32.v from))); } #push-options "--z3rlimit 16" let gaccessor_flbytes_slice' (sz: nat { sz < 4294967296 } ) (from: U32.t) (to: U32.t {U32.v from <= U32.v to /\ U32.v to <= sz } ) : Tot (gaccessor' (parse_flbytes sz) (parse_flbytes (U32.v to - U32.v from)) (clens_flbytes_slice sz from to)) = fun (input: bytes) -> ( begin if Seq.length input < sz then (0) // dummy else (U32.v from) end) let gaccessor_flbytes_slice (sz: nat { sz < 4294967296 } ) (from: U32.t) (to: U32.t {U32.v from <= U32.v to /\ U32.v to <= sz } ) : Tot (gaccessor (parse_flbytes sz) (parse_flbytes (U32.v to - U32.v from)) (clens_flbytes_slice sz from to)) = assert (forall x . gaccessor_pre (parse_flbytes sz) (parse_flbytes (U32.v to - U32.v from)) (clens_flbytes_slice sz from to) x ==> sz <= Seq.length x); gaccessor_prop_equiv (parse_flbytes sz) (parse_flbytes (U32.v to - U32.v from)) (clens_flbytes_slice sz from to) (gaccessor_flbytes_slice' sz from to); gaccessor_flbytes_slice' sz from to inline_for_extraction let accessor_flbytes_slice (sz: nat { sz < 4294967296 } ) (from: U32.t) (to: U32.t {U32.v from <= U32.v to /\ U32.v to <= sz } ) : Tot (accessor (gaccessor_flbytes_slice sz from to)) = fun #rrel #rel input pos -> let h = HST.get () in [@inline_let] let _ = slice_access_eq h (gaccessor_flbytes_slice sz from to) input pos in pos `U32.add` from #pop-options let clens_flbytes_get (sz: nat) (i: U32.t { U32.v i < sz } ) : Tot (clens (BY.lbytes sz) byte) = { clens_cond = (fun _ -> True); clens_get = (fun (x: BY.lbytes sz) -> (BY.get x i <: byte)); } #push-options "--z3rlimit 16 --max_fuel 1" let gaccessor_flbytes_get' (sz: nat { sz < 4294967296 } ) (i: U32.t { U32.v i < sz } ) : Tot (gaccessor' (parse_flbytes sz) (parse_u8) (clens_flbytes_get sz i)) = fun (input: bytes) -> ( begin let res = if Seq.length input < U32.v i then (0) // dummy else (U32.v i) in let g () : Lemma (requires (gaccessor_pre (parse_flbytes sz) parse_u8 (clens_flbytes_get sz i) input)) (ensures (gaccessor_post (parse_flbytes sz) parse_u8 (clens_flbytes_get sz i) input res)) = parser_kind_prop_equiv (get_parser_kind parse_u8) parse_u8; assert (res == (U32.v i)); parse_u8_spec' (Seq.slice input (U32.v i) (U32.v i + 1)); parse_strong_prefix parse_u8 (Seq.slice input (U32.v i) (U32.v i + 1)) (Seq.slice input (U32.v i) (Seq.length input)) in Classical.move_requires g (); res end) #pop-options let gaccessor_flbytes_get (sz: nat { sz < 4294967296 } ) (i: U32.t { U32.v i < sz } ) : Tot (gaccessor (parse_flbytes sz) (parse_u8) (clens_flbytes_get sz i)) = assert (forall x . gaccessor_pre (parse_flbytes sz) (parse_u8) (clens_flbytes_get sz i) x ==> U32.v i <= Seq.length x); gaccessor_prop_equiv (parse_flbytes sz) (parse_u8) (clens_flbytes_get sz i) (gaccessor_flbytes_get' sz i); gaccessor_flbytes_get' sz i inline_for_extraction let accessor_flbytes_get (sz: nat { sz < 4294967296 } ) (i: U32.t { U32.v i < sz } ) : Tot (accessor (gaccessor_flbytes_get sz i)) = fun #rrel #rel input pos -> let h = HST.get () in [@inline_let] let _ = slice_access_eq h (gaccessor_flbytes_get sz i) input pos in pos `U32.add` i (* Temporary: flbytes as leaf values *) (* TODO: convert store_bytes to monotonic buffers, using the "writable" predicate *) #push-options "--z3rlimit 32" inline_for_extraction let store_bytes (src: BY.bytes) (src_from src_to: U32.t) (#rrel #rel: _) (dst: B.mbuffer byte rrel rel) (dst_pos: U32.t) : HST.Stack unit (requires (fun h -> B.live h dst /\ U32.v src_from <= U32.v src_to /\ U32.v src_to <= BY.length src /\ U32.v dst_pos + (U32.v src_to - U32.v src_from) <= B.length dst /\ writable dst (U32.v dst_pos) (U32.v dst_pos + (U32.v src_to - U32.v src_from)) h )) (ensures (fun h _ h' -> B.modifies (B.loc_buffer_from_to dst dst_pos (dst_pos `U32.add` (src_to `U32.sub` src_from))) h h' /\ Seq.slice (B.as_seq h' dst) (U32.v dst_pos) (U32.v dst_pos + (U32.v src_to - U32.v src_from)) == Seq.slice (BY.reveal src) (U32.v src_from) (U32.v src_to) )) = let h0 = HST.get () in HST.push_frame (); let h1 = HST.get () in let bi = BF.alloca 0ul 1ul in let h2 = HST.get () in let len = src_to `U32.sub` src_from in C.Loops.do_while (fun h stop -> B.modifies (B.loc_union (B.loc_region_only true (HS.get_tip h1)) (B.loc_buffer_from_to dst dst_pos (dst_pos `U32.add` len))) h2 h /\ B.live h bi /\ ( let i = Seq.index (B.as_seq h bi) 0 in U32.v i <= U32.v len /\ writable dst (U32.v dst_pos) (U32.v dst_pos + U32.v len) h /\ Seq.slice (B.as_seq h dst) (U32.v dst_pos) (U32.v dst_pos + U32.v i) `Seq.equal` Seq.slice (BY.reveal src) (U32.v src_from) (U32.v src_from + U32.v i) /\ (stop == true ==> i == len) )) (fun _ -> let i = B.index bi 0ul in if i = len then true else begin let x = BY.get src (src_from `U32.add` i) in mbuffer_upd dst (Ghost.hide (U32.v dst_pos)) (Ghost.hide (U32.v dst_pos + U32.v len)) (dst_pos `U32.add` i) x; let i' = i `U32.add` 1ul in B.upd bi 0ul i'; let h' = HST.get () in Seq.lemma_split (Seq.slice (B.as_seq h' dst) (U32.v dst_pos) (U32.v dst_pos + U32.v i')) (U32.v i); i' = len end ) ; HST.pop_frame () #pop-options inline_for_extraction let serialize32_flbytes (sz32: U32.t) : Tot (serializer32 (serialize_flbytes (U32.v sz32))) = fun (x: BY.lbytes (U32.v sz32)) #rrel #rel b pos -> let _ = store_bytes x 0ul sz32 b pos in sz32 inline_for_extraction let write_flbytes (sz32: U32.t) : Tot (leaf_writer_strong (serialize_flbytes (U32.v sz32))) = leaf_writer_strong_of_serializer32 (serialize32_flbytes sz32) () inline_for_extraction let write_flbytes_weak (sz32: U32.t { U32.v sz32 < 4294967295 } ) // need to return that value if output buffer is too small : Tot (leaf_writer_weak (serialize_flbytes (U32.v sz32))) = leaf_writer_weak_of_strong_constant_size (write_flbytes sz32) sz32 () (* // TODO: remove, since nobody is using this inline_for_extraction let read_flbytes (sz32: U32.t) : Tot (leaf_reader (parse_flbytes (U32.v sz32))) = fun input pos -> let h = HST.get () in [@inline_let] let _ = valid_facts (parse_flbytes (U32.v sz32)) h input pos in BY.of_buffer sz32 (B.sub input.base pos sz32) *) (* Equality test between a vlbytes and a constant lbytes *) #push-options "--z3rlimit 32" inline_for_extraction let buffer_equals_bytes (const: BY.bytes) (#rrel #rel: _) (b: B.mbuffer byte rrel rel) (pos: U32.t) : HST.Stack bool (requires (fun h -> B.live h b /\ U32.v pos + BY.length const <= B.length b )) (ensures (fun h res h' -> B.modifies B.loc_none h h' /\ (res == true <==> Seq.slice (B.as_seq h b) (U32.v pos) (U32.v pos + BY.length const) == BY.reveal const) )) = let h0 = HST.get () in HST.push_frame (); let len = BY.len const in let bi = BF.alloca 0ul 1ul in let bres = BF.alloca true 1ul in let h1 = HST.get () in [@inline_let] let inv (h: HS.mem) (stop: bool) : GTot Type0 = B.modifies (B.loc_union (B.loc_buffer bi) (B.loc_buffer bres)) h1 h /\ ( let length = U32.v len in let i32 = (Seq.index (B.as_seq h bi) 0) in let i = U32.v i32 in let res = Seq.index (B.as_seq h bres) 0 in i <= length /\ (stop == false ==> res == true) /\ ((stop == true /\ res == true) ==> i == length) /\ (res == true <==> Seq.slice (B.as_seq h b) (U32.v pos) (U32.v pos + i) `Seq.equal` Seq.slice (BY.reveal const) 0 i) ) in C.Loops.do_while inv (fun _ -> let i = B.index bi 0ul in if i = len then true else begin let i' = i `U32.add` 1ul in [@inline_let] let _ = let s1 = (Seq.slice (B.as_seq h0 b) (U32.v pos) (U32.v pos + U32.v i)) in let c1 = (B.get h0 b (U32.v pos + U32.v i)) in let s2 = (Seq.slice (BY.reveal const) 0 (U32.v i)) in let c2 = (BY.index const (U32.v i)) in assert (Seq.slice (B.as_seq h0 b) (U32.v pos) (U32.v pos + U32.v i') `Seq.equal` Seq.snoc s1 c1); assert (Seq.slice (BY.reveal const) 0 (U32.v i') `Seq.equal` Seq.snoc s2 c2); Classical.move_requires (Seq.lemma_snoc_inj s1 s2 c1) c2 in let res = B.index b (pos `U32.add` i) = BY.get const i in B.upd bres 0ul res; B.upd bi 0ul i'; not res end ); let res = B.index bres 0ul in HST.pop_frame (); res #pop-options inline_for_extraction let valid_slice_equals_bytes (const: BY.bytes) (#rrel #rel: _) (input: slice rrel rel) (pos: U32.t) : HST.Stack bool (requires (fun h -> valid (parse_flbytes (BY.length const)) h input pos )) (ensures (fun h res h' -> B.modifies B.loc_none h h' /\ (res == true <==> contents (parse_flbytes (BY.length const)) h input pos == const ))) = let h = HST.get () in [@inline_let] let _ = valid_facts (parse_flbytes (BY.length const)) h input pos in buffer_equals_bytes const input.base pos inline_for_extraction let validate_all_bytes () : Tot (validator parse_all_bytes) = fun #rrel #rel input pos -> let h = HST.get () in [@inline_let] let _ = valid_facts parse_all_bytes h input (uint64_to_uint32 pos) in Cast.uint32_to_uint64 input.len inline_for_extraction let validate_bounded_vlbytes' (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (l: nat { l >= log256' max /\ l <= 4 } ) : Tot (validator (parse_bounded_vlbytes' min max l)) = validate_synth (validate_bounded_vldata_strong' min max l serialize_all_bytes (validate_all_bytes ())) (synth_bounded_vlbytes min max) () inline_for_extraction let validate_bounded_vlbytes (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) : Tot (validator (parse_bounded_vlbytes min max)) = validate_bounded_vlbytes' min max (log256' max) inline_for_extraction let jump_all_bytes () : Tot (jumper parse_all_bytes) = fun #rrel #rel input pos -> let h = HST.get () in [@inline_let] let _ = valid_facts parse_all_bytes h input pos in input.len inline_for_extraction let jump_bounded_vlbytes' (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (l: nat { l >= log256' max /\ l <= 4 } ) : Tot (jumper (parse_bounded_vlbytes' min max l)) = jump_synth (jump_bounded_vldata_strong' min max l serialize_all_bytes) (synth_bounded_vlbytes min max) () inline_for_extraction let jump_bounded_vlbytes (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) : Tot (jumper (parse_bounded_vlbytes min max)) = jump_bounded_vlbytes' min max (log256' max) let valid_exact_all_bytes_elim (h: HS.mem) (#rrel #rel: _) (input: slice rrel rel) (pos pos' : U32.t) : Lemma (requires (valid_exact parse_all_bytes h input pos pos')) (ensures ( let x = contents_exact parse_all_bytes h input pos pos' in let length = U32.v pos' - U32.v pos in BY.length x == length /\ valid_content_pos (parse_flbytes length) h input pos x pos' )) = valid_exact_equiv parse_all_bytes h input pos pos' ; contents_exact_eq parse_all_bytes h input pos pos' ; let length = U32.v pos' - U32.v pos in valid_facts (parse_flbytes length) h input pos ; assert (no_lookahead_on (parse_flbytes length) (bytes_of_slice_from_to h input pos pos') (bytes_of_slice_from h input pos)); assert (injective_postcond (parse_flbytes length) (bytes_of_slice_from_to h input pos pos') (bytes_of_slice_from h input pos)) #push-options "--z3rlimit 32" let valid_bounded_vlbytes'_elim (h: HS.mem) (min: nat) (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (l: nat { l >= log256' max /\ l <= 4 } ) (#rrel #rel: _) (input: slice rrel rel) (pos: U32.t) : Lemma (requires ( valid (parse_bounded_vlbytes' min max l) h input pos )) (ensures ( let sz = l in valid (parse_bounded_integer sz) h input pos /\ ( let len_payload = contents (parse_bounded_integer sz) h input pos in min <= U32.v len_payload /\ U32.v len_payload <= max /\ sz + U32.v len_payload == content_length (parse_bounded_vlbytes' min max l) h input pos /\ ( let pos_payload = pos `U32.add` U32.uint_to_t sz in let x = contents (parse_bounded_vlbytes' min max l) h input pos in BY.len x == len_payload /\ valid_pos (parse_bounded_vlbytes' min max l) h input pos (pos_payload `U32.add` len_payload) /\ valid_content_pos (parse_flbytes (U32.v len_payload)) h input pos_payload x (pos_payload `U32.add` len_payload) )))) = valid_synth h (parse_bounded_vlbytes_aux min max l) (synth_bounded_vlbytes min max) input pos; valid_bounded_vldata_strong'_elim h min max l serialize_all_bytes input pos; let sz = l in let len_payload = contents (parse_bounded_integer sz) h input pos in let pos_payload = pos `U32.add` U32.uint_to_t sz in valid_exact_all_bytes_elim h input pos_payload (pos_payload `U32.add` len_payload); () #pop-options let valid_bounded_vlbytes_elim (h: HS.mem) (min: nat) (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (#rrel #rel: _) (input: slice rrel rel) (pos: U32.t) : Lemma (requires ( valid (parse_bounded_vlbytes min max) h input pos )) (ensures ( let sz = log256' max in valid (parse_bounded_integer sz) h input pos /\ ( let len_payload = contents (parse_bounded_integer sz) h input pos in min <= U32.v len_payload /\ U32.v len_payload <= max /\ sz + U32.v len_payload == content_length (parse_bounded_vlbytes min max) h input pos /\ ( let pos_payload = pos `U32.add` U32.uint_to_t sz in let x = contents (parse_bounded_vlbytes min max) h input pos in BY.len x == len_payload /\ valid_pos (parse_bounded_vlbytes min max) h input pos (pos_payload `U32.add` len_payload) /\ valid_content_pos (parse_flbytes (U32.v len_payload)) h input pos_payload x (pos_payload `U32.add` len_payload) )))) = valid_bounded_vlbytes'_elim h min max (log256' max) input pos let valid_bounded_vlbytes_elim_length (h: HS.mem) (min: nat) (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (#rrel #rel: _) (input: slice rrel rel) (pos: U32.t) : Lemma (requires ( valid (parse_bounded_vlbytes min max) h input pos )) (ensures ( content_length (parse_bounded_vlbytes min max) h input pos == log256' max + BY.length (contents (parse_bounded_vlbytes min max) h input pos) )) [SMTPat (valid (parse_bounded_vlbytes min max) h input pos)] = valid_bounded_vlbytes_elim h min max input pos inline_for_extraction let bounded_vlbytes'_payload_length (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (l: nat { l >= log256' max /\ l <= 4 } ) (#rrel #rel: _) (input: slice rrel rel) (pos: U32.t) : HST.Stack U32.t (requires (fun h -> valid (parse_bounded_vlbytes' min max l) h input pos)) (ensures (fun h len h' -> B.modifies B.loc_none h h' /\ U32.v pos + l + U32.v len <= U32.v input.len /\ ( let x = contents (parse_bounded_vlbytes' min max l) h input pos in let pos' = get_valid_pos (parse_bounded_vlbytes' min max l) h input pos in BY.len x == len /\ valid_content_pos (parse_flbytes (U32.v len)) h input (pos `U32.add` U32.uint_to_t l) x pos' /\ bytes_of_slice_from_to h input (pos `U32.add` U32.uint_to_t l) pos' == BY.reveal x ))) = let h = HST.get () in [@inline_let] let _ = valid_bounded_vlbytes'_elim h min max l input pos in let len = read_bounded_integer l input pos in [@inline_let] let _ = valid_flbytes_elim h (U32.v len) input (pos `U32.add` U32.uint_to_t l) in len inline_for_extraction let bounded_vlbytes_payload_length (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (#rrel #rel: _) (input: slice rrel rel) (pos: U32.t) : HST.Stack U32.t (requires (fun h -> valid (parse_bounded_vlbytes min max) h input pos)) (ensures (fun h len h' -> B.modifies B.loc_none h h' /\ U32.v pos + log256' max + U32.v len <= U32.v input.len /\ ( let x = contents (parse_bounded_vlbytes min max) h input pos in let pos' = get_valid_pos (parse_bounded_vlbytes min max) h input pos in BY.len x == len /\ valid_content_pos (parse_flbytes (U32.v len)) h input (pos `U32.add` U32.uint_to_t (log256' max)) x pos' /\ bytes_of_slice_from_to h input (pos `U32.add` U32.uint_to_t (log256' max)) pos' == BY.reveal x ))) = bounded_vlbytes'_payload_length min max (log256' max) input pos (* Get the content buffer (with trivial buffers only, not generalizable to monotonicity) *) #push-options "--z3rlimit 32" inline_for_extraction let get_vlbytes'_contents (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (l: nat { l >= log256' max /\ l <= 4 } ) (input: slice (srel_of_buffer_srel (BF.trivial_preorder _)) (srel_of_buffer_srel (BF.trivial_preorder _))) (pos: U32.t) : HST.Stack (BF.buffer byte) (requires (fun h -> valid (parse_bounded_vlbytes' min max l) h input pos)) (ensures (fun h b h' -> let x = contents (parse_bounded_vlbytes' min max l) h input pos in B.modifies B.loc_none h h' /\ U32.v pos + l + BY.length x <= U32.v input.len /\ b == BF.gsub input.base (pos `U32.add` U32.uint_to_t l) (BY.len x) /\ B.as_seq h b == BY.reveal x )) = let h = HST.get () in [@inline_let] let _ = valid_bounded_vlbytes'_elim h min max l input pos in let len = read_bounded_integer l input pos in [@inline_let] let _ = valid_facts (parse_flbytes (U32.v len)) h input (pos `U32.add` U32.uint_to_t l) in BF.sub input.base (pos `U32.add` U32.uint_to_t l) len #pop-options inline_for_extraction let get_vlbytes_contents (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (input: slice (srel_of_buffer_srel (BF.trivial_preorder _)) (srel_of_buffer_srel (BF.trivial_preorder _))) (pos: U32.t) : HST.Stack (BF.buffer byte) (requires (fun h -> valid (parse_bounded_vlbytes min max) h input pos)) (ensures (fun h b h' -> let l = log256' max in let x = contents (parse_bounded_vlbytes min max) h input pos in B.modifies B.loc_none h h' /\ U32.v pos + l + BY.length x <= U32.v input.len /\ b == BF.gsub input.base (pos `U32.add` U32.uint_to_t l) (BY.len x) /\ B.as_seq h b == BY.reveal x )) = get_vlbytes'_contents min max (log256' max) input pos (* In fact, the following accessors are not useful in practice, because users would need to have the flbytes parser combinator in their scope *) let clens_vlbytes_cond (min: nat) (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (length: nat) (x: parse_bounded_vlbytes_t min max) : GTot Type0 = BY.length x == length let clens_vlbytes (min: nat) (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (length: nat) : Tot (clens (parse_bounded_vlbytes_t min max) (BY.lbytes length)) = { clens_cond = (clens_vlbytes_cond min max length); clens_get = (fun (x: parse_bounded_vlbytes_t min max) -> (x <: Ghost (BY.lbytes length) (requires (clens_vlbytes_cond min max length x)) (ensures (fun _ -> True)))); } #push-options "--z3rlimit 16 --max_fuel 2 --initial_fuel 2 --max_ifuel 6 --initial_ifuel 6" let gaccessor_vlbytes'_aux (min: nat) (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (l: nat { l >= log256' max /\ l <= 4 } ) (length: nat { length < 4294967296 } ) : Tot (gaccessor' (parse_bounded_vlbytes' min max l) (parse_flbytes length) (clens_vlbytes min max length)) = fun (input: bytes) -> (begin let res = if Seq.length input >= l then (l) else (0) in let g () : Lemma (requires (gaccessor_pre (parse_bounded_vlbytes' min max l) (parse_flbytes length) (clens_vlbytes min max length) input)) (ensures (gaccessor_post (parse_bounded_vlbytes' min max l) (parse_flbytes length) (clens_vlbytes min max length) input res)) = parse_bounded_vlbytes_eq min max l input; parse_strong_prefix (parse_flbytes length) (Seq.slice input l (l + length)) (Seq.slice input l (Seq.length input)) in Classical.move_requires g (); res end)
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowStar.Monotonic.Buffer.fsti.checked", "LowStar.Buffer.fst.checked", "LowParse.Spec.Bytes.fst.checked", "LowParse.Low.VLGen.fst.checked", "LowParse.Low.VLData.fst.checked", "LowParse.Low.Int.fsti.checked", "LowParse.Low.Combinators.fsti.checked", "LowParse.Bytes32.fst.checked", "FStar.UInt8.fsti.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Int.Cast.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked", "FStar.Classical.fsti.checked", "C.Loops.fst.checked" ], "interface_file": false, "source_file": "LowParse.Low.Bytes.fst" }
[ { "abbrev": true, "full_module": "LowStar.Buffer // for local variables in store_bytes", "short_module": "BF" }, { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "FStar.Int.Cast", "short_module": "Cast" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "LowParse.Bytes32", "short_module": "BY" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "BF" }, { "abbrev": true, "full_module": "LowStar.Monotonic.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": false, "full_module": "LowParse.Low.Int", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low.VLGen", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low.VLData", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low.Combinators", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec.Bytes", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 6, "max_fuel": 2, "max_ifuel": 6, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 16, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
min: Prims.nat -> max: Prims.nat{min <= max /\ max > 0 /\ max < 4294967296} -> l: Prims.nat{l >= LowParse.Spec.BoundedInt.log256' max /\ l <= 4} -> length: Prims.nat{length < 4294967296} -> LowParse.Low.Base.Spec.gaccessor (LowParse.Spec.Bytes.parse_bounded_vlbytes' min max l) (LowParse.Spec.Bytes.parse_flbytes length) (LowParse.Low.Bytes.clens_vlbytes min max length)
Prims.Tot
[ "total" ]
[]
[ "Prims.nat", "Prims.l_and", "Prims.b2t", "Prims.op_LessThanOrEqual", "Prims.op_GreaterThan", "Prims.op_LessThan", "Prims.op_GreaterThanOrEqual", "LowParse.Spec.BoundedInt.log256'", "LowParse.Low.Bytes.gaccessor_vlbytes'_aux", "Prims.unit", "LowParse.Low.Base.Spec.gaccessor_prop_equiv", "LowParse.Spec.VLData.parse_bounded_vldata_strong_kind", "LowParse.Spec.Bytes.parse_all_bytes_kind", "LowParse.Spec.Bytes.parse_bounded_vlbytes_t", "LowParse.Spec.Bytes.parse_bounded_vlbytes'", "LowParse.Spec.Base.total_constant_size_parser_kind", "FStar.Bytes.lbytes", "LowParse.Spec.Bytes.parse_flbytes", "LowParse.Low.Bytes.clens_vlbytes", "Prims._assert", "Prims.l_Forall", "FStar.Seq.Base.seq", "LowParse.Bytes.byte", "Prims.l_imp", "LowParse.Low.Base.Spec.gaccessor_pre", "FStar.Seq.Base.length", "LowParse.Spec.Base.parser_kind_prop_equiv", "LowParse.Low.Base.Spec.gaccessor" ]
[]
false
false
false
false
false
let gaccessor_vlbytes' (min: nat) (max: nat{min <= max /\ max > 0 /\ max < 4294967296}) (l: nat{l >= log256' max /\ l <= 4}) (length: nat{length < 4294967296}) : Tot (gaccessor (parse_bounded_vlbytes' min max l) (parse_flbytes length) (clens_vlbytes min max length)) =
parser_kind_prop_equiv (parse_bounded_vldata_strong_kind min max l parse_all_bytes_kind) (parse_bounded_vlbytes' min max l); assert (forall x. gaccessor_pre (parse_bounded_vlbytes' min max l) (parse_flbytes length) (clens_vlbytes min max length) x ==> Seq.length x >= l); gaccessor_prop_equiv (parse_bounded_vlbytes' min max l) (parse_flbytes length) (clens_vlbytes min max length) (gaccessor_vlbytes'_aux min max l length); gaccessor_vlbytes'_aux min max l length
false
LowParse.Low.Bytes.fst
LowParse.Low.Bytes.accessor_vlbytes
val accessor_vlbytes (min: nat) (max: nat{min <= max /\ max > 0 /\ max < 4294967296}) (length: U32.t) : Tot (accessor (gaccessor_vlbytes min max (U32.v length)))
val accessor_vlbytes (min: nat) (max: nat{min <= max /\ max > 0 /\ max < 4294967296}) (length: U32.t) : Tot (accessor (gaccessor_vlbytes min max (U32.v length)))
let accessor_vlbytes (min: nat) (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (length: U32.t) : Tot (accessor (gaccessor_vlbytes min max (U32.v length))) = accessor_vlbytes' min max (log256' max) length
{ "file_name": "src/lowparse/LowParse.Low.Bytes.fst", "git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
{ "end_col": 48, "end_line": 681, "start_col": 0, "start_line": 676 }
module LowParse.Low.Bytes include LowParse.Spec.Bytes include LowParse.Low.Combinators include LowParse.Low.VLData include LowParse.Low.VLGen include LowParse.Low.Int module U32 = FStar.UInt32 module HS = FStar.HyperStack module B = LowStar.Monotonic.Buffer module BF = LowStar.Buffer // for local variables in store_bytes module BY = LowParse.Bytes32 module HST = FStar.HyperStack.ST module U8 = FStar.UInt8 module Cast = FStar.Int.Cast module U64 = FStar.UInt64 inline_for_extraction let validate_flbytes (sz: nat) (sz64: U64.t { U64.v sz64 == sz /\ sz < 4294967296 } ) : Tot (validator (parse_flbytes sz)) = validate_total_constant_size (parse_flbytes sz) sz64 () inline_for_extraction let jump_flbytes (sz: nat) (sz32: U32.t { U32.v sz32 == sz } ) : Tot (jumper (parse_flbytes sz)) = jump_constant_size (parse_flbytes sz) sz32 () let valid_flbytes_intro (h: HS.mem) (sz: nat { sz < 4294967296 } ) (#rrel #rel: _) (s: slice rrel rel) (pos: U32.t) : Lemma (requires (U32.v pos + sz <= U32.v s.len /\ live_slice h s)) (ensures ( valid_content_pos (parse_flbytes sz) h s pos (BY.hide (bytes_of_slice_from_to h s pos (pos `U32.add` U32.uint_to_t sz))) (pos `U32.add` U32.uint_to_t sz) )) = valid_facts (parse_flbytes sz) h s pos let valid_pos_flbytes_elim (h: HS.mem) (sz: nat { sz < 4294967296 } ) (#rrel #rel: _) (s: slice rrel rel) (pos pos' : U32.t) : Lemma (requires (valid_pos (parse_flbytes sz) h s pos pos')) (ensures (U32.v pos + sz == U32.v pos')) [SMTPat (valid_pos (parse_flbytes sz) h s pos pos')] = valid_facts (parse_flbytes sz) h s pos let valid_flbytes_elim (h: HS.mem) (sz: nat { sz < 4294967296 } ) (#rrel #rel: _) (s: slice rrel rel) (pos: U32.t) : Lemma (requires (valid (parse_flbytes sz) h s pos)) (ensures ( valid_content_pos (parse_flbytes sz) h s pos (BY.hide (bytes_of_slice_from_to h s pos (pos `U32.add` U32.uint_to_t sz))) (pos `U32.add` U32.uint_to_t sz) )) = valid_flbytes_intro h sz s pos let clens_flbytes_slice (sz: nat) (from: U32.t) (to: U32.t {U32.v from <= U32.v to /\ U32.v to <= sz } ) : Tot (clens (BY.lbytes sz) (BY.lbytes (U32.v to - U32.v from))) = { clens_cond = (fun _ -> True); clens_get = (fun (x: BY.lbytes sz) -> (BY.slice x from to <: BY.lbytes (U32.v to - U32.v from))); } #push-options "--z3rlimit 16" let gaccessor_flbytes_slice' (sz: nat { sz < 4294967296 } ) (from: U32.t) (to: U32.t {U32.v from <= U32.v to /\ U32.v to <= sz } ) : Tot (gaccessor' (parse_flbytes sz) (parse_flbytes (U32.v to - U32.v from)) (clens_flbytes_slice sz from to)) = fun (input: bytes) -> ( begin if Seq.length input < sz then (0) // dummy else (U32.v from) end) let gaccessor_flbytes_slice (sz: nat { sz < 4294967296 } ) (from: U32.t) (to: U32.t {U32.v from <= U32.v to /\ U32.v to <= sz } ) : Tot (gaccessor (parse_flbytes sz) (parse_flbytes (U32.v to - U32.v from)) (clens_flbytes_slice sz from to)) = assert (forall x . gaccessor_pre (parse_flbytes sz) (parse_flbytes (U32.v to - U32.v from)) (clens_flbytes_slice sz from to) x ==> sz <= Seq.length x); gaccessor_prop_equiv (parse_flbytes sz) (parse_flbytes (U32.v to - U32.v from)) (clens_flbytes_slice sz from to) (gaccessor_flbytes_slice' sz from to); gaccessor_flbytes_slice' sz from to inline_for_extraction let accessor_flbytes_slice (sz: nat { sz < 4294967296 } ) (from: U32.t) (to: U32.t {U32.v from <= U32.v to /\ U32.v to <= sz } ) : Tot (accessor (gaccessor_flbytes_slice sz from to)) = fun #rrel #rel input pos -> let h = HST.get () in [@inline_let] let _ = slice_access_eq h (gaccessor_flbytes_slice sz from to) input pos in pos `U32.add` from #pop-options let clens_flbytes_get (sz: nat) (i: U32.t { U32.v i < sz } ) : Tot (clens (BY.lbytes sz) byte) = { clens_cond = (fun _ -> True); clens_get = (fun (x: BY.lbytes sz) -> (BY.get x i <: byte)); } #push-options "--z3rlimit 16 --max_fuel 1" let gaccessor_flbytes_get' (sz: nat { sz < 4294967296 } ) (i: U32.t { U32.v i < sz } ) : Tot (gaccessor' (parse_flbytes sz) (parse_u8) (clens_flbytes_get sz i)) = fun (input: bytes) -> ( begin let res = if Seq.length input < U32.v i then (0) // dummy else (U32.v i) in let g () : Lemma (requires (gaccessor_pre (parse_flbytes sz) parse_u8 (clens_flbytes_get sz i) input)) (ensures (gaccessor_post (parse_flbytes sz) parse_u8 (clens_flbytes_get sz i) input res)) = parser_kind_prop_equiv (get_parser_kind parse_u8) parse_u8; assert (res == (U32.v i)); parse_u8_spec' (Seq.slice input (U32.v i) (U32.v i + 1)); parse_strong_prefix parse_u8 (Seq.slice input (U32.v i) (U32.v i + 1)) (Seq.slice input (U32.v i) (Seq.length input)) in Classical.move_requires g (); res end) #pop-options let gaccessor_flbytes_get (sz: nat { sz < 4294967296 } ) (i: U32.t { U32.v i < sz } ) : Tot (gaccessor (parse_flbytes sz) (parse_u8) (clens_flbytes_get sz i)) = assert (forall x . gaccessor_pre (parse_flbytes sz) (parse_u8) (clens_flbytes_get sz i) x ==> U32.v i <= Seq.length x); gaccessor_prop_equiv (parse_flbytes sz) (parse_u8) (clens_flbytes_get sz i) (gaccessor_flbytes_get' sz i); gaccessor_flbytes_get' sz i inline_for_extraction let accessor_flbytes_get (sz: nat { sz < 4294967296 } ) (i: U32.t { U32.v i < sz } ) : Tot (accessor (gaccessor_flbytes_get sz i)) = fun #rrel #rel input pos -> let h = HST.get () in [@inline_let] let _ = slice_access_eq h (gaccessor_flbytes_get sz i) input pos in pos `U32.add` i (* Temporary: flbytes as leaf values *) (* TODO: convert store_bytes to monotonic buffers, using the "writable" predicate *) #push-options "--z3rlimit 32" inline_for_extraction let store_bytes (src: BY.bytes) (src_from src_to: U32.t) (#rrel #rel: _) (dst: B.mbuffer byte rrel rel) (dst_pos: U32.t) : HST.Stack unit (requires (fun h -> B.live h dst /\ U32.v src_from <= U32.v src_to /\ U32.v src_to <= BY.length src /\ U32.v dst_pos + (U32.v src_to - U32.v src_from) <= B.length dst /\ writable dst (U32.v dst_pos) (U32.v dst_pos + (U32.v src_to - U32.v src_from)) h )) (ensures (fun h _ h' -> B.modifies (B.loc_buffer_from_to dst dst_pos (dst_pos `U32.add` (src_to `U32.sub` src_from))) h h' /\ Seq.slice (B.as_seq h' dst) (U32.v dst_pos) (U32.v dst_pos + (U32.v src_to - U32.v src_from)) == Seq.slice (BY.reveal src) (U32.v src_from) (U32.v src_to) )) = let h0 = HST.get () in HST.push_frame (); let h1 = HST.get () in let bi = BF.alloca 0ul 1ul in let h2 = HST.get () in let len = src_to `U32.sub` src_from in C.Loops.do_while (fun h stop -> B.modifies (B.loc_union (B.loc_region_only true (HS.get_tip h1)) (B.loc_buffer_from_to dst dst_pos (dst_pos `U32.add` len))) h2 h /\ B.live h bi /\ ( let i = Seq.index (B.as_seq h bi) 0 in U32.v i <= U32.v len /\ writable dst (U32.v dst_pos) (U32.v dst_pos + U32.v len) h /\ Seq.slice (B.as_seq h dst) (U32.v dst_pos) (U32.v dst_pos + U32.v i) `Seq.equal` Seq.slice (BY.reveal src) (U32.v src_from) (U32.v src_from + U32.v i) /\ (stop == true ==> i == len) )) (fun _ -> let i = B.index bi 0ul in if i = len then true else begin let x = BY.get src (src_from `U32.add` i) in mbuffer_upd dst (Ghost.hide (U32.v dst_pos)) (Ghost.hide (U32.v dst_pos + U32.v len)) (dst_pos `U32.add` i) x; let i' = i `U32.add` 1ul in B.upd bi 0ul i'; let h' = HST.get () in Seq.lemma_split (Seq.slice (B.as_seq h' dst) (U32.v dst_pos) (U32.v dst_pos + U32.v i')) (U32.v i); i' = len end ) ; HST.pop_frame () #pop-options inline_for_extraction let serialize32_flbytes (sz32: U32.t) : Tot (serializer32 (serialize_flbytes (U32.v sz32))) = fun (x: BY.lbytes (U32.v sz32)) #rrel #rel b pos -> let _ = store_bytes x 0ul sz32 b pos in sz32 inline_for_extraction let write_flbytes (sz32: U32.t) : Tot (leaf_writer_strong (serialize_flbytes (U32.v sz32))) = leaf_writer_strong_of_serializer32 (serialize32_flbytes sz32) () inline_for_extraction let write_flbytes_weak (sz32: U32.t { U32.v sz32 < 4294967295 } ) // need to return that value if output buffer is too small : Tot (leaf_writer_weak (serialize_flbytes (U32.v sz32))) = leaf_writer_weak_of_strong_constant_size (write_flbytes sz32) sz32 () (* // TODO: remove, since nobody is using this inline_for_extraction let read_flbytes (sz32: U32.t) : Tot (leaf_reader (parse_flbytes (U32.v sz32))) = fun input pos -> let h = HST.get () in [@inline_let] let _ = valid_facts (parse_flbytes (U32.v sz32)) h input pos in BY.of_buffer sz32 (B.sub input.base pos sz32) *) (* Equality test between a vlbytes and a constant lbytes *) #push-options "--z3rlimit 32" inline_for_extraction let buffer_equals_bytes (const: BY.bytes) (#rrel #rel: _) (b: B.mbuffer byte rrel rel) (pos: U32.t) : HST.Stack bool (requires (fun h -> B.live h b /\ U32.v pos + BY.length const <= B.length b )) (ensures (fun h res h' -> B.modifies B.loc_none h h' /\ (res == true <==> Seq.slice (B.as_seq h b) (U32.v pos) (U32.v pos + BY.length const) == BY.reveal const) )) = let h0 = HST.get () in HST.push_frame (); let len = BY.len const in let bi = BF.alloca 0ul 1ul in let bres = BF.alloca true 1ul in let h1 = HST.get () in [@inline_let] let inv (h: HS.mem) (stop: bool) : GTot Type0 = B.modifies (B.loc_union (B.loc_buffer bi) (B.loc_buffer bres)) h1 h /\ ( let length = U32.v len in let i32 = (Seq.index (B.as_seq h bi) 0) in let i = U32.v i32 in let res = Seq.index (B.as_seq h bres) 0 in i <= length /\ (stop == false ==> res == true) /\ ((stop == true /\ res == true) ==> i == length) /\ (res == true <==> Seq.slice (B.as_seq h b) (U32.v pos) (U32.v pos + i) `Seq.equal` Seq.slice (BY.reveal const) 0 i) ) in C.Loops.do_while inv (fun _ -> let i = B.index bi 0ul in if i = len then true else begin let i' = i `U32.add` 1ul in [@inline_let] let _ = let s1 = (Seq.slice (B.as_seq h0 b) (U32.v pos) (U32.v pos + U32.v i)) in let c1 = (B.get h0 b (U32.v pos + U32.v i)) in let s2 = (Seq.slice (BY.reveal const) 0 (U32.v i)) in let c2 = (BY.index const (U32.v i)) in assert (Seq.slice (B.as_seq h0 b) (U32.v pos) (U32.v pos + U32.v i') `Seq.equal` Seq.snoc s1 c1); assert (Seq.slice (BY.reveal const) 0 (U32.v i') `Seq.equal` Seq.snoc s2 c2); Classical.move_requires (Seq.lemma_snoc_inj s1 s2 c1) c2 in let res = B.index b (pos `U32.add` i) = BY.get const i in B.upd bres 0ul res; B.upd bi 0ul i'; not res end ); let res = B.index bres 0ul in HST.pop_frame (); res #pop-options inline_for_extraction let valid_slice_equals_bytes (const: BY.bytes) (#rrel #rel: _) (input: slice rrel rel) (pos: U32.t) : HST.Stack bool (requires (fun h -> valid (parse_flbytes (BY.length const)) h input pos )) (ensures (fun h res h' -> B.modifies B.loc_none h h' /\ (res == true <==> contents (parse_flbytes (BY.length const)) h input pos == const ))) = let h = HST.get () in [@inline_let] let _ = valid_facts (parse_flbytes (BY.length const)) h input pos in buffer_equals_bytes const input.base pos inline_for_extraction let validate_all_bytes () : Tot (validator parse_all_bytes) = fun #rrel #rel input pos -> let h = HST.get () in [@inline_let] let _ = valid_facts parse_all_bytes h input (uint64_to_uint32 pos) in Cast.uint32_to_uint64 input.len inline_for_extraction let validate_bounded_vlbytes' (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (l: nat { l >= log256' max /\ l <= 4 } ) : Tot (validator (parse_bounded_vlbytes' min max l)) = validate_synth (validate_bounded_vldata_strong' min max l serialize_all_bytes (validate_all_bytes ())) (synth_bounded_vlbytes min max) () inline_for_extraction let validate_bounded_vlbytes (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) : Tot (validator (parse_bounded_vlbytes min max)) = validate_bounded_vlbytes' min max (log256' max) inline_for_extraction let jump_all_bytes () : Tot (jumper parse_all_bytes) = fun #rrel #rel input pos -> let h = HST.get () in [@inline_let] let _ = valid_facts parse_all_bytes h input pos in input.len inline_for_extraction let jump_bounded_vlbytes' (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (l: nat { l >= log256' max /\ l <= 4 } ) : Tot (jumper (parse_bounded_vlbytes' min max l)) = jump_synth (jump_bounded_vldata_strong' min max l serialize_all_bytes) (synth_bounded_vlbytes min max) () inline_for_extraction let jump_bounded_vlbytes (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) : Tot (jumper (parse_bounded_vlbytes min max)) = jump_bounded_vlbytes' min max (log256' max) let valid_exact_all_bytes_elim (h: HS.mem) (#rrel #rel: _) (input: slice rrel rel) (pos pos' : U32.t) : Lemma (requires (valid_exact parse_all_bytes h input pos pos')) (ensures ( let x = contents_exact parse_all_bytes h input pos pos' in let length = U32.v pos' - U32.v pos in BY.length x == length /\ valid_content_pos (parse_flbytes length) h input pos x pos' )) = valid_exact_equiv parse_all_bytes h input pos pos' ; contents_exact_eq parse_all_bytes h input pos pos' ; let length = U32.v pos' - U32.v pos in valid_facts (parse_flbytes length) h input pos ; assert (no_lookahead_on (parse_flbytes length) (bytes_of_slice_from_to h input pos pos') (bytes_of_slice_from h input pos)); assert (injective_postcond (parse_flbytes length) (bytes_of_slice_from_to h input pos pos') (bytes_of_slice_from h input pos)) #push-options "--z3rlimit 32" let valid_bounded_vlbytes'_elim (h: HS.mem) (min: nat) (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (l: nat { l >= log256' max /\ l <= 4 } ) (#rrel #rel: _) (input: slice rrel rel) (pos: U32.t) : Lemma (requires ( valid (parse_bounded_vlbytes' min max l) h input pos )) (ensures ( let sz = l in valid (parse_bounded_integer sz) h input pos /\ ( let len_payload = contents (parse_bounded_integer sz) h input pos in min <= U32.v len_payload /\ U32.v len_payload <= max /\ sz + U32.v len_payload == content_length (parse_bounded_vlbytes' min max l) h input pos /\ ( let pos_payload = pos `U32.add` U32.uint_to_t sz in let x = contents (parse_bounded_vlbytes' min max l) h input pos in BY.len x == len_payload /\ valid_pos (parse_bounded_vlbytes' min max l) h input pos (pos_payload `U32.add` len_payload) /\ valid_content_pos (parse_flbytes (U32.v len_payload)) h input pos_payload x (pos_payload `U32.add` len_payload) )))) = valid_synth h (parse_bounded_vlbytes_aux min max l) (synth_bounded_vlbytes min max) input pos; valid_bounded_vldata_strong'_elim h min max l serialize_all_bytes input pos; let sz = l in let len_payload = contents (parse_bounded_integer sz) h input pos in let pos_payload = pos `U32.add` U32.uint_to_t sz in valid_exact_all_bytes_elim h input pos_payload (pos_payload `U32.add` len_payload); () #pop-options let valid_bounded_vlbytes_elim (h: HS.mem) (min: nat) (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (#rrel #rel: _) (input: slice rrel rel) (pos: U32.t) : Lemma (requires ( valid (parse_bounded_vlbytes min max) h input pos )) (ensures ( let sz = log256' max in valid (parse_bounded_integer sz) h input pos /\ ( let len_payload = contents (parse_bounded_integer sz) h input pos in min <= U32.v len_payload /\ U32.v len_payload <= max /\ sz + U32.v len_payload == content_length (parse_bounded_vlbytes min max) h input pos /\ ( let pos_payload = pos `U32.add` U32.uint_to_t sz in let x = contents (parse_bounded_vlbytes min max) h input pos in BY.len x == len_payload /\ valid_pos (parse_bounded_vlbytes min max) h input pos (pos_payload `U32.add` len_payload) /\ valid_content_pos (parse_flbytes (U32.v len_payload)) h input pos_payload x (pos_payload `U32.add` len_payload) )))) = valid_bounded_vlbytes'_elim h min max (log256' max) input pos let valid_bounded_vlbytes_elim_length (h: HS.mem) (min: nat) (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (#rrel #rel: _) (input: slice rrel rel) (pos: U32.t) : Lemma (requires ( valid (parse_bounded_vlbytes min max) h input pos )) (ensures ( content_length (parse_bounded_vlbytes min max) h input pos == log256' max + BY.length (contents (parse_bounded_vlbytes min max) h input pos) )) [SMTPat (valid (parse_bounded_vlbytes min max) h input pos)] = valid_bounded_vlbytes_elim h min max input pos inline_for_extraction let bounded_vlbytes'_payload_length (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (l: nat { l >= log256' max /\ l <= 4 } ) (#rrel #rel: _) (input: slice rrel rel) (pos: U32.t) : HST.Stack U32.t (requires (fun h -> valid (parse_bounded_vlbytes' min max l) h input pos)) (ensures (fun h len h' -> B.modifies B.loc_none h h' /\ U32.v pos + l + U32.v len <= U32.v input.len /\ ( let x = contents (parse_bounded_vlbytes' min max l) h input pos in let pos' = get_valid_pos (parse_bounded_vlbytes' min max l) h input pos in BY.len x == len /\ valid_content_pos (parse_flbytes (U32.v len)) h input (pos `U32.add` U32.uint_to_t l) x pos' /\ bytes_of_slice_from_to h input (pos `U32.add` U32.uint_to_t l) pos' == BY.reveal x ))) = let h = HST.get () in [@inline_let] let _ = valid_bounded_vlbytes'_elim h min max l input pos in let len = read_bounded_integer l input pos in [@inline_let] let _ = valid_flbytes_elim h (U32.v len) input (pos `U32.add` U32.uint_to_t l) in len inline_for_extraction let bounded_vlbytes_payload_length (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (#rrel #rel: _) (input: slice rrel rel) (pos: U32.t) : HST.Stack U32.t (requires (fun h -> valid (parse_bounded_vlbytes min max) h input pos)) (ensures (fun h len h' -> B.modifies B.loc_none h h' /\ U32.v pos + log256' max + U32.v len <= U32.v input.len /\ ( let x = contents (parse_bounded_vlbytes min max) h input pos in let pos' = get_valid_pos (parse_bounded_vlbytes min max) h input pos in BY.len x == len /\ valid_content_pos (parse_flbytes (U32.v len)) h input (pos `U32.add` U32.uint_to_t (log256' max)) x pos' /\ bytes_of_slice_from_to h input (pos `U32.add` U32.uint_to_t (log256' max)) pos' == BY.reveal x ))) = bounded_vlbytes'_payload_length min max (log256' max) input pos (* Get the content buffer (with trivial buffers only, not generalizable to monotonicity) *) #push-options "--z3rlimit 32" inline_for_extraction let get_vlbytes'_contents (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (l: nat { l >= log256' max /\ l <= 4 } ) (input: slice (srel_of_buffer_srel (BF.trivial_preorder _)) (srel_of_buffer_srel (BF.trivial_preorder _))) (pos: U32.t) : HST.Stack (BF.buffer byte) (requires (fun h -> valid (parse_bounded_vlbytes' min max l) h input pos)) (ensures (fun h b h' -> let x = contents (parse_bounded_vlbytes' min max l) h input pos in B.modifies B.loc_none h h' /\ U32.v pos + l + BY.length x <= U32.v input.len /\ b == BF.gsub input.base (pos `U32.add` U32.uint_to_t l) (BY.len x) /\ B.as_seq h b == BY.reveal x )) = let h = HST.get () in [@inline_let] let _ = valid_bounded_vlbytes'_elim h min max l input pos in let len = read_bounded_integer l input pos in [@inline_let] let _ = valid_facts (parse_flbytes (U32.v len)) h input (pos `U32.add` U32.uint_to_t l) in BF.sub input.base (pos `U32.add` U32.uint_to_t l) len #pop-options inline_for_extraction let get_vlbytes_contents (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (input: slice (srel_of_buffer_srel (BF.trivial_preorder _)) (srel_of_buffer_srel (BF.trivial_preorder _))) (pos: U32.t) : HST.Stack (BF.buffer byte) (requires (fun h -> valid (parse_bounded_vlbytes min max) h input pos)) (ensures (fun h b h' -> let l = log256' max in let x = contents (parse_bounded_vlbytes min max) h input pos in B.modifies B.loc_none h h' /\ U32.v pos + l + BY.length x <= U32.v input.len /\ b == BF.gsub input.base (pos `U32.add` U32.uint_to_t l) (BY.len x) /\ B.as_seq h b == BY.reveal x )) = get_vlbytes'_contents min max (log256' max) input pos (* In fact, the following accessors are not useful in practice, because users would need to have the flbytes parser combinator in their scope *) let clens_vlbytes_cond (min: nat) (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (length: nat) (x: parse_bounded_vlbytes_t min max) : GTot Type0 = BY.length x == length let clens_vlbytes (min: nat) (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (length: nat) : Tot (clens (parse_bounded_vlbytes_t min max) (BY.lbytes length)) = { clens_cond = (clens_vlbytes_cond min max length); clens_get = (fun (x: parse_bounded_vlbytes_t min max) -> (x <: Ghost (BY.lbytes length) (requires (clens_vlbytes_cond min max length x)) (ensures (fun _ -> True)))); } #push-options "--z3rlimit 16 --max_fuel 2 --initial_fuel 2 --max_ifuel 6 --initial_ifuel 6" let gaccessor_vlbytes'_aux (min: nat) (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (l: nat { l >= log256' max /\ l <= 4 } ) (length: nat { length < 4294967296 } ) : Tot (gaccessor' (parse_bounded_vlbytes' min max l) (parse_flbytes length) (clens_vlbytes min max length)) = fun (input: bytes) -> (begin let res = if Seq.length input >= l then (l) else (0) in let g () : Lemma (requires (gaccessor_pre (parse_bounded_vlbytes' min max l) (parse_flbytes length) (clens_vlbytes min max length) input)) (ensures (gaccessor_post (parse_bounded_vlbytes' min max l) (parse_flbytes length) (clens_vlbytes min max length) input res)) = parse_bounded_vlbytes_eq min max l input; parse_strong_prefix (parse_flbytes length) (Seq.slice input l (l + length)) (Seq.slice input l (Seq.length input)) in Classical.move_requires g (); res end) let gaccessor_vlbytes' (min: nat) (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (l: nat { l >= log256' max /\ l <= 4 } ) (length: nat { length < 4294967296 } ) : Tot (gaccessor (parse_bounded_vlbytes' min max l) (parse_flbytes length) (clens_vlbytes min max length)) = parser_kind_prop_equiv (parse_bounded_vldata_strong_kind min max l parse_all_bytes_kind) (parse_bounded_vlbytes' min max l); assert (forall x . gaccessor_pre (parse_bounded_vlbytes' min max l) (parse_flbytes length) (clens_vlbytes min max length) x ==> Seq.length x >= l); gaccessor_prop_equiv (parse_bounded_vlbytes' min max l) (parse_flbytes length) (clens_vlbytes min max length) (gaccessor_vlbytes'_aux min max l length); gaccessor_vlbytes'_aux min max l length #pop-options let gaccessor_vlbytes (min: nat) (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (length: nat { length < 4294967296 } ) : Tot (gaccessor (parse_bounded_vlbytes min max) (parse_flbytes length) (clens_vlbytes min max length)) = gaccessor_vlbytes' min max (log256' max) length #push-options "--z3rlimit 64 --max_fuel 2 --initial_fuel 2 --max_ifuel 6 --initial_ifuel 6" inline_for_extraction let accessor_vlbytes' (min: nat) (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (l: nat { l >= log256' max /\ l <= 4 } ) (length: U32.t) : Tot (accessor (gaccessor_vlbytes' min max l (U32.v length))) = fun #rrel #rel sl pos -> let h = HST.get () in [@inline_let] let _ = slice_access_eq h (gaccessor_vlbytes' min max l (U32.v length)) sl pos; valid_bounded_vlbytes'_elim h min max l sl pos; parse_bounded_vlbytes_eq min max l (bytes_of_slice_from h sl pos) in pos `U32.add` U32.uint_to_t l #pop-options
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowStar.Monotonic.Buffer.fsti.checked", "LowStar.Buffer.fst.checked", "LowParse.Spec.Bytes.fst.checked", "LowParse.Low.VLGen.fst.checked", "LowParse.Low.VLData.fst.checked", "LowParse.Low.Int.fsti.checked", "LowParse.Low.Combinators.fsti.checked", "LowParse.Bytes32.fst.checked", "FStar.UInt8.fsti.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Int.Cast.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked", "FStar.Classical.fsti.checked", "C.Loops.fst.checked" ], "interface_file": false, "source_file": "LowParse.Low.Bytes.fst" }
[ { "abbrev": true, "full_module": "LowStar.Buffer // for local variables in store_bytes", "short_module": "BF" }, { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "FStar.Int.Cast", "short_module": "Cast" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "LowParse.Bytes32", "short_module": "BY" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "BF" }, { "abbrev": true, "full_module": "LowStar.Monotonic.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": false, "full_module": "LowParse.Low.Int", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low.VLGen", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low.VLData", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low.Combinators", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec.Bytes", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
min: Prims.nat -> max: Prims.nat{min <= max /\ max > 0 /\ max < 4294967296} -> length: FStar.UInt32.t -> LowParse.Low.Base.accessor (LowParse.Low.Bytes.gaccessor_vlbytes min max (FStar.UInt32.v length))
Prims.Tot
[ "total" ]
[]
[ "Prims.nat", "Prims.l_and", "Prims.b2t", "Prims.op_LessThanOrEqual", "Prims.op_GreaterThan", "Prims.op_LessThan", "FStar.UInt32.t", "LowParse.Low.Bytes.accessor_vlbytes'", "LowParse.Spec.BoundedInt.log256'", "LowParse.Low.Base.accessor", "LowParse.Spec.VLData.parse_bounded_vldata_strong_kind", "LowParse.Spec.Bytes.parse_all_bytes_kind", "LowParse.Spec.Bytes.parse_bounded_vlbytes_t", "LowParse.Spec.Bytes.parse_bounded_vlbytes", "LowParse.Spec.Base.total_constant_size_parser_kind", "FStar.UInt32.v", "FStar.Bytes.lbytes", "LowParse.Spec.Bytes.parse_flbytes", "LowParse.Low.Bytes.clens_vlbytes", "LowParse.Low.Bytes.gaccessor_vlbytes" ]
[]
false
false
false
false
false
let accessor_vlbytes (min: nat) (max: nat{min <= max /\ max > 0 /\ max < 4294967296}) (length: U32.t) : Tot (accessor (gaccessor_vlbytes min max (U32.v length))) =
accessor_vlbytes' min max (log256' max) length
false
Pulse.Syntax.Base.fsti
Pulse.Syntax.Base.host_term
val host_term : Type0
let host_term = t:R.term { not_tv_unknown t }
{ "file_name": "lib/steel/pulse/Pulse.Syntax.Base.fsti", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 45, "end_line": 86, "start_col": 0, "start_line": 86 }
(* Copyright 2023 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module Pulse.Syntax.Base module RTB = FStar.Reflection.Typing.Builtins module RT = FStar.Reflection.Typing module R = FStar.Reflection.V2 module RU = Pulse.RuntimeUtils module T = FStar.Tactics.V2 open FStar.List.Tot type constant = R.vconst let var = nat let index = nat type universe = R.universe (* locally nameless. *) let range_singleton_trigger (r:FStar.Range.range) = True let range = r:FStar.Range.range { range_singleton_trigger r } let range_singleton (r:FStar.Range.range) : Lemma (ensures r == FStar.Range.range_0) [SMTPat (range_singleton_trigger r)] = FStar.Sealed.sealed_singl r FStar.Range.range_0 noeq type ppname = { name : RT.pp_name_t; range : range } let ppname_default = { name = FStar.Sealed.seal "_"; range = FStar.Range.range_0 } let mk_ppname (name:RT.pp_name_t) (range:FStar.Range.range) : ppname = { name = name; range = range } let mk_ppname_no_range (s:string) : ppname = { name = FStar.Sealed.seal s; range = FStar.Range.range_0; } noeq type bv = { bv_index : index; bv_ppname : ppname; } noeq type nm = { nm_index : var; nm_ppname : ppname; } type qualifier = | Implicit noeq type fv = { fv_name : R.name; fv_range : range; } let as_fv l = { fv_name = l; fv_range = FStar.Range.range_0 }
{ "checked_file": "/", "dependencies": [ "Pulse.RuntimeUtils.fsti.checked", "Pulse.Reflection.Util.fst.checked", "prims.fst.checked", "FStar.Tactics.V2.fst.checked", "FStar.Sealed.Inhabited.fst.checked", "FStar.Sealed.fsti.checked", "FStar.Reflection.V2.fst.checked", "FStar.Reflection.Typing.Builtins.fsti.checked", "FStar.Reflection.Typing.fsti.checked", "FStar.Range.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked" ], "interface_file": false, "source_file": "Pulse.Syntax.Base.fsti" }
[ { "abbrev": false, "full_module": "FStar.List.Tot", "short_module": null }, { "abbrev": true, "full_module": "FStar.Tactics.V2", "short_module": "T" }, { "abbrev": true, "full_module": "Pulse.RuntimeUtils", "short_module": "RU" }, { "abbrev": true, "full_module": "FStar.Reflection.V2", "short_module": "R" }, { "abbrev": true, "full_module": "FStar.Reflection.Typing", "short_module": "RT" }, { "abbrev": true, "full_module": "FStar.Reflection.Typing.Builtins", "short_module": "RTB" }, { "abbrev": false, "full_module": "Pulse.Syntax", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Syntax", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": 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
Type0
Prims.Tot
[ "total" ]
[]
[ "FStar.Stubs.Reflection.Types.term", "Pulse.Syntax.Base.not_tv_unknown" ]
[]
false
false
false
true
true
let host_term =
t: R.term{not_tv_unknown t}
false
Pulse.Syntax.Base.fsti
Pulse.Syntax.Base.not_tv_unknown
val not_tv_unknown : t: FStar.Stubs.Reflection.Types.term -> Prims.logical
let not_tv_unknown (t:R.term) = R.inspect_ln t =!= R.Tv_Unknown
{ "file_name": "lib/steel/pulse/Pulse.Syntax.Base.fsti", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 63, "end_line": 85, "start_col": 0, "start_line": 85 }
(* Copyright 2023 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module Pulse.Syntax.Base module RTB = FStar.Reflection.Typing.Builtins module RT = FStar.Reflection.Typing module R = FStar.Reflection.V2 module RU = Pulse.RuntimeUtils module T = FStar.Tactics.V2 open FStar.List.Tot type constant = R.vconst let var = nat let index = nat type universe = R.universe (* locally nameless. *) let range_singleton_trigger (r:FStar.Range.range) = True let range = r:FStar.Range.range { range_singleton_trigger r } let range_singleton (r:FStar.Range.range) : Lemma (ensures r == FStar.Range.range_0) [SMTPat (range_singleton_trigger r)] = FStar.Sealed.sealed_singl r FStar.Range.range_0 noeq type ppname = { name : RT.pp_name_t; range : range } let ppname_default = { name = FStar.Sealed.seal "_"; range = FStar.Range.range_0 } let mk_ppname (name:RT.pp_name_t) (range:FStar.Range.range) : ppname = { name = name; range = range } let mk_ppname_no_range (s:string) : ppname = { name = FStar.Sealed.seal s; range = FStar.Range.range_0; } noeq type bv = { bv_index : index; bv_ppname : ppname; } noeq type nm = { nm_index : var; nm_ppname : ppname; } type qualifier = | Implicit noeq type fv = { fv_name : R.name; fv_range : range; } let as_fv l = { fv_name = l; fv_range = FStar.Range.range_0 }
{ "checked_file": "/", "dependencies": [ "Pulse.RuntimeUtils.fsti.checked", "Pulse.Reflection.Util.fst.checked", "prims.fst.checked", "FStar.Tactics.V2.fst.checked", "FStar.Sealed.Inhabited.fst.checked", "FStar.Sealed.fsti.checked", "FStar.Reflection.V2.fst.checked", "FStar.Reflection.Typing.Builtins.fsti.checked", "FStar.Reflection.Typing.fsti.checked", "FStar.Range.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked" ], "interface_file": false, "source_file": "Pulse.Syntax.Base.fsti" }
[ { "abbrev": false, "full_module": "FStar.List.Tot", "short_module": null }, { "abbrev": true, "full_module": "FStar.Tactics.V2", "short_module": "T" }, { "abbrev": true, "full_module": "Pulse.RuntimeUtils", "short_module": "RU" }, { "abbrev": true, "full_module": "FStar.Reflection.V2", "short_module": "R" }, { "abbrev": true, "full_module": "FStar.Reflection.Typing", "short_module": "RT" }, { "abbrev": true, "full_module": "FStar.Reflection.Typing.Builtins", "short_module": "RTB" }, { "abbrev": false, "full_module": "Pulse.Syntax", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Syntax", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": 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
t: FStar.Stubs.Reflection.Types.term -> Prims.logical
Prims.Tot
[ "total" ]
[]
[ "FStar.Stubs.Reflection.Types.term", "Prims.l_not", "Prims.eq2", "FStar.Stubs.Reflection.V2.Data.term_view", "FStar.Stubs.Reflection.V2.Builtins.inspect_ln", "FStar.Stubs.Reflection.V2.Data.Tv_Unknown", "Prims.logical" ]
[]
false
false
false
true
true
let not_tv_unknown (t: R.term) =
R.inspect_ln t =!= R.Tv_Unknown
false
Vale.Stdcalls.X64.GCTR.fst
Vale.Stdcalls.X64.GCTR.gctr128_lemma'
val gctr128_lemma' (s: Ghost.erased (Seq.seq nat32)) (code: V.va_code) (_win: bool) (in_b: b128) (num_bytes: uint64) (out_b inout_b keys_b ctr_b: b128) (num_blocks: uint64) (va_s0: V.va_state) : Ghost (V.va_state & V.va_fuel) (requires gctr128_pre s code in_b num_bytes out_b inout_b keys_b ctr_b num_blocks va_s0) (ensures (fun (va_s1, f) -> V.eval_code code va_s0 f va_s1 /\ VSig.vale_calling_conventions_stdcall va_s0 va_s1 /\ gctr128_post s code in_b num_bytes out_b inout_b keys_b ctr_b num_blocks va_s0 va_s1 f /\ ME.buffer_writeable (as_vale_buffer in_b) /\ ME.buffer_writeable (as_vale_buffer keys_b) /\ ME.buffer_writeable (as_vale_buffer ctr_b) /\ ME.buffer_writeable (as_vale_buffer inout_b) /\ ME.buffer_writeable (as_vale_buffer out_b)))
val gctr128_lemma' (s: Ghost.erased (Seq.seq nat32)) (code: V.va_code) (_win: bool) (in_b: b128) (num_bytes: uint64) (out_b inout_b keys_b ctr_b: b128) (num_blocks: uint64) (va_s0: V.va_state) : Ghost (V.va_state & V.va_fuel) (requires gctr128_pre s code in_b num_bytes out_b inout_b keys_b ctr_b num_blocks va_s0) (ensures (fun (va_s1, f) -> V.eval_code code va_s0 f va_s1 /\ VSig.vale_calling_conventions_stdcall va_s0 va_s1 /\ gctr128_post s code in_b num_bytes out_b inout_b keys_b ctr_b num_blocks va_s0 va_s1 f /\ ME.buffer_writeable (as_vale_buffer in_b) /\ ME.buffer_writeable (as_vale_buffer keys_b) /\ ME.buffer_writeable (as_vale_buffer ctr_b) /\ ME.buffer_writeable (as_vale_buffer inout_b) /\ ME.buffer_writeable (as_vale_buffer out_b)))
let gctr128_lemma' (s:Ghost.erased (Seq.seq nat32)) (code:V.va_code) (_win:bool) (in_b:b128) (num_bytes:uint64) (out_b:b128) (inout_b:b128) (keys_b:b128) (ctr_b:b128) (num_blocks:uint64) (va_s0:V.va_state) : Ghost (V.va_state & V.va_fuel) (requires gctr128_pre s code in_b num_bytes out_b inout_b keys_b ctr_b num_blocks va_s0) (ensures (fun (va_s1, f) -> V.eval_code code va_s0 f va_s1 /\ VSig.vale_calling_conventions_stdcall va_s0 va_s1 /\ gctr128_post s code in_b num_bytes out_b inout_b keys_b ctr_b num_blocks va_s0 va_s1 f /\ ME.buffer_writeable (as_vale_buffer in_b) /\ ME.buffer_writeable (as_vale_buffer keys_b) /\ ME.buffer_writeable (as_vale_buffer ctr_b) /\ ME.buffer_writeable (as_vale_buffer inout_b) /\ ME.buffer_writeable (as_vale_buffer out_b) )) = let va_s1, f = GC.va_lemma_Gctr_bytes_stdcall code va_s0 IA.win AES_128 (as_vale_buffer in_b) (UInt64.v num_bytes) (as_vale_buffer out_b) (as_vale_buffer inout_b) (as_vale_buffer keys_b) (as_vale_buffer ctr_b) (UInt64.v num_blocks) (Ghost.reveal s) in Vale.AsLowStar.MemoryHelpers.buffer_writeable_reveal ME.TUInt8 ME.TUInt128 in_b; Vale.AsLowStar.MemoryHelpers.buffer_writeable_reveal ME.TUInt8 ME.TUInt128 out_b; Vale.AsLowStar.MemoryHelpers.buffer_writeable_reveal ME.TUInt8 ME.TUInt128 inout_b; Vale.AsLowStar.MemoryHelpers.buffer_writeable_reveal ME.TUInt8 ME.TUInt128 keys_b; Vale.AsLowStar.MemoryHelpers.buffer_writeable_reveal ME.TUInt8 ME.TUInt128 ctr_b; (va_s1, f)
{ "file_name": "vale/code/arch/x64/interop/Vale.Stdcalls.X64.GCTR.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 13, "end_line": 125, "start_col": 0, "start_line": 91 }
module Vale.Stdcalls.X64.GCTR open FStar.HyperStack.ST module B = LowStar.Buffer module HS = FStar.HyperStack open FStar.Mul module DV = LowStar.BufferView.Down module UV = LowStar.BufferView.Up open Vale.Def.Types_s open Vale.Interop.Base module IX64 = Vale.Interop.X64 module VSig = Vale.AsLowStar.ValeSig module LSig = Vale.AsLowStar.LowStarSig module ME = Vale.X64.Memory module V = Vale.X64.Decls module IA = Vale.Interop.Assumptions module W = Vale.AsLowStar.Wrapper open Vale.X64.MemoryAdapters module VS = Vale.X64.State module MS = Vale.X64.Machine_s open Vale.AES.AES_s module GC = Vale.AES.X64.GCTR let uint64 = UInt64.t (* A little utility to trigger normalization in types *) noextract let as_t (#a:Type) (x:normal a) : a = x noextract let as_normal_t (#a:Type) (x:a) : normal a = x [@__reduce__] noextract let b128 = buf_t TUInt8 TUInt128 [@__reduce__] noextract let t128_mod = TD_Buffer TUInt8 TUInt128 default_bq [@__reduce__] noextract let t128_no_mod = TD_Buffer TUInt8 TUInt128 ({modified=false; strict_disjointness=false; taint=MS.Secret}) [@__reduce__] noextract let tuint64 = TD_Base TUInt64 [@__reduce__] noextract let (dom: list td{List.length dom <= 20}) = let y = [t128_no_mod; tuint64; t128_mod; t128_mod; t128_no_mod; t128_no_mod; tuint64] in assert_norm (List.length y = 7); y (* Need to rearrange the order of arguments *) [@__reduce__] noextract let gctr128_pre : (Ghost.erased (Seq.seq nat32)) -> VSig.vale_pre dom = fun (s:Ghost.erased (Seq.seq nat32)) (c:V.va_code) (in_b:b128) (num_bytes:uint64) (out_b:b128) (inout_b:b128) (keys_b:b128) (ctr_b:b128) (num_blocks:uint64) (va_s0:V.va_state) -> GC.va_req_Gctr_bytes_stdcall c va_s0 IA.win AES_128 (as_vale_buffer in_b) (UInt64.v num_bytes) (as_vale_buffer out_b) (as_vale_buffer inout_b) (as_vale_buffer keys_b) (as_vale_buffer ctr_b) (UInt64.v num_blocks) (Ghost.reveal s) (* Need to rearrange the order of arguments *) [@__reduce__] noextract let gctr128_post : (Ghost.erased (Seq.seq nat32)) -> VSig.vale_post dom = fun (s:Ghost.erased (Seq.seq nat32)) (c:V.va_code) (in_b:b128) (num_bytes:uint64) (out_b:b128) (inout_b:b128) (keys_b:b128) (ctr_b:b128) (num_blocks:uint64) (va_s0:V.va_state) (va_s1:V.va_state) (f:V.va_fuel) -> GC.va_ens_Gctr_bytes_stdcall c va_s0 IA.win AES_128 (as_vale_buffer in_b) (UInt64.v num_bytes) (as_vale_buffer out_b) (as_vale_buffer inout_b) (as_vale_buffer keys_b) (as_vale_buffer ctr_b) (UInt64.v num_blocks) (Ghost.reveal s) va_s1 f #set-options "--z3rlimit 20"
{ "checked_file": "/", "dependencies": [ "Vale.X64.State.fsti.checked", "Vale.X64.MemoryAdapters.fsti.checked", "Vale.X64.Memory.fsti.checked", "Vale.X64.Machine_s.fst.checked", "Vale.X64.Decls.fsti.checked", "Vale.Interop.X64.fsti.checked", "Vale.Interop.Base.fst.checked", "Vale.Interop.Assumptions.fst.checked", "Vale.Def.Types_s.fst.checked", "Vale.AsLowStar.Wrapper.fsti.checked", "Vale.AsLowStar.ValeSig.fst.checked", "Vale.AsLowStar.MemoryHelpers.fsti.checked", "Vale.AsLowStar.LowStarSig.fst.checked", "Vale.AES.X64.GCTR.fsti.checked", "Vale.AES.AES_s.fst.checked", "prims.fst.checked", "LowStar.BufferView.Up.fsti.checked", "LowStar.BufferView.Down.fsti.checked", "LowStar.Buffer.fst.checked", "FStar.UInt64.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.List.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked" ], "interface_file": false, "source_file": "Vale.Stdcalls.X64.GCTR.fst" }
[ { "abbrev": true, "full_module": "Vale.AES.X64.GCTR", "short_module": "GC" }, { "abbrev": false, "full_module": "Vale.AES.AES_s", "short_module": null }, { "abbrev": true, "full_module": "Vale.X64.Machine_s", "short_module": "MS" }, { "abbrev": true, "full_module": "Vale.X64.State", "short_module": "VS" }, { "abbrev": false, "full_module": "Vale.X64.MemoryAdapters", "short_module": null }, { "abbrev": true, "full_module": "Vale.AsLowStar.Wrapper", "short_module": "W" }, { "abbrev": true, "full_module": "Vale.Interop.Assumptions", "short_module": "IA" }, { "abbrev": true, "full_module": "Vale.X64.Decls", "short_module": "V" }, { "abbrev": true, "full_module": "Vale.X64.Memory", "short_module": "ME" }, { "abbrev": true, "full_module": "Vale.AsLowStar.LowStarSig", "short_module": "LSig" }, { "abbrev": true, "full_module": "Vale.AsLowStar.ValeSig", "short_module": "VSig" }, { "abbrev": true, "full_module": "Vale.Interop.X64", "short_module": "IX64" }, { "abbrev": false, "full_module": "Vale.Interop.Base", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Types_s", "short_module": null }, { "abbrev": true, "full_module": "LowStar.BufferView.Up", "short_module": "UV" }, { "abbrev": true, "full_module": "LowStar.BufferView.Down", "short_module": "DV" }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": false, "full_module": "Vale.Stdcalls.X64", "short_module": null }, { "abbrev": false, "full_module": "Vale.Stdcalls.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": 1, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": true, "smtencoding_l_arith_repr": "native", "smtencoding_nl_arith_repr": "wrapped", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [ "smt.arith.nl=false", "smt.QI.EAGER_THRESHOLD=100", "smt.CASE_SPLIT=3" ], "z3refresh": false, "z3rlimit": 20, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
s: FStar.Ghost.erased (FStar.Seq.Base.seq Vale.Def.Types_s.nat32) -> code: Vale.X64.Decls.va_code -> _win: Prims.bool -> in_b: Vale.Stdcalls.X64.GCTR.b128 -> num_bytes: Vale.Stdcalls.X64.GCTR.uint64 -> out_b: Vale.Stdcalls.X64.GCTR.b128 -> inout_b: Vale.Stdcalls.X64.GCTR.b128 -> keys_b: Vale.Stdcalls.X64.GCTR.b128 -> ctr_b: Vale.Stdcalls.X64.GCTR.b128 -> num_blocks: Vale.Stdcalls.X64.GCTR.uint64 -> va_s0: Vale.X64.Decls.va_state -> Prims.Ghost (Vale.X64.Decls.va_state * Vale.X64.Decls.va_fuel)
Prims.Ghost
[]
[]
[ "FStar.Ghost.erased", "FStar.Seq.Base.seq", "Vale.Def.Types_s.nat32", "Vale.X64.Decls.va_code", "Prims.bool", "Vale.Stdcalls.X64.GCTR.b128", "Vale.Stdcalls.X64.GCTR.uint64", "Vale.X64.Decls.va_state", "Vale.X64.Decls.va_fuel", "FStar.Pervasives.Native.Mktuple2", "Prims.unit", "Vale.AsLowStar.MemoryHelpers.buffer_writeable_reveal", "Vale.Arch.HeapTypes_s.TUInt8", "Vale.Arch.HeapTypes_s.TUInt128", "FStar.Pervasives.Native.tuple2", "Vale.X64.State.vale_state", "Vale.AES.X64.GCTR.va_lemma_Gctr_bytes_stdcall", "Vale.Interop.Assumptions.win", "Vale.AES.AES_common_s.AES_128", "Vale.X64.MemoryAdapters.as_vale_buffer", "FStar.UInt64.v", "FStar.Ghost.reveal", "Vale.Stdcalls.X64.GCTR.gctr128_pre", "Prims.l_and", "Vale.X64.Decls.eval_code", "Vale.AsLowStar.ValeSig.vale_calling_conventions_stdcall", "Vale.Stdcalls.X64.GCTR.gctr128_post", "Vale.X64.Memory.buffer_writeable" ]
[]
false
false
false
false
false
let gctr128_lemma' (s: Ghost.erased (Seq.seq nat32)) (code: V.va_code) (_win: bool) (in_b: b128) (num_bytes: uint64) (out_b inout_b keys_b ctr_b: b128) (num_blocks: uint64) (va_s0: V.va_state) : Ghost (V.va_state & V.va_fuel) (requires gctr128_pre s code in_b num_bytes out_b inout_b keys_b ctr_b num_blocks va_s0) (ensures (fun (va_s1, f) -> V.eval_code code va_s0 f va_s1 /\ VSig.vale_calling_conventions_stdcall va_s0 va_s1 /\ gctr128_post s code in_b num_bytes out_b inout_b keys_b ctr_b num_blocks va_s0 va_s1 f /\ ME.buffer_writeable (as_vale_buffer in_b) /\ ME.buffer_writeable (as_vale_buffer keys_b) /\ ME.buffer_writeable (as_vale_buffer ctr_b) /\ ME.buffer_writeable (as_vale_buffer inout_b) /\ ME.buffer_writeable (as_vale_buffer out_b))) =
let va_s1, f = GC.va_lemma_Gctr_bytes_stdcall code va_s0 IA.win AES_128 (as_vale_buffer in_b) (UInt64.v num_bytes) (as_vale_buffer out_b) (as_vale_buffer inout_b) (as_vale_buffer keys_b) (as_vale_buffer ctr_b) (UInt64.v num_blocks) (Ghost.reveal s) in Vale.AsLowStar.MemoryHelpers.buffer_writeable_reveal ME.TUInt8 ME.TUInt128 in_b; Vale.AsLowStar.MemoryHelpers.buffer_writeable_reveal ME.TUInt8 ME.TUInt128 out_b; Vale.AsLowStar.MemoryHelpers.buffer_writeable_reveal ME.TUInt8 ME.TUInt128 inout_b; Vale.AsLowStar.MemoryHelpers.buffer_writeable_reveal ME.TUInt8 ME.TUInt128 keys_b; Vale.AsLowStar.MemoryHelpers.buffer_writeable_reveal ME.TUInt8 ME.TUInt128 ctr_b; (va_s1, f)
false
LowParse.Low.Bytes.fst
LowParse.Low.Bytes.valid_bounded_vlbytes_elim
val valid_bounded_vlbytes_elim (h: HS.mem) (min: nat) (max: nat{min <= max /\ max > 0 /\ max < 4294967296}) (#rrel #rel: _) (input: slice rrel rel) (pos: U32.t) : Lemma (requires (valid (parse_bounded_vlbytes min max) h input pos)) (ensures (let sz = log256' max in valid (parse_bounded_integer sz) h input pos /\ (let len_payload = contents (parse_bounded_integer sz) h input pos in min <= U32.v len_payload /\ U32.v len_payload <= max /\ sz + U32.v len_payload == content_length (parse_bounded_vlbytes min max) h input pos /\ (let pos_payload = pos `U32.add` (U32.uint_to_t sz) in let x = contents (parse_bounded_vlbytes min max) h input pos in BY.len x == len_payload /\ valid_pos (parse_bounded_vlbytes min max) h input pos (pos_payload `U32.add` len_payload) /\ valid_content_pos (parse_flbytes (U32.v len_payload)) h input pos_payload x (pos_payload `U32.add` len_payload)))))
val valid_bounded_vlbytes_elim (h: HS.mem) (min: nat) (max: nat{min <= max /\ max > 0 /\ max < 4294967296}) (#rrel #rel: _) (input: slice rrel rel) (pos: U32.t) : Lemma (requires (valid (parse_bounded_vlbytes min max) h input pos)) (ensures (let sz = log256' max in valid (parse_bounded_integer sz) h input pos /\ (let len_payload = contents (parse_bounded_integer sz) h input pos in min <= U32.v len_payload /\ U32.v len_payload <= max /\ sz + U32.v len_payload == content_length (parse_bounded_vlbytes min max) h input pos /\ (let pos_payload = pos `U32.add` (U32.uint_to_t sz) in let x = contents (parse_bounded_vlbytes min max) h input pos in BY.len x == len_payload /\ valid_pos (parse_bounded_vlbytes min max) h input pos (pos_payload `U32.add` len_payload) /\ valid_content_pos (parse_flbytes (U32.v len_payload)) h input pos_payload x (pos_payload `U32.add` len_payload)))))
let valid_bounded_vlbytes_elim (h: HS.mem) (min: nat) (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (#rrel #rel: _) (input: slice rrel rel) (pos: U32.t) : Lemma (requires ( valid (parse_bounded_vlbytes min max) h input pos )) (ensures ( let sz = log256' max in valid (parse_bounded_integer sz) h input pos /\ ( let len_payload = contents (parse_bounded_integer sz) h input pos in min <= U32.v len_payload /\ U32.v len_payload <= max /\ sz + U32.v len_payload == content_length (parse_bounded_vlbytes min max) h input pos /\ ( let pos_payload = pos `U32.add` U32.uint_to_t sz in let x = contents (parse_bounded_vlbytes min max) h input pos in BY.len x == len_payload /\ valid_pos (parse_bounded_vlbytes min max) h input pos (pos_payload `U32.add` len_payload) /\ valid_content_pos (parse_flbytes (U32.v len_payload)) h input pos_payload x (pos_payload `U32.add` len_payload) )))) = valid_bounded_vlbytes'_elim h min max (log256' max) input pos
{ "file_name": "src/lowparse/LowParse.Low.Bytes.fst", "git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
{ "end_col": 63, "end_line": 477, "start_col": 0, "start_line": 454 }
module LowParse.Low.Bytes include LowParse.Spec.Bytes include LowParse.Low.Combinators include LowParse.Low.VLData include LowParse.Low.VLGen include LowParse.Low.Int module U32 = FStar.UInt32 module HS = FStar.HyperStack module B = LowStar.Monotonic.Buffer module BF = LowStar.Buffer // for local variables in store_bytes module BY = LowParse.Bytes32 module HST = FStar.HyperStack.ST module U8 = FStar.UInt8 module Cast = FStar.Int.Cast module U64 = FStar.UInt64 inline_for_extraction let validate_flbytes (sz: nat) (sz64: U64.t { U64.v sz64 == sz /\ sz < 4294967296 } ) : Tot (validator (parse_flbytes sz)) = validate_total_constant_size (parse_flbytes sz) sz64 () inline_for_extraction let jump_flbytes (sz: nat) (sz32: U32.t { U32.v sz32 == sz } ) : Tot (jumper (parse_flbytes sz)) = jump_constant_size (parse_flbytes sz) sz32 () let valid_flbytes_intro (h: HS.mem) (sz: nat { sz < 4294967296 } ) (#rrel #rel: _) (s: slice rrel rel) (pos: U32.t) : Lemma (requires (U32.v pos + sz <= U32.v s.len /\ live_slice h s)) (ensures ( valid_content_pos (parse_flbytes sz) h s pos (BY.hide (bytes_of_slice_from_to h s pos (pos `U32.add` U32.uint_to_t sz))) (pos `U32.add` U32.uint_to_t sz) )) = valid_facts (parse_flbytes sz) h s pos let valid_pos_flbytes_elim (h: HS.mem) (sz: nat { sz < 4294967296 } ) (#rrel #rel: _) (s: slice rrel rel) (pos pos' : U32.t) : Lemma (requires (valid_pos (parse_flbytes sz) h s pos pos')) (ensures (U32.v pos + sz == U32.v pos')) [SMTPat (valid_pos (parse_flbytes sz) h s pos pos')] = valid_facts (parse_flbytes sz) h s pos let valid_flbytes_elim (h: HS.mem) (sz: nat { sz < 4294967296 } ) (#rrel #rel: _) (s: slice rrel rel) (pos: U32.t) : Lemma (requires (valid (parse_flbytes sz) h s pos)) (ensures ( valid_content_pos (parse_flbytes sz) h s pos (BY.hide (bytes_of_slice_from_to h s pos (pos `U32.add` U32.uint_to_t sz))) (pos `U32.add` U32.uint_to_t sz) )) = valid_flbytes_intro h sz s pos let clens_flbytes_slice (sz: nat) (from: U32.t) (to: U32.t {U32.v from <= U32.v to /\ U32.v to <= sz } ) : Tot (clens (BY.lbytes sz) (BY.lbytes (U32.v to - U32.v from))) = { clens_cond = (fun _ -> True); clens_get = (fun (x: BY.lbytes sz) -> (BY.slice x from to <: BY.lbytes (U32.v to - U32.v from))); } #push-options "--z3rlimit 16" let gaccessor_flbytes_slice' (sz: nat { sz < 4294967296 } ) (from: U32.t) (to: U32.t {U32.v from <= U32.v to /\ U32.v to <= sz } ) : Tot (gaccessor' (parse_flbytes sz) (parse_flbytes (U32.v to - U32.v from)) (clens_flbytes_slice sz from to)) = fun (input: bytes) -> ( begin if Seq.length input < sz then (0) // dummy else (U32.v from) end) let gaccessor_flbytes_slice (sz: nat { sz < 4294967296 } ) (from: U32.t) (to: U32.t {U32.v from <= U32.v to /\ U32.v to <= sz } ) : Tot (gaccessor (parse_flbytes sz) (parse_flbytes (U32.v to - U32.v from)) (clens_flbytes_slice sz from to)) = assert (forall x . gaccessor_pre (parse_flbytes sz) (parse_flbytes (U32.v to - U32.v from)) (clens_flbytes_slice sz from to) x ==> sz <= Seq.length x); gaccessor_prop_equiv (parse_flbytes sz) (parse_flbytes (U32.v to - U32.v from)) (clens_flbytes_slice sz from to) (gaccessor_flbytes_slice' sz from to); gaccessor_flbytes_slice' sz from to inline_for_extraction let accessor_flbytes_slice (sz: nat { sz < 4294967296 } ) (from: U32.t) (to: U32.t {U32.v from <= U32.v to /\ U32.v to <= sz } ) : Tot (accessor (gaccessor_flbytes_slice sz from to)) = fun #rrel #rel input pos -> let h = HST.get () in [@inline_let] let _ = slice_access_eq h (gaccessor_flbytes_slice sz from to) input pos in pos `U32.add` from #pop-options let clens_flbytes_get (sz: nat) (i: U32.t { U32.v i < sz } ) : Tot (clens (BY.lbytes sz) byte) = { clens_cond = (fun _ -> True); clens_get = (fun (x: BY.lbytes sz) -> (BY.get x i <: byte)); } #push-options "--z3rlimit 16 --max_fuel 1" let gaccessor_flbytes_get' (sz: nat { sz < 4294967296 } ) (i: U32.t { U32.v i < sz } ) : Tot (gaccessor' (parse_flbytes sz) (parse_u8) (clens_flbytes_get sz i)) = fun (input: bytes) -> ( begin let res = if Seq.length input < U32.v i then (0) // dummy else (U32.v i) in let g () : Lemma (requires (gaccessor_pre (parse_flbytes sz) parse_u8 (clens_flbytes_get sz i) input)) (ensures (gaccessor_post (parse_flbytes sz) parse_u8 (clens_flbytes_get sz i) input res)) = parser_kind_prop_equiv (get_parser_kind parse_u8) parse_u8; assert (res == (U32.v i)); parse_u8_spec' (Seq.slice input (U32.v i) (U32.v i + 1)); parse_strong_prefix parse_u8 (Seq.slice input (U32.v i) (U32.v i + 1)) (Seq.slice input (U32.v i) (Seq.length input)) in Classical.move_requires g (); res end) #pop-options let gaccessor_flbytes_get (sz: nat { sz < 4294967296 } ) (i: U32.t { U32.v i < sz } ) : Tot (gaccessor (parse_flbytes sz) (parse_u8) (clens_flbytes_get sz i)) = assert (forall x . gaccessor_pre (parse_flbytes sz) (parse_u8) (clens_flbytes_get sz i) x ==> U32.v i <= Seq.length x); gaccessor_prop_equiv (parse_flbytes sz) (parse_u8) (clens_flbytes_get sz i) (gaccessor_flbytes_get' sz i); gaccessor_flbytes_get' sz i inline_for_extraction let accessor_flbytes_get (sz: nat { sz < 4294967296 } ) (i: U32.t { U32.v i < sz } ) : Tot (accessor (gaccessor_flbytes_get sz i)) = fun #rrel #rel input pos -> let h = HST.get () in [@inline_let] let _ = slice_access_eq h (gaccessor_flbytes_get sz i) input pos in pos `U32.add` i (* Temporary: flbytes as leaf values *) (* TODO: convert store_bytes to monotonic buffers, using the "writable" predicate *) #push-options "--z3rlimit 32" inline_for_extraction let store_bytes (src: BY.bytes) (src_from src_to: U32.t) (#rrel #rel: _) (dst: B.mbuffer byte rrel rel) (dst_pos: U32.t) : HST.Stack unit (requires (fun h -> B.live h dst /\ U32.v src_from <= U32.v src_to /\ U32.v src_to <= BY.length src /\ U32.v dst_pos + (U32.v src_to - U32.v src_from) <= B.length dst /\ writable dst (U32.v dst_pos) (U32.v dst_pos + (U32.v src_to - U32.v src_from)) h )) (ensures (fun h _ h' -> B.modifies (B.loc_buffer_from_to dst dst_pos (dst_pos `U32.add` (src_to `U32.sub` src_from))) h h' /\ Seq.slice (B.as_seq h' dst) (U32.v dst_pos) (U32.v dst_pos + (U32.v src_to - U32.v src_from)) == Seq.slice (BY.reveal src) (U32.v src_from) (U32.v src_to) )) = let h0 = HST.get () in HST.push_frame (); let h1 = HST.get () in let bi = BF.alloca 0ul 1ul in let h2 = HST.get () in let len = src_to `U32.sub` src_from in C.Loops.do_while (fun h stop -> B.modifies (B.loc_union (B.loc_region_only true (HS.get_tip h1)) (B.loc_buffer_from_to dst dst_pos (dst_pos `U32.add` len))) h2 h /\ B.live h bi /\ ( let i = Seq.index (B.as_seq h bi) 0 in U32.v i <= U32.v len /\ writable dst (U32.v dst_pos) (U32.v dst_pos + U32.v len) h /\ Seq.slice (B.as_seq h dst) (U32.v dst_pos) (U32.v dst_pos + U32.v i) `Seq.equal` Seq.slice (BY.reveal src) (U32.v src_from) (U32.v src_from + U32.v i) /\ (stop == true ==> i == len) )) (fun _ -> let i = B.index bi 0ul in if i = len then true else begin let x = BY.get src (src_from `U32.add` i) in mbuffer_upd dst (Ghost.hide (U32.v dst_pos)) (Ghost.hide (U32.v dst_pos + U32.v len)) (dst_pos `U32.add` i) x; let i' = i `U32.add` 1ul in B.upd bi 0ul i'; let h' = HST.get () in Seq.lemma_split (Seq.slice (B.as_seq h' dst) (U32.v dst_pos) (U32.v dst_pos + U32.v i')) (U32.v i); i' = len end ) ; HST.pop_frame () #pop-options inline_for_extraction let serialize32_flbytes (sz32: U32.t) : Tot (serializer32 (serialize_flbytes (U32.v sz32))) = fun (x: BY.lbytes (U32.v sz32)) #rrel #rel b pos -> let _ = store_bytes x 0ul sz32 b pos in sz32 inline_for_extraction let write_flbytes (sz32: U32.t) : Tot (leaf_writer_strong (serialize_flbytes (U32.v sz32))) = leaf_writer_strong_of_serializer32 (serialize32_flbytes sz32) () inline_for_extraction let write_flbytes_weak (sz32: U32.t { U32.v sz32 < 4294967295 } ) // need to return that value if output buffer is too small : Tot (leaf_writer_weak (serialize_flbytes (U32.v sz32))) = leaf_writer_weak_of_strong_constant_size (write_flbytes sz32) sz32 () (* // TODO: remove, since nobody is using this inline_for_extraction let read_flbytes (sz32: U32.t) : Tot (leaf_reader (parse_flbytes (U32.v sz32))) = fun input pos -> let h = HST.get () in [@inline_let] let _ = valid_facts (parse_flbytes (U32.v sz32)) h input pos in BY.of_buffer sz32 (B.sub input.base pos sz32) *) (* Equality test between a vlbytes and a constant lbytes *) #push-options "--z3rlimit 32" inline_for_extraction let buffer_equals_bytes (const: BY.bytes) (#rrel #rel: _) (b: B.mbuffer byte rrel rel) (pos: U32.t) : HST.Stack bool (requires (fun h -> B.live h b /\ U32.v pos + BY.length const <= B.length b )) (ensures (fun h res h' -> B.modifies B.loc_none h h' /\ (res == true <==> Seq.slice (B.as_seq h b) (U32.v pos) (U32.v pos + BY.length const) == BY.reveal const) )) = let h0 = HST.get () in HST.push_frame (); let len = BY.len const in let bi = BF.alloca 0ul 1ul in let bres = BF.alloca true 1ul in let h1 = HST.get () in [@inline_let] let inv (h: HS.mem) (stop: bool) : GTot Type0 = B.modifies (B.loc_union (B.loc_buffer bi) (B.loc_buffer bres)) h1 h /\ ( let length = U32.v len in let i32 = (Seq.index (B.as_seq h bi) 0) in let i = U32.v i32 in let res = Seq.index (B.as_seq h bres) 0 in i <= length /\ (stop == false ==> res == true) /\ ((stop == true /\ res == true) ==> i == length) /\ (res == true <==> Seq.slice (B.as_seq h b) (U32.v pos) (U32.v pos + i) `Seq.equal` Seq.slice (BY.reveal const) 0 i) ) in C.Loops.do_while inv (fun _ -> let i = B.index bi 0ul in if i = len then true else begin let i' = i `U32.add` 1ul in [@inline_let] let _ = let s1 = (Seq.slice (B.as_seq h0 b) (U32.v pos) (U32.v pos + U32.v i)) in let c1 = (B.get h0 b (U32.v pos + U32.v i)) in let s2 = (Seq.slice (BY.reveal const) 0 (U32.v i)) in let c2 = (BY.index const (U32.v i)) in assert (Seq.slice (B.as_seq h0 b) (U32.v pos) (U32.v pos + U32.v i') `Seq.equal` Seq.snoc s1 c1); assert (Seq.slice (BY.reveal const) 0 (U32.v i') `Seq.equal` Seq.snoc s2 c2); Classical.move_requires (Seq.lemma_snoc_inj s1 s2 c1) c2 in let res = B.index b (pos `U32.add` i) = BY.get const i in B.upd bres 0ul res; B.upd bi 0ul i'; not res end ); let res = B.index bres 0ul in HST.pop_frame (); res #pop-options inline_for_extraction let valid_slice_equals_bytes (const: BY.bytes) (#rrel #rel: _) (input: slice rrel rel) (pos: U32.t) : HST.Stack bool (requires (fun h -> valid (parse_flbytes (BY.length const)) h input pos )) (ensures (fun h res h' -> B.modifies B.loc_none h h' /\ (res == true <==> contents (parse_flbytes (BY.length const)) h input pos == const ))) = let h = HST.get () in [@inline_let] let _ = valid_facts (parse_flbytes (BY.length const)) h input pos in buffer_equals_bytes const input.base pos inline_for_extraction let validate_all_bytes () : Tot (validator parse_all_bytes) = fun #rrel #rel input pos -> let h = HST.get () in [@inline_let] let _ = valid_facts parse_all_bytes h input (uint64_to_uint32 pos) in Cast.uint32_to_uint64 input.len inline_for_extraction let validate_bounded_vlbytes' (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (l: nat { l >= log256' max /\ l <= 4 } ) : Tot (validator (parse_bounded_vlbytes' min max l)) = validate_synth (validate_bounded_vldata_strong' min max l serialize_all_bytes (validate_all_bytes ())) (synth_bounded_vlbytes min max) () inline_for_extraction let validate_bounded_vlbytes (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) : Tot (validator (parse_bounded_vlbytes min max)) = validate_bounded_vlbytes' min max (log256' max) inline_for_extraction let jump_all_bytes () : Tot (jumper parse_all_bytes) = fun #rrel #rel input pos -> let h = HST.get () in [@inline_let] let _ = valid_facts parse_all_bytes h input pos in input.len inline_for_extraction let jump_bounded_vlbytes' (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (l: nat { l >= log256' max /\ l <= 4 } ) : Tot (jumper (parse_bounded_vlbytes' min max l)) = jump_synth (jump_bounded_vldata_strong' min max l serialize_all_bytes) (synth_bounded_vlbytes min max) () inline_for_extraction let jump_bounded_vlbytes (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) : Tot (jumper (parse_bounded_vlbytes min max)) = jump_bounded_vlbytes' min max (log256' max) let valid_exact_all_bytes_elim (h: HS.mem) (#rrel #rel: _) (input: slice rrel rel) (pos pos' : U32.t) : Lemma (requires (valid_exact parse_all_bytes h input pos pos')) (ensures ( let x = contents_exact parse_all_bytes h input pos pos' in let length = U32.v pos' - U32.v pos in BY.length x == length /\ valid_content_pos (parse_flbytes length) h input pos x pos' )) = valid_exact_equiv parse_all_bytes h input pos pos' ; contents_exact_eq parse_all_bytes h input pos pos' ; let length = U32.v pos' - U32.v pos in valid_facts (parse_flbytes length) h input pos ; assert (no_lookahead_on (parse_flbytes length) (bytes_of_slice_from_to h input pos pos') (bytes_of_slice_from h input pos)); assert (injective_postcond (parse_flbytes length) (bytes_of_slice_from_to h input pos pos') (bytes_of_slice_from h input pos)) #push-options "--z3rlimit 32" let valid_bounded_vlbytes'_elim (h: HS.mem) (min: nat) (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (l: nat { l >= log256' max /\ l <= 4 } ) (#rrel #rel: _) (input: slice rrel rel) (pos: U32.t) : Lemma (requires ( valid (parse_bounded_vlbytes' min max l) h input pos )) (ensures ( let sz = l in valid (parse_bounded_integer sz) h input pos /\ ( let len_payload = contents (parse_bounded_integer sz) h input pos in min <= U32.v len_payload /\ U32.v len_payload <= max /\ sz + U32.v len_payload == content_length (parse_bounded_vlbytes' min max l) h input pos /\ ( let pos_payload = pos `U32.add` U32.uint_to_t sz in let x = contents (parse_bounded_vlbytes' min max l) h input pos in BY.len x == len_payload /\ valid_pos (parse_bounded_vlbytes' min max l) h input pos (pos_payload `U32.add` len_payload) /\ valid_content_pos (parse_flbytes (U32.v len_payload)) h input pos_payload x (pos_payload `U32.add` len_payload) )))) = valid_synth h (parse_bounded_vlbytes_aux min max l) (synth_bounded_vlbytes min max) input pos; valid_bounded_vldata_strong'_elim h min max l serialize_all_bytes input pos; let sz = l in let len_payload = contents (parse_bounded_integer sz) h input pos in let pos_payload = pos `U32.add` U32.uint_to_t sz in valid_exact_all_bytes_elim h input pos_payload (pos_payload `U32.add` len_payload); () #pop-options
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowStar.Monotonic.Buffer.fsti.checked", "LowStar.Buffer.fst.checked", "LowParse.Spec.Bytes.fst.checked", "LowParse.Low.VLGen.fst.checked", "LowParse.Low.VLData.fst.checked", "LowParse.Low.Int.fsti.checked", "LowParse.Low.Combinators.fsti.checked", "LowParse.Bytes32.fst.checked", "FStar.UInt8.fsti.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Int.Cast.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked", "FStar.Classical.fsti.checked", "C.Loops.fst.checked" ], "interface_file": false, "source_file": "LowParse.Low.Bytes.fst" }
[ { "abbrev": true, "full_module": "LowStar.Buffer // for local variables in store_bytes", "short_module": "BF" }, { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "FStar.Int.Cast", "short_module": "Cast" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "LowParse.Bytes32", "short_module": "BY" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "BF" }, { "abbrev": true, "full_module": "LowStar.Monotonic.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": false, "full_module": "LowParse.Low.Int", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low.VLGen", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low.VLData", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low.Combinators", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec.Bytes", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
h: FStar.Monotonic.HyperStack.mem -> min: Prims.nat -> max: Prims.nat{min <= max /\ max > 0 /\ max < 4294967296} -> input: LowParse.Slice.slice rrel rel -> pos: FStar.UInt32.t -> FStar.Pervasives.Lemma (requires LowParse.Low.Base.Spec.valid (LowParse.Spec.Bytes.parse_bounded_vlbytes min max) h input pos ) (ensures (let sz = LowParse.Spec.BoundedInt.log256' max in LowParse.Low.Base.Spec.valid (LowParse.Spec.BoundedInt.parse_bounded_integer sz) h input pos /\ (let len_payload = LowParse.Low.Base.Spec.contents (LowParse.Spec.BoundedInt.parse_bounded_integer sz) h input pos in min <= FStar.UInt32.v len_payload /\ FStar.UInt32.v len_payload <= max /\ sz + FStar.UInt32.v len_payload == LowParse.Low.Base.Spec.content_length (LowParse.Spec.Bytes.parse_bounded_vlbytes min max ) h input pos /\ (let pos_payload = FStar.UInt32.add pos (FStar.UInt32.uint_to_t sz) in let x = LowParse.Low.Base.Spec.contents (LowParse.Spec.Bytes.parse_bounded_vlbytes min max) h input pos in FStar.Bytes.len x == len_payload /\ LowParse.Low.Base.Spec.valid_pos (LowParse.Spec.Bytes.parse_bounded_vlbytes min max) h input pos (FStar.UInt32.add pos_payload len_payload) /\ LowParse.Low.Base.Spec.valid_content_pos (LowParse.Spec.Bytes.parse_flbytes (FStar.UInt32.v len_payload)) h input pos_payload x (FStar.UInt32.add pos_payload len_payload)))))
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "FStar.Monotonic.HyperStack.mem", "Prims.nat", "Prims.l_and", "Prims.b2t", "Prims.op_LessThanOrEqual", "Prims.op_GreaterThan", "Prims.op_LessThan", "LowParse.Slice.srel", "LowParse.Bytes.byte", "LowParse.Slice.slice", "FStar.UInt32.t", "LowParse.Low.Bytes.valid_bounded_vlbytes'_elim", "LowParse.Spec.BoundedInt.log256'", "Prims.unit", "LowParse.Low.Base.Spec.valid", "LowParse.Spec.VLData.parse_bounded_vldata_strong_kind", "LowParse.Spec.Bytes.parse_all_bytes_kind", "LowParse.Spec.Bytes.parse_bounded_vlbytes_t", "LowParse.Spec.Bytes.parse_bounded_vlbytes", "Prims.squash", "LowParse.Spec.BoundedInt.parse_bounded_integer_kind", "LowParse.Spec.BoundedInt.bounded_integer", "LowParse.Spec.BoundedInt.parse_bounded_integer", "FStar.UInt32.v", "Prims.eq2", "Prims.int", "Prims.op_Addition", "LowParse.Low.Base.Spec.content_length", "FStar.Bytes.len", "LowParse.Low.Base.Spec.valid_pos", "FStar.UInt32.add", "LowParse.Low.Base.Spec.valid_content_pos", "LowParse.Spec.Base.total_constant_size_parser_kind", "FStar.Bytes.lbytes", "LowParse.Spec.Bytes.parse_flbytes", "LowParse.Low.Base.Spec.contents", "FStar.UInt32.uint_to_t", "LowParse.Spec.BoundedInt.integer_size", "Prims.Nil", "FStar.Pervasives.pattern" ]
[]
true
false
true
false
false
let valid_bounded_vlbytes_elim (h: HS.mem) (min: nat) (max: nat{min <= max /\ max > 0 /\ max < 4294967296}) (#rrel #rel: _) (input: slice rrel rel) (pos: U32.t) : Lemma (requires (valid (parse_bounded_vlbytes min max) h input pos)) (ensures (let sz = log256' max in valid (parse_bounded_integer sz) h input pos /\ (let len_payload = contents (parse_bounded_integer sz) h input pos in min <= U32.v len_payload /\ U32.v len_payload <= max /\ sz + U32.v len_payload == content_length (parse_bounded_vlbytes min max) h input pos /\ (let pos_payload = pos `U32.add` (U32.uint_to_t sz) in let x = contents (parse_bounded_vlbytes min max) h input pos in BY.len x == len_payload /\ valid_pos (parse_bounded_vlbytes min max) h input pos (pos_payload `U32.add` len_payload) /\ valid_content_pos (parse_flbytes (U32.v len_payload)) h input pos_payload x (pos_payload `U32.add` len_payload))))) =
valid_bounded_vlbytes'_elim h min max (log256' max) input pos
false
Pulse.Syntax.Base.fsti
Pulse.Syntax.Base.binder_attrs_default
val binder_attrs_default : FStar.Sealed.sealed (Prims.list _)
let binder_attrs_default = FStar.Sealed.seal []
{ "file_name": "lib/steel/pulse/Pulse.Syntax.Base.fsti", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 47, "end_line": 120, "start_col": 0, "start_line": 120 }
(* Copyright 2023 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module Pulse.Syntax.Base module RTB = FStar.Reflection.Typing.Builtins module RT = FStar.Reflection.Typing module R = FStar.Reflection.V2 module RU = Pulse.RuntimeUtils module T = FStar.Tactics.V2 open FStar.List.Tot type constant = R.vconst let var = nat let index = nat type universe = R.universe (* locally nameless. *) let range_singleton_trigger (r:FStar.Range.range) = True let range = r:FStar.Range.range { range_singleton_trigger r } let range_singleton (r:FStar.Range.range) : Lemma (ensures r == FStar.Range.range_0) [SMTPat (range_singleton_trigger r)] = FStar.Sealed.sealed_singl r FStar.Range.range_0 noeq type ppname = { name : RT.pp_name_t; range : range } let ppname_default = { name = FStar.Sealed.seal "_"; range = FStar.Range.range_0 } let mk_ppname (name:RT.pp_name_t) (range:FStar.Range.range) : ppname = { name = name; range = range } let mk_ppname_no_range (s:string) : ppname = { name = FStar.Sealed.seal s; range = FStar.Range.range_0; } noeq type bv = { bv_index : index; bv_ppname : ppname; } noeq type nm = { nm_index : var; nm_ppname : ppname; } type qualifier = | Implicit noeq type fv = { fv_name : R.name; fv_range : range; } let as_fv l = { fv_name = l; fv_range = FStar.Range.range_0 } let not_tv_unknown (t:R.term) = R.inspect_ln t =!= R.Tv_Unknown let host_term = t:R.term { not_tv_unknown t } [@@ no_auto_projectors] noeq type term' = | Tm_Emp : term' | Tm_Pure : p:term -> term' | Tm_Star : l:vprop -> r:vprop -> term' | Tm_ExistsSL : u:universe -> b:binder -> body:vprop -> term' | Tm_ForallSL : u:universe -> b:binder -> body:vprop -> term' | Tm_VProp : term' | Tm_Inv : vprop -> term' | Tm_Inames : term' // type inames | Tm_EmpInames : term' | Tm_AddInv : i:term -> is:term -> term' | Tm_FStar : host_term -> term' | Tm_Unknown : term' and vprop = term and typ = term and binder = { binder_ty : term; binder_ppname : ppname; binder_attrs : FStar.Sealed.Inhabited.sealed #(list term) [] } and term = { t : term'; range : range; }
{ "checked_file": "/", "dependencies": [ "Pulse.RuntimeUtils.fsti.checked", "Pulse.Reflection.Util.fst.checked", "prims.fst.checked", "FStar.Tactics.V2.fst.checked", "FStar.Sealed.Inhabited.fst.checked", "FStar.Sealed.fsti.checked", "FStar.Reflection.V2.fst.checked", "FStar.Reflection.Typing.Builtins.fsti.checked", "FStar.Reflection.Typing.fsti.checked", "FStar.Range.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked" ], "interface_file": false, "source_file": "Pulse.Syntax.Base.fsti" }
[ { "abbrev": false, "full_module": "FStar.List.Tot", "short_module": null }, { "abbrev": true, "full_module": "FStar.Tactics.V2", "short_module": "T" }, { "abbrev": true, "full_module": "Pulse.RuntimeUtils", "short_module": "RU" }, { "abbrev": true, "full_module": "FStar.Reflection.V2", "short_module": "R" }, { "abbrev": true, "full_module": "FStar.Reflection.Typing", "short_module": "RT" }, { "abbrev": true, "full_module": "FStar.Reflection.Typing.Builtins", "short_module": "RTB" }, { "abbrev": false, "full_module": "Pulse.Syntax", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Syntax", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": 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.Sealed.sealed (Prims.list _)
Prims.Tot
[ "total" ]
[]
[ "FStar.Sealed.seal", "Prims.list", "Prims.Nil", "FStar.Sealed.sealed" ]
[]
false
false
false
true
false
let binder_attrs_default =
FStar.Sealed.seal []
false
LowParse.Low.Bytes.fst
LowParse.Low.Bytes.bounded_vlbytes_payload_length
val bounded_vlbytes_payload_length (min: nat) (max: nat{min <= max /\ max > 0 /\ max < 4294967296}) (#rrel #rel: _) (input: slice rrel rel) (pos: U32.t) : HST.Stack U32.t (requires (fun h -> valid (parse_bounded_vlbytes min max) h input pos)) (ensures (fun h len h' -> B.modifies B.loc_none h h' /\ U32.v pos + log256' max + U32.v len <= U32.v input.len /\ (let x = contents (parse_bounded_vlbytes min max) h input pos in let pos' = get_valid_pos (parse_bounded_vlbytes min max) h input pos in BY.len x == len /\ valid_content_pos (parse_flbytes (U32.v len)) h input (pos `U32.add` (U32.uint_to_t (log256' max))) x pos' /\ bytes_of_slice_from_to h input (pos `U32.add` (U32.uint_to_t (log256' max))) pos' == BY.reveal x)))
val bounded_vlbytes_payload_length (min: nat) (max: nat{min <= max /\ max > 0 /\ max < 4294967296}) (#rrel #rel: _) (input: slice rrel rel) (pos: U32.t) : HST.Stack U32.t (requires (fun h -> valid (parse_bounded_vlbytes min max) h input pos)) (ensures (fun h len h' -> B.modifies B.loc_none h h' /\ U32.v pos + log256' max + U32.v len <= U32.v input.len /\ (let x = contents (parse_bounded_vlbytes min max) h input pos in let pos' = get_valid_pos (parse_bounded_vlbytes min max) h input pos in BY.len x == len /\ valid_content_pos (parse_flbytes (U32.v len)) h input (pos `U32.add` (U32.uint_to_t (log256' max))) x pos' /\ bytes_of_slice_from_to h input (pos `U32.add` (U32.uint_to_t (log256' max))) pos' == BY.reveal x)))
let bounded_vlbytes_payload_length (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (#rrel #rel: _) (input: slice rrel rel) (pos: U32.t) : HST.Stack U32.t (requires (fun h -> valid (parse_bounded_vlbytes min max) h input pos)) (ensures (fun h len h' -> B.modifies B.loc_none h h' /\ U32.v pos + log256' max + U32.v len <= U32.v input.len /\ ( let x = contents (parse_bounded_vlbytes min max) h input pos in let pos' = get_valid_pos (parse_bounded_vlbytes min max) h input pos in BY.len x == len /\ valid_content_pos (parse_flbytes (U32.v len)) h input (pos `U32.add` U32.uint_to_t (log256' max)) x pos' /\ bytes_of_slice_from_to h input (pos `U32.add` U32.uint_to_t (log256' max)) pos' == BY.reveal x ))) = bounded_vlbytes'_payload_length min max (log256' max) input pos
{ "file_name": "src/lowparse/LowParse.Low.Bytes.fst", "git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
{ "end_col": 65, "end_line": 539, "start_col": 0, "start_line": 522 }
module LowParse.Low.Bytes include LowParse.Spec.Bytes include LowParse.Low.Combinators include LowParse.Low.VLData include LowParse.Low.VLGen include LowParse.Low.Int module U32 = FStar.UInt32 module HS = FStar.HyperStack module B = LowStar.Monotonic.Buffer module BF = LowStar.Buffer // for local variables in store_bytes module BY = LowParse.Bytes32 module HST = FStar.HyperStack.ST module U8 = FStar.UInt8 module Cast = FStar.Int.Cast module U64 = FStar.UInt64 inline_for_extraction let validate_flbytes (sz: nat) (sz64: U64.t { U64.v sz64 == sz /\ sz < 4294967296 } ) : Tot (validator (parse_flbytes sz)) = validate_total_constant_size (parse_flbytes sz) sz64 () inline_for_extraction let jump_flbytes (sz: nat) (sz32: U32.t { U32.v sz32 == sz } ) : Tot (jumper (parse_flbytes sz)) = jump_constant_size (parse_flbytes sz) sz32 () let valid_flbytes_intro (h: HS.mem) (sz: nat { sz < 4294967296 } ) (#rrel #rel: _) (s: slice rrel rel) (pos: U32.t) : Lemma (requires (U32.v pos + sz <= U32.v s.len /\ live_slice h s)) (ensures ( valid_content_pos (parse_flbytes sz) h s pos (BY.hide (bytes_of_slice_from_to h s pos (pos `U32.add` U32.uint_to_t sz))) (pos `U32.add` U32.uint_to_t sz) )) = valid_facts (parse_flbytes sz) h s pos let valid_pos_flbytes_elim (h: HS.mem) (sz: nat { sz < 4294967296 } ) (#rrel #rel: _) (s: slice rrel rel) (pos pos' : U32.t) : Lemma (requires (valid_pos (parse_flbytes sz) h s pos pos')) (ensures (U32.v pos + sz == U32.v pos')) [SMTPat (valid_pos (parse_flbytes sz) h s pos pos')] = valid_facts (parse_flbytes sz) h s pos let valid_flbytes_elim (h: HS.mem) (sz: nat { sz < 4294967296 } ) (#rrel #rel: _) (s: slice rrel rel) (pos: U32.t) : Lemma (requires (valid (parse_flbytes sz) h s pos)) (ensures ( valid_content_pos (parse_flbytes sz) h s pos (BY.hide (bytes_of_slice_from_to h s pos (pos `U32.add` U32.uint_to_t sz))) (pos `U32.add` U32.uint_to_t sz) )) = valid_flbytes_intro h sz s pos let clens_flbytes_slice (sz: nat) (from: U32.t) (to: U32.t {U32.v from <= U32.v to /\ U32.v to <= sz } ) : Tot (clens (BY.lbytes sz) (BY.lbytes (U32.v to - U32.v from))) = { clens_cond = (fun _ -> True); clens_get = (fun (x: BY.lbytes sz) -> (BY.slice x from to <: BY.lbytes (U32.v to - U32.v from))); } #push-options "--z3rlimit 16" let gaccessor_flbytes_slice' (sz: nat { sz < 4294967296 } ) (from: U32.t) (to: U32.t {U32.v from <= U32.v to /\ U32.v to <= sz } ) : Tot (gaccessor' (parse_flbytes sz) (parse_flbytes (U32.v to - U32.v from)) (clens_flbytes_slice sz from to)) = fun (input: bytes) -> ( begin if Seq.length input < sz then (0) // dummy else (U32.v from) end) let gaccessor_flbytes_slice (sz: nat { sz < 4294967296 } ) (from: U32.t) (to: U32.t {U32.v from <= U32.v to /\ U32.v to <= sz } ) : Tot (gaccessor (parse_flbytes sz) (parse_flbytes (U32.v to - U32.v from)) (clens_flbytes_slice sz from to)) = assert (forall x . gaccessor_pre (parse_flbytes sz) (parse_flbytes (U32.v to - U32.v from)) (clens_flbytes_slice sz from to) x ==> sz <= Seq.length x); gaccessor_prop_equiv (parse_flbytes sz) (parse_flbytes (U32.v to - U32.v from)) (clens_flbytes_slice sz from to) (gaccessor_flbytes_slice' sz from to); gaccessor_flbytes_slice' sz from to inline_for_extraction let accessor_flbytes_slice (sz: nat { sz < 4294967296 } ) (from: U32.t) (to: U32.t {U32.v from <= U32.v to /\ U32.v to <= sz } ) : Tot (accessor (gaccessor_flbytes_slice sz from to)) = fun #rrel #rel input pos -> let h = HST.get () in [@inline_let] let _ = slice_access_eq h (gaccessor_flbytes_slice sz from to) input pos in pos `U32.add` from #pop-options let clens_flbytes_get (sz: nat) (i: U32.t { U32.v i < sz } ) : Tot (clens (BY.lbytes sz) byte) = { clens_cond = (fun _ -> True); clens_get = (fun (x: BY.lbytes sz) -> (BY.get x i <: byte)); } #push-options "--z3rlimit 16 --max_fuel 1" let gaccessor_flbytes_get' (sz: nat { sz < 4294967296 } ) (i: U32.t { U32.v i < sz } ) : Tot (gaccessor' (parse_flbytes sz) (parse_u8) (clens_flbytes_get sz i)) = fun (input: bytes) -> ( begin let res = if Seq.length input < U32.v i then (0) // dummy else (U32.v i) in let g () : Lemma (requires (gaccessor_pre (parse_flbytes sz) parse_u8 (clens_flbytes_get sz i) input)) (ensures (gaccessor_post (parse_flbytes sz) parse_u8 (clens_flbytes_get sz i) input res)) = parser_kind_prop_equiv (get_parser_kind parse_u8) parse_u8; assert (res == (U32.v i)); parse_u8_spec' (Seq.slice input (U32.v i) (U32.v i + 1)); parse_strong_prefix parse_u8 (Seq.slice input (U32.v i) (U32.v i + 1)) (Seq.slice input (U32.v i) (Seq.length input)) in Classical.move_requires g (); res end) #pop-options let gaccessor_flbytes_get (sz: nat { sz < 4294967296 } ) (i: U32.t { U32.v i < sz } ) : Tot (gaccessor (parse_flbytes sz) (parse_u8) (clens_flbytes_get sz i)) = assert (forall x . gaccessor_pre (parse_flbytes sz) (parse_u8) (clens_flbytes_get sz i) x ==> U32.v i <= Seq.length x); gaccessor_prop_equiv (parse_flbytes sz) (parse_u8) (clens_flbytes_get sz i) (gaccessor_flbytes_get' sz i); gaccessor_flbytes_get' sz i inline_for_extraction let accessor_flbytes_get (sz: nat { sz < 4294967296 } ) (i: U32.t { U32.v i < sz } ) : Tot (accessor (gaccessor_flbytes_get sz i)) = fun #rrel #rel input pos -> let h = HST.get () in [@inline_let] let _ = slice_access_eq h (gaccessor_flbytes_get sz i) input pos in pos `U32.add` i (* Temporary: flbytes as leaf values *) (* TODO: convert store_bytes to monotonic buffers, using the "writable" predicate *) #push-options "--z3rlimit 32" inline_for_extraction let store_bytes (src: BY.bytes) (src_from src_to: U32.t) (#rrel #rel: _) (dst: B.mbuffer byte rrel rel) (dst_pos: U32.t) : HST.Stack unit (requires (fun h -> B.live h dst /\ U32.v src_from <= U32.v src_to /\ U32.v src_to <= BY.length src /\ U32.v dst_pos + (U32.v src_to - U32.v src_from) <= B.length dst /\ writable dst (U32.v dst_pos) (U32.v dst_pos + (U32.v src_to - U32.v src_from)) h )) (ensures (fun h _ h' -> B.modifies (B.loc_buffer_from_to dst dst_pos (dst_pos `U32.add` (src_to `U32.sub` src_from))) h h' /\ Seq.slice (B.as_seq h' dst) (U32.v dst_pos) (U32.v dst_pos + (U32.v src_to - U32.v src_from)) == Seq.slice (BY.reveal src) (U32.v src_from) (U32.v src_to) )) = let h0 = HST.get () in HST.push_frame (); let h1 = HST.get () in let bi = BF.alloca 0ul 1ul in let h2 = HST.get () in let len = src_to `U32.sub` src_from in C.Loops.do_while (fun h stop -> B.modifies (B.loc_union (B.loc_region_only true (HS.get_tip h1)) (B.loc_buffer_from_to dst dst_pos (dst_pos `U32.add` len))) h2 h /\ B.live h bi /\ ( let i = Seq.index (B.as_seq h bi) 0 in U32.v i <= U32.v len /\ writable dst (U32.v dst_pos) (U32.v dst_pos + U32.v len) h /\ Seq.slice (B.as_seq h dst) (U32.v dst_pos) (U32.v dst_pos + U32.v i) `Seq.equal` Seq.slice (BY.reveal src) (U32.v src_from) (U32.v src_from + U32.v i) /\ (stop == true ==> i == len) )) (fun _ -> let i = B.index bi 0ul in if i = len then true else begin let x = BY.get src (src_from `U32.add` i) in mbuffer_upd dst (Ghost.hide (U32.v dst_pos)) (Ghost.hide (U32.v dst_pos + U32.v len)) (dst_pos `U32.add` i) x; let i' = i `U32.add` 1ul in B.upd bi 0ul i'; let h' = HST.get () in Seq.lemma_split (Seq.slice (B.as_seq h' dst) (U32.v dst_pos) (U32.v dst_pos + U32.v i')) (U32.v i); i' = len end ) ; HST.pop_frame () #pop-options inline_for_extraction let serialize32_flbytes (sz32: U32.t) : Tot (serializer32 (serialize_flbytes (U32.v sz32))) = fun (x: BY.lbytes (U32.v sz32)) #rrel #rel b pos -> let _ = store_bytes x 0ul sz32 b pos in sz32 inline_for_extraction let write_flbytes (sz32: U32.t) : Tot (leaf_writer_strong (serialize_flbytes (U32.v sz32))) = leaf_writer_strong_of_serializer32 (serialize32_flbytes sz32) () inline_for_extraction let write_flbytes_weak (sz32: U32.t { U32.v sz32 < 4294967295 } ) // need to return that value if output buffer is too small : Tot (leaf_writer_weak (serialize_flbytes (U32.v sz32))) = leaf_writer_weak_of_strong_constant_size (write_flbytes sz32) sz32 () (* // TODO: remove, since nobody is using this inline_for_extraction let read_flbytes (sz32: U32.t) : Tot (leaf_reader (parse_flbytes (U32.v sz32))) = fun input pos -> let h = HST.get () in [@inline_let] let _ = valid_facts (parse_flbytes (U32.v sz32)) h input pos in BY.of_buffer sz32 (B.sub input.base pos sz32) *) (* Equality test between a vlbytes and a constant lbytes *) #push-options "--z3rlimit 32" inline_for_extraction let buffer_equals_bytes (const: BY.bytes) (#rrel #rel: _) (b: B.mbuffer byte rrel rel) (pos: U32.t) : HST.Stack bool (requires (fun h -> B.live h b /\ U32.v pos + BY.length const <= B.length b )) (ensures (fun h res h' -> B.modifies B.loc_none h h' /\ (res == true <==> Seq.slice (B.as_seq h b) (U32.v pos) (U32.v pos + BY.length const) == BY.reveal const) )) = let h0 = HST.get () in HST.push_frame (); let len = BY.len const in let bi = BF.alloca 0ul 1ul in let bres = BF.alloca true 1ul in let h1 = HST.get () in [@inline_let] let inv (h: HS.mem) (stop: bool) : GTot Type0 = B.modifies (B.loc_union (B.loc_buffer bi) (B.loc_buffer bres)) h1 h /\ ( let length = U32.v len in let i32 = (Seq.index (B.as_seq h bi) 0) in let i = U32.v i32 in let res = Seq.index (B.as_seq h bres) 0 in i <= length /\ (stop == false ==> res == true) /\ ((stop == true /\ res == true) ==> i == length) /\ (res == true <==> Seq.slice (B.as_seq h b) (U32.v pos) (U32.v pos + i) `Seq.equal` Seq.slice (BY.reveal const) 0 i) ) in C.Loops.do_while inv (fun _ -> let i = B.index bi 0ul in if i = len then true else begin let i' = i `U32.add` 1ul in [@inline_let] let _ = let s1 = (Seq.slice (B.as_seq h0 b) (U32.v pos) (U32.v pos + U32.v i)) in let c1 = (B.get h0 b (U32.v pos + U32.v i)) in let s2 = (Seq.slice (BY.reveal const) 0 (U32.v i)) in let c2 = (BY.index const (U32.v i)) in assert (Seq.slice (B.as_seq h0 b) (U32.v pos) (U32.v pos + U32.v i') `Seq.equal` Seq.snoc s1 c1); assert (Seq.slice (BY.reveal const) 0 (U32.v i') `Seq.equal` Seq.snoc s2 c2); Classical.move_requires (Seq.lemma_snoc_inj s1 s2 c1) c2 in let res = B.index b (pos `U32.add` i) = BY.get const i in B.upd bres 0ul res; B.upd bi 0ul i'; not res end ); let res = B.index bres 0ul in HST.pop_frame (); res #pop-options inline_for_extraction let valid_slice_equals_bytes (const: BY.bytes) (#rrel #rel: _) (input: slice rrel rel) (pos: U32.t) : HST.Stack bool (requires (fun h -> valid (parse_flbytes (BY.length const)) h input pos )) (ensures (fun h res h' -> B.modifies B.loc_none h h' /\ (res == true <==> contents (parse_flbytes (BY.length const)) h input pos == const ))) = let h = HST.get () in [@inline_let] let _ = valid_facts (parse_flbytes (BY.length const)) h input pos in buffer_equals_bytes const input.base pos inline_for_extraction let validate_all_bytes () : Tot (validator parse_all_bytes) = fun #rrel #rel input pos -> let h = HST.get () in [@inline_let] let _ = valid_facts parse_all_bytes h input (uint64_to_uint32 pos) in Cast.uint32_to_uint64 input.len inline_for_extraction let validate_bounded_vlbytes' (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (l: nat { l >= log256' max /\ l <= 4 } ) : Tot (validator (parse_bounded_vlbytes' min max l)) = validate_synth (validate_bounded_vldata_strong' min max l serialize_all_bytes (validate_all_bytes ())) (synth_bounded_vlbytes min max) () inline_for_extraction let validate_bounded_vlbytes (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) : Tot (validator (parse_bounded_vlbytes min max)) = validate_bounded_vlbytes' min max (log256' max) inline_for_extraction let jump_all_bytes () : Tot (jumper parse_all_bytes) = fun #rrel #rel input pos -> let h = HST.get () in [@inline_let] let _ = valid_facts parse_all_bytes h input pos in input.len inline_for_extraction let jump_bounded_vlbytes' (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (l: nat { l >= log256' max /\ l <= 4 } ) : Tot (jumper (parse_bounded_vlbytes' min max l)) = jump_synth (jump_bounded_vldata_strong' min max l serialize_all_bytes) (synth_bounded_vlbytes min max) () inline_for_extraction let jump_bounded_vlbytes (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) : Tot (jumper (parse_bounded_vlbytes min max)) = jump_bounded_vlbytes' min max (log256' max) let valid_exact_all_bytes_elim (h: HS.mem) (#rrel #rel: _) (input: slice rrel rel) (pos pos' : U32.t) : Lemma (requires (valid_exact parse_all_bytes h input pos pos')) (ensures ( let x = contents_exact parse_all_bytes h input pos pos' in let length = U32.v pos' - U32.v pos in BY.length x == length /\ valid_content_pos (parse_flbytes length) h input pos x pos' )) = valid_exact_equiv parse_all_bytes h input pos pos' ; contents_exact_eq parse_all_bytes h input pos pos' ; let length = U32.v pos' - U32.v pos in valid_facts (parse_flbytes length) h input pos ; assert (no_lookahead_on (parse_flbytes length) (bytes_of_slice_from_to h input pos pos') (bytes_of_slice_from h input pos)); assert (injective_postcond (parse_flbytes length) (bytes_of_slice_from_to h input pos pos') (bytes_of_slice_from h input pos)) #push-options "--z3rlimit 32" let valid_bounded_vlbytes'_elim (h: HS.mem) (min: nat) (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (l: nat { l >= log256' max /\ l <= 4 } ) (#rrel #rel: _) (input: slice rrel rel) (pos: U32.t) : Lemma (requires ( valid (parse_bounded_vlbytes' min max l) h input pos )) (ensures ( let sz = l in valid (parse_bounded_integer sz) h input pos /\ ( let len_payload = contents (parse_bounded_integer sz) h input pos in min <= U32.v len_payload /\ U32.v len_payload <= max /\ sz + U32.v len_payload == content_length (parse_bounded_vlbytes' min max l) h input pos /\ ( let pos_payload = pos `U32.add` U32.uint_to_t sz in let x = contents (parse_bounded_vlbytes' min max l) h input pos in BY.len x == len_payload /\ valid_pos (parse_bounded_vlbytes' min max l) h input pos (pos_payload `U32.add` len_payload) /\ valid_content_pos (parse_flbytes (U32.v len_payload)) h input pos_payload x (pos_payload `U32.add` len_payload) )))) = valid_synth h (parse_bounded_vlbytes_aux min max l) (synth_bounded_vlbytes min max) input pos; valid_bounded_vldata_strong'_elim h min max l serialize_all_bytes input pos; let sz = l in let len_payload = contents (parse_bounded_integer sz) h input pos in let pos_payload = pos `U32.add` U32.uint_to_t sz in valid_exact_all_bytes_elim h input pos_payload (pos_payload `U32.add` len_payload); () #pop-options let valid_bounded_vlbytes_elim (h: HS.mem) (min: nat) (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (#rrel #rel: _) (input: slice rrel rel) (pos: U32.t) : Lemma (requires ( valid (parse_bounded_vlbytes min max) h input pos )) (ensures ( let sz = log256' max in valid (parse_bounded_integer sz) h input pos /\ ( let len_payload = contents (parse_bounded_integer sz) h input pos in min <= U32.v len_payload /\ U32.v len_payload <= max /\ sz + U32.v len_payload == content_length (parse_bounded_vlbytes min max) h input pos /\ ( let pos_payload = pos `U32.add` U32.uint_to_t sz in let x = contents (parse_bounded_vlbytes min max) h input pos in BY.len x == len_payload /\ valid_pos (parse_bounded_vlbytes min max) h input pos (pos_payload `U32.add` len_payload) /\ valid_content_pos (parse_flbytes (U32.v len_payload)) h input pos_payload x (pos_payload `U32.add` len_payload) )))) = valid_bounded_vlbytes'_elim h min max (log256' max) input pos let valid_bounded_vlbytes_elim_length (h: HS.mem) (min: nat) (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (#rrel #rel: _) (input: slice rrel rel) (pos: U32.t) : Lemma (requires ( valid (parse_bounded_vlbytes min max) h input pos )) (ensures ( content_length (parse_bounded_vlbytes min max) h input pos == log256' max + BY.length (contents (parse_bounded_vlbytes min max) h input pos) )) [SMTPat (valid (parse_bounded_vlbytes min max) h input pos)] = valid_bounded_vlbytes_elim h min max input pos inline_for_extraction let bounded_vlbytes'_payload_length (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (l: nat { l >= log256' max /\ l <= 4 } ) (#rrel #rel: _) (input: slice rrel rel) (pos: U32.t) : HST.Stack U32.t (requires (fun h -> valid (parse_bounded_vlbytes' min max l) h input pos)) (ensures (fun h len h' -> B.modifies B.loc_none h h' /\ U32.v pos + l + U32.v len <= U32.v input.len /\ ( let x = contents (parse_bounded_vlbytes' min max l) h input pos in let pos' = get_valid_pos (parse_bounded_vlbytes' min max l) h input pos in BY.len x == len /\ valid_content_pos (parse_flbytes (U32.v len)) h input (pos `U32.add` U32.uint_to_t l) x pos' /\ bytes_of_slice_from_to h input (pos `U32.add` U32.uint_to_t l) pos' == BY.reveal x ))) = let h = HST.get () in [@inline_let] let _ = valid_bounded_vlbytes'_elim h min max l input pos in let len = read_bounded_integer l input pos in [@inline_let] let _ = valid_flbytes_elim h (U32.v len) input (pos `U32.add` U32.uint_to_t l) in len
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowStar.Monotonic.Buffer.fsti.checked", "LowStar.Buffer.fst.checked", "LowParse.Spec.Bytes.fst.checked", "LowParse.Low.VLGen.fst.checked", "LowParse.Low.VLData.fst.checked", "LowParse.Low.Int.fsti.checked", "LowParse.Low.Combinators.fsti.checked", "LowParse.Bytes32.fst.checked", "FStar.UInt8.fsti.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Int.Cast.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked", "FStar.Classical.fsti.checked", "C.Loops.fst.checked" ], "interface_file": false, "source_file": "LowParse.Low.Bytes.fst" }
[ { "abbrev": true, "full_module": "LowStar.Buffer // for local variables in store_bytes", "short_module": "BF" }, { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "FStar.Int.Cast", "short_module": "Cast" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "LowParse.Bytes32", "short_module": "BY" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "BF" }, { "abbrev": true, "full_module": "LowStar.Monotonic.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": false, "full_module": "LowParse.Low.Int", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low.VLGen", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low.VLData", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low.Combinators", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec.Bytes", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
min: Prims.nat -> max: Prims.nat{min <= max /\ max > 0 /\ max < 4294967296} -> input: LowParse.Slice.slice rrel rel -> pos: FStar.UInt32.t -> FStar.HyperStack.ST.Stack FStar.UInt32.t
FStar.HyperStack.ST.Stack
[]
[]
[ "Prims.nat", "Prims.l_and", "Prims.b2t", "Prims.op_LessThanOrEqual", "Prims.op_GreaterThan", "Prims.op_LessThan", "LowParse.Slice.srel", "LowParse.Bytes.byte", "LowParse.Slice.slice", "FStar.UInt32.t", "LowParse.Low.Bytes.bounded_vlbytes'_payload_length", "LowParse.Spec.BoundedInt.log256'", "FStar.Monotonic.HyperStack.mem", "LowParse.Low.Base.Spec.valid", "LowParse.Spec.VLData.parse_bounded_vldata_strong_kind", "LowParse.Spec.Bytes.parse_all_bytes_kind", "LowParse.Spec.Bytes.parse_bounded_vlbytes_t", "LowParse.Spec.Bytes.parse_bounded_vlbytes", "LowStar.Monotonic.Buffer.modifies", "LowStar.Monotonic.Buffer.loc_none", "Prims.op_Addition", "FStar.UInt32.v", "LowParse.Slice.__proj__Mkslice__item__len", "Prims.eq2", "FStar.Bytes.len", "LowParse.Low.Base.Spec.valid_content_pos", "LowParse.Spec.Base.total_constant_size_parser_kind", "FStar.Bytes.lbytes", "LowParse.Spec.Bytes.parse_flbytes", "FStar.UInt32.add", "FStar.UInt32.uint_to_t", "FStar.Seq.Base.seq", "FStar.Bytes.byte", "LowParse.Low.Base.Spec.bytes_of_slice_from_to", "FStar.Bytes.reveal", "LowParse.Low.Base.Spec.get_valid_pos", "LowParse.Low.Base.Spec.contents" ]
[]
false
true
false
false
false
let bounded_vlbytes_payload_length (min: nat) (max: nat{min <= max /\ max > 0 /\ max < 4294967296}) (#rrel #rel: _) (input: slice rrel rel) (pos: U32.t) : HST.Stack U32.t (requires (fun h -> valid (parse_bounded_vlbytes min max) h input pos)) (ensures (fun h len h' -> B.modifies B.loc_none h h' /\ U32.v pos + log256' max + U32.v len <= U32.v input.len /\ (let x = contents (parse_bounded_vlbytes min max) h input pos in let pos' = get_valid_pos (parse_bounded_vlbytes min max) h input pos in BY.len x == len /\ valid_content_pos (parse_flbytes (U32.v len)) h input (pos `U32.add` (U32.uint_to_t (log256' max))) x pos' /\ bytes_of_slice_from_to h input (pos `U32.add` (U32.uint_to_t (log256' max))) pos' == BY.reveal x))) =
bounded_vlbytes'_payload_length min max (log256' max) input pos
false
Pulse.Syntax.Base.fsti
Pulse.Syntax.Base.with_range
val with_range : t: Pulse.Syntax.Base.term' -> r: Pulse.Syntax.Base.range -> Pulse.Syntax.Base.term
let with_range (t:term') (r:range) = { t; range=r }
{ "file_name": "lib/steel/pulse/Pulse.Syntax.Base.fsti", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 51, "end_line": 124, "start_col": 0, "start_line": 124 }
(* Copyright 2023 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module Pulse.Syntax.Base module RTB = FStar.Reflection.Typing.Builtins module RT = FStar.Reflection.Typing module R = FStar.Reflection.V2 module RU = Pulse.RuntimeUtils module T = FStar.Tactics.V2 open FStar.List.Tot type constant = R.vconst let var = nat let index = nat type universe = R.universe (* locally nameless. *) let range_singleton_trigger (r:FStar.Range.range) = True let range = r:FStar.Range.range { range_singleton_trigger r } let range_singleton (r:FStar.Range.range) : Lemma (ensures r == FStar.Range.range_0) [SMTPat (range_singleton_trigger r)] = FStar.Sealed.sealed_singl r FStar.Range.range_0 noeq type ppname = { name : RT.pp_name_t; range : range } let ppname_default = { name = FStar.Sealed.seal "_"; range = FStar.Range.range_0 } let mk_ppname (name:RT.pp_name_t) (range:FStar.Range.range) : ppname = { name = name; range = range } let mk_ppname_no_range (s:string) : ppname = { name = FStar.Sealed.seal s; range = FStar.Range.range_0; } noeq type bv = { bv_index : index; bv_ppname : ppname; } noeq type nm = { nm_index : var; nm_ppname : ppname; } type qualifier = | Implicit noeq type fv = { fv_name : R.name; fv_range : range; } let as_fv l = { fv_name = l; fv_range = FStar.Range.range_0 } let not_tv_unknown (t:R.term) = R.inspect_ln t =!= R.Tv_Unknown let host_term = t:R.term { not_tv_unknown t } [@@ no_auto_projectors] noeq type term' = | Tm_Emp : term' | Tm_Pure : p:term -> term' | Tm_Star : l:vprop -> r:vprop -> term' | Tm_ExistsSL : u:universe -> b:binder -> body:vprop -> term' | Tm_ForallSL : u:universe -> b:binder -> body:vprop -> term' | Tm_VProp : term' | Tm_Inv : vprop -> term' | Tm_Inames : term' // type inames | Tm_EmpInames : term' | Tm_AddInv : i:term -> is:term -> term' | Tm_FStar : host_term -> term' | Tm_Unknown : term' and vprop = term and typ = term and binder = { binder_ty : term; binder_ppname : ppname; binder_attrs : FStar.Sealed.Inhabited.sealed #(list term) [] } and term = { t : term'; range : range; } let binder_attrs_default = FStar.Sealed.seal [] let term_range (t:term) = t.range
{ "checked_file": "/", "dependencies": [ "Pulse.RuntimeUtils.fsti.checked", "Pulse.Reflection.Util.fst.checked", "prims.fst.checked", "FStar.Tactics.V2.fst.checked", "FStar.Sealed.Inhabited.fst.checked", "FStar.Sealed.fsti.checked", "FStar.Reflection.V2.fst.checked", "FStar.Reflection.Typing.Builtins.fsti.checked", "FStar.Reflection.Typing.fsti.checked", "FStar.Range.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked" ], "interface_file": false, "source_file": "Pulse.Syntax.Base.fsti" }
[ { "abbrev": false, "full_module": "FStar.List.Tot", "short_module": null }, { "abbrev": true, "full_module": "FStar.Tactics.V2", "short_module": "T" }, { "abbrev": true, "full_module": "Pulse.RuntimeUtils", "short_module": "RU" }, { "abbrev": true, "full_module": "FStar.Reflection.V2", "short_module": "R" }, { "abbrev": true, "full_module": "FStar.Reflection.Typing", "short_module": "RT" }, { "abbrev": true, "full_module": "FStar.Reflection.Typing.Builtins", "short_module": "RTB" }, { "abbrev": false, "full_module": "Pulse.Syntax", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Syntax", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": 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
t: Pulse.Syntax.Base.term' -> r: Pulse.Syntax.Base.range -> Pulse.Syntax.Base.term
Prims.Tot
[ "total" ]
[]
[ "Pulse.Syntax.Base.term'", "Pulse.Syntax.Base.range", "Pulse.Syntax.Base.Mkterm", "Pulse.Syntax.Base.term" ]
[]
false
false
false
true
false
let with_range (t: term') (r: range) =
{ t = t; range = r }
false
Pulse.Syntax.Base.fsti
Pulse.Syntax.Base.tm_fstar
val tm_fstar (t: host_term) (r: range) : term
val tm_fstar (t: host_term) (r: range) : term
let tm_fstar (t:host_term) (r:range) : term = { t = Tm_FStar t; range=r }
{ "file_name": "lib/steel/pulse/Pulse.Syntax.Base.fsti", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 73, "end_line": 123, "start_col": 0, "start_line": 123 }
(* Copyright 2023 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module Pulse.Syntax.Base module RTB = FStar.Reflection.Typing.Builtins module RT = FStar.Reflection.Typing module R = FStar.Reflection.V2 module RU = Pulse.RuntimeUtils module T = FStar.Tactics.V2 open FStar.List.Tot type constant = R.vconst let var = nat let index = nat type universe = R.universe (* locally nameless. *) let range_singleton_trigger (r:FStar.Range.range) = True let range = r:FStar.Range.range { range_singleton_trigger r } let range_singleton (r:FStar.Range.range) : Lemma (ensures r == FStar.Range.range_0) [SMTPat (range_singleton_trigger r)] = FStar.Sealed.sealed_singl r FStar.Range.range_0 noeq type ppname = { name : RT.pp_name_t; range : range } let ppname_default = { name = FStar.Sealed.seal "_"; range = FStar.Range.range_0 } let mk_ppname (name:RT.pp_name_t) (range:FStar.Range.range) : ppname = { name = name; range = range } let mk_ppname_no_range (s:string) : ppname = { name = FStar.Sealed.seal s; range = FStar.Range.range_0; } noeq type bv = { bv_index : index; bv_ppname : ppname; } noeq type nm = { nm_index : var; nm_ppname : ppname; } type qualifier = | Implicit noeq type fv = { fv_name : R.name; fv_range : range; } let as_fv l = { fv_name = l; fv_range = FStar.Range.range_0 } let not_tv_unknown (t:R.term) = R.inspect_ln t =!= R.Tv_Unknown let host_term = t:R.term { not_tv_unknown t } [@@ no_auto_projectors] noeq type term' = | Tm_Emp : term' | Tm_Pure : p:term -> term' | Tm_Star : l:vprop -> r:vprop -> term' | Tm_ExistsSL : u:universe -> b:binder -> body:vprop -> term' | Tm_ForallSL : u:universe -> b:binder -> body:vprop -> term' | Tm_VProp : term' | Tm_Inv : vprop -> term' | Tm_Inames : term' // type inames | Tm_EmpInames : term' | Tm_AddInv : i:term -> is:term -> term' | Tm_FStar : host_term -> term' | Tm_Unknown : term' and vprop = term and typ = term and binder = { binder_ty : term; binder_ppname : ppname; binder_attrs : FStar.Sealed.Inhabited.sealed #(list term) [] } and term = { t : term'; range : range; } let binder_attrs_default = FStar.Sealed.seal []
{ "checked_file": "/", "dependencies": [ "Pulse.RuntimeUtils.fsti.checked", "Pulse.Reflection.Util.fst.checked", "prims.fst.checked", "FStar.Tactics.V2.fst.checked", "FStar.Sealed.Inhabited.fst.checked", "FStar.Sealed.fsti.checked", "FStar.Reflection.V2.fst.checked", "FStar.Reflection.Typing.Builtins.fsti.checked", "FStar.Reflection.Typing.fsti.checked", "FStar.Range.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked" ], "interface_file": false, "source_file": "Pulse.Syntax.Base.fsti" }
[ { "abbrev": false, "full_module": "FStar.List.Tot", "short_module": null }, { "abbrev": true, "full_module": "FStar.Tactics.V2", "short_module": "T" }, { "abbrev": true, "full_module": "Pulse.RuntimeUtils", "short_module": "RU" }, { "abbrev": true, "full_module": "FStar.Reflection.V2", "short_module": "R" }, { "abbrev": true, "full_module": "FStar.Reflection.Typing", "short_module": "RT" }, { "abbrev": true, "full_module": "FStar.Reflection.Typing.Builtins", "short_module": "RTB" }, { "abbrev": false, "full_module": "Pulse.Syntax", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Syntax", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": 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
t: Pulse.Syntax.Base.host_term -> r: Pulse.Syntax.Base.range -> Pulse.Syntax.Base.term
Prims.Tot
[ "total" ]
[]
[ "Pulse.Syntax.Base.host_term", "Pulse.Syntax.Base.range", "Pulse.Syntax.Base.Mkterm", "Pulse.Syntax.Base.Tm_FStar", "Pulse.Syntax.Base.term" ]
[]
false
false
false
true
false
let tm_fstar (t: host_term) (r: range) : term =
{ t = Tm_FStar t; range = r }
false
Pulse.Syntax.Base.fsti
Pulse.Syntax.Base.term_range
val term_range : t: Pulse.Syntax.Base.term -> Pulse.Syntax.Base.range
let term_range (t:term) = t.range
{ "file_name": "lib/steel/pulse/Pulse.Syntax.Base.fsti", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 33, "end_line": 122, "start_col": 0, "start_line": 122 }
(* Copyright 2023 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module Pulse.Syntax.Base module RTB = FStar.Reflection.Typing.Builtins module RT = FStar.Reflection.Typing module R = FStar.Reflection.V2 module RU = Pulse.RuntimeUtils module T = FStar.Tactics.V2 open FStar.List.Tot type constant = R.vconst let var = nat let index = nat type universe = R.universe (* locally nameless. *) let range_singleton_trigger (r:FStar.Range.range) = True let range = r:FStar.Range.range { range_singleton_trigger r } let range_singleton (r:FStar.Range.range) : Lemma (ensures r == FStar.Range.range_0) [SMTPat (range_singleton_trigger r)] = FStar.Sealed.sealed_singl r FStar.Range.range_0 noeq type ppname = { name : RT.pp_name_t; range : range } let ppname_default = { name = FStar.Sealed.seal "_"; range = FStar.Range.range_0 } let mk_ppname (name:RT.pp_name_t) (range:FStar.Range.range) : ppname = { name = name; range = range } let mk_ppname_no_range (s:string) : ppname = { name = FStar.Sealed.seal s; range = FStar.Range.range_0; } noeq type bv = { bv_index : index; bv_ppname : ppname; } noeq type nm = { nm_index : var; nm_ppname : ppname; } type qualifier = | Implicit noeq type fv = { fv_name : R.name; fv_range : range; } let as_fv l = { fv_name = l; fv_range = FStar.Range.range_0 } let not_tv_unknown (t:R.term) = R.inspect_ln t =!= R.Tv_Unknown let host_term = t:R.term { not_tv_unknown t } [@@ no_auto_projectors] noeq type term' = | Tm_Emp : term' | Tm_Pure : p:term -> term' | Tm_Star : l:vprop -> r:vprop -> term' | Tm_ExistsSL : u:universe -> b:binder -> body:vprop -> term' | Tm_ForallSL : u:universe -> b:binder -> body:vprop -> term' | Tm_VProp : term' | Tm_Inv : vprop -> term' | Tm_Inames : term' // type inames | Tm_EmpInames : term' | Tm_AddInv : i:term -> is:term -> term' | Tm_FStar : host_term -> term' | Tm_Unknown : term' and vprop = term and typ = term and binder = { binder_ty : term; binder_ppname : ppname; binder_attrs : FStar.Sealed.Inhabited.sealed #(list term) [] } and term = { t : term'; range : range; } let binder_attrs_default = FStar.Sealed.seal []
{ "checked_file": "/", "dependencies": [ "Pulse.RuntimeUtils.fsti.checked", "Pulse.Reflection.Util.fst.checked", "prims.fst.checked", "FStar.Tactics.V2.fst.checked", "FStar.Sealed.Inhabited.fst.checked", "FStar.Sealed.fsti.checked", "FStar.Reflection.V2.fst.checked", "FStar.Reflection.Typing.Builtins.fsti.checked", "FStar.Reflection.Typing.fsti.checked", "FStar.Range.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked" ], "interface_file": false, "source_file": "Pulse.Syntax.Base.fsti" }
[ { "abbrev": false, "full_module": "FStar.List.Tot", "short_module": null }, { "abbrev": true, "full_module": "FStar.Tactics.V2", "short_module": "T" }, { "abbrev": true, "full_module": "Pulse.RuntimeUtils", "short_module": "RU" }, { "abbrev": true, "full_module": "FStar.Reflection.V2", "short_module": "R" }, { "abbrev": true, "full_module": "FStar.Reflection.Typing", "short_module": "RT" }, { "abbrev": true, "full_module": "FStar.Reflection.Typing.Builtins", "short_module": "RTB" }, { "abbrev": false, "full_module": "Pulse.Syntax", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Syntax", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": 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
t: Pulse.Syntax.Base.term -> Pulse.Syntax.Base.range
Prims.Tot
[ "total" ]
[]
[ "Pulse.Syntax.Base.term", "Pulse.Syntax.Base.__proj__Mkterm__item__range", "Pulse.Syntax.Base.range" ]
[]
false
false
false
true
false
let term_range (t: term) =
t.range
false
LowParse.Low.Bytes.fst
LowParse.Low.Bytes.gaccessor_vlbytes_slice
val gaccessor_vlbytes_slice (min: nat) (max: nat{min <= max /\ max > 0 /\ max < 4294967296}) (from: U32.t) (to: U32.t{U32.v from <= U32.v to /\ U32.v to <= max}) : Tot (gaccessor (parse_bounded_vlbytes min max) (parse_flbytes (U32.v to - U32.v from)) (clens_vlbytes_slice min max from to))
val gaccessor_vlbytes_slice (min: nat) (max: nat{min <= max /\ max > 0 /\ max < 4294967296}) (from: U32.t) (to: U32.t{U32.v from <= U32.v to /\ U32.v to <= max}) : Tot (gaccessor (parse_bounded_vlbytes min max) (parse_flbytes (U32.v to - U32.v from)) (clens_vlbytes_slice min max from to))
let gaccessor_vlbytes_slice (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (from: U32.t) (to: U32.t {U32.v from <= U32.v to /\ U32.v to <= max } ) : Tot (gaccessor (parse_bounded_vlbytes min max) (parse_flbytes (U32.v to - U32.v from)) (clens_vlbytes_slice min max from to)) = gaccessor_vlbytes'_slice min max (log256' max) from to
{ "file_name": "src/lowparse/LowParse.Low.Bytes.fst", "git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
{ "end_col": 56, "end_line": 730, "start_col": 0, "start_line": 724 }
module LowParse.Low.Bytes include LowParse.Spec.Bytes include LowParse.Low.Combinators include LowParse.Low.VLData include LowParse.Low.VLGen include LowParse.Low.Int module U32 = FStar.UInt32 module HS = FStar.HyperStack module B = LowStar.Monotonic.Buffer module BF = LowStar.Buffer // for local variables in store_bytes module BY = LowParse.Bytes32 module HST = FStar.HyperStack.ST module U8 = FStar.UInt8 module Cast = FStar.Int.Cast module U64 = FStar.UInt64 inline_for_extraction let validate_flbytes (sz: nat) (sz64: U64.t { U64.v sz64 == sz /\ sz < 4294967296 } ) : Tot (validator (parse_flbytes sz)) = validate_total_constant_size (parse_flbytes sz) sz64 () inline_for_extraction let jump_flbytes (sz: nat) (sz32: U32.t { U32.v sz32 == sz } ) : Tot (jumper (parse_flbytes sz)) = jump_constant_size (parse_flbytes sz) sz32 () let valid_flbytes_intro (h: HS.mem) (sz: nat { sz < 4294967296 } ) (#rrel #rel: _) (s: slice rrel rel) (pos: U32.t) : Lemma (requires (U32.v pos + sz <= U32.v s.len /\ live_slice h s)) (ensures ( valid_content_pos (parse_flbytes sz) h s pos (BY.hide (bytes_of_slice_from_to h s pos (pos `U32.add` U32.uint_to_t sz))) (pos `U32.add` U32.uint_to_t sz) )) = valid_facts (parse_flbytes sz) h s pos let valid_pos_flbytes_elim (h: HS.mem) (sz: nat { sz < 4294967296 } ) (#rrel #rel: _) (s: slice rrel rel) (pos pos' : U32.t) : Lemma (requires (valid_pos (parse_flbytes sz) h s pos pos')) (ensures (U32.v pos + sz == U32.v pos')) [SMTPat (valid_pos (parse_flbytes sz) h s pos pos')] = valid_facts (parse_flbytes sz) h s pos let valid_flbytes_elim (h: HS.mem) (sz: nat { sz < 4294967296 } ) (#rrel #rel: _) (s: slice rrel rel) (pos: U32.t) : Lemma (requires (valid (parse_flbytes sz) h s pos)) (ensures ( valid_content_pos (parse_flbytes sz) h s pos (BY.hide (bytes_of_slice_from_to h s pos (pos `U32.add` U32.uint_to_t sz))) (pos `U32.add` U32.uint_to_t sz) )) = valid_flbytes_intro h sz s pos let clens_flbytes_slice (sz: nat) (from: U32.t) (to: U32.t {U32.v from <= U32.v to /\ U32.v to <= sz } ) : Tot (clens (BY.lbytes sz) (BY.lbytes (U32.v to - U32.v from))) = { clens_cond = (fun _ -> True); clens_get = (fun (x: BY.lbytes sz) -> (BY.slice x from to <: BY.lbytes (U32.v to - U32.v from))); } #push-options "--z3rlimit 16" let gaccessor_flbytes_slice' (sz: nat { sz < 4294967296 } ) (from: U32.t) (to: U32.t {U32.v from <= U32.v to /\ U32.v to <= sz } ) : Tot (gaccessor' (parse_flbytes sz) (parse_flbytes (U32.v to - U32.v from)) (clens_flbytes_slice sz from to)) = fun (input: bytes) -> ( begin if Seq.length input < sz then (0) // dummy else (U32.v from) end) let gaccessor_flbytes_slice (sz: nat { sz < 4294967296 } ) (from: U32.t) (to: U32.t {U32.v from <= U32.v to /\ U32.v to <= sz } ) : Tot (gaccessor (parse_flbytes sz) (parse_flbytes (U32.v to - U32.v from)) (clens_flbytes_slice sz from to)) = assert (forall x . gaccessor_pre (parse_flbytes sz) (parse_flbytes (U32.v to - U32.v from)) (clens_flbytes_slice sz from to) x ==> sz <= Seq.length x); gaccessor_prop_equiv (parse_flbytes sz) (parse_flbytes (U32.v to - U32.v from)) (clens_flbytes_slice sz from to) (gaccessor_flbytes_slice' sz from to); gaccessor_flbytes_slice' sz from to inline_for_extraction let accessor_flbytes_slice (sz: nat { sz < 4294967296 } ) (from: U32.t) (to: U32.t {U32.v from <= U32.v to /\ U32.v to <= sz } ) : Tot (accessor (gaccessor_flbytes_slice sz from to)) = fun #rrel #rel input pos -> let h = HST.get () in [@inline_let] let _ = slice_access_eq h (gaccessor_flbytes_slice sz from to) input pos in pos `U32.add` from #pop-options let clens_flbytes_get (sz: nat) (i: U32.t { U32.v i < sz } ) : Tot (clens (BY.lbytes sz) byte) = { clens_cond = (fun _ -> True); clens_get = (fun (x: BY.lbytes sz) -> (BY.get x i <: byte)); } #push-options "--z3rlimit 16 --max_fuel 1" let gaccessor_flbytes_get' (sz: nat { sz < 4294967296 } ) (i: U32.t { U32.v i < sz } ) : Tot (gaccessor' (parse_flbytes sz) (parse_u8) (clens_flbytes_get sz i)) = fun (input: bytes) -> ( begin let res = if Seq.length input < U32.v i then (0) // dummy else (U32.v i) in let g () : Lemma (requires (gaccessor_pre (parse_flbytes sz) parse_u8 (clens_flbytes_get sz i) input)) (ensures (gaccessor_post (parse_flbytes sz) parse_u8 (clens_flbytes_get sz i) input res)) = parser_kind_prop_equiv (get_parser_kind parse_u8) parse_u8; assert (res == (U32.v i)); parse_u8_spec' (Seq.slice input (U32.v i) (U32.v i + 1)); parse_strong_prefix parse_u8 (Seq.slice input (U32.v i) (U32.v i + 1)) (Seq.slice input (U32.v i) (Seq.length input)) in Classical.move_requires g (); res end) #pop-options let gaccessor_flbytes_get (sz: nat { sz < 4294967296 } ) (i: U32.t { U32.v i < sz } ) : Tot (gaccessor (parse_flbytes sz) (parse_u8) (clens_flbytes_get sz i)) = assert (forall x . gaccessor_pre (parse_flbytes sz) (parse_u8) (clens_flbytes_get sz i) x ==> U32.v i <= Seq.length x); gaccessor_prop_equiv (parse_flbytes sz) (parse_u8) (clens_flbytes_get sz i) (gaccessor_flbytes_get' sz i); gaccessor_flbytes_get' sz i inline_for_extraction let accessor_flbytes_get (sz: nat { sz < 4294967296 } ) (i: U32.t { U32.v i < sz } ) : Tot (accessor (gaccessor_flbytes_get sz i)) = fun #rrel #rel input pos -> let h = HST.get () in [@inline_let] let _ = slice_access_eq h (gaccessor_flbytes_get sz i) input pos in pos `U32.add` i (* Temporary: flbytes as leaf values *) (* TODO: convert store_bytes to monotonic buffers, using the "writable" predicate *) #push-options "--z3rlimit 32" inline_for_extraction let store_bytes (src: BY.bytes) (src_from src_to: U32.t) (#rrel #rel: _) (dst: B.mbuffer byte rrel rel) (dst_pos: U32.t) : HST.Stack unit (requires (fun h -> B.live h dst /\ U32.v src_from <= U32.v src_to /\ U32.v src_to <= BY.length src /\ U32.v dst_pos + (U32.v src_to - U32.v src_from) <= B.length dst /\ writable dst (U32.v dst_pos) (U32.v dst_pos + (U32.v src_to - U32.v src_from)) h )) (ensures (fun h _ h' -> B.modifies (B.loc_buffer_from_to dst dst_pos (dst_pos `U32.add` (src_to `U32.sub` src_from))) h h' /\ Seq.slice (B.as_seq h' dst) (U32.v dst_pos) (U32.v dst_pos + (U32.v src_to - U32.v src_from)) == Seq.slice (BY.reveal src) (U32.v src_from) (U32.v src_to) )) = let h0 = HST.get () in HST.push_frame (); let h1 = HST.get () in let bi = BF.alloca 0ul 1ul in let h2 = HST.get () in let len = src_to `U32.sub` src_from in C.Loops.do_while (fun h stop -> B.modifies (B.loc_union (B.loc_region_only true (HS.get_tip h1)) (B.loc_buffer_from_to dst dst_pos (dst_pos `U32.add` len))) h2 h /\ B.live h bi /\ ( let i = Seq.index (B.as_seq h bi) 0 in U32.v i <= U32.v len /\ writable dst (U32.v dst_pos) (U32.v dst_pos + U32.v len) h /\ Seq.slice (B.as_seq h dst) (U32.v dst_pos) (U32.v dst_pos + U32.v i) `Seq.equal` Seq.slice (BY.reveal src) (U32.v src_from) (U32.v src_from + U32.v i) /\ (stop == true ==> i == len) )) (fun _ -> let i = B.index bi 0ul in if i = len then true else begin let x = BY.get src (src_from `U32.add` i) in mbuffer_upd dst (Ghost.hide (U32.v dst_pos)) (Ghost.hide (U32.v dst_pos + U32.v len)) (dst_pos `U32.add` i) x; let i' = i `U32.add` 1ul in B.upd bi 0ul i'; let h' = HST.get () in Seq.lemma_split (Seq.slice (B.as_seq h' dst) (U32.v dst_pos) (U32.v dst_pos + U32.v i')) (U32.v i); i' = len end ) ; HST.pop_frame () #pop-options inline_for_extraction let serialize32_flbytes (sz32: U32.t) : Tot (serializer32 (serialize_flbytes (U32.v sz32))) = fun (x: BY.lbytes (U32.v sz32)) #rrel #rel b pos -> let _ = store_bytes x 0ul sz32 b pos in sz32 inline_for_extraction let write_flbytes (sz32: U32.t) : Tot (leaf_writer_strong (serialize_flbytes (U32.v sz32))) = leaf_writer_strong_of_serializer32 (serialize32_flbytes sz32) () inline_for_extraction let write_flbytes_weak (sz32: U32.t { U32.v sz32 < 4294967295 } ) // need to return that value if output buffer is too small : Tot (leaf_writer_weak (serialize_flbytes (U32.v sz32))) = leaf_writer_weak_of_strong_constant_size (write_flbytes sz32) sz32 () (* // TODO: remove, since nobody is using this inline_for_extraction let read_flbytes (sz32: U32.t) : Tot (leaf_reader (parse_flbytes (U32.v sz32))) = fun input pos -> let h = HST.get () in [@inline_let] let _ = valid_facts (parse_flbytes (U32.v sz32)) h input pos in BY.of_buffer sz32 (B.sub input.base pos sz32) *) (* Equality test between a vlbytes and a constant lbytes *) #push-options "--z3rlimit 32" inline_for_extraction let buffer_equals_bytes (const: BY.bytes) (#rrel #rel: _) (b: B.mbuffer byte rrel rel) (pos: U32.t) : HST.Stack bool (requires (fun h -> B.live h b /\ U32.v pos + BY.length const <= B.length b )) (ensures (fun h res h' -> B.modifies B.loc_none h h' /\ (res == true <==> Seq.slice (B.as_seq h b) (U32.v pos) (U32.v pos + BY.length const) == BY.reveal const) )) = let h0 = HST.get () in HST.push_frame (); let len = BY.len const in let bi = BF.alloca 0ul 1ul in let bres = BF.alloca true 1ul in let h1 = HST.get () in [@inline_let] let inv (h: HS.mem) (stop: bool) : GTot Type0 = B.modifies (B.loc_union (B.loc_buffer bi) (B.loc_buffer bres)) h1 h /\ ( let length = U32.v len in let i32 = (Seq.index (B.as_seq h bi) 0) in let i = U32.v i32 in let res = Seq.index (B.as_seq h bres) 0 in i <= length /\ (stop == false ==> res == true) /\ ((stop == true /\ res == true) ==> i == length) /\ (res == true <==> Seq.slice (B.as_seq h b) (U32.v pos) (U32.v pos + i) `Seq.equal` Seq.slice (BY.reveal const) 0 i) ) in C.Loops.do_while inv (fun _ -> let i = B.index bi 0ul in if i = len then true else begin let i' = i `U32.add` 1ul in [@inline_let] let _ = let s1 = (Seq.slice (B.as_seq h0 b) (U32.v pos) (U32.v pos + U32.v i)) in let c1 = (B.get h0 b (U32.v pos + U32.v i)) in let s2 = (Seq.slice (BY.reveal const) 0 (U32.v i)) in let c2 = (BY.index const (U32.v i)) in assert (Seq.slice (B.as_seq h0 b) (U32.v pos) (U32.v pos + U32.v i') `Seq.equal` Seq.snoc s1 c1); assert (Seq.slice (BY.reveal const) 0 (U32.v i') `Seq.equal` Seq.snoc s2 c2); Classical.move_requires (Seq.lemma_snoc_inj s1 s2 c1) c2 in let res = B.index b (pos `U32.add` i) = BY.get const i in B.upd bres 0ul res; B.upd bi 0ul i'; not res end ); let res = B.index bres 0ul in HST.pop_frame (); res #pop-options inline_for_extraction let valid_slice_equals_bytes (const: BY.bytes) (#rrel #rel: _) (input: slice rrel rel) (pos: U32.t) : HST.Stack bool (requires (fun h -> valid (parse_flbytes (BY.length const)) h input pos )) (ensures (fun h res h' -> B.modifies B.loc_none h h' /\ (res == true <==> contents (parse_flbytes (BY.length const)) h input pos == const ))) = let h = HST.get () in [@inline_let] let _ = valid_facts (parse_flbytes (BY.length const)) h input pos in buffer_equals_bytes const input.base pos inline_for_extraction let validate_all_bytes () : Tot (validator parse_all_bytes) = fun #rrel #rel input pos -> let h = HST.get () in [@inline_let] let _ = valid_facts parse_all_bytes h input (uint64_to_uint32 pos) in Cast.uint32_to_uint64 input.len inline_for_extraction let validate_bounded_vlbytes' (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (l: nat { l >= log256' max /\ l <= 4 } ) : Tot (validator (parse_bounded_vlbytes' min max l)) = validate_synth (validate_bounded_vldata_strong' min max l serialize_all_bytes (validate_all_bytes ())) (synth_bounded_vlbytes min max) () inline_for_extraction let validate_bounded_vlbytes (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) : Tot (validator (parse_bounded_vlbytes min max)) = validate_bounded_vlbytes' min max (log256' max) inline_for_extraction let jump_all_bytes () : Tot (jumper parse_all_bytes) = fun #rrel #rel input pos -> let h = HST.get () in [@inline_let] let _ = valid_facts parse_all_bytes h input pos in input.len inline_for_extraction let jump_bounded_vlbytes' (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (l: nat { l >= log256' max /\ l <= 4 } ) : Tot (jumper (parse_bounded_vlbytes' min max l)) = jump_synth (jump_bounded_vldata_strong' min max l serialize_all_bytes) (synth_bounded_vlbytes min max) () inline_for_extraction let jump_bounded_vlbytes (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) : Tot (jumper (parse_bounded_vlbytes min max)) = jump_bounded_vlbytes' min max (log256' max) let valid_exact_all_bytes_elim (h: HS.mem) (#rrel #rel: _) (input: slice rrel rel) (pos pos' : U32.t) : Lemma (requires (valid_exact parse_all_bytes h input pos pos')) (ensures ( let x = contents_exact parse_all_bytes h input pos pos' in let length = U32.v pos' - U32.v pos in BY.length x == length /\ valid_content_pos (parse_flbytes length) h input pos x pos' )) = valid_exact_equiv parse_all_bytes h input pos pos' ; contents_exact_eq parse_all_bytes h input pos pos' ; let length = U32.v pos' - U32.v pos in valid_facts (parse_flbytes length) h input pos ; assert (no_lookahead_on (parse_flbytes length) (bytes_of_slice_from_to h input pos pos') (bytes_of_slice_from h input pos)); assert (injective_postcond (parse_flbytes length) (bytes_of_slice_from_to h input pos pos') (bytes_of_slice_from h input pos)) #push-options "--z3rlimit 32" let valid_bounded_vlbytes'_elim (h: HS.mem) (min: nat) (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (l: nat { l >= log256' max /\ l <= 4 } ) (#rrel #rel: _) (input: slice rrel rel) (pos: U32.t) : Lemma (requires ( valid (parse_bounded_vlbytes' min max l) h input pos )) (ensures ( let sz = l in valid (parse_bounded_integer sz) h input pos /\ ( let len_payload = contents (parse_bounded_integer sz) h input pos in min <= U32.v len_payload /\ U32.v len_payload <= max /\ sz + U32.v len_payload == content_length (parse_bounded_vlbytes' min max l) h input pos /\ ( let pos_payload = pos `U32.add` U32.uint_to_t sz in let x = contents (parse_bounded_vlbytes' min max l) h input pos in BY.len x == len_payload /\ valid_pos (parse_bounded_vlbytes' min max l) h input pos (pos_payload `U32.add` len_payload) /\ valid_content_pos (parse_flbytes (U32.v len_payload)) h input pos_payload x (pos_payload `U32.add` len_payload) )))) = valid_synth h (parse_bounded_vlbytes_aux min max l) (synth_bounded_vlbytes min max) input pos; valid_bounded_vldata_strong'_elim h min max l serialize_all_bytes input pos; let sz = l in let len_payload = contents (parse_bounded_integer sz) h input pos in let pos_payload = pos `U32.add` U32.uint_to_t sz in valid_exact_all_bytes_elim h input pos_payload (pos_payload `U32.add` len_payload); () #pop-options let valid_bounded_vlbytes_elim (h: HS.mem) (min: nat) (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (#rrel #rel: _) (input: slice rrel rel) (pos: U32.t) : Lemma (requires ( valid (parse_bounded_vlbytes min max) h input pos )) (ensures ( let sz = log256' max in valid (parse_bounded_integer sz) h input pos /\ ( let len_payload = contents (parse_bounded_integer sz) h input pos in min <= U32.v len_payload /\ U32.v len_payload <= max /\ sz + U32.v len_payload == content_length (parse_bounded_vlbytes min max) h input pos /\ ( let pos_payload = pos `U32.add` U32.uint_to_t sz in let x = contents (parse_bounded_vlbytes min max) h input pos in BY.len x == len_payload /\ valid_pos (parse_bounded_vlbytes min max) h input pos (pos_payload `U32.add` len_payload) /\ valid_content_pos (parse_flbytes (U32.v len_payload)) h input pos_payload x (pos_payload `U32.add` len_payload) )))) = valid_bounded_vlbytes'_elim h min max (log256' max) input pos let valid_bounded_vlbytes_elim_length (h: HS.mem) (min: nat) (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (#rrel #rel: _) (input: slice rrel rel) (pos: U32.t) : Lemma (requires ( valid (parse_bounded_vlbytes min max) h input pos )) (ensures ( content_length (parse_bounded_vlbytes min max) h input pos == log256' max + BY.length (contents (parse_bounded_vlbytes min max) h input pos) )) [SMTPat (valid (parse_bounded_vlbytes min max) h input pos)] = valid_bounded_vlbytes_elim h min max input pos inline_for_extraction let bounded_vlbytes'_payload_length (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (l: nat { l >= log256' max /\ l <= 4 } ) (#rrel #rel: _) (input: slice rrel rel) (pos: U32.t) : HST.Stack U32.t (requires (fun h -> valid (parse_bounded_vlbytes' min max l) h input pos)) (ensures (fun h len h' -> B.modifies B.loc_none h h' /\ U32.v pos + l + U32.v len <= U32.v input.len /\ ( let x = contents (parse_bounded_vlbytes' min max l) h input pos in let pos' = get_valid_pos (parse_bounded_vlbytes' min max l) h input pos in BY.len x == len /\ valid_content_pos (parse_flbytes (U32.v len)) h input (pos `U32.add` U32.uint_to_t l) x pos' /\ bytes_of_slice_from_to h input (pos `U32.add` U32.uint_to_t l) pos' == BY.reveal x ))) = let h = HST.get () in [@inline_let] let _ = valid_bounded_vlbytes'_elim h min max l input pos in let len = read_bounded_integer l input pos in [@inline_let] let _ = valid_flbytes_elim h (U32.v len) input (pos `U32.add` U32.uint_to_t l) in len inline_for_extraction let bounded_vlbytes_payload_length (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (#rrel #rel: _) (input: slice rrel rel) (pos: U32.t) : HST.Stack U32.t (requires (fun h -> valid (parse_bounded_vlbytes min max) h input pos)) (ensures (fun h len h' -> B.modifies B.loc_none h h' /\ U32.v pos + log256' max + U32.v len <= U32.v input.len /\ ( let x = contents (parse_bounded_vlbytes min max) h input pos in let pos' = get_valid_pos (parse_bounded_vlbytes min max) h input pos in BY.len x == len /\ valid_content_pos (parse_flbytes (U32.v len)) h input (pos `U32.add` U32.uint_to_t (log256' max)) x pos' /\ bytes_of_slice_from_to h input (pos `U32.add` U32.uint_to_t (log256' max)) pos' == BY.reveal x ))) = bounded_vlbytes'_payload_length min max (log256' max) input pos (* Get the content buffer (with trivial buffers only, not generalizable to monotonicity) *) #push-options "--z3rlimit 32" inline_for_extraction let get_vlbytes'_contents (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (l: nat { l >= log256' max /\ l <= 4 } ) (input: slice (srel_of_buffer_srel (BF.trivial_preorder _)) (srel_of_buffer_srel (BF.trivial_preorder _))) (pos: U32.t) : HST.Stack (BF.buffer byte) (requires (fun h -> valid (parse_bounded_vlbytes' min max l) h input pos)) (ensures (fun h b h' -> let x = contents (parse_bounded_vlbytes' min max l) h input pos in B.modifies B.loc_none h h' /\ U32.v pos + l + BY.length x <= U32.v input.len /\ b == BF.gsub input.base (pos `U32.add` U32.uint_to_t l) (BY.len x) /\ B.as_seq h b == BY.reveal x )) = let h = HST.get () in [@inline_let] let _ = valid_bounded_vlbytes'_elim h min max l input pos in let len = read_bounded_integer l input pos in [@inline_let] let _ = valid_facts (parse_flbytes (U32.v len)) h input (pos `U32.add` U32.uint_to_t l) in BF.sub input.base (pos `U32.add` U32.uint_to_t l) len #pop-options inline_for_extraction let get_vlbytes_contents (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (input: slice (srel_of_buffer_srel (BF.trivial_preorder _)) (srel_of_buffer_srel (BF.trivial_preorder _))) (pos: U32.t) : HST.Stack (BF.buffer byte) (requires (fun h -> valid (parse_bounded_vlbytes min max) h input pos)) (ensures (fun h b h' -> let l = log256' max in let x = contents (parse_bounded_vlbytes min max) h input pos in B.modifies B.loc_none h h' /\ U32.v pos + l + BY.length x <= U32.v input.len /\ b == BF.gsub input.base (pos `U32.add` U32.uint_to_t l) (BY.len x) /\ B.as_seq h b == BY.reveal x )) = get_vlbytes'_contents min max (log256' max) input pos (* In fact, the following accessors are not useful in practice, because users would need to have the flbytes parser combinator in their scope *) let clens_vlbytes_cond (min: nat) (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (length: nat) (x: parse_bounded_vlbytes_t min max) : GTot Type0 = BY.length x == length let clens_vlbytes (min: nat) (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (length: nat) : Tot (clens (parse_bounded_vlbytes_t min max) (BY.lbytes length)) = { clens_cond = (clens_vlbytes_cond min max length); clens_get = (fun (x: parse_bounded_vlbytes_t min max) -> (x <: Ghost (BY.lbytes length) (requires (clens_vlbytes_cond min max length x)) (ensures (fun _ -> True)))); } #push-options "--z3rlimit 16 --max_fuel 2 --initial_fuel 2 --max_ifuel 6 --initial_ifuel 6" let gaccessor_vlbytes'_aux (min: nat) (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (l: nat { l >= log256' max /\ l <= 4 } ) (length: nat { length < 4294967296 } ) : Tot (gaccessor' (parse_bounded_vlbytes' min max l) (parse_flbytes length) (clens_vlbytes min max length)) = fun (input: bytes) -> (begin let res = if Seq.length input >= l then (l) else (0) in let g () : Lemma (requires (gaccessor_pre (parse_bounded_vlbytes' min max l) (parse_flbytes length) (clens_vlbytes min max length) input)) (ensures (gaccessor_post (parse_bounded_vlbytes' min max l) (parse_flbytes length) (clens_vlbytes min max length) input res)) = parse_bounded_vlbytes_eq min max l input; parse_strong_prefix (parse_flbytes length) (Seq.slice input l (l + length)) (Seq.slice input l (Seq.length input)) in Classical.move_requires g (); res end) let gaccessor_vlbytes' (min: nat) (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (l: nat { l >= log256' max /\ l <= 4 } ) (length: nat { length < 4294967296 } ) : Tot (gaccessor (parse_bounded_vlbytes' min max l) (parse_flbytes length) (clens_vlbytes min max length)) = parser_kind_prop_equiv (parse_bounded_vldata_strong_kind min max l parse_all_bytes_kind) (parse_bounded_vlbytes' min max l); assert (forall x . gaccessor_pre (parse_bounded_vlbytes' min max l) (parse_flbytes length) (clens_vlbytes min max length) x ==> Seq.length x >= l); gaccessor_prop_equiv (parse_bounded_vlbytes' min max l) (parse_flbytes length) (clens_vlbytes min max length) (gaccessor_vlbytes'_aux min max l length); gaccessor_vlbytes'_aux min max l length #pop-options let gaccessor_vlbytes (min: nat) (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (length: nat { length < 4294967296 } ) : Tot (gaccessor (parse_bounded_vlbytes min max) (parse_flbytes length) (clens_vlbytes min max length)) = gaccessor_vlbytes' min max (log256' max) length #push-options "--z3rlimit 64 --max_fuel 2 --initial_fuel 2 --max_ifuel 6 --initial_ifuel 6" inline_for_extraction let accessor_vlbytes' (min: nat) (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (l: nat { l >= log256' max /\ l <= 4 } ) (length: U32.t) : Tot (accessor (gaccessor_vlbytes' min max l (U32.v length))) = fun #rrel #rel sl pos -> let h = HST.get () in [@inline_let] let _ = slice_access_eq h (gaccessor_vlbytes' min max l (U32.v length)) sl pos; valid_bounded_vlbytes'_elim h min max l sl pos; parse_bounded_vlbytes_eq min max l (bytes_of_slice_from h sl pos) in pos `U32.add` U32.uint_to_t l #pop-options inline_for_extraction let accessor_vlbytes (min: nat) (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (length: U32.t) : Tot (accessor (gaccessor_vlbytes min max (U32.v length))) = accessor_vlbytes' min max (log256' max) length let clens_vlbytes_slice (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (from: U32.t) (to: U32.t {U32.v from <= U32.v to /\ U32.v to <= max } ) : Tot (clens (parse_bounded_vlbytes_t min max) (BY.lbytes (U32.v to - U32.v from))) = { clens_cond = (fun (x: parse_bounded_vlbytes_t min max) -> U32.v to <= BY.length x); clens_get = (fun (x: parse_bounded_vlbytes_t min max) -> (BY.slice x from to <: BY.lbytes (U32.v to - U32.v from))); } #push-options "--z3rlimit 16" let gaccessor_vlbytes'_slice_aux (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (l: nat { l >= log256' max /\ l <= 4 } ) (from: U32.t) (to: U32.t {U32.v from <= U32.v to /\ U32.v to <= max } ) : Tot (gaccessor' (parse_bounded_vlbytes' min max l) (parse_flbytes (U32.v to - U32.v from)) (clens_vlbytes_slice min max from to)) = fun (input: bytes) -> ( begin parse_bounded_vlbytes_eq min max l input; if Seq.length input < l + U32.v to then (0) // dummy else (l + U32.v from) end) let gaccessor_vlbytes'_slice (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (l: nat { l >= log256' max /\ l <= 4 } ) (from: U32.t) (to: U32.t {U32.v from <= U32.v to /\ U32.v to <= max } ) : Tot (gaccessor (parse_bounded_vlbytes' min max l) (parse_flbytes (U32.v to - U32.v from)) (clens_vlbytes_slice min max from to)) = parser_kind_prop_equiv (parse_bounded_vldata_strong_kind min max l parse_all_bytes_kind) (parse_bounded_vlbytes' min max l); Classical.forall_intro (parse_bounded_vlbytes_eq min max l); assert (forall x . gaccessor_pre (parse_bounded_vlbytes' min max l) (parse_flbytes (U32.v to - U32.v from)) (clens_vlbytes_slice min max from to) x ==> l + U32.v to <= Seq.length x); gaccessor_prop_equiv (parse_bounded_vlbytes' min max l) (parse_flbytes (U32.v to - U32.v from)) (clens_vlbytes_slice min max from to) (gaccessor_vlbytes'_slice_aux min max l from to); gaccessor_vlbytes'_slice_aux min max l from to
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowStar.Monotonic.Buffer.fsti.checked", "LowStar.Buffer.fst.checked", "LowParse.Spec.Bytes.fst.checked", "LowParse.Low.VLGen.fst.checked", "LowParse.Low.VLData.fst.checked", "LowParse.Low.Int.fsti.checked", "LowParse.Low.Combinators.fsti.checked", "LowParse.Bytes32.fst.checked", "FStar.UInt8.fsti.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Int.Cast.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked", "FStar.Classical.fsti.checked", "C.Loops.fst.checked" ], "interface_file": false, "source_file": "LowParse.Low.Bytes.fst" }
[ { "abbrev": true, "full_module": "LowStar.Buffer // for local variables in store_bytes", "short_module": "BF" }, { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "FStar.Int.Cast", "short_module": "Cast" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "LowParse.Bytes32", "short_module": "BY" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "BF" }, { "abbrev": true, "full_module": "LowStar.Monotonic.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": false, "full_module": "LowParse.Low.Int", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low.VLGen", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low.VLData", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low.Combinators", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec.Bytes", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 16, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
min: Prims.nat -> max: Prims.nat{min <= max /\ max > 0 /\ max < 4294967296} -> from: FStar.UInt32.t -> to: FStar.UInt32.t{FStar.UInt32.v from <= FStar.UInt32.v to /\ FStar.UInt32.v to <= max} -> LowParse.Low.Base.Spec.gaccessor (LowParse.Spec.Bytes.parse_bounded_vlbytes min max) (LowParse.Spec.Bytes.parse_flbytes (FStar.UInt32.v to - FStar.UInt32.v from)) (LowParse.Low.Bytes.clens_vlbytes_slice min max from to)
Prims.Tot
[ "total" ]
[]
[ "Prims.nat", "Prims.l_and", "Prims.b2t", "Prims.op_LessThanOrEqual", "Prims.op_GreaterThan", "Prims.op_LessThan", "FStar.UInt32.t", "FStar.UInt32.v", "LowParse.Low.Bytes.gaccessor_vlbytes'_slice", "LowParse.Spec.BoundedInt.log256'", "LowParse.Low.Base.Spec.gaccessor", "LowParse.Spec.VLData.parse_bounded_vldata_strong_kind", "LowParse.Spec.Bytes.parse_all_bytes_kind", "LowParse.Spec.Bytes.parse_bounded_vlbytes_t", "LowParse.Spec.Bytes.parse_bounded_vlbytes", "LowParse.Spec.Base.total_constant_size_parser_kind", "Prims.op_Subtraction", "FStar.Bytes.lbytes", "LowParse.Spec.Bytes.parse_flbytes", "LowParse.Low.Bytes.clens_vlbytes_slice" ]
[]
false
false
false
false
false
let gaccessor_vlbytes_slice (min: nat) (max: nat{min <= max /\ max > 0 /\ max < 4294967296}) (from: U32.t) (to: U32.t{U32.v from <= U32.v to /\ U32.v to <= max}) : Tot (gaccessor (parse_bounded_vlbytes min max) (parse_flbytes (U32.v to - U32.v from)) (clens_vlbytes_slice min max from to)) =
gaccessor_vlbytes'_slice min max (log256' max) from to
false
LowParse.Low.Bytes.fst
LowParse.Low.Bytes.get_vlbytes_contents
val get_vlbytes_contents (min: nat) (max: nat{min <= max /\ max > 0 /\ max < 4294967296}) (input: slice (srel_of_buffer_srel (BF.trivial_preorder _)) (srel_of_buffer_srel (BF.trivial_preorder _))) (pos: U32.t) : HST.Stack (BF.buffer byte) (requires (fun h -> valid (parse_bounded_vlbytes min max) h input pos)) (ensures (fun h b h' -> let l = log256' max in let x = contents (parse_bounded_vlbytes min max) h input pos in B.modifies B.loc_none h h' /\ U32.v pos + l + BY.length x <= U32.v input.len /\ b == BF.gsub input.base (pos `U32.add` (U32.uint_to_t l)) (BY.len x) /\ B.as_seq h b == BY.reveal x))
val get_vlbytes_contents (min: nat) (max: nat{min <= max /\ max > 0 /\ max < 4294967296}) (input: slice (srel_of_buffer_srel (BF.trivial_preorder _)) (srel_of_buffer_srel (BF.trivial_preorder _))) (pos: U32.t) : HST.Stack (BF.buffer byte) (requires (fun h -> valid (parse_bounded_vlbytes min max) h input pos)) (ensures (fun h b h' -> let l = log256' max in let x = contents (parse_bounded_vlbytes min max) h input pos in B.modifies B.loc_none h h' /\ U32.v pos + l + BY.length x <= U32.v input.len /\ b == BF.gsub input.base (pos `U32.add` (U32.uint_to_t l)) (BY.len x) /\ B.as_seq h b == BY.reveal x))
let get_vlbytes_contents (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (input: slice (srel_of_buffer_srel (BF.trivial_preorder _)) (srel_of_buffer_srel (BF.trivial_preorder _))) (pos: U32.t) : HST.Stack (BF.buffer byte) (requires (fun h -> valid (parse_bounded_vlbytes min max) h input pos)) (ensures (fun h b h' -> let l = log256' max in let x = contents (parse_bounded_vlbytes min max) h input pos in B.modifies B.loc_none h h' /\ U32.v pos + l + BY.length x <= U32.v input.len /\ b == BF.gsub input.base (pos `U32.add` U32.uint_to_t l) (BY.len x) /\ B.as_seq h b == BY.reveal x )) = get_vlbytes'_contents min max (log256' max) input pos
{ "file_name": "src/lowparse/LowParse.Low.Bytes.fst", "git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
{ "end_col": 55, "end_line": 586, "start_col": 0, "start_line": 571 }
module LowParse.Low.Bytes include LowParse.Spec.Bytes include LowParse.Low.Combinators include LowParse.Low.VLData include LowParse.Low.VLGen include LowParse.Low.Int module U32 = FStar.UInt32 module HS = FStar.HyperStack module B = LowStar.Monotonic.Buffer module BF = LowStar.Buffer // for local variables in store_bytes module BY = LowParse.Bytes32 module HST = FStar.HyperStack.ST module U8 = FStar.UInt8 module Cast = FStar.Int.Cast module U64 = FStar.UInt64 inline_for_extraction let validate_flbytes (sz: nat) (sz64: U64.t { U64.v sz64 == sz /\ sz < 4294967296 } ) : Tot (validator (parse_flbytes sz)) = validate_total_constant_size (parse_flbytes sz) sz64 () inline_for_extraction let jump_flbytes (sz: nat) (sz32: U32.t { U32.v sz32 == sz } ) : Tot (jumper (parse_flbytes sz)) = jump_constant_size (parse_flbytes sz) sz32 () let valid_flbytes_intro (h: HS.mem) (sz: nat { sz < 4294967296 } ) (#rrel #rel: _) (s: slice rrel rel) (pos: U32.t) : Lemma (requires (U32.v pos + sz <= U32.v s.len /\ live_slice h s)) (ensures ( valid_content_pos (parse_flbytes sz) h s pos (BY.hide (bytes_of_slice_from_to h s pos (pos `U32.add` U32.uint_to_t sz))) (pos `U32.add` U32.uint_to_t sz) )) = valid_facts (parse_flbytes sz) h s pos let valid_pos_flbytes_elim (h: HS.mem) (sz: nat { sz < 4294967296 } ) (#rrel #rel: _) (s: slice rrel rel) (pos pos' : U32.t) : Lemma (requires (valid_pos (parse_flbytes sz) h s pos pos')) (ensures (U32.v pos + sz == U32.v pos')) [SMTPat (valid_pos (parse_flbytes sz) h s pos pos')] = valid_facts (parse_flbytes sz) h s pos let valid_flbytes_elim (h: HS.mem) (sz: nat { sz < 4294967296 } ) (#rrel #rel: _) (s: slice rrel rel) (pos: U32.t) : Lemma (requires (valid (parse_flbytes sz) h s pos)) (ensures ( valid_content_pos (parse_flbytes sz) h s pos (BY.hide (bytes_of_slice_from_to h s pos (pos `U32.add` U32.uint_to_t sz))) (pos `U32.add` U32.uint_to_t sz) )) = valid_flbytes_intro h sz s pos let clens_flbytes_slice (sz: nat) (from: U32.t) (to: U32.t {U32.v from <= U32.v to /\ U32.v to <= sz } ) : Tot (clens (BY.lbytes sz) (BY.lbytes (U32.v to - U32.v from))) = { clens_cond = (fun _ -> True); clens_get = (fun (x: BY.lbytes sz) -> (BY.slice x from to <: BY.lbytes (U32.v to - U32.v from))); } #push-options "--z3rlimit 16" let gaccessor_flbytes_slice' (sz: nat { sz < 4294967296 } ) (from: U32.t) (to: U32.t {U32.v from <= U32.v to /\ U32.v to <= sz } ) : Tot (gaccessor' (parse_flbytes sz) (parse_flbytes (U32.v to - U32.v from)) (clens_flbytes_slice sz from to)) = fun (input: bytes) -> ( begin if Seq.length input < sz then (0) // dummy else (U32.v from) end) let gaccessor_flbytes_slice (sz: nat { sz < 4294967296 } ) (from: U32.t) (to: U32.t {U32.v from <= U32.v to /\ U32.v to <= sz } ) : Tot (gaccessor (parse_flbytes sz) (parse_flbytes (U32.v to - U32.v from)) (clens_flbytes_slice sz from to)) = assert (forall x . gaccessor_pre (parse_flbytes sz) (parse_flbytes (U32.v to - U32.v from)) (clens_flbytes_slice sz from to) x ==> sz <= Seq.length x); gaccessor_prop_equiv (parse_flbytes sz) (parse_flbytes (U32.v to - U32.v from)) (clens_flbytes_slice sz from to) (gaccessor_flbytes_slice' sz from to); gaccessor_flbytes_slice' sz from to inline_for_extraction let accessor_flbytes_slice (sz: nat { sz < 4294967296 } ) (from: U32.t) (to: U32.t {U32.v from <= U32.v to /\ U32.v to <= sz } ) : Tot (accessor (gaccessor_flbytes_slice sz from to)) = fun #rrel #rel input pos -> let h = HST.get () in [@inline_let] let _ = slice_access_eq h (gaccessor_flbytes_slice sz from to) input pos in pos `U32.add` from #pop-options let clens_flbytes_get (sz: nat) (i: U32.t { U32.v i < sz } ) : Tot (clens (BY.lbytes sz) byte) = { clens_cond = (fun _ -> True); clens_get = (fun (x: BY.lbytes sz) -> (BY.get x i <: byte)); } #push-options "--z3rlimit 16 --max_fuel 1" let gaccessor_flbytes_get' (sz: nat { sz < 4294967296 } ) (i: U32.t { U32.v i < sz } ) : Tot (gaccessor' (parse_flbytes sz) (parse_u8) (clens_flbytes_get sz i)) = fun (input: bytes) -> ( begin let res = if Seq.length input < U32.v i then (0) // dummy else (U32.v i) in let g () : Lemma (requires (gaccessor_pre (parse_flbytes sz) parse_u8 (clens_flbytes_get sz i) input)) (ensures (gaccessor_post (parse_flbytes sz) parse_u8 (clens_flbytes_get sz i) input res)) = parser_kind_prop_equiv (get_parser_kind parse_u8) parse_u8; assert (res == (U32.v i)); parse_u8_spec' (Seq.slice input (U32.v i) (U32.v i + 1)); parse_strong_prefix parse_u8 (Seq.slice input (U32.v i) (U32.v i + 1)) (Seq.slice input (U32.v i) (Seq.length input)) in Classical.move_requires g (); res end) #pop-options let gaccessor_flbytes_get (sz: nat { sz < 4294967296 } ) (i: U32.t { U32.v i < sz } ) : Tot (gaccessor (parse_flbytes sz) (parse_u8) (clens_flbytes_get sz i)) = assert (forall x . gaccessor_pre (parse_flbytes sz) (parse_u8) (clens_flbytes_get sz i) x ==> U32.v i <= Seq.length x); gaccessor_prop_equiv (parse_flbytes sz) (parse_u8) (clens_flbytes_get sz i) (gaccessor_flbytes_get' sz i); gaccessor_flbytes_get' sz i inline_for_extraction let accessor_flbytes_get (sz: nat { sz < 4294967296 } ) (i: U32.t { U32.v i < sz } ) : Tot (accessor (gaccessor_flbytes_get sz i)) = fun #rrel #rel input pos -> let h = HST.get () in [@inline_let] let _ = slice_access_eq h (gaccessor_flbytes_get sz i) input pos in pos `U32.add` i (* Temporary: flbytes as leaf values *) (* TODO: convert store_bytes to monotonic buffers, using the "writable" predicate *) #push-options "--z3rlimit 32" inline_for_extraction let store_bytes (src: BY.bytes) (src_from src_to: U32.t) (#rrel #rel: _) (dst: B.mbuffer byte rrel rel) (dst_pos: U32.t) : HST.Stack unit (requires (fun h -> B.live h dst /\ U32.v src_from <= U32.v src_to /\ U32.v src_to <= BY.length src /\ U32.v dst_pos + (U32.v src_to - U32.v src_from) <= B.length dst /\ writable dst (U32.v dst_pos) (U32.v dst_pos + (U32.v src_to - U32.v src_from)) h )) (ensures (fun h _ h' -> B.modifies (B.loc_buffer_from_to dst dst_pos (dst_pos `U32.add` (src_to `U32.sub` src_from))) h h' /\ Seq.slice (B.as_seq h' dst) (U32.v dst_pos) (U32.v dst_pos + (U32.v src_to - U32.v src_from)) == Seq.slice (BY.reveal src) (U32.v src_from) (U32.v src_to) )) = let h0 = HST.get () in HST.push_frame (); let h1 = HST.get () in let bi = BF.alloca 0ul 1ul in let h2 = HST.get () in let len = src_to `U32.sub` src_from in C.Loops.do_while (fun h stop -> B.modifies (B.loc_union (B.loc_region_only true (HS.get_tip h1)) (B.loc_buffer_from_to dst dst_pos (dst_pos `U32.add` len))) h2 h /\ B.live h bi /\ ( let i = Seq.index (B.as_seq h bi) 0 in U32.v i <= U32.v len /\ writable dst (U32.v dst_pos) (U32.v dst_pos + U32.v len) h /\ Seq.slice (B.as_seq h dst) (U32.v dst_pos) (U32.v dst_pos + U32.v i) `Seq.equal` Seq.slice (BY.reveal src) (U32.v src_from) (U32.v src_from + U32.v i) /\ (stop == true ==> i == len) )) (fun _ -> let i = B.index bi 0ul in if i = len then true else begin let x = BY.get src (src_from `U32.add` i) in mbuffer_upd dst (Ghost.hide (U32.v dst_pos)) (Ghost.hide (U32.v dst_pos + U32.v len)) (dst_pos `U32.add` i) x; let i' = i `U32.add` 1ul in B.upd bi 0ul i'; let h' = HST.get () in Seq.lemma_split (Seq.slice (B.as_seq h' dst) (U32.v dst_pos) (U32.v dst_pos + U32.v i')) (U32.v i); i' = len end ) ; HST.pop_frame () #pop-options inline_for_extraction let serialize32_flbytes (sz32: U32.t) : Tot (serializer32 (serialize_flbytes (U32.v sz32))) = fun (x: BY.lbytes (U32.v sz32)) #rrel #rel b pos -> let _ = store_bytes x 0ul sz32 b pos in sz32 inline_for_extraction let write_flbytes (sz32: U32.t) : Tot (leaf_writer_strong (serialize_flbytes (U32.v sz32))) = leaf_writer_strong_of_serializer32 (serialize32_flbytes sz32) () inline_for_extraction let write_flbytes_weak (sz32: U32.t { U32.v sz32 < 4294967295 } ) // need to return that value if output buffer is too small : Tot (leaf_writer_weak (serialize_flbytes (U32.v sz32))) = leaf_writer_weak_of_strong_constant_size (write_flbytes sz32) sz32 () (* // TODO: remove, since nobody is using this inline_for_extraction let read_flbytes (sz32: U32.t) : Tot (leaf_reader (parse_flbytes (U32.v sz32))) = fun input pos -> let h = HST.get () in [@inline_let] let _ = valid_facts (parse_flbytes (U32.v sz32)) h input pos in BY.of_buffer sz32 (B.sub input.base pos sz32) *) (* Equality test between a vlbytes and a constant lbytes *) #push-options "--z3rlimit 32" inline_for_extraction let buffer_equals_bytes (const: BY.bytes) (#rrel #rel: _) (b: B.mbuffer byte rrel rel) (pos: U32.t) : HST.Stack bool (requires (fun h -> B.live h b /\ U32.v pos + BY.length const <= B.length b )) (ensures (fun h res h' -> B.modifies B.loc_none h h' /\ (res == true <==> Seq.slice (B.as_seq h b) (U32.v pos) (U32.v pos + BY.length const) == BY.reveal const) )) = let h0 = HST.get () in HST.push_frame (); let len = BY.len const in let bi = BF.alloca 0ul 1ul in let bres = BF.alloca true 1ul in let h1 = HST.get () in [@inline_let] let inv (h: HS.mem) (stop: bool) : GTot Type0 = B.modifies (B.loc_union (B.loc_buffer bi) (B.loc_buffer bres)) h1 h /\ ( let length = U32.v len in let i32 = (Seq.index (B.as_seq h bi) 0) in let i = U32.v i32 in let res = Seq.index (B.as_seq h bres) 0 in i <= length /\ (stop == false ==> res == true) /\ ((stop == true /\ res == true) ==> i == length) /\ (res == true <==> Seq.slice (B.as_seq h b) (U32.v pos) (U32.v pos + i) `Seq.equal` Seq.slice (BY.reveal const) 0 i) ) in C.Loops.do_while inv (fun _ -> let i = B.index bi 0ul in if i = len then true else begin let i' = i `U32.add` 1ul in [@inline_let] let _ = let s1 = (Seq.slice (B.as_seq h0 b) (U32.v pos) (U32.v pos + U32.v i)) in let c1 = (B.get h0 b (U32.v pos + U32.v i)) in let s2 = (Seq.slice (BY.reveal const) 0 (U32.v i)) in let c2 = (BY.index const (U32.v i)) in assert (Seq.slice (B.as_seq h0 b) (U32.v pos) (U32.v pos + U32.v i') `Seq.equal` Seq.snoc s1 c1); assert (Seq.slice (BY.reveal const) 0 (U32.v i') `Seq.equal` Seq.snoc s2 c2); Classical.move_requires (Seq.lemma_snoc_inj s1 s2 c1) c2 in let res = B.index b (pos `U32.add` i) = BY.get const i in B.upd bres 0ul res; B.upd bi 0ul i'; not res end ); let res = B.index bres 0ul in HST.pop_frame (); res #pop-options inline_for_extraction let valid_slice_equals_bytes (const: BY.bytes) (#rrel #rel: _) (input: slice rrel rel) (pos: U32.t) : HST.Stack bool (requires (fun h -> valid (parse_flbytes (BY.length const)) h input pos )) (ensures (fun h res h' -> B.modifies B.loc_none h h' /\ (res == true <==> contents (parse_flbytes (BY.length const)) h input pos == const ))) = let h = HST.get () in [@inline_let] let _ = valid_facts (parse_flbytes (BY.length const)) h input pos in buffer_equals_bytes const input.base pos inline_for_extraction let validate_all_bytes () : Tot (validator parse_all_bytes) = fun #rrel #rel input pos -> let h = HST.get () in [@inline_let] let _ = valid_facts parse_all_bytes h input (uint64_to_uint32 pos) in Cast.uint32_to_uint64 input.len inline_for_extraction let validate_bounded_vlbytes' (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (l: nat { l >= log256' max /\ l <= 4 } ) : Tot (validator (parse_bounded_vlbytes' min max l)) = validate_synth (validate_bounded_vldata_strong' min max l serialize_all_bytes (validate_all_bytes ())) (synth_bounded_vlbytes min max) () inline_for_extraction let validate_bounded_vlbytes (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) : Tot (validator (parse_bounded_vlbytes min max)) = validate_bounded_vlbytes' min max (log256' max) inline_for_extraction let jump_all_bytes () : Tot (jumper parse_all_bytes) = fun #rrel #rel input pos -> let h = HST.get () in [@inline_let] let _ = valid_facts parse_all_bytes h input pos in input.len inline_for_extraction let jump_bounded_vlbytes' (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (l: nat { l >= log256' max /\ l <= 4 } ) : Tot (jumper (parse_bounded_vlbytes' min max l)) = jump_synth (jump_bounded_vldata_strong' min max l serialize_all_bytes) (synth_bounded_vlbytes min max) () inline_for_extraction let jump_bounded_vlbytes (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) : Tot (jumper (parse_bounded_vlbytes min max)) = jump_bounded_vlbytes' min max (log256' max) let valid_exact_all_bytes_elim (h: HS.mem) (#rrel #rel: _) (input: slice rrel rel) (pos pos' : U32.t) : Lemma (requires (valid_exact parse_all_bytes h input pos pos')) (ensures ( let x = contents_exact parse_all_bytes h input pos pos' in let length = U32.v pos' - U32.v pos in BY.length x == length /\ valid_content_pos (parse_flbytes length) h input pos x pos' )) = valid_exact_equiv parse_all_bytes h input pos pos' ; contents_exact_eq parse_all_bytes h input pos pos' ; let length = U32.v pos' - U32.v pos in valid_facts (parse_flbytes length) h input pos ; assert (no_lookahead_on (parse_flbytes length) (bytes_of_slice_from_to h input pos pos') (bytes_of_slice_from h input pos)); assert (injective_postcond (parse_flbytes length) (bytes_of_slice_from_to h input pos pos') (bytes_of_slice_from h input pos)) #push-options "--z3rlimit 32" let valid_bounded_vlbytes'_elim (h: HS.mem) (min: nat) (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (l: nat { l >= log256' max /\ l <= 4 } ) (#rrel #rel: _) (input: slice rrel rel) (pos: U32.t) : Lemma (requires ( valid (parse_bounded_vlbytes' min max l) h input pos )) (ensures ( let sz = l in valid (parse_bounded_integer sz) h input pos /\ ( let len_payload = contents (parse_bounded_integer sz) h input pos in min <= U32.v len_payload /\ U32.v len_payload <= max /\ sz + U32.v len_payload == content_length (parse_bounded_vlbytes' min max l) h input pos /\ ( let pos_payload = pos `U32.add` U32.uint_to_t sz in let x = contents (parse_bounded_vlbytes' min max l) h input pos in BY.len x == len_payload /\ valid_pos (parse_bounded_vlbytes' min max l) h input pos (pos_payload `U32.add` len_payload) /\ valid_content_pos (parse_flbytes (U32.v len_payload)) h input pos_payload x (pos_payload `U32.add` len_payload) )))) = valid_synth h (parse_bounded_vlbytes_aux min max l) (synth_bounded_vlbytes min max) input pos; valid_bounded_vldata_strong'_elim h min max l serialize_all_bytes input pos; let sz = l in let len_payload = contents (parse_bounded_integer sz) h input pos in let pos_payload = pos `U32.add` U32.uint_to_t sz in valid_exact_all_bytes_elim h input pos_payload (pos_payload `U32.add` len_payload); () #pop-options let valid_bounded_vlbytes_elim (h: HS.mem) (min: nat) (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (#rrel #rel: _) (input: slice rrel rel) (pos: U32.t) : Lemma (requires ( valid (parse_bounded_vlbytes min max) h input pos )) (ensures ( let sz = log256' max in valid (parse_bounded_integer sz) h input pos /\ ( let len_payload = contents (parse_bounded_integer sz) h input pos in min <= U32.v len_payload /\ U32.v len_payload <= max /\ sz + U32.v len_payload == content_length (parse_bounded_vlbytes min max) h input pos /\ ( let pos_payload = pos `U32.add` U32.uint_to_t sz in let x = contents (parse_bounded_vlbytes min max) h input pos in BY.len x == len_payload /\ valid_pos (parse_bounded_vlbytes min max) h input pos (pos_payload `U32.add` len_payload) /\ valid_content_pos (parse_flbytes (U32.v len_payload)) h input pos_payload x (pos_payload `U32.add` len_payload) )))) = valid_bounded_vlbytes'_elim h min max (log256' max) input pos let valid_bounded_vlbytes_elim_length (h: HS.mem) (min: nat) (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (#rrel #rel: _) (input: slice rrel rel) (pos: U32.t) : Lemma (requires ( valid (parse_bounded_vlbytes min max) h input pos )) (ensures ( content_length (parse_bounded_vlbytes min max) h input pos == log256' max + BY.length (contents (parse_bounded_vlbytes min max) h input pos) )) [SMTPat (valid (parse_bounded_vlbytes min max) h input pos)] = valid_bounded_vlbytes_elim h min max input pos inline_for_extraction let bounded_vlbytes'_payload_length (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (l: nat { l >= log256' max /\ l <= 4 } ) (#rrel #rel: _) (input: slice rrel rel) (pos: U32.t) : HST.Stack U32.t (requires (fun h -> valid (parse_bounded_vlbytes' min max l) h input pos)) (ensures (fun h len h' -> B.modifies B.loc_none h h' /\ U32.v pos + l + U32.v len <= U32.v input.len /\ ( let x = contents (parse_bounded_vlbytes' min max l) h input pos in let pos' = get_valid_pos (parse_bounded_vlbytes' min max l) h input pos in BY.len x == len /\ valid_content_pos (parse_flbytes (U32.v len)) h input (pos `U32.add` U32.uint_to_t l) x pos' /\ bytes_of_slice_from_to h input (pos `U32.add` U32.uint_to_t l) pos' == BY.reveal x ))) = let h = HST.get () in [@inline_let] let _ = valid_bounded_vlbytes'_elim h min max l input pos in let len = read_bounded_integer l input pos in [@inline_let] let _ = valid_flbytes_elim h (U32.v len) input (pos `U32.add` U32.uint_to_t l) in len inline_for_extraction let bounded_vlbytes_payload_length (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (#rrel #rel: _) (input: slice rrel rel) (pos: U32.t) : HST.Stack U32.t (requires (fun h -> valid (parse_bounded_vlbytes min max) h input pos)) (ensures (fun h len h' -> B.modifies B.loc_none h h' /\ U32.v pos + log256' max + U32.v len <= U32.v input.len /\ ( let x = contents (parse_bounded_vlbytes min max) h input pos in let pos' = get_valid_pos (parse_bounded_vlbytes min max) h input pos in BY.len x == len /\ valid_content_pos (parse_flbytes (U32.v len)) h input (pos `U32.add` U32.uint_to_t (log256' max)) x pos' /\ bytes_of_slice_from_to h input (pos `U32.add` U32.uint_to_t (log256' max)) pos' == BY.reveal x ))) = bounded_vlbytes'_payload_length min max (log256' max) input pos (* Get the content buffer (with trivial buffers only, not generalizable to monotonicity) *) #push-options "--z3rlimit 32" inline_for_extraction let get_vlbytes'_contents (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (l: nat { l >= log256' max /\ l <= 4 } ) (input: slice (srel_of_buffer_srel (BF.trivial_preorder _)) (srel_of_buffer_srel (BF.trivial_preorder _))) (pos: U32.t) : HST.Stack (BF.buffer byte) (requires (fun h -> valid (parse_bounded_vlbytes' min max l) h input pos)) (ensures (fun h b h' -> let x = contents (parse_bounded_vlbytes' min max l) h input pos in B.modifies B.loc_none h h' /\ U32.v pos + l + BY.length x <= U32.v input.len /\ b == BF.gsub input.base (pos `U32.add` U32.uint_to_t l) (BY.len x) /\ B.as_seq h b == BY.reveal x )) = let h = HST.get () in [@inline_let] let _ = valid_bounded_vlbytes'_elim h min max l input pos in let len = read_bounded_integer l input pos in [@inline_let] let _ = valid_facts (parse_flbytes (U32.v len)) h input (pos `U32.add` U32.uint_to_t l) in BF.sub input.base (pos `U32.add` U32.uint_to_t l) len #pop-options
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowStar.Monotonic.Buffer.fsti.checked", "LowStar.Buffer.fst.checked", "LowParse.Spec.Bytes.fst.checked", "LowParse.Low.VLGen.fst.checked", "LowParse.Low.VLData.fst.checked", "LowParse.Low.Int.fsti.checked", "LowParse.Low.Combinators.fsti.checked", "LowParse.Bytes32.fst.checked", "FStar.UInt8.fsti.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Int.Cast.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked", "FStar.Classical.fsti.checked", "C.Loops.fst.checked" ], "interface_file": false, "source_file": "LowParse.Low.Bytes.fst" }
[ { "abbrev": true, "full_module": "LowStar.Buffer // for local variables in store_bytes", "short_module": "BF" }, { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "FStar.Int.Cast", "short_module": "Cast" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "LowParse.Bytes32", "short_module": "BY" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "BF" }, { "abbrev": true, "full_module": "LowStar.Monotonic.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": false, "full_module": "LowParse.Low.Int", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low.VLGen", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low.VLData", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low.Combinators", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec.Bytes", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
min: Prims.nat -> max: Prims.nat{min <= max /\ max > 0 /\ max < 4294967296} -> input: LowParse.Slice.slice (LowParse.Slice.srel_of_buffer_srel (LowStar.Buffer.trivial_preorder LowParse.Bytes.byte )) (LowParse.Slice.srel_of_buffer_srel (LowStar.Buffer.trivial_preorder LowParse.Bytes.byte)) -> pos: FStar.UInt32.t -> FStar.HyperStack.ST.Stack (LowStar.Buffer.buffer LowParse.Bytes.byte)
FStar.HyperStack.ST.Stack
[]
[]
[ "Prims.nat", "Prims.l_and", "Prims.b2t", "Prims.op_LessThanOrEqual", "Prims.op_GreaterThan", "Prims.op_LessThan", "LowParse.Slice.slice", "LowParse.Slice.srel_of_buffer_srel", "LowParse.Bytes.byte", "LowStar.Buffer.trivial_preorder", "FStar.UInt32.t", "LowParse.Low.Bytes.get_vlbytes'_contents", "LowParse.Spec.BoundedInt.log256'", "LowStar.Buffer.buffer", "FStar.Monotonic.HyperStack.mem", "LowParse.Low.Base.Spec.valid", "LowParse.Spec.VLData.parse_bounded_vldata_strong_kind", "LowParse.Spec.Bytes.parse_all_bytes_kind", "LowParse.Spec.Bytes.parse_bounded_vlbytes_t", "LowParse.Spec.Bytes.parse_bounded_vlbytes", "LowStar.Monotonic.Buffer.modifies", "LowStar.Monotonic.Buffer.loc_none", "Prims.op_Addition", "FStar.UInt32.v", "FStar.Bytes.length", "LowParse.Slice.__proj__Mkslice__item__len", "Prims.eq2", "LowStar.Monotonic.Buffer.mbuffer", "LowStar.Buffer.gsub", "LowParse.Slice.__proj__Mkslice__item__base", "FStar.UInt32.add", "FStar.UInt32.uint_to_t", "FStar.Bytes.len", "FStar.Seq.Base.seq", "FStar.Bytes.byte", "LowStar.Monotonic.Buffer.as_seq", "FStar.Bytes.reveal", "LowParse.Low.Base.Spec.contents", "LowParse.Spec.BoundedInt.integer_size" ]
[]
false
true
false
false
false
let get_vlbytes_contents (min: nat) (max: nat{min <= max /\ max > 0 /\ max < 4294967296}) (input: slice (srel_of_buffer_srel (BF.trivial_preorder _)) (srel_of_buffer_srel (BF.trivial_preorder _))) (pos: U32.t) : HST.Stack (BF.buffer byte) (requires (fun h -> valid (parse_bounded_vlbytes min max) h input pos)) (ensures (fun h b h' -> let l = log256' max in let x = contents (parse_bounded_vlbytes min max) h input pos in B.modifies B.loc_none h h' /\ U32.v pos + l + BY.length x <= U32.v input.len /\ b == BF.gsub input.base (pos `U32.add` (U32.uint_to_t l)) (BY.len x) /\ B.as_seq h b == BY.reveal x)) =
get_vlbytes'_contents min max (log256' max) input pos
false
Pulse.Syntax.Base.fsti
Pulse.Syntax.Base.range_singleton
val range_singleton (r: FStar.Range.range) : Lemma (ensures r == FStar.Range.range_0) [SMTPat (range_singleton_trigger r)]
val range_singleton (r: FStar.Range.range) : Lemma (ensures r == FStar.Range.range_0) [SMTPat (range_singleton_trigger r)]
let range_singleton (r:FStar.Range.range) : Lemma (ensures r == FStar.Range.range_0) [SMTPat (range_singleton_trigger r)] = FStar.Sealed.sealed_singl r FStar.Range.range_0
{ "file_name": "lib/steel/pulse/Pulse.Syntax.Base.fsti", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 51, "end_line": 39, "start_col": 0, "start_line": 35 }
(* Copyright 2023 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module Pulse.Syntax.Base module RTB = FStar.Reflection.Typing.Builtins module RT = FStar.Reflection.Typing module R = FStar.Reflection.V2 module RU = Pulse.RuntimeUtils module T = FStar.Tactics.V2 open FStar.List.Tot type constant = R.vconst let var = nat let index = nat type universe = R.universe (* locally nameless. *) let range_singleton_trigger (r:FStar.Range.range) = True
{ "checked_file": "/", "dependencies": [ "Pulse.RuntimeUtils.fsti.checked", "Pulse.Reflection.Util.fst.checked", "prims.fst.checked", "FStar.Tactics.V2.fst.checked", "FStar.Sealed.Inhabited.fst.checked", "FStar.Sealed.fsti.checked", "FStar.Reflection.V2.fst.checked", "FStar.Reflection.Typing.Builtins.fsti.checked", "FStar.Reflection.Typing.fsti.checked", "FStar.Range.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked" ], "interface_file": false, "source_file": "Pulse.Syntax.Base.fsti" }
[ { "abbrev": false, "full_module": "FStar.List.Tot", "short_module": null }, { "abbrev": true, "full_module": "FStar.Tactics.V2", "short_module": "T" }, { "abbrev": true, "full_module": "Pulse.RuntimeUtils", "short_module": "RU" }, { "abbrev": true, "full_module": "FStar.Reflection.V2", "short_module": "R" }, { "abbrev": true, "full_module": "FStar.Reflection.Typing", "short_module": "RT" }, { "abbrev": true, "full_module": "FStar.Reflection.Typing.Builtins", "short_module": "RTB" }, { "abbrev": false, "full_module": "Pulse.Syntax", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Syntax", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
r: FStar.Range.range -> FStar.Pervasives.Lemma (ensures r == FStar.Range.range_0) [SMTPat (Pulse.Syntax.Base.range_singleton_trigger r)]
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "FStar.Range.range", "FStar.Sealed.sealed_singl", "FStar.Range.__range", "FStar.Range.range_0", "Prims.unit", "Prims.l_True", "Prims.squash", "Prims.eq2", "Prims.Cons", "FStar.Pervasives.pattern", "FStar.Pervasives.smt_pat", "Prims.logical", "Pulse.Syntax.Base.range_singleton_trigger", "Prims.Nil" ]
[]
true
false
true
false
false
let range_singleton (r: FStar.Range.range) : Lemma (ensures r == FStar.Range.range_0) [SMTPat (range_singleton_trigger r)] =
FStar.Sealed.sealed_singl r FStar.Range.range_0
false
Pulse.Syntax.Base.fsti
Pulse.Syntax.Base.tm_pure
val tm_pure (p: term) : term
val tm_pure (p: term) : term
let tm_pure (p:term) : term = { t = Tm_Pure p; range = p.range }
{ "file_name": "lib/steel/pulse/Pulse.Syntax.Base.fsti", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 64, "end_line": 131, "start_col": 0, "start_line": 131 }
(* Copyright 2023 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module Pulse.Syntax.Base module RTB = FStar.Reflection.Typing.Builtins module RT = FStar.Reflection.Typing module R = FStar.Reflection.V2 module RU = Pulse.RuntimeUtils module T = FStar.Tactics.V2 open FStar.List.Tot type constant = R.vconst let var = nat let index = nat type universe = R.universe (* locally nameless. *) let range_singleton_trigger (r:FStar.Range.range) = True let range = r:FStar.Range.range { range_singleton_trigger r } let range_singleton (r:FStar.Range.range) : Lemma (ensures r == FStar.Range.range_0) [SMTPat (range_singleton_trigger r)] = FStar.Sealed.sealed_singl r FStar.Range.range_0 noeq type ppname = { name : RT.pp_name_t; range : range } let ppname_default = { name = FStar.Sealed.seal "_"; range = FStar.Range.range_0 } let mk_ppname (name:RT.pp_name_t) (range:FStar.Range.range) : ppname = { name = name; range = range } let mk_ppname_no_range (s:string) : ppname = { name = FStar.Sealed.seal s; range = FStar.Range.range_0; } noeq type bv = { bv_index : index; bv_ppname : ppname; } noeq type nm = { nm_index : var; nm_ppname : ppname; } type qualifier = | Implicit noeq type fv = { fv_name : R.name; fv_range : range; } let as_fv l = { fv_name = l; fv_range = FStar.Range.range_0 } let not_tv_unknown (t:R.term) = R.inspect_ln t =!= R.Tv_Unknown let host_term = t:R.term { not_tv_unknown t } [@@ no_auto_projectors] noeq type term' = | Tm_Emp : term' | Tm_Pure : p:term -> term' | Tm_Star : l:vprop -> r:vprop -> term' | Tm_ExistsSL : u:universe -> b:binder -> body:vprop -> term' | Tm_ForallSL : u:universe -> b:binder -> body:vprop -> term' | Tm_VProp : term' | Tm_Inv : vprop -> term' | Tm_Inames : term' // type inames | Tm_EmpInames : term' | Tm_AddInv : i:term -> is:term -> term' | Tm_FStar : host_term -> term' | Tm_Unknown : term' and vprop = term and typ = term and binder = { binder_ty : term; binder_ppname : ppname; binder_attrs : FStar.Sealed.Inhabited.sealed #(list term) [] } and term = { t : term'; range : range; } let binder_attrs_default = FStar.Sealed.seal [] let term_range (t:term) = t.range let tm_fstar (t:host_term) (r:range) : term = { t = Tm_FStar t; range=r } let with_range (t:term') (r:range) = { t; range=r } let tm_vprop = with_range Tm_VProp FStar.Range.range_0 let tm_inv p = with_range (Tm_Inv p) FStar.Range.range_0 let tm_inames = with_range Tm_Inames FStar.Range.range_0 let tm_emp = with_range Tm_Emp FStar.Range.range_0 let tm_emp_inames = with_range Tm_EmpInames FStar.Range.range_0
{ "checked_file": "/", "dependencies": [ "Pulse.RuntimeUtils.fsti.checked", "Pulse.Reflection.Util.fst.checked", "prims.fst.checked", "FStar.Tactics.V2.fst.checked", "FStar.Sealed.Inhabited.fst.checked", "FStar.Sealed.fsti.checked", "FStar.Reflection.V2.fst.checked", "FStar.Reflection.Typing.Builtins.fsti.checked", "FStar.Reflection.Typing.fsti.checked", "FStar.Range.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked" ], "interface_file": false, "source_file": "Pulse.Syntax.Base.fsti" }
[ { "abbrev": false, "full_module": "FStar.List.Tot", "short_module": null }, { "abbrev": true, "full_module": "FStar.Tactics.V2", "short_module": "T" }, { "abbrev": true, "full_module": "Pulse.RuntimeUtils", "short_module": "RU" }, { "abbrev": true, "full_module": "FStar.Reflection.V2", "short_module": "R" }, { "abbrev": true, "full_module": "FStar.Reflection.Typing", "short_module": "RT" }, { "abbrev": true, "full_module": "FStar.Reflection.Typing.Builtins", "short_module": "RTB" }, { "abbrev": false, "full_module": "Pulse.Syntax", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Syntax", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
p: Pulse.Syntax.Base.term -> Pulse.Syntax.Base.term
Prims.Tot
[ "total" ]
[]
[ "Pulse.Syntax.Base.term", "Pulse.Syntax.Base.Mkterm", "Pulse.Syntax.Base.Tm_Pure", "Pulse.Syntax.Base.__proj__Mkterm__item__range" ]
[]
false
false
false
true
false
let tm_pure (p: term) : term =
{ t = Tm_Pure p; range = p.range }
false
Pulse.Syntax.Base.fsti
Pulse.Syntax.Base.mk_ppname
val mk_ppname (name: RT.pp_name_t) (range: FStar.Range.range) : ppname
val mk_ppname (name: RT.pp_name_t) (range: FStar.Range.range) : ppname
let mk_ppname (name:RT.pp_name_t) (range:FStar.Range.range) : ppname = { name = name; range = range }
{ "file_name": "lib/steel/pulse/Pulse.Syntax.Base.fsti", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 1, "end_line": 55, "start_col": 0, "start_line": 52 }
(* Copyright 2023 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module Pulse.Syntax.Base module RTB = FStar.Reflection.Typing.Builtins module RT = FStar.Reflection.Typing module R = FStar.Reflection.V2 module RU = Pulse.RuntimeUtils module T = FStar.Tactics.V2 open FStar.List.Tot type constant = R.vconst let var = nat let index = nat type universe = R.universe (* locally nameless. *) let range_singleton_trigger (r:FStar.Range.range) = True let range = r:FStar.Range.range { range_singleton_trigger r } let range_singleton (r:FStar.Range.range) : Lemma (ensures r == FStar.Range.range_0) [SMTPat (range_singleton_trigger r)] = FStar.Sealed.sealed_singl r FStar.Range.range_0 noeq type ppname = { name : RT.pp_name_t; range : range } let ppname_default = { name = FStar.Sealed.seal "_"; range = FStar.Range.range_0 }
{ "checked_file": "/", "dependencies": [ "Pulse.RuntimeUtils.fsti.checked", "Pulse.Reflection.Util.fst.checked", "prims.fst.checked", "FStar.Tactics.V2.fst.checked", "FStar.Sealed.Inhabited.fst.checked", "FStar.Sealed.fsti.checked", "FStar.Reflection.V2.fst.checked", "FStar.Reflection.Typing.Builtins.fsti.checked", "FStar.Reflection.Typing.fsti.checked", "FStar.Range.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked" ], "interface_file": false, "source_file": "Pulse.Syntax.Base.fsti" }
[ { "abbrev": false, "full_module": "FStar.List.Tot", "short_module": null }, { "abbrev": true, "full_module": "FStar.Tactics.V2", "short_module": "T" }, { "abbrev": true, "full_module": "Pulse.RuntimeUtils", "short_module": "RU" }, { "abbrev": true, "full_module": "FStar.Reflection.V2", "short_module": "R" }, { "abbrev": true, "full_module": "FStar.Reflection.Typing", "short_module": "RT" }, { "abbrev": true, "full_module": "FStar.Reflection.Typing.Builtins", "short_module": "RTB" }, { "abbrev": false, "full_module": "Pulse.Syntax", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Syntax", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": 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
name: FStar.Reflection.Typing.pp_name_t -> range: FStar.Range.range -> Pulse.Syntax.Base.ppname
Prims.Tot
[ "total" ]
[]
[ "FStar.Reflection.Typing.pp_name_t", "FStar.Range.range", "Pulse.Syntax.Base.Mkppname", "Pulse.Syntax.Base.ppname" ]
[]
false
false
false
true
false
let mk_ppname (name: RT.pp_name_t) (range: FStar.Range.range) : ppname =
{ name = name; range = range }
false
Pulse.Syntax.Base.fsti
Pulse.Syntax.Base.comp_st
val comp_st : Type0
let comp_st = c:comp {not (C_Tot? c) }
{ "file_name": "lib/steel/pulse/Pulse.Syntax.Base.fsti", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 38, "end_line": 157, "start_col": 0, "start_line": 157 }
(* Copyright 2023 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module Pulse.Syntax.Base module RTB = FStar.Reflection.Typing.Builtins module RT = FStar.Reflection.Typing module R = FStar.Reflection.V2 module RU = Pulse.RuntimeUtils module T = FStar.Tactics.V2 open FStar.List.Tot type constant = R.vconst let var = nat let index = nat type universe = R.universe (* locally nameless. *) let range_singleton_trigger (r:FStar.Range.range) = True let range = r:FStar.Range.range { range_singleton_trigger r } let range_singleton (r:FStar.Range.range) : Lemma (ensures r == FStar.Range.range_0) [SMTPat (range_singleton_trigger r)] = FStar.Sealed.sealed_singl r FStar.Range.range_0 noeq type ppname = { name : RT.pp_name_t; range : range } let ppname_default = { name = FStar.Sealed.seal "_"; range = FStar.Range.range_0 } let mk_ppname (name:RT.pp_name_t) (range:FStar.Range.range) : ppname = { name = name; range = range } let mk_ppname_no_range (s:string) : ppname = { name = FStar.Sealed.seal s; range = FStar.Range.range_0; } noeq type bv = { bv_index : index; bv_ppname : ppname; } noeq type nm = { nm_index : var; nm_ppname : ppname; } type qualifier = | Implicit noeq type fv = { fv_name : R.name; fv_range : range; } let as_fv l = { fv_name = l; fv_range = FStar.Range.range_0 } let not_tv_unknown (t:R.term) = R.inspect_ln t =!= R.Tv_Unknown let host_term = t:R.term { not_tv_unknown t } [@@ no_auto_projectors] noeq type term' = | Tm_Emp : term' | Tm_Pure : p:term -> term' | Tm_Star : l:vprop -> r:vprop -> term' | Tm_ExistsSL : u:universe -> b:binder -> body:vprop -> term' | Tm_ForallSL : u:universe -> b:binder -> body:vprop -> term' | Tm_VProp : term' | Tm_Inv : vprop -> term' | Tm_Inames : term' // type inames | Tm_EmpInames : term' | Tm_AddInv : i:term -> is:term -> term' | Tm_FStar : host_term -> term' | Tm_Unknown : term' and vprop = term and typ = term and binder = { binder_ty : term; binder_ppname : ppname; binder_attrs : FStar.Sealed.Inhabited.sealed #(list term) [] } and term = { t : term'; range : range; } let binder_attrs_default = FStar.Sealed.seal [] let term_range (t:term) = t.range let tm_fstar (t:host_term) (r:range) : term = { t = Tm_FStar t; range=r } let with_range (t:term') (r:range) = { t; range=r } let tm_vprop = with_range Tm_VProp FStar.Range.range_0 let tm_inv p = with_range (Tm_Inv p) FStar.Range.range_0 let tm_inames = with_range Tm_Inames FStar.Range.range_0 let tm_emp = with_range Tm_Emp FStar.Range.range_0 let tm_emp_inames = with_range Tm_EmpInames FStar.Range.range_0 let tm_unknown = with_range Tm_Unknown FStar.Range.range_0 let tm_pure (p:term) : term = { t = Tm_Pure p; range = p.range } let tm_star (l:vprop) (r:vprop) : term = { t = Tm_Star l r; range = RU.union_ranges l.range r.range } let tm_exists_sl (u:universe) (b:binder) (body:vprop) : term = { t = Tm_ExistsSL u b body; range = RU.union_ranges b.binder_ty.range body.range } let tm_forall_sl (u:universe) (b:binder) (body:vprop) : term = { t = Tm_ForallSL u b body; range = RU.union_ranges b.binder_ty.range body.range } noeq type st_comp = { (* ST pre (x:res) post ... x is free in post *) u:universe; res:term; pre:vprop; post:vprop } type observability = | Neutral | Observable | Unobservable noeq type comp = | C_Tot : term -> comp | C_ST : st_comp -> comp | C_STAtomic : inames:term -> obs:observability -> st_comp -> comp | C_STGhost : st_comp -> comp
{ "checked_file": "/", "dependencies": [ "Pulse.RuntimeUtils.fsti.checked", "Pulse.Reflection.Util.fst.checked", "prims.fst.checked", "FStar.Tactics.V2.fst.checked", "FStar.Sealed.Inhabited.fst.checked", "FStar.Sealed.fsti.checked", "FStar.Reflection.V2.fst.checked", "FStar.Reflection.Typing.Builtins.fsti.checked", "FStar.Reflection.Typing.fsti.checked", "FStar.Range.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked" ], "interface_file": false, "source_file": "Pulse.Syntax.Base.fsti" }
[ { "abbrev": false, "full_module": "FStar.List.Tot", "short_module": null }, { "abbrev": true, "full_module": "FStar.Tactics.V2", "short_module": "T" }, { "abbrev": true, "full_module": "Pulse.RuntimeUtils", "short_module": "RU" }, { "abbrev": true, "full_module": "FStar.Reflection.V2", "short_module": "R" }, { "abbrev": true, "full_module": "FStar.Reflection.Typing", "short_module": "RT" }, { "abbrev": true, "full_module": "FStar.Reflection.Typing.Builtins", "short_module": "RTB" }, { "abbrev": false, "full_module": "Pulse.Syntax", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Syntax", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": 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
Type0
Prims.Tot
[ "total" ]
[]
[ "Pulse.Syntax.Base.comp", "Prims.b2t", "Prims.op_Negation", "Pulse.Syntax.Base.uu___is_C_Tot" ]
[]
false
false
false
true
true
let comp_st =
c: comp{not (C_Tot? c)}
false
LowParse.Low.Bytes.fst
LowParse.Low.Bytes.accessor_vlbytes_slice
val accessor_vlbytes_slice (min: nat) (max: nat{min <= max /\ max > 0 /\ max < 4294967296}) (from: U32.t) (to: U32.t{U32.v from <= U32.v to /\ U32.v to <= max}) : Tot (accessor (gaccessor_vlbytes_slice min max from to))
val accessor_vlbytes_slice (min: nat) (max: nat{min <= max /\ max > 0 /\ max < 4294967296}) (from: U32.t) (to: U32.t{U32.v from <= U32.v to /\ U32.v to <= max}) : Tot (accessor (gaccessor_vlbytes_slice min max from to))
let accessor_vlbytes_slice (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (from: U32.t) (to: U32.t {U32.v from <= U32.v to /\ U32.v to <= max } ) : Tot (accessor (gaccessor_vlbytes_slice min max from to)) = accessor_vlbytes'_slice min max (log256' max) from to
{ "file_name": "src/lowparse/LowParse.Low.Bytes.fst", "git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
{ "end_col": 55, "end_line": 763, "start_col": 0, "start_line": 757 }
module LowParse.Low.Bytes include LowParse.Spec.Bytes include LowParse.Low.Combinators include LowParse.Low.VLData include LowParse.Low.VLGen include LowParse.Low.Int module U32 = FStar.UInt32 module HS = FStar.HyperStack module B = LowStar.Monotonic.Buffer module BF = LowStar.Buffer // for local variables in store_bytes module BY = LowParse.Bytes32 module HST = FStar.HyperStack.ST module U8 = FStar.UInt8 module Cast = FStar.Int.Cast module U64 = FStar.UInt64 inline_for_extraction let validate_flbytes (sz: nat) (sz64: U64.t { U64.v sz64 == sz /\ sz < 4294967296 } ) : Tot (validator (parse_flbytes sz)) = validate_total_constant_size (parse_flbytes sz) sz64 () inline_for_extraction let jump_flbytes (sz: nat) (sz32: U32.t { U32.v sz32 == sz } ) : Tot (jumper (parse_flbytes sz)) = jump_constant_size (parse_flbytes sz) sz32 () let valid_flbytes_intro (h: HS.mem) (sz: nat { sz < 4294967296 } ) (#rrel #rel: _) (s: slice rrel rel) (pos: U32.t) : Lemma (requires (U32.v pos + sz <= U32.v s.len /\ live_slice h s)) (ensures ( valid_content_pos (parse_flbytes sz) h s pos (BY.hide (bytes_of_slice_from_to h s pos (pos `U32.add` U32.uint_to_t sz))) (pos `U32.add` U32.uint_to_t sz) )) = valid_facts (parse_flbytes sz) h s pos let valid_pos_flbytes_elim (h: HS.mem) (sz: nat { sz < 4294967296 } ) (#rrel #rel: _) (s: slice rrel rel) (pos pos' : U32.t) : Lemma (requires (valid_pos (parse_flbytes sz) h s pos pos')) (ensures (U32.v pos + sz == U32.v pos')) [SMTPat (valid_pos (parse_flbytes sz) h s pos pos')] = valid_facts (parse_flbytes sz) h s pos let valid_flbytes_elim (h: HS.mem) (sz: nat { sz < 4294967296 } ) (#rrel #rel: _) (s: slice rrel rel) (pos: U32.t) : Lemma (requires (valid (parse_flbytes sz) h s pos)) (ensures ( valid_content_pos (parse_flbytes sz) h s pos (BY.hide (bytes_of_slice_from_to h s pos (pos `U32.add` U32.uint_to_t sz))) (pos `U32.add` U32.uint_to_t sz) )) = valid_flbytes_intro h sz s pos let clens_flbytes_slice (sz: nat) (from: U32.t) (to: U32.t {U32.v from <= U32.v to /\ U32.v to <= sz } ) : Tot (clens (BY.lbytes sz) (BY.lbytes (U32.v to - U32.v from))) = { clens_cond = (fun _ -> True); clens_get = (fun (x: BY.lbytes sz) -> (BY.slice x from to <: BY.lbytes (U32.v to - U32.v from))); } #push-options "--z3rlimit 16" let gaccessor_flbytes_slice' (sz: nat { sz < 4294967296 } ) (from: U32.t) (to: U32.t {U32.v from <= U32.v to /\ U32.v to <= sz } ) : Tot (gaccessor' (parse_flbytes sz) (parse_flbytes (U32.v to - U32.v from)) (clens_flbytes_slice sz from to)) = fun (input: bytes) -> ( begin if Seq.length input < sz then (0) // dummy else (U32.v from) end) let gaccessor_flbytes_slice (sz: nat { sz < 4294967296 } ) (from: U32.t) (to: U32.t {U32.v from <= U32.v to /\ U32.v to <= sz } ) : Tot (gaccessor (parse_flbytes sz) (parse_flbytes (U32.v to - U32.v from)) (clens_flbytes_slice sz from to)) = assert (forall x . gaccessor_pre (parse_flbytes sz) (parse_flbytes (U32.v to - U32.v from)) (clens_flbytes_slice sz from to) x ==> sz <= Seq.length x); gaccessor_prop_equiv (parse_flbytes sz) (parse_flbytes (U32.v to - U32.v from)) (clens_flbytes_slice sz from to) (gaccessor_flbytes_slice' sz from to); gaccessor_flbytes_slice' sz from to inline_for_extraction let accessor_flbytes_slice (sz: nat { sz < 4294967296 } ) (from: U32.t) (to: U32.t {U32.v from <= U32.v to /\ U32.v to <= sz } ) : Tot (accessor (gaccessor_flbytes_slice sz from to)) = fun #rrel #rel input pos -> let h = HST.get () in [@inline_let] let _ = slice_access_eq h (gaccessor_flbytes_slice sz from to) input pos in pos `U32.add` from #pop-options let clens_flbytes_get (sz: nat) (i: U32.t { U32.v i < sz } ) : Tot (clens (BY.lbytes sz) byte) = { clens_cond = (fun _ -> True); clens_get = (fun (x: BY.lbytes sz) -> (BY.get x i <: byte)); } #push-options "--z3rlimit 16 --max_fuel 1" let gaccessor_flbytes_get' (sz: nat { sz < 4294967296 } ) (i: U32.t { U32.v i < sz } ) : Tot (gaccessor' (parse_flbytes sz) (parse_u8) (clens_flbytes_get sz i)) = fun (input: bytes) -> ( begin let res = if Seq.length input < U32.v i then (0) // dummy else (U32.v i) in let g () : Lemma (requires (gaccessor_pre (parse_flbytes sz) parse_u8 (clens_flbytes_get sz i) input)) (ensures (gaccessor_post (parse_flbytes sz) parse_u8 (clens_flbytes_get sz i) input res)) = parser_kind_prop_equiv (get_parser_kind parse_u8) parse_u8; assert (res == (U32.v i)); parse_u8_spec' (Seq.slice input (U32.v i) (U32.v i + 1)); parse_strong_prefix parse_u8 (Seq.slice input (U32.v i) (U32.v i + 1)) (Seq.slice input (U32.v i) (Seq.length input)) in Classical.move_requires g (); res end) #pop-options let gaccessor_flbytes_get (sz: nat { sz < 4294967296 } ) (i: U32.t { U32.v i < sz } ) : Tot (gaccessor (parse_flbytes sz) (parse_u8) (clens_flbytes_get sz i)) = assert (forall x . gaccessor_pre (parse_flbytes sz) (parse_u8) (clens_flbytes_get sz i) x ==> U32.v i <= Seq.length x); gaccessor_prop_equiv (parse_flbytes sz) (parse_u8) (clens_flbytes_get sz i) (gaccessor_flbytes_get' sz i); gaccessor_flbytes_get' sz i inline_for_extraction let accessor_flbytes_get (sz: nat { sz < 4294967296 } ) (i: U32.t { U32.v i < sz } ) : Tot (accessor (gaccessor_flbytes_get sz i)) = fun #rrel #rel input pos -> let h = HST.get () in [@inline_let] let _ = slice_access_eq h (gaccessor_flbytes_get sz i) input pos in pos `U32.add` i (* Temporary: flbytes as leaf values *) (* TODO: convert store_bytes to monotonic buffers, using the "writable" predicate *) #push-options "--z3rlimit 32" inline_for_extraction let store_bytes (src: BY.bytes) (src_from src_to: U32.t) (#rrel #rel: _) (dst: B.mbuffer byte rrel rel) (dst_pos: U32.t) : HST.Stack unit (requires (fun h -> B.live h dst /\ U32.v src_from <= U32.v src_to /\ U32.v src_to <= BY.length src /\ U32.v dst_pos + (U32.v src_to - U32.v src_from) <= B.length dst /\ writable dst (U32.v dst_pos) (U32.v dst_pos + (U32.v src_to - U32.v src_from)) h )) (ensures (fun h _ h' -> B.modifies (B.loc_buffer_from_to dst dst_pos (dst_pos `U32.add` (src_to `U32.sub` src_from))) h h' /\ Seq.slice (B.as_seq h' dst) (U32.v dst_pos) (U32.v dst_pos + (U32.v src_to - U32.v src_from)) == Seq.slice (BY.reveal src) (U32.v src_from) (U32.v src_to) )) = let h0 = HST.get () in HST.push_frame (); let h1 = HST.get () in let bi = BF.alloca 0ul 1ul in let h2 = HST.get () in let len = src_to `U32.sub` src_from in C.Loops.do_while (fun h stop -> B.modifies (B.loc_union (B.loc_region_only true (HS.get_tip h1)) (B.loc_buffer_from_to dst dst_pos (dst_pos `U32.add` len))) h2 h /\ B.live h bi /\ ( let i = Seq.index (B.as_seq h bi) 0 in U32.v i <= U32.v len /\ writable dst (U32.v dst_pos) (U32.v dst_pos + U32.v len) h /\ Seq.slice (B.as_seq h dst) (U32.v dst_pos) (U32.v dst_pos + U32.v i) `Seq.equal` Seq.slice (BY.reveal src) (U32.v src_from) (U32.v src_from + U32.v i) /\ (stop == true ==> i == len) )) (fun _ -> let i = B.index bi 0ul in if i = len then true else begin let x = BY.get src (src_from `U32.add` i) in mbuffer_upd dst (Ghost.hide (U32.v dst_pos)) (Ghost.hide (U32.v dst_pos + U32.v len)) (dst_pos `U32.add` i) x; let i' = i `U32.add` 1ul in B.upd bi 0ul i'; let h' = HST.get () in Seq.lemma_split (Seq.slice (B.as_seq h' dst) (U32.v dst_pos) (U32.v dst_pos + U32.v i')) (U32.v i); i' = len end ) ; HST.pop_frame () #pop-options inline_for_extraction let serialize32_flbytes (sz32: U32.t) : Tot (serializer32 (serialize_flbytes (U32.v sz32))) = fun (x: BY.lbytes (U32.v sz32)) #rrel #rel b pos -> let _ = store_bytes x 0ul sz32 b pos in sz32 inline_for_extraction let write_flbytes (sz32: U32.t) : Tot (leaf_writer_strong (serialize_flbytes (U32.v sz32))) = leaf_writer_strong_of_serializer32 (serialize32_flbytes sz32) () inline_for_extraction let write_flbytes_weak (sz32: U32.t { U32.v sz32 < 4294967295 } ) // need to return that value if output buffer is too small : Tot (leaf_writer_weak (serialize_flbytes (U32.v sz32))) = leaf_writer_weak_of_strong_constant_size (write_flbytes sz32) sz32 () (* // TODO: remove, since nobody is using this inline_for_extraction let read_flbytes (sz32: U32.t) : Tot (leaf_reader (parse_flbytes (U32.v sz32))) = fun input pos -> let h = HST.get () in [@inline_let] let _ = valid_facts (parse_flbytes (U32.v sz32)) h input pos in BY.of_buffer sz32 (B.sub input.base pos sz32) *) (* Equality test between a vlbytes and a constant lbytes *) #push-options "--z3rlimit 32" inline_for_extraction let buffer_equals_bytes (const: BY.bytes) (#rrel #rel: _) (b: B.mbuffer byte rrel rel) (pos: U32.t) : HST.Stack bool (requires (fun h -> B.live h b /\ U32.v pos + BY.length const <= B.length b )) (ensures (fun h res h' -> B.modifies B.loc_none h h' /\ (res == true <==> Seq.slice (B.as_seq h b) (U32.v pos) (U32.v pos + BY.length const) == BY.reveal const) )) = let h0 = HST.get () in HST.push_frame (); let len = BY.len const in let bi = BF.alloca 0ul 1ul in let bres = BF.alloca true 1ul in let h1 = HST.get () in [@inline_let] let inv (h: HS.mem) (stop: bool) : GTot Type0 = B.modifies (B.loc_union (B.loc_buffer bi) (B.loc_buffer bres)) h1 h /\ ( let length = U32.v len in let i32 = (Seq.index (B.as_seq h bi) 0) in let i = U32.v i32 in let res = Seq.index (B.as_seq h bres) 0 in i <= length /\ (stop == false ==> res == true) /\ ((stop == true /\ res == true) ==> i == length) /\ (res == true <==> Seq.slice (B.as_seq h b) (U32.v pos) (U32.v pos + i) `Seq.equal` Seq.slice (BY.reveal const) 0 i) ) in C.Loops.do_while inv (fun _ -> let i = B.index bi 0ul in if i = len then true else begin let i' = i `U32.add` 1ul in [@inline_let] let _ = let s1 = (Seq.slice (B.as_seq h0 b) (U32.v pos) (U32.v pos + U32.v i)) in let c1 = (B.get h0 b (U32.v pos + U32.v i)) in let s2 = (Seq.slice (BY.reveal const) 0 (U32.v i)) in let c2 = (BY.index const (U32.v i)) in assert (Seq.slice (B.as_seq h0 b) (U32.v pos) (U32.v pos + U32.v i') `Seq.equal` Seq.snoc s1 c1); assert (Seq.slice (BY.reveal const) 0 (U32.v i') `Seq.equal` Seq.snoc s2 c2); Classical.move_requires (Seq.lemma_snoc_inj s1 s2 c1) c2 in let res = B.index b (pos `U32.add` i) = BY.get const i in B.upd bres 0ul res; B.upd bi 0ul i'; not res end ); let res = B.index bres 0ul in HST.pop_frame (); res #pop-options inline_for_extraction let valid_slice_equals_bytes (const: BY.bytes) (#rrel #rel: _) (input: slice rrel rel) (pos: U32.t) : HST.Stack bool (requires (fun h -> valid (parse_flbytes (BY.length const)) h input pos )) (ensures (fun h res h' -> B.modifies B.loc_none h h' /\ (res == true <==> contents (parse_flbytes (BY.length const)) h input pos == const ))) = let h = HST.get () in [@inline_let] let _ = valid_facts (parse_flbytes (BY.length const)) h input pos in buffer_equals_bytes const input.base pos inline_for_extraction let validate_all_bytes () : Tot (validator parse_all_bytes) = fun #rrel #rel input pos -> let h = HST.get () in [@inline_let] let _ = valid_facts parse_all_bytes h input (uint64_to_uint32 pos) in Cast.uint32_to_uint64 input.len inline_for_extraction let validate_bounded_vlbytes' (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (l: nat { l >= log256' max /\ l <= 4 } ) : Tot (validator (parse_bounded_vlbytes' min max l)) = validate_synth (validate_bounded_vldata_strong' min max l serialize_all_bytes (validate_all_bytes ())) (synth_bounded_vlbytes min max) () inline_for_extraction let validate_bounded_vlbytes (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) : Tot (validator (parse_bounded_vlbytes min max)) = validate_bounded_vlbytes' min max (log256' max) inline_for_extraction let jump_all_bytes () : Tot (jumper parse_all_bytes) = fun #rrel #rel input pos -> let h = HST.get () in [@inline_let] let _ = valid_facts parse_all_bytes h input pos in input.len inline_for_extraction let jump_bounded_vlbytes' (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (l: nat { l >= log256' max /\ l <= 4 } ) : Tot (jumper (parse_bounded_vlbytes' min max l)) = jump_synth (jump_bounded_vldata_strong' min max l serialize_all_bytes) (synth_bounded_vlbytes min max) () inline_for_extraction let jump_bounded_vlbytes (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) : Tot (jumper (parse_bounded_vlbytes min max)) = jump_bounded_vlbytes' min max (log256' max) let valid_exact_all_bytes_elim (h: HS.mem) (#rrel #rel: _) (input: slice rrel rel) (pos pos' : U32.t) : Lemma (requires (valid_exact parse_all_bytes h input pos pos')) (ensures ( let x = contents_exact parse_all_bytes h input pos pos' in let length = U32.v pos' - U32.v pos in BY.length x == length /\ valid_content_pos (parse_flbytes length) h input pos x pos' )) = valid_exact_equiv parse_all_bytes h input pos pos' ; contents_exact_eq parse_all_bytes h input pos pos' ; let length = U32.v pos' - U32.v pos in valid_facts (parse_flbytes length) h input pos ; assert (no_lookahead_on (parse_flbytes length) (bytes_of_slice_from_to h input pos pos') (bytes_of_slice_from h input pos)); assert (injective_postcond (parse_flbytes length) (bytes_of_slice_from_to h input pos pos') (bytes_of_slice_from h input pos)) #push-options "--z3rlimit 32" let valid_bounded_vlbytes'_elim (h: HS.mem) (min: nat) (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (l: nat { l >= log256' max /\ l <= 4 } ) (#rrel #rel: _) (input: slice rrel rel) (pos: U32.t) : Lemma (requires ( valid (parse_bounded_vlbytes' min max l) h input pos )) (ensures ( let sz = l in valid (parse_bounded_integer sz) h input pos /\ ( let len_payload = contents (parse_bounded_integer sz) h input pos in min <= U32.v len_payload /\ U32.v len_payload <= max /\ sz + U32.v len_payload == content_length (parse_bounded_vlbytes' min max l) h input pos /\ ( let pos_payload = pos `U32.add` U32.uint_to_t sz in let x = contents (parse_bounded_vlbytes' min max l) h input pos in BY.len x == len_payload /\ valid_pos (parse_bounded_vlbytes' min max l) h input pos (pos_payload `U32.add` len_payload) /\ valid_content_pos (parse_flbytes (U32.v len_payload)) h input pos_payload x (pos_payload `U32.add` len_payload) )))) = valid_synth h (parse_bounded_vlbytes_aux min max l) (synth_bounded_vlbytes min max) input pos; valid_bounded_vldata_strong'_elim h min max l serialize_all_bytes input pos; let sz = l in let len_payload = contents (parse_bounded_integer sz) h input pos in let pos_payload = pos `U32.add` U32.uint_to_t sz in valid_exact_all_bytes_elim h input pos_payload (pos_payload `U32.add` len_payload); () #pop-options let valid_bounded_vlbytes_elim (h: HS.mem) (min: nat) (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (#rrel #rel: _) (input: slice rrel rel) (pos: U32.t) : Lemma (requires ( valid (parse_bounded_vlbytes min max) h input pos )) (ensures ( let sz = log256' max in valid (parse_bounded_integer sz) h input pos /\ ( let len_payload = contents (parse_bounded_integer sz) h input pos in min <= U32.v len_payload /\ U32.v len_payload <= max /\ sz + U32.v len_payload == content_length (parse_bounded_vlbytes min max) h input pos /\ ( let pos_payload = pos `U32.add` U32.uint_to_t sz in let x = contents (parse_bounded_vlbytes min max) h input pos in BY.len x == len_payload /\ valid_pos (parse_bounded_vlbytes min max) h input pos (pos_payload `U32.add` len_payload) /\ valid_content_pos (parse_flbytes (U32.v len_payload)) h input pos_payload x (pos_payload `U32.add` len_payload) )))) = valid_bounded_vlbytes'_elim h min max (log256' max) input pos let valid_bounded_vlbytes_elim_length (h: HS.mem) (min: nat) (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (#rrel #rel: _) (input: slice rrel rel) (pos: U32.t) : Lemma (requires ( valid (parse_bounded_vlbytes min max) h input pos )) (ensures ( content_length (parse_bounded_vlbytes min max) h input pos == log256' max + BY.length (contents (parse_bounded_vlbytes min max) h input pos) )) [SMTPat (valid (parse_bounded_vlbytes min max) h input pos)] = valid_bounded_vlbytes_elim h min max input pos inline_for_extraction let bounded_vlbytes'_payload_length (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (l: nat { l >= log256' max /\ l <= 4 } ) (#rrel #rel: _) (input: slice rrel rel) (pos: U32.t) : HST.Stack U32.t (requires (fun h -> valid (parse_bounded_vlbytes' min max l) h input pos)) (ensures (fun h len h' -> B.modifies B.loc_none h h' /\ U32.v pos + l + U32.v len <= U32.v input.len /\ ( let x = contents (parse_bounded_vlbytes' min max l) h input pos in let pos' = get_valid_pos (parse_bounded_vlbytes' min max l) h input pos in BY.len x == len /\ valid_content_pos (parse_flbytes (U32.v len)) h input (pos `U32.add` U32.uint_to_t l) x pos' /\ bytes_of_slice_from_to h input (pos `U32.add` U32.uint_to_t l) pos' == BY.reveal x ))) = let h = HST.get () in [@inline_let] let _ = valid_bounded_vlbytes'_elim h min max l input pos in let len = read_bounded_integer l input pos in [@inline_let] let _ = valid_flbytes_elim h (U32.v len) input (pos `U32.add` U32.uint_to_t l) in len inline_for_extraction let bounded_vlbytes_payload_length (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (#rrel #rel: _) (input: slice rrel rel) (pos: U32.t) : HST.Stack U32.t (requires (fun h -> valid (parse_bounded_vlbytes min max) h input pos)) (ensures (fun h len h' -> B.modifies B.loc_none h h' /\ U32.v pos + log256' max + U32.v len <= U32.v input.len /\ ( let x = contents (parse_bounded_vlbytes min max) h input pos in let pos' = get_valid_pos (parse_bounded_vlbytes min max) h input pos in BY.len x == len /\ valid_content_pos (parse_flbytes (U32.v len)) h input (pos `U32.add` U32.uint_to_t (log256' max)) x pos' /\ bytes_of_slice_from_to h input (pos `U32.add` U32.uint_to_t (log256' max)) pos' == BY.reveal x ))) = bounded_vlbytes'_payload_length min max (log256' max) input pos (* Get the content buffer (with trivial buffers only, not generalizable to monotonicity) *) #push-options "--z3rlimit 32" inline_for_extraction let get_vlbytes'_contents (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (l: nat { l >= log256' max /\ l <= 4 } ) (input: slice (srel_of_buffer_srel (BF.trivial_preorder _)) (srel_of_buffer_srel (BF.trivial_preorder _))) (pos: U32.t) : HST.Stack (BF.buffer byte) (requires (fun h -> valid (parse_bounded_vlbytes' min max l) h input pos)) (ensures (fun h b h' -> let x = contents (parse_bounded_vlbytes' min max l) h input pos in B.modifies B.loc_none h h' /\ U32.v pos + l + BY.length x <= U32.v input.len /\ b == BF.gsub input.base (pos `U32.add` U32.uint_to_t l) (BY.len x) /\ B.as_seq h b == BY.reveal x )) = let h = HST.get () in [@inline_let] let _ = valid_bounded_vlbytes'_elim h min max l input pos in let len = read_bounded_integer l input pos in [@inline_let] let _ = valid_facts (parse_flbytes (U32.v len)) h input (pos `U32.add` U32.uint_to_t l) in BF.sub input.base (pos `U32.add` U32.uint_to_t l) len #pop-options inline_for_extraction let get_vlbytes_contents (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (input: slice (srel_of_buffer_srel (BF.trivial_preorder _)) (srel_of_buffer_srel (BF.trivial_preorder _))) (pos: U32.t) : HST.Stack (BF.buffer byte) (requires (fun h -> valid (parse_bounded_vlbytes min max) h input pos)) (ensures (fun h b h' -> let l = log256' max in let x = contents (parse_bounded_vlbytes min max) h input pos in B.modifies B.loc_none h h' /\ U32.v pos + l + BY.length x <= U32.v input.len /\ b == BF.gsub input.base (pos `U32.add` U32.uint_to_t l) (BY.len x) /\ B.as_seq h b == BY.reveal x )) = get_vlbytes'_contents min max (log256' max) input pos (* In fact, the following accessors are not useful in practice, because users would need to have the flbytes parser combinator in their scope *) let clens_vlbytes_cond (min: nat) (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (length: nat) (x: parse_bounded_vlbytes_t min max) : GTot Type0 = BY.length x == length let clens_vlbytes (min: nat) (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (length: nat) : Tot (clens (parse_bounded_vlbytes_t min max) (BY.lbytes length)) = { clens_cond = (clens_vlbytes_cond min max length); clens_get = (fun (x: parse_bounded_vlbytes_t min max) -> (x <: Ghost (BY.lbytes length) (requires (clens_vlbytes_cond min max length x)) (ensures (fun _ -> True)))); } #push-options "--z3rlimit 16 --max_fuel 2 --initial_fuel 2 --max_ifuel 6 --initial_ifuel 6" let gaccessor_vlbytes'_aux (min: nat) (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (l: nat { l >= log256' max /\ l <= 4 } ) (length: nat { length < 4294967296 } ) : Tot (gaccessor' (parse_bounded_vlbytes' min max l) (parse_flbytes length) (clens_vlbytes min max length)) = fun (input: bytes) -> (begin let res = if Seq.length input >= l then (l) else (0) in let g () : Lemma (requires (gaccessor_pre (parse_bounded_vlbytes' min max l) (parse_flbytes length) (clens_vlbytes min max length) input)) (ensures (gaccessor_post (parse_bounded_vlbytes' min max l) (parse_flbytes length) (clens_vlbytes min max length) input res)) = parse_bounded_vlbytes_eq min max l input; parse_strong_prefix (parse_flbytes length) (Seq.slice input l (l + length)) (Seq.slice input l (Seq.length input)) in Classical.move_requires g (); res end) let gaccessor_vlbytes' (min: nat) (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (l: nat { l >= log256' max /\ l <= 4 } ) (length: nat { length < 4294967296 } ) : Tot (gaccessor (parse_bounded_vlbytes' min max l) (parse_flbytes length) (clens_vlbytes min max length)) = parser_kind_prop_equiv (parse_bounded_vldata_strong_kind min max l parse_all_bytes_kind) (parse_bounded_vlbytes' min max l); assert (forall x . gaccessor_pre (parse_bounded_vlbytes' min max l) (parse_flbytes length) (clens_vlbytes min max length) x ==> Seq.length x >= l); gaccessor_prop_equiv (parse_bounded_vlbytes' min max l) (parse_flbytes length) (clens_vlbytes min max length) (gaccessor_vlbytes'_aux min max l length); gaccessor_vlbytes'_aux min max l length #pop-options let gaccessor_vlbytes (min: nat) (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (length: nat { length < 4294967296 } ) : Tot (gaccessor (parse_bounded_vlbytes min max) (parse_flbytes length) (clens_vlbytes min max length)) = gaccessor_vlbytes' min max (log256' max) length #push-options "--z3rlimit 64 --max_fuel 2 --initial_fuel 2 --max_ifuel 6 --initial_ifuel 6" inline_for_extraction let accessor_vlbytes' (min: nat) (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (l: nat { l >= log256' max /\ l <= 4 } ) (length: U32.t) : Tot (accessor (gaccessor_vlbytes' min max l (U32.v length))) = fun #rrel #rel sl pos -> let h = HST.get () in [@inline_let] let _ = slice_access_eq h (gaccessor_vlbytes' min max l (U32.v length)) sl pos; valid_bounded_vlbytes'_elim h min max l sl pos; parse_bounded_vlbytes_eq min max l (bytes_of_slice_from h sl pos) in pos `U32.add` U32.uint_to_t l #pop-options inline_for_extraction let accessor_vlbytes (min: nat) (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (length: U32.t) : Tot (accessor (gaccessor_vlbytes min max (U32.v length))) = accessor_vlbytes' min max (log256' max) length let clens_vlbytes_slice (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (from: U32.t) (to: U32.t {U32.v from <= U32.v to /\ U32.v to <= max } ) : Tot (clens (parse_bounded_vlbytes_t min max) (BY.lbytes (U32.v to - U32.v from))) = { clens_cond = (fun (x: parse_bounded_vlbytes_t min max) -> U32.v to <= BY.length x); clens_get = (fun (x: parse_bounded_vlbytes_t min max) -> (BY.slice x from to <: BY.lbytes (U32.v to - U32.v from))); } #push-options "--z3rlimit 16" let gaccessor_vlbytes'_slice_aux (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (l: nat { l >= log256' max /\ l <= 4 } ) (from: U32.t) (to: U32.t {U32.v from <= U32.v to /\ U32.v to <= max } ) : Tot (gaccessor' (parse_bounded_vlbytes' min max l) (parse_flbytes (U32.v to - U32.v from)) (clens_vlbytes_slice min max from to)) = fun (input: bytes) -> ( begin parse_bounded_vlbytes_eq min max l input; if Seq.length input < l + U32.v to then (0) // dummy else (l + U32.v from) end) let gaccessor_vlbytes'_slice (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (l: nat { l >= log256' max /\ l <= 4 } ) (from: U32.t) (to: U32.t {U32.v from <= U32.v to /\ U32.v to <= max } ) : Tot (gaccessor (parse_bounded_vlbytes' min max l) (parse_flbytes (U32.v to - U32.v from)) (clens_vlbytes_slice min max from to)) = parser_kind_prop_equiv (parse_bounded_vldata_strong_kind min max l parse_all_bytes_kind) (parse_bounded_vlbytes' min max l); Classical.forall_intro (parse_bounded_vlbytes_eq min max l); assert (forall x . gaccessor_pre (parse_bounded_vlbytes' min max l) (parse_flbytes (U32.v to - U32.v from)) (clens_vlbytes_slice min max from to) x ==> l + U32.v to <= Seq.length x); gaccessor_prop_equiv (parse_bounded_vlbytes' min max l) (parse_flbytes (U32.v to - U32.v from)) (clens_vlbytes_slice min max from to) (gaccessor_vlbytes'_slice_aux min max l from to); gaccessor_vlbytes'_slice_aux min max l from to let gaccessor_vlbytes_slice (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (from: U32.t) (to: U32.t {U32.v from <= U32.v to /\ U32.v to <= max } ) : Tot (gaccessor (parse_bounded_vlbytes min max) (parse_flbytes (U32.v to - U32.v from)) (clens_vlbytes_slice min max from to)) = gaccessor_vlbytes'_slice min max (log256' max) from to #pop-options #push-options "--z3rlimit 50" inline_for_extraction let accessor_vlbytes'_slice (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (l: nat { l >= log256' max /\ l <= 4 } ) (from: U32.t) (to: U32.t {U32.v from <= U32.v to /\ U32.v to <= max } ) : Tot (accessor (gaccessor_vlbytes'_slice min max l from to)) = fun #rrel #rel input pos -> let h = HST.get () in [@inline_let] let _ = valid_facts (parse_bounded_vlbytes' min max l) h input pos; parse_bounded_vlbytes_eq min max l (bytes_of_slice_from h input pos); slice_access_eq h (gaccessor_vlbytes'_slice min max l from to) input pos in pos `U32.add` U32.uint_to_t l `U32.add` from #pop-options
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowStar.Monotonic.Buffer.fsti.checked", "LowStar.Buffer.fst.checked", "LowParse.Spec.Bytes.fst.checked", "LowParse.Low.VLGen.fst.checked", "LowParse.Low.VLData.fst.checked", "LowParse.Low.Int.fsti.checked", "LowParse.Low.Combinators.fsti.checked", "LowParse.Bytes32.fst.checked", "FStar.UInt8.fsti.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Int.Cast.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked", "FStar.Classical.fsti.checked", "C.Loops.fst.checked" ], "interface_file": false, "source_file": "LowParse.Low.Bytes.fst" }
[ { "abbrev": true, "full_module": "LowStar.Buffer // for local variables in store_bytes", "short_module": "BF" }, { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "FStar.Int.Cast", "short_module": "Cast" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "LowParse.Bytes32", "short_module": "BY" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "BF" }, { "abbrev": true, "full_module": "LowStar.Monotonic.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": false, "full_module": "LowParse.Low.Int", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low.VLGen", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low.VLData", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low.Combinators", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec.Bytes", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
min: Prims.nat -> max: Prims.nat{min <= max /\ max > 0 /\ max < 4294967296} -> from: FStar.UInt32.t -> to: FStar.UInt32.t{FStar.UInt32.v from <= FStar.UInt32.v to /\ FStar.UInt32.v to <= max} -> LowParse.Low.Base.accessor (LowParse.Low.Bytes.gaccessor_vlbytes_slice min max from to)
Prims.Tot
[ "total" ]
[]
[ "Prims.nat", "Prims.l_and", "Prims.b2t", "Prims.op_LessThanOrEqual", "Prims.op_GreaterThan", "Prims.op_LessThan", "FStar.UInt32.t", "FStar.UInt32.v", "LowParse.Low.Bytes.accessor_vlbytes'_slice", "LowParse.Spec.BoundedInt.log256'", "LowParse.Low.Base.accessor", "LowParse.Spec.VLData.parse_bounded_vldata_strong_kind", "LowParse.Spec.Bytes.parse_all_bytes_kind", "LowParse.Spec.Bytes.parse_bounded_vlbytes_t", "LowParse.Spec.Bytes.parse_bounded_vlbytes", "LowParse.Spec.Base.total_constant_size_parser_kind", "Prims.op_Subtraction", "FStar.Bytes.lbytes", "LowParse.Spec.Bytes.parse_flbytes", "LowParse.Low.Bytes.clens_vlbytes_slice", "LowParse.Low.Bytes.gaccessor_vlbytes_slice" ]
[]
false
false
false
false
false
let accessor_vlbytes_slice (min: nat) (max: nat{min <= max /\ max > 0 /\ max < 4294967296}) (from: U32.t) (to: U32.t{U32.v from <= U32.v to /\ U32.v to <= max}) : Tot (accessor (gaccessor_vlbytes_slice min max from to)) =
accessor_vlbytes'_slice min max (log256' max) from to
false
Pulse.Syntax.Base.fsti
Pulse.Syntax.Base.effect_hint
val effect_hint : Type0
let effect_hint = FStar.Sealed.Inhabited.sealed #(option ctag) None
{ "file_name": "lib/steel/pulse/Pulse.Syntax.Base.fsti", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 67, "end_line": 171, "start_col": 0, "start_line": 171 }
(* Copyright 2023 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module Pulse.Syntax.Base module RTB = FStar.Reflection.Typing.Builtins module RT = FStar.Reflection.Typing module R = FStar.Reflection.V2 module RU = Pulse.RuntimeUtils module T = FStar.Tactics.V2 open FStar.List.Tot type constant = R.vconst let var = nat let index = nat type universe = R.universe (* locally nameless. *) let range_singleton_trigger (r:FStar.Range.range) = True let range = r:FStar.Range.range { range_singleton_trigger r } let range_singleton (r:FStar.Range.range) : Lemma (ensures r == FStar.Range.range_0) [SMTPat (range_singleton_trigger r)] = FStar.Sealed.sealed_singl r FStar.Range.range_0 noeq type ppname = { name : RT.pp_name_t; range : range } let ppname_default = { name = FStar.Sealed.seal "_"; range = FStar.Range.range_0 } let mk_ppname (name:RT.pp_name_t) (range:FStar.Range.range) : ppname = { name = name; range = range } let mk_ppname_no_range (s:string) : ppname = { name = FStar.Sealed.seal s; range = FStar.Range.range_0; } noeq type bv = { bv_index : index; bv_ppname : ppname; } noeq type nm = { nm_index : var; nm_ppname : ppname; } type qualifier = | Implicit noeq type fv = { fv_name : R.name; fv_range : range; } let as_fv l = { fv_name = l; fv_range = FStar.Range.range_0 } let not_tv_unknown (t:R.term) = R.inspect_ln t =!= R.Tv_Unknown let host_term = t:R.term { not_tv_unknown t } [@@ no_auto_projectors] noeq type term' = | Tm_Emp : term' | Tm_Pure : p:term -> term' | Tm_Star : l:vprop -> r:vprop -> term' | Tm_ExistsSL : u:universe -> b:binder -> body:vprop -> term' | Tm_ForallSL : u:universe -> b:binder -> body:vprop -> term' | Tm_VProp : term' | Tm_Inv : vprop -> term' | Tm_Inames : term' // type inames | Tm_EmpInames : term' | Tm_AddInv : i:term -> is:term -> term' | Tm_FStar : host_term -> term' | Tm_Unknown : term' and vprop = term and typ = term and binder = { binder_ty : term; binder_ppname : ppname; binder_attrs : FStar.Sealed.Inhabited.sealed #(list term) [] } and term = { t : term'; range : range; } let binder_attrs_default = FStar.Sealed.seal [] let term_range (t:term) = t.range let tm_fstar (t:host_term) (r:range) : term = { t = Tm_FStar t; range=r } let with_range (t:term') (r:range) = { t; range=r } let tm_vprop = with_range Tm_VProp FStar.Range.range_0 let tm_inv p = with_range (Tm_Inv p) FStar.Range.range_0 let tm_inames = with_range Tm_Inames FStar.Range.range_0 let tm_emp = with_range Tm_Emp FStar.Range.range_0 let tm_emp_inames = with_range Tm_EmpInames FStar.Range.range_0 let tm_unknown = with_range Tm_Unknown FStar.Range.range_0 let tm_pure (p:term) : term = { t = Tm_Pure p; range = p.range } let tm_star (l:vprop) (r:vprop) : term = { t = Tm_Star l r; range = RU.union_ranges l.range r.range } let tm_exists_sl (u:universe) (b:binder) (body:vprop) : term = { t = Tm_ExistsSL u b body; range = RU.union_ranges b.binder_ty.range body.range } let tm_forall_sl (u:universe) (b:binder) (body:vprop) : term = { t = Tm_ForallSL u b body; range = RU.union_ranges b.binder_ty.range body.range } noeq type st_comp = { (* ST pre (x:res) post ... x is free in post *) u:universe; res:term; pre:vprop; post:vprop } type observability = | Neutral | Observable | Unobservable noeq type comp = | C_Tot : term -> comp | C_ST : st_comp -> comp | C_STAtomic : inames:term -> obs:observability -> st_comp -> comp | C_STGhost : st_comp -> comp let comp_st = c:comp {not (C_Tot? c) } noeq type pattern = | Pat_Cons : fv -> list (pattern & bool) -> pattern | Pat_Constant : constant -> pattern | Pat_Var : RT.pp_name_t -> ty:RT.sort_t -> pattern | Pat_Dot_Term : option term -> pattern type ctag = | STT | STT_Atomic | STT_Ghost
{ "checked_file": "/", "dependencies": [ "Pulse.RuntimeUtils.fsti.checked", "Pulse.Reflection.Util.fst.checked", "prims.fst.checked", "FStar.Tactics.V2.fst.checked", "FStar.Sealed.Inhabited.fst.checked", "FStar.Sealed.fsti.checked", "FStar.Reflection.V2.fst.checked", "FStar.Reflection.Typing.Builtins.fsti.checked", "FStar.Reflection.Typing.fsti.checked", "FStar.Range.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked" ], "interface_file": false, "source_file": "Pulse.Syntax.Base.fsti" }
[ { "abbrev": false, "full_module": "FStar.List.Tot", "short_module": null }, { "abbrev": true, "full_module": "FStar.Tactics.V2", "short_module": "T" }, { "abbrev": true, "full_module": "Pulse.RuntimeUtils", "short_module": "RU" }, { "abbrev": true, "full_module": "FStar.Reflection.V2", "short_module": "R" }, { "abbrev": true, "full_module": "FStar.Reflection.Typing", "short_module": "RT" }, { "abbrev": true, "full_module": "FStar.Reflection.Typing.Builtins", "short_module": "RTB" }, { "abbrev": false, "full_module": "Pulse.Syntax", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Syntax", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": 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
Type0
Prims.Tot
[ "total" ]
[]
[ "FStar.Sealed.Inhabited.sealed", "FStar.Pervasives.Native.option", "Pulse.Syntax.Base.ctag", "FStar.Pervasives.Native.None" ]
[]
false
false
false
true
true
let effect_hint =
FStar.Sealed.Inhabited.sealed #(option ctag) None
false
Pulse.Syntax.Base.fsti
Pulse.Syntax.Base.ppname_default
val ppname_default : Pulse.Syntax.Base.ppname
let ppname_default = { name = FStar.Sealed.seal "_"; range = FStar.Range.range_0 }
{ "file_name": "lib/steel/pulse/Pulse.Syntax.Base.fsti", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 1, "end_line": 50, "start_col": 0, "start_line": 47 }
(* Copyright 2023 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module Pulse.Syntax.Base module RTB = FStar.Reflection.Typing.Builtins module RT = FStar.Reflection.Typing module R = FStar.Reflection.V2 module RU = Pulse.RuntimeUtils module T = FStar.Tactics.V2 open FStar.List.Tot type constant = R.vconst let var = nat let index = nat type universe = R.universe (* locally nameless. *) let range_singleton_trigger (r:FStar.Range.range) = True let range = r:FStar.Range.range { range_singleton_trigger r } let range_singleton (r:FStar.Range.range) : Lemma (ensures r == FStar.Range.range_0) [SMTPat (range_singleton_trigger r)] = FStar.Sealed.sealed_singl r FStar.Range.range_0 noeq type ppname = { name : RT.pp_name_t; range : range }
{ "checked_file": "/", "dependencies": [ "Pulse.RuntimeUtils.fsti.checked", "Pulse.Reflection.Util.fst.checked", "prims.fst.checked", "FStar.Tactics.V2.fst.checked", "FStar.Sealed.Inhabited.fst.checked", "FStar.Sealed.fsti.checked", "FStar.Reflection.V2.fst.checked", "FStar.Reflection.Typing.Builtins.fsti.checked", "FStar.Reflection.Typing.fsti.checked", "FStar.Range.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked" ], "interface_file": false, "source_file": "Pulse.Syntax.Base.fsti" }
[ { "abbrev": false, "full_module": "FStar.List.Tot", "short_module": null }, { "abbrev": true, "full_module": "FStar.Tactics.V2", "short_module": "T" }, { "abbrev": true, "full_module": "Pulse.RuntimeUtils", "short_module": "RU" }, { "abbrev": true, "full_module": "FStar.Reflection.V2", "short_module": "R" }, { "abbrev": true, "full_module": "FStar.Reflection.Typing", "short_module": "RT" }, { "abbrev": true, "full_module": "FStar.Reflection.Typing.Builtins", "short_module": "RTB" }, { "abbrev": false, "full_module": "Pulse.Syntax", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Syntax", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": 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
Pulse.Syntax.Base.ppname
Prims.Tot
[ "total" ]
[]
[ "Pulse.Syntax.Base.Mkppname", "FStar.Sealed.seal", "Prims.string", "FStar.Range.range_0" ]
[]
false
false
false
true
false
let ppname_default =
{ name = FStar.Sealed.seal "_"; range = FStar.Range.range_0 }
false
LowParse.Low.Bytes.fst
LowParse.Low.Bytes.clens_vlbytes_get
val clens_vlbytes_get (min: nat) (max: nat{min <= max /\ max > 0 /\ max < 4294967296}) (i: U32.t) : Tot (clens (parse_bounded_vlbytes_t min max) byte)
val clens_vlbytes_get (min: nat) (max: nat{min <= max /\ max > 0 /\ max < 4294967296}) (i: U32.t) : Tot (clens (parse_bounded_vlbytes_t min max) byte)
let clens_vlbytes_get (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (i: U32.t) : Tot (clens (parse_bounded_vlbytes_t min max) byte) = { clens_cond = (fun (x: parse_bounded_vlbytes_t min max) -> U32.v i < BY.length x); clens_get = (fun (x: parse_bounded_vlbytes_t min max) -> (BY.get x i <: byte)); }
{ "file_name": "src/lowparse/LowParse.Low.Bytes.fst", "git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
{ "end_col": 1, "end_line": 773, "start_col": 0, "start_line": 765 }
module LowParse.Low.Bytes include LowParse.Spec.Bytes include LowParse.Low.Combinators include LowParse.Low.VLData include LowParse.Low.VLGen include LowParse.Low.Int module U32 = FStar.UInt32 module HS = FStar.HyperStack module B = LowStar.Monotonic.Buffer module BF = LowStar.Buffer // for local variables in store_bytes module BY = LowParse.Bytes32 module HST = FStar.HyperStack.ST module U8 = FStar.UInt8 module Cast = FStar.Int.Cast module U64 = FStar.UInt64 inline_for_extraction let validate_flbytes (sz: nat) (sz64: U64.t { U64.v sz64 == sz /\ sz < 4294967296 } ) : Tot (validator (parse_flbytes sz)) = validate_total_constant_size (parse_flbytes sz) sz64 () inline_for_extraction let jump_flbytes (sz: nat) (sz32: U32.t { U32.v sz32 == sz } ) : Tot (jumper (parse_flbytes sz)) = jump_constant_size (parse_flbytes sz) sz32 () let valid_flbytes_intro (h: HS.mem) (sz: nat { sz < 4294967296 } ) (#rrel #rel: _) (s: slice rrel rel) (pos: U32.t) : Lemma (requires (U32.v pos + sz <= U32.v s.len /\ live_slice h s)) (ensures ( valid_content_pos (parse_flbytes sz) h s pos (BY.hide (bytes_of_slice_from_to h s pos (pos `U32.add` U32.uint_to_t sz))) (pos `U32.add` U32.uint_to_t sz) )) = valid_facts (parse_flbytes sz) h s pos let valid_pos_flbytes_elim (h: HS.mem) (sz: nat { sz < 4294967296 } ) (#rrel #rel: _) (s: slice rrel rel) (pos pos' : U32.t) : Lemma (requires (valid_pos (parse_flbytes sz) h s pos pos')) (ensures (U32.v pos + sz == U32.v pos')) [SMTPat (valid_pos (parse_flbytes sz) h s pos pos')] = valid_facts (parse_flbytes sz) h s pos let valid_flbytes_elim (h: HS.mem) (sz: nat { sz < 4294967296 } ) (#rrel #rel: _) (s: slice rrel rel) (pos: U32.t) : Lemma (requires (valid (parse_flbytes sz) h s pos)) (ensures ( valid_content_pos (parse_flbytes sz) h s pos (BY.hide (bytes_of_slice_from_to h s pos (pos `U32.add` U32.uint_to_t sz))) (pos `U32.add` U32.uint_to_t sz) )) = valid_flbytes_intro h sz s pos let clens_flbytes_slice (sz: nat) (from: U32.t) (to: U32.t {U32.v from <= U32.v to /\ U32.v to <= sz } ) : Tot (clens (BY.lbytes sz) (BY.lbytes (U32.v to - U32.v from))) = { clens_cond = (fun _ -> True); clens_get = (fun (x: BY.lbytes sz) -> (BY.slice x from to <: BY.lbytes (U32.v to - U32.v from))); } #push-options "--z3rlimit 16" let gaccessor_flbytes_slice' (sz: nat { sz < 4294967296 } ) (from: U32.t) (to: U32.t {U32.v from <= U32.v to /\ U32.v to <= sz } ) : Tot (gaccessor' (parse_flbytes sz) (parse_flbytes (U32.v to - U32.v from)) (clens_flbytes_slice sz from to)) = fun (input: bytes) -> ( begin if Seq.length input < sz then (0) // dummy else (U32.v from) end) let gaccessor_flbytes_slice (sz: nat { sz < 4294967296 } ) (from: U32.t) (to: U32.t {U32.v from <= U32.v to /\ U32.v to <= sz } ) : Tot (gaccessor (parse_flbytes sz) (parse_flbytes (U32.v to - U32.v from)) (clens_flbytes_slice sz from to)) = assert (forall x . gaccessor_pre (parse_flbytes sz) (parse_flbytes (U32.v to - U32.v from)) (clens_flbytes_slice sz from to) x ==> sz <= Seq.length x); gaccessor_prop_equiv (parse_flbytes sz) (parse_flbytes (U32.v to - U32.v from)) (clens_flbytes_slice sz from to) (gaccessor_flbytes_slice' sz from to); gaccessor_flbytes_slice' sz from to inline_for_extraction let accessor_flbytes_slice (sz: nat { sz < 4294967296 } ) (from: U32.t) (to: U32.t {U32.v from <= U32.v to /\ U32.v to <= sz } ) : Tot (accessor (gaccessor_flbytes_slice sz from to)) = fun #rrel #rel input pos -> let h = HST.get () in [@inline_let] let _ = slice_access_eq h (gaccessor_flbytes_slice sz from to) input pos in pos `U32.add` from #pop-options let clens_flbytes_get (sz: nat) (i: U32.t { U32.v i < sz } ) : Tot (clens (BY.lbytes sz) byte) = { clens_cond = (fun _ -> True); clens_get = (fun (x: BY.lbytes sz) -> (BY.get x i <: byte)); } #push-options "--z3rlimit 16 --max_fuel 1" let gaccessor_flbytes_get' (sz: nat { sz < 4294967296 } ) (i: U32.t { U32.v i < sz } ) : Tot (gaccessor' (parse_flbytes sz) (parse_u8) (clens_flbytes_get sz i)) = fun (input: bytes) -> ( begin let res = if Seq.length input < U32.v i then (0) // dummy else (U32.v i) in let g () : Lemma (requires (gaccessor_pre (parse_flbytes sz) parse_u8 (clens_flbytes_get sz i) input)) (ensures (gaccessor_post (parse_flbytes sz) parse_u8 (clens_flbytes_get sz i) input res)) = parser_kind_prop_equiv (get_parser_kind parse_u8) parse_u8; assert (res == (U32.v i)); parse_u8_spec' (Seq.slice input (U32.v i) (U32.v i + 1)); parse_strong_prefix parse_u8 (Seq.slice input (U32.v i) (U32.v i + 1)) (Seq.slice input (U32.v i) (Seq.length input)) in Classical.move_requires g (); res end) #pop-options let gaccessor_flbytes_get (sz: nat { sz < 4294967296 } ) (i: U32.t { U32.v i < sz } ) : Tot (gaccessor (parse_flbytes sz) (parse_u8) (clens_flbytes_get sz i)) = assert (forall x . gaccessor_pre (parse_flbytes sz) (parse_u8) (clens_flbytes_get sz i) x ==> U32.v i <= Seq.length x); gaccessor_prop_equiv (parse_flbytes sz) (parse_u8) (clens_flbytes_get sz i) (gaccessor_flbytes_get' sz i); gaccessor_flbytes_get' sz i inline_for_extraction let accessor_flbytes_get (sz: nat { sz < 4294967296 } ) (i: U32.t { U32.v i < sz } ) : Tot (accessor (gaccessor_flbytes_get sz i)) = fun #rrel #rel input pos -> let h = HST.get () in [@inline_let] let _ = slice_access_eq h (gaccessor_flbytes_get sz i) input pos in pos `U32.add` i (* Temporary: flbytes as leaf values *) (* TODO: convert store_bytes to monotonic buffers, using the "writable" predicate *) #push-options "--z3rlimit 32" inline_for_extraction let store_bytes (src: BY.bytes) (src_from src_to: U32.t) (#rrel #rel: _) (dst: B.mbuffer byte rrel rel) (dst_pos: U32.t) : HST.Stack unit (requires (fun h -> B.live h dst /\ U32.v src_from <= U32.v src_to /\ U32.v src_to <= BY.length src /\ U32.v dst_pos + (U32.v src_to - U32.v src_from) <= B.length dst /\ writable dst (U32.v dst_pos) (U32.v dst_pos + (U32.v src_to - U32.v src_from)) h )) (ensures (fun h _ h' -> B.modifies (B.loc_buffer_from_to dst dst_pos (dst_pos `U32.add` (src_to `U32.sub` src_from))) h h' /\ Seq.slice (B.as_seq h' dst) (U32.v dst_pos) (U32.v dst_pos + (U32.v src_to - U32.v src_from)) == Seq.slice (BY.reveal src) (U32.v src_from) (U32.v src_to) )) = let h0 = HST.get () in HST.push_frame (); let h1 = HST.get () in let bi = BF.alloca 0ul 1ul in let h2 = HST.get () in let len = src_to `U32.sub` src_from in C.Loops.do_while (fun h stop -> B.modifies (B.loc_union (B.loc_region_only true (HS.get_tip h1)) (B.loc_buffer_from_to dst dst_pos (dst_pos `U32.add` len))) h2 h /\ B.live h bi /\ ( let i = Seq.index (B.as_seq h bi) 0 in U32.v i <= U32.v len /\ writable dst (U32.v dst_pos) (U32.v dst_pos + U32.v len) h /\ Seq.slice (B.as_seq h dst) (U32.v dst_pos) (U32.v dst_pos + U32.v i) `Seq.equal` Seq.slice (BY.reveal src) (U32.v src_from) (U32.v src_from + U32.v i) /\ (stop == true ==> i == len) )) (fun _ -> let i = B.index bi 0ul in if i = len then true else begin let x = BY.get src (src_from `U32.add` i) in mbuffer_upd dst (Ghost.hide (U32.v dst_pos)) (Ghost.hide (U32.v dst_pos + U32.v len)) (dst_pos `U32.add` i) x; let i' = i `U32.add` 1ul in B.upd bi 0ul i'; let h' = HST.get () in Seq.lemma_split (Seq.slice (B.as_seq h' dst) (U32.v dst_pos) (U32.v dst_pos + U32.v i')) (U32.v i); i' = len end ) ; HST.pop_frame () #pop-options inline_for_extraction let serialize32_flbytes (sz32: U32.t) : Tot (serializer32 (serialize_flbytes (U32.v sz32))) = fun (x: BY.lbytes (U32.v sz32)) #rrel #rel b pos -> let _ = store_bytes x 0ul sz32 b pos in sz32 inline_for_extraction let write_flbytes (sz32: U32.t) : Tot (leaf_writer_strong (serialize_flbytes (U32.v sz32))) = leaf_writer_strong_of_serializer32 (serialize32_flbytes sz32) () inline_for_extraction let write_flbytes_weak (sz32: U32.t { U32.v sz32 < 4294967295 } ) // need to return that value if output buffer is too small : Tot (leaf_writer_weak (serialize_flbytes (U32.v sz32))) = leaf_writer_weak_of_strong_constant_size (write_flbytes sz32) sz32 () (* // TODO: remove, since nobody is using this inline_for_extraction let read_flbytes (sz32: U32.t) : Tot (leaf_reader (parse_flbytes (U32.v sz32))) = fun input pos -> let h = HST.get () in [@inline_let] let _ = valid_facts (parse_flbytes (U32.v sz32)) h input pos in BY.of_buffer sz32 (B.sub input.base pos sz32) *) (* Equality test between a vlbytes and a constant lbytes *) #push-options "--z3rlimit 32" inline_for_extraction let buffer_equals_bytes (const: BY.bytes) (#rrel #rel: _) (b: B.mbuffer byte rrel rel) (pos: U32.t) : HST.Stack bool (requires (fun h -> B.live h b /\ U32.v pos + BY.length const <= B.length b )) (ensures (fun h res h' -> B.modifies B.loc_none h h' /\ (res == true <==> Seq.slice (B.as_seq h b) (U32.v pos) (U32.v pos + BY.length const) == BY.reveal const) )) = let h0 = HST.get () in HST.push_frame (); let len = BY.len const in let bi = BF.alloca 0ul 1ul in let bres = BF.alloca true 1ul in let h1 = HST.get () in [@inline_let] let inv (h: HS.mem) (stop: bool) : GTot Type0 = B.modifies (B.loc_union (B.loc_buffer bi) (B.loc_buffer bres)) h1 h /\ ( let length = U32.v len in let i32 = (Seq.index (B.as_seq h bi) 0) in let i = U32.v i32 in let res = Seq.index (B.as_seq h bres) 0 in i <= length /\ (stop == false ==> res == true) /\ ((stop == true /\ res == true) ==> i == length) /\ (res == true <==> Seq.slice (B.as_seq h b) (U32.v pos) (U32.v pos + i) `Seq.equal` Seq.slice (BY.reveal const) 0 i) ) in C.Loops.do_while inv (fun _ -> let i = B.index bi 0ul in if i = len then true else begin let i' = i `U32.add` 1ul in [@inline_let] let _ = let s1 = (Seq.slice (B.as_seq h0 b) (U32.v pos) (U32.v pos + U32.v i)) in let c1 = (B.get h0 b (U32.v pos + U32.v i)) in let s2 = (Seq.slice (BY.reveal const) 0 (U32.v i)) in let c2 = (BY.index const (U32.v i)) in assert (Seq.slice (B.as_seq h0 b) (U32.v pos) (U32.v pos + U32.v i') `Seq.equal` Seq.snoc s1 c1); assert (Seq.slice (BY.reveal const) 0 (U32.v i') `Seq.equal` Seq.snoc s2 c2); Classical.move_requires (Seq.lemma_snoc_inj s1 s2 c1) c2 in let res = B.index b (pos `U32.add` i) = BY.get const i in B.upd bres 0ul res; B.upd bi 0ul i'; not res end ); let res = B.index bres 0ul in HST.pop_frame (); res #pop-options inline_for_extraction let valid_slice_equals_bytes (const: BY.bytes) (#rrel #rel: _) (input: slice rrel rel) (pos: U32.t) : HST.Stack bool (requires (fun h -> valid (parse_flbytes (BY.length const)) h input pos )) (ensures (fun h res h' -> B.modifies B.loc_none h h' /\ (res == true <==> contents (parse_flbytes (BY.length const)) h input pos == const ))) = let h = HST.get () in [@inline_let] let _ = valid_facts (parse_flbytes (BY.length const)) h input pos in buffer_equals_bytes const input.base pos inline_for_extraction let validate_all_bytes () : Tot (validator parse_all_bytes) = fun #rrel #rel input pos -> let h = HST.get () in [@inline_let] let _ = valid_facts parse_all_bytes h input (uint64_to_uint32 pos) in Cast.uint32_to_uint64 input.len inline_for_extraction let validate_bounded_vlbytes' (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (l: nat { l >= log256' max /\ l <= 4 } ) : Tot (validator (parse_bounded_vlbytes' min max l)) = validate_synth (validate_bounded_vldata_strong' min max l serialize_all_bytes (validate_all_bytes ())) (synth_bounded_vlbytes min max) () inline_for_extraction let validate_bounded_vlbytes (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) : Tot (validator (parse_bounded_vlbytes min max)) = validate_bounded_vlbytes' min max (log256' max) inline_for_extraction let jump_all_bytes () : Tot (jumper parse_all_bytes) = fun #rrel #rel input pos -> let h = HST.get () in [@inline_let] let _ = valid_facts parse_all_bytes h input pos in input.len inline_for_extraction let jump_bounded_vlbytes' (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (l: nat { l >= log256' max /\ l <= 4 } ) : Tot (jumper (parse_bounded_vlbytes' min max l)) = jump_synth (jump_bounded_vldata_strong' min max l serialize_all_bytes) (synth_bounded_vlbytes min max) () inline_for_extraction let jump_bounded_vlbytes (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) : Tot (jumper (parse_bounded_vlbytes min max)) = jump_bounded_vlbytes' min max (log256' max) let valid_exact_all_bytes_elim (h: HS.mem) (#rrel #rel: _) (input: slice rrel rel) (pos pos' : U32.t) : Lemma (requires (valid_exact parse_all_bytes h input pos pos')) (ensures ( let x = contents_exact parse_all_bytes h input pos pos' in let length = U32.v pos' - U32.v pos in BY.length x == length /\ valid_content_pos (parse_flbytes length) h input pos x pos' )) = valid_exact_equiv parse_all_bytes h input pos pos' ; contents_exact_eq parse_all_bytes h input pos pos' ; let length = U32.v pos' - U32.v pos in valid_facts (parse_flbytes length) h input pos ; assert (no_lookahead_on (parse_flbytes length) (bytes_of_slice_from_to h input pos pos') (bytes_of_slice_from h input pos)); assert (injective_postcond (parse_flbytes length) (bytes_of_slice_from_to h input pos pos') (bytes_of_slice_from h input pos)) #push-options "--z3rlimit 32" let valid_bounded_vlbytes'_elim (h: HS.mem) (min: nat) (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (l: nat { l >= log256' max /\ l <= 4 } ) (#rrel #rel: _) (input: slice rrel rel) (pos: U32.t) : Lemma (requires ( valid (parse_bounded_vlbytes' min max l) h input pos )) (ensures ( let sz = l in valid (parse_bounded_integer sz) h input pos /\ ( let len_payload = contents (parse_bounded_integer sz) h input pos in min <= U32.v len_payload /\ U32.v len_payload <= max /\ sz + U32.v len_payload == content_length (parse_bounded_vlbytes' min max l) h input pos /\ ( let pos_payload = pos `U32.add` U32.uint_to_t sz in let x = contents (parse_bounded_vlbytes' min max l) h input pos in BY.len x == len_payload /\ valid_pos (parse_bounded_vlbytes' min max l) h input pos (pos_payload `U32.add` len_payload) /\ valid_content_pos (parse_flbytes (U32.v len_payload)) h input pos_payload x (pos_payload `U32.add` len_payload) )))) = valid_synth h (parse_bounded_vlbytes_aux min max l) (synth_bounded_vlbytes min max) input pos; valid_bounded_vldata_strong'_elim h min max l serialize_all_bytes input pos; let sz = l in let len_payload = contents (parse_bounded_integer sz) h input pos in let pos_payload = pos `U32.add` U32.uint_to_t sz in valid_exact_all_bytes_elim h input pos_payload (pos_payload `U32.add` len_payload); () #pop-options let valid_bounded_vlbytes_elim (h: HS.mem) (min: nat) (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (#rrel #rel: _) (input: slice rrel rel) (pos: U32.t) : Lemma (requires ( valid (parse_bounded_vlbytes min max) h input pos )) (ensures ( let sz = log256' max in valid (parse_bounded_integer sz) h input pos /\ ( let len_payload = contents (parse_bounded_integer sz) h input pos in min <= U32.v len_payload /\ U32.v len_payload <= max /\ sz + U32.v len_payload == content_length (parse_bounded_vlbytes min max) h input pos /\ ( let pos_payload = pos `U32.add` U32.uint_to_t sz in let x = contents (parse_bounded_vlbytes min max) h input pos in BY.len x == len_payload /\ valid_pos (parse_bounded_vlbytes min max) h input pos (pos_payload `U32.add` len_payload) /\ valid_content_pos (parse_flbytes (U32.v len_payload)) h input pos_payload x (pos_payload `U32.add` len_payload) )))) = valid_bounded_vlbytes'_elim h min max (log256' max) input pos let valid_bounded_vlbytes_elim_length (h: HS.mem) (min: nat) (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (#rrel #rel: _) (input: slice rrel rel) (pos: U32.t) : Lemma (requires ( valid (parse_bounded_vlbytes min max) h input pos )) (ensures ( content_length (parse_bounded_vlbytes min max) h input pos == log256' max + BY.length (contents (parse_bounded_vlbytes min max) h input pos) )) [SMTPat (valid (parse_bounded_vlbytes min max) h input pos)] = valid_bounded_vlbytes_elim h min max input pos inline_for_extraction let bounded_vlbytes'_payload_length (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (l: nat { l >= log256' max /\ l <= 4 } ) (#rrel #rel: _) (input: slice rrel rel) (pos: U32.t) : HST.Stack U32.t (requires (fun h -> valid (parse_bounded_vlbytes' min max l) h input pos)) (ensures (fun h len h' -> B.modifies B.loc_none h h' /\ U32.v pos + l + U32.v len <= U32.v input.len /\ ( let x = contents (parse_bounded_vlbytes' min max l) h input pos in let pos' = get_valid_pos (parse_bounded_vlbytes' min max l) h input pos in BY.len x == len /\ valid_content_pos (parse_flbytes (U32.v len)) h input (pos `U32.add` U32.uint_to_t l) x pos' /\ bytes_of_slice_from_to h input (pos `U32.add` U32.uint_to_t l) pos' == BY.reveal x ))) = let h = HST.get () in [@inline_let] let _ = valid_bounded_vlbytes'_elim h min max l input pos in let len = read_bounded_integer l input pos in [@inline_let] let _ = valid_flbytes_elim h (U32.v len) input (pos `U32.add` U32.uint_to_t l) in len inline_for_extraction let bounded_vlbytes_payload_length (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (#rrel #rel: _) (input: slice rrel rel) (pos: U32.t) : HST.Stack U32.t (requires (fun h -> valid (parse_bounded_vlbytes min max) h input pos)) (ensures (fun h len h' -> B.modifies B.loc_none h h' /\ U32.v pos + log256' max + U32.v len <= U32.v input.len /\ ( let x = contents (parse_bounded_vlbytes min max) h input pos in let pos' = get_valid_pos (parse_bounded_vlbytes min max) h input pos in BY.len x == len /\ valid_content_pos (parse_flbytes (U32.v len)) h input (pos `U32.add` U32.uint_to_t (log256' max)) x pos' /\ bytes_of_slice_from_to h input (pos `U32.add` U32.uint_to_t (log256' max)) pos' == BY.reveal x ))) = bounded_vlbytes'_payload_length min max (log256' max) input pos (* Get the content buffer (with trivial buffers only, not generalizable to monotonicity) *) #push-options "--z3rlimit 32" inline_for_extraction let get_vlbytes'_contents (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (l: nat { l >= log256' max /\ l <= 4 } ) (input: slice (srel_of_buffer_srel (BF.trivial_preorder _)) (srel_of_buffer_srel (BF.trivial_preorder _))) (pos: U32.t) : HST.Stack (BF.buffer byte) (requires (fun h -> valid (parse_bounded_vlbytes' min max l) h input pos)) (ensures (fun h b h' -> let x = contents (parse_bounded_vlbytes' min max l) h input pos in B.modifies B.loc_none h h' /\ U32.v pos + l + BY.length x <= U32.v input.len /\ b == BF.gsub input.base (pos `U32.add` U32.uint_to_t l) (BY.len x) /\ B.as_seq h b == BY.reveal x )) = let h = HST.get () in [@inline_let] let _ = valid_bounded_vlbytes'_elim h min max l input pos in let len = read_bounded_integer l input pos in [@inline_let] let _ = valid_facts (parse_flbytes (U32.v len)) h input (pos `U32.add` U32.uint_to_t l) in BF.sub input.base (pos `U32.add` U32.uint_to_t l) len #pop-options inline_for_extraction let get_vlbytes_contents (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (input: slice (srel_of_buffer_srel (BF.trivial_preorder _)) (srel_of_buffer_srel (BF.trivial_preorder _))) (pos: U32.t) : HST.Stack (BF.buffer byte) (requires (fun h -> valid (parse_bounded_vlbytes min max) h input pos)) (ensures (fun h b h' -> let l = log256' max in let x = contents (parse_bounded_vlbytes min max) h input pos in B.modifies B.loc_none h h' /\ U32.v pos + l + BY.length x <= U32.v input.len /\ b == BF.gsub input.base (pos `U32.add` U32.uint_to_t l) (BY.len x) /\ B.as_seq h b == BY.reveal x )) = get_vlbytes'_contents min max (log256' max) input pos (* In fact, the following accessors are not useful in practice, because users would need to have the flbytes parser combinator in their scope *) let clens_vlbytes_cond (min: nat) (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (length: nat) (x: parse_bounded_vlbytes_t min max) : GTot Type0 = BY.length x == length let clens_vlbytes (min: nat) (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (length: nat) : Tot (clens (parse_bounded_vlbytes_t min max) (BY.lbytes length)) = { clens_cond = (clens_vlbytes_cond min max length); clens_get = (fun (x: parse_bounded_vlbytes_t min max) -> (x <: Ghost (BY.lbytes length) (requires (clens_vlbytes_cond min max length x)) (ensures (fun _ -> True)))); } #push-options "--z3rlimit 16 --max_fuel 2 --initial_fuel 2 --max_ifuel 6 --initial_ifuel 6" let gaccessor_vlbytes'_aux (min: nat) (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (l: nat { l >= log256' max /\ l <= 4 } ) (length: nat { length < 4294967296 } ) : Tot (gaccessor' (parse_bounded_vlbytes' min max l) (parse_flbytes length) (clens_vlbytes min max length)) = fun (input: bytes) -> (begin let res = if Seq.length input >= l then (l) else (0) in let g () : Lemma (requires (gaccessor_pre (parse_bounded_vlbytes' min max l) (parse_flbytes length) (clens_vlbytes min max length) input)) (ensures (gaccessor_post (parse_bounded_vlbytes' min max l) (parse_flbytes length) (clens_vlbytes min max length) input res)) = parse_bounded_vlbytes_eq min max l input; parse_strong_prefix (parse_flbytes length) (Seq.slice input l (l + length)) (Seq.slice input l (Seq.length input)) in Classical.move_requires g (); res end) let gaccessor_vlbytes' (min: nat) (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (l: nat { l >= log256' max /\ l <= 4 } ) (length: nat { length < 4294967296 } ) : Tot (gaccessor (parse_bounded_vlbytes' min max l) (parse_flbytes length) (clens_vlbytes min max length)) = parser_kind_prop_equiv (parse_bounded_vldata_strong_kind min max l parse_all_bytes_kind) (parse_bounded_vlbytes' min max l); assert (forall x . gaccessor_pre (parse_bounded_vlbytes' min max l) (parse_flbytes length) (clens_vlbytes min max length) x ==> Seq.length x >= l); gaccessor_prop_equiv (parse_bounded_vlbytes' min max l) (parse_flbytes length) (clens_vlbytes min max length) (gaccessor_vlbytes'_aux min max l length); gaccessor_vlbytes'_aux min max l length #pop-options let gaccessor_vlbytes (min: nat) (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (length: nat { length < 4294967296 } ) : Tot (gaccessor (parse_bounded_vlbytes min max) (parse_flbytes length) (clens_vlbytes min max length)) = gaccessor_vlbytes' min max (log256' max) length #push-options "--z3rlimit 64 --max_fuel 2 --initial_fuel 2 --max_ifuel 6 --initial_ifuel 6" inline_for_extraction let accessor_vlbytes' (min: nat) (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (l: nat { l >= log256' max /\ l <= 4 } ) (length: U32.t) : Tot (accessor (gaccessor_vlbytes' min max l (U32.v length))) = fun #rrel #rel sl pos -> let h = HST.get () in [@inline_let] let _ = slice_access_eq h (gaccessor_vlbytes' min max l (U32.v length)) sl pos; valid_bounded_vlbytes'_elim h min max l sl pos; parse_bounded_vlbytes_eq min max l (bytes_of_slice_from h sl pos) in pos `U32.add` U32.uint_to_t l #pop-options inline_for_extraction let accessor_vlbytes (min: nat) (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (length: U32.t) : Tot (accessor (gaccessor_vlbytes min max (U32.v length))) = accessor_vlbytes' min max (log256' max) length let clens_vlbytes_slice (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (from: U32.t) (to: U32.t {U32.v from <= U32.v to /\ U32.v to <= max } ) : Tot (clens (parse_bounded_vlbytes_t min max) (BY.lbytes (U32.v to - U32.v from))) = { clens_cond = (fun (x: parse_bounded_vlbytes_t min max) -> U32.v to <= BY.length x); clens_get = (fun (x: parse_bounded_vlbytes_t min max) -> (BY.slice x from to <: BY.lbytes (U32.v to - U32.v from))); } #push-options "--z3rlimit 16" let gaccessor_vlbytes'_slice_aux (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (l: nat { l >= log256' max /\ l <= 4 } ) (from: U32.t) (to: U32.t {U32.v from <= U32.v to /\ U32.v to <= max } ) : Tot (gaccessor' (parse_bounded_vlbytes' min max l) (parse_flbytes (U32.v to - U32.v from)) (clens_vlbytes_slice min max from to)) = fun (input: bytes) -> ( begin parse_bounded_vlbytes_eq min max l input; if Seq.length input < l + U32.v to then (0) // dummy else (l + U32.v from) end) let gaccessor_vlbytes'_slice (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (l: nat { l >= log256' max /\ l <= 4 } ) (from: U32.t) (to: U32.t {U32.v from <= U32.v to /\ U32.v to <= max } ) : Tot (gaccessor (parse_bounded_vlbytes' min max l) (parse_flbytes (U32.v to - U32.v from)) (clens_vlbytes_slice min max from to)) = parser_kind_prop_equiv (parse_bounded_vldata_strong_kind min max l parse_all_bytes_kind) (parse_bounded_vlbytes' min max l); Classical.forall_intro (parse_bounded_vlbytes_eq min max l); assert (forall x . gaccessor_pre (parse_bounded_vlbytes' min max l) (parse_flbytes (U32.v to - U32.v from)) (clens_vlbytes_slice min max from to) x ==> l + U32.v to <= Seq.length x); gaccessor_prop_equiv (parse_bounded_vlbytes' min max l) (parse_flbytes (U32.v to - U32.v from)) (clens_vlbytes_slice min max from to) (gaccessor_vlbytes'_slice_aux min max l from to); gaccessor_vlbytes'_slice_aux min max l from to let gaccessor_vlbytes_slice (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (from: U32.t) (to: U32.t {U32.v from <= U32.v to /\ U32.v to <= max } ) : Tot (gaccessor (parse_bounded_vlbytes min max) (parse_flbytes (U32.v to - U32.v from)) (clens_vlbytes_slice min max from to)) = gaccessor_vlbytes'_slice min max (log256' max) from to #pop-options #push-options "--z3rlimit 50" inline_for_extraction let accessor_vlbytes'_slice (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (l: nat { l >= log256' max /\ l <= 4 } ) (from: U32.t) (to: U32.t {U32.v from <= U32.v to /\ U32.v to <= max } ) : Tot (accessor (gaccessor_vlbytes'_slice min max l from to)) = fun #rrel #rel input pos -> let h = HST.get () in [@inline_let] let _ = valid_facts (parse_bounded_vlbytes' min max l) h input pos; parse_bounded_vlbytes_eq min max l (bytes_of_slice_from h input pos); slice_access_eq h (gaccessor_vlbytes'_slice min max l from to) input pos in pos `U32.add` U32.uint_to_t l `U32.add` from #pop-options inline_for_extraction let accessor_vlbytes_slice (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (from: U32.t) (to: U32.t {U32.v from <= U32.v to /\ U32.v to <= max } ) : Tot (accessor (gaccessor_vlbytes_slice min max from to)) = accessor_vlbytes'_slice min max (log256' max) from to
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowStar.Monotonic.Buffer.fsti.checked", "LowStar.Buffer.fst.checked", "LowParse.Spec.Bytes.fst.checked", "LowParse.Low.VLGen.fst.checked", "LowParse.Low.VLData.fst.checked", "LowParse.Low.Int.fsti.checked", "LowParse.Low.Combinators.fsti.checked", "LowParse.Bytes32.fst.checked", "FStar.UInt8.fsti.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Int.Cast.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked", "FStar.Classical.fsti.checked", "C.Loops.fst.checked" ], "interface_file": false, "source_file": "LowParse.Low.Bytes.fst" }
[ { "abbrev": true, "full_module": "LowStar.Buffer // for local variables in store_bytes", "short_module": "BF" }, { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "FStar.Int.Cast", "short_module": "Cast" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "LowParse.Bytes32", "short_module": "BY" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "BF" }, { "abbrev": true, "full_module": "LowStar.Monotonic.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": false, "full_module": "LowParse.Low.Int", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low.VLGen", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low.VLData", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low.Combinators", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec.Bytes", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
min: Prims.nat -> max: Prims.nat{min <= max /\ max > 0 /\ max < 4294967296} -> i: FStar.UInt32.t -> LowParse.Low.Base.Spec.clens (LowParse.Spec.Bytes.parse_bounded_vlbytes_t min max) LowParse.Bytes.byte
Prims.Tot
[ "total" ]
[]
[ "Prims.nat", "Prims.l_and", "Prims.b2t", "Prims.op_LessThanOrEqual", "Prims.op_GreaterThan", "Prims.op_LessThan", "FStar.UInt32.t", "LowParse.Low.Base.Spec.Mkclens", "LowParse.Spec.Bytes.parse_bounded_vlbytes_t", "LowParse.Bytes.byte", "FStar.UInt32.v", "FStar.Bytes.length", "FStar.Bytes.get", "LowParse.Low.Base.Spec.clens" ]
[]
false
false
false
false
false
let clens_vlbytes_get (min: nat) (max: nat{min <= max /\ max > 0 /\ max < 4294967296}) (i: U32.t) : Tot (clens (parse_bounded_vlbytes_t min max) byte) =
{ clens_cond = (fun (x: parse_bounded_vlbytes_t min max) -> U32.v i < BY.length x); clens_get = (fun (x: parse_bounded_vlbytes_t min max) -> (BY.get x i <: byte)) }
false