file_name
stringlengths
5
52
name
stringlengths
4
95
original_source_type
stringlengths
0
23k
source_type
stringlengths
9
23k
source_definition
stringlengths
9
57.9k
source
dict
source_range
dict
file_context
stringlengths
0
721k
dependencies
dict
opens_and_abbrevs
listlengths
2
94
vconfig
dict
interleaved
bool
1 class
verbose_type
stringlengths
1
7.42k
effect
stringclasses
118 values
effect_flags
sequencelengths
0
2
mutual_with
sequencelengths
0
11
ideal_premises
sequencelengths
0
236
proof_features
sequencelengths
0
1
is_simple_lemma
bool
2 classes
is_div
bool
2 classes
is_proof
bool
2 classes
is_simply_typed
bool
2 classes
is_type
bool
2 classes
partial_definition
stringlengths
5
3.99k
completed_definiton
stringlengths
1
1.63M
isa_cross_project_example
bool
1 class
Vale.X64.Lemmas.fst
Vale.X64.Lemmas.eval_code_ts
val eval_code_ts (g: bool) (c: code) (s0: machine_state) (f0: fuel) (s1: machine_state) : Type0
val eval_code_ts (g: bool) (c: code) (s0: machine_state) (f0: fuel) (s1: machine_state) : Type0
let eval_code_ts (g:bool) (c:code) (s0:machine_state) (f0:fuel) (s1:machine_state) : Type0 = state_eq_opt g (BS.machine_eval_code c f0 s0) (Some s1)
{ "file_name": "vale/code/arch/x64/Vale.X64.Lemmas.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 57, "end_line": 296, "start_col": 0, "start_line": 295 }
module Vale.X64.Lemmas open FStar.Mul open Vale.X64.Machine_s open Vale.X64.State open Vale.X64.StateLemmas open Vale.X64.Instruction_s open Vale.X64.Bytes_Code_s module BS = Vale.X64.Machine_Semantics_s module ME = Vale.X64.Memory #reset-options "--initial_fuel 1 --max_fuel 1 --z3rlimit 100" #restart-solver let rec lemma_eq_instr_apply_eval_args (outs:list instr_out) (args:list instr_operand) (f:instr_args_t outs args) (oprs:instr_operands_t_args args) (s1 s2:machine_state) : Lemma (requires state_eq_S true s1 s2) (ensures BS.instr_apply_eval_args outs args f oprs s1 == BS.instr_apply_eval_args outs args f oprs s2) = let open BS in lemma_heap_ignore_ghost_machine s1.BS.ms_heap s2.BS.ms_heap; match args with | [] -> () | i::args -> ( let (v, oprs) : option (instr_val_t i) & instr_operands_t_args args = match i with | IOpEx i -> let oprs = coerce oprs in (instr_eval_operand_explicit i (fst oprs) s1, snd oprs) | IOpIm i -> (instr_eval_operand_implicit i s1, coerce oprs) in let f:arrow (instr_val_t i) (instr_args_t outs args) = coerce f in match v with | None -> () | Some v -> lemma_eq_instr_apply_eval_args outs args (f v) oprs s1 s2 ) #restart-solver let rec lemma_eq_instr_apply_eval_inouts (outs inouts:list instr_out) (args:list instr_operand) (f:instr_inouts_t outs inouts args) (oprs:instr_operands_t inouts args) (s1 s2:machine_state) : Lemma (requires state_eq_S true s1 s2) (ensures BS.instr_apply_eval_inouts outs inouts args f oprs s1 == BS.instr_apply_eval_inouts outs inouts args f oprs s2) = let open BS in lemma_heap_ignore_ghost_machine s1.BS.ms_heap s2.BS.ms_heap; match inouts with | [] -> lemma_eq_instr_apply_eval_args outs args f oprs s1 s2 | (Out, i)::inouts -> let oprs = match i with | IOpEx i -> snd #(instr_operand_t i) (coerce oprs) | IOpIm i -> coerce oprs in lemma_eq_instr_apply_eval_inouts outs inouts args (coerce f) oprs s1 s2 | (InOut, i)::inouts -> ( let (v, oprs) : option (instr_val_t i) & instr_operands_t inouts args = match i with | IOpEx i -> let oprs = coerce oprs in (instr_eval_operand_explicit i (fst oprs) s1, snd oprs) | IOpIm i -> (instr_eval_operand_implicit i s1, coerce oprs) in let f:arrow (instr_val_t i) (instr_inouts_t outs inouts args) = coerce f in match v with | None -> () | Some v -> lemma_eq_instr_apply_eval_inouts outs inouts args (f v) oprs s1 s2 ) #restart-solver #push-options "--z3rlimit_factor 2" let rec lemma_eq_instr_write_outputs (outs:list instr_out) (args:list instr_operand) (vs:instr_ret_t outs) (oprs:instr_operands_t outs args) (s1_orig s1 s2_orig s2:machine_state) : Lemma (requires state_eq_S true s1_orig s2_orig /\ state_eq_S true s1 s2) (ensures state_eq_S true (BS.instr_write_outputs outs args vs oprs s1_orig s1) (BS.instr_write_outputs outs args vs oprs s2_orig s2)) = let open BS in use_machine_state_equal (); lemma_heap_ignore_ghost_machine s1.BS.ms_heap s2.BS.ms_heap; lemma_heap_ignore_ghost_machine s1_orig.BS.ms_heap s2_orig.BS.ms_heap; allow_inversion tmaddr; match outs with | [] -> () | (_, i)::outs -> ( let ((v:instr_val_t i), (vs:instr_ret_t outs)) = match outs with | [] -> (vs, ()) | _::_ -> let vs = coerce vs in (fst vs, snd vs) in match i with | IOpEx i -> let oprs = coerce oprs in let s1 = instr_write_output_explicit i v (fst oprs) s1_orig s1 in let s2 = instr_write_output_explicit i v (fst oprs) s2_orig s2 in lemma_eq_instr_write_outputs outs args vs (snd oprs) s1_orig s1 s2_orig s2 | IOpIm i -> let s1 = instr_write_output_implicit i v s1_orig s1 in let s2 = instr_write_output_implicit i v s2_orig s2 in allow_inversion operand64; allow_inversion operand128; lemma_eq_instr_write_outputs outs args vs (coerce oprs) s1_orig s1 s2_orig s2 ) #pop-options #restart-solver let eval_ins_eq_instr (inst:BS.ins) (s1 s2:machine_state) : Lemma (requires Instr? inst /\ state_eq_S true s1 s2) (ensures state_eq_S true (BS.machine_eval_ins inst s1) (BS.machine_eval_ins inst s2)) = let open BS in let Instr it oprs ann = inst in let InstrTypeRecord #outs #args #havoc_flags' i = it in lemma_eq_instr_apply_eval_inouts outs outs args (instr_eval i) oprs s1 s2; let vs = instr_apply_eval outs args (instr_eval i) oprs s1 in let hav s = match havoc_flags' with | HavocFlags -> {s with ms_flags = havoc_flags} | PreserveFlags -> s in let s1' = hav s1 in let s2' = hav s2 in match vs with | None -> () | Some vs -> lemma_eq_instr_write_outputs outs args vs oprs s1 s1' s2 s2' let eval_code_eq_instr (inst:BS.ins) (f:fuel) (s1 s2:machine_state) : Lemma (requires Instr? inst /\ state_eq_S true s1 s2) (ensures state_eq_opt true (BS.machine_eval_code (Ins inst) f s1) (BS.machine_eval_code (Ins inst) f s2)) = reveal_opaque (`%BS.machine_eval_code_ins) BS.machine_eval_code_ins; eval_ins_eq_instr inst ({s1 with BS.ms_trace = []}) ({s2 with BS.ms_trace = []}) let eval_code_eq_dealloc (inst:BS.ins) (f:fuel) (s1 s2:machine_state) : Lemma (requires Dealloc? inst /\ state_eq_S true s1 s2) (ensures state_eq_opt true (BS.machine_eval_code (Ins inst) f s1) (BS.machine_eval_code (Ins inst) f s2)) = reveal_opaque (`%BS.machine_eval_code_ins) BS.machine_eval_code_ins; use_machine_state_equal (); lemma_heap_ignore_ghost_machine s1.BS.ms_heap s2.BS.ms_heap; allow_inversion tmaddr let eval_code_eq_alloc (inst:BS.ins) (f:fuel) (s1 s2:machine_state) : Lemma (requires Alloc? inst /\ state_eq_S true s1 s2) (ensures state_eq_opt true (BS.machine_eval_code (Ins inst) f s1) (BS.machine_eval_code (Ins inst) f s2)) = reveal_opaque (`%BS.machine_eval_code_ins) BS.machine_eval_code_ins; use_machine_state_equal (); lemma_heap_ignore_ghost_machine s1.BS.ms_heap s2.BS.ms_heap; allow_inversion tmaddr let eval_code_eq_push (inst:BS.ins) (f:fuel) (s1 s2:machine_state) : Lemma (requires Push? inst /\ state_eq_S true s1 s2) (ensures state_eq_opt true (BS.machine_eval_code (Ins inst) f s1) (BS.machine_eval_code (Ins inst) f s2)) = reveal_opaque (`%BS.machine_eval_code_ins) BS.machine_eval_code_ins; use_machine_state_equal (); lemma_heap_ignore_ghost_machine s1.BS.ms_heap s2.BS.ms_heap; allow_inversion tmaddr let eval_code_eq_pop (inst:BS.ins) (f:fuel) (s1 s2:machine_state) : Lemma (requires Pop? inst /\ state_eq_S true s1 s2) (ensures state_eq_opt true (BS.machine_eval_code (Ins inst) f s1) (BS.machine_eval_code (Ins inst) f s2)) = reveal_opaque (`%BS.machine_eval_code_ins) BS.machine_eval_code_ins; use_machine_state_equal (); lemma_heap_ignore_ghost_machine s1.BS.ms_heap s2.BS.ms_heap; allow_inversion tmaddr let eval_code_eq_ins (i:BS.ins) (f:fuel) (s1 s2:machine_state) : Lemma (requires state_eq_S true s1 s2) (ensures state_eq_opt true (BS.machine_eval_code (Ins i) f s1) (BS.machine_eval_code (Ins i) f s2)) = match i with | Instr _ _ _ -> eval_code_eq_instr i f s1 s2 | Dealloc _ -> eval_code_eq_dealloc i f s1 s2 | Alloc _ -> eval_code_eq_alloc i f s1 s2 | Push _ _ -> eval_code_eq_push i f s1 s2 | Pop _ _ -> eval_code_eq_pop i f s1 s2 #reset-options "--fuel 2 --z3rlimit 30" let eval_ocmp_eq_core (g:bool) (cond:ocmp) (s:machine_state) : Lemma (ensures ( let (s1, b1) = BS.machine_eval_ocmp s cond in let (s2, b2) = BS.machine_eval_ocmp (core_state g s) cond in state_eq_S g s1 s2 /\ b1 == b2 )) = reveal_opaque (`%BS.valid_ocmp_opaque) BS.valid_ocmp_opaque; reveal_opaque (`%BS.eval_ocmp_opaque) BS.eval_ocmp_opaque; () #restart-solver let rec eval_code_eq_core (g:bool) (c:code) (f:fuel) (s:machine_state) : Lemma (ensures state_eq_opt g (BS.machine_eval_code c f s) (BS.machine_eval_code c f (core_state g s))) (decreases %[f; c]) = match c with | Ins i -> reveal_opaque (`%BS.machine_eval_code_ins) BS.machine_eval_code_ins; if g then eval_code_eq_ins i f s (core_state g s) | Block cs -> eval_codes_eq_core g cs f s | IfElse cond ct cf -> eval_ocmp_eq_core g cond s; let (s', _) = BS.machine_eval_ocmp s cond in let (t', _) = BS.machine_eval_ocmp (core_state g s) cond in eval_code_eq_core g ct f s'; eval_code_eq_core g ct f t'; eval_code_eq_core g cf f s'; eval_code_eq_core g cf f t'; () | While cond body -> eval_while_eq_core g cond body f s and eval_codes_eq_core (g:bool) (cs:codes) (f:fuel) (s:machine_state) : Lemma (ensures state_eq_opt g (BS.machine_eval_codes cs f s) (BS.machine_eval_codes cs f (core_state g s))) (decreases %[f; cs]) = match cs with | [] -> () | c'::cs' -> ( eval_code_eq_core g c' f s; match (machine_eval_code c' f s, machine_eval_code c' f (core_state g s)) with | (None, None) -> () | (Some s', Some t') -> eval_codes_eq_core g cs' f s'; eval_codes_eq_core g cs' f t' ) and eval_while_eq_core (g:bool) (cond:ocmp) (body:code) (f:fuel) (s:machine_state) : Lemma (ensures state_eq_opt g (BS.machine_eval_while cond body f s) (BS.machine_eval_while cond body f (core_state g s))) (decreases %[f; body]) = if f > 0 then ( eval_ocmp_eq_core g cond s; let (s1, _) = BS.machine_eval_ocmp s cond in let (t1, _) = BS.machine_eval_ocmp (core_state g s) cond in eval_code_eq_core g body (f - 1) s1; eval_code_eq_core g body (f - 1) t1; match (BS.machine_eval_code body (f - 1) s1, BS.machine_eval_code body (f - 1) t1) with | (None, None) -> () | (Some s2, Some t2) -> eval_while_eq_core g cond body (f - 1) s2; eval_while_eq_core g cond body (f - 1) t2; () ) let eval_code_eq_f (c:code) (f:fuel) (s1 s2:machine_state) : Lemma (requires state_eq_S false s1 s2) (ensures state_eq_opt false (BS.machine_eval_code c f s1) (BS.machine_eval_code c f s2)) [SMTPat (BS.machine_eval_code c f s1); SMTPat (BS.machine_eval_code c f s2)] = eval_code_eq_core false c f s1; eval_code_eq_core false c f s2 let eval_codes_eq_f (cs:codes) (f:fuel) (s1 s2:machine_state) : Lemma (requires state_eq_S false s1 s2) (ensures state_eq_opt false (BS.machine_eval_codes cs f s1) (BS.machine_eval_codes cs f s2)) [SMTPat (BS.machine_eval_codes cs f s1); SMTPat (BS.machine_eval_codes cs f s2)] = eval_codes_eq_core false cs f s1; eval_codes_eq_core false cs f s2 let eval_while_eq_f (cond:ocmp) (body:code) (f:fuel) (s1 s2:machine_state) : Lemma (requires state_eq_S false s1 s2) (ensures state_eq_opt false (BS.machine_eval_while cond body f s1) (BS.machine_eval_while cond body f s2)) [SMTPat (BS.machine_eval_while cond body f s1); SMTPat (BS.machine_eval_while cond body f s2)] = eval_while_eq_core false cond body f s1; eval_while_eq_core false cond body f s2 let eval_code_eq_t (c:code) (f:fuel) (s1 s2:machine_state) : Lemma (requires state_eq_S true s1 s2) (ensures state_eq_opt true (BS.machine_eval_code c f s1) (BS.machine_eval_code c f s2)) [SMTPat (BS.machine_eval_code c f s1); SMTPat (BS.machine_eval_code c f s2)] = eval_code_eq_core true c f s1; eval_code_eq_core true c f s2 let eval_codes_eq_t (cs:codes) (f:fuel) (s1 s2:machine_state) : Lemma (requires state_eq_S true s1 s2) (ensures state_eq_opt true (BS.machine_eval_codes cs f s1) (BS.machine_eval_codes cs f s2)) [SMTPat (BS.machine_eval_codes cs f s1); SMTPat (BS.machine_eval_codes cs f s2)] = eval_codes_eq_core true cs f s1; eval_codes_eq_core true cs f s2 let eval_while_eq_t (cond:ocmp) (body:code) (f:fuel) (s1 s2:machine_state) : Lemma (requires state_eq_S true s1 s2) (ensures state_eq_opt true (BS.machine_eval_while cond body f s1) (BS.machine_eval_while cond body f s2)) [SMTPat (BS.machine_eval_while cond body f s1); SMTPat (BS.machine_eval_while cond body f s2)] = eval_while_eq_core true cond body f s1; eval_while_eq_core true cond body f s2
{ "checked_file": "/", "dependencies": [ "Vale.X64.StateLemmas.fsti.checked", "Vale.X64.State.fsti.checked", "Vale.X64.Memory.fsti.checked", "Vale.X64.Machine_Semantics_s.fst.checked", "Vale.X64.Machine_s.fst.checked", "Vale.X64.Instruction_s.fsti.checked", "Vale.X64.Flags.fsti.checked", "Vale.X64.Bytes_Code_s.fst.checked", "prims.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.FunctionalExtensionality.fsti.checked" ], "interface_file": true, "source_file": "Vale.X64.Lemmas.fst" }
[ { "abbrev": true, "full_module": "Vale.X64.Memory", "short_module": "ME" }, { "abbrev": true, "full_module": "Vale.X64.Machine_Semantics_s", "short_module": "BS" }, { "abbrev": false, "full_module": "Vale.X64.Bytes_Code_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Instruction_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.StateLemmas", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.State", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Machine_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": true, "full_module": "Vale.Lib.Map16", "short_module": "Map16" }, { "abbrev": true, "full_module": "Vale.X64.Machine_Semantics_s", "short_module": "BS" }, { "abbrev": false, "full_module": "Vale.X64.Bytes_Code_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.StateLemmas", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.State", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Machine_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.HeapLemmas", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.HeapImpl", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.Heap", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 0, "max_fuel": 2, "max_ifuel": 1, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": true, "smtencoding_l_arith_repr": "native", "smtencoding_nl_arith_repr": "wrapped", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [ "smt.arith.nl=false", "smt.QI.EAGER_THRESHOLD=100", "smt.CASE_SPLIT=3" ], "z3refresh": false, "z3rlimit": 30, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
g: Prims.bool -> c: Vale.X64.StateLemmas.code -> s0: Vale.X64.StateLemmas.machine_state -> f0: Vale.X64.Lemmas.fuel -> s1: Vale.X64.StateLemmas.machine_state -> Type0
Prims.Tot
[ "total" ]
[]
[ "Prims.bool", "Vale.X64.StateLemmas.code", "Vale.X64.StateLemmas.machine_state", "Vale.X64.Lemmas.fuel", "Vale.X64.Lemmas.state_eq_opt", "Vale.X64.Machine_Semantics_s.machine_eval_code", "FStar.Pervasives.Native.Some", "Vale.X64.Machine_Semantics_s.machine_state" ]
[]
false
false
false
true
true
let eval_code_ts (g: bool) (c: code) (s0: machine_state) (f0: fuel) (s1: machine_state) : Type0 =
state_eq_opt g (BS.machine_eval_code c f0 s0) (Some s1)
false
Hacl.Bignum.fst
Hacl.Bignum.bn_from_bytes_le
val bn_from_bytes_le: #t:limb_t -> len:size_t{0 < v len /\ numbytes t * v (blocks len (size (numbytes t))) <= max_size_t} -> b:lbuffer uint8 len -> res:lbignum t (blocks len (size (numbytes t))) -> Stack unit (requires fun h -> live h b /\ live h res /\ disjoint res b) (ensures fun h0 _ h1 -> modifies (loc res) h0 h1 /\ as_seq h1 res == S.bn_from_bytes_le (v len) (as_seq h0 b))
val bn_from_bytes_le: #t:limb_t -> len:size_t{0 < v len /\ numbytes t * v (blocks len (size (numbytes t))) <= max_size_t} -> b:lbuffer uint8 len -> res:lbignum t (blocks len (size (numbytes t))) -> Stack unit (requires fun h -> live h b /\ live h res /\ disjoint res b) (ensures fun h0 _ h1 -> modifies (loc res) h0 h1 /\ as_seq h1 res == S.bn_from_bytes_le (v len) (as_seq h0 b))
let bn_from_bytes_le #t len b res = Hacl.Bignum.Convert.bn_from_bytes_le len b res
{ "file_name": "code/bignum/Hacl.Bignum.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 48, "end_line": 162, "start_col": 0, "start_line": 161 }
module Hacl.Bignum friend Hacl.Spec.Bignum #reset-options "--z3rlimit 50 --fuel 0 --ifuel 0" let bn_add1 #t aLen a b1 res = Hacl.Bignum.Addition.bn_add1 aLen a b1 res let bn_sub1 #t aLen a b1 res = Hacl.Bignum.Addition.bn_sub1 aLen a b1 res let bn_add_eq_len #t aLen a b res = Hacl.Bignum.Addition.bn_add_eq_len aLen a b res let bn_sub_eq_len #t aLen a b res = Hacl.Bignum.Addition.bn_sub_eq_len aLen a b res let bn_add #t aLen a bLen b res = Hacl.Bignum.Addition.bn_add aLen a bLen b res let bn_sub #t aLen a bLen b res = Hacl.Bignum.Addition.bn_sub aLen a bLen b res let bn_reduce_once #t len n c0 res = push_frame (); let tmp = create len (uint #t 0) in let c1 = bn_sub_eq_len len res n tmp in let c = c0 -. c1 in map2T len res (mask_select c) res tmp; pop_frame() let bn_add_mod_n #t len n a b res = let c0 = bn_add_eq_len len a b res in bn_reduce_once len n c0 res let bn_sub_mod_n #t len n a b res = push_frame (); let c0 = bn_sub_eq_len len a b res in let tmp = create len (uint #t 0) in let c1 = bn_add_eq_len len res n tmp in LowStar.Ignore.ignore c1; let c = uint #t 0 -. c0 in map2T len res (mask_select c) tmp res; pop_frame () let bn_mul1 #t aLen a l res = Hacl.Bignum.Multiplication.bn_mul1 #t aLen a l res let bn_karatsuba_mul #t len a b res = let h0 = ST.get () in Hacl.Spec.Bignum.bn_karatsuba_mul_lemma (as_seq h0 a) (as_seq h0 b); Hacl.Bignum.Karatsuba.bn_karatsuba_mul len a b res let bn_mul #t aLen bLen a b res = Hacl.Bignum.Multiplication.bn_mul aLen a bLen b res let bn_karatsuba_sqr #t len a res = let h0 = ST.get () in Hacl.Spec.Bignum.bn_karatsuba_sqr_lemma (as_seq h0 a); Hacl.Bignum.Karatsuba.bn_karatsuba_sqr len a res let bn_sqr #t len a res = let h0 = ST.get () in Hacl.Spec.Bignum.bn_sqr_lemma (as_seq h0 a); Hacl.Bignum.Multiplication.bn_sqr len a res let bn_mul1_lshift_add_in_place #t aLen a b j res = Hacl.Bignum.Multiplication.bn_mul1_lshift_add aLen a b j res let bn_rshift #t len b i res = copy res (sub b i (len -! i)) let bn_sub_mask #t len n a = push_frame (); let mask = create 1ul (ones t SEC) in let mod_mask = create len (uint #t 0) in let mask = Lib.ByteBuffer.buf_eq_mask n a len mask in mapT len mod_mask (logand mask) n; let _ = Hacl.Bignum.Addition.bn_sub_eq_len len a mod_mask a in pop_frame () let bn_get_ith_bit #t len input ind = Hacl.Bignum.Lib.bn_get_ith_bit len input ind let bn_get_bits #t len b i l = Hacl.Bignum.Lib.bn_get_bits len b i l let bn_set_ith_bit #t len input ind = Hacl.Bignum.Lib.bn_set_ith_bit len input ind (* conditional swap *) let cswap2 #t len bit b1 b2 = Hacl.Bignum.Lib.cswap2_st len bit b1 b2 let bn_add_mod_n_u32 (len:size_t{v len > 0}) : bn_add_mod_n_st U32 len = bn_add_mod_n len let bn_add_mod_n_u64 (len:size_t{v len > 0}) : bn_add_mod_n_st U64 len = bn_add_mod_n len inline_for_extraction noextract let bn_add_mod_n_ (#t:limb_t) (len:size_t{v len > 0}) : bn_add_mod_n_st t len = match t with | U32 -> bn_add_mod_n_u32 len | U64 -> bn_add_mod_n_u64 len let bn_sub_mod_n_u32 (len:size_t{v len > 0}) : bn_sub_mod_n_st U32 len = bn_sub_mod_n len let bn_sub_mod_n_u64 (len:size_t{v len > 0}) : bn_sub_mod_n_st U64 len = bn_sub_mod_n len inline_for_extraction noextract let bn_sub_mod_n_ (#t:limb_t) (len:size_t{v len > 0}) : bn_sub_mod_n_st t len = match t with | U32 -> bn_sub_mod_n_u32 len | U64 -> bn_sub_mod_n_u64 len /// This is a default implementation that *will* generate code depending on /// `len` at run-time! Only use if you want to generate run-time generic /// functions! let mk_runtime_bn (t:limb_t) (len:meta_len t) : bn t = { len = len; add = Hacl.Bignum.Addition.bn_add_eq_len_u len; sub = Hacl.Bignum.Addition.bn_sub_eq_len_u len; add_mod_n = bn_add_mod_n_ len; sub_mod_n = bn_sub_mod_n_ len; mul = bn_karatsuba_mul len; sqr = bn_karatsuba_sqr len; } let mk_runtime_bn_len_lemma t len = () (* bignum comparison and test functions *) let bn_is_odd #t len a = Hacl.Bignum.Comparison.bn_is_odd len a let bn_eq_mask #t len a b = Hacl.Bignum.Comparison.bn_eq_mask len a b let bn_is_zero_mask #t len b = Hacl.Bignum.Comparison.bn_is_zero_mask len b let bn_lt_mask #t len a b = Hacl.Bignum.Comparison.bn_lt_mask len a b let bn_lt_pow2_mask #t len b x = Hacl.Bignum.Comparison.bn_lt_pow2_mask len b x let bn_gt_pow2_mask #t len b x = Hacl.Bignum.Comparison.bn_gt_pow2_mask len b x (* Convertion functions *) let bn_from_uint #t len x b = Hacl.Bignum.Convert.bn_from_uint len x b let bn_from_bytes_be #t len b res = Hacl.Bignum.Convert.bn_from_bytes_be len b res let bn_to_bytes_be #t len b res = Hacl.Bignum.Convert.bn_to_bytes_be len b res
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowStar.Ignore.fsti.checked", "Lib.ByteBuffer.fsti.checked", "Hacl.Spec.Bignum.fst.checked", "Hacl.Bignum.Multiplication.fst.checked", "Hacl.Bignum.Lib.fst.checked", "Hacl.Bignum.Karatsuba.fst.checked", "Hacl.Bignum.Convert.fst.checked", "Hacl.Bignum.Comparison.fst.checked", "Hacl.Bignum.Addition.fst.checked", "FStar.UInt32.fsti.checked", "FStar.ST.fst.checked", "FStar.Pervasives.fsti.checked" ], "interface_file": true, "source_file": "Hacl.Bignum.fst" }
[ { "abbrev": true, "full_module": "Lib.LoopCombinators", "short_module": "Loops" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": true, "full_module": "Hacl.Spec.Bignum", "short_module": "S" }, { "abbrev": false, "full_module": "Hacl.Bignum.Definitions", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Bignum.Base", "short_module": null }, { "abbrev": false, "full_module": "Lib.Buffer", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack", "short_module": null }, { "abbrev": false, "full_module": "Hacl", "short_module": null }, { "abbrev": false, "full_module": "Hacl", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "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
len: Lib.IntTypes.size_t { 0 < Lib.IntTypes.v len /\ Lib.IntTypes.numbytes t * Lib.IntTypes.v (Hacl.Bignum.Definitions.blocks len (Lib.IntTypes.size (Lib.IntTypes.numbytes t))) <= Lib.IntTypes.max_size_t } -> b: Lib.Buffer.lbuffer Lib.IntTypes.uint8 len -> res: Hacl.Bignum.Definitions.lbignum t (Hacl.Bignum.Definitions.blocks len (Lib.IntTypes.size (Lib.IntTypes.numbytes t))) -> FStar.HyperStack.ST.Stack Prims.unit
FStar.HyperStack.ST.Stack
[]
[]
[ "Hacl.Bignum.Definitions.limb_t", "Lib.IntTypes.size_t", "Prims.l_and", "Prims.b2t", "Prims.op_LessThan", "Lib.IntTypes.v", "Lib.IntTypes.U32", "Lib.IntTypes.PUB", "Prims.op_LessThanOrEqual", "FStar.Mul.op_Star", "Lib.IntTypes.numbytes", "Hacl.Bignum.Definitions.blocks", "Lib.IntTypes.size", "Lib.IntTypes.max_size_t", "Lib.Buffer.lbuffer", "Lib.IntTypes.uint8", "Hacl.Bignum.Definitions.lbignum", "Hacl.Bignum.Convert.bn_from_bytes_le", "Prims.unit" ]
[]
false
true
false
false
false
let bn_from_bytes_le #t len b res =
Hacl.Bignum.Convert.bn_from_bytes_le len b res
false
Hacl.Impl.Ed25519.Ladder.fst
Hacl.Impl.Ed25519.Ladder.point_mul_g_double_vartime_table
val point_mul_g_double_vartime_table: out:point -> scalar1:lbuffer uint64 4ul -> q1:point -> scalar2:lbuffer uint64 4ul -> q2:point -> Stack unit (requires fun h -> live h out /\ live h scalar1 /\ live h q1 /\ live h scalar2 /\ live h q2 /\ eq_or_disjoint q1 q2 /\ disjoint out q1 /\ disjoint out q2 /\ disjoint out scalar1 /\ disjoint out scalar2 /\ BD.bn_v h scalar1 < pow2 256 /\ BD.bn_v h scalar2 < pow2 256 /\ F51.linv (as_seq h q1) /\ F51.linv (as_seq h q2) /\ F51.point_eval h q1 == g_c) (ensures fun h0 _ h1 -> modifies (loc out) h0 h1 /\ F51.linv (as_seq h1 out) /\ S.to_aff_point (F51.point_eval h1 out) == LE.exp_double_fw #S.aff_point_c S.mk_ed25519_comm_monoid (S.to_aff_point (F51.point_eval h0 q1)) 256 (BD.bn_v h0 scalar1) (S.to_aff_point (F51.point_eval h0 q2)) (BD.bn_v h0 scalar2) 5)
val point_mul_g_double_vartime_table: out:point -> scalar1:lbuffer uint64 4ul -> q1:point -> scalar2:lbuffer uint64 4ul -> q2:point -> Stack unit (requires fun h -> live h out /\ live h scalar1 /\ live h q1 /\ live h scalar2 /\ live h q2 /\ eq_or_disjoint q1 q2 /\ disjoint out q1 /\ disjoint out q2 /\ disjoint out scalar1 /\ disjoint out scalar2 /\ BD.bn_v h scalar1 < pow2 256 /\ BD.bn_v h scalar2 < pow2 256 /\ F51.linv (as_seq h q1) /\ F51.linv (as_seq h q2) /\ F51.point_eval h q1 == g_c) (ensures fun h0 _ h1 -> modifies (loc out) h0 h1 /\ F51.linv (as_seq h1 out) /\ S.to_aff_point (F51.point_eval h1 out) == LE.exp_double_fw #S.aff_point_c S.mk_ed25519_comm_monoid (S.to_aff_point (F51.point_eval h0 q1)) 256 (BD.bn_v h0 scalar1) (S.to_aff_point (F51.point_eval h0 q2)) (BD.bn_v h0 scalar2) 5)
let point_mul_g_double_vartime_table out scalar1 q1 scalar2 q2 = [@inline_let] let len = 20ul in [@inline_let] let ctx_len = 0ul in [@inline_let] let k = mk_ed25519_concrete_ops in [@inline_let] let table_len = 32ul in assert_norm (pow2 5 == v table_len); push_frame (); let table2 = create (table_len *! len) (u64 0) in PT.lprecomp_table len ctx_len k (null uint64) q2 table_len table2; point_mul_g_double_vartime_noalloc out scalar1 q1 scalar2 q2 table2; pop_frame ()
{ "file_name": "code/ed25519/Hacl.Impl.Ed25519.Ladder.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 14, "end_line": 335, "start_col": 0, "start_line": 323 }
module Hacl.Impl.Ed25519.Ladder module ST = FStar.HyperStack.ST open FStar.HyperStack.All open FStar.Mul open Lib.IntTypes open Lib.Buffer open Hacl.Bignum25519 module F51 = Hacl.Impl.Ed25519.Field51 module BSeq = Lib.ByteSequence module LE = Lib.Exponentiation module SE = Spec.Exponentiation module BE = Hacl.Impl.Exponentiation module ME = Hacl.Impl.MultiExponentiation module PT = Hacl.Impl.PrecompTable module SPT256 = Hacl.Spec.PrecompBaseTable256 module BD = Hacl.Bignum.Definitions module SD = Hacl.Spec.Bignum.Definitions module S = Spec.Ed25519 open Hacl.Impl.Ed25519.PointConstants include Hacl.Impl.Ed25519.Group include Hacl.Ed25519.PrecompTable #set-options "--z3rlimit 50 --fuel 0 --ifuel 0" inline_for_extraction noextract let table_inv_w4 : BE.table_inv_t U64 20ul 16ul = [@inline_let] let len = 20ul in [@inline_let] let ctx_len = 0ul in [@inline_let] let k = mk_ed25519_concrete_ops in [@inline_let] let l = 4ul in [@inline_let] let table_len = 16ul in BE.table_inv_precomp len ctx_len k l table_len inline_for_extraction noextract let table_inv_w5 : BE.table_inv_t U64 20ul 32ul = [@inline_let] let len = 20ul in [@inline_let] let ctx_len = 0ul in [@inline_let] let k = mk_ed25519_concrete_ops in [@inline_let] let l = 5ul in [@inline_let] let table_len = 32ul in assert_norm (pow2 (v l) = v table_len); BE.table_inv_precomp len ctx_len k l table_len inline_for_extraction noextract val convert_scalar: scalar:lbuffer uint8 32ul -> bscalar:lbuffer uint64 4ul -> Stack unit (requires fun h -> live h scalar /\ live h bscalar /\ disjoint scalar bscalar) (ensures fun h0 _ h1 -> modifies (loc bscalar) h0 h1 /\ BD.bn_v h1 bscalar == BSeq.nat_from_bytes_le (as_seq h0 scalar)) let convert_scalar scalar bscalar = let h0 = ST.get () in Hacl.Spec.Bignum.Convert.bn_from_bytes_le_lemma #U64 32 (as_seq h0 scalar); Hacl.Bignum.Convert.mk_bn_from_bytes_le true 32ul scalar bscalar inline_for_extraction noextract val point_mul_noalloc: out:point -> bscalar:lbuffer uint64 4ul -> q:point -> Stack unit (requires fun h -> live h bscalar /\ live h q /\ live h out /\ disjoint q out /\ disjoint q bscalar /\ disjoint out bscalar /\ F51.point_inv_t h q /\ F51.inv_ext_point (as_seq h q) /\ BD.bn_v h bscalar < pow2 256) (ensures fun h0 _ h1 -> modifies (loc out) h0 h1 /\ F51.point_inv_t h1 out /\ F51.inv_ext_point (as_seq h1 out) /\ S.to_aff_point (F51.point_eval h1 out) == LE.exp_fw S.mk_ed25519_comm_monoid (S.to_aff_point (F51.point_eval h0 q)) 256 (BD.bn_v h0 bscalar) 4) let point_mul_noalloc out bscalar q = BE.lexp_fw_consttime 20ul 0ul mk_ed25519_concrete_ops 4ul (null uint64) q 4ul 256ul bscalar out let point_mul out scalar q = let h0 = ST.get () in SE.exp_fw_lemma S.mk_ed25519_concrete_ops (F51.point_eval h0 q) 256 (BSeq.nat_from_bytes_le (as_seq h0 scalar)) 4; push_frame (); let bscalar = create 4ul (u64 0) in convert_scalar scalar bscalar; point_mul_noalloc out bscalar q; pop_frame () val precomp_get_consttime: BE.pow_a_to_small_b_st U64 20ul 0ul mk_ed25519_concrete_ops 4ul 16ul (BE.table_inv_precomp 20ul 0ul mk_ed25519_concrete_ops 4ul 16ul) [@CInline] let precomp_get_consttime ctx a table bits_l tmp = [@inline_let] let len = 20ul in [@inline_let] let ctx_len = 0ul in [@inline_let] let k = mk_ed25519_concrete_ops in [@inline_let] let l = 4ul in [@inline_let] let table_len = 16ul in BE.lprecomp_get_consttime len ctx_len k l table_len ctx a table bits_l tmp inline_for_extraction noextract val point_mul_g_noalloc: out:point -> bscalar:lbuffer uint64 4ul -> q1:point -> q2:point -> q3:point -> q4:point -> Stack unit (requires fun h -> live h bscalar /\ live h out /\ live h q1 /\ live h q2 /\ live h q3 /\ live h q4 /\ disjoint out bscalar /\ disjoint out q1 /\ disjoint out q2 /\ disjoint out q3 /\ disjoint out q4 /\ disjoint q1 q2 /\ disjoint q1 q3 /\ disjoint q1 q4 /\ disjoint q2 q3 /\ disjoint q2 q4 /\ disjoint q3 q4 /\ BD.bn_v h bscalar < pow2 256 /\ F51.linv (as_seq h q1) /\ refl (as_seq h q1) == g_aff /\ F51.linv (as_seq h q2) /\ refl (as_seq h q2) == g_pow2_64 /\ F51.linv (as_seq h q3) /\ refl (as_seq h q3) == g_pow2_128 /\ F51.linv (as_seq h q4) /\ refl (as_seq h q4) == g_pow2_192) (ensures fun h0 _ h1 -> modifies (loc out) h0 h1 /\ F51.linv (as_seq h1 out) /\ (let (b0, b1, b2, b3) = SPT256.decompose_nat256_as_four_u64 (BD.bn_v h0 bscalar) in S.to_aff_point (F51.point_eval h1 out) == LE.exp_four_fw S.mk_ed25519_comm_monoid g_aff 64 b0 g_pow2_64 b1 g_pow2_128 b2 g_pow2_192 b3 4)) let point_mul_g_noalloc out bscalar q1 q2 q3 q4 = [@inline_let] let len = 20ul in [@inline_let] let ctx_len = 0ul in [@inline_let] let k = mk_ed25519_concrete_ops in [@inline_let] let l = 4ul in [@inline_let] let table_len = 16ul in [@inline_let] let bLen = 1ul in [@inline_let] let bBits = 64ul in let h0 = ST.get () in recall_contents precomp_basepoint_table_w4 precomp_basepoint_table_lseq_w4; let h1 = ST.get () in precomp_basepoint_table_lemma_w4 (); assert (table_inv_w4 (as_seq h1 q1) (as_seq h1 precomp_basepoint_table_w4)); recall_contents precomp_g_pow2_64_table_w4 precomp_g_pow2_64_table_lseq_w4; let h1 = ST.get () in precomp_g_pow2_64_table_lemma_w4 (); assert (table_inv_w4 (as_seq h1 q2) (as_seq h1 precomp_g_pow2_64_table_w4)); recall_contents precomp_g_pow2_128_table_w4 precomp_g_pow2_128_table_lseq_w4; let h1 = ST.get () in precomp_g_pow2_128_table_lemma_w4 (); assert (table_inv_w4 (as_seq h1 q3) (as_seq h1 precomp_g_pow2_128_table_w4)); recall_contents precomp_g_pow2_192_table_w4 precomp_g_pow2_192_table_lseq_w4; let h1 = ST.get () in precomp_g_pow2_192_table_lemma_w4 (); assert (table_inv_w4 (as_seq h1 q4) (as_seq h1 precomp_g_pow2_192_table_w4)); let r1 = sub bscalar 0ul 1ul in let r2 = sub bscalar 1ul 1ul in let r3 = sub bscalar 2ul 1ul in let r4 = sub bscalar 3ul 1ul in SPT256.lemma_decompose_nat256_as_four_u64_lbignum (as_seq h0 bscalar); ME.mk_lexp_four_fw_tables len ctx_len k l table_len table_inv_w4 table_inv_w4 table_inv_w4 table_inv_w4 precomp_get_consttime precomp_get_consttime precomp_get_consttime precomp_get_consttime (null uint64) q1 bLen bBits r1 q2 r2 q3 r3 q4 r4 (to_const precomp_basepoint_table_w4) (to_const precomp_g_pow2_64_table_w4) (to_const precomp_g_pow2_128_table_w4) (to_const precomp_g_pow2_192_table_w4) out; LowStar.Ignore.ignore q2; // q2, q3, q4 are unused variables LowStar.Ignore.ignore q3; LowStar.Ignore.ignore q4 inline_for_extraction noextract val point_mul_g_mk_q1234: out:point -> bscalar:lbuffer uint64 4ul -> q1:point -> Stack unit (requires fun h -> live h bscalar /\ live h out /\ live h q1 /\ disjoint out bscalar /\ disjoint out q1 /\ BD.bn_v h bscalar < pow2 256 /\ F51.linv (as_seq h q1) /\ refl (as_seq h q1) == g_aff) (ensures fun h0 _ h1 -> modifies (loc out) h0 h1 /\ F51.linv (as_seq h1 out) /\ (let (b0, b1, b2, b3) = SPT256.decompose_nat256_as_four_u64 (BD.bn_v h0 bscalar) in S.to_aff_point (F51.point_eval h1 out) == LE.exp_four_fw S.mk_ed25519_comm_monoid g_aff 64 b0 g_pow2_64 b1 g_pow2_128 b2 g_pow2_192 b3 4)) let point_mul_g_mk_q1234 out bscalar q1 = push_frame (); let q2 = mk_ext_g_pow2_64 () in let q3 = mk_ext_g_pow2_128 () in let q4 = mk_ext_g_pow2_192 () in ext_g_pow2_64_lseq_lemma (); ext_g_pow2_128_lseq_lemma (); ext_g_pow2_192_lseq_lemma (); point_mul_g_noalloc out bscalar q1 q2 q3 q4; pop_frame () val lemma_exp_four_fw_local: b:BSeq.lbytes 32 -> Lemma (let bn = BSeq.nat_from_bytes_le b in let (b0, b1, b2, b3) = SPT256.decompose_nat256_as_four_u64 bn in let cm = S.mk_ed25519_comm_monoid in LE.exp_four_fw cm g_aff 64 b0 g_pow2_64 b1 g_pow2_128 b2 g_pow2_192 b3 4 == S.to_aff_point (S.point_mul_g b)) let lemma_exp_four_fw_local b = let bn = BSeq.nat_from_bytes_le b in let (b0, b1, b2, b3) = SPT256.decompose_nat256_as_four_u64 bn in let cm = S.mk_ed25519_comm_monoid in let res = LE.exp_four_fw cm g_aff 64 b0 g_pow2_64 b1 g_pow2_128 b2 g_pow2_192 b3 4 in assert (res == SPT256.exp_as_exp_four_nat256_precomp cm g_aff bn); SPT256.lemma_point_mul_base_precomp4 cm g_aff bn; assert (res == LE.pow cm g_aff bn); SE.exp_fw_lemma S.mk_ed25519_concrete_ops g_c 256 bn 4; LE.exp_fw_lemma cm g_aff 256 bn 4; assert (S.to_aff_point (S.point_mul_g b) == LE.pow cm g_aff bn) [@CInline] let point_mul_g out scalar = push_frame (); let h0 = ST.get () in let bscalar = create 4ul (u64 0) in convert_scalar scalar bscalar; let q1 = create 20ul (u64 0) in make_g q1; point_mul_g_mk_q1234 out bscalar q1; lemma_exp_four_fw_local (as_seq h0 scalar); pop_frame () inline_for_extraction noextract val point_mul_g_double_vartime_noalloc: out:point -> scalar1:lbuffer uint64 4ul -> q1:point -> scalar2:lbuffer uint64 4ul -> q2:point -> table2: lbuffer uint64 640ul -> Stack unit (requires fun h -> live h out /\ live h scalar1 /\ live h q1 /\ live h scalar2 /\ live h q2 /\ live h table2 /\ eq_or_disjoint q1 q2 /\ disjoint out q1 /\ disjoint out q2 /\ disjoint out scalar1 /\ disjoint out scalar2 /\ disjoint out table2 /\ BD.bn_v h scalar1 < pow2 256 /\ BD.bn_v h scalar2 < pow2 256 /\ F51.linv (as_seq h q1) /\ F51.linv (as_seq h q2) /\ F51.point_eval h q1 == g_c /\ table_inv_w5 (as_seq h q2) (as_seq h table2)) (ensures fun h0 _ h1 -> modifies (loc out) h0 h1 /\ F51.linv (as_seq h1 out) /\ S.to_aff_point (F51.point_eval h1 out) == LE.exp_double_fw #S.aff_point_c S.mk_ed25519_comm_monoid (S.to_aff_point (F51.point_eval h0 q1)) 256 (BD.bn_v h0 scalar1) (S.to_aff_point (F51.point_eval h0 q2)) (BD.bn_v h0 scalar2) 5) let point_mul_g_double_vartime_noalloc out scalar1 q1 scalar2 q2 table2 = [@inline_let] let len = 20ul in [@inline_let] let ctx_len = 0ul in [@inline_let] let k = mk_ed25519_concrete_ops in [@inline_let] let l = 5ul in [@inline_let] let table_len = 32ul in [@inline_let] let bLen = 4ul in [@inline_let] let bBits = 256ul in assert_norm (pow2 (v l) == v table_len); let h0 = ST.get () in recall_contents precomp_basepoint_table_w5 precomp_basepoint_table_lseq_w5; let h1 = ST.get () in precomp_basepoint_table_lemma_w5 (); assert (table_inv_w5 (as_seq h1 q1) (as_seq h1 precomp_basepoint_table_w5)); assert (table_inv_w5 (as_seq h1 q2) (as_seq h1 table2)); ME.mk_lexp_double_fw_tables len ctx_len k l table_len table_inv_w5 table_inv_w5 (BE.lprecomp_get_vartime len ctx_len k l table_len) (BE.lprecomp_get_vartime len ctx_len k l table_len) (null uint64) q1 bLen bBits scalar1 q2 scalar2 (to_const precomp_basepoint_table_w5) (to_const table2) out inline_for_extraction noextract val point_mul_g_double_vartime_table: out:point -> scalar1:lbuffer uint64 4ul -> q1:point -> scalar2:lbuffer uint64 4ul -> q2:point -> Stack unit (requires fun h -> live h out /\ live h scalar1 /\ live h q1 /\ live h scalar2 /\ live h q2 /\ eq_or_disjoint q1 q2 /\ disjoint out q1 /\ disjoint out q2 /\ disjoint out scalar1 /\ disjoint out scalar2 /\ BD.bn_v h scalar1 < pow2 256 /\ BD.bn_v h scalar2 < pow2 256 /\ F51.linv (as_seq h q1) /\ F51.linv (as_seq h q2) /\ F51.point_eval h q1 == g_c) (ensures fun h0 _ h1 -> modifies (loc out) h0 h1 /\ F51.linv (as_seq h1 out) /\ S.to_aff_point (F51.point_eval h1 out) == LE.exp_double_fw #S.aff_point_c S.mk_ed25519_comm_monoid (S.to_aff_point (F51.point_eval h0 q1)) 256 (BD.bn_v h0 scalar1) (S.to_aff_point (F51.point_eval h0 q2)) (BD.bn_v h0 scalar2) 5)
{ "checked_file": "/", "dependencies": [ "Spec.Exponentiation.fsti.checked", "Spec.Ed25519.Lemmas.fsti.checked", "Spec.Ed25519.fst.checked", "prims.fst.checked", "LowStar.Ignore.fsti.checked", "Lib.IntTypes.fsti.checked", "Lib.Exponentiation.fsti.checked", "Lib.ByteSequence.fsti.checked", "Lib.Buffer.fsti.checked", "Hacl.Spec.PrecompBaseTable256.fsti.checked", "Hacl.Spec.Bignum.Definitions.fst.checked", "Hacl.Spec.Bignum.Convert.fst.checked", "Hacl.Impl.PrecompTable.fsti.checked", "Hacl.Impl.MultiExponentiation.fsti.checked", "Hacl.Impl.Exponentiation.fsti.checked", "Hacl.Impl.Ed25519.PointNegate.fst.checked", "Hacl.Impl.Ed25519.PointConstants.fst.checked", "Hacl.Impl.Ed25519.Group.fst.checked", "Hacl.Impl.Ed25519.Field51.fst.checked", "Hacl.Ed25519.PrecompTable.fsti.checked", "Hacl.Bignum25519.fsti.checked", "Hacl.Bignum.Definitions.fst.checked", "Hacl.Bignum.Convert.fst.checked", "FStar.UInt32.fsti.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.All.fst.checked" ], "interface_file": true, "source_file": "Hacl.Impl.Ed25519.Ladder.fst" }
[ { "abbrev": false, "full_module": "Hacl.Ed25519.PrecompTable", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Impl.Ed25519.Group", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Impl.Ed25519.PointConstants", "short_module": null }, { "abbrev": true, "full_module": "Spec.Ed25519", "short_module": "S" }, { "abbrev": true, "full_module": "Hacl.Spec.Bignum.Definitions", "short_module": "SD" }, { "abbrev": true, "full_module": "Hacl.Bignum.Definitions", "short_module": "BD" }, { "abbrev": true, "full_module": "Hacl.Spec.PrecompBaseTable256", "short_module": "SPT256" }, { "abbrev": true, "full_module": "Hacl.Impl.PrecompTable", "short_module": "PT" }, { "abbrev": true, "full_module": "Hacl.Impl.MultiExponentiation", "short_module": "ME" }, { "abbrev": true, "full_module": "Hacl.Impl.Exponentiation", "short_module": "BE" }, { "abbrev": true, "full_module": "Spec.Exponentiation", "short_module": "SE" }, { "abbrev": true, "full_module": "Lib.Exponentiation", "short_module": "LE" }, { "abbrev": true, "full_module": "Lib.ByteSequence", "short_module": "BSeq" }, { "abbrev": true, "full_module": "Hacl.Impl.Ed25519.Field51", "short_module": "F51" }, { "abbrev": false, "full_module": "Hacl.Bignum25519", "short_module": null }, { "abbrev": false, "full_module": "Lib.Buffer", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.All", "short_module": null }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": true, "full_module": "Spec.Ed25519", "short_module": "S" }, { "abbrev": true, "full_module": "Hacl.Impl.Ed25519.Field51", "short_module": "F51" }, { "abbrev": true, "full_module": "Lib.ByteSequence", "short_module": "BSeq" }, { "abbrev": false, "full_module": "Hacl.Bignum25519", "short_module": null }, { "abbrev": false, "full_module": "Lib.Buffer", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.All", "short_module": null }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": false, "full_module": "Hacl.Impl.Ed25519", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Impl.Ed25519", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": 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
out: Hacl.Bignum25519.point -> scalar1: Lib.Buffer.lbuffer Lib.IntTypes.uint64 4ul -> q1: Hacl.Bignum25519.point -> scalar2: Lib.Buffer.lbuffer Lib.IntTypes.uint64 4ul -> q2: Hacl.Bignum25519.point -> FStar.HyperStack.ST.Stack Prims.unit
FStar.HyperStack.ST.Stack
[]
[]
[ "Hacl.Bignum25519.point", "Lib.Buffer.lbuffer", "Lib.IntTypes.uint64", "FStar.UInt32.__uint_to_t", "FStar.HyperStack.ST.pop_frame", "Prims.unit", "Hacl.Impl.Ed25519.Ladder.point_mul_g_double_vartime_noalloc", "Hacl.Impl.PrecompTable.lprecomp_table", "Lib.IntTypes.U64", "Lib.Buffer.null", "Lib.Buffer.MUT", "Lib.Buffer.lbuffer_t", "Lib.IntTypes.int_t", "Lib.IntTypes.SEC", "Lib.IntTypes.mul", "Lib.IntTypes.U32", "Lib.IntTypes.PUB", "Lib.Buffer.create", "Lib.IntTypes.uint_t", "Lib.IntTypes.op_Star_Bang", "Lib.IntTypes.u64", "FStar.HyperStack.ST.push_frame", "FStar.Pervasives.assert_norm", "Prims.eq2", "Prims.int", "Prims.l_or", "Lib.IntTypes.range", "Prims.b2t", "Prims.op_GreaterThan", "Prims.pow2", "Lib.IntTypes.v", "FStar.UInt32.t", "Hacl.Impl.Exponentiation.Definitions.concrete_ops", "FStar.UInt32.uint_to_t", "Hacl.Impl.Ed25519.Group.mk_ed25519_concrete_ops" ]
[]
false
true
false
false
false
let point_mul_g_double_vartime_table out scalar1 q1 scalar2 q2 =
[@@ inline_let ]let len = 20ul in [@@ inline_let ]let ctx_len = 0ul in [@@ inline_let ]let k = mk_ed25519_concrete_ops in [@@ inline_let ]let table_len = 32ul in assert_norm (pow2 5 == v table_len); push_frame (); let table2 = create (table_len *! len) (u64 0) in PT.lprecomp_table len ctx_len k (null uint64) q2 table_len table2; point_mul_g_double_vartime_noalloc out scalar1 q1 scalar2 q2 table2; pop_frame ()
false
Hacl.Bignum.fst
Hacl.Bignum.bn_sub_mask
val bn_sub_mask: #t:limb_t -> len:size_t{v len > 0} -> n:lbignum t len -> a:lbignum t len -> Stack unit (requires fun h -> live h n /\ live h a /\ disjoint n a) (ensures fun h0 _ h1 -> modifies (loc a) h0 h1 /\ as_seq h1 a == S.bn_sub_mask (as_seq h0 n) (as_seq h0 a))
val bn_sub_mask: #t:limb_t -> len:size_t{v len > 0} -> n:lbignum t len -> a:lbignum t len -> Stack unit (requires fun h -> live h n /\ live h a /\ disjoint n a) (ensures fun h0 _ h1 -> modifies (loc a) h0 h1 /\ as_seq h1 a == S.bn_sub_mask (as_seq h0 n) (as_seq h0 a))
let bn_sub_mask #t len n a = push_frame (); let mask = create 1ul (ones t SEC) in let mod_mask = create len (uint #t 0) in let mask = Lib.ByteBuffer.buf_eq_mask n a len mask in mapT len mod_mask (logand mask) n; let _ = Hacl.Bignum.Addition.bn_sub_eq_len len a mod_mask a in pop_frame ()
{ "file_name": "code/bignum/Hacl.Bignum.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 14, "end_line": 81, "start_col": 0, "start_line": 74 }
module Hacl.Bignum friend Hacl.Spec.Bignum #reset-options "--z3rlimit 50 --fuel 0 --ifuel 0" let bn_add1 #t aLen a b1 res = Hacl.Bignum.Addition.bn_add1 aLen a b1 res let bn_sub1 #t aLen a b1 res = Hacl.Bignum.Addition.bn_sub1 aLen a b1 res let bn_add_eq_len #t aLen a b res = Hacl.Bignum.Addition.bn_add_eq_len aLen a b res let bn_sub_eq_len #t aLen a b res = Hacl.Bignum.Addition.bn_sub_eq_len aLen a b res let bn_add #t aLen a bLen b res = Hacl.Bignum.Addition.bn_add aLen a bLen b res let bn_sub #t aLen a bLen b res = Hacl.Bignum.Addition.bn_sub aLen a bLen b res let bn_reduce_once #t len n c0 res = push_frame (); let tmp = create len (uint #t 0) in let c1 = bn_sub_eq_len len res n tmp in let c = c0 -. c1 in map2T len res (mask_select c) res tmp; pop_frame() let bn_add_mod_n #t len n a b res = let c0 = bn_add_eq_len len a b res in bn_reduce_once len n c0 res let bn_sub_mod_n #t len n a b res = push_frame (); let c0 = bn_sub_eq_len len a b res in let tmp = create len (uint #t 0) in let c1 = bn_add_eq_len len res n tmp in LowStar.Ignore.ignore c1; let c = uint #t 0 -. c0 in map2T len res (mask_select c) tmp res; pop_frame () let bn_mul1 #t aLen a l res = Hacl.Bignum.Multiplication.bn_mul1 #t aLen a l res let bn_karatsuba_mul #t len a b res = let h0 = ST.get () in Hacl.Spec.Bignum.bn_karatsuba_mul_lemma (as_seq h0 a) (as_seq h0 b); Hacl.Bignum.Karatsuba.bn_karatsuba_mul len a b res let bn_mul #t aLen bLen a b res = Hacl.Bignum.Multiplication.bn_mul aLen a bLen b res let bn_karatsuba_sqr #t len a res = let h0 = ST.get () in Hacl.Spec.Bignum.bn_karatsuba_sqr_lemma (as_seq h0 a); Hacl.Bignum.Karatsuba.bn_karatsuba_sqr len a res let bn_sqr #t len a res = let h0 = ST.get () in Hacl.Spec.Bignum.bn_sqr_lemma (as_seq h0 a); Hacl.Bignum.Multiplication.bn_sqr len a res let bn_mul1_lshift_add_in_place #t aLen a b j res = Hacl.Bignum.Multiplication.bn_mul1_lshift_add aLen a b j res let bn_rshift #t len b i res = copy res (sub b i (len -! i))
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowStar.Ignore.fsti.checked", "Lib.ByteBuffer.fsti.checked", "Hacl.Spec.Bignum.fst.checked", "Hacl.Bignum.Multiplication.fst.checked", "Hacl.Bignum.Lib.fst.checked", "Hacl.Bignum.Karatsuba.fst.checked", "Hacl.Bignum.Convert.fst.checked", "Hacl.Bignum.Comparison.fst.checked", "Hacl.Bignum.Addition.fst.checked", "FStar.UInt32.fsti.checked", "FStar.ST.fst.checked", "FStar.Pervasives.fsti.checked" ], "interface_file": true, "source_file": "Hacl.Bignum.fst" }
[ { "abbrev": true, "full_module": "Lib.LoopCombinators", "short_module": "Loops" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": true, "full_module": "Hacl.Spec.Bignum", "short_module": "S" }, { "abbrev": false, "full_module": "Hacl.Bignum.Definitions", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Bignum.Base", "short_module": null }, { "abbrev": false, "full_module": "Lib.Buffer", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack", "short_module": null }, { "abbrev": false, "full_module": "Hacl", "short_module": null }, { "abbrev": false, "full_module": "Hacl", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "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
len: Lib.IntTypes.size_t{Lib.IntTypes.v len > 0} -> n: Hacl.Bignum.Definitions.lbignum t len -> a: Hacl.Bignum.Definitions.lbignum t len -> FStar.HyperStack.ST.Stack Prims.unit
FStar.HyperStack.ST.Stack
[]
[]
[ "Hacl.Bignum.Definitions.limb_t", "Lib.IntTypes.size_t", "Prims.b2t", "Prims.op_GreaterThan", "Lib.IntTypes.v", "Lib.IntTypes.U32", "Lib.IntTypes.PUB", "Hacl.Bignum.Definitions.lbignum", "FStar.HyperStack.ST.pop_frame", "Prims.unit", "Hacl.Spec.Bignum.Base.carry", "Hacl.Bignum.Addition.bn_sub_eq_len", "Lib.Buffer.mapT", "Lib.Buffer.MUT", "Hacl.Bignum.Definitions.limb", "Lib.IntTypes.logand", "Lib.IntTypes.SEC", "Lib.IntTypes.int_t", "Lib.ByteBuffer.buf_eq_mask", "Lib.Buffer.lbuffer_t", "Lib.Buffer.create", "Lib.IntTypes.uint", "Lib.Buffer.lbuffer", "FStar.UInt32.uint_to_t", "FStar.UInt32.t", "FStar.UInt32.__uint_to_t", "Lib.IntTypes.ones", "FStar.HyperStack.ST.push_frame" ]
[]
false
true
false
false
false
let bn_sub_mask #t len n a =
push_frame (); let mask = create 1ul (ones t SEC) in let mod_mask = create len (uint #t 0) in let mask = Lib.ByteBuffer.buf_eq_mask n a len mask in mapT len mod_mask (logand mask) n; let _ = Hacl.Bignum.Addition.bn_sub_eq_len len a mod_mask a in pop_frame ()
false
Vale.X64.Lemmas.fst
Vale.X64.Lemmas.eval_code_eq_instr
val eval_code_eq_instr (inst: BS.ins) (f: fuel) (s1 s2: machine_state) : Lemma (requires Instr? inst /\ state_eq_S true s1 s2) (ensures state_eq_opt true (BS.machine_eval_code (Ins inst) f s1) (BS.machine_eval_code (Ins inst) f s2))
val eval_code_eq_instr (inst: BS.ins) (f: fuel) (s1 s2: machine_state) : Lemma (requires Instr? inst /\ state_eq_S true s1 s2) (ensures state_eq_opt true (BS.machine_eval_code (Ins inst) f s1) (BS.machine_eval_code (Ins inst) f s2))
let eval_code_eq_instr (inst:BS.ins) (f:fuel) (s1 s2:machine_state) : Lemma (requires Instr? inst /\ state_eq_S true s1 s2) (ensures state_eq_opt true (BS.machine_eval_code (Ins inst) f s1) (BS.machine_eval_code (Ins inst) f s2)) = reveal_opaque (`%BS.machine_eval_code_ins) BS.machine_eval_code_ins; eval_ins_eq_instr inst ({s1 with BS.ms_trace = []}) ({s2 with BS.ms_trace = []})
{ "file_name": "vale/code/arch/x64/Vale.X64.Lemmas.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 82, "end_line": 141, "start_col": 0, "start_line": 136 }
module Vale.X64.Lemmas open FStar.Mul open Vale.X64.Machine_s open Vale.X64.State open Vale.X64.StateLemmas open Vale.X64.Instruction_s open Vale.X64.Bytes_Code_s module BS = Vale.X64.Machine_Semantics_s module ME = Vale.X64.Memory #reset-options "--initial_fuel 1 --max_fuel 1 --z3rlimit 100" #restart-solver let rec lemma_eq_instr_apply_eval_args (outs:list instr_out) (args:list instr_operand) (f:instr_args_t outs args) (oprs:instr_operands_t_args args) (s1 s2:machine_state) : Lemma (requires state_eq_S true s1 s2) (ensures BS.instr_apply_eval_args outs args f oprs s1 == BS.instr_apply_eval_args outs args f oprs s2) = let open BS in lemma_heap_ignore_ghost_machine s1.BS.ms_heap s2.BS.ms_heap; match args with | [] -> () | i::args -> ( let (v, oprs) : option (instr_val_t i) & instr_operands_t_args args = match i with | IOpEx i -> let oprs = coerce oprs in (instr_eval_operand_explicit i (fst oprs) s1, snd oprs) | IOpIm i -> (instr_eval_operand_implicit i s1, coerce oprs) in let f:arrow (instr_val_t i) (instr_args_t outs args) = coerce f in match v with | None -> () | Some v -> lemma_eq_instr_apply_eval_args outs args (f v) oprs s1 s2 ) #restart-solver let rec lemma_eq_instr_apply_eval_inouts (outs inouts:list instr_out) (args:list instr_operand) (f:instr_inouts_t outs inouts args) (oprs:instr_operands_t inouts args) (s1 s2:machine_state) : Lemma (requires state_eq_S true s1 s2) (ensures BS.instr_apply_eval_inouts outs inouts args f oprs s1 == BS.instr_apply_eval_inouts outs inouts args f oprs s2) = let open BS in lemma_heap_ignore_ghost_machine s1.BS.ms_heap s2.BS.ms_heap; match inouts with | [] -> lemma_eq_instr_apply_eval_args outs args f oprs s1 s2 | (Out, i)::inouts -> let oprs = match i with | IOpEx i -> snd #(instr_operand_t i) (coerce oprs) | IOpIm i -> coerce oprs in lemma_eq_instr_apply_eval_inouts outs inouts args (coerce f) oprs s1 s2 | (InOut, i)::inouts -> ( let (v, oprs) : option (instr_val_t i) & instr_operands_t inouts args = match i with | IOpEx i -> let oprs = coerce oprs in (instr_eval_operand_explicit i (fst oprs) s1, snd oprs) | IOpIm i -> (instr_eval_operand_implicit i s1, coerce oprs) in let f:arrow (instr_val_t i) (instr_inouts_t outs inouts args) = coerce f in match v with | None -> () | Some v -> lemma_eq_instr_apply_eval_inouts outs inouts args (f v) oprs s1 s2 ) #restart-solver #push-options "--z3rlimit_factor 2" let rec lemma_eq_instr_write_outputs (outs:list instr_out) (args:list instr_operand) (vs:instr_ret_t outs) (oprs:instr_operands_t outs args) (s1_orig s1 s2_orig s2:machine_state) : Lemma (requires state_eq_S true s1_orig s2_orig /\ state_eq_S true s1 s2) (ensures state_eq_S true (BS.instr_write_outputs outs args vs oprs s1_orig s1) (BS.instr_write_outputs outs args vs oprs s2_orig s2)) = let open BS in use_machine_state_equal (); lemma_heap_ignore_ghost_machine s1.BS.ms_heap s2.BS.ms_heap; lemma_heap_ignore_ghost_machine s1_orig.BS.ms_heap s2_orig.BS.ms_heap; allow_inversion tmaddr; match outs with | [] -> () | (_, i)::outs -> ( let ((v:instr_val_t i), (vs:instr_ret_t outs)) = match outs with | [] -> (vs, ()) | _::_ -> let vs = coerce vs in (fst vs, snd vs) in match i with | IOpEx i -> let oprs = coerce oprs in let s1 = instr_write_output_explicit i v (fst oprs) s1_orig s1 in let s2 = instr_write_output_explicit i v (fst oprs) s2_orig s2 in lemma_eq_instr_write_outputs outs args vs (snd oprs) s1_orig s1 s2_orig s2 | IOpIm i -> let s1 = instr_write_output_implicit i v s1_orig s1 in let s2 = instr_write_output_implicit i v s2_orig s2 in allow_inversion operand64; allow_inversion operand128; lemma_eq_instr_write_outputs outs args vs (coerce oprs) s1_orig s1 s2_orig s2 ) #pop-options #restart-solver let eval_ins_eq_instr (inst:BS.ins) (s1 s2:machine_state) : Lemma (requires Instr? inst /\ state_eq_S true s1 s2) (ensures state_eq_S true (BS.machine_eval_ins inst s1) (BS.machine_eval_ins inst s2)) = let open BS in let Instr it oprs ann = inst in let InstrTypeRecord #outs #args #havoc_flags' i = it in lemma_eq_instr_apply_eval_inouts outs outs args (instr_eval i) oprs s1 s2; let vs = instr_apply_eval outs args (instr_eval i) oprs s1 in let hav s = match havoc_flags' with | HavocFlags -> {s with ms_flags = havoc_flags} | PreserveFlags -> s in let s1' = hav s1 in let s2' = hav s2 in match vs with | None -> () | Some vs -> lemma_eq_instr_write_outputs outs args vs oprs s1 s1' s2 s2'
{ "checked_file": "/", "dependencies": [ "Vale.X64.StateLemmas.fsti.checked", "Vale.X64.State.fsti.checked", "Vale.X64.Memory.fsti.checked", "Vale.X64.Machine_Semantics_s.fst.checked", "Vale.X64.Machine_s.fst.checked", "Vale.X64.Instruction_s.fsti.checked", "Vale.X64.Flags.fsti.checked", "Vale.X64.Bytes_Code_s.fst.checked", "prims.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.FunctionalExtensionality.fsti.checked" ], "interface_file": true, "source_file": "Vale.X64.Lemmas.fst" }
[ { "abbrev": true, "full_module": "Vale.X64.Memory", "short_module": "ME" }, { "abbrev": true, "full_module": "Vale.X64.Machine_Semantics_s", "short_module": "BS" }, { "abbrev": false, "full_module": "Vale.X64.Bytes_Code_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Instruction_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.StateLemmas", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.State", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Machine_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": true, "full_module": "Vale.Lib.Map16", "short_module": "Map16" }, { "abbrev": true, "full_module": "Vale.X64.Machine_Semantics_s", "short_module": "BS" }, { "abbrev": false, "full_module": "Vale.X64.Bytes_Code_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.StateLemmas", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.State", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Machine_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.HeapLemmas", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.HeapImpl", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.Heap", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 1, "initial_ifuel": 0, "max_fuel": 1, "max_ifuel": 1, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": true, "smtencoding_l_arith_repr": "native", "smtencoding_nl_arith_repr": "wrapped", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [ "smt.arith.nl=false", "smt.QI.EAGER_THRESHOLD=100", "smt.CASE_SPLIT=3" ], "z3refresh": false, "z3rlimit": 100, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
inst: Vale.X64.Machine_Semantics_s.ins -> f: Vale.X64.Lemmas.fuel -> s1: Vale.X64.StateLemmas.machine_state -> s2: Vale.X64.StateLemmas.machine_state -> FStar.Pervasives.Lemma (requires Instr? inst /\ Vale.X64.Lemmas.state_eq_S true s1 s2) (ensures Vale.X64.Lemmas.state_eq_opt true (Vale.X64.Machine_Semantics_s.machine_eval_code (Vale.X64.Machine_s.Ins inst) f s1) (Vale.X64.Machine_Semantics_s.machine_eval_code (Vale.X64.Machine_s.Ins inst) f s2))
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "Vale.X64.Machine_Semantics_s.ins", "Vale.X64.Lemmas.fuel", "Vale.X64.StateLemmas.machine_state", "Vale.X64.Lemmas.eval_ins_eq_instr", "Vale.X64.Machine_Semantics_s.Mkmachine_state", "Vale.X64.Machine_Semantics_s.__proj__Mkmachine_state__item__ms_ok", "Vale.X64.Machine_Semantics_s.__proj__Mkmachine_state__item__ms_regs", "Vale.X64.Machine_Semantics_s.__proj__Mkmachine_state__item__ms_flags", "Vale.X64.Machine_Semantics_s.__proj__Mkmachine_state__item__ms_heap", "Vale.X64.Machine_Semantics_s.__proj__Mkmachine_state__item__ms_stack", "Vale.X64.Machine_Semantics_s.__proj__Mkmachine_state__item__ms_stackTaint", "Prims.Nil", "Vale.X64.Machine_s.observation", "Prims.unit", "FStar.Pervasives.reveal_opaque", "Vale.X64.Machine_Semantics_s.machine_state", "FStar.Pervasives.Native.option", "Vale.X64.Machine_Semantics_s.machine_eval_code_ins", "Prims.l_and", "Prims.b2t", "Vale.X64.Bytes_Code_s.uu___is_Instr", "Vale.X64.Machine_Semantics_s.instr_annotation", "Vale.X64.Lemmas.state_eq_S", "Prims.squash", "Vale.X64.Lemmas.state_eq_opt", "Vale.X64.Machine_Semantics_s.machine_eval_code", "Vale.X64.Machine_s.Ins", "Vale.X64.Bytes_Code_s.instruction_t", "Vale.X64.Bytes_Code_s.ocmp", "FStar.Pervasives.pattern" ]
[]
true
false
true
false
false
let eval_code_eq_instr (inst: BS.ins) (f: fuel) (s1 s2: machine_state) : Lemma (requires Instr? inst /\ state_eq_S true s1 s2) (ensures state_eq_opt true (BS.machine_eval_code (Ins inst) f s1) (BS.machine_eval_code (Ins inst) f s2)) =
reveal_opaque (`%BS.machine_eval_code_ins) BS.machine_eval_code_ins; eval_ins_eq_instr inst ({ s1 with BS.ms_trace = [] }) ({ s2 with BS.ms_trace = [] })
false
Vale.X64.Lemmas.fst
Vale.X64.Lemmas.eval_code_eq_f
val eval_code_eq_f (c: code) (f: fuel) (s1 s2: machine_state) : Lemma (requires state_eq_S false s1 s2) (ensures state_eq_opt false (BS.machine_eval_code c f s1) (BS.machine_eval_code c f s2)) [SMTPat (BS.machine_eval_code c f s1); SMTPat (BS.machine_eval_code c f s2)]
val eval_code_eq_f (c: code) (f: fuel) (s1 s2: machine_state) : Lemma (requires state_eq_S false s1 s2) (ensures state_eq_opt false (BS.machine_eval_code c f s1) (BS.machine_eval_code c f s2)) [SMTPat (BS.machine_eval_code c f s1); SMTPat (BS.machine_eval_code c f s2)]
let eval_code_eq_f (c:code) (f:fuel) (s1 s2:machine_state) : Lemma (requires state_eq_S false s1 s2) (ensures state_eq_opt false (BS.machine_eval_code c f s1) (BS.machine_eval_code c f s2)) [SMTPat (BS.machine_eval_code c f s1); SMTPat (BS.machine_eval_code c f s2)] = eval_code_eq_core false c f s1; eval_code_eq_core false c f s2
{ "file_name": "vale/code/arch/x64/Vale.X64.Lemmas.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 64, "end_line": 258, "start_col": 0, "start_line": 253 }
module Vale.X64.Lemmas open FStar.Mul open Vale.X64.Machine_s open Vale.X64.State open Vale.X64.StateLemmas open Vale.X64.Instruction_s open Vale.X64.Bytes_Code_s module BS = Vale.X64.Machine_Semantics_s module ME = Vale.X64.Memory #reset-options "--initial_fuel 1 --max_fuel 1 --z3rlimit 100" #restart-solver let rec lemma_eq_instr_apply_eval_args (outs:list instr_out) (args:list instr_operand) (f:instr_args_t outs args) (oprs:instr_operands_t_args args) (s1 s2:machine_state) : Lemma (requires state_eq_S true s1 s2) (ensures BS.instr_apply_eval_args outs args f oprs s1 == BS.instr_apply_eval_args outs args f oprs s2) = let open BS in lemma_heap_ignore_ghost_machine s1.BS.ms_heap s2.BS.ms_heap; match args with | [] -> () | i::args -> ( let (v, oprs) : option (instr_val_t i) & instr_operands_t_args args = match i with | IOpEx i -> let oprs = coerce oprs in (instr_eval_operand_explicit i (fst oprs) s1, snd oprs) | IOpIm i -> (instr_eval_operand_implicit i s1, coerce oprs) in let f:arrow (instr_val_t i) (instr_args_t outs args) = coerce f in match v with | None -> () | Some v -> lemma_eq_instr_apply_eval_args outs args (f v) oprs s1 s2 ) #restart-solver let rec lemma_eq_instr_apply_eval_inouts (outs inouts:list instr_out) (args:list instr_operand) (f:instr_inouts_t outs inouts args) (oprs:instr_operands_t inouts args) (s1 s2:machine_state) : Lemma (requires state_eq_S true s1 s2) (ensures BS.instr_apply_eval_inouts outs inouts args f oprs s1 == BS.instr_apply_eval_inouts outs inouts args f oprs s2) = let open BS in lemma_heap_ignore_ghost_machine s1.BS.ms_heap s2.BS.ms_heap; match inouts with | [] -> lemma_eq_instr_apply_eval_args outs args f oprs s1 s2 | (Out, i)::inouts -> let oprs = match i with | IOpEx i -> snd #(instr_operand_t i) (coerce oprs) | IOpIm i -> coerce oprs in lemma_eq_instr_apply_eval_inouts outs inouts args (coerce f) oprs s1 s2 | (InOut, i)::inouts -> ( let (v, oprs) : option (instr_val_t i) & instr_operands_t inouts args = match i with | IOpEx i -> let oprs = coerce oprs in (instr_eval_operand_explicit i (fst oprs) s1, snd oprs) | IOpIm i -> (instr_eval_operand_implicit i s1, coerce oprs) in let f:arrow (instr_val_t i) (instr_inouts_t outs inouts args) = coerce f in match v with | None -> () | Some v -> lemma_eq_instr_apply_eval_inouts outs inouts args (f v) oprs s1 s2 ) #restart-solver #push-options "--z3rlimit_factor 2" let rec lemma_eq_instr_write_outputs (outs:list instr_out) (args:list instr_operand) (vs:instr_ret_t outs) (oprs:instr_operands_t outs args) (s1_orig s1 s2_orig s2:machine_state) : Lemma (requires state_eq_S true s1_orig s2_orig /\ state_eq_S true s1 s2) (ensures state_eq_S true (BS.instr_write_outputs outs args vs oprs s1_orig s1) (BS.instr_write_outputs outs args vs oprs s2_orig s2)) = let open BS in use_machine_state_equal (); lemma_heap_ignore_ghost_machine s1.BS.ms_heap s2.BS.ms_heap; lemma_heap_ignore_ghost_machine s1_orig.BS.ms_heap s2_orig.BS.ms_heap; allow_inversion tmaddr; match outs with | [] -> () | (_, i)::outs -> ( let ((v:instr_val_t i), (vs:instr_ret_t outs)) = match outs with | [] -> (vs, ()) | _::_ -> let vs = coerce vs in (fst vs, snd vs) in match i with | IOpEx i -> let oprs = coerce oprs in let s1 = instr_write_output_explicit i v (fst oprs) s1_orig s1 in let s2 = instr_write_output_explicit i v (fst oprs) s2_orig s2 in lemma_eq_instr_write_outputs outs args vs (snd oprs) s1_orig s1 s2_orig s2 | IOpIm i -> let s1 = instr_write_output_implicit i v s1_orig s1 in let s2 = instr_write_output_implicit i v s2_orig s2 in allow_inversion operand64; allow_inversion operand128; lemma_eq_instr_write_outputs outs args vs (coerce oprs) s1_orig s1 s2_orig s2 ) #pop-options #restart-solver let eval_ins_eq_instr (inst:BS.ins) (s1 s2:machine_state) : Lemma (requires Instr? inst /\ state_eq_S true s1 s2) (ensures state_eq_S true (BS.machine_eval_ins inst s1) (BS.machine_eval_ins inst s2)) = let open BS in let Instr it oprs ann = inst in let InstrTypeRecord #outs #args #havoc_flags' i = it in lemma_eq_instr_apply_eval_inouts outs outs args (instr_eval i) oprs s1 s2; let vs = instr_apply_eval outs args (instr_eval i) oprs s1 in let hav s = match havoc_flags' with | HavocFlags -> {s with ms_flags = havoc_flags} | PreserveFlags -> s in let s1' = hav s1 in let s2' = hav s2 in match vs with | None -> () | Some vs -> lemma_eq_instr_write_outputs outs args vs oprs s1 s1' s2 s2' let eval_code_eq_instr (inst:BS.ins) (f:fuel) (s1 s2:machine_state) : Lemma (requires Instr? inst /\ state_eq_S true s1 s2) (ensures state_eq_opt true (BS.machine_eval_code (Ins inst) f s1) (BS.machine_eval_code (Ins inst) f s2)) = reveal_opaque (`%BS.machine_eval_code_ins) BS.machine_eval_code_ins; eval_ins_eq_instr inst ({s1 with BS.ms_trace = []}) ({s2 with BS.ms_trace = []}) let eval_code_eq_dealloc (inst:BS.ins) (f:fuel) (s1 s2:machine_state) : Lemma (requires Dealloc? inst /\ state_eq_S true s1 s2) (ensures state_eq_opt true (BS.machine_eval_code (Ins inst) f s1) (BS.machine_eval_code (Ins inst) f s2)) = reveal_opaque (`%BS.machine_eval_code_ins) BS.machine_eval_code_ins; use_machine_state_equal (); lemma_heap_ignore_ghost_machine s1.BS.ms_heap s2.BS.ms_heap; allow_inversion tmaddr let eval_code_eq_alloc (inst:BS.ins) (f:fuel) (s1 s2:machine_state) : Lemma (requires Alloc? inst /\ state_eq_S true s1 s2) (ensures state_eq_opt true (BS.machine_eval_code (Ins inst) f s1) (BS.machine_eval_code (Ins inst) f s2)) = reveal_opaque (`%BS.machine_eval_code_ins) BS.machine_eval_code_ins; use_machine_state_equal (); lemma_heap_ignore_ghost_machine s1.BS.ms_heap s2.BS.ms_heap; allow_inversion tmaddr let eval_code_eq_push (inst:BS.ins) (f:fuel) (s1 s2:machine_state) : Lemma (requires Push? inst /\ state_eq_S true s1 s2) (ensures state_eq_opt true (BS.machine_eval_code (Ins inst) f s1) (BS.machine_eval_code (Ins inst) f s2)) = reveal_opaque (`%BS.machine_eval_code_ins) BS.machine_eval_code_ins; use_machine_state_equal (); lemma_heap_ignore_ghost_machine s1.BS.ms_heap s2.BS.ms_heap; allow_inversion tmaddr let eval_code_eq_pop (inst:BS.ins) (f:fuel) (s1 s2:machine_state) : Lemma (requires Pop? inst /\ state_eq_S true s1 s2) (ensures state_eq_opt true (BS.machine_eval_code (Ins inst) f s1) (BS.machine_eval_code (Ins inst) f s2)) = reveal_opaque (`%BS.machine_eval_code_ins) BS.machine_eval_code_ins; use_machine_state_equal (); lemma_heap_ignore_ghost_machine s1.BS.ms_heap s2.BS.ms_heap; allow_inversion tmaddr let eval_code_eq_ins (i:BS.ins) (f:fuel) (s1 s2:machine_state) : Lemma (requires state_eq_S true s1 s2) (ensures state_eq_opt true (BS.machine_eval_code (Ins i) f s1) (BS.machine_eval_code (Ins i) f s2)) = match i with | Instr _ _ _ -> eval_code_eq_instr i f s1 s2 | Dealloc _ -> eval_code_eq_dealloc i f s1 s2 | Alloc _ -> eval_code_eq_alloc i f s1 s2 | Push _ _ -> eval_code_eq_push i f s1 s2 | Pop _ _ -> eval_code_eq_pop i f s1 s2 #reset-options "--fuel 2 --z3rlimit 30" let eval_ocmp_eq_core (g:bool) (cond:ocmp) (s:machine_state) : Lemma (ensures ( let (s1, b1) = BS.machine_eval_ocmp s cond in let (s2, b2) = BS.machine_eval_ocmp (core_state g s) cond in state_eq_S g s1 s2 /\ b1 == b2 )) = reveal_opaque (`%BS.valid_ocmp_opaque) BS.valid_ocmp_opaque; reveal_opaque (`%BS.eval_ocmp_opaque) BS.eval_ocmp_opaque; () #restart-solver let rec eval_code_eq_core (g:bool) (c:code) (f:fuel) (s:machine_state) : Lemma (ensures state_eq_opt g (BS.machine_eval_code c f s) (BS.machine_eval_code c f (core_state g s))) (decreases %[f; c]) = match c with | Ins i -> reveal_opaque (`%BS.machine_eval_code_ins) BS.machine_eval_code_ins; if g then eval_code_eq_ins i f s (core_state g s) | Block cs -> eval_codes_eq_core g cs f s | IfElse cond ct cf -> eval_ocmp_eq_core g cond s; let (s', _) = BS.machine_eval_ocmp s cond in let (t', _) = BS.machine_eval_ocmp (core_state g s) cond in eval_code_eq_core g ct f s'; eval_code_eq_core g ct f t'; eval_code_eq_core g cf f s'; eval_code_eq_core g cf f t'; () | While cond body -> eval_while_eq_core g cond body f s and eval_codes_eq_core (g:bool) (cs:codes) (f:fuel) (s:machine_state) : Lemma (ensures state_eq_opt g (BS.machine_eval_codes cs f s) (BS.machine_eval_codes cs f (core_state g s))) (decreases %[f; cs]) = match cs with | [] -> () | c'::cs' -> ( eval_code_eq_core g c' f s; match (machine_eval_code c' f s, machine_eval_code c' f (core_state g s)) with | (None, None) -> () | (Some s', Some t') -> eval_codes_eq_core g cs' f s'; eval_codes_eq_core g cs' f t' ) and eval_while_eq_core (g:bool) (cond:ocmp) (body:code) (f:fuel) (s:machine_state) : Lemma (ensures state_eq_opt g (BS.machine_eval_while cond body f s) (BS.machine_eval_while cond body f (core_state g s))) (decreases %[f; body]) = if f > 0 then ( eval_ocmp_eq_core g cond s; let (s1, _) = BS.machine_eval_ocmp s cond in let (t1, _) = BS.machine_eval_ocmp (core_state g s) cond in eval_code_eq_core g body (f - 1) s1; eval_code_eq_core g body (f - 1) t1; match (BS.machine_eval_code body (f - 1) s1, BS.machine_eval_code body (f - 1) t1) with | (None, None) -> () | (Some s2, Some t2) -> eval_while_eq_core g cond body (f - 1) s2; eval_while_eq_core g cond body (f - 1) t2; () )
{ "checked_file": "/", "dependencies": [ "Vale.X64.StateLemmas.fsti.checked", "Vale.X64.State.fsti.checked", "Vale.X64.Memory.fsti.checked", "Vale.X64.Machine_Semantics_s.fst.checked", "Vale.X64.Machine_s.fst.checked", "Vale.X64.Instruction_s.fsti.checked", "Vale.X64.Flags.fsti.checked", "Vale.X64.Bytes_Code_s.fst.checked", "prims.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.FunctionalExtensionality.fsti.checked" ], "interface_file": true, "source_file": "Vale.X64.Lemmas.fst" }
[ { "abbrev": true, "full_module": "Vale.X64.Memory", "short_module": "ME" }, { "abbrev": true, "full_module": "Vale.X64.Machine_Semantics_s", "short_module": "BS" }, { "abbrev": false, "full_module": "Vale.X64.Bytes_Code_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Instruction_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.StateLemmas", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.State", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Machine_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": true, "full_module": "Vale.Lib.Map16", "short_module": "Map16" }, { "abbrev": true, "full_module": "Vale.X64.Machine_Semantics_s", "short_module": "BS" }, { "abbrev": false, "full_module": "Vale.X64.Bytes_Code_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.StateLemmas", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.State", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Machine_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.HeapLemmas", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.HeapImpl", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.Heap", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 0, "max_fuel": 2, "max_ifuel": 1, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": true, "smtencoding_l_arith_repr": "native", "smtencoding_nl_arith_repr": "wrapped", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [ "smt.arith.nl=false", "smt.QI.EAGER_THRESHOLD=100", "smt.CASE_SPLIT=3" ], "z3refresh": false, "z3rlimit": 30, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
c: Vale.X64.StateLemmas.code -> f: Vale.X64.Lemmas.fuel -> s1: Vale.X64.StateLemmas.machine_state -> s2: Vale.X64.StateLemmas.machine_state -> FStar.Pervasives.Lemma (requires Vale.X64.Lemmas.state_eq_S false s1 s2) (ensures Vale.X64.Lemmas.state_eq_opt false (Vale.X64.Machine_Semantics_s.machine_eval_code c f s1) (Vale.X64.Machine_Semantics_s.machine_eval_code c f s2)) [ SMTPat (Vale.X64.Machine_Semantics_s.machine_eval_code c f s1); SMTPat (Vale.X64.Machine_Semantics_s.machine_eval_code c f s2) ]
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "Vale.X64.StateLemmas.code", "Vale.X64.Lemmas.fuel", "Vale.X64.StateLemmas.machine_state", "Vale.X64.Lemmas.eval_code_eq_core", "Prims.unit", "Vale.X64.Lemmas.state_eq_S", "Prims.squash", "Vale.X64.Lemmas.state_eq_opt", "Vale.X64.Machine_Semantics_s.machine_eval_code", "Prims.Cons", "FStar.Pervasives.pattern", "FStar.Pervasives.smt_pat", "FStar.Pervasives.Native.option", "Vale.X64.Machine_Semantics_s.machine_state", "Prims.Nil" ]
[]
true
false
true
false
false
let eval_code_eq_f (c: code) (f: fuel) (s1 s2: machine_state) : Lemma (requires state_eq_S false s1 s2) (ensures state_eq_opt false (BS.machine_eval_code c f s1) (BS.machine_eval_code c f s2)) [SMTPat (BS.machine_eval_code c f s1); SMTPat (BS.machine_eval_code c f s2)] =
eval_code_eq_core false c f s1; eval_code_eq_core false c f s2
false
Vale.X64.Lemmas.fst
Vale.X64.Lemmas.eval_ins_eq_instr
val eval_ins_eq_instr (inst: BS.ins) (s1 s2: machine_state) : Lemma (requires Instr? inst /\ state_eq_S true s1 s2) (ensures state_eq_S true (BS.machine_eval_ins inst s1) (BS.machine_eval_ins inst s2))
val eval_ins_eq_instr (inst: BS.ins) (s1 s2: machine_state) : Lemma (requires Instr? inst /\ state_eq_S true s1 s2) (ensures state_eq_S true (BS.machine_eval_ins inst s1) (BS.machine_eval_ins inst s2))
let eval_ins_eq_instr (inst:BS.ins) (s1 s2:machine_state) : Lemma (requires Instr? inst /\ state_eq_S true s1 s2) (ensures state_eq_S true (BS.machine_eval_ins inst s1) (BS.machine_eval_ins inst s2)) = let open BS in let Instr it oprs ann = inst in let InstrTypeRecord #outs #args #havoc_flags' i = it in lemma_eq_instr_apply_eval_inouts outs outs args (instr_eval i) oprs s1 s2; let vs = instr_apply_eval outs args (instr_eval i) oprs s1 in let hav s = match havoc_flags' with | HavocFlags -> {s with ms_flags = havoc_flags} | PreserveFlags -> s in let s1' = hav s1 in let s2' = hav s2 in match vs with | None -> () | Some vs -> lemma_eq_instr_write_outputs outs args vs oprs s1 s1' s2 s2'
{ "file_name": "vale/code/arch/x64/Vale.X64.Lemmas.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 77, "end_line": 134, "start_col": 0, "start_line": 116 }
module Vale.X64.Lemmas open FStar.Mul open Vale.X64.Machine_s open Vale.X64.State open Vale.X64.StateLemmas open Vale.X64.Instruction_s open Vale.X64.Bytes_Code_s module BS = Vale.X64.Machine_Semantics_s module ME = Vale.X64.Memory #reset-options "--initial_fuel 1 --max_fuel 1 --z3rlimit 100" #restart-solver let rec lemma_eq_instr_apply_eval_args (outs:list instr_out) (args:list instr_operand) (f:instr_args_t outs args) (oprs:instr_operands_t_args args) (s1 s2:machine_state) : Lemma (requires state_eq_S true s1 s2) (ensures BS.instr_apply_eval_args outs args f oprs s1 == BS.instr_apply_eval_args outs args f oprs s2) = let open BS in lemma_heap_ignore_ghost_machine s1.BS.ms_heap s2.BS.ms_heap; match args with | [] -> () | i::args -> ( let (v, oprs) : option (instr_val_t i) & instr_operands_t_args args = match i with | IOpEx i -> let oprs = coerce oprs in (instr_eval_operand_explicit i (fst oprs) s1, snd oprs) | IOpIm i -> (instr_eval_operand_implicit i s1, coerce oprs) in let f:arrow (instr_val_t i) (instr_args_t outs args) = coerce f in match v with | None -> () | Some v -> lemma_eq_instr_apply_eval_args outs args (f v) oprs s1 s2 ) #restart-solver let rec lemma_eq_instr_apply_eval_inouts (outs inouts:list instr_out) (args:list instr_operand) (f:instr_inouts_t outs inouts args) (oprs:instr_operands_t inouts args) (s1 s2:machine_state) : Lemma (requires state_eq_S true s1 s2) (ensures BS.instr_apply_eval_inouts outs inouts args f oprs s1 == BS.instr_apply_eval_inouts outs inouts args f oprs s2) = let open BS in lemma_heap_ignore_ghost_machine s1.BS.ms_heap s2.BS.ms_heap; match inouts with | [] -> lemma_eq_instr_apply_eval_args outs args f oprs s1 s2 | (Out, i)::inouts -> let oprs = match i with | IOpEx i -> snd #(instr_operand_t i) (coerce oprs) | IOpIm i -> coerce oprs in lemma_eq_instr_apply_eval_inouts outs inouts args (coerce f) oprs s1 s2 | (InOut, i)::inouts -> ( let (v, oprs) : option (instr_val_t i) & instr_operands_t inouts args = match i with | IOpEx i -> let oprs = coerce oprs in (instr_eval_operand_explicit i (fst oprs) s1, snd oprs) | IOpIm i -> (instr_eval_operand_implicit i s1, coerce oprs) in let f:arrow (instr_val_t i) (instr_inouts_t outs inouts args) = coerce f in match v with | None -> () | Some v -> lemma_eq_instr_apply_eval_inouts outs inouts args (f v) oprs s1 s2 ) #restart-solver #push-options "--z3rlimit_factor 2" let rec lemma_eq_instr_write_outputs (outs:list instr_out) (args:list instr_operand) (vs:instr_ret_t outs) (oprs:instr_operands_t outs args) (s1_orig s1 s2_orig s2:machine_state) : Lemma (requires state_eq_S true s1_orig s2_orig /\ state_eq_S true s1 s2) (ensures state_eq_S true (BS.instr_write_outputs outs args vs oprs s1_orig s1) (BS.instr_write_outputs outs args vs oprs s2_orig s2)) = let open BS in use_machine_state_equal (); lemma_heap_ignore_ghost_machine s1.BS.ms_heap s2.BS.ms_heap; lemma_heap_ignore_ghost_machine s1_orig.BS.ms_heap s2_orig.BS.ms_heap; allow_inversion tmaddr; match outs with | [] -> () | (_, i)::outs -> ( let ((v:instr_val_t i), (vs:instr_ret_t outs)) = match outs with | [] -> (vs, ()) | _::_ -> let vs = coerce vs in (fst vs, snd vs) in match i with | IOpEx i -> let oprs = coerce oprs in let s1 = instr_write_output_explicit i v (fst oprs) s1_orig s1 in let s2 = instr_write_output_explicit i v (fst oprs) s2_orig s2 in lemma_eq_instr_write_outputs outs args vs (snd oprs) s1_orig s1 s2_orig s2 | IOpIm i -> let s1 = instr_write_output_implicit i v s1_orig s1 in let s2 = instr_write_output_implicit i v s2_orig s2 in allow_inversion operand64; allow_inversion operand128; lemma_eq_instr_write_outputs outs args vs (coerce oprs) s1_orig s1 s2_orig s2 ) #pop-options
{ "checked_file": "/", "dependencies": [ "Vale.X64.StateLemmas.fsti.checked", "Vale.X64.State.fsti.checked", "Vale.X64.Memory.fsti.checked", "Vale.X64.Machine_Semantics_s.fst.checked", "Vale.X64.Machine_s.fst.checked", "Vale.X64.Instruction_s.fsti.checked", "Vale.X64.Flags.fsti.checked", "Vale.X64.Bytes_Code_s.fst.checked", "prims.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.FunctionalExtensionality.fsti.checked" ], "interface_file": true, "source_file": "Vale.X64.Lemmas.fst" }
[ { "abbrev": true, "full_module": "Vale.X64.Memory", "short_module": "ME" }, { "abbrev": true, "full_module": "Vale.X64.Machine_Semantics_s", "short_module": "BS" }, { "abbrev": false, "full_module": "Vale.X64.Bytes_Code_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Instruction_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.StateLemmas", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.State", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Machine_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": true, "full_module": "Vale.Lib.Map16", "short_module": "Map16" }, { "abbrev": true, "full_module": "Vale.X64.Machine_Semantics_s", "short_module": "BS" }, { "abbrev": false, "full_module": "Vale.X64.Bytes_Code_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.StateLemmas", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.State", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Machine_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.HeapLemmas", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.HeapImpl", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.Heap", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 1, "initial_ifuel": 0, "max_fuel": 1, "max_ifuel": 1, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": true, "smtencoding_l_arith_repr": "native", "smtencoding_nl_arith_repr": "wrapped", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [ "smt.arith.nl=false", "smt.QI.EAGER_THRESHOLD=100", "smt.CASE_SPLIT=3" ], "z3refresh": false, "z3rlimit": 100, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
inst: Vale.X64.Machine_Semantics_s.ins -> s1: Vale.X64.StateLemmas.machine_state -> s2: Vale.X64.StateLemmas.machine_state -> FStar.Pervasives.Lemma (requires Instr? inst /\ Vale.X64.Lemmas.state_eq_S true s1 s2) (ensures Vale.X64.Lemmas.state_eq_S true (Vale.X64.Machine_Semantics_s.machine_eval_ins inst s1) (Vale.X64.Machine_Semantics_s.machine_eval_ins inst s2))
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "Vale.X64.Machine_Semantics_s.ins", "Vale.X64.StateLemmas.machine_state", "Vale.X64.Instruction_s.instr_t_record", "Vale.X64.Instruction_s.instr_operands_t", "Vale.X64.Instruction_s.__proj__InstrTypeRecord__item__outs", "Vale.X64.Instruction_s.__proj__InstrTypeRecord__item__args", "Vale.X64.Machine_Semantics_s.instr_annotation", "Prims.list", "Vale.X64.Instruction_s.instr_out", "Vale.X64.Instruction_s.instr_operand", "Vale.X64.Instruction_s.flag_havoc", "Vale.X64.Instruction_s.instr_t", "Vale.X64.Instruction_s.instr_ret_t", "Vale.X64.Lemmas.lemma_eq_instr_write_outputs", "Prims.unit", "Vale.X64.Machine_Semantics_s.machine_state", "Vale.X64.Machine_Semantics_s.Mkmachine_state", "Vale.X64.Machine_Semantics_s.__proj__Mkmachine_state__item__ms_ok", "Vale.X64.Machine_Semantics_s.__proj__Mkmachine_state__item__ms_regs", "Vale.X64.Machine_Semantics_s.havoc_flags", "Vale.X64.Machine_Semantics_s.__proj__Mkmachine_state__item__ms_heap", "Vale.X64.Machine_Semantics_s.__proj__Mkmachine_state__item__ms_stack", "Vale.X64.Machine_Semantics_s.__proj__Mkmachine_state__item__ms_stackTaint", "Vale.X64.Machine_Semantics_s.__proj__Mkmachine_state__item__ms_trace", "FStar.Pervasives.Native.option", "Vale.X64.Machine_Semantics_s.instr_apply_eval", "Vale.X64.Instruction_s.instr_eval", "Vale.X64.Lemmas.lemma_eq_instr_apply_eval_inouts", "Prims.l_and", "Prims.b2t", "Vale.X64.Bytes_Code_s.uu___is_Instr", "Vale.X64.Lemmas.state_eq_S", "Prims.squash", "Vale.X64.Machine_Semantics_s.machine_eval_ins", "Prims.Nil", "FStar.Pervasives.pattern" ]
[]
false
false
true
false
false
let eval_ins_eq_instr (inst: BS.ins) (s1 s2: machine_state) : Lemma (requires Instr? inst /\ state_eq_S true s1 s2) (ensures state_eq_S true (BS.machine_eval_ins inst s1) (BS.machine_eval_ins inst s2)) =
let open BS in let Instr it oprs ann = inst in let InstrTypeRecord #outs #args #havoc_flags' i = it in lemma_eq_instr_apply_eval_inouts outs outs args (instr_eval i) oprs s1 s2; let vs = instr_apply_eval outs args (instr_eval i) oprs s1 in let hav s = match havoc_flags' with | HavocFlags -> { s with ms_flags = havoc_flags } | PreserveFlags -> s in let s1' = hav s1 in let s2' = hav s2 in match vs with | None -> () | Some vs -> lemma_eq_instr_write_outputs outs args vs oprs s1 s1' s2 s2'
false
Vale.X64.Lemmas.fst
Vale.X64.Lemmas.eval_code_eq_alloc
val eval_code_eq_alloc (inst: BS.ins) (f: fuel) (s1 s2: machine_state) : Lemma (requires Alloc? inst /\ state_eq_S true s1 s2) (ensures state_eq_opt true (BS.machine_eval_code (Ins inst) f s1) (BS.machine_eval_code (Ins inst) f s2))
val eval_code_eq_alloc (inst: BS.ins) (f: fuel) (s1 s2: machine_state) : Lemma (requires Alloc? inst /\ state_eq_S true s1 s2) (ensures state_eq_opt true (BS.machine_eval_code (Ins inst) f s1) (BS.machine_eval_code (Ins inst) f s2))
let eval_code_eq_alloc (inst:BS.ins) (f:fuel) (s1 s2:machine_state) : Lemma (requires Alloc? inst /\ state_eq_S true s1 s2) (ensures state_eq_opt true (BS.machine_eval_code (Ins inst) f s1) (BS.machine_eval_code (Ins inst) f s2)) = reveal_opaque (`%BS.machine_eval_code_ins) BS.machine_eval_code_ins; use_machine_state_equal (); lemma_heap_ignore_ghost_machine s1.BS.ms_heap s2.BS.ms_heap; allow_inversion tmaddr
{ "file_name": "vale/code/arch/x64/Vale.X64.Lemmas.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 24, "end_line": 159, "start_col": 0, "start_line": 152 }
module Vale.X64.Lemmas open FStar.Mul open Vale.X64.Machine_s open Vale.X64.State open Vale.X64.StateLemmas open Vale.X64.Instruction_s open Vale.X64.Bytes_Code_s module BS = Vale.X64.Machine_Semantics_s module ME = Vale.X64.Memory #reset-options "--initial_fuel 1 --max_fuel 1 --z3rlimit 100" #restart-solver let rec lemma_eq_instr_apply_eval_args (outs:list instr_out) (args:list instr_operand) (f:instr_args_t outs args) (oprs:instr_operands_t_args args) (s1 s2:machine_state) : Lemma (requires state_eq_S true s1 s2) (ensures BS.instr_apply_eval_args outs args f oprs s1 == BS.instr_apply_eval_args outs args f oprs s2) = let open BS in lemma_heap_ignore_ghost_machine s1.BS.ms_heap s2.BS.ms_heap; match args with | [] -> () | i::args -> ( let (v, oprs) : option (instr_val_t i) & instr_operands_t_args args = match i with | IOpEx i -> let oprs = coerce oprs in (instr_eval_operand_explicit i (fst oprs) s1, snd oprs) | IOpIm i -> (instr_eval_operand_implicit i s1, coerce oprs) in let f:arrow (instr_val_t i) (instr_args_t outs args) = coerce f in match v with | None -> () | Some v -> lemma_eq_instr_apply_eval_args outs args (f v) oprs s1 s2 ) #restart-solver let rec lemma_eq_instr_apply_eval_inouts (outs inouts:list instr_out) (args:list instr_operand) (f:instr_inouts_t outs inouts args) (oprs:instr_operands_t inouts args) (s1 s2:machine_state) : Lemma (requires state_eq_S true s1 s2) (ensures BS.instr_apply_eval_inouts outs inouts args f oprs s1 == BS.instr_apply_eval_inouts outs inouts args f oprs s2) = let open BS in lemma_heap_ignore_ghost_machine s1.BS.ms_heap s2.BS.ms_heap; match inouts with | [] -> lemma_eq_instr_apply_eval_args outs args f oprs s1 s2 | (Out, i)::inouts -> let oprs = match i with | IOpEx i -> snd #(instr_operand_t i) (coerce oprs) | IOpIm i -> coerce oprs in lemma_eq_instr_apply_eval_inouts outs inouts args (coerce f) oprs s1 s2 | (InOut, i)::inouts -> ( let (v, oprs) : option (instr_val_t i) & instr_operands_t inouts args = match i with | IOpEx i -> let oprs = coerce oprs in (instr_eval_operand_explicit i (fst oprs) s1, snd oprs) | IOpIm i -> (instr_eval_operand_implicit i s1, coerce oprs) in let f:arrow (instr_val_t i) (instr_inouts_t outs inouts args) = coerce f in match v with | None -> () | Some v -> lemma_eq_instr_apply_eval_inouts outs inouts args (f v) oprs s1 s2 ) #restart-solver #push-options "--z3rlimit_factor 2" let rec lemma_eq_instr_write_outputs (outs:list instr_out) (args:list instr_operand) (vs:instr_ret_t outs) (oprs:instr_operands_t outs args) (s1_orig s1 s2_orig s2:machine_state) : Lemma (requires state_eq_S true s1_orig s2_orig /\ state_eq_S true s1 s2) (ensures state_eq_S true (BS.instr_write_outputs outs args vs oprs s1_orig s1) (BS.instr_write_outputs outs args vs oprs s2_orig s2)) = let open BS in use_machine_state_equal (); lemma_heap_ignore_ghost_machine s1.BS.ms_heap s2.BS.ms_heap; lemma_heap_ignore_ghost_machine s1_orig.BS.ms_heap s2_orig.BS.ms_heap; allow_inversion tmaddr; match outs with | [] -> () | (_, i)::outs -> ( let ((v:instr_val_t i), (vs:instr_ret_t outs)) = match outs with | [] -> (vs, ()) | _::_ -> let vs = coerce vs in (fst vs, snd vs) in match i with | IOpEx i -> let oprs = coerce oprs in let s1 = instr_write_output_explicit i v (fst oprs) s1_orig s1 in let s2 = instr_write_output_explicit i v (fst oprs) s2_orig s2 in lemma_eq_instr_write_outputs outs args vs (snd oprs) s1_orig s1 s2_orig s2 | IOpIm i -> let s1 = instr_write_output_implicit i v s1_orig s1 in let s2 = instr_write_output_implicit i v s2_orig s2 in allow_inversion operand64; allow_inversion operand128; lemma_eq_instr_write_outputs outs args vs (coerce oprs) s1_orig s1 s2_orig s2 ) #pop-options #restart-solver let eval_ins_eq_instr (inst:BS.ins) (s1 s2:machine_state) : Lemma (requires Instr? inst /\ state_eq_S true s1 s2) (ensures state_eq_S true (BS.machine_eval_ins inst s1) (BS.machine_eval_ins inst s2)) = let open BS in let Instr it oprs ann = inst in let InstrTypeRecord #outs #args #havoc_flags' i = it in lemma_eq_instr_apply_eval_inouts outs outs args (instr_eval i) oprs s1 s2; let vs = instr_apply_eval outs args (instr_eval i) oprs s1 in let hav s = match havoc_flags' with | HavocFlags -> {s with ms_flags = havoc_flags} | PreserveFlags -> s in let s1' = hav s1 in let s2' = hav s2 in match vs with | None -> () | Some vs -> lemma_eq_instr_write_outputs outs args vs oprs s1 s1' s2 s2' let eval_code_eq_instr (inst:BS.ins) (f:fuel) (s1 s2:machine_state) : Lemma (requires Instr? inst /\ state_eq_S true s1 s2) (ensures state_eq_opt true (BS.machine_eval_code (Ins inst) f s1) (BS.machine_eval_code (Ins inst) f s2)) = reveal_opaque (`%BS.machine_eval_code_ins) BS.machine_eval_code_ins; eval_ins_eq_instr inst ({s1 with BS.ms_trace = []}) ({s2 with BS.ms_trace = []}) let eval_code_eq_dealloc (inst:BS.ins) (f:fuel) (s1 s2:machine_state) : Lemma (requires Dealloc? inst /\ state_eq_S true s1 s2) (ensures state_eq_opt true (BS.machine_eval_code (Ins inst) f s1) (BS.machine_eval_code (Ins inst) f s2)) = reveal_opaque (`%BS.machine_eval_code_ins) BS.machine_eval_code_ins; use_machine_state_equal (); lemma_heap_ignore_ghost_machine s1.BS.ms_heap s2.BS.ms_heap; allow_inversion tmaddr
{ "checked_file": "/", "dependencies": [ "Vale.X64.StateLemmas.fsti.checked", "Vale.X64.State.fsti.checked", "Vale.X64.Memory.fsti.checked", "Vale.X64.Machine_Semantics_s.fst.checked", "Vale.X64.Machine_s.fst.checked", "Vale.X64.Instruction_s.fsti.checked", "Vale.X64.Flags.fsti.checked", "Vale.X64.Bytes_Code_s.fst.checked", "prims.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.FunctionalExtensionality.fsti.checked" ], "interface_file": true, "source_file": "Vale.X64.Lemmas.fst" }
[ { "abbrev": true, "full_module": "Vale.X64.Memory", "short_module": "ME" }, { "abbrev": true, "full_module": "Vale.X64.Machine_Semantics_s", "short_module": "BS" }, { "abbrev": false, "full_module": "Vale.X64.Bytes_Code_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Instruction_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.StateLemmas", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.State", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Machine_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": true, "full_module": "Vale.Lib.Map16", "short_module": "Map16" }, { "abbrev": true, "full_module": "Vale.X64.Machine_Semantics_s", "short_module": "BS" }, { "abbrev": false, "full_module": "Vale.X64.Bytes_Code_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.StateLemmas", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.State", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Machine_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.HeapLemmas", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.HeapImpl", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.Heap", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 1, "initial_ifuel": 0, "max_fuel": 1, "max_ifuel": 1, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": true, "smtencoding_l_arith_repr": "native", "smtencoding_nl_arith_repr": "wrapped", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [ "smt.arith.nl=false", "smt.QI.EAGER_THRESHOLD=100", "smt.CASE_SPLIT=3" ], "z3refresh": false, "z3rlimit": 100, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
inst: Vale.X64.Machine_Semantics_s.ins -> f: Vale.X64.Lemmas.fuel -> s1: Vale.X64.StateLemmas.machine_state -> s2: Vale.X64.StateLemmas.machine_state -> FStar.Pervasives.Lemma (requires Alloc? inst /\ Vale.X64.Lemmas.state_eq_S true s1 s2) (ensures Vale.X64.Lemmas.state_eq_opt true (Vale.X64.Machine_Semantics_s.machine_eval_code (Vale.X64.Machine_s.Ins inst) f s1) (Vale.X64.Machine_Semantics_s.machine_eval_code (Vale.X64.Machine_s.Ins inst) f s2))
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "Vale.X64.Machine_Semantics_s.ins", "Vale.X64.Lemmas.fuel", "Vale.X64.StateLemmas.machine_state", "FStar.Pervasives.allow_inversion", "Vale.X64.Machine_s.tmaddr", "Prims.unit", "Vale.Arch.HeapLemmas.lemma_heap_ignore_ghost_machine", "Vale.X64.Machine_Semantics_s.__proj__Mkmachine_state__item__ms_heap", "Vale.X64.StateLemmas.use_machine_state_equal", "FStar.Pervasives.reveal_opaque", "Vale.X64.Machine_Semantics_s.machine_state", "FStar.Pervasives.Native.option", "Vale.X64.Machine_Semantics_s.machine_eval_code_ins", "Prims.l_and", "Prims.b2t", "Vale.X64.Bytes_Code_s.uu___is_Alloc", "Vale.X64.Machine_Semantics_s.instr_annotation", "Vale.X64.Lemmas.state_eq_S", "Prims.squash", "Vale.X64.Lemmas.state_eq_opt", "Vale.X64.Machine_Semantics_s.machine_eval_code", "Vale.X64.Machine_s.Ins", "Vale.X64.Bytes_Code_s.instruction_t", "Vale.X64.Bytes_Code_s.ocmp", "Prims.Nil", "FStar.Pervasives.pattern" ]
[]
true
false
true
false
false
let eval_code_eq_alloc (inst: BS.ins) (f: fuel) (s1 s2: machine_state) : Lemma (requires Alloc? inst /\ state_eq_S true s1 s2) (ensures state_eq_opt true (BS.machine_eval_code (Ins inst) f s1) (BS.machine_eval_code (Ins inst) f s2)) =
reveal_opaque (`%BS.machine_eval_code_ins) BS.machine_eval_code_ins; use_machine_state_equal (); lemma_heap_ignore_ghost_machine s1.BS.ms_heap s2.BS.ms_heap; allow_inversion tmaddr
false
Vale.X64.Lemmas.fst
Vale.X64.Lemmas.eval_code_eq_ins
val eval_code_eq_ins (i: BS.ins) (f: fuel) (s1 s2: machine_state) : Lemma (requires state_eq_S true s1 s2) (ensures state_eq_opt true (BS.machine_eval_code (Ins i) f s1) (BS.machine_eval_code (Ins i) f s2))
val eval_code_eq_ins (i: BS.ins) (f: fuel) (s1 s2: machine_state) : Lemma (requires state_eq_S true s1 s2) (ensures state_eq_opt true (BS.machine_eval_code (Ins i) f s1) (BS.machine_eval_code (Ins i) f s2))
let eval_code_eq_ins (i:BS.ins) (f:fuel) (s1 s2:machine_state) : Lemma (requires state_eq_S true s1 s2) (ensures state_eq_opt true (BS.machine_eval_code (Ins i) f s1) (BS.machine_eval_code (Ins i) f s2)) = match i with | Instr _ _ _ -> eval_code_eq_instr i f s1 s2 | Dealloc _ -> eval_code_eq_dealloc i f s1 s2 | Alloc _ -> eval_code_eq_alloc i f s1 s2 | Push _ _ -> eval_code_eq_push i f s1 s2 | Pop _ _ -> eval_code_eq_pop i f s1 s2
{ "file_name": "vale/code/arch/x64/Vale.X64.Lemmas.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 42, "end_line": 188, "start_col": 0, "start_line": 179 }
module Vale.X64.Lemmas open FStar.Mul open Vale.X64.Machine_s open Vale.X64.State open Vale.X64.StateLemmas open Vale.X64.Instruction_s open Vale.X64.Bytes_Code_s module BS = Vale.X64.Machine_Semantics_s module ME = Vale.X64.Memory #reset-options "--initial_fuel 1 --max_fuel 1 --z3rlimit 100" #restart-solver let rec lemma_eq_instr_apply_eval_args (outs:list instr_out) (args:list instr_operand) (f:instr_args_t outs args) (oprs:instr_operands_t_args args) (s1 s2:machine_state) : Lemma (requires state_eq_S true s1 s2) (ensures BS.instr_apply_eval_args outs args f oprs s1 == BS.instr_apply_eval_args outs args f oprs s2) = let open BS in lemma_heap_ignore_ghost_machine s1.BS.ms_heap s2.BS.ms_heap; match args with | [] -> () | i::args -> ( let (v, oprs) : option (instr_val_t i) & instr_operands_t_args args = match i with | IOpEx i -> let oprs = coerce oprs in (instr_eval_operand_explicit i (fst oprs) s1, snd oprs) | IOpIm i -> (instr_eval_operand_implicit i s1, coerce oprs) in let f:arrow (instr_val_t i) (instr_args_t outs args) = coerce f in match v with | None -> () | Some v -> lemma_eq_instr_apply_eval_args outs args (f v) oprs s1 s2 ) #restart-solver let rec lemma_eq_instr_apply_eval_inouts (outs inouts:list instr_out) (args:list instr_operand) (f:instr_inouts_t outs inouts args) (oprs:instr_operands_t inouts args) (s1 s2:machine_state) : Lemma (requires state_eq_S true s1 s2) (ensures BS.instr_apply_eval_inouts outs inouts args f oprs s1 == BS.instr_apply_eval_inouts outs inouts args f oprs s2) = let open BS in lemma_heap_ignore_ghost_machine s1.BS.ms_heap s2.BS.ms_heap; match inouts with | [] -> lemma_eq_instr_apply_eval_args outs args f oprs s1 s2 | (Out, i)::inouts -> let oprs = match i with | IOpEx i -> snd #(instr_operand_t i) (coerce oprs) | IOpIm i -> coerce oprs in lemma_eq_instr_apply_eval_inouts outs inouts args (coerce f) oprs s1 s2 | (InOut, i)::inouts -> ( let (v, oprs) : option (instr_val_t i) & instr_operands_t inouts args = match i with | IOpEx i -> let oprs = coerce oprs in (instr_eval_operand_explicit i (fst oprs) s1, snd oprs) | IOpIm i -> (instr_eval_operand_implicit i s1, coerce oprs) in let f:arrow (instr_val_t i) (instr_inouts_t outs inouts args) = coerce f in match v with | None -> () | Some v -> lemma_eq_instr_apply_eval_inouts outs inouts args (f v) oprs s1 s2 ) #restart-solver #push-options "--z3rlimit_factor 2" let rec lemma_eq_instr_write_outputs (outs:list instr_out) (args:list instr_operand) (vs:instr_ret_t outs) (oprs:instr_operands_t outs args) (s1_orig s1 s2_orig s2:machine_state) : Lemma (requires state_eq_S true s1_orig s2_orig /\ state_eq_S true s1 s2) (ensures state_eq_S true (BS.instr_write_outputs outs args vs oprs s1_orig s1) (BS.instr_write_outputs outs args vs oprs s2_orig s2)) = let open BS in use_machine_state_equal (); lemma_heap_ignore_ghost_machine s1.BS.ms_heap s2.BS.ms_heap; lemma_heap_ignore_ghost_machine s1_orig.BS.ms_heap s2_orig.BS.ms_heap; allow_inversion tmaddr; match outs with | [] -> () | (_, i)::outs -> ( let ((v:instr_val_t i), (vs:instr_ret_t outs)) = match outs with | [] -> (vs, ()) | _::_ -> let vs = coerce vs in (fst vs, snd vs) in match i with | IOpEx i -> let oprs = coerce oprs in let s1 = instr_write_output_explicit i v (fst oprs) s1_orig s1 in let s2 = instr_write_output_explicit i v (fst oprs) s2_orig s2 in lemma_eq_instr_write_outputs outs args vs (snd oprs) s1_orig s1 s2_orig s2 | IOpIm i -> let s1 = instr_write_output_implicit i v s1_orig s1 in let s2 = instr_write_output_implicit i v s2_orig s2 in allow_inversion operand64; allow_inversion operand128; lemma_eq_instr_write_outputs outs args vs (coerce oprs) s1_orig s1 s2_orig s2 ) #pop-options #restart-solver let eval_ins_eq_instr (inst:BS.ins) (s1 s2:machine_state) : Lemma (requires Instr? inst /\ state_eq_S true s1 s2) (ensures state_eq_S true (BS.machine_eval_ins inst s1) (BS.machine_eval_ins inst s2)) = let open BS in let Instr it oprs ann = inst in let InstrTypeRecord #outs #args #havoc_flags' i = it in lemma_eq_instr_apply_eval_inouts outs outs args (instr_eval i) oprs s1 s2; let vs = instr_apply_eval outs args (instr_eval i) oprs s1 in let hav s = match havoc_flags' with | HavocFlags -> {s with ms_flags = havoc_flags} | PreserveFlags -> s in let s1' = hav s1 in let s2' = hav s2 in match vs with | None -> () | Some vs -> lemma_eq_instr_write_outputs outs args vs oprs s1 s1' s2 s2' let eval_code_eq_instr (inst:BS.ins) (f:fuel) (s1 s2:machine_state) : Lemma (requires Instr? inst /\ state_eq_S true s1 s2) (ensures state_eq_opt true (BS.machine_eval_code (Ins inst) f s1) (BS.machine_eval_code (Ins inst) f s2)) = reveal_opaque (`%BS.machine_eval_code_ins) BS.machine_eval_code_ins; eval_ins_eq_instr inst ({s1 with BS.ms_trace = []}) ({s2 with BS.ms_trace = []}) let eval_code_eq_dealloc (inst:BS.ins) (f:fuel) (s1 s2:machine_state) : Lemma (requires Dealloc? inst /\ state_eq_S true s1 s2) (ensures state_eq_opt true (BS.machine_eval_code (Ins inst) f s1) (BS.machine_eval_code (Ins inst) f s2)) = reveal_opaque (`%BS.machine_eval_code_ins) BS.machine_eval_code_ins; use_machine_state_equal (); lemma_heap_ignore_ghost_machine s1.BS.ms_heap s2.BS.ms_heap; allow_inversion tmaddr let eval_code_eq_alloc (inst:BS.ins) (f:fuel) (s1 s2:machine_state) : Lemma (requires Alloc? inst /\ state_eq_S true s1 s2) (ensures state_eq_opt true (BS.machine_eval_code (Ins inst) f s1) (BS.machine_eval_code (Ins inst) f s2)) = reveal_opaque (`%BS.machine_eval_code_ins) BS.machine_eval_code_ins; use_machine_state_equal (); lemma_heap_ignore_ghost_machine s1.BS.ms_heap s2.BS.ms_heap; allow_inversion tmaddr let eval_code_eq_push (inst:BS.ins) (f:fuel) (s1 s2:machine_state) : Lemma (requires Push? inst /\ state_eq_S true s1 s2) (ensures state_eq_opt true (BS.machine_eval_code (Ins inst) f s1) (BS.machine_eval_code (Ins inst) f s2)) = reveal_opaque (`%BS.machine_eval_code_ins) BS.machine_eval_code_ins; use_machine_state_equal (); lemma_heap_ignore_ghost_machine s1.BS.ms_heap s2.BS.ms_heap; allow_inversion tmaddr let eval_code_eq_pop (inst:BS.ins) (f:fuel) (s1 s2:machine_state) : Lemma (requires Pop? inst /\ state_eq_S true s1 s2) (ensures state_eq_opt true (BS.machine_eval_code (Ins inst) f s1) (BS.machine_eval_code (Ins inst) f s2)) = reveal_opaque (`%BS.machine_eval_code_ins) BS.machine_eval_code_ins; use_machine_state_equal (); lemma_heap_ignore_ghost_machine s1.BS.ms_heap s2.BS.ms_heap; allow_inversion tmaddr
{ "checked_file": "/", "dependencies": [ "Vale.X64.StateLemmas.fsti.checked", "Vale.X64.State.fsti.checked", "Vale.X64.Memory.fsti.checked", "Vale.X64.Machine_Semantics_s.fst.checked", "Vale.X64.Machine_s.fst.checked", "Vale.X64.Instruction_s.fsti.checked", "Vale.X64.Flags.fsti.checked", "Vale.X64.Bytes_Code_s.fst.checked", "prims.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.FunctionalExtensionality.fsti.checked" ], "interface_file": true, "source_file": "Vale.X64.Lemmas.fst" }
[ { "abbrev": true, "full_module": "Vale.X64.Memory", "short_module": "ME" }, { "abbrev": true, "full_module": "Vale.X64.Machine_Semantics_s", "short_module": "BS" }, { "abbrev": false, "full_module": "Vale.X64.Bytes_Code_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Instruction_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.StateLemmas", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.State", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Machine_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": true, "full_module": "Vale.Lib.Map16", "short_module": "Map16" }, { "abbrev": true, "full_module": "Vale.X64.Machine_Semantics_s", "short_module": "BS" }, { "abbrev": false, "full_module": "Vale.X64.Bytes_Code_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.StateLemmas", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.State", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Machine_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.HeapLemmas", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.HeapImpl", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.Heap", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 1, "initial_ifuel": 0, "max_fuel": 1, "max_ifuel": 1, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": true, "smtencoding_l_arith_repr": "native", "smtencoding_nl_arith_repr": "wrapped", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [ "smt.arith.nl=false", "smt.QI.EAGER_THRESHOLD=100", "smt.CASE_SPLIT=3" ], "z3refresh": false, "z3rlimit": 100, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
i: Vale.X64.Machine_Semantics_s.ins -> f: Vale.X64.Lemmas.fuel -> s1: Vale.X64.StateLemmas.machine_state -> s2: Vale.X64.StateLemmas.machine_state -> FStar.Pervasives.Lemma (requires Vale.X64.Lemmas.state_eq_S true s1 s2) (ensures Vale.X64.Lemmas.state_eq_opt true (Vale.X64.Machine_Semantics_s.machine_eval_code (Vale.X64.Machine_s.Ins i) f s1) (Vale.X64.Machine_Semantics_s.machine_eval_code (Vale.X64.Machine_s.Ins i) f s2))
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "Vale.X64.Machine_Semantics_s.ins", "Vale.X64.Lemmas.fuel", "Vale.X64.StateLemmas.machine_state", "Vale.X64.Instruction_s.instr_t_record", "Vale.X64.Instruction_s.instr_operands_t", "Vale.X64.Instruction_s.__proj__InstrTypeRecord__item__outs", "Vale.X64.Instruction_s.__proj__InstrTypeRecord__item__args", "Vale.X64.Machine_Semantics_s.instr_annotation", "Vale.X64.Lemmas.eval_code_eq_instr", "Vale.X64.Machine_s.nat64", "Vale.X64.Lemmas.eval_code_eq_dealloc", "Vale.X64.Lemmas.eval_code_eq_alloc", "Vale.X64.Machine_s.operand64", "Vale.Arch.HeapTypes_s.taint", "Vale.X64.Lemmas.eval_code_eq_push", "Vale.X64.Lemmas.eval_code_eq_pop", "Prims.unit", "Vale.X64.Lemmas.state_eq_S", "Prims.squash", "Vale.X64.Lemmas.state_eq_opt", "Vale.X64.Machine_Semantics_s.machine_eval_code", "Vale.X64.Machine_s.Ins", "Vale.X64.Bytes_Code_s.instruction_t", "Vale.X64.Bytes_Code_s.ocmp", "Prims.Nil", "FStar.Pervasives.pattern" ]
[]
false
false
true
false
false
let eval_code_eq_ins (i: BS.ins) (f: fuel) (s1 s2: machine_state) : Lemma (requires state_eq_S true s1 s2) (ensures state_eq_opt true (BS.machine_eval_code (Ins i) f s1) (BS.machine_eval_code (Ins i) f s2)) =
match i with | Instr _ _ _ -> eval_code_eq_instr i f s1 s2 | Dealloc _ -> eval_code_eq_dealloc i f s1 s2 | Alloc _ -> eval_code_eq_alloc i f s1 s2 | Push _ _ -> eval_code_eq_push i f s1 s2 | Pop _ _ -> eval_code_eq_pop i f s1 s2
false
Vale.X64.Lemmas.fst
Vale.X64.Lemmas.eval_codes_eq_f
val eval_codes_eq_f (cs: codes) (f: fuel) (s1 s2: machine_state) : Lemma (requires state_eq_S false s1 s2) (ensures state_eq_opt false (BS.machine_eval_codes cs f s1) (BS.machine_eval_codes cs f s2)) [SMTPat (BS.machine_eval_codes cs f s1); SMTPat (BS.machine_eval_codes cs f s2)]
val eval_codes_eq_f (cs: codes) (f: fuel) (s1 s2: machine_state) : Lemma (requires state_eq_S false s1 s2) (ensures state_eq_opt false (BS.machine_eval_codes cs f s1) (BS.machine_eval_codes cs f s2)) [SMTPat (BS.machine_eval_codes cs f s1); SMTPat (BS.machine_eval_codes cs f s2)]
let eval_codes_eq_f (cs:codes) (f:fuel) (s1 s2:machine_state) : Lemma (requires state_eq_S false s1 s2) (ensures state_eq_opt false (BS.machine_eval_codes cs f s1) (BS.machine_eval_codes cs f s2)) [SMTPat (BS.machine_eval_codes cs f s1); SMTPat (BS.machine_eval_codes cs f s2)] = eval_codes_eq_core false cs f s1; eval_codes_eq_core false cs f s2
{ "file_name": "vale/code/arch/x64/Vale.X64.Lemmas.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 68, "end_line": 265, "start_col": 0, "start_line": 260 }
module Vale.X64.Lemmas open FStar.Mul open Vale.X64.Machine_s open Vale.X64.State open Vale.X64.StateLemmas open Vale.X64.Instruction_s open Vale.X64.Bytes_Code_s module BS = Vale.X64.Machine_Semantics_s module ME = Vale.X64.Memory #reset-options "--initial_fuel 1 --max_fuel 1 --z3rlimit 100" #restart-solver let rec lemma_eq_instr_apply_eval_args (outs:list instr_out) (args:list instr_operand) (f:instr_args_t outs args) (oprs:instr_operands_t_args args) (s1 s2:machine_state) : Lemma (requires state_eq_S true s1 s2) (ensures BS.instr_apply_eval_args outs args f oprs s1 == BS.instr_apply_eval_args outs args f oprs s2) = let open BS in lemma_heap_ignore_ghost_machine s1.BS.ms_heap s2.BS.ms_heap; match args with | [] -> () | i::args -> ( let (v, oprs) : option (instr_val_t i) & instr_operands_t_args args = match i with | IOpEx i -> let oprs = coerce oprs in (instr_eval_operand_explicit i (fst oprs) s1, snd oprs) | IOpIm i -> (instr_eval_operand_implicit i s1, coerce oprs) in let f:arrow (instr_val_t i) (instr_args_t outs args) = coerce f in match v with | None -> () | Some v -> lemma_eq_instr_apply_eval_args outs args (f v) oprs s1 s2 ) #restart-solver let rec lemma_eq_instr_apply_eval_inouts (outs inouts:list instr_out) (args:list instr_operand) (f:instr_inouts_t outs inouts args) (oprs:instr_operands_t inouts args) (s1 s2:machine_state) : Lemma (requires state_eq_S true s1 s2) (ensures BS.instr_apply_eval_inouts outs inouts args f oprs s1 == BS.instr_apply_eval_inouts outs inouts args f oprs s2) = let open BS in lemma_heap_ignore_ghost_machine s1.BS.ms_heap s2.BS.ms_heap; match inouts with | [] -> lemma_eq_instr_apply_eval_args outs args f oprs s1 s2 | (Out, i)::inouts -> let oprs = match i with | IOpEx i -> snd #(instr_operand_t i) (coerce oprs) | IOpIm i -> coerce oprs in lemma_eq_instr_apply_eval_inouts outs inouts args (coerce f) oprs s1 s2 | (InOut, i)::inouts -> ( let (v, oprs) : option (instr_val_t i) & instr_operands_t inouts args = match i with | IOpEx i -> let oprs = coerce oprs in (instr_eval_operand_explicit i (fst oprs) s1, snd oprs) | IOpIm i -> (instr_eval_operand_implicit i s1, coerce oprs) in let f:arrow (instr_val_t i) (instr_inouts_t outs inouts args) = coerce f in match v with | None -> () | Some v -> lemma_eq_instr_apply_eval_inouts outs inouts args (f v) oprs s1 s2 ) #restart-solver #push-options "--z3rlimit_factor 2" let rec lemma_eq_instr_write_outputs (outs:list instr_out) (args:list instr_operand) (vs:instr_ret_t outs) (oprs:instr_operands_t outs args) (s1_orig s1 s2_orig s2:machine_state) : Lemma (requires state_eq_S true s1_orig s2_orig /\ state_eq_S true s1 s2) (ensures state_eq_S true (BS.instr_write_outputs outs args vs oprs s1_orig s1) (BS.instr_write_outputs outs args vs oprs s2_orig s2)) = let open BS in use_machine_state_equal (); lemma_heap_ignore_ghost_machine s1.BS.ms_heap s2.BS.ms_heap; lemma_heap_ignore_ghost_machine s1_orig.BS.ms_heap s2_orig.BS.ms_heap; allow_inversion tmaddr; match outs with | [] -> () | (_, i)::outs -> ( let ((v:instr_val_t i), (vs:instr_ret_t outs)) = match outs with | [] -> (vs, ()) | _::_ -> let vs = coerce vs in (fst vs, snd vs) in match i with | IOpEx i -> let oprs = coerce oprs in let s1 = instr_write_output_explicit i v (fst oprs) s1_orig s1 in let s2 = instr_write_output_explicit i v (fst oprs) s2_orig s2 in lemma_eq_instr_write_outputs outs args vs (snd oprs) s1_orig s1 s2_orig s2 | IOpIm i -> let s1 = instr_write_output_implicit i v s1_orig s1 in let s2 = instr_write_output_implicit i v s2_orig s2 in allow_inversion operand64; allow_inversion operand128; lemma_eq_instr_write_outputs outs args vs (coerce oprs) s1_orig s1 s2_orig s2 ) #pop-options #restart-solver let eval_ins_eq_instr (inst:BS.ins) (s1 s2:machine_state) : Lemma (requires Instr? inst /\ state_eq_S true s1 s2) (ensures state_eq_S true (BS.machine_eval_ins inst s1) (BS.machine_eval_ins inst s2)) = let open BS in let Instr it oprs ann = inst in let InstrTypeRecord #outs #args #havoc_flags' i = it in lemma_eq_instr_apply_eval_inouts outs outs args (instr_eval i) oprs s1 s2; let vs = instr_apply_eval outs args (instr_eval i) oprs s1 in let hav s = match havoc_flags' with | HavocFlags -> {s with ms_flags = havoc_flags} | PreserveFlags -> s in let s1' = hav s1 in let s2' = hav s2 in match vs with | None -> () | Some vs -> lemma_eq_instr_write_outputs outs args vs oprs s1 s1' s2 s2' let eval_code_eq_instr (inst:BS.ins) (f:fuel) (s1 s2:machine_state) : Lemma (requires Instr? inst /\ state_eq_S true s1 s2) (ensures state_eq_opt true (BS.machine_eval_code (Ins inst) f s1) (BS.machine_eval_code (Ins inst) f s2)) = reveal_opaque (`%BS.machine_eval_code_ins) BS.machine_eval_code_ins; eval_ins_eq_instr inst ({s1 with BS.ms_trace = []}) ({s2 with BS.ms_trace = []}) let eval_code_eq_dealloc (inst:BS.ins) (f:fuel) (s1 s2:machine_state) : Lemma (requires Dealloc? inst /\ state_eq_S true s1 s2) (ensures state_eq_opt true (BS.machine_eval_code (Ins inst) f s1) (BS.machine_eval_code (Ins inst) f s2)) = reveal_opaque (`%BS.machine_eval_code_ins) BS.machine_eval_code_ins; use_machine_state_equal (); lemma_heap_ignore_ghost_machine s1.BS.ms_heap s2.BS.ms_heap; allow_inversion tmaddr let eval_code_eq_alloc (inst:BS.ins) (f:fuel) (s1 s2:machine_state) : Lemma (requires Alloc? inst /\ state_eq_S true s1 s2) (ensures state_eq_opt true (BS.machine_eval_code (Ins inst) f s1) (BS.machine_eval_code (Ins inst) f s2)) = reveal_opaque (`%BS.machine_eval_code_ins) BS.machine_eval_code_ins; use_machine_state_equal (); lemma_heap_ignore_ghost_machine s1.BS.ms_heap s2.BS.ms_heap; allow_inversion tmaddr let eval_code_eq_push (inst:BS.ins) (f:fuel) (s1 s2:machine_state) : Lemma (requires Push? inst /\ state_eq_S true s1 s2) (ensures state_eq_opt true (BS.machine_eval_code (Ins inst) f s1) (BS.machine_eval_code (Ins inst) f s2)) = reveal_opaque (`%BS.machine_eval_code_ins) BS.machine_eval_code_ins; use_machine_state_equal (); lemma_heap_ignore_ghost_machine s1.BS.ms_heap s2.BS.ms_heap; allow_inversion tmaddr let eval_code_eq_pop (inst:BS.ins) (f:fuel) (s1 s2:machine_state) : Lemma (requires Pop? inst /\ state_eq_S true s1 s2) (ensures state_eq_opt true (BS.machine_eval_code (Ins inst) f s1) (BS.machine_eval_code (Ins inst) f s2)) = reveal_opaque (`%BS.machine_eval_code_ins) BS.machine_eval_code_ins; use_machine_state_equal (); lemma_heap_ignore_ghost_machine s1.BS.ms_heap s2.BS.ms_heap; allow_inversion tmaddr let eval_code_eq_ins (i:BS.ins) (f:fuel) (s1 s2:machine_state) : Lemma (requires state_eq_S true s1 s2) (ensures state_eq_opt true (BS.machine_eval_code (Ins i) f s1) (BS.machine_eval_code (Ins i) f s2)) = match i with | Instr _ _ _ -> eval_code_eq_instr i f s1 s2 | Dealloc _ -> eval_code_eq_dealloc i f s1 s2 | Alloc _ -> eval_code_eq_alloc i f s1 s2 | Push _ _ -> eval_code_eq_push i f s1 s2 | Pop _ _ -> eval_code_eq_pop i f s1 s2 #reset-options "--fuel 2 --z3rlimit 30" let eval_ocmp_eq_core (g:bool) (cond:ocmp) (s:machine_state) : Lemma (ensures ( let (s1, b1) = BS.machine_eval_ocmp s cond in let (s2, b2) = BS.machine_eval_ocmp (core_state g s) cond in state_eq_S g s1 s2 /\ b1 == b2 )) = reveal_opaque (`%BS.valid_ocmp_opaque) BS.valid_ocmp_opaque; reveal_opaque (`%BS.eval_ocmp_opaque) BS.eval_ocmp_opaque; () #restart-solver let rec eval_code_eq_core (g:bool) (c:code) (f:fuel) (s:machine_state) : Lemma (ensures state_eq_opt g (BS.machine_eval_code c f s) (BS.machine_eval_code c f (core_state g s))) (decreases %[f; c]) = match c with | Ins i -> reveal_opaque (`%BS.machine_eval_code_ins) BS.machine_eval_code_ins; if g then eval_code_eq_ins i f s (core_state g s) | Block cs -> eval_codes_eq_core g cs f s | IfElse cond ct cf -> eval_ocmp_eq_core g cond s; let (s', _) = BS.machine_eval_ocmp s cond in let (t', _) = BS.machine_eval_ocmp (core_state g s) cond in eval_code_eq_core g ct f s'; eval_code_eq_core g ct f t'; eval_code_eq_core g cf f s'; eval_code_eq_core g cf f t'; () | While cond body -> eval_while_eq_core g cond body f s and eval_codes_eq_core (g:bool) (cs:codes) (f:fuel) (s:machine_state) : Lemma (ensures state_eq_opt g (BS.machine_eval_codes cs f s) (BS.machine_eval_codes cs f (core_state g s))) (decreases %[f; cs]) = match cs with | [] -> () | c'::cs' -> ( eval_code_eq_core g c' f s; match (machine_eval_code c' f s, machine_eval_code c' f (core_state g s)) with | (None, None) -> () | (Some s', Some t') -> eval_codes_eq_core g cs' f s'; eval_codes_eq_core g cs' f t' ) and eval_while_eq_core (g:bool) (cond:ocmp) (body:code) (f:fuel) (s:machine_state) : Lemma (ensures state_eq_opt g (BS.machine_eval_while cond body f s) (BS.machine_eval_while cond body f (core_state g s))) (decreases %[f; body]) = if f > 0 then ( eval_ocmp_eq_core g cond s; let (s1, _) = BS.machine_eval_ocmp s cond in let (t1, _) = BS.machine_eval_ocmp (core_state g s) cond in eval_code_eq_core g body (f - 1) s1; eval_code_eq_core g body (f - 1) t1; match (BS.machine_eval_code body (f - 1) s1, BS.machine_eval_code body (f - 1) t1) with | (None, None) -> () | (Some s2, Some t2) -> eval_while_eq_core g cond body (f - 1) s2; eval_while_eq_core g cond body (f - 1) t2; () ) let eval_code_eq_f (c:code) (f:fuel) (s1 s2:machine_state) : Lemma (requires state_eq_S false s1 s2) (ensures state_eq_opt false (BS.machine_eval_code c f s1) (BS.machine_eval_code c f s2)) [SMTPat (BS.machine_eval_code c f s1); SMTPat (BS.machine_eval_code c f s2)] = eval_code_eq_core false c f s1; eval_code_eq_core false c f s2
{ "checked_file": "/", "dependencies": [ "Vale.X64.StateLemmas.fsti.checked", "Vale.X64.State.fsti.checked", "Vale.X64.Memory.fsti.checked", "Vale.X64.Machine_Semantics_s.fst.checked", "Vale.X64.Machine_s.fst.checked", "Vale.X64.Instruction_s.fsti.checked", "Vale.X64.Flags.fsti.checked", "Vale.X64.Bytes_Code_s.fst.checked", "prims.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.FunctionalExtensionality.fsti.checked" ], "interface_file": true, "source_file": "Vale.X64.Lemmas.fst" }
[ { "abbrev": true, "full_module": "Vale.X64.Memory", "short_module": "ME" }, { "abbrev": true, "full_module": "Vale.X64.Machine_Semantics_s", "short_module": "BS" }, { "abbrev": false, "full_module": "Vale.X64.Bytes_Code_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Instruction_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.StateLemmas", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.State", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Machine_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": true, "full_module": "Vale.Lib.Map16", "short_module": "Map16" }, { "abbrev": true, "full_module": "Vale.X64.Machine_Semantics_s", "short_module": "BS" }, { "abbrev": false, "full_module": "Vale.X64.Bytes_Code_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.StateLemmas", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.State", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Machine_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.HeapLemmas", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.HeapImpl", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.Heap", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 0, "max_fuel": 2, "max_ifuel": 1, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": true, "smtencoding_l_arith_repr": "native", "smtencoding_nl_arith_repr": "wrapped", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [ "smt.arith.nl=false", "smt.QI.EAGER_THRESHOLD=100", "smt.CASE_SPLIT=3" ], "z3refresh": false, "z3rlimit": 30, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
cs: Vale.X64.Lemmas.codes -> f: Vale.X64.Lemmas.fuel -> s1: Vale.X64.StateLemmas.machine_state -> s2: Vale.X64.StateLemmas.machine_state -> FStar.Pervasives.Lemma (requires Vale.X64.Lemmas.state_eq_S false s1 s2) (ensures Vale.X64.Lemmas.state_eq_opt false (Vale.X64.Machine_Semantics_s.machine_eval_codes cs f s1) (Vale.X64.Machine_Semantics_s.machine_eval_codes cs f s2)) [ SMTPat (Vale.X64.Machine_Semantics_s.machine_eval_codes cs f s1); SMTPat (Vale.X64.Machine_Semantics_s.machine_eval_codes cs f s2) ]
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "Vale.X64.Lemmas.codes", "Vale.X64.Lemmas.fuel", "Vale.X64.StateLemmas.machine_state", "Vale.X64.Lemmas.eval_codes_eq_core", "Prims.unit", "Vale.X64.Lemmas.state_eq_S", "Prims.squash", "Vale.X64.Lemmas.state_eq_opt", "Vale.X64.Machine_Semantics_s.machine_eval_codes", "Prims.Cons", "FStar.Pervasives.pattern", "FStar.Pervasives.smt_pat", "FStar.Pervasives.Native.option", "Vale.X64.Machine_Semantics_s.machine_state", "Prims.Nil" ]
[]
true
false
true
false
false
let eval_codes_eq_f (cs: codes) (f: fuel) (s1 s2: machine_state) : Lemma (requires state_eq_S false s1 s2) (ensures state_eq_opt false (BS.machine_eval_codes cs f s1) (BS.machine_eval_codes cs f s2)) [SMTPat (BS.machine_eval_codes cs f s1); SMTPat (BS.machine_eval_codes cs f s2)] =
eval_codes_eq_core false cs f s1; eval_codes_eq_core false cs f s2
false
Vale.X64.Lemmas.fst
Vale.X64.Lemmas.compute_merge_total
val compute_merge_total (f0:fuel) (fM:fuel) : fuel
val compute_merge_total (f0:fuel) (fM:fuel) : fuel
let compute_merge_total (f0:fuel) (fM:fuel) = if f0 > fM then f0 else fM
{ "file_name": "vale/code/arch/x64/Vale.X64.Lemmas.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 28, "end_line": 348, "start_col": 0, "start_line": 347 }
module Vale.X64.Lemmas open FStar.Mul open Vale.X64.Machine_s open Vale.X64.State open Vale.X64.StateLemmas open Vale.X64.Instruction_s open Vale.X64.Bytes_Code_s module BS = Vale.X64.Machine_Semantics_s module ME = Vale.X64.Memory #reset-options "--initial_fuel 1 --max_fuel 1 --z3rlimit 100" #restart-solver let rec lemma_eq_instr_apply_eval_args (outs:list instr_out) (args:list instr_operand) (f:instr_args_t outs args) (oprs:instr_operands_t_args args) (s1 s2:machine_state) : Lemma (requires state_eq_S true s1 s2) (ensures BS.instr_apply_eval_args outs args f oprs s1 == BS.instr_apply_eval_args outs args f oprs s2) = let open BS in lemma_heap_ignore_ghost_machine s1.BS.ms_heap s2.BS.ms_heap; match args with | [] -> () | i::args -> ( let (v, oprs) : option (instr_val_t i) & instr_operands_t_args args = match i with | IOpEx i -> let oprs = coerce oprs in (instr_eval_operand_explicit i (fst oprs) s1, snd oprs) | IOpIm i -> (instr_eval_operand_implicit i s1, coerce oprs) in let f:arrow (instr_val_t i) (instr_args_t outs args) = coerce f in match v with | None -> () | Some v -> lemma_eq_instr_apply_eval_args outs args (f v) oprs s1 s2 ) #restart-solver let rec lemma_eq_instr_apply_eval_inouts (outs inouts:list instr_out) (args:list instr_operand) (f:instr_inouts_t outs inouts args) (oprs:instr_operands_t inouts args) (s1 s2:machine_state) : Lemma (requires state_eq_S true s1 s2) (ensures BS.instr_apply_eval_inouts outs inouts args f oprs s1 == BS.instr_apply_eval_inouts outs inouts args f oprs s2) = let open BS in lemma_heap_ignore_ghost_machine s1.BS.ms_heap s2.BS.ms_heap; match inouts with | [] -> lemma_eq_instr_apply_eval_args outs args f oprs s1 s2 | (Out, i)::inouts -> let oprs = match i with | IOpEx i -> snd #(instr_operand_t i) (coerce oprs) | IOpIm i -> coerce oprs in lemma_eq_instr_apply_eval_inouts outs inouts args (coerce f) oprs s1 s2 | (InOut, i)::inouts -> ( let (v, oprs) : option (instr_val_t i) & instr_operands_t inouts args = match i with | IOpEx i -> let oprs = coerce oprs in (instr_eval_operand_explicit i (fst oprs) s1, snd oprs) | IOpIm i -> (instr_eval_operand_implicit i s1, coerce oprs) in let f:arrow (instr_val_t i) (instr_inouts_t outs inouts args) = coerce f in match v with | None -> () | Some v -> lemma_eq_instr_apply_eval_inouts outs inouts args (f v) oprs s1 s2 ) #restart-solver #push-options "--z3rlimit_factor 2" let rec lemma_eq_instr_write_outputs (outs:list instr_out) (args:list instr_operand) (vs:instr_ret_t outs) (oprs:instr_operands_t outs args) (s1_orig s1 s2_orig s2:machine_state) : Lemma (requires state_eq_S true s1_orig s2_orig /\ state_eq_S true s1 s2) (ensures state_eq_S true (BS.instr_write_outputs outs args vs oprs s1_orig s1) (BS.instr_write_outputs outs args vs oprs s2_orig s2)) = let open BS in use_machine_state_equal (); lemma_heap_ignore_ghost_machine s1.BS.ms_heap s2.BS.ms_heap; lemma_heap_ignore_ghost_machine s1_orig.BS.ms_heap s2_orig.BS.ms_heap; allow_inversion tmaddr; match outs with | [] -> () | (_, i)::outs -> ( let ((v:instr_val_t i), (vs:instr_ret_t outs)) = match outs with | [] -> (vs, ()) | _::_ -> let vs = coerce vs in (fst vs, snd vs) in match i with | IOpEx i -> let oprs = coerce oprs in let s1 = instr_write_output_explicit i v (fst oprs) s1_orig s1 in let s2 = instr_write_output_explicit i v (fst oprs) s2_orig s2 in lemma_eq_instr_write_outputs outs args vs (snd oprs) s1_orig s1 s2_orig s2 | IOpIm i -> let s1 = instr_write_output_implicit i v s1_orig s1 in let s2 = instr_write_output_implicit i v s2_orig s2 in allow_inversion operand64; allow_inversion operand128; lemma_eq_instr_write_outputs outs args vs (coerce oprs) s1_orig s1 s2_orig s2 ) #pop-options #restart-solver let eval_ins_eq_instr (inst:BS.ins) (s1 s2:machine_state) : Lemma (requires Instr? inst /\ state_eq_S true s1 s2) (ensures state_eq_S true (BS.machine_eval_ins inst s1) (BS.machine_eval_ins inst s2)) = let open BS in let Instr it oprs ann = inst in let InstrTypeRecord #outs #args #havoc_flags' i = it in lemma_eq_instr_apply_eval_inouts outs outs args (instr_eval i) oprs s1 s2; let vs = instr_apply_eval outs args (instr_eval i) oprs s1 in let hav s = match havoc_flags' with | HavocFlags -> {s with ms_flags = havoc_flags} | PreserveFlags -> s in let s1' = hav s1 in let s2' = hav s2 in match vs with | None -> () | Some vs -> lemma_eq_instr_write_outputs outs args vs oprs s1 s1' s2 s2' let eval_code_eq_instr (inst:BS.ins) (f:fuel) (s1 s2:machine_state) : Lemma (requires Instr? inst /\ state_eq_S true s1 s2) (ensures state_eq_opt true (BS.machine_eval_code (Ins inst) f s1) (BS.machine_eval_code (Ins inst) f s2)) = reveal_opaque (`%BS.machine_eval_code_ins) BS.machine_eval_code_ins; eval_ins_eq_instr inst ({s1 with BS.ms_trace = []}) ({s2 with BS.ms_trace = []}) let eval_code_eq_dealloc (inst:BS.ins) (f:fuel) (s1 s2:machine_state) : Lemma (requires Dealloc? inst /\ state_eq_S true s1 s2) (ensures state_eq_opt true (BS.machine_eval_code (Ins inst) f s1) (BS.machine_eval_code (Ins inst) f s2)) = reveal_opaque (`%BS.machine_eval_code_ins) BS.machine_eval_code_ins; use_machine_state_equal (); lemma_heap_ignore_ghost_machine s1.BS.ms_heap s2.BS.ms_heap; allow_inversion tmaddr let eval_code_eq_alloc (inst:BS.ins) (f:fuel) (s1 s2:machine_state) : Lemma (requires Alloc? inst /\ state_eq_S true s1 s2) (ensures state_eq_opt true (BS.machine_eval_code (Ins inst) f s1) (BS.machine_eval_code (Ins inst) f s2)) = reveal_opaque (`%BS.machine_eval_code_ins) BS.machine_eval_code_ins; use_machine_state_equal (); lemma_heap_ignore_ghost_machine s1.BS.ms_heap s2.BS.ms_heap; allow_inversion tmaddr let eval_code_eq_push (inst:BS.ins) (f:fuel) (s1 s2:machine_state) : Lemma (requires Push? inst /\ state_eq_S true s1 s2) (ensures state_eq_opt true (BS.machine_eval_code (Ins inst) f s1) (BS.machine_eval_code (Ins inst) f s2)) = reveal_opaque (`%BS.machine_eval_code_ins) BS.machine_eval_code_ins; use_machine_state_equal (); lemma_heap_ignore_ghost_machine s1.BS.ms_heap s2.BS.ms_heap; allow_inversion tmaddr let eval_code_eq_pop (inst:BS.ins) (f:fuel) (s1 s2:machine_state) : Lemma (requires Pop? inst /\ state_eq_S true s1 s2) (ensures state_eq_opt true (BS.machine_eval_code (Ins inst) f s1) (BS.machine_eval_code (Ins inst) f s2)) = reveal_opaque (`%BS.machine_eval_code_ins) BS.machine_eval_code_ins; use_machine_state_equal (); lemma_heap_ignore_ghost_machine s1.BS.ms_heap s2.BS.ms_heap; allow_inversion tmaddr let eval_code_eq_ins (i:BS.ins) (f:fuel) (s1 s2:machine_state) : Lemma (requires state_eq_S true s1 s2) (ensures state_eq_opt true (BS.machine_eval_code (Ins i) f s1) (BS.machine_eval_code (Ins i) f s2)) = match i with | Instr _ _ _ -> eval_code_eq_instr i f s1 s2 | Dealloc _ -> eval_code_eq_dealloc i f s1 s2 | Alloc _ -> eval_code_eq_alloc i f s1 s2 | Push _ _ -> eval_code_eq_push i f s1 s2 | Pop _ _ -> eval_code_eq_pop i f s1 s2 #reset-options "--fuel 2 --z3rlimit 30" let eval_ocmp_eq_core (g:bool) (cond:ocmp) (s:machine_state) : Lemma (ensures ( let (s1, b1) = BS.machine_eval_ocmp s cond in let (s2, b2) = BS.machine_eval_ocmp (core_state g s) cond in state_eq_S g s1 s2 /\ b1 == b2 )) = reveal_opaque (`%BS.valid_ocmp_opaque) BS.valid_ocmp_opaque; reveal_opaque (`%BS.eval_ocmp_opaque) BS.eval_ocmp_opaque; () #restart-solver let rec eval_code_eq_core (g:bool) (c:code) (f:fuel) (s:machine_state) : Lemma (ensures state_eq_opt g (BS.machine_eval_code c f s) (BS.machine_eval_code c f (core_state g s))) (decreases %[f; c]) = match c with | Ins i -> reveal_opaque (`%BS.machine_eval_code_ins) BS.machine_eval_code_ins; if g then eval_code_eq_ins i f s (core_state g s) | Block cs -> eval_codes_eq_core g cs f s | IfElse cond ct cf -> eval_ocmp_eq_core g cond s; let (s', _) = BS.machine_eval_ocmp s cond in let (t', _) = BS.machine_eval_ocmp (core_state g s) cond in eval_code_eq_core g ct f s'; eval_code_eq_core g ct f t'; eval_code_eq_core g cf f s'; eval_code_eq_core g cf f t'; () | While cond body -> eval_while_eq_core g cond body f s and eval_codes_eq_core (g:bool) (cs:codes) (f:fuel) (s:machine_state) : Lemma (ensures state_eq_opt g (BS.machine_eval_codes cs f s) (BS.machine_eval_codes cs f (core_state g s))) (decreases %[f; cs]) = match cs with | [] -> () | c'::cs' -> ( eval_code_eq_core g c' f s; match (machine_eval_code c' f s, machine_eval_code c' f (core_state g s)) with | (None, None) -> () | (Some s', Some t') -> eval_codes_eq_core g cs' f s'; eval_codes_eq_core g cs' f t' ) and eval_while_eq_core (g:bool) (cond:ocmp) (body:code) (f:fuel) (s:machine_state) : Lemma (ensures state_eq_opt g (BS.machine_eval_while cond body f s) (BS.machine_eval_while cond body f (core_state g s))) (decreases %[f; body]) = if f > 0 then ( eval_ocmp_eq_core g cond s; let (s1, _) = BS.machine_eval_ocmp s cond in let (t1, _) = BS.machine_eval_ocmp (core_state g s) cond in eval_code_eq_core g body (f - 1) s1; eval_code_eq_core g body (f - 1) t1; match (BS.machine_eval_code body (f - 1) s1, BS.machine_eval_code body (f - 1) t1) with | (None, None) -> () | (Some s2, Some t2) -> eval_while_eq_core g cond body (f - 1) s2; eval_while_eq_core g cond body (f - 1) t2; () ) let eval_code_eq_f (c:code) (f:fuel) (s1 s2:machine_state) : Lemma (requires state_eq_S false s1 s2) (ensures state_eq_opt false (BS.machine_eval_code c f s1) (BS.machine_eval_code c f s2)) [SMTPat (BS.machine_eval_code c f s1); SMTPat (BS.machine_eval_code c f s2)] = eval_code_eq_core false c f s1; eval_code_eq_core false c f s2 let eval_codes_eq_f (cs:codes) (f:fuel) (s1 s2:machine_state) : Lemma (requires state_eq_S false s1 s2) (ensures state_eq_opt false (BS.machine_eval_codes cs f s1) (BS.machine_eval_codes cs f s2)) [SMTPat (BS.machine_eval_codes cs f s1); SMTPat (BS.machine_eval_codes cs f s2)] = eval_codes_eq_core false cs f s1; eval_codes_eq_core false cs f s2 let eval_while_eq_f (cond:ocmp) (body:code) (f:fuel) (s1 s2:machine_state) : Lemma (requires state_eq_S false s1 s2) (ensures state_eq_opt false (BS.machine_eval_while cond body f s1) (BS.machine_eval_while cond body f s2)) [SMTPat (BS.machine_eval_while cond body f s1); SMTPat (BS.machine_eval_while cond body f s2)] = eval_while_eq_core false cond body f s1; eval_while_eq_core false cond body f s2 let eval_code_eq_t (c:code) (f:fuel) (s1 s2:machine_state) : Lemma (requires state_eq_S true s1 s2) (ensures state_eq_opt true (BS.machine_eval_code c f s1) (BS.machine_eval_code c f s2)) [SMTPat (BS.machine_eval_code c f s1); SMTPat (BS.machine_eval_code c f s2)] = eval_code_eq_core true c f s1; eval_code_eq_core true c f s2 let eval_codes_eq_t (cs:codes) (f:fuel) (s1 s2:machine_state) : Lemma (requires state_eq_S true s1 s2) (ensures state_eq_opt true (BS.machine_eval_codes cs f s1) (BS.machine_eval_codes cs f s2)) [SMTPat (BS.machine_eval_codes cs f s1); SMTPat (BS.machine_eval_codes cs f s2)] = eval_codes_eq_core true cs f s1; eval_codes_eq_core true cs f s2 let eval_while_eq_t (cond:ocmp) (body:code) (f:fuel) (s1 s2:machine_state) : Lemma (requires state_eq_S true s1 s2) (ensures state_eq_opt true (BS.machine_eval_while cond body f s1) (BS.machine_eval_while cond body f s2)) [SMTPat (BS.machine_eval_while cond body f s1); SMTPat (BS.machine_eval_while cond body f s2)] = eval_while_eq_core true cond body f s1; eval_while_eq_core true cond body f s2 let eval_code_ts (g:bool) (c:code) (s0:machine_state) (f0:fuel) (s1:machine_state) : Type0 = state_eq_opt g (BS.machine_eval_code c f0 s0) (Some s1) let rec increase_fuel (g:bool) (c:code) (s0:machine_state) (f0:fuel) (sN:machine_state) (fN:fuel) : Lemma (requires eval_code_ts g c s0 f0 sN /\ f0 <= fN) (ensures eval_code_ts g c s0 fN sN) (decreases %[f0; c]) = match c with | Ins ins -> () | Block l -> increase_fuels g l s0 f0 sN fN | IfElse cond t f -> let (s0, b0) = BS.machine_eval_ocmp s0 cond in if b0 then increase_fuel g t s0 f0 sN fN else increase_fuel g f s0 f0 sN fN | While cond c -> let (s1, b0) = BS.machine_eval_ocmp s0 cond in if b0 then ( match BS.machine_eval_code c (f0 - 1) s1 with | None -> () | Some s2 -> increase_fuel g c s1 (f0 - 1) s2 (fN - 1); if s2.BS.ms_ok then increase_fuel g (While cond c) s2 (f0 - 1) sN (fN - 1) else () ) and increase_fuels (g:bool) (c:codes) (s0:machine_state) (f0:fuel) (sN:machine_state) (fN:fuel) : Lemma (requires eval_code_ts g (Block c) s0 f0 sN /\ f0 <= fN) (ensures eval_code_ts g (Block c) s0 fN sN) (decreases %[f0; c]) = match c with | [] -> () | h::t -> ( let Some s1 = BS.machine_eval_code h f0 s0 in increase_fuel g h s0 f0 s1 fN; increase_fuels g t s1 f0 sN fN ) let lemma_cmp_eq s o1 o2 = reveal_opaque (`%BS.eval_ocmp_opaque) BS.eval_ocmp_opaque let lemma_cmp_ne s o1 o2 = reveal_opaque (`%BS.eval_ocmp_opaque) BS.eval_ocmp_opaque let lemma_cmp_le s o1 o2 = reveal_opaque (`%BS.eval_ocmp_opaque) BS.eval_ocmp_opaque let lemma_cmp_ge s o1 o2 = reveal_opaque (`%BS.eval_ocmp_opaque) BS.eval_ocmp_opaque let lemma_cmp_lt s o1 o2 = reveal_opaque (`%BS.eval_ocmp_opaque) BS.eval_ocmp_opaque let lemma_cmp_gt s o1 o2 = reveal_opaque (`%BS.eval_ocmp_opaque) BS.eval_ocmp_opaque let lemma_valid_cmp_eq s o1 o2 = () let lemma_valid_cmp_ne s o1 o2 = () let lemma_valid_cmp_le s o1 o2 = () let lemma_valid_cmp_ge s o1 o2 = () let lemma_valid_cmp_lt s o1 o2 = () let lemma_valid_cmp_gt s o1 o2 = ()
{ "checked_file": "/", "dependencies": [ "Vale.X64.StateLemmas.fsti.checked", "Vale.X64.State.fsti.checked", "Vale.X64.Memory.fsti.checked", "Vale.X64.Machine_Semantics_s.fst.checked", "Vale.X64.Machine_s.fst.checked", "Vale.X64.Instruction_s.fsti.checked", "Vale.X64.Flags.fsti.checked", "Vale.X64.Bytes_Code_s.fst.checked", "prims.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.FunctionalExtensionality.fsti.checked" ], "interface_file": true, "source_file": "Vale.X64.Lemmas.fst" }
[ { "abbrev": true, "full_module": "Vale.X64.Memory", "short_module": "ME" }, { "abbrev": true, "full_module": "Vale.X64.Machine_Semantics_s", "short_module": "BS" }, { "abbrev": false, "full_module": "Vale.X64.Bytes_Code_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Instruction_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.StateLemmas", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.State", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Machine_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": true, "full_module": "Vale.Lib.Map16", "short_module": "Map16" }, { "abbrev": true, "full_module": "Vale.X64.Machine_Semantics_s", "short_module": "BS" }, { "abbrev": false, "full_module": "Vale.X64.Bytes_Code_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.StateLemmas", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.State", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Machine_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.HeapLemmas", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.HeapImpl", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.Heap", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 0, "max_fuel": 2, "max_ifuel": 1, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": true, "smtencoding_l_arith_repr": "native", "smtencoding_nl_arith_repr": "wrapped", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [ "smt.arith.nl=false", "smt.QI.EAGER_THRESHOLD=100", "smt.CASE_SPLIT=3" ], "z3refresh": false, "z3rlimit": 30, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
f0: Vale.X64.Lemmas.fuel -> fM: Vale.X64.Lemmas.fuel -> Vale.X64.Lemmas.fuel
Prims.Tot
[ "total" ]
[]
[ "Vale.X64.Lemmas.fuel", "Prims.op_GreaterThan", "Prims.bool" ]
[]
false
false
false
true
false
let compute_merge_total (f0 fM: fuel) =
if f0 > fM then f0 else fM
false
Vale.X64.Lemmas.fst
Vale.X64.Lemmas.eval_while_eq_f
val eval_while_eq_f (cond: ocmp) (body: code) (f: fuel) (s1 s2: machine_state) : Lemma (requires state_eq_S false s1 s2) (ensures state_eq_opt false (BS.machine_eval_while cond body f s1) (BS.machine_eval_while cond body f s2)) [SMTPat (BS.machine_eval_while cond body f s1); SMTPat (BS.machine_eval_while cond body f s2)]
val eval_while_eq_f (cond: ocmp) (body: code) (f: fuel) (s1 s2: machine_state) : Lemma (requires state_eq_S false s1 s2) (ensures state_eq_opt false (BS.machine_eval_while cond body f s1) (BS.machine_eval_while cond body f s2)) [SMTPat (BS.machine_eval_while cond body f s1); SMTPat (BS.machine_eval_while cond body f s2)]
let eval_while_eq_f (cond:ocmp) (body:code) (f:fuel) (s1 s2:machine_state) : Lemma (requires state_eq_S false s1 s2) (ensures state_eq_opt false (BS.machine_eval_while cond body f s1) (BS.machine_eval_while cond body f s2)) [SMTPat (BS.machine_eval_while cond body f s1); SMTPat (BS.machine_eval_while cond body f s2)] = eval_while_eq_core false cond body f s1; eval_while_eq_core false cond body f s2
{ "file_name": "vale/code/arch/x64/Vale.X64.Lemmas.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 82, "end_line": 272, "start_col": 0, "start_line": 267 }
module Vale.X64.Lemmas open FStar.Mul open Vale.X64.Machine_s open Vale.X64.State open Vale.X64.StateLemmas open Vale.X64.Instruction_s open Vale.X64.Bytes_Code_s module BS = Vale.X64.Machine_Semantics_s module ME = Vale.X64.Memory #reset-options "--initial_fuel 1 --max_fuel 1 --z3rlimit 100" #restart-solver let rec lemma_eq_instr_apply_eval_args (outs:list instr_out) (args:list instr_operand) (f:instr_args_t outs args) (oprs:instr_operands_t_args args) (s1 s2:machine_state) : Lemma (requires state_eq_S true s1 s2) (ensures BS.instr_apply_eval_args outs args f oprs s1 == BS.instr_apply_eval_args outs args f oprs s2) = let open BS in lemma_heap_ignore_ghost_machine s1.BS.ms_heap s2.BS.ms_heap; match args with | [] -> () | i::args -> ( let (v, oprs) : option (instr_val_t i) & instr_operands_t_args args = match i with | IOpEx i -> let oprs = coerce oprs in (instr_eval_operand_explicit i (fst oprs) s1, snd oprs) | IOpIm i -> (instr_eval_operand_implicit i s1, coerce oprs) in let f:arrow (instr_val_t i) (instr_args_t outs args) = coerce f in match v with | None -> () | Some v -> lemma_eq_instr_apply_eval_args outs args (f v) oprs s1 s2 ) #restart-solver let rec lemma_eq_instr_apply_eval_inouts (outs inouts:list instr_out) (args:list instr_operand) (f:instr_inouts_t outs inouts args) (oprs:instr_operands_t inouts args) (s1 s2:machine_state) : Lemma (requires state_eq_S true s1 s2) (ensures BS.instr_apply_eval_inouts outs inouts args f oprs s1 == BS.instr_apply_eval_inouts outs inouts args f oprs s2) = let open BS in lemma_heap_ignore_ghost_machine s1.BS.ms_heap s2.BS.ms_heap; match inouts with | [] -> lemma_eq_instr_apply_eval_args outs args f oprs s1 s2 | (Out, i)::inouts -> let oprs = match i with | IOpEx i -> snd #(instr_operand_t i) (coerce oprs) | IOpIm i -> coerce oprs in lemma_eq_instr_apply_eval_inouts outs inouts args (coerce f) oprs s1 s2 | (InOut, i)::inouts -> ( let (v, oprs) : option (instr_val_t i) & instr_operands_t inouts args = match i with | IOpEx i -> let oprs = coerce oprs in (instr_eval_operand_explicit i (fst oprs) s1, snd oprs) | IOpIm i -> (instr_eval_operand_implicit i s1, coerce oprs) in let f:arrow (instr_val_t i) (instr_inouts_t outs inouts args) = coerce f in match v with | None -> () | Some v -> lemma_eq_instr_apply_eval_inouts outs inouts args (f v) oprs s1 s2 ) #restart-solver #push-options "--z3rlimit_factor 2" let rec lemma_eq_instr_write_outputs (outs:list instr_out) (args:list instr_operand) (vs:instr_ret_t outs) (oprs:instr_operands_t outs args) (s1_orig s1 s2_orig s2:machine_state) : Lemma (requires state_eq_S true s1_orig s2_orig /\ state_eq_S true s1 s2) (ensures state_eq_S true (BS.instr_write_outputs outs args vs oprs s1_orig s1) (BS.instr_write_outputs outs args vs oprs s2_orig s2)) = let open BS in use_machine_state_equal (); lemma_heap_ignore_ghost_machine s1.BS.ms_heap s2.BS.ms_heap; lemma_heap_ignore_ghost_machine s1_orig.BS.ms_heap s2_orig.BS.ms_heap; allow_inversion tmaddr; match outs with | [] -> () | (_, i)::outs -> ( let ((v:instr_val_t i), (vs:instr_ret_t outs)) = match outs with | [] -> (vs, ()) | _::_ -> let vs = coerce vs in (fst vs, snd vs) in match i with | IOpEx i -> let oprs = coerce oprs in let s1 = instr_write_output_explicit i v (fst oprs) s1_orig s1 in let s2 = instr_write_output_explicit i v (fst oprs) s2_orig s2 in lemma_eq_instr_write_outputs outs args vs (snd oprs) s1_orig s1 s2_orig s2 | IOpIm i -> let s1 = instr_write_output_implicit i v s1_orig s1 in let s2 = instr_write_output_implicit i v s2_orig s2 in allow_inversion operand64; allow_inversion operand128; lemma_eq_instr_write_outputs outs args vs (coerce oprs) s1_orig s1 s2_orig s2 ) #pop-options #restart-solver let eval_ins_eq_instr (inst:BS.ins) (s1 s2:machine_state) : Lemma (requires Instr? inst /\ state_eq_S true s1 s2) (ensures state_eq_S true (BS.machine_eval_ins inst s1) (BS.machine_eval_ins inst s2)) = let open BS in let Instr it oprs ann = inst in let InstrTypeRecord #outs #args #havoc_flags' i = it in lemma_eq_instr_apply_eval_inouts outs outs args (instr_eval i) oprs s1 s2; let vs = instr_apply_eval outs args (instr_eval i) oprs s1 in let hav s = match havoc_flags' with | HavocFlags -> {s with ms_flags = havoc_flags} | PreserveFlags -> s in let s1' = hav s1 in let s2' = hav s2 in match vs with | None -> () | Some vs -> lemma_eq_instr_write_outputs outs args vs oprs s1 s1' s2 s2' let eval_code_eq_instr (inst:BS.ins) (f:fuel) (s1 s2:machine_state) : Lemma (requires Instr? inst /\ state_eq_S true s1 s2) (ensures state_eq_opt true (BS.machine_eval_code (Ins inst) f s1) (BS.machine_eval_code (Ins inst) f s2)) = reveal_opaque (`%BS.machine_eval_code_ins) BS.machine_eval_code_ins; eval_ins_eq_instr inst ({s1 with BS.ms_trace = []}) ({s2 with BS.ms_trace = []}) let eval_code_eq_dealloc (inst:BS.ins) (f:fuel) (s1 s2:machine_state) : Lemma (requires Dealloc? inst /\ state_eq_S true s1 s2) (ensures state_eq_opt true (BS.machine_eval_code (Ins inst) f s1) (BS.machine_eval_code (Ins inst) f s2)) = reveal_opaque (`%BS.machine_eval_code_ins) BS.machine_eval_code_ins; use_machine_state_equal (); lemma_heap_ignore_ghost_machine s1.BS.ms_heap s2.BS.ms_heap; allow_inversion tmaddr let eval_code_eq_alloc (inst:BS.ins) (f:fuel) (s1 s2:machine_state) : Lemma (requires Alloc? inst /\ state_eq_S true s1 s2) (ensures state_eq_opt true (BS.machine_eval_code (Ins inst) f s1) (BS.machine_eval_code (Ins inst) f s2)) = reveal_opaque (`%BS.machine_eval_code_ins) BS.machine_eval_code_ins; use_machine_state_equal (); lemma_heap_ignore_ghost_machine s1.BS.ms_heap s2.BS.ms_heap; allow_inversion tmaddr let eval_code_eq_push (inst:BS.ins) (f:fuel) (s1 s2:machine_state) : Lemma (requires Push? inst /\ state_eq_S true s1 s2) (ensures state_eq_opt true (BS.machine_eval_code (Ins inst) f s1) (BS.machine_eval_code (Ins inst) f s2)) = reveal_opaque (`%BS.machine_eval_code_ins) BS.machine_eval_code_ins; use_machine_state_equal (); lemma_heap_ignore_ghost_machine s1.BS.ms_heap s2.BS.ms_heap; allow_inversion tmaddr let eval_code_eq_pop (inst:BS.ins) (f:fuel) (s1 s2:machine_state) : Lemma (requires Pop? inst /\ state_eq_S true s1 s2) (ensures state_eq_opt true (BS.machine_eval_code (Ins inst) f s1) (BS.machine_eval_code (Ins inst) f s2)) = reveal_opaque (`%BS.machine_eval_code_ins) BS.machine_eval_code_ins; use_machine_state_equal (); lemma_heap_ignore_ghost_machine s1.BS.ms_heap s2.BS.ms_heap; allow_inversion tmaddr let eval_code_eq_ins (i:BS.ins) (f:fuel) (s1 s2:machine_state) : Lemma (requires state_eq_S true s1 s2) (ensures state_eq_opt true (BS.machine_eval_code (Ins i) f s1) (BS.machine_eval_code (Ins i) f s2)) = match i with | Instr _ _ _ -> eval_code_eq_instr i f s1 s2 | Dealloc _ -> eval_code_eq_dealloc i f s1 s2 | Alloc _ -> eval_code_eq_alloc i f s1 s2 | Push _ _ -> eval_code_eq_push i f s1 s2 | Pop _ _ -> eval_code_eq_pop i f s1 s2 #reset-options "--fuel 2 --z3rlimit 30" let eval_ocmp_eq_core (g:bool) (cond:ocmp) (s:machine_state) : Lemma (ensures ( let (s1, b1) = BS.machine_eval_ocmp s cond in let (s2, b2) = BS.machine_eval_ocmp (core_state g s) cond in state_eq_S g s1 s2 /\ b1 == b2 )) = reveal_opaque (`%BS.valid_ocmp_opaque) BS.valid_ocmp_opaque; reveal_opaque (`%BS.eval_ocmp_opaque) BS.eval_ocmp_opaque; () #restart-solver let rec eval_code_eq_core (g:bool) (c:code) (f:fuel) (s:machine_state) : Lemma (ensures state_eq_opt g (BS.machine_eval_code c f s) (BS.machine_eval_code c f (core_state g s))) (decreases %[f; c]) = match c with | Ins i -> reveal_opaque (`%BS.machine_eval_code_ins) BS.machine_eval_code_ins; if g then eval_code_eq_ins i f s (core_state g s) | Block cs -> eval_codes_eq_core g cs f s | IfElse cond ct cf -> eval_ocmp_eq_core g cond s; let (s', _) = BS.machine_eval_ocmp s cond in let (t', _) = BS.machine_eval_ocmp (core_state g s) cond in eval_code_eq_core g ct f s'; eval_code_eq_core g ct f t'; eval_code_eq_core g cf f s'; eval_code_eq_core g cf f t'; () | While cond body -> eval_while_eq_core g cond body f s and eval_codes_eq_core (g:bool) (cs:codes) (f:fuel) (s:machine_state) : Lemma (ensures state_eq_opt g (BS.machine_eval_codes cs f s) (BS.machine_eval_codes cs f (core_state g s))) (decreases %[f; cs]) = match cs with | [] -> () | c'::cs' -> ( eval_code_eq_core g c' f s; match (machine_eval_code c' f s, machine_eval_code c' f (core_state g s)) with | (None, None) -> () | (Some s', Some t') -> eval_codes_eq_core g cs' f s'; eval_codes_eq_core g cs' f t' ) and eval_while_eq_core (g:bool) (cond:ocmp) (body:code) (f:fuel) (s:machine_state) : Lemma (ensures state_eq_opt g (BS.machine_eval_while cond body f s) (BS.machine_eval_while cond body f (core_state g s))) (decreases %[f; body]) = if f > 0 then ( eval_ocmp_eq_core g cond s; let (s1, _) = BS.machine_eval_ocmp s cond in let (t1, _) = BS.machine_eval_ocmp (core_state g s) cond in eval_code_eq_core g body (f - 1) s1; eval_code_eq_core g body (f - 1) t1; match (BS.machine_eval_code body (f - 1) s1, BS.machine_eval_code body (f - 1) t1) with | (None, None) -> () | (Some s2, Some t2) -> eval_while_eq_core g cond body (f - 1) s2; eval_while_eq_core g cond body (f - 1) t2; () ) let eval_code_eq_f (c:code) (f:fuel) (s1 s2:machine_state) : Lemma (requires state_eq_S false s1 s2) (ensures state_eq_opt false (BS.machine_eval_code c f s1) (BS.machine_eval_code c f s2)) [SMTPat (BS.machine_eval_code c f s1); SMTPat (BS.machine_eval_code c f s2)] = eval_code_eq_core false c f s1; eval_code_eq_core false c f s2 let eval_codes_eq_f (cs:codes) (f:fuel) (s1 s2:machine_state) : Lemma (requires state_eq_S false s1 s2) (ensures state_eq_opt false (BS.machine_eval_codes cs f s1) (BS.machine_eval_codes cs f s2)) [SMTPat (BS.machine_eval_codes cs f s1); SMTPat (BS.machine_eval_codes cs f s2)] = eval_codes_eq_core false cs f s1; eval_codes_eq_core false cs f s2
{ "checked_file": "/", "dependencies": [ "Vale.X64.StateLemmas.fsti.checked", "Vale.X64.State.fsti.checked", "Vale.X64.Memory.fsti.checked", "Vale.X64.Machine_Semantics_s.fst.checked", "Vale.X64.Machine_s.fst.checked", "Vale.X64.Instruction_s.fsti.checked", "Vale.X64.Flags.fsti.checked", "Vale.X64.Bytes_Code_s.fst.checked", "prims.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.FunctionalExtensionality.fsti.checked" ], "interface_file": true, "source_file": "Vale.X64.Lemmas.fst" }
[ { "abbrev": true, "full_module": "Vale.X64.Memory", "short_module": "ME" }, { "abbrev": true, "full_module": "Vale.X64.Machine_Semantics_s", "short_module": "BS" }, { "abbrev": false, "full_module": "Vale.X64.Bytes_Code_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Instruction_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.StateLemmas", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.State", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Machine_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": true, "full_module": "Vale.Lib.Map16", "short_module": "Map16" }, { "abbrev": true, "full_module": "Vale.X64.Machine_Semantics_s", "short_module": "BS" }, { "abbrev": false, "full_module": "Vale.X64.Bytes_Code_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.StateLemmas", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.State", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Machine_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.HeapLemmas", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.HeapImpl", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.Heap", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 0, "max_fuel": 2, "max_ifuel": 1, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": true, "smtencoding_l_arith_repr": "native", "smtencoding_nl_arith_repr": "wrapped", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [ "smt.arith.nl=false", "smt.QI.EAGER_THRESHOLD=100", "smt.CASE_SPLIT=3" ], "z3refresh": false, "z3rlimit": 30, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
cond: Vale.X64.Bytes_Code_s.ocmp -> body: Vale.X64.StateLemmas.code -> f: Vale.X64.Lemmas.fuel -> s1: Vale.X64.StateLemmas.machine_state -> s2: Vale.X64.StateLemmas.machine_state -> FStar.Pervasives.Lemma (requires Vale.X64.Lemmas.state_eq_S false s1 s2) (ensures Vale.X64.Lemmas.state_eq_opt false (Vale.X64.Machine_Semantics_s.machine_eval_while cond body f s1) (Vale.X64.Machine_Semantics_s.machine_eval_while cond body f s2)) [ SMTPat (Vale.X64.Machine_Semantics_s.machine_eval_while cond body f s1); SMTPat (Vale.X64.Machine_Semantics_s.machine_eval_while cond body f s2) ]
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "Vale.X64.Bytes_Code_s.ocmp", "Vale.X64.StateLemmas.code", "Vale.X64.Lemmas.fuel", "Vale.X64.StateLemmas.machine_state", "Vale.X64.Lemmas.eval_while_eq_core", "Prims.unit", "Vale.X64.Lemmas.state_eq_S", "Prims.squash", "Vale.X64.Lemmas.state_eq_opt", "Vale.X64.Machine_Semantics_s.machine_eval_while", "Prims.Cons", "FStar.Pervasives.pattern", "FStar.Pervasives.smt_pat", "FStar.Pervasives.Native.option", "Vale.X64.Machine_Semantics_s.machine_state", "Prims.Nil" ]
[]
true
false
true
false
false
let eval_while_eq_f (cond: ocmp) (body: code) (f: fuel) (s1 s2: machine_state) : Lemma (requires state_eq_S false s1 s2) (ensures state_eq_opt false (BS.machine_eval_while cond body f s1) (BS.machine_eval_while cond body f s2)) [SMTPat (BS.machine_eval_while cond body f s1); SMTPat (BS.machine_eval_while cond body f s2)] =
eval_while_eq_core false cond body f s1; eval_while_eq_core false cond body f s2
false
Vale.X64.Lemmas.fst
Vale.X64.Lemmas.eval_while_eq_t
val eval_while_eq_t (cond: ocmp) (body: code) (f: fuel) (s1 s2: machine_state) : Lemma (requires state_eq_S true s1 s2) (ensures state_eq_opt true (BS.machine_eval_while cond body f s1) (BS.machine_eval_while cond body f s2)) [SMTPat (BS.machine_eval_while cond body f s1); SMTPat (BS.machine_eval_while cond body f s2)]
val eval_while_eq_t (cond: ocmp) (body: code) (f: fuel) (s1 s2: machine_state) : Lemma (requires state_eq_S true s1 s2) (ensures state_eq_opt true (BS.machine_eval_while cond body f s1) (BS.machine_eval_while cond body f s2)) [SMTPat (BS.machine_eval_while cond body f s1); SMTPat (BS.machine_eval_while cond body f s2)]
let eval_while_eq_t (cond:ocmp) (body:code) (f:fuel) (s1 s2:machine_state) : Lemma (requires state_eq_S true s1 s2) (ensures state_eq_opt true (BS.machine_eval_while cond body f s1) (BS.machine_eval_while cond body f s2)) [SMTPat (BS.machine_eval_while cond body f s1); SMTPat (BS.machine_eval_while cond body f s2)] = eval_while_eq_core true cond body f s1; eval_while_eq_core true cond body f s2
{ "file_name": "vale/code/arch/x64/Vale.X64.Lemmas.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 80, "end_line": 293, "start_col": 0, "start_line": 288 }
module Vale.X64.Lemmas open FStar.Mul open Vale.X64.Machine_s open Vale.X64.State open Vale.X64.StateLemmas open Vale.X64.Instruction_s open Vale.X64.Bytes_Code_s module BS = Vale.X64.Machine_Semantics_s module ME = Vale.X64.Memory #reset-options "--initial_fuel 1 --max_fuel 1 --z3rlimit 100" #restart-solver let rec lemma_eq_instr_apply_eval_args (outs:list instr_out) (args:list instr_operand) (f:instr_args_t outs args) (oprs:instr_operands_t_args args) (s1 s2:machine_state) : Lemma (requires state_eq_S true s1 s2) (ensures BS.instr_apply_eval_args outs args f oprs s1 == BS.instr_apply_eval_args outs args f oprs s2) = let open BS in lemma_heap_ignore_ghost_machine s1.BS.ms_heap s2.BS.ms_heap; match args with | [] -> () | i::args -> ( let (v, oprs) : option (instr_val_t i) & instr_operands_t_args args = match i with | IOpEx i -> let oprs = coerce oprs in (instr_eval_operand_explicit i (fst oprs) s1, snd oprs) | IOpIm i -> (instr_eval_operand_implicit i s1, coerce oprs) in let f:arrow (instr_val_t i) (instr_args_t outs args) = coerce f in match v with | None -> () | Some v -> lemma_eq_instr_apply_eval_args outs args (f v) oprs s1 s2 ) #restart-solver let rec lemma_eq_instr_apply_eval_inouts (outs inouts:list instr_out) (args:list instr_operand) (f:instr_inouts_t outs inouts args) (oprs:instr_operands_t inouts args) (s1 s2:machine_state) : Lemma (requires state_eq_S true s1 s2) (ensures BS.instr_apply_eval_inouts outs inouts args f oprs s1 == BS.instr_apply_eval_inouts outs inouts args f oprs s2) = let open BS in lemma_heap_ignore_ghost_machine s1.BS.ms_heap s2.BS.ms_heap; match inouts with | [] -> lemma_eq_instr_apply_eval_args outs args f oprs s1 s2 | (Out, i)::inouts -> let oprs = match i with | IOpEx i -> snd #(instr_operand_t i) (coerce oprs) | IOpIm i -> coerce oprs in lemma_eq_instr_apply_eval_inouts outs inouts args (coerce f) oprs s1 s2 | (InOut, i)::inouts -> ( let (v, oprs) : option (instr_val_t i) & instr_operands_t inouts args = match i with | IOpEx i -> let oprs = coerce oprs in (instr_eval_operand_explicit i (fst oprs) s1, snd oprs) | IOpIm i -> (instr_eval_operand_implicit i s1, coerce oprs) in let f:arrow (instr_val_t i) (instr_inouts_t outs inouts args) = coerce f in match v with | None -> () | Some v -> lemma_eq_instr_apply_eval_inouts outs inouts args (f v) oprs s1 s2 ) #restart-solver #push-options "--z3rlimit_factor 2" let rec lemma_eq_instr_write_outputs (outs:list instr_out) (args:list instr_operand) (vs:instr_ret_t outs) (oprs:instr_operands_t outs args) (s1_orig s1 s2_orig s2:machine_state) : Lemma (requires state_eq_S true s1_orig s2_orig /\ state_eq_S true s1 s2) (ensures state_eq_S true (BS.instr_write_outputs outs args vs oprs s1_orig s1) (BS.instr_write_outputs outs args vs oprs s2_orig s2)) = let open BS in use_machine_state_equal (); lemma_heap_ignore_ghost_machine s1.BS.ms_heap s2.BS.ms_heap; lemma_heap_ignore_ghost_machine s1_orig.BS.ms_heap s2_orig.BS.ms_heap; allow_inversion tmaddr; match outs with | [] -> () | (_, i)::outs -> ( let ((v:instr_val_t i), (vs:instr_ret_t outs)) = match outs with | [] -> (vs, ()) | _::_ -> let vs = coerce vs in (fst vs, snd vs) in match i with | IOpEx i -> let oprs = coerce oprs in let s1 = instr_write_output_explicit i v (fst oprs) s1_orig s1 in let s2 = instr_write_output_explicit i v (fst oprs) s2_orig s2 in lemma_eq_instr_write_outputs outs args vs (snd oprs) s1_orig s1 s2_orig s2 | IOpIm i -> let s1 = instr_write_output_implicit i v s1_orig s1 in let s2 = instr_write_output_implicit i v s2_orig s2 in allow_inversion operand64; allow_inversion operand128; lemma_eq_instr_write_outputs outs args vs (coerce oprs) s1_orig s1 s2_orig s2 ) #pop-options #restart-solver let eval_ins_eq_instr (inst:BS.ins) (s1 s2:machine_state) : Lemma (requires Instr? inst /\ state_eq_S true s1 s2) (ensures state_eq_S true (BS.machine_eval_ins inst s1) (BS.machine_eval_ins inst s2)) = let open BS in let Instr it oprs ann = inst in let InstrTypeRecord #outs #args #havoc_flags' i = it in lemma_eq_instr_apply_eval_inouts outs outs args (instr_eval i) oprs s1 s2; let vs = instr_apply_eval outs args (instr_eval i) oprs s1 in let hav s = match havoc_flags' with | HavocFlags -> {s with ms_flags = havoc_flags} | PreserveFlags -> s in let s1' = hav s1 in let s2' = hav s2 in match vs with | None -> () | Some vs -> lemma_eq_instr_write_outputs outs args vs oprs s1 s1' s2 s2' let eval_code_eq_instr (inst:BS.ins) (f:fuel) (s1 s2:machine_state) : Lemma (requires Instr? inst /\ state_eq_S true s1 s2) (ensures state_eq_opt true (BS.machine_eval_code (Ins inst) f s1) (BS.machine_eval_code (Ins inst) f s2)) = reveal_opaque (`%BS.machine_eval_code_ins) BS.machine_eval_code_ins; eval_ins_eq_instr inst ({s1 with BS.ms_trace = []}) ({s2 with BS.ms_trace = []}) let eval_code_eq_dealloc (inst:BS.ins) (f:fuel) (s1 s2:machine_state) : Lemma (requires Dealloc? inst /\ state_eq_S true s1 s2) (ensures state_eq_opt true (BS.machine_eval_code (Ins inst) f s1) (BS.machine_eval_code (Ins inst) f s2)) = reveal_opaque (`%BS.machine_eval_code_ins) BS.machine_eval_code_ins; use_machine_state_equal (); lemma_heap_ignore_ghost_machine s1.BS.ms_heap s2.BS.ms_heap; allow_inversion tmaddr let eval_code_eq_alloc (inst:BS.ins) (f:fuel) (s1 s2:machine_state) : Lemma (requires Alloc? inst /\ state_eq_S true s1 s2) (ensures state_eq_opt true (BS.machine_eval_code (Ins inst) f s1) (BS.machine_eval_code (Ins inst) f s2)) = reveal_opaque (`%BS.machine_eval_code_ins) BS.machine_eval_code_ins; use_machine_state_equal (); lemma_heap_ignore_ghost_machine s1.BS.ms_heap s2.BS.ms_heap; allow_inversion tmaddr let eval_code_eq_push (inst:BS.ins) (f:fuel) (s1 s2:machine_state) : Lemma (requires Push? inst /\ state_eq_S true s1 s2) (ensures state_eq_opt true (BS.machine_eval_code (Ins inst) f s1) (BS.machine_eval_code (Ins inst) f s2)) = reveal_opaque (`%BS.machine_eval_code_ins) BS.machine_eval_code_ins; use_machine_state_equal (); lemma_heap_ignore_ghost_machine s1.BS.ms_heap s2.BS.ms_heap; allow_inversion tmaddr let eval_code_eq_pop (inst:BS.ins) (f:fuel) (s1 s2:machine_state) : Lemma (requires Pop? inst /\ state_eq_S true s1 s2) (ensures state_eq_opt true (BS.machine_eval_code (Ins inst) f s1) (BS.machine_eval_code (Ins inst) f s2)) = reveal_opaque (`%BS.machine_eval_code_ins) BS.machine_eval_code_ins; use_machine_state_equal (); lemma_heap_ignore_ghost_machine s1.BS.ms_heap s2.BS.ms_heap; allow_inversion tmaddr let eval_code_eq_ins (i:BS.ins) (f:fuel) (s1 s2:machine_state) : Lemma (requires state_eq_S true s1 s2) (ensures state_eq_opt true (BS.machine_eval_code (Ins i) f s1) (BS.machine_eval_code (Ins i) f s2)) = match i with | Instr _ _ _ -> eval_code_eq_instr i f s1 s2 | Dealloc _ -> eval_code_eq_dealloc i f s1 s2 | Alloc _ -> eval_code_eq_alloc i f s1 s2 | Push _ _ -> eval_code_eq_push i f s1 s2 | Pop _ _ -> eval_code_eq_pop i f s1 s2 #reset-options "--fuel 2 --z3rlimit 30" let eval_ocmp_eq_core (g:bool) (cond:ocmp) (s:machine_state) : Lemma (ensures ( let (s1, b1) = BS.machine_eval_ocmp s cond in let (s2, b2) = BS.machine_eval_ocmp (core_state g s) cond in state_eq_S g s1 s2 /\ b1 == b2 )) = reveal_opaque (`%BS.valid_ocmp_opaque) BS.valid_ocmp_opaque; reveal_opaque (`%BS.eval_ocmp_opaque) BS.eval_ocmp_opaque; () #restart-solver let rec eval_code_eq_core (g:bool) (c:code) (f:fuel) (s:machine_state) : Lemma (ensures state_eq_opt g (BS.machine_eval_code c f s) (BS.machine_eval_code c f (core_state g s))) (decreases %[f; c]) = match c with | Ins i -> reveal_opaque (`%BS.machine_eval_code_ins) BS.machine_eval_code_ins; if g then eval_code_eq_ins i f s (core_state g s) | Block cs -> eval_codes_eq_core g cs f s | IfElse cond ct cf -> eval_ocmp_eq_core g cond s; let (s', _) = BS.machine_eval_ocmp s cond in let (t', _) = BS.machine_eval_ocmp (core_state g s) cond in eval_code_eq_core g ct f s'; eval_code_eq_core g ct f t'; eval_code_eq_core g cf f s'; eval_code_eq_core g cf f t'; () | While cond body -> eval_while_eq_core g cond body f s and eval_codes_eq_core (g:bool) (cs:codes) (f:fuel) (s:machine_state) : Lemma (ensures state_eq_opt g (BS.machine_eval_codes cs f s) (BS.machine_eval_codes cs f (core_state g s))) (decreases %[f; cs]) = match cs with | [] -> () | c'::cs' -> ( eval_code_eq_core g c' f s; match (machine_eval_code c' f s, machine_eval_code c' f (core_state g s)) with | (None, None) -> () | (Some s', Some t') -> eval_codes_eq_core g cs' f s'; eval_codes_eq_core g cs' f t' ) and eval_while_eq_core (g:bool) (cond:ocmp) (body:code) (f:fuel) (s:machine_state) : Lemma (ensures state_eq_opt g (BS.machine_eval_while cond body f s) (BS.machine_eval_while cond body f (core_state g s))) (decreases %[f; body]) = if f > 0 then ( eval_ocmp_eq_core g cond s; let (s1, _) = BS.machine_eval_ocmp s cond in let (t1, _) = BS.machine_eval_ocmp (core_state g s) cond in eval_code_eq_core g body (f - 1) s1; eval_code_eq_core g body (f - 1) t1; match (BS.machine_eval_code body (f - 1) s1, BS.machine_eval_code body (f - 1) t1) with | (None, None) -> () | (Some s2, Some t2) -> eval_while_eq_core g cond body (f - 1) s2; eval_while_eq_core g cond body (f - 1) t2; () ) let eval_code_eq_f (c:code) (f:fuel) (s1 s2:machine_state) : Lemma (requires state_eq_S false s1 s2) (ensures state_eq_opt false (BS.machine_eval_code c f s1) (BS.machine_eval_code c f s2)) [SMTPat (BS.machine_eval_code c f s1); SMTPat (BS.machine_eval_code c f s2)] = eval_code_eq_core false c f s1; eval_code_eq_core false c f s2 let eval_codes_eq_f (cs:codes) (f:fuel) (s1 s2:machine_state) : Lemma (requires state_eq_S false s1 s2) (ensures state_eq_opt false (BS.machine_eval_codes cs f s1) (BS.machine_eval_codes cs f s2)) [SMTPat (BS.machine_eval_codes cs f s1); SMTPat (BS.machine_eval_codes cs f s2)] = eval_codes_eq_core false cs f s1; eval_codes_eq_core false cs f s2 let eval_while_eq_f (cond:ocmp) (body:code) (f:fuel) (s1 s2:machine_state) : Lemma (requires state_eq_S false s1 s2) (ensures state_eq_opt false (BS.machine_eval_while cond body f s1) (BS.machine_eval_while cond body f s2)) [SMTPat (BS.machine_eval_while cond body f s1); SMTPat (BS.machine_eval_while cond body f s2)] = eval_while_eq_core false cond body f s1; eval_while_eq_core false cond body f s2 let eval_code_eq_t (c:code) (f:fuel) (s1 s2:machine_state) : Lemma (requires state_eq_S true s1 s2) (ensures state_eq_opt true (BS.machine_eval_code c f s1) (BS.machine_eval_code c f s2)) [SMTPat (BS.machine_eval_code c f s1); SMTPat (BS.machine_eval_code c f s2)] = eval_code_eq_core true c f s1; eval_code_eq_core true c f s2 let eval_codes_eq_t (cs:codes) (f:fuel) (s1 s2:machine_state) : Lemma (requires state_eq_S true s1 s2) (ensures state_eq_opt true (BS.machine_eval_codes cs f s1) (BS.machine_eval_codes cs f s2)) [SMTPat (BS.machine_eval_codes cs f s1); SMTPat (BS.machine_eval_codes cs f s2)] = eval_codes_eq_core true cs f s1; eval_codes_eq_core true cs f s2
{ "checked_file": "/", "dependencies": [ "Vale.X64.StateLemmas.fsti.checked", "Vale.X64.State.fsti.checked", "Vale.X64.Memory.fsti.checked", "Vale.X64.Machine_Semantics_s.fst.checked", "Vale.X64.Machine_s.fst.checked", "Vale.X64.Instruction_s.fsti.checked", "Vale.X64.Flags.fsti.checked", "Vale.X64.Bytes_Code_s.fst.checked", "prims.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.FunctionalExtensionality.fsti.checked" ], "interface_file": true, "source_file": "Vale.X64.Lemmas.fst" }
[ { "abbrev": true, "full_module": "Vale.X64.Memory", "short_module": "ME" }, { "abbrev": true, "full_module": "Vale.X64.Machine_Semantics_s", "short_module": "BS" }, { "abbrev": false, "full_module": "Vale.X64.Bytes_Code_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Instruction_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.StateLemmas", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.State", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Machine_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": true, "full_module": "Vale.Lib.Map16", "short_module": "Map16" }, { "abbrev": true, "full_module": "Vale.X64.Machine_Semantics_s", "short_module": "BS" }, { "abbrev": false, "full_module": "Vale.X64.Bytes_Code_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.StateLemmas", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.State", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Machine_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.HeapLemmas", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.HeapImpl", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.Heap", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 0, "max_fuel": 2, "max_ifuel": 1, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": true, "smtencoding_l_arith_repr": "native", "smtencoding_nl_arith_repr": "wrapped", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [ "smt.arith.nl=false", "smt.QI.EAGER_THRESHOLD=100", "smt.CASE_SPLIT=3" ], "z3refresh": false, "z3rlimit": 30, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
cond: Vale.X64.Bytes_Code_s.ocmp -> body: Vale.X64.StateLemmas.code -> f: Vale.X64.Lemmas.fuel -> s1: Vale.X64.StateLemmas.machine_state -> s2: Vale.X64.StateLemmas.machine_state -> FStar.Pervasives.Lemma (requires Vale.X64.Lemmas.state_eq_S true s1 s2) (ensures Vale.X64.Lemmas.state_eq_opt true (Vale.X64.Machine_Semantics_s.machine_eval_while cond body f s1) (Vale.X64.Machine_Semantics_s.machine_eval_while cond body f s2)) [ SMTPat (Vale.X64.Machine_Semantics_s.machine_eval_while cond body f s1); SMTPat (Vale.X64.Machine_Semantics_s.machine_eval_while cond body f s2) ]
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "Vale.X64.Bytes_Code_s.ocmp", "Vale.X64.StateLemmas.code", "Vale.X64.Lemmas.fuel", "Vale.X64.StateLemmas.machine_state", "Vale.X64.Lemmas.eval_while_eq_core", "Prims.unit", "Vale.X64.Lemmas.state_eq_S", "Prims.squash", "Vale.X64.Lemmas.state_eq_opt", "Vale.X64.Machine_Semantics_s.machine_eval_while", "Prims.Cons", "FStar.Pervasives.pattern", "FStar.Pervasives.smt_pat", "FStar.Pervasives.Native.option", "Vale.X64.Machine_Semantics_s.machine_state", "Prims.Nil" ]
[]
true
false
true
false
false
let eval_while_eq_t (cond: ocmp) (body: code) (f: fuel) (s1 s2: machine_state) : Lemma (requires state_eq_S true s1 s2) (ensures state_eq_opt true (BS.machine_eval_while cond body f s1) (BS.machine_eval_while cond body f s2)) [SMTPat (BS.machine_eval_while cond body f s1); SMTPat (BS.machine_eval_while cond body f s2)] =
eval_while_eq_core true cond body f s1; eval_while_eq_core true cond body f s2
false
Vale.X64.Lemmas.fst
Vale.X64.Lemmas.eval_code_eq_t
val eval_code_eq_t (c: code) (f: fuel) (s1 s2: machine_state) : Lemma (requires state_eq_S true s1 s2) (ensures state_eq_opt true (BS.machine_eval_code c f s1) (BS.machine_eval_code c f s2)) [SMTPat (BS.machine_eval_code c f s1); SMTPat (BS.machine_eval_code c f s2)]
val eval_code_eq_t (c: code) (f: fuel) (s1 s2: machine_state) : Lemma (requires state_eq_S true s1 s2) (ensures state_eq_opt true (BS.machine_eval_code c f s1) (BS.machine_eval_code c f s2)) [SMTPat (BS.machine_eval_code c f s1); SMTPat (BS.machine_eval_code c f s2)]
let eval_code_eq_t (c:code) (f:fuel) (s1 s2:machine_state) : Lemma (requires state_eq_S true s1 s2) (ensures state_eq_opt true (BS.machine_eval_code c f s1) (BS.machine_eval_code c f s2)) [SMTPat (BS.machine_eval_code c f s1); SMTPat (BS.machine_eval_code c f s2)] = eval_code_eq_core true c f s1; eval_code_eq_core true c f s2
{ "file_name": "vale/code/arch/x64/Vale.X64.Lemmas.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 62, "end_line": 279, "start_col": 0, "start_line": 274 }
module Vale.X64.Lemmas open FStar.Mul open Vale.X64.Machine_s open Vale.X64.State open Vale.X64.StateLemmas open Vale.X64.Instruction_s open Vale.X64.Bytes_Code_s module BS = Vale.X64.Machine_Semantics_s module ME = Vale.X64.Memory #reset-options "--initial_fuel 1 --max_fuel 1 --z3rlimit 100" #restart-solver let rec lemma_eq_instr_apply_eval_args (outs:list instr_out) (args:list instr_operand) (f:instr_args_t outs args) (oprs:instr_operands_t_args args) (s1 s2:machine_state) : Lemma (requires state_eq_S true s1 s2) (ensures BS.instr_apply_eval_args outs args f oprs s1 == BS.instr_apply_eval_args outs args f oprs s2) = let open BS in lemma_heap_ignore_ghost_machine s1.BS.ms_heap s2.BS.ms_heap; match args with | [] -> () | i::args -> ( let (v, oprs) : option (instr_val_t i) & instr_operands_t_args args = match i with | IOpEx i -> let oprs = coerce oprs in (instr_eval_operand_explicit i (fst oprs) s1, snd oprs) | IOpIm i -> (instr_eval_operand_implicit i s1, coerce oprs) in let f:arrow (instr_val_t i) (instr_args_t outs args) = coerce f in match v with | None -> () | Some v -> lemma_eq_instr_apply_eval_args outs args (f v) oprs s1 s2 ) #restart-solver let rec lemma_eq_instr_apply_eval_inouts (outs inouts:list instr_out) (args:list instr_operand) (f:instr_inouts_t outs inouts args) (oprs:instr_operands_t inouts args) (s1 s2:machine_state) : Lemma (requires state_eq_S true s1 s2) (ensures BS.instr_apply_eval_inouts outs inouts args f oprs s1 == BS.instr_apply_eval_inouts outs inouts args f oprs s2) = let open BS in lemma_heap_ignore_ghost_machine s1.BS.ms_heap s2.BS.ms_heap; match inouts with | [] -> lemma_eq_instr_apply_eval_args outs args f oprs s1 s2 | (Out, i)::inouts -> let oprs = match i with | IOpEx i -> snd #(instr_operand_t i) (coerce oprs) | IOpIm i -> coerce oprs in lemma_eq_instr_apply_eval_inouts outs inouts args (coerce f) oprs s1 s2 | (InOut, i)::inouts -> ( let (v, oprs) : option (instr_val_t i) & instr_operands_t inouts args = match i with | IOpEx i -> let oprs = coerce oprs in (instr_eval_operand_explicit i (fst oprs) s1, snd oprs) | IOpIm i -> (instr_eval_operand_implicit i s1, coerce oprs) in let f:arrow (instr_val_t i) (instr_inouts_t outs inouts args) = coerce f in match v with | None -> () | Some v -> lemma_eq_instr_apply_eval_inouts outs inouts args (f v) oprs s1 s2 ) #restart-solver #push-options "--z3rlimit_factor 2" let rec lemma_eq_instr_write_outputs (outs:list instr_out) (args:list instr_operand) (vs:instr_ret_t outs) (oprs:instr_operands_t outs args) (s1_orig s1 s2_orig s2:machine_state) : Lemma (requires state_eq_S true s1_orig s2_orig /\ state_eq_S true s1 s2) (ensures state_eq_S true (BS.instr_write_outputs outs args vs oprs s1_orig s1) (BS.instr_write_outputs outs args vs oprs s2_orig s2)) = let open BS in use_machine_state_equal (); lemma_heap_ignore_ghost_machine s1.BS.ms_heap s2.BS.ms_heap; lemma_heap_ignore_ghost_machine s1_orig.BS.ms_heap s2_orig.BS.ms_heap; allow_inversion tmaddr; match outs with | [] -> () | (_, i)::outs -> ( let ((v:instr_val_t i), (vs:instr_ret_t outs)) = match outs with | [] -> (vs, ()) | _::_ -> let vs = coerce vs in (fst vs, snd vs) in match i with | IOpEx i -> let oprs = coerce oprs in let s1 = instr_write_output_explicit i v (fst oprs) s1_orig s1 in let s2 = instr_write_output_explicit i v (fst oprs) s2_orig s2 in lemma_eq_instr_write_outputs outs args vs (snd oprs) s1_orig s1 s2_orig s2 | IOpIm i -> let s1 = instr_write_output_implicit i v s1_orig s1 in let s2 = instr_write_output_implicit i v s2_orig s2 in allow_inversion operand64; allow_inversion operand128; lemma_eq_instr_write_outputs outs args vs (coerce oprs) s1_orig s1 s2_orig s2 ) #pop-options #restart-solver let eval_ins_eq_instr (inst:BS.ins) (s1 s2:machine_state) : Lemma (requires Instr? inst /\ state_eq_S true s1 s2) (ensures state_eq_S true (BS.machine_eval_ins inst s1) (BS.machine_eval_ins inst s2)) = let open BS in let Instr it oprs ann = inst in let InstrTypeRecord #outs #args #havoc_flags' i = it in lemma_eq_instr_apply_eval_inouts outs outs args (instr_eval i) oprs s1 s2; let vs = instr_apply_eval outs args (instr_eval i) oprs s1 in let hav s = match havoc_flags' with | HavocFlags -> {s with ms_flags = havoc_flags} | PreserveFlags -> s in let s1' = hav s1 in let s2' = hav s2 in match vs with | None -> () | Some vs -> lemma_eq_instr_write_outputs outs args vs oprs s1 s1' s2 s2' let eval_code_eq_instr (inst:BS.ins) (f:fuel) (s1 s2:machine_state) : Lemma (requires Instr? inst /\ state_eq_S true s1 s2) (ensures state_eq_opt true (BS.machine_eval_code (Ins inst) f s1) (BS.machine_eval_code (Ins inst) f s2)) = reveal_opaque (`%BS.machine_eval_code_ins) BS.machine_eval_code_ins; eval_ins_eq_instr inst ({s1 with BS.ms_trace = []}) ({s2 with BS.ms_trace = []}) let eval_code_eq_dealloc (inst:BS.ins) (f:fuel) (s1 s2:machine_state) : Lemma (requires Dealloc? inst /\ state_eq_S true s1 s2) (ensures state_eq_opt true (BS.machine_eval_code (Ins inst) f s1) (BS.machine_eval_code (Ins inst) f s2)) = reveal_opaque (`%BS.machine_eval_code_ins) BS.machine_eval_code_ins; use_machine_state_equal (); lemma_heap_ignore_ghost_machine s1.BS.ms_heap s2.BS.ms_heap; allow_inversion tmaddr let eval_code_eq_alloc (inst:BS.ins) (f:fuel) (s1 s2:machine_state) : Lemma (requires Alloc? inst /\ state_eq_S true s1 s2) (ensures state_eq_opt true (BS.machine_eval_code (Ins inst) f s1) (BS.machine_eval_code (Ins inst) f s2)) = reveal_opaque (`%BS.machine_eval_code_ins) BS.machine_eval_code_ins; use_machine_state_equal (); lemma_heap_ignore_ghost_machine s1.BS.ms_heap s2.BS.ms_heap; allow_inversion tmaddr let eval_code_eq_push (inst:BS.ins) (f:fuel) (s1 s2:machine_state) : Lemma (requires Push? inst /\ state_eq_S true s1 s2) (ensures state_eq_opt true (BS.machine_eval_code (Ins inst) f s1) (BS.machine_eval_code (Ins inst) f s2)) = reveal_opaque (`%BS.machine_eval_code_ins) BS.machine_eval_code_ins; use_machine_state_equal (); lemma_heap_ignore_ghost_machine s1.BS.ms_heap s2.BS.ms_heap; allow_inversion tmaddr let eval_code_eq_pop (inst:BS.ins) (f:fuel) (s1 s2:machine_state) : Lemma (requires Pop? inst /\ state_eq_S true s1 s2) (ensures state_eq_opt true (BS.machine_eval_code (Ins inst) f s1) (BS.machine_eval_code (Ins inst) f s2)) = reveal_opaque (`%BS.machine_eval_code_ins) BS.machine_eval_code_ins; use_machine_state_equal (); lemma_heap_ignore_ghost_machine s1.BS.ms_heap s2.BS.ms_heap; allow_inversion tmaddr let eval_code_eq_ins (i:BS.ins) (f:fuel) (s1 s2:machine_state) : Lemma (requires state_eq_S true s1 s2) (ensures state_eq_opt true (BS.machine_eval_code (Ins i) f s1) (BS.machine_eval_code (Ins i) f s2)) = match i with | Instr _ _ _ -> eval_code_eq_instr i f s1 s2 | Dealloc _ -> eval_code_eq_dealloc i f s1 s2 | Alloc _ -> eval_code_eq_alloc i f s1 s2 | Push _ _ -> eval_code_eq_push i f s1 s2 | Pop _ _ -> eval_code_eq_pop i f s1 s2 #reset-options "--fuel 2 --z3rlimit 30" let eval_ocmp_eq_core (g:bool) (cond:ocmp) (s:machine_state) : Lemma (ensures ( let (s1, b1) = BS.machine_eval_ocmp s cond in let (s2, b2) = BS.machine_eval_ocmp (core_state g s) cond in state_eq_S g s1 s2 /\ b1 == b2 )) = reveal_opaque (`%BS.valid_ocmp_opaque) BS.valid_ocmp_opaque; reveal_opaque (`%BS.eval_ocmp_opaque) BS.eval_ocmp_opaque; () #restart-solver let rec eval_code_eq_core (g:bool) (c:code) (f:fuel) (s:machine_state) : Lemma (ensures state_eq_opt g (BS.machine_eval_code c f s) (BS.machine_eval_code c f (core_state g s))) (decreases %[f; c]) = match c with | Ins i -> reveal_opaque (`%BS.machine_eval_code_ins) BS.machine_eval_code_ins; if g then eval_code_eq_ins i f s (core_state g s) | Block cs -> eval_codes_eq_core g cs f s | IfElse cond ct cf -> eval_ocmp_eq_core g cond s; let (s', _) = BS.machine_eval_ocmp s cond in let (t', _) = BS.machine_eval_ocmp (core_state g s) cond in eval_code_eq_core g ct f s'; eval_code_eq_core g ct f t'; eval_code_eq_core g cf f s'; eval_code_eq_core g cf f t'; () | While cond body -> eval_while_eq_core g cond body f s and eval_codes_eq_core (g:bool) (cs:codes) (f:fuel) (s:machine_state) : Lemma (ensures state_eq_opt g (BS.machine_eval_codes cs f s) (BS.machine_eval_codes cs f (core_state g s))) (decreases %[f; cs]) = match cs with | [] -> () | c'::cs' -> ( eval_code_eq_core g c' f s; match (machine_eval_code c' f s, machine_eval_code c' f (core_state g s)) with | (None, None) -> () | (Some s', Some t') -> eval_codes_eq_core g cs' f s'; eval_codes_eq_core g cs' f t' ) and eval_while_eq_core (g:bool) (cond:ocmp) (body:code) (f:fuel) (s:machine_state) : Lemma (ensures state_eq_opt g (BS.machine_eval_while cond body f s) (BS.machine_eval_while cond body f (core_state g s))) (decreases %[f; body]) = if f > 0 then ( eval_ocmp_eq_core g cond s; let (s1, _) = BS.machine_eval_ocmp s cond in let (t1, _) = BS.machine_eval_ocmp (core_state g s) cond in eval_code_eq_core g body (f - 1) s1; eval_code_eq_core g body (f - 1) t1; match (BS.machine_eval_code body (f - 1) s1, BS.machine_eval_code body (f - 1) t1) with | (None, None) -> () | (Some s2, Some t2) -> eval_while_eq_core g cond body (f - 1) s2; eval_while_eq_core g cond body (f - 1) t2; () ) let eval_code_eq_f (c:code) (f:fuel) (s1 s2:machine_state) : Lemma (requires state_eq_S false s1 s2) (ensures state_eq_opt false (BS.machine_eval_code c f s1) (BS.machine_eval_code c f s2)) [SMTPat (BS.machine_eval_code c f s1); SMTPat (BS.machine_eval_code c f s2)] = eval_code_eq_core false c f s1; eval_code_eq_core false c f s2 let eval_codes_eq_f (cs:codes) (f:fuel) (s1 s2:machine_state) : Lemma (requires state_eq_S false s1 s2) (ensures state_eq_opt false (BS.machine_eval_codes cs f s1) (BS.machine_eval_codes cs f s2)) [SMTPat (BS.machine_eval_codes cs f s1); SMTPat (BS.machine_eval_codes cs f s2)] = eval_codes_eq_core false cs f s1; eval_codes_eq_core false cs f s2 let eval_while_eq_f (cond:ocmp) (body:code) (f:fuel) (s1 s2:machine_state) : Lemma (requires state_eq_S false s1 s2) (ensures state_eq_opt false (BS.machine_eval_while cond body f s1) (BS.machine_eval_while cond body f s2)) [SMTPat (BS.machine_eval_while cond body f s1); SMTPat (BS.machine_eval_while cond body f s2)] = eval_while_eq_core false cond body f s1; eval_while_eq_core false cond body f s2
{ "checked_file": "/", "dependencies": [ "Vale.X64.StateLemmas.fsti.checked", "Vale.X64.State.fsti.checked", "Vale.X64.Memory.fsti.checked", "Vale.X64.Machine_Semantics_s.fst.checked", "Vale.X64.Machine_s.fst.checked", "Vale.X64.Instruction_s.fsti.checked", "Vale.X64.Flags.fsti.checked", "Vale.X64.Bytes_Code_s.fst.checked", "prims.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.FunctionalExtensionality.fsti.checked" ], "interface_file": true, "source_file": "Vale.X64.Lemmas.fst" }
[ { "abbrev": true, "full_module": "Vale.X64.Memory", "short_module": "ME" }, { "abbrev": true, "full_module": "Vale.X64.Machine_Semantics_s", "short_module": "BS" }, { "abbrev": false, "full_module": "Vale.X64.Bytes_Code_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Instruction_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.StateLemmas", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.State", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Machine_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": true, "full_module": "Vale.Lib.Map16", "short_module": "Map16" }, { "abbrev": true, "full_module": "Vale.X64.Machine_Semantics_s", "short_module": "BS" }, { "abbrev": false, "full_module": "Vale.X64.Bytes_Code_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.StateLemmas", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.State", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Machine_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.HeapLemmas", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.HeapImpl", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.Heap", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 0, "max_fuel": 2, "max_ifuel": 1, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": true, "smtencoding_l_arith_repr": "native", "smtencoding_nl_arith_repr": "wrapped", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [ "smt.arith.nl=false", "smt.QI.EAGER_THRESHOLD=100", "smt.CASE_SPLIT=3" ], "z3refresh": false, "z3rlimit": 30, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
c: Vale.X64.StateLemmas.code -> f: Vale.X64.Lemmas.fuel -> s1: Vale.X64.StateLemmas.machine_state -> s2: Vale.X64.StateLemmas.machine_state -> FStar.Pervasives.Lemma (requires Vale.X64.Lemmas.state_eq_S true s1 s2) (ensures Vale.X64.Lemmas.state_eq_opt true (Vale.X64.Machine_Semantics_s.machine_eval_code c f s1) (Vale.X64.Machine_Semantics_s.machine_eval_code c f s2)) [ SMTPat (Vale.X64.Machine_Semantics_s.machine_eval_code c f s1); SMTPat (Vale.X64.Machine_Semantics_s.machine_eval_code c f s2) ]
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "Vale.X64.StateLemmas.code", "Vale.X64.Lemmas.fuel", "Vale.X64.StateLemmas.machine_state", "Vale.X64.Lemmas.eval_code_eq_core", "Prims.unit", "Vale.X64.Lemmas.state_eq_S", "Prims.squash", "Vale.X64.Lemmas.state_eq_opt", "Vale.X64.Machine_Semantics_s.machine_eval_code", "Prims.Cons", "FStar.Pervasives.pattern", "FStar.Pervasives.smt_pat", "FStar.Pervasives.Native.option", "Vale.X64.Machine_Semantics_s.machine_state", "Prims.Nil" ]
[]
true
false
true
false
false
let eval_code_eq_t (c: code) (f: fuel) (s1 s2: machine_state) : Lemma (requires state_eq_S true s1 s2) (ensures state_eq_opt true (BS.machine_eval_code c f s1) (BS.machine_eval_code c f s2)) [SMTPat (BS.machine_eval_code c f s1); SMTPat (BS.machine_eval_code c f s2)] =
eval_code_eq_core true c f s1; eval_code_eq_core true c f s2
false
Vale.X64.Lemmas.fst
Vale.X64.Lemmas.eval_codes_eq_t
val eval_codes_eq_t (cs: codes) (f: fuel) (s1 s2: machine_state) : Lemma (requires state_eq_S true s1 s2) (ensures state_eq_opt true (BS.machine_eval_codes cs f s1) (BS.machine_eval_codes cs f s2)) [SMTPat (BS.machine_eval_codes cs f s1); SMTPat (BS.machine_eval_codes cs f s2)]
val eval_codes_eq_t (cs: codes) (f: fuel) (s1 s2: machine_state) : Lemma (requires state_eq_S true s1 s2) (ensures state_eq_opt true (BS.machine_eval_codes cs f s1) (BS.machine_eval_codes cs f s2)) [SMTPat (BS.machine_eval_codes cs f s1); SMTPat (BS.machine_eval_codes cs f s2)]
let eval_codes_eq_t (cs:codes) (f:fuel) (s1 s2:machine_state) : Lemma (requires state_eq_S true s1 s2) (ensures state_eq_opt true (BS.machine_eval_codes cs f s1) (BS.machine_eval_codes cs f s2)) [SMTPat (BS.machine_eval_codes cs f s1); SMTPat (BS.machine_eval_codes cs f s2)] = eval_codes_eq_core true cs f s1; eval_codes_eq_core true cs f s2
{ "file_name": "vale/code/arch/x64/Vale.X64.Lemmas.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 66, "end_line": 286, "start_col": 0, "start_line": 281 }
module Vale.X64.Lemmas open FStar.Mul open Vale.X64.Machine_s open Vale.X64.State open Vale.X64.StateLemmas open Vale.X64.Instruction_s open Vale.X64.Bytes_Code_s module BS = Vale.X64.Machine_Semantics_s module ME = Vale.X64.Memory #reset-options "--initial_fuel 1 --max_fuel 1 --z3rlimit 100" #restart-solver let rec lemma_eq_instr_apply_eval_args (outs:list instr_out) (args:list instr_operand) (f:instr_args_t outs args) (oprs:instr_operands_t_args args) (s1 s2:machine_state) : Lemma (requires state_eq_S true s1 s2) (ensures BS.instr_apply_eval_args outs args f oprs s1 == BS.instr_apply_eval_args outs args f oprs s2) = let open BS in lemma_heap_ignore_ghost_machine s1.BS.ms_heap s2.BS.ms_heap; match args with | [] -> () | i::args -> ( let (v, oprs) : option (instr_val_t i) & instr_operands_t_args args = match i with | IOpEx i -> let oprs = coerce oprs in (instr_eval_operand_explicit i (fst oprs) s1, snd oprs) | IOpIm i -> (instr_eval_operand_implicit i s1, coerce oprs) in let f:arrow (instr_val_t i) (instr_args_t outs args) = coerce f in match v with | None -> () | Some v -> lemma_eq_instr_apply_eval_args outs args (f v) oprs s1 s2 ) #restart-solver let rec lemma_eq_instr_apply_eval_inouts (outs inouts:list instr_out) (args:list instr_operand) (f:instr_inouts_t outs inouts args) (oprs:instr_operands_t inouts args) (s1 s2:machine_state) : Lemma (requires state_eq_S true s1 s2) (ensures BS.instr_apply_eval_inouts outs inouts args f oprs s1 == BS.instr_apply_eval_inouts outs inouts args f oprs s2) = let open BS in lemma_heap_ignore_ghost_machine s1.BS.ms_heap s2.BS.ms_heap; match inouts with | [] -> lemma_eq_instr_apply_eval_args outs args f oprs s1 s2 | (Out, i)::inouts -> let oprs = match i with | IOpEx i -> snd #(instr_operand_t i) (coerce oprs) | IOpIm i -> coerce oprs in lemma_eq_instr_apply_eval_inouts outs inouts args (coerce f) oprs s1 s2 | (InOut, i)::inouts -> ( let (v, oprs) : option (instr_val_t i) & instr_operands_t inouts args = match i with | IOpEx i -> let oprs = coerce oprs in (instr_eval_operand_explicit i (fst oprs) s1, snd oprs) | IOpIm i -> (instr_eval_operand_implicit i s1, coerce oprs) in let f:arrow (instr_val_t i) (instr_inouts_t outs inouts args) = coerce f in match v with | None -> () | Some v -> lemma_eq_instr_apply_eval_inouts outs inouts args (f v) oprs s1 s2 ) #restart-solver #push-options "--z3rlimit_factor 2" let rec lemma_eq_instr_write_outputs (outs:list instr_out) (args:list instr_operand) (vs:instr_ret_t outs) (oprs:instr_operands_t outs args) (s1_orig s1 s2_orig s2:machine_state) : Lemma (requires state_eq_S true s1_orig s2_orig /\ state_eq_S true s1 s2) (ensures state_eq_S true (BS.instr_write_outputs outs args vs oprs s1_orig s1) (BS.instr_write_outputs outs args vs oprs s2_orig s2)) = let open BS in use_machine_state_equal (); lemma_heap_ignore_ghost_machine s1.BS.ms_heap s2.BS.ms_heap; lemma_heap_ignore_ghost_machine s1_orig.BS.ms_heap s2_orig.BS.ms_heap; allow_inversion tmaddr; match outs with | [] -> () | (_, i)::outs -> ( let ((v:instr_val_t i), (vs:instr_ret_t outs)) = match outs with | [] -> (vs, ()) | _::_ -> let vs = coerce vs in (fst vs, snd vs) in match i with | IOpEx i -> let oprs = coerce oprs in let s1 = instr_write_output_explicit i v (fst oprs) s1_orig s1 in let s2 = instr_write_output_explicit i v (fst oprs) s2_orig s2 in lemma_eq_instr_write_outputs outs args vs (snd oprs) s1_orig s1 s2_orig s2 | IOpIm i -> let s1 = instr_write_output_implicit i v s1_orig s1 in let s2 = instr_write_output_implicit i v s2_orig s2 in allow_inversion operand64; allow_inversion operand128; lemma_eq_instr_write_outputs outs args vs (coerce oprs) s1_orig s1 s2_orig s2 ) #pop-options #restart-solver let eval_ins_eq_instr (inst:BS.ins) (s1 s2:machine_state) : Lemma (requires Instr? inst /\ state_eq_S true s1 s2) (ensures state_eq_S true (BS.machine_eval_ins inst s1) (BS.machine_eval_ins inst s2)) = let open BS in let Instr it oprs ann = inst in let InstrTypeRecord #outs #args #havoc_flags' i = it in lemma_eq_instr_apply_eval_inouts outs outs args (instr_eval i) oprs s1 s2; let vs = instr_apply_eval outs args (instr_eval i) oprs s1 in let hav s = match havoc_flags' with | HavocFlags -> {s with ms_flags = havoc_flags} | PreserveFlags -> s in let s1' = hav s1 in let s2' = hav s2 in match vs with | None -> () | Some vs -> lemma_eq_instr_write_outputs outs args vs oprs s1 s1' s2 s2' let eval_code_eq_instr (inst:BS.ins) (f:fuel) (s1 s2:machine_state) : Lemma (requires Instr? inst /\ state_eq_S true s1 s2) (ensures state_eq_opt true (BS.machine_eval_code (Ins inst) f s1) (BS.machine_eval_code (Ins inst) f s2)) = reveal_opaque (`%BS.machine_eval_code_ins) BS.machine_eval_code_ins; eval_ins_eq_instr inst ({s1 with BS.ms_trace = []}) ({s2 with BS.ms_trace = []}) let eval_code_eq_dealloc (inst:BS.ins) (f:fuel) (s1 s2:machine_state) : Lemma (requires Dealloc? inst /\ state_eq_S true s1 s2) (ensures state_eq_opt true (BS.machine_eval_code (Ins inst) f s1) (BS.machine_eval_code (Ins inst) f s2)) = reveal_opaque (`%BS.machine_eval_code_ins) BS.machine_eval_code_ins; use_machine_state_equal (); lemma_heap_ignore_ghost_machine s1.BS.ms_heap s2.BS.ms_heap; allow_inversion tmaddr let eval_code_eq_alloc (inst:BS.ins) (f:fuel) (s1 s2:machine_state) : Lemma (requires Alloc? inst /\ state_eq_S true s1 s2) (ensures state_eq_opt true (BS.machine_eval_code (Ins inst) f s1) (BS.machine_eval_code (Ins inst) f s2)) = reveal_opaque (`%BS.machine_eval_code_ins) BS.machine_eval_code_ins; use_machine_state_equal (); lemma_heap_ignore_ghost_machine s1.BS.ms_heap s2.BS.ms_heap; allow_inversion tmaddr let eval_code_eq_push (inst:BS.ins) (f:fuel) (s1 s2:machine_state) : Lemma (requires Push? inst /\ state_eq_S true s1 s2) (ensures state_eq_opt true (BS.machine_eval_code (Ins inst) f s1) (BS.machine_eval_code (Ins inst) f s2)) = reveal_opaque (`%BS.machine_eval_code_ins) BS.machine_eval_code_ins; use_machine_state_equal (); lemma_heap_ignore_ghost_machine s1.BS.ms_heap s2.BS.ms_heap; allow_inversion tmaddr let eval_code_eq_pop (inst:BS.ins) (f:fuel) (s1 s2:machine_state) : Lemma (requires Pop? inst /\ state_eq_S true s1 s2) (ensures state_eq_opt true (BS.machine_eval_code (Ins inst) f s1) (BS.machine_eval_code (Ins inst) f s2)) = reveal_opaque (`%BS.machine_eval_code_ins) BS.machine_eval_code_ins; use_machine_state_equal (); lemma_heap_ignore_ghost_machine s1.BS.ms_heap s2.BS.ms_heap; allow_inversion tmaddr let eval_code_eq_ins (i:BS.ins) (f:fuel) (s1 s2:machine_state) : Lemma (requires state_eq_S true s1 s2) (ensures state_eq_opt true (BS.machine_eval_code (Ins i) f s1) (BS.machine_eval_code (Ins i) f s2)) = match i with | Instr _ _ _ -> eval_code_eq_instr i f s1 s2 | Dealloc _ -> eval_code_eq_dealloc i f s1 s2 | Alloc _ -> eval_code_eq_alloc i f s1 s2 | Push _ _ -> eval_code_eq_push i f s1 s2 | Pop _ _ -> eval_code_eq_pop i f s1 s2 #reset-options "--fuel 2 --z3rlimit 30" let eval_ocmp_eq_core (g:bool) (cond:ocmp) (s:machine_state) : Lemma (ensures ( let (s1, b1) = BS.machine_eval_ocmp s cond in let (s2, b2) = BS.machine_eval_ocmp (core_state g s) cond in state_eq_S g s1 s2 /\ b1 == b2 )) = reveal_opaque (`%BS.valid_ocmp_opaque) BS.valid_ocmp_opaque; reveal_opaque (`%BS.eval_ocmp_opaque) BS.eval_ocmp_opaque; () #restart-solver let rec eval_code_eq_core (g:bool) (c:code) (f:fuel) (s:machine_state) : Lemma (ensures state_eq_opt g (BS.machine_eval_code c f s) (BS.machine_eval_code c f (core_state g s))) (decreases %[f; c]) = match c with | Ins i -> reveal_opaque (`%BS.machine_eval_code_ins) BS.machine_eval_code_ins; if g then eval_code_eq_ins i f s (core_state g s) | Block cs -> eval_codes_eq_core g cs f s | IfElse cond ct cf -> eval_ocmp_eq_core g cond s; let (s', _) = BS.machine_eval_ocmp s cond in let (t', _) = BS.machine_eval_ocmp (core_state g s) cond in eval_code_eq_core g ct f s'; eval_code_eq_core g ct f t'; eval_code_eq_core g cf f s'; eval_code_eq_core g cf f t'; () | While cond body -> eval_while_eq_core g cond body f s and eval_codes_eq_core (g:bool) (cs:codes) (f:fuel) (s:machine_state) : Lemma (ensures state_eq_opt g (BS.machine_eval_codes cs f s) (BS.machine_eval_codes cs f (core_state g s))) (decreases %[f; cs]) = match cs with | [] -> () | c'::cs' -> ( eval_code_eq_core g c' f s; match (machine_eval_code c' f s, machine_eval_code c' f (core_state g s)) with | (None, None) -> () | (Some s', Some t') -> eval_codes_eq_core g cs' f s'; eval_codes_eq_core g cs' f t' ) and eval_while_eq_core (g:bool) (cond:ocmp) (body:code) (f:fuel) (s:machine_state) : Lemma (ensures state_eq_opt g (BS.machine_eval_while cond body f s) (BS.machine_eval_while cond body f (core_state g s))) (decreases %[f; body]) = if f > 0 then ( eval_ocmp_eq_core g cond s; let (s1, _) = BS.machine_eval_ocmp s cond in let (t1, _) = BS.machine_eval_ocmp (core_state g s) cond in eval_code_eq_core g body (f - 1) s1; eval_code_eq_core g body (f - 1) t1; match (BS.machine_eval_code body (f - 1) s1, BS.machine_eval_code body (f - 1) t1) with | (None, None) -> () | (Some s2, Some t2) -> eval_while_eq_core g cond body (f - 1) s2; eval_while_eq_core g cond body (f - 1) t2; () ) let eval_code_eq_f (c:code) (f:fuel) (s1 s2:machine_state) : Lemma (requires state_eq_S false s1 s2) (ensures state_eq_opt false (BS.machine_eval_code c f s1) (BS.machine_eval_code c f s2)) [SMTPat (BS.machine_eval_code c f s1); SMTPat (BS.machine_eval_code c f s2)] = eval_code_eq_core false c f s1; eval_code_eq_core false c f s2 let eval_codes_eq_f (cs:codes) (f:fuel) (s1 s2:machine_state) : Lemma (requires state_eq_S false s1 s2) (ensures state_eq_opt false (BS.machine_eval_codes cs f s1) (BS.machine_eval_codes cs f s2)) [SMTPat (BS.machine_eval_codes cs f s1); SMTPat (BS.machine_eval_codes cs f s2)] = eval_codes_eq_core false cs f s1; eval_codes_eq_core false cs f s2 let eval_while_eq_f (cond:ocmp) (body:code) (f:fuel) (s1 s2:machine_state) : Lemma (requires state_eq_S false s1 s2) (ensures state_eq_opt false (BS.machine_eval_while cond body f s1) (BS.machine_eval_while cond body f s2)) [SMTPat (BS.machine_eval_while cond body f s1); SMTPat (BS.machine_eval_while cond body f s2)] = eval_while_eq_core false cond body f s1; eval_while_eq_core false cond body f s2 let eval_code_eq_t (c:code) (f:fuel) (s1 s2:machine_state) : Lemma (requires state_eq_S true s1 s2) (ensures state_eq_opt true (BS.machine_eval_code c f s1) (BS.machine_eval_code c f s2)) [SMTPat (BS.machine_eval_code c f s1); SMTPat (BS.machine_eval_code c f s2)] = eval_code_eq_core true c f s1; eval_code_eq_core true c f s2
{ "checked_file": "/", "dependencies": [ "Vale.X64.StateLemmas.fsti.checked", "Vale.X64.State.fsti.checked", "Vale.X64.Memory.fsti.checked", "Vale.X64.Machine_Semantics_s.fst.checked", "Vale.X64.Machine_s.fst.checked", "Vale.X64.Instruction_s.fsti.checked", "Vale.X64.Flags.fsti.checked", "Vale.X64.Bytes_Code_s.fst.checked", "prims.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.FunctionalExtensionality.fsti.checked" ], "interface_file": true, "source_file": "Vale.X64.Lemmas.fst" }
[ { "abbrev": true, "full_module": "Vale.X64.Memory", "short_module": "ME" }, { "abbrev": true, "full_module": "Vale.X64.Machine_Semantics_s", "short_module": "BS" }, { "abbrev": false, "full_module": "Vale.X64.Bytes_Code_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Instruction_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.StateLemmas", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.State", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Machine_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": true, "full_module": "Vale.Lib.Map16", "short_module": "Map16" }, { "abbrev": true, "full_module": "Vale.X64.Machine_Semantics_s", "short_module": "BS" }, { "abbrev": false, "full_module": "Vale.X64.Bytes_Code_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.StateLemmas", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.State", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Machine_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.HeapLemmas", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.HeapImpl", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.Heap", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 0, "max_fuel": 2, "max_ifuel": 1, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": true, "smtencoding_l_arith_repr": "native", "smtencoding_nl_arith_repr": "wrapped", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [ "smt.arith.nl=false", "smt.QI.EAGER_THRESHOLD=100", "smt.CASE_SPLIT=3" ], "z3refresh": false, "z3rlimit": 30, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
cs: Vale.X64.Lemmas.codes -> f: Vale.X64.Lemmas.fuel -> s1: Vale.X64.StateLemmas.machine_state -> s2: Vale.X64.StateLemmas.machine_state -> FStar.Pervasives.Lemma (requires Vale.X64.Lemmas.state_eq_S true s1 s2) (ensures Vale.X64.Lemmas.state_eq_opt true (Vale.X64.Machine_Semantics_s.machine_eval_codes cs f s1) (Vale.X64.Machine_Semantics_s.machine_eval_codes cs f s2)) [ SMTPat (Vale.X64.Machine_Semantics_s.machine_eval_codes cs f s1); SMTPat (Vale.X64.Machine_Semantics_s.machine_eval_codes cs f s2) ]
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "Vale.X64.Lemmas.codes", "Vale.X64.Lemmas.fuel", "Vale.X64.StateLemmas.machine_state", "Vale.X64.Lemmas.eval_codes_eq_core", "Prims.unit", "Vale.X64.Lemmas.state_eq_S", "Prims.squash", "Vale.X64.Lemmas.state_eq_opt", "Vale.X64.Machine_Semantics_s.machine_eval_codes", "Prims.Cons", "FStar.Pervasives.pattern", "FStar.Pervasives.smt_pat", "FStar.Pervasives.Native.option", "Vale.X64.Machine_Semantics_s.machine_state", "Prims.Nil" ]
[]
true
false
true
false
false
let eval_codes_eq_t (cs: codes) (f: fuel) (s1 s2: machine_state) : Lemma (requires state_eq_S true s1 s2) (ensures state_eq_opt true (BS.machine_eval_codes cs f s1) (BS.machine_eval_codes cs f s2)) [SMTPat (BS.machine_eval_codes cs f s1); SMTPat (BS.machine_eval_codes cs f s2)] =
eval_codes_eq_core true cs f s1; eval_codes_eq_core true cs f s2
false
Vale.X64.Lemmas.fst
Vale.X64.Lemmas.eval_code_eq_push
val eval_code_eq_push (inst: BS.ins) (f: fuel) (s1 s2: machine_state) : Lemma (requires Push? inst /\ state_eq_S true s1 s2) (ensures state_eq_opt true (BS.machine_eval_code (Ins inst) f s1) (BS.machine_eval_code (Ins inst) f s2))
val eval_code_eq_push (inst: BS.ins) (f: fuel) (s1 s2: machine_state) : Lemma (requires Push? inst /\ state_eq_S true s1 s2) (ensures state_eq_opt true (BS.machine_eval_code (Ins inst) f s1) (BS.machine_eval_code (Ins inst) f s2))
let eval_code_eq_push (inst:BS.ins) (f:fuel) (s1 s2:machine_state) : Lemma (requires Push? inst /\ state_eq_S true s1 s2) (ensures state_eq_opt true (BS.machine_eval_code (Ins inst) f s1) (BS.machine_eval_code (Ins inst) f s2)) = reveal_opaque (`%BS.machine_eval_code_ins) BS.machine_eval_code_ins; use_machine_state_equal (); lemma_heap_ignore_ghost_machine s1.BS.ms_heap s2.BS.ms_heap; allow_inversion tmaddr
{ "file_name": "vale/code/arch/x64/Vale.X64.Lemmas.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 24, "end_line": 168, "start_col": 0, "start_line": 161 }
module Vale.X64.Lemmas open FStar.Mul open Vale.X64.Machine_s open Vale.X64.State open Vale.X64.StateLemmas open Vale.X64.Instruction_s open Vale.X64.Bytes_Code_s module BS = Vale.X64.Machine_Semantics_s module ME = Vale.X64.Memory #reset-options "--initial_fuel 1 --max_fuel 1 --z3rlimit 100" #restart-solver let rec lemma_eq_instr_apply_eval_args (outs:list instr_out) (args:list instr_operand) (f:instr_args_t outs args) (oprs:instr_operands_t_args args) (s1 s2:machine_state) : Lemma (requires state_eq_S true s1 s2) (ensures BS.instr_apply_eval_args outs args f oprs s1 == BS.instr_apply_eval_args outs args f oprs s2) = let open BS in lemma_heap_ignore_ghost_machine s1.BS.ms_heap s2.BS.ms_heap; match args with | [] -> () | i::args -> ( let (v, oprs) : option (instr_val_t i) & instr_operands_t_args args = match i with | IOpEx i -> let oprs = coerce oprs in (instr_eval_operand_explicit i (fst oprs) s1, snd oprs) | IOpIm i -> (instr_eval_operand_implicit i s1, coerce oprs) in let f:arrow (instr_val_t i) (instr_args_t outs args) = coerce f in match v with | None -> () | Some v -> lemma_eq_instr_apply_eval_args outs args (f v) oprs s1 s2 ) #restart-solver let rec lemma_eq_instr_apply_eval_inouts (outs inouts:list instr_out) (args:list instr_operand) (f:instr_inouts_t outs inouts args) (oprs:instr_operands_t inouts args) (s1 s2:machine_state) : Lemma (requires state_eq_S true s1 s2) (ensures BS.instr_apply_eval_inouts outs inouts args f oprs s1 == BS.instr_apply_eval_inouts outs inouts args f oprs s2) = let open BS in lemma_heap_ignore_ghost_machine s1.BS.ms_heap s2.BS.ms_heap; match inouts with | [] -> lemma_eq_instr_apply_eval_args outs args f oprs s1 s2 | (Out, i)::inouts -> let oprs = match i with | IOpEx i -> snd #(instr_operand_t i) (coerce oprs) | IOpIm i -> coerce oprs in lemma_eq_instr_apply_eval_inouts outs inouts args (coerce f) oprs s1 s2 | (InOut, i)::inouts -> ( let (v, oprs) : option (instr_val_t i) & instr_operands_t inouts args = match i with | IOpEx i -> let oprs = coerce oprs in (instr_eval_operand_explicit i (fst oprs) s1, snd oprs) | IOpIm i -> (instr_eval_operand_implicit i s1, coerce oprs) in let f:arrow (instr_val_t i) (instr_inouts_t outs inouts args) = coerce f in match v with | None -> () | Some v -> lemma_eq_instr_apply_eval_inouts outs inouts args (f v) oprs s1 s2 ) #restart-solver #push-options "--z3rlimit_factor 2" let rec lemma_eq_instr_write_outputs (outs:list instr_out) (args:list instr_operand) (vs:instr_ret_t outs) (oprs:instr_operands_t outs args) (s1_orig s1 s2_orig s2:machine_state) : Lemma (requires state_eq_S true s1_orig s2_orig /\ state_eq_S true s1 s2) (ensures state_eq_S true (BS.instr_write_outputs outs args vs oprs s1_orig s1) (BS.instr_write_outputs outs args vs oprs s2_orig s2)) = let open BS in use_machine_state_equal (); lemma_heap_ignore_ghost_machine s1.BS.ms_heap s2.BS.ms_heap; lemma_heap_ignore_ghost_machine s1_orig.BS.ms_heap s2_orig.BS.ms_heap; allow_inversion tmaddr; match outs with | [] -> () | (_, i)::outs -> ( let ((v:instr_val_t i), (vs:instr_ret_t outs)) = match outs with | [] -> (vs, ()) | _::_ -> let vs = coerce vs in (fst vs, snd vs) in match i with | IOpEx i -> let oprs = coerce oprs in let s1 = instr_write_output_explicit i v (fst oprs) s1_orig s1 in let s2 = instr_write_output_explicit i v (fst oprs) s2_orig s2 in lemma_eq_instr_write_outputs outs args vs (snd oprs) s1_orig s1 s2_orig s2 | IOpIm i -> let s1 = instr_write_output_implicit i v s1_orig s1 in let s2 = instr_write_output_implicit i v s2_orig s2 in allow_inversion operand64; allow_inversion operand128; lemma_eq_instr_write_outputs outs args vs (coerce oprs) s1_orig s1 s2_orig s2 ) #pop-options #restart-solver let eval_ins_eq_instr (inst:BS.ins) (s1 s2:machine_state) : Lemma (requires Instr? inst /\ state_eq_S true s1 s2) (ensures state_eq_S true (BS.machine_eval_ins inst s1) (BS.machine_eval_ins inst s2)) = let open BS in let Instr it oprs ann = inst in let InstrTypeRecord #outs #args #havoc_flags' i = it in lemma_eq_instr_apply_eval_inouts outs outs args (instr_eval i) oprs s1 s2; let vs = instr_apply_eval outs args (instr_eval i) oprs s1 in let hav s = match havoc_flags' with | HavocFlags -> {s with ms_flags = havoc_flags} | PreserveFlags -> s in let s1' = hav s1 in let s2' = hav s2 in match vs with | None -> () | Some vs -> lemma_eq_instr_write_outputs outs args vs oprs s1 s1' s2 s2' let eval_code_eq_instr (inst:BS.ins) (f:fuel) (s1 s2:machine_state) : Lemma (requires Instr? inst /\ state_eq_S true s1 s2) (ensures state_eq_opt true (BS.machine_eval_code (Ins inst) f s1) (BS.machine_eval_code (Ins inst) f s2)) = reveal_opaque (`%BS.machine_eval_code_ins) BS.machine_eval_code_ins; eval_ins_eq_instr inst ({s1 with BS.ms_trace = []}) ({s2 with BS.ms_trace = []}) let eval_code_eq_dealloc (inst:BS.ins) (f:fuel) (s1 s2:machine_state) : Lemma (requires Dealloc? inst /\ state_eq_S true s1 s2) (ensures state_eq_opt true (BS.machine_eval_code (Ins inst) f s1) (BS.machine_eval_code (Ins inst) f s2)) = reveal_opaque (`%BS.machine_eval_code_ins) BS.machine_eval_code_ins; use_machine_state_equal (); lemma_heap_ignore_ghost_machine s1.BS.ms_heap s2.BS.ms_heap; allow_inversion tmaddr let eval_code_eq_alloc (inst:BS.ins) (f:fuel) (s1 s2:machine_state) : Lemma (requires Alloc? inst /\ state_eq_S true s1 s2) (ensures state_eq_opt true (BS.machine_eval_code (Ins inst) f s1) (BS.machine_eval_code (Ins inst) f s2)) = reveal_opaque (`%BS.machine_eval_code_ins) BS.machine_eval_code_ins; use_machine_state_equal (); lemma_heap_ignore_ghost_machine s1.BS.ms_heap s2.BS.ms_heap; allow_inversion tmaddr
{ "checked_file": "/", "dependencies": [ "Vale.X64.StateLemmas.fsti.checked", "Vale.X64.State.fsti.checked", "Vale.X64.Memory.fsti.checked", "Vale.X64.Machine_Semantics_s.fst.checked", "Vale.X64.Machine_s.fst.checked", "Vale.X64.Instruction_s.fsti.checked", "Vale.X64.Flags.fsti.checked", "Vale.X64.Bytes_Code_s.fst.checked", "prims.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.FunctionalExtensionality.fsti.checked" ], "interface_file": true, "source_file": "Vale.X64.Lemmas.fst" }
[ { "abbrev": true, "full_module": "Vale.X64.Memory", "short_module": "ME" }, { "abbrev": true, "full_module": "Vale.X64.Machine_Semantics_s", "short_module": "BS" }, { "abbrev": false, "full_module": "Vale.X64.Bytes_Code_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Instruction_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.StateLemmas", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.State", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Machine_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": true, "full_module": "Vale.Lib.Map16", "short_module": "Map16" }, { "abbrev": true, "full_module": "Vale.X64.Machine_Semantics_s", "short_module": "BS" }, { "abbrev": false, "full_module": "Vale.X64.Bytes_Code_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.StateLemmas", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.State", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Machine_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.HeapLemmas", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.HeapImpl", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.Heap", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 1, "initial_ifuel": 0, "max_fuel": 1, "max_ifuel": 1, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": true, "smtencoding_l_arith_repr": "native", "smtencoding_nl_arith_repr": "wrapped", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [ "smt.arith.nl=false", "smt.QI.EAGER_THRESHOLD=100", "smt.CASE_SPLIT=3" ], "z3refresh": false, "z3rlimit": 100, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
inst: Vale.X64.Machine_Semantics_s.ins -> f: Vale.X64.Lemmas.fuel -> s1: Vale.X64.StateLemmas.machine_state -> s2: Vale.X64.StateLemmas.machine_state -> FStar.Pervasives.Lemma (requires Push? inst /\ Vale.X64.Lemmas.state_eq_S true s1 s2) (ensures Vale.X64.Lemmas.state_eq_opt true (Vale.X64.Machine_Semantics_s.machine_eval_code (Vale.X64.Machine_s.Ins inst) f s1) (Vale.X64.Machine_Semantics_s.machine_eval_code (Vale.X64.Machine_s.Ins inst) f s2))
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "Vale.X64.Machine_Semantics_s.ins", "Vale.X64.Lemmas.fuel", "Vale.X64.StateLemmas.machine_state", "FStar.Pervasives.allow_inversion", "Vale.X64.Machine_s.tmaddr", "Prims.unit", "Vale.Arch.HeapLemmas.lemma_heap_ignore_ghost_machine", "Vale.X64.Machine_Semantics_s.__proj__Mkmachine_state__item__ms_heap", "Vale.X64.StateLemmas.use_machine_state_equal", "FStar.Pervasives.reveal_opaque", "Vale.X64.Machine_Semantics_s.machine_state", "FStar.Pervasives.Native.option", "Vale.X64.Machine_Semantics_s.machine_eval_code_ins", "Prims.l_and", "Prims.b2t", "Vale.X64.Bytes_Code_s.uu___is_Push", "Vale.X64.Machine_Semantics_s.instr_annotation", "Vale.X64.Lemmas.state_eq_S", "Prims.squash", "Vale.X64.Lemmas.state_eq_opt", "Vale.X64.Machine_Semantics_s.machine_eval_code", "Vale.X64.Machine_s.Ins", "Vale.X64.Bytes_Code_s.instruction_t", "Vale.X64.Bytes_Code_s.ocmp", "Prims.Nil", "FStar.Pervasives.pattern" ]
[]
true
false
true
false
false
let eval_code_eq_push (inst: BS.ins) (f: fuel) (s1 s2: machine_state) : Lemma (requires Push? inst /\ state_eq_S true s1 s2) (ensures state_eq_opt true (BS.machine_eval_code (Ins inst) f s1) (BS.machine_eval_code (Ins inst) f s2)) =
reveal_opaque (`%BS.machine_eval_code_ins) BS.machine_eval_code_ins; use_machine_state_equal (); lemma_heap_ignore_ghost_machine s1.BS.ms_heap s2.BS.ms_heap; allow_inversion tmaddr
false
Vale.X64.Lemmas.fst
Vale.X64.Lemmas.lemma_eq_instr_apply_eval_args
val lemma_eq_instr_apply_eval_args (outs: list instr_out) (args: list instr_operand) (f: instr_args_t outs args) (oprs: instr_operands_t_args args) (s1 s2: machine_state) : Lemma (requires state_eq_S true s1 s2) (ensures BS.instr_apply_eval_args outs args f oprs s1 == BS.instr_apply_eval_args outs args f oprs s2 )
val lemma_eq_instr_apply_eval_args (outs: list instr_out) (args: list instr_operand) (f: instr_args_t outs args) (oprs: instr_operands_t_args args) (s1 s2: machine_state) : Lemma (requires state_eq_S true s1 s2) (ensures BS.instr_apply_eval_args outs args f oprs s1 == BS.instr_apply_eval_args outs args f oprs s2 )
let rec lemma_eq_instr_apply_eval_args (outs:list instr_out) (args:list instr_operand) (f:instr_args_t outs args) (oprs:instr_operands_t_args args) (s1 s2:machine_state) : Lemma (requires state_eq_S true s1 s2) (ensures BS.instr_apply_eval_args outs args f oprs s1 == BS.instr_apply_eval_args outs args f oprs s2) = let open BS in lemma_heap_ignore_ghost_machine s1.BS.ms_heap s2.BS.ms_heap; match args with | [] -> () | i::args -> ( let (v, oprs) : option (instr_val_t i) & instr_operands_t_args args = match i with | IOpEx i -> let oprs = coerce oprs in (instr_eval_operand_explicit i (fst oprs) s1, snd oprs) | IOpIm i -> (instr_eval_operand_implicit i s1, coerce oprs) in let f:arrow (instr_val_t i) (instr_args_t outs args) = coerce f in match v with | None -> () | Some v -> lemma_eq_instr_apply_eval_args outs args (f v) oprs s1 s2 )
{ "file_name": "vale/code/arch/x64/Vale.X64.Lemmas.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 5, "end_line": 38, "start_col": 0, "start_line": 14 }
module Vale.X64.Lemmas open FStar.Mul open Vale.X64.Machine_s open Vale.X64.State open Vale.X64.StateLemmas open Vale.X64.Instruction_s open Vale.X64.Bytes_Code_s module BS = Vale.X64.Machine_Semantics_s module ME = Vale.X64.Memory #reset-options "--initial_fuel 1 --max_fuel 1 --z3rlimit 100"
{ "checked_file": "/", "dependencies": [ "Vale.X64.StateLemmas.fsti.checked", "Vale.X64.State.fsti.checked", "Vale.X64.Memory.fsti.checked", "Vale.X64.Machine_Semantics_s.fst.checked", "Vale.X64.Machine_s.fst.checked", "Vale.X64.Instruction_s.fsti.checked", "Vale.X64.Flags.fsti.checked", "Vale.X64.Bytes_Code_s.fst.checked", "prims.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.FunctionalExtensionality.fsti.checked" ], "interface_file": true, "source_file": "Vale.X64.Lemmas.fst" }
[ { "abbrev": true, "full_module": "Vale.X64.Memory", "short_module": "ME" }, { "abbrev": true, "full_module": "Vale.X64.Machine_Semantics_s", "short_module": "BS" }, { "abbrev": false, "full_module": "Vale.X64.Bytes_Code_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Instruction_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.StateLemmas", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.State", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Machine_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": true, "full_module": "Vale.Lib.Map16", "short_module": "Map16" }, { "abbrev": true, "full_module": "Vale.X64.Machine_Semantics_s", "short_module": "BS" }, { "abbrev": false, "full_module": "Vale.X64.Bytes_Code_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.StateLemmas", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.State", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Machine_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.HeapLemmas", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.HeapImpl", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.Heap", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 1, "initial_ifuel": 0, "max_fuel": 1, "max_ifuel": 1, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": true, "smtencoding_l_arith_repr": "native", "smtencoding_nl_arith_repr": "wrapped", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [ "smt.arith.nl=false", "smt.QI.EAGER_THRESHOLD=100", "smt.CASE_SPLIT=3" ], "z3refresh": false, "z3rlimit": 100, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
outs: Prims.list Vale.X64.Instruction_s.instr_out -> args: Prims.list Vale.X64.Instruction_s.instr_operand -> f: Vale.X64.Instruction_s.instr_args_t outs args -> oprs: Vale.X64.Instruction_s.instr_operands_t_args args -> s1: Vale.X64.StateLemmas.machine_state -> s2: Vale.X64.StateLemmas.machine_state -> FStar.Pervasives.Lemma (requires Vale.X64.Lemmas.state_eq_S true s1 s2) (ensures Vale.X64.Machine_Semantics_s.instr_apply_eval_args outs args f oprs s1 == Vale.X64.Machine_Semantics_s.instr_apply_eval_args outs args f oprs s2)
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "Prims.list", "Vale.X64.Instruction_s.instr_out", "Vale.X64.Instruction_s.instr_operand", "Vale.X64.Instruction_s.instr_args_t", "Vale.X64.Instruction_s.instr_operands_t_args", "Vale.X64.StateLemmas.machine_state", "FStar.Pervasives.Native.option", "Vale.X64.Instruction_s.instr_val_t", "Vale.X64.Lemmas.lemma_eq_instr_apply_eval_args", "Prims.unit", "Vale.X64.Instruction_s.arrow", "Vale.X64.Instruction_s.coerce", "FStar.Pervasives.Native.tuple2", "Vale.X64.Instruction_s.instr_operand_explicit", "FStar.Pervasives.Native.Mktuple2", "Vale.X64.Machine_Semantics_s.instr_eval_operand_explicit", "FStar.Pervasives.Native.fst", "Vale.X64.Instruction_s.instr_operand_t", "FStar.Pervasives.Native.snd", "Vale.X64.Instruction_s.instr_operand_implicit", "Vale.X64.Machine_Semantics_s.instr_eval_operand_implicit", "Vale.Arch.HeapLemmas.lemma_heap_ignore_ghost_machine", "Vale.X64.Machine_Semantics_s.__proj__Mkmachine_state__item__ms_heap", "Vale.X64.Lemmas.state_eq_S", "Prims.squash", "Prims.eq2", "Vale.X64.Instruction_s.instr_ret_t", "Vale.X64.Machine_Semantics_s.instr_apply_eval_args", "Prims.Nil", "FStar.Pervasives.pattern" ]
[ "recursion" ]
false
false
true
false
false
let rec lemma_eq_instr_apply_eval_args (outs: list instr_out) (args: list instr_operand) (f: instr_args_t outs args) (oprs: instr_operands_t_args args) (s1 s2: machine_state) : Lemma (requires state_eq_S true s1 s2) (ensures BS.instr_apply_eval_args outs args f oprs s1 == BS.instr_apply_eval_args outs args f oprs s2 ) =
let open BS in lemma_heap_ignore_ghost_machine s1.BS.ms_heap s2.BS.ms_heap; match args with | [] -> () | i :: args -> (let v, oprs:option (instr_val_t i) & instr_operands_t_args args = match i with | IOpEx i -> let oprs = coerce oprs in (instr_eval_operand_explicit i (fst oprs) s1, snd oprs) | IOpIm i -> (instr_eval_operand_implicit i s1, coerce oprs) in let f:arrow (instr_val_t i) (instr_args_t outs args) = coerce f in match v with | None -> () | Some v -> lemma_eq_instr_apply_eval_args outs args (f v) oprs s1 s2)
false
Vale.X64.Lemmas.fst
Vale.X64.Lemmas.eval_code_eq_dealloc
val eval_code_eq_dealloc (inst: BS.ins) (f: fuel) (s1 s2: machine_state) : Lemma (requires Dealloc? inst /\ state_eq_S true s1 s2) (ensures state_eq_opt true (BS.machine_eval_code (Ins inst) f s1) (BS.machine_eval_code (Ins inst) f s2))
val eval_code_eq_dealloc (inst: BS.ins) (f: fuel) (s1 s2: machine_state) : Lemma (requires Dealloc? inst /\ state_eq_S true s1 s2) (ensures state_eq_opt true (BS.machine_eval_code (Ins inst) f s1) (BS.machine_eval_code (Ins inst) f s2))
let eval_code_eq_dealloc (inst:BS.ins) (f:fuel) (s1 s2:machine_state) : Lemma (requires Dealloc? inst /\ state_eq_S true s1 s2) (ensures state_eq_opt true (BS.machine_eval_code (Ins inst) f s1) (BS.machine_eval_code (Ins inst) f s2)) = reveal_opaque (`%BS.machine_eval_code_ins) BS.machine_eval_code_ins; use_machine_state_equal (); lemma_heap_ignore_ghost_machine s1.BS.ms_heap s2.BS.ms_heap; allow_inversion tmaddr
{ "file_name": "vale/code/arch/x64/Vale.X64.Lemmas.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 24, "end_line": 150, "start_col": 0, "start_line": 143 }
module Vale.X64.Lemmas open FStar.Mul open Vale.X64.Machine_s open Vale.X64.State open Vale.X64.StateLemmas open Vale.X64.Instruction_s open Vale.X64.Bytes_Code_s module BS = Vale.X64.Machine_Semantics_s module ME = Vale.X64.Memory #reset-options "--initial_fuel 1 --max_fuel 1 --z3rlimit 100" #restart-solver let rec lemma_eq_instr_apply_eval_args (outs:list instr_out) (args:list instr_operand) (f:instr_args_t outs args) (oprs:instr_operands_t_args args) (s1 s2:machine_state) : Lemma (requires state_eq_S true s1 s2) (ensures BS.instr_apply_eval_args outs args f oprs s1 == BS.instr_apply_eval_args outs args f oprs s2) = let open BS in lemma_heap_ignore_ghost_machine s1.BS.ms_heap s2.BS.ms_heap; match args with | [] -> () | i::args -> ( let (v, oprs) : option (instr_val_t i) & instr_operands_t_args args = match i with | IOpEx i -> let oprs = coerce oprs in (instr_eval_operand_explicit i (fst oprs) s1, snd oprs) | IOpIm i -> (instr_eval_operand_implicit i s1, coerce oprs) in let f:arrow (instr_val_t i) (instr_args_t outs args) = coerce f in match v with | None -> () | Some v -> lemma_eq_instr_apply_eval_args outs args (f v) oprs s1 s2 ) #restart-solver let rec lemma_eq_instr_apply_eval_inouts (outs inouts:list instr_out) (args:list instr_operand) (f:instr_inouts_t outs inouts args) (oprs:instr_operands_t inouts args) (s1 s2:machine_state) : Lemma (requires state_eq_S true s1 s2) (ensures BS.instr_apply_eval_inouts outs inouts args f oprs s1 == BS.instr_apply_eval_inouts outs inouts args f oprs s2) = let open BS in lemma_heap_ignore_ghost_machine s1.BS.ms_heap s2.BS.ms_heap; match inouts with | [] -> lemma_eq_instr_apply_eval_args outs args f oprs s1 s2 | (Out, i)::inouts -> let oprs = match i with | IOpEx i -> snd #(instr_operand_t i) (coerce oprs) | IOpIm i -> coerce oprs in lemma_eq_instr_apply_eval_inouts outs inouts args (coerce f) oprs s1 s2 | (InOut, i)::inouts -> ( let (v, oprs) : option (instr_val_t i) & instr_operands_t inouts args = match i with | IOpEx i -> let oprs = coerce oprs in (instr_eval_operand_explicit i (fst oprs) s1, snd oprs) | IOpIm i -> (instr_eval_operand_implicit i s1, coerce oprs) in let f:arrow (instr_val_t i) (instr_inouts_t outs inouts args) = coerce f in match v with | None -> () | Some v -> lemma_eq_instr_apply_eval_inouts outs inouts args (f v) oprs s1 s2 ) #restart-solver #push-options "--z3rlimit_factor 2" let rec lemma_eq_instr_write_outputs (outs:list instr_out) (args:list instr_operand) (vs:instr_ret_t outs) (oprs:instr_operands_t outs args) (s1_orig s1 s2_orig s2:machine_state) : Lemma (requires state_eq_S true s1_orig s2_orig /\ state_eq_S true s1 s2) (ensures state_eq_S true (BS.instr_write_outputs outs args vs oprs s1_orig s1) (BS.instr_write_outputs outs args vs oprs s2_orig s2)) = let open BS in use_machine_state_equal (); lemma_heap_ignore_ghost_machine s1.BS.ms_heap s2.BS.ms_heap; lemma_heap_ignore_ghost_machine s1_orig.BS.ms_heap s2_orig.BS.ms_heap; allow_inversion tmaddr; match outs with | [] -> () | (_, i)::outs -> ( let ((v:instr_val_t i), (vs:instr_ret_t outs)) = match outs with | [] -> (vs, ()) | _::_ -> let vs = coerce vs in (fst vs, snd vs) in match i with | IOpEx i -> let oprs = coerce oprs in let s1 = instr_write_output_explicit i v (fst oprs) s1_orig s1 in let s2 = instr_write_output_explicit i v (fst oprs) s2_orig s2 in lemma_eq_instr_write_outputs outs args vs (snd oprs) s1_orig s1 s2_orig s2 | IOpIm i -> let s1 = instr_write_output_implicit i v s1_orig s1 in let s2 = instr_write_output_implicit i v s2_orig s2 in allow_inversion operand64; allow_inversion operand128; lemma_eq_instr_write_outputs outs args vs (coerce oprs) s1_orig s1 s2_orig s2 ) #pop-options #restart-solver let eval_ins_eq_instr (inst:BS.ins) (s1 s2:machine_state) : Lemma (requires Instr? inst /\ state_eq_S true s1 s2) (ensures state_eq_S true (BS.machine_eval_ins inst s1) (BS.machine_eval_ins inst s2)) = let open BS in let Instr it oprs ann = inst in let InstrTypeRecord #outs #args #havoc_flags' i = it in lemma_eq_instr_apply_eval_inouts outs outs args (instr_eval i) oprs s1 s2; let vs = instr_apply_eval outs args (instr_eval i) oprs s1 in let hav s = match havoc_flags' with | HavocFlags -> {s with ms_flags = havoc_flags} | PreserveFlags -> s in let s1' = hav s1 in let s2' = hav s2 in match vs with | None -> () | Some vs -> lemma_eq_instr_write_outputs outs args vs oprs s1 s1' s2 s2' let eval_code_eq_instr (inst:BS.ins) (f:fuel) (s1 s2:machine_state) : Lemma (requires Instr? inst /\ state_eq_S true s1 s2) (ensures state_eq_opt true (BS.machine_eval_code (Ins inst) f s1) (BS.machine_eval_code (Ins inst) f s2)) = reveal_opaque (`%BS.machine_eval_code_ins) BS.machine_eval_code_ins; eval_ins_eq_instr inst ({s1 with BS.ms_trace = []}) ({s2 with BS.ms_trace = []})
{ "checked_file": "/", "dependencies": [ "Vale.X64.StateLemmas.fsti.checked", "Vale.X64.State.fsti.checked", "Vale.X64.Memory.fsti.checked", "Vale.X64.Machine_Semantics_s.fst.checked", "Vale.X64.Machine_s.fst.checked", "Vale.X64.Instruction_s.fsti.checked", "Vale.X64.Flags.fsti.checked", "Vale.X64.Bytes_Code_s.fst.checked", "prims.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.FunctionalExtensionality.fsti.checked" ], "interface_file": true, "source_file": "Vale.X64.Lemmas.fst" }
[ { "abbrev": true, "full_module": "Vale.X64.Memory", "short_module": "ME" }, { "abbrev": true, "full_module": "Vale.X64.Machine_Semantics_s", "short_module": "BS" }, { "abbrev": false, "full_module": "Vale.X64.Bytes_Code_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Instruction_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.StateLemmas", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.State", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Machine_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": true, "full_module": "Vale.Lib.Map16", "short_module": "Map16" }, { "abbrev": true, "full_module": "Vale.X64.Machine_Semantics_s", "short_module": "BS" }, { "abbrev": false, "full_module": "Vale.X64.Bytes_Code_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.StateLemmas", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.State", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Machine_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.HeapLemmas", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.HeapImpl", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.Heap", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 1, "initial_ifuel": 0, "max_fuel": 1, "max_ifuel": 1, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": true, "smtencoding_l_arith_repr": "native", "smtencoding_nl_arith_repr": "wrapped", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [ "smt.arith.nl=false", "smt.QI.EAGER_THRESHOLD=100", "smt.CASE_SPLIT=3" ], "z3refresh": false, "z3rlimit": 100, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
inst: Vale.X64.Machine_Semantics_s.ins -> f: Vale.X64.Lemmas.fuel -> s1: Vale.X64.StateLemmas.machine_state -> s2: Vale.X64.StateLemmas.machine_state -> FStar.Pervasives.Lemma (requires Dealloc? inst /\ Vale.X64.Lemmas.state_eq_S true s1 s2) (ensures Vale.X64.Lemmas.state_eq_opt true (Vale.X64.Machine_Semantics_s.machine_eval_code (Vale.X64.Machine_s.Ins inst) f s1) (Vale.X64.Machine_Semantics_s.machine_eval_code (Vale.X64.Machine_s.Ins inst) f s2))
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "Vale.X64.Machine_Semantics_s.ins", "Vale.X64.Lemmas.fuel", "Vale.X64.StateLemmas.machine_state", "FStar.Pervasives.allow_inversion", "Vale.X64.Machine_s.tmaddr", "Prims.unit", "Vale.Arch.HeapLemmas.lemma_heap_ignore_ghost_machine", "Vale.X64.Machine_Semantics_s.__proj__Mkmachine_state__item__ms_heap", "Vale.X64.StateLemmas.use_machine_state_equal", "FStar.Pervasives.reveal_opaque", "Vale.X64.Machine_Semantics_s.machine_state", "FStar.Pervasives.Native.option", "Vale.X64.Machine_Semantics_s.machine_eval_code_ins", "Prims.l_and", "Prims.b2t", "Vale.X64.Bytes_Code_s.uu___is_Dealloc", "Vale.X64.Machine_Semantics_s.instr_annotation", "Vale.X64.Lemmas.state_eq_S", "Prims.squash", "Vale.X64.Lemmas.state_eq_opt", "Vale.X64.Machine_Semantics_s.machine_eval_code", "Vale.X64.Machine_s.Ins", "Vale.X64.Bytes_Code_s.instruction_t", "Vale.X64.Bytes_Code_s.ocmp", "Prims.Nil", "FStar.Pervasives.pattern" ]
[]
true
false
true
false
false
let eval_code_eq_dealloc (inst: BS.ins) (f: fuel) (s1 s2: machine_state) : Lemma (requires Dealloc? inst /\ state_eq_S true s1 s2) (ensures state_eq_opt true (BS.machine_eval_code (Ins inst) f s1) (BS.machine_eval_code (Ins inst) f s2)) =
reveal_opaque (`%BS.machine_eval_code_ins) BS.machine_eval_code_ins; use_machine_state_equal (); lemma_heap_ignore_ghost_machine s1.BS.ms_heap s2.BS.ms_heap; allow_inversion tmaddr
false
Vale.X64.Lemmas.fst
Vale.X64.Lemmas.lemma_cmp_ne
val lemma_cmp_ne (s:vale_state) (o1:operand64{not (OMem? o1 || OStack? o1)}) (o2:operand64{not (OMem? o2 || OStack? o2)}) : Lemma (ensures eval_ocmp s (ONe o1 o2) <==> eval_operand o1 s <> eval_operand o2 s) [SMTPat (eval_ocmp s (ONe o1 o2))]
val lemma_cmp_ne (s:vale_state) (o1:operand64{not (OMem? o1 || OStack? o1)}) (o2:operand64{not (OMem? o2 || OStack? o2)}) : Lemma (ensures eval_ocmp s (ONe o1 o2) <==> eval_operand o1 s <> eval_operand o2 s) [SMTPat (eval_ocmp s (ONe o1 o2))]
let lemma_cmp_ne s o1 o2 = reveal_opaque (`%BS.eval_ocmp_opaque) BS.eval_ocmp_opaque
{ "file_name": "vale/code/arch/x64/Vale.X64.Lemmas.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 84, "end_line": 334, "start_col": 0, "start_line": 334 }
module Vale.X64.Lemmas open FStar.Mul open Vale.X64.Machine_s open Vale.X64.State open Vale.X64.StateLemmas open Vale.X64.Instruction_s open Vale.X64.Bytes_Code_s module BS = Vale.X64.Machine_Semantics_s module ME = Vale.X64.Memory #reset-options "--initial_fuel 1 --max_fuel 1 --z3rlimit 100" #restart-solver let rec lemma_eq_instr_apply_eval_args (outs:list instr_out) (args:list instr_operand) (f:instr_args_t outs args) (oprs:instr_operands_t_args args) (s1 s2:machine_state) : Lemma (requires state_eq_S true s1 s2) (ensures BS.instr_apply_eval_args outs args f oprs s1 == BS.instr_apply_eval_args outs args f oprs s2) = let open BS in lemma_heap_ignore_ghost_machine s1.BS.ms_heap s2.BS.ms_heap; match args with | [] -> () | i::args -> ( let (v, oprs) : option (instr_val_t i) & instr_operands_t_args args = match i with | IOpEx i -> let oprs = coerce oprs in (instr_eval_operand_explicit i (fst oprs) s1, snd oprs) | IOpIm i -> (instr_eval_operand_implicit i s1, coerce oprs) in let f:arrow (instr_val_t i) (instr_args_t outs args) = coerce f in match v with | None -> () | Some v -> lemma_eq_instr_apply_eval_args outs args (f v) oprs s1 s2 ) #restart-solver let rec lemma_eq_instr_apply_eval_inouts (outs inouts:list instr_out) (args:list instr_operand) (f:instr_inouts_t outs inouts args) (oprs:instr_operands_t inouts args) (s1 s2:machine_state) : Lemma (requires state_eq_S true s1 s2) (ensures BS.instr_apply_eval_inouts outs inouts args f oprs s1 == BS.instr_apply_eval_inouts outs inouts args f oprs s2) = let open BS in lemma_heap_ignore_ghost_machine s1.BS.ms_heap s2.BS.ms_heap; match inouts with | [] -> lemma_eq_instr_apply_eval_args outs args f oprs s1 s2 | (Out, i)::inouts -> let oprs = match i with | IOpEx i -> snd #(instr_operand_t i) (coerce oprs) | IOpIm i -> coerce oprs in lemma_eq_instr_apply_eval_inouts outs inouts args (coerce f) oprs s1 s2 | (InOut, i)::inouts -> ( let (v, oprs) : option (instr_val_t i) & instr_operands_t inouts args = match i with | IOpEx i -> let oprs = coerce oprs in (instr_eval_operand_explicit i (fst oprs) s1, snd oprs) | IOpIm i -> (instr_eval_operand_implicit i s1, coerce oprs) in let f:arrow (instr_val_t i) (instr_inouts_t outs inouts args) = coerce f in match v with | None -> () | Some v -> lemma_eq_instr_apply_eval_inouts outs inouts args (f v) oprs s1 s2 ) #restart-solver #push-options "--z3rlimit_factor 2" let rec lemma_eq_instr_write_outputs (outs:list instr_out) (args:list instr_operand) (vs:instr_ret_t outs) (oprs:instr_operands_t outs args) (s1_orig s1 s2_orig s2:machine_state) : Lemma (requires state_eq_S true s1_orig s2_orig /\ state_eq_S true s1 s2) (ensures state_eq_S true (BS.instr_write_outputs outs args vs oprs s1_orig s1) (BS.instr_write_outputs outs args vs oprs s2_orig s2)) = let open BS in use_machine_state_equal (); lemma_heap_ignore_ghost_machine s1.BS.ms_heap s2.BS.ms_heap; lemma_heap_ignore_ghost_machine s1_orig.BS.ms_heap s2_orig.BS.ms_heap; allow_inversion tmaddr; match outs with | [] -> () | (_, i)::outs -> ( let ((v:instr_val_t i), (vs:instr_ret_t outs)) = match outs with | [] -> (vs, ()) | _::_ -> let vs = coerce vs in (fst vs, snd vs) in match i with | IOpEx i -> let oprs = coerce oprs in let s1 = instr_write_output_explicit i v (fst oprs) s1_orig s1 in let s2 = instr_write_output_explicit i v (fst oprs) s2_orig s2 in lemma_eq_instr_write_outputs outs args vs (snd oprs) s1_orig s1 s2_orig s2 | IOpIm i -> let s1 = instr_write_output_implicit i v s1_orig s1 in let s2 = instr_write_output_implicit i v s2_orig s2 in allow_inversion operand64; allow_inversion operand128; lemma_eq_instr_write_outputs outs args vs (coerce oprs) s1_orig s1 s2_orig s2 ) #pop-options #restart-solver let eval_ins_eq_instr (inst:BS.ins) (s1 s2:machine_state) : Lemma (requires Instr? inst /\ state_eq_S true s1 s2) (ensures state_eq_S true (BS.machine_eval_ins inst s1) (BS.machine_eval_ins inst s2)) = let open BS in let Instr it oprs ann = inst in let InstrTypeRecord #outs #args #havoc_flags' i = it in lemma_eq_instr_apply_eval_inouts outs outs args (instr_eval i) oprs s1 s2; let vs = instr_apply_eval outs args (instr_eval i) oprs s1 in let hav s = match havoc_flags' with | HavocFlags -> {s with ms_flags = havoc_flags} | PreserveFlags -> s in let s1' = hav s1 in let s2' = hav s2 in match vs with | None -> () | Some vs -> lemma_eq_instr_write_outputs outs args vs oprs s1 s1' s2 s2' let eval_code_eq_instr (inst:BS.ins) (f:fuel) (s1 s2:machine_state) : Lemma (requires Instr? inst /\ state_eq_S true s1 s2) (ensures state_eq_opt true (BS.machine_eval_code (Ins inst) f s1) (BS.machine_eval_code (Ins inst) f s2)) = reveal_opaque (`%BS.machine_eval_code_ins) BS.machine_eval_code_ins; eval_ins_eq_instr inst ({s1 with BS.ms_trace = []}) ({s2 with BS.ms_trace = []}) let eval_code_eq_dealloc (inst:BS.ins) (f:fuel) (s1 s2:machine_state) : Lemma (requires Dealloc? inst /\ state_eq_S true s1 s2) (ensures state_eq_opt true (BS.machine_eval_code (Ins inst) f s1) (BS.machine_eval_code (Ins inst) f s2)) = reveal_opaque (`%BS.machine_eval_code_ins) BS.machine_eval_code_ins; use_machine_state_equal (); lemma_heap_ignore_ghost_machine s1.BS.ms_heap s2.BS.ms_heap; allow_inversion tmaddr let eval_code_eq_alloc (inst:BS.ins) (f:fuel) (s1 s2:machine_state) : Lemma (requires Alloc? inst /\ state_eq_S true s1 s2) (ensures state_eq_opt true (BS.machine_eval_code (Ins inst) f s1) (BS.machine_eval_code (Ins inst) f s2)) = reveal_opaque (`%BS.machine_eval_code_ins) BS.machine_eval_code_ins; use_machine_state_equal (); lemma_heap_ignore_ghost_machine s1.BS.ms_heap s2.BS.ms_heap; allow_inversion tmaddr let eval_code_eq_push (inst:BS.ins) (f:fuel) (s1 s2:machine_state) : Lemma (requires Push? inst /\ state_eq_S true s1 s2) (ensures state_eq_opt true (BS.machine_eval_code (Ins inst) f s1) (BS.machine_eval_code (Ins inst) f s2)) = reveal_opaque (`%BS.machine_eval_code_ins) BS.machine_eval_code_ins; use_machine_state_equal (); lemma_heap_ignore_ghost_machine s1.BS.ms_heap s2.BS.ms_heap; allow_inversion tmaddr let eval_code_eq_pop (inst:BS.ins) (f:fuel) (s1 s2:machine_state) : Lemma (requires Pop? inst /\ state_eq_S true s1 s2) (ensures state_eq_opt true (BS.machine_eval_code (Ins inst) f s1) (BS.machine_eval_code (Ins inst) f s2)) = reveal_opaque (`%BS.machine_eval_code_ins) BS.machine_eval_code_ins; use_machine_state_equal (); lemma_heap_ignore_ghost_machine s1.BS.ms_heap s2.BS.ms_heap; allow_inversion tmaddr let eval_code_eq_ins (i:BS.ins) (f:fuel) (s1 s2:machine_state) : Lemma (requires state_eq_S true s1 s2) (ensures state_eq_opt true (BS.machine_eval_code (Ins i) f s1) (BS.machine_eval_code (Ins i) f s2)) = match i with | Instr _ _ _ -> eval_code_eq_instr i f s1 s2 | Dealloc _ -> eval_code_eq_dealloc i f s1 s2 | Alloc _ -> eval_code_eq_alloc i f s1 s2 | Push _ _ -> eval_code_eq_push i f s1 s2 | Pop _ _ -> eval_code_eq_pop i f s1 s2 #reset-options "--fuel 2 --z3rlimit 30" let eval_ocmp_eq_core (g:bool) (cond:ocmp) (s:machine_state) : Lemma (ensures ( let (s1, b1) = BS.machine_eval_ocmp s cond in let (s2, b2) = BS.machine_eval_ocmp (core_state g s) cond in state_eq_S g s1 s2 /\ b1 == b2 )) = reveal_opaque (`%BS.valid_ocmp_opaque) BS.valid_ocmp_opaque; reveal_opaque (`%BS.eval_ocmp_opaque) BS.eval_ocmp_opaque; () #restart-solver let rec eval_code_eq_core (g:bool) (c:code) (f:fuel) (s:machine_state) : Lemma (ensures state_eq_opt g (BS.machine_eval_code c f s) (BS.machine_eval_code c f (core_state g s))) (decreases %[f; c]) = match c with | Ins i -> reveal_opaque (`%BS.machine_eval_code_ins) BS.machine_eval_code_ins; if g then eval_code_eq_ins i f s (core_state g s) | Block cs -> eval_codes_eq_core g cs f s | IfElse cond ct cf -> eval_ocmp_eq_core g cond s; let (s', _) = BS.machine_eval_ocmp s cond in let (t', _) = BS.machine_eval_ocmp (core_state g s) cond in eval_code_eq_core g ct f s'; eval_code_eq_core g ct f t'; eval_code_eq_core g cf f s'; eval_code_eq_core g cf f t'; () | While cond body -> eval_while_eq_core g cond body f s and eval_codes_eq_core (g:bool) (cs:codes) (f:fuel) (s:machine_state) : Lemma (ensures state_eq_opt g (BS.machine_eval_codes cs f s) (BS.machine_eval_codes cs f (core_state g s))) (decreases %[f; cs]) = match cs with | [] -> () | c'::cs' -> ( eval_code_eq_core g c' f s; match (machine_eval_code c' f s, machine_eval_code c' f (core_state g s)) with | (None, None) -> () | (Some s', Some t') -> eval_codes_eq_core g cs' f s'; eval_codes_eq_core g cs' f t' ) and eval_while_eq_core (g:bool) (cond:ocmp) (body:code) (f:fuel) (s:machine_state) : Lemma (ensures state_eq_opt g (BS.machine_eval_while cond body f s) (BS.machine_eval_while cond body f (core_state g s))) (decreases %[f; body]) = if f > 0 then ( eval_ocmp_eq_core g cond s; let (s1, _) = BS.machine_eval_ocmp s cond in let (t1, _) = BS.machine_eval_ocmp (core_state g s) cond in eval_code_eq_core g body (f - 1) s1; eval_code_eq_core g body (f - 1) t1; match (BS.machine_eval_code body (f - 1) s1, BS.machine_eval_code body (f - 1) t1) with | (None, None) -> () | (Some s2, Some t2) -> eval_while_eq_core g cond body (f - 1) s2; eval_while_eq_core g cond body (f - 1) t2; () ) let eval_code_eq_f (c:code) (f:fuel) (s1 s2:machine_state) : Lemma (requires state_eq_S false s1 s2) (ensures state_eq_opt false (BS.machine_eval_code c f s1) (BS.machine_eval_code c f s2)) [SMTPat (BS.machine_eval_code c f s1); SMTPat (BS.machine_eval_code c f s2)] = eval_code_eq_core false c f s1; eval_code_eq_core false c f s2 let eval_codes_eq_f (cs:codes) (f:fuel) (s1 s2:machine_state) : Lemma (requires state_eq_S false s1 s2) (ensures state_eq_opt false (BS.machine_eval_codes cs f s1) (BS.machine_eval_codes cs f s2)) [SMTPat (BS.machine_eval_codes cs f s1); SMTPat (BS.machine_eval_codes cs f s2)] = eval_codes_eq_core false cs f s1; eval_codes_eq_core false cs f s2 let eval_while_eq_f (cond:ocmp) (body:code) (f:fuel) (s1 s2:machine_state) : Lemma (requires state_eq_S false s1 s2) (ensures state_eq_opt false (BS.machine_eval_while cond body f s1) (BS.machine_eval_while cond body f s2)) [SMTPat (BS.machine_eval_while cond body f s1); SMTPat (BS.machine_eval_while cond body f s2)] = eval_while_eq_core false cond body f s1; eval_while_eq_core false cond body f s2 let eval_code_eq_t (c:code) (f:fuel) (s1 s2:machine_state) : Lemma (requires state_eq_S true s1 s2) (ensures state_eq_opt true (BS.machine_eval_code c f s1) (BS.machine_eval_code c f s2)) [SMTPat (BS.machine_eval_code c f s1); SMTPat (BS.machine_eval_code c f s2)] = eval_code_eq_core true c f s1; eval_code_eq_core true c f s2 let eval_codes_eq_t (cs:codes) (f:fuel) (s1 s2:machine_state) : Lemma (requires state_eq_S true s1 s2) (ensures state_eq_opt true (BS.machine_eval_codes cs f s1) (BS.machine_eval_codes cs f s2)) [SMTPat (BS.machine_eval_codes cs f s1); SMTPat (BS.machine_eval_codes cs f s2)] = eval_codes_eq_core true cs f s1; eval_codes_eq_core true cs f s2 let eval_while_eq_t (cond:ocmp) (body:code) (f:fuel) (s1 s2:machine_state) : Lemma (requires state_eq_S true s1 s2) (ensures state_eq_opt true (BS.machine_eval_while cond body f s1) (BS.machine_eval_while cond body f s2)) [SMTPat (BS.machine_eval_while cond body f s1); SMTPat (BS.machine_eval_while cond body f s2)] = eval_while_eq_core true cond body f s1; eval_while_eq_core true cond body f s2 let eval_code_ts (g:bool) (c:code) (s0:machine_state) (f0:fuel) (s1:machine_state) : Type0 = state_eq_opt g (BS.machine_eval_code c f0 s0) (Some s1) let rec increase_fuel (g:bool) (c:code) (s0:machine_state) (f0:fuel) (sN:machine_state) (fN:fuel) : Lemma (requires eval_code_ts g c s0 f0 sN /\ f0 <= fN) (ensures eval_code_ts g c s0 fN sN) (decreases %[f0; c]) = match c with | Ins ins -> () | Block l -> increase_fuels g l s0 f0 sN fN | IfElse cond t f -> let (s0, b0) = BS.machine_eval_ocmp s0 cond in if b0 then increase_fuel g t s0 f0 sN fN else increase_fuel g f s0 f0 sN fN | While cond c -> let (s1, b0) = BS.machine_eval_ocmp s0 cond in if b0 then ( match BS.machine_eval_code c (f0 - 1) s1 with | None -> () | Some s2 -> increase_fuel g c s1 (f0 - 1) s2 (fN - 1); if s2.BS.ms_ok then increase_fuel g (While cond c) s2 (f0 - 1) sN (fN - 1) else () ) and increase_fuels (g:bool) (c:codes) (s0:machine_state) (f0:fuel) (sN:machine_state) (fN:fuel) : Lemma (requires eval_code_ts g (Block c) s0 f0 sN /\ f0 <= fN) (ensures eval_code_ts g (Block c) s0 fN sN) (decreases %[f0; c]) = match c with | [] -> () | h::t -> ( let Some s1 = BS.machine_eval_code h f0 s0 in increase_fuel g h s0 f0 s1 fN; increase_fuels g t s1 f0 sN fN )
{ "checked_file": "/", "dependencies": [ "Vale.X64.StateLemmas.fsti.checked", "Vale.X64.State.fsti.checked", "Vale.X64.Memory.fsti.checked", "Vale.X64.Machine_Semantics_s.fst.checked", "Vale.X64.Machine_s.fst.checked", "Vale.X64.Instruction_s.fsti.checked", "Vale.X64.Flags.fsti.checked", "Vale.X64.Bytes_Code_s.fst.checked", "prims.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.FunctionalExtensionality.fsti.checked" ], "interface_file": true, "source_file": "Vale.X64.Lemmas.fst" }
[ { "abbrev": true, "full_module": "Vale.X64.Memory", "short_module": "ME" }, { "abbrev": true, "full_module": "Vale.X64.Machine_Semantics_s", "short_module": "BS" }, { "abbrev": false, "full_module": "Vale.X64.Bytes_Code_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Instruction_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.StateLemmas", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.State", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Machine_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": true, "full_module": "Vale.Lib.Map16", "short_module": "Map16" }, { "abbrev": true, "full_module": "Vale.X64.Machine_Semantics_s", "short_module": "BS" }, { "abbrev": false, "full_module": "Vale.X64.Bytes_Code_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.StateLemmas", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.State", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Machine_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.HeapLemmas", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.HeapImpl", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.Heap", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 0, "max_fuel": 2, "max_ifuel": 1, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": true, "smtencoding_l_arith_repr": "native", "smtencoding_nl_arith_repr": "wrapped", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [ "smt.arith.nl=false", "smt.QI.EAGER_THRESHOLD=100", "smt.CASE_SPLIT=3" ], "z3refresh": false, "z3rlimit": 30, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
s: Vale.X64.State.vale_state -> o1: Vale.X64.Machine_s.operand64{Prims.op_Negation (OMem? o1 || OStack? o1)} -> o2: Vale.X64.Machine_s.operand64{Prims.op_Negation (OMem? o2 || OStack? o2)} -> FStar.Pervasives.Lemma (ensures Vale.X64.Lemmas.eval_ocmp s (Vale.X64.Bytes_Code_s.ONe o1 o2) <==> Vale.X64.State.eval_operand o1 s <> Vale.X64.State.eval_operand o2 s) [SMTPat (Vale.X64.Lemmas.eval_ocmp s (Vale.X64.Bytes_Code_s.ONe o1 o2))]
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "Vale.X64.State.vale_state", "Vale.X64.Machine_s.operand64", "Prims.b2t", "Prims.op_Negation", "Prims.op_BarBar", "Vale.X64.Machine_s.uu___is_OMem", "Vale.X64.Machine_s.nat64", "Vale.X64.Machine_s.reg_64", "Vale.X64.Machine_s.uu___is_OStack", "FStar.Pervasives.reveal_opaque", "Vale.X64.Machine_Semantics_s.machine_state", "Vale.X64.Machine_Semantics_s.ocmp", "Prims.bool", "Vale.X64.Machine_Semantics_s.eval_ocmp_opaque", "Prims.unit" ]
[]
true
false
true
false
false
let lemma_cmp_ne s o1 o2 =
reveal_opaque (`%BS.eval_ocmp_opaque) BS.eval_ocmp_opaque
false
Vale.X64.Lemmas.fst
Vale.X64.Lemmas.lemma_cmp_eq
val lemma_cmp_eq (s:vale_state) (o1:operand64{not (OMem? o1 || OStack? o1)}) (o2:operand64{not (OMem? o2 || OStack? o2)}) : Lemma (ensures eval_ocmp s (OEq o1 o2) <==> eval_operand o1 s == eval_operand o2 s) [SMTPat (eval_ocmp s (OEq o1 o2))]
val lemma_cmp_eq (s:vale_state) (o1:operand64{not (OMem? o1 || OStack? o1)}) (o2:operand64{not (OMem? o2 || OStack? o2)}) : Lemma (ensures eval_ocmp s (OEq o1 o2) <==> eval_operand o1 s == eval_operand o2 s) [SMTPat (eval_ocmp s (OEq o1 o2))]
let lemma_cmp_eq s o1 o2 = reveal_opaque (`%BS.eval_ocmp_opaque) BS.eval_ocmp_opaque
{ "file_name": "vale/code/arch/x64/Vale.X64.Lemmas.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 84, "end_line": 333, "start_col": 0, "start_line": 333 }
module Vale.X64.Lemmas open FStar.Mul open Vale.X64.Machine_s open Vale.X64.State open Vale.X64.StateLemmas open Vale.X64.Instruction_s open Vale.X64.Bytes_Code_s module BS = Vale.X64.Machine_Semantics_s module ME = Vale.X64.Memory #reset-options "--initial_fuel 1 --max_fuel 1 --z3rlimit 100" #restart-solver let rec lemma_eq_instr_apply_eval_args (outs:list instr_out) (args:list instr_operand) (f:instr_args_t outs args) (oprs:instr_operands_t_args args) (s1 s2:machine_state) : Lemma (requires state_eq_S true s1 s2) (ensures BS.instr_apply_eval_args outs args f oprs s1 == BS.instr_apply_eval_args outs args f oprs s2) = let open BS in lemma_heap_ignore_ghost_machine s1.BS.ms_heap s2.BS.ms_heap; match args with | [] -> () | i::args -> ( let (v, oprs) : option (instr_val_t i) & instr_operands_t_args args = match i with | IOpEx i -> let oprs = coerce oprs in (instr_eval_operand_explicit i (fst oprs) s1, snd oprs) | IOpIm i -> (instr_eval_operand_implicit i s1, coerce oprs) in let f:arrow (instr_val_t i) (instr_args_t outs args) = coerce f in match v with | None -> () | Some v -> lemma_eq_instr_apply_eval_args outs args (f v) oprs s1 s2 ) #restart-solver let rec lemma_eq_instr_apply_eval_inouts (outs inouts:list instr_out) (args:list instr_operand) (f:instr_inouts_t outs inouts args) (oprs:instr_operands_t inouts args) (s1 s2:machine_state) : Lemma (requires state_eq_S true s1 s2) (ensures BS.instr_apply_eval_inouts outs inouts args f oprs s1 == BS.instr_apply_eval_inouts outs inouts args f oprs s2) = let open BS in lemma_heap_ignore_ghost_machine s1.BS.ms_heap s2.BS.ms_heap; match inouts with | [] -> lemma_eq_instr_apply_eval_args outs args f oprs s1 s2 | (Out, i)::inouts -> let oprs = match i with | IOpEx i -> snd #(instr_operand_t i) (coerce oprs) | IOpIm i -> coerce oprs in lemma_eq_instr_apply_eval_inouts outs inouts args (coerce f) oprs s1 s2 | (InOut, i)::inouts -> ( let (v, oprs) : option (instr_val_t i) & instr_operands_t inouts args = match i with | IOpEx i -> let oprs = coerce oprs in (instr_eval_operand_explicit i (fst oprs) s1, snd oprs) | IOpIm i -> (instr_eval_operand_implicit i s1, coerce oprs) in let f:arrow (instr_val_t i) (instr_inouts_t outs inouts args) = coerce f in match v with | None -> () | Some v -> lemma_eq_instr_apply_eval_inouts outs inouts args (f v) oprs s1 s2 ) #restart-solver #push-options "--z3rlimit_factor 2" let rec lemma_eq_instr_write_outputs (outs:list instr_out) (args:list instr_operand) (vs:instr_ret_t outs) (oprs:instr_operands_t outs args) (s1_orig s1 s2_orig s2:machine_state) : Lemma (requires state_eq_S true s1_orig s2_orig /\ state_eq_S true s1 s2) (ensures state_eq_S true (BS.instr_write_outputs outs args vs oprs s1_orig s1) (BS.instr_write_outputs outs args vs oprs s2_orig s2)) = let open BS in use_machine_state_equal (); lemma_heap_ignore_ghost_machine s1.BS.ms_heap s2.BS.ms_heap; lemma_heap_ignore_ghost_machine s1_orig.BS.ms_heap s2_orig.BS.ms_heap; allow_inversion tmaddr; match outs with | [] -> () | (_, i)::outs -> ( let ((v:instr_val_t i), (vs:instr_ret_t outs)) = match outs with | [] -> (vs, ()) | _::_ -> let vs = coerce vs in (fst vs, snd vs) in match i with | IOpEx i -> let oprs = coerce oprs in let s1 = instr_write_output_explicit i v (fst oprs) s1_orig s1 in let s2 = instr_write_output_explicit i v (fst oprs) s2_orig s2 in lemma_eq_instr_write_outputs outs args vs (snd oprs) s1_orig s1 s2_orig s2 | IOpIm i -> let s1 = instr_write_output_implicit i v s1_orig s1 in let s2 = instr_write_output_implicit i v s2_orig s2 in allow_inversion operand64; allow_inversion operand128; lemma_eq_instr_write_outputs outs args vs (coerce oprs) s1_orig s1 s2_orig s2 ) #pop-options #restart-solver let eval_ins_eq_instr (inst:BS.ins) (s1 s2:machine_state) : Lemma (requires Instr? inst /\ state_eq_S true s1 s2) (ensures state_eq_S true (BS.machine_eval_ins inst s1) (BS.machine_eval_ins inst s2)) = let open BS in let Instr it oprs ann = inst in let InstrTypeRecord #outs #args #havoc_flags' i = it in lemma_eq_instr_apply_eval_inouts outs outs args (instr_eval i) oprs s1 s2; let vs = instr_apply_eval outs args (instr_eval i) oprs s1 in let hav s = match havoc_flags' with | HavocFlags -> {s with ms_flags = havoc_flags} | PreserveFlags -> s in let s1' = hav s1 in let s2' = hav s2 in match vs with | None -> () | Some vs -> lemma_eq_instr_write_outputs outs args vs oprs s1 s1' s2 s2' let eval_code_eq_instr (inst:BS.ins) (f:fuel) (s1 s2:machine_state) : Lemma (requires Instr? inst /\ state_eq_S true s1 s2) (ensures state_eq_opt true (BS.machine_eval_code (Ins inst) f s1) (BS.machine_eval_code (Ins inst) f s2)) = reveal_opaque (`%BS.machine_eval_code_ins) BS.machine_eval_code_ins; eval_ins_eq_instr inst ({s1 with BS.ms_trace = []}) ({s2 with BS.ms_trace = []}) let eval_code_eq_dealloc (inst:BS.ins) (f:fuel) (s1 s2:machine_state) : Lemma (requires Dealloc? inst /\ state_eq_S true s1 s2) (ensures state_eq_opt true (BS.machine_eval_code (Ins inst) f s1) (BS.machine_eval_code (Ins inst) f s2)) = reveal_opaque (`%BS.machine_eval_code_ins) BS.machine_eval_code_ins; use_machine_state_equal (); lemma_heap_ignore_ghost_machine s1.BS.ms_heap s2.BS.ms_heap; allow_inversion tmaddr let eval_code_eq_alloc (inst:BS.ins) (f:fuel) (s1 s2:machine_state) : Lemma (requires Alloc? inst /\ state_eq_S true s1 s2) (ensures state_eq_opt true (BS.machine_eval_code (Ins inst) f s1) (BS.machine_eval_code (Ins inst) f s2)) = reveal_opaque (`%BS.machine_eval_code_ins) BS.machine_eval_code_ins; use_machine_state_equal (); lemma_heap_ignore_ghost_machine s1.BS.ms_heap s2.BS.ms_heap; allow_inversion tmaddr let eval_code_eq_push (inst:BS.ins) (f:fuel) (s1 s2:machine_state) : Lemma (requires Push? inst /\ state_eq_S true s1 s2) (ensures state_eq_opt true (BS.machine_eval_code (Ins inst) f s1) (BS.machine_eval_code (Ins inst) f s2)) = reveal_opaque (`%BS.machine_eval_code_ins) BS.machine_eval_code_ins; use_machine_state_equal (); lemma_heap_ignore_ghost_machine s1.BS.ms_heap s2.BS.ms_heap; allow_inversion tmaddr let eval_code_eq_pop (inst:BS.ins) (f:fuel) (s1 s2:machine_state) : Lemma (requires Pop? inst /\ state_eq_S true s1 s2) (ensures state_eq_opt true (BS.machine_eval_code (Ins inst) f s1) (BS.machine_eval_code (Ins inst) f s2)) = reveal_opaque (`%BS.machine_eval_code_ins) BS.machine_eval_code_ins; use_machine_state_equal (); lemma_heap_ignore_ghost_machine s1.BS.ms_heap s2.BS.ms_heap; allow_inversion tmaddr let eval_code_eq_ins (i:BS.ins) (f:fuel) (s1 s2:machine_state) : Lemma (requires state_eq_S true s1 s2) (ensures state_eq_opt true (BS.machine_eval_code (Ins i) f s1) (BS.machine_eval_code (Ins i) f s2)) = match i with | Instr _ _ _ -> eval_code_eq_instr i f s1 s2 | Dealloc _ -> eval_code_eq_dealloc i f s1 s2 | Alloc _ -> eval_code_eq_alloc i f s1 s2 | Push _ _ -> eval_code_eq_push i f s1 s2 | Pop _ _ -> eval_code_eq_pop i f s1 s2 #reset-options "--fuel 2 --z3rlimit 30" let eval_ocmp_eq_core (g:bool) (cond:ocmp) (s:machine_state) : Lemma (ensures ( let (s1, b1) = BS.machine_eval_ocmp s cond in let (s2, b2) = BS.machine_eval_ocmp (core_state g s) cond in state_eq_S g s1 s2 /\ b1 == b2 )) = reveal_opaque (`%BS.valid_ocmp_opaque) BS.valid_ocmp_opaque; reveal_opaque (`%BS.eval_ocmp_opaque) BS.eval_ocmp_opaque; () #restart-solver let rec eval_code_eq_core (g:bool) (c:code) (f:fuel) (s:machine_state) : Lemma (ensures state_eq_opt g (BS.machine_eval_code c f s) (BS.machine_eval_code c f (core_state g s))) (decreases %[f; c]) = match c with | Ins i -> reveal_opaque (`%BS.machine_eval_code_ins) BS.machine_eval_code_ins; if g then eval_code_eq_ins i f s (core_state g s) | Block cs -> eval_codes_eq_core g cs f s | IfElse cond ct cf -> eval_ocmp_eq_core g cond s; let (s', _) = BS.machine_eval_ocmp s cond in let (t', _) = BS.machine_eval_ocmp (core_state g s) cond in eval_code_eq_core g ct f s'; eval_code_eq_core g ct f t'; eval_code_eq_core g cf f s'; eval_code_eq_core g cf f t'; () | While cond body -> eval_while_eq_core g cond body f s and eval_codes_eq_core (g:bool) (cs:codes) (f:fuel) (s:machine_state) : Lemma (ensures state_eq_opt g (BS.machine_eval_codes cs f s) (BS.machine_eval_codes cs f (core_state g s))) (decreases %[f; cs]) = match cs with | [] -> () | c'::cs' -> ( eval_code_eq_core g c' f s; match (machine_eval_code c' f s, machine_eval_code c' f (core_state g s)) with | (None, None) -> () | (Some s', Some t') -> eval_codes_eq_core g cs' f s'; eval_codes_eq_core g cs' f t' ) and eval_while_eq_core (g:bool) (cond:ocmp) (body:code) (f:fuel) (s:machine_state) : Lemma (ensures state_eq_opt g (BS.machine_eval_while cond body f s) (BS.machine_eval_while cond body f (core_state g s))) (decreases %[f; body]) = if f > 0 then ( eval_ocmp_eq_core g cond s; let (s1, _) = BS.machine_eval_ocmp s cond in let (t1, _) = BS.machine_eval_ocmp (core_state g s) cond in eval_code_eq_core g body (f - 1) s1; eval_code_eq_core g body (f - 1) t1; match (BS.machine_eval_code body (f - 1) s1, BS.machine_eval_code body (f - 1) t1) with | (None, None) -> () | (Some s2, Some t2) -> eval_while_eq_core g cond body (f - 1) s2; eval_while_eq_core g cond body (f - 1) t2; () ) let eval_code_eq_f (c:code) (f:fuel) (s1 s2:machine_state) : Lemma (requires state_eq_S false s1 s2) (ensures state_eq_opt false (BS.machine_eval_code c f s1) (BS.machine_eval_code c f s2)) [SMTPat (BS.machine_eval_code c f s1); SMTPat (BS.machine_eval_code c f s2)] = eval_code_eq_core false c f s1; eval_code_eq_core false c f s2 let eval_codes_eq_f (cs:codes) (f:fuel) (s1 s2:machine_state) : Lemma (requires state_eq_S false s1 s2) (ensures state_eq_opt false (BS.machine_eval_codes cs f s1) (BS.machine_eval_codes cs f s2)) [SMTPat (BS.machine_eval_codes cs f s1); SMTPat (BS.machine_eval_codes cs f s2)] = eval_codes_eq_core false cs f s1; eval_codes_eq_core false cs f s2 let eval_while_eq_f (cond:ocmp) (body:code) (f:fuel) (s1 s2:machine_state) : Lemma (requires state_eq_S false s1 s2) (ensures state_eq_opt false (BS.machine_eval_while cond body f s1) (BS.machine_eval_while cond body f s2)) [SMTPat (BS.machine_eval_while cond body f s1); SMTPat (BS.machine_eval_while cond body f s2)] = eval_while_eq_core false cond body f s1; eval_while_eq_core false cond body f s2 let eval_code_eq_t (c:code) (f:fuel) (s1 s2:machine_state) : Lemma (requires state_eq_S true s1 s2) (ensures state_eq_opt true (BS.machine_eval_code c f s1) (BS.machine_eval_code c f s2)) [SMTPat (BS.machine_eval_code c f s1); SMTPat (BS.machine_eval_code c f s2)] = eval_code_eq_core true c f s1; eval_code_eq_core true c f s2 let eval_codes_eq_t (cs:codes) (f:fuel) (s1 s2:machine_state) : Lemma (requires state_eq_S true s1 s2) (ensures state_eq_opt true (BS.machine_eval_codes cs f s1) (BS.machine_eval_codes cs f s2)) [SMTPat (BS.machine_eval_codes cs f s1); SMTPat (BS.machine_eval_codes cs f s2)] = eval_codes_eq_core true cs f s1; eval_codes_eq_core true cs f s2 let eval_while_eq_t (cond:ocmp) (body:code) (f:fuel) (s1 s2:machine_state) : Lemma (requires state_eq_S true s1 s2) (ensures state_eq_opt true (BS.machine_eval_while cond body f s1) (BS.machine_eval_while cond body f s2)) [SMTPat (BS.machine_eval_while cond body f s1); SMTPat (BS.machine_eval_while cond body f s2)] = eval_while_eq_core true cond body f s1; eval_while_eq_core true cond body f s2 let eval_code_ts (g:bool) (c:code) (s0:machine_state) (f0:fuel) (s1:machine_state) : Type0 = state_eq_opt g (BS.machine_eval_code c f0 s0) (Some s1) let rec increase_fuel (g:bool) (c:code) (s0:machine_state) (f0:fuel) (sN:machine_state) (fN:fuel) : Lemma (requires eval_code_ts g c s0 f0 sN /\ f0 <= fN) (ensures eval_code_ts g c s0 fN sN) (decreases %[f0; c]) = match c with | Ins ins -> () | Block l -> increase_fuels g l s0 f0 sN fN | IfElse cond t f -> let (s0, b0) = BS.machine_eval_ocmp s0 cond in if b0 then increase_fuel g t s0 f0 sN fN else increase_fuel g f s0 f0 sN fN | While cond c -> let (s1, b0) = BS.machine_eval_ocmp s0 cond in if b0 then ( match BS.machine_eval_code c (f0 - 1) s1 with | None -> () | Some s2 -> increase_fuel g c s1 (f0 - 1) s2 (fN - 1); if s2.BS.ms_ok then increase_fuel g (While cond c) s2 (f0 - 1) sN (fN - 1) else () ) and increase_fuels (g:bool) (c:codes) (s0:machine_state) (f0:fuel) (sN:machine_state) (fN:fuel) : Lemma (requires eval_code_ts g (Block c) s0 f0 sN /\ f0 <= fN) (ensures eval_code_ts g (Block c) s0 fN sN) (decreases %[f0; c]) = match c with | [] -> () | h::t -> ( let Some s1 = BS.machine_eval_code h f0 s0 in increase_fuel g h s0 f0 s1 fN; increase_fuels g t s1 f0 sN fN )
{ "checked_file": "/", "dependencies": [ "Vale.X64.StateLemmas.fsti.checked", "Vale.X64.State.fsti.checked", "Vale.X64.Memory.fsti.checked", "Vale.X64.Machine_Semantics_s.fst.checked", "Vale.X64.Machine_s.fst.checked", "Vale.X64.Instruction_s.fsti.checked", "Vale.X64.Flags.fsti.checked", "Vale.X64.Bytes_Code_s.fst.checked", "prims.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.FunctionalExtensionality.fsti.checked" ], "interface_file": true, "source_file": "Vale.X64.Lemmas.fst" }
[ { "abbrev": true, "full_module": "Vale.X64.Memory", "short_module": "ME" }, { "abbrev": true, "full_module": "Vale.X64.Machine_Semantics_s", "short_module": "BS" }, { "abbrev": false, "full_module": "Vale.X64.Bytes_Code_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Instruction_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.StateLemmas", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.State", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Machine_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": true, "full_module": "Vale.Lib.Map16", "short_module": "Map16" }, { "abbrev": true, "full_module": "Vale.X64.Machine_Semantics_s", "short_module": "BS" }, { "abbrev": false, "full_module": "Vale.X64.Bytes_Code_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.StateLemmas", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.State", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Machine_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.HeapLemmas", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.HeapImpl", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.Heap", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 0, "max_fuel": 2, "max_ifuel": 1, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": true, "smtencoding_l_arith_repr": "native", "smtencoding_nl_arith_repr": "wrapped", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [ "smt.arith.nl=false", "smt.QI.EAGER_THRESHOLD=100", "smt.CASE_SPLIT=3" ], "z3refresh": false, "z3rlimit": 30, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
s: Vale.X64.State.vale_state -> o1: Vale.X64.Machine_s.operand64{Prims.op_Negation (OMem? o1 || OStack? o1)} -> o2: Vale.X64.Machine_s.operand64{Prims.op_Negation (OMem? o2 || OStack? o2)} -> FStar.Pervasives.Lemma (ensures Vale.X64.Lemmas.eval_ocmp s (Vale.X64.Bytes_Code_s.OEq o1 o2) <==> Vale.X64.State.eval_operand o1 s == Vale.X64.State.eval_operand o2 s) [SMTPat (Vale.X64.Lemmas.eval_ocmp s (Vale.X64.Bytes_Code_s.OEq o1 o2))]
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "Vale.X64.State.vale_state", "Vale.X64.Machine_s.operand64", "Prims.b2t", "Prims.op_Negation", "Prims.op_BarBar", "Vale.X64.Machine_s.uu___is_OMem", "Vale.X64.Machine_s.nat64", "Vale.X64.Machine_s.reg_64", "Vale.X64.Machine_s.uu___is_OStack", "FStar.Pervasives.reveal_opaque", "Vale.X64.Machine_Semantics_s.machine_state", "Vale.X64.Machine_Semantics_s.ocmp", "Prims.bool", "Vale.X64.Machine_Semantics_s.eval_ocmp_opaque", "Prims.unit" ]
[]
true
false
true
false
false
let lemma_cmp_eq s o1 o2 =
reveal_opaque (`%BS.eval_ocmp_opaque) BS.eval_ocmp_opaque
false
Vale.X64.Lemmas.fst
Vale.X64.Lemmas.lemma_cmp_le
val lemma_cmp_le (s:vale_state) (o1:operand64{not (OMem? o1 || OStack? o1)}) (o2:operand64{not (OMem? o2 || OStack? o2)}) : Lemma (ensures eval_ocmp s (OLe o1 o2) <==> eval_operand o1 s <= eval_operand o2 s) [SMTPat (eval_ocmp s (OLe o1 o2))]
val lemma_cmp_le (s:vale_state) (o1:operand64{not (OMem? o1 || OStack? o1)}) (o2:operand64{not (OMem? o2 || OStack? o2)}) : Lemma (ensures eval_ocmp s (OLe o1 o2) <==> eval_operand o1 s <= eval_operand o2 s) [SMTPat (eval_ocmp s (OLe o1 o2))]
let lemma_cmp_le s o1 o2 = reveal_opaque (`%BS.eval_ocmp_opaque) BS.eval_ocmp_opaque
{ "file_name": "vale/code/arch/x64/Vale.X64.Lemmas.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 84, "end_line": 335, "start_col": 0, "start_line": 335 }
module Vale.X64.Lemmas open FStar.Mul open Vale.X64.Machine_s open Vale.X64.State open Vale.X64.StateLemmas open Vale.X64.Instruction_s open Vale.X64.Bytes_Code_s module BS = Vale.X64.Machine_Semantics_s module ME = Vale.X64.Memory #reset-options "--initial_fuel 1 --max_fuel 1 --z3rlimit 100" #restart-solver let rec lemma_eq_instr_apply_eval_args (outs:list instr_out) (args:list instr_operand) (f:instr_args_t outs args) (oprs:instr_operands_t_args args) (s1 s2:machine_state) : Lemma (requires state_eq_S true s1 s2) (ensures BS.instr_apply_eval_args outs args f oprs s1 == BS.instr_apply_eval_args outs args f oprs s2) = let open BS in lemma_heap_ignore_ghost_machine s1.BS.ms_heap s2.BS.ms_heap; match args with | [] -> () | i::args -> ( let (v, oprs) : option (instr_val_t i) & instr_operands_t_args args = match i with | IOpEx i -> let oprs = coerce oprs in (instr_eval_operand_explicit i (fst oprs) s1, snd oprs) | IOpIm i -> (instr_eval_operand_implicit i s1, coerce oprs) in let f:arrow (instr_val_t i) (instr_args_t outs args) = coerce f in match v with | None -> () | Some v -> lemma_eq_instr_apply_eval_args outs args (f v) oprs s1 s2 ) #restart-solver let rec lemma_eq_instr_apply_eval_inouts (outs inouts:list instr_out) (args:list instr_operand) (f:instr_inouts_t outs inouts args) (oprs:instr_operands_t inouts args) (s1 s2:machine_state) : Lemma (requires state_eq_S true s1 s2) (ensures BS.instr_apply_eval_inouts outs inouts args f oprs s1 == BS.instr_apply_eval_inouts outs inouts args f oprs s2) = let open BS in lemma_heap_ignore_ghost_machine s1.BS.ms_heap s2.BS.ms_heap; match inouts with | [] -> lemma_eq_instr_apply_eval_args outs args f oprs s1 s2 | (Out, i)::inouts -> let oprs = match i with | IOpEx i -> snd #(instr_operand_t i) (coerce oprs) | IOpIm i -> coerce oprs in lemma_eq_instr_apply_eval_inouts outs inouts args (coerce f) oprs s1 s2 | (InOut, i)::inouts -> ( let (v, oprs) : option (instr_val_t i) & instr_operands_t inouts args = match i with | IOpEx i -> let oprs = coerce oprs in (instr_eval_operand_explicit i (fst oprs) s1, snd oprs) | IOpIm i -> (instr_eval_operand_implicit i s1, coerce oprs) in let f:arrow (instr_val_t i) (instr_inouts_t outs inouts args) = coerce f in match v with | None -> () | Some v -> lemma_eq_instr_apply_eval_inouts outs inouts args (f v) oprs s1 s2 ) #restart-solver #push-options "--z3rlimit_factor 2" let rec lemma_eq_instr_write_outputs (outs:list instr_out) (args:list instr_operand) (vs:instr_ret_t outs) (oprs:instr_operands_t outs args) (s1_orig s1 s2_orig s2:machine_state) : Lemma (requires state_eq_S true s1_orig s2_orig /\ state_eq_S true s1 s2) (ensures state_eq_S true (BS.instr_write_outputs outs args vs oprs s1_orig s1) (BS.instr_write_outputs outs args vs oprs s2_orig s2)) = let open BS in use_machine_state_equal (); lemma_heap_ignore_ghost_machine s1.BS.ms_heap s2.BS.ms_heap; lemma_heap_ignore_ghost_machine s1_orig.BS.ms_heap s2_orig.BS.ms_heap; allow_inversion tmaddr; match outs with | [] -> () | (_, i)::outs -> ( let ((v:instr_val_t i), (vs:instr_ret_t outs)) = match outs with | [] -> (vs, ()) | _::_ -> let vs = coerce vs in (fst vs, snd vs) in match i with | IOpEx i -> let oprs = coerce oprs in let s1 = instr_write_output_explicit i v (fst oprs) s1_orig s1 in let s2 = instr_write_output_explicit i v (fst oprs) s2_orig s2 in lemma_eq_instr_write_outputs outs args vs (snd oprs) s1_orig s1 s2_orig s2 | IOpIm i -> let s1 = instr_write_output_implicit i v s1_orig s1 in let s2 = instr_write_output_implicit i v s2_orig s2 in allow_inversion operand64; allow_inversion operand128; lemma_eq_instr_write_outputs outs args vs (coerce oprs) s1_orig s1 s2_orig s2 ) #pop-options #restart-solver let eval_ins_eq_instr (inst:BS.ins) (s1 s2:machine_state) : Lemma (requires Instr? inst /\ state_eq_S true s1 s2) (ensures state_eq_S true (BS.machine_eval_ins inst s1) (BS.machine_eval_ins inst s2)) = let open BS in let Instr it oprs ann = inst in let InstrTypeRecord #outs #args #havoc_flags' i = it in lemma_eq_instr_apply_eval_inouts outs outs args (instr_eval i) oprs s1 s2; let vs = instr_apply_eval outs args (instr_eval i) oprs s1 in let hav s = match havoc_flags' with | HavocFlags -> {s with ms_flags = havoc_flags} | PreserveFlags -> s in let s1' = hav s1 in let s2' = hav s2 in match vs with | None -> () | Some vs -> lemma_eq_instr_write_outputs outs args vs oprs s1 s1' s2 s2' let eval_code_eq_instr (inst:BS.ins) (f:fuel) (s1 s2:machine_state) : Lemma (requires Instr? inst /\ state_eq_S true s1 s2) (ensures state_eq_opt true (BS.machine_eval_code (Ins inst) f s1) (BS.machine_eval_code (Ins inst) f s2)) = reveal_opaque (`%BS.machine_eval_code_ins) BS.machine_eval_code_ins; eval_ins_eq_instr inst ({s1 with BS.ms_trace = []}) ({s2 with BS.ms_trace = []}) let eval_code_eq_dealloc (inst:BS.ins) (f:fuel) (s1 s2:machine_state) : Lemma (requires Dealloc? inst /\ state_eq_S true s1 s2) (ensures state_eq_opt true (BS.machine_eval_code (Ins inst) f s1) (BS.machine_eval_code (Ins inst) f s2)) = reveal_opaque (`%BS.machine_eval_code_ins) BS.machine_eval_code_ins; use_machine_state_equal (); lemma_heap_ignore_ghost_machine s1.BS.ms_heap s2.BS.ms_heap; allow_inversion tmaddr let eval_code_eq_alloc (inst:BS.ins) (f:fuel) (s1 s2:machine_state) : Lemma (requires Alloc? inst /\ state_eq_S true s1 s2) (ensures state_eq_opt true (BS.machine_eval_code (Ins inst) f s1) (BS.machine_eval_code (Ins inst) f s2)) = reveal_opaque (`%BS.machine_eval_code_ins) BS.machine_eval_code_ins; use_machine_state_equal (); lemma_heap_ignore_ghost_machine s1.BS.ms_heap s2.BS.ms_heap; allow_inversion tmaddr let eval_code_eq_push (inst:BS.ins) (f:fuel) (s1 s2:machine_state) : Lemma (requires Push? inst /\ state_eq_S true s1 s2) (ensures state_eq_opt true (BS.machine_eval_code (Ins inst) f s1) (BS.machine_eval_code (Ins inst) f s2)) = reveal_opaque (`%BS.machine_eval_code_ins) BS.machine_eval_code_ins; use_machine_state_equal (); lemma_heap_ignore_ghost_machine s1.BS.ms_heap s2.BS.ms_heap; allow_inversion tmaddr let eval_code_eq_pop (inst:BS.ins) (f:fuel) (s1 s2:machine_state) : Lemma (requires Pop? inst /\ state_eq_S true s1 s2) (ensures state_eq_opt true (BS.machine_eval_code (Ins inst) f s1) (BS.machine_eval_code (Ins inst) f s2)) = reveal_opaque (`%BS.machine_eval_code_ins) BS.machine_eval_code_ins; use_machine_state_equal (); lemma_heap_ignore_ghost_machine s1.BS.ms_heap s2.BS.ms_heap; allow_inversion tmaddr let eval_code_eq_ins (i:BS.ins) (f:fuel) (s1 s2:machine_state) : Lemma (requires state_eq_S true s1 s2) (ensures state_eq_opt true (BS.machine_eval_code (Ins i) f s1) (BS.machine_eval_code (Ins i) f s2)) = match i with | Instr _ _ _ -> eval_code_eq_instr i f s1 s2 | Dealloc _ -> eval_code_eq_dealloc i f s1 s2 | Alloc _ -> eval_code_eq_alloc i f s1 s2 | Push _ _ -> eval_code_eq_push i f s1 s2 | Pop _ _ -> eval_code_eq_pop i f s1 s2 #reset-options "--fuel 2 --z3rlimit 30" let eval_ocmp_eq_core (g:bool) (cond:ocmp) (s:machine_state) : Lemma (ensures ( let (s1, b1) = BS.machine_eval_ocmp s cond in let (s2, b2) = BS.machine_eval_ocmp (core_state g s) cond in state_eq_S g s1 s2 /\ b1 == b2 )) = reveal_opaque (`%BS.valid_ocmp_opaque) BS.valid_ocmp_opaque; reveal_opaque (`%BS.eval_ocmp_opaque) BS.eval_ocmp_opaque; () #restart-solver let rec eval_code_eq_core (g:bool) (c:code) (f:fuel) (s:machine_state) : Lemma (ensures state_eq_opt g (BS.machine_eval_code c f s) (BS.machine_eval_code c f (core_state g s))) (decreases %[f; c]) = match c with | Ins i -> reveal_opaque (`%BS.machine_eval_code_ins) BS.machine_eval_code_ins; if g then eval_code_eq_ins i f s (core_state g s) | Block cs -> eval_codes_eq_core g cs f s | IfElse cond ct cf -> eval_ocmp_eq_core g cond s; let (s', _) = BS.machine_eval_ocmp s cond in let (t', _) = BS.machine_eval_ocmp (core_state g s) cond in eval_code_eq_core g ct f s'; eval_code_eq_core g ct f t'; eval_code_eq_core g cf f s'; eval_code_eq_core g cf f t'; () | While cond body -> eval_while_eq_core g cond body f s and eval_codes_eq_core (g:bool) (cs:codes) (f:fuel) (s:machine_state) : Lemma (ensures state_eq_opt g (BS.machine_eval_codes cs f s) (BS.machine_eval_codes cs f (core_state g s))) (decreases %[f; cs]) = match cs with | [] -> () | c'::cs' -> ( eval_code_eq_core g c' f s; match (machine_eval_code c' f s, machine_eval_code c' f (core_state g s)) with | (None, None) -> () | (Some s', Some t') -> eval_codes_eq_core g cs' f s'; eval_codes_eq_core g cs' f t' ) and eval_while_eq_core (g:bool) (cond:ocmp) (body:code) (f:fuel) (s:machine_state) : Lemma (ensures state_eq_opt g (BS.machine_eval_while cond body f s) (BS.machine_eval_while cond body f (core_state g s))) (decreases %[f; body]) = if f > 0 then ( eval_ocmp_eq_core g cond s; let (s1, _) = BS.machine_eval_ocmp s cond in let (t1, _) = BS.machine_eval_ocmp (core_state g s) cond in eval_code_eq_core g body (f - 1) s1; eval_code_eq_core g body (f - 1) t1; match (BS.machine_eval_code body (f - 1) s1, BS.machine_eval_code body (f - 1) t1) with | (None, None) -> () | (Some s2, Some t2) -> eval_while_eq_core g cond body (f - 1) s2; eval_while_eq_core g cond body (f - 1) t2; () ) let eval_code_eq_f (c:code) (f:fuel) (s1 s2:machine_state) : Lemma (requires state_eq_S false s1 s2) (ensures state_eq_opt false (BS.machine_eval_code c f s1) (BS.machine_eval_code c f s2)) [SMTPat (BS.machine_eval_code c f s1); SMTPat (BS.machine_eval_code c f s2)] = eval_code_eq_core false c f s1; eval_code_eq_core false c f s2 let eval_codes_eq_f (cs:codes) (f:fuel) (s1 s2:machine_state) : Lemma (requires state_eq_S false s1 s2) (ensures state_eq_opt false (BS.machine_eval_codes cs f s1) (BS.machine_eval_codes cs f s2)) [SMTPat (BS.machine_eval_codes cs f s1); SMTPat (BS.machine_eval_codes cs f s2)] = eval_codes_eq_core false cs f s1; eval_codes_eq_core false cs f s2 let eval_while_eq_f (cond:ocmp) (body:code) (f:fuel) (s1 s2:machine_state) : Lemma (requires state_eq_S false s1 s2) (ensures state_eq_opt false (BS.machine_eval_while cond body f s1) (BS.machine_eval_while cond body f s2)) [SMTPat (BS.machine_eval_while cond body f s1); SMTPat (BS.machine_eval_while cond body f s2)] = eval_while_eq_core false cond body f s1; eval_while_eq_core false cond body f s2 let eval_code_eq_t (c:code) (f:fuel) (s1 s2:machine_state) : Lemma (requires state_eq_S true s1 s2) (ensures state_eq_opt true (BS.machine_eval_code c f s1) (BS.machine_eval_code c f s2)) [SMTPat (BS.machine_eval_code c f s1); SMTPat (BS.machine_eval_code c f s2)] = eval_code_eq_core true c f s1; eval_code_eq_core true c f s2 let eval_codes_eq_t (cs:codes) (f:fuel) (s1 s2:machine_state) : Lemma (requires state_eq_S true s1 s2) (ensures state_eq_opt true (BS.machine_eval_codes cs f s1) (BS.machine_eval_codes cs f s2)) [SMTPat (BS.machine_eval_codes cs f s1); SMTPat (BS.machine_eval_codes cs f s2)] = eval_codes_eq_core true cs f s1; eval_codes_eq_core true cs f s2 let eval_while_eq_t (cond:ocmp) (body:code) (f:fuel) (s1 s2:machine_state) : Lemma (requires state_eq_S true s1 s2) (ensures state_eq_opt true (BS.machine_eval_while cond body f s1) (BS.machine_eval_while cond body f s2)) [SMTPat (BS.machine_eval_while cond body f s1); SMTPat (BS.machine_eval_while cond body f s2)] = eval_while_eq_core true cond body f s1; eval_while_eq_core true cond body f s2 let eval_code_ts (g:bool) (c:code) (s0:machine_state) (f0:fuel) (s1:machine_state) : Type0 = state_eq_opt g (BS.machine_eval_code c f0 s0) (Some s1) let rec increase_fuel (g:bool) (c:code) (s0:machine_state) (f0:fuel) (sN:machine_state) (fN:fuel) : Lemma (requires eval_code_ts g c s0 f0 sN /\ f0 <= fN) (ensures eval_code_ts g c s0 fN sN) (decreases %[f0; c]) = match c with | Ins ins -> () | Block l -> increase_fuels g l s0 f0 sN fN | IfElse cond t f -> let (s0, b0) = BS.machine_eval_ocmp s0 cond in if b0 then increase_fuel g t s0 f0 sN fN else increase_fuel g f s0 f0 sN fN | While cond c -> let (s1, b0) = BS.machine_eval_ocmp s0 cond in if b0 then ( match BS.machine_eval_code c (f0 - 1) s1 with | None -> () | Some s2 -> increase_fuel g c s1 (f0 - 1) s2 (fN - 1); if s2.BS.ms_ok then increase_fuel g (While cond c) s2 (f0 - 1) sN (fN - 1) else () ) and increase_fuels (g:bool) (c:codes) (s0:machine_state) (f0:fuel) (sN:machine_state) (fN:fuel) : Lemma (requires eval_code_ts g (Block c) s0 f0 sN /\ f0 <= fN) (ensures eval_code_ts g (Block c) s0 fN sN) (decreases %[f0; c]) = match c with | [] -> () | h::t -> ( let Some s1 = BS.machine_eval_code h f0 s0 in increase_fuel g h s0 f0 s1 fN; increase_fuels g t s1 f0 sN fN ) let lemma_cmp_eq s o1 o2 = reveal_opaque (`%BS.eval_ocmp_opaque) BS.eval_ocmp_opaque
{ "checked_file": "/", "dependencies": [ "Vale.X64.StateLemmas.fsti.checked", "Vale.X64.State.fsti.checked", "Vale.X64.Memory.fsti.checked", "Vale.X64.Machine_Semantics_s.fst.checked", "Vale.X64.Machine_s.fst.checked", "Vale.X64.Instruction_s.fsti.checked", "Vale.X64.Flags.fsti.checked", "Vale.X64.Bytes_Code_s.fst.checked", "prims.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.FunctionalExtensionality.fsti.checked" ], "interface_file": true, "source_file": "Vale.X64.Lemmas.fst" }
[ { "abbrev": true, "full_module": "Vale.X64.Memory", "short_module": "ME" }, { "abbrev": true, "full_module": "Vale.X64.Machine_Semantics_s", "short_module": "BS" }, { "abbrev": false, "full_module": "Vale.X64.Bytes_Code_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Instruction_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.StateLemmas", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.State", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Machine_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": true, "full_module": "Vale.Lib.Map16", "short_module": "Map16" }, { "abbrev": true, "full_module": "Vale.X64.Machine_Semantics_s", "short_module": "BS" }, { "abbrev": false, "full_module": "Vale.X64.Bytes_Code_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.StateLemmas", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.State", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Machine_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.HeapLemmas", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.HeapImpl", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.Heap", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 0, "max_fuel": 2, "max_ifuel": 1, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": true, "smtencoding_l_arith_repr": "native", "smtencoding_nl_arith_repr": "wrapped", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [ "smt.arith.nl=false", "smt.QI.EAGER_THRESHOLD=100", "smt.CASE_SPLIT=3" ], "z3refresh": false, "z3rlimit": 30, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
s: Vale.X64.State.vale_state -> o1: Vale.X64.Machine_s.operand64{Prims.op_Negation (OMem? o1 || OStack? o1)} -> o2: Vale.X64.Machine_s.operand64{Prims.op_Negation (OMem? o2 || OStack? o2)} -> FStar.Pervasives.Lemma (ensures Vale.X64.Lemmas.eval_ocmp s (Vale.X64.Bytes_Code_s.OLe o1 o2) <==> Vale.X64.State.eval_operand o1 s <= Vale.X64.State.eval_operand o2 s) [SMTPat (Vale.X64.Lemmas.eval_ocmp s (Vale.X64.Bytes_Code_s.OLe o1 o2))]
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "Vale.X64.State.vale_state", "Vale.X64.Machine_s.operand64", "Prims.b2t", "Prims.op_Negation", "Prims.op_BarBar", "Vale.X64.Machine_s.uu___is_OMem", "Vale.X64.Machine_s.nat64", "Vale.X64.Machine_s.reg_64", "Vale.X64.Machine_s.uu___is_OStack", "FStar.Pervasives.reveal_opaque", "Vale.X64.Machine_Semantics_s.machine_state", "Vale.X64.Machine_Semantics_s.ocmp", "Prims.bool", "Vale.X64.Machine_Semantics_s.eval_ocmp_opaque", "Prims.unit" ]
[]
true
false
true
false
false
let lemma_cmp_le s o1 o2 =
reveal_opaque (`%BS.eval_ocmp_opaque) BS.eval_ocmp_opaque
false
Vale.X64.Lemmas.fst
Vale.X64.Lemmas.lemma_eq_instr_apply_eval_inouts
val lemma_eq_instr_apply_eval_inouts (outs inouts: list instr_out) (args: list instr_operand) (f: instr_inouts_t outs inouts args) (oprs: instr_operands_t inouts args) (s1 s2: machine_state) : Lemma (requires state_eq_S true s1 s2) (ensures BS.instr_apply_eval_inouts outs inouts args f oprs s1 == BS.instr_apply_eval_inouts outs inouts args f oprs s2)
val lemma_eq_instr_apply_eval_inouts (outs inouts: list instr_out) (args: list instr_operand) (f: instr_inouts_t outs inouts args) (oprs: instr_operands_t inouts args) (s1 s2: machine_state) : Lemma (requires state_eq_S true s1 s2) (ensures BS.instr_apply_eval_inouts outs inouts args f oprs s1 == BS.instr_apply_eval_inouts outs inouts args f oprs s2)
let rec lemma_eq_instr_apply_eval_inouts (outs inouts:list instr_out) (args:list instr_operand) (f:instr_inouts_t outs inouts args) (oprs:instr_operands_t inouts args) (s1 s2:machine_state) : Lemma (requires state_eq_S true s1 s2) (ensures BS.instr_apply_eval_inouts outs inouts args f oprs s1 == BS.instr_apply_eval_inouts outs inouts args f oprs s2) = let open BS in lemma_heap_ignore_ghost_machine s1.BS.ms_heap s2.BS.ms_heap; match inouts with | [] -> lemma_eq_instr_apply_eval_args outs args f oprs s1 s2 | (Out, i)::inouts -> let oprs = match i with | IOpEx i -> snd #(instr_operand_t i) (coerce oprs) | IOpIm i -> coerce oprs in lemma_eq_instr_apply_eval_inouts outs inouts args (coerce f) oprs s1 s2 | (InOut, i)::inouts -> ( let (v, oprs) : option (instr_val_t i) & instr_operands_t inouts args = match i with | IOpEx i -> let oprs = coerce oprs in (instr_eval_operand_explicit i (fst oprs) s1, snd oprs) | IOpIm i -> (instr_eval_operand_implicit i s1, coerce oprs) in let f:arrow (instr_val_t i) (instr_inouts_t outs inouts args) = coerce f in match v with | None -> () | Some v -> lemma_eq_instr_apply_eval_inouts outs inouts args (f v) oprs s1 s2 )
{ "file_name": "vale/code/arch/x64/Vale.X64.Lemmas.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 5, "end_line": 72, "start_col": 0, "start_line": 41 }
module Vale.X64.Lemmas open FStar.Mul open Vale.X64.Machine_s open Vale.X64.State open Vale.X64.StateLemmas open Vale.X64.Instruction_s open Vale.X64.Bytes_Code_s module BS = Vale.X64.Machine_Semantics_s module ME = Vale.X64.Memory #reset-options "--initial_fuel 1 --max_fuel 1 --z3rlimit 100" #restart-solver let rec lemma_eq_instr_apply_eval_args (outs:list instr_out) (args:list instr_operand) (f:instr_args_t outs args) (oprs:instr_operands_t_args args) (s1 s2:machine_state) : Lemma (requires state_eq_S true s1 s2) (ensures BS.instr_apply_eval_args outs args f oprs s1 == BS.instr_apply_eval_args outs args f oprs s2) = let open BS in lemma_heap_ignore_ghost_machine s1.BS.ms_heap s2.BS.ms_heap; match args with | [] -> () | i::args -> ( let (v, oprs) : option (instr_val_t i) & instr_operands_t_args args = match i with | IOpEx i -> let oprs = coerce oprs in (instr_eval_operand_explicit i (fst oprs) s1, snd oprs) | IOpIm i -> (instr_eval_operand_implicit i s1, coerce oprs) in let f:arrow (instr_val_t i) (instr_args_t outs args) = coerce f in match v with | None -> () | Some v -> lemma_eq_instr_apply_eval_args outs args (f v) oprs s1 s2 )
{ "checked_file": "/", "dependencies": [ "Vale.X64.StateLemmas.fsti.checked", "Vale.X64.State.fsti.checked", "Vale.X64.Memory.fsti.checked", "Vale.X64.Machine_Semantics_s.fst.checked", "Vale.X64.Machine_s.fst.checked", "Vale.X64.Instruction_s.fsti.checked", "Vale.X64.Flags.fsti.checked", "Vale.X64.Bytes_Code_s.fst.checked", "prims.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.FunctionalExtensionality.fsti.checked" ], "interface_file": true, "source_file": "Vale.X64.Lemmas.fst" }
[ { "abbrev": true, "full_module": "Vale.X64.Memory", "short_module": "ME" }, { "abbrev": true, "full_module": "Vale.X64.Machine_Semantics_s", "short_module": "BS" }, { "abbrev": false, "full_module": "Vale.X64.Bytes_Code_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Instruction_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.StateLemmas", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.State", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Machine_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": true, "full_module": "Vale.Lib.Map16", "short_module": "Map16" }, { "abbrev": true, "full_module": "Vale.X64.Machine_Semantics_s", "short_module": "BS" }, { "abbrev": false, "full_module": "Vale.X64.Bytes_Code_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.StateLemmas", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.State", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Machine_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.HeapLemmas", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.HeapImpl", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.Heap", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 1, "initial_ifuel": 0, "max_fuel": 1, "max_ifuel": 1, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": true, "smtencoding_l_arith_repr": "native", "smtencoding_nl_arith_repr": "wrapped", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [ "smt.arith.nl=false", "smt.QI.EAGER_THRESHOLD=100", "smt.CASE_SPLIT=3" ], "z3refresh": false, "z3rlimit": 100, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
outs: Prims.list Vale.X64.Instruction_s.instr_out -> inouts: Prims.list Vale.X64.Instruction_s.instr_out -> args: Prims.list Vale.X64.Instruction_s.instr_operand -> f: Vale.X64.Instruction_s.instr_inouts_t outs inouts args -> oprs: Vale.X64.Instruction_s.instr_operands_t inouts args -> s1: Vale.X64.StateLemmas.machine_state -> s2: Vale.X64.StateLemmas.machine_state -> FStar.Pervasives.Lemma (requires Vale.X64.Lemmas.state_eq_S true s1 s2) (ensures Vale.X64.Machine_Semantics_s.instr_apply_eval_inouts outs inouts args f oprs s1 == Vale.X64.Machine_Semantics_s.instr_apply_eval_inouts outs inouts args f oprs s2)
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "Prims.list", "Vale.X64.Instruction_s.instr_out", "Vale.X64.Instruction_s.instr_operand", "Vale.X64.Instruction_s.instr_inouts_t", "Vale.X64.Instruction_s.instr_operands_t", "Vale.X64.StateLemmas.machine_state", "Vale.X64.Lemmas.lemma_eq_instr_apply_eval_args", "Vale.X64.Lemmas.lemma_eq_instr_apply_eval_inouts", "Vale.X64.Instruction_s.coerce", "Vale.X64.Instruction_s.instr_operand_explicit", "FStar.Pervasives.Native.snd", "Vale.X64.Instruction_s.instr_operand_t", "FStar.Pervasives.Native.tuple2", "Vale.X64.Instruction_s.instr_operand_implicit", "FStar.Pervasives.Native.option", "Vale.X64.Instruction_s.instr_val_t", "Prims.unit", "Vale.X64.Instruction_s.arrow", "FStar.Pervasives.Native.Mktuple2", "Vale.X64.Machine_Semantics_s.instr_eval_operand_explicit", "FStar.Pervasives.Native.fst", "Vale.X64.Machine_Semantics_s.instr_eval_operand_implicit", "Vale.Arch.HeapLemmas.lemma_heap_ignore_ghost_machine", "Vale.X64.Machine_Semantics_s.__proj__Mkmachine_state__item__ms_heap", "Vale.X64.Lemmas.state_eq_S", "Prims.squash", "Prims.eq2", "Vale.X64.Instruction_s.instr_ret_t", "Vale.X64.Machine_Semantics_s.instr_apply_eval_inouts", "Prims.Nil", "FStar.Pervasives.pattern" ]
[ "recursion" ]
false
false
true
false
false
let rec lemma_eq_instr_apply_eval_inouts (outs inouts: list instr_out) (args: list instr_operand) (f: instr_inouts_t outs inouts args) (oprs: instr_operands_t inouts args) (s1 s2: machine_state) : Lemma (requires state_eq_S true s1 s2) (ensures BS.instr_apply_eval_inouts outs inouts args f oprs s1 == BS.instr_apply_eval_inouts outs inouts args f oprs s2) =
let open BS in lemma_heap_ignore_ghost_machine s1.BS.ms_heap s2.BS.ms_heap; match inouts with | [] -> lemma_eq_instr_apply_eval_args outs args f oprs s1 s2 | (Out, i) :: inouts -> let oprs = match i with | IOpEx i -> snd #(instr_operand_t i) (coerce oprs) | IOpIm i -> coerce oprs in lemma_eq_instr_apply_eval_inouts outs inouts args (coerce f) oprs s1 s2 | (InOut, i) :: inouts -> (let v, oprs:option (instr_val_t i) & instr_operands_t inouts args = match i with | IOpEx i -> let oprs = coerce oprs in (instr_eval_operand_explicit i (fst oprs) s1, snd oprs) | IOpIm i -> (instr_eval_operand_implicit i s1, coerce oprs) in let f:arrow (instr_val_t i) (instr_inouts_t outs inouts args) = coerce f in match v with | None -> () | Some v -> lemma_eq_instr_apply_eval_inouts outs inouts args (f v) oprs s1 s2)
false
Vale.X64.Lemmas.fst
Vale.X64.Lemmas.lemma_cmp_ge
val lemma_cmp_ge (s:vale_state) (o1:operand64{not (OMem? o1 || OStack? o1)}) (o2:operand64{not (OMem? o2 || OStack? o2)}) : Lemma (ensures eval_ocmp s (OGe o1 o2) <==> eval_operand o1 s >= eval_operand o2 s) [SMTPat (eval_ocmp s (OGe o1 o2))]
val lemma_cmp_ge (s:vale_state) (o1:operand64{not (OMem? o1 || OStack? o1)}) (o2:operand64{not (OMem? o2 || OStack? o2)}) : Lemma (ensures eval_ocmp s (OGe o1 o2) <==> eval_operand o1 s >= eval_operand o2 s) [SMTPat (eval_ocmp s (OGe o1 o2))]
let lemma_cmp_ge s o1 o2 = reveal_opaque (`%BS.eval_ocmp_opaque) BS.eval_ocmp_opaque
{ "file_name": "vale/code/arch/x64/Vale.X64.Lemmas.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 84, "end_line": 336, "start_col": 0, "start_line": 336 }
module Vale.X64.Lemmas open FStar.Mul open Vale.X64.Machine_s open Vale.X64.State open Vale.X64.StateLemmas open Vale.X64.Instruction_s open Vale.X64.Bytes_Code_s module BS = Vale.X64.Machine_Semantics_s module ME = Vale.X64.Memory #reset-options "--initial_fuel 1 --max_fuel 1 --z3rlimit 100" #restart-solver let rec lemma_eq_instr_apply_eval_args (outs:list instr_out) (args:list instr_operand) (f:instr_args_t outs args) (oprs:instr_operands_t_args args) (s1 s2:machine_state) : Lemma (requires state_eq_S true s1 s2) (ensures BS.instr_apply_eval_args outs args f oprs s1 == BS.instr_apply_eval_args outs args f oprs s2) = let open BS in lemma_heap_ignore_ghost_machine s1.BS.ms_heap s2.BS.ms_heap; match args with | [] -> () | i::args -> ( let (v, oprs) : option (instr_val_t i) & instr_operands_t_args args = match i with | IOpEx i -> let oprs = coerce oprs in (instr_eval_operand_explicit i (fst oprs) s1, snd oprs) | IOpIm i -> (instr_eval_operand_implicit i s1, coerce oprs) in let f:arrow (instr_val_t i) (instr_args_t outs args) = coerce f in match v with | None -> () | Some v -> lemma_eq_instr_apply_eval_args outs args (f v) oprs s1 s2 ) #restart-solver let rec lemma_eq_instr_apply_eval_inouts (outs inouts:list instr_out) (args:list instr_operand) (f:instr_inouts_t outs inouts args) (oprs:instr_operands_t inouts args) (s1 s2:machine_state) : Lemma (requires state_eq_S true s1 s2) (ensures BS.instr_apply_eval_inouts outs inouts args f oprs s1 == BS.instr_apply_eval_inouts outs inouts args f oprs s2) = let open BS in lemma_heap_ignore_ghost_machine s1.BS.ms_heap s2.BS.ms_heap; match inouts with | [] -> lemma_eq_instr_apply_eval_args outs args f oprs s1 s2 | (Out, i)::inouts -> let oprs = match i with | IOpEx i -> snd #(instr_operand_t i) (coerce oprs) | IOpIm i -> coerce oprs in lemma_eq_instr_apply_eval_inouts outs inouts args (coerce f) oprs s1 s2 | (InOut, i)::inouts -> ( let (v, oprs) : option (instr_val_t i) & instr_operands_t inouts args = match i with | IOpEx i -> let oprs = coerce oprs in (instr_eval_operand_explicit i (fst oprs) s1, snd oprs) | IOpIm i -> (instr_eval_operand_implicit i s1, coerce oprs) in let f:arrow (instr_val_t i) (instr_inouts_t outs inouts args) = coerce f in match v with | None -> () | Some v -> lemma_eq_instr_apply_eval_inouts outs inouts args (f v) oprs s1 s2 ) #restart-solver #push-options "--z3rlimit_factor 2" let rec lemma_eq_instr_write_outputs (outs:list instr_out) (args:list instr_operand) (vs:instr_ret_t outs) (oprs:instr_operands_t outs args) (s1_orig s1 s2_orig s2:machine_state) : Lemma (requires state_eq_S true s1_orig s2_orig /\ state_eq_S true s1 s2) (ensures state_eq_S true (BS.instr_write_outputs outs args vs oprs s1_orig s1) (BS.instr_write_outputs outs args vs oprs s2_orig s2)) = let open BS in use_machine_state_equal (); lemma_heap_ignore_ghost_machine s1.BS.ms_heap s2.BS.ms_heap; lemma_heap_ignore_ghost_machine s1_orig.BS.ms_heap s2_orig.BS.ms_heap; allow_inversion tmaddr; match outs with | [] -> () | (_, i)::outs -> ( let ((v:instr_val_t i), (vs:instr_ret_t outs)) = match outs with | [] -> (vs, ()) | _::_ -> let vs = coerce vs in (fst vs, snd vs) in match i with | IOpEx i -> let oprs = coerce oprs in let s1 = instr_write_output_explicit i v (fst oprs) s1_orig s1 in let s2 = instr_write_output_explicit i v (fst oprs) s2_orig s2 in lemma_eq_instr_write_outputs outs args vs (snd oprs) s1_orig s1 s2_orig s2 | IOpIm i -> let s1 = instr_write_output_implicit i v s1_orig s1 in let s2 = instr_write_output_implicit i v s2_orig s2 in allow_inversion operand64; allow_inversion operand128; lemma_eq_instr_write_outputs outs args vs (coerce oprs) s1_orig s1 s2_orig s2 ) #pop-options #restart-solver let eval_ins_eq_instr (inst:BS.ins) (s1 s2:machine_state) : Lemma (requires Instr? inst /\ state_eq_S true s1 s2) (ensures state_eq_S true (BS.machine_eval_ins inst s1) (BS.machine_eval_ins inst s2)) = let open BS in let Instr it oprs ann = inst in let InstrTypeRecord #outs #args #havoc_flags' i = it in lemma_eq_instr_apply_eval_inouts outs outs args (instr_eval i) oprs s1 s2; let vs = instr_apply_eval outs args (instr_eval i) oprs s1 in let hav s = match havoc_flags' with | HavocFlags -> {s with ms_flags = havoc_flags} | PreserveFlags -> s in let s1' = hav s1 in let s2' = hav s2 in match vs with | None -> () | Some vs -> lemma_eq_instr_write_outputs outs args vs oprs s1 s1' s2 s2' let eval_code_eq_instr (inst:BS.ins) (f:fuel) (s1 s2:machine_state) : Lemma (requires Instr? inst /\ state_eq_S true s1 s2) (ensures state_eq_opt true (BS.machine_eval_code (Ins inst) f s1) (BS.machine_eval_code (Ins inst) f s2)) = reveal_opaque (`%BS.machine_eval_code_ins) BS.machine_eval_code_ins; eval_ins_eq_instr inst ({s1 with BS.ms_trace = []}) ({s2 with BS.ms_trace = []}) let eval_code_eq_dealloc (inst:BS.ins) (f:fuel) (s1 s2:machine_state) : Lemma (requires Dealloc? inst /\ state_eq_S true s1 s2) (ensures state_eq_opt true (BS.machine_eval_code (Ins inst) f s1) (BS.machine_eval_code (Ins inst) f s2)) = reveal_opaque (`%BS.machine_eval_code_ins) BS.machine_eval_code_ins; use_machine_state_equal (); lemma_heap_ignore_ghost_machine s1.BS.ms_heap s2.BS.ms_heap; allow_inversion tmaddr let eval_code_eq_alloc (inst:BS.ins) (f:fuel) (s1 s2:machine_state) : Lemma (requires Alloc? inst /\ state_eq_S true s1 s2) (ensures state_eq_opt true (BS.machine_eval_code (Ins inst) f s1) (BS.machine_eval_code (Ins inst) f s2)) = reveal_opaque (`%BS.machine_eval_code_ins) BS.machine_eval_code_ins; use_machine_state_equal (); lemma_heap_ignore_ghost_machine s1.BS.ms_heap s2.BS.ms_heap; allow_inversion tmaddr let eval_code_eq_push (inst:BS.ins) (f:fuel) (s1 s2:machine_state) : Lemma (requires Push? inst /\ state_eq_S true s1 s2) (ensures state_eq_opt true (BS.machine_eval_code (Ins inst) f s1) (BS.machine_eval_code (Ins inst) f s2)) = reveal_opaque (`%BS.machine_eval_code_ins) BS.machine_eval_code_ins; use_machine_state_equal (); lemma_heap_ignore_ghost_machine s1.BS.ms_heap s2.BS.ms_heap; allow_inversion tmaddr let eval_code_eq_pop (inst:BS.ins) (f:fuel) (s1 s2:machine_state) : Lemma (requires Pop? inst /\ state_eq_S true s1 s2) (ensures state_eq_opt true (BS.machine_eval_code (Ins inst) f s1) (BS.machine_eval_code (Ins inst) f s2)) = reveal_opaque (`%BS.machine_eval_code_ins) BS.machine_eval_code_ins; use_machine_state_equal (); lemma_heap_ignore_ghost_machine s1.BS.ms_heap s2.BS.ms_heap; allow_inversion tmaddr let eval_code_eq_ins (i:BS.ins) (f:fuel) (s1 s2:machine_state) : Lemma (requires state_eq_S true s1 s2) (ensures state_eq_opt true (BS.machine_eval_code (Ins i) f s1) (BS.machine_eval_code (Ins i) f s2)) = match i with | Instr _ _ _ -> eval_code_eq_instr i f s1 s2 | Dealloc _ -> eval_code_eq_dealloc i f s1 s2 | Alloc _ -> eval_code_eq_alloc i f s1 s2 | Push _ _ -> eval_code_eq_push i f s1 s2 | Pop _ _ -> eval_code_eq_pop i f s1 s2 #reset-options "--fuel 2 --z3rlimit 30" let eval_ocmp_eq_core (g:bool) (cond:ocmp) (s:machine_state) : Lemma (ensures ( let (s1, b1) = BS.machine_eval_ocmp s cond in let (s2, b2) = BS.machine_eval_ocmp (core_state g s) cond in state_eq_S g s1 s2 /\ b1 == b2 )) = reveal_opaque (`%BS.valid_ocmp_opaque) BS.valid_ocmp_opaque; reveal_opaque (`%BS.eval_ocmp_opaque) BS.eval_ocmp_opaque; () #restart-solver let rec eval_code_eq_core (g:bool) (c:code) (f:fuel) (s:machine_state) : Lemma (ensures state_eq_opt g (BS.machine_eval_code c f s) (BS.machine_eval_code c f (core_state g s))) (decreases %[f; c]) = match c with | Ins i -> reveal_opaque (`%BS.machine_eval_code_ins) BS.machine_eval_code_ins; if g then eval_code_eq_ins i f s (core_state g s) | Block cs -> eval_codes_eq_core g cs f s | IfElse cond ct cf -> eval_ocmp_eq_core g cond s; let (s', _) = BS.machine_eval_ocmp s cond in let (t', _) = BS.machine_eval_ocmp (core_state g s) cond in eval_code_eq_core g ct f s'; eval_code_eq_core g ct f t'; eval_code_eq_core g cf f s'; eval_code_eq_core g cf f t'; () | While cond body -> eval_while_eq_core g cond body f s and eval_codes_eq_core (g:bool) (cs:codes) (f:fuel) (s:machine_state) : Lemma (ensures state_eq_opt g (BS.machine_eval_codes cs f s) (BS.machine_eval_codes cs f (core_state g s))) (decreases %[f; cs]) = match cs with | [] -> () | c'::cs' -> ( eval_code_eq_core g c' f s; match (machine_eval_code c' f s, machine_eval_code c' f (core_state g s)) with | (None, None) -> () | (Some s', Some t') -> eval_codes_eq_core g cs' f s'; eval_codes_eq_core g cs' f t' ) and eval_while_eq_core (g:bool) (cond:ocmp) (body:code) (f:fuel) (s:machine_state) : Lemma (ensures state_eq_opt g (BS.machine_eval_while cond body f s) (BS.machine_eval_while cond body f (core_state g s))) (decreases %[f; body]) = if f > 0 then ( eval_ocmp_eq_core g cond s; let (s1, _) = BS.machine_eval_ocmp s cond in let (t1, _) = BS.machine_eval_ocmp (core_state g s) cond in eval_code_eq_core g body (f - 1) s1; eval_code_eq_core g body (f - 1) t1; match (BS.machine_eval_code body (f - 1) s1, BS.machine_eval_code body (f - 1) t1) with | (None, None) -> () | (Some s2, Some t2) -> eval_while_eq_core g cond body (f - 1) s2; eval_while_eq_core g cond body (f - 1) t2; () ) let eval_code_eq_f (c:code) (f:fuel) (s1 s2:machine_state) : Lemma (requires state_eq_S false s1 s2) (ensures state_eq_opt false (BS.machine_eval_code c f s1) (BS.machine_eval_code c f s2)) [SMTPat (BS.machine_eval_code c f s1); SMTPat (BS.machine_eval_code c f s2)] = eval_code_eq_core false c f s1; eval_code_eq_core false c f s2 let eval_codes_eq_f (cs:codes) (f:fuel) (s1 s2:machine_state) : Lemma (requires state_eq_S false s1 s2) (ensures state_eq_opt false (BS.machine_eval_codes cs f s1) (BS.machine_eval_codes cs f s2)) [SMTPat (BS.machine_eval_codes cs f s1); SMTPat (BS.machine_eval_codes cs f s2)] = eval_codes_eq_core false cs f s1; eval_codes_eq_core false cs f s2 let eval_while_eq_f (cond:ocmp) (body:code) (f:fuel) (s1 s2:machine_state) : Lemma (requires state_eq_S false s1 s2) (ensures state_eq_opt false (BS.machine_eval_while cond body f s1) (BS.machine_eval_while cond body f s2)) [SMTPat (BS.machine_eval_while cond body f s1); SMTPat (BS.machine_eval_while cond body f s2)] = eval_while_eq_core false cond body f s1; eval_while_eq_core false cond body f s2 let eval_code_eq_t (c:code) (f:fuel) (s1 s2:machine_state) : Lemma (requires state_eq_S true s1 s2) (ensures state_eq_opt true (BS.machine_eval_code c f s1) (BS.machine_eval_code c f s2)) [SMTPat (BS.machine_eval_code c f s1); SMTPat (BS.machine_eval_code c f s2)] = eval_code_eq_core true c f s1; eval_code_eq_core true c f s2 let eval_codes_eq_t (cs:codes) (f:fuel) (s1 s2:machine_state) : Lemma (requires state_eq_S true s1 s2) (ensures state_eq_opt true (BS.machine_eval_codes cs f s1) (BS.machine_eval_codes cs f s2)) [SMTPat (BS.machine_eval_codes cs f s1); SMTPat (BS.machine_eval_codes cs f s2)] = eval_codes_eq_core true cs f s1; eval_codes_eq_core true cs f s2 let eval_while_eq_t (cond:ocmp) (body:code) (f:fuel) (s1 s2:machine_state) : Lemma (requires state_eq_S true s1 s2) (ensures state_eq_opt true (BS.machine_eval_while cond body f s1) (BS.machine_eval_while cond body f s2)) [SMTPat (BS.machine_eval_while cond body f s1); SMTPat (BS.machine_eval_while cond body f s2)] = eval_while_eq_core true cond body f s1; eval_while_eq_core true cond body f s2 let eval_code_ts (g:bool) (c:code) (s0:machine_state) (f0:fuel) (s1:machine_state) : Type0 = state_eq_opt g (BS.machine_eval_code c f0 s0) (Some s1) let rec increase_fuel (g:bool) (c:code) (s0:machine_state) (f0:fuel) (sN:machine_state) (fN:fuel) : Lemma (requires eval_code_ts g c s0 f0 sN /\ f0 <= fN) (ensures eval_code_ts g c s0 fN sN) (decreases %[f0; c]) = match c with | Ins ins -> () | Block l -> increase_fuels g l s0 f0 sN fN | IfElse cond t f -> let (s0, b0) = BS.machine_eval_ocmp s0 cond in if b0 then increase_fuel g t s0 f0 sN fN else increase_fuel g f s0 f0 sN fN | While cond c -> let (s1, b0) = BS.machine_eval_ocmp s0 cond in if b0 then ( match BS.machine_eval_code c (f0 - 1) s1 with | None -> () | Some s2 -> increase_fuel g c s1 (f0 - 1) s2 (fN - 1); if s2.BS.ms_ok then increase_fuel g (While cond c) s2 (f0 - 1) sN (fN - 1) else () ) and increase_fuels (g:bool) (c:codes) (s0:machine_state) (f0:fuel) (sN:machine_state) (fN:fuel) : Lemma (requires eval_code_ts g (Block c) s0 f0 sN /\ f0 <= fN) (ensures eval_code_ts g (Block c) s0 fN sN) (decreases %[f0; c]) = match c with | [] -> () | h::t -> ( let Some s1 = BS.machine_eval_code h f0 s0 in increase_fuel g h s0 f0 s1 fN; increase_fuels g t s1 f0 sN fN ) let lemma_cmp_eq s o1 o2 = reveal_opaque (`%BS.eval_ocmp_opaque) BS.eval_ocmp_opaque let lemma_cmp_ne s o1 o2 = reveal_opaque (`%BS.eval_ocmp_opaque) BS.eval_ocmp_opaque
{ "checked_file": "/", "dependencies": [ "Vale.X64.StateLemmas.fsti.checked", "Vale.X64.State.fsti.checked", "Vale.X64.Memory.fsti.checked", "Vale.X64.Machine_Semantics_s.fst.checked", "Vale.X64.Machine_s.fst.checked", "Vale.X64.Instruction_s.fsti.checked", "Vale.X64.Flags.fsti.checked", "Vale.X64.Bytes_Code_s.fst.checked", "prims.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.FunctionalExtensionality.fsti.checked" ], "interface_file": true, "source_file": "Vale.X64.Lemmas.fst" }
[ { "abbrev": true, "full_module": "Vale.X64.Memory", "short_module": "ME" }, { "abbrev": true, "full_module": "Vale.X64.Machine_Semantics_s", "short_module": "BS" }, { "abbrev": false, "full_module": "Vale.X64.Bytes_Code_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Instruction_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.StateLemmas", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.State", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Machine_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": true, "full_module": "Vale.Lib.Map16", "short_module": "Map16" }, { "abbrev": true, "full_module": "Vale.X64.Machine_Semantics_s", "short_module": "BS" }, { "abbrev": false, "full_module": "Vale.X64.Bytes_Code_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.StateLemmas", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.State", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Machine_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.HeapLemmas", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.HeapImpl", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.Heap", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 0, "max_fuel": 2, "max_ifuel": 1, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": true, "smtencoding_l_arith_repr": "native", "smtencoding_nl_arith_repr": "wrapped", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [ "smt.arith.nl=false", "smt.QI.EAGER_THRESHOLD=100", "smt.CASE_SPLIT=3" ], "z3refresh": false, "z3rlimit": 30, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
s: Vale.X64.State.vale_state -> o1: Vale.X64.Machine_s.operand64{Prims.op_Negation (OMem? o1 || OStack? o1)} -> o2: Vale.X64.Machine_s.operand64{Prims.op_Negation (OMem? o2 || OStack? o2)} -> FStar.Pervasives.Lemma (ensures Vale.X64.Lemmas.eval_ocmp s (Vale.X64.Bytes_Code_s.OGe o1 o2) <==> Vale.X64.State.eval_operand o1 s >= Vale.X64.State.eval_operand o2 s) [SMTPat (Vale.X64.Lemmas.eval_ocmp s (Vale.X64.Bytes_Code_s.OGe o1 o2))]
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "Vale.X64.State.vale_state", "Vale.X64.Machine_s.operand64", "Prims.b2t", "Prims.op_Negation", "Prims.op_BarBar", "Vale.X64.Machine_s.uu___is_OMem", "Vale.X64.Machine_s.nat64", "Vale.X64.Machine_s.reg_64", "Vale.X64.Machine_s.uu___is_OStack", "FStar.Pervasives.reveal_opaque", "Vale.X64.Machine_Semantics_s.machine_state", "Vale.X64.Machine_Semantics_s.ocmp", "Prims.bool", "Vale.X64.Machine_Semantics_s.eval_ocmp_opaque", "Prims.unit" ]
[]
true
false
true
false
false
let lemma_cmp_ge s o1 o2 =
reveal_opaque (`%BS.eval_ocmp_opaque) BS.eval_ocmp_opaque
false
Vale.X64.Lemmas.fst
Vale.X64.Lemmas.eval_codes_eq_core
val eval_codes_eq_core (g: bool) (cs: codes) (f: fuel) (s: machine_state) : Lemma (ensures state_eq_opt g (BS.machine_eval_codes cs f s) (BS.machine_eval_codes cs f (core_state g s))) (decreases %[f;cs])
val eval_codes_eq_core (g: bool) (cs: codes) (f: fuel) (s: machine_state) : Lemma (ensures state_eq_opt g (BS.machine_eval_codes cs f s) (BS.machine_eval_codes cs f (core_state g s))) (decreases %[f;cs])
let rec eval_code_eq_core (g:bool) (c:code) (f:fuel) (s:machine_state) : Lemma (ensures state_eq_opt g (BS.machine_eval_code c f s) (BS.machine_eval_code c f (core_state g s))) (decreases %[f; c]) = match c with | Ins i -> reveal_opaque (`%BS.machine_eval_code_ins) BS.machine_eval_code_ins; if g then eval_code_eq_ins i f s (core_state g s) | Block cs -> eval_codes_eq_core g cs f s | IfElse cond ct cf -> eval_ocmp_eq_core g cond s; let (s', _) = BS.machine_eval_ocmp s cond in let (t', _) = BS.machine_eval_ocmp (core_state g s) cond in eval_code_eq_core g ct f s'; eval_code_eq_core g ct f t'; eval_code_eq_core g cf f s'; eval_code_eq_core g cf f t'; () | While cond body -> eval_while_eq_core g cond body f s and eval_codes_eq_core (g:bool) (cs:codes) (f:fuel) (s:machine_state) : Lemma (ensures state_eq_opt g (BS.machine_eval_codes cs f s) (BS.machine_eval_codes cs f (core_state g s))) (decreases %[f; cs]) = match cs with | [] -> () | c'::cs' -> ( eval_code_eq_core g c' f s; match (machine_eval_code c' f s, machine_eval_code c' f (core_state g s)) with | (None, None) -> () | (Some s', Some t') -> eval_codes_eq_core g cs' f s'; eval_codes_eq_core g cs' f t' ) and eval_while_eq_core (g:bool) (cond:ocmp) (body:code) (f:fuel) (s:machine_state) : Lemma (ensures state_eq_opt g (BS.machine_eval_while cond body f s) (BS.machine_eval_while cond body f (core_state g s))) (decreases %[f; body]) = if f > 0 then ( eval_ocmp_eq_core g cond s; let (s1, _) = BS.machine_eval_ocmp s cond in let (t1, _) = BS.machine_eval_ocmp (core_state g s) cond in eval_code_eq_core g body (f - 1) s1; eval_code_eq_core g body (f - 1) t1; match (BS.machine_eval_code body (f - 1) s1, BS.machine_eval_code body (f - 1) t1) with | (None, None) -> () | (Some s2, Some t2) -> eval_while_eq_core g cond body (f - 1) s2; eval_while_eq_core g cond body (f - 1) t2; () )
{ "file_name": "vale/code/arch/x64/Vale.X64.Lemmas.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 3, "end_line": 251, "start_col": 0, "start_line": 204 }
module Vale.X64.Lemmas open FStar.Mul open Vale.X64.Machine_s open Vale.X64.State open Vale.X64.StateLemmas open Vale.X64.Instruction_s open Vale.X64.Bytes_Code_s module BS = Vale.X64.Machine_Semantics_s module ME = Vale.X64.Memory #reset-options "--initial_fuel 1 --max_fuel 1 --z3rlimit 100" #restart-solver let rec lemma_eq_instr_apply_eval_args (outs:list instr_out) (args:list instr_operand) (f:instr_args_t outs args) (oprs:instr_operands_t_args args) (s1 s2:machine_state) : Lemma (requires state_eq_S true s1 s2) (ensures BS.instr_apply_eval_args outs args f oprs s1 == BS.instr_apply_eval_args outs args f oprs s2) = let open BS in lemma_heap_ignore_ghost_machine s1.BS.ms_heap s2.BS.ms_heap; match args with | [] -> () | i::args -> ( let (v, oprs) : option (instr_val_t i) & instr_operands_t_args args = match i with | IOpEx i -> let oprs = coerce oprs in (instr_eval_operand_explicit i (fst oprs) s1, snd oprs) | IOpIm i -> (instr_eval_operand_implicit i s1, coerce oprs) in let f:arrow (instr_val_t i) (instr_args_t outs args) = coerce f in match v with | None -> () | Some v -> lemma_eq_instr_apply_eval_args outs args (f v) oprs s1 s2 ) #restart-solver let rec lemma_eq_instr_apply_eval_inouts (outs inouts:list instr_out) (args:list instr_operand) (f:instr_inouts_t outs inouts args) (oprs:instr_operands_t inouts args) (s1 s2:machine_state) : Lemma (requires state_eq_S true s1 s2) (ensures BS.instr_apply_eval_inouts outs inouts args f oprs s1 == BS.instr_apply_eval_inouts outs inouts args f oprs s2) = let open BS in lemma_heap_ignore_ghost_machine s1.BS.ms_heap s2.BS.ms_heap; match inouts with | [] -> lemma_eq_instr_apply_eval_args outs args f oprs s1 s2 | (Out, i)::inouts -> let oprs = match i with | IOpEx i -> snd #(instr_operand_t i) (coerce oprs) | IOpIm i -> coerce oprs in lemma_eq_instr_apply_eval_inouts outs inouts args (coerce f) oprs s1 s2 | (InOut, i)::inouts -> ( let (v, oprs) : option (instr_val_t i) & instr_operands_t inouts args = match i with | IOpEx i -> let oprs = coerce oprs in (instr_eval_operand_explicit i (fst oprs) s1, snd oprs) | IOpIm i -> (instr_eval_operand_implicit i s1, coerce oprs) in let f:arrow (instr_val_t i) (instr_inouts_t outs inouts args) = coerce f in match v with | None -> () | Some v -> lemma_eq_instr_apply_eval_inouts outs inouts args (f v) oprs s1 s2 ) #restart-solver #push-options "--z3rlimit_factor 2" let rec lemma_eq_instr_write_outputs (outs:list instr_out) (args:list instr_operand) (vs:instr_ret_t outs) (oprs:instr_operands_t outs args) (s1_orig s1 s2_orig s2:machine_state) : Lemma (requires state_eq_S true s1_orig s2_orig /\ state_eq_S true s1 s2) (ensures state_eq_S true (BS.instr_write_outputs outs args vs oprs s1_orig s1) (BS.instr_write_outputs outs args vs oprs s2_orig s2)) = let open BS in use_machine_state_equal (); lemma_heap_ignore_ghost_machine s1.BS.ms_heap s2.BS.ms_heap; lemma_heap_ignore_ghost_machine s1_orig.BS.ms_heap s2_orig.BS.ms_heap; allow_inversion tmaddr; match outs with | [] -> () | (_, i)::outs -> ( let ((v:instr_val_t i), (vs:instr_ret_t outs)) = match outs with | [] -> (vs, ()) | _::_ -> let vs = coerce vs in (fst vs, snd vs) in match i with | IOpEx i -> let oprs = coerce oprs in let s1 = instr_write_output_explicit i v (fst oprs) s1_orig s1 in let s2 = instr_write_output_explicit i v (fst oprs) s2_orig s2 in lemma_eq_instr_write_outputs outs args vs (snd oprs) s1_orig s1 s2_orig s2 | IOpIm i -> let s1 = instr_write_output_implicit i v s1_orig s1 in let s2 = instr_write_output_implicit i v s2_orig s2 in allow_inversion operand64; allow_inversion operand128; lemma_eq_instr_write_outputs outs args vs (coerce oprs) s1_orig s1 s2_orig s2 ) #pop-options #restart-solver let eval_ins_eq_instr (inst:BS.ins) (s1 s2:machine_state) : Lemma (requires Instr? inst /\ state_eq_S true s1 s2) (ensures state_eq_S true (BS.machine_eval_ins inst s1) (BS.machine_eval_ins inst s2)) = let open BS in let Instr it oprs ann = inst in let InstrTypeRecord #outs #args #havoc_flags' i = it in lemma_eq_instr_apply_eval_inouts outs outs args (instr_eval i) oprs s1 s2; let vs = instr_apply_eval outs args (instr_eval i) oprs s1 in let hav s = match havoc_flags' with | HavocFlags -> {s with ms_flags = havoc_flags} | PreserveFlags -> s in let s1' = hav s1 in let s2' = hav s2 in match vs with | None -> () | Some vs -> lemma_eq_instr_write_outputs outs args vs oprs s1 s1' s2 s2' let eval_code_eq_instr (inst:BS.ins) (f:fuel) (s1 s2:machine_state) : Lemma (requires Instr? inst /\ state_eq_S true s1 s2) (ensures state_eq_opt true (BS.machine_eval_code (Ins inst) f s1) (BS.machine_eval_code (Ins inst) f s2)) = reveal_opaque (`%BS.machine_eval_code_ins) BS.machine_eval_code_ins; eval_ins_eq_instr inst ({s1 with BS.ms_trace = []}) ({s2 with BS.ms_trace = []}) let eval_code_eq_dealloc (inst:BS.ins) (f:fuel) (s1 s2:machine_state) : Lemma (requires Dealloc? inst /\ state_eq_S true s1 s2) (ensures state_eq_opt true (BS.machine_eval_code (Ins inst) f s1) (BS.machine_eval_code (Ins inst) f s2)) = reveal_opaque (`%BS.machine_eval_code_ins) BS.machine_eval_code_ins; use_machine_state_equal (); lemma_heap_ignore_ghost_machine s1.BS.ms_heap s2.BS.ms_heap; allow_inversion tmaddr let eval_code_eq_alloc (inst:BS.ins) (f:fuel) (s1 s2:machine_state) : Lemma (requires Alloc? inst /\ state_eq_S true s1 s2) (ensures state_eq_opt true (BS.machine_eval_code (Ins inst) f s1) (BS.machine_eval_code (Ins inst) f s2)) = reveal_opaque (`%BS.machine_eval_code_ins) BS.machine_eval_code_ins; use_machine_state_equal (); lemma_heap_ignore_ghost_machine s1.BS.ms_heap s2.BS.ms_heap; allow_inversion tmaddr let eval_code_eq_push (inst:BS.ins) (f:fuel) (s1 s2:machine_state) : Lemma (requires Push? inst /\ state_eq_S true s1 s2) (ensures state_eq_opt true (BS.machine_eval_code (Ins inst) f s1) (BS.machine_eval_code (Ins inst) f s2)) = reveal_opaque (`%BS.machine_eval_code_ins) BS.machine_eval_code_ins; use_machine_state_equal (); lemma_heap_ignore_ghost_machine s1.BS.ms_heap s2.BS.ms_heap; allow_inversion tmaddr let eval_code_eq_pop (inst:BS.ins) (f:fuel) (s1 s2:machine_state) : Lemma (requires Pop? inst /\ state_eq_S true s1 s2) (ensures state_eq_opt true (BS.machine_eval_code (Ins inst) f s1) (BS.machine_eval_code (Ins inst) f s2)) = reveal_opaque (`%BS.machine_eval_code_ins) BS.machine_eval_code_ins; use_machine_state_equal (); lemma_heap_ignore_ghost_machine s1.BS.ms_heap s2.BS.ms_heap; allow_inversion tmaddr let eval_code_eq_ins (i:BS.ins) (f:fuel) (s1 s2:machine_state) : Lemma (requires state_eq_S true s1 s2) (ensures state_eq_opt true (BS.machine_eval_code (Ins i) f s1) (BS.machine_eval_code (Ins i) f s2)) = match i with | Instr _ _ _ -> eval_code_eq_instr i f s1 s2 | Dealloc _ -> eval_code_eq_dealloc i f s1 s2 | Alloc _ -> eval_code_eq_alloc i f s1 s2 | Push _ _ -> eval_code_eq_push i f s1 s2 | Pop _ _ -> eval_code_eq_pop i f s1 s2 #reset-options "--fuel 2 --z3rlimit 30" let eval_ocmp_eq_core (g:bool) (cond:ocmp) (s:machine_state) : Lemma (ensures ( let (s1, b1) = BS.machine_eval_ocmp s cond in let (s2, b2) = BS.machine_eval_ocmp (core_state g s) cond in state_eq_S g s1 s2 /\ b1 == b2 )) = reveal_opaque (`%BS.valid_ocmp_opaque) BS.valid_ocmp_opaque; reveal_opaque (`%BS.eval_ocmp_opaque) BS.eval_ocmp_opaque; ()
{ "checked_file": "/", "dependencies": [ "Vale.X64.StateLemmas.fsti.checked", "Vale.X64.State.fsti.checked", "Vale.X64.Memory.fsti.checked", "Vale.X64.Machine_Semantics_s.fst.checked", "Vale.X64.Machine_s.fst.checked", "Vale.X64.Instruction_s.fsti.checked", "Vale.X64.Flags.fsti.checked", "Vale.X64.Bytes_Code_s.fst.checked", "prims.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.FunctionalExtensionality.fsti.checked" ], "interface_file": true, "source_file": "Vale.X64.Lemmas.fst" }
[ { "abbrev": true, "full_module": "Vale.X64.Memory", "short_module": "ME" }, { "abbrev": true, "full_module": "Vale.X64.Machine_Semantics_s", "short_module": "BS" }, { "abbrev": false, "full_module": "Vale.X64.Bytes_Code_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Instruction_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.StateLemmas", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.State", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Machine_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": true, "full_module": "Vale.Lib.Map16", "short_module": "Map16" }, { "abbrev": true, "full_module": "Vale.X64.Machine_Semantics_s", "short_module": "BS" }, { "abbrev": false, "full_module": "Vale.X64.Bytes_Code_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.StateLemmas", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.State", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Machine_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.HeapLemmas", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.HeapImpl", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.Heap", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 0, "max_fuel": 2, "max_ifuel": 1, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": true, "smtencoding_l_arith_repr": "native", "smtencoding_nl_arith_repr": "wrapped", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [ "smt.arith.nl=false", "smt.QI.EAGER_THRESHOLD=100", "smt.CASE_SPLIT=3" ], "z3refresh": false, "z3rlimit": 30, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
g: Prims.bool -> cs: Vale.X64.Lemmas.codes -> f: Vale.X64.Lemmas.fuel -> s: Vale.X64.StateLemmas.machine_state -> FStar.Pervasives.Lemma (ensures Vale.X64.Lemmas.state_eq_opt g (Vale.X64.Machine_Semantics_s.machine_eval_codes cs f s) (Vale.X64.Machine_Semantics_s.machine_eval_codes cs f (Vale.X64.Lemmas.core_state g s))) (decreases %[f;cs])
FStar.Pervasives.Lemma
[ "lemma", "" ]
[ "eval_code_eq_core", "eval_codes_eq_core", "eval_while_eq_core" ]
[ "Prims.bool", "Vale.X64.Lemmas.codes", "Vale.X64.Lemmas.fuel", "Vale.X64.StateLemmas.machine_state", "Vale.X64.Bytes_Code_s.code_t", "Vale.X64.Machine_Semantics_s.instr_annotation", "Prims.list", "FStar.Pervasives.Native.Mktuple2", "FStar.Pervasives.Native.option", "Vale.X64.Machine_Semantics_s.machine_state", "Vale.X64.StateLemmas.machine_eval_code", "Vale.X64.Lemmas.core_state", "Vale.X64.Lemmas.eval_codes_eq_core", "Prims.unit", "Vale.X64.Lemmas.eval_code_eq_core", "Prims.l_True", "Prims.squash", "Vale.X64.Lemmas.state_eq_opt", "Vale.X64.Machine_Semantics_s.machine_eval_codes", "Prims.Nil", "FStar.Pervasives.pattern" ]
[ "mutual recursion" ]
false
false
true
false
false
let rec eval_codes_eq_core (g: bool) (cs: codes) (f: fuel) (s: machine_state) : Lemma (ensures state_eq_opt g (BS.machine_eval_codes cs f s) (BS.machine_eval_codes cs f (core_state g s))) (decreases %[f;cs]) =
match cs with | [] -> () | c' :: cs' -> (eval_code_eq_core g c' f s; match (machine_eval_code c' f s, machine_eval_code c' f (core_state g s)) with | None, None -> () | Some s', Some t' -> eval_codes_eq_core g cs' f s'; eval_codes_eq_core g cs' f t')
false
Vale.X64.Lemmas.fst
Vale.X64.Lemmas.lemma_cmp_lt
val lemma_cmp_lt (s:vale_state) (o1:operand64{not (OMem? o1 || OStack? o1)}) (o2:operand64{not (OMem? o2 || OStack? o2)}) : Lemma (ensures eval_ocmp s (OLt o1 o2) <==> eval_operand o1 s < eval_operand o2 s) [SMTPat (eval_ocmp s (OLt o1 o2))]
val lemma_cmp_lt (s:vale_state) (o1:operand64{not (OMem? o1 || OStack? o1)}) (o2:operand64{not (OMem? o2 || OStack? o2)}) : Lemma (ensures eval_ocmp s (OLt o1 o2) <==> eval_operand o1 s < eval_operand o2 s) [SMTPat (eval_ocmp s (OLt o1 o2))]
let lemma_cmp_lt s o1 o2 = reveal_opaque (`%BS.eval_ocmp_opaque) BS.eval_ocmp_opaque
{ "file_name": "vale/code/arch/x64/Vale.X64.Lemmas.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 84, "end_line": 337, "start_col": 0, "start_line": 337 }
module Vale.X64.Lemmas open FStar.Mul open Vale.X64.Machine_s open Vale.X64.State open Vale.X64.StateLemmas open Vale.X64.Instruction_s open Vale.X64.Bytes_Code_s module BS = Vale.X64.Machine_Semantics_s module ME = Vale.X64.Memory #reset-options "--initial_fuel 1 --max_fuel 1 --z3rlimit 100" #restart-solver let rec lemma_eq_instr_apply_eval_args (outs:list instr_out) (args:list instr_operand) (f:instr_args_t outs args) (oprs:instr_operands_t_args args) (s1 s2:machine_state) : Lemma (requires state_eq_S true s1 s2) (ensures BS.instr_apply_eval_args outs args f oprs s1 == BS.instr_apply_eval_args outs args f oprs s2) = let open BS in lemma_heap_ignore_ghost_machine s1.BS.ms_heap s2.BS.ms_heap; match args with | [] -> () | i::args -> ( let (v, oprs) : option (instr_val_t i) & instr_operands_t_args args = match i with | IOpEx i -> let oprs = coerce oprs in (instr_eval_operand_explicit i (fst oprs) s1, snd oprs) | IOpIm i -> (instr_eval_operand_implicit i s1, coerce oprs) in let f:arrow (instr_val_t i) (instr_args_t outs args) = coerce f in match v with | None -> () | Some v -> lemma_eq_instr_apply_eval_args outs args (f v) oprs s1 s2 ) #restart-solver let rec lemma_eq_instr_apply_eval_inouts (outs inouts:list instr_out) (args:list instr_operand) (f:instr_inouts_t outs inouts args) (oprs:instr_operands_t inouts args) (s1 s2:machine_state) : Lemma (requires state_eq_S true s1 s2) (ensures BS.instr_apply_eval_inouts outs inouts args f oprs s1 == BS.instr_apply_eval_inouts outs inouts args f oprs s2) = let open BS in lemma_heap_ignore_ghost_machine s1.BS.ms_heap s2.BS.ms_heap; match inouts with | [] -> lemma_eq_instr_apply_eval_args outs args f oprs s1 s2 | (Out, i)::inouts -> let oprs = match i with | IOpEx i -> snd #(instr_operand_t i) (coerce oprs) | IOpIm i -> coerce oprs in lemma_eq_instr_apply_eval_inouts outs inouts args (coerce f) oprs s1 s2 | (InOut, i)::inouts -> ( let (v, oprs) : option (instr_val_t i) & instr_operands_t inouts args = match i with | IOpEx i -> let oprs = coerce oprs in (instr_eval_operand_explicit i (fst oprs) s1, snd oprs) | IOpIm i -> (instr_eval_operand_implicit i s1, coerce oprs) in let f:arrow (instr_val_t i) (instr_inouts_t outs inouts args) = coerce f in match v with | None -> () | Some v -> lemma_eq_instr_apply_eval_inouts outs inouts args (f v) oprs s1 s2 ) #restart-solver #push-options "--z3rlimit_factor 2" let rec lemma_eq_instr_write_outputs (outs:list instr_out) (args:list instr_operand) (vs:instr_ret_t outs) (oprs:instr_operands_t outs args) (s1_orig s1 s2_orig s2:machine_state) : Lemma (requires state_eq_S true s1_orig s2_orig /\ state_eq_S true s1 s2) (ensures state_eq_S true (BS.instr_write_outputs outs args vs oprs s1_orig s1) (BS.instr_write_outputs outs args vs oprs s2_orig s2)) = let open BS in use_machine_state_equal (); lemma_heap_ignore_ghost_machine s1.BS.ms_heap s2.BS.ms_heap; lemma_heap_ignore_ghost_machine s1_orig.BS.ms_heap s2_orig.BS.ms_heap; allow_inversion tmaddr; match outs with | [] -> () | (_, i)::outs -> ( let ((v:instr_val_t i), (vs:instr_ret_t outs)) = match outs with | [] -> (vs, ()) | _::_ -> let vs = coerce vs in (fst vs, snd vs) in match i with | IOpEx i -> let oprs = coerce oprs in let s1 = instr_write_output_explicit i v (fst oprs) s1_orig s1 in let s2 = instr_write_output_explicit i v (fst oprs) s2_orig s2 in lemma_eq_instr_write_outputs outs args vs (snd oprs) s1_orig s1 s2_orig s2 | IOpIm i -> let s1 = instr_write_output_implicit i v s1_orig s1 in let s2 = instr_write_output_implicit i v s2_orig s2 in allow_inversion operand64; allow_inversion operand128; lemma_eq_instr_write_outputs outs args vs (coerce oprs) s1_orig s1 s2_orig s2 ) #pop-options #restart-solver let eval_ins_eq_instr (inst:BS.ins) (s1 s2:machine_state) : Lemma (requires Instr? inst /\ state_eq_S true s1 s2) (ensures state_eq_S true (BS.machine_eval_ins inst s1) (BS.machine_eval_ins inst s2)) = let open BS in let Instr it oprs ann = inst in let InstrTypeRecord #outs #args #havoc_flags' i = it in lemma_eq_instr_apply_eval_inouts outs outs args (instr_eval i) oprs s1 s2; let vs = instr_apply_eval outs args (instr_eval i) oprs s1 in let hav s = match havoc_flags' with | HavocFlags -> {s with ms_flags = havoc_flags} | PreserveFlags -> s in let s1' = hav s1 in let s2' = hav s2 in match vs with | None -> () | Some vs -> lemma_eq_instr_write_outputs outs args vs oprs s1 s1' s2 s2' let eval_code_eq_instr (inst:BS.ins) (f:fuel) (s1 s2:machine_state) : Lemma (requires Instr? inst /\ state_eq_S true s1 s2) (ensures state_eq_opt true (BS.machine_eval_code (Ins inst) f s1) (BS.machine_eval_code (Ins inst) f s2)) = reveal_opaque (`%BS.machine_eval_code_ins) BS.machine_eval_code_ins; eval_ins_eq_instr inst ({s1 with BS.ms_trace = []}) ({s2 with BS.ms_trace = []}) let eval_code_eq_dealloc (inst:BS.ins) (f:fuel) (s1 s2:machine_state) : Lemma (requires Dealloc? inst /\ state_eq_S true s1 s2) (ensures state_eq_opt true (BS.machine_eval_code (Ins inst) f s1) (BS.machine_eval_code (Ins inst) f s2)) = reveal_opaque (`%BS.machine_eval_code_ins) BS.machine_eval_code_ins; use_machine_state_equal (); lemma_heap_ignore_ghost_machine s1.BS.ms_heap s2.BS.ms_heap; allow_inversion tmaddr let eval_code_eq_alloc (inst:BS.ins) (f:fuel) (s1 s2:machine_state) : Lemma (requires Alloc? inst /\ state_eq_S true s1 s2) (ensures state_eq_opt true (BS.machine_eval_code (Ins inst) f s1) (BS.machine_eval_code (Ins inst) f s2)) = reveal_opaque (`%BS.machine_eval_code_ins) BS.machine_eval_code_ins; use_machine_state_equal (); lemma_heap_ignore_ghost_machine s1.BS.ms_heap s2.BS.ms_heap; allow_inversion tmaddr let eval_code_eq_push (inst:BS.ins) (f:fuel) (s1 s2:machine_state) : Lemma (requires Push? inst /\ state_eq_S true s1 s2) (ensures state_eq_opt true (BS.machine_eval_code (Ins inst) f s1) (BS.machine_eval_code (Ins inst) f s2)) = reveal_opaque (`%BS.machine_eval_code_ins) BS.machine_eval_code_ins; use_machine_state_equal (); lemma_heap_ignore_ghost_machine s1.BS.ms_heap s2.BS.ms_heap; allow_inversion tmaddr let eval_code_eq_pop (inst:BS.ins) (f:fuel) (s1 s2:machine_state) : Lemma (requires Pop? inst /\ state_eq_S true s1 s2) (ensures state_eq_opt true (BS.machine_eval_code (Ins inst) f s1) (BS.machine_eval_code (Ins inst) f s2)) = reveal_opaque (`%BS.machine_eval_code_ins) BS.machine_eval_code_ins; use_machine_state_equal (); lemma_heap_ignore_ghost_machine s1.BS.ms_heap s2.BS.ms_heap; allow_inversion tmaddr let eval_code_eq_ins (i:BS.ins) (f:fuel) (s1 s2:machine_state) : Lemma (requires state_eq_S true s1 s2) (ensures state_eq_opt true (BS.machine_eval_code (Ins i) f s1) (BS.machine_eval_code (Ins i) f s2)) = match i with | Instr _ _ _ -> eval_code_eq_instr i f s1 s2 | Dealloc _ -> eval_code_eq_dealloc i f s1 s2 | Alloc _ -> eval_code_eq_alloc i f s1 s2 | Push _ _ -> eval_code_eq_push i f s1 s2 | Pop _ _ -> eval_code_eq_pop i f s1 s2 #reset-options "--fuel 2 --z3rlimit 30" let eval_ocmp_eq_core (g:bool) (cond:ocmp) (s:machine_state) : Lemma (ensures ( let (s1, b1) = BS.machine_eval_ocmp s cond in let (s2, b2) = BS.machine_eval_ocmp (core_state g s) cond in state_eq_S g s1 s2 /\ b1 == b2 )) = reveal_opaque (`%BS.valid_ocmp_opaque) BS.valid_ocmp_opaque; reveal_opaque (`%BS.eval_ocmp_opaque) BS.eval_ocmp_opaque; () #restart-solver let rec eval_code_eq_core (g:bool) (c:code) (f:fuel) (s:machine_state) : Lemma (ensures state_eq_opt g (BS.machine_eval_code c f s) (BS.machine_eval_code c f (core_state g s))) (decreases %[f; c]) = match c with | Ins i -> reveal_opaque (`%BS.machine_eval_code_ins) BS.machine_eval_code_ins; if g then eval_code_eq_ins i f s (core_state g s) | Block cs -> eval_codes_eq_core g cs f s | IfElse cond ct cf -> eval_ocmp_eq_core g cond s; let (s', _) = BS.machine_eval_ocmp s cond in let (t', _) = BS.machine_eval_ocmp (core_state g s) cond in eval_code_eq_core g ct f s'; eval_code_eq_core g ct f t'; eval_code_eq_core g cf f s'; eval_code_eq_core g cf f t'; () | While cond body -> eval_while_eq_core g cond body f s and eval_codes_eq_core (g:bool) (cs:codes) (f:fuel) (s:machine_state) : Lemma (ensures state_eq_opt g (BS.machine_eval_codes cs f s) (BS.machine_eval_codes cs f (core_state g s))) (decreases %[f; cs]) = match cs with | [] -> () | c'::cs' -> ( eval_code_eq_core g c' f s; match (machine_eval_code c' f s, machine_eval_code c' f (core_state g s)) with | (None, None) -> () | (Some s', Some t') -> eval_codes_eq_core g cs' f s'; eval_codes_eq_core g cs' f t' ) and eval_while_eq_core (g:bool) (cond:ocmp) (body:code) (f:fuel) (s:machine_state) : Lemma (ensures state_eq_opt g (BS.machine_eval_while cond body f s) (BS.machine_eval_while cond body f (core_state g s))) (decreases %[f; body]) = if f > 0 then ( eval_ocmp_eq_core g cond s; let (s1, _) = BS.machine_eval_ocmp s cond in let (t1, _) = BS.machine_eval_ocmp (core_state g s) cond in eval_code_eq_core g body (f - 1) s1; eval_code_eq_core g body (f - 1) t1; match (BS.machine_eval_code body (f - 1) s1, BS.machine_eval_code body (f - 1) t1) with | (None, None) -> () | (Some s2, Some t2) -> eval_while_eq_core g cond body (f - 1) s2; eval_while_eq_core g cond body (f - 1) t2; () ) let eval_code_eq_f (c:code) (f:fuel) (s1 s2:machine_state) : Lemma (requires state_eq_S false s1 s2) (ensures state_eq_opt false (BS.machine_eval_code c f s1) (BS.machine_eval_code c f s2)) [SMTPat (BS.machine_eval_code c f s1); SMTPat (BS.machine_eval_code c f s2)] = eval_code_eq_core false c f s1; eval_code_eq_core false c f s2 let eval_codes_eq_f (cs:codes) (f:fuel) (s1 s2:machine_state) : Lemma (requires state_eq_S false s1 s2) (ensures state_eq_opt false (BS.machine_eval_codes cs f s1) (BS.machine_eval_codes cs f s2)) [SMTPat (BS.machine_eval_codes cs f s1); SMTPat (BS.machine_eval_codes cs f s2)] = eval_codes_eq_core false cs f s1; eval_codes_eq_core false cs f s2 let eval_while_eq_f (cond:ocmp) (body:code) (f:fuel) (s1 s2:machine_state) : Lemma (requires state_eq_S false s1 s2) (ensures state_eq_opt false (BS.machine_eval_while cond body f s1) (BS.machine_eval_while cond body f s2)) [SMTPat (BS.machine_eval_while cond body f s1); SMTPat (BS.machine_eval_while cond body f s2)] = eval_while_eq_core false cond body f s1; eval_while_eq_core false cond body f s2 let eval_code_eq_t (c:code) (f:fuel) (s1 s2:machine_state) : Lemma (requires state_eq_S true s1 s2) (ensures state_eq_opt true (BS.machine_eval_code c f s1) (BS.machine_eval_code c f s2)) [SMTPat (BS.machine_eval_code c f s1); SMTPat (BS.machine_eval_code c f s2)] = eval_code_eq_core true c f s1; eval_code_eq_core true c f s2 let eval_codes_eq_t (cs:codes) (f:fuel) (s1 s2:machine_state) : Lemma (requires state_eq_S true s1 s2) (ensures state_eq_opt true (BS.machine_eval_codes cs f s1) (BS.machine_eval_codes cs f s2)) [SMTPat (BS.machine_eval_codes cs f s1); SMTPat (BS.machine_eval_codes cs f s2)] = eval_codes_eq_core true cs f s1; eval_codes_eq_core true cs f s2 let eval_while_eq_t (cond:ocmp) (body:code) (f:fuel) (s1 s2:machine_state) : Lemma (requires state_eq_S true s1 s2) (ensures state_eq_opt true (BS.machine_eval_while cond body f s1) (BS.machine_eval_while cond body f s2)) [SMTPat (BS.machine_eval_while cond body f s1); SMTPat (BS.machine_eval_while cond body f s2)] = eval_while_eq_core true cond body f s1; eval_while_eq_core true cond body f s2 let eval_code_ts (g:bool) (c:code) (s0:machine_state) (f0:fuel) (s1:machine_state) : Type0 = state_eq_opt g (BS.machine_eval_code c f0 s0) (Some s1) let rec increase_fuel (g:bool) (c:code) (s0:machine_state) (f0:fuel) (sN:machine_state) (fN:fuel) : Lemma (requires eval_code_ts g c s0 f0 sN /\ f0 <= fN) (ensures eval_code_ts g c s0 fN sN) (decreases %[f0; c]) = match c with | Ins ins -> () | Block l -> increase_fuels g l s0 f0 sN fN | IfElse cond t f -> let (s0, b0) = BS.machine_eval_ocmp s0 cond in if b0 then increase_fuel g t s0 f0 sN fN else increase_fuel g f s0 f0 sN fN | While cond c -> let (s1, b0) = BS.machine_eval_ocmp s0 cond in if b0 then ( match BS.machine_eval_code c (f0 - 1) s1 with | None -> () | Some s2 -> increase_fuel g c s1 (f0 - 1) s2 (fN - 1); if s2.BS.ms_ok then increase_fuel g (While cond c) s2 (f0 - 1) sN (fN - 1) else () ) and increase_fuels (g:bool) (c:codes) (s0:machine_state) (f0:fuel) (sN:machine_state) (fN:fuel) : Lemma (requires eval_code_ts g (Block c) s0 f0 sN /\ f0 <= fN) (ensures eval_code_ts g (Block c) s0 fN sN) (decreases %[f0; c]) = match c with | [] -> () | h::t -> ( let Some s1 = BS.machine_eval_code h f0 s0 in increase_fuel g h s0 f0 s1 fN; increase_fuels g t s1 f0 sN fN ) let lemma_cmp_eq s o1 o2 = reveal_opaque (`%BS.eval_ocmp_opaque) BS.eval_ocmp_opaque let lemma_cmp_ne s o1 o2 = reveal_opaque (`%BS.eval_ocmp_opaque) BS.eval_ocmp_opaque let lemma_cmp_le s o1 o2 = reveal_opaque (`%BS.eval_ocmp_opaque) BS.eval_ocmp_opaque
{ "checked_file": "/", "dependencies": [ "Vale.X64.StateLemmas.fsti.checked", "Vale.X64.State.fsti.checked", "Vale.X64.Memory.fsti.checked", "Vale.X64.Machine_Semantics_s.fst.checked", "Vale.X64.Machine_s.fst.checked", "Vale.X64.Instruction_s.fsti.checked", "Vale.X64.Flags.fsti.checked", "Vale.X64.Bytes_Code_s.fst.checked", "prims.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.FunctionalExtensionality.fsti.checked" ], "interface_file": true, "source_file": "Vale.X64.Lemmas.fst" }
[ { "abbrev": true, "full_module": "Vale.X64.Memory", "short_module": "ME" }, { "abbrev": true, "full_module": "Vale.X64.Machine_Semantics_s", "short_module": "BS" }, { "abbrev": false, "full_module": "Vale.X64.Bytes_Code_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Instruction_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.StateLemmas", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.State", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Machine_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": true, "full_module": "Vale.Lib.Map16", "short_module": "Map16" }, { "abbrev": true, "full_module": "Vale.X64.Machine_Semantics_s", "short_module": "BS" }, { "abbrev": false, "full_module": "Vale.X64.Bytes_Code_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.StateLemmas", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.State", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Machine_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.HeapLemmas", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.HeapImpl", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.Heap", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 0, "max_fuel": 2, "max_ifuel": 1, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": true, "smtencoding_l_arith_repr": "native", "smtencoding_nl_arith_repr": "wrapped", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [ "smt.arith.nl=false", "smt.QI.EAGER_THRESHOLD=100", "smt.CASE_SPLIT=3" ], "z3refresh": false, "z3rlimit": 30, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
s: Vale.X64.State.vale_state -> o1: Vale.X64.Machine_s.operand64{Prims.op_Negation (OMem? o1 || OStack? o1)} -> o2: Vale.X64.Machine_s.operand64{Prims.op_Negation (OMem? o2 || OStack? o2)} -> FStar.Pervasives.Lemma (ensures Vale.X64.Lemmas.eval_ocmp s (Vale.X64.Bytes_Code_s.OLt o1 o2) <==> Vale.X64.State.eval_operand o1 s < Vale.X64.State.eval_operand o2 s) [SMTPat (Vale.X64.Lemmas.eval_ocmp s (Vale.X64.Bytes_Code_s.OLt o1 o2))]
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "Vale.X64.State.vale_state", "Vale.X64.Machine_s.operand64", "Prims.b2t", "Prims.op_Negation", "Prims.op_BarBar", "Vale.X64.Machine_s.uu___is_OMem", "Vale.X64.Machine_s.nat64", "Vale.X64.Machine_s.reg_64", "Vale.X64.Machine_s.uu___is_OStack", "FStar.Pervasives.reveal_opaque", "Vale.X64.Machine_Semantics_s.machine_state", "Vale.X64.Machine_Semantics_s.ocmp", "Prims.bool", "Vale.X64.Machine_Semantics_s.eval_ocmp_opaque", "Prims.unit" ]
[]
true
false
true
false
false
let lemma_cmp_lt s o1 o2 =
reveal_opaque (`%BS.eval_ocmp_opaque) BS.eval_ocmp_opaque
false
Vale.X64.Lemmas.fst
Vale.X64.Lemmas.eval_while_eq_core
val eval_while_eq_core (g: bool) (cond: ocmp) (body: code) (f: fuel) (s: machine_state) : Lemma (ensures state_eq_opt g (BS.machine_eval_while cond body f s) (BS.machine_eval_while cond body f (core_state g s))) (decreases %[f;body])
val eval_while_eq_core (g: bool) (cond: ocmp) (body: code) (f: fuel) (s: machine_state) : Lemma (ensures state_eq_opt g (BS.machine_eval_while cond body f s) (BS.machine_eval_while cond body f (core_state g s))) (decreases %[f;body])
let rec eval_code_eq_core (g:bool) (c:code) (f:fuel) (s:machine_state) : Lemma (ensures state_eq_opt g (BS.machine_eval_code c f s) (BS.machine_eval_code c f (core_state g s))) (decreases %[f; c]) = match c with | Ins i -> reveal_opaque (`%BS.machine_eval_code_ins) BS.machine_eval_code_ins; if g then eval_code_eq_ins i f s (core_state g s) | Block cs -> eval_codes_eq_core g cs f s | IfElse cond ct cf -> eval_ocmp_eq_core g cond s; let (s', _) = BS.machine_eval_ocmp s cond in let (t', _) = BS.machine_eval_ocmp (core_state g s) cond in eval_code_eq_core g ct f s'; eval_code_eq_core g ct f t'; eval_code_eq_core g cf f s'; eval_code_eq_core g cf f t'; () | While cond body -> eval_while_eq_core g cond body f s and eval_codes_eq_core (g:bool) (cs:codes) (f:fuel) (s:machine_state) : Lemma (ensures state_eq_opt g (BS.machine_eval_codes cs f s) (BS.machine_eval_codes cs f (core_state g s))) (decreases %[f; cs]) = match cs with | [] -> () | c'::cs' -> ( eval_code_eq_core g c' f s; match (machine_eval_code c' f s, machine_eval_code c' f (core_state g s)) with | (None, None) -> () | (Some s', Some t') -> eval_codes_eq_core g cs' f s'; eval_codes_eq_core g cs' f t' ) and eval_while_eq_core (g:bool) (cond:ocmp) (body:code) (f:fuel) (s:machine_state) : Lemma (ensures state_eq_opt g (BS.machine_eval_while cond body f s) (BS.machine_eval_while cond body f (core_state g s))) (decreases %[f; body]) = if f > 0 then ( eval_ocmp_eq_core g cond s; let (s1, _) = BS.machine_eval_ocmp s cond in let (t1, _) = BS.machine_eval_ocmp (core_state g s) cond in eval_code_eq_core g body (f - 1) s1; eval_code_eq_core g body (f - 1) t1; match (BS.machine_eval_code body (f - 1) s1, BS.machine_eval_code body (f - 1) t1) with | (None, None) -> () | (Some s2, Some t2) -> eval_while_eq_core g cond body (f - 1) s2; eval_while_eq_core g cond body (f - 1) t2; () )
{ "file_name": "vale/code/arch/x64/Vale.X64.Lemmas.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 3, "end_line": 251, "start_col": 0, "start_line": 204 }
module Vale.X64.Lemmas open FStar.Mul open Vale.X64.Machine_s open Vale.X64.State open Vale.X64.StateLemmas open Vale.X64.Instruction_s open Vale.X64.Bytes_Code_s module BS = Vale.X64.Machine_Semantics_s module ME = Vale.X64.Memory #reset-options "--initial_fuel 1 --max_fuel 1 --z3rlimit 100" #restart-solver let rec lemma_eq_instr_apply_eval_args (outs:list instr_out) (args:list instr_operand) (f:instr_args_t outs args) (oprs:instr_operands_t_args args) (s1 s2:machine_state) : Lemma (requires state_eq_S true s1 s2) (ensures BS.instr_apply_eval_args outs args f oprs s1 == BS.instr_apply_eval_args outs args f oprs s2) = let open BS in lemma_heap_ignore_ghost_machine s1.BS.ms_heap s2.BS.ms_heap; match args with | [] -> () | i::args -> ( let (v, oprs) : option (instr_val_t i) & instr_operands_t_args args = match i with | IOpEx i -> let oprs = coerce oprs in (instr_eval_operand_explicit i (fst oprs) s1, snd oprs) | IOpIm i -> (instr_eval_operand_implicit i s1, coerce oprs) in let f:arrow (instr_val_t i) (instr_args_t outs args) = coerce f in match v with | None -> () | Some v -> lemma_eq_instr_apply_eval_args outs args (f v) oprs s1 s2 ) #restart-solver let rec lemma_eq_instr_apply_eval_inouts (outs inouts:list instr_out) (args:list instr_operand) (f:instr_inouts_t outs inouts args) (oprs:instr_operands_t inouts args) (s1 s2:machine_state) : Lemma (requires state_eq_S true s1 s2) (ensures BS.instr_apply_eval_inouts outs inouts args f oprs s1 == BS.instr_apply_eval_inouts outs inouts args f oprs s2) = let open BS in lemma_heap_ignore_ghost_machine s1.BS.ms_heap s2.BS.ms_heap; match inouts with | [] -> lemma_eq_instr_apply_eval_args outs args f oprs s1 s2 | (Out, i)::inouts -> let oprs = match i with | IOpEx i -> snd #(instr_operand_t i) (coerce oprs) | IOpIm i -> coerce oprs in lemma_eq_instr_apply_eval_inouts outs inouts args (coerce f) oprs s1 s2 | (InOut, i)::inouts -> ( let (v, oprs) : option (instr_val_t i) & instr_operands_t inouts args = match i with | IOpEx i -> let oprs = coerce oprs in (instr_eval_operand_explicit i (fst oprs) s1, snd oprs) | IOpIm i -> (instr_eval_operand_implicit i s1, coerce oprs) in let f:arrow (instr_val_t i) (instr_inouts_t outs inouts args) = coerce f in match v with | None -> () | Some v -> lemma_eq_instr_apply_eval_inouts outs inouts args (f v) oprs s1 s2 ) #restart-solver #push-options "--z3rlimit_factor 2" let rec lemma_eq_instr_write_outputs (outs:list instr_out) (args:list instr_operand) (vs:instr_ret_t outs) (oprs:instr_operands_t outs args) (s1_orig s1 s2_orig s2:machine_state) : Lemma (requires state_eq_S true s1_orig s2_orig /\ state_eq_S true s1 s2) (ensures state_eq_S true (BS.instr_write_outputs outs args vs oprs s1_orig s1) (BS.instr_write_outputs outs args vs oprs s2_orig s2)) = let open BS in use_machine_state_equal (); lemma_heap_ignore_ghost_machine s1.BS.ms_heap s2.BS.ms_heap; lemma_heap_ignore_ghost_machine s1_orig.BS.ms_heap s2_orig.BS.ms_heap; allow_inversion tmaddr; match outs with | [] -> () | (_, i)::outs -> ( let ((v:instr_val_t i), (vs:instr_ret_t outs)) = match outs with | [] -> (vs, ()) | _::_ -> let vs = coerce vs in (fst vs, snd vs) in match i with | IOpEx i -> let oprs = coerce oprs in let s1 = instr_write_output_explicit i v (fst oprs) s1_orig s1 in let s2 = instr_write_output_explicit i v (fst oprs) s2_orig s2 in lemma_eq_instr_write_outputs outs args vs (snd oprs) s1_orig s1 s2_orig s2 | IOpIm i -> let s1 = instr_write_output_implicit i v s1_orig s1 in let s2 = instr_write_output_implicit i v s2_orig s2 in allow_inversion operand64; allow_inversion operand128; lemma_eq_instr_write_outputs outs args vs (coerce oprs) s1_orig s1 s2_orig s2 ) #pop-options #restart-solver let eval_ins_eq_instr (inst:BS.ins) (s1 s2:machine_state) : Lemma (requires Instr? inst /\ state_eq_S true s1 s2) (ensures state_eq_S true (BS.machine_eval_ins inst s1) (BS.machine_eval_ins inst s2)) = let open BS in let Instr it oprs ann = inst in let InstrTypeRecord #outs #args #havoc_flags' i = it in lemma_eq_instr_apply_eval_inouts outs outs args (instr_eval i) oprs s1 s2; let vs = instr_apply_eval outs args (instr_eval i) oprs s1 in let hav s = match havoc_flags' with | HavocFlags -> {s with ms_flags = havoc_flags} | PreserveFlags -> s in let s1' = hav s1 in let s2' = hav s2 in match vs with | None -> () | Some vs -> lemma_eq_instr_write_outputs outs args vs oprs s1 s1' s2 s2' let eval_code_eq_instr (inst:BS.ins) (f:fuel) (s1 s2:machine_state) : Lemma (requires Instr? inst /\ state_eq_S true s1 s2) (ensures state_eq_opt true (BS.machine_eval_code (Ins inst) f s1) (BS.machine_eval_code (Ins inst) f s2)) = reveal_opaque (`%BS.machine_eval_code_ins) BS.machine_eval_code_ins; eval_ins_eq_instr inst ({s1 with BS.ms_trace = []}) ({s2 with BS.ms_trace = []}) let eval_code_eq_dealloc (inst:BS.ins) (f:fuel) (s1 s2:machine_state) : Lemma (requires Dealloc? inst /\ state_eq_S true s1 s2) (ensures state_eq_opt true (BS.machine_eval_code (Ins inst) f s1) (BS.machine_eval_code (Ins inst) f s2)) = reveal_opaque (`%BS.machine_eval_code_ins) BS.machine_eval_code_ins; use_machine_state_equal (); lemma_heap_ignore_ghost_machine s1.BS.ms_heap s2.BS.ms_heap; allow_inversion tmaddr let eval_code_eq_alloc (inst:BS.ins) (f:fuel) (s1 s2:machine_state) : Lemma (requires Alloc? inst /\ state_eq_S true s1 s2) (ensures state_eq_opt true (BS.machine_eval_code (Ins inst) f s1) (BS.machine_eval_code (Ins inst) f s2)) = reveal_opaque (`%BS.machine_eval_code_ins) BS.machine_eval_code_ins; use_machine_state_equal (); lemma_heap_ignore_ghost_machine s1.BS.ms_heap s2.BS.ms_heap; allow_inversion tmaddr let eval_code_eq_push (inst:BS.ins) (f:fuel) (s1 s2:machine_state) : Lemma (requires Push? inst /\ state_eq_S true s1 s2) (ensures state_eq_opt true (BS.machine_eval_code (Ins inst) f s1) (BS.machine_eval_code (Ins inst) f s2)) = reveal_opaque (`%BS.machine_eval_code_ins) BS.machine_eval_code_ins; use_machine_state_equal (); lemma_heap_ignore_ghost_machine s1.BS.ms_heap s2.BS.ms_heap; allow_inversion tmaddr let eval_code_eq_pop (inst:BS.ins) (f:fuel) (s1 s2:machine_state) : Lemma (requires Pop? inst /\ state_eq_S true s1 s2) (ensures state_eq_opt true (BS.machine_eval_code (Ins inst) f s1) (BS.machine_eval_code (Ins inst) f s2)) = reveal_opaque (`%BS.machine_eval_code_ins) BS.machine_eval_code_ins; use_machine_state_equal (); lemma_heap_ignore_ghost_machine s1.BS.ms_heap s2.BS.ms_heap; allow_inversion tmaddr let eval_code_eq_ins (i:BS.ins) (f:fuel) (s1 s2:machine_state) : Lemma (requires state_eq_S true s1 s2) (ensures state_eq_opt true (BS.machine_eval_code (Ins i) f s1) (BS.machine_eval_code (Ins i) f s2)) = match i with | Instr _ _ _ -> eval_code_eq_instr i f s1 s2 | Dealloc _ -> eval_code_eq_dealloc i f s1 s2 | Alloc _ -> eval_code_eq_alloc i f s1 s2 | Push _ _ -> eval_code_eq_push i f s1 s2 | Pop _ _ -> eval_code_eq_pop i f s1 s2 #reset-options "--fuel 2 --z3rlimit 30" let eval_ocmp_eq_core (g:bool) (cond:ocmp) (s:machine_state) : Lemma (ensures ( let (s1, b1) = BS.machine_eval_ocmp s cond in let (s2, b2) = BS.machine_eval_ocmp (core_state g s) cond in state_eq_S g s1 s2 /\ b1 == b2 )) = reveal_opaque (`%BS.valid_ocmp_opaque) BS.valid_ocmp_opaque; reveal_opaque (`%BS.eval_ocmp_opaque) BS.eval_ocmp_opaque; ()
{ "checked_file": "/", "dependencies": [ "Vale.X64.StateLemmas.fsti.checked", "Vale.X64.State.fsti.checked", "Vale.X64.Memory.fsti.checked", "Vale.X64.Machine_Semantics_s.fst.checked", "Vale.X64.Machine_s.fst.checked", "Vale.X64.Instruction_s.fsti.checked", "Vale.X64.Flags.fsti.checked", "Vale.X64.Bytes_Code_s.fst.checked", "prims.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.FunctionalExtensionality.fsti.checked" ], "interface_file": true, "source_file": "Vale.X64.Lemmas.fst" }
[ { "abbrev": true, "full_module": "Vale.X64.Memory", "short_module": "ME" }, { "abbrev": true, "full_module": "Vale.X64.Machine_Semantics_s", "short_module": "BS" }, { "abbrev": false, "full_module": "Vale.X64.Bytes_Code_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Instruction_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.StateLemmas", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.State", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Machine_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": true, "full_module": "Vale.Lib.Map16", "short_module": "Map16" }, { "abbrev": true, "full_module": "Vale.X64.Machine_Semantics_s", "short_module": "BS" }, { "abbrev": false, "full_module": "Vale.X64.Bytes_Code_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.StateLemmas", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.State", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Machine_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.HeapLemmas", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.HeapImpl", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.Heap", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 0, "max_fuel": 2, "max_ifuel": 1, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": true, "smtencoding_l_arith_repr": "native", "smtencoding_nl_arith_repr": "wrapped", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [ "smt.arith.nl=false", "smt.QI.EAGER_THRESHOLD=100", "smt.CASE_SPLIT=3" ], "z3refresh": false, "z3rlimit": 30, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
g: Prims.bool -> cond: Vale.X64.Bytes_Code_s.ocmp -> body: Vale.X64.StateLemmas.code -> f: Vale.X64.Lemmas.fuel -> s: Vale.X64.StateLemmas.machine_state -> FStar.Pervasives.Lemma (ensures Vale.X64.Lemmas.state_eq_opt g (Vale.X64.Machine_Semantics_s.machine_eval_while cond body f s) (Vale.X64.Machine_Semantics_s.machine_eval_while cond body f (Vale.X64.Lemmas.core_state g s))) (decreases %[f;body])
FStar.Pervasives.Lemma
[ "lemma", "" ]
[ "eval_code_eq_core", "eval_codes_eq_core", "eval_while_eq_core" ]
[ "Prims.bool", "Vale.X64.Bytes_Code_s.ocmp", "Vale.X64.StateLemmas.code", "Vale.X64.Lemmas.fuel", "Vale.X64.StateLemmas.machine_state", "Prims.op_GreaterThan", "Vale.X64.Machine_Semantics_s.machine_state", "FStar.Pervasives.Native.Mktuple2", "FStar.Pervasives.Native.option", "Vale.X64.Machine_Semantics_s.machine_eval_code", "Prims.op_Subtraction", "Prims.unit", "Vale.X64.Lemmas.eval_while_eq_core", "Vale.X64.Lemmas.eval_code_eq_core", "FStar.Pervasives.Native.tuple2", "Vale.X64.Machine_Semantics_s.machine_eval_ocmp", "Vale.X64.Lemmas.core_state", "Vale.X64.Lemmas.eval_ocmp_eq_core", "Prims.l_True", "Prims.squash", "Vale.X64.Lemmas.state_eq_opt", "Vale.X64.Machine_Semantics_s.machine_eval_while", "Prims.Nil", "FStar.Pervasives.pattern" ]
[ "mutual recursion" ]
false
false
true
false
false
let rec eval_while_eq_core (g: bool) (cond: ocmp) (body: code) (f: fuel) (s: machine_state) : Lemma (ensures state_eq_opt g (BS.machine_eval_while cond body f s) (BS.machine_eval_while cond body f (core_state g s))) (decreases %[f;body]) =
if f > 0 then (eval_ocmp_eq_core g cond s; let s1, _ = BS.machine_eval_ocmp s cond in let t1, _ = BS.machine_eval_ocmp (core_state g s) cond in eval_code_eq_core g body (f - 1) s1; eval_code_eq_core g body (f - 1) t1; match (BS.machine_eval_code body (f - 1) s1, BS.machine_eval_code body (f - 1) t1) with | None, None -> () | Some s2, Some t2 -> eval_while_eq_core g cond body (f - 1) s2; eval_while_eq_core g cond body (f - 1) t2; ())
false
Vale.X64.Lemmas.fst
Vale.X64.Lemmas.eval_code_eq_core
val eval_code_eq_core (g: bool) (c: code) (f: fuel) (s: machine_state) : Lemma (ensures state_eq_opt g (BS.machine_eval_code c f s) (BS.machine_eval_code c f (core_state g s))) (decreases %[f;c])
val eval_code_eq_core (g: bool) (c: code) (f: fuel) (s: machine_state) : Lemma (ensures state_eq_opt g (BS.machine_eval_code c f s) (BS.machine_eval_code c f (core_state g s))) (decreases %[f;c])
let rec eval_code_eq_core (g:bool) (c:code) (f:fuel) (s:machine_state) : Lemma (ensures state_eq_opt g (BS.machine_eval_code c f s) (BS.machine_eval_code c f (core_state g s))) (decreases %[f; c]) = match c with | Ins i -> reveal_opaque (`%BS.machine_eval_code_ins) BS.machine_eval_code_ins; if g then eval_code_eq_ins i f s (core_state g s) | Block cs -> eval_codes_eq_core g cs f s | IfElse cond ct cf -> eval_ocmp_eq_core g cond s; let (s', _) = BS.machine_eval_ocmp s cond in let (t', _) = BS.machine_eval_ocmp (core_state g s) cond in eval_code_eq_core g ct f s'; eval_code_eq_core g ct f t'; eval_code_eq_core g cf f s'; eval_code_eq_core g cf f t'; () | While cond body -> eval_while_eq_core g cond body f s and eval_codes_eq_core (g:bool) (cs:codes) (f:fuel) (s:machine_state) : Lemma (ensures state_eq_opt g (BS.machine_eval_codes cs f s) (BS.machine_eval_codes cs f (core_state g s))) (decreases %[f; cs]) = match cs with | [] -> () | c'::cs' -> ( eval_code_eq_core g c' f s; match (machine_eval_code c' f s, machine_eval_code c' f (core_state g s)) with | (None, None) -> () | (Some s', Some t') -> eval_codes_eq_core g cs' f s'; eval_codes_eq_core g cs' f t' ) and eval_while_eq_core (g:bool) (cond:ocmp) (body:code) (f:fuel) (s:machine_state) : Lemma (ensures state_eq_opt g (BS.machine_eval_while cond body f s) (BS.machine_eval_while cond body f (core_state g s))) (decreases %[f; body]) = if f > 0 then ( eval_ocmp_eq_core g cond s; let (s1, _) = BS.machine_eval_ocmp s cond in let (t1, _) = BS.machine_eval_ocmp (core_state g s) cond in eval_code_eq_core g body (f - 1) s1; eval_code_eq_core g body (f - 1) t1; match (BS.machine_eval_code body (f - 1) s1, BS.machine_eval_code body (f - 1) t1) with | (None, None) -> () | (Some s2, Some t2) -> eval_while_eq_core g cond body (f - 1) s2; eval_while_eq_core g cond body (f - 1) t2; () )
{ "file_name": "vale/code/arch/x64/Vale.X64.Lemmas.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 3, "end_line": 251, "start_col": 0, "start_line": 204 }
module Vale.X64.Lemmas open FStar.Mul open Vale.X64.Machine_s open Vale.X64.State open Vale.X64.StateLemmas open Vale.X64.Instruction_s open Vale.X64.Bytes_Code_s module BS = Vale.X64.Machine_Semantics_s module ME = Vale.X64.Memory #reset-options "--initial_fuel 1 --max_fuel 1 --z3rlimit 100" #restart-solver let rec lemma_eq_instr_apply_eval_args (outs:list instr_out) (args:list instr_operand) (f:instr_args_t outs args) (oprs:instr_operands_t_args args) (s1 s2:machine_state) : Lemma (requires state_eq_S true s1 s2) (ensures BS.instr_apply_eval_args outs args f oprs s1 == BS.instr_apply_eval_args outs args f oprs s2) = let open BS in lemma_heap_ignore_ghost_machine s1.BS.ms_heap s2.BS.ms_heap; match args with | [] -> () | i::args -> ( let (v, oprs) : option (instr_val_t i) & instr_operands_t_args args = match i with | IOpEx i -> let oprs = coerce oprs in (instr_eval_operand_explicit i (fst oprs) s1, snd oprs) | IOpIm i -> (instr_eval_operand_implicit i s1, coerce oprs) in let f:arrow (instr_val_t i) (instr_args_t outs args) = coerce f in match v with | None -> () | Some v -> lemma_eq_instr_apply_eval_args outs args (f v) oprs s1 s2 ) #restart-solver let rec lemma_eq_instr_apply_eval_inouts (outs inouts:list instr_out) (args:list instr_operand) (f:instr_inouts_t outs inouts args) (oprs:instr_operands_t inouts args) (s1 s2:machine_state) : Lemma (requires state_eq_S true s1 s2) (ensures BS.instr_apply_eval_inouts outs inouts args f oprs s1 == BS.instr_apply_eval_inouts outs inouts args f oprs s2) = let open BS in lemma_heap_ignore_ghost_machine s1.BS.ms_heap s2.BS.ms_heap; match inouts with | [] -> lemma_eq_instr_apply_eval_args outs args f oprs s1 s2 | (Out, i)::inouts -> let oprs = match i with | IOpEx i -> snd #(instr_operand_t i) (coerce oprs) | IOpIm i -> coerce oprs in lemma_eq_instr_apply_eval_inouts outs inouts args (coerce f) oprs s1 s2 | (InOut, i)::inouts -> ( let (v, oprs) : option (instr_val_t i) & instr_operands_t inouts args = match i with | IOpEx i -> let oprs = coerce oprs in (instr_eval_operand_explicit i (fst oprs) s1, snd oprs) | IOpIm i -> (instr_eval_operand_implicit i s1, coerce oprs) in let f:arrow (instr_val_t i) (instr_inouts_t outs inouts args) = coerce f in match v with | None -> () | Some v -> lemma_eq_instr_apply_eval_inouts outs inouts args (f v) oprs s1 s2 ) #restart-solver #push-options "--z3rlimit_factor 2" let rec lemma_eq_instr_write_outputs (outs:list instr_out) (args:list instr_operand) (vs:instr_ret_t outs) (oprs:instr_operands_t outs args) (s1_orig s1 s2_orig s2:machine_state) : Lemma (requires state_eq_S true s1_orig s2_orig /\ state_eq_S true s1 s2) (ensures state_eq_S true (BS.instr_write_outputs outs args vs oprs s1_orig s1) (BS.instr_write_outputs outs args vs oprs s2_orig s2)) = let open BS in use_machine_state_equal (); lemma_heap_ignore_ghost_machine s1.BS.ms_heap s2.BS.ms_heap; lemma_heap_ignore_ghost_machine s1_orig.BS.ms_heap s2_orig.BS.ms_heap; allow_inversion tmaddr; match outs with | [] -> () | (_, i)::outs -> ( let ((v:instr_val_t i), (vs:instr_ret_t outs)) = match outs with | [] -> (vs, ()) | _::_ -> let vs = coerce vs in (fst vs, snd vs) in match i with | IOpEx i -> let oprs = coerce oprs in let s1 = instr_write_output_explicit i v (fst oprs) s1_orig s1 in let s2 = instr_write_output_explicit i v (fst oprs) s2_orig s2 in lemma_eq_instr_write_outputs outs args vs (snd oprs) s1_orig s1 s2_orig s2 | IOpIm i -> let s1 = instr_write_output_implicit i v s1_orig s1 in let s2 = instr_write_output_implicit i v s2_orig s2 in allow_inversion operand64; allow_inversion operand128; lemma_eq_instr_write_outputs outs args vs (coerce oprs) s1_orig s1 s2_orig s2 ) #pop-options #restart-solver let eval_ins_eq_instr (inst:BS.ins) (s1 s2:machine_state) : Lemma (requires Instr? inst /\ state_eq_S true s1 s2) (ensures state_eq_S true (BS.machine_eval_ins inst s1) (BS.machine_eval_ins inst s2)) = let open BS in let Instr it oprs ann = inst in let InstrTypeRecord #outs #args #havoc_flags' i = it in lemma_eq_instr_apply_eval_inouts outs outs args (instr_eval i) oprs s1 s2; let vs = instr_apply_eval outs args (instr_eval i) oprs s1 in let hav s = match havoc_flags' with | HavocFlags -> {s with ms_flags = havoc_flags} | PreserveFlags -> s in let s1' = hav s1 in let s2' = hav s2 in match vs with | None -> () | Some vs -> lemma_eq_instr_write_outputs outs args vs oprs s1 s1' s2 s2' let eval_code_eq_instr (inst:BS.ins) (f:fuel) (s1 s2:machine_state) : Lemma (requires Instr? inst /\ state_eq_S true s1 s2) (ensures state_eq_opt true (BS.machine_eval_code (Ins inst) f s1) (BS.machine_eval_code (Ins inst) f s2)) = reveal_opaque (`%BS.machine_eval_code_ins) BS.machine_eval_code_ins; eval_ins_eq_instr inst ({s1 with BS.ms_trace = []}) ({s2 with BS.ms_trace = []}) let eval_code_eq_dealloc (inst:BS.ins) (f:fuel) (s1 s2:machine_state) : Lemma (requires Dealloc? inst /\ state_eq_S true s1 s2) (ensures state_eq_opt true (BS.machine_eval_code (Ins inst) f s1) (BS.machine_eval_code (Ins inst) f s2)) = reveal_opaque (`%BS.machine_eval_code_ins) BS.machine_eval_code_ins; use_machine_state_equal (); lemma_heap_ignore_ghost_machine s1.BS.ms_heap s2.BS.ms_heap; allow_inversion tmaddr let eval_code_eq_alloc (inst:BS.ins) (f:fuel) (s1 s2:machine_state) : Lemma (requires Alloc? inst /\ state_eq_S true s1 s2) (ensures state_eq_opt true (BS.machine_eval_code (Ins inst) f s1) (BS.machine_eval_code (Ins inst) f s2)) = reveal_opaque (`%BS.machine_eval_code_ins) BS.machine_eval_code_ins; use_machine_state_equal (); lemma_heap_ignore_ghost_machine s1.BS.ms_heap s2.BS.ms_heap; allow_inversion tmaddr let eval_code_eq_push (inst:BS.ins) (f:fuel) (s1 s2:machine_state) : Lemma (requires Push? inst /\ state_eq_S true s1 s2) (ensures state_eq_opt true (BS.machine_eval_code (Ins inst) f s1) (BS.machine_eval_code (Ins inst) f s2)) = reveal_opaque (`%BS.machine_eval_code_ins) BS.machine_eval_code_ins; use_machine_state_equal (); lemma_heap_ignore_ghost_machine s1.BS.ms_heap s2.BS.ms_heap; allow_inversion tmaddr let eval_code_eq_pop (inst:BS.ins) (f:fuel) (s1 s2:machine_state) : Lemma (requires Pop? inst /\ state_eq_S true s1 s2) (ensures state_eq_opt true (BS.machine_eval_code (Ins inst) f s1) (BS.machine_eval_code (Ins inst) f s2)) = reveal_opaque (`%BS.machine_eval_code_ins) BS.machine_eval_code_ins; use_machine_state_equal (); lemma_heap_ignore_ghost_machine s1.BS.ms_heap s2.BS.ms_heap; allow_inversion tmaddr let eval_code_eq_ins (i:BS.ins) (f:fuel) (s1 s2:machine_state) : Lemma (requires state_eq_S true s1 s2) (ensures state_eq_opt true (BS.machine_eval_code (Ins i) f s1) (BS.machine_eval_code (Ins i) f s2)) = match i with | Instr _ _ _ -> eval_code_eq_instr i f s1 s2 | Dealloc _ -> eval_code_eq_dealloc i f s1 s2 | Alloc _ -> eval_code_eq_alloc i f s1 s2 | Push _ _ -> eval_code_eq_push i f s1 s2 | Pop _ _ -> eval_code_eq_pop i f s1 s2 #reset-options "--fuel 2 --z3rlimit 30" let eval_ocmp_eq_core (g:bool) (cond:ocmp) (s:machine_state) : Lemma (ensures ( let (s1, b1) = BS.machine_eval_ocmp s cond in let (s2, b2) = BS.machine_eval_ocmp (core_state g s) cond in state_eq_S g s1 s2 /\ b1 == b2 )) = reveal_opaque (`%BS.valid_ocmp_opaque) BS.valid_ocmp_opaque; reveal_opaque (`%BS.eval_ocmp_opaque) BS.eval_ocmp_opaque; ()
{ "checked_file": "/", "dependencies": [ "Vale.X64.StateLemmas.fsti.checked", "Vale.X64.State.fsti.checked", "Vale.X64.Memory.fsti.checked", "Vale.X64.Machine_Semantics_s.fst.checked", "Vale.X64.Machine_s.fst.checked", "Vale.X64.Instruction_s.fsti.checked", "Vale.X64.Flags.fsti.checked", "Vale.X64.Bytes_Code_s.fst.checked", "prims.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.FunctionalExtensionality.fsti.checked" ], "interface_file": true, "source_file": "Vale.X64.Lemmas.fst" }
[ { "abbrev": true, "full_module": "Vale.X64.Memory", "short_module": "ME" }, { "abbrev": true, "full_module": "Vale.X64.Machine_Semantics_s", "short_module": "BS" }, { "abbrev": false, "full_module": "Vale.X64.Bytes_Code_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Instruction_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.StateLemmas", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.State", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Machine_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": true, "full_module": "Vale.Lib.Map16", "short_module": "Map16" }, { "abbrev": true, "full_module": "Vale.X64.Machine_Semantics_s", "short_module": "BS" }, { "abbrev": false, "full_module": "Vale.X64.Bytes_Code_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.StateLemmas", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.State", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Machine_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.HeapLemmas", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.HeapImpl", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.Heap", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 0, "max_fuel": 2, "max_ifuel": 1, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": true, "smtencoding_l_arith_repr": "native", "smtencoding_nl_arith_repr": "wrapped", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [ "smt.arith.nl=false", "smt.QI.EAGER_THRESHOLD=100", "smt.CASE_SPLIT=3" ], "z3refresh": false, "z3rlimit": 30, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
g: Prims.bool -> c: Vale.X64.StateLemmas.code -> f: Vale.X64.Lemmas.fuel -> s: Vale.X64.StateLemmas.machine_state -> FStar.Pervasives.Lemma (ensures Vale.X64.Lemmas.state_eq_opt g (Vale.X64.Machine_Semantics_s.machine_eval_code c f s) (Vale.X64.Machine_Semantics_s.machine_eval_code c f (Vale.X64.Lemmas.core_state g s))) (decreases %[f;c])
FStar.Pervasives.Lemma
[ "lemma", "" ]
[ "eval_code_eq_core", "eval_codes_eq_core", "eval_while_eq_core" ]
[ "Prims.bool", "Vale.X64.StateLemmas.code", "Vale.X64.Lemmas.fuel", "Vale.X64.StateLemmas.machine_state", "Vale.X64.Bytes_Code_s.instruction_t", "Vale.X64.Machine_Semantics_s.instr_annotation", "Vale.X64.Lemmas.eval_code_eq_ins", "Vale.X64.Lemmas.core_state", "Prims.unit", "FStar.Pervasives.reveal_opaque", "Vale.X64.Machine_Semantics_s.ins", "Vale.X64.Machine_Semantics_s.machine_state", "FStar.Pervasives.Native.option", "Vale.X64.Machine_Semantics_s.machine_eval_code_ins", "Prims.list", "Vale.X64.Machine_s.precode", "Vale.X64.Bytes_Code_s.ocmp", "Vale.X64.Lemmas.eval_codes_eq_core", "Vale.X64.Lemmas.eval_code_eq_core", "FStar.Pervasives.Native.tuple2", "Vale.X64.Machine_Semantics_s.machine_eval_ocmp", "Vale.X64.Lemmas.eval_ocmp_eq_core", "Vale.X64.Lemmas.eval_while_eq_core", "Prims.l_True", "Prims.squash", "Vale.X64.Lemmas.state_eq_opt", "Vale.X64.Machine_Semantics_s.machine_eval_code", "Prims.Nil", "FStar.Pervasives.pattern" ]
[ "mutual recursion" ]
false
false
true
false
false
let rec eval_code_eq_core (g: bool) (c: code) (f: fuel) (s: machine_state) : Lemma (ensures state_eq_opt g (BS.machine_eval_code c f s) (BS.machine_eval_code c f (core_state g s))) (decreases %[f;c]) =
match c with | Ins i -> reveal_opaque (`%BS.machine_eval_code_ins) BS.machine_eval_code_ins; if g then eval_code_eq_ins i f s (core_state g s) | Block cs -> eval_codes_eq_core g cs f s | IfElse cond ct cf -> eval_ocmp_eq_core g cond s; let s', _ = BS.machine_eval_ocmp s cond in let t', _ = BS.machine_eval_ocmp (core_state g s) cond in eval_code_eq_core g ct f s'; eval_code_eq_core g ct f t'; eval_code_eq_core g cf f s'; eval_code_eq_core g cf f t'; () | While cond body -> eval_while_eq_core g cond body f s
false
Vale.X64.Lemmas.fst
Vale.X64.Lemmas.lemma_cmp_gt
val lemma_cmp_gt (s:vale_state) (o1:operand64{not (OMem? o1 || OStack? o1)}) (o2:operand64{not (OMem? o2 || OStack? o2)}) : Lemma (ensures eval_ocmp s (OGt o1 o2) <==> eval_operand o1 s > eval_operand o2 s) [SMTPat (eval_ocmp s (OGt o1 o2))]
val lemma_cmp_gt (s:vale_state) (o1:operand64{not (OMem? o1 || OStack? o1)}) (o2:operand64{not (OMem? o2 || OStack? o2)}) : Lemma (ensures eval_ocmp s (OGt o1 o2) <==> eval_operand o1 s > eval_operand o2 s) [SMTPat (eval_ocmp s (OGt o1 o2))]
let lemma_cmp_gt s o1 o2 = reveal_opaque (`%BS.eval_ocmp_opaque) BS.eval_ocmp_opaque
{ "file_name": "vale/code/arch/x64/Vale.X64.Lemmas.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 84, "end_line": 338, "start_col": 0, "start_line": 338 }
module Vale.X64.Lemmas open FStar.Mul open Vale.X64.Machine_s open Vale.X64.State open Vale.X64.StateLemmas open Vale.X64.Instruction_s open Vale.X64.Bytes_Code_s module BS = Vale.X64.Machine_Semantics_s module ME = Vale.X64.Memory #reset-options "--initial_fuel 1 --max_fuel 1 --z3rlimit 100" #restart-solver let rec lemma_eq_instr_apply_eval_args (outs:list instr_out) (args:list instr_operand) (f:instr_args_t outs args) (oprs:instr_operands_t_args args) (s1 s2:machine_state) : Lemma (requires state_eq_S true s1 s2) (ensures BS.instr_apply_eval_args outs args f oprs s1 == BS.instr_apply_eval_args outs args f oprs s2) = let open BS in lemma_heap_ignore_ghost_machine s1.BS.ms_heap s2.BS.ms_heap; match args with | [] -> () | i::args -> ( let (v, oprs) : option (instr_val_t i) & instr_operands_t_args args = match i with | IOpEx i -> let oprs = coerce oprs in (instr_eval_operand_explicit i (fst oprs) s1, snd oprs) | IOpIm i -> (instr_eval_operand_implicit i s1, coerce oprs) in let f:arrow (instr_val_t i) (instr_args_t outs args) = coerce f in match v with | None -> () | Some v -> lemma_eq_instr_apply_eval_args outs args (f v) oprs s1 s2 ) #restart-solver let rec lemma_eq_instr_apply_eval_inouts (outs inouts:list instr_out) (args:list instr_operand) (f:instr_inouts_t outs inouts args) (oprs:instr_operands_t inouts args) (s1 s2:machine_state) : Lemma (requires state_eq_S true s1 s2) (ensures BS.instr_apply_eval_inouts outs inouts args f oprs s1 == BS.instr_apply_eval_inouts outs inouts args f oprs s2) = let open BS in lemma_heap_ignore_ghost_machine s1.BS.ms_heap s2.BS.ms_heap; match inouts with | [] -> lemma_eq_instr_apply_eval_args outs args f oprs s1 s2 | (Out, i)::inouts -> let oprs = match i with | IOpEx i -> snd #(instr_operand_t i) (coerce oprs) | IOpIm i -> coerce oprs in lemma_eq_instr_apply_eval_inouts outs inouts args (coerce f) oprs s1 s2 | (InOut, i)::inouts -> ( let (v, oprs) : option (instr_val_t i) & instr_operands_t inouts args = match i with | IOpEx i -> let oprs = coerce oprs in (instr_eval_operand_explicit i (fst oprs) s1, snd oprs) | IOpIm i -> (instr_eval_operand_implicit i s1, coerce oprs) in let f:arrow (instr_val_t i) (instr_inouts_t outs inouts args) = coerce f in match v with | None -> () | Some v -> lemma_eq_instr_apply_eval_inouts outs inouts args (f v) oprs s1 s2 ) #restart-solver #push-options "--z3rlimit_factor 2" let rec lemma_eq_instr_write_outputs (outs:list instr_out) (args:list instr_operand) (vs:instr_ret_t outs) (oprs:instr_operands_t outs args) (s1_orig s1 s2_orig s2:machine_state) : Lemma (requires state_eq_S true s1_orig s2_orig /\ state_eq_S true s1 s2) (ensures state_eq_S true (BS.instr_write_outputs outs args vs oprs s1_orig s1) (BS.instr_write_outputs outs args vs oprs s2_orig s2)) = let open BS in use_machine_state_equal (); lemma_heap_ignore_ghost_machine s1.BS.ms_heap s2.BS.ms_heap; lemma_heap_ignore_ghost_machine s1_orig.BS.ms_heap s2_orig.BS.ms_heap; allow_inversion tmaddr; match outs with | [] -> () | (_, i)::outs -> ( let ((v:instr_val_t i), (vs:instr_ret_t outs)) = match outs with | [] -> (vs, ()) | _::_ -> let vs = coerce vs in (fst vs, snd vs) in match i with | IOpEx i -> let oprs = coerce oprs in let s1 = instr_write_output_explicit i v (fst oprs) s1_orig s1 in let s2 = instr_write_output_explicit i v (fst oprs) s2_orig s2 in lemma_eq_instr_write_outputs outs args vs (snd oprs) s1_orig s1 s2_orig s2 | IOpIm i -> let s1 = instr_write_output_implicit i v s1_orig s1 in let s2 = instr_write_output_implicit i v s2_orig s2 in allow_inversion operand64; allow_inversion operand128; lemma_eq_instr_write_outputs outs args vs (coerce oprs) s1_orig s1 s2_orig s2 ) #pop-options #restart-solver let eval_ins_eq_instr (inst:BS.ins) (s1 s2:machine_state) : Lemma (requires Instr? inst /\ state_eq_S true s1 s2) (ensures state_eq_S true (BS.machine_eval_ins inst s1) (BS.machine_eval_ins inst s2)) = let open BS in let Instr it oprs ann = inst in let InstrTypeRecord #outs #args #havoc_flags' i = it in lemma_eq_instr_apply_eval_inouts outs outs args (instr_eval i) oprs s1 s2; let vs = instr_apply_eval outs args (instr_eval i) oprs s1 in let hav s = match havoc_flags' with | HavocFlags -> {s with ms_flags = havoc_flags} | PreserveFlags -> s in let s1' = hav s1 in let s2' = hav s2 in match vs with | None -> () | Some vs -> lemma_eq_instr_write_outputs outs args vs oprs s1 s1' s2 s2' let eval_code_eq_instr (inst:BS.ins) (f:fuel) (s1 s2:machine_state) : Lemma (requires Instr? inst /\ state_eq_S true s1 s2) (ensures state_eq_opt true (BS.machine_eval_code (Ins inst) f s1) (BS.machine_eval_code (Ins inst) f s2)) = reveal_opaque (`%BS.machine_eval_code_ins) BS.machine_eval_code_ins; eval_ins_eq_instr inst ({s1 with BS.ms_trace = []}) ({s2 with BS.ms_trace = []}) let eval_code_eq_dealloc (inst:BS.ins) (f:fuel) (s1 s2:machine_state) : Lemma (requires Dealloc? inst /\ state_eq_S true s1 s2) (ensures state_eq_opt true (BS.machine_eval_code (Ins inst) f s1) (BS.machine_eval_code (Ins inst) f s2)) = reveal_opaque (`%BS.machine_eval_code_ins) BS.machine_eval_code_ins; use_machine_state_equal (); lemma_heap_ignore_ghost_machine s1.BS.ms_heap s2.BS.ms_heap; allow_inversion tmaddr let eval_code_eq_alloc (inst:BS.ins) (f:fuel) (s1 s2:machine_state) : Lemma (requires Alloc? inst /\ state_eq_S true s1 s2) (ensures state_eq_opt true (BS.machine_eval_code (Ins inst) f s1) (BS.machine_eval_code (Ins inst) f s2)) = reveal_opaque (`%BS.machine_eval_code_ins) BS.machine_eval_code_ins; use_machine_state_equal (); lemma_heap_ignore_ghost_machine s1.BS.ms_heap s2.BS.ms_heap; allow_inversion tmaddr let eval_code_eq_push (inst:BS.ins) (f:fuel) (s1 s2:machine_state) : Lemma (requires Push? inst /\ state_eq_S true s1 s2) (ensures state_eq_opt true (BS.machine_eval_code (Ins inst) f s1) (BS.machine_eval_code (Ins inst) f s2)) = reveal_opaque (`%BS.machine_eval_code_ins) BS.machine_eval_code_ins; use_machine_state_equal (); lemma_heap_ignore_ghost_machine s1.BS.ms_heap s2.BS.ms_heap; allow_inversion tmaddr let eval_code_eq_pop (inst:BS.ins) (f:fuel) (s1 s2:machine_state) : Lemma (requires Pop? inst /\ state_eq_S true s1 s2) (ensures state_eq_opt true (BS.machine_eval_code (Ins inst) f s1) (BS.machine_eval_code (Ins inst) f s2)) = reveal_opaque (`%BS.machine_eval_code_ins) BS.machine_eval_code_ins; use_machine_state_equal (); lemma_heap_ignore_ghost_machine s1.BS.ms_heap s2.BS.ms_heap; allow_inversion tmaddr let eval_code_eq_ins (i:BS.ins) (f:fuel) (s1 s2:machine_state) : Lemma (requires state_eq_S true s1 s2) (ensures state_eq_opt true (BS.machine_eval_code (Ins i) f s1) (BS.machine_eval_code (Ins i) f s2)) = match i with | Instr _ _ _ -> eval_code_eq_instr i f s1 s2 | Dealloc _ -> eval_code_eq_dealloc i f s1 s2 | Alloc _ -> eval_code_eq_alloc i f s1 s2 | Push _ _ -> eval_code_eq_push i f s1 s2 | Pop _ _ -> eval_code_eq_pop i f s1 s2 #reset-options "--fuel 2 --z3rlimit 30" let eval_ocmp_eq_core (g:bool) (cond:ocmp) (s:machine_state) : Lemma (ensures ( let (s1, b1) = BS.machine_eval_ocmp s cond in let (s2, b2) = BS.machine_eval_ocmp (core_state g s) cond in state_eq_S g s1 s2 /\ b1 == b2 )) = reveal_opaque (`%BS.valid_ocmp_opaque) BS.valid_ocmp_opaque; reveal_opaque (`%BS.eval_ocmp_opaque) BS.eval_ocmp_opaque; () #restart-solver let rec eval_code_eq_core (g:bool) (c:code) (f:fuel) (s:machine_state) : Lemma (ensures state_eq_opt g (BS.machine_eval_code c f s) (BS.machine_eval_code c f (core_state g s))) (decreases %[f; c]) = match c with | Ins i -> reveal_opaque (`%BS.machine_eval_code_ins) BS.machine_eval_code_ins; if g then eval_code_eq_ins i f s (core_state g s) | Block cs -> eval_codes_eq_core g cs f s | IfElse cond ct cf -> eval_ocmp_eq_core g cond s; let (s', _) = BS.machine_eval_ocmp s cond in let (t', _) = BS.machine_eval_ocmp (core_state g s) cond in eval_code_eq_core g ct f s'; eval_code_eq_core g ct f t'; eval_code_eq_core g cf f s'; eval_code_eq_core g cf f t'; () | While cond body -> eval_while_eq_core g cond body f s and eval_codes_eq_core (g:bool) (cs:codes) (f:fuel) (s:machine_state) : Lemma (ensures state_eq_opt g (BS.machine_eval_codes cs f s) (BS.machine_eval_codes cs f (core_state g s))) (decreases %[f; cs]) = match cs with | [] -> () | c'::cs' -> ( eval_code_eq_core g c' f s; match (machine_eval_code c' f s, machine_eval_code c' f (core_state g s)) with | (None, None) -> () | (Some s', Some t') -> eval_codes_eq_core g cs' f s'; eval_codes_eq_core g cs' f t' ) and eval_while_eq_core (g:bool) (cond:ocmp) (body:code) (f:fuel) (s:machine_state) : Lemma (ensures state_eq_opt g (BS.machine_eval_while cond body f s) (BS.machine_eval_while cond body f (core_state g s))) (decreases %[f; body]) = if f > 0 then ( eval_ocmp_eq_core g cond s; let (s1, _) = BS.machine_eval_ocmp s cond in let (t1, _) = BS.machine_eval_ocmp (core_state g s) cond in eval_code_eq_core g body (f - 1) s1; eval_code_eq_core g body (f - 1) t1; match (BS.machine_eval_code body (f - 1) s1, BS.machine_eval_code body (f - 1) t1) with | (None, None) -> () | (Some s2, Some t2) -> eval_while_eq_core g cond body (f - 1) s2; eval_while_eq_core g cond body (f - 1) t2; () ) let eval_code_eq_f (c:code) (f:fuel) (s1 s2:machine_state) : Lemma (requires state_eq_S false s1 s2) (ensures state_eq_opt false (BS.machine_eval_code c f s1) (BS.machine_eval_code c f s2)) [SMTPat (BS.machine_eval_code c f s1); SMTPat (BS.machine_eval_code c f s2)] = eval_code_eq_core false c f s1; eval_code_eq_core false c f s2 let eval_codes_eq_f (cs:codes) (f:fuel) (s1 s2:machine_state) : Lemma (requires state_eq_S false s1 s2) (ensures state_eq_opt false (BS.machine_eval_codes cs f s1) (BS.machine_eval_codes cs f s2)) [SMTPat (BS.machine_eval_codes cs f s1); SMTPat (BS.machine_eval_codes cs f s2)] = eval_codes_eq_core false cs f s1; eval_codes_eq_core false cs f s2 let eval_while_eq_f (cond:ocmp) (body:code) (f:fuel) (s1 s2:machine_state) : Lemma (requires state_eq_S false s1 s2) (ensures state_eq_opt false (BS.machine_eval_while cond body f s1) (BS.machine_eval_while cond body f s2)) [SMTPat (BS.machine_eval_while cond body f s1); SMTPat (BS.machine_eval_while cond body f s2)] = eval_while_eq_core false cond body f s1; eval_while_eq_core false cond body f s2 let eval_code_eq_t (c:code) (f:fuel) (s1 s2:machine_state) : Lemma (requires state_eq_S true s1 s2) (ensures state_eq_opt true (BS.machine_eval_code c f s1) (BS.machine_eval_code c f s2)) [SMTPat (BS.machine_eval_code c f s1); SMTPat (BS.machine_eval_code c f s2)] = eval_code_eq_core true c f s1; eval_code_eq_core true c f s2 let eval_codes_eq_t (cs:codes) (f:fuel) (s1 s2:machine_state) : Lemma (requires state_eq_S true s1 s2) (ensures state_eq_opt true (BS.machine_eval_codes cs f s1) (BS.machine_eval_codes cs f s2)) [SMTPat (BS.machine_eval_codes cs f s1); SMTPat (BS.machine_eval_codes cs f s2)] = eval_codes_eq_core true cs f s1; eval_codes_eq_core true cs f s2 let eval_while_eq_t (cond:ocmp) (body:code) (f:fuel) (s1 s2:machine_state) : Lemma (requires state_eq_S true s1 s2) (ensures state_eq_opt true (BS.machine_eval_while cond body f s1) (BS.machine_eval_while cond body f s2)) [SMTPat (BS.machine_eval_while cond body f s1); SMTPat (BS.machine_eval_while cond body f s2)] = eval_while_eq_core true cond body f s1; eval_while_eq_core true cond body f s2 let eval_code_ts (g:bool) (c:code) (s0:machine_state) (f0:fuel) (s1:machine_state) : Type0 = state_eq_opt g (BS.machine_eval_code c f0 s0) (Some s1) let rec increase_fuel (g:bool) (c:code) (s0:machine_state) (f0:fuel) (sN:machine_state) (fN:fuel) : Lemma (requires eval_code_ts g c s0 f0 sN /\ f0 <= fN) (ensures eval_code_ts g c s0 fN sN) (decreases %[f0; c]) = match c with | Ins ins -> () | Block l -> increase_fuels g l s0 f0 sN fN | IfElse cond t f -> let (s0, b0) = BS.machine_eval_ocmp s0 cond in if b0 then increase_fuel g t s0 f0 sN fN else increase_fuel g f s0 f0 sN fN | While cond c -> let (s1, b0) = BS.machine_eval_ocmp s0 cond in if b0 then ( match BS.machine_eval_code c (f0 - 1) s1 with | None -> () | Some s2 -> increase_fuel g c s1 (f0 - 1) s2 (fN - 1); if s2.BS.ms_ok then increase_fuel g (While cond c) s2 (f0 - 1) sN (fN - 1) else () ) and increase_fuels (g:bool) (c:codes) (s0:machine_state) (f0:fuel) (sN:machine_state) (fN:fuel) : Lemma (requires eval_code_ts g (Block c) s0 f0 sN /\ f0 <= fN) (ensures eval_code_ts g (Block c) s0 fN sN) (decreases %[f0; c]) = match c with | [] -> () | h::t -> ( let Some s1 = BS.machine_eval_code h f0 s0 in increase_fuel g h s0 f0 s1 fN; increase_fuels g t s1 f0 sN fN ) let lemma_cmp_eq s o1 o2 = reveal_opaque (`%BS.eval_ocmp_opaque) BS.eval_ocmp_opaque let lemma_cmp_ne s o1 o2 = reveal_opaque (`%BS.eval_ocmp_opaque) BS.eval_ocmp_opaque let lemma_cmp_le s o1 o2 = reveal_opaque (`%BS.eval_ocmp_opaque) BS.eval_ocmp_opaque let lemma_cmp_ge s o1 o2 = reveal_opaque (`%BS.eval_ocmp_opaque) BS.eval_ocmp_opaque
{ "checked_file": "/", "dependencies": [ "Vale.X64.StateLemmas.fsti.checked", "Vale.X64.State.fsti.checked", "Vale.X64.Memory.fsti.checked", "Vale.X64.Machine_Semantics_s.fst.checked", "Vale.X64.Machine_s.fst.checked", "Vale.X64.Instruction_s.fsti.checked", "Vale.X64.Flags.fsti.checked", "Vale.X64.Bytes_Code_s.fst.checked", "prims.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.FunctionalExtensionality.fsti.checked" ], "interface_file": true, "source_file": "Vale.X64.Lemmas.fst" }
[ { "abbrev": true, "full_module": "Vale.X64.Memory", "short_module": "ME" }, { "abbrev": true, "full_module": "Vale.X64.Machine_Semantics_s", "short_module": "BS" }, { "abbrev": false, "full_module": "Vale.X64.Bytes_Code_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Instruction_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.StateLemmas", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.State", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Machine_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": true, "full_module": "Vale.Lib.Map16", "short_module": "Map16" }, { "abbrev": true, "full_module": "Vale.X64.Machine_Semantics_s", "short_module": "BS" }, { "abbrev": false, "full_module": "Vale.X64.Bytes_Code_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.StateLemmas", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.State", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Machine_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.HeapLemmas", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.HeapImpl", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.Heap", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 0, "max_fuel": 2, "max_ifuel": 1, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": true, "smtencoding_l_arith_repr": "native", "smtencoding_nl_arith_repr": "wrapped", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [ "smt.arith.nl=false", "smt.QI.EAGER_THRESHOLD=100", "smt.CASE_SPLIT=3" ], "z3refresh": false, "z3rlimit": 30, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
s: Vale.X64.State.vale_state -> o1: Vale.X64.Machine_s.operand64{Prims.op_Negation (OMem? o1 || OStack? o1)} -> o2: Vale.X64.Machine_s.operand64{Prims.op_Negation (OMem? o2 || OStack? o2)} -> FStar.Pervasives.Lemma (ensures Vale.X64.Lemmas.eval_ocmp s (Vale.X64.Bytes_Code_s.OGt o1 o2) <==> Vale.X64.State.eval_operand o1 s > Vale.X64.State.eval_operand o2 s) [SMTPat (Vale.X64.Lemmas.eval_ocmp s (Vale.X64.Bytes_Code_s.OGt o1 o2))]
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "Vale.X64.State.vale_state", "Vale.X64.Machine_s.operand64", "Prims.b2t", "Prims.op_Negation", "Prims.op_BarBar", "Vale.X64.Machine_s.uu___is_OMem", "Vale.X64.Machine_s.nat64", "Vale.X64.Machine_s.reg_64", "Vale.X64.Machine_s.uu___is_OStack", "FStar.Pervasives.reveal_opaque", "Vale.X64.Machine_Semantics_s.machine_state", "Vale.X64.Machine_Semantics_s.ocmp", "Prims.bool", "Vale.X64.Machine_Semantics_s.eval_ocmp_opaque", "Prims.unit" ]
[]
true
false
true
false
false
let lemma_cmp_gt s o1 o2 =
reveal_opaque (`%BS.eval_ocmp_opaque) BS.eval_ocmp_opaque
false
Vale.X64.Lemmas.fst
Vale.X64.Lemmas.eval_ocmp_eq_core
val eval_ocmp_eq_core (g: bool) (cond: ocmp) (s: machine_state) : Lemma (ensures (let s1, b1 = BS.machine_eval_ocmp s cond in let s2, b2 = BS.machine_eval_ocmp (core_state g s) cond in state_eq_S g s1 s2 /\ b1 == b2))
val eval_ocmp_eq_core (g: bool) (cond: ocmp) (s: machine_state) : Lemma (ensures (let s1, b1 = BS.machine_eval_ocmp s cond in let s2, b2 = BS.machine_eval_ocmp (core_state g s) cond in state_eq_S g s1 s2 /\ b1 == b2))
let eval_ocmp_eq_core (g:bool) (cond:ocmp) (s:machine_state) : Lemma (ensures ( let (s1, b1) = BS.machine_eval_ocmp s cond in let (s2, b2) = BS.machine_eval_ocmp (core_state g s) cond in state_eq_S g s1 s2 /\ b1 == b2 )) = reveal_opaque (`%BS.valid_ocmp_opaque) BS.valid_ocmp_opaque; reveal_opaque (`%BS.eval_ocmp_opaque) BS.eval_ocmp_opaque; ()
{ "file_name": "vale/code/arch/x64/Vale.X64.Lemmas.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 4, "end_line": 201, "start_col": 0, "start_line": 192 }
module Vale.X64.Lemmas open FStar.Mul open Vale.X64.Machine_s open Vale.X64.State open Vale.X64.StateLemmas open Vale.X64.Instruction_s open Vale.X64.Bytes_Code_s module BS = Vale.X64.Machine_Semantics_s module ME = Vale.X64.Memory #reset-options "--initial_fuel 1 --max_fuel 1 --z3rlimit 100" #restart-solver let rec lemma_eq_instr_apply_eval_args (outs:list instr_out) (args:list instr_operand) (f:instr_args_t outs args) (oprs:instr_operands_t_args args) (s1 s2:machine_state) : Lemma (requires state_eq_S true s1 s2) (ensures BS.instr_apply_eval_args outs args f oprs s1 == BS.instr_apply_eval_args outs args f oprs s2) = let open BS in lemma_heap_ignore_ghost_machine s1.BS.ms_heap s2.BS.ms_heap; match args with | [] -> () | i::args -> ( let (v, oprs) : option (instr_val_t i) & instr_operands_t_args args = match i with | IOpEx i -> let oprs = coerce oprs in (instr_eval_operand_explicit i (fst oprs) s1, snd oprs) | IOpIm i -> (instr_eval_operand_implicit i s1, coerce oprs) in let f:arrow (instr_val_t i) (instr_args_t outs args) = coerce f in match v with | None -> () | Some v -> lemma_eq_instr_apply_eval_args outs args (f v) oprs s1 s2 ) #restart-solver let rec lemma_eq_instr_apply_eval_inouts (outs inouts:list instr_out) (args:list instr_operand) (f:instr_inouts_t outs inouts args) (oprs:instr_operands_t inouts args) (s1 s2:machine_state) : Lemma (requires state_eq_S true s1 s2) (ensures BS.instr_apply_eval_inouts outs inouts args f oprs s1 == BS.instr_apply_eval_inouts outs inouts args f oprs s2) = let open BS in lemma_heap_ignore_ghost_machine s1.BS.ms_heap s2.BS.ms_heap; match inouts with | [] -> lemma_eq_instr_apply_eval_args outs args f oprs s1 s2 | (Out, i)::inouts -> let oprs = match i with | IOpEx i -> snd #(instr_operand_t i) (coerce oprs) | IOpIm i -> coerce oprs in lemma_eq_instr_apply_eval_inouts outs inouts args (coerce f) oprs s1 s2 | (InOut, i)::inouts -> ( let (v, oprs) : option (instr_val_t i) & instr_operands_t inouts args = match i with | IOpEx i -> let oprs = coerce oprs in (instr_eval_operand_explicit i (fst oprs) s1, snd oprs) | IOpIm i -> (instr_eval_operand_implicit i s1, coerce oprs) in let f:arrow (instr_val_t i) (instr_inouts_t outs inouts args) = coerce f in match v with | None -> () | Some v -> lemma_eq_instr_apply_eval_inouts outs inouts args (f v) oprs s1 s2 ) #restart-solver #push-options "--z3rlimit_factor 2" let rec lemma_eq_instr_write_outputs (outs:list instr_out) (args:list instr_operand) (vs:instr_ret_t outs) (oprs:instr_operands_t outs args) (s1_orig s1 s2_orig s2:machine_state) : Lemma (requires state_eq_S true s1_orig s2_orig /\ state_eq_S true s1 s2) (ensures state_eq_S true (BS.instr_write_outputs outs args vs oprs s1_orig s1) (BS.instr_write_outputs outs args vs oprs s2_orig s2)) = let open BS in use_machine_state_equal (); lemma_heap_ignore_ghost_machine s1.BS.ms_heap s2.BS.ms_heap; lemma_heap_ignore_ghost_machine s1_orig.BS.ms_heap s2_orig.BS.ms_heap; allow_inversion tmaddr; match outs with | [] -> () | (_, i)::outs -> ( let ((v:instr_val_t i), (vs:instr_ret_t outs)) = match outs with | [] -> (vs, ()) | _::_ -> let vs = coerce vs in (fst vs, snd vs) in match i with | IOpEx i -> let oprs = coerce oprs in let s1 = instr_write_output_explicit i v (fst oprs) s1_orig s1 in let s2 = instr_write_output_explicit i v (fst oprs) s2_orig s2 in lemma_eq_instr_write_outputs outs args vs (snd oprs) s1_orig s1 s2_orig s2 | IOpIm i -> let s1 = instr_write_output_implicit i v s1_orig s1 in let s2 = instr_write_output_implicit i v s2_orig s2 in allow_inversion operand64; allow_inversion operand128; lemma_eq_instr_write_outputs outs args vs (coerce oprs) s1_orig s1 s2_orig s2 ) #pop-options #restart-solver let eval_ins_eq_instr (inst:BS.ins) (s1 s2:machine_state) : Lemma (requires Instr? inst /\ state_eq_S true s1 s2) (ensures state_eq_S true (BS.machine_eval_ins inst s1) (BS.machine_eval_ins inst s2)) = let open BS in let Instr it oprs ann = inst in let InstrTypeRecord #outs #args #havoc_flags' i = it in lemma_eq_instr_apply_eval_inouts outs outs args (instr_eval i) oprs s1 s2; let vs = instr_apply_eval outs args (instr_eval i) oprs s1 in let hav s = match havoc_flags' with | HavocFlags -> {s with ms_flags = havoc_flags} | PreserveFlags -> s in let s1' = hav s1 in let s2' = hav s2 in match vs with | None -> () | Some vs -> lemma_eq_instr_write_outputs outs args vs oprs s1 s1' s2 s2' let eval_code_eq_instr (inst:BS.ins) (f:fuel) (s1 s2:machine_state) : Lemma (requires Instr? inst /\ state_eq_S true s1 s2) (ensures state_eq_opt true (BS.machine_eval_code (Ins inst) f s1) (BS.machine_eval_code (Ins inst) f s2)) = reveal_opaque (`%BS.machine_eval_code_ins) BS.machine_eval_code_ins; eval_ins_eq_instr inst ({s1 with BS.ms_trace = []}) ({s2 with BS.ms_trace = []}) let eval_code_eq_dealloc (inst:BS.ins) (f:fuel) (s1 s2:machine_state) : Lemma (requires Dealloc? inst /\ state_eq_S true s1 s2) (ensures state_eq_opt true (BS.machine_eval_code (Ins inst) f s1) (BS.machine_eval_code (Ins inst) f s2)) = reveal_opaque (`%BS.machine_eval_code_ins) BS.machine_eval_code_ins; use_machine_state_equal (); lemma_heap_ignore_ghost_machine s1.BS.ms_heap s2.BS.ms_heap; allow_inversion tmaddr let eval_code_eq_alloc (inst:BS.ins) (f:fuel) (s1 s2:machine_state) : Lemma (requires Alloc? inst /\ state_eq_S true s1 s2) (ensures state_eq_opt true (BS.machine_eval_code (Ins inst) f s1) (BS.machine_eval_code (Ins inst) f s2)) = reveal_opaque (`%BS.machine_eval_code_ins) BS.machine_eval_code_ins; use_machine_state_equal (); lemma_heap_ignore_ghost_machine s1.BS.ms_heap s2.BS.ms_heap; allow_inversion tmaddr let eval_code_eq_push (inst:BS.ins) (f:fuel) (s1 s2:machine_state) : Lemma (requires Push? inst /\ state_eq_S true s1 s2) (ensures state_eq_opt true (BS.machine_eval_code (Ins inst) f s1) (BS.machine_eval_code (Ins inst) f s2)) = reveal_opaque (`%BS.machine_eval_code_ins) BS.machine_eval_code_ins; use_machine_state_equal (); lemma_heap_ignore_ghost_machine s1.BS.ms_heap s2.BS.ms_heap; allow_inversion tmaddr let eval_code_eq_pop (inst:BS.ins) (f:fuel) (s1 s2:machine_state) : Lemma (requires Pop? inst /\ state_eq_S true s1 s2) (ensures state_eq_opt true (BS.machine_eval_code (Ins inst) f s1) (BS.machine_eval_code (Ins inst) f s2)) = reveal_opaque (`%BS.machine_eval_code_ins) BS.machine_eval_code_ins; use_machine_state_equal (); lemma_heap_ignore_ghost_machine s1.BS.ms_heap s2.BS.ms_heap; allow_inversion tmaddr let eval_code_eq_ins (i:BS.ins) (f:fuel) (s1 s2:machine_state) : Lemma (requires state_eq_S true s1 s2) (ensures state_eq_opt true (BS.machine_eval_code (Ins i) f s1) (BS.machine_eval_code (Ins i) f s2)) = match i with | Instr _ _ _ -> eval_code_eq_instr i f s1 s2 | Dealloc _ -> eval_code_eq_dealloc i f s1 s2 | Alloc _ -> eval_code_eq_alloc i f s1 s2 | Push _ _ -> eval_code_eq_push i f s1 s2 | Pop _ _ -> eval_code_eq_pop i f s1 s2 #reset-options "--fuel 2 --z3rlimit 30"
{ "checked_file": "/", "dependencies": [ "Vale.X64.StateLemmas.fsti.checked", "Vale.X64.State.fsti.checked", "Vale.X64.Memory.fsti.checked", "Vale.X64.Machine_Semantics_s.fst.checked", "Vale.X64.Machine_s.fst.checked", "Vale.X64.Instruction_s.fsti.checked", "Vale.X64.Flags.fsti.checked", "Vale.X64.Bytes_Code_s.fst.checked", "prims.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.FunctionalExtensionality.fsti.checked" ], "interface_file": true, "source_file": "Vale.X64.Lemmas.fst" }
[ { "abbrev": true, "full_module": "Vale.X64.Memory", "short_module": "ME" }, { "abbrev": true, "full_module": "Vale.X64.Machine_Semantics_s", "short_module": "BS" }, { "abbrev": false, "full_module": "Vale.X64.Bytes_Code_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Instruction_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.StateLemmas", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.State", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Machine_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": true, "full_module": "Vale.Lib.Map16", "short_module": "Map16" }, { "abbrev": true, "full_module": "Vale.X64.Machine_Semantics_s", "short_module": "BS" }, { "abbrev": false, "full_module": "Vale.X64.Bytes_Code_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.StateLemmas", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.State", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Machine_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.HeapLemmas", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.HeapImpl", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.Heap", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 0, "max_fuel": 2, "max_ifuel": 1, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": true, "smtencoding_l_arith_repr": "native", "smtencoding_nl_arith_repr": "wrapped", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [ "smt.arith.nl=false", "smt.QI.EAGER_THRESHOLD=100", "smt.CASE_SPLIT=3" ], "z3refresh": false, "z3rlimit": 30, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
g: Prims.bool -> cond: Vale.X64.Bytes_Code_s.ocmp -> s: Vale.X64.StateLemmas.machine_state -> FStar.Pervasives.Lemma (ensures (let _ = Vale.X64.Machine_Semantics_s.machine_eval_ocmp s cond in (let FStar.Pervasives.Native.Mktuple2 #_ #_ s1 b1 = _ in let _ = Vale.X64.Machine_Semantics_s.machine_eval_ocmp (Vale.X64.Lemmas.core_state g s) cond in (let FStar.Pervasives.Native.Mktuple2 #_ #_ s2 b2 = _ in Vale.X64.Lemmas.state_eq_S g s1 s2 /\ b1 == b2) <: Type0) <: Type0))
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "Prims.bool", "Vale.X64.Bytes_Code_s.ocmp", "Vale.X64.StateLemmas.machine_state", "Prims.unit", "FStar.Pervasives.reveal_opaque", "Vale.X64.Machine_Semantics_s.machine_state", "Vale.X64.Machine_Semantics_s.ocmp", "Vale.X64.Machine_Semantics_s.eval_ocmp_opaque", "Vale.X64.Machine_Semantics_s.valid_ocmp_opaque", "Prims.l_True", "Prims.squash", "Prims.l_and", "Vale.X64.Lemmas.state_eq_S", "Prims.eq2", "FStar.Pervasives.Native.tuple2", "Vale.X64.Machine_Semantics_s.machine_eval_ocmp", "Vale.X64.Lemmas.core_state", "Prims.Nil", "FStar.Pervasives.pattern" ]
[]
true
false
true
false
false
let eval_ocmp_eq_core (g: bool) (cond: ocmp) (s: machine_state) : Lemma (ensures (let s1, b1 = BS.machine_eval_ocmp s cond in let s2, b2 = BS.machine_eval_ocmp (core_state g s) cond in state_eq_S g s1 s2 /\ b1 == b2)) =
reveal_opaque (`%BS.valid_ocmp_opaque) BS.valid_ocmp_opaque; reveal_opaque (`%BS.eval_ocmp_opaque) BS.eval_ocmp_opaque; ()
false
Vale.X64.Lemmas.fst
Vale.X64.Lemmas.eval_while_inv
val eval_while_inv (c:code) (s0:vale_state) (fW:fuel) (sW:vale_state) : Type0
val eval_while_inv (c:code) (s0:vale_state) (fW:fuel) (sW:vale_state) : Type0
let eval_while_inv (c:code) (s0:vale_state) (fW:fuel) (sW:vale_state) : Type0 = eval_while_inv_temp c s0 fW sW
{ "file_name": "vale/code/arch/x64/Vale.X64.Lemmas.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 32, "end_line": 380, "start_col": 0, "start_line": 379 }
module Vale.X64.Lemmas open FStar.Mul open Vale.X64.Machine_s open Vale.X64.State open Vale.X64.StateLemmas open Vale.X64.Instruction_s open Vale.X64.Bytes_Code_s module BS = Vale.X64.Machine_Semantics_s module ME = Vale.X64.Memory #reset-options "--initial_fuel 1 --max_fuel 1 --z3rlimit 100" #restart-solver let rec lemma_eq_instr_apply_eval_args (outs:list instr_out) (args:list instr_operand) (f:instr_args_t outs args) (oprs:instr_operands_t_args args) (s1 s2:machine_state) : Lemma (requires state_eq_S true s1 s2) (ensures BS.instr_apply_eval_args outs args f oprs s1 == BS.instr_apply_eval_args outs args f oprs s2) = let open BS in lemma_heap_ignore_ghost_machine s1.BS.ms_heap s2.BS.ms_heap; match args with | [] -> () | i::args -> ( let (v, oprs) : option (instr_val_t i) & instr_operands_t_args args = match i with | IOpEx i -> let oprs = coerce oprs in (instr_eval_operand_explicit i (fst oprs) s1, snd oprs) | IOpIm i -> (instr_eval_operand_implicit i s1, coerce oprs) in let f:arrow (instr_val_t i) (instr_args_t outs args) = coerce f in match v with | None -> () | Some v -> lemma_eq_instr_apply_eval_args outs args (f v) oprs s1 s2 ) #restart-solver let rec lemma_eq_instr_apply_eval_inouts (outs inouts:list instr_out) (args:list instr_operand) (f:instr_inouts_t outs inouts args) (oprs:instr_operands_t inouts args) (s1 s2:machine_state) : Lemma (requires state_eq_S true s1 s2) (ensures BS.instr_apply_eval_inouts outs inouts args f oprs s1 == BS.instr_apply_eval_inouts outs inouts args f oprs s2) = let open BS in lemma_heap_ignore_ghost_machine s1.BS.ms_heap s2.BS.ms_heap; match inouts with | [] -> lemma_eq_instr_apply_eval_args outs args f oprs s1 s2 | (Out, i)::inouts -> let oprs = match i with | IOpEx i -> snd #(instr_operand_t i) (coerce oprs) | IOpIm i -> coerce oprs in lemma_eq_instr_apply_eval_inouts outs inouts args (coerce f) oprs s1 s2 | (InOut, i)::inouts -> ( let (v, oprs) : option (instr_val_t i) & instr_operands_t inouts args = match i with | IOpEx i -> let oprs = coerce oprs in (instr_eval_operand_explicit i (fst oprs) s1, snd oprs) | IOpIm i -> (instr_eval_operand_implicit i s1, coerce oprs) in let f:arrow (instr_val_t i) (instr_inouts_t outs inouts args) = coerce f in match v with | None -> () | Some v -> lemma_eq_instr_apply_eval_inouts outs inouts args (f v) oprs s1 s2 ) #restart-solver #push-options "--z3rlimit_factor 2" let rec lemma_eq_instr_write_outputs (outs:list instr_out) (args:list instr_operand) (vs:instr_ret_t outs) (oprs:instr_operands_t outs args) (s1_orig s1 s2_orig s2:machine_state) : Lemma (requires state_eq_S true s1_orig s2_orig /\ state_eq_S true s1 s2) (ensures state_eq_S true (BS.instr_write_outputs outs args vs oprs s1_orig s1) (BS.instr_write_outputs outs args vs oprs s2_orig s2)) = let open BS in use_machine_state_equal (); lemma_heap_ignore_ghost_machine s1.BS.ms_heap s2.BS.ms_heap; lemma_heap_ignore_ghost_machine s1_orig.BS.ms_heap s2_orig.BS.ms_heap; allow_inversion tmaddr; match outs with | [] -> () | (_, i)::outs -> ( let ((v:instr_val_t i), (vs:instr_ret_t outs)) = match outs with | [] -> (vs, ()) | _::_ -> let vs = coerce vs in (fst vs, snd vs) in match i with | IOpEx i -> let oprs = coerce oprs in let s1 = instr_write_output_explicit i v (fst oprs) s1_orig s1 in let s2 = instr_write_output_explicit i v (fst oprs) s2_orig s2 in lemma_eq_instr_write_outputs outs args vs (snd oprs) s1_orig s1 s2_orig s2 | IOpIm i -> let s1 = instr_write_output_implicit i v s1_orig s1 in let s2 = instr_write_output_implicit i v s2_orig s2 in allow_inversion operand64; allow_inversion operand128; lemma_eq_instr_write_outputs outs args vs (coerce oprs) s1_orig s1 s2_orig s2 ) #pop-options #restart-solver let eval_ins_eq_instr (inst:BS.ins) (s1 s2:machine_state) : Lemma (requires Instr? inst /\ state_eq_S true s1 s2) (ensures state_eq_S true (BS.machine_eval_ins inst s1) (BS.machine_eval_ins inst s2)) = let open BS in let Instr it oprs ann = inst in let InstrTypeRecord #outs #args #havoc_flags' i = it in lemma_eq_instr_apply_eval_inouts outs outs args (instr_eval i) oprs s1 s2; let vs = instr_apply_eval outs args (instr_eval i) oprs s1 in let hav s = match havoc_flags' with | HavocFlags -> {s with ms_flags = havoc_flags} | PreserveFlags -> s in let s1' = hav s1 in let s2' = hav s2 in match vs with | None -> () | Some vs -> lemma_eq_instr_write_outputs outs args vs oprs s1 s1' s2 s2' let eval_code_eq_instr (inst:BS.ins) (f:fuel) (s1 s2:machine_state) : Lemma (requires Instr? inst /\ state_eq_S true s1 s2) (ensures state_eq_opt true (BS.machine_eval_code (Ins inst) f s1) (BS.machine_eval_code (Ins inst) f s2)) = reveal_opaque (`%BS.machine_eval_code_ins) BS.machine_eval_code_ins; eval_ins_eq_instr inst ({s1 with BS.ms_trace = []}) ({s2 with BS.ms_trace = []}) let eval_code_eq_dealloc (inst:BS.ins) (f:fuel) (s1 s2:machine_state) : Lemma (requires Dealloc? inst /\ state_eq_S true s1 s2) (ensures state_eq_opt true (BS.machine_eval_code (Ins inst) f s1) (BS.machine_eval_code (Ins inst) f s2)) = reveal_opaque (`%BS.machine_eval_code_ins) BS.machine_eval_code_ins; use_machine_state_equal (); lemma_heap_ignore_ghost_machine s1.BS.ms_heap s2.BS.ms_heap; allow_inversion tmaddr let eval_code_eq_alloc (inst:BS.ins) (f:fuel) (s1 s2:machine_state) : Lemma (requires Alloc? inst /\ state_eq_S true s1 s2) (ensures state_eq_opt true (BS.machine_eval_code (Ins inst) f s1) (BS.machine_eval_code (Ins inst) f s2)) = reveal_opaque (`%BS.machine_eval_code_ins) BS.machine_eval_code_ins; use_machine_state_equal (); lemma_heap_ignore_ghost_machine s1.BS.ms_heap s2.BS.ms_heap; allow_inversion tmaddr let eval_code_eq_push (inst:BS.ins) (f:fuel) (s1 s2:machine_state) : Lemma (requires Push? inst /\ state_eq_S true s1 s2) (ensures state_eq_opt true (BS.machine_eval_code (Ins inst) f s1) (BS.machine_eval_code (Ins inst) f s2)) = reveal_opaque (`%BS.machine_eval_code_ins) BS.machine_eval_code_ins; use_machine_state_equal (); lemma_heap_ignore_ghost_machine s1.BS.ms_heap s2.BS.ms_heap; allow_inversion tmaddr let eval_code_eq_pop (inst:BS.ins) (f:fuel) (s1 s2:machine_state) : Lemma (requires Pop? inst /\ state_eq_S true s1 s2) (ensures state_eq_opt true (BS.machine_eval_code (Ins inst) f s1) (BS.machine_eval_code (Ins inst) f s2)) = reveal_opaque (`%BS.machine_eval_code_ins) BS.machine_eval_code_ins; use_machine_state_equal (); lemma_heap_ignore_ghost_machine s1.BS.ms_heap s2.BS.ms_heap; allow_inversion tmaddr let eval_code_eq_ins (i:BS.ins) (f:fuel) (s1 s2:machine_state) : Lemma (requires state_eq_S true s1 s2) (ensures state_eq_opt true (BS.machine_eval_code (Ins i) f s1) (BS.machine_eval_code (Ins i) f s2)) = match i with | Instr _ _ _ -> eval_code_eq_instr i f s1 s2 | Dealloc _ -> eval_code_eq_dealloc i f s1 s2 | Alloc _ -> eval_code_eq_alloc i f s1 s2 | Push _ _ -> eval_code_eq_push i f s1 s2 | Pop _ _ -> eval_code_eq_pop i f s1 s2 #reset-options "--fuel 2 --z3rlimit 30" let eval_ocmp_eq_core (g:bool) (cond:ocmp) (s:machine_state) : Lemma (ensures ( let (s1, b1) = BS.machine_eval_ocmp s cond in let (s2, b2) = BS.machine_eval_ocmp (core_state g s) cond in state_eq_S g s1 s2 /\ b1 == b2 )) = reveal_opaque (`%BS.valid_ocmp_opaque) BS.valid_ocmp_opaque; reveal_opaque (`%BS.eval_ocmp_opaque) BS.eval_ocmp_opaque; () #restart-solver let rec eval_code_eq_core (g:bool) (c:code) (f:fuel) (s:machine_state) : Lemma (ensures state_eq_opt g (BS.machine_eval_code c f s) (BS.machine_eval_code c f (core_state g s))) (decreases %[f; c]) = match c with | Ins i -> reveal_opaque (`%BS.machine_eval_code_ins) BS.machine_eval_code_ins; if g then eval_code_eq_ins i f s (core_state g s) | Block cs -> eval_codes_eq_core g cs f s | IfElse cond ct cf -> eval_ocmp_eq_core g cond s; let (s', _) = BS.machine_eval_ocmp s cond in let (t', _) = BS.machine_eval_ocmp (core_state g s) cond in eval_code_eq_core g ct f s'; eval_code_eq_core g ct f t'; eval_code_eq_core g cf f s'; eval_code_eq_core g cf f t'; () | While cond body -> eval_while_eq_core g cond body f s and eval_codes_eq_core (g:bool) (cs:codes) (f:fuel) (s:machine_state) : Lemma (ensures state_eq_opt g (BS.machine_eval_codes cs f s) (BS.machine_eval_codes cs f (core_state g s))) (decreases %[f; cs]) = match cs with | [] -> () | c'::cs' -> ( eval_code_eq_core g c' f s; match (machine_eval_code c' f s, machine_eval_code c' f (core_state g s)) with | (None, None) -> () | (Some s', Some t') -> eval_codes_eq_core g cs' f s'; eval_codes_eq_core g cs' f t' ) and eval_while_eq_core (g:bool) (cond:ocmp) (body:code) (f:fuel) (s:machine_state) : Lemma (ensures state_eq_opt g (BS.machine_eval_while cond body f s) (BS.machine_eval_while cond body f (core_state g s))) (decreases %[f; body]) = if f > 0 then ( eval_ocmp_eq_core g cond s; let (s1, _) = BS.machine_eval_ocmp s cond in let (t1, _) = BS.machine_eval_ocmp (core_state g s) cond in eval_code_eq_core g body (f - 1) s1; eval_code_eq_core g body (f - 1) t1; match (BS.machine_eval_code body (f - 1) s1, BS.machine_eval_code body (f - 1) t1) with | (None, None) -> () | (Some s2, Some t2) -> eval_while_eq_core g cond body (f - 1) s2; eval_while_eq_core g cond body (f - 1) t2; () ) let eval_code_eq_f (c:code) (f:fuel) (s1 s2:machine_state) : Lemma (requires state_eq_S false s1 s2) (ensures state_eq_opt false (BS.machine_eval_code c f s1) (BS.machine_eval_code c f s2)) [SMTPat (BS.machine_eval_code c f s1); SMTPat (BS.machine_eval_code c f s2)] = eval_code_eq_core false c f s1; eval_code_eq_core false c f s2 let eval_codes_eq_f (cs:codes) (f:fuel) (s1 s2:machine_state) : Lemma (requires state_eq_S false s1 s2) (ensures state_eq_opt false (BS.machine_eval_codes cs f s1) (BS.machine_eval_codes cs f s2)) [SMTPat (BS.machine_eval_codes cs f s1); SMTPat (BS.machine_eval_codes cs f s2)] = eval_codes_eq_core false cs f s1; eval_codes_eq_core false cs f s2 let eval_while_eq_f (cond:ocmp) (body:code) (f:fuel) (s1 s2:machine_state) : Lemma (requires state_eq_S false s1 s2) (ensures state_eq_opt false (BS.machine_eval_while cond body f s1) (BS.machine_eval_while cond body f s2)) [SMTPat (BS.machine_eval_while cond body f s1); SMTPat (BS.machine_eval_while cond body f s2)] = eval_while_eq_core false cond body f s1; eval_while_eq_core false cond body f s2 let eval_code_eq_t (c:code) (f:fuel) (s1 s2:machine_state) : Lemma (requires state_eq_S true s1 s2) (ensures state_eq_opt true (BS.machine_eval_code c f s1) (BS.machine_eval_code c f s2)) [SMTPat (BS.machine_eval_code c f s1); SMTPat (BS.machine_eval_code c f s2)] = eval_code_eq_core true c f s1; eval_code_eq_core true c f s2 let eval_codes_eq_t (cs:codes) (f:fuel) (s1 s2:machine_state) : Lemma (requires state_eq_S true s1 s2) (ensures state_eq_opt true (BS.machine_eval_codes cs f s1) (BS.machine_eval_codes cs f s2)) [SMTPat (BS.machine_eval_codes cs f s1); SMTPat (BS.machine_eval_codes cs f s2)] = eval_codes_eq_core true cs f s1; eval_codes_eq_core true cs f s2 let eval_while_eq_t (cond:ocmp) (body:code) (f:fuel) (s1 s2:machine_state) : Lemma (requires state_eq_S true s1 s2) (ensures state_eq_opt true (BS.machine_eval_while cond body f s1) (BS.machine_eval_while cond body f s2)) [SMTPat (BS.machine_eval_while cond body f s1); SMTPat (BS.machine_eval_while cond body f s2)] = eval_while_eq_core true cond body f s1; eval_while_eq_core true cond body f s2 let eval_code_ts (g:bool) (c:code) (s0:machine_state) (f0:fuel) (s1:machine_state) : Type0 = state_eq_opt g (BS.machine_eval_code c f0 s0) (Some s1) let rec increase_fuel (g:bool) (c:code) (s0:machine_state) (f0:fuel) (sN:machine_state) (fN:fuel) : Lemma (requires eval_code_ts g c s0 f0 sN /\ f0 <= fN) (ensures eval_code_ts g c s0 fN sN) (decreases %[f0; c]) = match c with | Ins ins -> () | Block l -> increase_fuels g l s0 f0 sN fN | IfElse cond t f -> let (s0, b0) = BS.machine_eval_ocmp s0 cond in if b0 then increase_fuel g t s0 f0 sN fN else increase_fuel g f s0 f0 sN fN | While cond c -> let (s1, b0) = BS.machine_eval_ocmp s0 cond in if b0 then ( match BS.machine_eval_code c (f0 - 1) s1 with | None -> () | Some s2 -> increase_fuel g c s1 (f0 - 1) s2 (fN - 1); if s2.BS.ms_ok then increase_fuel g (While cond c) s2 (f0 - 1) sN (fN - 1) else () ) and increase_fuels (g:bool) (c:codes) (s0:machine_state) (f0:fuel) (sN:machine_state) (fN:fuel) : Lemma (requires eval_code_ts g (Block c) s0 f0 sN /\ f0 <= fN) (ensures eval_code_ts g (Block c) s0 fN sN) (decreases %[f0; c]) = match c with | [] -> () | h::t -> ( let Some s1 = BS.machine_eval_code h f0 s0 in increase_fuel g h s0 f0 s1 fN; increase_fuels g t s1 f0 sN fN ) let lemma_cmp_eq s o1 o2 = reveal_opaque (`%BS.eval_ocmp_opaque) BS.eval_ocmp_opaque let lemma_cmp_ne s o1 o2 = reveal_opaque (`%BS.eval_ocmp_opaque) BS.eval_ocmp_opaque let lemma_cmp_le s o1 o2 = reveal_opaque (`%BS.eval_ocmp_opaque) BS.eval_ocmp_opaque let lemma_cmp_ge s o1 o2 = reveal_opaque (`%BS.eval_ocmp_opaque) BS.eval_ocmp_opaque let lemma_cmp_lt s o1 o2 = reveal_opaque (`%BS.eval_ocmp_opaque) BS.eval_ocmp_opaque let lemma_cmp_gt s o1 o2 = reveal_opaque (`%BS.eval_ocmp_opaque) BS.eval_ocmp_opaque let lemma_valid_cmp_eq s o1 o2 = () let lemma_valid_cmp_ne s o1 o2 = () let lemma_valid_cmp_le s o1 o2 = () let lemma_valid_cmp_ge s o1 o2 = () let lemma_valid_cmp_lt s o1 o2 = () let lemma_valid_cmp_gt s o1 o2 = () let compute_merge_total (f0:fuel) (fM:fuel) = if f0 > fM then f0 else fM let lemma_merge_total (b0:codes) (s0:vale_state) (f0:fuel) (sM:vale_state) (fM:fuel) (sN:vale_state) = let f = if f0 > fM then f0 else fM in increase_fuel (codes_modifies_ghost b0) (Cons?.hd b0) (state_to_S s0) f0 (state_to_S sM) f; increase_fuel (codes_modifies_ghost b0) (Block (Cons?.tl b0)) (state_to_S sM) fM (state_to_S sN) f let lemma_empty_total (s0:vale_state) (bN:codes) = (s0, 0) let lemma_ifElse_total (ifb:ocmp) (ct:code) (cf:code) (s0:vale_state) = (eval_ocmp s0 ifb, {s0 with vs_flags = havoc_flags}, s0, 0) let lemma_havoc_flags : squash (Flags.to_fun havoc_flags == BS.havoc_flags) = assert (FStar.FunctionalExtensionality.feq (Flags.to_fun havoc_flags) BS.havoc_flags) let lemma_ifElseTrue_total (ifb:ocmp) (ct:code) (cf:code) (s0:vale_state) (f0:fuel) (sM:vale_state) = reveal_opaque (`%BS.valid_ocmp_opaque) BS.valid_ocmp_opaque; reveal_opaque (`%BS.eval_ocmp_opaque) BS.eval_ocmp_opaque let lemma_ifElseFalse_total (ifb:ocmp) (ct:code) (cf:code) (s0:vale_state) (f0:fuel) (sM:vale_state) = reveal_opaque (`%BS.valid_ocmp_opaque) BS.valid_ocmp_opaque; reveal_opaque (`%BS.eval_ocmp_opaque) BS.eval_ocmp_opaque let eval_while_inv_temp (c:code) (s0:vale_state) (fW:fuel) (sW:vale_state) : Type0 = forall (f:nat).{:pattern BS.machine_eval_code c f (state_to_S sW)} Some? (BS.machine_eval_code c f (state_to_S sW)) ==> state_eq_opt (code_modifies_ghost c) (BS.machine_eval_code c (f + fW) (state_to_S s0)) (BS.machine_eval_code c f (state_to_S sW))
{ "checked_file": "/", "dependencies": [ "Vale.X64.StateLemmas.fsti.checked", "Vale.X64.State.fsti.checked", "Vale.X64.Memory.fsti.checked", "Vale.X64.Machine_Semantics_s.fst.checked", "Vale.X64.Machine_s.fst.checked", "Vale.X64.Instruction_s.fsti.checked", "Vale.X64.Flags.fsti.checked", "Vale.X64.Bytes_Code_s.fst.checked", "prims.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.FunctionalExtensionality.fsti.checked" ], "interface_file": true, "source_file": "Vale.X64.Lemmas.fst" }
[ { "abbrev": true, "full_module": "Vale.X64.Memory", "short_module": "ME" }, { "abbrev": true, "full_module": "Vale.X64.Machine_Semantics_s", "short_module": "BS" }, { "abbrev": false, "full_module": "Vale.X64.Bytes_Code_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Instruction_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.StateLemmas", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.State", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Machine_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": true, "full_module": "Vale.Lib.Map16", "short_module": "Map16" }, { "abbrev": true, "full_module": "Vale.X64.Machine_Semantics_s", "short_module": "BS" }, { "abbrev": false, "full_module": "Vale.X64.Bytes_Code_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.StateLemmas", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.State", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Machine_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.HeapLemmas", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.HeapImpl", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.Heap", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 0, "max_fuel": 2, "max_ifuel": 1, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": true, "smtencoding_l_arith_repr": "native", "smtencoding_nl_arith_repr": "wrapped", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [ "smt.arith.nl=false", "smt.QI.EAGER_THRESHOLD=100", "smt.CASE_SPLIT=3" ], "z3refresh": false, "z3rlimit": 30, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
c: Vale.X64.StateLemmas.code -> s0: Vale.X64.State.vale_state -> fW: Vale.X64.Lemmas.fuel -> sW: Vale.X64.State.vale_state -> Type0
Prims.Tot
[ "total" ]
[]
[ "Vale.X64.StateLemmas.code", "Vale.X64.State.vale_state", "Vale.X64.Lemmas.fuel", "Vale.X64.Lemmas.eval_while_inv_temp" ]
[]
false
false
false
true
true
let eval_while_inv (c: code) (s0: vale_state) (fW: fuel) (sW: vale_state) : Type0 =
eval_while_inv_temp c s0 fW sW
false
Vale.X64.Lemmas.fst
Vale.X64.Lemmas.lemma_empty_total
val lemma_empty_total (s0:vale_state) (bN:codes) : Ghost (vale_state & fuel) (requires True) (ensures (fun (sM, fM) -> s0 == sM /\ eval_code (Block []) s0 fM sM ))
val lemma_empty_total (s0:vale_state) (bN:codes) : Ghost (vale_state & fuel) (requires True) (ensures (fun (sM, fM) -> s0 == sM /\ eval_code (Block []) s0 fM sM ))
let lemma_empty_total (s0:vale_state) (bN:codes) = (s0, 0)
{ "file_name": "vale/code/arch/x64/Vale.X64.Lemmas.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 9, "end_line": 356, "start_col": 0, "start_line": 355 }
module Vale.X64.Lemmas open FStar.Mul open Vale.X64.Machine_s open Vale.X64.State open Vale.X64.StateLemmas open Vale.X64.Instruction_s open Vale.X64.Bytes_Code_s module BS = Vale.X64.Machine_Semantics_s module ME = Vale.X64.Memory #reset-options "--initial_fuel 1 --max_fuel 1 --z3rlimit 100" #restart-solver let rec lemma_eq_instr_apply_eval_args (outs:list instr_out) (args:list instr_operand) (f:instr_args_t outs args) (oprs:instr_operands_t_args args) (s1 s2:machine_state) : Lemma (requires state_eq_S true s1 s2) (ensures BS.instr_apply_eval_args outs args f oprs s1 == BS.instr_apply_eval_args outs args f oprs s2) = let open BS in lemma_heap_ignore_ghost_machine s1.BS.ms_heap s2.BS.ms_heap; match args with | [] -> () | i::args -> ( let (v, oprs) : option (instr_val_t i) & instr_operands_t_args args = match i with | IOpEx i -> let oprs = coerce oprs in (instr_eval_operand_explicit i (fst oprs) s1, snd oprs) | IOpIm i -> (instr_eval_operand_implicit i s1, coerce oprs) in let f:arrow (instr_val_t i) (instr_args_t outs args) = coerce f in match v with | None -> () | Some v -> lemma_eq_instr_apply_eval_args outs args (f v) oprs s1 s2 ) #restart-solver let rec lemma_eq_instr_apply_eval_inouts (outs inouts:list instr_out) (args:list instr_operand) (f:instr_inouts_t outs inouts args) (oprs:instr_operands_t inouts args) (s1 s2:machine_state) : Lemma (requires state_eq_S true s1 s2) (ensures BS.instr_apply_eval_inouts outs inouts args f oprs s1 == BS.instr_apply_eval_inouts outs inouts args f oprs s2) = let open BS in lemma_heap_ignore_ghost_machine s1.BS.ms_heap s2.BS.ms_heap; match inouts with | [] -> lemma_eq_instr_apply_eval_args outs args f oprs s1 s2 | (Out, i)::inouts -> let oprs = match i with | IOpEx i -> snd #(instr_operand_t i) (coerce oprs) | IOpIm i -> coerce oprs in lemma_eq_instr_apply_eval_inouts outs inouts args (coerce f) oprs s1 s2 | (InOut, i)::inouts -> ( let (v, oprs) : option (instr_val_t i) & instr_operands_t inouts args = match i with | IOpEx i -> let oprs = coerce oprs in (instr_eval_operand_explicit i (fst oprs) s1, snd oprs) | IOpIm i -> (instr_eval_operand_implicit i s1, coerce oprs) in let f:arrow (instr_val_t i) (instr_inouts_t outs inouts args) = coerce f in match v with | None -> () | Some v -> lemma_eq_instr_apply_eval_inouts outs inouts args (f v) oprs s1 s2 ) #restart-solver #push-options "--z3rlimit_factor 2" let rec lemma_eq_instr_write_outputs (outs:list instr_out) (args:list instr_operand) (vs:instr_ret_t outs) (oprs:instr_operands_t outs args) (s1_orig s1 s2_orig s2:machine_state) : Lemma (requires state_eq_S true s1_orig s2_orig /\ state_eq_S true s1 s2) (ensures state_eq_S true (BS.instr_write_outputs outs args vs oprs s1_orig s1) (BS.instr_write_outputs outs args vs oprs s2_orig s2)) = let open BS in use_machine_state_equal (); lemma_heap_ignore_ghost_machine s1.BS.ms_heap s2.BS.ms_heap; lemma_heap_ignore_ghost_machine s1_orig.BS.ms_heap s2_orig.BS.ms_heap; allow_inversion tmaddr; match outs with | [] -> () | (_, i)::outs -> ( let ((v:instr_val_t i), (vs:instr_ret_t outs)) = match outs with | [] -> (vs, ()) | _::_ -> let vs = coerce vs in (fst vs, snd vs) in match i with | IOpEx i -> let oprs = coerce oprs in let s1 = instr_write_output_explicit i v (fst oprs) s1_orig s1 in let s2 = instr_write_output_explicit i v (fst oprs) s2_orig s2 in lemma_eq_instr_write_outputs outs args vs (snd oprs) s1_orig s1 s2_orig s2 | IOpIm i -> let s1 = instr_write_output_implicit i v s1_orig s1 in let s2 = instr_write_output_implicit i v s2_orig s2 in allow_inversion operand64; allow_inversion operand128; lemma_eq_instr_write_outputs outs args vs (coerce oprs) s1_orig s1 s2_orig s2 ) #pop-options #restart-solver let eval_ins_eq_instr (inst:BS.ins) (s1 s2:machine_state) : Lemma (requires Instr? inst /\ state_eq_S true s1 s2) (ensures state_eq_S true (BS.machine_eval_ins inst s1) (BS.machine_eval_ins inst s2)) = let open BS in let Instr it oprs ann = inst in let InstrTypeRecord #outs #args #havoc_flags' i = it in lemma_eq_instr_apply_eval_inouts outs outs args (instr_eval i) oprs s1 s2; let vs = instr_apply_eval outs args (instr_eval i) oprs s1 in let hav s = match havoc_flags' with | HavocFlags -> {s with ms_flags = havoc_flags} | PreserveFlags -> s in let s1' = hav s1 in let s2' = hav s2 in match vs with | None -> () | Some vs -> lemma_eq_instr_write_outputs outs args vs oprs s1 s1' s2 s2' let eval_code_eq_instr (inst:BS.ins) (f:fuel) (s1 s2:machine_state) : Lemma (requires Instr? inst /\ state_eq_S true s1 s2) (ensures state_eq_opt true (BS.machine_eval_code (Ins inst) f s1) (BS.machine_eval_code (Ins inst) f s2)) = reveal_opaque (`%BS.machine_eval_code_ins) BS.machine_eval_code_ins; eval_ins_eq_instr inst ({s1 with BS.ms_trace = []}) ({s2 with BS.ms_trace = []}) let eval_code_eq_dealloc (inst:BS.ins) (f:fuel) (s1 s2:machine_state) : Lemma (requires Dealloc? inst /\ state_eq_S true s1 s2) (ensures state_eq_opt true (BS.machine_eval_code (Ins inst) f s1) (BS.machine_eval_code (Ins inst) f s2)) = reveal_opaque (`%BS.machine_eval_code_ins) BS.machine_eval_code_ins; use_machine_state_equal (); lemma_heap_ignore_ghost_machine s1.BS.ms_heap s2.BS.ms_heap; allow_inversion tmaddr let eval_code_eq_alloc (inst:BS.ins) (f:fuel) (s1 s2:machine_state) : Lemma (requires Alloc? inst /\ state_eq_S true s1 s2) (ensures state_eq_opt true (BS.machine_eval_code (Ins inst) f s1) (BS.machine_eval_code (Ins inst) f s2)) = reveal_opaque (`%BS.machine_eval_code_ins) BS.machine_eval_code_ins; use_machine_state_equal (); lemma_heap_ignore_ghost_machine s1.BS.ms_heap s2.BS.ms_heap; allow_inversion tmaddr let eval_code_eq_push (inst:BS.ins) (f:fuel) (s1 s2:machine_state) : Lemma (requires Push? inst /\ state_eq_S true s1 s2) (ensures state_eq_opt true (BS.machine_eval_code (Ins inst) f s1) (BS.machine_eval_code (Ins inst) f s2)) = reveal_opaque (`%BS.machine_eval_code_ins) BS.machine_eval_code_ins; use_machine_state_equal (); lemma_heap_ignore_ghost_machine s1.BS.ms_heap s2.BS.ms_heap; allow_inversion tmaddr let eval_code_eq_pop (inst:BS.ins) (f:fuel) (s1 s2:machine_state) : Lemma (requires Pop? inst /\ state_eq_S true s1 s2) (ensures state_eq_opt true (BS.machine_eval_code (Ins inst) f s1) (BS.machine_eval_code (Ins inst) f s2)) = reveal_opaque (`%BS.machine_eval_code_ins) BS.machine_eval_code_ins; use_machine_state_equal (); lemma_heap_ignore_ghost_machine s1.BS.ms_heap s2.BS.ms_heap; allow_inversion tmaddr let eval_code_eq_ins (i:BS.ins) (f:fuel) (s1 s2:machine_state) : Lemma (requires state_eq_S true s1 s2) (ensures state_eq_opt true (BS.machine_eval_code (Ins i) f s1) (BS.machine_eval_code (Ins i) f s2)) = match i with | Instr _ _ _ -> eval_code_eq_instr i f s1 s2 | Dealloc _ -> eval_code_eq_dealloc i f s1 s2 | Alloc _ -> eval_code_eq_alloc i f s1 s2 | Push _ _ -> eval_code_eq_push i f s1 s2 | Pop _ _ -> eval_code_eq_pop i f s1 s2 #reset-options "--fuel 2 --z3rlimit 30" let eval_ocmp_eq_core (g:bool) (cond:ocmp) (s:machine_state) : Lemma (ensures ( let (s1, b1) = BS.machine_eval_ocmp s cond in let (s2, b2) = BS.machine_eval_ocmp (core_state g s) cond in state_eq_S g s1 s2 /\ b1 == b2 )) = reveal_opaque (`%BS.valid_ocmp_opaque) BS.valid_ocmp_opaque; reveal_opaque (`%BS.eval_ocmp_opaque) BS.eval_ocmp_opaque; () #restart-solver let rec eval_code_eq_core (g:bool) (c:code) (f:fuel) (s:machine_state) : Lemma (ensures state_eq_opt g (BS.machine_eval_code c f s) (BS.machine_eval_code c f (core_state g s))) (decreases %[f; c]) = match c with | Ins i -> reveal_opaque (`%BS.machine_eval_code_ins) BS.machine_eval_code_ins; if g then eval_code_eq_ins i f s (core_state g s) | Block cs -> eval_codes_eq_core g cs f s | IfElse cond ct cf -> eval_ocmp_eq_core g cond s; let (s', _) = BS.machine_eval_ocmp s cond in let (t', _) = BS.machine_eval_ocmp (core_state g s) cond in eval_code_eq_core g ct f s'; eval_code_eq_core g ct f t'; eval_code_eq_core g cf f s'; eval_code_eq_core g cf f t'; () | While cond body -> eval_while_eq_core g cond body f s and eval_codes_eq_core (g:bool) (cs:codes) (f:fuel) (s:machine_state) : Lemma (ensures state_eq_opt g (BS.machine_eval_codes cs f s) (BS.machine_eval_codes cs f (core_state g s))) (decreases %[f; cs]) = match cs with | [] -> () | c'::cs' -> ( eval_code_eq_core g c' f s; match (machine_eval_code c' f s, machine_eval_code c' f (core_state g s)) with | (None, None) -> () | (Some s', Some t') -> eval_codes_eq_core g cs' f s'; eval_codes_eq_core g cs' f t' ) and eval_while_eq_core (g:bool) (cond:ocmp) (body:code) (f:fuel) (s:machine_state) : Lemma (ensures state_eq_opt g (BS.machine_eval_while cond body f s) (BS.machine_eval_while cond body f (core_state g s))) (decreases %[f; body]) = if f > 0 then ( eval_ocmp_eq_core g cond s; let (s1, _) = BS.machine_eval_ocmp s cond in let (t1, _) = BS.machine_eval_ocmp (core_state g s) cond in eval_code_eq_core g body (f - 1) s1; eval_code_eq_core g body (f - 1) t1; match (BS.machine_eval_code body (f - 1) s1, BS.machine_eval_code body (f - 1) t1) with | (None, None) -> () | (Some s2, Some t2) -> eval_while_eq_core g cond body (f - 1) s2; eval_while_eq_core g cond body (f - 1) t2; () ) let eval_code_eq_f (c:code) (f:fuel) (s1 s2:machine_state) : Lemma (requires state_eq_S false s1 s2) (ensures state_eq_opt false (BS.machine_eval_code c f s1) (BS.machine_eval_code c f s2)) [SMTPat (BS.machine_eval_code c f s1); SMTPat (BS.machine_eval_code c f s2)] = eval_code_eq_core false c f s1; eval_code_eq_core false c f s2 let eval_codes_eq_f (cs:codes) (f:fuel) (s1 s2:machine_state) : Lemma (requires state_eq_S false s1 s2) (ensures state_eq_opt false (BS.machine_eval_codes cs f s1) (BS.machine_eval_codes cs f s2)) [SMTPat (BS.machine_eval_codes cs f s1); SMTPat (BS.machine_eval_codes cs f s2)] = eval_codes_eq_core false cs f s1; eval_codes_eq_core false cs f s2 let eval_while_eq_f (cond:ocmp) (body:code) (f:fuel) (s1 s2:machine_state) : Lemma (requires state_eq_S false s1 s2) (ensures state_eq_opt false (BS.machine_eval_while cond body f s1) (BS.machine_eval_while cond body f s2)) [SMTPat (BS.machine_eval_while cond body f s1); SMTPat (BS.machine_eval_while cond body f s2)] = eval_while_eq_core false cond body f s1; eval_while_eq_core false cond body f s2 let eval_code_eq_t (c:code) (f:fuel) (s1 s2:machine_state) : Lemma (requires state_eq_S true s1 s2) (ensures state_eq_opt true (BS.machine_eval_code c f s1) (BS.machine_eval_code c f s2)) [SMTPat (BS.machine_eval_code c f s1); SMTPat (BS.machine_eval_code c f s2)] = eval_code_eq_core true c f s1; eval_code_eq_core true c f s2 let eval_codes_eq_t (cs:codes) (f:fuel) (s1 s2:machine_state) : Lemma (requires state_eq_S true s1 s2) (ensures state_eq_opt true (BS.machine_eval_codes cs f s1) (BS.machine_eval_codes cs f s2)) [SMTPat (BS.machine_eval_codes cs f s1); SMTPat (BS.machine_eval_codes cs f s2)] = eval_codes_eq_core true cs f s1; eval_codes_eq_core true cs f s2 let eval_while_eq_t (cond:ocmp) (body:code) (f:fuel) (s1 s2:machine_state) : Lemma (requires state_eq_S true s1 s2) (ensures state_eq_opt true (BS.machine_eval_while cond body f s1) (BS.machine_eval_while cond body f s2)) [SMTPat (BS.machine_eval_while cond body f s1); SMTPat (BS.machine_eval_while cond body f s2)] = eval_while_eq_core true cond body f s1; eval_while_eq_core true cond body f s2 let eval_code_ts (g:bool) (c:code) (s0:machine_state) (f0:fuel) (s1:machine_state) : Type0 = state_eq_opt g (BS.machine_eval_code c f0 s0) (Some s1) let rec increase_fuel (g:bool) (c:code) (s0:machine_state) (f0:fuel) (sN:machine_state) (fN:fuel) : Lemma (requires eval_code_ts g c s0 f0 sN /\ f0 <= fN) (ensures eval_code_ts g c s0 fN sN) (decreases %[f0; c]) = match c with | Ins ins -> () | Block l -> increase_fuels g l s0 f0 sN fN | IfElse cond t f -> let (s0, b0) = BS.machine_eval_ocmp s0 cond in if b0 then increase_fuel g t s0 f0 sN fN else increase_fuel g f s0 f0 sN fN | While cond c -> let (s1, b0) = BS.machine_eval_ocmp s0 cond in if b0 then ( match BS.machine_eval_code c (f0 - 1) s1 with | None -> () | Some s2 -> increase_fuel g c s1 (f0 - 1) s2 (fN - 1); if s2.BS.ms_ok then increase_fuel g (While cond c) s2 (f0 - 1) sN (fN - 1) else () ) and increase_fuels (g:bool) (c:codes) (s0:machine_state) (f0:fuel) (sN:machine_state) (fN:fuel) : Lemma (requires eval_code_ts g (Block c) s0 f0 sN /\ f0 <= fN) (ensures eval_code_ts g (Block c) s0 fN sN) (decreases %[f0; c]) = match c with | [] -> () | h::t -> ( let Some s1 = BS.machine_eval_code h f0 s0 in increase_fuel g h s0 f0 s1 fN; increase_fuels g t s1 f0 sN fN ) let lemma_cmp_eq s o1 o2 = reveal_opaque (`%BS.eval_ocmp_opaque) BS.eval_ocmp_opaque let lemma_cmp_ne s o1 o2 = reveal_opaque (`%BS.eval_ocmp_opaque) BS.eval_ocmp_opaque let lemma_cmp_le s o1 o2 = reveal_opaque (`%BS.eval_ocmp_opaque) BS.eval_ocmp_opaque let lemma_cmp_ge s o1 o2 = reveal_opaque (`%BS.eval_ocmp_opaque) BS.eval_ocmp_opaque let lemma_cmp_lt s o1 o2 = reveal_opaque (`%BS.eval_ocmp_opaque) BS.eval_ocmp_opaque let lemma_cmp_gt s o1 o2 = reveal_opaque (`%BS.eval_ocmp_opaque) BS.eval_ocmp_opaque let lemma_valid_cmp_eq s o1 o2 = () let lemma_valid_cmp_ne s o1 o2 = () let lemma_valid_cmp_le s o1 o2 = () let lemma_valid_cmp_ge s o1 o2 = () let lemma_valid_cmp_lt s o1 o2 = () let lemma_valid_cmp_gt s o1 o2 = () let compute_merge_total (f0:fuel) (fM:fuel) = if f0 > fM then f0 else fM let lemma_merge_total (b0:codes) (s0:vale_state) (f0:fuel) (sM:vale_state) (fM:fuel) (sN:vale_state) = let f = if f0 > fM then f0 else fM in increase_fuel (codes_modifies_ghost b0) (Cons?.hd b0) (state_to_S s0) f0 (state_to_S sM) f; increase_fuel (codes_modifies_ghost b0) (Block (Cons?.tl b0)) (state_to_S sM) fM (state_to_S sN) f
{ "checked_file": "/", "dependencies": [ "Vale.X64.StateLemmas.fsti.checked", "Vale.X64.State.fsti.checked", "Vale.X64.Memory.fsti.checked", "Vale.X64.Machine_Semantics_s.fst.checked", "Vale.X64.Machine_s.fst.checked", "Vale.X64.Instruction_s.fsti.checked", "Vale.X64.Flags.fsti.checked", "Vale.X64.Bytes_Code_s.fst.checked", "prims.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.FunctionalExtensionality.fsti.checked" ], "interface_file": true, "source_file": "Vale.X64.Lemmas.fst" }
[ { "abbrev": true, "full_module": "Vale.X64.Memory", "short_module": "ME" }, { "abbrev": true, "full_module": "Vale.X64.Machine_Semantics_s", "short_module": "BS" }, { "abbrev": false, "full_module": "Vale.X64.Bytes_Code_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Instruction_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.StateLemmas", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.State", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Machine_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": true, "full_module": "Vale.Lib.Map16", "short_module": "Map16" }, { "abbrev": true, "full_module": "Vale.X64.Machine_Semantics_s", "short_module": "BS" }, { "abbrev": false, "full_module": "Vale.X64.Bytes_Code_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.StateLemmas", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.State", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Machine_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.HeapLemmas", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.HeapImpl", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.Heap", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 0, "max_fuel": 2, "max_ifuel": 1, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": true, "smtencoding_l_arith_repr": "native", "smtencoding_nl_arith_repr": "wrapped", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [ "smt.arith.nl=false", "smt.QI.EAGER_THRESHOLD=100", "smt.CASE_SPLIT=3" ], "z3refresh": false, "z3rlimit": 30, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
s0: Vale.X64.State.vale_state -> bN: Vale.X64.Lemmas.codes -> Prims.Ghost (Vale.X64.State.vale_state * Vale.X64.Lemmas.fuel)
Prims.Ghost
[]
[]
[ "Vale.X64.State.vale_state", "Vale.X64.Lemmas.codes", "FStar.Pervasives.Native.Mktuple2", "Vale.X64.Lemmas.fuel", "FStar.Pervasives.Native.tuple2" ]
[]
false
false
false
false
false
let lemma_empty_total (s0: vale_state) (bN: codes) =
(s0, 0)
false
Hacl.Impl.Ed25519.Ladder.fst
Hacl.Impl.Ed25519.Ladder.point_negate_mul_double_g_vartime
val point_negate_mul_double_g_vartime: out:point -> scalar1:lbuffer uint8 32ul -> scalar2:lbuffer uint8 32ul -> q2:point -> Stack unit (requires fun h -> live h out /\ live h scalar1 /\ live h scalar2 /\ live h q2 /\ disjoint q2 out /\ disjoint scalar1 out /\ disjoint scalar2 out /\ F51.point_inv_t h q2 /\ F51.inv_ext_point (as_seq h q2)) (ensures fun h0 _ h1 -> modifies (loc out) h0 h1 /\ F51.point_inv_t h1 out /\ F51.inv_ext_point (as_seq h1 out) /\ S.to_aff_point (F51.point_eval h1 out) == S.to_aff_point (S.point_negate_mul_double_g (as_seq h0 scalar1) (as_seq h0 scalar2) (F51.point_eval h0 q2)))
val point_negate_mul_double_g_vartime: out:point -> scalar1:lbuffer uint8 32ul -> scalar2:lbuffer uint8 32ul -> q2:point -> Stack unit (requires fun h -> live h out /\ live h scalar1 /\ live h scalar2 /\ live h q2 /\ disjoint q2 out /\ disjoint scalar1 out /\ disjoint scalar2 out /\ F51.point_inv_t h q2 /\ F51.inv_ext_point (as_seq h q2)) (ensures fun h0 _ h1 -> modifies (loc out) h0 h1 /\ F51.point_inv_t h1 out /\ F51.inv_ext_point (as_seq h1 out) /\ S.to_aff_point (F51.point_eval h1 out) == S.to_aff_point (S.point_negate_mul_double_g (as_seq h0 scalar1) (as_seq h0 scalar2) (F51.point_eval h0 q2)))
let point_negate_mul_double_g_vartime out scalar1 scalar2 q2 = push_frame (); let q2_neg = create 20ul (u64 0) in let h0 = ST.get () in Spec.Ed25519.Lemmas.to_aff_point_negate (F51.refl_ext_point (as_seq h0 q2)); Hacl.Impl.Ed25519.PointNegate.point_negate q2 q2_neg; let h1 = ST.get () in point_mul_g_double_vartime out scalar1 scalar2 q2_neg; SE.exp_double_fw_lemma S.mk_ed25519_concrete_ops g_c 256 (BSeq.nat_from_bytes_le (as_seq h1 scalar1)) (F51.point_eval h1 q2_neg) (BSeq.nat_from_bytes_le (as_seq h1 scalar2)) 5; pop_frame ()
{ "file_name": "code/ed25519/Hacl.Impl.Ed25519.Ladder.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 14, "end_line": 419, "start_col": 0, "start_line": 408 }
module Hacl.Impl.Ed25519.Ladder module ST = FStar.HyperStack.ST open FStar.HyperStack.All open FStar.Mul open Lib.IntTypes open Lib.Buffer open Hacl.Bignum25519 module F51 = Hacl.Impl.Ed25519.Field51 module BSeq = Lib.ByteSequence module LE = Lib.Exponentiation module SE = Spec.Exponentiation module BE = Hacl.Impl.Exponentiation module ME = Hacl.Impl.MultiExponentiation module PT = Hacl.Impl.PrecompTable module SPT256 = Hacl.Spec.PrecompBaseTable256 module BD = Hacl.Bignum.Definitions module SD = Hacl.Spec.Bignum.Definitions module S = Spec.Ed25519 open Hacl.Impl.Ed25519.PointConstants include Hacl.Impl.Ed25519.Group include Hacl.Ed25519.PrecompTable #set-options "--z3rlimit 50 --fuel 0 --ifuel 0" inline_for_extraction noextract let table_inv_w4 : BE.table_inv_t U64 20ul 16ul = [@inline_let] let len = 20ul in [@inline_let] let ctx_len = 0ul in [@inline_let] let k = mk_ed25519_concrete_ops in [@inline_let] let l = 4ul in [@inline_let] let table_len = 16ul in BE.table_inv_precomp len ctx_len k l table_len inline_for_extraction noextract let table_inv_w5 : BE.table_inv_t U64 20ul 32ul = [@inline_let] let len = 20ul in [@inline_let] let ctx_len = 0ul in [@inline_let] let k = mk_ed25519_concrete_ops in [@inline_let] let l = 5ul in [@inline_let] let table_len = 32ul in assert_norm (pow2 (v l) = v table_len); BE.table_inv_precomp len ctx_len k l table_len inline_for_extraction noextract val convert_scalar: scalar:lbuffer uint8 32ul -> bscalar:lbuffer uint64 4ul -> Stack unit (requires fun h -> live h scalar /\ live h bscalar /\ disjoint scalar bscalar) (ensures fun h0 _ h1 -> modifies (loc bscalar) h0 h1 /\ BD.bn_v h1 bscalar == BSeq.nat_from_bytes_le (as_seq h0 scalar)) let convert_scalar scalar bscalar = let h0 = ST.get () in Hacl.Spec.Bignum.Convert.bn_from_bytes_le_lemma #U64 32 (as_seq h0 scalar); Hacl.Bignum.Convert.mk_bn_from_bytes_le true 32ul scalar bscalar inline_for_extraction noextract val point_mul_noalloc: out:point -> bscalar:lbuffer uint64 4ul -> q:point -> Stack unit (requires fun h -> live h bscalar /\ live h q /\ live h out /\ disjoint q out /\ disjoint q bscalar /\ disjoint out bscalar /\ F51.point_inv_t h q /\ F51.inv_ext_point (as_seq h q) /\ BD.bn_v h bscalar < pow2 256) (ensures fun h0 _ h1 -> modifies (loc out) h0 h1 /\ F51.point_inv_t h1 out /\ F51.inv_ext_point (as_seq h1 out) /\ S.to_aff_point (F51.point_eval h1 out) == LE.exp_fw S.mk_ed25519_comm_monoid (S.to_aff_point (F51.point_eval h0 q)) 256 (BD.bn_v h0 bscalar) 4) let point_mul_noalloc out bscalar q = BE.lexp_fw_consttime 20ul 0ul mk_ed25519_concrete_ops 4ul (null uint64) q 4ul 256ul bscalar out let point_mul out scalar q = let h0 = ST.get () in SE.exp_fw_lemma S.mk_ed25519_concrete_ops (F51.point_eval h0 q) 256 (BSeq.nat_from_bytes_le (as_seq h0 scalar)) 4; push_frame (); let bscalar = create 4ul (u64 0) in convert_scalar scalar bscalar; point_mul_noalloc out bscalar q; pop_frame () val precomp_get_consttime: BE.pow_a_to_small_b_st U64 20ul 0ul mk_ed25519_concrete_ops 4ul 16ul (BE.table_inv_precomp 20ul 0ul mk_ed25519_concrete_ops 4ul 16ul) [@CInline] let precomp_get_consttime ctx a table bits_l tmp = [@inline_let] let len = 20ul in [@inline_let] let ctx_len = 0ul in [@inline_let] let k = mk_ed25519_concrete_ops in [@inline_let] let l = 4ul in [@inline_let] let table_len = 16ul in BE.lprecomp_get_consttime len ctx_len k l table_len ctx a table bits_l tmp inline_for_extraction noextract val point_mul_g_noalloc: out:point -> bscalar:lbuffer uint64 4ul -> q1:point -> q2:point -> q3:point -> q4:point -> Stack unit (requires fun h -> live h bscalar /\ live h out /\ live h q1 /\ live h q2 /\ live h q3 /\ live h q4 /\ disjoint out bscalar /\ disjoint out q1 /\ disjoint out q2 /\ disjoint out q3 /\ disjoint out q4 /\ disjoint q1 q2 /\ disjoint q1 q3 /\ disjoint q1 q4 /\ disjoint q2 q3 /\ disjoint q2 q4 /\ disjoint q3 q4 /\ BD.bn_v h bscalar < pow2 256 /\ F51.linv (as_seq h q1) /\ refl (as_seq h q1) == g_aff /\ F51.linv (as_seq h q2) /\ refl (as_seq h q2) == g_pow2_64 /\ F51.linv (as_seq h q3) /\ refl (as_seq h q3) == g_pow2_128 /\ F51.linv (as_seq h q4) /\ refl (as_seq h q4) == g_pow2_192) (ensures fun h0 _ h1 -> modifies (loc out) h0 h1 /\ F51.linv (as_seq h1 out) /\ (let (b0, b1, b2, b3) = SPT256.decompose_nat256_as_four_u64 (BD.bn_v h0 bscalar) in S.to_aff_point (F51.point_eval h1 out) == LE.exp_four_fw S.mk_ed25519_comm_monoid g_aff 64 b0 g_pow2_64 b1 g_pow2_128 b2 g_pow2_192 b3 4)) let point_mul_g_noalloc out bscalar q1 q2 q3 q4 = [@inline_let] let len = 20ul in [@inline_let] let ctx_len = 0ul in [@inline_let] let k = mk_ed25519_concrete_ops in [@inline_let] let l = 4ul in [@inline_let] let table_len = 16ul in [@inline_let] let bLen = 1ul in [@inline_let] let bBits = 64ul in let h0 = ST.get () in recall_contents precomp_basepoint_table_w4 precomp_basepoint_table_lseq_w4; let h1 = ST.get () in precomp_basepoint_table_lemma_w4 (); assert (table_inv_w4 (as_seq h1 q1) (as_seq h1 precomp_basepoint_table_w4)); recall_contents precomp_g_pow2_64_table_w4 precomp_g_pow2_64_table_lseq_w4; let h1 = ST.get () in precomp_g_pow2_64_table_lemma_w4 (); assert (table_inv_w4 (as_seq h1 q2) (as_seq h1 precomp_g_pow2_64_table_w4)); recall_contents precomp_g_pow2_128_table_w4 precomp_g_pow2_128_table_lseq_w4; let h1 = ST.get () in precomp_g_pow2_128_table_lemma_w4 (); assert (table_inv_w4 (as_seq h1 q3) (as_seq h1 precomp_g_pow2_128_table_w4)); recall_contents precomp_g_pow2_192_table_w4 precomp_g_pow2_192_table_lseq_w4; let h1 = ST.get () in precomp_g_pow2_192_table_lemma_w4 (); assert (table_inv_w4 (as_seq h1 q4) (as_seq h1 precomp_g_pow2_192_table_w4)); let r1 = sub bscalar 0ul 1ul in let r2 = sub bscalar 1ul 1ul in let r3 = sub bscalar 2ul 1ul in let r4 = sub bscalar 3ul 1ul in SPT256.lemma_decompose_nat256_as_four_u64_lbignum (as_seq h0 bscalar); ME.mk_lexp_four_fw_tables len ctx_len k l table_len table_inv_w4 table_inv_w4 table_inv_w4 table_inv_w4 precomp_get_consttime precomp_get_consttime precomp_get_consttime precomp_get_consttime (null uint64) q1 bLen bBits r1 q2 r2 q3 r3 q4 r4 (to_const precomp_basepoint_table_w4) (to_const precomp_g_pow2_64_table_w4) (to_const precomp_g_pow2_128_table_w4) (to_const precomp_g_pow2_192_table_w4) out; LowStar.Ignore.ignore q2; // q2, q3, q4 are unused variables LowStar.Ignore.ignore q3; LowStar.Ignore.ignore q4 inline_for_extraction noextract val point_mul_g_mk_q1234: out:point -> bscalar:lbuffer uint64 4ul -> q1:point -> Stack unit (requires fun h -> live h bscalar /\ live h out /\ live h q1 /\ disjoint out bscalar /\ disjoint out q1 /\ BD.bn_v h bscalar < pow2 256 /\ F51.linv (as_seq h q1) /\ refl (as_seq h q1) == g_aff) (ensures fun h0 _ h1 -> modifies (loc out) h0 h1 /\ F51.linv (as_seq h1 out) /\ (let (b0, b1, b2, b3) = SPT256.decompose_nat256_as_four_u64 (BD.bn_v h0 bscalar) in S.to_aff_point (F51.point_eval h1 out) == LE.exp_four_fw S.mk_ed25519_comm_monoid g_aff 64 b0 g_pow2_64 b1 g_pow2_128 b2 g_pow2_192 b3 4)) let point_mul_g_mk_q1234 out bscalar q1 = push_frame (); let q2 = mk_ext_g_pow2_64 () in let q3 = mk_ext_g_pow2_128 () in let q4 = mk_ext_g_pow2_192 () in ext_g_pow2_64_lseq_lemma (); ext_g_pow2_128_lseq_lemma (); ext_g_pow2_192_lseq_lemma (); point_mul_g_noalloc out bscalar q1 q2 q3 q4; pop_frame () val lemma_exp_four_fw_local: b:BSeq.lbytes 32 -> Lemma (let bn = BSeq.nat_from_bytes_le b in let (b0, b1, b2, b3) = SPT256.decompose_nat256_as_four_u64 bn in let cm = S.mk_ed25519_comm_monoid in LE.exp_four_fw cm g_aff 64 b0 g_pow2_64 b1 g_pow2_128 b2 g_pow2_192 b3 4 == S.to_aff_point (S.point_mul_g b)) let lemma_exp_four_fw_local b = let bn = BSeq.nat_from_bytes_le b in let (b0, b1, b2, b3) = SPT256.decompose_nat256_as_four_u64 bn in let cm = S.mk_ed25519_comm_monoid in let res = LE.exp_four_fw cm g_aff 64 b0 g_pow2_64 b1 g_pow2_128 b2 g_pow2_192 b3 4 in assert (res == SPT256.exp_as_exp_four_nat256_precomp cm g_aff bn); SPT256.lemma_point_mul_base_precomp4 cm g_aff bn; assert (res == LE.pow cm g_aff bn); SE.exp_fw_lemma S.mk_ed25519_concrete_ops g_c 256 bn 4; LE.exp_fw_lemma cm g_aff 256 bn 4; assert (S.to_aff_point (S.point_mul_g b) == LE.pow cm g_aff bn) [@CInline] let point_mul_g out scalar = push_frame (); let h0 = ST.get () in let bscalar = create 4ul (u64 0) in convert_scalar scalar bscalar; let q1 = create 20ul (u64 0) in make_g q1; point_mul_g_mk_q1234 out bscalar q1; lemma_exp_four_fw_local (as_seq h0 scalar); pop_frame () inline_for_extraction noextract val point_mul_g_double_vartime_noalloc: out:point -> scalar1:lbuffer uint64 4ul -> q1:point -> scalar2:lbuffer uint64 4ul -> q2:point -> table2: lbuffer uint64 640ul -> Stack unit (requires fun h -> live h out /\ live h scalar1 /\ live h q1 /\ live h scalar2 /\ live h q2 /\ live h table2 /\ eq_or_disjoint q1 q2 /\ disjoint out q1 /\ disjoint out q2 /\ disjoint out scalar1 /\ disjoint out scalar2 /\ disjoint out table2 /\ BD.bn_v h scalar1 < pow2 256 /\ BD.bn_v h scalar2 < pow2 256 /\ F51.linv (as_seq h q1) /\ F51.linv (as_seq h q2) /\ F51.point_eval h q1 == g_c /\ table_inv_w5 (as_seq h q2) (as_seq h table2)) (ensures fun h0 _ h1 -> modifies (loc out) h0 h1 /\ F51.linv (as_seq h1 out) /\ S.to_aff_point (F51.point_eval h1 out) == LE.exp_double_fw #S.aff_point_c S.mk_ed25519_comm_monoid (S.to_aff_point (F51.point_eval h0 q1)) 256 (BD.bn_v h0 scalar1) (S.to_aff_point (F51.point_eval h0 q2)) (BD.bn_v h0 scalar2) 5) let point_mul_g_double_vartime_noalloc out scalar1 q1 scalar2 q2 table2 = [@inline_let] let len = 20ul in [@inline_let] let ctx_len = 0ul in [@inline_let] let k = mk_ed25519_concrete_ops in [@inline_let] let l = 5ul in [@inline_let] let table_len = 32ul in [@inline_let] let bLen = 4ul in [@inline_let] let bBits = 256ul in assert_norm (pow2 (v l) == v table_len); let h0 = ST.get () in recall_contents precomp_basepoint_table_w5 precomp_basepoint_table_lseq_w5; let h1 = ST.get () in precomp_basepoint_table_lemma_w5 (); assert (table_inv_w5 (as_seq h1 q1) (as_seq h1 precomp_basepoint_table_w5)); assert (table_inv_w5 (as_seq h1 q2) (as_seq h1 table2)); ME.mk_lexp_double_fw_tables len ctx_len k l table_len table_inv_w5 table_inv_w5 (BE.lprecomp_get_vartime len ctx_len k l table_len) (BE.lprecomp_get_vartime len ctx_len k l table_len) (null uint64) q1 bLen bBits scalar1 q2 scalar2 (to_const precomp_basepoint_table_w5) (to_const table2) out inline_for_extraction noextract val point_mul_g_double_vartime_table: out:point -> scalar1:lbuffer uint64 4ul -> q1:point -> scalar2:lbuffer uint64 4ul -> q2:point -> Stack unit (requires fun h -> live h out /\ live h scalar1 /\ live h q1 /\ live h scalar2 /\ live h q2 /\ eq_or_disjoint q1 q2 /\ disjoint out q1 /\ disjoint out q2 /\ disjoint out scalar1 /\ disjoint out scalar2 /\ BD.bn_v h scalar1 < pow2 256 /\ BD.bn_v h scalar2 < pow2 256 /\ F51.linv (as_seq h q1) /\ F51.linv (as_seq h q2) /\ F51.point_eval h q1 == g_c) (ensures fun h0 _ h1 -> modifies (loc out) h0 h1 /\ F51.linv (as_seq h1 out) /\ S.to_aff_point (F51.point_eval h1 out) == LE.exp_double_fw #S.aff_point_c S.mk_ed25519_comm_monoid (S.to_aff_point (F51.point_eval h0 q1)) 256 (BD.bn_v h0 scalar1) (S.to_aff_point (F51.point_eval h0 q2)) (BD.bn_v h0 scalar2) 5) let point_mul_g_double_vartime_table out scalar1 q1 scalar2 q2 = [@inline_let] let len = 20ul in [@inline_let] let ctx_len = 0ul in [@inline_let] let k = mk_ed25519_concrete_ops in [@inline_let] let table_len = 32ul in assert_norm (pow2 5 == v table_len); push_frame (); let table2 = create (table_len *! len) (u64 0) in PT.lprecomp_table len ctx_len k (null uint64) q2 table_len table2; point_mul_g_double_vartime_noalloc out scalar1 q1 scalar2 q2 table2; pop_frame () inline_for_extraction noextract val point_mul_g_double_vartime_aux: out:point -> scalar1:lbuffer uint8 32ul -> q1:point -> scalar2:lbuffer uint8 32ul -> q2:point -> bscalar1:lbuffer uint64 4ul -> bscalar2:lbuffer uint64 4ul -> Stack unit (requires fun h -> live h out /\ live h scalar1 /\ live h q1 /\ live h scalar2 /\ live h q2 /\ live h bscalar1 /\ live h bscalar2 /\ disjoint scalar1 bscalar1 /\ disjoint scalar2 bscalar2 /\ disjoint scalar2 bscalar1 /\ disjoint scalar1 bscalar2 /\ disjoint bscalar1 bscalar2 /\ disjoint bscalar1 out /\ disjoint bscalar1 q1 /\ disjoint bscalar1 q2 /\ disjoint bscalar2 out /\ disjoint bscalar2 q1 /\ disjoint bscalar2 q2 /\ eq_or_disjoint q1 q2 /\ disjoint q1 out /\ disjoint q2 out /\ disjoint scalar1 out /\ disjoint scalar2 out /\ F51.linv (as_seq h q1) /\ F51.linv (as_seq h q2) /\ F51.point_eval h q1 == g_c) (ensures fun h0 _ h1 -> modifies (loc out |+| loc bscalar1 |+| loc bscalar2) h0 h1 /\ F51.linv (as_seq h1 out) /\ BD.bn_v h1 bscalar1 == BSeq.nat_from_bytes_le (as_seq h0 scalar1) /\ BD.bn_v h1 bscalar2 == BSeq.nat_from_bytes_le (as_seq h0 scalar2) /\ S.to_aff_point (F51.point_eval h1 out) == LE.exp_double_fw #S.aff_point_c S.mk_ed25519_comm_monoid (S.to_aff_point (F51.point_eval h0 q1)) 256 (BD.bn_v h1 bscalar1) (S.to_aff_point (F51.point_eval h0 q2)) (BD.bn_v h1 bscalar2) 5) let point_mul_g_double_vartime_aux out scalar1 q1 scalar2 q2 bscalar1 bscalar2 = let h0 = ST.get () in convert_scalar scalar1 bscalar1; convert_scalar scalar2 bscalar2; let h1 = ST.get () in assert (BD.bn_v h1 bscalar1 == BSeq.nat_from_bytes_le (as_seq h0 scalar1)); assert (BD.bn_v h1 bscalar2 == BSeq.nat_from_bytes_le (as_seq h0 scalar2)); point_mul_g_double_vartime_table out bscalar1 q1 bscalar2 q2 val point_mul_g_double_vartime: out:point -> scalar1:lbuffer uint8 32ul -> scalar2:lbuffer uint8 32ul -> q2:point -> Stack unit (requires fun h -> live h out /\ live h scalar1 /\ live h scalar2 /\ live h q2 /\ disjoint q2 out /\ disjoint scalar1 out /\ disjoint scalar2 out /\ F51.linv (as_seq h q2)) (ensures fun h0 _ h1 -> modifies (loc out) h0 h1 /\ F51.linv (as_seq h1 out) /\ S.to_aff_point (F51.point_eval h1 out) == LE.exp_double_fw #S.aff_point_c S.mk_ed25519_comm_monoid (S.to_aff_point g_c) 256 (BSeq.nat_from_bytes_le (as_seq h0 scalar1)) (S.to_aff_point (F51.point_eval h0 q2)) (BSeq.nat_from_bytes_le (as_seq h0 scalar2)) 5) [@CInline] let point_mul_g_double_vartime out scalar1 scalar2 q2 = push_frame (); let tmp = create 28ul (u64 0) in let g = sub tmp 0ul 20ul in let bscalar1 = sub tmp 20ul 4ul in let bscalar2 = sub tmp 24ul 4ul in make_g g; point_mul_g_double_vartime_aux out scalar1 g scalar2 q2 bscalar1 bscalar2; pop_frame ()
{ "checked_file": "/", "dependencies": [ "Spec.Exponentiation.fsti.checked", "Spec.Ed25519.Lemmas.fsti.checked", "Spec.Ed25519.fst.checked", "prims.fst.checked", "LowStar.Ignore.fsti.checked", "Lib.IntTypes.fsti.checked", "Lib.Exponentiation.fsti.checked", "Lib.ByteSequence.fsti.checked", "Lib.Buffer.fsti.checked", "Hacl.Spec.PrecompBaseTable256.fsti.checked", "Hacl.Spec.Bignum.Definitions.fst.checked", "Hacl.Spec.Bignum.Convert.fst.checked", "Hacl.Impl.PrecompTable.fsti.checked", "Hacl.Impl.MultiExponentiation.fsti.checked", "Hacl.Impl.Exponentiation.fsti.checked", "Hacl.Impl.Ed25519.PointNegate.fst.checked", "Hacl.Impl.Ed25519.PointConstants.fst.checked", "Hacl.Impl.Ed25519.Group.fst.checked", "Hacl.Impl.Ed25519.Field51.fst.checked", "Hacl.Ed25519.PrecompTable.fsti.checked", "Hacl.Bignum25519.fsti.checked", "Hacl.Bignum.Definitions.fst.checked", "Hacl.Bignum.Convert.fst.checked", "FStar.UInt32.fsti.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.All.fst.checked" ], "interface_file": true, "source_file": "Hacl.Impl.Ed25519.Ladder.fst" }
[ { "abbrev": false, "full_module": "Hacl.Ed25519.PrecompTable", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Impl.Ed25519.Group", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Impl.Ed25519.PointConstants", "short_module": null }, { "abbrev": true, "full_module": "Spec.Ed25519", "short_module": "S" }, { "abbrev": true, "full_module": "Hacl.Spec.Bignum.Definitions", "short_module": "SD" }, { "abbrev": true, "full_module": "Hacl.Bignum.Definitions", "short_module": "BD" }, { "abbrev": true, "full_module": "Hacl.Spec.PrecompBaseTable256", "short_module": "SPT256" }, { "abbrev": true, "full_module": "Hacl.Impl.PrecompTable", "short_module": "PT" }, { "abbrev": true, "full_module": "Hacl.Impl.MultiExponentiation", "short_module": "ME" }, { "abbrev": true, "full_module": "Hacl.Impl.Exponentiation", "short_module": "BE" }, { "abbrev": true, "full_module": "Spec.Exponentiation", "short_module": "SE" }, { "abbrev": true, "full_module": "Lib.Exponentiation", "short_module": "LE" }, { "abbrev": true, "full_module": "Lib.ByteSequence", "short_module": "BSeq" }, { "abbrev": true, "full_module": "Hacl.Impl.Ed25519.Field51", "short_module": "F51" }, { "abbrev": false, "full_module": "Hacl.Bignum25519", "short_module": null }, { "abbrev": false, "full_module": "Lib.Buffer", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.All", "short_module": null }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": true, "full_module": "Spec.Ed25519", "short_module": "S" }, { "abbrev": true, "full_module": "Hacl.Impl.Ed25519.Field51", "short_module": "F51" }, { "abbrev": true, "full_module": "Lib.ByteSequence", "short_module": "BSeq" }, { "abbrev": false, "full_module": "Hacl.Bignum25519", "short_module": null }, { "abbrev": false, "full_module": "Lib.Buffer", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.All", "short_module": null }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": false, "full_module": "Hacl.Impl.Ed25519", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Impl.Ed25519", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": 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
out: Hacl.Bignum25519.point -> scalar1: Lib.Buffer.lbuffer Lib.IntTypes.uint8 32ul -> scalar2: Lib.Buffer.lbuffer Lib.IntTypes.uint8 32ul -> q2: Hacl.Bignum25519.point -> FStar.HyperStack.ST.Stack Prims.unit
FStar.HyperStack.ST.Stack
[]
[]
[ "Hacl.Bignum25519.point", "Lib.Buffer.lbuffer", "Lib.IntTypes.uint8", "FStar.UInt32.__uint_to_t", "FStar.HyperStack.ST.pop_frame", "Prims.unit", "Spec.Exponentiation.exp_double_fw_lemma", "Spec.Ed25519.ext_point_c", "Spec.Ed25519.mk_ed25519_concrete_ops", "Hacl.Ed25519.PrecompTable.g_c", "Lib.ByteSequence.nat_from_bytes_le", "Lib.IntTypes.SEC", "Lib.Buffer.as_seq", "Lib.Buffer.MUT", "Hacl.Impl.Ed25519.Field51.point_eval", "Hacl.Impl.Ed25519.Ladder.point_mul_g_double_vartime", "FStar.Monotonic.HyperStack.mem", "FStar.HyperStack.ST.get", "Hacl.Impl.Ed25519.PointNegate.point_negate", "Spec.Ed25519.Lemmas.to_aff_point_negate", "Hacl.Impl.Ed25519.Field51.refl_ext_point", "Lib.IntTypes.uint64", "Lib.Buffer.lbuffer_t", "Lib.IntTypes.int_t", "Lib.IntTypes.U64", "FStar.UInt32.uint_to_t", "FStar.UInt32.t", "Lib.Buffer.create", "Lib.IntTypes.u64", "FStar.HyperStack.ST.push_frame" ]
[]
false
true
false
false
false
let point_negate_mul_double_g_vartime out scalar1 scalar2 q2 =
push_frame (); let q2_neg = create 20ul (u64 0) in let h0 = ST.get () in Spec.Ed25519.Lemmas.to_aff_point_negate (F51.refl_ext_point (as_seq h0 q2)); Hacl.Impl.Ed25519.PointNegate.point_negate q2 q2_neg; let h1 = ST.get () in point_mul_g_double_vartime out scalar1 scalar2 q2_neg; SE.exp_double_fw_lemma S.mk_ed25519_concrete_ops g_c 256 (BSeq.nat_from_bytes_le (as_seq h1 scalar1)) (F51.point_eval h1 q2_neg) (BSeq.nat_from_bytes_le (as_seq h1 scalar2)) 5; pop_frame ()
false
Vale.X64.Lemmas.fst
Vale.X64.Lemmas.lemma_ifElse_total
val lemma_ifElse_total (ifb:ocmp) (ct:code) (cf:code) (s0:vale_state) : Ghost (bool & vale_state & vale_state & fuel) (requires True) (ensures (fun (cond, sM, sN, f0) -> cond == eval_ocmp s0 ifb /\ sM == {s0 with vs_flags = havoc_flags} ))
val lemma_ifElse_total (ifb:ocmp) (ct:code) (cf:code) (s0:vale_state) : Ghost (bool & vale_state & vale_state & fuel) (requires True) (ensures (fun (cond, sM, sN, f0) -> cond == eval_ocmp s0 ifb /\ sM == {s0 with vs_flags = havoc_flags} ))
let lemma_ifElse_total (ifb:ocmp) (ct:code) (cf:code) (s0:vale_state) = (eval_ocmp s0 ifb, {s0 with vs_flags = havoc_flags}, s0, 0)
{ "file_name": "vale/code/arch/x64/Vale.X64.Lemmas.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 61, "end_line": 359, "start_col": 0, "start_line": 358 }
module Vale.X64.Lemmas open FStar.Mul open Vale.X64.Machine_s open Vale.X64.State open Vale.X64.StateLemmas open Vale.X64.Instruction_s open Vale.X64.Bytes_Code_s module BS = Vale.X64.Machine_Semantics_s module ME = Vale.X64.Memory #reset-options "--initial_fuel 1 --max_fuel 1 --z3rlimit 100" #restart-solver let rec lemma_eq_instr_apply_eval_args (outs:list instr_out) (args:list instr_operand) (f:instr_args_t outs args) (oprs:instr_operands_t_args args) (s1 s2:machine_state) : Lemma (requires state_eq_S true s1 s2) (ensures BS.instr_apply_eval_args outs args f oprs s1 == BS.instr_apply_eval_args outs args f oprs s2) = let open BS in lemma_heap_ignore_ghost_machine s1.BS.ms_heap s2.BS.ms_heap; match args with | [] -> () | i::args -> ( let (v, oprs) : option (instr_val_t i) & instr_operands_t_args args = match i with | IOpEx i -> let oprs = coerce oprs in (instr_eval_operand_explicit i (fst oprs) s1, snd oprs) | IOpIm i -> (instr_eval_operand_implicit i s1, coerce oprs) in let f:arrow (instr_val_t i) (instr_args_t outs args) = coerce f in match v with | None -> () | Some v -> lemma_eq_instr_apply_eval_args outs args (f v) oprs s1 s2 ) #restart-solver let rec lemma_eq_instr_apply_eval_inouts (outs inouts:list instr_out) (args:list instr_operand) (f:instr_inouts_t outs inouts args) (oprs:instr_operands_t inouts args) (s1 s2:machine_state) : Lemma (requires state_eq_S true s1 s2) (ensures BS.instr_apply_eval_inouts outs inouts args f oprs s1 == BS.instr_apply_eval_inouts outs inouts args f oprs s2) = let open BS in lemma_heap_ignore_ghost_machine s1.BS.ms_heap s2.BS.ms_heap; match inouts with | [] -> lemma_eq_instr_apply_eval_args outs args f oprs s1 s2 | (Out, i)::inouts -> let oprs = match i with | IOpEx i -> snd #(instr_operand_t i) (coerce oprs) | IOpIm i -> coerce oprs in lemma_eq_instr_apply_eval_inouts outs inouts args (coerce f) oprs s1 s2 | (InOut, i)::inouts -> ( let (v, oprs) : option (instr_val_t i) & instr_operands_t inouts args = match i with | IOpEx i -> let oprs = coerce oprs in (instr_eval_operand_explicit i (fst oprs) s1, snd oprs) | IOpIm i -> (instr_eval_operand_implicit i s1, coerce oprs) in let f:arrow (instr_val_t i) (instr_inouts_t outs inouts args) = coerce f in match v with | None -> () | Some v -> lemma_eq_instr_apply_eval_inouts outs inouts args (f v) oprs s1 s2 ) #restart-solver #push-options "--z3rlimit_factor 2" let rec lemma_eq_instr_write_outputs (outs:list instr_out) (args:list instr_operand) (vs:instr_ret_t outs) (oprs:instr_operands_t outs args) (s1_orig s1 s2_orig s2:machine_state) : Lemma (requires state_eq_S true s1_orig s2_orig /\ state_eq_S true s1 s2) (ensures state_eq_S true (BS.instr_write_outputs outs args vs oprs s1_orig s1) (BS.instr_write_outputs outs args vs oprs s2_orig s2)) = let open BS in use_machine_state_equal (); lemma_heap_ignore_ghost_machine s1.BS.ms_heap s2.BS.ms_heap; lemma_heap_ignore_ghost_machine s1_orig.BS.ms_heap s2_orig.BS.ms_heap; allow_inversion tmaddr; match outs with | [] -> () | (_, i)::outs -> ( let ((v:instr_val_t i), (vs:instr_ret_t outs)) = match outs with | [] -> (vs, ()) | _::_ -> let vs = coerce vs in (fst vs, snd vs) in match i with | IOpEx i -> let oprs = coerce oprs in let s1 = instr_write_output_explicit i v (fst oprs) s1_orig s1 in let s2 = instr_write_output_explicit i v (fst oprs) s2_orig s2 in lemma_eq_instr_write_outputs outs args vs (snd oprs) s1_orig s1 s2_orig s2 | IOpIm i -> let s1 = instr_write_output_implicit i v s1_orig s1 in let s2 = instr_write_output_implicit i v s2_orig s2 in allow_inversion operand64; allow_inversion operand128; lemma_eq_instr_write_outputs outs args vs (coerce oprs) s1_orig s1 s2_orig s2 ) #pop-options #restart-solver let eval_ins_eq_instr (inst:BS.ins) (s1 s2:machine_state) : Lemma (requires Instr? inst /\ state_eq_S true s1 s2) (ensures state_eq_S true (BS.machine_eval_ins inst s1) (BS.machine_eval_ins inst s2)) = let open BS in let Instr it oprs ann = inst in let InstrTypeRecord #outs #args #havoc_flags' i = it in lemma_eq_instr_apply_eval_inouts outs outs args (instr_eval i) oprs s1 s2; let vs = instr_apply_eval outs args (instr_eval i) oprs s1 in let hav s = match havoc_flags' with | HavocFlags -> {s with ms_flags = havoc_flags} | PreserveFlags -> s in let s1' = hav s1 in let s2' = hav s2 in match vs with | None -> () | Some vs -> lemma_eq_instr_write_outputs outs args vs oprs s1 s1' s2 s2' let eval_code_eq_instr (inst:BS.ins) (f:fuel) (s1 s2:machine_state) : Lemma (requires Instr? inst /\ state_eq_S true s1 s2) (ensures state_eq_opt true (BS.machine_eval_code (Ins inst) f s1) (BS.machine_eval_code (Ins inst) f s2)) = reveal_opaque (`%BS.machine_eval_code_ins) BS.machine_eval_code_ins; eval_ins_eq_instr inst ({s1 with BS.ms_trace = []}) ({s2 with BS.ms_trace = []}) let eval_code_eq_dealloc (inst:BS.ins) (f:fuel) (s1 s2:machine_state) : Lemma (requires Dealloc? inst /\ state_eq_S true s1 s2) (ensures state_eq_opt true (BS.machine_eval_code (Ins inst) f s1) (BS.machine_eval_code (Ins inst) f s2)) = reveal_opaque (`%BS.machine_eval_code_ins) BS.machine_eval_code_ins; use_machine_state_equal (); lemma_heap_ignore_ghost_machine s1.BS.ms_heap s2.BS.ms_heap; allow_inversion tmaddr let eval_code_eq_alloc (inst:BS.ins) (f:fuel) (s1 s2:machine_state) : Lemma (requires Alloc? inst /\ state_eq_S true s1 s2) (ensures state_eq_opt true (BS.machine_eval_code (Ins inst) f s1) (BS.machine_eval_code (Ins inst) f s2)) = reveal_opaque (`%BS.machine_eval_code_ins) BS.machine_eval_code_ins; use_machine_state_equal (); lemma_heap_ignore_ghost_machine s1.BS.ms_heap s2.BS.ms_heap; allow_inversion tmaddr let eval_code_eq_push (inst:BS.ins) (f:fuel) (s1 s2:machine_state) : Lemma (requires Push? inst /\ state_eq_S true s1 s2) (ensures state_eq_opt true (BS.machine_eval_code (Ins inst) f s1) (BS.machine_eval_code (Ins inst) f s2)) = reveal_opaque (`%BS.machine_eval_code_ins) BS.machine_eval_code_ins; use_machine_state_equal (); lemma_heap_ignore_ghost_machine s1.BS.ms_heap s2.BS.ms_heap; allow_inversion tmaddr let eval_code_eq_pop (inst:BS.ins) (f:fuel) (s1 s2:machine_state) : Lemma (requires Pop? inst /\ state_eq_S true s1 s2) (ensures state_eq_opt true (BS.machine_eval_code (Ins inst) f s1) (BS.machine_eval_code (Ins inst) f s2)) = reveal_opaque (`%BS.machine_eval_code_ins) BS.machine_eval_code_ins; use_machine_state_equal (); lemma_heap_ignore_ghost_machine s1.BS.ms_heap s2.BS.ms_heap; allow_inversion tmaddr let eval_code_eq_ins (i:BS.ins) (f:fuel) (s1 s2:machine_state) : Lemma (requires state_eq_S true s1 s2) (ensures state_eq_opt true (BS.machine_eval_code (Ins i) f s1) (BS.machine_eval_code (Ins i) f s2)) = match i with | Instr _ _ _ -> eval_code_eq_instr i f s1 s2 | Dealloc _ -> eval_code_eq_dealloc i f s1 s2 | Alloc _ -> eval_code_eq_alloc i f s1 s2 | Push _ _ -> eval_code_eq_push i f s1 s2 | Pop _ _ -> eval_code_eq_pop i f s1 s2 #reset-options "--fuel 2 --z3rlimit 30" let eval_ocmp_eq_core (g:bool) (cond:ocmp) (s:machine_state) : Lemma (ensures ( let (s1, b1) = BS.machine_eval_ocmp s cond in let (s2, b2) = BS.machine_eval_ocmp (core_state g s) cond in state_eq_S g s1 s2 /\ b1 == b2 )) = reveal_opaque (`%BS.valid_ocmp_opaque) BS.valid_ocmp_opaque; reveal_opaque (`%BS.eval_ocmp_opaque) BS.eval_ocmp_opaque; () #restart-solver let rec eval_code_eq_core (g:bool) (c:code) (f:fuel) (s:machine_state) : Lemma (ensures state_eq_opt g (BS.machine_eval_code c f s) (BS.machine_eval_code c f (core_state g s))) (decreases %[f; c]) = match c with | Ins i -> reveal_opaque (`%BS.machine_eval_code_ins) BS.machine_eval_code_ins; if g then eval_code_eq_ins i f s (core_state g s) | Block cs -> eval_codes_eq_core g cs f s | IfElse cond ct cf -> eval_ocmp_eq_core g cond s; let (s', _) = BS.machine_eval_ocmp s cond in let (t', _) = BS.machine_eval_ocmp (core_state g s) cond in eval_code_eq_core g ct f s'; eval_code_eq_core g ct f t'; eval_code_eq_core g cf f s'; eval_code_eq_core g cf f t'; () | While cond body -> eval_while_eq_core g cond body f s and eval_codes_eq_core (g:bool) (cs:codes) (f:fuel) (s:machine_state) : Lemma (ensures state_eq_opt g (BS.machine_eval_codes cs f s) (BS.machine_eval_codes cs f (core_state g s))) (decreases %[f; cs]) = match cs with | [] -> () | c'::cs' -> ( eval_code_eq_core g c' f s; match (machine_eval_code c' f s, machine_eval_code c' f (core_state g s)) with | (None, None) -> () | (Some s', Some t') -> eval_codes_eq_core g cs' f s'; eval_codes_eq_core g cs' f t' ) and eval_while_eq_core (g:bool) (cond:ocmp) (body:code) (f:fuel) (s:machine_state) : Lemma (ensures state_eq_opt g (BS.machine_eval_while cond body f s) (BS.machine_eval_while cond body f (core_state g s))) (decreases %[f; body]) = if f > 0 then ( eval_ocmp_eq_core g cond s; let (s1, _) = BS.machine_eval_ocmp s cond in let (t1, _) = BS.machine_eval_ocmp (core_state g s) cond in eval_code_eq_core g body (f - 1) s1; eval_code_eq_core g body (f - 1) t1; match (BS.machine_eval_code body (f - 1) s1, BS.machine_eval_code body (f - 1) t1) with | (None, None) -> () | (Some s2, Some t2) -> eval_while_eq_core g cond body (f - 1) s2; eval_while_eq_core g cond body (f - 1) t2; () ) let eval_code_eq_f (c:code) (f:fuel) (s1 s2:machine_state) : Lemma (requires state_eq_S false s1 s2) (ensures state_eq_opt false (BS.machine_eval_code c f s1) (BS.machine_eval_code c f s2)) [SMTPat (BS.machine_eval_code c f s1); SMTPat (BS.machine_eval_code c f s2)] = eval_code_eq_core false c f s1; eval_code_eq_core false c f s2 let eval_codes_eq_f (cs:codes) (f:fuel) (s1 s2:machine_state) : Lemma (requires state_eq_S false s1 s2) (ensures state_eq_opt false (BS.machine_eval_codes cs f s1) (BS.machine_eval_codes cs f s2)) [SMTPat (BS.machine_eval_codes cs f s1); SMTPat (BS.machine_eval_codes cs f s2)] = eval_codes_eq_core false cs f s1; eval_codes_eq_core false cs f s2 let eval_while_eq_f (cond:ocmp) (body:code) (f:fuel) (s1 s2:machine_state) : Lemma (requires state_eq_S false s1 s2) (ensures state_eq_opt false (BS.machine_eval_while cond body f s1) (BS.machine_eval_while cond body f s2)) [SMTPat (BS.machine_eval_while cond body f s1); SMTPat (BS.machine_eval_while cond body f s2)] = eval_while_eq_core false cond body f s1; eval_while_eq_core false cond body f s2 let eval_code_eq_t (c:code) (f:fuel) (s1 s2:machine_state) : Lemma (requires state_eq_S true s1 s2) (ensures state_eq_opt true (BS.machine_eval_code c f s1) (BS.machine_eval_code c f s2)) [SMTPat (BS.machine_eval_code c f s1); SMTPat (BS.machine_eval_code c f s2)] = eval_code_eq_core true c f s1; eval_code_eq_core true c f s2 let eval_codes_eq_t (cs:codes) (f:fuel) (s1 s2:machine_state) : Lemma (requires state_eq_S true s1 s2) (ensures state_eq_opt true (BS.machine_eval_codes cs f s1) (BS.machine_eval_codes cs f s2)) [SMTPat (BS.machine_eval_codes cs f s1); SMTPat (BS.machine_eval_codes cs f s2)] = eval_codes_eq_core true cs f s1; eval_codes_eq_core true cs f s2 let eval_while_eq_t (cond:ocmp) (body:code) (f:fuel) (s1 s2:machine_state) : Lemma (requires state_eq_S true s1 s2) (ensures state_eq_opt true (BS.machine_eval_while cond body f s1) (BS.machine_eval_while cond body f s2)) [SMTPat (BS.machine_eval_while cond body f s1); SMTPat (BS.machine_eval_while cond body f s2)] = eval_while_eq_core true cond body f s1; eval_while_eq_core true cond body f s2 let eval_code_ts (g:bool) (c:code) (s0:machine_state) (f0:fuel) (s1:machine_state) : Type0 = state_eq_opt g (BS.machine_eval_code c f0 s0) (Some s1) let rec increase_fuel (g:bool) (c:code) (s0:machine_state) (f0:fuel) (sN:machine_state) (fN:fuel) : Lemma (requires eval_code_ts g c s0 f0 sN /\ f0 <= fN) (ensures eval_code_ts g c s0 fN sN) (decreases %[f0; c]) = match c with | Ins ins -> () | Block l -> increase_fuels g l s0 f0 sN fN | IfElse cond t f -> let (s0, b0) = BS.machine_eval_ocmp s0 cond in if b0 then increase_fuel g t s0 f0 sN fN else increase_fuel g f s0 f0 sN fN | While cond c -> let (s1, b0) = BS.machine_eval_ocmp s0 cond in if b0 then ( match BS.machine_eval_code c (f0 - 1) s1 with | None -> () | Some s2 -> increase_fuel g c s1 (f0 - 1) s2 (fN - 1); if s2.BS.ms_ok then increase_fuel g (While cond c) s2 (f0 - 1) sN (fN - 1) else () ) and increase_fuels (g:bool) (c:codes) (s0:machine_state) (f0:fuel) (sN:machine_state) (fN:fuel) : Lemma (requires eval_code_ts g (Block c) s0 f0 sN /\ f0 <= fN) (ensures eval_code_ts g (Block c) s0 fN sN) (decreases %[f0; c]) = match c with | [] -> () | h::t -> ( let Some s1 = BS.machine_eval_code h f0 s0 in increase_fuel g h s0 f0 s1 fN; increase_fuels g t s1 f0 sN fN ) let lemma_cmp_eq s o1 o2 = reveal_opaque (`%BS.eval_ocmp_opaque) BS.eval_ocmp_opaque let lemma_cmp_ne s o1 o2 = reveal_opaque (`%BS.eval_ocmp_opaque) BS.eval_ocmp_opaque let lemma_cmp_le s o1 o2 = reveal_opaque (`%BS.eval_ocmp_opaque) BS.eval_ocmp_opaque let lemma_cmp_ge s o1 o2 = reveal_opaque (`%BS.eval_ocmp_opaque) BS.eval_ocmp_opaque let lemma_cmp_lt s o1 o2 = reveal_opaque (`%BS.eval_ocmp_opaque) BS.eval_ocmp_opaque let lemma_cmp_gt s o1 o2 = reveal_opaque (`%BS.eval_ocmp_opaque) BS.eval_ocmp_opaque let lemma_valid_cmp_eq s o1 o2 = () let lemma_valid_cmp_ne s o1 o2 = () let lemma_valid_cmp_le s o1 o2 = () let lemma_valid_cmp_ge s o1 o2 = () let lemma_valid_cmp_lt s o1 o2 = () let lemma_valid_cmp_gt s o1 o2 = () let compute_merge_total (f0:fuel) (fM:fuel) = if f0 > fM then f0 else fM let lemma_merge_total (b0:codes) (s0:vale_state) (f0:fuel) (sM:vale_state) (fM:fuel) (sN:vale_state) = let f = if f0 > fM then f0 else fM in increase_fuel (codes_modifies_ghost b0) (Cons?.hd b0) (state_to_S s0) f0 (state_to_S sM) f; increase_fuel (codes_modifies_ghost b0) (Block (Cons?.tl b0)) (state_to_S sM) fM (state_to_S sN) f let lemma_empty_total (s0:vale_state) (bN:codes) = (s0, 0)
{ "checked_file": "/", "dependencies": [ "Vale.X64.StateLemmas.fsti.checked", "Vale.X64.State.fsti.checked", "Vale.X64.Memory.fsti.checked", "Vale.X64.Machine_Semantics_s.fst.checked", "Vale.X64.Machine_s.fst.checked", "Vale.X64.Instruction_s.fsti.checked", "Vale.X64.Flags.fsti.checked", "Vale.X64.Bytes_Code_s.fst.checked", "prims.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.FunctionalExtensionality.fsti.checked" ], "interface_file": true, "source_file": "Vale.X64.Lemmas.fst" }
[ { "abbrev": true, "full_module": "Vale.X64.Memory", "short_module": "ME" }, { "abbrev": true, "full_module": "Vale.X64.Machine_Semantics_s", "short_module": "BS" }, { "abbrev": false, "full_module": "Vale.X64.Bytes_Code_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Instruction_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.StateLemmas", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.State", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Machine_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": true, "full_module": "Vale.Lib.Map16", "short_module": "Map16" }, { "abbrev": true, "full_module": "Vale.X64.Machine_Semantics_s", "short_module": "BS" }, { "abbrev": false, "full_module": "Vale.X64.Bytes_Code_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.StateLemmas", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.State", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Machine_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.HeapLemmas", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.HeapImpl", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.Heap", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 0, "max_fuel": 2, "max_ifuel": 1, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": true, "smtencoding_l_arith_repr": "native", "smtencoding_nl_arith_repr": "wrapped", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [ "smt.arith.nl=false", "smt.QI.EAGER_THRESHOLD=100", "smt.CASE_SPLIT=3" ], "z3refresh": false, "z3rlimit": 30, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
ifb: Vale.X64.Bytes_Code_s.ocmp -> ct: Vale.X64.StateLemmas.code -> cf: Vale.X64.StateLemmas.code -> s0: Vale.X64.State.vale_state -> Prims.Ghost (((Prims.bool * Vale.X64.State.vale_state) * Vale.X64.State.vale_state) * Vale.X64.Lemmas.fuel)
Prims.Ghost
[]
[]
[ "Vale.X64.Bytes_Code_s.ocmp", "Vale.X64.StateLemmas.code", "Vale.X64.State.vale_state", "FStar.Pervasives.Native.Mktuple4", "Prims.bool", "Vale.X64.Lemmas.fuel", "Vale.X64.Lemmas.eval_ocmp", "Vale.X64.State.Mkvale_state", "Vale.X64.State.__proj__Mkvale_state__item__vs_ok", "Vale.X64.State.__proj__Mkvale_state__item__vs_regs", "Vale.X64.Lemmas.havoc_flags", "Vale.X64.State.__proj__Mkvale_state__item__vs_heap", "Vale.X64.State.__proj__Mkvale_state__item__vs_stack", "Vale.X64.State.__proj__Mkvale_state__item__vs_stackTaint", "FStar.Pervasives.Native.tuple4" ]
[]
false
false
false
false
false
let lemma_ifElse_total (ifb: ocmp) (ct cf: code) (s0: vale_state) =
(eval_ocmp s0 ifb, { s0 with vs_flags = havoc_flags }, s0, 0)
false
Vale.X64.Lemmas.fst
Vale.X64.Lemmas.lemma_havoc_flags
val lemma_havoc_flags:squash (Flags.to_fun havoc_flags == BS.havoc_flags)
val lemma_havoc_flags:squash (Flags.to_fun havoc_flags == BS.havoc_flags)
let lemma_havoc_flags : squash (Flags.to_fun havoc_flags == BS.havoc_flags) = assert (FStar.FunctionalExtensionality.feq (Flags.to_fun havoc_flags) BS.havoc_flags)
{ "file_name": "vale/code/arch/x64/Vale.X64.Lemmas.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 87, "end_line": 362, "start_col": 0, "start_line": 361 }
module Vale.X64.Lemmas open FStar.Mul open Vale.X64.Machine_s open Vale.X64.State open Vale.X64.StateLemmas open Vale.X64.Instruction_s open Vale.X64.Bytes_Code_s module BS = Vale.X64.Machine_Semantics_s module ME = Vale.X64.Memory #reset-options "--initial_fuel 1 --max_fuel 1 --z3rlimit 100" #restart-solver let rec lemma_eq_instr_apply_eval_args (outs:list instr_out) (args:list instr_operand) (f:instr_args_t outs args) (oprs:instr_operands_t_args args) (s1 s2:machine_state) : Lemma (requires state_eq_S true s1 s2) (ensures BS.instr_apply_eval_args outs args f oprs s1 == BS.instr_apply_eval_args outs args f oprs s2) = let open BS in lemma_heap_ignore_ghost_machine s1.BS.ms_heap s2.BS.ms_heap; match args with | [] -> () | i::args -> ( let (v, oprs) : option (instr_val_t i) & instr_operands_t_args args = match i with | IOpEx i -> let oprs = coerce oprs in (instr_eval_operand_explicit i (fst oprs) s1, snd oprs) | IOpIm i -> (instr_eval_operand_implicit i s1, coerce oprs) in let f:arrow (instr_val_t i) (instr_args_t outs args) = coerce f in match v with | None -> () | Some v -> lemma_eq_instr_apply_eval_args outs args (f v) oprs s1 s2 ) #restart-solver let rec lemma_eq_instr_apply_eval_inouts (outs inouts:list instr_out) (args:list instr_operand) (f:instr_inouts_t outs inouts args) (oprs:instr_operands_t inouts args) (s1 s2:machine_state) : Lemma (requires state_eq_S true s1 s2) (ensures BS.instr_apply_eval_inouts outs inouts args f oprs s1 == BS.instr_apply_eval_inouts outs inouts args f oprs s2) = let open BS in lemma_heap_ignore_ghost_machine s1.BS.ms_heap s2.BS.ms_heap; match inouts with | [] -> lemma_eq_instr_apply_eval_args outs args f oprs s1 s2 | (Out, i)::inouts -> let oprs = match i with | IOpEx i -> snd #(instr_operand_t i) (coerce oprs) | IOpIm i -> coerce oprs in lemma_eq_instr_apply_eval_inouts outs inouts args (coerce f) oprs s1 s2 | (InOut, i)::inouts -> ( let (v, oprs) : option (instr_val_t i) & instr_operands_t inouts args = match i with | IOpEx i -> let oprs = coerce oprs in (instr_eval_operand_explicit i (fst oprs) s1, snd oprs) | IOpIm i -> (instr_eval_operand_implicit i s1, coerce oprs) in let f:arrow (instr_val_t i) (instr_inouts_t outs inouts args) = coerce f in match v with | None -> () | Some v -> lemma_eq_instr_apply_eval_inouts outs inouts args (f v) oprs s1 s2 ) #restart-solver #push-options "--z3rlimit_factor 2" let rec lemma_eq_instr_write_outputs (outs:list instr_out) (args:list instr_operand) (vs:instr_ret_t outs) (oprs:instr_operands_t outs args) (s1_orig s1 s2_orig s2:machine_state) : Lemma (requires state_eq_S true s1_orig s2_orig /\ state_eq_S true s1 s2) (ensures state_eq_S true (BS.instr_write_outputs outs args vs oprs s1_orig s1) (BS.instr_write_outputs outs args vs oprs s2_orig s2)) = let open BS in use_machine_state_equal (); lemma_heap_ignore_ghost_machine s1.BS.ms_heap s2.BS.ms_heap; lemma_heap_ignore_ghost_machine s1_orig.BS.ms_heap s2_orig.BS.ms_heap; allow_inversion tmaddr; match outs with | [] -> () | (_, i)::outs -> ( let ((v:instr_val_t i), (vs:instr_ret_t outs)) = match outs with | [] -> (vs, ()) | _::_ -> let vs = coerce vs in (fst vs, snd vs) in match i with | IOpEx i -> let oprs = coerce oprs in let s1 = instr_write_output_explicit i v (fst oprs) s1_orig s1 in let s2 = instr_write_output_explicit i v (fst oprs) s2_orig s2 in lemma_eq_instr_write_outputs outs args vs (snd oprs) s1_orig s1 s2_orig s2 | IOpIm i -> let s1 = instr_write_output_implicit i v s1_orig s1 in let s2 = instr_write_output_implicit i v s2_orig s2 in allow_inversion operand64; allow_inversion operand128; lemma_eq_instr_write_outputs outs args vs (coerce oprs) s1_orig s1 s2_orig s2 ) #pop-options #restart-solver let eval_ins_eq_instr (inst:BS.ins) (s1 s2:machine_state) : Lemma (requires Instr? inst /\ state_eq_S true s1 s2) (ensures state_eq_S true (BS.machine_eval_ins inst s1) (BS.machine_eval_ins inst s2)) = let open BS in let Instr it oprs ann = inst in let InstrTypeRecord #outs #args #havoc_flags' i = it in lemma_eq_instr_apply_eval_inouts outs outs args (instr_eval i) oprs s1 s2; let vs = instr_apply_eval outs args (instr_eval i) oprs s1 in let hav s = match havoc_flags' with | HavocFlags -> {s with ms_flags = havoc_flags} | PreserveFlags -> s in let s1' = hav s1 in let s2' = hav s2 in match vs with | None -> () | Some vs -> lemma_eq_instr_write_outputs outs args vs oprs s1 s1' s2 s2' let eval_code_eq_instr (inst:BS.ins) (f:fuel) (s1 s2:machine_state) : Lemma (requires Instr? inst /\ state_eq_S true s1 s2) (ensures state_eq_opt true (BS.machine_eval_code (Ins inst) f s1) (BS.machine_eval_code (Ins inst) f s2)) = reveal_opaque (`%BS.machine_eval_code_ins) BS.machine_eval_code_ins; eval_ins_eq_instr inst ({s1 with BS.ms_trace = []}) ({s2 with BS.ms_trace = []}) let eval_code_eq_dealloc (inst:BS.ins) (f:fuel) (s1 s2:machine_state) : Lemma (requires Dealloc? inst /\ state_eq_S true s1 s2) (ensures state_eq_opt true (BS.machine_eval_code (Ins inst) f s1) (BS.machine_eval_code (Ins inst) f s2)) = reveal_opaque (`%BS.machine_eval_code_ins) BS.machine_eval_code_ins; use_machine_state_equal (); lemma_heap_ignore_ghost_machine s1.BS.ms_heap s2.BS.ms_heap; allow_inversion tmaddr let eval_code_eq_alloc (inst:BS.ins) (f:fuel) (s1 s2:machine_state) : Lemma (requires Alloc? inst /\ state_eq_S true s1 s2) (ensures state_eq_opt true (BS.machine_eval_code (Ins inst) f s1) (BS.machine_eval_code (Ins inst) f s2)) = reveal_opaque (`%BS.machine_eval_code_ins) BS.machine_eval_code_ins; use_machine_state_equal (); lemma_heap_ignore_ghost_machine s1.BS.ms_heap s2.BS.ms_heap; allow_inversion tmaddr let eval_code_eq_push (inst:BS.ins) (f:fuel) (s1 s2:machine_state) : Lemma (requires Push? inst /\ state_eq_S true s1 s2) (ensures state_eq_opt true (BS.machine_eval_code (Ins inst) f s1) (BS.machine_eval_code (Ins inst) f s2)) = reveal_opaque (`%BS.machine_eval_code_ins) BS.machine_eval_code_ins; use_machine_state_equal (); lemma_heap_ignore_ghost_machine s1.BS.ms_heap s2.BS.ms_heap; allow_inversion tmaddr let eval_code_eq_pop (inst:BS.ins) (f:fuel) (s1 s2:machine_state) : Lemma (requires Pop? inst /\ state_eq_S true s1 s2) (ensures state_eq_opt true (BS.machine_eval_code (Ins inst) f s1) (BS.machine_eval_code (Ins inst) f s2)) = reveal_opaque (`%BS.machine_eval_code_ins) BS.machine_eval_code_ins; use_machine_state_equal (); lemma_heap_ignore_ghost_machine s1.BS.ms_heap s2.BS.ms_heap; allow_inversion tmaddr let eval_code_eq_ins (i:BS.ins) (f:fuel) (s1 s2:machine_state) : Lemma (requires state_eq_S true s1 s2) (ensures state_eq_opt true (BS.machine_eval_code (Ins i) f s1) (BS.machine_eval_code (Ins i) f s2)) = match i with | Instr _ _ _ -> eval_code_eq_instr i f s1 s2 | Dealloc _ -> eval_code_eq_dealloc i f s1 s2 | Alloc _ -> eval_code_eq_alloc i f s1 s2 | Push _ _ -> eval_code_eq_push i f s1 s2 | Pop _ _ -> eval_code_eq_pop i f s1 s2 #reset-options "--fuel 2 --z3rlimit 30" let eval_ocmp_eq_core (g:bool) (cond:ocmp) (s:machine_state) : Lemma (ensures ( let (s1, b1) = BS.machine_eval_ocmp s cond in let (s2, b2) = BS.machine_eval_ocmp (core_state g s) cond in state_eq_S g s1 s2 /\ b1 == b2 )) = reveal_opaque (`%BS.valid_ocmp_opaque) BS.valid_ocmp_opaque; reveal_opaque (`%BS.eval_ocmp_opaque) BS.eval_ocmp_opaque; () #restart-solver let rec eval_code_eq_core (g:bool) (c:code) (f:fuel) (s:machine_state) : Lemma (ensures state_eq_opt g (BS.machine_eval_code c f s) (BS.machine_eval_code c f (core_state g s))) (decreases %[f; c]) = match c with | Ins i -> reveal_opaque (`%BS.machine_eval_code_ins) BS.machine_eval_code_ins; if g then eval_code_eq_ins i f s (core_state g s) | Block cs -> eval_codes_eq_core g cs f s | IfElse cond ct cf -> eval_ocmp_eq_core g cond s; let (s', _) = BS.machine_eval_ocmp s cond in let (t', _) = BS.machine_eval_ocmp (core_state g s) cond in eval_code_eq_core g ct f s'; eval_code_eq_core g ct f t'; eval_code_eq_core g cf f s'; eval_code_eq_core g cf f t'; () | While cond body -> eval_while_eq_core g cond body f s and eval_codes_eq_core (g:bool) (cs:codes) (f:fuel) (s:machine_state) : Lemma (ensures state_eq_opt g (BS.machine_eval_codes cs f s) (BS.machine_eval_codes cs f (core_state g s))) (decreases %[f; cs]) = match cs with | [] -> () | c'::cs' -> ( eval_code_eq_core g c' f s; match (machine_eval_code c' f s, machine_eval_code c' f (core_state g s)) with | (None, None) -> () | (Some s', Some t') -> eval_codes_eq_core g cs' f s'; eval_codes_eq_core g cs' f t' ) and eval_while_eq_core (g:bool) (cond:ocmp) (body:code) (f:fuel) (s:machine_state) : Lemma (ensures state_eq_opt g (BS.machine_eval_while cond body f s) (BS.machine_eval_while cond body f (core_state g s))) (decreases %[f; body]) = if f > 0 then ( eval_ocmp_eq_core g cond s; let (s1, _) = BS.machine_eval_ocmp s cond in let (t1, _) = BS.machine_eval_ocmp (core_state g s) cond in eval_code_eq_core g body (f - 1) s1; eval_code_eq_core g body (f - 1) t1; match (BS.machine_eval_code body (f - 1) s1, BS.machine_eval_code body (f - 1) t1) with | (None, None) -> () | (Some s2, Some t2) -> eval_while_eq_core g cond body (f - 1) s2; eval_while_eq_core g cond body (f - 1) t2; () ) let eval_code_eq_f (c:code) (f:fuel) (s1 s2:machine_state) : Lemma (requires state_eq_S false s1 s2) (ensures state_eq_opt false (BS.machine_eval_code c f s1) (BS.machine_eval_code c f s2)) [SMTPat (BS.machine_eval_code c f s1); SMTPat (BS.machine_eval_code c f s2)] = eval_code_eq_core false c f s1; eval_code_eq_core false c f s2 let eval_codes_eq_f (cs:codes) (f:fuel) (s1 s2:machine_state) : Lemma (requires state_eq_S false s1 s2) (ensures state_eq_opt false (BS.machine_eval_codes cs f s1) (BS.machine_eval_codes cs f s2)) [SMTPat (BS.machine_eval_codes cs f s1); SMTPat (BS.machine_eval_codes cs f s2)] = eval_codes_eq_core false cs f s1; eval_codes_eq_core false cs f s2 let eval_while_eq_f (cond:ocmp) (body:code) (f:fuel) (s1 s2:machine_state) : Lemma (requires state_eq_S false s1 s2) (ensures state_eq_opt false (BS.machine_eval_while cond body f s1) (BS.machine_eval_while cond body f s2)) [SMTPat (BS.machine_eval_while cond body f s1); SMTPat (BS.machine_eval_while cond body f s2)] = eval_while_eq_core false cond body f s1; eval_while_eq_core false cond body f s2 let eval_code_eq_t (c:code) (f:fuel) (s1 s2:machine_state) : Lemma (requires state_eq_S true s1 s2) (ensures state_eq_opt true (BS.machine_eval_code c f s1) (BS.machine_eval_code c f s2)) [SMTPat (BS.machine_eval_code c f s1); SMTPat (BS.machine_eval_code c f s2)] = eval_code_eq_core true c f s1; eval_code_eq_core true c f s2 let eval_codes_eq_t (cs:codes) (f:fuel) (s1 s2:machine_state) : Lemma (requires state_eq_S true s1 s2) (ensures state_eq_opt true (BS.machine_eval_codes cs f s1) (BS.machine_eval_codes cs f s2)) [SMTPat (BS.machine_eval_codes cs f s1); SMTPat (BS.machine_eval_codes cs f s2)] = eval_codes_eq_core true cs f s1; eval_codes_eq_core true cs f s2 let eval_while_eq_t (cond:ocmp) (body:code) (f:fuel) (s1 s2:machine_state) : Lemma (requires state_eq_S true s1 s2) (ensures state_eq_opt true (BS.machine_eval_while cond body f s1) (BS.machine_eval_while cond body f s2)) [SMTPat (BS.machine_eval_while cond body f s1); SMTPat (BS.machine_eval_while cond body f s2)] = eval_while_eq_core true cond body f s1; eval_while_eq_core true cond body f s2 let eval_code_ts (g:bool) (c:code) (s0:machine_state) (f0:fuel) (s1:machine_state) : Type0 = state_eq_opt g (BS.machine_eval_code c f0 s0) (Some s1) let rec increase_fuel (g:bool) (c:code) (s0:machine_state) (f0:fuel) (sN:machine_state) (fN:fuel) : Lemma (requires eval_code_ts g c s0 f0 sN /\ f0 <= fN) (ensures eval_code_ts g c s0 fN sN) (decreases %[f0; c]) = match c with | Ins ins -> () | Block l -> increase_fuels g l s0 f0 sN fN | IfElse cond t f -> let (s0, b0) = BS.machine_eval_ocmp s0 cond in if b0 then increase_fuel g t s0 f0 sN fN else increase_fuel g f s0 f0 sN fN | While cond c -> let (s1, b0) = BS.machine_eval_ocmp s0 cond in if b0 then ( match BS.machine_eval_code c (f0 - 1) s1 with | None -> () | Some s2 -> increase_fuel g c s1 (f0 - 1) s2 (fN - 1); if s2.BS.ms_ok then increase_fuel g (While cond c) s2 (f0 - 1) sN (fN - 1) else () ) and increase_fuels (g:bool) (c:codes) (s0:machine_state) (f0:fuel) (sN:machine_state) (fN:fuel) : Lemma (requires eval_code_ts g (Block c) s0 f0 sN /\ f0 <= fN) (ensures eval_code_ts g (Block c) s0 fN sN) (decreases %[f0; c]) = match c with | [] -> () | h::t -> ( let Some s1 = BS.machine_eval_code h f0 s0 in increase_fuel g h s0 f0 s1 fN; increase_fuels g t s1 f0 sN fN ) let lemma_cmp_eq s o1 o2 = reveal_opaque (`%BS.eval_ocmp_opaque) BS.eval_ocmp_opaque let lemma_cmp_ne s o1 o2 = reveal_opaque (`%BS.eval_ocmp_opaque) BS.eval_ocmp_opaque let lemma_cmp_le s o1 o2 = reveal_opaque (`%BS.eval_ocmp_opaque) BS.eval_ocmp_opaque let lemma_cmp_ge s o1 o2 = reveal_opaque (`%BS.eval_ocmp_opaque) BS.eval_ocmp_opaque let lemma_cmp_lt s o1 o2 = reveal_opaque (`%BS.eval_ocmp_opaque) BS.eval_ocmp_opaque let lemma_cmp_gt s o1 o2 = reveal_opaque (`%BS.eval_ocmp_opaque) BS.eval_ocmp_opaque let lemma_valid_cmp_eq s o1 o2 = () let lemma_valid_cmp_ne s o1 o2 = () let lemma_valid_cmp_le s o1 o2 = () let lemma_valid_cmp_ge s o1 o2 = () let lemma_valid_cmp_lt s o1 o2 = () let lemma_valid_cmp_gt s o1 o2 = () let compute_merge_total (f0:fuel) (fM:fuel) = if f0 > fM then f0 else fM let lemma_merge_total (b0:codes) (s0:vale_state) (f0:fuel) (sM:vale_state) (fM:fuel) (sN:vale_state) = let f = if f0 > fM then f0 else fM in increase_fuel (codes_modifies_ghost b0) (Cons?.hd b0) (state_to_S s0) f0 (state_to_S sM) f; increase_fuel (codes_modifies_ghost b0) (Block (Cons?.tl b0)) (state_to_S sM) fM (state_to_S sN) f let lemma_empty_total (s0:vale_state) (bN:codes) = (s0, 0) let lemma_ifElse_total (ifb:ocmp) (ct:code) (cf:code) (s0:vale_state) = (eval_ocmp s0 ifb, {s0 with vs_flags = havoc_flags}, s0, 0)
{ "checked_file": "/", "dependencies": [ "Vale.X64.StateLemmas.fsti.checked", "Vale.X64.State.fsti.checked", "Vale.X64.Memory.fsti.checked", "Vale.X64.Machine_Semantics_s.fst.checked", "Vale.X64.Machine_s.fst.checked", "Vale.X64.Instruction_s.fsti.checked", "Vale.X64.Flags.fsti.checked", "Vale.X64.Bytes_Code_s.fst.checked", "prims.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.FunctionalExtensionality.fsti.checked" ], "interface_file": true, "source_file": "Vale.X64.Lemmas.fst" }
[ { "abbrev": true, "full_module": "Vale.X64.Memory", "short_module": "ME" }, { "abbrev": true, "full_module": "Vale.X64.Machine_Semantics_s", "short_module": "BS" }, { "abbrev": false, "full_module": "Vale.X64.Bytes_Code_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Instruction_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.StateLemmas", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.State", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Machine_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": true, "full_module": "Vale.Lib.Map16", "short_module": "Map16" }, { "abbrev": true, "full_module": "Vale.X64.Machine_Semantics_s", "short_module": "BS" }, { "abbrev": false, "full_module": "Vale.X64.Bytes_Code_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.StateLemmas", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.State", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Machine_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.HeapLemmas", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.HeapImpl", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.Heap", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 0, "max_fuel": 2, "max_ifuel": 1, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": true, "smtencoding_l_arith_repr": "native", "smtencoding_nl_arith_repr": "wrapped", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [ "smt.arith.nl=false", "smt.QI.EAGER_THRESHOLD=100", "smt.CASE_SPLIT=3" ], "z3refresh": false, "z3rlimit": 30, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
Prims.squash (Vale.X64.Flags.to_fun Vale.X64.Lemmas.havoc_flags == Vale.X64.Machine_Semantics_s.havoc_flags)
Prims.Tot
[ "total" ]
[]
[ "Prims._assert", "FStar.FunctionalExtensionality.feq", "Vale.X64.Machine_s.flag", "Vale.X64.Flags.flag_val_t", "Vale.X64.Flags.to_fun", "Vale.X64.Lemmas.havoc_flags", "Vale.X64.Machine_Semantics_s.havoc_flags" ]
[]
false
false
true
false
false
let lemma_havoc_flags:squash (Flags.to_fun havoc_flags == BS.havoc_flags) =
assert (FStar.FunctionalExtensionality.feq (Flags.to_fun havoc_flags) BS.havoc_flags)
false
Vale.X64.Lemmas.fst
Vale.X64.Lemmas.lemma_ifElseTrue_total
val lemma_ifElseTrue_total (ifb:ocmp) (ct:code) (cf:code) (s0:vale_state) (f0:fuel) (sM:vale_state) : Lemma (requires valid_ocmp ifb s0 /\ eval_ocmp s0 ifb /\ eval_code ct ({s0 with vs_flags = havoc_flags}) f0 sM ) (ensures eval_code (IfElse ifb ct cf) s0 f0 sM )
val lemma_ifElseTrue_total (ifb:ocmp) (ct:code) (cf:code) (s0:vale_state) (f0:fuel) (sM:vale_state) : Lemma (requires valid_ocmp ifb s0 /\ eval_ocmp s0 ifb /\ eval_code ct ({s0 with vs_flags = havoc_flags}) f0 sM ) (ensures eval_code (IfElse ifb ct cf) s0 f0 sM )
let lemma_ifElseTrue_total (ifb:ocmp) (ct:code) (cf:code) (s0:vale_state) (f0:fuel) (sM:vale_state) = reveal_opaque (`%BS.valid_ocmp_opaque) BS.valid_ocmp_opaque; reveal_opaque (`%BS.eval_ocmp_opaque) BS.eval_ocmp_opaque
{ "file_name": "vale/code/arch/x64/Vale.X64.Lemmas.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 59, "end_line": 366, "start_col": 0, "start_line": 364 }
module Vale.X64.Lemmas open FStar.Mul open Vale.X64.Machine_s open Vale.X64.State open Vale.X64.StateLemmas open Vale.X64.Instruction_s open Vale.X64.Bytes_Code_s module BS = Vale.X64.Machine_Semantics_s module ME = Vale.X64.Memory #reset-options "--initial_fuel 1 --max_fuel 1 --z3rlimit 100" #restart-solver let rec lemma_eq_instr_apply_eval_args (outs:list instr_out) (args:list instr_operand) (f:instr_args_t outs args) (oprs:instr_operands_t_args args) (s1 s2:machine_state) : Lemma (requires state_eq_S true s1 s2) (ensures BS.instr_apply_eval_args outs args f oprs s1 == BS.instr_apply_eval_args outs args f oprs s2) = let open BS in lemma_heap_ignore_ghost_machine s1.BS.ms_heap s2.BS.ms_heap; match args with | [] -> () | i::args -> ( let (v, oprs) : option (instr_val_t i) & instr_operands_t_args args = match i with | IOpEx i -> let oprs = coerce oprs in (instr_eval_operand_explicit i (fst oprs) s1, snd oprs) | IOpIm i -> (instr_eval_operand_implicit i s1, coerce oprs) in let f:arrow (instr_val_t i) (instr_args_t outs args) = coerce f in match v with | None -> () | Some v -> lemma_eq_instr_apply_eval_args outs args (f v) oprs s1 s2 ) #restart-solver let rec lemma_eq_instr_apply_eval_inouts (outs inouts:list instr_out) (args:list instr_operand) (f:instr_inouts_t outs inouts args) (oprs:instr_operands_t inouts args) (s1 s2:machine_state) : Lemma (requires state_eq_S true s1 s2) (ensures BS.instr_apply_eval_inouts outs inouts args f oprs s1 == BS.instr_apply_eval_inouts outs inouts args f oprs s2) = let open BS in lemma_heap_ignore_ghost_machine s1.BS.ms_heap s2.BS.ms_heap; match inouts with | [] -> lemma_eq_instr_apply_eval_args outs args f oprs s1 s2 | (Out, i)::inouts -> let oprs = match i with | IOpEx i -> snd #(instr_operand_t i) (coerce oprs) | IOpIm i -> coerce oprs in lemma_eq_instr_apply_eval_inouts outs inouts args (coerce f) oprs s1 s2 | (InOut, i)::inouts -> ( let (v, oprs) : option (instr_val_t i) & instr_operands_t inouts args = match i with | IOpEx i -> let oprs = coerce oprs in (instr_eval_operand_explicit i (fst oprs) s1, snd oprs) | IOpIm i -> (instr_eval_operand_implicit i s1, coerce oprs) in let f:arrow (instr_val_t i) (instr_inouts_t outs inouts args) = coerce f in match v with | None -> () | Some v -> lemma_eq_instr_apply_eval_inouts outs inouts args (f v) oprs s1 s2 ) #restart-solver #push-options "--z3rlimit_factor 2" let rec lemma_eq_instr_write_outputs (outs:list instr_out) (args:list instr_operand) (vs:instr_ret_t outs) (oprs:instr_operands_t outs args) (s1_orig s1 s2_orig s2:machine_state) : Lemma (requires state_eq_S true s1_orig s2_orig /\ state_eq_S true s1 s2) (ensures state_eq_S true (BS.instr_write_outputs outs args vs oprs s1_orig s1) (BS.instr_write_outputs outs args vs oprs s2_orig s2)) = let open BS in use_machine_state_equal (); lemma_heap_ignore_ghost_machine s1.BS.ms_heap s2.BS.ms_heap; lemma_heap_ignore_ghost_machine s1_orig.BS.ms_heap s2_orig.BS.ms_heap; allow_inversion tmaddr; match outs with | [] -> () | (_, i)::outs -> ( let ((v:instr_val_t i), (vs:instr_ret_t outs)) = match outs with | [] -> (vs, ()) | _::_ -> let vs = coerce vs in (fst vs, snd vs) in match i with | IOpEx i -> let oprs = coerce oprs in let s1 = instr_write_output_explicit i v (fst oprs) s1_orig s1 in let s2 = instr_write_output_explicit i v (fst oprs) s2_orig s2 in lemma_eq_instr_write_outputs outs args vs (snd oprs) s1_orig s1 s2_orig s2 | IOpIm i -> let s1 = instr_write_output_implicit i v s1_orig s1 in let s2 = instr_write_output_implicit i v s2_orig s2 in allow_inversion operand64; allow_inversion operand128; lemma_eq_instr_write_outputs outs args vs (coerce oprs) s1_orig s1 s2_orig s2 ) #pop-options #restart-solver let eval_ins_eq_instr (inst:BS.ins) (s1 s2:machine_state) : Lemma (requires Instr? inst /\ state_eq_S true s1 s2) (ensures state_eq_S true (BS.machine_eval_ins inst s1) (BS.machine_eval_ins inst s2)) = let open BS in let Instr it oprs ann = inst in let InstrTypeRecord #outs #args #havoc_flags' i = it in lemma_eq_instr_apply_eval_inouts outs outs args (instr_eval i) oprs s1 s2; let vs = instr_apply_eval outs args (instr_eval i) oprs s1 in let hav s = match havoc_flags' with | HavocFlags -> {s with ms_flags = havoc_flags} | PreserveFlags -> s in let s1' = hav s1 in let s2' = hav s2 in match vs with | None -> () | Some vs -> lemma_eq_instr_write_outputs outs args vs oprs s1 s1' s2 s2' let eval_code_eq_instr (inst:BS.ins) (f:fuel) (s1 s2:machine_state) : Lemma (requires Instr? inst /\ state_eq_S true s1 s2) (ensures state_eq_opt true (BS.machine_eval_code (Ins inst) f s1) (BS.machine_eval_code (Ins inst) f s2)) = reveal_opaque (`%BS.machine_eval_code_ins) BS.machine_eval_code_ins; eval_ins_eq_instr inst ({s1 with BS.ms_trace = []}) ({s2 with BS.ms_trace = []}) let eval_code_eq_dealloc (inst:BS.ins) (f:fuel) (s1 s2:machine_state) : Lemma (requires Dealloc? inst /\ state_eq_S true s1 s2) (ensures state_eq_opt true (BS.machine_eval_code (Ins inst) f s1) (BS.machine_eval_code (Ins inst) f s2)) = reveal_opaque (`%BS.machine_eval_code_ins) BS.machine_eval_code_ins; use_machine_state_equal (); lemma_heap_ignore_ghost_machine s1.BS.ms_heap s2.BS.ms_heap; allow_inversion tmaddr let eval_code_eq_alloc (inst:BS.ins) (f:fuel) (s1 s2:machine_state) : Lemma (requires Alloc? inst /\ state_eq_S true s1 s2) (ensures state_eq_opt true (BS.machine_eval_code (Ins inst) f s1) (BS.machine_eval_code (Ins inst) f s2)) = reveal_opaque (`%BS.machine_eval_code_ins) BS.machine_eval_code_ins; use_machine_state_equal (); lemma_heap_ignore_ghost_machine s1.BS.ms_heap s2.BS.ms_heap; allow_inversion tmaddr let eval_code_eq_push (inst:BS.ins) (f:fuel) (s1 s2:machine_state) : Lemma (requires Push? inst /\ state_eq_S true s1 s2) (ensures state_eq_opt true (BS.machine_eval_code (Ins inst) f s1) (BS.machine_eval_code (Ins inst) f s2)) = reveal_opaque (`%BS.machine_eval_code_ins) BS.machine_eval_code_ins; use_machine_state_equal (); lemma_heap_ignore_ghost_machine s1.BS.ms_heap s2.BS.ms_heap; allow_inversion tmaddr let eval_code_eq_pop (inst:BS.ins) (f:fuel) (s1 s2:machine_state) : Lemma (requires Pop? inst /\ state_eq_S true s1 s2) (ensures state_eq_opt true (BS.machine_eval_code (Ins inst) f s1) (BS.machine_eval_code (Ins inst) f s2)) = reveal_opaque (`%BS.machine_eval_code_ins) BS.machine_eval_code_ins; use_machine_state_equal (); lemma_heap_ignore_ghost_machine s1.BS.ms_heap s2.BS.ms_heap; allow_inversion tmaddr let eval_code_eq_ins (i:BS.ins) (f:fuel) (s1 s2:machine_state) : Lemma (requires state_eq_S true s1 s2) (ensures state_eq_opt true (BS.machine_eval_code (Ins i) f s1) (BS.machine_eval_code (Ins i) f s2)) = match i with | Instr _ _ _ -> eval_code_eq_instr i f s1 s2 | Dealloc _ -> eval_code_eq_dealloc i f s1 s2 | Alloc _ -> eval_code_eq_alloc i f s1 s2 | Push _ _ -> eval_code_eq_push i f s1 s2 | Pop _ _ -> eval_code_eq_pop i f s1 s2 #reset-options "--fuel 2 --z3rlimit 30" let eval_ocmp_eq_core (g:bool) (cond:ocmp) (s:machine_state) : Lemma (ensures ( let (s1, b1) = BS.machine_eval_ocmp s cond in let (s2, b2) = BS.machine_eval_ocmp (core_state g s) cond in state_eq_S g s1 s2 /\ b1 == b2 )) = reveal_opaque (`%BS.valid_ocmp_opaque) BS.valid_ocmp_opaque; reveal_opaque (`%BS.eval_ocmp_opaque) BS.eval_ocmp_opaque; () #restart-solver let rec eval_code_eq_core (g:bool) (c:code) (f:fuel) (s:machine_state) : Lemma (ensures state_eq_opt g (BS.machine_eval_code c f s) (BS.machine_eval_code c f (core_state g s))) (decreases %[f; c]) = match c with | Ins i -> reveal_opaque (`%BS.machine_eval_code_ins) BS.machine_eval_code_ins; if g then eval_code_eq_ins i f s (core_state g s) | Block cs -> eval_codes_eq_core g cs f s | IfElse cond ct cf -> eval_ocmp_eq_core g cond s; let (s', _) = BS.machine_eval_ocmp s cond in let (t', _) = BS.machine_eval_ocmp (core_state g s) cond in eval_code_eq_core g ct f s'; eval_code_eq_core g ct f t'; eval_code_eq_core g cf f s'; eval_code_eq_core g cf f t'; () | While cond body -> eval_while_eq_core g cond body f s and eval_codes_eq_core (g:bool) (cs:codes) (f:fuel) (s:machine_state) : Lemma (ensures state_eq_opt g (BS.machine_eval_codes cs f s) (BS.machine_eval_codes cs f (core_state g s))) (decreases %[f; cs]) = match cs with | [] -> () | c'::cs' -> ( eval_code_eq_core g c' f s; match (machine_eval_code c' f s, machine_eval_code c' f (core_state g s)) with | (None, None) -> () | (Some s', Some t') -> eval_codes_eq_core g cs' f s'; eval_codes_eq_core g cs' f t' ) and eval_while_eq_core (g:bool) (cond:ocmp) (body:code) (f:fuel) (s:machine_state) : Lemma (ensures state_eq_opt g (BS.machine_eval_while cond body f s) (BS.machine_eval_while cond body f (core_state g s))) (decreases %[f; body]) = if f > 0 then ( eval_ocmp_eq_core g cond s; let (s1, _) = BS.machine_eval_ocmp s cond in let (t1, _) = BS.machine_eval_ocmp (core_state g s) cond in eval_code_eq_core g body (f - 1) s1; eval_code_eq_core g body (f - 1) t1; match (BS.machine_eval_code body (f - 1) s1, BS.machine_eval_code body (f - 1) t1) with | (None, None) -> () | (Some s2, Some t2) -> eval_while_eq_core g cond body (f - 1) s2; eval_while_eq_core g cond body (f - 1) t2; () ) let eval_code_eq_f (c:code) (f:fuel) (s1 s2:machine_state) : Lemma (requires state_eq_S false s1 s2) (ensures state_eq_opt false (BS.machine_eval_code c f s1) (BS.machine_eval_code c f s2)) [SMTPat (BS.machine_eval_code c f s1); SMTPat (BS.machine_eval_code c f s2)] = eval_code_eq_core false c f s1; eval_code_eq_core false c f s2 let eval_codes_eq_f (cs:codes) (f:fuel) (s1 s2:machine_state) : Lemma (requires state_eq_S false s1 s2) (ensures state_eq_opt false (BS.machine_eval_codes cs f s1) (BS.machine_eval_codes cs f s2)) [SMTPat (BS.machine_eval_codes cs f s1); SMTPat (BS.machine_eval_codes cs f s2)] = eval_codes_eq_core false cs f s1; eval_codes_eq_core false cs f s2 let eval_while_eq_f (cond:ocmp) (body:code) (f:fuel) (s1 s2:machine_state) : Lemma (requires state_eq_S false s1 s2) (ensures state_eq_opt false (BS.machine_eval_while cond body f s1) (BS.machine_eval_while cond body f s2)) [SMTPat (BS.machine_eval_while cond body f s1); SMTPat (BS.machine_eval_while cond body f s2)] = eval_while_eq_core false cond body f s1; eval_while_eq_core false cond body f s2 let eval_code_eq_t (c:code) (f:fuel) (s1 s2:machine_state) : Lemma (requires state_eq_S true s1 s2) (ensures state_eq_opt true (BS.machine_eval_code c f s1) (BS.machine_eval_code c f s2)) [SMTPat (BS.machine_eval_code c f s1); SMTPat (BS.machine_eval_code c f s2)] = eval_code_eq_core true c f s1; eval_code_eq_core true c f s2 let eval_codes_eq_t (cs:codes) (f:fuel) (s1 s2:machine_state) : Lemma (requires state_eq_S true s1 s2) (ensures state_eq_opt true (BS.machine_eval_codes cs f s1) (BS.machine_eval_codes cs f s2)) [SMTPat (BS.machine_eval_codes cs f s1); SMTPat (BS.machine_eval_codes cs f s2)] = eval_codes_eq_core true cs f s1; eval_codes_eq_core true cs f s2 let eval_while_eq_t (cond:ocmp) (body:code) (f:fuel) (s1 s2:machine_state) : Lemma (requires state_eq_S true s1 s2) (ensures state_eq_opt true (BS.machine_eval_while cond body f s1) (BS.machine_eval_while cond body f s2)) [SMTPat (BS.machine_eval_while cond body f s1); SMTPat (BS.machine_eval_while cond body f s2)] = eval_while_eq_core true cond body f s1; eval_while_eq_core true cond body f s2 let eval_code_ts (g:bool) (c:code) (s0:machine_state) (f0:fuel) (s1:machine_state) : Type0 = state_eq_opt g (BS.machine_eval_code c f0 s0) (Some s1) let rec increase_fuel (g:bool) (c:code) (s0:machine_state) (f0:fuel) (sN:machine_state) (fN:fuel) : Lemma (requires eval_code_ts g c s0 f0 sN /\ f0 <= fN) (ensures eval_code_ts g c s0 fN sN) (decreases %[f0; c]) = match c with | Ins ins -> () | Block l -> increase_fuels g l s0 f0 sN fN | IfElse cond t f -> let (s0, b0) = BS.machine_eval_ocmp s0 cond in if b0 then increase_fuel g t s0 f0 sN fN else increase_fuel g f s0 f0 sN fN | While cond c -> let (s1, b0) = BS.machine_eval_ocmp s0 cond in if b0 then ( match BS.machine_eval_code c (f0 - 1) s1 with | None -> () | Some s2 -> increase_fuel g c s1 (f0 - 1) s2 (fN - 1); if s2.BS.ms_ok then increase_fuel g (While cond c) s2 (f0 - 1) sN (fN - 1) else () ) and increase_fuels (g:bool) (c:codes) (s0:machine_state) (f0:fuel) (sN:machine_state) (fN:fuel) : Lemma (requires eval_code_ts g (Block c) s0 f0 sN /\ f0 <= fN) (ensures eval_code_ts g (Block c) s0 fN sN) (decreases %[f0; c]) = match c with | [] -> () | h::t -> ( let Some s1 = BS.machine_eval_code h f0 s0 in increase_fuel g h s0 f0 s1 fN; increase_fuels g t s1 f0 sN fN ) let lemma_cmp_eq s o1 o2 = reveal_opaque (`%BS.eval_ocmp_opaque) BS.eval_ocmp_opaque let lemma_cmp_ne s o1 o2 = reveal_opaque (`%BS.eval_ocmp_opaque) BS.eval_ocmp_opaque let lemma_cmp_le s o1 o2 = reveal_opaque (`%BS.eval_ocmp_opaque) BS.eval_ocmp_opaque let lemma_cmp_ge s o1 o2 = reveal_opaque (`%BS.eval_ocmp_opaque) BS.eval_ocmp_opaque let lemma_cmp_lt s o1 o2 = reveal_opaque (`%BS.eval_ocmp_opaque) BS.eval_ocmp_opaque let lemma_cmp_gt s o1 o2 = reveal_opaque (`%BS.eval_ocmp_opaque) BS.eval_ocmp_opaque let lemma_valid_cmp_eq s o1 o2 = () let lemma_valid_cmp_ne s o1 o2 = () let lemma_valid_cmp_le s o1 o2 = () let lemma_valid_cmp_ge s o1 o2 = () let lemma_valid_cmp_lt s o1 o2 = () let lemma_valid_cmp_gt s o1 o2 = () let compute_merge_total (f0:fuel) (fM:fuel) = if f0 > fM then f0 else fM let lemma_merge_total (b0:codes) (s0:vale_state) (f0:fuel) (sM:vale_state) (fM:fuel) (sN:vale_state) = let f = if f0 > fM then f0 else fM in increase_fuel (codes_modifies_ghost b0) (Cons?.hd b0) (state_to_S s0) f0 (state_to_S sM) f; increase_fuel (codes_modifies_ghost b0) (Block (Cons?.tl b0)) (state_to_S sM) fM (state_to_S sN) f let lemma_empty_total (s0:vale_state) (bN:codes) = (s0, 0) let lemma_ifElse_total (ifb:ocmp) (ct:code) (cf:code) (s0:vale_state) = (eval_ocmp s0 ifb, {s0 with vs_flags = havoc_flags}, s0, 0) let lemma_havoc_flags : squash (Flags.to_fun havoc_flags == BS.havoc_flags) = assert (FStar.FunctionalExtensionality.feq (Flags.to_fun havoc_flags) BS.havoc_flags)
{ "checked_file": "/", "dependencies": [ "Vale.X64.StateLemmas.fsti.checked", "Vale.X64.State.fsti.checked", "Vale.X64.Memory.fsti.checked", "Vale.X64.Machine_Semantics_s.fst.checked", "Vale.X64.Machine_s.fst.checked", "Vale.X64.Instruction_s.fsti.checked", "Vale.X64.Flags.fsti.checked", "Vale.X64.Bytes_Code_s.fst.checked", "prims.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.FunctionalExtensionality.fsti.checked" ], "interface_file": true, "source_file": "Vale.X64.Lemmas.fst" }
[ { "abbrev": true, "full_module": "Vale.X64.Memory", "short_module": "ME" }, { "abbrev": true, "full_module": "Vale.X64.Machine_Semantics_s", "short_module": "BS" }, { "abbrev": false, "full_module": "Vale.X64.Bytes_Code_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Instruction_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.StateLemmas", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.State", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Machine_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": true, "full_module": "Vale.Lib.Map16", "short_module": "Map16" }, { "abbrev": true, "full_module": "Vale.X64.Machine_Semantics_s", "short_module": "BS" }, { "abbrev": false, "full_module": "Vale.X64.Bytes_Code_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.StateLemmas", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.State", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Machine_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.HeapLemmas", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.HeapImpl", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.Heap", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 0, "max_fuel": 2, "max_ifuel": 1, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": true, "smtencoding_l_arith_repr": "native", "smtencoding_nl_arith_repr": "wrapped", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [ "smt.arith.nl=false", "smt.QI.EAGER_THRESHOLD=100", "smt.CASE_SPLIT=3" ], "z3refresh": false, "z3rlimit": 30, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
ifb: Vale.X64.Bytes_Code_s.ocmp -> ct: Vale.X64.StateLemmas.code -> cf: Vale.X64.StateLemmas.code -> s0: Vale.X64.State.vale_state -> f0: Vale.X64.Lemmas.fuel -> sM: Vale.X64.State.vale_state -> FStar.Pervasives.Lemma (requires Vale.X64.Lemmas.valid_ocmp ifb s0 /\ Vale.X64.Lemmas.eval_ocmp s0 ifb /\ Vale.X64.Lemmas.eval_code ct (Vale.X64.State.Mkvale_state (Mkvale_state?.vs_ok s0) (Mkvale_state?.vs_regs s0) Vale.X64.Lemmas.havoc_flags (Mkvale_state?.vs_heap s0) (Mkvale_state?.vs_stack s0) (Mkvale_state?.vs_stackTaint s0)) f0 sM) (ensures Vale.X64.Lemmas.eval_code (Vale.X64.Machine_s.IfElse ifb ct cf) s0 f0 sM)
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "Vale.X64.Bytes_Code_s.ocmp", "Vale.X64.StateLemmas.code", "Vale.X64.State.vale_state", "Vale.X64.Lemmas.fuel", "FStar.Pervasives.reveal_opaque", "Vale.X64.Machine_Semantics_s.machine_state", "Vale.X64.Machine_Semantics_s.ocmp", "Prims.bool", "Vale.X64.Machine_Semantics_s.eval_ocmp_opaque", "Prims.unit", "Vale.X64.Machine_Semantics_s.valid_ocmp_opaque" ]
[]
true
false
true
false
false
let lemma_ifElseTrue_total (ifb: ocmp) (ct cf: code) (s0: vale_state) (f0: fuel) (sM: vale_state) =
reveal_opaque (`%BS.valid_ocmp_opaque) BS.valid_ocmp_opaque; reveal_opaque (`%BS.eval_ocmp_opaque) BS.eval_ocmp_opaque
false
Vale.X64.Lemmas.fst
Vale.X64.Lemmas.increase_fuels
val increase_fuels (g: bool) (c: codes) (s0: machine_state) (f0: fuel) (sN: machine_state) (fN: fuel) : Lemma (requires eval_code_ts g (Block c) s0 f0 sN /\ f0 <= fN) (ensures eval_code_ts g (Block c) s0 fN sN) (decreases %[f0;c])
val increase_fuels (g: bool) (c: codes) (s0: machine_state) (f0: fuel) (sN: machine_state) (fN: fuel) : Lemma (requires eval_code_ts g (Block c) s0 f0 sN /\ f0 <= fN) (ensures eval_code_ts g (Block c) s0 fN sN) (decreases %[f0;c])
let rec increase_fuel (g:bool) (c:code) (s0:machine_state) (f0:fuel) (sN:machine_state) (fN:fuel) : Lemma (requires eval_code_ts g c s0 f0 sN /\ f0 <= fN) (ensures eval_code_ts g c s0 fN sN) (decreases %[f0; c]) = match c with | Ins ins -> () | Block l -> increase_fuels g l s0 f0 sN fN | IfElse cond t f -> let (s0, b0) = BS.machine_eval_ocmp s0 cond in if b0 then increase_fuel g t s0 f0 sN fN else increase_fuel g f s0 f0 sN fN | While cond c -> let (s1, b0) = BS.machine_eval_ocmp s0 cond in if b0 then ( match BS.machine_eval_code c (f0 - 1) s1 with | None -> () | Some s2 -> increase_fuel g c s1 (f0 - 1) s2 (fN - 1); if s2.BS.ms_ok then increase_fuel g (While cond c) s2 (f0 - 1) sN (fN - 1) else () ) and increase_fuels (g:bool) (c:codes) (s0:machine_state) (f0:fuel) (sN:machine_state) (fN:fuel) : Lemma (requires eval_code_ts g (Block c) s0 f0 sN /\ f0 <= fN) (ensures eval_code_ts g (Block c) s0 fN sN) (decreases %[f0; c]) = match c with | [] -> () | h::t -> ( let Some s1 = BS.machine_eval_code h f0 s0 in increase_fuel g h s0 f0 s1 fN; increase_fuels g t s1 f0 sN fN )
{ "file_name": "vale/code/arch/x64/Vale.X64.Lemmas.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 5, "end_line": 331, "start_col": 0, "start_line": 298 }
module Vale.X64.Lemmas open FStar.Mul open Vale.X64.Machine_s open Vale.X64.State open Vale.X64.StateLemmas open Vale.X64.Instruction_s open Vale.X64.Bytes_Code_s module BS = Vale.X64.Machine_Semantics_s module ME = Vale.X64.Memory #reset-options "--initial_fuel 1 --max_fuel 1 --z3rlimit 100" #restart-solver let rec lemma_eq_instr_apply_eval_args (outs:list instr_out) (args:list instr_operand) (f:instr_args_t outs args) (oprs:instr_operands_t_args args) (s1 s2:machine_state) : Lemma (requires state_eq_S true s1 s2) (ensures BS.instr_apply_eval_args outs args f oprs s1 == BS.instr_apply_eval_args outs args f oprs s2) = let open BS in lemma_heap_ignore_ghost_machine s1.BS.ms_heap s2.BS.ms_heap; match args with | [] -> () | i::args -> ( let (v, oprs) : option (instr_val_t i) & instr_operands_t_args args = match i with | IOpEx i -> let oprs = coerce oprs in (instr_eval_operand_explicit i (fst oprs) s1, snd oprs) | IOpIm i -> (instr_eval_operand_implicit i s1, coerce oprs) in let f:arrow (instr_val_t i) (instr_args_t outs args) = coerce f in match v with | None -> () | Some v -> lemma_eq_instr_apply_eval_args outs args (f v) oprs s1 s2 ) #restart-solver let rec lemma_eq_instr_apply_eval_inouts (outs inouts:list instr_out) (args:list instr_operand) (f:instr_inouts_t outs inouts args) (oprs:instr_operands_t inouts args) (s1 s2:machine_state) : Lemma (requires state_eq_S true s1 s2) (ensures BS.instr_apply_eval_inouts outs inouts args f oprs s1 == BS.instr_apply_eval_inouts outs inouts args f oprs s2) = let open BS in lemma_heap_ignore_ghost_machine s1.BS.ms_heap s2.BS.ms_heap; match inouts with | [] -> lemma_eq_instr_apply_eval_args outs args f oprs s1 s2 | (Out, i)::inouts -> let oprs = match i with | IOpEx i -> snd #(instr_operand_t i) (coerce oprs) | IOpIm i -> coerce oprs in lemma_eq_instr_apply_eval_inouts outs inouts args (coerce f) oprs s1 s2 | (InOut, i)::inouts -> ( let (v, oprs) : option (instr_val_t i) & instr_operands_t inouts args = match i with | IOpEx i -> let oprs = coerce oprs in (instr_eval_operand_explicit i (fst oprs) s1, snd oprs) | IOpIm i -> (instr_eval_operand_implicit i s1, coerce oprs) in let f:arrow (instr_val_t i) (instr_inouts_t outs inouts args) = coerce f in match v with | None -> () | Some v -> lemma_eq_instr_apply_eval_inouts outs inouts args (f v) oprs s1 s2 ) #restart-solver #push-options "--z3rlimit_factor 2" let rec lemma_eq_instr_write_outputs (outs:list instr_out) (args:list instr_operand) (vs:instr_ret_t outs) (oprs:instr_operands_t outs args) (s1_orig s1 s2_orig s2:machine_state) : Lemma (requires state_eq_S true s1_orig s2_orig /\ state_eq_S true s1 s2) (ensures state_eq_S true (BS.instr_write_outputs outs args vs oprs s1_orig s1) (BS.instr_write_outputs outs args vs oprs s2_orig s2)) = let open BS in use_machine_state_equal (); lemma_heap_ignore_ghost_machine s1.BS.ms_heap s2.BS.ms_heap; lemma_heap_ignore_ghost_machine s1_orig.BS.ms_heap s2_orig.BS.ms_heap; allow_inversion tmaddr; match outs with | [] -> () | (_, i)::outs -> ( let ((v:instr_val_t i), (vs:instr_ret_t outs)) = match outs with | [] -> (vs, ()) | _::_ -> let vs = coerce vs in (fst vs, snd vs) in match i with | IOpEx i -> let oprs = coerce oprs in let s1 = instr_write_output_explicit i v (fst oprs) s1_orig s1 in let s2 = instr_write_output_explicit i v (fst oprs) s2_orig s2 in lemma_eq_instr_write_outputs outs args vs (snd oprs) s1_orig s1 s2_orig s2 | IOpIm i -> let s1 = instr_write_output_implicit i v s1_orig s1 in let s2 = instr_write_output_implicit i v s2_orig s2 in allow_inversion operand64; allow_inversion operand128; lemma_eq_instr_write_outputs outs args vs (coerce oprs) s1_orig s1 s2_orig s2 ) #pop-options #restart-solver let eval_ins_eq_instr (inst:BS.ins) (s1 s2:machine_state) : Lemma (requires Instr? inst /\ state_eq_S true s1 s2) (ensures state_eq_S true (BS.machine_eval_ins inst s1) (BS.machine_eval_ins inst s2)) = let open BS in let Instr it oprs ann = inst in let InstrTypeRecord #outs #args #havoc_flags' i = it in lemma_eq_instr_apply_eval_inouts outs outs args (instr_eval i) oprs s1 s2; let vs = instr_apply_eval outs args (instr_eval i) oprs s1 in let hav s = match havoc_flags' with | HavocFlags -> {s with ms_flags = havoc_flags} | PreserveFlags -> s in let s1' = hav s1 in let s2' = hav s2 in match vs with | None -> () | Some vs -> lemma_eq_instr_write_outputs outs args vs oprs s1 s1' s2 s2' let eval_code_eq_instr (inst:BS.ins) (f:fuel) (s1 s2:machine_state) : Lemma (requires Instr? inst /\ state_eq_S true s1 s2) (ensures state_eq_opt true (BS.machine_eval_code (Ins inst) f s1) (BS.machine_eval_code (Ins inst) f s2)) = reveal_opaque (`%BS.machine_eval_code_ins) BS.machine_eval_code_ins; eval_ins_eq_instr inst ({s1 with BS.ms_trace = []}) ({s2 with BS.ms_trace = []}) let eval_code_eq_dealloc (inst:BS.ins) (f:fuel) (s1 s2:machine_state) : Lemma (requires Dealloc? inst /\ state_eq_S true s1 s2) (ensures state_eq_opt true (BS.machine_eval_code (Ins inst) f s1) (BS.machine_eval_code (Ins inst) f s2)) = reveal_opaque (`%BS.machine_eval_code_ins) BS.machine_eval_code_ins; use_machine_state_equal (); lemma_heap_ignore_ghost_machine s1.BS.ms_heap s2.BS.ms_heap; allow_inversion tmaddr let eval_code_eq_alloc (inst:BS.ins) (f:fuel) (s1 s2:machine_state) : Lemma (requires Alloc? inst /\ state_eq_S true s1 s2) (ensures state_eq_opt true (BS.machine_eval_code (Ins inst) f s1) (BS.machine_eval_code (Ins inst) f s2)) = reveal_opaque (`%BS.machine_eval_code_ins) BS.machine_eval_code_ins; use_machine_state_equal (); lemma_heap_ignore_ghost_machine s1.BS.ms_heap s2.BS.ms_heap; allow_inversion tmaddr let eval_code_eq_push (inst:BS.ins) (f:fuel) (s1 s2:machine_state) : Lemma (requires Push? inst /\ state_eq_S true s1 s2) (ensures state_eq_opt true (BS.machine_eval_code (Ins inst) f s1) (BS.machine_eval_code (Ins inst) f s2)) = reveal_opaque (`%BS.machine_eval_code_ins) BS.machine_eval_code_ins; use_machine_state_equal (); lemma_heap_ignore_ghost_machine s1.BS.ms_heap s2.BS.ms_heap; allow_inversion tmaddr let eval_code_eq_pop (inst:BS.ins) (f:fuel) (s1 s2:machine_state) : Lemma (requires Pop? inst /\ state_eq_S true s1 s2) (ensures state_eq_opt true (BS.machine_eval_code (Ins inst) f s1) (BS.machine_eval_code (Ins inst) f s2)) = reveal_opaque (`%BS.machine_eval_code_ins) BS.machine_eval_code_ins; use_machine_state_equal (); lemma_heap_ignore_ghost_machine s1.BS.ms_heap s2.BS.ms_heap; allow_inversion tmaddr let eval_code_eq_ins (i:BS.ins) (f:fuel) (s1 s2:machine_state) : Lemma (requires state_eq_S true s1 s2) (ensures state_eq_opt true (BS.machine_eval_code (Ins i) f s1) (BS.machine_eval_code (Ins i) f s2)) = match i with | Instr _ _ _ -> eval_code_eq_instr i f s1 s2 | Dealloc _ -> eval_code_eq_dealloc i f s1 s2 | Alloc _ -> eval_code_eq_alloc i f s1 s2 | Push _ _ -> eval_code_eq_push i f s1 s2 | Pop _ _ -> eval_code_eq_pop i f s1 s2 #reset-options "--fuel 2 --z3rlimit 30" let eval_ocmp_eq_core (g:bool) (cond:ocmp) (s:machine_state) : Lemma (ensures ( let (s1, b1) = BS.machine_eval_ocmp s cond in let (s2, b2) = BS.machine_eval_ocmp (core_state g s) cond in state_eq_S g s1 s2 /\ b1 == b2 )) = reveal_opaque (`%BS.valid_ocmp_opaque) BS.valid_ocmp_opaque; reveal_opaque (`%BS.eval_ocmp_opaque) BS.eval_ocmp_opaque; () #restart-solver let rec eval_code_eq_core (g:bool) (c:code) (f:fuel) (s:machine_state) : Lemma (ensures state_eq_opt g (BS.machine_eval_code c f s) (BS.machine_eval_code c f (core_state g s))) (decreases %[f; c]) = match c with | Ins i -> reveal_opaque (`%BS.machine_eval_code_ins) BS.machine_eval_code_ins; if g then eval_code_eq_ins i f s (core_state g s) | Block cs -> eval_codes_eq_core g cs f s | IfElse cond ct cf -> eval_ocmp_eq_core g cond s; let (s', _) = BS.machine_eval_ocmp s cond in let (t', _) = BS.machine_eval_ocmp (core_state g s) cond in eval_code_eq_core g ct f s'; eval_code_eq_core g ct f t'; eval_code_eq_core g cf f s'; eval_code_eq_core g cf f t'; () | While cond body -> eval_while_eq_core g cond body f s and eval_codes_eq_core (g:bool) (cs:codes) (f:fuel) (s:machine_state) : Lemma (ensures state_eq_opt g (BS.machine_eval_codes cs f s) (BS.machine_eval_codes cs f (core_state g s))) (decreases %[f; cs]) = match cs with | [] -> () | c'::cs' -> ( eval_code_eq_core g c' f s; match (machine_eval_code c' f s, machine_eval_code c' f (core_state g s)) with | (None, None) -> () | (Some s', Some t') -> eval_codes_eq_core g cs' f s'; eval_codes_eq_core g cs' f t' ) and eval_while_eq_core (g:bool) (cond:ocmp) (body:code) (f:fuel) (s:machine_state) : Lemma (ensures state_eq_opt g (BS.machine_eval_while cond body f s) (BS.machine_eval_while cond body f (core_state g s))) (decreases %[f; body]) = if f > 0 then ( eval_ocmp_eq_core g cond s; let (s1, _) = BS.machine_eval_ocmp s cond in let (t1, _) = BS.machine_eval_ocmp (core_state g s) cond in eval_code_eq_core g body (f - 1) s1; eval_code_eq_core g body (f - 1) t1; match (BS.machine_eval_code body (f - 1) s1, BS.machine_eval_code body (f - 1) t1) with | (None, None) -> () | (Some s2, Some t2) -> eval_while_eq_core g cond body (f - 1) s2; eval_while_eq_core g cond body (f - 1) t2; () ) let eval_code_eq_f (c:code) (f:fuel) (s1 s2:machine_state) : Lemma (requires state_eq_S false s1 s2) (ensures state_eq_opt false (BS.machine_eval_code c f s1) (BS.machine_eval_code c f s2)) [SMTPat (BS.machine_eval_code c f s1); SMTPat (BS.machine_eval_code c f s2)] = eval_code_eq_core false c f s1; eval_code_eq_core false c f s2 let eval_codes_eq_f (cs:codes) (f:fuel) (s1 s2:machine_state) : Lemma (requires state_eq_S false s1 s2) (ensures state_eq_opt false (BS.machine_eval_codes cs f s1) (BS.machine_eval_codes cs f s2)) [SMTPat (BS.machine_eval_codes cs f s1); SMTPat (BS.machine_eval_codes cs f s2)] = eval_codes_eq_core false cs f s1; eval_codes_eq_core false cs f s2 let eval_while_eq_f (cond:ocmp) (body:code) (f:fuel) (s1 s2:machine_state) : Lemma (requires state_eq_S false s1 s2) (ensures state_eq_opt false (BS.machine_eval_while cond body f s1) (BS.machine_eval_while cond body f s2)) [SMTPat (BS.machine_eval_while cond body f s1); SMTPat (BS.machine_eval_while cond body f s2)] = eval_while_eq_core false cond body f s1; eval_while_eq_core false cond body f s2 let eval_code_eq_t (c:code) (f:fuel) (s1 s2:machine_state) : Lemma (requires state_eq_S true s1 s2) (ensures state_eq_opt true (BS.machine_eval_code c f s1) (BS.machine_eval_code c f s2)) [SMTPat (BS.machine_eval_code c f s1); SMTPat (BS.machine_eval_code c f s2)] = eval_code_eq_core true c f s1; eval_code_eq_core true c f s2 let eval_codes_eq_t (cs:codes) (f:fuel) (s1 s2:machine_state) : Lemma (requires state_eq_S true s1 s2) (ensures state_eq_opt true (BS.machine_eval_codes cs f s1) (BS.machine_eval_codes cs f s2)) [SMTPat (BS.machine_eval_codes cs f s1); SMTPat (BS.machine_eval_codes cs f s2)] = eval_codes_eq_core true cs f s1; eval_codes_eq_core true cs f s2 let eval_while_eq_t (cond:ocmp) (body:code) (f:fuel) (s1 s2:machine_state) : Lemma (requires state_eq_S true s1 s2) (ensures state_eq_opt true (BS.machine_eval_while cond body f s1) (BS.machine_eval_while cond body f s2)) [SMTPat (BS.machine_eval_while cond body f s1); SMTPat (BS.machine_eval_while cond body f s2)] = eval_while_eq_core true cond body f s1; eval_while_eq_core true cond body f s2 let eval_code_ts (g:bool) (c:code) (s0:machine_state) (f0:fuel) (s1:machine_state) : Type0 = state_eq_opt g (BS.machine_eval_code c f0 s0) (Some s1)
{ "checked_file": "/", "dependencies": [ "Vale.X64.StateLemmas.fsti.checked", "Vale.X64.State.fsti.checked", "Vale.X64.Memory.fsti.checked", "Vale.X64.Machine_Semantics_s.fst.checked", "Vale.X64.Machine_s.fst.checked", "Vale.X64.Instruction_s.fsti.checked", "Vale.X64.Flags.fsti.checked", "Vale.X64.Bytes_Code_s.fst.checked", "prims.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.FunctionalExtensionality.fsti.checked" ], "interface_file": true, "source_file": "Vale.X64.Lemmas.fst" }
[ { "abbrev": true, "full_module": "Vale.X64.Memory", "short_module": "ME" }, { "abbrev": true, "full_module": "Vale.X64.Machine_Semantics_s", "short_module": "BS" }, { "abbrev": false, "full_module": "Vale.X64.Bytes_Code_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Instruction_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.StateLemmas", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.State", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Machine_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": true, "full_module": "Vale.Lib.Map16", "short_module": "Map16" }, { "abbrev": true, "full_module": "Vale.X64.Machine_Semantics_s", "short_module": "BS" }, { "abbrev": false, "full_module": "Vale.X64.Bytes_Code_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.StateLemmas", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.State", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Machine_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.HeapLemmas", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.HeapImpl", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.Heap", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 0, "max_fuel": 2, "max_ifuel": 1, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": true, "smtencoding_l_arith_repr": "native", "smtencoding_nl_arith_repr": "wrapped", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [ "smt.arith.nl=false", "smt.QI.EAGER_THRESHOLD=100", "smt.CASE_SPLIT=3" ], "z3refresh": false, "z3rlimit": 30, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
g: Prims.bool -> c: Vale.X64.Lemmas.codes -> s0: Vale.X64.StateLemmas.machine_state -> f0: Vale.X64.Lemmas.fuel -> sN: Vale.X64.StateLemmas.machine_state -> fN: Vale.X64.Lemmas.fuel -> FStar.Pervasives.Lemma (requires Vale.X64.Lemmas.eval_code_ts g (Vale.X64.Machine_s.Block c) s0 f0 sN /\ f0 <= fN) (ensures Vale.X64.Lemmas.eval_code_ts g (Vale.X64.Machine_s.Block c) s0 fN sN) (decreases %[f0;c])
FStar.Pervasives.Lemma
[ "lemma", "" ]
[ "increase_fuel", "increase_fuels" ]
[ "Prims.bool", "Vale.X64.Lemmas.codes", "Vale.X64.StateLemmas.machine_state", "Vale.X64.Lemmas.fuel", "Vale.X64.Bytes_Code_s.code_t", "Vale.X64.Machine_Semantics_s.instr_annotation", "Prims.list", "Vale.X64.Machine_Semantics_s.machine_state", "Vale.X64.Lemmas.increase_fuels", "Prims.unit", "Vale.X64.Lemmas.increase_fuel", "FStar.Pervasives.Native.option", "Vale.X64.Machine_Semantics_s.machine_eval_code", "Prims.l_and", "Vale.X64.Lemmas.eval_code_ts", "Vale.X64.Machine_s.Block", "Vale.X64.Bytes_Code_s.instruction_t", "Vale.X64.Bytes_Code_s.ocmp", "Prims.b2t", "Prims.op_LessThanOrEqual", "Prims.squash", "Prims.Nil", "FStar.Pervasives.pattern" ]
[ "mutual recursion" ]
false
false
true
false
false
let rec increase_fuels (g: bool) (c: codes) (s0: machine_state) (f0: fuel) (sN: machine_state) (fN: fuel) : Lemma (requires eval_code_ts g (Block c) s0 f0 sN /\ f0 <= fN) (ensures eval_code_ts g (Block c) s0 fN sN) (decreases %[f0;c]) =
match c with | [] -> () | h :: t -> (let Some s1 = BS.machine_eval_code h f0 s0 in increase_fuel g h s0 f0 s1 fN; increase_fuels g t s1 f0 sN fN)
false
Vale.X64.Lemmas.fst
Vale.X64.Lemmas.lemma_ifElseFalse_total
val lemma_ifElseFalse_total (ifb:ocmp) (ct:code) (cf:code) (s0:vale_state) (f0:fuel) (sM:vale_state) : Lemma (requires valid_ocmp ifb s0 /\ not (eval_ocmp s0 ifb) /\ eval_code cf ({s0 with vs_flags = havoc_flags}) f0 sM ) (ensures eval_code (IfElse ifb ct cf) s0 f0 sM )
val lemma_ifElseFalse_total (ifb:ocmp) (ct:code) (cf:code) (s0:vale_state) (f0:fuel) (sM:vale_state) : Lemma (requires valid_ocmp ifb s0 /\ not (eval_ocmp s0 ifb) /\ eval_code cf ({s0 with vs_flags = havoc_flags}) f0 sM ) (ensures eval_code (IfElse ifb ct cf) s0 f0 sM )
let lemma_ifElseFalse_total (ifb:ocmp) (ct:code) (cf:code) (s0:vale_state) (f0:fuel) (sM:vale_state) = reveal_opaque (`%BS.valid_ocmp_opaque) BS.valid_ocmp_opaque; reveal_opaque (`%BS.eval_ocmp_opaque) BS.eval_ocmp_opaque
{ "file_name": "vale/code/arch/x64/Vale.X64.Lemmas.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 59, "end_line": 370, "start_col": 0, "start_line": 368 }
module Vale.X64.Lemmas open FStar.Mul open Vale.X64.Machine_s open Vale.X64.State open Vale.X64.StateLemmas open Vale.X64.Instruction_s open Vale.X64.Bytes_Code_s module BS = Vale.X64.Machine_Semantics_s module ME = Vale.X64.Memory #reset-options "--initial_fuel 1 --max_fuel 1 --z3rlimit 100" #restart-solver let rec lemma_eq_instr_apply_eval_args (outs:list instr_out) (args:list instr_operand) (f:instr_args_t outs args) (oprs:instr_operands_t_args args) (s1 s2:machine_state) : Lemma (requires state_eq_S true s1 s2) (ensures BS.instr_apply_eval_args outs args f oprs s1 == BS.instr_apply_eval_args outs args f oprs s2) = let open BS in lemma_heap_ignore_ghost_machine s1.BS.ms_heap s2.BS.ms_heap; match args with | [] -> () | i::args -> ( let (v, oprs) : option (instr_val_t i) & instr_operands_t_args args = match i with | IOpEx i -> let oprs = coerce oprs in (instr_eval_operand_explicit i (fst oprs) s1, snd oprs) | IOpIm i -> (instr_eval_operand_implicit i s1, coerce oprs) in let f:arrow (instr_val_t i) (instr_args_t outs args) = coerce f in match v with | None -> () | Some v -> lemma_eq_instr_apply_eval_args outs args (f v) oprs s1 s2 ) #restart-solver let rec lemma_eq_instr_apply_eval_inouts (outs inouts:list instr_out) (args:list instr_operand) (f:instr_inouts_t outs inouts args) (oprs:instr_operands_t inouts args) (s1 s2:machine_state) : Lemma (requires state_eq_S true s1 s2) (ensures BS.instr_apply_eval_inouts outs inouts args f oprs s1 == BS.instr_apply_eval_inouts outs inouts args f oprs s2) = let open BS in lemma_heap_ignore_ghost_machine s1.BS.ms_heap s2.BS.ms_heap; match inouts with | [] -> lemma_eq_instr_apply_eval_args outs args f oprs s1 s2 | (Out, i)::inouts -> let oprs = match i with | IOpEx i -> snd #(instr_operand_t i) (coerce oprs) | IOpIm i -> coerce oprs in lemma_eq_instr_apply_eval_inouts outs inouts args (coerce f) oprs s1 s2 | (InOut, i)::inouts -> ( let (v, oprs) : option (instr_val_t i) & instr_operands_t inouts args = match i with | IOpEx i -> let oprs = coerce oprs in (instr_eval_operand_explicit i (fst oprs) s1, snd oprs) | IOpIm i -> (instr_eval_operand_implicit i s1, coerce oprs) in let f:arrow (instr_val_t i) (instr_inouts_t outs inouts args) = coerce f in match v with | None -> () | Some v -> lemma_eq_instr_apply_eval_inouts outs inouts args (f v) oprs s1 s2 ) #restart-solver #push-options "--z3rlimit_factor 2" let rec lemma_eq_instr_write_outputs (outs:list instr_out) (args:list instr_operand) (vs:instr_ret_t outs) (oprs:instr_operands_t outs args) (s1_orig s1 s2_orig s2:machine_state) : Lemma (requires state_eq_S true s1_orig s2_orig /\ state_eq_S true s1 s2) (ensures state_eq_S true (BS.instr_write_outputs outs args vs oprs s1_orig s1) (BS.instr_write_outputs outs args vs oprs s2_orig s2)) = let open BS in use_machine_state_equal (); lemma_heap_ignore_ghost_machine s1.BS.ms_heap s2.BS.ms_heap; lemma_heap_ignore_ghost_machine s1_orig.BS.ms_heap s2_orig.BS.ms_heap; allow_inversion tmaddr; match outs with | [] -> () | (_, i)::outs -> ( let ((v:instr_val_t i), (vs:instr_ret_t outs)) = match outs with | [] -> (vs, ()) | _::_ -> let vs = coerce vs in (fst vs, snd vs) in match i with | IOpEx i -> let oprs = coerce oprs in let s1 = instr_write_output_explicit i v (fst oprs) s1_orig s1 in let s2 = instr_write_output_explicit i v (fst oprs) s2_orig s2 in lemma_eq_instr_write_outputs outs args vs (snd oprs) s1_orig s1 s2_orig s2 | IOpIm i -> let s1 = instr_write_output_implicit i v s1_orig s1 in let s2 = instr_write_output_implicit i v s2_orig s2 in allow_inversion operand64; allow_inversion operand128; lemma_eq_instr_write_outputs outs args vs (coerce oprs) s1_orig s1 s2_orig s2 ) #pop-options #restart-solver let eval_ins_eq_instr (inst:BS.ins) (s1 s2:machine_state) : Lemma (requires Instr? inst /\ state_eq_S true s1 s2) (ensures state_eq_S true (BS.machine_eval_ins inst s1) (BS.machine_eval_ins inst s2)) = let open BS in let Instr it oprs ann = inst in let InstrTypeRecord #outs #args #havoc_flags' i = it in lemma_eq_instr_apply_eval_inouts outs outs args (instr_eval i) oprs s1 s2; let vs = instr_apply_eval outs args (instr_eval i) oprs s1 in let hav s = match havoc_flags' with | HavocFlags -> {s with ms_flags = havoc_flags} | PreserveFlags -> s in let s1' = hav s1 in let s2' = hav s2 in match vs with | None -> () | Some vs -> lemma_eq_instr_write_outputs outs args vs oprs s1 s1' s2 s2' let eval_code_eq_instr (inst:BS.ins) (f:fuel) (s1 s2:machine_state) : Lemma (requires Instr? inst /\ state_eq_S true s1 s2) (ensures state_eq_opt true (BS.machine_eval_code (Ins inst) f s1) (BS.machine_eval_code (Ins inst) f s2)) = reveal_opaque (`%BS.machine_eval_code_ins) BS.machine_eval_code_ins; eval_ins_eq_instr inst ({s1 with BS.ms_trace = []}) ({s2 with BS.ms_trace = []}) let eval_code_eq_dealloc (inst:BS.ins) (f:fuel) (s1 s2:machine_state) : Lemma (requires Dealloc? inst /\ state_eq_S true s1 s2) (ensures state_eq_opt true (BS.machine_eval_code (Ins inst) f s1) (BS.machine_eval_code (Ins inst) f s2)) = reveal_opaque (`%BS.machine_eval_code_ins) BS.machine_eval_code_ins; use_machine_state_equal (); lemma_heap_ignore_ghost_machine s1.BS.ms_heap s2.BS.ms_heap; allow_inversion tmaddr let eval_code_eq_alloc (inst:BS.ins) (f:fuel) (s1 s2:machine_state) : Lemma (requires Alloc? inst /\ state_eq_S true s1 s2) (ensures state_eq_opt true (BS.machine_eval_code (Ins inst) f s1) (BS.machine_eval_code (Ins inst) f s2)) = reveal_opaque (`%BS.machine_eval_code_ins) BS.machine_eval_code_ins; use_machine_state_equal (); lemma_heap_ignore_ghost_machine s1.BS.ms_heap s2.BS.ms_heap; allow_inversion tmaddr let eval_code_eq_push (inst:BS.ins) (f:fuel) (s1 s2:machine_state) : Lemma (requires Push? inst /\ state_eq_S true s1 s2) (ensures state_eq_opt true (BS.machine_eval_code (Ins inst) f s1) (BS.machine_eval_code (Ins inst) f s2)) = reveal_opaque (`%BS.machine_eval_code_ins) BS.machine_eval_code_ins; use_machine_state_equal (); lemma_heap_ignore_ghost_machine s1.BS.ms_heap s2.BS.ms_heap; allow_inversion tmaddr let eval_code_eq_pop (inst:BS.ins) (f:fuel) (s1 s2:machine_state) : Lemma (requires Pop? inst /\ state_eq_S true s1 s2) (ensures state_eq_opt true (BS.machine_eval_code (Ins inst) f s1) (BS.machine_eval_code (Ins inst) f s2)) = reveal_opaque (`%BS.machine_eval_code_ins) BS.machine_eval_code_ins; use_machine_state_equal (); lemma_heap_ignore_ghost_machine s1.BS.ms_heap s2.BS.ms_heap; allow_inversion tmaddr let eval_code_eq_ins (i:BS.ins) (f:fuel) (s1 s2:machine_state) : Lemma (requires state_eq_S true s1 s2) (ensures state_eq_opt true (BS.machine_eval_code (Ins i) f s1) (BS.machine_eval_code (Ins i) f s2)) = match i with | Instr _ _ _ -> eval_code_eq_instr i f s1 s2 | Dealloc _ -> eval_code_eq_dealloc i f s1 s2 | Alloc _ -> eval_code_eq_alloc i f s1 s2 | Push _ _ -> eval_code_eq_push i f s1 s2 | Pop _ _ -> eval_code_eq_pop i f s1 s2 #reset-options "--fuel 2 --z3rlimit 30" let eval_ocmp_eq_core (g:bool) (cond:ocmp) (s:machine_state) : Lemma (ensures ( let (s1, b1) = BS.machine_eval_ocmp s cond in let (s2, b2) = BS.machine_eval_ocmp (core_state g s) cond in state_eq_S g s1 s2 /\ b1 == b2 )) = reveal_opaque (`%BS.valid_ocmp_opaque) BS.valid_ocmp_opaque; reveal_opaque (`%BS.eval_ocmp_opaque) BS.eval_ocmp_opaque; () #restart-solver let rec eval_code_eq_core (g:bool) (c:code) (f:fuel) (s:machine_state) : Lemma (ensures state_eq_opt g (BS.machine_eval_code c f s) (BS.machine_eval_code c f (core_state g s))) (decreases %[f; c]) = match c with | Ins i -> reveal_opaque (`%BS.machine_eval_code_ins) BS.machine_eval_code_ins; if g then eval_code_eq_ins i f s (core_state g s) | Block cs -> eval_codes_eq_core g cs f s | IfElse cond ct cf -> eval_ocmp_eq_core g cond s; let (s', _) = BS.machine_eval_ocmp s cond in let (t', _) = BS.machine_eval_ocmp (core_state g s) cond in eval_code_eq_core g ct f s'; eval_code_eq_core g ct f t'; eval_code_eq_core g cf f s'; eval_code_eq_core g cf f t'; () | While cond body -> eval_while_eq_core g cond body f s and eval_codes_eq_core (g:bool) (cs:codes) (f:fuel) (s:machine_state) : Lemma (ensures state_eq_opt g (BS.machine_eval_codes cs f s) (BS.machine_eval_codes cs f (core_state g s))) (decreases %[f; cs]) = match cs with | [] -> () | c'::cs' -> ( eval_code_eq_core g c' f s; match (machine_eval_code c' f s, machine_eval_code c' f (core_state g s)) with | (None, None) -> () | (Some s', Some t') -> eval_codes_eq_core g cs' f s'; eval_codes_eq_core g cs' f t' ) and eval_while_eq_core (g:bool) (cond:ocmp) (body:code) (f:fuel) (s:machine_state) : Lemma (ensures state_eq_opt g (BS.machine_eval_while cond body f s) (BS.machine_eval_while cond body f (core_state g s))) (decreases %[f; body]) = if f > 0 then ( eval_ocmp_eq_core g cond s; let (s1, _) = BS.machine_eval_ocmp s cond in let (t1, _) = BS.machine_eval_ocmp (core_state g s) cond in eval_code_eq_core g body (f - 1) s1; eval_code_eq_core g body (f - 1) t1; match (BS.machine_eval_code body (f - 1) s1, BS.machine_eval_code body (f - 1) t1) with | (None, None) -> () | (Some s2, Some t2) -> eval_while_eq_core g cond body (f - 1) s2; eval_while_eq_core g cond body (f - 1) t2; () ) let eval_code_eq_f (c:code) (f:fuel) (s1 s2:machine_state) : Lemma (requires state_eq_S false s1 s2) (ensures state_eq_opt false (BS.machine_eval_code c f s1) (BS.machine_eval_code c f s2)) [SMTPat (BS.machine_eval_code c f s1); SMTPat (BS.machine_eval_code c f s2)] = eval_code_eq_core false c f s1; eval_code_eq_core false c f s2 let eval_codes_eq_f (cs:codes) (f:fuel) (s1 s2:machine_state) : Lemma (requires state_eq_S false s1 s2) (ensures state_eq_opt false (BS.machine_eval_codes cs f s1) (BS.machine_eval_codes cs f s2)) [SMTPat (BS.machine_eval_codes cs f s1); SMTPat (BS.machine_eval_codes cs f s2)] = eval_codes_eq_core false cs f s1; eval_codes_eq_core false cs f s2 let eval_while_eq_f (cond:ocmp) (body:code) (f:fuel) (s1 s2:machine_state) : Lemma (requires state_eq_S false s1 s2) (ensures state_eq_opt false (BS.machine_eval_while cond body f s1) (BS.machine_eval_while cond body f s2)) [SMTPat (BS.machine_eval_while cond body f s1); SMTPat (BS.machine_eval_while cond body f s2)] = eval_while_eq_core false cond body f s1; eval_while_eq_core false cond body f s2 let eval_code_eq_t (c:code) (f:fuel) (s1 s2:machine_state) : Lemma (requires state_eq_S true s1 s2) (ensures state_eq_opt true (BS.machine_eval_code c f s1) (BS.machine_eval_code c f s2)) [SMTPat (BS.machine_eval_code c f s1); SMTPat (BS.machine_eval_code c f s2)] = eval_code_eq_core true c f s1; eval_code_eq_core true c f s2 let eval_codes_eq_t (cs:codes) (f:fuel) (s1 s2:machine_state) : Lemma (requires state_eq_S true s1 s2) (ensures state_eq_opt true (BS.machine_eval_codes cs f s1) (BS.machine_eval_codes cs f s2)) [SMTPat (BS.machine_eval_codes cs f s1); SMTPat (BS.machine_eval_codes cs f s2)] = eval_codes_eq_core true cs f s1; eval_codes_eq_core true cs f s2 let eval_while_eq_t (cond:ocmp) (body:code) (f:fuel) (s1 s2:machine_state) : Lemma (requires state_eq_S true s1 s2) (ensures state_eq_opt true (BS.machine_eval_while cond body f s1) (BS.machine_eval_while cond body f s2)) [SMTPat (BS.machine_eval_while cond body f s1); SMTPat (BS.machine_eval_while cond body f s2)] = eval_while_eq_core true cond body f s1; eval_while_eq_core true cond body f s2 let eval_code_ts (g:bool) (c:code) (s0:machine_state) (f0:fuel) (s1:machine_state) : Type0 = state_eq_opt g (BS.machine_eval_code c f0 s0) (Some s1) let rec increase_fuel (g:bool) (c:code) (s0:machine_state) (f0:fuel) (sN:machine_state) (fN:fuel) : Lemma (requires eval_code_ts g c s0 f0 sN /\ f0 <= fN) (ensures eval_code_ts g c s0 fN sN) (decreases %[f0; c]) = match c with | Ins ins -> () | Block l -> increase_fuels g l s0 f0 sN fN | IfElse cond t f -> let (s0, b0) = BS.machine_eval_ocmp s0 cond in if b0 then increase_fuel g t s0 f0 sN fN else increase_fuel g f s0 f0 sN fN | While cond c -> let (s1, b0) = BS.machine_eval_ocmp s0 cond in if b0 then ( match BS.machine_eval_code c (f0 - 1) s1 with | None -> () | Some s2 -> increase_fuel g c s1 (f0 - 1) s2 (fN - 1); if s2.BS.ms_ok then increase_fuel g (While cond c) s2 (f0 - 1) sN (fN - 1) else () ) and increase_fuels (g:bool) (c:codes) (s0:machine_state) (f0:fuel) (sN:machine_state) (fN:fuel) : Lemma (requires eval_code_ts g (Block c) s0 f0 sN /\ f0 <= fN) (ensures eval_code_ts g (Block c) s0 fN sN) (decreases %[f0; c]) = match c with | [] -> () | h::t -> ( let Some s1 = BS.machine_eval_code h f0 s0 in increase_fuel g h s0 f0 s1 fN; increase_fuels g t s1 f0 sN fN ) let lemma_cmp_eq s o1 o2 = reveal_opaque (`%BS.eval_ocmp_opaque) BS.eval_ocmp_opaque let lemma_cmp_ne s o1 o2 = reveal_opaque (`%BS.eval_ocmp_opaque) BS.eval_ocmp_opaque let lemma_cmp_le s o1 o2 = reveal_opaque (`%BS.eval_ocmp_opaque) BS.eval_ocmp_opaque let lemma_cmp_ge s o1 o2 = reveal_opaque (`%BS.eval_ocmp_opaque) BS.eval_ocmp_opaque let lemma_cmp_lt s o1 o2 = reveal_opaque (`%BS.eval_ocmp_opaque) BS.eval_ocmp_opaque let lemma_cmp_gt s o1 o2 = reveal_opaque (`%BS.eval_ocmp_opaque) BS.eval_ocmp_opaque let lemma_valid_cmp_eq s o1 o2 = () let lemma_valid_cmp_ne s o1 o2 = () let lemma_valid_cmp_le s o1 o2 = () let lemma_valid_cmp_ge s o1 o2 = () let lemma_valid_cmp_lt s o1 o2 = () let lemma_valid_cmp_gt s o1 o2 = () let compute_merge_total (f0:fuel) (fM:fuel) = if f0 > fM then f0 else fM let lemma_merge_total (b0:codes) (s0:vale_state) (f0:fuel) (sM:vale_state) (fM:fuel) (sN:vale_state) = let f = if f0 > fM then f0 else fM in increase_fuel (codes_modifies_ghost b0) (Cons?.hd b0) (state_to_S s0) f0 (state_to_S sM) f; increase_fuel (codes_modifies_ghost b0) (Block (Cons?.tl b0)) (state_to_S sM) fM (state_to_S sN) f let lemma_empty_total (s0:vale_state) (bN:codes) = (s0, 0) let lemma_ifElse_total (ifb:ocmp) (ct:code) (cf:code) (s0:vale_state) = (eval_ocmp s0 ifb, {s0 with vs_flags = havoc_flags}, s0, 0) let lemma_havoc_flags : squash (Flags.to_fun havoc_flags == BS.havoc_flags) = assert (FStar.FunctionalExtensionality.feq (Flags.to_fun havoc_flags) BS.havoc_flags) let lemma_ifElseTrue_total (ifb:ocmp) (ct:code) (cf:code) (s0:vale_state) (f0:fuel) (sM:vale_state) = reveal_opaque (`%BS.valid_ocmp_opaque) BS.valid_ocmp_opaque; reveal_opaque (`%BS.eval_ocmp_opaque) BS.eval_ocmp_opaque
{ "checked_file": "/", "dependencies": [ "Vale.X64.StateLemmas.fsti.checked", "Vale.X64.State.fsti.checked", "Vale.X64.Memory.fsti.checked", "Vale.X64.Machine_Semantics_s.fst.checked", "Vale.X64.Machine_s.fst.checked", "Vale.X64.Instruction_s.fsti.checked", "Vale.X64.Flags.fsti.checked", "Vale.X64.Bytes_Code_s.fst.checked", "prims.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.FunctionalExtensionality.fsti.checked" ], "interface_file": true, "source_file": "Vale.X64.Lemmas.fst" }
[ { "abbrev": true, "full_module": "Vale.X64.Memory", "short_module": "ME" }, { "abbrev": true, "full_module": "Vale.X64.Machine_Semantics_s", "short_module": "BS" }, { "abbrev": false, "full_module": "Vale.X64.Bytes_Code_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Instruction_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.StateLemmas", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.State", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Machine_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": true, "full_module": "Vale.Lib.Map16", "short_module": "Map16" }, { "abbrev": true, "full_module": "Vale.X64.Machine_Semantics_s", "short_module": "BS" }, { "abbrev": false, "full_module": "Vale.X64.Bytes_Code_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.StateLemmas", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.State", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Machine_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.HeapLemmas", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.HeapImpl", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.Heap", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 0, "max_fuel": 2, "max_ifuel": 1, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": true, "smtencoding_l_arith_repr": "native", "smtencoding_nl_arith_repr": "wrapped", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [ "smt.arith.nl=false", "smt.QI.EAGER_THRESHOLD=100", "smt.CASE_SPLIT=3" ], "z3refresh": false, "z3rlimit": 30, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
ifb: Vale.X64.Bytes_Code_s.ocmp -> ct: Vale.X64.StateLemmas.code -> cf: Vale.X64.StateLemmas.code -> s0: Vale.X64.State.vale_state -> f0: Vale.X64.Lemmas.fuel -> sM: Vale.X64.State.vale_state -> FStar.Pervasives.Lemma (requires Vale.X64.Lemmas.valid_ocmp ifb s0 /\ Prims.op_Negation (Vale.X64.Lemmas.eval_ocmp s0 ifb) /\ Vale.X64.Lemmas.eval_code cf (Vale.X64.State.Mkvale_state (Mkvale_state?.vs_ok s0) (Mkvale_state?.vs_regs s0) Vale.X64.Lemmas.havoc_flags (Mkvale_state?.vs_heap s0) (Mkvale_state?.vs_stack s0) (Mkvale_state?.vs_stackTaint s0)) f0 sM) (ensures Vale.X64.Lemmas.eval_code (Vale.X64.Machine_s.IfElse ifb ct cf) s0 f0 sM)
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "Vale.X64.Bytes_Code_s.ocmp", "Vale.X64.StateLemmas.code", "Vale.X64.State.vale_state", "Vale.X64.Lemmas.fuel", "FStar.Pervasives.reveal_opaque", "Vale.X64.Machine_Semantics_s.machine_state", "Vale.X64.Machine_Semantics_s.ocmp", "Prims.bool", "Vale.X64.Machine_Semantics_s.eval_ocmp_opaque", "Prims.unit", "Vale.X64.Machine_Semantics_s.valid_ocmp_opaque" ]
[]
true
false
true
false
false
let lemma_ifElseFalse_total (ifb: ocmp) (ct cf: code) (s0: vale_state) (f0: fuel) (sM: vale_state) =
reveal_opaque (`%BS.valid_ocmp_opaque) BS.valid_ocmp_opaque; reveal_opaque (`%BS.eval_ocmp_opaque) BS.eval_ocmp_opaque
false
Vale.X64.Lemmas.fst
Vale.X64.Lemmas.lemma_while_total
val lemma_while_total (b:ocmp) (c:code) (s0:vale_state) : Ghost (vale_state & fuel) (requires True) (ensures fun (s1, f1) -> s1 == s0 /\ eval_while_inv (While b c) s1 f1 s1 )
val lemma_while_total (b:ocmp) (c:code) (s0:vale_state) : Ghost (vale_state & fuel) (requires True) (ensures fun (s1, f1) -> s1 == s0 /\ eval_while_inv (While b c) s1 f1 s1 )
let lemma_while_total (b:ocmp) (c:code) (s0:vale_state) = (s0, 0)
{ "file_name": "vale/code/arch/x64/Vale.X64.Lemmas.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 9, "end_line": 383, "start_col": 0, "start_line": 382 }
module Vale.X64.Lemmas open FStar.Mul open Vale.X64.Machine_s open Vale.X64.State open Vale.X64.StateLemmas open Vale.X64.Instruction_s open Vale.X64.Bytes_Code_s module BS = Vale.X64.Machine_Semantics_s module ME = Vale.X64.Memory #reset-options "--initial_fuel 1 --max_fuel 1 --z3rlimit 100" #restart-solver let rec lemma_eq_instr_apply_eval_args (outs:list instr_out) (args:list instr_operand) (f:instr_args_t outs args) (oprs:instr_operands_t_args args) (s1 s2:machine_state) : Lemma (requires state_eq_S true s1 s2) (ensures BS.instr_apply_eval_args outs args f oprs s1 == BS.instr_apply_eval_args outs args f oprs s2) = let open BS in lemma_heap_ignore_ghost_machine s1.BS.ms_heap s2.BS.ms_heap; match args with | [] -> () | i::args -> ( let (v, oprs) : option (instr_val_t i) & instr_operands_t_args args = match i with | IOpEx i -> let oprs = coerce oprs in (instr_eval_operand_explicit i (fst oprs) s1, snd oprs) | IOpIm i -> (instr_eval_operand_implicit i s1, coerce oprs) in let f:arrow (instr_val_t i) (instr_args_t outs args) = coerce f in match v with | None -> () | Some v -> lemma_eq_instr_apply_eval_args outs args (f v) oprs s1 s2 ) #restart-solver let rec lemma_eq_instr_apply_eval_inouts (outs inouts:list instr_out) (args:list instr_operand) (f:instr_inouts_t outs inouts args) (oprs:instr_operands_t inouts args) (s1 s2:machine_state) : Lemma (requires state_eq_S true s1 s2) (ensures BS.instr_apply_eval_inouts outs inouts args f oprs s1 == BS.instr_apply_eval_inouts outs inouts args f oprs s2) = let open BS in lemma_heap_ignore_ghost_machine s1.BS.ms_heap s2.BS.ms_heap; match inouts with | [] -> lemma_eq_instr_apply_eval_args outs args f oprs s1 s2 | (Out, i)::inouts -> let oprs = match i with | IOpEx i -> snd #(instr_operand_t i) (coerce oprs) | IOpIm i -> coerce oprs in lemma_eq_instr_apply_eval_inouts outs inouts args (coerce f) oprs s1 s2 | (InOut, i)::inouts -> ( let (v, oprs) : option (instr_val_t i) & instr_operands_t inouts args = match i with | IOpEx i -> let oprs = coerce oprs in (instr_eval_operand_explicit i (fst oprs) s1, snd oprs) | IOpIm i -> (instr_eval_operand_implicit i s1, coerce oprs) in let f:arrow (instr_val_t i) (instr_inouts_t outs inouts args) = coerce f in match v with | None -> () | Some v -> lemma_eq_instr_apply_eval_inouts outs inouts args (f v) oprs s1 s2 ) #restart-solver #push-options "--z3rlimit_factor 2" let rec lemma_eq_instr_write_outputs (outs:list instr_out) (args:list instr_operand) (vs:instr_ret_t outs) (oprs:instr_operands_t outs args) (s1_orig s1 s2_orig s2:machine_state) : Lemma (requires state_eq_S true s1_orig s2_orig /\ state_eq_S true s1 s2) (ensures state_eq_S true (BS.instr_write_outputs outs args vs oprs s1_orig s1) (BS.instr_write_outputs outs args vs oprs s2_orig s2)) = let open BS in use_machine_state_equal (); lemma_heap_ignore_ghost_machine s1.BS.ms_heap s2.BS.ms_heap; lemma_heap_ignore_ghost_machine s1_orig.BS.ms_heap s2_orig.BS.ms_heap; allow_inversion tmaddr; match outs with | [] -> () | (_, i)::outs -> ( let ((v:instr_val_t i), (vs:instr_ret_t outs)) = match outs with | [] -> (vs, ()) | _::_ -> let vs = coerce vs in (fst vs, snd vs) in match i with | IOpEx i -> let oprs = coerce oprs in let s1 = instr_write_output_explicit i v (fst oprs) s1_orig s1 in let s2 = instr_write_output_explicit i v (fst oprs) s2_orig s2 in lemma_eq_instr_write_outputs outs args vs (snd oprs) s1_orig s1 s2_orig s2 | IOpIm i -> let s1 = instr_write_output_implicit i v s1_orig s1 in let s2 = instr_write_output_implicit i v s2_orig s2 in allow_inversion operand64; allow_inversion operand128; lemma_eq_instr_write_outputs outs args vs (coerce oprs) s1_orig s1 s2_orig s2 ) #pop-options #restart-solver let eval_ins_eq_instr (inst:BS.ins) (s1 s2:machine_state) : Lemma (requires Instr? inst /\ state_eq_S true s1 s2) (ensures state_eq_S true (BS.machine_eval_ins inst s1) (BS.machine_eval_ins inst s2)) = let open BS in let Instr it oprs ann = inst in let InstrTypeRecord #outs #args #havoc_flags' i = it in lemma_eq_instr_apply_eval_inouts outs outs args (instr_eval i) oprs s1 s2; let vs = instr_apply_eval outs args (instr_eval i) oprs s1 in let hav s = match havoc_flags' with | HavocFlags -> {s with ms_flags = havoc_flags} | PreserveFlags -> s in let s1' = hav s1 in let s2' = hav s2 in match vs with | None -> () | Some vs -> lemma_eq_instr_write_outputs outs args vs oprs s1 s1' s2 s2' let eval_code_eq_instr (inst:BS.ins) (f:fuel) (s1 s2:machine_state) : Lemma (requires Instr? inst /\ state_eq_S true s1 s2) (ensures state_eq_opt true (BS.machine_eval_code (Ins inst) f s1) (BS.machine_eval_code (Ins inst) f s2)) = reveal_opaque (`%BS.machine_eval_code_ins) BS.machine_eval_code_ins; eval_ins_eq_instr inst ({s1 with BS.ms_trace = []}) ({s2 with BS.ms_trace = []}) let eval_code_eq_dealloc (inst:BS.ins) (f:fuel) (s1 s2:machine_state) : Lemma (requires Dealloc? inst /\ state_eq_S true s1 s2) (ensures state_eq_opt true (BS.machine_eval_code (Ins inst) f s1) (BS.machine_eval_code (Ins inst) f s2)) = reveal_opaque (`%BS.machine_eval_code_ins) BS.machine_eval_code_ins; use_machine_state_equal (); lemma_heap_ignore_ghost_machine s1.BS.ms_heap s2.BS.ms_heap; allow_inversion tmaddr let eval_code_eq_alloc (inst:BS.ins) (f:fuel) (s1 s2:machine_state) : Lemma (requires Alloc? inst /\ state_eq_S true s1 s2) (ensures state_eq_opt true (BS.machine_eval_code (Ins inst) f s1) (BS.machine_eval_code (Ins inst) f s2)) = reveal_opaque (`%BS.machine_eval_code_ins) BS.machine_eval_code_ins; use_machine_state_equal (); lemma_heap_ignore_ghost_machine s1.BS.ms_heap s2.BS.ms_heap; allow_inversion tmaddr let eval_code_eq_push (inst:BS.ins) (f:fuel) (s1 s2:machine_state) : Lemma (requires Push? inst /\ state_eq_S true s1 s2) (ensures state_eq_opt true (BS.machine_eval_code (Ins inst) f s1) (BS.machine_eval_code (Ins inst) f s2)) = reveal_opaque (`%BS.machine_eval_code_ins) BS.machine_eval_code_ins; use_machine_state_equal (); lemma_heap_ignore_ghost_machine s1.BS.ms_heap s2.BS.ms_heap; allow_inversion tmaddr let eval_code_eq_pop (inst:BS.ins) (f:fuel) (s1 s2:machine_state) : Lemma (requires Pop? inst /\ state_eq_S true s1 s2) (ensures state_eq_opt true (BS.machine_eval_code (Ins inst) f s1) (BS.machine_eval_code (Ins inst) f s2)) = reveal_opaque (`%BS.machine_eval_code_ins) BS.machine_eval_code_ins; use_machine_state_equal (); lemma_heap_ignore_ghost_machine s1.BS.ms_heap s2.BS.ms_heap; allow_inversion tmaddr let eval_code_eq_ins (i:BS.ins) (f:fuel) (s1 s2:machine_state) : Lemma (requires state_eq_S true s1 s2) (ensures state_eq_opt true (BS.machine_eval_code (Ins i) f s1) (BS.machine_eval_code (Ins i) f s2)) = match i with | Instr _ _ _ -> eval_code_eq_instr i f s1 s2 | Dealloc _ -> eval_code_eq_dealloc i f s1 s2 | Alloc _ -> eval_code_eq_alloc i f s1 s2 | Push _ _ -> eval_code_eq_push i f s1 s2 | Pop _ _ -> eval_code_eq_pop i f s1 s2 #reset-options "--fuel 2 --z3rlimit 30" let eval_ocmp_eq_core (g:bool) (cond:ocmp) (s:machine_state) : Lemma (ensures ( let (s1, b1) = BS.machine_eval_ocmp s cond in let (s2, b2) = BS.machine_eval_ocmp (core_state g s) cond in state_eq_S g s1 s2 /\ b1 == b2 )) = reveal_opaque (`%BS.valid_ocmp_opaque) BS.valid_ocmp_opaque; reveal_opaque (`%BS.eval_ocmp_opaque) BS.eval_ocmp_opaque; () #restart-solver let rec eval_code_eq_core (g:bool) (c:code) (f:fuel) (s:machine_state) : Lemma (ensures state_eq_opt g (BS.machine_eval_code c f s) (BS.machine_eval_code c f (core_state g s))) (decreases %[f; c]) = match c with | Ins i -> reveal_opaque (`%BS.machine_eval_code_ins) BS.machine_eval_code_ins; if g then eval_code_eq_ins i f s (core_state g s) | Block cs -> eval_codes_eq_core g cs f s | IfElse cond ct cf -> eval_ocmp_eq_core g cond s; let (s', _) = BS.machine_eval_ocmp s cond in let (t', _) = BS.machine_eval_ocmp (core_state g s) cond in eval_code_eq_core g ct f s'; eval_code_eq_core g ct f t'; eval_code_eq_core g cf f s'; eval_code_eq_core g cf f t'; () | While cond body -> eval_while_eq_core g cond body f s and eval_codes_eq_core (g:bool) (cs:codes) (f:fuel) (s:machine_state) : Lemma (ensures state_eq_opt g (BS.machine_eval_codes cs f s) (BS.machine_eval_codes cs f (core_state g s))) (decreases %[f; cs]) = match cs with | [] -> () | c'::cs' -> ( eval_code_eq_core g c' f s; match (machine_eval_code c' f s, machine_eval_code c' f (core_state g s)) with | (None, None) -> () | (Some s', Some t') -> eval_codes_eq_core g cs' f s'; eval_codes_eq_core g cs' f t' ) and eval_while_eq_core (g:bool) (cond:ocmp) (body:code) (f:fuel) (s:machine_state) : Lemma (ensures state_eq_opt g (BS.machine_eval_while cond body f s) (BS.machine_eval_while cond body f (core_state g s))) (decreases %[f; body]) = if f > 0 then ( eval_ocmp_eq_core g cond s; let (s1, _) = BS.machine_eval_ocmp s cond in let (t1, _) = BS.machine_eval_ocmp (core_state g s) cond in eval_code_eq_core g body (f - 1) s1; eval_code_eq_core g body (f - 1) t1; match (BS.machine_eval_code body (f - 1) s1, BS.machine_eval_code body (f - 1) t1) with | (None, None) -> () | (Some s2, Some t2) -> eval_while_eq_core g cond body (f - 1) s2; eval_while_eq_core g cond body (f - 1) t2; () ) let eval_code_eq_f (c:code) (f:fuel) (s1 s2:machine_state) : Lemma (requires state_eq_S false s1 s2) (ensures state_eq_opt false (BS.machine_eval_code c f s1) (BS.machine_eval_code c f s2)) [SMTPat (BS.machine_eval_code c f s1); SMTPat (BS.machine_eval_code c f s2)] = eval_code_eq_core false c f s1; eval_code_eq_core false c f s2 let eval_codes_eq_f (cs:codes) (f:fuel) (s1 s2:machine_state) : Lemma (requires state_eq_S false s1 s2) (ensures state_eq_opt false (BS.machine_eval_codes cs f s1) (BS.machine_eval_codes cs f s2)) [SMTPat (BS.machine_eval_codes cs f s1); SMTPat (BS.machine_eval_codes cs f s2)] = eval_codes_eq_core false cs f s1; eval_codes_eq_core false cs f s2 let eval_while_eq_f (cond:ocmp) (body:code) (f:fuel) (s1 s2:machine_state) : Lemma (requires state_eq_S false s1 s2) (ensures state_eq_opt false (BS.machine_eval_while cond body f s1) (BS.machine_eval_while cond body f s2)) [SMTPat (BS.machine_eval_while cond body f s1); SMTPat (BS.machine_eval_while cond body f s2)] = eval_while_eq_core false cond body f s1; eval_while_eq_core false cond body f s2 let eval_code_eq_t (c:code) (f:fuel) (s1 s2:machine_state) : Lemma (requires state_eq_S true s1 s2) (ensures state_eq_opt true (BS.machine_eval_code c f s1) (BS.machine_eval_code c f s2)) [SMTPat (BS.machine_eval_code c f s1); SMTPat (BS.machine_eval_code c f s2)] = eval_code_eq_core true c f s1; eval_code_eq_core true c f s2 let eval_codes_eq_t (cs:codes) (f:fuel) (s1 s2:machine_state) : Lemma (requires state_eq_S true s1 s2) (ensures state_eq_opt true (BS.machine_eval_codes cs f s1) (BS.machine_eval_codes cs f s2)) [SMTPat (BS.machine_eval_codes cs f s1); SMTPat (BS.machine_eval_codes cs f s2)] = eval_codes_eq_core true cs f s1; eval_codes_eq_core true cs f s2 let eval_while_eq_t (cond:ocmp) (body:code) (f:fuel) (s1 s2:machine_state) : Lemma (requires state_eq_S true s1 s2) (ensures state_eq_opt true (BS.machine_eval_while cond body f s1) (BS.machine_eval_while cond body f s2)) [SMTPat (BS.machine_eval_while cond body f s1); SMTPat (BS.machine_eval_while cond body f s2)] = eval_while_eq_core true cond body f s1; eval_while_eq_core true cond body f s2 let eval_code_ts (g:bool) (c:code) (s0:machine_state) (f0:fuel) (s1:machine_state) : Type0 = state_eq_opt g (BS.machine_eval_code c f0 s0) (Some s1) let rec increase_fuel (g:bool) (c:code) (s0:machine_state) (f0:fuel) (sN:machine_state) (fN:fuel) : Lemma (requires eval_code_ts g c s0 f0 sN /\ f0 <= fN) (ensures eval_code_ts g c s0 fN sN) (decreases %[f0; c]) = match c with | Ins ins -> () | Block l -> increase_fuels g l s0 f0 sN fN | IfElse cond t f -> let (s0, b0) = BS.machine_eval_ocmp s0 cond in if b0 then increase_fuel g t s0 f0 sN fN else increase_fuel g f s0 f0 sN fN | While cond c -> let (s1, b0) = BS.machine_eval_ocmp s0 cond in if b0 then ( match BS.machine_eval_code c (f0 - 1) s1 with | None -> () | Some s2 -> increase_fuel g c s1 (f0 - 1) s2 (fN - 1); if s2.BS.ms_ok then increase_fuel g (While cond c) s2 (f0 - 1) sN (fN - 1) else () ) and increase_fuels (g:bool) (c:codes) (s0:machine_state) (f0:fuel) (sN:machine_state) (fN:fuel) : Lemma (requires eval_code_ts g (Block c) s0 f0 sN /\ f0 <= fN) (ensures eval_code_ts g (Block c) s0 fN sN) (decreases %[f0; c]) = match c with | [] -> () | h::t -> ( let Some s1 = BS.machine_eval_code h f0 s0 in increase_fuel g h s0 f0 s1 fN; increase_fuels g t s1 f0 sN fN ) let lemma_cmp_eq s o1 o2 = reveal_opaque (`%BS.eval_ocmp_opaque) BS.eval_ocmp_opaque let lemma_cmp_ne s o1 o2 = reveal_opaque (`%BS.eval_ocmp_opaque) BS.eval_ocmp_opaque let lemma_cmp_le s o1 o2 = reveal_opaque (`%BS.eval_ocmp_opaque) BS.eval_ocmp_opaque let lemma_cmp_ge s o1 o2 = reveal_opaque (`%BS.eval_ocmp_opaque) BS.eval_ocmp_opaque let lemma_cmp_lt s o1 o2 = reveal_opaque (`%BS.eval_ocmp_opaque) BS.eval_ocmp_opaque let lemma_cmp_gt s o1 o2 = reveal_opaque (`%BS.eval_ocmp_opaque) BS.eval_ocmp_opaque let lemma_valid_cmp_eq s o1 o2 = () let lemma_valid_cmp_ne s o1 o2 = () let lemma_valid_cmp_le s o1 o2 = () let lemma_valid_cmp_ge s o1 o2 = () let lemma_valid_cmp_lt s o1 o2 = () let lemma_valid_cmp_gt s o1 o2 = () let compute_merge_total (f0:fuel) (fM:fuel) = if f0 > fM then f0 else fM let lemma_merge_total (b0:codes) (s0:vale_state) (f0:fuel) (sM:vale_state) (fM:fuel) (sN:vale_state) = let f = if f0 > fM then f0 else fM in increase_fuel (codes_modifies_ghost b0) (Cons?.hd b0) (state_to_S s0) f0 (state_to_S sM) f; increase_fuel (codes_modifies_ghost b0) (Block (Cons?.tl b0)) (state_to_S sM) fM (state_to_S sN) f let lemma_empty_total (s0:vale_state) (bN:codes) = (s0, 0) let lemma_ifElse_total (ifb:ocmp) (ct:code) (cf:code) (s0:vale_state) = (eval_ocmp s0 ifb, {s0 with vs_flags = havoc_flags}, s0, 0) let lemma_havoc_flags : squash (Flags.to_fun havoc_flags == BS.havoc_flags) = assert (FStar.FunctionalExtensionality.feq (Flags.to_fun havoc_flags) BS.havoc_flags) let lemma_ifElseTrue_total (ifb:ocmp) (ct:code) (cf:code) (s0:vale_state) (f0:fuel) (sM:vale_state) = reveal_opaque (`%BS.valid_ocmp_opaque) BS.valid_ocmp_opaque; reveal_opaque (`%BS.eval_ocmp_opaque) BS.eval_ocmp_opaque let lemma_ifElseFalse_total (ifb:ocmp) (ct:code) (cf:code) (s0:vale_state) (f0:fuel) (sM:vale_state) = reveal_opaque (`%BS.valid_ocmp_opaque) BS.valid_ocmp_opaque; reveal_opaque (`%BS.eval_ocmp_opaque) BS.eval_ocmp_opaque let eval_while_inv_temp (c:code) (s0:vale_state) (fW:fuel) (sW:vale_state) : Type0 = forall (f:nat).{:pattern BS.machine_eval_code c f (state_to_S sW)} Some? (BS.machine_eval_code c f (state_to_S sW)) ==> state_eq_opt (code_modifies_ghost c) (BS.machine_eval_code c (f + fW) (state_to_S s0)) (BS.machine_eval_code c f (state_to_S sW)) let eval_while_inv (c:code) (s0:vale_state) (fW:fuel) (sW:vale_state) : Type0 = eval_while_inv_temp c s0 fW sW
{ "checked_file": "/", "dependencies": [ "Vale.X64.StateLemmas.fsti.checked", "Vale.X64.State.fsti.checked", "Vale.X64.Memory.fsti.checked", "Vale.X64.Machine_Semantics_s.fst.checked", "Vale.X64.Machine_s.fst.checked", "Vale.X64.Instruction_s.fsti.checked", "Vale.X64.Flags.fsti.checked", "Vale.X64.Bytes_Code_s.fst.checked", "prims.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.FunctionalExtensionality.fsti.checked" ], "interface_file": true, "source_file": "Vale.X64.Lemmas.fst" }
[ { "abbrev": true, "full_module": "Vale.X64.Memory", "short_module": "ME" }, { "abbrev": true, "full_module": "Vale.X64.Machine_Semantics_s", "short_module": "BS" }, { "abbrev": false, "full_module": "Vale.X64.Bytes_Code_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Instruction_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.StateLemmas", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.State", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Machine_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": true, "full_module": "Vale.Lib.Map16", "short_module": "Map16" }, { "abbrev": true, "full_module": "Vale.X64.Machine_Semantics_s", "short_module": "BS" }, { "abbrev": false, "full_module": "Vale.X64.Bytes_Code_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.StateLemmas", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.State", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Machine_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.HeapLemmas", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.HeapImpl", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.Heap", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 0, "max_fuel": 2, "max_ifuel": 1, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": true, "smtencoding_l_arith_repr": "native", "smtencoding_nl_arith_repr": "wrapped", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [ "smt.arith.nl=false", "smt.QI.EAGER_THRESHOLD=100", "smt.CASE_SPLIT=3" ], "z3refresh": false, "z3rlimit": 30, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
b: Vale.X64.Bytes_Code_s.ocmp -> c: Vale.X64.StateLemmas.code -> s0: Vale.X64.State.vale_state -> Prims.Ghost (Vale.X64.State.vale_state * Vale.X64.Lemmas.fuel)
Prims.Ghost
[]
[]
[ "Vale.X64.Bytes_Code_s.ocmp", "Vale.X64.StateLemmas.code", "Vale.X64.State.vale_state", "FStar.Pervasives.Native.Mktuple2", "Vale.X64.Lemmas.fuel", "FStar.Pervasives.Native.tuple2" ]
[]
false
false
false
false
false
let lemma_while_total (b: ocmp) (c: code) (s0: vale_state) =
(s0, 0)
false
Vale.X64.Lemmas.fst
Vale.X64.Lemmas.eval_while_inv_temp
val eval_while_inv_temp (c: code) (s0: vale_state) (fW: fuel) (sW: vale_state) : Type0
val eval_while_inv_temp (c: code) (s0: vale_state) (fW: fuel) (sW: vale_state) : Type0
let eval_while_inv_temp (c:code) (s0:vale_state) (fW:fuel) (sW:vale_state) : Type0 = forall (f:nat).{:pattern BS.machine_eval_code c f (state_to_S sW)} Some? (BS.machine_eval_code c f (state_to_S sW)) ==> state_eq_opt (code_modifies_ghost c) (BS.machine_eval_code c (f + fW) (state_to_S s0)) (BS.machine_eval_code c f (state_to_S sW))
{ "file_name": "vale/code/arch/x64/Vale.X64.Lemmas.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 48, "end_line": 377, "start_col": 0, "start_line": 372 }
module Vale.X64.Lemmas open FStar.Mul open Vale.X64.Machine_s open Vale.X64.State open Vale.X64.StateLemmas open Vale.X64.Instruction_s open Vale.X64.Bytes_Code_s module BS = Vale.X64.Machine_Semantics_s module ME = Vale.X64.Memory #reset-options "--initial_fuel 1 --max_fuel 1 --z3rlimit 100" #restart-solver let rec lemma_eq_instr_apply_eval_args (outs:list instr_out) (args:list instr_operand) (f:instr_args_t outs args) (oprs:instr_operands_t_args args) (s1 s2:machine_state) : Lemma (requires state_eq_S true s1 s2) (ensures BS.instr_apply_eval_args outs args f oprs s1 == BS.instr_apply_eval_args outs args f oprs s2) = let open BS in lemma_heap_ignore_ghost_machine s1.BS.ms_heap s2.BS.ms_heap; match args with | [] -> () | i::args -> ( let (v, oprs) : option (instr_val_t i) & instr_operands_t_args args = match i with | IOpEx i -> let oprs = coerce oprs in (instr_eval_operand_explicit i (fst oprs) s1, snd oprs) | IOpIm i -> (instr_eval_operand_implicit i s1, coerce oprs) in let f:arrow (instr_val_t i) (instr_args_t outs args) = coerce f in match v with | None -> () | Some v -> lemma_eq_instr_apply_eval_args outs args (f v) oprs s1 s2 ) #restart-solver let rec lemma_eq_instr_apply_eval_inouts (outs inouts:list instr_out) (args:list instr_operand) (f:instr_inouts_t outs inouts args) (oprs:instr_operands_t inouts args) (s1 s2:machine_state) : Lemma (requires state_eq_S true s1 s2) (ensures BS.instr_apply_eval_inouts outs inouts args f oprs s1 == BS.instr_apply_eval_inouts outs inouts args f oprs s2) = let open BS in lemma_heap_ignore_ghost_machine s1.BS.ms_heap s2.BS.ms_heap; match inouts with | [] -> lemma_eq_instr_apply_eval_args outs args f oprs s1 s2 | (Out, i)::inouts -> let oprs = match i with | IOpEx i -> snd #(instr_operand_t i) (coerce oprs) | IOpIm i -> coerce oprs in lemma_eq_instr_apply_eval_inouts outs inouts args (coerce f) oprs s1 s2 | (InOut, i)::inouts -> ( let (v, oprs) : option (instr_val_t i) & instr_operands_t inouts args = match i with | IOpEx i -> let oprs = coerce oprs in (instr_eval_operand_explicit i (fst oprs) s1, snd oprs) | IOpIm i -> (instr_eval_operand_implicit i s1, coerce oprs) in let f:arrow (instr_val_t i) (instr_inouts_t outs inouts args) = coerce f in match v with | None -> () | Some v -> lemma_eq_instr_apply_eval_inouts outs inouts args (f v) oprs s1 s2 ) #restart-solver #push-options "--z3rlimit_factor 2" let rec lemma_eq_instr_write_outputs (outs:list instr_out) (args:list instr_operand) (vs:instr_ret_t outs) (oprs:instr_operands_t outs args) (s1_orig s1 s2_orig s2:machine_state) : Lemma (requires state_eq_S true s1_orig s2_orig /\ state_eq_S true s1 s2) (ensures state_eq_S true (BS.instr_write_outputs outs args vs oprs s1_orig s1) (BS.instr_write_outputs outs args vs oprs s2_orig s2)) = let open BS in use_machine_state_equal (); lemma_heap_ignore_ghost_machine s1.BS.ms_heap s2.BS.ms_heap; lemma_heap_ignore_ghost_machine s1_orig.BS.ms_heap s2_orig.BS.ms_heap; allow_inversion tmaddr; match outs with | [] -> () | (_, i)::outs -> ( let ((v:instr_val_t i), (vs:instr_ret_t outs)) = match outs with | [] -> (vs, ()) | _::_ -> let vs = coerce vs in (fst vs, snd vs) in match i with | IOpEx i -> let oprs = coerce oprs in let s1 = instr_write_output_explicit i v (fst oprs) s1_orig s1 in let s2 = instr_write_output_explicit i v (fst oprs) s2_orig s2 in lemma_eq_instr_write_outputs outs args vs (snd oprs) s1_orig s1 s2_orig s2 | IOpIm i -> let s1 = instr_write_output_implicit i v s1_orig s1 in let s2 = instr_write_output_implicit i v s2_orig s2 in allow_inversion operand64; allow_inversion operand128; lemma_eq_instr_write_outputs outs args vs (coerce oprs) s1_orig s1 s2_orig s2 ) #pop-options #restart-solver let eval_ins_eq_instr (inst:BS.ins) (s1 s2:machine_state) : Lemma (requires Instr? inst /\ state_eq_S true s1 s2) (ensures state_eq_S true (BS.machine_eval_ins inst s1) (BS.machine_eval_ins inst s2)) = let open BS in let Instr it oprs ann = inst in let InstrTypeRecord #outs #args #havoc_flags' i = it in lemma_eq_instr_apply_eval_inouts outs outs args (instr_eval i) oprs s1 s2; let vs = instr_apply_eval outs args (instr_eval i) oprs s1 in let hav s = match havoc_flags' with | HavocFlags -> {s with ms_flags = havoc_flags} | PreserveFlags -> s in let s1' = hav s1 in let s2' = hav s2 in match vs with | None -> () | Some vs -> lemma_eq_instr_write_outputs outs args vs oprs s1 s1' s2 s2' let eval_code_eq_instr (inst:BS.ins) (f:fuel) (s1 s2:machine_state) : Lemma (requires Instr? inst /\ state_eq_S true s1 s2) (ensures state_eq_opt true (BS.machine_eval_code (Ins inst) f s1) (BS.machine_eval_code (Ins inst) f s2)) = reveal_opaque (`%BS.machine_eval_code_ins) BS.machine_eval_code_ins; eval_ins_eq_instr inst ({s1 with BS.ms_trace = []}) ({s2 with BS.ms_trace = []}) let eval_code_eq_dealloc (inst:BS.ins) (f:fuel) (s1 s2:machine_state) : Lemma (requires Dealloc? inst /\ state_eq_S true s1 s2) (ensures state_eq_opt true (BS.machine_eval_code (Ins inst) f s1) (BS.machine_eval_code (Ins inst) f s2)) = reveal_opaque (`%BS.machine_eval_code_ins) BS.machine_eval_code_ins; use_machine_state_equal (); lemma_heap_ignore_ghost_machine s1.BS.ms_heap s2.BS.ms_heap; allow_inversion tmaddr let eval_code_eq_alloc (inst:BS.ins) (f:fuel) (s1 s2:machine_state) : Lemma (requires Alloc? inst /\ state_eq_S true s1 s2) (ensures state_eq_opt true (BS.machine_eval_code (Ins inst) f s1) (BS.machine_eval_code (Ins inst) f s2)) = reveal_opaque (`%BS.machine_eval_code_ins) BS.machine_eval_code_ins; use_machine_state_equal (); lemma_heap_ignore_ghost_machine s1.BS.ms_heap s2.BS.ms_heap; allow_inversion tmaddr let eval_code_eq_push (inst:BS.ins) (f:fuel) (s1 s2:machine_state) : Lemma (requires Push? inst /\ state_eq_S true s1 s2) (ensures state_eq_opt true (BS.machine_eval_code (Ins inst) f s1) (BS.machine_eval_code (Ins inst) f s2)) = reveal_opaque (`%BS.machine_eval_code_ins) BS.machine_eval_code_ins; use_machine_state_equal (); lemma_heap_ignore_ghost_machine s1.BS.ms_heap s2.BS.ms_heap; allow_inversion tmaddr let eval_code_eq_pop (inst:BS.ins) (f:fuel) (s1 s2:machine_state) : Lemma (requires Pop? inst /\ state_eq_S true s1 s2) (ensures state_eq_opt true (BS.machine_eval_code (Ins inst) f s1) (BS.machine_eval_code (Ins inst) f s2)) = reveal_opaque (`%BS.machine_eval_code_ins) BS.machine_eval_code_ins; use_machine_state_equal (); lemma_heap_ignore_ghost_machine s1.BS.ms_heap s2.BS.ms_heap; allow_inversion tmaddr let eval_code_eq_ins (i:BS.ins) (f:fuel) (s1 s2:machine_state) : Lemma (requires state_eq_S true s1 s2) (ensures state_eq_opt true (BS.machine_eval_code (Ins i) f s1) (BS.machine_eval_code (Ins i) f s2)) = match i with | Instr _ _ _ -> eval_code_eq_instr i f s1 s2 | Dealloc _ -> eval_code_eq_dealloc i f s1 s2 | Alloc _ -> eval_code_eq_alloc i f s1 s2 | Push _ _ -> eval_code_eq_push i f s1 s2 | Pop _ _ -> eval_code_eq_pop i f s1 s2 #reset-options "--fuel 2 --z3rlimit 30" let eval_ocmp_eq_core (g:bool) (cond:ocmp) (s:machine_state) : Lemma (ensures ( let (s1, b1) = BS.machine_eval_ocmp s cond in let (s2, b2) = BS.machine_eval_ocmp (core_state g s) cond in state_eq_S g s1 s2 /\ b1 == b2 )) = reveal_opaque (`%BS.valid_ocmp_opaque) BS.valid_ocmp_opaque; reveal_opaque (`%BS.eval_ocmp_opaque) BS.eval_ocmp_opaque; () #restart-solver let rec eval_code_eq_core (g:bool) (c:code) (f:fuel) (s:machine_state) : Lemma (ensures state_eq_opt g (BS.machine_eval_code c f s) (BS.machine_eval_code c f (core_state g s))) (decreases %[f; c]) = match c with | Ins i -> reveal_opaque (`%BS.machine_eval_code_ins) BS.machine_eval_code_ins; if g then eval_code_eq_ins i f s (core_state g s) | Block cs -> eval_codes_eq_core g cs f s | IfElse cond ct cf -> eval_ocmp_eq_core g cond s; let (s', _) = BS.machine_eval_ocmp s cond in let (t', _) = BS.machine_eval_ocmp (core_state g s) cond in eval_code_eq_core g ct f s'; eval_code_eq_core g ct f t'; eval_code_eq_core g cf f s'; eval_code_eq_core g cf f t'; () | While cond body -> eval_while_eq_core g cond body f s and eval_codes_eq_core (g:bool) (cs:codes) (f:fuel) (s:machine_state) : Lemma (ensures state_eq_opt g (BS.machine_eval_codes cs f s) (BS.machine_eval_codes cs f (core_state g s))) (decreases %[f; cs]) = match cs with | [] -> () | c'::cs' -> ( eval_code_eq_core g c' f s; match (machine_eval_code c' f s, machine_eval_code c' f (core_state g s)) with | (None, None) -> () | (Some s', Some t') -> eval_codes_eq_core g cs' f s'; eval_codes_eq_core g cs' f t' ) and eval_while_eq_core (g:bool) (cond:ocmp) (body:code) (f:fuel) (s:machine_state) : Lemma (ensures state_eq_opt g (BS.machine_eval_while cond body f s) (BS.machine_eval_while cond body f (core_state g s))) (decreases %[f; body]) = if f > 0 then ( eval_ocmp_eq_core g cond s; let (s1, _) = BS.machine_eval_ocmp s cond in let (t1, _) = BS.machine_eval_ocmp (core_state g s) cond in eval_code_eq_core g body (f - 1) s1; eval_code_eq_core g body (f - 1) t1; match (BS.machine_eval_code body (f - 1) s1, BS.machine_eval_code body (f - 1) t1) with | (None, None) -> () | (Some s2, Some t2) -> eval_while_eq_core g cond body (f - 1) s2; eval_while_eq_core g cond body (f - 1) t2; () ) let eval_code_eq_f (c:code) (f:fuel) (s1 s2:machine_state) : Lemma (requires state_eq_S false s1 s2) (ensures state_eq_opt false (BS.machine_eval_code c f s1) (BS.machine_eval_code c f s2)) [SMTPat (BS.machine_eval_code c f s1); SMTPat (BS.machine_eval_code c f s2)] = eval_code_eq_core false c f s1; eval_code_eq_core false c f s2 let eval_codes_eq_f (cs:codes) (f:fuel) (s1 s2:machine_state) : Lemma (requires state_eq_S false s1 s2) (ensures state_eq_opt false (BS.machine_eval_codes cs f s1) (BS.machine_eval_codes cs f s2)) [SMTPat (BS.machine_eval_codes cs f s1); SMTPat (BS.machine_eval_codes cs f s2)] = eval_codes_eq_core false cs f s1; eval_codes_eq_core false cs f s2 let eval_while_eq_f (cond:ocmp) (body:code) (f:fuel) (s1 s2:machine_state) : Lemma (requires state_eq_S false s1 s2) (ensures state_eq_opt false (BS.machine_eval_while cond body f s1) (BS.machine_eval_while cond body f s2)) [SMTPat (BS.machine_eval_while cond body f s1); SMTPat (BS.machine_eval_while cond body f s2)] = eval_while_eq_core false cond body f s1; eval_while_eq_core false cond body f s2 let eval_code_eq_t (c:code) (f:fuel) (s1 s2:machine_state) : Lemma (requires state_eq_S true s1 s2) (ensures state_eq_opt true (BS.machine_eval_code c f s1) (BS.machine_eval_code c f s2)) [SMTPat (BS.machine_eval_code c f s1); SMTPat (BS.machine_eval_code c f s2)] = eval_code_eq_core true c f s1; eval_code_eq_core true c f s2 let eval_codes_eq_t (cs:codes) (f:fuel) (s1 s2:machine_state) : Lemma (requires state_eq_S true s1 s2) (ensures state_eq_opt true (BS.machine_eval_codes cs f s1) (BS.machine_eval_codes cs f s2)) [SMTPat (BS.machine_eval_codes cs f s1); SMTPat (BS.machine_eval_codes cs f s2)] = eval_codes_eq_core true cs f s1; eval_codes_eq_core true cs f s2 let eval_while_eq_t (cond:ocmp) (body:code) (f:fuel) (s1 s2:machine_state) : Lemma (requires state_eq_S true s1 s2) (ensures state_eq_opt true (BS.machine_eval_while cond body f s1) (BS.machine_eval_while cond body f s2)) [SMTPat (BS.machine_eval_while cond body f s1); SMTPat (BS.machine_eval_while cond body f s2)] = eval_while_eq_core true cond body f s1; eval_while_eq_core true cond body f s2 let eval_code_ts (g:bool) (c:code) (s0:machine_state) (f0:fuel) (s1:machine_state) : Type0 = state_eq_opt g (BS.machine_eval_code c f0 s0) (Some s1) let rec increase_fuel (g:bool) (c:code) (s0:machine_state) (f0:fuel) (sN:machine_state) (fN:fuel) : Lemma (requires eval_code_ts g c s0 f0 sN /\ f0 <= fN) (ensures eval_code_ts g c s0 fN sN) (decreases %[f0; c]) = match c with | Ins ins -> () | Block l -> increase_fuels g l s0 f0 sN fN | IfElse cond t f -> let (s0, b0) = BS.machine_eval_ocmp s0 cond in if b0 then increase_fuel g t s0 f0 sN fN else increase_fuel g f s0 f0 sN fN | While cond c -> let (s1, b0) = BS.machine_eval_ocmp s0 cond in if b0 then ( match BS.machine_eval_code c (f0 - 1) s1 with | None -> () | Some s2 -> increase_fuel g c s1 (f0 - 1) s2 (fN - 1); if s2.BS.ms_ok then increase_fuel g (While cond c) s2 (f0 - 1) sN (fN - 1) else () ) and increase_fuels (g:bool) (c:codes) (s0:machine_state) (f0:fuel) (sN:machine_state) (fN:fuel) : Lemma (requires eval_code_ts g (Block c) s0 f0 sN /\ f0 <= fN) (ensures eval_code_ts g (Block c) s0 fN sN) (decreases %[f0; c]) = match c with | [] -> () | h::t -> ( let Some s1 = BS.machine_eval_code h f0 s0 in increase_fuel g h s0 f0 s1 fN; increase_fuels g t s1 f0 sN fN ) let lemma_cmp_eq s o1 o2 = reveal_opaque (`%BS.eval_ocmp_opaque) BS.eval_ocmp_opaque let lemma_cmp_ne s o1 o2 = reveal_opaque (`%BS.eval_ocmp_opaque) BS.eval_ocmp_opaque let lemma_cmp_le s o1 o2 = reveal_opaque (`%BS.eval_ocmp_opaque) BS.eval_ocmp_opaque let lemma_cmp_ge s o1 o2 = reveal_opaque (`%BS.eval_ocmp_opaque) BS.eval_ocmp_opaque let lemma_cmp_lt s o1 o2 = reveal_opaque (`%BS.eval_ocmp_opaque) BS.eval_ocmp_opaque let lemma_cmp_gt s o1 o2 = reveal_opaque (`%BS.eval_ocmp_opaque) BS.eval_ocmp_opaque let lemma_valid_cmp_eq s o1 o2 = () let lemma_valid_cmp_ne s o1 o2 = () let lemma_valid_cmp_le s o1 o2 = () let lemma_valid_cmp_ge s o1 o2 = () let lemma_valid_cmp_lt s o1 o2 = () let lemma_valid_cmp_gt s o1 o2 = () let compute_merge_total (f0:fuel) (fM:fuel) = if f0 > fM then f0 else fM let lemma_merge_total (b0:codes) (s0:vale_state) (f0:fuel) (sM:vale_state) (fM:fuel) (sN:vale_state) = let f = if f0 > fM then f0 else fM in increase_fuel (codes_modifies_ghost b0) (Cons?.hd b0) (state_to_S s0) f0 (state_to_S sM) f; increase_fuel (codes_modifies_ghost b0) (Block (Cons?.tl b0)) (state_to_S sM) fM (state_to_S sN) f let lemma_empty_total (s0:vale_state) (bN:codes) = (s0, 0) let lemma_ifElse_total (ifb:ocmp) (ct:code) (cf:code) (s0:vale_state) = (eval_ocmp s0 ifb, {s0 with vs_flags = havoc_flags}, s0, 0) let lemma_havoc_flags : squash (Flags.to_fun havoc_flags == BS.havoc_flags) = assert (FStar.FunctionalExtensionality.feq (Flags.to_fun havoc_flags) BS.havoc_flags) let lemma_ifElseTrue_total (ifb:ocmp) (ct:code) (cf:code) (s0:vale_state) (f0:fuel) (sM:vale_state) = reveal_opaque (`%BS.valid_ocmp_opaque) BS.valid_ocmp_opaque; reveal_opaque (`%BS.eval_ocmp_opaque) BS.eval_ocmp_opaque let lemma_ifElseFalse_total (ifb:ocmp) (ct:code) (cf:code) (s0:vale_state) (f0:fuel) (sM:vale_state) = reveal_opaque (`%BS.valid_ocmp_opaque) BS.valid_ocmp_opaque; reveal_opaque (`%BS.eval_ocmp_opaque) BS.eval_ocmp_opaque
{ "checked_file": "/", "dependencies": [ "Vale.X64.StateLemmas.fsti.checked", "Vale.X64.State.fsti.checked", "Vale.X64.Memory.fsti.checked", "Vale.X64.Machine_Semantics_s.fst.checked", "Vale.X64.Machine_s.fst.checked", "Vale.X64.Instruction_s.fsti.checked", "Vale.X64.Flags.fsti.checked", "Vale.X64.Bytes_Code_s.fst.checked", "prims.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.FunctionalExtensionality.fsti.checked" ], "interface_file": true, "source_file": "Vale.X64.Lemmas.fst" }
[ { "abbrev": true, "full_module": "Vale.X64.Memory", "short_module": "ME" }, { "abbrev": true, "full_module": "Vale.X64.Machine_Semantics_s", "short_module": "BS" }, { "abbrev": false, "full_module": "Vale.X64.Bytes_Code_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Instruction_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.StateLemmas", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.State", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Machine_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": true, "full_module": "Vale.Lib.Map16", "short_module": "Map16" }, { "abbrev": true, "full_module": "Vale.X64.Machine_Semantics_s", "short_module": "BS" }, { "abbrev": false, "full_module": "Vale.X64.Bytes_Code_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.StateLemmas", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.State", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Machine_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.HeapLemmas", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.HeapImpl", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.Heap", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 0, "max_fuel": 2, "max_ifuel": 1, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": true, "smtencoding_l_arith_repr": "native", "smtencoding_nl_arith_repr": "wrapped", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [ "smt.arith.nl=false", "smt.QI.EAGER_THRESHOLD=100", "smt.CASE_SPLIT=3" ], "z3refresh": false, "z3rlimit": 30, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
c: Vale.X64.StateLemmas.code -> s0: Vale.X64.State.vale_state -> fW: Vale.X64.Lemmas.fuel -> sW: Vale.X64.State.vale_state -> Type0
Prims.Tot
[ "total" ]
[]
[ "Vale.X64.StateLemmas.code", "Vale.X64.State.vale_state", "Vale.X64.Lemmas.fuel", "Prims.l_Forall", "Prims.nat", "Prims.l_imp", "Prims.b2t", "FStar.Pervasives.Native.uu___is_Some", "Vale.X64.Machine_Semantics_s.machine_state", "Vale.X64.Machine_Semantics_s.machine_eval_code", "Vale.X64.StateLemmas.state_to_S", "Vale.X64.Lemmas.state_eq_opt", "Vale.X64.Lemmas.code_modifies_ghost", "Prims.op_Addition" ]
[]
false
false
false
true
true
let eval_while_inv_temp (c: code) (s0: vale_state) (fW: fuel) (sW: vale_state) : Type0 =
forall (f: nat). {:pattern BS.machine_eval_code c f (state_to_S sW)} Some? (BS.machine_eval_code c f (state_to_S sW)) ==> state_eq_opt (code_modifies_ghost c) (BS.machine_eval_code c (f + fW) (state_to_S s0)) (BS.machine_eval_code c f (state_to_S sW))
false
prims.fst
Prims.auto_squash
val auto_squash : p: Type -> Type0
let auto_squash (p: Type) = squash p
{ "file_name": "ulib/prims.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 36, "end_line": 109, "start_col": 0, "start_line": 109 }
(* Copyright 2008-2020 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 Prims /// This module is implicitly opened in the scope of all other modules. /// /// It provides the very basic primitives on which F* is /// built, including the definition of total functions, the basic /// logical connectives, the PURE and GHOST effects and the like. /// /// While some of the primitives have logical significance, others are /// define various conveniences in the language, e.g., type of /// attributes. (***** Begin trusted primitives *****) (** Primitives up to the definition of the GTot effect are trusted Beyond that all definitions are fully verified *) (** Type of attributes *) assume new type attribute : Type0 (** An attribute indicating that some definition must be processed by the Dijkstra monads for free construction *) assume val cps:attribute (** A predicate to express when a type supports decidable equality The type-checker emits axioms for [hasEq] for each inductive type *) assume type hasEq : Type -> GTot Type0 (** A convenient abbreviation, [eqtype] is the type of types in universe 0 which support decidable equality *) type eqtype = a: Type0{hasEq a} (** [bool] is a two element type with elements [true] and [false]. We assume it is primitive, for convenient interop with other languages, although it could easily be defined as an inductive type with two cases, [BTrue | BFalse] *) assume new type bool : eqtype (** [empty] is the empty inductive type. The type with no inhabitants represents logical falsehood. Note, [empty] is seldom used directly in F*. We instead use its "squashed" variant, [False], see below. *) type empty = (** [trivial] is the singleton inductive type---it is trivially inhabited. Like [empty], [trivial] is seldom used. We instead use its "squashed" variants, [True] *) type trivial = | T (** [unit]: another singleton type, with its only inhabitant written [()] we assume it is primitive, for convenient interop with other languages *) assume new type unit : eqtype (** [squash p] is a central type in F*---[squash p] is the proof irrelevant analog of [p] and is represented as a unit refinement. Squashed proofs are typically discharged using an SMT solver, without any proof terms explicitly reconstructed. As such, one way to think of [squash p] is as the type of properties proven using classical axioms without building proof terms. Note, [squash p] is just a unit refinement, it resides in universe 0, lowering the universe of [p]. From this perspective, one may also see [squash] as a coercion down to universe 0. The type is marked [tac_opaque] to indicate to Meta-F* that instances of [squash] should not be unfolded when evaluating tactics (since many optimizations in F*'s SMT encoding rely specifically on occurrences of [squash]. See FStar.Squash for various ways of manipulating squashed types. *) [@@ "tac_opaque"] type squash (p: Type) : Type0 = x: unit{p} (** [auto_squash] is equivalent to [squash]. However, F* will automatically insert `auto_squash` when simplifying terms, converting terms of the form `p /\ True` to `auto_squash p`. We distinguish these automatically inserted squashes from explicit, user-written squashes. A user should not have to manipulate [auto_squash] at all, except in rare circumstances when writing tactics to process proofs that have already been partially simplified by F*'s simplifier.
{ "checked_file": "/", "dependencies": [], "interface_file": false, "source_file": "prims.fst" }
[ { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": 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: Type -> Type0
Prims.Tot
[ "total" ]
[]
[ "Prims.squash" ]
[]
false
false
false
true
true
let auto_squash (p: Type) =
squash p
false
prims.fst
Prims.l_True
val l_True:logical
val l_True:logical
let l_True:logical = squash trivial
{ "file_name": "ulib/prims.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 35, "end_line": 132, "start_col": 0, "start_line": 132 }
(* Copyright 2008-2020 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 Prims /// This module is implicitly opened in the scope of all other modules. /// /// It provides the very basic primitives on which F* is /// built, including the definition of total functions, the basic /// logical connectives, the PURE and GHOST effects and the like. /// /// While some of the primitives have logical significance, others are /// define various conveniences in the language, e.g., type of /// attributes. (***** Begin trusted primitives *****) (** Primitives up to the definition of the GTot effect are trusted Beyond that all definitions are fully verified *) (** Type of attributes *) assume new type attribute : Type0 (** An attribute indicating that some definition must be processed by the Dijkstra monads for free construction *) assume val cps:attribute (** A predicate to express when a type supports decidable equality The type-checker emits axioms for [hasEq] for each inductive type *) assume type hasEq : Type -> GTot Type0 (** A convenient abbreviation, [eqtype] is the type of types in universe 0 which support decidable equality *) type eqtype = a: Type0{hasEq a} (** [bool] is a two element type with elements [true] and [false]. We assume it is primitive, for convenient interop with other languages, although it could easily be defined as an inductive type with two cases, [BTrue | BFalse] *) assume new type bool : eqtype (** [empty] is the empty inductive type. The type with no inhabitants represents logical falsehood. Note, [empty] is seldom used directly in F*. We instead use its "squashed" variant, [False], see below. *) type empty = (** [trivial] is the singleton inductive type---it is trivially inhabited. Like [empty], [trivial] is seldom used. We instead use its "squashed" variants, [True] *) type trivial = | T (** [unit]: another singleton type, with its only inhabitant written [()] we assume it is primitive, for convenient interop with other languages *) assume new type unit : eqtype (** [squash p] is a central type in F*---[squash p] is the proof irrelevant analog of [p] and is represented as a unit refinement. Squashed proofs are typically discharged using an SMT solver, without any proof terms explicitly reconstructed. As such, one way to think of [squash p] is as the type of properties proven using classical axioms without building proof terms. Note, [squash p] is just a unit refinement, it resides in universe 0, lowering the universe of [p]. From this perspective, one may also see [squash] as a coercion down to universe 0. The type is marked [tac_opaque] to indicate to Meta-F* that instances of [squash] should not be unfolded when evaluating tactics (since many optimizations in F*'s SMT encoding rely specifically on occurrences of [squash]. See FStar.Squash for various ways of manipulating squashed types. *) [@@ "tac_opaque"] type squash (p: Type) : Type0 = x: unit{p} (** [auto_squash] is equivalent to [squash]. However, F* will automatically insert `auto_squash` when simplifying terms, converting terms of the form `p /\ True` to `auto_squash p`. We distinguish these automatically inserted squashes from explicit, user-written squashes. A user should not have to manipulate [auto_squash] at all, except in rare circumstances when writing tactics to process proofs that have already been partially simplified by F*'s simplifier. *) let auto_squash (p: Type) = squash p (** The [logical] type is transitionary. It is just an abbreviation for [Type0], but is used to classify uses of the basic squashed logical connectives that follow. Some day, we plan to remove the [logical] type, replacing it with [prop] (also defined below). The type is marked [private] to intentionally prevent user code from referencing this type, hopefully easing the removal of [logical] in the future. *) private type logical = Type0 (** An attribute indicating that a symbol is an smt theory symbol and hence may not be used in smt patterns. The typechecker warns if such symbols are used in patterns *) assume val smt_theory_symbol:attribute (** [l_True] has a special bit of syntactic sugar. It is written just as "True" and rendered in the ide as [True]. It is a squashed version of constructive truth, [trivial]. *)
{ "checked_file": "/", "dependencies": [], "interface_file": false, "source_file": "prims.fst" }
[ { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": 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.logical
Prims.Tot
[ "total" ]
[]
[ "Prims.squash", "Prims.trivial" ]
[]
false
false
false
true
true
let l_True:logical =
squash trivial
false
prims.fst
Prims.l_False
val l_False:logical
val l_False:logical
let l_False:logical = squash empty
{ "file_name": "ulib/prims.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 34, "end_line": 138, "start_col": 0, "start_line": 138 }
(* Copyright 2008-2020 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 Prims /// This module is implicitly opened in the scope of all other modules. /// /// It provides the very basic primitives on which F* is /// built, including the definition of total functions, the basic /// logical connectives, the PURE and GHOST effects and the like. /// /// While some of the primitives have logical significance, others are /// define various conveniences in the language, e.g., type of /// attributes. (***** Begin trusted primitives *****) (** Primitives up to the definition of the GTot effect are trusted Beyond that all definitions are fully verified *) (** Type of attributes *) assume new type attribute : Type0 (** An attribute indicating that some definition must be processed by the Dijkstra monads for free construction *) assume val cps:attribute (** A predicate to express when a type supports decidable equality The type-checker emits axioms for [hasEq] for each inductive type *) assume type hasEq : Type -> GTot Type0 (** A convenient abbreviation, [eqtype] is the type of types in universe 0 which support decidable equality *) type eqtype = a: Type0{hasEq a} (** [bool] is a two element type with elements [true] and [false]. We assume it is primitive, for convenient interop with other languages, although it could easily be defined as an inductive type with two cases, [BTrue | BFalse] *) assume new type bool : eqtype (** [empty] is the empty inductive type. The type with no inhabitants represents logical falsehood. Note, [empty] is seldom used directly in F*. We instead use its "squashed" variant, [False], see below. *) type empty = (** [trivial] is the singleton inductive type---it is trivially inhabited. Like [empty], [trivial] is seldom used. We instead use its "squashed" variants, [True] *) type trivial = | T (** [unit]: another singleton type, with its only inhabitant written [()] we assume it is primitive, for convenient interop with other languages *) assume new type unit : eqtype (** [squash p] is a central type in F*---[squash p] is the proof irrelevant analog of [p] and is represented as a unit refinement. Squashed proofs are typically discharged using an SMT solver, without any proof terms explicitly reconstructed. As such, one way to think of [squash p] is as the type of properties proven using classical axioms without building proof terms. Note, [squash p] is just a unit refinement, it resides in universe 0, lowering the universe of [p]. From this perspective, one may also see [squash] as a coercion down to universe 0. The type is marked [tac_opaque] to indicate to Meta-F* that instances of [squash] should not be unfolded when evaluating tactics (since many optimizations in F*'s SMT encoding rely specifically on occurrences of [squash]. See FStar.Squash for various ways of manipulating squashed types. *) [@@ "tac_opaque"] type squash (p: Type) : Type0 = x: unit{p} (** [auto_squash] is equivalent to [squash]. However, F* will automatically insert `auto_squash` when simplifying terms, converting terms of the form `p /\ True` to `auto_squash p`. We distinguish these automatically inserted squashes from explicit, user-written squashes. A user should not have to manipulate [auto_squash] at all, except in rare circumstances when writing tactics to process proofs that have already been partially simplified by F*'s simplifier. *) let auto_squash (p: Type) = squash p (** The [logical] type is transitionary. It is just an abbreviation for [Type0], but is used to classify uses of the basic squashed logical connectives that follow. Some day, we plan to remove the [logical] type, replacing it with [prop] (also defined below). The type is marked [private] to intentionally prevent user code from referencing this type, hopefully easing the removal of [logical] in the future. *) private type logical = Type0 (** An attribute indicating that a symbol is an smt theory symbol and hence may not be used in smt patterns. The typechecker warns if such symbols are used in patterns *) assume val smt_theory_symbol:attribute (** [l_True] has a special bit of syntactic sugar. It is written just as "True" and rendered in the ide as [True]. It is a squashed version of constructive truth, [trivial]. *) [@@ "tac_opaque"; smt_theory_symbol] let l_True:logical = squash trivial (** [l_False] has a special bit of syntactic sugar. It is written just as "False" and rendered in the ide as [Falsee]. It is a squashed version of constructive falsehood, the empty type. *)
{ "checked_file": "/", "dependencies": [], "interface_file": false, "source_file": "prims.fst" }
[ { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": 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.logical
Prims.Tot
[ "total" ]
[]
[ "Prims.squash", "Prims.empty" ]
[]
false
false
false
true
true
let l_False:logical =
squash empty
false
prims.fst
Prims.subtype_of
val subtype_of : p1: Type -> p2: Type -> Prims.logical
let subtype_of (p1 p2: Type) = forall (x: p1). has_type x p2
{ "file_name": "ulib/prims.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 60, "end_line": 270, "start_col": 0, "start_line": 270 }
(* Copyright 2008-2020 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 Prims /// This module is implicitly opened in the scope of all other modules. /// /// It provides the very basic primitives on which F* is /// built, including the definition of total functions, the basic /// logical connectives, the PURE and GHOST effects and the like. /// /// While some of the primitives have logical significance, others are /// define various conveniences in the language, e.g., type of /// attributes. (***** Begin trusted primitives *****) (** Primitives up to the definition of the GTot effect are trusted Beyond that all definitions are fully verified *) (** Type of attributes *) assume new type attribute : Type0 (** An attribute indicating that some definition must be processed by the Dijkstra monads for free construction *) assume val cps:attribute (** A predicate to express when a type supports decidable equality The type-checker emits axioms for [hasEq] for each inductive type *) assume type hasEq : Type -> GTot Type0 (** A convenient abbreviation, [eqtype] is the type of types in universe 0 which support decidable equality *) type eqtype = a: Type0{hasEq a} (** [bool] is a two element type with elements [true] and [false]. We assume it is primitive, for convenient interop with other languages, although it could easily be defined as an inductive type with two cases, [BTrue | BFalse] *) assume new type bool : eqtype (** [empty] is the empty inductive type. The type with no inhabitants represents logical falsehood. Note, [empty] is seldom used directly in F*. We instead use its "squashed" variant, [False], see below. *) type empty = (** [trivial] is the singleton inductive type---it is trivially inhabited. Like [empty], [trivial] is seldom used. We instead use its "squashed" variants, [True] *) type trivial = | T (** [unit]: another singleton type, with its only inhabitant written [()] we assume it is primitive, for convenient interop with other languages *) assume new type unit : eqtype (** [squash p] is a central type in F*---[squash p] is the proof irrelevant analog of [p] and is represented as a unit refinement. Squashed proofs are typically discharged using an SMT solver, without any proof terms explicitly reconstructed. As such, one way to think of [squash p] is as the type of properties proven using classical axioms without building proof terms. Note, [squash p] is just a unit refinement, it resides in universe 0, lowering the universe of [p]. From this perspective, one may also see [squash] as a coercion down to universe 0. The type is marked [tac_opaque] to indicate to Meta-F* that instances of [squash] should not be unfolded when evaluating tactics (since many optimizations in F*'s SMT encoding rely specifically on occurrences of [squash]. See FStar.Squash for various ways of manipulating squashed types. *) [@@ "tac_opaque"] type squash (p: Type) : Type0 = x: unit{p} (** [auto_squash] is equivalent to [squash]. However, F* will automatically insert `auto_squash` when simplifying terms, converting terms of the form `p /\ True` to `auto_squash p`. We distinguish these automatically inserted squashes from explicit, user-written squashes. A user should not have to manipulate [auto_squash] at all, except in rare circumstances when writing tactics to process proofs that have already been partially simplified by F*'s simplifier. *) let auto_squash (p: Type) = squash p (** The [logical] type is transitionary. It is just an abbreviation for [Type0], but is used to classify uses of the basic squashed logical connectives that follow. Some day, we plan to remove the [logical] type, replacing it with [prop] (also defined below). The type is marked [private] to intentionally prevent user code from referencing this type, hopefully easing the removal of [logical] in the future. *) private type logical = Type0 (** An attribute indicating that a symbol is an smt theory symbol and hence may not be used in smt patterns. The typechecker warns if such symbols are used in patterns *) assume val smt_theory_symbol:attribute (** [l_True] has a special bit of syntactic sugar. It is written just as "True" and rendered in the ide as [True]. It is a squashed version of constructive truth, [trivial]. *) [@@ "tac_opaque"; smt_theory_symbol] let l_True:logical = squash trivial (** [l_False] has a special bit of syntactic sugar. It is written just as "False" and rendered in the ide as [Falsee]. It is a squashed version of constructive falsehood, the empty type. *) [@@ "tac_opaque"; smt_theory_symbol] let l_False:logical = squash empty (** The type of provable equalities, defined as the usual inductive type with a single constructor for reflexivity. As with the other connectives, we often work instead with the squashed version of equality, below. *) type equals (#a: Type) (x: a) : a -> Type = | Refl : equals x x (** [eq2] is the squashed version of [equals]. It's a proof irrelevant, homogeneous equality in Type#0 and is written with an infix binary [==]. TODO: instead of hard-wiring the == syntax, we should just rename eq2 to op_Equals_Equals *) [@@ "tac_opaque"; smt_theory_symbol] type eq2 (#a: Type) (x: a) (y: a) : logical = squash (equals x y) (** bool-to-type coercion: This is often automatically inserted type, when using a boolean in context expecting a type. But, occasionally, one may have to write [b2t] explicitly *) type b2t (b: bool) : logical = (b == true) (** constructive conjunction *) type pair (p: Type) (q: Type) = | Pair : _1:p -> _2:q -> pair p q (** squashed conjunction, specialized to [Type0], written with an infix binary [/\] *) [@@ "tac_opaque"; smt_theory_symbol] type l_and (p: logical) (q: logical) : logical = squash (pair p q) (** constructive disjunction *) type sum (p: Type) (q: Type) = | Left : v:p -> sum p q | Right : v:q -> sum p q (** squashed disjunction, specialized to [Type0], written with an infix binary [\/] *) [@@ "tac_opaque"; smt_theory_symbol] type l_or (p: logical) (q: logical) : logical = squash (sum p q) (** squashed (non-dependent) implication, specialized to [Type0], written with an infix binary [==>]. Note, [==>] binds weaker than [/\] and [\/] *) [@@ "tac_opaque"; smt_theory_symbol] type l_imp (p: logical) (q: logical) : logical = squash (p -> GTot q) (* ^^^ NB: The GTot effect is primitive; *) (* elaborated using GHOST a few lines below *) (** squashed double implication, infix binary [<==>] *) [@@ smt_theory_symbol] type l_iff (p: logical) (q: logical) : logical = (p ==> q) /\ (q ==> p) (** squashed negation, prefix unary [~] *) [@@ smt_theory_symbol] type l_not (p: logical) : logical = l_imp p False (** l_ITE is a weak form of if-then-else at the level of logical formulae. It's not much used. TODO: Can we remove it *) unfold type l_ITE (p: logical) (q: logical) (r: logical) : logical = (p ==> q) /\ (~p ==> r) (** One of the main axioms provided by prims is [precedes], a built-in well-founded partial order over all terms. It's typically written with an infix binary [<<]. The [<<] order includes: * The [<] ordering on natural numbers * The subterm ordering on inductive types * [f x << D f] for data constructors D of an inductive t whose arguments include a ghost or total function returning a t *) assume type precedes : #a: Type -> #b: Type -> a -> b -> Type0 (** The type of primitive strings of characters; See FStar.String *) assume new type string : eqtype (** This attribute can be added to the declaration or definition of any top-level symbol. It causes F* to report a warning on any use of that symbol, printing the [msg] argument. This is used, for instance to: - tag every escape hatch, e.g., [assume], [admit], etc Reports for uses of symbols tagged with this attribute are controlled using the `--report_assumes` option and warning number 334. See tests/micro-benchmarks/WarnOnUse.fst *) assume val warn_on_use (msg: string) : Tot unit (** The [deprecated "s"] attribute: "s" is an alternative function that should be printed in the warning it can be omitted if the use case has no such function *) assume val deprecated (s: string) : Tot unit (** Within the SMT encoding, we have a relation [(HasType e t)] asserting that (the encoding of) [e] has a type corresponding to (the encoding of) [t]. It is sometimes convenient, e.g., when writing triggers for quantifiers, to have access to this relation at the source level. The [has_type] predicate below reflects the SMT encodings [HasType] relation. We also use it to define the type [prop] or proof irrelevant propositions, below. Note, unless you have a really good reason, you probably don't want to use this [has_type] predicate. F*'s type theory certainly does not internalize its own typing judgment *) [@@deprecated "'has_type' is intended for internal use and debugging purposes only; \ do not rely on it for your proofs"] assume type has_type : #a: Type -> a -> Type -> Type0 (** Squashed universal quantification, or dependent products, written [forall (x:a). p x], specialized to Type0 *) [@@ "tac_opaque"; smt_theory_symbol] type l_Forall (#a: Type) (p: (a -> GTot Type0)) : logical = squash (x: a -> GTot (p x)) #push-options "--warn_error -288" (** [p1 `subtype_of` p2] when every element of [p1] is also an element
{ "checked_file": "/", "dependencies": [], "interface_file": false, "source_file": "prims.fst" }
[ { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": 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
p1: Type -> p2: Type -> Prims.logical
Prims.Tot
[ "total" ]
[]
[ "Prims.l_Forall", "Prims.has_type", "Prims.logical" ]
[]
false
false
false
true
true
let subtype_of (p1 p2: Type) =
forall (x: p1). has_type x p2
false
prims.fst
Prims.pure_pre
val pure_pre : Type
let pure_pre = Type0
{ "file_name": "ulib/prims.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 20, "end_line": 288, "start_col": 0, "start_line": 288 }
(* Copyright 2008-2020 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 Prims /// This module is implicitly opened in the scope of all other modules. /// /// It provides the very basic primitives on which F* is /// built, including the definition of total functions, the basic /// logical connectives, the PURE and GHOST effects and the like. /// /// While some of the primitives have logical significance, others are /// define various conveniences in the language, e.g., type of /// attributes. (***** Begin trusted primitives *****) (** Primitives up to the definition of the GTot effect are trusted Beyond that all definitions are fully verified *) (** Type of attributes *) assume new type attribute : Type0 (** An attribute indicating that some definition must be processed by the Dijkstra monads for free construction *) assume val cps:attribute (** A predicate to express when a type supports decidable equality The type-checker emits axioms for [hasEq] for each inductive type *) assume type hasEq : Type -> GTot Type0 (** A convenient abbreviation, [eqtype] is the type of types in universe 0 which support decidable equality *) type eqtype = a: Type0{hasEq a} (** [bool] is a two element type with elements [true] and [false]. We assume it is primitive, for convenient interop with other languages, although it could easily be defined as an inductive type with two cases, [BTrue | BFalse] *) assume new type bool : eqtype (** [empty] is the empty inductive type. The type with no inhabitants represents logical falsehood. Note, [empty] is seldom used directly in F*. We instead use its "squashed" variant, [False], see below. *) type empty = (** [trivial] is the singleton inductive type---it is trivially inhabited. Like [empty], [trivial] is seldom used. We instead use its "squashed" variants, [True] *) type trivial = | T (** [unit]: another singleton type, with its only inhabitant written [()] we assume it is primitive, for convenient interop with other languages *) assume new type unit : eqtype (** [squash p] is a central type in F*---[squash p] is the proof irrelevant analog of [p] and is represented as a unit refinement. Squashed proofs are typically discharged using an SMT solver, without any proof terms explicitly reconstructed. As such, one way to think of [squash p] is as the type of properties proven using classical axioms without building proof terms. Note, [squash p] is just a unit refinement, it resides in universe 0, lowering the universe of [p]. From this perspective, one may also see [squash] as a coercion down to universe 0. The type is marked [tac_opaque] to indicate to Meta-F* that instances of [squash] should not be unfolded when evaluating tactics (since many optimizations in F*'s SMT encoding rely specifically on occurrences of [squash]. See FStar.Squash for various ways of manipulating squashed types. *) [@@ "tac_opaque"] type squash (p: Type) : Type0 = x: unit{p} (** [auto_squash] is equivalent to [squash]. However, F* will automatically insert `auto_squash` when simplifying terms, converting terms of the form `p /\ True` to `auto_squash p`. We distinguish these automatically inserted squashes from explicit, user-written squashes. A user should not have to manipulate [auto_squash] at all, except in rare circumstances when writing tactics to process proofs that have already been partially simplified by F*'s simplifier. *) let auto_squash (p: Type) = squash p (** The [logical] type is transitionary. It is just an abbreviation for [Type0], but is used to classify uses of the basic squashed logical connectives that follow. Some day, we plan to remove the [logical] type, replacing it with [prop] (also defined below). The type is marked [private] to intentionally prevent user code from referencing this type, hopefully easing the removal of [logical] in the future. *) private type logical = Type0 (** An attribute indicating that a symbol is an smt theory symbol and hence may not be used in smt patterns. The typechecker warns if such symbols are used in patterns *) assume val smt_theory_symbol:attribute (** [l_True] has a special bit of syntactic sugar. It is written just as "True" and rendered in the ide as [True]. It is a squashed version of constructive truth, [trivial]. *) [@@ "tac_opaque"; smt_theory_symbol] let l_True:logical = squash trivial (** [l_False] has a special bit of syntactic sugar. It is written just as "False" and rendered in the ide as [Falsee]. It is a squashed version of constructive falsehood, the empty type. *) [@@ "tac_opaque"; smt_theory_symbol] let l_False:logical = squash empty (** The type of provable equalities, defined as the usual inductive type with a single constructor for reflexivity. As with the other connectives, we often work instead with the squashed version of equality, below. *) type equals (#a: Type) (x: a) : a -> Type = | Refl : equals x x (** [eq2] is the squashed version of [equals]. It's a proof irrelevant, homogeneous equality in Type#0 and is written with an infix binary [==]. TODO: instead of hard-wiring the == syntax, we should just rename eq2 to op_Equals_Equals *) [@@ "tac_opaque"; smt_theory_symbol] type eq2 (#a: Type) (x: a) (y: a) : logical = squash (equals x y) (** bool-to-type coercion: This is often automatically inserted type, when using a boolean in context expecting a type. But, occasionally, one may have to write [b2t] explicitly *) type b2t (b: bool) : logical = (b == true) (** constructive conjunction *) type pair (p: Type) (q: Type) = | Pair : _1:p -> _2:q -> pair p q (** squashed conjunction, specialized to [Type0], written with an infix binary [/\] *) [@@ "tac_opaque"; smt_theory_symbol] type l_and (p: logical) (q: logical) : logical = squash (pair p q) (** constructive disjunction *) type sum (p: Type) (q: Type) = | Left : v:p -> sum p q | Right : v:q -> sum p q (** squashed disjunction, specialized to [Type0], written with an infix binary [\/] *) [@@ "tac_opaque"; smt_theory_symbol] type l_or (p: logical) (q: logical) : logical = squash (sum p q) (** squashed (non-dependent) implication, specialized to [Type0], written with an infix binary [==>]. Note, [==>] binds weaker than [/\] and [\/] *) [@@ "tac_opaque"; smt_theory_symbol] type l_imp (p: logical) (q: logical) : logical = squash (p -> GTot q) (* ^^^ NB: The GTot effect is primitive; *) (* elaborated using GHOST a few lines below *) (** squashed double implication, infix binary [<==>] *) [@@ smt_theory_symbol] type l_iff (p: logical) (q: logical) : logical = (p ==> q) /\ (q ==> p) (** squashed negation, prefix unary [~] *) [@@ smt_theory_symbol] type l_not (p: logical) : logical = l_imp p False (** l_ITE is a weak form of if-then-else at the level of logical formulae. It's not much used. TODO: Can we remove it *) unfold type l_ITE (p: logical) (q: logical) (r: logical) : logical = (p ==> q) /\ (~p ==> r) (** One of the main axioms provided by prims is [precedes], a built-in well-founded partial order over all terms. It's typically written with an infix binary [<<]. The [<<] order includes: * The [<] ordering on natural numbers * The subterm ordering on inductive types * [f x << D f] for data constructors D of an inductive t whose arguments include a ghost or total function returning a t *) assume type precedes : #a: Type -> #b: Type -> a -> b -> Type0 (** The type of primitive strings of characters; See FStar.String *) assume new type string : eqtype (** This attribute can be added to the declaration or definition of any top-level symbol. It causes F* to report a warning on any use of that symbol, printing the [msg] argument. This is used, for instance to: - tag every escape hatch, e.g., [assume], [admit], etc Reports for uses of symbols tagged with this attribute are controlled using the `--report_assumes` option and warning number 334. See tests/micro-benchmarks/WarnOnUse.fst *) assume val warn_on_use (msg: string) : Tot unit (** The [deprecated "s"] attribute: "s" is an alternative function that should be printed in the warning it can be omitted if the use case has no such function *) assume val deprecated (s: string) : Tot unit (** Within the SMT encoding, we have a relation [(HasType e t)] asserting that (the encoding of) [e] has a type corresponding to (the encoding of) [t]. It is sometimes convenient, e.g., when writing triggers for quantifiers, to have access to this relation at the source level. The [has_type] predicate below reflects the SMT encodings [HasType] relation. We also use it to define the type [prop] or proof irrelevant propositions, below. Note, unless you have a really good reason, you probably don't want to use this [has_type] predicate. F*'s type theory certainly does not internalize its own typing judgment *) [@@deprecated "'has_type' is intended for internal use and debugging purposes only; \ do not rely on it for your proofs"] assume type has_type : #a: Type -> a -> Type -> Type0 (** Squashed universal quantification, or dependent products, written [forall (x:a). p x], specialized to Type0 *) [@@ "tac_opaque"; smt_theory_symbol] type l_Forall (#a: Type) (p: (a -> GTot Type0)) : logical = squash (x: a -> GTot (p x)) #push-options "--warn_error -288" (** [p1 `subtype_of` p2] when every element of [p1] is also an element of [p2]. *) let subtype_of (p1 p2: Type) = forall (x: p1). has_type x p2 #pop-options (** The type of squashed types. Note, the [prop] type is a work in progress in F*. In particular, we would like in the future to more systematically use [prop] for proof-irrelevant propositions throughout the libraries. However, we still use [Type0] in many places. See https://github.com/FStarLang/FStar/issues/1048 for more details and the current status of the work. *) type prop = a: Type0{a `subtype_of` unit} (**** The PURE effect *)
{ "checked_file": "/", "dependencies": [], "interface_file": false, "source_file": "prims.fst" }
[ { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
Type
Prims.Tot
[ "total" ]
[]
[]
[]
false
false
false
true
true
let pure_pre =
Type0
false
prims.fst
Prims.pure_post'
val pure_post' : a: Type -> pre: Type -> Type
let pure_post' (a pre: Type) = _: a{pre} -> GTot Type0
{ "file_name": "ulib/prims.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 54, "end_line": 294, "start_col": 0, "start_line": 294 }
(* Copyright 2008-2020 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 Prims /// This module is implicitly opened in the scope of all other modules. /// /// It provides the very basic primitives on which F* is /// built, including the definition of total functions, the basic /// logical connectives, the PURE and GHOST effects and the like. /// /// While some of the primitives have logical significance, others are /// define various conveniences in the language, e.g., type of /// attributes. (***** Begin trusted primitives *****) (** Primitives up to the definition of the GTot effect are trusted Beyond that all definitions are fully verified *) (** Type of attributes *) assume new type attribute : Type0 (** An attribute indicating that some definition must be processed by the Dijkstra monads for free construction *) assume val cps:attribute (** A predicate to express when a type supports decidable equality The type-checker emits axioms for [hasEq] for each inductive type *) assume type hasEq : Type -> GTot Type0 (** A convenient abbreviation, [eqtype] is the type of types in universe 0 which support decidable equality *) type eqtype = a: Type0{hasEq a} (** [bool] is a two element type with elements [true] and [false]. We assume it is primitive, for convenient interop with other languages, although it could easily be defined as an inductive type with two cases, [BTrue | BFalse] *) assume new type bool : eqtype (** [empty] is the empty inductive type. The type with no inhabitants represents logical falsehood. Note, [empty] is seldom used directly in F*. We instead use its "squashed" variant, [False], see below. *) type empty = (** [trivial] is the singleton inductive type---it is trivially inhabited. Like [empty], [trivial] is seldom used. We instead use its "squashed" variants, [True] *) type trivial = | T (** [unit]: another singleton type, with its only inhabitant written [()] we assume it is primitive, for convenient interop with other languages *) assume new type unit : eqtype (** [squash p] is a central type in F*---[squash p] is the proof irrelevant analog of [p] and is represented as a unit refinement. Squashed proofs are typically discharged using an SMT solver, without any proof terms explicitly reconstructed. As such, one way to think of [squash p] is as the type of properties proven using classical axioms without building proof terms. Note, [squash p] is just a unit refinement, it resides in universe 0, lowering the universe of [p]. From this perspective, one may also see [squash] as a coercion down to universe 0. The type is marked [tac_opaque] to indicate to Meta-F* that instances of [squash] should not be unfolded when evaluating tactics (since many optimizations in F*'s SMT encoding rely specifically on occurrences of [squash]. See FStar.Squash for various ways of manipulating squashed types. *) [@@ "tac_opaque"] type squash (p: Type) : Type0 = x: unit{p} (** [auto_squash] is equivalent to [squash]. However, F* will automatically insert `auto_squash` when simplifying terms, converting terms of the form `p /\ True` to `auto_squash p`. We distinguish these automatically inserted squashes from explicit, user-written squashes. A user should not have to manipulate [auto_squash] at all, except in rare circumstances when writing tactics to process proofs that have already been partially simplified by F*'s simplifier. *) let auto_squash (p: Type) = squash p (** The [logical] type is transitionary. It is just an abbreviation for [Type0], but is used to classify uses of the basic squashed logical connectives that follow. Some day, we plan to remove the [logical] type, replacing it with [prop] (also defined below). The type is marked [private] to intentionally prevent user code from referencing this type, hopefully easing the removal of [logical] in the future. *) private type logical = Type0 (** An attribute indicating that a symbol is an smt theory symbol and hence may not be used in smt patterns. The typechecker warns if such symbols are used in patterns *) assume val smt_theory_symbol:attribute (** [l_True] has a special bit of syntactic sugar. It is written just as "True" and rendered in the ide as [True]. It is a squashed version of constructive truth, [trivial]. *) [@@ "tac_opaque"; smt_theory_symbol] let l_True:logical = squash trivial (** [l_False] has a special bit of syntactic sugar. It is written just as "False" and rendered in the ide as [Falsee]. It is a squashed version of constructive falsehood, the empty type. *) [@@ "tac_opaque"; smt_theory_symbol] let l_False:logical = squash empty (** The type of provable equalities, defined as the usual inductive type with a single constructor for reflexivity. As with the other connectives, we often work instead with the squashed version of equality, below. *) type equals (#a: Type) (x: a) : a -> Type = | Refl : equals x x (** [eq2] is the squashed version of [equals]. It's a proof irrelevant, homogeneous equality in Type#0 and is written with an infix binary [==]. TODO: instead of hard-wiring the == syntax, we should just rename eq2 to op_Equals_Equals *) [@@ "tac_opaque"; smt_theory_symbol] type eq2 (#a: Type) (x: a) (y: a) : logical = squash (equals x y) (** bool-to-type coercion: This is often automatically inserted type, when using a boolean in context expecting a type. But, occasionally, one may have to write [b2t] explicitly *) type b2t (b: bool) : logical = (b == true) (** constructive conjunction *) type pair (p: Type) (q: Type) = | Pair : _1:p -> _2:q -> pair p q (** squashed conjunction, specialized to [Type0], written with an infix binary [/\] *) [@@ "tac_opaque"; smt_theory_symbol] type l_and (p: logical) (q: logical) : logical = squash (pair p q) (** constructive disjunction *) type sum (p: Type) (q: Type) = | Left : v:p -> sum p q | Right : v:q -> sum p q (** squashed disjunction, specialized to [Type0], written with an infix binary [\/] *) [@@ "tac_opaque"; smt_theory_symbol] type l_or (p: logical) (q: logical) : logical = squash (sum p q) (** squashed (non-dependent) implication, specialized to [Type0], written with an infix binary [==>]. Note, [==>] binds weaker than [/\] and [\/] *) [@@ "tac_opaque"; smt_theory_symbol] type l_imp (p: logical) (q: logical) : logical = squash (p -> GTot q) (* ^^^ NB: The GTot effect is primitive; *) (* elaborated using GHOST a few lines below *) (** squashed double implication, infix binary [<==>] *) [@@ smt_theory_symbol] type l_iff (p: logical) (q: logical) : logical = (p ==> q) /\ (q ==> p) (** squashed negation, prefix unary [~] *) [@@ smt_theory_symbol] type l_not (p: logical) : logical = l_imp p False (** l_ITE is a weak form of if-then-else at the level of logical formulae. It's not much used. TODO: Can we remove it *) unfold type l_ITE (p: logical) (q: logical) (r: logical) : logical = (p ==> q) /\ (~p ==> r) (** One of the main axioms provided by prims is [precedes], a built-in well-founded partial order over all terms. It's typically written with an infix binary [<<]. The [<<] order includes: * The [<] ordering on natural numbers * The subterm ordering on inductive types * [f x << D f] for data constructors D of an inductive t whose arguments include a ghost or total function returning a t *) assume type precedes : #a: Type -> #b: Type -> a -> b -> Type0 (** The type of primitive strings of characters; See FStar.String *) assume new type string : eqtype (** This attribute can be added to the declaration or definition of any top-level symbol. It causes F* to report a warning on any use of that symbol, printing the [msg] argument. This is used, for instance to: - tag every escape hatch, e.g., [assume], [admit], etc Reports for uses of symbols tagged with this attribute are controlled using the `--report_assumes` option and warning number 334. See tests/micro-benchmarks/WarnOnUse.fst *) assume val warn_on_use (msg: string) : Tot unit (** The [deprecated "s"] attribute: "s" is an alternative function that should be printed in the warning it can be omitted if the use case has no such function *) assume val deprecated (s: string) : Tot unit (** Within the SMT encoding, we have a relation [(HasType e t)] asserting that (the encoding of) [e] has a type corresponding to (the encoding of) [t]. It is sometimes convenient, e.g., when writing triggers for quantifiers, to have access to this relation at the source level. The [has_type] predicate below reflects the SMT encodings [HasType] relation. We also use it to define the type [prop] or proof irrelevant propositions, below. Note, unless you have a really good reason, you probably don't want to use this [has_type] predicate. F*'s type theory certainly does not internalize its own typing judgment *) [@@deprecated "'has_type' is intended for internal use and debugging purposes only; \ do not rely on it for your proofs"] assume type has_type : #a: Type -> a -> Type -> Type0 (** Squashed universal quantification, or dependent products, written [forall (x:a). p x], specialized to Type0 *) [@@ "tac_opaque"; smt_theory_symbol] type l_Forall (#a: Type) (p: (a -> GTot Type0)) : logical = squash (x: a -> GTot (p x)) #push-options "--warn_error -288" (** [p1 `subtype_of` p2] when every element of [p1] is also an element of [p2]. *) let subtype_of (p1 p2: Type) = forall (x: p1). has_type x p2 #pop-options (** The type of squashed types. Note, the [prop] type is a work in progress in F*. In particular, we would like in the future to more systematically use [prop] for proof-irrelevant propositions throughout the libraries. However, we still use [Type0] in many places. See https://github.com/FStarLang/FStar/issues/1048 for more details and the current status of the work. *) type prop = a: Type0{a `subtype_of` unit} (**** The PURE effect *) (** The type of pure preconditions *) let pure_pre = Type0 (** Pure postconditions, predicates on [a], on which the precondition [pre] is also valid. This provides a way for postcondition formula to be typed in a context where they can assume the validity of the
{ "checked_file": "/", "dependencies": [], "interface_file": false, "source_file": "prims.fst" }
[ { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
a: Type -> pre: Type -> Type
Prims.Tot
[ "total" ]
[]
[]
[]
false
false
false
true
true
let pure_post' (a pre: Type) =
_: a{pre} -> GTot Type0
false
Vale.X64.Lemmas.fst
Vale.X64.Lemmas.lemma_whileTrue_total
val lemma_whileTrue_total (b:ocmp) (c:code) (s0:vale_state) (sW:vale_state) (fW:fuel) : Ghost (vale_state & fuel) (requires eval_ocmp sW b) (ensures fun (s1, f1) -> s1 == {sW with vs_flags = havoc_flags} /\ f1 == fW)
val lemma_whileTrue_total (b:ocmp) (c:code) (s0:vale_state) (sW:vale_state) (fW:fuel) : Ghost (vale_state & fuel) (requires eval_ocmp sW b) (ensures fun (s1, f1) -> s1 == {sW with vs_flags = havoc_flags} /\ f1 == fW)
let lemma_whileTrue_total (b:ocmp) (c:code) (s0:vale_state) (sW:vale_state) (fW:fuel) = ({sW with vs_flags = havoc_flags}, fW)
{ "file_name": "vale/code/arch/x64/Vale.X64.Lemmas.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 40, "end_line": 386, "start_col": 0, "start_line": 385 }
module Vale.X64.Lemmas open FStar.Mul open Vale.X64.Machine_s open Vale.X64.State open Vale.X64.StateLemmas open Vale.X64.Instruction_s open Vale.X64.Bytes_Code_s module BS = Vale.X64.Machine_Semantics_s module ME = Vale.X64.Memory #reset-options "--initial_fuel 1 --max_fuel 1 --z3rlimit 100" #restart-solver let rec lemma_eq_instr_apply_eval_args (outs:list instr_out) (args:list instr_operand) (f:instr_args_t outs args) (oprs:instr_operands_t_args args) (s1 s2:machine_state) : Lemma (requires state_eq_S true s1 s2) (ensures BS.instr_apply_eval_args outs args f oprs s1 == BS.instr_apply_eval_args outs args f oprs s2) = let open BS in lemma_heap_ignore_ghost_machine s1.BS.ms_heap s2.BS.ms_heap; match args with | [] -> () | i::args -> ( let (v, oprs) : option (instr_val_t i) & instr_operands_t_args args = match i with | IOpEx i -> let oprs = coerce oprs in (instr_eval_operand_explicit i (fst oprs) s1, snd oprs) | IOpIm i -> (instr_eval_operand_implicit i s1, coerce oprs) in let f:arrow (instr_val_t i) (instr_args_t outs args) = coerce f in match v with | None -> () | Some v -> lemma_eq_instr_apply_eval_args outs args (f v) oprs s1 s2 ) #restart-solver let rec lemma_eq_instr_apply_eval_inouts (outs inouts:list instr_out) (args:list instr_operand) (f:instr_inouts_t outs inouts args) (oprs:instr_operands_t inouts args) (s1 s2:machine_state) : Lemma (requires state_eq_S true s1 s2) (ensures BS.instr_apply_eval_inouts outs inouts args f oprs s1 == BS.instr_apply_eval_inouts outs inouts args f oprs s2) = let open BS in lemma_heap_ignore_ghost_machine s1.BS.ms_heap s2.BS.ms_heap; match inouts with | [] -> lemma_eq_instr_apply_eval_args outs args f oprs s1 s2 | (Out, i)::inouts -> let oprs = match i with | IOpEx i -> snd #(instr_operand_t i) (coerce oprs) | IOpIm i -> coerce oprs in lemma_eq_instr_apply_eval_inouts outs inouts args (coerce f) oprs s1 s2 | (InOut, i)::inouts -> ( let (v, oprs) : option (instr_val_t i) & instr_operands_t inouts args = match i with | IOpEx i -> let oprs = coerce oprs in (instr_eval_operand_explicit i (fst oprs) s1, snd oprs) | IOpIm i -> (instr_eval_operand_implicit i s1, coerce oprs) in let f:arrow (instr_val_t i) (instr_inouts_t outs inouts args) = coerce f in match v with | None -> () | Some v -> lemma_eq_instr_apply_eval_inouts outs inouts args (f v) oprs s1 s2 ) #restart-solver #push-options "--z3rlimit_factor 2" let rec lemma_eq_instr_write_outputs (outs:list instr_out) (args:list instr_operand) (vs:instr_ret_t outs) (oprs:instr_operands_t outs args) (s1_orig s1 s2_orig s2:machine_state) : Lemma (requires state_eq_S true s1_orig s2_orig /\ state_eq_S true s1 s2) (ensures state_eq_S true (BS.instr_write_outputs outs args vs oprs s1_orig s1) (BS.instr_write_outputs outs args vs oprs s2_orig s2)) = let open BS in use_machine_state_equal (); lemma_heap_ignore_ghost_machine s1.BS.ms_heap s2.BS.ms_heap; lemma_heap_ignore_ghost_machine s1_orig.BS.ms_heap s2_orig.BS.ms_heap; allow_inversion tmaddr; match outs with | [] -> () | (_, i)::outs -> ( let ((v:instr_val_t i), (vs:instr_ret_t outs)) = match outs with | [] -> (vs, ()) | _::_ -> let vs = coerce vs in (fst vs, snd vs) in match i with | IOpEx i -> let oprs = coerce oprs in let s1 = instr_write_output_explicit i v (fst oprs) s1_orig s1 in let s2 = instr_write_output_explicit i v (fst oprs) s2_orig s2 in lemma_eq_instr_write_outputs outs args vs (snd oprs) s1_orig s1 s2_orig s2 | IOpIm i -> let s1 = instr_write_output_implicit i v s1_orig s1 in let s2 = instr_write_output_implicit i v s2_orig s2 in allow_inversion operand64; allow_inversion operand128; lemma_eq_instr_write_outputs outs args vs (coerce oprs) s1_orig s1 s2_orig s2 ) #pop-options #restart-solver let eval_ins_eq_instr (inst:BS.ins) (s1 s2:machine_state) : Lemma (requires Instr? inst /\ state_eq_S true s1 s2) (ensures state_eq_S true (BS.machine_eval_ins inst s1) (BS.machine_eval_ins inst s2)) = let open BS in let Instr it oprs ann = inst in let InstrTypeRecord #outs #args #havoc_flags' i = it in lemma_eq_instr_apply_eval_inouts outs outs args (instr_eval i) oprs s1 s2; let vs = instr_apply_eval outs args (instr_eval i) oprs s1 in let hav s = match havoc_flags' with | HavocFlags -> {s with ms_flags = havoc_flags} | PreserveFlags -> s in let s1' = hav s1 in let s2' = hav s2 in match vs with | None -> () | Some vs -> lemma_eq_instr_write_outputs outs args vs oprs s1 s1' s2 s2' let eval_code_eq_instr (inst:BS.ins) (f:fuel) (s1 s2:machine_state) : Lemma (requires Instr? inst /\ state_eq_S true s1 s2) (ensures state_eq_opt true (BS.machine_eval_code (Ins inst) f s1) (BS.machine_eval_code (Ins inst) f s2)) = reveal_opaque (`%BS.machine_eval_code_ins) BS.machine_eval_code_ins; eval_ins_eq_instr inst ({s1 with BS.ms_trace = []}) ({s2 with BS.ms_trace = []}) let eval_code_eq_dealloc (inst:BS.ins) (f:fuel) (s1 s2:machine_state) : Lemma (requires Dealloc? inst /\ state_eq_S true s1 s2) (ensures state_eq_opt true (BS.machine_eval_code (Ins inst) f s1) (BS.machine_eval_code (Ins inst) f s2)) = reveal_opaque (`%BS.machine_eval_code_ins) BS.machine_eval_code_ins; use_machine_state_equal (); lemma_heap_ignore_ghost_machine s1.BS.ms_heap s2.BS.ms_heap; allow_inversion tmaddr let eval_code_eq_alloc (inst:BS.ins) (f:fuel) (s1 s2:machine_state) : Lemma (requires Alloc? inst /\ state_eq_S true s1 s2) (ensures state_eq_opt true (BS.machine_eval_code (Ins inst) f s1) (BS.machine_eval_code (Ins inst) f s2)) = reveal_opaque (`%BS.machine_eval_code_ins) BS.machine_eval_code_ins; use_machine_state_equal (); lemma_heap_ignore_ghost_machine s1.BS.ms_heap s2.BS.ms_heap; allow_inversion tmaddr let eval_code_eq_push (inst:BS.ins) (f:fuel) (s1 s2:machine_state) : Lemma (requires Push? inst /\ state_eq_S true s1 s2) (ensures state_eq_opt true (BS.machine_eval_code (Ins inst) f s1) (BS.machine_eval_code (Ins inst) f s2)) = reveal_opaque (`%BS.machine_eval_code_ins) BS.machine_eval_code_ins; use_machine_state_equal (); lemma_heap_ignore_ghost_machine s1.BS.ms_heap s2.BS.ms_heap; allow_inversion tmaddr let eval_code_eq_pop (inst:BS.ins) (f:fuel) (s1 s2:machine_state) : Lemma (requires Pop? inst /\ state_eq_S true s1 s2) (ensures state_eq_opt true (BS.machine_eval_code (Ins inst) f s1) (BS.machine_eval_code (Ins inst) f s2)) = reveal_opaque (`%BS.machine_eval_code_ins) BS.machine_eval_code_ins; use_machine_state_equal (); lemma_heap_ignore_ghost_machine s1.BS.ms_heap s2.BS.ms_heap; allow_inversion tmaddr let eval_code_eq_ins (i:BS.ins) (f:fuel) (s1 s2:machine_state) : Lemma (requires state_eq_S true s1 s2) (ensures state_eq_opt true (BS.machine_eval_code (Ins i) f s1) (BS.machine_eval_code (Ins i) f s2)) = match i with | Instr _ _ _ -> eval_code_eq_instr i f s1 s2 | Dealloc _ -> eval_code_eq_dealloc i f s1 s2 | Alloc _ -> eval_code_eq_alloc i f s1 s2 | Push _ _ -> eval_code_eq_push i f s1 s2 | Pop _ _ -> eval_code_eq_pop i f s1 s2 #reset-options "--fuel 2 --z3rlimit 30" let eval_ocmp_eq_core (g:bool) (cond:ocmp) (s:machine_state) : Lemma (ensures ( let (s1, b1) = BS.machine_eval_ocmp s cond in let (s2, b2) = BS.machine_eval_ocmp (core_state g s) cond in state_eq_S g s1 s2 /\ b1 == b2 )) = reveal_opaque (`%BS.valid_ocmp_opaque) BS.valid_ocmp_opaque; reveal_opaque (`%BS.eval_ocmp_opaque) BS.eval_ocmp_opaque; () #restart-solver let rec eval_code_eq_core (g:bool) (c:code) (f:fuel) (s:machine_state) : Lemma (ensures state_eq_opt g (BS.machine_eval_code c f s) (BS.machine_eval_code c f (core_state g s))) (decreases %[f; c]) = match c with | Ins i -> reveal_opaque (`%BS.machine_eval_code_ins) BS.machine_eval_code_ins; if g then eval_code_eq_ins i f s (core_state g s) | Block cs -> eval_codes_eq_core g cs f s | IfElse cond ct cf -> eval_ocmp_eq_core g cond s; let (s', _) = BS.machine_eval_ocmp s cond in let (t', _) = BS.machine_eval_ocmp (core_state g s) cond in eval_code_eq_core g ct f s'; eval_code_eq_core g ct f t'; eval_code_eq_core g cf f s'; eval_code_eq_core g cf f t'; () | While cond body -> eval_while_eq_core g cond body f s and eval_codes_eq_core (g:bool) (cs:codes) (f:fuel) (s:machine_state) : Lemma (ensures state_eq_opt g (BS.machine_eval_codes cs f s) (BS.machine_eval_codes cs f (core_state g s))) (decreases %[f; cs]) = match cs with | [] -> () | c'::cs' -> ( eval_code_eq_core g c' f s; match (machine_eval_code c' f s, machine_eval_code c' f (core_state g s)) with | (None, None) -> () | (Some s', Some t') -> eval_codes_eq_core g cs' f s'; eval_codes_eq_core g cs' f t' ) and eval_while_eq_core (g:bool) (cond:ocmp) (body:code) (f:fuel) (s:machine_state) : Lemma (ensures state_eq_opt g (BS.machine_eval_while cond body f s) (BS.machine_eval_while cond body f (core_state g s))) (decreases %[f; body]) = if f > 0 then ( eval_ocmp_eq_core g cond s; let (s1, _) = BS.machine_eval_ocmp s cond in let (t1, _) = BS.machine_eval_ocmp (core_state g s) cond in eval_code_eq_core g body (f - 1) s1; eval_code_eq_core g body (f - 1) t1; match (BS.machine_eval_code body (f - 1) s1, BS.machine_eval_code body (f - 1) t1) with | (None, None) -> () | (Some s2, Some t2) -> eval_while_eq_core g cond body (f - 1) s2; eval_while_eq_core g cond body (f - 1) t2; () ) let eval_code_eq_f (c:code) (f:fuel) (s1 s2:machine_state) : Lemma (requires state_eq_S false s1 s2) (ensures state_eq_opt false (BS.machine_eval_code c f s1) (BS.machine_eval_code c f s2)) [SMTPat (BS.machine_eval_code c f s1); SMTPat (BS.machine_eval_code c f s2)] = eval_code_eq_core false c f s1; eval_code_eq_core false c f s2 let eval_codes_eq_f (cs:codes) (f:fuel) (s1 s2:machine_state) : Lemma (requires state_eq_S false s1 s2) (ensures state_eq_opt false (BS.machine_eval_codes cs f s1) (BS.machine_eval_codes cs f s2)) [SMTPat (BS.machine_eval_codes cs f s1); SMTPat (BS.machine_eval_codes cs f s2)] = eval_codes_eq_core false cs f s1; eval_codes_eq_core false cs f s2 let eval_while_eq_f (cond:ocmp) (body:code) (f:fuel) (s1 s2:machine_state) : Lemma (requires state_eq_S false s1 s2) (ensures state_eq_opt false (BS.machine_eval_while cond body f s1) (BS.machine_eval_while cond body f s2)) [SMTPat (BS.machine_eval_while cond body f s1); SMTPat (BS.machine_eval_while cond body f s2)] = eval_while_eq_core false cond body f s1; eval_while_eq_core false cond body f s2 let eval_code_eq_t (c:code) (f:fuel) (s1 s2:machine_state) : Lemma (requires state_eq_S true s1 s2) (ensures state_eq_opt true (BS.machine_eval_code c f s1) (BS.machine_eval_code c f s2)) [SMTPat (BS.machine_eval_code c f s1); SMTPat (BS.machine_eval_code c f s2)] = eval_code_eq_core true c f s1; eval_code_eq_core true c f s2 let eval_codes_eq_t (cs:codes) (f:fuel) (s1 s2:machine_state) : Lemma (requires state_eq_S true s1 s2) (ensures state_eq_opt true (BS.machine_eval_codes cs f s1) (BS.machine_eval_codes cs f s2)) [SMTPat (BS.machine_eval_codes cs f s1); SMTPat (BS.machine_eval_codes cs f s2)] = eval_codes_eq_core true cs f s1; eval_codes_eq_core true cs f s2 let eval_while_eq_t (cond:ocmp) (body:code) (f:fuel) (s1 s2:machine_state) : Lemma (requires state_eq_S true s1 s2) (ensures state_eq_opt true (BS.machine_eval_while cond body f s1) (BS.machine_eval_while cond body f s2)) [SMTPat (BS.machine_eval_while cond body f s1); SMTPat (BS.machine_eval_while cond body f s2)] = eval_while_eq_core true cond body f s1; eval_while_eq_core true cond body f s2 let eval_code_ts (g:bool) (c:code) (s0:machine_state) (f0:fuel) (s1:machine_state) : Type0 = state_eq_opt g (BS.machine_eval_code c f0 s0) (Some s1) let rec increase_fuel (g:bool) (c:code) (s0:machine_state) (f0:fuel) (sN:machine_state) (fN:fuel) : Lemma (requires eval_code_ts g c s0 f0 sN /\ f0 <= fN) (ensures eval_code_ts g c s0 fN sN) (decreases %[f0; c]) = match c with | Ins ins -> () | Block l -> increase_fuels g l s0 f0 sN fN | IfElse cond t f -> let (s0, b0) = BS.machine_eval_ocmp s0 cond in if b0 then increase_fuel g t s0 f0 sN fN else increase_fuel g f s0 f0 sN fN | While cond c -> let (s1, b0) = BS.machine_eval_ocmp s0 cond in if b0 then ( match BS.machine_eval_code c (f0 - 1) s1 with | None -> () | Some s2 -> increase_fuel g c s1 (f0 - 1) s2 (fN - 1); if s2.BS.ms_ok then increase_fuel g (While cond c) s2 (f0 - 1) sN (fN - 1) else () ) and increase_fuels (g:bool) (c:codes) (s0:machine_state) (f0:fuel) (sN:machine_state) (fN:fuel) : Lemma (requires eval_code_ts g (Block c) s0 f0 sN /\ f0 <= fN) (ensures eval_code_ts g (Block c) s0 fN sN) (decreases %[f0; c]) = match c with | [] -> () | h::t -> ( let Some s1 = BS.machine_eval_code h f0 s0 in increase_fuel g h s0 f0 s1 fN; increase_fuels g t s1 f0 sN fN ) let lemma_cmp_eq s o1 o2 = reveal_opaque (`%BS.eval_ocmp_opaque) BS.eval_ocmp_opaque let lemma_cmp_ne s o1 o2 = reveal_opaque (`%BS.eval_ocmp_opaque) BS.eval_ocmp_opaque let lemma_cmp_le s o1 o2 = reveal_opaque (`%BS.eval_ocmp_opaque) BS.eval_ocmp_opaque let lemma_cmp_ge s o1 o2 = reveal_opaque (`%BS.eval_ocmp_opaque) BS.eval_ocmp_opaque let lemma_cmp_lt s o1 o2 = reveal_opaque (`%BS.eval_ocmp_opaque) BS.eval_ocmp_opaque let lemma_cmp_gt s o1 o2 = reveal_opaque (`%BS.eval_ocmp_opaque) BS.eval_ocmp_opaque let lemma_valid_cmp_eq s o1 o2 = () let lemma_valid_cmp_ne s o1 o2 = () let lemma_valid_cmp_le s o1 o2 = () let lemma_valid_cmp_ge s o1 o2 = () let lemma_valid_cmp_lt s o1 o2 = () let lemma_valid_cmp_gt s o1 o2 = () let compute_merge_total (f0:fuel) (fM:fuel) = if f0 > fM then f0 else fM let lemma_merge_total (b0:codes) (s0:vale_state) (f0:fuel) (sM:vale_state) (fM:fuel) (sN:vale_state) = let f = if f0 > fM then f0 else fM in increase_fuel (codes_modifies_ghost b0) (Cons?.hd b0) (state_to_S s0) f0 (state_to_S sM) f; increase_fuel (codes_modifies_ghost b0) (Block (Cons?.tl b0)) (state_to_S sM) fM (state_to_S sN) f let lemma_empty_total (s0:vale_state) (bN:codes) = (s0, 0) let lemma_ifElse_total (ifb:ocmp) (ct:code) (cf:code) (s0:vale_state) = (eval_ocmp s0 ifb, {s0 with vs_flags = havoc_flags}, s0, 0) let lemma_havoc_flags : squash (Flags.to_fun havoc_flags == BS.havoc_flags) = assert (FStar.FunctionalExtensionality.feq (Flags.to_fun havoc_flags) BS.havoc_flags) let lemma_ifElseTrue_total (ifb:ocmp) (ct:code) (cf:code) (s0:vale_state) (f0:fuel) (sM:vale_state) = reveal_opaque (`%BS.valid_ocmp_opaque) BS.valid_ocmp_opaque; reveal_opaque (`%BS.eval_ocmp_opaque) BS.eval_ocmp_opaque let lemma_ifElseFalse_total (ifb:ocmp) (ct:code) (cf:code) (s0:vale_state) (f0:fuel) (sM:vale_state) = reveal_opaque (`%BS.valid_ocmp_opaque) BS.valid_ocmp_opaque; reveal_opaque (`%BS.eval_ocmp_opaque) BS.eval_ocmp_opaque let eval_while_inv_temp (c:code) (s0:vale_state) (fW:fuel) (sW:vale_state) : Type0 = forall (f:nat).{:pattern BS.machine_eval_code c f (state_to_S sW)} Some? (BS.machine_eval_code c f (state_to_S sW)) ==> state_eq_opt (code_modifies_ghost c) (BS.machine_eval_code c (f + fW) (state_to_S s0)) (BS.machine_eval_code c f (state_to_S sW)) let eval_while_inv (c:code) (s0:vale_state) (fW:fuel) (sW:vale_state) : Type0 = eval_while_inv_temp c s0 fW sW let lemma_while_total (b:ocmp) (c:code) (s0:vale_state) = (s0, 0)
{ "checked_file": "/", "dependencies": [ "Vale.X64.StateLemmas.fsti.checked", "Vale.X64.State.fsti.checked", "Vale.X64.Memory.fsti.checked", "Vale.X64.Machine_Semantics_s.fst.checked", "Vale.X64.Machine_s.fst.checked", "Vale.X64.Instruction_s.fsti.checked", "Vale.X64.Flags.fsti.checked", "Vale.X64.Bytes_Code_s.fst.checked", "prims.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.FunctionalExtensionality.fsti.checked" ], "interface_file": true, "source_file": "Vale.X64.Lemmas.fst" }
[ { "abbrev": true, "full_module": "Vale.X64.Memory", "short_module": "ME" }, { "abbrev": true, "full_module": "Vale.X64.Machine_Semantics_s", "short_module": "BS" }, { "abbrev": false, "full_module": "Vale.X64.Bytes_Code_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Instruction_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.StateLemmas", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.State", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Machine_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": true, "full_module": "Vale.Lib.Map16", "short_module": "Map16" }, { "abbrev": true, "full_module": "Vale.X64.Machine_Semantics_s", "short_module": "BS" }, { "abbrev": false, "full_module": "Vale.X64.Bytes_Code_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.StateLemmas", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.State", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Machine_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.HeapLemmas", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.HeapImpl", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.Heap", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 0, "max_fuel": 2, "max_ifuel": 1, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": true, "smtencoding_l_arith_repr": "native", "smtencoding_nl_arith_repr": "wrapped", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [ "smt.arith.nl=false", "smt.QI.EAGER_THRESHOLD=100", "smt.CASE_SPLIT=3" ], "z3refresh": false, "z3rlimit": 30, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
b: Vale.X64.Bytes_Code_s.ocmp -> c: Vale.X64.StateLemmas.code -> s0: Vale.X64.State.vale_state -> sW: Vale.X64.State.vale_state -> fW: Vale.X64.Lemmas.fuel -> Prims.Ghost (Vale.X64.State.vale_state * Vale.X64.Lemmas.fuel)
Prims.Ghost
[]
[]
[ "Vale.X64.Bytes_Code_s.ocmp", "Vale.X64.StateLemmas.code", "Vale.X64.State.vale_state", "Vale.X64.Lemmas.fuel", "FStar.Pervasives.Native.Mktuple2", "Vale.X64.State.Mkvale_state", "Vale.X64.State.__proj__Mkvale_state__item__vs_ok", "Vale.X64.State.__proj__Mkvale_state__item__vs_regs", "Vale.X64.Lemmas.havoc_flags", "Vale.X64.State.__proj__Mkvale_state__item__vs_heap", "Vale.X64.State.__proj__Mkvale_state__item__vs_stack", "Vale.X64.State.__proj__Mkvale_state__item__vs_stackTaint", "FStar.Pervasives.Native.tuple2" ]
[]
false
false
false
false
false
let lemma_whileTrue_total (b: ocmp) (c: code) (s0 sW: vale_state) (fW: fuel) =
({ sW with vs_flags = havoc_flags }, fW)
false
prims.fst
Prims.pure_wp'
val pure_wp' : a: Type -> Type
let pure_wp' (a: Type) = pure_post a -> GTot pure_pre
{ "file_name": "ulib/prims.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 53, "end_line": 304, "start_col": 0, "start_line": 304 }
(* Copyright 2008-2020 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 Prims /// This module is implicitly opened in the scope of all other modules. /// /// It provides the very basic primitives on which F* is /// built, including the definition of total functions, the basic /// logical connectives, the PURE and GHOST effects and the like. /// /// While some of the primitives have logical significance, others are /// define various conveniences in the language, e.g., type of /// attributes. (***** Begin trusted primitives *****) (** Primitives up to the definition of the GTot effect are trusted Beyond that all definitions are fully verified *) (** Type of attributes *) assume new type attribute : Type0 (** An attribute indicating that some definition must be processed by the Dijkstra monads for free construction *) assume val cps:attribute (** A predicate to express when a type supports decidable equality The type-checker emits axioms for [hasEq] for each inductive type *) assume type hasEq : Type -> GTot Type0 (** A convenient abbreviation, [eqtype] is the type of types in universe 0 which support decidable equality *) type eqtype = a: Type0{hasEq a} (** [bool] is a two element type with elements [true] and [false]. We assume it is primitive, for convenient interop with other languages, although it could easily be defined as an inductive type with two cases, [BTrue | BFalse] *) assume new type bool : eqtype (** [empty] is the empty inductive type. The type with no inhabitants represents logical falsehood. Note, [empty] is seldom used directly in F*. We instead use its "squashed" variant, [False], see below. *) type empty = (** [trivial] is the singleton inductive type---it is trivially inhabited. Like [empty], [trivial] is seldom used. We instead use its "squashed" variants, [True] *) type trivial = | T (** [unit]: another singleton type, with its only inhabitant written [()] we assume it is primitive, for convenient interop with other languages *) assume new type unit : eqtype (** [squash p] is a central type in F*---[squash p] is the proof irrelevant analog of [p] and is represented as a unit refinement. Squashed proofs are typically discharged using an SMT solver, without any proof terms explicitly reconstructed. As such, one way to think of [squash p] is as the type of properties proven using classical axioms without building proof terms. Note, [squash p] is just a unit refinement, it resides in universe 0, lowering the universe of [p]. From this perspective, one may also see [squash] as a coercion down to universe 0. The type is marked [tac_opaque] to indicate to Meta-F* that instances of [squash] should not be unfolded when evaluating tactics (since many optimizations in F*'s SMT encoding rely specifically on occurrences of [squash]. See FStar.Squash for various ways of manipulating squashed types. *) [@@ "tac_opaque"] type squash (p: Type) : Type0 = x: unit{p} (** [auto_squash] is equivalent to [squash]. However, F* will automatically insert `auto_squash` when simplifying terms, converting terms of the form `p /\ True` to `auto_squash p`. We distinguish these automatically inserted squashes from explicit, user-written squashes. A user should not have to manipulate [auto_squash] at all, except in rare circumstances when writing tactics to process proofs that have already been partially simplified by F*'s simplifier. *) let auto_squash (p: Type) = squash p (** The [logical] type is transitionary. It is just an abbreviation for [Type0], but is used to classify uses of the basic squashed logical connectives that follow. Some day, we plan to remove the [logical] type, replacing it with [prop] (also defined below). The type is marked [private] to intentionally prevent user code from referencing this type, hopefully easing the removal of [logical] in the future. *) private type logical = Type0 (** An attribute indicating that a symbol is an smt theory symbol and hence may not be used in smt patterns. The typechecker warns if such symbols are used in patterns *) assume val smt_theory_symbol:attribute (** [l_True] has a special bit of syntactic sugar. It is written just as "True" and rendered in the ide as [True]. It is a squashed version of constructive truth, [trivial]. *) [@@ "tac_opaque"; smt_theory_symbol] let l_True:logical = squash trivial (** [l_False] has a special bit of syntactic sugar. It is written just as "False" and rendered in the ide as [Falsee]. It is a squashed version of constructive falsehood, the empty type. *) [@@ "tac_opaque"; smt_theory_symbol] let l_False:logical = squash empty (** The type of provable equalities, defined as the usual inductive type with a single constructor for reflexivity. As with the other connectives, we often work instead with the squashed version of equality, below. *) type equals (#a: Type) (x: a) : a -> Type = | Refl : equals x x (** [eq2] is the squashed version of [equals]. It's a proof irrelevant, homogeneous equality in Type#0 and is written with an infix binary [==]. TODO: instead of hard-wiring the == syntax, we should just rename eq2 to op_Equals_Equals *) [@@ "tac_opaque"; smt_theory_symbol] type eq2 (#a: Type) (x: a) (y: a) : logical = squash (equals x y) (** bool-to-type coercion: This is often automatically inserted type, when using a boolean in context expecting a type. But, occasionally, one may have to write [b2t] explicitly *) type b2t (b: bool) : logical = (b == true) (** constructive conjunction *) type pair (p: Type) (q: Type) = | Pair : _1:p -> _2:q -> pair p q (** squashed conjunction, specialized to [Type0], written with an infix binary [/\] *) [@@ "tac_opaque"; smt_theory_symbol] type l_and (p: logical) (q: logical) : logical = squash (pair p q) (** constructive disjunction *) type sum (p: Type) (q: Type) = | Left : v:p -> sum p q | Right : v:q -> sum p q (** squashed disjunction, specialized to [Type0], written with an infix binary [\/] *) [@@ "tac_opaque"; smt_theory_symbol] type l_or (p: logical) (q: logical) : logical = squash (sum p q) (** squashed (non-dependent) implication, specialized to [Type0], written with an infix binary [==>]. Note, [==>] binds weaker than [/\] and [\/] *) [@@ "tac_opaque"; smt_theory_symbol] type l_imp (p: logical) (q: logical) : logical = squash (p -> GTot q) (* ^^^ NB: The GTot effect is primitive; *) (* elaborated using GHOST a few lines below *) (** squashed double implication, infix binary [<==>] *) [@@ smt_theory_symbol] type l_iff (p: logical) (q: logical) : logical = (p ==> q) /\ (q ==> p) (** squashed negation, prefix unary [~] *) [@@ smt_theory_symbol] type l_not (p: logical) : logical = l_imp p False (** l_ITE is a weak form of if-then-else at the level of logical formulae. It's not much used. TODO: Can we remove it *) unfold type l_ITE (p: logical) (q: logical) (r: logical) : logical = (p ==> q) /\ (~p ==> r) (** One of the main axioms provided by prims is [precedes], a built-in well-founded partial order over all terms. It's typically written with an infix binary [<<]. The [<<] order includes: * The [<] ordering on natural numbers * The subterm ordering on inductive types * [f x << D f] for data constructors D of an inductive t whose arguments include a ghost or total function returning a t *) assume type precedes : #a: Type -> #b: Type -> a -> b -> Type0 (** The type of primitive strings of characters; See FStar.String *) assume new type string : eqtype (** This attribute can be added to the declaration or definition of any top-level symbol. It causes F* to report a warning on any use of that symbol, printing the [msg] argument. This is used, for instance to: - tag every escape hatch, e.g., [assume], [admit], etc Reports for uses of symbols tagged with this attribute are controlled using the `--report_assumes` option and warning number 334. See tests/micro-benchmarks/WarnOnUse.fst *) assume val warn_on_use (msg: string) : Tot unit (** The [deprecated "s"] attribute: "s" is an alternative function that should be printed in the warning it can be omitted if the use case has no such function *) assume val deprecated (s: string) : Tot unit (** Within the SMT encoding, we have a relation [(HasType e t)] asserting that (the encoding of) [e] has a type corresponding to (the encoding of) [t]. It is sometimes convenient, e.g., when writing triggers for quantifiers, to have access to this relation at the source level. The [has_type] predicate below reflects the SMT encodings [HasType] relation. We also use it to define the type [prop] or proof irrelevant propositions, below. Note, unless you have a really good reason, you probably don't want to use this [has_type] predicate. F*'s type theory certainly does not internalize its own typing judgment *) [@@deprecated "'has_type' is intended for internal use and debugging purposes only; \ do not rely on it for your proofs"] assume type has_type : #a: Type -> a -> Type -> Type0 (** Squashed universal quantification, or dependent products, written [forall (x:a). p x], specialized to Type0 *) [@@ "tac_opaque"; smt_theory_symbol] type l_Forall (#a: Type) (p: (a -> GTot Type0)) : logical = squash (x: a -> GTot (p x)) #push-options "--warn_error -288" (** [p1 `subtype_of` p2] when every element of [p1] is also an element of [p2]. *) let subtype_of (p1 p2: Type) = forall (x: p1). has_type x p2 #pop-options (** The type of squashed types. Note, the [prop] type is a work in progress in F*. In particular, we would like in the future to more systematically use [prop] for proof-irrelevant propositions throughout the libraries. However, we still use [Type0] in many places. See https://github.com/FStarLang/FStar/issues/1048 for more details and the current status of the work. *) type prop = a: Type0{a `subtype_of` unit} (**** The PURE effect *) (** The type of pure preconditions *) let pure_pre = Type0 (** Pure postconditions, predicates on [a], on which the precondition [pre] is also valid. This provides a way for postcondition formula to be typed in a context where they can assume the validity of the precondition. This is discussed extensively in Issue #57 *) let pure_post' (a pre: Type) = _: a{pre} -> GTot Type0 let pure_post (a: Type) = pure_post' a True (** A pure weakest precondition transforms postconditions on [a]-typed results to pure preconditions We require the weakest preconditions to satisfy the monotonicity property over the postconditions To enforce it, we first define a vanilla wp type,
{ "checked_file": "/", "dependencies": [], "interface_file": false, "source_file": "prims.fst" }
[ { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
a: Type -> Type
Prims.Tot
[ "total" ]
[]
[ "Prims.pure_post", "Prims.pure_pre" ]
[]
false
false
false
true
true
let pure_wp' (a: Type) =
pure_post a -> GTot pure_pre
false
prims.fst
Prims.pure_post
val pure_post : a: Type -> Type
let pure_post (a: Type) = pure_post' a True
{ "file_name": "ulib/prims.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 43, "end_line": 295, "start_col": 0, "start_line": 295 }
(* Copyright 2008-2020 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 Prims /// This module is implicitly opened in the scope of all other modules. /// /// It provides the very basic primitives on which F* is /// built, including the definition of total functions, the basic /// logical connectives, the PURE and GHOST effects and the like. /// /// While some of the primitives have logical significance, others are /// define various conveniences in the language, e.g., type of /// attributes. (***** Begin trusted primitives *****) (** Primitives up to the definition of the GTot effect are trusted Beyond that all definitions are fully verified *) (** Type of attributes *) assume new type attribute : Type0 (** An attribute indicating that some definition must be processed by the Dijkstra monads for free construction *) assume val cps:attribute (** A predicate to express when a type supports decidable equality The type-checker emits axioms for [hasEq] for each inductive type *) assume type hasEq : Type -> GTot Type0 (** A convenient abbreviation, [eqtype] is the type of types in universe 0 which support decidable equality *) type eqtype = a: Type0{hasEq a} (** [bool] is a two element type with elements [true] and [false]. We assume it is primitive, for convenient interop with other languages, although it could easily be defined as an inductive type with two cases, [BTrue | BFalse] *) assume new type bool : eqtype (** [empty] is the empty inductive type. The type with no inhabitants represents logical falsehood. Note, [empty] is seldom used directly in F*. We instead use its "squashed" variant, [False], see below. *) type empty = (** [trivial] is the singleton inductive type---it is trivially inhabited. Like [empty], [trivial] is seldom used. We instead use its "squashed" variants, [True] *) type trivial = | T (** [unit]: another singleton type, with its only inhabitant written [()] we assume it is primitive, for convenient interop with other languages *) assume new type unit : eqtype (** [squash p] is a central type in F*---[squash p] is the proof irrelevant analog of [p] and is represented as a unit refinement. Squashed proofs are typically discharged using an SMT solver, without any proof terms explicitly reconstructed. As such, one way to think of [squash p] is as the type of properties proven using classical axioms without building proof terms. Note, [squash p] is just a unit refinement, it resides in universe 0, lowering the universe of [p]. From this perspective, one may also see [squash] as a coercion down to universe 0. The type is marked [tac_opaque] to indicate to Meta-F* that instances of [squash] should not be unfolded when evaluating tactics (since many optimizations in F*'s SMT encoding rely specifically on occurrences of [squash]. See FStar.Squash for various ways of manipulating squashed types. *) [@@ "tac_opaque"] type squash (p: Type) : Type0 = x: unit{p} (** [auto_squash] is equivalent to [squash]. However, F* will automatically insert `auto_squash` when simplifying terms, converting terms of the form `p /\ True` to `auto_squash p`. We distinguish these automatically inserted squashes from explicit, user-written squashes. A user should not have to manipulate [auto_squash] at all, except in rare circumstances when writing tactics to process proofs that have already been partially simplified by F*'s simplifier. *) let auto_squash (p: Type) = squash p (** The [logical] type is transitionary. It is just an abbreviation for [Type0], but is used to classify uses of the basic squashed logical connectives that follow. Some day, we plan to remove the [logical] type, replacing it with [prop] (also defined below). The type is marked [private] to intentionally prevent user code from referencing this type, hopefully easing the removal of [logical] in the future. *) private type logical = Type0 (** An attribute indicating that a symbol is an smt theory symbol and hence may not be used in smt patterns. The typechecker warns if such symbols are used in patterns *) assume val smt_theory_symbol:attribute (** [l_True] has a special bit of syntactic sugar. It is written just as "True" and rendered in the ide as [True]. It is a squashed version of constructive truth, [trivial]. *) [@@ "tac_opaque"; smt_theory_symbol] let l_True:logical = squash trivial (** [l_False] has a special bit of syntactic sugar. It is written just as "False" and rendered in the ide as [Falsee]. It is a squashed version of constructive falsehood, the empty type. *) [@@ "tac_opaque"; smt_theory_symbol] let l_False:logical = squash empty (** The type of provable equalities, defined as the usual inductive type with a single constructor for reflexivity. As with the other connectives, we often work instead with the squashed version of equality, below. *) type equals (#a: Type) (x: a) : a -> Type = | Refl : equals x x (** [eq2] is the squashed version of [equals]. It's a proof irrelevant, homogeneous equality in Type#0 and is written with an infix binary [==]. TODO: instead of hard-wiring the == syntax, we should just rename eq2 to op_Equals_Equals *) [@@ "tac_opaque"; smt_theory_symbol] type eq2 (#a: Type) (x: a) (y: a) : logical = squash (equals x y) (** bool-to-type coercion: This is often automatically inserted type, when using a boolean in context expecting a type. But, occasionally, one may have to write [b2t] explicitly *) type b2t (b: bool) : logical = (b == true) (** constructive conjunction *) type pair (p: Type) (q: Type) = | Pair : _1:p -> _2:q -> pair p q (** squashed conjunction, specialized to [Type0], written with an infix binary [/\] *) [@@ "tac_opaque"; smt_theory_symbol] type l_and (p: logical) (q: logical) : logical = squash (pair p q) (** constructive disjunction *) type sum (p: Type) (q: Type) = | Left : v:p -> sum p q | Right : v:q -> sum p q (** squashed disjunction, specialized to [Type0], written with an infix binary [\/] *) [@@ "tac_opaque"; smt_theory_symbol] type l_or (p: logical) (q: logical) : logical = squash (sum p q) (** squashed (non-dependent) implication, specialized to [Type0], written with an infix binary [==>]. Note, [==>] binds weaker than [/\] and [\/] *) [@@ "tac_opaque"; smt_theory_symbol] type l_imp (p: logical) (q: logical) : logical = squash (p -> GTot q) (* ^^^ NB: The GTot effect is primitive; *) (* elaborated using GHOST a few lines below *) (** squashed double implication, infix binary [<==>] *) [@@ smt_theory_symbol] type l_iff (p: logical) (q: logical) : logical = (p ==> q) /\ (q ==> p) (** squashed negation, prefix unary [~] *) [@@ smt_theory_symbol] type l_not (p: logical) : logical = l_imp p False (** l_ITE is a weak form of if-then-else at the level of logical formulae. It's not much used. TODO: Can we remove it *) unfold type l_ITE (p: logical) (q: logical) (r: logical) : logical = (p ==> q) /\ (~p ==> r) (** One of the main axioms provided by prims is [precedes], a built-in well-founded partial order over all terms. It's typically written with an infix binary [<<]. The [<<] order includes: * The [<] ordering on natural numbers * The subterm ordering on inductive types * [f x << D f] for data constructors D of an inductive t whose arguments include a ghost or total function returning a t *) assume type precedes : #a: Type -> #b: Type -> a -> b -> Type0 (** The type of primitive strings of characters; See FStar.String *) assume new type string : eqtype (** This attribute can be added to the declaration or definition of any top-level symbol. It causes F* to report a warning on any use of that symbol, printing the [msg] argument. This is used, for instance to: - tag every escape hatch, e.g., [assume], [admit], etc Reports for uses of symbols tagged with this attribute are controlled using the `--report_assumes` option and warning number 334. See tests/micro-benchmarks/WarnOnUse.fst *) assume val warn_on_use (msg: string) : Tot unit (** The [deprecated "s"] attribute: "s" is an alternative function that should be printed in the warning it can be omitted if the use case has no such function *) assume val deprecated (s: string) : Tot unit (** Within the SMT encoding, we have a relation [(HasType e t)] asserting that (the encoding of) [e] has a type corresponding to (the encoding of) [t]. It is sometimes convenient, e.g., when writing triggers for quantifiers, to have access to this relation at the source level. The [has_type] predicate below reflects the SMT encodings [HasType] relation. We also use it to define the type [prop] or proof irrelevant propositions, below. Note, unless you have a really good reason, you probably don't want to use this [has_type] predicate. F*'s type theory certainly does not internalize its own typing judgment *) [@@deprecated "'has_type' is intended for internal use and debugging purposes only; \ do not rely on it for your proofs"] assume type has_type : #a: Type -> a -> Type -> Type0 (** Squashed universal quantification, or dependent products, written [forall (x:a). p x], specialized to Type0 *) [@@ "tac_opaque"; smt_theory_symbol] type l_Forall (#a: Type) (p: (a -> GTot Type0)) : logical = squash (x: a -> GTot (p x)) #push-options "--warn_error -288" (** [p1 `subtype_of` p2] when every element of [p1] is also an element of [p2]. *) let subtype_of (p1 p2: Type) = forall (x: p1). has_type x p2 #pop-options (** The type of squashed types. Note, the [prop] type is a work in progress in F*. In particular, we would like in the future to more systematically use [prop] for proof-irrelevant propositions throughout the libraries. However, we still use [Type0] in many places. See https://github.com/FStarLang/FStar/issues/1048 for more details and the current status of the work. *) type prop = a: Type0{a `subtype_of` unit} (**** The PURE effect *) (** The type of pure preconditions *) let pure_pre = Type0 (** Pure postconditions, predicates on [a], on which the precondition [pre] is also valid. This provides a way for postcondition formula to be typed in a context where they can assume the validity of the precondition. This is discussed extensively in Issue #57 *)
{ "checked_file": "/", "dependencies": [], "interface_file": false, "source_file": "prims.fst" }
[ { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
a: Type -> Type
Prims.Tot
[ "total" ]
[]
[ "Prims.pure_post'", "Prims.l_True" ]
[]
false
false
false
true
true
let pure_post (a: Type) =
pure_post' a True
false
prims.fst
Prims.pure_wp_monotonic
val pure_wp_monotonic : a: Type -> wp: Prims.pure_wp' a -> Prims.logical
let pure_wp_monotonic = pure_wp_monotonic0
{ "file_name": "ulib/prims.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 42, "end_line": 316, "start_col": 0, "start_line": 316 }
(* Copyright 2008-2020 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 Prims /// This module is implicitly opened in the scope of all other modules. /// /// It provides the very basic primitives on which F* is /// built, including the definition of total functions, the basic /// logical connectives, the PURE and GHOST effects and the like. /// /// While some of the primitives have logical significance, others are /// define various conveniences in the language, e.g., type of /// attributes. (***** Begin trusted primitives *****) (** Primitives up to the definition of the GTot effect are trusted Beyond that all definitions are fully verified *) (** Type of attributes *) assume new type attribute : Type0 (** An attribute indicating that some definition must be processed by the Dijkstra monads for free construction *) assume val cps:attribute (** A predicate to express when a type supports decidable equality The type-checker emits axioms for [hasEq] for each inductive type *) assume type hasEq : Type -> GTot Type0 (** A convenient abbreviation, [eqtype] is the type of types in universe 0 which support decidable equality *) type eqtype = a: Type0{hasEq a} (** [bool] is a two element type with elements [true] and [false]. We assume it is primitive, for convenient interop with other languages, although it could easily be defined as an inductive type with two cases, [BTrue | BFalse] *) assume new type bool : eqtype (** [empty] is the empty inductive type. The type with no inhabitants represents logical falsehood. Note, [empty] is seldom used directly in F*. We instead use its "squashed" variant, [False], see below. *) type empty = (** [trivial] is the singleton inductive type---it is trivially inhabited. Like [empty], [trivial] is seldom used. We instead use its "squashed" variants, [True] *) type trivial = | T (** [unit]: another singleton type, with its only inhabitant written [()] we assume it is primitive, for convenient interop with other languages *) assume new type unit : eqtype (** [squash p] is a central type in F*---[squash p] is the proof irrelevant analog of [p] and is represented as a unit refinement. Squashed proofs are typically discharged using an SMT solver, without any proof terms explicitly reconstructed. As such, one way to think of [squash p] is as the type of properties proven using classical axioms without building proof terms. Note, [squash p] is just a unit refinement, it resides in universe 0, lowering the universe of [p]. From this perspective, one may also see [squash] as a coercion down to universe 0. The type is marked [tac_opaque] to indicate to Meta-F* that instances of [squash] should not be unfolded when evaluating tactics (since many optimizations in F*'s SMT encoding rely specifically on occurrences of [squash]. See FStar.Squash for various ways of manipulating squashed types. *) [@@ "tac_opaque"] type squash (p: Type) : Type0 = x: unit{p} (** [auto_squash] is equivalent to [squash]. However, F* will automatically insert `auto_squash` when simplifying terms, converting terms of the form `p /\ True` to `auto_squash p`. We distinguish these automatically inserted squashes from explicit, user-written squashes. A user should not have to manipulate [auto_squash] at all, except in rare circumstances when writing tactics to process proofs that have already been partially simplified by F*'s simplifier. *) let auto_squash (p: Type) = squash p (** The [logical] type is transitionary. It is just an abbreviation for [Type0], but is used to classify uses of the basic squashed logical connectives that follow. Some day, we plan to remove the [logical] type, replacing it with [prop] (also defined below). The type is marked [private] to intentionally prevent user code from referencing this type, hopefully easing the removal of [logical] in the future. *) private type logical = Type0 (** An attribute indicating that a symbol is an smt theory symbol and hence may not be used in smt patterns. The typechecker warns if such symbols are used in patterns *) assume val smt_theory_symbol:attribute (** [l_True] has a special bit of syntactic sugar. It is written just as "True" and rendered in the ide as [True]. It is a squashed version of constructive truth, [trivial]. *) [@@ "tac_opaque"; smt_theory_symbol] let l_True:logical = squash trivial (** [l_False] has a special bit of syntactic sugar. It is written just as "False" and rendered in the ide as [Falsee]. It is a squashed version of constructive falsehood, the empty type. *) [@@ "tac_opaque"; smt_theory_symbol] let l_False:logical = squash empty (** The type of provable equalities, defined as the usual inductive type with a single constructor for reflexivity. As with the other connectives, we often work instead with the squashed version of equality, below. *) type equals (#a: Type) (x: a) : a -> Type = | Refl : equals x x (** [eq2] is the squashed version of [equals]. It's a proof irrelevant, homogeneous equality in Type#0 and is written with an infix binary [==]. TODO: instead of hard-wiring the == syntax, we should just rename eq2 to op_Equals_Equals *) [@@ "tac_opaque"; smt_theory_symbol] type eq2 (#a: Type) (x: a) (y: a) : logical = squash (equals x y) (** bool-to-type coercion: This is often automatically inserted type, when using a boolean in context expecting a type. But, occasionally, one may have to write [b2t] explicitly *) type b2t (b: bool) : logical = (b == true) (** constructive conjunction *) type pair (p: Type) (q: Type) = | Pair : _1:p -> _2:q -> pair p q (** squashed conjunction, specialized to [Type0], written with an infix binary [/\] *) [@@ "tac_opaque"; smt_theory_symbol] type l_and (p: logical) (q: logical) : logical = squash (pair p q) (** constructive disjunction *) type sum (p: Type) (q: Type) = | Left : v:p -> sum p q | Right : v:q -> sum p q (** squashed disjunction, specialized to [Type0], written with an infix binary [\/] *) [@@ "tac_opaque"; smt_theory_symbol] type l_or (p: logical) (q: logical) : logical = squash (sum p q) (** squashed (non-dependent) implication, specialized to [Type0], written with an infix binary [==>]. Note, [==>] binds weaker than [/\] and [\/] *) [@@ "tac_opaque"; smt_theory_symbol] type l_imp (p: logical) (q: logical) : logical = squash (p -> GTot q) (* ^^^ NB: The GTot effect is primitive; *) (* elaborated using GHOST a few lines below *) (** squashed double implication, infix binary [<==>] *) [@@ smt_theory_symbol] type l_iff (p: logical) (q: logical) : logical = (p ==> q) /\ (q ==> p) (** squashed negation, prefix unary [~] *) [@@ smt_theory_symbol] type l_not (p: logical) : logical = l_imp p False (** l_ITE is a weak form of if-then-else at the level of logical formulae. It's not much used. TODO: Can we remove it *) unfold type l_ITE (p: logical) (q: logical) (r: logical) : logical = (p ==> q) /\ (~p ==> r) (** One of the main axioms provided by prims is [precedes], a built-in well-founded partial order over all terms. It's typically written with an infix binary [<<]. The [<<] order includes: * The [<] ordering on natural numbers * The subterm ordering on inductive types * [f x << D f] for data constructors D of an inductive t whose arguments include a ghost or total function returning a t *) assume type precedes : #a: Type -> #b: Type -> a -> b -> Type0 (** The type of primitive strings of characters; See FStar.String *) assume new type string : eqtype (** This attribute can be added to the declaration or definition of any top-level symbol. It causes F* to report a warning on any use of that symbol, printing the [msg] argument. This is used, for instance to: - tag every escape hatch, e.g., [assume], [admit], etc Reports for uses of symbols tagged with this attribute are controlled using the `--report_assumes` option and warning number 334. See tests/micro-benchmarks/WarnOnUse.fst *) assume val warn_on_use (msg: string) : Tot unit (** The [deprecated "s"] attribute: "s" is an alternative function that should be printed in the warning it can be omitted if the use case has no such function *) assume val deprecated (s: string) : Tot unit (** Within the SMT encoding, we have a relation [(HasType e t)] asserting that (the encoding of) [e] has a type corresponding to (the encoding of) [t]. It is sometimes convenient, e.g., when writing triggers for quantifiers, to have access to this relation at the source level. The [has_type] predicate below reflects the SMT encodings [HasType] relation. We also use it to define the type [prop] or proof irrelevant propositions, below. Note, unless you have a really good reason, you probably don't want to use this [has_type] predicate. F*'s type theory certainly does not internalize its own typing judgment *) [@@deprecated "'has_type' is intended for internal use and debugging purposes only; \ do not rely on it for your proofs"] assume type has_type : #a: Type -> a -> Type -> Type0 (** Squashed universal quantification, or dependent products, written [forall (x:a). p x], specialized to Type0 *) [@@ "tac_opaque"; smt_theory_symbol] type l_Forall (#a: Type) (p: (a -> GTot Type0)) : logical = squash (x: a -> GTot (p x)) #push-options "--warn_error -288" (** [p1 `subtype_of` p2] when every element of [p1] is also an element of [p2]. *) let subtype_of (p1 p2: Type) = forall (x: p1). has_type x p2 #pop-options (** The type of squashed types. Note, the [prop] type is a work in progress in F*. In particular, we would like in the future to more systematically use [prop] for proof-irrelevant propositions throughout the libraries. However, we still use [Type0] in many places. See https://github.com/FStarLang/FStar/issues/1048 for more details and the current status of the work. *) type prop = a: Type0{a `subtype_of` unit} (**** The PURE effect *) (** The type of pure preconditions *) let pure_pre = Type0 (** Pure postconditions, predicates on [a], on which the precondition [pre] is also valid. This provides a way for postcondition formula to be typed in a context where they can assume the validity of the precondition. This is discussed extensively in Issue #57 *) let pure_post' (a pre: Type) = _: a{pre} -> GTot Type0 let pure_post (a: Type) = pure_post' a True (** A pure weakest precondition transforms postconditions on [a]-typed results to pure preconditions We require the weakest preconditions to satisfy the monotonicity property over the postconditions To enforce it, we first define a vanilla wp type, and then refine it with the monotonicity condition *) let pure_wp' (a: Type) = pure_post a -> GTot pure_pre (** The monotonicity predicate is marked opaque_to_smt, meaning that its definition is hidden from the SMT solver, and if required, will need to be explicitly revealed This has the advantage that clients that do not need to work with it directly, don't have the (quantified) definition in their solver context *) let pure_wp_monotonic0 (a:Type) (wp:pure_wp' a) = forall (p q:pure_post a). (forall (x:a). p x ==> q x) ==> (wp p ==> wp q)
{ "checked_file": "/", "dependencies": [], "interface_file": false, "source_file": "prims.fst" }
[ { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
a: Type -> wp: Prims.pure_wp' a -> Prims.logical
Prims.Tot
[ "total" ]
[]
[ "Prims.pure_wp_monotonic0" ]
[]
false
false
false
true
true
let pure_wp_monotonic =
pure_wp_monotonic0
false
prims.fst
Prims.pure_wp_monotonic0
val pure_wp_monotonic0 : a: Type -> wp: Prims.pure_wp' a -> Prims.logical
let pure_wp_monotonic0 (a:Type) (wp:pure_wp' a) = forall (p q:pure_post a). (forall (x:a). p x ==> q x) ==> (wp p ==> wp q)
{ "file_name": "ulib/prims.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 75, "end_line": 313, "start_col": 0, "start_line": 312 }
(* Copyright 2008-2020 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 Prims /// This module is implicitly opened in the scope of all other modules. /// /// It provides the very basic primitives on which F* is /// built, including the definition of total functions, the basic /// logical connectives, the PURE and GHOST effects and the like. /// /// While some of the primitives have logical significance, others are /// define various conveniences in the language, e.g., type of /// attributes. (***** Begin trusted primitives *****) (** Primitives up to the definition of the GTot effect are trusted Beyond that all definitions are fully verified *) (** Type of attributes *) assume new type attribute : Type0 (** An attribute indicating that some definition must be processed by the Dijkstra monads for free construction *) assume val cps:attribute (** A predicate to express when a type supports decidable equality The type-checker emits axioms for [hasEq] for each inductive type *) assume type hasEq : Type -> GTot Type0 (** A convenient abbreviation, [eqtype] is the type of types in universe 0 which support decidable equality *) type eqtype = a: Type0{hasEq a} (** [bool] is a two element type with elements [true] and [false]. We assume it is primitive, for convenient interop with other languages, although it could easily be defined as an inductive type with two cases, [BTrue | BFalse] *) assume new type bool : eqtype (** [empty] is the empty inductive type. The type with no inhabitants represents logical falsehood. Note, [empty] is seldom used directly in F*. We instead use its "squashed" variant, [False], see below. *) type empty = (** [trivial] is the singleton inductive type---it is trivially inhabited. Like [empty], [trivial] is seldom used. We instead use its "squashed" variants, [True] *) type trivial = | T (** [unit]: another singleton type, with its only inhabitant written [()] we assume it is primitive, for convenient interop with other languages *) assume new type unit : eqtype (** [squash p] is a central type in F*---[squash p] is the proof irrelevant analog of [p] and is represented as a unit refinement. Squashed proofs are typically discharged using an SMT solver, without any proof terms explicitly reconstructed. As such, one way to think of [squash p] is as the type of properties proven using classical axioms without building proof terms. Note, [squash p] is just a unit refinement, it resides in universe 0, lowering the universe of [p]. From this perspective, one may also see [squash] as a coercion down to universe 0. The type is marked [tac_opaque] to indicate to Meta-F* that instances of [squash] should not be unfolded when evaluating tactics (since many optimizations in F*'s SMT encoding rely specifically on occurrences of [squash]. See FStar.Squash for various ways of manipulating squashed types. *) [@@ "tac_opaque"] type squash (p: Type) : Type0 = x: unit{p} (** [auto_squash] is equivalent to [squash]. However, F* will automatically insert `auto_squash` when simplifying terms, converting terms of the form `p /\ True` to `auto_squash p`. We distinguish these automatically inserted squashes from explicit, user-written squashes. A user should not have to manipulate [auto_squash] at all, except in rare circumstances when writing tactics to process proofs that have already been partially simplified by F*'s simplifier. *) let auto_squash (p: Type) = squash p (** The [logical] type is transitionary. It is just an abbreviation for [Type0], but is used to classify uses of the basic squashed logical connectives that follow. Some day, we plan to remove the [logical] type, replacing it with [prop] (also defined below). The type is marked [private] to intentionally prevent user code from referencing this type, hopefully easing the removal of [logical] in the future. *) private type logical = Type0 (** An attribute indicating that a symbol is an smt theory symbol and hence may not be used in smt patterns. The typechecker warns if such symbols are used in patterns *) assume val smt_theory_symbol:attribute (** [l_True] has a special bit of syntactic sugar. It is written just as "True" and rendered in the ide as [True]. It is a squashed version of constructive truth, [trivial]. *) [@@ "tac_opaque"; smt_theory_symbol] let l_True:logical = squash trivial (** [l_False] has a special bit of syntactic sugar. It is written just as "False" and rendered in the ide as [Falsee]. It is a squashed version of constructive falsehood, the empty type. *) [@@ "tac_opaque"; smt_theory_symbol] let l_False:logical = squash empty (** The type of provable equalities, defined as the usual inductive type with a single constructor for reflexivity. As with the other connectives, we often work instead with the squashed version of equality, below. *) type equals (#a: Type) (x: a) : a -> Type = | Refl : equals x x (** [eq2] is the squashed version of [equals]. It's a proof irrelevant, homogeneous equality in Type#0 and is written with an infix binary [==]. TODO: instead of hard-wiring the == syntax, we should just rename eq2 to op_Equals_Equals *) [@@ "tac_opaque"; smt_theory_symbol] type eq2 (#a: Type) (x: a) (y: a) : logical = squash (equals x y) (** bool-to-type coercion: This is often automatically inserted type, when using a boolean in context expecting a type. But, occasionally, one may have to write [b2t] explicitly *) type b2t (b: bool) : logical = (b == true) (** constructive conjunction *) type pair (p: Type) (q: Type) = | Pair : _1:p -> _2:q -> pair p q (** squashed conjunction, specialized to [Type0], written with an infix binary [/\] *) [@@ "tac_opaque"; smt_theory_symbol] type l_and (p: logical) (q: logical) : logical = squash (pair p q) (** constructive disjunction *) type sum (p: Type) (q: Type) = | Left : v:p -> sum p q | Right : v:q -> sum p q (** squashed disjunction, specialized to [Type0], written with an infix binary [\/] *) [@@ "tac_opaque"; smt_theory_symbol] type l_or (p: logical) (q: logical) : logical = squash (sum p q) (** squashed (non-dependent) implication, specialized to [Type0], written with an infix binary [==>]. Note, [==>] binds weaker than [/\] and [\/] *) [@@ "tac_opaque"; smt_theory_symbol] type l_imp (p: logical) (q: logical) : logical = squash (p -> GTot q) (* ^^^ NB: The GTot effect is primitive; *) (* elaborated using GHOST a few lines below *) (** squashed double implication, infix binary [<==>] *) [@@ smt_theory_symbol] type l_iff (p: logical) (q: logical) : logical = (p ==> q) /\ (q ==> p) (** squashed negation, prefix unary [~] *) [@@ smt_theory_symbol] type l_not (p: logical) : logical = l_imp p False (** l_ITE is a weak form of if-then-else at the level of logical formulae. It's not much used. TODO: Can we remove it *) unfold type l_ITE (p: logical) (q: logical) (r: logical) : logical = (p ==> q) /\ (~p ==> r) (** One of the main axioms provided by prims is [precedes], a built-in well-founded partial order over all terms. It's typically written with an infix binary [<<]. The [<<] order includes: * The [<] ordering on natural numbers * The subterm ordering on inductive types * [f x << D f] for data constructors D of an inductive t whose arguments include a ghost or total function returning a t *) assume type precedes : #a: Type -> #b: Type -> a -> b -> Type0 (** The type of primitive strings of characters; See FStar.String *) assume new type string : eqtype (** This attribute can be added to the declaration or definition of any top-level symbol. It causes F* to report a warning on any use of that symbol, printing the [msg] argument. This is used, for instance to: - tag every escape hatch, e.g., [assume], [admit], etc Reports for uses of symbols tagged with this attribute are controlled using the `--report_assumes` option and warning number 334. See tests/micro-benchmarks/WarnOnUse.fst *) assume val warn_on_use (msg: string) : Tot unit (** The [deprecated "s"] attribute: "s" is an alternative function that should be printed in the warning it can be omitted if the use case has no such function *) assume val deprecated (s: string) : Tot unit (** Within the SMT encoding, we have a relation [(HasType e t)] asserting that (the encoding of) [e] has a type corresponding to (the encoding of) [t]. It is sometimes convenient, e.g., when writing triggers for quantifiers, to have access to this relation at the source level. The [has_type] predicate below reflects the SMT encodings [HasType] relation. We also use it to define the type [prop] or proof irrelevant propositions, below. Note, unless you have a really good reason, you probably don't want to use this [has_type] predicate. F*'s type theory certainly does not internalize its own typing judgment *) [@@deprecated "'has_type' is intended for internal use and debugging purposes only; \ do not rely on it for your proofs"] assume type has_type : #a: Type -> a -> Type -> Type0 (** Squashed universal quantification, or dependent products, written [forall (x:a). p x], specialized to Type0 *) [@@ "tac_opaque"; smt_theory_symbol] type l_Forall (#a: Type) (p: (a -> GTot Type0)) : logical = squash (x: a -> GTot (p x)) #push-options "--warn_error -288" (** [p1 `subtype_of` p2] when every element of [p1] is also an element of [p2]. *) let subtype_of (p1 p2: Type) = forall (x: p1). has_type x p2 #pop-options (** The type of squashed types. Note, the [prop] type is a work in progress in F*. In particular, we would like in the future to more systematically use [prop] for proof-irrelevant propositions throughout the libraries. However, we still use [Type0] in many places. See https://github.com/FStarLang/FStar/issues/1048 for more details and the current status of the work. *) type prop = a: Type0{a `subtype_of` unit} (**** The PURE effect *) (** The type of pure preconditions *) let pure_pre = Type0 (** Pure postconditions, predicates on [a], on which the precondition [pre] is also valid. This provides a way for postcondition formula to be typed in a context where they can assume the validity of the precondition. This is discussed extensively in Issue #57 *) let pure_post' (a pre: Type) = _: a{pre} -> GTot Type0 let pure_post (a: Type) = pure_post' a True (** A pure weakest precondition transforms postconditions on [a]-typed results to pure preconditions We require the weakest preconditions to satisfy the monotonicity property over the postconditions To enforce it, we first define a vanilla wp type, and then refine it with the monotonicity condition *) let pure_wp' (a: Type) = pure_post a -> GTot pure_pre (** The monotonicity predicate is marked opaque_to_smt, meaning that its definition is hidden from the SMT solver, and if required, will need to be explicitly revealed This has the advantage that clients that do not need to work with it directly, don't have the (quantified) definition in their solver context *)
{ "checked_file": "/", "dependencies": [], "interface_file": false, "source_file": "prims.fst" }
[ { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
a: Type -> wp: Prims.pure_wp' a -> Prims.logical
Prims.Tot
[ "total" ]
[]
[ "Prims.pure_wp'", "Prims.l_Forall", "Prims.pure_post", "Prims.l_imp", "Prims.logical" ]
[]
false
false
false
true
true
let pure_wp_monotonic0 (a: Type) (wp: pure_wp' a) =
forall (p: pure_post a) (q: pure_post a). (forall (x: a). p x ==> q x) ==> (wp p ==> wp q)
false
Vale.X64.Lemmas.fst
Vale.X64.Lemmas.lemma_whileFalse_total
val lemma_whileFalse_total (b:ocmp) (c:code) (s0:vale_state) (sW:vale_state) (fW:fuel) : Ghost (vale_state & fuel) (requires valid_ocmp b sW /\ not (eval_ocmp sW b) /\ eval_while_inv (While b c) s0 fW sW ) (ensures fun (s1, f1) -> s1 == {sW with vs_flags = havoc_flags} /\ eval_code (While b c) s0 f1 s1 )
val lemma_whileFalse_total (b:ocmp) (c:code) (s0:vale_state) (sW:vale_state) (fW:fuel) : Ghost (vale_state & fuel) (requires valid_ocmp b sW /\ not (eval_ocmp sW b) /\ eval_while_inv (While b c) s0 fW sW ) (ensures fun (s1, f1) -> s1 == {sW with vs_flags = havoc_flags} /\ eval_code (While b c) s0 f1 s1 )
let lemma_whileFalse_total (b:ocmp) (c:code) (s0:vale_state) (sW:vale_state) (fW:fuel) = reveal_opaque (`%BS.valid_ocmp_opaque) BS.valid_ocmp_opaque; reveal_opaque (`%BS.eval_ocmp_opaque) BS.eval_ocmp_opaque; let f1 = fW + 1 in let s1 = {sW with vs_flags = havoc_flags} in assert (state_eq_opt (code_modifies_ghost c) (BS.machine_eval_code (While b c) f1 (state_to_S s0)) (BS.machine_eval_code (While b c) 1 (state_to_S sW))); assert (eval_code (While b c) s0 f1 s1); (s1, f1)
{ "file_name": "vale/code/arch/x64/Vale.X64.Lemmas.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 10, "end_line": 395, "start_col": 0, "start_line": 388 }
module Vale.X64.Lemmas open FStar.Mul open Vale.X64.Machine_s open Vale.X64.State open Vale.X64.StateLemmas open Vale.X64.Instruction_s open Vale.X64.Bytes_Code_s module BS = Vale.X64.Machine_Semantics_s module ME = Vale.X64.Memory #reset-options "--initial_fuel 1 --max_fuel 1 --z3rlimit 100" #restart-solver let rec lemma_eq_instr_apply_eval_args (outs:list instr_out) (args:list instr_operand) (f:instr_args_t outs args) (oprs:instr_operands_t_args args) (s1 s2:machine_state) : Lemma (requires state_eq_S true s1 s2) (ensures BS.instr_apply_eval_args outs args f oprs s1 == BS.instr_apply_eval_args outs args f oprs s2) = let open BS in lemma_heap_ignore_ghost_machine s1.BS.ms_heap s2.BS.ms_heap; match args with | [] -> () | i::args -> ( let (v, oprs) : option (instr_val_t i) & instr_operands_t_args args = match i with | IOpEx i -> let oprs = coerce oprs in (instr_eval_operand_explicit i (fst oprs) s1, snd oprs) | IOpIm i -> (instr_eval_operand_implicit i s1, coerce oprs) in let f:arrow (instr_val_t i) (instr_args_t outs args) = coerce f in match v with | None -> () | Some v -> lemma_eq_instr_apply_eval_args outs args (f v) oprs s1 s2 ) #restart-solver let rec lemma_eq_instr_apply_eval_inouts (outs inouts:list instr_out) (args:list instr_operand) (f:instr_inouts_t outs inouts args) (oprs:instr_operands_t inouts args) (s1 s2:machine_state) : Lemma (requires state_eq_S true s1 s2) (ensures BS.instr_apply_eval_inouts outs inouts args f oprs s1 == BS.instr_apply_eval_inouts outs inouts args f oprs s2) = let open BS in lemma_heap_ignore_ghost_machine s1.BS.ms_heap s2.BS.ms_heap; match inouts with | [] -> lemma_eq_instr_apply_eval_args outs args f oprs s1 s2 | (Out, i)::inouts -> let oprs = match i with | IOpEx i -> snd #(instr_operand_t i) (coerce oprs) | IOpIm i -> coerce oprs in lemma_eq_instr_apply_eval_inouts outs inouts args (coerce f) oprs s1 s2 | (InOut, i)::inouts -> ( let (v, oprs) : option (instr_val_t i) & instr_operands_t inouts args = match i with | IOpEx i -> let oprs = coerce oprs in (instr_eval_operand_explicit i (fst oprs) s1, snd oprs) | IOpIm i -> (instr_eval_operand_implicit i s1, coerce oprs) in let f:arrow (instr_val_t i) (instr_inouts_t outs inouts args) = coerce f in match v with | None -> () | Some v -> lemma_eq_instr_apply_eval_inouts outs inouts args (f v) oprs s1 s2 ) #restart-solver #push-options "--z3rlimit_factor 2" let rec lemma_eq_instr_write_outputs (outs:list instr_out) (args:list instr_operand) (vs:instr_ret_t outs) (oprs:instr_operands_t outs args) (s1_orig s1 s2_orig s2:machine_state) : Lemma (requires state_eq_S true s1_orig s2_orig /\ state_eq_S true s1 s2) (ensures state_eq_S true (BS.instr_write_outputs outs args vs oprs s1_orig s1) (BS.instr_write_outputs outs args vs oprs s2_orig s2)) = let open BS in use_machine_state_equal (); lemma_heap_ignore_ghost_machine s1.BS.ms_heap s2.BS.ms_heap; lemma_heap_ignore_ghost_machine s1_orig.BS.ms_heap s2_orig.BS.ms_heap; allow_inversion tmaddr; match outs with | [] -> () | (_, i)::outs -> ( let ((v:instr_val_t i), (vs:instr_ret_t outs)) = match outs with | [] -> (vs, ()) | _::_ -> let vs = coerce vs in (fst vs, snd vs) in match i with | IOpEx i -> let oprs = coerce oprs in let s1 = instr_write_output_explicit i v (fst oprs) s1_orig s1 in let s2 = instr_write_output_explicit i v (fst oprs) s2_orig s2 in lemma_eq_instr_write_outputs outs args vs (snd oprs) s1_orig s1 s2_orig s2 | IOpIm i -> let s1 = instr_write_output_implicit i v s1_orig s1 in let s2 = instr_write_output_implicit i v s2_orig s2 in allow_inversion operand64; allow_inversion operand128; lemma_eq_instr_write_outputs outs args vs (coerce oprs) s1_orig s1 s2_orig s2 ) #pop-options #restart-solver let eval_ins_eq_instr (inst:BS.ins) (s1 s2:machine_state) : Lemma (requires Instr? inst /\ state_eq_S true s1 s2) (ensures state_eq_S true (BS.machine_eval_ins inst s1) (BS.machine_eval_ins inst s2)) = let open BS in let Instr it oprs ann = inst in let InstrTypeRecord #outs #args #havoc_flags' i = it in lemma_eq_instr_apply_eval_inouts outs outs args (instr_eval i) oprs s1 s2; let vs = instr_apply_eval outs args (instr_eval i) oprs s1 in let hav s = match havoc_flags' with | HavocFlags -> {s with ms_flags = havoc_flags} | PreserveFlags -> s in let s1' = hav s1 in let s2' = hav s2 in match vs with | None -> () | Some vs -> lemma_eq_instr_write_outputs outs args vs oprs s1 s1' s2 s2' let eval_code_eq_instr (inst:BS.ins) (f:fuel) (s1 s2:machine_state) : Lemma (requires Instr? inst /\ state_eq_S true s1 s2) (ensures state_eq_opt true (BS.machine_eval_code (Ins inst) f s1) (BS.machine_eval_code (Ins inst) f s2)) = reveal_opaque (`%BS.machine_eval_code_ins) BS.machine_eval_code_ins; eval_ins_eq_instr inst ({s1 with BS.ms_trace = []}) ({s2 with BS.ms_trace = []}) let eval_code_eq_dealloc (inst:BS.ins) (f:fuel) (s1 s2:machine_state) : Lemma (requires Dealloc? inst /\ state_eq_S true s1 s2) (ensures state_eq_opt true (BS.machine_eval_code (Ins inst) f s1) (BS.machine_eval_code (Ins inst) f s2)) = reveal_opaque (`%BS.machine_eval_code_ins) BS.machine_eval_code_ins; use_machine_state_equal (); lemma_heap_ignore_ghost_machine s1.BS.ms_heap s2.BS.ms_heap; allow_inversion tmaddr let eval_code_eq_alloc (inst:BS.ins) (f:fuel) (s1 s2:machine_state) : Lemma (requires Alloc? inst /\ state_eq_S true s1 s2) (ensures state_eq_opt true (BS.machine_eval_code (Ins inst) f s1) (BS.machine_eval_code (Ins inst) f s2)) = reveal_opaque (`%BS.machine_eval_code_ins) BS.machine_eval_code_ins; use_machine_state_equal (); lemma_heap_ignore_ghost_machine s1.BS.ms_heap s2.BS.ms_heap; allow_inversion tmaddr let eval_code_eq_push (inst:BS.ins) (f:fuel) (s1 s2:machine_state) : Lemma (requires Push? inst /\ state_eq_S true s1 s2) (ensures state_eq_opt true (BS.machine_eval_code (Ins inst) f s1) (BS.machine_eval_code (Ins inst) f s2)) = reveal_opaque (`%BS.machine_eval_code_ins) BS.machine_eval_code_ins; use_machine_state_equal (); lemma_heap_ignore_ghost_machine s1.BS.ms_heap s2.BS.ms_heap; allow_inversion tmaddr let eval_code_eq_pop (inst:BS.ins) (f:fuel) (s1 s2:machine_state) : Lemma (requires Pop? inst /\ state_eq_S true s1 s2) (ensures state_eq_opt true (BS.machine_eval_code (Ins inst) f s1) (BS.machine_eval_code (Ins inst) f s2)) = reveal_opaque (`%BS.machine_eval_code_ins) BS.machine_eval_code_ins; use_machine_state_equal (); lemma_heap_ignore_ghost_machine s1.BS.ms_heap s2.BS.ms_heap; allow_inversion tmaddr let eval_code_eq_ins (i:BS.ins) (f:fuel) (s1 s2:machine_state) : Lemma (requires state_eq_S true s1 s2) (ensures state_eq_opt true (BS.machine_eval_code (Ins i) f s1) (BS.machine_eval_code (Ins i) f s2)) = match i with | Instr _ _ _ -> eval_code_eq_instr i f s1 s2 | Dealloc _ -> eval_code_eq_dealloc i f s1 s2 | Alloc _ -> eval_code_eq_alloc i f s1 s2 | Push _ _ -> eval_code_eq_push i f s1 s2 | Pop _ _ -> eval_code_eq_pop i f s1 s2 #reset-options "--fuel 2 --z3rlimit 30" let eval_ocmp_eq_core (g:bool) (cond:ocmp) (s:machine_state) : Lemma (ensures ( let (s1, b1) = BS.machine_eval_ocmp s cond in let (s2, b2) = BS.machine_eval_ocmp (core_state g s) cond in state_eq_S g s1 s2 /\ b1 == b2 )) = reveal_opaque (`%BS.valid_ocmp_opaque) BS.valid_ocmp_opaque; reveal_opaque (`%BS.eval_ocmp_opaque) BS.eval_ocmp_opaque; () #restart-solver let rec eval_code_eq_core (g:bool) (c:code) (f:fuel) (s:machine_state) : Lemma (ensures state_eq_opt g (BS.machine_eval_code c f s) (BS.machine_eval_code c f (core_state g s))) (decreases %[f; c]) = match c with | Ins i -> reveal_opaque (`%BS.machine_eval_code_ins) BS.machine_eval_code_ins; if g then eval_code_eq_ins i f s (core_state g s) | Block cs -> eval_codes_eq_core g cs f s | IfElse cond ct cf -> eval_ocmp_eq_core g cond s; let (s', _) = BS.machine_eval_ocmp s cond in let (t', _) = BS.machine_eval_ocmp (core_state g s) cond in eval_code_eq_core g ct f s'; eval_code_eq_core g ct f t'; eval_code_eq_core g cf f s'; eval_code_eq_core g cf f t'; () | While cond body -> eval_while_eq_core g cond body f s and eval_codes_eq_core (g:bool) (cs:codes) (f:fuel) (s:machine_state) : Lemma (ensures state_eq_opt g (BS.machine_eval_codes cs f s) (BS.machine_eval_codes cs f (core_state g s))) (decreases %[f; cs]) = match cs with | [] -> () | c'::cs' -> ( eval_code_eq_core g c' f s; match (machine_eval_code c' f s, machine_eval_code c' f (core_state g s)) with | (None, None) -> () | (Some s', Some t') -> eval_codes_eq_core g cs' f s'; eval_codes_eq_core g cs' f t' ) and eval_while_eq_core (g:bool) (cond:ocmp) (body:code) (f:fuel) (s:machine_state) : Lemma (ensures state_eq_opt g (BS.machine_eval_while cond body f s) (BS.machine_eval_while cond body f (core_state g s))) (decreases %[f; body]) = if f > 0 then ( eval_ocmp_eq_core g cond s; let (s1, _) = BS.machine_eval_ocmp s cond in let (t1, _) = BS.machine_eval_ocmp (core_state g s) cond in eval_code_eq_core g body (f - 1) s1; eval_code_eq_core g body (f - 1) t1; match (BS.machine_eval_code body (f - 1) s1, BS.machine_eval_code body (f - 1) t1) with | (None, None) -> () | (Some s2, Some t2) -> eval_while_eq_core g cond body (f - 1) s2; eval_while_eq_core g cond body (f - 1) t2; () ) let eval_code_eq_f (c:code) (f:fuel) (s1 s2:machine_state) : Lemma (requires state_eq_S false s1 s2) (ensures state_eq_opt false (BS.machine_eval_code c f s1) (BS.machine_eval_code c f s2)) [SMTPat (BS.machine_eval_code c f s1); SMTPat (BS.machine_eval_code c f s2)] = eval_code_eq_core false c f s1; eval_code_eq_core false c f s2 let eval_codes_eq_f (cs:codes) (f:fuel) (s1 s2:machine_state) : Lemma (requires state_eq_S false s1 s2) (ensures state_eq_opt false (BS.machine_eval_codes cs f s1) (BS.machine_eval_codes cs f s2)) [SMTPat (BS.machine_eval_codes cs f s1); SMTPat (BS.machine_eval_codes cs f s2)] = eval_codes_eq_core false cs f s1; eval_codes_eq_core false cs f s2 let eval_while_eq_f (cond:ocmp) (body:code) (f:fuel) (s1 s2:machine_state) : Lemma (requires state_eq_S false s1 s2) (ensures state_eq_opt false (BS.machine_eval_while cond body f s1) (BS.machine_eval_while cond body f s2)) [SMTPat (BS.machine_eval_while cond body f s1); SMTPat (BS.machine_eval_while cond body f s2)] = eval_while_eq_core false cond body f s1; eval_while_eq_core false cond body f s2 let eval_code_eq_t (c:code) (f:fuel) (s1 s2:machine_state) : Lemma (requires state_eq_S true s1 s2) (ensures state_eq_opt true (BS.machine_eval_code c f s1) (BS.machine_eval_code c f s2)) [SMTPat (BS.machine_eval_code c f s1); SMTPat (BS.machine_eval_code c f s2)] = eval_code_eq_core true c f s1; eval_code_eq_core true c f s2 let eval_codes_eq_t (cs:codes) (f:fuel) (s1 s2:machine_state) : Lemma (requires state_eq_S true s1 s2) (ensures state_eq_opt true (BS.machine_eval_codes cs f s1) (BS.machine_eval_codes cs f s2)) [SMTPat (BS.machine_eval_codes cs f s1); SMTPat (BS.machine_eval_codes cs f s2)] = eval_codes_eq_core true cs f s1; eval_codes_eq_core true cs f s2 let eval_while_eq_t (cond:ocmp) (body:code) (f:fuel) (s1 s2:machine_state) : Lemma (requires state_eq_S true s1 s2) (ensures state_eq_opt true (BS.machine_eval_while cond body f s1) (BS.machine_eval_while cond body f s2)) [SMTPat (BS.machine_eval_while cond body f s1); SMTPat (BS.machine_eval_while cond body f s2)] = eval_while_eq_core true cond body f s1; eval_while_eq_core true cond body f s2 let eval_code_ts (g:bool) (c:code) (s0:machine_state) (f0:fuel) (s1:machine_state) : Type0 = state_eq_opt g (BS.machine_eval_code c f0 s0) (Some s1) let rec increase_fuel (g:bool) (c:code) (s0:machine_state) (f0:fuel) (sN:machine_state) (fN:fuel) : Lemma (requires eval_code_ts g c s0 f0 sN /\ f0 <= fN) (ensures eval_code_ts g c s0 fN sN) (decreases %[f0; c]) = match c with | Ins ins -> () | Block l -> increase_fuels g l s0 f0 sN fN | IfElse cond t f -> let (s0, b0) = BS.machine_eval_ocmp s0 cond in if b0 then increase_fuel g t s0 f0 sN fN else increase_fuel g f s0 f0 sN fN | While cond c -> let (s1, b0) = BS.machine_eval_ocmp s0 cond in if b0 then ( match BS.machine_eval_code c (f0 - 1) s1 with | None -> () | Some s2 -> increase_fuel g c s1 (f0 - 1) s2 (fN - 1); if s2.BS.ms_ok then increase_fuel g (While cond c) s2 (f0 - 1) sN (fN - 1) else () ) and increase_fuels (g:bool) (c:codes) (s0:machine_state) (f0:fuel) (sN:machine_state) (fN:fuel) : Lemma (requires eval_code_ts g (Block c) s0 f0 sN /\ f0 <= fN) (ensures eval_code_ts g (Block c) s0 fN sN) (decreases %[f0; c]) = match c with | [] -> () | h::t -> ( let Some s1 = BS.machine_eval_code h f0 s0 in increase_fuel g h s0 f0 s1 fN; increase_fuels g t s1 f0 sN fN ) let lemma_cmp_eq s o1 o2 = reveal_opaque (`%BS.eval_ocmp_opaque) BS.eval_ocmp_opaque let lemma_cmp_ne s o1 o2 = reveal_opaque (`%BS.eval_ocmp_opaque) BS.eval_ocmp_opaque let lemma_cmp_le s o1 o2 = reveal_opaque (`%BS.eval_ocmp_opaque) BS.eval_ocmp_opaque let lemma_cmp_ge s o1 o2 = reveal_opaque (`%BS.eval_ocmp_opaque) BS.eval_ocmp_opaque let lemma_cmp_lt s o1 o2 = reveal_opaque (`%BS.eval_ocmp_opaque) BS.eval_ocmp_opaque let lemma_cmp_gt s o1 o2 = reveal_opaque (`%BS.eval_ocmp_opaque) BS.eval_ocmp_opaque let lemma_valid_cmp_eq s o1 o2 = () let lemma_valid_cmp_ne s o1 o2 = () let lemma_valid_cmp_le s o1 o2 = () let lemma_valid_cmp_ge s o1 o2 = () let lemma_valid_cmp_lt s o1 o2 = () let lemma_valid_cmp_gt s o1 o2 = () let compute_merge_total (f0:fuel) (fM:fuel) = if f0 > fM then f0 else fM let lemma_merge_total (b0:codes) (s0:vale_state) (f0:fuel) (sM:vale_state) (fM:fuel) (sN:vale_state) = let f = if f0 > fM then f0 else fM in increase_fuel (codes_modifies_ghost b0) (Cons?.hd b0) (state_to_S s0) f0 (state_to_S sM) f; increase_fuel (codes_modifies_ghost b0) (Block (Cons?.tl b0)) (state_to_S sM) fM (state_to_S sN) f let lemma_empty_total (s0:vale_state) (bN:codes) = (s0, 0) let lemma_ifElse_total (ifb:ocmp) (ct:code) (cf:code) (s0:vale_state) = (eval_ocmp s0 ifb, {s0 with vs_flags = havoc_flags}, s0, 0) let lemma_havoc_flags : squash (Flags.to_fun havoc_flags == BS.havoc_flags) = assert (FStar.FunctionalExtensionality.feq (Flags.to_fun havoc_flags) BS.havoc_flags) let lemma_ifElseTrue_total (ifb:ocmp) (ct:code) (cf:code) (s0:vale_state) (f0:fuel) (sM:vale_state) = reveal_opaque (`%BS.valid_ocmp_opaque) BS.valid_ocmp_opaque; reveal_opaque (`%BS.eval_ocmp_opaque) BS.eval_ocmp_opaque let lemma_ifElseFalse_total (ifb:ocmp) (ct:code) (cf:code) (s0:vale_state) (f0:fuel) (sM:vale_state) = reveal_opaque (`%BS.valid_ocmp_opaque) BS.valid_ocmp_opaque; reveal_opaque (`%BS.eval_ocmp_opaque) BS.eval_ocmp_opaque let eval_while_inv_temp (c:code) (s0:vale_state) (fW:fuel) (sW:vale_state) : Type0 = forall (f:nat).{:pattern BS.machine_eval_code c f (state_to_S sW)} Some? (BS.machine_eval_code c f (state_to_S sW)) ==> state_eq_opt (code_modifies_ghost c) (BS.machine_eval_code c (f + fW) (state_to_S s0)) (BS.machine_eval_code c f (state_to_S sW)) let eval_while_inv (c:code) (s0:vale_state) (fW:fuel) (sW:vale_state) : Type0 = eval_while_inv_temp c s0 fW sW let lemma_while_total (b:ocmp) (c:code) (s0:vale_state) = (s0, 0) let lemma_whileTrue_total (b:ocmp) (c:code) (s0:vale_state) (sW:vale_state) (fW:fuel) = ({sW with vs_flags = havoc_flags}, fW)
{ "checked_file": "/", "dependencies": [ "Vale.X64.StateLemmas.fsti.checked", "Vale.X64.State.fsti.checked", "Vale.X64.Memory.fsti.checked", "Vale.X64.Machine_Semantics_s.fst.checked", "Vale.X64.Machine_s.fst.checked", "Vale.X64.Instruction_s.fsti.checked", "Vale.X64.Flags.fsti.checked", "Vale.X64.Bytes_Code_s.fst.checked", "prims.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.FunctionalExtensionality.fsti.checked" ], "interface_file": true, "source_file": "Vale.X64.Lemmas.fst" }
[ { "abbrev": true, "full_module": "Vale.X64.Memory", "short_module": "ME" }, { "abbrev": true, "full_module": "Vale.X64.Machine_Semantics_s", "short_module": "BS" }, { "abbrev": false, "full_module": "Vale.X64.Bytes_Code_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Instruction_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.StateLemmas", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.State", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Machine_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": true, "full_module": "Vale.Lib.Map16", "short_module": "Map16" }, { "abbrev": true, "full_module": "Vale.X64.Machine_Semantics_s", "short_module": "BS" }, { "abbrev": false, "full_module": "Vale.X64.Bytes_Code_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.StateLemmas", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.State", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Machine_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.HeapLemmas", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.HeapImpl", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.Heap", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 0, "max_fuel": 2, "max_ifuel": 1, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": true, "smtencoding_l_arith_repr": "native", "smtencoding_nl_arith_repr": "wrapped", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [ "smt.arith.nl=false", "smt.QI.EAGER_THRESHOLD=100", "smt.CASE_SPLIT=3" ], "z3refresh": false, "z3rlimit": 30, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
b: Vale.X64.Bytes_Code_s.ocmp -> c: Vale.X64.StateLemmas.code -> s0: Vale.X64.State.vale_state -> sW: Vale.X64.State.vale_state -> fW: Vale.X64.Lemmas.fuel -> Prims.Ghost (Vale.X64.State.vale_state * Vale.X64.Lemmas.fuel)
Prims.Ghost
[]
[]
[ "Vale.X64.Bytes_Code_s.ocmp", "Vale.X64.StateLemmas.code", "Vale.X64.State.vale_state", "Vale.X64.Lemmas.fuel", "FStar.Pervasives.Native.Mktuple2", "Prims.unit", "Prims._assert", "Vale.X64.Lemmas.eval_code", "Vale.X64.Machine_s.While", "Vale.X64.Bytes_Code_s.instruction_t", "Vale.X64.Machine_Semantics_s.instr_annotation", "Vale.X64.Lemmas.state_eq_opt", "Vale.X64.Lemmas.code_modifies_ghost", "Vale.X64.Machine_Semantics_s.machine_eval_code", "Vale.X64.StateLemmas.state_to_S", "Vale.X64.State.Mkvale_state", "Vale.X64.State.__proj__Mkvale_state__item__vs_ok", "Vale.X64.State.__proj__Mkvale_state__item__vs_regs", "Vale.X64.Lemmas.havoc_flags", "Vale.X64.State.__proj__Mkvale_state__item__vs_heap", "Vale.X64.State.__proj__Mkvale_state__item__vs_stack", "Vale.X64.State.__proj__Mkvale_state__item__vs_stackTaint", "Prims.int", "Prims.op_Addition", "FStar.Pervasives.reveal_opaque", "Vale.X64.Machine_Semantics_s.machine_state", "Vale.X64.Machine_Semantics_s.ocmp", "Prims.bool", "Vale.X64.Machine_Semantics_s.eval_ocmp_opaque", "Vale.X64.Machine_Semantics_s.valid_ocmp_opaque", "FStar.Pervasives.Native.tuple2" ]
[]
false
false
false
false
false
let lemma_whileFalse_total (b: ocmp) (c: code) (s0 sW: vale_state) (fW: fuel) =
reveal_opaque (`%BS.valid_ocmp_opaque) BS.valid_ocmp_opaque; reveal_opaque (`%BS.eval_ocmp_opaque) BS.eval_ocmp_opaque; let f1 = fW + 1 in let s1 = { sW with vs_flags = havoc_flags } in assert (state_eq_opt (code_modifies_ghost c) (BS.machine_eval_code (While b c) f1 (state_to_S s0)) (BS.machine_eval_code (While b c) 1 (state_to_S sW))); assert (eval_code (While b c) s0 f1 s1); (s1, f1)
false
prims.fst
Prims.pure_wp
val pure_wp : a: Type -> Type
let pure_wp (a: Type) = wp:pure_wp' a{pure_wp_monotonic a wp}
{ "file_name": "ulib/prims.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 61, "end_line": 318, "start_col": 0, "start_line": 318 }
(* Copyright 2008-2020 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 Prims /// This module is implicitly opened in the scope of all other modules. /// /// It provides the very basic primitives on which F* is /// built, including the definition of total functions, the basic /// logical connectives, the PURE and GHOST effects and the like. /// /// While some of the primitives have logical significance, others are /// define various conveniences in the language, e.g., type of /// attributes. (***** Begin trusted primitives *****) (** Primitives up to the definition of the GTot effect are trusted Beyond that all definitions are fully verified *) (** Type of attributes *) assume new type attribute : Type0 (** An attribute indicating that some definition must be processed by the Dijkstra monads for free construction *) assume val cps:attribute (** A predicate to express when a type supports decidable equality The type-checker emits axioms for [hasEq] for each inductive type *) assume type hasEq : Type -> GTot Type0 (** A convenient abbreviation, [eqtype] is the type of types in universe 0 which support decidable equality *) type eqtype = a: Type0{hasEq a} (** [bool] is a two element type with elements [true] and [false]. We assume it is primitive, for convenient interop with other languages, although it could easily be defined as an inductive type with two cases, [BTrue | BFalse] *) assume new type bool : eqtype (** [empty] is the empty inductive type. The type with no inhabitants represents logical falsehood. Note, [empty] is seldom used directly in F*. We instead use its "squashed" variant, [False], see below. *) type empty = (** [trivial] is the singleton inductive type---it is trivially inhabited. Like [empty], [trivial] is seldom used. We instead use its "squashed" variants, [True] *) type trivial = | T (** [unit]: another singleton type, with its only inhabitant written [()] we assume it is primitive, for convenient interop with other languages *) assume new type unit : eqtype (** [squash p] is a central type in F*---[squash p] is the proof irrelevant analog of [p] and is represented as a unit refinement. Squashed proofs are typically discharged using an SMT solver, without any proof terms explicitly reconstructed. As such, one way to think of [squash p] is as the type of properties proven using classical axioms without building proof terms. Note, [squash p] is just a unit refinement, it resides in universe 0, lowering the universe of [p]. From this perspective, one may also see [squash] as a coercion down to universe 0. The type is marked [tac_opaque] to indicate to Meta-F* that instances of [squash] should not be unfolded when evaluating tactics (since many optimizations in F*'s SMT encoding rely specifically on occurrences of [squash]. See FStar.Squash for various ways of manipulating squashed types. *) [@@ "tac_opaque"] type squash (p: Type) : Type0 = x: unit{p} (** [auto_squash] is equivalent to [squash]. However, F* will automatically insert `auto_squash` when simplifying terms, converting terms of the form `p /\ True` to `auto_squash p`. We distinguish these automatically inserted squashes from explicit, user-written squashes. A user should not have to manipulate [auto_squash] at all, except in rare circumstances when writing tactics to process proofs that have already been partially simplified by F*'s simplifier. *) let auto_squash (p: Type) = squash p (** The [logical] type is transitionary. It is just an abbreviation for [Type0], but is used to classify uses of the basic squashed logical connectives that follow. Some day, we plan to remove the [logical] type, replacing it with [prop] (also defined below). The type is marked [private] to intentionally prevent user code from referencing this type, hopefully easing the removal of [logical] in the future. *) private type logical = Type0 (** An attribute indicating that a symbol is an smt theory symbol and hence may not be used in smt patterns. The typechecker warns if such symbols are used in patterns *) assume val smt_theory_symbol:attribute (** [l_True] has a special bit of syntactic sugar. It is written just as "True" and rendered in the ide as [True]. It is a squashed version of constructive truth, [trivial]. *) [@@ "tac_opaque"; smt_theory_symbol] let l_True:logical = squash trivial (** [l_False] has a special bit of syntactic sugar. It is written just as "False" and rendered in the ide as [Falsee]. It is a squashed version of constructive falsehood, the empty type. *) [@@ "tac_opaque"; smt_theory_symbol] let l_False:logical = squash empty (** The type of provable equalities, defined as the usual inductive type with a single constructor for reflexivity. As with the other connectives, we often work instead with the squashed version of equality, below. *) type equals (#a: Type) (x: a) : a -> Type = | Refl : equals x x (** [eq2] is the squashed version of [equals]. It's a proof irrelevant, homogeneous equality in Type#0 and is written with an infix binary [==]. TODO: instead of hard-wiring the == syntax, we should just rename eq2 to op_Equals_Equals *) [@@ "tac_opaque"; smt_theory_symbol] type eq2 (#a: Type) (x: a) (y: a) : logical = squash (equals x y) (** bool-to-type coercion: This is often automatically inserted type, when using a boolean in context expecting a type. But, occasionally, one may have to write [b2t] explicitly *) type b2t (b: bool) : logical = (b == true) (** constructive conjunction *) type pair (p: Type) (q: Type) = | Pair : _1:p -> _2:q -> pair p q (** squashed conjunction, specialized to [Type0], written with an infix binary [/\] *) [@@ "tac_opaque"; smt_theory_symbol] type l_and (p: logical) (q: logical) : logical = squash (pair p q) (** constructive disjunction *) type sum (p: Type) (q: Type) = | Left : v:p -> sum p q | Right : v:q -> sum p q (** squashed disjunction, specialized to [Type0], written with an infix binary [\/] *) [@@ "tac_opaque"; smt_theory_symbol] type l_or (p: logical) (q: logical) : logical = squash (sum p q) (** squashed (non-dependent) implication, specialized to [Type0], written with an infix binary [==>]. Note, [==>] binds weaker than [/\] and [\/] *) [@@ "tac_opaque"; smt_theory_symbol] type l_imp (p: logical) (q: logical) : logical = squash (p -> GTot q) (* ^^^ NB: The GTot effect is primitive; *) (* elaborated using GHOST a few lines below *) (** squashed double implication, infix binary [<==>] *) [@@ smt_theory_symbol] type l_iff (p: logical) (q: logical) : logical = (p ==> q) /\ (q ==> p) (** squashed negation, prefix unary [~] *) [@@ smt_theory_symbol] type l_not (p: logical) : logical = l_imp p False (** l_ITE is a weak form of if-then-else at the level of logical formulae. It's not much used. TODO: Can we remove it *) unfold type l_ITE (p: logical) (q: logical) (r: logical) : logical = (p ==> q) /\ (~p ==> r) (** One of the main axioms provided by prims is [precedes], a built-in well-founded partial order over all terms. It's typically written with an infix binary [<<]. The [<<] order includes: * The [<] ordering on natural numbers * The subterm ordering on inductive types * [f x << D f] for data constructors D of an inductive t whose arguments include a ghost or total function returning a t *) assume type precedes : #a: Type -> #b: Type -> a -> b -> Type0 (** The type of primitive strings of characters; See FStar.String *) assume new type string : eqtype (** This attribute can be added to the declaration or definition of any top-level symbol. It causes F* to report a warning on any use of that symbol, printing the [msg] argument. This is used, for instance to: - tag every escape hatch, e.g., [assume], [admit], etc Reports for uses of symbols tagged with this attribute are controlled using the `--report_assumes` option and warning number 334. See tests/micro-benchmarks/WarnOnUse.fst *) assume val warn_on_use (msg: string) : Tot unit (** The [deprecated "s"] attribute: "s" is an alternative function that should be printed in the warning it can be omitted if the use case has no such function *) assume val deprecated (s: string) : Tot unit (** Within the SMT encoding, we have a relation [(HasType e t)] asserting that (the encoding of) [e] has a type corresponding to (the encoding of) [t]. It is sometimes convenient, e.g., when writing triggers for quantifiers, to have access to this relation at the source level. The [has_type] predicate below reflects the SMT encodings [HasType] relation. We also use it to define the type [prop] or proof irrelevant propositions, below. Note, unless you have a really good reason, you probably don't want to use this [has_type] predicate. F*'s type theory certainly does not internalize its own typing judgment *) [@@deprecated "'has_type' is intended for internal use and debugging purposes only; \ do not rely on it for your proofs"] assume type has_type : #a: Type -> a -> Type -> Type0 (** Squashed universal quantification, or dependent products, written [forall (x:a). p x], specialized to Type0 *) [@@ "tac_opaque"; smt_theory_symbol] type l_Forall (#a: Type) (p: (a -> GTot Type0)) : logical = squash (x: a -> GTot (p x)) #push-options "--warn_error -288" (** [p1 `subtype_of` p2] when every element of [p1] is also an element of [p2]. *) let subtype_of (p1 p2: Type) = forall (x: p1). has_type x p2 #pop-options (** The type of squashed types. Note, the [prop] type is a work in progress in F*. In particular, we would like in the future to more systematically use [prop] for proof-irrelevant propositions throughout the libraries. However, we still use [Type0] in many places. See https://github.com/FStarLang/FStar/issues/1048 for more details and the current status of the work. *) type prop = a: Type0{a `subtype_of` unit} (**** The PURE effect *) (** The type of pure preconditions *) let pure_pre = Type0 (** Pure postconditions, predicates on [a], on which the precondition [pre] is also valid. This provides a way for postcondition formula to be typed in a context where they can assume the validity of the precondition. This is discussed extensively in Issue #57 *) let pure_post' (a pre: Type) = _: a{pre} -> GTot Type0 let pure_post (a: Type) = pure_post' a True (** A pure weakest precondition transforms postconditions on [a]-typed results to pure preconditions We require the weakest preconditions to satisfy the monotonicity property over the postconditions To enforce it, we first define a vanilla wp type, and then refine it with the monotonicity condition *) let pure_wp' (a: Type) = pure_post a -> GTot pure_pre (** The monotonicity predicate is marked opaque_to_smt, meaning that its definition is hidden from the SMT solver, and if required, will need to be explicitly revealed This has the advantage that clients that do not need to work with it directly, don't have the (quantified) definition in their solver context *) let pure_wp_monotonic0 (a:Type) (wp:pure_wp' a) = forall (p q:pure_post a). (forall (x:a). p x ==> q x) ==> (wp p ==> wp q) [@@ "opaque_to_smt"] let pure_wp_monotonic = pure_wp_monotonic0
{ "checked_file": "/", "dependencies": [], "interface_file": false, "source_file": "prims.fst" }
[ { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
a: Type -> Type
Prims.Tot
[ "total" ]
[]
[ "Prims.pure_wp'", "Prims.pure_wp_monotonic" ]
[]
false
false
false
true
true
let pure_wp (a: Type) =
wp: pure_wp' a {pure_wp_monotonic a wp}
false
prims.fst
Prims.pure_stronger
val pure_stronger : a: Type -> wp1: Prims.pure_wp a -> wp2: Prims.pure_wp a -> Prims.logical
let pure_stronger (a: Type) (wp1 wp2: pure_wp a) = forall (p: pure_post a). wp1 p ==> wp2 p
{ "file_name": "ulib/prims.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 91, "end_line": 385, "start_col": 0, "start_line": 385 }
(* Copyright 2008-2020 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 Prims /// This module is implicitly opened in the scope of all other modules. /// /// It provides the very basic primitives on which F* is /// built, including the definition of total functions, the basic /// logical connectives, the PURE and GHOST effects and the like. /// /// While some of the primitives have logical significance, others are /// define various conveniences in the language, e.g., type of /// attributes. (***** Begin trusted primitives *****) (** Primitives up to the definition of the GTot effect are trusted Beyond that all definitions are fully verified *) (** Type of attributes *) assume new type attribute : Type0 (** An attribute indicating that some definition must be processed by the Dijkstra monads for free construction *) assume val cps:attribute (** A predicate to express when a type supports decidable equality The type-checker emits axioms for [hasEq] for each inductive type *) assume type hasEq : Type -> GTot Type0 (** A convenient abbreviation, [eqtype] is the type of types in universe 0 which support decidable equality *) type eqtype = a: Type0{hasEq a} (** [bool] is a two element type with elements [true] and [false]. We assume it is primitive, for convenient interop with other languages, although it could easily be defined as an inductive type with two cases, [BTrue | BFalse] *) assume new type bool : eqtype (** [empty] is the empty inductive type. The type with no inhabitants represents logical falsehood. Note, [empty] is seldom used directly in F*. We instead use its "squashed" variant, [False], see below. *) type empty = (** [trivial] is the singleton inductive type---it is trivially inhabited. Like [empty], [trivial] is seldom used. We instead use its "squashed" variants, [True] *) type trivial = | T (** [unit]: another singleton type, with its only inhabitant written [()] we assume it is primitive, for convenient interop with other languages *) assume new type unit : eqtype (** [squash p] is a central type in F*---[squash p] is the proof irrelevant analog of [p] and is represented as a unit refinement. Squashed proofs are typically discharged using an SMT solver, without any proof terms explicitly reconstructed. As such, one way to think of [squash p] is as the type of properties proven using classical axioms without building proof terms. Note, [squash p] is just a unit refinement, it resides in universe 0, lowering the universe of [p]. From this perspective, one may also see [squash] as a coercion down to universe 0. The type is marked [tac_opaque] to indicate to Meta-F* that instances of [squash] should not be unfolded when evaluating tactics (since many optimizations in F*'s SMT encoding rely specifically on occurrences of [squash]. See FStar.Squash for various ways of manipulating squashed types. *) [@@ "tac_opaque"] type squash (p: Type) : Type0 = x: unit{p} (** [auto_squash] is equivalent to [squash]. However, F* will automatically insert `auto_squash` when simplifying terms, converting terms of the form `p /\ True` to `auto_squash p`. We distinguish these automatically inserted squashes from explicit, user-written squashes. A user should not have to manipulate [auto_squash] at all, except in rare circumstances when writing tactics to process proofs that have already been partially simplified by F*'s simplifier. *) let auto_squash (p: Type) = squash p (** The [logical] type is transitionary. It is just an abbreviation for [Type0], but is used to classify uses of the basic squashed logical connectives that follow. Some day, we plan to remove the [logical] type, replacing it with [prop] (also defined below). The type is marked [private] to intentionally prevent user code from referencing this type, hopefully easing the removal of [logical] in the future. *) private type logical = Type0 (** An attribute indicating that a symbol is an smt theory symbol and hence may not be used in smt patterns. The typechecker warns if such symbols are used in patterns *) assume val smt_theory_symbol:attribute (** [l_True] has a special bit of syntactic sugar. It is written just as "True" and rendered in the ide as [True]. It is a squashed version of constructive truth, [trivial]. *) [@@ "tac_opaque"; smt_theory_symbol] let l_True:logical = squash trivial (** [l_False] has a special bit of syntactic sugar. It is written just as "False" and rendered in the ide as [Falsee]. It is a squashed version of constructive falsehood, the empty type. *) [@@ "tac_opaque"; smt_theory_symbol] let l_False:logical = squash empty (** The type of provable equalities, defined as the usual inductive type with a single constructor for reflexivity. As with the other connectives, we often work instead with the squashed version of equality, below. *) type equals (#a: Type) (x: a) : a -> Type = | Refl : equals x x (** [eq2] is the squashed version of [equals]. It's a proof irrelevant, homogeneous equality in Type#0 and is written with an infix binary [==]. TODO: instead of hard-wiring the == syntax, we should just rename eq2 to op_Equals_Equals *) [@@ "tac_opaque"; smt_theory_symbol] type eq2 (#a: Type) (x: a) (y: a) : logical = squash (equals x y) (** bool-to-type coercion: This is often automatically inserted type, when using a boolean in context expecting a type. But, occasionally, one may have to write [b2t] explicitly *) type b2t (b: bool) : logical = (b == true) (** constructive conjunction *) type pair (p: Type) (q: Type) = | Pair : _1:p -> _2:q -> pair p q (** squashed conjunction, specialized to [Type0], written with an infix binary [/\] *) [@@ "tac_opaque"; smt_theory_symbol] type l_and (p: logical) (q: logical) : logical = squash (pair p q) (** constructive disjunction *) type sum (p: Type) (q: Type) = | Left : v:p -> sum p q | Right : v:q -> sum p q (** squashed disjunction, specialized to [Type0], written with an infix binary [\/] *) [@@ "tac_opaque"; smt_theory_symbol] type l_or (p: logical) (q: logical) : logical = squash (sum p q) (** squashed (non-dependent) implication, specialized to [Type0], written with an infix binary [==>]. Note, [==>] binds weaker than [/\] and [\/] *) [@@ "tac_opaque"; smt_theory_symbol] type l_imp (p: logical) (q: logical) : logical = squash (p -> GTot q) (* ^^^ NB: The GTot effect is primitive; *) (* elaborated using GHOST a few lines below *) (** squashed double implication, infix binary [<==>] *) [@@ smt_theory_symbol] type l_iff (p: logical) (q: logical) : logical = (p ==> q) /\ (q ==> p) (** squashed negation, prefix unary [~] *) [@@ smt_theory_symbol] type l_not (p: logical) : logical = l_imp p False (** l_ITE is a weak form of if-then-else at the level of logical formulae. It's not much used. TODO: Can we remove it *) unfold type l_ITE (p: logical) (q: logical) (r: logical) : logical = (p ==> q) /\ (~p ==> r) (** One of the main axioms provided by prims is [precedes], a built-in well-founded partial order over all terms. It's typically written with an infix binary [<<]. The [<<] order includes: * The [<] ordering on natural numbers * The subterm ordering on inductive types * [f x << D f] for data constructors D of an inductive t whose arguments include a ghost or total function returning a t *) assume type precedes : #a: Type -> #b: Type -> a -> b -> Type0 (** The type of primitive strings of characters; See FStar.String *) assume new type string : eqtype (** This attribute can be added to the declaration or definition of any top-level symbol. It causes F* to report a warning on any use of that symbol, printing the [msg] argument. This is used, for instance to: - tag every escape hatch, e.g., [assume], [admit], etc Reports for uses of symbols tagged with this attribute are controlled using the `--report_assumes` option and warning number 334. See tests/micro-benchmarks/WarnOnUse.fst *) assume val warn_on_use (msg: string) : Tot unit (** The [deprecated "s"] attribute: "s" is an alternative function that should be printed in the warning it can be omitted if the use case has no such function *) assume val deprecated (s: string) : Tot unit (** Within the SMT encoding, we have a relation [(HasType e t)] asserting that (the encoding of) [e] has a type corresponding to (the encoding of) [t]. It is sometimes convenient, e.g., when writing triggers for quantifiers, to have access to this relation at the source level. The [has_type] predicate below reflects the SMT encodings [HasType] relation. We also use it to define the type [prop] or proof irrelevant propositions, below. Note, unless you have a really good reason, you probably don't want to use this [has_type] predicate. F*'s type theory certainly does not internalize its own typing judgment *) [@@deprecated "'has_type' is intended for internal use and debugging purposes only; \ do not rely on it for your proofs"] assume type has_type : #a: Type -> a -> Type -> Type0 (** Squashed universal quantification, or dependent products, written [forall (x:a). p x], specialized to Type0 *) [@@ "tac_opaque"; smt_theory_symbol] type l_Forall (#a: Type) (p: (a -> GTot Type0)) : logical = squash (x: a -> GTot (p x)) #push-options "--warn_error -288" (** [p1 `subtype_of` p2] when every element of [p1] is also an element of [p2]. *) let subtype_of (p1 p2: Type) = forall (x: p1). has_type x p2 #pop-options (** The type of squashed types. Note, the [prop] type is a work in progress in F*. In particular, we would like in the future to more systematically use [prop] for proof-irrelevant propositions throughout the libraries. However, we still use [Type0] in many places. See https://github.com/FStarLang/FStar/issues/1048 for more details and the current status of the work. *) type prop = a: Type0{a `subtype_of` unit} (**** The PURE effect *) (** The type of pure preconditions *) let pure_pre = Type0 (** Pure postconditions, predicates on [a], on which the precondition [pre] is also valid. This provides a way for postcondition formula to be typed in a context where they can assume the validity of the precondition. This is discussed extensively in Issue #57 *) let pure_post' (a pre: Type) = _: a{pre} -> GTot Type0 let pure_post (a: Type) = pure_post' a True (** A pure weakest precondition transforms postconditions on [a]-typed results to pure preconditions We require the weakest preconditions to satisfy the monotonicity property over the postconditions To enforce it, we first define a vanilla wp type, and then refine it with the monotonicity condition *) let pure_wp' (a: Type) = pure_post a -> GTot pure_pre (** The monotonicity predicate is marked opaque_to_smt, meaning that its definition is hidden from the SMT solver, and if required, will need to be explicitly revealed This has the advantage that clients that do not need to work with it directly, don't have the (quantified) definition in their solver context *) let pure_wp_monotonic0 (a:Type) (wp:pure_wp' a) = forall (p q:pure_post a). (forall (x:a). p x ==> q x) ==> (wp p ==> wp q) [@@ "opaque_to_smt"] let pure_wp_monotonic = pure_wp_monotonic0 let pure_wp (a: Type) = wp:pure_wp' a{pure_wp_monotonic a wp} (** This predicate is an internal detail, used to optimize the encoding of some quantifiers to SMT by omitting their typing guards. This is safe to use only when the quantifier serves to introduce a local macro---use with caution. *) assume type guard_free : Type0 -> Type0 (** The return combinator for the PURE effect requires proving the postcondition only on [x] Clients should not use it directly, instead use FStar.Pervasives.pure_return *) unfold let pure_return0 (a: Type) (x: a) : pure_wp a = fun (p: pure_post a) -> forall (return_val: a). return_val == x ==> p return_val (** Sequential composition for the PURE effect Clients should not use it directly, instead use FStar.Pervasives.pure_bind_wp *) unfold let pure_bind_wp0 (a b: Type) (wp1: pure_wp a) (wp2: (a -> GTot (pure_wp b))) : pure_wp b = fun (p: pure_post b) -> wp1 (fun (bind_result_1: a) -> wp2 bind_result_1 p) (** Conditional composition for the PURE effect The combinator is optimized to make use of how the typechecker generates VC for conditionals. The more intuitive form of the combinator would have been: [(p ==> wp_then post) /\ (~p ==> wp_else post)] However, the way the typechecker constructs the VC, [wp_then] is already weakened with [p]. Hence, here we only weaken [wp_else] Clients should not use it directly, instead use FStar.Pervasives.pure_if_then_else *) unfold let pure_if_then_else0 (a p: Type) (wp_then wp_else: pure_wp a) : pure_wp a = fun (post: pure_post a) -> wp_then post /\ (~p ==> wp_else post) (** Conditional composition for the PURE effect, while trying to avoid duplicating the postcondition by giving it a local name [k]. Note the use of [guard_free] here: [k] is just meant to be a macro for [post]. Clients should not use it directly, instead use FStar.Pervasives.pure_ite_wp *) unfold let pure_ite_wp0 (a: Type) (wp: pure_wp a) : pure_wp a = fun (post: pure_post a) -> forall (k: pure_post a). (forall (x: a). {:pattern (guard_free (k x))} post x ==> k x) ==> wp k (** Subsumption for the PURE effect *)
{ "checked_file": "/", "dependencies": [], "interface_file": false, "source_file": "prims.fst" }
[ { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
a: Type -> wp1: Prims.pure_wp a -> wp2: Prims.pure_wp a -> Prims.logical
Prims.Tot
[ "total" ]
[]
[ "Prims.pure_wp", "Prims.l_Forall", "Prims.pure_post", "Prims.l_imp", "Prims.logical" ]
[]
false
false
false
true
true
let pure_stronger (a: Type) (wp1 wp2: pure_wp a) =
forall (p: pure_post a). wp1 p ==> wp2 p
false
Vale.X64.Lemmas.fst
Vale.X64.Lemmas.increase_fuel
val increase_fuel (g: bool) (c: code) (s0: machine_state) (f0: fuel) (sN: machine_state) (fN: fuel) : Lemma (requires eval_code_ts g c s0 f0 sN /\ f0 <= fN) (ensures eval_code_ts g c s0 fN sN) (decreases %[f0;c])
val increase_fuel (g: bool) (c: code) (s0: machine_state) (f0: fuel) (sN: machine_state) (fN: fuel) : Lemma (requires eval_code_ts g c s0 f0 sN /\ f0 <= fN) (ensures eval_code_ts g c s0 fN sN) (decreases %[f0;c])
let rec increase_fuel (g:bool) (c:code) (s0:machine_state) (f0:fuel) (sN:machine_state) (fN:fuel) : Lemma (requires eval_code_ts g c s0 f0 sN /\ f0 <= fN) (ensures eval_code_ts g c s0 fN sN) (decreases %[f0; c]) = match c with | Ins ins -> () | Block l -> increase_fuels g l s0 f0 sN fN | IfElse cond t f -> let (s0, b0) = BS.machine_eval_ocmp s0 cond in if b0 then increase_fuel g t s0 f0 sN fN else increase_fuel g f s0 f0 sN fN | While cond c -> let (s1, b0) = BS.machine_eval_ocmp s0 cond in if b0 then ( match BS.machine_eval_code c (f0 - 1) s1 with | None -> () | Some s2 -> increase_fuel g c s1 (f0 - 1) s2 (fN - 1); if s2.BS.ms_ok then increase_fuel g (While cond c) s2 (f0 - 1) sN (fN - 1) else () ) and increase_fuels (g:bool) (c:codes) (s0:machine_state) (f0:fuel) (sN:machine_state) (fN:fuel) : Lemma (requires eval_code_ts g (Block c) s0 f0 sN /\ f0 <= fN) (ensures eval_code_ts g (Block c) s0 fN sN) (decreases %[f0; c]) = match c with | [] -> () | h::t -> ( let Some s1 = BS.machine_eval_code h f0 s0 in increase_fuel g h s0 f0 s1 fN; increase_fuels g t s1 f0 sN fN )
{ "file_name": "vale/code/arch/x64/Vale.X64.Lemmas.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 5, "end_line": 331, "start_col": 0, "start_line": 298 }
module Vale.X64.Lemmas open FStar.Mul open Vale.X64.Machine_s open Vale.X64.State open Vale.X64.StateLemmas open Vale.X64.Instruction_s open Vale.X64.Bytes_Code_s module BS = Vale.X64.Machine_Semantics_s module ME = Vale.X64.Memory #reset-options "--initial_fuel 1 --max_fuel 1 --z3rlimit 100" #restart-solver let rec lemma_eq_instr_apply_eval_args (outs:list instr_out) (args:list instr_operand) (f:instr_args_t outs args) (oprs:instr_operands_t_args args) (s1 s2:machine_state) : Lemma (requires state_eq_S true s1 s2) (ensures BS.instr_apply_eval_args outs args f oprs s1 == BS.instr_apply_eval_args outs args f oprs s2) = let open BS in lemma_heap_ignore_ghost_machine s1.BS.ms_heap s2.BS.ms_heap; match args with | [] -> () | i::args -> ( let (v, oprs) : option (instr_val_t i) & instr_operands_t_args args = match i with | IOpEx i -> let oprs = coerce oprs in (instr_eval_operand_explicit i (fst oprs) s1, snd oprs) | IOpIm i -> (instr_eval_operand_implicit i s1, coerce oprs) in let f:arrow (instr_val_t i) (instr_args_t outs args) = coerce f in match v with | None -> () | Some v -> lemma_eq_instr_apply_eval_args outs args (f v) oprs s1 s2 ) #restart-solver let rec lemma_eq_instr_apply_eval_inouts (outs inouts:list instr_out) (args:list instr_operand) (f:instr_inouts_t outs inouts args) (oprs:instr_operands_t inouts args) (s1 s2:machine_state) : Lemma (requires state_eq_S true s1 s2) (ensures BS.instr_apply_eval_inouts outs inouts args f oprs s1 == BS.instr_apply_eval_inouts outs inouts args f oprs s2) = let open BS in lemma_heap_ignore_ghost_machine s1.BS.ms_heap s2.BS.ms_heap; match inouts with | [] -> lemma_eq_instr_apply_eval_args outs args f oprs s1 s2 | (Out, i)::inouts -> let oprs = match i with | IOpEx i -> snd #(instr_operand_t i) (coerce oprs) | IOpIm i -> coerce oprs in lemma_eq_instr_apply_eval_inouts outs inouts args (coerce f) oprs s1 s2 | (InOut, i)::inouts -> ( let (v, oprs) : option (instr_val_t i) & instr_operands_t inouts args = match i with | IOpEx i -> let oprs = coerce oprs in (instr_eval_operand_explicit i (fst oprs) s1, snd oprs) | IOpIm i -> (instr_eval_operand_implicit i s1, coerce oprs) in let f:arrow (instr_val_t i) (instr_inouts_t outs inouts args) = coerce f in match v with | None -> () | Some v -> lemma_eq_instr_apply_eval_inouts outs inouts args (f v) oprs s1 s2 ) #restart-solver #push-options "--z3rlimit_factor 2" let rec lemma_eq_instr_write_outputs (outs:list instr_out) (args:list instr_operand) (vs:instr_ret_t outs) (oprs:instr_operands_t outs args) (s1_orig s1 s2_orig s2:machine_state) : Lemma (requires state_eq_S true s1_orig s2_orig /\ state_eq_S true s1 s2) (ensures state_eq_S true (BS.instr_write_outputs outs args vs oprs s1_orig s1) (BS.instr_write_outputs outs args vs oprs s2_orig s2)) = let open BS in use_machine_state_equal (); lemma_heap_ignore_ghost_machine s1.BS.ms_heap s2.BS.ms_heap; lemma_heap_ignore_ghost_machine s1_orig.BS.ms_heap s2_orig.BS.ms_heap; allow_inversion tmaddr; match outs with | [] -> () | (_, i)::outs -> ( let ((v:instr_val_t i), (vs:instr_ret_t outs)) = match outs with | [] -> (vs, ()) | _::_ -> let vs = coerce vs in (fst vs, snd vs) in match i with | IOpEx i -> let oprs = coerce oprs in let s1 = instr_write_output_explicit i v (fst oprs) s1_orig s1 in let s2 = instr_write_output_explicit i v (fst oprs) s2_orig s2 in lemma_eq_instr_write_outputs outs args vs (snd oprs) s1_orig s1 s2_orig s2 | IOpIm i -> let s1 = instr_write_output_implicit i v s1_orig s1 in let s2 = instr_write_output_implicit i v s2_orig s2 in allow_inversion operand64; allow_inversion operand128; lemma_eq_instr_write_outputs outs args vs (coerce oprs) s1_orig s1 s2_orig s2 ) #pop-options #restart-solver let eval_ins_eq_instr (inst:BS.ins) (s1 s2:machine_state) : Lemma (requires Instr? inst /\ state_eq_S true s1 s2) (ensures state_eq_S true (BS.machine_eval_ins inst s1) (BS.machine_eval_ins inst s2)) = let open BS in let Instr it oprs ann = inst in let InstrTypeRecord #outs #args #havoc_flags' i = it in lemma_eq_instr_apply_eval_inouts outs outs args (instr_eval i) oprs s1 s2; let vs = instr_apply_eval outs args (instr_eval i) oprs s1 in let hav s = match havoc_flags' with | HavocFlags -> {s with ms_flags = havoc_flags} | PreserveFlags -> s in let s1' = hav s1 in let s2' = hav s2 in match vs with | None -> () | Some vs -> lemma_eq_instr_write_outputs outs args vs oprs s1 s1' s2 s2' let eval_code_eq_instr (inst:BS.ins) (f:fuel) (s1 s2:machine_state) : Lemma (requires Instr? inst /\ state_eq_S true s1 s2) (ensures state_eq_opt true (BS.machine_eval_code (Ins inst) f s1) (BS.machine_eval_code (Ins inst) f s2)) = reveal_opaque (`%BS.machine_eval_code_ins) BS.machine_eval_code_ins; eval_ins_eq_instr inst ({s1 with BS.ms_trace = []}) ({s2 with BS.ms_trace = []}) let eval_code_eq_dealloc (inst:BS.ins) (f:fuel) (s1 s2:machine_state) : Lemma (requires Dealloc? inst /\ state_eq_S true s1 s2) (ensures state_eq_opt true (BS.machine_eval_code (Ins inst) f s1) (BS.machine_eval_code (Ins inst) f s2)) = reveal_opaque (`%BS.machine_eval_code_ins) BS.machine_eval_code_ins; use_machine_state_equal (); lemma_heap_ignore_ghost_machine s1.BS.ms_heap s2.BS.ms_heap; allow_inversion tmaddr let eval_code_eq_alloc (inst:BS.ins) (f:fuel) (s1 s2:machine_state) : Lemma (requires Alloc? inst /\ state_eq_S true s1 s2) (ensures state_eq_opt true (BS.machine_eval_code (Ins inst) f s1) (BS.machine_eval_code (Ins inst) f s2)) = reveal_opaque (`%BS.machine_eval_code_ins) BS.machine_eval_code_ins; use_machine_state_equal (); lemma_heap_ignore_ghost_machine s1.BS.ms_heap s2.BS.ms_heap; allow_inversion tmaddr let eval_code_eq_push (inst:BS.ins) (f:fuel) (s1 s2:machine_state) : Lemma (requires Push? inst /\ state_eq_S true s1 s2) (ensures state_eq_opt true (BS.machine_eval_code (Ins inst) f s1) (BS.machine_eval_code (Ins inst) f s2)) = reveal_opaque (`%BS.machine_eval_code_ins) BS.machine_eval_code_ins; use_machine_state_equal (); lemma_heap_ignore_ghost_machine s1.BS.ms_heap s2.BS.ms_heap; allow_inversion tmaddr let eval_code_eq_pop (inst:BS.ins) (f:fuel) (s1 s2:machine_state) : Lemma (requires Pop? inst /\ state_eq_S true s1 s2) (ensures state_eq_opt true (BS.machine_eval_code (Ins inst) f s1) (BS.machine_eval_code (Ins inst) f s2)) = reveal_opaque (`%BS.machine_eval_code_ins) BS.machine_eval_code_ins; use_machine_state_equal (); lemma_heap_ignore_ghost_machine s1.BS.ms_heap s2.BS.ms_heap; allow_inversion tmaddr let eval_code_eq_ins (i:BS.ins) (f:fuel) (s1 s2:machine_state) : Lemma (requires state_eq_S true s1 s2) (ensures state_eq_opt true (BS.machine_eval_code (Ins i) f s1) (BS.machine_eval_code (Ins i) f s2)) = match i with | Instr _ _ _ -> eval_code_eq_instr i f s1 s2 | Dealloc _ -> eval_code_eq_dealloc i f s1 s2 | Alloc _ -> eval_code_eq_alloc i f s1 s2 | Push _ _ -> eval_code_eq_push i f s1 s2 | Pop _ _ -> eval_code_eq_pop i f s1 s2 #reset-options "--fuel 2 --z3rlimit 30" let eval_ocmp_eq_core (g:bool) (cond:ocmp) (s:machine_state) : Lemma (ensures ( let (s1, b1) = BS.machine_eval_ocmp s cond in let (s2, b2) = BS.machine_eval_ocmp (core_state g s) cond in state_eq_S g s1 s2 /\ b1 == b2 )) = reveal_opaque (`%BS.valid_ocmp_opaque) BS.valid_ocmp_opaque; reveal_opaque (`%BS.eval_ocmp_opaque) BS.eval_ocmp_opaque; () #restart-solver let rec eval_code_eq_core (g:bool) (c:code) (f:fuel) (s:machine_state) : Lemma (ensures state_eq_opt g (BS.machine_eval_code c f s) (BS.machine_eval_code c f (core_state g s))) (decreases %[f; c]) = match c with | Ins i -> reveal_opaque (`%BS.machine_eval_code_ins) BS.machine_eval_code_ins; if g then eval_code_eq_ins i f s (core_state g s) | Block cs -> eval_codes_eq_core g cs f s | IfElse cond ct cf -> eval_ocmp_eq_core g cond s; let (s', _) = BS.machine_eval_ocmp s cond in let (t', _) = BS.machine_eval_ocmp (core_state g s) cond in eval_code_eq_core g ct f s'; eval_code_eq_core g ct f t'; eval_code_eq_core g cf f s'; eval_code_eq_core g cf f t'; () | While cond body -> eval_while_eq_core g cond body f s and eval_codes_eq_core (g:bool) (cs:codes) (f:fuel) (s:machine_state) : Lemma (ensures state_eq_opt g (BS.machine_eval_codes cs f s) (BS.machine_eval_codes cs f (core_state g s))) (decreases %[f; cs]) = match cs with | [] -> () | c'::cs' -> ( eval_code_eq_core g c' f s; match (machine_eval_code c' f s, machine_eval_code c' f (core_state g s)) with | (None, None) -> () | (Some s', Some t') -> eval_codes_eq_core g cs' f s'; eval_codes_eq_core g cs' f t' ) and eval_while_eq_core (g:bool) (cond:ocmp) (body:code) (f:fuel) (s:machine_state) : Lemma (ensures state_eq_opt g (BS.machine_eval_while cond body f s) (BS.machine_eval_while cond body f (core_state g s))) (decreases %[f; body]) = if f > 0 then ( eval_ocmp_eq_core g cond s; let (s1, _) = BS.machine_eval_ocmp s cond in let (t1, _) = BS.machine_eval_ocmp (core_state g s) cond in eval_code_eq_core g body (f - 1) s1; eval_code_eq_core g body (f - 1) t1; match (BS.machine_eval_code body (f - 1) s1, BS.machine_eval_code body (f - 1) t1) with | (None, None) -> () | (Some s2, Some t2) -> eval_while_eq_core g cond body (f - 1) s2; eval_while_eq_core g cond body (f - 1) t2; () ) let eval_code_eq_f (c:code) (f:fuel) (s1 s2:machine_state) : Lemma (requires state_eq_S false s1 s2) (ensures state_eq_opt false (BS.machine_eval_code c f s1) (BS.machine_eval_code c f s2)) [SMTPat (BS.machine_eval_code c f s1); SMTPat (BS.machine_eval_code c f s2)] = eval_code_eq_core false c f s1; eval_code_eq_core false c f s2 let eval_codes_eq_f (cs:codes) (f:fuel) (s1 s2:machine_state) : Lemma (requires state_eq_S false s1 s2) (ensures state_eq_opt false (BS.machine_eval_codes cs f s1) (BS.machine_eval_codes cs f s2)) [SMTPat (BS.machine_eval_codes cs f s1); SMTPat (BS.machine_eval_codes cs f s2)] = eval_codes_eq_core false cs f s1; eval_codes_eq_core false cs f s2 let eval_while_eq_f (cond:ocmp) (body:code) (f:fuel) (s1 s2:machine_state) : Lemma (requires state_eq_S false s1 s2) (ensures state_eq_opt false (BS.machine_eval_while cond body f s1) (BS.machine_eval_while cond body f s2)) [SMTPat (BS.machine_eval_while cond body f s1); SMTPat (BS.machine_eval_while cond body f s2)] = eval_while_eq_core false cond body f s1; eval_while_eq_core false cond body f s2 let eval_code_eq_t (c:code) (f:fuel) (s1 s2:machine_state) : Lemma (requires state_eq_S true s1 s2) (ensures state_eq_opt true (BS.machine_eval_code c f s1) (BS.machine_eval_code c f s2)) [SMTPat (BS.machine_eval_code c f s1); SMTPat (BS.machine_eval_code c f s2)] = eval_code_eq_core true c f s1; eval_code_eq_core true c f s2 let eval_codes_eq_t (cs:codes) (f:fuel) (s1 s2:machine_state) : Lemma (requires state_eq_S true s1 s2) (ensures state_eq_opt true (BS.machine_eval_codes cs f s1) (BS.machine_eval_codes cs f s2)) [SMTPat (BS.machine_eval_codes cs f s1); SMTPat (BS.machine_eval_codes cs f s2)] = eval_codes_eq_core true cs f s1; eval_codes_eq_core true cs f s2 let eval_while_eq_t (cond:ocmp) (body:code) (f:fuel) (s1 s2:machine_state) : Lemma (requires state_eq_S true s1 s2) (ensures state_eq_opt true (BS.machine_eval_while cond body f s1) (BS.machine_eval_while cond body f s2)) [SMTPat (BS.machine_eval_while cond body f s1); SMTPat (BS.machine_eval_while cond body f s2)] = eval_while_eq_core true cond body f s1; eval_while_eq_core true cond body f s2 let eval_code_ts (g:bool) (c:code) (s0:machine_state) (f0:fuel) (s1:machine_state) : Type0 = state_eq_opt g (BS.machine_eval_code c f0 s0) (Some s1)
{ "checked_file": "/", "dependencies": [ "Vale.X64.StateLemmas.fsti.checked", "Vale.X64.State.fsti.checked", "Vale.X64.Memory.fsti.checked", "Vale.X64.Machine_Semantics_s.fst.checked", "Vale.X64.Machine_s.fst.checked", "Vale.X64.Instruction_s.fsti.checked", "Vale.X64.Flags.fsti.checked", "Vale.X64.Bytes_Code_s.fst.checked", "prims.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.FunctionalExtensionality.fsti.checked" ], "interface_file": true, "source_file": "Vale.X64.Lemmas.fst" }
[ { "abbrev": true, "full_module": "Vale.X64.Memory", "short_module": "ME" }, { "abbrev": true, "full_module": "Vale.X64.Machine_Semantics_s", "short_module": "BS" }, { "abbrev": false, "full_module": "Vale.X64.Bytes_Code_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Instruction_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.StateLemmas", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.State", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Machine_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": true, "full_module": "Vale.Lib.Map16", "short_module": "Map16" }, { "abbrev": true, "full_module": "Vale.X64.Machine_Semantics_s", "short_module": "BS" }, { "abbrev": false, "full_module": "Vale.X64.Bytes_Code_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.StateLemmas", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.State", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Machine_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.HeapLemmas", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.HeapImpl", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.Heap", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 0, "max_fuel": 2, "max_ifuel": 1, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": true, "smtencoding_l_arith_repr": "native", "smtencoding_nl_arith_repr": "wrapped", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [ "smt.arith.nl=false", "smt.QI.EAGER_THRESHOLD=100", "smt.CASE_SPLIT=3" ], "z3refresh": false, "z3rlimit": 30, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
g: Prims.bool -> c: Vale.X64.StateLemmas.code -> s0: Vale.X64.StateLemmas.machine_state -> f0: Vale.X64.Lemmas.fuel -> sN: Vale.X64.StateLemmas.machine_state -> fN: Vale.X64.Lemmas.fuel -> FStar.Pervasives.Lemma (requires Vale.X64.Lemmas.eval_code_ts g c s0 f0 sN /\ f0 <= fN) (ensures Vale.X64.Lemmas.eval_code_ts g c s0 fN sN) (decreases %[f0;c])
FStar.Pervasives.Lemma
[ "lemma", "" ]
[ "increase_fuel", "increase_fuels" ]
[ "Prims.bool", "Vale.X64.StateLemmas.code", "Vale.X64.StateLemmas.machine_state", "Vale.X64.Lemmas.fuel", "Vale.X64.Bytes_Code_s.instruction_t", "Vale.X64.Machine_Semantics_s.instr_annotation", "Prims.list", "Vale.X64.Machine_s.precode", "Vale.X64.Bytes_Code_s.ocmp", "Vale.X64.Lemmas.increase_fuels", "Vale.X64.Machine_Semantics_s.machine_state", "Vale.X64.Lemmas.increase_fuel", "Prims.unit", "FStar.Pervasives.Native.tuple2", "Vale.X64.Machine_Semantics_s.machine_eval_ocmp", "Vale.X64.Machine_Semantics_s.machine_eval_code", "Prims.op_Subtraction", "Vale.X64.Machine_Semantics_s.__proj__Mkmachine_state__item__ms_ok", "Vale.X64.Machine_s.While", "Prims.l_and", "Vale.X64.Lemmas.eval_code_ts", "Prims.b2t", "Prims.op_LessThanOrEqual", "Prims.squash", "Prims.Nil", "FStar.Pervasives.pattern" ]
[ "mutual recursion" ]
false
false
true
false
false
let rec increase_fuel (g: bool) (c: code) (s0: machine_state) (f0: fuel) (sN: machine_state) (fN: fuel) : Lemma (requires eval_code_ts g c s0 f0 sN /\ f0 <= fN) (ensures eval_code_ts g c s0 fN sN) (decreases %[f0;c]) =
match c with | Ins ins -> () | Block l -> increase_fuels g l s0 f0 sN fN | IfElse cond t f -> let s0, b0 = BS.machine_eval_ocmp s0 cond in if b0 then increase_fuel g t s0 f0 sN fN else increase_fuel g f s0 f0 sN fN | While cond c -> let s1, b0 = BS.machine_eval_ocmp s0 cond in if b0 then (match BS.machine_eval_code c (f0 - 1) s1 with | None -> () | Some s2 -> increase_fuel g c s1 (f0 - 1) s2 (fN - 1); if s2.BS.ms_ok then increase_fuel g (While cond c) s2 (f0 - 1) sN (fN - 1))
false
prims.fst
Prims.pure_trivial
val pure_trivial : a: Type -> wp: Prims.pure_wp a -> Prims.pure_pre
let pure_trivial (a: Type) (wp: pure_wp a) = wp (fun (trivial_result: a) -> True)
{ "file_name": "ulib/prims.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 81, "end_line": 396, "start_col": 0, "start_line": 396 }
(* Copyright 2008-2020 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 Prims /// This module is implicitly opened in the scope of all other modules. /// /// It provides the very basic primitives on which F* is /// built, including the definition of total functions, the basic /// logical connectives, the PURE and GHOST effects and the like. /// /// While some of the primitives have logical significance, others are /// define various conveniences in the language, e.g., type of /// attributes. (***** Begin trusted primitives *****) (** Primitives up to the definition of the GTot effect are trusted Beyond that all definitions are fully verified *) (** Type of attributes *) assume new type attribute : Type0 (** An attribute indicating that some definition must be processed by the Dijkstra monads for free construction *) assume val cps:attribute (** A predicate to express when a type supports decidable equality The type-checker emits axioms for [hasEq] for each inductive type *) assume type hasEq : Type -> GTot Type0 (** A convenient abbreviation, [eqtype] is the type of types in universe 0 which support decidable equality *) type eqtype = a: Type0{hasEq a} (** [bool] is a two element type with elements [true] and [false]. We assume it is primitive, for convenient interop with other languages, although it could easily be defined as an inductive type with two cases, [BTrue | BFalse] *) assume new type bool : eqtype (** [empty] is the empty inductive type. The type with no inhabitants represents logical falsehood. Note, [empty] is seldom used directly in F*. We instead use its "squashed" variant, [False], see below. *) type empty = (** [trivial] is the singleton inductive type---it is trivially inhabited. Like [empty], [trivial] is seldom used. We instead use its "squashed" variants, [True] *) type trivial = | T (** [unit]: another singleton type, with its only inhabitant written [()] we assume it is primitive, for convenient interop with other languages *) assume new type unit : eqtype (** [squash p] is a central type in F*---[squash p] is the proof irrelevant analog of [p] and is represented as a unit refinement. Squashed proofs are typically discharged using an SMT solver, without any proof terms explicitly reconstructed. As such, one way to think of [squash p] is as the type of properties proven using classical axioms without building proof terms. Note, [squash p] is just a unit refinement, it resides in universe 0, lowering the universe of [p]. From this perspective, one may also see [squash] as a coercion down to universe 0. The type is marked [tac_opaque] to indicate to Meta-F* that instances of [squash] should not be unfolded when evaluating tactics (since many optimizations in F*'s SMT encoding rely specifically on occurrences of [squash]. See FStar.Squash for various ways of manipulating squashed types. *) [@@ "tac_opaque"] type squash (p: Type) : Type0 = x: unit{p} (** [auto_squash] is equivalent to [squash]. However, F* will automatically insert `auto_squash` when simplifying terms, converting terms of the form `p /\ True` to `auto_squash p`. We distinguish these automatically inserted squashes from explicit, user-written squashes. A user should not have to manipulate [auto_squash] at all, except in rare circumstances when writing tactics to process proofs that have already been partially simplified by F*'s simplifier. *) let auto_squash (p: Type) = squash p (** The [logical] type is transitionary. It is just an abbreviation for [Type0], but is used to classify uses of the basic squashed logical connectives that follow. Some day, we plan to remove the [logical] type, replacing it with [prop] (also defined below). The type is marked [private] to intentionally prevent user code from referencing this type, hopefully easing the removal of [logical] in the future. *) private type logical = Type0 (** An attribute indicating that a symbol is an smt theory symbol and hence may not be used in smt patterns. The typechecker warns if such symbols are used in patterns *) assume val smt_theory_symbol:attribute (** [l_True] has a special bit of syntactic sugar. It is written just as "True" and rendered in the ide as [True]. It is a squashed version of constructive truth, [trivial]. *) [@@ "tac_opaque"; smt_theory_symbol] let l_True:logical = squash trivial (** [l_False] has a special bit of syntactic sugar. It is written just as "False" and rendered in the ide as [Falsee]. It is a squashed version of constructive falsehood, the empty type. *) [@@ "tac_opaque"; smt_theory_symbol] let l_False:logical = squash empty (** The type of provable equalities, defined as the usual inductive type with a single constructor for reflexivity. As with the other connectives, we often work instead with the squashed version of equality, below. *) type equals (#a: Type) (x: a) : a -> Type = | Refl : equals x x (** [eq2] is the squashed version of [equals]. It's a proof irrelevant, homogeneous equality in Type#0 and is written with an infix binary [==]. TODO: instead of hard-wiring the == syntax, we should just rename eq2 to op_Equals_Equals *) [@@ "tac_opaque"; smt_theory_symbol] type eq2 (#a: Type) (x: a) (y: a) : logical = squash (equals x y) (** bool-to-type coercion: This is often automatically inserted type, when using a boolean in context expecting a type. But, occasionally, one may have to write [b2t] explicitly *) type b2t (b: bool) : logical = (b == true) (** constructive conjunction *) type pair (p: Type) (q: Type) = | Pair : _1:p -> _2:q -> pair p q (** squashed conjunction, specialized to [Type0], written with an infix binary [/\] *) [@@ "tac_opaque"; smt_theory_symbol] type l_and (p: logical) (q: logical) : logical = squash (pair p q) (** constructive disjunction *) type sum (p: Type) (q: Type) = | Left : v:p -> sum p q | Right : v:q -> sum p q (** squashed disjunction, specialized to [Type0], written with an infix binary [\/] *) [@@ "tac_opaque"; smt_theory_symbol] type l_or (p: logical) (q: logical) : logical = squash (sum p q) (** squashed (non-dependent) implication, specialized to [Type0], written with an infix binary [==>]. Note, [==>] binds weaker than [/\] and [\/] *) [@@ "tac_opaque"; smt_theory_symbol] type l_imp (p: logical) (q: logical) : logical = squash (p -> GTot q) (* ^^^ NB: The GTot effect is primitive; *) (* elaborated using GHOST a few lines below *) (** squashed double implication, infix binary [<==>] *) [@@ smt_theory_symbol] type l_iff (p: logical) (q: logical) : logical = (p ==> q) /\ (q ==> p) (** squashed negation, prefix unary [~] *) [@@ smt_theory_symbol] type l_not (p: logical) : logical = l_imp p False (** l_ITE is a weak form of if-then-else at the level of logical formulae. It's not much used. TODO: Can we remove it *) unfold type l_ITE (p: logical) (q: logical) (r: logical) : logical = (p ==> q) /\ (~p ==> r) (** One of the main axioms provided by prims is [precedes], a built-in well-founded partial order over all terms. It's typically written with an infix binary [<<]. The [<<] order includes: * The [<] ordering on natural numbers * The subterm ordering on inductive types * [f x << D f] for data constructors D of an inductive t whose arguments include a ghost or total function returning a t *) assume type precedes : #a: Type -> #b: Type -> a -> b -> Type0 (** The type of primitive strings of characters; See FStar.String *) assume new type string : eqtype (** This attribute can be added to the declaration or definition of any top-level symbol. It causes F* to report a warning on any use of that symbol, printing the [msg] argument. This is used, for instance to: - tag every escape hatch, e.g., [assume], [admit], etc Reports for uses of symbols tagged with this attribute are controlled using the `--report_assumes` option and warning number 334. See tests/micro-benchmarks/WarnOnUse.fst *) assume val warn_on_use (msg: string) : Tot unit (** The [deprecated "s"] attribute: "s" is an alternative function that should be printed in the warning it can be omitted if the use case has no such function *) assume val deprecated (s: string) : Tot unit (** Within the SMT encoding, we have a relation [(HasType e t)] asserting that (the encoding of) [e] has a type corresponding to (the encoding of) [t]. It is sometimes convenient, e.g., when writing triggers for quantifiers, to have access to this relation at the source level. The [has_type] predicate below reflects the SMT encodings [HasType] relation. We also use it to define the type [prop] or proof irrelevant propositions, below. Note, unless you have a really good reason, you probably don't want to use this [has_type] predicate. F*'s type theory certainly does not internalize its own typing judgment *) [@@deprecated "'has_type' is intended for internal use and debugging purposes only; \ do not rely on it for your proofs"] assume type has_type : #a: Type -> a -> Type -> Type0 (** Squashed universal quantification, or dependent products, written [forall (x:a). p x], specialized to Type0 *) [@@ "tac_opaque"; smt_theory_symbol] type l_Forall (#a: Type) (p: (a -> GTot Type0)) : logical = squash (x: a -> GTot (p x)) #push-options "--warn_error -288" (** [p1 `subtype_of` p2] when every element of [p1] is also an element of [p2]. *) let subtype_of (p1 p2: Type) = forall (x: p1). has_type x p2 #pop-options (** The type of squashed types. Note, the [prop] type is a work in progress in F*. In particular, we would like in the future to more systematically use [prop] for proof-irrelevant propositions throughout the libraries. However, we still use [Type0] in many places. See https://github.com/FStarLang/FStar/issues/1048 for more details and the current status of the work. *) type prop = a: Type0{a `subtype_of` unit} (**** The PURE effect *) (** The type of pure preconditions *) let pure_pre = Type0 (** Pure postconditions, predicates on [a], on which the precondition [pre] is also valid. This provides a way for postcondition formula to be typed in a context where they can assume the validity of the precondition. This is discussed extensively in Issue #57 *) let pure_post' (a pre: Type) = _: a{pre} -> GTot Type0 let pure_post (a: Type) = pure_post' a True (** A pure weakest precondition transforms postconditions on [a]-typed results to pure preconditions We require the weakest preconditions to satisfy the monotonicity property over the postconditions To enforce it, we first define a vanilla wp type, and then refine it with the monotonicity condition *) let pure_wp' (a: Type) = pure_post a -> GTot pure_pre (** The monotonicity predicate is marked opaque_to_smt, meaning that its definition is hidden from the SMT solver, and if required, will need to be explicitly revealed This has the advantage that clients that do not need to work with it directly, don't have the (quantified) definition in their solver context *) let pure_wp_monotonic0 (a:Type) (wp:pure_wp' a) = forall (p q:pure_post a). (forall (x:a). p x ==> q x) ==> (wp p ==> wp q) [@@ "opaque_to_smt"] let pure_wp_monotonic = pure_wp_monotonic0 let pure_wp (a: Type) = wp:pure_wp' a{pure_wp_monotonic a wp} (** This predicate is an internal detail, used to optimize the encoding of some quantifiers to SMT by omitting their typing guards. This is safe to use only when the quantifier serves to introduce a local macro---use with caution. *) assume type guard_free : Type0 -> Type0 (** The return combinator for the PURE effect requires proving the postcondition only on [x] Clients should not use it directly, instead use FStar.Pervasives.pure_return *) unfold let pure_return0 (a: Type) (x: a) : pure_wp a = fun (p: pure_post a) -> forall (return_val: a). return_val == x ==> p return_val (** Sequential composition for the PURE effect Clients should not use it directly, instead use FStar.Pervasives.pure_bind_wp *) unfold let pure_bind_wp0 (a b: Type) (wp1: pure_wp a) (wp2: (a -> GTot (pure_wp b))) : pure_wp b = fun (p: pure_post b) -> wp1 (fun (bind_result_1: a) -> wp2 bind_result_1 p) (** Conditional composition for the PURE effect The combinator is optimized to make use of how the typechecker generates VC for conditionals. The more intuitive form of the combinator would have been: [(p ==> wp_then post) /\ (~p ==> wp_else post)] However, the way the typechecker constructs the VC, [wp_then] is already weakened with [p]. Hence, here we only weaken [wp_else] Clients should not use it directly, instead use FStar.Pervasives.pure_if_then_else *) unfold let pure_if_then_else0 (a p: Type) (wp_then wp_else: pure_wp a) : pure_wp a = fun (post: pure_post a) -> wp_then post /\ (~p ==> wp_else post) (** Conditional composition for the PURE effect, while trying to avoid duplicating the postcondition by giving it a local name [k]. Note the use of [guard_free] here: [k] is just meant to be a macro for [post]. Clients should not use it directly, instead use FStar.Pervasives.pure_ite_wp *) unfold let pure_ite_wp0 (a: Type) (wp: pure_wp a) : pure_wp a = fun (post: pure_post a) -> forall (k: pure_post a). (forall (x: a). {:pattern (guard_free (k x))} post x ==> k x) ==> wp k (** Subsumption for the PURE effect *) unfold let pure_stronger (a: Type) (wp1 wp2: pure_wp a) = forall (p: pure_post a). wp1 p ==> wp2 p (** Closing a PURE WP under a binder for [b] Clients should not use it directly, instead use FStar.Pervasives.pure_close_wp *) unfold let pure_close_wp0 (a b: Type) (wp: (b -> GTot (pure_wp a))) : pure_wp a = fun (p: pure_post a) -> forall (b: b). wp b p (** Trivial WP for PURE: Prove the WP with the trivial postcondition *)
{ "checked_file": "/", "dependencies": [], "interface_file": false, "source_file": "prims.fst" }
[ { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
a: Type -> wp: Prims.pure_wp a -> Prims.pure_pre
Prims.Tot
[ "total" ]
[]
[ "Prims.pure_wp", "Prims.l_True", "Prims.pure_pre" ]
[]
false
false
false
true
false
let pure_trivial (a: Type) (wp: pure_wp a) =
wp (fun (trivial_result: a) -> True)
false
prims.fst
Prims.purewp_id
val purewp_id : a: Type -> wp: Prims.pure_wp a -> Prims.pure_wp a
let purewp_id (a: Type) (wp: pure_wp a) = wp
{ "file_name": "ulib/prims.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 44, "end_line": 455, "start_col": 0, "start_line": 455 }
(* Copyright 2008-2020 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 Prims /// This module is implicitly opened in the scope of all other modules. /// /// It provides the very basic primitives on which F* is /// built, including the definition of total functions, the basic /// logical connectives, the PURE and GHOST effects and the like. /// /// While some of the primitives have logical significance, others are /// define various conveniences in the language, e.g., type of /// attributes. (***** Begin trusted primitives *****) (** Primitives up to the definition of the GTot effect are trusted Beyond that all definitions are fully verified *) (** Type of attributes *) assume new type attribute : Type0 (** An attribute indicating that some definition must be processed by the Dijkstra monads for free construction *) assume val cps:attribute (** A predicate to express when a type supports decidable equality The type-checker emits axioms for [hasEq] for each inductive type *) assume type hasEq : Type -> GTot Type0 (** A convenient abbreviation, [eqtype] is the type of types in universe 0 which support decidable equality *) type eqtype = a: Type0{hasEq a} (** [bool] is a two element type with elements [true] and [false]. We assume it is primitive, for convenient interop with other languages, although it could easily be defined as an inductive type with two cases, [BTrue | BFalse] *) assume new type bool : eqtype (** [empty] is the empty inductive type. The type with no inhabitants represents logical falsehood. Note, [empty] is seldom used directly in F*. We instead use its "squashed" variant, [False], see below. *) type empty = (** [trivial] is the singleton inductive type---it is trivially inhabited. Like [empty], [trivial] is seldom used. We instead use its "squashed" variants, [True] *) type trivial = | T (** [unit]: another singleton type, with its only inhabitant written [()] we assume it is primitive, for convenient interop with other languages *) assume new type unit : eqtype (** [squash p] is a central type in F*---[squash p] is the proof irrelevant analog of [p] and is represented as a unit refinement. Squashed proofs are typically discharged using an SMT solver, without any proof terms explicitly reconstructed. As such, one way to think of [squash p] is as the type of properties proven using classical axioms without building proof terms. Note, [squash p] is just a unit refinement, it resides in universe 0, lowering the universe of [p]. From this perspective, one may also see [squash] as a coercion down to universe 0. The type is marked [tac_opaque] to indicate to Meta-F* that instances of [squash] should not be unfolded when evaluating tactics (since many optimizations in F*'s SMT encoding rely specifically on occurrences of [squash]. See FStar.Squash for various ways of manipulating squashed types. *) [@@ "tac_opaque"] type squash (p: Type) : Type0 = x: unit{p} (** [auto_squash] is equivalent to [squash]. However, F* will automatically insert `auto_squash` when simplifying terms, converting terms of the form `p /\ True` to `auto_squash p`. We distinguish these automatically inserted squashes from explicit, user-written squashes. A user should not have to manipulate [auto_squash] at all, except in rare circumstances when writing tactics to process proofs that have already been partially simplified by F*'s simplifier. *) let auto_squash (p: Type) = squash p (** The [logical] type is transitionary. It is just an abbreviation for [Type0], but is used to classify uses of the basic squashed logical connectives that follow. Some day, we plan to remove the [logical] type, replacing it with [prop] (also defined below). The type is marked [private] to intentionally prevent user code from referencing this type, hopefully easing the removal of [logical] in the future. *) private type logical = Type0 (** An attribute indicating that a symbol is an smt theory symbol and hence may not be used in smt patterns. The typechecker warns if such symbols are used in patterns *) assume val smt_theory_symbol:attribute (** [l_True] has a special bit of syntactic sugar. It is written just as "True" and rendered in the ide as [True]. It is a squashed version of constructive truth, [trivial]. *) [@@ "tac_opaque"; smt_theory_symbol] let l_True:logical = squash trivial (** [l_False] has a special bit of syntactic sugar. It is written just as "False" and rendered in the ide as [Falsee]. It is a squashed version of constructive falsehood, the empty type. *) [@@ "tac_opaque"; smt_theory_symbol] let l_False:logical = squash empty (** The type of provable equalities, defined as the usual inductive type with a single constructor for reflexivity. As with the other connectives, we often work instead with the squashed version of equality, below. *) type equals (#a: Type) (x: a) : a -> Type = | Refl : equals x x (** [eq2] is the squashed version of [equals]. It's a proof irrelevant, homogeneous equality in Type#0 and is written with an infix binary [==]. TODO: instead of hard-wiring the == syntax, we should just rename eq2 to op_Equals_Equals *) [@@ "tac_opaque"; smt_theory_symbol] type eq2 (#a: Type) (x: a) (y: a) : logical = squash (equals x y) (** bool-to-type coercion: This is often automatically inserted type, when using a boolean in context expecting a type. But, occasionally, one may have to write [b2t] explicitly *) type b2t (b: bool) : logical = (b == true) (** constructive conjunction *) type pair (p: Type) (q: Type) = | Pair : _1:p -> _2:q -> pair p q (** squashed conjunction, specialized to [Type0], written with an infix binary [/\] *) [@@ "tac_opaque"; smt_theory_symbol] type l_and (p: logical) (q: logical) : logical = squash (pair p q) (** constructive disjunction *) type sum (p: Type) (q: Type) = | Left : v:p -> sum p q | Right : v:q -> sum p q (** squashed disjunction, specialized to [Type0], written with an infix binary [\/] *) [@@ "tac_opaque"; smt_theory_symbol] type l_or (p: logical) (q: logical) : logical = squash (sum p q) (** squashed (non-dependent) implication, specialized to [Type0], written with an infix binary [==>]. Note, [==>] binds weaker than [/\] and [\/] *) [@@ "tac_opaque"; smt_theory_symbol] type l_imp (p: logical) (q: logical) : logical = squash (p -> GTot q) (* ^^^ NB: The GTot effect is primitive; *) (* elaborated using GHOST a few lines below *) (** squashed double implication, infix binary [<==>] *) [@@ smt_theory_symbol] type l_iff (p: logical) (q: logical) : logical = (p ==> q) /\ (q ==> p) (** squashed negation, prefix unary [~] *) [@@ smt_theory_symbol] type l_not (p: logical) : logical = l_imp p False (** l_ITE is a weak form of if-then-else at the level of logical formulae. It's not much used. TODO: Can we remove it *) unfold type l_ITE (p: logical) (q: logical) (r: logical) : logical = (p ==> q) /\ (~p ==> r) (** One of the main axioms provided by prims is [precedes], a built-in well-founded partial order over all terms. It's typically written with an infix binary [<<]. The [<<] order includes: * The [<] ordering on natural numbers * The subterm ordering on inductive types * [f x << D f] for data constructors D of an inductive t whose arguments include a ghost or total function returning a t *) assume type precedes : #a: Type -> #b: Type -> a -> b -> Type0 (** The type of primitive strings of characters; See FStar.String *) assume new type string : eqtype (** This attribute can be added to the declaration or definition of any top-level symbol. It causes F* to report a warning on any use of that symbol, printing the [msg] argument. This is used, for instance to: - tag every escape hatch, e.g., [assume], [admit], etc Reports for uses of symbols tagged with this attribute are controlled using the `--report_assumes` option and warning number 334. See tests/micro-benchmarks/WarnOnUse.fst *) assume val warn_on_use (msg: string) : Tot unit (** The [deprecated "s"] attribute: "s" is an alternative function that should be printed in the warning it can be omitted if the use case has no such function *) assume val deprecated (s: string) : Tot unit (** Within the SMT encoding, we have a relation [(HasType e t)] asserting that (the encoding of) [e] has a type corresponding to (the encoding of) [t]. It is sometimes convenient, e.g., when writing triggers for quantifiers, to have access to this relation at the source level. The [has_type] predicate below reflects the SMT encodings [HasType] relation. We also use it to define the type [prop] or proof irrelevant propositions, below. Note, unless you have a really good reason, you probably don't want to use this [has_type] predicate. F*'s type theory certainly does not internalize its own typing judgment *) [@@deprecated "'has_type' is intended for internal use and debugging purposes only; \ do not rely on it for your proofs"] assume type has_type : #a: Type -> a -> Type -> Type0 (** Squashed universal quantification, or dependent products, written [forall (x:a). p x], specialized to Type0 *) [@@ "tac_opaque"; smt_theory_symbol] type l_Forall (#a: Type) (p: (a -> GTot Type0)) : logical = squash (x: a -> GTot (p x)) #push-options "--warn_error -288" (** [p1 `subtype_of` p2] when every element of [p1] is also an element of [p2]. *) let subtype_of (p1 p2: Type) = forall (x: p1). has_type x p2 #pop-options (** The type of squashed types. Note, the [prop] type is a work in progress in F*. In particular, we would like in the future to more systematically use [prop] for proof-irrelevant propositions throughout the libraries. However, we still use [Type0] in many places. See https://github.com/FStarLang/FStar/issues/1048 for more details and the current status of the work. *) type prop = a: Type0{a `subtype_of` unit} (**** The PURE effect *) (** The type of pure preconditions *) let pure_pre = Type0 (** Pure postconditions, predicates on [a], on which the precondition [pre] is also valid. This provides a way for postcondition formula to be typed in a context where they can assume the validity of the precondition. This is discussed extensively in Issue #57 *) let pure_post' (a pre: Type) = _: a{pre} -> GTot Type0 let pure_post (a: Type) = pure_post' a True (** A pure weakest precondition transforms postconditions on [a]-typed results to pure preconditions We require the weakest preconditions to satisfy the monotonicity property over the postconditions To enforce it, we first define a vanilla wp type, and then refine it with the monotonicity condition *) let pure_wp' (a: Type) = pure_post a -> GTot pure_pre (** The monotonicity predicate is marked opaque_to_smt, meaning that its definition is hidden from the SMT solver, and if required, will need to be explicitly revealed This has the advantage that clients that do not need to work with it directly, don't have the (quantified) definition in their solver context *) let pure_wp_monotonic0 (a:Type) (wp:pure_wp' a) = forall (p q:pure_post a). (forall (x:a). p x ==> q x) ==> (wp p ==> wp q) [@@ "opaque_to_smt"] let pure_wp_monotonic = pure_wp_monotonic0 let pure_wp (a: Type) = wp:pure_wp' a{pure_wp_monotonic a wp} (** This predicate is an internal detail, used to optimize the encoding of some quantifiers to SMT by omitting their typing guards. This is safe to use only when the quantifier serves to introduce a local macro---use with caution. *) assume type guard_free : Type0 -> Type0 (** The return combinator for the PURE effect requires proving the postcondition only on [x] Clients should not use it directly, instead use FStar.Pervasives.pure_return *) unfold let pure_return0 (a: Type) (x: a) : pure_wp a = fun (p: pure_post a) -> forall (return_val: a). return_val == x ==> p return_val (** Sequential composition for the PURE effect Clients should not use it directly, instead use FStar.Pervasives.pure_bind_wp *) unfold let pure_bind_wp0 (a b: Type) (wp1: pure_wp a) (wp2: (a -> GTot (pure_wp b))) : pure_wp b = fun (p: pure_post b) -> wp1 (fun (bind_result_1: a) -> wp2 bind_result_1 p) (** Conditional composition for the PURE effect The combinator is optimized to make use of how the typechecker generates VC for conditionals. The more intuitive form of the combinator would have been: [(p ==> wp_then post) /\ (~p ==> wp_else post)] However, the way the typechecker constructs the VC, [wp_then] is already weakened with [p]. Hence, here we only weaken [wp_else] Clients should not use it directly, instead use FStar.Pervasives.pure_if_then_else *) unfold let pure_if_then_else0 (a p: Type) (wp_then wp_else: pure_wp a) : pure_wp a = fun (post: pure_post a) -> wp_then post /\ (~p ==> wp_else post) (** Conditional composition for the PURE effect, while trying to avoid duplicating the postcondition by giving it a local name [k]. Note the use of [guard_free] here: [k] is just meant to be a macro for [post]. Clients should not use it directly, instead use FStar.Pervasives.pure_ite_wp *) unfold let pure_ite_wp0 (a: Type) (wp: pure_wp a) : pure_wp a = fun (post: pure_post a) -> forall (k: pure_post a). (forall (x: a). {:pattern (guard_free (k x))} post x ==> k x) ==> wp k (** Subsumption for the PURE effect *) unfold let pure_stronger (a: Type) (wp1 wp2: pure_wp a) = forall (p: pure_post a). wp1 p ==> wp2 p (** Closing a PURE WP under a binder for [b] Clients should not use it directly, instead use FStar.Pervasives.pure_close_wp *) unfold let pure_close_wp0 (a b: Type) (wp: (b -> GTot (pure_wp a))) : pure_wp a = fun (p: pure_post a) -> forall (b: b). wp b p (** Trivial WP for PURE: Prove the WP with the trivial postcondition *) unfold let pure_trivial (a: Type) (wp: pure_wp a) = wp (fun (trivial_result: a) -> True) (** Introduces the PURE effect. The definition of the PURE effect is fixed. NO USER SHOULD EVER CHANGE THIS. *) total new_effect { PURE : a: Type -> wp: pure_wp a -> Effect with return_wp = pure_return0 ; bind_wp = pure_bind_wp0 ; if_then_else = pure_if_then_else0 ; ite_wp = pure_ite_wp0 ; stronger = pure_stronger ; close_wp = pure_close_wp0 ; trivial = pure_trivial } (** [Pure] is a Hoare-style counterpart of [PURE] Note the type of post, which allows to assume the precondition for the well-formedness of the postcondition. c.f. #57 *) effect Pure (a: Type) (pre: pure_pre) (post: pure_post' a pre) = PURE a (fun (p: pure_post a) -> pre /\ (forall (pure_result: a). post pure_result ==> p pure_result)) (** [Admit] is an effect abbreviation for a computation that disregards the verification condition of its continuation *) effect Admit (a: Type) = PURE a (fun (p: pure_post a) -> True) (** The primitive effect [Tot] is definitionally equal to an instance of [PURE] *) (** Clients should not use it directly, instead use FStar.Pervasives.pure_null_wp *) unfold let pure_null_wp0 (a: Type) : pure_wp a = fun (p: pure_post a) -> forall (any_result: a). p any_result (** [Tot]: From here on, we have [Tot] as a defined symbol in F*. *) effect Tot (a: Type) = PURE a (pure_null_wp0 a) (** Clients should not use it directly, instead use FStar.Pervasives.pure_assert_wp *) [@@ "opaque_to_smt"] unfold let pure_assert_wp0 (p: Type) : pure_wp unit = fun (post: pure_post unit) -> p /\ post () (** Clients should not use it directly, instead use FStar.Pervasives.pure_assume_wp *) [@@ "opaque_to_smt"] unfold let pure_assume_wp0 (p: Type) : pure_wp unit = fun (post: pure_post unit) -> p ==> post () (**** The [GHOST] effect *) (** [GHOST] is logically equivalent to [PURE], but distinguished from it nominally so that specific, computationally irrelevant operations, are provided only in [GHOST] and are erased during extraction *) total new_effect GHOST = PURE
{ "checked_file": "/", "dependencies": [], "interface_file": false, "source_file": "prims.fst" }
[ { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
a: Type -> wp: Prims.pure_wp a -> Prims.pure_wp a
Prims.Tot
[ "total" ]
[]
[ "Prims.pure_wp" ]
[]
false
false
false
true
false
let purewp_id (a: Type) (wp: pure_wp a) =
wp
false
prims.fst
Prims.op_Hat
val op_Hat : s1: Prims.string -> s2: Prims.string -> Prims.string
let op_Hat s1 s2 = strcat s1 s2
{ "file_name": "ulib/prims.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 31, "end_line": 590, "start_col": 0, "start_line": 590 }
(* Copyright 2008-2020 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 Prims /// This module is implicitly opened in the scope of all other modules. /// /// It provides the very basic primitives on which F* is /// built, including the definition of total functions, the basic /// logical connectives, the PURE and GHOST effects and the like. /// /// While some of the primitives have logical significance, others are /// define various conveniences in the language, e.g., type of /// attributes. (***** Begin trusted primitives *****) (** Primitives up to the definition of the GTot effect are trusted Beyond that all definitions are fully verified *) (** Type of attributes *) assume new type attribute : Type0 (** An attribute indicating that some definition must be processed by the Dijkstra monads for free construction *) assume val cps:attribute (** A predicate to express when a type supports decidable equality The type-checker emits axioms for [hasEq] for each inductive type *) assume type hasEq : Type -> GTot Type0 (** A convenient abbreviation, [eqtype] is the type of types in universe 0 which support decidable equality *) type eqtype = a: Type0{hasEq a} (** [bool] is a two element type with elements [true] and [false]. We assume it is primitive, for convenient interop with other languages, although it could easily be defined as an inductive type with two cases, [BTrue | BFalse] *) assume new type bool : eqtype (** [empty] is the empty inductive type. The type with no inhabitants represents logical falsehood. Note, [empty] is seldom used directly in F*. We instead use its "squashed" variant, [False], see below. *) type empty = (** [trivial] is the singleton inductive type---it is trivially inhabited. Like [empty], [trivial] is seldom used. We instead use its "squashed" variants, [True] *) type trivial = | T (** [unit]: another singleton type, with its only inhabitant written [()] we assume it is primitive, for convenient interop with other languages *) assume new type unit : eqtype (** [squash p] is a central type in F*---[squash p] is the proof irrelevant analog of [p] and is represented as a unit refinement. Squashed proofs are typically discharged using an SMT solver, without any proof terms explicitly reconstructed. As such, one way to think of [squash p] is as the type of properties proven using classical axioms without building proof terms. Note, [squash p] is just a unit refinement, it resides in universe 0, lowering the universe of [p]. From this perspective, one may also see [squash] as a coercion down to universe 0. The type is marked [tac_opaque] to indicate to Meta-F* that instances of [squash] should not be unfolded when evaluating tactics (since many optimizations in F*'s SMT encoding rely specifically on occurrences of [squash]. See FStar.Squash for various ways of manipulating squashed types. *) [@@ "tac_opaque"] type squash (p: Type) : Type0 = x: unit{p} (** [auto_squash] is equivalent to [squash]. However, F* will automatically insert `auto_squash` when simplifying terms, converting terms of the form `p /\ True` to `auto_squash p`. We distinguish these automatically inserted squashes from explicit, user-written squashes. A user should not have to manipulate [auto_squash] at all, except in rare circumstances when writing tactics to process proofs that have already been partially simplified by F*'s simplifier. *) let auto_squash (p: Type) = squash p (** The [logical] type is transitionary. It is just an abbreviation for [Type0], but is used to classify uses of the basic squashed logical connectives that follow. Some day, we plan to remove the [logical] type, replacing it with [prop] (also defined below). The type is marked [private] to intentionally prevent user code from referencing this type, hopefully easing the removal of [logical] in the future. *) private type logical = Type0 (** An attribute indicating that a symbol is an smt theory symbol and hence may not be used in smt patterns. The typechecker warns if such symbols are used in patterns *) assume val smt_theory_symbol:attribute (** [l_True] has a special bit of syntactic sugar. It is written just as "True" and rendered in the ide as [True]. It is a squashed version of constructive truth, [trivial]. *) [@@ "tac_opaque"; smt_theory_symbol] let l_True:logical = squash trivial (** [l_False] has a special bit of syntactic sugar. It is written just as "False" and rendered in the ide as [Falsee]. It is a squashed version of constructive falsehood, the empty type. *) [@@ "tac_opaque"; smt_theory_symbol] let l_False:logical = squash empty (** The type of provable equalities, defined as the usual inductive type with a single constructor for reflexivity. As with the other connectives, we often work instead with the squashed version of equality, below. *) type equals (#a: Type) (x: a) : a -> Type = | Refl : equals x x (** [eq2] is the squashed version of [equals]. It's a proof irrelevant, homogeneous equality in Type#0 and is written with an infix binary [==]. TODO: instead of hard-wiring the == syntax, we should just rename eq2 to op_Equals_Equals *) [@@ "tac_opaque"; smt_theory_symbol] type eq2 (#a: Type) (x: a) (y: a) : logical = squash (equals x y) (** bool-to-type coercion: This is often automatically inserted type, when using a boolean in context expecting a type. But, occasionally, one may have to write [b2t] explicitly *) type b2t (b: bool) : logical = (b == true) (** constructive conjunction *) type pair (p: Type) (q: Type) = | Pair : _1:p -> _2:q -> pair p q (** squashed conjunction, specialized to [Type0], written with an infix binary [/\] *) [@@ "tac_opaque"; smt_theory_symbol] type l_and (p: logical) (q: logical) : logical = squash (pair p q) (** constructive disjunction *) type sum (p: Type) (q: Type) = | Left : v:p -> sum p q | Right : v:q -> sum p q (** squashed disjunction, specialized to [Type0], written with an infix binary [\/] *) [@@ "tac_opaque"; smt_theory_symbol] type l_or (p: logical) (q: logical) : logical = squash (sum p q) (** squashed (non-dependent) implication, specialized to [Type0], written with an infix binary [==>]. Note, [==>] binds weaker than [/\] and [\/] *) [@@ "tac_opaque"; smt_theory_symbol] type l_imp (p: logical) (q: logical) : logical = squash (p -> GTot q) (* ^^^ NB: The GTot effect is primitive; *) (* elaborated using GHOST a few lines below *) (** squashed double implication, infix binary [<==>] *) [@@ smt_theory_symbol] type l_iff (p: logical) (q: logical) : logical = (p ==> q) /\ (q ==> p) (** squashed negation, prefix unary [~] *) [@@ smt_theory_symbol] type l_not (p: logical) : logical = l_imp p False (** l_ITE is a weak form of if-then-else at the level of logical formulae. It's not much used. TODO: Can we remove it *) unfold type l_ITE (p: logical) (q: logical) (r: logical) : logical = (p ==> q) /\ (~p ==> r) (** One of the main axioms provided by prims is [precedes], a built-in well-founded partial order over all terms. It's typically written with an infix binary [<<]. The [<<] order includes: * The [<] ordering on natural numbers * The subterm ordering on inductive types * [f x << D f] for data constructors D of an inductive t whose arguments include a ghost or total function returning a t *) assume type precedes : #a: Type -> #b: Type -> a -> b -> Type0 (** The type of primitive strings of characters; See FStar.String *) assume new type string : eqtype (** This attribute can be added to the declaration or definition of any top-level symbol. It causes F* to report a warning on any use of that symbol, printing the [msg] argument. This is used, for instance to: - tag every escape hatch, e.g., [assume], [admit], etc Reports for uses of symbols tagged with this attribute are controlled using the `--report_assumes` option and warning number 334. See tests/micro-benchmarks/WarnOnUse.fst *) assume val warn_on_use (msg: string) : Tot unit (** The [deprecated "s"] attribute: "s" is an alternative function that should be printed in the warning it can be omitted if the use case has no such function *) assume val deprecated (s: string) : Tot unit (** Within the SMT encoding, we have a relation [(HasType e t)] asserting that (the encoding of) [e] has a type corresponding to (the encoding of) [t]. It is sometimes convenient, e.g., when writing triggers for quantifiers, to have access to this relation at the source level. The [has_type] predicate below reflects the SMT encodings [HasType] relation. We also use it to define the type [prop] or proof irrelevant propositions, below. Note, unless you have a really good reason, you probably don't want to use this [has_type] predicate. F*'s type theory certainly does not internalize its own typing judgment *) [@@deprecated "'has_type' is intended for internal use and debugging purposes only; \ do not rely on it for your proofs"] assume type has_type : #a: Type -> a -> Type -> Type0 (** Squashed universal quantification, or dependent products, written [forall (x:a). p x], specialized to Type0 *) [@@ "tac_opaque"; smt_theory_symbol] type l_Forall (#a: Type) (p: (a -> GTot Type0)) : logical = squash (x: a -> GTot (p x)) #push-options "--warn_error -288" (** [p1 `subtype_of` p2] when every element of [p1] is also an element of [p2]. *) let subtype_of (p1 p2: Type) = forall (x: p1). has_type x p2 #pop-options (** The type of squashed types. Note, the [prop] type is a work in progress in F*. In particular, we would like in the future to more systematically use [prop] for proof-irrelevant propositions throughout the libraries. However, we still use [Type0] in many places. See https://github.com/FStarLang/FStar/issues/1048 for more details and the current status of the work. *) type prop = a: Type0{a `subtype_of` unit} (**** The PURE effect *) (** The type of pure preconditions *) let pure_pre = Type0 (** Pure postconditions, predicates on [a], on which the precondition [pre] is also valid. This provides a way for postcondition formula to be typed in a context where they can assume the validity of the precondition. This is discussed extensively in Issue #57 *) let pure_post' (a pre: Type) = _: a{pre} -> GTot Type0 let pure_post (a: Type) = pure_post' a True (** A pure weakest precondition transforms postconditions on [a]-typed results to pure preconditions We require the weakest preconditions to satisfy the monotonicity property over the postconditions To enforce it, we first define a vanilla wp type, and then refine it with the monotonicity condition *) let pure_wp' (a: Type) = pure_post a -> GTot pure_pre (** The monotonicity predicate is marked opaque_to_smt, meaning that its definition is hidden from the SMT solver, and if required, will need to be explicitly revealed This has the advantage that clients that do not need to work with it directly, don't have the (quantified) definition in their solver context *) let pure_wp_monotonic0 (a:Type) (wp:pure_wp' a) = forall (p q:pure_post a). (forall (x:a). p x ==> q x) ==> (wp p ==> wp q) [@@ "opaque_to_smt"] let pure_wp_monotonic = pure_wp_monotonic0 let pure_wp (a: Type) = wp:pure_wp' a{pure_wp_monotonic a wp} (** This predicate is an internal detail, used to optimize the encoding of some quantifiers to SMT by omitting their typing guards. This is safe to use only when the quantifier serves to introduce a local macro---use with caution. *) assume type guard_free : Type0 -> Type0 (** The return combinator for the PURE effect requires proving the postcondition only on [x] Clients should not use it directly, instead use FStar.Pervasives.pure_return *) unfold let pure_return0 (a: Type) (x: a) : pure_wp a = fun (p: pure_post a) -> forall (return_val: a). return_val == x ==> p return_val (** Sequential composition for the PURE effect Clients should not use it directly, instead use FStar.Pervasives.pure_bind_wp *) unfold let pure_bind_wp0 (a b: Type) (wp1: pure_wp a) (wp2: (a -> GTot (pure_wp b))) : pure_wp b = fun (p: pure_post b) -> wp1 (fun (bind_result_1: a) -> wp2 bind_result_1 p) (** Conditional composition for the PURE effect The combinator is optimized to make use of how the typechecker generates VC for conditionals. The more intuitive form of the combinator would have been: [(p ==> wp_then post) /\ (~p ==> wp_else post)] However, the way the typechecker constructs the VC, [wp_then] is already weakened with [p]. Hence, here we only weaken [wp_else] Clients should not use it directly, instead use FStar.Pervasives.pure_if_then_else *) unfold let pure_if_then_else0 (a p: Type) (wp_then wp_else: pure_wp a) : pure_wp a = fun (post: pure_post a) -> wp_then post /\ (~p ==> wp_else post) (** Conditional composition for the PURE effect, while trying to avoid duplicating the postcondition by giving it a local name [k]. Note the use of [guard_free] here: [k] is just meant to be a macro for [post]. Clients should not use it directly, instead use FStar.Pervasives.pure_ite_wp *) unfold let pure_ite_wp0 (a: Type) (wp: pure_wp a) : pure_wp a = fun (post: pure_post a) -> forall (k: pure_post a). (forall (x: a). {:pattern (guard_free (k x))} post x ==> k x) ==> wp k (** Subsumption for the PURE effect *) unfold let pure_stronger (a: Type) (wp1 wp2: pure_wp a) = forall (p: pure_post a). wp1 p ==> wp2 p (** Closing a PURE WP under a binder for [b] Clients should not use it directly, instead use FStar.Pervasives.pure_close_wp *) unfold let pure_close_wp0 (a b: Type) (wp: (b -> GTot (pure_wp a))) : pure_wp a = fun (p: pure_post a) -> forall (b: b). wp b p (** Trivial WP for PURE: Prove the WP with the trivial postcondition *) unfold let pure_trivial (a: Type) (wp: pure_wp a) = wp (fun (trivial_result: a) -> True) (** Introduces the PURE effect. The definition of the PURE effect is fixed. NO USER SHOULD EVER CHANGE THIS. *) total new_effect { PURE : a: Type -> wp: pure_wp a -> Effect with return_wp = pure_return0 ; bind_wp = pure_bind_wp0 ; if_then_else = pure_if_then_else0 ; ite_wp = pure_ite_wp0 ; stronger = pure_stronger ; close_wp = pure_close_wp0 ; trivial = pure_trivial } (** [Pure] is a Hoare-style counterpart of [PURE] Note the type of post, which allows to assume the precondition for the well-formedness of the postcondition. c.f. #57 *) effect Pure (a: Type) (pre: pure_pre) (post: pure_post' a pre) = PURE a (fun (p: pure_post a) -> pre /\ (forall (pure_result: a). post pure_result ==> p pure_result)) (** [Admit] is an effect abbreviation for a computation that disregards the verification condition of its continuation *) effect Admit (a: Type) = PURE a (fun (p: pure_post a) -> True) (** The primitive effect [Tot] is definitionally equal to an instance of [PURE] *) (** Clients should not use it directly, instead use FStar.Pervasives.pure_null_wp *) unfold let pure_null_wp0 (a: Type) : pure_wp a = fun (p: pure_post a) -> forall (any_result: a). p any_result (** [Tot]: From here on, we have [Tot] as a defined symbol in F*. *) effect Tot (a: Type) = PURE a (pure_null_wp0 a) (** Clients should not use it directly, instead use FStar.Pervasives.pure_assert_wp *) [@@ "opaque_to_smt"] unfold let pure_assert_wp0 (p: Type) : pure_wp unit = fun (post: pure_post unit) -> p /\ post () (** Clients should not use it directly, instead use FStar.Pervasives.pure_assume_wp *) [@@ "opaque_to_smt"] unfold let pure_assume_wp0 (p: Type) : pure_wp unit = fun (post: pure_post unit) -> p ==> post () (**** The [GHOST] effect *) (** [GHOST] is logically equivalent to [PURE], but distinguished from it nominally so that specific, computationally irrelevant operations, are provided only in [GHOST] and are erased during extraction *) total new_effect GHOST = PURE unfold let purewp_id (a: Type) (wp: pure_wp a) = wp (** [PURE] computations can be lifted to the [GHOST] effect (but not vice versa) using just the identity lifting on pure wps *) sub_effect PURE ~> GHOST { lift_wp = purewp_id } (** [Ghost] is a the Hoare-style counterpart of [GHOST] *) effect Ghost (a: Type) (pre: Type) (post: pure_post' a pre) = GHOST a (fun (p: pure_post a) -> pre /\ (forall (ghost_result: a). post ghost_result ==> p ghost_result) ) (** As with [Tot], the primitive effect [GTot] is definitionally equal to an instance of GHOST *) effect GTot (a: Type) = GHOST a (pure_null_wp0 a) (***** End trusted primitives *****) (** This point onward, F* fully verifies all the definitions *) (** [===] heterogeneous equality *) let ( === ) (#a #b: Type) (x: a) (y: b) : logical = a == b /\ x == y (** Dependent pairs [dtuple2] in concrete syntax is [x:a & b x]. Its values can be constructed with the concrete syntax [(| x, y |)] *) unopteq type dtuple2 (a: Type) (b: (a -> GTot Type)) = | Mkdtuple2 : _1: a -> _2: b _1 -> dtuple2 a b (** Squashed existential quantification, or dependent sums, are written [exists (x:a). p x] : specialized to Type0 *) [@@ "tac_opaque"; smt_theory_symbol] type l_Exists (#a: Type) (p: (a -> GTot Type0)) : logical = squash (x: a & p x) (** Primitive type of mathematical integers, mapped to zarith in OCaml extraction and to the SMT sort of integers *) assume new type int : eqtype (**** Basic operators on booleans and integers *) (** [&&] boolean conjunction *) [@@ smt_theory_symbol] assume val op_AmpAmp: bool -> bool -> Tot bool (** [||] boolean disjunction *) [@@ smt_theory_symbol] assume val op_BarBar: bool -> bool -> Tot bool (** [not] boolean negation *) [@@ smt_theory_symbol] assume val op_Negation: bool -> Tot bool (** Integer multiplication, no special symbol. See FStar.Mul *) [@@ smt_theory_symbol] assume val op_Multiply: int -> int -> Tot int (** [-] integer subtraction *) [@@ smt_theory_symbol] assume val op_Subtraction: int -> int -> Tot int (** [+] integer addition *) [@@ smt_theory_symbol] assume val op_Addition: int -> int -> Tot int (** [-] prefix unary integer negation *) [@@ smt_theory_symbol] assume val op_Minus: int -> Tot int (** [<=] integer comparison *) [@@ smt_theory_symbol] assume val op_LessThanOrEqual: int -> int -> Tot bool (** [>] integer comparison *) [@@ smt_theory_symbol] assume val op_GreaterThan: int -> int -> Tot bool (** [>=] integer comparison *) [@@ smt_theory_symbol] assume val op_GreaterThanOrEqual: int -> int -> Tot bool (** [<] integer comparison *) [@@ smt_theory_symbol] assume val op_LessThan: int -> int -> Tot bool (** [=] decidable equality on [eqtype] *) [@@ smt_theory_symbol] assume val op_Equality: #a: eqtype -> a -> a -> Tot bool (** [<>] decidable dis-equality on [eqtype] *) [@@ smt_theory_symbol] assume val op_disEquality: #a: eqtype -> a -> a -> Tot bool (** The extensible open inductive type of exceptions *) assume new type exn : Type0 (** [array]: TODO: should be removed. See FStar.Seq, LowStar.Buffer, etc. *) assume new type array : Type -> Type0 (** String concatenation and its abbreviation as [^]. TODO, both should be removed in favor of what is present in FStar.String *) assume val strcat: string -> string -> Tot string
{ "checked_file": "/", "dependencies": [], "interface_file": false, "source_file": "prims.fst" }
[ { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
s1: Prims.string -> s2: Prims.string -> Prims.string
Prims.Tot
[ "total" ]
[]
[ "Prims.string", "Prims.strcat" ]
[]
false
false
false
true
false
let ( ^ ) s1 s2 =
strcat s1 s2
false
prims.fst
Prims.as_ensures
val as_ensures (#a: Type) (wp: pure_wp a) : pure_post a
val as_ensures (#a: Type) (wp: pure_wp a) : pure_post a
let as_ensures (#a: Type) (wp: pure_wp a) : pure_post a = fun (x:a) -> ~(wp (fun y -> (y =!= x)))
{ "file_name": "ulib/prims.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 97, "end_line": 614, "start_col": 0, "start_line": 614 }
(* Copyright 2008-2020 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 Prims /// This module is implicitly opened in the scope of all other modules. /// /// It provides the very basic primitives on which F* is /// built, including the definition of total functions, the basic /// logical connectives, the PURE and GHOST effects and the like. /// /// While some of the primitives have logical significance, others are /// define various conveniences in the language, e.g., type of /// attributes. (***** Begin trusted primitives *****) (** Primitives up to the definition of the GTot effect are trusted Beyond that all definitions are fully verified *) (** Type of attributes *) assume new type attribute : Type0 (** An attribute indicating that some definition must be processed by the Dijkstra monads for free construction *) assume val cps:attribute (** A predicate to express when a type supports decidable equality The type-checker emits axioms for [hasEq] for each inductive type *) assume type hasEq : Type -> GTot Type0 (** A convenient abbreviation, [eqtype] is the type of types in universe 0 which support decidable equality *) type eqtype = a: Type0{hasEq a} (** [bool] is a two element type with elements [true] and [false]. We assume it is primitive, for convenient interop with other languages, although it could easily be defined as an inductive type with two cases, [BTrue | BFalse] *) assume new type bool : eqtype (** [empty] is the empty inductive type. The type with no inhabitants represents logical falsehood. Note, [empty] is seldom used directly in F*. We instead use its "squashed" variant, [False], see below. *) type empty = (** [trivial] is the singleton inductive type---it is trivially inhabited. Like [empty], [trivial] is seldom used. We instead use its "squashed" variants, [True] *) type trivial = | T (** [unit]: another singleton type, with its only inhabitant written [()] we assume it is primitive, for convenient interop with other languages *) assume new type unit : eqtype (** [squash p] is a central type in F*---[squash p] is the proof irrelevant analog of [p] and is represented as a unit refinement. Squashed proofs are typically discharged using an SMT solver, without any proof terms explicitly reconstructed. As such, one way to think of [squash p] is as the type of properties proven using classical axioms without building proof terms. Note, [squash p] is just a unit refinement, it resides in universe 0, lowering the universe of [p]. From this perspective, one may also see [squash] as a coercion down to universe 0. The type is marked [tac_opaque] to indicate to Meta-F* that instances of [squash] should not be unfolded when evaluating tactics (since many optimizations in F*'s SMT encoding rely specifically on occurrences of [squash]. See FStar.Squash for various ways of manipulating squashed types. *) [@@ "tac_opaque"] type squash (p: Type) : Type0 = x: unit{p} (** [auto_squash] is equivalent to [squash]. However, F* will automatically insert `auto_squash` when simplifying terms, converting terms of the form `p /\ True` to `auto_squash p`. We distinguish these automatically inserted squashes from explicit, user-written squashes. A user should not have to manipulate [auto_squash] at all, except in rare circumstances when writing tactics to process proofs that have already been partially simplified by F*'s simplifier. *) let auto_squash (p: Type) = squash p (** The [logical] type is transitionary. It is just an abbreviation for [Type0], but is used to classify uses of the basic squashed logical connectives that follow. Some day, we plan to remove the [logical] type, replacing it with [prop] (also defined below). The type is marked [private] to intentionally prevent user code from referencing this type, hopefully easing the removal of [logical] in the future. *) private type logical = Type0 (** An attribute indicating that a symbol is an smt theory symbol and hence may not be used in smt patterns. The typechecker warns if such symbols are used in patterns *) assume val smt_theory_symbol:attribute (** [l_True] has a special bit of syntactic sugar. It is written just as "True" and rendered in the ide as [True]. It is a squashed version of constructive truth, [trivial]. *) [@@ "tac_opaque"; smt_theory_symbol] let l_True:logical = squash trivial (** [l_False] has a special bit of syntactic sugar. It is written just as "False" and rendered in the ide as [Falsee]. It is a squashed version of constructive falsehood, the empty type. *) [@@ "tac_opaque"; smt_theory_symbol] let l_False:logical = squash empty (** The type of provable equalities, defined as the usual inductive type with a single constructor for reflexivity. As with the other connectives, we often work instead with the squashed version of equality, below. *) type equals (#a: Type) (x: a) : a -> Type = | Refl : equals x x (** [eq2] is the squashed version of [equals]. It's a proof irrelevant, homogeneous equality in Type#0 and is written with an infix binary [==]. TODO: instead of hard-wiring the == syntax, we should just rename eq2 to op_Equals_Equals *) [@@ "tac_opaque"; smt_theory_symbol] type eq2 (#a: Type) (x: a) (y: a) : logical = squash (equals x y) (** bool-to-type coercion: This is often automatically inserted type, when using a boolean in context expecting a type. But, occasionally, one may have to write [b2t] explicitly *) type b2t (b: bool) : logical = (b == true) (** constructive conjunction *) type pair (p: Type) (q: Type) = | Pair : _1:p -> _2:q -> pair p q (** squashed conjunction, specialized to [Type0], written with an infix binary [/\] *) [@@ "tac_opaque"; smt_theory_symbol] type l_and (p: logical) (q: logical) : logical = squash (pair p q) (** constructive disjunction *) type sum (p: Type) (q: Type) = | Left : v:p -> sum p q | Right : v:q -> sum p q (** squashed disjunction, specialized to [Type0], written with an infix binary [\/] *) [@@ "tac_opaque"; smt_theory_symbol] type l_or (p: logical) (q: logical) : logical = squash (sum p q) (** squashed (non-dependent) implication, specialized to [Type0], written with an infix binary [==>]. Note, [==>] binds weaker than [/\] and [\/] *) [@@ "tac_opaque"; smt_theory_symbol] type l_imp (p: logical) (q: logical) : logical = squash (p -> GTot q) (* ^^^ NB: The GTot effect is primitive; *) (* elaborated using GHOST a few lines below *) (** squashed double implication, infix binary [<==>] *) [@@ smt_theory_symbol] type l_iff (p: logical) (q: logical) : logical = (p ==> q) /\ (q ==> p) (** squashed negation, prefix unary [~] *) [@@ smt_theory_symbol] type l_not (p: logical) : logical = l_imp p False (** l_ITE is a weak form of if-then-else at the level of logical formulae. It's not much used. TODO: Can we remove it *) unfold type l_ITE (p: logical) (q: logical) (r: logical) : logical = (p ==> q) /\ (~p ==> r) (** One of the main axioms provided by prims is [precedes], a built-in well-founded partial order over all terms. It's typically written with an infix binary [<<]. The [<<] order includes: * The [<] ordering on natural numbers * The subterm ordering on inductive types * [f x << D f] for data constructors D of an inductive t whose arguments include a ghost or total function returning a t *) assume type precedes : #a: Type -> #b: Type -> a -> b -> Type0 (** The type of primitive strings of characters; See FStar.String *) assume new type string : eqtype (** This attribute can be added to the declaration or definition of any top-level symbol. It causes F* to report a warning on any use of that symbol, printing the [msg] argument. This is used, for instance to: - tag every escape hatch, e.g., [assume], [admit], etc Reports for uses of symbols tagged with this attribute are controlled using the `--report_assumes` option and warning number 334. See tests/micro-benchmarks/WarnOnUse.fst *) assume val warn_on_use (msg: string) : Tot unit (** The [deprecated "s"] attribute: "s" is an alternative function that should be printed in the warning it can be omitted if the use case has no such function *) assume val deprecated (s: string) : Tot unit (** Within the SMT encoding, we have a relation [(HasType e t)] asserting that (the encoding of) [e] has a type corresponding to (the encoding of) [t]. It is sometimes convenient, e.g., when writing triggers for quantifiers, to have access to this relation at the source level. The [has_type] predicate below reflects the SMT encodings [HasType] relation. We also use it to define the type [prop] or proof irrelevant propositions, below. Note, unless you have a really good reason, you probably don't want to use this [has_type] predicate. F*'s type theory certainly does not internalize its own typing judgment *) [@@deprecated "'has_type' is intended for internal use and debugging purposes only; \ do not rely on it for your proofs"] assume type has_type : #a: Type -> a -> Type -> Type0 (** Squashed universal quantification, or dependent products, written [forall (x:a). p x], specialized to Type0 *) [@@ "tac_opaque"; smt_theory_symbol] type l_Forall (#a: Type) (p: (a -> GTot Type0)) : logical = squash (x: a -> GTot (p x)) #push-options "--warn_error -288" (** [p1 `subtype_of` p2] when every element of [p1] is also an element of [p2]. *) let subtype_of (p1 p2: Type) = forall (x: p1). has_type x p2 #pop-options (** The type of squashed types. Note, the [prop] type is a work in progress in F*. In particular, we would like in the future to more systematically use [prop] for proof-irrelevant propositions throughout the libraries. However, we still use [Type0] in many places. See https://github.com/FStarLang/FStar/issues/1048 for more details and the current status of the work. *) type prop = a: Type0{a `subtype_of` unit} (**** The PURE effect *) (** The type of pure preconditions *) let pure_pre = Type0 (** Pure postconditions, predicates on [a], on which the precondition [pre] is also valid. This provides a way for postcondition formula to be typed in a context where they can assume the validity of the precondition. This is discussed extensively in Issue #57 *) let pure_post' (a pre: Type) = _: a{pre} -> GTot Type0 let pure_post (a: Type) = pure_post' a True (** A pure weakest precondition transforms postconditions on [a]-typed results to pure preconditions We require the weakest preconditions to satisfy the monotonicity property over the postconditions To enforce it, we first define a vanilla wp type, and then refine it with the monotonicity condition *) let pure_wp' (a: Type) = pure_post a -> GTot pure_pre (** The monotonicity predicate is marked opaque_to_smt, meaning that its definition is hidden from the SMT solver, and if required, will need to be explicitly revealed This has the advantage that clients that do not need to work with it directly, don't have the (quantified) definition in their solver context *) let pure_wp_monotonic0 (a:Type) (wp:pure_wp' a) = forall (p q:pure_post a). (forall (x:a). p x ==> q x) ==> (wp p ==> wp q) [@@ "opaque_to_smt"] let pure_wp_monotonic = pure_wp_monotonic0 let pure_wp (a: Type) = wp:pure_wp' a{pure_wp_monotonic a wp} (** This predicate is an internal detail, used to optimize the encoding of some quantifiers to SMT by omitting their typing guards. This is safe to use only when the quantifier serves to introduce a local macro---use with caution. *) assume type guard_free : Type0 -> Type0 (** The return combinator for the PURE effect requires proving the postcondition only on [x] Clients should not use it directly, instead use FStar.Pervasives.pure_return *) unfold let pure_return0 (a: Type) (x: a) : pure_wp a = fun (p: pure_post a) -> forall (return_val: a). return_val == x ==> p return_val (** Sequential composition for the PURE effect Clients should not use it directly, instead use FStar.Pervasives.pure_bind_wp *) unfold let pure_bind_wp0 (a b: Type) (wp1: pure_wp a) (wp2: (a -> GTot (pure_wp b))) : pure_wp b = fun (p: pure_post b) -> wp1 (fun (bind_result_1: a) -> wp2 bind_result_1 p) (** Conditional composition for the PURE effect The combinator is optimized to make use of how the typechecker generates VC for conditionals. The more intuitive form of the combinator would have been: [(p ==> wp_then post) /\ (~p ==> wp_else post)] However, the way the typechecker constructs the VC, [wp_then] is already weakened with [p]. Hence, here we only weaken [wp_else] Clients should not use it directly, instead use FStar.Pervasives.pure_if_then_else *) unfold let pure_if_then_else0 (a p: Type) (wp_then wp_else: pure_wp a) : pure_wp a = fun (post: pure_post a) -> wp_then post /\ (~p ==> wp_else post) (** Conditional composition for the PURE effect, while trying to avoid duplicating the postcondition by giving it a local name [k]. Note the use of [guard_free] here: [k] is just meant to be a macro for [post]. Clients should not use it directly, instead use FStar.Pervasives.pure_ite_wp *) unfold let pure_ite_wp0 (a: Type) (wp: pure_wp a) : pure_wp a = fun (post: pure_post a) -> forall (k: pure_post a). (forall (x: a). {:pattern (guard_free (k x))} post x ==> k x) ==> wp k (** Subsumption for the PURE effect *) unfold let pure_stronger (a: Type) (wp1 wp2: pure_wp a) = forall (p: pure_post a). wp1 p ==> wp2 p (** Closing a PURE WP under a binder for [b] Clients should not use it directly, instead use FStar.Pervasives.pure_close_wp *) unfold let pure_close_wp0 (a b: Type) (wp: (b -> GTot (pure_wp a))) : pure_wp a = fun (p: pure_post a) -> forall (b: b). wp b p (** Trivial WP for PURE: Prove the WP with the trivial postcondition *) unfold let pure_trivial (a: Type) (wp: pure_wp a) = wp (fun (trivial_result: a) -> True) (** Introduces the PURE effect. The definition of the PURE effect is fixed. NO USER SHOULD EVER CHANGE THIS. *) total new_effect { PURE : a: Type -> wp: pure_wp a -> Effect with return_wp = pure_return0 ; bind_wp = pure_bind_wp0 ; if_then_else = pure_if_then_else0 ; ite_wp = pure_ite_wp0 ; stronger = pure_stronger ; close_wp = pure_close_wp0 ; trivial = pure_trivial } (** [Pure] is a Hoare-style counterpart of [PURE] Note the type of post, which allows to assume the precondition for the well-formedness of the postcondition. c.f. #57 *) effect Pure (a: Type) (pre: pure_pre) (post: pure_post' a pre) = PURE a (fun (p: pure_post a) -> pre /\ (forall (pure_result: a). post pure_result ==> p pure_result)) (** [Admit] is an effect abbreviation for a computation that disregards the verification condition of its continuation *) effect Admit (a: Type) = PURE a (fun (p: pure_post a) -> True) (** The primitive effect [Tot] is definitionally equal to an instance of [PURE] *) (** Clients should not use it directly, instead use FStar.Pervasives.pure_null_wp *) unfold let pure_null_wp0 (a: Type) : pure_wp a = fun (p: pure_post a) -> forall (any_result: a). p any_result (** [Tot]: From here on, we have [Tot] as a defined symbol in F*. *) effect Tot (a: Type) = PURE a (pure_null_wp0 a) (** Clients should not use it directly, instead use FStar.Pervasives.pure_assert_wp *) [@@ "opaque_to_smt"] unfold let pure_assert_wp0 (p: Type) : pure_wp unit = fun (post: pure_post unit) -> p /\ post () (** Clients should not use it directly, instead use FStar.Pervasives.pure_assume_wp *) [@@ "opaque_to_smt"] unfold let pure_assume_wp0 (p: Type) : pure_wp unit = fun (post: pure_post unit) -> p ==> post () (**** The [GHOST] effect *) (** [GHOST] is logically equivalent to [PURE], but distinguished from it nominally so that specific, computationally irrelevant operations, are provided only in [GHOST] and are erased during extraction *) total new_effect GHOST = PURE unfold let purewp_id (a: Type) (wp: pure_wp a) = wp (** [PURE] computations can be lifted to the [GHOST] effect (but not vice versa) using just the identity lifting on pure wps *) sub_effect PURE ~> GHOST { lift_wp = purewp_id } (** [Ghost] is a the Hoare-style counterpart of [GHOST] *) effect Ghost (a: Type) (pre: Type) (post: pure_post' a pre) = GHOST a (fun (p: pure_post a) -> pre /\ (forall (ghost_result: a). post ghost_result ==> p ghost_result) ) (** As with [Tot], the primitive effect [GTot] is definitionally equal to an instance of GHOST *) effect GTot (a: Type) = GHOST a (pure_null_wp0 a) (***** End trusted primitives *****) (** This point onward, F* fully verifies all the definitions *) (** [===] heterogeneous equality *) let ( === ) (#a #b: Type) (x: a) (y: b) : logical = a == b /\ x == y (** Dependent pairs [dtuple2] in concrete syntax is [x:a & b x]. Its values can be constructed with the concrete syntax [(| x, y |)] *) unopteq type dtuple2 (a: Type) (b: (a -> GTot Type)) = | Mkdtuple2 : _1: a -> _2: b _1 -> dtuple2 a b (** Squashed existential quantification, or dependent sums, are written [exists (x:a). p x] : specialized to Type0 *) [@@ "tac_opaque"; smt_theory_symbol] type l_Exists (#a: Type) (p: (a -> GTot Type0)) : logical = squash (x: a & p x) (** Primitive type of mathematical integers, mapped to zarith in OCaml extraction and to the SMT sort of integers *) assume new type int : eqtype (**** Basic operators on booleans and integers *) (** [&&] boolean conjunction *) [@@ smt_theory_symbol] assume val op_AmpAmp: bool -> bool -> Tot bool (** [||] boolean disjunction *) [@@ smt_theory_symbol] assume val op_BarBar: bool -> bool -> Tot bool (** [not] boolean negation *) [@@ smt_theory_symbol] assume val op_Negation: bool -> Tot bool (** Integer multiplication, no special symbol. See FStar.Mul *) [@@ smt_theory_symbol] assume val op_Multiply: int -> int -> Tot int (** [-] integer subtraction *) [@@ smt_theory_symbol] assume val op_Subtraction: int -> int -> Tot int (** [+] integer addition *) [@@ smt_theory_symbol] assume val op_Addition: int -> int -> Tot int (** [-] prefix unary integer negation *) [@@ smt_theory_symbol] assume val op_Minus: int -> Tot int (** [<=] integer comparison *) [@@ smt_theory_symbol] assume val op_LessThanOrEqual: int -> int -> Tot bool (** [>] integer comparison *) [@@ smt_theory_symbol] assume val op_GreaterThan: int -> int -> Tot bool (** [>=] integer comparison *) [@@ smt_theory_symbol] assume val op_GreaterThanOrEqual: int -> int -> Tot bool (** [<] integer comparison *) [@@ smt_theory_symbol] assume val op_LessThan: int -> int -> Tot bool (** [=] decidable equality on [eqtype] *) [@@ smt_theory_symbol] assume val op_Equality: #a: eqtype -> a -> a -> Tot bool (** [<>] decidable dis-equality on [eqtype] *) [@@ smt_theory_symbol] assume val op_disEquality: #a: eqtype -> a -> a -> Tot bool (** The extensible open inductive type of exceptions *) assume new type exn : Type0 (** [array]: TODO: should be removed. See FStar.Seq, LowStar.Buffer, etc. *) assume new type array : Type -> Type0 (** String concatenation and its abbreviation as [^]. TODO, both should be removed in favor of what is present in FStar.String *) assume val strcat: string -> string -> Tot string inline_for_extraction unfold let op_Hat s1 s2 = strcat s1 s2 (** The inductive type of polymorphic lists *) type list (a: Type) = | Nil : list a | Cons : hd: a -> tl: list a -> list a (** The [M] marker is interpreted by the Dijkstra Monads for Free construction. It has a "double meaning", either as an alias for reasoning about the direct definitions, or as a marker for places where a CPS transformation should happen. *) effect M (a: Type) = Tot a (attributes cps) (** Returning a value into the [M] effect *) let returnM (a: Type) (x: a) : M a = x (** [as_requires] turns a WP into a precondition, by applying it to a trivial postcondition *) unfold let as_requires (#a: Type) (wp: pure_wp a) : pure_pre = wp (fun x -> True) (** [as_ensures] turns a WP into a postcondition, relying on a kind of double negation translation. *)
{ "checked_file": "/", "dependencies": [], "interface_file": false, "source_file": "prims.fst" }
[ { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": 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
wp: Prims.pure_wp a -> Prims.pure_post a
Prims.Tot
[ "total" ]
[]
[ "Prims.pure_wp", "Prims.l_not", "Prims.l_True", "Prims.eq2", "Prims.pure_post" ]
[]
false
false
false
true
false
let as_ensures (#a: Type) (wp: pure_wp a) : pure_post a =
fun (x: a) -> ~(wp (fun y -> (y =!= x)))
false
prims.fst
Prims.as_requires
val as_requires (#a: Type) (wp: pure_wp a) : pure_pre
val as_requires (#a: Type) (wp: pure_wp a) : pure_pre
let as_requires (#a: Type) (wp: pure_wp a) : pure_pre = wp (fun x -> True)
{ "file_name": "ulib/prims.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 74, "end_line": 609, "start_col": 0, "start_line": 609 }
(* Copyright 2008-2020 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 Prims /// This module is implicitly opened in the scope of all other modules. /// /// It provides the very basic primitives on which F* is /// built, including the definition of total functions, the basic /// logical connectives, the PURE and GHOST effects and the like. /// /// While some of the primitives have logical significance, others are /// define various conveniences in the language, e.g., type of /// attributes. (***** Begin trusted primitives *****) (** Primitives up to the definition of the GTot effect are trusted Beyond that all definitions are fully verified *) (** Type of attributes *) assume new type attribute : Type0 (** An attribute indicating that some definition must be processed by the Dijkstra monads for free construction *) assume val cps:attribute (** A predicate to express when a type supports decidable equality The type-checker emits axioms for [hasEq] for each inductive type *) assume type hasEq : Type -> GTot Type0 (** A convenient abbreviation, [eqtype] is the type of types in universe 0 which support decidable equality *) type eqtype = a: Type0{hasEq a} (** [bool] is a two element type with elements [true] and [false]. We assume it is primitive, for convenient interop with other languages, although it could easily be defined as an inductive type with two cases, [BTrue | BFalse] *) assume new type bool : eqtype (** [empty] is the empty inductive type. The type with no inhabitants represents logical falsehood. Note, [empty] is seldom used directly in F*. We instead use its "squashed" variant, [False], see below. *) type empty = (** [trivial] is the singleton inductive type---it is trivially inhabited. Like [empty], [trivial] is seldom used. We instead use its "squashed" variants, [True] *) type trivial = | T (** [unit]: another singleton type, with its only inhabitant written [()] we assume it is primitive, for convenient interop with other languages *) assume new type unit : eqtype (** [squash p] is a central type in F*---[squash p] is the proof irrelevant analog of [p] and is represented as a unit refinement. Squashed proofs are typically discharged using an SMT solver, without any proof terms explicitly reconstructed. As such, one way to think of [squash p] is as the type of properties proven using classical axioms without building proof terms. Note, [squash p] is just a unit refinement, it resides in universe 0, lowering the universe of [p]. From this perspective, one may also see [squash] as a coercion down to universe 0. The type is marked [tac_opaque] to indicate to Meta-F* that instances of [squash] should not be unfolded when evaluating tactics (since many optimizations in F*'s SMT encoding rely specifically on occurrences of [squash]. See FStar.Squash for various ways of manipulating squashed types. *) [@@ "tac_opaque"] type squash (p: Type) : Type0 = x: unit{p} (** [auto_squash] is equivalent to [squash]. However, F* will automatically insert `auto_squash` when simplifying terms, converting terms of the form `p /\ True` to `auto_squash p`. We distinguish these automatically inserted squashes from explicit, user-written squashes. A user should not have to manipulate [auto_squash] at all, except in rare circumstances when writing tactics to process proofs that have already been partially simplified by F*'s simplifier. *) let auto_squash (p: Type) = squash p (** The [logical] type is transitionary. It is just an abbreviation for [Type0], but is used to classify uses of the basic squashed logical connectives that follow. Some day, we plan to remove the [logical] type, replacing it with [prop] (also defined below). The type is marked [private] to intentionally prevent user code from referencing this type, hopefully easing the removal of [logical] in the future. *) private type logical = Type0 (** An attribute indicating that a symbol is an smt theory symbol and hence may not be used in smt patterns. The typechecker warns if such symbols are used in patterns *) assume val smt_theory_symbol:attribute (** [l_True] has a special bit of syntactic sugar. It is written just as "True" and rendered in the ide as [True]. It is a squashed version of constructive truth, [trivial]. *) [@@ "tac_opaque"; smt_theory_symbol] let l_True:logical = squash trivial (** [l_False] has a special bit of syntactic sugar. It is written just as "False" and rendered in the ide as [Falsee]. It is a squashed version of constructive falsehood, the empty type. *) [@@ "tac_opaque"; smt_theory_symbol] let l_False:logical = squash empty (** The type of provable equalities, defined as the usual inductive type with a single constructor for reflexivity. As with the other connectives, we often work instead with the squashed version of equality, below. *) type equals (#a: Type) (x: a) : a -> Type = | Refl : equals x x (** [eq2] is the squashed version of [equals]. It's a proof irrelevant, homogeneous equality in Type#0 and is written with an infix binary [==]. TODO: instead of hard-wiring the == syntax, we should just rename eq2 to op_Equals_Equals *) [@@ "tac_opaque"; smt_theory_symbol] type eq2 (#a: Type) (x: a) (y: a) : logical = squash (equals x y) (** bool-to-type coercion: This is often automatically inserted type, when using a boolean in context expecting a type. But, occasionally, one may have to write [b2t] explicitly *) type b2t (b: bool) : logical = (b == true) (** constructive conjunction *) type pair (p: Type) (q: Type) = | Pair : _1:p -> _2:q -> pair p q (** squashed conjunction, specialized to [Type0], written with an infix binary [/\] *) [@@ "tac_opaque"; smt_theory_symbol] type l_and (p: logical) (q: logical) : logical = squash (pair p q) (** constructive disjunction *) type sum (p: Type) (q: Type) = | Left : v:p -> sum p q | Right : v:q -> sum p q (** squashed disjunction, specialized to [Type0], written with an infix binary [\/] *) [@@ "tac_opaque"; smt_theory_symbol] type l_or (p: logical) (q: logical) : logical = squash (sum p q) (** squashed (non-dependent) implication, specialized to [Type0], written with an infix binary [==>]. Note, [==>] binds weaker than [/\] and [\/] *) [@@ "tac_opaque"; smt_theory_symbol] type l_imp (p: logical) (q: logical) : logical = squash (p -> GTot q) (* ^^^ NB: The GTot effect is primitive; *) (* elaborated using GHOST a few lines below *) (** squashed double implication, infix binary [<==>] *) [@@ smt_theory_symbol] type l_iff (p: logical) (q: logical) : logical = (p ==> q) /\ (q ==> p) (** squashed negation, prefix unary [~] *) [@@ smt_theory_symbol] type l_not (p: logical) : logical = l_imp p False (** l_ITE is a weak form of if-then-else at the level of logical formulae. It's not much used. TODO: Can we remove it *) unfold type l_ITE (p: logical) (q: logical) (r: logical) : logical = (p ==> q) /\ (~p ==> r) (** One of the main axioms provided by prims is [precedes], a built-in well-founded partial order over all terms. It's typically written with an infix binary [<<]. The [<<] order includes: * The [<] ordering on natural numbers * The subterm ordering on inductive types * [f x << D f] for data constructors D of an inductive t whose arguments include a ghost or total function returning a t *) assume type precedes : #a: Type -> #b: Type -> a -> b -> Type0 (** The type of primitive strings of characters; See FStar.String *) assume new type string : eqtype (** This attribute can be added to the declaration or definition of any top-level symbol. It causes F* to report a warning on any use of that symbol, printing the [msg] argument. This is used, for instance to: - tag every escape hatch, e.g., [assume], [admit], etc Reports for uses of symbols tagged with this attribute are controlled using the `--report_assumes` option and warning number 334. See tests/micro-benchmarks/WarnOnUse.fst *) assume val warn_on_use (msg: string) : Tot unit (** The [deprecated "s"] attribute: "s" is an alternative function that should be printed in the warning it can be omitted if the use case has no such function *) assume val deprecated (s: string) : Tot unit (** Within the SMT encoding, we have a relation [(HasType e t)] asserting that (the encoding of) [e] has a type corresponding to (the encoding of) [t]. It is sometimes convenient, e.g., when writing triggers for quantifiers, to have access to this relation at the source level. The [has_type] predicate below reflects the SMT encodings [HasType] relation. We also use it to define the type [prop] or proof irrelevant propositions, below. Note, unless you have a really good reason, you probably don't want to use this [has_type] predicate. F*'s type theory certainly does not internalize its own typing judgment *) [@@deprecated "'has_type' is intended for internal use and debugging purposes only; \ do not rely on it for your proofs"] assume type has_type : #a: Type -> a -> Type -> Type0 (** Squashed universal quantification, or dependent products, written [forall (x:a). p x], specialized to Type0 *) [@@ "tac_opaque"; smt_theory_symbol] type l_Forall (#a: Type) (p: (a -> GTot Type0)) : logical = squash (x: a -> GTot (p x)) #push-options "--warn_error -288" (** [p1 `subtype_of` p2] when every element of [p1] is also an element of [p2]. *) let subtype_of (p1 p2: Type) = forall (x: p1). has_type x p2 #pop-options (** The type of squashed types. Note, the [prop] type is a work in progress in F*. In particular, we would like in the future to more systematically use [prop] for proof-irrelevant propositions throughout the libraries. However, we still use [Type0] in many places. See https://github.com/FStarLang/FStar/issues/1048 for more details and the current status of the work. *) type prop = a: Type0{a `subtype_of` unit} (**** The PURE effect *) (** The type of pure preconditions *) let pure_pre = Type0 (** Pure postconditions, predicates on [a], on which the precondition [pre] is also valid. This provides a way for postcondition formula to be typed in a context where they can assume the validity of the precondition. This is discussed extensively in Issue #57 *) let pure_post' (a pre: Type) = _: a{pre} -> GTot Type0 let pure_post (a: Type) = pure_post' a True (** A pure weakest precondition transforms postconditions on [a]-typed results to pure preconditions We require the weakest preconditions to satisfy the monotonicity property over the postconditions To enforce it, we first define a vanilla wp type, and then refine it with the monotonicity condition *) let pure_wp' (a: Type) = pure_post a -> GTot pure_pre (** The monotonicity predicate is marked opaque_to_smt, meaning that its definition is hidden from the SMT solver, and if required, will need to be explicitly revealed This has the advantage that clients that do not need to work with it directly, don't have the (quantified) definition in their solver context *) let pure_wp_monotonic0 (a:Type) (wp:pure_wp' a) = forall (p q:pure_post a). (forall (x:a). p x ==> q x) ==> (wp p ==> wp q) [@@ "opaque_to_smt"] let pure_wp_monotonic = pure_wp_monotonic0 let pure_wp (a: Type) = wp:pure_wp' a{pure_wp_monotonic a wp} (** This predicate is an internal detail, used to optimize the encoding of some quantifiers to SMT by omitting their typing guards. This is safe to use only when the quantifier serves to introduce a local macro---use with caution. *) assume type guard_free : Type0 -> Type0 (** The return combinator for the PURE effect requires proving the postcondition only on [x] Clients should not use it directly, instead use FStar.Pervasives.pure_return *) unfold let pure_return0 (a: Type) (x: a) : pure_wp a = fun (p: pure_post a) -> forall (return_val: a). return_val == x ==> p return_val (** Sequential composition for the PURE effect Clients should not use it directly, instead use FStar.Pervasives.pure_bind_wp *) unfold let pure_bind_wp0 (a b: Type) (wp1: pure_wp a) (wp2: (a -> GTot (pure_wp b))) : pure_wp b = fun (p: pure_post b) -> wp1 (fun (bind_result_1: a) -> wp2 bind_result_1 p) (** Conditional composition for the PURE effect The combinator is optimized to make use of how the typechecker generates VC for conditionals. The more intuitive form of the combinator would have been: [(p ==> wp_then post) /\ (~p ==> wp_else post)] However, the way the typechecker constructs the VC, [wp_then] is already weakened with [p]. Hence, here we only weaken [wp_else] Clients should not use it directly, instead use FStar.Pervasives.pure_if_then_else *) unfold let pure_if_then_else0 (a p: Type) (wp_then wp_else: pure_wp a) : pure_wp a = fun (post: pure_post a) -> wp_then post /\ (~p ==> wp_else post) (** Conditional composition for the PURE effect, while trying to avoid duplicating the postcondition by giving it a local name [k]. Note the use of [guard_free] here: [k] is just meant to be a macro for [post]. Clients should not use it directly, instead use FStar.Pervasives.pure_ite_wp *) unfold let pure_ite_wp0 (a: Type) (wp: pure_wp a) : pure_wp a = fun (post: pure_post a) -> forall (k: pure_post a). (forall (x: a). {:pattern (guard_free (k x))} post x ==> k x) ==> wp k (** Subsumption for the PURE effect *) unfold let pure_stronger (a: Type) (wp1 wp2: pure_wp a) = forall (p: pure_post a). wp1 p ==> wp2 p (** Closing a PURE WP under a binder for [b] Clients should not use it directly, instead use FStar.Pervasives.pure_close_wp *) unfold let pure_close_wp0 (a b: Type) (wp: (b -> GTot (pure_wp a))) : pure_wp a = fun (p: pure_post a) -> forall (b: b). wp b p (** Trivial WP for PURE: Prove the WP with the trivial postcondition *) unfold let pure_trivial (a: Type) (wp: pure_wp a) = wp (fun (trivial_result: a) -> True) (** Introduces the PURE effect. The definition of the PURE effect is fixed. NO USER SHOULD EVER CHANGE THIS. *) total new_effect { PURE : a: Type -> wp: pure_wp a -> Effect with return_wp = pure_return0 ; bind_wp = pure_bind_wp0 ; if_then_else = pure_if_then_else0 ; ite_wp = pure_ite_wp0 ; stronger = pure_stronger ; close_wp = pure_close_wp0 ; trivial = pure_trivial } (** [Pure] is a Hoare-style counterpart of [PURE] Note the type of post, which allows to assume the precondition for the well-formedness of the postcondition. c.f. #57 *) effect Pure (a: Type) (pre: pure_pre) (post: pure_post' a pre) = PURE a (fun (p: pure_post a) -> pre /\ (forall (pure_result: a). post pure_result ==> p pure_result)) (** [Admit] is an effect abbreviation for a computation that disregards the verification condition of its continuation *) effect Admit (a: Type) = PURE a (fun (p: pure_post a) -> True) (** The primitive effect [Tot] is definitionally equal to an instance of [PURE] *) (** Clients should not use it directly, instead use FStar.Pervasives.pure_null_wp *) unfold let pure_null_wp0 (a: Type) : pure_wp a = fun (p: pure_post a) -> forall (any_result: a). p any_result (** [Tot]: From here on, we have [Tot] as a defined symbol in F*. *) effect Tot (a: Type) = PURE a (pure_null_wp0 a) (** Clients should not use it directly, instead use FStar.Pervasives.pure_assert_wp *) [@@ "opaque_to_smt"] unfold let pure_assert_wp0 (p: Type) : pure_wp unit = fun (post: pure_post unit) -> p /\ post () (** Clients should not use it directly, instead use FStar.Pervasives.pure_assume_wp *) [@@ "opaque_to_smt"] unfold let pure_assume_wp0 (p: Type) : pure_wp unit = fun (post: pure_post unit) -> p ==> post () (**** The [GHOST] effect *) (** [GHOST] is logically equivalent to [PURE], but distinguished from it nominally so that specific, computationally irrelevant operations, are provided only in [GHOST] and are erased during extraction *) total new_effect GHOST = PURE unfold let purewp_id (a: Type) (wp: pure_wp a) = wp (** [PURE] computations can be lifted to the [GHOST] effect (but not vice versa) using just the identity lifting on pure wps *) sub_effect PURE ~> GHOST { lift_wp = purewp_id } (** [Ghost] is a the Hoare-style counterpart of [GHOST] *) effect Ghost (a: Type) (pre: Type) (post: pure_post' a pre) = GHOST a (fun (p: pure_post a) -> pre /\ (forall (ghost_result: a). post ghost_result ==> p ghost_result) ) (** As with [Tot], the primitive effect [GTot] is definitionally equal to an instance of GHOST *) effect GTot (a: Type) = GHOST a (pure_null_wp0 a) (***** End trusted primitives *****) (** This point onward, F* fully verifies all the definitions *) (** [===] heterogeneous equality *) let ( === ) (#a #b: Type) (x: a) (y: b) : logical = a == b /\ x == y (** Dependent pairs [dtuple2] in concrete syntax is [x:a & b x]. Its values can be constructed with the concrete syntax [(| x, y |)] *) unopteq type dtuple2 (a: Type) (b: (a -> GTot Type)) = | Mkdtuple2 : _1: a -> _2: b _1 -> dtuple2 a b (** Squashed existential quantification, or dependent sums, are written [exists (x:a). p x] : specialized to Type0 *) [@@ "tac_opaque"; smt_theory_symbol] type l_Exists (#a: Type) (p: (a -> GTot Type0)) : logical = squash (x: a & p x) (** Primitive type of mathematical integers, mapped to zarith in OCaml extraction and to the SMT sort of integers *) assume new type int : eqtype (**** Basic operators on booleans and integers *) (** [&&] boolean conjunction *) [@@ smt_theory_symbol] assume val op_AmpAmp: bool -> bool -> Tot bool (** [||] boolean disjunction *) [@@ smt_theory_symbol] assume val op_BarBar: bool -> bool -> Tot bool (** [not] boolean negation *) [@@ smt_theory_symbol] assume val op_Negation: bool -> Tot bool (** Integer multiplication, no special symbol. See FStar.Mul *) [@@ smt_theory_symbol] assume val op_Multiply: int -> int -> Tot int (** [-] integer subtraction *) [@@ smt_theory_symbol] assume val op_Subtraction: int -> int -> Tot int (** [+] integer addition *) [@@ smt_theory_symbol] assume val op_Addition: int -> int -> Tot int (** [-] prefix unary integer negation *) [@@ smt_theory_symbol] assume val op_Minus: int -> Tot int (** [<=] integer comparison *) [@@ smt_theory_symbol] assume val op_LessThanOrEqual: int -> int -> Tot bool (** [>] integer comparison *) [@@ smt_theory_symbol] assume val op_GreaterThan: int -> int -> Tot bool (** [>=] integer comparison *) [@@ smt_theory_symbol] assume val op_GreaterThanOrEqual: int -> int -> Tot bool (** [<] integer comparison *) [@@ smt_theory_symbol] assume val op_LessThan: int -> int -> Tot bool (** [=] decidable equality on [eqtype] *) [@@ smt_theory_symbol] assume val op_Equality: #a: eqtype -> a -> a -> Tot bool (** [<>] decidable dis-equality on [eqtype] *) [@@ smt_theory_symbol] assume val op_disEquality: #a: eqtype -> a -> a -> Tot bool (** The extensible open inductive type of exceptions *) assume new type exn : Type0 (** [array]: TODO: should be removed. See FStar.Seq, LowStar.Buffer, etc. *) assume new type array : Type -> Type0 (** String concatenation and its abbreviation as [^]. TODO, both should be removed in favor of what is present in FStar.String *) assume val strcat: string -> string -> Tot string inline_for_extraction unfold let op_Hat s1 s2 = strcat s1 s2 (** The inductive type of polymorphic lists *) type list (a: Type) = | Nil : list a | Cons : hd: a -> tl: list a -> list a (** The [M] marker is interpreted by the Dijkstra Monads for Free construction. It has a "double meaning", either as an alias for reasoning about the direct definitions, or as a marker for places where a CPS transformation should happen. *) effect M (a: Type) = Tot a (attributes cps) (** Returning a value into the [M] effect *) let returnM (a: Type) (x: a) : M a = x (** [as_requires] turns a WP into a precondition, by applying it to a trivial postcondition *)
{ "checked_file": "/", "dependencies": [], "interface_file": false, "source_file": "prims.fst" }
[ { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": 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
wp: Prims.pure_wp a -> Prims.pure_pre
Prims.Tot
[ "total" ]
[]
[ "Prims.pure_wp", "Prims.l_True", "Prims.pure_pre" ]
[]
false
false
false
true
false
let as_requires (#a: Type) (wp: pure_wp a) : pure_pre =
wp (fun x -> True)
false
prims.fst
Prims.returnM
val returnM (a: Type) (x: a) : M a
val returnM (a: Type) (x: a) : M a
let returnM (a: Type) (x: a) : M a = x
{ "file_name": "ulib/prims.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 38, "end_line": 604, "start_col": 0, "start_line": 604 }
(* Copyright 2008-2020 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 Prims /// This module is implicitly opened in the scope of all other modules. /// /// It provides the very basic primitives on which F* is /// built, including the definition of total functions, the basic /// logical connectives, the PURE and GHOST effects and the like. /// /// While some of the primitives have logical significance, others are /// define various conveniences in the language, e.g., type of /// attributes. (***** Begin trusted primitives *****) (** Primitives up to the definition of the GTot effect are trusted Beyond that all definitions are fully verified *) (** Type of attributes *) assume new type attribute : Type0 (** An attribute indicating that some definition must be processed by the Dijkstra monads for free construction *) assume val cps:attribute (** A predicate to express when a type supports decidable equality The type-checker emits axioms for [hasEq] for each inductive type *) assume type hasEq : Type -> GTot Type0 (** A convenient abbreviation, [eqtype] is the type of types in universe 0 which support decidable equality *) type eqtype = a: Type0{hasEq a} (** [bool] is a two element type with elements [true] and [false]. We assume it is primitive, for convenient interop with other languages, although it could easily be defined as an inductive type with two cases, [BTrue | BFalse] *) assume new type bool : eqtype (** [empty] is the empty inductive type. The type with no inhabitants represents logical falsehood. Note, [empty] is seldom used directly in F*. We instead use its "squashed" variant, [False], see below. *) type empty = (** [trivial] is the singleton inductive type---it is trivially inhabited. Like [empty], [trivial] is seldom used. We instead use its "squashed" variants, [True] *) type trivial = | T (** [unit]: another singleton type, with its only inhabitant written [()] we assume it is primitive, for convenient interop with other languages *) assume new type unit : eqtype (** [squash p] is a central type in F*---[squash p] is the proof irrelevant analog of [p] and is represented as a unit refinement. Squashed proofs are typically discharged using an SMT solver, without any proof terms explicitly reconstructed. As such, one way to think of [squash p] is as the type of properties proven using classical axioms without building proof terms. Note, [squash p] is just a unit refinement, it resides in universe 0, lowering the universe of [p]. From this perspective, one may also see [squash] as a coercion down to universe 0. The type is marked [tac_opaque] to indicate to Meta-F* that instances of [squash] should not be unfolded when evaluating tactics (since many optimizations in F*'s SMT encoding rely specifically on occurrences of [squash]. See FStar.Squash for various ways of manipulating squashed types. *) [@@ "tac_opaque"] type squash (p: Type) : Type0 = x: unit{p} (** [auto_squash] is equivalent to [squash]. However, F* will automatically insert `auto_squash` when simplifying terms, converting terms of the form `p /\ True` to `auto_squash p`. We distinguish these automatically inserted squashes from explicit, user-written squashes. A user should not have to manipulate [auto_squash] at all, except in rare circumstances when writing tactics to process proofs that have already been partially simplified by F*'s simplifier. *) let auto_squash (p: Type) = squash p (** The [logical] type is transitionary. It is just an abbreviation for [Type0], but is used to classify uses of the basic squashed logical connectives that follow. Some day, we plan to remove the [logical] type, replacing it with [prop] (also defined below). The type is marked [private] to intentionally prevent user code from referencing this type, hopefully easing the removal of [logical] in the future. *) private type logical = Type0 (** An attribute indicating that a symbol is an smt theory symbol and hence may not be used in smt patterns. The typechecker warns if such symbols are used in patterns *) assume val smt_theory_symbol:attribute (** [l_True] has a special bit of syntactic sugar. It is written just as "True" and rendered in the ide as [True]. It is a squashed version of constructive truth, [trivial]. *) [@@ "tac_opaque"; smt_theory_symbol] let l_True:logical = squash trivial (** [l_False] has a special bit of syntactic sugar. It is written just as "False" and rendered in the ide as [Falsee]. It is a squashed version of constructive falsehood, the empty type. *) [@@ "tac_opaque"; smt_theory_symbol] let l_False:logical = squash empty (** The type of provable equalities, defined as the usual inductive type with a single constructor for reflexivity. As with the other connectives, we often work instead with the squashed version of equality, below. *) type equals (#a: Type) (x: a) : a -> Type = | Refl : equals x x (** [eq2] is the squashed version of [equals]. It's a proof irrelevant, homogeneous equality in Type#0 and is written with an infix binary [==]. TODO: instead of hard-wiring the == syntax, we should just rename eq2 to op_Equals_Equals *) [@@ "tac_opaque"; smt_theory_symbol] type eq2 (#a: Type) (x: a) (y: a) : logical = squash (equals x y) (** bool-to-type coercion: This is often automatically inserted type, when using a boolean in context expecting a type. But, occasionally, one may have to write [b2t] explicitly *) type b2t (b: bool) : logical = (b == true) (** constructive conjunction *) type pair (p: Type) (q: Type) = | Pair : _1:p -> _2:q -> pair p q (** squashed conjunction, specialized to [Type0], written with an infix binary [/\] *) [@@ "tac_opaque"; smt_theory_symbol] type l_and (p: logical) (q: logical) : logical = squash (pair p q) (** constructive disjunction *) type sum (p: Type) (q: Type) = | Left : v:p -> sum p q | Right : v:q -> sum p q (** squashed disjunction, specialized to [Type0], written with an infix binary [\/] *) [@@ "tac_opaque"; smt_theory_symbol] type l_or (p: logical) (q: logical) : logical = squash (sum p q) (** squashed (non-dependent) implication, specialized to [Type0], written with an infix binary [==>]. Note, [==>] binds weaker than [/\] and [\/] *) [@@ "tac_opaque"; smt_theory_symbol] type l_imp (p: logical) (q: logical) : logical = squash (p -> GTot q) (* ^^^ NB: The GTot effect is primitive; *) (* elaborated using GHOST a few lines below *) (** squashed double implication, infix binary [<==>] *) [@@ smt_theory_symbol] type l_iff (p: logical) (q: logical) : logical = (p ==> q) /\ (q ==> p) (** squashed negation, prefix unary [~] *) [@@ smt_theory_symbol] type l_not (p: logical) : logical = l_imp p False (** l_ITE is a weak form of if-then-else at the level of logical formulae. It's not much used. TODO: Can we remove it *) unfold type l_ITE (p: logical) (q: logical) (r: logical) : logical = (p ==> q) /\ (~p ==> r) (** One of the main axioms provided by prims is [precedes], a built-in well-founded partial order over all terms. It's typically written with an infix binary [<<]. The [<<] order includes: * The [<] ordering on natural numbers * The subterm ordering on inductive types * [f x << D f] for data constructors D of an inductive t whose arguments include a ghost or total function returning a t *) assume type precedes : #a: Type -> #b: Type -> a -> b -> Type0 (** The type of primitive strings of characters; See FStar.String *) assume new type string : eqtype (** This attribute can be added to the declaration or definition of any top-level symbol. It causes F* to report a warning on any use of that symbol, printing the [msg] argument. This is used, for instance to: - tag every escape hatch, e.g., [assume], [admit], etc Reports for uses of symbols tagged with this attribute are controlled using the `--report_assumes` option and warning number 334. See tests/micro-benchmarks/WarnOnUse.fst *) assume val warn_on_use (msg: string) : Tot unit (** The [deprecated "s"] attribute: "s" is an alternative function that should be printed in the warning it can be omitted if the use case has no such function *) assume val deprecated (s: string) : Tot unit (** Within the SMT encoding, we have a relation [(HasType e t)] asserting that (the encoding of) [e] has a type corresponding to (the encoding of) [t]. It is sometimes convenient, e.g., when writing triggers for quantifiers, to have access to this relation at the source level. The [has_type] predicate below reflects the SMT encodings [HasType] relation. We also use it to define the type [prop] or proof irrelevant propositions, below. Note, unless you have a really good reason, you probably don't want to use this [has_type] predicate. F*'s type theory certainly does not internalize its own typing judgment *) [@@deprecated "'has_type' is intended for internal use and debugging purposes only; \ do not rely on it for your proofs"] assume type has_type : #a: Type -> a -> Type -> Type0 (** Squashed universal quantification, or dependent products, written [forall (x:a). p x], specialized to Type0 *) [@@ "tac_opaque"; smt_theory_symbol] type l_Forall (#a: Type) (p: (a -> GTot Type0)) : logical = squash (x: a -> GTot (p x)) #push-options "--warn_error -288" (** [p1 `subtype_of` p2] when every element of [p1] is also an element of [p2]. *) let subtype_of (p1 p2: Type) = forall (x: p1). has_type x p2 #pop-options (** The type of squashed types. Note, the [prop] type is a work in progress in F*. In particular, we would like in the future to more systematically use [prop] for proof-irrelevant propositions throughout the libraries. However, we still use [Type0] in many places. See https://github.com/FStarLang/FStar/issues/1048 for more details and the current status of the work. *) type prop = a: Type0{a `subtype_of` unit} (**** The PURE effect *) (** The type of pure preconditions *) let pure_pre = Type0 (** Pure postconditions, predicates on [a], on which the precondition [pre] is also valid. This provides a way for postcondition formula to be typed in a context where they can assume the validity of the precondition. This is discussed extensively in Issue #57 *) let pure_post' (a pre: Type) = _: a{pre} -> GTot Type0 let pure_post (a: Type) = pure_post' a True (** A pure weakest precondition transforms postconditions on [a]-typed results to pure preconditions We require the weakest preconditions to satisfy the monotonicity property over the postconditions To enforce it, we first define a vanilla wp type, and then refine it with the monotonicity condition *) let pure_wp' (a: Type) = pure_post a -> GTot pure_pre (** The monotonicity predicate is marked opaque_to_smt, meaning that its definition is hidden from the SMT solver, and if required, will need to be explicitly revealed This has the advantage that clients that do not need to work with it directly, don't have the (quantified) definition in their solver context *) let pure_wp_monotonic0 (a:Type) (wp:pure_wp' a) = forall (p q:pure_post a). (forall (x:a). p x ==> q x) ==> (wp p ==> wp q) [@@ "opaque_to_smt"] let pure_wp_monotonic = pure_wp_monotonic0 let pure_wp (a: Type) = wp:pure_wp' a{pure_wp_monotonic a wp} (** This predicate is an internal detail, used to optimize the encoding of some quantifiers to SMT by omitting their typing guards. This is safe to use only when the quantifier serves to introduce a local macro---use with caution. *) assume type guard_free : Type0 -> Type0 (** The return combinator for the PURE effect requires proving the postcondition only on [x] Clients should not use it directly, instead use FStar.Pervasives.pure_return *) unfold let pure_return0 (a: Type) (x: a) : pure_wp a = fun (p: pure_post a) -> forall (return_val: a). return_val == x ==> p return_val (** Sequential composition for the PURE effect Clients should not use it directly, instead use FStar.Pervasives.pure_bind_wp *) unfold let pure_bind_wp0 (a b: Type) (wp1: pure_wp a) (wp2: (a -> GTot (pure_wp b))) : pure_wp b = fun (p: pure_post b) -> wp1 (fun (bind_result_1: a) -> wp2 bind_result_1 p) (** Conditional composition for the PURE effect The combinator is optimized to make use of how the typechecker generates VC for conditionals. The more intuitive form of the combinator would have been: [(p ==> wp_then post) /\ (~p ==> wp_else post)] However, the way the typechecker constructs the VC, [wp_then] is already weakened with [p]. Hence, here we only weaken [wp_else] Clients should not use it directly, instead use FStar.Pervasives.pure_if_then_else *) unfold let pure_if_then_else0 (a p: Type) (wp_then wp_else: pure_wp a) : pure_wp a = fun (post: pure_post a) -> wp_then post /\ (~p ==> wp_else post) (** Conditional composition for the PURE effect, while trying to avoid duplicating the postcondition by giving it a local name [k]. Note the use of [guard_free] here: [k] is just meant to be a macro for [post]. Clients should not use it directly, instead use FStar.Pervasives.pure_ite_wp *) unfold let pure_ite_wp0 (a: Type) (wp: pure_wp a) : pure_wp a = fun (post: pure_post a) -> forall (k: pure_post a). (forall (x: a). {:pattern (guard_free (k x))} post x ==> k x) ==> wp k (** Subsumption for the PURE effect *) unfold let pure_stronger (a: Type) (wp1 wp2: pure_wp a) = forall (p: pure_post a). wp1 p ==> wp2 p (** Closing a PURE WP under a binder for [b] Clients should not use it directly, instead use FStar.Pervasives.pure_close_wp *) unfold let pure_close_wp0 (a b: Type) (wp: (b -> GTot (pure_wp a))) : pure_wp a = fun (p: pure_post a) -> forall (b: b). wp b p (** Trivial WP for PURE: Prove the WP with the trivial postcondition *) unfold let pure_trivial (a: Type) (wp: pure_wp a) = wp (fun (trivial_result: a) -> True) (** Introduces the PURE effect. The definition of the PURE effect is fixed. NO USER SHOULD EVER CHANGE THIS. *) total new_effect { PURE : a: Type -> wp: pure_wp a -> Effect with return_wp = pure_return0 ; bind_wp = pure_bind_wp0 ; if_then_else = pure_if_then_else0 ; ite_wp = pure_ite_wp0 ; stronger = pure_stronger ; close_wp = pure_close_wp0 ; trivial = pure_trivial } (** [Pure] is a Hoare-style counterpart of [PURE] Note the type of post, which allows to assume the precondition for the well-formedness of the postcondition. c.f. #57 *) effect Pure (a: Type) (pre: pure_pre) (post: pure_post' a pre) = PURE a (fun (p: pure_post a) -> pre /\ (forall (pure_result: a). post pure_result ==> p pure_result)) (** [Admit] is an effect abbreviation for a computation that disregards the verification condition of its continuation *) effect Admit (a: Type) = PURE a (fun (p: pure_post a) -> True) (** The primitive effect [Tot] is definitionally equal to an instance of [PURE] *) (** Clients should not use it directly, instead use FStar.Pervasives.pure_null_wp *) unfold let pure_null_wp0 (a: Type) : pure_wp a = fun (p: pure_post a) -> forall (any_result: a). p any_result (** [Tot]: From here on, we have [Tot] as a defined symbol in F*. *) effect Tot (a: Type) = PURE a (pure_null_wp0 a) (** Clients should not use it directly, instead use FStar.Pervasives.pure_assert_wp *) [@@ "opaque_to_smt"] unfold let pure_assert_wp0 (p: Type) : pure_wp unit = fun (post: pure_post unit) -> p /\ post () (** Clients should not use it directly, instead use FStar.Pervasives.pure_assume_wp *) [@@ "opaque_to_smt"] unfold let pure_assume_wp0 (p: Type) : pure_wp unit = fun (post: pure_post unit) -> p ==> post () (**** The [GHOST] effect *) (** [GHOST] is logically equivalent to [PURE], but distinguished from it nominally so that specific, computationally irrelevant operations, are provided only in [GHOST] and are erased during extraction *) total new_effect GHOST = PURE unfold let purewp_id (a: Type) (wp: pure_wp a) = wp (** [PURE] computations can be lifted to the [GHOST] effect (but not vice versa) using just the identity lifting on pure wps *) sub_effect PURE ~> GHOST { lift_wp = purewp_id } (** [Ghost] is a the Hoare-style counterpart of [GHOST] *) effect Ghost (a: Type) (pre: Type) (post: pure_post' a pre) = GHOST a (fun (p: pure_post a) -> pre /\ (forall (ghost_result: a). post ghost_result ==> p ghost_result) ) (** As with [Tot], the primitive effect [GTot] is definitionally equal to an instance of GHOST *) effect GTot (a: Type) = GHOST a (pure_null_wp0 a) (***** End trusted primitives *****) (** This point onward, F* fully verifies all the definitions *) (** [===] heterogeneous equality *) let ( === ) (#a #b: Type) (x: a) (y: b) : logical = a == b /\ x == y (** Dependent pairs [dtuple2] in concrete syntax is [x:a & b x]. Its values can be constructed with the concrete syntax [(| x, y |)] *) unopteq type dtuple2 (a: Type) (b: (a -> GTot Type)) = | Mkdtuple2 : _1: a -> _2: b _1 -> dtuple2 a b (** Squashed existential quantification, or dependent sums, are written [exists (x:a). p x] : specialized to Type0 *) [@@ "tac_opaque"; smt_theory_symbol] type l_Exists (#a: Type) (p: (a -> GTot Type0)) : logical = squash (x: a & p x) (** Primitive type of mathematical integers, mapped to zarith in OCaml extraction and to the SMT sort of integers *) assume new type int : eqtype (**** Basic operators on booleans and integers *) (** [&&] boolean conjunction *) [@@ smt_theory_symbol] assume val op_AmpAmp: bool -> bool -> Tot bool (** [||] boolean disjunction *) [@@ smt_theory_symbol] assume val op_BarBar: bool -> bool -> Tot bool (** [not] boolean negation *) [@@ smt_theory_symbol] assume val op_Negation: bool -> Tot bool (** Integer multiplication, no special symbol. See FStar.Mul *) [@@ smt_theory_symbol] assume val op_Multiply: int -> int -> Tot int (** [-] integer subtraction *) [@@ smt_theory_symbol] assume val op_Subtraction: int -> int -> Tot int (** [+] integer addition *) [@@ smt_theory_symbol] assume val op_Addition: int -> int -> Tot int (** [-] prefix unary integer negation *) [@@ smt_theory_symbol] assume val op_Minus: int -> Tot int (** [<=] integer comparison *) [@@ smt_theory_symbol] assume val op_LessThanOrEqual: int -> int -> Tot bool (** [>] integer comparison *) [@@ smt_theory_symbol] assume val op_GreaterThan: int -> int -> Tot bool (** [>=] integer comparison *) [@@ smt_theory_symbol] assume val op_GreaterThanOrEqual: int -> int -> Tot bool (** [<] integer comparison *) [@@ smt_theory_symbol] assume val op_LessThan: int -> int -> Tot bool (** [=] decidable equality on [eqtype] *) [@@ smt_theory_symbol] assume val op_Equality: #a: eqtype -> a -> a -> Tot bool (** [<>] decidable dis-equality on [eqtype] *) [@@ smt_theory_symbol] assume val op_disEquality: #a: eqtype -> a -> a -> Tot bool (** The extensible open inductive type of exceptions *) assume new type exn : Type0 (** [array]: TODO: should be removed. See FStar.Seq, LowStar.Buffer, etc. *) assume new type array : Type -> Type0 (** String concatenation and its abbreviation as [^]. TODO, both should be removed in favor of what is present in FStar.String *) assume val strcat: string -> string -> Tot string inline_for_extraction unfold let op_Hat s1 s2 = strcat s1 s2 (** The inductive type of polymorphic lists *) type list (a: Type) = | Nil : list a | Cons : hd: a -> tl: list a -> list a (** The [M] marker is interpreted by the Dijkstra Monads for Free construction. It has a "double meaning", either as an alias for reasoning about the direct definitions, or as a marker for places where a CPS transformation should happen. *) effect M (a: Type) = Tot a (attributes cps)
{ "checked_file": "/", "dependencies": [], "interface_file": false, "source_file": "prims.fst" }
[ { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
a: Type -> x: a -> Prims.M a
Prims.Tot
[ "total" ]
[]
[]
[]
false
false
false
true
false
let returnM (a: Type) (x: a) : M a =
x
false
prims.fst
Prims.__cache_version_number__
val __cache_version_number__ : Prims.int
let __cache_version_number__ = 64
{ "file_name": "ulib/prims.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 33, "end_line": 711, "start_col": 0, "start_line": 711 }
(* Copyright 2008-2020 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 Prims /// This module is implicitly opened in the scope of all other modules. /// /// It provides the very basic primitives on which F* is /// built, including the definition of total functions, the basic /// logical connectives, the PURE and GHOST effects and the like. /// /// While some of the primitives have logical significance, others are /// define various conveniences in the language, e.g., type of /// attributes. (***** Begin trusted primitives *****) (** Primitives up to the definition of the GTot effect are trusted Beyond that all definitions are fully verified *) (** Type of attributes *) assume new type attribute : Type0 (** An attribute indicating that some definition must be processed by the Dijkstra monads for free construction *) assume val cps:attribute (** A predicate to express when a type supports decidable equality The type-checker emits axioms for [hasEq] for each inductive type *) assume type hasEq : Type -> GTot Type0 (** A convenient abbreviation, [eqtype] is the type of types in universe 0 which support decidable equality *) type eqtype = a: Type0{hasEq a} (** [bool] is a two element type with elements [true] and [false]. We assume it is primitive, for convenient interop with other languages, although it could easily be defined as an inductive type with two cases, [BTrue | BFalse] *) assume new type bool : eqtype (** [empty] is the empty inductive type. The type with no inhabitants represents logical falsehood. Note, [empty] is seldom used directly in F*. We instead use its "squashed" variant, [False], see below. *) type empty = (** [trivial] is the singleton inductive type---it is trivially inhabited. Like [empty], [trivial] is seldom used. We instead use its "squashed" variants, [True] *) type trivial = | T (** [unit]: another singleton type, with its only inhabitant written [()] we assume it is primitive, for convenient interop with other languages *) assume new type unit : eqtype (** [squash p] is a central type in F*---[squash p] is the proof irrelevant analog of [p] and is represented as a unit refinement. Squashed proofs are typically discharged using an SMT solver, without any proof terms explicitly reconstructed. As such, one way to think of [squash p] is as the type of properties proven using classical axioms without building proof terms. Note, [squash p] is just a unit refinement, it resides in universe 0, lowering the universe of [p]. From this perspective, one may also see [squash] as a coercion down to universe 0. The type is marked [tac_opaque] to indicate to Meta-F* that instances of [squash] should not be unfolded when evaluating tactics (since many optimizations in F*'s SMT encoding rely specifically on occurrences of [squash]. See FStar.Squash for various ways of manipulating squashed types. *) [@@ "tac_opaque"] type squash (p: Type) : Type0 = x: unit{p} (** [auto_squash] is equivalent to [squash]. However, F* will automatically insert `auto_squash` when simplifying terms, converting terms of the form `p /\ True` to `auto_squash p`. We distinguish these automatically inserted squashes from explicit, user-written squashes. A user should not have to manipulate [auto_squash] at all, except in rare circumstances when writing tactics to process proofs that have already been partially simplified by F*'s simplifier. *) let auto_squash (p: Type) = squash p (** The [logical] type is transitionary. It is just an abbreviation for [Type0], but is used to classify uses of the basic squashed logical connectives that follow. Some day, we plan to remove the [logical] type, replacing it with [prop] (also defined below). The type is marked [private] to intentionally prevent user code from referencing this type, hopefully easing the removal of [logical] in the future. *) private type logical = Type0 (** An attribute indicating that a symbol is an smt theory symbol and hence may not be used in smt patterns. The typechecker warns if such symbols are used in patterns *) assume val smt_theory_symbol:attribute (** [l_True] has a special bit of syntactic sugar. It is written just as "True" and rendered in the ide as [True]. It is a squashed version of constructive truth, [trivial]. *) [@@ "tac_opaque"; smt_theory_symbol] let l_True:logical = squash trivial (** [l_False] has a special bit of syntactic sugar. It is written just as "False" and rendered in the ide as [Falsee]. It is a squashed version of constructive falsehood, the empty type. *) [@@ "tac_opaque"; smt_theory_symbol] let l_False:logical = squash empty (** The type of provable equalities, defined as the usual inductive type with a single constructor for reflexivity. As with the other connectives, we often work instead with the squashed version of equality, below. *) type equals (#a: Type) (x: a) : a -> Type = | Refl : equals x x (** [eq2] is the squashed version of [equals]. It's a proof irrelevant, homogeneous equality in Type#0 and is written with an infix binary [==]. TODO: instead of hard-wiring the == syntax, we should just rename eq2 to op_Equals_Equals *) [@@ "tac_opaque"; smt_theory_symbol] type eq2 (#a: Type) (x: a) (y: a) : logical = squash (equals x y) (** bool-to-type coercion: This is often automatically inserted type, when using a boolean in context expecting a type. But, occasionally, one may have to write [b2t] explicitly *) type b2t (b: bool) : logical = (b == true) (** constructive conjunction *) type pair (p: Type) (q: Type) = | Pair : _1:p -> _2:q -> pair p q (** squashed conjunction, specialized to [Type0], written with an infix binary [/\] *) [@@ "tac_opaque"; smt_theory_symbol] type l_and (p: logical) (q: logical) : logical = squash (pair p q) (** constructive disjunction *) type sum (p: Type) (q: Type) = | Left : v:p -> sum p q | Right : v:q -> sum p q (** squashed disjunction, specialized to [Type0], written with an infix binary [\/] *) [@@ "tac_opaque"; smt_theory_symbol] type l_or (p: logical) (q: logical) : logical = squash (sum p q) (** squashed (non-dependent) implication, specialized to [Type0], written with an infix binary [==>]. Note, [==>] binds weaker than [/\] and [\/] *) [@@ "tac_opaque"; smt_theory_symbol] type l_imp (p: logical) (q: logical) : logical = squash (p -> GTot q) (* ^^^ NB: The GTot effect is primitive; *) (* elaborated using GHOST a few lines below *) (** squashed double implication, infix binary [<==>] *) [@@ smt_theory_symbol] type l_iff (p: logical) (q: logical) : logical = (p ==> q) /\ (q ==> p) (** squashed negation, prefix unary [~] *) [@@ smt_theory_symbol] type l_not (p: logical) : logical = l_imp p False (** l_ITE is a weak form of if-then-else at the level of logical formulae. It's not much used. TODO: Can we remove it *) unfold type l_ITE (p: logical) (q: logical) (r: logical) : logical = (p ==> q) /\ (~p ==> r) (** One of the main axioms provided by prims is [precedes], a built-in well-founded partial order over all terms. It's typically written with an infix binary [<<]. The [<<] order includes: * The [<] ordering on natural numbers * The subterm ordering on inductive types * [f x << D f] for data constructors D of an inductive t whose arguments include a ghost or total function returning a t *) assume type precedes : #a: Type -> #b: Type -> a -> b -> Type0 (** The type of primitive strings of characters; See FStar.String *) assume new type string : eqtype (** This attribute can be added to the declaration or definition of any top-level symbol. It causes F* to report a warning on any use of that symbol, printing the [msg] argument. This is used, for instance to: - tag every escape hatch, e.g., [assume], [admit], etc Reports for uses of symbols tagged with this attribute are controlled using the `--report_assumes` option and warning number 334. See tests/micro-benchmarks/WarnOnUse.fst *) assume val warn_on_use (msg: string) : Tot unit (** The [deprecated "s"] attribute: "s" is an alternative function that should be printed in the warning it can be omitted if the use case has no such function *) assume val deprecated (s: string) : Tot unit (** Within the SMT encoding, we have a relation [(HasType e t)] asserting that (the encoding of) [e] has a type corresponding to (the encoding of) [t]. It is sometimes convenient, e.g., when writing triggers for quantifiers, to have access to this relation at the source level. The [has_type] predicate below reflects the SMT encodings [HasType] relation. We also use it to define the type [prop] or proof irrelevant propositions, below. Note, unless you have a really good reason, you probably don't want to use this [has_type] predicate. F*'s type theory certainly does not internalize its own typing judgment *) [@@deprecated "'has_type' is intended for internal use and debugging purposes only; \ do not rely on it for your proofs"] assume type has_type : #a: Type -> a -> Type -> Type0 (** Squashed universal quantification, or dependent products, written [forall (x:a). p x], specialized to Type0 *) [@@ "tac_opaque"; smt_theory_symbol] type l_Forall (#a: Type) (p: (a -> GTot Type0)) : logical = squash (x: a -> GTot (p x)) #push-options "--warn_error -288" (** [p1 `subtype_of` p2] when every element of [p1] is also an element of [p2]. *) let subtype_of (p1 p2: Type) = forall (x: p1). has_type x p2 #pop-options (** The type of squashed types. Note, the [prop] type is a work in progress in F*. In particular, we would like in the future to more systematically use [prop] for proof-irrelevant propositions throughout the libraries. However, we still use [Type0] in many places. See https://github.com/FStarLang/FStar/issues/1048 for more details and the current status of the work. *) type prop = a: Type0{a `subtype_of` unit} (**** The PURE effect *) (** The type of pure preconditions *) let pure_pre = Type0 (** Pure postconditions, predicates on [a], on which the precondition [pre] is also valid. This provides a way for postcondition formula to be typed in a context where they can assume the validity of the precondition. This is discussed extensively in Issue #57 *) let pure_post' (a pre: Type) = _: a{pre} -> GTot Type0 let pure_post (a: Type) = pure_post' a True (** A pure weakest precondition transforms postconditions on [a]-typed results to pure preconditions We require the weakest preconditions to satisfy the monotonicity property over the postconditions To enforce it, we first define a vanilla wp type, and then refine it with the monotonicity condition *) let pure_wp' (a: Type) = pure_post a -> GTot pure_pre (** The monotonicity predicate is marked opaque_to_smt, meaning that its definition is hidden from the SMT solver, and if required, will need to be explicitly revealed This has the advantage that clients that do not need to work with it directly, don't have the (quantified) definition in their solver context *) let pure_wp_monotonic0 (a:Type) (wp:pure_wp' a) = forall (p q:pure_post a). (forall (x:a). p x ==> q x) ==> (wp p ==> wp q) [@@ "opaque_to_smt"] let pure_wp_monotonic = pure_wp_monotonic0 let pure_wp (a: Type) = wp:pure_wp' a{pure_wp_monotonic a wp} (** This predicate is an internal detail, used to optimize the encoding of some quantifiers to SMT by omitting their typing guards. This is safe to use only when the quantifier serves to introduce a local macro---use with caution. *) assume type guard_free : Type0 -> Type0 (** The return combinator for the PURE effect requires proving the postcondition only on [x] Clients should not use it directly, instead use FStar.Pervasives.pure_return *) unfold let pure_return0 (a: Type) (x: a) : pure_wp a = fun (p: pure_post a) -> forall (return_val: a). return_val == x ==> p return_val (** Sequential composition for the PURE effect Clients should not use it directly, instead use FStar.Pervasives.pure_bind_wp *) unfold let pure_bind_wp0 (a b: Type) (wp1: pure_wp a) (wp2: (a -> GTot (pure_wp b))) : pure_wp b = fun (p: pure_post b) -> wp1 (fun (bind_result_1: a) -> wp2 bind_result_1 p) (** Conditional composition for the PURE effect The combinator is optimized to make use of how the typechecker generates VC for conditionals. The more intuitive form of the combinator would have been: [(p ==> wp_then post) /\ (~p ==> wp_else post)] However, the way the typechecker constructs the VC, [wp_then] is already weakened with [p]. Hence, here we only weaken [wp_else] Clients should not use it directly, instead use FStar.Pervasives.pure_if_then_else *) unfold let pure_if_then_else0 (a p: Type) (wp_then wp_else: pure_wp a) : pure_wp a = fun (post: pure_post a) -> wp_then post /\ (~p ==> wp_else post) (** Conditional composition for the PURE effect, while trying to avoid duplicating the postcondition by giving it a local name [k]. Note the use of [guard_free] here: [k] is just meant to be a macro for [post]. Clients should not use it directly, instead use FStar.Pervasives.pure_ite_wp *) unfold let pure_ite_wp0 (a: Type) (wp: pure_wp a) : pure_wp a = fun (post: pure_post a) -> forall (k: pure_post a). (forall (x: a). {:pattern (guard_free (k x))} post x ==> k x) ==> wp k (** Subsumption for the PURE effect *) unfold let pure_stronger (a: Type) (wp1 wp2: pure_wp a) = forall (p: pure_post a). wp1 p ==> wp2 p (** Closing a PURE WP under a binder for [b] Clients should not use it directly, instead use FStar.Pervasives.pure_close_wp *) unfold let pure_close_wp0 (a b: Type) (wp: (b -> GTot (pure_wp a))) : pure_wp a = fun (p: pure_post a) -> forall (b: b). wp b p (** Trivial WP for PURE: Prove the WP with the trivial postcondition *) unfold let pure_trivial (a: Type) (wp: pure_wp a) = wp (fun (trivial_result: a) -> True) (** Introduces the PURE effect. The definition of the PURE effect is fixed. NO USER SHOULD EVER CHANGE THIS. *) total new_effect { PURE : a: Type -> wp: pure_wp a -> Effect with return_wp = pure_return0 ; bind_wp = pure_bind_wp0 ; if_then_else = pure_if_then_else0 ; ite_wp = pure_ite_wp0 ; stronger = pure_stronger ; close_wp = pure_close_wp0 ; trivial = pure_trivial } (** [Pure] is a Hoare-style counterpart of [PURE] Note the type of post, which allows to assume the precondition for the well-formedness of the postcondition. c.f. #57 *) effect Pure (a: Type) (pre: pure_pre) (post: pure_post' a pre) = PURE a (fun (p: pure_post a) -> pre /\ (forall (pure_result: a). post pure_result ==> p pure_result)) (** [Admit] is an effect abbreviation for a computation that disregards the verification condition of its continuation *) effect Admit (a: Type) = PURE a (fun (p: pure_post a) -> True) (** The primitive effect [Tot] is definitionally equal to an instance of [PURE] *) (** Clients should not use it directly, instead use FStar.Pervasives.pure_null_wp *) unfold let pure_null_wp0 (a: Type) : pure_wp a = fun (p: pure_post a) -> forall (any_result: a). p any_result (** [Tot]: From here on, we have [Tot] as a defined symbol in F*. *) effect Tot (a: Type) = PURE a (pure_null_wp0 a) (** Clients should not use it directly, instead use FStar.Pervasives.pure_assert_wp *) [@@ "opaque_to_smt"] unfold let pure_assert_wp0 (p: Type) : pure_wp unit = fun (post: pure_post unit) -> p /\ post () (** Clients should not use it directly, instead use FStar.Pervasives.pure_assume_wp *) [@@ "opaque_to_smt"] unfold let pure_assume_wp0 (p: Type) : pure_wp unit = fun (post: pure_post unit) -> p ==> post () (**** The [GHOST] effect *) (** [GHOST] is logically equivalent to [PURE], but distinguished from it nominally so that specific, computationally irrelevant operations, are provided only in [GHOST] and are erased during extraction *) total new_effect GHOST = PURE unfold let purewp_id (a: Type) (wp: pure_wp a) = wp (** [PURE] computations can be lifted to the [GHOST] effect (but not vice versa) using just the identity lifting on pure wps *) sub_effect PURE ~> GHOST { lift_wp = purewp_id } (** [Ghost] is a the Hoare-style counterpart of [GHOST] *) effect Ghost (a: Type) (pre: Type) (post: pure_post' a pre) = GHOST a (fun (p: pure_post a) -> pre /\ (forall (ghost_result: a). post ghost_result ==> p ghost_result) ) (** As with [Tot], the primitive effect [GTot] is definitionally equal to an instance of GHOST *) effect GTot (a: Type) = GHOST a (pure_null_wp0 a) (***** End trusted primitives *****) (** This point onward, F* fully verifies all the definitions *) (** [===] heterogeneous equality *) let ( === ) (#a #b: Type) (x: a) (y: b) : logical = a == b /\ x == y (** Dependent pairs [dtuple2] in concrete syntax is [x:a & b x]. Its values can be constructed with the concrete syntax [(| x, y |)] *) unopteq type dtuple2 (a: Type) (b: (a -> GTot Type)) = | Mkdtuple2 : _1: a -> _2: b _1 -> dtuple2 a b (** Squashed existential quantification, or dependent sums, are written [exists (x:a). p x] : specialized to Type0 *) [@@ "tac_opaque"; smt_theory_symbol] type l_Exists (#a: Type) (p: (a -> GTot Type0)) : logical = squash (x: a & p x) (** Primitive type of mathematical integers, mapped to zarith in OCaml extraction and to the SMT sort of integers *) assume new type int : eqtype (**** Basic operators on booleans and integers *) (** [&&] boolean conjunction *) [@@ smt_theory_symbol] assume val op_AmpAmp: bool -> bool -> Tot bool (** [||] boolean disjunction *) [@@ smt_theory_symbol] assume val op_BarBar: bool -> bool -> Tot bool (** [not] boolean negation *) [@@ smt_theory_symbol] assume val op_Negation: bool -> Tot bool (** Integer multiplication, no special symbol. See FStar.Mul *) [@@ smt_theory_symbol] assume val op_Multiply: int -> int -> Tot int (** [-] integer subtraction *) [@@ smt_theory_symbol] assume val op_Subtraction: int -> int -> Tot int (** [+] integer addition *) [@@ smt_theory_symbol] assume val op_Addition: int -> int -> Tot int (** [-] prefix unary integer negation *) [@@ smt_theory_symbol] assume val op_Minus: int -> Tot int (** [<=] integer comparison *) [@@ smt_theory_symbol] assume val op_LessThanOrEqual: int -> int -> Tot bool (** [>] integer comparison *) [@@ smt_theory_symbol] assume val op_GreaterThan: int -> int -> Tot bool (** [>=] integer comparison *) [@@ smt_theory_symbol] assume val op_GreaterThanOrEqual: int -> int -> Tot bool (** [<] integer comparison *) [@@ smt_theory_symbol] assume val op_LessThan: int -> int -> Tot bool (** [=] decidable equality on [eqtype] *) [@@ smt_theory_symbol] assume val op_Equality: #a: eqtype -> a -> a -> Tot bool (** [<>] decidable dis-equality on [eqtype] *) [@@ smt_theory_symbol] assume val op_disEquality: #a: eqtype -> a -> a -> Tot bool (** The extensible open inductive type of exceptions *) assume new type exn : Type0 (** [array]: TODO: should be removed. See FStar.Seq, LowStar.Buffer, etc. *) assume new type array : Type -> Type0 (** String concatenation and its abbreviation as [^]. TODO, both should be removed in favor of what is present in FStar.String *) assume val strcat: string -> string -> Tot string inline_for_extraction unfold let op_Hat s1 s2 = strcat s1 s2 (** The inductive type of polymorphic lists *) type list (a: Type) = | Nil : list a | Cons : hd: a -> tl: list a -> list a (** The [M] marker is interpreted by the Dijkstra Monads for Free construction. It has a "double meaning", either as an alias for reasoning about the direct definitions, or as a marker for places where a CPS transformation should happen. *) effect M (a: Type) = Tot a (attributes cps) (** Returning a value into the [M] effect *) let returnM (a: Type) (x: a) : M a = x (** [as_requires] turns a WP into a precondition, by applying it to a trivial postcondition *) unfold let as_requires (#a: Type) (wp: pure_wp a) : pure_pre = wp (fun x -> True) (** [as_ensures] turns a WP into a postcondition, relying on a kind of double negation translation. *) unfold let as_ensures (#a: Type) (wp: pure_wp a) : pure_post a = fun (x:a) -> ~(wp (fun y -> (y =!= x))) (** The keyword term-level keyword [assume] is desugared to [_assume]. It explicitly provides an escape hatch to assume a given property [p]. *) [@@ warn_on_use "Uses an axiom"] assume val _assume (p: Type) : Pure unit (requires (True)) (ensures (fun x -> p)) (** [admit] is another escape hatch: It discards the continuation and returns a value of any type *) [@@ warn_on_use "Uses an axiom"] assume val admit: #a: Type -> unit -> Admit a (** [magic] is another escape hatch: It retains the continuation but returns a value of any type *) [@@ warn_on_use "Uses an axiom"] assume val magic: #a: Type -> unit -> Tot a (** [unsafe_coerce] is another escape hatch: It coerces an [a] to a [b]. *) [@@ warn_on_use "Uses an axiom"] irreducible let unsafe_coerce (#a #b: Type) (x: a) : b = admit (); x (** [admitP]: TODO: Unused ... remove? *) [@@ warn_on_use "Uses an axiom"] assume val admitP (p: Type) : Pure unit True (fun x -> p) (** The keyword term-level keyword [assert] is desugared to [_assert]. It force a proof of a property [p], then assuming [p] for the continuation. *) val _assert (p: Type) : Pure unit (requires p) (ensures (fun x -> p)) let _assert p = () (** Logically equivalent to assert; TODO remove? *) val cut (p: Type) : Pure unit (requires p) (fun x -> p) let cut p = () (** The type of non-negative integers *) type nat = i: int{i >= 0} (** The type of positive integers *) type pos = i: int{i > 0} (** The type of non-zero integers *) type nonzero = i: int{i <> 0} /// Arbitrary precision ints are compiled to zarith (big_ints) in /// OCaml and to .NET BigInteger in F#. Both the modulus and division /// operations are Euclidean and are mapped to the corresponding /// theory symbols in the SMT encoding (** Euclidean modulus *) [@@ smt_theory_symbol] assume val op_Modulus: int -> nonzero -> Tot int (** Euclidean division, written [/] *) [@@ smt_theory_symbol] assume val op_Division: int -> nonzero -> Tot int (** [pow2 x] is [2^x]: TODO: maybe move this to FStar.Int *) let rec pow2 (x: nat) : Tot pos = match x with | 0 -> 1 | _ -> 2 `op_Multiply` (pow2 (x - 1)) (** [min] computes the minimum of two [int]s *) let min x y = if x <= y then x else y (** [abs] computes the absolute value of an [int] *) let abs (x: int) : Tot int = if x >= 0 then x else - x (** A primitive printer for booleans: TODO: unnecessary, this could easily be defined *) assume val string_of_bool: bool -> Tot string (** A primitive printer for [int] *) assume val string_of_int: int -> Tot string (** THIS IS MEANT TO BE KEPT IN SYNC WITH FStar.CheckedFiles.fs Incrementing this forces all .checked files to be invalidated *)
{ "checked_file": "/", "dependencies": [], "interface_file": false, "source_file": "prims.fst" }
[ { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
Prims.int
Prims.Tot
[ "total" ]
[]
[]
[]
false
false
false
true
false
let __cache_version_number__ =
64
false
prims.fst
Prims.abs
val abs (x: int) : Tot int
val abs (x: int) : Tot int
let abs (x: int) : Tot int = if x >= 0 then x else - x
{ "file_name": "ulib/prims.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 54, "end_line": 696, "start_col": 0, "start_line": 696 }
(* Copyright 2008-2020 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 Prims /// This module is implicitly opened in the scope of all other modules. /// /// It provides the very basic primitives on which F* is /// built, including the definition of total functions, the basic /// logical connectives, the PURE and GHOST effects and the like. /// /// While some of the primitives have logical significance, others are /// define various conveniences in the language, e.g., type of /// attributes. (***** Begin trusted primitives *****) (** Primitives up to the definition of the GTot effect are trusted Beyond that all definitions are fully verified *) (** Type of attributes *) assume new type attribute : Type0 (** An attribute indicating that some definition must be processed by the Dijkstra monads for free construction *) assume val cps:attribute (** A predicate to express when a type supports decidable equality The type-checker emits axioms for [hasEq] for each inductive type *) assume type hasEq : Type -> GTot Type0 (** A convenient abbreviation, [eqtype] is the type of types in universe 0 which support decidable equality *) type eqtype = a: Type0{hasEq a} (** [bool] is a two element type with elements [true] and [false]. We assume it is primitive, for convenient interop with other languages, although it could easily be defined as an inductive type with two cases, [BTrue | BFalse] *) assume new type bool : eqtype (** [empty] is the empty inductive type. The type with no inhabitants represents logical falsehood. Note, [empty] is seldom used directly in F*. We instead use its "squashed" variant, [False], see below. *) type empty = (** [trivial] is the singleton inductive type---it is trivially inhabited. Like [empty], [trivial] is seldom used. We instead use its "squashed" variants, [True] *) type trivial = | T (** [unit]: another singleton type, with its only inhabitant written [()] we assume it is primitive, for convenient interop with other languages *) assume new type unit : eqtype (** [squash p] is a central type in F*---[squash p] is the proof irrelevant analog of [p] and is represented as a unit refinement. Squashed proofs are typically discharged using an SMT solver, without any proof terms explicitly reconstructed. As such, one way to think of [squash p] is as the type of properties proven using classical axioms without building proof terms. Note, [squash p] is just a unit refinement, it resides in universe 0, lowering the universe of [p]. From this perspective, one may also see [squash] as a coercion down to universe 0. The type is marked [tac_opaque] to indicate to Meta-F* that instances of [squash] should not be unfolded when evaluating tactics (since many optimizations in F*'s SMT encoding rely specifically on occurrences of [squash]. See FStar.Squash for various ways of manipulating squashed types. *) [@@ "tac_opaque"] type squash (p: Type) : Type0 = x: unit{p} (** [auto_squash] is equivalent to [squash]. However, F* will automatically insert `auto_squash` when simplifying terms, converting terms of the form `p /\ True` to `auto_squash p`. We distinguish these automatically inserted squashes from explicit, user-written squashes. A user should not have to manipulate [auto_squash] at all, except in rare circumstances when writing tactics to process proofs that have already been partially simplified by F*'s simplifier. *) let auto_squash (p: Type) = squash p (** The [logical] type is transitionary. It is just an abbreviation for [Type0], but is used to classify uses of the basic squashed logical connectives that follow. Some day, we plan to remove the [logical] type, replacing it with [prop] (also defined below). The type is marked [private] to intentionally prevent user code from referencing this type, hopefully easing the removal of [logical] in the future. *) private type logical = Type0 (** An attribute indicating that a symbol is an smt theory symbol and hence may not be used in smt patterns. The typechecker warns if such symbols are used in patterns *) assume val smt_theory_symbol:attribute (** [l_True] has a special bit of syntactic sugar. It is written just as "True" and rendered in the ide as [True]. It is a squashed version of constructive truth, [trivial]. *) [@@ "tac_opaque"; smt_theory_symbol] let l_True:logical = squash trivial (** [l_False] has a special bit of syntactic sugar. It is written just as "False" and rendered in the ide as [Falsee]. It is a squashed version of constructive falsehood, the empty type. *) [@@ "tac_opaque"; smt_theory_symbol] let l_False:logical = squash empty (** The type of provable equalities, defined as the usual inductive type with a single constructor for reflexivity. As with the other connectives, we often work instead with the squashed version of equality, below. *) type equals (#a: Type) (x: a) : a -> Type = | Refl : equals x x (** [eq2] is the squashed version of [equals]. It's a proof irrelevant, homogeneous equality in Type#0 and is written with an infix binary [==]. TODO: instead of hard-wiring the == syntax, we should just rename eq2 to op_Equals_Equals *) [@@ "tac_opaque"; smt_theory_symbol] type eq2 (#a: Type) (x: a) (y: a) : logical = squash (equals x y) (** bool-to-type coercion: This is often automatically inserted type, when using a boolean in context expecting a type. But, occasionally, one may have to write [b2t] explicitly *) type b2t (b: bool) : logical = (b == true) (** constructive conjunction *) type pair (p: Type) (q: Type) = | Pair : _1:p -> _2:q -> pair p q (** squashed conjunction, specialized to [Type0], written with an infix binary [/\] *) [@@ "tac_opaque"; smt_theory_symbol] type l_and (p: logical) (q: logical) : logical = squash (pair p q) (** constructive disjunction *) type sum (p: Type) (q: Type) = | Left : v:p -> sum p q | Right : v:q -> sum p q (** squashed disjunction, specialized to [Type0], written with an infix binary [\/] *) [@@ "tac_opaque"; smt_theory_symbol] type l_or (p: logical) (q: logical) : logical = squash (sum p q) (** squashed (non-dependent) implication, specialized to [Type0], written with an infix binary [==>]. Note, [==>] binds weaker than [/\] and [\/] *) [@@ "tac_opaque"; smt_theory_symbol] type l_imp (p: logical) (q: logical) : logical = squash (p -> GTot q) (* ^^^ NB: The GTot effect is primitive; *) (* elaborated using GHOST a few lines below *) (** squashed double implication, infix binary [<==>] *) [@@ smt_theory_symbol] type l_iff (p: logical) (q: logical) : logical = (p ==> q) /\ (q ==> p) (** squashed negation, prefix unary [~] *) [@@ smt_theory_symbol] type l_not (p: logical) : logical = l_imp p False (** l_ITE is a weak form of if-then-else at the level of logical formulae. It's not much used. TODO: Can we remove it *) unfold type l_ITE (p: logical) (q: logical) (r: logical) : logical = (p ==> q) /\ (~p ==> r) (** One of the main axioms provided by prims is [precedes], a built-in well-founded partial order over all terms. It's typically written with an infix binary [<<]. The [<<] order includes: * The [<] ordering on natural numbers * The subterm ordering on inductive types * [f x << D f] for data constructors D of an inductive t whose arguments include a ghost or total function returning a t *) assume type precedes : #a: Type -> #b: Type -> a -> b -> Type0 (** The type of primitive strings of characters; See FStar.String *) assume new type string : eqtype (** This attribute can be added to the declaration or definition of any top-level symbol. It causes F* to report a warning on any use of that symbol, printing the [msg] argument. This is used, for instance to: - tag every escape hatch, e.g., [assume], [admit], etc Reports for uses of symbols tagged with this attribute are controlled using the `--report_assumes` option and warning number 334. See tests/micro-benchmarks/WarnOnUse.fst *) assume val warn_on_use (msg: string) : Tot unit (** The [deprecated "s"] attribute: "s" is an alternative function that should be printed in the warning it can be omitted if the use case has no such function *) assume val deprecated (s: string) : Tot unit (** Within the SMT encoding, we have a relation [(HasType e t)] asserting that (the encoding of) [e] has a type corresponding to (the encoding of) [t]. It is sometimes convenient, e.g., when writing triggers for quantifiers, to have access to this relation at the source level. The [has_type] predicate below reflects the SMT encodings [HasType] relation. We also use it to define the type [prop] or proof irrelevant propositions, below. Note, unless you have a really good reason, you probably don't want to use this [has_type] predicate. F*'s type theory certainly does not internalize its own typing judgment *) [@@deprecated "'has_type' is intended for internal use and debugging purposes only; \ do not rely on it for your proofs"] assume type has_type : #a: Type -> a -> Type -> Type0 (** Squashed universal quantification, or dependent products, written [forall (x:a). p x], specialized to Type0 *) [@@ "tac_opaque"; smt_theory_symbol] type l_Forall (#a: Type) (p: (a -> GTot Type0)) : logical = squash (x: a -> GTot (p x)) #push-options "--warn_error -288" (** [p1 `subtype_of` p2] when every element of [p1] is also an element of [p2]. *) let subtype_of (p1 p2: Type) = forall (x: p1). has_type x p2 #pop-options (** The type of squashed types. Note, the [prop] type is a work in progress in F*. In particular, we would like in the future to more systematically use [prop] for proof-irrelevant propositions throughout the libraries. However, we still use [Type0] in many places. See https://github.com/FStarLang/FStar/issues/1048 for more details and the current status of the work. *) type prop = a: Type0{a `subtype_of` unit} (**** The PURE effect *) (** The type of pure preconditions *) let pure_pre = Type0 (** Pure postconditions, predicates on [a], on which the precondition [pre] is also valid. This provides a way for postcondition formula to be typed in a context where they can assume the validity of the precondition. This is discussed extensively in Issue #57 *) let pure_post' (a pre: Type) = _: a{pre} -> GTot Type0 let pure_post (a: Type) = pure_post' a True (** A pure weakest precondition transforms postconditions on [a]-typed results to pure preconditions We require the weakest preconditions to satisfy the monotonicity property over the postconditions To enforce it, we first define a vanilla wp type, and then refine it with the monotonicity condition *) let pure_wp' (a: Type) = pure_post a -> GTot pure_pre (** The monotonicity predicate is marked opaque_to_smt, meaning that its definition is hidden from the SMT solver, and if required, will need to be explicitly revealed This has the advantage that clients that do not need to work with it directly, don't have the (quantified) definition in their solver context *) let pure_wp_monotonic0 (a:Type) (wp:pure_wp' a) = forall (p q:pure_post a). (forall (x:a). p x ==> q x) ==> (wp p ==> wp q) [@@ "opaque_to_smt"] let pure_wp_monotonic = pure_wp_monotonic0 let pure_wp (a: Type) = wp:pure_wp' a{pure_wp_monotonic a wp} (** This predicate is an internal detail, used to optimize the encoding of some quantifiers to SMT by omitting their typing guards. This is safe to use only when the quantifier serves to introduce a local macro---use with caution. *) assume type guard_free : Type0 -> Type0 (** The return combinator for the PURE effect requires proving the postcondition only on [x] Clients should not use it directly, instead use FStar.Pervasives.pure_return *) unfold let pure_return0 (a: Type) (x: a) : pure_wp a = fun (p: pure_post a) -> forall (return_val: a). return_val == x ==> p return_val (** Sequential composition for the PURE effect Clients should not use it directly, instead use FStar.Pervasives.pure_bind_wp *) unfold let pure_bind_wp0 (a b: Type) (wp1: pure_wp a) (wp2: (a -> GTot (pure_wp b))) : pure_wp b = fun (p: pure_post b) -> wp1 (fun (bind_result_1: a) -> wp2 bind_result_1 p) (** Conditional composition for the PURE effect The combinator is optimized to make use of how the typechecker generates VC for conditionals. The more intuitive form of the combinator would have been: [(p ==> wp_then post) /\ (~p ==> wp_else post)] However, the way the typechecker constructs the VC, [wp_then] is already weakened with [p]. Hence, here we only weaken [wp_else] Clients should not use it directly, instead use FStar.Pervasives.pure_if_then_else *) unfold let pure_if_then_else0 (a p: Type) (wp_then wp_else: pure_wp a) : pure_wp a = fun (post: pure_post a) -> wp_then post /\ (~p ==> wp_else post) (** Conditional composition for the PURE effect, while trying to avoid duplicating the postcondition by giving it a local name [k]. Note the use of [guard_free] here: [k] is just meant to be a macro for [post]. Clients should not use it directly, instead use FStar.Pervasives.pure_ite_wp *) unfold let pure_ite_wp0 (a: Type) (wp: pure_wp a) : pure_wp a = fun (post: pure_post a) -> forall (k: pure_post a). (forall (x: a). {:pattern (guard_free (k x))} post x ==> k x) ==> wp k (** Subsumption for the PURE effect *) unfold let pure_stronger (a: Type) (wp1 wp2: pure_wp a) = forall (p: pure_post a). wp1 p ==> wp2 p (** Closing a PURE WP under a binder for [b] Clients should not use it directly, instead use FStar.Pervasives.pure_close_wp *) unfold let pure_close_wp0 (a b: Type) (wp: (b -> GTot (pure_wp a))) : pure_wp a = fun (p: pure_post a) -> forall (b: b). wp b p (** Trivial WP for PURE: Prove the WP with the trivial postcondition *) unfold let pure_trivial (a: Type) (wp: pure_wp a) = wp (fun (trivial_result: a) -> True) (** Introduces the PURE effect. The definition of the PURE effect is fixed. NO USER SHOULD EVER CHANGE THIS. *) total new_effect { PURE : a: Type -> wp: pure_wp a -> Effect with return_wp = pure_return0 ; bind_wp = pure_bind_wp0 ; if_then_else = pure_if_then_else0 ; ite_wp = pure_ite_wp0 ; stronger = pure_stronger ; close_wp = pure_close_wp0 ; trivial = pure_trivial } (** [Pure] is a Hoare-style counterpart of [PURE] Note the type of post, which allows to assume the precondition for the well-formedness of the postcondition. c.f. #57 *) effect Pure (a: Type) (pre: pure_pre) (post: pure_post' a pre) = PURE a (fun (p: pure_post a) -> pre /\ (forall (pure_result: a). post pure_result ==> p pure_result)) (** [Admit] is an effect abbreviation for a computation that disregards the verification condition of its continuation *) effect Admit (a: Type) = PURE a (fun (p: pure_post a) -> True) (** The primitive effect [Tot] is definitionally equal to an instance of [PURE] *) (** Clients should not use it directly, instead use FStar.Pervasives.pure_null_wp *) unfold let pure_null_wp0 (a: Type) : pure_wp a = fun (p: pure_post a) -> forall (any_result: a). p any_result (** [Tot]: From here on, we have [Tot] as a defined symbol in F*. *) effect Tot (a: Type) = PURE a (pure_null_wp0 a) (** Clients should not use it directly, instead use FStar.Pervasives.pure_assert_wp *) [@@ "opaque_to_smt"] unfold let pure_assert_wp0 (p: Type) : pure_wp unit = fun (post: pure_post unit) -> p /\ post () (** Clients should not use it directly, instead use FStar.Pervasives.pure_assume_wp *) [@@ "opaque_to_smt"] unfold let pure_assume_wp0 (p: Type) : pure_wp unit = fun (post: pure_post unit) -> p ==> post () (**** The [GHOST] effect *) (** [GHOST] is logically equivalent to [PURE], but distinguished from it nominally so that specific, computationally irrelevant operations, are provided only in [GHOST] and are erased during extraction *) total new_effect GHOST = PURE unfold let purewp_id (a: Type) (wp: pure_wp a) = wp (** [PURE] computations can be lifted to the [GHOST] effect (but not vice versa) using just the identity lifting on pure wps *) sub_effect PURE ~> GHOST { lift_wp = purewp_id } (** [Ghost] is a the Hoare-style counterpart of [GHOST] *) effect Ghost (a: Type) (pre: Type) (post: pure_post' a pre) = GHOST a (fun (p: pure_post a) -> pre /\ (forall (ghost_result: a). post ghost_result ==> p ghost_result) ) (** As with [Tot], the primitive effect [GTot] is definitionally equal to an instance of GHOST *) effect GTot (a: Type) = GHOST a (pure_null_wp0 a) (***** End trusted primitives *****) (** This point onward, F* fully verifies all the definitions *) (** [===] heterogeneous equality *) let ( === ) (#a #b: Type) (x: a) (y: b) : logical = a == b /\ x == y (** Dependent pairs [dtuple2] in concrete syntax is [x:a & b x]. Its values can be constructed with the concrete syntax [(| x, y |)] *) unopteq type dtuple2 (a: Type) (b: (a -> GTot Type)) = | Mkdtuple2 : _1: a -> _2: b _1 -> dtuple2 a b (** Squashed existential quantification, or dependent sums, are written [exists (x:a). p x] : specialized to Type0 *) [@@ "tac_opaque"; smt_theory_symbol] type l_Exists (#a: Type) (p: (a -> GTot Type0)) : logical = squash (x: a & p x) (** Primitive type of mathematical integers, mapped to zarith in OCaml extraction and to the SMT sort of integers *) assume new type int : eqtype (**** Basic operators on booleans and integers *) (** [&&] boolean conjunction *) [@@ smt_theory_symbol] assume val op_AmpAmp: bool -> bool -> Tot bool (** [||] boolean disjunction *) [@@ smt_theory_symbol] assume val op_BarBar: bool -> bool -> Tot bool (** [not] boolean negation *) [@@ smt_theory_symbol] assume val op_Negation: bool -> Tot bool (** Integer multiplication, no special symbol. See FStar.Mul *) [@@ smt_theory_symbol] assume val op_Multiply: int -> int -> Tot int (** [-] integer subtraction *) [@@ smt_theory_symbol] assume val op_Subtraction: int -> int -> Tot int (** [+] integer addition *) [@@ smt_theory_symbol] assume val op_Addition: int -> int -> Tot int (** [-] prefix unary integer negation *) [@@ smt_theory_symbol] assume val op_Minus: int -> Tot int (** [<=] integer comparison *) [@@ smt_theory_symbol] assume val op_LessThanOrEqual: int -> int -> Tot bool (** [>] integer comparison *) [@@ smt_theory_symbol] assume val op_GreaterThan: int -> int -> Tot bool (** [>=] integer comparison *) [@@ smt_theory_symbol] assume val op_GreaterThanOrEqual: int -> int -> Tot bool (** [<] integer comparison *) [@@ smt_theory_symbol] assume val op_LessThan: int -> int -> Tot bool (** [=] decidable equality on [eqtype] *) [@@ smt_theory_symbol] assume val op_Equality: #a: eqtype -> a -> a -> Tot bool (** [<>] decidable dis-equality on [eqtype] *) [@@ smt_theory_symbol] assume val op_disEquality: #a: eqtype -> a -> a -> Tot bool (** The extensible open inductive type of exceptions *) assume new type exn : Type0 (** [array]: TODO: should be removed. See FStar.Seq, LowStar.Buffer, etc. *) assume new type array : Type -> Type0 (** String concatenation and its abbreviation as [^]. TODO, both should be removed in favor of what is present in FStar.String *) assume val strcat: string -> string -> Tot string inline_for_extraction unfold let op_Hat s1 s2 = strcat s1 s2 (** The inductive type of polymorphic lists *) type list (a: Type) = | Nil : list a | Cons : hd: a -> tl: list a -> list a (** The [M] marker is interpreted by the Dijkstra Monads for Free construction. It has a "double meaning", either as an alias for reasoning about the direct definitions, or as a marker for places where a CPS transformation should happen. *) effect M (a: Type) = Tot a (attributes cps) (** Returning a value into the [M] effect *) let returnM (a: Type) (x: a) : M a = x (** [as_requires] turns a WP into a precondition, by applying it to a trivial postcondition *) unfold let as_requires (#a: Type) (wp: pure_wp a) : pure_pre = wp (fun x -> True) (** [as_ensures] turns a WP into a postcondition, relying on a kind of double negation translation. *) unfold let as_ensures (#a: Type) (wp: pure_wp a) : pure_post a = fun (x:a) -> ~(wp (fun y -> (y =!= x))) (** The keyword term-level keyword [assume] is desugared to [_assume]. It explicitly provides an escape hatch to assume a given property [p]. *) [@@ warn_on_use "Uses an axiom"] assume val _assume (p: Type) : Pure unit (requires (True)) (ensures (fun x -> p)) (** [admit] is another escape hatch: It discards the continuation and returns a value of any type *) [@@ warn_on_use "Uses an axiom"] assume val admit: #a: Type -> unit -> Admit a (** [magic] is another escape hatch: It retains the continuation but returns a value of any type *) [@@ warn_on_use "Uses an axiom"] assume val magic: #a: Type -> unit -> Tot a (** [unsafe_coerce] is another escape hatch: It coerces an [a] to a [b]. *) [@@ warn_on_use "Uses an axiom"] irreducible let unsafe_coerce (#a #b: Type) (x: a) : b = admit (); x (** [admitP]: TODO: Unused ... remove? *) [@@ warn_on_use "Uses an axiom"] assume val admitP (p: Type) : Pure unit True (fun x -> p) (** The keyword term-level keyword [assert] is desugared to [_assert]. It force a proof of a property [p], then assuming [p] for the continuation. *) val _assert (p: Type) : Pure unit (requires p) (ensures (fun x -> p)) let _assert p = () (** Logically equivalent to assert; TODO remove? *) val cut (p: Type) : Pure unit (requires p) (fun x -> p) let cut p = () (** The type of non-negative integers *) type nat = i: int{i >= 0} (** The type of positive integers *) type pos = i: int{i > 0} (** The type of non-zero integers *) type nonzero = i: int{i <> 0} /// Arbitrary precision ints are compiled to zarith (big_ints) in /// OCaml and to .NET BigInteger in F#. Both the modulus and division /// operations are Euclidean and are mapped to the corresponding /// theory symbols in the SMT encoding (** Euclidean modulus *) [@@ smt_theory_symbol] assume val op_Modulus: int -> nonzero -> Tot int (** Euclidean division, written [/] *) [@@ smt_theory_symbol] assume val op_Division: int -> nonzero -> Tot int (** [pow2 x] is [2^x]: TODO: maybe move this to FStar.Int *) let rec pow2 (x: nat) : Tot pos = match x with | 0 -> 1 | _ -> 2 `op_Multiply` (pow2 (x - 1)) (** [min] computes the minimum of two [int]s *) let min x y = if x <= y then x else y
{ "checked_file": "/", "dependencies": [], "interface_file": false, "source_file": "prims.fst" }
[ { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
x: Prims.int -> Prims.int
Prims.Tot
[ "total" ]
[]
[ "Prims.int", "Prims.op_GreaterThanOrEqual", "Prims.bool", "Prims.op_Minus" ]
[]
false
false
false
true
false
let abs (x: int) : Tot int =
if x >= 0 then x else - x
false
prims.fst
Prims.min
val min : x: Prims.int -> y: Prims.int -> Prims.int
let min x y = if x <= y then x else y
{ "file_name": "ulib/prims.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 37, "end_line": 693, "start_col": 0, "start_line": 693 }
(* Copyright 2008-2020 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 Prims /// This module is implicitly opened in the scope of all other modules. /// /// It provides the very basic primitives on which F* is /// built, including the definition of total functions, the basic /// logical connectives, the PURE and GHOST effects and the like. /// /// While some of the primitives have logical significance, others are /// define various conveniences in the language, e.g., type of /// attributes. (***** Begin trusted primitives *****) (** Primitives up to the definition of the GTot effect are trusted Beyond that all definitions are fully verified *) (** Type of attributes *) assume new type attribute : Type0 (** An attribute indicating that some definition must be processed by the Dijkstra monads for free construction *) assume val cps:attribute (** A predicate to express when a type supports decidable equality The type-checker emits axioms for [hasEq] for each inductive type *) assume type hasEq : Type -> GTot Type0 (** A convenient abbreviation, [eqtype] is the type of types in universe 0 which support decidable equality *) type eqtype = a: Type0{hasEq a} (** [bool] is a two element type with elements [true] and [false]. We assume it is primitive, for convenient interop with other languages, although it could easily be defined as an inductive type with two cases, [BTrue | BFalse] *) assume new type bool : eqtype (** [empty] is the empty inductive type. The type with no inhabitants represents logical falsehood. Note, [empty] is seldom used directly in F*. We instead use its "squashed" variant, [False], see below. *) type empty = (** [trivial] is the singleton inductive type---it is trivially inhabited. Like [empty], [trivial] is seldom used. We instead use its "squashed" variants, [True] *) type trivial = | T (** [unit]: another singleton type, with its only inhabitant written [()] we assume it is primitive, for convenient interop with other languages *) assume new type unit : eqtype (** [squash p] is a central type in F*---[squash p] is the proof irrelevant analog of [p] and is represented as a unit refinement. Squashed proofs are typically discharged using an SMT solver, without any proof terms explicitly reconstructed. As such, one way to think of [squash p] is as the type of properties proven using classical axioms without building proof terms. Note, [squash p] is just a unit refinement, it resides in universe 0, lowering the universe of [p]. From this perspective, one may also see [squash] as a coercion down to universe 0. The type is marked [tac_opaque] to indicate to Meta-F* that instances of [squash] should not be unfolded when evaluating tactics (since many optimizations in F*'s SMT encoding rely specifically on occurrences of [squash]. See FStar.Squash for various ways of manipulating squashed types. *) [@@ "tac_opaque"] type squash (p: Type) : Type0 = x: unit{p} (** [auto_squash] is equivalent to [squash]. However, F* will automatically insert `auto_squash` when simplifying terms, converting terms of the form `p /\ True` to `auto_squash p`. We distinguish these automatically inserted squashes from explicit, user-written squashes. A user should not have to manipulate [auto_squash] at all, except in rare circumstances when writing tactics to process proofs that have already been partially simplified by F*'s simplifier. *) let auto_squash (p: Type) = squash p (** The [logical] type is transitionary. It is just an abbreviation for [Type0], but is used to classify uses of the basic squashed logical connectives that follow. Some day, we plan to remove the [logical] type, replacing it with [prop] (also defined below). The type is marked [private] to intentionally prevent user code from referencing this type, hopefully easing the removal of [logical] in the future. *) private type logical = Type0 (** An attribute indicating that a symbol is an smt theory symbol and hence may not be used in smt patterns. The typechecker warns if such symbols are used in patterns *) assume val smt_theory_symbol:attribute (** [l_True] has a special bit of syntactic sugar. It is written just as "True" and rendered in the ide as [True]. It is a squashed version of constructive truth, [trivial]. *) [@@ "tac_opaque"; smt_theory_symbol] let l_True:logical = squash trivial (** [l_False] has a special bit of syntactic sugar. It is written just as "False" and rendered in the ide as [Falsee]. It is a squashed version of constructive falsehood, the empty type. *) [@@ "tac_opaque"; smt_theory_symbol] let l_False:logical = squash empty (** The type of provable equalities, defined as the usual inductive type with a single constructor for reflexivity. As with the other connectives, we often work instead with the squashed version of equality, below. *) type equals (#a: Type) (x: a) : a -> Type = | Refl : equals x x (** [eq2] is the squashed version of [equals]. It's a proof irrelevant, homogeneous equality in Type#0 and is written with an infix binary [==]. TODO: instead of hard-wiring the == syntax, we should just rename eq2 to op_Equals_Equals *) [@@ "tac_opaque"; smt_theory_symbol] type eq2 (#a: Type) (x: a) (y: a) : logical = squash (equals x y) (** bool-to-type coercion: This is often automatically inserted type, when using a boolean in context expecting a type. But, occasionally, one may have to write [b2t] explicitly *) type b2t (b: bool) : logical = (b == true) (** constructive conjunction *) type pair (p: Type) (q: Type) = | Pair : _1:p -> _2:q -> pair p q (** squashed conjunction, specialized to [Type0], written with an infix binary [/\] *) [@@ "tac_opaque"; smt_theory_symbol] type l_and (p: logical) (q: logical) : logical = squash (pair p q) (** constructive disjunction *) type sum (p: Type) (q: Type) = | Left : v:p -> sum p q | Right : v:q -> sum p q (** squashed disjunction, specialized to [Type0], written with an infix binary [\/] *) [@@ "tac_opaque"; smt_theory_symbol] type l_or (p: logical) (q: logical) : logical = squash (sum p q) (** squashed (non-dependent) implication, specialized to [Type0], written with an infix binary [==>]. Note, [==>] binds weaker than [/\] and [\/] *) [@@ "tac_opaque"; smt_theory_symbol] type l_imp (p: logical) (q: logical) : logical = squash (p -> GTot q) (* ^^^ NB: The GTot effect is primitive; *) (* elaborated using GHOST a few lines below *) (** squashed double implication, infix binary [<==>] *) [@@ smt_theory_symbol] type l_iff (p: logical) (q: logical) : logical = (p ==> q) /\ (q ==> p) (** squashed negation, prefix unary [~] *) [@@ smt_theory_symbol] type l_not (p: logical) : logical = l_imp p False (** l_ITE is a weak form of if-then-else at the level of logical formulae. It's not much used. TODO: Can we remove it *) unfold type l_ITE (p: logical) (q: logical) (r: logical) : logical = (p ==> q) /\ (~p ==> r) (** One of the main axioms provided by prims is [precedes], a built-in well-founded partial order over all terms. It's typically written with an infix binary [<<]. The [<<] order includes: * The [<] ordering on natural numbers * The subterm ordering on inductive types * [f x << D f] for data constructors D of an inductive t whose arguments include a ghost or total function returning a t *) assume type precedes : #a: Type -> #b: Type -> a -> b -> Type0 (** The type of primitive strings of characters; See FStar.String *) assume new type string : eqtype (** This attribute can be added to the declaration or definition of any top-level symbol. It causes F* to report a warning on any use of that symbol, printing the [msg] argument. This is used, for instance to: - tag every escape hatch, e.g., [assume], [admit], etc Reports for uses of symbols tagged with this attribute are controlled using the `--report_assumes` option and warning number 334. See tests/micro-benchmarks/WarnOnUse.fst *) assume val warn_on_use (msg: string) : Tot unit (** The [deprecated "s"] attribute: "s" is an alternative function that should be printed in the warning it can be omitted if the use case has no such function *) assume val deprecated (s: string) : Tot unit (** Within the SMT encoding, we have a relation [(HasType e t)] asserting that (the encoding of) [e] has a type corresponding to (the encoding of) [t]. It is sometimes convenient, e.g., when writing triggers for quantifiers, to have access to this relation at the source level. The [has_type] predicate below reflects the SMT encodings [HasType] relation. We also use it to define the type [prop] or proof irrelevant propositions, below. Note, unless you have a really good reason, you probably don't want to use this [has_type] predicate. F*'s type theory certainly does not internalize its own typing judgment *) [@@deprecated "'has_type' is intended for internal use and debugging purposes only; \ do not rely on it for your proofs"] assume type has_type : #a: Type -> a -> Type -> Type0 (** Squashed universal quantification, or dependent products, written [forall (x:a). p x], specialized to Type0 *) [@@ "tac_opaque"; smt_theory_symbol] type l_Forall (#a: Type) (p: (a -> GTot Type0)) : logical = squash (x: a -> GTot (p x)) #push-options "--warn_error -288" (** [p1 `subtype_of` p2] when every element of [p1] is also an element of [p2]. *) let subtype_of (p1 p2: Type) = forall (x: p1). has_type x p2 #pop-options (** The type of squashed types. Note, the [prop] type is a work in progress in F*. In particular, we would like in the future to more systematically use [prop] for proof-irrelevant propositions throughout the libraries. However, we still use [Type0] in many places. See https://github.com/FStarLang/FStar/issues/1048 for more details and the current status of the work. *) type prop = a: Type0{a `subtype_of` unit} (**** The PURE effect *) (** The type of pure preconditions *) let pure_pre = Type0 (** Pure postconditions, predicates on [a], on which the precondition [pre] is also valid. This provides a way for postcondition formula to be typed in a context where they can assume the validity of the precondition. This is discussed extensively in Issue #57 *) let pure_post' (a pre: Type) = _: a{pre} -> GTot Type0 let pure_post (a: Type) = pure_post' a True (** A pure weakest precondition transforms postconditions on [a]-typed results to pure preconditions We require the weakest preconditions to satisfy the monotonicity property over the postconditions To enforce it, we first define a vanilla wp type, and then refine it with the monotonicity condition *) let pure_wp' (a: Type) = pure_post a -> GTot pure_pre (** The monotonicity predicate is marked opaque_to_smt, meaning that its definition is hidden from the SMT solver, and if required, will need to be explicitly revealed This has the advantage that clients that do not need to work with it directly, don't have the (quantified) definition in their solver context *) let pure_wp_monotonic0 (a:Type) (wp:pure_wp' a) = forall (p q:pure_post a). (forall (x:a). p x ==> q x) ==> (wp p ==> wp q) [@@ "opaque_to_smt"] let pure_wp_monotonic = pure_wp_monotonic0 let pure_wp (a: Type) = wp:pure_wp' a{pure_wp_monotonic a wp} (** This predicate is an internal detail, used to optimize the encoding of some quantifiers to SMT by omitting their typing guards. This is safe to use only when the quantifier serves to introduce a local macro---use with caution. *) assume type guard_free : Type0 -> Type0 (** The return combinator for the PURE effect requires proving the postcondition only on [x] Clients should not use it directly, instead use FStar.Pervasives.pure_return *) unfold let pure_return0 (a: Type) (x: a) : pure_wp a = fun (p: pure_post a) -> forall (return_val: a). return_val == x ==> p return_val (** Sequential composition for the PURE effect Clients should not use it directly, instead use FStar.Pervasives.pure_bind_wp *) unfold let pure_bind_wp0 (a b: Type) (wp1: pure_wp a) (wp2: (a -> GTot (pure_wp b))) : pure_wp b = fun (p: pure_post b) -> wp1 (fun (bind_result_1: a) -> wp2 bind_result_1 p) (** Conditional composition for the PURE effect The combinator is optimized to make use of how the typechecker generates VC for conditionals. The more intuitive form of the combinator would have been: [(p ==> wp_then post) /\ (~p ==> wp_else post)] However, the way the typechecker constructs the VC, [wp_then] is already weakened with [p]. Hence, here we only weaken [wp_else] Clients should not use it directly, instead use FStar.Pervasives.pure_if_then_else *) unfold let pure_if_then_else0 (a p: Type) (wp_then wp_else: pure_wp a) : pure_wp a = fun (post: pure_post a) -> wp_then post /\ (~p ==> wp_else post) (** Conditional composition for the PURE effect, while trying to avoid duplicating the postcondition by giving it a local name [k]. Note the use of [guard_free] here: [k] is just meant to be a macro for [post]. Clients should not use it directly, instead use FStar.Pervasives.pure_ite_wp *) unfold let pure_ite_wp0 (a: Type) (wp: pure_wp a) : pure_wp a = fun (post: pure_post a) -> forall (k: pure_post a). (forall (x: a). {:pattern (guard_free (k x))} post x ==> k x) ==> wp k (** Subsumption for the PURE effect *) unfold let pure_stronger (a: Type) (wp1 wp2: pure_wp a) = forall (p: pure_post a). wp1 p ==> wp2 p (** Closing a PURE WP under a binder for [b] Clients should not use it directly, instead use FStar.Pervasives.pure_close_wp *) unfold let pure_close_wp0 (a b: Type) (wp: (b -> GTot (pure_wp a))) : pure_wp a = fun (p: pure_post a) -> forall (b: b). wp b p (** Trivial WP for PURE: Prove the WP with the trivial postcondition *) unfold let pure_trivial (a: Type) (wp: pure_wp a) = wp (fun (trivial_result: a) -> True) (** Introduces the PURE effect. The definition of the PURE effect is fixed. NO USER SHOULD EVER CHANGE THIS. *) total new_effect { PURE : a: Type -> wp: pure_wp a -> Effect with return_wp = pure_return0 ; bind_wp = pure_bind_wp0 ; if_then_else = pure_if_then_else0 ; ite_wp = pure_ite_wp0 ; stronger = pure_stronger ; close_wp = pure_close_wp0 ; trivial = pure_trivial } (** [Pure] is a Hoare-style counterpart of [PURE] Note the type of post, which allows to assume the precondition for the well-formedness of the postcondition. c.f. #57 *) effect Pure (a: Type) (pre: pure_pre) (post: pure_post' a pre) = PURE a (fun (p: pure_post a) -> pre /\ (forall (pure_result: a). post pure_result ==> p pure_result)) (** [Admit] is an effect abbreviation for a computation that disregards the verification condition of its continuation *) effect Admit (a: Type) = PURE a (fun (p: pure_post a) -> True) (** The primitive effect [Tot] is definitionally equal to an instance of [PURE] *) (** Clients should not use it directly, instead use FStar.Pervasives.pure_null_wp *) unfold let pure_null_wp0 (a: Type) : pure_wp a = fun (p: pure_post a) -> forall (any_result: a). p any_result (** [Tot]: From here on, we have [Tot] as a defined symbol in F*. *) effect Tot (a: Type) = PURE a (pure_null_wp0 a) (** Clients should not use it directly, instead use FStar.Pervasives.pure_assert_wp *) [@@ "opaque_to_smt"] unfold let pure_assert_wp0 (p: Type) : pure_wp unit = fun (post: pure_post unit) -> p /\ post () (** Clients should not use it directly, instead use FStar.Pervasives.pure_assume_wp *) [@@ "opaque_to_smt"] unfold let pure_assume_wp0 (p: Type) : pure_wp unit = fun (post: pure_post unit) -> p ==> post () (**** The [GHOST] effect *) (** [GHOST] is logically equivalent to [PURE], but distinguished from it nominally so that specific, computationally irrelevant operations, are provided only in [GHOST] and are erased during extraction *) total new_effect GHOST = PURE unfold let purewp_id (a: Type) (wp: pure_wp a) = wp (** [PURE] computations can be lifted to the [GHOST] effect (but not vice versa) using just the identity lifting on pure wps *) sub_effect PURE ~> GHOST { lift_wp = purewp_id } (** [Ghost] is a the Hoare-style counterpart of [GHOST] *) effect Ghost (a: Type) (pre: Type) (post: pure_post' a pre) = GHOST a (fun (p: pure_post a) -> pre /\ (forall (ghost_result: a). post ghost_result ==> p ghost_result) ) (** As with [Tot], the primitive effect [GTot] is definitionally equal to an instance of GHOST *) effect GTot (a: Type) = GHOST a (pure_null_wp0 a) (***** End trusted primitives *****) (** This point onward, F* fully verifies all the definitions *) (** [===] heterogeneous equality *) let ( === ) (#a #b: Type) (x: a) (y: b) : logical = a == b /\ x == y (** Dependent pairs [dtuple2] in concrete syntax is [x:a & b x]. Its values can be constructed with the concrete syntax [(| x, y |)] *) unopteq type dtuple2 (a: Type) (b: (a -> GTot Type)) = | Mkdtuple2 : _1: a -> _2: b _1 -> dtuple2 a b (** Squashed existential quantification, or dependent sums, are written [exists (x:a). p x] : specialized to Type0 *) [@@ "tac_opaque"; smt_theory_symbol] type l_Exists (#a: Type) (p: (a -> GTot Type0)) : logical = squash (x: a & p x) (** Primitive type of mathematical integers, mapped to zarith in OCaml extraction and to the SMT sort of integers *) assume new type int : eqtype (**** Basic operators on booleans and integers *) (** [&&] boolean conjunction *) [@@ smt_theory_symbol] assume val op_AmpAmp: bool -> bool -> Tot bool (** [||] boolean disjunction *) [@@ smt_theory_symbol] assume val op_BarBar: bool -> bool -> Tot bool (** [not] boolean negation *) [@@ smt_theory_symbol] assume val op_Negation: bool -> Tot bool (** Integer multiplication, no special symbol. See FStar.Mul *) [@@ smt_theory_symbol] assume val op_Multiply: int -> int -> Tot int (** [-] integer subtraction *) [@@ smt_theory_symbol] assume val op_Subtraction: int -> int -> Tot int (** [+] integer addition *) [@@ smt_theory_symbol] assume val op_Addition: int -> int -> Tot int (** [-] prefix unary integer negation *) [@@ smt_theory_symbol] assume val op_Minus: int -> Tot int (** [<=] integer comparison *) [@@ smt_theory_symbol] assume val op_LessThanOrEqual: int -> int -> Tot bool (** [>] integer comparison *) [@@ smt_theory_symbol] assume val op_GreaterThan: int -> int -> Tot bool (** [>=] integer comparison *) [@@ smt_theory_symbol] assume val op_GreaterThanOrEqual: int -> int -> Tot bool (** [<] integer comparison *) [@@ smt_theory_symbol] assume val op_LessThan: int -> int -> Tot bool (** [=] decidable equality on [eqtype] *) [@@ smt_theory_symbol] assume val op_Equality: #a: eqtype -> a -> a -> Tot bool (** [<>] decidable dis-equality on [eqtype] *) [@@ smt_theory_symbol] assume val op_disEquality: #a: eqtype -> a -> a -> Tot bool (** The extensible open inductive type of exceptions *) assume new type exn : Type0 (** [array]: TODO: should be removed. See FStar.Seq, LowStar.Buffer, etc. *) assume new type array : Type -> Type0 (** String concatenation and its abbreviation as [^]. TODO, both should be removed in favor of what is present in FStar.String *) assume val strcat: string -> string -> Tot string inline_for_extraction unfold let op_Hat s1 s2 = strcat s1 s2 (** The inductive type of polymorphic lists *) type list (a: Type) = | Nil : list a | Cons : hd: a -> tl: list a -> list a (** The [M] marker is interpreted by the Dijkstra Monads for Free construction. It has a "double meaning", either as an alias for reasoning about the direct definitions, or as a marker for places where a CPS transformation should happen. *) effect M (a: Type) = Tot a (attributes cps) (** Returning a value into the [M] effect *) let returnM (a: Type) (x: a) : M a = x (** [as_requires] turns a WP into a precondition, by applying it to a trivial postcondition *) unfold let as_requires (#a: Type) (wp: pure_wp a) : pure_pre = wp (fun x -> True) (** [as_ensures] turns a WP into a postcondition, relying on a kind of double negation translation. *) unfold let as_ensures (#a: Type) (wp: pure_wp a) : pure_post a = fun (x:a) -> ~(wp (fun y -> (y =!= x))) (** The keyword term-level keyword [assume] is desugared to [_assume]. It explicitly provides an escape hatch to assume a given property [p]. *) [@@ warn_on_use "Uses an axiom"] assume val _assume (p: Type) : Pure unit (requires (True)) (ensures (fun x -> p)) (** [admit] is another escape hatch: It discards the continuation and returns a value of any type *) [@@ warn_on_use "Uses an axiom"] assume val admit: #a: Type -> unit -> Admit a (** [magic] is another escape hatch: It retains the continuation but returns a value of any type *) [@@ warn_on_use "Uses an axiom"] assume val magic: #a: Type -> unit -> Tot a (** [unsafe_coerce] is another escape hatch: It coerces an [a] to a [b]. *) [@@ warn_on_use "Uses an axiom"] irreducible let unsafe_coerce (#a #b: Type) (x: a) : b = admit (); x (** [admitP]: TODO: Unused ... remove? *) [@@ warn_on_use "Uses an axiom"] assume val admitP (p: Type) : Pure unit True (fun x -> p) (** The keyword term-level keyword [assert] is desugared to [_assert]. It force a proof of a property [p], then assuming [p] for the continuation. *) val _assert (p: Type) : Pure unit (requires p) (ensures (fun x -> p)) let _assert p = () (** Logically equivalent to assert; TODO remove? *) val cut (p: Type) : Pure unit (requires p) (fun x -> p) let cut p = () (** The type of non-negative integers *) type nat = i: int{i >= 0} (** The type of positive integers *) type pos = i: int{i > 0} (** The type of non-zero integers *) type nonzero = i: int{i <> 0} /// Arbitrary precision ints are compiled to zarith (big_ints) in /// OCaml and to .NET BigInteger in F#. Both the modulus and division /// operations are Euclidean and are mapped to the corresponding /// theory symbols in the SMT encoding (** Euclidean modulus *) [@@ smt_theory_symbol] assume val op_Modulus: int -> nonzero -> Tot int (** Euclidean division, written [/] *) [@@ smt_theory_symbol] assume val op_Division: int -> nonzero -> Tot int (** [pow2 x] is [2^x]: TODO: maybe move this to FStar.Int *) let rec pow2 (x: nat) : Tot pos = match x with | 0 -> 1 | _ -> 2 `op_Multiply` (pow2 (x - 1))
{ "checked_file": "/", "dependencies": [], "interface_file": false, "source_file": "prims.fst" }
[ { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
x: Prims.int -> y: Prims.int -> Prims.int
Prims.Tot
[ "total" ]
[]
[ "Prims.int", "Prims.op_LessThanOrEqual", "Prims.bool" ]
[]
false
false
false
true
false
let min x y =
if x <= y then x else y
false
prims.fst
Prims.pow2
val pow2 (x: nat) : Tot pos
val pow2 (x: nat) : Tot pos
let rec pow2 (x: nat) : Tot pos = match x with | 0 -> 1 | _ -> 2 `op_Multiply` (pow2 (x - 1))
{ "file_name": "ulib/prims.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 39, "end_line": 690, "start_col": 0, "start_line": 687 }
(* Copyright 2008-2020 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 Prims /// This module is implicitly opened in the scope of all other modules. /// /// It provides the very basic primitives on which F* is /// built, including the definition of total functions, the basic /// logical connectives, the PURE and GHOST effects and the like. /// /// While some of the primitives have logical significance, others are /// define various conveniences in the language, e.g., type of /// attributes. (***** Begin trusted primitives *****) (** Primitives up to the definition of the GTot effect are trusted Beyond that all definitions are fully verified *) (** Type of attributes *) assume new type attribute : Type0 (** An attribute indicating that some definition must be processed by the Dijkstra monads for free construction *) assume val cps:attribute (** A predicate to express when a type supports decidable equality The type-checker emits axioms for [hasEq] for each inductive type *) assume type hasEq : Type -> GTot Type0 (** A convenient abbreviation, [eqtype] is the type of types in universe 0 which support decidable equality *) type eqtype = a: Type0{hasEq a} (** [bool] is a two element type with elements [true] and [false]. We assume it is primitive, for convenient interop with other languages, although it could easily be defined as an inductive type with two cases, [BTrue | BFalse] *) assume new type bool : eqtype (** [empty] is the empty inductive type. The type with no inhabitants represents logical falsehood. Note, [empty] is seldom used directly in F*. We instead use its "squashed" variant, [False], see below. *) type empty = (** [trivial] is the singleton inductive type---it is trivially inhabited. Like [empty], [trivial] is seldom used. We instead use its "squashed" variants, [True] *) type trivial = | T (** [unit]: another singleton type, with its only inhabitant written [()] we assume it is primitive, for convenient interop with other languages *) assume new type unit : eqtype (** [squash p] is a central type in F*---[squash p] is the proof irrelevant analog of [p] and is represented as a unit refinement. Squashed proofs are typically discharged using an SMT solver, without any proof terms explicitly reconstructed. As such, one way to think of [squash p] is as the type of properties proven using classical axioms without building proof terms. Note, [squash p] is just a unit refinement, it resides in universe 0, lowering the universe of [p]. From this perspective, one may also see [squash] as a coercion down to universe 0. The type is marked [tac_opaque] to indicate to Meta-F* that instances of [squash] should not be unfolded when evaluating tactics (since many optimizations in F*'s SMT encoding rely specifically on occurrences of [squash]. See FStar.Squash for various ways of manipulating squashed types. *) [@@ "tac_opaque"] type squash (p: Type) : Type0 = x: unit{p} (** [auto_squash] is equivalent to [squash]. However, F* will automatically insert `auto_squash` when simplifying terms, converting terms of the form `p /\ True` to `auto_squash p`. We distinguish these automatically inserted squashes from explicit, user-written squashes. A user should not have to manipulate [auto_squash] at all, except in rare circumstances when writing tactics to process proofs that have already been partially simplified by F*'s simplifier. *) let auto_squash (p: Type) = squash p (** The [logical] type is transitionary. It is just an abbreviation for [Type0], but is used to classify uses of the basic squashed logical connectives that follow. Some day, we plan to remove the [logical] type, replacing it with [prop] (also defined below). The type is marked [private] to intentionally prevent user code from referencing this type, hopefully easing the removal of [logical] in the future. *) private type logical = Type0 (** An attribute indicating that a symbol is an smt theory symbol and hence may not be used in smt patterns. The typechecker warns if such symbols are used in patterns *) assume val smt_theory_symbol:attribute (** [l_True] has a special bit of syntactic sugar. It is written just as "True" and rendered in the ide as [True]. It is a squashed version of constructive truth, [trivial]. *) [@@ "tac_opaque"; smt_theory_symbol] let l_True:logical = squash trivial (** [l_False] has a special bit of syntactic sugar. It is written just as "False" and rendered in the ide as [Falsee]. It is a squashed version of constructive falsehood, the empty type. *) [@@ "tac_opaque"; smt_theory_symbol] let l_False:logical = squash empty (** The type of provable equalities, defined as the usual inductive type with a single constructor for reflexivity. As with the other connectives, we often work instead with the squashed version of equality, below. *) type equals (#a: Type) (x: a) : a -> Type = | Refl : equals x x (** [eq2] is the squashed version of [equals]. It's a proof irrelevant, homogeneous equality in Type#0 and is written with an infix binary [==]. TODO: instead of hard-wiring the == syntax, we should just rename eq2 to op_Equals_Equals *) [@@ "tac_opaque"; smt_theory_symbol] type eq2 (#a: Type) (x: a) (y: a) : logical = squash (equals x y) (** bool-to-type coercion: This is often automatically inserted type, when using a boolean in context expecting a type. But, occasionally, one may have to write [b2t] explicitly *) type b2t (b: bool) : logical = (b == true) (** constructive conjunction *) type pair (p: Type) (q: Type) = | Pair : _1:p -> _2:q -> pair p q (** squashed conjunction, specialized to [Type0], written with an infix binary [/\] *) [@@ "tac_opaque"; smt_theory_symbol] type l_and (p: logical) (q: logical) : logical = squash (pair p q) (** constructive disjunction *) type sum (p: Type) (q: Type) = | Left : v:p -> sum p q | Right : v:q -> sum p q (** squashed disjunction, specialized to [Type0], written with an infix binary [\/] *) [@@ "tac_opaque"; smt_theory_symbol] type l_or (p: logical) (q: logical) : logical = squash (sum p q) (** squashed (non-dependent) implication, specialized to [Type0], written with an infix binary [==>]. Note, [==>] binds weaker than [/\] and [\/] *) [@@ "tac_opaque"; smt_theory_symbol] type l_imp (p: logical) (q: logical) : logical = squash (p -> GTot q) (* ^^^ NB: The GTot effect is primitive; *) (* elaborated using GHOST a few lines below *) (** squashed double implication, infix binary [<==>] *) [@@ smt_theory_symbol] type l_iff (p: logical) (q: logical) : logical = (p ==> q) /\ (q ==> p) (** squashed negation, prefix unary [~] *) [@@ smt_theory_symbol] type l_not (p: logical) : logical = l_imp p False (** l_ITE is a weak form of if-then-else at the level of logical formulae. It's not much used. TODO: Can we remove it *) unfold type l_ITE (p: logical) (q: logical) (r: logical) : logical = (p ==> q) /\ (~p ==> r) (** One of the main axioms provided by prims is [precedes], a built-in well-founded partial order over all terms. It's typically written with an infix binary [<<]. The [<<] order includes: * The [<] ordering on natural numbers * The subterm ordering on inductive types * [f x << D f] for data constructors D of an inductive t whose arguments include a ghost or total function returning a t *) assume type precedes : #a: Type -> #b: Type -> a -> b -> Type0 (** The type of primitive strings of characters; See FStar.String *) assume new type string : eqtype (** This attribute can be added to the declaration or definition of any top-level symbol. It causes F* to report a warning on any use of that symbol, printing the [msg] argument. This is used, for instance to: - tag every escape hatch, e.g., [assume], [admit], etc Reports for uses of symbols tagged with this attribute are controlled using the `--report_assumes` option and warning number 334. See tests/micro-benchmarks/WarnOnUse.fst *) assume val warn_on_use (msg: string) : Tot unit (** The [deprecated "s"] attribute: "s" is an alternative function that should be printed in the warning it can be omitted if the use case has no such function *) assume val deprecated (s: string) : Tot unit (** Within the SMT encoding, we have a relation [(HasType e t)] asserting that (the encoding of) [e] has a type corresponding to (the encoding of) [t]. It is sometimes convenient, e.g., when writing triggers for quantifiers, to have access to this relation at the source level. The [has_type] predicate below reflects the SMT encodings [HasType] relation. We also use it to define the type [prop] or proof irrelevant propositions, below. Note, unless you have a really good reason, you probably don't want to use this [has_type] predicate. F*'s type theory certainly does not internalize its own typing judgment *) [@@deprecated "'has_type' is intended for internal use and debugging purposes only; \ do not rely on it for your proofs"] assume type has_type : #a: Type -> a -> Type -> Type0 (** Squashed universal quantification, or dependent products, written [forall (x:a). p x], specialized to Type0 *) [@@ "tac_opaque"; smt_theory_symbol] type l_Forall (#a: Type) (p: (a -> GTot Type0)) : logical = squash (x: a -> GTot (p x)) #push-options "--warn_error -288" (** [p1 `subtype_of` p2] when every element of [p1] is also an element of [p2]. *) let subtype_of (p1 p2: Type) = forall (x: p1). has_type x p2 #pop-options (** The type of squashed types. Note, the [prop] type is a work in progress in F*. In particular, we would like in the future to more systematically use [prop] for proof-irrelevant propositions throughout the libraries. However, we still use [Type0] in many places. See https://github.com/FStarLang/FStar/issues/1048 for more details and the current status of the work. *) type prop = a: Type0{a `subtype_of` unit} (**** The PURE effect *) (** The type of pure preconditions *) let pure_pre = Type0 (** Pure postconditions, predicates on [a], on which the precondition [pre] is also valid. This provides a way for postcondition formula to be typed in a context where they can assume the validity of the precondition. This is discussed extensively in Issue #57 *) let pure_post' (a pre: Type) = _: a{pre} -> GTot Type0 let pure_post (a: Type) = pure_post' a True (** A pure weakest precondition transforms postconditions on [a]-typed results to pure preconditions We require the weakest preconditions to satisfy the monotonicity property over the postconditions To enforce it, we first define a vanilla wp type, and then refine it with the monotonicity condition *) let pure_wp' (a: Type) = pure_post a -> GTot pure_pre (** The monotonicity predicate is marked opaque_to_smt, meaning that its definition is hidden from the SMT solver, and if required, will need to be explicitly revealed This has the advantage that clients that do not need to work with it directly, don't have the (quantified) definition in their solver context *) let pure_wp_monotonic0 (a:Type) (wp:pure_wp' a) = forall (p q:pure_post a). (forall (x:a). p x ==> q x) ==> (wp p ==> wp q) [@@ "opaque_to_smt"] let pure_wp_monotonic = pure_wp_monotonic0 let pure_wp (a: Type) = wp:pure_wp' a{pure_wp_monotonic a wp} (** This predicate is an internal detail, used to optimize the encoding of some quantifiers to SMT by omitting their typing guards. This is safe to use only when the quantifier serves to introduce a local macro---use with caution. *) assume type guard_free : Type0 -> Type0 (** The return combinator for the PURE effect requires proving the postcondition only on [x] Clients should not use it directly, instead use FStar.Pervasives.pure_return *) unfold let pure_return0 (a: Type) (x: a) : pure_wp a = fun (p: pure_post a) -> forall (return_val: a). return_val == x ==> p return_val (** Sequential composition for the PURE effect Clients should not use it directly, instead use FStar.Pervasives.pure_bind_wp *) unfold let pure_bind_wp0 (a b: Type) (wp1: pure_wp a) (wp2: (a -> GTot (pure_wp b))) : pure_wp b = fun (p: pure_post b) -> wp1 (fun (bind_result_1: a) -> wp2 bind_result_1 p) (** Conditional composition for the PURE effect The combinator is optimized to make use of how the typechecker generates VC for conditionals. The more intuitive form of the combinator would have been: [(p ==> wp_then post) /\ (~p ==> wp_else post)] However, the way the typechecker constructs the VC, [wp_then] is already weakened with [p]. Hence, here we only weaken [wp_else] Clients should not use it directly, instead use FStar.Pervasives.pure_if_then_else *) unfold let pure_if_then_else0 (a p: Type) (wp_then wp_else: pure_wp a) : pure_wp a = fun (post: pure_post a) -> wp_then post /\ (~p ==> wp_else post) (** Conditional composition for the PURE effect, while trying to avoid duplicating the postcondition by giving it a local name [k]. Note the use of [guard_free] here: [k] is just meant to be a macro for [post]. Clients should not use it directly, instead use FStar.Pervasives.pure_ite_wp *) unfold let pure_ite_wp0 (a: Type) (wp: pure_wp a) : pure_wp a = fun (post: pure_post a) -> forall (k: pure_post a). (forall (x: a). {:pattern (guard_free (k x))} post x ==> k x) ==> wp k (** Subsumption for the PURE effect *) unfold let pure_stronger (a: Type) (wp1 wp2: pure_wp a) = forall (p: pure_post a). wp1 p ==> wp2 p (** Closing a PURE WP under a binder for [b] Clients should not use it directly, instead use FStar.Pervasives.pure_close_wp *) unfold let pure_close_wp0 (a b: Type) (wp: (b -> GTot (pure_wp a))) : pure_wp a = fun (p: pure_post a) -> forall (b: b). wp b p (** Trivial WP for PURE: Prove the WP with the trivial postcondition *) unfold let pure_trivial (a: Type) (wp: pure_wp a) = wp (fun (trivial_result: a) -> True) (** Introduces the PURE effect. The definition of the PURE effect is fixed. NO USER SHOULD EVER CHANGE THIS. *) total new_effect { PURE : a: Type -> wp: pure_wp a -> Effect with return_wp = pure_return0 ; bind_wp = pure_bind_wp0 ; if_then_else = pure_if_then_else0 ; ite_wp = pure_ite_wp0 ; stronger = pure_stronger ; close_wp = pure_close_wp0 ; trivial = pure_trivial } (** [Pure] is a Hoare-style counterpart of [PURE] Note the type of post, which allows to assume the precondition for the well-formedness of the postcondition. c.f. #57 *) effect Pure (a: Type) (pre: pure_pre) (post: pure_post' a pre) = PURE a (fun (p: pure_post a) -> pre /\ (forall (pure_result: a). post pure_result ==> p pure_result)) (** [Admit] is an effect abbreviation for a computation that disregards the verification condition of its continuation *) effect Admit (a: Type) = PURE a (fun (p: pure_post a) -> True) (** The primitive effect [Tot] is definitionally equal to an instance of [PURE] *) (** Clients should not use it directly, instead use FStar.Pervasives.pure_null_wp *) unfold let pure_null_wp0 (a: Type) : pure_wp a = fun (p: pure_post a) -> forall (any_result: a). p any_result (** [Tot]: From here on, we have [Tot] as a defined symbol in F*. *) effect Tot (a: Type) = PURE a (pure_null_wp0 a) (** Clients should not use it directly, instead use FStar.Pervasives.pure_assert_wp *) [@@ "opaque_to_smt"] unfold let pure_assert_wp0 (p: Type) : pure_wp unit = fun (post: pure_post unit) -> p /\ post () (** Clients should not use it directly, instead use FStar.Pervasives.pure_assume_wp *) [@@ "opaque_to_smt"] unfold let pure_assume_wp0 (p: Type) : pure_wp unit = fun (post: pure_post unit) -> p ==> post () (**** The [GHOST] effect *) (** [GHOST] is logically equivalent to [PURE], but distinguished from it nominally so that specific, computationally irrelevant operations, are provided only in [GHOST] and are erased during extraction *) total new_effect GHOST = PURE unfold let purewp_id (a: Type) (wp: pure_wp a) = wp (** [PURE] computations can be lifted to the [GHOST] effect (but not vice versa) using just the identity lifting on pure wps *) sub_effect PURE ~> GHOST { lift_wp = purewp_id } (** [Ghost] is a the Hoare-style counterpart of [GHOST] *) effect Ghost (a: Type) (pre: Type) (post: pure_post' a pre) = GHOST a (fun (p: pure_post a) -> pre /\ (forall (ghost_result: a). post ghost_result ==> p ghost_result) ) (** As with [Tot], the primitive effect [GTot] is definitionally equal to an instance of GHOST *) effect GTot (a: Type) = GHOST a (pure_null_wp0 a) (***** End trusted primitives *****) (** This point onward, F* fully verifies all the definitions *) (** [===] heterogeneous equality *) let ( === ) (#a #b: Type) (x: a) (y: b) : logical = a == b /\ x == y (** Dependent pairs [dtuple2] in concrete syntax is [x:a & b x]. Its values can be constructed with the concrete syntax [(| x, y |)] *) unopteq type dtuple2 (a: Type) (b: (a -> GTot Type)) = | Mkdtuple2 : _1: a -> _2: b _1 -> dtuple2 a b (** Squashed existential quantification, or dependent sums, are written [exists (x:a). p x] : specialized to Type0 *) [@@ "tac_opaque"; smt_theory_symbol] type l_Exists (#a: Type) (p: (a -> GTot Type0)) : logical = squash (x: a & p x) (** Primitive type of mathematical integers, mapped to zarith in OCaml extraction and to the SMT sort of integers *) assume new type int : eqtype (**** Basic operators on booleans and integers *) (** [&&] boolean conjunction *) [@@ smt_theory_symbol] assume val op_AmpAmp: bool -> bool -> Tot bool (** [||] boolean disjunction *) [@@ smt_theory_symbol] assume val op_BarBar: bool -> bool -> Tot bool (** [not] boolean negation *) [@@ smt_theory_symbol] assume val op_Negation: bool -> Tot bool (** Integer multiplication, no special symbol. See FStar.Mul *) [@@ smt_theory_symbol] assume val op_Multiply: int -> int -> Tot int (** [-] integer subtraction *) [@@ smt_theory_symbol] assume val op_Subtraction: int -> int -> Tot int (** [+] integer addition *) [@@ smt_theory_symbol] assume val op_Addition: int -> int -> Tot int (** [-] prefix unary integer negation *) [@@ smt_theory_symbol] assume val op_Minus: int -> Tot int (** [<=] integer comparison *) [@@ smt_theory_symbol] assume val op_LessThanOrEqual: int -> int -> Tot bool (** [>] integer comparison *) [@@ smt_theory_symbol] assume val op_GreaterThan: int -> int -> Tot bool (** [>=] integer comparison *) [@@ smt_theory_symbol] assume val op_GreaterThanOrEqual: int -> int -> Tot bool (** [<] integer comparison *) [@@ smt_theory_symbol] assume val op_LessThan: int -> int -> Tot bool (** [=] decidable equality on [eqtype] *) [@@ smt_theory_symbol] assume val op_Equality: #a: eqtype -> a -> a -> Tot bool (** [<>] decidable dis-equality on [eqtype] *) [@@ smt_theory_symbol] assume val op_disEquality: #a: eqtype -> a -> a -> Tot bool (** The extensible open inductive type of exceptions *) assume new type exn : Type0 (** [array]: TODO: should be removed. See FStar.Seq, LowStar.Buffer, etc. *) assume new type array : Type -> Type0 (** String concatenation and its abbreviation as [^]. TODO, both should be removed in favor of what is present in FStar.String *) assume val strcat: string -> string -> Tot string inline_for_extraction unfold let op_Hat s1 s2 = strcat s1 s2 (** The inductive type of polymorphic lists *) type list (a: Type) = | Nil : list a | Cons : hd: a -> tl: list a -> list a (** The [M] marker is interpreted by the Dijkstra Monads for Free construction. It has a "double meaning", either as an alias for reasoning about the direct definitions, or as a marker for places where a CPS transformation should happen. *) effect M (a: Type) = Tot a (attributes cps) (** Returning a value into the [M] effect *) let returnM (a: Type) (x: a) : M a = x (** [as_requires] turns a WP into a precondition, by applying it to a trivial postcondition *) unfold let as_requires (#a: Type) (wp: pure_wp a) : pure_pre = wp (fun x -> True) (** [as_ensures] turns a WP into a postcondition, relying on a kind of double negation translation. *) unfold let as_ensures (#a: Type) (wp: pure_wp a) : pure_post a = fun (x:a) -> ~(wp (fun y -> (y =!= x))) (** The keyword term-level keyword [assume] is desugared to [_assume]. It explicitly provides an escape hatch to assume a given property [p]. *) [@@ warn_on_use "Uses an axiom"] assume val _assume (p: Type) : Pure unit (requires (True)) (ensures (fun x -> p)) (** [admit] is another escape hatch: It discards the continuation and returns a value of any type *) [@@ warn_on_use "Uses an axiom"] assume val admit: #a: Type -> unit -> Admit a (** [magic] is another escape hatch: It retains the continuation but returns a value of any type *) [@@ warn_on_use "Uses an axiom"] assume val magic: #a: Type -> unit -> Tot a (** [unsafe_coerce] is another escape hatch: It coerces an [a] to a [b]. *) [@@ warn_on_use "Uses an axiom"] irreducible let unsafe_coerce (#a #b: Type) (x: a) : b = admit (); x (** [admitP]: TODO: Unused ... remove? *) [@@ warn_on_use "Uses an axiom"] assume val admitP (p: Type) : Pure unit True (fun x -> p) (** The keyword term-level keyword [assert] is desugared to [_assert]. It force a proof of a property [p], then assuming [p] for the continuation. *) val _assert (p: Type) : Pure unit (requires p) (ensures (fun x -> p)) let _assert p = () (** Logically equivalent to assert; TODO remove? *) val cut (p: Type) : Pure unit (requires p) (fun x -> p) let cut p = () (** The type of non-negative integers *) type nat = i: int{i >= 0} (** The type of positive integers *) type pos = i: int{i > 0} (** The type of non-zero integers *) type nonzero = i: int{i <> 0} /// Arbitrary precision ints are compiled to zarith (big_ints) in /// OCaml and to .NET BigInteger in F#. Both the modulus and division /// operations are Euclidean and are mapped to the corresponding /// theory symbols in the SMT encoding (** Euclidean modulus *) [@@ smt_theory_symbol] assume val op_Modulus: int -> nonzero -> Tot int (** Euclidean division, written [/] *) [@@ smt_theory_symbol] assume val op_Division: int -> nonzero -> Tot int (** [pow2 x] is [2^x]:
{ "checked_file": "/", "dependencies": [], "interface_file": false, "source_file": "prims.fst" }
[ { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
x: Prims.nat -> Prims.pos
Prims.Tot
[ "total" ]
[]
[ "Prims.nat", "Prims.int", "Prims.op_Multiply", "Prims.pow2", "Prims.op_Subtraction", "Prims.pos" ]
[ "recursion" ]
false
false
false
true
false
let rec pow2 (x: nat) : Tot pos =
match x with | 0 -> 1 | _ -> 2 `op_Multiply` (pow2 (x - 1))
false
Vale.X64.Lemmas.fst
Vale.X64.Lemmas.lemma_merge_total
val lemma_merge_total (b0:codes) (s0:vale_state) (f0:fuel) (sM:vale_state) (fM:fuel) (sN:vale_state) : Lemma (requires Cons? b0 /\ eval_code (Cons?.hd b0) s0 f0 sM /\ eval_code (Block (Cons?.tl b0)) sM fM sN ) (ensures eval_code (Block b0) s0 (compute_merge_total f0 fM) sN)
val lemma_merge_total (b0:codes) (s0:vale_state) (f0:fuel) (sM:vale_state) (fM:fuel) (sN:vale_state) : Lemma (requires Cons? b0 /\ eval_code (Cons?.hd b0) s0 f0 sM /\ eval_code (Block (Cons?.tl b0)) sM fM sN ) (ensures eval_code (Block b0) s0 (compute_merge_total f0 fM) sN)
let lemma_merge_total (b0:codes) (s0:vale_state) (f0:fuel) (sM:vale_state) (fM:fuel) (sN:vale_state) = let f = if f0 > fM then f0 else fM in increase_fuel (codes_modifies_ghost b0) (Cons?.hd b0) (state_to_S s0) f0 (state_to_S sM) f; increase_fuel (codes_modifies_ghost b0) (Block (Cons?.tl b0)) (state_to_S sM) fM (state_to_S sN) f
{ "file_name": "vale/code/arch/x64/Vale.X64.Lemmas.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 100, "end_line": 353, "start_col": 0, "start_line": 350 }
module Vale.X64.Lemmas open FStar.Mul open Vale.X64.Machine_s open Vale.X64.State open Vale.X64.StateLemmas open Vale.X64.Instruction_s open Vale.X64.Bytes_Code_s module BS = Vale.X64.Machine_Semantics_s module ME = Vale.X64.Memory #reset-options "--initial_fuel 1 --max_fuel 1 --z3rlimit 100" #restart-solver let rec lemma_eq_instr_apply_eval_args (outs:list instr_out) (args:list instr_operand) (f:instr_args_t outs args) (oprs:instr_operands_t_args args) (s1 s2:machine_state) : Lemma (requires state_eq_S true s1 s2) (ensures BS.instr_apply_eval_args outs args f oprs s1 == BS.instr_apply_eval_args outs args f oprs s2) = let open BS in lemma_heap_ignore_ghost_machine s1.BS.ms_heap s2.BS.ms_heap; match args with | [] -> () | i::args -> ( let (v, oprs) : option (instr_val_t i) & instr_operands_t_args args = match i with | IOpEx i -> let oprs = coerce oprs in (instr_eval_operand_explicit i (fst oprs) s1, snd oprs) | IOpIm i -> (instr_eval_operand_implicit i s1, coerce oprs) in let f:arrow (instr_val_t i) (instr_args_t outs args) = coerce f in match v with | None -> () | Some v -> lemma_eq_instr_apply_eval_args outs args (f v) oprs s1 s2 ) #restart-solver let rec lemma_eq_instr_apply_eval_inouts (outs inouts:list instr_out) (args:list instr_operand) (f:instr_inouts_t outs inouts args) (oprs:instr_operands_t inouts args) (s1 s2:machine_state) : Lemma (requires state_eq_S true s1 s2) (ensures BS.instr_apply_eval_inouts outs inouts args f oprs s1 == BS.instr_apply_eval_inouts outs inouts args f oprs s2) = let open BS in lemma_heap_ignore_ghost_machine s1.BS.ms_heap s2.BS.ms_heap; match inouts with | [] -> lemma_eq_instr_apply_eval_args outs args f oprs s1 s2 | (Out, i)::inouts -> let oprs = match i with | IOpEx i -> snd #(instr_operand_t i) (coerce oprs) | IOpIm i -> coerce oprs in lemma_eq_instr_apply_eval_inouts outs inouts args (coerce f) oprs s1 s2 | (InOut, i)::inouts -> ( let (v, oprs) : option (instr_val_t i) & instr_operands_t inouts args = match i with | IOpEx i -> let oprs = coerce oprs in (instr_eval_operand_explicit i (fst oprs) s1, snd oprs) | IOpIm i -> (instr_eval_operand_implicit i s1, coerce oprs) in let f:arrow (instr_val_t i) (instr_inouts_t outs inouts args) = coerce f in match v with | None -> () | Some v -> lemma_eq_instr_apply_eval_inouts outs inouts args (f v) oprs s1 s2 ) #restart-solver #push-options "--z3rlimit_factor 2" let rec lemma_eq_instr_write_outputs (outs:list instr_out) (args:list instr_operand) (vs:instr_ret_t outs) (oprs:instr_operands_t outs args) (s1_orig s1 s2_orig s2:machine_state) : Lemma (requires state_eq_S true s1_orig s2_orig /\ state_eq_S true s1 s2) (ensures state_eq_S true (BS.instr_write_outputs outs args vs oprs s1_orig s1) (BS.instr_write_outputs outs args vs oprs s2_orig s2)) = let open BS in use_machine_state_equal (); lemma_heap_ignore_ghost_machine s1.BS.ms_heap s2.BS.ms_heap; lemma_heap_ignore_ghost_machine s1_orig.BS.ms_heap s2_orig.BS.ms_heap; allow_inversion tmaddr; match outs with | [] -> () | (_, i)::outs -> ( let ((v:instr_val_t i), (vs:instr_ret_t outs)) = match outs with | [] -> (vs, ()) | _::_ -> let vs = coerce vs in (fst vs, snd vs) in match i with | IOpEx i -> let oprs = coerce oprs in let s1 = instr_write_output_explicit i v (fst oprs) s1_orig s1 in let s2 = instr_write_output_explicit i v (fst oprs) s2_orig s2 in lemma_eq_instr_write_outputs outs args vs (snd oprs) s1_orig s1 s2_orig s2 | IOpIm i -> let s1 = instr_write_output_implicit i v s1_orig s1 in let s2 = instr_write_output_implicit i v s2_orig s2 in allow_inversion operand64; allow_inversion operand128; lemma_eq_instr_write_outputs outs args vs (coerce oprs) s1_orig s1 s2_orig s2 ) #pop-options #restart-solver let eval_ins_eq_instr (inst:BS.ins) (s1 s2:machine_state) : Lemma (requires Instr? inst /\ state_eq_S true s1 s2) (ensures state_eq_S true (BS.machine_eval_ins inst s1) (BS.machine_eval_ins inst s2)) = let open BS in let Instr it oprs ann = inst in let InstrTypeRecord #outs #args #havoc_flags' i = it in lemma_eq_instr_apply_eval_inouts outs outs args (instr_eval i) oprs s1 s2; let vs = instr_apply_eval outs args (instr_eval i) oprs s1 in let hav s = match havoc_flags' with | HavocFlags -> {s with ms_flags = havoc_flags} | PreserveFlags -> s in let s1' = hav s1 in let s2' = hav s2 in match vs with | None -> () | Some vs -> lemma_eq_instr_write_outputs outs args vs oprs s1 s1' s2 s2' let eval_code_eq_instr (inst:BS.ins) (f:fuel) (s1 s2:machine_state) : Lemma (requires Instr? inst /\ state_eq_S true s1 s2) (ensures state_eq_opt true (BS.machine_eval_code (Ins inst) f s1) (BS.machine_eval_code (Ins inst) f s2)) = reveal_opaque (`%BS.machine_eval_code_ins) BS.machine_eval_code_ins; eval_ins_eq_instr inst ({s1 with BS.ms_trace = []}) ({s2 with BS.ms_trace = []}) let eval_code_eq_dealloc (inst:BS.ins) (f:fuel) (s1 s2:machine_state) : Lemma (requires Dealloc? inst /\ state_eq_S true s1 s2) (ensures state_eq_opt true (BS.machine_eval_code (Ins inst) f s1) (BS.machine_eval_code (Ins inst) f s2)) = reveal_opaque (`%BS.machine_eval_code_ins) BS.machine_eval_code_ins; use_machine_state_equal (); lemma_heap_ignore_ghost_machine s1.BS.ms_heap s2.BS.ms_heap; allow_inversion tmaddr let eval_code_eq_alloc (inst:BS.ins) (f:fuel) (s1 s2:machine_state) : Lemma (requires Alloc? inst /\ state_eq_S true s1 s2) (ensures state_eq_opt true (BS.machine_eval_code (Ins inst) f s1) (BS.machine_eval_code (Ins inst) f s2)) = reveal_opaque (`%BS.machine_eval_code_ins) BS.machine_eval_code_ins; use_machine_state_equal (); lemma_heap_ignore_ghost_machine s1.BS.ms_heap s2.BS.ms_heap; allow_inversion tmaddr let eval_code_eq_push (inst:BS.ins) (f:fuel) (s1 s2:machine_state) : Lemma (requires Push? inst /\ state_eq_S true s1 s2) (ensures state_eq_opt true (BS.machine_eval_code (Ins inst) f s1) (BS.machine_eval_code (Ins inst) f s2)) = reveal_opaque (`%BS.machine_eval_code_ins) BS.machine_eval_code_ins; use_machine_state_equal (); lemma_heap_ignore_ghost_machine s1.BS.ms_heap s2.BS.ms_heap; allow_inversion tmaddr let eval_code_eq_pop (inst:BS.ins) (f:fuel) (s1 s2:machine_state) : Lemma (requires Pop? inst /\ state_eq_S true s1 s2) (ensures state_eq_opt true (BS.machine_eval_code (Ins inst) f s1) (BS.machine_eval_code (Ins inst) f s2)) = reveal_opaque (`%BS.machine_eval_code_ins) BS.machine_eval_code_ins; use_machine_state_equal (); lemma_heap_ignore_ghost_machine s1.BS.ms_heap s2.BS.ms_heap; allow_inversion tmaddr let eval_code_eq_ins (i:BS.ins) (f:fuel) (s1 s2:machine_state) : Lemma (requires state_eq_S true s1 s2) (ensures state_eq_opt true (BS.machine_eval_code (Ins i) f s1) (BS.machine_eval_code (Ins i) f s2)) = match i with | Instr _ _ _ -> eval_code_eq_instr i f s1 s2 | Dealloc _ -> eval_code_eq_dealloc i f s1 s2 | Alloc _ -> eval_code_eq_alloc i f s1 s2 | Push _ _ -> eval_code_eq_push i f s1 s2 | Pop _ _ -> eval_code_eq_pop i f s1 s2 #reset-options "--fuel 2 --z3rlimit 30" let eval_ocmp_eq_core (g:bool) (cond:ocmp) (s:machine_state) : Lemma (ensures ( let (s1, b1) = BS.machine_eval_ocmp s cond in let (s2, b2) = BS.machine_eval_ocmp (core_state g s) cond in state_eq_S g s1 s2 /\ b1 == b2 )) = reveal_opaque (`%BS.valid_ocmp_opaque) BS.valid_ocmp_opaque; reveal_opaque (`%BS.eval_ocmp_opaque) BS.eval_ocmp_opaque; () #restart-solver let rec eval_code_eq_core (g:bool) (c:code) (f:fuel) (s:machine_state) : Lemma (ensures state_eq_opt g (BS.machine_eval_code c f s) (BS.machine_eval_code c f (core_state g s))) (decreases %[f; c]) = match c with | Ins i -> reveal_opaque (`%BS.machine_eval_code_ins) BS.machine_eval_code_ins; if g then eval_code_eq_ins i f s (core_state g s) | Block cs -> eval_codes_eq_core g cs f s | IfElse cond ct cf -> eval_ocmp_eq_core g cond s; let (s', _) = BS.machine_eval_ocmp s cond in let (t', _) = BS.machine_eval_ocmp (core_state g s) cond in eval_code_eq_core g ct f s'; eval_code_eq_core g ct f t'; eval_code_eq_core g cf f s'; eval_code_eq_core g cf f t'; () | While cond body -> eval_while_eq_core g cond body f s and eval_codes_eq_core (g:bool) (cs:codes) (f:fuel) (s:machine_state) : Lemma (ensures state_eq_opt g (BS.machine_eval_codes cs f s) (BS.machine_eval_codes cs f (core_state g s))) (decreases %[f; cs]) = match cs with | [] -> () | c'::cs' -> ( eval_code_eq_core g c' f s; match (machine_eval_code c' f s, machine_eval_code c' f (core_state g s)) with | (None, None) -> () | (Some s', Some t') -> eval_codes_eq_core g cs' f s'; eval_codes_eq_core g cs' f t' ) and eval_while_eq_core (g:bool) (cond:ocmp) (body:code) (f:fuel) (s:machine_state) : Lemma (ensures state_eq_opt g (BS.machine_eval_while cond body f s) (BS.machine_eval_while cond body f (core_state g s))) (decreases %[f; body]) = if f > 0 then ( eval_ocmp_eq_core g cond s; let (s1, _) = BS.machine_eval_ocmp s cond in let (t1, _) = BS.machine_eval_ocmp (core_state g s) cond in eval_code_eq_core g body (f - 1) s1; eval_code_eq_core g body (f - 1) t1; match (BS.machine_eval_code body (f - 1) s1, BS.machine_eval_code body (f - 1) t1) with | (None, None) -> () | (Some s2, Some t2) -> eval_while_eq_core g cond body (f - 1) s2; eval_while_eq_core g cond body (f - 1) t2; () ) let eval_code_eq_f (c:code) (f:fuel) (s1 s2:machine_state) : Lemma (requires state_eq_S false s1 s2) (ensures state_eq_opt false (BS.machine_eval_code c f s1) (BS.machine_eval_code c f s2)) [SMTPat (BS.machine_eval_code c f s1); SMTPat (BS.machine_eval_code c f s2)] = eval_code_eq_core false c f s1; eval_code_eq_core false c f s2 let eval_codes_eq_f (cs:codes) (f:fuel) (s1 s2:machine_state) : Lemma (requires state_eq_S false s1 s2) (ensures state_eq_opt false (BS.machine_eval_codes cs f s1) (BS.machine_eval_codes cs f s2)) [SMTPat (BS.machine_eval_codes cs f s1); SMTPat (BS.machine_eval_codes cs f s2)] = eval_codes_eq_core false cs f s1; eval_codes_eq_core false cs f s2 let eval_while_eq_f (cond:ocmp) (body:code) (f:fuel) (s1 s2:machine_state) : Lemma (requires state_eq_S false s1 s2) (ensures state_eq_opt false (BS.machine_eval_while cond body f s1) (BS.machine_eval_while cond body f s2)) [SMTPat (BS.machine_eval_while cond body f s1); SMTPat (BS.machine_eval_while cond body f s2)] = eval_while_eq_core false cond body f s1; eval_while_eq_core false cond body f s2 let eval_code_eq_t (c:code) (f:fuel) (s1 s2:machine_state) : Lemma (requires state_eq_S true s1 s2) (ensures state_eq_opt true (BS.machine_eval_code c f s1) (BS.machine_eval_code c f s2)) [SMTPat (BS.machine_eval_code c f s1); SMTPat (BS.machine_eval_code c f s2)] = eval_code_eq_core true c f s1; eval_code_eq_core true c f s2 let eval_codes_eq_t (cs:codes) (f:fuel) (s1 s2:machine_state) : Lemma (requires state_eq_S true s1 s2) (ensures state_eq_opt true (BS.machine_eval_codes cs f s1) (BS.machine_eval_codes cs f s2)) [SMTPat (BS.machine_eval_codes cs f s1); SMTPat (BS.machine_eval_codes cs f s2)] = eval_codes_eq_core true cs f s1; eval_codes_eq_core true cs f s2 let eval_while_eq_t (cond:ocmp) (body:code) (f:fuel) (s1 s2:machine_state) : Lemma (requires state_eq_S true s1 s2) (ensures state_eq_opt true (BS.machine_eval_while cond body f s1) (BS.machine_eval_while cond body f s2)) [SMTPat (BS.machine_eval_while cond body f s1); SMTPat (BS.machine_eval_while cond body f s2)] = eval_while_eq_core true cond body f s1; eval_while_eq_core true cond body f s2 let eval_code_ts (g:bool) (c:code) (s0:machine_state) (f0:fuel) (s1:machine_state) : Type0 = state_eq_opt g (BS.machine_eval_code c f0 s0) (Some s1) let rec increase_fuel (g:bool) (c:code) (s0:machine_state) (f0:fuel) (sN:machine_state) (fN:fuel) : Lemma (requires eval_code_ts g c s0 f0 sN /\ f0 <= fN) (ensures eval_code_ts g c s0 fN sN) (decreases %[f0; c]) = match c with | Ins ins -> () | Block l -> increase_fuels g l s0 f0 sN fN | IfElse cond t f -> let (s0, b0) = BS.machine_eval_ocmp s0 cond in if b0 then increase_fuel g t s0 f0 sN fN else increase_fuel g f s0 f0 sN fN | While cond c -> let (s1, b0) = BS.machine_eval_ocmp s0 cond in if b0 then ( match BS.machine_eval_code c (f0 - 1) s1 with | None -> () | Some s2 -> increase_fuel g c s1 (f0 - 1) s2 (fN - 1); if s2.BS.ms_ok then increase_fuel g (While cond c) s2 (f0 - 1) sN (fN - 1) else () ) and increase_fuels (g:bool) (c:codes) (s0:machine_state) (f0:fuel) (sN:machine_state) (fN:fuel) : Lemma (requires eval_code_ts g (Block c) s0 f0 sN /\ f0 <= fN) (ensures eval_code_ts g (Block c) s0 fN sN) (decreases %[f0; c]) = match c with | [] -> () | h::t -> ( let Some s1 = BS.machine_eval_code h f0 s0 in increase_fuel g h s0 f0 s1 fN; increase_fuels g t s1 f0 sN fN ) let lemma_cmp_eq s o1 o2 = reveal_opaque (`%BS.eval_ocmp_opaque) BS.eval_ocmp_opaque let lemma_cmp_ne s o1 o2 = reveal_opaque (`%BS.eval_ocmp_opaque) BS.eval_ocmp_opaque let lemma_cmp_le s o1 o2 = reveal_opaque (`%BS.eval_ocmp_opaque) BS.eval_ocmp_opaque let lemma_cmp_ge s o1 o2 = reveal_opaque (`%BS.eval_ocmp_opaque) BS.eval_ocmp_opaque let lemma_cmp_lt s o1 o2 = reveal_opaque (`%BS.eval_ocmp_opaque) BS.eval_ocmp_opaque let lemma_cmp_gt s o1 o2 = reveal_opaque (`%BS.eval_ocmp_opaque) BS.eval_ocmp_opaque let lemma_valid_cmp_eq s o1 o2 = () let lemma_valid_cmp_ne s o1 o2 = () let lemma_valid_cmp_le s o1 o2 = () let lemma_valid_cmp_ge s o1 o2 = () let lemma_valid_cmp_lt s o1 o2 = () let lemma_valid_cmp_gt s o1 o2 = () let compute_merge_total (f0:fuel) (fM:fuel) = if f0 > fM then f0 else fM
{ "checked_file": "/", "dependencies": [ "Vale.X64.StateLemmas.fsti.checked", "Vale.X64.State.fsti.checked", "Vale.X64.Memory.fsti.checked", "Vale.X64.Machine_Semantics_s.fst.checked", "Vale.X64.Machine_s.fst.checked", "Vale.X64.Instruction_s.fsti.checked", "Vale.X64.Flags.fsti.checked", "Vale.X64.Bytes_Code_s.fst.checked", "prims.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.FunctionalExtensionality.fsti.checked" ], "interface_file": true, "source_file": "Vale.X64.Lemmas.fst" }
[ { "abbrev": true, "full_module": "Vale.X64.Memory", "short_module": "ME" }, { "abbrev": true, "full_module": "Vale.X64.Machine_Semantics_s", "short_module": "BS" }, { "abbrev": false, "full_module": "Vale.X64.Bytes_Code_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Instruction_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.StateLemmas", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.State", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Machine_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": true, "full_module": "Vale.Lib.Map16", "short_module": "Map16" }, { "abbrev": true, "full_module": "Vale.X64.Machine_Semantics_s", "short_module": "BS" }, { "abbrev": false, "full_module": "Vale.X64.Bytes_Code_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.StateLemmas", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.State", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Machine_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.HeapLemmas", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.HeapImpl", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.Heap", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 0, "max_fuel": 2, "max_ifuel": 1, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": true, "smtencoding_l_arith_repr": "native", "smtencoding_nl_arith_repr": "wrapped", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [ "smt.arith.nl=false", "smt.QI.EAGER_THRESHOLD=100", "smt.CASE_SPLIT=3" ], "z3refresh": false, "z3rlimit": 30, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
b0: Vale.X64.Lemmas.codes -> s0: Vale.X64.State.vale_state -> f0: Vale.X64.Lemmas.fuel -> sM: Vale.X64.State.vale_state -> fM: Vale.X64.Lemmas.fuel -> sN: Vale.X64.State.vale_state -> FStar.Pervasives.Lemma (requires Cons? b0 /\ Vale.X64.Lemmas.eval_code (Cons?.hd b0) s0 f0 sM /\ Vale.X64.Lemmas.eval_code (Vale.X64.Machine_s.Block (Cons?.tl b0)) sM fM sN) (ensures Vale.X64.Lemmas.eval_code (Vale.X64.Machine_s.Block b0) s0 (Vale.X64.Lemmas.compute_merge_total f0 fM) sN)
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "Vale.X64.Lemmas.codes", "Vale.X64.State.vale_state", "Vale.X64.Lemmas.fuel", "Vale.X64.Lemmas.increase_fuel", "Vale.X64.Lemmas.codes_modifies_ghost", "Vale.X64.Machine_s.Block", "Vale.X64.Bytes_Code_s.instruction_t", "Vale.X64.Machine_Semantics_s.instr_annotation", "Vale.X64.Bytes_Code_s.ocmp", "Prims.__proj__Cons__item__tl", "Vale.X64.Bytes_Code_s.code_t", "Vale.X64.StateLemmas.state_to_S", "Prims.unit", "Prims.__proj__Cons__item__hd", "Prims.nat", "Prims.op_GreaterThan", "Prims.bool" ]
[]
false
false
true
false
false
let lemma_merge_total (b0: codes) (s0: vale_state) (f0: fuel) (sM: vale_state) (fM: fuel) (sN: vale_state) =
let f = if f0 > fM then f0 else fM in increase_fuel (codes_modifies_ghost b0) (Cons?.hd b0) (state_to_S s0) f0 (state_to_S sM) f; increase_fuel (codes_modifies_ghost b0) (Block (Cons?.tl b0)) (state_to_S sM) fM (state_to_S sN) f
false
FStar.Int.Cast.Full.fst
FStar.Int.Cast.Full.uint64_to_uint128
val uint64_to_uint128: a:U64.t -> b:U128.t{U128.v b == U64.v a}
val uint64_to_uint128: a:U64.t -> b:U128.t{U128.v b == U64.v a}
let uint64_to_uint128 a = U128.uint64_to_uint128 a
{ "file_name": "ulib/FStar.Int.Cast.Full.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 50, "end_line": 26, "start_col": 0, "start_line": 26 }
(* Copyright 2008-2018 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module FStar.Int.Cast.Full include FStar.Int.Cast module U64 = FStar.UInt64 module U128 = FStar.UInt128 inline_for_extraction noextract val uint64_to_uint128: a:U64.t -> b:U128.t{U128.v b == U64.v a}
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.UInt64.fsti.checked", "FStar.UInt128.fsti.checked", "FStar.Pervasives.fsti.checked", "FStar.Int.Cast.fst.checked" ], "interface_file": false, "source_file": "FStar.Int.Cast.Full.fst" }
[ { "abbrev": true, "full_module": "FStar.UInt128", "short_module": "U128" }, { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": false, "full_module": "FStar.Int.Cast", "short_module": null }, { "abbrev": false, "full_module": "FStar.Int.Cast", "short_module": null }, { "abbrev": false, "full_module": "FStar.Int.Cast", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
a: FStar.UInt64.t -> b: FStar.UInt128.t{FStar.UInt128.v b == FStar.UInt64.v a}
Prims.Tot
[ "total" ]
[]
[ "FStar.UInt64.t", "FStar.UInt128.uint64_to_uint128", "FStar.UInt128.t", "Prims.eq2", "Prims.int", "Prims.l_or", "FStar.UInt.size", "FStar.UInt128.n", "FStar.UInt64.n", "FStar.UInt128.v", "FStar.UInt64.v" ]
[]
false
false
false
false
false
let uint64_to_uint128 a =
U128.uint64_to_uint128 a
false
FStar.Int.Cast.Full.fst
FStar.Int.Cast.Full.uint128_to_uint64
val uint128_to_uint64: a:U128.t -> b:U64.t{U64.v b == U128.v a % pow2 64}
val uint128_to_uint64: a:U128.t -> b:U64.t{U64.v b == U128.v a % pow2 64}
let uint128_to_uint64 a = U128.uint128_to_uint64 a
{ "file_name": "ulib/FStar.Int.Cast.Full.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 50, "end_line": 31, "start_col": 0, "start_line": 31 }
(* Copyright 2008-2018 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module FStar.Int.Cast.Full include FStar.Int.Cast module U64 = FStar.UInt64 module U128 = FStar.UInt128 inline_for_extraction noextract val uint64_to_uint128: a:U64.t -> b:U128.t{U128.v b == U64.v a} inline_for_extraction noextract let uint64_to_uint128 a = U128.uint64_to_uint128 a inline_for_extraction noextract val uint128_to_uint64: a:U128.t -> b:U64.t{U64.v b == U128.v a % pow2 64}
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.UInt64.fsti.checked", "FStar.UInt128.fsti.checked", "FStar.Pervasives.fsti.checked", "FStar.Int.Cast.fst.checked" ], "interface_file": false, "source_file": "FStar.Int.Cast.Full.fst" }
[ { "abbrev": true, "full_module": "FStar.UInt128", "short_module": "U128" }, { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": false, "full_module": "FStar.Int.Cast", "short_module": null }, { "abbrev": false, "full_module": "FStar.Int.Cast", "short_module": null }, { "abbrev": false, "full_module": "FStar.Int.Cast", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
a: FStar.UInt128.t -> b: FStar.UInt64.t{FStar.UInt64.v b == FStar.UInt128.v a % Prims.pow2 64}
Prims.Tot
[ "total" ]
[]
[ "FStar.UInt128.t", "FStar.UInt128.uint128_to_uint64", "FStar.UInt64.t", "Prims.eq2", "Prims.int", "FStar.UInt64.v", "Prims.op_Modulus", "FStar.UInt128.v", "Prims.pow2" ]
[]
false
false
false
false
false
let uint128_to_uint64 a =
U128.uint128_to_uint64 a
false
Vale.X64.Instruction_s.fsti
Vale.X64.Instruction_s.instr_out
val instr_out : Type0
let instr_out = instr_operand_inout & instr_operand
{ "file_name": "vale/specs/hardware/Vale.X64.Instruction_s.fsti", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 51, "end_line": 32, "start_col": 0, "start_line": 32 }
module Vale.X64.Instruction_s open FStar.Mul open Vale.Def.Words_s open Vale.Def.Types_s open Vale.X64.Machine_s (* An generic instruction has: - zero or more input operands - zero or more output operands or input/output operands - a possible effect on the status flags Some of the operands may be hard-coded to a particular register; other operands are flexible. For example, the Intel 64-bit MUL instruction, which executes "(RDX:RAX) := RAX * src" has: - one hard-coded input/output operand, the flags - note: the instruction can havoc the flags in addition to or instead of specifying a flags operand - one hard-coded output operand, RDX - one hard-coded input/output operand, RAX - one flexible input operand (src) *) type instr_operand_inout = | InOut | Out type instr_operand_explicit = // flexible operand | IOp64 : instr_operand_explicit | IOpXmm : instr_operand_explicit type instr_operand_implicit = // hard-coded operand | IOp64One : o:operand64 -> instr_operand_implicit | IOpXmmOne : o:operand128 -> instr_operand_implicit | IOpFlagsCf : instr_operand_implicit | IOpFlagsOf : instr_operand_implicit type instr_operand = | IOpEx : instr_operand_explicit -> instr_operand
{ "checked_file": "/", "dependencies": [ "Vale.X64.Machine_s.fst.checked", "Vale.Def.Words_s.fsti.checked", "Vale.Def.Types_s.fst.checked", "prims.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked" ], "interface_file": false, "source_file": "Vale.X64.Instruction_s.fsti" }
[ { "abbrev": false, "full_module": "Vale.X64.Machine_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Types_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 0, "max_fuel": 1, "max_ifuel": 1, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": true, "smtencoding_l_arith_repr": "native", "smtencoding_nl_arith_repr": "wrapped", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [ "smt.arith.nl=false", "smt.QI.EAGER_THRESHOLD=100", "smt.CASE_SPLIT=3" ], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
Type0
Prims.Tot
[ "total" ]
[]
[ "FStar.Pervasives.Native.tuple2", "Vale.X64.Instruction_s.instr_operand_inout", "Vale.X64.Instruction_s.instr_operand" ]
[]
false
false
false
true
true
let instr_out =
instr_operand_inout & instr_operand
false
Vale.X64.Instruction_s.fsti
Vale.X64.Instruction_s.normal
val normal (#a: Type) (x: a) : a
val normal (#a: Type) (x: a) : a
let normal (#a:Type) (x:a) : a = norm [zeta; iota; delta_attr [`%instr_attr]] x
{ "file_name": "vale/specs/hardware/Vale.X64.Instruction_s.fsti", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 86, "end_line": 35, "start_col": 7, "start_line": 35 }
module Vale.X64.Instruction_s open FStar.Mul open Vale.Def.Words_s open Vale.Def.Types_s open Vale.X64.Machine_s (* An generic instruction has: - zero or more input operands - zero or more output operands or input/output operands - a possible effect on the status flags Some of the operands may be hard-coded to a particular register; other operands are flexible. For example, the Intel 64-bit MUL instruction, which executes "(RDX:RAX) := RAX * src" has: - one hard-coded input/output operand, the flags - note: the instruction can havoc the flags in addition to or instead of specifying a flags operand - one hard-coded output operand, RDX - one hard-coded input/output operand, RAX - one flexible input operand (src) *) type instr_operand_inout = | InOut | Out type instr_operand_explicit = // flexible operand | IOp64 : instr_operand_explicit | IOpXmm : instr_operand_explicit type instr_operand_implicit = // hard-coded operand | IOp64One : o:operand64 -> instr_operand_implicit | IOpXmmOne : o:operand128 -> instr_operand_implicit | IOpFlagsCf : instr_operand_implicit | IOpFlagsOf : instr_operand_implicit type instr_operand = | IOpEx : instr_operand_explicit -> instr_operand | IOpIm : instr_operand_implicit -> instr_operand let instr_out = instr_operand_inout & instr_operand
{ "checked_file": "/", "dependencies": [ "Vale.X64.Machine_s.fst.checked", "Vale.Def.Words_s.fsti.checked", "Vale.Def.Types_s.fst.checked", "prims.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked" ], "interface_file": false, "source_file": "Vale.X64.Instruction_s.fsti" }
[ { "abbrev": false, "full_module": "Vale.X64.Machine_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Types_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 0, "max_fuel": 1, "max_ifuel": 1, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": true, "smtencoding_l_arith_repr": "native", "smtencoding_nl_arith_repr": "wrapped", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [ "smt.arith.nl=false", "smt.QI.EAGER_THRESHOLD=100", "smt.CASE_SPLIT=3" ], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
x: a -> a
Prims.Tot
[ "total" ]
[]
[ "FStar.Pervasives.norm", "Prims.Cons", "FStar.Pervasives.norm_step", "FStar.Pervasives.zeta", "FStar.Pervasives.iota", "FStar.Pervasives.delta_attr", "Prims.string", "Prims.Nil" ]
[]
false
false
false
true
false
let normal (#a: Type) (x: a) : a =
norm [zeta; iota; delta_attr [`%instr_attr]] x
false
Steel.ST.Effect.fsti
Steel.ST.Effect.bind_ens
val bind_ens : a: Type -> b: Type -> ens_f: Prims.pure_post a -> ens_g: (_: a -> Prims.pure_post b) -> y: b -> Prims.logical
let bind_ens (a:Type) (b:Type) (ens_f: pure_post a) (ens_g: a -> pure_post b) = fun (y:b) -> exists (x:a). ens_f x /\ ens_g x y
{ "file_name": "lib/steel/Steel.ST.Effect.fsti", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 51, "end_line": 57, "start_col": 0, "start_line": 54 }
(* Copyright 2020 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module Steel.ST.Effect (** This module provides an effect ST, a specialization of Steel.Effect.Steel removing selectors from the requires and ensures indexes *) open Steel.Memory open FStar.Ghost module Mem = Steel.Memory module T = FStar.Tactics include Steel.Effect.Common #set-options "--warn_error -330" //turn off the experimental feature warning #set-options "--ide_id_info_off" val repr (a:Type) (framed:bool) (pre:pre_t) (post:post_t a) (req:pure_pre) (ens:pure_post a) : Type u#2 val return_ (a:Type) (x:a) (#[@@@ framing_implicit] p:a -> vprop) : repr a true (return_pre (p x)) p True (fun v -> v == x) unfold let bind_req (a:Type) (req_f: pure_pre) (ens_f: pure_post a) (pr:a -> prop) (req_g: a -> pure_pre) = req_f /\ (forall (x:a). ens_f x ==> pr x /\ req_g x)
{ "checked_file": "/", "dependencies": [ "Steel.Memory.fsti.checked", "Steel.Effect.Common.fsti.checked", "prims.fst.checked", "FStar.Tactics.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Ghost.fsti.checked" ], "interface_file": false, "source_file": "Steel.ST.Effect.fsti" }
[ { "abbrev": false, "full_module": "Steel.Effect", "short_module": null }, { "abbrev": false, "full_module": "Steel.Effect.Common", "short_module": null }, { "abbrev": true, "full_module": "FStar.Tactics", "short_module": "T" }, { "abbrev": true, "full_module": "Steel.Memory", "short_module": "Mem" }, { "abbrev": false, "full_module": "FStar.Ghost", "short_module": null }, { "abbrev": false, "full_module": "Steel.Memory", "short_module": null }, { "abbrev": false, "full_module": "Steel.Effect.Common", "short_module": null }, { "abbrev": true, "full_module": "FStar.Tactics", "short_module": "T" }, { "abbrev": true, "full_module": "Steel.Memory", "short_module": "Mem" }, { "abbrev": false, "full_module": "FStar.Ghost", "short_module": null }, { "abbrev": false, "full_module": "Steel.Memory", "short_module": null }, { "abbrev": false, "full_module": "Steel.ST", "short_module": null }, { "abbrev": false, "full_module": "Steel.ST", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
a: Type -> b: Type -> ens_f: Prims.pure_post a -> ens_g: (_: a -> Prims.pure_post b) -> y: b -> Prims.logical
Prims.Tot
[ "total" ]
[]
[ "Prims.pure_post", "Prims.l_Exists", "Prims.l_and", "Prims.logical" ]
[]
false
false
false
true
true
let bind_ens (a b: Type) (ens_f: pure_post a) (ens_g: (a -> pure_post b)) =
fun (y: b) -> exists (x: a). ens_f x /\ ens_g x y
false
Vale.X64.Instruction_s.fsti
Vale.X64.Instruction_s.arrow
val arrow : a: Type -> b: Type -> Type
let arrow (a b:Type) = a -> b
{ "file_name": "vale/specs/hardware/Vale.X64.Instruction_s.fsti", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 29, "end_line": 37, "start_col": 0, "start_line": 37 }
module Vale.X64.Instruction_s open FStar.Mul open Vale.Def.Words_s open Vale.Def.Types_s open Vale.X64.Machine_s (* An generic instruction has: - zero or more input operands - zero or more output operands or input/output operands - a possible effect on the status flags Some of the operands may be hard-coded to a particular register; other operands are flexible. For example, the Intel 64-bit MUL instruction, which executes "(RDX:RAX) := RAX * src" has: - one hard-coded input/output operand, the flags - note: the instruction can havoc the flags in addition to or instead of specifying a flags operand - one hard-coded output operand, RDX - one hard-coded input/output operand, RAX - one flexible input operand (src) *) type instr_operand_inout = | InOut | Out type instr_operand_explicit = // flexible operand | IOp64 : instr_operand_explicit | IOpXmm : instr_operand_explicit type instr_operand_implicit = // hard-coded operand | IOp64One : o:operand64 -> instr_operand_implicit | IOpXmmOne : o:operand128 -> instr_operand_implicit | IOpFlagsCf : instr_operand_implicit | IOpFlagsOf : instr_operand_implicit type instr_operand = | IOpEx : instr_operand_explicit -> instr_operand | IOpIm : instr_operand_implicit -> instr_operand let instr_out = instr_operand_inout & instr_operand irreducible let instr_attr = () unfold let normal (#a:Type) (x:a) : a = norm [zeta; iota; delta_attr [`%instr_attr]] x
{ "checked_file": "/", "dependencies": [ "Vale.X64.Machine_s.fst.checked", "Vale.Def.Words_s.fsti.checked", "Vale.Def.Types_s.fst.checked", "prims.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked" ], "interface_file": false, "source_file": "Vale.X64.Instruction_s.fsti" }
[ { "abbrev": false, "full_module": "Vale.X64.Machine_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Types_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 0, "max_fuel": 1, "max_ifuel": 1, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": true, "smtencoding_l_arith_repr": "native", "smtencoding_nl_arith_repr": "wrapped", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [ "smt.arith.nl=false", "smt.QI.EAGER_THRESHOLD=100", "smt.CASE_SPLIT=3" ], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
a: Type -> b: Type -> Type
Prims.Tot
[ "total" ]
[]
[]
[]
false
false
false
true
true
let arrow (a b: Type) =
a -> b
false
Steel.ST.Effect.fsti
Steel.ST.Effect.if_then_else_ens
val if_then_else_ens (a: Type) (p: Type0) (ens_then ens_else: pure_post a) : pure_post a
val if_then_else_ens (a: Type) (p: Type0) (ens_then ens_else: pure_post a) : pure_post a
let if_then_else_ens (a:Type) (p:Type0) (ens_then ens_else : pure_post a) : pure_post a = fun (x:a) -> (p ==> ens_then x) /\ (~p ==> ens_else x)
{ "file_name": "lib/steel/Steel.ST.Effect.fsti", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 25, "end_line": 127, "start_col": 0, "start_line": 121 }
(* Copyright 2020 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module Steel.ST.Effect (** This module provides an effect ST, a specialization of Steel.Effect.Steel removing selectors from the requires and ensures indexes *) open Steel.Memory open FStar.Ghost module Mem = Steel.Memory module T = FStar.Tactics include Steel.Effect.Common #set-options "--warn_error -330" //turn off the experimental feature warning #set-options "--ide_id_info_off" val repr (a:Type) (framed:bool) (pre:pre_t) (post:post_t a) (req:pure_pre) (ens:pure_post a) : Type u#2 val return_ (a:Type) (x:a) (#[@@@ framing_implicit] p:a -> vprop) : repr a true (return_pre (p x)) p True (fun v -> v == x) unfold let bind_req (a:Type) (req_f: pure_pre) (ens_f: pure_post a) (pr:a -> prop) (req_g: a -> pure_pre) = req_f /\ (forall (x:a). ens_f x ==> pr x /\ req_g x) unfold let bind_ens (a:Type) (b:Type) (ens_f: pure_post a) (ens_g: a -> pure_post b) = fun (y:b) -> exists (x:a). ens_f x /\ ens_g x y val bind (a:Type) (b:Type) (#framed_f:eqtype_as_type bool) (#framed_g:eqtype_as_type bool) (#[@@@ framing_implicit] pre_f:pre_t) (#[@@@ framing_implicit] post_f:post_t a) (#[@@@ framing_implicit] req_f:pure_pre) (#[@@@ framing_implicit] ens_f:pure_post a) (#[@@@ framing_implicit] pre_g:a -> pre_t) (#[@@@ framing_implicit] post_g:a -> post_t b) (#[@@@ framing_implicit] req_g:a -> pure_pre) (#[@@@ framing_implicit] ens_g:(a -> pure_post b)) (#[@@@ framing_implicit] frame_f:vprop) (#[@@@ framing_implicit] frame_g:a -> vprop) (#[@@@ framing_implicit] post:post_t b) (#[@@@ framing_implicit] _ : squash (maybe_emp framed_f frame_f)) (#[@@@ framing_implicit] _ : squash (maybe_emp_dep framed_g frame_g)) (#[@@@ framing_implicit] pr:a -> prop) (#[@@@ framing_implicit] p1:squash (can_be_split_forall_dep pr (fun x -> post_f x `star` frame_f) (fun x -> pre_g x `star` frame_g x))) (#[@@@ framing_implicit] p2:squash (can_be_split_post (fun x y -> post_g x y `star` frame_g x) post)) (f:repr a framed_f pre_f post_f req_f ens_f) (g:(x:a -> repr b framed_g (pre_g x) (post_g x) (req_g x) (ens_g x))) : repr b true (pre_f `star` frame_f) post (bind_req a req_f ens_f pr req_g) (bind_ens a b ens_f ens_g) val subcomp (a:Type) (#framed_f:eqtype_as_type bool) (#framed_g:eqtype_as_type bool) (#[@@@ framing_implicit] pre_f:pre_t) (#[@@@ framing_implicit] post_f:post_t a) (#[@@@ framing_implicit] req_f:pure_pre) (#[@@@ framing_implicit] ens_f:pure_post a) (#[@@@ framing_implicit] pre_g:pre_t) (#[@@@ framing_implicit] post_g:post_t a) (#[@@@ framing_implicit] req_g:pure_pre) (#[@@@ framing_implicit] ens_g:pure_post a) (#[@@@ framing_implicit] frame:vprop) (#[@@@ framing_implicit] _ : squash (maybe_emp framed_f frame)) (#[@@@ framing_implicit] p1:squash (can_be_split pre_g (pre_f `star` frame))) (#[@@@ framing_implicit] p2:squash (equiv_forall post_g (fun x -> post_f x `star` frame))) (f:repr a framed_f pre_f post_f req_f ens_f) : Pure (repr a framed_g pre_g post_g req_g ens_g) (requires req_g ==> (req_f /\ (forall x. ens_f x ==> ens_g x))) (ensures fun _ -> True) /// Logical precondition for the if_then_else combinator unfold let if_then_else_req (p:Type0) (req_then req_else:pure_pre) : pure_pre = (p ==> req_then) /\ ((~ p) ==> req_else) /// Logical precondition for the if_then_else combinator
{ "checked_file": "/", "dependencies": [ "Steel.Memory.fsti.checked", "Steel.Effect.Common.fsti.checked", "prims.fst.checked", "FStar.Tactics.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Ghost.fsti.checked" ], "interface_file": false, "source_file": "Steel.ST.Effect.fsti" }
[ { "abbrev": false, "full_module": "Steel.Effect", "short_module": null }, { "abbrev": false, "full_module": "Steel.Effect.Common", "short_module": null }, { "abbrev": true, "full_module": "FStar.Tactics", "short_module": "T" }, { "abbrev": true, "full_module": "Steel.Memory", "short_module": "Mem" }, { "abbrev": false, "full_module": "FStar.Ghost", "short_module": null }, { "abbrev": false, "full_module": "Steel.Memory", "short_module": null }, { "abbrev": false, "full_module": "Steel.Effect.Common", "short_module": null }, { "abbrev": true, "full_module": "FStar.Tactics", "short_module": "T" }, { "abbrev": true, "full_module": "Steel.Memory", "short_module": "Mem" }, { "abbrev": false, "full_module": "FStar.Ghost", "short_module": null }, { "abbrev": false, "full_module": "Steel.Memory", "short_module": null }, { "abbrev": false, "full_module": "Steel.ST", "short_module": null }, { "abbrev": false, "full_module": "Steel.ST", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
a: Type -> p: Type0 -> ens_then: Prims.pure_post a -> ens_else: Prims.pure_post a -> Prims.pure_post a
Prims.Tot
[ "total" ]
[]
[ "Prims.pure_post", "Prims.l_and", "Prims.l_imp", "Prims.l_not" ]
[]
false
false
false
true
false
let if_then_else_ens (a: Type) (p: Type0) (ens_then ens_else: pure_post a) : pure_post a =
fun (x: a) -> (p ==> ens_then x) /\ (~p ==> ens_else x)
false
Steel.ST.Effect.fsti
Steel.ST.Effect.bind_req
val bind_req : a: Type -> req_f: Prims.pure_pre -> ens_f: Prims.pure_post a -> pr: (_: a -> Prims.prop) -> req_g: (_: a -> Prims.pure_pre) -> Prims.logical
let bind_req (a:Type) (req_f: pure_pre) (ens_f: pure_post a) (pr:a -> prop) (req_g: a -> pure_pre) = req_f /\ (forall (x:a). ens_f x ==> pr x /\ req_g x)
{ "file_name": "lib/steel/Steel.ST.Effect.fsti", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 56, "end_line": 50, "start_col": 0, "start_line": 45 }
(* Copyright 2020 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module Steel.ST.Effect (** This module provides an effect ST, a specialization of Steel.Effect.Steel removing selectors from the requires and ensures indexes *) open Steel.Memory open FStar.Ghost module Mem = Steel.Memory module T = FStar.Tactics include Steel.Effect.Common #set-options "--warn_error -330" //turn off the experimental feature warning #set-options "--ide_id_info_off" val repr (a:Type) (framed:bool) (pre:pre_t) (post:post_t a) (req:pure_pre) (ens:pure_post a) : Type u#2 val return_ (a:Type) (x:a) (#[@@@ framing_implicit] p:a -> vprop) : repr a true (return_pre (p x)) p True (fun v -> v == x)
{ "checked_file": "/", "dependencies": [ "Steel.Memory.fsti.checked", "Steel.Effect.Common.fsti.checked", "prims.fst.checked", "FStar.Tactics.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Ghost.fsti.checked" ], "interface_file": false, "source_file": "Steel.ST.Effect.fsti" }
[ { "abbrev": false, "full_module": "Steel.Effect", "short_module": null }, { "abbrev": false, "full_module": "Steel.Effect.Common", "short_module": null }, { "abbrev": true, "full_module": "FStar.Tactics", "short_module": "T" }, { "abbrev": true, "full_module": "Steel.Memory", "short_module": "Mem" }, { "abbrev": false, "full_module": "FStar.Ghost", "short_module": null }, { "abbrev": false, "full_module": "Steel.Memory", "short_module": null }, { "abbrev": false, "full_module": "Steel.Effect.Common", "short_module": null }, { "abbrev": true, "full_module": "FStar.Tactics", "short_module": "T" }, { "abbrev": true, "full_module": "Steel.Memory", "short_module": "Mem" }, { "abbrev": false, "full_module": "FStar.Ghost", "short_module": null }, { "abbrev": false, "full_module": "Steel.Memory", "short_module": null }, { "abbrev": false, "full_module": "Steel.ST", "short_module": null }, { "abbrev": false, "full_module": "Steel.ST", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
a: Type -> req_f: Prims.pure_pre -> ens_f: Prims.pure_post a -> pr: (_: a -> Prims.prop) -> req_g: (_: a -> Prims.pure_pre) -> Prims.logical
Prims.Tot
[ "total" ]
[]
[ "Prims.pure_pre", "Prims.pure_post", "Prims.prop", "Prims.l_and", "Prims.l_Forall", "Prims.l_imp", "Prims.logical" ]
[]
false
false
false
true
true
let bind_req (a: Type) (req_f: pure_pre) (ens_f: pure_post a) (pr: (a -> prop)) (req_g: (a -> pure_pre)) =
req_f /\ (forall (x: a). ens_f x ==> pr x /\ req_g x)
false
Vale.X64.Instruction_s.fsti
Vale.X64.Instruction_s.out
val out : o: Vale.X64.Instruction_s.instr_operand -> Vale.X64.Instruction_s.instr_operand_inout * Vale.X64.Instruction_s.instr_operand
let out (o:instr_operand) = (Out, o)
{ "file_name": "vale/specs/hardware/Vale.X64.Instruction_s.fsti", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 57, "end_line": 41, "start_col": 21, "start_line": 41 }
module Vale.X64.Instruction_s open FStar.Mul open Vale.Def.Words_s open Vale.Def.Types_s open Vale.X64.Machine_s (* An generic instruction has: - zero or more input operands - zero or more output operands or input/output operands - a possible effect on the status flags Some of the operands may be hard-coded to a particular register; other operands are flexible. For example, the Intel 64-bit MUL instruction, which executes "(RDX:RAX) := RAX * src" has: - one hard-coded input/output operand, the flags - note: the instruction can havoc the flags in addition to or instead of specifying a flags operand - one hard-coded output operand, RDX - one hard-coded input/output operand, RAX - one flexible input operand (src) *) type instr_operand_inout = | InOut | Out type instr_operand_explicit = // flexible operand | IOp64 : instr_operand_explicit | IOpXmm : instr_operand_explicit type instr_operand_implicit = // hard-coded operand | IOp64One : o:operand64 -> instr_operand_implicit | IOpXmmOne : o:operand128 -> instr_operand_implicit | IOpFlagsCf : instr_operand_implicit | IOpFlagsOf : instr_operand_implicit type instr_operand = | IOpEx : instr_operand_explicit -> instr_operand | IOpIm : instr_operand_implicit -> instr_operand let instr_out = instr_operand_inout & instr_operand irreducible let instr_attr = () unfold let normal (#a:Type) (x:a) : a = norm [zeta; iota; delta_attr [`%instr_attr]] x let arrow (a b:Type) = a -> b [@instr_attr] unfold let coerce (#b #a:Type) (x:a{a == b}) : b = x
{ "checked_file": "/", "dependencies": [ "Vale.X64.Machine_s.fst.checked", "Vale.Def.Words_s.fsti.checked", "Vale.Def.Types_s.fst.checked", "prims.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked" ], "interface_file": false, "source_file": "Vale.X64.Instruction_s.fsti" }
[ { "abbrev": false, "full_module": "Vale.X64.Machine_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Types_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 0, "max_fuel": 1, "max_ifuel": 1, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": true, "smtencoding_l_arith_repr": "native", "smtencoding_nl_arith_repr": "wrapped", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [ "smt.arith.nl=false", "smt.QI.EAGER_THRESHOLD=100", "smt.CASE_SPLIT=3" ], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
o: Vale.X64.Instruction_s.instr_operand -> Vale.X64.Instruction_s.instr_operand_inout * Vale.X64.Instruction_s.instr_operand
Prims.Tot
[ "total" ]
[]
[ "Vale.X64.Instruction_s.instr_operand", "FStar.Pervasives.Native.Mktuple2", "Vale.X64.Instruction_s.instr_operand_inout", "Vale.X64.Instruction_s.Out", "FStar.Pervasives.Native.tuple2" ]
[]
false
false
false
true
false
let out (o: instr_operand) =
(Out, o)
false
Vale.X64.Instruction_s.fsti
Vale.X64.Instruction_s.inOut
val inOut : o: Vale.X64.Instruction_s.instr_operand -> Vale.X64.Instruction_s.instr_operand_inout * Vale.X64.Instruction_s.instr_operand
let inOut (o:instr_operand) = (InOut, o)
{ "file_name": "vale/specs/hardware/Vale.X64.Instruction_s.fsti", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 61, "end_line": 40, "start_col": 21, "start_line": 40 }
module Vale.X64.Instruction_s open FStar.Mul open Vale.Def.Words_s open Vale.Def.Types_s open Vale.X64.Machine_s (* An generic instruction has: - zero or more input operands - zero or more output operands or input/output operands - a possible effect on the status flags Some of the operands may be hard-coded to a particular register; other operands are flexible. For example, the Intel 64-bit MUL instruction, which executes "(RDX:RAX) := RAX * src" has: - one hard-coded input/output operand, the flags - note: the instruction can havoc the flags in addition to or instead of specifying a flags operand - one hard-coded output operand, RDX - one hard-coded input/output operand, RAX - one flexible input operand (src) *) type instr_operand_inout = | InOut | Out type instr_operand_explicit = // flexible operand | IOp64 : instr_operand_explicit | IOpXmm : instr_operand_explicit type instr_operand_implicit = // hard-coded operand | IOp64One : o:operand64 -> instr_operand_implicit | IOpXmmOne : o:operand128 -> instr_operand_implicit | IOpFlagsCf : instr_operand_implicit | IOpFlagsOf : instr_operand_implicit type instr_operand = | IOpEx : instr_operand_explicit -> instr_operand | IOpIm : instr_operand_implicit -> instr_operand let instr_out = instr_operand_inout & instr_operand irreducible let instr_attr = () unfold let normal (#a:Type) (x:a) : a = norm [zeta; iota; delta_attr [`%instr_attr]] x let arrow (a b:Type) = a -> b [@instr_attr] unfold let coerce (#b #a:Type) (x:a{a == b}) : b = x
{ "checked_file": "/", "dependencies": [ "Vale.X64.Machine_s.fst.checked", "Vale.Def.Words_s.fsti.checked", "Vale.Def.Types_s.fst.checked", "prims.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked" ], "interface_file": false, "source_file": "Vale.X64.Instruction_s.fsti" }
[ { "abbrev": false, "full_module": "Vale.X64.Machine_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Types_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 0, "max_fuel": 1, "max_ifuel": 1, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": true, "smtencoding_l_arith_repr": "native", "smtencoding_nl_arith_repr": "wrapped", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [ "smt.arith.nl=false", "smt.QI.EAGER_THRESHOLD=100", "smt.CASE_SPLIT=3" ], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
o: Vale.X64.Instruction_s.instr_operand -> Vale.X64.Instruction_s.instr_operand_inout * Vale.X64.Instruction_s.instr_operand
Prims.Tot
[ "total" ]
[]
[ "Vale.X64.Instruction_s.instr_operand", "FStar.Pervasives.Native.Mktuple2", "Vale.X64.Instruction_s.instr_operand_inout", "Vale.X64.Instruction_s.InOut", "FStar.Pervasives.Native.tuple2" ]
[]
false
false
false
true
false
let inOut (o: instr_operand) =
(InOut, o)
false
Vale.X64.Instruction_s.fsti
Vale.X64.Instruction_s.op64
val op64 : Vale.X64.Instruction_s.instr_operand
let op64 = IOpEx IOp64
{ "file_name": "vale/specs/hardware/Vale.X64.Instruction_s.fsti", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 43, "end_line": 42, "start_col": 21, "start_line": 42 }
module Vale.X64.Instruction_s open FStar.Mul open Vale.Def.Words_s open Vale.Def.Types_s open Vale.X64.Machine_s (* An generic instruction has: - zero or more input operands - zero or more output operands or input/output operands - a possible effect on the status flags Some of the operands may be hard-coded to a particular register; other operands are flexible. For example, the Intel 64-bit MUL instruction, which executes "(RDX:RAX) := RAX * src" has: - one hard-coded input/output operand, the flags - note: the instruction can havoc the flags in addition to or instead of specifying a flags operand - one hard-coded output operand, RDX - one hard-coded input/output operand, RAX - one flexible input operand (src) *) type instr_operand_inout = | InOut | Out type instr_operand_explicit = // flexible operand | IOp64 : instr_operand_explicit | IOpXmm : instr_operand_explicit type instr_operand_implicit = // hard-coded operand | IOp64One : o:operand64 -> instr_operand_implicit | IOpXmmOne : o:operand128 -> instr_operand_implicit | IOpFlagsCf : instr_operand_implicit | IOpFlagsOf : instr_operand_implicit type instr_operand = | IOpEx : instr_operand_explicit -> instr_operand | IOpIm : instr_operand_implicit -> instr_operand let instr_out = instr_operand_inout & instr_operand irreducible let instr_attr = () unfold let normal (#a:Type) (x:a) : a = norm [zeta; iota; delta_attr [`%instr_attr]] x let arrow (a b:Type) = a -> b [@instr_attr] unfold let coerce (#b #a:Type) (x:a{a == b}) : b = x [@instr_attr] unfold let inOut (o:instr_operand) = (InOut, o)
{ "checked_file": "/", "dependencies": [ "Vale.X64.Machine_s.fst.checked", "Vale.Def.Words_s.fsti.checked", "Vale.Def.Types_s.fst.checked", "prims.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked" ], "interface_file": false, "source_file": "Vale.X64.Instruction_s.fsti" }
[ { "abbrev": false, "full_module": "Vale.X64.Machine_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Types_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 0, "max_fuel": 1, "max_ifuel": 1, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": true, "smtencoding_l_arith_repr": "native", "smtencoding_nl_arith_repr": "wrapped", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [ "smt.arith.nl=false", "smt.QI.EAGER_THRESHOLD=100", "smt.CASE_SPLIT=3" ], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
Vale.X64.Instruction_s.instr_operand
Prims.Tot
[ "total" ]
[]
[ "Vale.X64.Instruction_s.IOpEx", "Vale.X64.Instruction_s.IOp64" ]
[]
false
false
false
true
false
let op64 =
IOpEx IOp64
false
Steel.ST.Effect.fsti
Steel.ST.Effect.bind_pure_st_ens
val bind_pure_st_ens (#a #b: Type) (wp: pure_wp a) (ens: (a -> pure_post b)) : pure_post b
val bind_pure_st_ens (#a #b: Type) (wp: pure_wp a) (ens: (a -> pure_post b)) : pure_post b
let bind_pure_st_ens (#a:Type) (#b:Type) (wp:pure_wp a) (ens: a -> pure_post b) : pure_post b = fun (r:b) -> as_requires wp /\ (exists (x:a). as_ensures wp x /\ ens x r)
{ "file_name": "lib/steel/Steel.ST.Effect.fsti", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 79, "end_line": 205, "start_col": 0, "start_line": 200 }
(* Copyright 2020 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module Steel.ST.Effect (** This module provides an effect ST, a specialization of Steel.Effect.Steel removing selectors from the requires and ensures indexes *) open Steel.Memory open FStar.Ghost module Mem = Steel.Memory module T = FStar.Tactics include Steel.Effect.Common #set-options "--warn_error -330" //turn off the experimental feature warning #set-options "--ide_id_info_off" val repr (a:Type) (framed:bool) (pre:pre_t) (post:post_t a) (req:pure_pre) (ens:pure_post a) : Type u#2 val return_ (a:Type) (x:a) (#[@@@ framing_implicit] p:a -> vprop) : repr a true (return_pre (p x)) p True (fun v -> v == x) unfold let bind_req (a:Type) (req_f: pure_pre) (ens_f: pure_post a) (pr:a -> prop) (req_g: a -> pure_pre) = req_f /\ (forall (x:a). ens_f x ==> pr x /\ req_g x) unfold let bind_ens (a:Type) (b:Type) (ens_f: pure_post a) (ens_g: a -> pure_post b) = fun (y:b) -> exists (x:a). ens_f x /\ ens_g x y val bind (a:Type) (b:Type) (#framed_f:eqtype_as_type bool) (#framed_g:eqtype_as_type bool) (#[@@@ framing_implicit] pre_f:pre_t) (#[@@@ framing_implicit] post_f:post_t a) (#[@@@ framing_implicit] req_f:pure_pre) (#[@@@ framing_implicit] ens_f:pure_post a) (#[@@@ framing_implicit] pre_g:a -> pre_t) (#[@@@ framing_implicit] post_g:a -> post_t b) (#[@@@ framing_implicit] req_g:a -> pure_pre) (#[@@@ framing_implicit] ens_g:(a -> pure_post b)) (#[@@@ framing_implicit] frame_f:vprop) (#[@@@ framing_implicit] frame_g:a -> vprop) (#[@@@ framing_implicit] post:post_t b) (#[@@@ framing_implicit] _ : squash (maybe_emp framed_f frame_f)) (#[@@@ framing_implicit] _ : squash (maybe_emp_dep framed_g frame_g)) (#[@@@ framing_implicit] pr:a -> prop) (#[@@@ framing_implicit] p1:squash (can_be_split_forall_dep pr (fun x -> post_f x `star` frame_f) (fun x -> pre_g x `star` frame_g x))) (#[@@@ framing_implicit] p2:squash (can_be_split_post (fun x y -> post_g x y `star` frame_g x) post)) (f:repr a framed_f pre_f post_f req_f ens_f) (g:(x:a -> repr b framed_g (pre_g x) (post_g x) (req_g x) (ens_g x))) : repr b true (pre_f `star` frame_f) post (bind_req a req_f ens_f pr req_g) (bind_ens a b ens_f ens_g) val subcomp (a:Type) (#framed_f:eqtype_as_type bool) (#framed_g:eqtype_as_type bool) (#[@@@ framing_implicit] pre_f:pre_t) (#[@@@ framing_implicit] post_f:post_t a) (#[@@@ framing_implicit] req_f:pure_pre) (#[@@@ framing_implicit] ens_f:pure_post a) (#[@@@ framing_implicit] pre_g:pre_t) (#[@@@ framing_implicit] post_g:post_t a) (#[@@@ framing_implicit] req_g:pure_pre) (#[@@@ framing_implicit] ens_g:pure_post a) (#[@@@ framing_implicit] frame:vprop) (#[@@@ framing_implicit] _ : squash (maybe_emp framed_f frame)) (#[@@@ framing_implicit] p1:squash (can_be_split pre_g (pre_f `star` frame))) (#[@@@ framing_implicit] p2:squash (equiv_forall post_g (fun x -> post_f x `star` frame))) (f:repr a framed_f pre_f post_f req_f ens_f) : Pure (repr a framed_g pre_g post_g req_g ens_g) (requires req_g ==> (req_f /\ (forall x. ens_f x ==> ens_g x))) (ensures fun _ -> True) /// Logical precondition for the if_then_else combinator unfold let if_then_else_req (p:Type0) (req_then req_else:pure_pre) : pure_pre = (p ==> req_then) /\ ((~ p) ==> req_else) /// Logical precondition for the if_then_else combinator unfold let if_then_else_ens (a:Type) (p:Type0) (ens_then ens_else : pure_post a) : pure_post a = fun (x:a) -> (p ==> ens_then x) /\ (~p ==> ens_else x) let if_then_else (a:Type) (#framed_f:eqtype_as_type bool) (#framed_g:eqtype_as_type bool) (#[@@@ framing_implicit] pre_f:pre_t) (#[@@@ framing_implicit] pre_g:pre_t) (#[@@@ framing_implicit] post_f:post_t a) (#[@@@ framing_implicit] post_g:post_t a) (#[@@@ framing_implicit] req_then:pure_pre) (#[@@@ framing_implicit] ens_then:pure_post a) (#[@@@ framing_implicit] req_else:pure_pre) (#[@@@ framing_implicit] ens_else:pure_post a) (#[@@@ framing_implicit] frame_f : vprop) (#[@@@ framing_implicit] frame_g : vprop) (#[@@@ framing_implicit] me1 : squash (maybe_emp framed_f frame_f)) (#[@@@ framing_implicit] me2 : squash (maybe_emp framed_g frame_g)) (#[@@@ framing_implicit] s_pre: squash (can_be_split (pre_f `star` frame_f) (pre_g `star` frame_g))) (#[@@@ framing_implicit] s_post: squash (equiv_forall (fun x -> post_f x `star` frame_f) (fun x -> post_g x `star` frame_g))) (f:repr a framed_f pre_f post_f req_then ens_then) (g:repr a framed_g pre_g post_g req_else ens_else) (p:bool) : Type = repr a true (pre_f `star` frame_f) (fun x -> post_f x `star` frame_f) (if_then_else_req p req_then req_else) (if_then_else_ens a p ens_then ens_else) /// Assembling the combinators defined above into an actual effect /// /// If the effect appears at the top-level, make sure it is constrained as per STTop [@@ ite_soundness_by ite_attr; top_level_effect "Steel.ST.Effect.STTop"; primitive_extraction ] reflectable effect { STBase (a:Type) (framed:bool) (pre:pre_t) (post:post_t a) (req:pure_pre) (ens:pure_post a) with { repr = repr; return = return_; bind = bind; subcomp = subcomp; if_then_else = if_then_else } } effect ST (a:Type) (pre:pre_t) (post:post_t a) (req:pure_pre) (ens:pure_post a) = STBase a false pre post req ens effect STF (a:Type) (pre:pre_t) (post:post_t a) (req:pure_pre) (ens:pure_post a) = STBase a true pre post req ens // // Trivial preconditions for top-level effect // effect STTop (a:Type) (framed:bool) (post:post_t a) (ens:pure_post a) = STBase a framed emp post True ens /// Logical precondition of a Pure and a Steel computation composition. /// The current state (memory) must satisfy the precondition of the Steel computation, /// and the wp of the PURE computation `as_requires wp` must also be satisfied unfold let bind_pure_st_req (#a:Type) (wp:pure_wp a) (req:a -> pure_pre) : pure_pre = wp req /// Logical postcondition of a Pure and a Steel composition. /// There exists an intermediate value (the output of the Pure computation) such that /// the postcondition of the pure computation is satisfied.
{ "checked_file": "/", "dependencies": [ "Steel.Memory.fsti.checked", "Steel.Effect.Common.fsti.checked", "prims.fst.checked", "FStar.Tactics.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Ghost.fsti.checked" ], "interface_file": false, "source_file": "Steel.ST.Effect.fsti" }
[ { "abbrev": false, "full_module": "Steel.Effect", "short_module": null }, { "abbrev": false, "full_module": "Steel.Effect.Common", "short_module": null }, { "abbrev": true, "full_module": "FStar.Tactics", "short_module": "T" }, { "abbrev": true, "full_module": "Steel.Memory", "short_module": "Mem" }, { "abbrev": false, "full_module": "FStar.Ghost", "short_module": null }, { "abbrev": false, "full_module": "Steel.Memory", "short_module": null }, { "abbrev": false, "full_module": "Steel.Effect.Common", "short_module": null }, { "abbrev": true, "full_module": "FStar.Tactics", "short_module": "T" }, { "abbrev": true, "full_module": "Steel.Memory", "short_module": "Mem" }, { "abbrev": false, "full_module": "FStar.Ghost", "short_module": null }, { "abbrev": false, "full_module": "Steel.Memory", "short_module": null }, { "abbrev": false, "full_module": "Steel.ST", "short_module": null }, { "abbrev": false, "full_module": "Steel.ST", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
wp: Prims.pure_wp a -> ens: (_: a -> Prims.pure_post b) -> Prims.pure_post b
Prims.Tot
[ "total" ]
[]
[ "Prims.pure_wp", "Prims.pure_post", "Prims.l_and", "Prims.as_requires", "Prims.l_Exists", "Prims.as_ensures" ]
[]
false
false
false
true
false
let bind_pure_st_ens (#a #b: Type) (wp: pure_wp a) (ens: (a -> pure_post b)) : pure_post b =
fun (r: b) -> as_requires wp /\ (exists (x: a). as_ensures wp x /\ ens x r)
false
Vale.X64.Instruction_s.fsti
Vale.X64.Instruction_s.opXmm
val opXmm : Vale.X64.Instruction_s.instr_operand
let opXmm = IOpEx IOpXmm
{ "file_name": "vale/specs/hardware/Vale.X64.Instruction_s.fsti", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 45, "end_line": 43, "start_col": 21, "start_line": 43 }
module Vale.X64.Instruction_s open FStar.Mul open Vale.Def.Words_s open Vale.Def.Types_s open Vale.X64.Machine_s (* An generic instruction has: - zero or more input operands - zero or more output operands or input/output operands - a possible effect on the status flags Some of the operands may be hard-coded to a particular register; other operands are flexible. For example, the Intel 64-bit MUL instruction, which executes "(RDX:RAX) := RAX * src" has: - one hard-coded input/output operand, the flags - note: the instruction can havoc the flags in addition to or instead of specifying a flags operand - one hard-coded output operand, RDX - one hard-coded input/output operand, RAX - one flexible input operand (src) *) type instr_operand_inout = | InOut | Out type instr_operand_explicit = // flexible operand | IOp64 : instr_operand_explicit | IOpXmm : instr_operand_explicit type instr_operand_implicit = // hard-coded operand | IOp64One : o:operand64 -> instr_operand_implicit | IOpXmmOne : o:operand128 -> instr_operand_implicit | IOpFlagsCf : instr_operand_implicit | IOpFlagsOf : instr_operand_implicit type instr_operand = | IOpEx : instr_operand_explicit -> instr_operand | IOpIm : instr_operand_implicit -> instr_operand let instr_out = instr_operand_inout & instr_operand irreducible let instr_attr = () unfold let normal (#a:Type) (x:a) : a = norm [zeta; iota; delta_attr [`%instr_attr]] x let arrow (a b:Type) = a -> b [@instr_attr] unfold let coerce (#b #a:Type) (x:a{a == b}) : b = x [@instr_attr] unfold let inOut (o:instr_operand) = (InOut, o) [@instr_attr] unfold let out (o:instr_operand) = (Out, o)
{ "checked_file": "/", "dependencies": [ "Vale.X64.Machine_s.fst.checked", "Vale.Def.Words_s.fsti.checked", "Vale.Def.Types_s.fst.checked", "prims.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked" ], "interface_file": false, "source_file": "Vale.X64.Instruction_s.fsti" }
[ { "abbrev": false, "full_module": "Vale.X64.Machine_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Types_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 0, "max_fuel": 1, "max_ifuel": 1, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": true, "smtencoding_l_arith_repr": "native", "smtencoding_nl_arith_repr": "wrapped", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [ "smt.arith.nl=false", "smt.QI.EAGER_THRESHOLD=100", "smt.CASE_SPLIT=3" ], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
Vale.X64.Instruction_s.instr_operand
Prims.Tot
[ "total" ]
[]
[ "Vale.X64.Instruction_s.IOpEx", "Vale.X64.Instruction_s.IOpXmm" ]
[]
false
false
false
true
false
let opXmm =
IOpEx IOpXmm
false
Vale.X64.Instruction_s.fsti
Vale.X64.Instruction_s.one64
val one64 : o: Vale.X64.Machine_s.operand64 -> Vale.X64.Instruction_s.instr_operand
let one64 (o:operand64) = IOpIm (IOp64One o)
{ "file_name": "vale/specs/hardware/Vale.X64.Instruction_s.fsti", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 65, "end_line": 44, "start_col": 21, "start_line": 44 }
module Vale.X64.Instruction_s open FStar.Mul open Vale.Def.Words_s open Vale.Def.Types_s open Vale.X64.Machine_s (* An generic instruction has: - zero or more input operands - zero or more output operands or input/output operands - a possible effect on the status flags Some of the operands may be hard-coded to a particular register; other operands are flexible. For example, the Intel 64-bit MUL instruction, which executes "(RDX:RAX) := RAX * src" has: - one hard-coded input/output operand, the flags - note: the instruction can havoc the flags in addition to or instead of specifying a flags operand - one hard-coded output operand, RDX - one hard-coded input/output operand, RAX - one flexible input operand (src) *) type instr_operand_inout = | InOut | Out type instr_operand_explicit = // flexible operand | IOp64 : instr_operand_explicit | IOpXmm : instr_operand_explicit type instr_operand_implicit = // hard-coded operand | IOp64One : o:operand64 -> instr_operand_implicit | IOpXmmOne : o:operand128 -> instr_operand_implicit | IOpFlagsCf : instr_operand_implicit | IOpFlagsOf : instr_operand_implicit type instr_operand = | IOpEx : instr_operand_explicit -> instr_operand | IOpIm : instr_operand_implicit -> instr_operand let instr_out = instr_operand_inout & instr_operand irreducible let instr_attr = () unfold let normal (#a:Type) (x:a) : a = norm [zeta; iota; delta_attr [`%instr_attr]] x let arrow (a b:Type) = a -> b [@instr_attr] unfold let coerce (#b #a:Type) (x:a{a == b}) : b = x [@instr_attr] unfold let inOut (o:instr_operand) = (InOut, o) [@instr_attr] unfold let out (o:instr_operand) = (Out, o) [@instr_attr] unfold let op64 = IOpEx IOp64
{ "checked_file": "/", "dependencies": [ "Vale.X64.Machine_s.fst.checked", "Vale.Def.Words_s.fsti.checked", "Vale.Def.Types_s.fst.checked", "prims.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked" ], "interface_file": false, "source_file": "Vale.X64.Instruction_s.fsti" }
[ { "abbrev": false, "full_module": "Vale.X64.Machine_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Types_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 0, "max_fuel": 1, "max_ifuel": 1, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": true, "smtencoding_l_arith_repr": "native", "smtencoding_nl_arith_repr": "wrapped", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [ "smt.arith.nl=false", "smt.QI.EAGER_THRESHOLD=100", "smt.CASE_SPLIT=3" ], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
o: Vale.X64.Machine_s.operand64 -> Vale.X64.Instruction_s.instr_operand
Prims.Tot
[ "total" ]
[]
[ "Vale.X64.Machine_s.operand64", "Vale.X64.Instruction_s.IOpIm", "Vale.X64.Instruction_s.IOp64One", "Vale.X64.Instruction_s.instr_operand" ]
[]
false
false
false
true
false
let one64 (o: operand64) =
IOpIm (IOp64One o)
false
Vale.X64.Instruction_s.fsti
Vale.X64.Instruction_s.oneXmm
val oneXmm : o: Vale.X64.Machine_s.operand128 -> Vale.X64.Instruction_s.instr_operand
let oneXmm (o:operand128) = IOpIm (IOpXmmOne o)
{ "file_name": "vale/specs/hardware/Vale.X64.Instruction_s.fsti", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 68, "end_line": 46, "start_col": 21, "start_line": 46 }
module Vale.X64.Instruction_s open FStar.Mul open Vale.Def.Words_s open Vale.Def.Types_s open Vale.X64.Machine_s (* An generic instruction has: - zero or more input operands - zero or more output operands or input/output operands - a possible effect on the status flags Some of the operands may be hard-coded to a particular register; other operands are flexible. For example, the Intel 64-bit MUL instruction, which executes "(RDX:RAX) := RAX * src" has: - one hard-coded input/output operand, the flags - note: the instruction can havoc the flags in addition to or instead of specifying a flags operand - one hard-coded output operand, RDX - one hard-coded input/output operand, RAX - one flexible input operand (src) *) type instr_operand_inout = | InOut | Out type instr_operand_explicit = // flexible operand | IOp64 : instr_operand_explicit | IOpXmm : instr_operand_explicit type instr_operand_implicit = // hard-coded operand | IOp64One : o:operand64 -> instr_operand_implicit | IOpXmmOne : o:operand128 -> instr_operand_implicit | IOpFlagsCf : instr_operand_implicit | IOpFlagsOf : instr_operand_implicit type instr_operand = | IOpEx : instr_operand_explicit -> instr_operand | IOpIm : instr_operand_implicit -> instr_operand let instr_out = instr_operand_inout & instr_operand irreducible let instr_attr = () unfold let normal (#a:Type) (x:a) : a = norm [zeta; iota; delta_attr [`%instr_attr]] x let arrow (a b:Type) = a -> b [@instr_attr] unfold let coerce (#b #a:Type) (x:a{a == b}) : b = x [@instr_attr] unfold let inOut (o:instr_operand) = (InOut, o) [@instr_attr] unfold let out (o:instr_operand) = (Out, o) [@instr_attr] unfold let op64 = IOpEx IOp64 [@instr_attr] unfold let opXmm = IOpEx IOpXmm [@instr_attr] unfold let one64 (o:operand64) = IOpIm (IOp64One o)
{ "checked_file": "/", "dependencies": [ "Vale.X64.Machine_s.fst.checked", "Vale.Def.Words_s.fsti.checked", "Vale.Def.Types_s.fst.checked", "prims.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked" ], "interface_file": false, "source_file": "Vale.X64.Instruction_s.fsti" }
[ { "abbrev": false, "full_module": "Vale.X64.Machine_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Types_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 0, "max_fuel": 1, "max_ifuel": 1, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": true, "smtencoding_l_arith_repr": "native", "smtencoding_nl_arith_repr": "wrapped", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [ "smt.arith.nl=false", "smt.QI.EAGER_THRESHOLD=100", "smt.CASE_SPLIT=3" ], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
o: Vale.X64.Machine_s.operand128 -> Vale.X64.Instruction_s.instr_operand
Prims.Tot
[ "total" ]
[]
[ "Vale.X64.Machine_s.operand128", "Vale.X64.Instruction_s.IOpIm", "Vale.X64.Instruction_s.IOpXmmOne", "Vale.X64.Instruction_s.instr_operand" ]
[]
false
false
false
true
false
let oneXmm (o: operand128) =
IOpIm (IOpXmmOne o)
false
Steel.ST.Effect.fsti
Steel.ST.Effect.if_then_else_req
val if_then_else_req (p: Type0) (req_then req_else: pure_pre) : pure_pre
val if_then_else_req (p: Type0) (req_then req_else: pure_pre) : pure_pre
let if_then_else_req (p:Type0) (req_then req_else:pure_pre) : pure_pre = (p ==> req_then) /\ ((~ p) ==> req_else)
{ "file_name": "lib/steel/Steel.ST.Effect.fsti", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 25, "end_line": 117, "start_col": 0, "start_line": 114 }
(* Copyright 2020 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module Steel.ST.Effect (** This module provides an effect ST, a specialization of Steel.Effect.Steel removing selectors from the requires and ensures indexes *) open Steel.Memory open FStar.Ghost module Mem = Steel.Memory module T = FStar.Tactics include Steel.Effect.Common #set-options "--warn_error -330" //turn off the experimental feature warning #set-options "--ide_id_info_off" val repr (a:Type) (framed:bool) (pre:pre_t) (post:post_t a) (req:pure_pre) (ens:pure_post a) : Type u#2 val return_ (a:Type) (x:a) (#[@@@ framing_implicit] p:a -> vprop) : repr a true (return_pre (p x)) p True (fun v -> v == x) unfold let bind_req (a:Type) (req_f: pure_pre) (ens_f: pure_post a) (pr:a -> prop) (req_g: a -> pure_pre) = req_f /\ (forall (x:a). ens_f x ==> pr x /\ req_g x) unfold let bind_ens (a:Type) (b:Type) (ens_f: pure_post a) (ens_g: a -> pure_post b) = fun (y:b) -> exists (x:a). ens_f x /\ ens_g x y val bind (a:Type) (b:Type) (#framed_f:eqtype_as_type bool) (#framed_g:eqtype_as_type bool) (#[@@@ framing_implicit] pre_f:pre_t) (#[@@@ framing_implicit] post_f:post_t a) (#[@@@ framing_implicit] req_f:pure_pre) (#[@@@ framing_implicit] ens_f:pure_post a) (#[@@@ framing_implicit] pre_g:a -> pre_t) (#[@@@ framing_implicit] post_g:a -> post_t b) (#[@@@ framing_implicit] req_g:a -> pure_pre) (#[@@@ framing_implicit] ens_g:(a -> pure_post b)) (#[@@@ framing_implicit] frame_f:vprop) (#[@@@ framing_implicit] frame_g:a -> vprop) (#[@@@ framing_implicit] post:post_t b) (#[@@@ framing_implicit] _ : squash (maybe_emp framed_f frame_f)) (#[@@@ framing_implicit] _ : squash (maybe_emp_dep framed_g frame_g)) (#[@@@ framing_implicit] pr:a -> prop) (#[@@@ framing_implicit] p1:squash (can_be_split_forall_dep pr (fun x -> post_f x `star` frame_f) (fun x -> pre_g x `star` frame_g x))) (#[@@@ framing_implicit] p2:squash (can_be_split_post (fun x y -> post_g x y `star` frame_g x) post)) (f:repr a framed_f pre_f post_f req_f ens_f) (g:(x:a -> repr b framed_g (pre_g x) (post_g x) (req_g x) (ens_g x))) : repr b true (pre_f `star` frame_f) post (bind_req a req_f ens_f pr req_g) (bind_ens a b ens_f ens_g) val subcomp (a:Type) (#framed_f:eqtype_as_type bool) (#framed_g:eqtype_as_type bool) (#[@@@ framing_implicit] pre_f:pre_t) (#[@@@ framing_implicit] post_f:post_t a) (#[@@@ framing_implicit] req_f:pure_pre) (#[@@@ framing_implicit] ens_f:pure_post a) (#[@@@ framing_implicit] pre_g:pre_t) (#[@@@ framing_implicit] post_g:post_t a) (#[@@@ framing_implicit] req_g:pure_pre) (#[@@@ framing_implicit] ens_g:pure_post a) (#[@@@ framing_implicit] frame:vprop) (#[@@@ framing_implicit] _ : squash (maybe_emp framed_f frame)) (#[@@@ framing_implicit] p1:squash (can_be_split pre_g (pre_f `star` frame))) (#[@@@ framing_implicit] p2:squash (equiv_forall post_g (fun x -> post_f x `star` frame))) (f:repr a framed_f pre_f post_f req_f ens_f) : Pure (repr a framed_g pre_g post_g req_g ens_g) (requires req_g ==> (req_f /\ (forall x. ens_f x ==> ens_g x))) (ensures fun _ -> True) /// Logical precondition for the if_then_else combinator
{ "checked_file": "/", "dependencies": [ "Steel.Memory.fsti.checked", "Steel.Effect.Common.fsti.checked", "prims.fst.checked", "FStar.Tactics.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Ghost.fsti.checked" ], "interface_file": false, "source_file": "Steel.ST.Effect.fsti" }
[ { "abbrev": false, "full_module": "Steel.Effect", "short_module": null }, { "abbrev": false, "full_module": "Steel.Effect.Common", "short_module": null }, { "abbrev": true, "full_module": "FStar.Tactics", "short_module": "T" }, { "abbrev": true, "full_module": "Steel.Memory", "short_module": "Mem" }, { "abbrev": false, "full_module": "FStar.Ghost", "short_module": null }, { "abbrev": false, "full_module": "Steel.Memory", "short_module": null }, { "abbrev": false, "full_module": "Steel.Effect.Common", "short_module": null }, { "abbrev": true, "full_module": "FStar.Tactics", "short_module": "T" }, { "abbrev": true, "full_module": "Steel.Memory", "short_module": "Mem" }, { "abbrev": false, "full_module": "FStar.Ghost", "short_module": null }, { "abbrev": false, "full_module": "Steel.Memory", "short_module": null }, { "abbrev": false, "full_module": "Steel.ST", "short_module": null }, { "abbrev": false, "full_module": "Steel.ST", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
p: Type0 -> req_then: Prims.pure_pre -> req_else: Prims.pure_pre -> Prims.pure_pre
Prims.Tot
[ "total" ]
[]
[ "Prims.pure_pre", "Prims.l_and", "Prims.l_imp", "Prims.l_not" ]
[]
false
false
false
true
false
let if_then_else_req (p: Type0) (req_then req_else: pure_pre) : pure_pre =
(p ==> req_then) /\ ((~p) ==> req_else)
false
Vale.X64.Instruction_s.fsti
Vale.X64.Instruction_s.opFlagsCf
val opFlagsCf : Vale.X64.Instruction_s.instr_operand
let opFlagsCf = IOpIm IOpFlagsCf
{ "file_name": "vale/specs/hardware/Vale.X64.Instruction_s.fsti", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 53, "end_line": 47, "start_col": 21, "start_line": 47 }
module Vale.X64.Instruction_s open FStar.Mul open Vale.Def.Words_s open Vale.Def.Types_s open Vale.X64.Machine_s (* An generic instruction has: - zero or more input operands - zero or more output operands or input/output operands - a possible effect on the status flags Some of the operands may be hard-coded to a particular register; other operands are flexible. For example, the Intel 64-bit MUL instruction, which executes "(RDX:RAX) := RAX * src" has: - one hard-coded input/output operand, the flags - note: the instruction can havoc the flags in addition to or instead of specifying a flags operand - one hard-coded output operand, RDX - one hard-coded input/output operand, RAX - one flexible input operand (src) *) type instr_operand_inout = | InOut | Out type instr_operand_explicit = // flexible operand | IOp64 : instr_operand_explicit | IOpXmm : instr_operand_explicit type instr_operand_implicit = // hard-coded operand | IOp64One : o:operand64 -> instr_operand_implicit | IOpXmmOne : o:operand128 -> instr_operand_implicit | IOpFlagsCf : instr_operand_implicit | IOpFlagsOf : instr_operand_implicit type instr_operand = | IOpEx : instr_operand_explicit -> instr_operand | IOpIm : instr_operand_implicit -> instr_operand let instr_out = instr_operand_inout & instr_operand irreducible let instr_attr = () unfold let normal (#a:Type) (x:a) : a = norm [zeta; iota; delta_attr [`%instr_attr]] x let arrow (a b:Type) = a -> b [@instr_attr] unfold let coerce (#b #a:Type) (x:a{a == b}) : b = x [@instr_attr] unfold let inOut (o:instr_operand) = (InOut, o) [@instr_attr] unfold let out (o:instr_operand) = (Out, o) [@instr_attr] unfold let op64 = IOpEx IOp64 [@instr_attr] unfold let opXmm = IOpEx IOpXmm [@instr_attr] unfold let one64 (o:operand64) = IOpIm (IOp64One o) [@instr_attr] unfold let one64Reg (r:reg_64) = IOpIm (IOp64One (OReg r))
{ "checked_file": "/", "dependencies": [ "Vale.X64.Machine_s.fst.checked", "Vale.Def.Words_s.fsti.checked", "Vale.Def.Types_s.fst.checked", "prims.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked" ], "interface_file": false, "source_file": "Vale.X64.Instruction_s.fsti" }
[ { "abbrev": false, "full_module": "Vale.X64.Machine_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Types_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 0, "max_fuel": 1, "max_ifuel": 1, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": true, "smtencoding_l_arith_repr": "native", "smtencoding_nl_arith_repr": "wrapped", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [ "smt.arith.nl=false", "smt.QI.EAGER_THRESHOLD=100", "smt.CASE_SPLIT=3" ], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
Vale.X64.Instruction_s.instr_operand
Prims.Tot
[ "total" ]
[]
[ "Vale.X64.Instruction_s.IOpIm", "Vale.X64.Instruction_s.IOpFlagsCf" ]
[]
false
false
false
true
false
let opFlagsCf =
IOpIm IOpFlagsCf
false
Vale.X64.Instruction_s.fsti
Vale.X64.Instruction_s.opFlagsOf
val opFlagsOf : Vale.X64.Instruction_s.instr_operand
let opFlagsOf = IOpIm IOpFlagsOf
{ "file_name": "vale/specs/hardware/Vale.X64.Instruction_s.fsti", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 53, "end_line": 48, "start_col": 21, "start_line": 48 }
module Vale.X64.Instruction_s open FStar.Mul open Vale.Def.Words_s open Vale.Def.Types_s open Vale.X64.Machine_s (* An generic instruction has: - zero or more input operands - zero or more output operands or input/output operands - a possible effect on the status flags Some of the operands may be hard-coded to a particular register; other operands are flexible. For example, the Intel 64-bit MUL instruction, which executes "(RDX:RAX) := RAX * src" has: - one hard-coded input/output operand, the flags - note: the instruction can havoc the flags in addition to or instead of specifying a flags operand - one hard-coded output operand, RDX - one hard-coded input/output operand, RAX - one flexible input operand (src) *) type instr_operand_inout = | InOut | Out type instr_operand_explicit = // flexible operand | IOp64 : instr_operand_explicit | IOpXmm : instr_operand_explicit type instr_operand_implicit = // hard-coded operand | IOp64One : o:operand64 -> instr_operand_implicit | IOpXmmOne : o:operand128 -> instr_operand_implicit | IOpFlagsCf : instr_operand_implicit | IOpFlagsOf : instr_operand_implicit type instr_operand = | IOpEx : instr_operand_explicit -> instr_operand | IOpIm : instr_operand_implicit -> instr_operand let instr_out = instr_operand_inout & instr_operand irreducible let instr_attr = () unfold let normal (#a:Type) (x:a) : a = norm [zeta; iota; delta_attr [`%instr_attr]] x let arrow (a b:Type) = a -> b [@instr_attr] unfold let coerce (#b #a:Type) (x:a{a == b}) : b = x [@instr_attr] unfold let inOut (o:instr_operand) = (InOut, o) [@instr_attr] unfold let out (o:instr_operand) = (Out, o) [@instr_attr] unfold let op64 = IOpEx IOp64 [@instr_attr] unfold let opXmm = IOpEx IOpXmm [@instr_attr] unfold let one64 (o:operand64) = IOpIm (IOp64One o) [@instr_attr] unfold let one64Reg (r:reg_64) = IOpIm (IOp64One (OReg r)) [@instr_attr] unfold let oneXmm (o:operand128) = IOpIm (IOpXmmOne o)
{ "checked_file": "/", "dependencies": [ "Vale.X64.Machine_s.fst.checked", "Vale.Def.Words_s.fsti.checked", "Vale.Def.Types_s.fst.checked", "prims.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked" ], "interface_file": false, "source_file": "Vale.X64.Instruction_s.fsti" }
[ { "abbrev": false, "full_module": "Vale.X64.Machine_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Types_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 0, "max_fuel": 1, "max_ifuel": 1, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": true, "smtencoding_l_arith_repr": "native", "smtencoding_nl_arith_repr": "wrapped", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [ "smt.arith.nl=false", "smt.QI.EAGER_THRESHOLD=100", "smt.CASE_SPLIT=3" ], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
Vale.X64.Instruction_s.instr_operand
Prims.Tot
[ "total" ]
[]
[ "Vale.X64.Instruction_s.IOpIm", "Vale.X64.Instruction_s.IOpFlagsOf" ]
[]
false
false
false
true
false
let opFlagsOf =
IOpIm IOpFlagsOf
false
C.String.fsti
C.String.zero_free
val zero_free : s: FStar.Seq.Base.seq C.char -> Prims.logical
let zero_free (s: Seq.seq C.char) = forall (i: nat). {:pattern (Seq.index s i)} i < Seq.length s - 1 ==> Seq.index s i <> C.char_of_uint8 0uy
{ "file_name": "krmllib/C.String.fsti", "git_rev": "da1e941b2fcb196aa5d1e34941aa00b4c67ac321", "git_url": "https://github.com/FStarLang/karamel.git", "project_name": "karamel" }
{ "end_col": 65, "end_line": 13, "start_col": 0, "start_line": 11 }
module C.String module U8 = FStar.UInt8 module U32 = FStar.UInt32 module B = LowStar.Buffer module M = LowStar.Modifies open FStar.HyperStack.ST
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowStar.Modifies.fst.checked", "LowStar.Buffer.fst.checked", "FStar.UInt8.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.UInt.fsti.checked", "FStar.String.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked", "FStar.HyperStack.ST.fsti.checked", "C.fst.checked" ], "interface_file": false, "source_file": "C.String.fsti" }
[ { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": true, "full_module": "LowStar.Modifies", "short_module": "M" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": false, "full_module": "C", "short_module": null }, { "abbrev": false, "full_module": "C", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": 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
s: FStar.Seq.Base.seq C.char -> Prims.logical
Prims.Tot
[ "total" ]
[]
[ "FStar.Seq.Base.seq", "C.char", "Prims.l_Forall", "Prims.nat", "Prims.l_imp", "Prims.b2t", "Prims.op_LessThan", "Prims.op_Subtraction", "FStar.Seq.Base.length", "Prims.op_disEquality", "FStar.Seq.Base.index", "C.char_of_uint8", "FStar.UInt8.__uint_to_t", "Prims.logical" ]
[]
false
false
false
true
true
let zero_free (s: Seq.seq C.char) =
forall (i: nat). {:pattern (Seq.index s i)} i < Seq.length s - 1 ==> Seq.index s i <> C.char_of_uint8 0uy
false
Steel.ST.Effect.fsti
Steel.ST.Effect.bind_pure_st_req
val bind_pure_st_req (#a: Type) (wp: pure_wp a) (req: (a -> pure_pre)) : pure_pre
val bind_pure_st_req (#a: Type) (wp: pure_wp a) (req: (a -> pure_pre)) : pure_pre
let bind_pure_st_req (#a:Type) (wp:pure_wp a) (req:a -> pure_pre) : pure_pre = wp req
{ "file_name": "lib/steel/Steel.ST.Effect.fsti", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 9, "end_line": 194, "start_col": 0, "start_line": 190 }
(* Copyright 2020 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module Steel.ST.Effect (** This module provides an effect ST, a specialization of Steel.Effect.Steel removing selectors from the requires and ensures indexes *) open Steel.Memory open FStar.Ghost module Mem = Steel.Memory module T = FStar.Tactics include Steel.Effect.Common #set-options "--warn_error -330" //turn off the experimental feature warning #set-options "--ide_id_info_off" val repr (a:Type) (framed:bool) (pre:pre_t) (post:post_t a) (req:pure_pre) (ens:pure_post a) : Type u#2 val return_ (a:Type) (x:a) (#[@@@ framing_implicit] p:a -> vprop) : repr a true (return_pre (p x)) p True (fun v -> v == x) unfold let bind_req (a:Type) (req_f: pure_pre) (ens_f: pure_post a) (pr:a -> prop) (req_g: a -> pure_pre) = req_f /\ (forall (x:a). ens_f x ==> pr x /\ req_g x) unfold let bind_ens (a:Type) (b:Type) (ens_f: pure_post a) (ens_g: a -> pure_post b) = fun (y:b) -> exists (x:a). ens_f x /\ ens_g x y val bind (a:Type) (b:Type) (#framed_f:eqtype_as_type bool) (#framed_g:eqtype_as_type bool) (#[@@@ framing_implicit] pre_f:pre_t) (#[@@@ framing_implicit] post_f:post_t a) (#[@@@ framing_implicit] req_f:pure_pre) (#[@@@ framing_implicit] ens_f:pure_post a) (#[@@@ framing_implicit] pre_g:a -> pre_t) (#[@@@ framing_implicit] post_g:a -> post_t b) (#[@@@ framing_implicit] req_g:a -> pure_pre) (#[@@@ framing_implicit] ens_g:(a -> pure_post b)) (#[@@@ framing_implicit] frame_f:vprop) (#[@@@ framing_implicit] frame_g:a -> vprop) (#[@@@ framing_implicit] post:post_t b) (#[@@@ framing_implicit] _ : squash (maybe_emp framed_f frame_f)) (#[@@@ framing_implicit] _ : squash (maybe_emp_dep framed_g frame_g)) (#[@@@ framing_implicit] pr:a -> prop) (#[@@@ framing_implicit] p1:squash (can_be_split_forall_dep pr (fun x -> post_f x `star` frame_f) (fun x -> pre_g x `star` frame_g x))) (#[@@@ framing_implicit] p2:squash (can_be_split_post (fun x y -> post_g x y `star` frame_g x) post)) (f:repr a framed_f pre_f post_f req_f ens_f) (g:(x:a -> repr b framed_g (pre_g x) (post_g x) (req_g x) (ens_g x))) : repr b true (pre_f `star` frame_f) post (bind_req a req_f ens_f pr req_g) (bind_ens a b ens_f ens_g) val subcomp (a:Type) (#framed_f:eqtype_as_type bool) (#framed_g:eqtype_as_type bool) (#[@@@ framing_implicit] pre_f:pre_t) (#[@@@ framing_implicit] post_f:post_t a) (#[@@@ framing_implicit] req_f:pure_pre) (#[@@@ framing_implicit] ens_f:pure_post a) (#[@@@ framing_implicit] pre_g:pre_t) (#[@@@ framing_implicit] post_g:post_t a) (#[@@@ framing_implicit] req_g:pure_pre) (#[@@@ framing_implicit] ens_g:pure_post a) (#[@@@ framing_implicit] frame:vprop) (#[@@@ framing_implicit] _ : squash (maybe_emp framed_f frame)) (#[@@@ framing_implicit] p1:squash (can_be_split pre_g (pre_f `star` frame))) (#[@@@ framing_implicit] p2:squash (equiv_forall post_g (fun x -> post_f x `star` frame))) (f:repr a framed_f pre_f post_f req_f ens_f) : Pure (repr a framed_g pre_g post_g req_g ens_g) (requires req_g ==> (req_f /\ (forall x. ens_f x ==> ens_g x))) (ensures fun _ -> True) /// Logical precondition for the if_then_else combinator unfold let if_then_else_req (p:Type0) (req_then req_else:pure_pre) : pure_pre = (p ==> req_then) /\ ((~ p) ==> req_else) /// Logical precondition for the if_then_else combinator unfold let if_then_else_ens (a:Type) (p:Type0) (ens_then ens_else : pure_post a) : pure_post a = fun (x:a) -> (p ==> ens_then x) /\ (~p ==> ens_else x) let if_then_else (a:Type) (#framed_f:eqtype_as_type bool) (#framed_g:eqtype_as_type bool) (#[@@@ framing_implicit] pre_f:pre_t) (#[@@@ framing_implicit] pre_g:pre_t) (#[@@@ framing_implicit] post_f:post_t a) (#[@@@ framing_implicit] post_g:post_t a) (#[@@@ framing_implicit] req_then:pure_pre) (#[@@@ framing_implicit] ens_then:pure_post a) (#[@@@ framing_implicit] req_else:pure_pre) (#[@@@ framing_implicit] ens_else:pure_post a) (#[@@@ framing_implicit] frame_f : vprop) (#[@@@ framing_implicit] frame_g : vprop) (#[@@@ framing_implicit] me1 : squash (maybe_emp framed_f frame_f)) (#[@@@ framing_implicit] me2 : squash (maybe_emp framed_g frame_g)) (#[@@@ framing_implicit] s_pre: squash (can_be_split (pre_f `star` frame_f) (pre_g `star` frame_g))) (#[@@@ framing_implicit] s_post: squash (equiv_forall (fun x -> post_f x `star` frame_f) (fun x -> post_g x `star` frame_g))) (f:repr a framed_f pre_f post_f req_then ens_then) (g:repr a framed_g pre_g post_g req_else ens_else) (p:bool) : Type = repr a true (pre_f `star` frame_f) (fun x -> post_f x `star` frame_f) (if_then_else_req p req_then req_else) (if_then_else_ens a p ens_then ens_else) /// Assembling the combinators defined above into an actual effect /// /// If the effect appears at the top-level, make sure it is constrained as per STTop [@@ ite_soundness_by ite_attr; top_level_effect "Steel.ST.Effect.STTop"; primitive_extraction ] reflectable effect { STBase (a:Type) (framed:bool) (pre:pre_t) (post:post_t a) (req:pure_pre) (ens:pure_post a) with { repr = repr; return = return_; bind = bind; subcomp = subcomp; if_then_else = if_then_else } } effect ST (a:Type) (pre:pre_t) (post:post_t a) (req:pure_pre) (ens:pure_post a) = STBase a false pre post req ens effect STF (a:Type) (pre:pre_t) (post:post_t a) (req:pure_pre) (ens:pure_post a) = STBase a true pre post req ens // // Trivial preconditions for top-level effect // effect STTop (a:Type) (framed:bool) (post:post_t a) (ens:pure_post a) = STBase a framed emp post True ens /// Logical precondition of a Pure and a Steel computation composition. /// The current state (memory) must satisfy the precondition of the Steel computation, /// and the wp of the PURE computation `as_requires wp` must also be satisfied
{ "checked_file": "/", "dependencies": [ "Steel.Memory.fsti.checked", "Steel.Effect.Common.fsti.checked", "prims.fst.checked", "FStar.Tactics.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Ghost.fsti.checked" ], "interface_file": false, "source_file": "Steel.ST.Effect.fsti" }
[ { "abbrev": false, "full_module": "Steel.Effect", "short_module": null }, { "abbrev": false, "full_module": "Steel.Effect.Common", "short_module": null }, { "abbrev": true, "full_module": "FStar.Tactics", "short_module": "T" }, { "abbrev": true, "full_module": "Steel.Memory", "short_module": "Mem" }, { "abbrev": false, "full_module": "FStar.Ghost", "short_module": null }, { "abbrev": false, "full_module": "Steel.Memory", "short_module": null }, { "abbrev": false, "full_module": "Steel.Effect.Common", "short_module": null }, { "abbrev": true, "full_module": "FStar.Tactics", "short_module": "T" }, { "abbrev": true, "full_module": "Steel.Memory", "short_module": "Mem" }, { "abbrev": false, "full_module": "FStar.Ghost", "short_module": null }, { "abbrev": false, "full_module": "Steel.Memory", "short_module": null }, { "abbrev": false, "full_module": "Steel.ST", "short_module": null }, { "abbrev": false, "full_module": "Steel.ST", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
wp: Prims.pure_wp a -> req: (_: a -> Prims.pure_pre) -> Prims.pure_pre
Prims.Tot
[ "total" ]
[]
[ "Prims.pure_wp", "Prims.pure_pre" ]
[]
false
false
false
true
false
let bind_pure_st_req (#a: Type) (wp: pure_wp a) (req: (a -> pure_pre)) : pure_pre =
wp req
false
Vale.X64.Instruction_s.fsti
Vale.X64.Instruction_s.instr_eval_t
val instr_eval_t (outs: list instr_out) (args: list instr_operand) : Type0
val instr_eval_t (outs: list instr_out) (args: list instr_operand) : Type0
let instr_eval_t (outs:list instr_out) (args:list instr_operand) : Type0 = instr_inouts_t outs outs args
{ "file_name": "vale/specs/hardware/Vale.X64.Instruction_s.fsti", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 31, "end_line": 85, "start_col": 0, "start_line": 84 }
module Vale.X64.Instruction_s open FStar.Mul open Vale.Def.Words_s open Vale.Def.Types_s open Vale.X64.Machine_s (* An generic instruction has: - zero or more input operands - zero or more output operands or input/output operands - a possible effect on the status flags Some of the operands may be hard-coded to a particular register; other operands are flexible. For example, the Intel 64-bit MUL instruction, which executes "(RDX:RAX) := RAX * src" has: - one hard-coded input/output operand, the flags - note: the instruction can havoc the flags in addition to or instead of specifying a flags operand - one hard-coded output operand, RDX - one hard-coded input/output operand, RAX - one flexible input operand (src) *) type instr_operand_inout = | InOut | Out type instr_operand_explicit = // flexible operand | IOp64 : instr_operand_explicit | IOpXmm : instr_operand_explicit type instr_operand_implicit = // hard-coded operand | IOp64One : o:operand64 -> instr_operand_implicit | IOpXmmOne : o:operand128 -> instr_operand_implicit | IOpFlagsCf : instr_operand_implicit | IOpFlagsOf : instr_operand_implicit type instr_operand = | IOpEx : instr_operand_explicit -> instr_operand | IOpIm : instr_operand_implicit -> instr_operand let instr_out = instr_operand_inout & instr_operand irreducible let instr_attr = () unfold let normal (#a:Type) (x:a) : a = norm [zeta; iota; delta_attr [`%instr_attr]] x let arrow (a b:Type) = a -> b [@instr_attr] unfold let coerce (#b #a:Type) (x:a{a == b}) : b = x [@instr_attr] unfold let inOut (o:instr_operand) = (InOut, o) [@instr_attr] unfold let out (o:instr_operand) = (Out, o) [@instr_attr] unfold let op64 = IOpEx IOp64 [@instr_attr] unfold let opXmm = IOpEx IOpXmm [@instr_attr] unfold let one64 (o:operand64) = IOpIm (IOp64One o) [@instr_attr] unfold let one64Reg (r:reg_64) = IOpIm (IOp64One (OReg r)) [@instr_attr] unfold let oneXmm (o:operand128) = IOpIm (IOpXmmOne o) [@instr_attr] unfold let opFlagsCf = IOpIm IOpFlagsCf [@instr_attr] unfold let opFlagsOf = IOpIm IOpFlagsOf [@instr_attr] let instr_val_t (o:instr_operand) : Type0 = match o with | IOpEx IOp64 | IOpIm (IOp64One _) -> nat64 | IOpEx IOpXmm | IOpIm (IOpXmmOne _) -> quad32 | IOpIm IOpFlagsCf -> bool | IOpIm IOpFlagsOf -> bool [@instr_attr] let rec instr_ret_t (outs:list instr_out) : Type0 = match outs with | [] -> unit | [(_, o)] -> instr_val_t o | (_, o)::outs -> instr_val_t o & instr_ret_t outs [@instr_attr] let rec instr_args_t (outs:list instr_out) (args:list instr_operand) : Type0 = match args with | [] -> option (instr_ret_t outs) | i::args -> arrow (instr_val_t i) (instr_args_t outs args) [@instr_attr] let rec instr_inouts_t (outs inouts:list instr_out) (args:list instr_operand) : Type0 = match inouts with | [] -> instr_args_t outs args | (Out, _)::inouts -> instr_inouts_t outs inouts args | (InOut, i)::inouts -> arrow (instr_val_t i) (instr_inouts_t outs inouts args) (* An instr evaluator is a function of type: in_outs1 ... -> in_outsi -> args1 -> ...> argsj -> (outs1 & (... & outsk) ...) where in_outs = [(b, o) in outs | b = InOut] *)
{ "checked_file": "/", "dependencies": [ "Vale.X64.Machine_s.fst.checked", "Vale.Def.Words_s.fsti.checked", "Vale.Def.Types_s.fst.checked", "prims.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked" ], "interface_file": false, "source_file": "Vale.X64.Instruction_s.fsti" }
[ { "abbrev": false, "full_module": "Vale.X64.Machine_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Types_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 0, "max_fuel": 1, "max_ifuel": 1, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": true, "smtencoding_l_arith_repr": "native", "smtencoding_nl_arith_repr": "wrapped", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [ "smt.arith.nl=false", "smt.QI.EAGER_THRESHOLD=100", "smt.CASE_SPLIT=3" ], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
outs: Prims.list Vale.X64.Instruction_s.instr_out -> args: Prims.list Vale.X64.Instruction_s.instr_operand -> Type0
Prims.Tot
[ "total" ]
[]
[ "Prims.list", "Vale.X64.Instruction_s.instr_out", "Vale.X64.Instruction_s.instr_operand", "Vale.X64.Instruction_s.instr_inouts_t" ]
[]
false
false
false
true
true
let instr_eval_t (outs: list instr_out) (args: list instr_operand) : Type0 =
instr_inouts_t outs outs args
false
Vale.X64.Instruction_s.fsti
Vale.X64.Instruction_s.coerce
val coerce (#b #a: Type) (x: a{a == b}) : b
val coerce (#b #a: Type) (x: a{a == b}) : b
let coerce (#b #a:Type) (x:a{a == b}) : b = x
{ "file_name": "vale/specs/hardware/Vale.X64.Instruction_s.fsti", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 66, "end_line": 38, "start_col": 21, "start_line": 38 }
module Vale.X64.Instruction_s open FStar.Mul open Vale.Def.Words_s open Vale.Def.Types_s open Vale.X64.Machine_s (* An generic instruction has: - zero or more input operands - zero or more output operands or input/output operands - a possible effect on the status flags Some of the operands may be hard-coded to a particular register; other operands are flexible. For example, the Intel 64-bit MUL instruction, which executes "(RDX:RAX) := RAX * src" has: - one hard-coded input/output operand, the flags - note: the instruction can havoc the flags in addition to or instead of specifying a flags operand - one hard-coded output operand, RDX - one hard-coded input/output operand, RAX - one flexible input operand (src) *) type instr_operand_inout = | InOut | Out type instr_operand_explicit = // flexible operand | IOp64 : instr_operand_explicit | IOpXmm : instr_operand_explicit type instr_operand_implicit = // hard-coded operand | IOp64One : o:operand64 -> instr_operand_implicit | IOpXmmOne : o:operand128 -> instr_operand_implicit | IOpFlagsCf : instr_operand_implicit | IOpFlagsOf : instr_operand_implicit type instr_operand = | IOpEx : instr_operand_explicit -> instr_operand | IOpIm : instr_operand_implicit -> instr_operand let instr_out = instr_operand_inout & instr_operand irreducible let instr_attr = () unfold let normal (#a:Type) (x:a) : a = norm [zeta; iota; delta_attr [`%instr_attr]] x
{ "checked_file": "/", "dependencies": [ "Vale.X64.Machine_s.fst.checked", "Vale.Def.Words_s.fsti.checked", "Vale.Def.Types_s.fst.checked", "prims.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked" ], "interface_file": false, "source_file": "Vale.X64.Instruction_s.fsti" }
[ { "abbrev": false, "full_module": "Vale.X64.Machine_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Types_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 0, "max_fuel": 1, "max_ifuel": 1, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": true, "smtencoding_l_arith_repr": "native", "smtencoding_nl_arith_repr": "wrapped", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [ "smt.arith.nl=false", "smt.QI.EAGER_THRESHOLD=100", "smt.CASE_SPLIT=3" ], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
x: a{a == b} -> b
Prims.Tot
[ "total" ]
[]
[ "Prims.eq2" ]
[]
false
false
false
false
false
let coerce (#b #a: Type) (x: a{a == b}) : b =
x
false
C.String.fsti
C.String.well_formed
val well_formed : s: FStar.Seq.Base.seq C.char -> Prims.logical
let well_formed (s:Seq.seq C.char) = let l = Seq.length s in l <= FStar.UInt.max_int 32 /\ l >= 1 /\ Seq.index s (l - 1) = C.char_of_uint8 0uy /\ zero_free s
{ "file_name": "krmllib/C.String.fsti", "git_rev": "da1e941b2fcb196aa5d1e34941aa00b4c67ac321", "git_url": "https://github.com/FStarLang/karamel.git", "project_name": "karamel" }
{ "end_col": 13, "end_line": 20, "start_col": 0, "start_line": 15 }
module C.String module U8 = FStar.UInt8 module U32 = FStar.UInt32 module B = LowStar.Buffer module M = LowStar.Modifies open FStar.HyperStack.ST let zero_free (s: Seq.seq C.char) = forall (i: nat). {:pattern (Seq.index s i)} i < Seq.length s - 1 ==> Seq.index s i <> C.char_of_uint8 0uy
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowStar.Modifies.fst.checked", "LowStar.Buffer.fst.checked", "FStar.UInt8.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.UInt.fsti.checked", "FStar.String.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked", "FStar.HyperStack.ST.fsti.checked", "C.fst.checked" ], "interface_file": false, "source_file": "C.String.fsti" }
[ { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": true, "full_module": "LowStar.Modifies", "short_module": "M" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": false, "full_module": "C", "short_module": null }, { "abbrev": false, "full_module": "C", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": 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
s: FStar.Seq.Base.seq C.char -> Prims.logical
Prims.Tot
[ "total" ]
[]
[ "FStar.Seq.Base.seq", "C.char", "Prims.l_and", "Prims.b2t", "Prims.op_LessThanOrEqual", "FStar.UInt.max_int", "Prims.op_GreaterThanOrEqual", "Prims.op_Equality", "FStar.Seq.Base.index", "Prims.op_Subtraction", "C.char_of_uint8", "FStar.UInt8.__uint_to_t", "C.String.zero_free", "Prims.nat", "FStar.Seq.Base.length", "Prims.logical" ]
[]
false
false
false
true
true
let well_formed (s: Seq.seq C.char) =
let l = Seq.length s in l <= FStar.UInt.max_int 32 /\ l >= 1 /\ Seq.index s (l - 1) = C.char_of_uint8 0uy /\ zero_free s
false
Vale.X64.Instruction_s.fsti
Vale.X64.Instruction_s.one64Reg
val one64Reg : r: Vale.X64.Machine_s.reg_64 -> Vale.X64.Instruction_s.instr_operand
let one64Reg (r:reg_64) = IOpIm (IOp64One (OReg r))
{ "file_name": "vale/specs/hardware/Vale.X64.Instruction_s.fsti", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 72, "end_line": 45, "start_col": 21, "start_line": 45 }
module Vale.X64.Instruction_s open FStar.Mul open Vale.Def.Words_s open Vale.Def.Types_s open Vale.X64.Machine_s (* An generic instruction has: - zero or more input operands - zero or more output operands or input/output operands - a possible effect on the status flags Some of the operands may be hard-coded to a particular register; other operands are flexible. For example, the Intel 64-bit MUL instruction, which executes "(RDX:RAX) := RAX * src" has: - one hard-coded input/output operand, the flags - note: the instruction can havoc the flags in addition to or instead of specifying a flags operand - one hard-coded output operand, RDX - one hard-coded input/output operand, RAX - one flexible input operand (src) *) type instr_operand_inout = | InOut | Out type instr_operand_explicit = // flexible operand | IOp64 : instr_operand_explicit | IOpXmm : instr_operand_explicit type instr_operand_implicit = // hard-coded operand | IOp64One : o:operand64 -> instr_operand_implicit | IOpXmmOne : o:operand128 -> instr_operand_implicit | IOpFlagsCf : instr_operand_implicit | IOpFlagsOf : instr_operand_implicit type instr_operand = | IOpEx : instr_operand_explicit -> instr_operand | IOpIm : instr_operand_implicit -> instr_operand let instr_out = instr_operand_inout & instr_operand irreducible let instr_attr = () unfold let normal (#a:Type) (x:a) : a = norm [zeta; iota; delta_attr [`%instr_attr]] x let arrow (a b:Type) = a -> b [@instr_attr] unfold let coerce (#b #a:Type) (x:a{a == b}) : b = x [@instr_attr] unfold let inOut (o:instr_operand) = (InOut, o) [@instr_attr] unfold let out (o:instr_operand) = (Out, o) [@instr_attr] unfold let op64 = IOpEx IOp64 [@instr_attr] unfold let opXmm = IOpEx IOpXmm
{ "checked_file": "/", "dependencies": [ "Vale.X64.Machine_s.fst.checked", "Vale.Def.Words_s.fsti.checked", "Vale.Def.Types_s.fst.checked", "prims.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked" ], "interface_file": false, "source_file": "Vale.X64.Instruction_s.fsti" }
[ { "abbrev": false, "full_module": "Vale.X64.Machine_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Types_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 0, "max_fuel": 1, "max_ifuel": 1, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": true, "smtencoding_l_arith_repr": "native", "smtencoding_nl_arith_repr": "wrapped", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [ "smt.arith.nl=false", "smt.QI.EAGER_THRESHOLD=100", "smt.CASE_SPLIT=3" ], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
r: Vale.X64.Machine_s.reg_64 -> Vale.X64.Instruction_s.instr_operand
Prims.Tot
[ "total" ]
[]
[ "Vale.X64.Machine_s.reg_64", "Vale.X64.Instruction_s.IOpIm", "Vale.X64.Instruction_s.IOp64One", "Vale.X64.Machine_s.OReg", "Vale.X64.Machine_s.nat64", "Vale.X64.Instruction_s.instr_operand" ]
[]
false
false
false
true
false
let one64Reg (r: reg_64) =
IOpIm (IOp64One (OReg r))
false
Vale.X64.Instruction_s.fsti
Vale.X64.Instruction_s.instr_args_t
val instr_args_t (outs: list instr_out) (args: list instr_operand) : Type0
val instr_args_t (outs: list instr_out) (args: list instr_operand) : Type0
let rec instr_args_t (outs:list instr_out) (args:list instr_operand) : Type0 = match args with | [] -> option (instr_ret_t outs) | i::args -> arrow (instr_val_t i) (instr_args_t outs args)
{ "file_name": "vale/specs/hardware/Vale.X64.Instruction_s.fsti", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 61, "end_line": 69, "start_col": 0, "start_line": 66 }
module Vale.X64.Instruction_s open FStar.Mul open Vale.Def.Words_s open Vale.Def.Types_s open Vale.X64.Machine_s (* An generic instruction has: - zero or more input operands - zero or more output operands or input/output operands - a possible effect on the status flags Some of the operands may be hard-coded to a particular register; other operands are flexible. For example, the Intel 64-bit MUL instruction, which executes "(RDX:RAX) := RAX * src" has: - one hard-coded input/output operand, the flags - note: the instruction can havoc the flags in addition to or instead of specifying a flags operand - one hard-coded output operand, RDX - one hard-coded input/output operand, RAX - one flexible input operand (src) *) type instr_operand_inout = | InOut | Out type instr_operand_explicit = // flexible operand | IOp64 : instr_operand_explicit | IOpXmm : instr_operand_explicit type instr_operand_implicit = // hard-coded operand | IOp64One : o:operand64 -> instr_operand_implicit | IOpXmmOne : o:operand128 -> instr_operand_implicit | IOpFlagsCf : instr_operand_implicit | IOpFlagsOf : instr_operand_implicit type instr_operand = | IOpEx : instr_operand_explicit -> instr_operand | IOpIm : instr_operand_implicit -> instr_operand let instr_out = instr_operand_inout & instr_operand irreducible let instr_attr = () unfold let normal (#a:Type) (x:a) : a = norm [zeta; iota; delta_attr [`%instr_attr]] x let arrow (a b:Type) = a -> b [@instr_attr] unfold let coerce (#b #a:Type) (x:a{a == b}) : b = x [@instr_attr] unfold let inOut (o:instr_operand) = (InOut, o) [@instr_attr] unfold let out (o:instr_operand) = (Out, o) [@instr_attr] unfold let op64 = IOpEx IOp64 [@instr_attr] unfold let opXmm = IOpEx IOpXmm [@instr_attr] unfold let one64 (o:operand64) = IOpIm (IOp64One o) [@instr_attr] unfold let one64Reg (r:reg_64) = IOpIm (IOp64One (OReg r)) [@instr_attr] unfold let oneXmm (o:operand128) = IOpIm (IOpXmmOne o) [@instr_attr] unfold let opFlagsCf = IOpIm IOpFlagsCf [@instr_attr] unfold let opFlagsOf = IOpIm IOpFlagsOf [@instr_attr] let instr_val_t (o:instr_operand) : Type0 = match o with | IOpEx IOp64 | IOpIm (IOp64One _) -> nat64 | IOpEx IOpXmm | IOpIm (IOpXmmOne _) -> quad32 | IOpIm IOpFlagsCf -> bool | IOpIm IOpFlagsOf -> bool [@instr_attr] let rec instr_ret_t (outs:list instr_out) : Type0 = match outs with | [] -> unit | [(_, o)] -> instr_val_t o | (_, o)::outs -> instr_val_t o & instr_ret_t outs
{ "checked_file": "/", "dependencies": [ "Vale.X64.Machine_s.fst.checked", "Vale.Def.Words_s.fsti.checked", "Vale.Def.Types_s.fst.checked", "prims.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked" ], "interface_file": false, "source_file": "Vale.X64.Instruction_s.fsti" }
[ { "abbrev": false, "full_module": "Vale.X64.Machine_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Types_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 0, "max_fuel": 1, "max_ifuel": 1, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": true, "smtencoding_l_arith_repr": "native", "smtencoding_nl_arith_repr": "wrapped", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [ "smt.arith.nl=false", "smt.QI.EAGER_THRESHOLD=100", "smt.CASE_SPLIT=3" ], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
outs: Prims.list Vale.X64.Instruction_s.instr_out -> args: Prims.list Vale.X64.Instruction_s.instr_operand -> Type0
Prims.Tot
[ "total" ]
[]
[ "Prims.list", "Vale.X64.Instruction_s.instr_out", "Vale.X64.Instruction_s.instr_operand", "FStar.Pervasives.Native.option", "Vale.X64.Instruction_s.instr_ret_t", "Vale.X64.Instruction_s.arrow", "Vale.X64.Instruction_s.instr_val_t", "Vale.X64.Instruction_s.instr_args_t" ]
[ "recursion" ]
false
false
false
true
true
let rec instr_args_t (outs: list instr_out) (args: list instr_operand) : Type0 =
match args with | [] -> option (instr_ret_t outs) | i :: args -> arrow (instr_val_t i) (instr_args_t outs args)
false
Vale.X64.Instruction_s.fsti
Vale.X64.Instruction_s.instr_val_t
val instr_val_t (o: instr_operand) : Type0
val instr_val_t (o: instr_operand) : Type0
let instr_val_t (o:instr_operand) : Type0 = match o with | IOpEx IOp64 | IOpIm (IOp64One _) -> nat64 | IOpEx IOpXmm | IOpIm (IOpXmmOne _) -> quad32 | IOpIm IOpFlagsCf -> bool | IOpIm IOpFlagsOf -> bool
{ "file_name": "vale/specs/hardware/Vale.X64.Instruction_s.fsti", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 28, "end_line": 56, "start_col": 0, "start_line": 51 }
module Vale.X64.Instruction_s open FStar.Mul open Vale.Def.Words_s open Vale.Def.Types_s open Vale.X64.Machine_s (* An generic instruction has: - zero or more input operands - zero or more output operands or input/output operands - a possible effect on the status flags Some of the operands may be hard-coded to a particular register; other operands are flexible. For example, the Intel 64-bit MUL instruction, which executes "(RDX:RAX) := RAX * src" has: - one hard-coded input/output operand, the flags - note: the instruction can havoc the flags in addition to or instead of specifying a flags operand - one hard-coded output operand, RDX - one hard-coded input/output operand, RAX - one flexible input operand (src) *) type instr_operand_inout = | InOut | Out type instr_operand_explicit = // flexible operand | IOp64 : instr_operand_explicit | IOpXmm : instr_operand_explicit type instr_operand_implicit = // hard-coded operand | IOp64One : o:operand64 -> instr_operand_implicit | IOpXmmOne : o:operand128 -> instr_operand_implicit | IOpFlagsCf : instr_operand_implicit | IOpFlagsOf : instr_operand_implicit type instr_operand = | IOpEx : instr_operand_explicit -> instr_operand | IOpIm : instr_operand_implicit -> instr_operand let instr_out = instr_operand_inout & instr_operand irreducible let instr_attr = () unfold let normal (#a:Type) (x:a) : a = norm [zeta; iota; delta_attr [`%instr_attr]] x let arrow (a b:Type) = a -> b [@instr_attr] unfold let coerce (#b #a:Type) (x:a{a == b}) : b = x [@instr_attr] unfold let inOut (o:instr_operand) = (InOut, o) [@instr_attr] unfold let out (o:instr_operand) = (Out, o) [@instr_attr] unfold let op64 = IOpEx IOp64 [@instr_attr] unfold let opXmm = IOpEx IOpXmm [@instr_attr] unfold let one64 (o:operand64) = IOpIm (IOp64One o) [@instr_attr] unfold let one64Reg (r:reg_64) = IOpIm (IOp64One (OReg r)) [@instr_attr] unfold let oneXmm (o:operand128) = IOpIm (IOpXmmOne o) [@instr_attr] unfold let opFlagsCf = IOpIm IOpFlagsCf [@instr_attr] unfold let opFlagsOf = IOpIm IOpFlagsOf
{ "checked_file": "/", "dependencies": [ "Vale.X64.Machine_s.fst.checked", "Vale.Def.Words_s.fsti.checked", "Vale.Def.Types_s.fst.checked", "prims.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked" ], "interface_file": false, "source_file": "Vale.X64.Instruction_s.fsti" }
[ { "abbrev": false, "full_module": "Vale.X64.Machine_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Types_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 0, "max_fuel": 1, "max_ifuel": 1, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": true, "smtencoding_l_arith_repr": "native", "smtencoding_nl_arith_repr": "wrapped", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [ "smt.arith.nl=false", "smt.QI.EAGER_THRESHOLD=100", "smt.CASE_SPLIT=3" ], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
o: Vale.X64.Instruction_s.instr_operand -> Type0
Prims.Tot
[ "total" ]
[]
[ "Vale.X64.Instruction_s.instr_operand", "Vale.X64.Machine_s.nat64", "Vale.X64.Machine_s.operand64", "Vale.X64.Machine_s.quad32", "Vale.X64.Machine_s.operand128", "Prims.bool" ]
[]
false
false
false
true
true
let instr_val_t (o: instr_operand) : Type0 =
match o with | IOpEx IOp64 | IOpIm (IOp64One _) -> nat64 | IOpEx IOpXmm | IOpIm (IOpXmmOne _) -> quad32 | IOpIm IOpFlagsCf -> bool | IOpIm IOpFlagsOf -> bool
false
Vale.X64.Instruction_s.fsti
Vale.X64.Instruction_s.instr_ret_t
val instr_ret_t (outs: list instr_out) : Type0
val instr_ret_t (outs: list instr_out) : Type0
let rec instr_ret_t (outs:list instr_out) : Type0 = match outs with | [] -> unit | [(_, o)] -> instr_val_t o | (_, o)::outs -> instr_val_t o & instr_ret_t outs
{ "file_name": "vale/specs/hardware/Vale.X64.Instruction_s.fsti", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 52, "end_line": 63, "start_col": 0, "start_line": 59 }
module Vale.X64.Instruction_s open FStar.Mul open Vale.Def.Words_s open Vale.Def.Types_s open Vale.X64.Machine_s (* An generic instruction has: - zero or more input operands - zero or more output operands or input/output operands - a possible effect on the status flags Some of the operands may be hard-coded to a particular register; other operands are flexible. For example, the Intel 64-bit MUL instruction, which executes "(RDX:RAX) := RAX * src" has: - one hard-coded input/output operand, the flags - note: the instruction can havoc the flags in addition to or instead of specifying a flags operand - one hard-coded output operand, RDX - one hard-coded input/output operand, RAX - one flexible input operand (src) *) type instr_operand_inout = | InOut | Out type instr_operand_explicit = // flexible operand | IOp64 : instr_operand_explicit | IOpXmm : instr_operand_explicit type instr_operand_implicit = // hard-coded operand | IOp64One : o:operand64 -> instr_operand_implicit | IOpXmmOne : o:operand128 -> instr_operand_implicit | IOpFlagsCf : instr_operand_implicit | IOpFlagsOf : instr_operand_implicit type instr_operand = | IOpEx : instr_operand_explicit -> instr_operand | IOpIm : instr_operand_implicit -> instr_operand let instr_out = instr_operand_inout & instr_operand irreducible let instr_attr = () unfold let normal (#a:Type) (x:a) : a = norm [zeta; iota; delta_attr [`%instr_attr]] x let arrow (a b:Type) = a -> b [@instr_attr] unfold let coerce (#b #a:Type) (x:a{a == b}) : b = x [@instr_attr] unfold let inOut (o:instr_operand) = (InOut, o) [@instr_attr] unfold let out (o:instr_operand) = (Out, o) [@instr_attr] unfold let op64 = IOpEx IOp64 [@instr_attr] unfold let opXmm = IOpEx IOpXmm [@instr_attr] unfold let one64 (o:operand64) = IOpIm (IOp64One o) [@instr_attr] unfold let one64Reg (r:reg_64) = IOpIm (IOp64One (OReg r)) [@instr_attr] unfold let oneXmm (o:operand128) = IOpIm (IOpXmmOne o) [@instr_attr] unfold let opFlagsCf = IOpIm IOpFlagsCf [@instr_attr] unfold let opFlagsOf = IOpIm IOpFlagsOf [@instr_attr] let instr_val_t (o:instr_operand) : Type0 = match o with | IOpEx IOp64 | IOpIm (IOp64One _) -> nat64 | IOpEx IOpXmm | IOpIm (IOpXmmOne _) -> quad32 | IOpIm IOpFlagsCf -> bool | IOpIm IOpFlagsOf -> bool
{ "checked_file": "/", "dependencies": [ "Vale.X64.Machine_s.fst.checked", "Vale.Def.Words_s.fsti.checked", "Vale.Def.Types_s.fst.checked", "prims.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked" ], "interface_file": false, "source_file": "Vale.X64.Instruction_s.fsti" }
[ { "abbrev": false, "full_module": "Vale.X64.Machine_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Types_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 0, "max_fuel": 1, "max_ifuel": 1, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": true, "smtencoding_l_arith_repr": "native", "smtencoding_nl_arith_repr": "wrapped", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [ "smt.arith.nl=false", "smt.QI.EAGER_THRESHOLD=100", "smt.CASE_SPLIT=3" ], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
outs: Prims.list Vale.X64.Instruction_s.instr_out -> Type0
Prims.Tot
[ "total" ]
[]
[ "Prims.list", "Vale.X64.Instruction_s.instr_out", "Prims.unit", "Vale.X64.Instruction_s.instr_operand_inout", "Vale.X64.Instruction_s.instr_operand", "Vale.X64.Instruction_s.instr_val_t", "FStar.Pervasives.Native.tuple2", "Vale.X64.Instruction_s.instr_ret_t" ]
[ "recursion" ]
false
false
false
true
true
let rec instr_ret_t (outs: list instr_out) : Type0 =
match outs with | [] -> unit | [_, o] -> instr_val_t o | (_, o) :: outs -> instr_val_t o & instr_ret_t outs
false
Vale.X64.Instruction_s.fsti
Vale.X64.Instruction_s.instr_inouts_t
val instr_inouts_t (outs inouts: list instr_out) (args: list instr_operand) : Type0
val instr_inouts_t (outs inouts: list instr_out) (args: list instr_operand) : Type0
let rec instr_inouts_t (outs inouts:list instr_out) (args:list instr_operand) : Type0 = match inouts with | [] -> instr_args_t outs args | (Out, _)::inouts -> instr_inouts_t outs inouts args | (InOut, i)::inouts -> arrow (instr_val_t i) (instr_inouts_t outs inouts args)
{ "file_name": "vale/specs/hardware/Vale.X64.Instruction_s.fsti", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 81, "end_line": 76, "start_col": 0, "start_line": 72 }
module Vale.X64.Instruction_s open FStar.Mul open Vale.Def.Words_s open Vale.Def.Types_s open Vale.X64.Machine_s (* An generic instruction has: - zero or more input operands - zero or more output operands or input/output operands - a possible effect on the status flags Some of the operands may be hard-coded to a particular register; other operands are flexible. For example, the Intel 64-bit MUL instruction, which executes "(RDX:RAX) := RAX * src" has: - one hard-coded input/output operand, the flags - note: the instruction can havoc the flags in addition to or instead of specifying a flags operand - one hard-coded output operand, RDX - one hard-coded input/output operand, RAX - one flexible input operand (src) *) type instr_operand_inout = | InOut | Out type instr_operand_explicit = // flexible operand | IOp64 : instr_operand_explicit | IOpXmm : instr_operand_explicit type instr_operand_implicit = // hard-coded operand | IOp64One : o:operand64 -> instr_operand_implicit | IOpXmmOne : o:operand128 -> instr_operand_implicit | IOpFlagsCf : instr_operand_implicit | IOpFlagsOf : instr_operand_implicit type instr_operand = | IOpEx : instr_operand_explicit -> instr_operand | IOpIm : instr_operand_implicit -> instr_operand let instr_out = instr_operand_inout & instr_operand irreducible let instr_attr = () unfold let normal (#a:Type) (x:a) : a = norm [zeta; iota; delta_attr [`%instr_attr]] x let arrow (a b:Type) = a -> b [@instr_attr] unfold let coerce (#b #a:Type) (x:a{a == b}) : b = x [@instr_attr] unfold let inOut (o:instr_operand) = (InOut, o) [@instr_attr] unfold let out (o:instr_operand) = (Out, o) [@instr_attr] unfold let op64 = IOpEx IOp64 [@instr_attr] unfold let opXmm = IOpEx IOpXmm [@instr_attr] unfold let one64 (o:operand64) = IOpIm (IOp64One o) [@instr_attr] unfold let one64Reg (r:reg_64) = IOpIm (IOp64One (OReg r)) [@instr_attr] unfold let oneXmm (o:operand128) = IOpIm (IOpXmmOne o) [@instr_attr] unfold let opFlagsCf = IOpIm IOpFlagsCf [@instr_attr] unfold let opFlagsOf = IOpIm IOpFlagsOf [@instr_attr] let instr_val_t (o:instr_operand) : Type0 = match o with | IOpEx IOp64 | IOpIm (IOp64One _) -> nat64 | IOpEx IOpXmm | IOpIm (IOpXmmOne _) -> quad32 | IOpIm IOpFlagsCf -> bool | IOpIm IOpFlagsOf -> bool [@instr_attr] let rec instr_ret_t (outs:list instr_out) : Type0 = match outs with | [] -> unit | [(_, o)] -> instr_val_t o | (_, o)::outs -> instr_val_t o & instr_ret_t outs [@instr_attr] let rec instr_args_t (outs:list instr_out) (args:list instr_operand) : Type0 = match args with | [] -> option (instr_ret_t outs) | i::args -> arrow (instr_val_t i) (instr_args_t outs args)
{ "checked_file": "/", "dependencies": [ "Vale.X64.Machine_s.fst.checked", "Vale.Def.Words_s.fsti.checked", "Vale.Def.Types_s.fst.checked", "prims.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked" ], "interface_file": false, "source_file": "Vale.X64.Instruction_s.fsti" }
[ { "abbrev": false, "full_module": "Vale.X64.Machine_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Types_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 0, "max_fuel": 1, "max_ifuel": 1, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": true, "smtencoding_l_arith_repr": "native", "smtencoding_nl_arith_repr": "wrapped", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [ "smt.arith.nl=false", "smt.QI.EAGER_THRESHOLD=100", "smt.CASE_SPLIT=3" ], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
outs: Prims.list Vale.X64.Instruction_s.instr_out -> inouts: Prims.list Vale.X64.Instruction_s.instr_out -> args: Prims.list Vale.X64.Instruction_s.instr_operand -> Type0
Prims.Tot
[ "total" ]
[]
[ "Prims.list", "Vale.X64.Instruction_s.instr_out", "Vale.X64.Instruction_s.instr_operand", "Vale.X64.Instruction_s.instr_args_t", "Vale.X64.Instruction_s.instr_inouts_t", "Vale.X64.Instruction_s.arrow", "Vale.X64.Instruction_s.instr_val_t" ]
[ "recursion" ]
false
false
false
true
true
let rec instr_inouts_t (outs inouts: list instr_out) (args: list instr_operand) : Type0 =
match inouts with | [] -> instr_args_t outs args | (Out, _) :: inouts -> instr_inouts_t outs inouts args | (InOut, i) :: inouts -> arrow (instr_val_t i) (instr_inouts_t outs inouts args)
false
Vale.X64.Instruction_s.fsti
Vale.X64.Instruction_s.instr_operand_t
val instr_operand_t (arg: instr_operand_explicit) : Type0
val instr_operand_t (arg: instr_operand_explicit) : Type0
let instr_operand_t (arg:instr_operand_explicit) : Type0 = match arg with | IOp64 -> operand64 | IOpXmm -> operand128
{ "file_name": "vale/specs/hardware/Vale.X64.Instruction_s.fsti", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 24, "end_line": 91, "start_col": 0, "start_line": 88 }
module Vale.X64.Instruction_s open FStar.Mul open Vale.Def.Words_s open Vale.Def.Types_s open Vale.X64.Machine_s (* An generic instruction has: - zero or more input operands - zero or more output operands or input/output operands - a possible effect on the status flags Some of the operands may be hard-coded to a particular register; other operands are flexible. For example, the Intel 64-bit MUL instruction, which executes "(RDX:RAX) := RAX * src" has: - one hard-coded input/output operand, the flags - note: the instruction can havoc the flags in addition to or instead of specifying a flags operand - one hard-coded output operand, RDX - one hard-coded input/output operand, RAX - one flexible input operand (src) *) type instr_operand_inout = | InOut | Out type instr_operand_explicit = // flexible operand | IOp64 : instr_operand_explicit | IOpXmm : instr_operand_explicit type instr_operand_implicit = // hard-coded operand | IOp64One : o:operand64 -> instr_operand_implicit | IOpXmmOne : o:operand128 -> instr_operand_implicit | IOpFlagsCf : instr_operand_implicit | IOpFlagsOf : instr_operand_implicit type instr_operand = | IOpEx : instr_operand_explicit -> instr_operand | IOpIm : instr_operand_implicit -> instr_operand let instr_out = instr_operand_inout & instr_operand irreducible let instr_attr = () unfold let normal (#a:Type) (x:a) : a = norm [zeta; iota; delta_attr [`%instr_attr]] x let arrow (a b:Type) = a -> b [@instr_attr] unfold let coerce (#b #a:Type) (x:a{a == b}) : b = x [@instr_attr] unfold let inOut (o:instr_operand) = (InOut, o) [@instr_attr] unfold let out (o:instr_operand) = (Out, o) [@instr_attr] unfold let op64 = IOpEx IOp64 [@instr_attr] unfold let opXmm = IOpEx IOpXmm [@instr_attr] unfold let one64 (o:operand64) = IOpIm (IOp64One o) [@instr_attr] unfold let one64Reg (r:reg_64) = IOpIm (IOp64One (OReg r)) [@instr_attr] unfold let oneXmm (o:operand128) = IOpIm (IOpXmmOne o) [@instr_attr] unfold let opFlagsCf = IOpIm IOpFlagsCf [@instr_attr] unfold let opFlagsOf = IOpIm IOpFlagsOf [@instr_attr] let instr_val_t (o:instr_operand) : Type0 = match o with | IOpEx IOp64 | IOpIm (IOp64One _) -> nat64 | IOpEx IOpXmm | IOpIm (IOpXmmOne _) -> quad32 | IOpIm IOpFlagsCf -> bool | IOpIm IOpFlagsOf -> bool [@instr_attr] let rec instr_ret_t (outs:list instr_out) : Type0 = match outs with | [] -> unit | [(_, o)] -> instr_val_t o | (_, o)::outs -> instr_val_t o & instr_ret_t outs [@instr_attr] let rec instr_args_t (outs:list instr_out) (args:list instr_operand) : Type0 = match args with | [] -> option (instr_ret_t outs) | i::args -> arrow (instr_val_t i) (instr_args_t outs args) [@instr_attr] let rec instr_inouts_t (outs inouts:list instr_out) (args:list instr_operand) : Type0 = match inouts with | [] -> instr_args_t outs args | (Out, _)::inouts -> instr_inouts_t outs inouts args | (InOut, i)::inouts -> arrow (instr_val_t i) (instr_inouts_t outs inouts args) (* An instr evaluator is a function of type: in_outs1 ... -> in_outsi -> args1 -> ...> argsj -> (outs1 & (... & outsk) ...) where in_outs = [(b, o) in outs | b = InOut] *) [@instr_attr] let instr_eval_t (outs:list instr_out) (args:list instr_operand) : Type0 = instr_inouts_t outs outs args
{ "checked_file": "/", "dependencies": [ "Vale.X64.Machine_s.fst.checked", "Vale.Def.Words_s.fsti.checked", "Vale.Def.Types_s.fst.checked", "prims.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked" ], "interface_file": false, "source_file": "Vale.X64.Instruction_s.fsti" }
[ { "abbrev": false, "full_module": "Vale.X64.Machine_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Types_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 0, "max_fuel": 1, "max_ifuel": 1, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": true, "smtencoding_l_arith_repr": "native", "smtencoding_nl_arith_repr": "wrapped", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [ "smt.arith.nl=false", "smt.QI.EAGER_THRESHOLD=100", "smt.CASE_SPLIT=3" ], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
arg: Vale.X64.Instruction_s.instr_operand_explicit -> Type0
Prims.Tot
[ "total" ]
[]
[ "Vale.X64.Instruction_s.instr_operand_explicit", "Vale.X64.Machine_s.operand64", "Vale.X64.Machine_s.operand128" ]
[]
false
false
false
true
true
let instr_operand_t (arg: instr_operand_explicit) : Type0 =
match arg with | IOp64 -> operand64 | IOpXmm -> operand128
false
Vale.X64.Instruction_s.fsti
Vale.X64.Instruction_s.instr_operands_t_args
val instr_operands_t_args (args: list instr_operand) : Type0
val instr_operands_t_args (args: list instr_operand) : Type0
let rec instr_operands_t_args (args:list instr_operand) : Type0 = match args with | [] -> unit | (IOpEx i)::args -> instr_operand_t i & instr_operands_t_args args | (IOpIm _)::args -> instr_operands_t_args args
{ "file_name": "vale/specs/hardware/Vale.X64.Instruction_s.fsti", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 49, "end_line": 98, "start_col": 0, "start_line": 94 }
module Vale.X64.Instruction_s open FStar.Mul open Vale.Def.Words_s open Vale.Def.Types_s open Vale.X64.Machine_s (* An generic instruction has: - zero or more input operands - zero or more output operands or input/output operands - a possible effect on the status flags Some of the operands may be hard-coded to a particular register; other operands are flexible. For example, the Intel 64-bit MUL instruction, which executes "(RDX:RAX) := RAX * src" has: - one hard-coded input/output operand, the flags - note: the instruction can havoc the flags in addition to or instead of specifying a flags operand - one hard-coded output operand, RDX - one hard-coded input/output operand, RAX - one flexible input operand (src) *) type instr_operand_inout = | InOut | Out type instr_operand_explicit = // flexible operand | IOp64 : instr_operand_explicit | IOpXmm : instr_operand_explicit type instr_operand_implicit = // hard-coded operand | IOp64One : o:operand64 -> instr_operand_implicit | IOpXmmOne : o:operand128 -> instr_operand_implicit | IOpFlagsCf : instr_operand_implicit | IOpFlagsOf : instr_operand_implicit type instr_operand = | IOpEx : instr_operand_explicit -> instr_operand | IOpIm : instr_operand_implicit -> instr_operand let instr_out = instr_operand_inout & instr_operand irreducible let instr_attr = () unfold let normal (#a:Type) (x:a) : a = norm [zeta; iota; delta_attr [`%instr_attr]] x let arrow (a b:Type) = a -> b [@instr_attr] unfold let coerce (#b #a:Type) (x:a{a == b}) : b = x [@instr_attr] unfold let inOut (o:instr_operand) = (InOut, o) [@instr_attr] unfold let out (o:instr_operand) = (Out, o) [@instr_attr] unfold let op64 = IOpEx IOp64 [@instr_attr] unfold let opXmm = IOpEx IOpXmm [@instr_attr] unfold let one64 (o:operand64) = IOpIm (IOp64One o) [@instr_attr] unfold let one64Reg (r:reg_64) = IOpIm (IOp64One (OReg r)) [@instr_attr] unfold let oneXmm (o:operand128) = IOpIm (IOpXmmOne o) [@instr_attr] unfold let opFlagsCf = IOpIm IOpFlagsCf [@instr_attr] unfold let opFlagsOf = IOpIm IOpFlagsOf [@instr_attr] let instr_val_t (o:instr_operand) : Type0 = match o with | IOpEx IOp64 | IOpIm (IOp64One _) -> nat64 | IOpEx IOpXmm | IOpIm (IOpXmmOne _) -> quad32 | IOpIm IOpFlagsCf -> bool | IOpIm IOpFlagsOf -> bool [@instr_attr] let rec instr_ret_t (outs:list instr_out) : Type0 = match outs with | [] -> unit | [(_, o)] -> instr_val_t o | (_, o)::outs -> instr_val_t o & instr_ret_t outs [@instr_attr] let rec instr_args_t (outs:list instr_out) (args:list instr_operand) : Type0 = match args with | [] -> option (instr_ret_t outs) | i::args -> arrow (instr_val_t i) (instr_args_t outs args) [@instr_attr] let rec instr_inouts_t (outs inouts:list instr_out) (args:list instr_operand) : Type0 = match inouts with | [] -> instr_args_t outs args | (Out, _)::inouts -> instr_inouts_t outs inouts args | (InOut, i)::inouts -> arrow (instr_val_t i) (instr_inouts_t outs inouts args) (* An instr evaluator is a function of type: in_outs1 ... -> in_outsi -> args1 -> ...> argsj -> (outs1 & (... & outsk) ...) where in_outs = [(b, o) in outs | b = InOut] *) [@instr_attr] let instr_eval_t (outs:list instr_out) (args:list instr_operand) : Type0 = instr_inouts_t outs outs args [@instr_attr] let instr_operand_t (arg:instr_operand_explicit) : Type0 = match arg with | IOp64 -> operand64 | IOpXmm -> operand128
{ "checked_file": "/", "dependencies": [ "Vale.X64.Machine_s.fst.checked", "Vale.Def.Words_s.fsti.checked", "Vale.Def.Types_s.fst.checked", "prims.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked" ], "interface_file": false, "source_file": "Vale.X64.Instruction_s.fsti" }
[ { "abbrev": false, "full_module": "Vale.X64.Machine_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Types_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 0, "max_fuel": 1, "max_ifuel": 1, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": true, "smtencoding_l_arith_repr": "native", "smtencoding_nl_arith_repr": "wrapped", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [ "smt.arith.nl=false", "smt.QI.EAGER_THRESHOLD=100", "smt.CASE_SPLIT=3" ], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
args: Prims.list Vale.X64.Instruction_s.instr_operand -> Type0
Prims.Tot
[ "total" ]
[]
[ "Prims.list", "Vale.X64.Instruction_s.instr_operand", "Prims.unit", "Vale.X64.Instruction_s.instr_operand_explicit", "FStar.Pervasives.Native.tuple2", "Vale.X64.Instruction_s.instr_operand_t", "Vale.X64.Instruction_s.instr_operands_t_args", "Vale.X64.Instruction_s.instr_operand_implicit" ]
[ "recursion" ]
false
false
false
true
true
let rec instr_operands_t_args (args: list instr_operand) : Type0 =
match args with | [] -> unit | IOpEx i :: args -> instr_operand_t i & instr_operands_t_args args | IOpIm _ :: args -> instr_operands_t_args args
false
Vale.X64.Instruction_s.fsti
Vale.X64.Instruction_s.instr_operands_t
val instr_operands_t (outs: list instr_out) (args: list instr_operand) : Type0
val instr_operands_t (outs: list instr_out) (args: list instr_operand) : Type0
let rec instr_operands_t (outs:list instr_out) (args:list instr_operand) : Type0 = match outs with | [] -> instr_operands_t_args args | (_, IOpEx i)::outs -> instr_operand_t i & instr_operands_t outs args | (_, IOpIm _)::outs -> instr_operands_t outs args
{ "file_name": "vale/specs/hardware/Vale.X64.Instruction_s.fsti", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 52, "end_line": 105, "start_col": 0, "start_line": 101 }
module Vale.X64.Instruction_s open FStar.Mul open Vale.Def.Words_s open Vale.Def.Types_s open Vale.X64.Machine_s (* An generic instruction has: - zero or more input operands - zero or more output operands or input/output operands - a possible effect on the status flags Some of the operands may be hard-coded to a particular register; other operands are flexible. For example, the Intel 64-bit MUL instruction, which executes "(RDX:RAX) := RAX * src" has: - one hard-coded input/output operand, the flags - note: the instruction can havoc the flags in addition to or instead of specifying a flags operand - one hard-coded output operand, RDX - one hard-coded input/output operand, RAX - one flexible input operand (src) *) type instr_operand_inout = | InOut | Out type instr_operand_explicit = // flexible operand | IOp64 : instr_operand_explicit | IOpXmm : instr_operand_explicit type instr_operand_implicit = // hard-coded operand | IOp64One : o:operand64 -> instr_operand_implicit | IOpXmmOne : o:operand128 -> instr_operand_implicit | IOpFlagsCf : instr_operand_implicit | IOpFlagsOf : instr_operand_implicit type instr_operand = | IOpEx : instr_operand_explicit -> instr_operand | IOpIm : instr_operand_implicit -> instr_operand let instr_out = instr_operand_inout & instr_operand irreducible let instr_attr = () unfold let normal (#a:Type) (x:a) : a = norm [zeta; iota; delta_attr [`%instr_attr]] x let arrow (a b:Type) = a -> b [@instr_attr] unfold let coerce (#b #a:Type) (x:a{a == b}) : b = x [@instr_attr] unfold let inOut (o:instr_operand) = (InOut, o) [@instr_attr] unfold let out (o:instr_operand) = (Out, o) [@instr_attr] unfold let op64 = IOpEx IOp64 [@instr_attr] unfold let opXmm = IOpEx IOpXmm [@instr_attr] unfold let one64 (o:operand64) = IOpIm (IOp64One o) [@instr_attr] unfold let one64Reg (r:reg_64) = IOpIm (IOp64One (OReg r)) [@instr_attr] unfold let oneXmm (o:operand128) = IOpIm (IOpXmmOne o) [@instr_attr] unfold let opFlagsCf = IOpIm IOpFlagsCf [@instr_attr] unfold let opFlagsOf = IOpIm IOpFlagsOf [@instr_attr] let instr_val_t (o:instr_operand) : Type0 = match o with | IOpEx IOp64 | IOpIm (IOp64One _) -> nat64 | IOpEx IOpXmm | IOpIm (IOpXmmOne _) -> quad32 | IOpIm IOpFlagsCf -> bool | IOpIm IOpFlagsOf -> bool [@instr_attr] let rec instr_ret_t (outs:list instr_out) : Type0 = match outs with | [] -> unit | [(_, o)] -> instr_val_t o | (_, o)::outs -> instr_val_t o & instr_ret_t outs [@instr_attr] let rec instr_args_t (outs:list instr_out) (args:list instr_operand) : Type0 = match args with | [] -> option (instr_ret_t outs) | i::args -> arrow (instr_val_t i) (instr_args_t outs args) [@instr_attr] let rec instr_inouts_t (outs inouts:list instr_out) (args:list instr_operand) : Type0 = match inouts with | [] -> instr_args_t outs args | (Out, _)::inouts -> instr_inouts_t outs inouts args | (InOut, i)::inouts -> arrow (instr_val_t i) (instr_inouts_t outs inouts args) (* An instr evaluator is a function of type: in_outs1 ... -> in_outsi -> args1 -> ...> argsj -> (outs1 & (... & outsk) ...) where in_outs = [(b, o) in outs | b = InOut] *) [@instr_attr] let instr_eval_t (outs:list instr_out) (args:list instr_operand) : Type0 = instr_inouts_t outs outs args [@instr_attr] let instr_operand_t (arg:instr_operand_explicit) : Type0 = match arg with | IOp64 -> operand64 | IOpXmm -> operand128 [@instr_attr] let rec instr_operands_t_args (args:list instr_operand) : Type0 = match args with | [] -> unit | (IOpEx i)::args -> instr_operand_t i & instr_operands_t_args args | (IOpIm _)::args -> instr_operands_t_args args
{ "checked_file": "/", "dependencies": [ "Vale.X64.Machine_s.fst.checked", "Vale.Def.Words_s.fsti.checked", "Vale.Def.Types_s.fst.checked", "prims.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked" ], "interface_file": false, "source_file": "Vale.X64.Instruction_s.fsti" }
[ { "abbrev": false, "full_module": "Vale.X64.Machine_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Types_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 0, "max_fuel": 1, "max_ifuel": 1, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": true, "smtencoding_l_arith_repr": "native", "smtencoding_nl_arith_repr": "wrapped", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [ "smt.arith.nl=false", "smt.QI.EAGER_THRESHOLD=100", "smt.CASE_SPLIT=3" ], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
outs: Prims.list Vale.X64.Instruction_s.instr_out -> args: Prims.list Vale.X64.Instruction_s.instr_operand -> Type0
Prims.Tot
[ "total" ]
[]
[ "Prims.list", "Vale.X64.Instruction_s.instr_out", "Vale.X64.Instruction_s.instr_operand", "Vale.X64.Instruction_s.instr_operands_t_args", "Vale.X64.Instruction_s.instr_operand_inout", "Vale.X64.Instruction_s.instr_operand_explicit", "FStar.Pervasives.Native.tuple2", "Vale.X64.Instruction_s.instr_operand_t", "Vale.X64.Instruction_s.instr_operands_t", "Vale.X64.Instruction_s.instr_operand_implicit" ]
[ "recursion" ]
false
false
false
true
true
let rec instr_operands_t (outs: list instr_out) (args: list instr_operand) : Type0 =
match outs with | [] -> instr_operands_t_args args | (_, IOpEx i) :: outs -> instr_operand_t i & instr_operands_t outs args | (_, IOpIm _) :: outs -> instr_operands_t outs args
false
Vale.X64.Instruction_s.fsti
Vale.X64.Instruction_s.instr_dep
val instr_dep (outs: list instr_out) (args: list instr_operand) (havoc_flags: flag_havoc) (f: normal (instr_eval_t outs args)) : Type0
val instr_dep (outs: list instr_out) (args: list instr_operand) (havoc_flags: flag_havoc) (f: normal (instr_eval_t outs args)) : Type0
let instr_dep (outs:list instr_out) (args:list instr_operand) (havoc_flags:flag_havoc) (f:normal (instr_eval_t outs args)) : Type0 = i:(instr_t outs args havoc_flags){instr_eval i == f}
{ "file_name": "vale/specs/hardware/Vale.X64.Instruction_s.fsti", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 54, "end_line": 160, "start_col": 0, "start_line": 156 }
module Vale.X64.Instruction_s open FStar.Mul open Vale.Def.Words_s open Vale.Def.Types_s open Vale.X64.Machine_s (* An generic instruction has: - zero or more input operands - zero or more output operands or input/output operands - a possible effect on the status flags Some of the operands may be hard-coded to a particular register; other operands are flexible. For example, the Intel 64-bit MUL instruction, which executes "(RDX:RAX) := RAX * src" has: - one hard-coded input/output operand, the flags - note: the instruction can havoc the flags in addition to or instead of specifying a flags operand - one hard-coded output operand, RDX - one hard-coded input/output operand, RAX - one flexible input operand (src) *) type instr_operand_inout = | InOut | Out type instr_operand_explicit = // flexible operand | IOp64 : instr_operand_explicit | IOpXmm : instr_operand_explicit type instr_operand_implicit = // hard-coded operand | IOp64One : o:operand64 -> instr_operand_implicit | IOpXmmOne : o:operand128 -> instr_operand_implicit | IOpFlagsCf : instr_operand_implicit | IOpFlagsOf : instr_operand_implicit type instr_operand = | IOpEx : instr_operand_explicit -> instr_operand | IOpIm : instr_operand_implicit -> instr_operand let instr_out = instr_operand_inout & instr_operand irreducible let instr_attr = () unfold let normal (#a:Type) (x:a) : a = norm [zeta; iota; delta_attr [`%instr_attr]] x let arrow (a b:Type) = a -> b [@instr_attr] unfold let coerce (#b #a:Type) (x:a{a == b}) : b = x [@instr_attr] unfold let inOut (o:instr_operand) = (InOut, o) [@instr_attr] unfold let out (o:instr_operand) = (Out, o) [@instr_attr] unfold let op64 = IOpEx IOp64 [@instr_attr] unfold let opXmm = IOpEx IOpXmm [@instr_attr] unfold let one64 (o:operand64) = IOpIm (IOp64One o) [@instr_attr] unfold let one64Reg (r:reg_64) = IOpIm (IOp64One (OReg r)) [@instr_attr] unfold let oneXmm (o:operand128) = IOpIm (IOpXmmOne o) [@instr_attr] unfold let opFlagsCf = IOpIm IOpFlagsCf [@instr_attr] unfold let opFlagsOf = IOpIm IOpFlagsOf [@instr_attr] let instr_val_t (o:instr_operand) : Type0 = match o with | IOpEx IOp64 | IOpIm (IOp64One _) -> nat64 | IOpEx IOpXmm | IOpIm (IOpXmmOne _) -> quad32 | IOpIm IOpFlagsCf -> bool | IOpIm IOpFlagsOf -> bool [@instr_attr] let rec instr_ret_t (outs:list instr_out) : Type0 = match outs with | [] -> unit | [(_, o)] -> instr_val_t o | (_, o)::outs -> instr_val_t o & instr_ret_t outs [@instr_attr] let rec instr_args_t (outs:list instr_out) (args:list instr_operand) : Type0 = match args with | [] -> option (instr_ret_t outs) | i::args -> arrow (instr_val_t i) (instr_args_t outs args) [@instr_attr] let rec instr_inouts_t (outs inouts:list instr_out) (args:list instr_operand) : Type0 = match inouts with | [] -> instr_args_t outs args | (Out, _)::inouts -> instr_inouts_t outs inouts args | (InOut, i)::inouts -> arrow (instr_val_t i) (instr_inouts_t outs inouts args) (* An instr evaluator is a function of type: in_outs1 ... -> in_outsi -> args1 -> ...> argsj -> (outs1 & (... & outsk) ...) where in_outs = [(b, o) in outs | b = InOut] *) [@instr_attr] let instr_eval_t (outs:list instr_out) (args:list instr_operand) : Type0 = instr_inouts_t outs outs args [@instr_attr] let instr_operand_t (arg:instr_operand_explicit) : Type0 = match arg with | IOp64 -> operand64 | IOpXmm -> operand128 [@instr_attr] let rec instr_operands_t_args (args:list instr_operand) : Type0 = match args with | [] -> unit | (IOpEx i)::args -> instr_operand_t i & instr_operands_t_args args | (IOpIm _)::args -> instr_operands_t_args args [@instr_attr] let rec instr_operands_t (outs:list instr_out) (args:list instr_operand) : Type0 = match outs with | [] -> instr_operands_t_args args | (_, IOpEx i)::outs -> instr_operand_t i & instr_operands_t outs args | (_, IOpIm _)::outs -> instr_operands_t outs args (* The printed syntax may be different from the underlying semantics, so we have a separate data type to represent operand syntax. The print operands are listed in Intel/MASM order (destination operand listed first). *) type instr_print_operand = | P8 : operand64 -> instr_print_operand | P16 : operand64 -> instr_print_operand | P32 : operand64 -> instr_print_operand | P64 : operand64 -> instr_print_operand | PXmm : operand128 -> instr_print_operand | PImm : int -> instr_print_operand | PShift : operand64 -> instr_print_operand type instr_print_kind = | POpcode | PSuffix // add suffix character to opcode for GCC/ATT syntax | PrintPSha256rnds2 type instr_print = | Print : string -> instr_print_kind -> list instr_print_operand -> instr_print type flag_havoc = | HavocFlags | PreserveFlags (* This type is abstract so that untrusted code can't invent nonexistent instruction semantics out of thin air. (Only trusted instruction definitions can create new values of this type.) The arguments (outs, args, havoc_flags), together with a function instr_eval, determine the semantics. *) val instr_t (outs:list instr_out) (args:list instr_operand) (havoc_flags:flag_havoc) : Type0 noeq type instr_t_record = | InstrTypeRecord : #outs:list instr_out -> #args:list instr_operand -> #havoc_flags:flag_havoc -> i:instr_t outs args havoc_flags -> instr_t_record val instr_eval (#outs:list instr_out) (#args:list instr_operand) (#havoc_flags:flag_havoc) (i:instr_t outs args havoc_flags) // : normal (instr_eval_t outs args) : norm [zeta; iota; delta_attr [`%instr_attr]] (instr_eval_t outs args) val instr_printer (#outs:list instr_out) (#args:list instr_operand) (#havoc_flags:flag_havoc) (i:instr_t outs args havoc_flags) (oprs:normal (instr_operands_t outs args)) : instr_print
{ "checked_file": "/", "dependencies": [ "Vale.X64.Machine_s.fst.checked", "Vale.Def.Words_s.fsti.checked", "Vale.Def.Types_s.fst.checked", "prims.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked" ], "interface_file": false, "source_file": "Vale.X64.Instruction_s.fsti" }
[ { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Machine_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Types_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 0, "max_fuel": 1, "max_ifuel": 1, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": true, "smtencoding_l_arith_repr": "native", "smtencoding_nl_arith_repr": "wrapped", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [ "smt.arith.nl=false", "smt.QI.EAGER_THRESHOLD=100", "smt.CASE_SPLIT=3" ], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
outs: Prims.list Vale.X64.Instruction_s.instr_out -> args: Prims.list Vale.X64.Instruction_s.instr_operand -> havoc_flags: Vale.X64.Instruction_s.flag_havoc -> f: Vale.X64.Instruction_s.normal (Vale.X64.Instruction_s.instr_eval_t outs args) -> Type0
Prims.Tot
[ "total" ]
[]
[ "Prims.list", "Vale.X64.Instruction_s.instr_out", "Vale.X64.Instruction_s.instr_operand", "Vale.X64.Instruction_s.flag_havoc", "Vale.X64.Instruction_s.normal", "Vale.X64.Instruction_s.instr_eval_t", "Vale.X64.Instruction_s.instr_t", "Prims.eq2", "Vale.X64.Instruction_s.instr_args_t", "Vale.X64.Instruction_s.instr_inouts_t", "Vale.X64.Instruction_s.arrow", "Vale.X64.Instruction_s.instr_val_t", "Vale.X64.Instruction_s.instr_eval" ]
[]
false
false
false
false
true
let instr_dep (outs: list instr_out) (args: list instr_operand) (havoc_flags: flag_havoc) (f: normal (instr_eval_t outs args)) : Type0 =
i: (instr_t outs args havoc_flags){instr_eval i == f}
false
Vale.X64.Lemmas.fst
Vale.X64.Lemmas.eval_code_eq_pop
val eval_code_eq_pop (inst: BS.ins) (f: fuel) (s1 s2: machine_state) : Lemma (requires Pop? inst /\ state_eq_S true s1 s2) (ensures state_eq_opt true (BS.machine_eval_code (Ins inst) f s1) (BS.machine_eval_code (Ins inst) f s2))
val eval_code_eq_pop (inst: BS.ins) (f: fuel) (s1 s2: machine_state) : Lemma (requires Pop? inst /\ state_eq_S true s1 s2) (ensures state_eq_opt true (BS.machine_eval_code (Ins inst) f s1) (BS.machine_eval_code (Ins inst) f s2))
let eval_code_eq_pop (inst:BS.ins) (f:fuel) (s1 s2:machine_state) : Lemma (requires Pop? inst /\ state_eq_S true s1 s2) (ensures state_eq_opt true (BS.machine_eval_code (Ins inst) f s1) (BS.machine_eval_code (Ins inst) f s2)) = reveal_opaque (`%BS.machine_eval_code_ins) BS.machine_eval_code_ins; use_machine_state_equal (); lemma_heap_ignore_ghost_machine s1.BS.ms_heap s2.BS.ms_heap; allow_inversion tmaddr
{ "file_name": "vale/code/arch/x64/Vale.X64.Lemmas.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 24, "end_line": 177, "start_col": 0, "start_line": 170 }
module Vale.X64.Lemmas open FStar.Mul open Vale.X64.Machine_s open Vale.X64.State open Vale.X64.StateLemmas open Vale.X64.Instruction_s open Vale.X64.Bytes_Code_s module BS = Vale.X64.Machine_Semantics_s module ME = Vale.X64.Memory #reset-options "--initial_fuel 1 --max_fuel 1 --z3rlimit 100" #restart-solver let rec lemma_eq_instr_apply_eval_args (outs:list instr_out) (args:list instr_operand) (f:instr_args_t outs args) (oprs:instr_operands_t_args args) (s1 s2:machine_state) : Lemma (requires state_eq_S true s1 s2) (ensures BS.instr_apply_eval_args outs args f oprs s1 == BS.instr_apply_eval_args outs args f oprs s2) = let open BS in lemma_heap_ignore_ghost_machine s1.BS.ms_heap s2.BS.ms_heap; match args with | [] -> () | i::args -> ( let (v, oprs) : option (instr_val_t i) & instr_operands_t_args args = match i with | IOpEx i -> let oprs = coerce oprs in (instr_eval_operand_explicit i (fst oprs) s1, snd oprs) | IOpIm i -> (instr_eval_operand_implicit i s1, coerce oprs) in let f:arrow (instr_val_t i) (instr_args_t outs args) = coerce f in match v with | None -> () | Some v -> lemma_eq_instr_apply_eval_args outs args (f v) oprs s1 s2 ) #restart-solver let rec lemma_eq_instr_apply_eval_inouts (outs inouts:list instr_out) (args:list instr_operand) (f:instr_inouts_t outs inouts args) (oprs:instr_operands_t inouts args) (s1 s2:machine_state) : Lemma (requires state_eq_S true s1 s2) (ensures BS.instr_apply_eval_inouts outs inouts args f oprs s1 == BS.instr_apply_eval_inouts outs inouts args f oprs s2) = let open BS in lemma_heap_ignore_ghost_machine s1.BS.ms_heap s2.BS.ms_heap; match inouts with | [] -> lemma_eq_instr_apply_eval_args outs args f oprs s1 s2 | (Out, i)::inouts -> let oprs = match i with | IOpEx i -> snd #(instr_operand_t i) (coerce oprs) | IOpIm i -> coerce oprs in lemma_eq_instr_apply_eval_inouts outs inouts args (coerce f) oprs s1 s2 | (InOut, i)::inouts -> ( let (v, oprs) : option (instr_val_t i) & instr_operands_t inouts args = match i with | IOpEx i -> let oprs = coerce oprs in (instr_eval_operand_explicit i (fst oprs) s1, snd oprs) | IOpIm i -> (instr_eval_operand_implicit i s1, coerce oprs) in let f:arrow (instr_val_t i) (instr_inouts_t outs inouts args) = coerce f in match v with | None -> () | Some v -> lemma_eq_instr_apply_eval_inouts outs inouts args (f v) oprs s1 s2 ) #restart-solver #push-options "--z3rlimit_factor 2" let rec lemma_eq_instr_write_outputs (outs:list instr_out) (args:list instr_operand) (vs:instr_ret_t outs) (oprs:instr_operands_t outs args) (s1_orig s1 s2_orig s2:machine_state) : Lemma (requires state_eq_S true s1_orig s2_orig /\ state_eq_S true s1 s2) (ensures state_eq_S true (BS.instr_write_outputs outs args vs oprs s1_orig s1) (BS.instr_write_outputs outs args vs oprs s2_orig s2)) = let open BS in use_machine_state_equal (); lemma_heap_ignore_ghost_machine s1.BS.ms_heap s2.BS.ms_heap; lemma_heap_ignore_ghost_machine s1_orig.BS.ms_heap s2_orig.BS.ms_heap; allow_inversion tmaddr; match outs with | [] -> () | (_, i)::outs -> ( let ((v:instr_val_t i), (vs:instr_ret_t outs)) = match outs with | [] -> (vs, ()) | _::_ -> let vs = coerce vs in (fst vs, snd vs) in match i with | IOpEx i -> let oprs = coerce oprs in let s1 = instr_write_output_explicit i v (fst oprs) s1_orig s1 in let s2 = instr_write_output_explicit i v (fst oprs) s2_orig s2 in lemma_eq_instr_write_outputs outs args vs (snd oprs) s1_orig s1 s2_orig s2 | IOpIm i -> let s1 = instr_write_output_implicit i v s1_orig s1 in let s2 = instr_write_output_implicit i v s2_orig s2 in allow_inversion operand64; allow_inversion operand128; lemma_eq_instr_write_outputs outs args vs (coerce oprs) s1_orig s1 s2_orig s2 ) #pop-options #restart-solver let eval_ins_eq_instr (inst:BS.ins) (s1 s2:machine_state) : Lemma (requires Instr? inst /\ state_eq_S true s1 s2) (ensures state_eq_S true (BS.machine_eval_ins inst s1) (BS.machine_eval_ins inst s2)) = let open BS in let Instr it oprs ann = inst in let InstrTypeRecord #outs #args #havoc_flags' i = it in lemma_eq_instr_apply_eval_inouts outs outs args (instr_eval i) oprs s1 s2; let vs = instr_apply_eval outs args (instr_eval i) oprs s1 in let hav s = match havoc_flags' with | HavocFlags -> {s with ms_flags = havoc_flags} | PreserveFlags -> s in let s1' = hav s1 in let s2' = hav s2 in match vs with | None -> () | Some vs -> lemma_eq_instr_write_outputs outs args vs oprs s1 s1' s2 s2' let eval_code_eq_instr (inst:BS.ins) (f:fuel) (s1 s2:machine_state) : Lemma (requires Instr? inst /\ state_eq_S true s1 s2) (ensures state_eq_opt true (BS.machine_eval_code (Ins inst) f s1) (BS.machine_eval_code (Ins inst) f s2)) = reveal_opaque (`%BS.machine_eval_code_ins) BS.machine_eval_code_ins; eval_ins_eq_instr inst ({s1 with BS.ms_trace = []}) ({s2 with BS.ms_trace = []}) let eval_code_eq_dealloc (inst:BS.ins) (f:fuel) (s1 s2:machine_state) : Lemma (requires Dealloc? inst /\ state_eq_S true s1 s2) (ensures state_eq_opt true (BS.machine_eval_code (Ins inst) f s1) (BS.machine_eval_code (Ins inst) f s2)) = reveal_opaque (`%BS.machine_eval_code_ins) BS.machine_eval_code_ins; use_machine_state_equal (); lemma_heap_ignore_ghost_machine s1.BS.ms_heap s2.BS.ms_heap; allow_inversion tmaddr let eval_code_eq_alloc (inst:BS.ins) (f:fuel) (s1 s2:machine_state) : Lemma (requires Alloc? inst /\ state_eq_S true s1 s2) (ensures state_eq_opt true (BS.machine_eval_code (Ins inst) f s1) (BS.machine_eval_code (Ins inst) f s2)) = reveal_opaque (`%BS.machine_eval_code_ins) BS.machine_eval_code_ins; use_machine_state_equal (); lemma_heap_ignore_ghost_machine s1.BS.ms_heap s2.BS.ms_heap; allow_inversion tmaddr let eval_code_eq_push (inst:BS.ins) (f:fuel) (s1 s2:machine_state) : Lemma (requires Push? inst /\ state_eq_S true s1 s2) (ensures state_eq_opt true (BS.machine_eval_code (Ins inst) f s1) (BS.machine_eval_code (Ins inst) f s2)) = reveal_opaque (`%BS.machine_eval_code_ins) BS.machine_eval_code_ins; use_machine_state_equal (); lemma_heap_ignore_ghost_machine s1.BS.ms_heap s2.BS.ms_heap; allow_inversion tmaddr
{ "checked_file": "/", "dependencies": [ "Vale.X64.StateLemmas.fsti.checked", "Vale.X64.State.fsti.checked", "Vale.X64.Memory.fsti.checked", "Vale.X64.Machine_Semantics_s.fst.checked", "Vale.X64.Machine_s.fst.checked", "Vale.X64.Instruction_s.fsti.checked", "Vale.X64.Flags.fsti.checked", "Vale.X64.Bytes_Code_s.fst.checked", "prims.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.FunctionalExtensionality.fsti.checked" ], "interface_file": true, "source_file": "Vale.X64.Lemmas.fst" }
[ { "abbrev": true, "full_module": "Vale.X64.Memory", "short_module": "ME" }, { "abbrev": true, "full_module": "Vale.X64.Machine_Semantics_s", "short_module": "BS" }, { "abbrev": false, "full_module": "Vale.X64.Bytes_Code_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Instruction_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.StateLemmas", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.State", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Machine_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": true, "full_module": "Vale.Lib.Map16", "short_module": "Map16" }, { "abbrev": true, "full_module": "Vale.X64.Machine_Semantics_s", "short_module": "BS" }, { "abbrev": false, "full_module": "Vale.X64.Bytes_Code_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.StateLemmas", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.State", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Machine_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.HeapLemmas", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.HeapImpl", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.Heap", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 1, "initial_ifuel": 0, "max_fuel": 1, "max_ifuel": 1, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": true, "smtencoding_l_arith_repr": "native", "smtencoding_nl_arith_repr": "wrapped", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [ "smt.arith.nl=false", "smt.QI.EAGER_THRESHOLD=100", "smt.CASE_SPLIT=3" ], "z3refresh": false, "z3rlimit": 100, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
inst: Vale.X64.Machine_Semantics_s.ins -> f: Vale.X64.Lemmas.fuel -> s1: Vale.X64.StateLemmas.machine_state -> s2: Vale.X64.StateLemmas.machine_state -> FStar.Pervasives.Lemma (requires Pop? inst /\ Vale.X64.Lemmas.state_eq_S true s1 s2) (ensures Vale.X64.Lemmas.state_eq_opt true (Vale.X64.Machine_Semantics_s.machine_eval_code (Vale.X64.Machine_s.Ins inst) f s1) (Vale.X64.Machine_Semantics_s.machine_eval_code (Vale.X64.Machine_s.Ins inst) f s2))
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "Vale.X64.Machine_Semantics_s.ins", "Vale.X64.Lemmas.fuel", "Vale.X64.StateLemmas.machine_state", "FStar.Pervasives.allow_inversion", "Vale.X64.Machine_s.tmaddr", "Prims.unit", "Vale.Arch.HeapLemmas.lemma_heap_ignore_ghost_machine", "Vale.X64.Machine_Semantics_s.__proj__Mkmachine_state__item__ms_heap", "Vale.X64.StateLemmas.use_machine_state_equal", "FStar.Pervasives.reveal_opaque", "Vale.X64.Machine_Semantics_s.machine_state", "FStar.Pervasives.Native.option", "Vale.X64.Machine_Semantics_s.machine_eval_code_ins", "Prims.l_and", "Prims.b2t", "Vale.X64.Bytes_Code_s.uu___is_Pop", "Vale.X64.Machine_Semantics_s.instr_annotation", "Vale.X64.Lemmas.state_eq_S", "Prims.squash", "Vale.X64.Lemmas.state_eq_opt", "Vale.X64.Machine_Semantics_s.machine_eval_code", "Vale.X64.Machine_s.Ins", "Vale.X64.Bytes_Code_s.instruction_t", "Vale.X64.Bytes_Code_s.ocmp", "Prims.Nil", "FStar.Pervasives.pattern" ]
[]
true
false
true
false
false
let eval_code_eq_pop (inst: BS.ins) (f: fuel) (s1 s2: machine_state) : Lemma (requires Pop? inst /\ state_eq_S true s1 s2) (ensures state_eq_opt true (BS.machine_eval_code (Ins inst) f s1) (BS.machine_eval_code (Ins inst) f s2)) =
reveal_opaque (`%BS.machine_eval_code_ins) BS.machine_eval_code_ins; use_machine_state_equal (); lemma_heap_ignore_ghost_machine s1.BS.ms_heap s2.BS.ms_heap; allow_inversion tmaddr
false
Hacl.Impl.Frodo.KEM.Encaps.fst
Hacl.Impl.Frodo.KEM.Encaps.clear_matrix3
val clear_matrix3: a:FP.frodo_alg -> sp_matrix:matrix_t params_nbar (params_n a) -> ep_matrix:matrix_t params_nbar (params_n a) -> epp_matrix:matrix_t params_nbar params_nbar -> Stack unit (requires fun h -> live h sp_matrix /\ live h ep_matrix /\ live h epp_matrix /\ disjoint sp_matrix ep_matrix /\ disjoint sp_matrix epp_matrix /\ disjoint ep_matrix epp_matrix) (ensures fun h0 _ h1 -> modifies (loc sp_matrix |+| loc ep_matrix |+| loc epp_matrix) h0 h1)
val clear_matrix3: a:FP.frodo_alg -> sp_matrix:matrix_t params_nbar (params_n a) -> ep_matrix:matrix_t params_nbar (params_n a) -> epp_matrix:matrix_t params_nbar params_nbar -> Stack unit (requires fun h -> live h sp_matrix /\ live h ep_matrix /\ live h epp_matrix /\ disjoint sp_matrix ep_matrix /\ disjoint sp_matrix epp_matrix /\ disjoint ep_matrix epp_matrix) (ensures fun h0 _ h1 -> modifies (loc sp_matrix |+| loc ep_matrix |+| loc epp_matrix) h0 h1)
let clear_matrix3 a sp_matrix ep_matrix epp_matrix = clear_matrix sp_matrix; clear_matrix ep_matrix; clear_matrix epp_matrix
{ "file_name": "code/frodo/Hacl.Impl.Frodo.KEM.Encaps.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 25, "end_line": 245, "start_col": 0, "start_line": 242 }
module Hacl.Impl.Frodo.KEM.Encaps open FStar.HyperStack open FStar.HyperStack.ST open FStar.Mul open LowStar.Buffer open Lib.IntTypes open Lib.Buffer open Hacl.Impl.Matrix open Hacl.Impl.Frodo.Params open Hacl.Impl.Frodo.KEM open Hacl.Impl.Frodo.Encode open Hacl.Impl.Frodo.Pack open Hacl.Impl.Frodo.Sample open Hacl.Frodo.Random module ST = FStar.HyperStack.ST module LSeq = Lib.Sequence module LB = Lib.ByteSequence module FP = Spec.Frodo.Params module S = Spec.Frodo.KEM.Encaps module M = Spec.Matrix module KG = Hacl.Impl.Frodo.KEM.KeyGen #set-options "--z3rlimit 100 --fuel 0 --ifuel 0" inline_for_extraction noextract val frodo_mul_add_sa_plus_e: a:FP.frodo_alg -> gen_a:FP.frodo_gen_a{is_supported gen_a} -> seed_a:lbytes bytes_seed_a -> sp_matrix:matrix_t params_nbar (params_n a) -> ep_matrix:matrix_t params_nbar (params_n a) -> bp_matrix:matrix_t params_nbar (params_n a) -> Stack unit (requires fun h -> live h seed_a /\ live h ep_matrix /\ live h sp_matrix /\ live h bp_matrix /\ disjoint bp_matrix seed_a /\ disjoint bp_matrix ep_matrix /\ disjoint bp_matrix sp_matrix) (ensures fun h0 _ h1 -> modifies (loc bp_matrix) h0 h1 /\ as_matrix h1 bp_matrix == S.frodo_mul_add_sa_plus_e a gen_a (as_seq h0 seed_a) (as_matrix h0 sp_matrix) (as_matrix h0 ep_matrix)) let frodo_mul_add_sa_plus_e a gen_a seed_a sp_matrix ep_matrix bp_matrix = push_frame (); let a_matrix = matrix_create (params_n a) (params_n a) in frodo_gen_matrix gen_a (params_n a) seed_a a_matrix; matrix_mul sp_matrix a_matrix bp_matrix; matrix_add bp_matrix ep_matrix; pop_frame () inline_for_extraction noextract val crypto_kem_enc_ct_pack_c1: a:FP.frodo_alg -> gen_a:FP.frodo_gen_a{is_supported gen_a} -> seed_a:lbytes bytes_seed_a -> sp_matrix:matrix_t params_nbar (params_n a) -> ep_matrix:matrix_t params_nbar (params_n a) -> c1:lbytes (ct1bytes_len a) -> Stack unit (requires fun h -> live h seed_a /\ live h ep_matrix /\ live h sp_matrix /\ live h c1 /\ disjoint seed_a c1 /\ disjoint ep_matrix c1 /\ disjoint sp_matrix c1) (ensures fun h0 _ h1 -> modifies (loc c1) h0 h1 /\ as_seq h1 c1 == S.crypto_kem_enc_ct_pack_c1 a gen_a (as_seq h0 seed_a) (as_matrix h0 sp_matrix) (as_matrix h0 ep_matrix)) let crypto_kem_enc_ct_pack_c1 a gen_a seed_a sp_matrix ep_matrix c1 = push_frame (); let bp_matrix = matrix_create params_nbar (params_n a) in frodo_mul_add_sa_plus_e a gen_a seed_a sp_matrix ep_matrix bp_matrix; frodo_pack (params_logq a) bp_matrix c1; pop_frame () inline_for_extraction noextract val frodo_mul_add_sb_plus_e: a:FP.frodo_alg -> b:lbytes (publicmatrixbytes_len a) -> sp_matrix:matrix_t params_nbar (params_n a) -> epp_matrix:matrix_t params_nbar params_nbar -> v_matrix:matrix_t params_nbar params_nbar -> Stack unit (requires fun h -> live h b /\ live h epp_matrix /\ live h v_matrix /\ live h sp_matrix /\ disjoint v_matrix b /\ disjoint v_matrix epp_matrix /\ disjoint v_matrix sp_matrix) (ensures fun h0 _ h1 -> modifies (loc v_matrix) h0 h1 /\ as_matrix h1 v_matrix == S.frodo_mul_add_sb_plus_e a (as_seq h0 b) (as_matrix h0 sp_matrix) (as_matrix h0 epp_matrix)) let frodo_mul_add_sb_plus_e a b sp_matrix epp_matrix v_matrix = push_frame (); let b_matrix = matrix_create (params_n a) params_nbar in frodo_unpack (params_n a) params_nbar (params_logq a) b b_matrix; matrix_mul sp_matrix b_matrix v_matrix; matrix_add v_matrix epp_matrix; pop_frame () inline_for_extraction noextract val frodo_mul_add_sb_plus_e_plus_mu: a:FP.frodo_alg -> mu:lbytes (bytes_mu a) -> b:lbytes (publicmatrixbytes_len a) -> sp_matrix:matrix_t params_nbar (params_n a) -> epp_matrix:matrix_t params_nbar params_nbar -> v_matrix:matrix_t params_nbar params_nbar -> Stack unit (requires fun h -> live h b /\ live h mu /\ live h v_matrix /\ live h sp_matrix /\ live h epp_matrix /\ disjoint v_matrix b /\ disjoint v_matrix sp_matrix /\ disjoint v_matrix mu /\ disjoint v_matrix epp_matrix) (ensures fun h0 _ h1 -> modifies (loc v_matrix) h0 h1 /\ as_matrix h1 v_matrix == S.frodo_mul_add_sb_plus_e_plus_mu a (as_seq h0 mu) (as_seq h0 b) (as_matrix h0 sp_matrix) (as_matrix h0 epp_matrix)) let frodo_mul_add_sb_plus_e_plus_mu a mu b sp_matrix epp_matrix v_matrix = push_frame (); frodo_mul_add_sb_plus_e a b sp_matrix epp_matrix v_matrix; let mu_encode = matrix_create params_nbar params_nbar in frodo_key_encode (params_logq a) (params_extracted_bits a) params_nbar mu mu_encode; matrix_add v_matrix mu_encode; clear_matrix mu_encode; pop_frame () inline_for_extraction noextract val crypto_kem_enc_ct_pack_c2: a:FP.frodo_alg -> mu:lbytes (bytes_mu a) -> b:lbytes (publicmatrixbytes_len a) -> sp_matrix:matrix_t params_nbar (params_n a) -> epp_matrix:matrix_t params_nbar params_nbar -> c2:lbytes (ct2bytes_len a) -> Stack unit (requires fun h -> live h mu /\ live h b /\ live h sp_matrix /\ live h epp_matrix /\ live h c2 /\ disjoint mu c2 /\ disjoint b c2 /\ disjoint sp_matrix c2 /\ disjoint epp_matrix c2) (ensures fun h0 _ h1 -> modifies (loc c2) h0 h1 /\ as_seq h1 c2 == S.crypto_kem_enc_ct_pack_c2 a (as_seq h0 mu) (as_seq h0 b) (as_matrix h0 sp_matrix) (as_matrix h0 epp_matrix)) #push-options "--z3rlimit 200" let crypto_kem_enc_ct_pack_c2 a mu b sp_matrix epp_matrix c2 = push_frame (); let v_matrix = matrix_create params_nbar params_nbar in frodo_mul_add_sb_plus_e_plus_mu a mu b sp_matrix epp_matrix v_matrix; frodo_pack (params_logq a) v_matrix c2; clear_matrix v_matrix; pop_frame () #pop-options inline_for_extraction noextract val get_sp_ep_epp_matrices: a:FP.frodo_alg -> seed_se:lbytes (crypto_bytes a) -> sp_matrix:matrix_t params_nbar (params_n a) -> ep_matrix:matrix_t params_nbar (params_n a) -> epp_matrix:matrix_t params_nbar params_nbar -> Stack unit (requires fun h -> live h seed_se /\ live h sp_matrix /\ live h ep_matrix /\ live h epp_matrix /\ disjoint seed_se sp_matrix /\ disjoint seed_se ep_matrix /\ disjoint seed_se epp_matrix /\ disjoint sp_matrix ep_matrix /\ disjoint sp_matrix epp_matrix /\ disjoint ep_matrix epp_matrix) (ensures fun h0 _ h1 -> modifies (loc sp_matrix |+| loc ep_matrix |+| loc epp_matrix) h0 h1 /\ (as_matrix h1 sp_matrix, as_matrix h1 ep_matrix, as_matrix h1 epp_matrix) == S.get_sp_ep_epp_matrices a (as_seq h0 seed_se)) let get_sp_ep_epp_matrices a seed_se sp_matrix ep_matrix epp_matrix = push_frame (); [@inline_let] let s_bytes_len = secretmatrixbytes_len a in let r = create (2ul *! s_bytes_len +! 2ul *! params_nbar *! params_nbar) (u8 0) in KG.frodo_shake_r a (u8 0x96) seed_se (2ul *! s_bytes_len +! 2ul *! params_nbar *! params_nbar) r; frodo_sample_matrix a params_nbar (params_n a) (sub r 0ul s_bytes_len) sp_matrix; frodo_sample_matrix a params_nbar (params_n a) (sub r s_bytes_len s_bytes_len) ep_matrix; frodo_sample_matrix a params_nbar params_nbar (sub r (2ul *! s_bytes_len) (2ul *! params_nbar *! params_nbar)) epp_matrix; pop_frame () inline_for_extraction noextract val crypto_kem_enc_ct0: a:FP.frodo_alg -> gen_a:FP.frodo_gen_a{is_supported gen_a} -> seed_a:lbytes bytes_seed_a -> b:lbytes (publicmatrixbytes_len a) -> mu:lbytes (bytes_mu a) -> sp_matrix:matrix_t params_nbar (params_n a) -> ep_matrix:matrix_t params_nbar (params_n a) -> epp_matrix:matrix_t params_nbar params_nbar -> ct:lbytes (crypto_ciphertextbytes a) -> Stack unit (requires fun h -> live h seed_a /\ live h b /\ live h mu /\ live h ct /\ live h sp_matrix /\ live h ep_matrix /\ live h epp_matrix /\ disjoint ct seed_a /\ disjoint ct b /\ disjoint ct mu /\ disjoint ct sp_matrix /\ disjoint ct ep_matrix /\ disjoint ct epp_matrix) (ensures fun h0 _ h1 -> modifies (loc ct) h0 h1 /\ (let c1:LB.lbytes (FP.ct1bytes_len a) = S.crypto_kem_enc_ct_pack_c1 a gen_a (as_seq h0 seed_a) (as_seq h0 sp_matrix) (as_seq h0 ep_matrix) in let c2:LB.lbytes (FP.ct2bytes_len a) = S.crypto_kem_enc_ct_pack_c2 a (as_seq h0 mu) (as_seq h0 b) (as_seq h0 sp_matrix) (as_seq h0 epp_matrix) in v (crypto_ciphertextbytes a) == FP.ct1bytes_len a + FP.ct2bytes_len a /\ as_seq h1 ct `Seq.equal` LSeq.concat #_ #(FP.ct1bytes_len a) #(FP.ct2bytes_len a) c1 c2)) let crypto_kem_enc_ct0 a gen_a seed_a b mu sp_matrix ep_matrix epp_matrix ct = let c1 = sub ct 0ul (ct1bytes_len a) in let c2 = sub ct (ct1bytes_len a) (ct2bytes_len a) in let h0 = ST.get () in crypto_kem_enc_ct_pack_c1 a gen_a seed_a sp_matrix ep_matrix c1; let h1 = ST.get () in crypto_kem_enc_ct_pack_c2 a mu b sp_matrix epp_matrix c2; let h2 = ST.get () in LSeq.eq_intro (LSeq.sub (as_seq h2 ct) 0 (v (ct1bytes_len a))) (LSeq.sub (as_seq h1 ct) 0 (v (ct1bytes_len a))); LSeq.lemma_concat2 (v (ct1bytes_len a)) (LSeq.sub (as_seq h1 ct) 0 (v (ct1bytes_len a))) (v (ct2bytes_len a)) (LSeq.sub (as_seq h2 ct) (v (ct1bytes_len a)) (v (ct2bytes_len a))) (as_seq h2 ct) inline_for_extraction noextract val clear_matrix3: a:FP.frodo_alg -> sp_matrix:matrix_t params_nbar (params_n a) -> ep_matrix:matrix_t params_nbar (params_n a) -> epp_matrix:matrix_t params_nbar params_nbar -> Stack unit (requires fun h -> live h sp_matrix /\ live h ep_matrix /\ live h epp_matrix /\ disjoint sp_matrix ep_matrix /\ disjoint sp_matrix epp_matrix /\ disjoint ep_matrix epp_matrix) (ensures fun h0 _ h1 -> modifies (loc sp_matrix |+| loc ep_matrix |+| loc epp_matrix) h0 h1)
{ "checked_file": "/", "dependencies": [ "Spec.Matrix.fst.checked", "Spec.Frodo.Params.fst.checked", "Spec.Frodo.KEM.Encaps.fst.checked", "prims.fst.checked", "LowStar.Buffer.fst.checked", "Lib.Sequence.fsti.checked", "Lib.IntTypes.fsti.checked", "Lib.ByteSequence.fsti.checked", "Lib.Buffer.fsti.checked", "Hacl.Impl.Matrix.fst.checked", "Hacl.Impl.Frodo.Sample.fst.checked", "Hacl.Impl.Frodo.Params.fst.checked", "Hacl.Impl.Frodo.Pack.fst.checked", "Hacl.Impl.Frodo.KEM.KeyGen.fst.checked", "Hacl.Impl.Frodo.KEM.fst.checked", "Hacl.Impl.Frodo.Encode.fst.checked", "Hacl.Frodo.Random.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked" ], "interface_file": false, "source_file": "Hacl.Impl.Frodo.KEM.Encaps.fst" }
[ { "abbrev": true, "full_module": "Hacl.Impl.Frodo.KEM.KeyGen", "short_module": "KG" }, { "abbrev": true, "full_module": "Spec.Matrix", "short_module": "M" }, { "abbrev": true, "full_module": "Spec.Frodo.KEM.Encaps", "short_module": "S" }, { "abbrev": true, "full_module": "Spec.Frodo.Params", "short_module": "FP" }, { "abbrev": true, "full_module": "Lib.ByteSequence", "short_module": "LB" }, { "abbrev": true, "full_module": "Lib.Sequence", "short_module": "LSeq" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": false, "full_module": "Hacl.Frodo.Random", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Impl.Frodo.Sample", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Impl.Frodo.Pack", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Impl.Frodo.Encode", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Impl.Frodo.KEM", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Impl.Frodo.Params", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Impl.Matrix", "short_module": null }, { "abbrev": false, "full_module": "Lib.Buffer", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "LowStar.Buffer", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Impl.Frodo.KEM", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Impl.Frodo.KEM", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 0, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 100, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
a: Spec.Frodo.Params.frodo_alg -> sp_matrix: Hacl.Impl.Matrix.matrix_t Hacl.Impl.Frodo.Params.params_nbar (Hacl.Impl.Frodo.Params.params_n a) -> ep_matrix: Hacl.Impl.Matrix.matrix_t Hacl.Impl.Frodo.Params.params_nbar (Hacl.Impl.Frodo.Params.params_n a) -> epp_matrix: Hacl.Impl.Matrix.matrix_t Hacl.Impl.Frodo.Params.params_nbar Hacl.Impl.Frodo.Params.params_nbar -> FStar.HyperStack.ST.Stack Prims.unit
FStar.HyperStack.ST.Stack
[]
[]
[ "Spec.Frodo.Params.frodo_alg", "Hacl.Impl.Matrix.matrix_t", "Hacl.Impl.Frodo.Params.params_nbar", "Hacl.Impl.Frodo.Params.params_n", "Hacl.Impl.Frodo.KEM.clear_matrix", "Prims.unit" ]
[]
false
true
false
false
false
let clear_matrix3 a sp_matrix ep_matrix epp_matrix =
clear_matrix sp_matrix; clear_matrix ep_matrix; clear_matrix epp_matrix
false
AlgWP.fst
AlgWP.interp_morph
val interp_morph (#a #b #l1 #l2: _) (c: rwtree a l1) (f: (a -> rwtree b l2)) (p s0: _) : Lemma (interp_as_wp c s0 (fun (y, s1) -> interp_as_wp (f y) s1 p) == interp_as_wp (tbind #_ #_ #l1 #l2 c f) s0 p)
val interp_morph (#a #b #l1 #l2: _) (c: rwtree a l1) (f: (a -> rwtree b l2)) (p s0: _) : Lemma (interp_as_wp c s0 (fun (y, s1) -> interp_as_wp (f y) s1 p) == interp_as_wp (tbind #_ #_ #l1 #l2 c f) s0 p)
let rec interp_morph #a #b #l1 #l2 (c : rwtree a l1) (f : a -> rwtree b l2) (p:_) (s0:_) : Lemma (interp_as_wp c s0 (fun (y, s1) -> interp_as_wp (f y) s1 p) == interp_as_wp (tbind #_ #_ #l1 #l2 c f) s0 p) = match c with | Return x -> interp_ret #_ #l2 x | Op Read _ k -> let aux (o:state) : Lemma (interp_as_wp (k o) s0 (fun (y, s1) -> interp_as_wp (f y) s1 p) == interp_as_wp (tbind #_ #_ #l1 #l2 (k o) f) s0 p) = interp_morph #_ #_ #l1 #l2 (k o) f p s0 in Classical.forall_intro aux | Op Write s k -> let aux (o:unit) : Lemma (interp_as_wp (k o) s (fun (y, s1) -> interp_as_wp (f y) s1 p) == interp_as_wp (tbind #_ #_ #l1 #l2 (k o) f) s p) = interp_morph #_ #_ #l1 #l2 (k o) f p s in Classical.forall_intro aux | _ -> ()
{ "file_name": "examples/layeredeffects/AlgWP.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 13, "end_line": 159, "start_col": 0, "start_line": 140 }
module AlgWP (* AlgWP: tracking operation labels and WPs. At the end, we show how we can recover semantic facts from the labels alone, e.g. that interpreting a tree will not change the state, effectively allowing to strengthen a WP from intensional information about the operations in the tree. *) open FStar.List.Tot open FStar.Calc module FE = FStar.FunctionalExtensionality module F = FStar.FunctionalExtensionality module W = FStar.WellFounded module T = FStar.Tactics.V2 module ID5 = ID5 open Alg let rwops = labs:ops{sublist labs [Read; Write]} let noops : rwops = [] type rwtree a (l : ops{l `sublist` [Read;Write]}) = Alg.tree a l (* Somehow did not need this in Alg! *) let rec sublist_at_const (l1 l2 l3 : ops) : Lemma (requires (sublist l1 l3 /\ sublist l2 l3)) (ensures (sublist (l1@l2) l3)) [SMTPat (sublist (l1@l2) l3)] = match l1 with | [] -> () | h::t -> sublist_at_const t l2 l3 let (@@) : rwops -> rwops -> rwops = fun l1 l2 -> l1@l2 let subops : rwops -> rwops -> Type0 = sublist let sublist_at (l1 l2 : ops) : Lemma (sublist l1 (l1@l2) /\ sublist l2 (l1@l2)) [SMTPat (l1@l2)] = Alg.sublist_at l1 l2 let rwtree_help a labs (t : rwtree a labs) : Lemma (forall l. l `List.Tot.memP` labs ==> l == Read \/ l == Write) [SMTPat (has_type t (rwtree a labs))] = () let tbind : #a:_ -> #b:_ -> #labs1:_ -> #labs2:_ -> rwtree a labs1 -> (a -> rwtree b labs2) -> rwtree b (labs1@@labs2) = fun c f -> Alg.bind _ _ c f let st_wp0 (a:Type) : Type = state -> (a & state -> Type0) -> Type0 let st_monotonic #a (w : st_wp0 a) : Type0 = //forall s0 p1 p2. (forall r. p1 r ==> p2 r) ==> w s0 p1 ==> w s0 p2 // ^ this version seems to be less SMT-friendly forall s0 p1 p2. (forall x s1. p1 (x, s1) ==> p2 (x, s1)) ==> w s0 p1 ==> w s0 p2 let st_wp (a:Type) = wp:st_wp0 a{st_monotonic wp} unfold let return_wp #a x : st_wp a = fun s0 p -> p (x, s0) unfold let bind_wp #a #b (w : st_wp a) (wf : a -> st_wp b) : st_wp b = fun s0 p -> w s0 (fun (y, s1) -> wf y s1 p) unfold let read_wp : st_wp state = fun s0 p -> p (s0, s0) unfold let write_wp : state -> st_wp unit = fun s _ p -> p ((), s) (* Also doable with handlers *) let rec interp_as_wp #a (t : Alg.tree a [Read;Write]) : st_wp a = match t with | Return x -> return_wp x | Op Read _ k -> bind_wp read_wp (fun s -> interp_as_wp (k s)) | Op Write s k -> bind_wp (write_wp s) (fun (o:unit) -> interp_as_wp (k o)) (* With handlers. Can only be done into []? See the use of `run`. *) let interp_as_wp2 #a #l (t : rwtree a l) : Alg (st_wp a) [] = let t0 : Alg.tree a [Read; Write] = t in handle_with #a #(st_wp a) #[Read; Write] #[] (fun () -> Alg?.reflect t0) (fun x -> return_wp x) (function Read -> (fun i k -> bind_wp read_wp (fun s -> run (fun () -> k s))) | Write -> (fun i k -> bind_wp (write_wp i) (fun _ -> run k))) (* Bug: defining this as a FStar.Preorder.preorder causes stupid failures ahead *) unfold val stronger : (#a:Type) -> st_wp a -> st_wp a -> Type0 let stronger w1 w2 = forall p s. w1 p s ==> w2 p s let equiv #a (w1 w2 : st_wp a) = w1 `stronger` w2 /\ w2 `stronger` w1 let (<<=) = stronger val interp_ret (#a:Type) (#l:rwops) (x:a) : Lemma (return_wp x `stronger` interp_as_wp (Return x)) let interp_ret x = () val interp_ret' (#a:Type) (x:a) : Lemma (return_wp x == interp_as_wp (Return x)) let interp_ret' x = assert_norm (return_wp x == interp_as_wp (Return x)) let wp_is_monotonic #a (wp : st_wp a) : Type0 = forall p1 p2 s0. (forall x s1. p1 (x, s1) ==> p2 (x, s1)) ==> wp s0 p1 ==> wp s0 p2 let bind_preserves_mon #a #b (wp : st_wp a) (f : a -> st_wp b) : Lemma (requires (wp_is_monotonic wp /\ (forall x. wp_is_monotonic (f x)))) (ensures (wp_is_monotonic (bind_wp wp f))) = () let rec interp_monotonic #a #l (c:rwtree a l) : Lemma (wp_is_monotonic (interp_as_wp c)) = match c with | Return x -> () | Op Read _ k -> let aux (x:state) : Lemma (wp_is_monotonic (interp_as_wp (k x))) = interp_monotonic #_ #l (k x) in Classical.forall_intro aux; bind_preserves_mon read_wp (fun x -> interp_as_wp (k x)) | Op Write s k -> let aux (x:unit) : Lemma (wp_is_monotonic (interp_as_wp (k x))) = interp_monotonic #_ #l (k x) in Classical.forall_intro aux; bind_preserves_mon (write_wp s) (fun x -> interp_as_wp (k x)) let elim_str #a (w1 w2 : st_wp a) (p : (a & state -> Type0)) (s0:state) : Lemma (requires (w1 <<= w2)) (ensures w1 s0 p ==> w2 s0 p) = () #set-options "--print_implicits" (* Takes a while, known to fail sporadically *)
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "ID5.fst.checked", "FStar.WellFounded.fst.checked", "FStar.Tactics.V2.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Monotonic.Pure.fst.checked", "FStar.List.Tot.fst.checked", "FStar.FunctionalExtensionality.fsti.checked", "FStar.Classical.fsti.checked", "FStar.Calc.fsti.checked", "Alg.fst.checked" ], "interface_file": false, "source_file": "AlgWP.fst" }
[ { "abbrev": false, "full_module": "Alg", "short_module": null }, { "abbrev": true, "full_module": "ID5", "short_module": "ID5" }, { "abbrev": true, "full_module": "FStar.Tactics.V2", "short_module": "T" }, { "abbrev": true, "full_module": "FStar.WellFounded", "short_module": "W" }, { "abbrev": true, "full_module": "FStar.FunctionalExtensionality", "short_module": "F" }, { "abbrev": true, "full_module": "FStar.FunctionalExtensionality", "short_module": "FE" }, { "abbrev": false, "full_module": "FStar.Calc", "short_module": null }, { "abbrev": false, "full_module": "FStar.List.Tot", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": 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": 10, "quake_keep": false, "quake_lo": 1, "retry": true, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_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
c: AlgWP.rwtree a l1 -> f: (_: a -> AlgWP.rwtree b l2) -> p: (_: (b * Alg.state) -> Type0) -> s0: Alg.state -> FStar.Pervasives.Lemma (ensures AlgWP.interp_as_wp c s0 (fun _ -> (let FStar.Pervasives.Native.Mktuple2 #_ #_ y s1 = _ in AlgWP.interp_as_wp (f y) s1 p) <: Type0) == AlgWP.interp_as_wp (AlgWP.tbind c f) s0 p)
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "Alg.ops", "Alg.sublist", "Prims.Cons", "Alg.op", "Alg.Read", "Alg.Write", "Prims.Nil", "AlgWP.rwtree", "FStar.Pervasives.Native.tuple2", "Alg.state", "AlgWP.interp_ret", "Alg.op_inp", "Alg.op_out", "Alg.tree0", "FStar.Classical.forall_intro", "Prims.eq2", "AlgWP.interp_as_wp", "AlgWP.tbind", "Prims.unit", "Prims.l_True", "Prims.squash", "FStar.Pervasives.pattern", "AlgWP.interp_morph" ]
[ "recursion" ]
false
false
true
false
false
let rec interp_morph #a #b #l1 #l2 (c: rwtree a l1) (f: (a -> rwtree b l2)) (p: _) (s0: _) : Lemma (interp_as_wp c s0 (fun (y, s1) -> interp_as_wp (f y) s1 p) == interp_as_wp (tbind #_ #_ #l1 #l2 c f) s0 p) =
match c with | Return x -> interp_ret #_ #l2 x | Op Read _ k -> let aux (o: state) : Lemma (interp_as_wp (k o) s0 (fun (y, s1) -> interp_as_wp (f y) s1 p) == interp_as_wp (tbind #_ #_ #l1 #l2 (k o) f) s0 p) = interp_morph #_ #_ #l1 #l2 (k o) f p s0 in Classical.forall_intro aux | Op Write s k -> let aux (o: unit) : Lemma (interp_as_wp (k o) s (fun (y, s1) -> interp_as_wp (f y) s1 p) == interp_as_wp (tbind #_ #_ #l1 #l2 (k o) f) s p) = interp_morph #_ #_ #l1 #l2 (k o) f p s in Classical.forall_intro aux | _ -> ()
false